diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Object/assign | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Object/assign')
39 files changed, 1210 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Object/assign/ObjectOverride-sameproperty.js b/js/src/tests/test262/built-ins/Object/assign/ObjectOverride-sameproperty.js new file mode 100644 index 0000000000..81f0f531ac --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/ObjectOverride-sameproperty.js @@ -0,0 +1,22 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Object properties are assigned to target in ascending index order, + i.e. a later assignment to the same property overrides an earlier assignment. +es6id: 19.1.2.1 +---*/ + +var target = { + a: 1 +}; +var result = Object.assign(target, { + a: 2 +}, { + a: "c" +}); + +assert.sameValue(result.a, "c", "The value should be 'c'."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/OnlyOneArgument.js b/js/src/tests/test262/built-ins/Object/assign/OnlyOneArgument.js new file mode 100644 index 0000000000..3fe6d288f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/OnlyOneArgument.js @@ -0,0 +1,17 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + test Object.Assign(target,...sources),only one argument was passed, + return ToObject(target) +es6id: 19.1.2.1.3 +---*/ + +var target = "a"; +var result = Object.assign(target); + +assert.sameValue(typeof result, "object"); +assert.sameValue(result.valueOf(), "a", "The value should be 'a'."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Override-notstringtarget.js b/js/src/tests/test262/built-ins/Object/assign/Override-notstringtarget.js new file mode 100644 index 0000000000..2ade2ccbbd --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Override-notstringtarget.js @@ -0,0 +1,20 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Test override of Object.Assign(target,...sources), + Every string from sources will be wrapped to objects, and override from the first letter(result[0]) all the time +es6id: 19.1.2.1 +---*/ + +var target = 12; +var result = Object.assign(target, "aaa", "bb2b", "1c"); + +assert.sameValue(Object.getOwnPropertyNames(result).length, 4, "The length should be 4 in the final object."); +assert.sameValue(result[0], "1", "The value should be {\"0\":\"1\"}."); +assert.sameValue(result[1], "c", "The value should be {\"1\":\"c\"}."); +assert.sameValue(result[2], "2", "The value should be {\"2\":\"2\"}."); +assert.sameValue(result[3], "b", "The value should be {\"3\":\"b\"}."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Override.js b/js/src/tests/test262/built-ins/Object/assign/Override.js new file mode 100644 index 0000000000..af125dcca7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Override.js @@ -0,0 +1,37 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: Test Object.Assign(target,...sources). +esid: sec-object.assign +---*/ + +//"a" will be an property of the final object and the value should be 1 +var target = { + a: 1 +}; +/* +"1a2c3" have own enumerable properties, so it Should be wrapped to objects; +{b:6} is an object,should be assigned to final object. +undefined and null should be ignored; +125 is a number,it cannot has own enumerable properties; +{a:"c"},{a:5} will override property a, the value should be 5. +*/ +var result = Object.assign(target, "1a2c3", { + a: "c" +}, undefined, { + b: 6 +}, null, 125, { + a: 5 +}); + +assert.sameValue(Object.getOwnPropertyNames(result).length, 7, "The length should be 7 in the final object."); +assert.sameValue(result.a, 5, "The value should be {a:5}."); +assert.sameValue(result[0], "1", "The value should be {\"0\":\"1\"}."); +assert.sameValue(result[1], "a", "The value should be {\"1\":\"a\"}."); +assert.sameValue(result[2], "2", "The value should be {\"2\":\"2\"}."); +assert.sameValue(result[3], "c", "The value should be {\"3\":\"c\"}."); +assert.sameValue(result[4], "3", "The value should be {\"4\":\"3\"}."); +assert.sameValue(result.b, 6, "The value should be {b:6}."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Source-Null-Undefined.js b/js/src/tests/test262/built-ins/Object/assign/Source-Null-Undefined.js new file mode 100644 index 0000000000..b2f3a87750 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Source-Null-Undefined.js @@ -0,0 +1,14 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: null and undefined source should be ignored,result should be original object. +esid: sec-object.assign +---*/ + +var target = new Object(); +var result = Object.assign(target, undefined, null); + +assert.sameValue(result, target, 'The value of result is expected to equal the value of target'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Source-Number-Boolen-Symbol.js b/js/src/tests/test262/built-ins/Object/assign/Source-Number-Boolen-Symbol.js new file mode 100644 index 0000000000..60a851d5f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Source-Number-Boolen-Symbol.js @@ -0,0 +1,17 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Number,Boolean,Symbol cannot have own enumerable properties, + So cannot be Assigned.Here result should be original object. +esid: sec-object.assign +features: [Symbol] +---*/ + +var target = new Object(); +var result = Object.assign(target, 123, true, Symbol('foo')); + +assert.sameValue(result, target, 'The value of result is expected to equal the value of target'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Source-String.js b/js/src/tests/test262/built-ins/Object/assign/Source-String.js new file mode 100644 index 0000000000..d102c60f45 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Source-String.js @@ -0,0 +1,16 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: Test Object.Assign(target,...sources), string have own enumerable properties, so it can be wrapped to objects. +esid: sec-object.assign +---*/ + +var target = new Object(); +var result = Object.assign(target, "123"); + +assert.sameValue(result[0], "1", 'The value of result[0] is expected to be "1"'); +assert.sameValue(result[1], "2", 'The value of result[1] is expected to be "2"'); +assert.sameValue(result[2], "3", 'The value of result[2] is expected to be "3"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Target-Boolean.js b/js/src/tests/test262/built-ins/Object/assign/Target-Boolean.js new file mode 100644 index 0000000000..0f367bcf2d --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Target-Boolean.js @@ -0,0 +1,17 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Test the first argument(target) of Object.Assign(target,...sources), + if target is Boolean,the return value should be a new object whose value is target. +es6id: 19.1.2.1.1 +---*/ + +var result = Object.assign(true, { + a: 1 +}); +assert.sameValue(typeof result, "object", "Return value should be an object."); +assert.sameValue(result.valueOf(), true, "Return value should be true."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Target-Null.js b/js/src/tests/test262/built-ins/Object/assign/Target-Null.js new file mode 100644 index 0000000000..ffdd7fdabb --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Target-Null.js @@ -0,0 +1,17 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Test the first argument(target) of Object.Assign(target,...sources), + if target is null,Should Throw a TypeError exception. +es6id: 19.1.2.1.1 +---*/ + +assert.throws(TypeError, function() { + Object.assign(null, { + a: 1 + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Target-Number.js b/js/src/tests/test262/built-ins/Object/assign/Target-Number.js new file mode 100644 index 0000000000..bdda581c38 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Target-Number.js @@ -0,0 +1,17 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Test the first argument(target) of Object.Assign(target,...sources), + if target is Number,the return value should be a new object whose value is target. +es6id: 19.1.2.1.1 +---*/ + +var result = Object.assign(1, { + a: 1 +}); +assert.sameValue(typeof result, "object", "Return value should be an object."); +assert.sameValue(result.valueOf(), 1, "Return value should be 1."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Target-Object.js b/js/src/tests/test262/built-ins/Object/assign/Target-Object.js new file mode 100644 index 0000000000..f8e8a68404 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Target-Object.js @@ -0,0 +1,21 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Test the first argument(target) of Object.Assign(target,...sources), + if target is Object,its properties will be the properties of new object. +es6id: 19.1.2.1.1 +---*/ + +var target = { + foo: 1 +}; +var result = Object.assign(target, { + a: 2 +}); + +assert.sameValue(result.foo, 1, "The value should be {foo: 1}."); +assert.sameValue(result.a, 2, "The value should be {a: 2}."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Target-String.js b/js/src/tests/test262/built-ins/Object/assign/Target-String.js new file mode 100644 index 0000000000..aa16b4f2b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Target-String.js @@ -0,0 +1,17 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Test the first argument(target) of Object.Assign(target,...sources), + if target is String,the return value should be a new object whose value is target. +es6id: 19.1.2.1.1 +---*/ + +var result = Object.assign("test", { + a: 1 +}); +assert.sameValue(typeof result, "object", "Return value should be an object."); +assert.sameValue(result.valueOf(), "test", "Return value should be 'test'."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Target-Symbol.js b/js/src/tests/test262/built-ins/Object/assign/Target-Symbol.js new file mode 100644 index 0000000000..1430b4bd4f --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Target-Symbol.js @@ -0,0 +1,20 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Test the first argument(target) of Object.Assign(target,...sources), + if target is Symbol,the return value should be a new Symbol object whose [[SymbolData]] value is target. +es6id: 19.1.2.1.1 +features: [Symbol] +---*/ + +var target = Symbol('foo'); +var result = Object.assign(target, { + a: 1 +}); + +assert.sameValue(typeof result, "object", "Return value should be a symbol object."); +assert.sameValue(result.toString(), "Symbol(foo)", "Return value should be 'Symbol(foo)'."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/Target-Undefined.js b/js/src/tests/test262/built-ins/Object/assign/Target-Undefined.js new file mode 100644 index 0000000000..882c5b516b --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/Target-Undefined.js @@ -0,0 +1,17 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: > + Test the first argument(target) of Object.Assign(target,...sources), + if target is Undefined,Should Throw a TypeError exception. +es6id: 19.1.2.1.1 +---*/ + +assert.throws(TypeError, function() { + Object.assign(undefined, { + a: 1 + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/assign-descriptor.js b/js/src/tests/test262/built-ins/Object/assign/assign-descriptor.js new file mode 100644 index 0000000000..5ee1c8216e --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/assign-descriptor.js @@ -0,0 +1,14 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: Testing descriptor property of Object.assign +includes: [propertyHelper.js] +es6id: 19.1.2.1 +---*/ + +verifyWritable(Object, "assign"); +verifyNotEnumerable(Object, "assign"); +verifyConfigurable(Object, "assign"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/assign-length.js b/js/src/tests/test262/built-ins/Object/assign/assign-length.js new file mode 100644 index 0000000000..bcfe2e2eda --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/assign-length.js @@ -0,0 +1,26 @@ +// Copyright 2015 Microsoft Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +description: The length property of the assign method should be 2 +es6id: 19.1.2.1 +info: | + The length property of the assign method is 2. + + ES6 Section 17: + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Object.assign.length, 2, "The length property of the assign method should be 2." +); + +verifyNotEnumerable(Object.assign, 'length'); +verifyNotWritable(Object.assign, 'length'); +verifyConfigurable(Object.assign, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/assignment-to-readonly-property-of-target-must-throw-a-typeerror-exception.js b/js/src/tests/test262/built-ins/Object/assign/assignment-to-readonly-property-of-target-must-throw-a-typeerror-exception.js new file mode 100644 index 0000000000..d144ee5d49 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/assignment-to-readonly-property-of-target-must-throw-a-typeerror-exception.js @@ -0,0 +1,31 @@ +// Copyright 2020 Rick Waldron. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + Assignment to readonly property of target must throw a TypeError exception +info: | + Let to be ? ToObject(target). + If only one argument was passed, return to. + For each element nextSource of sources, do + If nextSource is neither undefined nor null, then + Let from be ! ToObject(nextSource). + Let keys be ? from.[[OwnPropertyKeys]](). + For each element nextKey of keys, do + Let desc be ? from.[[GetOwnProperty]](nextKey). + If desc is not undefined and desc.[[Enumerable]] is true, then + Let propValue be ? Get(from, nextKey). + Perform ? Set(to, nextKey, propValue, true). + + Set ( O, P, V, Throw ) sec-set-o-p-v-throw + + Let success be ? O.[[Set]](P, V, O). + If success is false and Throw is true, throw a TypeError exception. +---*/ + +assert.throws(TypeError, () => { + Object.assign('a', [1]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/browser.js b/js/src/tests/test262/built-ins/Object/assign/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/browser.js diff --git a/js/src/tests/test262/built-ins/Object/assign/invoked-as-ctor.js b/js/src/tests/test262/built-ins/Object/assign/invoked-as-ctor.js new file mode 100644 index 0000000000..e60b4ff645 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/invoked-as-ctor.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.1 +description: Invoked as a constructor +info: | + ES6 Section 9.3: + + 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. +---*/ + +assert.throws(TypeError, function() { + new Object.assign({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/name.js b/js/src/tests/test262/built-ins/Object/assign/name.js new file mode 100644 index 0000000000..bab32445c2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/name.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.1 +description: '`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] +---*/ + +assert.sameValue( + Object.assign.name, + 'assign', + 'The value of `Object.assign.name` is `"assign"`' +); + +verifyNotEnumerable(Object.assign, 'name'); +verifyNotWritable(Object.assign, 'name'); +verifyConfigurable(Object.assign, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/not-a-constructor.js b/js/src/tests/test262/built-ins/Object/assign/not-a-constructor.js new file mode 100644 index 0000000000..3c66a4c64a --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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: > + Object.assign 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, arrow-function] +---*/ + +assert.sameValue(isConstructor(Object.assign), false, 'isConstructor(Object.assign) must return false'); + +assert.throws(TypeError, () => { + new Object.assign({}); +}, '`new Object.assign({})` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/shell.js b/js/src/tests/test262/built-ins/Object/assign/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/shell.js diff --git a/js/src/tests/test262/built-ins/Object/assign/source-get-attr-error.js b/js/src/tests/test262/built-ins/Object/assign/source-get-attr-error.js new file mode 100644 index 0000000000..45dd48223d --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/source-get-attr-error.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: 19.1.2.1 +description: Errors thrown during retrieval of source object attributes +info: | + [...] + 5. For each element nextSource of sources, in ascending index order, + [...] + c. Repeat for each element nextKey of keys in List order, + [...] + iii. if desc is not undefined and desc.[[Enumerable]] is true, then + 1. Let propValue be Get(from, nextKey). + 2. ReturnIfAbrupt(propValue). +---*/ + +var source = { + get attr() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + Object.assign({}, source); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/source-non-enum.js b/js/src/tests/test262/built-ins/Object/assign/source-non-enum.js new file mode 100644 index 0000000000..e13857c627 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/source-non-enum.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.1 +description: Does not assign non-enumerable source properties +info: | + [...] + 5. For each element nextSource of sources, in ascending index order, + c. Repeat for each element nextKey of keys in List order, + i. Let desc be from.[[GetOwnProperty]](nextKey). + ii. ReturnIfAbrupt(desc). + iii. if desc is not undefined and desc.[[Enumerable]] is true, then +---*/ + +var target = {}; +var source = Object.defineProperty({}, 'attr', { + value: 1, + enumerable: false +}); +var result; + +result = Object.assign(target, source); + +assert( + !Object.prototype.hasOwnProperty.call(target, 'attr'), + "Non-enumerable property 'attr' does not get copied to target" +); +assert.sameValue(result, target); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/source-own-prop-desc-missing.js b/js/src/tests/test262/built-ins/Object/assign/source-own-prop-desc-missing.js new file mode 100644 index 0000000000..54fc0dbe66 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/source-own-prop-desc-missing.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.1 +description: Invoked with a source which does not have a descriptor for an own property +info: | + [...] + 5. For each element nextSource of sources, in ascending index order, + [...] + c. Repeat for each element nextKey of keys in List order, + i. Let desc be from.[[GetOwnProperty]](nextKey). + ii. ReturnIfAbrupt(desc). + iii. if desc is not undefined and desc.[[Enumerable]] is true, then +features: [Proxy] +---*/ + +var callCount = 0; +var target = {}; +var result; +var source = new Proxy({}, { + ownKeys: function() { + callCount += 1; + return ['missing']; + } +}); + +result = Object.assign(target, source); + +assert.sameValue(callCount, 1, 'Proxy trap was invoked exactly once'); +assert( + !Object.prototype.hasOwnProperty.call(target, 'missing'), + 'An own property was not created for a property without a property descriptor' +); +assert.sameValue(result, target); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/source-own-prop-error.js b/js/src/tests/test262/built-ins/Object/assign/source-own-prop-error.js new file mode 100644 index 0000000000..0229bd3354 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/source-own-prop-error.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.1 +description: Invoked with a source whose own property descriptor cannot be retrieved +info: | + [...] + 5. For each element nextSource of sources, in ascending index order, + [...] + c. Repeat for each element nextKey of keys in List order, + i. Let desc be from.[[GetOwnProperty]](nextKey). + ii. ReturnIfAbrupt(desc). +features: [Proxy] +---*/ + +var source = new Proxy({ + attr: null +}, { + getOwnPropertyDescriptor: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.assign({}, source); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/source-own-prop-keys-error.js b/js/src/tests/test262/built-ins/Object/assign/source-own-prop-keys-error.js new file mode 100644 index 0000000000..5cad1fbda1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/source-own-prop-keys-error.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.2.1 +description: Invoked with a source whose own property keys cannot be retrieved +info: | + [...] + 5. For each element nextSource of sources, in ascending index order, + a. If nextSource is undefined or null, let keys be an empty List. + b. Else, + i. Let from be ToObject(nextSource). + ii. ReturnIfAbrupt(from). + iii. Let keys be from.[[OwnPropertyKeys]](). + iv. ReturnIfAbrupt(keys). +features: [Proxy] +---*/ + +var source = new Proxy({}, { + ownKeys: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.assign({}, source); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/strings-and-symbol-order-proxy.js b/js/src/tests/test262/built-ins/Object/assign/strings-and-symbol-order-proxy.js new file mode 100644 index 0000000000..c4523a4df5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/strings-and-symbol-order-proxy.js @@ -0,0 +1,43 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-object.assign +description: > + Proxy keys are iterated in order they were provided by "ownKeys" trap. +info: | + Object.assign ( target, ...sources ) + + [...] + 4. For each element nextSource of sources, in ascending index order, do + a. If nextSource is neither undefined nor null, then + [...] + ii. Let keys be ? from.[[OwnPropertyKeys]](). + iii. For each element nextKey of keys in List order, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + + [[OwnPropertyKeys]] ( ) + + [...] + 7. Let trapResultArray be ? Call(trap, handler, « target »). + 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, Symbol »). + [...] + 23. Return trapResult. +features: [Proxy, Symbol] +includes: [compareArray.js] +---*/ + +var getOwnKeys = []; +var ownKeysResult = [Symbol(), "foo", "0"]; +var proxy = new Proxy({}, { + getOwnPropertyDescriptor: function(_target, key) { + getOwnKeys.push(key); + }, + ownKeys: function() { + return ownKeysResult; + }, +}); + +Object.assign({}, proxy); +assert.compareArray(getOwnKeys, ownKeysResult); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/strings-and-symbol-order.js b/js/src/tests/test262/built-ins/Object/assign/strings-and-symbol-order.js new file mode 100644 index 0000000000..57cf13c377 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/strings-and-symbol-order.js @@ -0,0 +1,63 @@ +// Copyright (C) 2018 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + Symbol-valued properties are copied after String-valued properties. +info: | + 19.1.2.1 Object.assign ( target, ...sources ) + + ... + 4. For each element nextSource of sources, in ascending index order, do + a. ... + b. Else, + i. Let from be ! ToObject(nextSource). + ii. Let keys be ? from.[[OwnPropertyKeys]](). + c. For each element nextKey of keys in List order, do + ... + ... + + 9.1.11.1 OrdinaryOwnPropertyKeys ( O ) + + ... + 3. For each own property key P of O that is a String but is not an integer index, + in ascending chronological order of property creation, do + a. Add P as the last element of keys. + 4. For each own property key P of O that is a Symbol, in ascending chronological + order of property creation, do + a. Add P as the last element of keys. + ... + +includes: [compareArray.js] +---*/ + +var log = []; + +var sym1 = Symbol("x"); +var sym2 = Symbol("y"); + +var source = {}; + +Object.defineProperty(source, sym1, { + get: function(){ log.push("get sym(x)") }, + enumerable: true, configurable: true, +}); +Object.defineProperty(source, "a", { + get: function(){ log.push("get a") }, + enumerable: true, configurable: true, +}); +Object.defineProperty(source, sym2, { + get: function(){ log.push("get sym(y)") }, + enumerable: true, configurable: true, +}); +Object.defineProperty(source, "b", { + get: function(){ log.push("get b") }, + enumerable: true, configurable: true, +}); + +var target = Object.assign({}, source); + +assert.compareArray(log, ["get a", "get b", "get sym(x)", "get sym(y)"]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/target-is-frozen-accessor-property-set-succeeds.js b/js/src/tests/test262/built-ins/Object/assign/target-is-frozen-accessor-property-set-succeeds.js new file mode 100644 index 0000000000..36d3065b26 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/target-is-frozen-accessor-property-set-succeeds.js @@ -0,0 +1,65 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to accessor property of frozen `target` succeeds. +info: | + SetIntegrityLevel ( O, level ) + + [...] + 3. Let status be ? O.[[PreventExtensions]](). + [...] + 7. Else, + a. Assert: level is frozen. + b. For each element k of keys, do + i. Let currentDesc be ? O.[[GetOwnProperty]](k). + ii. If currentDesc is not undefined, then + 1. If IsAccessorDescriptor(currentDesc) is true, then + a. Let desc be the PropertyDescriptor { [[Configurable]]: false }. + [...] + 3. Perform ? DefinePropertyOrThrow(O, k, desc). + 8. Return true. + + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 7. Perform ? Call(setter, Receiver, « V »). + 8. Return true. +features: [Symbol] +---*/ + +var value1 = 1; +var target1 = { + set foo(val) { value1 = val; }, +}; + +Object.freeze(target1); +Object.assign(target1, { foo: 2 }); +assert.sameValue(value1, 2); + + +var sym = Symbol(); +var value2 = 1; +var target2 = Object.freeze({ + set [sym](val) { value2 = val; }, +}); + +Object.freeze(target2); +Object.assign(target2, { [sym]: 2 }); +assert.sameValue(value2, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/target-is-frozen-data-property-set-throws.js b/js/src/tests/test262/built-ins/Object/assign/target-is-frozen-data-property-set-throws.js new file mode 100644 index 0000000000..943798ccc6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/target-is-frozen-data-property-set-throws.js @@ -0,0 +1,61 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to data property of frozen `target` fails with TypeError. +info: | + SetIntegrityLevel ( O, level ) + + [...] + 3. Let status be ? O.[[PreventExtensions]](). + [...] + 7. Else, + a. Assert: level is frozen. + b. For each element k of keys, do + i. Let currentDesc be ? O.[[GetOwnProperty]](k). + ii. If currentDesc is not undefined, then + 1. If IsAccessorDescriptor(currentDesc) is true, then + [...] + 2. Else, + a. Let desc be the PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }. + 3. Perform ? DefinePropertyOrThrow(O, k, desc). + 8. Return true. + + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 3. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. +features: [Symbol, Reflect] +---*/ + +var sym = Symbol(); +var target1 = { [sym]: 1 }; + +Object.freeze(target1); +assert.throws(TypeError, function() { + Object.assign(target1, { [sym]: 1 }); +}); + + +var target2 = Object.freeze({ foo: 1 }); + +assert.throws(TypeError, function() { + Object.assign(target2, { foo: 1 }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/target-is-non-extensible-existing-accessor-property.js b/js/src/tests/test262/built-ins/Object/assign/target-is-non-extensible-existing-accessor-property.js new file mode 100644 index 0000000000..f0d1d126fa --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/target-is-non-extensible-existing-accessor-property.js @@ -0,0 +1,52 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to existing accessor property of non-extensible `target` is successful. +info: | + OrdinaryPreventExtensions ( O ) + + 1. Set O.[[Extensible]] to false. + + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 7. Perform ? Call(setter, Receiver, « V »). + 8. Return true. +features: [Symbol] +---*/ + +var value1 = 1; +var target1 = Object.preventExtensions({ + set foo(val) { value1 = val; }, +}); + +Object.assign(target1, { foo: 2 }); +assert.sameValue(value1, 2); + + +var sym = Symbol(); +var value2 = 1; +var target2 = { + set [sym](val) { value2 = val; }, +}; + +Object.preventExtensions(target2); +Object.assign(target2, { [sym]: 2 }); +assert.sameValue(value2, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/target-is-non-extensible-existing-data-property.js b/js/src/tests/test262/built-ins/Object/assign/target-is-non-extensible-existing-data-property.js new file mode 100644 index 0000000000..ebbf3a8e15 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/target-is-non-extensible-existing-data-property.js @@ -0,0 +1,59 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to existing data property of non-extensible `target` is successful. +info: | + OrdinaryPreventExtensions ( O ) + + 1. Set O.[[Extensible]] to false. + + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 3. If IsDataDescriptor(ownDesc) is true, then + [...] + c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). + d. If existingDescriptor is not undefined, then + [...] + iii. Let valueDesc be the PropertyDescriptor { [[Value]]: V }. + iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc). + + ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) + + [...] + 9. If O is not undefined, then + a. For each field of Desc that is present, set the corresponding attribute + of the property named P of object O to the value of the field. + 10. Return true. +features: [Symbol] +---*/ + +var target1 = Object.preventExtensions({ foo: 1 }); + +Object.assign(target1, { foo: 2 }); +assert.sameValue(target1.foo, 2); + + +var sym = Symbol(); +var target2 = { [sym]: 1 }; + +Object.preventExtensions(target2); +Object.assign(target2, { [sym]: 2 }); +assert.sameValue(target2[sym], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/target-is-non-extensible-property-creation-throws.js b/js/src/tests/test262/built-ins/Object/assign/target-is-non-extensible-property-creation-throws.js new file mode 100644 index 0000000000..cbc5dda75e --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/target-is-non-extensible-property-creation-throws.js @@ -0,0 +1,55 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to non-existing property of non-extensible `target` fails with TypeError. +info: | + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 3. If IsDataDescriptor(ownDesc) is true, then + [...] + c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). + d. If existingDescriptor is not undefined, then + [...] + e. Else, + i. Assert: Receiver does not currently have a property P. + ii. Return ? CreateDataProperty(Receiver, P, V). + + ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) + + [...] + 2. If current is undefined, then + a. If extensible is false, return false. +features: [Symbol] +---*/ + +var target1 = Object.preventExtensions({ foo: 1 }); + +assert.throws(TypeError, function() { + Object.assign(target1, { get bar() {} }); +}); + + +var target2 = {}; + +Object.preventExtensions(target2); +assert.throws(TypeError, function() { + Object.assign(target2, { [Symbol()]: 1 }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/target-is-sealed-existing-accessor-property.js b/js/src/tests/test262/built-ins/Object/assign/target-is-sealed-existing-accessor-property.js new file mode 100644 index 0000000000..102511a969 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/target-is-sealed-existing-accessor-property.js @@ -0,0 +1,57 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to existing accessor property of sealed `target` is successful. +info: | + SetIntegrityLevel ( O, level ) + + [...] + 3. Let status be ? O.[[PreventExtensions]](). + [...] + + OrdinaryPreventExtensions ( O ) + + 1. Set O.[[Extensible]] to false. + + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 7. Perform ? Call(setter, Receiver, « V »). + 8. Return true. +---*/ + +var value1 = 1; +var target1 = Object.seal({ + set foo(val) { value1 = val; }, +}); + +Object.assign(target1, { foo: 2 }); +assert.sameValue(value1, 2); + + +var sym = Symbol(); +var value2 = 1; +var target2 = { + set [sym](val) { value2 = val; }, +}; + +Object.seal(target2); +Object.assign(target2, { [sym]: 2 }); +assert.sameValue(value2, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/target-is-sealed-existing-data-property.js b/js/src/tests/test262/built-ins/Object/assign/target-is-sealed-existing-data-property.js new file mode 100644 index 0000000000..31c05994e1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/target-is-sealed-existing-data-property.js @@ -0,0 +1,64 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to existing data property of sealed `target` is successful. +info: | + SetIntegrityLevel ( O, level ) + + [...] + 3. Let status be ? O.[[PreventExtensions]](). + [...] + + OrdinaryPreventExtensions ( O ) + + 1. Set O.[[Extensible]] to false. + + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 3. If IsDataDescriptor(ownDesc) is true, then + [...] + c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). + d. If existingDescriptor is not undefined, then + [...] + iii. Let valueDesc be the PropertyDescriptor { [[Value]]: V }. + iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc). + + ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) + + [...] + 9. If O is not undefined, then + a. For each field of Desc that is present, set the corresponding attribute + of the property named P of object O to the value of the field. + 10. Return true. +---*/ + +var target1 = Object.seal({ foo: 1 }); + +Object.assign(target1, { foo: 2 }); +assert.sameValue(target1.foo, 2); + + +var sym = Symbol(); +var target2 = { [sym]: 1 }; + +Object.seal(target2); +Object.assign(target2, { [sym]: 2 }); +assert.sameValue(target2[sym], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/target-is-sealed-property-creation-throws.js b/js/src/tests/test262/built-ins/Object/assign/target-is-sealed-property-creation-throws.js new file mode 100644 index 0000000000..dd7ebae67b --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/target-is-sealed-property-creation-throws.js @@ -0,0 +1,61 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-object.assign +description: > + [[Set]] to non-existing property of sealed `target` fails with TypeError. +info: | + SetIntegrityLevel ( O, level ) + + [...] + 3. Let status be ? O.[[PreventExtensions]](). + [...] + + Object.assign ( target, ...sources ) + + [...] + 3. For each element nextSource of sources, do + a. If nextSource is neither undefined nor null, then + [...] + iii. For each element nextKey of keys, do + 1. Let desc be ? from.[[GetOwnProperty]](nextKey). + 2. If desc is not undefined and desc.[[Enumerable]] is true, then + [...] + b. Perform ? Set(to, nextKey, propValue, true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 3. If IsDataDescriptor(ownDesc) is true, then + [...] + c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). + d. If existingDescriptor is not undefined, then + [...] + e. Else, + i. Assert: Receiver does not currently have a property P. + ii. Return ? CreateDataProperty(Receiver, P, V). + + ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) + + [...] + 2. If current is undefined, then + a. If extensible is false, return false. +features: [Symbol, Reflect] +---*/ + +var target1 = Object.seal({ foo: 1 }); + +assert.throws(TypeError, function() { + Object.assign(target1, { get bar() {} }); +}); + + +var target2 = {}; + +Object.seal(target2); +assert.throws(TypeError, function() { + Object.assign(target2, { [Symbol()]: 1 }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/target-set-not-writable.js b/js/src/tests/test262/built-ins/Object/assign/target-set-not-writable.js new file mode 100644 index 0000000000..930ddb8302 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/target-set-not-writable.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: 19.1.2.1 +description: Errors thrown during definition of target object attributes +info: | + [...] + 5. For each element nextSource of sources, in ascending index order, + [...] + c. Repeat for each element nextKey of keys in List order, + [...] + iii. if desc is not undefined and desc.[[Enumerable]] is true, then + [...] + 3. Let status be Set(to, nextKey, propValue, true). + 4. ReturnIfAbrupt(status). +---*/ + +var target = {}; +Object.defineProperty(target, 'attr', { + writable: false +}); + +assert.throws(TypeError, function() { + Object.assign(target, { + attr: 1 + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Object/assign/target-set-user-error.js b/js/src/tests/test262/built-ins/Object/assign/target-set-user-error.js new file mode 100644 index 0000000000..9a71116351 --- /dev/null +++ b/js/src/tests/test262/built-ins/Object/assign/target-set-user-error.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: 19.1.2.1 +description: Errors thrown during definition of target object attributes +info: | + [...] + 5. For each element nextSource of sources, in ascending index order, + [...] + c. Repeat for each element nextKey of keys in List order, + [...] + iii. if desc is not undefined and desc.[[Enumerable]] is true, then + [...] + 3. Let status be Set(to, nextKey, propValue, true). + 4. ReturnIfAbrupt(status). +---*/ + +var target = {}; +Object.defineProperty(target, 'attr', { + set: function(_) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.assign(target, { + attr: 1 + }); +}); + +reportCompare(0, 0); |