Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25748] iOS: Remove TiCore in favor of built-in JavaScriptCore #9798

Merged
merged 28 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8c20c0a
Remove TiCore
hansemannn Feb 4, 2018
4346b2e
Remove Ti -> JS aliases, remove TiCore references in the CLI, unlink …
hansemannn Feb 4, 2018
31b1357
Fix sorted imports
hansemannn Feb 4, 2018
ee8bd34
Fix typo
hansemannn Feb 4, 2018
b42f740
Another typo
hansemannn Feb 4, 2018
f713a31
Merge branch 'master' into remove-ticore
hansemannn Feb 5, 2018
b8cc542
Remove TiProfiler and TiDebugger, cleanup build scripts
hansemannn Feb 6, 2018
3ea5e1e
Merge branch 'master' into remove-ticore
hansemannn Feb 6, 2018
dd968e6
Merge branch 'master' into remove-ticore
hansemannn Feb 7, 2018
c864ca4
Merge branch 'master' into remove-ticore
sgtcoolguy Feb 7, 2018
340f65b
Fix so Ti.UI.TextArea.editable defaults to true (matching our docs).
sgtcoolguy Feb 7, 2018
6ca4155
Don't try to copy headers folder that no longer exists. Clean up unus…
sgtcoolguy Feb 8, 2018
d1256d9
Merge branch 'master' into remove-ticore
sgtcoolguy May 14, 2018
1dd0fbd
Fix indentation, remove unused 'humanize' dependency
sgtcoolguy May 14, 2018
d5060c8
Merge branch 'master' into remove-ticore
hansemannn Jul 20, 2018
01593be
Resolve remaining merge conflicts
hansemannn Jul 20, 2018
a99030b
Linting
hansemannn Jul 20, 2018
5502a7d
Update PlatformModule.m
hansemannn Jul 20, 2018
378f387
Update TiDOMDocumentProxy.m
hansemannn Jul 20, 2018
292312d
Merge branch 'master' into remove-ticore
sgtcoolguy Jul 23, 2018
53562aa
Fix formatting
sgtcoolguy Jul 23, 2018
823f6e4
Restore package-lock.json, restore iOS CLI option
hansemannn Jul 25, 2018
5ed1827
Use Hyperloop 3.1.0
hansemannn Jul 24, 2018
f8a8ed9
[TIMOB-26055] Android: Fixed bug where CLI would only replace 1st ins…
jquick-axway Jul 25, 2018
dcc8cd6
[TIMOB-26204] Android: Fix transformAfterLayout NPE (#10202)
drauggres Jul 25, 2018
dbc3dda
[TIMOB-26211] Round percentage up instead of down (parity) (#10194)
hansemannn Jul 25, 2018
0c18778
Migrate tests to suite
sgtcoolguy Jul 25, 2018
f6d0a07
Bump to 8.0.0, publish 'next' branch.
sgtcoolguy Jul 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 3 additions & 31 deletions build/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,9 @@ IOS.prototype.clean = function (next) {
next();
};

IOS.prototype.fetchLibTiCore = function (next) {
const url = 'http://timobile.appcelerator.com.s3.amazonaws.com/libTiCore-' + TI_CORE_VERSION + '.a.gz',
dest = path.join(IOS_LIB, 'libTiCore.a'),
markerFile = path.join(IOS_LIB, TI_CORE_VERSION.toString() + '.txt');

// Do we have the latest libTiCore?
if (fs.existsSync(dest) && fs.existsSync(markerFile)) {
return next();
}

console.log('You don\'t seem to have the appropriate thirdparty files. I\'ll fetch them.');
console.log('This could take awhile.. Might want to grab a cup of Joe or make fun of Nolan.');

downloadURL(url, TI_CORE_INTEGRITY, function (err, file) {
if (err) {
return next(err);
}
gunzip(file, dest, function (err) {
if (err) {
return next(err);
}
// Place "marker" file
fs.writeFile(markerFile, 'DO NOT DELETE THIS FILE', next);
});
});
};

IOS.prototype.build = function (next) {
this.fetchLibTiCore(next);
// no-op (used to fetch TiCore in the past)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly not related to this PR, but this jogs my memory. Weren't we going to pre-build libraries for iOS like we do for the other platforms at some point? Do we have JIRA tickets/PRs to track that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember you had an angry TODO comment somewhere that states that we should just place libraries inside the repo instead of fetching them manually. In case you mean that, it should be obsolete now that we remove TiCore. Other libraries like libAPSHTTPClient and libAPSAnalytics are prepackaged, just like Hyperloop should / will be in the future.

next();
};

IOS.prototype.package = function (packager, next) {
Expand All @@ -80,7 +54,6 @@ IOS.prototype.package = function (packager, next) {
const DEST_IOS = path.join(packager.zipSDKDir, 'iphone');

async.parallel([
this.fetchLibTiCore.bind(this),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to remove the step below where we try to copy iphone/headers/JavaScriptCore since there's no files there anymore (that's why the build is failing right now, lines 62-64 in your modified file) - and the 'headers' entry in the array of folders/files we try to copy (line 66 in your modified file)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also remove libti_ios_debugger.a? libti_ios_profiler.a?

Those were to be used against TiCore and do not work with JSCore.

I've been told several times we can kill off our profiler because it's not useful and no one uses/knows about it. The debugger has been replace by using the official debugger APIs built into JSCore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TiProfiler is dead. I think it was used in the past when Titanium wasn't fully compatible with Instruments, which works fine these days. I'll search related guides and docs to clarify that.

function (callback) {
async.series([
function (cb) {
Expand Down Expand Up @@ -118,8 +91,7 @@ IOS.prototype.package = function (packager, next) {
if (err) {
return next(err);
}
// Ensure we've fetched libTiCore before we copy it
copyFiles(IOS_LIB, DEST_IOS, [ 'libTiCore.a' ], next);
next();
});
};

Expand Down
41 changes: 1 addition & 40 deletions iphone/Classes/APIModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
#import "TiExceptionHandler.h"
#import "TiUtils.h"

#ifndef USE_JSCORE_FRAMEWORK
#import "TiDebugger.h"
#endif

extern NSString *const TI_APPLICATION_DEPLOYTYPE;

@implementation APIModule
Expand All @@ -25,42 +21,7 @@ - (NSString *)apiName

- (void)logMessage:(NSArray *)args severity:(NSString *)severity
{

NSString *lcSeverity = [severity lowercaseString];
#ifndef USE_JSCORE_FRAMEWORK
DebuggerLogLevel level = OUT;
if ([lcSeverity isEqualToString:@"warn"]) {
level = WARN;
} else if ([lcSeverity isEqualToString:@"error"] ||
[lcSeverity isEqualToString:@"critical"] ||
[lcSeverity isEqualToString:@"fatal"]) {
level = ERR;
} else if ([lcSeverity isEqualToString:@"trace"]) {
level = TRACE;
} else if ([lcSeverity isEqualToString:@"debug"]) {
level = LOG_DEBUG;
}

if ([[TiApp app] debugMode]) {
NSMutableArray *messages = [NSMutableArray arrayWithArray:args];

if (![lcSeverity isEqualToString:@"info"]) { // Custom severity, or just a badly-formed log; either way, debugger treats it as info
[messages insertObject:[NSString stringWithFormat:@"[%@]", severity] atIndex:0];
}

TiDebuggerLogMessage(level, [messages componentsJoinedByString:@" "]);
} else
#endif
{
#ifndef USE_JSCORE_FRAMEWORK
if ([TI_APPLICATION_DEPLOYTYPE isEqualToString:@"production"]) {
if (level != ERR) {
return;
}
}
#endif
NSLog(@"[%@] %@", [severity uppercaseString], [args componentsJoinedByString:@" "]);
}
NSLog(@"[%@] %@", [severity uppercaseString], [args componentsJoinedByString:@" "]);
}

- (id)transform:(id)arg
Expand Down
3 changes: 2 additions & 1 deletion iphone/Classes/KrollBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#import "TiEvaluator.h"
#import "TiModule.h"
#import "TiProxy.h"
#import "TiToJS.h"

#import <Foundation/Foundation.h>
#import <JavaScriptCore/JavaScriptCore.h>
#include <libkern/OSAtomic.h>

#ifdef KROLL_COVERAGE
Expand Down
98 changes: 35 additions & 63 deletions iphone/Classes/KrollBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
#import "TiConsole.h"
#import "TiExceptionHandler.h"
#import "TiHost.h"
#import "TiToJS.h"
#import "TiUtils.h"
#import "TopTiModule.h"
#import <JavaScriptCore/JavaScriptCore.h>
#import <libkern/OSAtomic.h>

#ifdef KROLL_COVERAGE
#include "KrollCoverage.h"
#endif
#ifndef USE_JSCORE_FRAMEWORK
#import "TiDebugger.h"
#endif
extern BOOL const TI_APPLICATION_ANALYTICS;
extern NSString *const TI_APPLICATION_DEPLOYTYPE;
extern NSString *const TI_APPLICATION_GUID;
Expand Down Expand Up @@ -369,9 +366,9 @@ - (void)evalFileOnThread:(NSString *)path context:(KrollContext *)context_
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSError *error = nil;
TiValueRef exception = NULL;
JSValueRef exception = NULL;

TiContextRef jsContext = [context_ context];
JSContextRef jsContext = [context_ context];

NSURL *url_ = [path hasPrefix:@"file:"] ? [NSURL URLWithString:path] : [NSURL fileURLWithPath:path];

Expand Down Expand Up @@ -410,23 +407,11 @@ - (void)evalFileOnThread:(NSString *)path context:(KrollContext *)context_

const char *urlCString = [[url_ absoluteString] UTF8String];

TiStringRef jsCode = TiStringCreateWithCFString((CFStringRef)jcode);
TiStringRef jsURL = TiStringCreateWithUTF8CString(urlCString);
JSStringRef jsCode = JSStringCreateWithCFString((CFStringRef)jcode);
JSStringRef jsURL = JSStringCreateWithUTF8CString(urlCString);

if (exception == NULL) {
#ifndef USE_JSCORE_FRAMEWORK
if ([[self host] debugMode]) {
TiDebuggerBeginScript(context_, urlCString);
}
#endif

TiEvalScript(jsContext, jsCode, NULL, jsURL, 1, &exception);

#ifndef USE_JSCORE_FRAMEWORK
if ([[self host] debugMode]) {
TiDebuggerEndScript(context_);
}
#endif
JSEvaluateScript(jsContext, jsCode, NULL, jsURL, 1, &exception);
if (exception == NULL) {
evaluationError = NO;
} else {
Expand All @@ -439,8 +424,8 @@ - (void)evalFileOnThread:(NSString *)path context:(KrollContext *)context_
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:excm]];
}

TiStringRelease(jsCode);
TiStringRelease(jsURL);
JSStringRelease(jsCode);
JSStringRelease(jsURL);
[pool release];
}

Expand Down Expand Up @@ -531,30 +516,30 @@ - (void)didStartNewContext:(KrollContext *)kroll
NSString *basePath = (url == nil) ? [TiHost resourcePath] : [[[url path] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"."];
titanium = [[TitaniumObject alloc] initWithContext:kroll host:host context:self baseURL:[NSURL fileURLWithPath:basePath]];

TiContextRef jsContext = [kroll context];
TiValueRef tiRef = [KrollObject toValue:kroll value:titanium];
JSContextRef jsContext = [kroll context];
JSValueRef tiRef = [KrollObject toValue:kroll value:titanium];

NSString *titaniumNS = [NSString stringWithFormat:@"T%sanium", "it"];
TiStringRef prop = TiStringCreateWithCFString((CFStringRef)titaniumNS);
TiStringRef prop2 = TiStringCreateWithCFString((CFStringRef)[NSString stringWithFormat:@"%si", "T"]);
TiObjectRef globalRef = TiContextGetGlobalObject(jsContext);
TiObjectSetProperty(jsContext, globalRef, prop, tiRef,
kTiPropertyAttributeDontDelete | kTiPropertyAttributeDontEnum,
JSStringRef prop = JSStringCreateWithCFString((CFStringRef)titaniumNS);
JSStringRef prop2 = JSStringCreateWithCFString((CFStringRef)[NSString stringWithFormat:@"%si", "T"]);
JSObjectRef globalRef = JSContextGetGlobalObject(jsContext);
JSObjectSetProperty(jsContext, globalRef, prop, tiRef,
kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum,
NULL);
TiObjectSetProperty(jsContext, globalRef, prop2, tiRef,
kTiPropertyAttributeDontDelete | kTiPropertyAttributeDontEnum,
JSObjectSetProperty(jsContext, globalRef, prop2, tiRef,
kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum,
NULL);
TiStringRelease(prop);
TiStringRelease(prop2);
JSStringRelease(prop);
JSStringRelease(prop2);

// Load the "console" object into the global scope
console = [[KrollObject alloc] initWithTarget:[[[TiConsole alloc] _initWithPageContext:self] autorelease] context:kroll];
prop = TiStringCreateWithCFString((CFStringRef) @"console");
TiObjectSetProperty(jsContext, globalRef, prop, [KrollObject toValue:kroll value:console], kTiPropertyAttributeNone, NULL);
prop = JSStringCreateWithCFString((CFStringRef) @"console");
JSObjectSetProperty(jsContext, globalRef, prop, [KrollObject toValue:kroll value:console], kJSPropertyAttributeNone, NULL);

// Make the global object itself available under the name "global"
TiStringRef globalPropertyName = TiStringCreateWithCFString((CFStringRef) @"global");
TiObjectSetProperty(jsContext, globalRef, globalPropertyName, globalRef, kTiPropertyAttributeDontEnum | kTiPropertyAttributeReadOnly | kTiPropertyAttributeDontDelete, NULL);
JSStringRef globalPropertyName = JSStringCreateWithCFString((CFStringRef) @"global");
JSObjectSetProperty(jsContext, globalRef, globalPropertyName, globalRef, kJSPropertyAttributeDontEnum | kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);

//if we have a preload dictionary, register those static key/values into our namespace
if (preload != nil) {
Expand Down Expand Up @@ -728,8 +713,8 @@ - (KrollWrapper *)loadCommonJSModule:(NSString *)code withSourceURL:(NSURL *)sou
* done, we should have as little footprint
*/
KrollEval *eval = [[KrollEval alloc] initWithCode:js sourceURL:sourceURL startingLineNo:1];
TiValueRef exception = NULL;
TiValueRef resultRef = [eval jsInvokeInContext:context exception:&exception];
JSValueRef exception = NULL;
JSValueRef resultRef = [eval jsInvokeInContext:context exception:&exception];
[js release];
[eval release];

Expand All @@ -745,7 +730,7 @@ - (KrollWrapper *)loadCommonJSModule:(NSString *)code withSourceURL:(NSURL *)sou

KrollWrapper *result = [[KrollWrapper alloc] init];
[result setBridge:self];
[result setJsobject:(TiObjectRef)resultRef];
[result setJsobject:(JSObjectRef)resultRef];
[result protectJsobject];

return [result autorelease];
Expand Down Expand Up @@ -784,22 +769,22 @@ - (TiModule *)loadTopLevelNativeModule:(TiModule *)module withPath:(NSString *)p
// are accessible. We store the exports object and then put references to its properties on the toplevel
// object.

TiContextRef jsContext = [[self krollContext] context];
TiObjectRef jsObject = [wrapper jsobject];
JSContextRef jsContext = [[self krollContext] context];
JSObjectRef jsObject = [wrapper jsobject];
KrollObject *moduleObject = [module krollObjectForContext:[self krollContext]];
[moduleObject noteObject:jsObject forTiString:kTiStringExportsKey context:jsContext];

TiPropertyNameArrayRef properties = TiObjectCopyPropertyNames(jsContext, jsObject);
size_t count = TiPropertyNameArrayGetCount(properties);
JSPropertyNameArrayRef properties = JSObjectCopyPropertyNames(jsContext, jsObject);
size_t count = JSPropertyNameArrayGetCount(properties);
for (size_t i = 0; i < count; i++) {
// Mixin the property onto the module JS object if it's not already there
TiStringRef propertyName = TiPropertyNameArrayGetNameAtIndex(properties, i);
if (!TiObjectHasProperty(jsContext, [moduleObject jsobject], propertyName)) {
TiValueRef property = TiObjectGetProperty(jsContext, jsObject, propertyName, NULL);
TiObjectSetProperty([[self krollContext] context], [moduleObject jsobject], propertyName, property, kTiPropertyAttributeReadOnly, NULL);
JSStringRef propertyName = JSPropertyNameArrayGetNameAtIndex(properties, i);
if (!JSObjectHasProperty(jsContext, [moduleObject jsobject], propertyName)) {
JSValueRef property = JSObjectGetProperty(jsContext, jsObject, propertyName, NULL);
JSObjectSetProperty([[self krollContext] context], [moduleObject jsobject], propertyName, property, kJSPropertyAttributeReadOnly, NULL);
}
}
TiPropertyNameArrayRelease(properties);
JSPropertyNameArrayRelease(properties);

return module;
}
Expand Down Expand Up @@ -910,21 +895,8 @@ - (KrollWrapper *)loadJavascriptObject:(NSString *)data fromFile:(NSString *)fil
- (KrollWrapper *)loadJavascriptText:(NSString *)data fromFile:(NSString *)filename withContext:(KrollContext *)kroll
{
NSURL *url_ = [TiHost resourceBasedURL:filename baseURL:NULL];
#ifndef USE_JSCORE_FRAMEWORK
const char *urlCString = [[url_ absoluteString] UTF8String];
if ([[self host] debugMode]) {
TiDebuggerBeginScript([self krollContext], urlCString);
}
#endif

KrollWrapper *wrapper = [self loadCommonJSModule:data withSourceURL:url_];

#ifndef USE_JSCORE_FRAMEWORK
if ([[self host] debugMode]) {
TiDebuggerEndScript([self krollContext]);
}
#endif

if (![wrapper respondsToSelector:@selector(replaceValue:forKey:notification:)]) {
@throw [NSException exceptionWithName:@"org.appcelerator.kroll"
reason:[NSString stringWithFormat:@"Module \"%@\" failed to leave a valid exports object", filename]
Expand Down
18 changes: 9 additions & 9 deletions iphone/Classes/KrollCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Please see the LICENSE included with this distribution for details.
*/
#import "KrollContext.h"
#import "TiToJS.h"
#import <Foundation/Foundation.h>
#import <JavaScriptCore/JavaScriptCore.h>

@class KrollBridge;
//
Expand All @@ -17,9 +17,9 @@
//
@interface KrollCallback : NSObject {
@private
TiContextRef jsContext;
TiObjectRef thisObj;
TiObjectRef function;
JSContextRef jsContext;
JSObjectRef thisObj;
JSObjectRef function;
KrollContext *context;
KrollBridge *bridge;
#ifdef TI_USE_KROLL_THREAD
Expand All @@ -30,10 +30,10 @@

@property (nonatomic, readwrite, retain) NSString *type;

- (id)initWithCallback:(TiValueRef)function_ thisObject:(TiObjectRef)thisObject_ context:(KrollContext *)context_;
- (id)initWithCallback:(JSValueRef)function_ thisObject:(JSObjectRef)thisObject_ context:(KrollContext *)context_;
- (void)callAsync:(NSArray *)args thisObject:(id)thisObject_;
- (id)call:(NSArray *)args thisObject:(id)thisObject_;
- (TiObjectRef)function;
- (JSObjectRef)function;
- (KrollContext *)context;
+ (void)shutdownContext:(KrollContext *)context;

Expand All @@ -55,7 +55,7 @@
* NOTE: This is an object that is never made explicitly by TiIdToValue;
* instead, all JS functions become KrollCallbacks, and both KrollCallbacks
* and KrollObjectProperties will be converted into functions.
* (or TiObjectRefs at any rate)
* (or JSObjectRefs at any rate)
* Instead, KrollWrapper is used in two places currently: When a function is
* retained as a property by a proxy (to avoid the above retain loop),
* and for JS-based modules which do not need proxy properties but do need to
Expand All @@ -67,12 +67,12 @@
@class KrollBridge;

@interface KrollWrapper : NSObject {
TiObjectRef jsobject;
JSObjectRef jsobject;
KrollBridge *bridge;
BOOL protecting;
}

@property (nonatomic, readwrite, assign) TiObjectRef jsobject;
@property (nonatomic, readwrite, assign) JSObjectRef jsobject;
@property (nonatomic, readwrite, assign) KrollBridge *bridge;

- (void)protectJsobject;
Expand Down