v8

Does JavaScript have the equivalent of Python's __getattribute__?

寵の児 提交于 2019-12-13 03:01:58
问题 Does JavaScript have the equivalent of Python's __getattribute__ ? In the sense that I'd like an object, a , for which a reference to a property x is equivalent to a.__get__('x') . Trying to get this to work in V8. Possible? Example: an object which makes REST-ful calls: RESTful("some-url").foo({x:1}) => response of call to "some-url/foo?x=1" 回答1: It is not possible for properties, though there is a non-standard way (__noSuchMethod__) for methods which is only available for Firefox. 来源: https

v8: Array of objects

牧云@^-^@ 提交于 2019-12-13 00:17:07
问题 I'm transforming a parser for v8 in NodeJS. Currently I have the following structure struct Node { short tag; std::string data; Node(std::string input, short tagId) { tag = tagId; data = input; } }; std::vector<Node> elems; And I'm populating the vector from loop like this: elems.push_back(Node(STRING, 3)); My goal is return a javascript object like this: [ { tag: 2, data: "asdsad" }, { tag: 2, data: "asdsad" }, { tag: 2, data: "asdsad" } ] But since the V8 documentation is crappy, I couldn't

Can't access V8 Context in “callback” function

我的梦境 提交于 2019-12-13 00:15:16
问题 I am writing a NodeJS addon where I use a C library that lets you register a callback at certain events. When the callback is fired I want to call a NodeJS callback function. The problem is that in my C callback function I get a segmentation fault when trying to do anything V8 related, like creating a HandleScope. In test.js: ... myaddon.register(function(data) { console.log("data: " + JSON.stringify(data)); }); ... In test.c: #include <stdlib.h> #include <stdio.h> #include <string.h>

大多数前端工程师了解但并不擅长的HTML语义化

时光怂恿深爱的人放手 提交于 2019-12-13 00:01:19
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 下面两段代码从HTML语义化的角度来看有什么问题? <!-- more --> <!-- 示例1 --> <label>作者: <input type="author" texture="deep pile"></label> <!-- 示例2 --> <body> <h1>【深度】扒开V8引擎的源码,我找到了你们想要的前端算法</h1> <h2>下次面试官再问算法,用它怼回去!</h2> ... 读者可以先试试将上面例子中的代码进行语义化,再来看文末的答案。 HTML 语义化(按照 W3C 规范正确地使用标签元素和其属性,以下简称“语义化”,HTML 指 HTML5)被很多文章提到,但内容大多是先宣传语义化的必要性,然后劝说读者在开发中多使用语义化标签。 本文不宣传必要性, 也不卖力推荐大多数读者能写出语义化的代码,只对语义化的现状进行探究,并给出可行的语义化操作方式。 语义化的现状 我们以非语义化标签的滥用为例来看看目前网页的语义化程度。 非语义化的标签其实只有两个 div 和 span,本来这两个标签只是作为默认标签的补充,但现实是它们的使用频率却远超其它语义化标签。 下面是一段统计标签数量的 js 脚本,用它可以统计出网页上各个标签数量和占比。 打开浏览器控制台,执行下面的代码就可以得到结果。 var

Hidden classes and equivalence between {} object vs. custom constructor (v8)

 ̄綄美尐妖づ 提交于 2019-12-12 19:05:04
问题 Given this article: http://richardartoul.github.io/jekyll/update/2015/04/26/hidden-classes.html If you create a constructor such as: function Point(x,y) { this.x = x; this.y = y; } Then doing this: var obj1 = new Point(1,2); var obj2 = new Point(3,4); obj1.a = 5; obj1.b = 10; obj2.b = 10; obj2.a = 5; means you get some sort of performance optimizations under the hood. I'm wondering though, if you just do this instead: var obj1 = { a: 5, b: 10 } var obj2 = { b: 10, a: 5 } Will you get the same

Any docs about V8JS in PHP?

偶尔善良 提交于 2019-12-12 18:17:38
问题 Is there any documentation about V8JS? Do I need only standard PHP or some extensions to use V8JS? I'll be very thankful for any information about V8JS in PHP. 回答1: Requirements PHP 5.3.3+ and V8 library and headers installed in proper paths. Install 回答2: I've found this docs on the v8js class. 回答3: The docs out there aren't complete or are not updated. I'm actually currently in the process of doing v8JS myself and it took me a few days to get the back end libs sorted out. First off, you must

Cross platform recursive file list using C++?

筅森魡賤 提交于 2019-12-12 18:16:58
问题 What is the most efficient way to recursively list files in a specific directory and its subdirectories? Should I use the standard library, or use some third party? I want this because I use v8 as a JavaScript engine, and I want to execute all scripts in some directory (and its subdirectories). If there's any built-in way to do that in v8, great :) It should support Windows, Linux and OS X. Thanks. 回答1: For a generic cross-platform C++ solution, check out boost::filesystem 来源: https:/

Return `undefined` from Python function with PyV8?

烈酒焚心 提交于 2019-12-12 17:32:05
问题 I'm using PyV8 and I'd like to call a javascript function with undefined . It seems that evaluating both undefined and null return Python's None value: >>> evaljs("undefined") None >>> evaljs("null") None The problem, of course, is that they're not the same in javascript: >>> evaljs("undefined === null") False False >>> evaljs("undefined") == evaljs("null") None None True Is there any nice way to go about doing this? I'd actually like to write a Python function, callable from javascript,

Customized Stack Traces in Google Chrome Developer Tools?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 16:01:06
问题 I'm looking to customize the items that show up in the strack trace panel in the Scripts tab of Google Chrome's developers tools. Specifically, I want to filter out items in the stack trace and to add more descriptive names to some of the items on the stack trace without having to rename my objects and functions. I found V8's Stack Trace API at http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi but overriding Error.prepareStackTrace doesn't seem to have any effect. 回答1: The description

how to deliver c++ array to node.js using v8 native addon

陌路散爱 提交于 2019-12-12 13:48:57
问题 I implemented a c++ addon module that creates some buffer using unsigned char(uint8_t) memory and delivers it to node.js. ---- c++ addon.cpp ---- void get_frame_buffer(const FunctionCallbackInfo<Value>& args){ Isolate* isolate = helper.get_current_isolate(); if (!args[0]->IsUint32()&& !args[1]->IsUint32()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments"))); return; } int width = args[0]->Uint32Value(); int height = args[1]->Uint32Value(); uint8_t