Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4405433
test_await_thenables.cjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_await_thenables.cjs
View Options
function assertEq(name, actual, expected) {
if (actual !== expected) {
throw new Error(`${name}: expected ${expected}, got ${actual}`);
}
console.log(`ok ${name}`);
}
class ProtoThenable {
constructor(value) {
this.value = value;
}
}
ProtoThenable.prototype.then = function(resolve, _reject) {
resolve(this.value);
};
class APIPromiseLike {
constructor(value) {
this.promise = Promise.resolve([{ ok: true, value }]);
}
then(onfulfilled, onrejected) {
return this.promise.then(
onfulfilled ? ([result]) => onfulfilled(result.value) : undefined,
onrejected
);
}
}
(async function() {
assertEq('await plain thenable', await {
then(resolve, _reject) {
resolve(42);
}
}, 42);
assertEq('await prototype thenable', await new ProtoThenable(99), 99);
assertEq('await APIPromise-like thenable', await new APIPromiseLike('ok'), 'ok');
assertEq(
'Promise.resolve still adopts thenables',
await Promise.resolve(new ProtoThenable('wrapped')),
'wrapped'
);
})().catch((err) => {
console.error(err);
process.exitCode = 1;
});
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, May 1, 5:38 PM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
543386
Default Alt Text
test_await_thenables.cjs (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment