Object.fromEntries: use verifyProperty; add specification details

This commit is contained in:
Rick Waldron 2018-08-13 12:44:09 -04:00
parent 55ffeaf5cf
commit ff475fce11
16 changed files with 286 additions and 25 deletions

View File

@ -2,8 +2,16 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: When given an empty list, makes an empty object.
esid: sec-object.fromentries
description: When given an empty list, makes an empty object.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
features: [Object.fromEntries]
---*/

View File

@ -2,8 +2,16 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Evaluation order is iterator.next(), get '0', get '1', toPropertyKey, repeat.
esid: sec-object.fromentries
description: Evaluation order is iterator.next(), get '0', get '1', toPropertyKey, repeat.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
includes: [compareArray.js]
features: [Symbol.iterator, Object.fromEntries]
---*/

View File

@ -2,8 +2,25 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Closes iterators when they return entries which are null.
esid: sec-object.fromentries
description: Closes iterators when they return entries which are null.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
AddEntriesFromIterable ( target, iterable, adder )
...
4. Repeat,
...
d. If Type(nextItem) is not Object, then
i. Let error be ThrowCompletion(a newly created TypeError object).
ii. Return ? IteratorClose(iteratorRecord, error).
features: [Symbol.iterator, Object.fromEntries]
---*/
@ -19,7 +36,7 @@ var iterable = {
advanced = true;
return {
done: false,
value: 'null',
value: null,
};
},
return: function() {

View File

@ -2,8 +2,25 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Closes iterators when they return entries which are strings.
esid: sec-object.fromentries
description: Closes iterators when they return entries which are strings.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
AddEntriesFromIterable ( target, iterable, adder )
...
4. Repeat,
...
d. If Type(nextItem) is not Object, then
i. Let error be ThrowCompletion(a newly created TypeError object).
ii. Return ? IteratorClose(iteratorRecord, error).
features: [Symbol.iterator, Object.fromEntries]
---*/

View File

@ -2,8 +2,24 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Closes iterators when accessing an entry's properties throws.
esid: sec-object.fromentries
description: Closes iterators when accessing an entry's key throws.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
AddEntriesFromIterable ( target, iterable, adder )
...
4. Repeat,
...
e. Let k be Get(nextItem, "0").
f. If k is an abrupt completion, return ? IteratorClose(iteratorRecord, k).
features: [Symbol.iterator, Object.fromEntries]
---*/

View File

@ -2,8 +2,24 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Closes iterators when toString on a key throws.
esid: sec-object.fromentries
description: Closes iterators when toString on a key throws.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
AddEntriesFromIterable ( target, iterable, adder )
...
4. Repeat,
...
e. Let k be Get(nextItem, "0").
f. If k is an abrupt completion, return ? IteratorClose(iteratorRecord, k).
features: [Symbol.iterator, Object.fromEntries]
---*/

View File

@ -0,0 +1,64 @@
// Copyright (C) 2018 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.fromentries
description: Closes iterators when accessing an entry's value throws.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
AddEntriesFromIterable ( target, iterable, adder )
...
4. Repeat,
...
g. Let v be Get(nextItem, "1").
h. If v is an abrupt completion, return ? IteratorClose(iteratorRecord, v).
features: [Symbol.iterator, Object.fromEntries]
---*/
function DummyError() {}
var returned = false;
var iterable = {
[Symbol.iterator]: function() {
var advanced = false;
return {
next: function() {
if (advanced) {
throw new Test262Error('should only advance once');
}
advanced = true;
return {
done: false,
value: {
get '0'() {
return 'key';
},
get '1'() {
throw new DummyError();
},
},
};
},
return: function() {
if (returned) {
throw new Test262Error('should only return once');
}
returned = true;
},
};
},
};
assert.throws(DummyError, function() {
Object.fromEntries(iterable);
});
assert(returned, 'iterator should be closed when entry value property access throws');

View File

@ -2,8 +2,33 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Does not close iterators with a `next` method which returns a non-object.
esid: sec-object.fromentries
description: Does not close iterators with a `next` method which returns a non-object.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
AddEntriesFromIterable ( target, iterable, adder )
...
4. Repeat,
a. Let next be ? IteratorStep(iteratorRecord).
IteratorStep ( iteratorRecord )
1. Let result be ? IteratorNext(iteratorRecord).
IteratorNext ( iteratorRecord [ , value ] )
...
3. If Type(result) is not Object, throw a TypeError exception.
features: [Symbol.iterator, Object.fromEntries]
---*/

View File

@ -2,8 +2,33 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Does not close iterators with a `done` accessor which throws.
esid: sec-object.fromentries
description: Does not close iterators with a `done` accessor which throws.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
AddEntriesFromIterable ( target, iterable, adder )
...
4. Repeat,
a. Let next be ? IteratorStep(iteratorRecord).
IteratorStep ( iteratorRecord )
1. Let result be ? IteratorNext(iteratorRecord).
IteratorNext ( iteratorRecord [ , value ] )
...
3. If Type(result) is not Object, throw a TypeError exception.
features: [Symbol.iterator, Object.fromEntries]
---*/

View File

@ -2,8 +2,33 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Does not close iterators with a `next` method which throws.
esid: sec-object.fromentries
description: Does not close iterators with a `next` method which throws.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
AddEntriesFromIterable ( target, iterable, adder )
...
4. Repeat,
a. Let next be ? IteratorStep(iteratorRecord).
IteratorStep ( iteratorRecord )
1. Let result be ? IteratorNext(iteratorRecord).
IteratorNext ( iteratorRecord [ , value ] )
...
3. If Type(result) is not Object, throw a TypeError exception.
features: [Symbol.iterator, Object.fromEntries]
---*/

View File

@ -2,8 +2,26 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Does not close iterators with an uncallable `next` property.
esid: sec-object.fromentries
description: Does not close iterators with an uncallable `next` property.
info: |
Object.fromEntries ( iterable )
...
4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
5. Let adder be CreateBuiltinFunction(stepsDefine, « »).
6. Return ? AddEntriesFromIterable(obj, iterable, adder).
AddEntriesFromIterable ( target, iterable, adder )
...
4. Repeat,
a. Let next be ? IteratorStep(iteratorRecord).
IteratorStep ( iteratorRecord )
1. Let result be ? IteratorNext(iteratorRecord).
features: [Symbol.iterator, Object.fromEntries]
---*/

View File

@ -8,8 +8,9 @@ includes: [propertyHelper.js]
features: [Object.fromEntries]
---*/
assert.sameValue(Object.fromEntries.length, 1);
verifyNotEnumerable(Object.fromEntries, "length");
verifyNotWritable(Object.fromEntries, "length");
verifyConfigurable(Object.fromEntries, "length");
verifyProperty(Object.fromEntries, "length", {
value: 1,
enumerable: false,
writable: false,
configurable: true
});

View File

@ -8,8 +8,9 @@ includes: [propertyHelper.js]
features: [Object.fromEntries]
---*/
assert.sameValue(Object.fromEntries.name, "fromEntries");
verifyNotEnumerable(Object.fromEntries, "name");
verifyNotWritable(Object.fromEntries, "name");
verifyConfigurable(Object.fromEntries, "name");
verifyProperty(Object.fromEntries, "name", {
value: "fromEntries",
enumerable: false,
writable: false,
configurable: true
});

View File

@ -2,8 +2,15 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Throws when called without an argument.
esid: sec-object.fromentries
description: Throws when called without an argument.
info: |
Object.fromEntries ( iterable )
1. Perform ? RequireObjectCoercible(iterable).
...
features: [Object.fromEntries]
---*/

View File

@ -9,6 +9,8 @@ features: [Object.fromEntries]
---*/
var result = Object.fromEntries([['key', 'value']]);
verifyEnumerable(result, 'key');
verifyWritable(result, 'key');
verifyConfigurable(result, 'key');
verifyProperty(result, "key", {
enumerable: true,
writable: true,
configurable: true,
});

View File

@ -0,0 +1,11 @@
// Copyright (C) 2018 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Succeeds when an entry object is a boxed string.
esid: sec-object.fromentries
features: [Object.fromEntries]
---*/
var result = Object.fromEntries([new String('ab')]);
assert.sameValue(result['a'], 'b');