Not forcing super in derived class's constructor?

2015-05-07 Thread Glen Huang
TLDR: If `this` is used without `super` (which should be statically 
analyzable), let it refer to Object.create(new.target.prototype). Otherwise, 
let super creates what it refers to.

I know the reason to force `super` in derived class's constructor is to make 
sure `this` refers to the exotic object the base class might allocate.

But I bet in real world, extending base classes who only create ordinary 
objects is more common than extending those create exotic objects. And forget 
to call super is going to be frequent mistake. In es5, when you extend a class 
like this

```js
function Foo() {
Bar.call(this)
}
Foo.prototype = Object.create(Bar.prototype);
```

`this` refers to Object.create(new.target.prototype). So I wonder if we can 
keep this behavior, making things less surprising when people transit to es 
2015?
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Fixing `Promise.resolve()`

2015-05-07 Thread C. Scott Ananian
Hopefully everyone has had a little bit of time to think over the
issues with Promise.resolve().

Last week I proposed three different reasonable semantics for
`Promise.resolve`, none of which involve the `[[PromiseConstructor]]`
internal field:
https://esdiscuss.org/topic/subclassing-es6-objects-with-es5-syntax#content-50

I continue to feel that the "no species" proposal is the best
alternative, reasoning that `Promise.resolve` is more like an explicit
constructor than an species-using instance-transformation method.
Here's that proposal again:

> Promise.resolve(x)
> 1. Let C be the this value.
> 2. If IsPromise(x) is true,
>  a. Let constructor be the value of Get(x, "constructor").
>  b. ReturnIfAbrupt(constructor)
>  c. If SameValue(constructor, C) is true, return x.
> 3. Let promiseCapability be NewPromiseCapability(C).
> 4. ReturnIfAbrupt(promiseCapability).
> 5. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, «x»).
> 6. ReturnIfAbrupt(resolveResult).
> 7. Return promiseCapability.[[Promise]].

All mentions of [[PromiseConstructor]] should then be
garbage-collected from the spec.

This simplifies the semantics and fixes the "hidden new.target"
brokenness which affects interoperability with code written in ES5
syntax.  Eliminating "species" here also yields more useful behavior
from `P.resolve` if an subclass sets `P[Symbol.species] !== P`.

It's my understanding that Mark Miller volunteered to champion the
changes to `Promise.resolve` at the next TC39 meeting.  (Thanks,
Mark!).

I'll update `es6-shim` and `core-js`/`babel` if/when TC39 reaches
consensus on this.

Thanks!
 --scott
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Subclassing Function

2015-05-07 Thread Erik Arvidsson
I filed one on us: https://code.google.com/p/v8/issues/detail?id=4087

On Thu, May 7, 2015 at 4:25 PM Allen Wirfs-Brock 
wrote:

>
> On May 7, 2015, at 12:50 PM, Francisco Tolmasky wrote:
>
> > In the existing implementations I’ve tried, it appears I can’t do this:
> >
> > class SuperFunction extends Function { }
> >
> > (also tried with constructor(str) { super(str) })
> >
> > It “works”, but the resulting new SuperFunction(“return 5”) is just a
> Function, not a SuperFunction. Is Function meants to be an exception to the
> subclassing built-ins, or should it also work?
>
> Nope, it's supposed to work. `Object.getPrototypeOf(new SuperFunction("")`
> should be SuperFunction.prototype and `new SuperFunction("") instanceof
> SuperFunction` should be true.
>
> You need to file a bug report on the implementations where you tried it.
> Sounds like they still have some work to do
>
> Allen
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Subclassing Function

2015-05-07 Thread Allen Wirfs-Brock

On May 7, 2015, at 12:50 PM, Francisco Tolmasky wrote:

> In the existing implementations I’ve tried, it appears I can’t do this:
> 
> class SuperFunction extends Function { }
> 
> (also tried with constructor(str) { super(str) })
> 
> It “works”, but the resulting new SuperFunction(“return 5”) is just a 
> Function, not a SuperFunction. Is Function meants to be an exception to the 
> subclassing built-ins, or should it also work?

Nope, it's supposed to work. `Object.getPrototypeOf(new SuperFunction("")` 
should be SuperFunction.prototype and `new SuperFunction("") instanceof 
SuperFunction` should be true.

