Skip to content
New issue

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

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

Already on GitHub? # to your account

ToPrimitive of Record wrapper throws #320

Closed
acutmore opened this issue Jul 11, 2022 · 1 comment · Fixed by #321
Closed

ToPrimitive of Record wrapper throws #320

acutmore opened this issue Jul 11, 2022 · 1 comment · Fixed by #321

Comments

@acutmore
Copy link
Collaborator

ToPrimitive of an object relies on looking up methods on the value, there is no default behavior:

delete Symbol.prototpe.toString;
delete Symbol.prototpe.valueOf;
delete Symbol.prototpe[Symbol.toPrimtive];
Object.setPrototypeOf(Symbol.prototype, null);

Symbol() == Object(Symbol()); // throws

This behavior currently happens by default for Record wrappers because they have a null prototype.

#{} == Object(#{}) // throws

It seems more future-proof to allow Record wrappers to safely pass ToPrimitive by unwrapping to their record primitive content. ToString and ToNumber can still throw.

We could add support for this either by adding a direct case for handing records to ToPrimitive, or always add a non-enumerable Symbol.toPrimitive to Record wrappers - though this would add a new hidden intrinsic.

@ljharb
Copy link
Member

ljharb commented Jul 11, 2022

tbh I would prefer both.

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

Successfully merging a pull request may close this issue.

2 participants