@zvenigora/ng-eval-core 0.15.1 → 0.16.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 +102 -3
- package/README.md +7 -7
- package/fesm2022/zvenigora-ng-eval-core.mjs +117 -45
- package/fesm2022/zvenigora-ng-eval-core.mjs.map +1 -1
- package/package.json +1 -1
- package/types/zvenigora-ng-eval-core.d.ts +18 -3
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,105 @@ Versions 0.1.104–0.1.107 are on npm without entries here.
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
+
## [0.16.0] - 2026-11-08
|
|
18
|
+
|
|
19
|
+
**A member read lets a getter's throw reach the caller, and member reads and writes change under
|
|
20
|
+
`caseInsensitive`, through `this` to a `Registry`, and to an `EvalScope`.** A minor carrying
|
|
21
|
+
breaking changes ([A55](../../docs/backlog-retired.md#a55),
|
|
22
|
+
[A48](../../docs/backlog-retired.md#a48), [A51](../../docs/backlog-retired.md#a51); the
|
|
23
|
+
[A48 plan](../../docs/a48/plan.md)), with [A50](../../docs/backlog-retired.md#a50)'s fix and
|
|
24
|
+
[A49](../../docs/backlog-retired.md#a49) decided a documented limit. No exported symbol changes
|
|
25
|
+
shape: the `.d.ts` differs from 0.15.1's in two JSDoc blocks only, `EvalContext`'s `lookups` and
|
|
26
|
+
`getThis`, A49's. What changes is behaviour: what a member read does with a getter or a proxy trap
|
|
27
|
+
that throws, how a `caseInsensitive` member read tests and searches a key, what a write through
|
|
28
|
+
`this` does to a `Registry` that is the context's original, and that a member write to an
|
|
29
|
+
`EvalScope` is refused; each bullet below names the paths it covers. Timed against 0.15.1 on seven
|
|
30
|
+
paths, with no regression on any. `eval-signals` 0.9.0 and `eval-forms` 0.9.0 raise their floors to
|
|
31
|
+
it.
|
|
32
|
+
|
|
33
|
+
### Breaking
|
|
34
|
+
- **A member read lets a getter's or a proxy `get` trap's throw reach the caller, in both case
|
|
35
|
+
modes.** It caught a throw from the read and gave `undefined`. Case-sensitively, over an object
|
|
36
|
+
whose getter `t` throws, own or inherited, `x.t` was `undefined`, `x.t || 1` was `1` and
|
|
37
|
+
`let {t} = x` bound `undefined`, and `x.t += 1` and `x.t++` threw at the write where `t` has no
|
|
38
|
+
setter and wrote `NaN` through the setter where it has one. Under `caseInsensitive` some of these
|
|
39
|
+
reads already threw, `x.t` over an own getter among them, and some did not, `x.t` over an inherited
|
|
40
|
+
one and `let {t} = x` over either. Each of these forms now throws the getter's own value, an `Error`
|
|
41
|
+
or not, as JavaScript does ([A55](../../docs/backlog-retired.md#a55)). A null or undefined object
|
|
42
|
+
still reads `undefined`.
|
|
43
|
+
- **Under `caseInsensitive`, a member read calls a proxy's `has` trap** for a key no own property
|
|
44
|
+
matches, as a member write already did; JavaScript's read calls none. A throw from that `has`
|
|
45
|
+
trap, or from the `ownKeys` trap of a prototype searched for a case variant, is caught, and the
|
|
46
|
+
key is then read as written ([A48](../../docs/backlog-retired.md#a48)).
|
|
47
|
+
- **Under `caseInsensitive`, a key a proxy answers by its `get` trap alone is searched for a case
|
|
48
|
+
variant.** For a proxy with no `has` trap, `in` does not find a key its target does not hold, so
|
|
49
|
+
the read searches the target's prototype for a case variant, as `=` already did: over a target
|
|
50
|
+
whose prototype has a method `getX`, `px.getx` reads `getX`, and `px.getx += 1` reads and writes
|
|
51
|
+
it; a variant that is a blocked name is refused, so over `{}` `px.tostring` throws
|
|
52
|
+
`Access to dangerous property "toString" is blocked for security reasons`. Up to 0.15.1 the read
|
|
53
|
+
tested the key by reading it, and read it as spelled. A key with no such variant, `px.q`, is read
|
|
54
|
+
as spelled, as before, and a case-sensitive read is unchanged
|
|
55
|
+
([A48](../../docs/backlog-retired.md#a48), [A59](../../docs/backlog.md#a59)).
|
|
56
|
+
- **A member write to an `EvalScope` is refused.** It throws
|
|
57
|
+
`Write to an evaluation scope is blocked`, where up to 0.15.1 it set an own property on the
|
|
58
|
+
instance. A host that places an `EvalScope` in the context as a value reads it through the scope's
|
|
59
|
+
`get`, so `ns.k = 5`, `ns.k += 5` and `ns.k++` left the scope's context unchanged and a later `ns.k`
|
|
60
|
+
read the old value, and `ns._context = 9`, `ns._options = 9` or `ns.type = 9` replaced the scope's
|
|
61
|
+
own fields. The write is refused, in both case modes, for every form a member write takes and every
|
|
62
|
+
key the blocklist does not already refuse, for a subclass too, and for an `EvalScope` that is a
|
|
63
|
+
prior scope's `thisArg`, reached through `this`. It is refused after the right side has run and
|
|
64
|
+
after a write policy, `EvalContext.checkMemberWrite`, has been asked, so a policy that refuses first
|
|
65
|
+
still gives its own error. A namespaced scope's object, `ns.n`, is not a scope, and `ns.n.k = 7`
|
|
66
|
+
still writes into it; a logical assignment that writes nothing, `ns.k ||= 5` with `k` set, is not
|
|
67
|
+
refused ([A51](../../docs/backlog-retired.md#a51)).
|
|
68
|
+
|
|
69
|
+
### Changed
|
|
70
|
+
- The README's `### Scopes` corrects two sentences. It said that a prior scope's `thisArg` changes
|
|
71
|
+
only the call's receiver; it now says so of a namespace, since through `this` a write can go to
|
|
72
|
+
`thisArg` ([A56](../../docs/backlog.md#a56)). And it said that `EvalContext.fromContext` copies a
|
|
73
|
+
plain object into a case-insensitive store; it now says that an object that is not an instance of
|
|
74
|
+
this realm's `Object`, one with a null prototype or one made in another realm, is not copied, and
|
|
75
|
+
is not yet read as the context in either mode ([A58](../../docs/backlog.md#a58)).
|
|
76
|
+
No behaviour changes. Documentation only: the README reaches the tarball.
|
|
77
|
+
- The README's `AssignmentExpression` entry states a limit as the contract: how many times an
|
|
78
|
+
expression calls a getter on the context or on a scope's object, or a lookup, is not part of it;
|
|
79
|
+
one can run where JavaScript reads nothing, or more than once for one read, and a registered read
|
|
80
|
+
hook can add a call. It said "two kinds of read remain beyond JavaScript's", with counts for each:
|
|
81
|
+
a getter on the context reached through `this` case-sensitively, `this.g = 1` once and
|
|
82
|
+
`this.g += 1` twice, and a lookup under `caseInsensitive`, `x = 1` once and `x += 1` twice. Of
|
|
83
|
+
those, the lookup's `x += 1` holds without a read hook only: with one, as `eval-signals`'
|
|
84
|
+
dependency tracking registers, it calls the lookup three times, and case-sensitively a plain `g`
|
|
85
|
+
calls a getter on the context twice, where JavaScript calls it once. A getter on a global
|
|
86
|
+
prior scope's object is called more than once for one read as well, `this.g` three times under
|
|
87
|
+
`caseInsensitive`. The entry keeps one example, `this.g = 1`, which holds with or without a hook.
|
|
88
|
+
`EvalContext`'s `lookups` JSDoc states the limit for a lookup and its `getThis` JSDoc for the
|
|
89
|
+
getter it reads, both in the published `.d.ts`. No behaviour changes
|
|
90
|
+
([A49](../../docs/backlog-retired.md#a49)).
|
|
91
|
+
|
|
92
|
+
### Fixed
|
|
93
|
+
- **Under `caseInsensitive`, `c.g` calls a getter on `c`'s prototype chain once.** The lookup tested
|
|
94
|
+
the key by reading it, then read it again: `c.g`, `c.g += 1`, `c.g++`, `c.g ||= 5` and
|
|
95
|
+
`` `${c.g}` `` called an inherited getter twice, and a proxy's `get` trap ran twice for a key no own
|
|
96
|
+
property matches. The key is now tested with `in`, as a member write tests it, and each of these
|
|
97
|
+
forms calls the getter once, and the trap runs once ([A48](../../docs/backlog-retired.md#a48)). The
|
|
98
|
+
read and the write now agree on the key: over an inherited `foo` whose value is `undefined`, behind
|
|
99
|
+
an accessor `Foo` on a nearer prototype, `p.foo` read `Foo`'s value and `p.foo += 1` wrote through
|
|
100
|
+
`Foo`'s setter, where `p.foo = 1` wrote `foo`; each now reads or writes `foo`.
|
|
101
|
+
- **A write through `this` to a `Registry` that is the context's original reaches its map, for a key
|
|
102
|
+
it holds.** Where the original holds `k`, `this.k = v`, `this.k += v`, `this.k ||= v` and `this.k++`
|
|
103
|
+
set an own property on the `Registry` instance and left its map, so a later `k` or `this.k` read the
|
|
104
|
+
old value: under `caseInsensitive` on the copy `EvalContext.fromContext` makes of a plain context,
|
|
105
|
+
and in both modes on a host's `Registry` passed as the context. The write now goes through the
|
|
106
|
+
`Registry`'s map, as `k = v` does, and a later read sees it
|
|
107
|
+
([A50](../../docs/backlog-retired.md#a50)). Under `caseInsensitive` it stays in the copy, as an
|
|
108
|
+
identifier write does, and does not reach the caller's object. The same holds where the original is
|
|
109
|
+
a global prior scope's `thisArg` and that scope holds the key: `this.k = v` writes the original's
|
|
110
|
+
map, and a later `k` or `this.k` reads `v`, where up to 0.15.1 the instance took an own property and
|
|
111
|
+
they read the scope's value. A `Registry` reached as a value is written as any object is, as before:
|
|
112
|
+
`r.k = v`, and the context's own `Registry` when the host holds it in its data, `self.k = v`.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
17
116
|
## [0.15.1] - 2026-11-02
|
|
18
117
|
|
|
19
118
|
**A patch that fixes [A33](../../docs/backlog-retired.md#a33)**, the case-insensitive lookup
|
|
@@ -212,8 +311,8 @@ their floors to it.
|
|
|
212
311
|
them: `getObj()[k()] += f()` runs `getObj`, `k`, the read, `f`, then the write, where up to 0.13.3
|
|
213
312
|
it evaluated the object, the key and the read a second time after `f`. A getter on the target is
|
|
214
313
|
called once where it was called twice. Two are read twice where they were read four times: a
|
|
215
|
-
prototype accessor under `caseInsensitive` ([A48](../../docs/backlog.md#a48)), and an accessor
|
|
216
|
-
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
|
|
314
|
+
prototype accessor under `caseInsensitive` ([A48](../../docs/backlog-retired.md#a48)), and an accessor
|
|
315
|
+
on the context reached through `this` ([A49](../../docs/backlog-retired.md#a49)). The read events are those of that one read, `a`, then `a.b`, where each was reported
|
|
217
316
|
twice; node hooks and the trace see the target's object and a computed key, and no longer the
|
|
218
317
|
target node, and an identifier target not at all. The value read still passes the checks every
|
|
219
318
|
read value passes, so a listed function as the target, `fetch += 1` or `obj.fetch ||= 1`, is
|
|
@@ -223,7 +322,7 @@ their floors to it.
|
|
|
223
322
|
to 0.13.3 it read the target, and after `f` evaluated the object and the key and read the target a
|
|
224
323
|
second time. A getter on the target is not called, except an accessor on the context reached
|
|
225
324
|
through `this`, which is called once where it was called four times
|
|
226
|
-
([A49](../../docs/backlog.md#a49)); under `caseInsensitive` a lookup answering an identifier
|
|
325
|
+
([A49](../../docs/backlog-retired.md#a49)); under `caseInsensitive` a lookup answering an identifier
|
|
227
326
|
target's name is called once, where it was called twice (A49). A listed function as the target is overwritten
|
|
228
327
|
as `obj.fetch++` overwrites one, so `fetch = 1` and `obj.fetch = 1` write `1` where they were
|
|
229
328
|
refused; `fetch += 1` and `fetch ||= 1` read it, and are still refused. The read events are the
|
package/README.md
CHANGED
|
@@ -175,7 +175,7 @@ expressions.length; // 2
|
|
|
175
175
|
|
|
176
176
|
An evaluation context may carry prior scopes, each with its own `namespace` and case sensitivity. Bare identifiers are read from the context itself; a namespaced scope is reached through its namespace.
|
|
177
177
|
|
|
178
|
-
`thisArg` is the `this` a scope's methods are called with. A method called on the scope's own object, such as `cat.action(...)` below, receives `thisArg`; so does `this.fn()` when a global scope supplies `fn`. Without `thisArg`, `cat.action(...)` receives the scope's object.
|
|
178
|
+
`thisArg` is the `this` a scope's methods are called with. A method called on the scope's own object, such as `cat.action(...)` below, receives `thisArg`; so does `this.fn()` when a global scope supplies `fn`. Without `thisArg`, `cat.action(...)` receives the scope's object. Through a namespace, only the call's receiver changes: `cat` still evaluates to the scope's object, so `cat.num` reads it and `cat.x = 1` writes to it. Up to 0.6.x `thisArg` was accepted and never applied.
|
|
179
179
|
|
|
180
180
|
```javascript
|
|
181
181
|
import { EvalContext, EvalScope, EvalScopeOptions,
|
|
@@ -207,7 +207,7 @@ const result = service.simpleEval('cat.action(args, cat.num, "times")', evalCont
|
|
|
207
207
|
// 'Mister Whiskers says meow 3 times' - `this` is thisArg; cat.num still reads cat
|
|
208
208
|
```
|
|
209
209
|
|
|
210
|
-
Note that an `EvalContext` may back any number of evaluations, and that `caseInsensitive` set on the context alone does not reach the walk — pass it in the evaluation options too. Even then, a plain object handed to `new EvalContext` matches no case variant: build the context with `EvalContext.fromContext(object, options)` instead, which copies the object into a case-insensitive store.
|
|
210
|
+
Note that an `EvalContext` may back any number of evaluations, and that `caseInsensitive` set on the context alone does not reach the walk — pass it in the evaluation options too. Even then, a plain object handed to `new EvalContext` matches no case variant: build the context with `EvalContext.fromContext(object, options)` instead, which copies the object into a case-insensitive store, unless it is not an instance of this realm's `Object` (an object with a null prototype, or one made in another realm): such an object is not copied, and `eval-core` does not yet read it as the context, in either mode.
|
|
211
211
|
|
|
212
212
|
### Colon-joined names — `provideColonIdentifiers`
|
|
213
213
|
|
|
@@ -288,11 +288,11 @@ The project has been tested with the following node types:
|
|
|
288
288
|
the target's value only for a compound or logical operator, then the right side, then the
|
|
289
289
|
write. So `=` does not read its target, and `+=` or `||=` reads it once; up to 0.13.3 the
|
|
290
290
|
target was read as an operand, and a member target was evaluated again after the right side.
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
`
|
|
295
|
-
|
|
291
|
+
How many times an expression calls a getter on the context or on a scope's object, or a
|
|
292
|
+
lookup, is not part of the contract: one can run where JavaScript reads nothing, or more than
|
|
293
|
+
once for one read, and a registered read hook can add a call. Case-sensitively, with a getter
|
|
294
|
+
`g` on the context, `this.g = 1` calls it once, where JavaScript calls none. Destructuring
|
|
295
|
+
assignment, `[a, b] = arr` or `({ m } = o)`, throws
|
|
296
296
|
`Unsupported assignment target`;
|
|
297
297
|
before `@zvenigora/ng-eval-core` 0.7.0 it silently did nothing. An identifier write that
|
|
298
298
|
would shadow `undefined`, or under `caseInsensitive` a literal, throws
|
|
@@ -750,10 +750,11 @@ const afterVisitor = (node, st) => {
|
|
|
750
750
|
*/
|
|
751
751
|
// Direct, not through the `classes/eval` barrel. `instanceof` needs the class
|
|
752
752
|
// itself and not its type, and this module is imported by most visitors, so
|
|
753
|
-
// the narrowest edge is the right one. Nothing here reads
|
|
754
|
-
// module scope - only inside {@link
|
|
755
|
-
//
|
|
756
|
-
// not deepened into an
|
|
753
|
+
// the narrowest edge is the right one. Nothing here reads either binding at
|
|
754
|
+
// module scope - only inside {@link refuseContextWrite} and
|
|
755
|
+
// {@link safeSetProperty} - so the import cycle the barrels already carry
|
|
756
|
+
// (`eval-scope.ts` imports the visitors barrel) is not deepened into an
|
|
757
|
+
// initialisation order.
|
|
757
758
|
/**
|
|
758
759
|
* Set of property names that are dangerous for prototype pollution attacks
|
|
759
760
|
*/
|
|
@@ -958,6 +959,18 @@ const safeSetProperty = (target, key, value) => {
|
|
|
958
959
|
throw new Error(`Cannot set property on non-object: ${typeof target}`);
|
|
959
960
|
}
|
|
960
961
|
refuseContextWrite(target);
|
|
962
|
+
// A scope a host placed in the context as a value is read only through its
|
|
963
|
+
// `get`, so a property written on the instance is never read back, and it
|
|
964
|
+
// could replace the scope's own fields (`docs/backlog-retired.md` A51). By
|
|
965
|
+
// class, so a subclass is refused too. Refused here, after the right side
|
|
966
|
+
// and after a write policy has been asked, as JavaScript refuses a write the
|
|
967
|
+
// object does not accept: a refusal earlier would run ahead of a policy such
|
|
968
|
+
// as a signal context's, whose own error bypasses `onError`
|
|
969
|
+
// (`docs/a48/plan.md`, P-1). The object a namespaced scope holds, `ns.n`, is
|
|
970
|
+
// not a scope, and is written as any object is.
|
|
971
|
+
if (target instanceof EvalScope) {
|
|
972
|
+
throw new Error(`Write to an evaluation scope is blocked`);
|
|
973
|
+
}
|
|
961
974
|
if (isDangerousProperty(key)) {
|
|
962
975
|
throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
|
|
963
976
|
}
|
|
@@ -1001,10 +1014,11 @@ const safeSetProperty = (target, key, value) => {
|
|
|
1001
1014
|
}
|
|
1002
1015
|
};
|
|
1003
1016
|
/**
|
|
1004
|
-
* Safely gets a property from an object with prototype pollution protection
|
|
1017
|
+
* Safely gets a property from an object with prototype pollution protection.
|
|
1018
|
+
* A getter's or a proxy trap's throw propagates, as in JavaScript.
|
|
1005
1019
|
* @param target The target object
|
|
1006
1020
|
* @param key The property key
|
|
1007
|
-
* @returns The property value or undefined
|
|
1021
|
+
* @returns The property value, or undefined for a target that is not an object
|
|
1008
1022
|
*/
|
|
1009
1023
|
const safeGetProperty = (target, key) => {
|
|
1010
1024
|
if (!target || (typeof target !== 'object' && typeof target !== 'function')) {
|
|
@@ -1022,14 +1036,9 @@ const safeGetProperty = (target, key) => {
|
|
|
1022
1036
|
// For other types, try to convert to string
|
|
1023
1037
|
propertyKey = String(key);
|
|
1024
1038
|
}
|
|
1025
|
-
//
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1029
|
-
catch {
|
|
1030
|
-
// If property access fails, return undefined
|
|
1031
|
-
return undefined;
|
|
1032
|
-
}
|
|
1039
|
+
// A getter's or a proxy trap's throw propagates, as it does in JavaScript
|
|
1040
|
+
// (`docs/backlog-retired.md` A55).
|
|
1041
|
+
return target[propertyKey];
|
|
1033
1042
|
};
|
|
1034
1043
|
/**
|
|
1035
1044
|
* Creates a safe object without dangerous prototype pollution vectors
|
|
@@ -1474,10 +1483,15 @@ const evaluateMember = (node, st, callback) => {
|
|
|
1474
1483
|
}
|
|
1475
1484
|
// If cache miss or not found in own properties, check if the original key exists (including prototype methods)
|
|
1476
1485
|
if (cachedFoundKey === undefined || !foundKey) {
|
|
1486
|
+
// The `catch` swallows a throw from a trap JavaScript's `x.k` does
|
|
1487
|
+
// not call, a `has` on the chain or the prototype's `ownKeys`, and
|
|
1488
|
+
// leaves the key as spelled, as `resolveMemberTarget`'s does; the
|
|
1489
|
+
// read below is the one JavaScript makes, and its throw propagates
|
|
1490
|
+
// (`docs/a48/plan.md` § 8 q1).
|
|
1477
1491
|
try {
|
|
1478
|
-
//
|
|
1479
|
-
|
|
1480
|
-
if (
|
|
1492
|
+
// The key as spelled, anywhere on the chain, tested with `in` as the
|
|
1493
|
+
// `=` resolver tests it, so no getter runs here (`docs/backlog-retired.md` A48)
|
|
1494
|
+
if (key in obj) {
|
|
1481
1495
|
foundKey = key;
|
|
1482
1496
|
}
|
|
1483
1497
|
else {
|
|
@@ -1553,15 +1567,23 @@ const evaluateMember = (node, st, callback) => {
|
|
|
1553
1567
|
* `null` and `undefined` included, the full blocklist.
|
|
1554
1568
|
*
|
|
1555
1569
|
* Under `caseInsensitive` a string key on an object is matched as the read
|
|
1556
|
-
* matches it, the own-key cache
|
|
1557
|
-
*
|
|
1558
|
-
*
|
|
1570
|
+
* matches it, the own-key cache, then the key tested with `in`, then the
|
|
1571
|
+
* prototype's own names, so no getter is called (`docs/backlog.md` A44;
|
|
1572
|
+
* the read's test, `docs/backlog-retired.md` A48). The match is checked against the blocklist, as the
|
|
1559
1573
|
* read's `foundKey` is. Any other object takes the key as spelled, as on the
|
|
1560
1574
|
* read path.
|
|
1561
1575
|
*
|
|
1562
|
-
* The context branch still calls `getThis`, which reads the value it tests
|
|
1563
|
-
*
|
|
1564
|
-
*
|
|
1576
|
+
* The context branch still calls `getThis`, which reads the value it tests,
|
|
1577
|
+
* so a getter there runs where JavaScript reads nothing; how many times is not
|
|
1578
|
+
* part of the contract (`docs/backlog-retired.md` A49). When it answers the
|
|
1579
|
+
* context's original and that is a `Registry`, the `caseInsensitive` copy or a
|
|
1580
|
+
* host's, {@link writeMemberTarget} writes it through its map
|
|
1581
|
+
* (`docs/backlog-retired.md` A50). An `EvalScope` is refused, by
|
|
1582
|
+
* `safeSetProperty` (`docs/backlog-retired.md` A51).
|
|
1583
|
+
*
|
|
1584
|
+
* The third slot is the receiver's origin, as `evaluateMember`'s fourth is:
|
|
1585
|
+
* true when the context branch chose it, so that a `Registry` the host holds
|
|
1586
|
+
* in its own data, even the original itself, is written as any object is.
|
|
1565
1587
|
*/
|
|
1566
1588
|
const resolveMemberTarget = (node, st, callback) => {
|
|
1567
1589
|
markThisPositional(node.object, !!st.options?.caseInsensitive);
|
|
@@ -1591,13 +1613,13 @@ const resolveMemberTarget = (node, st, callback) => {
|
|
|
1591
1613
|
throw new Error(`Access to dangerous property "${String(contextKey)}" is blocked for security reasons`);
|
|
1592
1614
|
}
|
|
1593
1615
|
}
|
|
1594
|
-
return [st.context.getThis(contextKey) ?? object, contextKey];
|
|
1616
|
+
return [st.context.getThis(contextKey) ?? object, contextKey, true];
|
|
1595
1617
|
}
|
|
1596
1618
|
else if (object instanceof EvalScope) {
|
|
1597
1619
|
if (isDangerousProperty(key)) {
|
|
1598
1620
|
throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
|
|
1599
1621
|
}
|
|
1600
|
-
return [object, key];
|
|
1622
|
+
return [object, key, false];
|
|
1601
1623
|
}
|
|
1602
1624
|
const isPrimitive = (typeof object === 'string' || typeof object === 'number' || typeof object === 'boolean');
|
|
1603
1625
|
if (isPrimitive ? isDangerousPrimitiveProperty(key) : isDangerousProperty(key)) {
|
|
@@ -1607,9 +1629,9 @@ const resolveMemberTarget = (node, st, callback) => {
|
|
|
1607
1629
|
const target = object;
|
|
1608
1630
|
let foundKey = getCachedCaseInsensitiveProperty(target, key, (a, b) => equalIgnoreCase(a, b) === true);
|
|
1609
1631
|
if (!foundKey) {
|
|
1610
|
-
// As the read path's `
|
|
1611
|
-
//
|
|
1612
|
-
//
|
|
1632
|
+
// As the read path's `in` test, a lookup that throws leaves the key as
|
|
1633
|
+
// spelled. A proxy's `has` trap is called here, which JavaScript's `=`
|
|
1634
|
+
// does not call.
|
|
1613
1635
|
try {
|
|
1614
1636
|
if (key in target) {
|
|
1615
1637
|
foundKey = key;
|
|
@@ -1628,9 +1650,37 @@ const resolveMemberTarget = (node, st, callback) => {
|
|
|
1628
1650
|
if (foundKey && isDangerousProperty(foundKey)) {
|
|
1629
1651
|
throw new Error(`Access to dangerous property "${foundKey}" is blocked for security reasons`);
|
|
1630
1652
|
}
|
|
1631
|
-
return [object, foundKey || key];
|
|
1653
|
+
return [object, foundKey || key, false];
|
|
1632
1654
|
}
|
|
1633
|
-
return [object, key];
|
|
1655
|
+
return [object, key, false];
|
|
1656
|
+
};
|
|
1657
|
+
/**
|
|
1658
|
+
* Writes `value` to `key` of a member target. The context's original, when it
|
|
1659
|
+
* is a `Registry` - a host's, or the `caseInsensitive` copy of a plain
|
|
1660
|
+
* context - and the context branch chose it (`fromContext`), is written through
|
|
1661
|
+
* its map, as `k = v` writes it: that path reads it through `get`, so a property
|
|
1662
|
+
* on the instance is never read back (`docs/backlog-retired.md` A50). Anything
|
|
1663
|
+
* else is `safeSetProperty`'s, a `Registry` reached as a value included, even
|
|
1664
|
+
* the original, which the host may hold in its own data: that path reads it as
|
|
1665
|
+
* an object, so it is written as one, consistent with itself as before.
|
|
1666
|
+
*
|
|
1667
|
+
* That branch bypasses `safeSetProperty`, so it refuses a blocked name itself,
|
|
1668
|
+
* with the same message. It stands behind the callers' own refusals: for `=`
|
|
1669
|
+
* and the compound and logical operators `resolveMemberTarget` refuses a
|
|
1670
|
+
* blocked key, and its `caseInsensitive` resolution, before the right side
|
|
1671
|
+
* runs, and for an update the read in `evaluateMember` refuses it.
|
|
1672
|
+
*/
|
|
1673
|
+
const writeMemberTarget = (st, object, key, value, fromContext) => {
|
|
1674
|
+
// The origin and the identity first: `instanceof` calls a proxy's
|
|
1675
|
+
// `getPrototypeOf` trap.
|
|
1676
|
+
if (fromContext && object === st.context?.original && object instanceof Registry) {
|
|
1677
|
+
if (isDangerousProperty(key)) {
|
|
1678
|
+
throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
|
|
1679
|
+
}
|
|
1680
|
+
object.set(key, value);
|
|
1681
|
+
return;
|
|
1682
|
+
}
|
|
1683
|
+
safeSetProperty(object, key, value);
|
|
1634
1684
|
};
|
|
1635
1685
|
|
|
1636
1686
|
const arrayExpressionVisitor = (node, st, callback) => {
|
|
@@ -1925,7 +1975,7 @@ const recordCreated = (created, value) => {
|
|
|
1925
1975
|
* here unchanged: nothing has been written yet.
|
|
1926
1976
|
*
|
|
1927
1977
|
* Called by the member branches of `assignment-expression.ts` and
|
|
1928
|
-
* `update-expression.ts`, immediately before `
|
|
1978
|
+
* `update-expression.ts`, immediately before `writeMemberTarget`, and only after
|
|
1929
1979
|
* the caller has read `st.createdObjects` and found it set. That read is the
|
|
1930
1980
|
* whole of the default path's cost: a state whose context has no policy holds
|
|
1931
1981
|
* no set, so neither visitor reaches this call.
|
|
@@ -2035,9 +2085,10 @@ const WRITE_SITES = (() => {
|
|
|
2035
2085
|
* the other half of `refuseContextWrite` (`docs/a35/plan.md` Revision 16,
|
|
2036
2086
|
* item 2's enumeration).
|
|
2037
2087
|
*
|
|
2038
|
-
* `
|
|
2039
|
-
* evaluator: dotted and computed member
|
|
2040
|
-
* the update expressions.
|
|
2088
|
+
* `writeMemberTarget`, and the `safeSetProperty` it falls to, cover every
|
|
2089
|
+
* write an expression makes through the evaluator: dotted and computed member
|
|
2090
|
+
* assignment, compound assignment and the update expressions. They do not
|
|
2091
|
+
* cover a write made by **native code**
|
|
2041
2092
|
* the expression merely calls - `Object.assign(c, { push: f })`,
|
|
2042
2093
|
* `Object.defineProperty`, `Reflect.set`, `Object.setPrototypeOf`,
|
|
2043
2094
|
* `Object.freeze`, and each of them reached through `call`, `apply` or
|
|
@@ -2476,7 +2527,7 @@ const callMember = (st, [object, propertyName, fn, contextResolved], args, optio
|
|
|
2476
2527
|
// not the caller's to write (`member-write-policy.ts`). After the
|
|
2477
2528
|
// consultation and not before, so a policy still sees the write it would
|
|
2478
2529
|
// have seen and its own refusal is still the one that surfaces - the same
|
|
2479
|
-
// order the member-write path has, where `
|
|
2530
|
+
// order the member-write path has, where `writeMemberTarget` refuses after
|
|
2480
2531
|
// `consultMemberWrite` has been asked.
|
|
2481
2532
|
refuseContextMethodWrite(fn, receiver, args);
|
|
2482
2533
|
// A receiver the evaluator resolved out of the context's own chain is
|
|
@@ -4320,6 +4371,7 @@ const assignmentExpressionVisitor = (node, st, callback) => {
|
|
|
4320
4371
|
let left;
|
|
4321
4372
|
let targetObject;
|
|
4322
4373
|
let targetKey;
|
|
4374
|
+
let targetFromContext = false;
|
|
4323
4375
|
if (target.type === 'Identifier') {
|
|
4324
4376
|
if (plain) {
|
|
4325
4377
|
refuseIdentifierTarget(target, st);
|
|
@@ -4329,12 +4381,13 @@ const assignmentExpressionVisitor = (node, st, callback) => {
|
|
|
4329
4381
|
}
|
|
4330
4382
|
}
|
|
4331
4383
|
else if (plain) {
|
|
4332
|
-
[targetObject, targetKey] = resolveMemberTarget(target, st, callback);
|
|
4384
|
+
[targetObject, targetKey, targetFromContext] = resolveMemberTarget(target, st, callback);
|
|
4333
4385
|
}
|
|
4334
4386
|
else {
|
|
4335
|
-
const [object, , value, , key] = evaluateMember(target, st, callback);
|
|
4387
|
+
const [object, , value, fromContext, key] = evaluateMember(target, st, callback);
|
|
4336
4388
|
targetObject = object;
|
|
4337
4389
|
targetKey = key;
|
|
4390
|
+
targetFromContext = fromContext === true;
|
|
4338
4391
|
left = value;
|
|
4339
4392
|
}
|
|
4340
4393
|
if (!plain) {
|
|
@@ -4387,8 +4440,10 @@ const assignmentExpressionVisitor = (node, st, callback) => {
|
|
|
4387
4440
|
if (created) {
|
|
4388
4441
|
consultMemberWrite(st, created, object, key);
|
|
4389
4442
|
}
|
|
4390
|
-
//
|
|
4391
|
-
|
|
4443
|
+
// A `Registry` that is the context's original, reached through the
|
|
4444
|
+
// context, through its map; anything else through `safeSetProperty`; each
|
|
4445
|
+
// refusing a blocked name.
|
|
4446
|
+
writeMemberTarget(st, object, key, value, targetFromContext);
|
|
4392
4447
|
pushVisitorResult(node, st, value);
|
|
4393
4448
|
}
|
|
4394
4449
|
afterVisitor(node, st);
|
|
@@ -4434,7 +4489,7 @@ const updateExpressionVisitor = (node, st, callback) => {
|
|
|
4434
4489
|
}
|
|
4435
4490
|
else if (target.type === 'MemberExpression') {
|
|
4436
4491
|
// The write reaches the key the lookup matched (`docs/backlog.md` A44).
|
|
4437
|
-
const [object, , value, , property] = evaluateMember(target, st, callback);
|
|
4492
|
+
const [object, , value, fromContext, property] = evaluateMember(target, st, callback);
|
|
4438
4493
|
// As in the identifier branch: one native conversion, before the write.
|
|
4439
4494
|
let updated = value;
|
|
4440
4495
|
const old = node.operator === '++' ? updated++ : updated--;
|
|
@@ -4443,8 +4498,10 @@ const updateExpressionVisitor = (node, st, callback) => {
|
|
|
4443
4498
|
if (created) {
|
|
4444
4499
|
consultMemberWrite(st, created, object, property);
|
|
4445
4500
|
}
|
|
4446
|
-
//
|
|
4447
|
-
|
|
4501
|
+
// A `Registry` that is the context's original, reached through the
|
|
4502
|
+
// context, through its map; anything else through `safeSetProperty`; each
|
|
4503
|
+
// refusing a blocked name.
|
|
4504
|
+
writeMemberTarget(st, object, property, updated, fromContext === true);
|
|
4448
4505
|
pushVisitorResult(node, st, node.prefix ? updated : old);
|
|
4449
4506
|
}
|
|
4450
4507
|
else {
|
|
@@ -5389,6 +5446,12 @@ class EvalContext {
|
|
|
5389
5446
|
}
|
|
5390
5447
|
/**
|
|
5391
5448
|
* Gets the lookups registry.
|
|
5449
|
+
*
|
|
5450
|
+
* A lookup is called while a name is resolved, and how many times an
|
|
5451
|
+
* expression calls it is not part of the contract
|
|
5452
|
+
* (`docs/backlog-retired.md` A49): it can be called where JavaScript would
|
|
5453
|
+
* read nothing, as under `caseInsensitive` by `x = 1`, or more than once for
|
|
5454
|
+
* one read, and a registered read hook can add a call.
|
|
5392
5455
|
*/
|
|
5393
5456
|
get lookups() {
|
|
5394
5457
|
return this._lookups;
|
|
@@ -5551,9 +5614,18 @@ class EvalContext {
|
|
|
5551
5614
|
* not an object that holds the key.
|
|
5552
5615
|
*
|
|
5553
5616
|
* Undefined means "no receiver of its own", and the member visitor then falls
|
|
5554
|
-
* back to the object it was evaluating.
|
|
5555
|
-
*
|
|
5556
|
-
*
|
|
5617
|
+
* back to the object it was evaluating.
|
|
5618
|
+
*
|
|
5619
|
+
* It decides by reading the value, through the original or a prior scope's
|
|
5620
|
+
* `get`, so a getter there runs where JavaScript reads nothing; how many
|
|
5621
|
+
* times an expression calls it is not part of the contract
|
|
5622
|
+
* (`docs/backlog-retired.md` A49). Case-sensitively, with a getter `g` on the
|
|
5623
|
+
* context, `this.g = 1` calls it once and `this.g += 1` twice, with or
|
|
5624
|
+
* without a read hook.
|
|
5625
|
+
*
|
|
5626
|
+
* Up to 0.6.x the prior-scope step re-tested the original context and could
|
|
5627
|
+
* never answer, and the lookup step returned the lookup function itself
|
|
5628
|
+
* (`docs/backlog-retired.md` A7).
|
|
5557
5629
|
* @param key - The key to retrieve the value for.
|
|
5558
5630
|
* @returns The `this` value associated with the key, or undefined.
|
|
5559
5631
|
*/
|