Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions NativeScript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ include_directories(
)

set(FFI_SHARED_SOURCE_FILES
ffi/objc/shared/Tasks.cpp
jsi/shared/Tasks.cpp
)

set(FFI_NAPI_SOURCE_FILES
Expand Down Expand Up @@ -274,26 +274,32 @@ set(FFI_HERMES_ENGINE_SOURCE_FILES

set(FFI_V8_ENGINE_SOURCE_FILES
${FFI_ENGINE_SHARED_SOURCE_FILES}
# Platform-neutral engine layer, shared with the Android runtime.
jsi/v8/V8HostObjects.cpp
jsi/v8/V8Runtime.cpp
jsi/v8/V8Value.cpp
# Apple-only ObjC bridge on top of it.
ffi/objc/v8/NativeApiV8.mm
ffi/objc/v8/NativeApiV8HostObjects.mm
ffi/objc/v8/NativeApiV8Runtime.mm
ffi/objc/v8/NativeApiV8Value.mm
)

set(FFI_JSC_ENGINE_SOURCE_FILES
${FFI_ENGINE_SHARED_SOURCE_FILES}
# Platform-neutral engine layer, shared with the Android runtime.
jsi/jsc/JSCHostObjects.cpp
jsi/jsc/JSCRuntime.cpp
jsi/jsc/JSCValue.cpp
# Apple-only ObjC bridge on top of it.
ffi/objc/jsc/NativeApiJSC.mm
ffi/objc/jsc/NativeApiJSCHostObjects.mm
ffi/objc/jsc/NativeApiJSCRuntime.mm
ffi/objc/jsc/NativeApiJSCValue.mm
)

set(FFI_QUICKJS_ENGINE_SOURCE_FILES
${FFI_ENGINE_SHARED_SOURCE_FILES}
ffi/objc/quickjs/NativeApiQuickJSHostObjects.mm
# Platform-neutral engine layer, shared with the Android runtime.
jsi/quickjs/QuickJSHostObjects.cpp
jsi/quickjs/QuickJSRuntime.cpp
jsi/quickjs/QuickJSValue.cpp
# Apple-only ObjC bridge on top of it.
ffi/objc/quickjs/NativeApiQuickJS.mm
ffi/objc/quickjs/NativeApiQuickJSRuntime.mm
ffi/objc/quickjs/NativeApiQuickJSValue.mm
)

set(SOURCE_FILES
Expand Down
67 changes: 9 additions & 58 deletions NativeScript/ffi/objc/hermes/NativeApiJsi.h
Original file line number Diff line number Diff line change
@@ -1,62 +1,13 @@
#ifndef NATIVE_API_JSI_H
#define NATIVE_API_JSI_H
#ifndef NATIVE_API_JSI_H_FFI_FORWARD
#define NATIVE_API_JSI_H_FFI_FORWARD

#include <jsi/jsi.h>

#include "ffi/objc/shared/NativeApiBackendConfig.h"

namespace nativescript {

using NativeApiJsiScheduler = NativeApiBackendScheduler;
using NativeApiJsiConfig = NativeApiBackendConfig;

facebook::jsi::Object CreateNativeApiJSI(
facebook::jsi::Runtime& runtime,
const NativeApiJsiConfig& config = NativeApiJsiConfig{});

void InstallNativeApiJSI(
facebook::jsi::Runtime& runtime,
const NativeApiJsiConfig& config = NativeApiJsiConfig{});

// M1 (ARCHITECTURE.md §4.3): the two ObjC<->JSI helpers that make the
// by-reference Fabric handoff possible; "the Fabric boundary must hand JS
// a real bridge-wrapped object, not a string handle"
// (CLEANUP_AND_REARCHITECTURE_PLAN.md §2.0). Both wrap the SAME
// NativeApiObjectHostObject mechanism every other native object crossing in
// this bridge already uses (Object.mm/Class.mm); so a wrapped value
// round-trips through the identical `nativeValue(...)`-style method dispatch
// as any other bridged object, not a bespoke RPC.
//
// `object`/the return value are `void*`-typed ObjC `id`s, kept untyped here
// (not `id`) so this header stays includable from a plain C++ translation
// unit that never imports Objective-C (e.g. runtime/apple/Runtime.cpp,
// which includes this header under `#ifdef TARGET_ENGINE_HERMES` without
// itself being compiled as Objective-C++); the same convention
// NativeApiBackendConfig.h already follows.
//
// Only implemented for the Hermes backend (this header/its .mm are
// Hermes-only, ffi/objc/hermes/); RN only ever uses Hermes, so this does not
// touch the V8/JSC/QuickJS engine backends or their standalone builds.
// Moved to jsi/hermes/NativeApiJsi.h. Hermes is the one backend that exposes
// the real facebook::jsi API rather than reimplementing the nativescript
// engine shape, and this declaration is already platform-neutral, so Android's
// Hermes backend can share it verbatim.
//
// If `ownsObject` is true, the wrapper takes over a +1 retain already held
// by the caller (matching `makeNativeObjectValue`'s `ownsObject` semantics
// used everywhere else in the bridge); if false, the wrapper retains its own
// reference and the caller's reference is untouched.
facebook::jsi::Value NativeScriptWrapNativeObject(facebook::jsi::Runtime& runtime,
void* object,
bool ownsObject = false);

// Reverse direction: given a JSI value produced by NativeScriptWrapNativeObject
// (or any other native-object-wrapping mechanism the bridge already uses --
// NativeApiObjectHostObject, NativeApiPointerHostObject,
// NativeApiReferenceHostObject), returns the underlying native pointer, or
// nullptr if `value` does not wrap a live native object.
void* NativeScriptUnwrapNativeObject(facebook::jsi::Runtime& runtime,
const facebook::jsi::Value& value);

} // namespace nativescript
// This forwarding header keeps the Apple include paths unchanged.

extern "C" void NativeScriptInstallNativeApiJSI(
facebook::jsi::Runtime* runtime, const char* metadataPath);
#include "jsi/hermes/NativeApiJsi.h"

#endif // NATIVE_API_JSI_H
#endif // NATIVE_API_JSI_H_FFI_FORWARD
Loading
Loading