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
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...
1 Answers
Answers 1
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. For example, the left-hand operand of an assignment is expected to produce a reference.
A Reference is a resolved name or property binding. A Reference consists of three components, the base value, the referenced name and the Boolean valued strict reference flag. The base value is either undefined, an Object, a Boolean, a String, a Symbol, a Number, or an Environment Record. A base value of undefined indicates that the Reference could not be resolved to a binding. The referenced name is a String or Symbol value.
A Super Reference is a Reference that is used to represents a name binding that was expressed using the super keyword. A Super Reference has an additional thisValue component and its base value will never be an Environment Record.
The following abstract operations are used in this specification to access the components of references:
- GetBase(V). Returns the base value component of the reference V.
- GetReferencedName(V). Returns the referenced name component of the reference V.
- IsStrictReference(V). Returns the strict reference flag component of the reference 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 reference has a thisValue component. 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"
0 comments:
Post a Comment