1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 10:01:13 +09:00

LibJS: Oops, "instanceof" was backwards!

Fix the "instanceof" operator to check if the constructor's prototype
property occurs anywhere in the prototype chain of the instance object.

This patch also adds Object.setPrototypeOf() to make it possible to
create a test for this bug.

Thanks to DexesTTP for pointing this out! :^)
This commit is contained in:
Andreas Kling 2020-03-28 19:48:12 +01:00
parent e5ebdb9bca
commit 82ca7ae1f8
Notes: sideshowbarker 2024-07-19 08:05:26 +09:00
5 changed files with 53 additions and 17 deletions

View file

@ -1,7 +1,28 @@
function Foo() {
this.x = 123;
}
function assert(x) { if (!x) throw 1; }
try {
function Foo() {
this.x = 123;
}
var foo = new Foo();
assert(foo instanceof Foo);
function Base() {
this.is_base = true;
}
function Derived() {
this.is_derived = true;
}
Object.setPrototypeOf(Derived.prototype, Base.prototype);
var d = new Derived();
assert(d instanceof Derived);
assert(d instanceof Base);
var foo = new Foo();
if (foo instanceof Foo)
console.log("PASS");
} catch(e) {
console.log("FAIL: " + e);
}