1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/Regress/regress-118849.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,152 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * 1.11 + * Date: 08 Jan 2002 1.12 + * SUMMARY: Just testing that we don't crash on this code 1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=118849 1.14 + * 1.15 + * http://developer.netscape.com:80/docs/manuals/js/core/jsref/function.htm 1.16 + * The Function constructor: 1.17 + * Function ([arg1[, arg2[, ... argN]],] functionBody) 1.18 + * 1.19 + * Parameters 1.20 + * arg1, arg2, ... argN 1.21 + * (Optional) Names to be used by the function as formal argument names. 1.22 + * Each must be a string that corresponds to a valid JavaScript identifier. 1.23 + * 1.24 + * functionBody 1.25 + * A string containing JS statements comprising the function definition. 1.26 + */ 1.27 +//----------------------------------------------------------------------------- 1.28 +var UBound = 0; 1.29 +var BUGNUMBER = 118849; 1.30 +var summary = 'Should not crash if we provide Function() with bad arguments' 1.31 + var status = ''; 1.32 +var statusitems = []; 1.33 +var actual = ''; 1.34 +var actualvalues = []; 1.35 +var expect= ''; 1.36 +var expectedvalues = []; 1.37 +var cnFAIL_1 = 'LEGAL call to Function() caused an ERROR!!!'; 1.38 +var cnFAIL_2 = 'ILLEGAL call to Function() FAILED to cause an error'; 1.39 +var cnSTRING = 'ASDF'; 1.40 +var cnNUMBER = 123; 1.41 + 1.42 + 1.43 +/***********************************************************/ 1.44 +/**** THESE ARE LEGITMATE CALLS AND SHOULD ALL SUCCEED ***/ 1.45 +/***********************************************************/ 1.46 +status = inSection(1); 1.47 +actual = cnFAIL_1; // initialize to failure 1.48 +try 1.49 +{ 1.50 + Function(cnSTRING); 1.51 + Function(cnNUMBER); // cnNUMBER is a valid functionBody 1.52 + Function(cnSTRING,cnSTRING); 1.53 + Function(cnSTRING,cnNUMBER); 1.54 + Function(cnSTRING,cnSTRING,cnNUMBER); 1.55 + 1.56 + new Function(cnSTRING); 1.57 + new Function(cnNUMBER); 1.58 + new Function(cnSTRING,cnSTRING); 1.59 + new Function(cnSTRING,cnNUMBER); 1.60 + new Function(cnSTRING,cnSTRING,cnNUMBER); 1.61 + 1.62 + actual = expect; 1.63 +} 1.64 +catch(e) 1.65 +{ 1.66 +} 1.67 +addThis(); 1.68 + 1.69 + 1.70 + 1.71 +/**********************************************************/ 1.72 +/*** EACH CASE THAT FOLLOWS SHOULD TRIGGER AN ERROR ***/ 1.73 +/*** (BUT NOT A CRASH) ***/ 1.74 +/*** NOTE WE NOW USE cnFAIL_2 INSTEAD OF cnFAIL_1 ***/ 1.75 +/**********************************************************/ 1.76 +status = inSection(2); 1.77 +actual = cnFAIL_2; 1.78 +try 1.79 +{ 1.80 + Function(cnNUMBER,cnNUMBER); // cnNUMBER is an invalid JS identifier name 1.81 +} 1.82 +catch(e) 1.83 +{ 1.84 + actual = expect; 1.85 +} 1.86 +addThis(); 1.87 + 1.88 + 1.89 +status = inSection(3); 1.90 +actual = cnFAIL_2; 1.91 +try 1.92 +{ 1.93 + Function(cnNUMBER,cnSTRING,cnSTRING); 1.94 +} 1.95 +catch(e) 1.96 +{ 1.97 + actual = expect; 1.98 +} 1.99 +addThis(); 1.100 + 1.101 + 1.102 +status = inSection(4); 1.103 +actual = cnFAIL_2; 1.104 +try 1.105 +{ 1.106 + new Function(cnNUMBER,cnNUMBER); 1.107 +} 1.108 +catch(e) 1.109 +{ 1.110 + actual = expect; 1.111 +} 1.112 +addThis(); 1.113 + 1.114 + 1.115 +status = inSection(5); 1.116 +actual = cnFAIL_2; 1.117 +try 1.118 +{ 1.119 + new Function(cnNUMBER,cnSTRING,cnSTRING); 1.120 +} 1.121 +catch(e) 1.122 +{ 1.123 + actual = expect; 1.124 +} 1.125 +addThis(); 1.126 + 1.127 + 1.128 + 1.129 +//----------------------------------------------------------------------------- 1.130 +test(); 1.131 +//----------------------------------------------------------------------------- 1.132 + 1.133 + 1.134 +function addThis() 1.135 +{ 1.136 + statusitems[UBound] = status; 1.137 + actualvalues[UBound] = actual; 1.138 + expectedvalues[UBound] = expect; 1.139 + UBound++; 1.140 +} 1.141 + 1.142 + 1.143 +function test() 1.144 +{ 1.145 + enterFunc ('test'); 1.146 + printBugNumber(BUGNUMBER); 1.147 + printStatus (summary); 1.148 + 1.149 + for (var i = 0; i < UBound; i++) 1.150 + { 1.151 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.152 + } 1.153 + 1.154 + exitFunc ('test'); 1.155 +}