Closed Bug 934311 Opened 11 years ago Closed 11 years ago

Javascript modules don't share definition of Array (and probably all other standard classes like String etc.)

Categories

(Core :: General, defect)

27 Branch
x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: peter.kehl, Unassigned)

Details

(Keywords: dev-doc-needed)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0 (Beta/Release) Build ID: 20131029134505 Steps to reproduce: Have two simple Firefox extensions XPI, each defining one Javascript module (loadable via chrome://). One module exports a function, which creatse new array (via 'new Array' or via [..]). The other module exports a function, that takes a parameter and it checks whether (param instanceof Array). Actual results: An array created and returned from one JS module is not recognized as an array in another module. If param was created as an array in a different JS module, (param instanceof Array) returns false. Expected results: Array instances should have same class (constructor) no matter what module. If the current behaviour is a correct one (because of scopes or memory leaks), please - explain why - update https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Using so it clearly states that
> param instanceof Array You should be using Array.isArray. Each module has its own global, of course; and per ES spec each global has a different Array instance. Maybe all we need to do is document that each module has its own global? I would have thought that's obvious from the way they work...
Flags: needinfo?(bobbyholley+bmo)
(In reply to Boris Zbarsky [:bz] from comment #1) > Maybe all we need to do is document that each module has its own global? I > would have thought that's obvious from the way they work... Yes.
Flags: needinfo?(bobbyholley+bmo)
Keywords: dev-doc-needed
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
In addition to mentioning/documenting that each module has its own global, please also make https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Using refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects so that the users know what is in 'global'.
(In reply to Peter Kehl from comment #3) > In addition to mentioning/documenting that each module has its own global, > please also make > https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/ > Using refer to > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/ > Global_Objects so that the users know what is in 'global'. MDN is a wiki, which you can freely edit. If you have any thoughts about how to make documentation better, you can just do it! :-)
You need to log in before you can comment on or make changes to this bug.