Skip to content
Snippets Groups Projects
Commit 39cd09f7 authored by Mike Pennisi's avatar Mike Pennisi
Browse files

Extend coverage for Object.assign

parent 12cc0148
No related branches found
No related tags found
No related merge requests found
Showing
with 251 additions and 1 deletion
...@@ -10,4 +10,5 @@ es6id: 19.1.2.1.3 ...@@ -10,4 +10,5 @@ es6id: 19.1.2.1.3
var target = "a"; var target = "a";
var result = Object.assign(target); var result = Object.assign(target);
assert.sameValue(typeof result, "object");
assert.sameValue(result.valueOf(), "a", "The value should be 'a'."); assert.sameValue(result.valueOf(), "a", "The value should be 'a'.");
...@@ -4,6 +4,21 @@ ...@@ -4,6 +4,21 @@
/*--- /*---
description: The length property of the assign method should be 2 description: The length property of the assign method should be 2
es6id: 19.1.2.1 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."); 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');
// 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({});
});
// 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');
// 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);
});
// 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.sameValue(Object.hasOwnProperty.call(target, 'attr'), false);
assert.sameValue(result, target);
// 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.sameValue(
Object.hasOwnProperty.call(target, 'missing'),
false,
'An own property was not created for a property without a property descriptor'
);
assert.sameValue(result, target);
// 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);
});
// 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);
});
// 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 });
});
// 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 });
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment