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.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 * Date: 2001-07-13
8 *
9 * SUMMARY: Applying Function.prototype.call to the Function object itself
10 *
11 *
12 * ECMA-262 15.3.4.4 Function.prototype.call (thisArg [,arg1 [,arg2,…] ] )
13 *
14 * When applied to the Function object itself, thisArg should be ignored.
15 * As explained by Waldemar (waldemar@netscape.com):
16 *
17 * Function.call(obj, "print(this)") is equivalent to invoking
18 * Function("print(this)") with this set to obj. Now, Function("print(this)")
19 * is equivalent to new Function("print(this)") (see 15.3.1.1), and the latter
20 * ignores the this value that you passed it and constructs a function
21 * (which we'll call F) which will print the value of the this that will be
22 * passed in when F will be invoked.
23 *
24 * With the last set of () you're invoking F(), which means you're calling it
25 * with no this value. When you don't provide a this value, it defaults to the
26 * global object.
27 *
28 */
30 //-----------------------------------------------------------------------------
31 var UBound = 0;
32 var BUGNUMBER = '(none)';
33 var summary = 'Applying Function.prototype.call to the Function object itself';
34 var status = '';
35 var statusitems = [];
36 var actual = '';
37 var actualvalues = [];
38 var expect= '';
39 var expectedvalues = [];
40 var self = this; // capture a reference to the global object
41 var cnOBJECT_GLOBAL = self.toString();
42 var cnOBJECT_OBJECT = (new Object).toString();
43 var cnHello = 'Hello';
44 var cnRed = 'red';
45 var objTEST = {color:cnRed};
46 var f = new Function();
47 var g = new Function();
50 f = Function.call(self, 'return cnHello');
51 g = Function.call(objTEST, 'return cnHello');
53 status = 'Section A of test';
54 actual = f();
55 expect = cnHello;
56 captureThis();
58 status = 'Section B of test';
59 actual = g();
60 expect = cnHello;
61 captureThis();
64 f = Function.call(self, 'return this.toString()');
65 g = Function.call(objTEST, 'return this.toString()');
67 status = 'Section C of test';
68 actual = f();
69 expect = cnOBJECT_GLOBAL;
70 captureThis();
72 status = 'Section D of test';
73 actual = g();
74 expect = cnOBJECT_GLOBAL;
75 captureThis();
78 f = Function.call(self, 'return this.color');
79 g = Function.call(objTEST, 'return this.color');
81 status = 'Section E of test';
82 actual = f();
83 expect = undefined;
84 captureThis();
86 status = 'Section F of test';
87 actual = g();
88 expect = undefined;
89 captureThis();
93 //-----------------------------------------------------------------------------
94 test();
95 //-----------------------------------------------------------------------------
98 function captureThis()
99 {
100 statusitems[UBound] = status;
101 actualvalues[UBound] = actual;
102 expectedvalues[UBound] = expect;
103 UBound++;
104 }
107 function test()
108 {
109 enterFunc ('test');
110 printBugNumber(BUGNUMBER);
111 printStatus (summary);
113 for (var i = 0; i < UBound; i++)
114 {
115 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
116 }
118 exitFunc ('test');
119 }