Skip to content

Commit 4096573

Browse files
Supports Social.framework.
1 parent cf5d44e commit 4096573

16 files changed

Lines changed: 221 additions & 33 deletions

File tree

Classes/JSBScriptingSupport.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,13 @@ + (id)require:(NSString *)name
156156

157157
+ (void)dispatch_async:(id)queue block:(JSValue *)function
158158
{
159+
JSContext *context = [JSContext currentContext];
160+
id currentSelf = context[@"self"];
161+
159162
dispatch_block_t block = NULL;
160163
if (!function.isUndefined) {
161164
block = ^() {
162-
[function callWithArguments:nil];
165+
dispatchFunction(currentSelf, function, nil);
163166
};
164167
}
165168

Classes/Private/JSBMessageForwarding.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ void forwardInvocation(id self, SEL _cmd, NSInvocation *invocation)
294294
invokeSuper(invocation);
295295
}
296296

297+
id currentSelf = context[@"self"];
297298
context[@"self"] = self;
298299

299300
NSString *propertyName = propertyNameFromSelector(invocation.selector);
@@ -306,7 +307,7 @@ void forwardInvocation(id self, SEL _cmd, NSInvocation *invocation)
306307
setReturnValue(returnValue, invocation);
307308
}
308309

309-
context[@"self"] = nil;
310+
context[@"self"] = currentSelf;
310311
}
311312

312313
NSMethodSignature *methodSignatureForSelector(id self, SEL _cmd, SEL selector)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// NSURLConnection+JavaScriptBridge.h
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/06.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface NSURLConnection (JavaScriptBridge)
12+
13+
@end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// NSURLConnection+JavaScriptBridge.m
3+
// JavaScriptBridge
4+
//
5+
// Created by kishikawa katsumi on 2014/01/06.
6+
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import "NSURLConnection+JavaScriptBridge.h"
10+
#import "JSBMessageForwarding.h"
11+
12+
@implementation NSURLConnection (JavaScriptBridge)
13+
14+
+ (void)__sendAsynchronousRequest:(NSURLRequest *)request
15+
queue:(NSOperationQueue *)queue
16+
completionHandler:(JSValue *)handlerFunction
17+
{
18+
JSContext *context = [JSContext currentContext];
19+
id currentSelf = context[@"self"];
20+
21+
void(^completionHandler)(NSURLResponse *response , NSData *data , NSError *connectionError) = NULL;
22+
if (!handlerFunction.isUndefined) {
23+
completionHandler = ^(NSURLResponse *response , NSData *data , NSError *connectionError) {
24+
NSMutableArray *parameters = [[NSMutableArray alloc] init];
25+
if (response) {
26+
[parameters addObject:response];
27+
} else {
28+
[parameters addObject:[NSNull null]];
29+
}
30+
if (data) {
31+
[parameters addObject:data];
32+
} else {
33+
[parameters addObject:[NSNull null]];
34+
}
35+
if (connectionError) {
36+
[parameters addObject:connectionError];
37+
} else {
38+
[parameters addObject:[NSNull null]];
39+
}
40+
41+
dispatchFunction(currentSelf, handlerFunction, parameters);
42+
};
43+
}
44+
45+
[self sendAsynchronousRequest:request queue:queue completionHandler:completionHandler];
46+
}
47+
48+
@end

Classes/iOS/FrameworkSupport/Foundation/JSBNSJSONSerialization.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
1212

1313
+ (BOOL)isValidJSONObject:(id)obj;
14-
+ (NSData *)dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error;
15-
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error;
16-
+ (NSInteger)writeJSONObject:(id)obj toStream:(NSOutputStream *)stream options:(NSJSONWritingOptions)opt error:(NSError **)error;
17-
+ (id)JSONObjectWithStream:(NSInputStream *)stream options:(NSJSONReadingOptions)opt error:(NSError **)error;
14+
+ (NSData *)dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(id)error;
15+
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(id)error;
16+
+ (NSInteger)writeJSONObject:(id)obj toStream:(NSOutputStream *)stream options:(NSJSONWritingOptions)opt error:(id)error;
17+
+ (id)JSONObjectWithStream:(NSInputStream *)stream options:(NSJSONReadingOptions)opt error:(id)error;
1818

1919
#pragma clang diagnostic pop
2020

Classes/iOS/FrameworkSupport/Foundation/JSBNSURLConnection.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
+ (NSURLConnection *)connectionWithRequest:(NSURLRequest *)request delegate:(id)delegate;
1414
+ (BOOL)canHandleRequest:(NSURLRequest *)request;
1515
+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error;
16-
+ (void)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue *)queue completionHandler:(void (^)(NSURLResponse *response , NSData *data , NSError *connectionError))handler;
16+
JSExportAs(sendAsynchronousRequestQueueCompletionHandler,
17+
+ (void)__sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue *)queue completionHandler:(JSValue *)handler);
1718

1819
- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate startImmediately:(BOOL)startImmediately;
1920
- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate;

