v8

Pass Node.js Buffer to C++ addon

半城伤御伤魂 提交于 2020-01-02 07:23:08
问题 test.js buf = new Buffer(100); for (var i = 0; i < 100; i++) buf[i] = i addon.myFync(buf); addon.cpp Handle<Value> set(const Arguments& args) { char *buf = SOMETHING(args[0]); return Undefined(); } How to get the pointer to a data of the buffer inside the C++ function? What should I write in place of SOMETHING(args[0]) ? I have node_buffer.h opened in my editor, but I cannot figure out. Node version = v0.10.29 回答1: You can do: char* buf = node::Buffer::Data(args[0]); to directly access the

Add a function template to a global object prototype in v8

▼魔方 西西 提交于 2020-01-02 04:43:08
问题 In V8, I would like to modify the prototype of the global built-in Array object, by adding some functions to it. In JavaScript, I would do it like this, for example: Array.prototype.sum = function() { // calculate sum of array values }; How can I achieve the same result in C++? I have some global function templates added to the global ObjectTemplate, but I am not sure how to do the same for a supposedly existing native object prototype. 回答1: native implementation: Handle<Value> native_example

how to run / debug javascript in command line

≡放荡痞女 提交于 2020-01-01 06:29:11
问题 I'm wondering (actually I know there definitely is such a way to run js in command line, because when I watch google I/0 presentations, they use a command like d8, maybe it's part of V8 engine) is there any way to run/debug my javascripts in command line? such as d8 myJsfile.js --prof etc.? Does anybody have any idea about this? 回答1: Yes, D8 is a command line tool that allows you to run and debug Javascript scripts. It comes with V8. Getting D8 Getting V8 on your machine is not hard. Follow

how to run / debug javascript in command line

旧城冷巷雨未停 提交于 2020-01-01 06:29:04
问题 I'm wondering (actually I know there definitely is such a way to run js in command line, because when I watch google I/0 presentations, they use a command like d8, maybe it's part of V8 engine) is there any way to run/debug my javascripts in command line? such as d8 myJsfile.js --prof etc.? Does anybody have any idea about this? 回答1: Yes, D8 is a command line tool that allows you to run and debug Javascript scripts. It comes with V8. Getting D8 Getting V8 on your machine is not hard. Follow

Is it possible to make Node.js use Rhino as the Javascript engine?

两盒软妹~` 提交于 2020-01-01 04:11:11
问题 I use Node.js for several jobs on my web apps and so far everthing's ok. But the Node.js uses Google's V8 as the default Javascript engine (JSE) and V8 runs exlusively on the x86 and ARM Instruction Set Architectures (ISA). Now I have a PPC processor Mac computer on which I want to run the Node.js . To do that, I'm adviced to use the Rhino + OpenJDK Shark Virtual Machine + Low Level Virtual Machine (LLVM) as the JIT compiler. Currently, that looks like the most applicable way of running Node

Garbage collector in Node.js

一个人想着一个人 提交于 2019-12-31 10:49:48
问题 According to google, V8 uses an efficient garbage collection by employing a "stop-the-world, generational, accurate, garbage collector". Part of the claim is that the V8 stops program execution when performing a garbage collection cycle. An obvious question is how can you have an efficient GC when you pause program execution? I was trying to find more about this topic as I would be interested to know how does the GC impacts the response time when you have possibly tens of thounsands requests

should we choose async await over Promise in Javascript

狂风中的少年 提交于 2019-12-30 17:23:19
问题 I know that the async await is the new Promise in the town and it is a new way to write asynchronous code and I also know that We didn’t have to write .then , create an anonymous function to handle the response Async/await makes it finally possible to handle both synchronous and asynchronous errors with the same construct, good old try/catch The error stack returned from a promise chain gives no clue of where the error happened. However, the error stack from async/await points to the function

what's the 'sort' method's difference between chrome environment and node environment

大城市里の小女人 提交于 2019-12-30 16:36:22
问题 I found the sort method shows different behavior between in Chrome environment and in the node environment const arr = ['l', 'h', 'z', 'b', 's']; arr.sort((pre, next) => { return pre < next; }); console.log(arr); the node environment's result is [ 'z', 's', 'l', 'h', 'b' ] , it's sorted. the chrome console environment's result is ['l', 'h', 'z', 'b', 's'] , nothing changed. chrome's result is what I expect, I don't understand why it working in node environment. chrome version is 74.0.3729.169

Shall I delete the pointer manually in v8::External?

假如想象 提交于 2019-12-30 10:23:28
问题 Local<ObjectTemplate> tpl = ObjectTemplate::New(isolate); tpl->SetInternalFieldCount(1); Local<Object> ret = tpl->NewInstance(); TestExternal* ex = new TestExternal(); ret->SetInternalField(0, External::New(isolate, ex)); Shall I delete the ex pointer manually when ret is no longer in use? Where's the evidence source code shows that I should or shouldn't do that? 回答1: Yes, C++ requires manual memory management: if you manually create an object with new , then you also have to manually delete

Shall I delete the pointer manually in v8::External?

不想你离开。 提交于 2019-12-30 10:21:11
问题 Local<ObjectTemplate> tpl = ObjectTemplate::New(isolate); tpl->SetInternalFieldCount(1); Local<Object> ret = tpl->NewInstance(); TestExternal* ex = new TestExternal(); ret->SetInternalField(0, External::New(isolate, ex)); Shall I delete the ex pointer manually when ret is no longer in use? Where's the evidence source code shows that I should or shouldn't do that? 回答1: Yes, C++ requires manual memory management: if you manually create an object with new , then you also have to manually delete