1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-26 19:47:20 +00:00

Polyfill is not needed, only globalCheck (#7492)

This commit is contained in:
Arlen22 2023-05-27 12:24:25 -04:00 committed by GitHub
parent 74e0619782
commit 90f0ff8067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -569,26 +569,17 @@ $tw.utils.getTypeEncoding = function(ext) {
return typeInfo ? typeInfo.encoding : "utf8";
};
var polyfill =[
"// this polyfills the globalThis variable",
"// using the this variable on a getter ",
"// inserted into the prototype of globalThis",
"(function() {",
" if (typeof globalThis === 'object') return;",
" // node.green says this is available since 0.10.48",
" Object.prototype.__defineGetter__('__temp__', function() {",
" return this;",
" });",
" __temp__.globalThis = __temp__;",
" delete Object.prototype.__temp__;",
"}());"
].join("\n");
var globalCheck =[
" if(Object.keys(globalThis).length){",
" console.log(Object.keys(globalThis));",
" Object.defineProperty(Object.prototype, '__temp__', {",
" get: function () { return this; },",
" configurable: true",
" });",
" if(Object.keys(__temp__).length){",
" console.log(Object.keys(__temp__));",
" delete Object.prototype.__temp__;",
" throw \"Global assignment is not allowed within modules on node.\";",
" }"
" }",
" delete Object.prototype.__temp__;",
].join('\n');
/*
@ -604,7 +595,6 @@ $tw.utils.evalGlobal = function(code,context,filename,sandbox,allowGlobals) {
});
// Add the code prologue and epilogue
code = [
(!$tw.browser ? polyfill : ""),
"(function(" + contextNames.join(",") + ") {",
" (function(){\n" + code + "\n;})();",
(!$tw.browser && sandbox && !allowGlobals) ? globalCheck : "",