mirror of https://github.com/tc39/test262.git
Map.prototype.has
This commit is contained in:
parent
b103418a17
commit
dc55c21084
|
@ -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.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);
|
||||
});
|
24
test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js
vendored
Normal file
24
test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js
vendored
Normal 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.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);
|
||||
});
|
|
@ -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.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);
|
||||
});
|
|
@ -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.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');
|
|
@ -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.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');
|
|
@ -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.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');
|
|
@ -0,0 +1,30 @@
|
|||
// 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);
|
|
@ -0,0 +1,29 @@
|
|||
// 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);
|
|
@ -0,0 +1,44 @@
|
|||
// 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);
|
|
@ -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.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);
|
||||
});
|
Loading…
Reference in New Issue