Permalink
Browse files

timers, feat: Compatible with Nodejs' setTimeout function, the parame…

…ter timeout can be undefined. (#446)

* Compatible with Nodejs' setTimeout function, the parameter timeout can be undefined.

* format code

* format code

* 独立setTimeout缺省参数用例

* 修改idl文件

* 清理无用参数

* 修改参数长度判断,如果需要截取的长度超过参数总长度,取当前参数长度。
  • Loading branch information...
bengbengca authored and xicilion committed Jul 9, 2018
1 parent 7b1d7e2 commit 6a252e73512115c54f743b35c7feae034895d01f
@@ -229,10 +229,10 @@ inline void global_base::s_setTimeout(const v8::FunctionCallbackInfo<v8::Value>&
METHOD_NAME("global.setTimeout");
METHOD_ENTER();
METHOD_OVER(-1, 2);
METHOD_OVER(-1, 1);
ARG(v8::Local<v8::Function>, 0);
ARG(double, 1);
OPT_ARG(double, 1, 1);
ARG_LIST(2);
hr = setTimeout(v0, v1, v2, vr);
@@ -88,10 +88,10 @@ inline void timers_base::s_setTimeout(const v8::FunctionCallbackInfo<v8::Value>&
METHOD_NAME("timers.setTimeout");
METHOD_ENTER();
METHOD_OVER(-1, 2);
METHOD_OVER(-1, 1);
ARG(v8::Local<v8::Function>, 0);
ARG(double, 1);
OPT_ARG(double, 1, 1);
ARG_LIST(2);
hr = setTimeout(v0, v1, v2, vr);
View
@@ -680,6 +680,8 @@ class OptArgs {
, m_base(base)
, m_argc(argc)
{
if (m_base > m_argc)
m_base = m_argc;
}
OptArgs(const OptArgs& a)
View
@@ -84,7 +84,7 @@ module global
@param args Optional arguments to pass when the callback is called.
@return The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout(); this value can be passed to clearTimeout() to cancel the timeout.
*/
static Timer setTimeout(Function callback, Number timeout, ...args);
static Timer setTimeout(Function callback, Number timeout = 1, ...args);
/*! @brief run a callback function immediately after the browser has completed other operations such as events and display updates.
@param callback the function you wish to call.
View
@@ -30,7 +30,7 @@ module timers
@param args Optional arguments to pass when the callback is called.
@return The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout(); this value can be passed to clearTimeout() to cancel the timeout.
*/
static Timer setTimeout(Function callback, Number timeout, ...args);
static Timer setTimeout(Function callback, Number timeout = 1, ...args);
/*! @brief run a callback function immediately after the browser has completed other operations such as events and display updates.
@param callback the function you wish to call.
View
@@ -103,7 +103,7 @@ module global
@param args 额外的参数,传入到指定的 callback 内,可选。
@return 返回定时器对象
*/
static Timer setTimeout(Function callback, Number timeout, ...args);
static Timer setTimeout(Function callback, Number timeout = 1, ...args);
/*! @brief 清除指定的定时器
@param t 指定要清除的定时器
View
@@ -7,7 +7,7 @@ module timers
@param args 额外的参数,传入到指定的 callback 内,可选。
@return 返回定时器对象
*/
static Timer setTimeout(Function callback, Number timeout, ...args);
static Timer setTimeout(Function callback, Number timeout = 1, ...args);
/*! @brief 清除指定的定时器
@param t 指定要清除的定时器
View
@@ -9,6 +9,45 @@ var timers = require("timers");
var os = require("os");
describe("timer", () => {
describe("setTimeout undefined timeout", () => {
function test(setTimeout) {
var n = 0;
GC();
var no1 = test_util.countObject('Timer');
var t = setTimeout(() => n = 1);
GC();
var no2 = test_util.countObject('Timer');
assert.equal(no1 + 1, no2);
assert.equal(n, 0);
for (var i = 0; i < 1000 && n == 0; i++)
coroutine.sleep(10);
assert.equal(n, 1);
assert.isTrue(t.stopped);
t = undefined;
GC();
no2 = test_util.countObject('Timer');
assert.equal(no1, no2);
}
it("global setTimeout", () => {
test(setTimeout);
});
it("global.setTimeout", () => {
test(global.setTimeout);
});
it("timers.setTimeout", () => {
test(timers.setTimeout);
});
});
describe("setTimeout/clearTimeout", () => {
function test(setTimeout, clearTimeout) {
var n = 0;

0 comments on commit 6a252e7

Please sign in to comment.