mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05: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:
parent
12bb8fdfe7
commit
b2c387f1f4
@ -17,7 +17,11 @@
|
|||||||
|
|
||||||
struct smjs_load_uri_hop {
|
struct smjs_load_uri_hop {
|
||||||
struct session *ses;
|
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
|
static void
|
||||||
@ -39,16 +43,13 @@ smjs_loading_callback(struct download *download, void *data)
|
|||||||
* the script is using it. */
|
* the script is using it. */
|
||||||
object_lock(download->cached);
|
object_lock(download->cached);
|
||||||
|
|
||||||
assert(hop->callback);
|
|
||||||
|
|
||||||
smjs_ses = hop->ses;
|
smjs_ses = hop->ses;
|
||||||
|
|
||||||
cache_entry_object = smjs_get_cache_entry_object(download->cached);
|
cache_entry_object = smjs_get_cache_entry_object(download->cached);
|
||||||
if (!cache_entry_object) goto end;
|
if (!cache_entry_object) goto end;
|
||||||
|
|
||||||
args[0] = OBJECT_TO_JSVAL(cache_entry_object);
|
args[0] = OBJECT_TO_JSVAL(cache_entry_object);
|
||||||
|
JS_CallFunctionValue(smjs_ctx, NULL, hop->callback, 1, args, &rval);
|
||||||
JS_CallFunction(smjs_ctx, NULL, hop->callback, 1, args, &rval);
|
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (download->cached)
|
if (download->cached)
|
||||||
@ -85,12 +86,12 @@ smjs_load_uri(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv,
|
|||||||
|
|
||||||
hop = mem_alloc(sizeof(*hop));
|
hop = mem_alloc(sizeof(*hop));
|
||||||
if (!hop) {
|
if (!hop) {
|
||||||
done_uri(uri);
|
|
||||||
mem_free(download);
|
mem_free(download);
|
||||||
|
done_uri(uri);
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
hop->callback = JS_ValueToFunction(smjs_ctx, argv[1]);
|
hop->callback = argv[1];
|
||||||
hop->ses = smjs_ses;
|
hop->ses = smjs_ses;
|
||||||
|
|
||||||
download->data = hop;
|
download->data = hop;
|
||||||
|
Loading…
Reference in New Issue
Block a user