mirror of
https://github.com/morluto/rea
synced 2026-10-28 06:46:47 -04:00
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:
@@ -6,9 +6,16 @@ import {
|
||||
unwrapJavaScriptExpression,
|
||||
} from "./javascriptAstValues.js";
|
||||
|
||||
/** Expand only literal array spreads whose positional arguments are all known. */
|
||||
export type JavaScriptArrayIterationProof = (
|
||||
array: t.ArrayExpression,
|
||||
) => boolean;
|
||||
|
||||
const unknownArrayIteration: JavaScriptArrayIterationProof = () => false;
|
||||
|
||||
/** Expand literal array spreads only when their native iterator is proven. */
|
||||
export const expandJavaScriptInvocationArguments = (
|
||||
arguments_: readonly t.CallExpression["arguments"][number][],
|
||||
nativeArrayIteration: JavaScriptArrayIterationProof = unknownArrayIteration,
|
||||
): t.CallExpression["arguments"] => {
|
||||
const expanded: t.CallExpression["arguments"] = [];
|
||||
const pending = [...arguments_].reverse();
|
||||
@@ -20,6 +27,7 @@ export const expandJavaScriptInvocationArguments = (
|
||||
: undefined;
|
||||
if (
|
||||
t.isArrayExpression(array) &&
|
||||
nativeArrayIteration(array) &&
|
||||
array.elements.every(
|
||||
(element) => t.isExpression(element) || t.isSpreadElement(element),
|
||||
)
|
||||
@@ -33,7 +41,10 @@ export const expandJavaScriptInvocationArguments = (
|
||||
return expanded;
|
||||
};
|
||||
|
||||
const arrayArguments = (node: t.Node | undefined) => {
|
||||
const arrayArguments = (
|
||||
node: t.Node | undefined,
|
||||
nativeArrayIteration: JavaScriptArrayIterationProof,
|
||||
) => {
|
||||
const array =
|
||||
node === undefined ? undefined : unwrapJavaScriptExpression(node).node;
|
||||
if (
|
||||
@@ -45,6 +56,7 @@ const arrayArguments = (node: t.Node | undefined) => {
|
||||
array.elements.filter(
|
||||
(element): element is t.Expression | t.SpreadElement => element !== null,
|
||||
),
|
||||
nativeArrayIteration,
|
||||
);
|
||||
return expanded.every((element) => t.isExpression(element))
|
||||
? expanded.filter((element): element is t.Expression =>
|
||||
@@ -56,13 +68,80 @@ const arrayArguments = (node: t.Node | undefined) => {
|
||||
const invocationArguments = (
|
||||
method: "call" | "apply",
|
||||
arguments_: JavaScriptIntrinsicInvocation["arguments"],
|
||||
nativeArrayIteration: JavaScriptArrayIterationProof,
|
||||
) =>
|
||||
t.isSpreadElement(arguments_?.[0])
|
||||
? undefined
|
||||
: method === "apply"
|
||||
? arrayArguments(arguments_?.[1])
|
||||
? arrayArguments(arguments_?.[1], nativeArrayIteration)
|
||||
: arguments_?.slice(1);
|
||||
|
||||
/** Positional state needed only by generic Function.call/apply invocation. */
|
||||
export interface JavaScriptSourceInvocationContext {
|
||||
readonly receiver: t.Node | undefined;
|
||||
readonly receiverUnknown?: boolean;
|
||||
readonly arguments: JavaScriptIntrinsicInvocation["arguments"];
|
||||
}
|
||||
|
||||
/** Only these generic function members consume a callable receiver. */
|
||||
export const javaScriptGenericInvocationMethod = (
|
||||
callee: t.Node,
|
||||
): "call" | "apply" | undefined => {
|
||||
const expression = unwrapJavaScriptExpression(callee).node;
|
||||
const method =
|
||||
t.isMemberExpression(expression) || t.isOptionalMemberExpression(expression)
|
||||
? semanticStaticPropertyKey(expression.property, expression.computed)
|
||||
: undefined;
|
||||
return method === "call" || method === "apply" ? method : undefined;
|
||||
};
|
||||
|
||||
/** A member call supplies its receiver; a captured/comma callable does not. */
|
||||
export const javaScriptSourceInvocationContext = (
|
||||
node: t.CallExpression | t.OptionalCallExpression,
|
||||
nativeArrayIteration: JavaScriptArrayIterationProof = unknownArrayIteration,
|
||||
): JavaScriptSourceInvocationContext => {
|
||||
const callee = unwrapJavaScriptExpression(node.callee).node;
|
||||
return {
|
||||
receiver:
|
||||
t.isMemberExpression(callee) || t.isOptionalMemberExpression(callee)
|
||||
? callee.object
|
||||
: undefined,
|
||||
arguments: expandJavaScriptInvocationArguments(
|
||||
node.arguments,
|
||||
nativeArrayIteration,
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
/** Select one generic function receiver without evaluating function arguments. */
|
||||
export const resolveJavaScriptGenericInvocation = (
|
||||
method: "call" | "apply",
|
||||
context: JavaScriptSourceInvocationContext,
|
||||
nativeArrayIteration: JavaScriptArrayIterationProof = unknownArrayIteration,
|
||||
):
|
||||
| {
|
||||
readonly callable: t.Expression;
|
||||
readonly context: JavaScriptSourceInvocationContext;
|
||||
}
|
||||
| undefined =>
|
||||
!t.isExpression(context.receiver)
|
||||
? undefined
|
||||
: {
|
||||
callable: context.receiver,
|
||||
context: {
|
||||
receiver: context.arguments?.[0],
|
||||
...(context.arguments === undefined ||
|
||||
t.isSpreadElement(context.arguments[0])
|
||||
? { receiverUnknown: true }
|
||||
: {}),
|
||||
arguments: invocationArguments(
|
||||
method,
|
||||
context.arguments,
|
||||
nativeArrayIteration,
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize known invocation syntax once, retaining bound argument prefixes.
|
||||
* Binding a function alone is not a write; only its eventual call is examined.
|
||||
@@ -72,11 +151,12 @@ export const resolveJavaScriptIntrinsicInvocation = (
|
||||
intrinsicPath: (node: t.Node) => readonly string[] | undefined,
|
||||
boundIntrinsic: (node: t.Node) => JavaScriptIntrinsicInvocation | undefined,
|
||||
intrinsicReadChanged: (node: t.Node, path: readonly string[]) => boolean,
|
||||
nativeArrayIteration: JavaScriptArrayIterationProof = unknownArrayIteration,
|
||||
): JavaScriptIntrinsicInvocation | undefined => {
|
||||
const visited = new Set<t.Node>();
|
||||
let callee: t.Node = node.callee;
|
||||
let arguments_: JavaScriptIntrinsicInvocation["arguments"] =
|
||||
expandJavaScriptInvocationArguments(node.arguments);
|
||||
expandJavaScriptInvocationArguments(node.arguments, nativeArrayIteration);
|
||||
let receiver: t.Node | undefined;
|
||||
let explicitReceiver = false;
|
||||
for (;;) {
|
||||
@@ -106,15 +186,21 @@ export const resolveJavaScriptIntrinsicInvocation = (
|
||||
);
|
||||
if (method === "call" || method === "apply") {
|
||||
const bound = boundIntrinsic(callee.object);
|
||||
// Caller-selected native loaders share Function.prototype authority.
|
||||
const callablePath = bound?.path ?? intrinsicPath(callee.object);
|
||||
if (
|
||||
bound !== undefined &&
|
||||
intrinsicReadChanged(callee, [...bound.path, method])
|
||||
callablePath !== undefined &&
|
||||
intrinsicReadChanged(callee, [...callablePath, method])
|
||||
)
|
||||
return { kind: "opaque", path: bound.path, arguments: undefined };
|
||||
return { kind: "opaque", path: callablePath, arguments: undefined };
|
||||
receiver = arguments_?.[0];
|
||||
explicitReceiver = true;
|
||||
callee = callee.object;
|
||||
arguments_ = invocationArguments(method, arguments_);
|
||||
arguments_ = invocationArguments(
|
||||
method,
|
||||
arguments_,
|
||||
nativeArrayIteration,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -138,12 +224,20 @@ export const resolveJavaScriptIntrinsicInvocation = (
|
||||
: t.isMemberExpression(callee) || t.isOptionalMemberExpression(callee)
|
||||
? callee.object
|
||||
: undefined;
|
||||
if (!t.isExpression(callable))
|
||||
const selected = resolveJavaScriptGenericInvocation(
|
||||
method,
|
||||
{
|
||||
receiver: callable,
|
||||
arguments: arguments_,
|
||||
},
|
||||
nativeArrayIteration,
|
||||
);
|
||||
if (selected === undefined)
|
||||
return { kind: "opaque", path, arguments: undefined };
|
||||
callee = callable;
|
||||
receiver = arguments_?.[0];
|
||||
callee = selected.callable;
|
||||
receiver = selected.context.receiver;
|
||||
explicitReceiver = true;
|
||||
arguments_ = invocationArguments(method, arguments_);
|
||||
arguments_ = selected.context.arguments;
|
||||
continue;
|
||||
}
|
||||
if (path.join(".") === "intrinsic.Reflect.apply") {
|
||||
@@ -152,7 +246,7 @@ export const resolveJavaScriptIntrinsicInvocation = (
|
||||
callee = callable;
|
||||
receiver = arguments_?.[1];
|
||||
explicitReceiver = true;
|
||||
arguments_ = arrayArguments(arguments_?.[2]);
|
||||
arguments_ = arrayArguments(arguments_?.[2], nativeArrayIteration);
|
||||
continue;
|
||||
}
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user