Namespaces in ECMA

Alexandre Bergel Alexandre.Bergel at hpi.uni-potsdam.de
Mon Jul 16 02:15:13 PDT 2007


Thanks for your answer.
I would be delighted to test the new interpreter and/or to "debug"  
the info on the wiki :-)

Regards,
Alexandre


On 16 Jul 2007, at 04:17, Lars T Hansen wrote:

> On 7/15/07, Jason Orendorff <jason.orendorff at gmail.com> wrote:
>> On 7/15/07, Alexandre Bergel <Alexandre.Bergel at hpi.uni-potsdam.de>  
>> wrote:
>> > The notion of namespace of ECMA 4 is very interesting. I spent some
>> > time in reading the new javascript description [1]. I try to
>> > understand whether a "stack of namespace" is present or not at
>> > runtime. [...]
>>
>> Thanks for the question.  You're right, that wiki page doesn't seem
>> to say.
>>
>> The scope of "use namespace" is determined statically.  So is the  
>> "set
>> of open namespaces" that the spec talks about.  When the spec says
>> "context", it means the lexical context. The runtime stack is not  
>> a factor.
>>
>> When an expression like "this.update()" is evaluated, the runtime
>> searches the open namespaces, in order, until an "update" property is
>> found.  The sequence of namespaces to search is determined
>> statically.  The search happens at runtime, because you can't tell
>> statically which properties the runtime value of "this" will have.
>>
>> > Is there a chance to get a fixed interpreter ?
>>
>> Yes, in time.  Both the spec and the reference implementation are
>> works in progress.
>>
>> For the impatient, this example can be munged into a form the
>> current interpreter can handle:
>>
>>   >> namespace N1;
>>   >> namespace N2;
>>   >> N1 var x: int = 10;
>>   >> N2 var x : String = "hello";
>>   >> {use namespace N1; print(x);}
>>   10
>>
>> Likewise:
>>
>>   >> namespace V2;
>>   >> class Component {function paint() {print("Component paint")}
>> function update() {this.paint()} V2 function paint() {print 
>> ("Component
>> paint V2")}}
>>   >> {use namespace V2; var c = new Component; c.update();}
>>   Component paint
>
> This is to my knowledge not a bug in the interpreter.  "use namespace"
> can only be used at the top of a block, not at the top level.  This
> fact is probably well hidden on the wiki pages :-/
>
> --lars

-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.






More information about the Es4-discuss mailing list