v8

v8js-在PHP中运行javascript代码

五迷三道 提交于 2019-12-06 05:00:26
起因 之前写自动登录操作一个网站的PHP脚本,但是发现该网站用js代码做了cookie的计算和验证,所以使用了v8js。 安装 安装v8。(Mac:brew install v8) 使用pecl install v8js 安装的过程中要求输入v8的安装目录。 安装完之后,把生成的.so动态链接库引入到ini文件中。 include_path = ".:/usr/lib/php/pear" extension=/usr/lib/php/extensions/no-debug-non-zts-20160303/v8js.so 用php -i | grep v8js查看v8扩展的运行状态。 使用 <?php $v8 = new V8Js(); /* basic.js */ $JS = <<< EOT len = print('Hello' + ' ' + 'World!' + "\\n"); len; EOT; try { var_dump($v8->executeString($JS, 'basic.js')); } catch (V8JsException $e) { var_dump($e); } ?> 以上例程会输出: Hello World! int(13) 相信很多人在刚接触前端或者中期时候总会遇到一些问题及瓶颈期

locate corresponding JS source of code which is not optimized by V8

走远了吗. 提交于 2019-12-06 04:37:30
问题 I try to optimize the performance of a node.js application and therefore I am analyzing the behavior of V8's JIT compiler. When running the application via node --trace_deopt --trace_opt --code_comments --print_optcode ... , the output contains many recurring lines like the following: [didn't find optimized code in optimized code map for 0x490a8b4aa69 <SharedFunctionInfo>] How can I find out which javascript code corresponds to 0x490a8b4aa69 ? The full output is available here. 回答1: That

Node.JS process uses 1.4 GB of memory, but heapdump is only 300 MB

狂风中的少年 提交于 2019-12-06 04:21:52
问题 I'm running a Socket.IO server with Node.JS, which normally uses about 400 MB of memory, because there's a lot of data being cached to send to clients. However, after a couple of hours it suddenly starts growing to 1.4 GB of usage over about 40 minutes. Someone told me to use heapdump to find if there is a memory leak. The problem is that the heapdump only turned out to be 317 MB and nothing in it looks out of the ordinary, so I'm stuck with debugging. I've also run it with nodetime, which

Execute browser page/javascript from a script/command-line

最后都变了- 提交于 2019-12-06 04:21:49
问题 Hope this isnt a stupid question. I have recently had an idea about something which I am very curious about. I am a fan of Node.js (not really relevent here I think) and the V8 engine but I was wondering if its possible to run a browser (get it to execute JS) but INTERNALLY. What I mean by that is to create a program (possibly using the V8 engine) which can open a page (as if in the browser) and execute its javascript. For instance say I have the below file hosted on www.mysite.co.uk/home.php

How do the various Javascript optimization projects affect DOM performance?

左心房为你撑大大i 提交于 2019-12-06 04:08:52
问题 There's a lot of capital C, capital S computer science going into Javascript via the Tracemonkey, Squirrelfish, and V8 projects. Do any of these projects (or others) address the performance of DOM operations, or are they purely Javascript computation related? 回答1: The performance of pure DOM operations (getElementById/Tagname/Selector, nextChild, etc) are unaffected as they're already in pure C++. How the JS engine improvements will effect performance does depend to an extent on the

前端知识体系-NodeJS相关】NodeJS基础知识全面总结

让人想犯罪 __ 提交于 2019-12-06 03:34:59
NodeJS基础知识 1. Node的全局对象和全局变量 1.1 全局对象:所有模块都可以调用的 global:表示Node所在的全局环境,类似于浏览器的window对象。 process:该对象表示Node所处的当前进程,允许开发者与该进程互动。 console:指向Node内置的console模块,提供命令行环境中的标准输入、标准输出功能。 1.2 全局函数 定时器函数:共有4个,分别是setTimeout(), clearTimeout(), setInterval(), clearInterval(); require:用于加载模块; Buffer():用于操作二进制数据。 1.3 全局变量 __filename:指向当前运行的脚本文件名。 __dirname:指向当前运行的脚本所在的目录。 2. Node的三大特点 2.1 单线程 Node.js不为每个客户连接创建一个新的线程,而仅仅使用一个线程。当有用户连接了,就触发一个内部事件,通过非阻塞I/O、事件驱动机制,让Node.js程序宏观上也是并行的。 2.2 非阻塞I/O 由于Node.js中采用了非阻塞型I/O机制,因此在执行了访问数据库的代码之后,将立即转而执行其后面的代码,把数据库返回结果的处理代码放在回调函数中,从而提高了程序的执行效率。 当某个I/O执行完毕时,将以事件的形式通知执行I/O操作的线程

Electron - How to load a html file into the current window?

北战南征 提交于 2019-12-06 02:59:40
问题 I was looking all around: docs, google, etc., on how to load a html file in the main window of an electron app, but I can't find a way. Is it really this complicated or dead simple? With what I have came up is ajax, thus works: $("#main").load("./views/details.html"); Another method I have found is via remote: const {BrowserWindow} = require('electron').remote let win = new BrowserWindow({width: 800, height: 600}) win.loadURL('https://github.com') But this opens always a new window, and I

NodeJS: calling global.gc() doesn't reduce memory to minimum?

南笙酒味 提交于 2019-12-06 01:54:19
问题 To investigate memory leaks, I have setup a route that triggers global.gc() at every POST /gc app.post('/gc', function(req, res){ global.gc(); }); However, I've noticed that if I spam this request, it reduces the memory usage more and more each time. Shouldn't calling global.gc() once is enough to reduce the memory to minimum ? If so, why does calling multiple times consecutively reduces memory at every call ? (I'm using Node.js v0.12) 回答1: At a very high level, V8 splits up GC into two parts

Google V8 Javascript Engine, Ubuntu and PHP - how to get it built and working?

北慕城南 提交于 2019-12-05 23:25:35
some help would be much appreciated here. I am running Ubuntu 10.04, I want to use the V8 Javacript engine inside PHP. Has anyone managed to do this yet? So I installed libv8-2.0.3 , libv8-dbg , libv8-dev from the software centre. Then I tried: sudo pecl install v8js-0.1.2 . This failed due to (i think) this: /tmp/pear/temp/v8js/v8js.cc:220: error: no matching function for call to ‘v8::Array::Get(unsigned int&)’ and /tmp/pear/temp/v8js/v8js.cc:438: error: ‘ContextDisposedNotification’ is not a member of ‘v8::V8’ I am assuming it is because the packaged version of libv8 is too old? I checked

Pass Node.js Buffer to C++ addon

a 夏天 提交于 2019-12-05 23:18:27
test.js buf = new Buffer(100); for (var i = 0; i < 100; i++) buf[i] = i addon.myFync(buf); addon.cpp Handle<Value> set(const Arguments& args) { char *buf = SOMETHING(args[0]); return Undefined(); } How to get the pointer to a data of the buffer inside the C++ function? What should I write in place of SOMETHING(args[0]) ? I have node_buffer.h opened in my editor, but I cannot figure out. Node version = v0.10.29 You can do: char* buf = node::Buffer::Data(args[0]); to directly access the bytes of a Buffer . According to the node.js node binding documentation the 'arg[0]' value argument can be