Skip to content
Snippets Groups Projects
Commit b103418a authored by Leonardo Balter's avatar Leonardo Balter
Browse files

Map.prototype.get

parent a31a62fc
No related branches found
No related tags found
No related merge requests found
Showing with 303 additions and 0 deletions
// 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);
});
// 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);
});
// 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);
});
// 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');
// 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');
// 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');
// 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'
);
// 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);
// 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);
// 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);
});
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