LibJS: Implement Object.prototype.isPrototypeOf

Spec: https://tc39.es/ecma262/#sec-object.prototype.isprototypeof
This commit is contained in:
Luke 2020-12-28 01:22:38 +00:00 committed by Andreas Kling
commit be30dc2b18
Notes: sideshowbarker 2024-07-19 00:30:06 +09:00
4 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,18 @@
test("basic functionality", () => {
function A() {}
function B() {}
A.prototype = new B();
const C = new A();
expect(A.prototype.isPrototypeOf(C)).toBeTrue();
expect(B.prototype.isPrototypeOf(C)).toBeTrue();
expect(A.isPrototypeOf(C)).toBeFalse();
expect(B.isPrototypeOf(C)).toBeFalse();
const D = new Object();
expect(Object.prototype.isPrototypeOf(D)).toBeTrue();
expect(Function.prototype.isPrototypeOf(D.toString)).toBeTrue();
expect(Array.prototype.isPrototypeOf([])).toBeTrue();
});