Nacre on Servo: first complete, reviewed, not yet built version
Everything in Rust on Servo 0.7 (trimmed: no WebXR, WebGPU, multiprocess): tabs and windows, address bar with suggestions, history, bookmarks and reading list, downloads with resume and external download managers, encrypted password vault with autofill, ad blocker (adblock-rust, 22 lists), VPN through Tor or a proxy and secure DNS via a local bridge proxy, picture in picture, Discord Rich Presence, media player and visualizer, spell check, site apps, user scripts and styles, import from other browsers, gamepads, Web Bluetooth, and every setting of the original Nacre in a plain egui interface. Not compiled yet; docs/HANDOFF.md has the first build checklist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
e8167c3f4a
81 changed files with 265927 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
target/
|
||||
releases/
|
||||
*.log
|
||||
11502
Cargo.lock
generated
Normal file
11502
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
89
Cargo.toml
Normal file
89
Cargo.toml
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
[package]
|
||||
name = "nacre"
|
||||
version = "0.4.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.88"
|
||||
description = "Nacre, a web browser built on Servo"
|
||||
license = "MPL-2.0"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "nacre"
|
||||
path = "src/main.rs"
|
||||
|
||||
[features]
|
||||
default = ["media"]
|
||||
# Audio and video through GStreamer. Without it pages load but <video>/<audio> stay silent.
|
||||
media = ["servo/media-gstreamer"]
|
||||
|
||||
[dependencies]
|
||||
# The engine. Trimmed: no webxr, webgpu, multiprocess, vello.
|
||||
servo = { version = "=0.7.0", default-features = false, features = [
|
||||
"bundled_freetype",
|
||||
"clipboard",
|
||||
"js_jit",
|
||||
"webgl",
|
||||
"webcrypto",
|
||||
"brotli-compression-stream",
|
||||
"gamepad",
|
||||
"bluetooth",
|
||||
"native-bluetooth",
|
||||
] }
|
||||
|
||||
# Window, GL and UI. Versions follow what Servo 0.7 and egui 0.37 use so the types are shared.
|
||||
winit = { version = "0.30.13", default-features = false, features = ["rwh_06", "x11", "wayland", "wayland-csd-adwaita"] }
|
||||
egui = { version = "0.37", default-features = false, features = ["default_fonts"] }
|
||||
egui_glow = { version = "0.37", default-features = false, features = ["winit", "x11", "wayland", "clipboard"] }
|
||||
glow = "0.17"
|
||||
euclid = "0.22"
|
||||
dpi = "0.1"
|
||||
raw-window-handle = "0.6"
|
||||
keyboard-types = "0.8.3"
|
||||
url = "2.5"
|
||||
http = "1.4"
|
||||
rustls = { version = "0.23", default-features = false, features = ["aws_lc_rs", "std"] }
|
||||
content-security-policy = "0.9"
|
||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "ico", "webp", "gif", "bmp"] }
|
||||
log = "0.4"
|
||||
|
||||
# Ad blocking
|
||||
adblock = { version = "0.13.5", default-features = false, features = ["embedded-domain-resolver", "full-regex-handling"] }
|
||||
|
||||
# Nacre's own HTTP (downloads, filter lists, updates, DoH)
|
||||
ureq = { version = "3.5", default-features = false, features = ["rustls-no-provider", "rustls-webpki-roots", "gzip", "brotli"] }
|
||||
|
||||
# Storage and formats (rusqlite: the same version Servo uses, for importing other browsers)
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
dirs = "6"
|
||||
rusqlite = { version = "0.38", features = ["bundled"] }
|
||||
base64 = "0.22"
|
||||
|
||||
# Password vault
|
||||
chacha20poly1305 = "0.10"
|
||||
argon2 = "0.5"
|
||||
getrandom = "0.3"
|
||||
|
||||
# Gamepads (Servo gets gamepad input from the embedder)
|
||||
gilrs = "0.11"
|
||||
|
||||
# Small features
|
||||
rfd = { version = "0.17", default-features = false, features = ["xdg-portal", "pollster"] }
|
||||
qrcode = { version = "0.14", default-features = false }
|
||||
spellbook = "0.4"
|
||||
arboard = { version = "3.6", default-features = false, features = ["wayland-data-control"] }
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
libc = "0.2"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
debug = false
|
||||
strip = true
|
||||
codegen-units = 16
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 2
|
||||
26124
assets/filters/cookies.txt
Normal file
26124
assets/filters/cookies.txt
Normal file
File diff suppressed because one or more lines are too long
84858
assets/filters/easylist.txt
Normal file
84858
assets/filters/easylist.txt
Normal file
File diff suppressed because it is too large
Load diff
57162
assets/filters/easyprivacy.txt
Normal file
57162
assets/filters/easyprivacy.txt
Normal file
File diff suppressed because one or more lines are too long
3586
assets/filters/pgl.txt
Normal file
3586
assets/filters/pgl.txt
Normal file
File diff suppressed because it is too large
Load diff
10835
assets/filters/ublock.txt
Normal file
10835
assets/filters/ublock.txt
Normal file
File diff suppressed because it is too large
Load diff
7179
assets/filters/ublock_badware.txt
Normal file
7179
assets/filters/ublock_badware.txt
Normal file
File diff suppressed because it is too large
Load diff
3379
assets/filters/ublock_privacy.txt
Normal file
3379
assets/filters/ublock_privacy.txt
Normal file
File diff suppressed because it is too large
Load diff
708
assets/filters/ublock_quick.txt
Normal file
708
assets/filters/ublock_quick.txt
Normal file
File diff suppressed because one or more lines are too long
6089
assets/filters/ublock_unbreak.txt
Normal file
6089
assets/filters/ublock_unbreak.txt
Normal file
File diff suppressed because it is too large
Load diff
24370
assets/filters/urlhaus.txt
Normal file
24370
assets/filters/urlhaus.txt
Normal file
File diff suppressed because it is too large
Load diff
223
assets/servo/about-memory.html
Normal file
223
assets/servo/about-memory.html
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>about:memory</title>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", start);
|
||||
|
||||
function insertNode(root, report) {
|
||||
let currentNode = root;
|
||||
for (let path of report.path) {
|
||||
if (!currentNode[path]) {
|
||||
currentNode[path] = { total: 0, container: true };
|
||||
}
|
||||
currentNode = currentNode[path];
|
||||
currentNode.total += report.size;
|
||||
}
|
||||
currentNode.size = report.size;
|
||||
currentNode.container = false;
|
||||
}
|
||||
|
||||
function formatBytes(bytes) {
|
||||
if (bytes < 1024) {
|
||||
return bytes + " B";
|
||||
} else if (bytes < 1024 * 1024) {
|
||||
return (bytes / 1024).toFixed(2) + " KiB";
|
||||
} else if (bytes < 1024 * 1024 * 1024) {
|
||||
return (bytes / (1024 * 1024)).toFixed(2) + " MiB";
|
||||
} else {
|
||||
return (bytes / (1024 * 1024 * 1024)).toFixed(2) + " GiB";
|
||||
}
|
||||
}
|
||||
|
||||
function formattedSize(size) {
|
||||
// Use enough padding to take into account the "MiB" part.
|
||||
return formatBytes(size).padStart(10);
|
||||
}
|
||||
|
||||
function convertNodeToDOM(node, name = null) {
|
||||
let result = document.createDocumentFragment();
|
||||
|
||||
if (node.container) {
|
||||
let details = document.createElement("details");
|
||||
let summary = document.createElement("summary");
|
||||
summary.textContent = `${formattedSize(node.total)} -- ${name}`;
|
||||
details.append(summary);
|
||||
result.append(details);
|
||||
|
||||
// Add the children in descending order of total size.
|
||||
let entries = Object.entries(node)
|
||||
.filter((item) => {
|
||||
return !["total", "size", "container"].includes(item[0]);
|
||||
})
|
||||
.sort((a, b) => b[1].total - a[1].total)
|
||||
.forEach((item) =>
|
||||
details.append(convertNodeToDOM(item[1], item[0]))
|
||||
);
|
||||
} else {
|
||||
let inner = document.createElement("div");
|
||||
inner.textContent = `${formattedSize(node.size)} -- ${name}`;
|
||||
result.append(inner);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function reportsForProcess(processReport) {
|
||||
let explicitRoot = {};
|
||||
let nonExplicitRoot = {};
|
||||
|
||||
let jemallocHeapReportedSize = 0;
|
||||
let systemHeapReportedSize = 0;
|
||||
|
||||
let jemallocHeapAllocatedSize = NaN;
|
||||
let systemHeapAllocatedSize = NaN;
|
||||
|
||||
// In content processes, get the list of urls.
|
||||
let urls = new Set();
|
||||
|
||||
processReport.reports.forEach((report) => {
|
||||
if (report.path[0].startsWith("url(")) {
|
||||
// This can be a list of urls.
|
||||
let path_urls = report.path[0].slice(4, -1).split(", ");
|
||||
path_urls.forEach((url) => urls.add(url));
|
||||
}
|
||||
|
||||
// Add "explicit" to the start of the path, when appropriate.
|
||||
if (report.kind.startsWith("Explicit")) {
|
||||
report.path.unshift("explicit");
|
||||
}
|
||||
|
||||
// Update the reported fractions of the heaps, when appropriate.
|
||||
if (report.kind == "ExplicitJemallocHeapSize") {
|
||||
jemallocHeapReportedSize += report.size;
|
||||
} else if (report.kind == "ExplicitSystemHeapSize") {
|
||||
systemHeapReportedSize += report.size;
|
||||
}
|
||||
|
||||
// Record total size of the heaps, when we see them.
|
||||
if (report.path.length == 1) {
|
||||
if (report.path[0] == "jemalloc-heap-allocated") {
|
||||
jemallocHeapAllocatedSize = report.size;
|
||||
} else if (report.path[0] == "system-heap-allocated") {
|
||||
systemHeapAllocatedSize = report.size;
|
||||
}
|
||||
}
|
||||
|
||||
// Insert this report at the proper position.
|
||||
insertNode(
|
||||
report.kind.startsWith("Explicit") ? explicitRoot : nonExplicitRoot,
|
||||
report
|
||||
);
|
||||
});
|
||||
|
||||
// Compute and insert the heap-unclassified values.
|
||||
if (!isNaN(jemallocHeapAllocatedSize)) {
|
||||
insertNode(explicitRoot, {
|
||||
path: ["explicit", "jemalloc-heap-unclassified"],
|
||||
size: jemallocHeapAllocatedSize - jemallocHeapReportedSize,
|
||||
});
|
||||
}
|
||||
if (!isNaN(systemHeapAllocatedSize)) {
|
||||
insertNode(explicitRoot, {
|
||||
path: ["explicit", "system-heap-unclassified"],
|
||||
size: systemHeapAllocatedSize - systemHeapReportedSize,
|
||||
});
|
||||
}
|
||||
|
||||
// Create the DOM structure for each process report:
|
||||
// <div class=process> <h4>...<h4> <pre> ...</pre> </div>
|
||||
let container = document.createElement("div");
|
||||
container.classList.add("process");
|
||||
let reportTitle = document.createElement("h4");
|
||||
reportTitle.textContent = `${
|
||||
processReport.isMainProcess ? "Main Process" : "Content Process"
|
||||
} (pid ${processReport.pid}) ${[...urls.values()].join(", ")}`;
|
||||
|
||||
container.append(reportTitle);
|
||||
let reportNode = document.createElement("pre");
|
||||
reportNode.classList.add("report");
|
||||
container.append(reportNode);
|
||||
|
||||
reportNode.append(convertNodeToDOM(explicitRoot.explicit, "explicit"));
|
||||
|
||||
for (let prop in nonExplicitRoot) {
|
||||
reportNode.append(convertNodeToDOM(nonExplicitRoot[prop], prop));
|
||||
}
|
||||
|
||||
// Make sure we always put the main process first.
|
||||
if (processReport.isMainProcess) {
|
||||
window.reports.prepend(container);
|
||||
} else {
|
||||
window.reports.append(container);
|
||||
}
|
||||
}
|
||||
|
||||
function start() {
|
||||
window.gcButton.onclick = async () => {
|
||||
window.gcButton.disabled = true;
|
||||
navigator.servo.garbageCollectAllContexts();
|
||||
window.gcButton.disabled = false;
|
||||
};
|
||||
|
||||
window.startButton.onclick = async () => {
|
||||
let content = await navigator.servo.reportMemory();
|
||||
let reports = JSON.parse(content);
|
||||
if (reports.error) {
|
||||
console.error(reports.error);
|
||||
return;
|
||||
}
|
||||
window.reports.innerHTML = "";
|
||||
window.reports.classList.remove("hidden");
|
||||
|
||||
if (!Array.isArray(reports)) {
|
||||
console.error("Unexpected memory report format!");
|
||||
return;
|
||||
}
|
||||
|
||||
reports.forEach(reportsForProcess);
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
html {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
details,
|
||||
details div {
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
summary:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
div.process {
|
||||
margin: 0.5em;
|
||||
border: 2px solid gray;
|
||||
border-radius: 10px;
|
||||
padding: 5px;
|
||||
background-color: lightgray;
|
||||
}
|
||||
|
||||
.report {
|
||||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
.report > details {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Memory Reports</h2>
|
||||
<button id="startButton">Measure</button>
|
||||
<button id="gcButton">Force GC</button>
|
||||
<div id="reports" class="hidden"></div>
|
||||
</body>
|
||||
</html>
|
||||
37
assets/servo/badcert.html
Normal file
37
assets/servo/badcert.html
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Connection not secure</title>
|
||||
<style>
|
||||
:root { color-scheme: light dark; font-family: system-ui, sans-serif; }
|
||||
body { max-width: 560px; margin: 12vh auto; padding: 0 24px; line-height: 1.5; }
|
||||
h1 { font-size: 1.5em; font-weight: 600; }
|
||||
#bytes { display: none; }
|
||||
button { font: inherit; padding: 6px 16px; margin-right: 8px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Connection not secure</h1>
|
||||
<p>This site's certificate can't be trusted, so someone could be reading or changing what you send.
|
||||
It's safest to go back.</p>
|
||||
<p><small>Details: <code>${reason}</code></small></p>
|
||||
<button id="leave" onclick="history.back()">Go back</button>
|
||||
<button id="allow">Open anyway for now</button>
|
||||
<div id="bytes">${bytes}</div>
|
||||
<script>
|
||||
let bytes = document.getElementById('bytes').textContent;
|
||||
let button = document.getElementById('allow');
|
||||
if (bytes.length) {
|
||||
button.onclick = function () {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', 'chrome:allowcert');
|
||||
xhr.onloadend = function () { location.reload(true); };
|
||||
xhr.send("${secret}&${bytes}");
|
||||
};
|
||||
} else {
|
||||
button.style.display = "none";
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
21
assets/servo/crash.html
Normal file
21
assets/servo/crash.html
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>This page crashed</title>
|
||||
<style>
|
||||
:root { color-scheme: light dark; font-family: system-ui, sans-serif; }
|
||||
body { max-width: 640px; margin: 12vh auto; padding: 0 24px; line-height: 1.5; }
|
||||
h1 { font-size: 1.5em; font-weight: 600; }
|
||||
details pre { white-space: pre-wrap; font-size: 12px; }
|
||||
button { font: inherit; padding: 6px 16px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>This page crashed</h1>
|
||||
<p>Something on the page broke the engine. Reloading usually fixes it. The details are also written to pages.log
|
||||
in Nacre's data folder.</p>
|
||||
<!-- Reloading turns a POST into a GET; see whatwg/html#6600. -->
|
||||
<button onclick="location.reload()">Reload</button>
|
||||
<details><summary>Details</summary><pre><plaintext>
|
||||
${details}
|
||||
957
assets/servo/debugger.js
Normal file
957
assets/servo/debugger.js
Normal file
|
|
@ -0,0 +1,957 @@
|
|||
if ("dbg" in this) {
|
||||
throw new Error("Debugger script must not run more than once!");
|
||||
}
|
||||
|
||||
const dbg = new Debugger;
|
||||
const debuggeesToPipelineIds = new Map;
|
||||
const debuggeesToWorkerIds = new Map;
|
||||
const sourceIdsToScripts = new Map;
|
||||
const frameActorsToFrames = new Map;
|
||||
const objectActorsToObjects = new Map;
|
||||
const environmentsToEnvironmentActors = new Map;
|
||||
const blackboxing = new Map;
|
||||
let suspendedFrame = null;
|
||||
let lastPauseLocation = null;
|
||||
let debuggerPaused = false;
|
||||
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#155>
|
||||
// Possible values for the `why.type` attribute in "paused" event
|
||||
const PAUSE_REASONS = {
|
||||
INTERRUPTED: "interrupted", // Associated with why.onNext attribute
|
||||
RESUME_LIMIT: "resumeLimit",
|
||||
};
|
||||
|
||||
// Find script by scriptId within a script tree
|
||||
function findScriptById(script, scriptId) {
|
||||
if (script.sourceStart === scriptId) {
|
||||
return script;
|
||||
}
|
||||
for (const child of script.getChildScripts()) {
|
||||
const found = findScriptById(child, scriptId);
|
||||
if (found) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Walk script tree and call callback for each script
|
||||
function walkScriptTree(script, callback) {
|
||||
callback(script);
|
||||
for (const child of script.getChildScripts()) {
|
||||
walkScriptTree(child, callback);
|
||||
}
|
||||
}
|
||||
|
||||
// Find a key by a value in a map
|
||||
function findKeyByValue(map, search) {
|
||||
for (const [key, value] of map) {
|
||||
if (value === search) return key;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// The === operator isn't really applicable to pipelineId
|
||||
function findDebuggeeByPipelineId(search) {
|
||||
for (const [key, value] of debuggeesToPipelineIds) {
|
||||
if (value.namespaceId == search.namespaceId && value.index == search.index) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
dbg.uncaughtExceptionHook = function(error) {
|
||||
console.error(`[debugger] Uncaught exception at ${error.fileName}:${error.lineNumber}:${error.columnNumber}: ${error.name}: ${error.message}`);
|
||||
};
|
||||
|
||||
dbg.onNewScript = function(script) {
|
||||
// TODO: handle wasm (`script.source.introductionType == wasm`)
|
||||
sourceIdsToScripts.set(script.source.id, script);
|
||||
notifyNewSource({
|
||||
pipelineId: debuggeesToPipelineIds.get(script.global),
|
||||
workerId: debuggeesToWorkerIds.get(script.global),
|
||||
spidermonkeyId: script.source.id,
|
||||
url: script.source.url,
|
||||
urlOverride: script.source.displayURL,
|
||||
text: script.source.text,
|
||||
introductionType: script.source.introductionType ?? null,
|
||||
});
|
||||
};
|
||||
|
||||
// Track a new debuggee global
|
||||
addEventListener("addDebuggee", event => {
|
||||
const {global, pipelineId, workerId} = event;
|
||||
const debuggerObject = dbg.addDebuggee(global);
|
||||
debuggeesToPipelineIds.set(debuggerObject, pipelineId);
|
||||
if (workerId !== undefined) {
|
||||
debuggeesToWorkerIds.set(debuggerObject, workerId);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Convert debuggee value to property descriptor value
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/object/utils.js#116>
|
||||
function createValueGrip(value, depth) {
|
||||
switch (typeof value) {
|
||||
case "undefined":
|
||||
return "VoidValue";
|
||||
case "boolean":
|
||||
return { BooleanValue: value };
|
||||
case "number":
|
||||
if (value === Infinity) {
|
||||
return { NumberValue: "Infinity" };
|
||||
} else if (value === -Infinity) {
|
||||
return { NumberValue: "-Infinity" };
|
||||
} else if (Number.isNaN(value)) {
|
||||
return { NumberValue: "NaN" };
|
||||
} else if (Object.is(value, -0)) {
|
||||
return { NumberValue: "-0" };
|
||||
}
|
||||
return { NumberValue: value };
|
||||
case "string":
|
||||
return { StringValue: value };
|
||||
case "object":
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/object/utils.js#153>
|
||||
if (value === null) {
|
||||
return { NullValue: false };
|
||||
}
|
||||
if (value.uninitialized) {
|
||||
return { NullValue: true };
|
||||
}
|
||||
if (value.optimizedOut || value.missingArguments) {
|
||||
return { NullValue: false };
|
||||
}
|
||||
// TODO: handle typed arrays and storage independently
|
||||
const ownPropertyLength = value.getOwnPropertyNamesLength();
|
||||
let objectActorId = findKeyByValue(objectActorsToObjects, value);
|
||||
const objectValue = {
|
||||
class: value.class,
|
||||
ownPropertyLength: Number.isFinite(ownPropertyLength) ? ownPropertyLength : undefined,
|
||||
};
|
||||
// Debugger.Object - get preview using registered previewers
|
||||
// <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.object/index.html>
|
||||
const preview = getPreview(value, depth + 1);
|
||||
if (!preview) {
|
||||
// Reusing an actor with a stored preview can cause recursion, we should handle it properly at some point.
|
||||
return { ObjectValue: objectValue };
|
||||
}
|
||||
objectValue.preview = preview;
|
||||
|
||||
if (!objectActorId) {
|
||||
objectActorId = registerObjectActor(JSON.stringify({ ObjectValue: objectValue }));
|
||||
if (!objectActorId) {
|
||||
console.error("[debugger] Couldn't create object actor");
|
||||
return { ObjectValue: objectValue };
|
||||
}
|
||||
objectActorsToObjects.set(objectActorId, value);
|
||||
}
|
||||
objectValue.actor = objectActorId;
|
||||
return { ObjectValue: objectValue };
|
||||
default:
|
||||
return { StringValue: String(value) };
|
||||
}
|
||||
}
|
||||
|
||||
// Extract own properties from a debuggee object
|
||||
// <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.object/index.html#function-properties-of-the-debugger-object-prototype>
|
||||
function extractOwnProperties(obj, depth) {
|
||||
const ownProperties = [];
|
||||
let totalLength = 0;
|
||||
|
||||
let names;
|
||||
try {
|
||||
names = obj.getOwnPropertyNames();
|
||||
totalLength = names.length;
|
||||
} catch (e) {
|
||||
return { ownProperties, ownPropertiesLength: 0 };
|
||||
}
|
||||
|
||||
for (const name of names) {
|
||||
try {
|
||||
const desc = obj.getOwnPropertyDescriptor(name);
|
||||
if (desc) {
|
||||
const prop = {
|
||||
name: name,
|
||||
configurable: desc.configurable ?? false,
|
||||
enumerable: desc.enumerable ?? false,
|
||||
writable: desc.writable ?? false,
|
||||
isAccessor: desc.get !== undefined || desc.set !== undefined,
|
||||
value: createValueGrip(undefined, depth + 1),
|
||||
};
|
||||
|
||||
if (desc.value !== undefined) {
|
||||
prop.value = createValueGrip(desc.value, depth + 1);
|
||||
} else if (desc.get) {
|
||||
try {
|
||||
const result = desc.get.call(obj);
|
||||
if (result && "return" in result) {
|
||||
prop.value = createValueGrip(result.return, depth + 1);
|
||||
}
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
ownProperties.push(prop);
|
||||
}
|
||||
} catch (e) {
|
||||
// For now skip properties that throw on access
|
||||
}
|
||||
}
|
||||
|
||||
return { ownProperties, ownPropertiesLength: totalLength };
|
||||
}
|
||||
|
||||
// <https://searchfox.org/mozilla-central/source/devtools/server/actors/object/previewers.js#80>
|
||||
const previewers = {};
|
||||
|
||||
// <https://searchfox.org/firefox-main/source/devtools/shared/DevToolsUtils.js#182>
|
||||
function getProperty(object, name) {
|
||||
const root = object;
|
||||
while (object) {
|
||||
let desc;
|
||||
try {
|
||||
desc = object.getOwnPropertyDescriptor(name);
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (desc) {
|
||||
if ("value" in desc) {
|
||||
return desc.value;
|
||||
}
|
||||
|
||||
if (desc.get) {
|
||||
try {
|
||||
return desc.get.call(root)?.return;
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
object = object.proto;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Calls the property with the given `name` on the given `object`, where
|
||||
// `name` is a string, and `object` a Debugger.Object instance.
|
||||
// <https://searchfox.org/firefox-main/source/devtools/shared/DevToolsUtils.js#943>
|
||||
function callPropertyOnObject(object, name, ...args) {
|
||||
let descriptor;
|
||||
let proto = object;
|
||||
do {
|
||||
descriptor = proto.getOwnPropertyDescriptor(name);
|
||||
if (descriptor !== undefined) {
|
||||
break;
|
||||
}
|
||||
proto = proto.proto;
|
||||
} while (proto !== null);
|
||||
|
||||
if (descriptor === undefined) {
|
||||
throw new Error("No such property");
|
||||
}
|
||||
|
||||
const value = descriptor.value;
|
||||
if (typeof value !== "object" || value === null || !("callable" in value)) {
|
||||
throw new Error("Not a callable object.");
|
||||
}
|
||||
|
||||
if (value.script !== undefined) {
|
||||
throw new Error(
|
||||
"The property isn't a native function and will execute code in the debuggee"
|
||||
);
|
||||
}
|
||||
|
||||
const result = value.call(object, ...args);
|
||||
if (result === null) {
|
||||
throw new Error("Code was terminated.");
|
||||
}
|
||||
if ("throw" in result) {
|
||||
throw result.throw;
|
||||
}
|
||||
return result.return;
|
||||
}
|
||||
|
||||
// <https://searchfox.org/firefox-main/source/devtools/shared/DevToolsUtils.js#983>
|
||||
function* makeDebuggeeIterator(object) {
|
||||
while (true) {
|
||||
const nextValue = callPropertyOnObject(object, "next");
|
||||
if (getProperty(nextValue, "done")) {
|
||||
break;
|
||||
}
|
||||
yield getProperty(nextValue, "value");
|
||||
}
|
||||
}
|
||||
|
||||
// <https://searchfox.org/mozilla-central/source/devtools/server/actors/object/previewers.js#125>
|
||||
previewers.Function = [ function FunctionPreviewer(obj, depth) {
|
||||
let functionDetails = {
|
||||
name: obj.name,
|
||||
displayName: obj.displayName,
|
||||
parameterNames: obj.parameterNames ? obj.parameterNames: [],
|
||||
isAsync: obj.isAsyncFunction,
|
||||
isGenerator: obj.isGeneratorFunction,
|
||||
}
|
||||
|
||||
let preview = { kind: "Object", function: functionDetails };
|
||||
if (depth > 1) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { ownProperties, ownPropertiesLength } = extractOwnProperties(obj, depth);
|
||||
preview.ownProperties = ownProperties;
|
||||
preview.ownPropertiesLength = ownPropertiesLength;
|
||||
|
||||
return preview;
|
||||
} ];
|
||||
|
||||
// <https://searchfox.org/mozilla-central/source/devtools/server/actors/object/previewers.js#172>
|
||||
previewers.Array = [ function ArrayPreviewer(obj, depth) {
|
||||
const lengthDescriptor = obj.getOwnPropertyDescriptor("length");
|
||||
const arrayLength = lengthDescriptor ? lengthDescriptor.value : 0;
|
||||
|
||||
let preview = { kind: "ArrayLike", arrayLength };
|
||||
if (depth > 1) {
|
||||
return preview;
|
||||
}
|
||||
|
||||
preview.items = [];
|
||||
for (let i = 0; i < arrayLength; i++) {
|
||||
const desc = obj.getOwnPropertyDescriptor(i);
|
||||
if (desc && desc.value !== undefined) {
|
||||
preview.items.push(createValueGrip(desc.value, depth + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return preview;
|
||||
} ];
|
||||
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/object/property-iterator.js#298>
|
||||
function enumMapEntries(obj, depth) {
|
||||
const entries = makeDebuggeeIterator(callPropertyOnObject(obj, "entries"));
|
||||
return {
|
||||
*[Symbol.iterator]() {
|
||||
for (const entry of entries) {
|
||||
yield [
|
||||
getProperty(entry, 0),
|
||||
getProperty(entry, 1),
|
||||
].map(value => createValueGrip(value, depth));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/object/previewers.js#450>
|
||||
previewers.Map = [ function MapPreviewer(object, depth) {
|
||||
const size = getProperty(object, "size");
|
||||
if (typeof size !== "number") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let preview = { kind: "MapLike", size };
|
||||
if (depth > 1) {
|
||||
return preview;
|
||||
}
|
||||
|
||||
preview.entries = [];
|
||||
for (const entry of enumMapEntries(object, depth)) {
|
||||
preview.entries.push(entry);
|
||||
}
|
||||
|
||||
return preview;
|
||||
} ];
|
||||
|
||||
// Generic fallback for object previewer
|
||||
// <https://searchfox.org/mozilla-central/source/devtools/server/actors/object/previewers.js#856>
|
||||
previewers.Object = [ function ObjectPreviewer(obj, depth) {
|
||||
let preview = { kind: "Object" };
|
||||
if (depth > 1) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { ownProperties, ownPropertiesLength } = extractOwnProperties(obj, depth);
|
||||
preview.ownProperties = ownProperties;
|
||||
preview.ownPropertiesLength = ownPropertiesLength;
|
||||
|
||||
return preview;
|
||||
} ];
|
||||
|
||||
function getPreview(obj, depth) {
|
||||
const className = obj.class;
|
||||
|
||||
// <https://searchfox.org/mozilla-central/source/devtools/server/actors/object.js#295>
|
||||
const typePreviewers = previewers[className] || previewers.Object;
|
||||
for (const previewer of typePreviewers) {
|
||||
try {
|
||||
const result = previewer(obj, depth);
|
||||
if (result) return result;
|
||||
} catch (e) {
|
||||
console.error(`[debugger] Couldn't populate ${className} preview: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Evaluate some javascript code in the global context of the debuggee
|
||||
// See executeInGlobal() at <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.object/index.html#function-properties-of-the-debugger-object-prototype>
|
||||
addEventListener("eval", event => {
|
||||
const { code, pipelineId, workerId, frameActorId } = event;
|
||||
|
||||
let frame;
|
||||
if (frameActorId) {
|
||||
frame = frameActorsToFrames.get(frameActorId);
|
||||
}
|
||||
let global = workerId !== undefined ?
|
||||
findKeyByValue(debuggeesToWorkerIds, workerId) :
|
||||
findDebuggeeByPipelineId(pipelineId);
|
||||
|
||||
let noSideEffectDebugger;
|
||||
if (event.eager) {
|
||||
noSideEffectDebugger = createSideEffectFreeDebugger(global);
|
||||
|
||||
// We need to eval in the context of the temporary debugger to apply side-effect tracking
|
||||
if (frame) {
|
||||
frame = noSideEffectDebugger.adoptFrame(frame);
|
||||
} else {
|
||||
global = noSideEffectDebugger.adoptDebuggeeValue(global);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
let completionValue;
|
||||
if (frame) {
|
||||
// <https://searchfox.org/firefox-main/source/js/src/doc/Debugger/Debugger.Frame.md#223>
|
||||
if (frame?.onStack) {
|
||||
completionValue = frame.eval(code);
|
||||
} else {
|
||||
completionValue = { throw: "Frame not available" };
|
||||
}
|
||||
} else {
|
||||
completionValue = global.executeInGlobal(code);
|
||||
}
|
||||
|
||||
// Completion values: <https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html#completion-values>
|
||||
let resultValue;
|
||||
if (completionValue === null) {
|
||||
resultValue = {
|
||||
value: createValueGrip(undefined, 0),
|
||||
hasException: false,
|
||||
};
|
||||
} else if ("throw" in completionValue) {
|
||||
let exceptionMessage = null;
|
||||
if (typeof completionValue.throw.unsafeDereference === "function") {
|
||||
const deref = completionValue.throw.unsafeDereference();
|
||||
if (typeof deref.message === "string") {
|
||||
exceptionMessage = deref.message;
|
||||
}
|
||||
}
|
||||
if (!exceptionMessage) {
|
||||
exceptionMessage = `Uncaught ${completionValue.throw}`;
|
||||
}
|
||||
resultValue = {
|
||||
value: createValueGrip(completionValue.throw, 0),
|
||||
exceptionMessage,
|
||||
hasException: true,
|
||||
};
|
||||
} else if ("return" in completionValue) {
|
||||
resultValue = {
|
||||
value: createValueGrip(completionValue.return, 0),
|
||||
hasException: false,
|
||||
};
|
||||
}
|
||||
|
||||
evalResult(event, {
|
||||
serializedValue: JSON.stringify(resultValue.value),
|
||||
exceptionMessage: resultValue.hasException ? resultValue.exceptionMessage : null,
|
||||
hasException: resultValue.hasException,
|
||||
});
|
||||
} finally {
|
||||
if (noSideEffectDebugger) {
|
||||
noSideEffectDebugger.onNativeCall = undefined;
|
||||
noSideEffectDebugger.shouldAvoidSideEffects = false;
|
||||
|
||||
// This must be called last as the cleanup above depends on the list of debuggees
|
||||
noSideEffectDebugger.removeAllDebuggees();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/webconsole/eval-with-debugger.js#436>
|
||||
function createSideEffectFreeDebugger(debuggee) {
|
||||
const eagerDbg = new Debugger;
|
||||
|
||||
// Special flag in order to ensure that any evaluation or call being
|
||||
// made via this debugger will be ignored by all debuggers except this one.
|
||||
eagerDbg.exclusiveDebuggerOnEval = true;
|
||||
|
||||
// TODO: Add other debuggees that the evaluation might use
|
||||
eagerDbg.addDebuggee(debuggee.unsafeDereference());
|
||||
|
||||
const timeoutDuration = 100;
|
||||
const endTime = Date.now() + timeoutDuration;
|
||||
let count = 0;
|
||||
function shouldCancel() {
|
||||
// To keep the evaled code as quick as possible, we avoid querying the
|
||||
// current time on ever single step and instead check every 100 steps
|
||||
// as an arbitrary count that seemed to be "often enough".
|
||||
return ++count % 100 === 0 && Date.now() > endTime;
|
||||
}
|
||||
|
||||
const executedScripts = new Set();
|
||||
const handler = {
|
||||
hit: () => null,
|
||||
};
|
||||
// null means abort; undefined means continue
|
||||
eagerDbg.onEnterFrame = frame => {
|
||||
if (shouldCancel()) {
|
||||
return null;
|
||||
}
|
||||
frame.onStep = () => {
|
||||
if (shouldCancel()) {
|
||||
return null;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const script = frame.script;
|
||||
if (executedScripts.has(script)) {
|
||||
// Skip setting breakpoints in the same script again
|
||||
return undefined;
|
||||
}
|
||||
executedScripts.add(script);
|
||||
|
||||
const offsets = script.getEffectfulOffsets();
|
||||
for (const offset of offsets) {
|
||||
script.setBreakpoint(offset, handler);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
eagerDbg.onNativeCall = (_callee, _reason) => {
|
||||
// TODO: Allow side-effect-free native calls
|
||||
// Aborting on all native calls is naïve but safe
|
||||
return null;
|
||||
};
|
||||
|
||||
eagerDbg.shouldAvoidSideEffects = true;
|
||||
|
||||
return eagerDbg;
|
||||
}
|
||||
|
||||
addEventListener("getPossibleBreakpoints", event => {
|
||||
const {spidermonkeyId} = event;
|
||||
const script = sourceIdsToScripts.get(spidermonkeyId);
|
||||
const result = [];
|
||||
walkScriptTree(script, (currentScript) => {
|
||||
for (const location of currentScript.getPossibleBreakpoints()) {
|
||||
location["scriptId"] = currentScript.sourceStart;
|
||||
result.push(location);
|
||||
}
|
||||
});
|
||||
getPossibleBreakpointsResult(event, result);
|
||||
});
|
||||
|
||||
function createFrameActor(frame, pipelineId) {
|
||||
let frameActorId = findKeyByValue(frameActorsToFrames, frame);
|
||||
if (!frameActorId) {
|
||||
// TODO: Check if we already have an actor for this frame
|
||||
frameActorId = registerFrameActor(pipelineId, {
|
||||
// TODO: Some properties throw if terminated is true
|
||||
// TODO: arguments: frame.arguments,
|
||||
displayName: frame.script.displayName ?? null,
|
||||
onStack: frame.onStack,
|
||||
oldest: frame.older == null,
|
||||
serializedThis: JSON.stringify(createValueGrip(frame.this, 0)),
|
||||
terminated: frame.terminated,
|
||||
type_: frame.type,
|
||||
url: frame.script.url,
|
||||
});
|
||||
|
||||
if (!frameActorId) {
|
||||
console.error("[debugger] Couldn't create frame");
|
||||
return undefined;
|
||||
}
|
||||
frameActorsToFrames.set(frameActorId, frame);
|
||||
}
|
||||
|
||||
return frameActorId;
|
||||
}
|
||||
|
||||
function handlePauseAndRespond(frame, pauseReason) {
|
||||
// https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#1706
|
||||
// We don't handle nested pauses correctly. Don't try - if we're
|
||||
// paused, just continue running whatever code triggered the pause.
|
||||
if (debuggerPaused) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
dbg.onEnterFrame = undefined;
|
||||
clearSteppingHooks(frame);
|
||||
|
||||
// Get the pipeline ID for this debuggee
|
||||
const pipelineId = debuggeesToPipelineIds.get(frame.script.global);
|
||||
if (!pipelineId) {
|
||||
console.error("[debugger] No pipeline ID for frame's global");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let frameActorId = createFrameActor(frame, pipelineId);
|
||||
|
||||
// <https://github.com/mozilla-firefox/firefox/blob/63719d122f9214f37fd1d285a91897b8345b88b0/js/src/doc/Debugger/Debugger.Script.md?plain=1#L293-L303>
|
||||
const offset = frame.offset;
|
||||
const offsetMetadata = frame.script.getOffsetMetadata(offset);
|
||||
const frameOffset = {
|
||||
frameActorId,
|
||||
column: offsetMetadata.columnNumber - 1,
|
||||
line: offsetMetadata.lineNumber
|
||||
};
|
||||
lastPauseLocation = { line: offsetMetadata.lineNumber, column: offsetMetadata.columnNumber };
|
||||
|
||||
const source = frame.script.source;
|
||||
if (source != null && isBlackBoxed(source.id, frameOffset.line, frameOffset.column)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Notify devtools and enter pause loop. This blocks until Resume.
|
||||
debuggerPaused = true;
|
||||
try {
|
||||
pauseAndRespond(
|
||||
pipelineId,
|
||||
frameOffset,
|
||||
pauseReason
|
||||
);
|
||||
} finally {
|
||||
debuggerPaused = false;
|
||||
}
|
||||
|
||||
// <https://web.archive.org/web/20251212212538/https://firefox-source-docs.mozilla.org/js/Debugger/Conventions.html#resumption-values>
|
||||
// Return undefined to continue execution normally after resume.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
addEventListener("frames", event => {
|
||||
const {pipelineId, start, count} = event;
|
||||
let frameList = handleListFrames(pipelineId, start, count);
|
||||
|
||||
listFramesResult(frameList);
|
||||
})
|
||||
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#1425>
|
||||
function handleListFrames(pipelineId, start, count) {
|
||||
let frame = dbg.getNewestFrame()
|
||||
|
||||
const walkToParentFrame = () => {
|
||||
if (!frame) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentFrame = frame;
|
||||
frame = null;
|
||||
|
||||
if (currentFrame.older) {
|
||||
frame = currentFrame.older;
|
||||
}
|
||||
}
|
||||
|
||||
let i = 0;
|
||||
while (frame && i < start) {
|
||||
walkToParentFrame();
|
||||
i++;
|
||||
}
|
||||
|
||||
// Return count frames, or all remaining frames if count is not defined.
|
||||
const frames = [];
|
||||
for (; frame && (!count || i < start + count); i++, walkToParentFrame()) {
|
||||
const frameActorId = createFrameActor(frame, pipelineId);
|
||||
frames.push(frameActorId);
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
addEventListener("setBreakpoint", event => {
|
||||
const {spidermonkeyId, scriptId, offset} = event;
|
||||
const script = sourceIdsToScripts.get(spidermonkeyId);
|
||||
const target = findScriptById(script, scriptId);
|
||||
if (target) {
|
||||
target.setBreakpoint(offset, {
|
||||
// setBreakpoint(offset, handler) in <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.script/index.html#function-properties-of-the-debugger-script-prototype-object>
|
||||
// The hit handler receives a Debugger.Frame instance representing the currently executing stack frame.
|
||||
hit: (frame) => handlePauseAndRespond(frame, {type_: "breakpoint"})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.frame/index.html>
|
||||
addEventListener("interrupt", event => {
|
||||
dbg.onEnterFrame = (frame) => handlePauseAndRespond(
|
||||
frame,
|
||||
{ type_: PAUSE_REASONS.INTERRUPTED, onNext: true }
|
||||
);
|
||||
});
|
||||
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#1088>
|
||||
function hasMoved(frame) {
|
||||
if (!lastPauseLocation) {
|
||||
return true;
|
||||
}
|
||||
const meta = frame.script.getOffsetMetadata(frame.offset);
|
||||
return meta.lineNumber !== lastPauseLocation.line ||
|
||||
meta.columnNumber !== lastPauseLocation.column;
|
||||
}
|
||||
|
||||
function makeSteppingHooks(steppingType, startFrame) {
|
||||
return {
|
||||
onEnterFrame: function (frame) {
|
||||
const { onStep, onPop } = makeSteppingHooks("next", frame);
|
||||
frame.onStep = onStep;
|
||||
frame.onPop = onPop;
|
||||
},
|
||||
onStep: function () {
|
||||
const meta = this.script.getOffsetMetadata(this.offset);
|
||||
if (!meta.isBreakpoint || !hasMoved(this)) {
|
||||
return undefined;
|
||||
}
|
||||
if (this !== startFrame || meta.isStepStart) {
|
||||
return handlePauseAndRespond(this, { type_: PAUSE_REASONS.RESUME_LIMIT });
|
||||
}
|
||||
},
|
||||
onPop: function (completion) {
|
||||
this.reportedPop = true;
|
||||
suspendedFrame = this;
|
||||
attachSteppingHooks(steppingType, this);
|
||||
return undefined;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function getNextStepFrame(frame) {
|
||||
const endOfFrame = frame.reportedPop;
|
||||
const stepFrame = endOfFrame ? frame.older : frame;
|
||||
if (!stepFrame || !stepFrame.script) {
|
||||
return null;
|
||||
}
|
||||
return stepFrame;
|
||||
}
|
||||
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#1235>
|
||||
function attachSteppingHooks(steppingType, frame) {
|
||||
if (steppingType === "finish" && frame.reportedPop) {
|
||||
steppingType = "next";
|
||||
}
|
||||
|
||||
const stepFrame = getNextStepFrame(frame);
|
||||
if (!stepFrame) {
|
||||
steppingType = "step";
|
||||
}
|
||||
|
||||
const { onEnterFrame, onStep, onPop } = makeSteppingHooks(
|
||||
steppingType,
|
||||
frame,
|
||||
);
|
||||
|
||||
if (steppingType === "step") {
|
||||
dbg.onEnterFrame = onEnterFrame;
|
||||
}
|
||||
|
||||
if (stepFrame) {
|
||||
switch (steppingType) {
|
||||
case "step":
|
||||
case "next":
|
||||
if (stepFrame.script) {
|
||||
stepFrame.onStep = onStep;
|
||||
}
|
||||
case "finish":
|
||||
stepFrame.onPop = onPop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function clearSteppingHooks(suspendedFrame) {
|
||||
if (suspendedFrame) {
|
||||
suspendedFrame.onStep = undefined;
|
||||
suspendedFrame.onPop = undefined;
|
||||
}
|
||||
let frame = dbg.getNewestFrame();
|
||||
if (frame?.onStack) {
|
||||
while (frame) {
|
||||
frame.onStep = undefined;
|
||||
frame.onPop = undefined;
|
||||
frame = frame.older;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// <https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html#resuming-a-thread>
|
||||
addEventListener("resume", event => {
|
||||
const {resumeLimitType: steppingType, frameActorID} = event;
|
||||
let frame = dbg.getNewestFrame();
|
||||
if (frameActorID) {
|
||||
frame = frameActorsToFrames.get(frameActorID);
|
||||
if (!frame) {
|
||||
console.error("[debugger] Couldn't find frame");
|
||||
}
|
||||
}
|
||||
if (steppingType) {
|
||||
// This is a temporary fix until we support async contexts.
|
||||
if (steppingType === "finish") {
|
||||
lastPauseLocation = null;
|
||||
}
|
||||
attachSteppingHooks(steppingType, frame);
|
||||
} else {
|
||||
clearSteppingHooks(frame);
|
||||
}
|
||||
});
|
||||
|
||||
// <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.script/index.html#function-properties-of-the-debugger-script-prototype-object>
|
||||
// There may be more than one breakpoint at the same offset with different handlers, but we don’t handle that case for now.
|
||||
addEventListener("clearBreakpoint", event => {
|
||||
const {spidermonkeyId, scriptId, offset} = event;
|
||||
const script = sourceIdsToScripts.get(spidermonkeyId);
|
||||
const target = findScriptById(script, scriptId);
|
||||
if (target) {
|
||||
// If the instance refers to a JSScript, remove all breakpoints set in this script at that offset.
|
||||
target.clearAllBreakpoints(offset);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: Get variables (scopes don't show if they don't have a variable)
|
||||
function createEnvironmentActor(environment) {
|
||||
let info = {};
|
||||
if (environment.type == "declarative") {
|
||||
info.type_ = environment.calleeScript ? "function" : "block";
|
||||
} else {
|
||||
info.type_ = environment.type;
|
||||
}
|
||||
|
||||
info.scopeKind = environment.scopeKind;
|
||||
|
||||
if (environment.calleeScript) {
|
||||
info.functionDisplayName = environment.calleeScript.displayName;
|
||||
}
|
||||
|
||||
let parent = null;
|
||||
if (environment.parent) {
|
||||
parent = createEnvironmentActor(environment.parent);
|
||||
}
|
||||
|
||||
let bindingVariables = [];
|
||||
if (environment.type == "declarative") {
|
||||
bindingVariables = buildBindings(environment);
|
||||
}
|
||||
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/environment.js#62>
|
||||
if (environment.type == "object" || environment.type == "with") {
|
||||
info.serializedObject = JSON.stringify(createValueGrip(environment.object, 0));
|
||||
}
|
||||
info.serializedBindings = JSON.stringify(bindingVariables);
|
||||
|
||||
let actor = environmentsToEnvironmentActors.get(environment);
|
||||
actor = registerEnvironmentActor(info, parent, actor);
|
||||
environmentsToEnvironmentActors.set(environment, actor);
|
||||
return actor;
|
||||
}
|
||||
|
||||
function buildBindings(environment) {
|
||||
const bindingVariables = [];
|
||||
for (const name of environment.names()) {
|
||||
const value = environment.getVariable(name);
|
||||
const property = {
|
||||
name: name,
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
writable: !(
|
||||
value &&
|
||||
(value.optimizedOut || value.uninitialized || value.missingArguments)
|
||||
),
|
||||
isAccessor: false,
|
||||
value: createValueGrip(value, 0),
|
||||
};
|
||||
|
||||
bindingVariables.push(property);
|
||||
}
|
||||
return bindingVariables;
|
||||
}
|
||||
|
||||
// Get a `Debugger.Environment` instance within which evaluation is taking place.
|
||||
// <https://searchfox.org/firefox-main/source/devtools/server/actors/frame.js#109>
|
||||
addEventListener("getEnvironment", event => {
|
||||
const { frameActorId, pipelineId } = event;
|
||||
let environment;
|
||||
if (frameActorId) {
|
||||
environment = frameActorsToFrames.get(frameActorId).environment;
|
||||
} else {
|
||||
environment = findDebuggeeByPipelineId(pipelineId).asEnvironment();
|
||||
}
|
||||
|
||||
const actor = createEnvironmentActor(environment);
|
||||
getEnvironmentResult(actor);
|
||||
});
|
||||
|
||||
addEventListener("blackbox", event => {
|
||||
if (event.coversFullSource) {
|
||||
// Blackbox the entire source
|
||||
blackboxing.set(event.spidermonkeyId, []);
|
||||
} else {
|
||||
// Blackbox only a part of the source
|
||||
let blackbox = blackboxing.get(event.spidermonkeyId);
|
||||
if (blackbox == undefined) {
|
||||
blackbox = [];
|
||||
}
|
||||
|
||||
blackbox.push({
|
||||
start: event.start(),
|
||||
end: event.end()
|
||||
});
|
||||
|
||||
blackboxing.set(event.spidermonkeyId, blackbox);
|
||||
}
|
||||
});
|
||||
|
||||
addEventListener("unblackbox", event => {
|
||||
if (event.coversFullSource) {
|
||||
// Unblackbox the entire source
|
||||
blackboxing.delete(event.spidermonkeyId);
|
||||
} else {
|
||||
// Unblackbox an earlier range of the source
|
||||
const array = blackboxing.get(event.spidermonkeyId);
|
||||
|
||||
const start = event.start();
|
||||
const end = event.end();
|
||||
const index = array.findIndex(range => range.start.line === start.line
|
||||
&& range.start.column === start.column
|
||||
&& range.end.line === end.line
|
||||
&& range.end.column === end.column
|
||||
);
|
||||
if (index !== -1) {
|
||||
array.splice(index, 1);
|
||||
|
||||
// Empty arrays represent a fully blackboxed file
|
||||
// Therefore, if we just made the array empty we will need to remove it from the map
|
||||
if (array.length === 0) {
|
||||
blackboxing.delete(event.spidermonkeyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function isBlackBoxed(spidermonkeyId, line, column) {
|
||||
const sourceBlackboxing = blackboxing.get(spidermonkeyId);
|
||||
|
||||
if (sourceBlackboxing == undefined) {
|
||||
return false;
|
||||
} else if (sourceBlackboxing.length === 0) {
|
||||
// An empty array represents a fully ignored source
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const range of sourceBlackboxing) {
|
||||
return (range.start.line < line || (range.start.line === line && range.start.column <= column))
|
||||
&& (range.end.line > line || (range.end.line === line && range.end.column >= column))
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
103
assets/servo/directory-listing.html
Normal file
103
assets/servo/directory-listing.html
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Index of</title>
|
||||
<style>
|
||||
h1 {
|
||||
border-bottom: 1px solid black;
|
||||
}
|
||||
|
||||
.listing {
|
||||
margin: 0.5em;
|
||||
display: table;
|
||||
}
|
||||
|
||||
.listing .header,
|
||||
.listing .entry {
|
||||
display: table-row;
|
||||
}
|
||||
|
||||
.listing .header {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.listing .header span,
|
||||
.listing .entry span {
|
||||
display: table-cell;
|
||||
padding-right: 1em;
|
||||
}
|
||||
|
||||
.entry span:nth-child(1) {
|
||||
min-width: 20em;
|
||||
}
|
||||
|
||||
.entry span.size,
|
||||
.entry span.last-modified {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.parent_link > a:before {
|
||||
content: "📁 ";
|
||||
}
|
||||
|
||||
.parent_link {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.entry.directory > .name:before {
|
||||
content: "📁 ";
|
||||
}
|
||||
|
||||
.entry.file > .name:before {
|
||||
content: "📄 ";
|
||||
}
|
||||
|
||||
.entry.symlink > .name:before {
|
||||
content: "🔗 ";
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function setData(directoryName, parentLink, rows) {
|
||||
document.title += " " + directoryName;
|
||||
document.querySelector("h1").innerHTML += " " + directoryName;
|
||||
|
||||
if (parentLink != "") {
|
||||
document.querySelector(".parent_link > a").href = parentLink;
|
||||
document.querySelector(".parent_link").style.display = "initial";
|
||||
}
|
||||
|
||||
rows.sort((rowA, rowB) => rowA[1].localeCompare(rowB[1]));
|
||||
|
||||
let listing = document.querySelector(".listing");
|
||||
let rowTemplate = document.getElementById("rowTemplate");
|
||||
for (row of rows) {
|
||||
let rowElement = rowTemplate.content.cloneNode(true);
|
||||
rowElement.querySelector(".entry").classList.add(row[0]);
|
||||
rowElement.querySelector(".name > .link").innerText = row[1];
|
||||
rowElement.querySelector(".name > .link").href = row[2];
|
||||
rowElement.querySelector(".size").innerText = row[3];
|
||||
rowElement.querySelector(".last-modified").innerText = row[4];
|
||||
listing.appendChild(rowElement);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Index of</h1>
|
||||
<div class="parent_link"><a href="">Up to parent directory</a></div>
|
||||
<div class="listing">
|
||||
<div class="header">
|
||||
<span class="name">Name</span>
|
||||
<span class="size">Size</span>
|
||||
<span class="last-modified">Last Modified</span>
|
||||
</div>
|
||||
</div>
|
||||
<template id="rowTemplate">
|
||||
<div class="entry">
|
||||
<span class="name"><a class="link"></a></span>
|
||||
<span class="size"></span>
|
||||
<span class="last-modified"></span>
|
||||
</div>
|
||||
</template>
|
||||
</body>
|
||||
</html>
|
||||
62
assets/servo/gatt_blocklist.txt
Normal file
62
assets/servo/gatt_blocklist.txt
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# Source:
|
||||
# https://github.com/WebBluetoothCG/registries/blob/master/gatt_blocklist.txt
|
||||
# License:
|
||||
# https://github.com/WebBluetoothCG/registries/blob/master/LICENSE
|
||||
|
||||
# This file holds a list of GATT UUIDs that websites using the Web
|
||||
# Bluetooth API are forbidden from accessing.
|
||||
|
||||
## Services
|
||||
|
||||
# org.bluetooth.service.human_interface_device
|
||||
# Direct access to HID devices like keyboards would let web pages
|
||||
# become keyloggers.
|
||||
00001812-0000-1000-8000-00805f9b34fb
|
||||
|
||||
# Firmware update services that don't check the update's signature
|
||||
# present a risk of devices' software being modified by malicious web
|
||||
# pages. Users may connect to a device believing they are enabling
|
||||
# only simple interaction or that they're interacting with the
|
||||
# device's manufacturer, but the site might instead persistently
|
||||
# compromise the device.
|
||||
#
|
||||
# Nordic's Device Firmware Update service, http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/examples_ble_dfu.html:
|
||||
00001530-1212-efde-1523-785feabcd123
|
||||
# TI's Over-the-Air Download service, http://www.ti.com/lit/ug/swru271g/swru271g.pdf:
|
||||
f000ffc0-0451-4000-b000-000000000000
|
||||
|
||||
|
||||
## Characteristics
|
||||
|
||||
# org.bluetooth.characteristic.gap.peripheral_privacy_flag
|
||||
# Don't let web pages turn off privacy mode.
|
||||
00002a02-0000-1000-8000-00805f9b34fb exclude-writes
|
||||
|
||||
# org.bluetooth.characteristic.gap.reconnection_address
|
||||
# Disallow messing with connection parameters
|
||||
00002a03-0000-1000-8000-00805f9b34fb
|
||||
|
||||
# org.bluetooth.characteristic.serial_number_string
|
||||
# Block access to standardized unique identifiers, for privacy reasons.
|
||||
00002a25-0000-1000-8000-00805f9b34fb
|
||||
|
||||
# Blocklisted characteristic used to test readValue function.
|
||||
bad1c9a2-9a5b-4015-8b60-1579bbbf2135 exclude-reads
|
||||
|
||||
|
||||
## Descriptors
|
||||
|
||||
# org.bluetooth.descriptor.gatt.client_characteristic_configuration
|
||||
# Writing to this would let a web page interfere with other pages'
|
||||
# notifications and indications.
|
||||
00002902-0000-1000-8000-00805f9b34fb exclude-writes
|
||||
|
||||
# org.bluetooth.descriptor.gatt.server_characteristic_configuration
|
||||
# Writing to this would let a web page interfere with the broadcasted services.
|
||||
00002903-0000-1000-8000-00805f9b34fb exclude-writes
|
||||
|
||||
# Blocklisted descriptor used to test.
|
||||
07711111-6104-0970-7011-1107105110aa
|
||||
|
||||
# Blocklisted descriptor used to test.
|
||||
aaaaaaaa-aaaa-1181-0510-810819516110 exclude-reads
|
||||
BIN
assets/servo/hsts_preload.fstmap
Normal file
BIN
assets/servo/hsts_preload.fstmap
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue