AsyncDisposableStack.js (2810B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 // Explicit Resource Management 6 // 27.4.3.3 AsyncDisposableStack.prototype.disposeAsync ( ) 7 // https://arai-a.github.io/ecma262-compare/?pr=3000&id=sec-asyncdisposablestack.prototype.disposeAsync 8 async function AsyncDisposableStackDisposeAsyncImpl() { 9 // Step 1. Let asyncDisposableStack be the this value. 10 var asyncDisposableStack = this; 11 12 if (!IsObject(asyncDisposableStack) || (asyncDisposableStack = GuardToAsyncDisposableStackHelper(asyncDisposableStack)) === null) { 13 return callFunction( 14 CallAsyncDisposableStackMethodIfWrapped, 15 this, 16 "$AsyncDisposableStackDisposeAsync" 17 ); 18 } 19 20 // Step 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). 21 // (implicit) 22 // Step 3. If asyncDisposableStack does not have an [[AsyncDisposableState]] internal slot, then 23 var state = UnsafeGetReservedSlot(asyncDisposableStack, DISPOSABLE_STACK_STATE_SLOT); 24 if (state === undefined) { 25 // Step 3.a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »). 26 // Step 3.b. Return promiseCapability.[[Promise]]. 27 // (implicit) 28 ThrowTypeError(JSMSG_INCOMPATIBLE_METHOD, 'disposeAsync', 'method', 'AsyncDisposableStack'); 29 } 30 31 // Step 4. If asyncDisposableStack.[[AsyncDisposableState]] is disposed, then 32 if (state === DISPOSABLE_STACK_STATE_DISPOSED) { 33 // Step 4.a. Perform ! Call(promiseCapability.[[Resolve]], undefined, « undefined »). 34 // Step 4.b. Return promiseCapability.[[Promise]]. 35 return undefined; 36 } 37 38 // Step 5. Set asyncDisposableStack.[[AsyncDisposableState]] to disposed. 39 UnsafeSetReservedSlot(asyncDisposableStack, DISPOSABLE_STACK_STATE_SLOT, DISPOSABLE_STACK_STATE_DISPOSED); 40 41 // Step 6. Let result be Completion(DisposeResources(asyncDisposableStack.[[DisposeCapability]], NormalCompletion(undefined))). 42 // Step 7. IfAbruptRejectPromise(result, promiseCapability). 43 var disposeCapability = UnsafeGetReservedSlot(asyncDisposableStack, DISPOSABLE_STACK_DISPOSABLE_RESOURCE_STACK_SLOT); 44 UnsafeSetReservedSlot(asyncDisposableStack, DISPOSABLE_STACK_DISPOSABLE_RESOURCE_STACK_SLOT, undefined); 45 if (disposeCapability === undefined) { 46 return undefined; 47 } 48 DisposeResourcesAsync(disposeCapability, disposeCapability.length); 49 50 // Step 8. Perform ! Call(promiseCapability.[[Resolve]], undefined, « result »). 51 // Step 9. Return promiseCapability.[[Promise]]. 52 return undefined; 53 } 54 55 function $AsyncDisposableStackDisposeAsync() { 56 return callFunction(AsyncDisposableStackDisposeAsyncImpl, this); 57 } 58 SetCanonicalName($AsyncDisposableStackDisposeAsync, "disposeAsync");