+_finline bool CYJSValueIsInstanceOfCachedConstructor(JSContextRef context, JSValueRef value, JSStringRef cache) {
+ return _jsccall(JSValueIsInstanceOfConstructor, context, value, CYGetCachedObject(context, cache));
+}
+
+struct CYBlockDescriptor {
+ struct {
+ BlockDescriptor1 one_;
+ BlockDescriptor2 two_;
+ BlockDescriptor3 three_;
+ } d_;
+
+ Closure_privateData *internal_;
+};
+
+void CYDisposeBlock(BlockLiteral *literal) {
+ delete reinterpret_cast<CYBlockDescriptor *>(literal->descriptor)->internal_;
+}
+
+static JSValueRef BlockAdapter_(JSContextRef context, size_t count, JSValueRef values[], JSObjectRef function) {
+ JSObjectRef _this(CYCastJSObject(context, values[0]));
+ return CYCallAsFunction(context, function, _this, count - 1, values + 1);
+}
+
+static void BlockClosure_(ffi_cif *cif, void *result, void **arguments, void *arg) {
+ CYExecuteClosure(cif, result, arguments, arg, &BlockAdapter_);
+}
+
+NSObject *CYMakeBlock(JSContextRef context, JSObjectRef function, sig::Signature &signature) {
+ BlockLiteral *literal(reinterpret_cast<BlockLiteral *>(malloc(sizeof(BlockLiteral))));
+
+ CYBlockDescriptor *descriptor(new CYBlockDescriptor);
+ memset(&descriptor->d_, 0, sizeof(descriptor->d_));
+
+ descriptor->internal_ = CYMakeFunctor_(context, function, signature, &BlockClosure_);
+ literal->invoke = reinterpret_cast<void (*)(void *, ...)>(descriptor->internal_->GetValue());
+
+ literal->isa = objc_getClass("__NSMallocBlock__");
+ literal->flags = BLOCK_HAS_SIGNATURE | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL;
+ literal->reserved = 0;
+ literal->descriptor = descriptor;
+
+ descriptor->d_.one_.size = sizeof(descriptor->d_);
+ descriptor->d_.two_.dispose_helper = &CYDisposeBlock;
+ descriptor->d_.three_.signature = sig::Unparse(*descriptor->internal_->pool_, &signature);
+
+ return reinterpret_cast<NSObject *>(literal);
+}
+
+NSObject *CYCastNSObject(CYPool *pool, JSContextRef context, JSObjectRef object) {
+ if (CYJSValueIsNSObject(context, object)) {