V8::Arguments中This和Holder的区别
## v8::Arguments
namespace v8 {
class Arguments {
public:
inline int Length() const;
inline Local<Value> operator[](int i) const;
inline Local<Function> Callee() const;
inline Local<Object> This() const;
inline Local<Object> Holder() const;
inline bool IsConstructCall() const;
inline Local<Value> Data() const;
inline Isolate* GetIsolate() const;
};
}
## 满眼都是问号
Length/operator[]:
一眼看去,Length和operator[]好懂,基本上就是与方法参数的值相关。
Data():
在创建FunctionTemplate时候,FunctionTemplate::New函数所提供的第二个参数。
This()/Holder():
This() corresponds to JS 'this' and should be operated upon when you'd like to have a normal JS semantics.
Holder() is the objects which is instance of your FunctionTemplate.
This()对应的是JavaScript的this,在很多情况下Holder和This其实是一样的。
在Google Group中的帖子提到了谈到了二者的区别:
The Holder value was introduced to deal with some corner cases that
happen because methods are just properties and can be moved around.
To explain it you need a bit of background but I'll get to the Holder
part in minute.
Consider this code:
var x = { };
x.createElement = document.createElement;
var div = x.createElement('div');
In the implementation of createElement we need to check what kind of
object we're being called on because createElement needs to use some
internal fields stored on the document object. To implement this we
use function signatures (by passing a Signature object to
FunctionTemplate::New for all dom methods). A signature specifies
what kind of objects a function can be called with. In this case we
would pass a signature that specifies that the receiver must be a
document and then v8 takes case of giving an error if it isn't.
However, with this type check in place there can still be problems.
Consider this code:
var x = { }
x.__proto__ = document;
var div = x.createElement('div');
In this case createElement is actually given a document, it's there in
the prototype chain, and for compatibility reasons we have to allow
this. However, 'This' is not a document so it's still not safe to try
to read internal fields from it. That's where Holder comes in. If
your function has a signature that says that it must be called on a
particular type v8 will search the prototype chain for an object of
that type when the function is called. If it is not there we given an
error. If it is there that's the value Holder will return to you.
In short: if you specify, through a Signature, that a function must
only be called on instances of function template T, the value returned
by Holder is guaranteed to hold an instance created from T or another
function template that directly or indirectly
"FunctionTemplate::Inherit"s from T. No guarantees hold about the
type of This.
## References
[This() vs. Holder()](https://groups.google.com/forum/#!topic/v8-users/fK9PBWxJxtQ)
[What is the difference between Arguments::Holder() and Arguments::This()?](https://groups.google.com/forum/#!topic/v8-users/Axf4hF_RfZo)
[V8 Javascript Engine Tutorial (Part 1)](https://www.homepluspower.info/2010/06/v8-javascript-engine-tutorial-part-1.html)
[V8 Javascript Engine Tutorial (Part 2)](https://www.homepluspower.info/2010/06/v8-javascript-engine-tutorial-part-2.html)
V8::Arguments中This和Holder的区别的更多相关文章
- DOM 中 Property 和 Attribute 的区别
原文地址:http://web.jobbole.com/83129/ property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute: ...
- DOM 中 Property 和 Attribute 的区别(转)
property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...
- How Javascript works (Javascript工作原理) (二) 引擎,运行时,如何在 V8 引擎中书写最优代码的 5 条小技巧
个人总结: 一个Javascript引擎由一个标准解释程序,或者即时编译器来实现. 解释器(Interpreter): 解释一行,执行一行. 编译器(Compiler): 全部编译成机器码,统一执行. ...
- Vue中computed与method的区别
转载于:https://segmentfault.com/a/1190000014478664?utm_source=tag-newest 1.computed区别于method的两个核心 在官方文档 ...
- 【转】为什么我们都理解错了HTTP中GET与POST的区别
GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一二. 最直观的区别就是GET把参数包含在URL中,POST通过request body传递参数. 你可能自己 ...
- Visual Studio 中 Build 和 Rebuild 的区别
因为之前写的程序比较小,编译起来比较快,所以一直都没有太在意 Build 和 Rebuild 之间的区别,后来发现两个还是有很大不同. Build 只针对在上次编译之后更改过的文件进行编译,在项目比较 ...
- SQL Server 中 EXEC 与 SP_EXECUTESQL 的区别
SQL Server 中 EXEC 与 SP_EXECUTESQL 的区别 MSSQL为我们提供了两种动态执行SQL语句的命令,分别是 EXEC 和 SP_EXECUTESQL ,我们先来看一下两种方 ...
- java集合中List与set的区别
java集合中List与set的区别. List可以存储元素为有序性并且元素可以相同. set存储元素为无序性并且元素不可以相同. 下面贴几段代码感受一下: ArrayL ...
- Java中Set Map List 的区别
java中set map list的区别: 都是集合接口 简要说明 set --其中的值不允许重复,无序的数据结构 list --其中的值允许重复,因为其为有序的数据结构 map--成对的数据结构 ...
随机推荐
- LeetCode(9) - Palindrome Number
题目要求判断一个整数是不是回文数,假设输入是1234321,就返回true,输入的是123421,就返回false.题目要求in-place,思路其实很简单,在LeetCode(7)里面我们刚好做了r ...
- geeksforgeeks@ Find sum of different corresponding bits for all pairs (Bit manipulation)
http://www.practice.geeksforgeeks.org/problem-page.php?pid=387 Find sum of different corresponding b ...
- freetds链接错误
用tsql连接mssql出现下面的错误 tsql -H 192.168.1.100 -p 1433 -U sa Password: sa locale is "en_US.UTF-8&quo ...
- 企业网管软件实战之SolarWinds LANsurveyor
SolarWinds LANsurveyor是一款比较容易掌握的网络管理软件,他能自动探索你的LAN或WAN,并生成全面的,易于浏览的集成了OSI 2层和 3层 拓扑数据的网络图表.其主要功能有: 1 ...
- Dagger2 scope
1. 一个没有scope的component是不能依赖于另外一个有scope的component 2.@Singleton不是真正意义的单例,比如下面 @Singleton @Component cl ...
- UIView的autoresizingMask属性
今天做相册列表的时候,发现有些 UITableViewController 属性不好记忆,然后就查找了一些资料.做一下备份. 在 UIView 中有一个autoresizingMask的属性,它对应的 ...
- Codeforces 161 B. Discounts (贪心)
题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...
- 欧几里德&扩展以及求解线性方程学习总结--附上poj1061解题报告
欧几里德算法: 欧几里德就是辗转相除法,调用这个gcd(a,b)这个函数求解a,b的最大公约数 公式: gcd(a,b)=gcd(b,a%b):并且gcd(a,b)=gcd(b,a)=gcd(-a,b ...
- hdoj 5392 Infoplane in Tina Town
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5392 #include<stdio.h> #include<cstring> ...
- getName()、getCanonicalName()、getSimpleName()异同
package classes; class Box { class Inner { } } public class TestGetName { public static void main(St ...