Skip to content

Commit

Permalink
add ticks for empty resources
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jul 22, 2023
1 parent 01f2059 commit c594fce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@
- Moved back into [the initial proposal](https://github.com/tc39/proposal-explicit-resource-management) -> moved to stage 3, [proposal-explicit-resource-management/154](https://github.com/tc39/proposal-explicit-resource-management/pull/154)
- Added `/actual/` namespace entries, disabled forced replacement
- Ignore return value of `[@@dispose]()` method when hint is `async-dispose`, [proposal-explicit-resource-management/180](https://github.com/tc39/proposal-explicit-resource-management/pull/180)
- Added ticks for empty resources, [proposal-explicit-resource-management/163](https://github.com/tc39/proposal-explicit-resource-management/pull/163)
- Added some methods from [`Float16Array` stage 3 proposal](https://github.com/tc39/proposal-float16array):
- There are some reason why I don't want to add `Float16Array` right now, however, make sense to add some methods from this proposal.
- Methods:
Expand Down
23 changes: 17 additions & 6 deletions packages/core-js/internals/add-disposable-resource.js
Expand Up @@ -3,6 +3,7 @@ var call = require('../internals/function-call');
var uncurryThis = require('../internals/function-uncurry-this');
var bind = require('../internals/function-bind-context');
var anObject = require('../internals/an-object');
var aCallable = require('../internals/a-callable');
var isNullOrUndefined = require('../internals/is-null-or-undefined');
var getMethod = require('../internals/get-method');
var wellKnownSymbol = require('../internals/well-known-symbol');
Expand All @@ -12,8 +13,10 @@ var DISPOSE = wellKnownSymbol('dispose');

var push = uncurryThis([].push);

// `GetDisposeMethod` abstract operation
// https://tc39.es/proposal-explicit-resource-management/#sec-getdisposemethod
var getDisposeMethod = function (V, hint) {
if (hint == 'async-dispose') {
if (hint === 'async-dispose') {
var method = getMethod(V, ASYNC_DISPOSE);
if (method !== undefined) return method;
method = getMethod(V, DISPOSE);
Expand All @@ -26,16 +29,24 @@ var getDisposeMethod = function (V, hint) {
// `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);
if (arguments.length < 3 && !isNullOrUndefined(V)) {
method = aCallable(getDisposeMethod(anObject(V), hint));
}

return method === undefined ? function () {
return undefined;
} : bind(method, V);
};

// `AddDisposableResource` abstract operation
// https://tc39.es/proposal-explicit-resource-management/#sec-adddisposableresource-disposable-v-hint-disposemethod
// https://tc39.es/proposal-explicit-resource-management/#sec-adddisposableresource
module.exports = function (disposable, V, hint, method) {
var resource;
if (!method) {
if (isNullOrUndefined(V)) return;
resource = createDisposableResource(anObject(V), hint);
if (arguments.length < 4) {
// When `V`` is either `null` or `undefined` and hint is `async-dispose`,
// we record that the resource was evaluated to ensure we will still perform an `Await` when resources are later disposed.
if (isNullOrUndefined(V) && hint === 'sync-dispose') return;
resource = createDisposableResource(V, hint);
} else {
resource = createDisposableResource(undefined, hint, method);
}
Expand Down

0 comments on commit c594fce

Please sign in to comment.