window.postMessage() / focus() / blur() throw a TypeError when called on a RemoteDOMWindow
https://bugs.webkit.org/show_bug.cgi?id=184981

Reviewed by Sam Weinig.

Source/WebCore:

window.postMessage() / focus() / blur() was throwing a TypeError when called on a RemoteDOMWindow,
complaining that |this| is not a Window. This was caused by a copy & paste mistake in
JSDOMWindowCustom where we were calling the JSDOMWindow methods instead of the JSRemoteDOMWindow
ones.

No new tests, updated existing tests.

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::jsDOMWindowGetOwnPropertySlotRestrictedAccess):
* page/RemoteDOMWindow.cpp:
(WebCore::RemoteDOMWindow::postMessage):
* page/RemoteDOMWindow.h:
* page/RemoteDOMWindow.idl:

LayoutTests:

Add layout test coverage.

* http/tests/navigation/process-swap-window-open-expected.txt:
* http/tests/navigation/process-swap-window-open.html:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@231037 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index c602e3f..ab59b83 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
+2018-04-25  Chris Dumez  <cdumez@apple.com>
+
+        window.postMessage() / focus() / blur() throw a TypeError when called on a RemoteDOMWindow
+        https://bugs.webkit.org/show_bug.cgi?id=184981
+
+        Reviewed by Sam Weinig.
+
+        Add layout test coverage.
+
+        * http/tests/navigation/process-swap-window-open-expected.txt:
+        * http/tests/navigation/process-swap-window-open.html:
+
 2018-04-25  Jiewen Tan  <jiewen_tan@apple.com>
 
         Unreviewed test gardening
diff --git a/LayoutTests/http/tests/navigation/process-swap-window-open-expected.txt b/LayoutTests/http/tests/navigation/process-swap-window-open-expected.txt
index d8bf5d0..4762dcd 100644
--- a/LayoutTests/http/tests/navigation/process-swap-window-open-expected.txt
+++ b/LayoutTests/http/tests/navigation/process-swap-window-open-expected.txt
@@ -28,6 +28,9 @@
 PASS w.focus is an instance of Function
 PASS w.blur is an instance of Function
 PASS w.postMessage is an instance of Function
+PASS w.postMessage('test', '*') did not throw exception.
+PASS w.focus() did not throw exception.
+PASS w.blur() did not throw exception.
 PASS w.location did not throw exception.
 FAIL w.location should not be null.
 PASS areArraysEqual(actual_properties, expected_property_names) is true
diff --git a/LayoutTests/http/tests/navigation/process-swap-window-open.html b/LayoutTests/http/tests/navigation/process-swap-window-open.html
index bc40e45..cff0f0a 100644
--- a/LayoutTests/http/tests/navigation/process-swap-window-open.html
+++ b/LayoutTests/http/tests/navigation/process-swap-window-open.html
@@ -36,6 +36,9 @@
     shouldBeType("w.focus", "Function");
     shouldBeType("w.blur", "Function");
     shouldBeType("w.postMessage", "Function");
+    shouldNotThrow("w.postMessage('test', '*')");
+    shouldNotThrow("w.focus()");
+    shouldNotThrow("w.blur()");
 
     shouldNotThrow("w.location");
     shouldNotBe("w.location", "null");
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 5ccacf3..5c74517 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,24 @@
+2018-04-25  Chris Dumez  <cdumez@apple.com>
+
+        window.postMessage() / focus() / blur() throw a TypeError when called on a RemoteDOMWindow
+        https://bugs.webkit.org/show_bug.cgi?id=184981
+
+        Reviewed by Sam Weinig.
+
+        window.postMessage() / focus() / blur() was throwing a TypeError when called on a RemoteDOMWindow,
+        complaining that |this| is not a Window. This was caused by a copy & paste mistake in
+        JSDOMWindowCustom where we were calling the JSDOMWindow methods instead of the JSRemoteDOMWindow
+        ones.
+
+        No new tests, updated existing tests.
+
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::jsDOMWindowGetOwnPropertySlotRestrictedAccess):
+        * page/RemoteDOMWindow.cpp:
+        (WebCore::RemoteDOMWindow::postMessage):
+        * page/RemoteDOMWindow.h:
+        * page/RemoteDOMWindow.idl:
+
 2018-04-25  Simon Fraser  <simon.fraser@apple.com>
 
         brightness() filter should default to 1, and not allow negative values
