/*----------------------------------------------------------------------------* * Scripter descriptor * *----------------------------------------------------------------------------*/ static void * _egueb_script_js_sm_scripter_new(void) { Egueb_Script_Js_Sm_Scripter *thiz; thiz = calloc(1, sizeof(Egueb_Script_Js_Sm_Scripter)); /* Create an instance of the engine */ thiz->rt = JS_NewRuntime(1024 * 1024); JS_SetRuntimePrivate(thiz->rt, thiz); /* Create an execution context */ thiz->cx = JS_NewContext(thiz->rt, 8192); JS_SetOptions(thiz->cx, JS_GetOptions(thiz->cx) | JSOPTION_VAROBJFIX); JS_SetErrorReporter(thiz->cx, _egueb_script_js_sm_scripter_report_error); _egueb_script_js_sm_init_global_object(thiz); return thiz; }
/** * gjs_runtime_init: * @runtime: a #JSRuntime * * Initializes a #JSRuntime for use with GJS * * This should only be called by GJS, not by applications. */ void gjs_runtime_init(JSRuntime *runtime) { RuntimeData *rd; /* If we went back to supporting foreign contexts, we couldn't use * JS_SetRuntimePrivate() because the runtime's owner might * already be using it. A simple solution would be to just store * the runtime data in a global variable - multiple copies of GJS * in the same process at the same time have issues anyways * because of limitations of GObject toggle references - if two * separate entities toggle reference an object it will leak. */ if (JS_GetRuntimePrivate(runtime) != NULL) gjs_fatal("JSRuntime already initialized or private data in use by someone else"); rd = g_slice_new0(RuntimeData); rd->dynamic_classes = g_hash_table_new(g_direct_hash, g_direct_equal); JS_SetRuntimePrivate(runtime, rd); }
static VALUE initialize_native(VALUE self, VALUE UNUSED(options)) { JohnsonRuntime* runtime; Data_Get_Struct(self, JohnsonRuntime, runtime); if ((runtime->js = JS_NewRuntime(0x100000)) && (runtime->jsids = create_id_hash()) && (runtime->rbids = create_id_hash()) ) { JS_SetRuntimePrivate(runtime->js, (void *)self); JS_SetGCCallbackRT(runtime->js, gc_callback); JSContext* context = johnson_get_current_context(runtime); if( (runtime->global = JS_GetGlobalObject(context)) && (JS_AddNamedRoot(context, &(runtime->global), "runtime->global")) ) { return self; } } if (runtime->rbids) JS_HashTableDestroy(runtime->rbids); if (runtime->jsids) JS_HashTableDestroy(runtime->jsids); if (runtime->js) JS_DestroyRuntime(runtime->js); rb_raise(rb_eRuntimeError, "Couldn't initialize the runtime!"); return Qnil; }