Return value from executed script in Chromium.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Apr 2012 01:10:25 +0000 (01:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Apr 2012 01:10:25 +0000 (01:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79851

Patch by Eriq Augustine <eaugusti@chromium.org> on 2012-04-23
Reviewed by Adam Barth.

Source/WebCore:

Providing a varaiant of evaluateScriptInIsolatedWorld that
returns the value of the evaluated script.

Test: platform/chromium/http/tests/misc/execute-and-return-value.html

* bindings/v8/ScriptController.cpp:
(WebCore::ScriptController::evaluateInIsolatedWorld):
* bindings/v8/ScriptController.h:
(ScriptController):
* bindings/v8/V8Proxy.cpp:
(WebCore::V8Proxy::evaluateInIsolatedWorld):
* bindings/v8/V8Proxy.h:
(V8Proxy):

Source/WebKit/chromium:

Providing a variant of evaluateScriptInIsolatedWorld that
returns the value of the evaluated script.

* public/WebFrame.h:
(WebFrame):
* src/WebFrameImpl.cpp:
(WebKit::WebFrameImpl::executeScriptInIsolatedWorldAndReturnValues):
(WebKit):
* src/WebFrameImpl.h:
(WebKit):
(WebFrameImpl):

Tools:

Adding a function to LayoutTestController that evaluates a script in
an isolated wold an returns the result of the evaluation.

* DumpRenderTree/LayoutTestController.cpp:
(evaluateScriptInIsolatedWorldAndReturnValue):
(LayoutTestController::staticFunctions):
* DumpRenderTree/LayoutTestController.h:
(LayoutTestController):
* DumpRenderTree/blackberry/LayoutTestControllerBlackBerry.cpp:
(LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
* DumpRenderTree/chromium/LayoutTestController.cpp:
(LayoutTestController::LayoutTestController):
(LayoutTestController::setXSSAuditorEnabled):
(LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
* DumpRenderTree/chromium/LayoutTestController.h:
(LayoutTestController):
* DumpRenderTree/efl/LayoutTestControllerEfl.cpp:
(LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
* DumpRenderTree/gtk/LayoutTestControllerGtk.cpp:
(LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
* DumpRenderTree/mac/LayoutTestControllerMac.mm:
(LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
* DumpRenderTree/qt/LayoutTestControllerQt.cpp:
(LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
* DumpRenderTree/qt/LayoutTestControllerQt.h:
(LayoutTestController):
* DumpRenderTree/win/LayoutTestControllerWin.cpp:
(LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
* DumpRenderTree/wx/LayoutTestControllerWx.cpp:
(LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):

LayoutTests:

Testing executing a script and getting the result of that script.

* platform/chromium/http/tests/misc/execute-and-return-value-expected.txt: Added.
* platform/chromium/http/tests/misc/execute-and-return-value.html: Added.

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

25 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/chromium/http/tests/misc/execute-and-return-value-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/http/tests/misc/execute-and-return-value.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/v8/ScriptController.cpp
Source/WebCore/bindings/v8/ScriptController.h
Source/WebCore/bindings/v8/V8Proxy.cpp
Source/WebCore/bindings/v8/V8Proxy.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebFrame.h
Source/WebKit/chromium/src/WebFrameImpl.cpp
Source/WebKit/chromium/src/WebFrameImpl.h
Tools/ChangeLog
Tools/DumpRenderTree/LayoutTestController.cpp
Tools/DumpRenderTree/LayoutTestController.h
Tools/DumpRenderTree/blackberry/LayoutTestControllerBlackBerry.cpp
Tools/DumpRenderTree/chromium/LayoutTestController.cpp
Tools/DumpRenderTree/chromium/LayoutTestController.h
Tools/DumpRenderTree/efl/LayoutTestControllerEfl.cpp
Tools/DumpRenderTree/gtk/LayoutTestControllerGtk.cpp
Tools/DumpRenderTree/mac/LayoutTestControllerMac.mm
Tools/DumpRenderTree/qt/LayoutTestControllerQt.cpp
Tools/DumpRenderTree/qt/LayoutTestControllerQt.h
Tools/DumpRenderTree/win/LayoutTestControllerWin.cpp
Tools/DumpRenderTree/wx/LayoutTestControllerWx.cpp

index 2147c23..c01e7f2 100644 (file)
@@ -1,3 +1,15 @@
+2012-04-23  Eriq Augustine  <eaugusti@chromium.org>
+
+        Return value from executed script in Chromium.
+        https://bugs.webkit.org/show_bug.cgi?id=79851
+
+        Reviewed by Adam Barth.
+
+        Testing executing a script and getting the result of that script.
+
+        * platform/chromium/http/tests/misc/execute-and-return-value-expected.txt: Added.
+        * platform/chromium/http/tests/misc/execute-and-return-value.html: Added.
+
 2012-04-23  Kent Tamura  <tkent@chromium.org>
 
         RenderDetailsMarker should draw the triangle inside the content box
diff --git a/LayoutTests/platform/chromium/http/tests/misc/execute-and-return-value-expected.txt b/LayoutTests/platform/chromium/http/tests/misc/execute-and-return-value-expected.txt
new file mode 100644 (file)
index 0000000..2ab854d
--- /dev/null
@@ -0,0 +1,6 @@
+Expecting 5: 5
+Expecting 3.14: 3.14
+Expecting "The quick brown dog.": The quick brown dog.
+Expecting false: false
+Expecting null: null
+
diff --git a/LayoutTests/platform/chromium/http/tests/misc/execute-and-return-value.html b/LayoutTests/platform/chromium/http/tests/misc/execute-and-return-value.html
new file mode 100644 (file)
index 0000000..fc79e03
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script>
+if (window.layoutTestController) {
+  layoutTestController.dumpAsText();
+
+  var intTest = layoutTestController.evaluateScriptInIsolatedWorldAndReturnValue(0, "5");
+  document.body.appendChild(document.createTextNode('Expecting 5: ' + intTest));
+  document.body.appendChild(document.createElement('br'));
+
+  var doubleTest = layoutTestController.evaluateScriptInIsolatedWorldAndReturnValue(0, "3.14");
+  document.body.appendChild(document.createTextNode('Expecting 3.14: ' + doubleTest));
+  document.body.appendChild(document.createElement('br'));
+
+  var stringTest = layoutTestController.evaluateScriptInIsolatedWorldAndReturnValue(0, '"The quick brown dog."');
+  document.body.appendChild(document.createTextNode('Expecting "The quick brown dog.": ' + stringTest));
+  document.body.appendChild(document.createElement('br'));
+
+  var booleanTest = layoutTestController.evaluateScriptInIsolatedWorldAndReturnValue(0, "!true");
+  document.body.appendChild(document.createTextNode('Expecting false: ' + booleanTest));
+  document.body.appendChild(document.createElement('br'));
+
+  var nullTest = layoutTestController.evaluateScriptInIsolatedWorldAndReturnValue(0, "null");
+  document.body.appendChild(document.createTextNode('Expecting null: ' + nullTest));
+  document.body.appendChild(document.createElement('br'));
+}
+</script>
+</body>
+</html>
index 187dc61..7b44cd0 100644 (file)
@@ -1,3 +1,24 @@
+2012-04-23  Eriq Augustine  <eaugusti@chromium.org>
+
+        Return value from executed script in Chromium.
+        https://bugs.webkit.org/show_bug.cgi?id=79851
+
+        Reviewed by Adam Barth.
+
+        Providing a varaiant of evaluateScriptInIsolatedWorld that
+        returns the value of the evaluated script.
+
+        Test: platform/chromium/http/tests/misc/execute-and-return-value.html
+
+        * bindings/v8/ScriptController.cpp:
+        (WebCore::ScriptController::evaluateInIsolatedWorld):
+        * bindings/v8/ScriptController.h:
+        (ScriptController):
+        * bindings/v8/V8Proxy.cpp:
+        (WebCore::V8Proxy::evaluateInIsolatedWorld):
+        * bindings/v8/V8Proxy.h:
+        (V8Proxy):
+
 2012-04-23  Kent Tamura  <tkent@chromium.org>
 
         RenderDetailsMarker should draw the triangle inside the content box
index beb426c..b554d55 100644 (file)
@@ -170,14 +170,22 @@ ScriptValue ScriptController::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Fu
     return ScriptValue(m_proxy->callFunction(function, receiver, argc, argv));
 }
 
-void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources)
+void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources, Vector<ScriptValue>* results)
 {
-    m_proxy->evaluateInIsolatedWorld(worldID, sources, 0);
+    evaluateInIsolatedWorld(worldID, sources, 0, results);
 }
 
-void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup)
+void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results)
 {
-    m_proxy->evaluateInIsolatedWorld(worldID, sources, extensionGroup);
+    v8::HandleScope handleScope;
+    if (results) {
+        Vector<v8::Local<v8::Value> > v8Results;
+        m_proxy->evaluateInIsolatedWorld(worldID, sources, extensionGroup, &v8Results);
+        Vector<v8::Local<v8::Value> >::iterator itr;
+        for (itr = v8Results.begin(); itr != v8Results.end(); ++itr)
+            results->append(ScriptValue(*itr));
+    } else
+        m_proxy->evaluateInIsolatedWorld(worldID, sources, extensionGroup, 0);
 }
 
 void ScriptController::setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin> securityOrigin)
@@ -380,7 +388,7 @@ void ScriptController::evaluateInWorld(const ScriptSourceCode& source,
     Vector<ScriptSourceCode> sources;
     sources.append(source);
     // FIXME: Get an ID from the world param.
-    evaluateInIsolatedWorld(0, sources);
+    evaluateInIsolatedWorld(0, sources, 0);
 }
 
 static NPObject* createNoScriptObject()
index 7b9e6ba..b394bed 100644 (file)
@@ -87,7 +87,7 @@ public:
     // as a string.
     ScriptValue evaluate(const ScriptSourceCode&);
 
-    void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>&);
+    void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources, Vector<ScriptValue>* results);
 
     // Executes JavaScript in an isolated world. The script gets its own global scope,
     // its own prototypes for intrinsic JavaScript objects (String, Array, and so-on),
@@ -99,7 +99,7 @@ public:
     // If the worldID is 0, a new world is always created.
     //
     // FIXME: Get rid of extensionGroup here.
-    void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>&, int extensionGroup);
+    void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results);
 
     // Associates an isolated world (see above for description) with a security
     // origin. XMLHttpRequest instances used in that world will be considered
index 82d740a..6961284 100644 (file)
@@ -217,7 +217,7 @@ bool V8Proxy::handleOutOfMemory()
     return true;
 }
 
-void V8Proxy::evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup)
+void V8Proxy::evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, WTF::Vector<v8::Local<v8::Value> >* results)
 {
     // FIXME: This will need to get reorganized once we have a windowShell for the isolated world.
     if (!windowShell()->initContextIfNeeded())
@@ -240,7 +240,7 @@ void V8Proxy::evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode
             // FIXME: We should change this to using window shells to match JSC.
             m_isolatedWorlds.set(worldID, isolatedContext);
         }
-        
+
         IsolatedWorldSecurityOriginMap::iterator securityOriginIter = m_isolatedWorldSecurityOrigins.find(worldID);
         if (securityOriginIter != m_isolatedWorldSecurityOrigins.end())
             isolatedContext->setSecurityOrigin(securityOriginIter->second);
@@ -254,11 +254,17 @@ void V8Proxy::evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode
 
     v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolatedContext->context());
     v8::Context::Scope context_scope(context);
-    for (size_t i = 0; i < sources.size(); ++i)
-      evaluate(sources[i], 0);
+
+    if (results) {
+        for (size_t i = 0; i < sources.size(); ++i)
+            results->append(evaluate(sources[i], 0));
+    } else {
+        for (size_t i = 0; i < sources.size(); ++i)
+            evaluate(sources[i], 0);
+    }
 
     if (worldID == 0)
-      isolatedContext->destroy();
+        isolatedContext->destroy();
 }
 
 void V8Proxy::setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin> prpSecurityOriginIn)
index 4f542b3..8319764 100644 (file)
@@ -147,8 +147,8 @@ namespace WebCore {
         // global scope, its own prototypes for intrinsic JavaScript objects (String,
         // Array, and so-on), and its own wrappers for all DOM nodes and DOM
         // constructors.
-        void evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup);
-        
+        void evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, WTF::Vector<v8::Local<v8::Value> >* result);
+
         void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin>);
 
         // Evaluate a script file in the current execution environment.
index bb8ec07..40c6bd8 100644 (file)
@@ -1,3 +1,22 @@
+2012-04-23  Eriq Augustine  <eaugusti@chromium.org>
+
+        Return value from executed script in Chromium.
+        https://bugs.webkit.org/show_bug.cgi?id=79851
+
+        Reviewed by Adam Barth.
+
+        Providing a variant of evaluateScriptInIsolatedWorld that
+        returns the value of the evaluated script.
+
+        * public/WebFrame.h:
+        (WebFrame):
+        * src/WebFrameImpl.cpp:
+        (WebKit::WebFrameImpl::executeScriptInIsolatedWorldAndReturnValues):
+        (WebKit):
+        * src/WebFrameImpl.h:
+        (WebKit):
+        (WebFrameImpl):
+
 2012-04-23  Raymond Toy  <rtoy@google.com>
 
         Move AudioDestinationChromium FIFO class to its own class.
