[Bug 15986] Specify exactly how and when ECMAScript arguments are evaluated

https://www.w3.org/Bugs/Public/show_bug.cgi?id=15986

--- Comment #5 from Allen Wirfs-Brock <allen@wirfs-brock.com> 2012-02-14 20:52:41 UTC ---
(In reply to comment #3)
> (In reply to comment #1)
...
> could become
> 
>  void drawImage(
>    (HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image,
>    double x1, double y1,
>    optional double w1, optional double h1,
>    optional double x2, optional double y2,
>    optional double w2, optional double h2);
> 
> with an extra couple lines of prose to handle the corner cases.  I don't
> suppose we could just get rid of overloading?

Note this is pretty much exactly what an ECMAScript programmer would do to
implement a similar set of operations using pure ECMAScript.  The
discrimination of the first argument type and the optional arguments would be
done in the logic of the function body. If ECMAScript is used to implement
operations defined using Web IDL then a single function like this would still
be used.  However, the Web IDL spec. requires that the function internally
perform the web IDL  over-load resolution algorithm, even if it isn't the most
efficient or effective way to implement this specific combination of logical
operations.  

Overload resolution is a one-size-fits-all solution.


> 
> (In reply to comment #2)
> 
> Do you mean this?  http://es5.github.com/#x11.2.4  That calls GetValue() on the
> arguments.  If I'm reading things correctly, calling GetValue() on {valueOf:
> function() { return 'foo'; }} will not invoke the valueOf function.  So any
> calls of that function will be only because of WebIDL.

yes, that is correct.

You can think of ValueOf as the internal specification operations that
ECMAScript uses to force evaluation of an expression.  In the case of a call
like:

foo(1+2,{valueOf: function(){return 4},3+{valueOf: function(){return 4})

ValueOf is applied in left to right order to each of the argument expressions
producing 3, an object with a valueOf method, and 7.  These are the values that
are initially assigned to the formal parameters of foo. If evaluating any of
the argument expressions had side-effects they would have occurred in left to
right order of the expressions. 

This ValueOf has no direct relationship with the user level valueOf property
defined by the object in the second argument expressions. However, evaluating
the third argument includes evaluating the + operator and evaluating + applies
the ToNumber internal operation to objects and ToNumber calls the valueOf
method.

> ...
> Operations in WebIDL operate on IDL values, and accessing IDL values can't have
> side effects, I don't think.

I wonder, might a object defined in ECMAScript meet all the type requirements
of an Web IDL interface while still producing side-effects on certain property
accesses.  This probably starts to approach the controversial topic of whether
duck typed ECMAScript objects are allowable as implementations of Web IDL
interfaces or is some form of nominal typing required.

-- 
Configure bugmail: https://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

Received on Tuesday, 14 February 2012 20:52:43 UTC