summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreu Botella <abb@randomunok.com>2021-09-12 00:20:30 +0200
committerGitHub <noreply@github.com>2021-09-12 00:20:30 +0200
commit676565c711d41443e25c07c0f47532eb1637830e (patch)
tree478fc849d5e1dbe1c4155442ec64700957bc738b
parent0cb22d4cba76cf86486db3d311a6a4c61b93d953 (diff)
refactor(runtime): Use `util.nonEnumerable` to define `console` (#11982)
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.
-rw-r--r--runtime/js/99_main.js7
1 files changed, 1 insertions, 6 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index d086a42b2..4fa10bad0 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,