[TIMOB-6573] iOS: Some modules designed for CommonJS not exporting, even with the "export" variable set
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-12-13T14:05:49.000+0000 |
Affected Version/s | Release 1.8.0.1 |
Fix Version/s | Sprint 2011-50, Release 1.8.0.1, Release 2.0.0 |
Components | iOS |
Labels | parity |
Reporter | Stephen Tramer |
Assignee | Blain Hamon |
Created | 2011-12-12T10:53:40.000+0000 |
Updated | 2012-03-04T22:08:00.000+0000 |
Description
From the Titans mailing list:
Using the CommonJS module "underscore" (available at http://documentcloud.github.com/underscore/) does not properly export when using
require()
. The relevant snippet from the code seems to be:
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = _;
}
exports._ = _;
} else if (typeof define === 'function' && define.amd) {
// Register as a named module with AMD.
define('underscore', function() {
return _;
});
} else {
// Exported as a string, for Closure Compiler "advanced" mode.
root['_'] = _;
}
And the developer is trying the following:
var _ = require('underscore')._;
This is leading to the following error:
[ERROR] Script Error = -[KrollCallback countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x8c27fb0.
This issue may be related to TIMOB-6458, TIMOB-6457, and our other require processing mechanisms. While performing work on require() these other issues should be examined (but maybe not resolved yet).
Note to self: This is because, for some reason, evaluating the module is returning a KrollCallback, not an NSDictionary.
Android is compliant with 1.1 CommonJS spec, which might give some clues as to the nature of this bug: http://wiki.commonjs.org/wiki/Modules/1.1
Adding test code, just to test not only the module is generated, but it's usable as well. Note that this sample test defines _ to be the module/function itself, so we can inspect the read-only URI and id properties.
Turns out these are unrelated to linked issues, but the link is still useful.
Tested with 1.8.0.1.v20111214093905 on Simulator 5.0 iPhone 4 (5.0.1) iPod 3g (4.0.2) iPad 1 (4.3.5) Returns: