From 9a6aee25195901611ee2f5c53d7fbedbeb862350 Mon Sep 17 00:00:00 2001 From: "commit-queue@webkit.org" Date: Wed, 28 Sep 2011 02:02:18 +0000 Subject: [PATCH] Implement a MessageEvent constructor for JSC https://bugs.webkit.org/show_bug.cgi?id=68883 Patch by Kentaro Hara on 2011-09-27 Reviewed by Adam Barth. Source/WebCore: The spec for MessageEvent is here: http://www.whatwg.org/specs/web-apps/current-work/#messageevent Currently, some tests in fast/events/constructors/message-event-constructor.html are failing or crashing in DRT, as we commented in the test file. This is because MessageEvent.data is implemented as SerializedScriptValue, and thus it cannot keep ScriptValue passed by JavaScript. This is the same issue as the bug (https://bugs.webkit.org/show_bug.cgi?id=68345). We will soon make a follow-up patch to fix these failures, after this patch is landed. Test: fast/events/constructors/message-event-constructor.html * bindings/generic/EventConstructors.h: Added a definition for the MessageEvent constructor. * bindings/js/JSDictionary.cpp: (WebCore::JSDictionary::convertValue): Generates MessagePortArray from the list of message ports in the format of JSValues. * bindings/js/JSDictionary.h: * bindings/js/JSEventConstructors.cpp: Added #includes for MessageEvent. * dom/MessageEvent.cpp: (WebCore::MessageEventInit::MessageEventInit): (WebCore::MessageEvent::MessageEvent): (WebCore::MessageEvent::initMessageEvent): * dom/MessageEvent.h: Added a definition for MessageEvent. Removed an extra leading spaces. (WebCore::MessageEvent::create): (WebCore::MessageEvent::origin): (WebCore::MessageEvent::lastEventId): (WebCore::MessageEvent::source): (WebCore::MessageEvent::ports): (WebCore::MessageEvent::dataType): (WebCore::MessageEvent::dataAsSerializedScriptValue): (WebCore::MessageEvent::dataAsString): (WebCore::MessageEvent::dataAsBlob): (WebCore::MessageEvent::dataAsArrayBuffer): * dom/MessageEvent.idl: Makes MessageEvent constructible. LayoutTests: message-event-constructor.html checks the behavior of the MessageEvent constructor. * fast/dom/constructed-objects-prototypes-expected.txt: Now window has MessageEvent. * fast/events/constructors/message-event-constructor-expected.txt: Added. * fast/events/constructors/message-event-constructor.html: Added. * platform/chromium/test_expectations.txt: Skipped message-event-constructor.html, since V8 does not yet have the MessageEvent constructor. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96179 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 14 ++ .../constructed-objects-prototypes-expected.txt | 2 + .../message-event-constructor-expected.txt | 107 ++++++++++++++ .../constructors/message-event-constructor.html | 138 ++++++++++++++++++ .../platform/chromium/test_expectations.txt | 3 + Source/WebCore/ChangeLog | 42 ++++++ .../WebCore/bindings/generic/EventConstructors.h | 12 ++ Source/WebCore/bindings/js/JSDictionary.cpp | 7 +- Source/WebCore/bindings/js/JSDictionary.h | 2 + Source/WebCore/bindings/js/JSEventConstructors.cpp | 2 + Source/WebCore/dom/MessageEvent.cpp | 18 ++- Source/WebCore/dom/MessageEvent.h | 158 ++++++++++++--------- Source/WebCore/dom/MessageEvent.idl | 4 +- 13 files changed, 435 insertions(+), 74 deletions(-) create mode 100644 LayoutTests/fast/events/constructors/message-event-constructor-expected.txt create mode 100644 LayoutTests/fast/events/constructors/message-event-constructor.html diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 01f4802..4174eb5 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,17 @@ +2011-09-27 Kentaro Hara + + Implement a MessageEvent constructor for JSC + https://bugs.webkit.org/show_bug.cgi?id=68883 + + Reviewed by Adam Barth. + + message-event-constructor.html checks the behavior of the MessageEvent constructor. + + * fast/dom/constructed-objects-prototypes-expected.txt: Now window has MessageEvent. + * fast/events/constructors/message-event-constructor-expected.txt: Added. + * fast/events/constructors/message-event-constructor.html: Added. + * platform/chromium/test_expectations.txt: Skipped message-event-constructor.html, since V8 does not yet have the MessageEvent constructor. + 2011-09-27 Eric Uhrhane [Chromium/FileWriter] race condition in FileWriter completion can lead to assert diff --git a/LayoutTests/fast/dom/constructed-objects-prototypes-expected.txt b/LayoutTests/fast/dom/constructed-objects-prototypes-expected.txt index 03dc8c8..4905284 100644 --- a/LayoutTests/fast/dom/constructed-objects-prototypes-expected.txt +++ b/LayoutTests/fast/dom/constructed-objects-prototypes-expected.txt @@ -23,6 +23,8 @@ PASS (new inner.Image()).isInner is true PASS (new inner.Image()).constructor.isInner is true PASS (new inner.MessageChannel()).isInner is true PASS (new inner.MessageChannel()).constructor.isInner is true +PASS (new inner.MessageEvent()).isInner is true +PASS (new inner.MessageEvent()).constructor.isInner is true PASS (new inner.Option()).isInner is true PASS (new inner.Option()).constructor.isInner is true PASS (new inner.PageTransitionEvent()).isInner is true diff --git a/LayoutTests/fast/events/constructors/message-event-constructor-expected.txt b/LayoutTests/fast/events/constructors/message-event-constructor-expected.txt new file mode 100644 index 0000000..5fcc4d2 --- /dev/null +++ b/LayoutTests/fast/events/constructors/message-event-constructor-expected.txt @@ -0,0 +1,107 @@ +This tests the constructor for the MessageEvent DOM class. + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS new MessageEvent('eventType').bubbles is false +PASS new MessageEvent('eventType').cancelable is false +PASS new MessageEvent('eventType').data is null +PASS new MessageEvent('eventType').origin is "" +PASS new MessageEvent('eventType').lastEventId is "" +PASS new MessageEvent('eventType').source is null +PASS new MessageEvent('eventType').ports is [] +PASS new MessageEvent('eventType', { bubbles: false }).bubbles is false +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: undefined }).data is undefined +PASS new MessageEvent('eventType', { data: null }).data is null +PASS new MessageEvent('eventType', { data: false }).data is false +PASS new MessageEvent('eventType', { data: true }).data is true +PASS new MessageEvent('eventType', { data: '' }).data is "" +PASS new MessageEvent('eventType', { data: 'chocolate' }).data is "chocolate" +PASS new MessageEvent('eventType', { data: 12345 }).data is 12345 +PASS new MessageEvent('eventType', { data: 18446744073709551615 }).data is 18446744073709552000 +PASS new MessageEvent('eventType', { data: NaN }).data is NaN +PASS new MessageEvent('eventType', { data: {valueOf: function () { return test_object; } } }).data == test_object is false +PASS new MessageEvent('eventType', { get data() { return 123; } }).data is 123 +PASS new MessageEvent('eventType', { get data() { throw 'MessageEvent Error'; } }) threw exception MessageEvent Error. +PASS new MessageEvent('eventType', { origin: 'melancholy' }).origin is "melancholy" +PASS new MessageEvent('eventType', { origin: '' }).origin is "" +PASS new MessageEvent('eventType', { origin: undefined }).origin is "undefined" +PASS new MessageEvent('eventType', { origin: null }).origin is "null" +PASS new MessageEvent('eventType', { origin: false }).origin is "false" +PASS new MessageEvent('eventType', { origin: true }).origin is "true" +PASS new MessageEvent('eventType', { origin: 12345 }).origin is "12345" +PASS new MessageEvent('eventType', { origin: 18446744073709551615 }).origin is "18446744073709552000" +PASS new MessageEvent('eventType', { origin: NaN }).origin is "NaN" +PASS new MessageEvent('eventType', { origin: [] }).origin is "" +PASS new MessageEvent('eventType', { origin: [1, 2, 3] }).origin is "1,2,3" +PASS new MessageEvent('eventType', { origin: {melancholy: 12345} }).origin is "[object Object]" +PASS new MessageEvent('eventType', { origin: {valueOf: function () { return 'melancholy'; } } }).origin is "[object Object]" +PASS new MessageEvent('eventType', { get origin() { return 123; } }).origin is "123" +PASS new MessageEvent('eventType', { get origin() { throw 'MessageEvent Error'; } }) threw exception MessageEvent Error. +PASS new MessageEvent('eventType', { lastEventId: 'melancholy' }).lastEventId is "melancholy" +PASS new MessageEvent('eventType', { lastEventId: '' }).lastEventId is "" +PASS new MessageEvent('eventType', { lastEventId: undefined }).lastEventId is "undefined" +PASS new MessageEvent('eventType', { lastEventId: null }).lastEventId is "null" +PASS new MessageEvent('eventType', { lastEventId: false }).lastEventId is "false" +PASS new MessageEvent('eventType', { lastEventId: true }).lastEventId is "true" +PASS new MessageEvent('eventType', { lastEventId: 12345 }).lastEventId is "12345" +PASS new MessageEvent('eventType', { lastEventId: 18446744073709551615 }).lastEventId is "18446744073709552000" +PASS new MessageEvent('eventType', { lastEventId: NaN }).lastEventId is "NaN" +PASS new MessageEvent('eventType', { lastEventId: [] }).lastEventId is "" +PASS new MessageEvent('eventType', { lastEventId: [1, 2, 3] }).lastEventId is "1,2,3" +PASS new MessageEvent('eventType', { lastEventId: {melancholy: 12345} }).lastEventId is "[object Object]" +PASS new MessageEvent('eventType', { lastEventId: {valueOf: function () { return 'melancholy'; } } }).lastEventId is "[object Object]" +PASS new MessageEvent('eventType', { get lastEventId() { return 123; } }).lastEventId is "123" +PASS new MessageEvent('eventType', { get lastEventId() { throw 'MessageEvent Error'; } }) threw exception MessageEvent Error. +PASS new MessageEvent('eventType', { source: window }).source is window +PASS new MessageEvent('eventType', { source: this }).source is this +PASS new MessageEvent('eventType', { source: test_object }).source is null +PASS new MessageEvent('eventType', { source: document }).source is null +PASS new MessageEvent('eventType', { source: undefined }).source is null +PASS new MessageEvent('eventType', { source: null }).source is null +PASS new MessageEvent('eventType', { source: false }).source is null +PASS new MessageEvent('eventType', { source: true }).source is null +PASS new MessageEvent('eventType', { source: '' }).source is null +PASS new MessageEvent('eventType', { source: 'chocolate' }).source is null +PASS new MessageEvent('eventType', { source: 12345 }).source is null +PASS new MessageEvent('eventType', { source: 18446744073709551615 }).source is null +PASS new MessageEvent('eventType', { source: NaN }).source is null +PASS new MessageEvent('eventType', { source: {valueOf: function () { return window; } } }).source == window is false +PASS new MessageEvent('eventType', { get source() { return 123; } }).source is null +PASS new MessageEvent('eventType', { get source() { throw 'MessageEvent Error'; } }) threw exception MessageEvent Error. +PASS new MessageEvent('eventType', { ports: [channel.port1, channel.port2, channel.port2] }).ports[0] is channel.port1 +PASS new MessageEvent('eventType', { ports: [channel.port1, channel.port2, channel.port2] }).ports[1] is channel.port2 +PASS new MessageEvent('eventType', { ports: [channel.port1, channel.port2, channel.port2] }).ports[2] is channel.port2 +PASS new MessageEvent('eventType', { ports: [] }).ports is [] +PASS new MessageEvent('eventType', { ports: undefined }).ports is [] +PASS new MessageEvent('eventType', { ports: null }).ports is [] +PASS new MessageEvent('eventType', { ports: [1, 2, 3] }).ports[2] threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { ports: test_object }).ports threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { ports: document }).ports threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { ports: false }).ports threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { ports: true }).ports threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { ports: '' }).ports threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { ports: 'chocolate' }).ports threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { ports: 12345 }).ports threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { ports: 18446744073709551615 }).ports threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { ports: NaN }).ports threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { get ports() { return 123; } }).ports threw exception TypeError: Type error. +PASS new MessageEvent('eventType', { get ports() { throw 'MessageEvent Error'; } }) threw exception MessageEvent Error. +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] }).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 +PASS new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).ports[0] is channel.port1 +PASS new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).ports[1] is channel.port2 +PASS new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).ports[2] is channel.port2 +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/events/constructors/message-event-constructor.html b/LayoutTests/fast/events/constructors/message-event-constructor.html new file mode 100644 index 0000000..6dfb6f1 --- /dev/null +++ b/LayoutTests/fast/events/constructors/message-event-constructor.html @@ -0,0 +1,138 @@ + + + + + + + +

