1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +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:
Linus Groh 2021-01-23 23:49:04 +01:00 committed by Andreas Kling
parent 397f432aed
commit 766f30f593
3 changed files with 27 additions and 3 deletions

View file

@ -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");
});