Skip to content

Instantly share code, notes, and snippets.

@gregglind
Created January 17, 2017 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregglind/c98939d205809ebeeb04bc3931064ae6 to your computer and use it in GitHub Desktop.
Save gregglind/c98939d205809ebeeb04bc3931064ae6 to your computer and use it in GitHub Desktop.
jetpack (addon-sdk frames) don't share constructors, busting instanceOf
20:20 < gregglind> Sorry to ask Jetpack questions :(
20:20 < gregglind> is `instanceof Object` ... reliable or funky across modules in jetpacks?
20:21 < gregglind> i have observed that Error is funky as well.
20:21 < gregglind> I am not even sure how to phrase it.
20:25 < The_8472> each module has its own global, including separate instances of the primordial types such as Object, Error, etc.
20:26 < The_8472> (foo !== null && typeof foo === "object") to check for objectness
20:27 < The_8472> or you can export the constructor function from that module
20:28 < The_8472> then foo instanceof MyClass should work. i think.
20:29 < gregglind> The_8472: different frames :)
20:29 < The_8472> yes, same thing
20:29 < gregglind> Thanks for confirming this is at least real.
20:30 < gregglind> 20:27 < The_8472> or you can export the constructor function from that module <- eplain this a bit more :)
20:30 < gregglind> so, module M has the isinstance check
20:31 < gregglind> then in module Q i need to make sure to create things using M's constructors?
20:32 < gregglind> also, this is going to be a big problem because the actual nasty code is imported `jsonschema` which is littered with this :)
20:32 < The_8472> no, Q can export the constructor (if it makes sense to have it public) then M can do instanceOfFooInM instanceof q.FooConstructor
20:32 < gregglind> noted, thanks.
20:32 < gregglind> this is going to be tough one :)
20:33 < The_8472> there also is a hacky way with chrome privileges
20:33 < The_8472> let otherGlobal = Components.utils.getGlobalForObject(foo); foo instanceof otherGlobal.Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment