Browse Source

Set __proto__ of function instances (#604)

pull/638/head
54k1 4 years ago committed by GitHub
parent
commit
91d9100ad9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 58
      boa/src/builtins/array/mod.rs
  2. 8
      boa/src/builtins/bigint/mod.rs
  3. 4
      boa/src/builtins/boolean/mod.rs
  4. 38
      boa/src/builtins/console/mod.rs
  5. 2
      boa/src/builtins/error/mod.rs
  6. 2
      boa/src/builtins/error/range.rs
  7. 2
      boa/src/builtins/error/reference.rs
  8. 2
      boa/src/builtins/error/syntax.rs
  9. 2
      boa/src/builtins/error/type.rs
  10. 19
      boa/src/builtins/function/mod.rs
  11. 4
      boa/src/builtins/json/mod.rs
  12. 12
      boa/src/builtins/map/mod.rs
  13. 77
      boa/src/builtins/math/mod.rs
  14. 71
      boa/src/builtins/number/mod.rs
  15. 21
      boa/src/builtins/object/mod.rs
  16. 6
      boa/src/builtins/regexp/mod.rs
  17. 69
      boa/src/builtins/string/mod.rs
  18. 2
      boa/src/builtins/symbol/mod.rs

58
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)
}

8
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)
}

4
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,

38
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)
}

2
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,

2
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,

2
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,

2
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,

2
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,

19
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<N>(function: NativeFunctionData, name: N, parent: &Value, length: usize)
where
pub fn make_builtin_fn<N>(
function: NativeFunctionData,
name: N,
parent: &Value,
length: usize,
interpreter: &Interpreter,
) where
N: Into<String>,
{
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

4
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)
}

12
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,

77
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))
}
}

71
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

21
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)
}

6
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);

69
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,

2
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,

Loading…
Cancel
Save