Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function use(value)
if (@getAsyncDisposableStackInternalField(this, @asyncDisposableStackFieldState) === @AsyncDisposableStackStateDisposed)
throw new @ReferenceError("AsyncDisposableStack.prototype.use requires that |this| be a pending AsyncDisposableStack object");

@addDisposableResource(@getDisposableStackInternalField(this, @disposableStackFieldCapability), value, /* isAsync */ true);
@addDisposableResource(@getAsyncDisposableStackInternalField(this, @asyncDisposableStackFieldCapability), value, /* isAsync */ true);

return value;
}
27 changes: 23 additions & 4 deletions Source/JavaScriptCore/builtins/DisposableStackPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,31 @@ function getAsyncDisposableMethod(value)

var method = value.@@asyncDispose;

if (@isUndefinedOrNull(method)) {
// Per spec, fall back to @@dispose when @@asyncDispose is not present.
method = value.@@dispose;

if (@isUndefinedOrNull(method))
return @undefined;

if (!@isCallable(method))
@throwTypeError("@@dispose must be callable");

// Wrap the sync dispose method to return a Promise.
var syncMethod = method;
return () => {
try {
syncMethod.@call(value);
} catch (e) {
return @promiseReject(@Promise, e);
}
return @promiseResolve(@Promise, @undefined);
};
}

if (!@isCallable(method))
@throwTypeError("@@asyncDispose must be callable");

if (@isUndefinedOrNull(method))
return @undefined;

return () => {
try {
method.@call(value);
Expand All @@ -63,7 +82,7 @@ function createDisposableResource(value, isAsync /* , method */)
if (isAsync) {
method = @getAsyncDisposableMethod(value);
if (method === @undefined)
@throwTypeError("@@asyncDispose must not be an undefined");
@throwTypeError("Either @@asyncDispose or @@dispose is required");
} else {
method = value.@@dispose;
if (!@isCallable(method))
Expand Down
Loading