Changeset 201835 in webkit


Ignore:
Timestamp:
Jun 8, 2016 3:14:55 PM (8 years ago)
Author:
Chris Dumez
Message:

First parameter to MessagePort / DedicatedWorkerGlobalScope.postMessage() should be mandatory
https://bugs.webkit.org/show_bug.cgi?id=158540

Reviewed by Geoffrey Garen.

Source/WebCore:

First parameter to MessagePort / DedicatedWorkerGlobalScope.postMessage() should be mandatory:

Previously, WebKit send a bogus MessageEvent whose data attribute is undefined. This would
cause a testharness error when running the following W3C test:

Firefox and Chrome already correctly throw in this case. Our Window.postMessage() API is also
already throwing in this case.

Test: fast/workers/postMessage-missing-parameter.html

  • bindings/js/JSMessagePortCustom.h:

(WebCore::handlePostMessage):

LayoutTests:

Add test coverage.

  • fast/files/workers/inline-worker-via-blob-url.html:
  • fast/workers/postMessage-missing-parameter-expected.txt: Added.
  • fast/workers/postMessage-missing-parameter.html: Added.
  • fast/workers/worker-messageport-expected.txt:
  • fast/workers/worker-messageport.html:
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r201832 r201835  
     12016-06-08  Chris Dumez  <cdumez@apple.com>
     2
     3        First parameter to MessagePort / DedicatedWorkerGlobalScope.postMessage() should be mandatory
     4        https://bugs.webkit.org/show_bug.cgi?id=158540
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Add test coverage.
     9
     10        * fast/files/workers/inline-worker-via-blob-url.html:
     11        * fast/workers/postMessage-missing-parameter-expected.txt: Added.
     12        * fast/workers/postMessage-missing-parameter.html: Added.
     13        * fast/workers/worker-messageport-expected.txt:
     14        * fast/workers/worker-messageport.html:
     15
    1162016-06-08  Nan Wang  <n_wang@apple.com>
    217
  • trunk/LayoutTests/fast/files/workers/inline-worker-via-blob-url.html

    r125149 r201835  
    2424            testRunner.notifyDone();
    2525    };
    26     worker.postMessage();
     26    worker.postMessage("message");
    2727}
    2828
  • trunk/LayoutTests/fast/workers/worker-messageport-expected.txt

    r93709 r201835  
    55PASS: Received response from Worker via MessagePort
    66PASS: Got port from worker
     7PASS: Calling MessagePort.postMessage() without parameter threw exception: TypeError: Not enough arguments
    78PASS: Received final response from worker
    89PASS: Got 1000 messages
  • trunk/LayoutTests/fast/workers/worker-messageport.html

    r124680 r201835  
    5252        } else {
    5353            log("PASS: Got port from worker");
     54            try {
     55                // Missing parameter, should throw.
     56                evt.ports[0].postMessage();
     57                log("FAIL: Calling MessagePort.postMessage() without parameter did not throw.");
     58            } catch (e) {
     59                log("PASS: Calling MessagePort.postMessage() without parameter threw exception: " + e);
     60            }
    5461            evt.ports[0].postMessage("ping");
    5562            evt.ports[0].onmessage = function(evt) {
  • trunk/Source/WebCore/ChangeLog

    r201834 r201835  
     12016-06-08  Chris Dumez  <cdumez@apple.com>
     2
     3        First parameter to MessagePort / DedicatedWorkerGlobalScope.postMessage() should be mandatory
     4        https://bugs.webkit.org/show_bug.cgi?id=158540
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        First parameter to MessagePort / DedicatedWorkerGlobalScope.postMessage() should be mandatory:
     9        - https://html.spec.whatwg.org/multipage/comms.html#messageport
     10        - https://html.spec.whatwg.org/multipage/workers.html#dedicated-workers-and-the-dedicatedworkerglobalscope-interface
     11
     12        Previously, WebKit send a bogus MessageEvent whose data attribute is undefined. This would
     13        cause a testharness error when running the following W3C test:
     14        - http://w3c-test.org/workers/interfaces.worker
     15
     16        Firefox and Chrome already correctly throw in this case. Our Window.postMessage() API is also
     17        already throwing in this case.
     18
     19        Test: fast/workers/postMessage-missing-parameter.html
     20
     21        * bindings/js/JSMessagePortCustom.h:
     22        (WebCore::handlePostMessage):
     23
    1242016-06-08  Gavin Barraclough  <barraclough@apple.com>
    225
  • trunk/Source/WebCore/bindings/js/JSMessagePortCustom.h

    r190036 r201835  
    3333
    3434#include "MessagePort.h"
     35#include <runtime/Error.h>
    3536#include <runtime/JSCInlines.h>
    3637#include <runtime/JSCJSValue.h>
     
    5051    inline JSC::JSValue handlePostMessage(JSC::ExecState& state, T* impl)
    5152    {
     53        if (UNLIKELY(state.argumentCount() < 1))
     54            return state.vm().throwException(&state, createNotEnoughArgumentsError(&state));
     55
    5256        MessagePortArray portArray;
    5357        ArrayBufferArray arrayBufferArray;
    5458        fillMessagePortArray(state, state.argument(1), portArray, arrayBufferArray);
    55         RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(&state, state.argument(0), &portArray, &arrayBufferArray);
     59        RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(&state, state.uncheckedArgument(0), &portArray, &arrayBufferArray);
    5660        if (state.hadException())
    5761            return JSC::jsUndefined();
Note: See TracChangeset for help on using the changeset viewer.