You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.4 KiB
38 lines
1.4 KiB
2 years ago
|
var uncurryThis = require('../internals/function-uncurry-this');
|
||
|
var bind = require('../internals/function-bind-context');
|
||
|
var anObject = require('../internals/an-object');
|
||
|
var isNullOrUndefined = require('../internals/is-null-or-undefined');
|
||
|
var getMethod = require('../internals/get-method');
|
||
|
var wellKnownSymbol = require('../internals/well-known-symbol');
|
||
|
|
||
|
var ASYNC_DISPOSE = wellKnownSymbol('asyncDispose');
|
||
|
var DISPOSE = wellKnownSymbol('dispose');
|
||
|
|
||
|
var push = uncurryThis([].push);
|
||
|
|
||
|
var getDisposeMethod = function (V, hint) {
|
||
|
if (hint == 'async-dispose') {
|
||
|
return getMethod(V, ASYNC_DISPOSE) || getMethod(V, DISPOSE);
|
||
|
} return getMethod(V, DISPOSE);
|
||
|
};
|
||
|
|
||
|
// `CreateDisposableResource` abstract operation
|
||
|
// https://tc39.es/proposal-explicit-resource-management/#sec-createdisposableresource
|
||
|
var createDisposableResource = function (V, hint, method) {
|
||
|
return bind(method || getDisposeMethod(V, hint), V);
|
||
|
};
|
||
|
|
||
|
// `AddDisposableResource` abstract operation
|
||
|
// https://tc39.es/proposal-explicit-resource-management/#sec-adddisposableresource-disposable-v-hint-disposemethod
|
||
|
module.exports = function (disposable, V, hint, method) {
|
||
|
var resource;
|
||
|
if (!method) {
|
||
|
if (isNullOrUndefined(V)) return;
|
||
|
resource = createDisposableResource(anObject(V), hint);
|
||
|
} else {
|
||
|
resource = createDisposableResource(undefined, hint, method);
|
||
|
}
|
||
|
|
||
|
push(disposable.stack, resource);
|
||
|
};
|