@@ -89,175 +89,8 @@ void SetNativeApiObjectPrototype(Runtime& runtime, Object& object,
8989#include " ../shared/bridge/HostObject.mm"
9090// clang-format on
9191
92- // --- GSD (Generated Signature Dispatch) for Hermes/JSI ---
93- // GsdObjCContext is the engine-neutral interface the generated invokers use:
94- // it reads jsi::Value arguments and writes the jsi::Value return value using
95- // the shared engine-neutral conversion helpers (which already operate on the
96- // jsi value type). Readers require the fast representation; anything else
97- // makes a reader return false so the invoker falls back to the generic path.
98- struct GsdObjCContext ;
99- using ObjCGsdInvoker = bool (*)(GsdObjCContext&);
100- struct ObjCGsdDispatchEntry {
101- uint64_t dispatchId;
102- ObjCGsdInvoker invoker;
103- };
104-
105- struct GsdObjCContext {
106- Runtime& runtime;
107- const std::shared_ptr<NativeApiBridge>& bridge;
108- id self;
109- SEL selector;
110- const Value* arguments;
111- const NativeApiType& returnType;
112- Value result = Value::undefined();
113-
114- template <typename Invocation>
115- void invokeNative (Invocation&& invocation) {
116- performGeneratedObjCInvocation (runtime, bridge, [&]() { invocation (); });
117- }
118-
119- bool readNumber (size_t i, double * out) {
120- const Value& v = arguments[i];
121- if (!v.isNumber ()) return false ;
122- *out = v.asNumber ();
123- return true ;
124- }
125- bool readBool (size_t i, uint8_t * out) {
126- const Value& v = arguments[i];
127- if (!v.isBool ()) return false ;
128- *out = v.getBool () ? 1 : 0 ;
129- return true ;
130- }
131- template <class T >
132- bool readSigned (size_t i, T* out) {
133- double tmp = 0 ;
134- if (!readNumber (i, &tmp)) return false ;
135- *out = static_cast <T>(tmp);
136- return true ;
137- }
138- template <class T >
139- bool readUnsigned (size_t i, T* out) {
140- double tmp = 0 ;
141- if (!readNumber (i, &tmp)) return false ;
142- *out = static_cast <T>(tmp);
143- return true ;
144- }
145- bool readFloat (size_t i, float * out) {
146- double tmp = 0 ;
147- if (!readNumber (i, &tmp)) return false ;
148- *out = static_cast <float >(tmp);
149- return true ;
150- }
151- bool readDouble (size_t i, double * out) { return readNumber (i, out); }
152- bool readSelector (size_t i, SEL * out) {
153- return readFastEngineSelectorArgument (runtime, arguments[i], out);
154- }
155- bool readClass (size_t i, Class * out) {
156- Class cls = classFromEngineValue (runtime, arguments[i]);
157- if (cls == Nil ) return false ;
158- *out = cls;
159- return true ;
160- }
161- bool readObject (size_t i, id * out) {
162- const Value& v = arguments[i];
163- if (v.isNull () || v.isUndefined ()) {
164- *out = nil ;
165- return true ;
166- }
167- if (!v.isObject ()) return false ;
168- Object o = v.getObject (runtime);
169- if (o.isHostObject <NativeApiObjectHostObject>(runtime)) {
170- *out = o.getHostObject <NativeApiObjectHostObject>(runtime)->object ();
171- return true ;
172- }
173- if (o.isHostObject <NativeApiClassHostObject>(runtime)) {
174- *out = static_cast <id >(
175- o.getHostObject <NativeApiClassHostObject>(runtime)->nativeClass ());
176- return true ;
177- }
178- Class cls = classFromEngineValue (runtime, v);
179- if (cls != Nil ) {
180- *out = static_cast <id >(cls);
181- return true ;
182- }
183- if (o.isHostObject <NativeApiProtocolHostObject>(runtime)) {
184- *out = static_cast <id >(
185- o.getHostObject <NativeApiProtocolHostObject>(runtime)
186- ->nativeProtocol ());
187- return true ;
188- }
189- return false ;
190- }
191-
192- void setVoid () { result = Value::undefined (); }
193- void setBool (bool v) { result = Value (v); }
194- void setInt32 (int32_t v) { result = Value (static_cast <double >(v)); }
195- void setUInt32 (uint32_t v) { result = Value (static_cast <double >(v)); }
196- void setUInt16 (uint16_t v) {
197- if (v >= 32 && v <= 126 ) {
198- result = makeString (runtime, std::string (1 , static_cast <char >(v)));
199- } else {
200- result = Value (static_cast <double >(v));
201- }
202- }
203- void setInt64 (int64_t v) { result = signedInteger64ToEngineValue (runtime, v); }
204- void setUInt64 (uint64_t v) {
205- result = unsignedInteger64ToEngineValue (runtime, v);
206- }
207- void setDouble (double v) { result = Value (v); }
208- void setSelector (SEL v) {
209- const char * name = v != nullptr ? sel_getName (v) : nullptr ;
210- result = name != nullptr ? makeString (runtime, name) : Value::null ();
211- }
212- void setClass (Class v) {
213- if (v == nil ) {
214- result = Value::null ();
215- return ;
216- }
217- const char * name = class_getName (v);
218- NativeApiSymbol symbol{
219- .kind = NativeApiSymbolKind::Class ,
220- .offset = MD_SECTION_OFFSET_NULL ,
221- .name = name != nullptr ? name : " " ,
222- .runtimeName = name != nullptr ? name : " " ,
223- };
224- if (const NativeApiSymbol* found = bridge->findClass (symbol.name )) {
225- symbol = *found;
226- }
227- result = makeNativeClassValue (runtime, bridge, std::move (symbol));
228- }
229- void setObject (id obj) {
230- result = convertNativeReturnValue (runtime, bridge, returnType, &obj);
231- }
232- };
233-
234- // Close the anonymous namespace so the generated dispatch table lives in
235- // namespace nativescript; GsdObjCContext/ObjCGsdDispatchEntry stay reachable
236- // via the unnamed namespace's implicit using-directive.
237- } // namespace (temporary close for GSD .inc)
238-
239- #if defined(__has_include)
240- #if __has_include("GeneratedGsdSignatureDispatch.inc")
241- #include " GeneratedGsdSignatureDispatch.inc"
242- #endif
243- #endif
244-
245- #ifndef NS_HAS_GENERATED_SIGNATURE_GSD_DISPATCH
246- inline constexpr ObjCGsdDispatchEntry kGeneratedObjCGsdDispatchEntries [] = {
247- {0 , nullptr }};
248- #endif
249-
250- ObjCGsdInvoker lookupObjCGsdInvoker (uint64_t dispatchId) {
251- if (!isGeneratedDispatchEnabled ()) {
252- return nullptr ;
253- }
254- return lookupDispatchInvoker<ObjCGsdDispatchEntry, ObjCGsdInvoker>(
255- kGeneratedObjCGsdDispatchEntries , dispatchId);
256- }
257-
258- namespace { // reopen anonymous namespace
92+ #include " NativeApiJsiGsd.mm"
25993
260- // --- End GSD ---
26194
26295void * lookupGeneratedEngineObjCGsdInvoker (uint64_t dispatchId) {
26396 return reinterpret_cast <void *>(lookupObjCGsdInvoker (dispatchId));
@@ -267,10 +100,9 @@ bool tryCallGeneratedEngineObjCSelector(
267100 Runtime& runtime, const std::shared_ptr<NativeApiBridge>& bridge,
268101 id receiver, const NativeApiPreparedObjCInvocation& prepared,
269102 const Value* args, size_t count, Class dispatchSuperClass, Value* result) {
270- const bool dispatchingNativeCallToUI = shouldDispatchNativeCallToUI ();
271103 if (result == nullptr || receiver == nil ||
272104 !prepared.gsdEngineCallable || dispatchSuperClass != Nil ||
273- count != prepared.gsdEngineArgumentCount || dispatchingNativeCallToUI ) {
105+ count != prepared.gsdEngineArgumentCount ) {
274106 return false ;
275107 }
276108
@@ -426,11 +258,9 @@ throw JSError(runtime,
426258 // typed cast, produce the jsi return value — bypassing all generic
427259 // marshalling. Only engages for plain calls (no super dispatch, init
428260 // disown handling, or implicit NSError-out argument).
429- const bool dispatchingNativeCallToUI = shouldDispatchNativeCallToUI ();
430261 if (prepared->gsdEngineCallable && gsdDispatchClass == Nil &&
431262 count == prepared->gsdEngineArgumentCount &&
432- !(!receiverIsClass && prepared->isInitMethod ) &&
433- !dispatchingNativeCallToUI) {
263+ !(!receiverIsClass && prepared->isInitMethod )) {
434264 auto invoker =
435265 reinterpret_cast <ObjCGsdInvoker>(prepared->engineInvoker );
436266 GsdObjCContext ctx{runtime, bridge, receiver, prepared->selector ,
0 commit comments