mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
fixes #3363: modulo operator evaluation order
This commit is contained in:
@@ -3075,7 +3075,7 @@
|
||||
return "[].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";
|
||||
},
|
||||
modulo: function() {
|
||||
return "function(a, b) { b = +b; return (a % b + b) % b; }";
|
||||
return "function(a, b) { return (+a % (b = +b) + b) % b; }";
|
||||
},
|
||||
hasProp: function() {
|
||||
return '{}.hasOwnProperty';
|
||||
|
||||
@@ -2194,7 +2194,7 @@ UTILITIES =
|
||||
"
|
||||
|
||||
modulo: -> """
|
||||
function(a, b) { b = +b; return (a % b + b) % b; }
|
||||
function(a, b) { return (+a % (b = +b) + b) % b; }
|
||||
"""
|
||||
|
||||
# Shortcuts to speed up the lookup time for native functions.
|
||||
|
||||
@@ -363,3 +363,10 @@ test "#3361: Modulo operator coerces right operand once", ->
|
||||
res = 42 %% valueOf: -> count += 1
|
||||
eq 1, count
|
||||
eq 0, res
|
||||
|
||||
test "#3363: Modulo operator coercing order", ->
|
||||
count = 2
|
||||
a = valueOf: -> count *= 2
|
||||
b = valueOf: -> count += 1
|
||||
eq 4, a %% b
|
||||
eq 5, count
|
||||
|
||||
Reference in New Issue
Block a user