2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2014-09-04 18:02:04 +02:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var domain = require('domain');
|
|
|
|
|
|
|
|
var implementations = [
|
2015-05-19 13:00:06 +02:00
|
|
|
function(fn) {
|
2014-09-04 18:02:04 +02:00
|
|
|
Promise.resolve().then(fn);
|
|
|
|
},
|
2015-05-19 13:00:06 +02:00
|
|
|
function(fn) {
|
2014-09-04 18:02:04 +02:00
|
|
|
var obj = {};
|
|
|
|
|
|
|
|
Object.observe(obj, fn);
|
|
|
|
|
|
|
|
obj.a = 1;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var expected = 0;
|
|
|
|
var done = 0;
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
process.on('exit', function() {
|
2014-09-04 18:02:04 +02:00
|
|
|
assert.equal(done, expected);
|
|
|
|
});
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
function test(scheduleMicrotask) {
|
2014-09-04 18:02:04 +02:00
|
|
|
var nextTickCalled = false;
|
|
|
|
expected++;
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
scheduleMicrotask(function() {
|
|
|
|
process.nextTick(function() {
|
2014-09-04 18:02:04 +02:00
|
|
|
nextTickCalled = true;
|
|
|
|
});
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
setTimeout(function() {
|
2014-09-04 18:02:04 +02:00
|
|
|
assert(nextTickCalled);
|
|
|
|
done++;
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// first tick case
|
|
|
|
implementations.forEach(test);
|
|
|
|
|
|
|
|
// tick callback case
|
2015-05-19 13:00:06 +02:00
|
|
|
setTimeout(function() {
|
|
|
|
implementations.forEach(function(impl) {
|
2014-09-04 18:02:04 +02:00
|
|
|
process.nextTick(test.bind(null, impl));
|
|
|
|
});
|
|
|
|
}, 0);
|