archives

« Bugzilla Issues Index

#3237 — 19.1.3.5 Object.prototype.toLocaleString: this-binding no longer boxed


19.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

The this-binding was always a boxed value in ES5, this got changed in ES6 rev6. Was this a deliberate change?


ES5: Returns "object"
ES6: Returns "number"

---
Number.prototype.toString = function() {
"use strict";
return typeof this;
};
Object.prototype.toLocaleString.call(0);
---


not, sure whether it was deliberate but I think it is a good change.

Arguably, the ES5 boxing was a bug that was a result of over zealous addition of this value boxing that was added when boxing was moved form the caller side to the callee side.

But, we also want to avoid unnecessary boxing, especially for values that a propagated to other functions. I think we should leave it as currently spec'ed and document it as in Annex D as a correction that has possible (although likely) compatibility impact.


(In reply to Allen Wirfs-Brock from comment #1)
> But, we also want to avoid unnecessary boxing, especially for values that a
> propagated to other functions.

Do you think it's possible to omit the current boxing in for-of loop iteration or collection classes?


(In reply to André Bargull from comment #2)
>
> Do you think it's possible to omit the current boxing in for-of loop
> iteration or collection classes?

Could you be more specific about the cases you are think of.


(In reply to Allen Wirfs-Brock from comment #3)
> Could you be more specific about the cases you are think of.

I realized this topic was already discussed in bug 3111. There is no follow up after the last comment (bug 3111 comment 10). Was there any outcome?

Basically I'm asking whether it makes sense to perform these changes [1]. Sorry for the rather large diff, what started as a snug, little modification turned quickly into a monstrous beast. That makes me wonder if this change is really worth it... :-/

The effect of these changes can be observed in this test case. Without the modifications the script prints "iterable-type: object", with the modifications applied it will print "iterable-type: number".

---
Number.prototype[Symbol.iterator] = function() {
"use strict";
print(`iterable-type: ${typeof this}`);
return {next: () => ({done: true})};
};
for (var v of 123);
---


[1] Patch: https://gist.github.com/anba/2f96c137f8fb2f67ebc0
Base (rev27): https://gist.github.com/anba/51eb15881522a107adf8
Modified: https://gist.github.com/anba/ba5923a3bb2e0aed93f7


fixed in rev29 editor's draft

That is, the observable boxing in for-of loops and related places has been eliminated. Also in destructuring


fixed in rev29