Skip to content

Commit

Permalink
Object.fromEntries: use verifyProperty; add specification details
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Aug 13, 2018
1 parent 55ffeaf commit ff475fc
Show file tree
Hide file tree
Showing 16 changed files with 286 additions and 25 deletions.
10 changes: 9 additions & 1 deletion test/built-ins/Object/fromEntries/empty-iterable.js
Expand Up @@ -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]
---*/

Expand Down
10 changes: 9 additions & 1 deletion test/built-ins/Object/fromEntries/evaluation-order.js
Expand Up @@ -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]
---*/
Expand Down
Expand Up @@ -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]
---*/

Expand All @@ -19,7 +36,7 @@ var iterable = {
advanced = true;
return {
done: false,
value: 'null',
value: null,
};
},
return: function() {
Expand Down
Expand Up @@ -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]
---*/

Expand Down
Expand Up @@ -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]
---*/

Expand Down
Expand Up @@ -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]
---*/

Expand Down
@@ -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');
Expand Up @@ -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]
---*/

Expand Down
Expand Up @@ -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]
---*/

Expand Down
Expand Up @@ -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]
---*/

Expand Down
Expand Up @@ -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]
---*/

Expand Down
11 changes: 6 additions & 5 deletions test/built-ins/Object/fromEntries/length.js
Expand Up @@ -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
});
11 changes: 6 additions & 5 deletions test/built-ins/Object/fromEntries/name.js
Expand Up @@ -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
});
9 changes: 8 additions & 1 deletion test/built-ins/Object/fromEntries/requires-argument.js
Expand Up @@ -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]
---*/

Expand Down

0 comments on commit ff475fc

Please sign in to comment.