mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
1031: Replace jsrt with spidermonkey_runtime
src/ecmascript/spidermonkey/ now uses a JSRuntime managed by spidermonkey-shared.c.
This commit is contained in:
parent
2024ea610b
commit
031c1e6143
@ -29,11 +29,24 @@ int
|
||||
spidermonkey_runtime_addref(void)
|
||||
{
|
||||
if (!spidermonkey_runtime) {
|
||||
JSContext *dummy;
|
||||
|
||||
assert(spidermonkey_runtime_refcount == 0);
|
||||
if_assert_failed return 0;
|
||||
spidermonkey_runtime = JS_NewRuntime(1L * 1024L * 1024L);
|
||||
|
||||
spidermonkey_runtime = JS_NewRuntime(4L * 1024L * 1024L);
|
||||
if (!spidermonkey_runtime) return 0;
|
||||
|
||||
/* XXX: This is a hack to avoid a crash on exit.
|
||||
* SMJS will crash on JS_DestroyRuntime if the given
|
||||
* runtime has never had any context created, which
|
||||
* will be the case if one closes ELinks without
|
||||
* having loaded any documents. */
|
||||
dummy = JS_NewContext(spidermonkey_runtime, 0);
|
||||
if (dummy) JS_DestroyContext(dummy);
|
||||
/* Else hope it works anyway. */
|
||||
}
|
||||
|
||||
spidermonkey_runtime_refcount++;
|
||||
assert(spidermonkey_runtime_refcount > 0);
|
||||
if_assert_failed { spidermonkey_runtime_refcount--; return 0; }
|
||||
@ -54,6 +67,7 @@ spidermonkey_runtime_release(void)
|
||||
if (spidermonkey_runtime_refcount == 0) {
|
||||
JS_DestroyRuntime(spidermonkey_runtime);
|
||||
spidermonkey_runtime = NULL;
|
||||
JS_ShutDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@
|
||||
|
||||
/* TODO? Are there any which need to be implemented? */
|
||||
|
||||
static JSRuntime *jsrt;
|
||||
static int js_module_init_ok;
|
||||
|
||||
static void
|
||||
error_reporter(JSContext *ctx, const char *message, JSErrorReport *report)
|
||||
@ -137,19 +137,14 @@ setup_safeguard(struct ecmascript_interpreter *interpreter,
|
||||
static void
|
||||
spidermonkey_init(struct module *xxx)
|
||||
{
|
||||
jsrt = JS_NewRuntime(0x400000UL);
|
||||
/* XXX: This is a hack to avoid a crash on exit. SMJS will crash
|
||||
* on JS_DestroyRuntime if the given runtime has never had any context
|
||||
* created, which will be the case if one closes ELinks without having
|
||||
* loaded any documents. */
|
||||
JS_DestroyContext(JS_NewContext(jsrt, 0));
|
||||
js_module_init_ok = spidermonkey_runtime_addref();
|
||||
}
|
||||
|
||||
static void
|
||||
spidermonkey_done(struct module *xxx)
|
||||
{
|
||||
JS_DestroyRuntime(jsrt);
|
||||
JS_ShutDown();
|
||||
if (js_module_init_ok)
|
||||
spidermonkey_runtime_release();
|
||||
}
|
||||
|
||||
|
||||
@ -161,8 +156,10 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
*statusbar_obj, *menubar_obj, *navigator_obj;
|
||||
|
||||
assert(interpreter);
|
||||
if (!js_module_init_ok) return NULL;
|
||||
|
||||
ctx = JS_NewContext(jsrt, 8192 /* Stack allocation chunk size */);
|
||||
ctx = JS_NewContext(spidermonkey_runtime,
|
||||
8192 /* Stack allocation chunk size */);
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
interpreter->backend_data = ctx;
|
||||
@ -236,6 +233,7 @@ spidermonkey_put_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
JSContext *ctx;
|
||||
|
||||
assert(interpreter);
|
||||
if (!js_module_init_ok) return;
|
||||
ctx = interpreter->backend_data;
|
||||
JS_DestroyContext(ctx);
|
||||
interpreter->backend_data = NULL;
|
||||
@ -250,6 +248,7 @@ spidermonkey_eval(struct ecmascript_interpreter *interpreter,
|
||||
jsval rval;
|
||||
|
||||
assert(interpreter);
|
||||
if (!js_module_init_ok) return;
|
||||
ctx = interpreter->backend_data;
|
||||
setup_safeguard(interpreter, ctx);
|
||||
interpreter->ret = ret;
|
||||
@ -266,6 +265,7 @@ spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter,
|
||||
jsval rval;
|
||||
|
||||
assert(interpreter);
|
||||
if (!js_module_init_ok) return NULL;
|
||||
ctx = interpreter->backend_data;
|
||||
setup_safeguard(interpreter, ctx);
|
||||
interpreter->ret = NULL;
|
||||
@ -293,6 +293,7 @@ spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter,
|
||||
int ret;
|
||||
|
||||
assert(interpreter);
|
||||
if (!js_module_init_ok) return 0;
|
||||
ctx = interpreter->backend_data;
|
||||
setup_safeguard(interpreter, ctx);
|
||||
interpreter->ret = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user