Comments (6)
Hey @AndyBrown91, have you considered using an ordinary JavaScript function instead of a jsi::HostObject
? You can populate your accessors as getters/setters on the function. Note that these getters or setters could be jsi::HostFunction
s that update state on the native side associated with the object.
If you need to store data on the native side, you can attach a jsi::NativeState
to any JS object (including functions), and access it from your HostFunction
s. In general, keeping properties you want to use from JS directly in JS, instead of accessing them through HostObject
s is preferable, since accessing JS properties is much more efficient, and reduces the risk of creating uncollectable cycles through jsi::Value
s.
from hermes.
Thanks so much for your reply @neildhar
I'm not able to see a way to link a jsi::HostFunction
with those property semantics though. Am I missing something?
I felt like the HostObject
was the only way to map a C++ getter to a whatever.myprop
The reason why I ask for this stuff is to ensure that it will match the semantics for your linked classes if you use a different JS engine
Maybes there is some magic JS stuff that I have missed for mapping property getters to functions within JS?
from hermes.
You can use Object.defineProperty
to set an arbitrary function (including a HostFunction) as a getter. Loosely, Object.defineProperty(whatever, "myprop", {get: myHF, ...<other flags>})
.
from hermes.
Was just in the process of editing the above, thanks for pointing that out. I'll absolutely give that a go
Really appreciate you helping me reframe the issue
from hermes.
Just chiming in on this, noticed that typeof function
is returning object
only within production builds.
from hermes.
@mikehuebner have you observed a bug with Hermes in typeof
? Could you open a new issue with the details and a minimal repro?
from hermes.
Related Issues (20)
- NULL pointer dereference in function getLiveInValue, file lib/Optimizer/Scalar/Mem2Reg.cpp
- NULL pointer dereference in function hermes::vm::JSObject::findProperty in include/hermes/VM/JSObject.h HOT 1
- Issue Title: Error installing FBLazyVector during pod install HOT 1
- Segfault in production Android app - facebook::hermes::debugger::EventObserver::breakpointResolved HOT 19
- Segfault in production Android app - facebook::hermes::debugger::EventObserver::breakpointResolved HOT 4
- Guide about benmarking JavaScript perf on Hermes HOT 1
- Support FinalizationRegistry in Hermes HOT 2
- Intentional fallthrough? HOT 4
- RangeError: Maximum callstack size exceeded with many modules in single bundle HOT 20
- "HBC version" should be reflected in the documentation or the file name HOT 1
- In iOS, is it possible to compile Hermes as a static library instead of a dynamic library? HOT 1
- Wrong bytecode version with hbcdump HOT 1
- Bug in scoped function promotion (non-strict mode) HOT 3
- Problems loading emscripten compiled js file in Hermes. Works on JSC/V8. HOT 6
- Invalid Source map HOT 1
- [hermes-parser] Support Import Attributes HOT 1
- When I CrossCompilation build for android, I got the error, the branch is 'rn/0.74-stable' HOT 3
- SyntaxError: Invalid RegExp: Invalid escape, js engine: hermes HOT 3
- Failed to build CLI on Linux HOT 2
- Intl.PluralRules support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hermes.