v8

javascript multidimensional object

扶醉桌前 提交于 2020-02-02 03:06:55
问题 I'm trying to define a multidimensional object in JavaScript with the following code: function A(one, two) { this.one = one; this.inner.two = two; } A.prototype = { one: undefined, inner: { two: undefined } }; A.prototype.print = function() { console.log("one=" + this.one + ", two=" + this.inner.two); } var a = new A(10, 20); var b = new A(30, 40); a.print(); b.print(); The result is: one=10, two=40 one=30, two=40 , but I expect one=10, two=20 one=30, two=40 What am I doing wrong? Is a

A puzzle about this/@ in Javascript/Coffeescript

孤街醉人 提交于 2020-02-02 02:55:32
问题 I'm working through Trevor Burnham's CoffeeScript book and I've run into a weird puzzle concerning this / @ . The puzzle has a few parts (and I may be just very confused), so I'll try to make this as clear as I can. The main problem I'm having is that I get varied and inconsistent results running the same code through different REPLs and interpreters. I'm testing with (1) the coffee REPL and interpreter, (2) Node's REPL and interpreter and (3) v8's REPL and interpreter. Here's the code, first

Are there ways to see the assembly code for the code generated by any of the JavaScript jits, especially V8's?

允我心安 提交于 2020-01-28 09:59:42
问题 The major JavaScript engines of web browsers and nodeJS have had just-in-time compilers for years. I was just watching a video on Compiler Explorer showing the assembly code output by many compilers for various CPUs. This reminded me that I've been curious about the code generated by the JS engines' jits. Do any of those engines have ways for us to see that low-level generated code? (If this is out of place on SO please feel free to migrate it to the correct SE site.) 回答1: For V8, there is a

V8 引擎是如何工作的?

老子叫甜甜 提交于 2020-01-27 21:59:51
V8 引擎是如何工作的? CSDN ​ 已认证的官方帐号 17 人赞同了该文章 作者 | Fundebug 来源|Fundebug 最近,JavaScript生态系统又多了2个非常硬核的项目。 大神Fabrice Bellard发布了一个新的JS引擎QuickJS,可以将JavaScript源码转换为C语言代码,然后再使用系统编译器(gcc或者clang)生成可执行文件。 Facebook为React Native开发了新的JS引擎Hermes,用于优化安卓端的性能。它可以在构建APP的时候将JavaScript源码编译为Bytecode,从而减少APK大小、减少内存使用,提高APP启动速度。 作为JavaScript程序员,只有极少数人有机会和能力去实现一个JS引擎,但是理解JS引擎还是很有必要的。本文将介绍一下V8引擎的原理,希望可以给大家一些帮助。 JavaScript引擎 我们写的JavaScript代码直接交给浏览器或者Node执行时,底层的CPU是不认识的,也没法执行。CPU只认识自己的指令集,指令集对应的是汇编代码。写汇编代码是一件很痛苦的事情,比如,我们要计算N阶乘的话,只需要7行的递归函数: function factorial(N) { if (N === 1) { return 1; } else { return N * factorial(N - 1);

Can we use process.hrtime() as UUID in node.js?

房东的猫 提交于 2020-01-25 05:00:06
问题 Can we use process.hrtime() as universal unique id within the current process ? var uuid = parseInt(process.hrtime().join('')); 回答1: You can use process.hrtime() to create identifiers with low chance of collision, but they are not unique, especially not across application restarts (which matters if you persist any of them to a database or similar), and not when several threads/processes/instances are involved. From the documentation: These times are relative to an arbitrary time in the past,

Are array methods in V8 written in C++, Torque or is the JS converted to machine code at run time?

眉间皱痕 提交于 2020-01-25 02:20:41
问题 I'm learning about the V8 run time and I'm wondering if array methods for example, such as array.map , are written in C++ inside V8? I see here some Torque files that confuse me so I am wondering if maybe they are written in Torque instead of C++? https://github.com/v8/v8/blob/master/src/builtins/array-map.tq My understanding is that V8 converts the JavaScript code to machine code using a Just in Time (JIT) concept. So I guess I'm wondering if there are C++ or Torque equivalents of array.map

How to write to Uint8ClampedArray?

£可爱£侵袭症+ 提交于 2020-01-24 21:58:30
问题 I'm writing a node addon which accepts HTML canvas Image data, that's of type Uint8ClampedArray . I want to modify the the contents of this array without any extra copy. The best candidate I've found is the v8::Object::Set method (v8::Object being a class in Uint8ClampedArray's inheritance hierarchy) However that method requires a handle to v8::Context object as first argument. I don't know how to get that. I've searched through github repos and found code inside Webkit that directly casts

How to call a Javascript function from V8 in C++

别说谁变了你拦得住时间么 提交于 2020-01-24 19:25:07
问题 To run a simple Javascript program using v8 I go about it as follows: // Create a string containing the JavaScript source code. v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, "'Hello' + ', from Javascript!'", v8::NewStringType::kNormal).ToLocalChecked(); // Compile the source code. v8::Local<v8::Script> script = v8::Script::Compile(context, source).ToLocalChecked(); // Run the script to get the result. v8::Local<v8::Value> result = script->Run(context).ToLocalChecked(); How

How to call a Javascript function from V8 in C++

爷,独闯天下 提交于 2020-01-24 19:24:27
问题 To run a simple Javascript program using v8 I go about it as follows: // Create a string containing the JavaScript source code. v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, "'Hello' + ', from Javascript!'", v8::NewStringType::kNormal).ToLocalChecked(); // Compile the source code. v8::Local<v8::Script> script = v8::Script::Compile(context, source).ToLocalChecked(); // Run the script to get the result. v8::Local<v8::Value> result = script->Run(context).ToLocalChecked(); How

Starting Node with Forever and --prof option V8 Log file not created

£可爱£侵袭症+ 提交于 2020-01-24 08:49:04
问题 I am trying to run my Node App using "forver" module , I also want to pass "--prof" option for profiling my app. The command I am using is NODE_ENV=staging PORT=3000 NODE_CONFIG_DIR="/domains/serving/src/config" forever start -c "node --prof" -l /var/log/forever.log -e /var/log/forever_error.log -o /var/log/forever_output.log -a /domains/serving/src/bin/www Or NODE_ENV=staging PORT=3000 NODE_CONFIG_DIR="/domains/serving/src/config" forever start -c "node --debug=3048 --prof" -l /var/log