Questions tagged [v8]

V8 is Google's open source JavaScript engine.

About V8

V8 is Google's Javascript engine that is used in Google Chrome (). It is written in C++ (), and is open source, which can be checked out by following the instructions on the v8 wiki.

V8 can run standalone, or can be embedded into C++ applications.

Documentation on V8 can be found on its wiki pages.

There are a number of flags that can be passed to V8 to expose its internals. For instance, --trace-deopt gets V8 to log code deoptimizations, and --expose-gc allows scripts to manually invoke a garbage collection. The full list of flags can be found by reading the source.

Links:

Tag Usage

Use this tag to ask questions about:

  • Usage of the V8 API
  • Performance and profiling with V8
  • How V8 works
2955 questions
64
votes
3 answers

What makes this function run much slower?

I've been trying to make an experiment to see if the local variables in functions are stored on a stack. So I wrote a little performance test function test(fn, times){ var i = times; var t = Date.now() while(i--){ fn() } …
Krzysztof Wende
  • 3,208
  • 25
  • 38
63
votes
6 answers

Node.js: for each … in not working

I wanted to use for each ... in with Node.js (v0.4.11). I use it like this: var conf = { index: { path: { first: "index.html", pattern: "index/{num}.html" }, template: "index.tpl", limit: 8 }, feed:…
pvorb
  • 7,157
  • 7
  • 47
  • 74
62
votes
2 answers

How to run user-submitted scripts securely in a node.js sandbox?

What are the options for running (possibly malicious) user-submitted scripts in node.js, securely? I.e. in an environment that prevents code from accessing sensitive data and APIs? vm.runInNewContext(userScript, {}) is a tempting starting point...…
broofa
  • 37,461
  • 11
  • 73
  • 73
61
votes
2 answers

Why is the execution time of this function call changing?

Preface This issue seems to only affect Chrome/V8, and may not be reproducible in Firefox or other browsers. In summary, the execution time of a function callback increases by an order of magnitude or more if the function is called with a new…
Lewis
  • 4,285
  • 1
  • 23
  • 36
61
votes
6 answers

How can I check if a JSON is empty in NodeJS?

I have a function that checks to see whether or not a request has any queries, and does different actions based off that. Currently, I have if(query) do this else something else. However, it seems that when there is no query data, I end up with a {}…
thisissami
  • 15,445
  • 16
  • 47
  • 74
60
votes
1 answer

Is it possible to get stack traces across async/await boundaries using --harmony_async_await in Node 7?

We're experimenting with using --harmony_async_await in Node 7, and compared to transpiling with babel for async/await are missing the ability to have long stack traces (http://bluebirdjs.com/docs/api/promise.longstacktraces.html). Obviously, it…
james.haggerty
  • 1,170
  • 6
  • 10
59
votes
13 answers

Why doesn't Node.js have a native DOM?

When I discovered that Node.js was built using the V8 JavaScript engine, I thought: Great, web scraping will be easier as the page will be rendered like in the browser, with a "native" DOM supporting XPath and any AJAX calls on the…
PeterB
  • 2,212
  • 2
  • 21
  • 33
55
votes
2 answers

What exactly is the difference between v8::Isolate and v8::Context?

What is the difference/connection between these objects in V8? Does a context "belong" to an Isolate or vice versa? I know that a single Isolate may only be accessed by one thread at a time (and that's what v8::Locker is for I guess?). I've looked…
DeX3
  • 5,200
  • 6
  • 44
  • 68
55
votes
8 answers

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I'd like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a command and then push data to it (only to exec and…
Maciek
  • 3,322
  • 6
  • 28
  • 35
53
votes
2 answers

Different results using the same maths in different browsers

Edit: since chrome has updated the browser - this question is some what redundant as they have fixed an internal bug which means this problem no longer occurs. I have an animation of a circle anchored to the center of the canvas. The larger the…
Sir
  • 8,135
  • 17
  • 83
  • 146
52
votes
3 answers

Do common JavaScript implementations use string interning?

Do common JavaScript engines, such as V8 and WebKit's JavaScriptCore, use string interning for JavaScript strings? Or do they actually keep multiple instances of identical strings in memory?
kpozin
  • 25,691
  • 19
  • 57
  • 76
52
votes
3 answers

What's the time complexity of array.splice() in Google Chrome?

If I remove one element from an array using splice() like so: arr.splice(i, 1); Will this be O(n) in the worst case because it shifts all the elements after i? Or is it constant time, with some linked list magic underneath?
Ivan
  • 2,314
  • 3
  • 18
  • 22
51
votes
2 answers

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

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++) { …
Gábor Bokodi
  • 525
  • 1
  • 5
  • 10
47
votes
5 answers

Android utilize V8 without WebView

I'm exercising executing javascript from Java. Rhino works very well for this on desktop, but has to fall back to (slow) interpreted mode on Android (due to dalvik being unable to execute the Java bytecode the Rhino JIT compiles). Android has its…
Uejji
  • 571
  • 1
  • 5
  • 4
46
votes
5 answers

What's the maximum size of a Node.js Buffer

I got a fatal error reading a file that was too big to fit in a buffer. FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() length exceeds max acceptable value Or, RangeError: "size" argument must not be larger than 2147483647 at…
Joel
  • 2,928
  • 2
  • 24
  • 34