/* Index Offsets {{{ */
size_t CYGetIndex(const CYUTF8String &value) {
if (value.data[0] != '0') {
- char *end;
- size_t index(strtoul(value.data, &end, 10));
- if (value.data + value.size == end)
- return index;
- } else if (value.data[1] == '\0')
+ size_t index(0);
+ for (size_t i(0); i != value.size; ++i) {
+ if (!DigitRange_[value.data[i]])
+ return _not(size_t);
+ index *= 10;
+ index += value.data[i] - '0';
+ }
+ return index;
+ } else if (value.size == 1)
return 0;
- return _not(size_t);
+ else
+ return _not(size_t);
}
size_t CYGetIndex(apr_pool_t *pool, JSContextRef context, JSStringRef value) {
return CYGetIndex(CYPoolUTF8String(pool, context, value));
}
+// XXX: this isn't actually right
bool CYGetOffset(const char *value, ssize_t &index) {
if (value[0] != '0') {
char *end;
#define method_getTypeEncoding(method) ((method)->method_types)
#define method_setImplementation(method, imp) ((void) ((method)->method_imp = (imp)))
+#undef objc_getClass
+#define objc_getClass GSClassFromName
+
#define objc_getProtocol GSProtocolFromName
#define object_getClass GSObjCClass
#define object_getInstanceVariable(object, name, value) ({ \
objc_ivar *ivar(class_getInstanceVariable(object_getClass(object), name)); \
- GSObjCGetVariable(object, ivar_getOffset(ivar), sizeof(void *), value); \
+ if (ivar != NULL) \
+ GSObjCGetVariable(object, ivar_getOffset(ivar), sizeof(void *), value); \
ivar; \
})
}
/* }}} */
+JSValueRef CYCastJSValue(JSContextRef context, NSObject *value);
+
void CYThrow(JSContextRef context, NSException *error, JSValueRef *exception) {
if (exception == NULL)
throw error;
return array;
}
-JSValueRef CYCastJSValue(JSContextRef context, id value) { CYPoolTry {
+JSValueRef CYCastJSValue(JSContextRef context, NSObject *value) { CYPoolTry {
if (value == nil)
return CYJSNull(context);
else if ([value respondsToSelector:@selector(cy$JSValueInContext:)])
- (void) setObject:(id)object forKey:(id)key { CYObjectiveTry {
// XXX: are NSDictionary keys always NSString *?
- CYSetProperty(context_, object_, CYJSString(context_, (NSString *) key), CYCastJSValue(context_, object));
+ CYSetProperty(context_, object_, CYJSString(context_, (NSString *) key), CYCastJSValue(context_, (NSString *) object));
} CYObjectiveCatch }
- (void) removeObjectForKey:(id)key { CYObjectiveTry {
- (void) addObject:(id)object { CYObjectiveTry {
JSValueRef exception(NULL);
JSValueRef arguments[1];
- arguments[0] = CYCastJSValue(context_, object);
+ arguments[0] = CYCastJSValue(context_, (NSObject *) object);
JSObjectCallAsFunction(context_, Array_push_, object_, 1, arguments, &exception);
CYThrow(context_, exception);
} CYObjectiveCatch }
JSValueRef arguments[3];
arguments[0] = CYCastJSValue(context_, index);
arguments[1] = CYCastJSValue(context_, 0);
- arguments[2] = CYCastJSValue(context_, object);
+ arguments[2] = CYCastJSValue(context_, (NSObject *) object);
JSObjectCallAsFunction(context_, Array_splice_, object_, 3, arguments, &exception);
CYThrow(context_, exception);
} CYObjectiveCatch }
size_t bounds([self count]);
if (index >= bounds)
@throw [NSException exceptionWithName:NSRangeException reason:[NSString stringWithFormat:@"*** -[CYJSArray replaceObjectAtIndex:withObject:]: index (%zu) beyond bounds (%zu)", index, bounds] userInfo:nil];
- CYSetProperty(context_, object_, index, CYCastJSValue(context_, object));
+ CYSetProperty(context_, object_, index, CYCastJSValue(context_, (NSObject *) object));
} CYObjectiveCatch }
@end
static JSValueRef CYObjectiveC_FromFFI(JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) { CYPoolTry {
switch (type->primitive) {
case sig::object_P:
- if (id object = *reinterpret_cast<id *>(data)) {
+ if (NSObject *object = *reinterpret_cast<NSObject **>(data)) {
JSValueRef value(CYCastJSValue(context, object));
if (initialize)
[object release];
void CYSetProperty(JSContextRef context, JSObjectRef object, size_t index, JSValueRef value);
void CYSetProperty(JSContextRef context, JSObjectRef object, JSStringRef name, JSValueRef value, JSPropertyAttributes attributes = kJSPropertyAttributeNone);
-JSValueRef CYCastJSValue(JSContextRef context, bool value);
+//JSValueRef CYCastJSValue(JSContextRef context, bool value);
JSValueRef CYCastJSValue(JSContextRef context, double value);
JSValueRef CYCastJSValue(JSContextRef context, int value);
JSValueRef CYCastJSValue(JSContextRef context, unsigned int value);