2013-08-21 313 views
2

我正在使用windows。我試圖通過使用來自underscorediscovery的V8在V8中運行hello world。這可能不是線Hello World和V8

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

我看着underscorediscovery頭編譯和它沒有了老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的addon development的指示。 其「hello world nodejs」成功。我認爲,實際的谷歌代碼也應該在類標題中使用Isolate。但它不是有錯誤編譯:

error C2664: 'v8::HandleScope::HandleScope(const v8::HandleSc 
ope &)' : cannot convert parameter 1 from 'v8::Isolate *' to 'const v8::HandleS 
cope &' [C:\Users\asnegi\company\nodejs project\node-v0.10.15\src\my_files\buil 
d\v8code.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的頭展望:\用戶\ abc.node-GYP \ 0.10.15 \ DEPS \ V8 \包括\ v8.h

它class 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); 
    ..... 

因此,谷歌的世界,你好,這部分應該有工作:

// 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); 

問題是什麼?

+0

我的svn不工作,所以無法下載svn-v8,所以尋找替代品。 –

回答

4

穩定節點v0.10.15使用谷歌的V8版本3.14.5(2012年10月22日) C:\文檔\ github上\節點\的DEP \ V8 \包括\ v8.h

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

不穩定節點V0 .11.5使用谷歌的V8版本3.20.14(2013年8月7日) C:\文檔\ github上\節點\的DEP \ V8 \包括\ v8.h

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

從節點\的DEP \ V8 \ changelog文件:

2013年3月15日:版本11年3月17日

增加了一個版本的V8引擎::與V8 HandleScope構造::隔離 參數和製造V8 ::隔離的AdjustAmountOfExternalAllocatedMemory實例 方法。 (issue 2487)

+0

你是對的。當我搜索HandleScope時,我正在查看v8分支。我的錯。 –

0

指針與參考文獻。看起來HandleScope()需要一個引用,而New()返回一個指針。

+0

請參閱我的編輯。 –