Skip to content

Commit

Permalink
JJSIRuntimeWrapper cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sugarmanz committed Jun 25, 2024
1 parent 05a23df commit 1824210
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 0 additions & 4 deletions jvm/hermes/src/main/jni/JJSIValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ void JJSIRuntime::registerNatives() {
});
}

void JJSIRuntimeWrapper::registerNatives() {
registerHybrid({});
}

local_ref<JJSIValue::jhybridobject> JJSIValue::fromBool(alias_ref<jclass>, bool b) {
return newObjectCxxArgs(Value(b));
}
Expand Down
20 changes: 12 additions & 8 deletions jvm/hermes/src/main/jni/JJSIValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ class JJSIRuntime : public HybridClass<JJSIRuntime> {
virtual Runtime& get_runtime() = 0;
};


// Base implementation can't partake in memory management b/c we don't
// know the concrete runtime type to create smart pointers for. So, we
// just wrap the reference up for use at a later point.
/**
* Runtime agnostic reference wrapper runtime implementation. Neither the
* base implementation, nor this, can partake in memory management b/c we don't
* know the concrete runtime type to create smart pointers for. So, we just wrap
* the reference up for use at a later point. This shouldn't be used for creating
* and managing instances of a runtime, that should be done with the runtime
* specific JNI constructs to ensure it can hold the correct smart pointer.
*/
class JJSIRuntimeWrapper : public HybridClass<JJSIRuntimeWrapper, JJSIRuntime> {
public:
static constexpr auto kJavaDescriptor = "Lcom/intuit/playerui/jsi/Runtime;";
static void registerNatives();

Runtime& get_runtime() override {
return runtime_;
};

JJSIRuntimeWrapper(Runtime& runtime) : HybridClass(), runtime_(runtime) {}

private:
std::reference_wrapper<Runtime> runtime_;
};
Expand Down Expand Up @@ -182,6 +182,10 @@ struct JJSIHostFunction : JavaClass<JJSIHostFunction> {
// is actually called.
static Value call(alias_ref<JJSIHostFunction> jThis, Runtime& runtime, Value& thisVal, Value* args, size_t count);

// TODO: HostFunctionType declares thisVal and args as const, which makes it difficult to wrap
// with JJSIValue for cross-jni usage. We've applied a patch to loosen the parameter
// constraints, but a better solution would likely be to follow a const (read-only)
// approach in a JJSIConstValue class.
Value call(Runtime& runtime, Value& thisVal, Value* args, size_t count);
};

Expand Down
1 change: 0 additions & 1 deletion jvm/hermes/src/main/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
return initialize(vm, [] {
intuit::playerui::JJSIPreparedJavaScript::registerNatives();
intuit::playerui::JJSIRuntime::registerNatives();
intuit::playerui::JJSIRuntimeWrapper::registerNatives();
intuit::playerui::JJSIValue::registerNatives();
intuit::playerui::JJSIObject::registerNatives();
intuit::playerui::JJSIArray::registerNatives();
Expand Down

0 comments on commit 1824210

Please sign in to comment.