Replace assertThrowsInstanceOf with assert.throws in sm/generators

This commit is contained in:
André Bargull 2025-04-30 14:15:51 +02:00 committed by Philip Chimento
parent e44e4bbc1a
commit 3dc9cae778
10 changed files with 53 additions and 54 deletions

View File

@ -20,9 +20,9 @@ var newTarget = Object.defineProperty(function(){}.bind(), "prototype", {
var Generator = function*(){}.constructor; var Generator = function*(){}.constructor;
assertThrowsInstanceOf(() => { assert.throws(SyntaxError, () => {
Reflect.construct(Generator, ["@error"], newTarget); Reflect.construct(Generator, ["@error"], newTarget);
}, SyntaxError); });
assert.sameValue(getProtoCalled, false); assert.sameValue(getProtoCalled, false);

View File

@ -53,7 +53,7 @@ assertIteratorNext(outer, 1);
delete GeneratorObjectPrototype.throw; delete GeneratorObjectPrototype.throw;
var outer_throw_42 = GeneratorObjectPrototype_throw.bind(outer, 42); var outer_throw_42 = GeneratorObjectPrototype_throw.bind(outer, 42);
// yield* protocol violation: no 'throw' method // yield* protocol violation: no 'throw' method
assertThrowsInstanceOf(outer_throw_42, TypeError); assert.throws(TypeError, outer_throw_42);
// Now done, so just throws. // Now done, so just throws.
assertThrowsValue(outer_throw_42, 42); assertThrowsValue(outer_throw_42, 42);

View File

@ -57,7 +57,7 @@ function TestGenerator(g, expected_values_for_next,
j == expected_values_for_next.length - 1); j == expected_values_for_next.length - 1);
} }
var Sentinel = function () {} var Sentinel = function () {}
assertThrowsInstanceOf(function () { iter.throw(new Sentinel); }, Sentinel); assert.throws(Sentinel, function () { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
} }
@ -352,14 +352,14 @@ function TestTryCatch(instantiate) {
Test1(instantiate(g)); Test1(instantiate(g));
function Test2(iter) { function Test2(iter) {
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test2(instantiate(g)); Test2(instantiate(g));
function Test3(iter) { function Test3(iter) {
assertIteratorNext(iter, 1); assertIteratorNext(iter, 1);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test3(instantiate(g)); Test3(instantiate(g));
@ -381,7 +381,7 @@ function TestTryCatch(instantiate) {
var exn = new Sentinel; var exn = new Sentinel;
assertIteratorResult(iter.throw(exn), exn, false); assertIteratorResult(iter.throw(exn), exn, false);
assertIteratorNext(iter, 3); assertIteratorNext(iter, 3);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
@ -392,7 +392,7 @@ function TestTryCatch(instantiate) {
assertIteratorNext(iter, 2); assertIteratorNext(iter, 2);
var exn = new Sentinel; var exn = new Sentinel;
assertIteratorResult(iter.throw(exn), exn, false); assertIteratorResult(iter.throw(exn), exn, false);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test6(instantiate(g)); Test6(instantiate(g));
@ -416,14 +416,14 @@ function TestTryFinally(instantiate) {
Test1(instantiate(g)); Test1(instantiate(g));
function Test2(iter) { function Test2(iter) {
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test2(instantiate(g)); Test2(instantiate(g));
function Test3(iter) { function Test3(iter) {
assertIteratorNext(iter, 1); assertIteratorNext(iter, 1);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test3(instantiate(g)); Test3(instantiate(g));
@ -432,7 +432,7 @@ function TestTryFinally(instantiate) {
assertIteratorNext(iter, 1); assertIteratorNext(iter, 1);
assertIteratorNext(iter, 2); assertIteratorNext(iter, 2);
assertIteratorResult(iter.throw(new Sentinel), 3, false); assertIteratorResult(iter.throw(new Sentinel), 3, false);
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel); assert.throws(Sentinel, function() { iter.next(); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
@ -442,7 +442,7 @@ function TestTryFinally(instantiate) {
assertIteratorNext(iter, 1); assertIteratorNext(iter, 1);
assertIteratorNext(iter, 2); assertIteratorNext(iter, 2);
assertIteratorResult(iter.throw(new Sentinel), 3, false); assertIteratorResult(iter.throw(new Sentinel), 3, false);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel2); }, Sentinel2); assert.throws(Sentinel2, function() { iter.throw(new Sentinel2); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test5(instantiate(g)); Test5(instantiate(g));
@ -451,7 +451,7 @@ function TestTryFinally(instantiate) {
assertIteratorNext(iter, 1); assertIteratorNext(iter, 1);
assertIteratorNext(iter, 2); assertIteratorNext(iter, 2);
assertIteratorNext(iter, 3); assertIteratorNext(iter, 3);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test6(instantiate(g)); Test6(instantiate(g));
@ -461,7 +461,7 @@ function TestTryFinally(instantiate) {
assertIteratorNext(iter, 2); assertIteratorNext(iter, 2);
assertIteratorNext(iter, 3); assertIteratorNext(iter, 3);
assertIteratorNext(iter, 4); assertIteratorNext(iter, 4);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test7(instantiate(g)); Test7(instantiate(g));
@ -495,7 +495,7 @@ function TestNestedTry(instantiate) {
Test1(instantiate(g)); Test1(instantiate(g));
function Test2(iter) { function Test2(iter) {
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel); assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test2(instantiate(g)); Test2(instantiate(g));
@ -503,7 +503,7 @@ function TestNestedTry(instantiate) {
function Test3(iter) { function Test3(iter) {
assertIteratorNext(iter, 1); assertIteratorNext(iter, 1);
assertIteratorResult(iter.throw(new Sentinel), 4, false); assertIteratorResult(iter.throw(new Sentinel), 4, false);
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel); assert.throws(Sentinel, function() { iter.next(); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test3(instantiate(g)); Test3(instantiate(g));
@ -511,7 +511,7 @@ function TestNestedTry(instantiate) {
function Test4(iter) { function Test4(iter) {
assertIteratorNext(iter, 1); assertIteratorNext(iter, 1);
assertIteratorResult(iter.throw(new Sentinel), 4, false); assertIteratorResult(iter.throw(new Sentinel), 4, false);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel2); }, Sentinel2); assert.throws(Sentinel2, function() { iter.throw(new Sentinel2); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test4(instantiate(g)); Test4(instantiate(g));
@ -536,7 +536,7 @@ function TestNestedTry(instantiate) {
var exn = new Sentinel; var exn = new Sentinel;
assertIteratorResult(iter.throw(exn), exn, false); assertIteratorResult(iter.throw(exn), exn, false);
assertIteratorResult(iter.throw(new Sentinel2), 4, false); assertIteratorResult(iter.throw(new Sentinel2), 4, false);
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel2); assert.throws(Sentinel2, function() { iter.next(); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
Test6(instantiate(g)); Test6(instantiate(g));
@ -548,7 +548,7 @@ function TestNestedTry(instantiate) {
assertIteratorResult(iter.throw(exn), exn, false); assertIteratorResult(iter.throw(exn), exn, false);
assertIteratorNext(iter, 3); assertIteratorNext(iter, 3);
assertIteratorResult(iter.throw(new Sentinel2), 4, false); assertIteratorResult(iter.throw(new Sentinel2), 4, false);
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel2); assert.throws(Sentinel2, function() { iter.next(); });
assertIteratorDone(iter, undefined); assertIteratorDone(iter, undefined);
} }
@ -575,9 +575,9 @@ function TestRecursion() {
var iter = g(); var iter = g();
return iter.next(); return iter.next();
} }
assertThrowsInstanceOf(TestNextRecursion, TypeError); assert.throws(TypeError, TestNextRecursion);
assertThrowsInstanceOf(TestSendRecursion, TypeError); assert.throws(TypeError, TestSendRecursion);
assertThrowsInstanceOf(TestThrowRecursion, TypeError); assert.throws(TypeError, TestThrowRecursion);
} }
TestRecursion(); TestRecursion();

View File

@ -41,33 +41,32 @@ function f() {
for (var nonobj of nonobjs) { for (var nonobj of nonobjs) {
var iterable = createIterable(nonobj); var iterable = createIterable(nonobj);
assertThrowsInstanceOf(() => [...iterable], TypeError); assert.throws(TypeError, () => [...iterable]);
assertThrowsInstanceOf(() => f(...iterable), TypeError); assert.throws(TypeError, () => f(...iterable));
assertThrowsInstanceOf(() => { for (var x of iterable) {} }, TypeError); assert.throws(TypeError, () => { for (var x of iterable) {} });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
var [a] = iterable; var [a] = iterable;
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
var [...a] = iterable; var [...a] = iterable;
}, TypeError); });
assertThrowsInstanceOf(() => Array.from(iterable), TypeError); assert.throws(TypeError, () => Array.from(iterable));
assertThrowsInstanceOf(() => new Map(iterable), TypeError); assert.throws(TypeError, () => new Map(iterable));
assertThrowsInstanceOf(() => new Set(iterable), TypeError); assert.throws(TypeError, () => new Set(iterable));
assertThrowsInstanceOf(() => new WeakMap(iterable), TypeError); assert.throws(TypeError, () => new WeakMap(iterable));
assertThrowsInstanceOf(() => new WeakSet(iterable), TypeError); assert.throws(TypeError, () => new WeakSet(iterable));
// FIXME: bug 1232266 assert.throws(TypeError, () => new Int8Array(iterable));
// assertThrowsInstanceOf(() => new Int8Array(iterable), TypeError); assert.throws(TypeError, () => Int8Array.from(iterable));
assertThrowsInstanceOf(() => Int8Array.from(iterable), TypeError);
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
var g = function*() { var g = function*() {
yield* iterable; yield* iterable;
}; };
var v = g(); var v = g();
v.next(); v.next();
}, TypeError); });
} }

View File

@ -40,11 +40,11 @@ function TestGeneratorObjectMethods() {
assert.sameValue(iter.throw.length, 1); assert.sameValue(iter.throw.length, 1);
function TestNonGenerator(non_generator) { function TestNonGenerator(non_generator) {
assertThrowsInstanceOf(function() { iter.next.call(non_generator); }, TypeError); assert.throws(TypeError, function() { iter.next.call(non_generator); });
assertThrowsInstanceOf(function() { iter.next.call(non_generator, 1); }, TypeError); assert.throws(TypeError, function() { iter.next.call(non_generator, 1); });
assertThrowsInstanceOf(function() { iter.return.call(non_generator, 1); }, TypeError); assert.throws(TypeError, function() { iter.return.call(non_generator, 1); });
assertThrowsInstanceOf(function() { iter.throw.call(non_generator, 1); }, TypeError); assert.throws(TypeError, function() { iter.throw.call(non_generator, 1); });
assertThrowsInstanceOf(function() { iter.close.call(non_generator); }, TypeError); assert.throws(TypeError, function() { iter.close.call(non_generator); });
} }
TestNonGenerator(1); TestNonGenerator(1);

View File

@ -19,7 +19,7 @@ esid: pending
// See http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.19.3. // See http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.19.3.
function assertSyntaxError(str) { function assertSyntaxError(str) {
assertThrowsInstanceOf(Function(str), SyntaxError); assert.throws(SyntaxError, Function(str));
} }

View File

@ -60,14 +60,14 @@ function* g() {
yield * yield *
foo foo
} }
assertThrowsInstanceOf(() => Function("function* g() { yield\n* foo }"), SyntaxError); assert.throws(SyntaxError, () => Function("function* g() { yield\n* foo }"));
assertIteratorNext(function*(){ assertIteratorNext(function*(){
yield yield
3 3
}(), undefined) }(), undefined)
// A YieldExpression is not a LogicalORExpression. // A YieldExpression is not a LogicalORExpression.
assertThrowsInstanceOf(() => Function("function* g() { yield ? yield : yield }"), SyntaxError); assert.throws(SyntaxError, () => Function("function* g() { yield ? yield : yield }"));
// You can have a generator in strict mode. // You can have a generator in strict mode.
function* g() { "use strict"; yield 3; yield 4; } function* g() { "use strict"; yield 3; yield 4; }

View File

@ -40,9 +40,9 @@ function test() {
// G.p.throw on an iterator without "throw" calls IteratorClose. // G.p.throw on an iterator without "throw" calls IteratorClose.
var g1 = y(); var g1 = y();
g1.next(); g1.next();
assertThrowsInstanceOf(function() { assert.throws(TypeError, function() {
g1.throw("foo"); g1.throw("foo");
}, TypeError); });
assert.sameValue(returnCalled, ++returnCalledExpected); assert.sameValue(returnCalled, ++returnCalledExpected);
assert.sameValue(nextCalled, ++nextCalledExpected); assert.sameValue(nextCalled, ++nextCalledExpected);
g1.next(); g1.next();
@ -117,9 +117,9 @@ function test() {
}; };
var g5 = y(); var g5 = y();
g5.next(); g5.next();
assertThrowsInstanceOf(function() { assert.throws(TypeError, function() {
g5.return("foo"); g5.return("foo");
}, TypeError); });
assert.sameValue(returnCalled, ++returnCalledExpected); assert.sameValue(returnCalled, ++returnCalledExpected);
// IteratorClose expects iter.return to return an Object. // IteratorClose expects iter.return to return an Object.

View File

@ -29,12 +29,12 @@ for (let primitive of primitives) {
return primitive; return primitive;
} }
}; };
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
function* g() { function* g() {
yield* obj; yield* obj;
} }
for (let x of g()) { for (let x of g()) {
} }
}, TypeError); });
} }

View File

@ -33,7 +33,7 @@ var it = g({
it.next(); it.next();
assertThrowsInstanceOf(() => it.throw(""), TypeError); assert.throws(TypeError, () => it.throw(""));
assert.sameValue(calledReturn, false); assert.sameValue(calledReturn, false);