From 0b3523d9c179545de449c565dcb25956d1567bfa Mon Sep 17 00:00:00 2001 From: Tarik Eshaq Date: Tue, 5 Jan 2021 13:37:27 -0800 Subject: [PATCH 1/2] Adds console API web platform tests --- cli/tests/wpt.jsonc | 24 ++++++++++++++++++++++++ test_util/wpt | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cli/tests/wpt.jsonc b/cli/tests/wpt.jsonc index 3099d3b48e00dc..22235f7698ffc9 100644 --- a/cli/tests/wpt.jsonc +++ b/cli/tests/wpt.jsonc @@ -179,5 +179,29 @@ ] }, "user_timing_exists" + ], + "console": [ + { + "name": "console-is-a-namespace", + "expectFail": [ + // TODO(???) console is enumerable when it shouldn't be. + "console has the right property descriptors" + ] + }, + "console-label-conversion", + { + "name": "console-namespace-object-class-string", + "expectFail": [ + // TODO(???): Symbol(Symbol.toStringTag) is missing on the console object + "@@toStringTag exists on the namespace object with the appropriate descriptor", + // TODO(???): doing `toString` on console should return [object console], instead returns [object Object] + "Object.prototype.toString applied to the namespace object", + // TODO(???): This fails due to precondition and Symbol.toStringTag not existing, the test itself doesn't even run + "Object.prototype.toString applied after modifying the namespace object's @@toStringTag", + // TODO(???): This fails due to precondition and Symbol.toStringTag not existing, the test itself doesn't even run + "Object.prototype.toString applied after deleting @@toStringTag" + ] + }, + "console-tests-historical", ] } diff --git a/test_util/wpt b/test_util/wpt index 835839463c5270..b6f4d8ca80c396 160000 --- a/test_util/wpt +++ b/test_util/wpt @@ -1 +1 @@ -Subproject commit 835839463c5270731a6a57885caff34cac7725e5 +Subproject commit b6f4d8ca80c396728754871433e61340da413022 From d14d0031122a111ce24af5a5e0f193a0aca48fcf Mon Sep 17 00:00:00 2001 From: Tarik Eshaq Date: Tue, 5 Jan 2021 16:00:14 -0800 Subject: [PATCH 2/2] Fixes console to be aligned with WPT --- cli/tests/unit/console_test.ts | 3 ++- cli/tests/wpt.jsonc | 22 ++-------------------- runtime/js/02_console.js | 9 ++++++++- runtime/js/99_main.js | 5 +++++ test_util/wpt | 2 +- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index 37112bea6acce5..c6511e12ec5fd8 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 22235f7698ffc9..3a50c676cdbbf7 100644 --- a/cli/tests/wpt.jsonc +++ b/cli/tests/wpt.jsonc @@ -181,27 +181,9 @@ "user_timing_exists" ], "console": [ - { - "name": "console-is-a-namespace", - "expectFail": [ - // TODO(???) console is enumerable when it shouldn't be. - "console has the right property descriptors" - ] - }, + "console-is-a-namespace", "console-label-conversion", - { - "name": "console-namespace-object-class-string", - "expectFail": [ - // TODO(???): Symbol(Symbol.toStringTag) is missing on the console object - "@@toStringTag exists on the namespace object with the appropriate descriptor", - // TODO(???): doing `toString` on console should return [object console], instead returns [object Object] - "Object.prototype.toString applied to the namespace object", - // TODO(???): This fails due to precondition and Symbol.toStringTag not existing, the test itself doesn't even run - "Object.prototype.toString applied after modifying the namespace object's @@toStringTag", - // TODO(???): This fails due to precondition and Symbol.toStringTag not existing, the test itself doesn't even run - "Object.prototype.toString applied after deleting @@toStringTag" - ] - }, + "console-namespace-object-class-string", "console-tests-historical", ] } diff --git a/runtime/js/02_console.js b/runtime/js/02_console.js index 971837bd63d0f5..11b81985087399 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 f38d51936abd60..80d01feb488ca5 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -242,6 +242,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), diff --git a/test_util/wpt b/test_util/wpt index b6f4d8ca80c396..835839463c5270 160000 --- a/test_util/wpt +++ b/test_util/wpt @@ -1 +1 @@ -Subproject commit b6f4d8ca80c396728754871433e61340da413022 +Subproject commit 835839463c5270731a6a57885caff34cac7725e5