// we create a new JS engine with the object "gt" as globalThis // gt can now be treated like globalThis. try (JScriptEngine engine = new JScriptEngine(new JsGlobalThis(),"gt")) { /* call your js code here */ }