Title: [97939] trunk
Revision
97939
Author
[email protected]
Date
2011-10-19 23:02:42 -0700 (Wed, 19 Oct 2011)

Log Message

MessageEvent.data can be stored as ScriptValue.
https://bugs.webkit.org/show_bug.cgi?id=68978

Reviewed by Hajime Morita.

Source/WebCore:

Currently, the following test cases fail or crash:

- shouldBe("new MessageEvent('eventType', { data: test_object }).data", "test_object") -> FAIL
- new MessageEvent('eventType', { data: document }).data -> CRASH

This is because MessageEvent.data is implemented just as SerializedScriptValue
and it cannot keep ScriptValue passed by _javascript_. This patch makes the following changes:

- If MessageEvent is constructed with ScriptValue, it is stored as ScriptValue internally.
When MessageEvent.data is called, the ScriptValue is returned.
- If MessageEvent is constructed with SerializedScriptValue, it is stored as
SerializedScriptValue internally (since we cannot deserialize it into ScriptValue
at this point because of lack of ExecState). When MessageEvent.data is called,
the SerializedScriptValue is deserialized into the corresponding ScriptValue,
and the ScriptValue is returned.

This patch does not make a fix for ObjC bindings code, since we need to first fix
the bug 28774, as commented in dom/MessageEvent.h and dom/MessageEvent.cpp.

Test: fast/events/constructors/message-event-constructor.html
      fast/dom/message-port-deleted-by-accessor.html
      fast/events/init-events.html
      fast/eventsource/eventsource-attribute-listeners.html

* bindings/js/JSMessageEventCustom.cpp:
(WebCore::JSMessageEvent::data): Custom getter for MessageEvent.data. Supported ScriptValue.
(WebCore::JSMessageEvent::handleInitMessageEvent): Changed SerializedScriptValue to ScriptValue. Removed a 'doTransfer' parameter.
(WebCore::JSMessageEvent::initMessageEvent): Removed a 'doTransfer' parameter.
(WebCore::JSMessageEvent::webkitInitMessageEvent): Ditto.
* bindings/v8/custom/V8MessageEventCustom.cpp:
(WebCore::V8MessageEvent::dataAccessorGetter): Custom getter for MessageEvent.data. Supported ScriptValue.
(WebCore::V8MessageEvent::portsAccessorGetter): Removed extra spaces.
(WebCore::V8MessageEvent::initMessageEventCallback): Changed SerializedScriptValue to ScriptValue.
* dom/MessageEvent.cpp:
(WebCore::MessageEvent::MessageEvent): Supported ScriptValue.
(WebCore::MessageEvent::initMessageEvent): Supported ScriptValue.
(WebCore::MessageEvent::isMessageEvent): Removed extra spaces.
* dom/MessageEvent.h: Added DataType::DataTypeScriptValue.
(WebCore::MessageEvent::create): Supported ScriptValue.
(WebCore::MessageEvent::dataAsScriptValue): Getter for data. Insert ASSERT() to guarantee that this accessor is not called for unintended type of data.
(WebCore::MessageEvent::dataAsSerializedScriptValue): Ditto.
(WebCore::MessageEvent::dataAsString): Ditto.
(WebCore::MessageEvent::dataAsBlob): Ditto.
(WebCore::MessageEvent::dataAsArrayBuffer): Ditto.
* dom/MessageEvent.idl: Changed SerializedScriptValue to DOMObject (i.e. ScriptValue). This patch does not touch an ObjC part. Removed [CachedAttribute] from MessageEvent.data, since it is now a DOMObject and needs not to be cached.

LayoutTests:

Removed failures and crashes.

* fast/events/constructors/message-event-constructor-expected.txt:
* fast/events/constructors/message-event-constructor.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (97938 => 97939)


--- trunk/LayoutTests/ChangeLog	2011-10-20 05:19:48 UTC (rev 97938)
+++ trunk/LayoutTests/ChangeLog	2011-10-20 06:02:42 UTC (rev 97939)
@@ -1,3 +1,15 @@
+2011-10-19  Kentaro Hara  <[email protected]>
+
+        MessageEvent.data can be stored as ScriptValue.
+        https://bugs.webkit.org/show_bug.cgi?id=68978
+
+        Reviewed by Hajime Morita.
+
+        Removed failures and crashes.
+
+        * fast/events/constructors/message-event-constructor-expected.txt:
+        * fast/events/constructors/message-event-constructor.html:
+
 2011-10-19  Yuzo Fujishima  <[email protected]>
 
         [chromium] Revert test expectaion change by 97932.

Modified: trunk/LayoutTests/fast/events/constructors/message-event-constructor-expected.txt (97938 => 97939)


--- trunk/LayoutTests/fast/events/constructors/message-event-constructor-expected.txt	2011-10-20 05:19:48 UTC (rev 97938)
+++ trunk/LayoutTests/fast/events/constructors/message-event-constructor-expected.txt	2011-10-20 06:02:42 UTC (rev 97939)
@@ -14,7 +14,8 @@
 PASS new MessageEvent('eventType', { bubbles: true }).bubbles is true
 PASS new MessageEvent('eventType', { cancelable: false }).cancelable is false
 PASS new MessageEvent('eventType', { cancelable: true }).cancelable is true
-FAIL new MessageEvent('eventType', { data: test_object }).data should be [object Object]. Was [object Object].
+PASS new MessageEvent('eventType', { data: test_object }).data is test_object
+PASS new MessageEvent('eventType', { data: document }).data is document
 PASS new MessageEvent('eventType', { data: undefined }).data is undefined
 PASS new MessageEvent('eventType', { data: null }).data is null
 PASS new MessageEvent('eventType', { data: false }).data is false
@@ -94,7 +95,7 @@
 PASS new MessageEvent('eventType', { ports: {valueOf: function () { return [channel.port1, channel.port2, channel.port2]; } } }).ports[0] threw exception TypeError: Type error.
 PASS new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).bubbles is true
 PASS new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).cancelable is true
-FAIL new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).data should be [object Object]. Was [object Object].
+PASS new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).data is test_object
 PASS new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).origin is "wonderful"
 PASS new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).lastEventId is "excellent"
 PASS new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).source is window

Modified: trunk/LayoutTests/fast/events/constructors/message-event-constructor.html (97938 => 97939)


--- trunk/LayoutTests/fast/events/constructors/message-event-constructor.html	2011-10-20 05:19:48 UTC (rev 97938)
+++ trunk/LayoutTests/fast/events/constructors/message-event-constructor.html	2011-10-20 06:02:42 UTC (rev 97939)
@@ -28,10 +28,8 @@
 shouldBe("new MessageEvent('eventType', { cancelable: true }).cancelable", "true");
 
 // data is passed.
-// FIXME(haraken): This fails because MessageEvent.data cannot handle ScriptValue.
 shouldBe("new MessageEvent('eventType', { data: test_object }).data", "test_object");
-// FIXME(haraken): When we pass a DOM object, it crashes in DRT (it returns TypeError in non-DRT build).
-// shouldBe("new MessageEvent('eventType', { data: document }).data", "document");
+shouldBe("new MessageEvent('eventType', { data: document }).data", "document");
 shouldBe("new MessageEvent('eventType', { data: undefined }).data", "undefined");
 shouldBe("new MessageEvent('eventType', { data: null }).data", "null");
 shouldBe("new MessageEvent('eventType', { data: false }).data", "false");
@@ -119,7 +117,6 @@
 // All initializers are passed.
 shouldBe("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).bubbles", "true");
 shouldBe("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).cancelable", "true");
-// FIXME(haraken): This fails because MessageEvent.data cannot handle ScriptValue.
 shouldBe("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).data", "test_object");
 shouldBeEqualToString("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).origin", "wonderful");
 shouldBeEqualToString("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).lastEventId", "excellent");

Modified: trunk/Source/WebCore/ChangeLog (97938 => 97939)


--- trunk/Source/WebCore/ChangeLog	2011-10-20 05:19:48 UTC (rev 97938)
+++ trunk/Source/WebCore/ChangeLog	2011-10-20 06:02:42 UTC (rev 97939)
@@ -1,3 +1,56 @@
+2011-10-19  Kentaro Hara  <[email protected]>
+
+        MessageEvent.data can be stored as ScriptValue.
+        https://bugs.webkit.org/show_bug.cgi?id=68978
+
+        Reviewed by Hajime Morita.
+
+        Currently, the following test cases fail or crash:
+
+        - shouldBe("new MessageEvent('eventType', { data: test_object }).data", "test_object") -> FAIL
+        - new MessageEvent('eventType', { data: document }).data -> CRASH
+
+        This is because MessageEvent.data is implemented just as SerializedScriptValue
+        and it cannot keep ScriptValue passed by _javascript_. This patch makes the following changes:
+
+        - If MessageEvent is constructed with ScriptValue, it is stored as ScriptValue internally.
+        When MessageEvent.data is called, the ScriptValue is returned.
+        - If MessageEvent is constructed with SerializedScriptValue, it is stored as
+        SerializedScriptValue internally (since we cannot deserialize it into ScriptValue
+        at this point because of lack of ExecState). When MessageEvent.data is called,
+        the SerializedScriptValue is deserialized into the corresponding ScriptValue,
+        and the ScriptValue is returned.
+
+        This patch does not make a fix for ObjC bindings code, since we need to first fix
+        the bug 28774, as commented in dom/MessageEvent.h and dom/MessageEvent.cpp.
+
+        Test: fast/events/constructors/message-event-constructor.html
+              fast/dom/message-port-deleted-by-accessor.html
+              fast/events/init-events.html
+              fast/eventsource/eventsource-attribute-listeners.html
+
+        * bindings/js/JSMessageEventCustom.cpp:
+        (WebCore::JSMessageEvent::data): Custom getter for MessageEvent.data. Supported ScriptValue.
+        (WebCore::JSMessageEvent::handleInitMessageEvent): Changed SerializedScriptValue to ScriptValue. Removed a 'doTransfer' parameter.
+        (WebCore::JSMessageEvent::initMessageEvent): Removed a 'doTransfer' parameter.
+        (WebCore::JSMessageEvent::webkitInitMessageEvent): Ditto.
+        * bindings/v8/custom/V8MessageEventCustom.cpp:
+        (WebCore::V8MessageEvent::dataAccessorGetter): Custom getter for MessageEvent.data. Supported ScriptValue.
+        (WebCore::V8MessageEvent::portsAccessorGetter): Removed extra spaces.
+        (WebCore::V8MessageEvent::initMessageEventCallback): Changed SerializedScriptValue to ScriptValue.
+        * dom/MessageEvent.cpp:
+        (WebCore::MessageEvent::MessageEvent): Supported ScriptValue.
+        (WebCore::MessageEvent::initMessageEvent): Supported ScriptValue.
+        (WebCore::MessageEvent::isMessageEvent): Removed extra spaces.
+        * dom/MessageEvent.h: Added DataType::DataTypeScriptValue.
+        (WebCore::MessageEvent::create): Supported ScriptValue.
+        (WebCore::MessageEvent::dataAsScriptValue): Getter for data. Insert ASSERT() to guarantee that this accessor is not called for unintended type of data.
+        (WebCore::MessageEvent::dataAsSerializedScriptValue): Ditto.
+        (WebCore::MessageEvent::dataAsString): Ditto.
+        (WebCore::MessageEvent::dataAsBlob): Ditto.
+        (WebCore::MessageEvent::dataAsArrayBuffer): Ditto.
+        * dom/MessageEvent.idl: Changed SerializedScriptValue to DOMObject (i.e. ScriptValue). This patch does not touch an ObjC part. Removed [CachedAttribute] from MessageEvent.data, since it is now a DOMObject and needs not to be cached.
+
 2011-10-19  Adam Barth  <[email protected]>
 
         Attempt to fix GTK build.

Modified: trunk/Source/WebCore/bindings/js/JSMessageEventCustom.cpp (97938 => 97939)


--- trunk/Source/WebCore/bindings/js/JSMessageEventCustom.cpp	2011-10-20 05:19:48 UTC (rev 97938)
+++ trunk/Source/WebCore/bindings/js/JSMessageEventCustom.cpp	2011-10-20 06:02:42 UTC (rev 97939)
@@ -52,6 +52,15 @@
     MessageEvent* event = static_cast<MessageEvent*>(impl());
     JSValue result;
     switch (event->dataType()) {
+    case MessageEvent::DataTypeScriptValue: {
+        ScriptValue scriptValue = event->dataAsScriptValue();
+        if (scriptValue.hasNoValue())
+            result = jsNull();
+        else
+            result = scriptValue.jsValue();
+        break;
+    }
+
     case MessageEvent::DataTypeSerializedScriptValue:
         if (SerializedScriptValue* serializedValue = event->dataAsSerializedScriptValue()) {
             MessagePortArray* ports = static_cast<MessageEvent*>(impl())->ports();
@@ -91,7 +100,7 @@
     return constructArray(exec, globalObject(), list);
 }
 
-static JSC::JSValue handleInitMessageEvent(JSMessageEvent* jsEvent, JSC::ExecState* exec, bool doTransfer)
+static JSC::JSValue handleInitMessageEvent(JSMessageEvent* jsEvent, JSC::ExecState* exec)
 {
     const UString& typeArg = exec->argument(0).toString(exec);
     bool canBubbleArg = exec->argument(1).toBoolean(exec);
@@ -106,30 +115,24 @@
         if (exec->hadException())
             return jsUndefined();
     }
-    RefPtr<SerializedScriptValue> dataArg = SerializedScriptValue::create(exec, exec->argument(3), doTransfer ? messagePorts.get() : 0);
+    ScriptValue dataArg = ScriptValue(exec->globalData(), exec->argument(3));
     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, jsEvent->globalObject(), event->ports(), NonThrowing);
