Skip to content

Commit 70f2ef4

Browse files
committed
Fixed name and length properties in global objects
1 parent d01d61a commit 70f2ef4

10 files changed

Lines changed: 27 additions & 21 deletions

File tree

boa/src/builtins/array/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ pub fn create(global: &Value) -> Value {
978978
make_builtin_fn!(slice, named "slice", with length 2, of prototype);
979979
make_builtin_fn!(some, named "some", with length 2, of prototype);
980980

981-
let array = make_constructor_fn(make_array, global, prototype, true);
981+
let array = make_constructor_fn("Array", 1, make_array, global, prototype, true);
982982

983983
// Static Methods
984984
make_builtin_fn!(is_array, named "isArray", with length 1, of array);

boa/src/builtins/bigint/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn create(global: &Value) -> Value {
9696
make_builtin_fn!(to_string, named "toString", with length 1, of prototype);
9797
make_builtin_fn!(value_of, named "valueOf", of prototype);
9898

99-
make_constructor_fn(make_bigint, global, prototype, false)
99+
make_constructor_fn("BigInt", 1, make_bigint, global, prototype, false)
100100
}
101101

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

boa/src/builtins/boolean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn create(global: &Value) -> Value {
104104
make_builtin_fn!(to_string, named "toString", of prototype);
105105
make_builtin_fn!(value_of, named "valueOf", of prototype);
106106

107-
make_constructor_fn(construct_boolean, global, prototype, true)
107+
make_constructor_fn("Boolean", 1, construct_boolean, global, prototype, true)
108108
}
109109

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

boa/src/builtins/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn create(global: &Value) -> Value {
6060
prototype.set_field_slice("name", Value::from("Error"));
6161
make_builtin_fn!(to_string, named "toString", of prototype);
6262

63-
make_constructor_fn(make_error, global, prototype, true)
63+
make_constructor_fn("Error", 1, make_error, global, prototype, true)
6464
}
6565

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

boa/src/builtins/function/mod.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl Function {
272272
}
273273
}
274274
} else {
275-
let name = this_obj.get_field_slice("name").to_string();
275+
let name = this.get_field_slice("name").to_string();
276276
panic!("TypeError: {} is not a constructor", name);
277277
}
278278
}
@@ -338,16 +338,6 @@ impl Debug for Function {
338338
}
339339
}
340340

341-
/// Function Prototype.
342-
///
343-
/// <https://tc39.es/ecma262/#sec-properties-of-the-function-prototype-object>
344-
pub fn create_function_prototype() {
345-
let mut function_prototype: Object = Object::default();
346-
// Set Kind to function (for historical & compatibility reasons)
347-
// <https://tc39.es/ecma262/#sec-properties-of-the-function-prototype-object>
348-
function_prototype.kind = ObjectKind::Function;
349-
}
350-
351341
/// Arguments.
352342
///
353343
/// <https://tc39.es/ecma262/#sec-createunmappedargumentsobject>
@@ -388,14 +378,16 @@ pub fn make_function(this: &mut Value, _: &[Value], _: &mut Interpreter) -> Resu
388378
pub fn create(global: &Value) -> Value {
389379
let prototype = Value::new_object(Some(global));
390380

391-
make_constructor_fn(make_function, global, prototype, true)
381+
make_constructor_fn("Function", 1, make_function, global, prototype, true)
392382
}
393383

394384
/// Creates a new constructor function
395385
///
396386
/// This utility function handling linking the new Constructor to the prototype.
397387
/// So far this is only used by internal functions
398388
pub fn make_constructor_fn(
389+
name: &str,
390+
length: i32,
399391
body: NativeFunctionData,
400392
global: &Value,
401393
proto: Value,
@@ -422,6 +414,20 @@ pub fn make_constructor_fn(
422414
proto.set_field_slice("constructor", constructor_val.clone());
423415
constructor_val.set_field_slice(PROTOTYPE, proto);
424416

417+
let length = Property::new()
418+
.value(Value::from(length))
419+
.writable(false)
420+
.configurable(false)
421+
.enumerable(false);
422+
constructor_val.set_property_slice("length", length);
423+
424+
let name = Property::new()
425+
.value(Value::from(name))
426+
.writable(false)
427+
.configurable(false)
428+
.enumerable(false);
429+
constructor_val.set_property_slice("name", name);
430+
425431
constructor_val
426432
}
427433

boa/src/builtins/number/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ pub fn create(global: &Value) -> Value {
366366
make_builtin_fn!(to_string, named "toString", with length 1, of prototype);
367367
make_builtin_fn!(value_of, named "valueOf", of prototype);
368368

369-
make_constructor_fn(make_number, global, prototype, true)
369+
make_constructor_fn("Number", 1, make_number, global, prototype, true)
370370
}
371371

372372
/// Initialise the `Number` object on the global object.

boa/src/builtins/object/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ pub fn create(global: &Value) -> Value {
620620
make_builtin_fn!(has_own_property, named "hasOwnProperty", of prototype);
621621
make_builtin_fn!(to_string, named "toString", of prototype);
622622

623-
let object = make_constructor_fn(make_object, global, prototype, true);
623+
let object = make_constructor_fn("Object", 1, make_object, global, prototype, true);
624624

625625
object.set_field_slice("length", Value::from(1));
626626
make_builtin_fn!(set_prototype_of, named "setPrototypeOf", with length 2, of object);

boa/src/builtins/regexp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ pub fn create(global: &Value) -> Value {
476476
make_builtin_fn!(get_sticky, named "sticky", of prototype);
477477
make_builtin_fn!(get_unicode, named "unicode", of prototype);
478478

479-
make_constructor_fn(make_regexp, global, prototype, true)
479+
make_constructor_fn("RegExp", 1, make_regexp, global, prototype, true)
480480
}
481481

482482
/// Initialise the `RegExp` object on the global object.

boa/src/builtins/string/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ pub fn create(global: &Value) -> Value {
10211021
make_builtin_fn!(match_all, named "matchAll", with length 1, of prototype);
10221022
make_builtin_fn!(replace, named "replace", with length 2, of prototype);
10231023

1024-
make_constructor_fn(make_string, global, prototype, true)
1024+
make_constructor_fn("String", 1, make_string, global, prototype, true)
10251025
}
10261026

10271027
/// Initialise the `String` object on the global object.

boa/src/builtins/symbol/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn create(global: &Value) -> Value {
9494
let prototype = Value::new_object(Some(global));
9595
make_builtin_fn!(to_string, named "toString", of prototype);
9696

97-
make_constructor_fn(call_symbol, global, prototype, false)
97+
make_constructor_fn("Symbol", 1, call_symbol, global, prototype, false)
9898
}
9999

100100
/// Initialise the `Symbol` object on the global object.

0 commit comments

Comments
 (0)