|
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/. */ |
|
5 |
|
6 /* |
|
7 * |
|
8 * Date: 06 Mar 2002 |
|
9 * SUMMARY: Testing cloned function objects |
|
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=127557 |
|
11 * |
|
12 * Before this bug was fixed, this testcase would error when run: |
|
13 * |
|
14 * ReferenceError: h_peer is not defined |
|
15 * |
|
16 * The line |g.prototype = new Object| below is essential: this is |
|
17 * what was confusing the engine in its attempt to look up h_peer |
|
18 */ |
|
19 //----------------------------------------------------------------------------- |
|
20 var UBound = 0; |
|
21 var BUGNUMBER = 127557; |
|
22 var summary = 'Testing cloned function objects'; |
|
23 var cnCOMMA = ','; |
|
24 var status = ''; |
|
25 var statusitems = []; |
|
26 var actual = ''; |
|
27 var actualvalues = []; |
|
28 var expect= ''; |
|
29 var expectedvalues = []; |
|
30 |
|
31 if (typeof clone == 'function') |
|
32 { |
|
33 status = inSection(1); |
|
34 var f = evaluate("(function(x, y) {\n" + |
|
35 " function h() { return h_peer(); }\n" + |
|
36 " function h_peer() { return (x + cnCOMMA + y); }\n" + |
|
37 " return h;\n" + |
|
38 "})", |
|
39 {compileAndGo: false}); |
|
40 var g = clone(f); |
|
41 g.prototype = new Object; |
|
42 var h = g(5,6); |
|
43 actual = h(); |
|
44 expect = '5,6'; |
|
45 addThis(); |
|
46 } |
|
47 else |
|
48 { |
|
49 reportCompare('Test not run', 'Test not run', 'shell only test requires clone()'); |
|
50 } |
|
51 |
|
52 |
|
53 |
|
54 //----------------------------------------------------------------------------- |
|
55 test(); |
|
56 //----------------------------------------------------------------------------- |
|
57 |
|
58 |
|
59 |
|
60 function addThis() |
|
61 { |
|
62 statusitems[UBound] = status; |
|
63 actualvalues[UBound] = actual; |
|
64 expectedvalues[UBound] = expect; |
|
65 UBound++; |
|
66 } |
|
67 |
|
68 |
|
69 function test() |
|
70 { |
|
71 enterFunc('test'); |
|
72 printBugNumber(BUGNUMBER); |
|
73 printStatus(summary); |
|
74 |
|
75 for (var i=0; i<UBound; i++) |
|
76 { |
|
77 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
|
78 } |
|
79 |
|
80 exitFunc ('test'); |
|
81 } |
|
82 |