diff options
Diffstat (limited to '')
13 files changed, 327 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/browser.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/browser.js diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-abrupt.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-abrupt.js new file mode 100644 index 0000000000..b47387ea73 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-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-additional-properties-of-the-object.prototype-object +description: Behavior when [[DefineOwnProperty]] returns an abrupt completion +info: | + [...] + 5. Perform ? DefinePropertyOrThrow(O, key, desc). +features: [Proxy, __getter__] +---*/ + +var noop = function() {}; +var thrower = function() { + throw new Test262Error(); +}; +var subject = new Proxy({}, { defineProperty: thrower }); + +assert.throws(Test262Error, function() { + subject.__defineGetter__('attr', noop); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-existing.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-existing.js new file mode 100644 index 0000000000..d23ffa10fe --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-existing.js @@ -0,0 +1,45 @@ +// 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 +description: Behavior when property exists and is configurable +info: | + [...] + 3. Let desc be PropertyDescriptor{[[Get]]: getter, [[Enumerable]]: true, + [[Configurable]]: true}. + 4. Let key be ? ToPropertyKey(P). + 5. Perform ? DefinePropertyOrThrow(O, key, desc). + 6. Return undefined. +includes: [propertyHelper.js] +features: [__getter__] +---*/ + +var subject = {}; +var originalGet = function() {}; +var originalSet = function() {}; +var newGet = function() {}; +var desc, result; + +Object.defineProperty(subject, 'stringAcsr', { + get: originalGet, + set: originalSet, + enumerable: false, + configurable: true +}); + +result = subject.__defineGetter__('stringAcsr', newGet); + +desc = Object.getOwnPropertyDescriptor(subject, 'stringAcsr'); + +verifyProperty(subject, "stringAcsr", { + enumerable: true, + configurable: true +}); + +assert.sameValue(desc.get, newGet, 'descriptor `get` method'); +assert.sameValue(desc.set, originalSet, 'descriptor `set` method'); +assert.sameValue(desc.value, undefined, 'descriptor `value` property'); + +assert.sameValue(result, undefined, 'method return value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-new.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-new.js new file mode 100644 index 0000000000..cdb4acc11e --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-new.js @@ -0,0 +1,36 @@ +// 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 +description: Behavior when property does not exist +info: | + [...] + 3. Let desc be PropertyDescriptor{[[Get]]: getter, [[Enumerable]]: true, + [[Configurable]]: true}. + 4. Let key be ? ToPropertyKey(P). + 5. Perform ? DefinePropertyOrThrow(O, key, desc). + 6. Return undefined. +includes: [propertyHelper.js] +features: [__getter__] +---*/ + +var subject = {}; +var get = function() {}; +var desc, result; + +result = subject.__defineGetter__('stringAcsr', get); + +desc = Object.getOwnPropertyDescriptor(subject, 'stringAcsr'); + +verifyProperty(subject, "stringAcsr", { + enumerable: true, + configurable: true +}); + +assert.sameValue(desc.get, get, 'descriptor `get` method'); +assert.sameValue(desc.set, undefined, 'descriptor `set` method'); +assert.sameValue(desc.value, undefined, 'descriptor `value` property'); + +assert.sameValue(result, undefined, 'method return value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-non-configurable.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-non-configurable.js new file mode 100644 index 0000000000..fbb5e0e0a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-non-configurable.js @@ -0,0 +1,23 @@ +// 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 +description: Behavior when property exists and is not configurable +info: | + [...] + 5. Perform ? DefinePropertyOrThrow(O, key, desc). +features: [__getter__] +---*/ + +var noop = function() {}; +var subject = Object.defineProperty( + {}, 'attr', { value: 1, configurable: false } +); + +assert.sameValue(typeof Object.prototype.__defineGetter__, 'function'); + +assert.throws(TypeError, function() { + subject.__defineGetter__('attr', noop); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-non-extensible.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-non-extensible.js new file mode 100644 index 0000000000..5cb7cb6ce2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/define-non-extensible.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 +description: Behavior when "this" value is not extensible +info: | + [...] + 5. Perform ? DefinePropertyOrThrow(O, key, desc). +features: [__getter__] +---*/ + +var noop = function() {}; +var subject = Object.preventExtensions({ existing: null }); + +subject.__defineGetter__('existing', noop); + +assert.throws(TypeError, function() { + subject.__defineGetter__('brand new', noop); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/getter-non-callable.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/getter-non-callable.js new file mode 100644 index 0000000000..c157c16ab6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/getter-non-callable.js @@ -0,0 +1,45 @@ +// 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 +description: Behavior when getter is not callable +info: | + [...] + 2. If IsCallable(getter) is false, throw a TypeError exception. +features: [Symbol, __getter__] +---*/ + +var subject = {}; +var symbol = Symbol(''); +var toStringCount = 0; +var key = { + toString: function() { + toStringCount += 1; + } +}; + +assert.sameValue(typeof Object.prototype.__defineGetter__, 'function'); + +assert.throws(TypeError, function() { + subject.__defineGetter__(key, ''); +}, 'string'); + +assert.throws(TypeError, function() { + subject.__defineGetter__(key, 23); +}, 'number'); + +assert.throws(TypeError, function() { + subject.__defineGetter__(key, true); +}, 'boolean'); + +assert.throws(TypeError, function() { + subject.__defineGetter__(key, symbol); +}, 'symbol'); + +assert.throws(TypeError, function() { + subject.__defineGetter__(key, {}); +}, 'object'); + +assert.sameValue(toStringCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/key-invalid.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/key-invalid.js new file mode 100644 index 0000000000..7f33e87995 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/key-invalid.js @@ -0,0 +1,24 @@ +// 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 +description: Behavior when property key cannot be derived +info: | + [...] + 4. Let key be ? ToPropertyKey(P). +features: [__getter__] +---*/ + +var noop = function() {}; +var subject = {}; +var key = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + subject.__defineGetter__(key, noop); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/length.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/length.js new file mode 100644 index 0000000000..ef93522cfd --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/length.js @@ -0,0 +1,29 @@ +// 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 +description: Object.prototype.__defineGetter__ `length` property +info: | + ES6 Section 17: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + + [...] + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [__getter__] +---*/ + +verifyProperty(Object.prototype.__defineGetter__, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 2 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/name.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/name.js new file mode 100644 index 0000000000..555dd53a28 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/name.js @@ -0,0 +1,30 @@ +// 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 +description: Object.prototype.__defineGetter__ `name` property +info: | + ES6 Section 17: + + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. Unless otherwise specified, this value is the name that is given to + the function in this specification. + + [...] + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [__getter__] +---*/ + +verifyProperty(Object.prototype.__defineGetter__, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "__defineGetter__" +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/prop-desc.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/prop-desc.js new file mode 100644 index 0000000000..0d383509df --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/prop-desc.js @@ -0,0 +1,20 @@ +// 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 +description: Property descriptor for Object.prototype.__defineGetter__ +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [__getter__] +---*/ + +verifyProperty(Object.prototype, "__defineGetter__", { + enumerable: false, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/shell.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/shell.js diff --git a/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/this-non-obj.js b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/this-non-obj.js new file mode 100644 index 0000000000..1629696292 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/prototype/__defineGetter__/this-non-obj.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-additional-properties-of-the-object.prototype-object +description: Behavior when "this" value is not Object-coercible +info: | + 1. Let O be ? ToObject(this value). +features: [__getter__] +---*/ + +var __defineGetter__ = Object.prototype.__defineGetter__; +var noop = function() {}; +var toStringCount = 0; +var key = { + toString: function() { + toStringCount += 1; + } +}; + +assert.sameValue(typeof __defineGetter__, 'function'); + +assert.throws(TypeError, function() { + __defineGetter__.call(undefined, key, noop); +}, 'undefined'); + +assert.throws(TypeError, function() { + __defineGetter__.call(null, key, noop); +}, 'null'); + +assert.sameValue(toStringCount, 0); + +reportCompare(0, 0); |