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

WeakMap.prototype.get

parent e44e0c17
No related branches found
No related tags found
No related merge requests found
Showing
with 297 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.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);
});
// 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);
});
// 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);
});
// 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');
// 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');
// 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');
// 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'
);
// 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'
);
// 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);
// 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, {});
});
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