mirror of https://github.com/tc39/test262.git
WeakMap.prototype.get
This commit is contained in:
parent
e44e0c1762
commit
7acd163264
24
test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-map.js
vendored
Normal file
24
test/built-ins/WeakMap/prototype/get/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.3
|
||||
description: >
|
||||
Throws a TypeError if `this` is a Map object.
|
||||
info: >
|
||||
WeakMap.prototype.get ( key )
|
||||
|
||||
...
|
||||
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
features: [Map]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.get.call(new Map(), 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.get.call(new Map(), 1);
|
||||
});
|
24
test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-set.js
vendored
Normal file
24
test/built-ins/WeakMap/prototype/get/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.3
|
||||
description: >
|
||||
Throws a TypeError if `this` is a Set object.
|
||||
info: >
|
||||
WeakMap.prototype.get ( key )
|
||||
|
||||
...
|
||||
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
features: [Set]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.get.call(new Set(), 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.get.call(new Set(), 1);
|
||||
});
|
31
test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.js
vendored
Normal file
31
test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.js
vendored
Normal file
|
@ -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: 23.3.3.3
|
||||
description: >
|
||||
Throws a TypeError if `this` does not have a [[WeakMapData]] internal slot.
|
||||
info: >
|
||||
WeakMap.prototype.get ( key )
|
||||
|
||||
...
|
||||
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
---*/
|
||||
var map = new WeakMap();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.get.call([], 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
map.get.call([], 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.get.call({}, 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
map.get.call({}, 1);
|
||||
});
|
|
@ -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.3
|
||||
description: >
|
||||
Property type and descriptor.
|
||||
info: >
|
||||
WeakMap.prototype.get ( key )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof WeakMap.prototype.get,
|
||||
'function',
|
||||
'`typeof WeakMap.prototype.get` is `function`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(WeakMap.prototype, 'get');
|
||||
verifyWritable(WeakMap.prototype, 'get');
|
||||
verifyConfigurable(WeakMap.prototype, 'get');
|
|
@ -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.3
|
||||
description: >
|
||||
WeakMap.prototype.get.length value and descriptor.
|
||||
info: >
|
||||
WeakMap.prototype.get ( key )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
WeakMap.prototype.get.length, 1,
|
||||
'The value of `WeakMap.prototype.get.length` is `1`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(WeakMap.prototype.get, 'length');
|
||||
verifyNotWritable(WeakMap.prototype.get, 'length');
|
||||
verifyConfigurable(WeakMap.prototype.get, 'length');
|
|
@ -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.3
|
||||
description: >
|
||||
WeakMap.prototype.get.name value and descriptor.
|
||||
info: >
|
||||
WeakMap.prototype.get ( key )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
WeakMap.prototype.get.name, 'get',
|
||||
'The value of `WeakMap.prototype.get.name` is `"get"`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(WeakMap.prototype.get, 'name');
|
||||
verifyNotWritable(WeakMap.prototype.get, 'name');
|
||||
verifyConfigurable(WeakMap.prototype.get, 'name');
|
|
@ -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: 23.3.3.3
|
||||
description: >
|
||||
Returns undefined when key is not an Object.
|
||||
info: >
|
||||
WeakMap.prototype.get ( key )
|
||||
|
||||
...
|
||||
4. Let entries be the List that is the value of M’s [[WeakMapData]] internal
|
||||
slot.
|
||||
5. If Type(key) is not Object, return undefined.
|
||||
...
|
||||
---*/
|
||||
|
||||
var map = new WeakMap();
|
||||
|
||||
assert.sameValue(map.get(null), undefined, 'Returns undefined if key is null');
|
||||
|
||||
assert.sameValue(map.get(NaN), undefined, 'Returns undefined if key is NaN');
|
||||
|
||||
assert.sameValue(
|
||||
map.get('foo'), undefined,
|
||||
'Returns undefined if key is a String'
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
map.get(1), undefined,
|
||||
'Returns undefined if key is a Number'
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
map.get(undefined), undefined,
|
||||
'Returns undefined if key is undefined'
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
map.get(Symbol()), undefined,
|
||||
'Returns undefined if key is a Symbol'
|
||||
);
|
|
@ -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.3
|
||||
description: >
|
||||
Returns undefined when key is not on the WeakMap object.
|
||||
info: >
|
||||
WeakMap.prototype.get ( key )
|
||||
|
||||
4. Let entries be the List that is the value of M’s [[WeakMapData]] internal
|
||||
slot.
|
||||
5. If Type(key) is not Object, return undefined.
|
||||
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, return
|
||||
p.[[value]].
|
||||
7. Return undefined.
|
||||
...
|
||||
---*/
|
||||
|
||||
var map = new WeakMap();
|
||||
var key = {};
|
||||
|
||||
assert.sameValue(
|
||||
map.get(key), undefined,
|
||||
'returns undefined if key is not on the weakmap'
|
||||
);
|
||||
|
||||
map.set(key, 1);
|
||||
map.set({}, 2);
|
||||
map.delete(key);
|
||||
map.set({}, 3);
|
||||
|
||||
assert.sameValue(
|
||||
map.get(key), undefined,
|
||||
'returns undefined if key was deleted'
|
||||
);
|
|
@ -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: 23.3.3.3
|
||||
description: >
|
||||
Returns the value from the specified key
|
||||
info: >
|
||||
WeakMap.prototype.get ( key )
|
||||
|
||||
4. Let entries be the List that is the value of M’s [[WeakMapData]] internal
|
||||
slot.
|
||||
5. If Type(key) is not Object, return undefined.
|
||||
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, return
|
||||
p.[[value]].
|
||||
...
|
||||
---*/
|
||||
|
||||
var foo = {};
|
||||
var bar = {};
|
||||
var baz = [];
|
||||
var map = new WeakMap([[foo,0]]);
|
||||
|
||||
assert.sameValue(map.get(foo), 0);
|
||||
|
||||
map.set(bar, 1);
|
||||
assert.sameValue(map.get(bar), 1);
|
||||
|
||||
map.set(baz, 2);
|
||||
assert.sameValue(map.get(baz), 2);
|
|
@ -0,0 +1,43 @@
|
|||
// 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.3
|
||||
description: >
|
||||
Throws a TypeError if `this` value is not an Object.
|
||||
info: >
|
||||
WeakMap.prototype.get ( key )
|
||||
|
||||
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.get.call(false, {});
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.get.call(1, {});
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.get.call('', {});
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.get.call(undefined, {});
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.get.call(null, {});
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
WeakMap.prototype.get.call(Symbol(), {});
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
var map = new WeakMap();
|
||||
map.get.call(false, {});
|
||||
});
|
Loading…
Reference in New Issue