index 19a7c37..cd0f1a5 100644 (file)
@@ -276,6 +276,10 @@ public:
     virtual v8::Handle<v8::Value> executeScriptAndReturnValue(
         const WebScriptSource&) = 0;
 
+    virtual void executeScriptInIsolatedWorld(
+        int worldID, const WebScriptSource* sourcesIn, unsigned numSources,
+        int extensionGroup, WebVector<v8::Local<v8::Value> >* results) = 0;
+
     // Call the function with the given receiver and arguments, bypassing
     // canExecute().
     virtual v8::Handle<v8::Value> callFunctionEvenIfScriptDisabled(
index 3f9d9d3..c26ff8c 100644 (file)
@@ -829,7 +829,7 @@ void WebFrameImpl::executeScriptInIsolatedWorld(
             sourcesIn[i].code, sourcesIn[i].url, position));
     }
 
-    m_frame->script()->evaluateInIsolatedWorld(worldID, sources, extensionGroup);
+    m_frame->script()->evaluateInIsolatedWorld(worldID, sources, extensionGroup, 0);
 }
 
 void WebFrameImpl::setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin& securityOrigin)
@@ -896,6 +896,28 @@ v8::Handle<v8::Value> WebFrameImpl::executeScriptAndReturnValue(const WebScriptS
     return m_frame->script()->executeScript(ScriptSourceCode(source.code, source.url, position)).v8Value();
 }
 
+void WebFrameImpl::executeScriptInIsolatedWorld(
+    int worldID, const WebScriptSource* sourcesIn, unsigned numSources,
+    int extensionGroup, WebVector<v8::Local<v8::Value> >* results)
+{
+    Vector<ScriptSourceCode> sources;
+
+    for (unsigned i = 0; i < numSources; ++i) {
+        TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startLine), OrdinalNumber::first());
+        sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, position));
+    }
+
+    if (results) {
+        Vector<ScriptValue> scriptResults;
+        m_frame->script()->evaluateInIsolatedWorld(worldID, sources, extensionGroup, &scriptResults);
+        WebVector<v8::Local<v8::Value> > v8Results(scriptResults.size());
+        for (unsigned i = 0; i < scriptResults.size(); i++)
+            v8Results[i] = v8::Local<v8::Value>::New(scriptResults[i].v8Value());
+        results->swap(v8Results);
+    } else
+        m_frame->script()->evaluateInIsolatedWorld(worldID, sources, extensionGroup, 0);
+}
+
 // Call the function with the given receiver and arguments, bypassing canExecuteScripts.
 v8::Handle<v8::Value> WebFrameImpl::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Function> function,
                                                                      v8::Handle<v8::Object> receiver,
