From eb0aba59b8f2d4d48b0b4e813f0f51c4677a49a4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 11 Jul 2023 23:21:40 -0700 Subject: [PATCH] bootstrap: use correct descriptor for Symbol.{dispose,asyncDispose} Followup to #48518; fixes #48699 PR-URL: https://github.com/nodejs/node/pull/48703 Reviewed-By: Luigi Pinca Reviewed-By: Nitzan Uziely Reviewed-By: Moshe Atlow Reviewed-By: Benjamin Gruenbaum --- lib/internal/process/pre_execution.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index cab2eacb8c0723..54258c572c07f6 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -128,9 +128,26 @@ function prepareExecution(options) { function setupSymbolDisposePolyfill() { // TODO(MoLow): Remove this polyfill once Symbol.dispose and Symbol.asyncDispose are available in V8. // eslint-disable-next-line node-core/prefer-primordials - Symbol.dispose ??= SymbolDispose; + if (typeof Symbol.dispose !== 'symbol') { + ObjectDefineProperty(Symbol, 'dispose', { + __proto__: null, + configurable: false, + enumerable: false, + value: SymbolDispose, + writable: false, + }); + } + // eslint-disable-next-line node-core/prefer-primordials - Symbol.asyncDispose ??= SymbolAsyncDispose; + if (typeof Symbol.asyncDispose !== 'symbol') { + ObjectDefineProperty(Symbol, 'asyncDispose', { + __proto__: null, + configurable: false, + enumerable: false, + value: SymbolAsyncDispose, + writable: false, + }); + } } function setupUserModules(isLoaderWorker = false) {