/src/serenity/Userland/Libraries/LibJS/Runtime/DisposableStackConstructor.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2022, David Tuin <davidot@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibJS/Runtime/AbstractOperations.h> |
8 | | #include <LibJS/Runtime/DisposableStack.h> |
9 | | #include <LibJS/Runtime/DisposableStackConstructor.h> |
10 | | |
11 | | namespace JS { |
12 | | |
13 | | JS_DEFINE_ALLOCATOR(DisposableStackConstructor); |
14 | | |
15 | | DisposableStackConstructor::DisposableStackConstructor(Realm& realm) |
16 | 0 | : NativeFunction(realm.vm().names.DisposableStack.as_string(), realm.intrinsics().function_prototype()) |
17 | 0 | { |
18 | 0 | } |
19 | | |
20 | | void DisposableStackConstructor::initialize(Realm& realm) |
21 | 0 | { |
22 | 0 | auto& vm = this->vm(); |
23 | 0 | Base::initialize(realm); |
24 | | |
25 | | // 26.2.2.1 DisposableStack.prototype, https://tc39.es/ecma262/#sec-finalization-registry.prototype |
26 | 0 | define_direct_property(vm.names.prototype, realm.intrinsics().disposable_stack_prototype(), 0); |
27 | |
|
28 | 0 | define_direct_property(vm.names.length, Value(0), Attribute::Configurable); |
29 | 0 | } |
30 | | |
31 | | // 11.3.1.1 DisposableStack ( ), https://tc39.es/proposal-explicit-resource-management/#sec-disposablestack |
32 | | ThrowCompletionOr<Value> DisposableStackConstructor::call() |
33 | 0 | { |
34 | 0 | auto& vm = this->vm(); |
35 | | |
36 | | // 1. If NewTarget is undefined, throw a TypeError exception. |
37 | 0 | return vm.throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, vm.names.DisposableStack); |
38 | 0 | } |
39 | | |
40 | | // 11.3.1.1 DisposableStack ( ), https://tc39.es/proposal-explicit-resource-management/#sec-disposablestack |
41 | | ThrowCompletionOr<NonnullGCPtr<Object>> DisposableStackConstructor::construct(FunctionObject& new_target) |
42 | 0 | { |
43 | 0 | auto& vm = this->vm(); |
44 | | |
45 | | // 2. Let disposableStack be ? OrdinaryCreateFromConstructor(NewTarget, "%DisposableStack.prototype%", « [[DisposableState]], [[DisposableResourceStack]] »). |
46 | | // 3. Set disposableStack.[[DisposableState]] to pending. |
47 | | // 4. Set disposableStack.[[DisposableResourceStack]] to a new empty List. |
48 | | // 5. Return disposableStack. |
49 | 0 | return TRY(ordinary_create_from_constructor<DisposableStack>(vm, new_target, &Intrinsics::disposable_stack_prototype, Vector<DisposableResource> {})); |
50 | 0 | } |
51 | | |
52 | | } |