mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
LibJS: Constructor function's "prototype" property should be writable
This matches other engines.
This commit is contained in:
parent
01c8765519
commit
2e4832c3da
3 changed files with 12 additions and 2 deletions
|
@ -759,7 +759,7 @@ Value ClassExpression::execute(Interpreter& interpreter, GlobalObject& global_ob
|
||||||
prototype->define_property(vm.names.constructor, class_constructor, 0);
|
prototype->define_property(vm.names.constructor, class_constructor, 0);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
class_constructor->define_property(vm.names.prototype, prototype, 0);
|
class_constructor->define_property(vm.names.prototype, prototype, Attribute::Writable);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
class_constructor->set_prototype(super_constructor.is_null() ? global_object.function_prototype() : &super_constructor.as_object());
|
class_constructor->set_prototype(super_constructor.is_null() ? global_object.function_prototype() : &super_constructor.as_object());
|
||||||
|
|
|
@ -71,7 +71,7 @@ void ScriptFunction::initialize(GlobalObject& global_object)
|
||||||
if (!m_is_arrow_function) {
|
if (!m_is_arrow_function) {
|
||||||
Object* prototype = vm.heap().allocate<Object>(global_object, *global_object.new_script_function_prototype_object_shape());
|
Object* prototype = vm.heap().allocate<Object>(global_object, *global_object.new_script_function_prototype_object_shape());
|
||||||
prototype->define_property(vm.names.constructor, this, Attribute::Writable | Attribute::Configurable);
|
prototype->define_property(vm.names.constructor, this, Attribute::Writable | Attribute::Configurable);
|
||||||
define_property(vm.names.prototype, prototype, 0);
|
define_property(vm.names.prototype, prototype, Attribute::Writable);
|
||||||
}
|
}
|
||||||
define_native_property(vm.names.length, length_getter, nullptr, Attribute::Configurable);
|
define_native_property(vm.names.length, length_getter, nullptr, Attribute::Configurable);
|
||||||
define_native_property(vm.names.name, name_getter, nullptr, Attribute::Configurable);
|
define_native_property(vm.names.name, name_getter, nullptr, Attribute::Configurable);
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
test("a function's prototype property should be writable", () => {
|
||||||
|
function x() {}
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(x, "prototype");
|
||||||
|
expect(desc.writable).toBe(true);
|
||||||
|
expect(desc.enumerable).toBe(false);
|
||||||
|
expect(desc.configurable).toBe(false);
|
||||||
|
|
||||||
|
x.prototype = 1;
|
||||||
|
expect(x.prototype).toBe(1);
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue