js/src/tests/js1_2/function/tostring-2.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // |reftest| skip -- obsolete test
     2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 /**
     9    File Name:          tostring-1.js
    10    Section:            Function.toString
    11    Description:
    13    Since the behavior of Function.toString() is implementation-dependent,
    14    toString tests for function are not in the ECMA suite.
    16    Currently, an attempt to parse the toString output for some functions
    17    and verify that the result is something reasonable.
    19    This verifies
    20    http://scopus.mcom.com/bugsplat/show_bug.cgi?id=99212
    22    Author:             christine@netscape.com
    23    Date:               12 november 1997
    24 */
    26 var SECTION = "tostring-2";
    27 var VERSION = "JS1_2";
    28 var TITLE   = "Function.toString()";
    29 var BUGNUMBER="123444";
    30 startTest();
    32 writeHeaderToLog( SECTION + " "+ TITLE);
    34 var tab = "    ";
    37 var equals = new TestFunction( "Equals", "a, b", tab+ "return a == b;" );
    38 function Equals (a, b) {
    39   return a == b;
    40 }
    42 var reallyequals = new TestFunction( "ReallyEquals", "a, b",
    43 				     ( version() <= 120 )  ? tab +"return a == b;" : tab +"return a === b;" );
    44 function ReallyEquals( a, b ) {
    45   return a === b;
    46 }
    48 var doesntequal = new TestFunction( "DoesntEqual", "a, b", tab + "return a != b;" );
    49 function DoesntEqual( a, b ) {
    50   return a != b;
    51 }
    53 var reallydoesntequal = new TestFunction( "ReallyDoesntEqual", "a, b",
    54 					  ( version() <= 120 ) ? tab +"return a != b;"  : tab +"return a !== b;" );
    55 function ReallyDoesntEqual( a, b ) {
    56   return a !== b;
    57 }
    59 var testor = new TestFunction( "TestOr", "a",  tab+"if (a == null || a == void 0) {\n"+
    60 			       tab +tab+"return 0;\n"+tab+"} else {\n"+tab+tab+"return a;\n"+tab+"}" );
    61 function TestOr( a ) {
    62   if ( a == null || a == void 0 )
    63     return 0;
    64   else
    65     return a;
    66 }
    68 var testand = new TestFunction( "TestAnd", "a", tab+"if (a != null && a != void 0) {\n"+
    69 				tab+tab+"return a;\n" + tab+ "} else {\n"+tab+tab+"return 0;\n"+tab+"}" );
    70 function TestAnd( a ) {
    71   if ( a != null && a != void 0 )
    72     return a;
    73   else
    74     return 0;
    75 }
    77 var or = new TestFunction( "Or", "a, b", tab + "return a | b;" );
    78 function Or( a, b ) {
    79   return a | b;
    80 }
    82 var and = new TestFunction( "And", "a, b", tab + "return a & b;" );
    83 function And( a, b ) {
    84   return a & b;
    85 }
    87 var xor = new TestFunction( "XOr", "a, b", tab + "return a ^ b;" );
    88 function XOr( a, b ) {
    89   return a ^ b;
    90 }
    92 new TestCase( SECTION,
    93 	      "Equals.toString()",
    94 	      equals.valueOf(),
    95 	      Equals.toString() );
    97 new TestCase( SECTION,
    98 	      "ReallyEquals.toString()",
    99 	      reallyequals.valueOf(),
   100 	      ReallyEquals.toString() );
   102 new TestCase( SECTION,
   103 	      "DoesntEqual.toString()",
   104 	      doesntequal.valueOf(),
   105 	      DoesntEqual.toString() );
   107 new TestCase( SECTION,
   108 	      "ReallyDoesntEqual.toString()",
   109 	      reallydoesntequal.valueOf(),
   110 	      ReallyDoesntEqual.toString() );
   112 new TestCase( SECTION,
   113 	      "TestOr.toString()",
   114 	      testor.valueOf(),
   115 	      TestOr.toString() );
   117 new TestCase( SECTION,
   118 	      "TestAnd.toString()",
   119 	      testand.valueOf(),
   120 	      TestAnd.toString() );
   122 new TestCase( SECTION,
   123 	      "Or.toString()",
   124 	      or.valueOf(),
   125 	      Or.toString() );
   127 new TestCase( SECTION,
   128 	      "And.toString()",
   129 	      and.valueOf(),
   130 	      And.toString() );
   132 new TestCase( SECTION,
   133 	      "XOr.toString()",
   134 	      xor.valueOf(),
   135 	      XOr.toString() );
   137 test();
   139 function TestFunction( name, args, body ) {
   140   this.name = name;
   141   this.arguments = args.toString();
   142   this.body = body;
   144   /* the format of Function.toString() in JavaScript 1.2 is:
   145      function name ( arguments ) {
   146      body
   147      }
   148   */
   149   this.value = "function " + (name ? name : "anonymous" )+
   150     "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}";
   152   this.toString = new Function( "return this.value" );
   153   this.valueOf = new Function( "return this.value" );
   154   return this;
   155 }

mercurial