Bug 28839 - Need to update v8 bindings to support passing multiple ports to postMessage()
Summary: Need to update v8 bindings to support passing multiple ports to postMessage()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Andrew Wilson
URL:
Keywords:
Depends on: 28460
Blocks:
  Show dependency treegraph
 
Reported: 2009-08-30 23:14 PDT by Andrew Wilson
Modified: 2009-09-03 11:37 PDT (History)
0 users

See Also:


Attachments
proposed patch (17.25 KB, patch)
2009-08-30 23:21 PDT, Andrew Wilson
dglazkov: review-
Details | Formatted Diff | Diff
patch addressing review comments (17.16 KB, patch)
2009-09-01 17:09 PDT, Andrew Wilson
dglazkov: review+
dglazkov: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Wilson 2009-08-30 23:14:24 PDT
The HTML5 spec not supports passing multiple ports to postMessage() - we need to update the v8 bindings accordingly.
Comment 1 Andrew Wilson 2009-08-30 23:21:30 PDT
Created attachment 38801 [details]
proposed patch

v8 bindings portion of bug 28460
Comment 2 Eric Seidel (no email) 2009-08-31 02:59:56 PDT
Comment on attachment 38801 [details]
proposed patch

Would be even better to list what tests now pass after this change:
 10         No new tests (tests for JSC bindings are sufficient)

I looked briefly, but it seems you'll need a v8 expert here.  Geez v8 bindings are so wordy/ugly!
Comment 3 Dimitri Glazkov (Google) 2009-08-31 11:13:34 PDT
Comment on attachment 38801 [details]
proposed patch

These are all style nits:

> +        if (!fillWebCoreMessagePortArray(args[1], portArray))
> +            return v8::Undefined();

if (!getMessagePortArray(.. is the common convention in WebKit. No need to use WebCore in prefix. It's in String conv methods only because there are two ambiguous string types.

> +        if (!fillWebCoreMessagePortArray(args[1], portArray))

ditto.

> +    if (ec)
> +        V8Proxy::setDOMException(ec);

return throwError(ec);

> +
> +CALLBACK_FUNC_DECL(MessageEventInitMessageEvent)
> +{
> +    INC_STATS("DOM.MessageEvent.initMessageEvent");
> +    MessageEvent* event = V8DOMWrapper::convertToNativeObject<MessageEvent>(V8ClassIndex::MESSAGEEVENT, args.Holder());
> +    String typeArg = v8ValueToWebCoreString(args[0]);
> +    bool canBubbleArg = args[1]->BooleanValue();
> +    bool cancelableArg = args[2]->BooleanValue();
> +    String dataArg = v8ValueToWebCoreString(args[3]);
> +    String originArg = v8ValueToWebCoreString(args[4]);
> +    String lastEventIdArg = v8ValueToWebCoreString(args[5]);
> +    DOMWindow* sourceArg = V8DOMWindow::HasInstance(args[6]) ? V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, v8::Handle<v8::Object>::Cast(args[6])) : 0;

I am surprised there's no arg checking here. Is this correct?

> +    if (ec)
> +        V8Proxy::setDOMException(ec);

return throwError(ec);

> +bool fillWebCoreMessagePortArray(v8::Local<v8::Value> value, MessagePortArray& portArray)

bool getMessagePortArray(v8::Local<v8::Value> value, MessagePortArray& portArray)

> +    if (!value->IsObject()) {
> +        V8Proxy::throwError(V8Proxy::TypeError, "MessagePortArray argument must be an object");
> +        return false;

throwError("MessagePortArray argument must be an object");
return false;

> +        v8::Local<v8::Value> sequenceLength = ports->Get(v8::String::New("length"));
> +        if (!sequenceLength->IsNumber()) {
> +            V8Proxy::throwError(V8Proxy::TypeError, "MessagePortArray argument has no length attribute");
> +            return false;

throwError("MessagePortArray argument has no length attribute");
return false;

> +            V8Proxy::setDOMException(INVALID_STATE_ERR);
> +            return false;


throwError(ec);
return false;

> +            V8Proxy::throwError(V8Proxy::TypeError, "MessagePortArray argument must contain only MessagePorts");
> +            return false;

ditto.

> +    if (ec)
> +        V8Proxy::setDOMException(ec);

return throwError(ec);
Comment 4 Andrew Wilson 2009-08-31 11:22:08 PDT
(In reply to comment #3)

> 
> > +
> > +CALLBACK_FUNC_DECL(MessageEventInitMessageEvent)
> > +{
> > +    INC_STATS("DOM.MessageEvent.initMessageEvent");
> > +    MessageEvent* event = V8DOMWrapper::convertToNativeObject<MessageEvent>(V8ClassIndex::MESSAGEEVENT, args.Holder());
> > +    String typeArg = v8ValueToWebCoreString(args[0]);
> > +    bool canBubbleArg = args[1]->BooleanValue();
> > +    bool cancelableArg = args[2]->BooleanValue();
> > +    String dataArg = v8ValueToWebCoreString(args[3]);
> > +    String originArg = v8ValueToWebCoreString(args[4]);
> > +    String lastEventIdArg = v8ValueToWebCoreString(args[5]);
> > +    DOMWindow* sourceArg = V8DOMWindow::HasInstance(args[6]) ? V8DOMWrapper::convertToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, v8::Handle<v8::Object>::Cast(args[6])) : 0;
> 
> I am surprised there's no arg checking here. Is this correct?

This is basically the verbatim code from the generated bindings (before I made this a custom binding).

I guess it's because pretty much anything (including an undefined argument) can be cast to a string/boolean, so the only arg checking that needs to be done is for the DOMWindow argument.

I'll make those other changes as suggested - thanks for the quick turnaround!
Comment 5 Andrew Wilson 2009-09-01 17:09:05 PDT
Created attachment 38901 [details]
patch addressing review comments
Comment 6 Dimitri Glazkov (Google) 2009-09-02 16:25:52 PDT
Comment on attachment 38901 [details]
patch addressing review comments

r=me.
Comment 7 Andrew Wilson 2009-09-03 11:37:55 PDT
Committed as r48026