mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Begin implementing Atomics
This adds the Atomics object to the global object and sets up only its @@toStringTag property.
This commit is contained in:
parent
df75c35d5b
commit
a61723ec59
Notes:
sideshowbarker
2024-07-18 09:02:42 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/a61723ec599 Pull-request: https://github.com/SerenityOS/serenity/pull/8656 Reviewed-by: https://github.com/linusg ✅
6 changed files with 57 additions and 0 deletions
|
@ -35,6 +35,7 @@ set(SOURCES
|
|||
Runtime/ArrayIterator.cpp
|
||||
Runtime/ArrayIteratorPrototype.cpp
|
||||
Runtime/ArrayPrototype.cpp
|
||||
Runtime/AtomicsObject.cpp
|
||||
Runtime/BigInt.cpp
|
||||
Runtime/BigIntConstructor.cpp
|
||||
Runtime/BigIntObject.cpp
|
||||
|
|
27
Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp
Normal file
27
Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/AtomicsObject.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
AtomicsObject::AtomicsObject(GlobalObject& global_object)
|
||||
: Object(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
void AtomicsObject::initialize(GlobalObject& global_object)
|
||||
{
|
||||
Object::initialize(global_object);
|
||||
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 25.4.15 Atomics [ @@toStringTag ], https://tc39.es/ecma262/#sec-atomics-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Atomics"), Attribute::Configurable);
|
||||
}
|
||||
|
||||
}
|
22
Userland/Libraries/LibJS/Runtime/AtomicsObject.h
Normal file
22
Userland/Libraries/LibJS/Runtime/AtomicsObject.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
class AtomicsObject : public Object {
|
||||
JS_OBJECT(AtomicsObject, Object);
|
||||
|
||||
public:
|
||||
explicit AtomicsObject(GlobalObject&);
|
||||
virtual void initialize(GlobalObject&) override;
|
||||
virtual ~AtomicsObject() override = default;
|
||||
};
|
||||
|
||||
}
|
|
@ -17,6 +17,7 @@ namespace JS {
|
|||
P(__defineSetter__) \
|
||||
P(__lookupGetter__) \
|
||||
P(__lookupSetter__) \
|
||||
P(Atomics) \
|
||||
P(BYTES_PER_ELEMENT) \
|
||||
P(BigInt) \
|
||||
P(Boolean) \
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <LibJS/Runtime/ArrayConstructor.h>
|
||||
#include <LibJS/Runtime/ArrayIteratorPrototype.h>
|
||||
#include <LibJS/Runtime/ArrayPrototype.h>
|
||||
#include <LibJS/Runtime/AtomicsObject.h>
|
||||
#include <LibJS/Runtime/BigIntConstructor.h>
|
||||
#include <LibJS/Runtime/BigIntPrototype.h>
|
||||
#include <LibJS/Runtime/BooleanConstructor.h>
|
||||
|
@ -184,6 +185,7 @@ void GlobalObject::initialize_global_object()
|
|||
|
||||
define_direct_property(vm.names.globalThis, this, attr);
|
||||
define_direct_property(vm.names.console, heap().allocate<ConsoleObject>(*this, *this), attr);
|
||||
define_direct_property(vm.names.Atomics, heap().allocate<AtomicsObject>(*this, *this), attr);
|
||||
define_direct_property(vm.names.Math, heap().allocate<MathObject>(*this, *this), attr);
|
||||
define_direct_property(vm.names.JSON, heap().allocate<JSONObject>(*this, *this), attr);
|
||||
define_direct_property(vm.names.Reflect, heap().allocate<ReflectObject>(*this, *this), attr);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Atomics[Symbol.toStringTag]).toBe("Atomics");
|
||||
expect(Atomics.toString()).toBe("[object Atomics]");
|
||||
});
|
Loading…
Reference in a new issue