Skip to content

Commit

Permalink
Resolve more merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Jul 30, 2018
1 parent d52c52f commit 2fa56c5
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 3 deletions.
2 changes: 1 addition & 1 deletion iphone/Classes/TiUIWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#ifdef USE_TI_UIWEBVIEW

#import "TiUIWebView.h"
#import "TiExceptionHandler.h"
#import "TiUIWebViewProxy.h"
#import <TitaniumKit/Mimetypes.h>
#import <TitaniumKit/TiApp.h>
#import <TitaniumKit/TiBlob.h>
#import <TitaniumKit/TiExceptionHandler.h>
#import <TitaniumKit/TiFile.h>
#import <TitaniumKit/TiHost.h>
#import <TitaniumKit/TiProxy.h>
Expand Down
12 changes: 10 additions & 2 deletions iphone/TitaniumKit/TitaniumKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
DB15FC811F0A855F00A82C45 /* UIImage+Resize.h in Headers */ = {isa = PBXBuildFile; fileRef = DB15FC7D1F0A855F00A82C45 /* UIImage+Resize.h */; settings = {ATTRIBUTES = (Public, ); }; };
DB15FC821F0A855F00A82C45 /* UIImage+Resize.m in Sources */ = {isa = PBXBuildFile; fileRef = DB15FC7E1F0A855F00A82C45 /* UIImage+Resize.m */; };
DB15FC841F0A857E00A82C45 /* TiControllerProtocols.h in Headers */ = {isa = PBXBuildFile; fileRef = DB15FC831F0A857E00A82C45 /* TiControllerProtocols.h */; settings = {ATTRIBUTES = (Public, ); }; };
DB15FC891F0A859800A82C45 /* TiExceptionHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = DB15FC851F0A859700A82C45 /* TiExceptionHandler.h */; };
DB15FC891F0A859800A82C45 /* TiExceptionHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = DB15FC851F0A859700A82C45 /* TiExceptionHandler.h */; settings = {ATTRIBUTES = (Public, ); }; };
DB15FC8A1F0A859800A82C45 /* TiExceptionHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = DB15FC861F0A859700A82C45 /* TiExceptionHandler.m */; };
DB15FC8B1F0A859800A82C45 /* UIImage+RoundedCorner.h in Headers */ = {isa = PBXBuildFile; fileRef = DB15FC871F0A859700A82C45 /* UIImage+RoundedCorner.h */; settings = {ATTRIBUTES = (Public, ); }; };
DB15FC8C1F0A859800A82C45 /* UIImage+RoundedCorner.m in Sources */ = {isa = PBXBuildFile; fileRef = DB15FC881F0A859700A82C45 /* UIImage+RoundedCorner.m */; };
Expand Down Expand Up @@ -174,6 +174,8 @@
DB3908692075228900AE31EC /* APSHTTPHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = DB3908632075228900AE31EC /* APSHTTPHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
DB39086A2075228900AE31EC /* APSHTTPPostForm.h in Headers */ = {isa = PBXBuildFile; fileRef = DB3908642075228900AE31EC /* APSHTTPPostForm.h */; settings = {ATTRIBUTES = (Public, ); }; };
DB5813E72075FCF200CA1437 /* TiDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = DB5813E62075FCF200CA1437 /* TiDefines.h */; settings = {ATTRIBUTES = (Public, ); }; };
DBE66A36210F92FD00095F1E /* KrollWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = DBE66A34210F92FD00095F1E /* KrollWrapper.h */; settings = {ATTRIBUTES = (Public, ); }; };
DBE66A37210F92FD00095F1E /* KrollWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = DBE66A35210F92FD00095F1E /* KrollWrapper.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -334,6 +336,8 @@
DB5813E92075FDF600CA1437 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
DBA197501F0C20E300B12D31 /* libAPSAnalytics.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libAPSAnalytics.a; path = TitaniumKit/Libraries/APSAnalytics/libAPSAnalytics.a; sourceTree = "<group>"; };
DBA197511F0C20E300B12D31 /* libAPSHTTPClient.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libAPSHTTPClient.a; path = TitaniumKit/Libraries/APSHTTPClient/libAPSHTTPClient.a; sourceTree = "<group>"; };
DBE66A34210F92FD00095F1E /* KrollWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KrollWrapper.h; sourceTree = "<group>"; };
DBE66A35210F92FD00095F1E /* KrollWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KrollWrapper.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -431,6 +435,8 @@
DB15FC301F0A833100A82C45 /* KrollPropertyDelegate.m */,
DB15FC311F0A833100A82C45 /* KrollTimer.h */,
DB15FC321F0A833100A82C45 /* KrollTimer.m */,
DBE66A34210F92FD00095F1E /* KrollWrapper.h */,
DBE66A35210F92FD00095F1E /* KrollWrapper.m */,
);
name = Kroll;
path = Sources/Kroll;
Expand Down Expand Up @@ -615,6 +621,7 @@
files = (
DB3908652075228900AE31EC /* APSAnalytics.h in Headers */,
DB15FCAC1F0A86D400A82C45 /* TiLogServer.h in Headers */,
DBE66A36210F92FD00095F1E /* KrollWrapper.h in Headers */,
DB3908682075228900AE31EC /* APSHTTPClient.h in Headers */,
DB15FBF41F0A80FA00A82C45 /* TiPublicAPI.h in Headers */,
DB15FC6F1F0A84FD00A82C45 /* TiBlob.h in Headers */,
Expand Down Expand Up @@ -683,8 +690,8 @@
DB24E0502076824C0033B2B1 /* TiSharedConfig.h in Headers */,
DB15FC3D1F0A833100A82C45 /* KrollObject.h in Headers */,
DB15FCA81F0A866300A82C45 /* TiRect.h in Headers */,
DB15FD281F0A93A900A82C45 /* TiFilesystemFileStreamProxy.h in Headers */,
DB15FC891F0A859800A82C45 /* TiExceptionHandler.h in Headers */,
DB15FD281F0A93A900A82C45 /* TiFilesystemFileStreamProxy.h in Headers */,
DB15FCB81F0A874F00A82C45 /* TopTiModule.h in Headers */,
DB15FC3B1F0A833100A82C45 /* KrollMethodDelegate.h in Headers */,
DB15FC391F0A833100A82C45 /* KrollMethod.h in Headers */,
Expand Down Expand Up @@ -819,6 +826,7 @@
DB15FD071F0A892500A82C45 /* Ti2DMatrix.m in Sources */,
DB15FC3E1F0A833100A82C45 /* KrollObject.m in Sources */,
DB15FC421F0A833100A82C45 /* KrollTimer.m in Sources */,
DBE66A37210F92FD00095F1E /* KrollWrapper.m in Sources */,
DB1596592075389000292B19 /* APIModule.m in Sources */,
DB258D641F097680000D0D8D /* KrollBridge.m in Sources */,
DB15FD2D1F0A93EF00A82C45 /* TiStreamProxy.m in Sources */,
Expand Down
55 changes: 55 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/Kroll/KrollWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2018 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#import "KrollContext.h"
#import <Foundation/Foundation.h>

@class KrollBridge;

/*
* For functions and other objects that need to be held by proxies without
* conversion or possible retain cycles, KrollWrapper passively refers to a
* JS Object. In the future, this should become the base class, instead of a
* collection of Kroll wrappers all based off of NSObject despite common
* functionality.
*
* 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)
* 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
* be first-class JS object citizens.
* TODO: Consolidate various KrollObjects, KrollCallbacks, etc to be
* KrollWrappers.
*/
@interface KrollWrapper : NSObject {
JSObjectRef jsobject;
KrollBridge *bridge;
BOOL protecting;
}

// Access the native JSCore object
@property (nonatomic, readwrite, assign) JSObjectRef jsobject;

// Access the kroll bridge (e.g. for the kroll context)
@property (nonatomic, readwrite, assign) KrollBridge *bridge;

// Protects a JSObject from being GC'd
- (void)protectJsobject;

// Unprotects a JSObject from being GC'd
- (void)unprotectJsobject;

// Replaces a value for a given key in it's underlaying JSContext
- (void)replaceValue:(id)value forKey:(NSString *)key notification:(BOOL)notify;

// Executes an async JavaScript function and returns the resulting JSCore value if any
- (JSValueRef)executeWithArguments:(NSArray<id> *)arguments;

@end
110 changes: 110 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/Kroll/KrollWrapper.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2018 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#import "KrollWrapper.h"
#import "KrollBridge.h"
#import "KrollCallback.h"
#import "KrollObject.h"
#import "TiExceptionHandler.h"

@implementation KrollWrapper
@synthesize jsobject, bridge;

/* NOTE:
* Until KrollWrapper takes a more expanded role as a general purpose wrapper,
* protectJsobject is to be used during commonJS inclusion ONLY.
* For example, KrollBridge ensures that this is only done in the JS thread,
* and unlike KrollObject, KrollWrapper does not have the infrastructure to
* handle being called outside the JS.
* Furthermore, KrollWrapper does not get notified of JSObject finalization,
* etc, etc. The specific cases where KrollWrapper is currently used do not
* make this an issue, but KrollWrapper needs hardening if it is to be a base
* class.
*/

- (void)dealloc
{
if (protecting) {
[self unprotectJsobject];
}
[super dealloc];
}

- (void)protectJsobject
{
if (protecting || ![KrollBridge krollBridgeExists:bridge]) {
return;
}

if (![[bridge krollContext] isKJSThread]) {
DeveloperLog(@"[WARN] KrollWrapper trying to protect in the wrong thread.%@", CODELOCATION);
return;
}
protecting = YES;
JSValueProtect([[bridge krollContext] context], jsobject);
}

- (void)unprotectJsobject
{
if (!protecting || ![KrollBridge krollBridgeExists:bridge]) {
return;
}

if (![[bridge krollContext] isKJSThread]) {
DeveloperLog(@"[WARN] KrollWrapper trying to unprotect in the wrong thread.%@", CODELOCATION);
return;
}
protecting = NO;
JSValueUnprotect([[bridge krollContext] context], jsobject);
}

- (void)replaceValue:(id)value forKey:(NSString *)key notification:(BOOL)notify
{ /*
* This is to be used ONLY from KrollBridge's require call, due to some
* JS files assigning exports to a function instead of a standard
* JS object.
*/
KrollContext *context = [bridge krollContext];
JSValueRef valueRef = [KrollObject toValue:context value:value];

/*
* Properties can only be added to objects
*/
if (JSValueIsObject([context context], jsobject)) {
JSStringRef keyRef = JSStringCreateWithCFString((CFStringRef)key);
JSObjectSetProperty([context context], jsobject, keyRef, valueRef, kJSPropertyAttributeReadOnly, NULL);
JSStringRelease(keyRef);
}
}

- (JSValueRef)executeWithArguments:(NSArray<id> *)arguments
{
if (![KrollBridge krollBridgeExists:[self bridge]]) {
return NULL;
}

JSObjectRef value = [self jsobject];
JSContextRef context = [self.bridge.krollContext context];

JSValueRef callException = NULL;
JSValueRef callArgs[arguments.count];

for (NSUInteger i = 0; i < arguments.count; i++) {
callArgs[i] = [KrollObject toValue:self.bridge.krollContext value:[arguments objectAtIndex:i]];
}

JSValueRef functionResult = JSObjectCallAsFunction(context, value, NULL, 1, callArgs, &callException);

if (callException != NULL) {
id exceptionPayload = [KrollObject toID:self.bridge.krollContext value:callException];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:exceptionPayload]];
}

return functionResult;
}

@end
1 change: 1 addition & 0 deletions iphone/TitaniumKit/TitaniumKit/TitaniumKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ FOUNDATION_EXPORT const unsigned char TitaniumKitVersionString[];
#import <TitaniumKit/TiColor.h>
#import <TitaniumKit/TiComplexValue.h>
#import <TitaniumKit/TiDefines.h>
#import <TitaniumKit/TiExceptionHandler.h>
#import <TitaniumKit/TiFilesystemFileProxy.h>
#import <TitaniumKit/TiFilesystemFileStreamProxy.h>
#import <TitaniumKit/TiLayoutQueue.h>
Expand Down

0 comments on commit 2fa56c5

Please sign in to comment.