-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
timers: fixing API refs to use safe internal refs #5882
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,21 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const timers = require('timers'); | ||
|
|
||
| // don't verify the globals for this test | ||
| common.globalCheck = false; | ||
| // delete global APIs to make sure they're not relied on by the internal timers | ||
| // code | ||
| delete global.setTimeout; | ||
| delete global.clearTimeout; | ||
| delete global.setInterval; | ||
| delete global.clearInterval; | ||
| delete global.setImmediate; | ||
| delete global.clearImmediate; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've also changed
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that if you override |
||
|
|
||
| // try overriding global APIs to make sure | ||
| // they're not relied on by the timers | ||
| global.clearTimeout = assert.fail; | ||
| const timeoutCallback = () => { timers.clearTimeout(timeout); }; | ||
| const timeout = timers.setTimeout(common.mustCall(timeoutCallback), 1); | ||
|
|
||
| // run timeouts/intervals through the paces | ||
| const intv = setInterval(function() {}, 1); | ||
|
|
||
| setTimeout(function() { | ||
| clearInterval(intv); | ||
| }, 100); | ||
|
|
||
| setTimeout(function() {}, 2); | ||
| const intervalCallback = () => { timers.clearInterval(interval); }; | ||
| const interval = timers.setInterval(common.mustCall(intervalCallback), 1); | ||
|
|
||
| const immediateCallback = () => { timers.clearImmediate(immediate); }; | ||
| const immediate = timers.setImmediate(immediateCallback); | ||
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.
is this possible? IIRC from before, you couldn't actually manually load internal modules from user code like tests.
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.
Already appears in five other tests!
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.
(Also: Yeah, it works. Test fails with a
ReferenceErrorin Node 5.9.1, as it should, and passes with your changes inlib/timers.js.)