Permalink
Browse files

timers, feat: process script error in timeout function.

  • Loading branch information...
xicilion committed Aug 14, 2018
1 parent 05e7995 commit 56806cddb15f062d08b673dc8b60d77968199e86
Showing with 14 additions and 16 deletions.
  1. +5 −15 fibjs/include/Timer.h
  2. +1 −1 fibjs/src/global/timeout.cpp
  3. +8 −0 test/timer_test.js
View
@@ -255,26 +255,16 @@ class TimeoutScope {
{
m_timer->clear();
if (hr < 0 || try_catch.HasCaught()) {
if (this_fiber->m_termed) {
try_catch.Reset();
this_fiber->m_termed = false;
m_isolate->m_isolate->CancelTerminateExecution();
return CHECK_ERROR(CALL_E_TIMEOUT);
} else {
if (hr < 0)
return hr;
try_catch.ReThrow();
return CHECK_ERROR(CALL_E_JAVASCRIPT);
}
if (this_fiber->m_termed) {
this_fiber->m_termed = false;
m_isolate->m_isolate->CancelTerminateExecution();
return CHECK_ERROR(CALL_E_TIMEOUT);
}
return 0;
return hr;
}
public:
TryCatch try_catch;
Isolate* m_isolate;
obj_ptr<JSFiber> this_fiber;
obj_ptr<JSTimer> m_timer;
@@ -19,6 +19,6 @@ result_t timers_base::call(v8::Local<v8::Function> func, double timeout,
TimeoutScope ts(timeout);
retVal = func->Call(v8::Undefined(ts.m_isolate->m_isolate), (int32_t)argv.size(), argv.data());
return ts.result();
return ts.result(retVal.IsEmpty() ? CALL_E_JAVASCRIPT : 0);
}
}
View
@@ -446,6 +446,10 @@ describe("timer", () => {
coroutine.sleep(100);
}
function test3() {
throw Error(100);
}
var t1 = new Date();
assert.throws(() => {
timers.call(test1, 30);
@@ -461,6 +465,10 @@ describe("timer", () => {
var t2 = new Date();
assert.greaterThan(t2 - t1, 90);
assert.lessThan(t2 - t1, 150);
assert.throws(() => {
timers.call(test3, 30);
});
});
});

0 comments on commit 56806cd

Please sign in to comment.