-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a PostMessageOptions API to workers and message_port
The current pull request against the HTML spec is here: whatwg/html#3799 Rename the RuntimeEnabledFeature from WindowPostMessageOptions to PostMessageOptions BUG=861735 Change-Id: Ia7980a85c10535f6d531c87f3790efcf6ed2d54d Reviewed-on: https://chromium-review.googlesource.com/1169304 Commit-Queue: Dave Tapuska <[email protected]> Reviewed-by: Marijn Kruisselbrink <[email protected]> Reviewed-by: Kentaro Hara <[email protected]> Cr-Commit-Position: refs/heads/master@{#582619}
- Loading branch information
Showing
5 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
service-workers/service-worker/resources/postmessage-dictionary-transferables-worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var messageHandler = function(port, e) { | ||
var text_decoder = new TextDecoder; | ||
port.postMessage({ | ||
content: text_decoder.decode(e.data), | ||
byteLength: e.data.byteLength | ||
}); | ||
|
||
// Send back the array buffer via Client.postMessage. | ||
port.postMessage(e.data, {transfer: [e.data.buffer]}); | ||
|
||
port.postMessage({ | ||
content: text_decoder.decode(e.data), | ||
byteLength: e.data.byteLength | ||
}); | ||
}; | ||
|
||
self.addEventListener('message', e => { | ||
if (e.ports[0]) { | ||
// Wait for messages sent via MessagePort. | ||
e.ports[0].onmessage = messageHandler.bind(null, e.ports[0]); | ||
return; | ||
} | ||
messageHandler(e.source, e); | ||
}); |
18 changes: 18 additions & 0 deletions
18
webmessaging/message-channels/dictionary-transferrable.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!doctype html> | ||
<title>basic messagechannel with transfer</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<div id="log"></div> | ||
<script> | ||
async_test(function(t) { | ||
var channel = new MessageChannel(); | ||
var ab = new ArrayBuffer(1); | ||
channel.port1.postMessage(ab, {transfer: [ab]}); | ||
channel.port2.onmessage = t.step_func( | ||
function(e) { | ||
assert_equals(e.data.byteLength, 1); | ||
t.done(); | ||
}); | ||
channel.port2.start(); | ||
}); | ||
</script> |
29 changes: 29 additions & 0 deletions
29
workers/interfaces/DedicatedWorkerGlobalScope/postMessage/second-argument-dictionary.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!-- | ||
onmessage = (event) => { | ||
try { | ||
postMessage(event.data, {transfer: [event.data]}); | ||
} catch(e) { | ||
postMessage(''+e); | ||
} | ||
} | ||
/* | ||
--> | ||
<!doctype html> | ||
<title>Using dictionary as postMessage's second argument</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<div id="log"></div> | ||
<script> | ||
(async_test()).step(function() { | ||
var worker = new Worker('#'); | ||
var ab = new ArrayBuffer(1); | ||
worker.postMessage(ab, {transfer: [ab]}); | ||
worker.onmessage = this.step_func(function(e) { | ||
assert_equals(e.data.byteLength, 1); | ||
this.done(); | ||
}); | ||
}); | ||
</script> | ||
<!-- | ||
*/ | ||
//--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters