| 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 Proposal |
| 6 |
// 27.3.3.3 DisposableStack.prototype.dispose ( ) |
| 7 |
// https://arai-a.github.io/ecma262-compare/?pr=3000&id=sec-disposablestack.prototype.dispose |
| 8 |
function $DisposableStackDispose() { |
| 9 |
// Step 1. Let disposableStack be the this value. |
| 10 |
var disposableStack = this; |
| 11 |
|
| 12 |
if (!IsObject(disposableStack) || (disposableStack = GuardToDisposableStackHelper(disposableStack)) === null) { |
| 13 |
return callFunction( |
| 14 |
CallDisposableStackMethodIfWrapped, |
| 15 |
this, |
| 16 |
"$DisposableStackDispose" |
| 17 |
); |
| 18 |
} |
| 19 |
|
| 20 |
// Step 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]). |
| 21 |
var state = UnsafeGetReservedSlot(disposableStack, DISPOSABLE_STACK_STATE_SLOT); |
| 22 |
|
| 23 |
// Step 3. If disposableStack.[[DisposableState]] is disposed, return undefined. |
| 24 |
if (state === DISPOSABLE_STACK_STATE_DISPOSED) { |
| 25 |
return undefined; |
| 26 |
} |
| 27 |
|
| 28 |
// Step 4. Set disposableStack.[[DisposableState]] to disposed. |
| 29 |
UnsafeSetReservedSlot(disposableStack, DISPOSABLE_STACK_STATE_SLOT, DISPOSABLE_STACK_STATE_DISPOSED); |
| 30 |
|
| 31 |
// Step 5. Return ? DisposeResources(disposableStack.[[DisposeCapability]], NormalCompletion(undefined)). |
| 32 |
var disposeCapability = UnsafeGetReservedSlot(disposableStack, DISPOSABLE_STACK_DISPOSABLE_RESOURCE_STACK_SLOT); |
| 33 |
UnsafeSetReservedSlot(disposableStack, DISPOSABLE_STACK_DISPOSABLE_RESOURCE_STACK_SLOT, undefined); |
| 34 |
// disposeCapability being undefined indicates that its an empty stack, thus |
| 35 |
// all the following operations are no-ops, hence we can return early. |
| 36 |
if (disposeCapability === undefined) { |
| 37 |
return undefined; |
| 38 |
} |
| 39 |
DisposeResourcesSync(disposeCapability, disposeCapability.length); |
| 40 |
|
| 41 |
return undefined; |
| 42 |
} |
| 43 |
SetCanonicalName($DisposableStackDispose, "dispose"); |