[ALOY-1686] Alloy: App crashes due to context used when accessing Ti.Database API
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2019-05-16T13:38:31.000+0000 |
Affected Version/s | Alloy 1.13.9 |
Fix Version/s | CLI Release 7.0.12, Alloy 1.13.10 |
Components | Models |
Labels | n/a |
Reporter | Hans Knöchel |
Assignee | Christopher Williams |
Created | 2019-05-02T09:27:34.000+0000 |
Updated | 2019-05-17T14:05:35.000+0000 |
Description
The current master is broken due to changes in the Obj-C JSCore interface (TIMOB-26038):
[ERROR] Script Error {
[ERROR] column = 38;
[ERROR] line = 214;
[ERROR] message = "self type check failed for Objective-C instance method";
[ERROR] sourceURL = "file:///Users/hans/Library/Developer/CoreSimulator/Devices/884D0F2B-46F2-41D5-AA78-C26BC42BF348/data/Containers/Bundle/Application/B1994734-79D4-40DD-9003-C940456A903D/Lambus.app/alloy/sync/sql.js";
[ERROR] stack = " at [native code]\n at Sync(/alloy/sync/sql.js:214:38)\n at sync(/alloy.js:92:22)\n at fetch(/alloy/backbone.js:344:47)\n at (/app.js:45:24)\n at global code(/app.js:225:70)\n at require@[native code]\n at (/ti.main.js:8997:10)\n at doLoad(/ti.main.js:8955:15)\n at loadBootstrapScripts(/ti.main.js:8967:11)\n at loadAsync(/ti.main.js:8972:23)\n at global code(/ti.main.js:8994:10)";
[ERROR] toJSON = "<KrollCallback: 0x600000bfba40>";
[ERROR] }
Specifically, changes in Ti.Database
seem to have caused this issues. It was triggered by Alloy models which use Backbone in the background which uses Ti.Database in the background.
To reproduce, simply create a new Alloy app and create a model as documented in the docs. For the core-team: This is also reproducible in the app you guys have access to.
*EDIT*: After investigating this, it seems like [this selector](https://github.com/appcelerator/titanium_mobile/pull/10381/files#diff-d0e600e43c92d0fe06ffee452771f44cR125) is causing the issues as it's referenced in the sql.js to get the field from the result-set at the specified index.
cc [~cwilliams] [~jvennemann]
Any update here? We're trying to stay on latest master to report back all issues, but this one is currently breaking us.
Another attempt to ping this…Does this really need to slip into a GA again to get people's attention on this? Every app that uses Ti.Database will be broken and I have no idea how the unit tests could have allowed this to be merged.
So at first glance this looks to me like a latent bug in Alloy that happened not to trigger before (oddly). It plays around with the result set's field method a little:
Notice that on Windows or Android it uses bind to explicitly tie
this
to the ResultSet instance. On iOS it does not. As a result,this
is implicitly the global object: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind Changing that line to always use bind on all platforms fixes the issue. Or simply callingrs.field(i);
which is much more common usage - I'm not sure why this redirection was used in the first place. Note that we ran into this exact same bug before on Windows (using JSCore) in TIMOB-20577.https://github.com/appcelerator/alloy/pull/930
[~cwilliams] Issue fixed, thank you so much!!
1_13_X backport: https://github.com/appcelerator/alloy/pull/931
Closing ticket also verified using CLI
7.1.0-master.16
with the above steps.