Re: Question about GetBindingValue

2014-08-29 Thread Sukyoung Ryu
Thank you all for your answers!  Your answers were really helpful.

Best,
--
Sukyoung


On Aug 30, 2014, at 12:34 AM, Allen Wirfs-Brock wrote:

 
 On Aug 29, 2014, at 4:07 AM, André Bargull wrote:
 
 ...
 
 We checked with the recent ES6 draft but it seems to have the same issue.
 
 In ES6 it's actually possible to reach that step (8.1.1.2.6 GetBindingValue, 
 step 5), albeit it's a somewhat tricky and involves doing unusual things 
 with proxy objects:
 
 ,,,
 Proxy objects allow you to define your own [[HasProperty]] implementation 
 (the has method in the example above). In this case [[HasProperty]] will 
 return `true` on the first call in order to report a binding is present in 
 HasBinding, but then will return `false` when the binding's presence is 
 checked the second time in GetBindingValue.
 
 
 And in ES5, host object have similar capabilities.  I believe we put this 
 checks in specifically to make sure everything was well defined in the 
 presence of such host objects.
 
 Allen
 

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Question about GetBindingValue

2014-08-28 Thread Sukyoung Ryu
Hello,

We found one dead part in ES5 and we're wondering whether we're missing 
something here.  The question is about the 4th step in Section 10.2.1.2.4 
GetBindingValue(N, S):

10.2.1.2.4 GetBindingValue(N,S)
The concrete Environment Record method GetBindingValue for object environment 
records returns the value of its associated binding object's property whose 
name is the String value of the argument identifier N.  The property should 
already exist but if it does not the result depends upon the value of the S 
argument:
 1. Let envRec be the object environment record for which the method was 
invoked.
 2. Let bindings be the binding object for envRec.
 3. Let value be the result of calling the [[HasProperty]] internal method of 
bindings, passing N as the property name.
 4. If value is false, then
   a. If S is false, return the value undefined, otherwise throw a 
ReferenceError exception.
 5. Return the result of calling the [[Get]] internal method of bindings, 
passing N for the argument.

We believe that the 4th step is unreachable.  In other words, whenever 
GetBindingValue(N, S) is called, the result of calling the [[HasProperty]](N) 
is always true and here's why:

Let's assume that we're calling GetBindingValue(N, S) where [[HasProperty]](N) 
is false.

1) GetBindingValue is called only by GetValue in 8.7.1.
2) 8.7.1 GetValue: Calls GetBindingValue at the 5th step only when its given 
argument is Reference.  Otherwise, it returns the argument at step 1.
3) 8.7 The Reference Specification Type: Reference is a resolved name binding 
created by evaluation of an identifier in 11.1.2.
4) 11.1.2 Identifier Reference: Evaluation of an identifier is specified in 
10.3.1.
5) 10.3.1 Identifier Resolution: Returns the result of calling 
GetIdentifierReference(lexenv, name, strict)
6) 10.2.2.1 GetIdentifierReference:
6-1) Let's assume that lexenv is not null.
6-2) Then, envRec is lexenv's environment record.
6-3) Let exists be HasBinding(N) of envRec.
   6-3-1) 10.2.1.1.2 HasBinding(N): Returns false at the 3rd step.
   6-3-1') 10.2.1.2.1 HasBinding(N): Returns [[HasProperty]](N) which is 
false by our assumption.
6-4) exists is false.
6-5) Calls GetIdentifierReference(outer, N, strict)
6-6) Let's assume that outer is null.
6-7) Returns Reference(undefined, N, strict)
7) Reference values are achieved by calling GetValue in 8.7.1.  Let's get the 
value of the reference by calling GetValue(Reference(undefined, N, strict)).
8) 8.7.1 GetValue:
8-1) Type(Reference(undefined, N, strict)) is Reference.
8-2) base is undefined.
8-3) IsUnresolvableReference(Reference(undefined, N, strict)) is true.  Throws 
a ReferenceError exception.

Thus, it does not get to the 5th step to call GetBindingValue.

10.2.1.1.4 may have a similar problem but we haven't checked it yet.  We 
checked with the recent ES6 draft but it seems to have the same issue.

Best,
--
Sukyoung


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Possible inconsistencies in the 5th edition

2012-09-13 Thread Sukyoung Ryu
Hi,

We found possible inconsistencies in the ECMAScript specification and we'd like 
to double check what we've found with experts. :-)

1) absent/present

As 8.6.1 Property Attributes says, a named accessor property may have four 
attributes: [[Get]], [[Set]], [[Enumerable]], and [[Configurable]].

As 8.10 The Property Descriptor and Property Identifier Specification Types 
says, Values of the Property Descriptor type are records composed of named 
fields where each field's name is an attribute name and its value is a 
corresponding attribute value as specified in 8.6.1.  In addition, any field 
may be present or absent.

However, in 8.10.4 FromPropertyDescriptor(Desc), the steps 4-a and 4-b do not 
check whether [[Get]] and [[Set]] are present in Desc but just access them. 
 Is it an oversight of the specification or are we missing something here?

We tried the following code:

   var o = { get abc() {} }
   x = Object.getOwnPropertyDescriptor(o, abc)
   for (y in x) { document.writeln(y); }

where 15.2.3.3 Object.getOwnPropertyDescriptor calls FromPropertyDescriptor, 
and an online JavaScript interpreter prints the following:

   get set enumerable configurable

which suggests that [[Set]] is present even though we didn't define a setter. 
 Calling the setter as follows:

   x.abc(3)

results in the following error:

   TypeError at line NaN: 'undefined' is not a function

which suggests that [[Set]] is present and its value is undefined.

So, we're confused.  When 8.10 says that any field may be present or absent, 
does the word absent mean that the field exists but its value is undefined? 
 A similar question is when the step 12 of 8.12.9 [[DefineOwnProperty]](P, 
Desc, Throw) says For each attribute field of Desc that is present, ... does 
the word present mean that the field exists and its value is not undefined? 
Yet another similar question is the step 2 of 8.10.1 
IsAccessorDescriptor(Desc): If both Desc.[[Get]] and Desc.[[Set]] are absent, 
...

Finally, when the step 2 of 8.10.2 IsDataDescriptor(Desc) says If both 
Desc.[[Value]] and Desc.[[Writable]] are absent, then return false. we might 
be able to say that Desc.[[Value]] is absent if its value is undefined, but how 
about Desc.[[Writable]]?  Its type is Boolean and its default value is false.  
Does the specification say that Does.[[Writable]] is absent if its value is 
false?


2) LabelledStatement

The first paragraph of 12 Statements says A LabelledStatement has no 
semantic meaning other than the introduction of a label to a label set.  
However, 12.12 Labelled Statements says that If the result of evaluating 
Statement is (break, V, L) where L is equal to Identifier, the production 
results in (normal, V, empty).  This might be a picky comment but I think 
because of the sentence in 12.12, a LabelledStatement has some semantic 
meaning. :-)


3) Arguments Object

10.6 Arguments Object says When control enters an execution context for 
function code, an arguments object is created unless (as specified in 10.5) the 
identifier arguments occurs as an Identifier in the function‘s 
FormalParameterList or occurs as the Identifier of a VariableDeclaration or 
FunctionDeclaration contained in the function code. which suggests that if 
there is a variable named arguments in a function body then it does not 
create the name arguments.  However, in 10.5, variable bindings in a function 
body is handled in the step 8 and checking the name arguments is in the step 
6, so even though the function body declares a variable of name arguments the 
name arguments is created.  We found them inconsistent.  What do you think?

Thank you for your comments in advance!

Best,
--
Sukyoung

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss