1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-14 17:39:56 +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"; 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 =[ var globalCheck =[
" if(Object.keys(globalThis).length){", " Object.defineProperty(Object.prototype, '__temp__', {",
" console.log(Object.keys(globalThis));", " 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.\";", " throw \"Global assignment is not allowed within modules on node.\";",
" }" " }",
" delete Object.prototype.__temp__;",
].join('\n'); ].join('\n');
/* /*
@ -604,7 +595,6 @@ $tw.utils.evalGlobal = function(code,context,filename,sandbox,allowGlobals) {
}); });
// Add the code prologue and epilogue // Add the code prologue and epilogue
code = [ code = [
(!$tw.browser ? polyfill : ""),
"(function(" + contextNames.join(",") + ") {", "(function(" + contextNames.join(",") + ") {",
" (function(){\n" + code + "\n;})();", " (function(){\n" + code + "\n;})();",
(!$tw.browser && sandbox && !allowGlobals) ? globalCheck : "", (!$tw.browser && sandbox && !allowGlobals) ? globalCheck : "",