mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00:00
LibJS/test-js: Clean up test-js code
This commit also exposes JSONObject's implementation of stringify to the public, so that it can be used by test-js without having to go through the interpreter's environment.
This commit is contained in:
parent
4c6fd49169
commit
26acc8ba88
5 changed files with 193 additions and 171 deletions
|
@ -54,13 +54,7 @@ JSONObject::~JSONObject()
|
|||
{
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify)
|
||||
{
|
||||
if (!interpreter.argument_count())
|
||||
return js_undefined();
|
||||
auto value = interpreter.argument(0);
|
||||
auto replacer = interpreter.argument(1);
|
||||
auto space = interpreter.argument(2);
|
||||
String JSONObject::stringify_impl(Interpreter& interpreter, GlobalObject& global_object, Value value, Value replacer, Value space) {
|
||||
|
||||
StringifyState state;
|
||||
|
||||
|
@ -129,8 +123,25 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify)
|
|||
if (interpreter.exception())
|
||||
return {};
|
||||
if (result.is_null())
|
||||
return {};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify)
|
||||
{
|
||||
if (!interpreter.argument_count())
|
||||
return js_undefined();
|
||||
return js_string(interpreter, result);
|
||||
|
||||
auto value = interpreter.argument(0);
|
||||
auto replacer = interpreter.argument(1);
|
||||
auto space = interpreter.argument(2);
|
||||
|
||||
auto string = stringify_impl(interpreter, global_object, value, replacer, space);
|
||||
if (string.is_null())
|
||||
return js_undefined();
|
||||
|
||||
return js_string(interpreter, string);
|
||||
}
|
||||
|
||||
String JSONObject::serialize_json_property(Interpreter& interpreter, StringifyState& state, const PropertyName& key, Object* holder)
|
||||
|
|
|
@ -38,6 +38,10 @@ public:
|
|||
virtual void initialize(Interpreter&, GlobalObject&) override;
|
||||
virtual ~JSONObject() override;
|
||||
|
||||
// The base implementation of stringify is exposed because it is used by
|
||||
// test-js to communicate between the JS tests and the C++ test runner.
|
||||
static String stringify_impl(Interpreter&, GlobalObject&, Value value, Value replacer, Value space);
|
||||
|
||||
private:
|
||||
struct StringifyState {
|
||||
Function* replacer_function { nullptr };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue