1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:07:34 +00:00

LibJS: Move DetachArrayBuffer implementation to the ArrayBuffer object

The spec notes that this AO is unused by ECMA-262, but is provided for
ECMAScript hosts. Move the definition to a common location to allow
test-js to also use it.
This commit is contained in:
Timothy Flynn 2022-04-07 13:03:08 -04:00 committed by Linus Groh
parent ce08fae13b
commit 13d05403ff
4 changed files with 28 additions and 5 deletions

View file

@ -62,17 +62,14 @@ JS_DEFINE_NATIVE_FUNCTION($262Object::create_realm)
return Value(realm->$262());
}
// 25.1.2.3 DetachArrayBuffer, https://tc39.es/ecma262/#sec-detacharraybuffer
JS_DEFINE_NATIVE_FUNCTION($262Object::detach_array_buffer)
{
auto array_buffer = vm.argument(0);
if (!array_buffer.is_object() || !is<ArrayBuffer>(array_buffer.as_object()))
return vm.throw_completion<TypeError>(global_object);
auto& array_buffer_object = static_cast<ArrayBuffer&>(array_buffer.as_object());
if (!same_value(array_buffer_object.detach_key(), vm.argument(1)))
return vm.throw_completion<TypeError>(global_object);
array_buffer_object.detach_buffer();
return js_null();
return JS::detach_array_buffer(global_object, array_buffer_object, vm.argument(1));
}
JS_DEFINE_NATIVE_FUNCTION($262Object::eval_script)