Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions test/built-ins/Promise/allKeyed/capability-executor-not-callable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright (C) 2026 Danial Asaria (Bloomberg LP). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allkeyed
description: >
Throws a TypeError if either resolve or reject capability is not callable.
info: |
Promise.allKeyed ( promises )

...
2. Let promiseCapability be ? NewPromiseCapability(C).

NewPromiseCapability ( C )

...
4. Let executor be a new built-in function object as defined in
GetCapabilitiesExecutor Functions.
5. Set the [[Capability]] internal slot of executor to promiseCapability.
6. Let promise be ? Construct(C, « executor »).
...
8. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception.
9. If IsCallable(promiseCapability.[[Reject]]) is false, throw a TypeError exception.
features: [await-dictionary]
---*/

var checkPoint = "";
function fn1(executor) {
checkPoint += "a";
}
Object.defineProperty(fn1, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allKeyed.call(fn1, {});
}, "executor not called at all");
assert.sameValue(checkPoint, "a", "executor not called at all");

checkPoint = "";
function fn2(executor) {
checkPoint += "a";
executor();
checkPoint += "b";
}
Object.defineProperty(fn2, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allKeyed.call(fn2, {});
}, "executor called with no arguments");
assert.sameValue(checkPoint, "ab", "executor called with no arguments");

checkPoint = "";
function fn3(executor) {
checkPoint += "a";
executor(undefined, undefined);
checkPoint += "b";
}
Object.defineProperty(fn3, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allKeyed.call(fn3, {});
}, "executor called with (undefined, undefined)");
assert.sameValue(checkPoint, "ab", "executor called with (undefined, undefined)");

checkPoint = "";
function fn4(executor) {
checkPoint += "a";
executor(undefined, function() {});
checkPoint += "b";
}
Object.defineProperty(fn4, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allKeyed.call(fn4, {});
}, "executor called with (undefined, function)");
assert.sameValue(checkPoint, "ab", "executor called with (undefined, function)");

checkPoint = "";
function fn5(executor) {
checkPoint += "a";
executor(function() {}, undefined);
checkPoint += "b";
}
Object.defineProperty(fn5, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allKeyed.call(fn5, {});
}, "executor called with (function, undefined)");
assert.sameValue(checkPoint, "ab", "executor called with (function, undefined)");

checkPoint = "";
function fn6(executor) {
checkPoint += "a";
executor(123, "invalid value");
checkPoint += "b";
}
Object.defineProperty(fn6, 'resolve', {
get() { throw new Test262Error(); }
});
assert.throws(TypeError, function() {
Promise.allKeyed.call(fn6, {});
}, "executor called with (Number, String)");
assert.sameValue(checkPoint, "ab", "executor called with (Number, String)");
35 changes: 35 additions & 0 deletions test/built-ins/Promise/allKeyed/ctx-ctor-constructed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2026 Danial Asaria (Bloomberg LP). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allkeyed
description: >
Promise.allKeyed invokes the constructor via Construct (not Call), passing
a single executor argument that is a function with length 2.
info: |
Promise.allKeyed ( promises )

1. Let C be the this value.
2. Let promiseCapability be ? NewPromiseCapability(C).

NewPromiseCapability ( C )

...
6. Let promise be Construct(C, « executor »).
features: [await-dictionary]
---*/

var error = new Test262Error();

function Constructor(executor) {
if (new.target !== Constructor) {
throw error;
}
assert.sameValue(arguments.length, 1, "expected exactly one argument");
assert.sameValue(typeof executor, "function", "executor is a function");
assert.sameValue(executor.length, 2, "executor.length === 2");
executor(function() {}, function() {});
}
Constructor.resolve = function(v) { return v; };

Promise.allKeyed.call(Constructor, { a: 1 });
28 changes: 28 additions & 0 deletions test/built-ins/Promise/allKeyed/ctx-ctor-throws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2026 Danial Asaria (Bloomberg LP). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allkeyed
description: >
Promise.allKeyed invoked on a constructor value that throws an error
info: |
Promise.allKeyed ( promises )

1. Let C be the this value.
2. Let promiseCapability be ? NewPromiseCapability(C).

NewPromiseCapability ( C )

...
6. Let promise be Construct(C, « executor »).
7. ReturnIfAbrupt(promise).
features: [await-dictionary]
---*/

var CustomPromise = function() {
throw new Test262Error();
};

