Skip to content

Commit 11f831b

Browse files
committed
Document consts leaking from nested scopes SM 1.8.5 vs 91/QuickJS/V8
Document Spidermonkey 1.8.5 leaking nested `const` references into outer scopes as `undefined` values. All other engines, including later Spidermonkey 91, throw a ReferenceError in that case. This could affect views which may declare a value inside an if expression and emit that value outside of it.
1 parent 198207a commit 11f831b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/docs/src/best-practices/jsdevel.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,24 @@ with a compilation error:
286286
}
287287
}
288288
289+
11. Constant values leak out of nested scopes
290+
291+
In Spidermonkey 1.8.5 ``const`` values leak from nested expression scopes.
292+
Referencing them in Spidermonkey 1.8.5 produces ``undefined``, while in
293+
Spidermonkey 91, QuickJS and V8 engines raises a ``ReferenceError``.
294+
295+
.. code-block::
296+
297+
% js
298+
js> f = function(doc){if(doc.x === 'x') { const value='inside_if'}; print(value)};
299+
js> f({'x':'y'})
300+
undefined
301+
302+
% js91
303+
js> f = function(doc){if(doc.x === 'x') {const value='inside_if';}; print(value)};
304+
js> f({'x':'y'})
305+
typein:1:23 TypeError: can't access property "x", doc is undefined
306+
289307
Using QuickJS
290308
=============
291309

0 commit comments

Comments
 (0)