2006-02-07 Alexey Proskuryakov <ap@nypop.com>
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Feb 2006 17:01:42 +0000 (17:01 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Feb 2006 17:01:42 +0000 (17:01 +0000)
        Reviewed by Timothy.

        Convert JavaScript objects to appropriate AppleScript types, instead of only strings
        http://bugzilla.opendarwin.org/show_bug.cgi?id=7012

WebKit:
        * WebView/WebView.m:
        (-[WebView aeDescByEvaluatingJavaScriptFromString:]): Added.
        * WebView/WebViewPrivate.h:

WebCore:
        * bridge/mac/WebCoreFrameBridge.h:
        * bridge/mac/WebCoreFrameBridge.mm:
        (aeDescFromJSValue): Added.
        (-[WebCoreFrameBridge aeDescByEvaluatingJavaScriptFromString:]): Added.

WebKitTools:
        * DumpRenderTree/AppleScriptController.h: Added.
        * DumpRenderTree/AppleScriptController.m: Added.
        * DumpRenderTree/DumpRenderTree.m:
        (-[WaitUntilDoneDelegate webView:windowScriptObjectAvailable:]):
        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:

LayoutTests:
        * fast/AppleScript: Added.
        * fast/AppleScript/001-expected.txt: Added.
        * fast/AppleScript/001.html: Added.
        * fast/AppleScript/array-expected.txt: Added.
        * fast/AppleScript/array.html: Added.
        * fast/AppleScript/date-expected.txt: Added.
        * fast/AppleScript/date.html: Added.

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

18 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/AppleScript/001-expected.txt [new file with mode: 0644]
LayoutTests/fast/AppleScript/001.html [new file with mode: 0644]
LayoutTests/fast/AppleScript/array-expected.txt [new file with mode: 0644]
LayoutTests/fast/AppleScript/array.html [new file with mode: 0644]
LayoutTests/fast/AppleScript/date-expected.txt [new file with mode: 0644]
LayoutTests/fast/AppleScript/date.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/bridge/mac/WebCoreFrameBridge.h
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebKit/ChangeLog
WebKit/WebView/WebView.m
WebKit/WebView/WebViewPrivate.h
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/AppleScriptController.h [new file with mode: 0644]
WebKitTools/DumpRenderTree/AppleScriptController.m [new file with mode: 0644]
WebKitTools/DumpRenderTree/DumpRenderTree.m
WebKitTools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj

index 74c274192c655ffb0a6c0353233d8f9036add6ce..64288925be8cf58829881a98f08b7ae304d3d88a 100644 (file)
@@ -1,3 +1,18 @@
+2006-02-07  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Timothy.
+
+        - tests for http://bugzilla.opendarwin.org/show_bug.cgi?id=7012
+        Convert JavaScript objects to appropriate AppleScript types, instead of only strings
+
+        * fast/AppleScript: Added.
+        * fast/AppleScript/001-expected.txt: Added.
+        * fast/AppleScript/001.html: Added.
+        * fast/AppleScript/array-expected.txt: Added.
+        * fast/AppleScript/array.html: Added.
+        * fast/AppleScript/date-expected.txt: Added.
+        * fast/AppleScript/date.html: Added.
+
 2006-02-06  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Eric.
diff --git a/LayoutTests/fast/AppleScript/001-expected.txt b/LayoutTests/fast/AppleScript/001-expected.txt
new file mode 100644 (file)
index 0000000..ac53abd
--- /dev/null
@@ -0,0 +1,22 @@
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > BODY > HTML > #document to 65 of #text > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+An automated test for basic AppleScript "do JavaScript" support.
+4 ('doub')
+4 ('doub')
+0.6666666666666666 ('doub')
+0.6666666666666666 ('doub')
+INF ('doub')
+-INF ('doub')
+false ('bool')
+false ('bool')
+a string ('utxt')
+a string ('utxt')
+An automated test for basic AppleScript "do JavaScript" support. ('utxt')
+An automated test for basic AppleScript "do JavaScript" support. ('utxt')
+[object HTMLDocument] ('utxt')
+do JavaScript - converting to AppleScript types ('utxt')
+<> ('null')
+(null)
+[object Object] ('utxt')
+
+
diff --git a/LayoutTests/fast/AppleScript/001.html b/LayoutTests/fast/AppleScript/001.html
new file mode 100644 (file)
index 0000000..2c1917f
--- /dev/null
@@ -0,0 +1,55 @@
+<html>
+<head>
+<title>do JavaScript - converting to AppleScript types</title>
+</head>
+<body>
+An automated test for basic AppleScript "do JavaScript" support.
+<script type="text/javascript">
+
+    var console_messages = document.createElement("ol");
+    
+    function log(message)
+    {
+        var item = document.createElement("li");
+        item.appendChild(document.createTextNode(message));
+        console_messages.appendChild(item);
+    }
+    if (window.layoutTestController) {
+        
+        try {
+        
+            layoutTestController.dumpAsText();
+            document.execCommand("SelectAll");
+            
+            log(appleScriptController.doJavaScript("2*2;"));
+            log(appleScriptController.doJavaScript("new Number(2*2);"));
+            log(appleScriptController.doJavaScript("2/3;"));
+            log(appleScriptController.doJavaScript("new Number(2/3);"));
+            log(appleScriptController.doJavaScript("2/0;"));
+            log(appleScriptController.doJavaScript("new Number(-2/0);"));
+            log(appleScriptController.doJavaScript("1!=1"));
+            log(appleScriptController.doJavaScript("new Boolean"));
+            log(appleScriptController.doJavaScript("'a string'"));
+            log(appleScriptController.doJavaScript("new String('a string')"));
+            log(appleScriptController.doJavaScript("window.getSelection()"));
+            log(appleScriptController.doJavaScript("window.getSelection() + \"\""));
+            log(appleScriptController.doJavaScript("document"));
+            log(appleScriptController.doJavaScript("document.title"));
+            log(appleScriptController.doJavaScript("document.lalala"));
+            log(appleScriptController.doJavaScript("document.lalala()")); // ideally, should pass the error to AppleScript
+            log(appleScriptController.doJavaScript("function Polygon() {this.edges = 8;} new Polygon;"));
+            
+        } catch (ex) {
+            log("Exception: " + ex.description);
+        }
+
+        var console = document.createElement("p");
+        console.appendChild(console_messages);
+        document.body.appendChild(console);
+        
+    } else {
+        document.write("(cannot run interactively)");
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/AppleScript/array-expected.txt b/LayoutTests/fast/AppleScript/array-expected.txt
new file mode 100644 (file)
index 0000000..7dcea08
--- /dev/null
@@ -0,0 +1,5 @@
+At the moment, toString() is just used. Perhaps, some arrays should be converted to AppleScript lists.
+1,2,three ('utxt')
+,,2 ('utxt')
+
+
diff --git a/LayoutTests/fast/AppleScript/array.html b/LayoutTests/fast/AppleScript/array.html
new file mode 100644 (file)
index 0000000..9cd35ee
--- /dev/null
@@ -0,0 +1,39 @@
+<html>
+<head>
+<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");
+    
+    function log(message)
+    {
+        var item = document.createElement("li");
+        item.appendChild(document.createTextNode(message));
+        console_messages.appendChild(item);
+    }
+    if (window.layoutTestController) {
+        
+        try {
+        
+            layoutTestController.dumpAsText();
+            
+            log(appleScriptController.doJavaScript("new Array(1, 2, 'three');"));
+            log(appleScriptController.doJavaScript("arr = new Array; arr['a'] = 'a'; arr[2] = 2; arr;"));
+            
+        } catch (ex) {
+            log("Exception: " + ex.description);
+        }
+
+        var console = document.createElement("p");
+        console.appendChild(console_messages);
+        document.body.appendChild(console);
+        
+    } else {
+        document.write("(cannot run interactively)");
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/AppleScript/date-expected.txt b/LayoutTests/fast/AppleScript/date-expected.txt
new file mode 100644 (file)
index 0000000..728804a
--- /dev/null
@@ -0,0 +1,10 @@
+<00000000 c00d6be5 > ('ldt ')
+<00000000 7c4e8f00 > ('ldt ')
+<00000000 7c25dab0 > ('ldt ')
+<00000001 383ec400 > ('ldt ')
+<00000000 56871300 > ('ldt ')
+<00000000 00000000 > ('ldt ')
+<ffffffff 3c637000 > ('ldt ')
+Invalid Date ('utxt')
+
+
diff --git a/LayoutTests/fast/AppleScript/date.html b/LayoutTests/fast/AppleScript/date.html
new file mode 100644 (file)
index 0000000..42b381e
--- /dev/null
@@ -0,0 +1,59 @@
+<html>
+<head>
+<title>do JavaScript - converting to AppleScript date type</title>
+</head>
+<body>
+<script type="text/javascript">
+
+    var console_messages = document.createElement("ol");
+    
+    function log(message)
+    {
+        var item = document.createElement("li");
+        item.appendChild(document.createTextNode(message));
+        console_messages.appendChild(item);
+    }
+    if (window.layoutTestController) {
+        
+        try {
+        
+            layoutTestController.dumpAsText();
+
+            // 0xc00d6be5 == Mon Feb 06 2006 21:11:01
+            log(appleScriptController.doJavaScript("new Date(2006,1,6,21,11,1)"));
+
+            // 0x7c4e8f00 == Sun Feb 01 1970 00:00:00
+            log(appleScriptController.doJavaScript("new Date(1970,1,1)"));
+             
+            // 0x7c25dab0 == Thu Jan 01 1970 03:00:00
+            log(appleScriptController.doJavaScript("new Date(1970,0,1,3)"));
+
+            // 0x1383ec400 == Wed Jan 01 2070 00:00:00
+            log(appleScriptController.doJavaScript("new Date(2070,0,1)"));
+            
+            // 0x56871300 == Sun Jan 01 1950 00:00:00
+            log(appleScriptController.doJavaScript("new Date(1950,0,1)"));
+            
+            // 0x00000000 == Fri Jan 01 1904 00:00:00
+            log(appleScriptController.doJavaScript("new Date(1904,0,1)"));
+            
+            // 0xffffffff3c637000 == Wed Jan 01 1800 00:00:00
+            log(appleScriptController.doJavaScript("new Date(1800,0,1)"));
+
+            // invalid date 
+            log(appleScriptController.doJavaScript("new Date(1e40)"));
+
+        } catch (ex) {
+            log("Exception: " + ex.description);
+        }
+
+        var console = document.createElement("p");
+        console.appendChild(console_messages);
+        document.body.appendChild(console);
+        
+    } else {
+        document.write("(cannot run interactively)");
+    }
+</script>
+</body>
+</html>
index 35396e01bf6f33aceaf2230c6549b3ca01353259..b9bb3e83ea5b160b434a7e2ed6f027c1df08f814 100644 (file)
@@ -1,3 +1,17 @@
+2006-02-07  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Timothy.
+
+        Convert JavaScript objects to appropriate AppleScript types, instead of only strings
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=7012
+
+        Tests: fast/AppleScript/*
+
+        * bridge/mac/WebCoreFrameBridge.h:
+        * bridge/mac/WebCoreFrameBridge.mm:
+        (aeDescFromJSValue):
+        (-[WebCoreFrameBridge aeDescByEvaluatingJavaScriptFromString:]):
+
 2006-02-07  Dave Hyatt <hyatt@apple.com>
 
         Rename ImageDecoderPlugin to ImageDecoder.  Rename
index d027b91b4db49f4386b23c9a4bb1e5ad5833fe76..2cef3c461459ff4be27fe773f0bc7e495027312e 100644 (file)
@@ -326,6 +326,7 @@ typedef enum
 
 - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)string;
 - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)string forceUserGesture:(BOOL)forceUserGesture;
+- (NSAppleEventDescriptor *)aeDescByEvaluatingJavaScriptFromString:(NSString *)string;
 
 - (DOMDocument *)DOMDocument;
 - (DOMHTMLElement *)frameElement;
index 9a3a9b4ac254ef4a81ee32d8c7f01e4cd1395a6a..69060d661fdadc3e45ad7bfbe04ffba7b41cecdd 100644 (file)
@@ -86,6 +86,7 @@
 #import <JavaScriptCore/jni_jsobject.h>
 #import <JavaScriptCore/npruntime.h>
 #import <JavaScriptCore/object.h>
+#import <JavaScriptCore/date_object.h>
 #import <JavaScriptCore/property_map.h>
 #import <JavaScriptCore/runtime_root.h>
 #import <kxmlcore/Assertions.h>
@@ -103,6 +104,19 @@ using KJS::JSValue;
 using KJS::SavedProperties;
 using KJS::SavedBuiltins;
 using KJS::Window;
+using KJS::BooleanType;
+using KJS::StringType;
+using KJS::NumberType;
+using KJS::ObjectType;
+using KJS::UnspecifiedType;
+using KJS::UndefinedType;
+using KJS::NullType;
+using KJS::GetterSetterType;
+using KJS::UString;
+using KJS::Identifier;
+using KJS::List;
+using KJS::Type;
+using KJS::DateInstance;
 
 using KJS::Bindings::RootObject;
 
@@ -188,6 +202,68 @@ static BOOL isCaseSensitiveEqual(NSString *a, NSString *b)
     return [a caseInsensitiveCompare:b] == NSOrderedSame;
 }
 
+static NSAppleEventDescriptor* aeDescFromJSValue(ExecState* exec, JSValue* jsValue)
+{
+    NSAppleEventDescriptor* aeDesc = 0;
+    switch (jsValue->type()) {
+        case BooleanType: {
+            bool value;
+            jsValue->getBoolean(value);
+            aeDesc = [NSAppleEventDescriptor descriptorWithBoolean:value];
+            break;
+        }
+        case StringType: {
+            UString value = jsValue->getString();
+            NSString* str = [NSString stringWithCharacters:reinterpret_cast<const unichar *>(value.data()) length:value.size()];
+            aeDesc = [NSAppleEventDescriptor descriptorWithString:str];
+            break;
+        }
+        case NumberType: {
+            double value = jsValue->getNumber();
+            aeDesc = [NSAppleEventDescriptor descriptorWithDescriptorType:typeIEEE64BitFloatingPoint bytes:&value length:sizeof(value)];
+            break;
+        }
+        case ObjectType: {
+            JSObject* object = jsValue->getObject();
+            if (object->inherits(&DateInstance::info)) {
+                DateInstance* date = static_cast<DateInstance*>(object);
+                double ms = 0;
+                int tzOffset = 0;
+
+                if (date->getTime(ms, tzOffset)) {
+                    CFAbsoluteTime utcSeconds = ms/1000 - kCFAbsoluteTimeIntervalSince1970;
+
+                    LongDateTime ldt;
+                    if (noErr == UCConvertCFAbsoluteTimeToLongDateTime(utcSeconds, &ldt))
+                        aeDesc = [NSAppleEventDescriptor descriptorWithDescriptorType:typeLongDateTime bytes:&ldt length:sizeof(ldt)];
+                }
+            }
+            
+            if (!aeDesc) {
+                JSValue* primitive = object->toPrimitive(exec);
+                if (exec->hadException()) {
+                    exec->clearException();
+                    return [NSAppleEventDescriptor nullDescriptor];
+                }
+                return aeDescFromJSValue(exec, primitive);
+            }
+
+            break;
+        }
+        default:
+            ERROR("Unknown JavaScript type: %d", jsValue->type());
+            // no break;
+        case UnspecifiedType:
+        case UndefinedType:
+        case NullType:
+        case GetterSetterType:
+            aeDesc = [NSAppleEventDescriptor nullDescriptor];
+            break;
+    }
+    
+    return aeDesc;
+}
+
 @implementation WebCoreFrameBridge
 
 static bool initializedObjectCacheSize = false;
@@ -1419,6 +1495,16 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     return result->getString().domString();
 }
 
+- (NSAppleEventDescriptor *)aeDescByEvaluatingJavaScriptFromString:(NSString *)string
+{
+    m_frame->createEmptyDocument();
+    JSValue* result = m_frame->executeScript(0, QString::fromNSString(string), true);
+    if (!result) // FIXME: pass errors
+        return 0;
+    JSLock lock;
+    return aeDescFromJSValue(m_frame->jScript()->interpreter()->globalExec(), result);
+}
+
 - (WebScriptObject *)windowScriptObject
 {
     return m_frame->windowScriptObject();
index 172c5222b26c2650892461b4236b060368c391fd..f64d05c128f7ea428ba8f2c055095a46eaeaa842 100644 (file)
@@ -1,3 +1,16 @@
+2006-02-07  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Timothy.
+
+        Convert JavaScript objects to appropriate AppleScript types, instead of only strings
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=7012
+
+        Tests: fast/AppleScript/*
+
+        * WebView/WebView.m:
+        (-[WebView aeDescByEvaluatingJavaScriptFromString:]): Added.
+        * WebView/WebViewPrivate.h:
+
 2006-02-06  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Eric.
index ba91eba554ce6ddb5b01b4ddf4247b3c5f6d8bd9..1539edaabde34cea1e5b5c927cbd5a1104fd8278 100644 (file)
@@ -2654,6 +2654,11 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
     return [bridge shouldClose];
 }
 
+- (NSAppleEventDescriptor *)aeDescByEvaluatingJavaScriptFromString:(NSString *)script
+{
+    return [[[self mainFrame] _bridge] aeDescByEvaluatingJavaScriptFromString:script];
+}
+
 @end
 
 @implementation WebView (WebViewPrintingPrivate)
index 19a1c9ee1c76ca4210443837f0b2654f1816db2c..41c596db35782330dfa5adf1edfb432e71f9d878 100644 (file)
@@ -117,6 +117,13 @@ typedef enum {
 
 - (BOOL)shouldClose;
 
+/*!
+    @method aeDescByEvaluatingJavaScriptFromString:
+    @param script The text of the JavaScript.
+    @result The result of the script, converted to an NSAppleEventDescriptor, or nil for failure.
+*/
+- (NSAppleEventDescriptor *)aeDescByEvaluatingJavaScriptFromString:(NSString *)script;
+
 @end
 
 @interface WebView (WebPrivate)
index 0c3684f0fcb2615f4f18db679c54df5d3bb2417d..4880d823388a742ec781189d620e98d0af08e3b3 100644 (file)
@@ -1,3 +1,16 @@
+2006-02-07  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Timothy.
+
+        Support automated testing of AppleScript "do JavaScript" command
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=7012
+
+        * DumpRenderTree/AppleScriptController.h: Added.
+        * DumpRenderTree/AppleScriptController.m: Added.
+        * DumpRenderTree/DumpRenderTree.m:
+        (-[WaitUntilDoneDelegate webView:windowScriptObjectAvailable:]):
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
+
 2006-02-06  Eric Seidel  <eseidel@apple.com>
 
         Reviewed by hyatt.
diff --git a/WebKitTools/DumpRenderTree/AppleScriptController.h b/WebKitTools/DumpRenderTree/AppleScriptController.h
new file mode 100644 (file)
index 0000000..c29789c
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+
+@class WebView;
+
+@interface AppleScriptController : NSObject
+{
+    WebView *webView;
+}
+- (id)initWithWebView:(WebView *)view;
+@end
diff --git a/WebKitTools/DumpRenderTree/AppleScriptController.m b/WebKitTools/DumpRenderTree/AppleScriptController.m
new file mode 100644 (file)
index 0000000..5fe118d
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "AppleScriptController.h"
+
+#import <WebKit/WebView.h>
+#import <WebKit/WebViewPrivate.h>   // for aeDescByEvaluatingJavaScriptFromString, which is pending API review
+
+@implementation AppleScriptController
+
++ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
+{
+    if (aSelector == @selector(doJavaScript:))
+        return NO;
+    return YES;
+}
+
++ (NSString *)webScriptNameForSelector:(SEL)aSelector
+{
+    if (aSelector == @selector(doJavaScript:))
+        return @"doJavaScript";
+
+    return nil;
+}
+
+- (id)initWithWebView:(WebView *)wv
+{
+    self = [super init];
+    webView = wv;
+    return self;
+}
+
+- (NSString *)doJavaScript:(NSString *)aString
+{
+    NSAppleEventDescriptor *aeDesc = [webView aeDescByEvaluatingJavaScriptFromString:aString];
+    if (!aeDesc)
+        return @"(null)";
+    
+    DescType descType = CFSwapInt32HostToBig([aeDesc descriptorType]);
+    id printableValue = [aeDesc stringValue];
+    if (!printableValue)
+        printableValue = [aeDesc data];
+    
+    return [NSString stringWithFormat:@"%@ ('%.4s')", printableValue, &descType];
+}
+
+@end
index 3888e4301a043a138e5047e4f79cddca941d616b..16299802334a8353e91d2d1538c02e02612e6cdf 100644 (file)
@@ -46,6 +46,7 @@
 
 #import "TextInputController.h"
 #import "NavigationController.h"
+#import "AppleScriptController.h"
 
 @interface DumpRenderTreePasteboard : NSPasteboard
 @end
@@ -356,6 +357,9 @@ static void dump(void)
     TextInputController *tic = [[TextInputController alloc] initWithWebView:sender];
     [obj setValue:tic forKey:@"textInputController"];
     [tic release];
+    AppleScriptController *asc = [[AppleScriptController alloc] initWithWebView:sender];
+    [obj setValue:asc forKey:@"appleScriptController"];
+    [asc release];
     [obj setValue:navigationController forKey:@"navigationController"];
 }
 
index 006fc662d6b7b8dd899777526233abc990531e1d..e7849e1006f1ef4b2c6d0907cda8f1f684043af1 100644 (file)
@@ -60,6 +60,8 @@
                AE8259F408D22463000507AB /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE8257EF08D22389000507AB /* Carbon.framework */; };
                B5A752A008AF5CD400138E45 /* ImageDiff.m in Sources */ = {isa = PBXBuildFile; fileRef = B5A7525808AF4A3600138E45 /* ImageDiff.m */; };
                B5A752A208AF5D1F00138E45 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5A752A108AF5D1F00138E45 /* QuartzCore.framework */; };
