mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
Let smjs_do_file return 0 to indicate failure and 1 to indicate
success. Add smjs_do_file_wrapper and let ECMAScript load files with do_file(path).
This commit is contained in:
parent
cb506ea412
commit
b52a29f8c0
@ -68,21 +68,39 @@ reported:
|
|||||||
|
|
||||||
static JSRuntime *smjs_rt;
|
static JSRuntime *smjs_rt;
|
||||||
|
|
||||||
static void
|
static int
|
||||||
smjs_do_file(unsigned char *path)
|
smjs_do_file(unsigned char *path)
|
||||||
{
|
{
|
||||||
|
int ret = 1;
|
||||||
jsval rval;
|
jsval rval;
|
||||||
struct string script;
|
struct string script;
|
||||||
|
|
||||||
if (!init_string(&script)) return;
|
if (!init_string(&script)) return 0;
|
||||||
|
|
||||||
if (add_file_to_string(&script, path)
|
if (!add_file_to_string(&script, path)
|
||||||
&& JS_FALSE == JS_EvaluateScript(smjs_ctx,
|
|| JS_FALSE == JS_EvaluateScript(smjs_ctx,
|
||||||
JS_GetGlobalObject(smjs_ctx),
|
JS_GetGlobalObject(smjs_ctx),
|
||||||
script.source, script.length, path, 1, &rval))
|
script.source, script.length, path, 1, &rval)) {
|
||||||
alert_smjs_error("error loading default script file");
|
alert_smjs_error("error loading default script file");
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
done_string(&script);
|
done_string(&script);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSBool
|
||||||
|
smjs_do_file_wrapper(JSContext *ctx, JSObject *obj, uintN argc,
|
||||||
|
jsval *argv, jsval *rval)
|
||||||
|
{
|
||||||
|
JSString *jsstr = JS_ValueToString(smjs_ctx, *argv);
|
||||||
|
unsigned char *path = JS_GetStringBytes(jsstr);
|
||||||
|
|
||||||
|
if (smjs_do_file(path))
|
||||||
|
return JS_TRUE;
|
||||||
|
|
||||||
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -122,6 +140,9 @@ init_smjs(struct module *module)
|
|||||||
smjs_init_elinks_object();
|
smjs_init_elinks_object();
|
||||||
|
|
||||||
smjs_load_hooks();
|
smjs_load_hooks();
|
||||||
|
|
||||||
|
JS_DefineFunction(smjs_ctx, smjs_global_object, "do_file",
|
||||||
|
&smjs_do_file_wrapper, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user