From 0226d428e0b3b0913a0c067f86cbf90339cd4c92 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" <saurik@saurik.com> Date: Wed, 4 Nov 2009 10:27:15 +0000 Subject: [PATCH 1/1] Half fixed (at least it doesn't throw an exception anymore) NSDictionaries that have non-NSString keys. --- ObjectiveC/Library.mm | 17 +++++++---------- todo.txt | 6 ++---- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index a3c1d66..3cfb90e 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -748,10 +748,10 @@ NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef valu bool comma(false); #ifdef __APPLE__ - for (id key in self) { + for (NSObject *key in self) { #else NSEnumerator *keys([self keyEnumerator]); - while (id key = [keys nextObject]) { + while (NSObject *key = [keys nextObject]) { #endif if (comma) [json appendString:@","]; @@ -779,10 +779,10 @@ NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef valu [super cy$getPropertyNames:names inContext:context]; #ifdef __APPLE__ - for (NSString *key in self) { + for (NSObject *key in self) { #else NSEnumerator *keys([self keyEnumerator]); - while (NSString *key = [keys nextObject]) { + while (NSObject *key = [keys nextObject]) { #endif JSPropertyNameAccumulatorAddName(names, CYJSString(context, key)); } @@ -1096,8 +1096,7 @@ JSValueRef CYCastJSValue(JSContextRef context, NSObject *value) { CYPoolTry { } CYObjectiveCatch } - (id) objectForKey:(id)key { CYObjectiveTry { - // XXX: are NSDictionary keys always NSString *? - JSValueRef value(CYGetProperty(context_, object_, CYJSString(context_, (NSString *) key))); + JSValueRef value(CYGetProperty(context_, object_, CYJSString(context_, (NSObject *) key))); if (JSValueIsUndefined(context_, value)) return nil; return CYCastNSObject(NULL, context_, value) ?: [NSNull null]; @@ -1111,14 +1110,12 @@ JSValueRef CYCastJSValue(JSContextRef context, NSObject *value) { CYPoolTry { } CYObjectiveCatch } - (void) setObject:(id)object forKey:(id)key { CYObjectiveTry { - // XXX: are NSDictionary keys always NSString *? - CYSetProperty(context_, object_, CYJSString(context_, (NSString *) key), CYCastJSValue(context_, (NSString *) object)); + CYSetProperty(context_, object_, CYJSString(context_, (NSObject *) key), CYCastJSValue(context_, (NSString *) object)); } CYObjectiveCatch } - (void) removeObjectForKey:(id)key { CYObjectiveTry { JSValueRef exception(NULL); - // XXX: are NSDictionary keys always NSString *? - (void) JSObjectDeleteProperty(context_, object_, CYJSString(context_, (NSString *) key), &exception); + (void) JSObjectDeleteProperty(context_, object_, CYJSString(context_, (NSObject *) key), &exception); CYThrow(context_, exception); } CYObjectiveCatch } diff --git a/todo.txt b/todo.txt index 60e8c15..5895845 100644 --- a/todo.txt +++ b/todo.txt @@ -2,6 +2,7 @@ unicode identifier support (native and \u) support unions (right now 0-1 fields parsed as struct) \\\n escapes in strings aren't handled in the console look into what String is, and whether to bridge it +think about bridging NSNumber with Number prototype some JS callbacks don't use exception pointers at all... a newline needs to not be allowed after a unary * finish implementing default xml namespace statement @@ -14,10 +15,7 @@ numerification needs to use specific precision values consider a mode where unicode string content is saved https://bugzilla.mozilla.org/show_bug.cgi?id=274152 -cy# SBAwayController.sharedAwayController->_displayValues -"*** -[NSCFNumber length]: unrecognized selector sent to instance 0x4a4bda0" -b = []; for (x in a) b.push(x); <- crashes - +NSDictionaries that have NSNumber keys don't getProperty errors in another process aren't displayed; to fix this, parse errors should get converted to exceptions and thrown CYPoolTry/Catch now carefully save the exception after it /no longer needs the exception/... uhh... wtf? throw CYJSError should probably be replaced with CYThrow() across the board -- 2.45.2