+               E1330800099624DA00AC0A91 /* AppleScriptController.h in Headers */ = {isa = PBXBuildFile; fileRef = E13307FE099624DA00AC0A91 /* AppleScriptController.h */; };
+               E1330801099624DA00AC0A91 /* AppleScriptController.m in Sources */ = {isa = PBXBuildFile; fileRef = E13307FF099624DA00AC0A91 /* AppleScriptController.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXBuildStyle section */
                B5A7525808AF4A3600138E45 /* ImageDiff.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = ImageDiff.m; sourceTree = "<group>"; };
                B5A7526708AF4A4A00138E45 /* ImageDiff */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ImageDiff; sourceTree = BUILT_PRODUCTS_DIR; };
                B5A752A108AF5D1F00138E45 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = /System/Library/Frameworks/QuartzCore.framework; sourceTree = "<absolute>"; };
+               E13307FE099624DA00AC0A91 /* AppleScriptController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppleScriptController.h; sourceTree = "<group>"; };
+               E13307FF099624DA00AC0A91 /* AppleScriptController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppleScriptController.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                                32A70AAB03705E1F00C91783 /* DumpRenderTreePrefix.h */,
                                93442CF408F8BA4900BFE8CA /* TextInputController.h */,
                                93442CF508F8BA4900BFE8CA /* TextInputController.m */,
+                               E13307FE099624DA00AC0A91 /* AppleScriptController.h */,
+                               E13307FF099624DA00AC0A91 /* AppleScriptController.m */,
                                B5A7525808AF4A3600138E45 /* ImageDiff.m */,
                                9335435F03D75502008635CE /* WebKit.framework */,
                                A817090308B164D300CCB9FB /* JavaScriptCore.framework */,
                                9340994C08540CAE007F3BC8 /* DumpRenderTreePrefix.h in Headers */,
                                93442CF608F8BA4900BFE8CA /* TextInputController.h in Headers */,
                                14A6FB8A0971CAE5008B014F /* NavigationController.h in Headers */,
+                               E1330800099624DA00AC0A91 /* AppleScriptController.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                9340994E08540CAE007F3BC8 /* DumpRenderTree.m in Sources */,
                                93442CF708F8BA4900BFE8CA /* TextInputController.m in Sources */,
                                14A6FB8B0971CAE5008B014F /* NavigationController.m in Sources */,
+                               E1330801099624DA00AC0A91 /* AppleScriptController.m in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };