forked from kishikawakatsumi/JavaScriptBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSContext+JavaScriptBridge.m
More file actions
48 lines (37 loc) · 1.57 KB
/
JSContext+JavaScriptBridge.m
File metadata and controls
48 lines (37 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// JSContext+JavaScriptBridge.m
// JavaScriptBridge
//
// Created by kishikawa katsumi on 2014/01/04.
// Copyright (c) 2014 kishikawa katsumi. All rights reserved.
//
#import "JSContext+JavaScriptBridge.h"
#import "JSBScriptingSupport+Private.h"
@implementation JSContext (JavaScriptBridge)
- (void)addScriptingSupport:(NSString *)framework
{
[JSBScriptingSupport setupSupportFunctionsToContext:self];
static NSMapTable *hashTables;
if (!hashTables) {
hashTables = [NSMapTable mapTableWithKeyOptions:NSPointerFunctionsWeakMemory valueOptions:NSPointerFunctionsWeakMemory];
}
NSHashTable *frameworks = [hashTables objectForKey:self];
if (!frameworks) {
frameworks = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory];
[hashTables setObject:frameworks forKey:self];
}
NSString *prefix = @"JSB";
id classObject = NSClassFromString([NSString stringWithFormat:@"%@%@", prefix, framework]);
if (classObject && ![frameworks containsObject:framework]) {
SEL selector = NSSelectorFromString(@"addScriptingSupportToContext:");
NSMethodSignature *methodSignature = [classObject methodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
invocation.target = classObject;
invocation.selector = selector;
JSContext *context = self;
[invocation setArgument:&context atIndex:2];
[invocation invoke];
[frameworks addObject:framework];
}
}
@end