Title: [111611] trunk
Revision
111611
Author
[email protected]
Date
2012-03-21 15:34:29 -0700 (Wed, 21 Mar 2012)

Log Message

"this" argument for MutationCallbacks should be the MutationObserver
https://bugs.webkit.org/show_bug.cgi?id=81712

Reviewed by Adam Barth.

Source/WebCore:

Test: fast/mutation/callback-arguments.html

* bindings/js/JSCallbackData.cpp:
(WebCore::JSCallbackData::invokeCallback): Add an overload that takes
an explicit this argument and have the old method call the new one.
* bindings/js/JSCallbackData.h:
(JSCallbackData):
* bindings/js/JSMutationCallbackCustom.cpp:
(WebCore::JSMutationCallback::handleEvent): Call the new overload.
* bindings/v8/custom/V8CustomVoidCallback.cpp:
(WebCore::invokeCallback): Add an overload that takes an explicit this
argument and have the old method call the new one.
* bindings/v8/custom/V8CustomVoidCallback.h:
(WebCore):
* bindings/v8/custom/V8MutationCallbackCustom.cpp:
(WebCore::V8MutationCallback::handleEvent): Call the new overload.

LayoutTests:

Merged new test with existing second-argument test.

* fast/mutation/callback-arguments-expected.txt: Added.
* fast/mutation/callback-arguments.html: Added.
* fast/mutation/callback-second-argument-expected.txt: Removed.
* fast/mutation/callback-second-argument.html: Removed.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (111610 => 111611)


--- trunk/LayoutTests/ChangeLog	2012-03-21 22:28:53 UTC (rev 111610)
+++ trunk/LayoutTests/ChangeLog	2012-03-21 22:34:29 UTC (rev 111611)
@@ -1,3 +1,17 @@
+2012-03-21  Adam Klein  <[email protected]>
+
+        "this" argument for MutationCallbacks should be the MutationObserver
+        https://bugs.webkit.org/show_bug.cgi?id=81712
+
+        Reviewed by Adam Barth.
+
+        Merged new test with existing second-argument test.
+
+        * fast/mutation/callback-arguments-expected.txt: Added.
+        * fast/mutation/callback-arguments.html: Added.
+        * fast/mutation/callback-second-argument-expected.txt: Removed.
+        * fast/mutation/callback-second-argument.html: Removed.
+
 2012-03-21  Alexandru Chiculita  <[email protected]>
 
         [CSS Shaders] Make CSS Shaders compile on Chromium

Added: trunk/LayoutTests/fast/mutation/callback-arguments-expected.txt (0 => 111611)


--- trunk/LayoutTests/fast/mutation/callback-arguments-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/mutation/callback-arguments-expected.txt	2012-03-21 22:34:29 UTC (rev 111611)
@@ -0,0 +1,11 @@
+Verifies that MutationObserver is passed to the callback as expected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS thisArgument is mutationObserver
+PASS argument2 is mutationObserver
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/mutation/callback-arguments.html (0 => 111611)


--- trunk/LayoutTests/fast/mutation/callback-arguments.html	                        (rev 0)
+++ trunk/LayoutTests/fast/mutation/callback-arguments.html	2012-03-21 22:34:29 UTC (rev 111611)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<body>
+<script src=""
+<script>
+window.jsTestIsAsync = true;
+description('Verifies that MutationObserver is passed to the callback as expected.');
+
+function mutationCallback(mutations, observer) {
+    window.thisArgument = this;
+    window.argument2 = observer;
+    shouldBe('thisArgument', 'mutationObserver');
+    shouldBe('argument2', 'mutationObserver');
+    finishJSTest();
+}
+var mutationObserver = new WebKitMutationObserver(mutationCallback);
+var div = document.createElement('div');
+mutationObserver.observe(div, {attributes: true});
+div.setAttribute('foo', 'bar');
+</script>
+<script src=""
+</body>

Deleted: trunk/LayoutTests/fast/mutation/callback-second-argument-expected.txt (111610 => 111611)


--- trunk/LayoutTests/fast/mutation/callback-second-argument-expected.txt	2012-03-21 22:28:53 UTC (rev 111610)
+++ trunk/LayoutTests/fast/mutation/callback-second-argument-expected.txt	2012-03-21 22:34:29 UTC (rev 111611)
@@ -1 +0,0 @@
-PASSED: Second argument is mutationObserver

Deleted: trunk/LayoutTests/fast/mutation/callback-second-argument.html (111610 => 111611)


