Tag: node.js addon

如何用ValgrindtestingNode C ++附件?

在运行valgrind node ,Node似乎放弃了一个与系统调用有关的错误。 我在macOS Sierra,Node v8.2.1上。 $ valgrind `which node` test-pass.js ==17115== Memcheck, a memory error detector ==17115== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==17115== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==17115== Command: /Users/junon/n/bin/node test-pass.js ==17115== ==17115== Syscall param msg->desc.port.name points to uninitialised byte(s) ==17115== at […]

有没有可能在node addon中注册eventloop?

AtExit钩子是在Node.js事件循环结束之后但在JavaScript VM终止并且Node.jsclosures之前调用的函数。 AtExit挂钩使用node :: AtExit API进行注册。 同样有什么办法可以在node addon中注册eventloop?

如何根据configuration更改库path?

我正在构build一个需要链接静态库的本地模块。 该库的path。 我的binding.gyp文件有以下外观: { "targets": [ { "target_name": "DcpServer", "sources": [ "DcpServer.cc" ], "include_dirs": [ "../../coratools", "../../../boost-1.65.1" ], "libraries": [ "<(module_root_dir)/../../coratools/release_uni64/coratools.lib" ], "defines": [ "CSIWEB_EMBEDDED", "UNICODE", "_UNICODE" ], "configurations": { "Release": { "msvs_settings": { "VCCLCompilerTool": { "ExceptionHandling": 1, "RuntimeTypeInfo": "true" } } }, "Debug": { "msvs_settings": { "VCCLCompilerTool": { "ExceptionHandling": 1, "RuntimeTypeInfo": "true" } } […]

节点插件和v8 GlobalTemplate

我正在构build节点插件与节点0.10.17并在我的一个类我正在做一个上下文的V8。 我有这个代码: v8::Locker locker; v8::HandleScope handle_scope; v8::Handle<v8::ObjectTemplate> globalTemplate; // vvv————— Exception here at ->Set() globalTemplate->Set(v8::String::New("version"), v8::FunctionTemplate::New(NodeVersion)); context = v8::Context::New(NULL, globalTemplate); if (context.IsEmpty()) { fprintf(stderr, "Error creating context\n"); } 这是给我例外->Set()函数调用。 应用程序正在打破。 我该怎么办 ?

使v8对象属性和方法对JS可见

我用node::ObjectWrap包装一个C ++对象,并且有一些定义如下的方法: auto tpl = NanNew<v8::FunctionTemplate>(New); tpl->SetClassName(NanNew("className")); tpl->InstanceTemplate()->SetInternalFieldCount(4); NanSetPrototypeTemplate(tpl, NanNew("method1") , NanNew<v8::FunctionTemplate>(Method1) , v8::ReadOnly); NanSetPrototypeTemplate(tpl, NanNew("method2") , NanNew<v8::FunctionTemplate>(Method2), v8::ReadOnly); NanSetPrototypeTemplate(tpl, NanNew("method3") , NanNew<v8::FunctionTemplate>(Method3) , v8::ReadOnly); NanSetPrototypeTemplate(tpl, NanNew("method4") , NanNew<v8::FunctionTemplate>(Method4), v8::ReadOnly); 一切都按预期工作,我可以通过以下方式在JS中创build对象的实例: var classInstance = new className(); 所有的方法工作得很好,但是当我尝试login函数: console.log(classInstance); 我期待看到像这样的东西: { method1 : [Native Function], method2 : [Native Function], method3 : [Native Function], method4 : [Native […]

ofstream不创build文件(Node.js插件)

我试图为Node.js创build一个插件 (其中包括)使用ofstream将内容写入我的C ++类中的文件。 std::ofstream license_file; std::string fileContent(*NanAsciiString(args[0])); license_file.open(PATH); //file doesn't yet exist, so create it if(!license_file) { printf("ERROR: %s (%s)\n", strerror(errno), PATH); } license_file << fileContent; license_file.close(); 如果PATH被设置为与我的Node.js代码(例如./license.txt )相同的目录,这工作正常。 但是,如果它位于其他地方,则不能打开/创build有问题的文件。 例如,使用~/license.txt不起作用(注意:我正在运行OSX)。 报告的错误总是No such file or directory – 即使我物理创build~/license.txt 。 任何想法,为什么这个工程在一个目录,但不是其他人? 如果这是一个权限问题,我会期待一个不同的错误信息。 为了logging,我已经看到关于“ofstream无法创build文件”的约20个其他SO问题,但将其他标志传递到open()没有任何效果。 我有一种感觉,这是与Node / V8内部运行有关。

我可以将Node.js C ++扩展与Node的内部OpenSSL实现链接起来吗?

我有一个用C ++编写的需要链接到OpenSSL的节点扩展。 我也看到Node有一个使用OpenSSL实现的TLS模块 。 我可以在我的binding.gyp文件中将我的扩展连接到OpenSSL的Node副本吗?

使用node-nan在一个node.js模块中设置WindowsHookEx

我正在尝试创build一个Electron node.js应用程序,它可以使用全局键绑定执行某些function。 Electron中的全局键绑定API在游戏中不起作用,所以我需要创build一个监听这些低级别键事件的本地节点模块。 所以我使用node-gyp来编译visual studio 2015和nan的项目来提供节点和c ++之间的通信。 我已经设法让这个项目的两个方面分别工作(低级别的键绑定和node.js < – > nan通信),但是我很难将它们结合起来。 我也承认我有很less的经验与c + +(我没有写一个单一的c + +程序)。 #include "node_modules/nan/nan.h" using namespace std; using namespace Nan; HHOOK _hook; KBDLLHOOKSTRUCT kbdStruct; class KeyboardEventWorker : public AsyncProgressWorker { public: KeyboardEventWorker(Callback *callback, Callback *progress) : AsyncProgressWorker(callback), progress(progress) {} ~KeyboardEventWorker() {} LRESULT CALLBACK HookCallback(int nCode,WPARAM wParam,LPARAM lParam) { executionProgress->Send(reinterpret_cast<const char*>(nCode), […]

为什么“Isolate :: GerCurrent()”在asynchronous线程中为空?

我的最终目标是解决这个问题 ,但我陷入了一些非常基本的东西。 我的整个C ++模块基本如下: void AsyncWork(void *arg) { Isolate* isolate = Isolate::GetCurrent(); // isolate is NULL if (isolate != NULL) { HandleScope scope(isolate); } else { printf("isolate is null\n"); return; } // … } void testAsync(const FunctionCallbackInfo<Value>& args) { uv_thread_t id; int data = 10; uv_thread_create(&id, AsyncWork, &data); } void init(Handle<Object> target) { NODE_SET_METHOD(target, "testAsync", […]

在Nodejs中创buildv8arrays的性能

我正在尝试将一个JSalgorithm移植到C ++中,以查看是否可以改进性能,但是在填充v8arrays时,我正面临着巨大的性能瓶颈。 这是一个片段,重现只是数组填充。 我创build了一个800k项目的数组,每个项目是17个数字的数组。 这个algorithm需要3秒才能在我的机器上执行,这是相当巨大的。 有反正加快吗? #include <node.h> namespace demo { using namespace v8; // just for lisibility of the example void Method(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); Local<Array> array = Array::New(isolate, 800000); for (int i = 0; i < 800000; ++i) { Local<Array> line = Array::New(isolate, 17); for (int j = 0; […]