assert.throws(Test262Error, function() {
Promise.allKeyed.call(CustomPromise, {});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (C) 2026 Danial Asaria (Bloomberg LP). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseallkeyed
description: >
Keys whose property descriptor has [[Enumerable]] false are skipped
info: |
PerformPromiseAllKeyed ( variant, promises, constructor, resultCapability, promiseResolve )

...
6. For each element key of allKeys, do
a. Let desc be ? promises.[[GetOwnProperty]](key).
b. If desc is not undefined and desc.[[Enumerable]] is true, then
...
includes: [asyncHelpers.js]
flags: [async]
features: [await-dictionary]
---*/

var input = Object.create(null);
Object.defineProperty(input, "a", {
value: Promise.resolve(1),
enumerable: true,
configurable: true
});
Object.defineProperty(input, "b", {
value: Promise.resolve(2),
enumerable: false,
configurable: true
});
Object.defineProperty(input, "c", {
value: Promise.resolve(3),
enumerable: true,
configurable: true
});

asyncTest(function() {
return Promise.allKeyed(input).then(function(result) {
assert.sameValue(Object.getPrototypeOf(result), null, "result is null-prototype");
var keys = Reflect.ownKeys(result);
assert.sameValue(keys.length, 2, "only enumerable keys are present");
assert.sameValue(keys[0], "a", "first key");
assert.sameValue(keys[1], "c", "second key");
assert.sameValue(result.a, 1, "result.a");
assert.sameValue(result.c, 3, "result.c");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2026 Danial Asaria (Bloomberg LP). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseallkeyed
description: >
Keys where [[GetOwnProperty]] returns undefined are skipped
info: |
PerformPromiseAllKeyed ( variant, promises, constructor, resultCapability, promiseResolve )

...
6. For each element key of allKeys, do
a. Let desc be ? promises.[[GetOwnProperty]](key).
b. If desc is not undefined and desc.[[Enumerable]] is true, then
...
includes: [asyncHelpers.js]
flags: [async]
features: [await-dictionary, Proxy]
---*/

var input = new Proxy({ key: Promise.resolve(1) }, {
ownKeys: function() {
return ['key'];
},
getOwnPropertyDescriptor: function() {
return undefined;
}
});

asyncTest(function() {
return Promise.allKeyed(input).then(function(result) {
assert.sameValue(Object.getPrototypeOf(result), null, "result is null-prototype");
assert.sameValue(Reflect.ownKeys(result).length, 0);
});
});
42 changes: 42 additions & 0 deletions test/built-ins/Promise/allKeyed/getownproperty-throws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2026 Danial Asaria (Bloomberg LP). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseallkeyed
description: >
Rejects when [[GetOwnProperty]] on the promises object throws
info: |
PerformPromiseAllKeyed ( variant, promises, constructor, resultCapability, promiseResolve )

...
6. For each element key of allKeys, do
a. Let desc be ? promises.[[GetOwnProperty]](key).
...

Promise.allKeyed ( promises )

...
6. Let result be Completion(PerformPromiseAllKeyed(...)).
7. IfAbruptRejectPromise(result, promiseCapability).
includes: [asyncHelpers.js]
flags: [async]
features: [await-dictionary, Proxy]
---*/

var error = new Test262Error();
var input = new Proxy({ key: 1 }, {
ownKeys: function() {
return ['key'];
},
getOwnPropertyDescriptor: function() {
throw error;
}
});

asyncTest(function() {
return Promise.allKeyed(input).then(function() {
throw new Test262Error('The promise should be rejected.');
}, function(reason) {
assert.sameValue(reason, error);
});
});
39 changes: 39 additions & 0 deletions test/built-ins/Promise/allKeyed/invoke-resolve-error-reject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2026 Danial Asaria (Bloomberg LP). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseallkeyed
description: >
Calling promiseResolve throws, resulting in promise rejection
info: |
PerformPromiseAllKeyed ( variant, promises, constructor, resultCapability, promiseResolve )

...
6. For each element key of allKeys, do
...
b. If desc is not undefined and desc.[[Enumerable]] is true, then
...
iv. Let nextPromise be ? Call(promiseResolve, constructor, « value »).

Promise.allKeyed ( promises )

...
6. Let result be Completion(PerformPromiseAllKeyed(...)).
7. IfAbruptRejectPromise(result, promiseCapability).
includes: [asyncHelpers.js]
flags: [async]
features: [await-dictionary]
---*/

var error = new Test262Error();
Promise.resolve = function() {
throw error;
};

asyncTest(function() {
return Promise.allKeyed({ key: 1 }).then(function() {
throw new Test262Error('The promise should be rejected.');
}, function(reason) {
assert.sameValue(reason, error);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2026 Danial Asaria (Bloomberg LP). All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allkeyed
description: >
Error retrieving the constructor's `resolve` method rejects the promise
info: |
Promise.allKeyed ( promises )

...
3. Let promiseResolve be Completion(GetPromiseResolve(C)).
4. IfAbruptRejectPromise(promiseResolve, promiseCapability).

GetPromiseResolve ( promiseConstructor )

1. Let promiseResolve be ? Get(promiseConstructor, "resolve").
...
includes: [asyncHelpers.js]
flags: [async]
features: [await-dictionary]
---*/

var error = new Test262Error();
Object.defineProperty(Promise, 'resolve', {
get: function() {
throw error;
}
});

asyncTest(function() {
return Promise.allKeyed({ key: 1 }).then(function() {
throw new Test262Error('The promise should be rejected.');
}, function(reason) {
assert.sameValue(reason, error);
});
});
Loading
Loading