Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6848] Android: lost global namespace

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-01-13T15:51:52.000+0000
Affected Version/sRelease 1.7.5, Release 1.8.0.1, Release 2.0.0
Fix Version/sn/a
ComponentsAndroid
Labelsregression
ReporterKarol Pomaski
AssigneePing Wang
Created2011-12-22T12:03:10.000+0000
Updated2012-09-04T15:18:06.000+0000

Description

Problem

Global namespace getting lost while separated in a bunch of files stored in different folders. In simulator the result differs from the one from device.

Reproducible Steps

1. Run the example project (attached inside JIRA) 2. Press "Click button"

Reproducible Code

File Structure
Resources
   ¡-sub1
     ¡-test.js
   ¡-sub2
     ¡-testTwo.js
   ¡-app.js
test.js
(function(){
    namespace.test = function(){
        var winTest = Titanium.UI.createWindow({
            title: 'Test',
            backgroundColor: '#fff',
        exitOnClose: true,
            fullscreen: false // making this a heavy weight window
        });
 
        var btnButton = Ti.UI.createButton({
            title: 'Click button',
            width: 150,
            height: 100,
            top: 100
        });
 
        btnButton.addEventListener('click', function(){
            Ti.include('sub2/testTwo.js');
            var winToOpen = namespace.testTwo();
            winToOpen.open();
        });
        winTest.add(btnButton);
 
        namespace.printout();
 
        return winTest;
    };
})();


testTwo.js
(function(){
    namespace.testTwo = function(){
        var winTestTwo = Titanium.UI.createWindow({
            title: 'Test2',
            backgroundColor: '#fff'
        });
 
        var btnBack = Ti.UI.createButton({
            title: 'back',
            height: 100,
            width: 100,
            top: 50
        });
 
        btnBack.addEventListener('click', function(){
            winTestTwo.close();
        });
 
        winTestTwo.add(btnBack);
        return winTestTwo;
    };
})();
app.js
//app.js 
var namespace = {};
Ti.include('sub1/test.js');

namespace.printout = function(){
    Ti.API.info('namespace.printout');
};
 

var win = namespace.test();

win.open();


Logs while testing on Simulator (Android 2.2 & 2.3.3) with SDK 1.7.5

12-22 13:33:03.388: D/KrollContext(307): (kroll$2: file:///android_asset/Resources/app.js) [17896,19589] Running evaluated script: file:///android_asset/Resources/sub2/testTwo.js
12-22 13:33:03.606: E/KrollContext(307): (kroll$2: file:///android_asset/Resources/app.js) [173,19762] ECMA Error evaluating source: ReferenceError: "namespace" is not defined. (file:///android_asset/Resources/sub2/testTwo.js#2)
12-22 13:33:03.606: E/KrollContext(307): org.mozilla.javascript.EcmaError: ReferenceError: "namespace" is not defined. (file:///android_asset/Resources/sub2/testTwo.js#2)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3784)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3762)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3847)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1846)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1785)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1780)
12-22 13:33:03.606: E/KrollContext(307): 	at script(file:///android_asset/Resources/sub2/testTwo.js:2)
12-22 13:33:03.606: E/KrollContext(307): 	at script(file:///android_asset/Resources/sub2/testTwo.js:1)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:178)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.Context.evaluateReader(Context.java:1142)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.titanium.kroll.KrollContext$DefaultEvaluator.evaluateFile(KrollContext.java:106)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.titanium.kroll.KrollContext.evaluateScript(KrollContext.java:353)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:382)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.titanium.kroll.KrollContext.evalFile(KrollContext.java:278)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.titanium.kroll.KrollBridge.evalFile(KrollBridge.java:130)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.titanium.TiContext.evalFile(TiContext.java:189)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.titanium.TiContext.evalFile(TiContext.java:209)
12-22 13:33:03.606: E/KrollContext(307): 	at ti.modules.titanium.TitaniumModule.include(TitaniumModule.java:122)
12-22 13:33:03.606: E/KrollContext(307): 	at ti.modules.titanium.TitaniumModuleBindingGen$14.invoke(TitaniumModuleBindingGen.java:571)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:51)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1701)
12-22 13:33:03.606: E/KrollContext(307): 	at script(file:///android_asset/Resources/sub1/test.js:18)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3177)
12-22 13:33:03.606: E/KrollContext(307): 	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.titanium.kroll.KrollCallback.callSync(KrollCallback.java:139)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.titanium.kroll.KrollCallback$1.run(KrollCallback.java:164)
12-22 13:33:03.606: E/KrollContext(307): 	at android.os.Handler.handleCallback(Handler.java:587)
12-22 13:33:03.606: E/KrollContext(307): 	at android.os.Handler.dispatchMessage(Handler.java:92)
12-22 13:33:03.606: E/KrollContext(307): 	at android.os.Looper.loop(Looper.java:123)
12-22 13:33:03.606: E/KrollContext(307): 	at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:86)
12-22 13:33:03.606: E/TiJSError(307): (kroll$2: file:///android_asset/Resources/app.js) [45,19807] ----- Titanium Javascript Runtime Error -----
12-22 13:33:03.606: E/TiJSError(307): (kroll$2: file:///android_asset/Resources/app.js) [5,19812] - In file:///android_asset/Resources/sub2/testTwo.js:2,0
12-22 13:33:03.606: E/TiJSError(307): (kroll$2: file:///android_asset/Resources/app.js) [2,19814] - Message: ReferenceError: "namespace" is not defined. (file:///android_asset/Resources/sub2/testTwo.js#2)
12-22 13:33:03.617: E/TiJSError(307): (kroll$2: file:///android_asset/Resources/app.js) [4,19818] - Source: null
12-22 13:33:03.717: E/KrollCallback(307): (kroll$2: file:///android_asset/Resources/app.js) [91,19909] ECMA Error evaluating source, invocation: [callMethod UI.Button.UI.Button:event:click null], message: TypeError: Cannot find function testTwo in object [object Object]. (file:///android_asset/Resources/sub1/test.js#19)
12-22 13:33:03.717: E/KrollCallback(307): org.mozilla.javascript.EcmaError: TypeError: Cannot find function testTwo in object [object Object]. (file:///android_asset/Resources/sub1/test.js#19)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3784)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3762)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3790)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3809)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3880)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2359)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2326)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1514)
12-22 13:33:03.717: E/KrollCallback(307): 	at script(file:///android_asset/Resources/sub1/test.js:19)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3177)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.appcelerator.titanium.kroll.KrollCallback.callSync(KrollCallback.java:139)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.appcelerator.titanium.kroll.KrollCallback$1.run(KrollCallback.java:164)
12-22 13:33:03.717: E/KrollCallback(307): 	at android.os.Handler.handleCallback(Handler.java:587)
12-22 13:33:03.717: E/KrollCallback(307): 	at android.os.Handler.dispatchMessage(Handler.java:92)
12-22 13:33:03.717: E/KrollCallback(307): 	at android.os.Looper.loop(Looper.java:123)
12-22 13:33:03.717: E/KrollCallback(307): 	at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:86)
12-22 13:33:03.717: E/TiJSError(307): (kroll$2: file:///android_asset/Resources/app.js) [7,19916] ----- Titanium Javascript Runtime Error -----
12-22 13:33:03.717: E/TiJSError(307): (kroll$2: file:///android_asset/Resources/app.js) [5,19921] - In file:///android_asset/Resources/sub1/test.js:19,0
12-22 13:33:03.717: E/TiJSError(307): (kroll$2: file:///android_asset/Resources/app.js) [2,19923] - Message: TypeError: Cannot find function testTwo in object [object Object]. (file:///android_asset/Resources/sub1/test.js#19)
12-22 13:33:03.727: E/TiJSError(307): (kroll$2: file:///android_asset/Resources/app.js) [4,19927] - Source: null
12-22 13:33:03.937: I/ARMAssembler(61): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x2f4548:0x2f4604] in 5194000 ns

Logs while testing on Simulator with Android 2.3.3 - SDK 1.8.0.1.RC3 (V8 & Rhino) & SDK 1.9.0.v20111219173133 (V8 & Rhino)

12-22 13:47:37.056: D/TiAssetHelper(362): Fetching "sub1/sub2/testTwo.js" with Fastdev...
12-22 13:47:37.205: E/TiJSError(362): (main) [406964,436222] ----- Titanium Javascript Runtime Error -----
12-22 13:47:37.205: E/TiJSError(362): (main) [0,436222] - In sub1/sub2/testTwo.js:1,17
12-22 13:47:37.205: E/TiJSError(362): (main) [0,436222] - Message: Uncaught ReferenceError: NOT_FOUND is not defined
12-22 13:47:37.205: E/TiJSError(362): (main) [1,436223] - Source: with(sandbox) { NOT_FOUND
12-22 13:47:37.676: E/V8Exception(362): Exception occurred at sub1/sub2/testTwo.js:1: Uncaught ReferenceError: NOT_FOUND is not defined

Logs while testing on device: Samsung Galaxy Fit with Android 2.2.1 with SDK 1.8.0.1.RC3 (V8)

12-22 14:10:57.879: V/AudioFlinger(94): MixerThread 0xbb38 TID 151 waking up
12-22 14:10:57.879: V/AudioPolicyManager(94): releaseOutput() 1
12-22 14:10:57.879: V/AudioFlinger(94): remove track (4101) and delete from mixer
12-22 14:10:57.879: V/AudioFlinger(94): PlaybackThread::Track destructor
12-22 14:10:57.899: E/TiAssetHelper(27831): Error while reading asset "Resources/sub1/sub2/testTwo.js":
12-22 14:10:57.899: E/TiAssetHelper(27831): java.io.FileNotFoundException: Resources/sub1/sub2/testTwo.js
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at android.content.res.AssetManager.openAsset(Native Method)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at android.content.res.AssetManager.open(AssetManager.java:313)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at android.content.res.AssetManager.open(AssetManager.java:287)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at org.appcelerator.kroll.util.KrollAssetHelper.readAsset(KrollAssetHelper.java:55)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:47)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:441)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:602)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:340)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at android.os.Handler.dispatchMessage(Handler.java:95)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at android.os.Looper.loop(Looper.java:123)
12-22 14:10:57.899: E/TiAssetHelper(27831): 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:102)
12-22 14:10:57.909: V/AudioHardwareMSM72XX(94): open driver
12-22 14:10:57.909: V/AudioHardwareMSM72XX(94): get config
12-22 14:10:57.909: V/AudioHardwareMSM72XX(94): set config
12-22 14:10:57.909: V/AudioHardwareMSM72XX(94): buffer_size: 4800
12-22 14:10:57.909: V/AudioHardwareMSM72XX(94): buffer_count: 2
12-22 14:10:57.909: V/AudioHardwareMSM72XX(94): channel_count: 2
12-22 14:10:57.909: V/AudioHardwareMSM72XX(94): sample_rate: 44100
12-22 14:10:57.979: E/TiJSError(27831): (main) [23362,23362] ----- Titanium Javascript Runtime Error -----
12-22 14:10:57.979: E/TiJSError(27831): (main) [0,23362] - In sub1/test.js:19,39
12-22 14:10:57.979: E/TiJSError(27831): (main) [0,23362] - Message: Uncaught TypeError: Object #<Object> has no method 'testTwo'
12-22 14:10:57.979: E/TiJSError(27831): (main) [0,23362] - Source:             var winToOpen = namespace.testTwo();
12-22 14:10:58.009: I/PowerManagerService(175): Light Animator Finished curIntValue=140
12-22 14:10:58.019: E/V8Exception(27831): Exception occurred at sub1/test.js:19: Uncaught TypeError: Object #<Object> has no method 'testTwo'
12-22 14:10:58.079: W/AudioFlinger(94): write blocked for 167 msecs, 245 delayed writes, thread 0xbb38
12-22 14:10:58.339: V/AudioFlinger(94): getNextBuffer() no more data for track 4100 on thread 0xbb38

Attachments

FileDateSize
device.png2011-12-22T12:16:59.000+000079157
namespace_sample.zip2011-12-22T12:03:10.000+00002345938

Comments

  1. Florian Schnell 2012-01-08

    I am having exactly the same issue. Our app worked fine until the last release of Titanium Studio and SDK 1.8.0.1. Titanium Studio version: 1.0.7.201112281340
  2. Ping Wang 2012-01-10

    In android, we can use either relative or absolute path for files. Therefore, in test.js, it should be
       Ti.include('../sub2/testTwo.js'); //use relative path
       
    or
       Ti.include('/sub2/testTwo.js');  //use absolute path
       
    Then the code will work fine.
  3. Maria Mercedes wyss Alvarez 2012-08-31

    This bug not is closed, no way to persist data for android, Ti.include() allow use the vars define in the js but not persist, when you exit of the file use this js. In iPhone only need define the global var in the app.js and you can access this in all application. Why this function not working in android.
  4. Ping Wang 2012-09-04

    Maria Mercedes wyss Alvarez, can you provide a test case to show the issue you described? Thanks.

JSON Source