Closed Bug 823790 Opened 12 years ago Closed 10 years ago

Remove instanceof dependencies in SDK code

Categories

(Core :: General, defect)

x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: brettz9, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0
Build ID: 20121128204232

Steps to reproduce:

In testing my AsYouWish addon (https://github.com/brettz9/asyouwish/), which adapts specialPowers.js code (http://mxr.mozilla.org/mozilla-central/source/testing/specialpowers/content/specialpowersAPI.js ) to wrap required objects for use by websites, I noticed that the ok() method of the Panel object had problems with user-created wrapped Panel's being added to a (user-created wrapped) widget.


Actual results:

This error was due to the SDK's use of the "instanceof" operator which, as I understand it, checks the object against the original "class" rather than a wrapped object, so these checks will fail against wrapped objects when they are supposed to pass.

I found this specific issue (though similar issues may exist elsewhere) in line 72 of /resources/addon-sdk/lib/sdk/widget.js (as at https://github.com/mozilla/addon-sdk/blob/master/lib/sdk/widget.js#L72 ).


Expected results:

As a workaround, instead of "v instanceof panels.Panel", I duck-typed for "v.show" and it worked fine. I'm not sure whether there may be another way around it, but I would think such code could be replaced by similar duck-typing.
Err, in bug 546848 comment 146, I was requesting that we move the discussion of AsYouWish out into its own tracking bug, rather than doing it in the enablePrivilege bug.

It's true that instanceof won't work for SpecialPowers wrappers, but this is why they're not anything we ship in production. I designed them solely for the purpose of simplifying our test suite, where their limitations can be worked around. I don't think the addon SDK is going to stop using instanceof. :-(
Ok, I have added a tracking bug in Bug 823811.

I will also see whether I can modify specialPowers to get wrapped objects to be treated as the original for instanceof checks, e.g., assigning a new instance of the original wrapped constructor on the wrapped function's prototype if that might work.
Please note that the original issue reported here, while it may not work with certain modules (and I still hold out hope that AsYouWish can be accommodated), it is working with "ui", the replacement for widget. All of my AsYouWish demos are working again, so looking good....
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.