mirror of https://github.com/tc39/test262.git
Add tests for Annex B extn: O.p.__proto__ (#625)
This commit is contained in:
parent
cb40133425
commit
d8f1b92cf4
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: Abrupt completion from [[GetPrototypeOf]]
|
||||
info: >
|
||||
1. Let O be ? ToObject(this value).
|
||||
2. Return ? O.[[GetPrototypeOf]]().
|
||||
features: [Proxy]
|
||||
---*/
|
||||
|
||||
var get = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').get;
|
||||
var thrower = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
|
||||
var subject = new Proxy({}, { getPrototypeOf: thrower });
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
get.call(subject);
|
||||
});
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: Normal completion from ordinary object's [[GetPrototypeOf]]
|
||||
info: >
|
||||
1. Let O be ? ToObject(this value).
|
||||
2. Return ? O.[[GetPrototypeOf]]().
|
||||
---*/
|
||||
|
||||
var get = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').get;
|
||||
var proto = {};
|
||||
var withCustomProto = Object.create(proto);
|
||||
var withNullProto = Object.create(null);
|
||||
|
||||
assert.sameValue(get.call({}), Object.prototype, 'Ordinary object');
|
||||
assert.sameValue(get.call(withCustomProto), proto, 'custom prototype object');
|
||||
assert.sameValue(get.call(withNullProto), null, 'null prototype');
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: Abrupt completion from ToObject
|
||||
info: >
|
||||
1. Let O be ? ToObject(this value).
|
||||
---*/
|
||||
|
||||
var get = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').get;
|
||||
|
||||
assert.sameValue(typeof get, 'function');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
get.call(undefined);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
get.call(null);
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-additional-properties-of-the-object.prototype-object
|
||||
es6id: B.2.2.1.2
|
||||
description: Property descriptor for Object.prototype.__proto__
|
||||
info: >
|
||||
Object.prototype.__proto__ is an accessor property with attributes {
|
||||
[[Enumerable]]: false, [[Configurable]]: true }. The [[Get]] and [[Set]]
|
||||
attributes are defined as follows:
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__');
|
||||
|
||||
verifyNotEnumerable(Object.prototype, '__proto__');
|
||||
verifyConfigurable(Object.prototype, '__proto__');
|
||||
|
||||
assert.sameValue(desc.value, undefined, '`value` property');
|
||||
assert.sameValue(typeof desc.get, 'function', '`get` property');
|
||||
assert.sameValue(typeof desc.set, 'function', '`set` property');
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: Abrupt completion from [[SetPrototypeOf]]
|
||||
info: >
|
||||
[...]
|
||||
4. Let status be ? O.[[SetPrototypeOf]](proto).
|
||||
features: [Proxy]
|
||||
---*/
|
||||
|
||||
var thrower = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
var subject = new Proxy({}, { setPrototypeOf: thrower });
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
subject.__proto__ = {};
|
||||
});
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(subject), Object.prototype);
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: >
|
||||
Cycles are not detected when a Proxy exotic object exists in the prototype
|
||||
chain
|
||||
info: >
|
||||
[...]
|
||||
4. Let status be ? O.[[SetPrototypeOf]](proto).
|
||||
5. If status is false, throw a TypeError exception.
|
||||
|
||||
9.1.2.1 OrdinarySetPrototypeOf
|
||||
|
||||
[...]
|
||||
6. Let p be V.
|
||||
7. Let done be false.
|
||||
8. Repeat while done is false,
|
||||
a. If p is null, let done be true.
|
||||
b. Else if SameValue(p, O) is true, return false.
|
||||
c. Else,
|
||||
i. If the [[GetPrototypeOf]] internal method of p is not the ordinary
|
||||
object internal method defined in 9.1.1, let done be true.
|
||||
ii. Else, let p be the value of p's [[Prototype]] internal slot.
|
||||
---*/
|
||||
|
||||
var root = {};
|
||||
var intermediary = new Proxy(Object.create(root), {});
|
||||
var leaf = Object.create(intermediary);
|
||||
|
||||
root.__proto__ = leaf;
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(root), leaf);
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: Cycle detection
|
||||
info: >
|
||||
[...]
|
||||
4. Let status be ? O.[[SetPrototypeOf]](proto).
|
||||
5. If status is false, throw a TypeError exception.
|
||||
|
||||
9.1.2.1 OrdinarySetPrototypeOf
|
||||
|
||||
[...]
|
||||
6. Let p be V.
|
||||
7. Let done be false.
|
||||
8. Repeat while done is false,
|
||||
a. If p is null, let done be true.
|
||||
b. Else if SameValue(p, O) is true, return false.
|
||||
c. Else,
|
||||
i. If the [[GetPrototypeOf]] internal method of p is not the ordinary
|
||||
object internal method defined in 9.1.1, let done be true.
|
||||
ii. Else, let p be the value of p's [[Prototype]] internal slot.
|
||||
---*/
|
||||
|
||||
var root = {};
|
||||
var intermediary = Object.create(root);
|
||||
var leaf = Object.create(intermediary);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
root.__proto__ = leaf;
|
||||
});
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(root), Object.prototype);
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
description: Called on an immutable prototype exotic object
|
||||
info: >
|
||||
[...]
|
||||
4. Let status be ? O.[[SetPrototypeOf]](proto).
|
||||
5. If status is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
Object.prototype.__proto__ = null;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.prototype.__proto__ = {};
|
||||
});
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(Object.prototype), null);
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: Called with a value that is neither an Object nor Null
|
||||
info: >
|
||||
1. Let O be ? RequireObjectCoercible(this value).
|
||||
2. If Type(proto) is neither Object nor Null, return undefined.
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var set = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
|
||||
var subject = {};
|
||||
|
||||
assert.sameValue(set.call(subject, true), undefined, 'boolean');
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(subject), Object.prototype, 'following boolean'
|
||||
);
|
||||
|
||||
assert.sameValue(set.call(subject, 1), undefined, 'number');
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(subject), Object.prototype, 'following number'
|
||||
);
|
||||
|
||||
assert.sameValue(set.call(subject, 'string'), undefined, 'string');
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(subject), Object.prototype, 'following string'
|
||||
);
|
||||
|
||||
assert.sameValue(set.call(subject, Symbol('')), undefined, 'symbol');
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(subject), Object.prototype, 'following symbol'
|
||||
);
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: Called on an non-extensible object
|
||||
info: >
|
||||
[...]
|
||||
4. Let status be ? O.[[SetPrototypeOf]](proto).
|
||||
5. If status is false, throw a TypeError exception.
|
||||
|
||||
9.1.2.1 OrdinarySetPrototypeOf
|
||||
|
||||
[...]
|
||||
2. Let extensible be the value of the [[Extensible]] internal slot of O.
|
||||
3. Let current be the value of the [[Prototype]] internal slot of O.
|
||||
4. If SameValue(V, current) is true, return true.
|
||||
5. If extensible is false, return false.
|
||||
---*/
|
||||
|
||||
var proto = {};
|
||||
var subject = Object.create(proto);
|
||||
|
||||
Object.preventExtensions(subject);
|
||||
|
||||
subject.__proto__ = proto;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
subject.__proto__ = {};
|
||||
});
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(subject), proto);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: Called on a value that is not object-coercible
|
||||
info: >
|
||||
1. Let O be ? RequireObjectCoercible(this value).
|
||||
---*/
|
||||
|
||||
var set = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
|
||||
|
||||
assert.sameValue(typeof set, 'function');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
set.call(undefined);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
set.call(null);
|
||||
});
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: Called on a value that is object-coercible but not an Object
|
||||
info: >
|
||||
1. Let O be ? RequireObjectCoercible(this value).
|
||||
2. If Type(proto) is neither Object nor Null, return undefined.
|
||||
3. If Type(O) is not Object, return undefined.
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var set = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
|
||||
|
||||
assert.sameValue(set.call(true), undefined, 'boolean');
|
||||
assert.sameValue(set.call(1), undefined, 'number');
|
||||
assert.sameValue(set.call('string'), undefined, 'string');
|
||||
assert.sameValue(set.call(Symbol('')), undefined, 'symbol');
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-object.prototype.__proto__
|
||||
es6id: B.2.2.1
|
||||
description: Setting valid value on an ordinary object
|
||||
info: >
|
||||
[...]
|
||||
4. Let status be ? O.[[SetPrototypeOf]](proto).
|
||||
5. If status is false, throw a TypeError exception.
|
||||
6. Return undefined.
|
||||
---*/
|
||||
|
||||
var set = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
|
||||
var proto = {};
|
||||
var subject = {};
|
||||
|
||||
assert.sameValue(set.call(subject, proto), undefined);
|
||||
assert.sameValue(Object.getPrototypeOf(subject), proto);
|
Loading…
Reference in New Issue