Files
sousa-gecko/devtools/client/webconsole/test/browser/browser_webconsole_console_detection.js
Alexandre Poirot cd88f266c8 Bug 1892638 - [devtools] Avoid triggering any page JS when previewing RegExp and Date. r=devtools-reviewers,nchevobbe
For some reason passing an opaque wrapper from the worker thread isn't an issue for Date.getTime, while it breaks RegExp.toString.
So that, in workers, RegExp with overloaded toString method won't be properly logged and will still have an object inspector,
but with an empty label.

Differential Revision: https://phabricator.services.mozilla.com/D223763
2024-10-03 15:26:28 +00:00

45 lines
1.3 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that the console doesn't trigger any function in the page when logging the message
"use strict";
const TEST_URI = `data:text/html,<script>function logMessages() {
/* Check if page functions can be called by console previewers */
const date = new Date(2024, 0, 1);
date.getTime = () => {
return 42;
};
Date.prototype.getTime = date.getTime;
console.log("date", date);
const regexp = /foo/m;
regexp.toString = () => {
return "24";
};
console.log("regexp", regexp);
}</script>`;
add_task(async function () {
await addTab(TEST_URI);
info("Open the console");
const hud = await openConsole();
// Only log messages *after* the console is opened as it may not trigger the same codepath for cached messages
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
content.wrappedJSObject.logMessages();
});
const dateMessage = await waitFor(() => findConsoleAPIMessage(hud, "date"));
Assert.stringContains(dateMessage.textContent, "Jan 01 2024");
const regExpMessage = await waitFor(() =>
findConsoleAPIMessage(hud, "regexp")
);
Assert.stringContains(regExpMessage.textContent, "/foo/m");
await closeTabAndToolbox();
});