Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25455] Syntax eval is not working inside the CommonJS module.

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionDuplicate
Resolution Date2017-11-07T08:58:50.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
Reporterlau.yikonn
AssigneeHans Knöchel
Created2017-09-07T04:01:26.000+0000
Updated2018-08-06T17:41:10.000+0000

Description

JavaScript eval() function is not working inside the CommonJS module and the iOS device. It can not detect the variable value when we write down inside the CommonJS module. But it works if we write eval() function to the app.js file. Steps to Reproduce: 1. Create a new App 2. Disable LiveView 3. Run the following test code on the iOS device Note: It works if liveveiw is enabled. Also, working in a simulator.
var win = Ti.UI.createWindow({
	backgroundColor : 'red',
	layout : "vertical"
});

// Create a Button.
var request = Ti.UI.createButton({
	title : 'Got it',
	height : Ti.UI.SIZE,
	width : Ti.UI.SIZE,
	top : 50
});


request.addEventListener('click', function(e) {

	var EvalTestClass = require('lib/evalTest');

	var evalTest = new EvalTestClass();

	evalTest.open();
});

win.add(request);

win.open();



function view() {

	var win = Ti.UI.createWindow({
		title : "Test",
		backgroundColor : '#fff'
	});

	var X = 10;
	var Y = 20;

	function iWantToKillMyslef() {
		alert("This works in the Simulator and in Live View");
	}

	var a = eval("X*Y");

	var label = Ti.UI.createLabel({
		text : a,
		color : "#333",
		font : {
			fontSize : 20
		}
	});
	win.add(label);

	try {
		eval("iWantToKillMyslef()");
	} catch (e) {
		alert(e);
	}

	return win;
};

module.exports = view;


Error Code
[ERROR] :  Script Error {
[ERROR] :      column = 2;
[ERROR] :      line = 1;
[ERROR] :      message = "Can't find variable: X";
[ERROR] :      stack = "eval code\neval@[native code]\nview@file:///var/containers/Bundle/Application/A4AEE4ED-3CBA-4F93-9E91-A3E4ACE80496/EvalTest.app/lib/evalTest.js:1:287\nfile:///var/containers/Bundle/Application/A4AEE4ED-3CBA-4F93-9E91-A3E4ACE80496/EvalTest.app/app.js:1:276";
[ERROR] :  }

Thanks

Comments

  1. Aminul Islam 2017-09-12

    Hi, We have tested this issue with 6.1.2.GA. So far we have been unable to reproduce this issue. Test Code
         var win = Ti.UI.createWindow({
               title: "Test",
               backgroundColor: '#fff'
           });
           
           var x = 10;
           var y = 20;
           var a = eval("x * y");
       
           var label = Ti.UI.createLabel({
               text: a,
               color: "#333",
               font: {
                   fontSize: 20
               }
           });   
           win.add(label);
       win.open();
       
    Environment:
       Operating System
         Name                        = Mac OS X
         Version                     = 10.11.6
         Architecture                = 64bit
         # CPUs                      = 4
         Memory                      = 8589934592
       Node.js
         Node.js Version             = 4.4.4
         npm Version                 = 2.15.1
       Titanium CLI
         CLI Version                 = 5.0.14
       Titanium SDK
         SDK Version                 = 6.1.2.GA
       
    Thanks
  2. Ivan Markovic 2017-10-22

    This is very much an issue with iOS too. Mac OS 10.13 Ti SDK 6.2.x (they all fail) iOS SDK 11.x (they all fail) It ONLY fails if you install the App via Ad Hoc Dist or direct to device with LiveView turned OFF. If LiveView is ON or it is running in the simulator it works! In app.js; you need the following: var EvalTestClass = require('/lib/EvalTest'); var evalTest = new EvalTestClass(); and I have attached EvalTest.js if you have the eval in the app.js file it works! This is a major issue as I can't perform a valid Ad Hoc Dist with 6.2.x
  3. lau.yikonn 2017-10-23

    @Ivan markovic, and i find out that, if you use the eval like below it works! var b = 10; var x = "b"; cosole.log(eval(x)); //result = 10 but you cant pass string to eval. eval("x"); // fail
  4. Aminul Islam 2017-10-23

    Hi [~imarkovi] [~lau.yikonn], Could you please share a demo project? We can offer you to look into your code and help to identify errors. Best, Axway Appcelerator Support
  5. Ivan Markovic 2017-10-23

    I already posted a file and the core code. That is all you'll need. Turn off live view and install that to device and it'll fail.
  6. Ivan Markovic 2017-10-24

    Aminul, I am now back in my office. Let me know how you get on. This is an absolute showstopper. I can't get around this bug, and I can't release anything to a device, either Ad Hoc or for Development. Thanks
  7. Aminul Islam 2017-10-24

    Hi [~imarkovi], we have tested this issue with latest SDK 6.2.2.GA on devices (direct to the device with LiveView turned OFF) we also create an EvalTest.js and require that file in app.js. So far we have been unable to reproduce any error. Could you please share app.js and EvalTest.js as gist or dropbox link? We don't get any file. Thanks
  8. Ivan Markovic 2017-10-24

    Okay I have attached the whole project as well as my build log so you can check all my settings. And the relief (for me) is that I created a NEW project and did as LITTLE as possible to the settings and it still failed. Same as before. Maybe there is something I can update but from what I have seen everything is updated to the latest and greatest versions and this fails on all flavours of 6.2.x
  9. Ivan Markovic 2017-10-24

    I am not sure if you can see the attachment that I added to the comment above so I am including it here too: https://www.dropbox.com/s/lmkanwc2uwrbixd/EvalTest.zip?dl=0
  10. Sharif AbuDarda 2017-10-24

    Hello, I have tried your sample code on the Android device. I don't see any crash or error in the console. I see a blank alert with {}. I am testing SDK 6.2.2.GA and in Android 7.1.2 device (Nokia 6). [See screenshot](https://ibb.co/kL2zT6). Thanks.
  11. Ivan Markovic 2017-10-24

    Please reference the first line of my initial report/comment: "This is very much an issue with iOS too" I don't use Android. This is an issue on iOS. on my iPhone and iPad
  12. Motiur Rahman 2017-10-26

    Hello [~imarkovi], I could not reproduce this issue with the following environment Appcelerator Command-Line Interface, version 6.2.4 Ti SDK: 6.1.1.GA, 6.1.2.GA iPhone 5s v11.0.3 Node: 6.11.4 I tested the [~aislam] test code. Did you try with that? Also, review your other code in your App. Thanks
  13. Ivan Markovic 2017-10-26

    Motiur, The issue does not arise with 6.1.x, as I mentioned it's all flavours of 6.2.x Please test with 6.2.x and also ensure you have live view turned off; it WORKS with live view turned on! VERY strange. You have the entirety of the App in the dropbox link above, and that App JUST contains those 2 files and nothing more; I didn't adjust the settings or add any modules, as simple and as generic as can be The eval function fails with every single string input I have used. Doesn't matter what the string contains, whether it's a 'dictionary' or a function call, it fails.
  14. Ivan Markovic 2017-10-26

    So yes, Aminul Islam's code very much fails as does any string containing anything Please note that this DOES appear to work if the eval is contained within the app.js file, outside any object structure... so maybe that is part of the issue here.
  15. daisyfoto 2017-10-27

    I have same problem Ti SDK: 6.2.2.GA eval it work on simulator but not work on real device
  16. Motiur Rahman 2017-10-27

    Hello! Still, I could not reproduce this issue with the real device and yes liveview was disabled. Try to clean build your App and change the Ti SDK version. Appcelerator Command-Line Interface, version 6.2.4 Ti SDK: 6.2.2.GA, iPhone 5s v11.0.3 Node: 6.11.4 I tested the following test code - https://www.dropbox.com/s/lmkanwc2uwrbixd/EvalTest.zip?dl=0 Here is the screenshot http://oi65.tinypic.com/2ecni8z.jpg Thanks
  17. Ivan Markovic 2017-10-27

    Motiur, I have cleaned my project more times than you've had hot dinners... I created a brand new project just to identify this issue (which is the one in DropBox)... I have restarted Studio, I have restarted my Mac, I have triple checked that I am running the latest and greatest of everything. I have tried multiple devices, I have tried it from the command line as well as Studio and everything fails! Seems that it's not just me that has this issue too! Can you go through the logs in my project and triple check that my settings and installs match yours and that I am running everything just as you are running it? Also do you have a newer device? A 6 or a 7 or an 8? At this point this is one thing that I see that might be different....
  18. Ivan Markovic 2017-10-27

    Motiur, to be honest at this point I think it's best for me to attempt to start from a clean slate. Can you give me instructions on how to completely, completely, completely clear out my Studio and Ti install and then I will start from scratch with a new install. But I need to clean EVERYTHING out... NodeJS, everything connected to Ti. But before I do that can you double check my logs... I have spent HOURS on this already and it's still failing. I have been working with Ti since version 1.x! So I am not a naieve user... I am keen not to waste too much more of my time on this if at all possible! Thanks.
  19. daisyfoto 2017-10-27

    Hi i my problem like Ivan Markovic -eval error on real device -test ios simulator is success -try on ti sdk 6.1.2 and 6.2.2 both error you can see in screen shot link [link Error Info https://drive.google.com/file/d/0B05s5MczZVCDRWEyZFBJeDFIN1k/view?usp=sharing] My environment Operating System Name = Mac OS X Version = 10.13 Architecture = 64bit # CPUs = 4 Memory = 16.0GB Node.js Node.js Version = 6.11.4 npm Version = 3.10.10 Appcelerator CLI Installer = 4.2.9 Core Package = 6.2.4 Titanium CLI CLI Version = 5.0.14 node-appc Version = 0.2.41 Titanium SDKs 6.2.2.GA Version = 6.2.2 Install Location = /Users/daisyfoto/Library/Application Support/Titanium/mobilesdk/osx/6.2.2.GA Platforms = iphone, android, mobileweb git Hash = 42c7196 git Timestamp = 9/19/2017 23:07 node-appc Version = 0.2.43 6.1.2.GA Version = 6.1.2 Install Location = /Users/daisyfoto/Library/Application Support/Titanium/mobilesdk/osx/6.1.2.GA Platforms = iphone, android, mobileweb git Hash = c4cd761 git Timestamp = 7/27/2017 23:13 node-appc Version = 0.2.43 5.3.0.GA Version = 5.3.0 Install Location = /Users/daisyfoto/Library/Application Support/Titanium/mobilesdk/osx/5.3.0.GA Platforms = android, mobileweb, iphone git Hash = 94fa8af git Timestamp = 06/01/16 10:17 node-appc Version = 0.2.33
  20. daisyfoto 2017-10-27

    [link My Screen Shot | https://drive.google.com/file/d/0B05s5MczZVCDRWEyZFBJeDFIN1k/view?usp=sharing]
  21. Motiur Rahman 2017-10-28

    Hello [~imarkovi], Finally, I can reproduce this issue with a new project but working with my old project. Also, WORKS when the liveview turned on! Really, it's a weird behavior. It seem's that the "eval" method does not work properly outside the app.js file like any commonJS object structure. Or the "eval" method does not detect the variable value outside the app.js file. As a workaround, you can declare the variable to the app.js file then use it anywhere of the App. Test Code:
        var win = Ti.UI.createWindow({
        	backgroundColor : 'red',
        	layout : "vertical"
        });
        
        // Create a Button.
        var request = Ti.UI.createButton({
        	title : "Got it",
        	height : Ti.UI.SIZE,
        	width : Ti.UI.SIZE,
        	top : 50
        });
        
        
        function iWantToKillMyslef() {
        	alert("This works in the Simulator and in Live View");
        }
        
        var X = 10;
        var Y = 20;
        
        request.addEventListener('click', function(e) {
        
        	var EvalTestClass = require('lib/evalTest');
        
        	var evalTest = new EvalTestClass();
        
        	evalTest.open();
        });
        
        win.add(request);
        
        win.open();
        
        
        function view() {
        
        	var win = Ti.UI.createWindow({
        		title : "Test",
        		backgroundColor : '#fff'
        	});
        
        	var a = eval("X*Y");
        
        	var label = Ti.UI.createLabel({
        		text : a,
        		color : "#333",
        		font : {
        			fontSize : 20
        		}
        	});
        	win.add(label);
        
        	try {
        		eval("iWantToKillMyslef()");
        	} catch (e) {
        		alert(e);
        	}
        
        	return win;
        };
        
        module.exports = view; 
        
    Try it then let me know.
  22. Ivan Markovic 2017-10-28

    Really really pleased that you've managed to reproduce it! But hold on this is anything but closed. The example you used is anything but realistic. I use the eval method throughout my code. To read in structures from data files and to execute functions. I'd have to move all that code into app's! That's not feasible I'm afraid. It works fine for this very simple example but it would make a mess of my code ! We need a fix for this. I appreciate your effort here to find a work around but it's a hack that would only suffice in an emergency for a simple problem. We really need this fixed in the code. Can you reopen this case please? And let us know when we might expect to see a fix? This looks pretty nasty to me... And it may well be hiding other issues that only arise when not using live view!
  23. Motiur Rahman 2017-10-30

    [~imarkovi], Also, you can declare variables outside of a CommonJS module as a global variable instead of app.js. Although we do not recommend that but as a workaround, you can use it.
        function iWantToKillMyslef() {
        	alert("This works in the Simulator and in Live View");
        }
        
        var X = 10;
        var Y = 20;
        
        function view() {
        
        	var win = Ti.UI.createWindow({
        		title : "Test",
        		backgroundColor : '#fff'
        	});
        
        	var a = eval("X*Y");
        
        	var label = Ti.UI.createLabel({
        		text : a,
        		color : "#333",
        		font : {
        			fontSize : 20
        		}
        	});
        	win.add(label);
        
        	try {
        		eval("iWantToKillMyslef()");
        	} catch (e) {
        		alert(e);
        	}
        
        	return win;
        };
        
        module.exports = view;
        
        
        
    Try it then let me know. Also, I will forward it to our engineering team for more investigation. Thanks
  24. Ivan Markovic 2017-10-30

    Motiur, Thank you for the suggestion but this wouldn't work. I am not just accessing functions and variables but also reading in objects from files and applying eval to them and if I was to move all the functions and make them global and find workarounds for the other issues it would be an absolute mess and I genuinely don't think this would work for a couple of the situations I have. I am sure that others must be having this issue but have not managed to track it down to the eval statement; it cannot be just the couple of us experiencing this. And this is really a rather severe problem! I am very lucky that I have an older version of the SDKs and can distribute on my old system but I am flying off to the US tomorrow and I won't have easy access to that system and that is where I will be attempting to update and deliver the App to my client! Which I obviously can't do at the moment! If you can reopen this case and attach a severe rating to it I think we would all appreciate it. Please keep us updated as to when we might expect a release with a fix for this issue? I hope in the next dot release. Thank you.
  25. Ingo Muschenetz 2017-11-03

    Hi All, what's the current status here?
  26. Hans Knöchel 2017-11-03

    Ivan, are you *really* sure this does not happen in 6.1.0 as stated above? Honestly, it should never work. You are referencing variables outside of their scope, which is invalid. This may work because the Javascript-context of the Simulator is more lossy and allows those references, but the device-one won't. I'd also wonder if this works in NodeJS generally. [~cwilliams], can you give us some insight of your knowledge here? A clean solution (rather the calling it "workaround") will be to pass the variables to the common-js file - either in it's constructor or inside the parameters of the method that computes the values.
  27. Ivan Markovic 2017-11-04

    Hans yes, it works fine in 6.1. It's only in 6.2.x I have been releasing versions of this App now for about 2+ years that use the eval function. It's always worked. This is the Mr Brainwash App that you helped with. I am confused as to what you are talking about referencing variables outside the scope... the scope of the function? So are you saying that this is not allowable: var x = 5; var y = 5; function addMe() { eval("x = y"); } because in my understanding x and y are global and therefore in the scope of the addMe function. This is basically all that I am doing. Exception that my eval looks a bit more like: eval(myVariable + "settings()"); but where the function is global and defined within the parent function that the calling function lives in.... this has always worked for me and it works in all the browsers I have tested it on as well as all the previous versions of the Ti SDK. So something has changed recently. I am not sure how I would be able to pass in the variables to the function containing the eval statement... in my use there are 12 function that the above eval could possibly call... so I would need to pass all those function objects into the function that called the eval? That would be a bit messy I fear....
  28. Hans Knöchel 2017-11-04

    I've gone through the 6.2.0 release-notes twice now (because I could not remember any change regarding that kind of functionality) and couldn't find anything. Please attach a anonymized version of you tiapp.xml here to check your general settings. Regarding the scope: If you are defining a variable inside another file (like the initial reporter of this ticket), it is not expected to work, because the other common-js file has a whole different scope then the one it's being called from. The only ticket that really touched the kroll-core was TIMOB-24830, but that was in *6.1.2* already. Can you confirm it still worked there?
  29. Ivan Markovic 2017-11-04

    Hans, You can find everything in the DropBox link that I included in my earlier posting: https://www.dropbox.com/s/lmkanwc2uwrbixd/EvalTest.zip?dl=0 You will find everything you need there... everything, including my build logs. I am not sure what the others are doing in their code but my code was super simple. I define a global variable inside a parent 'function' and then I call that variable from within a function inside the parent function... so all within the scope of the parent and all in the same file... I would never want to try to access variables outside the parent function, that's all too messy. My example is super simple and super clean. I am in LA at the moment and I do not have access to my main machine, I am using my alt machine which has a slightly older version of the Ti SDK and as it all works I am not touching it for the time being! But on my laptop, which runs 6.2.x, I am stuffed... Prior to 6.2.x I was building and distributing this App with all these eval statements for 2 years or so. Really appreciate your help on this.
  30. Hans Knöchel 2017-11-04

    Checking on Monday. In the mean time, Can you try setting the run-on-main-thread and check if there is a difference?
  31. Ivan Markovic 2017-11-05

    Hans, The setting run-on-main-thread is true in the project I posted here. I have double checked it here and it's still true here in my test build too. I did upgrade the Ti SDK to 6.3 in the hope that it would fix the issue and I actually saw a very different problem, this time the code failed to build! I have attached the log file from the build. It's exactly the same code as posted, no changes whatsoever. https://www.dropbox.com/s/2rwbz6lxbke3ljo/errorlog.txt?dl=0 I hope that this helps...
  32. Hans Knöchel 2017-11-07

    The error is *very* likely related to source-encryption (TIMOB-25328) because of the affected version and seen behavior. Resolving as Duplicate, product management to prioritize the other one.
  33. Eric Merriman 2018-08-06

    Closing as a duplicate. If this is in error, please reopen.

JSON Source