Response to comments:

On 2015/02/09 17:44:39, arv wrote:
I like this approach. But...

How is this going to work? new.target needs to work outside classes. That is
the
mechanism we are using to allow determining if a function was [[Call]]ed vs
[[Construct]]ed.

Sure. We cannot add new.target parameter to each and every function though -
that is expensive.
The rough sketch for new.target is as follows:
- we will determine, for every function, whether the new.target is required.
- functions that use new.target will:
- use yet another construct stub that will pass new.target to those functions
  - on entry to those functions they will determine whether they were
[[Construct]]ed or [[Call]]ed and populate their new.target in the right way. No need to do that for class constructors since they are always constructed
(and need a special construct stub anyway)


roughly:

function Date() {
   if (new.target === undefined) {
     return '2015-02-08';
   }
   return {[[TimeValue]]: 423443346, __proto__: new.target.prototype};
}

Maybe if we can keep track of `new.target` we can use the same idea for
ordinary
functions when they reference `new.target`?

https://codereview.chromium.org/908883002/diff/20001/src/compiler.cc
File src/compiler.cc (right):


https://codereview.chromium.org/908883002/diff/20001/src/compiler.cc#newcode623
src/compiler.cc:623:
function_info->set_formal_parameter_count(lit->parameter_count() + 1);
I'm worried about doing it at this high abstraction level. NewTarget is not a
formal parameter. Maybe it is better do it at a lower level abstraction in
case
other code wants to use the formal parameter count for what it sounds like
(function length, rest params etc).

The SFI already has a field for the FunctionKind so deferring this choice
seems
safer.

I thought of it, but this adds complexity to generated code with no good reason.
For example, ArgumentsAdaptor frame will need to switch on FunctionKind, but
that does not save us anything since say the code that sets up ArgumentsAccess
will need to do the same as well. And so on and so forth.
SFI's formal parameter count seems just right for this purpose - the number of
parameters that function's frame has on the stack.
If you want to get a 'true' parameter count, there is always
scope()->num_parameters()
Note that function's length is separate (there is a separate field in SFI just
for that)



https://codereview.chromium.org/908883002/diff/20001/src/runtime/runtime-object.cc
File src/runtime/runtime-object.cc (right):


https://codereview.chromium.org/908883002/diff/20001/src/runtime/runtime-object.cc#newcode1304
src/runtime/runtime-object.cc:1304: if (*original_function != *function) {
Is this is to set up the prototype from the NewTarget. Maybe add a comment?


https://codereview.chromium.org/908883002/diff/20001/test/mjsunit/harmony/classes-experimental.js
File test/mjsunit/harmony/classes-experimental.js (right):


https://codereview.chromium.org/908883002/diff/20001/test/mjsunit/harmony/classes-experimental.js#newcode161
test/mjsunit/harmony/classes-experimental.js:161: class ExtendedUint8Array
extends Uint8Array {
HOT!


https://codereview.chromium.org/908883002/diff/20001/test/mjsunit/harmony/classes-experimental.js#newcode174
test/mjsunit/harmony/classes-experimental.js:174: assertTrue(eua.__proto__ ===
ExtendedUint8Array.prototype);
Maybe a test with Object.prototype.toString to make sure the instance is the
right exotic object kind.



https://codereview.chromium.org/908883002/

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to