-    else
-        result = jsNull();
-    jsEvent->m_data.set(exec->globalData(), jsEvent, result);
+    event->initMessageEvent(ustringToAtomicString(typeArg), canBubbleArg, cancelableArg, dataArg, ustringToString(originArg), ustringToString(lastEventIdArg), sourceArg, messagePorts.release());
+    jsEvent->m_data.set(exec->globalData(), jsEvent, dataArg.jsValue());
     return jsUndefined();
-
 }
 
 JSC::JSValue JSMessageEvent::initMessageEvent(JSC::ExecState* exec)
 {
-    return handleInitMessageEvent(this, exec, false);
+    return handleInitMessageEvent(this, exec);
 }
 
 JSC::JSValue JSMessageEvent::webkitInitMessageEvent(JSC::ExecState* exec)
 {
-    return handleInitMessageEvent(this, exec, true);
+    return handleInitMessageEvent(this, exec);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp (97938 => 97939)


--- trunk/Source/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp	2011-10-20 05:19:48 UTC (rev 97938)
+++ trunk/Source/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp	2011-10-20 06:02:42 UTC (rev 97939)
@@ -51,6 +51,15 @@
 
     v8::Handle<v8::Value> result;
     switch (event->dataType()) {
+    case MessageEvent::DataTypeScriptValue: {
+        ScriptValue scriptValue = event->dataAsScriptValue();
+        if (scriptValue.hasNoValue())
+            result = v8::Null();
+        else
+            result = scriptValue.v8Value();
+        break;
+    }
+
     case MessageEvent::DataTypeSerializedScriptValue:
         if (SerializedScriptValue* serializedValue = event->dataAsSerializedScriptValue())
             result = serializedValue->deserialize(event->ports());
@@ -88,7 +97,7 @@
     MessagePortArray* ports = event->ports();
     if (!ports)
         return v8::Array::New(0);
-    
+
     MessagePortArray portsCopy(*ports);
 
     v8::Local<v8::Array> portArray = v8::Array::New(portsCopy.size());
@@ -105,7 +114,7 @@
     String typeArg = v8ValueToWebCoreString(args[0]);
     bool canBubbleArg = args[1]->BooleanValue();
     bool cancelableArg = args[2]->BooleanValue();
-    RefPtr<SerializedScriptValue> dataArg = SerializedScriptValue::create(args[3]);
+    ScriptValue dataArg = ScriptValue(args[3]);
     String originArg = v8ValueToWebCoreString(args[4]);
     String lastEventIdArg = v8ValueToWebCoreString(args[5]);
 
@@ -123,9 +132,7 @@
         if (!getMessagePortArray(args[7], *portArray))
             return v8::Undefined();
     }
-    event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, dataArg.release(), originArg, lastEventIdArg, sourceArg, portArray.release());
-    v8::PropertyAttribute dataAttr = static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly);
-    SerializedScriptValue::deserializeAndSetProperty(args.Holder(), "data", dataAttr, event->dataAsSerializedScriptValue());
+    event->initMessageEvent(typeArg, canBubbleArg, cancelableArg, dataArg, originArg, lastEventIdArg, sourceArg, portArray.release());
     return v8::Undefined();
 }
 

Modified: trunk/Source/WebCore/dom/MessageEvent.cpp (97938 => 97939)


--- trunk/Source/WebCore/dom/MessageEvent.cpp	2011-10-20 05:19:48 UTC (rev 97938)
+++ trunk/Source/WebCore/dom/MessageEvent.cpp	2011-10-20 06:02:42 UTC (rev 97939)
@@ -34,20 +34,18 @@
 namespace WebCore {
 
 MessageEventInit::MessageEventInit()
-    : data(SerializedScriptValue::create())
 {
 }
 
 MessageEvent::MessageEvent()
-    : m_dataType(DataTypeSerializedScriptValue)
-    , m_dataAsSerializedScriptValue(SerializedScriptValue::create())
+    : m_dataType(DataTypeScriptValue)
 {
 }
 
 MessageEvent::MessageEvent(const AtomicString& type, const MessageEventInit& initializer)
     : Event(type, initializer)
-    , m_dataType(DataTypeSerializedScriptValue)
-    , m_dataAsSerializedScriptValue(initializer.data)
+    , m_dataType(DataTypeScriptValue)
+    , m_dataAsScriptValue(initializer.data)
     , m_origin(initializer.origin)
     , m_lastEventId(initializer.lastEventId)
     , m_source(initializer.source)
@@ -55,6 +53,17 @@
 {
 }
 
+MessageEvent::MessageEvent(const ScriptValue& data, const String& origin, const String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortArray> ports)
+    : Event(eventNames().messageEvent, false, false)
+    , m_dataType(DataTypeScriptValue)
+    , m_dataAsScriptValue(data)
+    , m_origin(origin)
+    , m_lastEventId(lastEventId)
+    , m_source(source)
+    , m_ports(ports)
+{
+}
+
 MessageEvent::MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortArray> ports)
     : Event(eventNames().messageEvent, false, false)
     , m_dataType(DataTypeSerializedScriptValue)
@@ -97,6 +106,21 @@
 {
 }
 
+void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const ScriptValue& data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray> ports)
+{
+    if (dispatched())
+        return;
+
+    initEvent(type, canBubble, cancelable);
+
+    m_dataType = DataTypeScriptValue;
+    m_dataAsScriptValue = data;
+    m_origin = origin;
+    m_lastEventId = lastEventId;
+    m_source = source;
+    m_ports = ports;
+}
+
 void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray> ports)
 {
     if (dispatched())
@@ -129,6 +153,7 @@
     return (*m_ports)[0].get();
 }
 
+// FIXME: remove this when we update the ObjC bindings (bug #28774).
 void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, MessagePort* port)
 {
     OwnPtr<MessagePortArray> ports;
@@ -139,7 +164,7 @@
     initMessageEvent(type, canBubble, cancelable, data, origin, lastEventId, source, ports.release());
 }
 
-bool MessageEvent::isMessageEvent() const 
+bool MessageEvent::isMessageEvent() const
 {
     return true;
 }

Modified: trunk/Source/WebCore/dom/MessageEvent.h (97938 => 97939)


--- trunk/Source/WebCore/dom/MessageEvent.h	2011-10-20 05:19:48 UTC (rev 97938)
+++ trunk/Source/WebCore/dom/MessageEvent.h	2011-10-20 06:02:42 UTC (rev 97939)
@@ -33,6 +33,7 @@
 #include "DOMWindow.h"
 #include "Event.h"
 #include "MessagePort.h"
+#include "ScriptValue.h"
 #include "SerializedScriptValue.h"
 
 namespace WebCore {
@@ -42,7 +43,7 @@
 struct MessageEventInit : public EventInit {
     MessageEventInit();
 
-    RefPtr<SerializedScriptValue> data;
+    ScriptValue data;
     String origin;
     String lastEventId;
     RefPtr<DOMWindow> source;
@@ -55,10 +56,14 @@
     {
         return adoptRef(new MessageEvent);
     }
-    static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, PassRefPtr<SerializedScriptValue> data = "" const String& origin = "", const String& lastEventId = "", PassRefPtr<DOMWindow> source = 0)
+    static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, const ScriptValue& data = "" const String& origin = "", const String& lastEventId = "", PassRefPtr<DOMWindow> source = 0)
     {
         return adoptRef(new MessageEvent(data, origin, lastEventId, source, ports));
     }
+    static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, PassRefPtr<SerializedScriptValue> data, const String& origin = "", const String& lastEventId = "", PassRefPtr<DOMWindow> source = 0)
+    {
+        return adoptRef(new MessageEvent(data, origin, lastEventId, source, ports));
+    }
     static PassRefPtr<MessageEvent> create(const String& data)
     {
         return adoptRef(new MessageEvent(data));
@@ -77,6 +82,7 @@
     }
     virtual ~MessageEvent();
 
+    void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const ScriptValue& data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray>);
     void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray>);
 
     const String& origin() const { return m_origin; }
@@ -86,7 +92,6 @@
 
     // FIXME: Remove this when we have custom ObjC binding support.
     SerializedScriptValue* data() const;
-
     // FIXME: remove this when we update the ObjC bindings (bug #28774).
     MessagePort* messagePort();
     // FIXME: remove this when we update the ObjC bindings (bug #28774).
@@ -95,20 +100,23 @@
     virtual bool isMessageEvent() const;
 
     enum DataType {
+        DataTypeScriptValue,
         DataTypeSerializedScriptValue,
         DataTypeString,
         DataTypeBlob,
         DataTypeArrayBuffer
     };
     DataType dataType() const { return m_dataType; }
-    SerializedScriptValue* dataAsSerializedScriptValue() const { return m_dataAsSerializedScriptValue.get(); }
-    String dataAsString() const { return m_dataAsString; }
-    Blob* dataAsBlob() const { return m_dataAsBlob.get(); }
-    ArrayBuffer* dataAsArrayBuffer() const { return m_dataAsArrayBuffer.get(); }
+    ScriptValue dataAsScriptValue() const { ASSERT(m_dataType == DataTypeScriptValue); return m_dataAsScriptValue; }
+    SerializedScriptValue* dataAsSerializedScriptValue() const { ASSERT(m_dataType == DataTypeSerializedScriptValue); return m_dataAsSerializedScriptValue.get(); }
+    String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m_dataAsString; }
+    Blob* dataAsBlob() const { ASSERT(m_dataType == DataTypeBlob); return m_dataAsBlob.get(); }
+    ArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArrayBuffer); return m_dataAsArrayBuffer.get(); }
 
 private:
     MessageEvent();
     MessageEvent(const AtomicString&, const MessageEventInit&);
+    MessageEvent(const ScriptValue& data, const String& origin, const String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortArray>);
     MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, const String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortArray>);
 
     explicit MessageEvent(const String& data);
@@ -116,6 +124,7 @@
     explicit MessageEvent(PassRefPtr<ArrayBuffer> data);
 
     DataType m_dataType;
+    ScriptValue m_dataAsScriptValue;
     RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue;
     String m_dataAsString;
     RefPtr<Blob> m_dataAsBlob;

Modified: trunk/Source/WebCore/dom/MessageEvent.idl (97938 => 97939)


--- trunk/Source/WebCore/dom/MessageEvent.idl	2011-10-20 05:19:48 UTC (rev 97938)
+++ trunk/Source/WebCore/dom/MessageEvent.idl	2011-10-20 06:02:42 UTC (rev 97939)
@@ -36,13 +36,13 @@
         readonly attribute DOMString lastEventId;
         readonly attribute DOMWindow source;
 #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
-        readonly attribute [CachedAttribute, CustomGetter] any data;
+        readonly attribute [CachedAttribute, CustomGetter] DOMObject data;
         readonly attribute [CustomGetter] Array ports;
 
         [Custom] void initMessageEvent(in [Optional=CallWithDefaultValue] DOMString typeArg, 
                                        in [Optional=CallWithDefaultValue] boolean canBubbleArg, 
                                        in [Optional=CallWithDefaultValue] boolean cancelableArg, 
-                                       in [Optional=CallWithDefaultValue] SerializedScriptValue dataArg, 
+                                       in [Optional=CallWithDefaultValue] DOMObject dataArg, 
                                        in [Optional=CallWithDefaultValue] DOMString originArg, 
                                        in [Optional=CallWithDefaultValue] DOMString lastEventIdArg, 
                                        in [Optional=CallWithDefaultValue] DOMWindow sourceArg, 
@@ -51,7 +51,7 @@
         [Custom] void webkitInitMessageEvent(in [Optional=CallWithDefaultValue] DOMString typeArg,
                                              in [Optional=CallWithDefaultValue] boolean canBubbleArg,
                                              in [Optional=CallWithDefaultValue] boolean cancelableArg,
-                                             in [Optional=CallWithDefaultValue] SerializedScriptValue dataArg,
+                                             in [Optional=CallWithDefaultValue] DOMObject dataArg,
                                              in [Optional=CallWithDefaultValue] DOMString originArg,
                                              in [Optional=CallWithDefaultValue] DOMString lastEventIdArg,
                                              in [Optional=CallWithDefaultValue] DOMWindow sourceArg,
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to