From 676565c711d41443e25c07c0f47532eb1637830e Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Sun, 12 Sep 2021 00:20:30 +0200 Subject: [PATCH] refactor(runtime): Use `util.nonEnumerable` to define `console` (#11982) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A comment in `runtime.js` reads that `console` seems to be "the only one that should be writable and non-enumerable", which explains why it is declared with `util.writable` but then has its property descriptor's `enumerable` key changed to false. But it is not in fact true that `console` is the only global property for which this holds, and it wasn't even when this behavior was introduced in denoland#9013. All WebIDL interfaces are also writable and non-enumerable – the only difference here being that `console` is a namespace rather than an interface. Since WebIDL interfaces are defined with `util.nonEnumerable`, and `console` uses the same descriptor keys, this PR changes the definition of `console` to use `util.nonEnumerable` as well. --- runtime/js/99_main.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index d086a42b2b..4fa10bad0f 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -418,7 +418,7 @@ delete Object.prototype.__proto__; btoa: util.writable(base64.btoa), clearInterval: util.writable(timers.clearInterval), clearTimeout: util.writable(timers.clearTimeout), - console: util.writable( + console: util.nonEnumerable( new Console((msg, level) => core.print(msg, level > 1)), ), crypto: util.readOnly(crypto.crypto), @@ -468,11 +468,6 @@ delete Object.prototype.__proto__; GPUValidationError: util.nonEnumerable(webgpu.GPUValidationError), }; - // The console seems to be the only one that should be writable and non-enumerable - // thus we don't have a unique helper for it. If other properties follow the same - // structure, it might be worth it to define a helper in `util` - windowOrWorkerGlobalScope.console.enumerable = false; - const mainRuntimeGlobalProperties = { Location: location.locationConstructorDescriptor, location: location.locationDescriptor,