mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-15 23:09:05 +00:00
LibJS: Implement Atomics.sub
This commit is contained in:
parent
f9d8e234b2
commit
d2f6255b91
Notes:
sideshowbarker
2024-07-18 09:02:14 +09:00
Author: https://github.com/trflynn89
Commit: d2f6255b91
Pull-request: https://github.com/SerenityOS/serenity/pull/8656
Reviewed-by: https://github.com/linusg ✅
3 changed files with 94 additions and 0 deletions
|
@ -121,6 +121,7 @@ void AtomicsObject::initialize(GlobalObject& global_object)
|
|||
define_native_function(vm.names.and_, and_, 3, attr);
|
||||
define_native_function(vm.names.load, load, 2, attr);
|
||||
define_native_function(vm.names.or_, or_, 3, attr);
|
||||
define_native_function(vm.names.sub, sub, 3, attr);
|
||||
|
||||
// 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);
|
||||
|
@ -203,4 +204,22 @@ JS_DEFINE_NATIVE_FUNCTION(AtomicsObject::or_)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// 25.4.11 Atomics.sub ( typedArray, index, value ), https://tc39.es/ecma262/#sec-atomics.sub
|
||||
JS_DEFINE_NATIVE_FUNCTION(AtomicsObject::sub)
|
||||
{
|
||||
auto* typed_array = typed_array_from(global_object, vm.argument(0));
|
||||
if (!typed_array)
|
||||
return {};
|
||||
|
||||
auto atomic_sub = [](auto* storage, auto value) { return AK::atomic_fetch_sub(storage, value); };
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, Type) \
|
||||
if (is<ClassName>(typed_array)) \
|
||||
return perform_atomic_operation<Type>(global_object, *typed_array, move(atomic_sub));
|
||||
JS_ENUMERATE_TYPED_ARRAYS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue