mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 07:54:41 +02:00
Map.prototype.get
This commit is contained in:
parent
a31a62fcc8
commit
b103418a17
24
test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js
vendored
Normal file
24
test/built-ins/Map/prototype/get/does-not-have-mapdata-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.1.3.6
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if `this` is a Set object.
|
||||||
|
info: >
|
||||||
|
Map.prototype.get ( key )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If M does not have a [[MapData]] internal slot, throw a TypeError
|
||||||
|
exception.
|
||||||
|
...
|
||||||
|
features: [Set]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.get.call(new Set(), 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var m = new Map();
|
||||||
|
m.get.call(new Set(), 1);
|
||||||
|
});
|
24
test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js
vendored
Normal file
24
test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.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.1.3.6
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if `this` is a WeakMap object.
|
||||||
|
info: >
|
||||||
|
Map.prototype.get ( key )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If M does not have a [[MapData]] internal slot, throw a TypeError
|
||||||
|
exception.
|
||||||
|
...
|
||||||
|
features: [WeakMap]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.get.call(new WeakMap(), 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var m = new Map();
|
||||||
|
m.get.call(new WeakMap(), 1);
|
||||||
|
});
|
32
test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot.js
vendored
Normal file
32
test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot.js
vendored
Normal file
@ -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: 23.1.3.6
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if `this` object does not have a [[MapData]] internal slot.
|
||||||
|
info: >
|
||||||
|
Map.prototype.get ( key )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If M does not have a [[MapData]] internal slot, throw a TypeError
|
||||||
|
exception.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var m = new Map();
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.get.call([], 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
m.get.call([], 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.get.call({}, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
m.get.call({}, 1);
|
||||||
|
});
|
22
test/built-ins/Map/prototype/get/get.js
vendored
Normal file
22
test/built-ins/Map/prototype/get/get.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.1.3.6
|
||||||
|
description: >
|
||||||
|
Property type and descriptor.
|
||||||
|
info: >
|
||||||
|
Map.prototype.get ( key )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
typeof Map.prototype.get,
|
||||||
|
'function',
|
||||||
|
'`typeof Map.prototype.get` is `function`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Map.prototype, 'get');
|
||||||
|
verifyWritable(Map.prototype, 'get');
|
||||||
|
verifyConfigurable(Map.prototype, 'get');
|
22
test/built-ins/Map/prototype/get/length.js
vendored
Normal file
22
test/built-ins/Map/prototype/get/length.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.1.3.6
|
||||||
|
description: >
|
||||||
|
Map.prototype.get.length value and descriptor.
|
||||||
|
info: >
|
||||||
|
Map.prototype.get ( key )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Map.prototype.get.length, 1,
|
||||||
|
'The value of `Map.prototype.get.length` is `1`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Map.prototype.get, 'length');
|
||||||
|
verifyNotWritable(Map.prototype.get, 'length');
|
||||||
|
verifyConfigurable(Map.prototype.get, 'length');
|
22
test/built-ins/Map/prototype/get/name.js
vendored
Normal file
22
test/built-ins/Map/prototype/get/name.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.1.3.6
|
||||||
|
description: >
|
||||||
|
Map.prototype.get.name value and descriptor.
|
||||||
|
info: >
|
||||||
|
Map.prototype.get ( key )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Map.prototype.get.name, 'get',
|
||||||
|
'The value of `Map.prototype.get.name` is `"get"`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Map.prototype.get, 'name');
|
||||||
|
verifyNotWritable(Map.prototype.get, 'name');
|
||||||
|
verifyConfigurable(Map.prototype.get, 'name');
|
41
test/built-ins/Map/prototype/get/returns-undefined.js
vendored
Normal file
41
test/built-ins/Map/prototype/get/returns-undefined.js
vendored
Normal file
@ -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.1.3.6
|
||||||
|
description: >
|
||||||
|
Returns undefined when key is not on the map.
|
||||||
|
info: >
|
||||||
|
Map.prototype.get ( key )
|
||||||
|
|
||||||
|
4. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
5. Repeat for each Record {[[key]], [[value]]} p that is an element of
|
||||||
|
entries,
|
||||||
|
a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true,
|
||||||
|
return p.[[value]].
|
||||||
|
6. Return undefined.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
map.get('item'), undefined,
|
||||||
|
'returns undefined if key is not on the map'
|
||||||
|
);
|
||||||
|
|
||||||
|
map.set('item', 1);
|
||||||
|
map.set('another_item', 2);
|
||||||
|
map.delete('item');
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
map.get('item'), undefined,
|
||||||
|
'returns undefined if key was deleted'
|
||||||
|
);
|
||||||
|
|
||||||
|
map.set('item', 1);
|
||||||
|
map.clear();
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
map.get('item'), undefined,
|
||||||
|
'returns undefined after map is cleared'
|
||||||
|
);
|
48
test/built-ins/Map/prototype/get/returns-value-different-key-types.js
vendored
Normal file
48
test/built-ins/Map/prototype/get/returns-value-different-key-types.js
vendored
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
// 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.1.3.6
|
||||||
|
description: >
|
||||||
|
Returns the value from the specified key on different types.
|
||||||
|
info: >
|
||||||
|
Map.prototype.get ( key )
|
||||||
|
|
||||||
|
4. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
5. Repeat for each Record {[[key]], [[value]]} p that is an element of
|
||||||
|
entries,
|
||||||
|
a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true,
|
||||||
|
return p.[[value]].
|
||||||
|
...
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
|
||||||
|
map.set('bar', 0);
|
||||||
|
assert.sameValue(map.get('bar'), 0);
|
||||||
|
|
||||||
|
map.set(1, 42);
|
||||||
|
assert.sameValue(map.get(1), 42);
|
||||||
|
|
||||||
|
map.set(NaN, 1);
|
||||||
|
assert.sameValue(map.get(NaN), 1);
|
||||||
|
|
||||||
|
var item = {};
|
||||||
|
map.set(item, 2);
|
||||||
|
assert.sameValue(map.get(item), 2);
|
||||||
|
|
||||||
|
item = [];
|
||||||
|
map.set(item, 3);
|
||||||
|
assert.sameValue(map.get(item), 3);
|
||||||
|
|
||||||
|
item = Symbol('item');
|
||||||
|
map.set(item, 4);
|
||||||
|
assert.sameValue(map.get(item), 4);
|
||||||
|
|
||||||
|
item = null;
|
||||||
|
map.set(item, 5);
|
||||||
|
assert.sameValue(map.get(item), 5);
|
||||||
|
|
||||||
|
item = undefined;
|
||||||
|
map.set(item, 6);
|
||||||
|
assert.sameValue(map.get(item), 6);
|
25
test/built-ins/Map/prototype/get/returns-value-normalized-zero-key.js
vendored
Normal file
25
test/built-ins/Map/prototype/get/returns-value-normalized-zero-key.js
vendored
Normal file
@ -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: 23.1.3.6
|
||||||
|
description: >
|
||||||
|
-0 and +0 are normalized to +0;
|
||||||
|
info: >
|
||||||
|
Map.prototype.get ( key )
|
||||||
|
|
||||||
|
4. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
5. Repeat for each Record {[[key]], [[value]]} p that is an element of
|
||||||
|
entries,
|
||||||
|
a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true,
|
||||||
|
return p.[[value]].
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
|
||||||
|
map.set(+0, 42);
|
||||||
|
assert.sameValue(map.get(-0), 42);
|
||||||
|
|
||||||
|
map = new Map();
|
||||||
|
map.set(-0, 43);
|
||||||
|
assert.sameValue(map.get(+0), 43);
|
43
test/built-ins/Map/prototype/get/this-not-object-throw.js
vendored
Normal file
43
test/built-ins/Map/prototype/get/this-not-object-throw.js
vendored
Normal file
@ -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.1.3.6
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if `this` is not an Object.
|
||||||
|
info: >
|
||||||
|
Map.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() {
|
||||||
|
Map.prototype.get.call(false, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.get.call(1, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.get.call('', 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.get.call(undefined, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.get.call(null, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.get.call(Symbol(), 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var map = new Map();
|
||||||
|
map.get.call(false, 1);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user