mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -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)
|
spidermonkey_runtime_addref(void)
|
||||||
{
|
{
|
||||||
if (!spidermonkey_runtime) {
|
if (!spidermonkey_runtime) {
|
||||||
|
JSContext *dummy;
|
||||||
|
|
||||||
assert(spidermonkey_runtime_refcount == 0);
|
assert(spidermonkey_runtime_refcount == 0);
|
||||||
if_assert_failed return 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;
|
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++;
|
spidermonkey_runtime_refcount++;
|
||||||
assert(spidermonkey_runtime_refcount > 0);
|
assert(spidermonkey_runtime_refcount > 0);
|
||||||
if_assert_failed { spidermonkey_runtime_refcount--; return 0; }
|
if_assert_failed { spidermonkey_runtime_refcount--; return 0; }
|
||||||
@ -54,6 +67,7 @@ spidermonkey_runtime_release(void)
|
|||||||
if (spidermonkey_runtime_refcount == 0) {
|
if (spidermonkey_runtime_refcount == 0) {
|
||||||
JS_DestroyRuntime(spidermonkey_runtime);
|
JS_DestroyRuntime(spidermonkey_runtime);
|
||||||
spidermonkey_runtime = NULL;
|
spidermonkey_runtime = NULL;
|
||||||
|
JS_ShutDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
|
|
||||||
/* TODO? Are there any which need to be implemented? */
|
/* TODO? Are there any which need to be implemented? */
|
||||||
|
|
||||||
static JSRuntime *jsrt;
|
static int js_module_init_ok;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
error_reporter(JSContext *ctx, const char *message, JSErrorReport *report)
|
error_reporter(JSContext *ctx, const char *message, JSErrorReport *report)
|
||||||
@ -137,19 +137,14 @@ setup_safeguard(struct ecmascript_interpreter *interpreter,
|
|||||||
static void
|
static void
|
||||||
spidermonkey_init(struct module *xxx)
|
spidermonkey_init(struct module *xxx)
|
||||||
{
|
{
|
||||||
jsrt = JS_NewRuntime(0x400000UL);
|
js_module_init_ok = spidermonkey_runtime_addref();
|
||||||
/* 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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
spidermonkey_done(struct module *xxx)
|
spidermonkey_done(struct module *xxx)
|
||||||
{
|
{
|
||||||
JS_DestroyRuntime(jsrt);
|
if (js_module_init_ok)
|
||||||
JS_ShutDown();
|
spidermonkey_runtime_release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -161,8 +156,10 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
*statusbar_obj, *menubar_obj, *navigator_obj;
|
*statusbar_obj, *menubar_obj, *navigator_obj;
|
||||||
|
|
||||||
assert(interpreter);
|
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)
|
if (!ctx)
|
||||||
return NULL;
|
return NULL;
|
||||||
interpreter->backend_data = ctx;
|
interpreter->backend_data = ctx;
|
||||||
@ -236,6 +233,7 @@ spidermonkey_put_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
JSContext *ctx;
|
JSContext *ctx;
|
||||||
|
|
||||||
assert(interpreter);
|
assert(interpreter);
|
||||||
|
if (!js_module_init_ok) return;
|
||||||
ctx = interpreter->backend_data;
|
ctx = interpreter->backend_data;
|
||||||
JS_DestroyContext(ctx);
|
JS_DestroyContext(ctx);
|
||||||
interpreter->backend_data = NULL;
|
interpreter->backend_data = NULL;
|
||||||
@ -250,6 +248,7 @@ spidermonkey_eval(struct ecmascript_interpreter *interpreter,
|
|||||||
jsval rval;
|
jsval rval;
|
||||||
|
|
||||||
assert(interpreter);
|
assert(interpreter);
|
||||||
|
if (!js_module_init_ok) return;
|
||||||
ctx = interpreter->backend_data;
|
ctx = interpreter->backend_data;
|
||||||
setup_safeguard(interpreter, ctx);
|
setup_safeguard(interpreter, ctx);
|
||||||
interpreter->ret = ret;
|
interpreter->ret = ret;
|
||||||
@ -266,6 +265,7 @@ spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter,
|
|||||||
jsval rval;
|
jsval rval;
|
||||||
|
|
||||||
assert(interpreter);
|
assert(interpreter);
|
||||||
|
if (!js_module_init_ok) return NULL;
|
||||||
ctx = interpreter->backend_data;
|
ctx = interpreter->backend_data;
|
||||||
setup_safeguard(interpreter, ctx);
|
setup_safeguard(interpreter, ctx);
|
||||||
interpreter->ret = NULL;
|
interpreter->ret = NULL;
|
||||||
@ -293,6 +293,7 @@ spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
assert(interpreter);
|
assert(interpreter);
|
||||||
|
if (!js_module_init_ok) return 0;
|
||||||
ctx = interpreter->backend_data;
|
ctx = interpreter->backend_data;
|
||||||
setup_safeguard(interpreter, ctx);
|
setup_safeguard(interpreter, ctx);
|
||||||
interpreter->ret = NULL;
|
interpreter->ret = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user