Skip to content

Commit

Permalink
Merge pull request #11 from pec1985/TIMOB-23136
Browse files Browse the repository at this point in the history
[TIMOB-23136] Removed TiJSCore and only allow JSCore
  • Loading branch information
jhaynie committed Apr 20, 2016
2 parents aee17db + 2e60154 commit fdbf5ac
Show file tree
Hide file tree
Showing 9 changed files with 524 additions and 397 deletions.
13 changes: 3 additions & 10 deletions iphone/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [ "${CI}" = "1" ];
then
echo "Testing ..."
xcodebuild clean >/dev/null
xcodebuild -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' -scheme hyperloop -target Tests -configuration Debug GCC_PREPROCESSOR_DEFINITIONS='USE_JSCORE_FRAMEWORK=1' test | xcpretty -r junit
xcodebuild -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' -scheme hyperloop -target Tests -configuration Debug test | xcpretty -r junit
if [ $? -ne 0 ];
then
exit $?
Expand All @@ -39,15 +39,10 @@ cp manifest module.xcconfig build/zip/modules/iphone/hyperloop/$VERSION

# Build for the Apple JavaScriptCore built-in
xcodebuild clean >/dev/null
# we still need the "USE_JSCORE_FRAMEWORK=1" flag because of Titanium's header files
xcodebuild -sdk iphoneos -configuration Release GCC_PREPROCESSOR_DEFINITIONS='TIMODULE=1 USE_JSCORE_FRAMEWORK=1' ONLY_ACTIVE_ARCH=NO | xcpretty
xcodebuild -sdk iphonesimulator -configuration Debug GCC_PREPROCESSOR_DEFINITIONS='TIMODULE=1 USE_JSCORE_FRAMEWORK=1' ONLY_ACTIVE_ARCH=NO | xcpretty
lipo build/Debug-iphonesimulator/libhyperloop.a build/Release-iphoneos/libhyperloop.a -create -output build/zip/modules/iphone/hyperloop/$VERSION/libhyperloop-jscore.a >/dev/null 2>&1

# Build for the Titanium custom JavaScriptCore
xcodebuild clean >/dev/null
xcodebuild -sdk iphoneos -configuration Release GCC_PREPROCESSOR_DEFINITIONS='TIMODULE=1' ONLY_ACTIVE_ARCH=NO | xcpretty
xcodebuild -sdk iphonesimulator -configuration Debug GCC_PREPROCESSOR_DEFINITIONS='TIMODULE=1' ONLY_ACTIVE_ARCH=NO | xcpretty
lipo build/Debug-iphonesimulator/libhyperloop.a build/Release-iphoneos/libhyperloop.a -create -output build/zip/modules/iphone/hyperloop/$VERSION/libhyperloop-ticore.a
lipo build/Debug-iphonesimulator/libhyperloop.a build/Release-iphoneos/libhyperloop.a -create -output build/zip/modules/iphone/hyperloop/$VERSION/libhyperloop.a >/dev/null 2>&1

echo "Packaging ..."
# make sure to update the plugin with the latest version in it's package.json
Expand All @@ -73,8 +68,6 @@ npm i --production >/dev/null 2>&1
rm -rf unittest
cp -R * $CWD/build/zip/plugins/hyperloop/node_modules/hyperloop-metabase

# titanium requires at least this file so just create an empty one
echo 1 > $CWD/build/zip/modules/iphone/hyperloop/$VERSION/libhyperloop.a

cd $CWD/build/zip
rm -rf $CWD/hyperloop-iphone-$VERSION.zip
Expand Down
6 changes: 2 additions & 4 deletions iphone/plugin/hyperloop.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ HyperloopiOSBuilder.prototype.validate = function validate() {
HyperloopiOSBuilder.prototype.setup = function setup() {
// check for built-in JSCore but only warn if not set
if (this.builder.tiapp.ios['use-jscore-framework'] === undefined) {
this.logger.info('Hyperloop compiler works best with the built-in iOS JavaScript library.');
this.logger.info('Hyperloop compiler only works with the built-in iOS JavaScript library.');
this.logger.info('Add the following to your tiapp.xml <ios> section to enable or disable this:');
this.logger.info('');
this.logger.info(' <use-jscore-framework>true</use-jscore-framework>');
Expand All @@ -180,11 +180,9 @@ HyperloopiOSBuilder.prototype.setup = function setup() {
// update to use the correct libhyperloop based on which JS engine is configured
this.builder.nativeLibModules.some(function (mod) {
if (mod.id === 'hyperloop') {
var frag = this.builder.tiapp.ios['use-jscore-framework'] ? 'js' : 'ti';
mod.libName = 'libhyperloop-' + frag + 'core.a';
mod.libName = 'libhyperloop.a';
mod.libFile = path.join(mod.modulePath, mod.libName);
mod.hash = crypto.createHash('md5').update(fs.readFileSync(mod.libFile)).digest('hex');
this.logger.debug('Using Hyperloop library -> ' + mod.libName);
return true;
}
}, this);
Expand Down
153 changes: 153 additions & 0 deletions iphone/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// script to replace all Ti* to JS* symbols
var symbols = {
TiObjectCallAsConstructor: 'JSObjectCallAsConstructor',
TiClassCreate: 'JSClassCreate',
TiClassDefinition: 'JSClassDefinition',
TiClassRef: 'JSClassRef',
TiClassRelease: 'JSClassRelease',
TiClassRetain: 'JSClassRetain',
TiContextGetGlobalContext: 'JSContextGetGlobalContext',
TiContextGetGlobalObject: 'JSContextGetGlobalObject',
TiContextGetGroup: 'JSContextGetGroup',
TiContextGroupCreate: 'JSContextGroupCreate',
TiContextGroupRef: 'JSContextGroupRef',
TiContextGroupRelease: 'JSContextGroupRelease',
TiContextGroupRetain: 'JSContextGroupRetain',
TiContextRef: 'JSContextRef',
TiEvalScript: 'JSEvaluateScript',
TiGlobalContextCreate: 'JSGlobalContextCreate',
TiGlobalContextCreateInGroup: 'JSGlobalContextCreateInGroup',
TiGlobalContextRef: 'JSGlobalContextRef',
TiGlobalContextRelease: 'JSGlobalContextRelease',
TiGlobalContextRetain: 'JSGlobalContextRetain',
TiObjectCallAsConstructorCallback: 'JSObjectCallAsConstructorCallback',
TiObjectCallAsFunction: 'JSObjectCallAsFunction',
TiObjectCallAsFunctionCallback: 'JSObjectCallAsFunctionCallback',
TiObjectConvertToTypeCallback: 'JSObjectConvertToTypeCallback',
TiObjectCopyPropertyNames: 'JSObjectCopyPropertyNames',
TiObjectDeleteProperty: 'JSObjectDeleteProperty',
TiObjectFinalizeCallback: 'JSObjectFinalizeCallback',
TiObjectGetPrivate: 'JSObjectGetPrivate',
TiObjectGetProperty: 'JSObjectGetProperty',
TiObjectGetPropertyAtIndex: 'JSObjectGetPropertyAtIndex',
TiObjectHasInstanceCallback: 'JSObjectHasInstanceCallback',
TiObjectHasProperty: 'JSObjectHasProperty',
TiObjectInitializeCallback: 'JSObjectInitializeCallback',
TiObjectIsFunction: 'JSObjectIsFunction',
TiObjectMake: 'JSObjectMake',
TiObjectMakeArray: 'JSObjectMakeArray',
TiObjectMakeDate: 'JSObjectMakeDate',
TiObjectMakeError: 'JSObjectMakeError',
TiObjectMakeFunction: 'JSObjectMakeFunction',
TiObjectMakeFunctionWithCallback: 'JSObjectMakeFunctionWithCallback',
TiObjectRef: 'JSObjectRef',
TiObjectSetPrivate: 'JSObjectSetPrivate',
TiObjectSetProperty: 'JSObjectSetProperty',
TiObjectSetPropertyAtIndex: 'JSObjectSetPropertyAtIndex',
TiObjectGetPrototype: 'JSObjectGetPrototype',
TiPropertyNameAccumulatorAddName: 'JSPropertyNameAccumulatorAddName',
TiPropertyNameAccumulatorRef: 'JSPropertyNameAccumulatorRef',
TiPropertyNameArrayGetCount: 'JSPropertyNameArrayGetCount',
TiPropertyNameArrayGetNameAtIndex: 'JSPropertyNameArrayGetNameAtIndex',
TiPropertyNameArrayRef: 'JSPropertyNameArrayRef',
TiPropertyNameArrayRef: 'JSPropertyNameArrayRef',
TiPropertyNameArrayRelease: 'JSPropertyNameArrayRelease',
TiStaticFunction: 'JSStaticFunction',
TiStaticValue: 'JSStaticValue',
TiStringCopyCFString: 'JSStringCopyCFString',
TiStringCreateWithCFString: 'JSStringCreateWithCFString',
TiStringCreateWithCharacters: 'JSStringCreateWithCharacters',
TiStringCreateWithUTF8CString: 'JSStringCreateWithUTF8CString',
TiStringGetCharactersPtr: 'JSStringGetCharactersPtr',
TiStringGetLength: 'JSStringGetLength',
TiStringGetMaximumUTF8CStringSize: 'JSStringGetMaximumUTF8CStringSize',
TiStringGetUTF8CString: 'JSStringGetUTF8CString',
TiStringIsEqual: 'JSStringIsEqual',
TiStringIsEqualToUTF8CString: 'JSStringIsEqualToUTF8CString',
TiStringRef: 'JSStringRef',
TiStringRelease: 'JSStringRelease',
TiStringRetain: 'JSStringRetain',
TiType: 'JSType',
TiValueCreateJSONString: 'JSValueCreateJSONString',
TiValueGetType: 'JSValueGetType',
TiValueIsBoolean: 'JSValueIsBoolean',
TiValueIsEqual: 'JSValueIsEqual',
TiValueIsInstanceOfConstructor: 'JSValueIsInstanceOfConstructor',
TiValueIsNull: 'JSValueIsNull',
TiValueIsNumber: 'JSValueIsNumber',
TiValueIsObject: 'JSValueIsObject',
TiValueIsObjectOfClass: 'JSValueIsObjectOfClass',
TiValueIsStrictEqual: 'JSValueIsStrictEqual',
TiValueIsString: 'JSValueIsString',
TiValueIsUndefined: 'JSValueIsUndefined',
TiValueMakeBoolean: 'JSValueMakeBoolean',
TiValueMakeFromJSONString: 'JSValueMakeFromJSONString',
TiValueMakeNull: 'JSValueMakeNull',
TiValueMakeNumber: 'JSValueMakeNumber',
TiValueMakeString: 'JSValueMakeString',
TiValueMakeUndefined: 'JSValueMakeUndefined',
TiValueProtect: 'JSValueProtect',
TiValueRef: 'JSValueRef',
TiValueToBoolean: 'JSValueToBoolean',
TiValueToNumber: 'JSValueToNumber',
TiValueToObject: 'JSValueToObject',
TiValueToStringCopy: 'JSValueToStringCopy',
TiValueToStringCopy: 'JSValueToStringCopy',
TiValueUnprotect: 'JSValueUnprotect',
kTITypeBoolean: 'kJSTypeBoolean',
kTITypeNull: 'kJSTypeNull',
kTITypeNumber: 'kJSTypeNumber',
kTITypeObject: 'kJSTypeObject',
kTITypeString: 'kJSTypeString',
kTITypeUndefined: 'kJSTypeUndefined',
kTiClassDefinitionEmpty: 'kJSClassDefinitionEmpty',
kTiPropertyAttributeDontDelete: 'kJSPropertyAttributeDontDelete',
kTiPropertyAttributeDontEnum: 'kJSPropertyAttributeDontEnum',
kTiPropertyAttributeNone: 'kJSPropertyAttributeNone',
kTiPropertyAttributeReadOnly: 'kJSPropertyAttributeReadOnly',
};


String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};


var walk = require('walk');
var fs = require('fs');
var files = [];

function getFromFolder(_folder, _callback) {
var walker = walk.walk('./' + _folder, { followLinks: false });

walker.on('file', function(root, stat, next) {
// Add this file to the list of files
files.push(root + '/' + stat.name);
next();
});

walker.on('end', function() {
_callback && _callback();
});
}

getFromFolder('titanium', function() {
getFromFolder('src', function() {
findAndReplace();
});
});


function findAndReplace() {

files.forEach(function(each) {
var content = fs.readFileSync(each).toString();
for (var key in symbols) {
content = content.replaceAll(key, symbols[key]);
}
fs.writeFileSync(each, content)

});

}
20 changes: 3 additions & 17 deletions iphone/src/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,21 @@
*/
#define STR(a) #a

#import <JavaScriptCore/JavaScriptCore.h>

#ifdef TIMODULE
#import "TiBase.h"
#import "KrollCallback.h"
#endif

#define BASECLASS NSObject<HyperloopBase>

#import "TiToJS.h"

#ifdef USE_JSCORE_FRAMEWORK
extern BOOL isIOS9OrGreater();
extern BOOL HLValueIsArray(JSContextRef js_context_ref, JSValueRef js_value_ref);
extern BOOL HLValueIsDate(JSContextRef js_context_ref, JSValueRef js_value_ref);
#else
#define HLValueIsDate TiValueIsDate
#define HLValueIsArray TiValueIsArray
#endif

#define TiObjectMakeConstructor JSObjectMakeConstructor
#define JSObjectMakeConstructor JSObjectMakeConstructor

#ifdef TIMODULE
#ifdef USE_JSCORE_FRAMEWORK
#define TiObjectCallAsConstructor JSObjectCallAsConstructor
#else
TiObjectRef TiObjectCallAsConstructor(TiContextRef ctx, TiObjectRef object, size_t argumentCount, const TiValueRef arguments[], TiValueRef* exception);
#endif
#else
#define TiObjectCallAsConstructor JSObjectCallAsConstructor
#endif

#define RELEASE_AND_CHECK(s) { if (s) { s = nil; } }

Expand Down
7 changes: 2 additions & 5 deletions iphone/src/define.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

#include "define.h"

#ifdef USE_JSCORE_FRAMEWORK
BOOL isIOS9OrGreater() {
return [NSClassFromString(@"UIImage") instancesRespondToSelector:@selector(flipsForRightToLeftLayoutDirection)];;
}

BOOL HLValueIsArray(JSContextRef js_context_ref, JSValueRef js_value_ref) {
if (!TiValueIsObject(js_context_ref, js_value_ref)) return NO;
if (!JSValueIsObject(js_context_ref, js_value_ref)) return NO;
if (isIOS9OrGreater()) return JSValueIsArray(js_context_ref, js_value_ref);
JSStringRef property_name = JSStringCreateWithUTF8CString("Array");
JSObjectRef js_object_ref = (JSObjectRef)JSObjectGetProperty(js_context_ref, JSContextGetGlobalObject(js_context_ref), property_name, NULL);
Expand All @@ -20,15 +19,14 @@ BOOL HLValueIsArray(JSContextRef js_context_ref, JSValueRef js_value_ref) {
return isArray;
}
BOOL HLValueIsDate(JSContextRef js_context_ref, JSValueRef js_value_ref) {
if (!TiValueIsObject(js_context_ref, js_value_ref)) return NO;
if (!JSValueIsObject(js_context_ref, js_value_ref)) return NO;
if (isIOS9OrGreater()) return JSValueIsDate(js_context_ref, js_value_ref);
JSStringRef property_name = JSStringCreateWithUTF8CString("Date");
JSObjectRef js_object_ref = (JSObjectRef)JSObjectGetProperty(js_context_ref, JSContextGetGlobalObject(js_context_ref), property_name, NULL);
JSStringRelease(property_name);
BOOL isDate = JSValueIsInstanceOfConstructor(js_context_ref, js_value_ref, js_object_ref, NULL);
return isDate;
}
#endif

#ifdef HYPERLOOP_MEMORY_TRACKING
static NSMutableDictionary *hashTable;
Expand Down Expand Up @@ -59,5 +57,4 @@ void HyperloopTrackDumpAll() {
}
hashTable = nil;
}

#endif

0 comments on commit fdbf5ac

Please sign in to comment.