-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
timers: fixing API refs to use safe internal refs #2500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||||||||||
| 'use strict'; | ||||||||||||||
| const common = require('../common'); | ||||||||||||||
| const assert = require('assert'); | ||||||||||||||
|
|
||||||||||||||
| // don't verify the globals for this test | ||||||||||||||
| common.globalCheck = false; | ||||||||||||||
|
|
||||||||||||||
| // try overriding global APIs to make sure | ||||||||||||||
| // they're not relied on by the timers | ||||||||||||||
| global.clearTimeout = assert.fail; | ||||||||||||||
|
||||||||||||||
| global.clearImmediate = timers.clearImmediate; | |
| global.clearInterval = timers.clearInterval; | |
| global.clearTimeout = timers.clearTimeout; | |
| global.setImmediate = timers.setImmediate; | |
| global.setInterval = timers.setInterval; | |
| global.setTimeout = timers.setTimeout; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clearTimeout(..), unenroll(..) and active(..) are the only methods that are called from the code itself, which means they are the only ones that could break code if allowed to be overwritten without a safe internal reference. That's why I went the conservative route.
We could apply the fix to all API methods, but if they aren't being called, it seems like unnecessary extra code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking about it and I think it would be best to only do this for the globals, so only
clearTimeoutin this patch. (Plus we also don't test active/{un}enroll and there's not a terribly good reason to.