Skip to content

Commit

Permalink
Fixed function object constructable/callable
Browse files Browse the repository at this point in the history
 - Maded arrow functions non-constructable
 - Simplified Function object and removed FunctionKind
 - Rnamed create_ordinary -> ordinary, create_builtin -> builtin
 - Added name and length properties in global objects
  • Loading branch information
HalidOdat committed May 25, 2020
1 parent 4beadfc commit 317b4c5
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 188 deletions.
2 changes: 1 addition & 1 deletion boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ impl Array {
make_builtin_fn(Self::slice, "slice", &prototype, 2);
make_builtin_fn(Self::some, "some", &prototype, 2);

let array = make_constructor_fn(Self::make_array, global, prototype);
let array = make_constructor_fn("Array", 1, Self::make_array, global, prototype, true);

// Static Methods
make_builtin_fn(Self::is_array, "isArray", &array, 1);
Expand Down
18 changes: 9 additions & 9 deletions boa/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ impl BigInt {
))
}

// /// `BigInt.prototype.valueOf()`
// ///
// /// The `valueOf()` method returns the wrapped primitive value of a Number object.
// ///
// /// More information:
// /// - [ECMAScript reference][spec]
// /// - [MDN documentation][mdn]
// ///
/// `BigInt.prototype.valueOf()`
///
/// The `valueOf()` method returns the wrapped primitive value of a Number object.
///
/// More information:
/// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn]
///
/// [spec]: https://tc39.es/ecma262/#sec-bigint.prototype.valueof
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf
pub(crate) fn value_of(
Expand All @@ -124,7 +124,7 @@ impl BigInt {
make_builtin_fn(Self::to_string, "toString", &prototype, 1);
make_builtin_fn(Self::value_of, "valueOf", &prototype, 0);

make_constructor_fn(Self::make_bigint, global, prototype)
make_constructor_fn("BigInt", 1, Self::make_bigint, global, prototype, false)
}

/// Initialise the `BigInt` object on the global object.
Expand Down
9 changes: 8 additions & 1 deletion boa/src/builtins/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ impl Boolean {
make_builtin_fn(Self::to_string, "toString", &prototype, 0);
make_builtin_fn(Self::value_of, "valueOf", &prototype, 0);

make_constructor_fn(Self::construct_boolean, global, prototype)
make_constructor_fn(
"Boolean",
1,
Self::construct_boolean,
global,
prototype,
true,
)
}

/// Initialise the `Boolean` object on the global object.
Expand Down
5 changes: 3 additions & 2 deletions boa/src/builtins/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ impl Error {
pub(crate) fn create(global: &Value) -> Value {
let prototype = Value::new_object(Some(global));
prototype.set_field("message", Value::from(""));
prototype.set_field("name", Value::from("Error"));

make_builtin_fn(Self::to_string, "toString", &prototype, 0);
make_constructor_fn(Self::make_error, global, prototype)

make_constructor_fn("Error", 1, Self::make_error, global, prototype, true)
}

/// Initialise the global object with the `Error` object.
Expand Down
5 changes: 3 additions & 2 deletions boa/src/builtins/error/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ impl RangeError {
pub(crate) fn create(global: &Value) -> Value {
let prototype = Value::new_object(Some(global));
prototype.set_field("message", Value::from(""));
prototype.set_field("name", Value::from("RangeError"));

make_builtin_fn(Self::to_string, "toString", &prototype, 0);
make_constructor_fn(Self::make_error, global, prototype)

make_constructor_fn("RangeError", 1, Self::make_error, global, prototype, true)
}

/// Runs a `new RangeError(message)`.
Expand Down
Loading

0 comments on commit 317b4c5

Please sign in to comment.