Fix #2953. Method calls on splice endpoints

This commit is contained in:
Michal Srb 2013-04-23 05:42:37 +02:00
parent fd61476106
commit e7ebdce60f
3 changed files with 12 additions and 2 deletions

View File

@ -1746,7 +1746,7 @@
fromDecl = fromRef = '0';
}
if (to) {
if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) {
if (from && from instanceof Value && (from != null ? from.isSimpleNumber() : void 0) && to instanceof Value && to.isSimpleNumber()) {
to = +to.compile(o) - +fromRef;
if (!exclusive) {
to += 1;

View File

@ -1261,7 +1261,8 @@ exports.Assign = class Assign extends Base
else
fromDecl = fromRef = '0'
if to
if from?.isSimpleNumber() and to.isSimpleNumber()
if from and from instanceof Value and from?.isSimpleNumber() and
to instanceof Value and to.isSimpleNumber()
to = +to.compile(o) - +fromRef
to += 1 unless exclusive
else

View File

@ -144,3 +144,12 @@ test "#1723: operator precedence in unbounded splice compilation", ->
list = [0..9]
list[..if n then n else 0] = n
arrayEq [n..9], list
test "#2953: methods on endpoints in assignment from array splice literal", ->
list = [0..9]
Number.prototype.same = -> this
list[1.same()...9.same()] = 5
delete Number.prototype.same
arrayEq [0, 5, 9], list