1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00

Bug 1029: Use JS_CallFunctionValue in load_uri.c

JS_CallFunction does not support closures in SpiderMonkey versions
earlier than 1.8.  Test case:

elinks.keymaps.main["!"] = function() {
    elinks.load_uri("http://www.eldar.org/cgi-bin/fortune.pl?text_format=yes",
		    function (cached) { elinks.alert(cached.content); });
}
This commit is contained in:
Kalle Olavi Niemitalo 2008-07-12 01:24:51 +03:00 committed by Kalle Olavi Niemitalo
parent 12bb8fdfe7
commit b2c387f1f4

View File

@ -17,7 +17,11 @@
struct smjs_load_uri_hop {
struct session *ses;
JSFunction *callback;
/* SpiderMonkey versions earlier than 1.8 cannot properly call
* a closure if given just a JSFunction pointer. They need a
* jsval that points to the corresponding JSObject. */
jsval callback;
};
static void
@ -39,16 +43,13 @@ smjs_loading_callback(struct download *download, void *data)
* the script is using it. */
object_lock(download->cached);
assert(hop->callback);
smjs_ses = hop->ses;
cache_entry_object = smjs_get_cache_entry_object(download->cached);
if (!cache_entry_object) goto end;
args[0] = OBJECT_TO_JSVAL(cache_entry_object);
JS_CallFunction(smjs_ctx, NULL, hop->callback, 1, args, &rval);
JS_CallFunctionValue(smjs_ctx, NULL, hop->callback, 1, args, &rval);
end:
if (download->cached)
@ -85,12 +86,12 @@ smjs_load_uri(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
hop = mem_alloc(sizeof(*hop));
if (!hop) {
done_uri(uri);
mem_free(download);
done_uri(uri);
return JS_FALSE;
}
hop->callback = JS_ValueToFunction(smjs_ctx, argv[1]);
hop->callback = argv[1];
hop->ses = smjs_ses;
download->data = hop;