tc39 / proposal-record-tuple

ECMAScript proposal for the Record and Tuple value types. | Stage 2: it will change!
https://tc39.es/proposal-record-tuple/
2.48k stars 62 forks source link

ToPrimitive of Record wrapper throws #320

Closed acutmore closed 2 years ago

acutmore commented 2 years ago

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 commented 2 years ago

tbh I would prefer both.