| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dba8d20 commit 0a2fb0d
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ function range(n) { | |||
| 7 | 7 | } | |
| 8 | 8 | ||
| 9 | 9 | function timeout(nargs) { | |
| 10 | - var args = range(nargs); | ||
| 10 | + const args = range(nargs); | ||
| 11 | 11 | setTimeout.apply(null, [callback, 1].concat(args)); | |
| 12 | 12 | ||
| 13 | 13 | function callback() { | |
@@ -17,8 +17,8 @@ function timeout(nargs) { | |||
| 17 | 17 | } | |
| 18 | 18 | ||
| 19 | 19 | function interval(nargs) { | |
| 20 | - var args = range(nargs); | ||
| 21 | - var timer = setTimeout.apply(null, [callback, 1].concat(args)); | ||
| 20 | + const args = range(nargs); | ||
| 21 | + const timer = setTimeout.apply(null, [callback, 1].concat(args)); | ||
| 22 | 22 | ||
| 23 | 23 | function callback() { | |
| 24 | 24 | clearInterval(timer); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,15 +6,13 @@ const assert = require('assert'); | |||
| 6 | 6 | // but immediates queued while processing the current queue should happen | |
| 7 | 7 | // on the next turn of the event loop. | |
| 8 | 8 | ||
| 9 | - // in v0.10 hit should be 1, because we only process one cb per turn | ||
| 10 | - // in v0.11 and beyond it should be the exact same size of QUEUE | ||
| 11 | - // if we're letting things recursively add to the immediate QUEUE hit will be | ||
| 12 | - // > QUEUE | ||
| 9 | + // hit should be the exact same size of QUEUE, if we're letting things | ||
| 10 | + // recursively add to the immediate QUEUE hit will be > QUEUE | ||
| 13 | 11 | ||
| 14 | - var ticked = false; | ||
| 12 | + let ticked = false; | ||
| 15 | 13 | ||
| 16 | - var hit = 0; | ||
| 17 | - var QUEUE = 1000; | ||
| 14 | + let hit = 0; | ||
| 15 | + const QUEUE = 1000; | ||
| 18 | 16 | ||
| 19 | 17 | function run() { | |
| 20 | 18 | if (hit === 0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | + require('../common'); | ||
| 3 | + | ||
| 2 | 4 | /* | |
| 3 | 5 | * This test makes sure that non-integer timer delays do not make the process | |
| 4 | 6 | * hang. See https://github.com/joyent/node/issues/8065 and | |
@@ -15,13 +17,11 @@ | |||
| 15 | 17 | * it 100%. | |
| 16 | 18 | */ | |
| 17 | 19 | ||
| 18 | - require('../common'); | ||
| 19 | - | ||
| 20 | - var TIMEOUT_DELAY = 1.1; | ||
| 21 | - var NB_TIMEOUTS_FIRED = 50; | ||
| 20 | + const TIMEOUT_DELAY = 1.1; | ||
| 21 | + const NB_TIMEOUTS_FIRED = 50; | ||
| 22 | 22 | ||
| 23 | - var nbTimeoutFired = 0; | ||
| 24 | - var interval = setInterval(function() { | ||
| 23 | + let nbTimeoutFired = 0; | ||
| 24 | + const interval = setInterval(function() { | ||
| 25 | 25 | ++nbTimeoutFired; | |
| 26 | 26 | if (nbTimeoutFired === NB_TIMEOUTS_FIRED) { | |
| 27 | 27 | clearInterval(interval); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,22 +1,22 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | require('../common'); | |
| 3 | 3 | const assert = require('assert'); | |
| 4 | - var Timer = process.binding('timer_wrap').Timer; | ||
| 5 | 4 | ||
| 6 | - var N = 30; | ||
| 5 | + const Timer = process.binding('timer_wrap').Timer; | ||
| 6 | + const N = 30; | ||
| 7 | 7 | ||
| 8 | - var last_i = 0; | ||
| 9 | - var last_ts = 0; | ||
| 8 | + let last_i = 0; | ||
| 9 | + let last_ts = 0; | ||
| 10 | 10 | ||
| 11 | - var f = function(i) { | ||
| 11 | + const f = function(i) { | ||
| 12 | 12 | if (i <= N) { | |
| 13 | 13 | // check order | |
| 14 | - assert.equal(i, last_i + 1, 'order is broken: ' + i + ' != ' + | ||
| 14 | + assert.strictEqual(i, last_i + 1, 'order is broken: ' + i + ' != ' + | ||
| 15 | 15 | last_i + ' + 1'); | |
| 16 | 16 | last_i = i; | |
| 17 | 17 | ||
| 18 | 18 | // check that this iteration is fired at least 1ms later than the previous | |
| 19 | - var now = Timer.now(); | ||
| 19 | + const now = Timer.now(); | ||
| 20 | 20 | console.log(i, now); | |
| 21 | 21 | assert(now >= last_ts + 1, | |
| 22 | 22 | 'current ts ' + now + ' < prev ts ' + last_ts + ' + 1'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,40 +1,18 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | - | ||
| 5 | - var exceptions = 0; | ||
| 6 | - var timer1 = 0; | ||
| 7 | - var timer2 = 0; | ||
| 4 | + const errorMsg = 'BAM!'; | ||
| 8 | 5 | ||
| 9 | 6 | // the first timer throws... | |
| 10 | - console.error('set first timer'); | ||
| 11 | - setTimeout(function() { | ||
| 12 | - console.error('first timer'); | ||
| 13 | - timer1++; | ||
| 14 | - throw new Error('BAM!'); | ||
| 15 | - }, 100); | ||
| 7 | + setTimeout(common.mustCall(function() { | ||
| 8 | + throw new Error(errorMsg); | ||
| 9 | + }), 1); | ||
| 16 | 10 | ||
| 17 | 11 | // ...but the second one should still run | |
| 18 | - console.error('set second timer'); | ||
| 19 | - setTimeout(function() { | ||
| 20 | - console.error('second timer'); | ||
| 21 | - assert.equal(timer1, 1); | ||
| 22 | - timer2++; | ||
| 23 | - }, 100); | ||
| 12 | + setTimeout(common.mustCall(function() {}), 1); | ||
| 24 | 13 | ||
| 25 | 14 | function uncaughtException(err) { | |
| 26 | - console.error('uncaught handler'); | ||
| 27 | - assert.equal(err.message, 'BAM!'); | ||
| 28 | - exceptions++; | ||
| 15 | + assert.strictEqual(err.message, errorMsg); | ||
| 29 | 16 | } | |
| 30 | - process.on('uncaughtException', uncaughtException); | ||
| 31 | 17 | ||
| 32 | - var exited = false; | ||
| 33 | - process.on('exit', function() { | ||
| 34 | - assert(!exited); | ||
| 35 | - exited = true; | ||
| 36 | - process.removeListener('uncaughtException', uncaughtException); | ||
| 37 | - assert.equal(exceptions, 1); | ||
| 38 | - assert.equal(timer1, 1); | ||
| 39 | - assert.equal(timer2, 1); | ||
| 40 | - }); | ||
| 18 | + process.on('uncaughtException', common.mustCall(uncaughtException)); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments