2022-03-29 20:36:22 +01:00
|
|
|
/*
|
2022-08-21 14:00:56 +01:00
|
|
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
2022-03-29 20:36:22 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/Format.h>
|
|
|
|
#include <LibJS/Contrib/Test262/$262Object.h>
|
|
|
|
#include <LibJS/Contrib/Test262/AgentObject.h>
|
|
|
|
#include <LibJS/Contrib/Test262/GlobalObject.h>
|
|
|
|
#include <LibJS/Heap/Cell.h>
|
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
|
|
#include <LibJS/Runtime/VM.h>
|
|
|
|
|
|
|
|
namespace JS::Test262 {
|
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
ThrowCompletionOr<void> GlobalObject::initialize(Realm& realm)
|
2022-03-29 20:36:22 +01:00
|
|
|
{
|
2023-01-28 12:33:35 -05:00
|
|
|
MUST_OR_THROW_OOM(Base::initialize(realm));
|
2022-03-29 20:36:22 +01:00
|
|
|
|
2023-01-28 13:39:44 -05:00
|
|
|
m_$262 = MUST_OR_THROW_OOM(vm().heap().allocate<$262Object>(realm, realm));
|
2022-03-29 20:36:22 +01:00
|
|
|
|
|
|
|
// https://github.com/tc39/test262/blob/master/INTERPRETING.md#host-defined-functions
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
2022-08-22 21:47:35 +01:00
|
|
|
define_native_function(realm, "print", print, 1, attr);
|
2022-03-29 20:36:22 +01:00
|
|
|
define_direct_property("$262", m_$262, attr);
|
2023-01-28 12:33:35 -05:00
|
|
|
|
|
|
|
return {};
|
2022-03-29 20:36:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalObject::visit_edges(Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
visitor.visit(m_$262);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_DEFINE_NATIVE_FUNCTION(GlobalObject::print)
|
|
|
|
{
|
2023-01-13 10:29:02 -05:00
|
|
|
auto string = TRY(vm.argument(0).to_deprecated_string(vm));
|
2022-03-29 20:36:22 +01:00
|
|
|
outln("{}", string);
|
|
|
|
return js_undefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|