Reviewed by Tim H.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Sep 2006 19:08:07 +0000 (19:08 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Sep 2006 19:08:07 +0000 (19:08 +0000)
        http://bugzilla.opendarwin.org/show_bug.cgi?id=10693
        Convert JavaScript arrays to AppleScript lists

JavaScriptCore:
        * JavaScriptCore.exp: Export ArrayInstance::info and ArrayInstance::getItem().
        * kjs/array_instance.h:
        * kjs/array_object.cpp:
        (ArrayInstance::getItem): Added a method to access array items from C++.

WebCore:
        * bridge/mac/WebCoreFrameBridge.mm:
        (aeDescFromJSValue): Added a case for ArrayInstance.

LayoutTests:
        * fast/AppleScript/array-expected.txt:
        * fast/AppleScript/array.html: Updated results, added a test for
        circular dependencies.

WebKitTools:
        * DumpRenderTree/AppleScriptController.m:
        (convertAEDescToObject):
        (-[AppleScriptController doJavaScript:]): Support printing AEDescLists.

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

JavaScriptCore/ChangeLog
JavaScriptCore/JavaScriptCore.exp
JavaScriptCore/kjs/array_instance.h
JavaScriptCore/kjs/array_object.cpp
LayoutTests/ChangeLog
LayoutTests/fast/AppleScript/array-expected.txt
LayoutTests/fast/AppleScript/array.html
WebCore/ChangeLog
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/AppleScriptController.m

index 772622e27f1c894a2713650de77157e07b1cb5a5..44c1f10cc142d8e3a65b0b615e21756c7ea23b7e 100644 (file)
@@ -1,3 +1,15 @@
+2006-09-03  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Tim H.
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=10693
+        Convert JavaScript arrays to AppleScript lists
+
+        * JavaScriptCore.exp: Export ArrayInstance::info and ArrayInstance::getItem().
+        * kjs/array_instance.h:
+        * kjs/array_object.cpp:
+        (ArrayInstance::getItem): Added a method to access array items from C++.
+
 2006-09-02  Krzysztof Kowalczyk  <kkowalczyk@gmail.com>
 
         Reviewed by Tim H.
index 11184a47b787a8650dc595a239e48e54339ba3eb..446ba57fdf5626108c629bbb53d0af50d5aca515 100644 (file)
@@ -141,6 +141,7 @@ __ZN3KJS11PropertyMapD1Ev
 __ZN3KJS12DateInstance4infoE
 __ZN3KJS12PropertySlot15undefinedGetterEPNS_9ExecStateEPNS_8JSObjectERKNS_10IdentifierERKS0_
 __ZN3KJS12jsNumberCellEd
+__ZN3KJS13ArrayInstance4infoE
 __ZN3KJS13SavedBuiltinsC1Ev
 __ZN3KJS13SavedBuiltinsD1Ev
 __ZN3KJS14StringInstance14deletePropertyEPNS_9ExecStateERKNS_10IdentifierE
@@ -235,6 +236,7 @@ __ZNK3KJS11Interpreter24builtinFunctionPrototypeEv
 __ZNK3KJS11PropertyMap3getERKNS_10IdentifierE
 __ZNK3KJS11PropertyMap4saveERNS_15SavedPropertiesE
 __ZNK3KJS12DateInstance7getTimeERdRi
+__ZNK3KJS13ArrayInstance7getItemEj
 __ZNK3KJS19InternalFunctionImp14implementsCallEv
 __ZNK3KJS19InternalFunctionImp21implementsHasInstanceEv
 __ZNK3KJS4List2atEi
index 54341a5f8cbe2515153807071d7012f34a78a548..2fc5550bb8400255c2cde5337619dbfb77eb2d00 100644 (file)
@@ -47,6 +47,7 @@ namespace KJS {
     static const ClassInfo info;
     
     unsigned getLength() const { return length; }
+    JSValue* getItem(unsigned) const;
     
     void sort(ExecState *exec);
     void sort(ExecState *exec, JSObject *compareFunction);
index 158d9f14dc3a015d1c9bc63663a8eae2e8f486b3..eca277ab5c9dad2fad12cbbe4836e149c40569ae 100644 (file)
@@ -4,6 +4,7 @@
  *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
  *  Copyright (C) 2003 Apple Computer, Inc.
  *  Copyright (C) 2003 Peter Kelly (pmk@post.com)
+ *  Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -69,6 +70,18 @@ ArrayInstance::~ArrayInstance()
   fastFree(storage);
 }
 
+JSValue* ArrayInstance::getItem(unsigned i) const
+{
+    if (i >= length)
+        return jsUndefined();
+    
+    JSValue* val = (i < storageLength) ? 
+                            storage[i] :
+                            getDirect(Identifier::from(i));
+
+    return val ? val : jsUndefined();
+}
+
 JSValue *ArrayInstance::lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot)
 {
   return jsNumber(static_cast<ArrayInstance *>(slot.slotBase())->length);
index ade64a964bbc5a0e29065c7ab9fcdab08f661a11..cc3f08ab2db86bb8beb6950dfb9e5bec07de3cb8 100644 (file)
@@ -1,3 +1,14 @@
+2006-09-03  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Tim H.
+
+        Test for http://bugzilla.opendarwin.org/show_bug.cgi?id=10693
+        Convert JavaScript arrays to AppleScript lists
+
+        * fast/AppleScript/array-expected.txt:
+        * fast/AppleScript/array.html: Updated results, added a test for
+        circular dependencies.
+
 2006-09-03  Alexey Proskuryakov  <ap@nypop.com>
 
         Reviewed by Eric.
index 7dcea0818329fb1eed67a1a89bde8cb617965bdd..c45cfe33d263fd2e07053b34906e7b8d3ab51626 100644 (file)
@@ -1,5 +1,5 @@
-At the moment, toString() is just used. Perhaps, some arrays should be converted to AppleScript lists.
-1,2,three ('utxt')
-,,2 ('utxt')
+(1, 2, three) ('list')
+(<>, <>, 2) ('list')
+(0, "0,") ('list')
 
 
index 9cd35ee058c65aa630da52735aba6bf081bb891f..db9f70f8905ef0ea383694968c83dd2576f10584 100644 (file)
@@ -3,7 +3,6 @@
 <title>do JavaScript - converting JavaScript arrays to AppleScript</title>
 </head>
 <body>
-At the moment, toString() is just used. Perhaps, some arrays should be converted to AppleScript lists.
 <script type="text/javascript">
 
     var console_messages = document.createElement("ol");
@@ -22,6 +21,10 @@ At the moment, toString() is just used. Perhaps, some arrays should be converted
             
             log(appleScriptController.doJavaScript("new Array(1, 2, 'three');"));
             log(appleScriptController.doJavaScript("arr = new Array; arr['a'] = 'a'; arr[2] = 2; arr;"));
+            log(appleScriptController.doJavaScript("arr = new Array; arr[0] = 0; arr[1] = arr; arr;"));
+
+// This takes ~10 seconds on my G4/1.25
+//            log(appleScriptController.doJavaScript("arr = new Array; arr[1] = 1; arr[10001] = 10001; arr;"));
             
         } catch (ex) {
             log("Exception: " + ex.description);
index 0171b3b01efb52597cfb7a20201c9df20602f189..1daba831a02ba811b0887351143b0554547d1275 100644 (file)
@@ -1,3 +1,15 @@
+2006-09-03  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Tim H.
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=10693
+        Convert JavaScript arrays to AppleScript lists
+
+        Test: fast/AppleScript/array.html
+
+        * bridge/mac/WebCoreFrameBridge.mm:
+        (aeDescFromJSValue): Added a case for ArrayInstance.
+
 2006-09-03  Alexey Proskuryakov  <ap@nypop.com>
 
         Reviewed by Eric.
index a468962ade57176ad96ecb27ec36bd87bb145995..b00abfd58f0eb93a7675152f15acf13ab3e31cd1 100644 (file)
@@ -75,6 +75,7 @@
 #import "markup.h"
 #import "visible_units.h"
 #import "XMLTokenizer.h"
+#import <JavaScriptCore/array_instance.h>
 #import <JavaScriptCore/date_object.h>
 #import <JavaScriptCore/runtime_root.h>
 #import <kjs/SavedBuiltins.h>
@@ -85,6 +86,7 @@ using namespace std;
 using namespace WebCore;
 using namespace HTMLNames;
 
+using KJS::ArrayInstance;
 using KJS::BooleanType;
 using KJS::DateInstance;
 using KJS::ExecState;
@@ -185,6 +187,20 @@ static NSAppleEventDescriptor* aeDescFromJSValue(ExecState* exec, JSValue* jsVal
                         aeDesc = [NSAppleEventDescriptor descriptorWithDescriptorType:typeLongDateTime bytes:&ldt length:sizeof(ldt)];
                 }
             }
+            else if (object->inherits(&ArrayInstance::info)) {
+                static HashSet<JSObject*> visitedElems;
+                if (!visitedElems.contains(object)) {
+                    visitedElems.add(object);
+                    
+                    ArrayInstance* array = static_cast<ArrayInstance*>(object);
+                    aeDesc = [NSAppleEventDescriptor listDescriptor];
+                    unsigned numItems = array->getLength();
+                    for (unsigned i = 0; i < numItems; ++i)
+                        [aeDesc insertDescriptor:aeDescFromJSValue(exec, array->getItem(i)) atIndex:0];
+                    
+                    visitedElems.remove(object);
+                }
+            }
             if (!aeDesc) {
                 JSValue* primitive = object->toPrimitive(exec);
                 if (exec->hadException()) {
index 1aa851255cca09387bdc11b09f0914c2ef49576d..25339e6a04fe9f64c4e64fa1fa12780f40238ade 100644 (file)
@@ -1,3 +1,14 @@
+2006-09-03  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Tim H.
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=10693
+        Convert JavaScript arrays to AppleScript lists
+
+        * DumpRenderTree/AppleScriptController.m:
+        (convertAEDescToObject):
+        (-[AppleScriptController doJavaScript:]): Support printing AEDescLists.
+
 2006-08-31  Darin Adler  <darin@apple.com>
 
         * Scripts/do-webcore-rename: Prepare for another round of renaming.
index 9c94c7cc84843d2b1bb24c5a77d6006c98b484f3..9f2df3aee6d07dcd775bafac5db0bbd96346ea64 100644 (file)
     return self;
 }
 
-- (NSString *)doJavaScript:(NSString *)aString
+static id convertAEDescToObject(NSAppleEventDescriptor *aeDesc)
 {
-    NSAppleEventDescriptor *aeDesc = [webView aeDescByEvaluatingJavaScriptFromString:aString];
-    if (!aeDesc)
-        return @"(null)";
-    
     id value = nil;
 
     DescType descType = [aeDesc descriptorType];
                 value = [NSString stringWithFormat:@"%016llX", (unsigned long long)d];
             }
             break;
+        case typeAEList:
+            value = [NSMutableArray array];
+            int numItems = [aeDesc numberOfItems];
+            for (int i = 0; i < numItems; ++i)
+                [(NSMutableArray*)value addObject:convertAEDescToObject([aeDesc descriptorAtIndex:(i + 1)])];
+            break;
     }
  
     if (!value)
     if (!value)
         value = [aeDesc data];
 
+    return value;
+}
+
+- (NSString *)doJavaScript:(NSString *)aString
+{
+    NSAppleEventDescriptor *aeDesc = [webView aeDescByEvaluatingJavaScriptFromString:aString];
+    if (!aeDesc)
+        return @"(null)";
+    
+    DescType descType = [aeDesc descriptorType];
     char descTypeStr[5];
     descTypeStr[0] = descType >> 24;
     descTypeStr[1] = descType >> 16;
     descTypeStr[2] = descType >> 8;
     descTypeStr[3] = descType;
     descTypeStr[4] = 0;
-    
-    return [NSString stringWithFormat:@"%@ ('%s')", value, descTypeStr];
+
+    return [NSString stringWithFormat:@"%@ ('%s')", convertAEDescToObject(aeDesc), descTypeStr];
 }
 
 @end