Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26038] iOS: Move from legacy JavaScriptCore C Api to Obj-C API

GitHub Issuen/a
TypeEpic
PriorityHigh
StatusIn Progress
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterChristopher Williams
AssigneeChristopher Williams
Created2018-05-14T19:24:24.000+0000
Updated2019-05-21T00:02:37.000+0000

Description

We currently make use of the "legacy" C API for JavaScriptCore. In the past few years Apple has made a much nicer Obj-C API to the framework which makes it much simpler to expose native objects to JavaScript. We already attempt to make use of this in HAL/Windows, though it's lower level, while the Obj-C API transparently does the bindings for us. - https://developer.apple.com/documentation/javascriptcore?language=objc - https://www.steamclock.com/blog/2013/05/apple-objective-c-javascript-bridge/ - http://asciiwwdc.com/2013/sessions/615 More: - https://github.com/phoboslab/JavaScriptCore-iOS/blob/master/JavaScriptCore/API/tests/testapi.mm - https://github.com/WebKit/webkit/blob/dd7199d7f8f417992f60c9f1514e4b548ec923fb/Source/JavaScriptCore/API/JSWrapperMap.mm

Comments

  1. Christopher Williams 2018-05-17

    Note also that our implementation using the JavaScriptCore C API is not very well tuned. The iOS implementation behaves similarly to how Android hyperloop does: with a generic KrollObject that is exported/bound to JS with native callbacks for getProperty/setProperty/etc which then uses the equivalent of "reflection" to delegate to the wrapped Obj-C instance. The new JSExport API offers a similar proxy writing API as we currently do, but actually generates the correct bindings at the property/function level on a defined JS class specific to the Obj-C class. This avoid the need for our custom routing of calls through a generic getProperty impl, for example. What it does not handle though is: - indexed property access (like we use in Ti.Buffer) - setting static values for properties (i.e. we often return a static string/value for APIs such as Ti.Platform.manufacturer, JSExport will still delegate that into a method call, but using the C API we could just set a static value for that property on the JS side).

JSON Source