mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:27: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 };
|
||||
|
|
|
@ -11,16 +11,6 @@ else
|
|||
export UBSAN_OPTIONS=print_stacktrace=1
|
||||
fi
|
||||
|
||||
# FIXME: Support "find -name" in Serenity to remove the file name checks below
|
||||
test_files_tmp=$(find . -type f | cut -b 3- | sort)
|
||||
|
||||
for f in $test_files_tmp; do
|
||||
if [ "$f" = "test-common.js" ] || [ "$f" = "run-tests.sh" ]; then
|
||||
continue
|
||||
fi
|
||||
test_files=("${test_files[@]}" "$f");
|
||||
done
|
||||
|
||||
$js_program "$test_root" "${test_files[@]}"
|
||||
$js_program "$test_root"
|
||||
|
||||
exit $!
|
||||
|
|
|
@ -425,7 +425,7 @@ describe = (message, callback) => {
|
|||
suiteMessage = defaultSuiteMessage;
|
||||
}
|
||||
|
||||
test = (message, callback) => {
|
||||
const getTestFunction = successMessage => (message, callback) => {
|
||||
if (!__TestResults__[suiteMessage])
|
||||
__TestResults__[suiteMessage] = {};
|
||||
|
||||
|
@ -437,13 +437,15 @@ test = (message, callback) => {
|
|||
try {
|
||||
callback();
|
||||
suite[message] = {
|
||||
passed: true,
|
||||
result: successMessage,
|
||||
};
|
||||
} catch (e) {
|
||||
suite[message] = {
|
||||
passed: false,
|
||||
result: "fail",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
test = getTestFunction("pass");
|
||||
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue