mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 00:29:15 +00:00
LibJS: Implement the AsyncDisposableStack interface
This is very similar to the DisposableStack interface, except disposal of resources is promise-based.
This commit is contained in:
parent
5ea0aa5f08
commit
26c2484c2f
Notes:
github-actions[bot]
2025-01-17 19:47:28 +00:00
Author: https://github.com/trflynn89
Commit: 26c2484c2f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3290
22 changed files with 873 additions and 0 deletions
52
Libraries/LibJS/Runtime/AsyncDisposableStackConstructor.cpp
Normal file
52
Libraries/LibJS/Runtime/AsyncDisposableStackConstructor.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/AsyncDisposableStack.h>
|
||||
#include <LibJS/Runtime/AsyncDisposableStackConstructor.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(AsyncDisposableStackConstructor);
|
||||
|
||||
AsyncDisposableStackConstructor::AsyncDisposableStackConstructor(Realm& realm)
|
||||
: NativeFunction(realm.vm().names.AsyncDisposableStack.as_string(), realm.intrinsics().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
void AsyncDisposableStackConstructor::initialize(Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
Base::initialize(realm);
|
||||
|
||||
// 12.4.2.1 AsyncDisposableStack.prototype, https://tc39.es/proposal-explicit-resource-management/#sec-asyncdisposablestack.prototype
|
||||
define_direct_property(vm.names.prototype, realm.intrinsics().async_disposable_stack_prototype(), 0);
|
||||
|
||||
define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
|
||||
}
|
||||
|
||||
// 12.4.1.1 AsyncDisposableStack ( ), https://tc39.es/proposal-explicit-resource-management/#sec-asyncdisposablestack
|
||||
ThrowCompletionOr<Value> AsyncDisposableStackConstructor::call()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. If NewTarget is undefined, throw a TypeError exception.
|
||||
return vm.throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, vm.names.AsyncDisposableStack);
|
||||
}
|
||||
|
||||
// 12.4.1.1 AsyncDisposableStack ( ), https://tc39.es/proposal-explicit-resource-management/#sec-asyncdisposablestack
|
||||
ThrowCompletionOr<GC::Ref<Object>> AsyncDisposableStackConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 2. Let asyncDisposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%AsyncDisposableStack.prototype%", « [[AsyncDisposableState]], [[DisposeCapability]] »).
|
||||
// 3. Set asyncDisposableStack.[[AsyncDisposableState]] to pending.
|
||||
// 4. Set asyncDisposableStack.[[DisposeCapability]] to NewDisposeCapability().
|
||||
// 5. Return asyncDisposableStack.
|
||||
return TRY(ordinary_create_from_constructor<AsyncDisposableStack>(vm, new_target, &Intrinsics::async_disposable_stack_prototype, new_dispose_capability()));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue