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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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    Author:             christine@netscape.com
    20    Date:               12 november 1997
    21 */
    23 var SECTION = "tostring-1";
    24 var VERSION = "JS1_2";
    25 startTest();
    26 var TITLE   = "Function.toString()";
    28 writeHeaderToLog( SECTION + " "+ TITLE);
    30 var tab = "    ";
    32 t1 = new TestFunction( "stub", "value", tab + "return value;" );
    34 t2 = new TestFunction( "ToString", "object", tab+"return object + \"\";" );
    36 t3 = new TestFunction( "Add", "a, b, c, d, e",  tab +"var s = a + b + c + d + e;\n" +
    37 		       tab + "return s;" );
    39 t4 = new TestFunction( "noop", "value" );
    41 t5 = new TestFunction( "anonymous", "", tab+"return \"hello!\";" );
    43 var f = new Function( "return \"hello!\"");
    45 new TestCase( SECTION,
    46 	      "stub.toString()",
    47 	      t1.valueOf(),
    48 	      stub.toString() );
    50 new TestCase( SECTION,
    51 	      "ToString.toString()",
    52 	      t2.valueOf(),
    53 	      ToString.toString() );
    55 new TestCase( SECTION,
    56 	      "Add.toString()",
    57 	      t3.valueOf(),
    58 	      Add.toString() );
    60 new TestCase( SECTION,
    61 	      "noop.toString()",
    62 	      t4.toString(),
    63 	      noop.toString() );
    65 new TestCase( SECTION,
    66 	      "f.toString()",
    67 	      t5.toString(),
    68 	      f.toString() );
    69 test();
    71 function noop( value ) {
    72 }
    73 function Add( a, b, c, d, e ) {
    74   var s = a + b + c + d + e;
    75   return s;
    76 }
    77 function stub( value ) {
    78   return value;
    79 }
    80 function ToString( object ) {
    81   return object + "";
    82 }
    84 function ToBoolean( value ) {
    85   if ( value == 0 || value == NaN || value == false ) {
    86     return false;
    87   } else {
    88     return true;
    89   }
    90 }
    92 function TestFunction( name, args, body ) {
    93   if ( name == "anonymous" && version() == 120 ) {
    94     name = "";
    95   }
    97   this.name = name;
    98   this.arguments = args.toString();
    99   this.body = body;
   101   /* the format of Function.toString() in JavaScript 1.2 is:
   102      function name ( arguments ) {
   103      body
   104      }
   105   */
   106   this.value = "function " + (name ? name : "" )+
   107     "("+args+") {\n"+ (( body ) ? body +"\n" : "") + "}";
   109   this.toString = new Function( "return this.value" );
   110   this.valueOf = new Function( "return this.value" );
   111   return this;
   112 }

mercurial