index 3abc6c4..8856d86 100644 (file)
@@ -62,6 +62,8 @@ class WebPluginContainerImpl;
 class WebView;
 class WebViewImpl;
 
+template <typename T> class WebVector;
+
 // Implementation of WebFrame, note that this is a reference counted object.
 class WebFrameImpl : public WebFrame, public RefCounted<WebFrameImpl> {
 public:
@@ -110,6 +112,9 @@ public:
 #if WEBKIT_USING_V8
     virtual v8::Handle<v8::Value> executeScriptAndReturnValue(
         const WebScriptSource&);
+    virtual void executeScriptInIsolatedWorld(
+        int worldID, const WebScriptSource* sourcesIn, unsigned numSources,
+        int extensionGroup, WebVector<v8::Local<v8::Value> >* results);
     virtual v8::Handle<v8::Value> callFunctionEvenIfScriptDisabled(
         v8::Handle<v8::Function>,
         v8::Handle<v8::Object>,
index 7df4d68..79935c5 100644 (file)
@@ -1,3 +1,41 @@
+2012-04-23  Eriq Augustine  <eaugusti@chromium.org>
+
+        Return value from executed script in Chromium.
+        https://bugs.webkit.org/show_bug.cgi?id=79851
+
+        Reviewed by Adam Barth.
+
+        Adding a function to LayoutTestController that evaluates a script in
+        an isolated wold an returns the result of the evaluation.
+
+        * DumpRenderTree/LayoutTestController.cpp:
+        (evaluateScriptInIsolatedWorldAndReturnValue):
+        (LayoutTestController::staticFunctions):
+        * DumpRenderTree/LayoutTestController.h:
+        (LayoutTestController):
+        * DumpRenderTree/blackberry/LayoutTestControllerBlackBerry.cpp:
+        (LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
+        * DumpRenderTree/chromium/LayoutTestController.cpp:
+        (LayoutTestController::LayoutTestController):
+        (LayoutTestController::setXSSAuditorEnabled):
+        (LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
+        * DumpRenderTree/chromium/LayoutTestController.h:
+        (LayoutTestController):
+        * DumpRenderTree/efl/LayoutTestControllerEfl.cpp:
+        (LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
+        * DumpRenderTree/gtk/LayoutTestControllerGtk.cpp:
+        (LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
+        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
+        (LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
+        * DumpRenderTree/qt/LayoutTestControllerQt.cpp:
+        (LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
+        * DumpRenderTree/qt/LayoutTestControllerQt.h:
+        (LayoutTestController):
+        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
+        (LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
+        * DumpRenderTree/wx/LayoutTestControllerWx.cpp:
+        (LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue):
+
 2012-04-23  Dirk Pranke  <dpranke@chromium.org>
 
         run-perf-tests fail intermittently with an exception
index b7ca36d..e0944e5 100644 (file)
@@ -1827,6 +1827,18 @@ static JSValueRef evaluateScriptInIsolatedWorldCallback(JSContextRef context, JS
     return JSValueMakeUndefined(context);
 }
 
+static JSValueRef evaluateScriptInIsolatedWorldAndReturnValueCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+    double worldID = JSValueToNumber(context, arguments[0], exception);
+    ASSERT(!*exception);
+    JSRetainPtr<JSStringRef> script(Adopt, JSValueToStringCopy(context, arguments[1], exception));
+    ASSERT(!*exception);
+
+    controller->evaluateScriptInIsolatedWorldAndReturnValue(static_cast<unsigned>(worldID), JSContextGetGlobalObject(context), script.get());
+    return JSValueMakeUndefined(context);
+}
+
 static JSValueRef elementDoesAutoCompleteForElementWithIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
@@ -2351,6 +2363,7 @@ JSStaticFunction* LayoutTestController::staticFunctions()
         { "elementDoesAutoCompleteForElementWithId", elementDoesAutoCompleteForElementWithIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "encodeHostName", encodeHostNameCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "evaluateInWebInspector", evaluateInWebInspectorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "evaluateScriptInIsolatedWorldAndReturnValue", evaluateScriptInIsolatedWorldAndReturnValueCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "evaluateScriptInIsolatedWorld", evaluateScriptInIsolatedWorldCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "execCommand", execCommandCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "findString", findStringCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index f5ea242..a11387d 100644 (file)
@@ -311,6 +311,7 @@ public:
     void closeWebInspector();
     void evaluateInWebInspector(long callId, JSStringRef script);
     void evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script);
+    void evaluateScriptInIsolatedWorldAndReturnValue(unsigned worldID, JSObjectRef globalObject, JSStringRef script);
     void allowRoundingHacks();
 
     bool shouldStayOnPageAfterHandlingBeforeUnload() const { return m_shouldStayOnPageAfterHandlingBeforeUnload; }
index 0a6c580..a62755b 100644 (file)
@@ -502,6 +502,14 @@ void LayoutTestController::evaluateInWebInspector(long callId, JSStringRef scrip
     notImplemented();
 }
 
+void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
+{
+    UNUSED_PARAM(worldID);
+    UNUSED_PARAM(globalObject);
+    UNUSED_PARAM(script);
+    notImplemented();
+}
+
 void LayoutTestController::evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
 {
     UNUSED_PARAM(worldID);
index 9ae31e8..7378183 100644 (file)
@@ -128,6 +128,7 @@ LayoutTestController::LayoutTestController(TestShell* shell)
     bindMethod("enableAutoResizeMode", &LayoutTestController::enableAutoResizeMode);
     bindMethod("evaluateInWebInspector", &LayoutTestController::evaluateInWebInspector);
     bindMethod("evaluateScriptInIsolatedWorld", &LayoutTestController::evaluateScriptInIsolatedWorld);
+    bindMethod("evaluateScriptInIsolatedWorldAndReturnValue", &LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue);
     bindMethod("setIsolatedWorldSecurityOrigin", &LayoutTestController::setIsolatedWorldSecurityOrigin);
     bindMethod("execCommand", &LayoutTestController::execCommand);
     bindMethod("forceRedSelectionColors", &LayoutTestController::forceRedSelectionColors);
@@ -1334,6 +1335,36 @@ void LayoutTestController::setXSSAuditorEnabled(const CppArgumentList& arguments
     result->setNull();
 }
 
+void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(const CppArgumentList& arguments, CppVariant* result)
+{
+    v8::HandleScope scope;
+    WebVector<v8::Local<v8::Value> > values;
+    if (arguments.size() >= 2 && arguments[0].isNumber() && arguments[1].isString()) {
+        WebScriptSource source(cppVariantToWebString(arguments[1]));
+        // This relies on the iframe focusing itself when it loads. This is a bit
+        // sketchy, but it seems to be what other tests do.
+        m_shell->webView()->focusedFrame()->executeScriptInIsolatedWorld(arguments[0].toInt32(), &source, 1, 1, &values);
+    }
+    result->setNull();
+    // Since only one script was added, only one result is expected
+    if (values.size() == 1 && !values[0].IsEmpty()) {
+        v8::Local<v8::Value> scriptValue = values[0];
+        // FIXME: There are many more types that can be handled.
+        if (scriptValue->IsString()) {
+            v8::String::AsciiValue asciiV8(scriptValue);
+            result->set(std::string(*asciiV8));
+        } else if (scriptValue->IsBoolean())
+            result->set(scriptValue->ToBoolean()->Value());
+        else if (scriptValue->IsNumber()) {
+            if (scriptValue->IsInt32())
+                result->set(scriptValue->ToInt32()->Value());
+            else
+                result->set(scriptValue->ToNumber()->Value());
+        } else if (scriptValue->IsNull())
+              result->setNull();
+    }
+}
+
 void LayoutTestController::evaluateScriptInIsolatedWorld(const CppArgumentList& arguments, CppVariant* result)
 {
     if (arguments.size() >= 2 && arguments[0].isNumber() && arguments[1].isString()) {
index 5b83002..e8f87e6 100644 (file)
@@ -289,6 +289,7 @@ public:
     void setAllowFileAccessFromFileURLs(const CppArgumentList&, CppVariant*);
     void setAllowRunningOfInsecureContent(const CppArgumentList&, CppVariant*);
 
+    void evaluateScriptInIsolatedWorldAndReturnValue(const CppArgumentList&, CppVariant*);
     void evaluateScriptInIsolatedWorld(const CppArgumentList&, CppVariant*);
     void setIsolatedWorldSecurityOrigin(const CppArgumentList&, CppVariant*);
 
index 93a917f..81e73e3 100644 (file)
@@ -692,6 +692,11 @@ void LayoutTestController::evaluateInWebInspector(long, JSStringRef)
     notImplemented();
 }
 
+void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(unsigned, JSObjectRef, JSStringRef)
+{
+    notImplemented();
+}
+
 void LayoutTestController::evaluateScriptInIsolatedWorld(unsigned, JSObjectRef, JSStringRef)
 {
     notImplemented();
index 375a206..716b72d 100644 (file)
@@ -916,6 +916,11 @@ void LayoutTestController::evaluateInWebInspector(long callId, JSStringRef scrip
     g_free(scriptString);
 }
 
+void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
+{
+    // FIXME: Implement this.
+}
+
 void LayoutTestController::evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
 {
     // FIXME: Implement this.
index 18991ce..cf08e54 100644 (file)
@@ -952,6 +952,11 @@ unsigned worldIDForWorld(WebScriptWorld *world)
     return 0;
 }
 
+void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
+{
+    // FIXME: Implement this.
+}
+
 void LayoutTestController::evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
 {
     RetainPtr<CFStringRef> scriptCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, script));
index 7365a3a..0309d0a 100644 (file)
@@ -910,6 +910,11 @@ void LayoutTestController::startSpeechInput(const QString& inputElement)
     // See https://bugs.webkit.org/show_bug.cgi?id=39485.
 }
 
+void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(int worldID, const QString& script)
+{
+    // FIXME: Implement.
+}
+
 void LayoutTestController::evaluateScriptInIsolatedWorld(int worldID, const QString& script)
 {
     DumpRenderTreeSupportQt::evaluateScriptInIsolatedWorld(m_drt->webPage()->mainFrame(), worldID, script);
index a397fba..ebd2279 100644 (file)
@@ -258,6 +258,7 @@ public slots:
 
     void setEditingBehavior(const QString& editingBehavior);
 
+    void evaluateScriptInIsolatedWorldAndReturnValue(int worldID, const QString& script);
     void evaluateScriptInIsolatedWorld(int worldID, const QString& script);
     bool isPageBoxVisible(int pageIndex);
     QString pageSizeAndMarginsInPixels(int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
index 1b6a415..ae7e09c 100644 (file)
@@ -1289,6 +1289,11 @@ unsigned worldIDForWorld(IWebScriptWorld* world)
     return 0;
 }
 
+void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
+{
+    // FIXME: Implement this.
+}
+
 void LayoutTestController::evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
 {
     COMPtr<IWebFramePrivate> framePrivate(Query, frame);
index 5ba9587..5a0fc72 100644 (file)
@@ -456,6 +456,11 @@ void LayoutTestController::removeAllVisitedLinks()
     // FIXME: Implement this.
 }
 
+void LayoutTestController::evaluateScriptInIsolatedWorldAndReturnValue(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
+{
+
+}
+
 void LayoutTestController::evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script)
 {