简体   繁体   English

ECMA-262 7.0 GetValue(V)

[英]ECMA-262 7.0 GetValue(V)

Can anyone explain to me with examples how this algorithm works? 谁能用例子向我解释这个算法是如何工作的?

GetValue (V)#

1. ReturnIfAbrupt(V).
2. If Type(V) is not Reference, return V. 
3. Let base be GetBase(V). 
4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception. 
5. If IsPropertyReference(V) is true, then  
    a. If HasPrimitiveBase(V) is true, then  
        i. Assert: In this case, base will never be null or undefined.  
        ii. Let base be ToObject(base).  
    b. Return ? base.[[Get]](GetReferencedName(V), GetThisValue(V)). 
6. Else base must be an Environment Record,  
    a. Return ? base.GetBindingValue(GetReferencedName(V), IsStrictReference(V)) (see 8.1.1).

http://www.ecma-international.org/ecma-262/7.0/#sec-getvalue http://www.ecma-international.org/ecma-262/7.0/#sec-getvalue

It would be nice if someone with examples explained how it works. 如果有人用例子解释它是如何工作的,那就太好了。 I tried, but I did not understand much. 我试过了,但我不太了解。

Examples for explanation: 解释示例:

let a = 10, b = {name: "Unknown"};
(null, a);
(null, a.name);
(null, b);
(null, b.name);
(null, b.surname);
(null, 10);
/// etc...

This segment gives more context: 此细分提供更多背景信息:

...The Reference Specification Type# ...参考规格类型#

NOTE The Reference type is used to explain the behaviour of such operators as delete, typeof, the assignment operators, the super keyword and other language features. 注意引用类型用于解释诸如delete,typeof,赋值运算符,super关键字和其他语言特性之类的运算符的行为。 For example, the left-hand operand of an assignment is expected to produce a reference. 例如,期望赋值的左侧操作数生成引用。

A Reference is a resolved name or property binding. Reference是已解析的名称或属性绑定。 A Reference consists of three components, the base value, the referenced name and the Boolean valued strict reference flag. Reference由三个组件组成,基值,引用名称和布尔值严格引用标志。 The base value is either undefined, an Object, a Boolean, a String, a Symbol, a Number, or an Environment Record. 基值可以是undefined,Object,Boolean,String,Symbol,Number或Environment Record。 A base value of undefined indicates that the Reference could not be resolved to a binding. 基本值undefined表示无法将Reference解析为绑定。 The referenced name is a String or Symbol value. 引用的名称是String或Symbol值。

A Super Reference is a Reference that is used to represents a name binding that was expressed using the super keyword. 超级引用是一个引用,用于表示使用super关键字表示的名称绑定。 A Super Reference has an additional thisValue component and its base value will never be an Environment Record. 超级引用具有附加的thisValue组件,其基值永远不会是环境记录。

The following abstract operations are used in this specification to access the components of references: 本规范中使用以下抽象操作来访问引用的组件:

  • GetBase(V). GetBase(V)。 Returns the base value component of the reference V. 返回引用V的基值组件。
  • GetReferencedName(V). GetReferencedName(V)。 Returns the referenced name component of the reference V. 返回引用V的引用名称组件。
  • IsStrictReference(V). IsStrictReference(V)。 Returns the strict reference flag component of the reference V. 返回引用V的严格引用标志组件。
  • HasPrimitiveBase(V). HasPrimitiveBase(V)。 Returns true if Type(base) is Boolean, String, Symbol, or Number. 如果Type(base)是Boolean,String,Symbol或Number,则返回true。
  • IsPropertyReference(V). IsPropertyReference(V)。 Returns true if either the base value is an object or HasPrimitiveBase(V) is true; 如果基值是对象或HasPrimitiveBase(V)为true,则返回true;否则返回true。 otherwise returns false. 否则返回false。
  • IsUnresolvableReference(V). IsUnresolvableReference(V)。 Returns true if the base value is undefined and false otherwise. 如果基值未定义则返回true,否则返回false。
  • IsSuperReference(V). IsSuperReference(V)。 Returns true if this reference has a thisValue component. 如果此引用具有thisValue组件,则返回true。 The following abstract operations are used in this specification to operate on references... 本规范中使用以下抽象操作来操作引用...

This is language internals. 这是语言内部。 From a quick glance it looks like it is related to type inference before additional actions are performed on the value. 从快速浏览一下,在对值执行附加操作之前,它看起来与类型推断有关。 This kind of operations are performed on a lower level when you call things like 当你打电话时,这种操作会在较低的级别上执行

delete someObject.prop

or 要么

typeof someVarIdentifier

Example: 例:

("" + a);

Parse expression -> getValue("") + getValue(a) -> string{""} + (number{10} -> cast to string) -> concat("","10") -> "10" Parse表达式 - > getValue(“”)+ getValue(a) - > string {“”} +(number {10} - > cast to string) - > concat(“”,“10”) - >“10”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM