- else {
- JSValueRef exception(NULL);
- JSStringRef string(JSValueToStringCopy(context, value, &exception));
- CYThrow(context, exception);
- size_t size(JSStringGetMaximumUTF8CStringSize(string));
- char utf8[size];
- JSStringGetUTF8CString(string, utf8, size);
- JSStringRelease(string);
- return sel_registerName(utf8);
+ else
+ return sel_registerName(CYCastCString(context, value));
+}
+
+void *CYCastPointer(JSContextRef context, JSValueRef value) {
+ switch (JSValueGetType(context, value)) {
+ case kJSTypeNull:
+ return NULL;
+ break;
+
+ case kJSTypeString:
+ return dlsym(RTLD_DEFAULT, CYCastCString(context, value));
+ break;
+
+ case kJSTypeObject:
+ if (JSValueIsObjectOfClass(context, value, ptr_)) {
+ ptrData *data(reinterpret_cast<ptrData *>(JSObjectGetPrivate((JSObjectRef) value)));
+ return data->value_;
+ }
+ default:
+ JSValueRef exception(NULL);
+ double number(JSValueToNumber(context, value, &exception));
+ CYThrow(context, exception);
+ return reinterpret_cast<void *>(static_cast<uintptr_t>(number));
+ break;