## 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的区别的更多相关文章

  1. DOM 中 Property 和 Attribute 的区别

    原文地址:http://web.jobbole.com/83129/ property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute: ...

  2. DOM 中 Property 和 Attribute 的区别(转)

    property 和 attribute非常容易混淆,两个单词的中文翻译也都非常相近(property:属性,attribute:特性),但实际上,二者是不同的东西,属于不同的范畴. property ...

  3. How Javascript works (Javascript工作原理) (二) 引擎,运行时,如何在 V8 引擎中书写最优代码的 5 条小技巧

    个人总结: 一个Javascript引擎由一个标准解释程序,或者即时编译器来实现. 解释器(Interpreter): 解释一行,执行一行. 编译器(Compiler): 全部编译成机器码,统一执行. ...

  4. Vue中computed与method的区别

    转载于:https://segmentfault.com/a/1190000014478664?utm_source=tag-newest 1.computed区别于method的两个核心 在官方文档 ...

  5. 【转】为什么我们都理解错了HTTP中GET与POST的区别

    GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一二. 最直观的区别就是GET把参数包含在URL中,POST通过request body传递参数. 你可能自己 ...

  6. Visual Studio 中 Build 和 Rebuild 的区别

    因为之前写的程序比较小,编译起来比较快,所以一直都没有太在意 Build 和 Rebuild 之间的区别,后来发现两个还是有很大不同. Build 只针对在上次编译之后更改过的文件进行编译,在项目比较 ...

  7. SQL Server 中 EXEC 与 SP_EXECUTESQL 的区别

    SQL Server 中 EXEC 与 SP_EXECUTESQL 的区别 MSSQL为我们提供了两种动态执行SQL语句的命令,分别是 EXEC 和 SP_EXECUTESQL ,我们先来看一下两种方 ...

  8. java集合中List与set的区别

       java集合中List与set的区别.     List可以存储元素为有序性并且元素可以相同.     set存储元素为无序性并且元素不可以相同.     下面贴几段代码感受一下: ArrayL ...

  9. Java中Set Map List 的区别

    java中set map list的区别: 都是集合接口 简要说明 set --其中的值不允许重复,无序的数据结构 list   --其中的值允许重复,因为其为有序的数据结构 map--成对的数据结构 ...

随机推荐

  1. APIO2014 爆零总结

    真心爆零 不要不服 这次apio给了一种新的赛制 看上去很好? 所有人都可以在线提交 并且实时知道自己的分数 它对每个题目分成若干分数段 每个分数段有若干数据 要获得这个分数段的分数需要通过这个分数段 ...

  2. 轻松学习Linux之理解Shell的硬链接与软连接

     大家在学习linux的过程中常常遇到一些模糊且容易混淆的概念比如什么是硬链接和软链接,他们有什么区别?  软连接有点象windows中的快捷方式,连接和目标文件具有相同的节点,而硬连接就好象重新复制 ...

  3. 通过Microsoft Azure服务设计网络架构的经验分享(转)

    原文:http://www.infoq.com/cn/articles/azure-networking-tips 本文从产品设计和架构角度分享了 Microsoft Azure 网络服务方面的使用经 ...

  4. <转载>内存管理内幕-动态分配的选择、折衷和实现 对malloc内存分配有个简单的描述,对内存管理有个大致的说明

    这篇文章看后感觉不错,和我在glibc下的hurdmalloc.c文件里关于malloc的实现基本意思相同,同时,这篇文章还介绍了一些内存管理方面的知识,值得推荐. 原文链接地址为:http://ww ...

  5. 安装完Oracle之后的注意事项

    1.修改密码过期问题.ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; 2.修改最大连接数问题. alter system set p ...

  6. 在VS2013中使用水晶报表

    又遇到了在B/S系统中打印,打印格式要求比较高,打印出的效果要求高大上.用VS2013中微软自带的报表,实在难以实现应用的效果,主要问题表现在: 1.不能插入用Word做好的打印模板,自己按照模板来做 ...

  7. 题目连接:http://acm.zznu.edu.cn/problem.php?id=1329

    题目大意: 定理:把一个至少两位的正整数的个位数字去掉,再从余下的数中减去个位数的5倍.当且仅当差是17的倍数时,原数也是17的倍数 . 例如,34是17的倍数,因为3-20=-17是17的倍数:20 ...

  8. 了解 JavaScript 中的内置对象

    所有编程语言都具有内部(或内置的)对象来创建 语言的基本功能.内部对象是 您编写自定义代码所用语言的基础, 该代码基于您的想象实现自定义功能.JavaScript 有许多 将其定义为语言的内部对象.本 ...

  9. CodeForces 711D Directed Roads (DFS判环+计数)

    题意:给定一个有向图,然后你可能改变某一些边的方向,然后就形成一种新图,让你求最多有多少种无环图. 析:假设这个图中没有环,那么有多少种呢?也就是说每一边都有两种放法,一共有2^x种,x是边数,那么如 ...

  10. My集合框架第六弹 左式堆

    左式堆(Leftist Heaps)又称作最左堆.左倾堆.左式堆作为堆的一种,保留了堆的一些属性. 第1,左式堆仍然以二叉树的形式构建: 第2,左式堆的任意结点的值比其子树任意结点值均小(最小堆的特性 ...