LibJS: Make Object.prototype.constructor non-enumerable

This commit is contained in:
Linus Groh 2020-05-16 17:59:57 +01:00 committed by Andreas Kling
parent 9f064d4439
commit b299c75d45
Notes: sideshowbarker 2024-07-19 06:36:12 +09:00
2 changed files with 24 additions and 18 deletions

View file

@ -73,7 +73,7 @@ inline void GlobalObject::add_constructor(const FlyString& property_name, Constr
{ {
constructor = heap().allocate<ConstructorType>(); constructor = heap().allocate<ConstructorType>();
constructor->put("name", js_string(heap(), property_name), Attribute::Configurable); 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); put(property_name, constructor, Attribute::Writable | Attribute::Configurable);
} }

View file

@ -1,28 +1,34 @@
load("test-common.js"); load("test-common.js");
try { try {
assert(Array.prototype.constructor === Array) assert(Array.prototype.constructor === Array);
assert(Boolean.prototype.constructor === Boolean) assert(Boolean.prototype.constructor === Boolean);
assert(Date.prototype.constructor === Date) assert(Date.prototype.constructor === Date);
assert(Error.prototype.constructor === Error) assert(Error.prototype.constructor === Error);
assert(Function.prototype.constructor === Function) assert(Function.prototype.constructor === Function);
assert(Number.prototype.constructor === Number) assert(Number.prototype.constructor === Number);
assert(Object.prototype.constructor === Object) assert(Object.prototype.constructor === Object);
o = {} o = {};
assert(o.constructor === Object) assert(o.constructor === Object);
o = new Object o = new Object();
assert(o.constructor === Object) assert(o.constructor === Object);
a = [] a = [];
assert(a.constructor === Array) assert(a.constructor === Array);
a = new Array a = new Array();
assert(a.constructor === Array) assert(a.constructor === Array);
n = new Number(3) n = new Number(3);
assert(n.constructor === Number) 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"); console.log("PASS");
} catch (e) { } catch (e) {