You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: Should Streams have the prototype for Symbol.toStringTag and toString declared?Β #952
In certain implementations of whatwg streams, I've come across them not implementing toString or Symbol.toStringTag on the prototype meaning that if you're trying to find out if you've been given a stream (or another data type) then you have to rely on duck typing.
In the following, I'd expect to see "[object ReadableStream]" returned:
In Safari these all return as I'd expect, in Chrome and Firefox they return "[object Object]". The spec doesn't actually specify the toString behavior.
Interesting point. It looks like "[object ReadableStream]" would be correct. I don't think it would hurt to be explicit about this in the standard. I'm not sure of the best way to do it. Perhaps specifying the value of ReadableStream.prototype[Symbol.toStringTag] is sufficient?
@domenic Can you suggest the correct way to specify this, off the top of your head?
Currently the spec required [object Object]. We could change this if we wanted, but I'm not sure what the benefits would be. People can just use x.constructor.name for the same effect.
I think the benefit is consistency. Language objects Promise, Map, WeakMap, and WeakSet all return "[object Foo]", and AFAIK all IDL types that don't specifically override it also return "[object Foo]". Which leaves streams as a weird odd-one-out.
Activity
ThisIsMissEm commentedon Aug 31, 2018
(Relatedly I've opened an issue on the node.js FormData module for the same issue: form-data/form-data#396 )
ricea commentedon Aug 31, 2018
Interesting point. It looks like "[object ReadableStream]" would be correct. I don't think it would hurt to be explicit about this in the standard. I'm not sure of the best way to do it. Perhaps specifying the value of ReadableStream.prototype[Symbol.toStringTag] is sufficient?
@domenic Can you suggest the correct way to specify this, off the top of your head?
domenic commentedon Aug 31, 2018
Currently the spec required [object Object]. We could change this if we wanted, but I'm not sure what the benefits would be. People can just use x.constructor.name for the same effect.
ricea commentedon Aug 31, 2018
I think the benefit is consistency. Language objects Promise, Map, WeakMap, and WeakSet all return
"[object Foo]", and AFAIK all IDL types that don't specifically override it also return"[object Foo]". Which leaves streams as a weird odd-one-out.Rewrite to use Web IDL, and generally modernize
Rewrite to use Web IDL, and generally modernize
Rewrite to use Web IDL, and generally modernize
Rewrite to use Web IDL, and generally modernize
Rewrite to use Web IDL, and generally modernize