Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

function statement and __define(G|S)etter__ interaction

4 views
Skip to first unread message

al_9x

unread,
Jul 2, 2010, 5:43:26 AM7/2/10
to
Should one expect a function statement to trigger a call to a preexisting
setter? and subsequent calls to the function to invoke the preexisting
getter? That is what happens in Chrome and Opera, but not in Firefox 3.6.6.

In the following sample, "function foo()" statement does not call the foo
setter and what's even stranger, after it, "window.foo()" invokes the getter
but just "foo()" does not and instead calls the statement defined foo
function.

If the function statement is replaced by a function expression "var foo =
function() ..." then it bahves as expected, same as Chrome and Opera.

<html>
<head>
<script>
__defineGetter__('foo', function() {alert('foo getter'); return function()
{alert('new foo');};});
__defineSetter__('foo', function() {alert('foo setter');});
</script>
<script>
function foo()
{
alert('statement foo');
}
</script>
</head>
<body>
<button onclick="foo();">foo()</button><br>
<button onclick="window.foo();">window.foo()</button>
</body>
</html>

Here's what the standard (10.1.3) has to say about this:

"For each FunctionDeclaration in the code, in source text order, create a
property of the variable object whose name is the Identifier in the
FunctionDeclaration, whose value is the result returned by creating a
Function object as described in section 13, and whose attributes are
determined by the type of code. If the variable object already has a
property with this name, replace its value and attributes. Semantically,
this step must follow the creation of FormalParameterList properties."

So the value of the existing property is to be replaced. That appears to be
consistent with calling the setter with the new value, as Chrome and Opera
are doing.


al_9x

unread,
Jul 6, 2010, 11:02:31 AM7/6/10
to
"al_9x" <al...@yahoo.com> wrote in message
news:PKednZ_t-ZUvKbDR...@mozilla.org...

Is this not the right group for the above? Can someone from Mozilla please
comment?


Brendan Eich

unread,
Jul 14, 2010, 3:19:39 PM7/14/10
to

This moved to es5-discuss:

https://mail.mozilla.org/pipermail/es5-discuss/2010-July/thread.html

as well as the bug you filed:

https://bugzilla.mozilla.org/show_bug.cgi?id=577325

The es5-discuss thread is settling on a change to ES5 for ISO
standardization, if I'm recalling and following correctly. The spec
change should then lead to a code change for the SpiderMonkey bug. All
very soon (in time for ISO standardization of ES5, and for Firefox
4!).

/be

0 new messages