Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18770] HAL: Variables using unicode characters cause Application Error

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2015-07-14T23:16:31.000+0000
Affected Version/sRelease 4.1.0
Fix Version/sRelease 4.1.0
ComponentsHyperloop, Windows
LabelsHAL, JavaScriptCore
ReporterFokke Zandbergen
AssigneeGary Mathews
Created2015-03-31T14:48:35.000+0000
Updated2017-03-16T21:55:43.000+0000

Description

When you use a special unicode character in a variable name (which is perfectly fine on iOS and Android and valid JS) the application will crash.

Test case

var φ = 'hello world';

Ti.UI.createWindow({
  backgroundColor: "white"
}).open();

Crash

[ERROR] Application Error: {
[ERROR]   "message": "Error while require(./app) Invalid character '\\u0966'",
[ERROR]   "native_stack": [
[ERROR]     "JSExportClass<class Titanium::GlobalObject>::CallNamedFunction"
[ERROR]   ],
[ERROR]   "stack": "require@[native code]\nglobal code",
[ERROR]   "line": 2
[ERROR] }

Comments

  1. Ingo Muschenetz 2015-03-31

    Kota, can you please take a look when you get a moment?
  2. Kota Iguchi 2015-04-07

    Confirmed that this issue originally came from JavaScriptCore C API itself on Windows. Thus HAL on Windows can not handle this well. For instance following code should return "hello, world" string but on Windows it returns "undefined". I'm expecting there's some issue handling UTF-8 string on JavaScriptCore Windows but I'm not sure where it is and how to fix this.
       	JSGlobalContextRef context = JSGlobalContextCreate(NULL);
       	JSStringRef jsScriptString = JSStringCreateWithUTF8CString("var φ = 'hello world'; φ;");
       	JSStringRef jsFilenameString = JSStringCreateWithUTF8CString("app.js");
       	JSValueRef exception = NULL;
       
       	JSValueRef result = JSEvaluateScript(context, jsScriptString, NULL, jsFilenameString, 0, &exception);
       
       	JSStringRelease(jsScriptString);
       	JSStringRelease(jsFilenameString);
       
  3. Kota Iguchi 2015-05-10

    Confirmed that the character φ is successfully converted into valid UTF-8 bytes (0xcf86) and passed to JSC functions. It means the issues are inside JavaScriptCore so in order to fix this issue we need to update JavaScriptCore. may be related: https://github.com/WebKit/webkit/commits/master/Source/JavaScriptCore/parser/Lexer.cpp
  4. Christopher Williams 2015-05-20

    This may the commit that fixes the issue in webkit/JSC? https://github.com/WebKit/webkit/commit/2eb5f4de2fb20e7dddaba89da5118e84d71d82c5#diff-0af0b457165c27ee7ef19b92709c2df1
  5. Kota Iguchi 2015-06-08

    While trying to apply recent changes around [JavaScriptCore Lexer | https://github.com/WebKit/webkit/commit/2eb5f4de2fb20e7dddaba89da5118e84d71d82c5#diff-0af0b457165c27ee7ef19b92709c2df1], I found that recent JavaScriptCore is trying to eliminates use of WTF::Unicode but instead use ICU directly. The problem here is that our JavaScriptCore for Windows is relying on custom WTF::Unicode handler for wchar_t which is built specifically for Windows, which doesn't depend on ICU. That's why we can't merge latest changes around Lexer as it is. So the actual issue now is that, it looks like we actually didn't implement Unicode detection in our custom WTF::Unicode handler. See [WTF/wtf/unicode/wchar/UnicodeWchar.cpp](https://github.com/appcelerator/webkit/blob/javascriptcore-wp8.1/Source/WTF/wtf/unicode/wchar/UnicodeWchar.cpp#L33), we can see some FIXME: implement comment there. I would assume at least we should implement these to handle Unicode correctly to make JavaScriptCore Lexer work well.
  6. Kota Iguchi 2015-06-08

    https://github.com/appcelerator/webkit/pull/5
  7. Kota Iguchi 2015-06-14

    Original issue in JavaScriptCore is already fixed by [webkit#PR5](https://github.com/appcelerator/webkit/pull/5). Waiting for TIMOB-18948 to be done.
  8. Ewan Harris 2015-07-13

    Reopening ticket, when building with: Windows 8.1 Appc CLI (NPM): 4.1.0 Appc CLI (Registry): 4.1.0 Ti SDK: 4.1.0.GA, 4.2.0.v20150710092422 When using the code attached I still see the error
       [ERROR] Application Error: {
       [ERROR]   "message": "Error while require(./app) Invalid character '\\u0966'",
       [ERROR]   "native_stack": [
       [ERROR]     "JSExportClass<class Titanium::GlobalObject>::CallNamedFunction"
       [ERROR]   ],
       [ERROR]   "stack": "require@[native code]\nglobal code",
       [ERROR]   "line": 2
       [ERROR] }
       
  9. Gary Mathews 2015-07-14

    This is because the build server for titanium_mobile_windows is using an old JavaScriptCore build to compile the SDK. [titanium_mobile_windows/Tools/Scripts/setup.js](https://github.com/appcelerator/titanium_mobile_windows/blob/master/Tools/Scripts/setup.js#L33) We should be using [JavaScriptCore-Windows-1433795599.zip](http://studio-jenkins.appcelerator.org/job/JavaScriptCore/lastSuccessfulBuild/artifact/dist/JavaScriptCore-Windows-1433795599.zip)
  10. Gary Mathews 2015-07-14

    PR: https://github.com/appcelerator/titanium_mobile_windows/pull/373
  11. Lee Morris 2017-03-16

    Closing ticket as fixed.

JSON Source