ExtendableMessageEvent.data should return the value it was initialized to
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Dec 2017 21:56:54 +0000 (21:56 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Dec 2017 21:56:54 +0000 (21:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180868

Reviewed by Geoffrey Garen.

LayoutTests/imported/w3c:

Rebaseline WPT test now that one more subtest is passing.

* web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/extendable-message-event-constructor.https-expected.txt:

Source/WebCore:

No new tests, rebaselined existing test.

* bindings/js/JSExtendableMessageEventCustom.cpp:
(WebCore::constructJSExtendableMessageEvent):
* workers/service/ExtendableMessageEvent.cpp:
(WebCore::ExtendableMessageEvent::ExtendableMessageEvent):
* workers/service/ExtendableMessageEvent.idl:

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

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/extendable-message-event-constructor.https-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSExtendableMessageEventCustom.cpp
Source/WebCore/workers/service/ExtendableMessageEvent.cpp
Source/WebCore/workers/service/ExtendableMessageEvent.idl

index baf6ec9..7c73ec4 100644 (file)
@@ -1,3 +1,14 @@
+2017-12-18  Chris Dumez  <cdumez@apple.com>
+
+        ExtendableMessageEvent.data should return the value it was initialized to
+        https://bugs.webkit.org/show_bug.cgi?id=180868
+
+        Reviewed by Geoffrey Garen.
+
+        Rebaseline WPT test now that one more subtest is passing.
+
+        * web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/extendable-message-event-constructor.https-expected.txt:
+
 2017-12-18  Youenn Fablet  <youenn@apple.com>
 
         Add support for response blob given to fetch events
index 6ad457b..a0f0d43 100644 (file)
@@ -3,11 +3,11 @@ PASS ServiceWorkerGlobalScope: ExtendableMessageEvent Constructor
 PASS no initializer specified 
 PASS `bubbles` is specified 
 PASS `cancelable` is specified 
-FAIL `data` is specified assert_equals: expected object "[object Object]" but got object "[object Object]"
+PASS `data` is specified 
 PASS `origin` is specified 
 PASS `lastEventId` is specified 
 FAIL `source` is specified assert_equals: expected object "[object MessagePort]" but got null
 FAIL `ports` is specified assert_throws: function "function () {
       createEvent({ get ports() { throw { name: 'Error' }; } }); }" threw object "TypeError: Value is not a sequence" ("TypeError") expected object "[object Object]" ("Error")
-FAIL all initial values are specified assert_equals: expected object "[object Object]" but got object "[object Object]"
+FAIL all initial values are specified assert_equals: expected object "[object MessagePort]" but got null
 
index 40275f2..b37b8ab 100644 (file)
@@ -1,3 +1,18 @@
+2017-12-18  Chris Dumez  <cdumez@apple.com>
+
+        ExtendableMessageEvent.data should return the value it was initialized to
+        https://bugs.webkit.org/show_bug.cgi?id=180868
+
+        Reviewed by Geoffrey Garen.
+
+        No new tests, rebaselined existing test.
+
+        * bindings/js/JSExtendableMessageEventCustom.cpp:
+        (WebCore::constructJSExtendableMessageEvent):
+        * workers/service/ExtendableMessageEvent.cpp:
+        (WebCore::ExtendableMessageEvent::ExtendableMessageEvent):
+        * workers/service/ExtendableMessageEvent.idl:
+
 2017-12-18  Megan Gardner  <megan_gardner@apple.com>
 
         Support Autoscrolling in contenteditable for WK2
index 1e47959..d9e250a 100644 (file)
 #if ENABLE(SERVICE_WORKER)
 #include "JSExtendableMessageEvent.h"
 
+#include "JSDOMConstructor.h"
+
 namespace WebCore {
 
 using namespace JSC;
 
+JSC::EncodedJSValue constructJSExtendableMessageEvent(JSC::ExecState& state)
+{
+    VM& vm = state.vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    UNUSED_PARAM(throwScope);
+
+    auto* jsConstructor = jsCast<JSDOMConstructorBase*>(state.jsCallee());
+    ASSERT(jsConstructor);
+    if (UNLIKELY(state.argumentCount() < 1))
+        return throwVMError(&state, throwScope, createNotEnoughArgumentsError(&state));
+    auto type = convert<IDLDOMString>(state, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    auto eventInitDict = convert<IDLDictionary<ExtendableMessageEvent::Init>>(state, state.argument(1));
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+    JSValue data = eventInitDict.data;
+    auto object = ExtendableMessageEvent::create(state, WTFMove(type), WTFMove(eventInitDict));
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+    JSValue wrapper = toJSNewlyCreated<IDLInterface<ExtendableMessageEvent>>(state, *jsConstructor->globalObject(), WTFMove(object));
+
+    // Cache the JSValue passed in for data parameter in the wrapper so the getter returns the exact value
+    // it was initialized too. We do not store the JSValue in the implementation object to avoid leaks.
+    auto* jsMessageEvent = jsCast<JSExtendableMessageEvent*>(wrapper);
+    jsMessageEvent->m_data.set(state.vm(), jsMessageEvent, data);
+
+    return JSValue::encode(wrapper);
+}
+
 JSValue JSExtendableMessageEvent::data(ExecState& state) const
 {
     if (JSValue cachedValue = m_data.get()) {
index df16b2d..2526738 100644 (file)
@@ -39,7 +39,7 @@ Ref<ExtendableMessageEvent> ExtendableMessageEvent::create(Vector<RefPtr<Message
 
 ExtendableMessageEvent::ExtendableMessageEvent(JSC::ExecState& state, const AtomicString& type, const Init& init, IsTrusted isTrusted)
     : ExtendableEvent(type, init, isTrusted)
-    , m_data(SerializedScriptValue::create(state, init.data))
+    , m_data(SerializedScriptValue::create(state, init.data, SerializationErrorMode::NonThrowing))
     , m_origin(init.origin)
     , m_lastEventId(init.lastEventId)
     , m_ports(init.ports)
index e9840b0..83f32e2 100644 (file)
  */
 
 [
-    Constructor(DOMString type, optional ExtendableMessageEventInit eventInitDict),
-    ConstructorCallWith=ScriptState,
+    CustomConstructor(DOMString type, optional ExtendableMessageEventInit eventInitDict),
     Conditional=SERVICE_WORKER,
     EnabledAtRuntime=ServiceWorker,
     Exposed=ServiceWorker,
+    JSGenerateToJSObject,
 ] interface ExtendableMessageEvent : ExtendableEvent {
     [CachedAttribute, CustomGetter] readonly attribute any data;
     readonly attribute USVString origin;