Closed Bug 943233 Opened 11 years ago Closed 11 years ago

SpecialPowers-wrapped objects exported from jsm are not correctly wrapped/unwrapped when passed to Promise.resolve

Categories

(Remote Protocol :: Marionette, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: vicamo, Unassigned)

Details

Attachments

(1 file)

Say I get an object exported from a js module: let obj = SpecialPowers.Cu.import("resource://gre/modules/foo.jsm").exportedObj; and it has some attributes and methods: is(typeof obj, "object", "imported object"); // success is(typeof obj.attr1, "string", "obj.attr1"); // success is(typeof obj.method1, "function", "obj.method1"); // success but when I pass it to |Promise.resolve()| as an parameter for next handler, I got empty object "{}" instead. Promise.resolve(obj) .then(function aPassedObj) { // |obj| is still valid and so are all its attributes and methods. // But |aPassedObj| is an empty object here. }); This behaviour is only found in Marionette JS test script so far. General chrome js component works fine.
Attached patch test caseSplinter Review
This is a quick test case by reusing |Promise.jsm|. If we trace into |Promise.jsm|, it will be near line 755, Handler::process [1]. The line: 767 nextValue = this.onResolve(nextValue); We have initially |nextValue| equal to the obj exported from the jsm, but inside that |this.onResolve()| function, we get an empty object instead. [1]: https://mxr.mozilla.org/mozilla-central/source/toolkit/modules/Promise.jsm#755
(In reply to Vicamo Yang [:vicamo][:vyang] from comment #0) > let obj = > SpecialPowers.Cu.import("resource://gre/modules/foo.jsm").exportedObj; SpecialPowers wrappers are very hacky things, and you should definitely not be using them for things like Cu.import. For stuff like this, you should be using SpecialPowers.loadChromeScript.
Summary: objects exported from jsm are not correctly wrapped/unwrapped when passed to Promise.resolve → SpecialPowers-wrapped objects exported from jsm are not correctly wrapped/unwrapped when passed to Promise.resolve
(In reply to Bobby Holley (:bholley) from comment #2) > SpecialPowers wrappers are very hacky things, and you should definitely not > be using them for things like Cu.import. There are other usages of |SpecialPowers.Cu.import|. Look like a common way to test chrome functions? > For stuff like this, you should be using SpecialPowers.loadChromeScript. It seems |SpecialPowers.loadChromeScript| is for communicating with a chrome script, not simply importing it as a module. Am I supposed to write some |addListener|, |removeListener| for this?
(In reply to Vicamo Yang [:vicamo][:vyang] from comment #3) > (In reply to Bobby Holley (:bholley) from comment #2) > > SpecialPowers wrappers are very hacky things, and you should definitely not > > be using them for things like Cu.import. > > There are other usages of |SpecialPowers.Cu.import|. Look like a common way > to test chrome functions? It might do what you want. Sometimes. But my point is that they're hacky enough that any bugs related to them should be solved by simply not using them. They're a quick-and-dirty approach that doesn't always work. > > For stuff like this, you should be using SpecialPowers.loadChromeScript. > > It seems |SpecialPowers.loadChromeScript| is for communicating with a chrome > script, not simply importing it as a module. Am I supposed to write some > |addListener|, |removeListener| for this? The idea is that you do the privileged work in a separate script, and communicate with that via message passing.
Hi, it seems I abused Promise and/or Marionette. The thing I really want to do is to run some test cases for MobileMessageDB.jsm. [1] That jsm is always running in chrome process, and that's what I really should do. [1]: http://mxr.mozilla.org/mozilla-central/source/dom/mobilemessage/src/gonk/MobileMessageDB.jsm
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
Product: Testing → Remote Protocol
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: