blackberry / WebWorks-TabletOS

BlackBerry WebWorks for Tablet OS is a platform for building deeply integrated web applications for the BlackBerry PlayBook
http://us.blackberry.com/developers/tablet/webworks.jsp
Apache License 2.0
70 stars 14 forks source link

Callback IDs in ActionScript are stored on the instance and overwritten. #5

Closed gtanner closed 13 years ago

gtanner commented 13 years ago

Example Case:

//I am expecting this to be successful
blackberry.payment.purchase({digitalGoodName: "Successful Purchase"}, function () {
     console.log("win 1");
},
function () {
     console.log("fail 1");
});

blackberry.payment.purchase({digitalGoodName: "Unsuccessful Purchase"}, function () {
     console.log("win 2");
},
function () {
     console.log("fail 2");
});

What will Happen:

Console:
win 2
fail 2

That is not good! The reason for this is the Actionscript code stores the callback IDs in instance variables and trumps them each call.

See: https://github.com/blackberry/WebWorks-TabletOS/blob/master/js_api/blackberry.payment/src/Air/Payment/src/blackberry/payment/Payment.as#L33-34

Which is trumped each call here: https://github.com/blackberry/WebWorks-TabletOS/blob/master/js_api/blackberry.payment/src/Air/Payment/src/blackberry/payment/Payment.as#L83-84

This problem can be observed in the following APIs:

Dialog

https://github.com/blackberry/WebWorks-TabletOS/blob/master/js_api/blackberry.ui.dialog/src/Air/UserInterface/src/blackberry/ui/dialog/Dialog.as#L53

Camera

https://github.com/blackberry/WebWorks-TabletOS/blob/master/js_api/blackberry.media.camera/src/Air/Camera/src/blackberry/media/camera/Camera.as#L37-39

Microphone

https://github.com/blackberry/WebWorks-TabletOS/blob/master/js_api/blackberry.media.microphone/src/Air/Microphone/src/blackberry/media/microphone/MicrophoneExtension.as#L39-40

Payment

https://github.com/blackberry/WebWorks-TabletOS/blob/master/js_api/blackberry.payment/src/Air/Payment/src/blackberry/payment/Payment.as#L33-34


As a general rule I would expect all of the actionscript code to be stateless and not store anything in instance variables as we need to think of the actionscript as a stateless webserver.

gtanner commented 13 years ago

We ran into this issue while developing the barcode extension and fixed it by closuring the callback IDs see: https://github.com/tneil/MessingAround/commit/ce2c4054580fd43db4c9ab71903e701042d50c6c

cdelcol commented 13 years ago

Fixed with Pull request #34.

Closed.