Skip to content

Commit

Permalink
LibJS: Add missing to_property_key exception check in ClassExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
IdanHo authored and awesomekling committed Jun 17, 2021
1 parent 9cbd90f commit d6df955
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Userland/Libraries/LibJS/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,20 +816,24 @@ Value ClassExpression::execute(Interpreter& interpreter, GlobalObject& global_ob
if (interpreter.exception())
return {};

auto property_key = key.to_property_key(global_object);
if (interpreter.exception())
return {};

auto& target = method.is_static() ? *class_constructor : class_prototype.as_object();
method_function.set_home_object(&target);

switch (method.kind()) {
case ClassMethod::Kind::Method:
target.define_property(key.to_property_key(global_object), method_value);
target.define_property(property_key, method_value);
break;
case ClassMethod::Kind::Getter:
update_function_name(method_value, String::formatted("get {}", get_function_name(global_object, key)));
target.define_accessor(key.to_property_key(global_object), &method_function, nullptr, Attribute::Configurable | Attribute::Enumerable);
target.define_accessor(property_key, &method_function, nullptr, Attribute::Configurable | Attribute::Enumerable);
break;
case ClassMethod::Kind::Setter:
update_function_name(method_value, String::formatted("set {}", get_function_name(global_object, key)));
target.define_accessor(key.to_property_key(global_object), nullptr, &method_function, Attribute::Configurable | Attribute::Enumerable);
target.define_accessor(property_key, nullptr, &method_function, Attribute::Configurable | Attribute::Enumerable);
break;
default:
VERIFY_NOT_REACHED();
Expand Down

0 comments on commit d6df955

Please sign in to comment.