-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(std/node): add os Symbol.toPrimitive methods #4073
Conversation
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
@@ -89,6 +89,17 @@ interface UserInfo { | |||
homedir: string; | |||
} | |||
|
|||
arch[Symbol.toPrimitive] = (): string => arch(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using arch[Symbol.toPrimitive] = arch;
directly ?
Same applie for the rest of the symbols.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because that's how Node.js does it. I figured that if we're adding a compatibility shim, we might as well aim for 100% fidelity. :-)
There's an observable difference in that os.arch[Symbol.toPrimitive].name
is the empty string in Node.js but it would be 'arch'
with your suggestion, i.e., it'd print differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is a unit test for this use case on node side, it would be mandatory to do as node do.
Can you check ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the answer but it's the wrong question to ask, IMO. Node is so widely used that chances are > 50% that there's some code somewhere depending on this particular quirk. Even if Node's test suite didn't test for it, that doesn't mean we can just deviate.
Random example: people complained their code broke when the util.inspect()
representation of streams changed in a really minor way. When the user base is big enough, any change is going to get noticed by someone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks Ben!
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
Node's os module exports a number of methods that evaluate to themselves
when coerced to a primitive.
I.e.,
"" + os.arch
andos.arch()
evaluate to the same string, andnow Deno's shims do too.