JSObject * SavedStacks::getOrCreateSavedFramePrototype(JSContext *cx) { if (savedFrameProto) return savedFrameProto; Rooted<GlobalObject *> global(cx, cx->compartment()->maybeGlobal()); if (!global) return nullptr; RootedObject proto(cx, NewObjectWithGivenProto(cx, &SavedFrame::class_, global->getOrCreateObjectPrototype(cx), global)); if (!proto || !JS_DefineProperties(cx, proto, SavedFrame::properties) || !JS_DefineFunctions(cx, proto, SavedFrame::methods) || !JSObject::freeze(cx, proto)) return nullptr; savedFrameProto = proto; // The only object with the SavedFrame::class_ that doesn't have a source // should be the prototype. savedFrameProto->setReservedSlot(SavedFrame::JSSLOT_SOURCE, NullValue()); return savedFrameProto; }
/** Return an SMJS object through which scripts can access @a cached. * If there already is such an object, return that; otherwise create a * new one. The SMJS object holds only a weak reference to @a cached; * so if the caller wants to guarantee that @a cached exists at least * until a script returns, it should use lock_object() and * unlock_object(). */ JSObject * smjs_get_cache_entry_object(struct cache_entry *cached) { JSObject *cache_entry_object; if (cached->jsobject) return cached->jsobject; assert(smjs_ctx); if_assert_failed return NULL; cache_entry_object = JS_NewObject(smjs_ctx, (JSClass *) &cache_entry_class, NULL, NULL); if (!cache_entry_object) return NULL; if (JS_FALSE == JS_DefineProperties(smjs_ctx, cache_entry_object, (JSPropertySpec *) cache_entry_props)) return NULL; /* Do this last, so that if any previous step fails, we can * just forget the object and its finalizer won't attempt to * access @cached. */ if (JS_FALSE == JS_SetPrivate(smjs_ctx, cache_entry_object, cached)) /* to @cache_entry_class */ return NULL; cached->jsobject = cache_entry_object; return cache_entry_object; }
bool DefinePropertiesAndBrand(JSContext *cx, JSObject *obj, JSPropertySpec *ps, JSFunctionSpec *fs) { if ((ps && !JS_DefineProperties(cx, obj, ps)) || (fs && !JS_DefineFunctions(cx, obj, fs))) return false; return true; }
JSObject * js_InitNavigatorClass(JSContext *cx, JSObject *obj) { JSObject *Navigator; Navigator = JS_DefineObject(cx, obj, "navigator", &navigator_class, NULL, 0); if (!Navigator) return NULL; if (!JS_DefineFunctions(cx, Navigator, navigator_static_methods)) return NULL; if (!JS_DefineProperties(cx, Navigator, navigator_properties)) return NULL; CMNavigator *cmNav; cmNav = JS_malloc(cx, sizeof *cmNav); if (!cmNav) return NULL; memset(cmNav, 0 , sizeof *cmNav); cmNav->appVersion = JS_malloc(cx, strlen("Firefox/2")); cmNav->appVersion = strdup("Firefox/2"); JS_SetPrivate(cx, Navigator, cmNav); return Navigator; }
xjse_result_t xjse_xgg_define_system(XJSECTX* pctxa) { JSBool b1; jsval v1; JSObject *posystem = JS_NewObject( pctxa->pctx, &class_xgg_system, NULL, NULL); if(posystem == 0) goto failed; v1 = OBJECT_TO_JSVAL(posystem); b1 = JS_SetProperty(pctxa->pctx, pctxa->poglobal, "system", &v1); if(b1 != JS_TRUE) goto failed; JSObject *posystem_power = JS_NewObject( pctxa->pctx, &class_xgg_system_power, NULL, NULL); if(posystem_power == 0) goto failed; b1 = JS_DefineProperties( pctxa->pctx, posystem_power, props_xgg_system_power); if(b1 != JS_TRUE) goto failed; v1 = OBJECT_TO_JSVAL(posystem_power); b1 = JS_SetProperty(pctxa->pctx, posystem, "power", &v1); if(b1 != JS_TRUE) goto failed; return XJSE_SUCCESS; failed: return XJSE_E_UNKNOWN; }
static JSObject* CreateInterfacePrototypeObject(JSContext* cx, JSObject* global, JSObject* parentProto, JSClass* protoClass, JSFunctionSpec* methods, JSPropertySpec* properties, ConstantSpec* constants) { JSObject* ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global); if (!ourProto) { return NULL; } if (methods && !JS_DefineFunctions(cx, ourProto, methods)) { return NULL; } if (properties && !JS_DefineProperties(cx, ourProto, properties)) { return NULL; } if (constants && !DefineConstants(cx, ourProto, constants)) { return NULL; } return ourProto; }
JSObject* xgg_new_nodelist(XJSECTX* pctxa, JSObject* poparent) { JSBool b1; #ifdef NODELISTISCLASS JSObject* pobjbase = 0; JSObject* pobj = JS_DefineObject(pctxa->pctx, poparent, pszobjname, &class_nodelist, pobjbase, JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_ENUMERATE); #else //NODELISTISCLASS JSObject* pobj = JS_NewArrayObject(pctxa->pctx, 0, NULL); if(pobj == 0) { XJSE_TRACE("(E) JS_NewArrayObject() failed!"); goto failed; } #if 0 b1 = JS_DefineFunctions(pctxa->pctx, pobj, funcs_nodelist); if(b1 != JS_TRUE) goto failed; b1 = JS_DefineProperties(pctxa->pctx, pobj, props_nodelist); if(b1 != JS_TRUE) goto failed; #endif #endif //NODELISTISCLASS // b1 = xgg_nodelist_ctor(pctxa->pctx, pobj, 0, 0, 0); //args, rval if(b1 != JS_TRUE) { XJSE_TRACE("(E) xgg_nodelist_ctor failed!"); } // return pobj; failed: return 0; }
JSObject* NewCoreTexture(JSContext* cx, CoreTexture* tex) { JS::RootedObject self(cx, JS_NewObject(cx, &coreTextureClass)); if (!JS_DefineProperties(cx, self, CoreTexture_props)) { __android_log_print(ANDROID_LOG_ERROR, LOG_COMPONENT, "Could not define properties on Texture\n"); } JS_SetPrivate(self, (void *)tex); return self; }
bool DefinePropertiesAndBrand(JSContext *cx, JSObject *obj, JSPropertySpec *ps, JSFunctionSpec *fs) { if ((ps && !JS_DefineProperties(cx, obj, ps)) || (fs && !JS_DefineFunctions(cx, obj, fs))) return false; if (!cx->typeInferenceEnabled()) obj->brand(cx); return true; }
JSObject *JSCustomer::JSInit(JSContext *cx, JSObject *obj, JSObject *proto) { JSObject *newProtoObj = JS_InitClass(cx, obj, proto, &Customer_class, JSCustomer::JSConstructor, 0, NULL, JSCustomer::Customer_methods, NULL, NULL); JS_DefineProperties(cx, newProtoObj, JSCustomer::Customer_properties); return newProtoObj; }
FieldObjectPtr ScriptContext::newFieldObject(BattleField *p) { JSContext *cx = (JSContext *)m_p; JS_BeginRequest(cx); JSObject *obj = JS_NewObject(cx, &fieldClass, NULL, NULL); FieldObjectPtr ptr = addRoot(new FieldObject(obj)); JS_DefineProperties(cx, obj, fieldProperties); JS_DefineFunctions(cx, obj, fieldFunctions); JS_SetPrivate(cx, obj, p); JS_EndRequest(cx); return ptr; }
bool DefinePropertiesAndBrand(JSContext *cx, JSObject *obj_, const JSPropertySpec *ps, const JSFunctionSpec *fs) { RootedObject obj(cx, obj_); if (ps && !JS_DefineProperties(cx, obj, const_cast<JSPropertySpec*>(ps))) return false; if (fs && !JS_DefineFunctions(cx, obj, const_cast<JSFunctionSpec*>(fs))) return false; return true; }
JSObject* lm_DefineComponents(MochaDecoder *decoder) { JSObject *obj; JSComponentArray *array; JSContext *cx = decoder->js_context; JSPreDefComponent def_comps; JSComponent *component; jsint slot; obj = decoder->components; if (obj) return obj; array = JS_malloc(cx, sizeof(JSComponentArray)); if (!array) return NULL; XP_BZERO(array, sizeof *array); obj = JS_NewObject(cx, &lm_component_array_class, NULL, decoder->window_object); if (!obj || !JS_SetPrivate(cx, obj, array)) { JS_free(cx, array); return NULL; } if (!JS_DefineProperties(cx, obj, componentarray_props)) return NULL; array->decoder = HOLD_BACK_COUNT(decoder); array->obj = obj; /* Components can be added dynamically but some are predefined */ slot = 0; array->length = 0; def_comps = predef_components[slot]; while (def_comps.name) { component = JS_malloc(cx, sizeof(JSComponent)); if (!component) return NULL; if (ET_moz_VerifyComponentFunction(def_comps.func, &(component->active_callback), &(component->startup_callback))) { componentarray_create_component(cx, array, component, def_comps.name, array->length); } else { /*Component call failed somewhere.*/ JS_free(cx, component); } def_comps = predef_components[++slot]; } return obj; }
JSObject *query_InitObject(JSContext *cx, JSObject *moduleObject) { JSObject *queryObject; query_private_t *hnd; static JSClass query_class = /* not exposed to JS, but finalizer needed when GC */ { GPSEE_CLASS_NAME(Query), JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, query_Finalize, JSCLASS_NO_OPTIONAL_MEMBERS }; static JSFunctionSpec query_methods[] = { { "readQuery", query_readQuery, 2, 0, 0 }, { NULL, NULL, 0, 0, 0 } }; static JSPropertySpec query_props[] = { { NULL, 0, 0, NULL, NULL } }; queryObject = JS_NewObject(cx, &query_class, NULL, moduleObject); if (!queryObject) return NULL; if (!JS_DefineFunctions(cx, queryObject, query_methods) || !JS_DefineProperties(cx, queryObject, query_props)) return NULL; hnd = JS_malloc(cx, sizeof(*hnd)); if (!hnd) { JS_ReportOutOfMemory(cx); return NULL; } memset(hnd, 0, sizeof(*hnd)); JS_SetPrivate(cx, queryObject, hnd); return queryObject; }
static JSObject * smjs_get_bookmark_object(struct bookmark *bookmark) { JSObject *jsobj; jsobj = smjs_get_bookmark_generic_object(bookmark, (JSClass *) &bookmark_class); if (jsobj && JS_TRUE == JS_DefineProperties(smjs_ctx, jsobj, (JSPropertySpec *) bookmark_props)) return jsobj; return NULL; }
static JSBool AfxGlobal_testObject(JSContext *cx, unsigned argc, JS::Value *vp) { JS::RootedObject thisobj(cx, JS_THIS_OBJECT(cx, vp)); if (!thisobj) return false; JSObject *obj = JS_NewObjectWithGivenProto(cx, &JsTestObject_class, NULL, JS_GetGlobalForScopeChain(cx)); JS_DefineProperties(cx, obj, JsTestObject_properties); JS_SetPrivate(obj, new JsTestObject()); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); return JS_TRUE; }
JSObject * js_InitScreenClass (JSContext * cx, JSObject * obj) { JSObject *Screen; Screen = JS_DefineObject (cx, obj, "screen", &screen_class, NULL, 0); if (!Screen) return NULL; if (!JS_DefineFunctions (cx, Screen, screen_static_methods)) return NULL; if (!JS_DefineProperties (cx, Screen, screen_properties)) return NULL; return Screen; }
static JSObject * smjs_get_globhist_item_object(struct global_history_item *history_item) { JSObject *jsobj; jsobj = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_item_class, NULL, NULL); if (!jsobj || JS_TRUE != JS_DefineProperties(smjs_ctx, jsobj, (JSPropertySpec *) smjs_globhist_item_props) || JS_TRUE != JS_SetPrivate(smjs_ctx, jsobj, history_item)) /* to @smjs_globhist_item_class */ return NULL; object_lock(history_item); return jsobj; }
const char *vm_InitModule(JSContext *cx, JSObject *moduleObject) { static JSFunctionSpec vm_static_methods[] = { #ifdef JS_GCMETER { "dumpGCstats", vm_dumpGCstats, 0, 0, 0 }, /* char: filename */ #endif { "GC", vm_gc, 0, 0, 0 }, { "isCompilableUnit", vm_isCompilableUnit, 0, 0, 0 }, { "jsval", vm_jsval, 0, 0, 0 }, { "objectPtrValue", vm_objectPtrValue, 0, 0, 0 }, { "stringPtrValue", vm_stringPtrValue, 0, 0, 0 }, { "jsvalPtrValue", vm_jsvalPtrValue, 0, 0, 0 }, { "jschars", vm_jschars, 0, 0, 0 }, { "dumpHeap", vm_dumpHeap, 0, 0, 0 }, { "dumpValue", vm_dumpValue, 0, 0, 0 }, { "dumpObject", vm_dumpObject, 0, 0, 0 }, { "halt", vm_halt, 0, 0, 0 }, { NULL, NULL, 0, 0, 0 }, }; static JSPropertySpec vm_static_props[] = { { "version", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY, vm_version_getter, JS_PropertyStub }, { "jit", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, vm_jit_getter, vm_jit_setter }, { "cx", -1, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY, vm_generic_getter, JS_PropertyStub }, { "rt", -2, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY, vm_generic_getter, JS_PropertyStub }, { "globalObject", -3, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY, vm_generic_getter, JS_PropertyStub }, { "realm", -4, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY, vm_generic_getter, JS_PropertyStub }, { NULL, 0, 0, NULL, NULL } }; if (JS_DefineProperties(cx, moduleObject, vm_static_props) != JS_TRUE) return NULL; if (JS_DefineFunctions(cx, moduleObject, vm_static_methods) != JS_TRUE) return NULL; return MODULE_ID; }
static JSObject * NewGlobalObject(JSContext *cx) { JS::RootedObject glob(cx, JS_NewGlobalObject(cx, &AfxGlobal_class, NULL, JS::CompartmentOptions())); if(!glob) return NULL; { JSAutoCompartment ac(cx, glob); if(!JS_InitStandardClasses(cx, glob)) return NULL; if(!JS_DefineFunctions(cx, glob, AfxGlobal_functions)) return NULL; if (!JS_DefineProperties(cx, glob, AfxGlobal_properties)) return NULL; } return glob; }
JSObject * lm_GetEmbedArray(MochaDecoder *decoder, JSObject *document) { JSContext *cx = decoder->js_context; JSObject *obj; JSObjectArray *array; JSDocument *doc; doc = JS_GetPrivate(cx, document); if (!doc) return NULL; obj = doc->embeds; if (obj) return obj; array = JS_malloc(cx, sizeof *array); if (!array) return NULL; array->decoder = NULL; /* in case of error below */ obj = JS_NewObject(cx, &lm_embed_array_class, NULL, document); if (!obj || !JS_SetPrivate(cx, obj, array)) { JS_free(cx, array); return NULL; } if (!JS_DefineProperties(cx, obj, embed_array_props)) return NULL; array->decoder = HOLD_BACK_COUNT(decoder); array->length = 0; array->layer_id = doc->layer_id; doc->embeds = obj; return obj; }
/* Constructor method for a JSComponent object */ static JSComponent* component_create_self(JSContext *cx, MochaDecoder* decoder, JSComponent *component, const char *name) { JSObject *obj; /* JSComponent may be malloc'd previous to this to make it easier * to fill in the struct with data from the Mozilla thread */ if (!component) { component = JS_malloc(cx, sizeof(JSComponent)); if (!component) return NULL; } obj = JS_NewObject(cx, &lm_component_class, NULL, NULL); if (!obj || !JS_SetPrivate(cx, obj, component)) { JS_free(cx, component); return NULL; } if (!JS_DefineProperties(cx, obj, component_props)) return NULL; if (!JS_DefineFunctions(cx, obj, component_methods)) return NULL; /* Fill out static property fields */ component->decoder = HOLD_BACK_COUNT(decoder); component->obj = obj; component->name = JS_NewStringCopyZ(cx, name); if (!component->name || !JS_LockGCThing(cx, component->name)) return NULL; return component; }
static inline bool Define(JSContext* cx, JSObject* obj, JSPropertySpec* spec) { return JS_DefineProperties(cx, obj, spec); }
PRBool CreateFakeBrowserWindow(JSContext* cx, JSObject* parent, nsIPrincipal* systemPrincipal) { nsresult rv; jsval value; nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID()); if (xpc == nsnull) { JS_ReportError(cx, "Adblock Plus: Coult not retrieve nsIXPConnect - wrong Gecko version?"); return PR_FALSE; } rv = xpc->FlagSystemFilenamePrefix("adblockplus.dll/"); if (NS_FAILED(rv)) { JS_ReportError(cx, "Adblock Plus: Failed to enable protection for inline JavaScript"); return PR_FALSE; } JSObject* obj = JS_NewObject(cx, nsnull, nsnull, parent); if (obj == nsnull) { JS_ReportError(cx, "Adblock Plus: Failed to create fake browser window object - out of memory?"); return PR_FALSE; } JS_SetGlobalObject(cx, obj); // Have to loop through the methods manually because JS_DefineFunctions won't do anything for some reason for (JSFunctionSpec *fs = window_methods; fs->name; fs++) { JSFunction *fun = JS_DefineFunction(cx, obj, fs->name, fs->call, fs->nargs, fs->flags); if (!fun) { JS_ReportError(cx, "Adblock Plus: Failed to attach native methods to fake browser window"); return PR_FALSE; } } if (!JS_DefineProperties(cx, obj, window_properties)) { JS_ReportError(cx, "Adblock Plus: Failed to attach native properties to fake browser window"); return PR_FALSE; } JSPrincipals* principals; rv = systemPrincipal->GetJSPrincipals(cx, &principals); if (NS_FAILED(rv)) { JS_ReportError(cx, "Adblock Plus: Could not convert system principal into JavaScript principals"); return PR_FALSE; } for (int i = 0; includes[i]; i += 2) { JSScript* inlineScript = JS_CompileScriptForPrincipals(cx, obj, principals, includes[i+1], strlen(includes[i+1]), includes[i], 1); if (inlineScript == nsnull) { JS_ReportError(cx, "Adblock Plus: Failed to compile %s", includes[i]); return PR_FALSE; } if (!JS_ExecuteScript(cx, obj, inlineScript, &value)) { JS_ReportError(cx, "Adblock Plus: Failed to execute %s", includes[i]); return PR_FALSE; } JS_DestroyScript(cx, inlineScript); } JSPRINCIPALS_DROP(cx, principals); nsCOMPtr<nsISupports> wrapped; rv = xpc->WrapJS(cx, obj, NS_GET_IID(nsISupports), getter_AddRefs(wrapped)); if (NS_FAILED(rv)) { JS_ReportError(cx, "Adblock Plus: Failed to create XPConnect wrapper for fake browser window"); return PR_FALSE; } fakeBrowserWindow = do_QueryInterface(wrapped); if (fakeBrowserWindow == nsnull) { JS_ReportError(cx, "Adblock Plus: Failed to QI fake browser window"); return PR_FALSE; } jsval readerVal; JS_GetProperty(cx, obj, "_dtdReader", &readerVal); if (readerVal == JSVAL_VOID) { JS_ReportError(cx, "Adblock Plus: Failed to retrieve DTD reader object"); return PR_FALSE; } JSObject* reader = JSVAL_TO_OBJECT(readerVal); for (int i = 0; i < NUM_LABELS; i++) { JSString* str = JS_NewStringCopyZ(cx, context_labels[i]); if (str == nsnull) { JS_ReportError(cx, "Adblock Plus: Could not create JavaScript string for '%s' - out of memory?", context_labels[i]); return PR_FALSE; } jsval args[] = {STRING_TO_JSVAL(str)}; jsval retval; if (!JS_CallFunctionName(cx, reader, "getEntity", 1, args, &retval)) { JS_ReportError(cx, "Adblock Plus: Failed to retrieve entity '%s' from overlay.dtd", context_labels[i]); return PR_FALSE; } str = JS_ValueToString(cx, retval); if (str == nsnull) { JS_ReportError(cx, "Adblock Plus: Could not convert return value of _dtdReader.getEntity() to string"); return PR_FALSE; } strcpy_s(labelValues[i], sizeof(labelValues[i]), JS_GetStringBytes(str)); } return PR_TRUE; }
int ExecShellScript(const char * file, int argc, char** argv, JSContext * context, JSObject * env, jsval * vp) { register FILE * filep; register int c; filep = fopen(file, "rb"); if (!filep) { JS_ReportError(context, "%s: %s", file, "No such file or directory"); return 0; } if (getc(filep) == '#' && getc(filep) == '!') { c = 1; while (c != EOF && c != '\n') c = getc(filep); ungetc(c, filep); } else { fclose(filep); JS_ReportError(context, "%s: %s", file, "is not a shell script"); return 0; } JSObject* argsObj = JS_NewArrayObject(context, 0, NULL); JS_DefineProperty(context, env, "parameter", OBJECT_TO_JSVAL(argsObj), NULL, NULL, 0); JSString* str = JS_NewStringCopyZ(context, file); JS_DefineElement(context, argsObj, 0, STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE); int i; for (i = 0; i < argc; i++) { str = JS_NewStringCopyZ(context, argv[i]); JS_DefineElement(context, argsObj, i + 1, STRING_TO_JSVAL(str), NULL, NULL, JSPROP_ENUMERATE); } setenv(SMASH_RESOURCE_PATH_ENV_ID, GET_STRING_DEF(SMASH_RESOURCE_PATH), 0); JS_InitCTypesClass(context, env); JS_DefineFunctions(context, env, shell_functions); JS_DefineProperties(context, env, shell_properties); jsval fun; JS_GetProperty(context, env, "system", &fun); JS_DefineFunction(context, JSVAL_TO_OBJECT(fun), "read", ShellSystemRead, 1, JSPROP_ENUMERATE); JS_DefineFunction(context, JSVAL_TO_OBJECT(fun), "write", ShellSystemWrite, 2, JSPROP_ENUMERATE); jsval fun2; JS_GetProperty(context, env, "echo", &fun2); JS_DefineFunction(context, JSVAL_TO_OBJECT(fun2), "error", ShellEchoError, 1, JSPROP_ENUMERATE); jsval fun3; JS_GetProperty(context, env, "setFileContent", &fun3); JS_DefineFunction(context, JSVAL_TO_OBJECT(fun3), "append", ShellSetFileContentAppend, 2, JSPROP_ENUMERATE); #ifdef SMASH_MAIN_LOADER //ExecScriptFile(context, env, GET_STRING_DEF(SMASH_MAIN_LOADER), NULL); #endif #ifdef SMASH_SHELL_LOADER ExecScriptFile(context, env, GET_STRING_DEF(SMASH_SHELL_LOADER), NULL); #endif JSObject * jsTemp = JS_CompileFileHandle(context, env, file, filep); fclose(filep); if (jsTemp) { return JS_ExecuteScript(context, env, jsTemp, vp); } else { JS_ReportPendingException(context); return 1; } }
void * spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter) { JSContext *ctx; JSObject *window_obj, *document_obj, *forms_obj, *history_obj, *location_obj, *statusbar_obj, *menubar_obj, *navigator_obj; assert(interpreter); if (!js_module_init_ok) return NULL; ctx = JS_NewContext(spidermonkey_runtime, 8192 /* Stack allocation chunk size */); if (!ctx) return NULL; interpreter->backend_data = ctx; JS_SetContextPrivate(ctx, interpreter); JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); JS_SetVersion(ctx, JSVERSION_LATEST); JS_SetErrorReporter(ctx, error_reporter); #if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT) JS_SetOperationCallback(ctx, heartbeat_callback); #endif window_obj = JS_NewCompartmentAndGlobalObject(ctx, (JSClass *) &window_class, NULL); if (!window_obj) goto release_and_fail; if (!JS_InitStandardClasses(ctx, window_obj)) goto release_and_fail; if (!JS_DefineProperties(ctx, window_obj, (JSPropertySpec *) window_props)) goto release_and_fail; if (!spidermonkey_DefineFunctions(ctx, window_obj, window_funcs)) goto release_and_fail; if (!JS_SetPrivate(ctx, window_obj, interpreter->vs)) /* to @window_class */ goto release_and_fail; document_obj = spidermonkey_InitClass(ctx, window_obj, NULL, (JSClass *) &document_class, NULL, 0, (JSPropertySpec *) document_props, document_funcs, NULL, NULL); if (!document_obj) goto release_and_fail; forms_obj = spidermonkey_InitClass(ctx, document_obj, NULL, (JSClass *) &forms_class, NULL, 0, (JSPropertySpec *) forms_props, forms_funcs, NULL, NULL); if (!forms_obj) goto release_and_fail; history_obj = spidermonkey_InitClass(ctx, window_obj, NULL, (JSClass *) &history_class, NULL, 0, (JSPropertySpec *) NULL, history_funcs, NULL, NULL); if (!history_obj) goto release_and_fail; location_obj = spidermonkey_InitClass(ctx, window_obj, NULL, (JSClass *) &location_class, NULL, 0, (JSPropertySpec *) location_props, location_funcs, NULL, NULL); if (!location_obj) goto release_and_fail; menubar_obj = JS_InitClass(ctx, window_obj, NULL, (JSClass *) &menubar_class, NULL, 0, (JSPropertySpec *) unibar_props, NULL, NULL, NULL); if (!menubar_obj) goto release_and_fail; if (!JS_SetPrivate(ctx, menubar_obj, "t")) /* to @menubar_class */ goto release_and_fail; statusbar_obj = JS_InitClass(ctx, window_obj, NULL, (JSClass *) &statusbar_class, NULL, 0, (JSPropertySpec *) unibar_props, NULL, NULL, NULL); if (!statusbar_obj) goto release_and_fail; if (!JS_SetPrivate(ctx, statusbar_obj, "s")) /* to @statusbar_class */ goto release_and_fail; navigator_obj = JS_InitClass(ctx, window_obj, NULL, (JSClass *) &navigator_class, NULL, 0, (JSPropertySpec *) navigator_props, NULL, NULL, NULL); if (!navigator_obj) goto release_and_fail; return ctx; release_and_fail: spidermonkey_put_interpreter(interpreter); return NULL; }