José Julián Espina 2 years ago
parent
commit
81680ff5c4
  1. 6
      .github/workflows/rust.yml
  2. 268
      Cargo.lock
  3. 6
      boa_cli/Cargo.toml
  4. 6
      boa_cli/src/main.rs
  5. 2
      boa_engine/Cargo.toml
  6. 10
      boa_engine/src/builtins/array/array_iterator.rs
  7. 120
      boa_engine/src/builtins/array/mod.rs
  8. 20
      boa_engine/src/builtins/array_buffer/mod.rs
  9. 4
      boa_engine/src/builtins/async_function/mod.rs
  10. 18
      boa_engine/src/builtins/async_generator/mod.rs
  11. 4
      boa_engine/src/builtins/async_generator_function/mod.rs
  12. 21
      boa_engine/src/builtins/bigint/mod.rs
  13. 2
      boa_engine/src/builtins/bigint/tests.rs
  14. 16
      boa_engine/src/builtins/boolean/mod.rs
  15. 82
      boa_engine/src/builtins/console/mod.rs
  16. 54
      boa_engine/src/builtins/dataview/mod.rs
  17. 88
      boa_engine/src/builtins/date/mod.rs
  18. 2
      boa_engine/src/builtins/date/tests.rs
  19. 4
      boa_engine/src/builtins/error/aggregate.rs
  20. 4
      boa_engine/src/builtins/error/eval.rs
  21. 8
      boa_engine/src/builtins/error/mod.rs
  22. 4
      boa_engine/src/builtins/error/range.rs
  23. 4
      boa_engine/src/builtins/error/reference.rs
  24. 4
      boa_engine/src/builtins/error/syntax.rs
  25. 8
      boa_engine/src/builtins/error/type.rs
  26. 4
      boa_engine/src/builtins/error/uri.rs
  27. 8
      boa_engine/src/builtins/eval/mod.rs
  28. 4
      boa_engine/src/builtins/function/arguments.rs
  29. 37
      boa_engine/src/builtins/function/mod.rs
  30. 14
      boa_engine/src/builtins/generator/mod.rs
  31. 4
      boa_engine/src/builtins/generator_function/mod.rs
  32. 2
      boa_engine/src/builtins/global_this/mod.rs
  33. 2
      boa_engine/src/builtins/infinity/mod.rs
  34. 44
      boa_engine/src/builtins/intl/collator/mod.rs
  35. 8
      boa_engine/src/builtins/intl/date_time_format.rs
  36. 33
      boa_engine/src/builtins/intl/list_format/mod.rs
  37. 2
      boa_engine/src/builtins/intl/list_format/options.rs
  38. 58
      boa_engine/src/builtins/intl/locale/mod.rs
  39. 4
      boa_engine/src/builtins/intl/locale/options.rs
  40. 25
      boa_engine/src/builtins/intl/locale/tests.rs
  41. 50
      boa_engine/src/builtins/intl/locale/utils.rs
  42. 21
      boa_engine/src/builtins/intl/mod.rs
  43. 18
      boa_engine/src/builtins/intl/options.rs
  44. 8
      boa_engine/src/builtins/intl/segmenter/mod.rs
  45. 12
      boa_engine/src/builtins/iterable/async_from_sync_iterator.rs
  46. 22
      boa_engine/src/builtins/iterable/mod.rs
  47. 18
      boa_engine/src/builtins/json/mod.rs
  48. 10
      boa_engine/src/builtins/map/map_iterator.rs
  49. 40
      boa_engine/src/builtins/map/mod.rs
  50. 204
      boa_engine/src/builtins/math/mod.rs
  51. 6
      boa_engine/src/builtins/mod.rs
  52. 2
      boa_engine/src/builtins/nan/mod.rs
  53. 36
      boa_engine/src/builtins/number/mod.rs
  54. 10
      boa_engine/src/builtins/object/for_in_iterator.rs
  55. 94
      boa_engine/src/builtins/object/mod.rs
  56. 60
      boa_engine/src/builtins/promise/mod.rs
  57. 6
      boa_engine/src/builtins/promise/promise_job.rs
  58. 10
      boa_engine/src/builtins/proxy/mod.rs
  59. 44
      boa_engine/src/builtins/reflect/mod.rs
  60. 56
      boa_engine/src/builtins/regexp/mod.rs
  61. 6
      boa_engine/src/builtins/regexp/regexp_string_iterator.rs
  62. 30
      boa_engine/src/builtins/set/mod.rs
  63. 10
      boa_engine/src/builtins/set/set_iterator.rs
  64. 102
      boa_engine/src/builtins/string/mod.rs
  65. 6
      boa_engine/src/builtins/string/string_iterator.rs
  66. 28
      boa_engine/src/builtins/symbol/mod.rs
  67. 118
      boa_engine/src/builtins/typed_array/mod.rs
  68. 2
      boa_engine/src/builtins/undefined/mod.rs
  69. 10
      boa_engine/src/builtins/uri/mod.rs
  70. 10
      boa_engine/src/builtins/weak/weak_ref.rs
  71. 2
      boa_engine/src/bytecompiler/class.rs
  72. 2
      boa_engine/src/bytecompiler/declaration/declaration_pattern.rs
  73. 4
      boa_engine/src/bytecompiler/expression/assign.rs
  74. 2
      boa_engine/src/bytecompiler/expression/binary.rs
  75. 2
      boa_engine/src/bytecompiler/expression/mod.rs
  76. 2
      boa_engine/src/bytecompiler/expression/object_literal.rs
  77. 2
      boa_engine/src/bytecompiler/expression/unary.rs
  78. 2
      boa_engine/src/bytecompiler/function.rs
  79. 20
      boa_engine/src/bytecompiler/mod.rs
  80. 2
      boa_engine/src/bytecompiler/statement/continue.rs
  81. 2
      boa_engine/src/bytecompiler/statement/loop.rs
  82. 2
      boa_engine/src/bytecompiler/statement/mod.rs
  83. 2
      boa_engine/src/bytecompiler/statement/try.rs
  84. 24
      boa_engine/src/class.rs
  85. 66
      boa_engine/src/context/icu.rs
  86. 2
      boa_engine/src/context/intrinsics.rs
  87. 77
      boa_engine/src/context/mod.rs
  88. 2
      boa_engine/src/environments/compile.rs
  89. 2
      boa_engine/src/environments/runtime.rs
  90. 8
      boa_engine/src/error.rs
  91. 2
      boa_engine/src/job.rs
  92. 4
      boa_engine/src/lib.rs
  93. 58
      boa_engine/src/object/builtins/jsarray.rs
  94. 6
      boa_engine/src/object/builtins/jsarraybuffer.rs
  95. 48
      boa_engine/src/object/builtins/jsdataview.rs
  96. 122
      boa_engine/src/object/builtins/jsdate.rs
  97. 8
      boa_engine/src/object/builtins/jsgenerator.rs
  98. 26
      boa_engine/src/object/builtins/jsmap.rs
  99. 2
      boa_engine/src/object/builtins/jsmap_iterator.rs
  100. 6
      boa_engine/src/object/builtins/jsproxy.rs
  101. Some files were not shown because too many files have changed in this diff Show More

6
.github/workflows/rust.yml

@ -71,10 +71,12 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
key: misc
- name: Lint (rustfmt)
- name: Format (rustfmt)
run: cargo fmt --all --check
- name: Lint (clippy)
- name: Lint (All features)
run: cargo clippy --all-features --all-targets
- name: Lint (No features)
run: cargo clippy --no-default-features --all-targets
- name: Generate documentation
run: cargo doc -v --document-private-items --all-features
- name: Build

268
Cargo.lock generated

@ -4,11 +4,11 @@ version = 3
[[package]]
name = "addr2line"
version = "0.17.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97"
dependencies = [
"gimli",
"gimli 0.27.0",
]
[[package]]
@ -42,9 +42,9 @@ dependencies = [
[[package]]
name = "aho-corasick"
version = "0.7.19"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
@ -101,16 +101,16 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.66"
version = "0.3.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7"
checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca"
dependencies = [
"addr2line",
"cc",
"cfg-if 1.0.0",
"libc",
"miniz_oxide 0.5.4",
"object 0.29.0",
"miniz_oxide",
"object 0.30.0",
"rustc-demangle",
]
@ -211,7 +211,6 @@ dependencies = [
"icu_locid_transform",
"icu_plurals",
"icu_provider",
"icu_provider_adapters",
"indexmap",
"jemallocator",
"num-bigint",
@ -258,8 +257,10 @@ version = "0.16.0"
dependencies = [
"icu_datagen",
"icu_provider",
"icu_provider_adapters",
"icu_provider_blob",
"log",
"once_cell",
"simple_logger",
]
@ -319,14 +320,11 @@ dependencies = [
"bitflags",
"boa_engine",
"boa_gc",
"boa_icu_provider",
"boa_parser",
"clap 4.0.32",
"color-eyre",
"colored",
"fxhash",
"icu_provider_adapters",
"icu_provider_blob",
"once_cell",
"rayon",
"regex",
@ -443,9 +441,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
[[package]]
name = "cc"
version = "1.0.74"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574"
checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d"
dependencies = [
"jobserver",
]
@ -472,7 +470,7 @@ dependencies = [
"js-sys",
"num-integer",
"num-traits",
"time 0.1.44",
"time 0.1.45",
"wasm-bindgen",
"winapi",
]
@ -638,15 +636,14 @@ dependencies = [
[[package]]
name = "console"
version = "0.15.2"
version = "0.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c"
checksum = "5556015fe3aad8b968e5d4124980fbe2f6aaee7aeec6b749de1faaa2ca5d0a4c"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"terminal_size",
"winapi",
"windows-sys 0.42.0",
]
[[package]]
@ -779,22 +776,22 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.11"
version = "0.9.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348"
checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a"
dependencies = [
"autocfg",
"cfg-if 1.0.0",
"crossbeam-utils",
"memoffset",
"memoffset 0.7.1",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.12"
version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac"
checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f"
dependencies = [
"cfg-if 1.0.0",
]
@ -811,9 +808,9 @@ dependencies = [
[[package]]
name = "cxx"
version = "1.0.80"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a"
checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd"
dependencies = [
"cc",
"cxxbridge-flags",
@ -823,9 +820,9 @@ dependencies = [
[[package]]
name = "cxx-build"
version = "1.0.80"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827"
checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0"
dependencies = [
"cc",
"codespan-reporting",
@ -838,15 +835,15 @@ dependencies = [
[[package]]
name = "cxxbridge-flags"
version = "1.0.80"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a"
checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59"
[[package]]
name = "cxxbridge-macro"
version = "1.0.80"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7"
checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6"
dependencies = [
"proc-macro2",
"quote",
@ -922,9 +919,9 @@ dependencies = [
[[package]]
name = "derive_arbitrary"
version = "1.2.0"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4903dff04948f22033ca30232ab8eca2c3fc4c913a8b6a34ee5199699814817f"
checksum = "f8a16495aeb28047bb1185fca837baf755e7d71ed3aeed7f8504654ffa927208"
dependencies = [
"proc-macro2",
"quote",
@ -1107,9 +1104,9 @@ dependencies = [
[[package]]
name = "erased-serde"
version = "0.3.23"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54558e0ba96fbe24280072642eceb9d7d442e32c7ec0ea9e7ecd7b4ea2cf4e11"
checksum = "e4ca605381c017ec7a5fef5e548f1cfaa419ed0f6df6367339300db74c92aa7d"
dependencies = [
"serde",
]
@ -1178,12 +1175,12 @@ dependencies = [
[[package]]
name = "fd-lock"
version = "3.0.7"
version = "3.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c93a581058d957dc4176875aad04f82f81613e6611d64aa1a9c755bdfb16711"
checksum = "bb21c69b9fea5e15dbc1049e4b77145dd0ba1c84019c488102de0dc4ea4b0a27"
dependencies = [
"cfg-if 1.0.0",
"rustix 0.35.13",
"rustix",
"windows-sys 0.42.0",
]
@ -1201,13 +1198,12 @@ dependencies = [
[[package]]
name = "fixed_decimal"
version = "0.5.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ceab5dbd7a3a08385160503f6b6636420dbd72d29babdf8c894d4534304191c3"
checksum = "a7f6fa77730b2c921549ccecf3ad7b0ce0fb14481d47fad0c358addc4aeb456a"
dependencies = [
"displaydoc",
"smallvec",
"static_assertions",
"writeable",
]
@ -1218,7 +1214,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
dependencies = [
"crc32fast",
"miniz_oxide 0.6.2",
"miniz_oxide",
]
[[package]]
@ -1376,6 +1372,12 @@ dependencies = [
"stable_deref_trait",
]
[[package]]
name = "gimli"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793"
[[package]]
name = "glob"
version = "0.3.0"
@ -1977,15 +1979,9 @@ dependencies = [
[[package]]
name = "io-lifetimes"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074"
[[package]]
name = "io-lifetimes"
version = "1.0.1"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7d367024b3f3414d8e01f437f704f41a9f64ab36f9067fa73e526ad4c763c87"
checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c"
dependencies = [
"libc",
"windows-sys 0.42.0",
@ -1999,13 +1995,13 @@ checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e"
[[package]]
name = "is-terminal"
version = "0.4.1"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330"
checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189"
dependencies = [
"hermit-abi 0.2.6",
"io-lifetimes 1.0.1",
"rustix 0.36.4",
"io-lifetimes",
"rustix",
"windows-sys 0.42.0",
]
@ -2020,9 +2016,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.4"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
[[package]]
name = "jemalloc-sys"
@ -2077,9 +2073,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.137"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "libloading"
@ -2093,24 +2089,18 @@ dependencies = [
[[package]]
name = "link-cplusplus"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369"
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
dependencies = [
"cc",
]
[[package]]
name = "linux-raw-sys"
version = "0.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d"
[[package]]
name = "linux-raw-sys"
version = "0.1.3"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]]
name = "litemap"
@ -2218,19 +2208,19 @@ dependencies = [
]
[[package]]
name = "mime"
version = "0.3.16"
name = "memoffset"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
dependencies = [
"autocfg",
]
[[package]]
name = "miniz_oxide"
version = "0.5.4"
name = "mime"
version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34"
dependencies = [
"adler",
]
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "miniz_oxide"
@ -2298,9 +2288,9 @@ dependencies = [
[[package]]
name = "nix"
version = "0.24.2"
version = "0.24.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc"
checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
@ -2341,11 +2331,11 @@ dependencies = [
[[package]]
name = "num_cpus"
version = "1.14.0"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
"hermit-abi 0.1.19",
"hermit-abi 0.2.6",
"libc",
]
@ -2378,9 +2368,9 @@ dependencies = [
[[package]]
name = "object"
version = "0.29.0"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53"
checksum = "239da7f290cfa979f43f85a8efeee9a8a76d0827c356d37f9d3d7254d6b537fb"
dependencies = [
"memchr",
]
@ -2405,9 +2395,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "openssl"
version = "0.10.44"
version = "0.10.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29d971fd5722fec23977260f6e81aa67d2f22cadbdc2aa049f1022d9a3be1566"
checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
@ -2437,9 +2427,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.79"
version = "0.9.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5454462c0eced1e97f2ec09036abc8da362e66802f66fd20f86854d9d8cbcbc4"
checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7"
dependencies = [
"autocfg",
"cc",
@ -2450,15 +2440,15 @@ dependencies = [
[[package]]
name = "os_str_bytes"
version = "6.3.1"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "owo-colors"
version = "3.5.0"
version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
checksum = "69dc4ec9e7e12502579e09e8a53c6a305b3aceb62ad5c307a62f7c3eada78324"
[[package]]
name = "parking_lot"
@ -2468,7 +2458,7 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core 0.8.5",
"parking_lot_core 0.8.6",
]
[[package]]
@ -2483,9 +2473,9 @@ dependencies = [
[[package]]
name = "parking_lot_core"
version = "0.8.5"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
dependencies = [
"cfg-if 1.0.0",
"instant",
@ -2677,9 +2667,9 @@ dependencies = [
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
version = "0.5.20+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
[[package]]
name = "proc-macro2"
@ -2956,42 +2946,28 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver 1.0.14",
"semver 1.0.16",
]
[[package]]
name = "rustix"
version = "0.35.13"
version = "0.36.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9"
checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549"
dependencies = [
"bitflags",
"errno",
"io-lifetimes 0.7.5",
"io-lifetimes",
"libc",
"linux-raw-sys 0.0.46",
"windows-sys 0.42.0",
]
[[package]]
name = "rustix"
version = "0.36.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb93e85278e08bb5788653183213d3a60fc242b10cb9be96586f5a73dcb67c23"
dependencies = [
"bitflags",
"errno",
"io-lifetimes 1.0.1",
"libc",
"linux-raw-sys 0.1.3",
"linux-raw-sys",
"windows-sys 0.42.0",
]
[[package]]
name = "rustversion"
version = "1.0.9"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"
checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70"
[[package]]
name = "rustyline"
@ -3029,9 +3005,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.11"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
[[package]]
name = "ryu-js"
@ -3066,9 +3042,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "scratch"
version = "1.0.2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898"
checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
[[package]]
name = "seahash"
@ -3110,9 +3086,9 @@ dependencies = [
[[package]]
name = "semver"
version = "1.0.14"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a"
[[package]]
name = "semver-parser"
@ -3152,9 +3128,9 @@ dependencies = [
[[package]]
name = "serde_bytes"
version = "0.11.7"
version = "0.11.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b"
checksum = "718dc5fff5b36f99093fc49b280cfc96ce6fc824317783bff5a1fed0c7a64819"
dependencies = [
"serde",
]
@ -3494,16 +3470,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "terminal_size"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "textwrap"
version = "0.16.0"
@ -3547,9 +3513,9 @@ dependencies = [
[[package]]
name = "time"
version = "0.1.44"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
@ -3797,9 +3763,9 @@ checksum = "2281c8c1d221438e373249e065ca4989c4c36952c211ff21a0ee91c44a3869e7"
[[package]]
name = "unicode-ident"
version = "1.0.5"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
name = "unicode-normalization"
@ -3830,9 +3796,9 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "unsafe-libyaml"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68"
checksum = "bc7ed8ba44ca06be78ea1ad2c3682a43349126c8818054231ee6f4748012aed2"
[[package]]
name = "url"
@ -4046,7 +4012,7 @@ dependencies = [
"byteorder",
"dynasm",
"dynasmrt",
"gimli",
"gimli 0.26.2",
"lazy_static",
"loupe",
"more-asserts",
@ -4208,7 +4174,7 @@ dependencies = [
"libc",
"loupe",
"mach",
"memoffset",
"memoffset 0.6.5",
"more-asserts",
"region",
"rkyv",
@ -4495,9 +4461,9 @@ dependencies = [
[[package]]
name = "yoke-derive"
version = "0.6.0"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58c2c5bb7c929b85c1b9ec69091b0d835f0878b4fd9eb67973b25936e06c4374"
checksum = "1346e4cd025ae818b88566eac7eb65ab33a994ea55f355c86889af2e7e56b14e"
dependencies = [
"proc-macro2",
"quote",
@ -4528,9 +4494,9 @@ dependencies = [
[[package]]
name = "zerovec"
version = "0.9.0"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d919a74c17749ccb17beaf6405562e413cd94e98ba52ca1e64bbe7eefbd8b8"
checksum = "25931c326414781db3d859f6e341e5bba119a3eddb7c5ae9976fe0d703b2dd26"
dependencies = [
"databake",
"serde",
@ -4562,7 +4528,7 @@ dependencies = [
"crc32fast",
"flate2",
"thiserror",
"time 0.1.44",
"time 0.1.45",
]
[[package]]

6
boa_cli/Cargo.toml

@ -12,7 +12,7 @@ repository.workspace = true
rust-version.workspace = true
[dependencies]
boa_engine = { workspace = true, features = ["deser", "console", "flowgraph", "intl"] }
boa_engine = { workspace = true, features = ["deser", "console", "flowgraph"] }
boa_ast = { workspace = true, features = ["serde"]}
boa_parser.workspace = true
rustyline = "10.0.0"
@ -23,6 +23,10 @@ colored = "2.0.0"
regex = "1.7.0"
phf = { version = "0.11.1", features = ["macros"] }
[features]
default = ["intl"]
intl = ["boa_engine/intl"]
[target.x86_64-unknown-linux-gnu.dependencies]
jemallocator = "0.5.0"

6
boa_cli/src/main.rs

@ -187,7 +187,7 @@ enum FlowgraphDirection {
///
/// Returns a error of type String with a message,
/// if the token stream has a parsing error.
fn parse_tokens<S>(src: S, context: &mut Context) -> Result<StatementList, String>
fn parse_tokens<S>(src: S, context: &mut Context<'_>) -> Result<StatementList, String>
where
S: AsRef<[u8]>,
{
@ -201,7 +201,7 @@ where
///
/// Returns a error of type String with a error message,
/// if the source has a syntax or parsing error.
fn dump<S>(src: S, args: &Opt, context: &mut Context) -> Result<(), String>
fn dump<S>(src: S, args: &Opt, context: &mut Context<'_>) -> Result<(), String>
where
S: AsRef<[u8]>,
{
@ -226,7 +226,7 @@ where
}
fn generate_flowgraph(
context: &mut Context,
context: &mut Context<'_>,
src: &[u8],
format: FlowgraphFormat,
direction: Option<FlowgraphDirection>,

2
boa_engine/Cargo.toml

@ -21,7 +21,6 @@ intl = [
"dep:icu_datetime",
"dep:icu_plurals",
"dep:icu_provider",
"dep:icu_provider_adapters",
"dep:icu_calendar",
"dep:icu_collator",
"dep:icu_list",
@ -74,7 +73,6 @@ icu_calendar = { version = "1.0.0", optional = true }
icu_collator = { version = "1.0.1", features = ["serde"], optional = true }
icu_plurals = { version = "1.0.0", features = ["serde"], optional = true }
icu_provider = { version = "1.0.1", optional = true }
icu_provider_adapters = { version = "1.0.0", features = ["serde"], optional = true }
icu_list = { version = "1.0.0", features = ["serde"], optional = true }
writeable = { version = "0.5.0", optional = true }
sys-locale = { version = "0.2.3", optional = true }

10
boa_engine/src/builtins/array/array_iterator.rs

@ -54,7 +54,7 @@ impl ArrayIterator {
pub(crate) fn create_array_iterator(
array: JsObject,
kind: PropertyNameKind,
context: &Context,
context: &Context<'_>,
) -> JsValue {
let array_iterator = JsObject::from_proto_and_data(
context
@ -75,7 +75,11 @@ impl ArrayIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next
pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn next(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let mut array_iterator = this.as_object().map(JsObject::borrow_mut);
let array_iterator = array_iterator
.as_mut()
@ -135,7 +139,7 @@ impl ArrayIterator {
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object
pub(crate) fn create_prototype(
iterator_prototype: JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsObject {
let _timer = Profiler::global().start_event(Self::NAME, "init");

120
boa_engine/src/builtins/array/mod.rs

@ -44,7 +44,7 @@ pub(crate) struct Array;
impl BuiltIn for Array {
const NAME: &'static str = "Array";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let symbol_iterator = WellKnownSymbols::iterator();
@ -140,7 +140,7 @@ impl Array {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
// 2. Let proto be ? GetPrototypeFromConstructor(newTarget, "%Array.prototype%").
@ -225,7 +225,7 @@ impl Array {
pub(crate) fn array_create(
length: u64,
prototype: Option<JsObject>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// 1. If length > 2^32 - 1, throw a RangeError exception.
if length > 2u64.pow(32) - 1 {
@ -264,7 +264,7 @@ impl Array {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-createarrayfromlist
pub(crate) fn create_array_from_list<I>(elements: I, context: &mut Context) -> JsObject
pub(crate) fn create_array_from_list<I>(elements: I, context: &mut Context<'_>) -> JsObject
where
I: IntoIterator<Item = JsValue>,
{
@ -298,7 +298,7 @@ impl Array {
/// Returns a Boolean valued property that if `true` indicates that
/// an object should be flattened to its array elements
/// by `Array.prototype.concat`.
fn is_concat_spreadable(o: &JsValue, context: &mut Context) -> JsResult<bool> {
fn is_concat_spreadable(o: &JsValue, context: &mut Context<'_>) -> JsResult<bool> {
// 1. If Type(O) is not Object, return false.
let Some(o) = o.as_object() else {
return Ok(false);
@ -327,7 +327,7 @@ impl Array {
/// [spec]: https://tc39.es/ecma262/#sec-get-array-@@species
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/@@species
#[allow(clippy::unnecessary_wraps)]
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Return the this value.
Ok(this.clone())
}
@ -339,7 +339,7 @@ impl Array {
pub(crate) fn array_species_create(
original_array: &JsObject,
length: u64,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// 1. Let isArray be ? IsArray(originalArray).
// 2. If isArray is false, return ? ArrayCreate(length).
@ -405,7 +405,7 @@ impl Array {
pub(crate) fn from(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let items = args.get_or_undefined(0);
let mapfn = args.get_or_undefined(1);
@ -557,7 +557,7 @@ impl Array {
pub(crate) fn is_array(
_: &JsValue,
args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Return ? IsArray(arg).
args.get_or_undefined(0).is_array().map(Into::into)
@ -574,7 +574,11 @@ impl Array {
///
/// [spec]: https://tc39.es/ecma262/#sec-array.of
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of
pub(crate) fn of(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn of(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let len be the number of elements in items.
// 2. Let lenNumber be 𝔽(len).
let len = args.len();
@ -618,7 +622,11 @@ impl Array {
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype.at
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
pub(crate) fn at(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn at(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
//1. let O be ? ToObject(this value)
let obj = this.to_object(context)?;
//2. let len be ? LengthOfArrayLike(O)
@ -658,7 +666,7 @@ impl Array {
pub(crate) fn concat(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let obj = this.to_object(context)?;
@ -741,7 +749,7 @@ impl Array {
pub(crate) fn push(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -780,7 +788,11 @@ impl Array {
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype.pop
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop
pub(crate) fn pop(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn pop(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
// 2. Let len be ? LengthOfArrayLike(O).
@ -822,7 +834,7 @@ impl Array {
pub(crate) fn for_each(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -868,7 +880,7 @@ impl Array {
pub(crate) fn join(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -924,7 +936,7 @@ impl Array {
pub(crate) fn to_string(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let array be ? ToObject(this value).
let array = this.to_object(context)?;
@ -954,7 +966,7 @@ impl Array {
pub(crate) fn reverse(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1032,7 +1044,11 @@ impl Array {
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype.shift
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
pub(crate) fn shift(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn shift(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
// 2. Let len be ? LengthOfArrayLike(O).
@ -1092,7 +1108,7 @@ impl Array {
pub(crate) fn unshift(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1163,7 +1179,7 @@ impl Array {
pub(crate) fn every(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1215,7 +1231,7 @@ impl Array {
pub(crate) fn map(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1264,7 +1280,7 @@ impl Array {
pub(crate) fn index_of(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1351,7 +1367,7 @@ impl Array {
pub(crate) fn last_index_of(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1421,7 +1437,7 @@ impl Array {
pub(crate) fn find(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1478,7 +1494,7 @@ impl Array {
pub(crate) fn find_index(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1530,7 +1546,7 @@ impl Array {
pub(crate) fn find_last(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1582,7 +1598,7 @@ impl Array {
pub(crate) fn find_last_index(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1632,7 +1648,7 @@ impl Array {
pub(crate) fn flat(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ToObject(this value)
let o = this.to_object(context)?;
@ -1688,7 +1704,7 @@ impl Array {
pub(crate) fn flat_map(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ToObject(this value)
let o = this.to_object(context)?;
@ -1735,7 +1751,7 @@ impl Array {
depth: u64,
mapper_function: Option<&JsObject>,
this_arg: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<u64> {
// 1. Assert target is Object
// 2. Assert source is Object
@ -1848,7 +1864,7 @@ impl Array {
pub(crate) fn fill(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1896,7 +1912,7 @@ impl Array {
pub(crate) fn includes_value(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1973,7 +1989,7 @@ impl Array {
pub(crate) fn slice(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2041,7 +2057,7 @@ impl Array {
pub(crate) fn to_locale_string(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let array be ? ToObject(this value).
let array = this.to_object(context)?;
@ -2101,7 +2117,7 @@ impl Array {
pub(crate) fn splice(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2286,7 +2302,7 @@ impl Array {
pub(crate) fn filter(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2352,7 +2368,7 @@ impl Array {
pub(crate) fn some(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2404,7 +2420,7 @@ impl Array {
pub(crate) fn sort(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception.
let comparefn = match args.get_or_undefined(0) {
@ -2424,7 +2440,7 @@ impl Array {
//
// [spec]: https://tc39.es/ecma262/#sec-sortcompare
let sort_compare =
|x: &JsValue, y: &JsValue, context: &mut Context| -> JsResult<Ordering> {
|x: &JsValue, y: &JsValue, context: &mut Context<'_>| -> JsResult<Ordering> {
match (x.is_undefined(), y.is_undefined()) {
// 1. If x and y are both undefined, return +0𝔽.
(true, true) => return Ok(Ordering::Equal),
@ -2535,7 +2551,7 @@ impl Array {
pub(crate) fn reduce(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2632,7 +2648,7 @@ impl Array {
pub(crate) fn reduce_right(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2726,7 +2742,7 @@ impl Array {
pub(crate) fn copy_within(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2816,7 +2832,7 @@ impl Array {
pub(crate) fn values(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2830,7 +2846,7 @@ impl Array {
}
/// Creates an `Array.prototype.values( )` function object.
pub(crate) fn create_array_prototype_values(context: &mut Context) -> JsFunction {
pub(crate) fn create_array_prototype_values(context: &mut Context<'_>) -> JsFunction {
FunctionBuilder::native(context, Self::values)
.name("values")
.length(0)
@ -2848,7 +2864,11 @@ impl Array {
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype.keys
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values
pub(crate) fn keys(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn keys(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2873,7 +2893,7 @@ impl Array {
pub(crate) fn entries(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2888,7 +2908,7 @@ impl Array {
/// Represents the algorithm to calculate `relativeStart` (or `k`) in array functions.
pub(super) fn get_relative_start(
context: &mut Context,
context: &mut Context<'_>,
arg: Option<&JsValue>,
len: u64,
) -> JsResult<u64> {
@ -2913,7 +2933,7 @@ impl Array {
/// Represents the algorithm to calculate `relativeEnd` (or `final`) in array functions.
pub(super) fn get_relative_end(
context: &mut Context,
context: &mut Context<'_>,
arg: Option<&JsValue>,
len: u64,
) -> JsResult<u64> {
@ -2953,7 +2973,7 @@ impl Array {
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/@@unscopables
pub(crate) fn unscopables_intrinsic(context: &mut Context) -> JsObject {
pub(crate) fn unscopables_intrinsic(context: &mut Context<'_>) -> JsObject {
// 1. Let unscopableList be OrdinaryObjectCreate(null).
let unscopable_list = JsObject::with_null_proto();
// 2. Perform ! CreateDataPropertyOrThrow(unscopableList, "at", true).

20
boa_engine/src/builtins/array_buffer/mod.rs

@ -50,7 +50,7 @@ impl ArrayBuffer {
impl BuiltIn for ArrayBuffer {
const NAME: &'static str = "ArrayBuffer";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let flag_attributes = Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE;
@ -103,7 +103,7 @@ impl ArrayBuffer {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, throw a TypeError exception.
if new_target.is_undefined() {
@ -126,7 +126,7 @@ impl ArrayBuffer {
///
/// [spec]: https://tc39.es/ecma262/#sec-get-arraybuffer-@@species
#[allow(clippy::unnecessary_wraps)]
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Return the this value.
Ok(this.clone())
}
@ -138,7 +138,7 @@ impl ArrayBuffer {
///
/// [spec]: https://tc39.es/ecma262/#sec-arraybuffer.isview
#[allow(clippy::unnecessary_wraps)]
fn is_view(_: &JsValue, args: &[JsValue], _context: &mut Context) -> JsResult<JsValue> {
fn is_view(_: &JsValue, args: &[JsValue], _context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. If Type(arg) is not Object, return false.
// 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true.
// 3. Return false.
@ -159,7 +159,7 @@ impl ArrayBuffer {
pub(crate) fn get_byte_length(
this: &JsValue,
_args: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
@ -190,7 +190,7 @@ impl ArrayBuffer {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice
fn slice(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn slice(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
let obj = this.as_object().ok_or_else(|| {
@ -332,7 +332,7 @@ impl ArrayBuffer {
pub(crate) fn allocate(
constructor: &JsValue,
byte_length: u64,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBuffer.prototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]], [[ArrayBufferDetachKey]] »).
let prototype = get_prototype_from_constructor(
@ -382,7 +382,7 @@ impl ArrayBuffer {
src_byte_offset: u64,
src_length: u64,
clone_constructor: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// 1. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, srcLength).
let target_buffer = Self::allocate(clone_constructor, src_length, context)?;
@ -627,7 +627,7 @@ impl ArrayBuffer {
t: TypedArrayKind,
value: &JsValue,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Vec<u8>> {
Ok(match t {
TypedArrayKind::Int8 if is_little_endian => {
@ -722,7 +722,7 @@ impl ArrayBuffer {
value: &JsValue,
_order: SharedMemoryOrder,
is_little_endian: Option<bool>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Assert: IsDetachedBuffer(arrayBuffer) is false.
// 2. Assert: There are sufficient bytes in arrayBuffer starting at byteIndex to represent a value of type.

4
boa_engine/src/builtins/async_function/mod.rs

@ -26,7 +26,7 @@ pub struct AsyncFunction;
impl BuiltIn for AsyncFunction {
const NAME: &'static str = "AsyncFunction";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let prototype = &context
@ -98,7 +98,7 @@ impl AsyncFunction {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
crate::builtins::function::BuiltInFunctionObject::create_dynamic_function(
new_target, args, true, false, context,

18
boa_engine/src/builtins/async_generator/mod.rs

@ -65,7 +65,7 @@ pub struct AsyncGenerator {
impl BuiltIn for AsyncGenerator {
const NAME: &'static str = "AsyncGenerator";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let iterator_prototype = context
@ -125,7 +125,7 @@ impl AsyncGenerator {
pub(crate) fn constructor(
_: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let prototype = context
.intrinsics()
@ -154,7 +154,7 @@ impl AsyncGenerator {
pub(crate) fn next(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let generator be the this value.
let generator = this;
@ -247,7 +247,7 @@ impl AsyncGenerator {
pub(crate) fn r#return(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let generator be the this value.
let generator = this;
@ -335,7 +335,7 @@ impl AsyncGenerator {
pub(crate) fn throw(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let generator be the this value.
let generator = this;
@ -460,7 +460,7 @@ impl AsyncGenerator {
next: &AsyncGeneratorRequest,
completion: JsResult<JsValue>,
done: bool,
context: &mut Context,
context: &mut Context<'_>,
) {
// 1. Let queue be generator.[[AsyncGeneratorQueue]].
// 2. Assert: queue is not empty.
@ -513,7 +513,7 @@ impl AsyncGenerator {
state: AsyncGeneratorState,
generator_context: &Gc<GcCell<GeneratorContext>>,
completion: (JsResult<JsValue>, bool),
context: &mut Context,
context: &mut Context<'_>,
) {
// 1. Assert: generator.[[AsyncGeneratorState]] is either suspendedStart or suspendedYield.
assert!(
@ -589,7 +589,7 @@ impl AsyncGenerator {
pub(crate) fn await_return(
generator: JsObject,
completion: JsResult<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) {
// 1. Let queue be generator.[[AsyncGeneratorQueue]].
// 2. Assert: queue is not empty.
@ -708,7 +708,7 @@ impl AsyncGenerator {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-asyncgeneratordrainqueue
pub(crate) fn drain_queue(generator: &JsObject, context: &mut Context) {
pub(crate) fn drain_queue(generator: &JsObject, context: &mut Context<'_>) {
let mut generator_borrow_mut = generator.borrow_mut();
let gen = generator_borrow_mut
.as_async_generator_mut()

4
boa_engine/src/builtins/async_generator_function/mod.rs

@ -25,7 +25,7 @@ pub struct AsyncGeneratorFunction;
impl BuiltIn for AsyncGeneratorFunction {
const NAME: &'static str = "AsyncGeneratorFunction";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let prototype = &context
@ -121,7 +121,7 @@ impl AsyncGeneratorFunction {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
BuiltInFunctionObject::create_dynamic_function(new_target, args, true, true, context)
.map(Into::into)

21
boa_engine/src/builtins/bigint/mod.rs

@ -35,7 +35,7 @@ pub struct BigInt;
impl BuiltIn for BigInt {
const NAME: &'static str = "BigInt";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let to_string_tag = WellKnownSymbols::to_string_tag();
@ -81,7 +81,7 @@ impl BigInt {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is not undefined, throw a TypeError exception.
if !new_target.is_undefined() {
@ -167,7 +167,7 @@ impl BigInt {
pub(crate) fn to_string(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let x be ? thisBigIntValue(this value).
let x = Self::this_bigint_value(this)?;
@ -216,7 +216,11 @@ impl BigInt {
///
/// [spec]: https://tc39.es/ecma262/#sec-bigint.prototype.valueof
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf
pub(crate) fn value_of(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn value_of(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(JsValue::new(Self::this_bigint_value(this)?))
}
@ -230,7 +234,7 @@ impl BigInt {
pub(crate) fn as_int_n(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let (modulo, bits) = Self::calculate_as_uint_n(args, context)?;
@ -256,7 +260,7 @@ impl BigInt {
pub(crate) fn as_uint_n(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let (modulo, _) = Self::calculate_as_uint_n(args, context)?;
@ -268,7 +272,10 @@ impl BigInt {
/// This function expects the same arguments as `as_uint_n` and wraps the value of a `BigInt`.
/// Additionally to the wrapped unsigned value it returns the converted `bits` argument, so it
/// can be reused from the `as_int_n` method.
fn calculate_as_uint_n(args: &[JsValue], context: &mut Context) -> JsResult<(JsBigInt, u32)> {
fn calculate_as_uint_n(
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<(JsBigInt, u32)> {
let bits_arg = args.get_or_undefined(0);
let bigint_arg = args.get_or_undefined(1);

2
boa_engine/src/builtins/bigint/tests.rs

@ -395,7 +395,7 @@ fn as_uint_n_errors() {
assert_throws(&mut context, "BigInt.asUintN(0n, 0n)", "TypeError");
}
fn assert_throws(context: &mut Context, src: &str, error_type: &str) {
fn assert_throws(context: &mut Context<'_>, src: &str, error_type: &str) {
let result = forward(context, src);
assert!(result.contains(error_type));
}

16
boa_engine/src/builtins/boolean/mod.rs

@ -32,7 +32,7 @@ impl BuiltIn for Boolean {
/// The name of the object.
const NAME: &'static str = "Boolean";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
ConstructorBuilder::with_standard_constructor(
@ -60,7 +60,7 @@ impl Boolean {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// Get the argument, if any
let data = args.get(0).map_or(false, JsValue::to_boolean);
@ -100,7 +100,11 @@ impl Boolean {
/// [spec]: https://tc39.es/ecma262/#sec-boolean-object
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/toString
#[allow(clippy::wrong_self_convention)]
pub(crate) fn to_string(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn to_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
let boolean = Self::this_boolean_value(this)?;
Ok(JsValue::new(boolean.to_string()))
}
@ -113,7 +117,11 @@ impl Boolean {
///
/// [spec]: https://tc39.es/ecma262/#sec-boolean.prototype.valueof
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf
pub(crate) fn value_of(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn value_of(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(JsValue::new(Self::this_boolean_value(this)?))
}
}

82
boa_engine/src/builtins/console/mod.rs

@ -51,7 +51,7 @@ fn logger(msg: LogMessage, console_state: &Console) {
}
/// This represents the `console` formatter.
pub fn formatter(data: &[JsValue], context: &mut Context) -> JsResult<String> {
pub fn formatter(data: &[JsValue], context: &mut Context<'_>) -> JsResult<String> {
match data {
[] => Ok(String::new()),
[val] => Ok(val.to_string(context)?.to_std_string_escaped()),
@ -133,7 +133,7 @@ pub(crate) struct Console {
impl BuiltIn for Console {
const NAME: &'static str = "console";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
ObjectInitializer::new(context)
.function(Self::assert, "assert", 0)
@ -179,7 +179,7 @@ impl Console {
pub(crate) fn assert(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let assertion = args.get(0).map_or(false, JsValue::to_boolean);
@ -215,7 +215,11 @@ impl Console {
/// [spec]: https://console.spec.whatwg.org/#clear
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/clear
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn clear(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn clear(
_: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
context.console_mut().groups.clear();
Ok(JsValue::undefined())
}
@ -230,7 +234,11 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#debug
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/debug
pub(crate) fn debug(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn debug(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
logger(
LogMessage::Log(formatter(args, context)?),
context.console(),
@ -248,7 +256,11 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#error
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/error
pub(crate) fn error(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn error(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
logger(
LogMessage::Error(formatter(args, context)?),
context.console(),
@ -266,7 +278,11 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#info
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/info
pub(crate) fn info(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn info(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
logger(
LogMessage::Info(formatter(args, context)?),
context.console(),
@ -284,7 +300,11 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#log
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/log
pub(crate) fn log(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn log(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
logger(
LogMessage::Log(formatter(args, context)?),
context.console(),
@ -292,7 +312,7 @@ impl Console {
Ok(JsValue::undefined())
}
fn get_stack_trace(context: &mut Context) -> Vec<String> {
fn get_stack_trace(context: &mut Context<'_>) -> Vec<String> {
let mut stack_trace: Vec<String> = vec![];
for frame in context.vm.frames.iter().rev() {
@ -317,7 +337,11 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#trace
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/trace
pub(crate) fn trace(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn trace(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if !args.is_empty() {
logger(
LogMessage::Log(formatter(args, context)?),
@ -341,7 +365,11 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#warn
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/warn
pub(crate) fn warn(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn warn(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
logger(
LogMessage::Warn(formatter(args, context)?),
context.console(),
@ -359,7 +387,11 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#count
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/count
pub(crate) fn count(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn count(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let label = match args.get(0) {
Some(value) => value.to_string(context)?,
None => "default".into(),
@ -386,7 +418,7 @@ impl Console {
pub(crate) fn count_reset(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let label = match args.get(0) {
Some(value) => value.to_string(context)?,
@ -421,7 +453,11 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#time
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/time
pub(crate) fn time(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn time(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let label = match args.get(0) {
Some(value) => value.to_string(context)?,
None => "default".into(),
@ -456,7 +492,7 @@ impl Console {
pub(crate) fn time_log(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let label = match args.get(0) {
Some(value) => value.to_string(context)?,
@ -496,7 +532,7 @@ impl Console {
pub(crate) fn time_end(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let label = match args.get(0) {
Some(value) => value.to_string(context)?,
@ -536,7 +572,11 @@ impl Console {
///
/// [spec]: https://console.spec.whatwg.org/#group
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/group
pub(crate) fn group(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn group(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let group_label = formatter(args, context)?;
logger(
@ -562,7 +602,7 @@ impl Console {
pub(crate) fn group_end(
_: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
context.console_mut().groups.pop();
@ -580,7 +620,11 @@ impl Console {
/// [spec]: https://console.spec.whatwg.org/#dir
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/dir
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn dir(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn dir(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
logger(
LogMessage::Info(display_obj(args.get_or_undefined(0), true)),
context.console(),

54
boa_engine/src/builtins/dataview/mod.rs

@ -34,7 +34,7 @@ pub struct DataView {
impl BuiltIn for DataView {
const NAME: &'static str = "DataView";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let flag_attributes = Attribute::CONFIGURABLE | Attribute::NON_ENUMERABLE;
let get_buffer = FunctionBuilder::native(context, Self::get_buffer)
@ -107,7 +107,7 @@ impl DataView {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_length = args.get_or_undefined(2);
@ -210,7 +210,7 @@ impl DataView {
pub(crate) fn get_buffer(
this: &JsValue,
_args: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[DataView]]).
@ -239,7 +239,7 @@ impl DataView {
pub(crate) fn get_byte_length(
this: &JsValue,
_args: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[DataView]]).
@ -280,7 +280,7 @@ impl DataView {
pub(crate) fn get_byte_offset(
this: &JsValue,
_args: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[DataView]]).
@ -322,7 +322,7 @@ impl DataView {
request_index: &JsValue,
is_little_endian: &JsValue,
t: TypedArrayKind,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Perform ? RequireInternalSlot(view, [[DataView]]).
// 2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
@ -393,7 +393,7 @@ impl DataView {
pub(crate) fn get_big_int64(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let is_little_endian = args.get_or_undefined(1);
@ -422,7 +422,7 @@ impl DataView {
pub(crate) fn get_big_uint64(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let is_little_endian = args.get_or_undefined(1);
@ -451,7 +451,7 @@ impl DataView {
pub(crate) fn get_float32(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let is_little_endian = args.get_or_undefined(1);
@ -480,7 +480,7 @@ impl DataView {
pub(crate) fn get_float64(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let is_little_endian = args.get_or_undefined(1);
@ -509,7 +509,7 @@ impl DataView {
pub(crate) fn get_int8(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let is_little_endian = args.get_or_undefined(1);
@ -538,7 +538,7 @@ impl DataView {
pub(crate) fn get_int16(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let is_little_endian = args.get_or_undefined(1);
@ -567,7 +567,7 @@ impl DataView {
pub(crate) fn get_int32(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let is_little_endian = args.get_or_undefined(1);
@ -596,7 +596,7 @@ impl DataView {
pub(crate) fn get_uint8(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let is_little_endian = args.get_or_undefined(1);
@ -625,7 +625,7 @@ impl DataView {
pub(crate) fn get_uint16(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let is_little_endian = args.get_or_undefined(1);
@ -654,7 +654,7 @@ impl DataView {
pub(crate) fn get_uint32(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let is_little_endian = args.get_or_undefined(1);
@ -685,7 +685,7 @@ impl DataView {
is_little_endian: &JsValue,
t: TypedArrayKind,
value: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Perform ? RequireInternalSlot(view, [[DataView]]).
// 2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
@ -765,7 +765,7 @@ impl DataView {
pub(crate) fn set_big_int64(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let value = args.get_or_undefined(1);
@ -796,7 +796,7 @@ impl DataView {
pub(crate) fn set_big_uint64(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let value = args.get_or_undefined(1);
@ -827,7 +827,7 @@ impl DataView {
pub(crate) fn set_float32(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let value = args.get_or_undefined(1);
@ -858,7 +858,7 @@ impl DataView {
pub(crate) fn set_float64(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let value = args.get_or_undefined(1);
@ -889,7 +889,7 @@ impl DataView {
pub(crate) fn set_int8(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let value = args.get_or_undefined(1);
@ -920,7 +920,7 @@ impl DataView {
pub(crate) fn set_int16(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let value = args.get_or_undefined(1);
@ -951,7 +951,7 @@ impl DataView {
pub(crate) fn set_int32(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let value = args.get_or_undefined(1);
@ -982,7 +982,7 @@ impl DataView {
pub(crate) fn set_uint8(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let value = args.get_or_undefined(1);
@ -1013,7 +1013,7 @@ impl DataView {
pub(crate) fn set_uint16(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let value = args.get_or_undefined(1);
@ -1044,7 +1044,7 @@ impl DataView {
pub(crate) fn set_uint32(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let byte_offset = args.get_or_undefined(0);
let value = args.get_or_undefined(1);

88
boa_engine/src/builtins/date/mod.rs

@ -104,7 +104,7 @@ impl Default for Date {
impl BuiltIn for Date {
const NAME: &'static str = "Date";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
ConstructorBuilder::with_standard_constructor(
@ -190,7 +190,7 @@ impl Date {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, then
if new_target.is_undefined() {
@ -278,7 +278,7 @@ impl Date {
/// Gets the timestamp from a list of component values.
fn construct_date(
values: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Option<NaiveDateTime>> {
// 1. Let y be ? ToNumber(year).
let Some(mut year) = values.get_or_undefined(0).to_integer_or_nan(context)?.as_integer() else {
@ -371,7 +371,7 @@ impl Date {
/// [spec]: https://tc39.es/ecma262/#sec-date.now
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn now(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn now(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
Ok(JsValue::new(Utc::now().timestamp_millis()))
}
@ -387,7 +387,11 @@ impl Date {
///
/// [spec]: https://tc39.es/ecma262/#sec-date.parse
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
pub(crate) fn parse(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn parse(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// This method is implementation-defined and discouraged, so we just require the same format as the string
// constructor.
@ -413,7 +417,11 @@ impl Date {
///
/// [spec]: https://tc39.es/ecma262/#sec-date.utc
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC
pub(crate) fn utc(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn utc(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let t = some_or_nan!(Self::construct_date(args, context)?);
Ok(JsValue::from(t.timestamp_millis()))
@ -429,7 +437,7 @@ impl Date {
pub(crate) fn get_date<const LOCAL: bool>(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -453,7 +461,7 @@ impl Date {
pub(crate) fn get_day<const LOCAL: bool>(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -480,7 +488,7 @@ impl Date {
pub(crate) fn get_year(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -501,7 +509,7 @@ impl Date {
pub(crate) fn get_full_year<const LOCAL: bool>(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -524,7 +532,7 @@ impl Date {
pub(crate) fn get_hours<const LOCAL: bool>(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -547,7 +555,7 @@ impl Date {
pub(crate) fn get_milliseconds<const LOCAL: bool>(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -570,7 +578,7 @@ impl Date {
pub(crate) fn get_minutes<const LOCAL: bool>(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -594,7 +602,7 @@ impl Date {
pub(crate) fn get_month<const LOCAL: bool>(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -617,7 +625,7 @@ impl Date {
pub(crate) fn get_seconds<const LOCAL: bool>(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -643,7 +651,7 @@ impl Date {
pub(crate) fn get_time(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Return ? thisTimeValue(this value).
let t = some_or_nan!(this_time_value(this)?);
@ -664,7 +672,7 @@ impl Date {
pub(crate) fn get_timezone_offset(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -685,7 +693,7 @@ impl Date {
pub(crate) fn set_date<const LOCAL: bool>(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be LocalTime(? thisTimeValue(this value)).
get_mut_date!(let t = this);
@ -726,7 +734,7 @@ impl Date {
pub(crate) fn set_full_year<const LOCAL: bool>(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
get_mut_date!(let t = this);
@ -795,7 +803,7 @@ impl Date {
pub(crate) fn set_hours<const LOCAL: bool>(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
get_mut_date!(let t = this);
@ -859,7 +867,7 @@ impl Date {
pub(crate) fn set_milliseconds<const LOCAL: bool>(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 1. Let t be LocalTime(? thisTimeValue(this value)).
@ -900,7 +908,7 @@ impl Date {
pub(crate) fn set_minutes<const LOCAL: bool>(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
get_mut_date!(let t = this);
@ -957,7 +965,7 @@ impl Date {
pub(crate) fn set_month<const LOCAL: bool>(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
get_mut_date!(let t = this);
@ -1005,7 +1013,7 @@ impl Date {
pub(crate) fn set_seconds<const LOCAL: bool>(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
get_mut_date!(let t = this);
@ -1060,7 +1068,7 @@ impl Date {
pub(crate) fn set_year(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
get_mut_date!(let t = this);
@ -1127,7 +1135,7 @@ impl Date {
pub(crate) fn set_time(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Perform ? thisTimeValue(this value).
get_mut_date!(let t = this);
@ -1160,7 +1168,7 @@ impl Date {
pub(crate) fn to_date_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be this Date object.
// 2. Let tv be ? thisTimeValue(O).
@ -1193,7 +1201,7 @@ impl Date {
pub(crate) fn to_iso_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
let t = this_time_value(this)?
.ok_or_else(|| JsNativeError::range().with_message("Invalid time value"))?;
@ -1217,7 +1225,7 @@ impl Date {
pub(crate) fn to_json(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1250,7 +1258,7 @@ impl Date {
pub(crate) fn to_locale_date_string(
_this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
Err(JsError::from_opaque(JsValue::new("Function Unimplemented")))
}
@ -1267,7 +1275,7 @@ impl Date {
pub(crate) fn to_locale_string(
_this: &JsValue,
_: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
Err(JsError::from_opaque(JsValue::new(
"Function Unimplemented]",
@ -1287,7 +1295,7 @@ impl Date {
pub(crate) fn to_locale_time_string(
_this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
Err(JsError::from_opaque(JsValue::new(
"Function Unimplemented]",
@ -1303,7 +1311,11 @@ impl Date {
///
/// [spec]: https://tc39.es/ecma262/#sec-date.prototype.tostring
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString
pub(crate) fn to_string(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn to_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let tv be ? thisTimeValue(this value).
// 2. Return ToDateString(tv).
let Some(t) = this_time_value(this)? else {
@ -1330,7 +1342,7 @@ impl Date {
pub(crate) fn to_time_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be this Date object.
// 2. Let tv be ? thisTimeValue(O).
@ -1361,7 +1373,7 @@ impl Date {
pub(crate) fn to_utc_string(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be this Date object.
let Some(t) = this_time_value(this)? else {
@ -1395,7 +1407,7 @@ impl Date {
pub(crate) fn value_of(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Return ? thisTimeValue(this value).
Ok(Date(this_time_value(this)?).as_value())
@ -1413,7 +1425,7 @@ impl Date {
pub(crate) fn to_primitive(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. If Type(O) is not Object, throw a TypeError exception.
@ -1457,7 +1469,7 @@ impl Date {
pub(crate) fn to_gmt_string(
this: &JsValue,
_args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// The initial value of the "toGMTString" property is %Date.prototype.toUTCString%
Self::to_utc_string(this, &[], context)

2
boa_engine/src/builtins/date/tests.rs

@ -25,7 +25,7 @@ fn datetime_from_local(
.naive_utc()
}
fn forward_dt(context: &mut Context, src: &str) -> Option<NaiveDateTime> {
fn forward_dt(context: &mut Context<'_>, src: &str) -> Option<NaiveDateTime> {
let date_time = forward_val(context, src).unwrap();
let date_time = date_time.as_object().unwrap();
let date_time = date_time.borrow();

4
boa_engine/src/builtins/error/aggregate.rs

@ -27,7 +27,7 @@ pub(crate) struct AggregateError;
impl BuiltIn for AggregateError {
const NAME: &'static str = "AggregateError";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let error_constructor = context.intrinsics().constructors().error().constructor();
@ -64,7 +64,7 @@ impl AggregateError {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
// 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%AggregateError.prototype%", « [[ErrorData]] »).

4
boa_engine/src/builtins/error/eval.rs

@ -32,7 +32,7 @@ pub(crate) struct EvalError;
impl BuiltIn for EvalError {
const NAME: &'static str = "EvalError";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let error_constructor = context.intrinsics().constructors().error().constructor();
@ -64,7 +64,7 @@ impl EvalError {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
// 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »).

8
boa_engine/src/builtins/error/mod.rs

@ -132,7 +132,7 @@ pub(crate) struct Error;
impl BuiltIn for Error {
const NAME: &'static str = "Error";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let attribute = Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE;
@ -159,7 +159,7 @@ impl Error {
pub(crate) fn install_error_cause(
o: &JsObject,
options: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<()> {
// 1. If Type(options) is Object and ? HasProperty(options, "cause") is true, then
if let Some(options) = options.as_object() {
@ -182,7 +182,7 @@ impl Error {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
@ -222,7 +222,7 @@ impl Error {
pub(crate) fn to_string(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. If Type(O) is not Object, throw a TypeError exception.

4
boa_engine/src/builtins/error/range.rs

@ -30,7 +30,7 @@ pub(crate) struct RangeError;
impl BuiltIn for RangeError {
const NAME: &'static str = "RangeError";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let error_constructor = context.intrinsics().constructors().error().constructor();
@ -62,7 +62,7 @@ impl RangeError {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
// 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »).

4
boa_engine/src/builtins/error/reference.rs

@ -29,7 +29,7 @@ pub(crate) struct ReferenceError;
impl BuiltIn for ReferenceError {
const NAME: &'static str = "ReferenceError";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let error_constructor = context.intrinsics().constructors().error().constructor();
@ -65,7 +65,7 @@ impl ReferenceError {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
// 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »).

4
boa_engine/src/builtins/error/syntax.rs

@ -32,7 +32,7 @@ pub(crate) struct SyntaxError;
impl BuiltIn for SyntaxError {
const NAME: &'static str = "SyntaxError";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let error_constructor = context.intrinsics().constructors().error().constructor();
@ -64,7 +64,7 @@ impl SyntaxError {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
// 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »).

8
boa_engine/src/builtins/error/type.rs

@ -37,7 +37,7 @@ pub(crate) struct TypeError;
impl BuiltIn for TypeError {
const NAME: &'static str = "TypeError";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let error_constructor = context.intrinsics().constructors().error().constructor();
@ -69,7 +69,7 @@ impl TypeError {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
// 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »).
@ -95,8 +95,8 @@ impl TypeError {
}
}
pub(crate) fn create_throw_type_error(context: &mut Context) -> JsObject {
fn throw_type_error(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn create_throw_type_error(context: &mut Context<'_>) -> JsObject {
fn throw_type_error(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
Err(JsNativeError::typ().with_message("'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them").into())
}

4
boa_engine/src/builtins/error/uri.rs

@ -31,7 +31,7 @@ pub(crate) struct UriError;
impl BuiltIn for UriError {
const NAME: &'static str = "URIError";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let error_constructor = context.intrinsics().constructors().error().constructor();
@ -63,7 +63,7 @@ impl UriError {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
// 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »).

8
boa_engine/src/builtins/eval/mod.rs

@ -34,7 +34,7 @@ impl BuiltIn for Eval {
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::WRITABLE);
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let object = FunctionBuilder::native(context, Self::eval)
@ -54,7 +54,7 @@ impl Eval {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-eval-x
fn eval(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn eval(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Return ? PerformEval(x, false, false).
Self::perform_eval(args.get_or_undefined(0), false, false, context)
}
@ -69,7 +69,7 @@ impl Eval {
x: &JsValue,
direct: bool,
mut strict: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
bitflags::bitflags! {
/// Flags used to throw early errors on invalid `eval` calls.
@ -91,7 +91,7 @@ impl Eval {
}
/// Restores the environment after calling `eval` or after throwing an error.
fn restore_environment(context: &mut Context, action: EnvStackAction) {
fn restore_environment(context: &mut Context<'_>, action: EnvStackAction) {
match action {
EnvStackAction::Truncate(size) => {
context.realm.environments.truncate(size);

4
boa_engine/src/builtins/function/arguments.rs

@ -71,7 +71,7 @@ impl Arguments {
/// [spec]: https://tc39.es/ecma262/#sec-createunmappedargumentsobject
pub(crate) fn create_unmapped_arguments_object(
arguments_list: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsObject {
// 1. Let len be the number of elements in argumentsList.
let len = arguments_list.len();
@ -151,7 +151,7 @@ impl Arguments {
formals: &FormalParameterList,
arguments_list: &[JsValue],
env: &Gc<DeclarativeEnvironment>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsObject {
// 1. Assert: formals does not contain a rest parameter, any binding patterns, or any initializers.
// It may contain duplicate identifiers.

37
boa_engine/src/builtins/function/mod.rs

@ -64,7 +64,7 @@ mod tests;
/// - The second argument represents a list of all arguments passed to the function.
///
/// - The last argument is the [`Context`] of the engine.
pub type NativeFunctionSignature = fn(&JsValue, &[JsValue], &mut Context) -> JsResult<JsValue>;
pub type NativeFunctionSignature = fn(&JsValue, &[JsValue], &mut Context<'_>) -> JsResult<JsValue>;
// Allows restricting closures to only `Copy` ones.
// Used the sealed pattern to disallow external implementations
@ -85,12 +85,15 @@ impl<T: Copy> DynCopy for T {}
/// be callable from Javascript, but most of the time the compiler
/// is smart enough to correctly infer the types.
pub trait ClosureFunctionSignature:
Fn(&JsValue, &[JsValue], Captures, &mut Context) -> JsResult<JsValue> + DynCopy + DynClone + 'static
Fn(&JsValue, &[JsValue], Captures, &mut Context<'_>) -> JsResult<JsValue>
+ DynCopy
+ DynClone
+ 'static
{
}
impl<T> ClosureFunctionSignature for T where
T: Fn(&JsValue, &[JsValue], Captures, &mut Context) -> JsResult<JsValue> + Copy + 'static
T: Fn(&JsValue, &[JsValue], Captures, &mut Context<'_>) -> JsResult<JsValue> + Copy + 'static
{
}
@ -488,7 +491,7 @@ pub(crate) fn make_builtin_fn<N>(
name: N,
parent: &JsObject,
length: usize,
interpreter: &Context,
interpreter: &Context<'_>,
) where
N: Into<String>,
{
@ -544,7 +547,7 @@ impl BuiltInFunctionObject {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Self::create_dynamic_function(new_target, args, false, false, context).map(Into::into)
}
@ -560,7 +563,7 @@ impl BuiltInFunctionObject {
args: &[JsValue],
r#async: bool,
generator: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
let default = if r#async && generator {
StandardConstructors::async_generator_function
@ -740,7 +743,7 @@ impl BuiltInFunctionObject {
///
/// [spec]: https://tc39.es/ecma262/#sec-function.prototype.apply
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
fn apply(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn apply(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let func be the this value.
// 2. If IsCallable(func) is false, throw a TypeError exception.
let func = this.as_callable().ok_or_else(|| {
@ -780,7 +783,7 @@ impl BuiltInFunctionObject {
///
/// [spec]: https://tc39.es/ecma262/#sec-function.prototype.bind
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind
fn bind(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn bind(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let Target be the this value.
// 2. If IsCallable(Target) is false, throw a TypeError exception.
let target = this.as_callable().ok_or_else(|| {
@ -860,7 +863,7 @@ impl BuiltInFunctionObject {
///
/// [spec]: https://tc39.es/ecma262/#sec-function.prototype.call
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
fn call(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn call(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let func be the this value.
// 2. If IsCallable(func) is false, throw a TypeError exception.
let func = this.as_callable().ok_or_else(|| {
@ -876,7 +879,7 @@ impl BuiltInFunctionObject {
}
#[allow(clippy::wrong_self_convention)]
fn to_string(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn to_string(this: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let object = this.as_object().map(JsObject::borrow);
let function = object
.as_deref()
@ -923,14 +926,18 @@ impl BuiltInFunctionObject {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-function.prototype-@@hasinstance
fn has_instance(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn has_instance(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let F be the this value.
// 2. Return ? OrdinaryHasInstance(F, V).
Ok(JsValue::ordinary_has_instance(this, args.get_or_undefined(0), context)?.into())
}
#[allow(clippy::unnecessary_wraps)]
fn prototype(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn prototype(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
Ok(JsValue::undefined())
}
}
@ -938,7 +945,7 @@ impl BuiltInFunctionObject {
impl BuiltIn for BuiltInFunctionObject {
const NAME: &'static str = "Function";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event("function", "init");
let function_prototype = context.intrinsics().constructors().function().prototype();
@ -1002,7 +1009,7 @@ fn set_function_name(
function: &JsObject,
name: &PropertyKey,
prefix: Option<JsString>,
context: &mut Context,
context: &mut Context<'_>,
) {
// 1. Assert: F is an extensible object that does not have a "name" own property.
// 2. If Type(name) is Symbol, then
@ -1070,7 +1077,7 @@ impl BoundFunction {
target_function: JsObject,
this: JsValue,
args: Vec<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// 1. Let proto be ? targetFunction.[[GetPrototypeOf]]().
let proto = target_function.__get_prototype_of__(context)?;

14
boa_engine/src/builtins/generator/mod.rs

@ -58,7 +58,7 @@ pub struct Generator {
impl BuiltIn for Generator {
const NAME: &'static str = "Generator";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let iterator_prototype = context
@ -116,7 +116,7 @@ impl Generator {
pub(crate) fn constructor(
_: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let prototype = context.intrinsics().constructors().generator().prototype();
@ -145,7 +145,7 @@ impl Generator {
pub(crate) fn next(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Return ? GeneratorResume(this value, value, empty).
this.as_object().map_or_else(
@ -171,7 +171,7 @@ impl Generator {
pub(crate) fn r#return(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let g be the this value.
// 2. Let C be Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty }.
@ -193,7 +193,7 @@ impl Generator {
pub(crate) fn throw(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let g be the this value.
// 2. Let C be ThrowCompletion(exception).
@ -214,7 +214,7 @@ impl Generator {
pub(crate) fn generator_resume(
generator_obj: &JsObject,
value: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let state be ? GeneratorValidate(generator, generatorBrand).
let mut generator_obj_mut = generator_obj.borrow_mut();
@ -319,7 +319,7 @@ impl Generator {
pub(crate) fn generator_resume_abrupt(
this: &JsValue,
abrupt_completion: JsResult<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let state be ? GeneratorValidate(generator, generatorBrand).
let generator_obj = this.as_object().ok_or_else(|| {

4
boa_engine/src/builtins/generator_function/mod.rs

@ -30,7 +30,7 @@ pub struct GeneratorFunction;
impl BuiltIn for GeneratorFunction {
const NAME: &'static str = "GeneratorFunction";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let prototype = &context
@ -120,7 +120,7 @@ impl GeneratorFunction {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
BuiltInFunctionObject::create_dynamic_function(new_target, args, false, true, context)
.map(Into::into)

2
boa_engine/src/builtins/global_this/mod.rs

@ -22,7 +22,7 @@ pub(crate) struct GlobalThis;
impl BuiltIn for GlobalThis {
const NAME: &'static str = "globalThis";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
Some(context.global_object().clone().into())

2
boa_engine/src/builtins/infinity/mod.rs

@ -26,7 +26,7 @@ impl BuiltIn for Infinity {
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::PERMANENT);
fn init(_: &mut Context) -> Option<JsValue> {
fn init(_: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
Some(f64::INFINITY.into())

44
boa_engine/src/builtins/intl/collator/mod.rs

@ -8,7 +8,7 @@ use icu_locid::{
extensions::unicode::Value, extensions_unicode_key as key, extensions_unicode_value as value,
Locale,
};
use icu_provider::{DataLocale, DataProvider};
use icu_provider::DataLocale;
use tap::{Conv, Pipe};
use crate::{
@ -81,19 +81,18 @@ pub(in crate::builtins::intl) struct CollatorLocaleOptions {
case_first: Option<CaseFirst>,
}
impl<P> Service<P> for Collator
where
P: DataProvider<CollationMetadataV1Marker>,
{
impl Service for Collator {
type LangMarker = CollationMetadataV1Marker;
type LocaleOptions = CollatorLocaleOptions;
fn resolve(locale: &mut Locale, options: &mut Self::LocaleOptions, provider: &P) {
fn resolve(locale: &mut Locale, options: &mut Self::LocaleOptions, provider: BoaProvider<'_>) {
let collation = options
.collation
.take()
.filter(|co| validate_extension(locale.id.clone(), key!("co"), co, provider))
.filter(|co| {
validate_extension::<Self::LangMarker>(locale.id.clone(), key!("co"), co, &provider)
})
.or_else(|| {
locale
.extensions
@ -101,7 +100,14 @@ where
.keywords
.get(&key!("co"))
.cloned()
.filter(|co| validate_extension(locale.id.clone(), key!("co"), co, provider))
.filter(|co| {
validate_extension::<Self::LangMarker>(
locale.id.clone(),
key!("co"),
co,
&provider,
)
})
})
.filter(|co| co != &value!("search"));
@ -151,7 +157,7 @@ where
impl BuiltIn for Collator {
const NAME: &'static str = "Collator";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let compare = FunctionBuilder::native(context, Self::compare)
@ -195,7 +201,7 @@ impl Collator {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
// 2. Let internalSlotsList be « [[InitializedCollator]], [[Locale]], [[Usage]], [[Sensitivity]], [[IgnorePunctuation]], [[Collation]], [[BoundCompare]] ».
@ -260,7 +266,7 @@ impl Collator {
// 18. Let relevantExtensionKeys be %Collator%.[[RelevantExtensionKeys]].
// 19. Let r be ResolveLocale(%Collator%.[[AvailableLocales]], requestedLocales, opt, relevantExtensionKeys, localeData).
let mut locale =
resolve_locale::<Self, _>(&requested_locales, &mut intl_options, context.icu());
resolve_locale::<Self>(&requested_locales, &mut intl_options, context.icu());
let collator_locale = {
// `collator_locale` needs to be different from the resolved locale because ECMA402 doesn't
@ -365,7 +371,7 @@ impl Collator {
fn supported_locales_of(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let locales = args.get_or_undefined(0);
let options = args.get_or_undefined(1);
@ -375,11 +381,7 @@ impl Collator {
let requested_locales = canonicalize_locale_list(locales, context)?;
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
supported_locales::<<Self as Service<BoaProvider>>::LangMarker>(
&requested_locales,
options,
context,
)
supported_locales::<<Self as Service>::LangMarker>(&requested_locales, options, context)
.map(JsValue::from)
}
@ -392,7 +394,7 @@ impl Collator {
///
/// [spec]: https://tc39.es/ecma402/#sec-intl.collator.prototype.compare
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare
fn compare(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn compare(this: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let collator be the this value.
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
let this = this.as_object().ok_or_else(|| {
@ -461,7 +463,11 @@ impl Collator {
///
/// [spec]: https://tc39.es/ecma402/#sec-intl.collator.prototype.resolvedoptions
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/resolvedOptions
fn resolved_options(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn resolved_options(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let collator be the this value.
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
let collator = this.as_object().map(JsObject::borrow).ok_or_else(|| {

8
boa_engine/src/builtins/intl/date_time_format.rs

@ -25,7 +25,7 @@ use icu_datetime::options::preferences::HourCycle;
use super::options::OptionType;
impl OptionType for HourCycle {
fn from_value(value: JsValue, context: &mut Context) -> JsResult<Self> {
fn from_value(value: JsValue, context: &mut Context<'_>) -> JsResult<Self> {
match value.to_string(context)?.to_std_string_escaped().as_str() {
"h11" => Ok(HourCycle::H11),
"h12" => Ok(HourCycle::H12),
@ -65,7 +65,7 @@ pub struct DateTimeFormat {
impl DateTimeFormat {
const NAME: &'static str = "DateTimeFormat";
pub(super) fn init(context: &mut Context) -> JsFunction {
pub(super) fn init(context: &mut Context<'_>) -> JsFunction {
let _timer = Profiler::global().start_event(Self::NAME, "init");
ConstructorBuilder::new(context, Self::constructor)
@ -87,7 +87,7 @@ impl DateTimeFormat {
pub(crate) fn constructor(
new_target: &JsValue,
_args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
let prototype = get_prototype_from_constructor(
@ -159,7 +159,7 @@ pub(crate) fn to_date_time_options(
options: &JsValue,
required: &DateTimeReqs,
defaults: &DateTimeReqs,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// 1. If options is undefined, let options be null;
// otherwise let options be ? ToObject(options).

33
boa_engine/src/builtins/intl/list_format/mod.rs

@ -8,7 +8,7 @@ use tap::{Conv, Pipe};
use crate::{
builtins::{Array, BuiltIn, JsArgs},
context::{intrinsics::StandardConstructors, BoaProvider},
context::intrinsics::StandardConstructors,
object::{
internal_methods::get_prototype_from_constructor, ConstructorBuilder, JsObject, ObjectData,
},
@ -43,7 +43,7 @@ impl std::fmt::Debug for ListFormat {
}
}
impl<P> Service<P> for ListFormat {
impl Service for ListFormat {
type LangMarker = AndListV1Marker;
type LocaleOptions = ();
@ -52,7 +52,7 @@ impl<P> Service<P> for ListFormat {
impl BuiltIn for ListFormat {
const NAME: &'static str = "ListFormat";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
ConstructorBuilder::with_standard_constructor(
@ -92,7 +92,7 @@ impl ListFormat {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, throw a TypeError exception.
if new_target.is_undefined() {
@ -119,7 +119,7 @@ impl ListFormat {
// 8. Let localeData be %ListFormat%.[[LocaleData]].
// 9. Let r be ResolveLocale(%ListFormat%.[[AvailableLocales]], requestedLocales, opt, %ListFormat%.[[RelevantExtensionKeys]], localeData).
// 10. Set listFormat.[[Locale]] to r.[[locale]].
let locale = resolve_locale::<Self, _>(
let locale = resolve_locale::<Self>(
&requested_locales,
&mut IntlOptions {
matcher,
@ -177,7 +177,7 @@ impl ListFormat {
fn supported_locales_of(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let locales = args.get_or_undefined(0);
let options = args.get_or_undefined(1);
@ -187,11 +187,7 @@ impl ListFormat {
let requested_locales = canonicalize_locale_list(locales, context)?;
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
supported_locales::<<Self as Service<BoaProvider>>::LangMarker>(
&requested_locales,
options,
context,
)
supported_locales::<<Self as Service>::LangMarker>(&requested_locales, options, context)
.map(JsValue::from)
}
@ -204,7 +200,7 @@ impl ListFormat {
///
/// [spec]: https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype.format
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format
fn format(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn format(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
let lf = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -239,7 +235,7 @@ impl ListFormat {
fn format_to_parts(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// TODO: maybe try to move this into icu4x?
use writeable::{PartsWrite, Writeable};
@ -394,7 +390,11 @@ impl ListFormat {
///
/// [spec]: https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype.resolvedoptions
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions
fn resolved_options(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn resolved_options(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
let lf = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -452,7 +452,10 @@ impl ListFormat {
/// Abstract operation [`StringListFromIterable ( iterable )`][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-createstringlistfromiterable
fn string_list_from_iterable(iterable: &JsValue, context: &mut Context) -> JsResult<Vec<JsString>> {
fn string_list_from_iterable(
iterable: &JsValue,
context: &mut Context<'_>,
) -> JsResult<Vec<JsString>> {
// 1. If iterable is undefined, then
if iterable.is_undefined() {
// a. Return a new empty List.

2
boa_engine/src/builtins/intl/list_format/options.rs

@ -40,7 +40,7 @@ impl FromStr for ListFormatType {
impl OptionTypeParsable for ListFormatType {}
impl OptionType for ListLength {
fn from_value(value: JsValue, context: &mut Context) -> JsResult<Self> {
fn from_value(value: JsValue, context: &mut Context<'_>) -> JsResult<Self> {
match value.to_string(context)?.to_std_string_escaped().as_str() {
"long" => Ok(Self::Wide),
"short" => Ok(Self::Short),

58
boa_engine/src/builtins/intl/locale/mod.rs

@ -37,7 +37,7 @@ pub(crate) struct Locale;
impl BuiltIn for Locale {
const NAME: &'static str = "Locale";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let base_name = FunctionBuilder::native(context, Self::base_name)
@ -141,7 +141,7 @@ impl Locale {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, throw a TypeError exception.
if new_target.is_undefined() {
@ -360,7 +360,7 @@ impl Locale {
pub(crate) fn maximize(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
@ -393,7 +393,7 @@ impl Locale {
pub(crate) fn minimize(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
@ -423,7 +423,11 @@ impl Locale {
///
/// [spec]: https://tc39.es/ecma402/#sec-Intl.Locale.prototype.toString
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/toString
pub(crate) fn to_string(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn to_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
let loc = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -444,7 +448,11 @@ impl Locale {
///
/// [spec]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName
/// [mdn]: https://tc39.es/ecma402/#sec-Intl.Locale.prototype.baseName
pub(crate) fn base_name(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn base_name(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
let loc = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -468,7 +476,11 @@ impl Locale {
///
/// [spec]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar
/// [mdn]: https://tc39.es/ecma402/#sec-Intl.Locale.prototype.calendar
pub(crate) fn calendar(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn calendar(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
let loc = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -497,7 +509,11 @@ impl Locale {
///
/// [spec]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar
/// [mdn]: https://tc39.es/ecma402/#sec-Intl.Locale.prototype.calendar
pub(crate) fn case_first(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn case_first(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
let loc = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -526,7 +542,11 @@ impl Locale {
///
/// [spec]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation
/// [mdn]: https://tc39.es/ecma402/#sec-Intl.Locale.prototype.collation
pub(crate) fn collation(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn collation(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
let loc = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -555,7 +575,11 @@ impl Locale {
///
/// [spec]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle
/// [mdn]: https://tc39.es/ecma402/#sec-Intl.Locale.prototype.hourCycle
pub(crate) fn hour_cycle(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn hour_cycle(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
let loc = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -584,7 +608,7 @@ impl Locale {
///
/// [spec]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric
/// [mdn]: https://tc39.es/ecma402/#sec-Intl.Locale.prototype.numeric
pub(crate) fn numeric(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn numeric(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
let loc = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -620,7 +644,7 @@ impl Locale {
pub(crate) fn numbering_system(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
@ -650,7 +674,11 @@ impl Locale {
///
/// [spec]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language
/// [mdn]: https://tc39.es/ecma402/#sec-Intl.Locale.prototype.language
pub(crate) fn language(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn language(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
let loc = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -675,7 +703,7 @@ impl Locale {
///
/// [spec]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script
/// [mdn]: https://tc39.es/ecma402/#sec-Intl.Locale.prototype.script
pub(crate) fn script(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn script(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
let loc = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -705,7 +733,7 @@ impl Locale {
///
/// [spec]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region
/// [mdn]: https://tc39.es/ecma402/#sec-Intl.Locale.prototype.region
pub(crate) fn region(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn region(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
let loc = this.as_object().map(JsObject::borrow).ok_or_else(|| {

4
boa_engine/src/builtins/intl/locale/options.rs

@ -1,9 +1,9 @@
use icu_locid::extensions::unicode::Value;
use crate::{builtins::intl::options::OptionType, JsNativeError};
use crate::{builtins::intl::options::OptionType, Context, JsNativeError};
impl OptionType for Value {
fn from_value(value: crate::JsValue, context: &mut crate::Context) -> crate::JsResult<Self> {
fn from_value(value: crate::JsValue, context: &mut Context<'_>) -> crate::JsResult<Self> {
let val = value
.to_string(context)?
.to_std_string_escaped()

25
boa_engine/src/builtins/intl/locale/tests.rs

@ -8,7 +8,6 @@ use icu_locid::{
};
use icu_plurals::provider::CardinalV1Marker;
use icu_provider::{DataLocale, DataProvider, DataRequest, DataRequestMetadata};
use icu_provider_adapters::fallback::LocaleFallbackProvider;
use crate::{
builtins::intl::{
@ -26,15 +25,12 @@ struct TestOptions {
struct TestService;
impl<P> Service<P> for TestService
where
P: DataProvider<TimeLengthsV1Marker>,
{
impl Service for TestService {
type LangMarker = CardinalV1Marker;
type LocaleOptions = TestOptions;
fn resolve(locale: &mut Locale, options: &mut Self::LocaleOptions, provider: &P) {
fn resolve(locale: &mut Locale, options: &mut Self::LocaleOptions, provider: BoaProvider<'_>) {
let loc_hc = locale
.extensions
.unicode
@ -53,7 +49,7 @@ where
locale: &DataLocale::from(&*locale),
metadata: DataRequestMetadata::default(),
};
let preferred = DataProvider::<TimeLengthsV1Marker>::load(provider, req)
let preferred = DataProvider::<TimeLengthsV1Marker>::load(&provider, req)
.unwrap()
.take_payload()
.unwrap()
@ -77,9 +73,8 @@ where
#[test]
fn locale_resolution() {
let provider =
LocaleFallbackProvider::try_new_with_buffer_provider(boa_icu_provider::blob()).unwrap();
let icu = Icu::new(BoaProvider::Buffer(Box::new(provider))).unwrap();
let provider = boa_icu_provider::buffer();
let icu = Icu::new(BoaProvider::Buffer(provider)).unwrap();
let mut default = default_locale(icu.locale_canonicalizer());
default
.extensions
@ -94,7 +89,7 @@ fn locale_resolution() {
hc: Some(HourCycle::H11),
},
};
let locale = resolve_locale::<TestService, _>(&[], &mut options, &icu);
let locale = resolve_locale::<TestService>(&[], &mut options, &icu);
assert_eq!(locale, default);
// test best fit
@ -105,10 +100,10 @@ fn locale_resolution() {
},
};
let locale = resolve_locale::<TestService, _>(&[], &mut options, &icu);
let best = best_locale_for_provider::<<TestService as Service<BoaProvider>>::LangMarker>(
let locale = resolve_locale::<TestService>(&[], &mut options, &icu);
let best = best_locale_for_provider::<<TestService as Service>::LangMarker>(
default.id.clone(),
icu.provider(),
&icu.provider(),
)
.unwrap();
let mut best = Locale::from(best);
@ -121,6 +116,6 @@ fn locale_resolution() {
service_options: TestOptions { hc: None },
};
let locale = resolve_locale::<TestService, _>(&[locale!("es-AR")], &mut options, &icu);
let locale = resolve_locale::<TestService>(&[locale!("es-AR")], &mut options, &icu);
assert_eq!(locale, "es-u-hc-h23".parse().unwrap());
}

50
boa_engine/src/builtins/intl/locale/utils.rs

@ -58,7 +58,7 @@ pub(crate) fn default_locale(canonicalizer: &LocaleCanonicalizer) -> Locale {
/// [canon]: https://unicode.org/reports/tr35/#LocaleId_Canonicalization
pub(crate) fn canonicalize_locale_list(
locales: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Vec<Locale>> {
// 1. If locales is undefined, then
if locales.is_undefined() {
@ -265,10 +265,13 @@ pub(crate) fn best_locale_for_provider<M: KeyedDataMarker>(
/// in order to see if a certain [`Locale`] is supported.
///
/// [spec]: https://tc39.es/ecma402/#sec-lookupmatcher
fn lookup_matcher<M: KeyedDataMarker>(
fn lookup_matcher<'provider, M: KeyedDataMarker>(
requested_locales: &[Locale],
icu: &Icu<impl DataProvider<M>>,
) -> Locale {
icu: &Icu<'provider>,
) -> Locale
where
BoaProvider<'provider>: DataProvider<M>,
{
// 1. Let result be a new Record.
// 2. For each element locale of requestedLocales, do
for locale in requested_locales {
@ -278,7 +281,7 @@ fn lookup_matcher<M: KeyedDataMarker>(
let id = std::mem::take(&mut locale.id);
// b. Let availableLocale be ! BestAvailableLocale(availableLocales, noExtensionsLocale).
let available_locale = best_available_locale::<M>(id, icu.provider());
let available_locale = best_available_locale::<M>(id, &icu.provider());
// c. If availableLocale is not undefined, then
if let Some(available_locale) = available_locale {
@ -310,10 +313,13 @@ fn lookup_matcher<M: KeyedDataMarker>(
/// produced by the `LookupMatcher` abstract operation.
///
/// [spec]: https://tc39.es/ecma402/#sec-bestfitmatcher
fn best_fit_matcher<M: KeyedDataMarker>(
fn best_fit_matcher<'provider, M: KeyedDataMarker>(
requested_locales: &[Locale],
icu: &Icu<impl DataProvider<M>>,
) -> Locale {
icu: &Icu<'provider>,
) -> Locale
where
BoaProvider<'provider>: DataProvider<M>,
{
for mut locale in requested_locales
.iter()
.cloned()
@ -323,7 +329,7 @@ fn best_fit_matcher<M: KeyedDataMarker>(
{
let id = std::mem::take(&mut locale.id);
if let Some(available) = best_locale_for_provider(id, icu.provider()) {
if let Some(available) = best_locale_for_provider(id, &icu.provider()) {
locale.id = available;
return locale;
@ -343,14 +349,14 @@ fn best_fit_matcher<M: KeyedDataMarker>(
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-resolvelocale
pub(in crate::builtins::intl) fn resolve_locale<S, P>(
pub(in crate::builtins::intl) fn resolve_locale<'provider, S>(
requested_locales: &[Locale],
options: &mut IntlOptions<S::LocaleOptions>,
icu: &Icu<P>,
icu: &Icu<'provider>,
) -> Locale
where
S: Service<P>,
P: DataProvider<S::LangMarker>,
S: Service,
BoaProvider<'provider>: DataProvider<S::LangMarker>,
{
// 1. Let matcher be options.[[localeMatcher]].
// 2. If matcher is "lookup", then
@ -479,13 +485,13 @@ fn best_fit_supported_locales<M: KeyedDataMarker>(
/// availableLocales has a matching locale
///
/// [spec]: https://tc39.es/ecma402/#sec-supportedlocales
pub(in crate::builtins::intl) fn supported_locales<M: KeyedDataMarker>(
pub(in crate::builtins::intl) fn supported_locales<'ctx, 'icu: 'ctx, M: KeyedDataMarker>(
requested_locales: &[Locale],
options: &JsValue,
context: &mut Context,
context: &'ctx mut Context<'icu>,
) -> JsResult<JsObject>
where
BoaProvider: DataProvider<M>,
BoaProvider<'icu>: DataProvider<M>,
{
// 1. Set options to ? CoerceOptionsToObject(options).
let options = coerce_options_to_object(options, context)?;
@ -498,12 +504,12 @@ where
// 4. Else,
// a. Let supportedLocales be LookupSupportedLocales(availableLocales, requestedLocales).
LocaleMatcher::Lookup => {
lookup_supported_locales(requested_locales, context.icu().provider())
lookup_supported_locales(requested_locales, &context.icu().provider())
}
// 3. If matcher is "best fit", then
// a. Let supportedLocales be BestFitSupportedLocales(availableLocales, requestedLocales).
LocaleMatcher::BestFit => {
best_fit_supported_locales(requested_locales, context.icu().provider())
best_fit_supported_locales(requested_locales, &context.icu().provider())
}
};
@ -541,7 +547,6 @@ mod tests {
use icu_locid::{langid, locale, Locale};
use icu_plurals::provider::CardinalV1Marker;
use icu_provider::AsDeserializingBufferProvider;
use icu_provider_adapters::fallback::LocaleFallbackProvider;
use crate::{
builtins::intl::locale::utils::{
@ -552,7 +557,7 @@ mod tests {
#[test]
fn best_avail_loc() {
let provider = boa_icu_provider::blob();
let provider = boa_icu_provider::buffer();
let provider = provider.as_deserializing();
assert_eq!(
@ -573,9 +578,8 @@ mod tests {
#[test]
fn lookup_match() {
let provider =
LocaleFallbackProvider::try_new_with_buffer_provider(boa_icu_provider::blob()).unwrap();
let icu = Icu::new(BoaProvider::Buffer(Box::new(provider))).unwrap();
let provider = boa_icu_provider::buffer();
let icu = Icu::new(BoaProvider::Buffer(provider)).unwrap();
// requested: []

21
boa_engine/src/builtins/intl/mod.rs

@ -13,6 +13,7 @@ use super::JsArgs;
use crate::{
builtins::intl::date_time_format::DateTimeFormat,
builtins::{Array, BuiltIn},
context::BoaProvider,
object::ObjectInitializer,
property::Attribute,
symbol::WellKnownSymbols,
@ -39,7 +40,7 @@ pub(crate) struct Intl;
impl BuiltIn for Intl {
const NAME: &'static str = "Intl";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let collator = Collator::init(context).expect("initialization should return a constructor");
@ -106,7 +107,7 @@ impl Intl {
pub(crate) fn get_canonical_locales(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let locales = args.get_or_undefined(0);
@ -121,11 +122,11 @@ impl Intl {
}
}
// Making `provider: &BoaProvider` instead of a type parameter `P` makes it so that we need
// to copy-paste the bounds of `impl<M> DataProvider<M> for BoaProvider` every time we need
// to use `provider`. The type parameter solves this by delegating simpler bounds to every
// implementor of `Service`.
trait Service<P> {
/// A service component that is part of the `Intl` API.
///
/// This needs to be implemented for every `Intl` service in order to use the functions
/// defined in `locale::utils`, such as locale resolution and selection.
trait Service {
/// The data marker used by [`resolve_locale`][locale::resolve_locale] to decide
/// which locales are supported by this service.
type LangMarker: KeyedDataMarker;
@ -145,6 +146,10 @@ trait Service<P> {
/// new final values.
/// - If the implementor service doesn't contain any `[[RelevantExtensionKeys]]`, this can be
/// skipped.
fn resolve(_locale: &mut icu_locid::Locale, _options: &mut Self::LocaleOptions, _provider: &P) {
fn resolve(
_locale: &mut icu_locid::Locale,
_options: &mut Self::LocaleOptions,
_provider: BoaProvider<'_>,
) {
}
}

18
boa_engine/src/builtins/intl/options.rs

@ -27,7 +27,7 @@ pub(super) trait OptionType: Sized {
/// steps instead of returning a pure string, number or boolean.
///
/// [spec]: https://tc39.es/ecma402/#sec-getoption
fn from_value(value: JsValue, context: &mut Context) -> JsResult<Self>;
fn from_value(value: JsValue, context: &mut Context<'_>) -> JsResult<Self>;
}
pub(super) trait OptionTypeParsable: FromStr {}
@ -36,7 +36,7 @@ impl<T: OptionTypeParsable> OptionType for T
where
T::Err: Display,
{
fn from_value(value: JsValue, context: &mut Context) -> JsResult<Self> {
fn from_value(value: JsValue, context: &mut Context<'_>) -> JsResult<Self> {
value
.to_string(context)?
.to_std_string_escaped()
@ -46,7 +46,7 @@ where
}
impl OptionType for bool {
fn from_value(value: JsValue, _: &mut Context) -> JsResult<Self> {
fn from_value(value: JsValue, _: &mut Context<'_>) -> JsResult<Self> {
// 5. If type is "boolean", then
// a. Set value to ! ToBoolean(value).
Ok(value.to_boolean())
@ -54,7 +54,7 @@ impl OptionType for bool {
}
impl OptionType for JsString {
fn from_value(value: JsValue, context: &mut Context) -> JsResult<Self> {
fn from_value(value: JsValue, context: &mut Context<'_>) -> JsResult<Self> {
// 6. If type is "string", then
// a. Set value to ? ToString(value).
value.to_string(context)
@ -92,7 +92,7 @@ impl FromStr for LocaleMatcher {
impl OptionTypeParsable for LocaleMatcher {}
impl OptionType for CaseFirst {
fn from_value(value: JsValue, context: &mut Context) -> JsResult<Self> {
fn from_value(value: JsValue, context: &mut Context<'_>) -> JsResult<Self> {
match value.to_string(context)?.to_std_string_escaped().as_str() {
"upper" => Ok(CaseFirst::UpperFirst),
"lower" => Ok(CaseFirst::LowerFirst),
@ -122,7 +122,7 @@ pub(super) fn get_option<T: OptionType>(
options: &JsObject,
property: &str,
required: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Option<T>> {
// 1. Let value be ? Get(options, property).
let value = options.get(property, context)?;
@ -161,7 +161,7 @@ pub(super) fn get_number_option(
minimum: f64,
maximum: f64,
fallback: Option<f64>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Option<f64>> {
// 1. Assert: Type(options) is Object.
// 2. Let value be ? Get(options, property).
@ -183,7 +183,7 @@ pub(super) fn default_number_option(
minimum: f64,
maximum: f64,
fallback: Option<f64>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Option<f64>> {
// 1. If value is undefined, return fallback.
if value.is_undefined() {
@ -239,7 +239,7 @@ pub(super) fn get_options_object(options: &JsValue) -> JsResult<JsObject> {
/// [spec]: https://tc39.es/ecma402/#sec-coerceoptionstoobject
pub(super) fn coerce_options_to_object(
options: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// If options is undefined, then
if options.is_undefined() {

8
boa_engine/src/builtins/intl/segmenter/mod.rs

@ -15,7 +15,7 @@ pub(crate) struct Segmenter;
impl BuiltIn for Segmenter {
const NAME: &'static str = "Segmenter";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
ConstructorBuilder::with_standard_constructor(
@ -35,7 +35,11 @@ impl Segmenter {
pub(crate) const LENGTH: usize = 0;
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn constructor(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn constructor(
_: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(JsValue::Undefined)
}
}

12
boa_engine/src/builtins/iterable/async_from_sync_iterator.rs

@ -17,7 +17,7 @@ use boa_profiler::Profiler;
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%-object
pub(crate) fn create_async_from_sync_iterator_prototype(context: &mut Context) -> JsObject {
pub(crate) fn create_async_from_sync_iterator_prototype(context: &mut Context<'_>) -> JsObject {
let _timer = Profiler::global().start_event("AsyncFromSyncIteratorPrototype", "init");
let prototype = JsObject::from_proto_and_data(
@ -95,7 +95,7 @@ impl AsyncFromSyncIterator {
/// [spec]: https://tc39.es/ecma262/#sec-createasyncfromsynciterator
pub(crate) fn create(
sync_iterator_record: IteratorRecord,
context: &mut Context,
context: &mut Context<'_>,
) -> IteratorRecord {
// 1. Let asyncIterator be OrdinaryObjectCreate(%AsyncFromSyncIteratorPrototype%, « [[SyncIteratorRecord]] »).
// 2. Set asyncIterator.[[SyncIteratorRecord]] to syncIteratorRecord.
@ -126,7 +126,7 @@ impl AsyncFromSyncIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.next
fn next(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn next(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
// 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]].
@ -170,7 +170,7 @@ impl AsyncFromSyncIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.return
fn r#return(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn r#return(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
// 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]].
@ -268,7 +268,7 @@ impl AsyncFromSyncIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.throw
fn throw(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn throw(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
// 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]].
@ -369,7 +369,7 @@ impl AsyncFromSyncIterator {
fn continuation(
result: &IteratorResult,
promise_capability: &PromiseCapability,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. NOTE: Because promiseCapability is derived from the intrinsic %Promise%,
// the calls to promiseCapability.[[Reject]] entailed by the

22
boa_engine/src/builtins/iterable/mod.rs

@ -51,7 +51,7 @@ pub struct IteratorPrototypes {
}
impl IteratorPrototypes {
pub(crate) fn init(context: &mut Context) -> Self {
pub(crate) fn init(context: &mut Context<'_>) -> Self {
let _timer = Profiler::global().start_event("IteratorPrototypes::init", "init");
let iterator_prototype = create_iterator_prototype(context);
@ -131,7 +131,7 @@ impl IteratorPrototypes {
/// `CreateIterResultObject( value, done )`
///
/// Generates an object supporting the `IteratorResult` interface.
pub fn create_iter_result_object(value: JsValue, done: bool, context: &mut Context) -> JsValue {
pub fn create_iter_result_object(value: JsValue, done: bool, context: &mut Context<'_>) -> JsValue {
let _timer = Profiler::global().start_event("create_iter_result_object", "init");
// 1. Assert: Type(done) is Boolean.
@ -167,7 +167,7 @@ impl JsValue {
/// [spec]: https://tc39.es/ecma262/#sec-getiterator
pub fn get_iterator(
&self,
context: &mut Context,
context: &mut Context<'_>,
hint: Option<IteratorHint>,
method: Option<JsObject>,
) -> JsResult<IteratorRecord> {
@ -236,7 +236,7 @@ impl JsValue {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%iteratorprototype%-object
fn create_iterator_prototype(context: &mut Context) -> JsObject {
fn create_iterator_prototype(context: &mut Context<'_>) -> JsObject {
let _timer = Profiler::global().start_event("Iterator Prototype", "init");
let symbol_iterator = WellKnownSymbols::iterator();
@ -272,7 +272,7 @@ impl IteratorResult {
///
/// [spec]: https://tc39.es/ecma262/#sec-iteratorcomplete
#[inline]
pub fn complete(&self, context: &mut Context) -> JsResult<bool> {
pub fn complete(&self, context: &mut Context<'_>) -> JsResult<bool> {
// 1. Return ToBoolean(? Get(iterResult, "done")).
Ok(self.object.get("done", context)?.to_boolean())
}
@ -288,7 +288,7 @@ impl IteratorResult {
///
/// [spec]: https://tc39.es/ecma262/#sec-iteratorvalue
#[inline]
pub fn value(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn value(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Return ? Get(iterResult, "value").
self.object.get("value", context)
}
@ -365,7 +365,7 @@ impl IteratorRecord {
pub(crate) fn next(
&self,
value: Option<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<IteratorResult> {
let _timer = Profiler::global().start_event("IteratorRecord::next", "iterator");
@ -409,7 +409,7 @@ impl IteratorRecord {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-iteratorstep
pub(crate) fn step(&self, context: &mut Context) -> JsResult<Option<IteratorResult>> {
pub(crate) fn step(&self, context: &mut Context<'_>) -> JsResult<Option<IteratorResult>> {
let _timer = Profiler::global().start_event("IteratorRecord::step", "iterator");
// 1. Let result be ? IteratorNext(iteratorRecord).
@ -441,7 +441,7 @@ impl IteratorRecord {
pub(crate) fn close(
&self,
completion: JsResult<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let _timer = Profiler::global().start_event("IteratorRecord::close", "iterator");
@ -501,7 +501,7 @@ impl IteratorRecord {
///
/// [spec]: https://tc39.es/ecma262/#sec-iterabletolist
pub(crate) fn iterable_to_list(
context: &mut Context,
context: &mut Context<'_>,
items: &JsValue,
method: Option<JsObject>,
) -> JsResult<Vec<JsValue>> {
@ -560,7 +560,7 @@ pub(crate) use if_abrupt_close_iterator;
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-asynciteratorprototype
fn create_async_iterator_prototype(context: &mut Context) -> JsObject {
fn create_async_iterator_prototype(context: &mut Context<'_>) -> JsObject {
let _timer = Profiler::global().start_event("AsyncIteratorPrototype", "init");
let symbol_iterator = WellKnownSymbols::async_iterator();

18
boa_engine/src/builtins/json/mod.rs

@ -138,7 +138,7 @@ pub(crate) struct Json;
impl BuiltIn for Json {
const NAME: &'static str = "JSON";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let to_string_tag = WellKnownSymbols::to_string_tag();
@ -167,7 +167,11 @@ impl Json {
///
/// [spec]: https://tc39.es/ecma262/#sec-json.parse
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
pub(crate) fn parse(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn parse(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let jsonString be ? ToString(text).
let json_string = args
.get(0)
@ -229,7 +233,7 @@ impl Json {
holder: &JsObject,
name: JsString,
reviver: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let val be ? Get(holder, name).
let val = holder.get(name.clone(), context)?;
@ -319,7 +323,7 @@ impl Json {
pub(crate) fn stringify(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let stack be a new empty List.
let stack = Vec::new();
@ -469,7 +473,7 @@ impl Json {
state: &mut StateRecord,
key: JsString,
holder: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Option<JsString>> {
// 1. Let value be ? Get(holder, key).
let mut value = holder.get(key.clone(), context)?;
@ -640,7 +644,7 @@ impl Json {
fn serialize_json_object(
state: &mut StateRecord,
value: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsString> {
// 1. If state.[[Stack]] contains value, throw a TypeError exception because the structure is cyclical.
let limiter = RecursionLimiter::new(value);
@ -768,7 +772,7 @@ impl Json {
fn serialize_json_array(
state: &mut StateRecord,
value: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsString> {
// 1. If state.[[Stack]] contains value, throw a TypeError exception because the structure is cyclical.
let limiter = RecursionLimiter::new(value);

10
boa_engine/src/builtins/map/map_iterator.rs

@ -46,7 +46,7 @@ impl MapIterator {
pub(crate) fn create_map_iterator(
map: &JsValue,
kind: PropertyNameKind,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if let Some(map_obj) = map.as_object() {
if let Some(map) = map_obj.borrow_mut().as_map_mut() {
@ -81,7 +81,11 @@ impl MapIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%mapiteratorprototype%.next
pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn next(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let mut map_iterator = this.as_object().map(JsObject::borrow_mut);
let map_iterator = map_iterator
.as_mut()
@ -134,7 +138,7 @@ impl MapIterator {
/// [spec]: https://tc39.es/ecma262/#sec-%mapiteratorprototype%-object
pub(crate) fn create_prototype(
iterator_prototype: JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsObject {
let _timer = Profiler::global().start_event(Self::NAME, "init");

40
boa_engine/src/builtins/map/mod.rs

@ -39,7 +39,7 @@ pub(crate) struct Map;
impl BuiltIn for Map {
const NAME: &'static str = "Map";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let get_species = FunctionBuilder::native(context, Self::get_species)
@ -118,7 +118,7 @@ impl Map {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, throw a TypeError exception.
if new_target.is_undefined() {
@ -157,7 +157,7 @@ impl Map {
/// [spec]: https://tc39.es/ecma262/#sec-get-map-@@species
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/@@species
#[allow(clippy::unnecessary_wraps)]
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Return the this value.
Ok(this.clone())
}
@ -175,7 +175,7 @@ impl Map {
pub(crate) fn entries(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let M be the this value.
// 2. Return ? CreateMapIterator(M, key+value).
@ -192,7 +192,11 @@ impl Map {
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.keys
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys
pub(crate) fn keys(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn keys(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let M be the this value.
// 2. Return ? CreateMapIterator(M, key).
MapIterator::create_map_iterator(this, PropertyNameKind::Key, context)
@ -208,7 +212,7 @@ impl Map {
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.set
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set
pub(crate) fn set(this: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn set(this: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
let key = args.get_or_undefined(0);
let value = args.get_or_undefined(1);
@ -255,7 +259,11 @@ impl Map {
///
/// [spec]: https://tc39.es/ecma262/#sec-get-map.prototype.size
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size
pub(crate) fn get_size(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn get_size(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let M be the this value.
if let Some(object) = this.as_object() {
// 2. Perform ? RequireInternalSlot(M, [[MapData]]).
@ -284,7 +292,11 @@ impl Map {
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.delete
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete
pub(crate) fn delete(this: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn delete(
this: &JsValue,
args: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
let key = args.get_or_undefined(0);
// 1. Let M be the this value.
@ -315,7 +327,7 @@ impl Map {
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.get
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get
pub(crate) fn get(this: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn get(this: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
const JS_ZERO: &JsValue = &JsValue::Rational(0f64);
let key = args.get_or_undefined(0);
@ -357,7 +369,7 @@ impl Map {
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.clear
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear
pub(crate) fn clear(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn clear(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let M be the this value.
// 2. Perform ? RequireInternalSlot(M, [[MapData]]).
if let Some(object) = this.as_object() {
@ -387,7 +399,7 @@ impl Map {
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.has
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has
pub(crate) fn has(this: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn has(this: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
const JS_ZERO: &JsValue = &JsValue::Rational(0f64);
let key = args.get_or_undefined(0);
@ -432,7 +444,7 @@ impl Map {
pub(crate) fn for_each(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let M be the this value.
// 2. Perform ? RequireInternalSlot(M, [[MapData]]).
@ -503,7 +515,7 @@ impl Map {
pub(crate) fn values(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let M be the this value.
// 2. Return ? CreateMapIterator(M, value).
@ -523,7 +535,7 @@ pub(crate) fn add_entries_from_iterable(
target: &JsObject,
iterable: &JsValue,
adder: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If IsCallable(adder) is false, throw a TypeError exception.
let adder = adder.as_callable().ok_or_else(|| {

204
boa_engine/src/builtins/math/mod.rs

@ -29,7 +29,7 @@ pub(crate) struct Math;
impl BuiltIn for Math {
const NAME: &'static str = "Math";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let attribute = Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT;
@ -98,7 +98,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.abs
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs
pub(crate) fn abs(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn abs(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -120,7 +124,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.acos
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos
pub(crate) fn acos(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn acos(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -140,7 +148,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.acosh
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh
pub(crate) fn acosh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn acosh(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -161,7 +173,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.asin
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin
pub(crate) fn asin(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn asin(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -181,7 +197,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.asinh
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh
pub(crate) fn asinh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn asinh(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -200,7 +220,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.atan
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan
pub(crate) fn atan(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn atan(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -221,7 +245,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.atanh
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh
pub(crate) fn atanh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn atanh(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -243,7 +271,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.atan2
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2
pub(crate) fn atan2(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn atan2(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let ny be ? ToNumber(y).
let y = args.get_or_undefined(0).to_number(context)?;
@ -286,7 +318,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.cbrt
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt
pub(crate) fn cbrt(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn cbrt(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -305,7 +341,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.ceil
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil
pub(crate) fn ceil(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn ceil(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -326,7 +366,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.clz32
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
pub(crate) fn clz32(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn clz32(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToUint32(x).
@ -345,7 +389,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.cos
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos
pub(crate) fn cos(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn cos(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -365,7 +413,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.cosh
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh
pub(crate) fn cosh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn cosh(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -386,7 +438,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.exp
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp
pub(crate) fn exp(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn exp(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -409,7 +465,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.expm1
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1
pub(crate) fn expm1(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn expm1(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -429,7 +489,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.floor
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
pub(crate) fn floor(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn floor(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -453,7 +517,7 @@ impl Math {
pub(crate) fn fround(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let n be ? ToNumber(x).
let x = args.get_or_undefined(0).to_number(context)?;
@ -474,7 +538,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.hypot
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot
pub(crate) fn hypot(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn hypot(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let coerced be a new empty List.
// 2. For each element arg of args, do
// a. Let n be ? ToNumber(arg).
@ -504,7 +572,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.imul
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
pub(crate) fn imul(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn imul(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let a be ℝ(? ToUint32(x)).
let x = args.get_or_undefined(0).to_u32(context)?;
@ -524,7 +596,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.log
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log
pub(crate) fn log(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn log(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -546,7 +622,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.log1p
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p
pub(crate) fn log1p(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn log1p(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -567,7 +647,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.log10
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10
pub(crate) fn log10(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn log10(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -589,7 +673,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.log2
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2
pub(crate) fn log2(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn log2(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -611,7 +699,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.max
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max
pub(crate) fn max(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn max(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let coerced be a new empty List.
// 2. For each element arg of args, do
// b. Append n to coerced.
@ -649,7 +741,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.min
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min
pub(crate) fn min(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn min(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let coerced be a new empty List.
// 2. For each element arg of args, do
// b. Append n to coerced.
@ -688,7 +784,11 @@ impl Math {
/// [spec]: https://tc39.es/ecma262/#sec-math.pow
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow
#[allow(clippy::float_cmp)]
pub(crate) fn pow(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn pow(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Set base to ? ToNumber(base).
let x = args.get_or_undefined(0).to_number(context)?;
@ -713,7 +813,7 @@ impl Math {
/// [spec]: https://tc39.es/ecma262/#sec-math.random
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn random(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn random(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// NOTE: Each Math.random function created for distinct realms must produce a distinct sequence of values from successive calls.
Ok(rand::random::<f64>().into())
}
@ -727,7 +827,11 @@ impl Math {
/// [spec]: https://tc39.es/ecma262/#sec-math.round
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
#[allow(clippy::float_cmp)]
pub(crate) fn round(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn round(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let num = args
.get_or_undefined(0)
//1. Let n be ? ToNumber(x).
@ -753,7 +857,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.sign
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
pub(crate) fn sign(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn sign(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let n be ? ToNumber(x).
let n = args.get_or_undefined(0).to_number(context)?;
@ -774,7 +882,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.sin
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin
pub(crate) fn sin(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn sin(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -794,7 +906,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.sinh
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh
pub(crate) fn sinh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn sinh(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -813,7 +929,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.sqrt
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt
pub(crate) fn sqrt(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn sqrt(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -833,7 +953,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.tan
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan
pub(crate) fn tan(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn tan(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -853,7 +977,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.tanh
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh
pub(crate) fn tanh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn tanh(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).
@ -874,7 +1002,11 @@ impl Math {
///
/// [spec]: https://tc39.es/ecma262/#sec-math.trunc
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
pub(crate) fn trunc(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn trunc(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args
.get_or_undefined(0)
// 1. Let n be ? ToNumber(x).

6
boa_engine/src/builtins/mod.rs

@ -116,12 +116,12 @@ pub(crate) trait BuiltIn {
///
/// A return value of `None` indicates that the value must not be added as a global attribute
/// for the global object.
fn init(context: &mut Context) -> Option<JsValue>;
fn init(context: &mut Context<'_>) -> Option<JsValue>;
}
/// Utility function that checks if a type implements `BuiltIn` before initializing it as a global
/// built-in.
fn init_builtin<B: BuiltIn>(context: &mut Context) {
fn init_builtin<B: BuiltIn>(context: &mut Context<'_>) {
if let Some(value) = B::init(context) {
let property = PropertyDescriptor::builder()
.value(value)
@ -136,7 +136,7 @@ fn init_builtin<B: BuiltIn>(context: &mut Context) {
}
/// Initializes built-in objects and functions
pub fn init(context: &mut Context) {
pub fn init(context: &mut Context<'_>) {
macro_rules! globals {
($( $builtin:ty ),*) => {
$(init_builtin::<$builtin>(context)

2
boa_engine/src/builtins/nan/mod.rs

@ -27,7 +27,7 @@ impl BuiltIn for NaN {
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::PERMANENT);
fn init(_: &mut Context) -> Option<JsValue> {
fn init(_: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
Some(f64::NAN.into())

36
boa_engine/src/builtins/number/mod.rs

@ -47,7 +47,7 @@ pub(crate) struct Number;
impl BuiltIn for Number {
const NAME: &'static str = "Number";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let parse_int = FunctionBuilder::native(context, Self::parse_int)
@ -173,7 +173,7 @@ impl Number {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let data = match args.get(0) {
Some(value) => value.to_numeric_number(context)?,
@ -222,7 +222,7 @@ impl Number {
pub(crate) fn to_exponential(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let x be ? thisNumberValue(this value).
let this_num = Self::this_number_value(this)?;
@ -267,7 +267,7 @@ impl Number {
pub(crate) fn to_fixed(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let this_num be ? thisNumberValue(this value).
let this_num = Self::this_number_value(this)?;
@ -316,7 +316,7 @@ impl Number {
pub(crate) fn to_locale_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
let this_num = Self::this_number_value(this)?;
let this_str_num = this_num.to_string();
@ -424,7 +424,7 @@ impl Number {
pub(crate) fn to_precision(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let precision = args.get_or_undefined(0);
@ -675,7 +675,7 @@ impl Number {
pub(crate) fn to_string(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let x be ? thisNumberValue(this value).
let x = Self::this_number_value(this)?;
@ -734,7 +734,11 @@ impl Number {
///
/// [spec]: https://tc39.es/ecma262/#sec-number.prototype.valueof
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf
pub(crate) fn value_of(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn value_of(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(JsValue::new(Self::this_number_value(this)?))
}
@ -755,7 +759,7 @@ impl Number {
pub(crate) fn parse_int(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if let (Some(val), radix) = (args.get(0), args.get_or_undefined(1)) {
// 1. Let inputString be ? ToString(string).
@ -880,7 +884,7 @@ impl Number {
pub(crate) fn parse_float(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if let Some(val) = args.get(0) {
// TODO: parse float with optimal utf16 algorithm
@ -934,7 +938,7 @@ impl Number {
pub(crate) fn global_is_finite(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if let Some(value) = args.get(0) {
let number = value.to_number(context)?;
@ -961,7 +965,7 @@ impl Number {
pub(crate) fn global_is_nan(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if let Some(value) = args.get(0) {
let number = value.to_number(context)?;
@ -989,7 +993,7 @@ impl Number {
pub(crate) fn number_is_finite(
_: &JsValue,
args: &[JsValue],
_ctx: &mut Context,
_ctx: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If number is not a Number, return false.
// 2. If number is not finite, return false.
@ -1015,7 +1019,7 @@ impl Number {
pub(crate) fn number_is_integer(
_: &JsValue,
args: &[JsValue],
_ctx: &mut Context,
_ctx: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(args.get(0).map_or(false, Self::is_integer).into())
}
@ -1038,7 +1042,7 @@ impl Number {
pub(crate) fn number_is_nan(
_: &JsValue,
args: &[JsValue],
_ctx: &mut Context,
_ctx: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(JsValue::new(
if let Some(&JsValue::Rational(number)) = args.get(0) {
@ -1067,7 +1071,7 @@ impl Number {
pub(crate) fn is_safe_integer(
_: &JsValue,
args: &[JsValue],
_ctx: &mut Context,
_ctx: &mut Context<'_>,
) -> JsResult<JsValue> {
Ok(JsValue::new(match args.get(0) {
Some(JsValue::Integer(_)) => true,

10
boa_engine/src/builtins/object/for_in_iterator.rs

@ -54,7 +54,7 @@ impl ForInIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-createforiniterator
pub(crate) fn create_for_in_iterator(object: JsValue, context: &Context) -> JsValue {
pub(crate) fn create_for_in_iterator(object: JsValue, context: &Context<'_>) -> JsValue {
let for_in_iterator = JsObject::from_proto_and_data(
context
.intrinsics()
@ -74,7 +74,11 @@ impl ForInIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%foriniteratorprototype%.next
pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn next(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let mut iterator = this.as_object().map(JsObject::borrow_mut);
let iterator = iterator
.as_mut()
@ -135,7 +139,7 @@ impl ForInIterator {
/// [spec]: https://tc39.es/ecma262/#sec-%foriniteratorprototype%-object
pub(crate) fn create_prototype(
iterator_prototype: JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsObject {
let _timer = Profiler::global().start_event(Self::NAME, "init");

94
boa_engine/src/builtins/object/mod.rs

@ -45,7 +45,7 @@ pub struct Object;
impl BuiltIn for Object {
const NAME: &'static str = "Object";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let legacy_proto_getter = FunctionBuilder::native(context, Self::legacy_proto_getter)
@ -122,7 +122,7 @@ impl Object {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is neither undefined nor the active function object, then
if !new_target.is_undefined() {
@ -158,7 +158,7 @@ impl Object {
pub fn legacy_proto_getter(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let obj = this.to_object(context)?;
@ -183,7 +183,7 @@ impl Object {
pub fn legacy_proto_setter(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -228,7 +228,7 @@ impl Object {
pub fn legacy_define_getter(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let getter = args.get_or_undefined(1);
@ -271,7 +271,7 @@ impl Object {
pub fn legacy_define_setter(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let setter = args.get_or_undefined(1);
@ -314,7 +314,7 @@ impl Object {
pub fn legacy_lookup_getter(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let mut obj = this.to_object(context)?;
@ -358,7 +358,7 @@ impl Object {
pub fn legacy_lookup_setter(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let mut obj = this.to_object(context)?;
@ -400,7 +400,7 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.create
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create
pub fn create(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn create(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let prototype = args.get_or_undefined(0);
let properties = args.get_or_undefined(1);
@ -440,7 +440,7 @@ impl Object {
pub fn get_own_property_descriptor(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(O).
let obj = args.get_or_undefined(0).to_object(context)?;
@ -468,7 +468,7 @@ impl Object {
pub fn get_own_property_descriptors(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(O).
let obj = args.get_or_undefined(0).to_object(context)?;
@ -507,7 +507,7 @@ impl Object {
/// [spec]: https://tc39.es/ecma262/#sec-frompropertydescriptor
pub(crate) fn from_property_descriptor(
desc: Option<PropertyDescriptor>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsValue {
// 1. If Desc is undefined, return undefined.
let desc = if let Some(desc) = desc {
@ -567,7 +567,7 @@ impl Object {
}
/// Uses the `SameValue` algorithm to check equality of objects
pub fn is(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub fn is(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
let x = args.get_or_undefined(0);
let y = args.get_or_undefined(1);
@ -582,7 +582,7 @@ impl Object {
pub fn get_prototype_of(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if args.is_empty() {
return Err(JsNativeError::typ()
@ -609,7 +609,7 @@ impl Object {
pub fn set_prototype_of(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if args.len() < 2 {
return Err(JsNativeError::typ()
@ -674,7 +674,7 @@ impl Object {
pub fn is_prototype_of(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let v = args.get_or_undefined(0);
if !v.is_object() {
@ -697,7 +697,7 @@ impl Object {
pub fn define_property(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let object = args.get_or_undefined(0);
if let JsValue::Object(object) = object {
@ -733,7 +733,7 @@ impl Object {
pub fn define_properties(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let arg = args.get_or_undefined(0);
if let JsValue::Object(obj) = arg {
@ -755,7 +755,7 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.prototype.valueof
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf
pub fn value_of(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn value_of(this: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Return ? ToObject(this value).
Ok(this.to_object(context)?.into())
}
@ -771,7 +771,11 @@ impl Object {
/// [spec]: https://tc39.es/ecma262/#sec-object.prototype.tostring
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
#[allow(clippy::wrong_self_convention)]
pub fn to_string(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn to_string(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If the this value is undefined, return "[object Undefined]".
if this.is_undefined() {
return Ok("[object Undefined]".into());
@ -832,7 +836,7 @@ impl Object {
pub fn to_locale_string(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Return ? Invoke(O, "toString").
@ -853,7 +857,7 @@ impl Object {
pub fn has_own_property(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let P be ? ToPropertyKey(V).
let key = args.get_or_undefined(0).to_property_key(context)?;
@ -879,7 +883,7 @@ impl Object {
pub fn property_is_enumerable(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let key = match args.get(0) {
None => return Ok(JsValue::new(false)),
@ -910,7 +914,7 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.assign
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
pub fn assign(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn assign(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let to be ? ToObject(target).
let to = args.get_or_undefined(0).to_object(context)?;
@ -960,7 +964,7 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.keys
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
pub fn keys(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn keys(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(target).
let obj = args
.get(0)
@ -985,7 +989,7 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.values
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values
pub fn values(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn values(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(target).
let obj = args
.get(0)
@ -1014,7 +1018,7 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.entries
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
pub fn entries(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn entries(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(target).
let obj = args
.get(0)
@ -1040,7 +1044,7 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.seal
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal
pub fn seal(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn seal(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let o = args.get_or_undefined(0);
if let Some(o) = o.as_object() {
@ -1066,7 +1070,11 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.issealed
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
pub fn is_sealed(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn is_sealed(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let o = args.get_or_undefined(0);
// 1. If Type(O) is not Object, return true.
@ -1087,7 +1095,7 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.freeze
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
pub fn freeze(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn freeze(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let o = args.get_or_undefined(0);
if let Some(o) = o.as_object() {
@ -1113,7 +1121,11 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.isfrozen
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
pub fn is_frozen(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn is_frozen(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let o = args.get_or_undefined(0);
// 1. If Type(O) is not Object, return true.
@ -1137,7 +1149,7 @@ impl Object {
pub fn prevent_extensions(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let o = args.get_or_undefined(0);
@ -1167,7 +1179,7 @@ impl Object {
pub fn is_extensible(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let o = args.get_or_undefined(0);
// 1. If Type(O) is not Object, return false.
@ -1190,7 +1202,7 @@ impl Object {
pub fn get_own_property_names(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Return ? GetOwnPropertyKeys(O, string).
let o = args.get_or_undefined(0);
@ -1208,7 +1220,7 @@ impl Object {
pub fn get_own_property_symbols(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Return ? GetOwnPropertyKeys(O, symbol).
let o = args.get_or_undefined(0);
@ -1223,7 +1235,7 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.hasown
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn
pub fn has_own(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn has_own(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(O).
let obj = args.get_or_undefined(0).to_object(context)?;
@ -1242,7 +1254,11 @@ impl Object {
///
/// [spec]: https://tc39.es/ecma262/#sec-object.fromentries
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries
pub fn from_entries(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn from_entries(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Perform ? RequireObjectCoercible(iterable).
let iterable = args.get_or_undefined(0).require_object_coercible()?;
@ -1287,7 +1303,7 @@ impl Object {
fn object_define_properties(
object: &JsObject,
props: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<()> {
// 1. Assert: Type(O) is Object.
// 2. Let props be ? ToObject(Properties).
@ -1345,7 +1361,7 @@ enum PropertyKeyType {
fn get_own_property_keys(
o: &JsValue,
r#type: PropertyKeyType,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let obj be ? ToObject(o).
let obj = o.to_object(context)?;

60
boa_engine/src/builtins/promise/mod.rs

@ -128,7 +128,7 @@ impl PromiseCapability {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-newpromisecapability
pub(crate) fn new(c: &JsValue, context: &mut Context) -> JsResult<Self> {
pub(crate) fn new(c: &JsValue, context: &mut Context<'_>) -> JsResult<Self> {
#[derive(Debug, Clone, Trace, Finalize)]
struct RejectResolve {
reject: JsValue,
@ -251,7 +251,7 @@ impl BuiltIn for Promise {
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let get_species = FunctionBuilder::native(context, Self::get_species)
@ -316,7 +316,7 @@ impl Promise {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, throw a TypeError exception.
if new_target.is_undefined() {
@ -386,7 +386,7 @@ impl Promise {
pub(crate) fn all(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let C be the this value.
let c = this;
@ -448,7 +448,7 @@ impl Promise {
constructor: &JsObject,
result_capability: &PromiseCapability,
promise_resolve: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
#[derive(Debug, Trace, Finalize)]
struct ResolveElementCaptures {
@ -627,7 +627,7 @@ impl Promise {
pub(crate) fn all_settled(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let C be the this value.
let c = this;
@ -689,7 +689,7 @@ impl Promise {
constructor: &JsObject,
result_capability: &PromiseCapability,
promise_resolve: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
#[derive(Debug, Trace, Finalize)]
struct ResolveRejectElementCaptures {
@ -966,7 +966,7 @@ impl Promise {
pub(crate) fn any(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let C be the this value.
let c = this;
@ -1028,7 +1028,7 @@ impl Promise {
constructor: &JsObject,
result_capability: &PromiseCapability,
promise_resolve: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
#[derive(Debug, Trace, Finalize)]
struct RejectElementCaptures {
@ -1240,7 +1240,7 @@ impl Promise {
/// [spec]: https://tc39.es/ecma262/#sec-createresolvingfunctions
fn create_resolving_functions(
promise: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> ResolvingFunctionsRecord {
#[derive(Debug, Trace, Finalize)]
struct RejectResolveCaptures {
@ -1442,7 +1442,7 @@ impl Promise {
/// # Panics
///
/// Panics if `Promise` is not pending.
fn fulfill_promise(&mut self, value: &JsValue, context: &mut Context) {
fn fulfill_promise(&mut self, value: &JsValue, context: &mut Context<'_>) {
// 1. Assert: The value of promise.[[PromiseState]] is pending.
assert!(
matches!(self.promise_state, PromiseState::Pending),
@ -1482,7 +1482,7 @@ impl Promise {
/// # Panics
///
/// Panics if `Promise` is not pending.
pub fn reject_promise(&mut self, reason: &JsValue, context: &mut Context) {
pub fn reject_promise(&mut self, reason: &JsValue, context: &mut Context<'_>) {
// 1. Assert: The value of promise.[[PromiseState]] is pending.
assert!(
matches!(self.promise_state, PromiseState::Pending),
@ -1530,7 +1530,7 @@ impl Promise {
fn trigger_promise_reactions(
reactions: &[ReactionRecord],
argument: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) {
// 1. For each element reaction of reactions, do
for reaction in reactions {
@ -1556,7 +1556,7 @@ impl Promise {
///
/// [spec]: https://tc39.es/ecma262/#sec-promise.race
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race
pub fn race(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn race(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let iterable = args.get_or_undefined(0);
// 1. Let C be the this value.
@ -1621,7 +1621,7 @@ impl Promise {
constructor: &JsValue,
result_capability: &PromiseCapability,
promise_resolve: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Repeat,
loop {
@ -1679,7 +1679,11 @@ impl Promise {
///
/// [spec]: https://tc39.es/ecma262/#sec-promise.reject
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject
pub fn reject(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn reject(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let r = args.get_or_undefined(0);
// 1. Let C be the this value.
@ -1706,7 +1710,11 @@ impl Promise {
///
/// [spec]: https://tc39.es/ecma262/#sec-promise.resolve
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve
pub fn resolve(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn resolve(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let x = args.get_or_undefined(0);
// 1. Let C be the this value.
@ -1734,7 +1742,7 @@ impl Promise {
/// [spec]: https://tc39.es/ecma262/#sec-get-promise-@@species
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/@@species
#[allow(clippy::unnecessary_wraps)]
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Return the this value.
Ok(this.clone())
}
@ -1747,7 +1755,7 @@ impl Promise {
///
/// [spec]: https://tc39.es/ecma262/#sec-promise.prototype.catch
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
pub fn catch(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn catch(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let on_rejected = args.get_or_undefined(0);
// 1. Let promise be the this value.
@ -1768,7 +1776,11 @@ impl Promise {
///
/// [spec]: https://tc39.es/ecma262/#sec-promise.prototype.finally
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally
pub fn finally(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn finally(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let promise be the this value.
let promise = this;
@ -1914,7 +1926,7 @@ impl Promise {
///
/// [spec]: https://tc39.es/ecma262/#sec-promise.prototype.then
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
pub fn then(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn then(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let promise be the this value.
let promise = this;
@ -1957,7 +1969,7 @@ impl Promise {
on_fulfilled: &JsValue,
on_rejected: &JsValue,
result_capability: Option<PromiseCapability>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsValue {
// 1. Assert: IsPromise(promise) is true.
@ -2067,7 +2079,7 @@ impl Promise {
pub(crate) fn promise_resolve(
c: JsObject,
x: JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If IsPromise(x) is true, then
if let Some(x) = x.as_promise() {
@ -2103,7 +2115,7 @@ impl Promise {
/// [spec]: https://tc39.es/ecma262/#sec-getpromiseresolve
fn get_promise_resolve(
promise_constructor: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// 1. Let promiseResolve be ? Get(promiseConstructor, "resolve").
let promise_resolve = promise_constructor.get("resolve", context)?;

6
boa_engine/src/builtins/promise/promise_job.rs

@ -18,7 +18,7 @@ impl PromiseJob {
pub(crate) fn new_promise_reaction_job(
reaction: ReactionRecord,
argument: JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JobCallback {
#[derive(Debug, Trace, Finalize)]
struct ReactionJobCaptures {
@ -118,12 +118,12 @@ impl PromiseJob {
promise_to_resolve: JsObject,
thenable: JsValue,
then: JobCallback,
context: &mut Context,
context: &mut Context<'_>,
) -> JobCallback {
// 1. Let job be a new Job Abstract Closure with no parameters that captures promiseToResolve, thenable, and then and performs the following steps when called:
let job = FunctionBuilder::closure_with_captures(
context,
|_this: &JsValue, _args: &[JsValue], captures, context: &mut Context| {
|_this: &JsValue, _args: &[JsValue], captures, context: &mut Context<'_>| {
let JobCapture {
promise_to_resolve,
thenable,

10
boa_engine/src/builtins/proxy/mod.rs

@ -29,7 +29,7 @@ pub struct Proxy {
impl BuiltIn for Proxy {
const NAME: &'static str = "Proxy";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
ConstructorBuilder::with_standard_constructor(
@ -76,7 +76,7 @@ impl Proxy {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, throw a TypeError exception.
if new_target.is_undefined() {
@ -98,7 +98,7 @@ impl Proxy {
pub(crate) fn create(
target: &JsValue,
handler: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// 1. If Type(target) is not Object, throw a TypeError exception.
let target = target.as_object().ok_or_else(|| {
@ -131,7 +131,7 @@ impl Proxy {
Ok(p)
}
pub(crate) fn revoker(proxy: JsObject, context: &mut Context) -> JsFunction {
pub(crate) fn revoker(proxy: JsObject, context: &mut Context<'_>) -> JsFunction {
// 3. Let revoker be ! CreateBuiltinFunction(revokerClosure, 0, "", « [[RevocableProxy]] »).
// 4. Set revoker.[[RevocableProxy]] to p.
FunctionBuilder::closure_with_captures(
@ -165,7 +165,7 @@ impl Proxy {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-proxy.revocable
fn revocable(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn revocable(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let p be ? ProxyCreate(target, handler).
let p = Self::create(args.get_or_undefined(0), args.get_or_undefined(1), context)?;

44
boa_engine/src/builtins/reflect/mod.rs

@ -32,7 +32,7 @@ pub(crate) struct Reflect;
impl BuiltIn for Reflect {
const NAME: &'static str = "Reflect";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let to_string_tag = WellKnownSymbols::to_string_tag();
@ -75,7 +75,11 @@ impl Reflect {
///
/// [spec]: https://tc39.es/ecma262/#sec-reflect.apply
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply
pub(crate) fn apply(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn apply(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let target = args
.get(0)
.and_then(JsValue::as_object)
@ -103,7 +107,7 @@ impl Reflect {
pub(crate) fn construct(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If IsConstructor(target) is false, throw a TypeError exception.
let target = args
@ -143,7 +147,7 @@ impl Reflect {
pub(crate) fn define_property(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -174,7 +178,7 @@ impl Reflect {
pub(crate) fn delete_property(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -193,7 +197,11 @@ impl Reflect {
///
/// [spec]: https://tc39.es/ecma262/#sec-reflect.get
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get
pub(crate) fn get(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn get(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If Type(target) is not Object, throw a TypeError exception.
let target = args
.get(0)
@ -222,7 +230,7 @@ impl Reflect {
pub(crate) fn get_own_property_descriptor(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if args.get_or_undefined(0).is_object() {
// This function is the same as Object.prototype.getOwnPropertyDescriptor, that why
@ -250,7 +258,7 @@ impl Reflect {
pub(crate) fn get_prototype_of(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -269,7 +277,11 @@ impl Reflect {
///
/// [spec]: https://tc39.es/ecma262/#sec-reflect.has
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has
pub(crate) fn has(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn has(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let target = args
.get(0)
.and_then(JsValue::as_object)
@ -292,7 +304,7 @@ impl Reflect {
pub(crate) fn is_extensible(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -312,7 +324,7 @@ impl Reflect {
pub(crate) fn own_keys(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -339,7 +351,7 @@ impl Reflect {
pub(crate) fn prevent_extensions(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -357,7 +369,11 @@ impl Reflect {
///
/// [spec]: https://tc39.es/ecma262/#sec-reflect.set
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set
pub(crate) fn set(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn set(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let target = args
.get(0)
.and_then(JsValue::as_object)
@ -384,7 +400,7 @@ impl Reflect {
pub(crate) fn set_prototype_of(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let target = args
.get(0)

56
boa_engine/src/builtins/regexp/mod.rs

@ -50,7 +50,7 @@ pub struct RegExp {
impl BuiltIn for RegExp {
const NAME: &'static str = "RegExp";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let get_species = FunctionBuilder::native(context, Self::get_species)
@ -169,7 +169,7 @@ impl RegExp {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let pattern = args.get_or_undefined(0);
let flags = args.get_or_undefined(1);
@ -232,7 +232,7 @@ impl RegExp {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-regexpalloc
pub(crate) fn alloc(new_target: &JsValue, context: &mut Context) -> JsResult<JsObject> {
pub(crate) fn alloc(new_target: &JsValue, context: &mut Context<'_>) -> JsResult<JsObject> {
// 1. Let obj be ? OrdinaryCreateFromConstructor(newTarget, "%RegExp.prototype%", « [[RegExpMatcher]], [[OriginalSource]], [[OriginalFlags]] »).
let proto =
get_prototype_from_constructor(new_target, StandardConstructors::regexp, context)?;
@ -264,7 +264,7 @@ impl RegExp {
obj: JsObject,
pattern: &JsValue,
flags: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If pattern is undefined, let P be the empty String.
// 2. Else, let P be ? ToString(pattern).
@ -331,7 +331,7 @@ impl RegExp {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-regexpcreate
pub(crate) fn create(p: &JsValue, f: &JsValue, context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn create(p: &JsValue, f: &JsValue, context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let obj be ? RegExpAlloc(%RegExp%).
let obj = Self::alloc(
&context.global_object().clone().get(Self::NAME, context)?,
@ -353,12 +353,12 @@ impl RegExp {
/// [spec]: https://tc39.es/ecma262/#sec-get-regexp-@@species
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@species
#[allow(clippy::unnecessary_wraps)]
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Return the this value.
Ok(this.clone())
}
fn regexp_has_flag(this: &JsValue, flag: u8, context: &mut Context) -> JsResult<JsValue> {
fn regexp_has_flag(this: &JsValue, flag: u8, context: &mut Context<'_>) -> JsResult<JsValue> {
if let Some(object) = this.as_object() {
if let Some(regexp) = object.borrow().as_regexp() {
return Ok(JsValue::new(match flag {
@ -410,7 +410,7 @@ impl RegExp {
pub(crate) fn get_has_indices(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Self::regexp_has_flag(this, b'd', context)
}
@ -428,7 +428,7 @@ impl RegExp {
pub(crate) fn get_global(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Self::regexp_has_flag(this, b'g', context)
}
@ -446,7 +446,7 @@ impl RegExp {
pub(crate) fn get_ignore_case(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Self::regexp_has_flag(this, b'i', context)
}
@ -464,7 +464,7 @@ impl RegExp {
pub(crate) fn get_multiline(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Self::regexp_has_flag(this, b'm', context)
}
@ -482,7 +482,7 @@ impl RegExp {
pub(crate) fn get_dot_all(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Self::regexp_has_flag(this, b's', context)
}
@ -501,7 +501,7 @@ impl RegExp {
pub(crate) fn get_unicode(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Self::regexp_has_flag(this, b'u', context)
}
@ -520,7 +520,7 @@ impl RegExp {
pub(crate) fn get_sticky(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Self::regexp_has_flag(this, b'y', context)
}
@ -539,7 +539,7 @@ impl RegExp {
pub(crate) fn get_flags(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let R be the this value.
// 2. If Type(R) is not Object, throw a TypeError exception.
@ -610,7 +610,7 @@ impl RegExp {
pub(crate) fn get_source(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let R be the this value.
// 2. If Type(R) is not Object, throw a TypeError exception.
@ -694,7 +694,7 @@ impl RegExp {
pub(crate) fn test(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let R be the this value.
// 2. If Type(R) is not Object, throw a TypeError exception.
@ -736,7 +736,7 @@ impl RegExp {
pub(crate) fn exec(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let R be the this value.
// 2. Perform ? RequireInternalSlot(R, [[RegExpMatcher]]).
@ -764,7 +764,7 @@ impl RegExp {
pub(crate) fn abstract_exec(
this: &JsObject,
input: JsString,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Option<JsObject>> {
// 1. Assert: Type(R) is Object.
// 2. Assert: Type(S) is String.
@ -808,7 +808,7 @@ impl RegExp {
pub(crate) fn abstract_builtin_exec(
this: &JsObject,
input: &JsString,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Option<JsObject>> {
// 1. Assert: R is an initialized RegExp instance.
let rx = {
@ -1036,7 +1036,7 @@ impl RegExp {
pub(crate) fn r#match(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let rx be the this value.
// 2. If Type(rx) is not Object, throw a TypeError exception.
@ -1126,7 +1126,11 @@ impl RegExp {
/// [spec]: https://tc39.es/ecma262/#sec-regexp.prototype.tostring
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString
#[allow(clippy::wrong_self_convention)]
pub(crate) fn to_string(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn to_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
let (body, flags) = if let Some(object) = this.as_object() {
let object = object.borrow();
let regex = object.as_regexp().ok_or_else(|| {
@ -1160,7 +1164,7 @@ impl RegExp {
pub(crate) fn match_all(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let R be the this value.
// 2. If Type(R) is not Object, throw a TypeError exception.
@ -1220,7 +1224,7 @@ impl RegExp {
pub(crate) fn replace(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let rx be the this value.
// 2. If Type(rx) is not Object, throw a TypeError exception.
@ -1436,7 +1440,7 @@ impl RegExp {
pub(crate) fn search(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let rx be the this value.
// 2. If Type(rx) is not Object, throw a TypeError exception.
@ -1490,7 +1494,7 @@ impl RegExp {
pub(crate) fn split(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let rx be the this value.
// 2. If Type(rx) is not Object, throw a TypeError exception.

6
boa_engine/src/builtins/regexp/regexp_string_iterator.rs

@ -60,7 +60,7 @@ impl RegExpStringIterator {
string: JsString,
global: bool,
unicode: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsValue {
// TODO: Implement this with closures and generators.
// For now all values of the closure are stored in RegExpStringIterator and the actual closure execution is in `.next()`.
@ -92,7 +92,7 @@ impl RegExpStringIterator {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%regexpstringiteratorprototype%.next
pub fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn next(this: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let mut iterator = this.as_object().map(JsObject::borrow_mut);
let iterator = iterator
.as_mut()
@ -164,7 +164,7 @@ impl RegExpStringIterator {
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object
pub(crate) fn create_prototype(
iterator_prototype: JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsObject {
let _timer = Profiler::global().start_event("RegExp String Iterator", "init");

30
boa_engine/src/builtins/set/mod.rs

@ -38,7 +38,7 @@ pub(crate) struct Set;
impl BuiltIn for Set {
const NAME: &'static str = "Set";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let get_species = FunctionBuilder::native(context, Self::get_species)
@ -114,7 +114,7 @@ impl Set {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, throw a TypeError exception.
if new_target.is_undefined() {
@ -167,7 +167,7 @@ impl Set {
}
/// Utility for constructing `Set` objects.
pub(crate) fn set_create(prototype: Option<JsObject>, context: &mut Context) -> JsObject {
pub(crate) fn set_create(prototype: Option<JsObject>, context: &mut Context<'_>) -> JsObject {
let prototype =
prototype.unwrap_or_else(|| context.intrinsics().constructors().set().prototype());
@ -175,7 +175,7 @@ impl Set {
}
/// Utility for constructing `Set` objects from an iterator of `JsValue`'s.
pub(crate) fn create_set_from_list<I>(elements: I, context: &mut Context) -> JsObject
pub(crate) fn create_set_from_list<I>(elements: I, context: &mut Context<'_>) -> JsObject
where
I: IntoIterator<Item = JsValue>,
{
@ -201,7 +201,7 @@ impl Set {
/// [spec]: https://tc39.es/ecma262/#sec-get-set-@@species
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/@@species
#[allow(clippy::unnecessary_wraps)]
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Return the this value.
Ok(this.clone())
}
@ -216,7 +216,7 @@ impl Set {
///
/// [spec]: https://tc39.es/ecma262/#sec-set.prototype.add
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add
pub(crate) fn add(this: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn add(this: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
let value = args.get_or_undefined(0);
if let Some(object) = this.as_object() {
@ -250,7 +250,7 @@ impl Set {
///
/// [spec]: https://tc39.es/ecma262/#sec-set.prototype.clear
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear
pub(crate) fn clear(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn clear(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
let mut object = this
.as_object()
.map(JsObject::borrow_mut)
@ -276,7 +276,11 @@ impl Set {
///
/// [spec]: https://tc39.es/ecma262/#sec-set.prototype.delete
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete
pub(crate) fn delete(this: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn delete(
this: &JsValue,
args: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
let value = args.get_or_undefined(0);
let mut object = this
@ -304,7 +308,7 @@ impl Set {
pub(crate) fn entries(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if let Some(object) = this.as_object() {
let object = object.borrow();
@ -339,7 +343,7 @@ impl Set {
pub(crate) fn for_each(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if args.is_empty() {
return Err(JsNativeError::typ()
@ -390,7 +394,7 @@ impl Set {
///
/// [spec]: https://tc39.es/ecma262/#sec-map.prototype.has
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has
pub(crate) fn has(this: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn has(this: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
let value = args.get_or_undefined(0);
this.as_object()
@ -415,7 +419,7 @@ impl Set {
pub(crate) fn values(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
if let Some(object) = this.as_object() {
let object = object.borrow();
@ -437,7 +441,7 @@ impl Set {
))
}
fn size_getter(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn size_getter(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
Self::get_size(this).map(JsValue::from)
}

10
boa_engine/src/builtins/set/set_iterator.rs

@ -53,7 +53,7 @@ impl SetIterator {
pub(crate) fn create_set_iterator(
set: JsValue,
kind: PropertyNameKind,
context: &Context,
context: &Context<'_>,
) -> JsValue {
let set_iterator = JsObject::from_proto_and_data(
context
@ -74,7 +74,11 @@ impl SetIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%setiteratorprototype%.next
pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn next(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let mut set_iterator = this.as_object().map(JsObject::borrow_mut);
let set_iterator = set_iterator
@ -141,7 +145,7 @@ impl SetIterator {
/// [spec]: https://tc39.es/ecma262/#sec-%setiteratorprototype%-object
pub(crate) fn create_prototype(
iterator_prototype: JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsObject {
let _timer = Profiler::global().start_event(Self::NAME, "init");

102
boa_engine/src/builtins/string/mod.rs

@ -66,7 +66,7 @@ pub(crate) struct String;
impl BuiltIn for String {
const NAME: &'static str = "String";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let symbol_iterator = WellKnownSymbols::iterator();
@ -138,7 +138,7 @@ impl String {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// This value is used by console.log and other routines to match Object type
// to its Javascript Identifier (global constructor method name)
@ -173,7 +173,7 @@ impl String {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-stringcreate
fn string_create(value: JsString, prototype: JsObject, context: &mut Context) -> JsObject {
fn string_create(value: JsString, prototype: JsObject, context: &mut Context<'_>) -> JsObject {
// 7. Let length be the number of code unit elements in value.
let len = value.len();
@ -238,7 +238,7 @@ impl String {
pub(crate) fn from_code_point(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let result be the empty String.
let mut result = Vec::with_capacity(args.len());
@ -284,7 +284,11 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.raw
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw
pub(crate) fn raw(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn raw(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let substitutions = args.get(1..).unwrap_or_default();
// 1. Let numberOfSubstitutions be the number of elements in substitutions.
@ -358,7 +362,7 @@ impl String {
pub(crate) fn from_char_code(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let result be the empty String.
let mut result = Vec::new();
@ -383,7 +387,11 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.tostring
#[allow(clippy::wrong_self_convention)]
pub(crate) fn to_string(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn to_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Return ? thisStringValue(this value).
Ok(Self::this_string_value(this)?.into())
}
@ -407,7 +415,7 @@ impl String {
pub(crate) fn char_at(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -441,7 +449,11 @@ impl String {
///
/// [spec]: https://tc39.es/proposal-relative-indexing-method/#sec-string.prototype.at
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at
pub(crate) fn at(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn at(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -485,7 +497,7 @@ impl String {
pub(crate) fn code_point_at(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -528,7 +540,7 @@ impl String {
pub(crate) fn char_code_at(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -567,7 +579,7 @@ impl String {
pub(crate) fn concat(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -601,7 +613,7 @@ impl String {
pub(crate) fn repeat(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -654,7 +666,7 @@ impl String {
pub(crate) fn slice(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -719,7 +731,7 @@ impl String {
pub(crate) fn starts_with(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -788,7 +800,7 @@ impl String {
pub(crate) fn ends_with(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -854,7 +866,7 @@ impl String {
pub(crate) fn includes(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -906,7 +918,7 @@ impl String {
pub(crate) fn replace(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
this.require_object_coercible()?;
@ -1011,7 +1023,7 @@ impl String {
pub(crate) fn replace_all(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let o = this.require_object_coercible()?;
@ -1163,7 +1175,7 @@ impl String {
pub(crate) fn index_of(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -1207,7 +1219,7 @@ impl String {
pub(crate) fn last_index_of(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -1274,7 +1286,7 @@ impl String {
pub(crate) fn locale_compare(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let o = this.require_object_coercible()?;
@ -1315,7 +1327,7 @@ impl String {
// Default to common comparison if the user doesn't have `Intl` enabled.
#[cfg(not(feature = "intl"))]
{
s.cmp(&that_value) as i8;
s.cmp(&that_value) as i8
}
};
@ -1337,7 +1349,7 @@ impl String {
pub(crate) fn r#match(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let o = this.require_object_coercible()?;
@ -1377,7 +1389,7 @@ impl String {
max_length: &JsValue,
fill_string: &JsValue,
placement: Placement,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let S be ? ToString(O).
let string = object.to_string(context)?;
@ -1449,7 +1461,7 @@ impl String {
pub(crate) fn pad_end(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -1476,7 +1488,7 @@ impl String {
pub(crate) fn pad_start(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -1500,7 +1512,11 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.trim
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim
pub(crate) fn trim(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn trim(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let S be the this value.
// 2. Return ? TrimString(S, start+end).
let object = this.require_object_coercible()?;
@ -1523,7 +1539,7 @@ impl String {
pub(crate) fn trim_start(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let S be the this value.
// 2. Return ? TrimString(S, start).
@ -1547,7 +1563,7 @@ impl String {
pub(crate) fn trim_end(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let S be the this value.
// 2. Return ? TrimString(S, end).
@ -1570,7 +1586,7 @@ impl String {
pub(crate) fn to_lowercase(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -1628,7 +1644,7 @@ impl String {
pub(crate) fn to_uppercase(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// This function behaves in exactly the same way as `String.prototype.toLowerCase`, except that the String is
// mapped using the toUppercase algorithm of the Unicode Default Case Conversion.
@ -1688,7 +1704,7 @@ impl String {
pub(crate) fn substring(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -1738,7 +1754,7 @@ impl String {
pub(crate) fn substr(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -1801,7 +1817,7 @@ impl String {
pub(crate) fn split(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -1920,7 +1936,7 @@ impl String {
pub(crate) fn value_of(
this: &JsValue,
_args: &[JsValue],
_context: &mut Context,
_context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Return ? thisStringValue(this value).
Self::this_string_value(this).map(JsValue::from)
@ -1941,7 +1957,7 @@ impl String {
pub(crate) fn match_all(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let o = this.require_object_coercible()?;
@ -2000,7 +2016,7 @@ impl String {
pub(crate) fn normalize(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
use unicode_normalization::UnicodeNormalization;
/// Represents the type of normalization applied to a [`JsString`]
@ -2102,7 +2118,7 @@ impl String {
pub(crate) fn search(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let o = this.require_object_coercible()?;
@ -2132,7 +2148,7 @@ impl String {
pub(crate) fn iterator(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
StringIterator::create_string_iterator(this.clone(), context)
}
@ -2151,7 +2167,7 @@ pub(crate) fn get_substitution(
captures: &[JsValue],
named_captures: &JsValue,
replacement: &JsString,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsString> {
let mut buf = [0; 2];
// 1. Assert: Type(matched) is String.
@ -2337,7 +2353,7 @@ pub(crate) fn get_substitution(
/// [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-isregexp
fn is_reg_exp(argument: &JsValue, context: &mut Context) -> JsResult<bool> {
fn is_reg_exp(argument: &JsValue, context: &mut Context<'_>) -> JsResult<bool> {
// 1. If Type(argument) is not Object, return false.
let argument = match argument {
JsValue::Object(o) => o,
@ -2346,7 +2362,7 @@ fn is_reg_exp(argument: &JsValue, context: &mut Context) -> JsResult<bool> {
is_reg_exp_object(argument, context)
}
fn is_reg_exp_object(argument: &JsObject, context: &mut Context) -> JsResult<bool> {
fn is_reg_exp_object(argument: &JsObject, context: &mut Context<'_>) -> JsResult<bool> {
// 2. Let matcher be ? Get(argument, @@match).
let matcher = argument.get(WellKnownSymbols::r#match(), context)?;

6
boa_engine/src/builtins/string/string_iterator.rs

@ -30,7 +30,7 @@ pub struct StringIterator {
impl StringIterator {
/// Create a new `StringIterator`.
pub fn create_string_iterator(string: JsValue, context: &mut Context) -> JsResult<JsValue> {
pub fn create_string_iterator(string: JsValue, context: &mut Context<'_>) -> JsResult<JsValue> {
let string_iterator = JsObject::from_proto_and_data(
context
.intrinsics()
@ -46,7 +46,7 @@ impl StringIterator {
}
/// `StringIterator.prototype.next( )`
pub fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn next(this: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
let mut string_iterator = this.as_object().map(JsObject::borrow_mut);
let string_iterator = string_iterator
.as_mut()
@ -89,7 +89,7 @@ impl StringIterator {
/// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-object
pub(crate) fn create_prototype(
iterator_prototype: JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsObject {
let _timer = Profiler::global().start_event("String Iterator", "init");

28
boa_engine/src/builtins/symbol/mod.rs

@ -77,7 +77,7 @@ pub struct Symbol;
impl BuiltIn for Symbol {
const NAME: &'static str = "Symbol";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let symbol_async_iterator = WellKnownSymbols::async_iterator();
@ -173,7 +173,7 @@ impl Symbol {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is not undefined, throw a TypeError exception.
if !new_target.is_undefined() {
@ -215,7 +215,11 @@ impl Symbol {
/// [spec]: https://tc39.es/ecma262/#sec-symbol.prototype.tostring
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString
#[allow(clippy::wrong_self_convention)]
pub(crate) fn to_string(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn to_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let sym be ? thisSymbolValue(this value).
let symbol = Self::this_symbol_value(this)?;
@ -233,7 +237,11 @@ impl Symbol {
///
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf
/// [spec]: https://tc39.es/ecma262/#sec-symbol.prototype.valueof
pub(crate) fn value_of(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn value_of(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Return ? thisSymbolValue(this value).
let symbol = Self::this_symbol_value(this)?;
Ok(JsValue::Symbol(symbol))
@ -252,7 +260,7 @@ impl Symbol {
pub(crate) fn get_description(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let s be the this value.
// 2. Let sym be ? thisSymbolValue(s).
@ -272,7 +280,11 @@ impl Symbol {
///
/// [spec]: https://tc39.es/ecma262/#sec-symbol.prototype.for
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for
pub(crate) fn for_(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn for_(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let stringKey be ? ToString(key).
let string_key = args
.get(0)
@ -302,7 +314,7 @@ impl Symbol {
///
/// [spec]: https://tc39.es/ecma262/#sec-symbol.prototype.keyfor
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor
pub(crate) fn key_for(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn key_for(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
let sym = args.get_or_undefined(0);
// 1. If Type(sym) is not Symbol, throw a TypeError exception.
if let Some(sym) = sym.as_symbol() {
@ -337,7 +349,7 @@ impl Symbol {
pub(crate) fn to_primitive(
this: &JsValue,
_: &[JsValue],
_: &mut Context,
_: &mut Context<'_>,
) -> JsResult<JsValue> {
let sym = Self::this_symbol_value(this)?;
// 1. Return ? thisSymbolValue(this value).

118
boa_engine/src/builtins/typed_array/mod.rs

@ -52,7 +52,7 @@ macro_rules! typed_array {
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::CONFIGURABLE);
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
let typed_array_constructor = context
@ -118,7 +118,7 @@ macro_rules! typed_array {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, throw a TypeError exception.
if new_target.is_undefined() {
@ -249,7 +249,7 @@ pub(crate) struct TypedArray;
impl BuiltIn for TypedArray {
const NAME: &'static str = "TypedArray";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let get_species = FunctionBuilder::native(context, Self::get_species)
.name("get [Symbol.species]")
.constructor(false)
@ -383,7 +383,11 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%typedarray%
fn constructor(_new_target: &JsValue, _args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn constructor(
_new_target: &JsValue,
_args: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Throw a TypeError exception.
Err(JsNativeError::typ()
.with_message("the TypedArray constructor should never be called directly")
@ -396,7 +400,7 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%typedarray%.from
fn from(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn from(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let C be the this value.
// 2. If IsConstructor(C) is false, throw a TypeError exception.
let constructor = match this.as_object() {
@ -506,7 +510,7 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%typedarray%.of
fn of(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn of(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let len be the number of elements in items.
// 2. Let C be the this value.
@ -543,7 +547,7 @@ impl TypedArray {
///
/// [spec]: https://tc39.es/ecma262/#sec-get-%typedarray%-@@species
#[allow(clippy::unnecessary_wraps)]
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Return the this value.
Ok(this.clone())
}
@ -554,7 +558,11 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%typedarray%.prototype.at
pub(crate) fn at(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn at(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
let obj = this.as_object().ok_or_else(|| {
@ -604,7 +612,7 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.buffer
fn buffer(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn buffer(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
// 3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
@ -629,7 +637,11 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.bytelength
pub(crate) fn byte_length(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn byte_length(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
// 3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
@ -658,7 +670,11 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.byteoffset
pub(crate) fn byte_offset(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn byte_offset(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
// 3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
@ -687,7 +703,11 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%typedarray%.prototype.copywithin
fn copy_within(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn copy_within(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
let obj = this.as_object().ok_or_else(|| {
JsNativeError::typ().with_message("Value is not a typed array object")
@ -860,7 +880,7 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%typedarray%.prototype.entries
fn entries(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn entries(this: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
let o = this.as_object().ok_or_else(|| {
@ -893,7 +913,7 @@ impl TypedArray {
pub(crate) fn every(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -960,7 +980,7 @@ impl TypedArray {
pub(crate) fn fill(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1048,7 +1068,7 @@ impl TypedArray {
pub(crate) fn filter(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1136,7 +1156,7 @@ impl TypedArray {
pub(crate) fn find(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1202,7 +1222,7 @@ impl TypedArray {
pub(crate) fn findindex(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1266,7 +1286,7 @@ impl TypedArray {
pub(crate) fn foreach(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1325,7 +1345,7 @@ impl TypedArray {
pub(crate) fn includes(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1404,7 +1424,7 @@ impl TypedArray {
pub(crate) fn index_of(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1492,7 +1512,7 @@ impl TypedArray {
pub(crate) fn join(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1552,7 +1572,11 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%typedarray%.prototype.keys
pub(crate) fn keys(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn keys(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
let o = this.as_object().ok_or_else(|| {
@ -1585,7 +1609,7 @@ impl TypedArray {
pub(crate) fn last_index_of(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1662,7 +1686,7 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.length
pub(crate) fn length(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
pub(crate) fn length(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
// 3. Assert: O has [[ViewedArrayBuffer]] and [[ArrayLength]] internal slots.
@ -1694,7 +1718,7 @@ impl TypedArray {
pub(crate) fn map(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1760,7 +1784,7 @@ impl TypedArray {
pub(crate) fn reduce(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1845,7 +1869,7 @@ impl TypedArray {
pub(crate) fn reduceright(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1933,7 +1957,7 @@ impl TypedArray {
pub(crate) fn reverse(
this: &JsValue,
_: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1994,7 +2018,7 @@ impl TypedArray {
pub(crate) fn set(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let target be the this value.
// 2. Perform ? RequireInternalSlot(target, [[TypedArrayName]]).
@ -2054,7 +2078,7 @@ impl TypedArray {
target: &JsObject,
target_offset: IntegerOrInfinity,
source: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<()> {
let target_borrow = target.borrow();
let target_array = target_borrow
@ -2277,7 +2301,7 @@ impl TypedArray {
target: &JsObject,
target_offset: IntegerOrInfinity,
source: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<()> {
let target_borrow = target.borrow();
let target_array = target_borrow
@ -2396,7 +2420,7 @@ impl TypedArray {
pub(crate) fn slice(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -2569,7 +2593,7 @@ impl TypedArray {
pub(crate) fn some(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -2635,7 +2659,7 @@ impl TypedArray {
pub(crate) fn sort(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception.
let compare_fn = match args.get(0) {
@ -2702,7 +2726,7 @@ impl TypedArray {
let sort_compare = |x: &JsValue,
y: &JsValue,
compare_fn: Option<&JsObject>,
context: &mut Context|
context: &mut Context<'_>|
-> JsResult<Ordering> {
// 1. Assert: Both Type(x) and Type(y) are Number or both are BigInt.
// 2. If comparefn is not undefined, then
@ -2849,7 +2873,7 @@ impl TypedArray {
pub(crate) fn subarray(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
@ -2935,7 +2959,7 @@ impl TypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%typedarray%.prototype.values
fn values(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
fn values(this: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
let o = this.as_object().ok_or_else(|| {
@ -2966,7 +2990,7 @@ impl TypedArray {
///
/// [spec]: https://tc39.es/ecma262/#sec-get-%typedarray%.prototype-@@tostringtag
#[allow(clippy::unnecessary_wraps)]
fn to_string_tag(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn to_string_tag(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. If Type(O) is not Object, return undefined.
// 3. If O does not have a [[TypedArrayName]] internal slot, return undefined.
@ -2993,7 +3017,7 @@ impl TypedArray {
exemplar: &JsObject,
typed_array_name: TypedArrayKind,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// 1. Let defaultConstructor be the intrinsic object listed in column one of Table 73 for exemplar.[[TypedArrayName]].
let default_constructor = match typed_array_name {
@ -3044,7 +3068,7 @@ impl TypedArray {
fn create(
constructor: &JsObject,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject> {
// 1. Let newTypedArray be ? Construct(constructor, argumentList).
let new_typed_array = constructor.construct(args, Some(constructor), context)?;
@ -3080,7 +3104,7 @@ impl TypedArray {
fn allocate_buffer(
indexed: &mut IntegerIndexed,
length: u64,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<()> {
// 1. Assert: O.[[ViewedArrayBuffer]] is undefined.
assert!(indexed.viewed_array_buffer().is_none());
@ -3121,7 +3145,7 @@ impl TypedArray {
pub(crate) fn initialize_from_list(
o: &JsObject,
values: Vec<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<()> {
// 1. Let len be the number of elements in values.
let len = values.len() as u64;
@ -3163,7 +3187,7 @@ impl TypedArray {
new_target: &JsValue,
default_proto: P,
length: Option<u64>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsObject>
where
P: FnOnce(&StandardConstructors) -> &StandardConstructor,
@ -3203,7 +3227,7 @@ impl TypedArray {
fn initialize_from_typed_array(
o: &JsObject,
src_array: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<()> {
let o_obj = o.borrow();
let src_array_obj = src_array.borrow();
@ -3354,7 +3378,7 @@ impl TypedArray {
buffer: JsObject,
byte_offset: &JsValue,
length: &JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<()> {
// 1. Let constructorName be the String value of O.[[TypedArrayName]].
// 2. Let elementSize be the Element Size value specified in Table 73 for constructorName.
@ -3455,7 +3479,7 @@ impl TypedArray {
fn initialize_from_array_like(
o: &JsObject,
array_like: &JsObject,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<()> {
// 1. Let len be ? LengthOfArrayLike(arrayLike).
let len = array_like.length_of_array_like(context)?;

2
boa_engine/src/builtins/undefined/mod.rs

@ -26,7 +26,7 @@ impl BuiltIn for Undefined {
.union(Attribute::NON_ENUMERABLE)
.union(Attribute::PERMANENT);
fn init(_: &mut Context) -> Option<JsValue> {
fn init(_: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
Some(JsValue::undefined())

10
boa_engine/src/builtins/uri/mod.rs

@ -30,7 +30,7 @@ pub(crate) struct Uri;
impl BuiltIn for Uri {
const NAME: &'static str = "Uri";
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let decode_uri = FunctionBuilder::native(context, Self::decode_uri)
.name("decodeURI")
.length(1)
@ -100,7 +100,7 @@ impl Uri {
pub(crate) fn decode_uri(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let encoded_uri = args.get_or_undefined(0);
@ -129,7 +129,7 @@ impl Uri {
pub(crate) fn decode_uri_component(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let encoded_uri_component = args.get_or_undefined(0);
@ -161,7 +161,7 @@ impl Uri {
pub(crate) fn encode_uri(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let uri = args.get_or_undefined(0);
@ -190,7 +190,7 @@ impl Uri {
pub(crate) fn encode_uri_component(
_: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let uri_component = args.get_or_undefined(0);

10
boa_engine/src/builtins/weak/weak_ref.rs

@ -31,7 +31,7 @@ impl BuiltIn for WeakRef {
const ATTRIBUTE: Attribute = Attribute::WRITABLE.union(Attribute::CONFIGURABLE);
fn init(context: &mut Context) -> Option<JsValue> {
fn init(context: &mut Context<'_>) -> Option<JsValue> {
let _timer = Profiler::global().start_event(Self::NAME, "init");
ConstructorBuilder::with_standard_constructor(
context,
@ -62,7 +62,7 @@ impl WeakRef {
pub(crate) fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// If NewTarget is undefined, throw a TypeError exception.
if new_target.is_undefined() {
@ -99,7 +99,11 @@ impl WeakRef {
/// proper [`JsObject`], or returns `undefined` otherwise.
///
/// [spec]: https://tc39.es/ecma262/#sec-weak-ref.prototype.deref
pub(crate) fn deref(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub(crate) fn deref(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// 1. Let weakRef be the this value.
// 2. Perform ? RequireInternalSlot(weakRef, [[WeakRefTarget]]).
let weak_ref = this.as_object().map(JsObject::borrow).ok_or_else(|| {

2
boa_engine/src/bytecompiler/class.rs

@ -16,7 +16,7 @@ use crate::{
use super::{ByteCompiler, Literal, NodeKind};
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
/// This function compiles a class declaration or expression.
///
/// The compilation of a class declaration and expression is mostly equal.

2
boa_engine/src/bytecompiler/declaration/declaration_pattern.rs

@ -9,7 +9,7 @@ use crate::{
JsResult,
};
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
pub(crate) fn compile_declaration_pattern_impl(
&mut self,
pattern: &Pattern,

4
boa_engine/src/bytecompiler/expression/assign.rs

@ -6,7 +6,7 @@ use crate::{
JsResult,
};
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
pub(crate) fn compile_assign(&mut self, assign: &Assign, use_expr: bool) -> JsResult<()> {
if assign.op() == AssignOp::Assign {
match Access::from_assign_target(assign.lhs()) {
@ -27,7 +27,7 @@ impl ByteCompiler<'_> {
.expect("patterns should throw early errors on complex assignment operators");
let shortcircuit_operator_compilation =
|compiler: &mut ByteCompiler<'_>, opcode: Opcode| -> JsResult<()> {
|compiler: &mut ByteCompiler<'_, '_>, opcode: Opcode| -> JsResult<()> {
let (early_exit, pop_count) =
compiler.access_set(access, use_expr, |compiler, level| {
compiler.access_get(access, true)?;

2
boa_engine/src/bytecompiler/expression/binary.rs

@ -5,7 +5,7 @@ use boa_ast::expression::operator::{
use crate::{bytecompiler::ByteCompiler, vm::Opcode, JsResult};
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
pub(crate) fn compile_binary(&mut self, binary: &Binary, use_expr: bool) -> JsResult<()> {
self.compile_expr(binary.lhs(), true)?;
match binary.op() {

2
boa_engine/src/bytecompiler/expression/mod.rs

@ -21,7 +21,7 @@ mod unary;
use boa_interner::Sym;
use super::{Access, Callable, NodeKind};
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
fn compile_literal(&mut self, lit: &AstLiteral, use_expr: bool) {
match lit {
AstLiteral::String(v) => self.emit_push_literal(Literal::String(

2
boa_engine/src/bytecompiler/expression/object_literal.rs

@ -9,7 +9,7 @@ use crate::{
vm::Opcode,
JsNativeError, JsResult,
};
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
pub(crate) fn compile_object_literal(
&mut self,
object: &ObjectLiteral,

2
boa_engine/src/bytecompiler/expression/unary.rs

@ -9,7 +9,7 @@ use crate::{
JsNativeError, JsResult,
};
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
pub(crate) fn compile_unary(&mut self, unary: &Unary, use_expr: bool) -> JsResult<()> {
let opcode = match unary.op() {
UnaryOp::IncrementPre => {

2
boa_engine/src/bytecompiler/function.rs

@ -82,7 +82,7 @@ impl FunctionCompiler {
mut self,
parameters: &FormalParameterList,
body: &StatementList,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Gc<CodeBlock>> {
self.strict = self.strict || body.strict();

20
boa_engine/src/bytecompiler/mod.rs

@ -222,7 +222,7 @@ impl Access<'_> {
/// The [`ByteCompiler`] is used to compile ECMAScript AST from [`boa_ast`] to bytecode.
#[derive(Debug)]
pub struct ByteCompiler<'b> {
pub struct ByteCompiler<'b, 'icu> {
code_block: CodeBlock,
literals_map: FxHashMap<Literal, u32>,
names_map: FxHashMap<Identifier, u32>,
@ -230,16 +230,21 @@ pub struct ByteCompiler<'b> {
jump_info: Vec<JumpControlInfo>,
in_async_generator: bool,
json_parse: bool,
context: &'b mut Context,
context: &'b mut Context<'icu>,
}
impl<'b> ByteCompiler<'b> {
impl<'b, 'icu> ByteCompiler<'b, 'icu> {
/// Represents a placeholder address that will be patched later.
const DUMMY_ADDRESS: u32 = u32::MAX;
/// Creates a new [`ByteCompiler`].
#[inline]
pub fn new(name: Sym, strict: bool, json_parse: bool, context: &'b mut Context) -> Self {
pub fn new(
name: Sym,
strict: bool,
json_parse: bool,
context: &'b mut Context<'icu>,
) -> ByteCompiler<'b, 'icu> {
Self {
code_block: CodeBlock::new(name, 0, strict),
literals_map: FxHashMap::default(),
@ -703,7 +708,10 @@ impl<'b> ByteCompiler<'b> {
// The wrap is needed so it can match the function signature.
#[allow(clippy::unnecessary_wraps)]
fn access_set_top_of_stack_expr_fn(compiler: &mut ByteCompiler<'_>, level: u8) -> JsResult<()> {
fn access_set_top_of_stack_expr_fn(
compiler: &mut ByteCompiler<'_, '_>,
level: u8,
) -> JsResult<()> {
match level {
0 => {}
1 => compiler.emit_opcode(Opcode::Swap),
@ -717,7 +725,7 @@ impl<'b> ByteCompiler<'b> {
fn access_set<F, R>(&mut self, access: Access<'_>, use_expr: bool, expr_fn: F) -> JsResult<R>
where
F: FnOnce(&mut ByteCompiler<'_>, u8) -> JsResult<R>,
F: FnOnce(&mut ByteCompiler<'_, '_>, u8) -> JsResult<R>,
{
match access {
Access::Variable { name } => {

2
boa_engine/src/bytecompiler/statement/continue.rs

@ -6,7 +6,7 @@ use crate::{
JsNativeError, JsResult,
};
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
pub(crate) fn compile_continue(&mut self, node: Continue) -> JsResult<()> {
let next = self.next_opcode_location();
if let Some(info) = self

2
boa_engine/src/bytecompiler/statement/loop.rs

@ -14,7 +14,7 @@ use crate::{
JsResult,
};
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
pub(crate) fn compile_for_loop(
&mut self,
for_loop: &ForLoop,

2
boa_engine/src/bytecompiler/statement/mod.rs

@ -12,7 +12,7 @@ mod r#continue;
mod r#loop;
mod r#try;
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
pub(crate) fn compile_if(&mut self, node: &If, configurable_globals: bool) -> JsResult<()> {
self.compile_expr(node.cond(), true)?;
let jelse = self.jump_if_false();

2
boa_engine/src/bytecompiler/statement/try.rs

@ -6,7 +6,7 @@ use crate::{
JsResult,
};
impl ByteCompiler<'_> {
impl ByteCompiler<'_, '_> {
pub(crate) fn compile_try(
&mut self,
t: &Try,

24
boa_engine/src/class.rs

@ -26,7 +26,7 @@
//! const LENGTH: usize = 1;
//!
//! // This is what is called when we do `new Animal()`
//! fn constructor(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<Self> {
//! fn constructor(_this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<Self> {
//! // This is equivalent to `String(arg)`.
//! let kind = args.get_or_undefined(0).to_string(context)?;
//!
@ -79,10 +79,10 @@ pub trait Class: NativeObject + Sized {
const ATTRIBUTES: Attribute = Attribute::all();
/// The constructor of the class.
fn constructor(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<Self>;
fn constructor(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<Self>;
/// Initializes the internals and the methods of the class.
fn init(class: &mut ClassBuilder<'_>) -> JsResult<()>;
fn init(class: &mut ClassBuilder<'_, '_>) -> JsResult<()>;
}
/// This is a wrapper around `Class::constructor` that sets the internal data of a class.
@ -93,14 +93,18 @@ pub trait ClassConstructor: Class {
fn raw_constructor(
this: &JsValue,
args: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue>
where
Self: Sized;
}
impl<T: Class> ClassConstructor for T {
fn raw_constructor(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue>
fn raw_constructor(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue>
where
Self: Sized,
{
@ -153,12 +157,12 @@ impl<T: Class> ClassConstructor for T {
/// Class builder which allows adding methods and static methods to the class.
#[derive(Debug)]
pub struct ClassBuilder<'context> {
builder: ConstructorBuilder<'context>,
pub struct ClassBuilder<'ctx, 'icu> {
builder: ConstructorBuilder<'ctx, 'icu>,
}
impl<'context> ClassBuilder<'context> {
pub(crate) fn new<T>(context: &'context mut Context) -> Self
impl<'ctx, 'icu> ClassBuilder<'ctx, 'icu> {
pub(crate) fn new<T>(context: &'ctx mut Context<'icu>) -> Self
where
T: ClassConstructor,
{
@ -288,7 +292,7 @@ impl<'context> ClassBuilder<'context> {
/// Return the current context.
#[inline]
pub fn context(&mut self) -> &'_ mut Context {
pub fn context(&mut self) -> &mut Context<'icu> {
self.builder.context()
}
}

66
boa_engine/src/context/icu.rs

@ -18,23 +18,24 @@ use crate::builtins::intl::list_format::ListFormatType;
/// Providers can be either [`BufferProvider`]s or [`AnyProvider`]s.
///
/// The [`icu_provider`] documentation has more information about data providers.
pub enum BoaProvider {
#[derive(Clone, Copy)]
pub enum BoaProvider<'a> {
/// A [`BufferProvider`] data provider.
Buffer(Box<dyn BufferProvider>),
/// An [`AnyProvider] data provider.
Any(Box<dyn AnyProvider>),
Buffer(&'a dyn BufferProvider),
/// An [`AnyProvider`] data provider.
Any(&'a dyn AnyProvider),
}
impl Debug for BoaProvider {
impl Debug for BoaProvider<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Buffer(_) => f.debug_tuple("Buffer").field(&"_").finish(),
Self::Any(_) => f.debug_tuple("Any").field(&"_").finish(),
Self::Buffer(_) => f.debug_tuple("Buffer").field(&"..").finish(),
Self::Any(_) => f.debug_tuple("Any").field(&"..").finish(),
}
}
}
impl<M> DataProvider<M> for BoaProvider
impl<M> DataProvider<M> for BoaProvider<'_>
where
M: KeyedDataMarker + 'static,
for<'de> YokeTraitHack<<M::Yokeable as Yokeable<'de>>::Output>: Deserialize<'de>,
@ -42,14 +43,14 @@ where
M::Yokeable: ZeroFrom<'static, M::Yokeable> + MaybeSendSync,
{
fn load(&self, req: DataRequest<'_>) -> Result<DataResponse<M>, DataError> {
match self {
match *self {
BoaProvider::Buffer(provider) => provider.as_deserializing().load(req),
BoaProvider::Any(provider) => provider.as_downcasting().load(req),
}
}
}
impl BoaProvider {
impl BoaProvider<'_> {
/// Creates a new [`LocaleCanonicalizer`] from the provided [`DataProvider`].
pub(crate) fn try_new_locale_canonicalizer(
&self,
@ -126,50 +127,51 @@ impl BoaProvider {
/// Collection of tools initialized from a [`DataProvider`] that are used
/// for the functionality of `Intl`.
pub(crate) struct Icu<P> {
provider: P,
pub(crate) struct Icu<'provider> {
provider: BoaProvider<'provider>,
locale_canonicalizer: LocaleCanonicalizer,
locale_expander: LocaleExpander,
}
impl<P: Debug> Debug for Icu<P> {
impl Debug for Icu<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Icu")
.field("provider", &self.provider)
.field("locale_canonicalizer", &"LocaleCanonicalizer")
.field("locale_expander", &"LocaleExpander")
.finish()
}
}
impl<P> Icu<P> {
/// Gets the [`LocaleCanonicalizer`] tool.
pub(crate) const fn locale_canonicalizer(&self) -> &LocaleCanonicalizer {
&self.locale_canonicalizer
}
/// Gets the inner icu data provider
pub(crate) const fn provider(&self) -> &P {
&self.provider
}
/// Gets the [`LocaleExpander`] tool.
pub(crate) const fn locale_expander(&self) -> &LocaleExpander {
&self.locale_expander
}
}
impl Icu<BoaProvider> {
impl<'provider> Icu<'provider> {
/// Creates a new [`Icu`] from a valid [`BoaProvider`]
///
/// # Errors
///
/// This method will return an error if any of the tools
/// required cannot be constructed.
pub(crate) fn new(provider: BoaProvider) -> Result<Self, LocaleTransformError> {
pub(crate) fn new(
provider: BoaProvider<'provider>,
) -> Result<Icu<'provider>, LocaleTransformError> {
Ok(Self {
locale_canonicalizer: provider.try_new_locale_canonicalizer()?,
locale_expander: provider.try_new_locale_expander()?,
provider,
})
}
/// Gets the [`LocaleCanonicalizer`] tool.
pub(crate) const fn locale_canonicalizer(&self) -> &LocaleCanonicalizer {
&self.locale_canonicalizer
}
/// Gets the [`LocaleExpander`] tool.
pub(crate) const fn locale_expander(&self) -> &LocaleExpander {
&self.locale_expander
}
/// Gets the inner icu data provider
pub(crate) const fn provider(&self) -> BoaProvider<'provider> {
self.provider
}
}

2
boa_engine/src/context/intrinsics.rs

@ -751,7 +751,7 @@ pub struct IntrinsicObjects {
impl IntrinsicObjects {
/// Initialize the intrinsic objects
pub fn init(context: &mut Context) -> Self {
pub fn init(context: &mut Context<'_>) -> Self {
Self {
throw_type_error: create_throw_type_error(context),
array_prototype_values: Array::create_array_prototype_values(context).into(),

77
boa_engine/src/context/mod.rs

@ -11,6 +11,9 @@ pub use icu::BoaProvider;
use intrinsics::{IntrinsicObjects, Intrinsics};
use std::collections::VecDeque;
#[cfg(not(feature = "intl"))]
pub use std::marker::PhantomData;
#[cfg(feature = "console")]
use crate::builtins::console::Console;
use crate::{
@ -72,7 +75,7 @@ use boa_profiler::Profiler;
///
/// assert_eq!(value.as_number(), Some(12.0))
/// ```
pub struct Context {
pub struct Context<'icu> {
/// realm holds both the global object and the environment
pub(crate) realm: Realm,
@ -88,7 +91,10 @@ pub struct Context {
/// ICU related utilities
#[cfg(feature = "intl")]
icu: icu::Icu<BoaProvider>,
icu: icu::Icu<'icu>,
#[cfg(not(feature = "intl"))]
icu: PhantomData<&'icu ()>,
/// Number of instructions remaining before a forced exit
#[cfg(feature = "fuzz")]
@ -101,7 +107,7 @@ pub struct Context {
pub(crate) kept_alive: Vec<JsObject>,
}
impl std::fmt::Debug for Context {
impl std::fmt::Debug for Context<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut debug = f.debug_struct("Context");
@ -124,7 +130,7 @@ impl std::fmt::Debug for Context {
}
}
impl Default for Context {
impl Default for Context<'_> {
fn default() -> Self {
ContextBuilder::default().build()
}
@ -132,11 +138,11 @@ impl Default for Context {
// ==== Public API ====
impl Context {
impl Context<'_> {
/// Create a new [`ContextBuilder`] to specify the [`Interner`] and/or
/// the icu data provider.
#[must_use]
pub fn builder() -> ContextBuilder {
pub fn builder() -> ContextBuilder<'static> {
ContextBuilder::default()
}
@ -364,7 +370,7 @@ impl Context {
/// why we need to restrict the set of accepted closures.
pub fn register_global_closure<F>(&mut self, name: &str, length: usize, body: F) -> JsResult<()>
where
F: Fn(&JsValue, &[JsValue], &mut Self) -> JsResult<JsValue> + Copy + 'static,
F: Fn(&JsValue, &[JsValue], &mut Context<'_>) -> JsResult<JsValue> + Copy + 'static,
{
let function = FunctionBuilder::closure(self, body)
.name(name)
@ -472,7 +478,7 @@ impl Context {
// ==== Private API ====
impl Context {
impl Context<'_> {
/// A helper function for getting an immutable reference to the `console` object.
#[cfg(feature = "console")]
pub(crate) const fn console(&self) -> &Console {
@ -514,12 +520,6 @@ impl Context {
Ok(Gc::new(compiler.finish()))
}
/// Get the ICU related utilities
#[cfg(feature = "intl")]
pub(crate) const fn icu(&self) -> &icu::Icu<BoaProvider> {
&self.icu
}
/// Sets up the default global objects within Global
fn create_intrinsics(&mut self) {
let _timer = Profiler::global().start_event("create_intrinsics", "interpreter");
@ -536,6 +536,15 @@ impl Context {
Ok(())
}
}
#[cfg(feature = "intl")]
impl<'icu> Context<'icu> {
/// Get the ICU related utilities
pub(crate) const fn icu(&self) -> &icu::Icu<'icu> {
&self.icu
}
}
/// Builder for the [`Context`] type.
///
/// This builder allows custom initialization of the [`Interner`] within
@ -548,15 +557,17 @@ impl Context {
doc = "The required data in a valid provider is specified in [`BoaProvider`]"
)]
#[derive(Default, Debug)]
pub struct ContextBuilder {
pub struct ContextBuilder<'icu> {
interner: Option<Interner>,
#[cfg(feature = "intl")]
icu: Option<icu::Icu<BoaProvider>>,
icu: Option<icu::Icu<'icu>>,
#[cfg(not(feature = "intl"))]
icu: PhantomData<&'icu ()>,
#[cfg(feature = "fuzz")]
instructions_remaining: usize,
}
impl ContextBuilder {
impl<'a> ContextBuilder<'a> {
/// Initializes the context [`Interner`] to the provided interner.
///
/// This is useful when you want to initialize an [`Interner`] with
@ -571,13 +582,25 @@ impl ContextBuilder {
/// Provides an icu data provider to the [`Context`].
///
/// This function is only available if the `intl` feature is enabled.
///
/// # Errors
///
/// This returns `Err` if the provided provider doesn't have the required locale information
/// to construct both a [`LocaleCanonicalizer`] and a [`LocaleExpander`]. Note that this doesn't
/// mean that the provider will successfully construct all `Intl` services; that check is made
/// until the creation of an instance of a service.
///
/// [`LocaleCanonicalizer`]: icu_locid_transform::LocaleCanonicalizer
/// [`LocaleExpander`]: icu_locid_transform::LocaleExpander
#[cfg(feature = "intl")]
pub fn icu_provider(
mut self,
provider: BoaProvider,
) -> Result<Self, icu_locid_transform::LocaleTransformError> {
self.icu = Some(icu::Icu::new(provider)?);
Ok(self)
self,
provider: BoaProvider<'_>,
) -> Result<ContextBuilder<'_>, icu_locid_transform::LocaleTransformError> {
Ok(ContextBuilder {
icu: Some(icu::Icu::new(provider)?),
..self
})
}
/// Specifies the number of instructions remaining to the [`Context`].
@ -600,7 +623,7 @@ impl ContextBuilder {
/// Builds a new [`Context`] with the provided parameters, and defaults
/// all missing parameters to their default values.
#[must_use]
pub fn build(self) -> Context {
pub fn build(self) -> Context<'a> {
let intrinsics = Intrinsics::default();
let mut context = Context {
realm: Realm::create(intrinsics.constructors().object().prototype().into()),
@ -616,13 +639,11 @@ impl ContextBuilder {
},
#[cfg(feature = "intl")]
icu: self.icu.unwrap_or_else(|| {
use icu_provider_adapters::fallback::LocaleFallbackProvider;
let provider = BoaProvider::Buffer(Box::new(
LocaleFallbackProvider::try_new_with_buffer_provider(boa_icu_provider::blob())
.expect("boa_icu_provider should return a valid provider"),
));
let provider = BoaProvider::Buffer(boa_icu_provider::buffer());
icu::Icu::new(provider).expect("Failed to initialize default icu data.")
}),
#[cfg(not(feature = "intl"))]
icu: PhantomData,
#[cfg(feature = "fuzz")]
instructions_remaining: self.instructions_remaining,
promise_job_queue: VecDeque::new(),

2
boa_engine/src/environments/compile.rs

@ -200,7 +200,7 @@ impl CompileTimeEnvironment {
}
}
impl Context {
impl Context<'_> {
/// Push either a new declarative or function environment on the compile time environment stack.
///
/// Note: This function only works at bytecode compile time!

2
boa_engine/src/environments/runtime.rs

@ -840,7 +840,7 @@ impl BindingLocator {
/// Helper method to throws an error if the binding access is illegal.
pub(crate) fn throw_mutate_immutable(
&self,
context: &mut Context,
context: &mut Context<'_>,
) -> Result<(), JsNativeError> {
if self.mutate_immutable {
Err(JsNativeError::typ().with_message(format!(

8
boa_engine/src/error.rs

@ -156,7 +156,7 @@ impl JsError {
///
/// assert!(error_val.as_object().unwrap().borrow().is_error());
/// ```
pub fn to_opaque(&self, context: &mut Context) -> JsValue {
pub fn to_opaque(&self, context: &mut Context<'_>) -> JsValue {
match &self.inner {
Repr::Native(e) => e.to_opaque(context).into(),
Repr::Opaque(v) => v.clone(),
@ -201,7 +201,7 @@ impl JsError {
/// assert!(matches!(error.kind, JsNativeErrorKind::Type));
/// assert_eq!(error.message(), "type error!");
/// ```
pub fn try_native(&self, context: &mut Context) -> Result<JsNativeError, TryNativeError> {
pub fn try_native(&self, context: &mut Context<'_>) -> Result<JsNativeError, TryNativeError> {
match &self.inner {
Repr::Native(e) => Ok(e.clone()),
Repr::Opaque(val) => {
@ -213,7 +213,7 @@ impl JsError {
.as_error()
.ok_or_else(|| TryNativeError::NotAnErrorObject(val.clone()))?;
let try_get_property = |key, context: &mut Context| {
let try_get_property = |key, context: &mut Context<'_>| {
obj.has_property(key, context)
.map_err(|e| TryNativeError::InaccessibleProperty {
property: key,
@ -636,7 +636,7 @@ impl JsNativeError {
/// assert!(error_obj.borrow().is_error());
/// assert_eq!(error_obj.get("message", context).unwrap(), "error!".into())
/// ```
pub fn to_opaque(&self, context: &mut Context) -> JsObject {
pub fn to_opaque(&self, context: &mut Context<'_>) -> JsObject {
let Self {
kind,
message,

2
boa_engine/src/job.rs

@ -48,7 +48,7 @@ impl JobCallback {
&self,
v: &JsValue,
arguments_list: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
// It must perform and return the result of Call(jobCallback.[[Callback]], V, argumentsList).

4
boa_engine/src/lib.rs

@ -155,7 +155,7 @@ pub type JsResult<T> = StdResult<T, JsError>;
///
/// The state of the `Context` is changed, and a string representation of the result is returned.
#[cfg(test)]
pub(crate) fn forward<S>(context: &mut Context, src: S) -> String
pub(crate) fn forward<S>(context: &mut Context<'_>, src: S) -> String
where
S: AsRef<[u8]>,
{
@ -170,7 +170,7 @@ where
/// If the interpreter fails parsing an error value is returned instead (error object)
#[allow(clippy::unit_arg, clippy::drop_copy)]
#[cfg(test)]
pub(crate) fn forward_val<T: AsRef<[u8]>>(context: &mut Context, src: T) -> JsResult<JsValue> {
pub(crate) fn forward_val<T: AsRef<[u8]>>(context: &mut Context<'_>, src: T) -> JsResult<JsValue> {
use boa_profiler::Profiler;
let main_timer = Profiler::global().start_event("Main", "Main");

58
boa_engine/src/object/builtins/jsarray.rs

@ -18,7 +18,7 @@ pub struct JsArray {
impl JsArray {
/// Create a new empty array.
#[inline]
pub fn new(context: &mut Context) -> Self {
pub fn new(context: &mut Context<'_>) -> Self {
let inner = Array::array_create(0, None, context)
.expect("creating an empty array with the default prototype must not fail");
@ -26,7 +26,7 @@ impl JsArray {
}
/// Create an array from a `IntoIterator<Item = JsValue>` convertible object.
pub fn from_iter<I>(elements: I, context: &mut Context) -> Self
pub fn from_iter<I>(elements: I, context: &mut Context<'_>) -> Self
where
I: IntoIterator<Item = JsValue>,
{
@ -53,18 +53,18 @@ impl JsArray {
///
/// Same a `array.length` in JavaScript.
#[inline]
pub fn length(&self, context: &mut Context) -> JsResult<u64> {
pub fn length(&self, context: &mut Context<'_>) -> JsResult<u64> {
self.inner.length_of_array_like(context)
}
/// Check if the array is empty, i.e. the `length` is zero.
#[inline]
pub fn is_empty(&self, context: &mut Context) -> JsResult<bool> {
pub fn is_empty(&self, context: &mut Context<'_>) -> JsResult<bool> {
self.inner.length_of_array_like(context).map(|len| len == 0)
}
/// Push an element to the array.
pub fn push<T>(&self, value: T, context: &mut Context) -> JsResult<JsValue>
pub fn push<T>(&self, value: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -73,18 +73,18 @@ impl JsArray {
/// Pushes a slice of elements to the array.
#[inline]
pub fn push_items(&self, items: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn push_items(&self, items: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
Array::push(&self.inner.clone().into(), items, context)
}
/// Pops an element from the array.
#[inline]
pub fn pop(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn pop(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Array::pop(&self.inner.clone().into(), &[], context)
}
/// Calls `Array.prototype.at()`.
pub fn at<T>(&self, index: T, context: &mut Context) -> JsResult<JsValue>
pub fn at<T>(&self, index: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<i64>,
{
@ -93,26 +93,26 @@ impl JsArray {
/// Calls `Array.prototype.shift()`.
#[inline]
pub fn shift(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn shift(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Array::shift(&self.inner.clone().into(), &[], context)
}
/// Calls `Array.prototype.unshift()`.
#[inline]
pub fn unshift(&self, items: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn unshift(&self, items: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
Array::shift(&self.inner.clone().into(), items, context)
}
/// Calls `Array.prototype.reverse()`.
#[inline]
pub fn reverse(&self, context: &mut Context) -> JsResult<Self> {
pub fn reverse(&self, context: &mut Context<'_>) -> JsResult<Self> {
Array::reverse(&self.inner.clone().into(), &[], context)?;
Ok(self.clone())
}
/// Calls `Array.prototype.concat()`.
#[inline]
pub fn concat(&self, items: &[JsValue], context: &mut Context) -> JsResult<Self> {
pub fn concat(&self, items: &[JsValue], context: &mut Context<'_>) -> JsResult<Self> {
let object = Array::concat(&self.inner.clone().into(), items, context)?
.as_object()
.cloned()
@ -123,7 +123,11 @@ impl JsArray {
/// Calls `Array.prototype.join()`.
#[inline]
pub fn join(&self, separator: Option<JsString>, context: &mut Context) -> JsResult<JsString> {
pub fn join(
&self,
separator: Option<JsString>,
context: &mut Context<'_>,
) -> JsResult<JsString> {
Array::join(
&self.inner.clone().into(),
&[separator.into_or_undefined()],
@ -142,7 +146,7 @@ impl JsArray {
value: T,
start: Option<u32>,
end: Option<u32>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Self>
where
T: Into<JsValue>,
@ -164,7 +168,7 @@ impl JsArray {
&self,
search_element: T,
from_index: Option<u32>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Option<u32>>
where
T: Into<JsValue>,
@ -190,7 +194,7 @@ impl JsArray {
&self,
search_element: T,
from_index: Option<u32>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Option<u32>>
where
T: Into<JsValue>,
@ -217,7 +221,7 @@ impl JsArray {
&self,
predicate: JsFunction,
this_arg: Option<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Array::find(
&self.inner.clone().into(),
@ -232,7 +236,7 @@ impl JsArray {
&self,
callback: JsFunction,
this_arg: Option<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Self> {
let object = Array::filter(
&self.inner.clone().into(),
@ -252,7 +256,7 @@ impl JsArray {
&self,
callback: JsFunction,
this_arg: Option<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Self> {
let object = Array::map(
&self.inner.clone().into(),
@ -272,7 +276,7 @@ impl JsArray {
&self,
callback: JsFunction,
this_arg: Option<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<bool> {
let result = Array::every(
&self.inner.clone().into(),
@ -291,7 +295,7 @@ impl JsArray {
&self,
callback: JsFunction,
this_arg: Option<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<bool> {
let result = Array::some(
&self.inner.clone().into(),
@ -306,7 +310,11 @@ impl JsArray {
/// Calls `Array.prototype.sort()`.
#[inline]
pub fn sort(&self, compare_fn: Option<JsFunction>, context: &mut Context) -> JsResult<Self> {
pub fn sort(
&self,
compare_fn: Option<JsFunction>,
context: &mut Context<'_>,
) -> JsResult<Self> {
Array::sort(
&self.inner.clone().into(),
&[compare_fn.into_or_undefined()],
@ -322,7 +330,7 @@ impl JsArray {
&self,
start: Option<u32>,
end: Option<u32>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Self> {
let object = Array::slice(
&self.inner.clone().into(),
@ -342,7 +350,7 @@ impl JsArray {
&self,
callback: JsFunction,
initial_value: Option<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Array::reduce(
&self.inner.clone().into(),
@ -357,7 +365,7 @@ impl JsArray {
&self,
callback: JsFunction,
initial_value: Option<JsValue>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Array::reduce_right(
&self.inner.clone().into(),

6
boa_engine/src/object/builtins/jsarraybuffer.rs

@ -37,7 +37,7 @@ impl JsArrayBuffer {
/// # }
/// ```
#[inline]
pub fn new(byte_length: usize, context: &mut Context) -> JsResult<Self> {
pub fn new(byte_length: usize, context: &mut Context<'_>) -> JsResult<Self> {
let inner = ArrayBuffer::allocate(
&context
.intrinsics()
@ -75,7 +75,7 @@ impl JsArrayBuffer {
/// # Ok(())
/// # }
/// ```
pub fn from_byte_block(byte_block: Vec<u8>, context: &mut Context) -> JsResult<Self> {
pub fn from_byte_block(byte_block: Vec<u8>, context: &mut Context<'_>) -> JsResult<Self> {
let byte_length = byte_block.len();
let constructor = context
@ -148,7 +148,7 @@ impl JsArrayBuffer {
/// # }
/// ```
#[inline]
pub fn byte_length(&self, context: &mut Context) -> usize {
pub fn byte_length(&self, context: &mut Context<'_>) -> usize {
ArrayBuffer::get_byte_length(&self.inner.clone().into(), &[], context)
.expect("it should not throw")
.as_number()

48
boa_engine/src/object/builtins/jsdataview.rs

@ -42,7 +42,7 @@ impl JsDataView {
array_buffer: &JsArrayBuffer,
offset: Option<u64>,
byte_length: Option<u64>,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<Self> {
let (byte_offset, byte_length) = {
let borrowed_buffer = array_buffer.borrow();
@ -122,20 +122,20 @@ impl JsDataView {
/// Returns the `viewed_array_buffer` field for [`JsDataView`]
#[inline]
pub fn buffer(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn buffer(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
DataView::get_buffer(&self.inner.clone().into(), &[], context)
}
/// Returns the `byte_length` property of [`JsDataView`] as a u64 integer
#[inline]
pub fn byte_length(&self, context: &mut Context) -> JsResult<u64> {
pub fn byte_length(&self, context: &mut Context<'_>) -> JsResult<u64> {
DataView::get_byte_length(&self.inner.clone().into(), &[], context)
.map(|v| v.as_number().expect("value should be a number") as u64)
}
/// Returns the `byte_offset` field property of [`JsDataView`] as a u64 integer
#[inline]
pub fn byte_offset(&self, context: &mut Context) -> JsResult<u64> {
pub fn byte_offset(&self, context: &mut Context<'_>) -> JsResult<u64> {
DataView::get_byte_offset(&self.inner.clone().into(), &[], context)
.map(|v| v.as_number().expect("byte_offset value must be a number") as u64)
}
@ -146,7 +146,7 @@ impl JsDataView {
&self,
byte_offset: usize,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<i64> {
DataView::get_big_int64(
&self.inner.clone().into(),
@ -162,7 +162,7 @@ impl JsDataView {
&self,
byte_offset: usize,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<u64> {
DataView::get_big_uint64(
&self.inner.clone().into(),
@ -178,7 +178,7 @@ impl JsDataView {
&self,
byte_offset: usize,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<f32> {
DataView::get_float32(
&self.inner.clone().into(),
@ -194,7 +194,7 @@ impl JsDataView {
&self,
byte_offset: usize,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<f64> {
DataView::get_float64(
&self.inner.clone().into(),
@ -210,7 +210,7 @@ impl JsDataView {
&self,
byte_offset: usize,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<i8> {
DataView::get_int8(
&self.inner.clone().into(),
@ -226,7 +226,7 @@ impl JsDataView {
&self,
byte_offset: usize,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<i16> {
DataView::get_int16(
&self.inner.clone().into(),
@ -242,7 +242,7 @@ impl JsDataView {
&self,
byte_offset: usize,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<i32> {
DataView::get_int32(
&self.inner.clone().into(),
@ -258,7 +258,7 @@ impl JsDataView {
&self,
byte_offset: usize,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<u8> {
DataView::get_uint8(
&self.inner.clone().into(),
@ -274,7 +274,7 @@ impl JsDataView {
&self,
byte_offset: usize,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<u16> {
DataView::get_uint16(
&self.inner.clone().into(),
@ -290,7 +290,7 @@ impl JsDataView {
&self,
byte_offset: usize,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<u32> {
DataView::get_uint32(
&self.inner.clone().into(),
@ -307,7 +307,7 @@ impl JsDataView {
byte_offset: usize,
value: i64,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
DataView::set_big_int64(
&self.inner.clone().into(),
@ -323,7 +323,7 @@ impl JsDataView {
byte_offset: usize,
value: u64,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
DataView::set_big_uint64(
&self.inner.clone().into(),
@ -339,7 +339,7 @@ impl JsDataView {
byte_offset: usize,
value: f32,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
DataView::set_float32(
&self.inner.clone().into(),
@ -355,7 +355,7 @@ impl JsDataView {
byte_offset: usize,
value: f64,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
DataView::set_float64(
&self.inner.clone().into(),
@ -371,7 +371,7 @@ impl JsDataView {
byte_offset: usize,
value: i8,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
DataView::set_int8(
&self.inner.clone().into(),
@ -387,7 +387,7 @@ impl JsDataView {
byte_offset: usize,
value: i16,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
DataView::set_int16(
&self.inner.clone().into(),
@ -403,7 +403,7 @@ impl JsDataView {
byte_offset: usize,
value: i32,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
DataView::set_int32(
&self.inner.clone().into(),
@ -419,7 +419,7 @@ impl JsDataView {
byte_offset: usize,
value: u8,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
DataView::set_uint8(
&self.inner.clone().into(),
@ -435,7 +435,7 @@ impl JsDataView {
byte_offset: usize,
value: u16,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
DataView::set_uint16(
&self.inner.clone().into(),
@ -451,7 +451,7 @@ impl JsDataView {
byte_offset: usize,
value: u32,
is_little_endian: bool,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
DataView::set_uint32(
&self.inner.clone().into(),

122
boa_engine/src/object/builtins/jsdate.rs

@ -40,7 +40,7 @@ pub struct JsDate {
impl JsDate {
/// Create a new `Date` object with universal time.
#[inline]
pub fn new(context: &mut Context) -> Self {
pub fn new(context: &mut Context<'_>) -> Self {
let prototype = context.intrinsics().constructors().date().prototype();
let inner = JsObject::from_proto_and_data(prototype, ObjectData::date(Date::default()));
@ -51,7 +51,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.now()`
#[inline]
pub fn now(context: &mut Context) -> JsResult<JsValue> {
pub fn now(context: &mut Context<'_>) -> JsResult<JsValue> {
Date::now(&JsValue::Null, &[JsValue::Null], context)
}
@ -63,7 +63,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.parse(value)`.
#[inline]
pub fn parse(value: JsValue, context: &mut Context) -> JsResult<JsValue> {
pub fn parse(value: JsValue, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::parse(&JsValue::Null, &[value], context)
}
@ -72,7 +72,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.UTC()`
#[inline]
pub fn utc(values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn utc(values: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
Date::utc(&JsValue::Null, values, context)
}
@ -81,7 +81,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getDate()`.
#[inline]
pub fn get_date(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_date(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_date::<true>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -90,7 +90,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getDay()`.
#[inline]
pub fn get_day(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_day(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_day::<true>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -99,7 +99,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getFullYear()`.
#[inline]
pub fn get_full_year(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_full_year(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_full_year::<true>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -107,7 +107,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getHours()`.
#[inline]
pub fn get_hours(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_hours(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_hours::<true>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -116,7 +116,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getMilliseconds()`.
#[inline]
pub fn get_milliseconds(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_milliseconds(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_milliseconds::<true>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -124,7 +124,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getMinutes()`.
#[inline]
pub fn get_minutes(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_minutes(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_minutes::<true>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -132,7 +132,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getMonth()`.
#[inline]
pub fn get_month(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_month(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_month::<true>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -140,7 +140,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getSeconds()`.
#[inline]
pub fn get_seconds(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_seconds(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_seconds::<true>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -150,7 +150,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getTime()`.
#[inline]
pub fn get_time(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_time(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_time(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -158,7 +158,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getTimezoneOffset()`.
#[inline]
pub fn get_timezone_offset(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_timezone_offset(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_timezone_offset(&self.inner.clone().into(), &[JsValue::Null], context)
}
@ -167,7 +167,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getUTCDate()`.
#[inline]
pub fn get_utc_date(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_utc_date(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_date::<false>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -176,7 +176,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getUTCDay()`.
#[inline]
pub fn get_utc_day(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_utc_day(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_day::<false>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -185,7 +185,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getUTCFullYear()`.
#[inline]
pub fn get_utc_full_year(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_utc_full_year(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_full_year::<false>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -194,7 +194,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getUTCHours()`.
#[inline]
pub fn get_utc_hours(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_utc_hours(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_hours::<false>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -203,7 +203,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getUTCMilliseconds()`.
#[inline]
pub fn get_utc_milliseconds(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_utc_milliseconds(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_milliseconds::<false>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -212,7 +212,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getUTCMinutes()`.
#[inline]
pub fn get_utc_minutes(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_utc_minutes(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_minutes::<false>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -221,7 +221,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getUTCMonth()`.
#[inline]
pub fn get_utc_month(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_utc_month(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_month::<false>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -230,7 +230,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.getUTCSeconds()`.
#[inline]
pub fn get_utc_seconds(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_utc_seconds(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::get_seconds::<false>(&self.inner.clone().into(), &[JsValue::null()], context)
}
@ -241,7 +241,7 @@ impl JsDate {
/// the UNIX epoch and the given date.
///
/// Same as JavaScript's `Date.prototype.setDate()`.
pub fn set_date<T>(&self, value: T, context: &mut Context) -> JsResult<JsValue>
pub fn set_date<T>(&self, value: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -256,7 +256,11 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.setFullYear()`.
#[inline]
pub fn set_full_year(&self, values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn set_full_year(
&self,
values: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Date::set_full_year::<true>(&self.inner.clone().into(), values, context)
}
@ -267,7 +271,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.setHours()`.
#[inline]
pub fn set_hours(&self, values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn set_hours(&self, values: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
Date::set_hours::<true>(&self.inner.clone().into(), values, context)
}
@ -277,7 +281,7 @@ impl JsDate {
/// the UNIX epoch and updated date.
///
/// Same as JavaScript's `Date.prototype.setMilliseconds()`.
pub fn set_milliseconds<T>(&self, value: T, context: &mut Context) -> JsResult<JsValue>
pub fn set_milliseconds<T>(&self, value: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -291,7 +295,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.setMinutes()`.
#[inline]
pub fn set_minutes(&self, values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn set_minutes(&self, values: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
Date::set_minutes::<true>(&self.inner.clone().into(), values, context)
}
@ -302,7 +306,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.setMonth()`.
#[inline]
pub fn set_month(&self, values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn set_month(&self, values: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
Date::set_month::<true>(&self.inner.clone().into(), values, context)
}
@ -313,7 +317,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.setSeconds()`.
#[inline]
pub fn set_seconds(&self, values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn set_seconds(&self, values: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
Date::set_seconds::<true>(&self.inner.clone().into(), values, context)
}
@ -325,7 +329,7 @@ impl JsDate {
/// the UNIX epoch and the updated date.
///
/// Same as JavaScript's `Date.prototype.setTime()`.
pub fn set_time<T>(&self, value: T, context: &mut Context) -> JsResult<JsValue>
pub fn set_time<T>(&self, value: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -339,7 +343,7 @@ impl JsDate {
/// the UNIX epoch and the updated date.
///
/// Same as JavaScript's `Date.prototype.setUTCDate()`.
pub fn set_utc_date<T>(&self, value: T, context: &mut Context) -> JsResult<JsValue>
pub fn set_utc_date<T>(&self, value: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -357,7 +361,7 @@ impl JsDate {
pub fn set_utc_full_year(
&self,
values: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Date::set_full_year::<false>(&self.inner.clone().into(), values, context)
}
@ -369,7 +373,11 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.setUTCHours()`.
#[inline]
pub fn set_utc_hours(&self, values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn set_utc_hours(
&self,
values: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Date::set_hours::<false>(&self.inner.clone().into(), values, context)
}
@ -379,7 +387,7 @@ impl JsDate {
/// the UNIX epoch and the updated date.
///
/// Same as JavaScript's `Date.prototype.setUTCMilliseconds()`.
pub fn set_utc_milliseconds<T>(&self, value: T, context: &mut Context) -> JsResult<JsValue>
pub fn set_utc_milliseconds<T>(&self, value: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -393,7 +401,11 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.setUTCMinutes()`.
#[inline]
pub fn set_utc_minutes(&self, values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn set_utc_minutes(
&self,
values: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Date::set_minutes::<false>(&self.inner.clone().into(), values, context)
}
@ -404,7 +416,11 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.setUTCMonth()`.
#[inline]
pub fn set_utc_month(&self, values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn set_utc_month(
&self,
values: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Date::set_month::<false>(&self.inner.clone().into(), values, context)
}
@ -415,7 +431,11 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.setUTCSeconds()`.
#[inline]
pub fn set_utc_seconds(&self, values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn set_utc_seconds(
&self,
values: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Date::set_seconds::<false>(&self.inner.clone().into(), values, context)
}
@ -423,7 +443,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.toDateString()`.
#[inline]
pub fn to_date_string(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn to_date_string(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::to_date_string(&self.inner.clone().into(), &[JsValue::Null], context)
}
@ -434,7 +454,7 @@ impl JsDate {
/// Same as JavaScript's legacy `Date.prototype.toGMTString()`
#[deprecated]
#[inline]
pub fn to_gmt_string(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn to_gmt_string(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::to_gmt_string(&self.inner.clone().into(), &[JsValue::Null], context)
}
@ -443,7 +463,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.toISOString()`.
#[inline]
pub fn to_iso_string(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn to_iso_string(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::to_iso_string(&self.inner.clone().into(), &[JsValue::Null], context)
}
@ -451,7 +471,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.toJSON()`.
#[inline]
pub fn to_json(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn to_json(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::to_json(&self.inner.clone().into(), &[JsValue::Null], context)
}
@ -464,7 +484,7 @@ impl JsDate {
pub fn to_local_date_string(
&self,
values: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Date::to_locale_date_string(&self.inner.clone().into(), values, context)
}
@ -474,7 +494,11 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.toLocaleDateString()`.
#[inline]
pub fn to_locale_string(&self, values: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
pub fn to_locale_string(
&self,
values: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Date::to_locale_string(&self.inner.clone().into(), values, context)
}
@ -485,7 +509,7 @@ impl JsDate {
pub fn to_locale_time_string(
&self,
values: &[JsValue],
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Date::to_locale_time_string(&self.inner.clone().into(), values, context)
}
@ -494,7 +518,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.toString()`.
#[inline]
pub fn to_string(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn to_string(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::to_string(&self.inner.clone().into(), &[JsValue::Null], context)
}
@ -502,7 +526,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.toTimeString()`.
#[inline]
pub fn to_time_string(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn to_time_string(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::to_time_string(&self.inner.clone().into(), &[JsValue::Null], context)
}
@ -510,7 +534,7 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.toUTCString()`.
#[inline]
pub fn to_utc_string(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn to_utc_string(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::to_utc_string(&self.inner.clone().into(), &[JsValue::Null], context)
}
@ -518,12 +542,12 @@ impl JsDate {
///
/// Same as JavaScript's `Date.prototype.valueOf()`.
#[inline]
pub fn value_of(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn value_of(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Date::value_of(&self.inner.clone().into(), &[JsValue::Null], context)
}
/// Utility create a `Date` object from RFC3339 string
pub fn new_from_parse(value: &JsValue, context: &mut Context) -> JsResult<Self> {
pub fn new_from_parse(value: &JsValue, context: &mut Context<'_>) -> JsResult<Self> {
let prototype = context.intrinsics().constructors().date().prototype();
let string = value
.to_string(context)?

8
boa_engine/src/object/builtins/jsgenerator.rs

@ -17,7 +17,7 @@ pub struct JsGenerator {
impl JsGenerator {
/// Create a new `JsGenerator` object
#[inline]
pub fn new(context: &mut Context) -> Self {
pub fn new(context: &mut Context<'_>) -> Self {
let prototype = context.intrinsics().constructors().generator().prototype();
let generator = JsObject::from_proto_and_data(
@ -46,7 +46,7 @@ impl JsGenerator {
/// Calls `Generator.prototype.next()`
///
/// This method returns an object with the properties `done` and `value`
pub fn next<T>(&self, value: T, context: &mut Context) -> JsResult<JsValue>
pub fn next<T>(&self, value: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -56,7 +56,7 @@ impl JsGenerator {
/// Calls `Generator.prototype.return()`
///
/// This method returns the given value and finishes the generator
pub fn r#return<T>(&self, value: T, context: &mut Context) -> JsResult<JsValue>
pub fn r#return<T>(&self, value: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -67,7 +67,7 @@ impl JsGenerator {
///
/// This method resumes the execution of a generator by throwing an error and returning an
/// an object with the properties `done` and `value`
pub fn throw<T>(&self, value: T, context: &mut Context) -> JsResult<JsValue>
pub fn throw<T>(&self, value: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{

26
boa_engine/src/object/builtins/jsmap.rs

@ -86,7 +86,7 @@ impl JsMap {
/// let map = JsMap::new(context);
/// ```
#[inline]
pub fn new(context: &mut Context) -> Self {
pub fn new(context: &mut Context<'_>) -> Self {
let map = Self::create_map(context);
Self { inner: map }
}
@ -115,7 +115,7 @@ impl JsMap {
/// # Ok(())
/// # }
/// ```
pub fn from_js_iterable(iterable: &JsValue, context: &mut Context) -> JsResult<Self> {
pub fn from_js_iterable(iterable: &JsValue, context: &mut Context<'_>) -> JsResult<Self> {
// Create a new map object.
let map = Self::create_map(context);
@ -178,7 +178,7 @@ impl JsMap {
}
// Utility function to generate the default `Map` object.
fn create_map(context: &mut Context) -> JsObject {
fn create_map(context: &mut Context<'_>) -> JsObject {
// Get default Map prototype
let prototype = context.intrinsics().constructors().map().prototype();
@ -188,7 +188,7 @@ impl JsMap {
/// Returns a new [`JsMapIterator`] object that yields the `[key, value]` pairs within the [`JsMap`] in insertion order.
#[inline]
pub fn entries(&self, context: &mut Context) -> JsResult<JsMapIterator> {
pub fn entries(&self, context: &mut Context<'_>) -> JsResult<JsMapIterator> {
let iterator_record = Map::entries(&self.inner.clone().into(), &[], context)?
.get_iterator(context, None, None)?;
let map_iterator_object = iterator_record.iterator();
@ -197,7 +197,7 @@ impl JsMap {
/// Returns a new [`JsMapIterator`] object that yields the `key` for each element within the [`JsMap`] in insertion order.
#[inline]
pub fn keys(&self, context: &mut Context) -> JsResult<JsMapIterator> {
pub fn keys(&self, context: &mut Context<'_>) -> JsResult<JsMapIterator> {
let iterator_record = Map::keys(&self.inner.clone().into(), &[], context)?
.get_iterator(context, None, None)?;
let map_iterator_object = iterator_record.iterator();
@ -225,7 +225,7 @@ impl JsMap {
/// # Ok(())
/// # }
/// ```
pub fn set<K, V>(&self, key: K, value: V, context: &mut Context) -> JsResult<JsValue>
pub fn set<K, V>(&self, key: K, value: V, context: &mut Context<'_>) -> JsResult<JsValue>
where
K: Into<JsValue>,
V: Into<JsValue>,
@ -259,7 +259,7 @@ impl JsMap {
/// # }
/// ```
#[inline]
pub fn get_size(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn get_size(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Map::get_size(&self.inner.clone().into(), &[], context)
}
@ -285,7 +285,7 @@ impl JsMap {
/// # Ok(())
/// # }
/// ```
pub fn delete<T>(&self, key: T, context: &mut Context) -> JsResult<JsValue>
pub fn delete<T>(&self, key: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -312,7 +312,7 @@ impl JsMap {
/// # Ok(())
/// # }
/// ```
pub fn get<T>(&self, key: T, context: &mut Context) -> JsResult<JsValue>
pub fn get<T>(&self, key: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -341,7 +341,7 @@ impl JsMap {
/// # }
/// ```
#[inline]
pub fn clear(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn clear(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
Map::clear(&self.inner.clone().into(), &[], context)
}
@ -365,7 +365,7 @@ impl JsMap {
/// # Ok(())
/// # }
/// ```
pub fn has<T>(&self, key: T, context: &mut Context) -> JsResult<JsValue>
pub fn has<T>(&self, key: T, context: &mut Context<'_>) -> JsResult<JsValue>
where
T: Into<JsValue>,
{
@ -378,7 +378,7 @@ impl JsMap {
&self,
callback: JsFunction,
this_arg: JsValue,
context: &mut Context,
context: &mut Context<'_>,
) -> JsResult<JsValue> {
Map::for_each(
&self.inner.clone().into(),
@ -389,7 +389,7 @@ impl JsMap {
/// Returns a new [`JsMapIterator`] object that yields the `value` for each element within the [`JsMap`] in insertion order.
#[inline]
pub fn values(&self, context: &mut Context) -> JsResult<JsMapIterator> {
pub fn values(&self, context: &mut Context<'_>) -> JsResult<JsMapIterator> {
let iterator_record = Map::values(&self.inner.clone().into(), &[], context)?
.get_iterator(context, None, None)?;
let map_iterator_object = iterator_record.iterator();

2
boa_engine/src/object/builtins/jsmap_iterator.rs

@ -29,7 +29,7 @@ impl JsMapIterator {
}
/// Advances the `JsMapIterator` and gets the next result in the `JsMap`
pub fn next(&self, context: &mut Context) -> JsResult<JsValue> {
pub fn next(&self, context: &mut Context<'_>) -> JsResult<JsValue> {
MapIterator::next(&self.inner.clone().into(), &[], context)
}
}

6
boa_engine/src/object/builtins/jsproxy.rs

@ -80,7 +80,7 @@ impl JsRevocableProxy {
/// Disables the traps of the internal `proxy` object, essentially
/// making it unusable and throwing `TypeError`s for all the traps.
#[inline]
pub fn revoke(self, context: &mut Context) -> JsResult<()> {
pub fn revoke(self, context: &mut Context<'_>) -> JsResult<()> {
self.revoker.call(&JsValue::undefined(), &[], context)?;
Ok(())
}
@ -370,7 +370,7 @@ impl JsProxyBuilder {
/// [`JsObject`] in case there's a need to manipulate the returned object
/// inside Rust code.
#[must_use]
pub fn build(self, context: &mut Context) -> JsProxy {
pub fn build(self, context: &mut Context<'_>) -> JsProxy {
let handler = JsObject::with_object_proto(context);
if let Some(apply) = self.apply {
@ -487,7 +487,7 @@ impl JsProxyBuilder {
/// revoker in case there's a need to manipulate the returned objects
/// inside Rust code.
#[must_use]
pub fn build_revocable(self, context: &mut Context) -> JsRevocableProxy {
pub fn build_revocable(self, context: &mut Context<'_>) -> JsRevocableProxy {
let proxy = self.build(context);
let revoker = Proxy::revoker(proxy.inner.clone(), context);

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save