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

Map.prototype.has

parent b103418a
No related branches found
No related tags found
No related merge requests found
Showing with 292 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.7
description: >
Throws a TypeError if `this` is a Set object.
info: >
Map.prototype.has ( key )
...
3. If M does not have a [[MapData]] internal slot, throw a TypeError
exception.
...
features: [Set]
---*/
assert.throws(TypeError, function() {
Map.prototype.has.call(new Set(), 1);
});
assert.throws(TypeError, function() {
var m = new Map();
m.has.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.7
description: >
Throws a TypeError if `this` is a WeakMap object.
info: >
Map.prototype.has ( key )
...
3. If M does not have a [[MapData]] internal slot, throw a TypeError
exception.
...
features: [WeakMap]
---*/
assert.throws(TypeError, function() {
Map.prototype.has.call(new WeakMap(), 1);
});
assert.throws(TypeError, function() {
var m = new Map();
m.has.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.7
description: >
Throws a TypeError if `this` object does not have a [[MapData]] internal slot.
info: >
Map.prototype.has ( 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.has.call([], 1);
});
assert.throws(TypeError, function() {
m.has.call([], 1);
});
assert.throws(TypeError, function() {
Map.prototype.has.call({}, 1);
});
assert.throws(TypeError, function() {
m.has.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.7
description: >
Property type and descriptor.
info: >
Map.prototype.has ( key )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
typeof Map.prototype.has,
'function',
'`typeof Map.prototype.has` is `function`'
);
verifyNotEnumerable(Map.prototype, 'has');
verifyWritable(Map.prototype, 'has');
verifyConfigurable(Map.prototype, 'has');
// 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.7
description: >
Map.prototype.has.length value and descriptor.
info: >
Map.prototype.has ( key )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Map.prototype.has.length, 1,
'The value of `Map.prototype.has.length` is `1`'
);
verifyNotEnumerable(Map.prototype.has, 'length');
verifyNotWritable(Map.prototype.has, 'length');
verifyConfigurable(Map.prototype.has, '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.7
description: >
Map.prototype.has.name value and descriptor.
info: >
Map.prototype.has ( key )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Map.prototype.has.name, 'has',
'The value of `Map.prototype.has.name` is `"has"`'
);
verifyNotEnumerable(Map.prototype.has, 'name');
verifyNotWritable(Map.prototype.has, 'name');
verifyConfigurable(Map.prototype.has, '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.7
description: >
-0 and +0 are normalized to +0;
info: >
Map.prototype.has ( key )
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 true.
...
---*/
var map = new Map();
assert.sameValue(map.has(-0), false);
assert.sameValue(map.has(+0), false);
map.set(-0, 42);
assert.sameValue(map.has(-0), true);
assert.sameValue(map.has(+0), true);
map.clear();
map.set(+0, 42);
assert.sameValue(map.has(-0), true);
assert.sameValue(map.has(+0), 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.1.3.7
description: >
Returns true for existing keys, using different key types.
info: >
Map.prototype.has ( key )
5. Repeat for each Record {[[key]], [[value]]} p that is an element of
entries,
i. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true,
return true.
...
features: [Symbol]
---*/
var map = new Map();
assert.sameValue(map.has('str'), false);
assert.sameValue(map.has(1), false);
assert.sameValue(map.has(NaN), false);
assert.sameValue(map.has(true), false);
assert.sameValue(map.has(false), false);
assert.sameValue(map.has({}), false);
assert.sameValue(map.has([]), false);
assert.sameValue(map.has(Symbol()), false);
assert.sameValue(map.has(null), false);
assert.sameValue(map.has(undefined), 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.1.3.7
description: >
Returns true for existing keys, using different key types.
info: >
Map.prototype.has ( key )
5. Repeat for each Record {[[key]], [[value]]} p that is an element of
entries,
i. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true,
return true.
...
features: [Symbol]
---*/
var map = new Map();
var obj = {};
var arr = [];
var symb = Symbol();
map.set('str', undefined);
map.set(1, undefined);
map.set(NaN, undefined);
map.set(true, undefined);
map.set(false, undefined);
map.set(obj, undefined);
map.set(arr, undefined);
map.set(symb, undefined);
map.set(null, undefined);
map.set(undefined, undefined);
assert.sameValue(map.has('str'), true);
assert.sameValue(map.has(1), true);
assert.sameValue(map.has(NaN), true);
assert.sameValue(map.has(true), true);
assert.sameValue(map.has(false), true);
assert.sameValue(map.has(obj), true);
assert.sameValue(map.has(arr), true);
assert.sameValue(map.has(symb), true);
assert.sameValue(map.has(null), true);
assert.sameValue(map.has(undefined), 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.1.3.7
description: >
Throws a TypeError if `this` is not an Object.
info: >
Map.prototype.has ( 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.has.call(false, 1);
});
assert.throws(TypeError, function() {
Map.prototype.has.call(1, 1);
});
assert.throws(TypeError, function() {
Map.prototype.has.call('', 1);
});
assert.throws(TypeError, function() {
Map.prototype.has.call(undefined, 1);
});
assert.throws(TypeError, function() {
Map.prototype.has.call(null, 1);
});
assert.throws(TypeError, function() {
Map.prototype.has.call(Symbol(), 1);
});
assert.throws(TypeError, function() {
var map = new Map();
map.has.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