-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Switch IsCallable
and IsConstructor
to return boolean
#218
base: main
Are you sure you want to change the base?
Conversation
I like this idea, but it is ambiguous when we should use BooleanValue and when we should use a boolean. Also, the test failed. |
There are a few other functions that return
I missed a usage of |
do you feel ok with this change? cc @devsnek |
there used to be a util to call runtime/abstract ops from inside js by prefixing them with my biggest curiosity is around the "future type safety". The spec does not statically care whether a value is callable or a constructor, in fact that's why these test functions exist in the first place, so why would engine262 care? if this work is generally going in the direction of what happened to completion.mts i would suggest not doing it.
this package doesn't follow semver, but you should probably double check that https://engine262.js.org keeps working: https://github.com/engine262/engine262.github.io/blob/master/src/worker.js |
For me, the type of safety that is worth adding is if we can avoid casting things. (Cast is somehow a foot gun that might get unaligned with the actual status of the code) For example, if there is code like below, I think this is worth adding: if (IsGenerator(value) === Value.true) {
const brand = (value as GeneratorObjectValue).GeneratorBrand
}
// to
if (IsGenerator(value)) {
const brand = value.GeneratorBrand
// do not need cast, value is already GeneratorObjectValue
} Assert(IsGenerator(value) === Value.true)
const brand = (value as GeneratorObjectValue).GeneratorBrand
// to
Assert(IsGenerator(value))
const brand = value.GeneratorBrand
// do not need cast, value is already GeneratorObjectValue |
This changes the behavior of
IsCallable
andIsConstructor
to returnboolean
instead ofBooleanValue
so that they can be turned into type guards in a future type-safety PR.