Bug 27419

Summary: Storing a reference to WorkerContext.postMessage() and calling it later yields a TypeError
Product: WebKit Reporter: Andrew Wilson <atwilson@chromium.org>
Component: WebCore JavaScriptAssignee: Dmitry Titov <dimich@chromium.org>
Status: RESOLVED FIXED    
Severity: Normal CC: ap@webkit.org, dimich@chromium.org, sam@webkit.org
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Mac OS X 10.5   
Bug Depends on: 27420    
Bug Blocks:    
Attachments:
Description Flags
test case
none
proposed patch abarth: review+

Description From 2009-07-18 17:51:47 PST
There are a number of functions defined at global scope in WorkerContext - for example, setTimeout() and postMessage() are both defined in the worker global context.

It's perfectly valid for worker code to do this:

postMessage("hello");

However, if the worker code does this instead, it gets a TypeError:

var saved = postMessage;
saved("hello");
------- Comment #1 From 2009-07-18 17:58:36 PST -------
The test case works in Chromium, so it's somewhere in the JSC bindings.
------- Comment #2 From 2009-07-20 10:30:23 PST -------
On a related note, the following line of code from Worker Context results in a TypeError also:

postMessage.call(null, "foobar");
------- Comment #3 From 2009-07-20 10:50:44 PST -------
Created an attachment (id=33094) [details]
test case

test case that shows this problem (passes on FF/Chrome, fails on Safari 4)
------- Comment #4 From 2009-07-21 13:52:48 PST -------
Created an attachment (id=33209) [details]
proposed patch

This is dependent on 27420 as it relies on the IsWorkerContext attribute added in that patch.
------- Comment #5 From 2009-07-23 23:11:40 PST -------
(From update of attachment 33209 [details])
Awesome.  Thanks for the patch.
------- Comment #6 From 2009-07-24 11:01:13 PST -------
assingning to me for landing
------- Comment #7 From 2009-07-24 12:56:49 PST -------
Landed: http://trac.webkit.org/changeset/46371