From d8f1b92cf47c3a8ba082b813ade2e3c7efc7af37 Mon Sep 17 00:00:00 2001 From: jugglinmike Date: Mon, 16 May 2016 13:53:43 -0400 Subject: [PATCH] Add tests for Annex B extn: O.p.__proto__ (#625) --- .../Object/prototype/__proto__/get-abrupt.js | 22 ++++++++++++ .../{B.2.2.1.1.js => get-fn-name.js} | 0 .../prototype/__proto__/get-ordinary-obj.js | 19 ++++++++++ .../prototype/__proto__/get-to-obj-abrupt.js | 21 +++++++++++ .../Object/prototype/__proto__/prop-desc.js | 21 +++++++++++ .../Object/prototype/__proto__/set-abrupt.js | 22 ++++++++++++ .../prototype/__proto__/set-cycle-shadowed.js | 34 ++++++++++++++++++ .../Object/prototype/__proto__/set-cycle.js | 34 ++++++++++++++++++ .../{B.2.2.1.2.js => set-fn-name.js} | 0 .../prototype/__proto__/set-immutable.js | 18 ++++++++++ .../prototype/__proto__/set-invalid-value.js | 35 +++++++++++++++++++ .../prototype/__proto__/set-non-extensible.js | 32 +++++++++++++++++ .../__proto__/set-non-obj-coercible.js | 21 +++++++++++ .../prototype/__proto__/set-non-object.js | 19 ++++++++++ .../prototype/__proto__/set-ordinary-obj.js | 19 ++++++++++ 15 files changed, 317 insertions(+) create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/get-abrupt.js rename test/annexB/built-ins/Object/prototype/__proto__/{B.2.2.1.1.js => get-fn-name.js} (100%) create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/get-ordinary-obj.js create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/get-to-obj-abrupt.js create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/prop-desc.js create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/set-abrupt.js create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/set-cycle-shadowed.js create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/set-cycle.js rename test/annexB/built-ins/Object/prototype/__proto__/{B.2.2.1.2.js => set-fn-name.js} (100%) create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/set-immutable.js create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/set-invalid-value.js create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/set-non-extensible.js create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/set-non-obj-coercible.js create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/set-non-object.js create mode 100644 test/annexB/built-ins/Object/prototype/__proto__/set-ordinary-obj.js diff --git a/test/annexB/built-ins/Object/prototype/__proto__/get-abrupt.js b/test/annexB/built-ins/Object/prototype/__proto__/get-abrupt.js new file mode 100644 index 0000000000..5cba28f080 --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/get-abrupt.js @@ -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); +}); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/B.2.2.1.1.js b/test/annexB/built-ins/Object/prototype/__proto__/get-fn-name.js similarity index 100% rename from test/annexB/built-ins/Object/prototype/__proto__/B.2.2.1.1.js rename to test/annexB/built-ins/Object/prototype/__proto__/get-fn-name.js diff --git a/test/annexB/built-ins/Object/prototype/__proto__/get-ordinary-obj.js b/test/annexB/built-ins/Object/prototype/__proto__/get-ordinary-obj.js new file mode 100644 index 0000000000..027f0ce576 --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/get-ordinary-obj.js @@ -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'); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/get-to-obj-abrupt.js b/test/annexB/built-ins/Object/prototype/__proto__/get-to-obj-abrupt.js new file mode 100644 index 0000000000..94d81de5cc --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/get-to-obj-abrupt.js @@ -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); +}); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/prop-desc.js b/test/annexB/built-ins/Object/prototype/__proto__/prop-desc.js new file mode 100644 index 0000000000..543d6da7d0 --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/prop-desc.js @@ -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'); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/set-abrupt.js b/test/annexB/built-ins/Object/prototype/__proto__/set-abrupt.js new file mode 100644 index 0000000000..c4ba596cac --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/set-abrupt.js @@ -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); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/set-cycle-shadowed.js b/test/annexB/built-ins/Object/prototype/__proto__/set-cycle-shadowed.js new file mode 100644 index 0000000000..f8fed8d11c --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/set-cycle-shadowed.js @@ -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); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/set-cycle.js b/test/annexB/built-ins/Object/prototype/__proto__/set-cycle.js new file mode 100644 index 0000000000..8a35eac3af --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/set-cycle.js @@ -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); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/B.2.2.1.2.js b/test/annexB/built-ins/Object/prototype/__proto__/set-fn-name.js similarity index 100% rename from test/annexB/built-ins/Object/prototype/__proto__/B.2.2.1.2.js rename to test/annexB/built-ins/Object/prototype/__proto__/set-fn-name.js diff --git a/test/annexB/built-ins/Object/prototype/__proto__/set-immutable.js b/test/annexB/built-ins/Object/prototype/__proto__/set-immutable.js new file mode 100644 index 0000000000..2b1819087d --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/set-immutable.js @@ -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); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/set-invalid-value.js b/test/annexB/built-ins/Object/prototype/__proto__/set-invalid-value.js new file mode 100644 index 0000000000..f650702c2c --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/set-invalid-value.js @@ -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' +); + diff --git a/test/annexB/built-ins/Object/prototype/__proto__/set-non-extensible.js b/test/annexB/built-ins/Object/prototype/__proto__/set-non-extensible.js new file mode 100644 index 0000000000..857f175ad0 --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/set-non-extensible.js @@ -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); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/set-non-obj-coercible.js b/test/annexB/built-ins/Object/prototype/__proto__/set-non-obj-coercible.js new file mode 100644 index 0000000000..665f73e96c --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/set-non-obj-coercible.js @@ -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); +}); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/set-non-object.js b/test/annexB/built-ins/Object/prototype/__proto__/set-non-object.js new file mode 100644 index 0000000000..d30e5f55ae --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/set-non-object.js @@ -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'); diff --git a/test/annexB/built-ins/Object/prototype/__proto__/set-ordinary-obj.js b/test/annexB/built-ins/Object/prototype/__proto__/set-ordinary-obj.js new file mode 100644 index 0000000000..76d01300d4 --- /dev/null +++ b/test/annexB/built-ins/Object/prototype/__proto__/set-ordinary-obj.js @@ -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);