blob: 8440fd7e0437054074898f5ebc48dad27b97718f [file] [log] [blame]
<p>
This page tests var declarations that attempt to shadow interesting global properties in
interesting ways. <a href="http://bugs.webkit.org/show_bug.cgi?id=16644">Bug 16644</a>.
</p>
<p>
If the test passes, you'll see a series of PASS messages below.
</p>
<pre id="console"></pre>
<script>
if (window.testRunner)
testRunner.dumpAsText();
function log(s)
{
document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
}
function shouldBe(a, aDescription, b)
{
if (a == b) {
log("PASS: " + aDescription + " should be " + b + " and is.");
} else {
log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
}
}
var marker = { };
var Node; // shadow existing property of the global object
eval("var Element;"); // ditto, but using eval
var toString; // shadow existing property of the global object's prototype
eval("var valueOf;"); // ditto, but using eval
shouldBe(Node == undefined, "Node == undefined", false);
shouldBe(eval('Node == undefined'), "eval('Node == undefined')", false);
shouldBe(Element == undefined, "Element == undefined", false);
shouldBe(eval('Element == undefined'), "eval('Element == undefined')", false);
shouldBe(toString == undefined, "toString == undefined", false);
shouldBe(eval('toString == undefined'), "eval('toString == undefined')", false);
shouldBe(valueOf == undefined, "valueOf == undefined", false);
shouldBe(eval('valueOf == undefined'), "eval('valueOf == undefined')", false);
log("-----");
// Repeat the tests above, this time explicitly overwriting existing properties
var HTMLElement = marker;
eval("var HTMLLinkElement = marker;");
var moveBy = marker;
eval("var find = marker;");
shouldBe(HTMLElement == marker, "HTMLElement == marker", true);
shouldBe(eval('HTMLElement == marker'), "eval('HTMLElement == marker')", true);
shouldBe(HTMLLinkElement == marker, "HTMLLinkElement == marker", true);
shouldBe(eval('HTMLLinkElement == marker'), "eval('HTMLLinkElement == marker')", true);
shouldBe(moveBy == marker, "moveBy == marker", true);
shouldBe(eval('moveBy == marker'), "eval('moveBy == marker')", true);
shouldBe(find == marker, "find == marker", true);
shouldBe(eval('find == marker'), "eval('find == marker')", true);
log("-----");
// Various variable names that are, or at one point were, unsettable in WebKit.
try {
eval("var locationbar = marker");
} catch(e) { }
shouldBe(locationbar == marker, "locationbar == marker", true);
shouldBe(eval('locationbar == marker'), "eval('locationbar == marker')", true);
try {
eval("var menubar = marker");
} catch(e) { }
shouldBe(menubar == marker, "menubar == marker", true);
shouldBe(eval('menubar == marker'), "eval('menubar == marker')", true);
try {
eval("var personalbar = marker");
} catch(e) { }
shouldBe(personalbar == marker, "personalbar == marker", true);
shouldBe(eval('personalbar == marker'), "eval('personalbar == marker')", true);
try {
eval("var scrollbars = marker");
} catch(e) { }
shouldBe(scrollbars == marker, "scrollbars == marker", true);
shouldBe(eval('scrollbars == marker'), "eval('scrollbars == marker')", true);
try {
eval("var statusbar = marker");
} catch(e) { }
shouldBe(statusbar == marker, "statusbar == marker", true);
shouldBe(eval('statusbar == marker'), "eval('statusbar == marker')", true);
try {
eval("var toolbar = marker");
} catch(e) { }
shouldBe(toolbar == marker, "toolbar == marker", true);
shouldBe(eval('toolbar == marker'), "eval('toolbar == marker')", true);
try {
eval("var offscreenBuffering = marker");
} catch(e) { }
shouldBe(offscreenBuffering == marker, "offscreenBuffering == marker", true);
shouldBe(eval('offscreenBuffering == marker'), "eval('offscreenBuffering == marker')", true);
try {
eval("var outerHeight = marker");
} catch(e) { }
shouldBe(outerHeight == marker, "outerHeight == marker", true);
shouldBe(eval('outerHeight == marker'), "eval('outerHeight == marker')", true);
try {
eval("var outerWidth = marker");
} catch(e) { }
shouldBe(outerWidth == marker, "outerWidth == marker", true);
shouldBe(eval('outerWidth == marker'), "eval('outerWidth == marker')", true);
try {
eval("var innerHeight = marker");
} catch(e) { }
shouldBe(innerHeight == marker, "innerHeight == marker", true);
shouldBe(eval('innerHeight == marker'), "eval('innerHeight == marker')", true);
try {
eval("var innerWidth = marker");
} catch(e) { }
shouldBe(innerWidth == marker, "innerWidth == marker", true);
shouldBe(eval('innerWidth == marker'), "eval('innerWidth == marker')", true);
try {
eval("var screenX = marker");
} catch(e) { }
shouldBe(screenX == marker, "screenX == marker", true);
shouldBe(eval('screenX == marker'), "eval('screenX == marker')", true);
try {
eval("var screenY = marker");
} catch(e) { }
shouldBe(screenY == marker, "screenY == marker", true);
shouldBe(eval('screenY == marker'), "eval('screenY == marker')", true);
try {
eval("var screenLeft = marker");
} catch(e) { }
shouldBe(screenLeft == marker, "screenLeft == marker", true);
shouldBe(eval('screenLeft == marker'), "eval('screenLeft == marker')", true);
try {
eval("var screenTop = marker");
} catch(e) { }
shouldBe(screenTop == marker, "screenTop == marker", true);
shouldBe(eval('screenTop == marker'), "eval('screenTop == marker')", true);
try {
eval("var scrollX = marker");
} catch(e) { }
shouldBe(scrollX == marker, "scrollX == marker", true);
shouldBe(eval('scrollX == marker'), "eval('scrollX == marker')", true);
try {
eval("var scrollY = marker");
} catch(e) { }
shouldBe(scrollY == marker, "scrollY == marker", true);
shouldBe(eval('scrollY == marker'), "eval('scrollY == marker')", true);
try {
eval("var length = marker");
} catch(e) { }
shouldBe(length == marker, "length == marker", true);
shouldBe(eval('length == marker'), "eval('length == marker')", true);
try {
eval("var self = marker");
} catch(e) { }
shouldBe(self == marker, "self == marker", true);
shouldBe(eval('self == marker'), "eval('self == marker')", true);
try {
eval("var frames = marker");
} catch(e) { }
shouldBe(frames == marker, "frames == marker", true);
shouldBe(eval('frames == marker'), "eval('frames == marker')", true);
try {
eval("var opener = marker");
} catch(e) { }
shouldBe(opener == marker, "opener == marker", true);
shouldBe(eval('opener == marker'), "eval('opener == marker')", true);
try {
eval("var parent = marker");
} catch(e) { }
shouldBe(parent == marker, "parent == marker", true);
shouldBe(eval('parent == marker'), "eval('parent == marker')", true);
try {
eval("var devicePixelRatio = marker");
} catch(e) { }
shouldBe(devicePixelRatio == marker, "devicePixelRatio == marker", true);
shouldBe(eval('devicePixelRatio == marker'), "eval('devicePixelRatio == marker')", true);
try {
eval("var devicePixelRatio = marker");
} catch(e) { }
shouldBe(devicePixelRatio == marker, "devicePixelRatio == marker", true);
shouldBe(eval('devicePixelRatio == marker'), "eval('devicePixelRatio == marker')", true);
try {
eval("var navigator = marker");
} catch(e) { }
shouldBe(navigator == marker, "navigator == marker", true);
shouldBe(eval('navigator == marker'), "eval('navigator == marker')", true);
try {
eval("var clientInformation = marker");
} catch(e) { }
shouldBe(clientInformation == marker, "clientInformation == marker", true);
shouldBe(eval('clientInformation == marker'), "eval('clientInformation == marker')", true);
try {
eval("var status = marker");
} catch(e) { }
shouldBe(status == marker, "status == marker", true);
shouldBe(eval('status == marker'), "eval('status == marker')", true);
try {
eval("var defaultStatus = marker");
} catch(e) { }
shouldBe(defaultStatus == marker, "defaultStatus == marker", true);
shouldBe(eval('defaultStatus == marker'), "eval('defaultStatus == marker')", true);
try {
eval("var defaultstatus = marker");
} catch(e) { }
shouldBe(defaultstatus == marker, "defaultstatus == marker", true);
shouldBe(eval('defaultstatus == marker'), "eval('defaultstatus == marker')", true);
try {
eval("var screen = marker");
} catch(e) { }
shouldBe(screen == marker, "screen == marker", true);
shouldBe(eval('screen == marker'), "eval('screen == marker')", true);
try {
eval("var history = marker");
} catch(e) { }
shouldBe(history == marker, "history == marker", true);
shouldBe(eval('history == marker'), "eval('history == marker')", true);
log("-----");
try {
eval("var frameElement = marker");
} catch(e) { }
shouldBe(frameElement == marker, "frameElement == marker", false);
shouldBe(eval('frameElement == marker'), "eval('frameElement == marker')", false);
try {
eval("var pageXOffset = marker");
} catch(e) { }
shouldBe(pageXOffset == marker, "pageXOffset == marker", false);
shouldBe(eval('pageXOffset == marker'), "eval('pageXOffset == marker')", false);
try {
eval("var pageYOffset = marker");
} catch(e) { }
shouldBe(pageYOffset == marker, "pageYOffset == marker", false);
shouldBe(eval('pageYOffset == marker'), "eval('pageYOffset == marker')", false);
try {
eval("var closed = marker");
} catch(e) { }
shouldBe(closed == marker, "closed == marker", false);
shouldBe(eval('closed == marker'), "eval('closed == marker')", false);
try {
eval("var window = marker");
} catch(e) { }
shouldBe(window == marker, "window == marker", false);
shouldBe(eval('window == marker'), "eval('window == marker')", false);
try {
eval("var document = marker");
} catch(e) { }
shouldBe(document == marker, "document == marker", false);
shouldBe(eval('document == marker'), "eval('document == marker')", false);
try {
eval("var crypto = marker");
} catch(e) { }
shouldBe(crypto == marker, "crypto == marker", false);
shouldBe(eval('crypto == marker'), "eval('crypto == marker')", false);
try {
eval("var top = marker");
} catch(e) { }
shouldBe(top == marker, "top == marker", false);
shouldBe(eval('top == marker'), "eval('top == marker')", false);
</script>