1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

LibJS: Define the "constructor" property on ScriptFunction's prototype

and set it to the current function
This commit is contained in:
Jack Karamanian 2020-06-08 13:24:15 -05:00 committed by Andreas Kling
parent f833362536
commit 949bffdc93
2 changed files with 21 additions and 8 deletions

View file

@ -66,8 +66,11 @@ ScriptFunction::ScriptFunction(GlobalObject& global_object, const FlyString& nam
void ScriptFunction::initialize(Interpreter& interpreter, GlobalObject& global_object) void ScriptFunction::initialize(Interpreter& interpreter, GlobalObject& global_object)
{ {
Function::initialize(interpreter, global_object); Function::initialize(interpreter, global_object);
if (!m_is_arrow_function) if (!is_arrow_function) {
define_property("prototype", Object::create_empty(interpreter, global_object), 0); Object* prototype = Object::create_empty(interpreter(), interpreter().global_object());
prototype->define_property("constructor", this, Attribute::Writable | Attribute::Configurable);
define_property("prototype", prototype, 0);
}
define_native_property("length", length_getter, nullptr, Attribute::Configurable); define_native_property("length", length_getter, nullptr, Attribute::Configurable);
define_native_property("name", name_getter, nullptr, Attribute::Configurable); define_native_property("name", name_getter, nullptr, Attribute::Configurable);
} }

View file

@ -1,7 +1,17 @@
function Foo() { load("test-common.js");
this.x = 123;
}
var foo = new Foo(); try {
if (foo.x === 123) function Foo() {
console.log("PASS"); this.x = 123;
}
assert(Foo.prototype.constructor === Foo);
var foo = new Foo();
assert(foo.constructor === Foo);
assert(foo.x === 123);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}