-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Reflect.hasField returns false on property getters on the JavaScript target #11613
Comments
DCE is granular at field level by design. If anything, the argument could be made that If you can, avoid reflection like the plague. More often than not, safer and faster alternatives are available. If not, you could either use Additionally, there could be a That said, I would yet again advise against using such a thing though ;) |
Reproduction
https://try.haxe.org/#8C3c6C77
Explanation
I have encountered some strange behavior with regards to Reflection against non-physical properties on the JavaScript target.
I am working on a fork of HScript, which needs to function properly on the HTML5 target. As part of variable resolution, I use
Reflect.hasField
to determine if I should resolve a field or throw a syntax error.On the Eval target,
Reflect.hasField('myValue')
returns false, butReflect.hasField('get_myValue')
returns true. This allows me to determine ifgetProperty
(which the docs state is slower thanReflect.field
) is necessary.However,
Reflect.hasField('get_myValue')
returns false on JavaScript, even thoughReflect.getProperty('myValue')
does succeed. This gives me no way to detect ifgetProperty
will return a valid result or not (checkinggetProperty() == null
won't work since there is no way to distinguish between "this value exists and is null" and "this value does not exist").I cannot use
Reflect.properties()
orReflect.hasProperty()
, because no such functions do not exist for some reason.Additional notes:
Reflect.fields()
does not include properties.getProperty('myField')
to fail, presumably because the getter function is getting culled. Getter and setter functions should definitely never get culled if the class itself has not been culled.The text was updated successfully, but these errors were encountered: