mirror of
https://github.com/morluto/rea
synced 2026-10-28 15:07:26 -04:00
fix(javascript): enforce semantic byte bounds for literals
Fixes #3933. Part of #4027. Normalize exact literals and configuration defaults through the shared primitive owner. Preserve tagged limits through member/destructuring projection and record encountered bounds in per-analysis state independently of later selected values. Remove the retained-value rescan and duplicate default reader. Preserve source Evidence, bounded/null values, aggregate wire capacity and complete endpoint lookup identities for query/trace/comparison. Validated 66 focused and 932 semantic tests on the restored identical runtime; final public selection 7/7 adds an augmented large-endpoint acceptance (67 distinct focused cases across invocations). Full static/docs and fresh real Obsidian controls passed. Compact measurements and rejected attempts remain recorded. Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
@@ -26,6 +26,7 @@ import type {
|
||||
JavaScriptSemanticValue,
|
||||
} from "./javascriptSemanticValueTypes.js";
|
||||
import {
|
||||
recordSemanticValueLimit,
|
||||
resolveSemanticBindingState,
|
||||
type JavaScriptSemanticAnalysisState,
|
||||
type JavaScriptSemanticBindingState,
|
||||
@@ -451,6 +452,15 @@ const evaluateBinding = (
|
||||
const evaluateExpression = (
|
||||
node: t.Node,
|
||||
context: EvaluationContext,
|
||||
): JavaScriptSemanticValue => {
|
||||
const value = evaluateExpressionValue(node, context);
|
||||
recordSemanticValueLimit(context.state, value);
|
||||
return value;
|
||||
};
|
||||
|
||||
const evaluateExpressionValue = (
|
||||
node: t.Node,
|
||||
context: EvaluationContext,
|
||||
): JavaScriptSemanticValue => {
|
||||
if (context.expressionDepth > SEMANTIC_EXPRESSION_DEPTH_LIMIT) {
|
||||
context.dependence.lowest = EVERY_CALLER;
|
||||
@@ -471,10 +481,7 @@ const evaluateExpression = (
|
||||
});
|
||||
}
|
||||
const literal = readExactJavaScriptLiteral(node);
|
||||
if (literal.found)
|
||||
return typeof literal.value === "number"
|
||||
? primitiveSet([literal.value])
|
||||
: { status: "literal", value: literal.value };
|
||||
if (literal.found) return primitiveSet([literal.value]);
|
||||
if (t.isIdentifier(node)) {
|
||||
const binding = resolveSemanticBindingState(context.state, node, node.name);
|
||||
return binding === undefined
|
||||
@@ -757,11 +764,12 @@ const projectValue = (
|
||||
value: JavaScriptSemanticValue,
|
||||
projection: readonly (string | number | null)[],
|
||||
): JavaScriptSemanticValue => {
|
||||
if (isSemanticResourceLimit(value)) return value;
|
||||
if (projection.includes(null))
|
||||
return { status: "unknown", reason: "Cannot project a dynamic property." };
|
||||
const path = projection.map((key) => String(key));
|
||||
const slot = semanticSlotAtPath(value, path);
|
||||
return slot.presence === "present"
|
||||
return slot.presence === "present" || isSemanticResourceLimit(slot.value)
|
||||
? slot.value
|
||||
: {
|
||||
status: "unknown",
|
||||
|
||||
Reference in New Issue
Block a user