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

WeakMap.prototype.delete

parent 806beb5a
No related branches found
No related tags found
No related merge requests found
Showing
with 408 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.2
description: >
Delete an entry from initial iterable.
info: >
WeakMap.prototype.delete ( value )
...
5. Let entries be the List that is the value of M’s [[WeakMapData]] internal
slot.
6. If Type(key) is not Object, return false.
7. 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, then
i. Set p.[[key]] to empty.
ii. Set p.[[value]] to empty.
iii. Return true.
...
---*/
var foo = {};
var map = new WeakMap([[foo, 42]]);
var result = map.delete(foo);
assert.sameValue(map.has(foo), false);
assert.sameValue(result, true, 'WeakMap#delete returns true');
// 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.2
description: >
Delete an entry.
info: >
WeakMap.prototype.delete ( value )
...
5. Let entries be the List that is the value of M’s [[WeakMapData]] internal
slot.
6. If Type(key) is not Object, return false.
7. 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, then
i. Set p.[[key]] to empty.
ii. Set p.[[value]] to empty.
iii. Return true.
...
---*/
var foo = {};
var map = new WeakMap();
map.set(foo, 42);
var result = map.delete(foo);
assert.sameValue(map.has(foo), false);
assert.sameValue(result, true, 'WeakMap#delete returns true');
// 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.2
description: >
WeakMap.prototype.delete property descriptor
info: >
WeakMap.prototype.delete ( value )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
typeof WeakMap.prototype.delete,
'function',
'typeof WeakMap.prototype.delete is "function"'
);
verifyNotEnumerable(WeakMap.prototype, 'delete');
verifyWritable(WeakMap.prototype, 'delete');
verifyConfigurable(WeakMap.prototype, 'delete');
// 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.2
description: >
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
info: >
WeakMap.prototype.delete ( value )
...
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
exception.
...
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.delete.call([], {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call([], {});
});
// 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.2
description: >
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
info: >
WeakMap.prototype.delete ( value )
...
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
exception.
...
features: [Map]
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.delete.call(new Map(), {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call(new Map(), {});
});
// 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.2
description: >
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
info: >
WeakMap.prototype.delete ( value )
...
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
exception.
...
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.delete.call({}, {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call({}, {});
});
// 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.2
description: >
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
info: >
WeakMap.prototype.delete ( value )
...
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
exception.
...
features: [Set]
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.delete.call(new Set(), {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call(new Set(), {});
});
// 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.2
description: >
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
info: >
WeakMap.prototype.delete ( value )
...
3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError
exception.
...
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.delete.call(WeakMap.prototype, {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call(WeakMap.prototype, {});
});
// 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.2
description: >
WeakMap.prototype.delete.length value and writability.
info: >
WeakMap.prototype.delete ( value )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
WeakMap.prototype.delete.length, 1,
'The value of WeakMap.prototype.delete.length is 1'
);
verifyNotEnumerable(WeakMap.prototype.delete, 'length');
verifyNotWritable(WeakMap.prototype.delete, 'length');
verifyConfigurable(WeakMap.prototype.delete, '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.2
description: >
WeakMap.prototype.delete.name value and writability.
info: >
WeakMap.prototype.delete ( value )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
WeakMap.prototype.delete.name, 'delete',
'The value of WeakMap.prototype.delete.name is "delete"'
);
verifyNotEnumerable(WeakMap.prototype.delete, 'name');
verifyNotWritable(WeakMap.prototype.delete, 'name');
verifyConfigurable(WeakMap.prototype.delete, '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.2
description: >
Return false if value is not an Object.
info: >
WeakMap.prototype.delete ( value )
5. If Type(key) is not Object, return false.
features: [Symbol]
---*/
var map = new WeakMap();
assert.sameValue(map.delete(1), false);
assert.sameValue(map.delete(''), false);
assert.sameValue(map.delete(NaN), false);
assert.sameValue(map.delete(null), false);
assert.sameValue(map.delete(undefined), false);
assert.sameValue(map.delete(true), false);
assert.sameValue(map.delete(Symbol()), false);
// 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.2
description: >
Return false if entry is not in the WeakMap.
info: >
WeakMap.prototype.delete ( value )
...
7. Return false.
---*/
var map = new WeakMap();
var foo = {};
var bar = {};
map.set(foo, 42);
assert.sameValue(map.delete(bar), false);
// 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.2
description: Throws TypeError if `this` is not Object.
info: >
WeakMap.prototype.delete ( value )
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.delete.call(false, {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call(false, {});
});
// 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.2
description: Throws TypeError if `this` is not Object.
info: >
WeakMap.prototype.delete ( value )
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.delete.call(null, {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call(null, {});
});
// 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.2
description: Throws TypeError if `this` is not Object.
info: >
WeakMap.prototype.delete ( value )
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.delete.call(0, {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call(0, {});
});
// 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.2
description: Throws TypeError if `this` is not Object.
info: >
WeakMap.prototype.delete ( value )
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.delete.call('', {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call('', {});
});
// 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.2
description: Throws TypeError if `this` is not Object.
info: >
WeakMap.prototype.delete ( value )
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.delete.call(Symbol(), {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call(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.2
description: Throws TypeError if `this` is not Object.
info: >
WeakMap.prototype.delete ( value )
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.delete.call(undefined, {});
});
assert.throws(TypeError, function() {
var map = new WeakMap();
map.delete.call(undefined, {});
});
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