diff --git a/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp b/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
index 90214ce..281ea4e 100644
--- a/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
+++ b/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
@@ -100,15 +100,15 @@
         return true;
     }
     if (propertyName == builtinNames.closePublicName()) {
-        slot.setCustom(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum), windowType == DOMWindowType::Remote ? nonCachingStaticFunctionGetter<jsDOMWindowInstanceFunctionClose, 0> : nonCachingStaticFunctionGetter<jsDOMWindowInstanceFunctionClose, 0>);
+        slot.setCustom(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum), windowType == DOMWindowType::Remote ? nonCachingStaticFunctionGetter<jsRemoteDOMWindowInstanceFunctionClose, 0> : nonCachingStaticFunctionGetter<jsDOMWindowInstanceFunctionClose, 0>);
         return true;
     }
     if (propertyName == builtinNames.focusPublicName()) {
-        slot.setCustom(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum), windowType == DOMWindowType::Remote ? nonCachingStaticFunctionGetter<jsDOMWindowInstanceFunctionFocus, 0> : nonCachingStaticFunctionGetter<jsDOMWindowInstanceFunctionFocus, 0>);
+        slot.setCustom(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum), windowType == DOMWindowType::Remote ? nonCachingStaticFunctionGetter<jsRemoteDOMWindowInstanceFunctionFocus, 0> : nonCachingStaticFunctionGetter<jsDOMWindowInstanceFunctionFocus, 0>);
         return true;
     }
     if (propertyName == builtinNames.postMessagePublicName()) {
-        slot.setCustom(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum), windowType == DOMWindowType::Remote ? nonCachingStaticFunctionGetter<jsDOMWindowInstanceFunctionPostMessage, 0> : nonCachingStaticFunctionGetter<jsDOMWindowInstanceFunctionPostMessage, 2>);
+        slot.setCustom(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum), windowType == DOMWindowType::Remote ? nonCachingStaticFunctionGetter<jsRemoteDOMWindowInstanceFunctionPostMessage, 0> : nonCachingStaticFunctionGetter<jsDOMWindowInstanceFunctionPostMessage, 2>);
         return true;
     }
 
diff --git a/Source/WebCore/page/RemoteDOMWindow.cpp b/Source/WebCore/page/RemoteDOMWindow.cpp
index 825348d..92f7793 100644
--- a/Source/WebCore/page/RemoteDOMWindow.cpp
+++ b/Source/WebCore/page/RemoteDOMWindow.cpp
@@ -115,14 +115,13 @@
     return &m_frame->windowProxy();
 }
 
-ExceptionOr<void> RemoteDOMWindow::postMessage(JSC::ExecState&, DOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&&)
+void RemoteDOMWindow::postMessage(JSC::ExecState&, DOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&&)
 {
     UNUSED_PARAM(incumbentWindow);
     UNUSED_PARAM(message);
     UNUSED_PARAM(targetOrigin);
 
     // FIXME: Implemented this.
-    return Exception { NotSupportedError };
 }
 
 } // namespace WebCore
diff --git a/Source/WebCore/page/RemoteDOMWindow.h b/Source/WebCore/page/RemoteDOMWindow.h
index bd0c052..cb8611c 100644
--- a/Source/WebCore/page/RemoteDOMWindow.h
+++ b/Source/WebCore/page/RemoteDOMWindow.h
@@ -65,7 +65,7 @@
     WindowProxy* top() const;
     WindowProxy* opener() const;
     WindowProxy* parent() const;
-    ExceptionOr<void> postMessage(JSC::ExecState&, DOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&&);
+    void postMessage(JSC::ExecState&, DOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&&);
 
 private:
     WEBCORE_EXPORT RemoteDOMWindow(Ref<RemoteFrame>&&, GlobalWindowIdentifier&&);
diff --git a/Source/WebCore/page/RemoteDOMWindow.idl b/Source/WebCore/page/RemoteDOMWindow.idl
index 0e25b5a..319ed33 100644
--- a/Source/WebCore/page/RemoteDOMWindow.idl
+++ b/Source/WebCore/page/RemoteDOMWindow.idl
@@ -55,5 +55,5 @@
     [Unforgeable] readonly attribute WindowProxy? top;
     readonly attribute WindowProxy? opener;
     [Replaceable] readonly attribute WindowProxy? parent;
-    [CallWith=ScriptState&IncumbentWindow, ForwardDeclareInHeader, MayThrowException] void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer = []);
+    [CallWith=ScriptState&IncumbentWindow, ForwardDeclareInHeader] void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer = []);
 };