Browse Source

Simplify all extensions APIs of `Context` (#3456)

pull/3460/head
José Julián Espina 12 months ago committed by GitHub
parent
commit
baa4f9893b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      boa_cli/src/debug/function.rs
  2. 4
      boa_cli/src/debug/gc.rs
  3. 14
      boa_cli/src/debug/limits.rs
  4. 4
      boa_cli/src/debug/mod.rs
  5. 4
      boa_cli/src/debug/object.rs
  6. 18
      boa_cli/src/debug/optimizer.rs
  7. 4
      boa_cli/src/debug/realm.rs
  8. 8
      boa_cli/src/debug/shape.rs
  9. 31
      boa_cli/src/main.rs
  10. 8
      boa_engine/src/builtins/array/array_iterator.rs
  11. 140
      boa_engine/src/builtins/array/mod.rs
  12. 4
      boa_engine/src/builtins/array/tests.rs
  13. 18
      boa_engine/src/builtins/array_buffer/mod.rs
  14. 14
      boa_engine/src/builtins/array_buffer/shared.rs
  15. 2
      boa_engine/src/builtins/array_buffer/utils.rs
  16. 2
      boa_engine/src/builtins/async_function/mod.rs
  17. 14
      boa_engine/src/builtins/async_generator/mod.rs
  18. 2
      boa_engine/src/builtins/async_generator_function/mod.rs
  19. 20
      boa_engine/src/builtins/atomics/mod.rs
  20. 19
      boa_engine/src/builtins/bigint/mod.rs
  21. 14
      boa_engine/src/builtins/boolean/mod.rs
  22. 52
      boa_engine/src/builtins/dataview/mod.rs
  23. 98
      boa_engine/src/builtins/date/mod.rs
  24. 2
      boa_engine/src/builtins/error/aggregate.rs
  25. 2
      boa_engine/src/builtins/error/eval.rs
  26. 6
      boa_engine/src/builtins/error/mod.rs
  27. 2
      boa_engine/src/builtins/error/range.rs
  28. 2
      boa_engine/src/builtins/error/reference.rs
  29. 2
      boa_engine/src/builtins/error/syntax.rs
  30. 2
      boa_engine/src/builtins/error/type.rs
  31. 2
      boa_engine/src/builtins/error/uri.rs
  32. 4
      boa_engine/src/builtins/escape/mod.rs
  33. 4
      boa_engine/src/builtins/eval/mod.rs
  34. 4
      boa_engine/src/builtins/function/arguments.rs
  35. 24
      boa_engine/src/builtins/function/mod.rs
  36. 14
      boa_engine/src/builtins/generator/mod.rs
  37. 2
      boa_engine/src/builtins/generator_function/mod.rs
  38. 20
      boa_engine/src/builtins/intl/collator/mod.rs
  39. 2
      boa_engine/src/builtins/intl/collator/options.rs
  40. 6
      boa_engine/src/builtins/intl/date_time_format.rs
  41. 25
      boa_engine/src/builtins/intl/list_format/mod.rs
  42. 2
      boa_engine/src/builtins/intl/list_format/options.rs
  43. 56
      boa_engine/src/builtins/intl/locale/mod.rs
  44. 8
      boa_engine/src/builtins/intl/locale/options.rs
  45. 16
      boa_engine/src/builtins/intl/locale/tests.rs
  46. 46
      boa_engine/src/builtins/intl/locale/utils.rs
  47. 4
      boa_engine/src/builtins/intl/mod.rs
  48. 2
      boa_engine/src/builtins/intl/number_format/utils.rs
  49. 6
      boa_engine/src/builtins/intl/options.rs
  50. 16
      boa_engine/src/builtins/intl/plural_rules/mod.rs
  51. 2
      boa_engine/src/builtins/intl/plural_rules/options.rs
  52. 8
      boa_engine/src/builtins/intl/segmenter/iterator.rs
  53. 20
      boa_engine/src/builtins/intl/segmenter/mod.rs
  54. 14
      boa_engine/src/builtins/intl/segmenter/segments.rs
  55. 10
      boa_engine/src/builtins/iterable/async_from_sync_iterator.rs
  56. 24
      boa_engine/src/builtins/iterable/mod.rs
  57. 16
      boa_engine/src/builtins/json/mod.rs
  58. 8
      boa_engine/src/builtins/map/map_iterator.rs
  59. 40
      boa_engine/src/builtins/map/mod.rs
  60. 202
      boa_engine/src/builtins/math/mod.rs
  61. 6
      boa_engine/src/builtins/mod.rs
  62. 16
      boa_engine/src/builtins/number/globals.rs
  63. 26
      boa_engine/src/builtins/number/mod.rs
  64. 8
      boa_engine/src/builtins/object/for_in_iterator.rs
  65. 94
      boa_engine/src/builtins/object/mod.rs
  66. 10
      boa_engine/src/builtins/options.rs
  67. 62
      boa_engine/src/builtins/promise/mod.rs
  68. 8
      boa_engine/src/builtins/proxy/mod.rs
  69. 42
      boa_engine/src/builtins/reflect/mod.rs
  70. 58
      boa_engine/src/builtins/regexp/mod.rs
  71. 4
      boa_engine/src/builtins/regexp/regexp_string_iterator.rs
  72. 28
      boa_engine/src/builtins/set/mod.rs
  73. 8
      boa_engine/src/builtins/set/set_iterator.rs
  74. 156
      boa_engine/src/builtins/string/mod.rs
  75. 4
      boa_engine/src/builtins/string/string_iterator.rs
  76. 26
      boa_engine/src/builtins/symbol/mod.rs
  77. 132
      boa_engine/src/builtins/temporal/calendar/mod.rs
  78. 60
      boa_engine/src/builtins/temporal/duration/mod.rs
  79. 12
      boa_engine/src/builtins/temporal/duration/record.rs
  80. 32
      boa_engine/src/builtins/temporal/fields.rs
  81. 38
      boa_engine/src/builtins/temporal/instant/mod.rs
  82. 19
      boa_engine/src/builtins/temporal/mod.rs
  83. 22
      boa_engine/src/builtins/temporal/now.rs
  84. 4
      boa_engine/src/builtins/temporal/options.rs
  85. 66
      boa_engine/src/builtins/temporal/plain_date/mod.rs
  86. 28
      boa_engine/src/builtins/temporal/plain_date_time/mod.rs
  87. 4
      boa_engine/src/builtins/temporal/plain_month_day/mod.rs
  88. 2
      boa_engine/src/builtins/temporal/plain_time/mod.rs
  89. 36
      boa_engine/src/builtins/temporal/plain_year_month/mod.rs
  90. 30
      boa_engine/src/builtins/temporal/time_zone/mod.rs
  91. 2
      boa_engine/src/builtins/temporal/zoned_date_time/mod.rs
  92. 130
      boa_engine/src/builtins/typed_array/builtin.rs
  93. 4
      boa_engine/src/builtins/typed_array/element/mod.rs
  94. 4
      boa_engine/src/builtins/typed_array/mod.rs
  95. 8
      boa_engine/src/builtins/uri/mod.rs
  96. 8
      boa_engine/src/builtins/weak/weak_ref.rs
  97. 10
      boa_engine/src/builtins/weak_map/mod.rs
  98. 8
      boa_engine/src/builtins/weak_set/mod.rs
  99. 2
      boa_engine/src/bytecompiler/class.rs
  100. 2
      boa_engine/src/bytecompiler/declaration/declaration_pattern.rs
  101. Some files were not shown because too many files have changed in this diff Show More

10
boa_cli/src/debug/function.rs

@ -51,7 +51,7 @@ fn flowgraph_parse_direction_option(value: &JsValue) -> JsResult<Direction> {
}
/// Get functions instruction flowgraph
fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let Some(value) = args.get(0) else {
return Err(JsNativeError::typ()
.with_message("expected function argument")
@ -101,7 +101,7 @@ fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> Js
Ok(JsValue::new(js_string!(result)))
}
fn bytecode(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn bytecode(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let Some(value) = args.get(0) else {
return Err(JsNativeError::typ()
.with_message("expected function argument")
@ -137,7 +137,7 @@ fn set_trace_flag_in_function_object(object: &JsObject, value: bool) -> JsResult
}
/// Trace function.
fn trace(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn trace(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let value = args.get_or_undefined(0);
let this = args.get_or_undefined(1);
@ -156,7 +156,7 @@ fn trace(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<J
result
}
fn traceable(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn traceable(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let value = args.get_or_undefined(0);
let traceable = args.get_or_undefined(1).to_boolean();
@ -171,7 +171,7 @@ fn traceable(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsV
Ok(value.clone())
}
pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
pub(super) fn create_object(context: &mut Context) -> JsObject {
ObjectInitializer::new(context)
.function(
NativeFunction::from_fn_ptr(flowgraph),

4
boa_cli/src/debug/gc.rs

@ -3,12 +3,12 @@ use boa_engine::{
};
/// Trigger garbage collection.
fn collect(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn collect(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
boa_gc::force_collect();
Ok(JsValue::undefined())
}
pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
pub(super) fn create_object(context: &mut Context) -> JsObject {
ObjectInitializer::new(context)
.function(
NativeFunction::from_fn_ptr(collect),

14
boa_cli/src/debug/limits.rs

@ -5,23 +5,23 @@ use boa_engine::{
Context, JsArgs, JsNativeError, JsObject, JsResult, JsValue, NativeFunction,
};
fn get_loop(_: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn get_loop(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let max = context.runtime_limits().loop_iteration_limit();
Ok(JsValue::from(max))
}
fn set_loop(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn set_loop(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let value = args.get_or_undefined(0).to_length(context)?;
context.runtime_limits_mut().set_loop_iteration_limit(value);
Ok(JsValue::undefined())
}
fn get_stack(_: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn get_stack(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let max = context.runtime_limits().stack_size_limit();
Ok(JsValue::from(max))
}
fn set_stack(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn set_stack(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let value = args.get_or_undefined(0).to_length(context)?;
let Ok(value) = value.try_into() else {
return Err(JsNativeError::range()
@ -32,12 +32,12 @@ fn set_stack(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResu
Ok(JsValue::undefined())
}
fn get_recursion(_: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn get_recursion(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let max = context.runtime_limits().recursion_limit();
Ok(JsValue::from(max))
}
fn set_recursion(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn set_recursion(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let value = args.get_or_undefined(0).to_length(context)?;
let Ok(value) = value.try_into() else {
return Err(JsNativeError::range()
@ -48,7 +48,7 @@ fn set_recursion(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> Js
Ok(JsValue::undefined())
}
pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
pub(super) fn create_object(context: &mut Context) -> JsObject {
let get_loop =
FunctionObjectBuilder::new(context.realm(), NativeFunction::from_fn_ptr(get_loop))
.name("get loop")

4
boa_cli/src/debug/mod.rs

@ -11,7 +11,7 @@ mod optimizer;
mod realm;
mod shape;
fn create_boa_object(context: &mut Context<'_>) -> JsObject {
fn create_boa_object(context: &mut Context) -> JsObject {
let function_module = function::create_object(context);
let object_module = object::create_object(context);
let shape_module = shape::create_object(context);
@ -60,7 +60,7 @@ fn create_boa_object(context: &mut Context<'_>) -> JsObject {
}
#[allow(clippy::redundant_pub_crate)]
pub(crate) fn init_boa_debug_object(context: &mut Context<'_>) {
pub(crate) fn init_boa_debug_object(context: &mut Context) {
let boa_object = create_boa_object(context);
context
.register_global_property(

4
boa_cli/src/debug/object.rs

@ -4,7 +4,7 @@ use boa_engine::{
};
/// Returns objects pointer in memory.
fn id(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn id(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let Some(value) = args.get(0) else {
return Err(JsNativeError::typ()
.with_message("expected object argument")
@ -21,7 +21,7 @@ fn id(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
Ok(js_string!(format!("0x{:X}", ptr as usize)).into())
}
pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
pub(super) fn create_object(context: &mut Context) -> JsObject {
ObjectInitializer::new(context)
.function(NativeFunction::from_fn_ptr(id), js_string!("id"), 1)
.build()

18
boa_cli/src/debug/optimizer.rs

@ -6,22 +6,14 @@ use boa_engine::{
Context, JsArgs, JsObject, JsResult, JsValue, NativeFunction,
};
fn get_constant_folding(
_: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn get_constant_folding(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
Ok(context
.optimizer_options()
.contains(OptimizerOptions::CONSTANT_FOLDING)
.into())
}
fn set_constant_folding(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn set_constant_folding(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let value = args.get_or_undefined(0).to_boolean();
let mut options = context.optimizer_options();
options.set(OptimizerOptions::CONSTANT_FOLDING, value);
@ -29,14 +21,14 @@ fn set_constant_folding(
Ok(JsValue::undefined())
}
fn get_statistics(_: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn get_statistics(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
Ok(context
.optimizer_options()
.contains(OptimizerOptions::STATISTICS)
.into())
}
fn set_statistics(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn set_statistics(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let value = args.get_or_undefined(0).to_boolean();
let mut options = context.optimizer_options();
options.set(OptimizerOptions::STATISTICS, value);
@ -44,7 +36,7 @@ fn set_statistics(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> J
Ok(JsValue::undefined())
}
pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
pub(super) fn create_object(context: &mut Context) -> JsObject {
let get_constant_folding = FunctionObjectBuilder::new(
context.realm(),
NativeFunction::from_fn_ptr(get_constant_folding),

4
boa_cli/src/debug/realm.rs

@ -3,13 +3,13 @@ use boa_engine::{
};
/// Creates a new ECMAScript Realm and returns the global object of the realm.
fn create(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn create(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let context = &mut Context::default();
Ok(context.global_object().into())
}
pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
pub(super) fn create_object(context: &mut Context) -> JsObject {
ObjectInitializer::new(context)
.function(NativeFunction::from_fn_ptr(create), js_string!("create"), 0)
.build()

8
boa_cli/src/debug/shape.rs

@ -19,7 +19,7 @@ fn get_object(args: &[JsValue], position: usize) -> JsResult<&JsObject> {
}
/// Returns object's shape pointer in memory.
fn id(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn id(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let object = get_object(args, 0)?;
let object = object.borrow();
let shape = object.shape();
@ -27,7 +27,7 @@ fn id(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
}
/// Returns object's shape type.
fn r#type(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn r#type(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let object = get_object(args, 0)?;
let object = object.borrow();
let shape = object.shape();
@ -41,7 +41,7 @@ fn r#type(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValu
}
/// Returns object's shape type.
fn same(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn same(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let lhs = get_object(args, 0)?;
let rhs = get_object(args, 1)?;
@ -60,7 +60,7 @@ fn same(_: &JsValue, args: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue>
Ok(JsValue::new(lhs_shape_ptr == rhs_shape_ptr))
}
pub(super) fn create_object(context: &mut Context<'_>) -> JsObject {
pub(super) fn create_object(context: &mut Context) -> JsObject {
ObjectInitializer::new(context)
.function(NativeFunction::from_fn_ptr(id), js_string!("id"), 1)
.function(NativeFunction::from_fn_ptr(r#type), js_string!("type"), 1)

31
boa_cli/src/main.rs

@ -67,7 +67,7 @@ use boa_engine::{
context::ContextBuilder,
job::{FutureJob, JobQueue, NativeJob},
js_string,
module::{Module, ModuleLoader, SimpleModuleLoader},
module::{Module, SimpleModuleLoader},
optimizer::OptimizerOptions,
property::Attribute,
script::Script,
@ -81,7 +81,7 @@ use debug::init_boa_debug_object;
use rustyline::{config::Config, error::ReadlineError, EditMode, Editor};
use std::{
cell::RefCell, collections::VecDeque, eprintln, fs::read, fs::OpenOptions, io, path::PathBuf,
println,
println, rc::Rc,
};
#[cfg(all(
@ -233,7 +233,7 @@ enum FlowgraphDirection {
///
/// 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]> + ?Sized,
{
@ -278,7 +278,7 @@ where
}
fn generate_flowgraph(
context: &mut Context<'_>,
context: &mut Context,
src: &[u8],
format: FlowgraphFormat,
direction: Option<FlowgraphDirection>,
@ -304,8 +304,8 @@ fn generate_flowgraph(
fn evaluate_files(
args: &Opt,
context: &mut Context<'_>,
loader: &SimpleModuleLoader,
context: &mut Context,
loader: Rc<SimpleModuleLoader>,
) -> Result<(), io::Error> {
for file in &args.files {
let buffer = read(file)?;
@ -382,13 +382,14 @@ fn main() -> Result<(), io::Error> {
let args = Opt::parse();
let queue: &dyn JobQueue = &Jobs::default();
let loader = &SimpleModuleLoader::new(&args.root)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?;
let dyn_loader: &dyn ModuleLoader = loader;
let queue = Rc::new(Jobs::default());
let loader = Rc::new(
SimpleModuleLoader::new(&args.root)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?,
);
let mut context = ContextBuilder::new()
.job_queue(queue)
.module_loader(dyn_loader)
.module_loader(loader.clone())
.build()
.expect("cannot fail with default global object");
@ -491,7 +492,7 @@ fn main() -> Result<(), io::Error> {
}
/// Adds the CLI runtime to the context.
fn add_runtime(context: &mut Context<'_>) {
fn add_runtime(context: &mut Context) {
let console = Console::init(context);
context
.register_global_property(js_string!(Console::NAME), console, Attribute::all())
@ -502,11 +503,11 @@ fn add_runtime(context: &mut Context<'_>) {
struct Jobs(RefCell<VecDeque<NativeJob>>);
impl JobQueue for Jobs {
fn enqueue_promise_job(&self, job: NativeJob, _: &mut Context<'_>) {
fn enqueue_promise_job(&self, job: NativeJob, _: &mut Context) {
self.0.borrow_mut().push_back(job);
}
fn run_jobs(&self, context: &mut Context<'_>) {
fn run_jobs(&self, context: &mut Context) {
loop {
let jobs = std::mem::take(&mut *self.0.borrow_mut());
if jobs.is_empty() {
@ -520,7 +521,7 @@ impl JobQueue for Jobs {
}
}
fn enqueue_future_job(&self, future: FutureJob, _: &mut Context<'_>) {
fn enqueue_future_job(&self, future: FutureJob, _: &mut Context) {
let job = pollster::block_on(future);
self.0.borrow_mut().push_back(job);
}

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

@ -83,7 +83,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_with_shared_shape(
context.root_shape(),
@ -101,11 +101,7 @@ 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()

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

@ -174,7 +174,7 @@ impl BuiltInConstructor for 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.
let new_target = &if new_target.is_undefined() {
@ -263,7 +263,7 @@ impl BuiltInConstructor for Array {
impl Array {
/// Optimized helper function, that sets the length of the array.
fn set_length(o: &JsObject, len: u64, context: &mut Context<'_>) -> JsResult<()> {
fn set_length(o: &JsObject, len: u64, context: &mut Context) -> JsResult<()> {
if o.is_array() && len < (2u64.pow(32) - 1) {
let mut borrowed_object = o.borrow_mut();
if borrowed_object.properties().shape.to_addr_usize()
@ -293,7 +293,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 {
@ -361,7 +361,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>,
{
@ -392,7 +392,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);
@ -421,7 +421,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())
}
@ -433,7 +433,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).
@ -504,7 +504,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);
@ -653,7 +653,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)
@ -670,11 +670,7 @@ 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();
@ -718,11 +714,7 @@ 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)
@ -762,7 +754,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)?;
@ -845,7 +837,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)?;
@ -885,11 +877,7 @@ 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).
@ -932,7 +920,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)?;
@ -978,7 +966,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)?;
@ -1034,7 +1022,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)?;
@ -1064,7 +1052,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)?;
@ -1142,7 +1130,7 @@ impl Array {
pub(crate) fn to_reversed(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -1184,11 +1172,7 @@ 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).
@ -1265,7 +1249,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)?;
@ -1337,7 +1321,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)?;
@ -1389,7 +1373,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)?;
@ -1438,7 +1422,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)?;
@ -1525,7 +1509,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)?;
@ -1595,7 +1579,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)?;
@ -1636,7 +1620,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)?;
@ -1675,7 +1659,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)?;
@ -1714,7 +1698,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)?;
@ -1754,7 +1738,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)?;
@ -1810,7 +1794,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)?;
@ -1857,7 +1841,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
@ -1970,7 +1954,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)?;
@ -2018,7 +2002,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)?;
@ -2095,7 +2079,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)?;
@ -2163,7 +2147,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)?;
@ -2221,7 +2205,7 @@ impl Array {
actual_start: u64,
start: Option<&JsValue>,
delete_count: Option<&JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<u64> {
// 8. If start is not present, then
let actual_delete_count = if start.is_none() {
@ -2260,7 +2244,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)?;
@ -2400,11 +2384,7 @@ impl Array {
/// Splices the target array, returning the result as a new array.
///
/// [spec]: https://tc39.es/ecma262/#sec-array.prototype.tospliced
fn to_spliced(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn to_spliced(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let O be ? ToObject(this value).
let o = this.to_object(context)?;
@ -2506,7 +2486,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)?;
@ -2572,7 +2552,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)?;
@ -2617,10 +2597,10 @@ impl Array {
len: u64,
sort_compare: F,
skip_holes: bool,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Vec<JsValue>>
where
F: Fn(&JsValue, &JsValue, &mut Context<'_>) -> JsResult<Ordering>,
F: Fn(&JsValue, &JsValue, &mut Context) -> JsResult<Ordering>,
{
// 1. Let items be a new empty List.
// doesn't matter if it clamps since it's just a best-effort optimization
@ -2683,7 +2663,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) {
@ -2704,7 +2684,7 @@ impl Array {
// 4. Let SortCompare be a new Abstract Closure with parameters (x, y) that captures comparefn and performs the following steps when called:
let sort_compare =
|x: &JsValue, y: &JsValue, context: &mut Context<'_>| -> JsResult<Ordering> {
|x: &JsValue, y: &JsValue, context: &mut Context| -> JsResult<Ordering> {
// a. Return ? CompareArrayElements(x, y, comparefn).
compare_array_elements(x, y, comparefn, context)
};
@ -2746,7 +2726,7 @@ impl Array {
pub(crate) fn to_sorted(
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) {
@ -2770,7 +2750,7 @@ impl Array {
// 5. Let SortCompare be a new Abstract Closure with parameters (x, y) that captures comparefn and performs the following steps when called:
let sort_compare =
|x: &JsValue, y: &JsValue, context: &mut Context<'_>| -> JsResult<Ordering> {
|x: &JsValue, y: &JsValue, context: &mut Context| -> JsResult<Ordering> {
// a. Return ? CompareArrayElements(x, y, comparefn).
compare_array_elements(x, y, comparefn, context)
};
@ -2803,7 +2783,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)?;
@ -2900,7 +2880,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)?;
@ -2994,7 +2974,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)?;
@ -3084,7 +3064,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)?;
@ -3107,11 +3087,7 @@ 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)?;
@ -3136,7 +3112,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)?;
@ -3155,7 +3131,7 @@ impl Array {
pub(crate) fn with(
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)?;
@ -3215,7 +3191,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: &JsValue,
len: u64,
) -> JsResult<u64> {
@ -3237,7 +3213,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,
value: &JsValue,
len: u64,
) -> JsResult<u64> {
@ -3326,7 +3302,7 @@ fn compare_array_elements(
x: &JsValue,
y: &JsValue,
comparefn: Option<&JsObject>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Ordering> {
match (x.is_undefined(), y.is_undefined()) {
// 1. If x and y are both undefined, return +0𝔽.
@ -3378,7 +3354,7 @@ pub(crate) fn find_via_predicate(
direction: Direction,
predicate: &JsValue,
this_arg: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
caller_name: &str,
) -> JsResult<(JsValue, JsValue)> {
// 1. If IsCallable(predicate) is false, throw a TypeError exception.

4
boa_engine/src/builtins/array/tests.rs

@ -873,7 +873,7 @@ fn array_spread_non_iterable() {
#[test]
fn get_relative_start() {
#[track_caller]
fn assert(context: &mut Context<'_>, arg: Option<&JsValue>, len: u64, expected: u64) {
fn assert(context: &mut Context, arg: Option<&JsValue>, len: u64, expected: u64) {
let arg = arg.unwrap_or(&JsValue::Undefined);
assert_eq!(
Array::get_relative_start(context, arg, len).unwrap(),
@ -900,7 +900,7 @@ fn get_relative_start() {
#[test]
fn get_relative_end() {
#[track_caller]
fn assert(context: &mut Context<'_>, arg: Option<&JsValue>, len: u64, expected: u64) {
fn assert(context: &mut Context, arg: Option<&JsValue>, len: u64, expected: u64) {
let arg = arg.unwrap_or(&JsValue::Undefined);
assert_eq!(
Array::get_relative_end(context, arg, len).unwrap(),

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

@ -192,7 +192,7 @@ impl BuiltInConstructor for 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() {
@ -217,7 +217,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())
}
@ -229,7 +229,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.
@ -250,7 +250,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]]).
@ -275,7 +275,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(|| {
@ -384,7 +384,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(
@ -424,7 +424,7 @@ fn get_slice_range(
len: u64,
relative_start: &JsValue,
end: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<SliceRange> {
// 5. Let len be O.[[ArrayBufferByteLength]].
@ -471,8 +471,8 @@ fn get_slice_range(
/// integer). For more information, check the [spec][spec].
///
/// [spec]: https://tc39.es/ecma262/#sec-createbytedatablock
pub(crate) fn create_byte_data_block(size: u64, context: &mut Context<'_>) -> JsResult<Vec<u8>> {
if size > context.host_hooks().max_buffer_size() {
pub(crate) fn create_byte_data_block(size: u64, context: &mut Context) -> JsResult<Vec<u8>> {
if size > context.host_hooks().max_buffer_size(context) {
return Err(JsNativeError::range()
.with_message(
"cannot allocate a buffer that exceeds the maximum buffer size".to_string(),

14
boa_engine/src/builtins/array_buffer/shared.rs

@ -112,7 +112,7 @@ impl BuiltInConstructor for SharedArrayBuffer {
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() {
@ -137,7 +137,7 @@ impl SharedArrayBuffer {
///
/// [spec]: https://tc39.es/ecma262/#sec-sharedarraybuffer-@@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())
}
@ -151,7 +151,7 @@ impl SharedArrayBuffer {
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]]).
@ -178,7 +178,7 @@ impl SharedArrayBuffer {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-sharedarraybuffer.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(|| {
@ -259,7 +259,7 @@ impl SharedArrayBuffer {
pub(crate) fn allocate(
constructor: &JsValue,
byte_length: u64,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// TODO:
// 1. Let slots be « [[ArrayBufferData]] ».
@ -315,9 +315,9 @@ impl SharedArrayBuffer {
/// [spec]: https://tc39.es/ecma262/#sec-createsharedbytedatablock
pub(crate) fn create_shared_byte_data_block(
size: u64,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Arc<Box<[AtomicU8]>>> {
if size > context.host_hooks().max_buffer_size() {
if size > context.host_hooks().max_buffer_size(context) {
return Err(JsNativeError::range()
.with_message(
"cannot allocate a buffer that exceeds the maximum buffer size".to_string(),

2
boa_engine/src/builtins/array_buffer/utils.rs

@ -120,7 +120,7 @@ impl SliceRef<'_> {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-clonearraybuffer
pub(crate) fn clone(&self, context: &mut Context<'_>) -> JsResult<JsObject> {
pub(crate) fn clone(&self, context: &mut Context) -> JsResult<JsObject> {
// 1. Assert: IsDetachedBuffer(srcBuffer) is false.
// 2. Let targetBuffer be ? AllocateArrayBuffer(%ArrayBuffer%, srcLength).

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

@ -65,7 +65,7 @@ impl BuiltInConstructor for AsyncFunction {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let active_function = context.active_function_object().unwrap_or_else(|| {
context

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

@ -117,7 +117,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;
@ -205,7 +205,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;
@ -283,7 +283,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;
@ -403,7 +403,7 @@ impl AsyncGenerator {
completion: JsResult<JsValue>,
done: bool,
realm: Option<Realm>,
context: &mut Context<'_>,
context: &mut Context,
) {
// 1. Let queue be generator.[[AsyncGeneratorQueue]].
// 2. Assert: queue is not empty.
@ -465,7 +465,7 @@ impl AsyncGenerator {
state: AsyncGeneratorState,
mut generator_context: GeneratorContext,
completion: CompletionRecord,
context: &mut Context<'_>,
context: &mut Context,
) {
// 1. Assert: generator.[[AsyncGeneratorState]] is either suspendedStart or suspendedYield.
assert!(
@ -516,7 +516,7 @@ impl AsyncGenerator {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-asyncgeneratorawaitreturn
pub(crate) fn await_return(generator: JsObject, value: JsValue, context: &mut Context<'_>) {
pub(crate) fn await_return(generator: JsObject, value: JsValue, context: &mut Context) {
// 1. Let queue be generator.[[AsyncGeneratorQueue]].
// 2. Assert: queue is not empty.
// 3. Let next be the first element of queue.
@ -639,7 +639,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()

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

@ -70,7 +70,7 @@ impl BuiltInConstructor for AsyncGeneratorFunction {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let active_function = context.active_function_object().unwrap_or_else(|| {
context

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

@ -78,7 +78,7 @@ impl BuiltInObject for Atomics {
macro_rules! atomic_op {
($(#[$attr:meta])* $name:ident) => {
$(#[$attr])* fn $name(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
$(#[$attr])* fn $name(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let array = args.get_or_undefined(0);
let index = args.get_or_undefined(1);
@ -145,7 +145,7 @@ impl Atomics {
/// [`Atomics.isLockFree ( size )`][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-atomics.islockfree
fn is_lock_free(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn is_lock_free(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let n be ? ToIntegerOrInfinity(size).
let n = args.get_or_undefined(0).to_integer_or_infinity(context)?;
@ -168,7 +168,7 @@ impl Atomics {
/// [`Atomics.load ( typedArray, index )`][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-atomics.load
fn load(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn load(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let array = args.get_or_undefined(0);
let index = args.get_or_undefined(1);
@ -201,7 +201,7 @@ impl Atomics {
/// [`Atomics.store ( typedArray, index, value )`][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-atomics.store
fn store(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn store(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let array = args.get_or_undefined(0);
let index = args.get_or_undefined(1);
let value = args.get_or_undefined(2);
@ -253,11 +253,7 @@ impl Atomics {
/// [`Atomics.compareExchange ( typedArray, index, expectedValue, replacementValue )`][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-atomics.compareexchange
fn compare_exchange(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn compare_exchange(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let array = args.get_or_undefined(0);
let index = args.get_or_undefined(1);
let expected = args.get_or_undefined(2);
@ -408,7 +404,7 @@ impl Atomics {
/// [`Atomics.wait ( typedArray, index, value, timeout )`][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-atomics.wait
fn wait(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn wait(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let array = args.get_or_undefined(0);
let index = args.get_or_undefined(1);
let value = args.get_or_undefined(2);
@ -482,7 +478,7 @@ impl Atomics {
/// [`Atomics.notify ( typedArray, index, count )`][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-atomics.notify
fn notify(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn notify(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let array = args.get_or_undefined(0);
let index = args.get_or_undefined(1);
let count = args.get_or_undefined(2);
@ -576,7 +572,7 @@ fn validate_integer_typed_array(
fn validate_atomic_access(
array: &IntegerIndexed,
request_index: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<usize> {
// 1. Let length be typedArray.[[ArrayLength]].
let length = array.array_length();

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

@ -82,7 +82,7 @@ impl BuiltInConstructor for 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() {
@ -170,7 +170,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)?;
@ -219,11 +219,7 @@ 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)?))
}
@ -237,7 +233,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)?;
@ -263,7 +259,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)?;
@ -275,10 +271,7 @@ 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);

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

@ -61,7 +61,7 @@ impl BuiltInConstructor for Boolean {
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);
@ -107,11 +107,7 @@ 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(js_string!(boolean.to_string())))
}
@ -124,11 +120,7 @@ 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)?))
}
}

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

@ -131,7 +131,7 @@ impl BuiltInConstructor for DataView {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let byte_length = args.get_or_undefined(2);
@ -239,7 +239,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]]).
@ -268,7 +268,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]]).
@ -309,7 +309,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]]).
@ -350,7 +350,7 @@ impl DataView {
view: &JsValue,
request_index: &JsValue,
is_little_endian: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Perform ? RequireInternalSlot(view, [[DataView]]).
// 2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
@ -431,7 +431,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);
@ -454,7 +454,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);
@ -477,7 +477,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);
@ -500,7 +500,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);
@ -523,7 +523,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);
@ -546,7 +546,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);
@ -569,7 +569,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);
@ -592,7 +592,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);
@ -615,7 +615,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);
@ -638,7 +638,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);
@ -662,7 +662,7 @@ impl DataView {
request_index: &JsValue,
is_little_endian: &JsValue,
value: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Perform ? RequireInternalSlot(view, [[DataView]]).
// 2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
@ -745,7 +745,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);
@ -769,7 +769,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);
@ -793,7 +793,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);
@ -817,7 +817,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);
@ -841,7 +841,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);
@ -865,7 +865,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);
@ -889,7 +889,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);
@ -913,7 +913,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);
@ -937,7 +937,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);
@ -961,7 +961,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);

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

@ -235,7 +235,7 @@ impl BuiltInConstructor for Date {
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() {
@ -252,7 +252,7 @@ impl BuiltInConstructor for Date {
// 3. If numberOfArgs = 0, then
[] => {
// a. Let dv be the time value (UTC) identifying the current time.
Self::utc_now(&*context.host_hooks())
Self::utc_now(context.host_hooks())
}
// 4. Else if numberOfArgs = 1, then
// a. Let value be values[0].
@ -328,7 +328,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
@ -431,7 +431,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], context: &mut Context<'_>) -> JsResult<JsValue> {
pub(crate) fn now(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
Ok(JsValue::new(
context.host_hooks().utc_now().timestamp_millis(),
))
@ -449,11 +449,7 @@ 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.
@ -479,11 +475,7 @@ 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()))
@ -499,7 +491,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).
let t = this_time_value(this)?;
@ -528,7 +520,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).
let t = this_time_value(this)?;
@ -560,7 +552,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).
let t = this_time_value(this)?;
@ -583,7 +575,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).
let t = this_time_value(this)?;
@ -611,7 +603,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).
let t = this_time_value(this)?;
@ -639,7 +631,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).
let t = this_time_value(this)?;
@ -667,7 +659,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).
let t = this_time_value(this)?;
@ -696,7 +688,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).
let t = this_time_value(this)?;
@ -724,7 +716,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).
let t = this_time_value(this)?;
@ -755,7 +747,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).
Ok(this_time_value(this)?.map_or(JsValue::nan(), JsValue::from))
@ -775,7 +767,7 @@ impl Date {
pub(crate) fn get_timezone_offset(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let t be ? thisTimeValue(this value).
// 2. If t is NaN, return NaN.
@ -803,7 +795,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);
@ -823,7 +815,7 @@ impl Date {
date: Some(date),
..Default::default()
},
&*context.host_hooks(),
context.host_hooks(),
);
// 7. Set the [[DateValue]] internal slot of this Date object to u.
@ -844,7 +836,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);
@ -890,7 +882,7 @@ impl Date {
date,
..Default::default()
},
&*context.host_hooks(),
context.host_hooks(),
);
// 8. Set the [[DateValue]] internal slot of this Date object to u.
@ -912,7 +904,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);
@ -956,7 +948,7 @@ impl Date {
millisecond,
..Default::default()
},
&*context.host_hooks(),
context.host_hooks(),
);
// 13. Set the [[DateValue]] internal slot of this Date object to u.
@ -976,7 +968,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)).
@ -997,7 +989,7 @@ impl Date {
millisecond: Some(ms),
..Default::default()
},
&*context.host_hooks(),
context.host_hooks(),
);
// 7. Set the [[DateValue]] internal slot of this Date object to u.
@ -1017,7 +1009,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);
@ -1053,7 +1045,7 @@ impl Date {
millisecond,
..Default::default()
},
&*context.host_hooks(),
context.host_hooks(),
);
// 11. Set the [[DateValue]] internal slot of this Date object to u.
@ -1074,7 +1066,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);
@ -1102,7 +1094,7 @@ impl Date {
date,
..Default::default()
},
&*context.host_hooks(),
context.host_hooks(),
);
// 9. Set the [[DateValue]] internal slot of this Date object to u.
@ -1122,7 +1114,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);
@ -1150,7 +1142,7 @@ impl Date {
millisecond,
..Default::default()
},
&*context.host_hooks(),
context.host_hooks(),
);
// 9. Set the [[DateValue]] internal slot of this Date object to u.
@ -1177,7 +1169,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);
@ -1221,7 +1213,7 @@ impl Date {
year: Some(IntegerOrNan::Integer(year)),
..Default::default()
},
&*context.host_hooks(),
context.host_hooks(),
);
// 10. Set the [[DateValue]] internal slot of this Date object to TimeClip(date).
@ -1244,7 +1236,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);
@ -1276,7 +1268,7 @@ impl Date {
pub(crate) fn to_date_string(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be this Date object.
// 2. Let tv be ? thisTimeValue(O).
@ -1309,7 +1301,7 @@ impl Date {
pub(crate) fn to_iso_string(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
let t = this_time_value(this)?
.and_then(NaiveDateTime::from_timestamp_millis)
@ -1333,7 +1325,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)?;
@ -1366,7 +1358,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(js_string!(
"Function Unimplemented"
@ -1385,7 +1377,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(js_string!(
"Function Unimplemented]"
@ -1405,7 +1397,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(js_string!(
"Function Unimplemented]"
@ -1424,7 +1416,7 @@ impl Date {
pub(crate) fn to_string(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let tv be ? thisTimeValue(this value).
// 2. Return ToDateString(tv).
@ -1452,7 +1444,7 @@ impl Date {
pub(crate) fn to_time_string(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be this Date object.
// 2. Let tv be ? thisTimeValue(O).
@ -1483,7 +1475,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)?.and_then(NaiveDateTime::from_timestamp_millis) else {
@ -1517,7 +1509,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(Self::new(this_time_value(this)?).as_value())
@ -1535,7 +1527,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.

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

@ -59,7 +59,7 @@ impl BuiltInConstructor for AggregateError {
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 new_target = &if new_target.is_undefined() {

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

@ -61,7 +61,7 @@ impl BuiltInConstructor for EvalError {
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 new_target = &if new_target.is_undefined() {

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

@ -160,7 +160,7 @@ impl BuiltInConstructor for Error {
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 new_target = &if new_target.is_undefined() {
@ -203,7 +203,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() {
@ -234,7 +234,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.

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

@ -59,7 +59,7 @@ impl BuiltInConstructor for RangeError {
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 new_target = &if new_target.is_undefined() {

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

@ -58,7 +58,7 @@ impl BuiltInConstructor for ReferenceError {
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 new_target = &if new_target.is_undefined() {

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

@ -61,7 +61,7 @@ impl BuiltInConstructor for SyntaxError {
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 new_target = &if new_target.is_undefined() {

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

@ -67,7 +67,7 @@ impl BuiltInConstructor for TypeError {
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 new_target = &if new_target.is_undefined() {

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

@ -60,7 +60,7 @@ impl BuiltInConstructor for UriError {
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 new_target = &if new_target.is_undefined() {

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

@ -38,7 +38,7 @@ impl BuiltInObject for Escape {
}
/// Builtin JavaScript `escape ( string )` function.
fn escape(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn escape(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
/// Returns `true` if the codepoint `cp` is part of the `unescapedSet`.
fn is_unescaped(cp: u16) -> bool {
let Ok(cp) = TryInto::<u8>::try_into(cp) else {
@ -110,7 +110,7 @@ impl BuiltInObject for Unescape {
}
/// Builtin JavaScript `unescape ( string )` function.
fn unescape(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn unescape(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
/// Converts a char `cp` to its corresponding hex digit value.
fn to_hex_digit(cp: u16) -> Option<u16> {
char::from_u32(u32::from(cp))

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

@ -58,7 +58,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)
}
@ -73,7 +73,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.

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();
@ -125,7 +125,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.

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

@ -333,7 +333,7 @@ impl BuiltInConstructor for BuiltInFunctionObject {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let active_function = context
.active_function_object()
@ -356,7 +356,7 @@ impl BuiltInFunctionObject {
args: &[JsValue],
r#async: bool,
generator: bool,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 1. Let currentRealm be the current Realm Record.
// 2. Perform ? HostEnsureCanCompileStrings(currentRealm).
@ -586,7 +586,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(|| {
@ -626,7 +626,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(|| {
@ -708,7 +708,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(|| {
@ -732,7 +732,7 @@ impl BuiltInFunctionObject {
/// [spec]: https://tc39.es/ecma262/#sec-function.prototype.tostring
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString
#[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> {
// 1. Let func be the this value.
let func = this;
@ -794,18 +794,14 @@ 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())
}
}
@ -820,7 +816,7 @@ pub(crate) 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
@ -888,7 +884,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

@ -73,7 +73,7 @@ impl GeneratorContext {
}
/// Creates a new `GeneratorContext` from the current `Context` state.
pub(crate) fn from_current(context: &mut Context<'_>) -> Self {
pub(crate) fn from_current(context: &mut Context) -> Self {
let mut frame = context.vm.frame().clone();
frame.environments = context.vm.environments.clone();
frame.realm = context.realm().clone();
@ -93,7 +93,7 @@ impl GeneratorContext {
&mut self,
value: Option<JsValue>,
resume_kind: GeneratorResumeKind,
context: &mut Context<'_>,
context: &mut Context,
) -> CompletionRecord {
std::mem::swap(&mut context.vm.stack, &mut self.stack);
context
@ -178,7 +178,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).
Self::generator_resume(this, args.get_or_undefined(0).clone(), context)
@ -197,7 +197,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 }.
@ -219,7 +219,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).
@ -240,7 +240,7 @@ impl Generator {
pub(crate) fn generator_resume(
gen: &JsValue,
value: JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let state be ? GeneratorValidate(generator, generatorBrand).
let Some(generator_obj) = gen.as_object() else {
@ -324,7 +324,7 @@ impl Generator {
pub(crate) fn generator_resume_abrupt(
gen: &JsValue,
abrupt_completion: JsResult<JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let state be ? GeneratorValidate(generator, generatorBrand).
let Some(generator_obj) = gen.as_object() else {

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

@ -75,7 +75,7 @@ impl BuiltInConstructor for GeneratorFunction {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let active_function = context.active_function_object().unwrap_or_else(|| {
context

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

@ -80,12 +80,12 @@ impl Service for Collator {
type LocaleOptions = CollatorLocaleOptions;
fn resolve(locale: &mut Locale, options: &mut Self::LocaleOptions, provider: BoaProvider<'_>) {
fn resolve(locale: &mut Locale, options: &mut Self::LocaleOptions, provider: &BoaProvider) {
let collation = options
.collation
.take()
.filter(|co| {
validate_extension::<Self::LangMarker>(locale.id.clone(), key!("co"), co, &provider)
validate_extension::<Self::LangMarker>(locale.id.clone(), key!("co"), co, provider)
})
.or_else(|| {
locale
@ -99,7 +99,7 @@ impl Service for Collator {
locale.id.clone(),
key!("co"),
co,
&provider,
provider,
)
})
})
@ -204,7 +204,7 @@ impl BuiltInConstructor for Collator {
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 new_target = &if new_target.is_undefined() {
@ -333,7 +333,7 @@ impl BuiltInConstructor for Collator {
.unzip();
let collator =
NativeCollator::try_new_unstable(&context.icu().provider(), &collator_locale, {
NativeCollator::try_new_unstable(context.icu().provider(), &collator_locale, {
let mut options = icu_collator::CollatorOptions::new();
options.strength = strength;
options.case_level = case_level;
@ -382,7 +382,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);
@ -405,7 +405,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(|| {
@ -476,11 +476,7 @@ 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(|| {

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

@ -83,7 +83,7 @@ impl FromStr for Usage {
impl ParsableOptionType for Usage {}
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(Self::UpperFirst),
"lower" => Ok(Self::LowerFirst),

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

@ -25,7 +25,7 @@ use boa_profiler::Profiler;
use icu_datetime::options::preferences::HourCycle;
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(Self::H11),
"h12" => Ok(Self::H12),
@ -94,7 +94,7 @@ impl BuiltInConstructor for DateTimeFormat {
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 new_target = &if new_target.is_undefined() {
@ -181,7 +181,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).

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

@ -91,7 +91,7 @@ impl BuiltInConstructor for ListFormat {
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() {
@ -141,17 +141,17 @@ impl BuiltInConstructor for ListFormat {
let data_locale = DataLocale::from(&locale);
let formatter = match typ {
ListFormatType::Conjunction => ListFormatter::try_new_and_with_length_unstable(
&context.icu().provider(),
context.icu().provider(),
&data_locale,
style,
),
ListFormatType::Disjunction => ListFormatter::try_new_or_with_length_unstable(
&context.icu().provider(),
context.icu().provider(),
&data_locale,
style,
),
ListFormatType::Unit => ListFormatter::try_new_unit_with_length_unstable(
&context.icu().provider(),
context.icu().provider(),
&data_locale,
style,
),
@ -191,7 +191,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);
@ -214,7 +214,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(|| {
@ -250,7 +250,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};
@ -406,11 +406,7 @@ 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(|| {
@ -473,10 +469,7 @@ 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 ParsableOptionType 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),

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

@ -176,7 +176,7 @@ impl BuiltInConstructor for Locale {
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() {
@ -390,7 +390,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]]).
@ -428,7 +428,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]]).
@ -463,11 +463,7 @@ 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(|| {
@ -488,11 +484,7 @@ 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(|| {
@ -516,11 +508,7 @@ 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(|| {
@ -549,11 +537,7 @@ 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(|| {
@ -582,11 +566,7 @@ 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(|| {
@ -615,11 +595,7 @@ 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(|| {
@ -648,7 +624,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(|| {
@ -684,7 +660,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]]).
@ -714,11 +690,7 @@ 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(|| {
@ -743,7 +715,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(|| {
@ -773,7 +745,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(|| {

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

@ -6,7 +6,7 @@ use icu_locid::{
use crate::{builtins::options::OptionType, Context, JsNativeError};
impl OptionType for Value {
fn from_value(value: crate::JsValue, context: &mut 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();
if val.len() < 3 {
@ -21,7 +21,7 @@ impl OptionType for Value {
}
impl OptionType for Language {
fn from_value(value: crate::JsValue, context: &mut Context<'_>) -> crate::JsResult<Self> {
fn from_value(value: crate::JsValue, context: &mut Context) -> crate::JsResult<Self> {
value
.to_string(context)?
.to_std_string_escaped()
@ -31,7 +31,7 @@ impl OptionType for Language {
}
impl OptionType for Script {
fn from_value(value: crate::JsValue, context: &mut Context<'_>) -> crate::JsResult<Self> {
fn from_value(value: crate::JsValue, context: &mut Context) -> crate::JsResult<Self> {
value
.to_string(context)?
.to_std_string_escaped()
@ -41,7 +41,7 @@ impl OptionType for Script {
}
impl OptionType for Region {
fn from_value(value: crate::JsValue, context: &mut Context<'_>) -> crate::JsResult<Self> {
fn from_value(value: crate::JsValue, context: &mut Context) -> crate::JsResult<Self> {
value
.to_string(context)?
.to_std_string_escaped()

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

@ -7,7 +7,7 @@ use icu_locid::{
locale, Locale,
};
use icu_plurals::provider::CardinalV1Marker;
use icu_provider::{BufferProvider, DataLocale, DataProvider, DataRequest, DataRequestMetadata};
use icu_provider::{DataLocale, DataProvider, DataRequest, DataRequestMetadata};
use crate::{
builtins::intl::{
@ -15,7 +15,7 @@ use crate::{
options::{IntlOptions, LocaleMatcher},
Service,
},
context::icu::{BoaProvider, Icu},
context::icu::{BoaProvider, Icu, StaticProviderAdapter},
};
#[derive(Debug)]
@ -30,7 +30,7 @@ impl Service for TestService {
type LocaleOptions = TestOptions;
fn resolve(locale: &mut Locale, options: &mut Self::LocaleOptions, provider: BoaProvider<'_>) {
fn resolve(locale: &mut Locale, options: &mut Self::LocaleOptions, provider: &BoaProvider) {
let loc_hc = locale
.extensions
.unicode
@ -49,7 +49,7 @@ impl Service for TestService {
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()
@ -73,8 +73,10 @@ impl Service for TestService {
#[test]
fn locale_resolution() {
let provider: &dyn BufferProvider = boa_icu_provider::buffer();
let icu = Icu::new(BoaProvider::Buffer(provider)).unwrap();
let icu = Icu::new(BoaProvider::Buffer(Box::new(StaticProviderAdapter(
boa_icu_provider::buffer(),
))))
.unwrap();
let mut default = default_locale(icu.locale_canonicalizer());
default
.extensions
@ -103,7 +105,7 @@ fn locale_resolution() {
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);

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

@ -65,7 +65,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() {
@ -314,12 +314,9 @@ 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<'provider, M: KeyedDataMarker>(
requested_locales: &[Locale],
icu: &Icu<'provider>,
) -> Locale
fn lookup_matcher<M: KeyedDataMarker>(requested_locales: &[Locale], icu: &Icu) -> Locale
where
BoaProvider<'provider>: DataProvider<M>,
BoaProvider: DataProvider<M>,
{
// 1. Let result be a new Record.
// 2. For each element locale of requestedLocales, do
@ -330,7 +327,7 @@ where
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 {
@ -362,12 +359,9 @@ where
/// produced by the `LookupMatcher` abstract operation.
///
/// [spec]: https://tc39.es/ecma402/#sec-bestfitmatcher
fn best_fit_matcher<'provider, M: KeyedDataMarker>(
requested_locales: &[Locale],
icu: &Icu<'provider>,
) -> Locale
fn best_fit_matcher<M: KeyedDataMarker>(requested_locales: &[Locale], icu: &Icu) -> Locale
where
BoaProvider<'provider>: DataProvider<M>,
BoaProvider: DataProvider<M>,
{
for mut locale in requested_locales
.iter()
@ -378,7 +372,7 @@ where
{
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;
@ -398,14 +392,14 @@ where
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-resolvelocale
pub(in crate::builtins::intl) fn resolve_locale<'provider, S>(
pub(in crate::builtins::intl) fn resolve_locale<S>(
requested_locales: &[Locale],
options: &mut IntlOptions<S::LocaleOptions>,
icu: &Icu<'provider>,
icu: &Icu,
) -> Locale
where
S: Service,
BoaProvider<'provider>: DataProvider<S::LangMarker>,
BoaProvider: DataProvider<S::LangMarker>,
{
// 1. Let matcher be options.[[localeMatcher]].
// 2. If matcher is "lookup", then
@ -534,13 +528,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<'ctx, 'icu: 'ctx, M: KeyedDataMarker>(
pub(in crate::builtins::intl) fn supported_locales<M: KeyedDataMarker>(
requested_locales: &[Locale],
options: &JsValue,
context: &'ctx mut Context<'icu>,
context: &mut Context,
) -> JsResult<JsObject>
where
BoaProvider<'icu>: DataProvider<M>,
BoaProvider: DataProvider<M>,
{
// 1. Set options to ? CoerceOptionsToObject(options).
let options = coerce_options_to_object(options, context)?;
@ -552,12 +546,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())
}
};
@ -596,13 +590,13 @@ pub(in crate::builtins::intl) fn validate_extension<M: KeyedDataMarker>(
mod tests {
use icu_locid::{langid, locale, Locale};
use icu_plurals::provider::CardinalV1Marker;
use icu_provider::{AsDeserializingBufferProvider, BufferProvider};
use icu_provider::AsDeserializingBufferProvider;
use crate::{
builtins::intl::locale::utils::{
best_available_locale, best_fit_matcher, default_locale, lookup_matcher,
},
context::icu::{BoaProvider, Icu},
context::icu::{BoaProvider, Icu, StaticProviderAdapter},
};
#[test]
@ -628,8 +622,10 @@ mod tests {
#[test]
fn lookup_match() {
let provider: &dyn BufferProvider = boa_icu_provider::buffer();
let icu = Icu::new(BoaProvider::Buffer(provider)).unwrap();
let icu = Icu::new(BoaProvider::Buffer(Box::new(StaticProviderAdapter(
boa_icu_provider::buffer(),
))))
.unwrap();
// requested: []

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

@ -130,7 +130,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);
@ -172,7 +172,7 @@ trait Service {
fn resolve(
_locale: &mut icu_locid::Locale,
_options: &mut Self::LocaleOptions,
_provider: BoaProvider<'_>,
_provider: &BoaProvider,
) {
}
}

2
boa_engine/src/builtins/intl/number_format/utils.rs

@ -24,7 +24,7 @@ pub(crate) fn get_digit_format_options(
min_float_digits_default: u8,
mut max_float_digits_default: u8,
notation: Notation,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<DigitFormatOptions> {
const VALID_ROUNDING_INCREMENTS: [u16; 15] = [
1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000,

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

@ -63,7 +63,7 @@ pub(super) fn get_number_option<T>(
property: &[u16],
minimum: T,
maximum: T,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Option<T>>
where
T: Into<f64> + FromPrimitive,
@ -86,7 +86,7 @@ pub(super) fn default_number_option<T>(
value: &JsValue,
minimum: T,
maximum: T,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Option<T>>
where
T: Into<f64> + FromPrimitive,
@ -123,7 +123,7 @@ where
/// [`get_options_object`]: crate::builtins::options::get_options_object
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() {

16
boa_engine/src/builtins/intl/plural_rules/mod.rs

@ -85,7 +85,7 @@ impl BuiltInConstructor for PluralRules {
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() {
@ -137,11 +137,11 @@ impl BuiltInConstructor for PluralRules {
let native = match rule_type {
PluralRuleType::Cardinal => NativePluralRules::try_new_cardinal_unstable(
&context.icu().provider(),
context.icu().provider(),
&DataLocale::from(&locale),
),
PluralRuleType::Ordinal => NativePluralRules::try_new_ordinal_unstable(
&context.icu().provider(),
context.icu().provider(),
&DataLocale::from(&locale),
),
_ => {
@ -183,7 +183,7 @@ impl PluralRules {
///
/// [spec]: https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.select
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/select
fn select(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn select(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let pr be the this value.
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
let plural_rules = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -214,7 +214,7 @@ impl PluralRules {
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);
@ -238,11 +238,7 @@ impl PluralRules {
///
/// [spec]: https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/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 pr be the this value.
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
let plural_rules = this.as_object().map(JsObject::borrow).ok_or_else(|| {

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

@ -3,7 +3,7 @@ use icu_plurals::PluralRuleType;
use crate::{builtins::options::OptionType, Context, JsNativeError, JsResult, JsValue};
impl OptionType for PluralRuleType {
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() {
"cardinal" => Ok(Self::Cardinal),
"ordinal" => Ok(Self::Ordinal),

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

@ -76,11 +76,7 @@ impl SegmentIterator {
/// [`CreateSegmentIterator ( segmenter, string )`][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-createsegmentiterator
pub(crate) fn create(
segmenter: JsObject,
string: JsString,
context: &mut Context<'_>,
) -> JsObject {
pub(crate) fn create(segmenter: JsObject, string: JsString, context: &mut Context) -> JsObject {
// 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ».
// 2. Let iterator be OrdinaryObjectCreate(%SegmentIteratorPrototype%, internalSlotsList).
// 3. Set iterator.[[IteratingSegmenter]] to segmenter.
@ -104,7 +100,7 @@ impl SegmentIterator {
/// [`%SegmentIteratorPrototype%.next ( )`][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-%segmentiteratorprototype%.next
fn next(this: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let iterator be the this value.
// 2. Perform ? RequireInternalSlot(iterator, [[IteratingSegmenter]]).
let mut iter = this.as_object().map(JsObject::borrow_mut).ok_or_else(|| {

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

@ -114,7 +114,7 @@ impl BuiltInConstructor for Segmenter {
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() {
@ -154,14 +154,14 @@ impl BuiltInConstructor for Segmenter {
let native = match granularity {
Granularity::Grapheme => {
GraphemeClusterSegmenter::try_new_unstable(&context.icu().provider())
GraphemeClusterSegmenter::try_new_unstable(context.icu().provider())
.map(|s| NativeSegmenter::Grapheme(Box::new(s)))
}
Granularity::Word => WordSegmenter::try_new_auto_unstable(&context.icu().provider())
Granularity::Word => WordSegmenter::try_new_auto_unstable(context.icu().provider())
.map(|s| NativeSegmenter::Word(Box::new(s))),
Granularity::Sentence => SentenceSegmenter::try_new_unstable(&context.icu().provider())
Granularity::Sentence => SentenceSegmenter::try_new_unstable(context.icu().provider())
.map(|s| NativeSegmenter::Sentence(Box::new(s))),
}
.map_err(|err| JsNativeError::typ().with_message(err.to_string()))?;
@ -199,7 +199,7 @@ impl Segmenter {
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);
@ -223,11 +223,7 @@ impl Segmenter {
///
/// [spec]: https://tc39.es/ecma402/#sec-Intl.Segmenter.prototype.resolvedoptions
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/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 segmenter be the this value.
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
let segmenter = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -267,7 +263,7 @@ impl Segmenter {
/// Segments a string according to the locale and granularity of this `Intl.Segmenter` object.
///
/// [spec]: https://tc39.es/ecma402/#sec-intl.segmenter.prototype.segment
fn segment(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn segment(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let segmenter be the this value.
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
let segmenter = this
@ -294,7 +290,7 @@ fn create_segment_data_object(
string: JsString,
range: Range<usize>,
is_word_like: Option<bool>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsObject {
// 1. Let len be the length of string.
// 2. Assert: startIndex ≥ 0.

14
boa_engine/src/builtins/intl/segmenter/segments.rs

@ -38,11 +38,7 @@ impl Segments {
/// [`CreateSegmentsObject ( segmenter, string )`][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-createsegmentsobject
pub(crate) fn create(
segmenter: JsObject,
string: JsString,
context: &mut Context<'_>,
) -> JsObject {
pub(crate) fn create(segmenter: JsObject, string: JsString, context: &mut Context) -> JsObject {
// 1. Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ».
// 2. Let segments be OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList).
// 3. Set segments.[[SegmentsSegmenter]] to segmenter.
@ -57,11 +53,7 @@ impl Segments {
/// [`%SegmentsPrototype%.containing ( index )`][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-%segmentsprototype%.containing
fn containing(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn containing(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let segments be the this value.
// 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]).
let segments = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -116,7 +108,7 @@ impl Segments {
/// [`%SegmentsPrototype% [ @@iterator ] ( )`][spec]
///
/// [spec]: https://tc39.es/ecma402/#sec-%segmentsprototype%-@@iterator
fn iterator(this: &JsValue, _: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn iterator(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let segments be the this value.
// 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]).
let segments = this.as_object().map(JsObject::borrow).ok_or_else(|| {

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

@ -62,7 +62,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.
@ -94,7 +94,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]].
@ -141,7 +141,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]].
@ -213,7 +213,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]].
@ -288,7 +288,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

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

@ -195,7 +195,7 @@ impl IntrinsicObject for AsyncIterator {
/// `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.
@ -231,7 +231,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> {
@ -322,7 +322,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(js_string!("done"), context)?.to_boolean())
}
@ -338,7 +338,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(js_string!("value"), context)
}
@ -418,7 +418,7 @@ impl IteratorRecord {
}
/// Gets the current value of the `IteratorRecord`.
pub(crate) fn value(&mut self, context: &mut Context<'_>) -> JsResult<JsValue> {
pub(crate) fn value(&mut self, context: &mut Context) -> JsResult<JsValue> {
self.set_done_on_err(|iter| iter.last_result.value(context))
}
@ -428,11 +428,7 @@ impl IteratorRecord {
}
/// Updates the current result value of this iterator record.
pub(crate) fn update_result(
&mut self,
result: JsValue,
context: &mut Context<'_>,
) -> JsResult<()> {
pub(crate) fn update_result(&mut self, result: JsValue, context: &mut Context) -> JsResult<()> {
self.set_done_on_err(|iter| {
// 3. If Type(result) is not Object, throw a TypeError exception.
// 4. Return result.
@ -466,7 +462,7 @@ impl IteratorRecord {
pub(crate) fn step_with(
&mut self,
value: Option<&JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<bool> {
let _timer = Profiler::global().start_event("IteratorRecord::step_with", "iterator");
@ -498,7 +494,7 @@ impl IteratorRecord {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-iteratorstep
pub(crate) fn step(&mut self, context: &mut Context<'_>) -> JsResult<bool> {
pub(crate) fn step(&mut self, context: &mut Context) -> JsResult<bool> {
self.step_with(None, context)
}
@ -516,7 +512,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");
@ -576,7 +572,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>> {

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

@ -82,11 +82,7 @@ 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)
@ -175,7 +171,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)?;
@ -265,7 +261,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();
@ -415,7 +411,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)?;
@ -586,7 +582,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.
if state.stack.contains(value) {
@ -719,7 +715,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.
if state.stack.contains(value) {

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

@ -75,7 +75,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() {
@ -107,11 +107,7 @@ 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()

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

@ -125,7 +125,7 @@ impl BuiltInConstructor for Map {
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() {
@ -170,7 +170,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())
}
@ -188,7 +188,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).
@ -205,11 +205,7 @@ 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)
@ -225,7 +221,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);
@ -272,11 +268,7 @@ 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]]).
@ -305,11 +297,7 @@ 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> {
const JS_ZERO: &JsValue = &JsValue::Integer(0);
let key = args.get_or_undefined(0);
let key = match key.as_number() {
@ -345,7 +333,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::Integer(0);
let key = args.get_or_undefined(0);
let key = match key.as_number() {
@ -380,7 +368,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() {
@ -410,7 +398,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::Integer(0);
let key = args.get_or_undefined(0);
let key = match key.as_number() {
@ -448,7 +436,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]]).
@ -519,7 +507,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).
@ -533,7 +521,7 @@ impl Map {
pub(crate) fn group_by(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
use std::hash::BuildHasherDefault;
@ -650,7 +638,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(|| {

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

@ -106,11 +106,7 @@ 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).
@ -132,11 +128,7 @@ 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).
@ -156,11 +148,7 @@ 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).
@ -181,11 +169,7 @@ 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).
@ -205,11 +189,7 @@ 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).
@ -228,11 +208,7 @@ 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).
@ -253,11 +229,7 @@ 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).
@ -279,11 +251,7 @@ 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)?;
@ -326,11 +294,7 @@ 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).
@ -349,11 +313,7 @@ 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).
@ -374,11 +334,7 @@ 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).
@ -397,11 +353,7 @@ 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).
@ -421,11 +373,7 @@ 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).
@ -446,11 +394,7 @@ 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).
@ -473,11 +417,7 @@ 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).
@ -497,11 +437,7 @@ 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).
@ -525,7 +461,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)?;
@ -546,11 +482,7 @@ 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).
@ -580,11 +512,7 @@ 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)?;
@ -604,11 +532,7 @@ 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).
@ -630,11 +554,7 @@ 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).
@ -655,11 +575,7 @@ 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).
@ -681,11 +597,7 @@ 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).
@ -707,11 +619,7 @@ 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.
@ -749,11 +657,7 @@ 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.
@ -792,11 +696,7 @@ 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)?;
@ -821,7 +721,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())
}
@ -835,11 +735,7 @@ 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).
@ -865,11 +761,7 @@ 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)?;
@ -890,11 +782,7 @@ 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).
@ -914,11 +802,7 @@ 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).
@ -937,11 +821,7 @@ 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).
@ -961,11 +841,7 @@ 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).
@ -985,11 +861,7 @@ 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).
@ -1010,11 +882,7 @@ 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

@ -170,11 +170,11 @@ pub(crate) trait BuiltInConstructor: BuiltInObject {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue>;
}
fn global_binding<B: BuiltInObject>(context: &mut Context<'_>) -> JsResult<()> {
fn global_binding<B: BuiltInObject>(context: &mut Context) -> JsResult<()> {
let name = B::NAME;
let attr = B::ATTRIBUTE;
let intrinsic = B::get(context.intrinsics());
@ -307,7 +307,7 @@ impl Realm {
/// Abstract operation [`SetDefaultGlobalBindings ( realmRec )`][spec].
///
/// [spec]: https://tc39.es/ecma262/#sec-setdefaultglobalbindings
pub(crate) fn set_default_global_bindings(context: &mut Context<'_>) -> JsResult<()> {
pub(crate) fn set_default_global_bindings(context: &mut Context) -> JsResult<()> {
let global_object = context.global_object();
global_object.define_property_or_throw(

16
boa_engine/src/builtins/number/globals.rs

@ -25,7 +25,7 @@ use num_traits::Num;
///
/// [spec]: https://tc39.es/ecma262/#sec-isfinite-number
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite
fn is_finite(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn is_finite(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
if let Some(value) = args.get(0) {
let number = value.to_number(context)?;
Ok(number.is_finite().into())
@ -67,11 +67,7 @@ impl BuiltInObject for IsFinite {
///
/// [spec]: https://tc39.es/ecma262/#sec-isnan-number
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN
pub(crate) fn is_nan(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn is_nan(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
if let Some(value) = args.get(0) {
let number = value.to_number(context)?;
Ok(number.is_nan().into())
@ -113,11 +109,7 @@ impl BuiltInObject for IsNaN {
///
/// [spec]: https://tc39.es/ecma262/#sec-parseint-string-radix
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
pub(crate) fn parse_int(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn parse_int(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
if let (Some(val), radix) = (args.get(0), args.get_or_undefined(1)) {
// 1. Let inputString be ? ToString(string).
let input_string = val.to_string(context)?;
@ -258,7 +250,7 @@ impl BuiltInObject for ParseInt {
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

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

@ -115,7 +115,7 @@ impl BuiltInConstructor for Number {
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)?,
@ -216,7 +216,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)?;
@ -261,7 +261,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)?;
@ -302,7 +302,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();
@ -410,7 +410,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);
@ -661,7 +661,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)?;
@ -720,11 +720,7 @@ 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)?))
}
@ -746,7 +742,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.
@ -772,7 +768,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())
}
@ -795,7 +791,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) {
@ -824,7 +820,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,

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

@ -77,7 +77,7 @@ impl ForInIterator {
/// - [ECMA reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-createforiniterator
pub(crate) fn create_for_in_iterator(object: JsValue, context: &Context<'_>) -> JsObject {
pub(crate) fn create_for_in_iterator(object: JsValue, context: &Context) -> JsObject {
JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
context
@ -97,11 +97,7 @@ 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()

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

@ -157,7 +157,7 @@ impl BuiltInConstructor for 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()
@ -205,7 +205,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)?;
@ -230,7 +230,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()?;
@ -274,7 +274,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);
@ -317,7 +317,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);
@ -360,7 +360,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)?;
@ -404,7 +404,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)?;
@ -446,7 +446,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);
@ -487,7 +487,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)?;
@ -515,7 +515,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)?;
@ -554,7 +554,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 Some(desc) = desc else {
@ -612,7 +612,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);
@ -627,7 +627,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()
@ -654,7 +654,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()
@ -719,7 +719,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() {
@ -742,7 +742,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 {
@ -778,7 +778,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 {
@ -800,7 +800,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())
}
@ -816,11 +816,7 @@ 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(js_string!("[object Undefined]").into());
@ -881,7 +877,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").
@ -902,7 +898,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)?;
@ -928,7 +924,7 @@ impl Object {
pub fn property_is_enumerable(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let Some(key) = args.get(0) else {
return Ok(JsValue::new(false));
@ -958,7 +954,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)?;
@ -1008,7 +1004,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)
@ -1033,7 +1029,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)
@ -1062,7 +1058,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)
@ -1088,7 +1084,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() {
@ -1114,11 +1110,7 @@ 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.
@ -1139,7 +1131,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() {
@ -1165,11 +1157,7 @@ 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.
@ -1193,7 +1181,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);
@ -1223,7 +1211,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.
@ -1246,7 +1234,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);
@ -1264,7 +1252,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);
@ -1279,7 +1267,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)?;
@ -1298,11 +1286,7 @@ 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()?;
@ -1346,7 +1330,7 @@ impl Object {
pub(crate) fn group_by(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
use std::hash::BuildHasherDefault;
@ -1453,7 +1437,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).
@ -1511,7 +1495,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)?;

10
boa_engine/src/builtins/options.rs

@ -12,7 +12,7 @@ pub(crate) 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>;
}
/// A type that implements [`OptionType`] by parsing a string.
@ -24,7 +24,7 @@ impl<T: ParsableOptionType> OptionType for T
where
T::Err: fmt::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()
@ -51,7 +51,7 @@ where
pub(crate) fn get_option<T: OptionType>(
options: &JsObject,
property: &[u16],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Option<T>> {
// 1. Let value be ? Get(options, property).
let value = options.get(property, context)?;
@ -95,7 +95,7 @@ pub(crate) fn get_options_object(options: &JsValue) -> JsResult<JsObject> {
// Common options used in several builtins
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())
@ -103,7 +103,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)

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

@ -219,7 +219,7 @@ impl PromiseCapability {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-newpromisecapability
pub(crate) fn new(c: &JsObject, context: &mut Context<'_>) -> JsResult<Self> {
pub(crate) fn new(c: &JsObject, context: &mut Context) -> JsResult<Self> {
#[derive(Debug, Clone, Trace, Finalize)]
struct RejectResolve {
reject: JsValue,
@ -393,7 +393,7 @@ impl BuiltInConstructor for 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() {
@ -475,7 +475,7 @@ impl Promise {
pub(crate) fn with_resolvers(
this: &JsValue,
_args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let C be the this value.
let c = this.as_object().ok_or_else(|| {
@ -512,7 +512,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.as_object().ok_or_else(|| {
@ -573,7 +573,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 {
@ -739,7 +739,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.as_object().ok_or_else(|| {
@ -800,7 +800,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 {
@ -1074,7 +1074,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.as_object().ok_or_else(|| {
@ -1135,7 +1135,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 {
@ -1315,7 +1315,7 @@ impl Promise {
pub(crate) fn race(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let iterable = args.get_or_undefined(0);
@ -1383,7 +1383,7 @@ impl Promise {
constructor: &JsObject,
result_capability: &PromiseCapability,
promise_resolve: &JsObject,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
let constructor = constructor.clone().into();
// 1. Repeat,
@ -1431,7 +1431,7 @@ impl Promise {
pub(crate) fn reject(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let r = args.get_or_undefined(0).clone();
@ -1447,7 +1447,7 @@ impl Promise {
pub(crate) fn promise_reject(
c: &JsObject,
e: &JsError,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
let e = e.to_opaque(context);
@ -1475,7 +1475,7 @@ impl Promise {
pub(crate) fn resolve(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let x = args.get_or_undefined(0);
@ -1502,7 +1502,7 @@ impl Promise {
pub(crate) fn promise_resolve(
c: &JsObject,
x: JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 1. If IsPromise(x) is true, then
if let Some(x) = x.as_promise() {
@ -1541,7 +1541,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())
}
@ -1557,7 +1557,7 @@ impl Promise {
pub(crate) fn catch(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let on_rejected = args.get_or_undefined(0);
@ -1582,7 +1582,7 @@ impl Promise {
pub(crate) fn finally(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let promise be the this value.
let promise = this;
@ -1626,7 +1626,7 @@ impl Promise {
pub(crate) fn then_catch_finally_closures(
c: JsObject,
on_finally: JsFunction,
context: &mut Context<'_>,
context: &mut Context,
) -> (JsFunction, JsFunction) {
/// Capture object for the `thenFinallyClosure` abstract closure.
#[derive(Debug, Trace, Finalize)]
@ -1748,7 +1748,7 @@ impl Promise {
pub(crate) fn then(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let promise be the this value.
let promise = this;
@ -1779,7 +1779,7 @@ impl Promise {
promise: &JsObject,
on_fulfilled: Option<JsFunction>,
on_rejected: Option<JsFunction>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 3. Let C be ? SpeciesConstructor(promise, %Promise%).
let c = promise.species_constructor(StandardConstructors::promise, context)?;
@ -1811,7 +1811,7 @@ impl Promise {
on_fulfilled: Option<JsFunction>,
on_rejected: Option<JsFunction>,
result_capability: Option<PromiseCapability>,
context: &mut Context<'_>,
context: &mut Context,
) {
// 1. Assert: IsPromise(promise) is true.
@ -1928,7 +1928,7 @@ impl Promise {
/// [spec]: https://tc39.es/ecma262/#sec-getpromiseresolve
pub(crate) 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(utf16!("resolve"), context)?;
@ -1949,7 +1949,7 @@ impl Promise {
/// [spec]: https://tc39.es/ecma262/#sec-createresolvingfunctions
pub(crate) fn create_resolving_functions(
promise: &JsObject,
context: &mut Context<'_>,
context: &mut Context,
) -> ResolvingFunctions {
/// `TriggerPromiseReactions ( reactions, argument )`
///
@ -1967,7 +1967,7 @@ impl Promise {
fn trigger_promise_reactions(
reactions: Vec<ReactionRecord>,
argument: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) {
// 1. For each element reaction of reactions, do
for reaction in reactions {
@ -1993,7 +1993,7 @@ impl Promise {
/// # Panics
///
/// Panics if `Promise` is not pending.
fn fulfill_promise(promise: &JsObject, value: JsValue, context: &mut Context<'_>) {
fn fulfill_promise(promise: &JsObject, value: JsValue, context: &mut Context) {
let mut promise = promise.borrow_mut();
let promise = promise
.as_promise_mut()
@ -2037,7 +2037,7 @@ impl Promise {
/// # Panics
///
/// Panics if `Promise` is not pending.
fn reject_promise(promise: &JsObject, reason: JsValue, context: &mut Context<'_>) {
fn reject_promise(promise: &JsObject, reason: JsValue, context: &mut Context) {
let handled = {
let mut promise = promise.borrow_mut();
let promise = promise
@ -2230,7 +2230,7 @@ impl Promise {
fn new_promise_reaction_job(
mut reaction: ReactionRecord,
argument: JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> NativeJob {
// Inverting order since `job` captures `reaction` by value.
@ -2248,7 +2248,7 @@ fn new_promise_reaction_job(
.unwrap_or_else(|| context.realm().clone());
// 1. Let job be a new Job Abstract Closure with no parameters that captures reaction and argument and performs the following steps when called:
let job = move |context: &mut Context<'_>| {
let job = move |context: &mut Context| {
// a. Let promiseCapability be reaction.[[Capability]].
let promise_capability = reaction.promise_capability.take();
// b. Let type be reaction.[[Type]].
@ -2323,7 +2323,7 @@ fn new_promise_resolve_thenable_job(
promise_to_resolve: JsObject,
thenable: JsValue,
then: JobCallback,
context: &mut Context<'_>,
context: &mut Context,
) -> NativeJob {
// Inverting order since `job` captures variables by value.
@ -2337,7 +2337,7 @@ fn new_promise_resolve_thenable_job(
.unwrap_or_else(|_| context.realm().clone());
// 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 = move |context: &mut Context<'_>| {
let job = move |context: &mut Context| {
// a. Let resolvingFunctions be CreateResolvingFunctions(promiseToResolve).
let resolving_functions = Promise::create_resolving_functions(&promise_to_resolve, context);

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

@ -65,7 +65,7 @@ impl BuiltInConstructor for Proxy {
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() {
@ -106,7 +106,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(|| {
@ -140,7 +140,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.
FunctionObjectBuilder::new(
@ -176,7 +176,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)?;

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

@ -82,11 +82,7 @@ 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)
@ -114,7 +110,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
@ -154,7 +150,7 @@ impl Reflect {
pub(crate) fn define_property(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -185,7 +181,7 @@ impl Reflect {
pub(crate) fn delete_property(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -204,11 +200,7 @@ 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)
@ -237,7 +229,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
@ -265,7 +257,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)
@ -284,11 +276,7 @@ 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)
@ -311,7 +299,7 @@ impl Reflect {
pub(crate) fn is_extensible(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -331,7 +319,7 @@ impl Reflect {
pub(crate) fn own_keys(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -358,7 +346,7 @@ impl Reflect {
pub(crate) fn prevent_extensions(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let target = args
.get(0)
@ -376,11 +364,7 @@ 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)
@ -407,7 +391,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)

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

@ -179,7 +179,7 @@ impl BuiltInConstructor for RegExp {
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);
@ -270,7 +270,7 @@ impl RegExp {
/// [spec]: https://tc39.es/ecma262/#sec-isregexp
pub(crate) fn is_reg_exp<'a>(
argument: &'a JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Option<&'a JsObject>> {
// 1. If argument is not an Object, return false.
let Some(argument) = argument.as_object() else {
@ -302,7 +302,7 @@ impl RegExp {
fn compile_native_regexp(
pattern: &JsValue,
flags: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<RegExp> {
// 1. If pattern is undefined, let P be the empty String.
// 2. Else, let P be ? ToString(pattern).
@ -364,7 +364,7 @@ impl RegExp {
prototype: Option<JsObject>,
pattern: &JsValue,
flags: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// Has the steps of `RegExpInitialize`.
let regexp = Self::compile_native_regexp(pattern, flags, context)?;
@ -397,7 +397,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%).
// 2. Return ? RegExpInitialize(obj, P, F).
Self::initialize(None, p, f, context)
@ -414,12 +414,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 {
@ -471,7 +471,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)
}
@ -489,7 +489,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)
}
@ -507,7 +507,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)
}
@ -525,7 +525,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)
}
@ -543,7 +543,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)
}
@ -562,7 +562,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)
}
@ -581,7 +581,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)
}
@ -600,7 +600,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.
@ -671,7 +671,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.
@ -753,7 +753,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.
@ -795,7 +795,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]]).
@ -823,7 +823,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.
@ -867,7 +867,7 @@ impl RegExp {
pub(crate) fn abstract_builtin_exec(
this: &JsObject,
input: &JsString,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Option<JsObject>> {
let rx = {
let obj = this.borrow();
@ -1187,7 +1187,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.
@ -1278,11 +1278,7 @@ 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(|| {
@ -1316,7 +1312,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.
@ -1378,7 +1374,7 @@ impl RegExp {
pub(crate) fn replace(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// Helper enum.
enum CallableOrString<'a> {
@ -1617,7 +1613,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.
@ -1671,7 +1667,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.
@ -1843,7 +1839,7 @@ impl RegExp {
///
/// [spec]: https://tc39.es/ecma262/#sec-regexp.prototype.compile
#[cfg(feature = "annex-b")]
fn compile(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn compile(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[RegExpMatcher]]).

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

@ -90,7 +90,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()`.
@ -123,7 +123,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()

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

@ -112,7 +112,7 @@ impl BuiltInConstructor for Set {
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() {
@ -171,7 +171,7 @@ impl BuiltInConstructor for Set {
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());
@ -183,7 +183,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>,
{
@ -209,7 +209,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())
}
@ -224,7 +224,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> {
const JS_ZERO: &JsValue = &JsValue::Integer(0);
// 1. Let S be the this value.
@ -267,7 +267,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)
@ -293,11 +293,7 @@ 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> {
const JS_ZERO: &JsValue = &JsValue::Integer(0);
// 1. Let S be the this value.
@ -340,7 +336,7 @@ impl Set {
pub(crate) fn entries(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let Some(lock) = this
.as_object()
@ -372,7 +368,7 @@ impl Set {
pub(crate) fn for_each(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let S be the this value.
// 2. Perform ? RequireInternalSlot(S, [[SetData]]).
@ -443,7 +439,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> {
const JS_ZERO: &JsValue = &JsValue::Integer(0);
// 1. Let S be the this value.
@ -484,7 +480,7 @@ impl Set {
pub(crate) fn values(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let Some(lock) = this
.as_object()
@ -503,7 +499,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)
}

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

@ -86,7 +86,7 @@ impl SetIterator {
set: JsValue,
kind: PropertyNameKind,
lock: SetLock,
context: &Context<'_>,
context: &Context,
) -> JsValue {
let set_iterator = JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
@ -104,11 +104,7 @@ 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

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

@ -205,7 +205,7 @@ impl BuiltInConstructor for String {
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)
@ -249,7 +249,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();
@ -318,7 +318,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());
@ -372,11 +372,7 @@ 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.
@ -450,7 +446,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();
@ -475,11 +471,7 @@ 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())
}
@ -503,7 +495,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()?;
@ -537,11 +529,7 @@ 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()?;
@ -585,7 +573,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()?;
@ -628,7 +616,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()?;
@ -667,7 +655,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()?;
@ -701,7 +689,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()?;
@ -754,7 +742,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()?;
@ -819,7 +807,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()?;
@ -888,7 +876,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()?;
@ -954,7 +942,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()?;
@ -1006,7 +994,7 @@ impl String {
pub(crate) fn replace(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// Helper enum.
enum CallableOrString<'a> {
@ -1115,7 +1103,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()?;
@ -1267,7 +1255,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()?;
@ -1306,7 +1294,7 @@ impl String {
pub(crate) fn is_well_formed(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let o = this.require_object_coercible()?;
@ -1339,7 +1327,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()?;
@ -1406,7 +1394,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()?;
@ -1469,7 +1457,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()?;
@ -1509,7 +1497,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)?;
@ -1581,7 +1569,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()?;
@ -1608,7 +1596,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()?;
@ -1632,11 +1620,7 @@ 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()?;
@ -1659,7 +1643,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).
@ -1683,7 +1667,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).
@ -1707,7 +1691,7 @@ impl String {
pub(crate) fn to_case<const UPPER: bool>(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let this = this.require_object_coercible()?;
@ -1739,7 +1723,7 @@ impl String {
pub(crate) fn to_locale_case<const UPPER: bool>(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
#[cfg(feature = "intl")]
{
@ -1774,7 +1758,7 @@ impl String {
// 5. Let availableLocales be a List with language tags that includes the languages for which the Unicode Character Database contains language sensitive case mappings. Implementations may add additional language tags if they support case mapping for additional locales.
// 6. Let locale be ! BestAvailableLocale(availableLocales, noExtensionsLocale).
// 7. If locale is undefined, set locale to "und".
let lang = best_available_locale::<CaseMapV1Marker>(lang, &context.icu().provider())
let lang = best_available_locale::<CaseMapV1Marker>(lang, context.icu().provider())
.unwrap_or(LanguageIdentifier::UND);
let casemapper = context.icu().case_mapper();
@ -1814,7 +1798,7 @@ impl String {
pub(crate) fn to_well_formed(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let o = this.require_object_coercible()?;
@ -1857,7 +1841,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()?;
@ -1907,7 +1891,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()?;
@ -2026,7 +2010,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)
@ -2047,7 +2031,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()?;
@ -2104,7 +2088,7 @@ impl String {
pub(crate) fn normalize(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
/// Represents the type of normalization applied to a [`JsString`]
#[derive(Clone, Copy)]
@ -2185,7 +2169,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()?;
@ -2215,7 +2199,7 @@ impl String {
pub(crate) fn iterator(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be ? RequireObjectCoercible(this value).
let o = this.require_object_coercible()?;
@ -2242,7 +2226,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 o = this.require_object_coercible()?;
@ -2306,7 +2290,7 @@ impl String {
string: &JsValue,
tag: &[u16],
attribute_and_value: Option<(&[u16], &JsValue)>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let str be ? RequireObjectCoercible(string).
let str = string.require_object_coercible()?;
@ -2379,7 +2363,7 @@ impl String {
pub(crate) fn anchor(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let name = args.get_or_undefined(0);
@ -2397,11 +2381,7 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.big
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/big
pub(crate) fn big(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn big(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let S be the this value.
let s = this;
// 2. Return ? CreateHTML(S, "big", "", "").
@ -2416,11 +2396,7 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.blink
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/blink
pub(crate) fn blink(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn blink(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let S be the this value.
let s = this;
// 2. Return ? CreateHTML(S, "blink", "", "").
@ -2435,11 +2411,7 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.bold
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/bold
pub(crate) fn bold(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn bold(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let S be the this value.
let s = this;
// 2. Return ? CreateHTML(S, "b", "", "").
@ -2454,11 +2426,7 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.fixed
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fixed
pub(crate) fn fixed(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn fixed(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let S be the this value.
let s = this;
// 2. Return ? CreateHTML(S, "big", "", "").
@ -2476,7 +2444,7 @@ impl String {
pub(crate) fn fontcolor(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let color = args.get_or_undefined(0);
@ -2497,7 +2465,7 @@ impl String {
pub(crate) fn fontsize(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let size = args.get_or_undefined(0);
@ -2518,7 +2486,7 @@ impl String {
pub(crate) fn italics(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let S be the this value.
let s = this;
@ -2537,7 +2505,7 @@ impl String {
pub(crate) fn link(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let url = args.get_or_undefined(0);
@ -2555,11 +2523,7 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.small
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/small
pub(crate) fn small(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn small(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let S be the this value.
let s = this;
// 2. Return ? CreateHTML(S, "small", "", "").
@ -2577,7 +2541,7 @@ impl String {
pub(crate) fn strike(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let S be the this value.
let s = this;
@ -2593,11 +2557,7 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.sub
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/sub
pub(crate) fn sub(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn sub(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let S be the this value.
let s = this;
// 2. Return ? CreateHTML(S, "sub", "", "").
@ -2612,11 +2572,7 @@ impl String {
///
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.sup
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/sup
pub(crate) fn sup(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn sup(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let S be the this value.
let s = this;
// 2. Return ? CreateHTML(S, "sup", "", "").
@ -2637,7 +2593,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.

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

@ -59,7 +59,7 @@ impl IntrinsicObject for StringIterator {
impl StringIterator {
/// Create a new `StringIterator`.
pub fn create_string_iterator(string: JsString, context: &mut Context<'_>) -> JsObject {
pub fn create_string_iterator(string: JsString, context: &mut Context) -> JsObject {
JsObject::from_proto_and_data_with_shared_shape(
context.root_shape(),
context
@ -75,7 +75,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()

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

@ -202,7 +202,7 @@ impl BuiltInConstructor for Symbol {
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() {
@ -251,11 +251,7 @@ 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)?;
@ -273,11 +269,7 @@ 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))
@ -296,7 +288,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).
@ -316,11 +308,7 @@ 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)
@ -347,7 +335,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> {
// 1. If Type(sym) is not Symbol, throw a TypeError exception.
let sym = args.get_or_undefined(0).as_symbol().ok_or_else(|| {
JsNativeError::typ().with_message("Symbol.keyFor: sym is not a symbol")
@ -378,7 +366,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).

132
boa_engine/src/builtins/temporal/calendar/mod.rs

@ -235,7 +235,7 @@ impl BuiltInConstructor for Calendar {
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() {
@ -270,7 +270,7 @@ impl BuiltInConstructor for Calendar {
}
impl Calendar {
fn get_id(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_id(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -287,7 +287,7 @@ impl Calendar {
fn date_from_fields(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
@ -373,7 +373,7 @@ impl Calendar {
fn year_month_from_fields(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
@ -448,7 +448,7 @@ impl Calendar {
fn month_day_from_fields(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
@ -523,7 +523,7 @@ impl Calendar {
}
/// 15.8.2.4 `Temporal.Calendar.prototype.dateAdd ( date, duration [ , options ] )` - supercedes 12.5.7
fn date_add(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn date_add(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
// 3. Assert: calendar.[[Identifier]] is "iso8601".
@ -567,11 +567,7 @@ impl Calendar {
}
///15.8.2.5 `Temporal.Calendar.prototype.dateUntil ( one, two [ , options ] )` - Supercedes 12.5.8
fn date_until(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn date_until(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
// 3. Assert: calendar.[[Identifier]] is "iso8601".
@ -614,7 +610,7 @@ impl Calendar {
}
/// 15.8.2.6 `Temporal.Calendar.prototype.era ( temporalDateLike )`
fn era(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn era(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -662,7 +658,7 @@ impl Calendar {
}
/// 15.8.2.7 `Temporal.Calendar.prototype.eraYear ( temporalDateLike )`
fn era_year(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn era_year(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -710,7 +706,7 @@ impl Calendar {
}
/// 15.8.2.8 `Temporal.Calendar.prototype.year ( temporalDateLike )`
fn year(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn year(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -756,7 +752,7 @@ impl Calendar {
}
/// 15.8.2.9 `Temporal.Calendar.prototype.month ( temporalDateLike )`
fn month(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn month(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -811,11 +807,7 @@ impl Calendar {
}
/// 15.8.2.10 `Temporal.Calendar.prototype.monthCode ( temporalDateLike )`
fn month_code(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn month_code(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -867,7 +859,7 @@ impl Calendar {
}
/// 15.8.2.11 `Temporal.Calendar.prototype.day ( temporalDateLike )`
fn day(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn day(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -913,11 +905,7 @@ impl Calendar {
}
/// 15.8.2.12 `Temporal.Calendar.prototype.dayOfWeek ( dateOrDateTime )`
fn day_of_week(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn day_of_week(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -943,11 +931,7 @@ impl Calendar {
}
/// 15.8.2.13 `Temporal.Calendar.prototype.dayOfYear ( temporalDateLike )`
fn day_of_year(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn day_of_year(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -972,11 +956,7 @@ impl Calendar {
}
/// 15.8.2.14 `Temporal.Calendar.prototype.weekOfYear ( temporalDateLike )`
fn week_of_year(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn week_of_year(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -1000,11 +980,7 @@ impl Calendar {
}
/// 15.8.2.15 `Temporal.Calendar.prototype.yearOfWeek ( temporalDateLike )`
fn year_of_week(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn year_of_week(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -1028,11 +1004,7 @@ impl Calendar {
}
/// 15.8.2.16 `Temporal.Calendar.prototype.daysInWeek ( temporalDateLike )`
fn days_in_week(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn days_in_week(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -1056,11 +1028,7 @@ impl Calendar {
}
/// 15.8.2.17 `Temporal.Calendar.prototype.daysInMonth ( temporalDateLike )`
fn days_in_month(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn days_in_month(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -1108,11 +1076,7 @@ impl Calendar {
}
/// 15.8.2.18 `Temporal.Calendar.prototype.daysInYear ( temporalDateLike )`
fn days_in_year(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn days_in_year(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -1163,7 +1127,7 @@ impl Calendar {
fn months_in_year(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
@ -1212,11 +1176,7 @@ impl Calendar {
}
/// 15.8.2.20 `Temporal.Calendar.prototype.inLeapYear ( temporalDateLike )`
fn in_leap_year(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn in_leap_year(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value of Calendar must be an object.")
})?;
@ -1264,7 +1224,7 @@ impl Calendar {
}
/// 15.8.2.21 `Temporal.Calendar.prototype.fields ( fields )`
fn fields(this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResult<JsValue> {
fn fields(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -1349,11 +1309,7 @@ impl Calendar {
}
/// 15.8.2.22 `Temporal.Calendar.prototype.mergeFields ( fields, additionalFields )`
fn merge_fields(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn merge_fields(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let calendar be the this value.
// 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -1455,7 +1411,7 @@ impl Calendar {
pub(crate) fn create_temporal_calendar(
identifier: &JsString,
new_target: Option<JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Assert: IsBuiltinCalendar(identifier) is true.
assert!(is_builtin_calendar(identifier));
@ -1489,7 +1445,7 @@ pub(crate) fn create_temporal_calendar(
#[allow(unused)]
pub(crate) fn get_temporal_calendar_slot_value_with_default(
item: &JsObject,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. If item has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
// a. Return item.[[Calendar]].
@ -1627,7 +1583,7 @@ fn call_method_on_abstract_calendar(
calendar: &JsValue,
method: &JsString,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// If Calendar is a string
let this_calendar = match calendar {
@ -1651,7 +1607,7 @@ fn call_method_on_abstract_calendar(
pub(crate) fn calendar_fields(
calendar: &JsValue,
field_names: Vec<JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Vec<JsValue>> {
let field_names = Array::create_array_from_list(field_names, context);
// 1. If calendar is a String, then
@ -1680,7 +1636,7 @@ pub(crate) fn calendar_merge_fields(
calendar: &JsValue,
fields: &TemporalFields,
additional_fields: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -1712,7 +1668,7 @@ pub(crate) fn calendar_date_add(
date: &PlainDate,
duration: &DurationRecord,
options: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<PlainDate> {
// NOTE: The specification never calls CalendarDateAdd without an options argument provided.
// 1. If options is not present, set options to undefined.
@ -1755,7 +1711,7 @@ pub(crate) fn calendar_date_until(
one: &PlainDate,
two: &PlainDate,
options: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<DurationRecord> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -1798,7 +1754,7 @@ pub(crate) fn calendar_date_until(
pub(crate) fn calendar_year(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -1834,7 +1790,7 @@ pub(crate) fn calendar_year(
pub(crate) fn calendar_month(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -1877,7 +1833,7 @@ pub(crate) fn calendar_month(
pub(crate) fn calendar_month_code(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsString> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -1905,7 +1861,7 @@ pub(crate) fn calendar_month_code(
pub(crate) fn calendar_day(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -1948,7 +1904,7 @@ pub(crate) fn calendar_day(
pub(crate) fn calendar_day_of_week(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -2008,7 +1964,7 @@ pub(crate) fn calendar_day_of_week(
pub(crate) fn calendar_day_of_year(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -2051,7 +2007,7 @@ pub(crate) fn calendar_day_of_year(
pub(crate) fn calendar_week_of_year(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -2094,7 +2050,7 @@ pub(crate) fn calendar_week_of_year(
pub(crate) fn calendar_year_of_week(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -2130,7 +2086,7 @@ pub(crate) fn calendar_year_of_week(
pub(crate) fn calendar_days_in_week(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -2173,7 +2129,7 @@ pub(crate) fn calendar_days_in_week(
pub(crate) fn calendar_days_in_month(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -2216,7 +2172,7 @@ pub(crate) fn calendar_days_in_month(
pub(crate) fn calendar_days_in_year(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -2259,7 +2215,7 @@ pub(crate) fn calendar_days_in_year(
pub(crate) fn calendar_months_in_year(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<f64> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).
@ -2302,7 +2258,7 @@ pub(crate) fn calendar_months_in_year(
pub(crate) fn calendar_in_lear_year(
calendar: &JsValue,
datelike: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<bool> {
// 1. If calendar is a String, then
// a. Set calendar to ! CreateTemporalCalendar(calendar).

60
boa_engine/src/builtins/temporal/duration/mod.rs

@ -171,7 +171,7 @@ impl BuiltInConstructor for Duration {
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() {
@ -288,57 +288,57 @@ impl Duration {
}
/// 7.3.3 get Temporal.Duration.prototype.years
fn get_years(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_years(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Self::get_internal_field(this, &DateTimeValues::Year)
}
// 7.3.4 get Temporal.Duration.prototype.months
fn get_months(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_months(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Self::get_internal_field(this, &DateTimeValues::Month)
}
/// 7.3.5 get Temporal.Duration.prototype.weeks
fn get_weeks(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_weeks(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Self::get_internal_field(this, &DateTimeValues::Week)
}
/// 7.3.6 get Temporal.Duration.prototype.days
fn get_days(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_days(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Self::get_internal_field(this, &DateTimeValues::Day)
}
/// 7.3.7 get Temporal.Duration.prototype.hours
fn get_hours(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_hours(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Self::get_internal_field(this, &DateTimeValues::Hour)
}
/// 7.3.8 get Temporal.Duration.prototype.minutes
fn get_minutes(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_minutes(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Self::get_internal_field(this, &DateTimeValues::Minute)
}
/// 7.3.9 get Temporal.Duration.prototype.seconds
fn get_seconds(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_seconds(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Self::get_internal_field(this, &DateTimeValues::Second)
}
/// 7.3.10 get Temporal.Duration.prototype.milliseconds
fn get_milliseconds(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_milliseconds(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Self::get_internal_field(this, &DateTimeValues::Millisecond)
}
/// 7.3.11 get Temporal.Duration.prototype.microseconds
fn get_microseconds(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_microseconds(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Self::get_internal_field(this, &DateTimeValues::Microsecond)
}
/// 7.3.12 get Temporal.Duration.prototype.nanoseconds
fn get_nanoseconds(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_nanoseconds(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Self::get_internal_field(this, &DateTimeValues::Nanosecond)
}
/// 7.3.13 get Temporal.Duration.prototype.sign
fn get_sign(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_sign(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
// 1. Let duration be the this value.
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -355,7 +355,7 @@ impl Duration {
}
/// 7.3.14 get Temporal.Duration.prototype.blank
fn get_blank(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_blank(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
// 1. Let duration be the this value.
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
@ -386,7 +386,7 @@ impl Duration {
pub(crate) fn with(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let duration be the this value.
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
@ -518,7 +518,7 @@ impl Duration {
}
/// 7.3.16 `Temporal.Duration.prototype.negated ( )`
pub(crate) fn negated(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
pub(crate) fn negated(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
// 1. Let duration be the this value.
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
// 3. Return ! CreateNegatedTemporalDuration(duration).
@ -529,11 +529,7 @@ impl Duration {
}
/// 7.3.17 `Temporal.Duration.prototype.abs ( )`
pub(crate) fn abs(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn abs(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Let duration be the this value.
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
// 3. Return ! CreateTemporalDuration(abs(duration.[[Years]]), abs(duration.[[Months]]),
@ -552,14 +548,14 @@ impl Duration {
}
/// 7.3.18 `Temporal.Duration.prototype.add ( other [ , options ] )`
pub(crate) fn add(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
pub(crate) fn add(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::range()
.with_message("not yet implemented.")
.into())
}
/// 7.3.19 `Temporal.Duration.prototype.subtract ( other [ , options ] )`
pub(crate) fn subtract(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
pub(crate) fn subtract(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::range()
.with_message("not yet implemented.")
.into())
@ -570,7 +566,7 @@ impl Duration {
pub(crate) fn round(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let duration be the this value.
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
@ -809,7 +805,7 @@ impl Duration {
pub(crate) fn total(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let duration be the this value.
// 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
@ -874,22 +870,14 @@ impl Duration {
}
/// 7.3.22 `Temporal.Duration.prototype.toString ( [ options ] )`
pub(crate) fn to_string(
_this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn to_string(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::range()
.with_message("not yet implemented.")
.into())
}
/// 7.3.23 `Temporal.Duration.prototype.toJSON ( )`
pub(crate) fn to_json(
_this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn to_json(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::range()
.with_message("not yet implemented.")
.into())
@ -933,7 +921,7 @@ pub(crate) fn to_temporal_duration_record(
pub(crate) fn create_temporal_duration(
record: DurationRecord,
new_target: Option<&JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 1. If ! IsValidDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) is false, throw a RangeError exception.
if !record.is_valid_duration() {
@ -993,7 +981,7 @@ fn move_relative_date(
calendar: &JsValue,
relative_to: &PlainDate,
duration: &DurationRecord,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<(PlainDate, f64)> {
let new_date = plain_date::add_date(
calendar,

12
boa_engine/src/builtins/temporal/duration/record.rs

@ -260,7 +260,7 @@ impl DurationRecord {
/// Takes an unknown `JsObject` and attempts to create a partial duration
pub(crate) fn from_partial_js_object(
duration_like: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Self> {
// 1. If Type(temporalDurationLike) is not Object, then
let JsValue::Object(unknown_object) = duration_like else {
@ -588,7 +588,7 @@ impl DurationRecord {
// Trace current callers and check whether the value
// can be fed a native `DurationRecord` instead.
/// Creates a `Duration` object from the current `DurationRecord`.
pub(crate) fn as_object(&self, context: &mut Context<'_>) -> JsResult<JsObject> {
pub(crate) fn as_object(&self, context: &mut Context) -> JsResult<JsObject> {
super::create_temporal_duration(*self, None, context)
}
@ -905,7 +905,7 @@ impl DurationRecord {
&self,
largest_unit: TemporalUnit,
plain_relative_to: Option<&PlainDate>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<DateDuration> {
// 1. Let allZero be false.
// 2. If years = 0, and months = 0, and weeks = 0, and days = 0, set allZero to true.
@ -1152,7 +1152,7 @@ impl DurationRecord {
&mut self,
largest_unit: TemporalUnit,
relative_to: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<()> {
// 1. Let allZero be false.
// 2. If years = 0, and months = 0, and weeks = 0, and days = 0, set allZero to true.
@ -1416,7 +1416,7 @@ impl DurationRecord {
Option<&ZonedDateTime>,
Option<&PlainDateTime>,
),
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<(Self, f64)> {
let mut result = DurationRecord::new(unbalance_date_duration, self.time());
@ -1909,7 +1909,7 @@ impl DurationRecord {
unit: TemporalUnit,
rounding_mode: RoundingMode,
relative_to: Option<&JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<()> {
// 1. If Type(relativeTo) is not Object; or relativeTo does not have an [[InitializedTemporalZonedDateTime]]
// internal slot; or unit is one of "year", "month", "week", or "day"; or unit is "nanosecond" and increment is 1, then

32
boa_engine/src/builtins/temporal/fields.rs

@ -116,7 +116,7 @@ impl TemporalFields {
&mut self,
field: &JsString,
value: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<()> {
match field.to_std_string_escaped().as_str() {
"year" => self.set_year(value, context)?,
@ -140,7 +140,7 @@ impl TemporalFields {
}
#[inline]
fn set_year(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_year(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let y = super::to_integer_with_truncation(value, context)?;
self.year = Some(y);
self.bit_map.set(FieldMap::YEAR, true);
@ -148,7 +148,7 @@ impl TemporalFields {
}
#[inline]
fn set_month(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_month(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let mo = super::to_positive_integer_with_trunc(value, context)?;
self.year = Some(mo);
self.bit_map.set(FieldMap::MONTH, true);
@ -156,7 +156,7 @@ impl TemporalFields {
}
#[inline]
fn set_month_code(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_month_code(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let mc = value.to_primitive(context, PreferredType::String)?;
if let Some(string) = mc.as_string() {
self.month_code = Some(string.clone());
@ -172,7 +172,7 @@ impl TemporalFields {
}
#[inline]
fn set_day(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_day(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let d = super::to_positive_integer_with_trunc(value, context)?;
self.day = Some(d);
self.bit_map.set(FieldMap::DAY, true);
@ -180,7 +180,7 @@ impl TemporalFields {
}
#[inline]
fn set_hour(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_hour(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let h = super::to_integer_with_truncation(value, context)?;
self.hour = h;
self.bit_map.set(FieldMap::HOUR, true);
@ -188,7 +188,7 @@ impl TemporalFields {
}
#[inline]
fn set_minute(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_minute(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let m = super::to_integer_with_truncation(value, context)?;
self.minute = m;
self.bit_map.set(FieldMap::MINUTE, true);
@ -196,7 +196,7 @@ impl TemporalFields {
}
#[inline]
fn set_second(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_second(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let sec = super::to_integer_with_truncation(value, context)?;
self.second = sec;
self.bit_map.set(FieldMap::SECOND, true);
@ -204,7 +204,7 @@ impl TemporalFields {
}
#[inline]
fn set_milli(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_milli(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let milli = super::to_integer_with_truncation(value, context)?;
self.millisecond = milli;
self.bit_map.set(FieldMap::MILLISECOND, true);
@ -212,7 +212,7 @@ impl TemporalFields {
}
#[inline]
fn set_micro(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_micro(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let micro = super::to_integer_with_truncation(value, context)?;
self.microsecond = micro;
self.bit_map.set(FieldMap::MICROSECOND, true);
@ -220,7 +220,7 @@ impl TemporalFields {
}
#[inline]
fn set_nano(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_nano(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let nano = super::to_integer_with_truncation(value, context)?;
self.nanosecond = nano;
self.bit_map.set(FieldMap::NANOSECOND, true);
@ -228,7 +228,7 @@ impl TemporalFields {
}
#[inline]
fn set_offset(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_offset(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let mc = value.to_primitive(context, PreferredType::String)?;
if let Some(string) = mc.as_string() {
self.offset = Some(string.clone());
@ -243,7 +243,7 @@ impl TemporalFields {
}
#[inline]
fn set_era(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_era(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let mc = value.to_primitive(context, PreferredType::String)?;
if let Some(string) = mc.as_string() {
self.era = Some(string.clone());
@ -258,7 +258,7 @@ impl TemporalFields {
}
#[inline]
fn set_era_year(&mut self, value: &JsValue, context: &mut Context<'_>) -> JsResult<()> {
fn set_era_year(&mut self, value: &JsValue, context: &mut Context) -> JsResult<()> {
let ey = super::to_integer_with_truncation(value, context)?;
self.era_year = Some(ey);
self.bit_map.set(FieldMap::ERA_YEAR, true);
@ -286,7 +286,7 @@ impl TemporalFields {
extended_fields: Option<Vec<(JsString, bool)>>,
partial: bool,
dup_behaviour: Option<JsString>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Self> {
// 1. If duplicateBehaviour is not present, set duplicateBehaviour to throw.
let dup_option = dup_behaviour.unwrap_or_else(|| js_string!("throw"));
@ -392,7 +392,7 @@ impl TemporalFields {
}
/// Convert a `TemporalFields` struct into a `JsObject`.
pub(crate) fn as_object(&self, context: &mut Context<'_>) -> JsResult<JsObject> {
pub(crate) fn as_object(&self, context: &mut Context) -> JsResult<JsObject> {
let obj = JsObject::with_null_proto();
for bit in self.bit_map.iter() {

38
boa_engine/src/builtins/temporal/instant/mod.rs

@ -117,7 +117,7 @@ impl BuiltInConstructor for Instant {
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() {
@ -148,7 +148,7 @@ impl Instant {
pub(crate) fn get_epoc_seconds(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
@ -170,7 +170,7 @@ impl Instant {
pub(crate) fn get_epoc_milliseconds(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
@ -192,7 +192,7 @@ impl Instant {
pub(crate) fn get_epoc_microseconds(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
@ -217,7 +217,7 @@ impl Instant {
pub(crate) fn get_epoc_nanoseconds(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
@ -237,7 +237,7 @@ impl Instant {
pub(crate) fn add(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
@ -257,7 +257,7 @@ impl Instant {
pub(crate) fn subtract(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
@ -277,7 +277,7 @@ impl Instant {
pub(crate) fn until(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
@ -298,7 +298,7 @@ impl Instant {
pub(crate) fn since(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
@ -319,7 +319,7 @@ impl Instant {
pub(crate) fn round(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
@ -418,11 +418,7 @@ impl Instant {
}
/// 8.3.12 `Temporal.Instant.prototype.equals ( other )`
pub(crate) fn equals(
this: &JsValue,
args: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(crate) fn equals(this: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
// 1. Let instant be the this value.
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
// 4. If instant.[[Nanoseconds]] ≠ other.[[Nanoseconds]], return false.
@ -448,7 +444,7 @@ impl Instant {
pub(crate) fn to_zoned_date_time(
_: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
// TODO: Complete
Err(JsNativeError::error()
@ -460,7 +456,7 @@ impl Instant {
pub(crate) fn to_zoned_date_time_iso(
_: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
// TODO Complete
Err(JsNativeError::error()
@ -491,7 +487,7 @@ fn is_valid_epoch_nanos(epoch_nanos: &JsBigInt) -> bool {
fn create_temporal_instant(
epoch_nanos: JsBigInt,
new_target: Option<JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Assert: ! IsValidEpochNanoseconds(epochNanoseconds) is true.
assert!(is_valid_epoch_nanos(&epoch_nanos));
@ -575,7 +571,7 @@ fn diff_instant(
smallest_unit: TemporalUnit,
largest_unit: TemporalUnit,
rounding_mode: RoundingMode,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<DurationRecord> {
// 1. Let difference be ℝ(ns2) - ℝ(ns1).
let difference = JsBigInt::sub(ns1, ns2);
@ -692,7 +688,7 @@ fn diff_temporal_instant(
instant: &Instant,
other: &JsValue,
options: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
let sign = if op { 1_f64 } else { -1_f64 };
@ -749,7 +745,7 @@ fn add_or_subtract_duration_from_instant(
op: bool,
instant: &Instant,
temporal_duration_like: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. If operation is subtract, let sign be -1. Otherwise, let sign be 1.
let sign = if op { 1 } else { -1 };

19
boa_engine/src/builtins/temporal/mod.rs

@ -195,7 +195,7 @@ fn to_zero_padded_decimal_string(n: u64, min_length: usize) -> String {
pub(crate) fn iterator_to_list_of_types(
iterator: &mut IteratorRecord,
element_types: &[Type],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Vec<JsValue>> {
// 1. Let values be a new empty List.
let mut values = Vec::new();
@ -293,7 +293,7 @@ pub(crate) fn validate_temporal_rounding_increment(
/// 13.21 `ToRelativeTemporalObject ( options )`
pub(crate) fn to_relative_temporal_object(
_options: &JsObject,
_context: &mut Context<'_>,
_context: &mut Context,
) -> JsResult<(Option<PlainDate>, Option<ZonedDateTime>)> {
Err(JsNativeError::range()
.with_message("not yet implemented.")
@ -435,7 +435,7 @@ pub(crate) fn round_to_increment_as_if_positive(
#[inline]
pub(crate) fn to_positive_integer_with_trunc(
value: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<i32> {
// 1. Let integer be ? ToIntegerWithTruncation(argument).
let int = to_integer_with_truncation(value, context)?;
@ -451,10 +451,7 @@ pub(crate) fn to_positive_integer_with_trunc(
/// 13.44 `ToIntegerWithTruncation ( argument )`
#[inline]
pub(crate) fn to_integer_with_truncation(
value: &JsValue,
context: &mut Context<'_>,
) -> JsResult<i32> {
pub(crate) fn to_integer_with_truncation(value: &JsValue, context: &mut Context) -> JsResult<i32> {
// 1. Let number be ? ToNumber(argument).
let number = value.to_number(context)?;
// 2. If number is NaN, +∞𝔽 or -∞𝔽, throw a RangeError exception.
@ -469,7 +466,7 @@ pub(crate) fn to_integer_with_truncation(
/// Abstract operation 13.45 `ToIntegerIfIntegral( argument )`
#[inline]
pub(crate) fn to_integer_if_integral(arg: &JsValue, context: &mut Context<'_>) -> JsResult<i32> {
pub(crate) fn to_integer_if_integral(arg: &JsValue, context: &mut Context) -> JsResult<i32> {
// 1. Let number be ? ToNumber(argument).
// 2. If IsIntegralNumber(number) is false, throw a RangeError exception.
// 3. Return ℝ(number).
@ -495,7 +492,7 @@ pub(crate) fn get_diff_settings(
disallowed_units: &[TemporalUnit],
fallback_smallest_unit: TemporalUnit,
smallest_largest_default_unit: TemporalUnit,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<(TemporalUnit, TemporalUnit, RoundingMode, f64)> {
// 1. NOTE: The following steps read options and perform independent validation in alphabetical order (ToTemporalRoundingIncrement reads "roundingIncrement" and ToTemporalRoundingMode reads "roundingMode").
// 2. Let largestUnit be ? GetTemporalUnit(options, "largestUnit", unitGroup, "auto").
@ -574,7 +571,7 @@ pub(crate) fn copy_data_properties(
source: &JsValue,
excluded_keys: &Vec<JsString>,
excluded_values: Option<&Vec<JsValue>>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<()> {
// 1. If source is undefined or null, return unused.
if source.is_null_or_undefined() {
@ -644,7 +641,7 @@ fn snapshot_own_properties(
source: &JsObject,
excluded_keys: Option<Vec<JsString>>,
excluded_values: Option<Vec<JsValue>>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 1. Let copy be OrdinaryObjectCreate(proto).
let copy = JsObject::with_null_proto();

22
boa_engine/src/builtins/temporal/now.rs

@ -65,59 +65,55 @@ impl Now {
///
/// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.now.timezone
#[allow(clippy::unnecessary_wraps)]
fn time_zone_id(
_: &JsValue,
_args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
fn time_zone_id(_: &JsValue, _args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
// 1. Return ! SystemTimeZone().
Ok(system_time_zone(context).expect("retrieving the system timezone must not fail"))
}
/// `Temporal.Now.instant()`
fn instant(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn instant(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
/// `Temporal.Now.plainDateTime()`
fn plain_date_time(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn plain_date_time(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
/// `Temporal.Now.plainDateTimeISO`
fn plain_date_time_iso(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn plain_date_time_iso(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
/// `Temporal.Now.zonedDateTime`
fn zoned_date_time(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn zoned_date_time(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
/// `Temporal.Now.zonedDateTimeISO`
fn zoned_date_time_iso(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn zoned_date_time_iso(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
/// `Temporal.Now.plainDate()`
fn plain_date(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn plain_date(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
/// `Temporal.Now.plainDateISO`
fn plain_date_iso(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn plain_date_iso(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
@ -180,7 +176,7 @@ fn system_zoned_date_time() {
///
/// [spec]: https://tc39.es/proposal-temporal/#sec-temporal-systemtimezone
#[allow(unused)]
fn system_time_zone(context: &mut Context<'_>) -> JsResult<JsValue> {
fn system_time_zone(context: &mut Context) -> JsResult<JsValue> {
// 1. Let identifier be ! DefaultTimeZone().
let identifier = default_time_zone(context);
// 2. Return ! CreateTemporalTimeZone(identifier).

4
boa_engine/src/builtins/temporal/options.rs

@ -19,7 +19,7 @@ use std::{fmt, str::FromStr};
#[inline]
pub(crate) fn get_temporal_rounding_increment(
options: &JsObject,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<u32> {
// 1. Let increment be ? GetOption(normalizedOptions, "roundingIncrement", "number", undefined, 1𝔽).
let value = options.get(js_string!("roundingIncrement"), context)?;
@ -58,7 +58,7 @@ pub(crate) fn get_temporal_unit(
key: &[u16],
unit_group: TemporalUnitGroup,
extra_values: Option<Vec<TemporalUnit>>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<Option<TemporalUnit>> {
let extra = extra_values.unwrap_or_default();
let mut unit_values = unit_group.group();

66
boa_engine/src/builtins/temporal/plain_date/mod.rs

@ -208,7 +208,7 @@ impl BuiltInConstructor for PlainDate {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
if new_target.is_undefined() {
return Err(JsNativeError::typ()
@ -230,85 +230,85 @@ impl BuiltInConstructor for PlainDate {
// -- `PlainDate` getter methods --
impl PlainDate {
fn get_calendar_id(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_calendar_id(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn get_year(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_month(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_month(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_month_code(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_month_code(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_day(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_day(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_day_of_week(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_day_of_week(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_day_of_year(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_day_of_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_week_of_year(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_week_of_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_year_of_week(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_year_of_week(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_days_in_week(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_days_in_week(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_days_in_month(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_days_in_month(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_days_in_year(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_days_in_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_months_in_year(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_months_in_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_in_leap_year(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_in_leap_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
@ -318,71 +318,67 @@ impl PlainDate {
// ==== `PlainDate.prototype` method implementation ====
impl PlainDate {
fn to_plain_year_month(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
fn to_plain_year_month(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn to_plain_month_day(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn to_plain_month_day(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_iso_fields(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_iso_fields(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_calendar(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_calendar(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn add(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn add(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn subtract(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn subtract(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn with(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn with(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn with_calendar(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn with_calendar(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn until(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn until(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn since(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn since(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn equals(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn equals(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
@ -393,7 +389,7 @@ impl PlainDate {
impl PlainDate {
/// Utitily function for translating a `Temporal.PlainDate` into a `JsObject`.
pub(crate) fn as_object(&self, context: &mut Context<'_>) -> JsResult<JsObject> {
pub(crate) fn as_object(&self, context: &mut Context) -> JsResult<JsObject> {
create_temporal_date(self.inner, self.calendar.clone(), None, context)
}
}
@ -406,7 +402,7 @@ pub(crate) fn create_temporal_date(
iso_date: IsoDateRecord,
calendar: JsValue,
new_target: Option<&JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 1. If IsValidISODate(isoYear, isoMonth, isoDay) is false, throw a RangeError exception.
if !iso_date.is_valid() {
@ -462,7 +458,7 @@ pub(crate) fn create_temporal_date(
pub(crate) fn to_temporal_date(
item: &JsValue,
options: Option<JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<PlainDate> {
// 1. If options is not present, set options to undefined.
let options = options.unwrap_or(JsValue::undefined());
@ -577,7 +573,7 @@ pub(crate) fn difference_date(
one: &PlainDate,
two: &PlainDate,
largest_unit: TemporalUnit,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<DurationRecord> {
// 1. Assert: one.[[Calendar]] and two.[[Calendar]] have been determined to be equivalent as with CalendarEquals.
// 2. Assert: options is an ordinary Object.
@ -633,7 +629,7 @@ pub(crate) fn add_date(
plain_date: &PlainDate,
duration: &DurationRecord,
options: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<PlainDate> {
// 1. If options is not present, set options to undefined.
// 2. If duration.[[Years]] ≠ 0, or duration.[[Months]] ≠ 0, or duration.[[Weeks]] ≠ 0, then

28
boa_engine/src/builtins/temporal/plain_date_time/mod.rs

@ -53,7 +53,7 @@ impl BuiltInConstructor for PlainDateTime {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
Err(JsNativeError::range()
.with_message("Not yet implemented.")
@ -64,79 +64,79 @@ impl BuiltInConstructor for PlainDateTime {
// ==== `PlainDateTime` Accessor Properties ====
impl PlainDateTime {
fn calendar_id(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn calendar_id(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn year(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn month(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn month(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn month_code(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn month_code(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn day(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn day(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn hour(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn hour(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn minute(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn minute(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn second(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn second(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn millisecond(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn millisecond(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn microsecond(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn microsecond(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn nanosecond(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn nanosecond(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn era(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn era(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())
}
fn era_year(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn era_year(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("calendars not yet implemented.")
.into())

4
boa_engine/src/builtins/temporal/plain_month_day/mod.rs

@ -51,7 +51,7 @@ impl BuiltInConstructor for PlainMonthDay {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
Err(JsNativeError::range()
.with_message("Not yet implemented.")
@ -65,7 +65,7 @@ pub(crate) fn create_temporal_month_day(
iso: IsoDateRecord,
calendar: JsValue,
new_target: Option<&JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. If IsValidISODate(referenceISOYear, isoMonth, isoDay) is false, throw a RangeError exception.
if iso.is_valid() {

2
boa_engine/src/builtins/temporal/plain_time/mod.rs

@ -53,7 +53,7 @@ impl BuiltInConstructor for PlainTime {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
Err(JsNativeError::range()
.with_message("Not yet implemented.")

36
boa_engine/src/builtins/temporal/plain_year_month/mod.rs

@ -128,7 +128,7 @@ impl BuiltInConstructor for PlainYearMonth {
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() {
@ -170,53 +170,49 @@ impl BuiltInConstructor for PlainYearMonth {
// ==== `PlainYearMonth` Accessor Implementations ====
impl PlainYearMonth {
fn get_calendar_id(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_calendar_id(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_year(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_year(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_month(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_month(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_month_code(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_month_code(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_days_in_year(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_days_in_year(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_days_in_month(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_days_in_month(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_months_in_year(
_this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
fn get_months_in_year(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
fn get_in_leap_year(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn get_in_leap_year(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
@ -226,37 +222,37 @@ impl PlainYearMonth {
// ==== `PlainYearMonth` Method Implementations ====
impl PlainYearMonth {
fn with(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn with(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("not yet implemented.")
.into())
}
fn add(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn add(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("not yet implemented.")
.into())
}
fn subtract(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn subtract(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("not yet implemented.")
.into())
}
fn until(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn until(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("not yet implemented.")
.into())
}
fn since(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn since(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("not yet implemented.")
.into())
}
fn equals(_this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn equals(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("not yet implemented.")
.into())
@ -273,7 +269,7 @@ pub(crate) fn create_temporal_year_month(
year_month_record: IsoDateRecord,
calendar: JsValue,
new_target: Option<&JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. If IsValidISODate(isoYear, isoMonth, referenceISODay) is false, throw a RangeError exception.
if !year_month_record.is_valid() {

30
boa_engine/src/builtins/temporal/time_zone/mod.rs

@ -97,7 +97,7 @@ impl BuiltInConstructor for TimeZone {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. If NewTarget is undefined, then
// 1a. Throw a TypeError exception.
@ -130,7 +130,7 @@ impl BuiltInConstructor for TimeZone {
impl TimeZone {
// NOTE: id, toJSON, toString currently share the exact same implementation -> Consolidate into one function and define multiple accesors?
pub(crate) fn get_id(this: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
pub(crate) fn get_id(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
let o = this.as_object().map(JsObject::borrow).ok_or_else(|| {
JsNativeError::typ().with_message("this value must be a Temporal.TimeZone")
})?;
@ -143,7 +143,7 @@ impl TimeZone {
pub(crate) fn get_offset_nanoseconds_for(
this: &JsValue,
args: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
// 1. Let timeZone be the this value.
// 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimeZone]]).
@ -172,7 +172,7 @@ impl TimeZone {
pub(crate) fn get_offset_string_for(
this: &JsValue,
args: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
// 1. Let timeZone be the this value.
// 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimeZone]]).
@ -200,7 +200,7 @@ impl TimeZone {
pub(crate) fn get_plain_date_time_for(
_: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
@ -210,7 +210,7 @@ impl TimeZone {
pub(crate) fn get_instant_for(
_: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
@ -220,7 +220,7 @@ impl TimeZone {
pub(crate) fn get_possible_instants_for(
_: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
@ -230,7 +230,7 @@ impl TimeZone {
pub(crate) fn get_next_transition(
_: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
@ -240,18 +240,14 @@ impl TimeZone {
pub(crate) fn get_previous_transition(
_: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
_: &mut Context,
) -> JsResult<JsValue> {
Err(JsNativeError::error()
.with_message("not yet implemented.")
.into())
}
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 timeZone be the this value.
// 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimeZone]]).
let o = this.as_object().ok_or_else(|| {
@ -283,7 +279,7 @@ impl TimeZone {
///
/// [spec]: https://tc39.es/proposal-temporal/#sec-defaulttimezone
#[allow(unused)]
pub(super) fn default_time_zone(context: &mut Context<'_>) -> String {
pub(super) fn default_time_zone(context: &mut Context) -> String {
// The minimum implementation of DefaultTimeZone for ECMAScript implementations that do not
// include the ECMA-402 API, supporting only the "UTC" time zone, performs the following steps
// when called:
@ -304,7 +300,7 @@ pub(super) fn default_time_zone(context: &mut Context<'_>) -> String {
pub(super) fn create_temporal_time_zone(
identifier: String,
new_target: Option<JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. If newTarget is not present, set newTarget to %Temporal.TimeZone%.
let new_target = new_target.unwrap_or_else(|| {
@ -367,7 +363,7 @@ pub(super) fn create_temporal_time_zone(
///
/// [spec]: https://tc39.es/ecma262/#sec-parsetimezoneoffsetstring
#[allow(clippy::unnecessary_wraps, unused)]
fn parse_timezone_offset_string(offset_string: &str, context: &mut Context<'_>) -> JsResult<i64> {
fn parse_timezone_offset_string(offset_string: &str, context: &mut Context) -> JsResult<i64> {
use boa_parser::temporal::{IsoCursor, TemporalTimeZoneString};
// 1. Let parseResult be ParseText(StringToCodePoints(offsetString), UTCOffset).

2
boa_engine/src/builtins/temporal/zoned_date_time/mod.rs

@ -48,7 +48,7 @@ impl BuiltInConstructor for ZonedDateTime {
fn constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// TODO: Implement ZonedDateTime.
Err(JsNativeError::error()

130
boa_engine/src/builtins/typed_array/builtin.rs

@ -176,7 +176,7 @@ impl BuiltInConstructor for BuiltinTypedArray {
/// - [ECMAScript reference][spec]
///
/// [spec]: https://tc39.es/ecma262/#sec-%typedarray%
fn constructor(_: &JsValue, _: &[JsValue], _: &mut Context<'_>) -> JsResult<JsValue> {
fn constructor(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
// 1. Throw a TypeError exception.
Err(JsNativeError::typ()
.with_message("the TypedArray constructor should never be called directly")
@ -191,7 +191,7 @@ impl BuiltinTypedArray {
/// - [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() {
@ -301,7 +301,7 @@ impl BuiltinTypedArray {
fn from_kind_and_length(
kind: TypedArrayKind,
length: u64,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
let constructor =
kind.standard_constructor()(context.intrinsics().constructors()).constructor();
@ -315,7 +315,7 @@ impl BuiltinTypedArray {
/// - [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.
@ -352,11 +352,7 @@ impl BuiltinTypedArray {
///
/// [spec]: https://tc39.es/ecma262/#sec-get-%typedarray%-@@species
#[allow(clippy::unnecessary_wraps)]
pub(super) fn get_species(
this: &JsValue,
_: &[JsValue],
_: &mut Context<'_>,
) -> JsResult<JsValue> {
pub(super) fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
// 1. Return the this value.
Ok(this.clone())
}
@ -367,11 +363,7 @@ impl BuiltinTypedArray {
/// - [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(|| {
@ -423,7 +415,7 @@ impl BuiltinTypedArray {
/// - [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.
@ -446,11 +438,7 @@ impl BuiltinTypedArray {
/// - [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.
@ -479,11 +467,7 @@ impl BuiltinTypedArray {
/// - [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.
@ -512,11 +496,7 @@ impl BuiltinTypedArray {
/// - [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")
@ -658,7 +638,7 @@ impl BuiltinTypedArray {
/// - [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(|| {
@ -691,7 +671,7 @@ impl BuiltinTypedArray {
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).
@ -760,7 +740,7 @@ impl BuiltinTypedArray {
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).
@ -850,7 +830,7 @@ impl BuiltinTypedArray {
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).
@ -942,7 +922,7 @@ impl BuiltinTypedArray {
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).
@ -991,7 +971,7 @@ impl BuiltinTypedArray {
pub(crate) fn find_index(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1040,7 +1020,7 @@ impl BuiltinTypedArray {
pub(crate) fn find_last(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1087,7 +1067,7 @@ impl BuiltinTypedArray {
pub(crate) fn find_last_index(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Perform ? ValidateTypedArray(O).
@ -1134,7 +1114,7 @@ impl BuiltinTypedArray {
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).
@ -1195,7 +1175,7 @@ impl BuiltinTypedArray {
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).
@ -1276,7 +1256,7 @@ impl BuiltinTypedArray {
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).
@ -1366,7 +1346,7 @@ impl BuiltinTypedArray {
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).
@ -1428,11 +1408,7 @@ impl BuiltinTypedArray {
/// - [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(|| {
@ -1465,7 +1441,7 @@ impl BuiltinTypedArray {
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).
@ -1544,7 +1520,7 @@ impl BuiltinTypedArray {
/// - [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.
@ -1576,7 +1552,7 @@ impl BuiltinTypedArray {
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).
@ -1646,7 +1622,7 @@ impl BuiltinTypedArray {
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).
@ -1733,7 +1709,7 @@ impl BuiltinTypedArray {
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).
@ -1823,7 +1799,7 @@ impl BuiltinTypedArray {
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).
@ -1883,7 +1859,7 @@ impl BuiltinTypedArray {
pub(crate) fn to_reversed(
this: &JsValue,
_: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
// 2. Let iieoRecord be ? ValidateTypedArray(O, seq-cst).
@ -1937,7 +1913,7 @@ impl BuiltinTypedArray {
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]]).
@ -1998,7 +1974,7 @@ impl BuiltinTypedArray {
target: &JsObject,
target_offset: &U64OrPositiveInfinity,
source: &JsObject,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<()> {
let target_borrow = target.borrow();
let target_array = target_borrow
@ -2232,7 +2208,7 @@ impl BuiltinTypedArray {
target: &JsObject,
target_offset: &U64OrPositiveInfinity,
source: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<()> {
let target_length = {
let target_borrow = target.borrow();
@ -2304,7 +2280,7 @@ impl BuiltinTypedArray {
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).
@ -2477,7 +2453,7 @@ impl BuiltinTypedArray {
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).
@ -2545,7 +2521,7 @@ impl BuiltinTypedArray {
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) {
@ -2585,7 +2561,7 @@ impl BuiltinTypedArray {
// 5. NOTE: The following closure performs a numeric comparison rather than the string comparison used in 23.1.3.30.
// 6. Let SortCompare be a new Abstract Closure with parameters (x, y) that captures comparefn and performs the following steps when called:
let sort_compare =
|x: &JsValue, y: &JsValue, context: &mut Context<'_>| -> JsResult<cmp::Ordering> {
|x: &JsValue, y: &JsValue, context: &mut Context| -> JsResult<cmp::Ordering> {
// a. Return ? CompareTypedArrayElements(x, y, comparefn).
compare_typed_array_elements(x, y, compare_fn, context)
};
@ -2613,7 +2589,7 @@ impl BuiltinTypedArray {
pub(crate) fn to_sorted(
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) {
@ -2653,7 +2629,7 @@ impl BuiltinTypedArray {
// 6. NOTE: The following closure performs a numeric comparison rather than the string comparison used in 23.1.3.34.
// 7. Let SortCompare be a new Abstract Closure with parameters (x, y) that captures comparefn and performs the following steps when called:
let sort_compare =
|x: &JsValue, y: &JsValue, context: &mut Context<'_>| -> JsResult<cmp::Ordering> {
|x: &JsValue, y: &JsValue, context: &mut Context| -> JsResult<cmp::Ordering> {
// a. Return ? CompareTypedArrayElements(x, y, comparefn).
compare_typed_array_elements(x, y, compare_fn, context)
};
@ -2684,7 +2660,7 @@ impl BuiltinTypedArray {
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]]).
@ -2772,7 +2748,7 @@ impl BuiltinTypedArray {
fn to_locale_string(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let array be ? ToObject(this value).
// Note: ValidateTypedArray is applied to the this value prior to evaluating the algorithm.
@ -2856,7 +2832,7 @@ impl BuiltinTypedArray {
/// - [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(|| {
@ -2886,7 +2862,7 @@ impl BuiltinTypedArray {
pub(crate) fn with(
this: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let O be the this value.
let obj = this.as_object().ok_or_else(|| {
@ -2980,7 +2956,7 @@ impl BuiltinTypedArray {
///
/// [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.
@ -3007,7 +2983,7 @@ impl BuiltinTypedArray {
exemplar: &JsObject,
kind: 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 = kind.standard_constructor();
@ -3046,7 +3022,7 @@ impl BuiltinTypedArray {
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)?;
@ -3081,7 +3057,7 @@ impl BuiltinTypedArray {
/// <https://tc39.es/ecma262/#sec-allocatetypedarraybuffer>
fn allocate_buffer<T: TypedArray>(
length: u64,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<IntegerIndexed> {
// 1. Assert: O.[[ViewedArrayBuffer]] is undefined.
@ -3117,7 +3093,7 @@ impl BuiltinTypedArray {
pub(crate) fn initialize_from_list<T: TypedArray>(
proto: JsObject,
values: Vec<JsValue>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 1. Let len be the number of elements in values.
let len = values.len() as u64;
@ -3157,7 +3133,7 @@ impl BuiltinTypedArray {
pub(super) fn allocate<T: TypedArray>(
new_target: &JsValue,
length: u64,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
let proto = get_prototype_from_constructor(new_target, T::STANDARD_CONSTRUCTOR, context)?;
@ -3195,7 +3171,7 @@ impl BuiltinTypedArray {
pub(super) fn initialize_from_typed_array<T: TypedArray>(
proto: JsObject,
src_array: &JsObject,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
let src_array = src_array.borrow();
let src_array = src_array
@ -3355,7 +3331,7 @@ impl BuiltinTypedArray {
buffer: JsObject,
byte_offset: &JsValue,
length: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 1. Let elementSize be TypedArrayElementSize(O).
let element_size = T::ERASED.element_size();
@ -3457,7 +3433,7 @@ impl BuiltinTypedArray {
pub(super) fn initialize_from_array_like<T: TypedArray>(
proto: JsObject,
array_like: &JsObject,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsObject> {
// 1. Let len be ? LengthOfArrayLike(arrayLike).
let len = array_like.length_of_array_like(context)?;
@ -3501,7 +3477,7 @@ fn compare_typed_array_elements(
x: &JsValue,
y: &JsValue,
compare_fn: Option<&JsObject>,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<cmp::Ordering> {
// 1. Assert: x is a Number and y is a Number, or x is a BigInt and y is a BigInt.

4
boa_engine/src/builtins/typed_array/element/mod.rs

@ -194,7 +194,7 @@ pub(crate) trait Element:
type Atomic: Atomic;
/// Converts a `JsValue` into the native element `Self`.
fn from_js_value(value: &JsValue, context: &mut Context<'_>) -> JsResult<Self>;
fn from_js_value(value: &JsValue, context: &mut Context) -> JsResult<Self>;
/// Converts from the plain type of an atomic to `Self`.
fn from_plain(bytes: <Self::Atomic as Atomic>::Plain) -> Self;
@ -255,7 +255,7 @@ macro_rules! element {
impl Element for $element {
type Atomic = $atomic;
fn from_js_value(value: &JsValue, context: &mut Context<'_>) -> JsResult<Self> {
fn from_js_value(value: &JsValue, context: &mut Context) -> JsResult<Self> {
$from_js(value, context)
}

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

@ -108,7 +108,7 @@ impl<T: TypedArray> BuiltInConstructor for T {
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() {
@ -458,7 +458,7 @@ impl TypedArrayKind {
pub(crate) fn get_element(
self,
value: &JsValue,
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<TypedArrayElement> {
match self {
TypedArrayKind::Int8 => value.to_int8(context).map(TypedArrayElement::Int8),

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

@ -173,7 +173,7 @@ impl BuiltInObject for EncodeUriComponent {
pub(crate) fn decode_uri(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let encoded_uri = args.get_or_undefined(0);
@ -201,7 +201,7 @@ pub(crate) fn decode_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);
@ -233,7 +233,7 @@ pub(crate) fn decode_uri_component(
pub(crate) fn encode_uri(
_: &JsValue,
args: &[JsValue],
context: &mut Context<'_>,
context: &mut Context,
) -> JsResult<JsValue> {
let uri = args.get_or_undefined(0);
@ -262,7 +262,7 @@ pub(crate) fn encode_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);

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

@ -63,7 +63,7 @@ impl BuiltInConstructor for WeakRef {
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() {
@ -105,11 +105,7 @@ 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(|| {

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

@ -72,7 +72,7 @@ impl BuiltInConstructor for WeakMap {
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() {
@ -124,7 +124,7 @@ impl WeakMap {
pub(crate) fn delete(
this: &JsValue,
args: &[JsValue],
_context: &mut Context<'_>,
_context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let M be the this value.
// 2. Perform ? RequireInternalSlot(M, [[WeakMapData]]).
@ -164,7 +164,7 @@ impl WeakMap {
pub(crate) fn get(
this: &JsValue,
args: &[JsValue],
_context: &mut Context<'_>,
_context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let M be the this value.
// 2. Perform ? RequireInternalSlot(M, [[WeakMapData]]).
@ -201,7 +201,7 @@ impl WeakMap {
pub(crate) fn has(
this: &JsValue,
args: &[JsValue],
_context: &mut Context<'_>,
_context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let M be the this value.
// 2. Perform ? RequireInternalSlot(M, [[WeakMapData]]).
@ -238,7 +238,7 @@ impl WeakMap {
pub(crate) fn set(
this: &JsValue,
args: &[JsValue],
_context: &mut Context<'_>,
_context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let M be the this value.
// 2. Perform ? RequireInternalSlot(M, [[WeakMapData]]).

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

@ -68,7 +68,7 @@ impl BuiltInConstructor for WeakSet {
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() {
@ -136,7 +136,7 @@ impl WeakSet {
pub(crate) fn add(
this: &JsValue,
args: &[JsValue],
_context: &mut Context<'_>,
_context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let S be the this value.
// 2. Perform ? RequireInternalSlot(S, [[WeakSetData]]).
@ -188,7 +188,7 @@ impl WeakSet {
pub(crate) fn delete(
this: &JsValue,
args: &[JsValue],
_context: &mut Context<'_>,
_context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let S be the this value.
// 2. Perform ? RequireInternalSlot(S, [[WeakSetData]]).
@ -230,7 +230,7 @@ impl WeakSet {
pub(crate) fn has(
this: &JsValue,
args: &[JsValue],
_context: &mut Context<'_>,
_context: &mut Context,
) -> JsResult<JsValue> {
// 1. Let S be the this value.
// 2. Perform ? RequireInternalSlot(S, [[WeakSetData]]).

2
boa_engine/src/bytecompiler/class.rs

@ -17,7 +17,7 @@ enum StaticElement {
StaticField((Gc<CodeBlock>, Option<u32>)),
}
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

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

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

Loading…
Cancel
Save