ladybird/Userland/Libraries/LibJS/Contrib/Test262/IsHTMLDDA.cpp
Linus Groh 1e01a85cdf LibJS: Import C++ sources from libjs-test262 :^)
This commit upstreams most of the C++ bits of the LibJS test262 runner
at https://github.com/linusg/libjs-test262/, specifically everything but
the main.cpp file serving as the actual executable.
Since all of these are just regular JS objects, I opted to put them in
LibJS itself, in a new Contrib/ directory like many other projects have
one. Other code that can end up there in the future is the runtime for
esvu, which might even share some functionality with test262's $262
object.

The code has been copied verbatim, and only a small number of changes
have been made:

- Putting everything into the JS::Test262 namespace
- Removing now redundant JS namespace prefixes
- Updating includes to use absolute <LibJS/...> paths
- Updating the SPDX-License-Identifier comments from MIT to BSD-2-Clause

I gained permission to change the license and upstream these changes
from all the major contributors to this code: Ali, Andrew, David, Idan.

The removal of the code from the source repository is here:
https://github.com/linusg/libjs-test262/pull/54

This is only the first step, the goal is to eventually upstream the
actual libjs-test262-runner executable and supporting Python scripts
into SerenityOS as well.
2022-03-29 21:01:08 +01:00

40 lines
1.3 KiB
C++

/*
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Contrib/Test262/IsHTMLDDA.h>
#include <LibJS/Runtime/GlobalObject.h>
namespace JS::Test262 {
IsHTMLDDA::IsHTMLDDA(JS::GlobalObject& global_object)
// NativeFunction without prototype is currently not possible (only due to the lack of a ctor that supports it)
: NativeFunction("IsHTMLDDA", *global_object.function_prototype())
{
}
ThrowCompletionOr<Value> IsHTMLDDA::call()
{
auto& vm = this->vm();
if (vm.argument_count() == 0)
return js_null();
if (vm.argument(0).is_string() && vm.argument(0).as_string().string().is_empty())
return js_null();
// Not sure if this really matters, INTERPRETING.md simply says:
// * IsHTMLDDA - (present only in implementations that can provide it) an object that:
// a. has an [[IsHTMLDDA]] internal slot, and
// b. when called with no arguments or with the first argument "" (an empty string) returns null.
return js_undefined();
}
ThrowCompletionOr<Object*> IsHTMLDDA::construct(FunctionObject&)
{
// Not sure if we need to support construction, but ¯\_(ツ)_/¯
auto& vm = this->vm();
auto& global_object = this->global_object();
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAConstructor, "IsHTMLDDA");
}
}