1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

ECMAScript: evaluating onclick, onsubmit etc. done in the right way.

Scripts such as onsubmit are called as a function not as a script.
This commit is contained in:
Witold Filipczyk 2007-05-19 20:54:08 +02:00 committed by Witold Filipczyk
parent a29ef8600c
commit 688ca8cf31
2 changed files with 10 additions and 3 deletions

View File

@ -209,6 +209,7 @@ see_eval_boolback(struct ecmascript_interpreter *interpreter,
struct SEE_interpreter *interp = interpreter->backend_data; struct SEE_interpreter *interp = interpreter->backend_data;
struct global_object *g = (struct global_object *)interp; struct global_object *g = (struct global_object *)interp;
struct SEE_input *input = see_input_elinks(interp, code->source); struct SEE_input *input = see_input_elinks(interp, code->source);
struct SEE_object *fun;
SEE_try_context_t try_ctxt; SEE_try_context_t try_ctxt;
struct SEE_value result; struct SEE_value result;
struct SEE_value *e; struct SEE_value *e;
@ -220,7 +221,8 @@ see_eval_boolback(struct ecmascript_interpreter *interpreter,
g->exec_start = time(NULL); g->exec_start = time(NULL);
g->ret = NULL; g->ret = NULL;
SEE_TRY(interp, try_ctxt) { SEE_TRY(interp, try_ctxt) {
SEE_Global_eval(interp, input, &result); fun = SEE_Function_new(interp, NULL, NULL, input);
SEE_OBJECT_CALL(interp, fun, NULL, 0, NULL, &result);
/* history.back() returns SEE_NULL */ /* history.back() returns SEE_NULL */
if (SEE_VALUE_GET_TYPE(&result) == SEE_NULL) if (SEE_VALUE_GET_TYPE(&result) == SEE_NULL)
res = 0; res = 0;

View File

@ -288,6 +288,7 @@ spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter,
struct string *code) struct string *code)
{ {
JSContext *ctx; JSContext *ctx;
JSFunction *fun;
jsval rval; jsval rval;
int ret; int ret;
@ -295,8 +296,12 @@ spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter,
ctx = interpreter->backend_data; ctx = interpreter->backend_data;
setup_safeguard(interpreter, ctx); setup_safeguard(interpreter, ctx);
interpreter->ret = NULL; interpreter->ret = NULL;
ret = JS_EvaluateScript(ctx, JS_GetGlobalObject(ctx), fun = JS_CompileFunction(ctx, NULL, "", 0, NULL, code->source,
code->source, code->length, "", 0, &rval); code->length, "", 0);
if (!fun)
return -1;
ret = JS_CallFunction(ctx, NULL, fun, 0, NULL, &rval);
if (ret == 2) { /* onClick="history.back()" */ if (ret == 2) { /* onClick="history.back()" */
return 0; return 0;
} }