You need to file a bug report on the implementations where you tried it.  
Sounds like they still have some work to do

Allen

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Subclassing Function

2015-05-07 Thread Francisco Tolmasky
In the existing implementations I’ve tried, it appears I can’t do this:

class SuperFunction extends Function { }

(also tried with constructor(str) { super(str) })

It “works”, but the resulting new SuperFunction(“return 5”) is just a
Function, not a SuperFunction. Is Function meants to be an exception to the
subclassing built-ins, or should it also work?

Thanks,

Francisco

-- 
Francisco Tolmasky
www.tolmasky.com
tolma...@gmail.com
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: 'stream' values

2015-05-07 Thread Brendan Eich

I've been working to put the JavaScript in Java since 1995 :-D.

/be

Tab Atkins Jr. wrote:

On Thu, May 7, 2015 at 12:36 AM,  wrote:

>  That was helpful.
>
>  I find it interesting that ES6 code is very similar to Java 8 lambdas.


The relationship is closer to the other way around. ^_^

~TJ

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Parser for ES6?

2015-05-07 Thread Michael Ficarra
The Shift parser has, to my knowledge, the most complete support for ES6.
You can try it out in the online demo at
http://jsoverson.github.io/shift-visualizer/. Note that the demo is using a
slightly out of date parser, but I've asked the maintainer to update it
ASAP.

On Thu, May 7, 2015 at 8:52 AM, Mathias Bynens  wrote:

> On Thu, May 7, 2015 at 5:37 PM, Park, Daejun  wrote:
> > Is there any parser for ES6?
>
> https://github.com/shapesecurity/shift-parser-js supports ES6/ES2015
> RC2. You can read more about it here:
> http://engineering.shapesecurity.com/2015/04/two-phase-parsing.html
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
Shape Security is hiring outstanding individuals. Check us out at
*https://shapesecurity.com/jobs/
*
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Parser for ES6?

2015-05-07 Thread joe
There's my crappy transpiler:

https://github.com/joeedh/fairmotion/tree/master/tools/extjs_cc

Which uses a parser generator (and yes, the standard is quite helpful in
pointing out ways to make JS work in a bottom-up grammar).   The grammar is
inline with the code, so I've extracted it and attached it to this email.
Note that I've extended the grammar a bit, mostly to implement a type
annotation system but there are a few other non-standard things as well (I
still need to replace my python-style multiline strings with template
strings, for example).  The grammar is also a bit messy.

I believe the only thing I'm missing is template strings and some of the
new numeric literal stuff (e.g. binary literals).  I just recently added a
bunch of stuff in preparation to move my codebase to a different transpiler
(one I don't have to maintain myself).  Oh, and I think I'm missing yield
assignments in generators (e.g. var x = yield y), too.  Also, I'm not sure
if arrow functions work in all cases, I have an ambiguity in my grammar
there (which I don't feel like debugging because I'm switching to babel :)
).

The regular expression stuff is kindof interesting; figuring out how to
parse RE literals wasn't easy (it's not strictly possible to parse them
with a RE tokenizer, but I managed to hackishly make it work).

Joe


On Thu, May 7, 2015 at 8:37 AM, Park, Daejun  wrote:

