Reflect.toStringSpec proposal

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Reflect.toStringSpec proposal

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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Reflect.toStringSpec proposal

Allen Wirfs-Brock

On Dec 13, 2016, at 4:51 PM, Sergey R <[hidden email]> 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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Reflect.toStringSpec proposal

Bergi
In reply to this post by Sergey R
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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Reflect.toStringSpec proposal

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 <[hidden email]> 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/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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Reflect.toStringSpec proposal

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 <[hidden email]> 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 <[hidden email]> 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/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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss