/
KrollBridge.m
665 lines (568 loc) Β· 21.1 KB
/
KrollBridge.m
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
/**
* Titanium SDK
* Copyright TiDev, Inc. 04/07/2022-Present. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#import "KrollBridge.h"
#import "APSAnalytics.h"
#import "AssetsModule.h"
#import "JSValue+Addons.h"
#import "KrollCallback.h"
#import "KrollModule.h"
#import "TiApp.h"
#import "TiExceptionHandler.h"
#import "TiHost.h"
#import "TiSharedConfig.h"
#import "TiUtils.h"
#import "TopTiModule.h"
#ifndef TI_USE_NATIVE
#define TI_USE_NATIVE 0
#endif
NSString *TitaniumModuleRequireFormat = @"(function(exports){"
"var __OXP=exports;var module={'exports':exports,'paths':[]};var __dirname=\"%@\";var __filename=\"%@\";%@;\n"
"if(module.exports !== __OXP){return module.exports;}"
"return exports;})({})";
// Defined private method inside TiBindingRunLoop.m (Perhaps to move to .c?)
void TiBindingRunLoopAnnounceStart(TiBindingRunLoop runLoop);
os_unfair_lock krollBridgeRegistryLock = OS_UNFAIR_LOCK_INIT;
CFMutableSetRef krollBridgeRegistry = nil;
@implementation KrollBridge
+ (void)initialize
{
if (krollBridgeRegistry == nil) {
CFSetCallBacks doNotRetain = kCFTypeSetCallBacks;
doNotRetain.retain = NULL;
doNotRetain.release = NULL;
krollBridgeRegistry = CFSetCreateMutable(NULL, 3, &doNotRetain);
}
}
@synthesize currentURL;
- (void)registerForMemoryWarning
{
WARN_IF_BACKGROUND_THREAD_OBJ; // NSNotificationCenter is not threadsafe!
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveMemoryWarning:)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
}
- (void)unregisterForMemoryWarning
{
WARN_IF_BACKGROUND_THREAD_OBJ; // NSNotificationCenter is not threadsafe!
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
}
- (id)init
{
if (self = [super init]) {
#if KROLLBRIDGE_MEMORY_DEBUG == 1
NSLog(@"[DEBUG] INIT: %@", self);
#endif
proxyLock = OS_UNFAIR_LOCK_INIT;
os_unfair_lock_lock(&krollBridgeRegistryLock);
CFSetAddValue(krollBridgeRegistry, self);
os_unfair_lock_unlock(&krollBridgeRegistryLock);
TiThreadPerformOnMainThread(
^{
[self registerForMemoryWarning];
},
NO);
}
return self;
}
- (void)didReceiveMemoryWarning:(NSNotification *)notification
{
os_unfair_lock_lock(&proxyLock);
if (registeredProxies == NULL) {
os_unfair_lock_unlock(&proxyLock);
[self gc];
return;
}
BOOL keepWarning = YES;
signed long proxiesCount = CFDictionaryGetCount(registeredProxies);
os_unfair_lock_unlock(&proxyLock);
// During a memory panic, we may not get the chance to copy proxies.
while (keepWarning) {
keepWarning = NO;
for (id proxy in [(NSDictionary *)registeredProxies allKeys]) {
[proxy didReceiveMemoryWarning:notification];
os_unfair_lock_lock(&proxyLock);
if (registeredProxies == NULL) {
os_unfair_lock_unlock(&proxyLock);
break;
}
signed long newCount = CFDictionaryGetCount(registeredProxies);
os_unfair_lock_unlock(&proxyLock);
if (newCount != proxiesCount) {
proxiesCount = newCount;
keepWarning = YES;
break;
}
}
}
[self gc];
}
#if KROLLBRIDGE_MEMORY_DEBUG == 1
- (id)retain
{
NSLog(@"[MEMORY DEBUG] RETAIN: %@ (%d)", self, [self retainCount] + 1);
return [super retain];
}
- (oneway void)release
{
NSLog(@"[MEMORY DEBUG] RELEASE: %@ (%d)", self, [self retainCount] - 1);
[super release];
}
#endif
- (void)removeProxies
{
os_unfair_lock_lock(&proxyLock);
CFDictionaryRef oldProxies = registeredProxies;
registeredProxies = NULL;
os_unfair_lock_unlock(&proxyLock);
for (id thisProxy in (NSDictionary *)oldProxies) {
KrollObject *thisKrollObject = (id)CFDictionaryGetValue(oldProxies, thisProxy);
[thisProxy contextShutdown:self];
[thisKrollObject unprotectJsobject];
}
if (oldProxies != NULL) {
CFRelease(oldProxies);
}
}
- (void)dealloc
{
#if KROLLBRIDGE_MEMORY_DEBUG == 1
NSLog(@"[MEMORY DEBUG] DEALLOC: %@", self);
#endif
[self removeProxies];
RELEASE_TO_NIL(preload);
RELEASE_TO_NIL(context);
os_unfair_lock_lock(&krollBridgeRegistryLock);
CFSetRemoveValue(krollBridgeRegistry, self);
os_unfair_lock_unlock(&krollBridgeRegistryLock);
[super dealloc];
}
- (TiHost *)host
{
return host;
}
- (KrollContext *)krollContext
{
return context;
}
- (id)preloadForKey:(id)key name:(id)name
{
if (preload != nil) {
NSDictionary *dict = [preload objectForKey:name];
if (dict != nil) {
return [dict objectForKey:key];
}
}
return nil;
}
- (void)boot:(id)callback url:(NSURL *)url_ preload:(NSDictionary *)preload_
{
preload = [preload_ retain];
[super boot:callback url:url_ preload:preload_];
context = [[KrollContext alloc] init];
context.delegate = self;
[context start];
}
- (void)evalJSWithoutResult:(NSString *)code
{
[context evalJS:code];
}
// NOTE: this must only be called on the JS thread or an exception will be raised
- (id)evalJSAndWait:(NSString *)code
{
return [context evalJSAndWait:code];
}
- (BOOL)evaluationError
{
return evaluationError;
}
- (void)setEvaluationError:(BOOL)value
{
evaluationError = value;
}
- (void)evalFileOnThread:(NSString *)path context:(KrollContext *)context_
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *url_ = [path hasPrefix:@"file:"] ? [NSURL URLWithString:path] : [NSURL fileURLWithPath:path];
if (![path hasPrefix:@"/"] && ![path hasPrefix:@"file:"]) {
url_ = [NSURL URLWithString:path relativeToURL:url];
}
NSString *jcode = [AssetsModule readURL:url_];
if (jcode == nil) {
NSLog(@"[ERROR] Error loading path: %@", path);
evaluationError = YES;
TiScriptError *scriptError = [[TiScriptError alloc] initWithMessage:[NSString stringWithFormat:@"Error loading script %@.", [path lastPathComponent]] sourceURL:nil lineNo:0];
[TiExceptionHandler.defaultExceptionHandler reportScriptError:scriptError];
[scriptError release];
return;
}
// When we run a file as the entry point of the app or a service:
// we bootstrap, then Module.runModule(source, filename, service)
JSGlobalContextRef jsContext = context_.context;
JSContext *objCContext = [JSContext contextWithJSGlobalContextRef:jsContext];
JSValue *moduleGlobal = objCContext.globalObject[@"Module"];
// make the path relative to the resources Dir!
NSString *relativePath = [TiHost resourceRelativePath:url_];
// FIXME: If the entry point is a service, we should pass that in here as last arg instead of null!
[moduleGlobal invokeMethod:@"runModule" withArguments:@[ jcode, relativePath, [NSNull null] ]];
if (objCContext.exception != nil) {
evaluationError = YES;
[TiExceptionHandler.defaultExceptionHandler reportScriptError:objCContext.exception inJSContext:objCContext];
}
[pool release];
}
- (void)evalFile:(NSString *)path callback:(id)callback selector:(SEL)selector
{
[context invokeOnThread:self method:@selector(evalFileOnThread:context:) withObject:path callback:callback selector:selector];
}
- (void)evalFile:(NSString *)file
{
[context invokeOnThread:self method:@selector(evalFileOnThread:context:) withObject:file condition:nil];
}
- (void)fireEvent:(id)listener withObject:(id)obj remove:(BOOL)yn thisObject:(TiProxy *)thisObject_
{
if (![listener isKindOfClass:[KrollCallback class]]) {
DebugLog(@"[ERROR] Listener callback is of a non-supported type: %@", [listener class]);
return;
}
KrollEvent *event = [[KrollEvent alloc] initWithCallback:listener eventObject:obj thisObject:thisObject_];
[context enqueue:event];
[event release];
}
- (void)enqueueEvent:(NSString *)type forProxy:(TiProxy *)proxy withObject:(id)obj
{
KrollObject *eventKrollObject = [self krollObjectForProxy:proxy];
KrollEvent *newEvent = [[KrollEvent alloc]
initWithType:type
ForKrollObject:eventKrollObject
eventObject:obj
thisObject:eventKrollObject];
[context enqueue:newEvent];
[newEvent release];
}
- (void)shutdown:(NSCondition *)condition
{
#if KROLLBRIDGE_MEMORY_DEBUG == 1
NSLog(@"[MEMORY DEBUG] DESTROY: %@", self);
#endif
if (!shutdown) {
shutdownCondition = [condition retain];
shutdown = YES;
// fire a notification event to our listeners
WARN_IF_BACKGROUND_THREAD_OBJ; // NSNotificationCenter is not threadsafe!
NSNotification *notification = [NSNotification notificationWithName:kTiContextShutdownNotification object:self];
[[NSNotificationCenter defaultCenter] postNotification:notification];
[context stop];
} else {
[condition lock];
[condition signal];
[condition unlock];
}
}
- (void)gc
{
[context gc];
}
#pragma mark Delegate
- (void)willStartNewContext:(KrollContext *)kroll
{
if (TiUtils.isHyperloopAvailable) {
Class cls = NSClassFromString(@"Hyperloop");
[cls performSelector:@selector(willStartNewContext:bridge:) withObject:kroll withObject:self];
}
[self retain]; // Hold onto ourselves as long as the context needs us
}
- (void)didStartNewContext:(KrollContext *)kroll
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
JSGlobalContextRef jsContext = kroll.context;
JSContext *objcJSContext = [JSContext contextWithJSGlobalContextRef:jsContext];
JSValue *global = [objcJSContext globalObject];
// TODO: Move to real paths for __dirname/__filename, but that affects Android and may break users/debugging?
// NSString *dirname = [[TiHost resourcePath] stringByStandardizingPath];
// Set the __dirname and __filename for the app.js.
// For other files, it will be injected via require
[global defineReadOnlyProperty:@"__dirname" withValue:@"/"];
// NSString *filename = [dirname stringByAppendingString:@"/ti.kernel.js"];
[global defineReadOnlyProperty:@"__filename" withValue:@"/ti.kernel.js"];
// Load ti.kernel.js (kroll.js equivalent)
NSURL *bootstrapURL = [TiHost resourceBasedURL:@"ti.kernel.js" baseURL:NULL];
NSString *source = [AssetsModule readURL:bootstrapURL];
if (source == nil || source.length == 0) {
NSLog(@"[ERROR] Error reading ti.kernel.js, source is nil/empty. Most likely due to failure to decrypt via remote policy and device offline.");
evaluationError = YES;
// Don't put up a dialog, as the most likely cause here is remote policy encryption/decryption failing to decrypt due to being offline.
// And if we have a dialog up, the security violation dialog won't appear
} else {
JSValue *bootstrapFunc = [objcJSContext evaluateScript:source withSourceURL:bootstrapURL];
if (objcJSContext.exception != nil) {
NSLog(@"[ERROR] Error eval'ing ti.kernel.js bootstrap script. Please contact Titanium developers and file a bug report.");
evaluationError = YES;
[TiExceptionHandler.defaultExceptionHandler reportScriptError:objcJSContext.exception inJSContext:objcJSContext];
} else if (bootstrapFunc == nil || [bootstrapFunc isUndefined]) {
// it didn't export a bootstrap function! Most likely reason is we hosed the file
NSLog(@"[ERROR] Error eval'ing ti.kernel.js, bootstrap function is undefined/nil. Please contact Titanium developers and file a bug report.");
evaluationError = YES;
[TiExceptionHandler.defaultExceptionHandler reportScriptError:objcJSContext.exception inJSContext:objcJSContext];
} else {
// ti.kernel.js eval'd OK, so now let's run the exported bootstrap function
[bootstrapFunc callWithArguments:@[ global, [[KrollModule alloc] init] ]];
if (objcJSContext.exception != nil) {
NSLog(@"[ERROR] Error calling ti.kernel.js' exported bootstrap function. Please contact Titanium developers and file a bug report.");
evaluationError = YES;
[TiExceptionHandler.defaultExceptionHandler reportScriptError:objcJSContext.exception inJSContext:objcJSContext];
}
}
}
JSValue *titanium = global[@"Ti"]; // This may be nil/undefined it we couldn't load ti.kernel.js or the bootstrapping failed
if (TiSharedConfig.defaultConfig.isAnalyticsEnabled) {
// TODO: Remove this unused statement once we can fully remove APSAnalytics
// Right now, the build would fail is we fully remove it
APSAnalytics *sharedAnalytics = APSAnalytics.sharedInstance;
}
NSURL *startURL = nil;
// if we have a preload dictionary, register those static key/values into our namespace
if (preload != nil) {
// Guard for top level Titanium object being unassigned. likley means we had issues
// setting up ti.kernel.js, so we likely need to skip most everything here.
if (titanium != nil && ![titanium isUndefined]) {
for (NSString *name in preload) {
JSValue *moduleJSObject = titanium[name];
KrollObject *ti = (KrollObject *)JSObjectGetPrivate(JSValueToObject(jsContext, moduleJSObject.JSValueRef, NULL));
NSDictionary *values = preload[name];
for (id key in values) {
id target = values[key];
KrollObject *ko = [self krollObjectForProxy:target];
if (ko == nil) {
ko = [self registerProxy:target];
}
[ti noteKrollObject:ko forKey:key];
[ti setStaticValue:ko forKey:key purgable:NO];
}
}
}
startURL = [url copy]; // should be the entry point of the background service js file
} else {
startURL = [host startURL]; // should be ti.main.js
}
// We need to run this before the entry js file, which means it has to be here.
TiBindingRunLoopAnnounceStart(kroll);
if (!evaluationError) {
[self evalFile:[startURL absoluteString] callback:self selector:@selector(booted)];
} else {
NSLog(@"[ERROR] Error loading/executing ti.kernel.js bootstrap code, refusing to launch app main file.");
// DO NOT POP AN ERROR DIALOG! The most likley scenario here is that the app is remotely encrypted
// and the decryption failed because the device is offline
// If we pop a dialog here, it will block the "Security Violation" error dialog that would show in that case
}
if (TiUtils.isHyperloopAvailable) {
Class cls = NSClassFromString(@"Hyperloop");
[cls performSelector:@selector(didStartNewContext:bridge:) withObject:kroll withObject:self];
}
[pool release];
}
- (void)willStopNewContext:(KrollContext *)kroll
{
if (TiUtils.isHyperloopAvailable) {
Class cls = NSClassFromString(@"Hyperloop");
[cls performSelector:@selector(willStopNewContext:bridge:) withObject:kroll withObject:self];
}
if (!shutdown) {
shutdown = YES;
// fire a notification event to our listeners
WARN_IF_BACKGROUND_THREAD_OBJ; // NSNotificationCenter is not threadsafe!
NSNotification *notification = [NSNotification notificationWithName:kTiContextShutdownNotification object:self];
[[NSNotificationCenter defaultCenter] postNotification:notification];
}
if (shutdownCondition) {
[shutdownCondition lock];
[shutdownCondition signal];
[shutdownCondition unlock];
RELEASE_TO_NIL(shutdownCondition);
}
}
- (void)didStopNewContext:(KrollContext *)kroll
{
TiThreadPerformOnMainThread(
^{
[self unregisterForMemoryWarning];
},
NO);
[self removeProxies];
RELEASE_TO_NIL(context);
RELEASE_TO_NIL(preload);
if (TiUtils.isHyperloopAvailable) {
Class cls = NSClassFromString(@"Hyperloop");
[cls performSelector:@selector(didStopNewContext:bridge:) withObject:kroll withObject:self];
}
[self autorelease]; // Safe to release now that the context is done
}
- (void)registerProxy:(id)proxy krollObject:(KrollObject *)ourKrollObject
{
os_unfair_lock_lock(&proxyLock);
if (registeredProxies == NULL) {
registeredProxies = CFDictionaryCreateMutable(NULL, 10, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}
// NOTE: Do NOT treat registeredProxies like a mutableDictionary; mutable dictionaries copy keys,
// CFMutableDictionaryRefs only retain keys, which lets them work with proxies properly.
CFDictionaryAddValue(registeredProxies, proxy, ourKrollObject);
os_unfair_lock_unlock(&proxyLock);
[proxy boundBridge:self withKrollObject:ourKrollObject];
}
- (id)registerProxy:(id)proxy
{
KrollObject *ourKrollObject = [self krollObjectForProxy:proxy];
if (ourKrollObject != nil) {
return ourKrollObject;
}
if (![context isKJSThread]) {
return nil;
}
ourKrollObject = [[KrollObject alloc] initWithTarget:proxy context:context];
[ourKrollObject applyGarbageCollectionSafeguard];
[self registerProxy:proxy
krollObject:ourKrollObject];
return [ourKrollObject autorelease];
}
- (void)unregisterProxy:(id)proxy
{
os_unfair_lock_lock(&proxyLock);
if (registeredProxies != NULL) {
CFDictionaryRemoveValue(registeredProxies, proxy);
// Don't bother with removing the empty registry. It's small and leaves on dealloc anyways.
}
os_unfair_lock_unlock(&proxyLock);
[proxy unboundBridge:self];
}
- (BOOL)usesProxy:(id)proxy
{
if (proxy == nil) {
return NO;
}
BOOL result = NO;
os_unfair_lock_lock(&proxyLock);
if (registeredProxies != NULL) {
result = (CFDictionaryGetCountOfKey(registeredProxies, proxy) != 0);
}
os_unfair_lock_unlock(&proxyLock);
return result;
}
- (id)krollObjectForProxy:(id)proxy
{
id result = nil;
os_unfair_lock_lock(&proxyLock);
if (registeredProxies != NULL) {
result = (id)CFDictionaryGetValue(registeredProxies, proxy);
}
os_unfair_lock_unlock(&proxyLock);
return result;
}
- (id)require:(KrollContext *)kroll path:(NSString *)path
{
if (!kroll || !path) {
return nil;
}
JSContext *jsContext = [JSContext contextWithJSGlobalContextRef:kroll.context];
JSValue *jsResult = [jsContext.globalObject invokeMethod:@"require" withArguments:@[ path ]];
if (![jsResult isObject]) {
return nil;
}
KrollWrapper *krollResult = [[KrollWrapper alloc] init];
[krollResult setBridge:self];
[krollResult setJsobject:(JSObjectRef)[jsResult JSValueRef]];
[krollResult protectJsobject];
return [krollResult autorelease];
}
+ (NSArray *)krollBridgesUsingProxy:(id)proxy
{
NSMutableArray *results = nil;
os_unfair_lock_lock(&krollBridgeRegistryLock);
signed long bridgeCount = CFSetGetCount(krollBridgeRegistry);
KrollBridge *registryObjects[bridgeCount];
CFSetGetValues(krollBridgeRegistry, (const void **)registryObjects);
for (int currentBridgeIndex = 0; currentBridgeIndex < bridgeCount; currentBridgeIndex++) {
KrollBridge *currentBridge = registryObjects[currentBridgeIndex];
if (![currentBridge usesProxy:proxy]) {
continue;
}
if (results == nil) {
results = [NSMutableArray arrayWithObject:currentBridge];
continue;
}
[results addObject:currentBridge];
}
// Why do we wait so long? In case someone tries to dealloc the krollBridge while we're looking at it.
// registryObjects nor the registry does a retain here!
os_unfair_lock_unlock(&krollBridgeRegistryLock);
return results;
}
+ (NSArray *)krollContexts
{
os_unfair_lock_lock(&krollBridgeRegistryLock);
signed long bridgeCount = CFSetGetCount(krollBridgeRegistry);
KrollBridge *registryObjects[bridgeCount];
CFSetGetValues(krollBridgeRegistry, (const void **)registryObjects);
NSMutableArray *results = [[NSMutableArray alloc] initWithCapacity:0];
for (NSUInteger currentBridgeIndex = 0; currentBridgeIndex < bridgeCount; ++currentBridgeIndex) {
KrollBridge *bridge = registryObjects[currentBridgeIndex];
[results addObject:bridge.krollContext];
}
os_unfair_lock_unlock(&krollBridgeRegistryLock);
return [results autorelease];
}
+ (BOOL)krollBridgeExists:(KrollBridge *)bridge
{
if (bridge == nil) {
return NO;
}
bool result = NO;
os_unfair_lock_lock(&krollBridgeRegistryLock);
signed long bridgeCount = CFSetGetCount(krollBridgeRegistry);
KrollBridge *registryObjects[bridgeCount];
CFSetGetValues(krollBridgeRegistry, (const void **)registryObjects);
for (int currentBridgeIndex = 0; currentBridgeIndex < bridgeCount; currentBridgeIndex++) {
KrollBridge *currentBridge = registryObjects[currentBridgeIndex];
if (currentBridge == bridge) {
result = YES;
break;
}
}
// Why not CFSetContainsValue? Because bridge may not be a valid pointer, and SetContainsValue
// will ask it for a hash!
os_unfair_lock_unlock(&krollBridgeRegistryLock);
return result;
}
+ (KrollBridge *)krollBridgeForThreadName:(NSString *)threadName;
{
if (threadName == nil) {
return nil;
}
KrollBridge *result = nil;
os_unfair_lock_lock(&krollBridgeRegistryLock);
signed long bridgeCount = CFSetGetCount(krollBridgeRegistry);
KrollBridge *registryObjects[bridgeCount];
CFSetGetValues(krollBridgeRegistry, (const void **)registryObjects);
for (int currentBridgeIndex = 0; currentBridgeIndex < bridgeCount; currentBridgeIndex++) {
}
os_unfair_lock_unlock(&krollBridgeRegistryLock);
return result;
}
- (int)forceGarbageCollectNow;
{
[context gc];
// Actually forcing garbage collect now will cause a deadlock.
return 0;
}
- (BOOL)shouldDebugContext
{
return [[self host] debugMode];
}
- (BOOL)shouldProfileContext
{
return [[self host] profileMode];
}
@end