https://bugs.webkit.org/show_bug.cgi?id=70186
authordslomov@google.com <dslomov@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Oct 2011 19:19:42 +0000 (19:19 +0000)
committerdslomov@google.com <dslomov@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Oct 2011 19:19:42 +0000 (19:19 +0000)
Pass MessagePortArray to JSC's SerializedScriptValue::serialize/deserialize.

Reviewed by Oliver Hunt.

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::handlePostMessage):
(WebCore::JSDOMWindow::postMessage):
(WebCore::JSDOMWindow::webkitPostMessage):
* bindings/js/JSDictionary.cpp:
(WebCore::JSDictionary::convertValue):
* bindings/js/JSHistoryCustom.cpp:
(WebCore::JSHistory::pushState):
(WebCore::JSHistory::replaceState):
* bindings/js/JSMessageEventCustom.cpp:
(WebCore::JSMessageEvent::data):
(WebCore::handleInitMessageEvent):
(WebCore::JSMessageEvent::initMessageEvent):
(WebCore::JSMessageEvent::webkitInitMessageEvent):
* bindings/js/JSMessagePortCustom.h:
(WebCore::handlePostMessage):
* bindings/js/JSPopStateEventCustom.cpp:
(WebCore::JSPopStateEvent::state):
* bindings/js/ScriptValue.cpp:
(WebCore::ScriptValue::serialize):
(WebCore::ScriptValue::deserialize):
* bindings/js/SerializedScriptValue.cpp:
(WebCore::SerializedScriptValue::create):
(WebCore::SerializedScriptValue::deserialize):
* bindings/js/SerializedScriptValue.h:

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
Source/WebCore/bindings/js/JSDictionary.cpp
Source/WebCore/bindings/js/JSHistoryCustom.cpp
Source/WebCore/bindings/js/JSMessageEventCustom.cpp
Source/WebCore/bindings/js/JSMessagePortCustom.h
Source/WebCore/bindings/js/JSPopStateEventCustom.cpp
Source/WebCore/bindings/js/ScriptValue.cpp
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/bindings/js/SerializedScriptValue.h

index efe17a7..7b7782e 100644 (file)
@@ -1,3 +1,36 @@
+2011-10-16  Dmitry Lomov  <dslomov@google.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=70186
+        Pass MessagePortArray to JSC's SerializedScriptValue::serialize/deserialize.
+
+        Reviewed by Oliver Hunt.
+
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::handlePostMessage):
+        (WebCore::JSDOMWindow::postMessage):
+        (WebCore::JSDOMWindow::webkitPostMessage):
+        * bindings/js/JSDictionary.cpp:
+        (WebCore::JSDictionary::convertValue):
+        * bindings/js/JSHistoryCustom.cpp:
+        (WebCore::JSHistory::pushState):
+        (WebCore::JSHistory::replaceState):
+        * bindings/js/JSMessageEventCustom.cpp:
+        (WebCore::JSMessageEvent::data):
+        (WebCore::handleInitMessageEvent):
+        (WebCore::JSMessageEvent::initMessageEvent):
+        (WebCore::JSMessageEvent::webkitInitMessageEvent):
+        * bindings/js/JSMessagePortCustom.h:
+        (WebCore::handlePostMessage):
+        * bindings/js/JSPopStateEventCustom.cpp:
+        (WebCore::JSPopStateEvent::state):
+        * bindings/js/ScriptValue.cpp:
+        (WebCore::ScriptValue::serialize):
+        (WebCore::ScriptValue::deserialize):
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::SerializedScriptValue::create):
+        (WebCore::SerializedScriptValue::deserialize):
+        * bindings/js/SerializedScriptValue.h:
+
 2011-10-16  Dan Bernstein  <mitz@apple.com>
 
         REGRESSION (r96620): Float-avoiding block positioned incorrectly in right-to-left block
index 732b81c..7035b1d 100644 (file)
@@ -715,33 +715,39 @@ JSValue JSDOMWindow::showModalDialog(ExecState* exec)
     return handler.returnValue();
 }
 
