Skip to content

Commit 7bd0d42

Browse files
goffrieConvex, Inc.
authored andcommitted
global.console nitpicks (#42534)
GitOrigin-RevId: c3f1fc2698d7ae920d39b792e1f669b975d09477
1 parent 8225a16 commit 7bd0d42

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

npm-packages/udf-runtime/src/02_console.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ function toString(value: unknown, defaultValue: string) {
2727
function consoleMessage(level, args) {
2828
performOp("console/message", level, getMessage(args));
2929
}
30-
const consoleImpl = {
30+
// For historical web-compatibility reasons, the namespace object for console
31+
// must have as its [[Prototype]] an empty object, created as if by
32+
// ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%.
33+
const consoleImpl = Object.assign(Object.create({}), {
3134
debug: function (...args) {
3235
consoleMessage("DEBUG", args);
3336
},
@@ -65,14 +68,18 @@ const consoleImpl = {
6568
performOp("console/timeEnd", labelStr);
6669
},
6770
// TODO: Implement the rest of the Console API.
68-
69-
get [Symbol.toStringTag]() {
70-
return "console";
71-
},
72-
};
71+
});
72+
Object.defineProperty(consoleImpl, Symbol.toStringTag, {
73+
value: "console",
74+
enumerable: false,
75+
writable: false,
76+
});
7377
export function setupConsole(global) {
7478
// Delete v8's console since it doesn't go anywhere. We'll eventually want to mirror our console
7579
// output to v8's console since apparently its output shows up in v8's debugger.
7680
delete global.console;
77-
global.console = consoleImpl;
81+
Object.defineProperty(global, "console", {
82+
value: consoleImpl,
83+
enumerable: false,
84+
});
7885
}

0 commit comments

Comments
 (0)