-
Notifications
You must be signed in to change notification settings - Fork 648
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
Makes HermesRuntimeImpl::isArray proxy-compatible #1489
Conversation
Hi @dorentus! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
7800479
to
8b32930
Compare
Hey @dorentus, thanks for submitting this. This is a little tricky because Hermes today assumes that any |
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.
To support this properly, we should fix all users of jsi::Array
in this file to no longer imply that the underlying object is a vm::JSArray
. In most cases, this should just be a matter of using handle()
instead of arrayHandle()
. But for length we will need to have a fast path that follows the current behaviour, and a slow path that does a regular property lookup.
API/hermes/hermes.cpp
Outdated
@@ -1996,7 +1998,20 @@ void HermesRuntimeImpl::setPropertyValue( | |||
} | |||
|
|||
bool HermesRuntimeImpl::isArray(const jsi::Object &obj) const { | |||
return vm::vmisa<vm::JSArray>(phv(obj)); | |||
vm::JSObject *jsobj = static_cast<vm::JSObject *>(phv(obj).getPointer()); |
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.
We have an isArray
in Operations.h
that you can call into that will provide the right functionality here.
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.
Code updated.
Question: Should I call runtime_.clearThrownValue()
on ExecutionStatus::EXCEPTION
before returning false
?
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.
You should use checkStatus
to rethrow the exception as a C++ exception
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.
checkStatus
isn't const
thus cannot be used here without modification...
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.
It should be safe to remove the constness and call checkStatus
here. Code updated.
When using hermes engine, [`dynamicFromValue` in React Native](https://github.com/facebook/hermes/blob/main/API/jsi/jsi/JSIDynamic.cpp#L166) calls `isArray` here to check if the input object is an array. Consider this piece of code: ```js const list = ['a', 'b', 'c', 'd']; const proxyed_list = new Proxy(list, {}); ``` The `proxyed_list` behaves exactly the same as list in Javascript. But when been passed to native and converted to `folly::dynamic` by `dynamicFromValue`, `proxyed_list` will be converted to `{"0": "a", "1": "b", "2": "c", "3": "d"}` but not the expected `["a", "b", "c", "d"]`. This patch implements similar routines in commit [26840ed](facebook@26840ed#diff-059b8f2fcb0235b35582efc591e065bd8caa898c3ea2ef2a3e453bff97584e4dR1575) and makes `isArray` proxy-compatible.
`runtime_` is modified on error and restored in `checkStatus`, So it should be safe to remove the constness and call `checkStatus` here.
JSC used to implement And So yes, changes suggested by this PR might cause more problems than expected. As for the dynamicFromValue problem, I'm trying the |
Closing for now, since no progress. Please feel free to re-open when there are updates. |
When using hermes engine,
dynamicFromValue
in React Native callsisArray
here to check if the input object is an array.Consider this piece of code:
The
proxyed_list
behaves exactly the same as list in Javascript. But when been passed to native and converted tofolly::dynamic
bydynamicFromValue
,proxyed_list
will be converted to{"0": "a", "1": "b", "2": "c", "3": "d"}
but not the expected["a", "b", "c", "d"]
.This patch implements similar routines in commit 26840ed441d614a07809c612521074ca9544086c and makes
isArray
proxy-compatible.Summary
Test Plan