Skip to content

Commit

Permalink
refactor(runtime): Use util.nonEnumerable to define console
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Andreu Botella committed Sep 11, 2021
1 parent fa96390 commit 5b444f7
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5b444f7

Please sign in to comment.