|
1 // |reftest| skip-if(!xulRuntime.shell) |
|
2 // Any copyright is dedicated to the Public Domain. |
|
3 // http://creativecommons.org/licenses/publicdomain/ |
|
4 |
|
5 //----------------------------------------------------------------------------- |
|
6 var BUGNUMBER = 671947; |
|
7 var summary = "Unqualified function invocation uses the global object of the called property as |this|"; |
|
8 var actual = "------------------------"; |
|
9 var expect = "ooaoboabuuaubuabooaoboab"; |
|
10 |
|
11 print(BUGNUMBER + ": " + summary); |
|
12 |
|
13 /************** |
|
14 * BEGIN TEST * |
|
15 **************/ |
|
16 |
|
17 this.name = "o"; |
|
18 |
|
19 function f() { |
|
20 return this ? this.name : "t"; |
|
21 } |
|
22 function g() { |
|
23 "use strict"; |
|
24 return this ? this.name : "u"; |
|
25 } |
|
26 function h() { |
|
27 return this ? this.name : "v"; |
|
28 } |
|
29 |
|
30 var sb = newGlobal('same-compartment'); |
|
31 sb.parent = this; |
|
32 |
|
33 evalcx('\n' + |
|
34 ' this.name="i";\n' + |
|
35 ' this.f = parent.f;\n' + |
|
36 ' this.g = parent.g;\n' + |
|
37 ' this.a = { name:"a", f:parent.f, g:parent.g };\n' + |
|
38 ' this.b = { name:"b", f:parent.f, g:parent.g };\n' + |
|
39 ' Object.defineProperty(this, "h", { get: (function(){ return parent.h; })});\n' + |
|
40 ' Object.defineProperty(a, "h", { get: (function(){ return parent.h; })});\n' + |
|
41 ' Object.defineProperty(b, "h", { get: (function(){ return parent.h; })});\n' + |
|
42 |
|
43 ' var results = "";\n' + |
|
44 |
|
45 ' /* Three of the first four cases pass undefined (promoted inside the callee to the callee\'s global object). */\n' + |
|
46 ' /* a.f() is the one exception, which passes the base, a, as the this object. */\n' + |
|
47 ' results += (function(){return f();})();\n' + |
|
48 ' results += (function(){return (1,f)();})();\n' + |
|
49 ' results += (function(){return a.f();})();\n' + |
|
50 ' results += (function(){return eval("f()");})();\n' + |
|
51 ' /* Same cases as above, but wrapped in a with. The first & last of these cases pass b, */\n' + |
|
52 ' /* the object scoped by the with, as the this value. */\n' + |
|
53 ' /* a.f() still passes the explicit base, a. (1,f)() is a little tricksier - this passes */\n' + |
|
54 ' /* undefined (promoted to the callee global object) since the comma operator calles GetValue */\n' + |
|
55 ' /* on the reference (see ES5 11.14.) */\n' + |
|
56 ' results += (function(){with(b){ return (function(){ return f();})(); }})();\n' + |
|
57 ' results += (function(){with(b){ return (function(){ return (1,f)();})(); }})();\n' + |
|
58 ' results += (function(){with(b){ return (function(){ return a.f();})(); }})();\n' + |
|
59 ' results += (function(){with(b){ return (function(){ return eval("f()");})(); }})();\n' + |
|
60 |
|
61 ' /* Same tests as above, but with a strict callee. */\n' + |
|
62 ' /* We expect the same results, except undefined this is not replaced with the global object. */\n' + |
|
63 ' results += (function(){return g();})();\n' + |
|
64 ' results += (function(){return (1,g)();})();\n' + |
|
65 ' results += (function(){return a.g();})();\n' + |
|
66 ' results += (function(){return eval("g()");})();\n' + |
|
67 ' results += (function(){with(b){ return g(); }})();\n' + |
|
68 ' results += (function(){with(b){ return (1,g)(); }})();\n' + |
|
69 ' results += (function(){with(b){ return a.g(); }})();\n' + |
|
70 ' results += (function(){with(b){ return (function(){ return eval("g()");})(); }})();\n' + |
|
71 |
|
72 ' /* Same as the first set, but h is a getter property. */\n' + |
|
73 ' results += (function(){return h();})();\n' + |
|
74 ' results += (function(){return (1,h)();})();\n' + |
|
75 ' results += (function(){return a.h();})();\n' + |
|
76 ' results += (function(){return eval("h()");})();\n' + |
|
77 ' results += (function(){with(b){ return h(); }})();\n' + |
|
78 ' results += (function(){with(b){ return (1,h)(); }})();\n' + |
|
79 ' results += (function(){with(b){ return a.h(); }})();\n' + |
|
80 ' results += (function(){with(b){ return (function(){ return eval("h()");})(); }})();\n' + |
|
81 |
|
82 ' parent.actual = results;\n' + |
|
83 '', |
|
84 sb); |
|
85 |
|
86 reportCompare(expect, actual, "ok"); |