node.js - 为什么要将 Local<Value>::New 与 String::New() 一起使用

标签 node.js v8 embedded-v8

我用过这个:

 Local<Value> argv[argc] = { String::New("hello world") };

但现在我在 node.js 网站上看到了这个例子:

 Local<Value> argv[argc] = { Local<Value>::New(String::New("hello world")) };

这是什么意思?有什么区别,当一个 dwhy 我应该使用 Local<Value>除了String::New()

最佳答案

显然,本例中的 node.js 示例是错误的/低效的。

https://github.com/joyent/node/commit/98aad77f466d9c36947f2cbb6d07b75009795ed2#commitcomment-5532648

jnardone added a note 2 hours ago

Was this just one of those things that was always wrong, or was there an underlying v8 change that meant that this should change? The additional Local::New always looked odd but I can't tell if something buried inside v8 required this additional wrapper or not.

bnoordhuis added a note 7 minutes ago

It's cleanup. Creating a Local out of a Local is not actively harmful but it's superfluous and slightly inefficient.

所以,您的第一种格式没问题。

关于node.js - 为什么要将 Local<Value>::New 与 String::New() 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22114724/

相关文章:

javascript - Node.js 堆内存不足

javascript - JavaScript 是否具有与 Python 的 __getattribute__ 等效的功能?

javascript - node/lib 中的 *.js 文件是否在 Node 可执行文件的编译过程中使用?

javascript - "Hello World"+ JS V8 + VS2010

javascript - 如何在不同的 c++ 项目中使用 Google V8 引擎?

JavaScript - 用数组助手替换 for 循环

node.js - Mongoose 中的多文档更新插入

javascript - 未捕获的异常 : ReferenceError: debug is not defined

javascript - 带有 GYP "exceptions"的 Node.js 附加组件

c++ - 如何运行 JavaScript 文件 - V8