> Hi,
>
> Is there any parser for ES6? It seems that no implementation completely
> supports ES6 yet (http://kangax.github.io/compat-table/es6/), and I'm
> just curious to see if there is at least a parser supporting all the
> features of ES6. For example, the grammar given in the spec seems to be fit
> to a parser generator, and I wonder if the grammar has been mechanized in
> such a parser generator or is just a written spec.
>
> Best,
> Daejun
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


grammar
Description: Binary data
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: 'stream' values

2015-05-07 Thread Tab Atkins Jr.
On Thu, May 7, 2015 at 12:36 AM,   wrote:
> That was helpful.
>
> I find it interesting that ES6 code is very similar to Java 8 lambdas.

The relationship is closer to the other way around. ^_^

~TJ
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Parser for ES6?

2015-05-07 Thread Mathias Bynens
On Thu, May 7, 2015 at 5:37 PM, Park, Daejun  wrote:
> Is there any parser for ES6?

https://github.com/shapesecurity/shift-parser-js supports ES6/ES2015
RC2. You can read more about it here:
http://engineering.shapesecurity.com/2015/04/two-phase-parsing.html
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Parser for ES6?

2015-05-07 Thread Park, Daejun
Hi,

Is there any parser for ES6? It seems that no implementation completely 
supports ES6 yet (http://kangax.github.io/compat-table/es6/), and I'm just 
curious to see if there is at least a parser supporting all the features of 
ES6. For example, the grammar given in the spec seems to be fit to a parser 
generator, and I wonder if the grammar has been mechanized in such a parser 
generator or is just a written spec.

Best,
Daejun
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: extends null

2015-05-07 Thread Glen Huang
Ah, didn't notice the special case, thanks for the heads up.

Having methods for function in the prototype chain makes sense.

Another related question: If I want to override a superclass's constructor(), 
without calling it, I should do something like this?

```js
class A extends B {
   constructor() {
   let _this = Object.create(new.target.prototype);
   return _this;
   }
}
```

Anyway to use `this` here? Having to use a different name is a bit painful.

> On May 7, 2015, at 6:55 PM, Claude Pache  wrote:
> 
> 
>> Le 7 mai 2015 à 11:49, Glen Huang > > a écrit :
>> 
>> Isn't super-constructor null in this case?
>> 
>> From step 4 in 
>> https://people.mozilla.org/~jorendorff/es6-draft.html#sec-getsuperconstructor
>>  
>> 
>> 
>> superConstructor is C.[[GetPrototypeOf]]()
>> 
>> which should be `null` after the class definition, if I'm not wrong. (But it 
>> finally throws due to type error, so technically speaking, you can't even 
>> reference the super constructor)
> 
> No, as a special case of the `extends` semantics, `C.[[GetPrototypeOf]]()` 
> will be %FunctionPrototype%; see step 6.e.ii of:
> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-runtime-semantics-classdefinitionevaluation
>  
> 
> 
> The reason is presumably that, since the constructor is a function, it should 
> always have the methods for functions (`.bind`, `.call`, etc.) on its 
> prototype chain.
> 
> The true meaning of `C extends null` is the following: The instances of `C` 
> won’t have %ObjectPrototype% in their prototype chain. (For the use cases, 
> don’t ask me.)
> 
> —Claude

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: extends null

2015-05-07 Thread Claude Pache

> Le 7 mai 2015 à 11:49, Glen Huang  a écrit :
> 
> Isn't super-constructor null in this case?
> 
> From step 4 in 
> https://people.mozilla.org/~jorendorff/es6-draft.html#sec-getsuperconstructor 
> 
> 
> superConstructor is C.[[GetPrototypeOf]]()
> 
> which should be `null` after the class definition, if I'm not wrong. (But it 
> finally throws due to type error, so technically speaking, you can't even 
> reference the super constructor)

No, as a special case of the `extends` semantics, `C.[[GetPrototypeOf]]()` will 
be %FunctionPrototype%; see step 6.e.ii of:
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-runtime-semantics-classdefinitionevaluation

The reason is presumably that, since the constructor is a function, it should 
always have the methods for functions (`.bind`, `.call`, etc.) on its prototype 
chain.

The true meaning of `C extends null` is the following: The instances of `C` 
won’t have %ObjectPrototype% in their prototype chain. (For the use cases, 
don’t ask me.)

—Claude___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: extends null

2015-05-07 Thread Claude Pache

> Le 7 mai 2015 à 10:25, Axel Rauschmayer  a écrit :
> 
> Is this the best way to use `extends null`?
> 
> ```js
> class C extends null {
> constructor() {
> let _this = Object.create(C.prototype);
> return _this;
> }
> }
> ```

No, you should say: `Object.create(new.target.prototype)`

—Claude

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: extends null

2015-05-07 Thread Glen Huang
Isn't super-constructor null in this case?

From step 4 in 
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-getsuperconstructor 


superConstructor is C.[[GetPrototypeOf]]()

which should be `null` after the class definition, if I'm not wrong. (But it 
finally throws due to type error, so technically speaking, you can't even 
reference the super constructor)

I can't think of a better way of extending null, but I wonder what's the use 
case? null usually represents lacking of a value, and extending the lacking of 
a value? My brain hurts.

