Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions JSTests/stress/async-function-without-await.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error("Bad value: " + actual + " expected: " + expected);
}

function shouldThrow(func, errorType) {
let errorThrown = false;
try {
func();
} catch (error) {
errorThrown = true;
if (!(error instanceof errorType))
throw new Error("Bad error: " + error);
}
if (!errorThrown)
throw new Error("Should have thrown");
}

async function asyncReturn42() {
return 42;
}

async function asyncReturnUndefined() {
let x = 1;
x++;
}

async function asyncThrow() {
throw new Error("test error");
}

const asyncArrowReturn = async () => {
return "arrow result";
};

const asyncArrowExpr = async () => "expression result";

async function asyncWithLocals() {
let a = 1;
let b = 2;
let c = a + b;
return c;
}

function helper() {
return "helper result";
}

async function asyncCallsHelper() {
return helper();
}

async function asyncWithTryCatch() {
try {
throw new Error("caught");
} catch (e) {
return "caught: " + e.message;
}
}

async function asyncWithControlFlow(x) {
if (x > 0) {
return "positive";
} else if (x < 0) {
return "negative";
} else {
return "zero";
}
}

class AsyncClass {
async asyncMethod() {
return "method result";
}

static async staticAsyncMethod() {
return "static method result";
}
}

async function asyncWithAwait() {
return await Promise.resolve(100);
}

async function runTests() {
let result1 = await asyncReturn42();
shouldBe(result1, 42);

let result2 = await asyncReturnUndefined();
shouldBe(result2, undefined);

let caught3 = false;
try {
await asyncThrow();
} catch (e) {
caught3 = true;
shouldBe(e.message, "test error");
}
shouldBe(caught3, true);

let result4 = await asyncArrowReturn();
shouldBe(result4, "arrow result");

let result5 = await asyncArrowExpr();
shouldBe(result5, "expression result");

let result6 = await asyncWithLocals();
shouldBe(result6, 3);

let result7 = await asyncCallsHelper();
shouldBe(result7, "helper result");

let result8 = await asyncWithTryCatch();
shouldBe(result8, "caught: caught");

shouldBe(await asyncWithControlFlow(5), "positive");
shouldBe(await asyncWithControlFlow(-5), "negative");
shouldBe(await asyncWithControlFlow(0), "zero");

let instance = new AsyncClass();
shouldBe(await instance.asyncMethod(), "method result");
shouldBe(await AsyncClass.staticAsyncMethod(), "static method result");

let result11 = await asyncWithAwait();
shouldBe(result11, 100);

for (let i = 0; i < 10000; i++) {
await asyncReturn42();
await asyncArrowReturn();
await asyncWithLocals();
}
}

runTests().catch($vm.abort);
1 change: 0 additions & 1 deletion JSTests/stress/async-stack-trace-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ function shouldThrowAsync(run, errorType, message, stackFunctions) {
}, Error, "error",
[
["throwError", "200:24"],
["throwError", "199:35"],
["two", "196:25"],
["async one", "187:18"],
["async test", "206:26"],
Expand Down
1 change: 0 additions & 1 deletion JSTests/stress/async-stack-trace-nested-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ for (let i = 0; i < count; i++) {
}, Error, "error",
[
["problematicFunction", "645:20"],
["problematicFunction", "641:36"],
["level101", "632:30"],
["async level100", "620:19"],
["async level99", "615:19"],
Expand Down
6 changes: 3 additions & 3 deletions JSTests/stress/async-stack-trace-nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ async function problematicFunction() {

nop();
throw new Error("error");
await 30;
}

for (let i = 0; i < testLoopCount; i++) {
Expand All @@ -161,7 +162,6 @@ for (let i = 0; i < testLoopCount; i++) {
}, Error, "error",
[
["problematicFunction", "154:20"],
["problematicFunction", "150:36"],
["level10", "141:30"],
["async level9", "130:18"],
["async level8", "124:17"],
Expand All @@ -172,10 +172,10 @@ for (let i = 0; i < testLoopCount; i++) {
["async level3", "85:17"],
["async level2", "77:17"],
["async level1", "69:17"],
["async test", "160:25"],
["async test", "161:25"],
["drainMicrotasks", "[native code]"],
["shouldThrowAsync", "19:20"],
["global code", "158:21"]
["global code", "159:21"]
],
);
drainMicrotasks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ FAIL :iff_uncaptured:useOnuncapturederror=true;errorType="out-of-memory" assert_
- EXCEPTION: Error: there were outstanding immediateAsyncExpectations (e.g. expectUncapturedError) at the end of the test
assert@http://127.0.0.1:8000/webgpu/common/util/util.js:37:20
finalize@http://127.0.0.1:8000/webgpu/common/framework/fixture.js:119:11
finalize@http://127.0.0.1:8000/webgpu/common/framework/fixture.js:118:20
runTest@http://127.0.0.1:8000/webgpu/common/internal/test_group.js:534:28
Reached unreachable code
FAIL :iff_uncaptured:useOnuncapturederror=true;errorType="validation" assert_unreached:
- EXCEPTION: Error: there were outstanding immediateAsyncExpectations (e.g. expectUncapturedError) at the end of the test
assert@http://127.0.0.1:8000/webgpu/common/util/util.js:37:20
finalize@http://127.0.0.1:8000/webgpu/common/framework/fixture.js:119:11
finalize@http://127.0.0.1:8000/webgpu/common/framework/fixture.js:118:20
runTest@http://127.0.0.1:8000/webgpu/common/internal/test_group.js:534:28
Reached unreachable code
PASS :only_original_device_is_event_target:
Expand Down
Loading