Bug 87384 - postMessage and webkitPostMessage should behave the same way
Summary: postMessage and webkitPostMessage should behave the same way
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks: 87118
  Show dependency treegraph
 
Reported: 2012-05-24 06:13 PDT by Chris Dumez
Modified: 2012-05-24 16:56 PDT (History)
9 users (show)

See Also:


Attachments
Patch (3.60 KB, patch)
2012-05-24 06:24 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (8.00 KB, patch)
2012-05-24 06:54 PDT, Chris Dumez
abarth: review-
Details | Formatted Diff | Diff
Patch (12.02 KB, patch)
2012-05-24 10:55 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2012-05-24 06:13:31 PDT
In Bug 73589, the V8 implementation has been updated in order to support transfer of MessagePorts. This follows the latest "implementation-ready" spec.
However, the JSC implementation has not been updated accordingly.

The following test case is supposed to test it:
  fast/dom/Window/window-postmessage-args.html

In particular, this check:
  tryPostMessageFunction(window.postMessage, channel3.port1, '*', [channel3.port1, channel3.port2]);

However, with JSC, this will not throw because of Bug 87118 (SerializedScriptValue.create() succeeds even if MessagePort object cannot be found in transferred ports).
Comment 1 Chris Dumez 2012-05-24 06:24:15 PDT
Created attachment 143812 [details]
Patch

The new expected global result for fast/dom/Window/window-postmessage-args.html is now closer to the one for Chromium. The remaining diff is:
3,8c3,8
< PASS: Posting message ('1', 1): threw exception TypeError: Type error
< PASS: Posting message ('1', 1): threw exception TypeError: Type error
< PASS: Posting message ('2', c): threw exception TypeError: Type error
< PASS: Posting message ('2', c): threw exception TypeError: Type error
< PASS: Posting message ('3', [object Object]): threw exception TypeError: Type error
< PASS: Posting message ('3', [object Object]): threw exception TypeError: Type error
---
> PASS: Posting message ('1', 1): threw exception TypeError: TransferArray argument must be an object
> PASS: Posting message ('1', 1): threw exception TypeError: TransferArray argument must be an object
> PASS: Posting message ('2', c): threw exception TypeError: TransferArray argument must be an object
> PASS: Posting message ('2', c): threw exception TypeError: TransferArray argument must be an object
> PASS: Posting message ('3', [object Object]): threw exception TypeError: TransferArray argument has no length attribute
> PASS: Posting message ('3', [object Object]): threw exception TypeError: TransferArray argument has no length attribute
Comment 2 Chris Dumez 2012-05-24 06:54:33 PDT
Created attachment 143820 [details]
Patch

Update JSC implementation of postMessage for MessagePort, DedicatedWorkerContext and Worker as well. This now matches the V8 implementation.
Comment 3 Adam Barth 2012-05-24 08:43:06 PDT
Comment on attachment 143820 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=143820&action=review

Rather than introduce a difference between postMessage and webkitPotMessage, I'd rather change both to be the same and match the spec.  I believe that means always passing "true" for this value, including in V8.

> Source/WebCore/ChangeLog:28
> +2012-05-24  Christophe Dumez  <christophe.dumez@intel.com>

Looks like you've got an extra ChangeLog entry.
Comment 4 Chris Dumez 2012-05-24 10:55:26 PDT
Created attachment 143850 [details]
Patch

Make postMessage behave the same way as webkitPostMessage, meaning that it supports transfer of MessagePorts and ArrayBuffers. Both JSC and V8 implementations have been updated, as per Adam Barth's feedback.

Instead of passing 'true' always for extendedTransfer argument, I simply removed it. It is never used without extended transfer so I thought I would clean up.
Comment 5 Adam Barth 2012-05-24 10:58:24 PDT
+levin because we've discussed this in the past.
Comment 6 Adam Barth 2012-05-24 11:00:18 PDT
Comment on attachment 143850 [details]
Patch

Thanks.  There's some compatibility risk with this change, but it seems like the right thing to do.
Comment 7 David Levin 2012-05-24 11:12:00 PDT
Fine with me. Adding Oliver just in case he had any concerns.
Comment 8 Alexey Proskuryakov 2012-05-24 12:23:56 PDT
> Rather than introduce a difference between postMessage and webkitPotMessage, I'd rather change both to be the same and match the spec.  

I do not have a lot of insight in this particular issue, but in general, this doesn't sounds like a great approach. Why break existing pages that use a webkit-prefixed version when new pages will use unprefixed one anyway?

There is some risk of a page doing something like "if (!window.postMessage && window.webkitPostMessage) window.postMessage = window.webkitPostMessage" and not testing in old browser versions. But breaking old browser versions seems like a much lesser evil than breaking pages.
Comment 9 David Levin 2012-05-24 12:26:36 PDT
(In reply to comment #8)
> > Rather than introduce a difference between postMessage and webkitPotMessage, I'd rather change both to be the same and match the spec.  
> 
> I do not have a lot of insight in this particular issue, but in general, this doesn't sounds like a great approach. Why break existing pages that use a webkit-prefixed version when new pages will use unprefixed one anyway?
> 
> There is some risk of a page doing something like "if (!window.postMessage && window.webkitPostMessage) window.postMessage = window.webkitPostMessage" and not testing in old browser versions. But breaking old browser versions seems like a much lesser evil than breaking pages.

The behavior of postMessage has been augmented. webkitPostMessage should be unaffected and the change to postMessage is backward compatible.
Comment 10 Adam Barth 2012-05-24 12:37:05 PDT
> There is some risk of a page doing something like "if (!window.postMessage && window.webkitPostMessage)

This conditional will never return true because there never existed a browser that contained webkitPostMessage but not postMessage.
Comment 11 WebKit Review Bot 2012-05-24 16:56:14 PDT
Comment on attachment 143850 [details]
Patch

Clearing flags on attachment: 143850

Committed r118445: <http://trac.webkit.org/changeset/118445>
Comment 12 WebKit Review Bot 2012-05-24 16:56:26 PDT
All reviewed patches have been landed.  Closing bug.