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;
assertThrowsInstanceOf(() => {
assert.throws(SyntaxError, () => {
Reflect.construct(Generator, ["@error"], newTarget);
}, SyntaxError);
});
assert.sameValue(getProtoCalled, false);

View File

@ -53,7 +53,7 @@ assertIteratorNext(outer, 1);
delete GeneratorObjectPrototype.throw;
var outer_throw_42 = GeneratorObjectPrototype_throw.bind(outer, 42);
// yield* protocol violation: no 'throw' method
assertThrowsInstanceOf(outer_throw_42, TypeError);
assert.throws(TypeError, outer_throw_42);
// Now done, so just throws.
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);
}
var Sentinel = function () {}
assertThrowsInstanceOf(function () { iter.throw(new Sentinel); }, Sentinel);
assert.throws(Sentinel, function () { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined);
}
}
@ -352,14 +352,14 @@ function TestTryCatch(instantiate) {
Test1(instantiate(g));
function Test2(iter) {
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined);
}
Test2(instantiate(g));
function Test3(iter) {
assertIteratorNext(iter, 1);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined);
}
Test3(instantiate(g));
@ -381,7 +381,7 @@ function TestTryCatch(instantiate) {
var exn = new Sentinel;
assertIteratorResult(iter.throw(exn), exn, false);
assertIteratorNext(iter, 3);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined);
}
@ -392,7 +392,7 @@ function TestTryCatch(instantiate) {
assertIteratorNext(iter, 2);
var exn = new Sentinel;
assertIteratorResult(iter.throw(exn), exn, false);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined);
}
Test6(instantiate(g));
@ -416,14 +416,14 @@ function TestTryFinally(instantiate) {
Test1(instantiate(g));
function Test2(iter) {
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined);
}
Test2(instantiate(g));
function Test3(iter) {
assertIteratorNext(iter, 1);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined);
}
Test3(instantiate(g));
@ -432,7 +432,7 @@ function TestTryFinally(instantiate) {
assertIteratorNext(iter, 1);
assertIteratorNext(iter, 2);
assertIteratorResult(iter.throw(new Sentinel), 3, false);
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel);
assert.throws(Sentinel, function() { iter.next(); });
assertIteratorDone(iter, undefined);
}
@ -442,7 +442,7 @@ function TestTryFinally(instantiate) {
assertIteratorNext(iter, 1);
assertIteratorNext(iter, 2);
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);
}
Test5(instantiate(g));
@ -451,7 +451,7 @@ function TestTryFinally(instantiate) {
assertIteratorNext(iter, 1);
assertIteratorNext(iter, 2);
assertIteratorNext(iter, 3);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined);
}
Test6(instantiate(g));
@ -461,7 +461,7 @@ function TestTryFinally(instantiate) {
assertIteratorNext(iter, 2);
assertIteratorNext(iter, 3);
assertIteratorNext(iter, 4);
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined);
}
Test7(instantiate(g));
@ -495,7 +495,7 @@ function TestNestedTry(instantiate) {
Test1(instantiate(g));
function Test2(iter) {
assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
assert.throws(Sentinel, function() { iter.throw(new Sentinel); });
assertIteratorDone(iter, undefined);
}
Test2(instantiate(g));
@ -503,7 +503,7 @@ function TestNestedTry(instantiate) {
function Test3(iter) {
assertIteratorNext(iter, 1);
assertIteratorResult(iter.throw(new Sentinel), 4, false);
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel);
assert.throws(Sentinel, function() { iter.next(); });
assertIteratorDone(iter, undefined);
}
Test3(instantiate(g));
@ -511,7 +511,7 @@ function TestNestedTry(instantiate) {
function Test4(iter) {
assertIteratorNext(iter, 1);
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);
}
Test4(instantiate(g));
@ -536,7 +536,7 @@ function TestNestedTry(instantiate) {
var exn = new Sentinel;
assertIteratorResult(iter.throw(exn), exn, false);
assertIteratorResult(iter.throw(new Sentinel2), 4, false);
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel2);
assert.throws(Sentinel2, function() { iter.next(); });
assertIteratorDone(iter, undefined);
}
Test6(instantiate(g));
@ -548,7 +548,7 @@ function TestNestedTry(instantiate) {
assertIteratorResult(iter.throw(exn), exn, false);
assertIteratorNext(iter, 3);
assertIteratorResult(iter.throw(new Sentinel2), 4, false);
assertThrowsInstanceOf(function() { iter.next(); }, Sentinel2);
assert.throws(Sentinel2, function() { iter.next(); });
assertIteratorDone(iter, undefined);
}
@ -575,9 +575,9 @@ function TestRecursion() {
var iter = g();
return iter.next();
}
assertThrowsInstanceOf(TestNextRecursion, TypeError);
assertThrowsInstanceOf(TestSendRecursion, TypeError);
assertThrowsInstanceOf(TestThrowRecursion, TypeError);
assert.throws(TypeError, TestNextRecursion);
assert.throws(TypeError, TestSendRecursion);
assert.throws(TypeError, TestThrowRecursion);
}
TestRecursion();

View File

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

View File

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

View File

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

View File

@ -60,14 +60,14 @@ function* g() {
yield *
foo
}
assertThrowsInstanceOf(() => Function("function* g() { yield\n* foo }"), SyntaxError);
assert.throws(SyntaxError, () => Function("function* g() { yield\n* foo }"));
assertIteratorNext(function*(){
yield
3
}(), undefined)
// 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.
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.
var g1 = y();
g1.next();
assertThrowsInstanceOf(function() {
assert.throws(TypeError, function() {
g1.throw("foo");
}, TypeError);
});
assert.sameValue(returnCalled, ++returnCalledExpected);
assert.sameValue(nextCalled, ++nextCalledExpected);
g1.next();
@ -117,9 +117,9 @@ function test() {
};
var g5 = y();
g5.next();
assertThrowsInstanceOf(function() {
assert.throws(TypeError, function() {
g5.return("foo");
}, TypeError);
});
assert.sameValue(returnCalled, ++returnCalledExpected);
// IteratorClose expects iter.return to return an Object.

View File

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

View File

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