NeilFraser / JS-Interpreter

A sandboxed JavaScript interpreter in JavaScript.
Apache License 2.0
1.96k stars 352 forks source link

Minor bug fix #253

Closed SumukhPrasad closed 4 months ago

SumukhPrasad commented 11 months ago

Changed line 190 in interpreter.js to fix a bug with "this" not referring to the browser in Svelte-based npm contexts.

NeilFraser commented 4 months ago

Do you know what this refers to in these contexts? Is in null, undefined, or some other object?

SumukhPrasad commented 4 months ago

Is in null, undefined, or some other object?

In this context it actually ends up being undefined.

Screenshot 2024-03-06 at 4 57 47 AM

Screenshot 2024-03-06 at 4 58 01 AM
NeilFraser commented 4 months ago

Thanks. In that case I'll use this || window since there are non-browser enviornments where window doesn't exist and we need this. I've committed 824d8331cc4b72c09ca3e0f1b3a6ed7914cf16c6 which makes this change in both JS-Interpreter and Acorn.

We may need to revisit this issue in the future if people find more exotic environments. Here's what claims to be a complete solution: https://mathiasbynens.be/notes/globalthis I'm hopeful that in the real world the growing prevalence of globalThis will make this issue fade away.

cpcallen commented 4 months ago

Here's what claims to be a complete solution: https://mathiasbynens.be/notes/globalthis

Wow, that is both impressive and appalling in equal measure.