Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1518 from platinumazure/close-over-settimeout
Avoid issues caused by clobbering of global setTimeout
- Loading branch information
Showing
4 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(function (global) { | ||
// Store local setTimeout reference for monkey-patching DOH | ||
var localSetTimeout = global.setTimeout; | ||
|
||
// Clobber setTimeout to ensure that the below require() still works... | ||
global.setTimeout = null; | ||
|
||
// ...but ensure doh.setTimeout does not get broken | ||
doh.setTimeout = function (fn, delay) { | ||
return localSetTimeout.call(global, fn, delay); | ||
}; | ||
|
||
require({ baseUrl: "./" }, ["simple"], function(simple) { | ||
doh.register( | ||
"setTimeout", | ||
[ | ||
function checkSetTimeout(t){ | ||
t.is("blue", simple.color); | ||
} | ||
] | ||
); | ||
|
||
doh.run(); | ||
}); | ||
})(this); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>require.js: setTimeout Test</title> | ||
<script type="text/javascript" src="../require.js"></script> | ||
<script type="text/javascript" src="doh/runner.js"></script> | ||
<script type="text/javascript" src="doh/_browserRunner.js"></script> | ||
<script type="text/javascript" src="setTimeout-tests.js"></script> | ||
</head> | ||
<body> | ||
<h1>require.js: setTimeout Test</h1> | ||
<p>Check console for messages</p> | ||
</body> | ||
</html> |