Merge branch 'main' into chromium-export-7eb56ce860

This commit is contained in:
test262-merge-bot 2024-05-19 12:19:57 +02:00 committed by GitHub
commit 0eb7f6eccb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 175 additions and 86 deletions

View File

@ -28,7 +28,8 @@ function asyncTest(testFunc) {
}
}
assert.throwsAsync = async function (expectedErrorConstructor, func, message) {
assert.throwsAsync = function (expectedErrorConstructor, func, message) {
return new Promise(function (resolve) {
var innerThenable;
if (message === undefined) {
message = "";
@ -63,7 +64,7 @@ assert.throwsAsync = async function (expectedErrorConstructor, func, message) {
}
try {
return innerThenable.then(
resolve(innerThenable.then(
function () {
message +=
"Expected a " +
@ -91,7 +92,7 @@ assert.throwsAsync = async function (expectedErrorConstructor, func, message) {
throw new Test262Error(message);
}
}
);
));
} catch (thrown) {
if (typeof thrown !== "object" || thrown === null) {
message +=
@ -108,4 +109,5 @@ assert.throwsAsync = async function (expectedErrorConstructor, func, message) {
}
throw new Test262Error(message);
}
});
};

View File

@ -11,12 +11,12 @@ includes: [asyncHelpers.js, compareArray.js]
var sentinel = { sentinel: true };
asyncTest(
Promise.try(function () {
asyncTest(function () {
return Promise.try(function () {
assert.compareArray(
Array.prototype.slice.call(arguments),
[1, 2, Test262Error, sentinel]
);
}, 1, 2, Test262Error, sentinel)
);
});

View File

@ -20,8 +20,8 @@ class SubPromise extends Promise {
var instance = Promise.try.call(SubPromise, function () {});
assert.sameValue(instance.promise.constructor, SubPromise);
assert.sameValue(instance.promise instanceof SubPromise, true);
assert.sameValue(instance.constructor, SubPromise);
assert.sameValue(instance instanceof SubPromise, true);
assert.sameValue(callCount, 1);
assert.sameValue(typeof executor, 'function');

View File

@ -11,11 +11,11 @@ includes: [asyncHelpers.js]
var sentinel = { sentinel: true };
asyncTest(
Promise.try(function () {
asyncTest(function() {
return Promise.try(function () {
return sentinel;
}).then(function (v) {
assert.sameValue(v, sentinel);
})
);
});

View File

@ -6,12 +6,15 @@ description: Promise.try returns a Promise that rejects when the function throws
esid: sec-promise.try
features: [promise-try]
flags: [async]
includes: [asyncHelpers.js]
---*/
assert.throwsAsync(
asyncTest(function () {
return assert.throwsAsync(
Test262Error,
function () {
Promise.try(function () { throw new Test262Error(); })
return Promise.try(function () { throw new Test262Error(); })
},
"error thrown from callback must become a rejection"
);
);
});

View File

@ -0,0 +1,84 @@
// Copyright (C) 2024 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |
Test developer exposed DisposableStack protype methods adopt() and defer().
includes: [compareArray.js]
features: [explicit-resource-management]
---*/
// adopt() method on disposed stack --------
function TestDisposableStackAdoptOnDisposedStack() {
let stack = new DisposableStack();
stack.dispose();
stack.adopt(42, function(v) {return v});
};
assert.throws(
ReferenceError, () => TestDisposableStackUseOnDisposedStack(),
'Cannot add values to a disposed stack!');
// adopt() method when onDispose is not callable--------
function TestDisposableStackAdoptWithNonCallableOnDispose() {
let stack = new DisposableStack();
stack.adopt(42, 43);
};
assert.throws(
TypeError, () => TestDisposableStackAdoptWithNonCallableOnDispose(),
'onDispose is not callable');
// adopt() method --------
let valuesNormal = [];
(function TestDisposableStackAdopt() {
let stack = new DisposableStack();
stack.adopt(42, function(v) {valuesNormal.push(v)});
const disposable = {
value: 1,
[Symbol.dispose]() {
valuesNormal.push(43);
}
};
stack.use(disposable);
stack.adopt(44, function(v) {valuesNormal.push(v)});
stack.dispose();
})();
assert.compareArray(valuesNormal, [44, 43, 42]);
// defer() method on disposed stack --------
function TestDisposableStackDeferOnDisposedStack() {
let stack = new DisposableStack();
stack.dispose();
stack.defer(() => console.log(42));
};
assert.throws(
ReferenceError, () => TestDisposableStackDeferOnDisposedStack(),
'Cannot add values to a disposed stack!');
// defer() method when onDispose is not callable--------
function TestDisposableStackDeferWithNonCallableOnDispose() {
let stack = new DisposableStack();
stack.defer(42);
};
assert.throws(
TypeError, () => TestDisposableStackDeferWithNonCallableOnDispose(),
'onDispose is not callable');
// defer() method --------
let deferValuesNormal = [];
(function TestDisposableStackAdopt() {
let stack = new DisposableStack();
stack.defer(() => deferValuesNormal.push(42));
const disposable = {
value: 1,
[Symbol.dispose]() {
deferValuesNormal.push(43);
}
};
stack.use(disposable);
stack.defer(() => deferValuesNormal.push(44));
stack.dispose();
})();
assert.compareArray(deferValuesNormal, [44, 43, 42]);