ECMA-262 7.0 GetValue (V)

Can someone explain me examples of 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

It would be nice if someone with examples explained how this works. I tried, but I did not quite understand.

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... 
+7
javascript ecmascript-6
source share
1 answer

This segment gives more context:

... Reference Specification Type #

NOTE. The Reference type is used to explain the behavior of such operators as delete, typeof, assignment operators, super keyword and other language functions. For example, the left is assumed that the operand of the job will give a link.

A reference is a resolved name or property binding. A link consists of three components, a base value, a reference name, and a boolean meaning strong reference flag. Base value undefined, object, boolean, string, character, number, or environmental record. A base value of undefined indicates that the Link cannot be resolved by binding. The specified name is a String or Symbol value.

A reference directory is a link that is used to indicate a name that has been expressed using the super keyword. Super reference has an additional component thisvalue, and its basic value will never be an entry about the environment.

The following abstract operations are used in this specification: access to link components:

  • GetBase (V). Returns the base value component of reference V.
  • GetReferencedName (V). Returns the link component of the name link V.
  • IsStrictReference (V). Returns a strict reference flag for link component V.
  • HasPrimitiveBase (V). Returns true if Type (base) is Boolean, String, Symbol or Number.
  • IsPropertyReference (V). Returns true if either the base value is an object or HasPrimitiveBase (V) is true; otherwise returns false.
  • IsUnresolvableReference (V). Returns true if the base value is undefined and false otherwise.
  • IsSuperReference (V). Returns true if this link has this component. The following thesis operations are used in this specification for working with links ...

These are internal languages. With a quick glance, it looks like it is associated with type inference before additional actions are performed on the value. Such operations are performed at a lower level when you call things like

 delete someObject.prop 

or

 typeof someVarIdentifier 

Example:

 ("" + a); 

Expression parse → getValue (") + getValue (a) → string {" "} + (number {10} → cast to string) → concat (" "," 10 ") →" 10 "

+1
source share

All Articles