v8

How is asynchronous callback implemented?

时间秒杀一切 提交于 2019-12-05 05:43:46
How do all the languages implements asynchronous callbacks? For example in C++, one need to have a "monitor thread" to start a std::async . If it is started in main thread, it has to wait for the callback. std::thread t{[]{std::async(callback_function).get();}}.detach(); v.s. std::async(callback_function).get(); //Main thread will have to wait What about asynchronous callbacks in JavaScript? In JS callbacks are massively used... How does V8 implement them? Does V8 create a lot of threads to listen on them and execute callback when it gets message? Or does it use one thread to listen on all the

javascript internals: how events are implemented?

蓝咒 提交于 2019-12-05 05:41:55
My question is related to how the JS engines implement the pattern of asynchronous events when we do something like bind event handlers on a dom for lets say a click event.? Do they have something like a separate thread that is listening to all the click events ? When an event does occur , do they refer the bind list and bubble up the events ? Similar is with Ajax,the asynchronous network call, where the browser spans a new thread that would start listening to the data from the server and when the response is received, it would call the success handler? jfriend00 Read this post about the

Tail Call Optimization implementation in Javascript Engines

一笑奈何 提交于 2019-12-05 05:10:38
As of February 2019 in Chrome Version 71.0.3578.98 on Mac , the following program throws Uncaught RangeError: Maximum call stack size exceeded error. at a count of 16516 . const a = x => { console.log(x) a(x + 1) } a(1) I've done quite a bit of Googling, but wasn't able to find any articles discussing Chrome or other browser support for Tail Call Optimization (TCO) or any future plans to implement it. My two questions are: Is TCO currently supported in Chrome or any other browser or Javascript Engine Are there plans to implement TCO in the near future in any Javascript Engine The posts that I

node.js安装及环境变量配置

若如初见. 提交于 2019-12-05 03:00:23
前言 本文详细讲解了node.js压缩包版安装配置过程,配置安装时间在十分钟左右。 下载node.js 下载并解压好 node.js,本文下载的是v8.11.1 windows64位版本。 配置node与npm 1.打开NodeJs文件目录,如下图: 2.在NodeJs文件目录下建立”node_global“及”node_cache“两个文件夹 3.启动cmd,依次输入: npm config set prefix "F:\Program Files\node-v8.11.1-win-x64\node_global" npm config set cache "F:\Program Files\node-v8.11.1-win-x64\node_cache" Ps:本文nodejs地址为F:\Program Files\node-v8.11.1-win-x64 此时在cmd输入 npm root -g 出现下图则说明配置成功: 配置环境变量 1.右键‘我的电脑’依次选择‘属性’- ->‘高级系统设置’- ->‘环境变量’,看到如下界面: 2.复制nodejs目录路径(F:\Program Files\node-v8.11.1-win-x64)然后选中用户变量中的Path,单击’编辑’- ->’新建’- ->输入刚复制的地址 - ->确认完成。 重启cmd并输入

Node.js

人盡茶涼 提交于 2019-12-05 02:42:42
Node.js是一个JS的运行环境. 基于google的V8引擎. 可以用来编写Web服务器一样的网络应用, 使JS可以通过node.js与后端互动. Node.js是非堵塞的,多条命令可同时执行. 是事件驱动的,可以不使用线程创建一个能够承载高并发的服务器. 前端可通过node.js来编写与后端互动的相关语句. 来源: https://www.cnblogs.com/jrri/p/11898959.html

Implementing inheritance in node.js bindings

南楼画角 提交于 2019-12-05 01:13:12
问题 I am writing Node.js bindings around a C++ library. I can identify key objects in the C++ library that I can expose as classes to the Node.js (i.e. derivatives of ObjectWrap). I can also see an inheritance relationship between these objects. How can I expose ClassA , ClassB , ClassC as node.js classes (derivatives of ObjectWrap ) and manipulate their prototypes (in v8 C++ code) so that ClassB and ClassC are derivates of ClassA ? 回答1: This can be done using v8::FunctionTemplate 's Inherit

Build googles v8 as shared library on windows?

 ̄綄美尐妖づ 提交于 2019-12-04 20:45:39
问题 Is it possible to build googles v8 as a shared library with gyp on windows (msvc 2012)? Everything I tried doesn't work. What I've tried: python build\gyp_v8 -Dcomponent=shared_library python build\gyp_v8 library=shared The second one gives an error that "library" is unknown. The first one does not have any effect. 回答1: This works in a project I'm using: python build\gyp_v8 -Dtarget_arch=ia32 -Dcomponent=shared_library msbuild /p:Configuration=Release /p:Platform=Win32 tools\gyp\v8.sln 来源:

Use of TerminateExecution in V8

北慕城南 提交于 2019-12-04 19:29:20
I'm experimenting with V8 at the moment. I want to be able to run some (possibly long-running) javascript in one thread and then be able to terminate the execution "gracefully" at will from another thread. I've written this simple snippet to test the concept of Lockers and the usage of TerminateExecution: void breaker( Isolate* isolate, int tid ) { getchar(); //wait for keyboard input on stdin std::cout << "Breaking V8 execution" << std::endl; v8::Locker locker( isolate ); //lock the isolate v8::V8::TerminateExecution( tid ); //and terminate it } int main( int argc, char **argv ) { if( argc !=

How to install V8js on PHP5.5?

心不动则不痛 提交于 2019-12-04 17:22:25
问题 I want to install the v8js extension for PHP5.5 on Ubuntu 12.04 but can't make it working. When I try to install the v8js extension version 0.2.0 (latest) with PECL, I have this message: configure: error: libv8 must be version 3.24.6 or greater ERROR: `/tmp/pear/temp/v8js/configure --with-v8js' failed If I try to install an old version, I have a compilation error. This message is very similar to my issue: Install v8js for php on ubuntu How can I fix this issue? EDIT: I couldn't install it on

JavaScript深入浅出第3课:什么是垃圾回收算法?

空扰寡人 提交于 2019-12-04 16:47:24
摘要: JS是如何回收内存的? 《 JavaScript深入浅出 》系列 : JavaScript深入浅出第1课:箭头函数中的this究竟是什么鬼? JavaScript深入浅出第2课:函数是一等公民是什么意思呢? JavaScript深入浅出第3课:什么是垃圾回收算法? 最近垃圾回收这个话题非常火,大家不能随随便便的扔垃圾了,还得先分类,这样方便对垃圾进行回收再利用。 其实,对于写代码来说,也有 垃圾回收(garbage collection) 这个问题,这里所说的垃圾,指的是 程序中不再需要的内存空间 ,垃圾回收指的是回收这些不再需要的内存空间,让程序可以重新利用这些释放的内存空间。 手动管理内存 对于C这种底层语言来说,我们可以使用malloc()函数分配内存空间,当所分配的内存不再需要的时候,可以使用free()函数来释放内存空间。 #include <stdio.h> #include <stdlib.h> #define TRUE 1 int main () { int *p, i, n, sum; while (TRUE) { printf ("请输入数组长度: "); scanf ("%d", &n); p = (int *) malloc (n * sizeof (int)); // 分配内存空间 sum = 0; for (i = 0; i < n; ++i)