michael@0: // |reftest| skip-if(!xulRuntime.shell) michael@0: // Any copyright is dedicated to the Public Domain. michael@0: // http://creativecommons.org/licenses/publicdomain/ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 671947; michael@0: var summary = "Unqualified function invocation uses the global object of the called property as |this|"; michael@0: var actual = "------------------------"; michael@0: var expect = "ooaoboabuuaubuabooaoboab"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: this.name = "o"; michael@0: michael@0: function f() { michael@0: return this ? this.name : "t"; michael@0: } michael@0: function g() { michael@0: "use strict"; michael@0: return this ? this.name : "u"; michael@0: } michael@0: function h() { michael@0: return this ? this.name : "v"; michael@0: } michael@0: michael@0: var sb = newGlobal('same-compartment'); michael@0: sb.parent = this; michael@0: michael@0: evalcx('\n' + michael@0: ' this.name="i";\n' + michael@0: ' this.f = parent.f;\n' + michael@0: ' this.g = parent.g;\n' + michael@0: ' this.a = { name:"a", f:parent.f, g:parent.g };\n' + michael@0: ' this.b = { name:"b", f:parent.f, g:parent.g };\n' + michael@0: ' Object.defineProperty(this, "h", { get: (function(){ return parent.h; })});\n' + michael@0: ' Object.defineProperty(a, "h", { get: (function(){ return parent.h; })});\n' + michael@0: ' Object.defineProperty(b, "h", { get: (function(){ return parent.h; })});\n' + michael@0: michael@0: ' var results = "";\n' + michael@0: michael@0: ' /* Three of the first four cases pass undefined (promoted inside the callee to the callee\'s global object). */\n' + michael@0: ' /* a.f() is the one exception, which passes the base, a, as the this object. */\n' + michael@0: ' results += (function(){return f();})();\n' + michael@0: ' results += (function(){return (1,f)();})();\n' + michael@0: ' results += (function(){return a.f();})();\n' + michael@0: ' results += (function(){return eval("f()");})();\n' + michael@0: ' /* Same cases as above, but wrapped in a with. The first & last of these cases pass b, */\n' + michael@0: ' /* the object scoped by the with, as the this value. */\n' + michael@0: ' /* a.f() still passes the explicit base, a. (1,f)() is a little tricksier - this passes */\n' + michael@0: ' /* undefined (promoted to the callee global object) since the comma operator calles GetValue */\n' + michael@0: ' /* on the reference (see ES5 11.14.) */\n' + michael@0: ' results += (function(){with(b){ return (function(){ return f();})(); }})();\n' + michael@0: ' results += (function(){with(b){ return (function(){ return (1,f)();})(); }})();\n' + michael@0: ' results += (function(){with(b){ return (function(){ return a.f();})(); }})();\n' + michael@0: ' results += (function(){with(b){ return (function(){ return eval("f()");})(); }})();\n' + michael@0: michael@0: ' /* Same tests as above, but with a strict callee. */\n' + michael@0: ' /* We expect the same results, except undefined this is not replaced with the global object. */\n' + michael@0: ' results += (function(){return g();})();\n' + michael@0: ' results += (function(){return (1,g)();})();\n' + michael@0: ' results += (function(){return a.g();})();\n' + michael@0: ' results += (function(){return eval("g()");})();\n' + michael@0: ' results += (function(){with(b){ return g(); }})();\n' + michael@0: ' results += (function(){with(b){ return (1,g)(); }})();\n' + michael@0: ' results += (function(){with(b){ return a.g(); }})();\n' + michael@0: ' results += (function(){with(b){ return (function(){ return eval("g()");})(); }})();\n' + michael@0: michael@0: ' /* Same as the first set, but h is a getter property. */\n' + michael@0: ' results += (function(){return h();})();\n' + michael@0: ' results += (function(){return (1,h)();})();\n' + michael@0: ' results += (function(){return a.h();})();\n' + michael@0: ' results += (function(){return eval("h()");})();\n' + michael@0: ' results += (function(){with(b){ return h(); }})();\n' + michael@0: ' results += (function(){with(b){ return (1,h)(); }})();\n' + michael@0: ' results += (function(){with(b){ return a.h(); }})();\n' + michael@0: ' results += (function(){with(b){ return (function(){ return eval("h()");})(); }})();\n' + michael@0: michael@0: ' parent.actual = results;\n' + michael@0: '', michael@0: sb); michael@0: michael@0: reportCompare(expect, actual, "ok");