js/src/tests/js1_2/function/tostring-2.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.

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

mercurial