@zvenigora/ng-eval-core 0.13.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +84 -1
- package/README.md +17 -4
- package/fesm2022/zvenigora-ng-eval-core.mjs +267 -43
- package/fesm2022/zvenigora-ng-eval-core.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -14,13 +14,96 @@ Versions 0.1.104–0.1.107 are on npm without entries here.
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
+
## [0.14.0] - 2026-10-25
|
|
18
|
+
|
|
19
|
+
**An assignment evaluates its target as JavaScript does.** A minor carrying breaking changes
|
|
20
|
+
([A45](../../docs/backlog-retired.md#a45) part 2, [A44](../../docs/backlog-retired.md#a44),
|
|
21
|
+
[A52](../../docs/backlog-retired.md#a52); the [A45 plan](../../docs/a45/plan.md)). No exported
|
|
22
|
+
symbol changes shape: the `.d.ts` is byte-identical to 0.13.3's. What changes is behaviour —
|
|
23
|
+
which reads an assignment makes and reports, which key a `caseInsensitive` write reaches, and what
|
|
24
|
+
an identifier holding `null` reads as under `caseInsensitive`. `eval-signals` 0.7.0 and `eval-forms` 0.7.0 raise
|
|
25
|
+
their floors to it.
|
|
26
|
+
|
|
27
|
+
### Breaking
|
|
28
|
+
- **A compound or logical assignment reads its target once, and does not walk it.** A
|
|
29
|
+
member target's object and key are evaluated once, before the right side, and the write reuses
|
|
30
|
+
them: `getObj()[k()] += f()` runs `getObj`, `k`, the read, `f`, then the write, where up to 0.13.3
|
|
31
|
+
it evaluated the object, the key and the read a second time after `f`. A getter on the target is
|
|
32
|
+
called once where it was called twice. Two are read twice where they were read four times: a
|
|
33
|
+
prototype accessor under `caseInsensitive` ([A48](../../docs/backlog.md#a48)), and an accessor
|
|
34
|
+
on the context reached through `this` ([A49](../../docs/backlog.md#a49)). The read events are those of that one read, `a`, then `a.b`, where each was reported
|
|
35
|
+
twice; node hooks and the trace see the target's object and a computed key, and no longer the
|
|
36
|
+
target node, and an identifier target not at all. The value read still passes the checks every
|
|
37
|
+
read value passes, so a listed function as the target, `fetch += 1` or `obj.fetch ||= 1`, is
|
|
38
|
+
still refused ([A45](../../docs/backlog-retired.md#a45), part 2).
|
|
39
|
+
- **`=` does not read its target, and walks it no further than its object and a computed
|
|
40
|
+
key.** As in JavaScript, `getObj()[k()] = f()` runs `getObj`, `k`, `f`, then the write, where up
|
|
41
|
+
to 0.13.3 it read the target, and after `f` evaluated the object and the key and read the target a
|
|
42
|
+
second time. A getter on the target is not called, except an accessor on the context reached
|
|
43
|
+
through `this`, which is called once where it was called four times
|
|
44
|
+
([A49](../../docs/backlog.md#a49)); under `caseInsensitive` a lookup answering an identifier
|
|
45
|
+
target's name is called once, where it was called twice (A49). A listed function as the target is overwritten
|
|
46
|
+
as `obj.fetch++` overwrites one, so `fetch = 1` and `obj.fetch = 1` write `1` where they were
|
|
47
|
+
refused; `fetch += 1` and `fetch ||= 1` read it, and are still refused. The read events are the
|
|
48
|
+
object's own reads: `a.b = 1` reports `a`, where it reported `a` and `a.b` twice each, and
|
|
49
|
+
`x = 1` and `this.x = 1` report nothing. Node hooks and the trace see the object and a computed
|
|
50
|
+
key, and no longer the target node, and an identifier target not at all. The blocklist checks a
|
|
51
|
+
target was given by being read stay, before the right side: `constructor = 1` and
|
|
52
|
+
`o.__proto__ = f()` are refused with `f` not called. Case-sensitive, a `null` or `undefined`
|
|
53
|
+
object with a blocklisted key, `n.constructor = 1`, is now refused as a dangerous property, as it
|
|
54
|
+
already was under `caseInsensitive`, where it was refused as `Cannot set property on non-object`
|
|
55
|
+
([A45](../../docs/backlog-retired.md#a45), part 2).
|
|
56
|
+
- **An identifier update reports the read of its operand**: `x++` and `++x` report one
|
|
57
|
+
read of `x`, as `a.b++` reports one of `a.b`, where they reported none. So a dependency tracker
|
|
58
|
+
records `x`, and a `for` loop's `i++` adds its reads, each flagged `scoped`.
|
|
59
|
+
|
|
60
|
+
### Changed
|
|
61
|
+
- **The README states what an assignment target reads and reports**, in the `AssignmentExpression`
|
|
62
|
+
row and beside `onRead`, with the reads that remain beyond JavaScript's, and that under
|
|
63
|
+
`caseInsensitive` a member write or update reaches the key the read would match. No code change.
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
- **Under `caseInsensitive`, a member write reaches the key the read would match**: `OBJ.X = 2`,
|
|
67
|
+
`obj["X"] = 2`, `OBJ.X += 1` and `OBJ.X++` on `{ obj: { x: 1 } }` write `x`, where they created a new key `X`
|
|
68
|
+
beside it, and `c.G = 1` calls the setter `g` an instance inherits. A key the lookup matches on
|
|
69
|
+
nothing is written as spelled ([A44](../../docs/backlog-retired.md#a44)).
|
|
70
|
+
- **Under `caseInsensitive`, an identifier holding `null` reads as `null`**, where it read as
|
|
71
|
+
`undefined`: `x === null` is `true`, and `x += 1` gives `1`, where it gave `NaN`. The literals
|
|
72
|
+
registry now answers only a name the context finds nothing for
|
|
73
|
+
([A52](../../docs/backlog-retired.md#a52)).
|
|
74
|
+
|
|
75
|
+
### Security
|
|
76
|
+
- **An identifier update of a blocklisted name is refused**, as its assignment is: `constructor++`,
|
|
77
|
+
`toString++` and `__proto__++` throw `Access to dangerous property … is blocked for security
|
|
78
|
+
reasons`, where up to 0.13.3 the first two wrote an own key onto the caller's context, and under
|
|
79
|
+
`caseInsensitive` all three wrote into its copy.
|
|
80
|
+
- **An identifier update of `this` written as a name is refused**, as every other use of it outside
|
|
81
|
+
a member's object is: `This++` under `caseInsensitive`, and a host-built `this++`, throw `Access
|
|
82
|
+
to "this" outside a member access is blocked for security reasons`, where up to 0.13.3 they wrote
|
|
83
|
+
`NaN` under that key.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## [0.13.3] - 2026-10-23
|
|
88
|
+
|
|
89
|
+
### Fixed
|
|
90
|
+
- **A logical assignment that short-circuits no longer evaluates its right side or writes**:
|
|
91
|
+
`a ||= f()` with `a` truthy does not call `f`, and a write policy is not asked about a write that
|
|
92
|
+
does not happen. A refusal on the write path, such as a `const` binding or a read-only name, no
|
|
93
|
+
longer fires when the assignment short-circuits and writes nothing, as in JavaScript. Logical
|
|
94
|
+
assignment is ES2021, and the default parser options, at `ecmaVersion: 2020`, refuse it at the
|
|
95
|
+
parse, so this reaches only a caller whose own parser options set `ecmaVersion` to 2021 or later
|
|
96
|
+
([A45](../../docs/backlog-retired.md#a45), part 1).
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
17
100
|
## [0.13.2] - 2026-10-22
|
|
18
101
|
|
|
19
102
|
### Changed
|
|
20
103
|
- **The README states a limit of `caseInsensitive` on a context built with `new EvalContext`**: a
|
|
21
104
|
plain object handed to the constructor matches no case variant, even with the option passed to
|
|
22
105
|
the walk too, and `EvalContext.fromContext` is the way to build one that does. No code change
|
|
23
|
-
([A44](../../docs/backlog.md#a44), where it was measured).
|
|
106
|
+
([A44](../../docs/backlog-retired.md#a44), where it was measured).
|
|
24
107
|
|
|
25
108
|
### Fixed
|
|
26
109
|
- **An update converts its operand to a number once, as JavaScript does**, and uses that one
|
package/README.md
CHANGED
|
@@ -274,12 +274,23 @@ The project has been tested with the following node types:
|
|
|
274
274
|
- `TemplateLiteral`
|
|
275
275
|
- `TaggedTemplateExpression`
|
|
276
276
|
- `ObjectExpression`
|
|
277
|
-
- `AssignmentExpression` — to an identifier or a member, parenthesised or not.
|
|
278
|
-
|
|
277
|
+
- `AssignmentExpression` — to an identifier or a member, parenthesised or not. Since 0.14.0 the
|
|
278
|
+
target is evaluated as JavaScript evaluates it: a member target's object and key once, then
|
|
279
|
+
the target's value only for a compound or logical operator, then the right side, then the
|
|
280
|
+
write. So `=` does not read its target, and `+=` or `||=` reads it once; up to 0.13.3 the
|
|
281
|
+
target was read as an operand, and a member target was evaluated again after the right side.
|
|
282
|
+
Three kinds of read remain beyond JavaScript's. Case-sensitive, a getter `g` on the context,
|
|
283
|
+
reached through `this`: `this.g = 1` calls it once and `this.g += 1` twice. Under
|
|
284
|
+
`caseInsensitive`, a lookup that answers an identifier target: `x = 1` calls it once and
|
|
285
|
+
`x += 1` twice. And under `caseInsensitive`, a getter an instance inherits: `c.g += 1` calls it
|
|
286
|
+
twice, as `c.g` does. Destructuring assignment, `[a, b] = arr` or `({ m } = o)`, throws
|
|
287
|
+
`Unsupported assignment target`;
|
|
279
288
|
before `@zvenigora/ng-eval-core` 0.7.0 it silently did nothing. An identifier write that
|
|
280
289
|
would shadow `undefined`, or under `caseInsensitive` a literal, throws
|
|
281
290
|
`Assignment to read-only name`, since 0.13.2
|
|
282
|
-
- `UpdateExpression` — to an identifier or a member, parenthesised or not
|
|
291
|
+
- `UpdateExpression` — to an identifier or a member, parenthesised or not. Under
|
|
292
|
+
`caseInsensitive` a member update writes the key its read matched, since 0.14.0: `OBJ.X++`
|
|
293
|
+
on `{ obj: { x: 1 } }` writes `x`
|
|
283
294
|
- `ArrowFunctionExpression` *potentially unsafe* (AssignmentPattern is not implemented, so a
|
|
284
295
|
destructuring default — `({ a = 1 }) => a` — is rejected rather than defaulted)
|
|
285
296
|
- `SequenceExpression` — each expression in order, the value the last one's
|
|
@@ -351,7 +362,7 @@ To change the evaluator's default behaviour, pass `options`: the last argument o
|
|
|
351
362
|
|
|
352
363
|
### Case-insensitive evaluation
|
|
353
364
|
|
|
354
|
-
While JavaScript is a case-sensitive language, some may find it hard to use. To provide case-insensitive evaluation, set `caseInsensitive` to `true`. It applies to identifiers and to member names alike.
|
|
365
|
+
While JavaScript is a case-sensitive language, some may find it hard to use. To provide case-insensitive evaluation, set `caseInsensitive` to `true`. It applies to identifiers and to member names alike. Since 0.14.0 a member write reaches the key the read would match: `OBJ.X = 2` on `{ obj: { x: 1 } }` writes `x`, where up to 0.13.3 it created a key `X` beside it. A key that matches nothing is written as spelled.
|
|
355
366
|
|
|
356
367
|
```javascript
|
|
357
368
|
import { EvalService } from '@zvenigora/ng-eval-core';
|
|
@@ -521,6 +532,8 @@ state.hooks.onRead((event) => {
|
|
|
521
532
|
});
|
|
522
533
|
```
|
|
523
534
|
|
|
535
|
+
Since 0.14.0 an assignment or an update reports the reads JavaScript makes: `a.b = 1` reports `a` and not `a.b`, `x = 1` reports nothing, a compound or logical assignment one read of its target — `a.b += 1` reports `a`, then `a.b` — and `x++` one read of `x`.
|
|
536
|
+
|
|
524
537
|
If you want a dependency set rather than raw events, `createDependencyTracker()` builds one and applies the `scoped` filtering for you.
|
|
525
538
|
|
|
526
539
|
#### Statements and the empty-completion sentinel
|
|
@@ -914,8 +914,11 @@ const refuseContextWrite = (target) => {
|
|
|
914
914
|
*
|
|
915
915
|
* The companion to {@link refuseContextWrite}, and the load-bearing one: the
|
|
916
916
|
* context cannot be written to, and it cannot be obtained either. It is
|
|
917
|
-
* raised from the value funnel in `visitor-result.ts`,
|
|
918
|
-
*
|
|
917
|
+
* raised from the value funnel, `refuseFunnelledValue` in `visitor-result.ts`,
|
|
918
|
+
* which has two call sites: `pushVisitorResult`, so it covers every value the
|
|
919
|
+
* walk pushes, whatever node pushed it, and `assignment-expression.ts`, for a
|
|
920
|
+
* compound or logical assignment's target, which is read once and not pushed
|
|
921
|
+
* (`docs/backlog.md` A45, part 2).
|
|
919
922
|
*
|
|
920
923
|
* **It is at the funnel because a member read was not enough.** The first
|
|
921
924
|
* version refused a context only as a member read's object and value, and
|
|
@@ -1398,7 +1401,10 @@ const evaluateMember = (node, st, callback) => {
|
|
|
1398
1401
|
// holds with the original, which is an ordinary host object - so the fact
|
|
1399
1402
|
// is carried from here, where it is known, rather than re-derived at the
|
|
1400
1403
|
// call, where it is not (`docs/a35/plan.md` § 8 q7).
|
|
1401
|
-
|
|
1404
|
+
//
|
|
1405
|
+
// The fifth slot is the key the lookup matched, which a write reaches
|
|
1406
|
+
// (`docs/backlog.md` A44). Here it is the key the context resolved.
|
|
1407
|
+
return [thisValue ?? object, contextKey, value, true, contextKey];
|
|
1402
1408
|
}
|
|
1403
1409
|
else if (object instanceof EvalScope) {
|
|
1404
1410
|
// A global scope reads its object as the context does, with a bare
|
|
@@ -1423,7 +1429,7 @@ const evaluateMember = (node, st, callback) => {
|
|
|
1423
1429
|
// A namespaced or global prior scope is not the context's own chain: its
|
|
1424
1430
|
// object, or the `thisArg` its host declared, is the receiver it has
|
|
1425
1431
|
// always been.
|
|
1426
|
-
return [thisValue ?? object, key, value, false];
|
|
1432
|
+
return [thisValue ?? object, key, value, false, key];
|
|
1427
1433
|
}
|
|
1428
1434
|
else {
|
|
1429
1435
|
// Not the walk's own context, and not a scope. A context cannot reach
|
|
@@ -1432,8 +1438,10 @@ const evaluateMember = (node, st, callback) => {
|
|
|
1432
1438
|
//
|
|
1433
1439
|
// For regular objects, we need both case-insensitive lookup AND prototype pollution protection
|
|
1434
1440
|
let value;
|
|
1435
|
-
// The key the lookup actually matched, reported to the read hooks
|
|
1436
|
-
// returned
|
|
1441
|
+
// The key the lookup actually matched, reported to the read hooks and
|
|
1442
|
+
// returned in the fifth slot, which a compound assignment and an update
|
|
1443
|
+
// write to (`docs/backlog.md` A44). The second slot keeps the original
|
|
1444
|
+
// `key`, which the call path names a function by.
|
|
1437
1445
|
let resolvedKey = key;
|
|
1438
1446
|
// A primitive receiver (string, number, boolean) is checked against the
|
|
1439
1447
|
// primitive subset of the blocklist: `toString` and its kin are ordinary
|
|
@@ -1527,8 +1535,100 @@ const evaluateMember = (node, st, callback) => {
|
|
|
1527
1535
|
value
|
|
1528
1536
|
});
|
|
1529
1537
|
}
|
|
1530
|
-
return [object, key, value, false];
|
|
1538
|
+
return [object, key, value, false, resolvedKey];
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
/**
|
|
1542
|
+
* An `=` target's object and key, with no value read: JavaScript's `=` does
|
|
1543
|
+
* not read its target (`docs/backlog.md` A45, part 2). The object, and a
|
|
1544
|
+
* computed key, are evaluated as {@link evaluateMember} evaluates them, once
|
|
1545
|
+
* and before the right side, and nothing reports a read of the target.
|
|
1546
|
+
*
|
|
1547
|
+
* The key checks the read used to make stay, and run here, before the right
|
|
1548
|
+
* side (`docs/a45/plan.md` D7): `safeSetProperty` refuses the same keys with
|
|
1549
|
+
* the same message, but only after the right side has run. A string, number or
|
|
1550
|
+
* boolean object gets the primitive subset's check, and any other object,
|
|
1551
|
+
* `null` and `undefined` included, the full blocklist.
|
|
1552
|
+
*
|
|
1553
|
+
* Under `caseInsensitive` a string key on an object is matched as the read
|
|
1554
|
+
* matches it, the own-key cache and then the prototype's own names, but tested
|
|
1555
|
+
* with `in` where the read tests `obj[key]`, so no getter is called
|
|
1556
|
+
* (`docs/backlog.md` A44). The match is checked against the blocklist, as the
|
|
1557
|
+
* read's `foundKey` is. Any other object takes the key as spelled, as on the
|
|
1558
|
+
* read path.
|
|
1559
|
+
*
|
|
1560
|
+
* The context branch still calls `getThis`, which reads the value it tests
|
|
1561
|
+
* (`docs/backlog.md` A49), and under `caseInsensitive` answers the `Registry`
|
|
1562
|
+
* copy (A50). An `EvalScope` is written as an object (A51).
|
|
1563
|
+
*/
|
|
1564
|
+
const resolveMemberTarget = (node, st, callback) => {
|
|
1565
|
+
markThisPositional(node.object, !!st.options?.caseInsensitive);
|
|
1566
|
+
callback(node.object, st);
|
|
1567
|
+
const obj = popVisitorResult(node, st);
|
|
1568
|
+
const object = (node.optional ? (obj || {}) : obj);
|
|
1569
|
+
let key;
|
|
1570
|
+
if (!node.computed && node.property.type === 'Identifier') {
|
|
1571
|
+
key = node.property.name;
|
|
1572
|
+
}
|
|
1573
|
+
else if (node.property.type === 'Literal') {
|
|
1574
|
+
key = node.property.value;
|
|
1575
|
+
}
|
|
1576
|
+
else {
|
|
1577
|
+
callback(node.property, st);
|
|
1578
|
+
key = popVisitorResult(node, st);
|
|
1579
|
+
}
|
|
1580
|
+
if (object === st.context) {
|
|
1581
|
+
// As the read path's context branch, without its `get`.
|
|
1582
|
+
if (isDangerousProperty(key)) {
|
|
1583
|
+
throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
|
|
1584
|
+
}
|
|
1585
|
+
let contextKey = key;
|
|
1586
|
+
if (st.options?.caseInsensitive && typeof key === 'string') {
|
|
1587
|
+
contextKey = st.context.getKey(key);
|
|
1588
|
+
if (isDangerousProperty(contextKey)) {
|
|
1589
|
+
throw new Error(`Access to dangerous property "${String(contextKey)}" is blocked for security reasons`);
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
return [st.context.getThis(contextKey) ?? object, contextKey];
|
|
1593
|
+
}
|
|
1594
|
+
else if (object instanceof EvalScope) {
|
|
1595
|
+
if (isDangerousProperty(key)) {
|
|
1596
|
+
throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
|
|
1597
|
+
}
|
|
1598
|
+
return [object, key];
|
|
1599
|
+
}
|
|
1600
|
+
const isPrimitive = (typeof object === 'string' || typeof object === 'number' || typeof object === 'boolean');
|
|
1601
|
+
if (isPrimitive ? isDangerousPrimitiveProperty(key) : isDangerousProperty(key)) {
|
|
1602
|
+
throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
|
|
1603
|
+
}
|
|
1604
|
+
if (st.options?.caseInsensitive && typeof key === 'string' && object && typeof object === 'object') {
|
|
1605
|
+
const target = object;
|
|
1606
|
+
let foundKey = getCachedCaseInsensitiveProperty(target, key, (a, b) => equalIgnoreCase(a, b) === true);
|
|
1607
|
+
if (!foundKey) {
|
|
1608
|
+
// As the read path's `obj[key]` test, a lookup that throws leaves the
|
|
1609
|
+
// key as spelled. A proxy's `has` trap is called here, which
|
|
1610
|
+
// JavaScript's `=` does not call.
|
|
1611
|
+
try {
|
|
1612
|
+
if (key in target) {
|
|
1613
|
+
foundKey = key;
|
|
1614
|
+
}
|
|
1615
|
+
else {
|
|
1616
|
+
const prototype = Object.getPrototypeOf(target);
|
|
1617
|
+
if (prototype) {
|
|
1618
|
+
foundKey = Object.getOwnPropertyNames(prototype).find(k => equalIgnoreCase(k, key));
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
catch {
|
|
1623
|
+
foundKey = undefined;
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
if (foundKey && isDangerousProperty(foundKey)) {
|
|
1627
|
+
throw new Error(`Access to dangerous property "${foundKey}" is blocked for security reasons`);
|
|
1628
|
+
}
|
|
1629
|
+
return [object, foundKey || key];
|
|
1531
1630
|
}
|
|
1631
|
+
return [object, key];
|
|
1532
1632
|
};
|
|
1533
1633
|
|
|
1534
1634
|
const arrayExpressionVisitor = (node, st, callback) => {
|
|
@@ -2323,8 +2423,9 @@ const safeCall = (caller, thisArg, args, optional = false, fnName) => {
|
|
|
2323
2423
|
* `ns.fn()` reaches `fn` through the namespace, which evaluates to the scope's
|
|
2324
2424
|
* object and has to keep doing so - `ns` alone, or `ns === x`, must not see
|
|
2325
2425
|
* `thisArg`. So the substitution is made here, at the call, and nowhere
|
|
2326
|
-
* earlier: `evaluateMember`'s first slot is also the target of `ns.x
|
|
2327
|
-
*
|
|
2426
|
+
* earlier: `evaluateMember`'s first slot is also the target of `ns.x += v` and
|
|
2427
|
+
* `ns.x++`, as `resolveMemberTarget`'s is of `ns.x = v`, and a write belongs on
|
|
2428
|
+
* the scope's object. Matched by identity, so it follows the
|
|
2328
2429
|
* object rather than the name it was reached by; the first scope holding the
|
|
2329
2430
|
* object answers, as in `EvalContext.get`. Up to 0.6.x `thisArg` was never
|
|
2330
2431
|
* applied (`docs/backlog-retired.md` A7).
|
|
@@ -2643,11 +2744,14 @@ const readName = (node, fn) => {
|
|
|
2643
2744
|
* The funnel (`docs/a35/plan.md` § 3.3): refuses a dangerous function pushed
|
|
2644
2745
|
* by any node but an exempt one, so no visitor - including one not yet
|
|
2645
2746
|
* written - can hand it on as an argument, a receiver, an element, a branch
|
|
2646
|
-
* or the expression's result. `
|
|
2647
|
-
* value only
|
|
2648
|
-
*
|
|
2649
|
-
*
|
|
2650
|
-
*
|
|
2747
|
+
* or the expression's result. `refuseFunnelledValue` (`visitor-result.ts`)
|
|
2748
|
+
* calls it for a function value only, from its two call sites:
|
|
2749
|
+
* `pushVisitorResult`, for every pushed value, and `assignment-expression.ts`,
|
|
2750
|
+
* for a compound or logical assignment's target, which is read once and not
|
|
2751
|
+
* pushed (`docs/backlog.md` A45, part 2).
|
|
2752
|
+
*
|
|
2753
|
+
* It sees only what is pushed on the walk's own stack, and those targets. A
|
|
2754
|
+
* value that reaches native code without either is not seen: the elements of an array the
|
|
2651
2755
|
* host built, spread into a call, which stays a documented limit. The other
|
|
2652
2756
|
* such route, through `this` and the receiver of a call
|
|
2653
2757
|
* (`docs/backlog-retired.md` A39), is closed in 0.13.0 elsewhere - by
|
|
@@ -2682,20 +2786,40 @@ const refuseDangerousRead = (node, value) => {
|
|
|
2682
2786
|
* run-to-run noise, so this is not a speed claim; it is that the helper cost a
|
|
2683
2787
|
* frame on the hot path and bought nothing, and that `addTraceBounded`'s own
|
|
2684
2788
|
* docblock claims one call per push, which only this shape makes true.
|
|
2789
|
+
* {@link refuseFunnelledValue} is the one frame the push path does take, since
|
|
2790
|
+
* an assignment target read without a push needs the same two tests, and a
|
|
2791
|
+
* second copy of them could drift from the first (`docs/a45/plan.md` § 3.2;
|
|
2792
|
+
* its cost is measured by that plan's step 4).
|
|
2685
2793
|
*
|
|
2686
2794
|
* **The value stack is not bounded and must not be.** It is how visitors return
|
|
2687
2795
|
* values to each other, and dropping an entry desynchronises every node above
|
|
2688
2796
|
* it. Only the trace - which nothing in this library reads - is capped.
|
|
2689
2797
|
*
|
|
2690
|
-
* **Every
|
|
2691
|
-
* (`docs/a35/plan.md` § 3.3): a dangerous function is refused wherever it was
|
|
2692
|
-
* read, unless the node pushing it is a callee, a tag or `typeof`'s operand.
|
|
2693
|
-
* The call is behind `typeof value === 'function'`, so a value that is not a
|
|
2694
|
-
* function pays one comparison and no frame on this per-node path. `await`
|
|
2695
|
-
* pushes its promise here too, which is not a function.
|
|
2798
|
+
* **Every value pushed here passes the funnel**, {@link refuseFunnelledValue}.
|
|
2696
2799
|
* `pushVisitorResultAsync` has no caller, and no check.
|
|
2697
2800
|
*/
|
|
2698
2801
|
const pushVisitorResult = (node, st, value) => {
|
|
2802
|
+
refuseFunnelledValue(node, st, value);
|
|
2803
|
+
const result = st.result;
|
|
2804
|
+
result.stack.push(value);
|
|
2805
|
+
result.addTraceBounded(node, value, st.maxTraceItems);
|
|
2806
|
+
return value;
|
|
2807
|
+
};
|
|
2808
|
+
/**
|
|
2809
|
+
* The funnel's two tests, made on every pushed value and on a value a visitor
|
|
2810
|
+
* reads without pushing it: a compound or logical assignment's target, which
|
|
2811
|
+
* `assignment-expression.ts` reads once and does not walk
|
|
2812
|
+
* (`docs/backlog.md` A45, part 2). One definition serves both, so what the
|
|
2813
|
+
* funnel refuses cannot differ between them.
|
|
2814
|
+
*
|
|
2815
|
+
* **A function value passes `refuseDangerousRead`** (`docs/a35/plan.md`
|
|
2816
|
+
* § 3.3): a dangerous function is refused wherever it was read, unless the
|
|
2817
|
+
* node is a callee, a tag or `typeof`'s operand. The call is behind
|
|
2818
|
+
* `typeof value === 'function'`, so a value that is not a function pays one
|
|
2819
|
+
* comparison on this per-node path. `await` pushes its promise here too,
|
|
2820
|
+
* which is not a function.
|
|
2821
|
+
*/
|
|
2822
|
+
const refuseFunnelledValue = (node, st, value) => {
|
|
2699
2823
|
if (typeof value === 'function') {
|
|
2700
2824
|
refuseDangerousRead(node, value);
|
|
2701
2825
|
}
|
|
@@ -2728,10 +2852,6 @@ const pushVisitorResult = (node, st, value) => {
|
|
|
2728
2852
|
// `eval.service.context-write.spec.ts`.
|
|
2729
2853
|
refuseContextRead();
|
|
2730
2854
|
}
|
|
2731
|
-
const result = st.result;
|
|
2732
|
-
result.stack.push(value);
|
|
2733
|
-
result.addTraceBounded(node, value, st.maxTraceItems);
|
|
2734
|
-
return value;
|
|
2735
2855
|
};
|
|
2736
2856
|
const popVisitorResult = (node, st) => {
|
|
2737
2857
|
const result = st.result;
|
|
@@ -2871,6 +2991,60 @@ const refuseDangerousMatch = (node, st) => {
|
|
|
2871
2991
|
throw new Error(`Access to dangerous property "${String(matched)}" is blocked for security reasons`);
|
|
2872
2992
|
}
|
|
2873
2993
|
};
|
|
2994
|
+
/**
|
|
2995
|
+
* The `caseInsensitive` read of a name: the context, then the literals
|
|
2996
|
+
* registry for a name `get` finds nothing for. Only `undefined` falls through,
|
|
2997
|
+
* so a key holding `null` reads as `null`. Up to 0.13.3 the fallback was
|
|
2998
|
+
* `??`, which turned that `null` into `undefined` (`docs/backlog.md` A52).
|
|
2999
|
+
*/
|
|
3000
|
+
const readCaseInsensitive = (node, st) => {
|
|
3001
|
+
const found = st.context?.get(node.name);
|
|
3002
|
+
return found === undefined ? literals.get(node.name) : found;
|
|
3003
|
+
};
|
|
3004
|
+
/**
|
|
3005
|
+
* An identifier target's checks, which the visitor makes before any lookup: a
|
|
3006
|
+
* name on the blocklist, `this` written as a name - a host-built one, or under
|
|
3007
|
+
* `caseInsensitive` any spelling of it - and under `caseInsensitive` a name
|
|
3008
|
+
* whose lookup matched a blocklisted key. A target is never a member's object,
|
|
3009
|
+
* so `refuseThisValue` refuses every `this` that reaches it - unless a
|
|
3010
|
+
* host-built AST reused one `this` node as a member's object, visited first,
|
|
3011
|
+
* the mark-reuse limit `this-position.ts` describes. No target path evaluates
|
|
3012
|
+
* `this` to the context, so that node is written as a key named `this`.
|
|
3013
|
+
*
|
|
3014
|
+
* Every identifier target is checked here and by nothing else: `=`'s, which
|
|
3015
|
+
* reads nothing, and through {@link readIdentifierTarget} a compound or logical
|
|
3016
|
+
* operator's and an update's (`docs/a45/plan.md` D8, D11). Without it,
|
|
3017
|
+
* `constructor = 1` would write an own `constructor` onto the context, as
|
|
3018
|
+
* `constructor++` did up to 0.13.3.
|
|
3019
|
+
*/
|
|
3020
|
+
const refuseIdentifierTarget = (node, st) => {
|
|
3021
|
+
refuseDangerousName(node);
|
|
3022
|
+
const caseInsensitive = !!st.options?.caseInsensitive;
|
|
3023
|
+
if (caseInsensitive ? !!equalIgnoreCase(node.name, 'this') : node.name === 'this') {
|
|
3024
|
+
refuseThisValue(node);
|
|
3025
|
+
}
|
|
3026
|
+
if (caseInsensitive) {
|
|
3027
|
+
refuseDangerousMatch(node, st);
|
|
3028
|
+
}
|
|
3029
|
+
};
|
|
3030
|
+
/**
|
|
3031
|
+
* An assignment or update target's read, for a compound or logical operator
|
|
3032
|
+
* and for `++` and `--`: the visitor's own checks and read, with no push and
|
|
3033
|
+
* no node hooks, since the target is read and not walked (`docs/backlog.md`
|
|
3034
|
+
* A45, part 2). The checks are {@link refuseIdentifierTarget}'s, so a refused
|
|
3035
|
+
* target reads nothing. Then it reads the name as the visitor does, and
|
|
3036
|
+
* reports the read: up to 0.13.3 an identifier update reported none.
|
|
3037
|
+
*/
|
|
3038
|
+
const readIdentifierTarget = (node, st) => {
|
|
3039
|
+
refuseIdentifierTarget(node, st);
|
|
3040
|
+
const value = st.options?.caseInsensitive
|
|
3041
|
+
? readCaseInsensitive(node, st)
|
|
3042
|
+
: st.context?.get(node.name);
|
|
3043
|
+
if (st.hasHooks && st.hooks.hasReadHooks) {
|
|
3044
|
+
emitRead(node, st, value);
|
|
3045
|
+
}
|
|
3046
|
+
return value;
|
|
3047
|
+
};
|
|
2874
3048
|
const identifierVisitor = (node, st) => {
|
|
2875
3049
|
if (st.options?.caseInsensitive) {
|
|
2876
3050
|
return identifierVisitorCaseInsensitive(node, st);
|
|
@@ -2900,7 +3074,6 @@ const identifierVisitor = (node, st) => {
|
|
|
2900
3074
|
const identifierVisitorCaseInsensitive = (node, st) => {
|
|
2901
3075
|
beforeVisitor(node, st);
|
|
2902
3076
|
refuseDangerousName(node);
|
|
2903
|
-
const context = st.context;
|
|
2904
3077
|
const isThis = !!equalIgnoreCase(node.name, 'this');
|
|
2905
3078
|
// `This` is refused outside a member's object, as `this` is
|
|
2906
3079
|
// (`this-position.ts`).
|
|
@@ -2912,7 +3085,7 @@ const identifierVisitorCaseInsensitive = (node, st) => {
|
|
|
2912
3085
|
}
|
|
2913
3086
|
const value = isThis
|
|
2914
3087
|
? st.context
|
|
2915
|
-
:
|
|
3088
|
+
: readCaseInsensitive(node, st);
|
|
2916
3089
|
if (st.hasHooks && st.hooks.hasReadHooks && !isThis) {
|
|
2917
3090
|
emitRead(node, st, value);
|
|
2918
3091
|
}
|
|
@@ -4041,8 +4214,51 @@ const assignmentExpressionVisitor = (node, st, callback) => {
|
|
|
4041
4214
|
if (target.type !== 'Identifier' && target.type !== 'MemberExpression') {
|
|
4042
4215
|
throw new Error(`Unsupported assignment target: ${target.type}`);
|
|
4043
4216
|
}
|
|
4044
|
-
|
|
4045
|
-
|
|
4217
|
+
// The target is not walked, and is evaluated once, before the right side
|
|
4218
|
+
// (`docs/backlog.md` A45, part 2). `=` reads nothing of it, as JavaScript's
|
|
4219
|
+
// `=` does not: an identifier gets the identifier visitor's checks, and a
|
|
4220
|
+
// member is resolved to its object and key. A compound or logical target is
|
|
4221
|
+
// read once, as an update reads its operand: a member through one
|
|
4222
|
+
// `evaluateMember` call, whose object and matched key the write reuses
|
|
4223
|
+
// (A44), and an identifier through the identifier visitor's own read. The
|
|
4224
|
+
// value read is not pushed, so it is given the funnel's tests here, or a
|
|
4225
|
+
// listed function read as a target would be combined and written where
|
|
4226
|
+
// `fetch || 1` refuses it.
|
|
4227
|
+
const plain = node.operator === '=';
|
|
4228
|
+
let left;
|
|
4229
|
+
let targetObject;
|
|
4230
|
+
let targetKey;
|
|
4231
|
+
if (target.type === 'Identifier') {
|
|
4232
|
+
if (plain) {
|
|
4233
|
+
refuseIdentifierTarget(target, st);
|
|
4234
|
+
}
|
|
4235
|
+
else {
|
|
4236
|
+
left = readIdentifierTarget(target, st);
|
|
4237
|
+
}
|
|
4238
|
+
}
|
|
4239
|
+
else if (plain) {
|
|
4240
|
+
[targetObject, targetKey] = resolveMemberTarget(target, st, callback);
|
|
4241
|
+
}
|
|
4242
|
+
else {
|
|
4243
|
+
const [object, , value, , key] = evaluateMember(target, st, callback);
|
|
4244
|
+
targetObject = object;
|
|
4245
|
+
targetKey = key;
|
|
4246
|
+
left = value;
|
|
4247
|
+
}
|
|
4248
|
+
if (!plain) {
|
|
4249
|
+
refuseFunnelledValue(target, st, left);
|
|
4250
|
+
}
|
|
4251
|
+
// A logical assignment that short-circuits gives `left` and does nothing
|
|
4252
|
+
// more: its right side is not evaluated and nothing is written, so no write
|
|
4253
|
+
// policy is asked (`docs/backlog.md` A45, part 1). The rule is
|
|
4254
|
+
// `logical-expression.ts`'s, for `||`, `&&` and `??`.
|
|
4255
|
+
if ((node.operator === '||=' && left) ||
|
|
4256
|
+
(node.operator === '&&=' && !left) ||
|
|
4257
|
+
(node.operator === '??=' && left !== null && left !== undefined)) {
|
|
4258
|
+
pushVisitorResult(node, st, left);
|
|
4259
|
+
afterVisitor(node, st);
|
|
4260
|
+
return;
|
|
4261
|
+
}
|
|
4046
4262
|
callback(node.right, st);
|
|
4047
4263
|
const right = popVisitorResult(node, st);
|
|
4048
4264
|
const func = assignmentOperators[node.operator];
|
|
@@ -4070,7 +4286,8 @@ const assignmentExpressionVisitor = (node, st, callback) => {
|
|
|
4070
4286
|
pushVisitorResult(node, st, value);
|
|
4071
4287
|
}
|
|
4072
4288
|
else if (target.type === 'MemberExpression') {
|
|
4073
|
-
const
|
|
4289
|
+
const object = targetObject;
|
|
4290
|
+
const key = targetKey;
|
|
4074
4291
|
const value = func(left, right);
|
|
4075
4292
|
// A member write never reaches `EvalContext.set`, so a context policing
|
|
4076
4293
|
// writes is asked here instead - `EvalContext.checkMemberWrite`.
|
|
@@ -4093,12 +4310,18 @@ const updateExpressionVisitor = (node, st, callback) => {
|
|
|
4093
4310
|
throw new Error(`Context is not set.`);
|
|
4094
4311
|
}
|
|
4095
4312
|
else if (target.type === 'Identifier') {
|
|
4313
|
+
// The target read a compound assignment makes: the identifier visitor's
|
|
4314
|
+
// checks, before any lookup, then one read and its read event
|
|
4315
|
+
// (`docs/a45/plan.md` D8, D9, D11). Up to 0.13.3 an update checked
|
|
4316
|
+
// nothing and reported nothing, so `constructor++` wrote an own
|
|
4317
|
+
// `constructor` onto the context. It takes no funnel check, as the member
|
|
4318
|
+
// branch takes none: `fetch++` gives `NaN` (`docs/backlog-retired.md` A40).
|
|
4319
|
+
const value = readIdentifierTarget(target, st);
|
|
4096
4320
|
// The fallback `assignment-expression.ts` takes, for the same reason
|
|
4097
4321
|
// (`docs/backlog-retired.md` A43).
|
|
4098
4322
|
const key = st.options?.caseInsensitive
|
|
4099
4323
|
? st.context.getKey(target.name) ?? target.name
|
|
4100
4324
|
: target.name;
|
|
4101
|
-
const value = st.context?.get(key);
|
|
4102
4325
|
// The update run natively on a copy of the operand. JavaScript converts
|
|
4103
4326
|
// the operand to a numeric once, then adds or subtracts, and a postfix
|
|
4104
4327
|
// update gives that converted old value. `value + 1` on the operand as
|
|
@@ -4118,7 +4341,8 @@ const updateExpressionVisitor = (node, st, callback) => {
|
|
|
4118
4341
|
pushVisitorResult(node, st, node.prefix ? updated : old);
|
|
4119
4342
|
}
|
|
4120
4343
|
else if (target.type === 'MemberExpression') {
|
|
4121
|
-
|
|
4344
|
+
// The write reaches the key the lookup matched (`docs/backlog.md` A44).
|
|
4345
|
+
const [object, , value, , property] = evaluateMember(target, st, callback);
|
|
4122
4346
|
// As in the identifier branch: one native conversion, before the write.
|
|
4123
4347
|
let updated = value;
|
|
4124
4348
|
const old = node.operator === '++' ? updated++ : updated--;
|
|
@@ -7324,10 +7548,10 @@ class ParserService {
|
|
|
7324
7548
|
}
|
|
7325
7549
|
return undefined;
|
|
7326
7550
|
}
|
|
7327
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.
|
|
7328
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.
|
|
7551
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: ParserService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
7552
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: ParserService, providedIn: 'root' }); }
|
|
7329
7553
|
}
|
|
7330
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.
|
|
7554
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: ParserService, decorators: [{
|
|
7331
7555
|
type: Injectable,
|
|
7332
7556
|
args: [{
|
|
7333
7557
|
providedIn: 'root'
|
|
@@ -7446,10 +7670,10 @@ class EvalService extends BaseEval {
|
|
|
7446
7670
|
const promise = evaluateAsync(ast, state);
|
|
7447
7671
|
return promise;
|
|
7448
7672
|
}
|
|
7449
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.
|
|
7450
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.
|
|
7673
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: EvalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
7674
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: EvalService, providedIn: 'root' }); }
|
|
7451
7675
|
}
|
|
7452
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.
|
|
7676
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: EvalService, decorators: [{
|
|
7453
7677
|
type: Injectable,
|
|
7454
7678
|
args: [{
|
|
7455
7679
|
providedIn: 'root'
|
|
@@ -7728,10 +7952,10 @@ class CompilerService extends BaseEval {
|
|
|
7728
7952
|
}
|
|
7729
7953
|
return undefined;
|
|
7730
7954
|
}
|
|
7731
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.
|
|
7732
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.
|
|
7955
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: CompilerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
7956
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: CompilerService, providedIn: 'root' }); }
|
|
7733
7957
|
}
|
|
7734
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.
|
|
7958
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: CompilerService, decorators: [{
|
|
7735
7959
|
type: Injectable,
|
|
7736
7960
|
args: [{
|
|
7737
7961
|
providedIn: 'root'
|
|
@@ -7768,10 +7992,10 @@ class DiscoveryService extends BaseEval {
|
|
|
7768
7992
|
const value = extract(ast, searchType);
|
|
7769
7993
|
return value;
|
|
7770
7994
|
}
|
|
7771
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.
|
|
7772
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.
|
|
7995
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: DiscoveryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
7996
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: DiscoveryService, providedIn: 'root' }); }
|
|
7773
7997
|
}
|
|
7774
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.
|
|
7998
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: DiscoveryService, decorators: [{
|
|
7775
7999
|
type: Injectable,
|
|
7776
8000
|
args: [{
|
|
7777
8001
|
providedIn: 'root'
|