order-01.js (2393B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 //----------------------------------------------------------------------------- 7 var BUGNUMBER = 433672; 8 var summary = 'operator evaluation order'; 9 var actual = ''; 10 var expect = ''; 11 12 function makeObject(label) 13 { 14 var o = (function (){}); 15 16 o.label = label; 17 o.valueOf = (function() { actual += this.label + ' valueOf, '; return Object.prototype.valueOf.call(this); }); 18 o.toString = (function() { actual += this.label + ' toString, '; return Object.prototype.toString.call(this); }); 19 20 return o; 21 } 22 23 operators = [ 24 {section: '11.5.1', operator: '*'}, 25 {section: '11.5.2', operator: '/'}, 26 {section: '11.5.3', operator: '%'}, 27 {section: '11.6.1', operator: '+'}, 28 {section: '11.6.2', operator: '-'}, 29 {section: '11.7.1', operator: '<<'}, 30 {section: '11.7.2', operator: '>>'}, 31 {section: '11.7.3', operator: '>>>'}, 32 {section: '11.8.1', operator: '<'}, 33 {section: '11.8.2', operator: '>'}, 34 {section: '11.8.3', operator: '<='}, 35 {section: '11.8.4', operator: '>='}, 36 {section: '11.10', operator: '&'}, 37 {section: '11.10', operator: '^'}, 38 {section: '11.10', operator: '|'}, 39 {section: '11.13.2', operator: '*='}, 40 {section: '11.13.2', operator: '/='}, 41 {section: '11.13.2', operator: '%='}, 42 {section: '11.13.2', operator: '+='}, 43 {section: '11.13.2', operator: '<<='}, 44 {section: '11.13.2', operator: '>>='}, 45 {section: '11.13.2', operator: '>>>='}, 46 {section: '11.13.2', operator: '&='}, 47 {section: '11.13.2', operator: '^='}, 48 {section: '11.13.2', operator: '|='}, 49 ]; 50 51 //----------------------------------------------------------------------------- 52 test(); 53 //----------------------------------------------------------------------------- 54 55 function test() 56 { 57 printBugNumber(BUGNUMBER); 58 printStatus (summary); 59 60 for (var i = 0; i < operators.length; i++) 61 { 62 expect = 'left valueOf, left toString, right valueOf, right toString, '; 63 actual = ''; 64 65 var left = makeObject('left'); 66 var right = makeObject('right'); 67 68 eval('left ' + operators[i].operator + ' right'); 69 70 reportCompare(expect, actual, summary + ': ' + operators[i].section + ' ' + operators[i].operator); 71 } 72 }