]> git.saurik.com Git - cycript.git/commitdiff
Support .type on NSBlock to get their signature.
authorJay Freeman (saurik) <saurik@saurik.com>
Fri, 24 Jan 2014 16:35:21 +0000 (08:35 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Fri, 24 Jan 2014 16:35:21 +0000 (08:35 -0800)
ObjectiveC/Library.mm

index 6f47cbf04035a127a3c96d62b8caf11528469644..46c7f98970fb3b1a7e056feeb22f2232e038d4e9 100644 (file)
@@ -2574,6 +2574,18 @@ static JSValueRef CYValue_callAsFunction_$cya(JSContextRef context, JSObjectRef
     return CYMakePointer(context, &internal->value_, _not(size_t), type, ffi, object);
 } CYCatch(NULL) }
 
     return CYMakePointer(context, &internal->value_, _not(size_t), type, ffi, object);
 } CYCatch(NULL) }
 
+static JSValueRef FunctionInstance_getProperty_type(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
+    Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
+    const char *encoding(CYBlockEncoding(internal->GetValue()));
+    if (encoding == NULL)
+        return CYJSNull(context);
+    // XXX: this should be stored on a FunctionInstance private value subclass
+    CYPool pool;
+    sig::Signature signature;
+    sig::Parse(pool, &signature, encoding, &Structor_);
+    return CYMakeType(context, &signature);
+} CYCatch(NULL) }
+
 static JSValueRef Instance_getProperty_constructor(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
     return Instance::Make(context, (id) object_getClass(internal->GetValue()));
 static JSValueRef Instance_getProperty_constructor(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
     Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
     return Instance::Make(context, (id) object_getClass(internal->GetValue()));
@@ -2733,6 +2745,7 @@ static JSStaticValue Selector_staticValues[2] = {
     {NULL, NULL, NULL, 0}
 };
 
     {NULL, NULL, NULL, 0}
 };
 
+// XXX: this is sadly duplicated in FunctionInstance_staticValues
 static JSStaticValue Instance_staticValues[5] = {
     {"constructor", &Instance_getProperty_constructor, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"messages", &Instance_getProperty_messages, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
 static JSStaticValue Instance_staticValues[5] = {
     {"constructor", &Instance_getProperty_constructor, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"messages", &Instance_getProperty_messages, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
@@ -2741,6 +2754,16 @@ static JSStaticValue Instance_staticValues[5] = {
     {NULL, NULL, NULL, 0}
 };
 
     {NULL, NULL, NULL, 0}
 };
 
+static JSStaticValue FunctionInstance_staticValues[6] = {
+    {"type", &FunctionInstance_getProperty_type, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+    // XXX: this is sadly a duplicate of Instance_staticValues
+    {"constructor", &Instance_getProperty_constructor, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+    {"messages", &Instance_getProperty_messages, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+    {"prototype", &Instance_getProperty_prototype, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+    {"value", &CYValue_getProperty_value, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+    {NULL, NULL, NULL, 0}
+};
+
 static JSStaticFunction Instance_staticFunctions[7] = {
     {"$cya", &CYValue_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"toCYON", &Instance_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
 static JSStaticFunction Instance_staticFunctions[7] = {
     {"$cya", &CYValue_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
     {"toCYON", &Instance_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
@@ -2836,6 +2859,7 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry {
     BooleanInstance_ = JSClassCreate(&definition);
 
     definition.className = "FunctionInstance";
     BooleanInstance_ = JSClassCreate(&definition);
 
     definition.className = "FunctionInstance";
+    definition.staticValues = FunctionInstance_staticValues;
     definition.callAsFunction = &FunctionInstance_callAsFunction;
     FunctionInstance_ = JSClassCreate(&definition);
 
     definition.callAsFunction = &FunctionInstance_callAsFunction;
     FunctionInstance_ = JSClassCreate(&definition);