Hello World and V8

Hello World and V8

本文关键字:V8 and World Hello      更新时间:2023-10-16

我正在开发windows。我正在尝试使用undercorediscovery中的V8在V8中运行helloworld。这无法在行编译

// Get the default Isolate created at startup.
  Isolate* isolate = Isolate::GetCurrent();

我查看了undercorediscovery标头,当这个类不在标头中时,它确实有旧的lib和标头。那很好。我删除了这条线路,用替换了前四条线路

  // Create a stack-allocated handle scope.
  HandleScope handle_scope;
  // Create a new context.
  Handle<Context> context = Context::New();
  // Here's how you could create a Persistent handle to the context, if needed.
  Persistent<Context> persistent_context(context);

它奏效了。所以这个隔离被添加到V8中。

然后我安装了node.js,它的deps文件夹中也有v8。我构建了node.js,v8也得到了构建。我遵循了nodejs插件开发的说明。它的"helloworld nodejs"是成功的。我认为实际的谷歌代码也应该像标题中的隔离类一样工作。但它并没有编译错误:

error C2664: 'v8::HandleScope::HandleScope(const v8::HandleSc
ope &)' : cannot convert parameter 1 from 'v8::Isolate *' to 'const v8::HandleS
cope &' [C:Usersasnegicompanynodejs projectnode-v0.10.15srcmy_filesbuil
dv8code.vcxproj]
          Reason: cannot convert from 'v8::Isolate *' to 'const v8::HandleScope
  '
          No constructor could take the source type, or constructor overload re
  solution was ambiguous

查看C:\Users\abc.node gyp\0.10.15\deps\v8\include\v8.h 的标题

它定义了类Isolate。此外,

template <class T> class Handle {
 public:
  /**
   * Creates an empty handle.
   */
  inline Handle() : val_(0) {}
  /**
   * Creates a new handle for the specified value.
   */
  inline explicit Handle(T* val) : val_(val) {}
  ...........
  ...........

 class HandleScope {
    public:
  inline HandleScope();
  explicit inline HandleScope(Isolate* isolate);
  .....

因此,谷歌的Hello世界的这一部分本应发挥作用:

// Get the default Isolate created at startup.
  Isolate* isolate = Isolate::GetCurrent();
  // Create a stack-allocated handle scope.
  HandleScope handle_scope(isolate);
  // Create a new context.
  Handle<Context> context = Context::New(isolate);

问题出在哪里?

稳定节点v0.10.15使用Google V8版本3.14.5(2012-10-22)C: \Documents\github\nodes\deps\v8\include\v8.h

class V8EXPORT HandleScope {
 private:
  HandleScope(const HandleScope&);

不稳定节点v0.11.5使用Google V8版本3.20.14(2013-08-07)C: \Documents\github\nodes\deps\v8\include\v8.h

class V8_EXPORT HandleScope {
 public:
  // TODO(svenpanne) Deprecate me when Chrome is fixed!
  HandleScope();
  HandleScope(Isolate* isolate);
  ~HandleScope();

从节点\deps\v8\ChangeLog文件:

2013-03-15:版本3.17.11

添加了带有v8::Isolate的v8::HandleScope构造函数的版本参数,并使AdjustAmountOfExternalAllocatedMemory成为实例v8的方法:隔离。(第2487期)

指针与引用。看起来HandleScope()需要一个引用,而New()返回一个指针。