mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Make sure to evaluate (compare) in the proper order
This commit is contained in:
parent
4abba5f6c6
commit
3f54041eb6
|
@ -378,6 +378,7 @@ var lessThanTable [4](map[_lessThanResult]bool) = [4](map[_lessThanResult]bool){
|
|||
|
||||
func (self *_runtime) calculateComparison(comparator string, left Value, right Value) bool {
|
||||
|
||||
// TODO This might be redundant now (with regards to evaluateComparison)
|
||||
x := self.GetValue(left)
|
||||
y := self.GetValue(right)
|
||||
|
||||
|
@ -463,8 +464,8 @@ ERROR:
|
|||
|
||||
func (self *_runtime) evaluateComparison(node *_comparisonNode) Value {
|
||||
|
||||
left := self.evaluate(node.Left)
|
||||
right := self.evaluate(node.Right)
|
||||
left := self.GetValue(self.evaluate(node.Left))
|
||||
right := self.GetValue(self.evaluate(node.Right))
|
||||
|
||||
return toValue(self.calculateComparison(node.Comparator, left, right))
|
||||
}
|
||||
|
|
|
@ -1156,6 +1156,16 @@ func Test_toString(t *testing.T) {
|
|||
|
||||
test := runTest()
|
||||
test(`
|
||||
[undefined+""]
|
||||
[undefined+""]
|
||||
`, "undefined")
|
||||
}
|
||||
|
||||
func TestEvaluationOrder(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
test(`
|
||||
var abc = 0;
|
||||
abc < (abc = 1) === true;
|
||||
`, "true")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user