1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:48:12 +00:00

LibJS: Add a helper for calling JS::Function's with arguments

The fact that a `MarkedValueList` had to be created was just annoying,
so here's an alternative.
This patchset also removes some (now) unneeded MarkedValueList.h includes.
This commit is contained in:
AnotherTest 2020-08-25 22:18:32 +04:30 committed by Andreas Kling
parent 521e730df1
commit 394e4c04cd
15 changed files with 72 additions and 113 deletions

View file

@ -56,7 +56,8 @@ JSONObject::~JSONObject()
{
}
String JSONObject::stringify_impl(Interpreter& interpreter, GlobalObject& global_object, Value value, Value replacer, Value space) {
String JSONObject::stringify_impl(Interpreter& interpreter, GlobalObject& global_object, Value value, Value replacer, Value space)
{
StringifyState state;
@ -154,19 +155,14 @@ String JSONObject::serialize_json_property(Interpreter& interpreter, StringifySt
if (interpreter.exception())
return {};
if (to_json.is_function()) {
MarkedValueList arguments(interpreter.heap());
arguments.append(js_string(interpreter, key.to_string()));
value = interpreter.call(to_json.as_function(), value, move(arguments));
value = interpreter.call(to_json.as_function(), value, js_string(interpreter, key.to_string()));
if (interpreter.exception())
return {};
}
}
if (state.replacer_function) {
MarkedValueList arguments(interpreter.heap());
arguments.append(js_string(interpreter, key.to_string()));
arguments.append(value);
value = interpreter.call(*state.replacer_function, holder, move(arguments));
value = interpreter.call(*state.replacer_function, holder, js_string(interpreter, key.to_string()), value);
if (interpreter.exception())
return {};
}
@ -494,10 +490,8 @@ Value JSONObject::internalize_json_property(Interpreter& interpreter, Object* ho
}
}
}
MarkedValueList arguments(interpreter.heap());
arguments.append(js_string(interpreter, name.to_string()));
arguments.append(value);
return interpreter.call(reviver, Value(holder), move(arguments));
return interpreter.call(reviver, Value(holder), js_string(interpreter, name.to_string()), value);
}
}