Skip to content

Commit

Permalink
Test async error throwing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Stegmaier committed Dec 12, 2022
1 parent d2a6eec commit 8c57969
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,7 @@ window.triggerConsoleTraceWithObject = function () {
window.triggerConsoleLogObjectWithSubstitution = function () {
console.log("a string: %s; an integer: %i; an object: %o", "foo", 1.23, { a: 1 }); // The leak goes away if you stringify a param.
};

window.triggerAsyncThrowError = async function () {
throw new Error("MyAsyncError");
};
1 change: 1 addition & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ <h1>Test page for iframe error objects</h1>
<!-- <option value="trigger-console-log-object-with-substitution-in-iframe">
Call console log with an object with string substitution -- (**CAUSES A LEAK**)
</option> -->
<option value="catch-async-thrown-error-from-iframe">Try catching an error from inside the iframe -- (**CAUSES A LEAK**)</option>
</select>

<button id="add-iframe">Add iframe</button>
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ function doPostAddingScenario(iframe) {
case "trigger-console-log-object-with-substitution-in-iframe":
iframe.contentWindow.triggerConsoleLogObjectWithSubstitution();
return;
case "catch-async-thrown-error-from-iframe":
throwAsyncErrorInIframeAndCatchItOutside(iframe);
return;
default:
alert("Invalid value for after-adding-iframe dropdown");
return;
Expand Down Expand Up @@ -352,3 +355,11 @@ function overrideConsoleErrorToStringifyNonPrimitives(iframeWindow) {
}
};
}

async function throwAsyncErrorInIframeAndCatchItOutside(iframe) {
try {
await iframe.contentWindow.triggerAsyncThrowError();
} catch (e) {
console.log("Could not load", e);
}
}

0 comments on commit 8c57969

Please sign in to comment.