Classes/iOS/FrameworkSupport/Social/JSBSLRequest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
- (void)addMultipartData:(NSData *)data withName:(NSString *)name type:(NSString *)type filename:(NSString *)filename;
2323
- (NSURLRequest *)preparedURLRequest;
24-
JSExportAs(enumerateAssetsUsingBlock,
24+
JSExportAs(performRequestWithHandler,
2525
- (void)__performRequestWithHandler:(JSValue *)handler);
2626

2727
#pragma clang diagnostic pop

Classes/iOS/FrameworkSupport/UIKit/JSBUICollectionViewLayout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
- (void)invalidateLayout;
4040
- (void)invalidateLayoutWithContext:(UICollectionViewLayoutInvalidationContext *)context;
41-
- (void)registerClass:(Class)viewClass forDecorationViewOfKind:(NSString *)decorationViewKind;
41+
- (void)registerClass:(id)viewClass forDecorationViewOfKind:(NSString *)decorationViewKind;
4242
- (void)registerNib:(UINib *)nib forDecorationViewOfKind:(NSString *)decorationViewKind;
4343
- (void)prepareLayout;
4444
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect;

Classes/iOS/FrameworkSupport/UIKit/JSBUITableView.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;
8181
- (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier;
8282
- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier;
83-
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier;
83+
- (void)registerClass:(id)cellClass forCellReuseIdentifier:(NSString *)identifier;
8484
- (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier;
85-
- (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier;
85+
- (void)registerClass:(id)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier;
8686

8787
#pragma clang diagnostic pop
8888

Examples/HelloWorld/HelloWorld.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
149A460C1879730A007C2CA7 /* SLComposeViewController+JavaScriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 149A46091879730A007C2CA7 /* SLComposeViewController+JavaScriptBridge.m */; };
1515
149A460D1879730A007C2CA7 /* SLRequest+JavaScriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 149A460B1879730A007C2CA7 /* SLRequest+JavaScriptBridge.m */; };
1616
149A4619187984E8007C2CA7 /* ACAccountStore+JavaScriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 149A4618187984E8007C2CA7 /* ACAccountStore+JavaScriptBridge.m */; };
17+
149A46231879B4A6007C2CA7 /* NSURLConnection+JavaScriptBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 149A46221879B4A6007C2CA7 /* NSURLConnection+JavaScriptBridge.m */; };
1718
14A0452D18782920004831E8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 14A0452C18782920004831E8 /* Foundation.framework */; };
1819
14A0452F18782920004831E8 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 14A0452E18782920004831E8 /* CoreGraphics.framework */; };
1920
14A0453118782920004831E8 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 14A0453018782920004831E8 /* UIKit.framework */; };
@@ -71,6 +72,8 @@
7172
149A460B1879730A007C2CA7 /* SLRequest+JavaScriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SLRequest+JavaScriptBridge.m"; sourceTree = "<group>"; };
7273
149A4617187984E8007C2CA7 /* ACAccountStore+JavaScriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ACAccountStore+JavaScriptBridge.h"; sourceTree = "<group>"; };
7374
149A4618187984E8007C2CA7 /* ACAccountStore+JavaScriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ACAccountStore+JavaScriptBridge.m"; sourceTree = "<group>"; };
75+
149A46211879B4A6007C2CA7 /* NSURLConnection+JavaScriptBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURLConnection+JavaScriptBridge.h"; sourceTree = "<group>"; };
76+
149A46221879B4A6007C2CA7 /* NSURLConnection+JavaScriptBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURLConnection+JavaScriptBridge.m"; sourceTree = "<group>"; };
7477
14A0452918782920004831E8 /* HelloWorld.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloWorld.app; sourceTree = BUILT_PRODUCTS_DIR; };
7578
14A0452C18782920004831E8 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
7679
14A0452E18782920004831E8 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
@@ -859,6 +862,8 @@
859862
children = (
860863
14A0455E187829B4004831E8 /* JSBMessageForwarding.h */,
861864
149A45EF18796C5D007C2CA7 /* JSBMessageForwarding.m */,
865+
149A46211879B4A6007C2CA7 /* NSURLConnection+JavaScriptBridge.h */,
866+
149A46221879B4A6007C2CA7 /* NSURLConnection+JavaScriptBridge.m */,
862867
14A0455F187829B4004831E8 /* UIControl+JavaScriptBridge.h */,
863868
14A04560187829B4004831E8 /* UIControl+JavaScriptBridge.m */,
864869
149A4617187984E8007C2CA7 /* ACAccountStore+JavaScriptBridge.h */,
@@ -1877,6 +1882,7 @@
18771882
14A04830187829CB004831E8 /* JSBCoreData.m in Sources */,
18781883
14A0483D187829CB004831E8 /* JSBMessageUI.m in Sources */,
18791884
14A04846187829CB004831E8 /* JSBTwitter.m in Sources */,
1885+
149A46231879B4A6007C2CA7 /* NSURLConnection+JavaScriptBridge.m in Sources */,
18801886
14A0482E187829CB004831E8 /* JSBAssetsLibrary.m in Sources */,
18811887
14A0482C187829CB004831E8 /* JSBAdSupport.m in Sources */,
18821888
149A45F018796C5D007C2CA7 /* JSBMessageForwarding.m in Sources */,

0 commit comments

Comments
 (0)