Comparing version 0.11.8 to 0.11.9
@@ -12,16 +12,26 @@ // shim for using process in browser | ||
function defaultSetTimout() { | ||
throw new Error('setTimeout has not been defined'); | ||
} | ||
function defaultClearTimeout () { | ||
throw new Error('clearTimeout has not been defined'); | ||
} | ||
(function () { | ||
try { | ||
cachedSetTimeout = setTimeout; | ||
if (typeof setTimeout === 'function') { | ||
cachedSetTimeout = setTimeout; | ||
} else { | ||
cachedSetTimeout = defaultSetTimout; | ||
} | ||
} catch (e) { | ||
cachedSetTimeout = function () { | ||
throw new Error('setTimeout is not defined'); | ||
} | ||
cachedSetTimeout = defaultSetTimout; | ||
} | ||
try { | ||
cachedClearTimeout = clearTimeout; | ||
if (typeof clearTimeout === 'function') { | ||
cachedClearTimeout = clearTimeout; | ||
} else { | ||
cachedClearTimeout = defaultClearTimeout; | ||
} | ||
} catch (e) { | ||
cachedClearTimeout = function () { | ||
throw new Error('clearTimeout is not defined'); | ||
} | ||
cachedClearTimeout = defaultClearTimeout; | ||
} | ||
@@ -34,2 +44,7 @@ } ()) | ||
} | ||
// if setTimeout wasn't available but was latter defined | ||
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { | ||
cachedSetTimeout = setTimeout; | ||
return setTimeout(fun, 0); | ||
} | ||
try { | ||
@@ -55,2 +70,7 @@ // when when somebody has screwed with setTimeout but no I.E. maddness | ||
} | ||
// if clearTimeout wasn't available but was latter defined | ||
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { | ||
cachedClearTimeout = clearTimeout; | ||
return clearTimeout(marker); | ||
} | ||
try { | ||
@@ -57,0 +77,0 @@ // when when somebody has screwed with setTimeout but no I.E. maddness |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "0.11.8", | ||
"version": "0.11.9", | ||
"repository": { | ||
@@ -15,0 +15,0 @@ "type": "git", |
57
test.js
@@ -13,3 +13,3 @@ var assert = require('assert'); | ||
function test (ourProcess) { | ||
describe('test arguments', function (t) { | ||
describe('test arguments', function () { | ||
it ('works', function (done) { | ||
@@ -80,5 +80,3 @@ var order = 0; | ||
var ran = false; | ||
console.log('clear timeout start'); | ||
function cleanup() { | ||
console.log('seccond'); | ||
clearTimeout = oldClear; | ||
@@ -96,3 +94,2 @@ var err; | ||
ourProcess.nextTick(function () { | ||
console.log('first'); | ||
ran = true; | ||
@@ -152,3 +149,55 @@ }); | ||
}); | ||
it('should generally work', function (done) { | ||
var str = '"use strict";var module = {exports:{}};'; | ||
str += process; | ||
str += 'process.nextTick(function () {assert.ok(true);done();})'; | ||
var script = new vm.Script(str); | ||
var context = { | ||
clearTimeout: clearTimeout, | ||
setTimeout: setTimeout, | ||
done: done, | ||
assert: assert | ||
}; | ||
script.runInNewContext(context); | ||
}); | ||
it('late defs setTimeout', function (done) { | ||
var str = '"use strict";var module = {exports:{}};'; | ||
str += process; | ||
str += 'var setTimeout = hiddenSetTimeout;process.nextTick(function () {assert.ok(true);done();})'; | ||
var script = new vm.Script(str); | ||
var context = { | ||
clearTimeout: clearTimeout, | ||
hiddenSetTimeout: setTimeout, | ||
done: done, | ||
assert: assert | ||
}; | ||
script.runInNewContext(context); | ||
}); | ||
it('late defs clearTimeout', function (done) { | ||
var str = '"use strict";var module = {exports:{}};'; | ||
str += process; | ||
str += 'var clearTimeout = hiddenClearTimeout;process.nextTick(function () {assert.ok(true);done();})'; | ||
var script = new vm.Script(str); | ||
var context = { | ||
hiddenClearTimeout: clearTimeout, | ||
setTimeout: setTimeout, | ||
done: done, | ||
assert: assert | ||
}; | ||
script.runInNewContext(context); | ||
}); | ||
it('late defs setTimeout and then redefine', function (done) { | ||
var str = '"use strict";var module = {exports:{}};'; | ||
str += process; | ||
str += 'var setTimeout = hiddenSetTimeout;process.nextTick(function () {setTimeout = function (){throw new Error("foo")};hiddenSetTimeout(function(){process.nextTick(function (){assert.ok(true);done();});});});'; | ||
var script = new vm.Script(str); | ||
var context = { | ||
clearTimeout: clearTimeout, | ||
hiddenSetTimeout: setTimeout, | ||
done: done, | ||
assert: assert | ||
}; | ||
script.runInNewContext(context); | ||
}); | ||
}); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15205
7
353