Titanium JIRA Archive
Appcelerator Community (AC)

[AC-3033] Android: CommonJS brakes when trying to use global scope reference inside exported function

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2011-12-21T19:56:26.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterIvan Skugor
AssigneeShak Hossain
Created2011-11-16T04:19:57.000+0000
Updated2016-03-08T07:48:04.000+0000

Description

Hi. See this simple code:
//app.js
var testModule = require('test');
 
testModule.doTest();
 
 
//test.js
var moduleScope = this;
 
exports.doTest = function() {
    Ti.API.debug(moduleScope);
};
It brakes the app and, IMHO, it shouldn't brake in a way it brakes now ("StackOverflowError"), in worst case "moduleScope" should throw "ReferenceError" ("moduleScope" is not defined). I'm not sure how CommonJS and module scope behaves, but this also could be legal code and it shouldn't brake at all.

Comments

  1. Ivan Skugor 2011-11-16

    Ah yes, I forgot about Q/A link: http://developer.appcelerator.com/question/128188/commonjs-brakes-when-trying-to-use-global-scope-reference-inside-function
  2. Paul Dowsett 2011-12-21

    Ivan, the test case is now not showing the error as of Titanium 1.8.0.1 (2011/12/17 19:53 c903964) + Android APIs 2.2. This could have been fixed in the meantime. See logcat output below.
        463          AndroidRuntime  D  >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
         463          AndroidRuntime  D  CheckJNI is ON
         463          AndroidRuntime  D  --- registering native functions ---
          60         ActivityManager  I  Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.testing.testing9/.
                                         Testing9Activity }
         463          AndroidRuntime  D  Shutting down VM
         463                    jdwp  D  Got wake-up signal, bailing out of select
          60         ActivityManager  I  Start proc com.testing.testing9 for activity com.testing.testing9/.Testing9Activity: pid=470 uid=10040 gids={1015, 3003}
         470           TiApplication  I  (main) [0,0] checkpoint, app created.
         470           TiApplication  I  (main) [797,797] Titanium 1.8.0.1 (2011/12/17 19:53 c903964)
         470               TiFastDev  D  (main) [613,1410] Enabling Fastdev on port 45406
         470               TiFastDev  D  (main) [156,1566] sent tokens successfully
         470               TiFastDev  D  (main) [1,1567] Fastdev session handshake succesful.
         470           TiApplication  I  (main) [23,1590] Titanium Javascript runtime: v8
         470           TiApplication  W  (main) [266,1856] activity stack is emtpy, unable to get current activity
         470          TiRootActivity  I  (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
         470           TiApplication  W  (main) [528,528] activity stack is emtpy, unable to get current activity
         470           TiApplication  W  (main) [0,528] activity stack is emtpy, unable to get current activity
         470           TiApplication  W  (main) [3,531] activity stack is emtpy, unable to get current activity
         470           TiApplication  E  (KrollRuntimeThread) [2684,3215] APP PROXY: ti.modules.titanium.app.AppModule@44f738c0
         470           TiAssetHelper  D  Fetching "app.js" with Fastdev...
         470                  Module  D  Loading module: test1 -> Resources/test1.js
         470           TiAssetHelper  D  Fetching "test1.js" with Fastdev...
         470          TiRootActivity  I  (main) [0,0] checkpoint, on root activity resume. activity = com.testing.testing9.Testing9Activity@44f49b18
          60         ActivityManager  W  Launch timeout has expired, giving up wake lock!
          60         ActivityManager  I  Displayed activity com.testing.testing9/.Testing9Activity: 10600 ms (total 10600 ms)
         470          TiAnalyticsSvc  W  (Thread-12) [25660,25660] Analytics Service Started
         470          TiAnalyticsSvc  I  (Thread-12) [135,25795] Sending 1 analytics events.
         470          TiAnalyticsSvc  W  (Thread-12) [1686,27481] Stopping Analytics Service
       
    I'll close this for now, but reopen it if you still see the problem.
  3. Ivan Skugor 2011-12-22

    I can confirm that it has been fixed. Thanks.

JSON Source