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>
|
2023-07-15 13:38:57 +02:00
|
|
|
#include <LibJS/Contrib/Test262/262Object.h>
|
2022-03-29 20:36:22 +01:00
|
|
|
#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 {
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(GlobalObject);
|
2023-11-19 09:45:05 +01:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void GlobalObject::initialize(Realm& realm)
|
2022-03-29 20:36:22 +01:00
|
|
|
{
|
2023-08-07 08:41:28 +02:00
|
|
|
Base::initialize(realm);
|
2022-03-29 20:36:22 +01:00
|
|
|
|
2024-11-14 05:50:17 +13:00
|
|
|
m_$262 = realm.create<$262Object>(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;
|
2025-03-16 21:25:29 -05:00
|
|
|
define_native_function(realm, "print"_fly_string, print, 1, attr);
|
|
|
|
|
define_direct_property("$262"_fly_string, m_$262, attr);
|
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-12-16 17:49:34 +03:30
|
|
|
auto string = TRY(vm.argument(0).to_byte_string(vm));
|
2022-03-29 20:36:22 +01:00
|
|
|
outln("{}", string);
|
|
|
|
|
return js_undefined();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|