+
+ + + + diff --git a/LayoutTests/platform/chromium/test_expectations.txt b/LayoutTests/platform/chromium/test_expectations.txt index 7215a0b..3a13a9d 100644 --- a/LayoutTests/platform/chromium/test_expectations.txt +++ b/LayoutTests/platform/chromium/test_expectations.txt @@ -81,6 +81,9 @@ BUGWK68048 : fast/events/constructors/page-transition-event-constructor.html = F BUGWK60877 SKIP : loader/navigation-while-deferring-loads.html = FAIL BUGWK60877 SKIP : loader/load-defer-resume-crash.html = FAIL +// This will soon be fixed after implementing a MessageEvent constructor for V8. +BUGWK68883 : fast/events/constructors/message-event-constructor.html = FAIL + // CSS3 Selectors3 test suite BUGCR89468 : css3/selectors3 = PASS FAIL diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index cad5f32..fe437c1 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,45 @@ +2011-09-27 Kentaro Hara + + Implement a MessageEvent constructor for JSC + https://bugs.webkit.org/show_bug.cgi?id=68883 + + Reviewed by Adam Barth. + + The spec for MessageEvent is here: + http://www.whatwg.org/specs/web-apps/current-work/#messageevent + + Currently, some tests in fast/events/constructors/message-event-constructor.html + are failing or crashing in DRT, as we commented in the test file. + This is because MessageEvent.data is implemented as SerializedScriptValue, + and thus it cannot keep ScriptValue passed by JavaScript. + This is the same issue as the bug (https://bugs.webkit.org/show_bug.cgi?id=68345). + We will soon make a follow-up patch to fix these failures, after this + patch is landed. + + Test: fast/events/constructors/message-event-constructor.html + + * bindings/generic/EventConstructors.h: Added a definition for the MessageEvent constructor. + * bindings/js/JSDictionary.cpp: + (WebCore::JSDictionary::convertValue): Generates MessagePortArray from the list of message ports in the format of JSValues. + * bindings/js/JSDictionary.h: + * bindings/js/JSEventConstructors.cpp: Added #includes for MessageEvent. + * dom/MessageEvent.cpp: + (WebCore::MessageEventInit::MessageEventInit): + (WebCore::MessageEvent::MessageEvent): + (WebCore::MessageEvent::initMessageEvent): + * dom/MessageEvent.h: Added a definition for MessageEvent. Removed an extra leading spaces. + (WebCore::MessageEvent::create): + (WebCore::MessageEvent::origin): + (WebCore::MessageEvent::lastEventId): + (WebCore::MessageEvent::source): + (WebCore::MessageEvent::ports): + (WebCore::MessageEvent::dataType): + (WebCore::MessageEvent::dataAsSerializedScriptValue): + (WebCore::MessageEvent::dataAsString): + (WebCore::MessageEvent::dataAsBlob): + (WebCore::MessageEvent::dataAsArrayBuffer): + * dom/MessageEvent.idl: Makes MessageEvent constructible. + 2011-09-27 Eric Uhrhane [Chromium/FileWriter] race condition in FileWriter completion can lead to assert diff --git a/Source/WebCore/bindings/generic/EventConstructors.h b/Source/WebCore/bindings/generic/EventConstructors.h index e23bf16..82acf72 100644 --- a/Source/WebCore/bindings/generic/EventConstructors.h +++ b/Source/WebCore/bindings/generic/EventConstructors.h @@ -99,6 +99,17 @@ namespace WebCore { FILL_PROPERTY(reason) \ DICTIONARY_END(CloseEvent) +#define INSTANTIATE_INITIALIZING_CONSTRUCTOR_FOR_MESSAGE_EVENT(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \ + \ + DICTIONARY_START(MessageEvent) \ + FILL_PARENT_PROPERTIES(Event) \ + FILL_PROPERTY(data) \ + FILL_PROPERTY(origin) \ + FILL_PROPERTY(lastEventId) \ + FILL_PROPERTY(source) \ + FILL_PROPERTY(ports) \ + DICTIONARY_END(MessageEvent) + #define INSTANTIATE_ALL_EVENT_INITIALIZING_CONSTRUCTORS(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \ INSTANTIATE_INITIALIZING_CONSTRUCTOR_FOR_EVENT(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \ @@ -110,6 +121,7 @@ namespace WebCore { INSTANTIATE_INITIALIZING_CONSTRUCTOR_FOR_POP_STATE_EVENT(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \ INSTANTIATE_INITIALIZING_CONSTRUCTOR_FOR_ERROR_EVENT(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \ INSTANTIATE_INITIALIZING_CONSTRUCTOR_FOR_CLOSE_EVENT(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \ + INSTANTIATE_INITIALIZING_CONSTRUCTOR_FOR_MESSAGE_EVENT(DICTIONARY_START, DICTIONARY_END, FILL_PARENT_PROPERTIES, FILL_PROPERTY) \ } // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDictionary.cpp b/Source/WebCore/bindings/js/JSDictionary.cpp index 18bb307..58531f3 100644 --- a/Source/WebCore/bindings/js/JSDictionary.cpp +++ b/Source/WebCore/bindings/js/JSDictionary.cpp @@ -1,4 +1,3 @@ - /* * Copyright (C) 2011 Apple Inc. All rights reserved. * @@ -29,6 +28,7 @@ #include "JSDOMWindow.h" #include "JSEventTarget.h" +#include "JSMessagePortCustom.h" #include "JSNode.h" #include "SerializedScriptValue.h" #include "ScriptValue.h" @@ -119,4 +119,9 @@ void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr& result) result = toNode(value); } +void JSDictionary::convertValue(ExecState* exec, JSValue value, MessagePortArray& result) +{ + fillMessagePortArray(exec, value, result); +} + } // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDictionary.h b/Source/WebCore/bindings/js/JSDictionary.h index 2da9239..7790d70 100644 --- a/Source/WebCore/bindings/js/JSDictionary.h +++ b/Source/WebCore/bindings/js/JSDictionary.h @@ -26,6 +26,7 @@ #ifndef JSDictionary_h #define JSDictionary_h +#include "MessagePort.h" #include #include @@ -71,6 +72,7 @@ private: static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr& result); static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr& result); static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr& result); + static void convertValue(JSC::ExecState*, JSC::JSValue, MessagePortArray& result); JSC::ExecState* m_exec; JSC::JSObject* m_initializerObject; diff --git a/Source/WebCore/bindings/js/JSEventConstructors.cpp b/Source/WebCore/bindings/js/JSEventConstructors.cpp index 2ec3445..f65bfec 100644 --- a/Source/WebCore/bindings/js/JSEventConstructors.cpp +++ b/Source/WebCore/bindings/js/JSEventConstructors.cpp @@ -37,10 +37,12 @@ #include "JSErrorEvent.h" #include "JSEvent.h" #include "JSHashChangeEvent.h" +#include "JSMessageEvent.h" #include "JSPageTransitionEvent.h" #include "JSPopStateEvent.h" #include "JSProgressEvent.h" #include "JSWebKitAnimationEvent.h" +#include "MessageEvent.h" #include "PageTransitionEvent.h" #include "PopStateEvent.h" #include "ProgressEvent.h" diff --git a/Source/WebCore/dom/MessageEvent.cpp b/Source/WebCore/dom/MessageEvent.cpp index 2731fa3..6b9564b 100644 --- a/Source/WebCore/dom/MessageEvent.cpp +++ b/Source/WebCore/dom/MessageEvent.cpp @@ -33,12 +33,28 @@ namespace WebCore { +MessageEventInit::MessageEventInit() + : data(SerializedScriptValue::create()) +{ +} + MessageEvent::MessageEvent() : m_dataType(DataTypeSerializedScriptValue) , m_dataAsSerializedScriptValue(SerializedScriptValue::create()) { } +MessageEvent::MessageEvent(const AtomicString& type, const MessageEventInit& initializer) + : Event(type, initializer) + , m_dataType(DataTypeSerializedScriptValue) + , m_dataAsSerializedScriptValue(initializer.data) + , m_origin(initializer.origin) + , m_lastEventId(initializer.lastEventId) + , m_source(initializer.source) + , m_ports(adoptPtr(new MessagePortArray(initializer.ports))) +{ +} + MessageEvent::MessageEvent(PassRefPtr data, const String& origin, const String& lastEventId, PassRefPtr source, PassOwnPtr ports) : Event(eventNames().messageEvent, false, false) , m_dataType(DataTypeSerializedScriptValue) @@ -85,7 +101,7 @@ void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bo { if (dispatched()) return; - + initEvent(type, canBubble, cancelable); m_dataType = DataTypeSerializedScriptValue; diff --git a/Source/WebCore/dom/MessageEvent.h b/Source/WebCore/dom/MessageEvent.h index ded8074..6ac4dde 100644 --- a/Source/WebCore/dom/MessageEvent.h +++ b/Source/WebCore/dom/MessageEvent.h @@ -37,78 +37,94 @@ namespace WebCore { - class DOMWindow; - - class MessageEvent : public Event { - public: - static PassRefPtr create() - { - return adoptRef(new MessageEvent); - } - static PassRefPtr create(PassOwnPtr ports, PassRefPtr data = 0, const String& origin = "", const String& lastEventId = "", PassRefPtr source = 0) - { - return adoptRef(new MessageEvent(data, origin, lastEventId, source, ports)); - } - static PassRefPtr create(const String& data) - { - return adoptRef(new MessageEvent(data)); - } - static PassRefPtr create(PassRefPtr data) - { - return adoptRef(new MessageEvent(data)); - } - static PassRefPtr create(PassRefPtr data) - { - return adoptRef(new MessageEvent(data)); - } - virtual ~MessageEvent(); - - void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr); - - const String& origin() const { return m_origin; } - const String& lastEventId() const { return m_lastEventId; } - DOMWindow* source() const { return m_source.get(); } - MessagePortArray* ports() const { return m_ports.get(); } - - // 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). - void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr data, const String& origin, const String& lastEventId, DOMWindow* source, MessagePort*); - - virtual bool isMessageEvent() const; - - enum DataType { - 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(); } - - private: - MessageEvent(); - MessageEvent(PassRefPtr data, const String& origin, const String& lastEventId, PassRefPtr source, PassOwnPtr); - explicit MessageEvent(const String& data); - explicit MessageEvent(PassRefPtr data); - explicit MessageEvent(PassRefPtr data); - - DataType m_dataType; - RefPtr m_dataAsSerializedScriptValue; - String m_dataAsString; - RefPtr m_dataAsBlob; - RefPtr m_dataAsArrayBuffer; - String m_origin; - String m_lastEventId; - RefPtr m_source; - OwnPtr m_ports; +class DOMWindow; + +struct MessageEventInit : public EventInit { + MessageEventInit(); + + RefPtr data; + String origin; + String lastEventId; + RefPtr source; + MessagePortArray ports; +}; + +class MessageEvent : public Event { +public: + static PassRefPtr create() + { + return adoptRef(new MessageEvent); + } + static PassRefPtr create(PassOwnPtr ports, PassRefPtr data = 0, const String& origin = "", const String& lastEventId = "", PassRefPtr source = 0) + { + return adoptRef(new MessageEvent(data, origin, lastEventId, source, ports)); + } + static PassRefPtr create(const String& data) + { + return adoptRef(new MessageEvent(data)); + } + static PassRefPtr create(PassRefPtr data) + { + return adoptRef(new MessageEvent(data)); + } + static PassRefPtr create(PassRefPtr data) + { + return adoptRef(new MessageEvent(data)); + } + static PassRefPtr create(const AtomicString& type, const MessageEventInit& initializer) + { + return adoptRef(new MessageEvent(type, initializer)); + } + virtual ~MessageEvent(); + + void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr data, const String& origin, const String& lastEventId, DOMWindow* source, PassOwnPtr); + + const String& origin() const { return m_origin; } + const String& lastEventId() const { return m_lastEventId; } + DOMWindow* source() const { return m_source.get(); } + MessagePortArray* ports() const { return m_ports.get(); } + + // 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). + void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr data, const String& origin, const String& lastEventId, DOMWindow* source, MessagePort*); + + virtual bool isMessageEvent() const; + + enum DataType { + 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(); } + +private: + MessageEvent(); + MessageEvent(const AtomicString&, const MessageEventInit&); + MessageEvent(PassRefPtr data, const String& origin, const String& lastEventId, PassRefPtr source, PassOwnPtr); + + explicit MessageEvent(const String& data); + explicit MessageEvent(PassRefPtr data); + explicit MessageEvent(PassRefPtr data); + + DataType m_dataType; + RefPtr m_dataAsSerializedScriptValue; + String m_dataAsString; + RefPtr m_dataAsBlob; + RefPtr m_dataAsArrayBuffer; + String m_origin; + String m_lastEventId; + RefPtr m_source; + OwnPtr m_ports; +}; } // namespace WebCore diff --git a/Source/WebCore/dom/MessageEvent.idl b/Source/WebCore/dom/MessageEvent.idl index 6bb2b65..1c56326 100644 --- a/Source/WebCore/dom/MessageEvent.idl +++ b/Source/WebCore/dom/MessageEvent.idl @@ -28,7 +28,9 @@ module events { interface [ - NoStaticTables + NoStaticTables, + CanBeConstructed, + CustomConstructFunction ] MessageEvent : Event { readonly attribute DOMString origin; readonly attribute DOMString lastEventId; -- 2.7.4