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

Map.prototype.size

parent 7ee11aae
Branches
No related tags found
No related merge requests found
Showing
with 316 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.10
description: >
Throws a TypeError if `this` is a Set object.
info: >
Map.prototype.set ( key , value )
...
3. If M does not have a [[MapData]] internal slot, throw a TypeError
exception.
...
features: [Set]
---*/
var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
var map = new Map();
// Does not throw
descriptor.get.call(map);
assert.throws(TypeError, function() {
descriptor.get.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.1.3.9
description: >
Throws a TypeError if `this` is a WeakMap object.
info: >
get Map.prototype.size
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
3. If M does not have a [[MapData]] internal slot, throw a TypeError
exception.
...
features: [WeakMap]
---*/
var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
var map = new Map();
// Does not throw
descriptor.get.call(map);
assert.throws(TypeError, function() {
descriptor.get.call(new WeakMap());
});
// 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.9
description: >
Throws a TypeError if `this` object does not have a [[MapData]] internal slot.
info: >
get Map.prototype.size
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
3. If M does not have a [[MapData]] internal slot, throw a TypeError
exception.
...
---*/
var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
var map = new Map();
// Does not throw
descriptor.get.call(map);
assert.throws(TypeError, function() {
descriptor.get.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.1.3.10
description: >
Map.prototype.size.length value and descriptor.
info: >
get Map.prototype.size
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
assert.sameValue(
descriptor.get.length, 0,
'The value of `Map.prototype.size.length` is `0`'
);
verifyNotEnumerable(descriptor.get, 'length');
verifyNotWritable(descriptor.get, 'length');
verifyConfigurable(descriptor.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.1.3.10
description: >
Map.prototype.size.name value and descriptor.
info: >
get Map.prototype.size
17 ECMAScript Standard Built-in Objects
Functions that are specified as get or set accessor functions of built-in
properties have "get " or "set " prepended to the property name string.
includes: [propertyHelper.js]
---*/
var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
assert.sameValue(descriptor.get.name,
'get size',
'The value of `descriptor.get.name` is `get size`'
);
verifyNotEnumerable(descriptor.get, 'name');
verifyNotWritable(descriptor.get, 'name');
verifyConfigurable(descriptor.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.1.3.10
description: >
Returns count of present values before and after using `set` and `clear`.
info: >
get Map.prototype.size
5. Let count be 0.
6. For each Record {[[key]], [[value]]} p that is an element of entries
a. If p.[[key]] is not empty, set count to count+1.
---*/
var map = new Map();
assert.sameValue(map.size, 0, 'The value of `map.size` is `0`');
map.set(1, 1);
map.set(2, 2);
assert.sameValue(
map.size, 2,
'The value of `map.size` is `2`'
);
map.clear();
assert.sameValue(
map.size, 0,
'The value of `map.size` is `0`, after executing `map.clear()`'
);
// 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.10
description: >
Returns count of present values before and after using `set` and `delete`.
info: >
get Map.prototype.size
5. Let count be 0.
6. For each Record {[[key]], [[value]]} p that is an element of entries
a. If p.[[key]] is not empty, set count to count+1.
---*/
var map = new Map();
assert.sameValue(map.size, 0, 'The value of `map.size` is `0`');
map.set(1, 1);
assert.sameValue(
map.size, 1,
'The value of `map.size` is `1`, after executing `map.set(1, 1)`'
);
map.delete(1);
assert.sameValue(
map.size, 0,
'The value of `map.size` is `0`, after executing `map.delete(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.10
description: >
Returns count of present values inserted with set.
info: >
get Map.prototype.size
5. Let count be 0.
6. For each Record {[[key]], [[value]]} p that is an element of entries
a. If p.[[key]] is not empty, set count to count+1.
features: [Symbol]
---*/
var map = new Map();
map.set(0, undefined);
map.set(undefined, undefined);
map.set(false, undefined);
map.set(NaN, undefined);
map.set(null, undefined);
map.set('', undefined);
map.set(Symbol(), undefined);
assert.sameValue(map.size, 7, 'The value of `map.size` is `7`');
// 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.10
description: >
Returns count of present values inserted via iterable argument.
info: >
get Map.prototype.size
5. Let count be 0.
6. For each Record {[[key]], [[value]]} p that is an element of entries
a. If p.[[key]] is not empty, set count to count+1.
features: [Symbol]
---*/
var map = new Map([
[0, undefined],
[undefined, undefined],
[false, undefined],
[NaN, undefined],
[null, undefined],
['', undefined],
[Symbol(), undefined],
]);
assert.sameValue(map.size, 7, 'The value of `map.size` is `7`');
// 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.10
description: >
Property type and descriptor.
info: >
get Map.prototype.size
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
assert.sameValue(
typeof descriptor.get,
'function',
'typeof descriptor.get is function'
);
assert.sameValue(
typeof descriptor.set,
'undefined',
'typeof descriptor.set is undefined'
);
verifyNotEnumerable(Map.prototype, 'size');
verifyConfigurable(Map.prototype, 'size');
// 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.10
description: >
Throws a TypeError if `this` is not an Object.
info: >
get Map.prototype.size
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
3. If M does not have a [[MapData]] internal slot, throw a TypeError
exception.
...
includes: [propertyHelper.js]
---*/
var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size');
assert.throws(TypeError, function() {
descriptor.get.call(1);
});
assert.throws(TypeError, function() {
descriptor.get.call(false);
});
assert.throws(TypeError, function() {
descriptor.get.call(1);
});
assert.throws(TypeError, function() {
descriptor.get.call('');
});
assert.throws(TypeError, function() {
descriptor.get.call(undefined);
});
assert.throws(TypeError, function() {
descriptor.get.call(null);
});
assert.throws(TypeError, function() {
descriptor.get.call(Symbol());
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment