Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-25578
Browse files Browse the repository at this point in the history
  • Loading branch information
lokeshchdhry authored Dec 4, 2019
2 parents 36dee0f + 2c8e2ac commit 49c3ba6
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 27 deletions.
1 change: 1 addition & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/ObjcProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ JSExportAs(fireEvent,
@deprecated Only here for backwards compatibility with SDK < 8.1.0. Use `init` instead.
*/
- (id)_initWithPageContext:(id<TiEvaluator>)context __attribute__((deprecated));
- (id)_initWithPageContext:(id<TiEvaluator>)context args:(NSArray *)args __attribute__((deprecated));

// hooks for when an event listener gets added/removed
- (void)_listenerAdded:(NSString *)type count:(int)count;
Expand Down
64 changes: 55 additions & 9 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/ObjcProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ @implementation ObjcProxy
+ (JSValue *)createError:(NSString *)reason subreason:(NSString *)subreason location:(NSString *)location inContext:(JSContext *)context
{
NSString *exceptionName = @"org.appcelerator";
NSDictionary *details = @{
kTiExceptionSubreason : subreason,
kTiExceptionLocation : location
};
NSDictionary *details;
if (subreason != nil) {
details = @{
kTiExceptionSubreason : subreason,
kTiExceptionLocation : location
};
} else {
details = @{
kTiExceptionLocation : location
};
}
NSException *exc = [NSException exceptionWithName:exceptionName reason:reason userInfo:details];
JSGlobalContextRef jsContext = [context JSGlobalContextRef];
JSValueRef jsValueRef = TiBindingTiValueFromNSObject(jsContext, exc);
Expand All @@ -29,10 +36,17 @@ + (JSValue *)createError:(NSString *)reason subreason:(NSString *)subreason loca
- (JSValue *)createError:(NSString *)reason subreason:(NSString *)subreason location:(NSString *)location inContext:(JSContext *)context
{
NSString *exceptionName = [@"org.appcelerator." stringByAppendingString:NSStringFromClass([self class])];
NSDictionary *details = @{
kTiExceptionSubreason : subreason,
kTiExceptionLocation : location
};
NSDictionary *details;
if (subreason != nil) {
details = @{
kTiExceptionSubreason : subreason,
kTiExceptionLocation : location
};
} else {
details = @{
kTiExceptionLocation : location
};
}
NSException *exc = [NSException exceptionWithName:exceptionName reason:reason userInfo:details];
JSGlobalContextRef jsContext = [context JSGlobalContextRef];
JSValueRef jsValueRef = TiBindingTiValueFromNSObject(jsContext, exc);
Expand Down Expand Up @@ -98,6 +112,38 @@ - (id)_initWithPageContext:(id<TiEvaluator>)context
return [self init];
}

- (id)_initWithPageContext:(id<TiEvaluator>)context_ args:(NSArray *)args
{
if (self = [self _initWithPageContext:context_]) {
NSDictionary *a = nil;
NSUInteger count = [args count];
if (count > 0 && [[args objectAtIndex:0] isKindOfClass:[NSDictionary class]]) {
a = [args objectAtIndex:0];
}

// If we're being created by an old proxy/module but we're a new-style obj-c proxy
// we need to handle assigning the properties object passed into the constructor
if (a != nil) {
// Get the JS object corresponding to "this" proxy
// Note that [JSContext currentContext] is nil, so we need to hack and get the global context
// TODO: Can we hack in a nice method that gets current context if available, falls back to global context?
// Because a lot of the code in the proxy base class assumes current context is not nil
KrollContext *krollContext = [context_ krollContext];
JSGlobalContextRef ref = krollContext.context;
JSValueRef jsValueRef = TiBindingTiValueFromNSObject(ref, self);
JSContext *context = [JSContext contextWithJSGlobalContextRef:ref];
JSValue *this = [JSValue valueWithJSValueRef:jsValueRef inContext:context];

// Go through the key/value pairs and set them on "this"
for (NSString *key in a) {
id value = a[key];
this[key] = value;
}
}
}
return self;
}

- (NSURL *)_baseURL
{
return baseURL;
Expand Down Expand Up @@ -206,7 +252,7 @@ - (void)fireEvent:(NSString *)name withDict:(NSDictionary *)dict
// FIXME: looks like we need to handle bubble logic/etc. See other fireEvent impl
for (JSManagedValue *storedCallback in listenersForType) {
JSValue *function = [storedCallback value];
[function callWithArguments:@[ dict ]];
[self _fireEventToListener:name withObject:dict listener:function];
}
}
@finally {
Expand Down
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"ssri": "^7.1.0",
"titanium-docgen": "^0.2.0"
"titanium-docgen": "^4.0.0"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 49c3ba6

Please sign in to comment.