@@ -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
388378pub 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
398388pub 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
0 commit comments