如果我在 V8 中新建一个没有 HandleScope 的 Local<Value> 会怎样?

what would happen if I new a Local<Value> without a HandleScope in 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 {

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

关于 "check_api_usage" 之类的事情。

这条消息我已经看过太多次了。

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