diff --git a/.dprint.json b/.dprint.json index a0d7690942af7d..dfaed6314b5aa8 100644 --- a/.dprint.json +++ b/.dprint.json @@ -38,9 +38,9 @@ "tools/wpt/manifest.json" ], "plugins": [ - "https://plugins.dprint.dev/typescript-0.60.0.wasm", - "https://plugins.dprint.dev/json-0.13.2.wasm", - "https://plugins.dprint.dev/markdown-0.11.3.wasm", + "https://plugins.dprint.dev/typescript-0.61.0.wasm", + "https://plugins.dprint.dev/json-0.14.0.wasm", + "https://plugins.dprint.dev/markdown-0.12.0.wasm", "https://plugins.dprint.dev/toml-0.5.3.wasm" ] } diff --git a/.github/mtime_cache/action.js b/.github/mtime_cache/action.js index 8c00f1925d7555..e77fe0b9f9b7ee 100644 --- a/.github/mtime_cache/action.js +++ b/.github/mtime_cache/action.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // This file contains the implementation of a Github Action. Github uses // Node.js v12.x to run actions, so this is Node code and not Deno code. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e4dd3d0d1ff48..0b1f540d5ef83c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -262,7 +262,7 @@ jobs: ~/.cargo/registry/index ~/.cargo/registry/cache ~/.cargo/git/db - key: 2-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }} + key: 3-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }} # In main branch, always creates fresh cache - name: Cache build output (main) @@ -278,7 +278,7 @@ jobs: !./target/*/*.zip !./target/*/*.tar.gz key: | - 2-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }} + 3-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }} # Restore cache from the latest 'main' branch build. - name: Cache build output (PR) @@ -294,7 +294,7 @@ jobs: !./target/*/*.tar.gz key: never_saved restore-keys: | - 2-cargo-target-${{ matrix.os }}-${{ matrix.profile }}- + 3-cargo-target-${{ matrix.os }}-${{ matrix.profile }}- # Don't save cache after building PRs or branches other than 'main'. - name: Skip save cache (PR) diff --git a/.rustfmt.toml b/.rustfmt.toml index 7d282f4f0b2d05..b86b9a6e86db35 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,4 +1,4 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. max_width = 80 tab_spaces = 2 edition = "2021" diff --git a/Cargo.lock b/Cargo.lock index 98f47340ab4d1c..c919f7beaa07a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aead" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" +dependencies = [ + "generic-array", +] + [[package]] name = "aes" version = "0.7.5" @@ -36,6 +45,20 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "aes-gcm" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", +] + [[package]] name = "ahash" version = "0.7.6" @@ -91,9 +114,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" +checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3" [[package]] name = "arrayvec" @@ -121,9 +144,9 @@ dependencies = [ [[package]] name = "ast_node" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96d5444b02f3080edac8a144f6baf29b2fb6ff589ad4311559731a7c7529381" +checksum = "82b2dd56b7c509b3a0bb47a97a066cba459983470d3b8a3c20428737270f70bd" dependencies = [ "darling", "pmutil", @@ -643,9 +666,18 @@ dependencies = [ "matches", ] +[[package]] +name = "debug_unreachable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a032eac705ca39214d169f83e3d3da290af06d8d1d344d1baad2fd002dca4b3" +dependencies = [ + "unreachable", +] + [[package]] name = "deno" -version = "1.17.1" +version = "1.17.2" dependencies = [ "atty", "base64 0.13.0", @@ -716,9 +748,9 @@ dependencies = [ [[package]] name = "deno_ast" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f1c58caca74265d1c63a5c26069e037846f8bdf6a3e2dde3da66c6f6f51297d" +checksum = "72a3eb87c6fddf68e02f7438728a611ff6ca84a644fc00d3b9ad5a006e212484" dependencies = [ "data-url", "dprint-swc-ecma-ast-view", @@ -733,7 +765,7 @@ dependencies = [ [[package]] name = "deno_bench_util" -version = "0.24.0" +version = "0.25.0" dependencies = [ "bencher", "deno_core", @@ -742,7 +774,7 @@ dependencies = [ [[package]] name = "deno_broadcast_channel" -version = "0.24.0" +version = "0.25.0" dependencies = [ "async-trait", "deno_core", @@ -752,14 +784,14 @@ dependencies = [ [[package]] name = "deno_console" -version = "0.30.0" +version = "0.31.0" dependencies = [ "deno_core", ] [[package]] name = "deno_core" -version = "0.112.0" +version = "0.113.0" dependencies = [ "anyhow", "futures", @@ -779,9 +811,10 @@ dependencies = [ [[package]] name = "deno_crypto" -version = "0.44.0" +version = "0.45.0" dependencies = [ "aes", + "aes-gcm", "base64 0.13.0", "block-modes", "ctr", @@ -806,9 +839,9 @@ dependencies = [ [[package]] name = "deno_doc" -version = "0.24.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6563f9d5f40a4e8c29a43a512536734f22eca1e7f86de1eb6d6d7d5a622c2afb" +checksum = "e3fd524cf36cae45b06de577f8f18b6ef786b56a3840fb721923ccddeeb09833" dependencies = [ "cfg-if 1.0.0", "deno_ast", @@ -823,7 +856,7 @@ dependencies = [ [[package]] name = "deno_fetch" -version = "0.53.0" +version = "0.54.0" dependencies = [ "bytes", "data-url", @@ -840,7 +873,7 @@ dependencies = [ [[package]] name = "deno_ffi" -version = "0.17.0" +version = "0.18.0" dependencies = [ "deno_core", "dlopen", @@ -852,9 +885,9 @@ dependencies = [ [[package]] name = "deno_graph" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db82fb9c644a51d9d4303ff21d04c4c3e32175576efbddc1c7498eda665ea4fd" +checksum = "c5eda28d50fc84d2b1774829316dcecdce1d41f0923b3a174f88cd599cafd529" dependencies = [ "anyhow", "cfg-if 1.0.0", @@ -873,7 +906,7 @@ dependencies = [ [[package]] name = "deno_http" -version = "0.22.0" +version = "0.23.0" dependencies = [ "base64 0.13.0", "bytes", @@ -888,9 +921,9 @@ dependencies = [ [[package]] name = "deno_lint" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c213b1d00e3579f156d95cb8329de2d0fcc85b308cdec0b9ec954f840a5ebc7c" +checksum = "90b4b3dfb590568c6cb9ff24d4fb36645b47e480059517420fcb5d19758f75c9" dependencies = [ "anyhow", "deno_ast", @@ -905,7 +938,7 @@ dependencies = [ [[package]] name = "deno_net" -version = "0.22.0" +version = "0.23.0" dependencies = [ "deno_core", "deno_tls", @@ -918,7 +951,7 @@ dependencies = [ [[package]] name = "deno_runtime" -version = "0.38.0" +version = "0.39.0" dependencies = [ "atty", "deno_broadcast_channel", @@ -953,6 +986,7 @@ dependencies = [ "regex", "ring", "serde", + "signal-hook-registry", "sys-info", "termcolor", "test_util", @@ -964,7 +998,7 @@ dependencies = [ [[package]] name = "deno_timers" -version = "0.28.0" +version = "0.29.0" dependencies = [ "deno_bench_util", "deno_core", @@ -976,7 +1010,7 @@ dependencies = [ [[package]] name = "deno_tls" -version = "0.17.0" +version = "0.18.0" dependencies = [ "deno_core", "once_cell", @@ -990,7 +1024,7 @@ dependencies = [ [[package]] name = "deno_url" -version = "0.30.0" +version = "0.31.0" dependencies = [ "deno_bench_util", "deno_core", @@ -1002,7 +1036,7 @@ dependencies = [ [[package]] name = "deno_web" -version = "0.61.0" +version = "0.62.0" dependencies = [ "async-trait", "base64 0.13.0", @@ -1015,7 +1049,7 @@ dependencies = [ [[package]] name = "deno_webgpu" -version = "0.31.0" +version = "0.32.0" dependencies = [ "deno_core", "serde", @@ -1026,14 +1060,14 @@ dependencies = [ [[package]] name = "deno_webidl" -version = "0.30.0" +version = "0.31.0" dependencies = [ "deno_core", ] [[package]] name = "deno_websocket" -version = "0.35.0" +version = "0.36.0" dependencies = [ "deno_core", "deno_tls", @@ -1047,7 +1081,7 @@ dependencies = [ [[package]] name = "deno_webstorage" -version = "0.25.0" +version = "0.26.0" dependencies = [ "deno_core", "deno_web", @@ -1124,10 +1158,11 @@ dependencies = [ [[package]] name = "dprint-core" -version = "0.47.1" +version = "0.49.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6400fcb8f2d6d4a231d2fc374edd1cf0e3713439e781a680b4b4f2afe2d31c7e" +checksum = "8113ac9998173de8fa4fcf6fc7fe80c15c93df290828afa060dbdbb84337afbf" dependencies = [ + "anyhow", "bumpalo", "rustc-hash", "serde", @@ -1135,10 +1170,11 @@ dependencies = [ [[package]] name = "dprint-plugin-json" -version = "0.13.2" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aba7fe282566c4f217295b19d69ddaee7a4e179a6ea63f28efc7cc7b9fd766c" +checksum = "6c531c535098419053a6ad7a166c7cfb940a54f97a36f934315394e61a329d85" dependencies = [ + "anyhow", "dprint-core", "jsonc-parser", "serde", @@ -1146,10 +1182,11 @@ dependencies = [ [[package]] name = "dprint-plugin-markdown" -version = "0.11.3" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b28f3f469ccd62d6e93fec9926dae032b8e8e05ffc20217c05e80b27ed372e3" +checksum = "835cf6371fc1474544f70dd28778789bd39474093997fb721c36082b0b4ee316" dependencies = [ + "anyhow", "dprint-core", "pulldown-cmark", "regex", @@ -1158,10 +1195,11 @@ dependencies = [ [[package]] name = "dprint-plugin-typescript" -version = "0.60.0" +version = "0.61.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0a43c5093e898d4fc54b14c2583d83e9ab30d68e3bde374ab6a74996af2f1e2" +checksum = "e2cf0922de1556135f425df4de9968fd0b8e424eebc7fdb4001058c678bde475" dependencies = [ + "anyhow", "deno_ast", "dprint-core", "parking_lot_core", @@ -1171,9 +1209,9 @@ dependencies = [ [[package]] name = "dprint-swc-ecma-ast-view" -version = "0.45.0" +version = "0.47.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2654eb6e5d6e02096f6969d1370e9e474b43c9ad1a7142556c7d1e9d1afe0a" +checksum = "bbbf1d058db8ad7c9790db7dbe852d0cbddd2a314e592387232fa3db02fe0771" dependencies = [ "bumpalo", "num-bigint", @@ -1600,6 +1638,16 @@ dependencies = [ "wasi 0.10.0+wasi-snapshot-preview1", ] +[[package]] +name = "ghash" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" +dependencies = [ + "opaque-debug", + "polyval", +] + [[package]] name = "glow" version = "0.11.0" @@ -1948,9 +1996,9 @@ dependencies = [ [[package]] name = "jsonc-parser" -version = "0.17.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cb8a8eb6349c33f5ff1c6f12d09936f048c039411c9a08cd54a378fbf1905e2" +checksum = "2ceb55b30bfc8869d48b43a7f117380bae1dc5e97484b46ecccf77fdc1ec057f" dependencies = [ "serde_json", ] @@ -2677,6 +2725,18 @@ dependencies = [ "syn 1.0.65", ] +[[package]] +name = "polyval" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "opaque-debug", + "universal-hash", +] + [[package]] name = "ppv-lite86" version = "0.2.15" @@ -2767,9 +2827,9 @@ dependencies = [ [[package]] name = "pulldown-cmark" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +checksum = "acd16514d1af5f7a71f909a44ef253cdb712a376d7ebc8ae4a471a9be9743548" dependencies = [ "bitflags", "memchr", @@ -3293,9 +3353,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" dependencies = [ "serde_derive", ] @@ -3311,9 +3371,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" dependencies = [ "proc-macro2 1.0.33", "quote 1.0.10", @@ -3357,7 +3417,7 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.23.0" +version = "0.24.0" dependencies = [ "bencher", "serde", @@ -3593,9 +3653,9 @@ dependencies = [ [[package]] name = "swc_bundler" -version = "0.89.0" +version = "0.96.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7266b804885475a9f2d829946747d72b4806e23be690a44c8b6f7819453fd0bc" +checksum = "e4df8e45a1d523403a5f256fca9ab216bcccbd5883b7aba6f8b5a5c1e69bcd31" dependencies = [ "ahash", "anyhow", @@ -3625,13 +3685,14 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560998b621793a613c98ec8cdbd729e46332dd3fbf7619b57e9d98c15e142e2e" +checksum = "757c84b893b4b16bbbe983acc8262f52fe5efd9b87b362f4196549e4f798c0a0" dependencies = [ "ahash", "ast_node", "cfg-if 0.1.10", + "debug_unreachable", "either", "from_variant", "num-bigint", @@ -3651,9 +3712,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.59.1" +version = "0.62.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49c93361aba26b56682cfa53709939b1511a09289dbed7753ace5f300b52d3b5" +checksum = "d00427977875928f37e92e260f226a91783812aaf3713562526a920befd6aa39" dependencies = [ "is-macro", "num-bigint", @@ -3661,13 +3722,14 @@ dependencies = [ "string_enum", "swc_atoms", "swc_common", + "unicode-xid 0.2.2", ] [[package]] name = "swc_ecma_codegen" -version = "0.83.1" +version = "0.86.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7af562472cb19a0a13912ee21aec49a8a8c19092994e2a5ee84f93f5fd762caa" +checksum = "025d9bb2d836fac57bf5579f7049ff96e702632c0affb362234b26d587f996d1" dependencies = [ "bitflags", "memchr", @@ -3697,9 +3759,9 @@ dependencies = [ [[package]] name = "swc_ecma_dep_graph" -version = "0.50.1" +version = "0.55.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f07f7c6513e4eb53f92d116c1aaeff9e6b7eba969635d8b61af4da35f1f2cacf" +checksum = "a3368bafec3d3dd3f19e2108551b9d6dd1362c515cd138a652aff9f911409316" dependencies = [ "swc_atoms", "swc_common", @@ -3709,23 +3771,22 @@ dependencies = [ [[package]] name = "swc_ecma_loader" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c9672f7cf71bf2a98fc0c66eed90d43db9252c82e52096c7159ea5521f3478" +checksum = "61e4a236d9fc809d88e8d346381e72936dc8a4e4a2418d1f66ea8acb6ed298be" dependencies = [ "ahash", "anyhow", "serde", - "swc_atoms", "swc_common", "tracing", ] [[package]] name = "swc_ecma_parser" -version = "0.81.0" +version = "0.84.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97570156b3eec2e91b43f3adf9526caaf5cdf656c65a7722715b3537c2952261" +checksum = "55406a1e109a7c4ad281ee4fe295249553b7fcbfa43b27f7b53d6112b2924af4" dependencies = [ "either", "enum_kind", @@ -3736,7 +3797,6 @@ dependencies = [ "swc_atoms", "swc_common", "swc_ecma_ast", - "swc_ecma_visit", "tracing", "typed-arena", "unicode-xid 0.2.2", @@ -3744,9 +3804,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms" -version = "0.101.0" +version = "0.106.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15931263dab79ddee709e981b5222d84a684cfaa66d2913394bee6d5b4635cca" +checksum = "e7f2517337858bcbb43be51ff34033f80ca0379e0838e6cbdcdb62e88d56b9ec" dependencies = [ "swc_atoms", "swc_common", @@ -3763,9 +3823,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.48.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12032e1af75c83a4c40c4784b4ae46c56b74326609aca7104e30ababfe9a7f28" +checksum = "06384503de52f097bbaa41fbe488510041906a69b3f01449ef024384eeb7fabf" dependencies = [ "once_cell", "phf", @@ -3782,9 +3842,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.34.0" +version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7305d99e9851ae762e8bca1f7d43a0a1dd6c55b78220b10425b06a5f54c4498f" +checksum = "19ad7eb4fb019fc608ccff8a2ceffb7548ec94018cc2f523367b137b90b1d6a6" dependencies = [ "swc_atoms", "swc_common", @@ -3809,15 +3869,14 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.71.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d528d813fd0af0c8727b0143b0c60759ff6a1cefb7223ee955da85c90edaaa6" +checksum = "eb91bd9aea0f0dd57688340306203ec776ed2fd1e2b75871b7135566c5a4e82a" dependencies = [ "ahash", "dashmap", "indexmap", "once_cell", - "retain_mut", "serde_json", "swc_atoms", "swc_common", @@ -3832,9 +3891,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.63.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1185431bc8fb9d5460f662effbe4eaa10f1038f4e7fc7cfb2edfef4a7cc1104e" +checksum = "e6520f06130f57292dfd986c0484034f37f6a129699a139010a818e4cd164975" dependencies = [ "either", "serde", @@ -3852,9 +3911,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.65.1" +version = "0.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99f7d18dca4fbdc563244658bcea15b8151cd37ae7462588bf4b15eada4e5688" +checksum = "3ef966c28b0f13412c546ebd777e61b197b2ef8c9214bee8393f25d0027adfef" dependencies = [ "ahash", "base64 0.13.0", @@ -3877,9 +3936,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "0.67.2" +version = "0.72.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aff4b2e2bf68f042313dcb56c61b66410cb8232692e1ab0e789472ad6b32aa85" +checksum = "5ca12da83a3ce8fa61defa77256f11bf63048830d45b2e3a67fb7208d5dfa8b5" dependencies = [ "serde", "swc_atoms", @@ -3894,9 +3953,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.55.1" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba7fd9af7d4d4e972dd92f47c36094bbf6e345dc15d5e1260201156e74e21cb2" +checksum = "4684e029d1c06cd3ee86e83a3cffb7a90acb421b58204ed72c8e3719bc88eca5" dependencies = [ "once_cell", "swc_atoms", @@ -3904,14 +3963,13 @@ dependencies = [ "swc_ecma_ast", "swc_ecma_visit", "tracing", - "unicode-xid 0.2.2", ] [[package]] name = "swc_ecma_visit" -version = "0.45.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3826abd1e68214fe9743437236608a0a22d27912e84a85a53f1e977e10468" +checksum = "3185cd9fa4460935d9a9f1efc5eed1efc5b57a58d471313b88bee1ecfdeff268" dependencies = [ "num-bigint", "swc_atoms", @@ -3923,9 +3981,9 @@ dependencies = [ [[package]] name = "swc_ecmascript" -version = "0.95.0" +version = "0.103.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "703291bc32dd81c1d73761e02442bdefed5844490f853f9979b8b8cb21e7392b" +checksum = "ff3180fe209baa9f0fa4a693b2c569f40b010ee3e8155c72435b3b79fc0686e3" dependencies = [ "swc_ecma_ast", "swc_ecma_codegen", @@ -3950,9 +4008,9 @@ dependencies = [ [[package]] name = "swc_fast_graph" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4e08c814c7283238c72c61069614b55d58ccfeeb5e4fd9887913e9d34102632" +checksum = "4857942a9c79e9836f51dca4ca0df89f354acfedc573708006c4365bad07083c" dependencies = [ "ahash", "indexmap", @@ -3962,9 +4020,9 @@ dependencies = [ [[package]] name = "swc_graph_analyzer" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13707fe5ba172950c56e16ab206f4d2a7da4e16742e7f527c331c1e0973267d4" +checksum = "3c5f079d9350dee80a59ac2f8be9867ed0a8ac9fb0023461b173e9e42168ff30" dependencies = [ "ahash", "auto_impl", @@ -4547,6 +4605,25 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "universal-hash" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "unreachable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91" +dependencies = [ + "void", +] + [[package]] name = "untrusted" version = "0.7.1" @@ -4632,6 +4709,12 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + [[package]] name = "walkdir" version = "2.3.2" diff --git a/Cargo.toml b/Cargo.toml index f9481ce2f54012..e8ee6b8ed50f6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,4 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [workspace] resolver = "2" diff --git a/LICENSE.md b/LICENSE.md index bbf190721dbda3..cfc3a5226e2140 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright 2018-2021 the Deno authors +Copyright 2018-2022 the Deno authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/Releases.md b/Releases.md index cd14b479c6b199..379e391a404e83 100644 --- a/Releases.md +++ b/Releases.md @@ -6,6 +6,27 @@ https://github.com/denoland/deno/releases We also have one-line install commands at: https://github.com/denoland/deno_install +### 1.17.2 / 2022.01.05 + +- fix(cli): include JSON modules in bundle (#13188) +- fix(core): inspector works if no "Runtime.runIfWaitingForDebugger" message is + sent (#13191) +- fix(coverage): use only string byte indexes and 0-indexed line numbers + (#13190) +- fix(doc): Make private types which show up in the rustdocs public (#13230) +- fix(ext/console): map basic css color keywords to ansi (#13175) +- fix(ext/crypto) - exportKey JWK for AES/HMAC must use base64url (#13264) +- fix(ext/crypto) include AES-CTR for deriveKey (#13174) +- fix(ext/crypto): use forgiving base64 encoding for JWK (#13240) +- fix(ext/ffi): throw errors instead of panic (#13283) +- fix(lsp): add code lens for tests just using named functions (#13218) +- fix(lsp): better handling of folders in registry completions (#13250) +- fix(lsp): handle repeating patterns in registry correctly (#13275) +- fix(lsp): properly generate data URLs for completion items (#13246) +- fix(signals): prevent panic when listening to forbidden signals (#13273) +- fix: support `mts`, `cjs` & `cts` files for `deno test` & `deno fmt` (#13274) +- fix: upgrade swc_ecmascript to 0.103 (#13284) + ### 1.17.1 / 2021.12.22 - feat(lsp, unstable): add code lens for debugging tests (#13138) diff --git a/bench_util/Cargo.toml b/bench_util/Cargo.toml index 6b75731278ccc6..7b2d24f71ac84a 100644 --- a/bench_util/Cargo.toml +++ b/bench_util/Cargo.toml @@ -1,7 +1,7 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_bench_util" -version = "0.24.0" +version = "0.25.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,7 +14,7 @@ description = "Bench and profiling utilities for deno crates" [dependencies] bencher = "0.1" -deno_core = { version = "0.112.0", path = "../core" } +deno_core = { version = "0.113.0", path = "../core" } tokio = { version = "1.10.1", features = ["full"] } [[bench]] diff --git a/bench_util/src/js_runtime.rs b/bench_util/src/js_runtime.rs index 3643c805f43860..3caf4073be8854 100644 --- a/bench_util/src/js_runtime.rs +++ b/bench_util/src/js_runtime.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use bencher::Bencher; use deno_core::v8; use deno_core::Extension; diff --git a/bench_util/src/lib.rs b/bench_util/src/lib.rs index 943474c47b3d92..1dfb06ae09cb45 100644 --- a/bench_util/src/lib.rs +++ b/bench_util/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. mod js_runtime; mod profiling; diff --git a/bench_util/src/profiling.rs b/bench_util/src/profiling.rs index b4459ad60a2e03..26d8d8fd6f96da 100644 --- a/bench_util/src/profiling.rs +++ b/bench_util/src/profiling.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use bencher::{DynBenchFn, StaticBenchFn, TestDescAndFn, TestOpts}; pub fn is_profiling() -> bool { diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c02735a0f40ce5..15a82b5eb3e595 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno" -version = "1.17.1" +version = "1.17.2" authors = ["the Deno authors"] default-run = "deno" edition = "2021" @@ -20,31 +20,31 @@ harness = false path = "./bench/main.rs" [build-dependencies] -deno_broadcast_channel = { version = "0.24.0", path = "../ext/broadcast_channel" } -deno_console = { version = "0.30.0", path = "../ext/console" } -deno_core = { version = "0.112.0", path = "../core" } -deno_crypto = { version = "0.44.0", path = "../ext/crypto" } -deno_fetch = { version = "0.53.0", path = "../ext/fetch" } -deno_net = { version = "0.22.0", path = "../ext/net" } -deno_url = { version = "0.30.0", path = "../ext/url" } -deno_web = { version = "0.61.0", path = "../ext/web" } -deno_webgpu = { version = "0.31.0", path = "../ext/webgpu" } -deno_websocket = { version = "0.35.0", path = "../ext/websocket" } -deno_webstorage = { version = "0.25.0", path = "../ext/webstorage" } +deno_broadcast_channel = { version = "0.25.0", path = "../ext/broadcast_channel" } +deno_console = { version = "0.31.0", path = "../ext/console" } +deno_core = { version = "0.113.0", path = "../core" } +deno_crypto = { version = "0.45.0", path = "../ext/crypto" } +deno_fetch = { version = "0.54.0", path = "../ext/fetch" } +deno_net = { version = "0.23.0", path = "../ext/net" } +deno_url = { version = "0.31.0", path = "../ext/url" } +deno_web = { version = "0.62.0", path = "../ext/web" } +deno_webgpu = { version = "0.32.0", path = "../ext/webgpu" } +deno_websocket = { version = "0.36.0", path = "../ext/websocket" } +deno_webstorage = { version = "0.26.0", path = "../ext/webstorage" } regex = "=1.5.4" -serde = { version = "=1.0.130", features = ["derive"] } +serde = { version = "=1.0.133", features = ["derive"] } [target.'cfg(windows)'.build-dependencies] winapi = "=0.3.9" winres = "=0.1.11" [dependencies] -deno_ast = { version = "0.7.0", features = ["bundler", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] } -deno_core = { version = "0.112.0", path = "../core" } -deno_doc = "0.24.0" -deno_graph = "0.16.0" -deno_lint = { version = "0.20.0", features = ["docs"] } -deno_runtime = { version = "0.38.0", path = "../runtime" } +deno_ast = { version = "0.8.0", features = ["bundler", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] } +deno_core = { version = "0.113.0", path = "../core" } +deno_doc = "0.25.0" +deno_graph = "0.17.0" +deno_lint = { version = "0.21.0", features = ["docs"] } +deno_runtime = { version = "0.39.0", path = "../runtime" } atty = "=0.2.14" base64 = "=0.13.0" @@ -53,15 +53,15 @@ chrono = "=0.4.19" clap = "=2.33.3" data-url = "=0.1.1" dissimilar = "=1.0.2" -dprint-plugin-json = "=0.13.2" -dprint-plugin-markdown = "=0.11.3" -dprint-plugin-typescript = "=0.60.0" +dprint-plugin-json = "=0.14.0" +dprint-plugin-markdown = "=0.12.0" +dprint-plugin-typescript = "=0.61.0" encoding_rs = "=0.8.29" env_logger = "=0.8.4" fancy-regex = "=0.7.1" http = "=0.2.4" import_map = "=0.4.0" -jsonc-parser = { version = "=0.17.0", features = ["serde"] } +jsonc-parser = { version = "=0.17.1", features = ["serde"] } libc = "=0.2.106" log = { version = "=0.4.14", features = ["serde"] } lspower = "=1.4.0" @@ -76,7 +76,7 @@ ring = "=0.16.20" rustyline = { version = "=9.0.0", default-features = false } rustyline-derive = "=0.5.0" semver-parser = "=0.10.2" -serde = { version = "=1.0.130", features = ["derive"] } +serde = { version = "=1.0.133", features = ["derive"] } shell-escape = "=0.1.5" sourcemap = "=6.0.1" tempfile = "=3.2.0" diff --git a/cli/ast/bundle_hook.rs b/cli/ast/bundle_hook.rs index 3f47946f7a3bec..a2dd658e3453a1 100644 --- a/cli/ast/bundle_hook.rs +++ b/cli/ast/bundle_hook.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_ast::swc::bundler::Hook; use deno_ast::swc::bundler::ModuleRecord; use deno_ast::swc::common::Span; diff --git a/cli/ast/mod.rs b/cli/ast/mod.rs index 80cbd5c4bb69d8..419471daa42336 100644 --- a/cli/ast/mod.rs +++ b/cli/ast/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::config_file; use crate::text_encoding::strip_bom; @@ -602,8 +602,7 @@ mod tests { #[test] fn test_transpile() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.ts") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.ts").unwrap(); let source = r#" enum D { A, @@ -637,24 +636,21 @@ export class A { scope_analysis: false, }) .unwrap(); - let (code, maybe_map) = transpile(&module, &EmitOptions::default()) - .expect("could not strip types"); + let (code, maybe_map) = + transpile(&module, &EmitOptions::default()).unwrap(); let expected_text = r#"var D; (function(D) { D[D["A"] = 0] = "A"; D[D["B"] = 1] = "B"; -})(D || (D = { -})); +})(D || (D = {})); var N; (function(N1) { let D; (function(D) { D["A"] = "value"; - })(D = N1.D || (N1.D = { - })); - N1.Value = 5; -})(N || (N = { -})); + })(D = N1.D || (N1.D = {})); + var Value = N1.Value = 5; +})(N || (N = {})); export class A { d; b; @@ -677,8 +673,7 @@ export class A { #[test] fn test_transpile_tsx() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.ts") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.ts").unwrap(); let source = r#" export class A { render() { @@ -694,16 +689,14 @@ export class A { maybe_syntax: None, scope_analysis: true, // ensure scope analysis doesn't conflict with a second resolver pass }) - .expect("could not parse module"); - let (code, _) = transpile(&module, &EmitOptions::default()) - .expect("could not strip types"); + .unwrap(); + let (code, _) = transpile(&module, &EmitOptions::default()).unwrap(); assert!(code.contains("React.createElement(\"div\", null")); } #[test] fn test_transpile_jsx_pragma() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.ts") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.ts").unwrap(); let source = r#" /** @jsx h */ /** @jsxFrag Fragment */ @@ -733,8 +726,7 @@ function App() { #[test] fn test_transpile_jsx_import_source_pragma() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx").unwrap(); let source = r#" /** @jsxImportSource jsx_lib */ @@ -756,8 +748,7 @@ function App() { let expected = r#"import { jsx as _jsx, Fragment as _Fragment } from "jsx_lib/jsx-runtime"; /** @jsxImportSource jsx_lib */ function App() { return(/*#__PURE__*/ _jsx("div", { - children: /*#__PURE__*/ _jsx(_Fragment, { - }) + children: /*#__PURE__*/ _jsx(_Fragment, {}) })); "#; assert_eq!(&code[..expected.len()], expected); @@ -765,8 +756,7 @@ function App() { #[test] fn test_transpile_jsx_import_source_no_pragma() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx").unwrap(); let source = r#" function App() { return ( @@ -791,8 +781,7 @@ function App() { let expected = r#"import { jsx as _jsx, Fragment as _Fragment } from "jsx_lib/jsx-runtime"; function App() { return(/*#__PURE__*/ _jsx("div", { - children: /*#__PURE__*/ _jsx(_Fragment, { - }) + children: /*#__PURE__*/ _jsx(_Fragment, {}) })); } "#; @@ -802,8 +791,7 @@ function App() { // TODO(@kitsonk) https://github.com/swc-project/swc/issues/2656 // #[test] // fn test_transpile_jsx_import_source_no_pragma_dev() { - // let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx") - // .expect("could not resolve specifier"); + // let specifier = resolve_url_or_path("https://deno.land/x/mod.tsx").unwrap(); // let source = r#" // function App() { // return ( @@ -839,8 +827,7 @@ function App() { #[test] fn test_transpile_decorators() { - let specifier = resolve_url_or_path("https://deno.land/x/mod.ts") - .expect("could not resolve specifier"); + let specifier = resolve_url_or_path("https://deno.land/x/mod.ts").unwrap(); let source = r#" function enumerable(value: boolean) { return function ( @@ -867,9 +854,8 @@ function App() { maybe_syntax: None, scope_analysis: false, }) - .expect("could not parse module"); - let (code, _) = transpile(&module, &EmitOptions::default()) - .expect("could not strip types"); + .unwrap(); + let (code, _) = transpile(&module, &EmitOptions::default()).unwrap(); assert!(code.contains("_applyDecoratedDescriptor(")); } @@ -903,8 +889,7 @@ export function g() { let (code, _) = transpile(&module, &emit_options).unwrap(); let expected = r#"export function g() { let algorithm; - algorithm = { - }; + algorithm = {}; return test(algorithm, false, keyUsages); }"#; assert_eq!(&code[..expected.len()], expected); diff --git a/cli/ast/transforms.rs b/cli/ast/transforms.rs index ba8af59aff7898..a89edc01d385eb 100644 --- a/cli/ast/transforms.rs +++ b/cli/ast/transforms.rs @@ -50,7 +50,10 @@ impl Fold for DownlevelImportsFolder { ImportSpecifier::Named(specifier) => { Some(match specifier.imported.as_ref() { Some(name) => create_key_value( - name.sym.to_string(), + match name { + ModuleExportName::Ident(ident) => ident.sym.to_string(), + ModuleExportName::Str(str) => str.value.to_string(), + }, specifier.local.sym.to_string(), ), None => create_assignment(specifier.local.sym.to_string()), @@ -200,10 +203,12 @@ fn create_ident(name: String) -> swc_ast::Ident { fn create_key_value(key: String, value: String) -> swc_ast::ObjectPatProp { swc_ast::ObjectPatProp::KeyValue(swc_ast::KeyValuePatProp { - key: swc_ast::PropName::Ident(swc_ast::Ident { + // use a string literal because it will work in more scenarios than an identifier + key: swc_ast::PropName::Str(swc_ast::Str { span: DUMMY_SP, - sym: key.into(), - optional: false, + value: key.into(), + has_escape: false, + kind: swc_ast::StrKind::Synthesized, }), value: Box::new(swc_ast::Pat::Ident(swc_ast::BindingIdent { id: swc_ast::Ident { @@ -320,7 +325,7 @@ mod test { test_transform( DownlevelImportsFolder, r#"import mod from "./mod.ts";"#, - r#"const { default: mod } = await import("./mod.ts");"#, + r#"const { "default": mod } = await import("./mod.ts");"#, ); } @@ -341,7 +346,7 @@ mod test { test_transform( DownlevelImportsFolder, r#"import { A as LocalA, B, C as LocalC } from "./mod.ts";"#, - r#"const { A: LocalA , B , C: LocalC } = await import("./mod.ts");"#, + r#"const { "A": LocalA , B , "C": LocalC } = await import("./mod.ts");"#, ); } @@ -359,13 +364,13 @@ mod test { test_transform( DownlevelImportsFolder, r#"import myDefault, { A, B as LocalB } from "./mod.ts";"#, - r#"const { default: myDefault , A , B: LocalB } = await import("./mod.ts");"#, + r#"const { "default": myDefault , A , "B": LocalB } = await import("./mod.ts");"#, ); test_transform( DownlevelImportsFolder, r#"import myDefault, * as mod from "./mod.ts";"#, - r#"const { default: myDefault } = await import("./mod.ts"), mod = await import("./mod.ts");"#, + r#"const { "default": myDefault } = await import("./mod.ts"), mod = await import("./mod.ts");"#, ); } @@ -374,7 +379,7 @@ mod test { test_transform( DownlevelImportsFolder, r#"import data from "./mod.json" assert { type: "json" };"#, - "const { default: data } = await import(\"./mod.json\", {\n assert: {\n type: \"json\"\n }\n});", + "const { \"default\": data } = await import(\"./mod.json\", {\n assert: {\n type: \"json\"\n }\n});", ); } @@ -433,7 +438,7 @@ mod test { test_transform( StripExportsFolder, "export default function test() {}", - "function test() {\n}", + "function test() {}", ); } @@ -455,7 +460,7 @@ mod test { test_transform( StripExportsFolder, "export function test() {}", - "function test() {\n}", + "function test() {}", ); test_transform(StripExportsFolder, "export enum Test {}", "enum Test {\n}"); diff --git a/cli/auth_tokens.rs b/cli/auth_tokens.rs index c81c296f370eb5..4afd87e5946ea8 100644 --- a/cli/auth_tokens.rs +++ b/cli/auth_tokens.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::ModuleSpecifier; use log::debug; diff --git a/cli/bench/deno_common.js b/cli/bench/deno_common.js index 73a2f62c5f0c80..2d8fa8793fdf9a 100644 --- a/cli/bench/deno_common.js +++ b/cli/bench/deno_common.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Run with: deno run -A ./cli/bench/deno_common.js function benchSync(name, n, innerLoop) { const t1 = Date.now(); diff --git a/cli/bench/deno_http_native.js b/cli/bench/deno_http_native.js index abb2d061f6d06f..a45416adaa1120 100644 --- a/cli/bench/deno_http_native.js +++ b/cli/bench/deno_http_native.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. const addr = Deno.args[0] || "127.0.0.1:4500"; const [hostname, port] = addr.split(":"); diff --git a/cli/bench/http.rs b/cli/bench/http.rs index 9394f381b29810..72edb487c624f8 100644 --- a/cli/bench/http.rs +++ b/cli/bench/http.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::Result; use std::{collections::HashMap, path::Path, process::Command, time::Duration}; diff --git a/cli/bench/lsp.rs b/cli/bench/lsp.rs index 3ec914d9e76268..c84b5c9a68d35e 100644 --- a/cli/bench/lsp.rs +++ b/cli/bench/lsp.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::serde::Deserialize; diff --git a/cli/bench/main.rs b/cli/bench/main.rs index e17ed40686aeeb..9571be72ab7bae 100644 --- a/cli/bench/main.rs +++ b/cli/bench/main.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::serde_json; diff --git a/cli/bench/node_http.js b/cli/bench/node_http.js index 07a16db07b8b47..3380c86a52c16b 100644 --- a/cli/bench/node_http.js +++ b/cli/bench/node_http.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. const http = require("http"); const port = process.argv[2] || "4544"; console.log("port", port); diff --git a/cli/bench/node_tcp.js b/cli/bench/node_tcp.js index f1211f827f9c4d..cb51a63a5df437 100644 --- a/cli/bench/node_tcp.js +++ b/cli/bench/node_tcp.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Note: this is a keep-alive server. const { Server } = require("net"); const port = process.argv[2] || "4544"; diff --git a/cli/bench/node_tcp_proxy.js b/cli/bench/node_tcp_proxy.js index 9f91679f88bc2f..8b4b958d7a4367 100644 --- a/cli/bench/node_tcp_proxy.js +++ b/cli/bench/node_tcp_proxy.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. const net = require("net"); process.on("uncaughtException", function (error) { diff --git a/cli/build.rs b/cli/build.rs index 327b75f0a3a279..48c55e628d6c31 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::custom_error; use deno_core::op_sync; diff --git a/cli/cache.rs b/cli/cache.rs index c5fd0a8a0f5d64..218c699a133432 100644 --- a/cli/cache.rs +++ b/cli/cache.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::disk_cache::DiskCache; use crate::errors::get_error_class_name; diff --git a/cli/checksum.rs b/cli/checksum.rs index 77b255c2d0dce1..c0e41356de9fe9 100644 --- a/cli/checksum.rs +++ b/cli/checksum.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use ring::digest::Context; use ring::digest::SHA256; diff --git a/cli/compat/errors.rs b/cli/compat/errors.rs index e9cc31a0db1a2d..fa9846ed639c22 100644 --- a/cli/compat/errors.rs +++ b/cli/compat/errors.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::generic_error; use deno_core::error::type_error; diff --git a/cli/compat/esm_resolver.rs b/cli/compat/esm_resolver.rs index d2fdeaae059fc0..029521f4662d6c 100644 --- a/cli/compat/esm_resolver.rs +++ b/cli/compat/esm_resolver.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::errors; use crate::resolver::ImportMapResolver; @@ -1193,7 +1193,7 @@ mod tests { let cwd = testdir("basic"); let main = Url::from_file_path(cwd.join("main.js")).unwrap(); let expected = - Url::parse("https://deno.land/std@0.119.0/node/http.ts").unwrap(); + Url::parse("https://deno.land/std@0.120.0/node/http.ts").unwrap(); let actual = node_resolve("http", main.as_str(), &cwd).unwrap(); println!("actual {}", actual); diff --git a/cli/compat/mod.rs b/cli/compat/mod.rs index 401e1ab40259a8..989113ad3cf9c1 100644 --- a/cli/compat/mod.rs +++ b/cli/compat/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. mod errors; mod esm_resolver; @@ -16,7 +16,7 @@ pub(crate) use esm_resolver::NodeEsmResolver; // each release, a better mechanism is preferable, but it's a quick and dirty // solution to avoid printing `X-Deno-Warning` headers when the compat layer is // downloaded -static STD_URL_STR: &str = "https://deno.land/std@0.119.0/"; +static STD_URL_STR: &str = "https://deno.land/std@0.120.0/"; static SUPPORTED_MODULES: &[&str] = &[ "assert", diff --git a/cli/config_file.rs b/cli/config_file.rs index a254d074dd78ff..f18e56fc1b8e6f 100644 --- a/cli/config_file.rs +++ b/cli/config_file.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::fs_util::canonicalize_path; use crate::fs_util::specifier_parent; diff --git a/cli/deno_dir.rs b/cli/deno_dir.rs index b9bb5893451651..674d32c5103438 100644 --- a/cli/deno_dir.rs +++ b/cli/deno_dir.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::disk_cache::DiskCache; use std::path::PathBuf; diff --git a/cli/diagnostics.rs b/cli/diagnostics.rs index 03255950b35c80..ff2b5dbb8169f3 100644 --- a/cli/diagnostics.rs +++ b/cli/diagnostics.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_runtime::colors; diff --git a/cli/diff.rs b/cli/diff.rs index 8285139b5e051a..f5596bef53149e 100644 --- a/cli/diff.rs +++ b/cli/diff.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::colors; use dissimilar::{diff as difference, Chunk}; diff --git a/cli/disk_cache.rs b/cli/disk_cache.rs index 6a5fd6ec8fcfc6..d3d294c18b1778 100644 --- a/cli/disk_cache.rs +++ b/cli/disk_cache.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::fs_util; use crate::http_cache::url_to_filename; diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 914c63b246c53a..e23f44d9acc817 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -870,7 +870,7 @@ declare namespace Deno { * * Returns the number of bytes written. This function is one of the lowest * level APIs and most users should not work with this directly, but rather use - * Deno.writeAllSync() instead. + * `writeAllSync()` from https://deno.land/std/streams/conversion.ts instead. * * **It is not guaranteed that the full buffer will be written in a single * call.** @@ -2745,6 +2745,14 @@ declare namespace Deno { export interface UpgradeWebSocketOptions { protocol?: string; + /** + * If the client does not respond to this frame with a + * `pong` within the timeout specified, the connection is deemed + * unhealthy and is closed. The `close` and `error` event will be emitted. + * + * The default is 120 seconds. Set to 0 to disable timeouts. + */ + idleTimeout?: number; } /** diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index d9f03fe527570b..dd0040bbbee22f 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -1174,6 +1174,7 @@ declare interface WorkerOptions { declare interface WebSocketStreamOptions { protocols?: string[]; signal?: AbortSignal; + headers?: HeadersInit; } declare interface WebSocketConnection { diff --git a/cli/emit.rs b/cli/emit.rs index b7d2b7d84b0fb6..50d4eb821d3e83 100644 --- a/cli/emit.rs +++ b/cli/emit.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! The collection of APIs to be able to take `deno_graph` module graphs and //! populate a cache, emit files, and transform a graph into the structures for diff --git a/cli/errors.rs b/cli/errors.rs index 9d0f1371ae5035..1cef35399ebc5d 100644 --- a/cli/errors.rs +++ b/cli/errors.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! There are many types of errors in Deno: //! - AnyError: a generic wrapper that can encapsulate any type of error. diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 29e4f41febed6e..1c3b093ff9a1b8 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::auth_tokens::AuthTokens; use crate::colors; diff --git a/cli/file_watcher.rs b/cli/file_watcher.rs index b2d2ee15a320c3..3b245e08f9d565 100644 --- a/cli/file_watcher.rs +++ b/cli/file_watcher.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::colors; use crate::fs_util::canonicalize_path; diff --git a/cli/flags.rs b/cli/flags.rs index 2cf79d44fbc4bb..bdd97eea491541 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use clap::App; use clap::AppSettings; @@ -214,6 +214,7 @@ pub struct Flags { pub argv: Vec, pub subcommand: DenoSubcommand, + pub allow_all: bool, pub allow_env: Option>, pub allow_hrtime: bool, pub allow_net: Option>, @@ -269,6 +270,11 @@ impl Flags { pub fn to_permission_args(&self) -> Vec { let mut args = vec![]; + if self.allow_all { + args.push("--allow-all".to_string()); + return args; + } + match &self.allow_read { Some(read_allowlist) if read_allowlist.is_empty() => { args.push("--allow-read".to_string()); @@ -2252,6 +2258,7 @@ fn permission_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) { flags.allow_hrtime = true; } if matches.is_present("allow-all") { + flags.allow_all = true; flags.allow_read = Some(vec![]); flags.allow_env = Some(vec![]); flags.allow_net = Some(vec![]); @@ -2647,6 +2654,7 @@ mod tests { subcommand: DenoSubcommand::Run(RunFlags { script: "gist.ts".to_string(), }), + allow_all: true, allow_net: Some(vec![]), allow_env: Some(vec![]), allow_run: Some(vec![]), diff --git a/cli/flags_allow_net.rs b/cli/flags_allow_net.rs index 801258e4995a29..d947666849d52e 100644 --- a/cli/flags_allow_net.rs +++ b/cli/flags_allow_net.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::url::Url; use std::net::IpAddr; diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs index b4e45502696c0a..1266212793afb8 100644 --- a/cli/fmt_errors.rs +++ b/cli/fmt_errors.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! This mod provides DenoError to unify errors across Deno. use crate::colors::cyan; use crate::colors::italic_bold; diff --git a/cli/fs_util.rs b/cli/fs_util.rs index 20b20cccdbbbca..06bdb689a6e472 100644 --- a/cli/fs_util.rs +++ b/cli/fs_util.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::anyhow::Context; use deno_core::error::{uri_error, AnyError}; @@ -130,7 +130,10 @@ pub fn resolve_from_cwd(path: &Path) -> Result { /// Checks if the path has extension Deno supports. pub fn is_supported_ext(path: &Path) -> bool { if let Some(ext) = get_extension(path) { - matches!(ext.as_str(), "ts" | "tsx" | "js" | "jsx" | "mjs") + matches!( + ext.as_str(), + "ts" | "tsx" | "js" | "jsx" | "mjs" | "mts" | "cjs" | "cts" + ) } else { false } @@ -147,6 +150,9 @@ pub fn is_supported_ext_fmt(path: &Path) -> bool { | "js" | "jsx" | "mjs" + | "mts" + | "cjs" + | "cts" | "json" | "jsonc" | "md" @@ -163,26 +169,12 @@ pub fn is_supported_ext_fmt(path: &Path) -> bool { /// Checks if the path has a basename and extension Deno supports for tests. pub fn is_supported_test_path(path: &Path) -> bool { - use std::path::Component; - if let Some(Component::Normal(basename_os_str)) = - path.components().next_back() - { - let basename = basename_os_str.to_string_lossy(); - basename.ends_with("_test.ts") - || basename.ends_with("_test.tsx") - || basename.ends_with("_test.js") - || basename.ends_with("_test.mjs") - || basename.ends_with("_test.jsx") - || basename.ends_with(".test.ts") - || basename.ends_with(".test.tsx") - || basename.ends_with(".test.js") - || basename.ends_with(".test.mjs") - || basename.ends_with(".test.jsx") - || basename == "test.ts" - || basename == "test.tsx" - || basename == "test.js" - || basename == "test.mjs" - || basename == "test.jsx" + if let Some(name) = path.file_stem() { + let basename = name.to_string_lossy(); + (basename.ends_with("_test") + || basename.ends_with(".test") + || basename == "test") + && is_supported_ext(path) } else { false } @@ -198,6 +190,9 @@ pub fn is_supported_test_ext(path: &Path) -> bool { | "js" | "jsx" | "mjs" + | "mts" + | "cjs" + | "cts" | "md" | "mkd" | "mkdn" @@ -443,6 +438,9 @@ mod tests { assert!(is_supported_ext(Path::new("foo.JS"))); assert!(is_supported_ext(Path::new("foo.JSX"))); assert!(is_supported_ext(Path::new("foo.mjs"))); + assert!(is_supported_ext(Path::new("foo.mts"))); + assert!(is_supported_ext(Path::new("foo.cjs"))); + assert!(is_supported_ext(Path::new("foo.cts"))); assert!(!is_supported_ext(Path::new("foo.mjsx"))); } @@ -466,6 +464,9 @@ mod tests { assert!(is_supported_ext_fmt(Path::new("foo.JS"))); assert!(is_supported_ext_fmt(Path::new("foo.JSX"))); assert!(is_supported_ext_fmt(Path::new("foo.mjs"))); + assert!(is_supported_ext_fmt(Path::new("foo.mts"))); + assert!(is_supported_ext_fmt(Path::new("foo.cjs"))); + assert!(is_supported_ext_fmt(Path::new("foo.cts"))); assert!(!is_supported_ext_fmt(Path::new("foo.mjsx"))); assert!(is_supported_ext_fmt(Path::new("foo.jsonc"))); assert!(is_supported_ext_fmt(Path::new("foo.JSONC"))); @@ -493,6 +494,9 @@ mod tests { assert!(is_supported_test_ext(Path::new("foo.JS"))); assert!(is_supported_test_ext(Path::new("foo.JSX"))); assert!(is_supported_test_ext(Path::new("foo.mjs"))); + assert!(is_supported_test_ext(Path::new("foo.mts"))); + assert!(is_supported_test_ext(Path::new("foo.cjs"))); + assert!(is_supported_test_ext(Path::new("foo.cts"))); assert!(!is_supported_test_ext(Path::new("foo.mjsx"))); assert!(!is_supported_test_ext(Path::new("foo.jsonc"))); assert!(!is_supported_test_ext(Path::new("foo.JSONC"))); diff --git a/cli/graph_util.rs b/cli/graph_util.rs index fc1b742b8d63ca..d186a1ab117481 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::colors; use crate::emit::TypeLib; diff --git a/cli/http_cache.rs b/cli/http_cache.rs index 8a1995acefc31e..ba70512d8751c4 100644 --- a/cli/http_cache.rs +++ b/cli/http_cache.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! This module is meant to eventually implement HTTP cache //! as defined in RFC 7234 (). //! Currently it's a very simplified version to fulfill Deno needs diff --git a/cli/http_util.rs b/cli/http_util.rs index 78a22d3e5bd48c..3f11e88593dee2 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::auth_tokens::AuthToken; use cache_control::Cachability; diff --git a/cli/lockfile.rs b/cli/lockfile.rs index 5df3b1213c0f2b..58ddc7320365f7 100644 --- a/cli/lockfile.rs +++ b/cli/lockfile.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::parking_lot::Mutex; use deno_core::serde_json; diff --git a/cli/logger.rs b/cli/logger.rs index ff3c8f066f3fef..7765032bdddd6f 100644 --- a/cli/logger.rs +++ b/cli/logger.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::io::Write; diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index 560a846031b6b2..182b90488bd58b 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::language_server; use super::tsc; diff --git a/cli/lsp/cache.rs b/cli/lsp/cache.rs index 941b6d9cfc2a0f..16ad7645135825 100644 --- a/cli/lsp/cache.rs +++ b/cli/lsp/cache.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::cache::CacherLoader; use crate::cache::FetchCacher; diff --git a/cli/lsp/capabilities.rs b/cli/lsp/capabilities.rs index 94275024341426..87d2c31da387e0 100644 --- a/cli/lsp/capabilities.rs +++ b/cli/lsp/capabilities.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. ///! ///! Provides information about what capabilities that are supported by the diff --git a/cli/lsp/code_lens.rs b/cli/lsp/code_lens.rs index d13a75f627fefd..d0034069db3fb5 100644 --- a/cli/lsp/code_lens.rs +++ b/cli/lsp/code_lens.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::config::Config; use super::config::WorkspaceSettings; diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index ec9467a1f2322e..51a3ffb88f681f 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::client::Client; use super::language_server; diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index 1c707e68f59274..7be4135d2dfe09 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::anyhow::anyhow; use deno_core::error::AnyError; diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 12d403ebb4fcba..96153dacc68079 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::analysis; use super::client::Client; diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 1125d381fb1796..b0da53ef3ef231 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::text::LineIndex; use super::tsc; @@ -590,7 +590,8 @@ pub(crate) fn to_hover_text( "{}​{}", specifier[..url::Position::AfterScheme].to_string(), specifier[url::Position::AfterScheme..].to_string() - ), + ) + .replace('@', "​@"), }, Err(_) => "_[errored]_".to_string(), } diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 384b100b250dad..0fec7ff80c8ec2 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_ast::MediaType; use deno_core::anyhow::anyhow; @@ -1035,7 +1035,7 @@ impl Inner { Some(Ok(parsed_source)) => { format_parsed_source(&parsed_source, fmt_options) } - Some(Err(err)) => Err(err.to_string()), + Some(Err(err)) => Err(anyhow!("{}", err)), None => { // it's not a js/ts file, so attempt to format its contents format_file(&file_path, document.content().as_str(), fmt_options) @@ -1119,6 +1119,12 @@ impl Inner { ), (None, None, _) => unreachable!("{}", json!(params)), }; + let value = + if let Some(docs) = self.module_registries.get_hover(&dep).await { + format!("{}\n\n---\n\n{}", value, docs) + } else { + value + }; Some(Hover { contents: HoverContents::Markup(MarkupContent { kind: MarkupKind::Markdown, diff --git a/cli/lsp/logging.rs b/cli/lsp/logging.rs index 0bfc2fbc84dc54..b3fc06d8960772 100644 --- a/cli/lsp/logging.rs +++ b/cli/lsp/logging.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicUsize; diff --git a/cli/lsp/lsp_custom.rs b/cli/lsp/lsp_custom.rs index c543a6c1ba6a84..1d8c209846bfe9 100644 --- a/cli/lsp/lsp_custom.rs +++ b/cli/lsp/lsp_custom.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::serde::Deserialize; use deno_core::serde::Serialize; diff --git a/cli/lsp/mod.rs b/cli/lsp/mod.rs index ac4dfc7e9dcf10..436aee001fefd4 100644 --- a/cli/lsp/mod.rs +++ b/cli/lsp/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // FIXME(bartlomieju): remove this attribute #![allow(unused)] diff --git a/cli/lsp/parent_process_checker.rs b/cli/lsp/parent_process_checker.rs index 9e48c3fa8f508e..f4bf99d3e6d93d 100644 --- a/cli/lsp/parent_process_checker.rs +++ b/cli/lsp/parent_process_checker.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use tokio::time::sleep; use tokio::time::Duration; diff --git a/cli/lsp/path_to_regex.rs b/cli/lsp/path_to_regex.rs index ef782c4db713a0..b1929c9b9387b8 100644 --- a/cli/lsp/path_to_regex.rs +++ b/cli/lsp/path_to_regex.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // The logic of this module is heavily influenced by path-to-regexp at: // https://github.com/pillarjs/path-to-regexp/ which is licensed as follows: diff --git a/cli/lsp/performance.rs b/cli/lsp/performance.rs index 2c58ab9c939c90..d251e012f9d3f9 100644 --- a/cli/lsp/performance.rs +++ b/cli/lsp/performance.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::parking_lot::Mutex; use deno_core::serde::Deserialize; diff --git a/cli/lsp/refactor.rs b/cli/lsp/refactor.rs index 2694b7c5afcf4c..cf18eca795a03b 100644 --- a/cli/lsp/refactor.rs +++ b/cli/lsp/refactor.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // The logic of this module is heavily influenced by // https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/refactor.ts diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index 93333dd928b063..94c3c49fc775c7 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::path_to_regex::parse; use super::path_to_regex::string_to_regex; @@ -27,6 +27,7 @@ use deno_core::url::ParseError; use deno_core::url::Position; use deno_core::url::Url; use deno_core::ModuleSpecifier; +use deno_graph::Dependency; use deno_runtime::deno_web::BlobStore; use deno_runtime::permissions::Permissions; use log::error; @@ -565,6 +566,60 @@ impl ModuleRegistry { Ok(()) } + pub(crate) async fn get_hover( + &self, + dependency: &Dependency, + ) -> Option { + let maybe_code = dependency.get_code(); + let maybe_type = dependency.get_type(); + let specifier = match (maybe_code, maybe_type) { + (Some(specifier), _) => Some(specifier), + (_, Some(specifier)) => Some(specifier), + _ => None, + }?; + let origin = base_url(specifier); + let registries = self.origins.get(&origin)?; + let path = &specifier[Position::BeforePath..]; + for registry in registries { + let tokens = parse(®istry.schema, None).ok()?; + let matcher = Matcher::new(&tokens, None).ok()?; + if let Some(match_result) = matcher.matches(path) { + let key = if let Some(Token::Key(key)) = tokens.iter().last() { + Some(key) + } else { + None + }?; + let url = registry.get_documentation_url_for_key(key)?; + let endpoint = get_endpoint_with_match( + key, + url, + specifier, + &tokens, + &match_result, + None, + ) + .ok()?; + let file = self + .file_fetcher + .fetch(&endpoint, &mut Permissions::allow_all()) + .await + .ok()?; + let documentation: lsp::Documentation = + serde_json::from_str(&file.source).ok()?; + return match documentation { + lsp::Documentation::String(doc) => Some(doc), + lsp::Documentation::MarkupContent(lsp::MarkupContent { + value, + .. + }) => Some(value), + _ => None, + }; + } + } + + None + } + /// For a string specifier from the client, provide a set of completions, if /// any, for the specifier. pub(crate) async fn get_completions( @@ -858,7 +913,7 @@ impl ModuleRegistry { self.get_origin_completions(current_specifier, range) } - pub async fn get_documentation( + pub(crate) async fn get_documentation( &self, url: &str, ) -> Option { diff --git a/cli/lsp/repl.rs b/cli/lsp/repl.rs index 458841c1943f76..b4bc1daf7e906a 100644 --- a/cli/lsp/repl.rs +++ b/cli/lsp/repl.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::collections::HashMap; use std::future::Future; diff --git a/cli/lsp/semantic_tokens.rs b/cli/lsp/semantic_tokens.rs index 326eb7dde80ec3..dd3766c04c650f 100644 --- a/cli/lsp/semantic_tokens.rs +++ b/cli/lsp/semantic_tokens.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // The logic of this module is heavily influenced by // https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/semanticTokens.ts diff --git a/cli/lsp/text.rs b/cli/lsp/text.rs index 0b9ae79beeb3c4..9a99624fa027a5 100644 --- a/cli/lsp/text.rs +++ b/cli/lsp/text.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::custom_error; use deno_core::error::AnyError; diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index e2ae5f275227f1..6a8141d4d3983d 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::code_lens; use super::config; diff --git a/cli/lsp/urls.rs b/cli/lsp/urls.rs index 94830d34a49005..74fcc757ab5242 100644 --- a/cli/lsp/urls.rs +++ b/cli/lsp/urls.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::file_fetcher::map_content_type; diff --git a/cli/main.rs b/cli/main.rs index 5fe5d6659e6f5d..f4800b72a1166e 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. mod ast; mod auth_tokens; diff --git a/cli/module_loader.rs b/cli/module_loader.rs index 6fa3e3a0ea8e54..afd47c2d42c87c 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::emit::TypeLib; use crate::proc_state::ProcState; diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs index 92843f577db4ab..a9193b0cda6c6f 100644 --- a/cli/ops/errors.rs +++ b/cli/ops/errors.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::diagnostics::Diagnostics; use crate::fmt_errors::format_file_name; diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index 3584bdbefde38e..34b310b20b9766 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::proc_state::ProcState; use deno_core::Extension; diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index 11504edd581b88..faa427ae76862b 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::cache; use crate::config_file::IgnoredCompilerOptions; diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 7f49b6b1b1206a..ceff64c54a9afc 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::cache; use crate::colors; diff --git a/cli/resolver.rs b/cli/resolver.rs index da8fafe672017f..6143ac6a078bd4 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::resolve_import; diff --git a/cli/source_maps.rs b/cli/source_maps.rs index c2b95095487dbb..80d97f1b936465 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! This mod provides functions to remap a `JsError` based on a source map. diff --git a/cli/standalone.rs b/cli/standalone.rs index f135e994658dc4..e31fa15f7bf0cf 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::colors; use crate::file_fetcher::get_source_from_data_url; diff --git a/cli/tests/integration/bundle_tests.rs b/cli/tests/integration/bundle_tests.rs index adc0dbd1dfde6c..4ef48b7e305f56 100644 --- a/cli/tests/integration/bundle_tests.rs +++ b/cli/tests/integration/bundle_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; use tempfile::TempDir; diff --git a/cli/tests/integration/cache_tests.rs b/cli/tests/integration/cache_tests.rs index 1fc035b9b074bb..773f98f6bb5b49 100644 --- a/cli/tests/integration/cache_tests.rs +++ b/cli/tests/integration/cache_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; diff --git a/cli/tests/integration/compat_tests.rs b/cli/tests/integration/compat_tests.rs index 7eff64f12043e4..bafe24af3cc496 100644 --- a/cli/tests/integration/compat_tests.rs +++ b/cli/tests/integration/compat_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; use deno_core::url::Url; diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs index 3cb628204f12aa..d2abd04d5a943e 100644 --- a/cli/tests/integration/compile_tests.rs +++ b/cli/tests/integration/compile_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::process::Command; use tempfile::TempDir; diff --git a/cli/tests/integration/coverage_tests.rs b/cli/tests/integration/coverage_tests.rs index 2f72508171bd00..feba0769e82388 100644 --- a/cli/tests/integration/coverage_tests.rs +++ b/cli/tests/integration/coverage_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::fs; use tempfile::TempDir; diff --git a/cli/tests/integration/doc_tests.rs b/cli/tests/integration/doc_tests.rs index 05da3852974e2a..95bc2a3358887a 100644 --- a/cli/tests/integration/doc_tests.rs +++ b/cli/tests/integration/doc_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; diff --git a/cli/tests/integration/eval_tests.rs b/cli/tests/integration/eval_tests.rs index 40fa26158c8ea0..d7586e919c87f1 100644 --- a/cli/tests/integration/eval_tests.rs +++ b/cli/tests/integration/eval_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; use test_util as util; diff --git a/cli/tests/integration/fmt_tests.rs b/cli/tests/integration/fmt_tests.rs index 65a248a458604d..18743fb0060a46 100644 --- a/cli/tests/integration/fmt_tests.rs +++ b/cli/tests/integration/fmt_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; use tempfile::TempDir; diff --git a/cli/tests/integration/info_tests.rs b/cli/tests/integration/info_tests.rs index 9e7dbda5b54dc7..6ac6e849bdb57d 100644 --- a/cli/tests/integration/info_tests.rs +++ b/cli/tests/integration/info_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; use tempfile::TempDir; diff --git a/cli/tests/integration/inspector_tests.rs b/cli/tests/integration/inspector_tests.rs index f6b95c1b495fc6..644758cd2bc6cb 100644 --- a/cli/tests/integration/inspector_tests.rs +++ b/cli/tests/integration/inspector_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::futures; use deno_core::futures::prelude::*; @@ -13,6 +13,15 @@ use std::pin::Pin; use test_util as util; use tokio::net::TcpStream; +macro_rules! assert_starts_with { + ($string:expr, $($test:expr),+) => { + let string = $string; // This might be a function call or something + if !($(string.starts_with($test))||+) { + panic!("{:?} does not start with {:?}", string, [$($test),+]); + } + } +} + fn inspect_flag_with_unique_port(flag_prefix: &str) -> String { use std::sync::atomic::{AtomicU16, Ordering}; static PORT: AtomicU16 = AtomicU16::new(9229); @@ -23,8 +32,8 @@ fn inspect_flag_with_unique_port(flag_prefix: &str) -> String { fn extract_ws_url_from_stderr( stderr_lines: &mut impl std::iter::Iterator, ) -> url::Url { - let stderr_first_line = stderr_lines.next().unwrap(); - assert!(stderr_first_line.starts_with("Debugger listening on ")); + let stderr_first_line = skip_check_line(stderr_lines); + assert_starts_with!(&stderr_first_line, "Debugger listening on "); let v: Vec<_> = stderr_first_line.match_indices("ws:").collect(); assert_eq!(v.len(), 1); let ws_url_index = v[0].0; @@ -32,25 +41,57 @@ fn extract_ws_url_from_stderr( url::Url::parse(ws_url).unwrap() } +fn skip_check_line( + stderr_lines: &mut impl std::iter::Iterator, +) -> String { + loop { + let mut line = stderr_lines.next().unwrap(); + line = util::strip_ansi_codes(&line).to_string(); + + if line.starts_with("Check") { + continue; + } + + return line; + } +} + +fn assert_stderr( + stderr_lines: &mut impl std::iter::Iterator, + expected_lines: &[&str], +) { + let mut expected_index = 0; + + loop { + let line = skip_check_line(stderr_lines); + + assert_eq!(line, expected_lines[expected_index]); + expected_index += 1; + + if expected_index >= expected_lines.len() { + break; + } + } +} + fn assert_stderr_for_inspect( stderr_lines: &mut impl std::iter::Iterator, ) { - assert_eq!( - &stderr_lines.next().unwrap(), - "Visit chrome://inspect to connect to the debugger." + assert_stderr( + stderr_lines, + &["Visit chrome://inspect to connect to the debugger."], ); } fn assert_stderr_for_inspect_brk( stderr_lines: &mut impl std::iter::Iterator, ) { - assert_eq!( - &stderr_lines.next().unwrap(), - "Visit chrome://inspect to connect to the debugger." - ); - assert_eq!( - &stderr_lines.next().unwrap(), - "Deno is waiting for debugger to connect." + assert_stderr( + stderr_lines, + &[ + "Visit chrome://inspect to connect to the debugger.", + "Deno is waiting for debugger to connect.", + ], ); } @@ -99,7 +140,7 @@ async fn assert_inspector_messages( #[tokio::test] async fn inspector_connect() { - let script = util::testdata_path().join("inspector1.js"); + let script = util::testdata_path().join("inspector/inspector1.js"); let mut child = util::deno_cmd() .arg("run") .arg(inspect_flag_with_unique_port("--inspect")) @@ -125,7 +166,7 @@ async fn inspector_connect() { #[tokio::test] async fn inspector_break_on_first_line() { - let script = util::testdata_path().join("inspector2.js"); + let script = util::testdata_path().join("inspector/inspector2.js"); let mut child = util::deno_cmd() .arg("run") .arg(inspect_flag_with_unique_port("--inspect-brk")) @@ -216,7 +257,7 @@ async fn inspector_break_on_first_line() { #[tokio::test] async fn inspector_pause() { - let script = util::testdata_path().join("inspector1.js"); + let script = util::testdata_path().join("inspector/inspector1.js"); let mut child = util::deno_cmd() .arg("run") .arg(inspect_flag_with_unique_port("--inspect")) @@ -263,7 +304,7 @@ async fn inspector_pause() { let msg = ws_read_msg(&mut socket).await; println!("response msg 1 {}", msg); - assert!(msg.starts_with(r#"{"id":6,"result":{"debuggerId":"#)); + assert_starts_with!(msg, r#"{"id":6,"result":{"debuggerId":"#); socket .send(r#"{"id":31,"method":"Debugger.pause"}"#.into()) @@ -286,7 +327,7 @@ async fn inspector_port_collision() { return; } - let script = util::testdata_path().join("inspector1.js"); + let script = util::testdata_path().join("inspector/inspector1.js"); let inspect_flag = inspect_flag_with_unique_port("--inspect"); let mut child1 = util::deno_cmd() @@ -326,7 +367,7 @@ async fn inspector_port_collision() { #[tokio::test] async fn inspector_does_not_hang() { - let script = util::testdata_path().join("inspector3.js"); + let script = util::testdata_path().join("inspector/inspector3.js"); let mut child = util::deno_cmd() .arg("run") .arg(inspect_flag_with_unique_port("--inspect-brk")) @@ -438,7 +479,7 @@ async fn inspector_does_not_hang() { #[tokio::test] async fn inspector_without_brk_runs_code() { - let script = util::testdata_path().join("inspector4.js"); + let script = util::testdata_path().join("inspector/inspector4.js"); let mut child = util::deno_cmd() .arg("run") .arg(inspect_flag_with_unique_port("--inspect")) @@ -566,7 +607,7 @@ async fn inspector_runtime_evaluate_does_not_crash() { #[tokio::test] async fn inspector_json() { - let script = util::testdata_path().join("inspector1.js"); + let script = util::testdata_path().join("inspector/inspector1.js"); let mut child = util::deno_cmd() .arg("run") .arg(inspect_flag_with_unique_port("--inspect")) @@ -595,7 +636,7 @@ async fn inspector_json() { #[tokio::test] async fn inspector_json_list() { - let script = util::testdata_path().join("inspector1.js"); + let script = util::testdata_path().join("inspector/inspector1.js"); let mut child = util::deno_cmd() .arg("run") .arg(inspect_flag_with_unique_port("--inspect")) @@ -626,7 +667,7 @@ async fn inspector_json_list() { async fn inspector_connect_non_ws() { // https://github.com/denoland/deno/issues/11449 // Verify we don't panic if non-WS connection is being established - let script = util::testdata_path().join("inspector1.js"); + let script = util::testdata_path().join("inspector/inspector1.js"); let mut child = util::deno_cmd() .arg("run") .arg(inspect_flag_with_unique_port("--inspect")) @@ -650,7 +691,7 @@ async fn inspector_connect_non_ws() { #[tokio::test] async fn inspector_break_on_first_line_in_test() { - let script = util::testdata_path().join("inspector_test.js"); + let script = util::testdata_path().join("inspector/inspector_test.js"); let mut child = util::deno_cmd() .arg("test") .arg(inspect_flag_with_unique_port("--inspect-brk")) @@ -733,10 +774,7 @@ async fn inspector_break_on_first_line_in_test() { ) .await; - assert!(&stdout_lines - .next() - .unwrap() - .starts_with("running 1 test from")); + assert_starts_with!(&stdout_lines.next().unwrap(), "running 1 test from"); assert!(&stdout_lines .next() .unwrap() @@ -745,3 +783,129 @@ async fn inspector_break_on_first_line_in_test() { child.kill().unwrap(); child.wait().unwrap(); } + +#[tokio::test] +async fn inspector_with_ts_files() { + let script = util::testdata_path().join("inspector/test.ts"); + let mut child = util::deno_cmd() + .arg("run") + .arg(inspect_flag_with_unique_port("--inspect-brk")) + .arg(script) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap(); + + let stderr = child.stderr.as_mut().unwrap(); + let mut stderr_lines = + std::io::BufReader::new(stderr).lines().map(|r| r.unwrap()); + let ws_url = extract_ws_url_from_stderr(&mut stderr_lines); + + let (socket, response) = tokio_tungstenite::connect_async(ws_url) + .await + .expect("Can't connect"); + assert_eq!(response.status(), 101); // Switching protocols. + + let (mut socket_tx, socket_rx) = socket.split(); + let mut socket_rx = socket_rx + .map(|msg| msg.unwrap().to_string()) + .filter(|msg| { + let pass = (msg.starts_with(r#"{"method":"Debugger.scriptParsed","#) + && msg.contains("testdata/inspector")) + || !msg.starts_with(r#"{"method":"Debugger.scriptParsed","#); + futures::future::ready(pass) + }) + .boxed_local(); + + let stdout = child.stdout.as_mut().unwrap(); + let mut stdout_lines = + std::io::BufReader::new(stdout).lines().map(|r| r.unwrap()); + + assert_stderr_for_inspect_brk(&mut stderr_lines); + + assert_inspector_messages( + &mut socket_tx, + &[ + r#"{"id":1,"method":"Runtime.enable"}"#, + r#"{"id":2,"method":"Debugger.enable"}"#, + ], + &mut socket_rx, + &[ + r#"{"id":1,"result":{}}"#, + ], + &[ + r#"{"method":"Runtime.executionContextCreated","params":{"context":{"id":1,"#, + ], + ) + .await; + + // receive messages with sources from this test + let script1 = socket_rx.next().await.unwrap(); + assert!(script1.contains("testdata/inspector/test.ts")); + let script1_id = { + let v: serde_json::Value = serde_json::from_str(&script1).unwrap(); + v["params"]["scriptId"].as_str().unwrap().to_string() + }; + let script2 = socket_rx.next().await.unwrap(); + assert!(script2.contains("testdata/inspector/foo.ts")); + let script2_id = { + let v: serde_json::Value = serde_json::from_str(&script2).unwrap(); + v["params"]["scriptId"].as_str().unwrap().to_string() + }; + let script3 = socket_rx.next().await.unwrap(); + assert!(script3.contains("testdata/inspector/bar.js")); + let script3_id = { + let v: serde_json::Value = serde_json::from_str(&script3).unwrap(); + v["params"]["scriptId"].as_str().unwrap().to_string() + }; + + assert_inspector_messages( + &mut socket_tx, + &[], + &mut socket_rx, + &[r#"{"id":2,"result":{"debuggerId":"#], + &[], + ) + .await; + + assert_inspector_messages( + &mut socket_tx, + &[r#"{"id":3,"method":"Runtime.runIfWaitingForDebugger"}"#], + &mut socket_rx, + &[r#"{"id":3,"result":{}}"#], + &[r#"{"method":"Debugger.paused","#], + ) + .await; + + assert_inspector_messages( + &mut socket_tx, + &[ + &format!(r#"{{"id":4,"method":"Debugger.getScriptSource","params":{{"scriptId":"{}"}}}}"#, script1_id), + &format!(r#"{{"id":5,"method":"Debugger.getScriptSource","params":{{"scriptId":"{}"}}}}"#, script2_id), + &format!(r#"{{"id":6,"method":"Debugger.getScriptSource","params":{{"scriptId":"{}"}}}}"#, script3_id), + ], + &mut socket_rx, + &[ + r#"{"id":4,"result":{"scriptSource":"import { foo } from \"./foo.ts\";\nimport { bar } from \"./bar.js\";\nconsole.log(foo());\nconsole.log(bar());\n//# sourceMappingURL=data:application/json;base64,"#, + r#"{"id":5,"result":{"scriptSource":"class Foo {\n hello() {\n return \"hello\";\n }\n}\nexport function foo() {\n const f = new Foo();\n return f.hello();\n}\n//# sourceMappingURL=data:application/json;base64,"#, + r#"{"id":6,"result":{"scriptSource":"export function bar() {\n return \"world\";\n}\n"#, + ], + &[], + ) + .await; + + assert_inspector_messages( + &mut socket_tx, + &[r#"{"id":7,"method":"Debugger.resume"}"#], + &mut socket_rx, + &[r#"{"id":7,"result":{}}"#], + &[], + ) + .await; + + assert_eq!(&stdout_lines.next().unwrap(), "hello"); + assert_eq!(&stdout_lines.next().unwrap(), "world"); + + child.kill().unwrap(); + child.wait().unwrap(); +} diff --git a/cli/tests/integration/install_tests.rs b/cli/tests/integration/install_tests.rs index ff93c157fb538e..68f519686d57cc 100644 --- a/cli/tests/integration/install_tests.rs +++ b/cli/tests/integration/install_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::process::Command; use tempfile::TempDir; diff --git a/cli/tests/integration/lint_tests.rs b/cli/tests/integration/lint_tests.rs index 3fee16aca3ce59..5ed12f59e68f6c 100644 --- a/cli/tests/integration/lint_tests.rs +++ b/cli/tests/integration/lint_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; use test_util as util; diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index a3e1138b630bfa..21894f7e82fd1b 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_ast::ModuleSpecifier; use deno_core::serde::Deserialize; @@ -3044,7 +3044,8 @@ fn lsp_cache_location() { let _g = http_server(); let temp_dir = TempDir::new().expect("could not create temp dir"); let mut params: lsp::InitializeParams = - serde_json::from_value(load_fixture("initialize_params.json")).unwrap(); + serde_json::from_value(load_fixture("initialize_params_registry.json")) + .unwrap(); params.root_uri = Some(Url::from_file_path(temp_dir.path()).unwrap()); if let Some(Value::Object(mut map)) = params.initialization_options { @@ -3075,7 +3076,7 @@ fn lsp_cache_location() { load_fixture("did_open_params_import_hover.json"), ); let diagnostics = diagnostics.into_iter().flat_map(|x| x.diagnostics); - assert_eq!(diagnostics.count(), 12); + assert_eq!(diagnostics.count(), 14); let (maybe_res, maybe_err) = client .write_request::<_, _, Value>( "deno/cache", @@ -3123,6 +3124,40 @@ fn lsp_cache_location() { } })) ); + let (maybe_res, maybe_err) = client + .write_request::<_, _, Value>( + "textDocument/hover", + json!({ + "textDocument": { + "uri": "file:///a/file.ts", + }, + "position": { + "line": 7, + "character": 28 + } + }), + ) + .unwrap(); + assert!(maybe_err.is_none()); + assert_eq!( + maybe_res, + Some(json!({ + "contents": { + "kind": "markdown", + "value": "**Resolved Dependency**\n\n**Code**: http​://localhost:4545/x/a/mod.ts\n\n\n---\n\n**a**\n\nmod.ts" + }, + "range": { + "start": { + "line": 7, + "character": 19 + }, + "end": { + "line": 7, + "character": 53 + } + } + })) + ); let cache_path = temp_dir.path().join(".cache"); assert!(cache_path.is_dir()); assert!(cache_path.join("gen").is_dir()); diff --git a/cli/tests/integration/mod.rs b/cli/tests/integration/mod.rs index 150683749ab497..6321e86ad67c3c 100644 --- a/cli/tests/integration/mod.rs +++ b/cli/tests/integration/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; use deno_core::url; @@ -735,6 +735,39 @@ fn websocket_server_multi_field_connection_header() { assert!(child.wait().unwrap().success()); } +#[test] +fn websocket_server_idletimeout() { + let script = util::testdata_path().join("websocket_server_idletimeout.ts"); + let root_ca = util::testdata_path().join("tls/RootCA.pem"); + let mut child = util::deno_cmd() + .arg("test") + .arg("--unstable") + .arg("--allow-net") + .arg("--cert") + .arg(root_ca) + .arg(script) + .stdout(std::process::Stdio::piped()) + .spawn() + .unwrap(); + + let stdout = child.stdout.as_mut().unwrap(); + let mut buffer = [0; 5]; + let read = stdout.read(&mut buffer).unwrap(); + assert_eq!(read, 5); + let msg = std::str::from_utf8(&buffer).unwrap(); + assert_eq!(msg, "READY"); + + let req = http::request::Builder::new() + .uri("ws://localhost:4502") + .body(()) + .unwrap(); + let (_ws, _request) = + deno_runtime::deno_websocket::tokio_tungstenite::tungstenite::connect(req) + .unwrap(); + + assert!(child.wait().unwrap().success()); +} + #[cfg(not(windows))] #[test] fn set_raw_should_not_panic_on_no_tty() { diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index 7d8cb4d7142b70..68379c69517d2d 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use test_util as util; diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 6e4f45338ad755..f4793a9690684a 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::url; use std::process::Command; diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs index effd615f6b9e84..639b664c134ce5 100644 --- a/cli/tests/integration/test_tests.rs +++ b/cli/tests/integration/test_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; use test_util as util; diff --git a/cli/tests/integration/upgrade_tests.rs b/cli/tests/integration/upgrade_tests.rs index 60a84e673ca148..01554f6dac2636 100644 --- a/cli/tests/integration/upgrade_tests.rs +++ b/cli/tests/integration/upgrade_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::process::{Command, Stdio}; use tempfile::TempDir; diff --git a/cli/tests/integration/watcher_tests.rs b/cli/tests/integration/watcher_tests.rs index 855538b162f742..89d4bf3f75af7e 100644 --- a/cli/tests/integration/watcher_tests.rs +++ b/cli/tests/integration/watcher_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use flaky_test::flaky_test; use std::fs::write; diff --git a/cli/tests/integration/worker_tests.rs b/cli/tests/integration/worker_tests.rs index 8bb051ff370d6a..57faaa6d384109 100644 --- a/cli/tests/integration/worker_tests.rs +++ b/cli/tests/integration/worker_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::itest; diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 368e96f9497e2c..ae6bf98f6f1660 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // The tests exist in a sub folder instead of as separate files in // this directory so that cargo doesn't compile each file as a new crate. diff --git a/cli/tests/testdata/bundle_jsx.out b/cli/tests/testdata/bundle_jsx.out index 44c9e45559042e..da83cde82808c9 100644 --- a/cli/tests/testdata/bundle_jsx.out +++ b/cli/tests/testdata/bundle_jsx.out @@ -1,7 +1,6 @@ [WILDCARD] const React = { - createElement () { - } + createElement () {} }; function app() { return React.createElement("div", null, React.createElement("h2", null, "asdf")); diff --git a/cli/tests/testdata/compat/import_map.json b/cli/tests/testdata/compat/import_map.json index eea58edb44cc75..d84c7a8829b5a0 100644 --- a/cli/tests/testdata/compat/import_map.json +++ b/cli/tests/testdata/compat/import_map.json @@ -1,5 +1,5 @@ { "imports": { - "std/": "https://deno.land/std@0.119.0/" + "std/": "https://deno.land/std@0.120.0/" } } diff --git a/cli/tests/testdata/compat/import_map_https_imports.mjs b/cli/tests/testdata/compat/import_map_https_imports.mjs index bfea1e0edecd6a..9ba7dd81f9eaaf 100644 --- a/cli/tests/testdata/compat/import_map_https_imports.mjs +++ b/cli/tests/testdata/compat/import_map_https_imports.mjs @@ -1,5 +1,5 @@ import { sortBy } from "std/collections/sort_by.ts"; -import { findSingle } from "https://deno.land/std@0.119.0/collections/find_single.ts"; +import { findSingle } from "https://deno.land/std@0.120.0/collections/find_single.ts"; import os from "node:os"; console.log(sortBy([2, 3, 1], (it) => it)); diff --git a/cli/tests/testdata/finalization_registry.js b/cli/tests/testdata/finalization_registry.js index f75979358ee9aa..7d7d58149044d1 100644 --- a/cli/tests/testdata/finalization_registry.js +++ b/cli/tests/testdata/finalization_registry.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; function assertEquals(a, b) { diff --git a/cli/tests/testdata/heapstats.js b/cli/tests/testdata/heapstats.js index 675fac2d61038a..1f06e7f6e22789 100644 --- a/cli/tests/testdata/heapstats.js +++ b/cli/tests/testdata/heapstats.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; function allocTest(alloc, allocAssert, deallocAssert) { diff --git a/cli/tests/testdata/inspector/bar.js b/cli/tests/testdata/inspector/bar.js new file mode 100644 index 00000000000000..278fc9030d0f1a --- /dev/null +++ b/cli/tests/testdata/inspector/bar.js @@ -0,0 +1,3 @@ +export function bar() { + return "world"; +} diff --git a/cli/tests/testdata/inspector/foo.ts b/cli/tests/testdata/inspector/foo.ts new file mode 100644 index 00000000000000..c0735926f1af9f --- /dev/null +++ b/cli/tests/testdata/inspector/foo.ts @@ -0,0 +1,10 @@ +class Foo { + hello(): string { + return "hello"; + } +} + +export function foo(): string { + const f = new Foo(); + return f.hello(); +} diff --git a/cli/tests/testdata/inspector1.js b/cli/tests/testdata/inspector/inspector1.js similarity index 100% rename from cli/tests/testdata/inspector1.js rename to cli/tests/testdata/inspector/inspector1.js diff --git a/cli/tests/testdata/inspector2.js b/cli/tests/testdata/inspector/inspector2.js similarity index 100% rename from cli/tests/testdata/inspector2.js rename to cli/tests/testdata/inspector/inspector2.js diff --git a/cli/tests/testdata/inspector3.js b/cli/tests/testdata/inspector/inspector3.js similarity index 100% rename from cli/tests/testdata/inspector3.js rename to cli/tests/testdata/inspector/inspector3.js diff --git a/cli/tests/testdata/inspector4.js b/cli/tests/testdata/inspector/inspector4.js similarity index 100% rename from cli/tests/testdata/inspector4.js rename to cli/tests/testdata/inspector/inspector4.js diff --git a/cli/tests/testdata/inspector_test.js b/cli/tests/testdata/inspector/inspector_test.js similarity index 100% rename from cli/tests/testdata/inspector_test.js rename to cli/tests/testdata/inspector/inspector_test.js diff --git a/cli/tests/testdata/inspector/test.ts b/cli/tests/testdata/inspector/test.ts new file mode 100644 index 00000000000000..2b33f22e56bd38 --- /dev/null +++ b/cli/tests/testdata/inspector/test.ts @@ -0,0 +1,5 @@ +import { foo } from "./foo.ts"; +import { bar } from "./bar.js"; + +console.log(foo()); +console.log(bar()); diff --git a/cli/tests/testdata/lsp/did_open_params_import_hover.json b/cli/tests/testdata/lsp/did_open_params_import_hover.json index e054eef3e8f481..a79ba0d7fce833 100644 --- a/cli/tests/testdata/lsp/did_open_params_import_hover.json +++ b/cli/tests/testdata/lsp/did_open_params_import_hover.json @@ -3,6 +3,6 @@ "uri": "file:///a/file.ts", "languageId": "typescript", "version": 1, - "text": "import * as a from \"http://127.0.0.1:4545/xTypeScriptTypes.js\";\n// @deno-types=\"http://127.0.0.1:4545/type_definitions/foo.d.ts\"\nimport * as b from \"http://127.0.0.1:4545/type_definitions/foo.js\";\nimport * as c from \"http://127.0.0.1:4545/subdir/type_reference.js\";\nimport * as d from \"http://127.0.0.1:4545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\n\nconsole.log(a, b, c, d, e, f);\n" + "text": "import * as a from \"http://127.0.0.1:4545/xTypeScriptTypes.js\";\n// @deno-types=\"http://127.0.0.1:4545/type_definitions/foo.d.ts\"\nimport * as b from \"http://127.0.0.1:4545/type_definitions/foo.js\";\nimport * as c from \"http://127.0.0.1:4545/subdir/type_reference.js\";\nimport * as d from \"http://127.0.0.1:4545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\nimport * as g from \"http://localhost:4545/x/a/mod.ts\";\n\nconsole.log(a, b, c, d, e, f, g);\n" } } diff --git a/cli/tests/testdata/lsp/did_open_params_large.json b/cli/tests/testdata/lsp/did_open_params_large.json index 996434c0c02ed9..9936c1bdc950b1 100644 --- a/cli/tests/testdata/lsp/did_open_params_large.json +++ b/cli/tests/testdata/lsp/did_open_params_large.json @@ -3,6 +3,6 @@ "uri": "file:///a/file.ts", "languageId": "javascript", "version": 1, - "text": "// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.\n\n// @ts-check\n/// \n// deno-lint-ignore-file no-undef\n\n// This module is the entry point for \"compiler\" isolate, ie. the one\n// that is created when Deno needs to type check TypeScript, and in some\n// instances convert TypeScript to JavaScript.\n\n// Removes the `__proto__` for security reasons. This intentionally makes\n// Deno non compliant with ECMA-262 Annex B.2.2.1\ndelete Object.prototype.__proto__;\n\n((window) => {\n /** @type {DenoCore} */\n const core = window.Deno.core;\n\n let logDebug = false;\n let logSource = \"JS\";\n\n function setLogDebug(debug, source) {\n logDebug = debug;\n if (source) {\n logSource = source;\n }\n }\n\n function debug(...args) {\n if (logDebug) {\n const stringifiedArgs = args.map((arg) =>\n typeof arg === \"string\" ? arg : JSON.stringify(arg)\n ).join(\" \");\n // adding a non-zero integer value to the end of the debug string causes\n // the message to be printed to stderr instead of stdout, which is better\n // aligned to the behaviour of debug messages\n core.print(`DEBUG ${logSource} - ${stringifiedArgs}\\n`, 1);\n }\n }\n\n function error(...args) {\n const stringifiedArgs = args.map((arg) =>\n typeof arg === \"string\" || arg instanceof Error\n ? String(arg)\n : JSON.stringify(arg)\n ).join(\" \");\n core.print(`ERROR ${logSource} = ${stringifiedArgs}\\n`, 1);\n }\n\n class AssertionError extends Error {\n constructor(msg) {\n super(msg);\n this.name = \"AssertionError\";\n }\n }\n\n function assert(cond, msg = \"Assertion failed.\") {\n if (!cond) {\n throw new AssertionError(msg);\n }\n }\n\n /** @type {Map} */\n const sourceFileCache = new Map();\n\n /** @param {ts.DiagnosticRelatedInformation} diagnostic */\n function fromRelatedInformation({\n start,\n length,\n file,\n messageText: msgText,\n ...ri\n }) {\n let messageText;\n let messageChain;\n if (typeof msgText === \"object\") {\n messageChain = msgText;\n } else {\n messageText = msgText;\n }\n if (start !== undefined && length !== undefined && file) {\n const startPos = file.getLineAndCharacterOfPosition(start);\n const sourceLine = file.getFullText().split(\"\\n\")[startPos.line];\n const fileName = file.fileName;\n return {\n start: startPos,\n end: file.getLineAndCharacterOfPosition(start + length),\n fileName,\n messageChain,\n messageText,\n sourceLine,\n ...ri,\n };\n } else {\n return {\n messageChain,\n messageText,\n ...ri,\n };\n }\n }\n\n /** @param {ts.Diagnostic[]} diagnostics */\n function fromTypeScriptDiagnostic(diagnostics) {\n return diagnostics.map(({ relatedInformation: ri, source, ...diag }) => {\n /** @type {any} */\n const value = fromRelatedInformation(diag);\n value.relatedInformation = ri\n ? ri.map(fromRelatedInformation)\n : undefined;\n value.source = source;\n return value;\n });\n }\n\n // Using incremental compile APIs requires that all\n // paths must be either relative or absolute. Since\n // analysis in Rust operates on fully resolved URLs,\n // it makes sense to use the same scheme here.\n const ASSETS = \"asset:///\";\n const CACHE = \"cache:///\";\n\n /** Diagnostics that are intentionally ignored when compiling TypeScript in\n * Deno, as they provide misleading or incorrect information. */\n const IGNORED_DIAGNOSTICS = [\n // TS1208: All files must be modules when the '--isolatedModules' flag is\n // provided. We can ignore because we guarantee that all files are\n // modules.\n 1208,\n // TS1375: 'await' expressions are only allowed at the top level of a file\n // when that file is a module, but this file has no imports or exports.\n // Consider adding an empty 'export {}' to make this file a module.\n 1375,\n // TS1103: 'for-await-of' statement is only allowed within an async function\n // or async generator.\n 1103,\n // TS2306: File 'file:///Users/rld/src/deno/subdir/amd_like.js' is\n // not a module.\n 2306,\n // TS2691: An import path cannot end with a '.ts' extension. Consider\n // importing 'bad-module' instead.\n 2691,\n // TS2792: Cannot find module. Did you mean to set the 'moduleResolution'\n // option to 'node', or to add aliases to the 'paths' option?\n 2792,\n // TS5009: Cannot find the common subdirectory path for the input files.\n 5009,\n // TS5055: Cannot write file\n // 'http://localhost:4545/subdir/mt_application_x_javascript.j4.js'\n // because it would overwrite input file.\n 5055,\n // TypeScript is overly opinionated that only CommonJS modules kinds can\n // support JSON imports. Allegedly this was fixed in\n // Microsoft/TypeScript#26825 but that doesn't seem to be working here,\n // so we will ignore complaints about this compiler setting.\n 5070,\n // TS7016: Could not find a declaration file for module '...'. '...'\n // implicitly has an 'any' type. This is due to `allowJs` being off by\n // default but importing of a JavaScript module.\n 7016,\n ];\n\n const SNAPSHOT_COMPILE_OPTIONS = {\n esModuleInterop: true,\n jsx: ts.JsxEmit.React,\n module: ts.ModuleKind.ESNext,\n noEmit: true,\n strict: true,\n target: ts.ScriptTarget.ESNext,\n };\n\n class ScriptSnapshot {\n /** @type {string} */\n specifier;\n /** @type {string} */\n version;\n /**\n * @param {string} specifier\n * @param {string} version \n */\n constructor(specifier, version) {\n this.specifier = specifier;\n this.version = version;\n }\n /**\n * @param {number} start \n * @param {number} end \n * @returns {string}\n */\n getText(start, end) {\n const { specifier, version } = this;\n debug(\n `snapshot.getText(${start}, ${end}) specifier: ${specifier} version: ${version}`,\n );\n return core.jsonOpSync(\"op_get_text\", { specifier, version, start, end });\n }\n /**\n * @returns {number}\n */\n getLength() {\n const { specifier, version } = this;\n debug(`snapshot.getLength() specifier: ${specifier} version: ${version}`);\n return core.jsonOpSync(\"op_get_length\", { specifier, version });\n }\n /**\n * @param {ScriptSnapshot} oldSnapshot\n * @returns {ts.TextChangeRange | undefined}\n */\n getChangeRange(oldSnapshot) {\n const { specifier, version } = this;\n const { version: oldVersion } = oldSnapshot;\n const oldLength = oldSnapshot.getLength();\n debug(\n `snapshot.getLength() specifier: ${specifier} oldVersion: ${oldVersion} version: ${version}`,\n );\n return core.jsonOpSync(\n \"op_get_change_range\",\n { specifier, oldLength, oldVersion, version },\n );\n }\n dispose() {\n const { specifier, version } = this;\n debug(`snapshot.dispose() specifier: ${specifier} version: ${version}`);\n core.jsonOpSync(\"op_dispose\", { specifier, version });\n }\n }\n\n /** @type {ts.CompilerOptions} */\n let compilationSettings = {};\n\n /** @type {ts.LanguageService} */\n let languageService;\n\n /** An object literal of the incremental compiler host, which provides the\n * specific \"bindings\" to the Deno environment that tsc needs to work.\n *\n * @type {ts.CompilerHost & ts.LanguageServiceHost} */\n const host = {\n fileExists(fileName) {\n debug(`host.fileExists(\"${fileName}\")`);\n return false;\n },\n readFile(specifier) {\n debug(`host.readFile(\"${specifier}\")`);\n return core.jsonOpSync(\"op_load\", { specifier }).data;\n },\n getSourceFile(\n specifier,\n languageVersion,\n _onError,\n _shouldCreateNewSourceFile,\n ) {\n debug(\n `host.getSourceFile(\"${specifier}\", ${\n ts.ScriptTarget[languageVersion]\n })`,\n );\n let sourceFile = sourceFileCache.get(specifier);\n if (sourceFile) {\n return sourceFile;\n }\n\n /** @type {{ data: string; hash?: string; scriptKind: ts.ScriptKind }} */\n const { data, hash, scriptKind } = core.jsonOpSync(\n \"op_load\",\n { specifier },\n );\n assert(\n data != null,\n `\"data\" is unexpectedly null for \"${specifier}\".`,\n );\n sourceFile = ts.createSourceFile(\n specifier,\n data,\n languageVersion,\n false,\n scriptKind,\n );\n sourceFile.moduleName = specifier;\n sourceFile.version = hash;\n sourceFileCache.set(specifier, sourceFile);\n return sourceFile;\n },\n getDefaultLibFileName() {\n return `${ASSETS}/lib.esnext.d.ts`;\n },\n getDefaultLibLocation() {\n return ASSETS;\n },\n writeFile(fileName, data, _writeByteOrderMark, _onError, sourceFiles) {\n debug(`host.writeFile(\"${fileName}\")`);\n let maybeSpecifiers;\n if (sourceFiles) {\n maybeSpecifiers = sourceFiles.map((sf) => sf.moduleName);\n }\n return core.jsonOpSync(\n \"op_emit\",\n { maybeSpecifiers, fileName, data },\n );\n },\n getCurrentDirectory() {\n return CACHE;\n },\n getCanonicalFileName(fileName) {\n return fileName;\n },\n useCaseSensitiveFileNames() {\n return true;\n },\n getNewLine() {\n return \"\\n\";\n },\n resolveModuleNames(specifiers, base) {\n debug(`host.resolveModuleNames()`);\n debug(` base: ${base}`);\n debug(` specifiers: ${specifiers.join(\", \")}`);\n /** @type {Array<[string, ts.Extension] | undefined>} */\n const resolved = core.jsonOpSync(\"op_resolve\", {\n specifiers,\n base,\n });\n if (resolved) {\n const result = resolved.map((item) => {\n if (item) {\n const [resolvedFileName, extension] = item;\n return {\n resolvedFileName,\n extension,\n isExternalLibraryImport: false,\n };\n }\n return undefined;\n });\n result.length = specifiers.length;\n return result;\n } else {\n return new Array(specifiers.length);\n }\n },\n createHash(data) {\n return core.jsonOpSync(\"op_create_hash\", { data }).hash;\n },\n\n // LanguageServiceHost\n getCompilationSettings() {\n debug(\"host.getCompilationSettings()\");\n return compilationSettings;\n },\n getScriptFileNames() {\n debug(\"host.getScriptFileNames()\");\n return core.jsonOpSync(\"op_script_names\", undefined);\n },\n getScriptVersion(specifier) {\n debug(`host.getScriptVersion(\"${specifier}\")`);\n const sourceFile = sourceFileCache.get(specifier);\n if (sourceFile) {\n return sourceFile.version ?? \"1\";\n }\n return core.jsonOpSync(\"op_script_version\", { specifier });\n },\n getScriptSnapshot(specifier) {\n debug(`host.getScriptSnapshot(\"${specifier}\")`);\n const sourceFile = sourceFileCache.get(specifier);\n if (sourceFile) {\n return {\n getText(start, end) {\n return sourceFile.text.substring(start, end);\n },\n getLength() {\n return sourceFile.text.length;\n },\n getChangeRange() {\n return undefined;\n },\n };\n }\n /** @type {string | undefined} */\n const version = core.jsonOpSync(\"op_script_version\", { specifier });\n if (version != null) {\n return new ScriptSnapshot(specifier, version);\n }\n return undefined;\n },\n };\n\n /** @type {Array<[string, number]>} */\n const stats = [];\n let statsStart = 0;\n\n function performanceStart() {\n stats.length = 0;\n statsStart = Date.now();\n ts.performance.enable();\n }\n\n /**\n * @param {{ program: ts.Program | ts.EmitAndSemanticDiagnosticsBuilderProgram, fileCount?: number }} options \n */\n function performanceProgram({ program, fileCount }) {\n if (program) {\n if (\"getProgram\" in program) {\n program = program.getProgram();\n }\n stats.push([\"Files\", program.getSourceFiles().length]);\n stats.push([\"Nodes\", program.getNodeCount()]);\n stats.push([\"Identifiers\", program.getIdentifierCount()]);\n stats.push([\"Symbols\", program.getSymbolCount()]);\n stats.push([\"Types\", program.getTypeCount()]);\n stats.push([\"Instantiations\", program.getInstantiationCount()]);\n } else if (fileCount != null) {\n stats.push([\"Files\", fileCount]);\n }\n const programTime = ts.performance.getDuration(\"Program\");\n const bindTime = ts.performance.getDuration(\"Bind\");\n const checkTime = ts.performance.getDuration(\"Check\");\n const emitTime = ts.performance.getDuration(\"Emit\");\n stats.push([\"Parse time\", programTime]);\n stats.push([\"Bind time\", bindTime]);\n stats.push([\"Check time\", checkTime]);\n stats.push([\"Emit time\", emitTime]);\n stats.push(\n [\"Total TS time\", programTime + bindTime + checkTime + emitTime],\n );\n }\n\n function performanceEnd() {\n const duration = Date.now() - statsStart;\n stats.push([\"Compile time\", duration]);\n return stats;\n }\n\n /**\n * @typedef {object} Request\n * @property {Record} config\n * @property {boolean} debug\n * @property {string[]} rootNames\n */\n\n /** The API that is called by Rust when executing a request.\n * @param {Request} request\n */\n function exec({ config, debug: debugFlag, rootNames }) {\n setLogDebug(debugFlag, \"TS\");\n performanceStart();\n debug(\">>> exec start\", { rootNames });\n debug(config);\n\n const { options, errors: configFileParsingDiagnostics } = ts\n .convertCompilerOptionsFromJson(config, \"\");\n // The `allowNonTsExtensions` is a \"hidden\" compiler option used in VSCode\n // which is not allowed to be passed in JSON, we need it to allow special\n // URLs which Deno supports. So we need to either ignore the diagnostic, or\n // inject it ourselves.\n Object.assign(options, { allowNonTsExtensions: true });\n const program = ts.createIncrementalProgram({\n rootNames,\n options,\n host,\n configFileParsingDiagnostics,\n });\n\n const { diagnostics: emitDiagnostics } = program.emit();\n\n const diagnostics = [\n ...program.getConfigFileParsingDiagnostics(),\n ...program.getSyntacticDiagnostics(),\n ...program.getOptionsDiagnostics(),\n ...program.getGlobalDiagnostics(),\n ...program.getSemanticDiagnostics(),\n ...emitDiagnostics,\n ].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code));\n performanceProgram({ program });\n\n core.jsonOpSync(\"op_respond\", {\n diagnostics: fromTypeScriptDiagnostic(diagnostics),\n stats: performanceEnd(),\n });\n debug(\"<<< exec stop\");\n }\n\n /**\n * @param {number} id \n * @param {any} data \n */\n function respond(id, data = null) {\n core.jsonOpSync(\"op_respond\", { id, data });\n }\n\n /**\n * @param {LanguageServerRequest} request \n */\n function serverRequest({ id, ...request }) {\n debug(`serverRequest()`, { id, ...request });\n switch (request.method) {\n case \"configure\": {\n const { options, errors } = ts\n .convertCompilerOptionsFromJson(request.compilerOptions, \"\");\n Object.assign(options, { allowNonTsExtensions: true });\n if (errors.length) {\n debug(ts.formatDiagnostics(errors, host));\n }\n compilationSettings = options;\n return respond(id, true);\n }\n case \"getAsset\": {\n const sourceFile = host.getSourceFile(\n request.specifier,\n ts.ScriptTarget.ESNext,\n );\n return respond(id, sourceFile && sourceFile.text);\n }\n case \"getDiagnostics\": {\n try {\n /** @type {Record} */\n const diagnosticMap = {};\n for (const specifier of request.specifiers) {\n diagnosticMap[specifier] = fromTypeScriptDiagnostic([\n ...languageService.getSemanticDiagnostics(specifier),\n ...languageService.getSuggestionDiagnostics(specifier),\n ...languageService.getSyntacticDiagnostics(specifier),\n ].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code)));\n }\n return respond(id, diagnosticMap);\n } catch (e) {\n if (\"stack\" in e) {\n error(e.stack);\n } else {\n error(e);\n }\n return respond(id, {});\n }\n }\n case \"getQuickInfo\": {\n return respond(\n id,\n languageService.getQuickInfoAtPosition(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"getCompletions\": {\n return respond(\n id,\n languageService.getCompletionsAtPosition(\n request.specifier,\n request.position,\n request.preferences,\n ),\n );\n }\n case \"getDocumentHighlights\": {\n return respond(\n id,\n languageService.getDocumentHighlights(\n request.specifier,\n request.position,\n request.filesToSearch,\n ),\n );\n }\n case \"getReferences\": {\n return respond(\n id,\n languageService.getReferencesAtPosition(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"getDefinition\": {\n return respond(\n id,\n languageService.getDefinitionAndBoundSpan(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"getImplementation\": {\n return respond(\n id,\n languageService.getImplementationAtPosition(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"findRenameLocations\": {\n return respond(\n id,\n languageService.findRenameLocations(\n request.specifier,\n request.position,\n request.findInStrings,\n request.findInComments,\n request.providePrefixAndSuffixTextForRename,\n ),\n );\n }\n default:\n throw new TypeError(\n // @ts-ignore exhausted case statement sets type to never\n `Invalid request method for request: \"${request.method}\" (${id})`,\n );\n }\n }\n\n /** @param {{ debug: boolean; }} init */\n function serverInit({ debug: debugFlag }) {\n if (hasStarted) {\n throw new Error(\"The language server has already been initialized.\");\n }\n hasStarted = true;\n languageService = ts.createLanguageService(host);\n core.ops();\n setLogDebug(debugFlag, \"TSLS\");\n debug(\"serverInit()\");\n }\n\n let hasStarted = false;\n\n /** Startup the runtime environment, setting various flags.\n * @param {{ debugFlag?: boolean; legacyFlag?: boolean; }} msg\n */\n function startup({ debugFlag = false }) {\n if (hasStarted) {\n throw new Error(\"The compiler runtime already started.\");\n }\n hasStarted = true;\n core.ops();\n setLogDebug(!!debugFlag, \"TS\");\n }\n\n // Setup the compiler runtime during the build process.\n core.ops();\n core.registerErrorClass(\"Error\", Error);\n\n // A build time only op that provides some setup information that is used to\n // ensure the snapshot is setup properly.\n /** @type {{ buildSpecifier: string; libs: string[] }} */\n const { buildSpecifier, libs } = core.jsonOpSync(\"op_build_info\", {});\n for (const lib of libs) {\n const specifier = `lib.${lib}.d.ts`;\n // we are using internal APIs here to \"inject\" our custom libraries into\n // tsc, so things like `\"lib\": [ \"deno.ns\" ]` are supported.\n if (!ts.libs.includes(lib)) {\n ts.libs.push(lib);\n ts.libMap.set(lib, `lib.${lib}.d.ts`);\n }\n // we are caching in memory common type libraries that will be re-used by\n // tsc on when the snapshot is restored\n assert(\n host.getSourceFile(`${ASSETS}${specifier}`, ts.ScriptTarget.ESNext),\n );\n }\n // this helps ensure as much as possible is in memory that is re-usable\n // before the snapshotting is done, which helps unsure fast \"startup\" for\n // subsequent uses of tsc in Deno.\n const TS_SNAPSHOT_PROGRAM = ts.createProgram({\n rootNames: [buildSpecifier],\n options: SNAPSHOT_COMPILE_OPTIONS,\n host,\n });\n ts.getPreEmitDiagnostics(TS_SNAPSHOT_PROGRAM);\n\n // exposes the two functions that are called by `tsc::exec()` when type\n // checking TypeScript.\n globalThis.startup = startup;\n globalThis.exec = exec;\n\n // exposes the functions that are called when the compiler is used as a\n // language service.\n globalThis.serverInit = serverInit;\n globalThis.serverRequest = serverRequest;\n})(this);\n" + "text": "// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.\n\n// @ts-check\n/// \n// deno-lint-ignore-file no-undef\n\n// This module is the entry point for \"compiler\" isolate, ie. the one\n// that is created when Deno needs to type check TypeScript, and in some\n// instances convert TypeScript to JavaScript.\n\n// Removes the `__proto__` for security reasons. This intentionally makes\n// Deno non compliant with ECMA-262 Annex B.2.2.1\ndelete Object.prototype.__proto__;\n\n((window) => {\n /** @type {DenoCore} */\n const core = window.Deno.core;\n\n let logDebug = false;\n let logSource = \"JS\";\n\n function setLogDebug(debug, source) {\n logDebug = debug;\n if (source) {\n logSource = source;\n }\n }\n\n function debug(...args) {\n if (logDebug) {\n const stringifiedArgs = args.map((arg) =>\n typeof arg === \"string\" ? arg : JSON.stringify(arg)\n ).join(\" \");\n // adding a non-zero integer value to the end of the debug string causes\n // the message to be printed to stderr instead of stdout, which is better\n // aligned to the behaviour of debug messages\n core.print(`DEBUG ${logSource} - ${stringifiedArgs}\\n`, 1);\n }\n }\n\n function error(...args) {\n const stringifiedArgs = args.map((arg) =>\n typeof arg === \"string\" || arg instanceof Error\n ? String(arg)\n : JSON.stringify(arg)\n ).join(\" \");\n core.print(`ERROR ${logSource} = ${stringifiedArgs}\\n`, 1);\n }\n\n class AssertionError extends Error {\n constructor(msg) {\n super(msg);\n this.name = \"AssertionError\";\n }\n }\n\n function assert(cond, msg = \"Assertion failed.\") {\n if (!cond) {\n throw new AssertionError(msg);\n }\n }\n\n /** @type {Map} */\n const sourceFileCache = new Map();\n\n /** @param {ts.DiagnosticRelatedInformation} diagnostic */\n function fromRelatedInformation({\n start,\n length,\n file,\n messageText: msgText,\n ...ri\n }) {\n let messageText;\n let messageChain;\n if (typeof msgText === \"object\") {\n messageChain = msgText;\n } else {\n messageText = msgText;\n }\n if (start !== undefined && length !== undefined && file) {\n const startPos = file.getLineAndCharacterOfPosition(start);\n const sourceLine = file.getFullText().split(\"\\n\")[startPos.line];\n const fileName = file.fileName;\n return {\n start: startPos,\n end: file.getLineAndCharacterOfPosition(start + length),\n fileName,\n messageChain,\n messageText,\n sourceLine,\n ...ri,\n };\n } else {\n return {\n messageChain,\n messageText,\n ...ri,\n };\n }\n }\n\n /** @param {ts.Diagnostic[]} diagnostics */\n function fromTypeScriptDiagnostic(diagnostics) {\n return diagnostics.map(({ relatedInformation: ri, source, ...diag }) => {\n /** @type {any} */\n const value = fromRelatedInformation(diag);\n value.relatedInformation = ri\n ? ri.map(fromRelatedInformation)\n : undefined;\n value.source = source;\n return value;\n });\n }\n\n // Using incremental compile APIs requires that all\n // paths must be either relative or absolute. Since\n // analysis in Rust operates on fully resolved URLs,\n // it makes sense to use the same scheme here.\n const ASSETS = \"asset:///\";\n const CACHE = \"cache:///\";\n\n /** Diagnostics that are intentionally ignored when compiling TypeScript in\n * Deno, as they provide misleading or incorrect information. */\n const IGNORED_DIAGNOSTICS = [\n // TS1208: All files must be modules when the '--isolatedModules' flag is\n // provided. We can ignore because we guarantee that all files are\n // modules.\n 1208,\n // TS1375: 'await' expressions are only allowed at the top level of a file\n // when that file is a module, but this file has no imports or exports.\n // Consider adding an empty 'export {}' to make this file a module.\n 1375,\n // TS1103: 'for-await-of' statement is only allowed within an async function\n // or async generator.\n 1103,\n // TS2306: File 'file:///Users/rld/src/deno/subdir/amd_like.js' is\n // not a module.\n 2306,\n // TS2691: An import path cannot end with a '.ts' extension. Consider\n // importing 'bad-module' instead.\n 2691,\n // TS2792: Cannot find module. Did you mean to set the 'moduleResolution'\n // option to 'node', or to add aliases to the 'paths' option?\n 2792,\n // TS5009: Cannot find the common subdirectory path for the input files.\n 5009,\n // TS5055: Cannot write file\n // 'http://localhost:4545/subdir/mt_application_x_javascript.j4.js'\n // because it would overwrite input file.\n 5055,\n // TypeScript is overly opinionated that only CommonJS modules kinds can\n // support JSON imports. Allegedly this was fixed in\n // Microsoft/TypeScript#26825 but that doesn't seem to be working here,\n // so we will ignore complaints about this compiler setting.\n 5070,\n // TS7016: Could not find a declaration file for module '...'. '...'\n // implicitly has an 'any' type. This is due to `allowJs` being off by\n // default but importing of a JavaScript module.\n 7016,\n ];\n\n const SNAPSHOT_COMPILE_OPTIONS = {\n esModuleInterop: true,\n jsx: ts.JsxEmit.React,\n module: ts.ModuleKind.ESNext,\n noEmit: true,\n strict: true,\n target: ts.ScriptTarget.ESNext,\n };\n\n class ScriptSnapshot {\n /** @type {string} */\n specifier;\n /** @type {string} */\n version;\n /**\n * @param {string} specifier\n * @param {string} version \n */\n constructor(specifier, version) {\n this.specifier = specifier;\n this.version = version;\n }\n /**\n * @param {number} start \n * @param {number} end \n * @returns {string}\n */\n getText(start, end) {\n const { specifier, version } = this;\n debug(\n `snapshot.getText(${start}, ${end}) specifier: ${specifier} version: ${version}`,\n );\n return core.jsonOpSync(\"op_get_text\", { specifier, version, start, end });\n }\n /**\n * @returns {number}\n */\n getLength() {\n const { specifier, version } = this;\n debug(`snapshot.getLength() specifier: ${specifier} version: ${version}`);\n return core.jsonOpSync(\"op_get_length\", { specifier, version });\n }\n /**\n * @param {ScriptSnapshot} oldSnapshot\n * @returns {ts.TextChangeRange | undefined}\n */\n getChangeRange(oldSnapshot) {\n const { specifier, version } = this;\n const { version: oldVersion } = oldSnapshot;\n const oldLength = oldSnapshot.getLength();\n debug(\n `snapshot.getLength() specifier: ${specifier} oldVersion: ${oldVersion} version: ${version}`,\n );\n return core.jsonOpSync(\n \"op_get_change_range\",\n { specifier, oldLength, oldVersion, version },\n );\n }\n dispose() {\n const { specifier, version } = this;\n debug(`snapshot.dispose() specifier: ${specifier} version: ${version}`);\n core.jsonOpSync(\"op_dispose\", { specifier, version });\n }\n }\n\n /** @type {ts.CompilerOptions} */\n let compilationSettings = {};\n\n /** @type {ts.LanguageService} */\n let languageService;\n\n /** An object literal of the incremental compiler host, which provides the\n * specific \"bindings\" to the Deno environment that tsc needs to work.\n *\n * @type {ts.CompilerHost & ts.LanguageServiceHost} */\n const host = {\n fileExists(fileName) {\n debug(`host.fileExists(\"${fileName}\")`);\n return false;\n },\n readFile(specifier) {\n debug(`host.readFile(\"${specifier}\")`);\n return core.jsonOpSync(\"op_load\", { specifier }).data;\n },\n getSourceFile(\n specifier,\n languageVersion,\n _onError,\n _shouldCreateNewSourceFile,\n ) {\n debug(\n `host.getSourceFile(\"${specifier}\", ${\n ts.ScriptTarget[languageVersion]\n })`,\n );\n let sourceFile = sourceFileCache.get(specifier);\n if (sourceFile) {\n return sourceFile;\n }\n\n /** @type {{ data: string; hash?: string; scriptKind: ts.ScriptKind }} */\n const { data, hash, scriptKind } = core.jsonOpSync(\n \"op_load\",\n { specifier },\n );\n assert(\n data != null,\n `\"data\" is unexpectedly null for \"${specifier}\".`,\n );\n sourceFile = ts.createSourceFile(\n specifier,\n data,\n languageVersion,\n false,\n scriptKind,\n );\n sourceFile.moduleName = specifier;\n sourceFile.version = hash;\n sourceFileCache.set(specifier, sourceFile);\n return sourceFile;\n },\n getDefaultLibFileName() {\n return `${ASSETS}/lib.esnext.d.ts`;\n },\n getDefaultLibLocation() {\n return ASSETS;\n },\n writeFile(fileName, data, _writeByteOrderMark, _onError, sourceFiles) {\n debug(`host.writeFile(\"${fileName}\")`);\n let maybeSpecifiers;\n if (sourceFiles) {\n maybeSpecifiers = sourceFiles.map((sf) => sf.moduleName);\n }\n return core.jsonOpSync(\n \"op_emit\",\n { maybeSpecifiers, fileName, data },\n );\n },\n getCurrentDirectory() {\n return CACHE;\n },\n getCanonicalFileName(fileName) {\n return fileName;\n },\n useCaseSensitiveFileNames() {\n return true;\n },\n getNewLine() {\n return \"\\n\";\n },\n resolveModuleNames(specifiers, base) {\n debug(`host.resolveModuleNames()`);\n debug(` base: ${base}`);\n debug(` specifiers: ${specifiers.join(\", \")}`);\n /** @type {Array<[string, ts.Extension] | undefined>} */\n const resolved = core.jsonOpSync(\"op_resolve\", {\n specifiers,\n base,\n });\n if (resolved) {\n const result = resolved.map((item) => {\n if (item) {\n const [resolvedFileName, extension] = item;\n return {\n resolvedFileName,\n extension,\n isExternalLibraryImport: false,\n };\n }\n return undefined;\n });\n result.length = specifiers.length;\n return result;\n } else {\n return new Array(specifiers.length);\n }\n },\n createHash(data) {\n return core.jsonOpSync(\"op_create_hash\", { data }).hash;\n },\n\n // LanguageServiceHost\n getCompilationSettings() {\n debug(\"host.getCompilationSettings()\");\n return compilationSettings;\n },\n getScriptFileNames() {\n debug(\"host.getScriptFileNames()\");\n return core.jsonOpSync(\"op_script_names\", undefined);\n },\n getScriptVersion(specifier) {\n debug(`host.getScriptVersion(\"${specifier}\")`);\n const sourceFile = sourceFileCache.get(specifier);\n if (sourceFile) {\n return sourceFile.version ?? \"1\";\n }\n return core.jsonOpSync(\"op_script_version\", { specifier });\n },\n getScriptSnapshot(specifier) {\n debug(`host.getScriptSnapshot(\"${specifier}\")`);\n const sourceFile = sourceFileCache.get(specifier);\n if (sourceFile) {\n return {\n getText(start, end) {\n return sourceFile.text.substring(start, end);\n },\n getLength() {\n return sourceFile.text.length;\n },\n getChangeRange() {\n return undefined;\n },\n };\n }\n /** @type {string | undefined} */\n const version = core.jsonOpSync(\"op_script_version\", { specifier });\n if (version != null) {\n return new ScriptSnapshot(specifier, version);\n }\n return undefined;\n },\n };\n\n /** @type {Array<[string, number]>} */\n const stats = [];\n let statsStart = 0;\n\n function performanceStart() {\n stats.length = 0;\n statsStart = Date.now();\n ts.performance.enable();\n }\n\n /**\n * @param {{ program: ts.Program | ts.EmitAndSemanticDiagnosticsBuilderProgram, fileCount?: number }} options \n */\n function performanceProgram({ program, fileCount }) {\n if (program) {\n if (\"getProgram\" in program) {\n program = program.getProgram();\n }\n stats.push([\"Files\", program.getSourceFiles().length]);\n stats.push([\"Nodes\", program.getNodeCount()]);\n stats.push([\"Identifiers\", program.getIdentifierCount()]);\n stats.push([\"Symbols\", program.getSymbolCount()]);\n stats.push([\"Types\", program.getTypeCount()]);\n stats.push([\"Instantiations\", program.getInstantiationCount()]);\n } else if (fileCount != null) {\n stats.push([\"Files\", fileCount]);\n }\n const programTime = ts.performance.getDuration(\"Program\");\n const bindTime = ts.performance.getDuration(\"Bind\");\n const checkTime = ts.performance.getDuration(\"Check\");\n const emitTime = ts.performance.getDuration(\"Emit\");\n stats.push([\"Parse time\", programTime]);\n stats.push([\"Bind time\", bindTime]);\n stats.push([\"Check time\", checkTime]);\n stats.push([\"Emit time\", emitTime]);\n stats.push(\n [\"Total TS time\", programTime + bindTime + checkTime + emitTime],\n );\n }\n\n function performanceEnd() {\n const duration = Date.now() - statsStart;\n stats.push([\"Compile time\", duration]);\n return stats;\n }\n\n /**\n * @typedef {object} Request\n * @property {Record} config\n * @property {boolean} debug\n * @property {string[]} rootNames\n */\n\n /** The API that is called by Rust when executing a request.\n * @param {Request} request\n */\n function exec({ config, debug: debugFlag, rootNames }) {\n setLogDebug(debugFlag, \"TS\");\n performanceStart();\n debug(\">>> exec start\", { rootNames });\n debug(config);\n\n const { options, errors: configFileParsingDiagnostics } = ts\n .convertCompilerOptionsFromJson(config, \"\");\n // The `allowNonTsExtensions` is a \"hidden\" compiler option used in VSCode\n // which is not allowed to be passed in JSON, we need it to allow special\n // URLs which Deno supports. So we need to either ignore the diagnostic, or\n // inject it ourselves.\n Object.assign(options, { allowNonTsExtensions: true });\n const program = ts.createIncrementalProgram({\n rootNames,\n options,\n host,\n configFileParsingDiagnostics,\n });\n\n const { diagnostics: emitDiagnostics } = program.emit();\n\n const diagnostics = [\n ...program.getConfigFileParsingDiagnostics(),\n ...program.getSyntacticDiagnostics(),\n ...program.getOptionsDiagnostics(),\n ...program.getGlobalDiagnostics(),\n ...program.getSemanticDiagnostics(),\n ...emitDiagnostics,\n ].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code));\n performanceProgram({ program });\n\n core.jsonOpSync(\"op_respond\", {\n diagnostics: fromTypeScriptDiagnostic(diagnostics),\n stats: performanceEnd(),\n });\n debug(\"<<< exec stop\");\n }\n\n /**\n * @param {number} id \n * @param {any} data \n */\n function respond(id, data = null) {\n core.jsonOpSync(\"op_respond\", { id, data });\n }\n\n /**\n * @param {LanguageServerRequest} request \n */\n function serverRequest({ id, ...request }) {\n debug(`serverRequest()`, { id, ...request });\n switch (request.method) {\n case \"configure\": {\n const { options, errors } = ts\n .convertCompilerOptionsFromJson(request.compilerOptions, \"\");\n Object.assign(options, { allowNonTsExtensions: true });\n if (errors.length) {\n debug(ts.formatDiagnostics(errors, host));\n }\n compilationSettings = options;\n return respond(id, true);\n }\n case \"getAsset\": {\n const sourceFile = host.getSourceFile(\n request.specifier,\n ts.ScriptTarget.ESNext,\n );\n return respond(id, sourceFile && sourceFile.text);\n }\n case \"getDiagnostics\": {\n try {\n /** @type {Record} */\n const diagnosticMap = {};\n for (const specifier of request.specifiers) {\n diagnosticMap[specifier] = fromTypeScriptDiagnostic([\n ...languageService.getSemanticDiagnostics(specifier),\n ...languageService.getSuggestionDiagnostics(specifier),\n ...languageService.getSyntacticDiagnostics(specifier),\n ].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code)));\n }\n return respond(id, diagnosticMap);\n } catch (e) {\n if (\"stack\" in e) {\n error(e.stack);\n } else {\n error(e);\n }\n return respond(id, {});\n }\n }\n case \"getQuickInfo\": {\n return respond(\n id,\n languageService.getQuickInfoAtPosition(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"getCompletions\": {\n return respond(\n id,\n languageService.getCompletionsAtPosition(\n request.specifier,\n request.position,\n request.preferences,\n ),\n );\n }\n case \"getDocumentHighlights\": {\n return respond(\n id,\n languageService.getDocumentHighlights(\n request.specifier,\n request.position,\n request.filesToSearch,\n ),\n );\n }\n case \"getReferences\": {\n return respond(\n id,\n languageService.getReferencesAtPosition(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"getDefinition\": {\n return respond(\n id,\n languageService.getDefinitionAndBoundSpan(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"getImplementation\": {\n return respond(\n id,\n languageService.getImplementationAtPosition(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"findRenameLocations\": {\n return respond(\n id,\n languageService.findRenameLocations(\n request.specifier,\n request.position,\n request.findInStrings,\n request.findInComments,\n request.providePrefixAndSuffixTextForRename,\n ),\n );\n }\n default:\n throw new TypeError(\n // @ts-ignore exhausted case statement sets type to never\n `Invalid request method for request: \"${request.method}\" (${id})`,\n );\n }\n }\n\n /** @param {{ debug: boolean; }} init */\n function serverInit({ debug: debugFlag }) {\n if (hasStarted) {\n throw new Error(\"The language server has already been initialized.\");\n }\n hasStarted = true;\n languageService = ts.createLanguageService(host);\n core.ops();\n setLogDebug(debugFlag, \"TSLS\");\n debug(\"serverInit()\");\n }\n\n let hasStarted = false;\n\n /** Startup the runtime environment, setting various flags.\n * @param {{ debugFlag?: boolean; legacyFlag?: boolean; }} msg\n */\n function startup({ debugFlag = false }) {\n if (hasStarted) {\n throw new Error(\"The compiler runtime already started.\");\n }\n hasStarted = true;\n core.ops();\n setLogDebug(!!debugFlag, \"TS\");\n }\n\n // Setup the compiler runtime during the build process.\n core.ops();\n core.registerErrorClass(\"Error\", Error);\n\n // A build time only op that provides some setup information that is used to\n // ensure the snapshot is setup properly.\n /** @type {{ buildSpecifier: string; libs: string[] }} */\n const { buildSpecifier, libs } = core.jsonOpSync(\"op_build_info\", {});\n for (const lib of libs) {\n const specifier = `lib.${lib}.d.ts`;\n // we are using internal APIs here to \"inject\" our custom libraries into\n // tsc, so things like `\"lib\": [ \"deno.ns\" ]` are supported.\n if (!ts.libs.includes(lib)) {\n ts.libs.push(lib);\n ts.libMap.set(lib, `lib.${lib}.d.ts`);\n }\n // we are caching in memory common type libraries that will be re-used by\n // tsc on when the snapshot is restored\n assert(\n host.getSourceFile(`${ASSETS}${specifier}`, ts.ScriptTarget.ESNext),\n );\n }\n // this helps ensure as much as possible is in memory that is re-usable\n // before the snapshotting is done, which helps unsure fast \"startup\" for\n // subsequent uses of tsc in Deno.\n const TS_SNAPSHOT_PROGRAM = ts.createProgram({\n rootNames: [buildSpecifier],\n options: SNAPSHOT_COMPILE_OPTIONS,\n host,\n });\n ts.getPreEmitDiagnostics(TS_SNAPSHOT_PROGRAM);\n\n // exposes the two functions that are called by `tsc::exec()` when type\n // checking TypeScript.\n globalThis.startup = startup;\n globalThis.exec = exec;\n\n // exposes the functions that are called when the compiler is used as a\n // language service.\n globalThis.serverInit = serverInit;\n globalThis.serverRequest = serverRequest;\n})(this);\n" } } diff --git a/cli/tests/testdata/lsp/initialize_params_registry.json b/cli/tests/testdata/lsp/initialize_params_registry.json index 67559ebb31eabd..286f6085f1e4f3 100644 --- a/cli/tests/testdata/lsp/initialize_params_registry.json +++ b/cli/tests/testdata/lsp/initialize_params_registry.json @@ -10,8 +10,10 @@ "cache": null, "codeLens": { "implementations": true, - "references": true + "references": true, + "test": true }, + "config": "", "importMap": null, "lint": true, "suggest": { diff --git a/cli/tests/testdata/lsp/registries/deno-import-intellisense.json b/cli/tests/testdata/lsp/registries/deno-import-intellisense.json index 7fe514dc09db10..5fd87085eecca5 100644 --- a/cli/tests/testdata/lsp/registries/deno-import-intellisense.json +++ b/cli/tests/testdata/lsp/registries/deno-import-intellisense.json @@ -16,6 +16,7 @@ }, { "key": "path", + "documentation": "/lsp/registries/doc_${module}_${{version}}_${path}.json", "url": "/lsp/registries/${module}_${{version}}_${path}.json" } ] @@ -30,6 +31,7 @@ }, { "key": "path", + "documentation": "/lsp/registries/doc_${module}_latest_${path}.json", "url": "/lsp/registries/${module}_latest_${path}.json" } ] diff --git a/cli/tests/testdata/lsp/registries/doc_a_latest_mod.ts.json b/cli/tests/testdata/lsp/registries/doc_a_latest_mod.ts.json new file mode 100644 index 00000000000000..522f5b27189a73 --- /dev/null +++ b/cli/tests/testdata/lsp/registries/doc_a_latest_mod.ts.json @@ -0,0 +1,4 @@ +{ + "kind": "markdown", + "value": "**a**\n\nmod.ts" +} diff --git a/cli/tests/testdata/types.out b/cli/tests/testdata/types.out index 9cda650eb789d0..089a9381fe8d00 100644 --- a/cli/tests/testdata/types.out +++ b/cli/tests/testdata/types.out @@ -1,4 +1,3 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. [WILDCARD] declare namespace Deno [WILDCARD] declare var window: Window [WILDCARD] diff --git a/cli/tests/testdata/websocket_server_idletimeout.ts b/cli/tests/testdata/websocket_server_idletimeout.ts new file mode 100644 index 00000000000000..ffd88c3d37594e --- /dev/null +++ b/cli/tests/testdata/websocket_server_idletimeout.ts @@ -0,0 +1,26 @@ +import { assertEquals } from "../../../test_util/std/testing/asserts.ts"; +import { deferred } from "../../../test_util/std/async/deferred.ts"; + +const errorDeferred = deferred(); +const closeDeferred = deferred(); + +const listener = Deno.listen({ port: 4502 }); +console.log("READY"); +const httpConn = Deno.serveHttp(await listener.accept()); +const { request, respondWith } = (await httpConn.nextRequest())!; +const { response, socket } = Deno.upgradeWebSocket(request, { + idleTimeout: 1, +}); +socket.onerror = (e) => { + assertEquals((e as ErrorEvent).message, "No response from ping frame."); + errorDeferred.resolve(); +}; +socket.onclose = (e) => { + assertEquals(e.reason, "No response from ping frame."); + closeDeferred.resolve(); +}; +await respondWith(response); + +await errorDeferred; +await closeDeferred; +listener.close(); diff --git a/cli/tests/testdata/websocketstream_test.ts b/cli/tests/testdata/websocketstream_test.ts index 1198c416417845..b43b901396ed43 100644 --- a/cli/tests/testdata/websocketstream_test.ts +++ b/cli/tests/testdata/websocketstream_test.ts @@ -3,6 +3,7 @@ import { assert, assertEquals, + assertNotEquals, assertRejects, assertThrows, unreachable, @@ -137,3 +138,59 @@ Deno.test("aborting immediately with a primitive as reason throws that primitive (e) => assertEquals(e, "Some string"), ); }); + +Deno.test("headers", async () => { + const listener = Deno.listen({ port: 4501 }); + const promise = (async () => { + const httpConn = Deno.serveHttp(await listener.accept()); + const { request, respondWith } = (await httpConn.nextRequest())!; + assertEquals(request.headers.get("x-some-header"), "foo"); + const { + response, + socket, + } = Deno.upgradeWebSocket(request); + socket.onopen = () => socket.close(); + await respondWith(response); + })(); + + const ws = new WebSocketStream("ws://localhost:4501", { + headers: [["x-some-header", "foo"]], + }); + await promise; + await ws.closed; + listener.close(); +}); + +Deno.test("forbidden headers", async () => { + const forbiddenHeaders = [ + "sec-websocket-accept", + "sec-websocket-extensions", + "sec-websocket-key", + "sec-websocket-protocol", + "sec-websocket-version", + "upgrade", + "connection", + ]; + + const listener = Deno.listen({ port: 4501 }); + const promise = (async () => { + const httpConn = Deno.serveHttp(await listener.accept()); + const { request, respondWith } = (await httpConn.nextRequest())!; + for (const header of request.headers.keys()) { + assertNotEquals(header, "foo"); + } + const { + response, + socket, + } = Deno.upgradeWebSocket(request); + socket.onopen = () => socket.close(); + await respondWith(response); + })(); + + const ws = new WebSocketStream("ws://localhost:4501", { + headers: forbiddenHeaders.map((header) => [header, "foo"]), + }); + await promise; + await ws.closed; + listener.close(); +}); diff --git a/cli/tests/testdata/worker_close_in_wasm_reactions.js b/cli/tests/testdata/worker_close_in_wasm_reactions.js index 2f5ea32d5db936..d87190726d279e 100644 --- a/cli/tests/testdata/worker_close_in_wasm_reactions.js +++ b/cli/tests/testdata/worker_close_in_wasm_reactions.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // https://github.com/denoland/deno/issues/12263 // Test for a panic that happens when a worker is closed in the reactions of a diff --git a/cli/tests/testdata/worker_close_nested.js b/cli/tests/testdata/worker_close_nested.js index fd47a5ae44fcf5..e2eef29f286349 100644 --- a/cli/tests/testdata/worker_close_nested.js +++ b/cli/tests/testdata/worker_close_nested.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Test that closing a worker which has living child workers will automatically // close the children. diff --git a/cli/tests/testdata/worker_close_race.js b/cli/tests/testdata/worker_close_race.js index 6d5bbe2c3aa9ed..d8439c826c7a40 100644 --- a/cli/tests/testdata/worker_close_race.js +++ b/cli/tests/testdata/worker_close_race.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // https://github.com/denoland/deno/issues/11416 // Test for a race condition between a worker's `close()` and the main thread's diff --git a/cli/tests/testdata/worker_drop_handle_race.js b/cli/tests/testdata/worker_drop_handle_race.js index d637ac8c269028..0285b55d2fdc42 100644 --- a/cli/tests/testdata/worker_drop_handle_race.js +++ b/cli/tests/testdata/worker_drop_handle_race.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // https://github.com/denoland/deno/issues/11342 // Test for a panic that happens when the main thread's event loop finishes diff --git a/cli/tests/testdata/workers/close_nested_child.js b/cli/tests/testdata/workers/close_nested_child.js index 627a176aa32c94..15300cb03b2d41 100644 --- a/cli/tests/testdata/workers/close_nested_child.js +++ b/cli/tests/testdata/workers/close_nested_child.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. console.log("Starting the child worker"); diff --git a/cli/tests/testdata/workers/close_nested_parent.js b/cli/tests/testdata/workers/close_nested_parent.js index c528632ce8a5eb..8b3e2cf935e0d5 100644 --- a/cli/tests/testdata/workers/close_nested_parent.js +++ b/cli/tests/testdata/workers/close_nested_parent.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. console.log("Starting the parent worker"); diff --git a/cli/tests/testdata/workers/close_race_worker.js b/cli/tests/testdata/workers/close_race_worker.js index f582a0d99e0f18..7646f3a67c42e5 100644 --- a/cli/tests/testdata/workers/close_race_worker.js +++ b/cli/tests/testdata/workers/close_race_worker.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. setTimeout(() => { self.postMessage(""); diff --git a/cli/tests/testdata/workers/http_worker.js b/cli/tests/testdata/workers/http_worker.js index 34603ed562b17e..43ad5e12cceab2 100644 --- a/cli/tests/testdata/workers/http_worker.js +++ b/cli/tests/testdata/workers/http_worker.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. const listener = Deno.listen({ hostname: "127.0.0.1", port: 4506 }); postMessage("ready"); for await (const conn of listener) { diff --git a/cli/tests/testdata/workers/test.ts b/cli/tests/testdata/workers/test.ts index 1c345f80b7c4f2..43df417fb3e435 100644 --- a/cli/tests/testdata/workers/test.ts +++ b/cli/tests/testdata/workers/test.ts @@ -798,3 +798,32 @@ Deno.test({ worker.terminate(); }, }); + +Deno.test({ + name: "worker Deno.memoryUsage", + fn: async function () { + const w = new Worker( + /** + * Source code + * self.onmessage = function() {self.postMessage(Deno.memoryUsage())} + */ + "data:application/typescript;base64,c2VsZi5vbm1lc3NhZ2UgPSBmdW5jdGlvbigpIHtzZWxmLnBvc3RNZXNzYWdlKERlbm8ubWVtb3J5VXNhZ2UoKSl9", + { type: "module", name: "tsWorker", deno: true }, + ); + + w.postMessage(null); + + const memoryUsagePromise = deferred(); + w.onmessage = function (evt) { + memoryUsagePromise.resolve(evt.data); + }; + + assertEquals( + Object.keys( + await memoryUsagePromise as unknown as Record, + ), + ["rss", "heapTotal", "heapUsed", "external"], + ); + w.terminate(); + }, +}); diff --git a/cli/tests/unit/signal_test.ts b/cli/tests/unit/signal_test.ts index 31562c99a605f3..b67dc96686f9db 100644 --- a/cli/tests/unit/signal_test.ts +++ b/cli/tests/unit/signal_test.ts @@ -203,3 +203,37 @@ Deno.test( }); }, ); + +Deno.test( + { + ignore: Deno.build.os === "windows", + permissions: { run: true }, + }, + function signalForbiddenSignalTest() { + assertThrows( + () => Deno.addSignalListener("SIGKILL", () => {}), + TypeError, + "Binding to signal 'SIGKILL' is not allowed", + ); + assertThrows( + () => Deno.addSignalListener("SIGSTOP", () => {}), + TypeError, + "Binding to signal 'SIGSTOP' is not allowed", + ); + assertThrows( + () => Deno.addSignalListener("SIGILL", () => {}), + TypeError, + "Binding to signal 'SIGILL' is not allowed", + ); + assertThrows( + () => Deno.addSignalListener("SIGFPE", () => {}), + TypeError, + "Binding to signal 'SIGFPE' is not allowed", + ); + assertThrows( + () => Deno.addSignalListener("SIGSEGV", () => {}), + TypeError, + "Binding to signal 'SIGSEGV' is not allowed", + ); + }, +); diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts index 80af8fdfc791c3..85c59717c10d8a 100644 --- a/cli/tests/unit/test_util.ts +++ b/cli/tests/unit/test_util.ts @@ -1,6 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert } from "../../../test_util/std/testing/asserts.ts"; import * as colors from "../../../test_util/std/fmt/colors.ts"; export { colors }; import { resolve } from "../../../test_util/std/path/mod.ts"; diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 2d101e9750c45d..926ed6b6c18cc0 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -1388,8 +1388,6 @@ Deno.test(async function testImportEcSpkiPkcs8() { for ( const hash of [/*"SHA-1", */ "SHA-256" /*"SHA-384", "SHA-512"*/] ) { - console.log(hash); - const signatureECDSA = await subtle.sign( { name: "ECDSA", hash }, privateKeyECDSA, @@ -1420,27 +1418,146 @@ Deno.test(async function testImportEcSpkiPkcs8() { } }); -Deno.test(async function testBase64Forgiving() { - const keyData = `{ - "kty": "oct", - "k": "xxx", - "alg": "HS512", - "key_ops": ["sign", "verify"], - "ext": true - }`; +Deno.test(async function testAesGcmEncrypt() { + const key = await crypto.subtle.importKey( + "raw", + new Uint8Array(16), + { name: "AES-GCM", length: 256 }, + true, + ["encrypt", "decrypt"], + ); + // deno-fmt-ignore + const iv = new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11]); + const data = new Uint8Array([1, 2, 3]); + + const cipherText = await crypto.subtle.encrypt( + { name: "AES-GCM", iv, additionalData: new Uint8Array() }, + key, + data, + ); + + assert(cipherText instanceof ArrayBuffer); + assertEquals(cipherText.byteLength, 19); + assertEquals( + new Uint8Array(cipherText), + // deno-fmt-ignore + new Uint8Array([50,223,112,178,166,156,255,110,125,138,95,141,82,47,14,164,134,247,22]), + ); +}); + +async function roundTripSecretJwk( + jwk: JsonWebKey, + algId: AlgorithmIdentifier | HmacImportParams, + ops: KeyUsage[], + validateKeys: ( + key: CryptoKey, + originalJwk: JsonWebKey, + exportedJwk: JsonWebKey, + ) => void, +) { const key = await crypto.subtle.importKey( "jwk", - JSON.parse(keyData), - { name: "HMAC", hash: "SHA-512" }, + jwk, + algId, true, - ["sign", "verify"], + ops, ); assert(key instanceof CryptoKey); assertEquals(key.type, "secret"); - assertEquals((key.algorithm as HmacKeyAlgorithm).length, 16); const exportedKey = await crypto.subtle.exportKey("jwk", key); - assertEquals(exportedKey.k, "xxw"); + + validateKeys(key, jwk, exportedKey); +} + +Deno.test(async function testSecretJwkBase64Url() { + // Test 16bits with "overflow" in 3rd pos of 'quartet', no padding + const keyData = `{ + "kty": "oct", + "k": "xxx", + "alg": "HS512", + "key_ops": ["sign", "verify"], + "ext": true + }`; + + await roundTripSecretJwk( + JSON.parse(keyData), + { name: "HMAC", hash: "SHA-512" }, + ["sign", "verify"], + (key, _orig, exp) => { + assertEquals((key.algorithm as HmacKeyAlgorithm).length, 16); + + assertEquals(exp.k, "xxw"); + }, + ); + + // HMAC 128bits with base64url characters (-_) + await roundTripSecretJwk( + { + kty: "oct", + k: "HnZXRyDKn-_G5Fx4JWR1YA", + alg: "HS256", + "key_ops": ["sign", "verify"], + ext: true, + }, + { name: "HMAC", hash: "SHA-256" }, + ["sign", "verify"], + (key, orig, exp) => { + assertEquals((key.algorithm as HmacKeyAlgorithm).length, 128); + + assertEquals(orig.k, exp.k); + }, + ); + + // HMAC 104bits/(12+1) bytes with base64url characters (-_), padding and overflow in 2rd pos of "quartet" + await roundTripSecretJwk( + { + kty: "oct", + k: "a-_AlFa-2-OmEGa_-z==", + alg: "HS384", + "key_ops": ["sign", "verify"], + ext: true, + }, + { name: "HMAC", hash: "SHA-384" }, + ["sign", "verify"], + (key, _orig, exp) => { + assertEquals((key.algorithm as HmacKeyAlgorithm).length, 104); + + assertEquals("a-_AlFa-2-OmEGa_-w", exp.k); + }, + ); + + // AES-CBC 128bits with base64url characters (-_) no padding + await roundTripSecretJwk( + { + kty: "oct", + k: "_u3K_gEjRWf-7cr-ASNFZw", + alg: "A128CBC", + "key_ops": ["encrypt", "decrypt"], + ext: true, + }, + { name: "AES-CBC" }, + ["encrypt", "decrypt"], + (_key, orig, exp) => { + assertEquals(orig.k, exp.k); + }, + ); + + // AES-CBC 128bits of '1' with padding chars + await roundTripSecretJwk( + { + kty: "oct", + k: "_____________________w==", + alg: "A128CBC", + "key_ops": ["encrypt", "decrypt"], + ext: true, + }, + { name: "AES-CBC" }, + ["encrypt", "decrypt"], + (_key, _orig, exp) => { + assertEquals(exp.k, "_____________________w"); + }, + ); }); diff --git a/cli/text_encoding.rs b/cli/text_encoding.rs index 5c638ccd5c8f88..392bab7b832146 100644 --- a/cli/text_encoding.rs +++ b/cli/text_encoding.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use encoding_rs::*; use std::{ diff --git a/cli/tools/coverage.rs b/cli/tools/coverage.rs index c91fca512a0c7d..888344fe1d280a 100644 --- a/cli/tools/coverage.rs +++ b/cli/tools/coverage.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::colors; use crate::emit; diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index 2b47d700835ccd..5b258a5404604b 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::colors; use crate::file_fetcher::File; diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 9172421b5100cb..1d48e70255b9b6 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! This module provides file formatting utilities using //! [`dprint-plugin-typescript`](https://github.com/dprint/dprint-plugin-typescript). @@ -19,12 +19,14 @@ use crate::fs_util::specifier_to_file_path; use crate::fs_util::{collect_files, get_extension, is_supported_ext_fmt}; use crate::text_encoding; use deno_ast::ParsedSource; +use deno_core::anyhow::bail; use deno_core::anyhow::Context; use deno_core::error::generic_error; use deno_core::error::AnyError; use deno_core::futures; use log::debug; use log::info; +use std::borrow::Cow; use std::fs; use std::io::stdin; use std::io::stdout; @@ -157,7 +159,7 @@ pub async fn format( fn format_markdown( file_text: &str, fmt_options: &FmtOptionsConfig, -) -> Result { +) -> Result { let markdown_config = get_resolved_markdown_config(fmt_options); dprint_plugin_markdown::format_text( file_text, @@ -186,7 +188,7 @@ fn format_markdown( if matches!(extension, "json" | "jsonc") { let mut json_config = get_resolved_json_config(fmt_options); json_config.line_width = line_width; - dprint_plugin_json::format_text(text, &json_config) + dprint_plugin_json::format_text(text, &json_config).map(Cow::Owned) } else { let fake_filename = PathBuf::from(format!("deno_fmt_stdin.{}", extension)); @@ -198,13 +200,13 @@ fn format_markdown( text, &codeblock_config, ) + .map(Cow::Owned) } } else { - Ok(text.to_string()) + Ok(Cow::Borrowed(text)) } }, ) - .map_err(|e| e.to_string()) } /// Formats JSON and JSONC using the rules provided by .deno() @@ -213,9 +215,9 @@ fn format_markdown( pub fn format_json( file_text: &str, fmt_options: &FmtOptionsConfig, -) -> Result { +) -> Result { let config = get_resolved_json_config(fmt_options); - dprint_plugin_json::format_text(file_text, &config).map_err(|e| e.to_string()) + dprint_plugin_json::format_text(file_text, &config) } /// Formats a single TS, TSX, JS, JSX, JSONC, JSON, or MD file. @@ -223,7 +225,7 @@ pub fn format_file( file_path: &Path, file_text: &str, fmt_options: FmtOptionsConfig, -) -> Result { +) -> Result { let ext = get_extension(file_path).unwrap_or_else(String::new); if matches!( ext.as_str(), @@ -235,19 +237,17 @@ pub fn format_file( } else { let config = get_resolved_typescript_config(&fmt_options); dprint_plugin_typescript::format_text(file_path, file_text, &config) - .map_err(|e| e.to_string()) } } pub fn format_parsed_source( parsed_source: &ParsedSource, fmt_options: FmtOptionsConfig, -) -> Result { +) -> Result { dprint_plugin_typescript::format_parsed_source( parsed_source, &get_resolved_typescript_config(&fmt_options), ) - .map_err(|e| e.to_string()) } async fn check_source_files( @@ -373,24 +373,18 @@ pub fn format_stdin( ) -> Result<(), AnyError> { let mut source = String::new(); if stdin().read_to_string(&mut source).is_err() { - return Err(generic_error("Failed to read from stdin")); + bail!("Failed to read from stdin"); } let file_path = PathBuf::from(format!("_stdin.{}", fmt_flags.ext)); let fmt_options = resolve_fmt_options(&fmt_flags, fmt_options); - match format_file(&file_path, &source, fmt_options) { - Ok(formatted_text) => { - if fmt_flags.check { - if formatted_text != source { - println!("Not formatted stdin"); - } - } else { - stdout().write_all(formatted_text.as_bytes())?; - } - } - Err(e) => { - return Err(generic_error(e)); + let formatted_text = format_file(&file_path, &source, fmt_options)?; + if fmt_flags.check { + if formatted_text != source { + println!("Not formatted stdin"); } + } else { + stdout().write_all(formatted_text.as_bytes())?; } Ok(()) } diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index 4fbc03c0f00167..b65de26150f24b 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::flags::CheckFlag; use crate::flags::Flags; @@ -729,6 +729,43 @@ mod tests { } } + #[test] + fn install_allow_all() { + let temp_dir = TempDir::new().expect("tempdir fail"); + let bin_dir = temp_dir.path().join("bin"); + std::fs::create_dir(&bin_dir).unwrap(); + + install( + Flags { + allow_all: true, + ..Flags::default() + }, + InstallFlags { + module_url: "http://localhost:4545/echo_server.ts".to_string(), + args: vec![], + name: Some("echo_test".to_string()), + root: Some(temp_dir.path().to_path_buf()), + force: false, + }, + ) + .unwrap(); + + let mut file_path = bin_dir.join("echo_test"); + if cfg!(windows) { + file_path = file_path.with_extension("cmd"); + } + + let content = fs::read_to_string(file_path).unwrap(); + if cfg!(windows) { + assert!(content.contains( + r#""run" "--allow-all" "http://localhost:4545/echo_server.ts""# + )); + } else { + assert!(content + .contains(r#"run --allow-all 'http://localhost:4545/echo_server.ts'"#)); + } + } + #[test] fn install_local_module() { let temp_dir = TempDir::new().expect("tempdir fail"); diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs index 4a7e0115e9a9ec..b103550e254eb0 100644 --- a/cli/tools/lint.rs +++ b/cli/tools/lint.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! This module provides file linting utilities using //! [`deno_lint`](https://github.com/denoland/deno_lint). diff --git a/cli/tools/mod.rs b/cli/tools/mod.rs index 74d6431ed9bba8..83c501ddebd0b8 100644 --- a/cli/tools/mod.rs +++ b/cli/tools/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. pub mod coverage; pub mod doc; diff --git a/cli/tools/repl/channel.rs b/cli/tools/repl/channel.rs index a02f885231bf20..7cc8029057dc8c 100644 --- a/cli/tools/repl/channel.rs +++ b/cli/tools/repl/channel.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::anyhow::anyhow; use deno_core::error::AnyError; diff --git a/cli/tools/repl/editor.rs b/cli/tools/repl/editor.rs index f61e53d3f8608c..30b9fba87b8585 100644 --- a/cli/tools/repl/editor.rs +++ b/cli/tools/repl/editor.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::colors; use deno_ast::swc::parser::error::SyntaxError; diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs index 4c8eec87a4f976..0c9fdbfb0cb216 100644 --- a/cli/tools/repl/mod.rs +++ b/cli/tools/repl/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::proc_state::ProcState; use deno_core::error::AnyError; diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index bc9f215fff27a0..d8276396a5d387 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::ast::transpile; use crate::ast::Diagnostics; diff --git a/cli/tools/standalone.rs b/cli/tools/standalone.rs index 2277c76973fdca..a29b405bad13a2 100644 --- a/cli/tools/standalone.rs +++ b/cli/tools/standalone.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::deno_dir::DenoDir; use crate::flags::CheckFlag; @@ -204,6 +204,7 @@ pub fn compile_to_runtime_flags( subcommand: DenoSubcommand::Run(RunFlags { script: "placeholder".to_string(), }), + allow_all: flags.allow_all, allow_env: flags.allow_env, allow_hrtime: flags.allow_hrtime, allow_net: flags.allow_net, diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 3fd53d88a3edab..e5f03a19c52700 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::ast::Location; use crate::cache; diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index 49c8d742372637..e9bafd9be8242f 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! This module provides feature to upgrade deno executable diff --git a/cli/tsc.rs b/cli/tsc.rs index b5df0c350e9a5a..3dfb975880c480 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::config_file::TsConfig; use crate::diagnostics::Diagnostics; diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index d309956cb34818..45fd7b994647ae 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/cli/unix_util.rs b/cli/unix_util.rs index c48c754a1951cd..927b99d64b0a34 100644 --- a/cli/unix_util.rs +++ b/cli/unix_util.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. /// Raise soft file descriptor limit to hard file descriptor limit. /// This is the difference between `ulimit -n` and `ulimit -n -H`. diff --git a/cli/version.rs b/cli/version.rs index 8d82f513013483..00301c85de2505 100644 --- a/cli/version.rs +++ b/cli/version.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. pub const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH"); pub const TYPESCRIPT: &str = env!("TS_VERSION"); diff --git a/cli/windows_util.rs b/cli/windows_util.rs index 0f30bb04c5f4c0..deab9f38a0b8b8 100644 --- a/cli/windows_util.rs +++ b/cli/windows_util.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. /// Ensures that stdin, stdout, and stderr are open and have valid HANDLEs /// associated with them. There are many places where a `std::fs::File` is diff --git a/core/00_primordials.js b/core/00_primordials.js index d8704a96d80e90..908278e2107aa4 100644 --- a/core/00_primordials.js +++ b/core/00_primordials.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Based on https://github.com/nodejs/node/blob/889ad35d3d41e376870f785b0c1b669cb732013d/lib/internal/per_context/primordials.js // Copyright Joyent, Inc. and other Node contributors. diff --git a/core/01_core.js b/core/01_core.js index c3fd7cf9d9856d..66530f7d5763e0 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/core/02_error.js b/core/02_error.js index 4ec9f7267cdabb..756098738d98d6 100644 --- a/core/02_error.js +++ b/core/02_error.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/core/Cargo.toml b/core/Cargo.toml index b742d6c822f641..624a57d20c0ff4 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,7 +1,7 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_core" -version = "0.112.0" +version = "0.113.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -23,7 +23,7 @@ parking_lot = "0.11.1" pin-project = "1.0.7" serde = { version = "1.0.129", features = ["derive"] } serde_json = { version = "1.0.66", features = ["preserve_order"] } -serde_v8 = { version = "0.23.0", path = "../serde_v8" } +serde_v8 = { version = "0.24.0", path = "../serde_v8" } url = { version = "2.2.2", features = ["serde"] } v8 = "0.37.0" diff --git a/core/async_cancel.rs b/core/async_cancel.rs index 1cdddcdb537758..4c1cded0e16f0f 100644 --- a/core/async_cancel.rs +++ b/core/async_cancel.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::RcLike; use futures::future::FusedFuture; diff --git a/core/async_cell.rs b/core/async_cell.rs index 2e054d739b2108..8798861cf35214 100644 --- a/core/async_cell.rs +++ b/core/async_cell.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::any::type_name; use std::any::Any; diff --git a/core/bindings.rs b/core/bindings.rs index 8aed39ea9e4326..4fd2678fdf4c62 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::error::is_instance_of_error; use crate::modules::get_module_type_from_assertions; diff --git a/core/encode_decode_test.js b/core/encode_decode_test.js index 85f787fdce30c9..94a65dad433a40 100644 --- a/core/encode_decode_test.js +++ b/core/encode_decode_test.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; function assert(cond) { if (!cond) { diff --git a/core/error.rs b/core/error.rs index dd8d95d45ebf3a..a462d3341631ac 100644 --- a/core/error.rs +++ b/core/error.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use anyhow::Error; use std::borrow::Cow; diff --git a/core/error_builder_test.js b/core/error_builder_test.js index 1ee092522e9233..8a3ca0383d5cca 100644 --- a/core/error_builder_test.js +++ b/core/error_builder_test.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. const { core } = Deno; class DOMException { diff --git a/core/examples/disable_ops.rs b/core/examples/disable_ops.rs index 2d28908bf57183..0612845c8cb6d1 100644 --- a/core/examples/disable_ops.rs +++ b/core/examples/disable_ops.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! This example shows you how to define ops in Rust and then call them from //! JavaScript. diff --git a/core/examples/eval_js_value.rs b/core/examples/eval_js_value.rs index 682cbc6088f9d5..920a3c5326a3b8 100644 --- a/core/examples/eval_js_value.rs +++ b/core/examples/eval_js_value.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! This example shows you how to evaluate JavaScript expression and deserialize //! return value into a Rust object. diff --git a/core/examples/fs_module_loader.rs b/core/examples/fs_module_loader.rs index d5fe2c5b8e19f2..4b62b56873f5b0 100644 --- a/core/examples/fs_module_loader.rs +++ b/core/examples/fs_module_loader.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::anyhow::Error; use deno_core::FsModuleLoader; diff --git a/core/examples/hello_world.rs b/core/examples/hello_world.rs index aa822917e19ca2..42c9779f3d0549 100644 --- a/core/examples/hello_world.rs +++ b/core/examples/hello_world.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! This example shows you how to define ops in Rust and then call them from //! JavaScript. diff --git a/core/examples/http_bench_json_ops.js b/core/examples/http_bench_json_ops.js index 12d79a0ced1dba..22e1b468c56804 100644 --- a/core/examples/http_bench_json_ops.js +++ b/core/examples/http_bench_json_ops.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // This is not a real HTTP server. We read blindly one time into 'requestBuf', // then write this fixed 'responseBuf'. The point of this benchmark is to // exercise the event loop in a simple yet semi-realistic way. diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs index f1dfb1039f1fbc..9e60df4a4bd896 100644 --- a/core/examples/http_bench_json_ops.rs +++ b/core/examples/http_bench_json_ops.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::anyhow::Error; use deno_core::AsyncRefCell; use deno_core::AsyncResult; diff --git a/core/flags.rs b/core/flags.rs index 78ed081253e237..119dfb1616d822 100644 --- a/core/flags.rs +++ b/core/flags.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. /// Pass the command line arguments to v8. /// Returns a vector of command line arguments that V8 did not understand. diff --git a/core/gotham_state.rs b/core/gotham_state.rs index 4da8ac27860828..6c637ac503a571 100644 --- a/core/gotham_state.rs +++ b/core/gotham_state.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Forked from Gotham: // https://github.com/gotham-rs/gotham/blob/bcbbf8923789e341b7a0e62c59909428ca4e22e2/gotham/src/state/mod.rs // Copyright 2017 Gotham Project Developers. MIT license. diff --git a/core/inspector.rs b/core/inspector.rs index 03392488544b23..97a04407d3031e 100644 --- a/core/inspector.rs +++ b/core/inspector.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! The documentation for the inspector API is sparse, but these are helpful: //! @@ -13,7 +13,7 @@ use crate::futures::future::select; use crate::futures::future::Either; use crate::futures::future::Future; use crate::futures::prelude::*; -use crate::futures::stream::FuturesUnordered; +use crate::futures::stream::SelectAll; use crate::futures::stream::StreamExt; use crate::futures::task; use crate::futures::task::Context; @@ -226,9 +226,19 @@ impl JsRuntimeInspector { loop { // Do one "handshake" with a newly connected session at a time. if let Some(mut session) = sessions.handshake.take() { - if session.poll_unpin(cx).is_pending() { - sessions.established.push(session); - continue; + let poll_result = session.poll_next_unpin(cx); + match poll_result { + Poll::Pending => { + sessions.established.push(session); + continue; + } + Poll::Ready(Some(session_stream_item)) => { + let (v8_session_ptr, msg) = session_stream_item; + InspectorSession::dispatch_message(v8_session_ptr, msg); + sessions.established.push(session); + continue; + } + Poll::Ready(None) => {} } } @@ -243,7 +253,11 @@ impl JsRuntimeInspector { // Poll established sessions. match sessions.established.poll_next_unpin(cx) { - Poll::Ready(Some(_)) => continue, + Poll::Ready(Some(session_stream_item)) => { + let (v8_session_ptr, msg) = session_stream_item; + InspectorSession::dispatch_message(v8_session_ptr, msg); + continue; + } Poll::Ready(None) => break, Poll::Pending => break, }; @@ -371,7 +385,7 @@ struct SessionContainer { v8_inspector: Rc>>, session_rx: UnboundedReceiver, handshake: Option>, - established: FuturesUnordered>, + established: SelectAll>, } impl SessionContainer { @@ -383,7 +397,7 @@ impl SessionContainer { v8_inspector, session_rx: new_session_rx, handshake: None, - established: FuturesUnordered::new(), + established: SelectAll::new(), } } @@ -411,7 +425,7 @@ impl SessionContainer { v8_inspector: Default::default(), session_rx: rx, handshake: None, - established: FuturesUnordered::new(), + established: SelectAll::new(), } } } @@ -492,7 +506,7 @@ impl task::ArcWake for InspectorWaker { /// eg. Websocket or another set of channels. struct InspectorSession { v8_channel: v8::inspector::ChannelBase, - v8_session: Rc>>, + v8_session: v8::UniqueRef, proxy: InspectorSessionProxy, } @@ -507,13 +521,13 @@ impl InspectorSession { let v8_channel = v8::inspector::ChannelBase::new::(); let mut v8_inspector = v8_inspector_rc.borrow_mut(); let v8_inspector_ptr = v8_inspector.as_mut().unwrap(); - let v8_session = Rc::new(RefCell::new(v8_inspector_ptr.connect( + let v8_session = v8_inspector_ptr.connect( Self::CONTEXT_GROUP_ID, // Todo(piscisaureus): V8Inspector::connect() should require that // the 'v8_channel' argument cannot move. unsafe { &mut *self_ptr }, v8::inspector::StringView::empty(), - ))); + ); Self { v8_channel, @@ -524,12 +538,14 @@ impl InspectorSession { } // Dispatch message to V8 session - #[allow(unused)] - fn dispatch_message(&mut self, msg: Vec) { - let msg = v8::inspector::StringView::from(msg.as_slice()); - let mut v8_session = self.v8_session.borrow_mut(); - let v8_session_ptr = v8_session.as_mut(); - v8_session_ptr.dispatch_protocol_message(msg); + fn dispatch_message( + v8_session_ptr: *mut v8::inspector::V8InspectorSession, + msg: String, + ) { + let msg = v8::inspector::StringView::from(msg.as_bytes()); + unsafe { + (*v8_session_ptr).dispatch_protocol_message(msg); + }; } fn send_message( @@ -547,11 +563,9 @@ impl InspectorSession { pub fn break_on_next_statement(&mut self) { let reason = v8::inspector::StringView::from(&b"debugCommand"[..]); let detail = v8::inspector::StringView::empty(); - self - .v8_session - .borrow_mut() - .as_mut() - .schedule_pause_on_next_statement(reason, detail); + // TODO(bartlomieju): use raw `*mut V8InspectorSession` pointer, as this + // reference may become aliased. + (*self.v8_session).schedule_pause_on_next_statement(reason, detail); } } @@ -582,19 +596,19 @@ impl v8::inspector::ChannelImpl for InspectorSession { fn flush_protocol_notifications(&mut self) {} } -/// This is a "pump" future takes care of receiving messages and dispatching -/// them to the inspector. It resolves when receiver closes. -impl Future for InspectorSession { - type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll { - while let Poll::Ready(maybe_msg) = self.proxy.rx.poll_next_unpin(cx) { +impl Stream for InspectorSession { + type Item = (*mut v8::inspector::V8InspectorSession, String); + + fn poll_next( + self: Pin<&mut Self>, + cx: &mut Context, + ) -> Poll> { + let inner = self.get_mut(); + if let Poll::Ready(maybe_msg) = inner.proxy.rx.poll_next_unpin(cx) { if let Some(msg) = maybe_msg { - let msg = v8::inspector::StringView::from(msg.as_bytes()); - let mut v8_session = self.v8_session.borrow_mut(); - let v8_session_ptr = v8_session.as_mut(); - v8_session_ptr.dispatch_protocol_message(msg); + return Poll::Ready(Some((&mut *inner.v8_session, msg))); } else { - return Poll::Ready(()); + return Poll::Ready(None); } } diff --git a/core/lib.deno_core.d.ts b/core/lib.deno_core.d.ts index 240284c886e85a..e914a50c2a0d29 100644 --- a/core/lib.deno_core.d.ts +++ b/core/lib.deno_core.d.ts @@ -6,7 +6,7 @@ /// declare namespace Deno { - declare namespace core { + namespace core { /** Call an op in Rust, and synchronously receive the result. */ function opSync( opName: string, @@ -104,16 +104,16 @@ declare namespace Deno { ): void; /** Check if there's a scheduled "next tick". */ - function hasNextTickScheduled(): bool; + function hasNextTickScheduled(): boolean; /** Set a value telling the runtime if there are "next ticks" scheduled */ - function setHasNextTickScheduled(value: bool): void; + function setHasNextTickScheduled(value: boolean): void; /** * Set a callback that will be called after resolving ops and "next ticks". */ function setMacrotaskCallback( - cb: () => bool, + cb: () => boolean, ): void; /** @@ -126,7 +126,7 @@ declare namespace Deno { export type PromiseRejectCallback = ( type: number, - promise: Promise, + promise: Promise, reason: any, ) => void; diff --git a/core/lib.rs b/core/lib.rs index acaa273e244a58..2f46c1ffc9afb1 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. mod async_cancel; mod async_cell; mod bindings; diff --git a/core/module_specifier.rs b/core/module_specifier.rs index 0668fd016bf81e..581249f9edf776 100644 --- a/core/module_specifier.rs +++ b/core/module_specifier.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::normalize_path; use std::env::current_dir; diff --git a/core/modules.rs b/core/modules.rs index fc505c31efeacc..d4a0a86ef74fb3 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::bindings; use crate::error::attach_handle_to_error; diff --git a/core/normalize_path.rs b/core/normalize_path.rs index a7facf4db39175..150f30b590831a 100644 --- a/core/normalize_path.rs +++ b/core/normalize_path.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::path::Component; use std::path::Path; diff --git a/core/ops.rs b/core/ops.rs index 6b2c06397f5386..fbdb96fcd70d30 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::error::type_error; use crate::gotham_state::GothamState; diff --git a/core/ops_json.rs b/core/ops_json.rs index b7e8331293d62f..6d8af602fae241 100644 --- a/core/ops_json.rs +++ b/core/ops_json.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::ops::OpCall; use crate::serialize_op_result; diff --git a/core/ops_metrics.rs b/core/ops_metrics.rs index f2e9bc255cc2b8..7e45ec4ea8a5c9 100644 --- a/core/ops_metrics.rs +++ b/core/ops_metrics.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::serde::Serialize; use crate::OpId; use std::cell::RefCell; diff --git a/core/resources.rs b/core/resources.rs index e1b923fd031772..07d4e7041e9b36 100644 --- a/core/resources.rs +++ b/core/resources.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Think of Resources as File Descriptors. They are integers that are allocated // by the privileged side of Deno which refer to various rust objects that need diff --git a/core/runtime.rs b/core/runtime.rs index 1f4a958d99aeaf..fbe97fd93e98c5 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::bindings; use crate::error::attach_handle_to_error; diff --git a/core/serialize_deserialize_test.js b/core/serialize_deserialize_test.js index b71bed0c9a1be4..c1b92a3dfb5610 100644 --- a/core/serialize_deserialize_test.js +++ b/core/serialize_deserialize_test.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; function assert(cond) { diff --git a/ext/broadcast_channel/01_broadcast_channel.js b/ext/broadcast_channel/01_broadcast_channel.js index d1970b1eb6ad4f..d89b19a1b9a6a0 100644 --- a/ext/broadcast_channel/01_broadcast_channel.js +++ b/ext/broadcast_channel/01_broadcast_channel.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. /// diff --git a/ext/broadcast_channel/Cargo.toml b/ext/broadcast_channel/Cargo.toml index 15d0977c0bf6de..088cadd5311b38 100644 --- a/ext/broadcast_channel/Cargo.toml +++ b/ext/broadcast_channel/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_broadcast_channel" -version = "0.24.0" +version = "0.25.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -15,6 +15,6 @@ path = "lib.rs" [dependencies] async-trait = "0.1" -deno_core = { version = "0.112.0", path = "../../core" } +deno_core = { version = "0.113.0", path = "../../core" } tokio = { version = "1.10.1", features = ["full"] } uuid = { version = "0.8.2", features = ["v4"] } diff --git a/ext/broadcast_channel/in_memory_broadcast_channel.rs b/ext/broadcast_channel/in_memory_broadcast_channel.rs index 879a3dbd55b09a..2259957472f5ef 100644 --- a/ext/broadcast_channel/in_memory_broadcast_channel.rs +++ b/ext/broadcast_channel/in_memory_broadcast_channel.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::BroadcastChannel; use async_trait::async_trait; diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs index ad641755810af1..0b0c2495a46671 100644 --- a/ext/broadcast_channel/lib.rs +++ b/ext/broadcast_channel/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. mod in_memory_broadcast_channel; diff --git a/ext/console/01_colors.js b/ext/console/01_colors.js index 3c7384a6c4aecd..138eaa6d90b6f7 100644 --- a/ext/console/01_colors.js +++ b/ext/console/01_colors.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. /// diff --git a/ext/console/02_console.js b/ext/console/02_console.js index 6a80f18670dc0e..435c95187637ad 100644 --- a/ext/console/02_console.js +++ b/ext/console/02_console.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. /// diff --git a/ext/console/Cargo.toml b/ext/console/Cargo.toml index 9cf26e7c417b6d..4af51835b8da4a 100644 --- a/ext/console/Cargo.toml +++ b/ext/console/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_console" -version = "0.30.0" +version = "0.31.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,4 +14,4 @@ description = "Implementation of Console API for Deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.112.0", path = "../../core" } +deno_core = { version = "0.113.0", path = "../../core" } diff --git a/ext/console/lib.rs b/ext/console/lib.rs index 40a428fa965b5a..6c5bba9fa91662 100644 --- a/ext/console/lib.rs +++ b/ext/console/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::include_js_files; use deno_core::Extension; diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js index 5d216dbf458c75..88045741694075 100644 --- a/ext/crypto/00_crypto.js +++ b/ext/crypto/00_crypto.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// @@ -12,7 +12,7 @@ const core = window.Deno.core; const webidl = window.__bootstrap.webidl; const { DOMException } = window.__bootstrap.domException; - const { btoa } = window.__bootstrap.base64; + const { TextEncoder, TextDecoder } = window.__bootstrap.encoding; const { ArrayBuffer, @@ -24,9 +24,9 @@ Int16Array, Int32Array, Int8Array, + JSONParse, + JSONStringify, ObjectAssign, - StringFromCharCode, - StringPrototypeReplace, StringPrototypeToLowerCase, StringPrototypeToUpperCase, Symbol, @@ -57,6 +57,7 @@ ]; const simpleAlgorithmDictionaries = { + AesGcmParams: { iv: "BufferSource", additionalData: "BufferSource" }, RsaHashedKeyGenParams: { hash: "HashAlgorithmIdentifier" }, EcKeyGenParams: {}, HmacKeyGenParams: { hash: "HashAlgorithmIdentifier" }, @@ -126,6 +127,7 @@ "encrypt": { "RSA-OAEP": "RsaOaepParams", "AES-CBC": "AesCbcParams", + "AES-GCM": "AesGcmParams", "AES-CTR": "AesCtrParams", }, "decrypt": { @@ -175,15 +177,6 @@ }, }; - function unpaddedBase64(bytes) { - let binaryString = ""; - for (let i = 0; i < bytes.length; i++) { - binaryString += StringFromCharCode(bytes[i]); - } - const base64String = btoa(binaryString); - return StringPrototypeReplace(base64String, /=/g, ""); - } - // See https://www.w3.org/TR/WebCryptoAPI/#dfn-normalize-an-algorithm // 18.4.4 function normalizeAlgorithm(algorithm, op) { @@ -1269,11 +1262,9 @@ if (format !== "jwk") { bytes = new Uint8Array(exportedKey); } else { - // TODO(@littledivy): Implement JWK. - throw new DOMException( - "Not implemented", - "NotSupportedError", - ); + const jwk = JSONStringify(exportedKey); + + bytes = new TextEncoder("utf-8").encode(jwk); } // 14-15. @@ -1288,7 +1279,17 @@ } else if ( supportedAlgorithms["encrypt"][normalizedAlgorithm.name] !== undefined ) { - return await encrypt(normalizedAlgorithm, wrappingKey, bytes); + return await encrypt( + normalizedAlgorithm, + constructKey( + wrappingKey[_type], + wrappingKey[_extractable], + ["encrypt"], + wrappingKey[_algorithm], + wrappingKey[_handle], + ), + bytes, + ); } else { throw new DOMException( "Algorithm not supported", @@ -1400,7 +1401,13 @@ ) { key = await this.decrypt( normalizedAlgorithm, - unwrappingKey, + constructKey( + unwrappingKey[_type], + unwrappingKey[_extractable], + ["decrypt"], + unwrappingKey[_algorithm], + unwrappingKey[_handle], + ), wrappedKey, ); } else { @@ -1410,14 +1417,14 @@ ); } + let bytes; // 14. - const bytes = key; - if (format == "jwk") { - // TODO(@littledivy): Implement JWK. - throw new DOMException( - "Not implemented", - "NotSupportedError", - ); + if (format !== "jwk") { + bytes = key; + } else { + const utf8 = new TextDecoder("utf-8").decode(key); + + bytes = JSONParse(utf8); } // 15. @@ -1836,16 +1843,18 @@ return data.buffer; } case "jwk": { - // 1-3. + // 1-2. const jwk = { kty: "oct", - // 5. - ext: key[_extractable], - // 6. - "key_ops": key.usages, - k: unpaddedBase64(innerKey.data), }; + // 3. + const data = core.opSync("op_crypto_export_key", { + format: "jwksecret", + algorithm: "AES", + }, innerKey); + ObjectAssign(jwk, data); + // 4. const algorithm = key[_algorithm]; switch (algorithm.length) { @@ -1865,6 +1874,12 @@ ); } + // 5. + jwk.key_ops = key.usages; + + // 6. + jwk.ext = key[_extractable]; + // 7. return jwk; } @@ -3092,11 +3107,18 @@ return bits.buffer; } case "jwk": { - // 1-3. + // 1-2. const jwk = { kty: "oct", - k: unpaddedBase64(innerKey.data), }; + + // 3. + const data = core.opSync("op_crypto_export_key", { + format: "jwksecret", + algorithm: key[_algorithm].name, + }, innerKey); + jwk.k = data.k; + // 4. const algorithm = key[_algorithm]; // 5. @@ -3499,6 +3521,69 @@ // 4. return cipherText.buffer; } + case "AES-GCM": { + normalizedAlgorithm.iv = copyBuffer(normalizedAlgorithm.iv); + + // 1. + if (data.byteLength > (2 ** 39) - 256) { + throw new DOMException( + "Plaintext too large", + "OperationError", + ); + } + + // 2. + // We only support 96-bit nonce for now. + if (normalizedAlgorithm.iv.byteLength !== 12) { + throw new DOMException( + "Initialization vector length not supported", + "NotSupportedError", + ); + } + + // 3. + if (normalizedAlgorithm.additionalData !== undefined) { + if (normalizedAlgorithm.additionalData.byteLength > (2 ** 64) - 1) { + throw new DOMException( + "Additional data too large", + "OperationError", + ); + } + } + + // 4. + if (normalizedAlgorithm.tagLength == undefined) { + normalizedAlgorithm.tagLength = 128; + } else if ( + !ArrayPrototypeIncludes( + [32, 64, 96, 104, 112, 120, 128], + normalizedAlgorithm.tagLength, + ) + ) { + throw new DOMException( + "Invalid tag length", + "OperationError", + ); + } + // 5. + if (normalizedAlgorithm.additionalData) { + normalizedAlgorithm.additionalData = copyBuffer( + normalizedAlgorithm.additionalData, + ); + } + // 6-7. + const cipherText = await core.opAsync("op_crypto_encrypt", { + key: keyData, + algorithm: "AES-GCM", + length: key[_algorithm].length, + iv: normalizedAlgorithm.iv, + additionalData: normalizedAlgorithm.additionalData, + tagLength: normalizedAlgorithm.tagLength, + }, data); + + // 8. + return cipherText.buffer; + } default: throw new DOMException("Not implemented", "NotSupportedError"); } diff --git a/ext/crypto/01_webidl.js b/ext/crypto/01_webidl.js index 04315204f35f9b..39d1eb1e4f819d 100644 --- a/ext/crypto/01_webidl.js +++ b/ext/crypto/01_webidl.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// @@ -398,11 +398,23 @@ }, ]; - webidl.converters.AesDerivedKeyParams = webidl - .createDictionaryConverter("AesDerivedKeyParams", dictAesDerivedKeyParams); - - webidl.converters.AesCbcParams = webidl - .createDictionaryConverter("AesCbcParams", dictAesCbcParams); + const dictAesGcmParams = [ + ...dictAlgorithm, + { + key: "iv", + converter: webidl.converters["BufferSource"], + required: true, + }, + { + key: "tagLength", + converter: (V, opts) => + webidl.converters["unsigned long"](V, { ...opts, enforceRange: true }), + }, + { + key: "additionalData", + converter: webidl.converters["BufferSource"], + }, + ]; const dictAesCtrParams = [ ...dictAlgorithm, @@ -419,6 +431,15 @@ }, ]; + webidl.converters.AesDerivedKeyParams = webidl + .createDictionaryConverter("AesDerivedKeyParams", dictAesDerivedKeyParams); + + webidl.converters.AesCbcParams = webidl + .createDictionaryConverter("AesCbcParams", dictAesCbcParams); + + webidl.converters.AesGcmParams = webidl + .createDictionaryConverter("AesGcmParams", dictAesGcmParams); + webidl.converters.AesCtrParams = webidl .createDictionaryConverter("AesCtrParams", dictAesCtrParams); diff --git a/ext/crypto/Cargo.toml b/ext/crypto/Cargo.toml index 2ab3ff171333e1..a387644bf51872 100644 --- a/ext/crypto/Cargo.toml +++ b/ext/crypto/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_crypto" -version = "0.44.0" +version = "0.45.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -15,11 +15,12 @@ path = "lib.rs" [dependencies] aes = "0.7.5" +aes-gcm = "0.9.4" base64 = "0.13.0" block-modes = "0.8.1" ctr = "0.8.0" -deno_core = { version = "0.112.0", path = "../../core" } -deno_web = { version = "0.61.0", path = "../web" } +deno_core = { version = "0.113.0", path = "../../core" } +deno_web = { version = "0.62.0", path = "../web" } elliptic-curve = { version = "0.10.6", features = ["std", "pem"] } num-traits = "0.2.14" once_cell = "=1.9.0" diff --git a/ext/crypto/encrypt.rs b/ext/crypto/encrypt.rs index 99f4762d0991dc..f1d88438b5f5c8 100644 --- a/ext/crypto/encrypt.rs +++ b/ext/crypto/encrypt.rs @@ -6,6 +6,13 @@ use crate::shared::*; use aes::cipher::NewCipher; use aes::BlockEncrypt; use aes::NewBlockCipher; +use aes_gcm::aead::generic_array::typenum::U12; +use aes_gcm::aes::Aes192; +use aes_gcm::AeadInPlace; +use aes_gcm::Aes128Gcm; +use aes_gcm::Aes256Gcm; +use aes_gcm::NewAead; +use aes_gcm::Nonce; use ctr::Ctr; use block_modes::BlockMode; @@ -53,6 +60,15 @@ pub enum EncryptAlgorithm { iv: Vec, length: usize, }, + #[serde(rename = "AES-GCM", rename_all = "camelCase")] + AesGcm { + #[serde(with = "serde_bytes")] + iv: Vec, + #[serde(with = "serde_bytes")] + additional_data: Option>, + length: usize, + tag_length: usize, + }, #[serde(rename = "AES-CTR", rename_all = "camelCase")] AesCtr { #[serde(with = "serde_bytes")] @@ -74,6 +90,12 @@ pub async fn op_crypto_encrypt( EncryptAlgorithm::AesCbc { iv, length } => { encrypt_aes_cbc(key, length, iv, &data) } + EncryptAlgorithm::AesGcm { + iv, + additional_data, + length, + tag_length, + } => encrypt_aes_gcm(key, length, tag_length, iv, additional_data, &data), EncryptAlgorithm::AesCtr { counter, ctr_length, @@ -89,7 +111,7 @@ fn encrypt_rsa_oaep( hash: ShaHash, label: Vec, data: &[u8], -) -> Result, deno_core::anyhow::Error> { +) -> Result, AnyError> { let label = String::from_utf8_lossy(&label).to_string(); let public_key = key.as_rsa_public_key()?; @@ -129,7 +151,7 @@ fn encrypt_aes_cbc( length: usize, iv: Vec, data: &[u8], -) -> Result, deno_core::anyhow::Error> { +) -> Result, AnyError> { let key = key.as_secret_key()?; let ciphertext = match length { 128 => { @@ -161,6 +183,62 @@ fn encrypt_aes_cbc( Ok(ciphertext) } +fn encrypt_aes_gcm( + key: RawKeyData, + length: usize, + tag_length: usize, + iv: Vec, + additional_data: Option>, + data: &[u8], +) -> Result, AnyError> { + let key = key.as_secret_key()?; + let additional_data = additional_data.unwrap_or_default(); + + // Fixed 96-bit nonce + if iv.len() != 12 { + return Err(type_error("iv length not equal to 12")); + } + + let nonce = Nonce::from_slice(&iv); + + let mut ciphertext = data.to_vec(); + let tag = match length { + 128 => { + let cipher = Aes128Gcm::new_from_slice(key) + .map_err(|_| operation_error("Encryption failed"))?; + cipher + .encrypt_in_place_detached(nonce, &additional_data, &mut ciphertext) + .map_err(|_| operation_error("Encryption failed"))? + } + 192 => { + type Aes192Gcm = aes_gcm::AesGcm; + + let cipher = Aes192Gcm::new_from_slice(key) + .map_err(|_| operation_error("Encryption failed"))?; + cipher + .encrypt_in_place_detached(nonce, &additional_data, &mut ciphertext) + .map_err(|_| operation_error("Encryption failed"))? + } + 256 => { + let cipher = Aes256Gcm::new_from_slice(key) + .map_err(|_| operation_error("Encryption failed"))?; + cipher + .encrypt_in_place_detached(nonce, &additional_data, &mut ciphertext) + .map_err(|_| operation_error("Encryption failed"))? + } + _ => return Err(type_error("invalid length")), + }; + + // Truncated tag to the specified tag length. + // `tag` is fixed to be 16 bytes long and (tag_length / 8) is always <= 16 + let tag = &tag[..(tag_length / 8)]; + + // C | T + ciphertext.extend_from_slice(tag); + + Ok(ciphertext) +} + fn encrypt_aes_ctr_gen( key: &[u8], counter: &[u8], diff --git a/ext/crypto/export_key.rs b/ext/crypto/export_key.rs index 2e74d61f228a90..25faf1791fff04 100644 --- a/ext/crypto/export_key.rs +++ b/ext/crypto/export_key.rs @@ -26,6 +26,7 @@ pub enum ExportKeyFormat { Spki, JwkPublic, JwkPrivate, + JwkSecret, } #[derive(Deserialize)] @@ -37,6 +38,10 @@ pub enum ExportKeyAlgorithm { RsaPss {}, #[serde(rename = "RSA-OAEP")] RsaOaep {}, + #[serde(rename = "AES")] + Aes {}, + #[serde(rename = "HMAC")] + Hmac {}, } #[derive(Serialize)] @@ -44,6 +49,9 @@ pub enum ExportKeyAlgorithm { pub enum ExportKeyResult { Pkcs8(ZeroCopyBuf), Spki(ZeroCopyBuf), + JwkSecret { + k: String, + }, JwkPublicRsa { n: String, e: String, @@ -69,6 +77,9 @@ pub fn op_crypto_export_key( ExportKeyAlgorithm::RsassaPkcs1v15 {} | ExportKeyAlgorithm::RsaPss {} | ExportKeyAlgorithm::RsaOaep {} => export_key_rsa(opts.format, key_data), + ExportKeyAlgorithm::Aes {} | ExportKeyAlgorithm::Hmac {} => { + export_key_symmetric(opts.format, key_data) + } } } @@ -76,6 +87,10 @@ fn uint_to_b64(bytes: UIntBytes) -> String { base64::encode_config(bytes.as_bytes(), base64::URL_SAFE_NO_PAD) } +fn bytes_to_b64(bytes: &[u8]) -> String { + base64::encode_config(bytes, base64::URL_SAFE_NO_PAD) +} + fn export_key_rsa( format: ExportKeyFormat, key_data: RawKeyData, @@ -166,5 +181,22 @@ fn export_key_rsa( qi: uint_to_b64(private_key.coefficient), }) } + _ => Err(unsupported_format()), + } +} + +fn export_key_symmetric( + format: ExportKeyFormat, + key_data: RawKeyData, +) -> Result { + match format { + ExportKeyFormat::JwkSecret => { + let bytes = key_data.as_secret_key()?; + + Ok(ExportKeyResult::JwkSecret { + k: bytes_to_b64(bytes), + }) + } + _ => Err(unsupported_format()), } } diff --git a/ext/crypto/key.rs b/ext/crypto/key.rs index 63d48dd1058918..da73d21916d5d2 100644 --- a/ext/crypto/key.rs +++ b/ext/crypto/key.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use ring::agreement::Algorithm as RingAlgorithm; use ring::digest; diff --git a/ext/crypto/lib.deno_crypto.d.ts b/ext/crypto/lib.deno_crypto.d.ts index f7d735721c5aa4..9c7386dc970638 100644 --- a/ext/crypto/lib.deno_crypto.d.ts +++ b/ext/crypto/lib.deno_crypto.d.ts @@ -62,6 +62,12 @@ interface AesCbcParams extends Algorithm { iv: BufferSource; } +interface AesGcmParams extends Algorithm { + iv: BufferSource; + additionalData?: BufferSource; + tagLength?: number; +} + interface AesCtrParams extends Algorithm { counter: BufferSource; length: number; @@ -248,6 +254,7 @@ interface SubtleCrypto { | AlgorithmIdentifier | RsaOaepParams | AesCbcParams + | AesGcmParams | AesCtrParams, key: CryptoKey, data: BufferSource, diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs index c509cedd7c7b67..8cbd399ee88134 100644 --- a/ext/crypto/lib.rs +++ b/ext/crypto/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::custom_error; use deno_core::error::not_supported; diff --git a/ext/fetch/01_fetch_util.js b/ext/fetch/01_fetch_util.js index 9cf19588b7790e..dad23b6e5f3cce 100644 --- a/ext/fetch/01_fetch_util.js +++ b/ext/fetch/01_fetch_util.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/ext/fetch/20_headers.js b/ext/fetch/20_headers.js index c6b40d5201d95a..b1299fb1ba8d59 100644 --- a/ext/fetch/20_headers.js +++ b/ext/fetch/20_headers.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/fetch/21_formdata.js b/ext/fetch/21_formdata.js index 555e31a69c5450..cc338de729ae61 100644 --- a/ext/fetch/21_formdata.js +++ b/ext/fetch/21_formdata.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/fetch/22_body.js b/ext/fetch/22_body.js index 4291643c0bf4a3..acfd06b0f7c19b 100644 --- a/ext/fetch/22_body.js +++ b/ext/fetch/22_body.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/fetch/22_http_client.js b/ext/fetch/22_http_client.js index 1746122884ad0b..44159de07bd268 100644 --- a/ext/fetch/22_http_client.js +++ b/ext/fetch/22_http_client.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js index b13b8e68732d3f..5783cac9e4fe04 100644 --- a/ext/fetch/23_request.js +++ b/ext/fetch/23_request.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/fetch/23_response.js b/ext/fetch/23_response.js index 8ac12125c44e66..e7b2054185ad62 100644 --- a/ext/fetch/23_response.js +++ b/ext/fetch/23_response.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/fetch/26_fetch.js b/ext/fetch/26_fetch.js index 2282441198ed56..c6fc9197b2d867 100644 --- a/ext/fetch/26_fetch.js +++ b/ext/fetch/26_fetch.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/fetch/Cargo.toml b/ext/fetch/Cargo.toml index b6b7bd63b557f0..2a4cca0d6be2bd 100644 --- a/ext/fetch/Cargo.toml +++ b/ext/fetch/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_fetch" -version = "0.53.0" +version = "0.54.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -16,8 +16,8 @@ path = "lib.rs" [dependencies] bytes = "1.1.0" data-url = "0.1.0" -deno_core = { version = "0.112.0", path = "../../core" } -deno_tls = { version = "0.17.0", path = "../tls" } +deno_core = { version = "0.113.0", path = "../../core" } +deno_tls = { version = "0.18.0", path = "../tls" } dyn-clone = "1" http = "0.2.4" reqwest = { version = "0.11.7", default-features = false, features = ["rustls-tls", "stream", "gzip", "brotli"] } diff --git a/ext/fetch/fs_fetch_handler.rs b/ext/fetch/fs_fetch_handler.rs index 1a8fa3e6f955ab..d0e6da307f3add 100644 --- a/ext/fetch/fs_fetch_handler.rs +++ b/ext/fetch/fs_fetch_handler.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::CancelHandle; use crate::CancelableResponseFuture; diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index a4cff402fb337c..9296fb95c9efc4 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. mod fs_fetch_handler; diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js index 48e2e4f9238b1b..b0bdbe8cfc9065 100644 --- a/ext/ffi/00_ffi.js +++ b/ext/ffi/00_ffi.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/ext/ffi/Cargo.toml b/ext/ffi/Cargo.toml index 08e8de36eda717..5a5f719d745fc5 100644 --- a/ext/ffi/Cargo.toml +++ b/ext/ffi/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_ffi" -version = "0.17.0" +version = "0.18.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,7 +14,7 @@ description = "Dynamic library ffi for deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.112.0", path = "../../core" } +deno_core = { version = "0.113.0", path = "../../core" } dlopen = "0.1.8" libffi = "2.0.0" serde = { version = "1.0.129", features = ["derive"] } diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index 1ae809189e7993..2a6799b5ffe1b5 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -1,7 +1,9 @@ // Copyright 2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::bad_resource_id; +use deno_core::error::generic_error; use deno_core::error::range_error; +use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::include_js_files; use deno_core::op_async; @@ -83,7 +85,17 @@ impl DynamicLibraryResource { Some(symbol) => symbol, None => &name, }; - let fn_ptr = unsafe { self.lib.symbol::<*const c_void>(symbol) }?; + // By default, Err returned by this function does not tell + // which symbol wasn't exported. So we'll modify the error + // message to include the name of symbol. + let fn_ptr = match unsafe { self.lib.symbol::<*const c_void>(symbol) } { + Ok(value) => Ok(value), + Err(err) => Err(generic_error(format!( + "Failed to register symbol {}: {}", + symbol, + err.to_string() + ))), + }?; let ptr = libffi::middle::CodePtr::from_ptr(fn_ptr as _); let cif = libffi::middle::Cif::new( foreign_fn @@ -198,44 +210,44 @@ union NativeValue { } impl NativeValue { - fn new(native_type: NativeType, value: Value) -> Self { - match native_type { + fn new(native_type: NativeType, value: Value) -> Result { + let value = match native_type { NativeType::Void => Self { void_value: () }, NativeType::U8 => Self { - u8_value: value_as_uint::(value), + u8_value: value_as_uint::(value)?, }, NativeType::I8 => Self { - i8_value: value_as_int::(value), + i8_value: value_as_int::(value)?, }, NativeType::U16 => Self { - u16_value: value_as_uint::(value), + u16_value: value_as_uint::(value)?, }, NativeType::I16 => Self { - i16_value: value_as_int::(value), + i16_value: value_as_int::(value)?, }, NativeType::U32 => Self { - u32_value: value_as_uint::(value), + u32_value: value_as_uint::(value)?, }, NativeType::I32 => Self { - i32_value: value_as_int::(value), + i32_value: value_as_int::(value)?, }, NativeType::U64 => Self { - u64_value: value_as_uint::(value), + u64_value: value_as_uint::(value)?, }, NativeType::I64 => Self { - i64_value: value_as_int::(value), + i64_value: value_as_int::(value)?, }, NativeType::USize => Self { - usize_value: value_as_uint::(value), + usize_value: value_as_uint::(value)?, }, NativeType::ISize => Self { - isize_value: value_as_int::(value), + isize_value: value_as_int::(value)?, }, NativeType::F32 => Self { - f32_value: value_as_f32(value), + f32_value: value_as_f32(value)?, }, NativeType::F64 => Self { - f64_value: value_as_f64(value), + f64_value: value_as_f64(value)?, }, NativeType::Pointer => { if value.is_null() { @@ -244,14 +256,13 @@ impl NativeValue { } } else { Self { - pointer: u64::from( - serde_json::from_value::(value) - .expect("Expected ffi arg value to be a tuple of the low and high bits of a pointer address") - ) as *const u8, + pointer: u64::from(serde_json::from_value::(value)?) + as *const u8, } } } - } + }; + Ok(value) } fn buffer(ptr: *const u8) -> Self { @@ -278,28 +289,38 @@ impl NativeValue { } } -fn value_as_uint>(value: Value) -> T { - value - .as_u64() - .and_then(|v| T::try_from(v).ok()) - .expect("Expected ffi arg value to be an unsigned integer") +fn value_as_uint>(value: Value) -> Result { + match value.as_u64().and_then(|v| T::try_from(v).ok()) { + Some(value) => Ok(value), + None => Err(type_error(format!( + "Expected FFI argument to be an unsigned integer, but got {:?}", + value + ))), + } } -fn value_as_int>(value: Value) -> T { - value - .as_i64() - .and_then(|v| T::try_from(v).ok()) - .expect("Expected ffi arg value to be a signed integer") +fn value_as_int>(value: Value) -> Result { + match value.as_i64().and_then(|v| T::try_from(v).ok()) { + Some(value) => Ok(value), + None => Err(type_error(format!( + "Expected FFI argument to be a signed integer, but got {:?}", + value + ))), + } } -fn value_as_f32(value: Value) -> f32 { - value_as_f64(value) as f32 +fn value_as_f32(value: Value) -> Result { + Ok(value_as_f64(value)? as f32) } -fn value_as_f64(value: Value) -> f64 { - value - .as_f64() - .expect("Expected ffi arg value to be a float") +fn value_as_f64(value: Value) -> Result { + match value.as_f64() { + Some(value) => Ok(value), + None => Err(type_error(format!( + "Expected FFI argument to be a double, but got {:?}", + value + ))), + } } #[derive(Serialize, Deserialize, Debug)] @@ -455,22 +476,35 @@ fn ffi_call(args: FfiCallArgs, symbol: &Symbol) -> Result { .map(|buffer| buffer.as_ref().map(|buffer| &buffer[..])) .collect(); - let native_values = symbol + let mut native_values: Vec = vec![]; + + for (&native_type, value) in symbol .parameter_types .iter() .zip(args.parameters.into_iter()) - .map(|(&native_type, value)| { - if let NativeType::Pointer = native_type { - if let Some(idx) = value.as_u64() { - if let Some(&Some(buf)) = buffers.get(idx as usize) { - return NativeValue::buffer(buf.as_ptr()); - } + { + match native_type { + NativeType::Pointer => match value.as_u64() { + Some(idx) => { + let buf = buffers + .get(idx as usize) + .ok_or_else(|| { + generic_error(format!("No buffer present at index {}", idx)) + })? + .unwrap(); + native_values.push(NativeValue::buffer(buf.as_ptr())); + } + _ => { + let value = NativeValue::new(native_type, value)?; + native_values.push(value); } + }, + _ => { + let value = NativeValue::new(native_type, value)?; + native_values.push(value); } - - NativeValue::new(native_type, value) - }) - .collect::>(); + } + } let call_args = symbol .parameter_types diff --git a/ext/http/01_http.js b/ext/http/01_http.js index 7620d154a1d794..f04ba849486132 100644 --- a/ext/http/01_http.js +++ b/ext/http/01_http.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { @@ -17,8 +17,17 @@ const { BadResource, Interrupted } = core; const { ReadableStream } = window.__bootstrap.streams; const abortSignal = window.__bootstrap.abortSignal; - const { WebSocket, _rid, _readyState, _eventLoop, _protocol, _server } = - window.__bootstrap.webSocket; + const { + WebSocket, + _rid, + _readyState, + _eventLoop, + _protocol, + _server, + _idleTimeoutDuration, + _idleTimeoutTimeout, + _serverHandleIdleTimeout, + } = window.__bootstrap.webSocket; const { ArrayPrototypeIncludes, ArrayPrototypePush, @@ -277,6 +286,13 @@ ws.dispatchEvent(event); ws[_eventLoop](); + if (ws[_idleTimeoutDuration]) { + ws.addEventListener( + "close", + () => clearTimeout(ws[_idleTimeoutTimeout]), + ); + } + ws[_serverHandleIdleTimeout](); } } } finally { @@ -378,6 +394,8 @@ setEventTargetData(socket); socket[_server] = true; response[_ws] = socket; + socket[_idleTimeoutDuration] = options.idleTimeout ?? 120; + socket[_idleTimeoutTimeout] = null; return { response, socket }; } diff --git a/ext/http/Cargo.toml b/ext/http/Cargo.toml index aa09dc1439c16c..03d958f2edc6f5 100644 --- a/ext/http/Cargo.toml +++ b/ext/http/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_http" -version = "0.22.0" +version = "0.23.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -16,8 +16,8 @@ path = "lib.rs" [dependencies] base64 = "0.13.0" bytes = "1" -deno_core = { version = "0.112.0", path = "../../core" } -deno_websocket = { version = "0.35.0", path = "../websocket" } +deno_core = { version = "0.113.0", path = "../../core" } +deno_websocket = { version = "0.36.0", path = "../websocket" } hyper = { version = "0.14.9", features = ["server", "stream", "http1", "http2", "runtime"] } ring = "0.16.20" serde = { version = "1.0.129", features = ["derive"] } diff --git a/ext/http/lib.rs b/ext/http/lib.rs index 5a14f845f6444f..24dd77c92b3315 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use bytes::Bytes; use deno_core::error::custom_error; diff --git a/ext/net/01_net.js b/ext/net/01_net.js index 0afdbeebc061be..4a4005954b70f8 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/ext/net/02_tls.js b/ext/net/02_tls.js index 00acd7c96983b0..90f395193cd0c7 100644 --- a/ext/net/02_tls.js +++ b/ext/net/02_tls.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/ext/net/04_net_unstable.js b/ext/net/04_net_unstable.js index ca265bfaa7cdbf..e22c9bf937d61a 100644 --- a/ext/net/04_net_unstable.js +++ b/ext/net/04_net_unstable.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/ext/net/Cargo.toml b/ext/net/Cargo.toml index dfc99b24c23dcf..4d791e930110e2 100644 --- a/ext/net/Cargo.toml +++ b/ext/net/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_net" -version = "0.22.0" +version = "0.23.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,8 +14,8 @@ description = "Networking for Deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.112.0", path = "../../core" } -deno_tls = { version = "0.17.0", path = "../tls" } +deno_core = { version = "0.113.0", path = "../../core" } +deno_tls = { version = "0.18.0", path = "../tls" } log = "0.4.14" serde = { version = "1.0.129", features = ["derive"] } tokio = { version = "1.10.1", features = ["full"] } diff --git a/ext/net/io.rs b/ext/net/io.rs index 2b7aec44605cba..9673a4a896c187 100644 --- a/ext/net/io.rs +++ b/ext/net/io.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::AsyncMutFuture; diff --git a/ext/net/lib.rs b/ext/net/lib.rs index bbbfb3331a8661..15bf8a79aae514 100644 --- a/ext/net/lib.rs +++ b/ext/net/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. pub mod io; pub mod ops; diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 538eab2d9fde03..05085b4018ca89 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::io::TcpStreamResource; use crate::resolve_addr::resolve_addr; diff --git a/ext/net/ops_tls.rs b/ext/net/ops_tls.rs index 036aab5e628cfc..64f1d458ba8a02 100644 --- a/ext/net/ops_tls.rs +++ b/ext/net/ops_tls.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::io::TcpStreamResource; use crate::ops::IpAddr; diff --git a/ext/net/ops_unix.rs b/ext/net/ops_unix.rs index 58bfa05576c252..4f03ecb0a360ab 100644 --- a/ext/net/ops_unix.rs +++ b/ext/net/ops_unix.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::io::UnixStreamResource; use crate::ops::AcceptArgs; diff --git a/ext/net/resolve_addr.rs b/ext/net/resolve_addr.rs index ebf1374d16a8ea..a7bd335e6b5223 100644 --- a/ext/net/resolve_addr.rs +++ b/ext/net/resolve_addr.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use std::net::SocketAddr; diff --git a/ext/timers/01_timers.js b/ext/timers/01_timers.js index 6bed6ba4c947a2..6ef2e6654aa86a 100644 --- a/ext/timers/01_timers.js +++ b/ext/timers/01_timers.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/ext/timers/02_performance.js b/ext/timers/02_performance.js index e09a6f9c0750ac..ce04c8dccc0c4f 100644 --- a/ext/timers/02_performance.js +++ b/ext/timers/02_performance.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/ext/timers/Cargo.toml b/ext/timers/Cargo.toml index a3270b01bc23f1..2a355b254f7006 100644 --- a/ext/timers/Cargo.toml +++ b/ext/timers/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_timers" -version = "0.28.0" +version = "0.29.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,14 +14,14 @@ description = "Timers API implementation for Deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.112.0", path = "../../core" } +deno_core = { version = "0.113.0", path = "../../core" } tokio = { version = "1.10.1", features = ["full"] } [dev-dependencies] -deno_bench_util = { version = "0.24.0", path = "../../bench_util" } -deno_url = { version = "0.30.0", path = "../url" } -deno_web = { version = "0.61.0", path = "../web" } -deno_webidl = { version = "0.30.0", path = "../webidl" } +deno_bench_util = { version = "0.25.0", path = "../../bench_util" } +deno_url = { version = "0.31.0", path = "../url" } +deno_web = { version = "0.62.0", path = "../web" } +deno_webidl = { version = "0.31.0", path = "../webidl" } [[bench]] name = "timers_ops" diff --git a/ext/timers/lib.rs b/ext/timers/lib.rs index 7d0b9ddc13fc5f..63aabe9d4e0ee2 100644 --- a/ext/timers/lib.rs +++ b/ext/timers/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! This module helps deno implement timers and performance APIs. diff --git a/ext/tls/Cargo.toml b/ext/tls/Cargo.toml index 76be009deffa6f..777e4a1222cb58 100644 --- a/ext/tls/Cargo.toml +++ b/ext/tls/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_tls" -version = "0.17.0" +version = "0.18.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,7 +14,7 @@ description = "TLS for Deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.112.0", path = "../../core" } +deno_core = { version = "0.113.0", path = "../../core" } once_cell = "=1.9.0" rustls = { version = "0.20", features = ["dangerous_configuration"] } rustls-native-certs = "0.6.1" diff --git a/ext/tls/lib.rs b/ext/tls/lib.rs index a6775b95d3aaf4..66545ec7dbe127 100644 --- a/ext/tls/lib.rs +++ b/ext/tls/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. pub use rustls; pub use rustls_native_certs; diff --git a/ext/url/00_url.js b/ext/url/00_url.js index b483d8bd518d28..4bba06ce1596db 100644 --- a/ext/url/00_url.js +++ b/ext/url/00_url.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/url/01_urlpattern.js b/ext/url/01_urlpattern.js index b6ff9e40efb06f..19883311f1f986 100644 --- a/ext/url/01_urlpattern.js +++ b/ext/url/01_urlpattern.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/url/Cargo.toml b/ext/url/Cargo.toml index 129cd76d93d8a0..958957c30f1960 100644 --- a/ext/url/Cargo.toml +++ b/ext/url/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_url" -version = "0.30.0" +version = "0.31.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,14 +14,14 @@ description = "URL API implementation for Deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.112.0", path = "../../core" } +deno_core = { version = "0.113.0", path = "../../core" } serde = { version = "1.0.129", features = ["derive"] } serde_repr = "0.1.7" urlpattern = "0.1.2" [dev-dependencies] -deno_bench_util = { version = "0.24.0", path = "../../bench_util" } -deno_webidl = { version = "0.30.0", path = "../webidl" } +deno_bench_util = { version = "0.25.0", path = "../../bench_util" } +deno_webidl = { version = "0.31.0", path = "../webidl" } [[bench]] name = "url_ops" diff --git a/ext/url/lib.rs b/ext/url/lib.rs index 0f8d5c599edc31..a36c1460876fdb 100644 --- a/ext/url/lib.rs +++ b/ext/url/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. mod urlpattern; diff --git a/ext/web/00_infra.js b/ext/web/00_infra.js index 55cd69f7c6700f..40595be768603d 100644 --- a/ext/web/00_infra.js +++ b/ext/web/00_infra.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js index d08a208dbd692d..44aa72abe1f336 100644 --- a/ext/web/01_dom_exception.js +++ b/ext/web/01_dom_exception.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/web/01_mimesniff.js b/ext/web/01_mimesniff.js index 360d1ffe49d337..c6ac7c66c36a3e 100644 --- a/ext/web/01_mimesniff.js +++ b/ext/web/01_mimesniff.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/web/02_event.js b/ext/web/02_event.js index 5ca36300c6c4b1..f9a69c625ea458 100644 --- a/ext/web/02_event.js +++ b/ext/web/02_event.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // This module follows most of the WHATWG Living Standard for the DOM logic. // Many parts of the DOM are not implemented in Deno, but the logic for those diff --git a/ext/web/02_structured_clone.js b/ext/web/02_structured_clone.js index 65a015a6829589..005b668af8ee3a 100644 --- a/ext/web/02_structured_clone.js +++ b/ext/web/02_structured_clone.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/web/03_abort_signal.js b/ext/web/03_abort_signal.js index d46291b1471e78..cd9b11d4bdba01 100644 --- a/ext/web/03_abort_signal.js +++ b/ext/web/03_abort_signal.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; // @ts-check diff --git a/ext/web/04_global_interfaces.js b/ext/web/04_global_interfaces.js index 8117bface27285..fcf8caea5d3983 100644 --- a/ext/web/04_global_interfaces.js +++ b/ext/web/04_global_interfaces.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; // @ts-check diff --git a/ext/web/05_base64.js b/ext/web/05_base64.js index 9c9c23b0f4d3cf..e0c2a36f8ef0e1 100644 --- a/ext/web/05_base64.js +++ b/ext/web/05_base64.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index ed77dde6677eaf..b66d4dca3dea56 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/web/08_text_encoding.js b/ext/web/08_text_encoding.js index d2922a6d45af9d..cf7b7e12f3e652 100644 --- a/ext/web/08_text_encoding.js +++ b/ext/web/08_text_encoding.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// @@ -292,6 +292,9 @@ transform: (chunk, controller) => { try { chunk = webidl.converters.DOMString(chunk); + if (chunk === "") { + return PromiseResolve(); + } if (this.#pendingHighSurrogate !== null) { chunk = this.#pendingHighSurrogate + chunk; } diff --git a/ext/web/09_file.js b/ext/web/09_file.js index 6681f7a13ad5ba..289db22ecdda76 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/web/10_filereader.js b/ext/web/10_filereader.js index 9df0086b481ec7..294d96ebd812c4 100644 --- a/ext/web/10_filereader.js +++ b/ext/web/10_filereader.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/web/11_blob_url.js b/ext/web/11_blob_url.js index fa0ea041c34543..cd9d0929ee0c58 100644 --- a/ext/web/11_blob_url.js +++ b/ext/web/11_blob_url.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/web/12_location.js b/ext/web/12_location.js index 36b70b4e60101e..570eeab0ff0712 100644 --- a/ext/web/12_location.js +++ b/ext/web/12_location.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; /// diff --git a/ext/web/13_message_port.js b/ext/web/13_message_port.js index 1430d8327ad0f9..ef332dd7afd5c3 100644 --- a/ext/web/13_message_port.js +++ b/ext/web/13_message_port.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/web/Cargo.toml b/ext/web/Cargo.toml index 6bbc241c8020b8..138265ab229a4e 100644 --- a/ext/web/Cargo.toml +++ b/ext/web/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_web" -version = "0.61.0" +version = "0.62.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -16,7 +16,7 @@ path = "lib.rs" [dependencies] async-trait = "0.1.51" base64 = "0.13.0" -deno_core = { version = "0.112.0", path = "../../core" } +deno_core = { version = "0.113.0", path = "../../core" } encoding_rs = "0.8.29" serde = "1.0.129" tokio = { version = "1.10.1", features = ["full"] } diff --git a/ext/web/lib.rs b/ext/web/lib.rs index 5f8ab1625bb7e3..281e55e06eb40a 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. mod blob; mod message_port; diff --git a/ext/webgpu/01_webgpu.js b/ext/webgpu/01_webgpu.js index 4b5101bf448359..f1d3eb120a3735 100644 --- a/ext/webgpu/01_webgpu.js +++ b/ext/webgpu/01_webgpu.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/webgpu/02_idl_types.js b/ext/webgpu/02_idl_types.js index 6f871a4ff25135..3c49c18884bb4b 100644 --- a/ext/webgpu/02_idl_types.js +++ b/ext/webgpu/02_idl_types.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check /// diff --git a/ext/webgpu/Cargo.toml b/ext/webgpu/Cargo.toml index 6527bc26dfeabc..706f07f04a5d43 100644 --- a/ext/webgpu/Cargo.toml +++ b/ext/webgpu/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_webgpu" -version = "0.31.0" +version = "0.32.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,7 +14,7 @@ description = "WebGPU implementation for Deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.112.0", path = "../../core" } +deno_core = { version = "0.113.0", path = "../../core" } serde = { version = "1.0.129", features = ["derive"] } tokio = { version = "1.10.1", features = ["full"] } wgpu-core = { version = "0.10.1", features = ["trace"] } diff --git a/ext/webgpu/binding.rs b/ext/webgpu/binding.rs index 4f68c65e92395c..fea99fc163583a 100644 --- a/ext/webgpu/binding.rs +++ b/ext/webgpu/binding.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::ResourceId; diff --git a/ext/webgpu/buffer.rs b/ext/webgpu/buffer.rs index 30818194fab932..3f2c078831ffcd 100644 --- a/ext/webgpu/buffer.rs +++ b/ext/webgpu/buffer.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::type_error; use deno_core::error::AnyError; diff --git a/ext/webgpu/bundle.rs b/ext/webgpu/bundle.rs index 8b2828a30fdf78..7b32c1ecefc1c9 100644 --- a/ext/webgpu/bundle.rs +++ b/ext/webgpu/bundle.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::ResourceId; diff --git a/ext/webgpu/command_encoder.rs b/ext/webgpu/command_encoder.rs index afffe77a0fa60e..cbd57f694e8015 100644 --- a/ext/webgpu/command_encoder.rs +++ b/ext/webgpu/command_encoder.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::ResourceId; diff --git a/ext/webgpu/compute_pass.rs b/ext/webgpu/compute_pass.rs index fe1186c4e66d90..e52db461c7a8bf 100644 --- a/ext/webgpu/compute_pass.rs +++ b/ext/webgpu/compute_pass.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::ResourceId; diff --git a/ext/webgpu/error.rs b/ext/webgpu/error.rs index c821fbf8f0bd0e..18ffdf1a8225ed 100644 --- a/ext/webgpu/error.rs +++ b/ext/webgpu/error.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::ResourceId; use serde::Serialize; diff --git a/ext/webgpu/lib.rs b/ext/webgpu/lib.rs index 0fdd30dd3e0c7e..81f84f6bf934ee 100644 --- a/ext/webgpu/lib.rs +++ b/ext/webgpu/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::include_js_files; diff --git a/ext/webgpu/pipeline.rs b/ext/webgpu/pipeline.rs index 3b0f035404389c..1d22bdba0da19e 100644 --- a/ext/webgpu/pipeline.rs +++ b/ext/webgpu/pipeline.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::ResourceId; diff --git a/ext/webgpu/queue.rs b/ext/webgpu/queue.rs index 79698e7b8e67e2..39bd936037c4af 100644 --- a/ext/webgpu/queue.rs +++ b/ext/webgpu/queue.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::num::NonZeroU32; diff --git a/ext/webgpu/render_pass.rs b/ext/webgpu/render_pass.rs index 125579b52da5b0..780b6ea577e4ed 100644 --- a/ext/webgpu/render_pass.rs +++ b/ext/webgpu/render_pass.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::type_error; use deno_core::error::AnyError; diff --git a/ext/webgpu/sampler.rs b/ext/webgpu/sampler.rs index 95fb167aceb64f..23652cc4702c17 100644 --- a/ext/webgpu/sampler.rs +++ b/ext/webgpu/sampler.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::ResourceId; diff --git a/ext/webgpu/shader.rs b/ext/webgpu/shader.rs index efb67e8f082f8a..2477beceb965e5 100644 --- a/ext/webgpu/shader.rs +++ b/ext/webgpu/shader.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::ResourceId; diff --git a/ext/webgpu/texture.rs b/ext/webgpu/texture.rs index ac3ceda6a1ed53..9b007b34d463e4 100644 --- a/ext/webgpu/texture.rs +++ b/ext/webgpu/texture.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::not_supported; use deno_core::error::AnyError; diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js index 4cbba195c6f3c0..668c141cb04d60 100644 --- a/ext/webidl/00_webidl.js +++ b/ext/webidl/00_webidl.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Adapted from https://github.com/jsdom/webidl-conversions. // Copyright Domenic Denicola. Licensed under BSD-2-Clause License. diff --git a/ext/webidl/Cargo.toml b/ext/webidl/Cargo.toml index d7a7ba8b60b2e8..6e40e2fc49e233 100644 --- a/ext/webidl/Cargo.toml +++ b/ext/webidl/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_webidl" -version = "0.30.0" +version = "0.31.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,4 +14,4 @@ description = "WebIDL implementation for Deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.112.0", path = "../../core" } +deno_core = { version = "0.113.0", path = "../../core" } diff --git a/ext/webidl/lib.rs b/ext/webidl/lib.rs index 6dda68442153a3..ae5e6403a6420c 100644 --- a/ext/webidl/lib.rs +++ b/ext/webidl/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::include_js_files; use deno_core::Extension; diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js index e11a2c55f32857..d04d7dab363598 100644 --- a/ext/websocket/01_websocket.js +++ b/ext/websocket/01_websocket.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; /// @@ -69,7 +69,11 @@ const _binaryType = Symbol("[[binaryType]]"); const _bufferedAmount = Symbol("[[bufferedAmount]]"); const _eventLoop = Symbol("[[eventLoop]]"); + const _server = Symbol("[[server]]"); + const _idleTimeoutDuration = Symbol("[[idleTimeout]]"); + const _idleTimeoutTimeout = Symbol("[[idleTimeoutTimeout]]"); + const _serverHandleIdleTimeout = Symbol("[[serverHandleIdleTimeout]]"); class WebSocket extends EventTarget { [_rid]; @@ -388,6 +392,7 @@ switch (kind) { case "string": { + this[_serverHandleIdleTimeout](); const event = new MessageEvent("message", { data: value, origin: this[_url], @@ -396,6 +401,7 @@ break; } case "binary": { + this[_serverHandleIdleTimeout](); let data; if (this.binaryType === "blob") { @@ -417,9 +423,14 @@ }); break; } + case "pong": { + this[_serverHandleIdleTimeout](); + break; + } case "closed": case "close": { this[_readyState] = CLOSED; + clearTimeout(this[_idleTimeoutTimeout]); const event = new CloseEvent("close", { wasClean: true, @@ -446,6 +457,40 @@ } } } + + [_serverHandleIdleTimeout]() { + if (this[_idleTimeoutDuration]) { + clearTimeout(this[_idleTimeoutTimeout]); + this[_idleTimeoutTimeout] = setTimeout(async () => { + await core.opAsync("op_ws_send", this[_rid], { + kind: "ping", + }); + this[_idleTimeoutTimeout] = setTimeout(async () => { + this[_readyState] = CLOSING; + const reason = "No response from ping frame."; + await core.opAsync("op_ws_close", { + rid: this[_rid], + code: 1001, + reason, + }); + this[_readyState] = CLOSED; + + const errEvent = new ErrorEvent("error", { + message: reason, + }); + this.dispatchEvent(errEvent); + + const event = new CloseEvent("close", { + wasClean: false, + code: 1001, + reason, + }); + this.dispatchEvent(event); + core.tryClose(this[_rid]); + }, (this[_idleTimeoutDuration] / 2) * 1000); + }, (this[_idleTimeoutDuration] / 2) * 1000); + } + } } ObjectDefineProperties(WebSocket, { @@ -477,5 +522,8 @@ _eventLoop, _protocol, _server, + _idleTimeoutDuration, + _idleTimeoutTimeout, + _serverHandleIdleTimeout, }; })(this); diff --git a/ext/websocket/02_websocketstream.js b/ext/websocket/02_websocketstream.js index 8b032d1c208e67..0a14657e9b25ef 100644 --- a/ext/websocket/02_websocketstream.js +++ b/ext/websocket/02_websocketstream.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; /// @@ -39,6 +39,10 @@ key: "signal", converter: webidl.converters.AbortSignal, }, + { + key: "headers", + converter: webidl.converters.HeadersInit, + }, ], ); webidl.converters.WebSocketCloseInfo = webidl.createDictionaryConverter( @@ -139,6 +143,7 @@ ? ArrayPrototypeJoin(options.protocols, ", ") : "", cancelHandle: cancelRid, + headers: [...new Headers(options.headers).entries()], }), (create) => { options.signal?.[remove](abort); diff --git a/ext/websocket/Cargo.toml b/ext/websocket/Cargo.toml index 04dcb91f01d408..5aa9fb1585ed5f 100644 --- a/ext/websocket/Cargo.toml +++ b/ext/websocket/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_websocket" -version = "0.35.0" +version = "0.36.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,8 +14,8 @@ description = "Implementation of WebSocket API for Deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.112.0", path = "../../core" } -deno_tls = { version = "0.17.0", path = "../tls" } +deno_core = { version = "0.113.0", path = "../../core" } +deno_tls = { version = "0.18.0", path = "../tls" } http = "0.2.4" hyper = { version = "0.14.12" } serde = { version = "1.0.129", features = ["derive"] } diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index 4796eddc650132..9358fb4b0b6a6a 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -1,6 +1,7 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::invalid_hostname; +use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::futures::stream::SplitSink; use deno_core::futures::stream::SplitStream; @@ -11,6 +12,7 @@ use deno_core::op_async; use deno_core::op_sync; use deno_core::url; use deno_core::AsyncRefCell; +use deno_core::ByteString; use deno_core::CancelFuture; use deno_core::CancelHandle; use deno_core::Extension; @@ -20,6 +22,8 @@ use deno_core::Resource; use deno_core::ResourceId; use deno_core::ZeroCopyBuf; use deno_tls::create_client_config; +use http::header::HeaderName; +use http::HeaderValue; use http::Method; use http::Request; use http::Uri; @@ -215,6 +219,7 @@ pub struct CreateArgs { url: String, protocols: String, cancel_handle: Option, + headers: Option>, } #[derive(Serialize)] @@ -267,6 +272,30 @@ where request = request.header("Sec-WebSocket-Protocol", args.protocols); } + if let Some(headers) = args.headers { + for (key, value) in headers { + let name = HeaderName::from_bytes(&key) + .map_err(|err| type_error(err.to_string()))?; + let v = HeaderValue::from_bytes(&value) + .map_err(|err| type_error(err.to_string()))?; + + let is_disallowed_header = matches!( + name, + http::header::HOST + | http::header::SEC_WEBSOCKET_ACCEPT + | http::header::SEC_WEBSOCKET_EXTENSIONS + | http::header::SEC_WEBSOCKET_KEY + | http::header::SEC_WEBSOCKET_PROTOCOL + | http::header::SEC_WEBSOCKET_VERSION + | http::header::UPGRADE + | http::header::CONNECTION + ); + if !is_disallowed_header { + request = request.header(name, v); + } + } + } + let request = request.body(())?; let domain = &uri.host().unwrap().to_string(); let port = &uri.port_u16().unwrap_or(match uri.scheme_str() { @@ -347,6 +376,7 @@ pub enum SendValue { Text(String), Binary(ZeroCopyBuf), Pong, + Ping, } pub async fn op_ws_send( @@ -358,6 +388,7 @@ pub async fn op_ws_send( SendValue::Text(text) => Message::Text(text), SendValue::Binary(buf) => Message::Binary(buf.to_vec()), SendValue::Pong => Message::Pong(vec![]), + SendValue::Ping => Message::Ping(vec![]), }; let resource = state diff --git a/ext/webstorage/01_webstorage.js b/ext/webstorage/01_webstorage.js index 4abb64bfcb7e9b..e71aafade9ae4e 100644 --- a/ext/webstorage/01_webstorage.js +++ b/ext/webstorage/01_webstorage.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. /// diff --git a/ext/webstorage/Cargo.toml b/ext/webstorage/Cargo.toml index 5a3e3680d1e3ce..4ad5381fa4afbf 100644 --- a/ext/webstorage/Cargo.toml +++ b/ext/webstorage/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_webstorage" -version = "0.25.0" +version = "0.26.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -14,7 +14,7 @@ description = "Implementation of WebStorage API for Deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.112.0", path = "../../core" } -deno_web = { version = "0.61.0", path = "../web" } +deno_core = { version = "0.113.0", path = "../../core" } +deno_web = { version = "0.62.0", path = "../web" } rusqlite = { version = "0.25.3", features = ["unlock_notify", "bundled"] } serde = { version = "1.0.129", features = ["derive"] } diff --git a/ext/webstorage/lib.rs b/ext/webstorage/lib.rs index 9894c265d39fab..ef053d2b969274 100644 --- a/ext/webstorage/lib.rs +++ b/ext/webstorage/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // NOTE to all: use **cached** prepared statements when interfacing with SQLite. diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index fa6ed4e25572b1..67fc6a82d70610 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,8 +1,8 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "deno_runtime" -version = "0.38.0" +version = "0.39.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" @@ -22,44 +22,44 @@ name = "hello_runtime" path = "examples/hello_runtime.rs" [build-dependencies] -deno_broadcast_channel = { version = "0.24.0", path = "../ext/broadcast_channel" } -deno_console = { version = "0.30.0", path = "../ext/console" } -deno_core = { version = "0.112.0", path = "../core" } -deno_crypto = { version = "0.44.0", path = "../ext/crypto" } -deno_fetch = { version = "0.53.0", path = "../ext/fetch" } -deno_ffi = { version = "0.17.0", path = "../ext/ffi" } -deno_http = { version = "0.22.0", path = "../ext/http" } -deno_net = { version = "0.22.0", path = "../ext/net" } -deno_timers = { version = "0.28.0", path = "../ext/timers" } -deno_tls = { version = "0.17.0", path = "../ext/tls" } -deno_url = { version = "0.30.0", path = "../ext/url" } -deno_web = { version = "0.61.0", path = "../ext/web" } -deno_webgpu = { version = "0.31.0", path = "../ext/webgpu" } -deno_webidl = { version = "0.30.0", path = "../ext/webidl" } -deno_websocket = { version = "0.35.0", path = "../ext/websocket" } -deno_webstorage = { version = "0.25.0", path = "../ext/webstorage" } +deno_broadcast_channel = { version = "0.25.0", path = "../ext/broadcast_channel" } +deno_console = { version = "0.31.0", path = "../ext/console" } +deno_core = { version = "0.113.0", path = "../core" } +deno_crypto = { version = "0.45.0", path = "../ext/crypto" } +deno_fetch = { version = "0.54.0", path = "../ext/fetch" } +deno_ffi = { version = "0.18.0", path = "../ext/ffi" } +deno_http = { version = "0.23.0", path = "../ext/http" } +deno_net = { version = "0.23.0", path = "../ext/net" } +deno_timers = { version = "0.29.0", path = "../ext/timers" } +deno_tls = { version = "0.18.0", path = "../ext/tls" } +deno_url = { version = "0.31.0", path = "../ext/url" } +deno_web = { version = "0.62.0", path = "../ext/web" } +deno_webgpu = { version = "0.32.0", path = "../ext/webgpu" } +deno_webidl = { version = "0.31.0", path = "../ext/webidl" } +deno_websocket = { version = "0.36.0", path = "../ext/websocket" } +deno_webstorage = { version = "0.26.0", path = "../ext/webstorage" } [target.'cfg(windows)'.build-dependencies] winres = "0.1.11" winapi = "0.3.9" [dependencies] -deno_broadcast_channel = { version = "0.24.0", path = "../ext/broadcast_channel" } -deno_console = { version = "0.30.0", path = "../ext/console" } -deno_core = { version = "0.112.0", path = "../core" } -deno_crypto = { version = "0.44.0", path = "../ext/crypto" } -deno_fetch = { version = "0.53.0", path = "../ext/fetch" } -deno_ffi = { version = "0.17.0", path = "../ext/ffi" } -deno_http = { version = "0.22.0", path = "../ext/http" } -deno_net = { version = "0.22.0", path = "../ext/net" } -deno_timers = { version = "0.28.0", path = "../ext/timers" } -deno_tls = { version = "0.17.0", path = "../ext/tls" } -deno_url = { version = "0.30.0", path = "../ext/url" } -deno_web = { version = "0.61.0", path = "../ext/web" } -deno_webgpu = { version = "0.31.0", path = "../ext/webgpu" } -deno_webidl = { version = "0.30.0", path = "../ext/webidl" } -deno_websocket = { version = "0.35.0", path = "../ext/websocket" } -deno_webstorage = { version = "0.25.0", path = "../ext/webstorage" } +deno_broadcast_channel = { version = "0.25.0", path = "../ext/broadcast_channel" } +deno_console = { version = "0.31.0", path = "../ext/console" } +deno_core = { version = "0.113.0", path = "../core" } +deno_crypto = { version = "0.45.0", path = "../ext/crypto" } +deno_fetch = { version = "0.54.0", path = "../ext/fetch" } +deno_ffi = { version = "0.18.0", path = "../ext/ffi" } +deno_http = { version = "0.23.0", path = "../ext/http" } +deno_net = { version = "0.23.0", path = "../ext/net" } +deno_timers = { version = "0.29.0", path = "../ext/timers" } +deno_tls = { version = "0.18.0", path = "../ext/tls" } +deno_url = { version = "0.31.0", path = "../ext/url" } +deno_web = { version = "0.62.0", path = "../ext/web" } +deno_webgpu = { version = "0.32.0", path = "../ext/webgpu" } +deno_webidl = { version = "0.31.0", path = "../ext/webidl" } +deno_websocket = { version = "0.36.0", path = "../ext/websocket" } +deno_webstorage = { version = "0.26.0", path = "../ext/webstorage" } atty = "0.2.14" dlopen = "0.1.8" @@ -76,6 +76,7 @@ once_cell = "=1.9.0" regex = "1.5.4" ring = "0.16.20" serde = { version = "1.0.129", features = ["derive"] } +signal-hook-registry = "1.4.0" sys-info = "0.9.0" termcolor = "1.1.2" tokio = { version = "1.10.1", features = ["full"] } diff --git a/runtime/build.rs b/runtime/build.rs index c83f13070702d7..d1e8517b8c1b0e 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::env; use std::path::Path; diff --git a/runtime/colors.rs b/runtime/colors.rs index c66f528db075c3..f2dbf22bd6eb77 100644 --- a/runtime/colors.rs +++ b/runtime/colors.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use once_cell::sync::Lazy; use std::fmt; diff --git a/runtime/errors.rs b/runtime/errors.rs index c16572b5a9ed5d..0f6df5828c6980 100644 --- a/runtime/errors.rs +++ b/runtime/errors.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. //! There are many types of errors in Deno: //! - AnyError: a generic wrapper that can encapsulate any type of error. diff --git a/runtime/examples/hello_runtime.js b/runtime/examples/hello_runtime.js index e2db3139e6909a..6c5679f094f0e4 100644 --- a/runtime/examples/hello_runtime.js +++ b/runtime/examples/hello_runtime.js @@ -1,3 +1,3 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. console.log("Hello world!"); console.log(Deno); diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs index 5ff482c5641c93..74a9ef398d02df 100644 --- a/runtime/examples/hello_runtime.rs +++ b/runtime/examples/hello_runtime.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::FsModuleLoader; diff --git a/runtime/fs_util.rs b/runtime/fs_util.rs index 695b3be62d6aa6..02bcddd76de290 100644 --- a/runtime/fs_util.rs +++ b/runtime/fs_util.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::anyhow::Context; use deno_core::error::AnyError; diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs index 04a8db959da938..899e128c7397d1 100644 --- a/runtime/inspector_server.rs +++ b/runtime/inspector_server.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use core::convert::Infallible as Never; // Alias for the future `!` type. use deno_core::error::AnyError; diff --git a/runtime/js.rs b/runtime/js.rs index 904377b89603a4..58053ac02fca6d 100644 --- a/runtime/js.rs +++ b/runtime/js.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::Snapshot; use log::debug; diff --git a/runtime/js/01_build.js b/runtime/js/01_build.js index 94b0feea3cb632..57ac13883e641e 100644 --- a/runtime/js/01_build.js +++ b/runtime/js/01_build.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/01_errors.js b/runtime/js/01_errors.js index 844a8872a7b501..ff2cf89fa43e95 100644 --- a/runtime/js/01_errors.js +++ b/runtime/js/01_errors.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/01_version.js b/runtime/js/01_version.js index d25a5175d86961..bd89c6a1ea4fde 100644 --- a/runtime/js/01_version.js +++ b/runtime/js/01_version.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/01_web_util.js b/runtime/js/01_web_util.js index ca3d748269a389..450ad5743d9595 100644 --- a/runtime/js/01_web_util.js +++ b/runtime/js/01_web_util.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js index 97c0adea4e47a1..9b255615ee4e73 100644 --- a/runtime/js/06_util.js +++ b/runtime/js/06_util.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/10_permissions.js b/runtime/js/10_permissions.js index a6884aab9a5cde..f3498b95054848 100644 --- a/runtime/js/10_permissions.js +++ b/runtime/js/10_permissions.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/11_workers.js b/runtime/js/11_workers.js index 8f0095056eb08a..4510004d6976b2 100644 --- a/runtime/js/11_workers.js +++ b/runtime/js/11_workers.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/12_io.js b/runtime/js/12_io.js index 213e0a1eefc03e..2e466c81fbd775 100644 --- a/runtime/js/12_io.js +++ b/runtime/js/12_io.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Interfaces 100% copied from Go. // Documentation liberally lifted from them too. diff --git a/runtime/js/13_buffer.js b/runtime/js/13_buffer.js index fe5e5a22328218..d620920104e5c5 100644 --- a/runtime/js/13_buffer.js +++ b/runtime/js/13_buffer.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // This code has been ported almost directly from Go's src/bytes/buffer.go // Copyright 2009 The Go Authors. All rights reserved. BSD license. diff --git a/runtime/js/30_fs.js b/runtime/js/30_fs.js index feb9f8f54dacc0..bdd575f19f8d48 100644 --- a/runtime/js/30_fs.js +++ b/runtime/js/30_fs.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/30_os.js b/runtime/js/30_os.js index f6bada6a524b70..4c3c188461bf5c 100644 --- a/runtime/js/30_os.js +++ b/runtime/js/30_os.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/40_compiler_api.js b/runtime/js/40_compiler_api.js index 4d5cda398aaa4d..011373eb0ea92b 100644 --- a/runtime/js/40_compiler_api.js +++ b/runtime/js/40_compiler_api.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // @ts-check diff --git a/runtime/js/40_diagnostics.js b/runtime/js/40_diagnostics.js index f4ab67689f1850..a6aba7b2e2dc73 100644 --- a/runtime/js/40_diagnostics.js +++ b/runtime/js/40_diagnostics.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Diagnostic provides an abstraction for advice/errors received from a // compiler, which is strongly influenced by the format of TypeScript diff --git a/runtime/js/40_error_stack.js b/runtime/js/40_error_stack.js index c8f2aff5a52c96..7ed46327312552 100644 --- a/runtime/js/40_error_stack.js +++ b/runtime/js/40_error_stack.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/40_files.js b/runtime/js/40_files.js index dfd4717507b0a0..d7768375b0e103 100644 --- a/runtime/js/40_files.js +++ b/runtime/js/40_files.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/40_fs_events.js b/runtime/js/40_fs_events.js index 8402cb4592abe5..27825eaacf74d0 100644 --- a/runtime/js/40_fs_events.js +++ b/runtime/js/40_fs_events.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/40_http.js b/runtime/js/40_http.js index d68b4f45ce7d0f..9afca0f5b17824 100644 --- a/runtime/js/40_http.js +++ b/runtime/js/40_http.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/40_process.js b/runtime/js/40_process.js index 26d452a4d40661..8d9f402ffae57e 100644 --- a/runtime/js/40_process.js +++ b/runtime/js/40_process.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/40_read_file.js b/runtime/js/40_read_file.js index 5e90b523a6b327..5862454db8f588 100644 --- a/runtime/js/40_read_file.js +++ b/runtime/js/40_read_file.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/40_signals.js b/runtime/js/40_signals.js index 2498c40d727aff..d387b068f36942 100644 --- a/runtime/js/40_signals.js +++ b/runtime/js/40_signals.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index 90da6ddb026e72..118db5db1fe0c6 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/40_tty.js b/runtime/js/40_tty.js index e76d7d90e8fafc..1abed5f2578a39 100644 --- a/runtime/js/40_tty.js +++ b/runtime/js/40_tty.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { diff --git a/runtime/js/40_write_file.js b/runtime/js/40_write_file.js index bb3f91789f031d..8eac953d49af52 100644 --- a/runtime/js/40_write_file.js +++ b/runtime/js/40_write_file.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { const { stat, statSync, chmod, chmodSync } = window.__bootstrap.fs; diff --git a/runtime/js/41_prompt.js b/runtime/js/41_prompt.js index e941461de2efd0..3dc9f4a406eca3 100644 --- a/runtime/js/41_prompt.js +++ b/runtime/js/41_prompt.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { const { stdin } = window.__bootstrap.files; diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 029423ee16572e..f7f5184272f339 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. "use strict"; ((window) => { @@ -29,6 +29,7 @@ makeTempDir: __bootstrap.fs.makeTempDir, makeTempFileSync: __bootstrap.fs.makeTempFileSync, makeTempFile: __bootstrap.fs.makeTempFile, + memoryUsage: core.memoryUsage, mkdirSync: __bootstrap.fs.mkdirSync, mkdir: __bootstrap.fs.mkdir, chdir: __bootstrap.fs.chdir, diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 5a2d2bc3f6865f..3a56d93dc4e6f4 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Removes the `__proto__` for security reasons. This intentionally makes // Deno non compliant with ECMA-262 Annex B.2.2.1 // @@ -588,7 +588,6 @@ delete Object.prototype.__proto__; [internalSymbol]: internals, resources: core.resources, close: core.close, - memoryUsage: core.memoryUsage, ...denoNs, }; ObjectDefineProperties(finalDenoNs, { diff --git a/runtime/lib.rs b/runtime/lib.rs index 58de3725bf1cd3..fef3956eacd1e5 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. pub use deno_broadcast_channel; pub use deno_console; diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs index 4c29898d7babd5..bc84cffb1c0fa4 100644 --- a/runtime/ops/fs.rs +++ b/runtime/ops/fs.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Some deserializer fields are only used on Unix and Windows build fails without it use super::io::StdFileResource; use super::utils::into_string; diff --git a/runtime/ops/fs_events.rs b/runtime/ops/fs_events.rs index 26ad255fd654cd..89ded2731dd886 100644 --- a/runtime/ops/fs_events.rs +++ b/runtime/ops/fs_events.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::permissions::Permissions; use deno_core::error::AnyError; diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs index 89da5f508a6646..61f1a2578cf74a 100644 --- a/runtime/ops/io.rs +++ b/runtime/ops/io.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::not_supported; use deno_core::error::resource_unavailable; diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs index f2f1bdfadeed46..750dfe0f2c6bd8 100644 --- a/runtime/ops/mod.rs +++ b/runtime/ops/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. pub mod fs; pub mod fs_events; diff --git a/runtime/ops/os.rs b/runtime/ops/os.rs index bbc571cc6f23a2..877dbce21499d5 100644 --- a/runtime/ops/os.rs +++ b/runtime/ops/os.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::utils::into_string; use crate::permissions::Permissions; diff --git a/runtime/ops/permissions.rs b/runtime/ops/permissions.rs index d8005a743eb3ee..da82f1fd0f66d5 100644 --- a/runtime/ops/permissions.rs +++ b/runtime/ops/permissions.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::permissions::Permissions; use deno_core::error::custom_error; diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index 0324cb599cf05e..eee266986ffe6d 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::io::ChildStderrResource; use super::io::ChildStdinResource; diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index 6006716efa1636..19228af7802767 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::permissions::Permissions; use deno_core::anyhow::Context; diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index db30c66d884a73..7f897c048b3ed1 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. #[cfg(not(unix))] use deno_core::error::generic_error; #[cfg(not(target_os = "windows"))] @@ -181,8 +181,14 @@ fn op_signal_bind( ) -> Result { super::check_unstable(state, "Deno.signal"); let signo = signal_str_to_int(&sig)?; + if signal_hook_registry::FORBIDDEN.contains(&signo) { + return Err(type_error(format!( + "Binding to signal '{}' is not allowed", + sig + ))); + } let resource = SignalStreamResource { - signal: AsyncRefCell::new(signal(SignalKind::from_raw(signo)).unwrap()), + signal: AsyncRefCell::new(signal(SignalKind::from_raw(signo))?), cancel: Default::default(), }; let rid = state.resource_table.add(resource); diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index 8295af1c79e533..ee6b112bc484fb 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::io::StdFileResource; use deno_core::error::bad_resource_id; diff --git a/runtime/ops/utils.rs b/runtime/ops/utils.rs index 5cbbde00af45a2..d950ae9aba8daa 100644 --- a/runtime/ops/utils.rs +++ b/runtime/ops/utils.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::custom_error; use deno_core::error::AnyError; diff --git a/runtime/ops/web_worker.rs b/runtime/ops/web_worker.rs index 14ebb8d6e7d1d7..e32f2371d80004 100644 --- a/runtime/ops/web_worker.rs +++ b/runtime/ops/web_worker.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. mod sync_fetch; diff --git a/runtime/ops/web_worker/sync_fetch.rs b/runtime/ops/web_worker/sync_fetch.rs index fafe62047272b4..9f146b67e75c43 100644 --- a/runtime/ops/web_worker/sync_fetch.rs +++ b/runtime/ops/web_worker/sync_fetch.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::web_worker::WebWorkerInternalHandle; use crate::web_worker::WebWorkerType; diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index f290b3833bd155..c241e9a54051fc 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::ops::TestingFeaturesEnabled; use crate::permissions::create_child_permissions; diff --git a/runtime/permissions.rs b/runtime/permissions.rs index 1b0d8b914c47a6..d4e1ec4f644e69 100644 --- a/runtime/permissions.rs +++ b/runtime/permissions.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::colors; use crate::fs_util::resolve_from_cwd; diff --git a/runtime/tokio_util.rs b/runtime/tokio_util.rs index 695b9480258cb8..25693ae552a6e9 100644 --- a/runtime/tokio_util.rs +++ b/runtime/tokio_util.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. pub fn create_basic_runtime() -> tokio::runtime::Runtime { tokio::runtime::Builder::new_current_thread() diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index e4c727977db31b..130b13dc0b4936 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::colors; use crate::inspector_server::InspectorServer; use crate::js; diff --git a/runtime/worker.rs b/runtime/worker.rs index 9029ab9674f39a..ad31cacc66f439 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::inspector_server::InspectorServer; use crate::js; diff --git a/serde_v8/Cargo.toml b/serde_v8/Cargo.toml index 80b42f085d9880..4d8b1caa58d008 100644 --- a/serde_v8/Cargo.toml +++ b/serde_v8/Cargo.toml @@ -1,7 +1,7 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "serde_v8" -version = "0.23.0" +version = "0.24.0" authors = ["the Deno authors"] edition = "2021" license = "MIT" diff --git a/serde_v8/benches/de.rs b/serde_v8/benches/de.rs index 83a46eb4e1c838..3b750ac28fcede 100644 --- a/serde_v8/benches/de.rs +++ b/serde_v8/benches/de.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use bencher::{benchmark_group, benchmark_main, Bencher}; use serde::Deserialize; diff --git a/serde_v8/benches/ser.rs b/serde_v8/benches/ser.rs index 1318f9585e66e6..8c87be26137ded 100644 --- a/serde_v8/benches/ser.rs +++ b/serde_v8/benches/ser.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use bencher::{benchmark_group, benchmark_main, Bencher}; use serde::Serialize; diff --git a/serde_v8/examples/basic.rs b/serde_v8/examples/basic.rs index ee5e28fe6a5b27..252e3fc0676d13 100644 --- a/serde_v8/examples/basic.rs +++ b/serde_v8/examples/basic.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use serde::Deserialize; #[derive(Debug, Deserialize)] diff --git a/serde_v8/src/de.rs b/serde_v8/src/de.rs index 44f94b2d6e1e07..69e618cb3a1f98 100644 --- a/serde_v8/src/de.rs +++ b/serde_v8/src/de.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use serde::de::{self, Visitor}; use serde::Deserialize; @@ -375,7 +375,7 @@ impl<'de, 'a, 'b, 's, 'x> de::Deserializer<'de> // Regular struct let obj = v8::Local::::try_from(self.input) .map_err(|_| Error::ExpectedObject)?; - let map = ObjectAccess { + let struct_access = StructAccess { fields, obj, pos: 0, @@ -383,7 +383,7 @@ impl<'de, 'a, 'b, 's, 'x> de::Deserializer<'de> _cache: None, }; - visitor.visit_map(map) + visitor.visit_seq(struct_access) } /// To be compatible with `serde-json`, we expect enums to be: @@ -511,7 +511,7 @@ impl<'de> de::MapAccess<'de> for MapAccess<'_, '_, '_> { } } -struct ObjectAccess<'a, 'b, 's> { +struct StructAccess<'a, 'b, 's> { obj: v8::Local<'a, v8::Object>, scope: &'b mut v8::HandleScope<'s>, fields: &'static [&'static str], @@ -519,57 +519,31 @@ struct ObjectAccess<'a, 'b, 's> { _cache: Option<&'b mut KeyCache>, } -fn str_deserializer(s: &str) -> de::value::StrDeserializer { - de::IntoDeserializer::into_deserializer(s) -} - -impl<'de, 'a, 'b, 's> de::MapAccess<'de> for ObjectAccess<'a, 'b, 's> { +impl<'de> de::SeqAccess<'de> for StructAccess<'_, '_, '_> { type Error = Error; - fn next_key_seed>( - &mut self, - seed: K, - ) -> Result> { - Ok(match self.fields.get(self.pos) { - Some(&field) => Some(seed.deserialize(str_deserializer(field))?), - None => None, - }) - } - - fn next_value_seed>( + fn next_element_seed>( &mut self, - seed: V, - ) -> Result { + seed: T, + ) -> Result> { if self.pos >= self.fields.len() { - return Err(Error::LengthMismatch); + return Ok(None); } - let field = self.fields[self.pos]; + + let pos = self.pos; self.pos += 1; - let key = v8_struct_key(self.scope, field).into(); - let v8_val = self.obj.get(self.scope, key).unwrap(); - let mut deserializer = Deserializer::new(self.scope, v8_val, None); - seed.deserialize(&mut deserializer) - } - fn next_entry_seed< - K: de::DeserializeSeed<'de>, - V: de::DeserializeSeed<'de>, - >( - &mut self, - kseed: K, - vseed: V, - ) -> Result> { - if self.pos >= self.fields.len() { - return Ok(None); + let field = self.fields[pos]; + let key = v8_struct_key(self.scope, field).into(); + let val = self.obj.get(self.scope, key).unwrap(); + let mut deserializer = Deserializer::new(self.scope, val, None); + match seed.deserialize(&mut deserializer) { + Ok(val) => Ok(Some(val)), + // Fallback to Ok(None) for #[serde(Default)] at cost of error quality ... + // TODO(@AaronO): double check that there's no better solution + Err(_) if val.is_undefined() => Ok(None), + Err(e) => Err(e), } - let field = self.fields[self.pos]; - self.pos += 1; - Ok(Some((kseed.deserialize(str_deserializer(field))?, { - let key = v8_struct_key(self.scope, field).into(); - let v8_val = self.obj.get(self.scope, key).unwrap(); - let mut deserializer = Deserializer::new(self.scope, v8_val, None); - vseed.deserialize(&mut deserializer)? - }))) } } diff --git a/serde_v8/src/error.rs b/serde_v8/src/error.rs index 099d8493d9eac9..523dd62b01e765 100644 --- a/serde_v8/src/error.rs +++ b/serde_v8/src/error.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::fmt::{self, Display}; use serde::{de, ser}; diff --git a/serde_v8/src/keys.rs b/serde_v8/src/keys.rs index 783b7aaeffbf67..4811a87f8efdbc 100644 --- a/serde_v8/src/keys.rs +++ b/serde_v8/src/keys.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::collections::HashMap; // KeyCache stores a pool struct keys mapped to v8, diff --git a/serde_v8/src/lib.rs b/serde_v8/src/lib.rs index d97b1f1afe7e80..9d07151950a14a 100644 --- a/serde_v8/src/lib.rs +++ b/serde_v8/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. mod de; mod error; mod keys; diff --git a/serde_v8/src/magic/buffer.rs b/serde_v8/src/magic/buffer.rs index 7a3a3b8ee526d0..80f2f8bc773f43 100644 --- a/serde_v8/src/magic/buffer.rs +++ b/serde_v8/src/magic/buffer.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::fmt; use std::ops::Deref; diff --git a/serde_v8/src/magic/bytestring.rs b/serde_v8/src/magic/bytestring.rs index e90b7528e42ca3..942aec64a08655 100644 --- a/serde_v8/src/magic/bytestring.rs +++ b/serde_v8/src/magic/bytestring.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::ops::{Deref, DerefMut}; diff --git a/serde_v8/src/magic/field.rs b/serde_v8/src/magic/field.rs index e6bb9ee547d755..a188ed0e57e804 100644 --- a/serde_v8/src/magic/field.rs +++ b/serde_v8/src/magic/field.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::error::{Error, Result}; use serde::ser::{Impossible, Serialize, Serializer}; diff --git a/serde_v8/src/magic/mod.rs b/serde_v8/src/magic/mod.rs index 91a09e2f4bcbee..941a69d412223d 100644 --- a/serde_v8/src/magic/mod.rs +++ b/serde_v8/src/magic/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. pub mod buffer; pub mod bytestring; mod field; diff --git a/serde_v8/src/magic/value.rs b/serde_v8/src/magic/value.rs index 05223000767933..7bd9a4059ebbb4 100644 --- a/serde_v8/src/magic/value.rs +++ b/serde_v8/src/magic/value.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::fmt; use std::marker::PhantomData; diff --git a/serde_v8/src/magic/zero_copy_buf.rs b/serde_v8/src/magic/zero_copy_buf.rs index 5c200a8423e051..b536f58598606f 100644 --- a/serde_v8/src/magic/zero_copy_buf.rs +++ b/serde_v8/src/magic/zero_copy_buf.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::cell::Cell; use std::ops::Deref; diff --git a/serde_v8/src/payload.rs b/serde_v8/src/payload.rs index cad9bc868619f5..1450664036a55e 100644 --- a/serde_v8/src/payload.rs +++ b/serde_v8/src/payload.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // TODO: maybe add a Payload type that holds scope & v8::Value // so it can implement Deserialize by itself diff --git a/serde_v8/src/ser.rs b/serde_v8/src/ser.rs index d3853f1a3cb18c..8829b9fc376f73 100644 --- a/serde_v8/src/ser.rs +++ b/serde_v8/src/ser.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use serde::ser; use serde::ser::Serialize; diff --git a/serde_v8/src/serializable.rs b/serde_v8/src/serializable.rs index 6cb638440948b5..7b19ac13ccbac4 100644 --- a/serde_v8/src/serializable.rs +++ b/serde_v8/src/serializable.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::any::TypeId; use std::mem::transmute_copy; diff --git a/serde_v8/src/utils.rs b/serde_v8/src/utils.rs index f18d2269cb7bb5..6305732060a871 100644 --- a/serde_v8/src/utils.rs +++ b/serde_v8/src/utils.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::sync::Once; pub fn js_exec<'s>( diff --git a/serde_v8/tests/de.rs b/serde_v8/tests/de.rs index fee532518635fe..2b85d883979785 100644 --- a/serde_v8/tests/de.rs +++ b/serde_v8/tests/de.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use serde::Deserialize; use serde_v8::utils::{js_exec, v8_do}; @@ -271,3 +271,19 @@ detest!(de_bigint_i64, i64, "BigInt(-(2**59))", -(1 << 59)); defail!(defail_struct, MathOp, "123", |e| e == Err(Error::ExpectedObject)); + +#[derive(PartialEq, Debug, Deserialize)] +pub struct SomeThing { + pub a: String, + #[serde(default)] + pub b: String, +} +detest!( + de_struct_defaults, + SomeThing, + "({ a: 'hello' })", + SomeThing { + a: "hello".into(), + b: "".into() + } +); diff --git a/serde_v8/tests/magic.rs b/serde_v8/tests/magic.rs index 036fc52396ddef..02fa41a68a28d7 100644 --- a/serde_v8/tests/magic.rs +++ b/serde_v8/tests/magic.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use serde::{Deserialize, Serialize}; use serde_v8::utils::{js_exec, v8_do}; diff --git a/serde_v8/tests/ser.rs b/serde_v8/tests/ser.rs index 951c16d5557844..e292e242da5579 100644 --- a/serde_v8/tests/ser.rs +++ b/serde_v8/tests/ser.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use serde::Serialize; use serde_json::json; use serde_v8::utils::{js_exec, v8_do}; diff --git a/test_ffi/Cargo.toml b/test_ffi/Cargo.toml index 8c9be227c4c1b2..cc7708fbc24bf5 100644 --- a/test_ffi/Cargo.toml +++ b/test_ffi/Cargo.toml @@ -1,4 +1,4 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "test_ffi" diff --git a/test_ffi/src/lib.rs b/test_ffi/src/lib.rs index b0206276a35d1c..93b274b4b03d76 100644 --- a/test_ffi/src/lib.rs +++ b/test_ffi/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::thread::sleep; use std::time::Duration; diff --git a/test_ffi/tests/integration_tests.rs b/test_ffi/tests/integration_tests.rs index 02ef9deb6d3e56..44231e35ba6e85 100644 --- a/test_ffi/tests/integration_tests.rs +++ b/test_ffi/tests/integration_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use std::process::Command; use test_util::deno_cmd; @@ -24,6 +24,7 @@ fn basic() { .arg("--allow-ffi") .arg("--allow-read") .arg("--unstable") + .arg("--quiet") .arg("tests/test.js") .env("NO_COLOR", "1") .output() @@ -37,7 +38,6 @@ fn basic() { println!("{:?}", output.status); assert!(output.status.success()); let expected = "\ - dlopen doesn't panic\n\ something\n\ [1, 2, 3, 4, 5, 6, 7, 8]\n\ [1, 2, 3, 4, 5, 6, 7, 8] [9, 10]\n\ diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js index c9cd57e37bcef6..7ebcf4460de96d 100644 --- a/test_ffi/tests/test.js +++ b/test_ffi/tests/test.js @@ -1,6 +1,8 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // deno-lint-ignore-file +import { assertThrows } from "../../test_util/std/testing/asserts.ts"; + const targetDir = Deno.execPath().replace(/[^\/\\]+$/, ""); const [libPrefix, libSuffix] = { darwin: ["lib", "dylib"], @@ -12,11 +14,22 @@ const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`; const resourcesPre = Deno.resources(); // dlopen shouldn't panic -try { +assertThrows(() => { Deno.dlopen("cli/src/main.rs", {}); -} catch (_) { - console.log("dlopen doesn't panic"); -} +}); + +assertThrows( + () => { + Deno.dlopen(libPath, { + non_existent_symbol: { + parameters: [], + result: "void", + }, + }); + }, + Error, + "Failed to register symbol non_existent_symbol", +); const dylib = Deno.dlopen(libPath, { "printSomething": { @@ -85,6 +98,20 @@ console.log(Boolean(dylib.symbols.is_null_ptr(ptr))); console.log(Boolean(dylib.symbols.is_null_ptr(null))); console.log(Boolean(dylib.symbols.is_null_ptr(Deno.UnsafePointer.of(into)))); console.log(dylib.symbols.add_u32(123, 456)); +assertThrows( + () => { + dylib.symbols.add_u32(-1, 100); + }, + TypeError, + "Expected FFI argument to be an unsigned integer, but got Number(-1)", +); +assertThrows( + () => { + dylib.symbols.add_u32(null, 100); + }, + TypeError, + "Expected FFI argument to be an unsigned integer, but got Null", +); console.log(dylib.symbols.add_i32(123, 456)); console.log(dylib.symbols.add_u64(123, 456)); console.log(dylib.symbols.add_i64(123, 456)); diff --git a/test_util/Cargo.toml b/test_util/Cargo.toml index c545fcfea8c432..1bcbd605259551 100644 --- a/test_util/Cargo.toml +++ b/test_util/Cargo.toml @@ -1,4 +1,4 @@ -# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. [package] name = "test_util" diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 79afdde1270721..9eb58d91a6ef4c 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Usage: provide a port as argument to run hyper_hello benchmark server // otherwise this starts multiple servers on many ports for test endpoints. use anyhow::anyhow; diff --git a/test_util/src/lsp.rs b/test_util/src/lsp.rs index 6cc4576d8ab2fe..92dc98102cffb9 100644 --- a/test_util/src/lsp.rs +++ b/test_util/src/lsp.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use super::new_deno_dir; diff --git a/test_util/src/test_server.rs b/test_util/src/test_server.rs index e97378b897967e..8678d92a7a3191 100644 --- a/test_util/src/test_server.rs +++ b/test_util/src/test_server.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. fn main() { test_util::run_all_servers(); diff --git a/tools/build_benchmark_jsons.js b/tools/build_benchmark_jsons.js index 056d22cd6f44b6..d281e70428f5a8 100755 --- a/tools/build_benchmark_jsons.js +++ b/tools/build_benchmark_jsons.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. import { buildPath, existsSync, join } from "./util.js"; const currentDataFile = join(buildPath(), "bench.json"); diff --git a/tools/flamebench.js b/tools/flamebench.js index bd409c86c4dced..35f739e1e797fa 100755 --- a/tools/flamebench.js +++ b/tools/flamebench.js @@ -1,5 +1,5 @@ #!/usr/bin/env -S deno run --unstable --allow-read --allow-run -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. import { join, ROOT_PATH as ROOT } from "./util.js"; async function bashOut(subcmd) { diff --git a/tools/format.js b/tools/format.js index a21bcd64ef906b..392db9c17b5f6a 100755 --- a/tools/format.js +++ b/tools/format.js @@ -1,5 +1,5 @@ #!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. import { getPrebuiltToolPath, getSources, join, ROOT_PATH } from "./util.js"; async function dprint() { diff --git a/tools/lint.js b/tools/lint.js index cb9a6feff2f26e..0bbcb1fe02fd0a 100755 --- a/tools/lint.js +++ b/tools/lint.js @@ -1,5 +1,5 @@ #!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. import { buildMode, getPrebuiltToolPath, diff --git a/tools/util.js b/tools/util.js index 90f72b9efb6b5d..b4742f6054ec82 100644 --- a/tools/util.js +++ b/tools/util.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. import { dirname, fromFileUrl, diff --git a/tools/wpt.ts b/tools/wpt.ts index d56ff34d66a7ce..b582219fac1aee 100755 --- a/tools/wpt.ts +++ b/tools/wpt.ts @@ -20,6 +20,7 @@ import { getExpectation, getExpectFailForCase, getManifest, + inspectBrk, json, ManifestFolder, ManifestTestOptions, @@ -161,6 +162,7 @@ async function run() { test.url, test.options, createReportTestCase(test.expectation), + inspectBrk, ); results.push({ test, result }); reportVariation(result, test.expectation); @@ -312,6 +314,7 @@ async function update() { test.url, test.options, json ? () => {} : createReportTestCase(test.expectation), + inspectBrk, ); results.push({ test, result }); reportVariation(result, test.expectation); diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json index 5d6128cb3897d5..e4b810548cd43c 100644 --- a/tools/wpt/expectation.json +++ b/tools/wpt/expectation.json @@ -212,48 +212,6 @@ "AES-GCM 256-bit key, no additional data, 120-bit tag decryption with altered ciphertext", "AES-GCM 256-bit key, 128-bit tag decryption with altered ciphertext", "AES-GCM 256-bit key, no additional data, 128-bit tag decryption with altered ciphertext", - "AES-GCM 128-bit key, 32-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 32-bit tag without encrypt usage", - "AES-GCM 128-bit key, 64-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 64-bit tag without encrypt usage", - "AES-GCM 128-bit key, 96-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 96-bit tag without encrypt usage", - "AES-GCM 128-bit key, 104-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 104-bit tag without encrypt usage", - "AES-GCM 128-bit key, 112-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 112-bit tag without encrypt usage", - "AES-GCM 128-bit key, 120-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 120-bit tag without encrypt usage", - "AES-GCM 128-bit key, 128-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 128-bit tag without encrypt usage", - "AES-GCM 192-bit key, 32-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 32-bit tag without encrypt usage", - "AES-GCM 192-bit key, 64-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 64-bit tag without encrypt usage", - "AES-GCM 192-bit key, 96-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 96-bit tag without encrypt usage", - "AES-GCM 192-bit key, 104-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 104-bit tag without encrypt usage", - "AES-GCM 192-bit key, 112-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 112-bit tag without encrypt usage", - "AES-GCM 192-bit key, 120-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 120-bit tag without encrypt usage", - "AES-GCM 192-bit key, 128-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 128-bit tag without encrypt usage", - "AES-GCM 256-bit key, 32-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 32-bit tag without encrypt usage", - "AES-GCM 256-bit key, 64-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 64-bit tag without encrypt usage", - "AES-GCM 256-bit key, 96-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 96-bit tag without encrypt usage", - "AES-GCM 256-bit key, 104-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 104-bit tag without encrypt usage", - "AES-GCM 256-bit key, 112-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 112-bit tag without encrypt usage", - "AES-GCM 256-bit key, 120-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 120-bit tag without encrypt usage", - "AES-GCM 256-bit key, 128-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 128-bit tag without encrypt usage", "AES-GCM 128-bit key, 32-bit tag without decrypt usage", "AES-GCM 128-bit key, no additional data, 32-bit tag without decrypt usage", "AES-GCM 128-bit key, 64-bit tag without decrypt usage", @@ -502,48 +460,6 @@ "AES-GCM 256-bit key, no additional data, 120-bit tag decryption with altered ciphertext", "AES-GCM 256-bit key, 128-bit tag decryption with altered ciphertext", "AES-GCM 256-bit key, no additional data, 128-bit tag decryption with altered ciphertext", - "AES-GCM 128-bit key, 32-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 32-bit tag without encrypt usage", - "AES-GCM 128-bit key, 64-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 64-bit tag without encrypt usage", - "AES-GCM 128-bit key, 96-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 96-bit tag without encrypt usage", - "AES-GCM 128-bit key, 104-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 104-bit tag without encrypt usage", - "AES-GCM 128-bit key, 112-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 112-bit tag without encrypt usage", - "AES-GCM 128-bit key, 120-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 120-bit tag without encrypt usage", - "AES-GCM 128-bit key, 128-bit tag without encrypt usage", - "AES-GCM 128-bit key, no additional data, 128-bit tag without encrypt usage", - "AES-GCM 192-bit key, 32-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 32-bit tag without encrypt usage", - "AES-GCM 192-bit key, 64-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 64-bit tag without encrypt usage", - "AES-GCM 192-bit key, 96-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 96-bit tag without encrypt usage", - "AES-GCM 192-bit key, 104-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 104-bit tag without encrypt usage", - "AES-GCM 192-bit key, 112-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 112-bit tag without encrypt usage", - "AES-GCM 192-bit key, 120-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 120-bit tag without encrypt usage", - "AES-GCM 192-bit key, 128-bit tag without encrypt usage", - "AES-GCM 192-bit key, no additional data, 128-bit tag without encrypt usage", - "AES-GCM 256-bit key, 32-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 32-bit tag without encrypt usage", - "AES-GCM 256-bit key, 64-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 64-bit tag without encrypt usage", - "AES-GCM 256-bit key, 96-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 96-bit tag without encrypt usage", - "AES-GCM 256-bit key, 104-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 104-bit tag without encrypt usage", - "AES-GCM 256-bit key, 112-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 112-bit tag without encrypt usage", - "AES-GCM 256-bit key, 120-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 120-bit tag without encrypt usage", - "AES-GCM 256-bit key, 128-bit tag without encrypt usage", - "AES-GCM 256-bit key, no additional data, 128-bit tag without encrypt usage", "AES-GCM 128-bit key, 32-bit tag without decrypt usage", "AES-GCM 128-bit key, no additional data, 32-bit tag without decrypt usage", "AES-GCM 128-bit key, 64-bit tag without decrypt usage", @@ -1203,8 +1119,166 @@ "rsa_pss.https.any.worker.html": true }, "wrapKey_unwrapKey": { - "wrapKey_unwrapKey.https.any.html": false, - "wrapKey_unwrapKey.https.any.worker.html": false + "wrapKey_unwrapKey.https.any.html": [ + "setup", + "Can wrap and unwrap AES-GCM keys as non-extractable using raw and AES-CTR", + "Can wrap and unwrap AES-GCM keys as non-extractable using jwk and AES-CTR", + "Can unwrap AES-GCM non-extractable keys using jwk and AES-CTR", + "Can wrap and unwrap AES-KW keys as non-extractable using raw and AES-CTR", + "Can wrap and unwrap AES-KW keys as non-extractable using jwk and AES-CTR", + "Can unwrap AES-KW non-extractable keys using jwk and AES-CTR", + "Can wrap and unwrap AES-GCM keys as non-extractable using raw and AES-CBC", + "Can wrap and unwrap AES-GCM keys as non-extractable using jwk and AES-CBC", + "Can unwrap AES-GCM non-extractable keys using jwk and AES-CBC", + "Can wrap and unwrap AES-KW keys as non-extractable using raw and AES-CBC", + "Can wrap and unwrap AES-KW keys as non-extractable using jwk and AES-CBC", + "Can unwrap AES-KW non-extractable keys using jwk and AES-CBC", + "Can wrap and unwrap HMAC keys using raw and AES-GCM", + "Can wrap and unwrap HMAC keys as non-extractable using raw and AES-GCM", + "Can wrap and unwrap HMAC keys using jwk and AES-GCM", + "Can wrap and unwrap HMAC keys as non-extractable using jwk and AES-GCM", + "Can unwrap HMAC non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap AES-CTR keys using raw and AES-GCM", + "Can wrap and unwrap AES-CTR keys as non-extractable using raw and AES-GCM", + "Can wrap and unwrap AES-CTR keys using jwk and AES-GCM", + "Can wrap and unwrap AES-CTR keys as non-extractable using jwk and AES-GCM", + "Can unwrap AES-CTR non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap AES-CBC keys using raw and AES-GCM", + "Can wrap and unwrap AES-CBC keys as non-extractable using raw and AES-GCM", + "Can wrap and unwrap AES-CBC keys using jwk and AES-GCM", + "Can wrap and unwrap AES-CBC keys as non-extractable using jwk and AES-GCM", + "Can unwrap AES-CBC non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap AES-GCM keys using raw and AES-GCM", + "Can wrap and unwrap AES-GCM keys as non-extractable using raw and AES-GCM", + "Can wrap and unwrap AES-GCM keys using jwk and AES-GCM", + "Can wrap and unwrap AES-GCM keys as non-extractable using jwk and AES-GCM", + "Can unwrap AES-GCM non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap AES-KW keys using raw and AES-GCM", + "Can wrap and unwrap AES-KW keys as non-extractable using raw and AES-GCM", + "Can wrap and unwrap AES-KW keys using jwk and AES-GCM", + "Can wrap and unwrap AES-KW keys as non-extractable using jwk and AES-GCM", + "Can unwrap AES-KW non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-PSS public key keys using spki and AES-GCM", + "Can wrap and unwrap RSA-PSS public key keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-PSS private key keys using pkcs8 and AES-GCM", + "Can wrap and unwrap RSA-PSS private key keys as non-extractable using pkcs8 and AES-GCM", + "Can wrap and unwrap RSA-PSS private key keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-PSS private key keys as non-extractable using jwk and AES-GCM", + "Can unwrap RSA-PSS private key non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-OAEP public key keys using spki and AES-GCM", + "Can wrap and unwrap RSA-OAEP public key keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-OAEP private key keys using pkcs8 and AES-GCM", + "Can wrap and unwrap RSA-OAEP private key keys as non-extractable using pkcs8 and AES-GCM", + "Can wrap and unwrap RSA-OAEP private key keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-OAEP private key keys as non-extractable using jwk and AES-GCM", + "Can unwrap RSA-OAEP private key non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 public key keys using spki and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 public key keys using jwk and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 private key keys using pkcs8 and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 private key keys as non-extractable using pkcs8 and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 private key keys using jwk and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 private key keys as non-extractable using jwk and AES-GCM", + "Can unwrap RSASSA-PKCS1-v1_5 private key non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap HMAC keys using raw and AES-KW", + "Can wrap and unwrap HMAC keys as non-extractable using raw and AES-KW", + "Can wrap and unwrap AES-CTR keys using raw and AES-KW", + "Can wrap and unwrap AES-CTR keys as non-extractable using raw and AES-KW", + "Can wrap and unwrap AES-CBC keys using raw and AES-KW", + "Can wrap and unwrap AES-CBC keys as non-extractable using raw and AES-KW", + "Can wrap and unwrap AES-GCM keys using raw and AES-KW", + "Can wrap and unwrap AES-GCM keys as non-extractable using raw and AES-KW", + "Can wrap and unwrap AES-KW keys using raw and AES-KW", + "Can wrap and unwrap AES-KW keys as non-extractable using raw and AES-KW", + "Can wrap and unwrap RSA-PSS public key keys using jwk and AES-KW", + "Can wrap and unwrap RSA-OAEP public key keys using jwk and AES-KW", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 public key keys using jwk and AES-KW", + "Can wrap and unwrap AES-GCM keys as non-extractable using raw and RSA-OAEP", + "Can wrap and unwrap AES-GCM keys as non-extractable using jwk and RSA-OAEP", + "Can unwrap AES-GCM non-extractable keys using jwk and RSA-OAEP", + "Can wrap and unwrap AES-KW keys as non-extractable using raw and RSA-OAEP", + "Can wrap and unwrap AES-KW keys as non-extractable using jwk and RSA-OAEP", + "Can unwrap AES-KW non-extractable keys using jwk and RSA-OAEP" + ], + "wrapKey_unwrapKey.https.any.worker.html": [ + "setup", + "Can wrap and unwrap AES-GCM keys as non-extractable using raw and AES-CTR", + "Can wrap and unwrap AES-GCM keys as non-extractable using jwk and AES-CTR", + "Can unwrap AES-GCM non-extractable keys using jwk and AES-CTR", + "Can wrap and unwrap AES-KW keys as non-extractable using raw and AES-CTR", + "Can wrap and unwrap AES-KW keys as non-extractable using jwk and AES-CTR", + "Can unwrap AES-KW non-extractable keys using jwk and AES-CTR", + "Can wrap and unwrap AES-GCM keys as non-extractable using raw and AES-CBC", + "Can wrap and unwrap AES-GCM keys as non-extractable using jwk and AES-CBC", + "Can unwrap AES-GCM non-extractable keys using jwk and AES-CBC", + "Can wrap and unwrap AES-KW keys as non-extractable using raw and AES-CBC", + "Can wrap and unwrap AES-KW keys as non-extractable using jwk and AES-CBC", + "Can unwrap AES-KW non-extractable keys using jwk and AES-CBC", + "Can wrap and unwrap HMAC keys using raw and AES-GCM", + "Can wrap and unwrap HMAC keys as non-extractable using raw and AES-GCM", + "Can wrap and unwrap HMAC keys using jwk and AES-GCM", + "Can wrap and unwrap HMAC keys as non-extractable using jwk and AES-GCM", + "Can unwrap HMAC non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap AES-CTR keys using raw and AES-GCM", + "Can wrap and unwrap AES-CTR keys as non-extractable using raw and AES-GCM", + "Can wrap and unwrap AES-CTR keys using jwk and AES-GCM", + "Can wrap and unwrap AES-CTR keys as non-extractable using jwk and AES-GCM", + "Can unwrap AES-CTR non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap AES-CBC keys using raw and AES-GCM", + "Can wrap and unwrap AES-CBC keys as non-extractable using raw and AES-GCM", + "Can wrap and unwrap AES-CBC keys using jwk and AES-GCM", + "Can wrap and unwrap AES-CBC keys as non-extractable using jwk and AES-GCM", + "Can unwrap AES-CBC non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap AES-GCM keys using raw and AES-GCM", + "Can wrap and unwrap AES-GCM keys as non-extractable using raw and AES-GCM", + "Can wrap and unwrap AES-GCM keys using jwk and AES-GCM", + "Can wrap and unwrap AES-GCM keys as non-extractable using jwk and AES-GCM", + "Can unwrap AES-GCM non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap AES-KW keys using raw and AES-GCM", + "Can wrap and unwrap AES-KW keys as non-extractable using raw and AES-GCM", + "Can wrap and unwrap AES-KW keys using jwk and AES-GCM", + "Can wrap and unwrap AES-KW keys as non-extractable using jwk and AES-GCM", + "Can unwrap AES-KW non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-OAEP public key keys using spki and AES-GCM", + "Can wrap and unwrap RSA-OAEP public key keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-OAEP private key keys using pkcs8 and AES-GCM", + "Can wrap and unwrap RSA-OAEP private key keys as non-extractable using pkcs8 and AES-GCM", + "Can wrap and unwrap RSA-OAEP private key keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-OAEP private key keys as non-extractable using jwk and AES-GCM", + "Can unwrap RSA-OAEP private key non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 public key keys using spki and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 public key keys using jwk and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 private key keys using pkcs8 and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 private key keys as non-extractable using pkcs8 and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 private key keys using jwk and AES-GCM", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 private key keys as non-extractable using jwk and AES-GCM", + "Can unwrap RSASSA-PKCS1-v1_5 private key non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-PSS public key keys using spki and AES-GCM", + "Can wrap and unwrap RSA-PSS public key keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-PSS private key keys using pkcs8 and AES-GCM", + "Can wrap and unwrap RSA-PSS private key keys as non-extractable using pkcs8 and AES-GCM", + "Can wrap and unwrap RSA-PSS private key keys using jwk and AES-GCM", + "Can wrap and unwrap RSA-PSS private key keys as non-extractable using jwk and AES-GCM", + "Can unwrap RSA-PSS private key non-extractable keys using jwk and AES-GCM", + "Can wrap and unwrap HMAC keys using raw and AES-KW", + "Can wrap and unwrap HMAC keys as non-extractable using raw and AES-KW", + "Can wrap and unwrap AES-CTR keys using raw and AES-KW", + "Can wrap and unwrap AES-CTR keys as non-extractable using raw and AES-KW", + "Can wrap and unwrap AES-CBC keys using raw and AES-KW", + "Can wrap and unwrap AES-CBC keys as non-extractable using raw and AES-KW", + "Can wrap and unwrap AES-GCM keys using raw and AES-KW", + "Can wrap and unwrap AES-GCM keys as non-extractable using raw and AES-KW", + "Can wrap and unwrap AES-KW keys using raw and AES-KW", + "Can wrap and unwrap AES-KW keys as non-extractable using raw and AES-KW", + "Can wrap and unwrap RSA-OAEP public key keys using jwk and AES-KW", + "Can wrap and unwrap RSASSA-PKCS1-v1_5 public key keys using jwk and AES-KW", + "Can wrap and unwrap RSA-PSS public key keys using jwk and AES-KW", + "Can wrap and unwrap AES-GCM keys as non-extractable using raw and RSA-OAEP", + "Can wrap and unwrap AES-GCM keys as non-extractable using jwk and RSA-OAEP", + "Can unwrap AES-GCM non-extractable keys using jwk and RSA-OAEP", + "Can wrap and unwrap AES-KW keys as non-extractable using raw and RSA-OAEP", + "Can wrap and unwrap AES-KW keys as non-extractable using jwk and RSA-OAEP", + "Can unwrap AES-KW non-extractable keys using jwk and RSA-OAEP" + ] } }, "console": { diff --git a/tools/wpt/runner.ts b/tools/wpt/runner.ts index 4f4389fd3d4d2b..b7a51af9ddfdc4 100644 --- a/tools/wpt/runner.ts +++ b/tools/wpt/runner.ts @@ -76,6 +76,7 @@ export async function runSingleTest( url: URL, _options: ManifestTestOptions, reporter: (result: TestCaseResult) => void, + inspectBrk: boolean, ): Promise { const bundle = await generateBundle(url); const tempFile = await Deno.makeTempFile({ @@ -88,20 +89,32 @@ export async function runSingleTest( const startTime = new Date().getTime(); + const cmd = [ + denoBinary(), + "run", + ]; + + cmd.push( + "-A", + "--unstable", + ); + + if (inspectBrk) { + cmd.push("--inspect-brk"); + } + + cmd.push( + "--enable-testing-features-do-not-use", + "--location", + url.toString(), + "--cert", + join(ROOT_PATH, `./tools/wpt/certs/cacert.pem`), + tempFile, + "[]", + ); + const proc = Deno.run({ - cmd: [ - denoBinary(), - "run", - "-A", - "--unstable", - "--enable-testing-features-do-not-use", - "--location", - url.toString(), - "--cert", - join(ROOT_PATH, `./tools/wpt/certs/cacert.pem`), - tempFile, - "[]", - ], + cmd, env: { NO_COLOR: "1", }, diff --git a/tools/wpt/testharnessreport.js b/tools/wpt/testharnessreport.js index 24383a5b0cf1f7..3368faa4eb12ed 100644 --- a/tools/wpt/testharnessreport.js +++ b/tools/wpt/testharnessreport.js @@ -1,4 +1,4 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. window.add_result_callback(({ message, name, stack, status }) => { const data = new TextEncoder().encode( diff --git a/tools/wpt/utils.ts b/tools/wpt/utils.ts index 1a7a682be66bf1..a5e7625271df1b 100644 --- a/tools/wpt/utils.ts +++ b/tools/wpt/utils.ts @@ -12,10 +12,11 @@ export const { rebuild, ["--"]: rest, ["auto-config"]: autoConfig, + ["inspect-brk"]: inspectBrk, binary, } = parse(Deno.args, { "--": true, - boolean: ["quiet", "release", "no-interactive"], + boolean: ["quiet", "release", "no-interactive", "inspect-brk"], string: ["json", "wptreport", "binary"], });