regress-383674.js (1443B)
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 = 383674; 8 var summary = 'Statement that implicitly calls toString should not be optimized away as a "useless expression"'; 9 var actual = ''; 10 var expect = ''; 11 12 13 //----------------------------------------------------------------------------- 14 test(); 15 //----------------------------------------------------------------------------- 16 17 function test() 18 { 19 printBugNumber(BUGNUMBER); 20 printStatus (summary); 21 22 expect = 'toString called'; 23 actual = 'toString not called'; 24 try 25 { 26 var x = {toString: function() { 27 actual = 'toString called'; 28 print(actual); 29 } 30 }; 31 var f = function() { var j = x; j + ""; } 32 f(); 33 reportCompare(expect, actual, summary + ': 1'); 34 } 35 catch(ex) 36 { 37 reportCompare("No Error", ex + "", summary + ': 1'); 38 } 39 40 actual = 'toString not called'; 41 try 42 { 43 (function() { var a = 44 ({toString: function(){ 45 actual = 'toString called'; print(actual)} }); a += ""; })(); 46 reportCompare(expect, actual, summary + ': 2'); 47 } 48 catch(ex) 49 { 50 reportCompare("No Error", ex + "", summary + ': 2'); 51 } 52 }