From b299c75d4559aa2aa14e42210a64e523a0e9c813 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 16 May 2020 17:59:57 +0100 Subject: [PATCH] LibJS: Make Object.prototype.constructor non-enumerable --- Libraries/LibJS/Runtime/GlobalObject.h | 2 +- .../Tests/Object.prototype.constructor.js | 40 +++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) 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) {