Skip to content

Commit 824d833

Browse files
committed
Add 'window' as fallback for globalThis or this.
Resolves #253.
1 parent f3e1c38 commit 824d833

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

acorn.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
if (typeof exports === "object" && typeof module === "object") return mod(exports); // CommonJS
3131
if (typeof define === "function" && define.amd) return define(["exports"], mod); // AMD
3232
mod(root.acorn || (root.acorn = {})); // Plain browser env
33-
})((typeof globalThis === 'undefined') ? this : globalThis, function(exports) {
33+
})((typeof globalThis === 'undefined') ? this || window : globalThis, function(exports) {
3434
"use strict";
3535

3636
exports.version = "0.5.0";
3737
// Plus additional edits marked with 'JS-Interpreter change' comments.
3838

3939
// JS-Interpreter change:
40-
// For global object, use 'globalThis' if it exists, fall back to 'this'.
40+
// For global object, use 'globalThis' if it exists,
41+
// fall back to 'this' or 'window'. Same logic as in JS-Interpreter.
4142
// -- Neil Fraser, March 2024.
4243

4344
// JS-Interpreter change:

acorn_interpreter.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

interpreter.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ Interpreter.vm = null;
201201
Interpreter.currentInterpreter_ = null;
202202

203203
/**
204-
* The global object (`window` in a browser, `global` in node.js) is usually
205-
* `globalThis`, but older systems use `this`.
204+
* The global object. Ideally use `globalThis`. Failing that try `this` or
205+
* `window`. Other options to consider are `self` and `global`.
206+
* Same logic as in Acorn.
206207
*/
207208
Interpreter.nativeGlobal =
208-
(typeof globalThis === 'undefined') ? this : globalThis;
209+
(typeof globalThis === 'undefined') ? this || window : globalThis;
209210

210211
/**
211212
* Code for executing regular expressions in a thread.

0 commit comments

Comments
 (0)