mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[spidermonkey] JS::Heap in element listeners
This commit is contained in:
parent
bf1ef237b7
commit
7d0b5899a3
@ -120,13 +120,13 @@ static bool element_set_property_value(JSContext *ctx, unsigned int argc, JS::Va
|
||||
struct ele_listener {
|
||||
LIST_HEAD_EL(struct ele_listener);
|
||||
char *typ;
|
||||
JS::RootedValue fun;
|
||||
JS::Heap<JS::Value> *fun;
|
||||
};
|
||||
|
||||
struct element_private {
|
||||
LIST_OF(struct ele_listener) listeners;
|
||||
struct ecmascript_interpreter *interpreter;
|
||||
JS::RootedObject thisval;
|
||||
JS::Heap<JSObject *> thisval;
|
||||
dom_event_listener *listener;
|
||||
dom_node *node;
|
||||
int ref_count;
|
||||
@ -221,6 +221,7 @@ static void element_finalize(JS::GCContext *op, JSObject *obj)
|
||||
|
||||
foreach(l, el_private->listeners) {
|
||||
mem_free_set(&l->typ, NULL);
|
||||
delete (l->fun);
|
||||
}
|
||||
free_list(el_private->listeners);
|
||||
mem_free(el_private);
|
||||
@ -3879,7 +3880,7 @@ element_addEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
if (strcmp(l->typ, method)) {
|
||||
continue;
|
||||
}
|
||||
if (l->fun == fun) {
|
||||
if (*(l->fun) == fun) {
|
||||
mem_free(method);
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
@ -3891,7 +3892,7 @@ element_addEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
args.rval().setUndefined();
|
||||
return false;
|
||||
}
|
||||
n->fun = fun;
|
||||
n->fun = new JS::Heap<JS::Value>(fun);
|
||||
n->typ = method;
|
||||
add_to_list_end(el_private->listeners, n);
|
||||
dom_exception exc;
|
||||
@ -3978,7 +3979,7 @@ element_removeEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
if (strcmp(l->typ, method)) {
|
||||
continue;
|
||||
}
|
||||
if (l->fun == fun) {
|
||||
if (*(l->fun) == fun) {
|
||||
|
||||
dom_string *typ = NULL;
|
||||
dom_exception exc = dom_string_create(method, strlen(method), &typ);
|
||||
@ -3991,6 +3992,7 @@ element_removeEventListener(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
|
||||
del_from_list(l);
|
||||
mem_free_set(&l->typ, NULL);
|
||||
delete (l->fun);
|
||||
mem_free(l);
|
||||
mem_free(method);
|
||||
args.rval().setUndefined();
|
||||
@ -5331,15 +5333,18 @@ check_element_event(void *interp, void *elem, const char *event_name, struct ter
|
||||
continue;
|
||||
}
|
||||
if (ev && ev->ev == EVENT_KBD && (!strcmp(event_name, "keydown") || !strcmp(event_name, "keyup") || !strcmp(event_name, "keypress"))) {
|
||||
JS::RootedValueVector argv(ctx);
|
||||
if (!argv.resize(1)) {
|
||||
return;
|
||||
}
|
||||
JS::RootedValueArray<1> argv(ctx);
|
||||
obj = get_keyboardEvent(ctx, ev);
|
||||
argv[0].setObject(*obj);
|
||||
JS_CallFunctionValue(ctx, el_private->thisval, l->fun, argv, &r_val);
|
||||
JS::RootedValue r_val(ctx);
|
||||
JS::RootedObject thisv(ctx, el_private->thisval);
|
||||
JS::RootedValue vfun(ctx, *(l->fun));
|
||||
JS_CallFunctionValue(ctx, thisv, vfun, argv, &r_val);
|
||||
} else {
|
||||
JS_CallFunctionValue(ctx, el_private->thisval, l->fun, JS::HandleValueArray::empty(), &r_val);
|
||||
JS::RootedValue r_val(ctx);
|
||||
JS::RootedObject thisv(ctx, el_private->thisval);
|
||||
JS::RootedValue vfun(ctx, *(l->fun));
|
||||
JS_CallFunctionValue(ctx, thisv, vfun, JS::HandleValueArray::empty(), &r_val);
|
||||
}
|
||||
}
|
||||
done_heartbeat(interpreter->heartbeat);
|
||||
@ -5424,14 +5429,12 @@ element_event_handler(dom_event *event, void *pw)
|
||||
if (strcmp(l->typ, dom_string_data(typ))) {
|
||||
continue;
|
||||
}
|
||||
JS::RootedValueVector argv(ctx);
|
||||
|
||||
if (!argv.resize(1)) {
|
||||
return;
|
||||
}
|
||||
JS::RootedValueArray<1> argv(ctx);
|
||||
argv[0].setObject(*obj_ev);
|
||||
JS::RootedValue r_val(ctx);
|
||||
JS_CallFunctionValue(ctx, el_private->thisval, l->fun, argv, &r_val);
|
||||
JS::RootedObject thisv(ctx, el_private->thisval);
|
||||
JS::RootedValue vfun(ctx, *(l->fun));
|
||||
JS_CallFunctionValue(ctx, thisv, vfun, argv, &r_val);
|
||||
}
|
||||
done_heartbeat(interpreter->heartbeat);
|
||||
check_for_rerender(interpreter, dom_string_data(typ));
|
||||
|
Loading…
x
Reference in New Issue
Block a user