jasnell / proposal-istypes

TC-39 Proposal for additional is{Type} APIs
201 stars 7 forks source link

Should deleting Symbol.builtin fall back to brand checks? #35

Open ljharb opened 7 years ago

ljharb commented 7 years ago

In the same way as deleting Symbol.toStringTag falls back to brand checks, should this?

Using the example from the readme (which currently erroneously says "non-function value", but should say "non-string value"):

Uint8Array[Symbol.builtin];             // 'Uint8Array'

Builtin.typeOf(new Uint8Array(0));      // 'Uint8Array'

Uint8Array[Symbol.builtin] = undefined;

Builtin.typeOf(new Uint8Array(0));      // 'object'

delete Uint8Array[Symbol.builtin];

Builtin.typeOf(new Uint8Array(0));      // 'Uint8Array' or 'object'?
jasnell commented 7 years ago

I'd say it falls back to default behavior... so after the delete it would return Uint8Array

Oh... and as we discussed previously, Uint8Array[Symbol.builtin] is a function... so Uint8Array[Symbol.builtin]() returns Uint8Array.

ljharb commented 7 years ago

ohh right sorry, early morning review :-p some of the examples have it as a string still.

ljharb commented 7 years ago

That sounds great tho - the spec text for getting the builtin value for x would then roughly be:

  1. Get x[Symbol.builtin]
  2. if it's not undefined and isn't callable, throw
  3. if callable, call it and ToString the result
  4. else, call an abstract operation that does the series of brand checks that Object.prototype.toString does, but ideally with a few more of them added

?