mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -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 void
|
||||
static int
|
||||
smjs_do_file(unsigned char *path)
|
||||
{
|
||||
int ret = 1;
|
||||
jsval rval;
|
||||
struct string script;
|
||||
|
||||
if (!init_string(&script)) return;
|
||||
if (!init_string(&script)) return 0;
|
||||
|
||||
if (add_file_to_string(&script, path)
|
||||
&& JS_FALSE == JS_EvaluateScript(smjs_ctx,
|
||||
if (!add_file_to_string(&script, path)
|
||||
|| JS_FALSE == JS_EvaluateScript(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");
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
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
|
||||
@ -122,6 +140,9 @@ init_smjs(struct module *module)
|
||||
smjs_init_elinks_object();
|
||||
|
||||
smjs_load_hooks();
|
||||
|
||||
JS_DefineFunction(smjs_ctx, smjs_global_object, "do_file",
|
||||
&smjs_do_file_wrapper, 1, 0);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user