Skip to content

Instantly share code, notes, and snippets.

@fhinkel
Last active November 7, 2019 20:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhinkel/e1cf8cbb10d1bea582a4 to your computer and use it in GitHub Desktop.
Save fhinkel/e1cf8cbb10d1bea582a4 to your computer and use it in GitHub Desktop.
V8 Installation and d8 shell usage

Installing V8 on a Mac

Install depot_tools

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=`pwd`/depot_tools:"$PATH"

Build v8

$ fetch v8
$ cd v8
$ make x64.debug

Run d8

$ ./out/x64.debug/d8

You can alias d8 in you .bash_profile by adding the following line to it:

alias d8=/path/to/v8/repo/out/x64.debug/d8

d8 Shell Examples

Create a file classes.js with the following content

var a = {}
a.x = 8;
a.y = 8;

var b = {}
b.x = 3;
b.y = 9;

print(%HaveSameMap(a, b));  // true
a.z = 1;
print(%HaveSameMap(a, b));  // false

Run it via d8 --allow_natives_syntax classes.js.

Check for optimization and deoptimization d8 --traceopt --trace-deopt twice.js

function twice( a ) {	
	return a + a;
}

var i = 0;
while (i++ < 1000000) {
	twice(4);
	if (i % 10000 == 0) {
		twice('a');
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment