Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upSpecify Symbol.prototype methods as [[Writable]]: false #273
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
domenic
Dec 22, 2015
Member
This is just the usual confusion between wrapper objects and primitives. It's the same as
var s = false;
s.toString = function() { return ''; };
s.toString(); // => "false"line 2 creates a useless wrapper object that is immediately discarded. It doesn't set {Symbol,Boolean}.prototype.toString.
|
This is just the usual confusion between wrapper objects and primitives. It's the same as var s = false;
s.toString = function() { return ''; };
s.toString(); // => "false"line 2 creates a useless wrapper object that is immediately discarded. It doesn't set |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jdalton
Dec 22, 2015
Member
Ah yes, my bad.
var s = Object(Symbol());
typeof s; // => "object"
s.toString = function() { return '' };
s.toString(); // => ""then
var o = {};
o[s] = 1;
Object.keys(o);
// => []
Object.getOwnPropertySymbols(o)
// => [Symbol()]Kinda neat it works as an object too.
|
Ah yes, my bad. var s = Object(Symbol());
typeof s; // => "object"
s.toString = function() { return '' };
s.toString(); // => ""then var o = {};
o[s] = 1;
Object.keys(o);
// => []
Object.getOwnPropertySymbols(o)
// => [Symbol()]Kinda neat it works as an object too. |
jdalton
closed this
Dec 22, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
Dec 22, 2015
Contributor
line 2 creates a useless wrapper object that is immediately discarded
It's less cumbersome to think as: Primitives are frozen.
It's less cumbersome to think as: Primitives are frozen. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
domenic
Dec 22, 2015
Member
It's less cumbersome to think as: Primitives are frozen.
Except "modifying" them doesn't throw in strict mode.
Except "modifying" them doesn't throw in strict mode. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
Dec 22, 2015
Contributor
Except "modifying" them doesn't throw in strict mode.
It should. (It does in JSC and V8. If it doesn’t in ECMA262, I consider it as a bug.)
It should. (It does in JSC and V8. If it doesn’t in ECMA262, I consider it as a bug.) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Dec 22, 2015
Member
Except "modifying" them doesn't throw in strict mode.
It should. (It does in JSC and V8. If it doesn’t in ECMA262, I consider it as a bug.)
No, Wrapper objects are not created frozen and hence there should be no strict mode errors associated with creating own properties on them. This is legacy behavior for Number, Boolean, String and modify it would be a web breaking change. As a new kind of primitive wrapper, it was conceivable that Symbol wrapper could be frozen. But that would then have created an internal inconsistency between Symbol wrapper objects and the other pre-existing kinds of wrapper objects..
No, Wrapper objects are not created frozen and hence there should be no strict mode errors associated with creating own properties on them. This is legacy behavior for Number, Boolean, String and modify it would be a web breaking change. As a new kind of primitive wrapper, it was conceivable that Symbol wrapper could be frozen. But that would then have created an internal inconsistency between Symbol wrapper objects and the other pre-existing kinds of wrapper objects.. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
anba
Dec 22, 2015
Contributor
there should be no strict mode errors associated with creating own properties on them.
Except in most cases PutValue ends up in 9.1.9 [[Set]], which returns false if the receiver is a primitive value and the property is not present (or a data property). And then a TypeError is thrown. (I think this is what @claudepache meant.)
Except in most cases PutValue ends up in 9.1.9 [[Set]], which returns |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
Dec 22, 2015
Contributor
I meant that it is more useful that it throws, so that the programmer is warned that their intention could not be satisfied. The wrapper object dance is a legacy specification detail. In practice, what the programmer sees is what @jdalton reported: attempt to define an own property on a primitive fails, just as for frozen objects.
|
I meant that it is more useful that it throws, so that the programmer is warned that their intention could not be satisfied. The wrapper object dance is a legacy specification detail. In practice, what the programmer sees is what @jdalton reported: attempt to define an own property on a primitive fails, just as for frozen objects. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Dec 22, 2015
Member
But 9.1.9 returns that false to step 6.c of 6.2.3.2 which only throws for strict references.
@claudepache is correct it would be better if it could always throw, but that isn't the legacy semantics outside of strict mode. But strict mode does give the more desirable error behavior.
|
But 9.1.9 returns that false to step 6.c of 6.2.3.2 which only throws for strict references. @claudepache is correct it would be better if it could always throw, but that isn't the legacy semantics outside of strict mode. But strict mode does give the more desirable error behavior. |
jdalton commentedDec 22, 2015
I'm not sure if this is mentioned in another place in the spec, I didn't see it, but I noticed all implementations have symbol methods like
Symbol#toStringas [[Writable]]: false.but