Skip to content

Commit d42e413

Browse files
authored
Fixed function object constructable/callable (#409)
- 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
1 parent e7a9c80 commit d42e413

16 files changed

Lines changed: 227 additions & 188 deletions

File tree

boa/src/builtins/array/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ impl Array {
10311031
make_builtin_fn(Self::slice, "slice", &prototype, 2);
10321032
make_builtin_fn(Self::some, "some", &prototype, 2);
10331033

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

10361036
// Static Methods
10371037
make_builtin_fn(Self::is_array, "isArray", &array, 1);

boa/src/builtins/bigint/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ impl BigInt {
9696
))
9797
}
9898

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

127-
make_constructor_fn(Self::make_bigint, global, prototype)
127+
make_constructor_fn("BigInt", 1, Self::make_bigint, global, prototype, false)
128128
}
129129

130130
/// Initialise the `BigInt` object on the global object.

boa/src/builtins/boolean/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ impl Boolean {
115115
make_builtin_fn(Self::to_string, "toString", &prototype, 0);
116116
make_builtin_fn(Self::value_of, "valueOf", &prototype, 0);
117117

118-
make_constructor_fn(Self::construct_boolean, global, prototype)
118+
make_constructor_fn(
119+
"Boolean",
120+
1,
121+
Self::construct_boolean,
122+
global,
123+
prototype,
124+
true,
125+
)
119126
}
120127

121128
/// Initialise the `Boolean` object on the global object.

boa/src/builtins/error/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ impl Error {
7272
pub(crate) fn create(global: &Value) -> Value {
7373
let prototype = Value::new_object(Some(global));
7474
prototype.set_field("message", Value::from(""));
75-
prototype.set_field("name", Value::from("Error"));
75+
7676
make_builtin_fn(Self::to_string, "toString", &prototype, 0);
77-
make_constructor_fn(Self::make_error, global, prototype)
77+
78+
make_constructor_fn("Error", 1, Self::make_error, global, prototype, true)
7879
}
7980

8081
/// Initialise the global object with the `Error` object.

boa/src/builtins/error/range.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ impl RangeError {
6363
pub(crate) fn create(global: &Value) -> Value {
6464
let prototype = Value::new_object(Some(global));
6565
prototype.set_field("message", Value::from(""));
66-
prototype.set_field("name", Value::from("RangeError"));
66+
6767
make_builtin_fn(Self::to_string, "toString", &prototype, 0);
68-
make_constructor_fn(Self::make_error, global, prototype)
68+
69+
make_constructor_fn("RangeError", 1, Self::make_error, global, prototype, true)
6970
}
7071

7172
/// Runs a `new RangeError(message)`.

0 commit comments

Comments
 (0)