如果我在V8中没有HandleScope的情况下新建一个Local <值>,会发生什么?

时间:2016-04-08 02:13:43

标签: node.js v8

是允许的吗?或者如果我这样做会发生什么。 这个处理程序是不是由GC跟踪,还是由GC跟踪但未发布?

在v8.h:

 /**
 * A stack-allocated class that governs a number of local handles.
 * After a handle scope has been created, all local handles will be
 * allocated within that handle scope until either the handle scope is
 * deleted or another handle scope is created.  If there is already a
* handle scope and a new one is created, all allocations will take
* place in the new handle scope until it is deleted.  After that,
 * new handles will again be allocated in the original handle scope.
*
* After the handle scope of a local handle has been deleted the
* garbage collector will no longer track the object stored in the
* handle and may deallocate it.  The behavior of accessing a handle
* for which the handle scope has been deleted is undefined.
*/
class V8_EXPORT HandleScope {

1 个答案:

答案 0 :(得分:0)

V8爆炸了。如果您正在运行调试版本,您将收到更好的错误消息,但它会崩溃。

关于“check_api_usage”或类似的东西。

我已经看过很多次了。

如果您需要保持比词法范围更长的javascript值,则需要将其放入(更昂贵的)v8::Global<T>对象中。请注意,global是仅移动的,类似于unique_ptr。

相关问题