How can I call variable in script like this global.var

muhammad sami <[email protected]> Mon, 1 Apr 2019 08:41:23 -0700 (PDT)
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
in class --> JavaScriptEngine
bool run(JSContext *cx, RootedObject *globaloObj, const char *script, const char *filename = "noname", int lineno = 1) {
        JSAutoRequest ar(cx);
        JSAutoCompartment ac(cx, *globaloObj);

        JS::RootedValue rval(cx);

        JS::CompileOptions opts(cx);
        opts.setFileAndLine(filename, lineno);

        bool ok = JS::Evaluate(cx, opts, script, strlen(script), &rval);

        if (!ok)
            return 1;

        JSString *str = rval.toString();
     
       printf("output: %s\n", JS_EncodeString(cx, str));

      }

JSClass JavaScriptEngine::document_class = {
    "global",
    JSCLASS_GLOBAL_FLAGS,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    nullptr, nullptr, nullptr, nullptr,
    JS_GlobalObjectTraceHook
};

in main(){
    JavaScriptEngine e;
    run(e.cx, e.dialog, "x=5");
    run(cx,e.dialog, "global.x");
}

-----output------
noname:1:ReferenceError: global is not defined