@@ -324,6 +324,36 @@ void consoleAssert(
324
324
#include " ForwardingConsoleMethods.def"
325
325
#undef FORWARDING_CONSOLE_METHOD
326
326
327
+ /* *
328
+ * Call innerFn and forward any arguments to the original console method
329
+ * named methodName, if possible.
330
+ */
331
+ jsi::Value forwardToOriginalConsole (
332
+ std::shared_ptr<jsi::Object> originalConsole,
333
+ const char * methodName,
334
+ CallableAsHostFunction auto innerFn) {
335
+ return [originalConsole = std::move (originalConsole),
336
+ innerFn = std::move (innerFn),
337
+ methodName](
338
+ jsi::Runtime& runtime,
339
+ const jsi::Value& thisVal,
340
+ const jsi::Value* args,
341
+ size_t count) {
342
+ jsi::Value retVal = innerFn (runtime, thisVal, args, count);
343
+ if (originalConsole) {
344
+ auto val = originalConsole->getProperty (runtime, methodName);
345
+ if (val.isObject ()) {
346
+ auto obj = val.getObject (runtime);
347
+ if (obj.isFunction (runtime)) {
348
+ auto func = obj.getFunction (runtime);
349
+ func.callWithThis (runtime, *originalConsole, args, count);
350
+ }
351
+ }
352
+ }
353
+ return std::move (retVal);
354
+ };
355
+ };
356
+
327
357
} // namespace
328
358
329
359
void RuntimeTarget::installConsoleHandler () {
@@ -368,33 +398,6 @@ void RuntimeTarget::installConsoleHandler() {
368
398
}
369
399
};
370
400
371
- /* *
372
- * Call innerFn and forward any arguments to the original console method
373
- * named methodName, if possible.
374
- */
375
- auto forwardToOriginalConsole = [originalConsole](
376
- const char * methodName,
377
- CallableAsHostFunction auto innerFn) {
378
- return [originalConsole, innerFn = std::move (innerFn), methodName](
379
- jsi::Runtime& runtime,
380
- const jsi::Value& thisVal,
381
- const jsi::Value* args,
382
- size_t count) {
383
- jsi::Value retVal = innerFn (runtime, thisVal, args, count);
384
- if (originalConsole) {
385
- auto val = originalConsole->getProperty (runtime, methodName);
386
- if (val.isObject ()) {
387
- auto obj = val.getObject (runtime);
388
- if (obj.isFunction (runtime)) {
389
- auto func = obj.getFunction (runtime);
390
- func.callWithThis (runtime, *originalConsole, args, count);
391
- }
392
- }
393
- }
394
- return retVal;
395
- };
396
- };
397
-
398
401
/* *
399
402
* Install a console method with the given name and body. The body receives
400
403
* the usual JSI host function parameters plus a ConsoleState reference, a
@@ -413,6 +416,7 @@ void RuntimeTarget::installConsoleHandler() {
413
416
jsi::PropNameID::forAscii (runtime, methodName),
414
417
0 ,
415
418
forwardToOriginalConsole (
419
+ originalConsole,
416
420
methodName,
417
421
[body = std::move (body), state, delegateExecutorSync](
418
422
jsi::Runtime& runtime,
0 commit comments