mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
watchdog: terminate one specific isolate
This commit is contained in:
1 parent
d78a3787d2
commit
d5198768de
3 files changed
+14
-5
No files matched your search
@@ -646,14 +646,14 @@ class ContextifyScript : public BaseObject {
|
||||
|
||||
Local<Value> result;
|
||||
if (timeout != -1) {
|
||||
Watchdog wd(timeout);
|
||||
Watchdog wd(env, timeout);
|
||||
result = script->Run();
|
||||
} else {
|
||||
result = script->Run();
|
||||
}
|
||||
|
||||
if (try_catch.HasCaught() && try_catch.HasTerminated()) {
|
||||
V8::CancelTerminateExecution(args.GetIsolate());
|
||||
V8::CancelTerminateExecution(env->isolate());
|
||||
env->ThrowError("Script execution timed out.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include "node_watchdog.h"
|
||||
#include "env.h"
|
||||
#include "env-inl.h"
|
||||
#include "util.h"
|
||||
#include <assert.h>
|
||||
|
||||
@@ -28,7 +30,8 @@ namespace node {
|
||||
using v8::V8;
|
||||
|
||||
|
||||
Watchdog::Watchdog(uint64_t ms) : destroyed_(false) {
|
||||
Watchdog::Watchdog(Environment* env, uint64_t ms) : env_(env),
|
||||
destroyed_(false) {
|
||||
int rc;
|
||||
loop_ = new uv_loop_t;
|
||||
CHECK(loop_);
|
||||
@@ -98,7 +101,8 @@ void Watchdog::Async(uv_async_t* async) {
|
||||
|
||||
|
||||
void Watchdog::Timer(uv_timer_t* timer) {
|
||||
V8::TerminateExecution();
|
||||
Watchdog* w = ContainerOf(&Watchdog::timer_, timer);
|
||||
V8::TerminateExecution(w->env()->isolate());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+6
-1
@@ -25,15 +25,19 @@
|
||||
#include "v8.h"
|
||||
#include "uv.h"
|
||||
|
||||
#include "env.h"
|
||||
|
||||
namespace node {
|
||||
|
||||
class Watchdog {
|
||||
public:
|
||||
explicit Watchdog(uint64_t ms);
|
||||
explicit Watchdog(Environment* env, uint64_t ms);
|
||||
~Watchdog();
|
||||
|
||||
void Dispose();
|
||||
|
||||
inline Environment* env() const { return env_; }
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
|
||||
@@ -41,6 +45,7 @@ class Watchdog {
|
||||
static void Async(uv_async_t* async);
|
||||
static void Timer(uv_timer_t* timer);
|
||||
|
||||
Environment* env_;
|
||||
uv_thread_t thread_;
|
||||
uv_loop_t* loop_;
|
||||
uv_async_t async_;
|
||||
|
||||
Reference in new issue
Block a user