JS: Attribute external JS to the URI it came from in backtraces

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
Daniel Silverstone 2019-05-04 17:32:17 +01:00
parent 8009444918
commit ed829a4772
4 changed files with 16 additions and 9 deletions

View File

@ -42,7 +42,7 @@
#include "html/html.h" #include "html/html.h"
#include "html/html_internal.h" #include "html/html_internal.h"
typedef bool (script_handler_t)(struct jscontext *jscontext, const char *data, size_t size) ; typedef bool (script_handler_t)(struct jscontext *jscontext, const char *data, size_t size, const char *name);
static script_handler_t *select_script_handler(content_type ctype) static script_handler_t *select_script_handler(content_type ctype)
@ -91,10 +91,11 @@ nserror html_script_exec(html_content *c, bool allow_defer)
CONTENT_STATUS_DONE) { CONTENT_STATUS_DONE) {
/* external script is now available */ /* external script is now available */
const char *data; const char *data;
unsigned long size; size_t size;
data = content_get_source_data( data = content_get_source_data(
s->data.handle, &size ); s->data.handle, &size );
script_handler(c->jscontext, data, size); script_handler(c->jscontext, data, size,
nsurl_access(hlcache_handle_get_url(s->data.handle)));
s->already_started = true; s->already_started = true;
@ -307,7 +308,8 @@ convert_script_sync_cb(hlcache_handle *script,
const char *data; const char *data;
unsigned long size; unsigned long size;
data = content_get_source_data(s->data.handle, &size ); data = content_get_source_data(s->data.handle, &size );
script_handler(parent->jscontext, data, size); script_handler(parent->jscontext, data, size,
nsurl_access(hlcache_handle_get_url(s->data.handle)));
} }
/* continue parse */ /* continue parse */
@ -531,7 +533,8 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
if (script_handler != NULL) { if (script_handler != NULL) {
script_handler(c->jscontext, script_handler(c->jscontext,
dom_string_data(script), dom_string_data(script),
dom_string_byte_length(script)); dom_string_byte_length(script),
"?inline script?");
} }
return DOM_HUBBUB_OK; return DOM_HUBBUB_OK;
} }

View File

@ -716,7 +716,7 @@ duk_int_t dukky_pcall(duk_context *ctx, duk_size_t argc, bool reset_timeout)
} }
bool js_exec(jscontext *ctx, const char *txt, size_t txtlen) bool js_exec(jscontext *ctx, const char *txt, size_t txtlen, const char *name)
{ {
assert(ctx); assert(ctx);
if (txt == NULL || txtlen == 0) return false; if (txt == NULL || txtlen == 0) return false;
@ -724,7 +724,11 @@ bool js_exec(jscontext *ctx, const char *txt, size_t txtlen)
NSLOG(dukky, DEEPDEBUG, "%zd bytes: %s", txtlen, txt); NSLOG(dukky, DEEPDEBUG, "%zd bytes: %s", txtlen, txt);
(void) nsu_getmonotonic_ms(&ctx->exec_start_time); (void) nsu_getmonotonic_ms(&ctx->exec_start_time);
duk_push_string(CTX, "?unknown source?"); if (name != NULL) {
duk_push_string(CTX, name);
} else {
duk_push_string(CTX, "?unknown source?");
}
if (duk_pcompile_lstring_filename(CTX, DUK_COMPILE_EVAL, txt, txtlen) != 0) { if (duk_pcompile_lstring_filename(CTX, DUK_COMPILE_EVAL, txt, txtlen) != 0) {
NSLOG(dukky, INFO, "Failed to compile JavaScript input"); NSLOG(dukky, INFO, "Failed to compile JavaScript input");
goto handle_error; goto handle_error;

View File

@ -67,7 +67,7 @@ void js_destroycontext(jscontext *ctx);
jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv); jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv);
/* execute some javascript in a context */ /* execute some javascript in a context */
bool js_exec(jscontext *ctx, const char *txt, size_t txtlen); bool js_exec(jscontext *ctx, const char *txt, size_t txtlen, const char *name);
/* fire an event at a dom node */ /* fire an event at a dom node */

View File

@ -51,7 +51,7 @@ jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv)
return NULL; return NULL;
} }
bool js_exec(jscontext *ctx, const char *txt, size_t txtlen) bool js_exec(jscontext *ctx, const char *txt, size_t txtlen, const char *name)
{ {
return true; return true;
} }