@@ -314,4 +314,68 @@ inline void debugPrintJSIObject(jsi::Runtime& rt, std::string& name, jsi::Object
314314 log.call (rt, " ===/" + name + " ===" );
315315}
316316
317+ inline void debugPrintFollyDynamic (jsi::Runtime& rt, const std::string& name, const folly::dynamic& obj) {
318+ auto console = rt.global ().getPropertyAsObject (rt, " console" );
319+ auto log = console.getPropertyAsFunction (rt, " log" );
320+
321+ std::function<void (const std::string&, const folly::dynamic&)> parser = [&](const std::string& key, const folly::dynamic& value) {
322+ if (value.isBool ()) {
323+ std::string output = key + " : " + (value.getBool () ? " true" : " false" );
324+ log.call (rt, output);
325+ return ;
326+ }
327+
328+ if (value.isNumber ()) {
329+ std::string output = key + " : " + std::to_string (value.asDouble ());
330+ log.call (rt, output);
331+ return ;
332+ }
333+
334+ if (value.isString ()) {
335+ std::string output = key + " : " + value.getString ();
336+ log.call (rt, output);
337+ return ;
338+ }
339+
340+ if (value.isNull ()) {
341+ std::string output = key + " : null" ;
342+ log.call (rt, output);
343+ return ;
344+ }
345+
346+ if (value.isArray ()) {
347+ for (size_t i = 0 ; i < value.size (); i++) {
348+ std::string arrayKey = key + " : Array[" + std::to_string (i) + " ]" ;
349+ log.call (rt, arrayKey);
350+ parser (arrayKey, value[i]);
351+ std::string endKey = key + " : Array[end]" ;
352+ log.call (rt, endKey);
353+ }
354+ return ;
355+ }
356+
357+ if (value.isObject ()) {
358+ for (const auto & pair : value.items ()) {
359+ parser (pair.first .asString (), pair.second );
360+ }
361+ return ;
362+ }
363+
364+ std::string output = key + " : [Unknown type]" ;
365+ log.call (rt, output);
366+ };
367+
368+ log.call (rt, " ===" + name + " ===" );
369+
370+ if (obj.isObject ()) {
371+ for (const auto & pair : obj.items ()) {
372+ parser (pair.first .asString (), pair.second );
373+ }
374+ } else {
375+ parser (name, obj);
376+ }
377+
378+ log.call (rt, " ===/" + name + " ===" );
379+ }
380+
317381}
0 commit comments