#pragma mark blocks
- (id)enumerationBlockCalling: (JSValueRefAndContextRef)callbackFunction
{
JSContextRef mainContext = [[JSCocoa controllerFromContext:callbackFunction.ctx] ctx];
JSValueProtect(mainContext, callbackFunction.value);
[JSCocoaController upJSValueProtectCount];
void (^aBlock)(id,NSUInteger,BOOL* ) = ^(id obj, NSUInteger idx, BOOL* stop) {
id jsc = [JSCocoa controllerFromContext:mainContext];
JSObjectRef fn = JSValueToObject(mainContext, callbackFunction.value, NULL);
id args = [NSArray arrayWithObjects:obj
,[NSNumber numberWithInteger:idx]
, nil];
JSValueRef res = [ jsc callJSFunction:fn withArguments:args ];
*stop = JSValueToBoolean(mainContext, res);
};
return [aBlock copy];
} |