mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 07:54:41 +02:00
Add Object.values tests
This commit is contained in:
parent
b517ca7119
commit
e459048f22
21
test/built-ins/object/values/exception-during-enumeration.js
Normal file
21
test/built-ins/object/values/exception-during-enumeration.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values should terminate if getting a value throws an exception
|
||||||
|
includes: [Test262Error.js]
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var trappedKey = {
|
||||||
|
get a() {
|
||||||
|
throw new Test262Error('This error should be re-thrown');
|
||||||
|
},
|
||||||
|
get b() {
|
||||||
|
$ERROR('Should not try to get the second element');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function () {
|
||||||
|
Object.values(trappedKey);
|
||||||
|
});
|
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values should fail if given a null or undefined value
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function () {
|
||||||
|
Object.values(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function () {
|
||||||
|
Object.values(undefined);
|
||||||
|
});
|
14
test/built-ins/object/values/function-length.js
Normal file
14
test/built-ins/object/values/function-length.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values should have length 1
|
||||||
|
author: Jordan Harband
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(Object.values.length, 1, 'Expected Object.values.length to be 1');
|
||||||
|
|
||||||
|
verifyNotEnumerable(Object.values, 'length');
|
||||||
|
verifyNotWritable(Object.values, 'length');
|
||||||
|
verifyConfigurable(Object.values, 'length');
|
18
test/built-ins/object/values/function-name.js
Normal file
18
test/built-ins/object/values/function-name.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values should have name property with value 'values'
|
||||||
|
author: Jordan Harband
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Object.values.name,
|
||||||
|
'values',
|
||||||
|
'Expected Object.values.name to be "values"'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Object.values, 'name');
|
||||||
|
verifyNotWritable(Object.values, 'name');
|
||||||
|
verifyConfigurable(Object.values, 'name');
|
12
test/built-ins/object/values/function-property-descriptor.js
Normal file
12
test/built-ins/object/values/function-property-descriptor.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values should be writable, non-enumerable, and configurable
|
||||||
|
author: Jordan Harband
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyConfigurable(Object, 'values');
|
||||||
|
verifyNotEnumerable(Object, 'values');
|
||||||
|
verifyWritable(Object, 'values');
|
24
test/built-ins/object/values/getter-adding-key.js
Normal file
24
test/built-ins/object/values/getter-adding-key.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values sees a new element added by a getter that is hit during iteration
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var bAddsC = {
|
||||||
|
a: 'A',
|
||||||
|
get b() {
|
||||||
|
this.c = 'C';
|
||||||
|
return 'B';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = Object.values(bAddsC);
|
||||||
|
|
||||||
|
assert.sameValue(Array.isArray(result), true, 'result is an array');
|
||||||
|
assert.sameValue(result.length, 3, 'result has 3 items');
|
||||||
|
|
||||||
|
assert.sameValue(result[0], 'A', 'first value is "A"');
|
||||||
|
assert.sameValue(result[1], 'B', 'second value is "B"');
|
||||||
|
assert.sameValue(result[2], 'C', 'third value is "C"');
|
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values does not see an element made non-enumerable by a getter that is hit during iteration
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var bDeletesC = {
|
||||||
|
a: 'A',
|
||||||
|
get b() {
|
||||||
|
Object.defineProperty(this, 'c', {
|
||||||
|
enumerable: false
|
||||||
|
});
|
||||||
|
return 'B';
|
||||||
|
},
|
||||||
|
c: 'C'
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = Object.values(bDeletesC);
|
||||||
|
|
||||||
|
assert.sameValue(Array.isArray(result), true, 'result is an array');
|
||||||
|
assert.sameValue(result.length, 2, 'result has 2 items');
|
||||||
|
|
||||||
|
assert.sameValue(result[0], 'A', 'first value is "A"');
|
||||||
|
assert.sameValue(result[1], 'B', 'second value is "B"');
|
24
test/built-ins/object/values/getter-removing-future-key.js
Normal file
24
test/built-ins/object/values/getter-removing-future-key.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values does not see an element removed by a getter that is hit during iteration
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var bDeletesC = {
|
||||||
|
a: 'A',
|
||||||
|
get b() {
|
||||||
|
delete this.c;
|
||||||
|
return 'B';
|
||||||
|
},
|
||||||
|
c: 'C'
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = Object.values(bDeletesC);
|
||||||
|
|
||||||
|
assert.sameValue(Array.isArray(result), true, 'result is an array');
|
||||||
|
assert.sameValue(result.length, 2, 'result has 2 items');
|
||||||
|
|
||||||
|
assert.sameValue(result[0], 'A', 'first value is "A"');
|
||||||
|
assert.sameValue(result[1], 'B', 'second value is "B"');
|
23
test/built-ins/object/values/inherited-properties-omitted.js
Normal file
23
test/built-ins/object/values/inherited-properties-omitted.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values does not see inherited properties.
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var F = function G() {};
|
||||||
|
F.prototype.a = {};
|
||||||
|
F.prototype.b = {};
|
||||||
|
|
||||||
|
var f = new F();
|
||||||
|
f.b = {}; // shadow the prototype
|
||||||
|
f.c = {}; // solely an own property
|
||||||
|
|
||||||
|
var result = Object.values(f);
|
||||||
|
|
||||||
|
assert.sameValue(Array.isArray(result), true, 'result is an array');
|
||||||
|
assert.sameValue(result.length, 2, 'result has 2 items');
|
||||||
|
|
||||||
|
assert.sameValue(result[0], f.b, 'first value is f.b');
|
||||||
|
assert.sameValue(result[1], f.c, 'second value is f.c');
|
17
test/built-ins/object/values/primitive-booleans.js
Normal file
17
test/built-ins/object/values/primitive-booleans.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values accepts boolean primitives.
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var trueResult = Object.values(true);
|
||||||
|
|
||||||
|
assert.sameValue(Array.isArray(trueResult), true, 'trueResult is an array');
|
||||||
|
assert.sameValue(trueResult.length, 0, 'trueResult has 0 items');
|
||||||
|
|
||||||
|
var falseResult = Object.values(false);
|
||||||
|
|
||||||
|
assert.sameValue(Array.isArray(falseResult), true, 'falseResult is an array');
|
||||||
|
assert.sameValue(falseResult.length, 0, 'falseResult has 0 items');
|
14
test/built-ins/object/values/primitive-numbers.js
Normal file
14
test/built-ins/object/values/primitive-numbers.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values accepts number primitives.
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(Object.values(0).length, 0, '0 has zero values');
|
||||||
|
assert.sameValue(Object.values(-0).length, 0, '-0 has zero values');
|
||||||
|
assert.sameValue(Object.values(Infinity).length, 0, 'Infinity has zero values');
|
||||||
|
assert.sameValue(Object.values(-Infinity).length, 0, '-Infinity has zero values');
|
||||||
|
assert.sameValue(Object.values(NaN).length, 0, 'NaN has zero values');
|
||||||
|
assert.sameValue(Object.values(Math.PI).length, 0, 'Math.PI has zero values');
|
16
test/built-ins/object/values/primitive-strings.js
Normal file
16
test/built-ins/object/values/primitive-strings.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values accepts string primitives.
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = Object.values('abc');
|
||||||
|
|
||||||
|
assert.sameValue(Array.isArray(result), true, 'result is an array');
|
||||||
|
assert.sameValue(result.length, 3, 'result has 3 items');
|
||||||
|
|
||||||
|
assert.sameValue(result[0], 'a', 'first value is "a"');
|
||||||
|
assert.sameValue(result[1], 'b', 'second value is "b"');
|
||||||
|
assert.sameValue(result[2], 'c', 'second value is "c"');
|
13
test/built-ins/object/values/primitive-symbols.js
Normal file
13
test/built-ins/object/values/primitive-symbols.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values accepts Symbol primitives.
|
||||||
|
author: Jordan Harband
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = Object.values(Symbol());
|
||||||
|
|
||||||
|
assert.sameValue(Array.isArray(result), true, 'result is an array');
|
||||||
|
assert.sameValue(result.length, 0, 'result has 0 items');
|
24
test/built-ins/object/values/symbols-omitted.js
Normal file
24
test/built-ins/object/values/symbols-omitted.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Object.values does not include Symbol keys.
|
||||||
|
author: Jordan Harband
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var value = {};
|
||||||
|
var enumSym = Symbol('enum');
|
||||||
|
var nonEnumSym = Symbol('nonenum');
|
||||||
|
var symValue = Symbol('value');
|
||||||
|
|
||||||
|
var obj = { key: symValue };
|
||||||
|
obj[enumSym] = value;
|
||||||
|
Object.defineProperty(obj, nonEnumSym, { enumerable: false, value: value });
|
||||||
|
|
||||||
|
var result = Object.values(obj);
|
||||||
|
|
||||||
|
assert.sameValue(Array.isArray(result), true, 'result is an array');
|
||||||
|
assert.sameValue(result.length, 1, 'result has 1 item');
|
||||||
|
|
||||||
|
assert.sameValue(result[0][1], symValue, 'first value is `symValue`');
|
18
test/built-ins/object/values/tamper-with-global-object.js
Normal file
18
test/built-ins/object/values/tamper-with-global-object.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Object.values should not have its behavior impacted by modifications to the global property Object
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function fakeObject() {
|
||||||
|
$ERROR('The overriden version of Object was called!');
|
||||||
|
}
|
||||||
|
|
||||||
|
var global = Function('return this;')();
|
||||||
|
global.Object = fakeObject;
|
||||||
|
|
||||||
|
assert.sameValue(Object, fakeObject, 'Sanity check failed: could not modify the global Object');
|
||||||
|
assert.sameValue(Object.values(1).length, 0, 'Expected number primitive to have zero values');
|
17
test/built-ins/object/values/tamper-with-object-keys.js
Normal file
17
test/built-ins/object/values/tamper-with-object-keys.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2015 Jordan Harband. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Object.values should not have its behavior impacted by modifications to Object.keys
|
||||||
|
author: Jordan Harband
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function fakeObjectKeys() {
|
||||||
|
$ERROR('The overriden version of Object.keys was called!');
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys = fakeObjectKeys;
|
||||||
|
|
||||||
|
assert.sameValue(Object.keys, fakeObjectKeys, 'Sanity check failed: could not modify the global Object.keys');
|
||||||
|
assert.sameValue(Object.values({ a: 1 }).length, 1, 'Expected object with 1 key to have 1 value');
|
Loading…
x
Reference in New Issue
Block a user