Last active
August 29, 2015 13:57
-
-
Save IgnoredAmbience/9738403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script type="text/javascript" src="this.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof global === 'undefined') { | |
if (typeof window !== 'undefined') { | |
global = window; | |
} else { | |
// Assumes this is bound to global object in default scope | |
global = this; | |
} | |
} | |
if (typeof console === 'undefined') { | |
console = {}; | |
// Assume print function provided by minimal environment | |
console.log = print; | |
} | |
function assert(expr, error) { | |
if(!expr) { | |
console.log(error); | |
} | |
} | |
assert(false, "starting tests"); | |
(function() { | |
var f = function() { | |
var t = this; | |
return t; | |
} | |
var o = {fun: f}; | |
global.myFunction = f; | |
var g = function() { | |
"use strict"; | |
var t = this; | |
return t; | |
} | |
var p = {fun: g}; | |
global.myOtherFunction = g; | |
var wo = {w: "wo"}; | |
// f on environment record | |
assert(f() === global, "non-strict mode, no-receiver did not return global object"); | |
// method call | |
assert(o.fun() === o, "non-strict mode, o was not receiver"); | |
// global method call | |
assert(global.myFunction() === global, "non-strict mode, global was not receiver"); | |
// myFunction on global object in var store | |
assert(myFunction() === global, "non-strict mode, no-receiver function call on global object did not return global"); | |
// g on environment record | |
assert(g() === undefined, "strict mode, no-receiver was not undefined"); | |
// method call | |
assert(p.fun() === p, "strict mode, p was not receiver"); | |
// global method call | |
assert(global.myOtherFunction() === global, "strict mode, global was not receiver"); | |
// myOtherFunction on global object in var store | |
assert(myOtherFunction() === undefined, "strict mode, no-receiver function call on global object, receiver was not undefined"); | |
with(wo) { | |
assert(myOtherFunction() === undefined, "with"); | |
} | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment