mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
* feat(electron): report V8 cachedData execution boundaries
analyze-javascript-application treated new vm.Script(source, {cachedData}) and vm.compileFunction(..., {cachedData}) as ordinary source. V8 deserializes previously compiled bytecode for those calls, so an Electron preload wrapper that delegates its whole contextBridge and IPC surface to a .cache/.jsc snapshot appeared to have been fully analyzed with zero exposed APIs.
Record each vm compilation with its inert cache path when the cachedData value traces to a readFileSync/readFile of path syntax, and project a cached-data execution unknown plus a loads edge from the owning source. Compilations without a cache stay recorded as no-cached-data so absence remains distinguishable from an unparsed snapshot. Count cachedData executions in the Electron summary and state the coverage limit in the graph limitations.
* style(cli): wrap the native data type path description
The `inspect-native-data-type` argument description line is 82 columns, over the repository's 80-column `.oxfmtrc.json` limit, so `npm run format:check` fails on main and on every branch merged from it. It came in with #9465 and the following commits to this file did not touch it. Reformat the one call the formatter objects to; no behaviour change.
* style(domain): reformat the pending dynamic-code accumulator field
`npm run format:check` fails on this branch, which is what `Static checks` reports: oxfmt wants the `pendingDynamicCode` union on one line. Applying it is the whole change; no behaviour is touched.
* fix(electron): preserve VM callable and cache source uncertainty
* docs(javascript): specify cached-data compilation boundaries
* fix(electron): exclude disabled caches from recovered boundaries
---------
Co-authored-by: 2SinceJuly <202121119+2SinceJuly@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
59 lines
2.5 KiB
TypeScript
59 lines
2.5 KiB
TypeScript
import type { JavaScriptStaticAnalysis } from "./javascriptStaticAnalysisTypes.js";
|
|
|
|
/** Forecast static-fact expansion into observations, nodes and relationships. */
|
|
export const estimateJavaScriptStaticApplicationProjection = (
|
|
facts: JavaScriptStaticAnalysis,
|
|
checkpointBytes: number,
|
|
sourcePath: string,
|
|
): number => {
|
|
// A finding can produce a node, a separate observation and several edges.
|
|
// Allow for identifiers, locations, authority, coverage and schema copies,
|
|
// independently of the producer's compact checkpoint representation.
|
|
const findings =
|
|
(facts.electron.app_path_changes?.length ?? 0) +
|
|
facts.references.length +
|
|
facts.endpoints.length +
|
|
facts.storage.length +
|
|
facts.role_paths.length +
|
|
facts.source_map_urls.length +
|
|
facts.electron.browser_windows.length +
|
|
facts.electron.context_bridge_apis.length +
|
|
facts.electron.ipc.length +
|
|
facts.electron.sender_validations.length +
|
|
facts.electron.utility_processes.length +
|
|
facts.electron.native_addon_bindings.length +
|
|
facts.electron.protocols.length +
|
|
(facts.electron.dynamic_code ?? []).length;
|
|
let records = findings * 8;
|
|
let repeatedBytes = 0;
|
|
for (const registration of facts.bundler_registrations) {
|
|
records +=
|
|
3 +
|
|
registration.modules.length * 3 +
|
|
registration.entry_module_keys.length * 3 +
|
|
registration.async_chunk_keys.length * 3;
|
|
// Every module observation and containment edge repeats its chunk keys.
|
|
repeatedBytes +=
|
|
Buffer.byteLength(JSON.stringify(registration.chunk_keys)) *
|
|
registration.modules.length *
|
|
2;
|
|
}
|
|
for (const binding of facts.electron.native_addon_bindings)
|
|
records += binding.members.length * 3;
|
|
for (const path of facts.electron.call_paths ?? []) {
|
|
// One contextual node and edge per step, with repeated guards and identity.
|
|
records += path.steps.length * 4 + 8;
|
|
repeatedBytes +=
|
|
Buffer.byteLength(JSON.stringify(path.conditions)) *
|
|
path.steps.length *
|
|
2;
|
|
}
|
|
// The per-record allowance already covers retention: projected Vite-style
|
|
// chunks serialize to about 0.46 KB per record, under a quarter of it.
|
|
// Expanding the allowance again charged about 25x the serialized
|
|
// relationships, so a few files used up the parent budget that every later
|
|
// source shares. Checkpoint and repeated bytes keep their expansion.
|
|
const metadataBytes = 2048 + Buffer.byteLength(sourcePath) * 4;
|
|
return (checkpointBytes * 4 + repeatedBytes) * 8 + records * metadataBytes;
|
|
};
|