fix(javascript): preserve runtime path bytes and Electron ownership (#4941)

* fix(javascript): preserve literal percent runtime paths

* fix(javascript): ignore resolve prefixes before the final anchor

* fix(electron): retain application roots for loadFile declarations

* fix(electron): resolve loadFile from enclosing application package

* fix(electron): retain outer application root across package scopes

* fix(electron): derive application ownership from inventoried packages

* fix(electron): retain resolved package entrypoint ownership

* fix(electron): preserve competing application ownership

* fix(electron): retain invalid and omitted runtime ownership

* fix(electron): preserve omitted module ownership and runtime paths

* fix(electron): preserve proven roots before confining page paths

* fix(electron): retain possible owners behind missing imports

* fix(electron): distinguish absent imports and owned page candidates

* fix(electron): keep unavailable JSON out of owner gaps

* fix(electron): retain exact loader formats and default entry status

* fix(electron): retain unavailable entrypoint ownership candidates

* test(ghidra): preserve Windows Node probe prerequisites

* test(ghidra): assert cancellation during profile shutdown

* fix(electron): separate examined imports from frontend ownership

* fix(electron): retain unavailable directory entrypoint owners

* test(jeb): retain Linux ownership prerequisite in isolation

* fix(javascript): retain unchecked loader ownership and literal main paths

* fix(javascript): preserve runtime paths and call-site module aliases

* fix(javascript): bound module alias traversal and preserve projections

* fix(javascript): retain host module and nested artifact path boundaries

* fix(javascript): preserve ESM and archive module loader provenance

* test(javascript): distinguish unmapped containers from missing exports

* fix: retain default module aliases and Electron builtin imports

* fix: preserve host file URL and inward ASAR ownership

* fix: preserve CommonJS file URL classification in CI fixtures

* fix: retain bound module loaders and Windows entrypoint uncertainty

* fix: retain ASAR uncertainty and invalidate changed Electron app roots

* fix(javascript): retain ownership uncertainty across loader boundaries

* fix(javascript): preserve loader sources and bound alias queries

* fix(javascript): retain destructured loader sources

* fix(javascript): preserve loader uncertainty at resolution boundaries

* fix(javascript): preserve callable and package launch ownership

* fix(javascript): preserve captured values across member reads

* test(process): assert tagged filesystem cancellation failures

* fix(javascript): preserve inventory bases and invocation read timing

* fix(javascript): preserve ownership across indirect and unread loads

* test(javascript): order fixture directory creation on Windows

* test(javascript): share ordered filesystem fixture writer

* fix(javascript): unify loader provenance and package validation

* fix(javascript): preserve captured Node require loader values

* fix(javascript): preserve loader invocation authority

* fix(javascript): verify generic loader invocation authority

* fix(javascript): preserve conditional loader method alternatives

* fix(javascript): require proven factories for source association

* fix(javascript): honor replaced Electron app path setters

* fix(javascript): prove path and assignment source ownership

* fix(javascript): retain native delegate eligibility through shared writes

* fix(process): settle stale baseline errors after confirmed absence

* fix(javascript): preserve assignment and path boundary evidence

* fix(javascript): prove source-directory resolve anchors

* fix: preserve application path provenance and portable schemas

* fix(javascript): retain CommonJS exported setter effects

* fix: isolate Linux identity observations and retain native module exports

* fix(javascript): preserve published app and helper provenance

* fix(javascript): normalize typed stores and native path fixtures
This commit is contained in:
ShuaixinHuang
2026-10-20 17:25:19 +08:00
committed by GitHub
parent d532b18123
commit e9fc8fb30c
149 changed files with 16881 additions and 988 deletions
@@ -25,7 +25,6 @@ import {
import { range } from "./javascriptStaticAnalysisHelpers.js";
import {
propertyName,
semanticFinalObjectProperty,
semanticStaticPropertyKey,
semanticWrappedWriteSite,
semanticWriteSiteReadsFirst,
@@ -40,11 +39,11 @@ import {
semanticImportEqualsSpecifier,
} from "./javascriptModuleDeclaration.js";
import {
commonJsDefinedExport,
commonJsExportName,
commonJsRuntimeExportValues,
type CommonJsExportReceiverEffect,
type CommonJsExportSite,
} from "./javascriptCommonJsExportReceivers.js";
import type { JavaScriptSemanticPropertyPath } from "./javascriptSemanticPropertyPaths.js";
interface CollectCallableInput {
readonly node: t.Node;
@@ -124,7 +123,7 @@ export const collectSemanticModuleLink = (
else if (t.isAssignmentExpression(node))
collectCommonJsExport(node, state, commonJsReceivers.get(node));
else if (t.isCallExpression(node)) {
collectDefinedCommonJsExport(node, state, commonJsReceivers.get(node));
collectCommonJsExport(node, state, commonJsReceivers.get(node));
collectUnboundRequireLink(node, state);
}
};
@@ -472,34 +471,21 @@ const requirePatternBindings = (
};
const collectCommonJsExport = (
node: t.AssignmentExpression,
node: CommonJsExportSite,
state: JavaScriptSemanticAnalysisState,
receiverEffect: CommonJsExportReceiverEffect | undefined,
): void => {
const exportedName = commonJsExportName(node.left, state);
if (exportedName === undefined) return;
if (receiverEffect === "detached") return;
// Compound and logical writes also depend on the previous value, so remain
// unknown.
const value =
node.operator === "=" && receiverEffect !== "uncertain" ? node.right : null;
addCommonJsExport(node, state, exportedName, value);
};
const collectDefinedCommonJsExport = (
node: t.CallExpression,
state: JavaScriptSemanticAnalysisState,
receiverEffect: CommonJsExportReceiverEffect | undefined,
): void => {
const defined = commonJsDefinedExport(node, state);
if (defined === undefined || receiverEffect === "detached") return;
// A data descriptor exports its value; an accessor's result stays unknown.
const descriptor = unwrapJavaScriptExpression(defined.descriptor).node;
const value =
receiverEffect !== "uncertain" && t.isObjectExpression(descriptor)
? (semanticFinalObjectProperty(descriptor, "value") ?? null)
: null;
addCommonJsExport(node, state, defined.exportedName, value);
for (const exported of commonJsRuntimeExportValues(node, state))
addCommonJsExport(
node,
state,
exported.exportedName,
receiverEffect === "uncertain" ? null : exported.value,
exported.projection,
);
};
const addCommonJsExport = (
@@ -507,6 +493,7 @@ const addCommonJsExport = (
state: JavaScriptSemanticAnalysisState,
exportedName: string,
exported: t.Node | null,
projection?: JavaScriptSemanticPropertyPath,
): void => {
// Simple assignment chains yield their rightmost assigned value.
let value = exported;
@@ -514,21 +501,41 @@ const addCommonJsExport = (
value = value.right;
const required =
value === null ? undefined : semanticRequireOrigin(value, state);
const origin = required?.origin;
// Copies retain their module provenance, but do not export the source object
// itself. A wildcard with exclusions cannot express one module link.
const origin = projection?.some(
(key) =>
typeof key === "object" && key !== null && key.excludedKeys.length > 0,
)
? undefined
: required?.origin;
const selectedName = projection?.at(-1);
addModuleLink(
state,
{
kind: "commonjs-export",
specifier: origin?.specifier ?? null,
importedName: origin?.importedPath.at(-1) ?? null,
localName: value !== null && t.isIdentifier(value) ? value.name : null,
importedName:
origin === undefined
? null
: typeof selectedName === "string" || typeof selectedName === "number"
? String(selectedName)
: (origin.importedPath.at(-1) ?? null),
localName:
projection === undefined && value !== null && t.isIdentifier(value)
? value.name
: null,
exportedName,
callableId: value === null ? null : semanticCallableIdForNode(value),
callableId:
projection !== undefined || value === null
? null
: semanticCallableIdForNode(value),
location: range(node),
},
node,
);
if (required !== undefined) state.linkedRequireCalls.add(required.call);
if (origin !== undefined && required !== undefined)
state.linkedRequireCalls.add(required.call);
};
const addModuleLink = (