-JSValue JSDOMWindow::postMessage(ExecState* exec)
+static JSValue handlePostMessage(DOMWindow* impl, ExecState* exec, bool doTransfer)
 {
-    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(exec, exec->argument(0));
-
-    if (exec->hadException())
-        return jsUndefined();
-
     MessagePortArray messagePorts;
     if (exec->argumentCount() > 2)
         fillMessagePortArray(exec, exec->argument(1), messagePorts);
     if (exec->hadException())
         return jsUndefined();
 
+    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(exec, exec->argument(0), 
+                                                                         doTransfer ? &messagePorts : 0);
+
+    if (exec->hadException())
+        return jsUndefined();
+
     String targetOrigin = valueToStringWithUndefinedOrNullCheck(exec, exec->argument((exec->argumentCount() == 2) ? 1 : 2));
     if (exec->hadException())
         return jsUndefined();
 
     ExceptionCode ec = 0;
-    impl()->postMessage(message.release(), &messagePorts, targetOrigin, activeDOMWindow(exec), ec);
+    impl->postMessage(message.release(), &messagePorts, targetOrigin, activeDOMWindow(exec), ec);
     setDOMException(exec, ec);
 
     return jsUndefined();
 }
 
+JSValue JSDOMWindow::postMessage(ExecState* exec)
+{
+    return handlePostMessage(impl(), exec, false);
+}
+
 JSValue JSDOMWindow::webkitPostMessage(ExecState* exec)
 {
-    return postMessage(exec);
+    return handlePostMessage(impl(), exec, true);
 }
 
 JSValue JSDOMWindow::setTimeout(ExecState* exec)
index 58531f3..e319aa1 100644 (file)
@@ -101,7 +101,7 @@ void JSDictionary::convertValue(ExecState* exec, JSValue value, ScriptValue& res
 
 void JSDictionary::convertValue(ExecState* exec, JSValue value, RefPtr<SerializedScriptValue>& result)
 {
-    result = SerializedScriptValue::create(exec, value);
+    result = SerializedScriptValue::create(exec, value, 0);
 }
 
 void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<DOMWindow>& result)
index 00d7900..be26b7b 100644 (file)
@@ -164,7 +164,7 @@ void JSHistory::getOwnPropertyNames(ExecState* exec, PropertyNameArray& property
 
 JSValue JSHistory::pushState(ExecState* exec)
 {
-    RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(exec, exec->argument(0));
+    RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(exec, exec->argument(0), 0);
     if (exec->hadException())
         return jsUndefined();
 
@@ -188,7 +188,7 @@ JSValue JSHistory::pushState(ExecState* exec)
 
 JSValue JSHistory::replaceState(ExecState* exec)
 {
-    RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(exec, exec->argument(0));
+    RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(exec, exec->argument(0), 0);
     if (exec->hadException())
         return jsUndefined();
 
index e748cff..5091c48 100644 (file)
@@ -53,8 +53,10 @@ JSValue JSMessageEvent::data(ExecState* exec) const
     JSValue result;
     switch (event->dataType()) {
     case MessageEvent::DataTypeSerializedScriptValue:
-        if (SerializedScriptValue* serializedValue = event->dataAsSerializedScriptValue())
-            result = serializedValue->deserialize(exec, globalObject(), NonThrowing);
+        if (SerializedScriptValue* serializedValue = event->dataAsSerializedScriptValue()) {
+            MessagePortArray* ports = static_cast<MessageEvent*>(impl())->ports();
+            result = serializedValue->deserialize(exec, globalObject(), ports, NonThrowing);
+        }
         else
             result = jsNull();
         break;
@@ -89,14 +91,11 @@ JSValue JSMessageEvent::ports(ExecState* exec) const
     return constructArray(exec, globalObject(), list);
 }
 
-JSC::JSValue JSMessageEvent::initMessageEvent(JSC::ExecState* exec)
+static JSC::JSValue handleInitMessageEvent(JSMessageEvent* jsEvent, JSC::ExecState* exec, bool doTransfer)
 {
     const UString& typeArg = exec->argument(0).toString(exec);
     bool canBubbleArg = exec->argument(1).toBoolean(exec);
     bool cancelableArg = exec->argument(2).toBoolean(exec);
-    RefPtr<SerializedScriptValue> dataArg = SerializedScriptValue::create(exec, exec->argument(3));
-    if (exec->hadException())
-        return jsUndefined();
     const UString& originArg = exec->argument(4).toString(exec);
     const UString& lastEventIdArg = exec->argument(5).toString(exec);
     DOMWindow* sourceArg = toDOMWindow(exec->argument(6));
@@ -107,21 +106,30 @@ JSC::JSValue JSMessageEvent::initMessageEvent(JSC::ExecState* exec)
         if (exec->hadException())
             return jsUndefined();
     }
-
-    MessageEvent* event = static_cast<MessageEvent*>(this->impl());
+    RefPtr<SerializedScriptValue> dataArg = SerializedScriptValue::create(exec, exec->argument(3), doTransfer ? messagePorts.get() : 0);
+    if (exec->hadException())
+        return jsUndefined();
+    MessageEvent* event = static_cast<MessageEvent*>(jsEvent->impl());
     event->initMessageEvent(ustringToAtomicString(typeArg), canBubbleArg, cancelableArg, dataArg.release(), ustringToString(originArg), ustringToString(lastEventIdArg), sourceArg, messagePorts.release());
     JSValue result;
     if (SerializedScriptValue* serializedValue = event->dataAsSerializedScriptValue())
-        result = serializedValue->deserialize(exec, globalObject(), NonThrowing);
+        result = serializedValue->deserialize(exec, jsEvent->globalObject(), event->ports(), NonThrowing);
     else
         result = jsNull();
-    m_data.set(exec->globalData(), this, result);
+    jsEvent->m_data.set(exec->globalData(), jsEvent, result);
     return jsUndefined();
+
+}
+
+JSC::JSValue JSMessageEvent::initMessageEvent(JSC::ExecState* exec)
+{
+    return handleInitMessageEvent(this, exec, false);
 }
 
 JSC::JSValue JSMessageEvent::webkitInitMessageEvent(JSC::ExecState* exec)
 {
-    return initMessageEvent(exec);
+    return handleInitMessageEvent(this, exec, true);
 }
 
 } // namespace WebCore
index 805e483..5a9e04b 100644 (file)
@@ -48,9 +48,9 @@ namespace WebCore {
     template <typename T>
     inline JSC::JSValue handlePostMessage(JSC::ExecState* exec, T* impl)
     {
-        RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(exec, exec->argument(0));
         MessagePortArray portArray;
         fillMessagePortArray(exec, exec->argument(1), portArray);
+        RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(exec, exec->argument(0), &portArray);
         if (exec->hadException())
             return JSC::jsUndefined();
 
index 3ab56ff..38edfb6 100644 (file)
@@ -41,7 +41,7 @@ JSValue JSPopStateEvent::state(ExecState* exec) const
     PopStateEvent* event = static_cast<PopStateEvent*>(impl());
     SerializedScriptValue* serializedState = event->serializedState();
     if (serializedState)
-        return serializedState->deserialize(exec, globalObject());
+        return serializedState->deserialize(exec, globalObject(), 0);
     if (!event->state().hasNoValue())
         return event->state().jsValue();
     return jsNull();
index 967f264..af1a406 100644 (file)
@@ -102,12 +102,12 @@ bool ScriptValue::isFunction() const
 
 PassRefPtr<SerializedScriptValue> ScriptValue::serialize(ScriptState* scriptState, SerializationErrorMode throwExceptions)
 {
-    return SerializedScriptValue::create(scriptState, jsValue(), throwExceptions);
+    return SerializedScriptValue::create(scriptState, jsValue(), 0, throwExceptions);
 }
 
 ScriptValue ScriptValue::deserialize(ScriptState* scriptState, SerializedScriptValue* value, SerializationErrorMode throwExceptions)
 {
-    return ScriptValue(scriptState->globalData(), value->deserialize(scriptState, scriptState->lexicalGlobalObject(), throwExceptions));
+    return ScriptValue(scriptState->globalData(), value->deserialize(scriptState, scriptState->lexicalGlobalObject(), 0, throwExceptions));
 }
 
 #if ENABLE(INSPECTOR)
index cf12b1b..57943be 100644 (file)
@@ -1339,7 +1339,7 @@ SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>& buffer)
     m_data.swap(buffer);
 }
 
-PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(ExecState* exec, JSValue value, SerializationErrorMode throwExceptions)
+PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(ExecState* exec, JSValue value, MessagePortArray*, SerializationErrorMode throwExceptions)
 {
     Vector<uint8_t> buffer;
     SerializationReturnCode code = CloneSerializer::serialize(exec, value, buffer);
@@ -1366,12 +1366,13 @@ PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const String& st
     return adoptRef(new SerializedScriptValue(buffer));
 }
 
-PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(JSContextRef originContext, JSValueRef apiValue, JSValueRef* exception)
+PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(JSContextRef originContext, JSValueRef apiValue, 
+                                                                MessagePortArray* messagePorts, JSValueRef* exception)
 {
     ExecState* exec = toJS(originContext);
     APIEntryShim entryShim(exec);
     JSValue value = toJS(exec, apiValue);
-    RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::create(exec, value);
+    RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::create(exec, value, messagePorts);
     if (exec->hadException()) {
         if (exception)
             *exception = toRef(exec, exec->exception());
@@ -1382,12 +1383,19 @@ PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(JSContextRef ori
     return serializedValue.release();
 }
 
+PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(JSContextRef originContext, JSValueRef apiValue,
+                                                                JSValueRef* exception)
+{
+    return create(originContext, apiValue, 0, exception);
+}
+
 String SerializedScriptValue::toString()
 {
     return CloneDeserializer::deserializeString(m_data);
 }
 
-JSValue SerializedScriptValue::deserialize(ExecState* exec, JSGlobalObject* globalObject, SerializationErrorMode throwExceptions)
+JSValue SerializedScriptValue::deserialize(ExecState* exec, JSGlobalObject* globalObject, 
+                                           MessagePortArray*, SerializationErrorMode throwExceptions)
 {
     DeserializationResult result = CloneDeserializer::deserialize(exec, globalObject, m_data);
     if (throwExceptions == Throwing)
@@ -1395,11 +1403,11 @@ JSValue SerializedScriptValue::deserialize(ExecState* exec, JSGlobalObject* glob
     return result.first;
 }
 
-JSValueRef SerializedScriptValue::deserialize(JSContextRef destinationContext, JSValueRef* exception)
+JSValueRef SerializedScriptValue::deserialize(JSContextRef destinationContext, JSValueRef* exception, MessagePortArray* messagePorts)
 {
     ExecState* exec = toJS(destinationContext);
     APIEntryShim entryShim(exec);
-    JSValue value = deserialize(exec, exec->lexicalGlobalObject());
+    JSValue value = deserialize(exec, exec->lexicalGlobalObject(), messagePorts);
     if (exec->hadException()) {
         if (exception)
             *exception = toRef(exec, exec->exception());
@@ -1410,6 +1418,12 @@ JSValueRef SerializedScriptValue::deserialize(JSContextRef destinationContext, J
     return toRef(exec, value);
 }
 
+
+JSValueRef SerializedScriptValue::deserialize(JSContextRef destinationContext, JSValueRef* exception)
+{
+    return deserialize(destinationContext, exception, 0);
+}
+
 SerializedScriptValue* SerializedScriptValue::nullValue()
 {
     DEFINE_STATIC_LOCAL(RefPtr<SerializedScriptValue>, emptyValue, (SerializedScriptValue::create()));
index 3fe4e02..5072fa6 100644 (file)
@@ -38,6 +38,8 @@ typedef const struct OpaqueJSValue* JSValueRef;
 
 namespace WebCore {
 
+class MessagePort;
+typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray;
  
 enum SerializationReturnCode {
     SuccessfullyCompleted,
@@ -54,8 +56,10 @@ class SharedBuffer;
 
 class SerializedScriptValue : public RefCounted<SerializedScriptValue> {
 public:
-    static PassRefPtr<SerializedScriptValue> create(JSC::ExecState*, JSC::JSValue, SerializationErrorMode = Throwing);
-    static PassRefPtr<SerializedScriptValue> create(JSContextRef, JSValueRef value, JSValueRef* exception);
+    static PassRefPtr<SerializedScriptValue> create(JSC::ExecState*, JSC::JSValue, MessagePortArray*, SerializationErrorMode = Throwing);
+    static PassRefPtr<SerializedScriptValue> create(JSContextRef, JSValueRef, MessagePortArray*,  JSValueRef* exception);
+    static PassRefPtr<SerializedScriptValue> create(JSContextRef, JSValueRef, JSValueRef* exception);
+
     static PassRefPtr<SerializedScriptValue> create(const String&);
     static PassRefPtr<SerializedScriptValue> adopt(Vector<uint8_t>& buffer)
     {
@@ -67,7 +71,8 @@ public:
 
     String toString();
     
-    JSC::JSValue deserialize(JSC::ExecState*, JSC::JSGlobalObject*, SerializationErrorMode = Throwing);
+    JSC::JSValue deserialize(JSC::ExecState*, JSC::JSGlobalObject*, MessagePortArray*, SerializationErrorMode = Throwing);
+    JSValueRef deserialize(JSContextRef, JSValueRef* exception, MessagePortArray*);
     JSValueRef deserialize(JSContextRef, JSValueRef* exception);
 
     const Vector<uint8_t>& data() { return m_data; }