diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/built-ins/Reflect/defineProperty | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Reflect/defineProperty')
14 files changed, 396 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/browser.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/browser.js diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/define-properties.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/define-properties.js new file mode 100644 index 0000000000..70db2bfc03 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/define-properties.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Define properties from the attributes object. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 6. Return target.[[DefineOwnProperty]](key, desc). +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +var o = {}; +var desc; + +Reflect.defineProperty(o, 'p1', { + value: 42, + writable: true, + enumerable: true +}); + +assert.sameValue(o.p1, 42); + +verifyWritable(o, 'p1'); +verifyNotConfigurable(o, 'p1'); +verifyEnumerable(o, 'p1'); + +var f1 = function() {}; +var f2 = function() {}; +Reflect.defineProperty(o, 'p2', { + get: f1, + set: f2 +}); + +desc = Object.getOwnPropertyDescriptor(o, 'p2'); +assert.sameValue(desc.get, f1); +assert.sameValue(desc.set, f2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/define-symbol-properties.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/define-symbol-properties.js new file mode 100644 index 0000000000..06ce6e3145 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/define-symbol-properties.js @@ -0,0 +1,55 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Define symbol properties. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + ... + + 7.1.14 ToPropertyKey ( argument ) + + ... + 3. If Type(key) is Symbol, then + a. Return key. + ... +features: [Reflect, Symbol] +---*/ + +var o = {}; +var desc; + +var s1 = Symbol('1'); + +Reflect.defineProperty(o, s1, { + value: 42, + writable: true, + enumerable: true +}); + +assert.sameValue(o[s1], 42); + +desc = Object.getOwnPropertyDescriptor(o, s1); + +assert.sameValue(desc.writable, true); +assert.sameValue(desc.configurable, false); +assert.sameValue(desc.enumerable, true); + +var s2 = Symbol('2'); + +var f1 = function() {}; +var f2 = function() {}; +Reflect.defineProperty(o, s2, { + get: f1, + set: f2 +}); + +desc = Object.getOwnPropertyDescriptor(o, s2); +assert.sameValue(desc.get, f1); +assert.sameValue(desc.set, f2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/defineProperty.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/defineProperty.js new file mode 100644 index 0000000000..ddcd54b03a --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/defineProperty.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Reflect.defineProperty is configurable, writable and not enumerable. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +verifyNotEnumerable(Reflect, 'defineProperty'); +verifyWritable(Reflect, 'defineProperty'); +verifyConfigurable(Reflect, 'defineProperty'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/length.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/length.js new file mode 100644 index 0000000000..2b5b742918 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/length.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Reflect.defineProperty.length value and property descriptor +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.defineProperty.length, 3, + 'The value of `Reflect.defineProperty.length` is `3`' +); + +verifyNotEnumerable(Reflect.defineProperty, 'length'); +verifyNotWritable(Reflect.defineProperty, 'length'); +verifyConfigurable(Reflect.defineProperty, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/name.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/name.js new file mode 100644 index 0000000000..5315b9d272 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/name.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Reflect.defineProperty.name value and property descriptor +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [Reflect] +---*/ + +assert.sameValue( + Reflect.defineProperty.name, 'defineProperty', + 'The value of `Reflect.defineProperty.name` is `"defineProperty"`' +); + +verifyNotEnumerable(Reflect.defineProperty, 'name'); +verifyNotWritable(Reflect.defineProperty, 'name'); +verifyConfigurable(Reflect.defineProperty, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/not-a-constructor.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/not-a-constructor.js new file mode 100644 index 0000000000..c878ad4756 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Reflect.defineProperty does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Reflect, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Reflect.defineProperty), + false, + 'isConstructor(Reflect.defineProperty) must return false' +); + +assert.throws(TypeError, () => { + new Reflect.defineProperty({}, ''); +}, '`new Reflect.defineProperty({}, \'\')` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-attributes.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-attributes.js new file mode 100644 index 0000000000..0d7b06651a --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-attributes.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Return abrupt from ToPropertyDescriptor(attributes). +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 4. Let desc be ToPropertyDescriptor(attributes). + 5. ReturnIfAbrupt(desc). + ... +features: [Reflect] +---*/ + +var attributes = {}; + +Object.defineProperty(attributes, 'enumerable', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.defineProperty({}, 'a', attributes); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-property-key.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-property-key.js new file mode 100644 index 0000000000..445091d121 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-property-key.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Return abrupt from ToPropertyKey(propertyKey) +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 2. Let key be ToPropertyKey(propertyKey). + 3. ReturnIfAbrupt(key). + ... +features: [Reflect] +---*/ + +var p = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Reflect.defineProperty({}, p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-result.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-result.js new file mode 100644 index 0000000000..9e63455414 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-abrupt-from-result.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Return abrupt result on defining a property. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 6. Return target.[[DefineOwnProperty]](key, desc). + ... + + 9.1.6.1 OrdinaryDefineOwnProperty (O, P, Desc) + + 1. Let current be O.[[GetOwnProperty]](P). + 2. ReturnIfAbrupt(current). + ... +features: [Proxy, Reflect] +---*/ + +var o = {}; +var p = new Proxy(o, { + defineProperty: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.defineProperty(p, 'p1', {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/return-boolean.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-boolean.js new file mode 100644 index 0000000000..897788f299 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/return-boolean.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Return boolean result of the property definition. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + ... + 6. Return target.[[DefineOwnProperty]](key, desc). +features: [Reflect] +---*/ + +var o = {}; + +o.p1 = 'foo'; +assert.sameValue(Reflect.defineProperty(o, 'p1', {}), true); +assert.sameValue(o.hasOwnProperty('p1'), true); + +assert.sameValue(Reflect.defineProperty(o, 'p2', { + value: 42 +}), true); +assert.sameValue(o.hasOwnProperty('p2'), true); + +Object.freeze(o); + +assert.sameValue(Reflect.defineProperty(o, 'p2', { + value: 43 +}), false); +assert.sameValue(o.p2, 42); + +assert.sameValue(Reflect.defineProperty(o, 'p3', {}), false); +assert.sameValue(o.hasOwnProperty('p4'), false); + +assert.sameValue(Reflect.defineProperty(o, 'p4', { + value: 1 +}), false); +assert.sameValue(o.hasOwnProperty('p4'), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/shell.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/shell.js new file mode 100644 index 0000000000..54371b7789 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/shell.js @@ -0,0 +1,19 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +---*/ + +function isConstructor(f) { + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/target-is-not-object-throws.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/target-is-not-object-throws.js new file mode 100644 index 0000000000..37013cb696 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/target-is-not-object-throws.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Throws a TypeError if target is not an Object. +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Reflect.defineProperty(1, 'p', {}); +}); + +assert.throws(TypeError, function() { + Reflect.defineProperty(null, 'p', {}); +}); + +assert.throws(TypeError, function() { + Reflect.defineProperty(undefined, 'p', {}); +}); + +assert.throws(TypeError, function() { + Reflect.defineProperty('', 'p', {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Reflect/defineProperty/target-is-symbol-throws.js b/js/src/tests/test262/built-ins/Reflect/defineProperty/target-is-symbol-throws.js new file mode 100644 index 0000000000..1cf53974d1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Reflect/defineProperty/target-is-symbol-throws.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.3 +description: > + Throws a TypeError if target is a Symbol +info: | + 26.1.3 Reflect.defineProperty ( target, propertyKey, attributes ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Reflect, Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.defineProperty(Symbol(1), 'p', {}); +}); + +reportCompare(0, 0); |