js/src/tests/js1_4/Regress/function-002.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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /**
michael@0 8 * File Name: function-002.js
michael@0 9 * Description:
michael@0 10 *
michael@0 11 * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=330462
michael@0 12 * js> function f(a){var a,b;}
michael@0 13 *
michael@0 14 * causes an an assert on a null 'sprop' in the 'Variables' function in
michael@0 15 * jsparse.c This will crash non-debug build.
michael@0 16 *
michael@0 17 * Author: christine@netscape.com
michael@0 18 * Date: 11 August 1998
michael@0 19 * REVISED: 04 February 2001
michael@0 20 * (changed the comma expressions from trivial to non-trivial)
michael@0 21 * Author: pschwartau@netscape.com
michael@0 22 *
michael@0 23 * Brendan: "The test seemed to require something that ECMA does not
michael@0 24 * guarantee, and that JS1.4 didn't either. For example, given
michael@0 25 *
michael@0 26 * dec2 = "function f2(){1,2}";
michael@0 27 *
michael@0 28 * the engine is free to decompile a function object compiled from this source,
michael@0 29 * via Function.prototype.toString(), into some other string that compiles to
michael@0 30 * an equivalent function. The engine now eliminates the useless comma expression
michael@0 31 * 1,2, giving function f2(){}. This should be legal by the testsuite's lights."
michael@0 32 *
michael@0 33 */
michael@0 34 var SECTION = "function-002.js";
michael@0 35 var VERSION = "JS1_4";
michael@0 36 var TITLE = "Regression test case for 325843";
michael@0 37 var BUGNUMBER="330462";
michael@0 38
michael@0 39 startTest();
michael@0 40
michael@0 41 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 42
michael@0 43 dec1 = "function f1(x,y){++x, --y}";
michael@0 44 dec2 = "function f2(){var y; f1(1,2); y=new Date(); print(y.toString())}";
michael@0 45
michael@0 46 eval(dec1);
michael@0 47 eval(dec2);
michael@0 48
michael@0 49 new TestCase(
michael@0 50 SECTION,
michael@0 51 "typeof f1",
michael@0 52 "function",
michael@0 53 typeof f1 );
michael@0 54
michael@0 55
michael@0 56 // force a function decompilation
michael@0 57 new TestCase(
michael@0 58 SECTION,
michael@0 59 "f1.toString() == dec1",
michael@0 60 true,
michael@0 61 StripSpaces(f1.toString()) == StripSpaces(dec1));
michael@0 62
michael@0 63 new TestCase(
michael@0 64 SECTION,
michael@0 65 "typeof f2",
michael@0 66 "function",
michael@0 67 typeof f2 );
michael@0 68
michael@0 69 // force a function decompilation
michael@0 70
michael@0 71 new TestCase(
michael@0 72 SECTION,
michael@0 73 "f2.toString() == dec2",
michael@0 74 true,
michael@0 75 StripSpaces(f2.toString().replace(/new Date\(\)/g, 'new Date')) ==
michael@0 76 StripSpaces(dec2.replace(/new Date\(\)/g, 'new Date')));
michael@0 77
michael@0 78 test();
michael@0 79
michael@0 80 function StripSpaces( s ) {
michael@0 81 var strippedString = "";
michael@0 82 for ( var currentChar = 0; currentChar < s.length; currentChar++ ) {
michael@0 83 if (!IsWhiteSpace(s.charAt(currentChar))) {
michael@0 84 strippedString += s.charAt(currentChar);
michael@0 85 }
michael@0 86 }
michael@0 87 return strippedString;
michael@0 88 }
michael@0 89
michael@0 90 function IsWhiteSpace( string ) {
michael@0 91 var cc = string.charCodeAt(0);
michael@0 92
michael@0 93 switch (cc) {
michael@0 94 case (0x0009):
michael@0 95 case (0x000B):
michael@0 96 case (0x000C):
michael@0 97 case (0x0020):
michael@0 98 case (0x000A):
michael@0 99 case (0x000D):
michael@0 100 case ( 59 ): // let's strip out semicolons, too
michael@0 101 return true;
michael@0 102 break;
michael@0 103 default:
michael@0 104 return false;
michael@0 105 }
michael@0 106 }
michael@0 107

mercurial