Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template literals are improperly being coerced #1836

Open
sebmck opened this issue Mar 23, 2015 · 2 comments
Open

Template literals are improperly being coerced #1836

sebmck opened this issue Mar 23, 2015 · 2 comments
Assignees

Comments

@sebmck
Copy link

sebmck commented Mar 23, 2015

According to 12.2.8.5 template literal expressions should be coerced to strings.

Let sub be the result of evaluating Expression.
Let middle be ToString(sub).

var x = { toString: function () { return "foo"; }, valueOf: function () { return "bar"; } };
console.log(`${x}`);

Actual:

var x = { toString: function () { return "foo"; }, valueOf: function () { return "bar"; } };
console.log(("" + x));

Expected:

var x = { toString: function () { return "foo"; }, valueOf: function () { return "bar"; } };
console.log(("" + String(x)));

Relevant V8 bug report here.

arv added a commit to arv/traceur-compiler that referenced this issue Mar 24, 2015
We were not calling ToString correctly for template literal
placeholder expressions. This lead to cases where we ended up with
calling valueOf instead as required by a + b.

Fixes google#1836
arv added a commit to arv/traceur-compiler that referenced this issue Mar 24, 2015
We were not calling ToString correctly for template literal
placeholder expressions. This lead to cases where we ended up with
calling valueOf instead as required by a + b.

Fixes google#1836
@arv arv assigned arv Mar 24, 2015
@arv
Copy link
Collaborator

arv commented Mar 29, 2015

If you've been following the discussion on the PR it is not clear we care about fixing this. To fix this we need to make sure that we throw for symbols which makes the generated code pretty ugly (and slower).

Maybe Traceur should follow Babel and use a spec/loose mode?

@sebmck
Copy link
Author

sebmck commented Mar 30, 2015

I think that's a good approach. I'm concerned about performance too since template literals are almost certainly going to appear in hot code. Not sure whether it's a good idea to do it by default though. Perhaps it can be considered the same as the typeof symbol rewriting (opt-in)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants