[Webkit-unassigned] [Bug 7751] Scope is broken with nested evals inside of functions.

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Jul 11 03:03:31 PDT 2007


http://bugs.webkit.org/show_bug.cgi?id=7751





------- Comment #4 from cwzwarich at uwaterloo.ca  2007-07-11 03:03 PDT -------
Created an attachment (id=15472)
 --> (http://bugs.webkit.org/attachment.cgi?id=15472&action=view)
Further reduced test case

(In reply to comment #2)

> I believe what's happening is that if the scope is not 100% "shallow" it
> refuses to allow declarations of type function [name] { } to be added to the
> global object.

It also happens for other declarations, and for single evals, not just nested
evals. I simplified your original example a bit to get the attached test case.
In Firefox and Opera it outputs "bluebird of happiness" three times, but in
WebKit it outputs "undefined" instead of the first.

However, I don't think this is actually a bug. I think Safari has the correct
behaviour here, judging by the ECMA spec. I will explain my argument.

In the spec (chapter 10, although most of what I am saying comes from section
10.2), there are a few important pieces of context-sensitive information. The
two that affect the situation in this bug report are the variable instantiation
context and the value of "this".

According to 10.2.3, when you call a function without specifying the "this"
value, it is inherited from the caller. Thus, in my example, the value of
"this" in the function body of f() the only time it is called is the global
object. The variable instantiation context is, of course, local to the function
and is not the same as the global variable instantiation context.

According to 10.2.2, for code run by using eval, the variable instantiation
context and the "this" value are inherited from the caller. If you take my
attached example and change "eval.call(this, " to simply "eval(", all three
major Mac browsers agree (I couldn't test IE) that it should output "undefined"
and then "bluebird of happiness" two times.

So, what is different when you use eval.call (or eval.apply) that causes the
other browsers to behave differently? First, note that 10.2.2 seems to imply
that evaluated code always has a "this" object of its calling context, although
that isn't the issue here, as all of the browsers agree on what the "this"
object should be. However, they disagree on what the variable instantiation
context should be. Firefox and Opera think that by passing "this" as the first
argument of call, the variable instantiation context of the evaluated code
changes to the top level. But 10.2.2 says that the variable instantiation
context is always that of the caller and is not dependent on the value of
"this". And according to 15.3.4.4, passing something as the first argument of
call could only possibly change the value of "this". Therefore, WebKit's
behaviour seems to be correct.


-- 
Configure bugmail: http://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list