> On May 7, 2015, at 4:25 PM, Axel Rauschmayer  wrote:
> 
> Is this the best way to use `extends null`?
> 
> ```js
> class C extends null {
> constructor() {
> let _this = Object.create(C.prototype);
> return _this;
> }
> }
> ```
> 
> You can’t use `this`, because it can’t be initialized via a super-constructor 
> call: the super-constructor is `Function.prototype` (which can’t be 
> constructor-called).
> 
> -- 
> Dr. Axel Rauschmayer
> a...@rauschma.de 
> rauschma.de
> 
> 
> 
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


extends null

2015-05-07 Thread Axel Rauschmayer
Is this the best way to use `extends null`?

```js
class C extends null {
constructor() {
let _this = Object.create(C.prototype);
return _this;
}
}
```

You can’t use `this`, because it can’t be initialized via a super-constructor 
call: the super-constructor is `Function.prototype` (which can’t be 
constructor-called).

-- 
Dr. Axel Rauschmayer
a...@rauschma.de
rauschma.de



___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: 'stream' values

2015-05-07 Thread Mohan.Radhakrishnan
That was helpful.

I find it interesting that ES6 code is very similar to Java 8 lambdas.

Thanks,
Mohan

From: Erik Arvidsson [mailto:erik.arvids...@gmail.com]
Sent: Wednesday, May 06, 2015 6:37 PM
To: Radhakrishnan, Mohan (Cognizant); r.mark.volkm...@gmail.com
Cc: es-discuss@mozilla.org
Subject: Re: 'stream' values


entries() returns an iterator.

To sort you need to convert to an array first.

let a = [...map.entries()];
a.sort()

On Wed, May 6, 2015, 08:37  
mailto:mohan.radhakrish...@cognizant.com>> 
wrote:
That line matches my Java code almost exactly. My traceur transpiler though 
throws ‘TypeError: map.entries(...).sort is not a function’. Should I switch 
the traspiler ?

Thanks,
Mohan

From: Mark Volkmann 
[mailto:r.mark.volkm...@gmail.com]
Sent: Wednesday, May 06, 2015 4:19 PM
To: Radhakrishnan, Mohan (Cognizant)
Cc: mailto:es-discuss@mozilla.org>>
Subject: Re: 'stream' values

The entries method of a Map doesn't take a function. It does return an array 
though. That array contains [key, value] arrays. So you could do this.

map.entries().sort(([k1, v1], [k2, v2]) => k1.localeCompare(k2)).forEach(([k, 
v]) => do-something);

---
R. Mark Volkmann
Object Computing, Inc.

On May 6, 2015, at 4:27 AM, 
mailto:mohan.radhakrish...@cognizant.com>> 
mailto:mohan.radhakrish...@cognizant.com>> 
wrote:
Hi,
   Can I stream values and operate on them like this ? I have a map and I 
would like to stream them. I also want to chain the functions. So, for example, 
I may sort the map’s values and pass them on.

map.entries((e,m) => sort by using a predicate ).foreach(manipulate the map’s 
values);

Thanks,
Mohan
This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
If you are not the intended recipient(s), please reply to the sender and 
destroy all copies of the original message. Any unauthorized review, use, 
disclosure, dissemination, forwarding, printing or copying of this email, 
and/or any action taken in reliance on the contents of this e-mail is strictly 
prohibited and may be unlawful. Where permitted by applicable law, this e-mail 
and other e-mail communications sent to and from Cognizant e-mail addresses may 
be monitored.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
If you are not the intended recipient(s), please reply to the sender and 
destroy all copies of the original message. Any unauthorized review, use, 
disclosure, dissemination, forwarding, printing or copying of this email, 
and/or any action taken in reliance on the contents of this e-mail is strictly 
prohibited and may be unlawful. Where permitted by applicable law, this e-mail 
and other e-mail communications sent to and from Cognizant e-mail addresses may 
be monitored.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
If you are not the intended recipient(s), please reply to the sender and 
destroy all copies of the original message. Any unauthorized review, use, 
disclosure, dissemination, forwarding, printing or copying of this email, 
and/or any action taken in reliance on the contents of this e-mail is strictly 
prohibited and may be unlawful. Where permitted by applicable law, this e-mail 
and other e-mail communications sent to and from Cognizant e-mail addresses may 
be monitored.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss