mirror of https://github.com/tc39/test262.git
Extend coverage for Object.assign
This commit is contained in:
parent
12cc01484e
commit
39cd09f7a8
|
@ -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 @@
|
||||||
/*---
|
/*---
|
||||||
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');
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
// 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({});
|
||||||
|
});
|
|
@ -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: '`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');
|
||||||
|
|
|
@ -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: 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);
|
||||||
|
});
|
|
@ -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: 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);
|
|
@ -0,0 +1,35 @@
|
||||||
|
// 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);
|
|
@ -0,0 +1,24 @@
|
||||||
|
// 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);
|
||||||
|
});
|
|
@ -0,0 +1,26 @@
|
||||||
|
// 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);
|
||||||
|
});
|
|
@ -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: 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 });
|
||||||
|
});
|
|
@ -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 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 });
|
||||||
|
});
|
Loading…
Reference in New Issue