commit-queue@webkit.org | a4201b0 | 2015-08-17 22:24:20 +0000 | [diff] [blame] | 1 | var sortedValues; |
| 2 | |
| 3 | var testCase = function (actual, expected, message) { |
| 4 | if (actual !== expected) { |
| 5 | throw message + ". Expected '" + expected + "', but was '" + actual + "'"; |
| 6 | } |
| 7 | }; |
| 8 | |
| 9 | |
| 10 | var obj = { |
| 11 | arr: [1, 4, 6, 3, 7, 0], |
| 12 | bubbleSort: function () { |
| 13 | return () => { |
| 14 | var tmp; |
| 15 | var ar = this.arr.slice(); |
| 16 | var _length = ar.length |
| 17 | for (var i = 0; i < _length; i++) { |
| 18 | for (var j = i; j > 0; j--) { |
| 19 | if ((ar[j] - ar[j - 1]) < 0) { |
| 20 | tmp = ar[j]; |
| 21 | ar[j] = ar[j - 1]; |
| 22 | ar[j - 1] = tmp; |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | return ar; |
| 27 | } |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | noInline(obj.bubbleSort); |
| 32 | |
| 33 | for (var i=0; i<10000; i++) { |
| 34 | obj.arr = [1, 2, 4, 6, 3, 7, 0]; |
| 35 | testCase(obj.bubbleSort()().length, 7, "Error: this is not lexically binded inside of the arrow function #1"); |
| 36 | |
| 37 | var sortedValues = obj.bubbleSort()(); |
| 38 | testCase(sortedValues[0], 0, "Error: this is not lexically binded inside of the arrow function #6"); |
| 39 | testCase(sortedValues[6], 7, "Error: this is not lexically binded inside of the arrow function #7"); |
| 40 | |
| 41 | obj.arr = [1, 2, 4, 6, 5, 8, 21, 19, 0]; |
| 42 | |
| 43 | testCase(obj.bubbleSort()().length, 9, "Error: this is not lexically binded inside of the arrow function #8"); |
| 44 | |
| 45 | sortedValues = obj.bubbleSort()(); |
| 46 | testCase(sortedValues[1], 1, "Error: this is not lexically binded inside of the arrow function #12"); |
| 47 | testCase(sortedValues[8], 21, "Error: this is not lexically binded inside of the arrow function #13"); |
| 48 | } |