From dc55c21084c22718d10dec6a1c884812e59d14e1 Mon Sep 17 00:00:00 2001 From: Leonardo Balter <leonardo.balter@gmail.com> Date: Mon, 29 Jun 2015 16:17:07 -0400 Subject: [PATCH] Map.prototype.has --- ...does-not-have-mapdata-internal-slot-set.js | 24 ++++++++++ ...-not-have-mapdata-internal-slot-weakmap.js | 24 ++++++++++ .../does-not-have-mapdata-internal-slot.js | 32 ++++++++++++++ test/built-ins/Map/prototype/has/has.js | 22 ++++++++++ test/built-ins/Map/prototype/has/length.js | 22 ++++++++++ test/built-ins/Map/prototype/has/name.js | 22 ++++++++++ .../Map/prototype/has/normalizes-zero-key.js | 30 +++++++++++++ .../has/return-false-different-key-types.js | 29 ++++++++++++ .../has/return-true-different-key-types.js | 44 +++++++++++++++++++ .../prototype/has/this-not-object-throw.js | 43 ++++++++++++++++++ 10 files changed, 292 insertions(+) create mode 100644 test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-set.js create mode 100644 test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js create mode 100644 test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot.js create mode 100644 test/built-ins/Map/prototype/has/has.js create mode 100644 test/built-ins/Map/prototype/has/length.js create mode 100644 test/built-ins/Map/prototype/has/name.js create mode 100644 test/built-ins/Map/prototype/has/normalizes-zero-key.js create mode 100644 test/built-ins/Map/prototype/has/return-false-different-key-types.js create mode 100644 test/built-ins/Map/prototype/has/return-true-different-key-types.js create mode 100644 test/built-ins/Map/prototype/has/this-not-object-throw.js diff --git a/test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-set.js b/test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..8463ed436a --- /dev/null +++ b/test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-set.js @@ -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); +}); diff --git a/test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js b/test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..a095316c34 --- /dev/null +++ b/test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js @@ -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); +}); diff --git a/test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot.js b/test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..0a43e5b920 --- /dev/null +++ b/test/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot.js @@ -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); +}); diff --git a/test/built-ins/Map/prototype/has/has.js b/test/built-ins/Map/prototype/has/has.js new file mode 100644 index 0000000000..1785c6731d --- /dev/null +++ b/test/built-ins/Map/prototype/has/has.js @@ -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'); diff --git a/test/built-ins/Map/prototype/has/length.js b/test/built-ins/Map/prototype/has/length.js new file mode 100644 index 0000000000..7ad1d6d286 --- /dev/null +++ b/test/built-ins/Map/prototype/has/length.js @@ -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'); diff --git a/test/built-ins/Map/prototype/has/name.js b/test/built-ins/Map/prototype/has/name.js new file mode 100644 index 0000000000..cf6b6f9123 --- /dev/null +++ b/test/built-ins/Map/prototype/has/name.js @@ -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'); diff --git a/test/built-ins/Map/prototype/has/normalizes-zero-key.js b/test/built-ins/Map/prototype/has/normalizes-zero-key.js new file mode 100644 index 0000000000..c8a31e1d3a --- /dev/null +++ b/test/built-ins/Map/prototype/has/normalizes-zero-key.js @@ -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); diff --git a/test/built-ins/Map/prototype/has/return-false-different-key-types.js b/test/built-ins/Map/prototype/has/return-false-different-key-types.js new file mode 100644 index 0000000000..4567fb119d --- /dev/null +++ b/test/built-ins/Map/prototype/has/return-false-different-key-types.js @@ -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); diff --git a/test/built-ins/Map/prototype/has/return-true-different-key-types.js b/test/built-ins/Map/prototype/has/return-true-different-key-types.js new file mode 100644 index 0000000000..21fdb2f723 --- /dev/null +++ b/test/built-ins/Map/prototype/has/return-true-different-key-types.js @@ -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); diff --git a/test/built-ins/Map/prototype/has/this-not-object-throw.js b/test/built-ins/Map/prototype/has/this-not-object-throw.js new file mode 100644 index 0000000000..4664fed22f --- /dev/null +++ b/test/built-ins/Map/prototype/has/this-not-object-throw.js @@ -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); +}); -- GitLab