diff --git a/index.js.in b/index.js.in index efebcf44..9dc7f6d1 100644 --- a/index.js.in +++ b/index.js.in @@ -10,7 +10,8 @@ var loadingPromises = []; if (config.midletClassName == "RunTests") { loadingPromises.push(loadScript("tests/contacts.js"), - loadScript("tests/index.js")); + loadScript("tests/index.js"), + loadScript("tests/mozactivitymock.js")); } if (navigator.userAgent.indexOf('Chrome') > -1) { @@ -746,5 +747,9 @@ DumbPipe.registerOpener("backgroundCheck", function(message, sender) { }); DumbPipe.registerOpener("mozActivity", function(message, sender) { - new MozActivity(message); + var activity = new MozActivity(message); + + activity.onsuccess = sender.bind(null, { type: "onsuccess" }); + + activity.onerror = sender.bind(null, { type: "onerror" }); }); diff --git a/midp/sms.js b/midp/sms.js index eda809ab..60f001d0 100644 --- a/midp/sms.js +++ b/midp/sms.js @@ -186,22 +186,25 @@ Native["com/sun/midp/io/j2me/sms/Protocol.send0.(IILjava/lang/String;II[B)I"] = function(handle, type, host, destPort, sourcePort, message) { var ctx = $.ctx; asyncImpl("I", new Promise(function(resolve, reject) { - var activity = new MozActivity({ + var pipe = DumbPipe.open("mozActivity", { name: "new", data: { - type: "websms/sms", - number: J2ME.fromJavaString(host), - body: new TextDecoder('utf-16be').decode(message), + type: "websms/sms", + number: J2ME.fromJavaString(host), + body: new TextDecoder('utf-16be').decode(message), }, + }, function(message) { + switch (message.type) { + case "onsuccess": + DumbPipe.close(pipe); + resolve(message.byteLength); + break; + + case "onerror": + ctx.setAsCurrentContext(); + reject($.newIOException("Error while sending SMS message")); + break; + } }); - - activity.onsuccess = function() { - resolve(message.byteLength); - }; - - activity.onerror = function() { - ctx.setAsCurrentContext(); - reject($.newIOException("Error while sending SMS message")); - }; })); };