Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(wpt/console): Enables web platform tests for console #9013

Merged
merged 3 commits into from
Jan 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/tests/unit/console_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ unitTest(function consoleTestStringifyCircular(): void {
);
assertEquals(
stringify(console),
`{
`console {
log: [Function: log],
debug: [Function: log],
info: [Function: log],
Expand All @@ -334,6 +334,7 @@ unitTest(function consoleTestStringifyCircular(): void {
clear: [Function: clear],
trace: [Function: trace],
indentLevel: 0,
[Symbol(Symbol.toStringTag)]: "console",
[Symbol(isConsoleInstance)]: true
}`,
);
Expand Down
6 changes: 6 additions & 0 deletions cli/tests/wpt.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
9 changes: 8 additions & 1 deletion runtime/js/02_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure if this is the best place to do this, it seemed to me that non of the existing "util" functions do the desired behavior and since this seemed like a one-off I put it here, open to moving this


const mainRuntimeGlobalProperties = {
Window: globalInterfaces.windowConstructorDescriptor,
window: util.readOnly(globalThis),
Expand Down