-
-
Notifications
You must be signed in to change notification settings - Fork 760
Description
Related: #1691
Investigating this a bit more, @djeis97 had an idea that this might be a bigger problem. Indeed, the following expression incorrectly raises a ReferenceError
:
[undefined][0]
This is because [undefined]
is a temporary value, so it has no references. jspeFactorFunctionCall
correctly evaluates this expression to a JsVar NAME whose varData is the integer 0, and whose firstChild is undefined
([r1,l1] Name Integer 0 undefined
). But at the end of that function, it unlocks the parent value, which in this case is the array [undefined]
.
When jsvUnLock
unlocks this array, the array's lock count is 0, so its ref count becomes 0, so it is freed. This in turn decrements our name var's refcount to 0 ([r0,l1] Name Integer 0 undefined
).
Later, jspParse
calls jsvCheckReferenceError
, which sees [r0,l1] Name Integer 0 undefined
and treats it as a ReferenceError.
Fundamentally, this seems to be an issue because [r0,l_] Name _ undefined
are used both for indicating a ReferenceError, and for representing the reference obtained by indexing into an object with no references itself.
Other examples of this error:
x = [undefined]
x.pop()
({a: undefined})['a']
cc @kiranshila