mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
LibJS: Check if class extends value has a valid prototype
If we have a function as class extends value, we still cannot assume that it has a prototype property and that property has a function or null as its value - blindly calling to_object() on it may fail. Fixes #5075.
This commit is contained in:
parent
397f432aed
commit
766f30f593
3 changed files with 27 additions and 3 deletions
|
@ -33,3 +33,17 @@ test("extending String", () => {
|
|||
const ms2 = new MyString2("abc");
|
||||
expect(ms2.charAt(1)).toBe("#b");
|
||||
});
|
||||
|
||||
test("class extends value is invalid", () => {
|
||||
expect(() => {
|
||||
class A extends 123 {}
|
||||
}).toThrowWithMessage(TypeError, "Class extends value 123 is not a constructor or null");
|
||||
});
|
||||
|
||||
test("class extends value has invalid prototype", () => {
|
||||
function f() {}
|
||||
f.prototype = 123;
|
||||
expect(() => {
|
||||
class A extends f {}
|
||||
}).toThrowWithMessage(TypeError, "Class extends value has an invalid prototype 123");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue