mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 17:29:01 +00:00
LibJS: Make class accessors non-enumerable
According to ECMA-262 §15.4.5 (MethodDefinitionEvaluation), getters and setters defined in class bodies must create property descriptors with [[Enumerable]]: false. Previously we incorrectly marked them enumerable. This patch updates `ClassMethod::class_element_evaluation` so that both getter and setter descriptors use `.enumerable = false`.
This commit is contained in:
parent
21082f5002
commit
4f0e8236a0
Notes:
github-actions[bot]
2025-09-07 12:36:12 +00:00
Author: https://github.com/shlyakpavel
Commit: 4f0e8236a0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6100
Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 14 additions and 2 deletions
|
@ -191,11 +191,11 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassMethod::class_element_evaluatio
|
|||
break;
|
||||
case ClassMethod::Kind::Getter:
|
||||
set_function_name("get"sv);
|
||||
TRY(target.define_property_or_throw(property_key, { .get = &method_function, .enumerable = true, .configurable = true }));
|
||||
TRY(target.define_property_or_throw(property_key, { .get = &method_function, .enumerable = false, .configurable = true }));
|
||||
break;
|
||||
case ClassMethod::Kind::Setter:
|
||||
set_function_name("set"sv);
|
||||
TRY(target.define_property_or_throw(property_key, { .set = &method_function, .enumerable = true, .configurable = true }));
|
||||
TRY(target.define_property_or_throw(property_key, { .set = &method_function, .enumerable = false, .configurable = true }));
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
|
|
12
Libraries/LibJS/Tests/classes/class-accessor-enumerable.js
Normal file
12
Libraries/LibJS/Tests/classes/class-accessor-enumerable.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
test("class accessor should be non-enumerable", () => {
|
||||
class C {
|
||||
get x() {
|
||||
return 1;
|
||||
}
|
||||
set x(v) {}
|
||||
}
|
||||
|
||||
const desc = Object.getOwnPropertyDescriptor(C.prototype, "x");
|
||||
expect(desc.enumerable).toBeFalse();
|
||||
expect(Object.keys(C.prototype).includes("x")).toBeFalse();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue