mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 00:44:58 +00:00

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! :^)
28 lines
504 B
JavaScript
28 lines
504 B
JavaScript
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);
|
|
|
|
console.log("PASS");
|
|
} catch(e) {
|
|
console.log("FAIL: " + e);
|
|
}
|