summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2012-12-08 00:07:55 +0100
committerportix <portix@gmx.net>2012-12-08 00:07:55 +0100
commite546c944645580065fd7b8df7f2e048f11d26311 (patch)
treec118c4f11485bd9f4bc963c1ae436b2ceaefff4a /src
parent258e4e4b60c69c2d47369d15003cac863444b1d8 (diff)
downloaddwb-e546c944645580065fd7b8df7f2e048f11d26311.zip
Don't break a callback chain of a deferred if one callback function is missing
Diffstat (limited to 'src')
-rw-r--r--src/scripts.c53
1 files changed, 26 insertions, 27 deletions
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);