workaround toString() quirks on global context (#4814)

This commit is contained in:
Alex Lam S.L
2021-03-23 03:15:41 +00:00
committed by GitHub
parent f9055df44d
commit 44394e61c9
4 changed files with 16 additions and 19 deletions

View File

@@ -170,12 +170,6 @@ function setup(global, builtins, setup_log, setup_tty) {
},
global: { get: self },
self: { get: self },
// for Node.js v8+
toString: {
get: function() {
return global_toString;
},
},
window: { get: self },
};
[
@@ -205,15 +199,19 @@ function setup(global, builtins, setup_log, setup_tty) {
} catch (e) {}
});
Object.defineProperties(global, props);
// for Node.js v8+
if (global.toString !== Object.prototype.toString) {
global.__proto__ = Object.defineProperty(Object.create(global.__proto__), "toString", {
value: function() {
return "[object global]";
},
});
}
function self() {
return this;
}
function global_toString() {
return "[object global]";
}
function safe_log(arg, cache) {
if (arg) switch (typeof arg) {
case "function":