From: kangax on
Asen Bozhilov wrote:
> Dmitry A. Soshnikov wrote:
>
>> But if you need to declare a local variable of some function context,
>> you still have to use `eval`, as there's no ability to access the
>> activation object (which stores declared variable) of the function
>> context.
>
> Dmitry that isn't only approach to declare *local* variable. He cans
> put in the front of the scope chain `object' which haves property for
> instance name using `with' statement:
>
> function testFn()
> {
> with({'instance_name' : new Foo()})
> {
> window.alert(instance_name);
> }
> };
>
> `with' statement put on the front of Scope Chain reference to `object'
> which have property `instance_name'. Resolving properties against
> Scope Chain here is interesting part.
>
> Global Object <- Global execution context

-------------------^

It could as well be an `Object.prototype` here, since, as we know,
Global Object's [[Prototype]] is implementation dependent (and does in
fact inherit from Object.prototype in many implementations).

> ^
> AO/VO <- `testFn'

--------------^

[[Prototype]] of AO/VO could also refer to `Object.prototype` here,
since ES3 implicitly permits it (and some implementations, e.g.
Blackberry browser, do implement it that way).

It could also reference any other object, of course.

[...]

--
kangax
From: kangax on
Dmitry A. Soshnikov wrote:
> On Nov 28, 5:51 pm, Asen Bozhilov <asen.bozhi...(a)gmail.com> wrote:
>
> [...]
>
>> Dmitry that isn't only approach to "declare" local variable.
>>
>
> What exactly do you mean? The only way to declare variable is to use
> `var` keyword. If to summarize points which could be related to

I guess it would depend on what exactly you mean by "to declare a
variable", but I would say that function declaration "declares a
variable" too ;)

[...]

--
kangax
From: Dmitry A. Soshnikov on
On Nov 29, 4:10 am, Asen Bozhilov <asen.bozhi...(a)gmail.com> wrote:
> Dmitry A. Soshnikov wrote:
>

[...]

> > If to summarize points which could be related to
> > `variable` (regardless syntax rules such as `VariableStatement` -
> > 12.2, ES-3) we can get the following:
>
> > (1) affecting on the VO/AO;
> > (2) created on entering execution context (main sign);
> > (3) get {DontDelete} attribute unless type of code is `eval`.
>
> > The point (1) is used to show that not every named object is affected
> > on VO/AO, e.g. named function expression (NFE) which by specification
> > should keep optional identifier in special object added in front of
> > scope chain but not in VO/AO itself; but as you know there're some non-
> > conformant impementations as some versions of JScript, including
> > current version.
>
> Of course but, using indirect call of `eval' at the moment you can be
> sure to defined local variable, because `eval' use VO of calling
> execution context.
> ECMA 262-3
>
> | 10.2.2 Eval Code
> | Variable instantiation is performed using the calling context's
> | variable object and using empty property attributes.
>
> But in ECMA 5 in strict mode you cannot be create local variable using
> indirect call of `eval'
>
> | 10.4.2.1  Strict Mode Restrictions
> | The eval code cannot instantiate variable or
> | function bindings in the variable environment of the calling
> | context that invoked the eval if either the code
> | of the calling context or the eval code is strict code. Instead
> | such bindings are instantiated in a new
> | VariableEnvironment that is only accessible to the eval code.
>

Yeah, thanks, I know that.

> > The point (2) I suggest to use as a main sign to distinguish them from
> > the properties added to the special object of `with` statement and
> > `catch` clause. The two last will be available in the scope chain at
> > runtime, but not right after entering the execution context.
>
> `eval' defined properties of VO runtime too.
>

Yes, but formal parameter is also created on entering execution
context. So, the main sign (if do not use combination of "created on
entering context" + "always has `undefined` value") is - _always_ has
`undefined` value on entering the context. Any other entities
affecting on VO/AO do not require this condition (formal parameters,
repeat, have values if values are passed).

> > Moreover, regarding `with`, it doesn't declare that properties of its
> > special object should have {DontDelete} attributes, it depends on
> > object itself. So, in simple case we can delete this property:
>
> > with ({a: 10}) {
> >   alert(typeof a); // number
> >   delete a;
> >   alert(typeof a); // undefined
>
> > }
>
> No, here depend from internal attribute {DontDelete} of property which
> want to deleted.
>

Didn't I say the same? I said - from difference of `var` (not in
`eval` context) special object of `with` statement doesn't require
that all of it's properties should have {DontDelete}. So, {DontDelete}
was related sure to properties of the object, but not the object
itself ;)

/ds
From: Dmitry A. Soshnikov on
On Nov 29, 5:28 am, kangax <kan...(a)gmail.com> wrote:

[...]

>
> [[Prototype]] of AO/VO could also refer to `Object.prototype` here,
> since ES3 implicitly permits it (and some implementations, e.g.
> Blackberry browser, do implement it that way).
>

Yep, "implicitly" here is the main word which can serves as
justification. Funny, but yep, ECMA-262-3 doesn't say anything about
Activation object - should it be some special internal object, or
should it be simple object `as by new Object` or anything else? So
Blackberry didn't think much here and used simple object which
inherits from `Object.prototype`. Regarding special object for
optional identifier of NFE, Spidermonkey doesn't break the rules as
they did it conforming to the specification where is written: 'as by
new Object', so this is "error" of specification, thought, other
implementations fix this editorial error, as the guessed to do with
Activation object (in difference from Blackberry) - do not set
prototype to it at all, or at least not inherit from
`Object.prototype` ;)

/ds
From: Dmitry A. Soshnikov on
On Nov 29, 5:36 am, kangax <kan...(a)gmail.com> wrote:
> Dmitry A. Soshnikov wrote:

[...]

> > What exactly do you mean? The only way to declare variable is to use
> > `var` keyword. If to summarize points which could be related to
>
> I guess it would depend on what exactly you mean by "to declare a
> variable", but I would say that function declaration "declares a
> variable" too ;)
>

I suggest to take for a basis 10.1.3, ES-3 section. The main
difference of `var` (not of `eval` code) from other (FD and formal
parameters) is that `var` _always_ has `undefined` value on entering
execution context stage. FD have concrete value, formal parameters
also can have values if they passed.

/ds
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5
Prev: Native Objects .prototype extending
Next: The 3rd way