v8

转发:几个常见的 NodeJS 误区

Deadly 提交于 2019-12-23 19:03:14
很多不熟悉 NodeJS 的开发者,总是对 NodeJS 抱有怀疑态度,其中的原因基本是对其具有误解,而这些误解往往又最终导致自己放弃 NodeJS 的学习。在这篇文章里,我将会尽可能言简意赅的介绍和解释这些误区的所在之处,并不遗余力地挽留那些正在迷茫中的人,同时增强正在使用 NodeJS 的开发者们的信心。 一、 NodeJS 是一门服务器语言 这个错误非常明显,NodeJS 是一个使用 Chrome V8 引擎运行 JavaScript 程序的运行时环境,正如 JRE (Java Runtime Environment) 是 Java 程序的运行环境一样,语言还是 JavaScript,和我们在浏览器中运行 JS 脚本没什么不同。区别在于,NodeJS 提供了一整套用于服务器编程(准确来说应该是除网页编程外)的工具包,例如处理网络连接的 net, http, https 模块,用于读写文件的 fs 模块等,以及 NPM 仓库中数十万的第三方模块。这些模块,加上 NodeJS 运行时,为 JavaScript 语言提供了跨平台、跨领域的编程能力。 除了服务器编程,NodeJS 还被广泛应用于客户端编程,如桌面软件( Electron 框架),手机软件( React-Native 框架, Apache Cordova 框架)等,当然还有现在特别火的“前端”开发,例如 React

In JavaScript, why is a “reverse while” loop an order of magnitude faster than “for”?

倾然丶 夕夏残阳落幕 提交于 2019-12-23 12:16:49
问题 In these benchmarks, http://jsperf.com/the-loops, Barbara Cassani showed that a "reverse while" loop is way faster, while (iterations > 0) { a = a + 1; a = a - 1; iterations--; } than a usual "for" loop: for (i = 0; i < iterations; i++) { a = a + 1; a = a - 1; } Why? Update Okay, forget about it, there is a bug in the test, iterations = 100 , is executed only once per page. Therefore reducing it, well, means that we don't really enter the loops. Sorry. 回答1: Except for the big bug in the

V8 是怎么跑起来的 —— V8 的 JavaScript 执行管道

帅比萌擦擦* 提交于 2019-12-23 10:21:26
文章创作于 2019-11-08,2019-12-20 迁移至此。 作者有话说 “V8 是怎么跑起来的” 系列是我学习 V8 过程中的总结。从一年前正式成为前端工程师开始,我便有意识地了解和学习 V8。我也发现,在技术社区中鲜有内容新鲜的、原创度高的中文资料,于是开始将我学习过程中的总结分享出来。 由于工作繁忙,我已经半年没有更新博客。这个系列的引子是 4 月写的一篇 《V8 是怎么跑起来的 —— V8 中的对象表示》 ,我们通过使用 Chrome DevTools 验证的方式介绍了 V8 中的对象表示。 本文是这个系列真正意义的第一篇文章。文章的定位是这个系列的大纲,将按照 JavaScript 在 V8 中的执行流程,顺序介绍每一步的操作,并澄清一个社区中流传甚广的 “错误”。本文不会过于深究其中的细节(后续篇章将展开),您可以在评论中留下您想了解 V8 引擎的部分,也许下一篇选题会采纳并优先介绍。 祝阅读愉快。 1. 为什么是 V8 Any application that can be written in JavaScript, will eventually be written in JavaScript. 相信很多的朋友都听过前端界的一个著名定律,叫做 Atwood’s Law 。2007 年,Jeff Atwood 提出 “所有可以用 JavaScript

size of an object reference in Javascript V8

余生颓废 提交于 2019-12-23 09:47:42
问题 Does anyone know the size of an object reference in Javascript (V8). It's 8 bytes like in C pointers? Thank you very much. 回答1: Yes, as I remember it takes 8 bytes. Nowadays it's the optimal size in x64 systems for all pointers/references. 来源: https://stackoverflow.com/questions/32538685/size-of-an-object-reference-in-javascript-v8

Tracking down stack overflow in meteor/node fiber

大兔子大兔子 提交于 2019-12-23 09:38:45
问题 I'm seeing this crash now and am not familiar enough with the node fiber infrastructure to know where to begin interpreting the error or instrumenting the code... Meteor server running on: http://localhost:3000/ W202407-10:06:05.740(-8)? (STDERR) /Users/dauser/.meteor/tools/0b2f28e18b/lib/node_modules/fibers/future.js:173 W202407-10:06:07.363(-8)? (STDERR) throw(ex); W202407-10:06:07.363(-8)? (STDERR) ^ W202407-10:06:07.363(-8)? (STDERR) RangeError: Maximum call stack size exceeded => Exited

Why does V8 in Node.js 0.12.0 release require SSE2 CPU instructions?

帅比萌擦擦* 提交于 2019-12-23 07:43:13
问题 Trying to upgrade Node.js from 0.10.x to 0.12.0. The first thing noticed is that I am getting an error that SSE2 instructions are not supported by my CPU (indeed they are not). Tried to compile Node.js from sources but it failed for the same reason. In deps/v8/src/ia32/assembler-ia32.cc there is a line stating CHECK(cpu.has_sse2()); // SSE2 support is mandatory. I wonder if there is a way to get rid of this SSE2 dependency which was not required in Node.js 0.10.x. Just commenting out this

JavaScript engine for Java

江枫思渺然 提交于 2019-12-22 23:34:06
问题 Currently I'm using Rhino in my application. I need to eval some JavaScript ant get values from it (I don't need to use Java classes through JavaScript). But it is too slow. Maybe there are any ways to use V8 with Java application? Update: I have a large collection of objects of different types. I need a flexible mechanism for validation and transformation these objects to the required form (the user should be able to change the rules of validation and transformation (in runtime), ie

JavaScript engine for Java

那年仲夏 提交于 2019-12-22 23:33:11
问题 Currently I'm using Rhino in my application. I need to eval some JavaScript ant get values from it (I don't need to use Java classes through JavaScript). But it is too slow. Maybe there are any ways to use V8 with Java application? Update: I have a large collection of objects of different types. I need a flexible mechanism for validation and transformation these objects to the required form (the user should be able to change the rules of validation and transformation (in runtime), ie

v8 WeakCallback never gets called

蓝咒 提交于 2019-12-22 12:31:39
问题 I know that this question is old but all the answers I found doesn't work and are outdated. But here is my code: void Destroyed(const v8::WeakCallbackData<v8::Object, int>& info) { std::cout << "d: " << *info.GetParameter() << std::endl; } std::vector<v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object>>> persistent; int i = 0; void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { v8::HandleScope scope(v8::Isolate::GetCurrent()); v8::Persistent<v8::Object, v8:

Analyzing an ELF binary to minimize its size

对着背影说爱祢 提交于 2019-12-22 07:44:46
问题 I'm cross-compiling a V8 project to an embedded ARM target using the GCC arm-gnueabi cross compiler. I got the V8 library itself cross-compiled successfully, and as a smoke test I wanted to link it to Google's hello world example and run it on the ARM board. The libraries themselves clock in at a bit over 1.2 MB: v8 % find out/arm.release/obj.target/ -name '*.a' -exec du -h {} + 1.2M out/arm.release/obj.target/tools/gyp/libv8_base.a 12K out/arm.release/obj.target/tools/gyp/libv8_libbase.a 4