[
https://issues.apache.org/jira/browse/CB-9256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15264064#comment-15264064
]
Steven Wexler edited comment on CB-9256 at 4/29/16 1:47 PM:
------------------------------------------------------------
{quote}
An error thrown in a onDeviceReady callback will prevent execution of all
following onDeviceReady callbacks.
{quote}
That quote is only try for callbacks that are registered before device ready is
fired. All callbacks registered after deviceready is fired will be invoked
regardless of whichever callbacks hit errors. The difference between callbacks
registered before or after deviceready is unexpected and confusing.
If events registered before deviceready is fired:
{code}
document.addEventListener("deviceready", function () { throw new Error("oops");
});
document.addeventListener("deviceready", function () { /*never hit*/ });
{code}
If events registered after deviceready is fired:
{code}
document.addEventListener("deviceready", function () { throw new Error("oops");
});
document.addeventListener("deviceready", function () { /*is hit*/ });
{code}
was (Author: swexler):
{quote}
An error thrown in a onDeviceReady callback will prevent execution of all
following onDeviceReady callbacks.
{quote}
That quote is only try for callbacks that are registered before device ready is
fired. All callbacks registered after deviceready is fired will be invoked
regardless of whichever callbacks hit errors. The difference between callbacks
registered before or after deviceready is unexpected and confusing.
//If events registered before deviceready is fired
{code}
document.addEventListener("deviceready", function () { throw new Error("oops");
});
document.addeventListener("deviceready", function () { /*never hit*/ });
{code}
//If events registered after deviceready is fired
{code}
document.addEventListener("deviceready", function () { throw new Error("oops");
});
document.addeventListener("deviceready", function () { /*is hit*/ });
{code}
> Errors in subscribed event callbacks prevent other subscribed callbacks from
> being invoked
> ------------------------------------------------------------------------------------------
>
> Key: CB-9256
> URL: https://issues.apache.org/jira/browse/CB-9256
> Project: Apache Cordova
> Issue Type: Bug
> Components: CordovaJS
> Reporter: Steven Wexler
>
> Let's say I register two callbacks for the "deviceReady" event before the
> event fires. If the first callback hits an error, the second callback will
> not be invoked
> {code}
> document.addEventListener("deviceready", function () { throw new
> Error("oops"); });
> document.addeventListener("deviceready", function () { /*never hit*/ });
> {code}
> This behavior differs if the events were registered after the event was fired.
> I think the following code should handle callbacks that fail:
> https://github.com/apache/cordova-js/blob/master/src/common/channel.js#L213
> {code}
> for (var i = 0; i < toCall.length; ++i) {
> toCall[i].apply(this, fireArgs);
> }
> {code}
> Should be something like:
> {code}
> var errors = [];
> for (var i = 0; i < toCall.length; ++i) {
> try {
> toCall[i].apply(this, fireArgs);
> } catch (e) {
> errors.push(e);
> }
> }
> for (var j = 0; j < errors.length; ++j) {
> (function (arg) {
> setTimeout(function () { throw errors[arg]; });
> })(j);
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]