mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:47:35 +00:00
LibJS: Implement Atomics.isLockFree
This commit is contained in:
parent
d9c2447999
commit
1a3e1bff7b
4 changed files with 46 additions and 0 deletions
|
@ -122,6 +122,7 @@ void AtomicsObject::initialize(GlobalObject& global_object)
|
|||
define_native_function(vm.names.and_, and_, 3, attr);
|
||||
define_native_function(vm.names.compareExchange, compare_exchange, 4, attr);
|
||||
define_native_function(vm.names.exchange, exchange, 3, attr);
|
||||
define_native_function(vm.names.isLockFree, is_lock_free, 1, attr);
|
||||
define_native_function(vm.names.load, load, 2, attr);
|
||||
define_native_function(vm.names.or_, or_, 3, attr);
|
||||
define_native_function(vm.names.store, store, 3, attr);
|
||||
|
@ -262,6 +263,24 @@ JS_DEFINE_NATIVE_FUNCTION(AtomicsObject::exchange)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// 25.4.7 Atomics.isLockFree ( size ), https://tc39.es/ecma262/#sec-atomics.islockfree
|
||||
JS_DEFINE_NATIVE_FUNCTION(AtomicsObject::is_lock_free)
|
||||
{
|
||||
auto size = vm.argument(0).to_integer_or_infinity(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
if (size == 1)
|
||||
return Value(AK::atomic_is_lock_free<u8>());
|
||||
if (size == 2)
|
||||
return Value(AK::atomic_is_lock_free<u16>());
|
||||
if (size == 4)
|
||||
return Value(true);
|
||||
if (size == 8)
|
||||
return Value(AK::atomic_is_lock_free<u64>());
|
||||
return Value(false);
|
||||
}
|
||||
|
||||
// 25.4.8 Atomics.load ( typedArray, index ), https://tc39.es/ecma262/#sec-atomics.load
|
||||
JS_DEFINE_NATIVE_FUNCTION(AtomicsObject::load)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue