diff options
-rw-r--r-- | api/dwb-js.7 | 12 | ||||
-rw-r--r-- | api/jsapi.7.txt | 9 | ||||
-rw-r--r-- | api/jsapi.txt | 7 | ||||
-rw-r--r-- | src/scripts.c | 53 |
4 files changed, 39 insertions, 42 deletions
diff --git a/api/dwb-js.7 b/api/dwb-js.7 index db781718..b3cc9a31 100644 --- a/api/dwb-js.7 +++ b/api/dwb-js.7 @@ -2,12 +2,12 @@ .\" Title: dwb-js .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.77.1 <http://docbook.sf.net/> -.\" Date: 12/07/2012 +.\" Date: 12/08/2012 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "DWB\-JS" "7" "12/07/2012" "\ \&" "\ \&" +.TH "DWB\-JS" "7" "12/08/2012" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -1292,7 +1292,7 @@ foo()\&.fail(onResponse)\&.fail(onResponse); .RE .\} .sp -Note that if the deferred is rejected only the fail chain is called, when it is resolved only the done chain is called\&. It is not possible to mix up done and fail chain\&. +Note that if the deferred is rejected only the fail chain is called, when it is resolved only the done chain is called\&. .sp .if n \{\ .RS 4 @@ -1314,10 +1314,10 @@ function onResponse(response) io\&.print(response); } -// Will not be executed at all\&. -foo()\&.done(onResponse)\&.fail(onResponse); -// Only the first callback is executed +// Only the fail will be executed + foo()\&.fail(onResponse)\&.done(onResponse); +foo()\&.done(onResponse)\&.fail(onResponse); .fi .if n \{\ .RE diff --git a/api/jsapi.7.txt b/api/jsapi.7.txt index 3a2ca7cd..a0d223d4 100644 --- a/api/jsapi.7.txt +++ b/api/jsapi.7.txt @@ -631,8 +631,7 @@ foo().fail(onResponse).fail(onResponse); --------------------------------- Note that if the deferred is rejected only the fail chain is called, when it is -resolved only the done chain is called. It is not possible to mix up done -and fail chain. +resolved only the done chain is called. [source,javascript] --------------------------------- function foo() @@ -651,10 +650,10 @@ function onResponse(response) io.print(response); } -// Will not be executed at all. -foo().done(onResponse).fail(onResponse); -// Only the first callback is executed +// Only the fail will be executed + foo().fail(onResponse).done(onResponse); +foo().done(onResponse).fail(onResponse); --------------------------------- Changing the deferred in a callback chain: diff --git a/api/jsapi.txt b/api/jsapi.txt index b04c583a..cb411b95 100644 --- a/api/jsapi.txt +++ b/api/jsapi.txt @@ -1205,8 +1205,7 @@ foo().fail(onResponse).fail(onResponse); --------------------------------- Note that if the deferred is rejected only the fail chain is called, when it is -resolved only the done chain is called. It is not possible to mix up done -and fail chain. +resolved only the done chain is called. [source,javascript] --------------------------------- function foo() @@ -1225,9 +1224,9 @@ function onResponse(response) io.print(response); } -// Will not be executed at all. +// Only the fail will be executed + foo().done(onResponse).fail(onResponse); -// Only the first callback is executed foo().fail(onResponse).done(onResponse); --------------------------------- diff --git a/src/scripts.c b/src/scripts.c index c38f2d24..4da0aed1 100644 --- a/src/scripts.c +++ b/src/scripts.c @@ -1386,10 +1386,10 @@ deferred_destroy(JSContextRef ctx, JSObjectRef this, DeferredPriv *priv) if (priv == NULL) priv = JSObjectGetPrivate(this); + JSObjectSetPrivate(this, NULL); g_free(priv); - JSObjectSetPrivate(this, NULL); JSValueUnprotect(ctx, this); } @@ -1407,13 +1407,12 @@ deferred_new(JSContextRef ctx) static JSValueRef deferred_then(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc) { - if (argc == 0) - return this; DeferredPriv *priv = JSObjectGetPrivate(this); if (priv == NULL) return NIL; - priv->resolve = js_value_to_function(ctx, argv[0], NULL); + if (argc > 0) + priv->resolve = js_value_to_function(ctx, argv[0], NULL); if (argc > 1) priv->reject = js_value_to_function(ctx, argv[1], NULL); @@ -1435,27 +1434,27 @@ deferred_transition(JSContextRef ctx, JSObjectRef old, JSObjectRef new) static JSValueRef deferred_resolve(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc) { + JSValueRef ret = NULL; + DeferredPriv *priv = JSObjectGetPrivate(this); if (priv == NULL) return UNDEFINED; if (priv->resolve) - { + ret = JSObjectCallAsFunction(ctx, priv->resolve, NULL, argc, argv, exc); - JSValueRef ret = JSObjectCallAsFunction(ctx, priv->resolve, NULL, argc, argv, exc); - - if (priv->next) + if (priv->next) + { + if ( ret && JSValueIsObjectOfClass(ctx, ret, s_deferred_class) ) { - if ( ret && JSValueIsObjectOfClass(ctx, ret, s_deferred_class) ) - { - JSObjectRef o = JSValueToObject(ctx, ret, NULL); - deferred_transition(ctx, priv->next, o)->reject = NULL; - priv->next = o; - } - else - deferred_resolve(ctx, f, priv->next, argc, argv, exc); + JSObjectRef o = JSValueToObject(ctx, ret, NULL); + deferred_transition(ctx, priv->next, o)->reject = NULL; + priv->next = o; } + else + deferred_resolve(ctx, f, priv->next, argc, argv, exc); } + deferred_destroy(ctx, this, priv); return UNDEFINED; @@ -1463,25 +1462,25 @@ deferred_resolve(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, static JSValueRef deferred_reject(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc) { + JSValueRef ret = NULL; + DeferredPriv *priv = JSObjectGetPrivate(this); if (priv == NULL) return UNDEFINED; if (priv->reject) - { - JSValueRef ret = JSObjectCallAsFunction(ctx, priv->reject, NULL, argc, argv, exc); + ret = JSObjectCallAsFunction(ctx, priv->reject, NULL, argc, argv, exc); - if (priv->next) + if (priv->next) + { + if ( ret && JSValueIsObjectOfClass(ctx, ret, s_deferred_class) ) { - if ( ret && JSValueIsObjectOfClass(ctx, ret, s_deferred_class) ) - { - JSObjectRef o = JSValueToObject(ctx, ret, NULL); - deferred_transition(ctx, priv->next, o)->resolve = NULL; - priv->next = o; - } - else - deferred_reject(ctx, f, priv->next, argc, argv, exc); + JSObjectRef o = JSValueToObject(ctx, ret, NULL); + deferred_transition(ctx, priv->next, o)->resolve = NULL; + priv->next = o; } + else + deferred_reject(ctx, f, priv->next, argc, argv, exc); } deferred_destroy(ctx, this, priv); |