source: imaps-frontend/node_modules/core-js/internals/add-disposable-resource.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.3 KB
Line 
1'use strict';
2var getBuiltIn = require('../internals/get-built-in');
3var call = require('../internals/function-call');
4var uncurryThis = require('../internals/function-uncurry-this');
5var bind = require('../internals/function-bind-context');
6var anObject = require('../internals/an-object');
7var aCallable = require('../internals/a-callable');
8var isNullOrUndefined = require('../internals/is-null-or-undefined');
9var getMethod = require('../internals/get-method');
10var wellKnownSymbol = require('../internals/well-known-symbol');
11
12var ASYNC_DISPOSE = wellKnownSymbol('asyncDispose');
13var DISPOSE = wellKnownSymbol('dispose');
14
15var push = uncurryThis([].push);
16
17// `GetDisposeMethod` abstract operation
18// https://tc39.es/proposal-explicit-resource-management/#sec-getdisposemethod
19var getDisposeMethod = function (V, hint) {
20 if (hint === 'async-dispose') {
21 var method = getMethod(V, ASYNC_DISPOSE);
22 if (method !== undefined) return method;
23 method = getMethod(V, DISPOSE);
24 if (method === undefined) return method;
25 return function () {
26 var O = this;
27 var Promise = getBuiltIn('Promise');
28 return new Promise(function (resolve) {
29 call(method, O);
30 resolve(undefined);
31 });
32 };
33 } return getMethod(V, DISPOSE);
34};
35
36// `CreateDisposableResource` abstract operation
37// https://tc39.es/proposal-explicit-resource-management/#sec-createdisposableresource
38var createDisposableResource = function (V, hint, method) {
39 if (arguments.length < 3 && !isNullOrUndefined(V)) {
40 method = aCallable(getDisposeMethod(anObject(V), hint));
41 }
42
43 return method === undefined ? function () {
44 return undefined;
45 } : bind(method, V);
46};
47
48// `AddDisposableResource` abstract operation
49// https://tc39.es/proposal-explicit-resource-management/#sec-adddisposableresource
50module.exports = function (disposable, V, hint, method) {
51 var resource;
52 if (arguments.length < 4) {
53 // When `V`` is either `null` or `undefined` and hint is `async-dispose`,
54 // we record that the resource was evaluated to ensure we will still perform an `Await` when resources are later disposed.
55 if (isNullOrUndefined(V) && hint === 'sync-dispose') return;
56 resource = createDisposableResource(V, hint);
57 } else {
58 resource = createDisposableResource(undefined, hint, method);
59 }
60
61 push(disposable.stack, resource);
62};
Note: See TracBrowser for help on using the repository browser.