mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 13:45:30 +00:00
fix(javascript): count escapes of Function.prototype before trusting call and apply (#11501)
* fix(javascript): count escapes of Function.prototype before trusting call and apply * fix(javascript): key cached returned references on ambient escapes too * fix(javascript): track arguments of directly invoked functions through their parameters (#11538) * fix(javascript): track arguments of directly invoked functions through their parameters Passing a value to a function expression invoked where it is defined, such as a UMD header (function(root, factory){...})(this, ...), recorded an escape of the argument to unevaluated code although the callee's body is source code whose effects are indexed. javascriptSemanticDirectInvocations owns which arguments reach such a callee only through a plain parameter; the ambient path resolver and member mutation indexing follow that parameter back to its argument, and neither records an escape for it. Spread and rest lists, pattern or default parameters, arguments and direct eval keep the escape, as do unknown callees. Refs #11499 * fix(javascript): escape values thrown out of a function and scan arguments once A value thrown out of a function or class body reaches handlers the throw-to-catch index does not link to it. Arguments of a directly invoked function used to hide this behind the call escape; they no longer do, and captured values had the same gap. The binding pass records such throws, and ambient and member effect indexing escape their values at the throw. Which functions name 'arguments' is now found in one program walk instead of one subtree scan per directly invoked function. * perf(javascript): find shadowed direct-invocation parameters in one pass * fix(javascript): settle Object and Reflect static call receivers in one owner (#11543) * fix(javascript): settle Object and Reflect static call receivers in one owner Ambient write indexing skipped the receiver escape of any resolved Object or Reflect static call, even when source code had replaced the method, while member mutation indexing escaped the constructor for every such call. The second escape (global.Object contents) made each later Function.prototype.call/apply check uncertain in bundles that call Object.defineProperty or Object.freeze. Ambient indexing now settles these receivers once all ambient writes are known: the constructor escapes only when a write or escape may replace the method before the call, and member mutation reuses that decision through retainedGlobalCallReceivers. Refs #11535 * fix(javascript): retain the receiver only for native Object and Reflect statics A resolved Object member that is not one of the language's own static methods (for example one Object inherits from Function.prototype, or an unknown name) may be user code that receives the constructor, so its call keeps the receiver escape. * fix(javascript): look up intrinsic and builtin method tables by own key only NATIVE_STATIC_METHODS and BUILTIN_RECEIVER_METHODS were plain objects, so an owner such as globalThis.constructor or a module named 'constructor' or 'toString' found an inherited Object.prototype function and analysis threw a TypeError on '.has'. Both are Maps now. * fix(javascript): escape values thrown uncaught at the top level (#11556) A value thrown uncaught at the top level reaches the host's uncaught-exception handlers (process.on('uncaughtException'), window.onerror), which may change it before a timer or callback reads it. The binding pass recorded escaping throws only when the walk reached a function or class body; a throw that reaches the program without a handler now escapes the same way. * fix(javascript): follow direct-invocation arguments through returned references and function arguments properties A callable argument of a directly invoked function no longer escapes at the call, but the shared returned-reference owner could not follow the parameter to it, so patch(get()) inside the callee lost the escape of the value get returns. The returned-reference walk now follows the parameter to its argument like the write and escape walkers. A sloppy function's arguments property (f["arguments"], g.caller.arguments from a function it calls) exposes its activation's arguments. A non-strict callee is no longer tracked through its parameters when the program reads an arguments or caller property by a static key. The strictness reader moves beside javaScriptProgramStrictness so both modules share it.
This commit is contained in:
1 parent
ff6467ca97
commit
a86a668718
14 files changed
+826
-68
No files matched your search
@@ -441,12 +441,17 @@ export const ambientBindingMayObserveWriteAt = (
|
||||
);
|
||||
|
||||
/**
|
||||
* A count that grows whenever an ambient write is recorded. A cache that
|
||||
* depends on ambient writes stores it and recomputes when it differs.
|
||||
* A count that grows whenever an ambient write is recorded, or with
|
||||
* `"contents"` also an ambient escape: the effects `ambientPathMayObserveAt`
|
||||
* reads with the same argument. A cache that depends on them stores it and
|
||||
* recomputes when it differs.
|
||||
*/
|
||||
export const semanticAmbientWriteGeneration = (
|
||||
export const semanticAmbientEffectGeneration = (
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): number => state.ambientWriteEffects.length;
|
||||
observes: "value" | "contents" = "value",
|
||||
): number =>
|
||||
state.ambientWriteEffects.length +
|
||||
(observes === "contents" ? state.ambientEscapeEffects.length : 0);
|
||||
|
||||
/**
|
||||
* A count that grows whenever a member write or escape is recorded on
|
||||
|
||||
Reference in new issue
Block a user