Skip to content

Commit f27d883

Browse files
committed
[Refactor] sync dispose used in an async dispose should reject, not throw
See tc39/proposal-explicit-resource-management#218
1 parent 525559f commit f27d883

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"GetMethod",
2929
"IsCallable",
3030
"NewDisposeCapability",
31+
"NewPromiseCapability",
3132
"NormalCompletion",
3233
"PromiseResolve",
3334
"ThrowCompletion",

aos/GetDisposeMethod.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var $TypeError = require('es-errors/type');
55

66
var Call = require('es-abstract/2024/Call');
77
var GetMethod = require('es-abstract/2024/GetMethod');
8+
var NewPromiseCapability = require('es-abstract/2024/NewPromiseCapability');
89
var Type = require('es-abstract/2024/Type');
910

1011
var symbolDispose = require('../Symbol.dispose/polyfill')();
@@ -33,7 +34,24 @@ module.exports = function GetDisposeMethod(V, hint) {
3334
return function () { // step 1.b.ii.1, 1.b.ii.3
3435
// eslint-disable-next-line no-invalid-this
3536
var O = this; // step 1.b.ii.1.a
36-
Call(method, O); // step // step 1.b.ii.1.b
37+
// Call(method, O); // step // step 1.b.ii.1.b
38+
39+
if (hint === 'ASYNC-DISPOSE') {
40+
var promiseCapability = NewPromiseCapability(Promise); // step 1.b.ii.1.b
41+
try {
42+
Call(method, O); // step 1.b.ii.1.c
43+
44+
Call(promiseCapability['[[Resolve]]'], undefined, [undefined]); // step 1.b.ii.1.e
45+
} catch (e) {
46+
promiseCapability['[[Reject]]'](e); // step 1.b.ii.1.d
47+
}
48+
49+
return promiseCapability['[[Promise]]']; // step 1.b.ii.1.f
50+
}
51+
52+
Call(method, O);
53+
54+
return void undefined;
3755
};
3856
}
3957
}

0 commit comments

Comments
 (0)