mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 14:30:27 +02:00
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
133 lines
3.1 KiB
JavaScript
133 lines
3.1 KiB
JavaScript
function shouldBe(actual, expected) {
|
|
if (actual !== expected)
|
|
throw new Error(`bad value: ${String(actual)}`);
|
|
}
|
|
|
|
function shouldBeIteratorResult(actual, { value, done })
|
|
{
|
|
shouldBe(actual.value, value);
|
|
shouldBe(actual.done, done);
|
|
}
|
|
|
|
function shouldThrow(func, errorMessage) {
|
|
var errorThrown = false;
|
|
var error = null;
|
|
try {
|
|
func();
|
|
} catch (e) {
|
|
errorThrown = true;
|
|
error = e;
|
|
}
|
|
if (!errorThrown)
|
|
throw new Error('not thrown');
|
|
if (String(error) !== errorMessage)
|
|
throw new Error(`bad error: ${String(error)}`);
|
|
}
|
|
|
|
class CallSite {
|
|
constructor()
|
|
{
|
|
this.count = 0;
|
|
}
|
|
|
|
call()
|
|
{
|
|
return this.count++;
|
|
}
|
|
}
|
|
|
|
(function () {
|
|
function *gen() {
|
|
yield yield 20;
|
|
yield 42;
|
|
}
|
|
|
|
{
|
|
let g = gen();
|
|
shouldBeIteratorResult(g.next(0), { value: 20, done: false });
|
|
shouldThrow(() => g.throw(20), `20`);
|
|
shouldThrow(() => g.throw(20), `20`);
|
|
shouldBeIteratorResult(g.next(42), { value: undefined, done: true });
|
|
shouldBeIteratorResult(g.return(42), { value: 42, done: true });
|
|
}
|
|
{
|
|
let g = gen();
|
|
shouldThrow(() => g.throw(42), `42`);
|
|
shouldBeIteratorResult(g.next(42), { value: undefined, done: true });
|
|
shouldBeIteratorResult(g.return(42), { value: 42, done: true });
|
|
shouldThrow(() => g.throw(42), `42`);
|
|
}
|
|
}());
|
|
|
|
(function () {
|
|
function *gen() {
|
|
return 42;
|
|
}
|
|
|
|
{
|
|
let g = gen();
|
|
shouldBeIteratorResult(g.next(), { value: 42, done: true });
|
|
shouldThrow(() => g.throw(0), `0`);
|
|
}
|
|
{
|
|
let g = gen();
|
|
shouldBeIteratorResult(g.return(0), { value: 0, done: true });
|
|
shouldBeIteratorResult(g.next(), { value: undefined, done: true });
|
|
shouldThrow(() => g.throw(42), `42`);
|
|
}
|
|
}());
|
|
|
|
(function () {
|
|
function *gen() {
|
|
}
|
|
|
|
{
|
|
let g = gen();
|
|
shouldBeIteratorResult(g.next(), { value: undefined, done: true });
|
|
shouldThrow(() => g.throw(0), `0`);
|
|
}
|
|
{
|
|
let g = gen();
|
|
shouldBeIteratorResult(g.return(0), { value: 0, done: true });
|
|
shouldBeIteratorResult(g.next(), { value: undefined, done: true });
|
|
shouldThrow(() => g.throw(42), `42`);
|
|
}
|
|
}());
|
|
|
|
(function () {
|
|
let site = new CallSite();
|
|
function *gen() {
|
|
try {
|
|
yield 42;
|
|
} catch (e) {
|
|
shouldBe(e, 0);
|
|
site.call();
|
|
}
|
|
return 42;
|
|
}
|
|
|
|
{
|
|
let g = gen();
|
|
shouldBeIteratorResult(g.next(), { value: 42, done: false });
|
|
shouldBeIteratorResult(g.throw(0), { value: 42, done: true });
|
|
shouldBe(site.count, 1);
|
|
}
|
|
}());
|
|
|
|
(function () {
|
|
function *gen() {
|
|
try {
|
|
yield 42;
|
|
} finally {
|
|
return 42;
|
|
}
|
|
}
|
|
|
|
{
|
|
let g = gen();
|
|
shouldBeIteratorResult(g.next(), { value: 42, done: false });
|
|
shouldBeIteratorResult(g.throw(0), { value: 42, done: true });
|
|
shouldThrow(() => g.throw(0), `0`);
|
|
}
|
|
}());
|