--- trunk/LayoutTests/fast/mutation/callback-second-argument.html	2012-03-21 22:28:53 UTC (rev 111610)
+++ trunk/LayoutTests/fast/mutation/callback-second-argument.html	2012-03-21 22:34:29 UTC (rev 111611)
@@ -1,20 +0,0 @@
-<!DOCTYPE html>
-<body>
-<script>
-if (window.layoutTestController) {
-    layoutTestController.dumpAsText();
-    layoutTestController.waitUntilDone();
-}
-
-function mutationCallback(mutations, observer) {
-    mutations[0].addedNodes[0].textContent = (observer === mutationObserver)
-        ? 'PASSED: Second argument is mutationObserver'
-        : 'FAILED: Second argument is not mutationObserver';
-    if (window.layoutTestController)
-        layoutTestController.notifyDone();
-}
-var mutationObserver = new WebKitMutationObserver(mutationCallback);
-mutationObserver.observe(document.body, {childList: true});
-document.body.appendChild(document.createTextNode('FAILED'));
-</script>
-</body>

Modified: trunk/Source/WebCore/ChangeLog (111610 => 111611)


--- trunk/Source/WebCore/ChangeLog	2012-03-21 22:28:53 UTC (rev 111610)
+++ trunk/Source/WebCore/ChangeLog	2012-03-21 22:34:29 UTC (rev 111611)
@@ -1,3 +1,27 @@
+2012-03-21  Adam Klein  <[email protected]>
+
+        "this" argument for MutationCallbacks should be the MutationObserver
+        https://bugs.webkit.org/show_bug.cgi?id=81712
+
+        Reviewed by Adam Barth.
+
+        Test: fast/mutation/callback-arguments.html
+
+        * bindings/js/JSCallbackData.cpp:
+        (WebCore::JSCallbackData::invokeCallback): Add an overload that takes
+        an explicit this argument and have the old method call the new one.
+        * bindings/js/JSCallbackData.h:
+        (JSCallbackData):
+        * bindings/js/JSMutationCallbackCustom.cpp:
+        (WebCore::JSMutationCallback::handleEvent): Call the new overload.
+        * bindings/v8/custom/V8CustomVoidCallback.cpp:
+        (WebCore::invokeCallback): Add an overload that takes an explicit this
+        argument and have the old method call the new one.
+        * bindings/v8/custom/V8CustomVoidCallback.h:
+        (WebCore):
+        * bindings/v8/custom/V8MutationCallbackCustom.cpp:
+        (WebCore::V8MutationCallback::handleEvent): Call the new overload.
+
 2012-03-21  Alexandru Chiculita  <[email protected]>
 
         [CSS Shaders] Make CSS Shaders compile on Chromium

Modified: trunk/Source/WebCore/bindings/js/JSCallbackData.cpp (111610 => 111611)


--- trunk/Source/WebCore/bindings/js/JSCallbackData.cpp	2012-03-21 22:28:53 UTC (rev 111610)
+++ trunk/Source/WebCore/bindings/js/JSCallbackData.cpp	2012-03-21 22:34:29 UTC (rev 111611)
@@ -45,6 +45,12 @@
 JSValue JSCallbackData::invokeCallback(MarkedArgumentBuffer& args, bool* raisedException)
 {
     ASSERT(callback());
+    return invokeCallback(callback(), args, raisedException);
+}
+
+JSValue JSCallbackData::invokeCallback(JSValue thisValue, MarkedArgumentBuffer& args, bool* raisedException)
+{
+    ASSERT(callback());
     ASSERT(globalObject());
 
     ExecState* exec = globalObject()->globalExec();
@@ -58,7 +64,7 @@
         if (callType == CallTypeNone)
             return JSValue();
     }
-    
+
     ScriptExecutionContext* context = globalObject()->scriptExecutionContext();
     // We will fail to get the context if the frame has been detached.
     if (!context)
@@ -69,8 +75,8 @@
 
     bool contextIsDocument = context->isDocument();
     JSValue result = contextIsDocument
-        ? JSMainThreadExecState::call(exec, function, callType, callData, callback(), args)
-        : JSC::call(exec, function, callType, callData, callback(), args);
+        ? JSMainThreadExecState::call(exec, function, callType, callData, thisValue, args)
+        : JSC::call(exec, function, callType, callData, thisValue, args);
 
     InspectorInstrumentation::didCallFunction(cookie);
     globalObject()->globalData().timeoutChecker.stop();
@@ -84,8 +90,8 @@
             *raisedException = true;
         return result;
     }
-    
+
     return result;
 }
-    
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/JSCallbackData.h (111610 => 111611)


--- trunk/Source/WebCore/bindings/js/JSCallbackData.h	2012-03-21 22:28:53 UTC (rev 111610)
+++ trunk/Source/WebCore/bindings/js/JSCallbackData.h	2012-03-21 22:34:29 UTC (rev 111611)
@@ -65,6 +65,7 @@
     JSDOMGlobalObject* globalObject() { return m_globalObject.get(); }
     
     JSC::JSValue invokeCallback(JSC::MarkedArgumentBuffer&, bool* raisedException = 0);
+    JSC::JSValue invokeCallback(JSC::JSValue thisValue, JSC::MarkedArgumentBuffer&, bool* raisedException = 0);
 
 private:
     JSC::Strong<JSC::JSObject> m_callback;

Modified: trunk/Source/WebCore/bindings/js/JSMutationCallbackCustom.cpp (111610 => 111611)


--- trunk/Source/WebCore/bindings/js/JSMutationCallbackCustom.cpp	2012-03-21 22:28:53 UTC (rev 111610)
+++ trunk/Source/WebCore/bindings/js/JSMutationCallbackCustom.cpp	2012-03-21 22:34:29 UTC (rev 111611)
@@ -58,12 +58,14 @@
     for (size_t i = 0; i < mutations->size(); ++i)
         mutationList.append(toJS(exec, m_data->globalObject(), mutations->at(i).get()));
 
+    JSValue jsObserver = toJS(exec, m_data->globalObject(), observer);
+
     MarkedArgumentBuffer args;
     args.append(constructArray(exec, m_data->globalObject(), mutationList));
-    args.append(toJS(exec, m_data->globalObject(), observer));
+    args.append(jsObserver);
 
     bool raisedException = false;
-    m_data->invokeCallback(args, &raisedException);
+    m_data->invokeCallback(jsObserver, args, &raisedException);
     return !raisedException;
 }
 

Modified: trunk/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp (111610 => 111611)


--- trunk/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp	2012-03-21 22:28:53 UTC (rev 111610)
+++ trunk/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.cpp	2012-03-21 22:34:29 UTC (rev 111611)
@@ -65,6 +65,11 @@
 
 bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext)
 {
+    return invokeCallback(callback, v8::Context::GetCurrent()->Global(), argc, argv, callbackReturnValue, scriptExecutionContext);
+}
+
+bool invokeCallback(v8::Persistent<v8::Object> callback, v8::Handle<v8::Object> thisObject, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext)
+{
     v8::TryCatch exceptionCatcher;
     exceptionCatcher.SetVerbose(true);
 
@@ -81,8 +86,6 @@
     if (callbackFunction.IsEmpty())
         return false;
 
-    v8::Handle<v8::Object> thisObject = v8::Context::GetCurrent()->Global();
-
     Frame* frame = scriptExecutionContext && scriptExecutionContext->isDocument() ? static_cast<Document*>(scriptExecutionContext)->frame() : 0;
     v8::Handle<v8::Value> result = V8Proxy::instrumentedCallFunction(frame, callbackFunction, thisObject, argc, argv);
 

Modified: trunk/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.h (111610 => 111611)


--- trunk/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.h	2012-03-21 22:28:53 UTC (rev 111610)
+++ trunk/Source/WebCore/bindings/v8/custom/V8CustomVoidCallback.h	2012-03-21 22:34:29 UTC (rev 111611)
@@ -61,7 +61,8 @@
 };
 
 // Returns false if callback failed (null, wrong type, or threw exception).
-bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext);
+bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext*);
+bool invokeCallback(v8::Persistent<v8::Object> callback, v8::Handle<v8::Object> thisObject, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext*);
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/bindings/v8/custom/V8MutationCallbackCustom.cpp (111610 => 111611)


--- trunk/Source/WebCore/bindings/v8/custom/V8MutationCallbackCustom.cpp	2012-03-21 22:28:53 UTC (rev 111610)
+++ trunk/Source/WebCore/bindings/v8/custom/V8MutationCallbackCustom.cpp	2012-03-21 22:34:29 UTC (rev 111611)
@@ -75,13 +75,16 @@
         return true;
     }
 
+    if (!observerHandle->IsObject())
+        return true;
+
     v8::Handle<v8::Value> argv[] = {
         mutationsArray,
         observerHandle
     };
 
     bool callbackReturnValue = false;
-    return !invokeCallback(m_callback, 2, argv, callbackReturnValue, scriptExecutionContext());
+    return !invokeCallback(m_callback, v8::Handle<v8::Object>::Cast(observerHandle), 2, argv, callbackReturnValue, scriptExecutionContext());
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to