summaryrefslogtreecommitdiff
path: root/src/scripts.c
diff options
context:
space:
mode:
authorportix <none@none>2013-02-25 16:43:26 +0100
committerportix <none@none>2013-02-25 16:43:26 +0100
commitcf51ec02bdb453a642e3a0a468dc67259d2aa904 (patch)
tree42c77712109084e06fa4c6201bf9bcd9980165c0 /src/scripts.c
parentb843d5c2abeee780ec3ef2d14c61e185986e9509 (diff)
downloaddwb-cf51ec02bdb453a642e3a0a468dc67259d2aa904.zip
Check script syntax before creating the script object; implementing Function.debug
Diffstat (limited to 'src/scripts.c')
-rw-r--r--src/scripts.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/scripts.c b/src/scripts.c
index 6797f6c1..2cb547d1 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -3406,14 +3406,17 @@ scripts_init_script(const char *path, const char *script)
if (s_global_context == NULL)
create_global_object();
- debug = g_strdup_printf("\n"
- "try{const self=this;"
- "Object.defineProperties(this,{'path':{value:'%s'},'debug':{value:io.debug.bind(this)}});Object.freeze(this);"
- "/*<dwb*/%s/*dwb>*/}catch(e){this.debug({error:e});};", path, script);
- JSObjectRef function = js_make_function(s_global_context, debug);
+ if (js_check_syntax(s_global_context, script, path, 1))
+ {
+ debug = g_strdup_printf("\n"
+ "try{const script=this;"
+ "Object.defineProperties(this,{'path':{value:'%s'},'debug':{value:io.debug.bind(this)}});Object.freeze(this);"
+ "/*<dwb*/%s/*dwb>*/}catch(e){this.debug({error:e});};", path, script);
+ JSObjectRef function = js_make_function(s_global_context, debug);
- if (function != NULL)
- s_script_list = g_slist_prepend(s_script_list, function);
+ if (function != NULL)
+ s_script_list = g_slist_prepend(s_script_list, function);
+ }
g_free(debug);
}/*}}}*/
@@ -3534,20 +3537,10 @@ scripts_check_syntax(char **scripts)
const char *tmp = content;
if (g_str_has_prefix(tmp, "#!javascript"))
tmp += 12;
-
- JSValueRef exc = NULL;
- JSStringRef script = JSStringCreateWithUTF8CString(tmp);
-
- if (!JSCheckScriptSyntax(s_global_context, script, NULL, 0, &exc))
- {
- fprintf(stderr, "DWB SCRIPT EXCEPTION: in file %s\n", scripts[i]);
- js_print_exception(s_global_context, exc);
- }
- else
+ if (js_check_syntax(s_global_context, tmp, scripts[i], 0))
{
fprintf(stderr, "Syntax of %s is correct.\n", scripts[i]);
}
- JSStringRelease(script);
g_free(content);
}
}