Re: Reflect.toStringSpec proposal

2016-12-13 Thread Jordan Harband
This was also pointed out to me elsewhere:

```js
const ToStringSpec = x => `${x}`;
```

On Tue, Dec 13, 2016 at 9:05 PM, Jordan Harband  wrote:

> Here you go: `require('es-abstract').ToString` https://www.npmjs.
> com/package/es-abstract
>
> On Tue, Dec 13, 2016 at 7:44 PM, Bergi  wrote:
>
>> Sergey R schrieb:
>>
>>> I want to propose a new language feature — Reflect.toStringSpec.
>>>
>>
>> `Reflect.toString` or `Reflect.toStringSpec`?
>>
>> Here is a repo https://github.com/chicoxyzzy/
>>> proposal-reflect-tostringspec
>>>
>>
>> | Rationale
>> |
>> | There is no exact way to call spec's `ToString` in JS.
>> | However it may be necessary for polyfills.
>>
>> It's not that hard to emulate, is it? There are other internal operations
>> would be more important.
>>
>> Regardless, the `Reflect` namespace is supposed to only contain object
>> tools that would be the default for proxy traps. No `ToString` in there.
>>
>> | Current solution is to do something like:
>> |
>> | function toStringSpec(target) {
>> |return target == null ? target : String(Object(target));
>> | }
>>
>> That looks horribly wrong. It doesn't do the least what `ToString` does
>> in ES6.
>>
>> The spec says it should do
>> ```
>> function ToString(x) {
>> if (typeof x != "symbol) return String(x);
>> else throw new TypeError("…");
>> }
>> ```
>> This would be a pretty standard approach, also being used e.g. in
>> https://github.com/ljharb/es-abstract/blob/035153777213981e0
>> e24f6cf007ffbd279384130/es6.js#L129-L135
>>
>> And if you don't care about Symbols, you can easily just use `String`.
>>
>> Kind regards,
>>  Bergi
>> ___
>> 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: Reflect.toStringSpec proposal

2016-12-13 Thread Jordan Harband
Here you go: `require('es-abstract').ToString`
https://www.npmjs.com/package/es-abstract

On Tue, Dec 13, 2016 at 7:44 PM, Bergi  wrote:

> Sergey R schrieb:
>
>> I want to propose a new language feature — Reflect.toStringSpec.
>>
>
> `Reflect.toString` or `Reflect.toStringSpec`?
>
> Here is a repo https://github.com/chicoxyzzy/proposal-reflect-tostringspec
>>
>
> | Rationale
> |
> | There is no exact way to call spec's `ToString` in JS.
> | However it may be necessary for polyfills.
>
> It's not that hard to emulate, is it? There are other internal operations
> would be more important.
>
> Regardless, the `Reflect` namespace is supposed to only contain object
> tools that would be the default for proxy traps. No `ToString` in there.
>
> | Current solution is to do something like:
> |
> | function toStringSpec(target) {
> |return target == null ? target : String(Object(target));
> | }
>
> That looks horribly wrong. It doesn't do the least what `ToString` does in
> ES6.
>
> The spec says it should do
> ```
> function ToString(x) {
> if (typeof x != "symbol) return String(x);
> else throw new TypeError("…");
> }
> ```
> This would be a pretty standard approach, also being used e.g. in
> https://github.com/ljharb/es-abstract/blob/035153777213981e0
> e24f6cf007ffbd279384130/es6.js#L129-L135
>
> And if you don't care about Symbols, you can easily just use `String`.
>
> Kind regards,
>  Bergi
> ___
> 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: Reflect.toStringSpec proposal

2016-12-13 Thread Bergi

Sergey R schrieb:

I want to propose a new language feature — Reflect.toStringSpec.


`Reflect.toString` or `Reflect.toStringSpec`?


Here is a repo https://github.com/chicoxyzzy/proposal-reflect-tostringspec


| Rationale
|
| There is no exact way to call spec's `ToString` in JS.
| However it may be necessary for polyfills.

It's not that hard to emulate, is it? There are other internal 
operations would be more important.


Regardless, the `Reflect` namespace is supposed to only contain object 
tools that would be the default for proxy traps. No `ToString` in there.


| Current solution is to do something like:
|
| function toStringSpec(target) {
|return target == null ? target : String(Object(target));
| }

That looks horribly wrong. It doesn't do the least what `ToString` does 
in ES6.


The spec says it should do
```
function ToString(x) {
if (typeof x != "symbol) return String(x);
else throw new TypeError("…");
}
```
This would be a pretty standard approach, also being used e.g. in 
https://github.com/ljharb/es-abstract/blob/035153777213981e0e24f6cf007ffbd279384130/es6.js#L129-L135


And if you don't care about Symbols, you can easily just use `String`.

Kind regards,
 Bergi
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Reflect.toStringSpec proposal

2016-12-13 Thread Allen Wirfs-Brock

> On Dec 13, 2016, at 4:51 PM, Sergey R  wrote:
> 
> I want to propose a new language feature — Reflect.toStringSpec.
> Here is a repo https://github.com/chicoxyzzy/proposal-reflect-tostringspec 
> 
> Some context: 
> https://github.com/airbnb/babel-plugin-dynamic-import-node/pull/2/ 
> ___

Doesn’t this do exactly what you want:

```js
// JS level equivalent of ES spec ToString abstract operation 
https://tc39.github.io/ecma262/#sec-tostring 
 
function ToString(v) {
   if (typeof v === “symbol”) throw TypeError(“Can’t convert a symbol to a 
string”);
   return String(v);  //for non-symbols String(v) primitively returns 
ToString(v)
}
```

This seems like something that can reasonably be coded as part of a polyfill___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Ranges

2016-12-13 Thread Hikaru Nakashima
Oh, I understood it.
It looks like serious problem, but it is may not actually.
If this spec change doesn't break web, we can introduce this idea?
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Reflect.toStringSpec proposal

2016-12-13 Thread Sergey R
I want to propose a new language feature — Reflect.toStringSpec.
Here is a repo https://github.com/chicoxyzzy/proposal-reflect-tostringspec
Some context:
https://github.com/airbnb/babel-plugin-dynamic-import-node/pull/2/
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Ranges

2016-12-13 Thread Tab Atkins Jr.
On Tue, Dec 13, 2016 at 3:07 AM, Hikaru Nakashima
 wrote:
> My idia is as follows:
>
> ```
> [1..5]  //-> [1,2,3,4,5]
>
> (1..5)   //-> iterate 1, 2, 3, 4, 5
>
>
> [1..Infinity]  // -> TypeError because n > 2**32-1
>
> (1..Infinity)  // -> valid iterator
> ```

As Andy just explained in the previous message, that doesn't work.  In
particular, `[1..end]` is equivalent to `[(1).end]`, which is a
perfectly valid expression that creates a length-1 array containing
the value of the "end" property from a Number wrapper auto-constructed
around 1.  (Which happens to be undefined, unless you do shenanigans.)

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


Re: Ranges

2016-12-13 Thread Hikaru Nakashima
My idia is as follows:

```
[1..5]  //-> [1,2,3,4,5]

(1..5)   //-> iterate 1, 2, 3, 4, 5


[1..Infinity]  // -> TypeError because n > 2**32-1

(1..Infinity)  // -> valid iterator
```
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: name anonymous functions on property assignments

2016-12-13 Thread T.J. Crowder
About a year ago, Bergi asked[1] why no name is assigned to a function
when it's created as part of an assignment to an object property:

o.method = () => { };

Allen Wirfs-Brock replied:

> We did not have consensus on doing the same for:
> `MemberExpression.IdentifierName = FunctionExpression` or
> `MemberExpression[Expression] = FunctionExpression`
> so it is not part of ES2015. There were various objections that would have
> to be overcome before we could adopt that.

Does anyone remember what the objections were?

I've been through the TC39 meeting notes[2] without luck (so far). In
the May 28 2015 notes I can find "function name property" listed as an
open issue, but nothing in the May 29 notes and those are the last two
in the "es6" folder. Other than those, searching for "function name"
in meeting notes turns up Mar 24 2015, then Nov 18 2014, then July 23
2013; that last one talks about doing inference (as a whole) and AWB
says "It's not an insignificant amount of work" suggesting to me that
at that point, it hadn't been done yet. But Nov 18 2014 and Mar 24
2015 don't seem to address this case. Other mentions of "function
name" are unrelated (for instance, relate to `toString`). Searching
for "MemberExpression" only turns up one unrelated match.

The strawman[3] (linked from the July 23 2013 notes) does have the
name being set in this case (it's the final example).

Thanks,

[1] https://esdiscuss.org/topic/name-anonymous-functions-on-property-assignments
[2] https://github.com/rwaldron/tc39-notes
[3] http://wiki.ecmascript.org/doku.php?id=harmony:function_name_property

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


Membranes: filtering own properties, questions on ES7 intent

2016-12-13 Thread Alex Vincent
Hello, everyone.  Now that the quarter at my local university is over,
I'm working on my es7-membrane project again.  [1]

In implementing "filterOwnKeys", I realized I have wandered into a
couple of open questions, where I do not know from the ES7
specification what the desirable behavior is.  I have written tests
for these two cases that I've discovered so far, but I currently have
them disabled.  Hopefully this mailing list can provide me with some
insight.

The filterOwnKeys API is pretty much as it sounds:  you name the
object graph and object you want filtering to apply to, and pass in an
array filtering function.

The first "unclear" testcase asks, "Reflect.defineOwnProperty(dry,
'blacklisted', desc) should return what?" [2]  The question there is,
"should didSet be true because we set a value on the wet object graph,
or false because we failed to set a value on the dry object graph?"

The second "unclear" testcase examines "Deleting a blacklisted
property defined on the original target via the dry graph".  [2]  In
this case, defining the property worked (albeit invisibly to the dry
graph), but it's unclear if a delete operation on the property should
propagate.

These questions, by the way, should be explicitly handled when the
membrane customer invokes other modification API's -
"requireLocalDelete" and "storeUnknownAsLocal", specifically.  The
three modification API's, plus a "proxy creation observer" API, will
combine to form a practical whitelisting example.  I am therefore
explicitly asking about what should the proxy API should do in an
otherwise perfect-mirror membrane implementation.

Advice, and debate, is most welcome!

Alex Vincent
Hayward, CA, U.S.A.


[1] https://github.com/ajvincent/es7-membrane
[2] 
https://github.com/ajvincent/es7-membrane/blob/master/spec/properties/filterOwnKeys.js

-- 
"The first step in confirming there is a bug in someone else's work is
confirming there are no bugs in your own."
-- Alexander J. Vincent, June 30, 2001
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss