mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Improve Object.prototype.isPrototypeOf coverage (#2446)
This commit is contained in:
parent
0ea69c7864
commit
19fd4bea79
@ -1,59 +0,0 @@
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
When the isPrototypeOf method is called with argument V and when O and
|
||||
V refer to the same object or to objects joined to each other, return true
|
||||
es5id: 15.2.4.6_A1
|
||||
description: Creating two objects with the same prototype
|
||||
---*/
|
||||
|
||||
function USER_FACTORY(name) {
|
||||
this.name = name;
|
||||
this.getName = function() {
|
||||
return name;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function FORCEDUSER_FACTORY(name, grade) {
|
||||
this.name = name;
|
||||
this.grade = grade;
|
||||
this.getGrade = function() {
|
||||
return grade;
|
||||
};
|
||||
}
|
||||
|
||||
var proto = new USER_FACTORY("noname");
|
||||
|
||||
FORCEDUSER_FACTORY.prototype = proto;
|
||||
|
||||
var luke = new FORCEDUSER_FACTORY("Luke Skywalker", 12);
|
||||
//////
|
||||
// CHECK#1
|
||||
assert.sameValue(
|
||||
proto.isPrototypeOf(luke),
|
||||
true,
|
||||
'#1: native ECMAScript objects have an internal property called [[Prototype]].'
|
||||
);
|
||||
|
||||
//
|
||||
/////////
|
||||
//////
|
||||
// CHECK#2
|
||||
assert.sameValue(
|
||||
USER_FACTORY.prototype.isPrototypeOf(luke),
|
||||
true,
|
||||
'#2: native ECMAScript objects have an internal property called [[Prototype]].'
|
||||
);
|
||||
|
||||
//
|
||||
/////////
|
||||
//////
|
||||
// CHECK#3
|
||||
if (Number.isPrototypeOf(luke)) {
|
||||
$ERROR('#2: Native ECMAScript objects have an internal property called [[Prototype]].');
|
||||
}
|
||||
//
|
||||
/////////
|
@ -1,29 +0,0 @@
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
The Object.prototype.isPrototypeOf.length property has the attribute
|
||||
ReadOnly
|
||||
es5id: 15.2.4.6_A10
|
||||
description: >
|
||||
Checking if varying the Object.prototype.isPrototypeOf.length
|
||||
property fails
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
//CHECK#1
|
||||
if (!(Object.prototype.isPrototypeOf.hasOwnProperty('length'))) {
|
||||
$ERROR('#1: the Object.prototype.isPrototypeOf has length property');
|
||||
}
|
||||
|
||||
var obj = Object.prototype.isPrototypeOf.length;
|
||||
|
||||
verifyNotWritable(Object.prototype.isPrototypeOf, "length", null, function() {
|
||||
return "shifted";
|
||||
});
|
||||
|
||||
//CHECK#2
|
||||
if (Object.prototype.isPrototypeOf.length !== obj) {
|
||||
$ERROR('#2: the Object.prototype.isPrototypeOf length property has the attributes ReadOnly');
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: The length property of the hasOwnProperty method is 1
|
||||
es5id: 15.2.4.6_A11
|
||||
description: Checking the Object.prototype.hasOwnProperty.length
|
||||
---*/
|
||||
|
||||
//CHECK#1
|
||||
if (!(Object.prototype.isPrototypeOf.hasOwnProperty("length"))) {
|
||||
$ERROR('#1: the Object.prototype.isPrototypeOf has length property');
|
||||
}
|
||||
|
||||
//CHECK#2
|
||||
if (Object.prototype.isPrototypeOf.length !== 1) {
|
||||
$ERROR('#2: The length property of the toObject method is 1');
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
// Copyright 2011 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es5id: 15.2.4.6_A12
|
||||
description: >
|
||||
Let O be the result of calling ToObject passing the this value as
|
||||
the argument.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.prototype.isPrototypeOf.call(undefined, {});
|
||||
});
|
@ -1,13 +0,0 @@
|
||||
// Copyright 2011 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es5id: 15.2.4.6_A13
|
||||
description: >
|
||||
Let O be the result of calling ToObject passing the this value as
|
||||
the argument.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.prototype.isPrototypeOf.call(null, {});
|
||||
});
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Object.prototype.isPrototypeOf has not prototype property
|
||||
es5id: 15.2.4.6_A6
|
||||
description: >
|
||||
Checking if obtaining the prototype property of
|
||||
Object.prototype.isPrototypeOf fails
|
||||
---*/
|
||||
|
||||
//CHECK#1
|
||||
if (Object.prototype.isPrototypeOf.prototype !== undefined) {
|
||||
$ERROR('#1: Object.prototype.isPrototypeOf has not prototype property' + Object.prototype.isPrototypeOf.prototype);
|
||||
}
|
||||
//
|
@ -1,14 +0,0 @@
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Object.prototype.isPrototypeOf can't be used as a constructor
|
||||
es5id: 15.2.4.6_A7
|
||||
description: Checking if creating new "Object.prototype.isPrototypeOf" fails
|
||||
---*/
|
||||
|
||||
var FACTORY = Object.prototype.isPrototypeOf;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new FACTORY;
|
||||
});
|
@ -1,30 +0,0 @@
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
The Object.prototype.isPrototypeOf.length property has the attribute
|
||||
DontEnum
|
||||
es5id: 15.2.4.6_A8
|
||||
description: >
|
||||
Checknig if enumerating the Object.prototype.isPrototypeOf.length
|
||||
property fails
|
||||
---*/
|
||||
|
||||
//CHECK#0
|
||||
if (!(Object.prototype.isPrototypeOf.hasOwnProperty('length'))) {
|
||||
$ERROR('#0: the Object.prototype.isPrototypeOf has length property');
|
||||
}
|
||||
|
||||
|
||||
// CHECK#1
|
||||
if (Object.prototype.isPrototypeOf.propertyIsEnumerable('length')) {
|
||||
$ERROR('#1: the Object.prototype.isPrototypeOf.length property has the attributes DontEnum');
|
||||
}
|
||||
|
||||
// CHECK#2
|
||||
for (var p in Object.prototype.isPrototypeOf) {
|
||||
if (p === "length")
|
||||
$ERROR('#2: the Object.prototype.isPrototypeOf.length property has the attributes DontEnum');
|
||||
}
|
||||
//
|
@ -1,23 +0,0 @@
|
||||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: |
|
||||
The Object.prototype.isPrototypeOf.length property does not have the
|
||||
attribute DontDelete
|
||||
es5id: 15.2.4.6_A9
|
||||
description: >
|
||||
Checking deleting the Object.prototype.isPrototypeOf.length
|
||||
property fails
|
||||
---*/
|
||||
|
||||
//CHECK#0
|
||||
if (!(Object.prototype.isPrototypeOf.hasOwnProperty('length'))) {
|
||||
$ERROR('#0: the Object.prototype.isPrototypeOf has length property');
|
||||
}
|
||||
|
||||
//CHECK#1
|
||||
if (!delete Object.prototype.isPrototypeOf.length) {
|
||||
$ERROR('#1: The Object.prototype.isPrototypeOf.length property does not have the attributes DontDelete');
|
||||
}
|
||||
//
|
29
test/built-ins/Object/prototype/isPrototypeOf/arg-is-proxy.js
vendored
Normal file
29
test/built-ins/Object/prototype/isPrototypeOf/arg-is-proxy.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2019 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.prototype.isprototypeof
|
||||
description: >
|
||||
If V is a Proxy object, only its "getPrototypeOf" trap gets invoked.
|
||||
info: |
|
||||
Object.prototype.isPrototypeOf ( V )
|
||||
|
||||
...
|
||||
3. Repeat,
|
||||
a. Set V to ? V.[[GetPrototypeOf]]().
|
||||
b. If V is null, return false.
|
||||
c. If SameValue(O, V) is true, return true.
|
||||
includes: [proxyTrapsHelper.js]
|
||||
features: [Proxy]
|
||||
---*/
|
||||
|
||||
var proxyProto = [];
|
||||
var handler = allowProxyTraps({
|
||||
getPrototypeOf: function(_target) {
|
||||
return proxyProto;
|
||||
},
|
||||
});
|
||||
|
||||
var proxy = new Proxy({}, handler);
|
||||
|
||||
assert.sameValue(proxyProto.isPrototypeOf(proxy), true);
|
18
test/built-ins/Object/prototype/isPrototypeOf/builtin.js
vendored
Normal file
18
test/built-ins/Object/prototype/isPrototypeOf/builtin.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.prototype.isprototypeof
|
||||
description: >
|
||||
Tests that Object.prototype.isPrototypeOf meets the requirements
|
||||
for built-in objects defined by the introduction of chapter 17 of
|
||||
the ECMAScript Language Specification.
|
||||
includes: [isConstructor.js]
|
||||
features: [Reflect.construct]
|
||||
---*/
|
||||
|
||||
assert(Object.isExtensible(Object.prototype.isPrototypeOf));
|
||||
assert.sameValue(Object.prototype.toString.call(Object.prototype.isPrototypeOf), "[object Function]");
|
||||
assert.sameValue(Object.getPrototypeOf(Object.prototype.isPrototypeOf), Function.prototype);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.hasOwnProperty("prototype"), false);
|
||||
assert.sameValue(isConstructor(Object.prototype.isPrototypeOf), false);
|
24
test/built-ins/Object/prototype/isPrototypeOf/length.js
vendored
Normal file
24
test/built-ins/Object/prototype/isPrototypeOf/length.js
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.prototype.isprototypeof
|
||||
description: >
|
||||
Object.prototype.isPrototypeOf.length is 1.
|
||||
info: |
|
||||
Object.prototype.isPrototypeOf ( V )
|
||||
|
||||
ECMAScript Standard Built-in Objects
|
||||
|
||||
Unless otherwise specified, the length property of a built-in Function
|
||||
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||
[[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
verifyProperty(Object.prototype.isPrototypeOf, "length", {
|
||||
value: 1,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
@ -2,7 +2,7 @@
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 19.1.3.3
|
||||
esid: sec-object.prototype.isprototypeof
|
||||
description: >
|
||||
Object.prototype.isPrototypeOf.name is "isPrototypeOf".
|
||||
info: |
|
||||
@ -19,8 +19,9 @@ info: |
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.name, "isPrototypeOf");
|
||||
|
||||
verifyNotEnumerable(Object.prototype.isPrototypeOf, "name");
|
||||
verifyNotWritable(Object.prototype.isPrototypeOf, "name");
|
||||
verifyConfigurable(Object.prototype.isPrototypeOf, "name");
|
||||
verifyProperty(Object.prototype.isPrototypeOf, "name", {
|
||||
value: "isPrototypeOf",
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
||||
|
19
test/built-ins/Object/prototype/isPrototypeOf/null-this-and-object-arg-throws.js
vendored
Normal file
19
test/built-ins/Object/prototype/isPrototypeOf/null-this-and-object-arg-throws.js
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2011 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.prototype.isprototypeof
|
||||
description: >
|
||||
The ordering of steps 1 and 2 preserves the behaviour specified by previous
|
||||
editions of this specification for the case where V is not an object and
|
||||
the this value is undefined or null.
|
||||
info: |
|
||||
Object.prototype.isPrototypeOf ( V )
|
||||
|
||||
1. If Type(V) is not Object, return false.
|
||||
2. Let O be ? ToObject(this value).
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.prototype.isPrototypeOf.call(null, function() {});
|
||||
});
|
23
test/built-ins/Object/prototype/isPrototypeOf/null-this-and-primitive-arg-returns-false.js
vendored
Normal file
23
test/built-ins/Object/prototype/isPrototypeOf/null-this-and-primitive-arg-returns-false.js
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2019 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.prototype.isprototypeof
|
||||
description: >
|
||||
The ordering of steps 1 and 2 preserves the behaviour specified by previous
|
||||
editions of this specification for the case where V is not an object and
|
||||
the this value is undefined or null.
|
||||
info: |
|
||||
Object.prototype.isPrototypeOf ( V )
|
||||
|
||||
1. If Type(V) is not Object, return false.
|
||||
2. Let O be ? ToObject(this value).
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(null, undefined), false);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(null, null), false);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(null, false), false);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(null, ""), false);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(null, Symbol()), false);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(null, 10), false);
|
42
test/built-ins/Object/prototype/isPrototypeOf/this-value-is-in-prototype-chain-of-arg.js
vendored
Normal file
42
test/built-ins/Object/prototype/isPrototypeOf/this-value-is-in-prototype-chain-of-arg.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.prototype.isprototypeof
|
||||
description: >
|
||||
Object.prototype.isPrototypeOf returns true if either parameter V
|
||||
and O refer to the same object or O is in [[Prototype]] chain of V.
|
||||
info: |
|
||||
Object.prototype.isPrototypeOf ( V )
|
||||
|
||||
...
|
||||
3. Repeat,
|
||||
a. Set V to ? V.[[GetPrototypeOf]]().
|
||||
b. If V is null, return false.
|
||||
c. If SameValue(O, V) is true, return true.
|
||||
---*/
|
||||
|
||||
function USER_FACTORY(name) {
|
||||
this.name = name;
|
||||
this.getName = function() {
|
||||
return name;
|
||||
};
|
||||
}
|
||||
|
||||
function FORCEDUSER_FACTORY(name, grade) {
|
||||
this.name = name;
|
||||
this.grade = grade;
|
||||
this.getGrade = function() {
|
||||
return grade;
|
||||
};
|
||||
}
|
||||
|
||||
var proto = new USER_FACTORY("noname");
|
||||
|
||||
FORCEDUSER_FACTORY.prototype = proto;
|
||||
|
||||
var luke = new FORCEDUSER_FACTORY("Luke Skywalker", 12);
|
||||
|
||||
assert.sameValue(proto.isPrototypeOf(luke), true);
|
||||
assert.sameValue(USER_FACTORY.prototype.isPrototypeOf(luke), true);
|
||||
assert.sameValue(Number.isPrototypeOf(luke), false);
|
19
test/built-ins/Object/prototype/isPrototypeOf/undefined-this-and-object-arg-throws.js
vendored
Normal file
19
test/built-ins/Object/prototype/isPrototypeOf/undefined-this-and-object-arg-throws.js
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2011 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.prototype.isprototypeof
|
||||
description: >
|
||||
The ordering of steps 1 and 2 preserves the behaviour specified by previous
|
||||
editions of this specification for the case where V is not an object and
|
||||
the this value is undefined or null.
|
||||
info: |
|
||||
Object.prototype.isPrototypeOf ( V )
|
||||
|
||||
1. If Type(V) is not Object, return false.
|
||||
2. Let O be ? ToObject(this value).
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.prototype.isPrototypeOf.call(undefined, {});
|
||||
});
|
23
test/built-ins/Object/prototype/isPrototypeOf/undefined-this-and-primitive-arg-returns-false.js
vendored
Normal file
23
test/built-ins/Object/prototype/isPrototypeOf/undefined-this-and-primitive-arg-returns-false.js
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2019 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.prototype.isprototypeof
|
||||
description: >
|
||||
The ordering of steps 1 and 2 preserves the behaviour specified by previous
|
||||
editions of this specification for the case where V is not an object and
|
||||
the this value is undefined or null.
|
||||
info: |
|
||||
Object.prototype.isPrototypeOf ( V )
|
||||
|
||||
1. If Type(V) is not Object, return false.
|
||||
2. Let O be ? ToObject(this value).
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(undefined, undefined), false);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(undefined, null), false);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(undefined, true), false);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(undefined, "str"), false);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(undefined, Symbol("desc")), false);
|
||||
assert.sameValue(Object.prototype.isPrototypeOf.call(undefined, 3.14), false);
|
Loading…
x
Reference in New Issue
Block a user