mirror of https://github.com/tc39/test262.git
WeakMap.prototype.set
This commit is contained in:
parent
0887df4c67
commit
74665f0558
|
@ -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: 23.3.3.5
|
||||
description: >
|
||||
Appends value as the last element of entries.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
...
|
||||
7. Let p be the Record {[[key]]: key, [[value]]: value}.
|
||||
8. Append p as the last element of entries.
|
||||
...
|
||||
---*/
|
||||
|
||||
var map = new WeakMap();
|
||||
var foo = {};
|
||||
var bar = {};
|
||||
var baz = {};
|
||||
|
||||
map.set(foo, 1);
|
||||
map.set(bar, 2);
|
||||
map.set(baz, 3);
|
||||
|
||||
assert(map.has(foo));
|
||||
assert(map.has(bar));
|
||||
assert(map.has(baz));
|
24
test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-array.js
vendored
Normal file
24
test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-array.js
vendored
Normal file
|
@ -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: 23.3.3.5
|
||||
description: >
|
||||
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
...
|
||||
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call([], {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call([], {}, 1);
|
||||
});
|
24
test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-map.js
vendored
Normal file
24
test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-map.js
vendored
Normal file
|
@ -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: 23.3.3.5
|
||||
description: >
|
||||
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
...
|
||||
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
features: [Map]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call(new Map(), {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call(new Map(), {}, 1);
|
||||
});
|
23
test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-object.js
vendored
Normal file
23
test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-object.js
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 23.3.3.5
|
||||
description: >
|
||||
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
...
|
||||
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call({}, {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call({}, {}, 1);
|
||||
});
|
24
test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-set.js
vendored
Normal file
24
test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-set.js
vendored
Normal file
|
@ -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: 23.3.3.5
|
||||
description: >
|
||||
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
...
|
||||
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
features: [Set]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call(new Set(), {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call(new Set(), {}, 1);
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 23.3.3.5
|
||||
description: >
|
||||
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
...
|
||||
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call(WeakMap.prototype, {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call(WeakMap.prototype, {}, 1);
|
||||
});
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 23.3.3.5
|
||||
description: Throws TypeError if `key` is not Object.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
5. If Type(key) is not Object, throw a TypeError exception.
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = new WeakMap();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.set(1, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.set(false, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.set(undefined, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.set('string', 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.set(null, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
s.set(Symbol(), 1);
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 23.3.3.5
|
||||
description: WeakMap.prototype.set.length descriptor
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
WeakMap.prototype.set.length, 2,
|
||||
'The value of `WeakMap.prototype.set.length` is `2`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(WeakMap.prototype.set, 'length');
|
||||
verifyNotWritable(WeakMap.prototype.set, 'length');
|
||||
verifyConfigurable(WeakMap.prototype.set, 'length');
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 23.3.3.5
|
||||
description: WeakMap.prototype.set.name descriptor
|
||||
info: >
|
||||
WeakMap.prototype.set ( value )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
WeakMap.prototype.set.name, 'set',
|
||||
'The value of WeakMap.prototype.set.name is "set"'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(WeakMap.prototype.set, 'name');
|
||||
verifyNotWritable(WeakMap.prototype.set, 'name');
|
||||
verifyConfigurable(WeakMap.prototype.set, 'name');
|
22
test/built-ins/WeakMap/prototype/set/returns-this-when-ignoring-duplicate.js
vendored
Normal file
22
test/built-ins/WeakMap/prototype/set/returns-this-when-ignoring-duplicate.js
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 23.3.3.5
|
||||
description: Returns `this` when new value is duplicate.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
1. Let M be the this value.
|
||||
...
|
||||
6. Repeat for each Record {[[key]], [[value]]} p that is an element of
|
||||
entries,
|
||||
a. If p.[[key]] is not empty and SameValue(p.[[key]], key) is true, then
|
||||
i. Set p.[[value]] to value.
|
||||
ii. Return M.
|
||||
...
|
||||
---*/
|
||||
|
||||
var foo = {};
|
||||
var map = new WeakMap([[foo, 1]]);
|
||||
|
||||
assert.sameValue(map.set(foo, 1), map, '`map.set(foo, 1)` returns `map`');
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 23.3.3.5
|
||||
description: Returns `this` after setting a new value.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
1. Let M be this value.
|
||||
...
|
||||
9. Return M.
|
||||
|
||||
---*/
|
||||
|
||||
var map = new WeakMap();
|
||||
|
||||
assert.sameValue(map.set({}, 1), map, '`map.set({}, 1)` returns `map`');
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 23.3.3.5
|
||||
description: WeakMap.prototype.set property descriptor
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof WeakMap.prototype.set,
|
||||
'function',
|
||||
'typeof WeakMap.prototype.set is "function"'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(WeakMap.prototype, 'set');
|
||||
verifyWritable(WeakMap.prototype, 'set');
|
||||
verifyConfigurable(WeakMap.prototype, 'set');
|
|
@ -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: 23.3.3.5
|
||||
description: Throws TypeError if `this` is not Object.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
1. Let M be the this value.
|
||||
2. If Type(M) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call(false, {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call(false, {}, 1);
|
||||
});
|
|
@ -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: 23.3.3.5
|
||||
description: Throws TypeError if `this` is not Object.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
1. Let M be the this value.
|
||||
2. If Type(M) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call(null, {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call(null, {}, 1);
|
||||
});
|
|
@ -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: 23.3.3.5
|
||||
description: Throws TypeError if `this` is not Object.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
1. Let M be the this value.
|
||||
2. If Type(M) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call(0, {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call(0, {}, 1);
|
||||
});
|
|
@ -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: 23.3.3.5
|
||||
description: Throws TypeError if `this` is not Object.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
1. Let M be the this value.
|
||||
2. If Type(M) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call('', {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call('', {}, 1);
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 23.3.3.5
|
||||
description: Throws TypeError if `this` is not Object.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
1. Let M be the this value.
|
||||
2. If Type(M) is not Object, throw a TypeError exception.
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call(Symbol(), {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call(Symbol(), {}, 1);
|
||||
});
|
|
@ -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: 23.3.3.5
|
||||
description: Throws TypeError if `this` is not Object.
|
||||
info: >
|
||||
WeakMap.prototype.set ( key, value )
|
||||
|
||||
1. Let M be the this value.
|
||||
2. If Type(M) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.set.call(undefined, {}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.set.call(undefined, {}, 1);
|
||||
});
|
Loading…
Reference in New Issue