{"id":2144,"date":"2020-09-13T15:56:13","date_gmt":"2020-09-13T13:56:13","guid":{"rendered":"https:\/\/blog.atlant.is\/?p=2144"},"modified":"2021-02-21T13:35:46","modified_gmt":"2021-02-21T11:35:46","slug":"d8-cheatsheet","status":"publish","type":"post","link":"https:\/\/blog.douzeb.is\/?p=2144","title":{"rendered":"d8 cheatsheet"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blog.atlant.is\/wp-content\/uploads\/2021\/02\/v8-1024x1024.png\" alt=\"\" class=\"wp-image-3424\" width=\"512\" height=\"512\" srcset=\"https:\/\/blog.douzeb.is\/wp-content\/uploads\/2021\/02\/v8-1024x1024.png 1024w, https:\/\/blog.douzeb.is\/wp-content\/uploads\/2021\/02\/v8-300x300.png 300w, https:\/\/blog.douzeb.is\/wp-content\/uploads\/2021\/02\/v8-150x150.png 150w, https:\/\/blog.douzeb.is\/wp-content\/uploads\/2021\/02\/v8-768x768.png 768w, https:\/\/blog.douzeb.is\/wp-content\/uploads\/2021\/02\/v8-1536x1536.png 1536w, https:\/\/blog.douzeb.is\/wp-content\/uploads\/2021\/02\/v8-1200x1200.png 1200w, https:\/\/blog.douzeb.is\/wp-content\/uploads\/2021\/02\/v8.png 1900w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/figure><\/div>\n\n\n\n<p><a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/master:v8\/src\/d8\/d8.h?q=d8&amp;ss=chromium\">d8<\/a> is V8 developer shell<span id='easy-footnote-1-2144' class='easy-footnote-margin-adjust'><\/span><span class='easy-footnote'><a href='https:\/\/blog.douzeb.is\/?p=2144#easy-footnote-bottom-1-2144' title='d8 stands for developer the same way i18n stands for internationalization and l10n stands for localization.'><sup>1<\/sup><\/a><\/span>: a powerful JavaScript interpreter and a convenient tool for developing CLI-based utilities.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Useful documentation for d8 include:<\/p>\n\n\n\n<ul><li>the <a href=\"https:\/\/v8.dev\/docs\/d8\">d8 page<\/a> on v8.dev<\/li><li>Kevin Ennis\u2019s <a href=\"https:\/\/gist.github.com\/kevincennis\/0cd2138c78a07412ef21\">d8 guide<\/a><\/li><li>the <a href=\"https:\/\/riptutorial.com\/v8\/example\/25393\/useful-built-in-functions-and-objects-in-d8\">getting started with d8 pages<\/a> on RIP tutorial<\/li><\/ul>\n\n\n\n<p>Of particular interest:<\/p>\n\n\n\n<ul><li><a href=\"#new-worker-with-inlined-script\">new Worker with inlined script<\/a><\/li><\/ul>\n\n\n\n<h4 id=\"new-worker-with-inlined-script\">New Worker with inlined script<\/h4>\n\n\n\n<p>This undocumented syntax<span id='easy-footnote-2-2144' class='easy-footnote-margin-adjust'><\/span><span class='easy-footnote'><a href='https:\/\/blog.douzeb.is\/?p=2144#easy-footnote-bottom-2-2144' title='Look for the &lt;code&gt;Shell::WorkerNew&lt;\/code&gt; method in the d8 &lt;a href=&quot;https:\/\/denolib.github.io\/v8-docs\/d8_8cc_source.html&quot;&gt;source&lt;\/a&gt;.'><sup>2<\/sup><\/a><\/span> allows for spawning a Worker and passing the script parameter directly as a string.<\/p>\n\n\n\n<pre style=\"font-size:15px !important;\"><code class=\"language-js;\"><!--const script = 'console.log(42)'; \nlet worker = new Worker(script, {type: 'string'});--><\/code><\/pre>\n\n\n\n<p>Note that d8 does not support the <a href=\"https:\/\/stackoverflow.com\/questions\/12381882\/can-i-pass-parameters-to-js-function-when-i-create-the-new-web-workers-object\">location construct<\/a> for passing environment variables to a new worker: instead simply set the variables directly in the code of the worker.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>d8 is V8 developer shell: a powerful JavaScript interpreter and a convenient tool for developing CLI-based utilities.<\/p>\n","protected":false},"author":1,"featured_media":3422,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23,21],"tags":[],"ppma_author":[76],"authors":[{"term_id":76,"user_id":1,"is_guest":0,"slug":"fred","display_name":"Fred","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/ec0326d654fdf9f66e9eb42bb34a9bc4?s=96&d=mm&r=g","description":"","first_name":"","last_name":"","user_url":""}],"_links":{"self":[{"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=\/wp\/v2\/posts\/2144"}],"collection":[{"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2144"}],"version-history":[{"count":11,"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=\/wp\/v2\/posts\/2144\/revisions"}],"predecessor-version":[{"id":3495,"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=\/wp\/v2\/posts\/2144\/revisions\/3495"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=\/wp\/v2\/media\/3422"}],"wp:attachment":[{"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2144"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.douzeb.is\/index.php?rest_route=%2Fwp%2Fv2%2Fppma_author&post=2144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}