mirror of https://github.com/tc39/test262.git
Add test for for-in order (#2432)
* Add EnumerateObjectProperties tests for builtins which use it * Add tests for EnumerateObjectProperties for for-in * Add feature flag for for-in-order
This commit is contained in:
parent
f7ad2953ed
commit
cadd47aa5f
|
@ -162,6 +162,10 @@ AggregateError
|
|||
# https://github.com/tc39/proposal-string-replaceall
|
||||
String.prototype.replaceAll
|
||||
|
||||
# Enumeration order for for-in
|
||||
# https://github.com/tc39/proposal-for-in-order
|
||||
for-in-order
|
||||
|
||||
## Standard language features
|
||||
#
|
||||
# Language features that have been included in a published version of the
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2019 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-internalizejsonproperty
|
||||
description: JSON.parse reviver call order
|
||||
features: [for-in-order]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var calls = [];
|
||||
function reviver(name, val) {
|
||||
calls.push(name);
|
||||
return val;
|
||||
}
|
||||
|
||||
JSON.parse('{"p1":0,"p2":0,"p1":0,"2":0,"1":0}', reviver);
|
||||
|
||||
// The empty string is the _rootName_ in JSON.parse
|
||||
assert.compareArray(calls, ['1', '2', 'p1', 'p2', '']);
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright 2019 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-serializejsonobject
|
||||
description: JSON.stringify property enumeration order
|
||||
features: [for-in-order]
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
p1: 'p1',
|
||||
p2: 'p2',
|
||||
p3: 'p3',
|
||||
};
|
||||
|
||||
// This getter will be triggered during enumeration, but the property it adds should not be enumerated.
|
||||
Object.defineProperty(o, 'add', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
o.extra = 'extra';
|
||||
return 'add';
|
||||
}
|
||||
});
|
||||
|
||||
o.p4 = 'p4';
|
||||
|
||||
o[2] = '2';
|
||||
o[0] = '0';
|
||||
o[1] = '1';
|
||||
|
||||
delete o.p1;
|
||||
delete o.p3;
|
||||
o.p1 = 'p1';
|
||||
|
||||
var actual = JSON.stringify(o);
|
||||
|
||||
var expected = '{"0":"0","1":"1","2":"2","p2":"p2","add":"add","p4":"p4","p1":"p1"}';
|
||||
|
||||
assert.sameValue(actual, expected);
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2019 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.entries
|
||||
description: Object.entries enumeration order
|
||||
features: [for-in-order]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
p1: 'p1',
|
||||
p2: 'p2',
|
||||
p3: 'p3',
|
||||
};
|
||||
|
||||
// This getter will be triggered during enumeration, but the property it adds should not be enumerated.
|
||||
Object.defineProperty(o, 'add', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
o.extra = 'extra';
|
||||
return 'add';
|
||||
}
|
||||
});
|
||||
|
||||
o.p4 = 'p4';
|
||||
|
||||
o[2] = '2';
|
||||
o[0] = '0';
|
||||
o[1] = '1';
|
||||
|
||||
delete o.p1;
|
||||
delete o.p3;
|
||||
o.p1 = 'p1';
|
||||
|
||||
|
||||
var actual = Object.entries(o).map(function(e) { return e[0]; });
|
||||
|
||||
var expected = ['0', '1', '2', 'p2', 'add', 'p4', 'p1'];
|
||||
|
||||
assert.compareArray(actual, expected);
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2019 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.keys
|
||||
description: Object.keys enumeration order
|
||||
features: [for-in-order]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
p1: 'p1',
|
||||
p2: 'p2',
|
||||
p3: 'p3',
|
||||
};
|
||||
o.p4 = 'p4';
|
||||
|
||||
o[2] = '2';
|
||||
o[0] = '0';
|
||||
o[1] = '1';
|
||||
|
||||
delete o.p1;
|
||||
delete o.p3;
|
||||
o.p1 = 'p1';
|
||||
|
||||
var actual = Object.keys(o);
|
||||
|
||||
var expected = ['0', '1', '2', 'p2', 'p4', 'p1'];
|
||||
|
||||
assert.compareArray(actual, expected);
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2019 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-object.values
|
||||
description: Object.values enumeration order
|
||||
features: [for-in-order]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
p1: 'p1',
|
||||
p2: 'p2',
|
||||
p3: 'p3',
|
||||
};
|
||||
|
||||
// This getter will be triggered during enumeration, but the property it adds should not be enumerated.
|
||||
Object.defineProperty(o, 'add', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
o.extra = 'extra';
|
||||
return 'add';
|
||||
}
|
||||
});
|
||||
|
||||
o.p4 = 'p4';
|
||||
|
||||
o[2] = '2';
|
||||
o[0] = '0';
|
||||
o[1] = '1';
|
||||
|
||||
delete o.p1;
|
||||
delete o.p3;
|
||||
o.p1 = 'p1';
|
||||
|
||||
|
||||
var actual = Object.values(o);
|
||||
|
||||
var expected = ['0', '1', '2', 'p2', 'add', 'p4', 'p1'];
|
||||
|
||||
assert.compareArray(actual, expected);
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2019 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-enumerate-object-properties
|
||||
description: Enumerable properties the prototype which are shadowed by non-enumerable properties on the object are not enumerated
|
||||
features: [for-in-order]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var proto = {
|
||||
p2: 'p2',
|
||||
};
|
||||
|
||||
var o = Object.create(proto, {
|
||||
'p1': {
|
||||
value: 'p1',
|
||||
enumerable: true,
|
||||
},
|
||||
'p2': {
|
||||
value: 'p1',
|
||||
enumerable: false,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
var keys = [];
|
||||
for (var key in o) {
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
assert.compareArray(keys, ['p1']);
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright 2019 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-enumerate-object-properties
|
||||
description: Properties added to the object during iteration are not enumerated
|
||||
features: [for-in-order]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
p1: 'p1',
|
||||
p2: 'p2',
|
||||
p3: 'p3',
|
||||
};
|
||||
|
||||
var keys = [];
|
||||
for (var key in o) {
|
||||
if (key === 'p1') {
|
||||
o.p4 = 'p4';
|
||||
}
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
assert.compareArray(keys, ['p1', 'p2', 'p3']);
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2019 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-enumerate-object-properties
|
||||
description: Properties on the prototype are enumerated after properties on the object
|
||||
features: [for-in-order]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var proto = {
|
||||
p4: 'p4',
|
||||
};
|
||||
|
||||
var o = {
|
||||
p1: 'p1',
|
||||
p2: 'p2',
|
||||
p3: 'p3',
|
||||
};
|
||||
|
||||
Object.setPrototypeOf(o, proto);
|
||||
|
||||
var keys = [];
|
||||
for (var key in o) {
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
assert.compareArray(keys, ['p1', 'p2', 'p3', 'p4']);
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2019 Kevin Gibbons. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-enumerate-object-properties
|
||||
description: Property enumeration order for simple objects
|
||||
features: [for-in-order]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
p1: 'p1',
|
||||
p2: 'p2',
|
||||
p3: 'p3',
|
||||
};
|
||||
|
||||
o.p4 = 'p4';
|
||||
|
||||
o[2] = '2';
|
||||
o[0] = '0';
|
||||
o[1] = '1';
|
||||
|
||||
delete o.p1;
|
||||
delete o.p3;
|
||||
o.p1 = 'p1';
|
||||
|
||||
|
||||
var keys = [];
|
||||
for (var key in o) {
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
assert.compareArray(keys, ['0', '1', '2', 'p2', 'p4', 'p1']);
|
Loading…
Reference in New Issue