js/src/tests/js1_4/Regress/function-002.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_4/Regress/function-002.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     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 + *  File Name:          function-002.js
    1.12 + *  Description:
    1.13 + *
    1.14 + * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=330462
    1.15 + * js> function f(a){var a,b;}
    1.16 + *
    1.17 + * causes an an assert on a null 'sprop' in the 'Variables' function in
    1.18 + * jsparse.c This will crash non-debug build.
    1.19 + *
    1.20 + *  Author:      christine@netscape.com
    1.21 + *  Date:           11 August 1998
    1.22 + *  REVISED:   04 February 2001
    1.23 + *  (changed  the comma expressions from trivial to  non-trivial)
    1.24 + *  Author:      pschwartau@netscape.com
    1.25 + *
    1.26 + * Brendan: "The test seemed to require something that ECMA does not
    1.27 + * guarantee, and that JS1.4 didn't either. For example, given
    1.28 + *
    1.29 + *             dec2 = "function f2(){1,2}";
    1.30 + *
    1.31 + * the engine is free to decompile a function object compiled from this source,
    1.32 + * via Function.prototype.toString(), into some other string that compiles to
    1.33 + * an equivalent function. The engine now eliminates the useless comma expression
    1.34 + * 1,2, giving function f2(){}. This should be legal by the testsuite's lights."
    1.35 + *
    1.36 + */
    1.37 +var SECTION = "function-002.js";
    1.38 +var VERSION = "JS1_4";
    1.39 +var TITLE   = "Regression test case for 325843";
    1.40 +var BUGNUMBER="330462";
    1.41 +
    1.42 +startTest();
    1.43 +
    1.44 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.45 +
    1.46 +dec1 = "function f1(x,y){++x, --y}";
    1.47 +dec2 = "function f2(){var y; f1(1,2); y=new Date(); print(y.toString())}";
    1.48 +
    1.49 +eval(dec1);
    1.50 +eval(dec2);
    1.51 +
    1.52 +new TestCase(
    1.53 +  SECTION,
    1.54 +  "typeof f1",
    1.55 +  "function",
    1.56 +  typeof f1 );
    1.57 +
    1.58 +
    1.59 +// force a function decompilation
    1.60 +new TestCase(
    1.61 +  SECTION,
    1.62 +  "f1.toString() == dec1",
    1.63 +  true,
    1.64 +  StripSpaces(f1.toString()) == StripSpaces(dec1));
    1.65 +
    1.66 +new TestCase(
    1.67 +  SECTION,
    1.68 +  "typeof f2",
    1.69 +  "function",
    1.70 +  typeof f2 );
    1.71 +
    1.72 +// force a function decompilation
    1.73 +
    1.74 +new TestCase(
    1.75 +  SECTION,
    1.76 +  "f2.toString() == dec2",
    1.77 +  true,
    1.78 +  StripSpaces(f2.toString().replace(/new Date\(\)/g, 'new Date')) ==
    1.79 +  StripSpaces(dec2.replace(/new Date\(\)/g, 'new Date')));
    1.80 +
    1.81 +test();
    1.82 +
    1.83 +function StripSpaces( s ) {
    1.84 +  var strippedString = "";
    1.85 +  for ( var currentChar = 0; currentChar < s.length; currentChar++ ) {
    1.86 +    if (!IsWhiteSpace(s.charAt(currentChar))) {
    1.87 +      strippedString += s.charAt(currentChar);
    1.88 +    }
    1.89 +  }
    1.90 +  return strippedString;
    1.91 +}
    1.92 +
    1.93 +function IsWhiteSpace( string ) {
    1.94 +  var cc = string.charCodeAt(0);
    1.95 +
    1.96 +  switch (cc) {
    1.97 +  case (0x0009):
    1.98 +  case (0x000B):
    1.99 +  case (0x000C):
   1.100 +  case (0x0020):
   1.101 +  case (0x000A):
   1.102 +  case (0x000D):
   1.103 +  case ( 59 ): // let's strip out semicolons, too
   1.104 +    return true;
   1.105 +    break;
   1.106 +  default:
   1.107 +    return false;
   1.108 +  }
   1.109 +}
   1.110 +

mercurial