当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - Interrupt execution of v8 script inside native function

问题描述:

I use v8 and spidermonkey from C++ programs. In spidermonkey it is easy to stop the execution, you just return FALSE in any of native methods you implemented in C++.

But I fail to see how to do the same thing in v8.

Handle<Value> enough(const v8::Arguments& a) {

// want to tell v8, that execution is not needed to continue.

return v8::Undefined();

}

maybe return something specific, or set some variable, or call v8 function, or send a message, or throw and exception, any idea?

网友答案:

I am not exactly sure what do you mean by "interrupt" in this case.. But I will give it a shot with my answer:

You can either return a value from your C++ function early on (return v8::False()) to skip execution of other code inside the same function or throw a JavaScript exception with v8::ThrowException(...).

And you can use the v8::V8::TerminateExecution(). This will terminate the execution in current isolate/thread. The way v8 does that is by throwing an uncatchable exception (in JavaScript land). You can still use the v8::TryCatch to handle the termination from your C++ code.

分享给朋友:
您可能感兴趣的文章:
随机阅读: