Problem
When trying to evalJS a string with code that starts with
var
it doesn't work and I get this error message in Console:
[INFO][TiWebChromeClient.console( 1229)] (main) [493,23278] Uncaught SyntaxError: Unexpected token var (1:http://www.google.com/)
Expected Behavior
Should not throw and instead replace the site contents with "test". Works on iOS.
Test case
var win = Ti.UI.createWindow();
var webView = Ti.UI.createWebView({
url: 'http://google.com',
top: 0,
bottom: 0,
height: Ti.UI.FILL,
});
win.add(webView);
win.open({
modal: true,
animated: false
});
webView.addEventListener('load', function() {
webView.evalJS('var a="test";document.body.innerHTML=a'); // doesn't works
//webView.evalJS('document.body.innerHTML="test"'); // works
});
bump
bump
If passed in value is not an expression but a statement block, extract the last statement and add prepend 'return'. https://github.com/appcelerator/titanium_mobile/pull/5210
Verified the fix using: OSX: 10.9.2 Xcode: 5.1.1 Studio - 3.3.0.201404251359 SDK - 3.3.0.v20140425191906 acs-1.0.14 alloy-1.4.0-dev npm-1.3.2 titanium-3.3.0-dev titanium-code-processor-1.1.1-beta1 Device: LG-P970 (4.0.4) & ipod touch 2 (7.1)
Based on the regressions caused by this issue, reopening. We need to find a solution with less side effects.