- From: poot <cvsmail@w3.org>
- Date: Mon, 07 Feb 2011 17:17:47 -0500
- To: public-html-diffs@w3.org
workers; hixie: Comment out an example that uses startConversation(), which isn't yet in the spec (it's commented out also). (whatwg r5838) http://dev.w3.org/cvsweb/html5/workers/Overview.html?r1=1.274&r2=1.275&f=h http://html5.org/tools/web-apps-tracker?from=5837&to=5838 =================================================================== RCS file: /sources/public/html5/workers/Overview.html,v retrieving revision 1.274 retrieving revision 1.275 diff -u -d -r1.274 -r1.275 --- Overview.html 7 Feb 2011 21:41:08 -0000 1.274 +++ Overview.html 7 Feb 2011 22:16:32 -0000 1.275 @@ -346,8 +346,7 @@ <li><a href="#worker-used-for-background-i-o"><span class="secno">1.2.3 </span>Worker used for background I/O</a></li> <li><a href="#shared-workers-introduction"><span class="secno">1.2.4 </span>Shared workers introduction</a></li> <li><a href="#shared-state-using-a-shared-worker"><span class="secno">1.2.5 </span>Shared state using a shared worker</a></li> - <li><a href="#delegation"><span class="secno">1.2.6 </span>Delegation</a></li> - <li><a href="#providing-libraries"><span class="secno">1.2.7 </span>Providing libraries</a></ol></ol></li> + <li><a href="#delegation"><span class="secno">1.2.6 </span>Delegation</a></ol></ol></li> <li><a href="#conformance-requirements"><span class="secno">2 </span>Conformance requirements</a> <ol> <li><a href="#dependencies"><span class="secno">2.1 </span>Dependencies</a></ol></li> @@ -922,8 +921,18 @@ close(); }</pre><p>They receive two numbers in two events, perform the computation for the range of numbers thus specified, and then report the result - back to the parent.<p><a href="http://www.whatwg.org/demos/workers/multicore/page.html">View this example online</a>.<h4 id="providing-libraries"><span class="secno">1.2.7 </span>Providing libraries</h4><p><i>This section is non-normative.</i><p>Suppose that a cryptography library is made available that - provides three tasks:<dl><dt>Generate a public/private key pair</dt> + back to the parent.<p><a href="http://www.whatwg.org/demos/workers/multicore/page.html">View this example online</a>.</p><!--(this uses startConversation, which is currently commented out) + + <h4>Providing libraries</h4> + + <!- -END dev-html- -><p><i>This section is non-normative.</i></p><!- -START dev-html- -> + + <p>Suppose that a cryptography library is made available that + provides three tasks:</p> + + <dl> + + <dt>Generate a public/private key pair</dt> <dd>Takes a port, on which it will send two messages, first the public key and then the private key.</dd> @@ -944,7 +953,11 @@ channel as the plaintext. The user can close the port when it is done decrypting content.</dd> - </dl><p>The library itself is as follows:<pre>function handleMessage(e) { + </dl> + + <p>The library itself is as follows:</p> + + <pre>function handleMessage(e) { if (e.data == "genkeys") genkeys(e.ports[0]); else if (e.data == "encrypt") @@ -1002,13 +1015,19 @@ function _decrypt(k, s) { return s.substr(s.indexOf(' ')+1); -}</pre><p>Note that the crypto functions here are just stubs and don't do - real cryptography.<p>This library could be used as follows:<pre><!DOCTYPE HTML> -<html> - <head> - <title>Worker example: Crypto library</title> - <script> - var crytoLib = new Worker('libcrypto-v1.js'); // or could use 'libcrypto-v2.js' +}</pre> + + <p>Note that the crypto functions here are just stubs and don't do + real cryptography.</p> + + <p>This library could be used as follows:</p> + + <pre><!DOCTYPE HTML> +<html> + <head> + <title>Worker example: Crypto library</title> + <script> + var cryptoLib = new Worker('libcrypto-v1.js'); // or could use 'libcrypto-v2.js' function getKeys() { var state = 0; cryptoLib.startConversation("genkeys").onmessage = function (e) { @@ -1037,22 +1056,26 @@ port.close(); }; } - </script> - <style> + </script> + <style> textarea { display: block; } - </style> - </head> - <body onload="getKeys()"> - <fieldset> - <legend>Keys</legend> - <p><label>Public Key: <textarea id="public"></textarea></label></p> - <p><label>Private Key: <textarea id="private"></textarea></label></p> - </fieldset> - <p><label>Input: <textarea id="input"></textarea></label></p> - <p><button onclick="enc()">Encrypt</button> <button onclick="dec()">Decrypt</button></p> - </body> -</html></pre><p>A later version of the API, though, might want to offload all the - crypto work onto subworkers. This could be done as follows:<pre>function handleMessage(e) { + </style> + </head> + <body onload="getKeys()"> + <fieldset> + <legend>Keys</legend> + <p><label>Public Key: <textarea id="public"></textarea></label></p> + <p><label>Private Key: <textarea id="private"></textarea></label></p> + </fieldset> + <p><label>Input: <textarea id="input"></textarea></label></p> + <p><button onclick="enc()">Encrypt</button> <button onclick="dec()">Decrypt</button></p> + </body> +</html></pre> + + <p>A later version of the API, though, might want to offload all the + crypto work onto subworkers. This could be done as follows:</p> + + <pre>function handleMessage(e) { if (e.data == "genkeys") genkeys(e.ports[0]); else if (e.data == "encrypt") @@ -1087,7 +1110,13 @@ onmessage = handleMessage; else // shared worker onconnect = function (e) { e.ports[0].onmessage = handleMessage }; -</pre><p>The little subworkers would then be as follows.<p>For generating key pairs:<pre>onmessage = function (e) { +</pre> + + <p>The little subworkers would then be as follows.</p> + + <p>For generating key pairs:</p> + + <pre>onmessage = function (e) { var k = _generateKeyPair(); e.ports[0].postMessage(k[0]); e.ports[0].postMessage(k[1]); @@ -1096,7 +1125,11 @@ function _generateKeyPair() { return [Math.random(), Math.random()]; -}</pre><p>For encrypting:<pre>onmessage = function (e) { +}</pre> + + <p>For encrypting:</p> + + <pre>onmessage = function (e) { var key = e.data; e.ports[0].onmessage = function (e) { var s = e.data; @@ -1106,7 +1139,11 @@ function _encrypt(k, s) { return 'encrypted-' + k + ' ' + s; -}</pre><p>For decrypting:<pre>onmessage = function (e) { +}</pre> + + <p>For decrypting:</p> + + <pre>onmessage = function (e) { var key = e.data; e.ports[0].onmessage = function (e) { var s = e.data; @@ -1116,10 +1153,16 @@ function _decrypt(k, s) { return s.substr(s.indexOf(' ')+1); -}</pre><p>Notice how the users of the API don't have to even know that this +}</pre> + + <p>Notice how the users of the API don't have to even know that this is happening — the API hasn't changed; the library can delegate to subworkers without changing its API, even though it is - accepting data using message channels.<p><a href="http://www.whatwg.org/demos/workers/crypto/page.html">View this example online</a>.<h2 id="conformance-requirements"><span class="secno">2 </span>Conformance requirements</h2><p>All diagrams, examples, and notes in this specification are + accepting data using message channels.</p> + + <p><a href="http://www.whatwg.org/demos/workers/crypto/page.html">View this example online</a>.</p> + +(end startConversation block) (beware nested comments)--><h2 id="conformance-requirements"><span class="secno">2 </span>Conformance requirements</h2><p>All diagrams, examples, and notes in this specification are non-normative, as are all sections explicitly marked non-normative. Everything else in this specification is normative.<p>The key words "MUST", "MUST NOT", "REQUIRED", <!--"SHALL", "SHALL NOT",--> "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
Received on Monday, 7 February 2011 22:17:51 UTC