Skip to content

Commit 9fed38b

Browse files
aardvark179gbrail
authored andcommitted
Ensure global is present in top level
* Set `global` as part of initialisation. * Add a test that `global` and `globalThis` are the same thing.
1 parent 5b97109 commit 9fed38b

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ public static ScriptableObject initSafeStandardObjects(
190190
((TopLevel) scope).clearCache();
191191
}
192192

193+
scope.put("global", scope, scope);
194+
193195
scope.associateValue(LIBRARY_SCOPE_KEY, scope);
194196
new ClassCache().associate(scope);
195197
new ConcurrentFactory().associate(scope);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.mozilla.javascript.tests;
2+
3+
import org.mozilla.javascript.drivers.RhinoTest;
4+
import org.mozilla.javascript.drivers.ScriptTestsBase;
5+
6+
@RhinoTest(value = "testsrc/jstests/top-level.js")
7+
public class TopLevelTest extends ScriptTestsBase {}

tests/testsrc/jstests/top-level.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
load("testsrc/assert.js");
4+
5+
assertSame(global, globalThis);
6+
7+
"success";

0 commit comments

Comments
 (0)