#include "Error.hpp"
#include "JavaScript.hpp"
#include "String.hpp"
-#include "Bridge.hpp"
+#include "Execute.hpp"
#include <cmath>
#include <map>
return Instance::Make(context, nil);
if (Class _class = objc_getClass(name.data))
return CYMakeInstance(context, _class, true);
+ if (Protocol *protocol = objc_getProtocol(name.data))
+ return CYMakeInstance(context, protocol, true);
return NULL;
} CYPoolCatch(NULL) return /*XXX*/ NULL; }
if (count > 1)
throw CYJSError(context, "incorrect number of arguments to Instance constructor");
id self(count == 0 ? nil : CYCastPointer<id>(context, arguments[0]));
- return Instance::Make(context, self);
+ return CYMakeInstance(context, self, false);
} CYCatch }
static JSValueRef CYValue_getProperty_value(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) {
} CYPoolCatch(NULL)
} CYCatch return /*XXX*/ NULL; }
+#if 0
+static JSValueRef Instance_callAsFunction_valueOf(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
+ if (!JSValueIsObjectOfClass(context, _this, Instance_))
+ return NULL;
+
+ Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
+ return CYCastJSValue(context, reinterpret_cast<uintptr_t>(internal->GetValue()));
+} CYCatch return /*XXX*/ NULL; }
+#endif
+
+static JSValueRef Instance_callAsFunction_toPointer(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
+ if (!JSValueIsObjectOfClass(context, _this, Instance_))
+ return NULL;
+
+ Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
+ // XXX: but... but... THIS ISN'T A POINTER! :(
+ return CYCastJSValue(context, reinterpret_cast<uintptr_t>(internal->GetValue()));
+} CYCatch return /*XXX*/ NULL; }
+
static JSValueRef Instance_callAsFunction_toString(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
if (!JSValueIsObjectOfClass(context, _this, Instance_))
return NULL;
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(_this)));
+ id value(internal->GetValue());
+ if (value == nil)
+ return CYCastJSValue(context, "nil");
+
CYPoolTry {
// XXX: this seems like a stupid implementation; what if it crashes? why not use the CYONifier backend?
return CYCastJSValue(context, CYJSString(context, [internal->GetValue() description]));
{NULL, NULL, NULL, 0}
};
-static JSStaticFunction Instance_staticFunctions[5] = {
+static JSStaticFunction Instance_staticFunctions[6] = {
{"$cya", &CYValue_callAsFunction_$cya, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"toCYON", &Instance_callAsFunction_toCYON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"toJSON", &Instance_callAsFunction_toJSON, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+ //{"valueOf", &Instance_callAsFunction_valueOf, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
+ {"toPointer", &Instance_callAsFunction_toPointer, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"toString", &Instance_callAsFunction_toString, kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL, 0}
};
struct CYObjectiveC {
CYObjectiveC() {
hooks_ = &CYObjectiveCHooks;
+ // XXX: evil magic juju to make this actually take effect on a Mac when compiled with autoconf/libtool doom!
+ _assert(hooks_ != NULL);
}
} CYObjectiveC;