From 91d9100ad97fbd59834b45f7d7c6ad9ea55ce54b Mon Sep 17 00:00:00 2001 From: 54k1 <59379616+54k1@users.noreply.github.com> Date: Sun, 9 Aug 2020 10:32:48 +0530 Subject: [PATCH] Set __proto__ of function instances (#604) --- boa/src/builtins/array/mod.rs | 58 +++++++++++++--------- boa/src/builtins/bigint/mod.rs | 8 +-- boa/src/builtins/boolean/mod.rs | 4 +- boa/src/builtins/console/mod.rs | 38 +++++++------- boa/src/builtins/error/mod.rs | 2 +- boa/src/builtins/error/range.rs | 2 +- boa/src/builtins/error/reference.rs | 2 +- boa/src/builtins/error/syntax.rs | 2 +- boa/src/builtins/error/type.rs | 2 +- boa/src/builtins/function/mod.rs | 19 +++++-- boa/src/builtins/json/mod.rs | 4 +- boa/src/builtins/map/mod.rs | 12 ++--- boa/src/builtins/math/mod.rs | 77 +++++++++++++++-------------- boa/src/builtins/number/mod.rs | 71 ++++++++++++++++++++------ boa/src/builtins/object/mod.rs | 21 +++++--- boa/src/builtins/regexp/mod.rs | 6 +-- boa/src/builtins/string/mod.rs | 69 ++++++++++++++++---------- boa/src/builtins/symbol/mod.rs | 2 +- 18 files changed, 246 insertions(+), 153 deletions(-) diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index abb5512ec2..6976a17b9d 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -1124,28 +1124,40 @@ impl Array { prototype.set_property("length", length); - make_builtin_fn(Self::concat, "concat", &prototype, 1); - make_builtin_fn(Self::push, "push", &prototype, 1); - make_builtin_fn(Self::index_of, "indexOf", &prototype, 1); - make_builtin_fn(Self::last_index_of, "lastIndexOf", &prototype, 1); - make_builtin_fn(Self::includes_value, "includes", &prototype, 1); - make_builtin_fn(Self::map, "map", &prototype, 1); - make_builtin_fn(Self::fill, "fill", &prototype, 1); - make_builtin_fn(Self::for_each, "forEach", &prototype, 1); - make_builtin_fn(Self::filter, "filter", &prototype, 1); - make_builtin_fn(Self::pop, "pop", &prototype, 0); - make_builtin_fn(Self::join, "join", &prototype, 1); - make_builtin_fn(Self::to_string, "toString", &prototype, 0); - make_builtin_fn(Self::reverse, "reverse", &prototype, 0); - make_builtin_fn(Self::shift, "shift", &prototype, 0); - make_builtin_fn(Self::unshift, "unshift", &prototype, 1); - make_builtin_fn(Self::every, "every", &prototype, 1); - make_builtin_fn(Self::find, "find", &prototype, 1); - make_builtin_fn(Self::find_index, "findIndex", &prototype, 1); - make_builtin_fn(Self::slice, "slice", &prototype, 2); - make_builtin_fn(Self::some, "some", &prototype, 2); - make_builtin_fn(Self::reduce, "reduce", &prototype, 2); - make_builtin_fn(Self::reduce_right, "reduceRight", &prototype, 2); + make_builtin_fn(Self::concat, "concat", &prototype, 1, interpreter); + make_builtin_fn(Self::push, "push", &prototype, 1, interpreter); + make_builtin_fn(Self::index_of, "indexOf", &prototype, 1, interpreter); + make_builtin_fn( + Self::last_index_of, + "lastIndexOf", + &prototype, + 1, + interpreter, + ); + make_builtin_fn(Self::includes_value, "includes", &prototype, 1, interpreter); + make_builtin_fn(Self::map, "map", &prototype, 1, interpreter); + make_builtin_fn(Self::fill, "fill", &prototype, 1, interpreter); + make_builtin_fn(Self::for_each, "forEach", &prototype, 1, interpreter); + make_builtin_fn(Self::filter, "filter", &prototype, 1, interpreter); + make_builtin_fn(Self::pop, "pop", &prototype, 0, interpreter); + make_builtin_fn(Self::join, "join", &prototype, 1, interpreter); + make_builtin_fn(Self::to_string, "toString", &prototype, 0, interpreter); + make_builtin_fn(Self::reverse, "reverse", &prototype, 0, interpreter); + make_builtin_fn(Self::shift, "shift", &prototype, 0, interpreter); + make_builtin_fn(Self::unshift, "unshift", &prototype, 1, interpreter); + make_builtin_fn(Self::every, "every", &prototype, 1, interpreter); + make_builtin_fn(Self::find, "find", &prototype, 1, interpreter); + make_builtin_fn(Self::find_index, "findIndex", &prototype, 1, interpreter); + make_builtin_fn(Self::slice, "slice", &prototype, 2, interpreter); + make_builtin_fn(Self::some, "some", &prototype, 2, interpreter); + make_builtin_fn(Self::reduce, "reduce", &prototype, 2, interpreter); + make_builtin_fn( + Self::reduce_right, + "reduceRight", + &prototype, + 2, + interpreter, + ); let array = make_constructor_fn( Self::NAME, @@ -1158,7 +1170,7 @@ impl Array { ); // Static Methods - make_builtin_fn(Self::is_array, "isArray", &array, 1); + make_builtin_fn(Self::is_array, "isArray", &array, 1, interpreter); (Self::NAME, array) } diff --git a/boa/src/builtins/bigint/mod.rs b/boa/src/builtins/bigint/mod.rs index aac4b68ff4..45a82a1a71 100644 --- a/boa/src/builtins/bigint/mod.rs +++ b/boa/src/builtins/bigint/mod.rs @@ -206,8 +206,8 @@ impl BigInt { let prototype = Value::new_object(Some(global)); - make_builtin_fn(Self::to_string, "toString", &prototype, 1); - make_builtin_fn(Self::value_of, "valueOf", &prototype, 0); + make_builtin_fn(Self::to_string, "toString", &prototype, 1, interpreter); + make_builtin_fn(Self::value_of, "valueOf", &prototype, 0, interpreter); let bigint_object = make_constructor_fn( Self::NAME, @@ -219,8 +219,8 @@ impl BigInt { true, ); - make_builtin_fn(Self::as_int_n, "asIntN", &bigint_object, 2); - make_builtin_fn(Self::as_uint_n, "asUintN", &bigint_object, 2); + make_builtin_fn(Self::as_int_n, "asIntN", &bigint_object, 2, interpreter); + make_builtin_fn(Self::as_uint_n, "asUintN", &bigint_object, 2, interpreter); (Self::NAME, bigint_object) } diff --git a/boa/src/builtins/boolean/mod.rs b/boa/src/builtins/boolean/mod.rs index 1698f33c16..f29d6f4726 100644 --- a/boa/src/builtins/boolean/mod.rs +++ b/boa/src/builtins/boolean/mod.rs @@ -106,8 +106,8 @@ impl Boolean { // https://tc39.es/ecma262/#sec-properties-of-the-boolean-prototype-object let prototype = Value::new_object(Some(global)); - make_builtin_fn(Self::to_string, "toString", &prototype, 0); - make_builtin_fn(Self::value_of, "valueOf", &prototype, 0); + make_builtin_fn(Self::to_string, "toString", &prototype, 0, interpreter); + make_builtin_fn(Self::value_of, "valueOf", &prototype, 0, interpreter); let boolean_object = make_constructor_fn( Self::NAME, diff --git a/boa/src/builtins/console/mod.rs b/boa/src/builtins/console/mod.rs index c362e6a6fa..5493571958 100644 --- a/boa/src/builtins/console/mod.rs +++ b/boa/src/builtins/console/mod.rs @@ -495,25 +495,25 @@ impl Console { let console = Value::new_object(Some(global)); - make_builtin_fn(Self::assert, "assert", &console, 0); - make_builtin_fn(Self::clear, "clear", &console, 0); - make_builtin_fn(Self::debug, "debug", &console, 0); - make_builtin_fn(Self::error, "error", &console, 0); - make_builtin_fn(Self::info, "info", &console, 0); - make_builtin_fn(Self::log, "log", &console, 0); - make_builtin_fn(Self::trace, "trace", &console, 0); - make_builtin_fn(Self::warn, "warn", &console, 0); - make_builtin_fn(Self::error, "exception", &console, 0); - make_builtin_fn(Self::count, "count", &console, 0); - make_builtin_fn(Self::count_reset, "countReset", &console, 0); - make_builtin_fn(Self::group, "group", &console, 0); - make_builtin_fn(Self::group, "groupCollapsed", &console, 0); - make_builtin_fn(Self::group_end, "groupEnd", &console, 0); - make_builtin_fn(Self::time, "time", &console, 0); - make_builtin_fn(Self::time_log, "timeLog", &console, 0); - make_builtin_fn(Self::time_end, "timeEnd", &console, 0); - make_builtin_fn(Self::dir, "dir", &console, 0); - make_builtin_fn(Self::dir, "dirxml", &console, 0); + make_builtin_fn(Self::assert, "assert", &console, 0, interpreter); + make_builtin_fn(Self::clear, "clear", &console, 0, interpreter); + make_builtin_fn(Self::debug, "debug", &console, 0, interpreter); + make_builtin_fn(Self::error, "error", &console, 0, interpreter); + make_builtin_fn(Self::info, "info", &console, 0, interpreter); + make_builtin_fn(Self::log, "log", &console, 0, interpreter); + make_builtin_fn(Self::trace, "trace", &console, 0, interpreter); + make_builtin_fn(Self::warn, "warn", &console, 0, interpreter); + make_builtin_fn(Self::error, "exception", &console, 0, interpreter); + make_builtin_fn(Self::count, "count", &console, 0, interpreter); + make_builtin_fn(Self::count_reset, "countReset", &console, 0, interpreter); + make_builtin_fn(Self::group, "group", &console, 0, interpreter); + make_builtin_fn(Self::group, "groupCollapsed", &console, 0, interpreter); + make_builtin_fn(Self::group_end, "groupEnd", &console, 0, interpreter); + make_builtin_fn(Self::time, "time", &console, 0, interpreter); + make_builtin_fn(Self::time_log, "timeLog", &console, 0, interpreter); + make_builtin_fn(Self::time_end, "timeEnd", &console, 0, interpreter); + make_builtin_fn(Self::dir, "dir", &console, 0, interpreter); + make_builtin_fn(Self::dir, "dirxml", &console, 0, interpreter); (Self::NAME, console) } diff --git a/boa/src/builtins/error/mod.rs b/boa/src/builtins/error/mod.rs index 99fc5f7af0..51024a8cc0 100644 --- a/boa/src/builtins/error/mod.rs +++ b/boa/src/builtins/error/mod.rs @@ -84,7 +84,7 @@ impl Error { prototype.set_field("name", Self::NAME); prototype.set_field("message", ""); - make_builtin_fn(Self::to_string, "toString", &prototype, 0); + make_builtin_fn(Self::to_string, "toString", &prototype, 0, interpreter); let error_object = make_constructor_fn( Self::NAME, diff --git a/boa/src/builtins/error/range.rs b/boa/src/builtins/error/range.rs index d4b2ea778f..87c6dc2740 100644 --- a/boa/src/builtins/error/range.rs +++ b/boa/src/builtins/error/range.rs @@ -70,7 +70,7 @@ impl RangeError { prototype.set_field("name", Self::NAME); prototype.set_field("message", ""); - make_builtin_fn(Self::to_string, "toString", &prototype, 0); + make_builtin_fn(Self::to_string, "toString", &prototype, 0, interpreter); let range_error_object = make_constructor_fn( Self::NAME, diff --git a/boa/src/builtins/error/reference.rs b/boa/src/builtins/error/reference.rs index 1636beec4b..baa79d3137 100644 --- a/boa/src/builtins/error/reference.rs +++ b/boa/src/builtins/error/reference.rs @@ -68,7 +68,7 @@ impl ReferenceError { prototype.set_field("name", Self::NAME); prototype.set_field("message", ""); - make_builtin_fn(Self::to_string, "toString", &prototype, 0); + make_builtin_fn(Self::to_string, "toString", &prototype, 0, interpreter); let reference_error_object = make_constructor_fn( Self::NAME, diff --git a/boa/src/builtins/error/syntax.rs b/boa/src/builtins/error/syntax.rs index 07b4497f29..508015770f 100644 --- a/boa/src/builtins/error/syntax.rs +++ b/boa/src/builtins/error/syntax.rs @@ -72,7 +72,7 @@ impl SyntaxError { prototype.set_field("name", Self::NAME); prototype.set_field("message", ""); - make_builtin_fn(Self::to_string, "toString", &prototype, 0); + make_builtin_fn(Self::to_string, "toString", &prototype, 0, interpreter); let syntax_error_object = make_constructor_fn( Self::NAME, diff --git a/boa/src/builtins/error/type.rs b/boa/src/builtins/error/type.rs index 63bec5122b..5e61e91a59 100644 --- a/boa/src/builtins/error/type.rs +++ b/boa/src/builtins/error/type.rs @@ -76,7 +76,7 @@ impl TypeError { prototype.set_field("name", Self::NAME); prototype.set_field("message", ""); - make_builtin_fn(Self::to_string, "toString", &prototype, 0); + make_builtin_fn(Self::to_string, "toString", &prototype, 0, interpreter); let type_error_object = make_constructor_fn( Self::NAME, diff --git a/boa/src/builtins/function/mod.rs b/boa/src/builtins/function/mod.rs index 51d4e3763c..fb701dd6b1 100644 --- a/boa/src/builtins/function/mod.rs +++ b/boa/src/builtins/function/mod.rs @@ -513,15 +513,26 @@ pub fn make_constructor_fn( /// some other number of arguments. /// /// If no length is provided, the length will be set to 0. -pub fn make_builtin_fn(function: NativeFunctionData, name: N, parent: &Value, length: usize) -where +pub fn make_builtin_fn( + function: NativeFunctionData, + name: N, + parent: &Value, + length: usize, + interpreter: &Interpreter, +) where N: Into, { let name = name.into(); let _timer = BoaProfiler::global().start_event(&format!("make_builtin_fn: {}", &name), "init"); - // FIXME: function needs the Function prototype set. - let mut function = Object::function(Function::builtin(Vec::new(), function), Value::null()); + let mut function = Object::function( + Function::builtin(Vec::new(), function), + interpreter + .global() + .get_field("Function") + .get_field("prototype"), + ); + function.insert_field("length", Value::from(length)); parent diff --git a/boa/src/builtins/json/mod.rs b/boa/src/builtins/json/mod.rs index adc570fefd..1393b48385 100644 --- a/boa/src/builtins/json/mod.rs +++ b/boa/src/builtins/json/mod.rs @@ -177,8 +177,8 @@ impl Json { let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let json = Value::new_object(Some(global)); - make_builtin_fn(Self::parse, "parse", &json, 2); - make_builtin_fn(Self::stringify, "stringify", &json, 3); + make_builtin_fn(Self::parse, "parse", &json, 2, interpreter); + make_builtin_fn(Self::stringify, "stringify", &json, 3, interpreter); (Self::NAME, json) } diff --git a/boa/src/builtins/map/mod.rs b/boa/src/builtins/map/mod.rs index 0de4d53619..a6eaaf6033 100644 --- a/boa/src/builtins/map/mod.rs +++ b/boa/src/builtins/map/mod.rs @@ -291,12 +291,12 @@ impl Map { // Create prototype let prototype = Value::new_object(Some(global)); - make_builtin_fn(Self::set, "set", &prototype, 2); - make_builtin_fn(Self::delete, "delete", &prototype, 1); - make_builtin_fn(Self::get, "get", &prototype, 1); - make_builtin_fn(Self::clear, "clear", &prototype, 0); - make_builtin_fn(Self::has, "has", &prototype, 1); - make_builtin_fn(Self::for_each, "forEach", &prototype, 1); + make_builtin_fn(Self::set, "set", &prototype, 2, interpreter); + make_builtin_fn(Self::delete, "delete", &prototype, 1, interpreter); + make_builtin_fn(Self::get, "get", &prototype, 1, interpreter); + make_builtin_fn(Self::clear, "clear", &prototype, 0, interpreter); + make_builtin_fn(Self::has, "has", &prototype, 1, interpreter); + make_builtin_fn(Self::for_each, "forEach", &prototype, 1, interpreter); let map_object = make_constructor_fn( Self::NAME, diff --git a/boa/src/builtins/math/mod.rs b/boa/src/builtins/math/mod.rs index 49189cb1f4..fa8af32ee1 100644 --- a/boa/src/builtins/math/mod.rs +++ b/boa/src/builtins/math/mod.rs @@ -641,7 +641,8 @@ impl Math { } /// Create a new `Math` object - pub(crate) fn create(global: &Value) -> Value { + pub(crate) fn create(interpreter: &mut Interpreter) -> Value { + let global = interpreter.global(); let _timer = BoaProfiler::global().start_event("math:create", "init"); let math = Value::new_object(Some(global)); @@ -656,41 +657,42 @@ impl Math { properties.insert_field("SQRT2", Value::from(f64::consts::SQRT_2)); properties.insert_field("PI", Value::from(f64::consts::PI)); } - make_builtin_fn(Self::abs, "abs", &math, 1); - make_builtin_fn(Self::acos, "acos", &math, 1); - make_builtin_fn(Self::acosh, "acosh", &math, 1); - make_builtin_fn(Self::asin, "asin", &math, 1); - make_builtin_fn(Self::asinh, "asinh", &math, 1); - make_builtin_fn(Self::atan, "atan", &math, 1); - make_builtin_fn(Self::atanh, "atanh", &math, 1); - make_builtin_fn(Self::atan2, "atan2", &math, 2); - make_builtin_fn(Self::cbrt, "cbrt", &math, 1); - make_builtin_fn(Self::ceil, "ceil", &math, 1); - make_builtin_fn(Self::clz32, "clz32", &math, 1); - make_builtin_fn(Self::cos, "cos", &math, 1); - make_builtin_fn(Self::cosh, "cosh", &math, 1); - make_builtin_fn(Self::exp, "exp", &math, 1); - make_builtin_fn(Self::expm1, "expm1", &math, 1); - make_builtin_fn(Self::floor, "floor", &math, 1); - make_builtin_fn(Self::fround, "fround", &math, 1); - make_builtin_fn(Self::hypot, "hypot", &math, 1); - make_builtin_fn(Self::imul, "imul", &math, 1); - make_builtin_fn(Self::log, "log", &math, 1); - make_builtin_fn(Self::log1p, "log1p", &math, 1); - make_builtin_fn(Self::log10, "log10", &math, 1); - make_builtin_fn(Self::log2, "log2", &math, 1); - make_builtin_fn(Self::max, "max", &math, 2); - make_builtin_fn(Self::min, "min", &math, 2); - make_builtin_fn(Self::pow, "pow", &math, 2); - make_builtin_fn(Self::random, "random", &math, 0); - make_builtin_fn(Self::round, "round", &math, 1); - make_builtin_fn(Self::sign, "sign", &math, 1); - make_builtin_fn(Self::sin, "sin", &math, 1); - make_builtin_fn(Self::sinh, "sinh", &math, 1); - make_builtin_fn(Self::sqrt, "sqrt", &math, 1); - make_builtin_fn(Self::tan, "tan", &math, 1); - make_builtin_fn(Self::tanh, "tanh", &math, 1); - make_builtin_fn(Self::trunc, "trunc", &math, 1); + + make_builtin_fn(Self::abs, "abs", &math, 1, interpreter); + make_builtin_fn(Self::acos, "acos", &math, 1, interpreter); + make_builtin_fn(Self::acosh, "acosh", &math, 1, interpreter); + make_builtin_fn(Self::asin, "asin", &math, 1, interpreter); + make_builtin_fn(Self::asinh, "asinh", &math, 1, interpreter); + make_builtin_fn(Self::atan, "atan", &math, 1, interpreter); + make_builtin_fn(Self::atanh, "atanh", &math, 1, interpreter); + make_builtin_fn(Self::atan2, "atan2", &math, 2, interpreter); + make_builtin_fn(Self::cbrt, "cbrt", &math, 1, interpreter); + make_builtin_fn(Self::ceil, "ceil", &math, 1, interpreter); + make_builtin_fn(Self::clz32, "clz32", &math, 1, interpreter); + make_builtin_fn(Self::cos, "cos", &math, 1, interpreter); + make_builtin_fn(Self::cosh, "cosh", &math, 1, interpreter); + make_builtin_fn(Self::exp, "exp", &math, 1, interpreter); + make_builtin_fn(Self::expm1, "expm1", &math, 1, interpreter); + make_builtin_fn(Self::floor, "floor", &math, 1, interpreter); + make_builtin_fn(Self::fround, "fround", &math, 1, interpreter); + make_builtin_fn(Self::hypot, "hypot", &math, 1, interpreter); + make_builtin_fn(Self::imul, "imul", &math, 1, interpreter); + make_builtin_fn(Self::log, "log", &math, 1, interpreter); + make_builtin_fn(Self::log1p, "log1p", &math, 1, interpreter); + make_builtin_fn(Self::log10, "log10", &math, 1, interpreter); + make_builtin_fn(Self::log2, "log2", &math, 1, interpreter); + make_builtin_fn(Self::max, "max", &math, 2, interpreter); + make_builtin_fn(Self::min, "min", &math, 2, interpreter); + make_builtin_fn(Self::pow, "pow", &math, 2, interpreter); + make_builtin_fn(Self::random, "random", &math, 0, interpreter); + make_builtin_fn(Self::round, "round", &math, 1, interpreter); + make_builtin_fn(Self::sign, "sign", &math, 1, interpreter); + make_builtin_fn(Self::sin, "sin", &math, 1, interpreter); + make_builtin_fn(Self::sinh, "sinh", &math, 1, interpreter); + make_builtin_fn(Self::sqrt, "sqrt", &math, 1, interpreter); + make_builtin_fn(Self::tan, "tan", &math, 1, interpreter); + make_builtin_fn(Self::tanh, "tanh", &math, 1, interpreter); + make_builtin_fn(Self::trunc, "trunc", &math, 1, interpreter); math } @@ -698,9 +700,8 @@ impl Math { /// Initialise the `Math` object on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); - (Self::NAME, Self::create(global)) + (Self::NAME, Self::create(interpreter)) } } diff --git a/boa/src/builtins/number/mod.rs b/boa/src/builtins/number/mod.rs index fa738d75c0..d34b606591 100644 --- a/boa/src/builtins/number/mod.rs +++ b/boa/src/builtins/number/mod.rs @@ -733,23 +733,48 @@ impl Number { let prototype = Value::new_object(Some(global)); - make_builtin_fn(Self::to_exponential, "toExponential", &prototype, 1); - make_builtin_fn(Self::to_fixed, "toFixed", &prototype, 1); - make_builtin_fn(Self::to_locale_string, "toLocaleString", &prototype, 0); - make_builtin_fn(Self::to_precision, "toPrecision", &prototype, 1); - make_builtin_fn(Self::to_string, "toString", &prototype, 1); - make_builtin_fn(Self::value_of, "valueOf", &prototype, 0); - - make_builtin_fn(Self::parse_int, "parseInt", global, PARSE_INT_MAX_ARG_COUNT); + make_builtin_fn( + Self::to_exponential, + "toExponential", + &prototype, + 1, + interpreter, + ); + make_builtin_fn(Self::to_fixed, "toFixed", &prototype, 1, interpreter); + make_builtin_fn( + Self::to_locale_string, + "toLocaleString", + &prototype, + 0, + interpreter, + ); + make_builtin_fn( + Self::to_precision, + "toPrecision", + &prototype, + 1, + interpreter, + ); + make_builtin_fn(Self::to_string, "toString", &prototype, 1, interpreter); + make_builtin_fn(Self::value_of, "valueOf", &prototype, 0, interpreter); + + make_builtin_fn( + Self::parse_int, + "parseInt", + global, + PARSE_INT_MAX_ARG_COUNT, + interpreter, + ); make_builtin_fn( Self::parse_float, "parseFloat", global, PARSE_FLOAT_MAX_ARG_COUNT, + interpreter, ); - make_builtin_fn(Self::global_is_finite, "isFinite", global, 1); - make_builtin_fn(Self::global_is_nan, "isNaN", global, 1); + make_builtin_fn(Self::global_is_finite, "isFinite", global, 1, interpreter); + make_builtin_fn(Self::global_is_nan, "isNaN", global, 1, interpreter); let number_object = make_constructor_fn( Self::NAME, @@ -761,10 +786,28 @@ impl Number { true, ); - make_builtin_fn(Self::number_is_finite, "isFinite", &number_object, 1); - make_builtin_fn(Self::number_is_nan, "isNaN", &number_object, 1); - make_builtin_fn(Self::is_safe_integer, "isSafeInteger", &number_object, 1); - make_builtin_fn(Self::number_is_integer, "isInteger", &number_object, 1); + make_builtin_fn( + Self::number_is_finite, + "isFinite", + &number_object, + 1, + interpreter, + ); + make_builtin_fn(Self::number_is_nan, "isNaN", &number_object, 1, interpreter); + make_builtin_fn( + Self::is_safe_integer, + "isSafeInteger", + &number_object, + 1, + interpreter, + ); + make_builtin_fn( + Self::number_is_integer, + "isInteger", + &number_object, + 1, + interpreter, + ); // Constants from: // https://tc39.es/ecma262/#sec-properties-of-the-number-constructor diff --git a/boa/src/builtins/object/mod.rs b/boa/src/builtins/object/mod.rs index 7d6ddcb214..89d6af5094 100644 --- a/boa/src/builtins/object/mod.rs +++ b/boa/src/builtins/object/mod.rs @@ -585,23 +585,30 @@ pub fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { let prototype = Value::new_object(None); - make_builtin_fn(has_own_property, "hasOwnProperty", &prototype, 0); + make_builtin_fn( + has_own_property, + "hasOwnProperty", + &prototype, + 0, + interpreter, + ); make_builtin_fn( property_is_enumerable, "propertyIsEnumerable", &prototype, 0, + interpreter, ); - make_builtin_fn(to_string, "toString", &prototype, 0); + make_builtin_fn(to_string, "toString", &prototype, 0, interpreter); let object = make_constructor_fn("Object", 1, make_object, global, prototype, true, true); // static methods of the builtin Object - make_builtin_fn(create, "create", &object, 2); - make_builtin_fn(set_prototype_of, "setPrototypeOf", &object, 2); - make_builtin_fn(get_prototype_of, "getPrototypeOf", &object, 1); - make_builtin_fn(define_property, "defineProperty", &object, 3); - make_builtin_fn(is, "is", &object, 2); + make_builtin_fn(create, "create", &object, 2, interpreter); + make_builtin_fn(set_prototype_of, "setPrototypeOf", &object, 2, interpreter); + make_builtin_fn(get_prototype_of, "getPrototypeOf", &object, 1, interpreter); + make_builtin_fn(define_property, "defineProperty", &object, 3, interpreter); + make_builtin_fn(is, "is", &object, 2, interpreter); ("Object", object) } diff --git a/boa/src/builtins/regexp/mod.rs b/boa/src/builtins/regexp/mod.rs index a537f83f6e..579ec60930 100644 --- a/boa/src/builtins/regexp/mod.rs +++ b/boa/src/builtins/regexp/mod.rs @@ -487,9 +487,9 @@ impl RegExp { .unwrap() .insert_field("lastIndex", Value::from(0)); - make_builtin_fn(Self::test, "test", &prototype, 1); - make_builtin_fn(Self::exec, "exec", &prototype, 1); - make_builtin_fn(Self::to_string, "toString", &prototype, 0); + make_builtin_fn(Self::test, "test", &prototype, 1, interpreter); + make_builtin_fn(Self::exec, "exec", &prototype, 1, interpreter); + make_builtin_fn(Self::to_string, "toString", &prototype, 0, interpreter); // TODO: make them accessor properties, not methods. // make_builtin_fn(Self::get_dot_all, "dotAll", &prototype, 0); diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index 4b83ba13fa..80bc7909d7 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -1003,39 +1003,58 @@ impl String { /// Initialise the `String` object on the global object. #[inline] pub(crate) fn init(interpreter: &mut Interpreter) -> (&'static str, Value) { - let global = interpreter.global(); let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); // Create `String` `prototype` + + let global = interpreter.global(); let prototype = Value::new_object(Some(global)); let length = Property::default().value(Value::from(0)); prototype.set_property("length", length); - make_builtin_fn(Self::char_at, "charAt", &prototype, 1); - make_builtin_fn(Self::char_code_at, "charCodeAt", &prototype, 1); - make_builtin_fn(Self::to_string, "toString", &prototype, 0); - make_builtin_fn(Self::concat, "concat", &prototype, 1); - make_builtin_fn(Self::repeat, "repeat", &prototype, 1); - make_builtin_fn(Self::slice, "slice", &prototype, 2); - make_builtin_fn(Self::starts_with, "startsWith", &prototype, 1); - make_builtin_fn(Self::ends_with, "endsWith", &prototype, 1); - make_builtin_fn(Self::includes, "includes", &prototype, 1); - make_builtin_fn(Self::index_of, "indexOf", &prototype, 1); - make_builtin_fn(Self::last_index_of, "lastIndexOf", &prototype, 1); - make_builtin_fn(Self::r#match, "match", &prototype, 1); - make_builtin_fn(Self::pad_end, "padEnd", &prototype, 1); - make_builtin_fn(Self::pad_start, "padStart", &prototype, 1); - make_builtin_fn(Self::trim, "trim", &prototype, 0); - make_builtin_fn(Self::trim_start, "trimStart", &prototype, 0); - make_builtin_fn(Self::trim_end, "trimEnd", &prototype, 0); - make_builtin_fn(Self::to_lowercase, "toLowerCase", &prototype, 0); - make_builtin_fn(Self::to_uppercase, "toUpperCase", &prototype, 0); - make_builtin_fn(Self::substring, "substring", &prototype, 2); - make_builtin_fn(Self::substr, "substr", &prototype, 2); - make_builtin_fn(Self::value_of, "valueOf", &prototype, 0); - make_builtin_fn(Self::match_all, "matchAll", &prototype, 1); - make_builtin_fn(Self::replace, "replace", &prototype, 2); + make_builtin_fn(Self::char_at, "charAt", &prototype, 1, interpreter); + make_builtin_fn(Self::char_code_at, "charCodeAt", &prototype, 1, interpreter); + make_builtin_fn(Self::to_string, "toString", &prototype, 0, interpreter); + make_builtin_fn(Self::concat, "concat", &prototype, 1, interpreter); + make_builtin_fn(Self::repeat, "repeat", &prototype, 1, interpreter); + make_builtin_fn(Self::slice, "slice", &prototype, 2, interpreter); + make_builtin_fn(Self::starts_with, "startsWith", &prototype, 1, interpreter); + make_builtin_fn(Self::ends_with, "endsWith", &prototype, 1, interpreter); + make_builtin_fn(Self::includes, "includes", &prototype, 1, interpreter); + make_builtin_fn(Self::index_of, "indexOf", &prototype, 1, interpreter); + make_builtin_fn( + Self::last_index_of, + "lastIndexOf", + &prototype, + 1, + interpreter, + ); + make_builtin_fn(Self::r#match, "match", &prototype, 1, interpreter); + make_builtin_fn(Self::pad_end, "padEnd", &prototype, 1, interpreter); + make_builtin_fn(Self::pad_start, "padStart", &prototype, 1, interpreter); + make_builtin_fn(Self::trim, "trim", &prototype, 0, interpreter); + make_builtin_fn(Self::trim_start, "trimStart", &prototype, 0, interpreter); + make_builtin_fn(Self::trim_end, "trimEnd", &prototype, 0, interpreter); + make_builtin_fn( + Self::to_lowercase, + "toLowerCase", + &prototype, + 0, + interpreter, + ); + make_builtin_fn( + Self::to_uppercase, + "toUpperCase", + &prototype, + 0, + interpreter, + ); + make_builtin_fn(Self::substring, "substring", &prototype, 2, interpreter); + make_builtin_fn(Self::substr, "substr", &prototype, 2, interpreter); + make_builtin_fn(Self::value_of, "valueOf", &prototype, 0, interpreter); + make_builtin_fn(Self::match_all, "matchAll", &prototype, 1, interpreter); + make_builtin_fn(Self::replace, "replace", &prototype, 2, interpreter); let string_object = make_constructor_fn( Self::NAME, diff --git a/boa/src/builtins/symbol/mod.rs b/boa/src/builtins/symbol/mod.rs index 3498970fec..853aa90d86 100644 --- a/boa/src/builtins/symbol/mod.rs +++ b/boa/src/builtins/symbol/mod.rs @@ -141,7 +141,7 @@ impl Symbol { // Create prototype object let prototype = Value::new_object(Some(global)); - make_builtin_fn(Self::to_string, "toString", &prototype, 0); + make_builtin_fn(Self::to_string, "toString", &prototype, 0, interpreter); let symbol_object = make_constructor_fn( Self::NAME,