-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #453 from ljharb/object_values_entries
Object.{values,entries} tests
- Loading branch information
Showing
34 changed files
with
744 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (C) 2015 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Object.entries should perform observable operations in the correct order | ||
es7id: pending | ||
author: Jordan Harband | ||
features: [Proxy] | ||
---*/ | ||
|
||
var log = ""; | ||
var object = { a: 0, b: 0, c: 0 }; | ||
var handler = { | ||
get: function (target, propertyKey, receiver) { | ||
assert.sameValue(target, object, "get target"); | ||
assert.sameValue(receiver, proxy, "get receiver"); | ||
log += "|get:" + propertyKey; | ||
return target[propertyKey]; | ||
}, | ||
getOwnPropertyDescriptor: function (target, propertyKey) { | ||
assert.sameValue(target, object, "getOwnPropertyDescriptor"); | ||
log += "|getOwnPropertyDescriptor:" + propertyKey; | ||
return Object.getOwnPropertyDescriptor(target, propertyKey); | ||
}, | ||
ownKeys: function (target) { | ||
assert.sameValue(target, object, "ownKeys"); | ||
log += "|ownKeys"; | ||
return Object.getOwnPropertyNames(target); | ||
}, | ||
deleteProperty: function (oTarget, sKey) { | ||
throw new Test262Error('properties should not be deleted'); | ||
}, | ||
defineProperty: function (oTarget, sKey, oDesc) { | ||
throw new Test262Error('properties should not be defined'); | ||
}, | ||
set: function (oTarget, sKey, vValue) { | ||
throw new Test262Error('properties should not be assigned'); | ||
} | ||
}; | ||
var check = { | ||
get: function (target, propertyKey, receiver) { | ||
assert(propertyKey in target, "handler check: " + propertyKey); | ||
return target[propertyKey]; | ||
} | ||
}; | ||
var proxy = new Proxy(object, new Proxy(handler, check)); | ||
var result = Object.entries(proxy); | ||
assert.sameValue(log, "|ownKeys|getOwnPropertyDescriptor:a|get:a|getOwnPropertyDescriptor:b|get:b|getOwnPropertyDescriptor:c|get:c", log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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 perform observable operations in the correct order | ||
es7id: pending | ||
author: Jordan Harband | ||
features: [Proxy] | ||
---*/ | ||
|
||
var log = ""; | ||
var object = { a: 0, b: 0, c: 0 }; | ||
var handler = { | ||
get: function (target, propertyKey, receiver) { | ||
assert.sameValue(target, object, "get target"); | ||
assert.sameValue(receiver, proxy, "get receiver"); | ||
log += "|get:" + propertyKey; | ||
return target[propertyKey]; | ||
}, | ||
getOwnPropertyDescriptor: function (target, propertyKey) { | ||
assert.sameValue(target, object, "getOwnPropertyDescriptor"); | ||
log += "|getOwnPropertyDescriptor:" + propertyKey; | ||
return Object.getOwnPropertyDescriptor(target, propertyKey); | ||
}, | ||
ownKeys: function (target) { | ||
assert.sameValue(target, object, "ownKeys"); | ||
log += "|ownKeys"; | ||
return Object.getOwnPropertyNames(target); | ||
}, | ||
deleteProperty: function (oTarget, sKey) { | ||
throw new Test262Error('properties should not be deleted'); | ||
}, | ||
defineProperty: function (oTarget, sKey, oDesc) { | ||
throw new Test262Error('properties should not be defined'); | ||
}, | ||
set: function (oTarget, sKey, vValue) { | ||
throw new Test262Error('properties should not be assigned'); | ||
} | ||
}; | ||
var check = { | ||
get: function (target, propertyKey, receiver) { | ||
assert(propertyKey in target, "handler check: " + propertyKey); | ||
return target[propertyKey]; | ||
} | ||
}; | ||
var proxy = new Proxy(object, new Proxy(handler, check)); | ||
var result = Object.values(proxy); | ||
assert.sameValue(log, "|ownKeys|getOwnPropertyDescriptor:a|get:a|getOwnPropertyDescriptor:b|get:b|getOwnPropertyDescriptor:c|get:c", log); |
21 changes: 21 additions & 0 deletions
21
test/built-ins/object/entries/exception-during-enumeration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.entries should terminate if getting a value throws an exception | ||
es7id: pending | ||
author: Jordan Harband | ||
---*/ | ||
|
||
var trappedKey = { | ||
get a() { | ||
throw new RangeError('This error should be re-thrown'); | ||
}, | ||
get b() { | ||
$ERROR('Should not try to get the second element'); | ||
} | ||
}; | ||
|
||
assert.throws(RangeError, function () { | ||
Object.entries(trappedKey); | ||
}); |
16 changes: 16 additions & 0 deletions
16
test/built-ins/object/entries/exception-not-object-coercible.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.entries should fail if given a null or undefined value | ||
es7id: pending | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.throws(TypeError, function () { | ||
Object.entries(null); | ||
}); | ||
|
||
assert.throws(TypeError, function () { | ||
Object.entries(undefined); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.entries should have length 1 | ||
es7id: pending | ||
author: Jordan Harband | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
assert.sameValue(Object.entries.length, 1, 'Expected Object.entries.length to be 1'); | ||
|
||
verifyNotEnumerable(Object.entries, 'length'); | ||
verifyNotWritable(Object.entries, 'length'); | ||
verifyConfigurable(Object.entries, 'length'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (C) 2015 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Object.entries should have name property with value 'entries' | ||
es7id: pending | ||
author: Jordan Harband | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
assert.sameValue( | ||
Object.entries.name, | ||
'entries', | ||
'Expected Object.entries.name to be "entries"' | ||
); | ||
|
||
verifyNotEnumerable(Object.entries, 'name'); | ||
verifyNotWritable(Object.entries, 'name'); | ||
verifyConfigurable(Object.entries, 'name'); |
13 changes: 13 additions & 0 deletions
13
test/built-ins/object/entries/function-property-descriptor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.entries should be writable, non-enumerable, and configurable | ||
es7id: pending | ||
author: Jordan Harband | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
verifyNotEnumerable(Object, 'entries'); | ||
verifyWritable(Object, 'entries'); | ||
verifyConfigurable(Object, 'entries'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2015 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Object.entries does not see a new element added by a getter that is hit during iteration | ||
es7id: pending | ||
author: Jordan Harband | ||
---*/ | ||
|
||
var bAddsC = { | ||
a: 'A', | ||
get b() { | ||
this.c = 'C'; | ||
return 'B'; | ||
} | ||
}; | ||
|
||
var result = Object.entries(bAddsC); | ||
|
||
assert.sameValue(Array.isArray(result), true, 'result is an array'); | ||
assert.sameValue(result.length, 2, 'result has 2 items'); | ||
|
||
assert.sameValue(Array.isArray(result[0]), true, 'first entry is an array'); | ||
assert.sameValue(Array.isArray(result[1]), true, 'second entry is an array'); | ||
|
||
assert.sameValue(result[0][0], 'a', 'first entry has key "a"'); | ||
assert.sameValue(result[0][1], 'A', 'first entry has value "A"'); | ||
assert.sameValue(result[1][0], 'b', 'second entry has key "b"'); | ||
assert.sameValue(result[1][1], 'B', 'second entry has value "B"'); |
32 changes: 32 additions & 0 deletions
32
test/built-ins/object/entries/getter-making-future-key-nonenumerable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (C) 2015 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Object.entries does not see an element made non-enumerable by a getter that is hit during iteration | ||
es7id: pending | ||
author: Jordan Harband | ||
---*/ | ||
|
||
var bDeletesC = { | ||
a: 'A', | ||
get b() { | ||
Object.defineProperty(this, 'c', { | ||
enumerable: false | ||
}); | ||
return 'B'; | ||
}, | ||
c: 'C' | ||
}; | ||
|
||
var result = Object.entries(bDeletesC); | ||
|
||
assert.sameValue(Array.isArray(result), true, 'result is an array'); | ||
assert.sameValue(result.length, 2, 'result has 2 items'); | ||
|
||
assert.sameValue(Array.isArray(result[0]), true, 'first entry is an array'); | ||
assert.sameValue(Array.isArray(result[1]), true, 'second entry is an array'); | ||
|
||
assert.sameValue(result[0][0], 'a', 'first entry has key "a"'); | ||
assert.sameValue(result[0][1], 'A', 'first entry has value "A"'); | ||
assert.sameValue(result[1][0], 'b', 'second entry has key "b"'); | ||
assert.sameValue(result[1][1], 'B', 'second entry has value "B"'); |
30 changes: 30 additions & 0 deletions
30
test/built-ins/object/entries/getter-removing-future-key.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2015 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Object.entries does not see an element removed by a getter that is hit during iteration | ||
es7id: pending | ||
author: Jordan Harband | ||
---*/ | ||
|
||
var bDeletesC = { | ||
a: 'A', | ||
get b() { | ||
delete this.c; | ||
return 'B'; | ||
}, | ||
c: 'C' | ||
}; | ||
|
||
var result = Object.entries(bDeletesC); | ||
|
||
assert.sameValue(Array.isArray(result), true, 'result is an array'); | ||
assert.sameValue(result.length, 2, 'result has 2 items'); | ||
|
||
assert.sameValue(Array.isArray(result[0]), true, 'first entry is an array'); | ||
assert.sameValue(Array.isArray(result[1]), true, 'second entry is an array'); | ||
|
||
assert.sameValue(result[0][0], 'a', 'first entry has key "a"'); | ||
assert.sameValue(result[0][1], 'A', 'first entry has value "A"'); | ||
assert.sameValue(result[1][0], 'b', 'second entry has key "b"'); | ||
assert.sameValue(result[1][1], 'B', 'second entry has value "B"'); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/object/entries/inherited-properties-omitted.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2015 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Object.entries does not see inherited properties. | ||
es7id: pending | ||
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.entries(f); | ||
|
||
assert.sameValue(Array.isArray(result), true, 'result is an array'); | ||
assert.sameValue(result.length, 2, 'result has 2 items'); | ||
|
||
assert.sameValue(Array.isArray(result[0]), true, 'first entry is an array'); | ||
assert.sameValue(Array.isArray(result[1]), true, 'second entry is an array'); | ||
|
||
assert.sameValue(result[0][0], 'b', 'first entry has key "b"'); | ||
assert.sameValue(result[0][1], f.b, 'first entry has value f.b'); | ||
assert.sameValue(result[1][0], 'c', 'second entry has key "c"'); | ||
assert.sameValue(result[1][1], f.c, 'second entry has value f.c'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.entries accepts boolean primitives. | ||
es7id: pending | ||
author: Jordan Harband | ||
---*/ | ||
|
||
var trueResult = Object.entries(true); | ||
|
||
assert.sameValue(Array.isArray(trueResult), true, 'trueResult is an array'); | ||
assert.sameValue(trueResult.length, 0, 'trueResult has 0 items'); | ||
|
||
var falseResult = Object.entries(false); | ||
|
||
assert.sameValue(Array.isArray(falseResult), true, 'falseResult is an array'); | ||
assert.sameValue(falseResult.length, 0, 'falseResult has 0 items'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.entries accepts number primitives. | ||
es7id: pending | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.sameValue(Object.entries(0).length, 0, '0 has zero entries'); | ||
assert.sameValue(Object.entries(-0).length, 0, '-0 has zero entries'); | ||
assert.sameValue(Object.entries(Infinity).length, 0, 'Infinity has zero entries'); | ||
assert.sameValue(Object.entries(-Infinity).length, 0, '-Infinity has zero entries'); | ||
assert.sameValue(Object.entries(NaN).length, 0, 'NaN has zero entries'); | ||
assert.sameValue(Object.entries(Math.PI).length, 0, 'Math.PI has zero entries'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (C) 2015 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: Object.entries accepts string primitives. | ||
es7id: pending | ||
author: Jordan Harband | ||
---*/ | ||
|
||
var result = Object.entries('abc'); | ||
|
||
assert.sameValue(Array.isArray(result), true, 'result is an array'); | ||
assert.sameValue(result.length, 3, 'result has 3 items'); | ||
|
||
assert.sameValue(result[0][0], '0', 'first entry has key "0"'); | ||
assert.sameValue(result[0][1], 'a', 'first entry has value "a"'); | ||
assert.sameValue(result[1][0], '1', 'second entry has key "1"'); | ||
assert.sameValue(result[1][1], 'b', 'second entry has value "b"'); | ||
assert.sameValue(result[2][0], '2', 'third entry has key "2"'); | ||
assert.sameValue(result[2][1], 'c', 'third entry has value "c"'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.entries accepts Symbol primitives. | ||
es7id: pending | ||
author: Jordan Harband | ||
features: [Symbol] | ||
---*/ | ||
|
||
var result = Object.entries(Symbol()); | ||
|
||
assert.sameValue(Array.isArray(result), true, 'result is an array'); | ||
assert.sameValue(result.length, 0, 'result has 0 items'); |
Oops, something went wrong.