From 9801858cb0675de801b1c15d1b3826c88406068a Mon Sep 17 00:00:00 2001 From: Tarik Eshaq Date: Sun, 10 Jan 2021 09:49:45 -0800 Subject: [PATCH] tests(wpt/console): Enables web platform tests for console (#9013) --- cli/tests/unit/console_test.ts | 3 ++- cli/tests/wpt.jsonc | 6 ++++++ runtime/js/02_console.js | 9 ++++++++- runtime/js/99_main.js | 5 +++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index 37112bea6a..c6511e12ec 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -313,7 +313,7 @@ unitTest(function consoleTestStringifyCircular(): void { ); assertEquals( stringify(console), - `{ + `console { log: [Function: log], debug: [Function: log], info: [Function: log], @@ -334,6 +334,7 @@ unitTest(function consoleTestStringifyCircular(): void { clear: [Function: clear], trace: [Function: trace], indentLevel: 0, + [Symbol(Symbol.toStringTag)]: "console", [Symbol(isConsoleInstance)]: true }`, ); diff --git a/cli/tests/wpt.jsonc b/cli/tests/wpt.jsonc index 2e3882fe23..29f3967adf 100644 --- a/cli/tests/wpt.jsonc +++ b/cli/tests/wpt.jsonc @@ -174,6 +174,12 @@ "structured-serialize-detail", "user_timing_exists" ], + "console": [ + "console-is-a-namespace", + "console-label-conversion", + "console-namespace-object-class-string", + "console-tests-historical", + ], "WebCryptoApi": [ "getRandomValues" ] diff --git a/runtime/js/02_console.js b/runtime/js/02_console.js index 971837bd63..11b8198508 100644 --- a/runtime/js/02_console.js +++ b/runtime/js/02_console.js @@ -1449,7 +1449,14 @@ // For historical web-compatibility reasons, the namespace object for // console must have as its [[Prototype]] an empty object, created as if // by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%. - const console = Object.create({}); + const console = Object.create({}, { + [Symbol.toStringTag]: { + enumerable: false, + writable: false, + configurable: true, + value: "console", + }, + }); Object.assign(console, this); return console; } diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 284bef48c8..21e1ed5ebb 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -245,6 +245,11 @@ delete Object.prototype.__proto__; setTimeout: util.writable(timers.setTimeout), }; + // 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 = { Window: globalInterfaces.windowConstructorDescriptor, window: util.readOnly(globalThis),