From 983d81bda622ca61fcb1210e2041a1aba57cfdc8 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 30 May 2024 17:56:55 -0400 Subject: [PATCH] 'await using' normative changes (#258) --- tslib.es6.js | 5 ++++- tslib.es6.mjs | 12 +++++++----- tslib.js | 4 +++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tslib.es6.js b/tslib.es6.js index 55dd360..b212c25 100644 --- a/tslib.es6.js +++ b/tslib.es6.js @@ -296,7 +296,7 @@ export function __classPrivateFieldIn(state, receiver) { export function __addDisposableResource(env, value, async) { if (value !== null && value !== void 0) { if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); - var dispose; + var dispose, inner; if (async) { if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); dispose = value[Symbol.asyncDispose]; @@ -304,14 +304,17 @@ export function __addDisposableResource(env, value, async) { if (dispose === void 0) { if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); dispose = value[Symbol.dispose]; + if (async) inner = dispose; } if (typeof dispose !== "function") throw new TypeError("Object not disposable."); + if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; env.stack.push({ value: value, dispose: dispose, async: async }); } else if (async) { env.stack.push({ async: true }); } return value; + } var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { diff --git a/tslib.es6.mjs b/tslib.es6.mjs index 65081a6..0df91b1 100644 --- a/tslib.es6.mjs +++ b/tslib.es6.mjs @@ -296,16 +296,18 @@ export function __classPrivateFieldIn(state, receiver) { export function __addDisposableResource(env, value, async) { if (value !== null && value !== void 0) { if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); - var dispose; + var dispose, inner; if (async) { - if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); - dispose = value[Symbol.asyncDispose]; + if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); + dispose = value[Symbol.asyncDispose]; } if (dispose === void 0) { - if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); - dispose = value[Symbol.dispose]; + if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); + dispose = value[Symbol.dispose]; + if (async) inner = dispose; } if (typeof dispose !== "function") throw new TypeError("Object not disposable."); + if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; env.stack.push({ value: value, dispose: dispose, async: async }); } else if (async) { diff --git a/tslib.js b/tslib.js index 697469f..0f7c846 100644 --- a/tslib.js +++ b/tslib.js @@ -344,7 +344,7 @@ var __disposeResources; __addDisposableResource = function (env, value, async) { if (value !== null && value !== void 0) { if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); - var dispose; + var dispose, inner; if (async) { if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); dispose = value[Symbol.asyncDispose]; @@ -352,8 +352,10 @@ var __disposeResources; if (dispose === void 0) { if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); dispose = value[Symbol.dispose]; + if (async) inner = dispose; } if (typeof dispose !== "function") throw new TypeError("Object not disposable."); + if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; env.stack.push({ value: value, dispose: dispose, async: async }); } else if (async) {