diff --git a/Libraries/LibJS/Runtime/GlobalObject.h b/Libraries/LibJS/Runtime/GlobalObject.h index 9d6c52c8b7e..214a447a252 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Libraries/LibJS/Runtime/GlobalObject.h @@ -73,7 +73,7 @@ inline void GlobalObject::add_constructor(const FlyString& property_name, Constr { constructor = heap().allocate(); constructor->put("name", js_string(heap(), property_name), Attribute::Configurable); - prototype.put("constructor", constructor); + prototype.put("constructor", constructor, Attribute::Writable | Attribute::Configurable); put(property_name, constructor, Attribute::Writable | Attribute::Configurable); } diff --git a/Libraries/LibJS/Tests/Object.prototype.constructor.js b/Libraries/LibJS/Tests/Object.prototype.constructor.js index 06f5921bf87..ff862fae058 100644 --- a/Libraries/LibJS/Tests/Object.prototype.constructor.js +++ b/Libraries/LibJS/Tests/Object.prototype.constructor.js @@ -1,28 +1,34 @@ load("test-common.js"); try { - assert(Array.prototype.constructor === Array) - assert(Boolean.prototype.constructor === Boolean) - assert(Date.prototype.constructor === Date) - assert(Error.prototype.constructor === Error) - assert(Function.prototype.constructor === Function) - assert(Number.prototype.constructor === Number) - assert(Object.prototype.constructor === Object) + assert(Array.prototype.constructor === Array); + assert(Boolean.prototype.constructor === Boolean); + assert(Date.prototype.constructor === Date); + assert(Error.prototype.constructor === Error); + assert(Function.prototype.constructor === Function); + assert(Number.prototype.constructor === Number); + assert(Object.prototype.constructor === Object); - o = {} - assert(o.constructor === Object) + o = {}; + assert(o.constructor === Object); - o = new Object - assert(o.constructor === Object) + o = new Object(); + assert(o.constructor === Object); - a = [] - assert(a.constructor === Array) + a = []; + assert(a.constructor === Array); - a = new Array - assert(a.constructor === Array) + a = new Array(); + assert(a.constructor === Array); - n = new Number(3) - assert(n.constructor === Number) + n = new Number(3); + assert(n.constructor === Number); + + d = Object.getOwnPropertyDescriptor(Object.prototype, "constructor"); + assert(d.configurable === true); + assert(d.enumerable === false); + assert(d.writable === true); + assert(d.value === Object); console.log("PASS"); } catch (e) {