mirror of
https://github.com/morluto/rea.git
synced 2026-10-29 02:45:58 +00:00
fix(runtime): retain Inspector and Electron cleanup ownership
This commit is contained in:
1 parent
7f4e7d5577
commit
87ab054ea3
23 files changed
+1901
-321
No files matched your search
@@ -22,9 +22,12 @@ export type RuntimeLocationDecision =
|
||||
/** Throw the operation's typed cancellation error whenever its signal is aborted. */
|
||||
export const throwIfRuntimeObservationCancelled = (
|
||||
signal?: AbortSignal,
|
||||
operation:
|
||||
| "observe_javascript_runtime"
|
||||
| "list_javascript_runtime_targets" = "observe_javascript_runtime",
|
||||
): void => {
|
||||
if (signal?.aborted === true)
|
||||
throw new AnalysisCancelledError("observe_javascript_runtime");
|
||||
throw new AnalysisCancelledError(operation, { cause: signal.reason });
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -45,11 +48,14 @@ export const inspectorExclusionKey = (
|
||||
export const authorizeRuntimeLocation = async (
|
||||
value: string,
|
||||
signal?: AbortSignal,
|
||||
operation:
|
||||
| "observe_javascript_runtime"
|
||||
| "list_javascript_runtime_targets" = "observe_javascript_runtime",
|
||||
): Promise<RuntimeLocationDecision> => {
|
||||
throwIfRuntimeObservationCancelled(signal);
|
||||
throwIfRuntimeObservationCancelled(signal, operation);
|
||||
if (value.startsWith("file:")) {
|
||||
const filePath = await authorizedElectronFile(value);
|
||||
throwIfRuntimeObservationCancelled(signal);
|
||||
const filePath = await authorizedElectronFile(value, signal, operation);
|
||||
throwIfRuntimeObservationCancelled(signal, operation);
|
||||
return filePath === undefined
|
||||
? { allowed: false, reason: "not_approved" }
|
||||
: { allowed: true, location: { kind: "file", file_path: filePath } };
|
||||
@@ -93,6 +99,10 @@ export const projectReportedRuntimeUrl = (
|
||||
export const authorizeRuntimeTargetLocation = async (
|
||||
value: string,
|
||||
context: { readonly type: string; readonly product: string },
|
||||
signal?: AbortSignal,
|
||||
operation:
|
||||
| "observe_javascript_runtime"
|
||||
| "list_javascript_runtime_targets" = "list_javascript_runtime_targets",
|
||||
): Promise<
|
||||
| {
|
||||
readonly allowed: true;
|
||||
@@ -100,15 +110,16 @@ export const authorizeRuntimeTargetLocation = async (
|
||||
}
|
||||
| { readonly allowed: false; readonly reason: BrowserExclusionReason }
|
||||
> => {
|
||||
throwIfRuntimeObservationCancelled(signal, operation);
|
||||
if (
|
||||
context.type !== "node" ||
|
||||
!/^node\.js\/v/iu.test(context.product) ||
|
||||
!value.startsWith("file://")
|
||||
)
|
||||
return authorizeRuntimeLocation(value);
|
||||
return authorizeRuntimeLocation(value, signal, operation);
|
||||
const reportedPath = value.slice("file://".length);
|
||||
if (!reportedPath.startsWith("/") && !/^[a-z]:[/\\_]/iu.test(reportedPath))
|
||||
return authorizeRuntimeLocation(value);
|
||||
return authorizeRuntimeLocation(value, signal, operation);
|
||||
|
||||
// Node concatenates the pathname, then replaces quotes and backslashes with
|
||||
// underscores. A remaining underscore cannot prove which pathname was used.
|
||||
@@ -116,6 +127,8 @@ export const authorizeRuntimeTargetLocation = async (
|
||||
if (reportedPath.startsWith("/")) {
|
||||
const decision = await authorizeRuntimeLocation(
|
||||
pathToFileURL(reportedPath).href,
|
||||
signal,
|
||||
operation,
|
||||
);
|
||||
if (decision.allowed) return decision;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user