Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | * Date: 10 September 2001 |
michael@0 | 8 | * |
michael@0 | 9 | * SUMMARY: Testing with() statement with nested functions |
michael@0 | 10 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=97921 |
michael@0 | 11 | * |
michael@0 | 12 | * Brendan: "The bug is peculiar to functions that have formal parameters, |
michael@0 | 13 | * but that are called with fewer actual arguments than the declared number |
michael@0 | 14 | * of formal parameters." |
michael@0 | 15 | */ |
michael@0 | 16 | //----------------------------------------------------------------------------- |
michael@0 | 17 | var UBound = 0; |
michael@0 | 18 | var BUGNUMBER = 97921; |
michael@0 | 19 | var summary = 'Testing with() statement with nested functions'; |
michael@0 | 20 | var cnYES = 'Inner value === outer value'; |
michael@0 | 21 | var cnNO = "Inner value !== outer value!"; |
michael@0 | 22 | var status = ''; |
michael@0 | 23 | var statusitems = []; |
michael@0 | 24 | var actual = ''; |
michael@0 | 25 | var actualvalues = []; |
michael@0 | 26 | var expect= ''; |
michael@0 | 27 | var expectedvalues = []; |
michael@0 | 28 | var outerValue = ''; |
michael@0 | 29 | var innerValue = ''; |
michael@0 | 30 | var useWith = ''; |
michael@0 | 31 | |
michael@0 | 32 | |
michael@0 | 33 | function F(i) |
michael@0 | 34 | { |
michael@0 | 35 | i = 0; |
michael@0 | 36 | if(useWith) with(1){i;} |
michael@0 | 37 | i++; |
michael@0 | 38 | |
michael@0 | 39 | outerValue = i; // capture value of i in outer function |
michael@0 | 40 | F1 = function() {innerValue = i;}; // capture value of i in inner function |
michael@0 | 41 | F1(); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | |
michael@0 | 45 | status = inSection(1); |
michael@0 | 46 | useWith=false; |
michael@0 | 47 | F(); // call F without supplying the argument |
michael@0 | 48 | actual = innerValue === outerValue; |
michael@0 | 49 | expect = true; |
michael@0 | 50 | addThis(); |
michael@0 | 51 | |
michael@0 | 52 | status = inSection(2); |
michael@0 | 53 | useWith=true; |
michael@0 | 54 | F(); // call F without supplying the argument |
michael@0 | 55 | actual = innerValue === outerValue; |
michael@0 | 56 | expect = true; |
michael@0 | 57 | addThis(); |
michael@0 | 58 | |
michael@0 | 59 | |
michael@0 | 60 | function G(i) |
michael@0 | 61 | { |
michael@0 | 62 | i = 0; |
michael@0 | 63 | with (new Object()) {i=100}; |
michael@0 | 64 | i++; |
michael@0 | 65 | |
michael@0 | 66 | outerValue = i; // capture value of i in outer function |
michael@0 | 67 | G1 = function() {innerValue = i;}; // capture value of i in inner function |
michael@0 | 68 | G1(); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | |
michael@0 | 72 | status = inSection(3); |
michael@0 | 73 | G(); // call G without supplying the argument |
michael@0 | 74 | actual = innerValue === 101; |
michael@0 | 75 | expect = true; |
michael@0 | 76 | addThis(); |
michael@0 | 77 | |
michael@0 | 78 | status = inSection(4); |
michael@0 | 79 | G(); // call G without supplying the argument |
michael@0 | 80 | actual = innerValue === outerValue; |
michael@0 | 81 | expect = true; |
michael@0 | 82 | addThis(); |
michael@0 | 83 | |
michael@0 | 84 | |
michael@0 | 85 | |
michael@0 | 86 | //----------------------------------------------------------------------------- |
michael@0 | 87 | test(); |
michael@0 | 88 | //----------------------------------------------------------------------------- |
michael@0 | 89 | |
michael@0 | 90 | |
michael@0 | 91 | function addThis() |
michael@0 | 92 | { |
michael@0 | 93 | statusitems[UBound] = status; |
michael@0 | 94 | actualvalues[UBound] = areTheseEqual(actual); |
michael@0 | 95 | expectedvalues[UBound] = areTheseEqual(expect); |
michael@0 | 96 | UBound++; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | |
michael@0 | 100 | function test() |
michael@0 | 101 | { |
michael@0 | 102 | enterFunc ('test'); |
michael@0 | 103 | printBugNumber(BUGNUMBER); |
michael@0 | 104 | printStatus (summary); |
michael@0 | 105 | |
michael@0 | 106 | for (var i = 0; i < UBound; i++) |
michael@0 | 107 | { |
michael@0 | 108 | reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | exitFunc ('test'); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | |
michael@0 | 115 | function areTheseEqual(yes) |
michael@0 | 116 | { |
michael@0 | 117 | return yes? cnYES : cnNO |
michael@0 | 118 | } |