Map.prototype.get

This commit is contained in:
Leonardo Balter 2015-06-29 15:57:49 -04:00
parent a31a62fcc8
commit b103418a17
10 changed files with 303 additions and 0 deletions

View 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);
});

View 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);
});

View 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
View 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');

View 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');

View 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');

View 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 Ms [[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'
);

View 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 Ms [[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);

View 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 Ms [[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);

View 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);
});