mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 05:55:36 +02:00
Merge branch 'main' into chromium-export-7eb56ce860
This commit is contained in:
commit
0eb7f6eccb
@ -28,84 +28,86 @@ function asyncTest(testFunc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.throwsAsync = async function (expectedErrorConstructor, func, message) {
|
assert.throwsAsync = function (expectedErrorConstructor, func, message) {
|
||||||
var innerThenable;
|
return new Promise(function (resolve) {
|
||||||
if (message === undefined) {
|
var innerThenable;
|
||||||
message = "";
|
if (message === undefined) {
|
||||||
} else {
|
message = "";
|
||||||
message += " ";
|
} else {
|
||||||
}
|
message += " ";
|
||||||
if (typeof func === "function") {
|
|
||||||
try {
|
|
||||||
innerThenable = func();
|
|
||||||
if (
|
|
||||||
innerThenable === null ||
|
|
||||||
typeof innerThenable !== "object" ||
|
|
||||||
typeof innerThenable.then !== "function"
|
|
||||||
) {
|
|
||||||
message +=
|
|
||||||
"Expected to obtain an inner promise that would reject with a" +
|
|
||||||
expectedErrorConstructor.name +
|
|
||||||
" but result was not a thenable";
|
|
||||||
throw new Test262Error(message);
|
|
||||||
}
|
|
||||||
} catch (thrown) {
|
|
||||||
message +=
|
|
||||||
"Expected a " +
|
|
||||||
expectedErrorConstructor.name +
|
|
||||||
" to be thrown asynchronously but an exception was thrown synchronously while obtaining the inner promise";
|
|
||||||
throw new Test262Error(message);
|
|
||||||
}
|
}
|
||||||
} else {
|
if (typeof func === "function") {
|
||||||
message +=
|
try {
|
||||||
"assert.throwsAsync called with an argument that is not a function";
|
innerThenable = func();
|
||||||
throw new Test262Error(message);
|
if (
|
||||||
}
|
innerThenable === null ||
|
||||||
|
typeof innerThenable !== "object" ||
|
||||||
try {
|
typeof innerThenable.then !== "function"
|
||||||
return innerThenable.then(
|
) {
|
||||||
function () {
|
message +=
|
||||||
|
"Expected to obtain an inner promise that would reject with a" +
|
||||||
|
expectedErrorConstructor.name +
|
||||||
|
" but result was not a thenable";
|
||||||
|
throw new Test262Error(message);
|
||||||
|
}
|
||||||
|
} catch (thrown) {
|
||||||
message +=
|
message +=
|
||||||
"Expected a " +
|
"Expected a " +
|
||||||
expectedErrorConstructor.name +
|
expectedErrorConstructor.name +
|
||||||
" to be thrown asynchronously but no exception was thrown at all";
|
" to be thrown asynchronously but an exception was thrown synchronously while obtaining the inner promise";
|
||||||
throw new Test262Error(message);
|
throw new Test262Error(message);
|
||||||
},
|
|
||||||
function (thrown) {
|
|
||||||
var expectedName, actualName;
|
|
||||||
if (typeof thrown !== "object" || thrown === null) {
|
|
||||||
message += "Thrown value was not an object!";
|
|
||||||
throw new Test262Error(message);
|
|
||||||
} else if (thrown.constructor !== expectedErrorConstructor) {
|
|
||||||
expectedName = expectedErrorConstructor.name;
|
|
||||||
actualName = thrown.constructor.name;
|
|
||||||
if (expectedName === actualName) {
|
|
||||||
message +=
|
|
||||||
"Expected a " +
|
|
||||||
expectedName +
|
|
||||||
" but got a different error constructor with the same name";
|
|
||||||
} else {
|
|
||||||
message +=
|
|
||||||
"Expected a " + expectedName + " but got a " + actualName;
|
|
||||||
}
|
|
||||||
throw new Test262Error(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
} catch (thrown) {
|
|
||||||
if (typeof thrown !== "object" || thrown === null) {
|
|
||||||
message +=
|
|
||||||
"Expected a " +
|
|
||||||
expectedErrorConstructor.name +
|
|
||||||
" to be thrown asynchronously but innerThenable synchronously threw a value that was not an object ";
|
|
||||||
} else {
|
} else {
|
||||||
message +=
|
message +=
|
||||||
"Expected a " +
|
"assert.throwsAsync called with an argument that is not a function";
|
||||||
expectedErrorConstructor.name +
|
throw new Test262Error(message);
|
||||||
" to be thrown asynchronously but a " +
|
|
||||||
thrown.constructor.name +
|
|
||||||
" was thrown synchronously";
|
|
||||||
}
|
}
|
||||||
throw new Test262Error(message);
|
|
||||||
}
|
try {
|
||||||
|
resolve(innerThenable.then(
|
||||||
|
function () {
|
||||||
|
message +=
|
||||||
|
"Expected a " +
|
||||||
|
expectedErrorConstructor.name +
|
||||||
|
" to be thrown asynchronously but no exception was thrown at all";
|
||||||
|
throw new Test262Error(message);
|
||||||
|
},
|
||||||
|
function (thrown) {
|
||||||
|
var expectedName, actualName;
|
||||||
|
if (typeof thrown !== "object" || thrown === null) {
|
||||||
|
message += "Thrown value was not an object!";
|
||||||
|
throw new Test262Error(message);
|
||||||
|
} else if (thrown.constructor !== expectedErrorConstructor) {
|
||||||
|
expectedName = expectedErrorConstructor.name;
|
||||||
|
actualName = thrown.constructor.name;
|
||||||
|
if (expectedName === actualName) {
|
||||||
|
message +=
|
||||||
|
"Expected a " +
|
||||||
|
expectedName +
|
||||||
|
" but got a different error constructor with the same name";
|
||||||
|
} else {
|
||||||
|
message +=
|
||||||
|
"Expected a " + expectedName + " but got a " + actualName;
|
||||||
|
}
|
||||||
|
throw new Test262Error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
} catch (thrown) {
|
||||||
|
if (typeof thrown !== "object" || thrown === null) {
|
||||||
|
message +=
|
||||||
|
"Expected a " +
|
||||||
|
expectedErrorConstructor.name +
|
||||||
|
" to be thrown asynchronously but innerThenable synchronously threw a value that was not an object ";
|
||||||
|
} else {
|
||||||
|
message +=
|
||||||
|
"Expected a " +
|
||||||
|
expectedErrorConstructor.name +
|
||||||
|
" to be thrown asynchronously but a " +
|
||||||
|
thrown.constructor.name +
|
||||||
|
" was thrown synchronously";
|
||||||
|
}
|
||||||
|
throw new Test262Error(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@ -11,12 +11,12 @@ includes: [asyncHelpers.js, compareArray.js]
|
|||||||
|
|
||||||
var sentinel = { sentinel: true };
|
var sentinel = { sentinel: true };
|
||||||
|
|
||||||
asyncTest(
|
asyncTest(function () {
|
||||||
Promise.try(function () {
|
return Promise.try(function () {
|
||||||
assert.compareArray(
|
assert.compareArray(
|
||||||
Array.prototype.slice.call(arguments),
|
Array.prototype.slice.call(arguments),
|
||||||
[1, 2, Test262Error, sentinel]
|
[1, 2, Test262Error, sentinel]
|
||||||
);
|
);
|
||||||
}, 1, 2, Test262Error, sentinel)
|
}, 1, 2, Test262Error, sentinel)
|
||||||
);
|
});
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ class SubPromise extends Promise {
|
|||||||
|
|
||||||
var instance = Promise.try.call(SubPromise, function () {});
|
var instance = Promise.try.call(SubPromise, function () {});
|
||||||
|
|
||||||
assert.sameValue(instance.promise.constructor, SubPromise);
|
assert.sameValue(instance.constructor, SubPromise);
|
||||||
assert.sameValue(instance.promise instanceof SubPromise, true);
|
assert.sameValue(instance instanceof SubPromise, true);
|
||||||
|
|
||||||
assert.sameValue(callCount, 1);
|
assert.sameValue(callCount, 1);
|
||||||
assert.sameValue(typeof executor, 'function');
|
assert.sameValue(typeof executor, 'function');
|
||||||
|
@ -11,11 +11,11 @@ includes: [asyncHelpers.js]
|
|||||||
|
|
||||||
var sentinel = { sentinel: true };
|
var sentinel = { sentinel: true };
|
||||||
|
|
||||||
asyncTest(
|
asyncTest(function() {
|
||||||
Promise.try(function () {
|
return Promise.try(function () {
|
||||||
return sentinel;
|
return sentinel;
|
||||||
}).then(function (v) {
|
}).then(function (v) {
|
||||||
assert.sameValue(v, sentinel);
|
assert.sameValue(v, sentinel);
|
||||||
})
|
})
|
||||||
);
|
});
|
||||||
|
|
||||||
|
@ -6,12 +6,15 @@ description: Promise.try returns a Promise that rejects when the function throws
|
|||||||
esid: sec-promise.try
|
esid: sec-promise.try
|
||||||
features: [promise-try]
|
features: [promise-try]
|
||||||
flags: [async]
|
flags: [async]
|
||||||
|
includes: [asyncHelpers.js]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
assert.throwsAsync(
|
asyncTest(function () {
|
||||||
Test262Error,
|
return assert.throwsAsync(
|
||||||
function () {
|
Test262Error,
|
||||||
Promise.try(function () { throw new Test262Error(); })
|
function () {
|
||||||
},
|
return Promise.try(function () { throw new Test262Error(); })
|
||||||
"error thrown from callback must become a rejection"
|
},
|
||||||
);
|
"error thrown from callback must become a rejection"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
@ -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]);
|
Loading…
x
Reference in New Issue
Block a user