Fixed <rdar://problem/3880561> Default string value of ObjC object in JS...
authorrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Nov 2004 01:24:55 +0000 (01:24 +0000)
committerrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Nov 2004 01:24:55 +0000 (01:24 +0000)
        Reviewed by Hyatt.

        * bindings/objc/objc_instance.mm:
        (ObjcInstance::stringValue):
        * bindings/objc/objc_utility.h:
        * bindings/objc/objc_utility.mm:
        (KJS::Bindings::convertNSStringToString):
        (KJS::Bindings::convertObjcValueToValue):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8019 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/bindings/objc/objc_instance.mm
JavaScriptCore/bindings/objc/objc_utility.h
JavaScriptCore/bindings/objc/objc_utility.mm

index 45b880bdf9c0a61b9849a996793462902e728cc3..1623d0cb9855ebd7c5f85563eed5f95ea81d70dc 100644 (file)
@@ -1,3 +1,16 @@
+2004-11-15  Richard Williamson   <rjw@apple.com>
+
+        Fixed <rdar://problem/3880561> Default string value of ObjC object in JS should be [obj description].
+
+        Reviewed by Hyatt.
+
+        * bindings/objc/objc_instance.mm:
+        (ObjcInstance::stringValue):
+        * bindings/objc/objc_utility.h:
+        * bindings/objc/objc_utility.mm:
+        (KJS::Bindings::convertNSStringToString):
+        (KJS::Bindings::convertObjcValueToValue):
+
 === Safari-171 ===
 
 2004-11-09  Chris Blumenberg  <cblu@apple.com>
index 2064baa6b3e3c0852bef1ac34d46ba9cf310ed13..88e24e5f7067d1cb7559203e1a55d3ee4badb899 100644 (file)
@@ -385,9 +385,7 @@ KJS::Value ObjcInstance::defaultValue (KJS::Type hint) const
 
 KJS::Value ObjcInstance::stringValue() const
 {
-    // FIXME:  Implement something sensible, like calling toString...
-    KJS::String v("");
-    return v;
+    return convertNSStringToString ([getObject() description]);
 }
 
 KJS::Value ObjcInstance::numberValue() const
index e0ed4cb3333aba6bdd19e96d21e6b18d51c60047..8cbb108c5ac876c295f3089a4c7dae7b9074e1f6 100644 (file)
 
 #include <objc_header.h>
 
+#ifdef __OBJC__
+@class NSString;
+#else
+class NSString;
+#endif
+
 namespace KJS
 {
 
@@ -61,6 +67,7 @@ typedef enum {
 } ObjcValueType;
 
 ObjcValue convertValueToObjcValue (KJS::ExecState *exec, const KJS::Value &value, ObjcValueType type);
+Value convertNSStringToString(NSString *nsstring);
 Value convertObjcValueToValue (KJS::ExecState *exec, void *buffer, ObjcValueType type);
 ObjcValueType objcValueTypeForType (const char *type);
 
index 85c64c5950826d3d84289ed80f8ac6a780285a9f..1b6a6b3ad000bfe418791873f1161f93f0d2af55 100644 (file)
@@ -153,6 +153,18 @@ ObjcValue KJS::Bindings::convertValueToObjcValue (KJS::ExecState *exec, const KJ
     return result;
 }
 
+Value KJS::Bindings::convertNSStringToString(NSString *nsstring)
+{
+    unichar *chars;
+    unsigned int length = [nsstring length];
+    chars = (unichar *)malloc(sizeof(unichar)*length);
+    [nsstring getCharacters:chars];
+    UString u((const KJS::UChar*)chars, length);
+    Value aValue = String (u);
+    free((void *)chars);
+    return aValue;
+}
+
 /*
 
     ObjC      to    JavaScript
@@ -186,13 +198,7 @@ Value KJS::Bindings::convertObjcValueToValue (KJS::ExecState *exec, void *buffer
                 */
                 if ([*obj isKindOfClass:[NSString class]]){
                     NSString *string = (NSString *)*obj;
-                    unichar *chars;
-                    unsigned int length = [string length];
-                    chars = (unichar *)malloc(sizeof(unichar)*length);
-                    [string getCharacters:chars];
-                    UString u((const KJS::UChar*)chars, length);
-                    aValue = String (u);
-                    free((void *)chars);
+                    aValue = convertNSStringToString (string);
                 }
                 else if (*obj == [WebUndefined undefined]) {
                     return Undefined();