Skip to content

Commit

Permalink
LibJS: get_iterator_values() should pass Value to callback (not Value&)
Browse files Browse the repository at this point in the history
Value& implies that the callback is expected/able to modify the value,
which is not the case.
  • Loading branch information
awesomekling committed Sep 8, 2020
1 parent b4bfc3e commit d85eed5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Libraries/LibJS/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj
if (interpreter.exception())
return {};
if (m_arguments[i].is_spread) {
get_iterator_values(global_object, value, [&](Value& iterator_value) {
get_iterator_values(global_object, value, [&](Value iterator_value) {
if (interpreter.exception())
return IterationDecision::Break;
arguments.append(iterator_value);
Expand Down Expand Up @@ -419,7 +419,7 @@ Value ForOfStatement::execute(Interpreter& interpreter, GlobalObject& global_obj
if (interpreter.exception())
return {};

get_iterator_values(global_object, rhs_result, [&](Value& value) {
get_iterator_values(global_object, rhs_result, [&](Value value) {
interpreter.set_variable(variable_name, value, global_object);
last_value = interpreter.run(global_object, *m_body);
if (interpreter.exception())
Expand Down Expand Up @@ -1652,7 +1652,7 @@ Value ArrayExpression::execute(Interpreter& interpreter, GlobalObject& global_ob
return {};

if (element->is_spread_expression()) {
get_iterator_values(global_object, value, [&](Value& iterator_value) {
get_iterator_values(global_object, value, [&](Value iterator_value) {
array->indexed_properties().append(iterator_value);
return IterationDecision::Continue;
});
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibJS/Runtime/ArrayConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
array->set_indexed_property_elements(move(elements));
} else {
// * iterable objects
get_iterator_values(global_object, value, [&](Value& element) {
get_iterator_values(global_object, value, [&](Value element) {
if (interpreter.exception())
return IterationDecision::Break;
array->indexed_properties().append(element);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibJS/Runtime/IteratorOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Value create_iterator_result_object(GlobalObject& global_object, Value value, bo
return object;
}

void get_iterator_values(GlobalObject& global_object, Value value, AK::Function<IterationDecision(Value&)> callback)
void get_iterator_values(GlobalObject& global_object, Value value, AK::Function<IterationDecision(Value)> callback)
{
auto& interpreter = global_object.interpreter();

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibJS/Runtime/IteratorOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ Value create_iterator_result_object(GlobalObject&, Value value, bool done);
Object* iterator_next(Object& iterator, Value value = {});
void iterator_close(Object& iterator);

void get_iterator_values(GlobalObject&, Value value, AK::Function<IterationDecision(Value&)> callback);
void get_iterator_values(GlobalObject&, Value value, AK::Function<IterationDecision(Value)> callback);

}

0 comments on commit d85eed5

Please sign in to comment.