From 42d8f20917672986d936d03740f537e375957196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 24 Aug 2021 08:15:48 +0200 Subject: [PATCH] Rename `boa::Result` to `JsResult` (#1493) * Rename `boa::Result` to `JsResult` * fix vm/mod.rs * rustfmt --- boa/examples/classes.rs | 8 +- boa/src/builtins/array/array_iterator.rs | 4 +- boa/src/builtins/array/mod.rs | 199 +++++++++++------- boa/src/builtins/bigint/mod.rs | 16 +- boa/src/builtins/boolean/mod.rs | 10 +- boa/src/builtins/console/mod.rs | 44 ++-- boa/src/builtins/date/mod.rs | 86 +++++--- boa/src/builtins/error/eval.rs | 4 +- boa/src/builtins/error/mod.rs | 6 +- boa/src/builtins/error/range.rs | 4 +- boa/src/builtins/error/reference.rs | 4 +- boa/src/builtins/error/syntax.rs | 4 +- boa/src/builtins/error/type.rs | 4 +- boa/src/builtins/error/uri.rs | 4 +- boa/src/builtins/function/mod.rs | 18 +- boa/src/builtins/iterable/mod.rs | 10 +- boa/src/builtins/json/mod.rs | 8 +- boa/src/builtins/map/map_iterator.rs | 8 +- boa/src/builtins/map/mod.rs | 53 +++-- boa/src/builtins/math/mod.rs | 76 +++---- boa/src/builtins/number/mod.rs | 36 ++-- boa/src/builtins/object/for_in_iterator.rs | 4 +- boa/src/builtins/object/mod.rs | 34 +-- boa/src/builtins/reflect/mod.rs | 28 +-- boa/src/builtins/regexp/mod.rs | 60 +++--- .../builtins/regexp/regexp_string_iterator.rs | 6 +- boa/src/builtins/set/mod.rs | 40 ++-- boa/src/builtins/set/set_iterator.rs | 4 +- boa/src/builtins/string/mod.rs | 72 +++---- boa/src/builtins/string/string_iterator.rs | 6 +- boa/src/builtins/symbol/mod.rs | 18 +- boa/src/class.rs | 20 +- boa/src/context.rs | 34 +-- .../declarative_environment_record.rs | 19 +- .../environment/environment_record_trait.rs | 33 +-- .../function_environment_record.rs | 25 ++- .../environment/global_environment_record.rs | 29 +-- boa/src/environment/lexical_environment.rs | 14 +- .../environment/object_environment_record.rs | 19 +- boa/src/exec/mod.rs | 4 +- boa/src/lib.rs | 8 +- boa/src/object/gcobject.rs | 27 ++- boa/src/object/internal_methods.rs | 36 ++-- boa/src/syntax/ast/node/array/mod.rs | 4 +- boa/src/syntax/ast/node/await_expr/mod.rs | 4 +- boa/src/syntax/ast/node/block/mod.rs | 4 +- boa/src/syntax/ast/node/break_node/mod.rs | 4 +- boa/src/syntax/ast/node/call/mod.rs | 4 +- .../node/conditional/conditional_op/mod.rs | 4 +- .../ast/node/conditional/if_node/mod.rs | 4 +- .../declaration/arrow_function_decl/mod.rs | 4 +- .../declaration/async_function_decl/mod.rs | 4 +- .../declaration/async_function_expr/mod.rs | 4 +- .../ast/node/declaration/function_decl/mod.rs | 4 +- .../ast/node/declaration/function_expr/mod.rs | 4 +- boa/src/syntax/ast/node/declaration/mod.rs | 10 +- .../ast/node/field/get_const_field/mod.rs | 4 +- .../syntax/ast/node/field/get_field/mod.rs | 4 +- boa/src/syntax/ast/node/identifier/mod.rs | 4 +- .../ast/node/iteration/continue_node/mod.rs | 4 +- .../ast/node/iteration/do_while_loop/mod.rs | 4 +- .../ast/node/iteration/for_in_loop/mod.rs | 4 +- .../syntax/ast/node/iteration/for_loop/mod.rs | 4 +- .../ast/node/iteration/for_of_loop/mod.rs | 4 +- .../ast/node/iteration/while_loop/mod.rs | 4 +- boa/src/syntax/ast/node/mod.rs | 4 +- boa/src/syntax/ast/node/new/mod.rs | 4 +- boa/src/syntax/ast/node/object/mod.rs | 4 +- .../syntax/ast/node/operator/assign/mod.rs | 4 +- .../syntax/ast/node/operator/bin_op/mod.rs | 6 +- .../syntax/ast/node/operator/unary_op/mod.rs | 4 +- boa/src/syntax/ast/node/return_smt/mod.rs | 4 +- boa/src/syntax/ast/node/spread/mod.rs | 4 +- boa/src/syntax/ast/node/statement_list/mod.rs | 4 +- boa/src/syntax/ast/node/switch/mod.rs | 4 +- boa/src/syntax/ast/node/template/mod.rs | 6 +- boa/src/syntax/ast/node/throw/mod.rs | 4 +- boa/src/syntax/ast/node/try_node/mod.rs | 4 +- boa/src/value/equality.rs | 2 +- boa/src/value/mod.rs | 42 ++-- boa/src/value/operations.rs | 38 ++-- boa/src/vm/mod.rs | 6 +- boa_tester/src/exec/js262.rs | 14 +- boa_tester/src/exec/mod.rs | 2 +- 84 files changed, 784 insertions(+), 616 deletions(-) diff --git a/boa/examples/classes.rs b/boa/examples/classes.rs index be857f6b71e..4a0960d9feb 100644 --- a/boa/examples/classes.rs +++ b/boa/examples/classes.rs @@ -2,7 +2,7 @@ use boa::{ class::{Class, ClassBuilder}, gc::{Finalize, Trace}, property::Attribute, - Context, JsValue, Result, + Context, JsResult, JsValue, }; // We create a new struct that is going to represent a person. @@ -26,7 +26,7 @@ struct Person { // or any function that matches that signature. impl Person { /// This function says hello - fn say_hello(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + fn say_hello(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { // We check if this is an object. if let Some(object) = this.as_object() { // If it is we downcast the type to type `Person`. @@ -57,7 +57,7 @@ impl Class for Person { const LENGTH: usize = 2; // This is what is called when we do `new Person()` - fn constructor(_this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + fn constructor(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // We get the first argument. If it is unavailable we get `undefined`. And, then call `to_string()`. // // This is equivalent to `String(arg)`. @@ -81,7 +81,7 @@ impl Class for Person { } /// This is where the object is intitialized. - fn init(class: &mut ClassBuilder) -> Result<()> { + fn init(class: &mut ClassBuilder) -> JsResult<()> { // we add a inheritable method `sayHello` with length `0` the amount of args it takes. // // This function is added to `Person.prototype.sayHello()` diff --git a/boa/src/builtins/array/array_iterator.rs b/boa/src/builtins/array/array_iterator.rs index d0ff5bce53e..2e44c37d8ca 100644 --- a/boa/src/builtins/array/array_iterator.rs +++ b/boa/src/builtins/array/array_iterator.rs @@ -4,7 +4,7 @@ use crate::{ object::{GcObject, ObjectData}, property::PropertyDescriptor, symbol::WellKnownSymbols, - BoaProfiler, Context, Result, + BoaProfiler, Context, JsResult, }; #[derive(Debug, Clone, Finalize, Trace)] @@ -68,7 +68,7 @@ impl ArrayIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next - pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { if let JsValue::Object(ref object) = this { let mut object = object.borrow_mut(); if let Some(array_iterator) = object.as_array_iterator_mut() { diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index 218d4334c17..e7d2c140f06 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -21,7 +21,7 @@ use crate::{ property::{Attribute, PropertyDescriptor}, symbol::WellKnownSymbols, value::{IntegerOrInfinity, JsValue}, - BoaProfiler, Context, JsString, Result, + BoaProfiler, Context, JsResult, JsString, }; use std::cmp::{max, min, Ordering}; @@ -124,7 +124,7 @@ impl Array { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget. // 2. Let proto be ? GetPrototypeFromConstructor(newTarget, "%Array.prototype%"). let prototype = new_target @@ -208,7 +208,7 @@ impl Array { length: usize, prototype: Option, context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. If length > 2^32 - 1, throw a RangeError exception. if length > 2usize.pow(32) - 1 { return Err(context.construct_range_error("array exceeded max size")); @@ -296,7 +296,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(this: &JsValue, context: &mut Context) -> Result { + fn is_concat_spreadable(this: &JsValue, context: &mut Context) -> JsResult { // 1. If Type(O) is not Object, return false. if !this.is_object() { return Ok(false); @@ -325,7 +325,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 - fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> Result { + fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult { // 1. Return the this value. Ok(this.clone()) } @@ -338,7 +338,7 @@ impl Array { original_array: &GcObject, length: usize, context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let isArray be ? IsArray(originalArray). // 2. If isArray is false, return ? ArrayCreate(length). if !original_array.is_array() { @@ -395,7 +395,7 @@ impl Array { array_ptr: &JsValue, add_values: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let orig_length = array_ptr.get_field("length", context)?.to_length(context)?; for (n, value) in add_values.iter().enumerate() { @@ -431,7 +431,7 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.isarray /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray - pub(crate) fn is_array(_: &JsValue, args: &[JsValue], _: &mut Context) -> Result { + pub(crate) fn is_array(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult { match args.get(0).and_then(|x| x.as_object()) { Some(object) => Ok(JsValue::new(object.borrow().is_array())), None => Ok(JsValue::new(false)), @@ -449,7 +449,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) -> Result { + pub(crate) fn of(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let len be the number of elements in items. // 2. Let lenNumber be ๐”ฝ(len). let len = args.len(); @@ -500,7 +500,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let obj = this.to_object(context)?; // 2. Let A be ? ArraySpeciesCreate(O, 0). @@ -575,7 +575,11 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.push /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push - pub(crate) fn push(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn push( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; // 2. Let len be ? LengthOfArrayLike(O). @@ -611,7 +615,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) -> Result { + pub(crate) fn pop(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; // 2. Let len be ? LengthOfArrayLike(O). @@ -654,7 +658,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; // 2. Let len be ? LengthOfArrayLike(O). @@ -702,7 +706,11 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.join /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join - pub(crate) fn join(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn join( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; // 2. Let len be ? LengthOfArrayLike(O). @@ -757,7 +765,7 @@ impl Array { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let array be ? ToObject(this value). let array = this.to_object(context)?; // 2. Let func be ? Get(array, "join"). @@ -783,7 +791,11 @@ impl Array { /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.reverse /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse #[allow(clippy::else_if_without_else)] - pub(crate) fn reverse(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn reverse( + this: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; // 2. Let len be ? LengthOfArrayLike(O). @@ -860,7 +872,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) -> Result { + pub(crate) fn shift(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; // 2. Let len be ? LengthOfArrayLike(O). @@ -921,7 +933,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; // 2. Let len be ? LengthOfArrayLike(O). @@ -992,7 +1004,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; // 2. Let len be ? LengthOfArrayLike(O). @@ -1046,7 +1058,11 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.map /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map - pub(crate) fn map(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn map( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; // 2. Let len be ? LengthOfArrayLike(O). @@ -1096,7 +1112,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -1183,7 +1199,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -1249,7 +1265,11 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.find /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find - pub(crate) fn find(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn find( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -1309,7 +1329,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -1361,7 +1381,11 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.flat /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat - pub(crate) fn flat(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn flat( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let O be ToObject(this value) let o = this.to_object(context)?; @@ -1417,7 +1441,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ToObject(this value) let o = this.to_object(context)?; @@ -1465,7 +1489,7 @@ impl Array { mapper_function: Option, this_arg: &JsValue, context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Assert target is Object // 2. Assert source is Object @@ -1573,7 +1597,11 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.fill /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill - pub(crate) fn fill(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn fill( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -1621,7 +1649,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -1698,7 +1726,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -1766,7 +1794,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -1838,7 +1866,11 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.some /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some - pub(crate) fn some(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn some( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; // 2. Let len be ? LengthOfArrayLike(O). @@ -1892,7 +1924,11 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.sort /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort - pub(crate) fn sort(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn sort( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception. let comparefn = match args.get(0).cloned() { // todo: change to `is_callable` inside `JsValue` @@ -1911,43 +1947,44 @@ impl Array { // - [ECMAScript reference][spec] // // [spec]: https://tc39.es/ecma262/#sec-sortcompare - let sort_compare = |x: &JsValue, y: &JsValue, context: &mut Context| -> Result { - match (x.is_undefined(), y.is_undefined()) { - // 1. If x and y are both undefined, return +0๐”ฝ. - (true, true) => return Ok(Ordering::Equal), - // 2. If x is undefined, return 1๐”ฝ. - (true, false) => return Ok(Ordering::Greater), - // 3. If y is undefined, return -1๐”ฝ. - (false, true) => return Ok(Ordering::Less), - _ => {} - } + let sort_compare = + |x: &JsValue, y: &JsValue, context: &mut Context| -> JsResult { + match (x.is_undefined(), y.is_undefined()) { + // 1. If x and y are both undefined, return +0๐”ฝ. + (true, true) => return Ok(Ordering::Equal), + // 2. If x is undefined, return 1๐”ฝ. + (true, false) => return Ok(Ordering::Greater), + // 3. If y is undefined, return -1๐”ฝ. + (false, true) => return Ok(Ordering::Less), + _ => {} + } - // 4. If comparefn is not undefined, then - if !comparefn.is_undefined() { - let args = [x.clone(), y.clone()]; - // a. Let v be ? ToNumber(? Call(comparefn, undefined, ยซ x, y ยป)). - let v = context - .call(&comparefn, &JsValue::Undefined, &args)? - .to_number(context)?; - // b. If v is NaN, return +0๐”ฝ. - // c. Return v. - return Ok(v.partial_cmp(&0.0).unwrap_or(Ordering::Equal)); - } - // 5. Let xString be ? ToString(x). - // 6. Let yString be ? ToString(y). - let x_str = x.to_string(context)?; - let y_str = y.to_string(context)?; - - // 7. Let xSmaller be IsLessThan(xString, yString, true). - // 8. If xSmaller is true, return -1๐”ฝ. - // 9. Let ySmaller be IsLessThan(yString, xString, true). - // 10. If ySmaller is true, return 1๐”ฝ. - // 11. Return +0๐”ฝ. - - // NOTE: skipped IsLessThan because it just makes a lexicographic comparation - // when x and y are strings - Ok(x_str.cmp(&y_str)) - }; + // 4. If comparefn is not undefined, then + if !comparefn.is_undefined() { + let args = [x.clone(), y.clone()]; + // a. Let v be ? ToNumber(? Call(comparefn, undefined, ยซ x, y ยป)). + let v = context + .call(&comparefn, &JsValue::Undefined, &args)? + .to_number(context)?; + // b. If v is NaN, return +0๐”ฝ. + // c. Return v. + return Ok(v.partial_cmp(&0.0).unwrap_or(Ordering::Equal)); + } + // 5. Let xString be ? ToString(x). + // 6. Let yString be ? ToString(y). + let x_str = x.to_string(context)?; + let y_str = y.to_string(context)?; + + // 7. Let xSmaller be IsLessThan(xString, yString, true). + // 8. If xSmaller is true, return -1๐”ฝ. + // 9. Let ySmaller be IsLessThan(yString, xString, true). + // 10. If ySmaller is true, return 1๐”ฝ. + // 11. Return +0๐”ฝ. + + // NOTE: skipped IsLessThan because it just makes a lexicographic comparation + // when x and y are strings + Ok(x_str.cmp(&y_str)) + }; // 2. Let obj be ? ToObject(this value). let obj = this.to_object(context)?; @@ -2023,7 +2060,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -2121,7 +2158,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -2219,7 +2256,7 @@ impl Array { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -2305,7 +2342,11 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.values /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values - pub(crate) fn values(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn values( + this: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { Ok(ArrayIterator::create_array_iterator( context, this.clone(), @@ -2323,7 +2364,7 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.values /// [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) -> Result { + pub(crate) fn keys(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { Ok(ArrayIterator::create_array_iterator( context, this.clone(), @@ -2341,7 +2382,11 @@ impl Array { /// /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.values /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values - pub(crate) fn entries(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn entries( + this: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { Ok(ArrayIterator::create_array_iterator( context, this.clone(), @@ -2354,7 +2399,7 @@ impl Array { context: &mut Context, arg: Option<&JsValue>, len: usize, - ) -> Result { + ) -> JsResult { // 1. Let relativeStart be ? ToIntegerOrInfinity(start). let relative_start = arg .cloned() @@ -2379,7 +2424,7 @@ impl Array { context: &mut Context, arg: Option<&JsValue>, len: usize, - ) -> Result { + ) -> JsResult { let default_value = JsValue::undefined(); let value = arg.unwrap_or(&default_value); // 1. If end is undefined, let relativeEnd be len [and return it] diff --git a/boa/src/builtins/bigint/mod.rs b/boa/src/builtins/bigint/mod.rs index 5da0d460d8a..b3f7919f7b5 100644 --- a/boa/src/builtins/bigint/mod.rs +++ b/boa/src/builtins/bigint/mod.rs @@ -17,7 +17,7 @@ use crate::{ object::{ConstructorBuilder, ObjectData}, property::Attribute, symbol::WellKnownSymbols, - BoaProfiler, Context, JsBigInt, JsValue, Result, + BoaProfiler, Context, JsBigInt, JsResult, JsValue, }; #[cfg(test)] mod tests; @@ -76,7 +76,7 @@ impl BigInt { /// /// [spec]: https://tc39.es/ecma262/#sec-bigint-objects /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt - fn constructor(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + fn constructor(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let data = match args.get(0) { Some(value) => value.to_bigint(context)?, None => JsBigInt::zero(), @@ -95,7 +95,7 @@ impl BigInt { /// /// [spec]: https://tc39.es/ecma262/#sec-thisbigintvalue #[inline] - fn this_bigint_value(value: &JsValue, context: &mut Context) -> Result { + fn this_bigint_value(value: &JsValue, context: &mut Context) -> JsResult { match value { // 1. If Type(value) is BigInt, return value. JsValue::BigInt(ref bigint) => return Ok(bigint.clone()), @@ -130,7 +130,7 @@ impl BigInt { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let radix = if !args.is_empty() { args[0].to_integer(context)? as i32 } else { @@ -159,7 +159,7 @@ impl BigInt { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { Ok(JsValue::new(Self::this_bigint_value(this, context)?)) } @@ -174,7 +174,7 @@ impl BigInt { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let (modulo, bits) = Self::calculate_as_uint_n(args, context)?; if bits > 0 @@ -200,7 +200,7 @@ impl BigInt { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let (modulo, _) = Self::calculate_as_uint_n(args, context)?; Ok(JsValue::new(modulo)) @@ -211,7 +211,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) -> Result<(JsBigInt, u32)> { + fn calculate_as_uint_n(args: &[JsValue], context: &mut Context) -> JsResult<(JsBigInt, u32)> { use std::convert::TryFrom; let undefined_value = JsValue::undefined(); diff --git a/boa/src/builtins/boolean/mod.rs b/boa/src/builtins/boolean/mod.rs index 25abe7bf857..8be7c2bc3db 100644 --- a/boa/src/builtins/boolean/mod.rs +++ b/boa/src/builtins/boolean/mod.rs @@ -16,7 +16,7 @@ use crate::{ builtins::BuiltIn, object::{ConstructorBuilder, ObjectData, PROTOTYPE}, property::Attribute, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; /// Boolean implementation. @@ -60,7 +60,7 @@ impl Boolean { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // Get the argument, if any let data = args.get(0).map(|x| x.to_boolean()).unwrap_or(false); if new_target.is_undefined() { @@ -92,7 +92,7 @@ impl Boolean { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-thisbooleanvalue - fn this_boolean_value(value: &JsValue, context: &mut Context) -> Result { + fn this_boolean_value(value: &JsValue, context: &mut Context) -> JsResult { match value { JsValue::Boolean(boolean) => return Ok(*boolean), JsValue::Object(ref object) => { @@ -120,7 +120,7 @@ impl Boolean { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let boolean = Self::this_boolean_value(this, context)?; Ok(JsValue::new(boolean.to_string())) } @@ -138,7 +138,7 @@ impl Boolean { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { Ok(JsValue::new(Self::this_boolean_value(this, context)?)) } } diff --git a/boa/src/builtins/console/mod.rs b/boa/src/builtins/console/mod.rs index 5cd14d401c9..95b2561738f 100644 --- a/boa/src/builtins/console/mod.rs +++ b/boa/src/builtins/console/mod.rs @@ -21,7 +21,7 @@ use crate::{ object::ObjectInitializer, property::Attribute, value::{display::display_obj, JsValue}, - BoaProfiler, Context, JsString, Result, + BoaProfiler, Context, JsResult, JsString, }; use rustc_hash::FxHashMap; use std::time::SystemTime; @@ -50,7 +50,7 @@ pub(crate) fn logger(msg: LogMessage, console_state: &Console) { } /// This represents the `console` formatter. -pub fn formatter(data: &[JsValue], context: &mut Context) -> Result { +pub fn formatter(data: &[JsValue], context: &mut Context) -> JsResult { let target = data .get(0) .cloned() @@ -184,7 +184,11 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#assert /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/assert - pub(crate) fn assert(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn assert( + _: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { let assertion = args.get(0).map(JsValue::to_boolean).unwrap_or(false); if !assertion { @@ -218,7 +222,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#clear /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/clear - pub(crate) fn clear(_: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn clear(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { context.console_mut().groups.clear(); Ok(JsValue::undefined()) } @@ -233,7 +237,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#debug /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/debug - pub(crate) fn debug(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn debug(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { logger( LogMessage::Log(formatter(args, context)?), context.console(), @@ -251,7 +255,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#error /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/error - pub(crate) fn error(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn error(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { logger( LogMessage::Error(formatter(args, context)?), context.console(), @@ -269,7 +273,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#info /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/info - pub(crate) fn info(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn info(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { logger( LogMessage::Info(formatter(args, context)?), context.console(), @@ -287,7 +291,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#log /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/log - pub(crate) fn log(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn log(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { logger( LogMessage::Log(formatter(args, context)?), context.console(), @@ -305,7 +309,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#trace /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/trace - pub(crate) fn trace(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn trace(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { if !args.is_empty() { logger( LogMessage::Log(formatter(args, context)?), @@ -332,7 +336,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#warn /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/warn - pub(crate) fn warn(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn warn(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { logger( LogMessage::Warn(formatter(args, context)?), context.console(), @@ -350,7 +354,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#count /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/count - pub(crate) fn count(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn count(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let label = match args.get(0) { Some(value) => value.to_string(context)?, None => "default".into(), @@ -381,7 +385,7 @@ impl Console { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let label = match args.get(0) { Some(value) => value.to_string(context)?, None => "default".into(), @@ -415,7 +419,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#time /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/time - pub(crate) fn time(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn time(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let label = match args.get(0) { Some(value) => value.to_string(context)?, None => "default".into(), @@ -448,7 +452,7 @@ impl Console { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let label = match args.get(0) { Some(value) => value.to_string(context)?, None => "default".into(), @@ -485,7 +489,7 @@ impl Console { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let label = match args.get(0) { Some(value) => value.to_string(context)?, None => "default".into(), @@ -517,7 +521,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#group /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/group - pub(crate) fn group(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn group(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let group_label = formatter(args, context)?; logger( @@ -539,7 +543,11 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#groupend /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/groupEnd - pub(crate) fn group_end(_: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn group_end( + _: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { context.console_mut().groups.pop(); Ok(JsValue::undefined()) @@ -555,7 +563,7 @@ impl Console { /// /// [spec]: https://console.spec.whatwg.org/#dir /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/dir - pub(crate) fn dir(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn dir(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let undefined = JsValue::undefined(); logger( LogMessage::Info(display_obj(args.get(0).unwrap_or(&undefined), true)), diff --git a/boa/src/builtins/date/mod.rs b/boa/src/builtins/date/mod.rs index ec6958d1566..a7784e9e494 100644 --- a/boa/src/builtins/date/mod.rs +++ b/boa/src/builtins/date/mod.rs @@ -8,7 +8,7 @@ use crate::{ property::Attribute, symbol::WellKnownSymbols, value::{JsValue, PreferredType}, - BoaProfiler, Context, JsString, Result, + BoaProfiler, Context, JsResult, JsString, }; use chrono::{prelude::*, Duration, LocalResult}; use std::fmt::Display; @@ -46,13 +46,13 @@ fn ignore_ambiguity(result: LocalResult) -> Option { macro_rules! getter_method { ($name:ident) => {{ - fn get_value(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + fn get_value(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { Ok(JsValue::new(this_time_value(this, context)?.$name())) } get_value }}; (Self::$name:ident) => {{ - fn get_value(_: &JsValue, _: &[JsValue], _: &mut Context) -> Result { + fn get_value(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult { Ok(JsValue::new(Date::$name())) } get_value @@ -334,7 +334,7 @@ impl Date { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if new_target.is_undefined() { Ok(Self::make_date_string()) } else { @@ -404,7 +404,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let value = &args[0]; let tv = match this_time_value(value, context) { Ok(dt) => dt.0, @@ -446,7 +446,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let mut year = args[0].to_number(context)?; let month = args[1].to_number(context)?; let day = args @@ -514,7 +514,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be the this value. // 2. If Type(O) is not Object, throw a TypeError exception. let o = if let Some(o) = this.as_object() { @@ -709,7 +709,7 @@ impl Date { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let t be ? thisTimeValue(this value). let t = this_time_value(this, context)?; @@ -854,7 +854,7 @@ impl Date { /// /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.setdate /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate - pub fn set_date(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub fn set_date(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let t be LocalTime(? thisTimeValue(this value)). let mut t = this_time_value(this, context)?; @@ -893,7 +893,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let t be ? thisTimeValue(this value). let mut t = this_time_value(this, context)?; @@ -951,7 +951,7 @@ impl Date { /// /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.sethours /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours - pub fn set_hours(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub fn set_hours(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let t be LocalTime(? thisTimeValue(this value)). let mut t = this_time_value(this, context)?; @@ -1010,7 +1010,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let t be LocalTime(? thisTimeValue(this value)). let mut t = this_time_value(this, context)?; @@ -1044,7 +1044,11 @@ impl Date { /// /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.setminutes /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes - pub fn set_minutes(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub fn set_minutes( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let t be LocalTime(? thisTimeValue(this value)). let mut t = this_time_value(this, context)?; @@ -1092,7 +1096,7 @@ impl Date { /// /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.setmonth /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth - pub fn set_month(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub fn set_month(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let t be LocalTime(? thisTimeValue(this value)). let mut t = this_time_value(this, context)?; @@ -1133,7 +1137,11 @@ impl Date { /// /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.setseconds /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds - pub fn set_seconds(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub fn set_seconds( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let t be LocalTime(? thisTimeValue(this value)). let mut t = this_time_value(this, context)?; @@ -1174,7 +1182,7 @@ impl Date { /// /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.setyear /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setYear - pub fn set_year(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub fn set_year(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let t be ? thisTimeValue(this value). let mut t = this_time_value(this, context)?; @@ -1231,7 +1239,7 @@ impl Date { /// /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.settime /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime - pub fn set_time(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub fn set_time(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Perform ? thisTimeValue(this value). this_time_value(this, context)?; @@ -1272,7 +1280,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let t be ? thisTimeValue(this value). let mut t = this_time_value(this, context)?; @@ -1311,7 +1319,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let t be ? thisTimeValue(this value). let mut t = this_time_value(this, context)?; @@ -1373,7 +1381,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let t be ? thisTimeValue(this value). let mut t = this_time_value(this, context)?; @@ -1432,7 +1440,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let t be ? thisTimeValue(this value). let mut t = this_time_value(this, context)?; @@ -1470,7 +1478,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let t be ? thisTimeValue(this value). let mut t = this_time_value(this, context)?; @@ -1526,7 +1534,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let t be ? thisTimeValue(this value). let mut t = this_time_value(this, context)?; @@ -1573,7 +1581,7 @@ impl Date { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let t be ? thisTimeValue(this value). let mut t = this_time_value(this, context)?; @@ -1617,7 +1625,11 @@ impl Date { /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.todatestring /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString #[allow(clippy::wrong_self_convention)] - pub fn to_date_string(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub fn to_date_string( + this: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let O be this Date object. // 2. Let tv be ? thisTimeValue(O). let tv = this_time_value(this, context)?; @@ -1659,7 +1671,11 @@ impl Date { /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.toisostring /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString #[allow(clippy::wrong_self_convention)] - pub fn to_iso_string(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub fn to_iso_string( + this: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { if let Some(t) = this_time_value(this, context)?.0 { Ok(Utc::now() .timezone() @@ -1683,7 +1699,7 @@ impl Date { /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.tojson /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON #[allow(clippy::wrong_self_convention)] - pub fn to_json(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub fn to_json(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { // 1. Let O be ? ToObject(this value). let o = this.to_object(context)?; @@ -1716,7 +1732,7 @@ impl Date { /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.tostring /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString #[allow(clippy::wrong_self_convention)] - pub fn to_string(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub fn to_string(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { // 1. Let tv be ? thisTimeValue(this value). let tv = this_time_value(this, context)?; @@ -1745,7 +1761,11 @@ impl Date { /// [spec]: https://tc39.es/ecma262/#sec-date.prototype.totimestring /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString #[allow(clippy::wrong_self_convention)] - pub fn to_time_string(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub fn to_time_string( + this: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let O be this Date object. // 2. Let tv be ? thisTimeValue(O). let tv = this_time_value(this, context)?; @@ -1805,7 +1825,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 - pub(crate) fn now(_: &JsValue, _: &[JsValue], _: &mut Context) -> Result { + pub(crate) fn now(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult { Ok(JsValue::new(Utc::now().timestamp_millis() as f64)) } @@ -1821,7 +1841,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) -> Result { + pub(crate) fn parse(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // This method is implementation-defined and discouraged, so we just require the same format as the string // constructor. @@ -1845,7 +1865,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) -> Result { + pub(crate) fn utc(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let year = args .get(0) .map_or(Ok(f64::NAN), |value| value.to_number(context))?; @@ -1906,7 +1926,7 @@ impl Date { /// /// [spec]: https://tc39.es/ecma262/#sec-thistimevalue #[inline] -pub fn this_time_value(value: &JsValue, context: &mut Context) -> Result { +pub fn this_time_value(value: &JsValue, context: &mut Context) -> JsResult { if let JsValue::Object(ref object) = value { if let ObjectData::Date(ref date) = object.borrow().data { return Ok(*date); diff --git a/boa/src/builtins/error/eval.rs b/boa/src/builtins/error/eval.rs index fcc8e3f6505..d32d504b81e 100644 --- a/boa/src/builtins/error/eval.rs +++ b/boa/src/builtins/error/eval.rs @@ -17,7 +17,7 @@ use crate::{ object::{ConstructorBuilder, ObjectData}, profiler::BoaProfiler, property::Attribute, - Context, JsValue, Result, + Context, JsResult, JsValue, }; /// JavaScript `EvalError` impleentation. @@ -61,7 +61,7 @@ impl EvalError { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let prototype = new_target .as_object() .and_then(|obj| { diff --git a/boa/src/builtins/error/mod.rs b/boa/src/builtins/error/mod.rs index cb04a5af3f1..4bdeac3abf3 100644 --- a/boa/src/builtins/error/mod.rs +++ b/boa/src/builtins/error/mod.rs @@ -15,7 +15,7 @@ use crate::{ object::{ConstructorBuilder, ObjectData, PROTOTYPE}, profiler::BoaProfiler, property::Attribute, - Context, JsValue, Result, + Context, JsResult, JsValue, }; pub(crate) mod eval; @@ -77,7 +77,7 @@ impl Error { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let prototype = new_target .as_object() .and_then(|obj| { @@ -117,7 +117,7 @@ impl Error { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if !this.is_object() { return context.throw_type_error("'this' is not an Object"); } diff --git a/boa/src/builtins/error/range.rs b/boa/src/builtins/error/range.rs index ea688719d5a..bf758c8a55b 100644 --- a/boa/src/builtins/error/range.rs +++ b/boa/src/builtins/error/range.rs @@ -14,7 +14,7 @@ use crate::{ object::{ConstructorBuilder, ObjectData, PROTOTYPE}, profiler::BoaProfiler, property::Attribute, - Context, JsValue, Result, + Context, JsResult, JsValue, }; /// JavaScript `RangeError` implementation. @@ -58,7 +58,7 @@ impl RangeError { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let prototype = new_target .as_object() .and_then(|obj| { diff --git a/boa/src/builtins/error/reference.rs b/boa/src/builtins/error/reference.rs index 3c23bc6d111..0dade3eec3a 100644 --- a/boa/src/builtins/error/reference.rs +++ b/boa/src/builtins/error/reference.rs @@ -14,7 +14,7 @@ use crate::{ object::{ConstructorBuilder, ObjectData, PROTOTYPE}, profiler::BoaProfiler, property::Attribute, - Context, JsValue, Result, + Context, JsResult, JsValue, }; #[derive(Debug, Clone, Copy)] @@ -57,7 +57,7 @@ impl ReferenceError { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let prototype = new_target .as_object() .and_then(|obj| { diff --git a/boa/src/builtins/error/syntax.rs b/boa/src/builtins/error/syntax.rs index b2f4701a80f..3765274a586 100644 --- a/boa/src/builtins/error/syntax.rs +++ b/boa/src/builtins/error/syntax.rs @@ -16,7 +16,7 @@ use crate::{ object::{ConstructorBuilder, ObjectData, PROTOTYPE}, profiler::BoaProfiler, property::Attribute, - Context, JsValue, Result, + Context, JsResult, JsValue, }; /// JavaScript `SyntaxError` impleentation. @@ -60,7 +60,7 @@ impl SyntaxError { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let prototype = new_target .as_object() .and_then(|obj| { diff --git a/boa/src/builtins/error/type.rs b/boa/src/builtins/error/type.rs index 02c9378c0bb..df56f02aa97 100644 --- a/boa/src/builtins/error/type.rs +++ b/boa/src/builtins/error/type.rs @@ -19,7 +19,7 @@ use crate::{ builtins::BuiltIn, object::{ConstructorBuilder, ObjectData, PROTOTYPE}, property::Attribute, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; /// JavaScript `TypeError` implementation. @@ -63,7 +63,7 @@ impl TypeError { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let prototype = new_target .as_object() .and_then(|obj| { diff --git a/boa/src/builtins/error/uri.rs b/boa/src/builtins/error/uri.rs index 5b86d0d6d44..7b50e7ef3b1 100644 --- a/boa/src/builtins/error/uri.rs +++ b/boa/src/builtins/error/uri.rs @@ -15,7 +15,7 @@ use crate::{ object::{ConstructorBuilder, ObjectData, PROTOTYPE}, profiler::BoaProfiler, property::Attribute, - Context, JsValue, Result, + Context, JsResult, JsValue, }; /// JavaScript `URIError` impleentation. @@ -59,7 +59,7 @@ impl UriError { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let prototype = new_target .as_object() .and_then(|obj| { diff --git a/boa/src/builtins/function/mod.rs b/boa/src/builtins/function/mod.rs index 0f2dab96bd9..9ee1b7567e5 100644 --- a/boa/src/builtins/function/mod.rs +++ b/boa/src/builtins/function/mod.rs @@ -19,7 +19,7 @@ use crate::{ object::{ConstructorBuilder, FunctionBuilder, GcObject, Object, ObjectData}, property::{Attribute, PropertyDescriptor}, syntax::ast::node::{FormalParameter, RcStatementList}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use bitflags::bitflags; use std::fmt::{self, Debug}; @@ -29,10 +29,10 @@ use std::rc::Rc; mod tests; /// _fn(this, arguments, context) -> ResultValue_ - The signature of a native built-in function -pub type NativeFunction = fn(&JsValue, &[JsValue], &mut Context) -> Result; +pub type NativeFunction = fn(&JsValue, &[JsValue], &mut Context) -> JsResult; /// _fn(this, arguments, context) -> ResultValue_ - The signature of a closure built-in function -pub type ClosureFunction = dyn Fn(&JsValue, &[JsValue], &mut Context) -> Result; +pub type ClosureFunction = dyn Fn(&JsValue, &[JsValue], &mut Context) -> JsResult; #[derive(Clone, Copy, Finalize)] pub struct BuiltInFunction(pub(crate) NativeFunction); @@ -268,7 +268,11 @@ pub struct BuiltInFunctionObject; impl BuiltInFunctionObject { pub const LENGTH: usize = 1; - fn constructor(new_target: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + fn constructor( + new_target: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { let prototype = new_target .as_object() .and_then(|obj| { @@ -291,7 +295,7 @@ impl BuiltInFunctionObject { Ok(this) } - fn prototype(_: &JsValue, _: &[JsValue], _: &mut Context) -> Result { + fn prototype(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult { Ok(JsValue::undefined()) } @@ -305,7 +309,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) -> Result { + fn call(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { if !this.is_function() { return context.throw_type_error(format!("{} is not a function", this.display())); } @@ -326,7 +330,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) -> Result { + fn apply(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { if !this.is_function() { return context.throw_type_error(format!("{} is not a function", this.display())); } diff --git a/boa/src/builtins/iterable/mod.rs b/boa/src/builtins/iterable/mod.rs index fb012b2aa64..157137daaf0 100644 --- a/boa/src/builtins/iterable/mod.rs +++ b/boa/src/builtins/iterable/mod.rs @@ -6,7 +6,7 @@ use crate::{ }, object::{GcObject, ObjectInitializer}, symbol::WellKnownSymbols, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; #[derive(Debug, Default)] @@ -101,7 +101,7 @@ pub fn create_iter_result_object(context: &mut Context, value: JsValue, done: bo } /// Get an iterator record -pub fn get_iterator(context: &mut Context, iterable: JsValue) -> Result { +pub fn get_iterator(context: &mut Context, iterable: JsValue) -> JsResult { let iterator_function = iterable.get_field(WellKnownSymbols::iterator(), context)?; if iterator_function.is_null_or_undefined() { return Err(context.construct_type_error("Not an iterable")); @@ -154,7 +154,7 @@ impl IteratorRecord { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-iteratornext - pub(crate) fn next(&self, context: &mut Context) -> Result { + pub(crate) fn next(&self, context: &mut Context) -> JsResult { let next = context.call(&self.next_function, &self.iterator_object, &[])?; let done = next.get_field("done", context)?.to_boolean(); @@ -170,9 +170,9 @@ impl IteratorRecord { /// [spec]: https://tc39.es/ecma262/#sec-iteratorclose pub(crate) fn close( &self, - completion: Result, + completion: JsResult, context: &mut Context, - ) -> Result { + ) -> JsResult { let mut inner_result = self.iterator_object.get_field("return", context); // 5 diff --git a/boa/src/builtins/json/mod.rs b/boa/src/builtins/json/mod.rs index b8e04614b75..79e138221bb 100644 --- a/boa/src/builtins/json/mod.rs +++ b/boa/src/builtins/json/mod.rs @@ -20,7 +20,7 @@ use crate::{ property::{Attribute, PropertyDescriptor, PropertyKey}, symbol::WellKnownSymbols, value::IntegerOrInfinity, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use serde::Serialize; use serde_json::{self, ser::PrettyFormatter, Serializer, Value as JSONValue}; @@ -68,7 +68,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) -> Result { + pub(crate) fn parse(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let arg = args .get(0) .cloned() @@ -102,7 +102,7 @@ impl Json { context: &mut Context, holder: &mut JsValue, key: &PropertyKey, - ) -> Result { + ) -> JsResult { let value = holder.get_field(key.clone(), context)?; if let JsValue::Object(ref object) = value { @@ -144,7 +144,7 @@ impl Json { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let object = match args.get(0) { None => return Ok(JsValue::undefined()), Some(obj) => obj, diff --git a/boa/src/builtins/map/map_iterator.rs b/boa/src/builtins/map/map_iterator.rs index 556ab28264e..fa3e60c3a70 100644 --- a/boa/src/builtins/map/map_iterator.rs +++ b/boa/src/builtins/map/map_iterator.rs @@ -3,7 +3,7 @@ use crate::{ object::{GcObject, ObjectData}, property::PropertyDescriptor, symbol::WellKnownSymbols, - BoaProfiler, Context, Result, + BoaProfiler, Context, JsResult, }; use gc::{Finalize, Trace}; @@ -34,7 +34,7 @@ impl MapIterator { pub(crate) const NAME: &'static str = "MapIterator"; /// Constructs a new `MapIterator`, that will iterate over `map`, starting at index 0 - fn new(map: JsValue, kind: MapIterationKind, context: &mut Context) -> Result { + fn new(map: JsValue, kind: MapIterationKind, context: &mut Context) -> JsResult { let lock = Map::lock(&map, context)?; Ok(MapIterator { iterated_map: map, @@ -56,7 +56,7 @@ impl MapIterator { context: &mut Context, map: JsValue, kind: MapIterationKind, - ) -> Result { + ) -> JsResult { let map_iterator = JsValue::new_object(context); map_iterator.set_data(ObjectData::MapIterator(Self::new(map, kind, context)?)); map_iterator @@ -74,7 +74,7 @@ impl MapIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-%mapiteratorprototype%.next - pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { if let JsValue::Object(ref object) = this { let mut object = object.borrow_mut(); if let Some(map_iterator) = object.as_map_iterator_mut() { diff --git a/boa/src/builtins/map/mod.rs b/boa/src/builtins/map/mod.rs index fc9eaf3dcdf..b7d9cc02740 100644 --- a/boa/src/builtins/map/mod.rs +++ b/boa/src/builtins/map/mod.rs @@ -17,7 +17,7 @@ use crate::{ object::{ConstructorBuilder, FunctionBuilder, ObjectData, PROTOTYPE}, property::{Attribute, PropertyDescriptor}, symbol::WellKnownSymbols, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use ordered_map::OrderedMap; @@ -107,7 +107,7 @@ impl Map { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if new_target.is_undefined() { return context .throw_type_error("calling a builtin Map constructor without new is forbidden"); @@ -182,7 +182,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 - fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> Result { + fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult { // 1. Return the this value. Ok(this.clone()) } @@ -197,7 +197,11 @@ impl Map { /// /// [spec]: https://www.ecma-international.org/ecma-262/11.0/index.html#sec-map.prototype.entries /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries - pub(crate) fn entries(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn entries( + this: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { MapIterator::create_map_iterator(context, this.clone(), MapIterationKind::KeyAndValue) } @@ -211,7 +215,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) -> Result { + pub(crate) fn keys(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { MapIterator::create_map_iterator(context, this.clone(), MapIterationKind::Key) } @@ -236,7 +240,11 @@ 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], context: &mut Context) -> Result { + pub(crate) fn set( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { let (key, value) = match args.len() { 0 => (JsValue::undefined(), JsValue::undefined()), 1 => (args[0].clone(), JsValue::undefined()), @@ -272,7 +280,7 @@ impl Map { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let key = args.get(0).cloned().unwrap_or_default(); let (deleted, size) = if let Some(object) = this.as_object() { @@ -299,7 +307,11 @@ 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], context: &mut Context) -> Result { + pub(crate) fn get( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { let key = args.get(0).cloned().unwrap_or_default(); if let JsValue::Object(ref object) = this { @@ -326,7 +338,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) -> Result { + pub(crate) fn clear(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult { this.set_data(ObjectData::Map(OrderedMap::new())); Self::set_size(this, 0); @@ -344,7 +356,11 @@ 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], context: &mut Context) -> Result { + pub(crate) fn has( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { let key = args.get(0).cloned().unwrap_or_default(); if let JsValue::Object(ref object) = this { @@ -371,7 +387,7 @@ impl Map { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if args.is_empty() { return Err(JsValue::new("Missing argument for Map.prototype.forEach")); } @@ -412,7 +428,7 @@ impl Map { } /// Helper function to get the full size of the map. - fn get_full_len(map: &JsValue, context: &mut Context) -> Result { + fn get_full_len(map: &JsValue, context: &mut Context) -> JsResult { if let JsValue::Object(ref object) = map { let object = object.borrow(); if let Some(map) = object.as_map_ref() { @@ -426,7 +442,7 @@ impl Map { } /// Helper function to lock the map. - fn lock(map: &JsValue, context: &mut Context) -> Result { + fn lock(map: &JsValue, context: &mut Context) -> JsResult { if let JsValue::Object(ref object) = map { let mut map = object.borrow_mut(); if let Some(map) = map.as_map_mut() { @@ -449,12 +465,19 @@ impl Map { /// /// [spec]: https://tc39.es/ecma262/#sec-map.prototype.values /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values - pub(crate) fn values(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn values( + this: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { MapIterator::create_map_iterator(context, this.clone(), MapIterationKind::Value) } /// Helper function to get a key-value pair from an array. - fn get_key_value(value: &JsValue, context: &mut Context) -> Result> { + fn get_key_value( + value: &JsValue, + context: &mut Context, + ) -> JsResult> { if let JsValue::Object(object) = value { if object.is_array() { let (key, value) = diff --git a/boa/src/builtins/math/mod.rs b/boa/src/builtins/math/mod.rs index cc64a593742..5ebc8c2771b 100644 --- a/boa/src/builtins/math/mod.rs +++ b/boa/src/builtins/math/mod.rs @@ -13,7 +13,7 @@ use crate::{ builtins::BuiltIn, object::ObjectInitializer, property::Attribute, symbol::WellKnownSymbols, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; #[cfg(test)] @@ -99,7 +99,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) -> Result { + pub(crate) fn abs(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -116,7 +116,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) -> Result { + pub(crate) fn acos(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -133,7 +133,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) -> Result { + pub(crate) fn acosh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -150,7 +150,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) -> Result { + pub(crate) fn asin(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -167,7 +167,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) -> Result { + pub(crate) fn asinh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -184,7 +184,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) -> Result { + pub(crate) fn atan(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -201,7 +201,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) -> Result { + pub(crate) fn atanh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -218,7 +218,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) -> Result { + pub(crate) fn atan2(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(match ( args.get(0).map(|x| x.to_number(context)).transpose()?, args.get(1).map(|x| x.to_number(context)).transpose()?, @@ -237,7 +237,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) -> Result { + pub(crate) fn cbrt(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -254,7 +254,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) -> Result { + pub(crate) fn ceil(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -271,7 +271,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) -> Result { + pub(crate) fn clz32(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_u32(context)) @@ -289,7 +289,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) -> Result { + pub(crate) fn cos(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -306,7 +306,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) -> Result { + pub(crate) fn cosh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -323,7 +323,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) -> Result { + pub(crate) fn exp(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -342,7 +342,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) -> Result { + pub(crate) fn expm1(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -359,7 +359,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) -> Result { + pub(crate) fn floor(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -376,7 +376,11 @@ impl Math { /// /// [spec]: https://tc39.es/ecma262/#sec-math.fround /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround - pub(crate) fn fround(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn fround( + _: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -393,7 +397,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) -> Result { + pub(crate) fn hypot(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let mut result = 0f64; for arg in args { let x = arg.to_number(context)?; @@ -410,7 +414,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) -> Result { + pub(crate) fn imul(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(match ( args.get(0).map(|x| x.to_u32(context)).transpose()?, args.get(1).map(|x| x.to_u32(context)).transpose()?, @@ -429,7 +433,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) -> Result { + pub(crate) fn log(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -446,7 +450,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) -> Result { + pub(crate) fn log1p(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -463,7 +467,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) -> Result { + pub(crate) fn log10(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -480,7 +484,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) -> Result { + pub(crate) fn log2(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -497,7 +501,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) -> Result { + pub(crate) fn max(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let mut max = f64::NEG_INFINITY; for arg in args { let num = arg.to_number(context)?; @@ -514,7 +518,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) -> Result { + pub(crate) fn min(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let mut min = f64::INFINITY; for arg in args { let num = arg.to_number(context)?; @@ -531,7 +535,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 - pub(crate) fn pow(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn pow(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(match ( args.get(0).map(|x| x.to_number(context)).transpose()?, args.get(1).map(|x| x.to_number(context)).transpose()?, @@ -550,7 +554,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 - pub(crate) fn random(_: &JsValue, _: &[JsValue], _: &mut Context) -> Result { + pub(crate) fn random(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult { Ok(rand::random::().into()) } @@ -562,7 +566,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 - pub(crate) fn round(_: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn round(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -579,7 +583,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) -> Result { + pub(crate) fn sign(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -605,7 +609,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) -> Result { + pub(crate) fn sin(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -622,7 +626,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) -> Result { + pub(crate) fn sinh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -639,7 +643,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) -> Result { + pub(crate) fn sqrt(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -656,7 +660,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) -> Result { + pub(crate) fn tan(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -673,7 +677,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) -> Result { + pub(crate) fn tanh(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) @@ -690,7 +694,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) -> Result { + pub(crate) fn trunc(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { Ok(args .get(0) .map(|x| x.to_number(context)) diff --git a/boa/src/builtins/number/mod.rs b/boa/src/builtins/number/mod.rs index 21ccaee2a0c..7b7a226ffd2 100644 --- a/boa/src/builtins/number/mod.rs +++ b/boa/src/builtins/number/mod.rs @@ -20,7 +20,7 @@ use crate::{ object::{ConstructorBuilder, ObjectData, PROTOTYPE}, property::Attribute, value::{AbstractRelation, IntegerOrInfinity, JsValue}, - BoaProfiler, Context, Result, + BoaProfiler, Context, JsResult, }; use num_traits::{float::FloatCore, Num}; @@ -158,7 +158,7 @@ impl Number { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let data = match args.get(0) { Some(value) => value.to_numeric_number(context)?, None => 0.0, @@ -184,7 +184,7 @@ impl Number { Ok(this) } - /// This function returns a `Result` of the number `Value`. + /// This function returns a `JsResult` of the number `Value`. /// /// If the `Value` is a `Number` primitive of `Number` object the number is returned. /// Otherwise an `TypeError` is thrown. @@ -193,7 +193,7 @@ impl Number { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-thisnumbervalue - fn this_number_value(value: &JsValue, context: &mut Context) -> Result { + fn this_number_value(value: &JsValue, context: &mut Context) -> JsResult { match *value { JsValue::Integer(integer) => return Ok(f64::from(integer)), JsValue::Rational(rational) => return Ok(rational), @@ -232,7 +232,7 @@ impl Number { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let this_num = Self::this_number_value(this, context)?; let this_str_num = Self::num_to_exponential(this_num); Ok(JsValue::new(this_str_num)) @@ -253,7 +253,7 @@ impl Number { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let this_num = Self::this_number_value(this, context)?; let precision = match args.get(0) { Some(n) => match n.to_integer(context)? as i32 { @@ -284,7 +284,7 @@ impl Number { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let this_num = Self::this_number_value(this, context)?; let this_str_num = format!("{}", this_num); Ok(JsValue::new(this_str_num)) @@ -391,7 +391,7 @@ impl Number { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let precision = args.get(0).cloned().unwrap_or_default(); // 1 & 6 @@ -638,7 +638,7 @@ impl Number { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let x be ? thisNumberValue(this value). let x = Self::this_number_value(this, context)?; @@ -697,7 +697,7 @@ impl Number { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { Ok(JsValue::new(Self::this_number_value(this, context)?)) } @@ -719,7 +719,7 @@ impl Number { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if let (Some(val), radix) = (args.get(0), args.get(1)) { // 1. Let inputString be ? ToString(string). let input_string = val.to_string(context)?; @@ -845,7 +845,7 @@ impl Number { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if let Some(val) = args.get(0) { let input_string = val.to_string(context)?; let s = input_string.trim_start_matches(is_trimmable_whitespace); @@ -897,7 +897,7 @@ impl Number { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if let Some(value) = args.get(0) { let number = value.to_number(context)?; Ok(number.is_finite().into()) @@ -924,7 +924,7 @@ impl Number { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if let Some(value) = args.get(0) { let number = value.to_number(context)?; Ok(number.is_nan().into()) @@ -951,7 +951,7 @@ impl Number { _: &JsValue, args: &[JsValue], _ctx: &mut Context, - ) -> Result { + ) -> JsResult { Ok(JsValue::new(if let Some(val) = args.get(0) { match val { JsValue::Integer(_) => true, @@ -977,7 +977,7 @@ impl Number { _: &JsValue, args: &[JsValue], _ctx: &mut Context, - ) -> Result { + ) -> JsResult { Ok(args.get(0).map_or(false, Self::is_integer).into()) } @@ -999,7 +999,7 @@ impl Number { _: &JsValue, args: &[JsValue], _ctx: &mut Context, - ) -> Result { + ) -> JsResult { Ok(JsValue::new(if let Some(val) = args.get(0) { match val { JsValue::Integer(_) => false, @@ -1029,7 +1029,7 @@ impl Number { _: &JsValue, args: &[JsValue], _ctx: &mut Context, - ) -> Result { + ) -> JsResult { Ok(JsValue::new(match args.get(0) { Some(JsValue::Integer(_)) => true, Some(JsValue::Rational(number)) if Self::is_float_integer(*number) => { diff --git a/boa/src/builtins/object/for_in_iterator.rs b/boa/src/builtins/object/for_in_iterator.rs index eaede65e725..a7751860474 100644 --- a/boa/src/builtins/object/for_in_iterator.rs +++ b/boa/src/builtins/object/for_in_iterator.rs @@ -5,7 +5,7 @@ use crate::{ property::PropertyDescriptor, property::PropertyKey, symbol::WellKnownSymbols, - BoaProfiler, Context, JsString, JsValue, Result, + BoaProfiler, Context, JsResult, JsString, JsValue, }; use rustc_hash::FxHashSet; use std::collections::VecDeque; @@ -63,7 +63,7 @@ impl ForInIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-%foriniteratorprototype%.next - pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { if let JsValue::Object(ref o) = this { let mut for_in_iterator = o.borrow_mut(); if let Some(iterator) = for_in_iterator.as_for_in_iterator_mut() { diff --git a/boa/src/builtins/object/mod.rs b/boa/src/builtins/object/mod.rs index 3986c85fa40..0399e7e3217 100644 --- a/boa/src/builtins/object/mod.rs +++ b/boa/src/builtins/object/mod.rs @@ -21,7 +21,7 @@ use crate::{ property::{Attribute, DescriptorKind, PropertyDescriptor, PropertyNameKind}, symbol::WellKnownSymbols, value::{JsValue, Type}, - BoaProfiler, Context, Result, + BoaProfiler, Context, JsResult, }; use super::Array; @@ -88,7 +88,7 @@ impl Object { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if !new_target.is_undefined() { let prototype = new_target .as_object() @@ -125,7 +125,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) -> Result { + pub fn create(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let prototype = args.get(0).cloned().unwrap_or_else(JsValue::undefined); let properties = args.get(1).cloned().unwrap_or_else(JsValue::undefined); @@ -163,7 +163,7 @@ impl Object { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let object = args .get(0) .unwrap_or(&JsValue::undefined()) @@ -193,7 +193,7 @@ impl Object { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let object = args .get(0) .unwrap_or(&JsValue::undefined()) @@ -265,7 +265,7 @@ impl Object { } /// Uses the SameValue algorithm to check equality of objects - pub fn is(_: &JsValue, args: &[JsValue], _: &mut Context) -> Result { + pub fn is(_: &JsValue, args: &[JsValue], _: &mut Context) -> JsResult { let x = args.get(0).cloned().unwrap_or_else(JsValue::undefined); let y = args.get(1).cloned().unwrap_or_else(JsValue::undefined); @@ -273,7 +273,7 @@ impl Object { } /// Get the `prototype` of an object. - pub fn get_prototype_of(_: &JsValue, args: &[JsValue], ctx: &mut Context) -> Result { + pub fn get_prototype_of(_: &JsValue, args: &[JsValue], ctx: &mut Context) -> JsResult { if args.is_empty() { return ctx.throw_type_error( "Object.getPrototypeOf: At least 1 argument required, but only 0 passed", @@ -292,7 +292,7 @@ impl Object { /// [More information][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-object.setprototypeof - pub fn set_prototype_of(_: &JsValue, args: &[JsValue], ctx: &mut Context) -> Result { + pub fn set_prototype_of(_: &JsValue, args: &[JsValue], ctx: &mut Context) -> JsResult { if args.len() < 2 { return ctx.throw_type_error(format!( "Object.setPrototypeOf: At least 2 arguments required, but only {} passed", @@ -351,7 +351,7 @@ impl Object { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let undefined = JsValue::undefined(); let mut v = args.get(0).unwrap_or(&undefined).clone(); if !v.is_object() { @@ -374,7 +374,7 @@ impl Object { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let object = args.get(0).cloned().unwrap_or_else(JsValue::undefined); if let Some(object) = object.as_object() { let key = args @@ -408,7 +408,7 @@ impl Object { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let arg = args.get(0).cloned().unwrap_or_default(); let arg_obj = arg.as_object(); if let Some(mut obj) = arg_obj { @@ -430,7 +430,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) -> Result { + pub fn to_string(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { // 1. If the this value is undefined, return "[object Undefined]". if this.is_undefined() { return Ok("[object Undefined]".into()); @@ -494,7 +494,7 @@ impl Object { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let key = args .get(0) .unwrap_or(&JsValue::undefined()) @@ -519,7 +519,7 @@ impl Object { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let key = match args.get(0) { None => return Ok(JsValue::new(false)), Some(key) => key, @@ -544,7 +544,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) -> Result { + pub fn assign(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let to be ? ToObject(target). let to = args .get(0) @@ -596,7 +596,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) -> Result { + pub fn keys(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let obj be ? ToObject(target). let obj = args .get(0) @@ -625,7 +625,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) -> Result { + pub fn entries(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let obj be ? ToObject(target). let obj = args .get(0) diff --git a/boa/src/builtins/reflect/mod.rs b/boa/src/builtins/reflect/mod.rs index ac1265f85ff..23cc99531fa 100644 --- a/boa/src/builtins/reflect/mod.rs +++ b/boa/src/builtins/reflect/mod.rs @@ -15,7 +15,7 @@ use crate::{ object::{Object, ObjectData, ObjectInitializer}, property::{Attribute, PropertyDescriptor}, symbol::WellKnownSymbols, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; #[cfg(test)] @@ -74,7 +74,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) -> Result { + pub(crate) fn apply(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let undefined = JsValue::undefined(); let target = args .get(0) @@ -105,7 +105,7 @@ impl Reflect { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let target = args .get(0) .and_then(|v| v.as_object()) @@ -144,7 +144,7 @@ impl Reflect { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let undefined = JsValue::undefined(); let target = args .get(0) @@ -174,7 +174,7 @@ impl Reflect { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let undefined = JsValue::undefined(); let target = args .get(0) @@ -193,7 +193,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) -> Result { + pub(crate) fn get(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let undefined = JsValue::undefined(); // 1. If Type(target) is not Object, throw a TypeError exception. let target = args @@ -225,7 +225,7 @@ impl Reflect { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { match args.get(0) { Some(v) if v.is_object() => (), _ => return context.throw_type_error("target must be an object"), @@ -247,7 +247,7 @@ impl Reflect { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let target = args .get(0) .and_then(|v| v.as_object()) @@ -263,7 +263,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) -> Result { + pub(crate) fn has(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let target = args .get(0) .and_then(|v| v.as_object()) @@ -287,7 +287,7 @@ impl Reflect { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let target = args .get(0) .and_then(|v| v.as_object()) @@ -307,7 +307,7 @@ impl Reflect { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let target = args .get(0) .and_then(|v| v.as_object()) @@ -344,7 +344,7 @@ impl Reflect { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let mut target = args .get(0) .and_then(|v| v.as_object()) @@ -361,7 +361,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) -> Result { + pub(crate) fn set(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let undefined = JsValue::undefined(); let target = args .get(0) @@ -391,7 +391,7 @@ impl Reflect { _: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let undefined = JsValue::undefined(); let mut target = args .get(0) diff --git a/boa/src/builtins/regexp/mod.rs b/boa/src/builtins/regexp/mod.rs index 4d362779db3..4eb32d03e98 100644 --- a/boa/src/builtins/regexp/mod.rs +++ b/boa/src/builtins/regexp/mod.rs @@ -18,7 +18,7 @@ use crate::{ property::Attribute, symbol::WellKnownSymbols, value::{IntegerOrInfinity, JsValue}, - BoaProfiler, Context, JsString, Result, + BoaProfiler, Context, JsResult, JsString, }; use regexp_string_iterator::RegExpStringIterator; use regress::Regex; @@ -186,7 +186,7 @@ impl RegExp { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let pattern = args.get(0).cloned().unwrap_or_else(JsValue::undefined); let flags = args.get(1).cloned().unwrap_or_else(JsValue::undefined); @@ -254,7 +254,7 @@ impl RegExp { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-regexpalloc - fn alloc(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + fn alloc(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { let proto = if let Some(obj) = this.as_object() { obj.get(PROTOTYPE, context)? } else { @@ -274,7 +274,7 @@ impl RegExp { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-regexpinitialize - fn initialize(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + fn initialize(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let pattern = args.get(0).cloned().unwrap_or_else(JsValue::undefined); let flags = args.get(1).cloned().unwrap_or_else(JsValue::undefined); @@ -373,7 +373,7 @@ impl RegExp { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-regexpcreate - pub(crate) fn create(p: JsValue, f: JsValue, context: &mut Context) -> Result { + pub(crate) fn create(p: JsValue, f: JsValue, context: &mut Context) -> JsResult { // 1. Let obj be ? RegExpAlloc(%RegExp%). let obj = RegExp::alloc( &context.global_object().get(RegExp::NAME, context)?, @@ -395,13 +395,13 @@ 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 - fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> Result { + fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult { // 1. Return the this value. Ok(this.clone()) } #[inline] - fn regexp_has_flag(this: &JsValue, flag: char, context: &mut Context) -> Result { + fn regexp_has_flag(this: &JsValue, flag: char, context: &mut Context) -> JsResult { if let Some(object) = this.as_object() { if let Some(regexp) = object.borrow().as_regexp() { return Ok(JsValue::new(match flag { @@ -453,7 +453,7 @@ impl RegExp { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { Self::regexp_has_flag(this, 'g', context) } @@ -471,7 +471,7 @@ impl RegExp { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { Self::regexp_has_flag(this, 'i', context) } @@ -489,7 +489,7 @@ impl RegExp { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { Self::regexp_has_flag(this, 'm', context) } @@ -507,7 +507,7 @@ impl RegExp { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { Self::regexp_has_flag(this, 's', context) } @@ -526,7 +526,7 @@ impl RegExp { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { Self::regexp_has_flag(this, 'u', context) } @@ -545,7 +545,7 @@ impl RegExp { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { Self::regexp_has_flag(this, 'y', context) } @@ -564,7 +564,7 @@ impl RegExp { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. if let Some(object) = this.as_object() { @@ -626,7 +626,7 @@ impl RegExp { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. if let Some(object) = this.as_object() { @@ -667,7 +667,7 @@ impl RegExp { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-escaperegexppattern - fn escape_pattern(src: &str, _flags: &str) -> Result { + fn escape_pattern(src: &str, _flags: &str) -> JsResult { if src.is_empty() { Ok(JsValue::new("(?:)")) } else { @@ -698,7 +698,11 @@ impl RegExp { /// /// [spec]: https://tc39.es/ecma262/#sec-regexp.prototype.test /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test - pub(crate) fn test(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn test( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. if !this.is_object() { @@ -736,7 +740,11 @@ impl RegExp { /// /// [spec]: https://tc39.es/ecma262/#sec-regexp.prototype.exec /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec - pub(crate) fn exec(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn exec( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { // 1. Let R be the this value. // 2. Perform ? RequireInternalSlot(R, [[RegExpMatcher]]). let obj = this.as_object().unwrap_or_default(); @@ -771,7 +779,7 @@ impl RegExp { this: &JsValue, input: JsString, context: &mut Context, - ) -> Result> { + ) -> JsResult> { // 1. Assert: Type(R) is Object. let object = this .as_object() @@ -816,7 +824,7 @@ impl RegExp { this: GcObject, input: JsString, context: &mut Context, - ) -> Result> { + ) -> JsResult> { // 1. Assert: R is an initialized RegExp instance. let rx = { let obj = this.borrow(); @@ -1049,7 +1057,7 @@ impl RegExp { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let rx be the this value. // 2. If Type(rx) is not Object, throw a TypeError exception. let rx = if let Some(rx) = this.as_object() { @@ -1152,7 +1160,7 @@ impl RegExp { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let (body, flags) = if let Some(object) = this.as_object() { let object = object.borrow(); let regex = object.as_regexp().ok_or_else(|| { @@ -1185,7 +1193,7 @@ impl RegExp { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. if !this.is_object() { @@ -1252,7 +1260,7 @@ impl RegExp { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let rx be the this value. // 2. If Type(rx) is not Object, throw a TypeError exception. let rx = if let Some(rx) = this.as_object() { @@ -1495,7 +1503,7 @@ impl RegExp { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let rx be the this value. // 2. If Type(rx) is not Object, throw a TypeError exception. let rx = if let Some(rx) = this.as_object() { @@ -1557,7 +1565,7 @@ impl RegExp { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let rx be the this value. // 2. If Type(rx) is not Object, throw a TypeError exception. let rx = if let Some(rx) = this.as_object() { diff --git a/boa/src/builtins/regexp/regexp_string_iterator.rs b/boa/src/builtins/regexp/regexp_string_iterator.rs index a349a22929e..292e1c54158 100644 --- a/boa/src/builtins/regexp/regexp_string_iterator.rs +++ b/boa/src/builtins/regexp/regexp_string_iterator.rs @@ -17,7 +17,7 @@ use crate::{ object::{GcObject, ObjectData}, property::PropertyDescriptor, symbol::WellKnownSymbols, - BoaProfiler, Context, JsString, JsValue, Result, + BoaProfiler, Context, JsResult, JsString, JsValue, }; // TODO: See todos in create_regexp_string_iterator and next. @@ -54,7 +54,7 @@ impl RegExpStringIterator { global: bool, unicode: bool, context: &mut Context, - ) -> Result { + ) -> JsResult { // 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()`. @@ -86,7 +86,7 @@ impl RegExpStringIterator { Ok(regexp_string_iterator) } - pub fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { if let JsValue::Object(ref object) = this { let mut object = object.borrow_mut(); if let Some(iterator) = object.as_regexp_string_iterator_mut() { diff --git a/boa/src/builtins/set/mod.rs b/boa/src/builtins/set/mod.rs index 01bd4d4cae6..09bcbec5e51 100644 --- a/boa/src/builtins/set/mod.rs +++ b/boa/src/builtins/set/mod.rs @@ -15,7 +15,7 @@ use crate::{ object::{ConstructorBuilder, FunctionBuilder, ObjectData, PROTOTYPE}, property::Attribute, symbol::WellKnownSymbols, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use ordered_set::OrderedSet; @@ -113,7 +113,7 @@ impl Set { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1 if new_target.is_undefined() { return context @@ -186,7 +186,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 - fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> Result { + fn get_species(this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult { // 1. Return the this value. Ok(this.clone()) } @@ -201,7 +201,11 @@ 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], context: &mut Context) -> Result { + pub(crate) fn add( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { let mut value = args.get(0).cloned().unwrap_or_default(); if let Some(object) = this.as_object() { @@ -230,7 +234,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], context: &mut Context) -> Result { + pub(crate) fn clear(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { if let Some(object) = this.as_object() { if object.borrow().is_set() { this.set_data(ObjectData::Set(OrderedSet::new())); @@ -258,7 +262,7 @@ impl Set { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let value = args.get(0).cloned().unwrap_or_default(); let res = if let Some(object) = this.as_object() { @@ -284,7 +288,11 @@ impl Set { /// /// [spec]: https://tc39.es/ecma262/#sec-set.prototype.entries /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries - pub(crate) fn entries(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn entries( + this: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { if let Some(object) = this.as_object() { let object = object.borrow(); if !object.is_set() { @@ -318,7 +326,7 @@ impl Set { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if args.is_empty() { return Err(JsValue::new("Missing argument for Set.prototype.forEach")); } @@ -367,7 +375,11 @@ 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], context: &mut Context) -> Result { + pub(crate) fn has( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { let value = args.get(0).cloned().unwrap_or_default(); if let JsValue::Object(ref object) = this { @@ -390,7 +402,11 @@ impl Set { /// /// [spec]: https://tc39.es/ecma262/#sec-set.prototype.values /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values - pub(crate) fn values(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn values( + this: &JsValue, + _: &[JsValue], + context: &mut Context, + ) -> JsResult { if let Some(object) = this.as_object() { let object = object.borrow(); if !object.is_set() { @@ -410,12 +426,12 @@ impl Set { )) } - fn size_getter(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + fn size_getter(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { Set::get_size(this, context).map(JsValue::from) } /// Helper function to get the size of the set. - fn get_size(set: &JsValue, context: &mut Context) -> Result { + fn get_size(set: &JsValue, context: &mut Context) -> JsResult { if let JsValue::Object(ref object) = set { let object = object.borrow(); if let Some(set) = object.as_set_ref() { diff --git a/boa/src/builtins/set/set_iterator.rs b/boa/src/builtins/set/set_iterator.rs index 865e29ea547..2c921a422a8 100644 --- a/boa/src/builtins/set/set_iterator.rs +++ b/boa/src/builtins/set/set_iterator.rs @@ -6,7 +6,7 @@ use crate::{ object::{GcObject, ObjectData}, property::PropertyDescriptor, symbol::WellKnownSymbols, - BoaProfiler, Context, Result, + BoaProfiler, Context, JsResult, }; use gc::{Finalize, Trace}; @@ -71,7 +71,7 @@ impl SetIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-%setiteratorprototype%.next - pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub(crate) fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { if let JsValue::Object(ref object) = this { let mut object = object.borrow_mut(); if let Some(set_iterator) = object.as_set_iterator_mut() { diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index 2525ebc451c..d9d695a5a65 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -20,7 +20,7 @@ use crate::{ object::{ConstructorBuilder, ObjectData}, property::{Attribute, PropertyDescriptor}, symbol::WellKnownSymbols, - BoaProfiler, Context, JsString, JsValue, Result, + BoaProfiler, Context, JsResult, JsString, JsValue, }; use std::{ char::{decode_utf16, from_u32}, @@ -159,7 +159,7 @@ impl String { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // This value is used by console.log and other routines to match Object type // to its Javascript Identifier (global constructor method name) let string = match args.get(0) { @@ -205,7 +205,7 @@ impl String { Ok(this) } - fn this_string_value(this: &JsValue, context: &mut Context) -> Result { + fn this_string_value(this: &JsValue, context: &mut Context) -> JsResult { match this { JsValue::String(ref string) => return Ok(string.clone()), JsValue::Object(ref object) => { @@ -227,7 +227,7 @@ impl String { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // Get String from String Object and send it back as a new value Ok(JsValue::new(Self::this_string_value(this, context)?)) } @@ -252,7 +252,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let primitive_val = this.to_string(context)?; @@ -289,7 +289,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) -> Result { + pub(crate) fn at(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { let this = this.require_object_coercible(context)?; let s = this.to_string(context)?; let len = s.encode_utf16().count(); @@ -331,7 +331,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let primitive_val = this.to_string(context)?; @@ -371,7 +371,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let primitive_val = this.to_string(context)?; @@ -414,7 +414,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let object = this.require_object_coercible(context)?; let mut string = object.to_string(context)?.to_string(); @@ -440,7 +440,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let object = this.require_object_coercible(context)?; let string = object.to_string(context)?; @@ -478,7 +478,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let primitive_val = this.to_string(context)?; @@ -533,7 +533,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let primitive_val = this.to_string(context)?; @@ -588,7 +588,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let primitive_val = this.to_string(context)?; @@ -642,7 +642,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let primitive_val = this.to_string(context)?; @@ -702,7 +702,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? RequireObjectCoercible(this value). this.require_object_coercible(context)?; @@ -818,7 +818,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? RequireObjectCoercible(this value). let o = this.require_object_coercible(context)?; @@ -988,7 +988,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let this = this.require_object_coercible(context)?; let string = this.to_string(context)?; @@ -1035,7 +1035,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let this = this.require_object_coercible(context)?; let string = this.to_string(context)?; @@ -1080,7 +1080,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? RequireObjectCoercible(this value). let o = this.require_object_coercible(context)?; @@ -1166,7 +1166,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let primitive = this.to_string(context)?; if args.is_empty() { return Err(JsValue::new("padEnd requires maxLength argument")); @@ -1197,7 +1197,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let primitive = this.to_string(context)?; if args.is_empty() { return Err(JsValue::new("padStart requires maxLength argument")); @@ -1224,7 +1224,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) -> Result { + pub(crate) fn trim(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { let this = this.require_object_coercible(context)?; let string = this.to_string(context)?; Ok(JsValue::new(string.trim_matches(is_trimmable_whitespace))) @@ -1246,7 +1246,7 @@ impl String { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let string = this.to_string(context)?; Ok(JsValue::new( string.trim_start_matches(is_trimmable_whitespace), @@ -1269,7 +1269,7 @@ impl String { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let this = this.require_object_coercible(context)?; let string = this.to_string(context)?; Ok(JsValue::new( @@ -1292,7 +1292,7 @@ impl String { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let this_str = this.to_string(context)?; @@ -1318,7 +1318,7 @@ impl String { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let this_str = this.to_string(context)?; @@ -1341,7 +1341,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let primitive_val = this.to_string(context)?; @@ -1371,7 +1371,7 @@ impl String { let to = max(final_start, final_end) as usize; // Extract the part of the string contained between the start index and the end index // where start is guaranteed to be smaller or equals to end - let extracted_string: std::result::Result = decode_utf16( + let extracted_string: Result = decode_utf16( primitive_val .encode_utf16() .skip(from) @@ -1396,7 +1396,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // First we get it the actual string a private field stored on the object only the context has access to. // Then we convert it into a Rust String by wrapping it in from_value let primitive_val = this.to_string(context)?; @@ -1457,7 +1457,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? RequireObjectCoercible(this value). let this = this.require_object_coercible(context)?; @@ -1611,7 +1611,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // Use the to_string method because it is specified to do the same thing in this case Self::to_string(this, args, context) } @@ -1632,7 +1632,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? RequireObjectCoercible(this value). let o = this.require_object_coercible(context)?; @@ -1695,7 +1695,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let this = this.require_object_coercible(context)?; let s = this.to_string(context)?; let form = args.get(0).cloned().unwrap_or_default(); @@ -1733,7 +1733,7 @@ impl String { this: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Let O be ? RequireObjectCoercible(this value). let o = this.require_object_coercible(context)?; @@ -1769,7 +1769,7 @@ impl String { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { StringIterator::create_string_iterator(context, this.clone()) } } @@ -1788,7 +1788,7 @@ pub(crate) fn get_substitution( named_captures: JsValue, replacement: JsString, context: &mut Context, -) -> Result { +) -> JsResult { // 1. Assert: Type(matched) is String. // 2. Let matchLength be the number of code units in matched. diff --git a/boa/src/builtins/string/string_iterator.rs b/boa/src/builtins/string/string_iterator.rs index a8aaec97f6d..3d8e5372a34 100644 --- a/boa/src/builtins/string/string_iterator.rs +++ b/boa/src/builtins/string/string_iterator.rs @@ -6,7 +6,7 @@ use crate::{ object::{GcObject, ObjectData}, property::PropertyDescriptor, symbol::WellKnownSymbols, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; #[derive(Debug, Clone, Finalize, Trace)] @@ -23,7 +23,7 @@ impl StringIterator { } } - pub fn create_string_iterator(context: &mut Context, string: JsValue) -> Result { + pub fn create_string_iterator(context: &mut Context, string: JsValue) -> JsResult { let string_iterator = JsValue::new_object(context); string_iterator.set_data(ObjectData::StringIterator(Self::new(string))); string_iterator @@ -33,7 +33,7 @@ impl StringIterator { Ok(string_iterator) } - pub fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> Result { + pub fn next(this: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult { if let JsValue::Object(ref object) = this { let mut object = object.borrow_mut(); if let Some(string_iterator) = object.as_string_iterator_mut() { diff --git a/boa/src/builtins/symbol/mod.rs b/boa/src/builtins/symbol/mod.rs index 0c88cc9caa4..78c11defbf5 100644 --- a/boa/src/builtins/symbol/mod.rs +++ b/boa/src/builtins/symbol/mod.rs @@ -24,7 +24,7 @@ use crate::{ property::Attribute, symbol::{JsSymbol, WellKnownSymbols}, value::JsValue, - BoaProfiler, Context, JsString, Result, + BoaProfiler, Context, JsResult, JsString, }; use std::cell::RefCell; @@ -163,7 +163,7 @@ impl Symbol { new_target: &JsValue, args: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { if new_target.is_undefined() { return context.throw_type_error("Symbol is not a constructor"); } @@ -175,7 +175,7 @@ impl Symbol { Ok(JsSymbol::new(description).into()) } - fn this_symbol_value(value: &JsValue, context: &mut Context) -> Result { + fn this_symbol_value(value: &JsValue, context: &mut Context) -> JsResult { match value { JsValue::Symbol(ref symbol) => return Ok(symbol.clone()), JsValue::Object(ref object) => { @@ -205,7 +205,7 @@ impl Symbol { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let symbol = Self::this_symbol_value(this, context)?; Ok(symbol.to_string().into()) } @@ -224,7 +224,7 @@ impl Symbol { this: &JsValue, _: &[JsValue], context: &mut Context, - ) -> Result { + ) -> JsResult { let symbol = Self::this_symbol_value(this, context)?; if let Some(ref description) = symbol.description() { Ok(description.clone().into()) @@ -241,7 +241,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) -> Result { + pub(crate) fn for_(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let stringKey be ? ToString(key). let string_key = args .get(0) @@ -271,7 +271,11 @@ 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], context: &mut Context) -> Result { + pub(crate) fn key_for( + _: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { let sym = args.get(0).cloned().unwrap_or_default(); // 1. If Type(sym) is not Symbol, throw a TypeError exception. if let Some(sym) = sym.as_symbol() { diff --git a/boa/src/class.rs b/boa/src/class.rs index 08f743c646d..67f1b5327ae 100644 --- a/boa/src/class.rs +++ b/boa/src/class.rs @@ -6,7 +6,7 @@ //!# property::Attribute, //!# class::{Class, ClassBuilder}, //!# gc::{Finalize, Trace}, -//!# Context, Result, JsValue, +//!# Context, JsResult, JsValue, //!# }; //!# //! // This does not have to be an enum it can also be a struct. @@ -25,7 +25,7 @@ //! const LENGTH: usize = 1; //! //! // This is what is called when we do `new Animal()` -//! fn constructor(_this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { +//! fn constructor(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { //! // This is equivalent to `String(arg)`. //! let kind = args.get(0).cloned().unwrap_or_default().to_string(context)?; //! @@ -39,7 +39,7 @@ //! } //! //! /// This is where the object is intitialized. -//! fn init(class: &mut ClassBuilder) -> Result<()> { +//! fn init(class: &mut ClassBuilder) -> JsResult<()> { //! class.method("speak", 0, |this, _args, _ctx| { //! if let Some(object) = this.as_object() { //! if let Some(animal) = object.downcast_ref::() { @@ -64,7 +64,7 @@ use crate::{ builtins::function::NativeFunction, object::{ConstructorBuilder, GcObject, NativeObject, ObjectData}, property::{Attribute, PropertyDescriptor, PropertyKey}, - Context, JsValue, Result, + Context, JsResult, JsValue, }; /// Native class. @@ -77,10 +77,10 @@ pub trait Class: NativeObject + Sized { const ATTRIBUTES: Attribute = Attribute::all(); /// The constructor of the class. - fn constructor(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result; + fn constructor(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult; /// Initializes the internals and the methods of the class. - fn init(class: &mut ClassBuilder<'_>) -> Result<()>; + fn init(class: &mut ClassBuilder<'_>) -> JsResult<()>; } /// This is a wrapper around `Class::constructor` that sets the internal data of a class. @@ -88,13 +88,17 @@ pub trait Class: NativeObject + Sized { /// This is automatically implemented, when a type implements `Class`. pub trait ClassConstructor: Class { /// The raw constructor that mathces the `NativeFunction` signature. - fn raw_constructor(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result + fn raw_constructor( + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult where Self: Sized; } impl ClassConstructor for T { - fn raw_constructor(this: &JsValue, args: &[JsValue], context: &mut Context) -> Result + fn raw_constructor(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult where Self: Sized, { diff --git a/boa/src/context.rs b/boa/src/context.rs index 954a0171db5..9e1d265d300 100644 --- a/boa/src/context.rs +++ b/boa/src/context.rs @@ -21,7 +21,7 @@ use crate::{ }, Parser, }, - BoaProfiler, Executable, JsString, JsValue, Result, + BoaProfiler, Executable, JsResult, JsString, JsValue, }; #[cfg(feature = "console")] @@ -345,7 +345,7 @@ impl Context { f: &JsValue, this: &JsValue, args: &[JsValue], - ) -> Result { + ) -> JsResult { match *f { JsValue::Object(ref object) => object.call(this, args, self), _ => self.throw_type_error("not a function"), @@ -375,7 +375,7 @@ impl Context { /// Throws a `Error` with the specified message. #[inline] - pub fn throw_error(&mut self, message: M) -> Result + pub fn throw_error(&mut self, message: M) -> JsResult where M: Into>, { @@ -399,7 +399,7 @@ impl Context { /// Throws a `RangeError` with the specified message. #[inline] - pub fn throw_range_error(&mut self, message: M) -> Result + pub fn throw_range_error(&mut self, message: M) -> JsResult where M: Into>, { @@ -423,7 +423,7 @@ impl Context { /// Throws a `TypeError` with the specified message. #[inline] - pub fn throw_type_error(&mut self, message: M) -> Result + pub fn throw_type_error(&mut self, message: M) -> JsResult where M: Into>, { @@ -446,7 +446,7 @@ impl Context { /// Throws a `ReferenceError` with the specified message. #[inline] - pub fn throw_reference_error(&mut self, message: M) -> Result + pub fn throw_reference_error(&mut self, message: M) -> JsResult where M: Into>, { @@ -469,7 +469,7 @@ impl Context { /// Throws a `SyntaxError` with the specified message. #[inline] - pub fn throw_syntax_error(&mut self, message: M) -> Result + pub fn throw_syntax_error(&mut self, message: M) -> JsResult where M: Into>, { @@ -503,7 +503,7 @@ impl Context { } /// Throws a `EvalError` with the specified message. - pub fn throw_eval_error(&mut self, message: M) -> Result + pub fn throw_eval_error(&mut self, message: M) -> JsResult where M: Into>, { @@ -511,7 +511,7 @@ impl Context { } /// Throws a `URIError` with the specified message. - pub fn throw_uri_error(&mut self, message: M) -> Result + pub fn throw_uri_error(&mut self, message: M) -> JsResult where M: Into>, { @@ -525,7 +525,7 @@ impl Context { params: P, body: B, flags: FunctionFlags, - ) -> Result + ) -> JsResult where N: Into, P: Into>, @@ -602,7 +602,7 @@ impl Context { name: &str, length: usize, body: NativeFunction, - ) -> Result<()> { + ) -> JsResult<()> { let function = FunctionBuilder::native(self, body) .name(name) .length(length) @@ -633,9 +633,9 @@ impl Context { /// to the global object, you can create the function object with [`FunctionBuilder`](crate::object::FunctionBuilder::closure). /// And bind it to the global object with [`Context::register_global_property`](Context::register_global_property) method. #[inline] - pub fn register_global_closure(&mut self, name: &str, length: usize, body: F) -> Result<()> + pub fn register_global_closure(&mut self, name: &str, length: usize, body: F) -> JsResult<()> where - F: Fn(&JsValue, &[JsValue], &mut Context) -> Result + 'static, + F: Fn(&JsValue, &[JsValue], &mut Context) -> JsResult + 'static, { let function = FunctionBuilder::closure(self, body) .name(name) @@ -665,7 +665,7 @@ impl Context { } #[inline] - pub(crate) fn set_value(&mut self, node: &Node, value: JsValue) -> Result { + pub(crate) fn set_value(&mut self, node: &Node, value: JsValue) -> JsResult { match node { Node::Identifier(ref name) => { self.set_mutable_binding(name.as_ref(), value.clone(), true)?; @@ -701,7 +701,7 @@ impl Context { /// context.register_global_class::(); /// ``` #[inline] - pub fn register_global_class(&mut self) -> Result<()> + pub fn register_global_class(&mut self) -> JsResult<()> where T: Class, { @@ -781,7 +781,7 @@ impl Context { #[cfg(not(feature = "vm"))] #[allow(clippy::unit_arg, clippy::drop_copy)] #[inline] - pub fn eval>(&mut self, src: T) -> Result { + pub fn eval>(&mut self, src: T) -> JsResult { let main_timer = BoaProfiler::global().start_event("Main", "Main"); let src_bytes: &[u8] = src.as_ref(); @@ -815,7 +815,7 @@ impl Context { /// ``` #[cfg(feature = "vm")] #[allow(clippy::unit_arg, clippy::drop_copy)] - pub fn eval>(&mut self, src: T) -> Result { + pub fn eval>(&mut self, src: T) -> JsResult { let main_timer = BoaProfiler::global().start_event("Main", "Main"); let src_bytes: &[u8] = src.as_ref(); diff --git a/boa/src/environment/declarative_environment_record.rs b/boa/src/environment/declarative_environment_record.rs index cf718fc90e8..242c93f238f 100644 --- a/boa/src/environment/declarative_environment_record.rs +++ b/boa/src/environment/declarative_environment_record.rs @@ -12,7 +12,7 @@ use crate::{ }, gc::{Finalize, Trace}, object::GcObject, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use gc::{Gc, GcCell}; use rustc_hash::FxHashMap; @@ -59,7 +59,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord { deletion: bool, allow_name_reuse: bool, _context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { if !allow_name_reuse { assert!( !self.env_rec.borrow().contains_key(name.as_str()), @@ -85,7 +85,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord { name: String, strict: bool, _context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { assert!( !self.env_rec.borrow().contains_key(name.as_str()), "Identifier {} has already been declared", @@ -104,7 +104,12 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord { Ok(()) } - fn initialize_binding(&self, name: &str, value: JsValue, _context: &mut Context) -> Result<()> { + fn initialize_binding( + &self, + name: &str, + value: JsValue, + _context: &mut Context, + ) -> JsResult<()> { if let Some(ref mut record) = self.env_rec.borrow_mut().get_mut(name) { if record.value.is_none() { record.value = Some(value); @@ -121,7 +126,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord { value: JsValue, mut strict: bool, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { if self.env_rec.borrow().get(name).is_none() { if strict { return Err(context.construct_reference_error(format!("{} not found", name))); @@ -164,7 +169,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord { name: &str, _strict: bool, context: &mut Context, - ) -> Result { + ) -> JsResult { if let Some(binding) = self.env_rec.borrow().get(name) { if let Some(ref val) = binding.value { Ok(val.clone()) @@ -194,7 +199,7 @@ impl EnvironmentRecordTrait for DeclarativeEnvironmentRecord { false } - fn get_this_binding(&self, _context: &mut Context) -> Result { + fn get_this_binding(&self, _context: &mut Context) -> JsResult { Ok(JsValue::undefined()) } diff --git a/boa/src/environment/environment_record_trait.rs b/boa/src/environment/environment_record_trait.rs index 29c0878e59d..485baa38613 100644 --- a/boa/src/environment/environment_record_trait.rs +++ b/boa/src/environment/environment_record_trait.rs @@ -13,7 +13,7 @@ use crate::{environment::lexical_environment::VariableScope, object::GcObject}; use crate::{ environment::lexical_environment::{Environment, EnvironmentType}, gc::{Finalize, Trace}, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt::Debug; @@ -39,7 +39,7 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { deletion: bool, allow_name_reuse: bool, context: &mut Context, - ) -> Result<()>; + ) -> JsResult<()>; /// Create a new but uninitialized immutable binding in an Environment Record. /// The String value N is the text of the bound name. @@ -50,12 +50,13 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { name: String, strict: bool, context: &mut Context, - ) -> Result<()>; + ) -> JsResult<()>; /// Set the value of an already existing but uninitialized binding in an Environment Record. /// The String value N is the text of the bound name. /// V is the value for the binding and is a value of any ECMAScript language type. - fn initialize_binding(&self, name: &str, value: JsValue, context: &mut Context) -> Result<()>; + fn initialize_binding(&self, name: &str, value: JsValue, context: &mut Context) + -> JsResult<()>; /// Set the value of an already existing mutable binding in an Environment Record. /// The String value `name` is the text of the bound name. @@ -67,14 +68,18 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { value: JsValue, strict: bool, context: &mut Context, - ) -> Result<()>; + ) -> JsResult<()>; /// Returns the value of an already existing binding from an Environment Record. /// The String value N is the text of the bound name. /// S is used to identify references originating in strict mode code or that /// otherwise require strict mode reference semantics. - fn get_binding_value(&self, name: &str, strict: bool, context: &mut Context) - -> Result; + fn get_binding_value( + &self, + name: &str, + strict: bool, + context: &mut Context, + ) -> JsResult; /// Delete a binding from an Environment Record. /// The String value name is the text of the bound name. @@ -87,7 +92,7 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { fn has_this_binding(&self) -> bool; /// Return the `this` binding from the environment - fn get_this_binding(&self, context: &mut Context) -> Result; + fn get_this_binding(&self, context: &mut Context) -> JsResult; /// Determine if an Environment Record establishes a super method binding. /// Return true if it does and false if it does not. @@ -110,7 +115,7 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { fn get_environment_type(&self) -> EnvironmentType; /// Return the `this` binding from the environment or try to get it from outer environments - fn recursive_get_this_binding(&self, context: &mut Context) -> Result { + fn recursive_get_this_binding(&self, context: &mut Context) -> JsResult { if self.has_this_binding() { self.get_this_binding(context) } else { @@ -128,7 +133,7 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { deletion: bool, scope: VariableScope, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { match scope { VariableScope::Block => self.create_mutable_binding(name, deletion, false, context), VariableScope::Function => self @@ -145,7 +150,7 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { deletion: bool, scope: VariableScope, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { match scope { VariableScope::Block => self.create_immutable_binding(name, deletion, context), VariableScope::Function => self @@ -162,7 +167,7 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { value: JsValue, strict: bool, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { if self.has_binding(name) { self.set_mutable_binding(name, value, strict, context) } else { @@ -178,7 +183,7 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { name: &str, value: JsValue, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { if self.has_binding(name) { self.initialize_binding(name, value, context) } else { @@ -198,7 +203,7 @@ pub trait EnvironmentRecordTrait: Debug + Trace + Finalize { } /// Retrieve binding from current or any outer environment - fn recursive_get_binding_value(&self, name: &str, context: &mut Context) -> Result { + fn recursive_get_binding_value(&self, name: &str, context: &mut Context) -> JsResult { if self.has_binding(name) { self.get_binding_value(name, false, context) } else { diff --git a/boa/src/environment/function_environment_record.rs b/boa/src/environment/function_environment_record.rs index 8dce92024ba..1ef0797ac8f 100644 --- a/boa/src/environment/function_environment_record.rs +++ b/boa/src/environment/function_environment_record.rs @@ -18,7 +18,7 @@ use crate::{ }, gc::{empty_trace, Finalize, Trace}, object::GcObject, - Context, JsValue, Result, + Context, JsResult, JsValue, }; /// Different binding status for `this`. @@ -80,7 +80,7 @@ impl FunctionEnvironmentRecord { func_env } - pub fn bind_this_value(&mut self, value: JsValue) -> Result { + pub fn bind_this_value(&mut self, value: JsValue) -> JsResult { match self.this_binding_status { // You can not bind an arrow function, their `this` value comes from the lexical scope above BindingStatus::Lexical => { @@ -123,7 +123,7 @@ impl EnvironmentRecordTrait for FunctionEnvironmentRecord { deletion: bool, allow_name_reuse: bool, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { self.declarative_record .create_mutable_binding(name, deletion, allow_name_reuse, context) } @@ -133,12 +133,17 @@ impl EnvironmentRecordTrait for FunctionEnvironmentRecord { name: String, strict: bool, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { self.declarative_record .create_immutable_binding(name, strict, context) } - fn initialize_binding(&self, name: &str, value: JsValue, context: &mut Context) -> Result<()> { + fn initialize_binding( + &self, + name: &str, + value: JsValue, + context: &mut Context, + ) -> JsResult<()> { self.declarative_record .initialize_binding(name, value, context) } @@ -149,7 +154,7 @@ impl EnvironmentRecordTrait for FunctionEnvironmentRecord { value: JsValue, strict: bool, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { self.declarative_record .set_mutable_binding(name, value, strict, context) } @@ -159,7 +164,7 @@ impl EnvironmentRecordTrait for FunctionEnvironmentRecord { name: &str, strict: bool, context: &mut Context, - ) -> Result { + ) -> JsResult { self.declarative_record .get_binding_value(name, strict, context) } @@ -172,7 +177,7 @@ impl EnvironmentRecordTrait for FunctionEnvironmentRecord { !matches!(self.this_binding_status, BindingStatus::Lexical) } - fn get_this_binding(&self, context: &mut Context) -> Result { + fn get_this_binding(&self, context: &mut Context) -> JsResult { match self.this_binding_status { BindingStatus::Lexical => { panic!("There is no this for a lexical function record"); @@ -214,7 +219,7 @@ impl EnvironmentRecordTrait for FunctionEnvironmentRecord { deletion: bool, _scope: VariableScope, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { self.create_mutable_binding(name, deletion, false, context) } @@ -224,7 +229,7 @@ impl EnvironmentRecordTrait for FunctionEnvironmentRecord { deletion: bool, _scope: VariableScope, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { self.create_immutable_binding(name, deletion, context) } } diff --git a/boa/src/environment/global_environment_record.rs b/boa/src/environment/global_environment_record.rs index b5408c96916..524293db8d1 100644 --- a/boa/src/environment/global_environment_record.rs +++ b/boa/src/environment/global_environment_record.rs @@ -17,7 +17,7 @@ use crate::{ gc::{Finalize, Trace}, object::GcObject, property::PropertyDescriptor, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use gc::{Gc, GcCell}; use rustc_hash::FxHashSet; @@ -104,7 +104,7 @@ impl GlobalEnvironmentRecord { name: String, deletion: bool, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { let obj_rec = &mut self.object_record; let global_object = &obj_rec.bindings; let has_property = global_object.has_field(name.as_str()); @@ -157,7 +157,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { deletion: bool, allow_name_reuse: bool, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { if !allow_name_reuse && self.declarative_record.has_binding(&name) { return Err( context.construct_type_error(format!("Binding already exists for {}", name)) @@ -173,7 +173,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { name: String, strict: bool, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { if self.declarative_record.has_binding(&name) { return Err( context.construct_type_error(format!("Binding already exists for {}", name)) @@ -184,7 +184,12 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { .create_immutable_binding(name, strict, context) } - fn initialize_binding(&self, name: &str, value: JsValue, context: &mut Context) -> Result<()> { + fn initialize_binding( + &self, + name: &str, + value: JsValue, + context: &mut Context, + ) -> JsResult<()> { if self.declarative_record.has_binding(name) { return self .declarative_record @@ -204,7 +209,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { value: JsValue, strict: bool, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { if self.declarative_record.has_binding(name) { return self .declarative_record @@ -219,7 +224,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { name: &str, strict: bool, context: &mut Context, - ) -> Result { + ) -> JsResult { if self.declarative_record.has_binding(name) { return self .declarative_record @@ -251,7 +256,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { true } - fn get_this_binding(&self, _context: &mut Context) -> Result { + fn get_this_binding(&self, _context: &mut Context) -> JsResult { Ok(self.global_this_binding.clone().into()) } @@ -286,7 +291,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { deletion: bool, _scope: VariableScope, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { self.create_mutable_binding(name, deletion, false, context) } @@ -296,7 +301,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { deletion: bool, _scope: VariableScope, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { self.create_immutable_binding(name, deletion, context) } @@ -306,7 +311,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { value: JsValue, strict: bool, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { self.set_mutable_binding(name, value, strict, context) } @@ -315,7 +320,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { name: &str, value: JsValue, context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { self.initialize_binding(name, value, context) } } diff --git a/boa/src/environment/lexical_environment.rs b/boa/src/environment/lexical_environment.rs index 6fb07c5cd92..c690abf0003 100644 --- a/boa/src/environment/lexical_environment.rs +++ b/boa/src/environment/lexical_environment.rs @@ -8,7 +8,7 @@ use super::global_environment_record::GlobalEnvironmentRecord; use crate::{ environment::environment_record_trait::EnvironmentRecordTrait, object::GcObject, BoaProfiler, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use gc::Gc; use std::{collections::VecDeque, error, fmt}; @@ -88,7 +88,7 @@ impl Context { self.realm.environment.environment_stack.pop_back() } - pub(crate) fn get_this_binding(&mut self) -> Result { + pub(crate) fn get_this_binding(&mut self) -> JsResult { self.get_current_environment() .recursive_get_this_binding(self) } @@ -98,7 +98,7 @@ impl Context { name: String, deletion: bool, scope: VariableScope, - ) -> Result<()> { + ) -> JsResult<()> { self.get_current_environment() .recursive_create_mutable_binding(name, deletion, scope, self) } @@ -108,7 +108,7 @@ impl Context { name: String, deletion: bool, scope: VariableScope, - ) -> Result<()> { + ) -> JsResult<()> { self.get_current_environment() .recursive_create_immutable_binding(name, deletion, scope, self) } @@ -118,12 +118,12 @@ impl Context { name: &str, value: JsValue, strict: bool, - ) -> Result<()> { + ) -> JsResult<()> { self.get_current_environment() .recursive_set_mutable_binding(name, value, strict, self) } - pub(crate) fn initialize_binding(&mut self, name: &str, value: JsValue) -> Result<()> { + pub(crate) fn initialize_binding(&mut self, name: &str, value: JsValue) -> JsResult<()> { self.get_current_environment() .recursive_initialize_binding(name, value, self) } @@ -143,7 +143,7 @@ impl Context { self.get_current_environment().recursive_has_binding(name) } - pub(crate) fn get_binding_value(&mut self, name: &str) -> Result { + pub(crate) fn get_binding_value(&mut self, name: &str) -> JsResult { self.get_current_environment() .recursive_get_binding_value(name, self) } diff --git a/boa/src/environment/object_environment_record.rs b/boa/src/environment/object_environment_record.rs index 8e37b948117..2c8e40016c4 100644 --- a/boa/src/environment/object_environment_record.rs +++ b/boa/src/environment/object_environment_record.rs @@ -16,7 +16,7 @@ use crate::{ gc::{Finalize, Trace}, object::GcObject, property::PropertyDescriptor, - Context, JsValue, Result, + Context, JsResult, JsValue, }; #[derive(Debug, Trace, Finalize, Clone)] @@ -60,7 +60,7 @@ impl EnvironmentRecordTrait for ObjectEnvironmentRecord { deletion: bool, _allow_name_reuse: bool, _context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { // TODO: could save time here and not bother generating a new undefined object, // only for it to be replace with the real value later. We could just add the name to a Vector instead let bindings = &self.bindings; @@ -79,11 +79,16 @@ impl EnvironmentRecordTrait for ObjectEnvironmentRecord { _name: String, _strict: bool, _context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { Ok(()) } - fn initialize_binding(&self, name: &str, value: JsValue, context: &mut Context) -> Result<()> { + fn initialize_binding( + &self, + name: &str, + value: JsValue, + context: &mut Context, + ) -> JsResult<()> { // We should never need to check if a binding has been created, // As all calls to create_mutable_binding are followed by initialized binding // The below is just a check. @@ -97,7 +102,7 @@ impl EnvironmentRecordTrait for ObjectEnvironmentRecord { value: JsValue, strict: bool, _context: &mut Context, - ) -> Result<()> { + ) -> JsResult<()> { debug_assert!(value.is_object() || value.is_function()); let property = PropertyDescriptor::builder() .value(value) @@ -115,7 +120,7 @@ impl EnvironmentRecordTrait for ObjectEnvironmentRecord { name: &str, strict: bool, context: &mut Context, - ) -> Result { + ) -> JsResult { if self.bindings.has_field(name) { Ok(self .bindings @@ -140,7 +145,7 @@ impl EnvironmentRecordTrait for ObjectEnvironmentRecord { false } - fn get_this_binding(&self, _context: &mut Context) -> Result { + fn get_this_binding(&self, _context: &mut Context) -> JsResult { Ok(JsValue::undefined()) } diff --git a/boa/src/exec/mod.rs b/boa/src/exec/mod.rs index 803d55a69bf..eae8bef3b45 100644 --- a/boa/src/exec/mod.rs +++ b/boa/src/exec/mod.rs @@ -3,11 +3,11 @@ #[cfg(test)] mod tests; -use crate::{Context, JsValue, Result}; +use crate::{Context, JsResult, JsValue}; pub trait Executable { /// Runs this executable in the given context. - fn run(&self, context: &mut Context) -> Result; + fn run(&self, context: &mut Context) -> JsResult; } #[derive(Debug, Eq, PartialEq)] diff --git a/boa/src/lib.rs b/boa/src/lib.rs index 175194ceb7d..df08df78726 100644 --- a/boa/src/lib.rs +++ b/boa/src/lib.rs @@ -64,9 +64,7 @@ pub mod vm; /// A convenience module that re-exports the most commonly-used Boa APIs pub mod prelude { - pub use crate::{ - object::GcObject as JsObject, Context, JsBigInt, JsString, JsValue, Result as JsResult, - }; + pub use crate::{object::GcObject as JsObject, Context, JsBigInt, JsResult, JsString, JsValue}; } use std::result::Result as StdResult; @@ -86,7 +84,7 @@ use crate::syntax::{ /// The result of a Javascript expression is represented like this so it can succeed (`Ok`) or fail (`Err`) #[must_use] -pub type Result = StdResult; +pub type JsResult = StdResult; /// Parses the given source code. /// @@ -129,7 +127,7 @@ pub(crate) fn forward>(context: &mut Context, src: T) -> String { /// If the interpreter fails parsing an error value is returned instead (error object) #[allow(clippy::unit_arg, clippy::drop_copy)] #[cfg(test)] -pub(crate) fn forward_val>(context: &mut Context, src: T) -> Result { +pub(crate) fn forward_val>(context: &mut Context, src: T) -> JsResult { let main_timer = BoaProfiler::global().start_event("Main", "Main"); let src_bytes: &[u8] = src.as_ref(); diff --git a/boa/src/object/gcobject.rs b/boa/src/object/gcobject.rs index 0753056270e..195e4279038 100644 --- a/boa/src/object/gcobject.rs +++ b/boa/src/object/gcobject.rs @@ -17,7 +17,7 @@ use crate::{ symbol::WellKnownSymbols, syntax::ast::node::RcStatementList, value::PreferredType, - Context, Executable, JsValue, Result, + Context, Executable, JsResult, JsValue, }; use gc::{Finalize, Gc, GcCell, GcCellRef, GcCellRefMut, Trace}; use serde_json::{map::Map, Value as JSONValue}; @@ -130,7 +130,7 @@ impl GcObject { args: &[JsValue], context: &mut Context, construct: bool, - ) -> Result { + ) -> JsResult { let this_function_object = self.clone(); let mut has_parameter_expressions = false; @@ -345,7 +345,12 @@ impl GcObject { // #[track_caller] #[inline] - pub fn call(&self, this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { + pub fn call( + &self, + this: &JsValue, + args: &[JsValue], + context: &mut Context, + ) -> JsResult { self.call_construct(this, args, context, false) } @@ -362,7 +367,7 @@ impl GcObject { args: &[JsValue], new_target: &JsValue, context: &mut Context, - ) -> Result { + ) -> JsResult { self.call_construct(new_target, args, context, true) } @@ -388,7 +393,7 @@ impl GcObject { &self, context: &mut Context, hint: PreferredType, - ) -> Result { + ) -> JsResult { // 1. Assert: Type(O) is Object. // Already is GcObject by type. // 2. Assert: Type(hint) is String and its value is either "string" or "number". @@ -439,7 +444,7 @@ impl GcObject { } /// Converts an object to JSON, checking for reference cycles and throwing a TypeError if one is found - pub(crate) fn to_json(&self, context: &mut Context) -> Result> { + pub(crate) fn to_json(&self, context: &mut Context) -> JsResult> { let rec_limiter = RecursionLimiter::new(self); if rec_limiter.live { Err(context.construct_type_error("cyclic object value")) @@ -704,7 +709,7 @@ impl GcObject { /// /// [spec]: https://tc39.es/ecma262/#sec-getmethod #[inline] - pub fn get_method(&self, context: &mut Context, key: K) -> Result> + pub fn get_method(&self, context: &mut Context, key: K) -> JsResult> where K: Into, { @@ -737,7 +742,7 @@ impl GcObject { &self, context: &mut Context, value: &JsValue, - ) -> Result { + ) -> JsResult { // 1. If IsCallable(C) is false, return false. if !self.is_callable() { return Ok(false); @@ -789,7 +794,7 @@ impl GcObject { &self, default_constructor: JsValue, context: &mut Context, - ) -> Result { + ) -> JsResult { // 1. Assert: Type(O) is Object. // 2. Let C be ? Get(O, "constructor"). @@ -828,7 +833,7 @@ impl GcObject { } } - pub fn to_property_descriptor(&self, context: &mut Context) -> Result { + pub fn to_property_descriptor(&self, context: &mut Context) -> JsResult { // 1 is implemented on the method `to_property_descriptor` of value // 2. Let desc be a new Property Descriptor that initially has no fields. @@ -929,7 +934,7 @@ impl GcObject { source: &JsValue, excluded_keys: Vec, context: &mut Context, - ) -> Result<()> + ) -> JsResult<()> where K: Into, { diff --git a/boa/src/object/internal_methods.rs b/boa/src/object/internal_methods.rs index f5474ae3598..e5a6a7bef66 100644 --- a/boa/src/object/internal_methods.rs +++ b/boa/src/object/internal_methods.rs @@ -10,7 +10,7 @@ use crate::{ object::{GcObject, Object, ObjectData}, property::{DescriptorKind, PropertyDescriptor, PropertyKey, PropertyNameKind}, value::{JsValue, Type}, - BoaProfiler, Context, Result, + BoaProfiler, Context, JsResult, }; impl GcObject { @@ -22,7 +22,7 @@ impl GcObject { /// [spec]: https://tc39.es/ecma262/#sec-hasproperty // NOTE: for now context is not used but it will in the future. #[inline] - pub fn has_property(&self, key: K, _context: &mut Context) -> Result + pub fn has_property(&self, key: K, _context: &mut Context) -> JsResult where K: Into, { @@ -40,7 +40,7 @@ impl GcObject { /// [spec]: https://tc39.es/ecma262/#sec-isextensible-o // NOTE: for now context is not used but it will in the future. #[inline] - pub fn is_extensible(&self, _context: &mut Context) -> Result { + pub fn is_extensible(&self, _context: &mut Context) -> JsResult { // 1. Assert: Type(O) is Object. // 2. Return ? O.[[IsExtensible]](). Ok(self.__is_extensible__()) @@ -62,7 +62,7 @@ impl GcObject { /// /// [spec]: https://tc39.es/ecma262/#sec-definepropertyorthrow #[inline] - pub fn delete_property_or_throw(&self, key: K, context: &mut Context) -> Result + pub fn delete_property_or_throw(&self, key: K, context: &mut Context) -> JsResult where K: Into, { @@ -86,7 +86,7 @@ impl GcObject { /// /// [spec]: https://tc39.es/ecma262/#sec-hasownproperty #[inline] - pub fn has_own_property(&self, key: K, _context: &mut Context) -> Result + pub fn has_own_property(&self, key: K, _context: &mut Context) -> JsResult where K: Into, { @@ -107,7 +107,7 @@ impl GcObject { /// /// [spec]: https://tc39.es/ecma262/#sec-get-o-p #[inline] - pub fn get(&self, key: K, context: &mut Context) -> Result + pub fn get(&self, key: K, context: &mut Context) -> JsResult where K: Into, { @@ -124,7 +124,7 @@ impl GcObject { /// /// [spec]: https://tc39.es/ecma262/#sec-set-o-p-v-throw #[inline] - pub fn set(&self, key: K, value: V, throw: bool, context: &mut Context) -> Result + pub fn set(&self, key: K, value: V, throw: bool, context: &mut Context) -> JsResult where K: Into, V: Into, @@ -157,7 +157,7 @@ impl GcObject { key: K, desc: P, context: &mut Context, - ) -> Result + ) -> JsResult where K: Into, P: Into, @@ -186,7 +186,7 @@ impl GcObject { key: K, value: V, context: &mut Context, - ) -> Result + ) -> JsResult where K: Into, V: Into, @@ -214,7 +214,7 @@ impl GcObject { key: K, value: V, context: &mut Context, - ) -> Result + ) -> JsResult where K: Into, V: Into, @@ -289,7 +289,7 @@ impl GcObject { key: &PropertyKey, receiver: JsValue, context: &mut Context, - ) -> Result { + ) -> JsResult { match self.__get_own_property__(key) { None => { // parent will either be null or an Object @@ -318,7 +318,7 @@ impl GcObject { value: JsValue, receiver: JsValue, context: &mut Context, - ) -> Result { + ) -> JsResult { let _timer = BoaProfiler::global().start_event("Object::set", "object"); // Fetch property key @@ -377,7 +377,7 @@ impl GcObject { key: PropertyKey, desc: PropertyDescriptor, context: &mut Context, - ) -> Result { + ) -> JsResult { if self.is_array() { self.array_define_own_property(key, desc, context) } else { @@ -482,7 +482,7 @@ impl GcObject { key: PropertyKey, desc: PropertyDescriptor, context: &mut Context, - ) -> Result { + ) -> JsResult { match key { PropertyKey::String(ref s) if s == "length" => { let new_len_val = match desc.value() { @@ -691,7 +691,7 @@ impl GcObject { /// /// [spec]: https://tc39.es/ecma262/#sec-object.defineproperties #[inline] - pub fn define_properties(&mut self, props: JsValue, context: &mut Context) -> Result<()> { + pub fn define_properties(&mut self, props: JsValue, context: &mut Context) -> JsResult<()> { let props = &props.to_object(context)?; let keys = props.own_property_keys(); let mut descriptors: Vec<(PropertyKey, PropertyDescriptor)> = Vec::new(); @@ -838,7 +838,7 @@ impl GcObject { &self, element_types: &[Type], context: &mut Context, - ) -> Result> { + ) -> JsResult> { // 1. If elementTypes is not present, set elementTypes to ยซ Undefined, Null, Boolean, String, Symbol, Number, BigInt, Object ยป. let types = if element_types.is_empty() { &[ @@ -892,7 +892,7 @@ impl GcObject { &self, kind: PropertyNameKind, context: &mut Context, - ) -> Result> { + ) -> JsResult> { // 1. Assert: Type(O) is Object. // 2. Let ownKeys be ? O.[[OwnPropertyKeys]](). let own_keys = self.own_property_keys(); @@ -941,7 +941,7 @@ impl GcObject { Ok(properties) } - pub(crate) fn length_of_array_like(&self, context: &mut Context) -> Result { + pub(crate) fn length_of_array_like(&self, context: &mut Context) -> JsResult { // 1. Assert: Type(obj) is Object. // 2. Return โ„(? ToLength(? Get(obj, "length"))). self.get("length", context)?.to_length(context) diff --git a/boa/src/syntax/ast/node/array/mod.rs b/boa/src/syntax/ast/node/array/mod.rs index 7ea413db3a6..484fab733c6 100644 --- a/boa/src/syntax/ast/node/array/mod.rs +++ b/boa/src/syntax/ast/node/array/mod.rs @@ -5,7 +5,7 @@ use crate::{ builtins::{iterable, Array}, exec::Executable, gc::{Finalize, Trace}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -39,7 +39,7 @@ pub struct ArrayDecl { } impl Executable for ArrayDecl { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("ArrayDecl", "exec"); let array = Array::new_array(context); let mut elements = Vec::new(); diff --git a/boa/src/syntax/ast/node/await_expr/mod.rs b/boa/src/syntax/ast/node/await_expr/mod.rs index d5f8faa35fb..ecdeef97686 100644 --- a/boa/src/syntax/ast/node/await_expr/mod.rs +++ b/boa/src/syntax/ast/node/await_expr/mod.rs @@ -1,7 +1,7 @@ //! Await expression node. use super::Node; -use crate::{exec::Executable, BoaProfiler, Context, JsValue, Result}; +use crate::{exec::Executable, BoaProfiler, Context, JsResult, JsValue}; use gc::{Finalize, Trace}; use std::fmt; @@ -27,7 +27,7 @@ pub struct AwaitExpr { } impl Executable for AwaitExpr { - fn run(&self, _: &mut Context) -> Result { + fn run(&self, _: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("AwaitExpression", "exec"); // TODO: Implement AwaitExpr Ok(JsValue::undefined()) diff --git a/boa/src/syntax/ast/node/block/mod.rs b/boa/src/syntax/ast/node/block/mod.rs index 838ec3c451b..c89b0d01135 100644 --- a/boa/src/syntax/ast/node/block/mod.rs +++ b/boa/src/syntax/ast/node/block/mod.rs @@ -6,7 +6,7 @@ use crate::{ exec::Executable, exec::InterpreterState, gc::{Finalize, Trace}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -54,7 +54,7 @@ impl Block { } impl Executable for Block { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("Block", "exec"); { let env = context.get_current_environment(); diff --git a/boa/src/syntax/ast/node/break_node/mod.rs b/boa/src/syntax/ast/node/break_node/mod.rs index 49903ca8813..b5f7fb298e3 100644 --- a/boa/src/syntax/ast/node/break_node/mod.rs +++ b/boa/src/syntax/ast/node/break_node/mod.rs @@ -3,7 +3,7 @@ use crate::{ exec::Executable, exec::InterpreterState, gc::{Finalize, Trace}, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -52,7 +52,7 @@ impl Break { } impl Executable for Break { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { context .executor() .set_current_state(InterpreterState::Break(self.label().map(Box::from))); diff --git a/boa/src/syntax/ast/node/call/mod.rs b/boa/src/syntax/ast/node/call/mod.rs index 40ec7f6a91a..3d082ffb6bc 100644 --- a/boa/src/syntax/ast/node/call/mod.rs +++ b/boa/src/syntax/ast/node/call/mod.rs @@ -4,7 +4,7 @@ use crate::{ exec::InterpreterState, gc::{Finalize, Trace}, syntax::ast::node::{join_nodes, Node}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -60,7 +60,7 @@ impl Call { } impl Executable for Call { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("Call", "exec"); let (this, func) = match self.expr() { Node::GetConstField(ref get_const_field) => { diff --git a/boa/src/syntax/ast/node/conditional/conditional_op/mod.rs b/boa/src/syntax/ast/node/conditional/conditional_op/mod.rs index d69667c9c04..c37ecbec264 100644 --- a/boa/src/syntax/ast/node/conditional/conditional_op/mod.rs +++ b/boa/src/syntax/ast/node/conditional/conditional_op/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -60,7 +60,7 @@ impl ConditionalOp { } impl Executable for ConditionalOp { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { Ok(if self.cond().run(context)?.to_boolean() { self.if_true().run(context)? } else { diff --git a/boa/src/syntax/ast/node/conditional/if_node/mod.rs b/boa/src/syntax/ast/node/conditional/if_node/mod.rs index 45009466ab1..e04dd8f3e6e 100644 --- a/boa/src/syntax/ast/node/conditional/if_node/mod.rs +++ b/boa/src/syntax/ast/node/conditional/if_node/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -79,7 +79,7 @@ impl If { } impl Executable for If { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { Ok(if self.cond().run(context)?.to_boolean() { self.body().run(context)? } else if let Some(else_e) = self.else_node() { diff --git a/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs b/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs index 4d0f3443f84..e631e612375 100644 --- a/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs +++ b/boa/src/syntax/ast/node/declaration/arrow_function_decl/mod.rs @@ -3,7 +3,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::{join_nodes, FormalParameter, Node, StatementList}, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -72,7 +72,7 @@ impl ArrowFunctionDecl { } impl Executable for ArrowFunctionDecl { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { context.create_function( "", self.params().to_vec(), diff --git a/boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs b/boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs index f567da89001..ae5d271ee02 100644 --- a/boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs +++ b/boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs @@ -3,7 +3,7 @@ use crate::{ exec::Executable, syntax::ast::node::{join_nodes, FormalParameter, Node, StatementList}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use gc::{Finalize, Trace}; use std::fmt; @@ -79,7 +79,7 @@ impl AsyncFunctionDecl { } impl Executable for AsyncFunctionDecl { - fn run(&self, _: &mut Context) -> Result { + fn run(&self, _: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("AsyncFunctionDecl", "exec"); // TODO: Implement AsyncFunctionDecl Ok(JsValue::undefined()) diff --git a/boa/src/syntax/ast/node/declaration/async_function_expr/mod.rs b/boa/src/syntax/ast/node/declaration/async_function_expr/mod.rs index a4057c61f47..cfe68312026 100644 --- a/boa/src/syntax/ast/node/declaration/async_function_expr/mod.rs +++ b/boa/src/syntax/ast/node/declaration/async_function_expr/mod.rs @@ -3,7 +3,7 @@ use crate::{ exec::Executable, syntax::ast::node::{join_nodes, FormalParameter, Node, StatementList}, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use gc::{Finalize, Trace}; use std::fmt; @@ -81,7 +81,7 @@ impl AsyncFunctionExpr { } impl Executable for AsyncFunctionExpr { - fn run(&self, _: &mut Context) -> Result { + fn run(&self, _: &mut Context) -> JsResult { // TODO: Implement AsyncFunctionExpr Ok(JsValue::undefined()) } diff --git a/boa/src/syntax/ast/node/declaration/function_decl/mod.rs b/boa/src/syntax/ast/node/declaration/function_decl/mod.rs index 680e232c994..b3c39c17bcf 100644 --- a/boa/src/syntax/ast/node/declaration/function_decl/mod.rs +++ b/boa/src/syntax/ast/node/declaration/function_decl/mod.rs @@ -4,7 +4,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::{join_nodes, FormalParameter, Node, StatementList}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -86,7 +86,7 @@ impl FunctionDecl { } impl Executable for FunctionDecl { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("FunctionDecl", "exec"); let val = context.create_function( self.name(), diff --git a/boa/src/syntax/ast/node/declaration/function_expr/mod.rs b/boa/src/syntax/ast/node/declaration/function_expr/mod.rs index bd149b37121..77472fec758 100644 --- a/boa/src/syntax/ast/node/declaration/function_expr/mod.rs +++ b/boa/src/syntax/ast/node/declaration/function_expr/mod.rs @@ -3,7 +3,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::{join_nodes, FormalParameter, Node, StatementList}, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -98,7 +98,7 @@ impl FunctionExpr { } impl Executable for FunctionExpr { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let val = context.create_function( self.name().unwrap_or(""), self.parameters().to_vec(), diff --git a/boa/src/syntax/ast/node/declaration/mod.rs b/boa/src/syntax/ast/node/declaration/mod.rs index 2ac3c5d5a8b..1316c55c2fc 100644 --- a/boa/src/syntax/ast/node/declaration/mod.rs +++ b/boa/src/syntax/ast/node/declaration/mod.rs @@ -5,7 +5,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::{join_nodes, Identifier, Node}, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -91,7 +91,7 @@ pub enum DeclarationList { } impl Executable for DeclarationList { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { for decl in self.as_ref() { use DeclarationList::*; let val = match decl.init() { @@ -355,7 +355,7 @@ impl DeclarationPattern { &self, init: Option, context: &mut Context, - ) -> Result, JsValue)>> { + ) -> JsResult, JsValue)>> { match &self { DeclarationPattern::Object(pattern) => pattern.run(init, context), DeclarationPattern::Array(pattern) => pattern.run(init, context), @@ -446,7 +446,7 @@ impl DeclarationPatternObject { &self, init: Option, context: &mut Context, - ) -> Result, JsValue)>> { + ) -> JsResult, JsValue)>> { let value = if let Some(value) = init { value } else if let Some(node) = &self.init { @@ -652,7 +652,7 @@ impl DeclarationPatternArray { &self, init: Option, context: &mut Context, - ) -> Result, JsValue)>> { + ) -> JsResult, JsValue)>> { let value = if let Some(value) = init { value } else if let Some(node) = &self.init { diff --git a/boa/src/syntax/ast/node/field/get_const_field/mod.rs b/boa/src/syntax/ast/node/field/get_const_field/mod.rs index 4d1adcff7e8..7ae400cf1f5 100644 --- a/boa/src/syntax/ast/node/field/get_const_field/mod.rs +++ b/boa/src/syntax/ast/node/field/get_const_field/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -62,7 +62,7 @@ impl GetConstField { } impl Executable for GetConstField { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let mut obj = self.obj().run(context)?; if !obj.is_object() { obj = JsValue::Object(obj.to_object(context)?); diff --git a/boa/src/syntax/ast/node/field/get_field/mod.rs b/boa/src/syntax/ast/node/field/get_field/mod.rs index a6f42bfdb95..6efa7367c25 100644 --- a/boa/src/syntax/ast/node/field/get_field/mod.rs +++ b/boa/src/syntax/ast/node/field/get_field/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -61,7 +61,7 @@ impl GetField { } impl Executable for GetField { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let mut obj = self.obj().run(context)?; if !obj.is_object() { obj = JsValue::Object(obj.to_object(context)?); diff --git a/boa/src/syntax/ast/node/identifier/mod.rs b/boa/src/syntax/ast/node/identifier/mod.rs index 48d127cae54..a1a301a8096 100644 --- a/boa/src/syntax/ast/node/identifier/mod.rs +++ b/boa/src/syntax/ast/node/identifier/mod.rs @@ -4,7 +4,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::Node, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -34,7 +34,7 @@ pub struct Identifier { } impl Executable for Identifier { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("Identifier", "exec"); context.get_binding_value(self.as_ref()) } diff --git a/boa/src/syntax/ast/node/iteration/continue_node/mod.rs b/boa/src/syntax/ast/node/iteration/continue_node/mod.rs index 80c63bfbc01..cda656a45f8 100644 --- a/boa/src/syntax/ast/node/iteration/continue_node/mod.rs +++ b/boa/src/syntax/ast/node/iteration/continue_node/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::{Executable, InterpreterState}, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -46,7 +46,7 @@ impl Continue { } impl Executable for Continue { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { context .executor() .set_current_state(InterpreterState::Continue(self.label().map(Box::from))); diff --git a/boa/src/syntax/ast/node/iteration/do_while_loop/mod.rs b/boa/src/syntax/ast/node/iteration/do_while_loop/mod.rs index 76cc11d0458..9310909c6c2 100644 --- a/boa/src/syntax/ast/node/iteration/do_while_loop/mod.rs +++ b/boa/src/syntax/ast/node/iteration/do_while_loop/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::{Executable, InterpreterState}, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -74,7 +74,7 @@ impl DoWhileLoop { } impl Executable for DoWhileLoop { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let mut result; loop { result = self.body().run(context)?; diff --git a/boa/src/syntax/ast/node/iteration/for_in_loop/mod.rs b/boa/src/syntax/ast/node/iteration/for_in_loop/mod.rs index 2b800e7ce07..0b0a7944812 100644 --- a/boa/src/syntax/ast/node/iteration/for_in_loop/mod.rs +++ b/boa/src/syntax/ast/node/iteration/for_in_loop/mod.rs @@ -7,7 +7,7 @@ use crate::{ exec::{Executable, InterpreterState}, gc::{Finalize, Trace}, syntax::ast::node::{Declaration, Node}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -80,7 +80,7 @@ impl From for Node { } impl Executable for ForInLoop { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("ForIn", "exec"); let object = self.expr().run(context)?; let mut result = JsValue::undefined(); diff --git a/boa/src/syntax/ast/node/iteration/for_loop/mod.rs b/boa/src/syntax/ast/node/iteration/for_loop/mod.rs index 4788363d8ab..47b90acaba8 100644 --- a/boa/src/syntax/ast/node/iteration/for_loop/mod.rs +++ b/boa/src/syntax/ast/node/iteration/for_loop/mod.rs @@ -3,7 +3,7 @@ use crate::{ exec::{Executable, InterpreterState}, gc::{Finalize, Trace}, syntax::ast::node::Node, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -98,7 +98,7 @@ impl ForLoop { } impl Executable for ForLoop { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { // Create the block environment. let _timer = BoaProfiler::global().start_event("ForLoop", "exec"); { diff --git a/boa/src/syntax/ast/node/iteration/for_of_loop/mod.rs b/boa/src/syntax/ast/node/iteration/for_of_loop/mod.rs index 5552fc81f2d..5c8e3e9395e 100644 --- a/boa/src/syntax/ast/node/iteration/for_of_loop/mod.rs +++ b/boa/src/syntax/ast/node/iteration/for_of_loop/mod.rs @@ -7,7 +7,7 @@ use crate::{ exec::{Executable, InterpreterState}, gc::{Finalize, Trace}, syntax::ast::node::{Declaration, Node}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -80,7 +80,7 @@ impl From for Node { } impl Executable for ForOfLoop { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("ForOf", "exec"); let iterable = self.iterable().run(context)?; let iterator = get_iterator(context, iterable)?; diff --git a/boa/src/syntax/ast/node/iteration/while_loop/mod.rs b/boa/src/syntax/ast/node/iteration/while_loop/mod.rs index 00b076a0838..0438c2f6347 100644 --- a/boa/src/syntax/ast/node/iteration/while_loop/mod.rs +++ b/boa/src/syntax/ast/node/iteration/while_loop/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::{Executable, InterpreterState}, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -72,7 +72,7 @@ impl WhileLoop { } impl Executable for WhileLoop { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let mut result = JsValue::undefined(); while self.cond().run(context)?.to_boolean() { result = self.body().run(context)?; diff --git a/boa/src/syntax/ast/node/mod.rs b/boa/src/syntax/ast/node/mod.rs index 1745bdee4fd..f4ce62a70b1 100644 --- a/boa/src/syntax/ast/node/mod.rs +++ b/boa/src/syntax/ast/node/mod.rs @@ -50,7 +50,7 @@ use super::Const; use crate::{ exec::Executable, gc::{empty_trace, Finalize, Trace}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::{ cmp::Ordering, @@ -307,7 +307,7 @@ impl Node { } impl Executable for Node { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("Executable", "exec"); match *self { Node::AsyncFunctionDecl(ref decl) => decl.run(context), diff --git a/boa/src/syntax/ast/node/new/mod.rs b/boa/src/syntax/ast/node/new/mod.rs index c409e38692d..897a3442df7 100644 --- a/boa/src/syntax/ast/node/new/mod.rs +++ b/boa/src/syntax/ast/node/new/mod.rs @@ -4,7 +4,7 @@ use crate::{ gc::{Finalize, Trace}, syntax::ast::node::{Call, Node}, value::JsValue, - BoaProfiler, Context, Result, + BoaProfiler, Context, JsResult, }; use std::fmt; @@ -48,7 +48,7 @@ impl New { } impl Executable for New { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("New", "exec"); let func_object = self.expr().run(context)?; diff --git a/boa/src/syntax/ast/node/object/mod.rs b/boa/src/syntax/ast/node/object/mod.rs index 8a060fd71b5..e7cb47f3a33 100644 --- a/boa/src/syntax/ast/node/object/mod.rs +++ b/boa/src/syntax/ast/node/object/mod.rs @@ -5,7 +5,7 @@ use crate::{ gc::{Finalize, Trace}, property::PropertyDescriptor, syntax::ast::node::{join_nodes, MethodDefinitionKind, Node, PropertyDefinition}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -87,7 +87,7 @@ impl Object { } impl Executable for Object { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("object", "exec"); let obj = JsValue::new_object(context); diff --git a/boa/src/syntax/ast/node/operator/assign/mod.rs b/boa/src/syntax/ast/node/operator/assign/mod.rs index 17e06e9cc6b..0f993de17e0 100644 --- a/boa/src/syntax/ast/node/operator/assign/mod.rs +++ b/boa/src/syntax/ast/node/operator/assign/mod.rs @@ -3,7 +3,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::Node, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -53,7 +53,7 @@ impl Assign { } impl Executable for Assign { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("Assign", "exec"); let val = self.rhs().run(context)?; match self.lhs() { diff --git a/boa/src/syntax/ast/node/operator/bin_op/mod.rs b/boa/src/syntax/ast/node/operator/bin_op/mod.rs index 144b0e997e5..42888e6e22b 100644 --- a/boa/src/syntax/ast/node/operator/bin_op/mod.rs +++ b/boa/src/syntax/ast/node/operator/bin_op/mod.rs @@ -6,7 +6,7 @@ use crate::{ node::Node, op::{self, AssignOp, BitOp, CompOp, LogOp, NumOp}, }, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -58,7 +58,7 @@ impl BinOp { } /// Runs the assignment operators. - fn run_assign(op: AssignOp, x: JsValue, y: &Node, context: &mut Context) -> Result { + fn run_assign(op: AssignOp, x: JsValue, y: &Node, context: &mut Context) -> JsResult { match op { AssignOp::Add => x.add(&y.run(context)?, context), AssignOp::Sub => x.sub(&y.run(context)?, context), @@ -98,7 +98,7 @@ impl BinOp { } impl Executable for BinOp { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { match self.op() { op::BinOp::Num(op) => { let x = self.lhs().run(context)?; diff --git a/boa/src/syntax/ast/node/operator/unary_op/mod.rs b/boa/src/syntax/ast/node/operator/unary_op/mod.rs index 26f75e89ab9..38e1db961ae 100644 --- a/boa/src/syntax/ast/node/operator/unary_op/mod.rs +++ b/boa/src/syntax/ast/node/operator/unary_op/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::{node::Node, op}, - Context, JsBigInt, JsValue, Result, + Context, JsBigInt, JsResult, JsValue, }; use std::fmt; @@ -50,7 +50,7 @@ impl UnaryOp { } impl Executable for UnaryOp { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { Ok(match self.op() { op::UnaryOp::Minus => self.target().run(context)?.neg(context)?, op::UnaryOp::Plus => JsValue::new(self.target().run(context)?.to_number(context)?), diff --git a/boa/src/syntax/ast/node/return_smt/mod.rs b/boa/src/syntax/ast/node/return_smt/mod.rs index fff1ddb1a7d..dc1dd95ad9f 100644 --- a/boa/src/syntax/ast/node/return_smt/mod.rs +++ b/boa/src/syntax/ast/node/return_smt/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::{Executable, InterpreterState}, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -61,7 +61,7 @@ impl Return { } impl Executable for Return { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let result = match self.expr() { Some(v) => v.run(context), None => Ok(JsValue::undefined()), diff --git a/boa/src/syntax/ast/node/spread/mod.rs b/boa/src/syntax/ast/node/spread/mod.rs index ae4de96bfb9..2c3d26dac43 100644 --- a/boa/src/syntax/ast/node/spread/mod.rs +++ b/boa/src/syntax/ast/node/spread/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -52,7 +52,7 @@ impl Spread { } impl Executable for Spread { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { // TODO: for now we can do nothing but return the value as-is self.val().run(context) } diff --git a/boa/src/syntax/ast/node/statement_list/mod.rs b/boa/src/syntax/ast/node/statement_list/mod.rs index 1cd8cc5416d..a6d70f85db5 100644 --- a/boa/src/syntax/ast/node/statement_list/mod.rs +++ b/boa/src/syntax/ast/node/statement_list/mod.rs @@ -4,7 +4,7 @@ use crate::{ exec::{Executable, InterpreterState}, gc::{empty_trace, Finalize, Trace}, syntax::ast::node::{Declaration, Node}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::{collections::HashSet, fmt, ops::Deref, rc::Rc}; @@ -112,7 +112,7 @@ impl StatementList { } impl Executable for StatementList { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("StatementList", "exec"); // https://tc39.es/ecma262/#sec-block-runtime-semantics-evaluation diff --git a/boa/src/syntax/ast/node/switch/mod.rs b/boa/src/syntax/ast/node/switch/mod.rs index 3fe3c0ec83e..d7b9df61f0f 100644 --- a/boa/src/syntax/ast/node/switch/mod.rs +++ b/boa/src/syntax/ast/node/switch/mod.rs @@ -4,7 +4,7 @@ use crate::{ exec::{Executable, InterpreterState}, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -123,7 +123,7 @@ impl Switch { } impl Executable for Switch { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let val = self.val().run(context)?; let mut result = JsValue::null(); let mut matched = false; diff --git a/boa/src/syntax/ast/node/template/mod.rs b/boa/src/syntax/ast/node/template/mod.rs index 633a0822c01..7daf0200bae 100644 --- a/boa/src/syntax/ast/node/template/mod.rs +++ b/boa/src/syntax/ast/node/template/mod.rs @@ -1,7 +1,7 @@ //! Template literal node. use super::Node; -use crate::{builtins::Array, exec::Executable, BoaProfiler, Context, JsValue, Result}; +use crate::{builtins::Array, exec::Executable, BoaProfiler, Context, JsResult, JsValue}; use gc::{Finalize, Trace}; #[cfg(feature = "deser")] @@ -32,7 +32,7 @@ impl TemplateLit { } impl Executable for TemplateLit { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("TemplateLiteral", "exec"); let mut result = String::new(); @@ -90,7 +90,7 @@ impl TaggedTemplate { } impl Executable for TaggedTemplate { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("TaggedTemplate", "exec"); let template_object = Array::new_array(context); diff --git a/boa/src/syntax/ast/node/throw/mod.rs b/boa/src/syntax/ast/node/throw/mod.rs index 248844f0672..d28a99b3d31 100644 --- a/boa/src/syntax/ast/node/throw/mod.rs +++ b/boa/src/syntax/ast/node/throw/mod.rs @@ -2,7 +2,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::Node, - Context, JsValue, Result, + Context, JsResult, JsValue, }; use std::fmt; @@ -50,7 +50,7 @@ impl Throw { impl Executable for Throw { #[inline] - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { Err(self.expr().run(context)?) } } diff --git a/boa/src/syntax/ast/node/try_node/mod.rs b/boa/src/syntax/ast/node/try_node/mod.rs index 45b817772b5..0bb5486a4a3 100644 --- a/boa/src/syntax/ast/node/try_node/mod.rs +++ b/boa/src/syntax/ast/node/try_node/mod.rs @@ -6,7 +6,7 @@ use crate::{ exec::Executable, gc::{Finalize, Trace}, syntax::ast::node::{Block, Identifier, Node}, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; use std::fmt; @@ -95,7 +95,7 @@ impl Try { } impl Executable for Try { - fn run(&self, context: &mut Context) -> Result { + fn run(&self, context: &mut Context) -> JsResult { let _timer = BoaProfiler::global().start_event("Try", "exec"); let res = self.block().run(context).map_or_else( |err| { diff --git a/boa/src/value/equality.rs b/boa/src/value/equality.rs index 6903bdea125..a31337a9fbb 100644 --- a/boa/src/value/equality.rs +++ b/boa/src/value/equality.rs @@ -37,7 +37,7 @@ impl JsValue { /// This method is executed when doing abstract equality comparisons with the `==` operator. /// For more information, check #[allow(clippy::float_cmp)] - pub fn equals(&self, other: &Self, context: &mut Context) -> Result { + pub fn equals(&self, other: &Self, context: &mut Context) -> JsResult { // 1. If Type(x) is the same as Type(y), then // a. Return the result of performing Strict Equality Comparison x === y. if self.get_type() == other.get_type() { diff --git a/boa/src/value/mod.rs b/boa/src/value/mod.rs index 0e6f4308a0e..89a97900f68 100644 --- a/boa/src/value/mod.rs +++ b/boa/src/value/mod.rs @@ -14,7 +14,7 @@ use crate::{ object::{GcObject, Object, ObjectData}, property::{PropertyDescriptor, PropertyKey}, symbol::{JsSymbol, WellKnownSymbols}, - BoaProfiler, Context, JsBigInt, JsString, Result, + BoaProfiler, Context, JsBigInt, JsResult, JsString, }; use gc::{Finalize, Trace}; use serde_json::{Number as JSONNumber, Value as JSONValue}; @@ -174,7 +174,7 @@ impl JsValue { } /// Converts the `JsValue` to `JSON`. - pub fn to_json(&self, context: &mut Context) -> Result> { + pub fn to_json(&self, context: &mut Context) -> JsResult> { let to_json = self.get_field("toJSON", context)?; if to_json.is_function() { let json_value = context.call(&to_json, self, &[])?; @@ -405,7 +405,7 @@ impl JsValue { /// Resolve the property in the object and get its value, or undefined if this is not an object or the field doesn't exist /// get_field receives a Property from get_prop(). It should then return the `[[Get]]` result value if that's set, otherwise fall back to `[[Value]]` - pub(crate) fn get_field(&self, key: K, context: &mut Context) -> Result + pub(crate) fn get_field(&self, key: K, context: &mut Context) -> JsResult where K: Into, { @@ -445,7 +445,7 @@ impl JsValue { value: V, throw: bool, context: &mut Context, - ) -> Result + ) -> JsResult where K: Into, V: Into, @@ -503,7 +503,7 @@ impl JsValue { &self, context: &mut Context, preferred_type: PreferredType, - ) -> Result { + ) -> JsResult { // 1. Assert: input is an ECMAScript language value. (always a value not need to check) // 2. If Type(input) is Object, then if let JsValue::Object(obj) = self { @@ -541,7 +541,7 @@ impl JsValue { /// Converts the value to a `BigInt`. /// /// This function is equivelent to `BigInt(value)` in JavaScript. - pub fn to_bigint(&self, context: &mut Context) -> Result { + pub fn to_bigint(&self, context: &mut Context) -> JsResult { match self { JsValue::Null => Err(context.construct_type_error("cannot convert null to a BigInt")), JsValue::Undefined => { @@ -599,7 +599,7 @@ impl JsValue { /// Converts the value to a string. /// /// This function is equivalent to `String(value)` in JavaScript. - pub fn to_string(&self, context: &mut Context) -> Result { + pub fn to_string(&self, context: &mut Context) -> JsResult { match self { JsValue::Null => Ok("null".into()), JsValue::Undefined => Ok("undefined".into()), @@ -623,7 +623,7 @@ impl JsValue { /// This function is equivalent to `Object(value)` in JavaScript /// /// See: - pub fn to_object(&self, context: &mut Context) -> Result { + pub fn to_object(&self, context: &mut Context) -> JsResult { match self { JsValue::Undefined | JsValue::Null => { Err(context.construct_type_error("cannot convert 'null' or 'undefined' to object")) @@ -688,7 +688,7 @@ impl JsValue { /// Converts the value to a `PropertyKey`, that can be used as a key for properties. /// /// See - pub fn to_property_key(&self, context: &mut Context) -> Result { + pub fn to_property_key(&self, context: &mut Context) -> JsResult { Ok(match self { // Fast path: JsValue::String(string) => string.clone().into(), @@ -705,7 +705,7 @@ impl JsValue { /// It returns value converted to a numeric value of type `Number` or `BigInt`. /// /// See: - pub fn to_numeric(&self, context: &mut Context) -> Result { + pub fn to_numeric(&self, context: &mut Context) -> JsResult { let primitive = self.to_primitive(context, PreferredType::Number)?; if let Some(bigint) = primitive.as_bigint() { return Ok(bigint.clone().into()); @@ -718,7 +718,7 @@ impl JsValue { /// This function is equivalent to `value | 0` in JavaScript /// /// See: - pub fn to_u32(&self, context: &mut Context) -> Result { + pub fn to_u32(&self, context: &mut Context) -> JsResult { // This is the fast path, if the value is Integer we can just return it. if let JsValue::Integer(number) = *self { return Ok(number as u32); @@ -731,7 +731,7 @@ impl JsValue { /// Converts a value to an integral 32 bit signed integer. /// /// See: - pub fn to_i32(&self, context: &mut Context) -> Result { + pub fn to_i32(&self, context: &mut Context) -> JsResult { // This is the fast path, if the value is Integer we can just return it. if let JsValue::Integer(number) = *self { return Ok(number); @@ -744,7 +744,7 @@ impl JsValue { /// Converts a value to a non-negative integer if it is a valid integer index value. /// /// See: - pub fn to_index(&self, context: &mut Context) -> Result { + pub fn to_index(&self, context: &mut Context) -> JsResult { if self.is_undefined() { return Ok(0); } @@ -767,7 +767,7 @@ impl JsValue { /// Converts argument to an integer suitable for use as the length of an array-like object. /// /// See: - pub fn to_length(&self, context: &mut Context) -> Result { + pub fn to_length(&self, context: &mut Context) -> JsResult { // 1. Let len be ? ToInteger(argument). let len = self.to_integer(context)?; @@ -783,7 +783,7 @@ impl JsValue { /// Converts a value to an integral Number value. /// /// See: - pub fn to_integer(&self, context: &mut Context) -> Result { + pub fn to_integer(&self, context: &mut Context) -> JsResult { // 1. Let number be ? ToNumber(argument). let number = self.to_number(context)?; @@ -807,7 +807,7 @@ impl JsValue { /// This function is equivalent to the unary `+` operator (`+value`) in JavaScript /// /// See: - pub fn to_number(&self, context: &mut Context) -> Result { + pub fn to_number(&self, context: &mut Context) -> JsResult { match *self { JsValue::Null => Ok(0.0), JsValue::Undefined => Ok(f64::NAN), @@ -856,7 +856,7 @@ impl JsValue { /// This function is equivalent to `Number(value)` in JavaScript /// /// See: - pub fn to_numeric_number(&self, context: &mut Context) -> Result { + pub fn to_numeric_number(&self, context: &mut Context) -> JsResult { let primitive = self.to_primitive(context, PreferredType::Number)?; if let Some(bigint) = primitive.as_bigint() { return Ok(bigint.to_f64()); @@ -876,7 +876,7 @@ impl JsValue { /// [table]: https://tc39.es/ecma262/#table-14 /// [spec]: https://tc39.es/ecma262/#sec-requireobjectcoercible #[inline] - pub fn require_object_coercible(&self, context: &mut Context) -> Result<&JsValue> { + pub fn require_object_coercible(&self, context: &mut Context) -> JsResult<&JsValue> { if self.is_null_or_undefined() { Err(context.construct_type_error("cannot convert null or undefined to Object")) } else { @@ -885,7 +885,7 @@ impl JsValue { } #[inline] - pub fn to_property_descriptor(&self, context: &mut Context) -> Result { + pub fn to_property_descriptor(&self, context: &mut Context) -> JsResult { // 1. If Type(Obj) is not Object, throw a TypeError exception. match self { JsValue::Object(ref obj) => obj.to_property_descriptor(context), @@ -897,7 +897,7 @@ impl JsValue { /// Converts argument to an integer, +โˆž, or -โˆž. /// /// See: - pub fn to_integer_or_infinity(&self, context: &mut Context) -> Result { + pub fn to_integer_or_infinity(&self, context: &mut Context) -> JsResult { // 1. Let number be ? ToNumber(argument). let number = self.to_number(context)?; @@ -958,7 +958,7 @@ impl JsValue { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-isarray - pub(crate) fn is_array(&self, _context: &mut Context) -> Result { + pub(crate) fn is_array(&self, _context: &mut Context) -> JsResult { // 1. If Type(argument) is not Object, return false. if let Some(object) = self.as_object() { // 2. If argument is an Array exotic object, return true. diff --git a/boa/src/value/operations.rs b/boa/src/value/operations.rs index 072ab7fe837..f0ddec27e73 100644 --- a/boa/src/value/operations.rs +++ b/boa/src/value/operations.rs @@ -3,7 +3,7 @@ use crate::builtins::number::{f64_to_int32, f64_to_uint32, Number}; impl JsValue { #[inline] - pub fn add(&self, other: &Self, context: &mut Context) -> Result { + pub fn add(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new(f64::from(*x) + f64::from(*y)), @@ -43,7 +43,7 @@ impl JsValue { } #[inline] - pub fn sub(&self, other: &Self, context: &mut Context) -> Result { + pub fn sub(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new(f64::from(*x) - f64::from(*y)), @@ -67,7 +67,7 @@ impl JsValue { } #[inline] - pub fn mul(&self, other: &Self, context: &mut Context) -> Result { + pub fn mul(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new(f64::from(*x) * f64::from(*y)), @@ -91,7 +91,7 @@ impl JsValue { } #[inline] - pub fn div(&self, other: &Self, context: &mut Context) -> Result { + pub fn div(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new(f64::from(*x) / f64::from(*y)), @@ -125,7 +125,7 @@ impl JsValue { } #[inline] - pub fn rem(&self, other: &Self, context: &mut Context) -> Result { + pub fn rem(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => { @@ -165,7 +165,7 @@ impl JsValue { } #[inline] - pub fn pow(&self, other: &Self, context: &mut Context) -> Result { + pub fn pow(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new(f64::from(*x).powi(*y)), @@ -191,7 +191,7 @@ impl JsValue { } #[inline] - pub fn bitand(&self, other: &Self, context: &mut Context) -> Result { + pub fn bitand(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new(x & y), @@ -221,7 +221,7 @@ impl JsValue { } #[inline] - pub fn bitor(&self, other: &Self, context: &mut Context) -> Result { + pub fn bitor(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new(x | y), @@ -251,7 +251,7 @@ impl JsValue { } #[inline] - pub fn bitxor(&self, other: &Self, context: &mut Context) -> Result { + pub fn bitxor(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new(x ^ y), @@ -281,7 +281,7 @@ impl JsValue { } #[inline] - pub fn shl(&self, other: &Self, context: &mut Context) -> Result { + pub fn shl(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new(x.wrapping_shl(*y as u32)), @@ -315,7 +315,7 @@ impl JsValue { } #[inline] - pub fn shr(&self, other: &Self, context: &mut Context) -> Result { + pub fn shr(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new(x.wrapping_shr(*y as u32)), @@ -349,7 +349,7 @@ impl JsValue { } #[inline] - pub fn ushr(&self, other: &Self, context: &mut Context) -> Result { + pub fn ushr(&self, other: &Self, context: &mut Context) -> JsResult { Ok(match (self, other) { // Fast path: (Self::Integer(x), Self::Integer(y)) => Self::new((*x as u32).wrapping_shr(*y as u32)), @@ -382,7 +382,7 @@ impl JsValue { } #[inline] - pub fn neg(&self, context: &mut Context) -> Result { + pub fn neg(&self, context: &mut Context) -> JsResult { Ok(match *self { Self::Symbol(_) | Self::Undefined => Self::new(f64::NAN), Self::Object(_) => Self::new(match self.to_numeric_number(context) { @@ -402,7 +402,7 @@ impl JsValue { } #[inline] - pub fn not(&self, _: &mut Context) -> Result { + pub fn not(&self, _: &mut Context) -> JsResult { Ok(!self.to_boolean()) } @@ -428,7 +428,7 @@ impl JsValue { other: &Self, left_first: bool, context: &mut Context, - ) -> Result { + ) -> JsResult { Ok(match (self, other) { // Fast path (for some common operations): (Self::Integer(x), Self::Integer(y)) => (x < y).into(), @@ -526,7 +526,7 @@ impl JsValue { /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than /// [spec]: https://tc39.es/ecma262/#sec-relational-operators-runtime-semantics-evaluation #[inline] - pub fn lt(&self, other: &Self, context: &mut Context) -> Result { + pub fn lt(&self, other: &Self, context: &mut Context) -> JsResult { match self.abstract_relation(other, true, context)? { AbstractRelation::True => Ok(true), AbstractRelation::False | AbstractRelation::Undefined => Ok(false), @@ -543,7 +543,7 @@ impl JsValue { /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than_or_equal /// [spec]: https://tc39.es/ecma262/#sec-relational-operators-runtime-semantics-evaluation #[inline] - pub fn le(&self, other: &Self, context: &mut Context) -> Result { + pub fn le(&self, other: &Self, context: &mut Context) -> JsResult { match other.abstract_relation(self, false, context)? { AbstractRelation::False => Ok(true), AbstractRelation::True | AbstractRelation::Undefined => Ok(false), @@ -560,7 +560,7 @@ impl JsValue { /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than /// [spec]: https://tc39.es/ecma262/#sec-relational-operators-runtime-semantics-evaluation #[inline] - pub fn gt(&self, other: &Self, context: &mut Context) -> Result { + pub fn gt(&self, other: &Self, context: &mut Context) -> JsResult { match other.abstract_relation(self, false, context)? { AbstractRelation::True => Ok(true), AbstractRelation::False | AbstractRelation::Undefined => Ok(false), @@ -577,7 +577,7 @@ impl JsValue { /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than_or_equal /// [spec]: https://tc39.es/ecma262/#sec-relational-operators-runtime-semantics-evaluation #[inline] - pub fn ge(&self, other: &Self, context: &mut Context) -> Result { + pub fn ge(&self, other: &Self, context: &mut Context) -> JsResult { match self.abstract_relation(other, true, context)? { AbstractRelation::False => Ok(true), AbstractRelation::True | AbstractRelation::Undefined => Ok(false), diff --git a/boa/src/vm/mod.rs b/boa/src/vm/mod.rs index 9809f3fcbd9..b0dfd140761 100644 --- a/boa/src/vm/mod.rs +++ b/boa/src/vm/mod.rs @@ -4,7 +4,7 @@ use crate::{ builtins::Array, environment::lexical_environment::VariableScope, symbol::WellKnownSymbols, - BoaProfiler, Context, JsValue, Result, + BoaProfiler, Context, JsResult, JsValue, }; mod code_block; @@ -70,7 +70,7 @@ impl<'a> Vm<'a> { value } - fn execute_instruction(&mut self) -> Result<()> { + fn execute_instruction(&mut self) -> JsResult<()> { let _timer = BoaProfiler::global().start_event("execute_instruction", "vm"); macro_rules! bin_op { @@ -445,7 +445,7 @@ impl<'a> Vm<'a> { Ok(()) } - pub fn run(&mut self) -> Result { + pub fn run(&mut self) -> JsResult { let _timer = BoaProfiler::global().start_event("run", "vm"); const COLUMN_WIDTH: usize = 24; diff --git a/boa_tester/src/exec/js262.rs b/boa_tester/src/exec/js262.rs index a892469a86f..53c9e14def7 100644 --- a/boa_tester/src/exec/js262.rs +++ b/boa_tester/src/exec/js262.rs @@ -2,7 +2,7 @@ use boa::{ exec::Executable, object::{GcObject, ObjectInitializer}, property::Attribute, - Context, JsValue, Result, + Context, JsResult, JsValue, }; /// Initializes the object in the context. @@ -25,7 +25,7 @@ pub(super) fn init(context: &mut Context) -> GcObject { /// /// Creates a new ECMAScript Realm, defines this API on the new realm's global object, and /// returns the `$262` property of the new realm's global object. -fn create_realm(_this: &JsValue, _: &[JsValue], _context: &mut Context) -> Result { +fn create_realm(_this: &JsValue, _: &[JsValue], _context: &mut Context) -> JsResult { // eprintln!("called $262.createRealm()"); let mut context = Context::new(); @@ -40,14 +40,18 @@ fn create_realm(_this: &JsValue, _: &[JsValue], _context: &mut Context) -> Resul /// /// Implements the `DetachArrayBuffer` abstract operation. #[allow(dead_code)] -fn detach_array_buffer(_this: &JsValue, _: &[JsValue], _context: &mut Context) -> Result { +fn detach_array_buffer( + _this: &JsValue, + _: &[JsValue], + _context: &mut Context, +) -> JsResult { todo!() } /// The `$262.evalScript()` function. /// /// Accepts a string value as its first argument and executes it as an ECMAScript script. -fn eval_script(_this: &JsValue, args: &[JsValue], context: &mut Context) -> Result { +fn eval_script(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // eprintln!("called $262.evalScript()"); if let Some(source_text) = args.get(0).and_then(|val| val.as_string()) { @@ -67,6 +71,6 @@ fn eval_script(_this: &JsValue, args: &[JsValue], context: &mut Context) -> Resu /// Must throw an exception if no capability exists. This is necessary for testing the /// semantics of any feature that relies on garbage collection, e.g. the `WeakRef` API. #[allow(dead_code)] -fn gc(_this: &JsValue, _: &[JsValue], _context: &mut Context) -> Result { +fn gc(_this: &JsValue, _: &[JsValue], _context: &mut Context) -> JsResult { todo!() } diff --git a/boa_tester/src/exec/mod.rs b/boa_tester/src/exec/mod.rs index 8e77b42b757..8ee29a790a6 100644 --- a/boa_tester/src/exec/mod.rs +++ b/boa_tester/src/exec/mod.rs @@ -312,6 +312,6 @@ impl Test { } /// `print()` function required by the test262 suite. -fn test262_print(_this: &JsValue, _: &[JsValue], _context: &mut Context) -> boa::Result { +fn test262_print(_this: &JsValue, _: &[JsValue], _context: &mut Context) -> boa::JsResult { todo!("print() function"); }