FAQ Database Discussion Community


Pass arguments to another function

c++,node.js,v8
Here I assign one Argument to the Handler: const unsigned argc = 1; v8::Local<v8::Value> argv[1] = { NanNew("hello world") }; NanMakeCallback(NanGetCurrentContext()->Global(), callHandle, argc, argv); It works But I want to assign two parameters! That is why I tried to do: const unsigned argc = 2; v8::Local<v8::Value> argv[1] = { NanNew("hello...

Are node.js and V8 builtins written in JS or compiled and run as native code?

javascript,node.js,v8
In node.js and I assume by extension V8, are built-ins (such as JSON, Math, etc) native code residing in the interpreter or are they javascript code that gets interpreted the same way as the rest of user-written code? So for example, does a call to JSON.stringify(my_data) jump to compiled machine...

Best way to check on heap in V8

node.js,v8
What is the best way, say for an Express server, to check that the overall heap is not growing over time in V8?

V8 installation in ubuntu

v8
I have followed the following steps to install v8 in ubuntu .No error occured during the process svn checkout http://v8.googlecode.com/svn/trunk/ ./v8 cd v8 make builddeps make native but when I am trying to run the hello world program with the following command I'm getting error g++ -Iv8/include hello_world.cpp -o hello_world.o...

nodejs decrease v8 garbage collector memory usage

node.js,memory-management,garbage-collection,v8
I'm debugging a nodejs application with util module and while heapUsed value stays around 30-100MB, heapTotal value grows up to 1.4GB. Here is a question about similar behaviour I've read that this is the way how v8 garbage collector behaves, but the question is how to decrease the amount of...

ECMAScript 6 features available in Node.js 0.12

javascript,node.js,v8,ecmascript-6
A new stable release of Node.js (0.12) has landed recently with an upgraded Google's v8 JavaScript engine, v3.28.73. What ECMAScript 6 features are currently present in Node.js, without using the --harmony flag? I have checked several sites claiming to list the ES 6 features but all of them seem out...

Traversing a string using arm assembly inside V8 source

arm,v8
I am trying to implement a fastpath for regular expressions in arm/code-stubs-arm.cc in the RegExpExecStub::Generate function. The subject string is stored in the register 'r4'. I need to traverse character by character in the string but I can't seem to be able to do it. I have tried things like:...

Node v8 variable default NULL but reassign based on argument passed

c,v8
I'm sure it's really basic but I haven't been able to find anything like it (perhaps I'm going about it completely the wrong way).. I'm trying to pass str to the 'call_to_c_lib_func' function which takes either NULL or a string (char*). #include <stdio.h> #include <string.h> #include <v8.h> void test(const v8::FunctionCallbackInfo<Value>&...

performance between object.property and map.get(object)

javascript,performance,v8,ecmascript-6
In ECMAScript 6, I have two way to define a dictionary: Traditional method (with dictionary = Object.create(null)): set property: dictionary.key = value or dictionary[key] = value get property: dictionary.key or dictionary[key] Using Map (with dictionary = new Map()): set a reference: dictionary.set(key, value) get a reference: dictionary.get(key) In V8, are...

Why do variable names start with the letter 'k'?

variables,v8,naming
such as kFastDtoaMaximalLength in fast-dtoa.h(Google v8) is it represent kernel? ...

Should I worry about cleaning up large objects in Node.js or leave it for the garbage collector?

javascript,node.js,garbage-collection,v8
Recently I ran into an issue with a node.js API where my memory was growing larger and larger with every request. I'm hosting my server on Heroku using their free version which is only 512MB of RAM. After getting a lot of traffic over the weekend, I started getting exceeded...

Unclear about V8 Garbage Collection

javascript,node.js,garbage-collection,v8
I am having a hard time wrapping my head around exactly what will be garbage collected in Node.js by V8 and why (or why not). I have an example below using the async.js library. I would love some insight into how V8 treats each case below (numbered from 1 to...

V8 “Hello World” Segfault on “InitializeBuiltinTypedArrays”

c++,v8,embedded-v8
This code is working fine on Windows/Visual Studio, but segfaulting on Ubuntu/GCC. Why? I've compiled V8 4.5.8 to a shared library. I've put the following code in a CPPUNIT test. /** * A simple test for basic V8 functionality, just running the "Hello World" example from * from <a href="https://developers.google.com/v8/get_started">the...

JavaScript engine to enable scripting support / application automation [closed]

javascript,node.js,v8
I am planning to switch to JavaScript as a scripting language for our application, currently we are using VBScript with Microsoft VB Script engine. Scripting scope is being used for Application Automation via exposed APIs and scripts execution can be on-demand, time-based, conditional or event-based. To enable JavaScript support for...

Internally how does JavaScript iterate over object keys?

javascript,object,iterator,hashmap,v8
In JavaScript, when we use the for...in loop or the Object.keys() method, how does the internal engine iterate over the object keys? I know this might slightly change from one implementation to another, but I'm sure there's a general approach, could you give a bird's-eye overview? Thanks!...

Why does Javascript's Math.pow() seem to return a rounded value compared to the same in C?

javascript,c,node.js,v8
My understanding is that both C's double and Javascript's numbers are IEEE 754 64 bit floating point numbers. I am trying to port some code from C to Nodejs, and I am running into what appears to be a rounding error in Javascript's Math.pow(). Here is my C program: #include...

Conversion of std::string to v8::string

v8
How can I convert std::string to v8::string,when I am trying to pass an std::string to a script in the following way script1 = Script::Compile(param1); I am getting conversion error. ...

How do you convert a Dart_Handle List to a C++ array?

c++,dart,v8,dart-native-extension
I'm trying to port over a node.js native abstraction to dart as a native extension. The node.js nan also happens to be using the v8 namespace, which I'm not terribly familiar with. The [incomplete] code snippet in particular that I'm having trouble with would be this: NAN_METHOD(TestFunction) { NanScope(); String::Utf8Value...

Change PATH for npm installs

node.js,npm,v8,gyp
Is it possible to run a pre-script before the install of a package's dependencies? I need to change the environment slightly before install of any of my package's dependencies, because my Python version is 3.3 and node-gyp (via gyp) breaks if the default Python version is not a 2.x version....

Which edition of the ECMAScript standard is actually implemented in Chrome V8?

javascript,google-chrome,v8,ecmascript-5,ecmascript-harmony
Which edition of the ECMAScript standard is actually implemented in Chrome V8? According to the introduction page to Chrome V8 on the Google Developers website, V8 implements the ECMA-262 5th edition specification (content last updated: September 17, 2012). Yet on the front page of the Chrome V8 product on the...

Converting Python objects to JavaScript for PyV8

python,v8,pyv8
I'm trying to pass Python data (lists, dicts, strings..., arbitrarily nested) to PyV8. class Global(object): def __init__(self, data): self.data = data ctx = PyV8.JSContext(Global([{'a':1}])) ctx.enter() res = ctx.eval('data.length') js_len = PyV8.convert(res) print js_len The code above prints None, presumably because the data object is not transformed to a JSArray and...

Date.parse(0) returns midnight of 2000, why?

javascript,v8
When I try to Date.parse() an integer or string 0, it returns 946681200000, which translates to a date of: Sat Jan 01 2000 00:00:00 GMT+0100 (CET) Why? I would assume that the parser interprets the single zero as a year 2000, but the specs say nothing about single-character year definition...

Why isn't Map subclassable in chrome/node?

javascript,v8,ecmascript-6
So ES 6 is bringing us Maps (and none too soon). Wishing to subclass Map for my own nefarious purposes, I tried the following (abbreviated for clarity): function Foo() { return Map.apply(this, [].slice.call(arguments)); } var bar = new Foo(); In V8 environments this throws an Error "Map constructor not called...

javascript V8 optimisation and “leaking arguments”

javascript,v8
I read in various places that it's advisable to be careful with the arguments object and that this is ok... var i = arguments.length, args = new Array(i); while (i--) args[i] = arguments[i]; But, is this ok or not?... function makeArray (l) { var i = l.length, array = new...

Convert a v8 Object to a custom C++ object

c++,node.js,opencv,v8
I'm currently developing a nodejs module, written in C++ and I've been looking for a way to convert a v8::Object to a cv::Mat object from opencv, without any luck for now. I saw that nan library could help to convert objects, but i couldn't find how, I don't even know...

slow function call in V8 when using the same key for the functions in different objects

javascript,node.js,performance,google-chrome,v8
Maybe not because the call is slow, but rather the lookup is; I'm not sure, but here is an example: var foo = {}; foo.fn = function() {}; var bar = {}; bar.fn = function() {}; console.time('t'); for (var i = 0; i < 100000000; i++) { foo.fn(); } console.timeEnd('t');...

ofstream not creating file (Node.js addon)

c++,node.js,v8
I am attempting to create an addon for Node.js that (among other things) writes content to a file inside my C++ class using ofstream. 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(); This works...

Pass Node.js Buffer to C++ addon

c++,node.js,v8
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...

Passing null argument to v8 callback

node.js,v8
I have a native addon that implements a function that accepts a callback and calls that callback with a possible error and a result. I currently have the following code from NodeJS documentation that calls that callback directly with the result: v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(args[0]); const unsigned callback_argc = 1;...