From 4f4eac0ddf285b48c626aaaeb697e42d111c1459 Mon Sep 17 00:00:00 2001 From: Olga Zinoveva Date: Thu, 16 Feb 2023 09:56:02 -0800 Subject: [PATCH] Reverting linter changes to files outside of the github folder --- .../RCTPushNotificationPlugins.h | 3 +- Libraries/TypeSafety/RCTConvertHelpers.h | 2 +- .../TypeSafety/RCTTypedModuleConstants.h | 4 +- React/Base/RCTManagedPointer.h | 4 +- React/CxxBridge/NSDataBigString.h | 4 +- React/CxxBridge/RCTCxxBridgeDelegate.h | 2 +- React/CxxModule/DispatchMessageQueueThread.h | 4 +- React/CxxModule/RCTCxxModule.h | 4 +- React/CxxModule/RCTCxxUtils.h | 4 +- .../RCTFabricComponentsPlugins.h | 15 +- .../main/jni/first-party/fb/include/fb/log.h | 2 +- .../first-party/yogajni/jni/ScopedGlobalRef.h | 24 +- .../first-party/yogajni/jni/ScopedLocalRef.h | 32 +- .../main/jni/first-party/yogajni/jni/YGJNI.h | 20 +- .../first-party/yogajni/jni/YGJNIVanilla.h | 2 +- .../first-party/yogajni/jni/YGJTypesVanilla.h | 10 +- .../yogajni/jni/YogaJniException.h | 8 +- .../main/jni/first-party/yogajni/jni/common.h | 35 +- .../first-party/yogajni/jni/corefunctions.h | 10 +- .../src/main/jni/third-party/glog/config.h | 7 +- .../third-party/libevent/evconfig-private.h | 10 +- ReactCommon/jsi/jsi/JSIDynamic.h | 8 +- ReactCommon/jsi/jsi/decorator.h | 308 +++++------ ReactCommon/jsi/jsi/instrumentation.h | 10 +- ReactCommon/jsi/jsi/jsi-inl.h | 148 ++--- ReactCommon/jsi/jsi/jsi.h | 520 +++++++++--------- ReactCommon/jsi/jsi/jsilib.h | 10 +- ReactCommon/jsi/jsi/test/testlib.h | 8 +- ReactCommon/jsi/jsi/threadsafe.h | 8 +- ReactCommon/react/renderer/debug/flags.h | 10 +- .../react/utils/ManagedObjectWrapper.h | 2 +- ReactCommon/yoga/yoga/BitUtils.h | 8 +- ReactCommon/yoga/yoga/CompactValue.h | 18 +- ReactCommon/yoga/yoga/Utils.h | 12 +- ReactCommon/yoga/yoga/YGConfig.h | 20 +- ReactCommon/yoga/yoga/YGFloatOptional.h | 12 +- ReactCommon/yoga/yoga/YGLayout.h | 8 +- ReactCommon/yoga/yoga/YGMacros.h | 8 +- ReactCommon/yoga/yoga/YGNode.h | 142 ++--- ReactCommon/yoga/yoga/YGNodePrint.h | 2 +- ReactCommon/yoga/yoga/YGStyle.h | 176 ++---- ReactCommon/yoga/yoga/YGValue.h | 8 +- ReactCommon/yoga/yoga/Yoga-internal.h | 28 +- ReactCommon/yoga/yoga/Yoga.h | 88 +-- ReactCommon/yoga/yoga/event/event.h | 44 +- ReactCommon/yoga/yoga/log.h | 12 +- 46 files changed, 844 insertions(+), 980 deletions(-) diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationPlugins.h b/Libraries/PushNotificationIOS/RCTPushNotificationPlugins.h index b738c1ca62381a..d25e019c14b384 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationPlugins.h +++ b/Libraries/PushNotificationIOS/RCTPushNotificationPlugins.h @@ -9,8 +9,7 @@ #ifdef RN_DISABLE_OSS_PLUGIN_HEADER -// FB Internal: FBRCTPushNotificationPlugins.h is autogenerated by the build -// system. +// FB Internal: FBRCTPushNotificationPlugins.h is autogenerated by the build system. #import #else diff --git a/Libraries/TypeSafety/RCTConvertHelpers.h b/Libraries/TypeSafety/RCTConvertHelpers.h index 0059c14a63300b..d33f42c8ff18d8 100644 --- a/Libraries/TypeSafety/RCTConvertHelpers.h +++ b/Libraries/TypeSafety/RCTConvertHelpers.h @@ -18,7 +18,7 @@ namespace react { template using LazyVector = FB::LazyVector; } -} // namespace facebook +} template NSArray *RCTConvertVecToArray(const ContainerT &vec, id (^convertor)(typename ContainerT::value_type element)) diff --git a/Libraries/TypeSafety/RCTTypedModuleConstants.h b/Libraries/TypeSafety/RCTTypedModuleConstants.h index fa5aa51ec4b79e..a787b6788ebc5d 100644 --- a/Libraries/TypeSafety/RCTTypedModuleConstants.h +++ b/Libraries/TypeSafety/RCTTypedModuleConstants.h @@ -45,5 +45,5 @@ ModuleConstants typedConstants(typename T::Builder::Input &&value) return [_RCTTypedModuleConstants newWithUnsafeDictionary:builder.buildUnsafeRawValue()]; } -} // namespace react -} // namespace facebook +} +} diff --git a/React/Base/RCTManagedPointer.h b/React/Base/RCTManagedPointer.h index acf7479c1ff2d8..ff444d27e711ee 100644 --- a/React/Base/RCTManagedPointer.h +++ b/React/Base/RCTManagedPointer.h @@ -34,7 +34,7 @@ RCTManagedPointer *managedPointer(P initializer) return [[RCTManagedPointer alloc] initWithPointer:std::move(ptr)]; } -} // namespace react -} // namespace facebook +} +} #endif diff --git a/React/CxxBridge/NSDataBigString.h b/React/CxxBridge/NSDataBigString.h index a42efb26bde3ec..c7f5ae7f61eac4 100644 --- a/React/CxxBridge/NSDataBigString.h +++ b/React/CxxBridge/NSDataBigString.h @@ -38,5 +38,5 @@ class NSDataBigString : public JSBigString { size_t m_length; }; -} // namespace react -} // namespace facebook +} +} diff --git a/React/CxxBridge/RCTCxxBridgeDelegate.h b/React/CxxBridge/RCTCxxBridgeDelegate.h index 9381c6692a852d..0285b70f217ee8 100644 --- a/React/CxxBridge/RCTCxxBridgeDelegate.h +++ b/React/CxxBridge/RCTCxxBridgeDelegate.h @@ -15,7 +15,7 @@ namespace react { class JSExecutorFactory; } -} // namespace facebook +} // This is a separate class so non-C++ implementations don't need to // take a C++ dependency. diff --git a/React/CxxModule/DispatchMessageQueueThread.h b/React/CxxModule/DispatchMessageQueueThread.h index 4e91f8476fbd79..76eaa15fd975b9 100644 --- a/React/CxxModule/DispatchMessageQueueThread.h +++ b/React/CxxModule/DispatchMessageQueueThread.h @@ -43,5 +43,5 @@ class DispatchMessageQueueThread : public MessageQueueThread { RCTModuleData *moduleData_; }; -} // namespace react -} // namespace facebook +} +} diff --git a/React/CxxModule/RCTCxxModule.h b/React/CxxModule/RCTCxxModule.h index 7fde83c66b01b6..75d95a30901d97 100644 --- a/React/CxxModule/RCTCxxModule.h +++ b/React/CxxModule/RCTCxxModule.h @@ -16,8 +16,8 @@ namespace xplat { namespace module { class CxxModule; } -} // namespace xplat -} // namespace facebook +} +} /** * Subclass RCTCxxModule to use cross-platform CxxModule on iOS. diff --git a/React/CxxModule/RCTCxxUtils.h b/React/CxxModule/RCTCxxUtils.h index 257827df833143..cc1454f07601ff 100644 --- a/React/CxxModule/RCTCxxUtils.h +++ b/React/CxxModule/RCTCxxUtils.h @@ -25,5 +25,5 @@ createNativeModules(NSArray *modules, RCTBridge *bridge, const NSError *tryAndReturnError(const std::function &func); NSString *deriveSourceURL(NSURL *url); -} // namespace react -} // namespace facebook +} +} diff --git a/React/Fabric/Mounting/ComponentViews/RCTFabricComponentsPlugins.h b/React/Fabric/Mounting/ComponentViews/RCTFabricComponentsPlugins.h index 349ea3b4bce73a..6ce762210f0e99 100644 --- a/React/Fabric/Mounting/ComponentViews/RCTFabricComponentsPlugins.h +++ b/React/Fabric/Mounting/ComponentViews/RCTFabricComponentsPlugins.h @@ -9,8 +9,7 @@ #ifdef RN_DISABLE_OSS_PLUGIN_HEADER -// FB Internal: FBRCTFabricComponentsPlugins.h is autogenerated by the build -// system. +// FB Internal: FBRCTFabricComponentsPlugins.h is autogenerated by the build system. #import #else @@ -33,17 +32,13 @@ Class RCTFabricComponentsProvider(const char *name); // Lookup functions Class RCTSafeAreaViewCls(void) __attribute__((used)); Class RCTScrollViewCls(void) __attribute__((used)); -Class RCTPullToRefreshViewCls(void) - __attribute__((used)); -Class RCTActivityIndicatorViewCls(void) - __attribute__((used)); +Class RCTPullToRefreshViewCls(void) __attribute__((used)); +Class RCTActivityIndicatorViewCls(void) __attribute__((used)); Class RCTSwitchCls(void) __attribute__((used)); -Class RCTUnimplementedNativeViewCls(void) - __attribute__((used)); +Class RCTUnimplementedNativeViewCls(void) __attribute__((used)); Class RCTParagraphCls(void) __attribute__((used)); Class RCTTextInputCls(void) __attribute__((used)); -Class RCTInputAccessoryCls(void) - __attribute__((used)); +Class RCTInputAccessoryCls(void) __attribute__((used)); Class RCTViewCls(void) __attribute__((used)); Class RCTImageCls(void) __attribute__((used)); Class RCTModalHostViewCls(void) __attribute__((used)); diff --git a/ReactAndroid/src/main/jni/first-party/fb/include/fb/log.h b/ReactAndroid/src/main/jni/first-party/fb/include/fb/log.h index 7e3e3dd7bc2d0b..ecc2a1f5a1789e 100644 --- a/ReactAndroid/src/main/jni/first-party/fb/include/fb/log.h +++ b/ReactAndroid/src/main/jni/first-party/fb/include/fb/log.h @@ -264,7 +264,7 @@ int __android_log_print(int prio, const char *tag, const char *fmt, ...) * Stripped out of release builds. Uses the current LOG_TAG. */ #define FBLOG_ASSERT(cond, ...) FBLOG_FATAL_IF(!(cond), __VA_ARGS__) -// #define LOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond) +//#define LOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond) // --------------------------------------------------------------------- diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/ScopedGlobalRef.h b/ReactAndroid/src/main/jni/first-party/yogajni/jni/ScopedGlobalRef.h index 0c700b3662c1ee..e50a5702f5cfaf 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/ScopedGlobalRef.h +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/ScopedGlobalRef.h @@ -58,7 +58,7 @@ class ScopedGlobalRef { std::is_same(), "ScopedGlobalRef instantiated for invalid type"); - public: +public: /** * Constructs a ScopedGlobalRef with a JNI global reference. * @@ -74,19 +74,17 @@ class ScopedGlobalRef { /** * Move construction is allowed. */ - ScopedGlobalRef(ScopedGlobalRef &&s) : mGlobalRef(s.release()) {} + ScopedGlobalRef(ScopedGlobalRef&& s) : mGlobalRef(s.release()) {} /** * Move assignment is allowed. */ - ScopedGlobalRef &operator=(ScopedGlobalRef &&s) { + ScopedGlobalRef& operator=(ScopedGlobalRef&& s) { reset(s.release()); return *this; } - ~ScopedGlobalRef() { - reset(); - } + ~ScopedGlobalRef() { reset(); } /** * Deletes the currently held reference and reassigns a new one to the @@ -115,21 +113,17 @@ class ScopedGlobalRef { /** * Returns the underlying JNI global reference. */ - T get() const { - return mGlobalRef; - } + T get() const { return mGlobalRef; } /** * Returns true if the underlying JNI reference is not NULL. */ - operator bool() const { - return mGlobalRef != NULL; - } + operator bool() const { return mGlobalRef != NULL; } - ScopedGlobalRef(const ScopedGlobalRef &ref) = delete; - ScopedGlobalRef &operator=(const ScopedGlobalRef &other) = delete; + ScopedGlobalRef(const ScopedGlobalRef& ref) = delete; + ScopedGlobalRef& operator=(const ScopedGlobalRef& other) = delete; - private: +private: T mGlobalRef; }; diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/ScopedLocalRef.h b/ReactAndroid/src/main/jni/first-party/yogajni/jni/ScopedLocalRef.h index cd151e33e0484a..9e127db308e82c 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/ScopedLocalRef.h +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/ScopedLocalRef.h @@ -56,36 +56,34 @@ class ScopedLocalRef { std::is_same(), "ScopedLocalRef instantiated for invalid type"); - public: +public: /** * Constructs a ScopedLocalRef with a JNI local reference. * * @param localRef the local reference to wrap. Can be NULL. */ - ScopedLocalRef(JNIEnv *env, T localRef) : mEnv(env), mLocalRef(localRef) {} + ScopedLocalRef(JNIEnv* env, T localRef) : mEnv(env), mLocalRef(localRef) {} /** * Equivalent to ScopedLocalRef(env, NULL) */ - explicit ScopedLocalRef(JNIEnv *env) : mEnv(env), mLocalRef(NULL) {} + explicit ScopedLocalRef(JNIEnv* env) : mEnv(env), mLocalRef(NULL) {} /** * Move construction is allowed. */ - ScopedLocalRef(ScopedLocalRef &&s) : mEnv(s.mEnv), mLocalRef(s.release()) {} + ScopedLocalRef(ScopedLocalRef&& s) : mEnv(s.mEnv), mLocalRef(s.release()) {} /** * Move assignment is allowed. */ - ScopedLocalRef &operator=(ScopedLocalRef &&s) { + ScopedLocalRef& operator=(ScopedLocalRef&& s) { reset(s.release()); mEnv = s.mEnv; return *this; } - ~ScopedLocalRef() { - reset(); - } + ~ScopedLocalRef() { reset(); } /** * Deletes the currently held reference and reassigns a new one to the @@ -114,27 +112,23 @@ class ScopedLocalRef { /** * Returns the underlying JNI local reference. */ - T get() const { - return mLocalRef; - } + T get() const { return mLocalRef; } /** * Returns true if the underlying JNI reference is not NULL. */ - operator bool() const { - return mLocalRef != NULL; - } + operator bool() const { return mLocalRef != NULL; } - ScopedLocalRef(const ScopedLocalRef &ref) = delete; - ScopedLocalRef &operator=(const ScopedLocalRef &other) = delete; + ScopedLocalRef(const ScopedLocalRef& ref) = delete; + ScopedLocalRef& operator=(const ScopedLocalRef& other) = delete; - private: - JNIEnv *mEnv; +private: + JNIEnv* mEnv; T mLocalRef; }; template -ScopedLocalRef make_local_ref(JNIEnv *env, T localRef) { +ScopedLocalRef make_local_ref(JNIEnv* env, T localRef) { return ScopedLocalRef(env, localRef); } diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h index 02c0c68f3ae2ff..69f11392d3fd4c 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.h @@ -21,13 +21,13 @@ const int HAS_NEW_LAYOUT = 16; union YGNodeContext { uintptr_t edgesSet = 0; - void *asVoidPtr; + void* asVoidPtr; }; class YGNodeEdges { uintptr_t edges_; - public: +public: enum Edge { MARGIN = 1, PADDING = 2, @@ -46,30 +46,26 @@ class YGNodeEdges { node->setContext(context.asVoidPtr); } - bool has(Edge edge) { - return (edges_ & edge) == edge; - } + bool has(Edge edge) { return (edges_ & edge) == edge; } - YGNodeEdges &add(Edge edge) { + YGNodeEdges& add(Edge edge) { edges_ |= edge; return *this; } - int get() { - return edges_; - } + int get() { return edges_; } }; struct YogaValue { static constexpr jint NAN_BYTES = 0x7fc00000; - static jlong asJavaLong(const YGValue &value) { + static jlong asJavaLong(const YGValue& value) { uint32_t valueBytes = 0; memcpy(&valueBytes, &value.value, sizeof valueBytes); - return ((jlong)value.unit) << 32 | valueBytes; + return ((jlong) value.unit) << 32 | valueBytes; } constexpr static jlong undefinedAsJavaLong() { - return ((jlong)YGUnitUndefined) << 32 | NAN_BYTES; + return ((jlong) YGUnitUndefined) << 32 | NAN_BYTES; } }; } // namespace diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.h b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.h index f50ecc21fb1f5f..77b8b11ba3c02a 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.h +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNIVanilla.h @@ -8,5 +8,5 @@ #include "jni.h" namespace YGJNIVanilla { -void registerNatives(JNIEnv *env); +void registerNatives(JNIEnv* env); }; diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJTypesVanilla.h b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJTypesVanilla.h index 409c09e2ba65e0..1b4d62dfae49fc 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJTypesVanilla.h +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJTypesVanilla.h @@ -5,37 +5,37 @@ * LICENSE file in the root directory of this source tree. */ +#include "jni.h" #include #include #include #include "common.h" -#include "jni.h" class PtrJNodeMapVanilla { std::map ptrsToIdxs_; jobjectArray javaNodes_; - public: +public: PtrJNodeMapVanilla() : ptrsToIdxs_{}, javaNodes_{} {} PtrJNodeMapVanilla(jlongArray javaNativePointers, jobjectArray javaNodes) : javaNodes_{javaNodes} { using namespace facebook::yoga::vanillajni; - JNIEnv *env = getCurrentEnv(); + JNIEnv* env = getCurrentEnv(); size_t nativePointersSize = env->GetArrayLength(javaNativePointers); std::vector nativePointers(nativePointersSize); env->GetLongArrayRegion( javaNativePointers, 0, nativePointersSize, nativePointers.data()); for (size_t i = 0; i < nativePointersSize; ++i) { - ptrsToIdxs_[(YGNodeRef)nativePointers[i]] = i; + ptrsToIdxs_[(YGNodeRef) nativePointers[i]] = i; } } facebook::yoga::vanillajni::ScopedLocalRef ref(YGNodeRef node) { using namespace facebook::yoga::vanillajni; - JNIEnv *env = getCurrentEnv(); + JNIEnv* env = getCurrentEnv(); auto idx = ptrsToIdxs_.find(node); if (idx == ptrsToIdxs_.end()) { return ScopedLocalRef(env); diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YogaJniException.h b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YogaJniException.h index 7b98ea599fd053..b0378ab450ff83 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YogaJniException.h +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YogaJniException.h @@ -18,19 +18,19 @@ namespace vanillajni { * does not gets cleared before jni call completion */ class YogaJniException : public std::exception { - public: +public: YogaJniException(); ~YogaJniException() override; explicit YogaJniException(jthrowable throwable); - YogaJniException(YogaJniException &&rhs); + YogaJniException(YogaJniException&& rhs); - YogaJniException(const YogaJniException &other); + YogaJniException(const YogaJniException& other); ScopedLocalRef getThrowable() const noexcept; - private: +private: ScopedGlobalRef throwable_; }; } // namespace vanillajni diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/common.h b/ReactAndroid/src/main/jni/first-party/yogajni/jni/common.h index a46922a668a480..d79c3e50ceb005 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/common.h +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/common.h @@ -17,8 +17,8 @@ namespace vanillajni { * Registers a set of methods for a JNI class. Aborts if registration fails. */ void registerNatives( - JNIEnv *env, - const char *className, + JNIEnv* env, + const char* className, const JNINativeMethod methods[], size_t numMethods); @@ -26,29 +26,29 @@ void registerNatives( * Returns a jmethodID for a class static method. Aborts if any error happens. */ jmethodID getStaticMethodId( - JNIEnv *env, + JNIEnv* env, jclass clazz, - const char *methodName, - const char *methodDescriptor); + const char* methodName, + const char* methodDescriptor); /** * Returns a jmethodID for a class non-static method. Aborts if any error * happens. */ jmethodID getMethodId( - JNIEnv *env, + JNIEnv* env, jclass clazz, - const char *methodName, - const char *methodDescriptor); + const char* methodName, + const char* methodDescriptor); /** * Returns a class non-static field ID. Aborts if any error happens. */ jfieldID getFieldId( - JNIEnv *env, + JNIEnv* env, jclass clazz, - const char *fieldName, - const char *fieldSignature); + const char* fieldName, + const char* fieldSignature); // Helper methods to call a non-static method on an object depending on the // return type. Each method will abort the execution if an error @@ -56,21 +56,24 @@ jfieldID getFieldId( // Java method. #define DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jnitype, readableType) \ jnitype call##readableType##Method( \ - JNIEnv *env, jobject obj, jmethodID methodId, ...) + JNIEnv* env, jobject obj, jmethodID methodId, ...) DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(void, Void); DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jlong, Long); DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jfloat, Float); -ScopedLocalRef -callStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodId, ...); +ScopedLocalRef callStaticObjectMethod( + JNIEnv* env, + jclass clazz, + jmethodID methodId, + ...); /** * Given a local or a global reference, this method creates a new global * reference out of it. If any error happens, aborts the process. */ -ScopedGlobalRef newGlobalRef(JNIEnv *env, jobject obj); +ScopedGlobalRef newGlobalRef(JNIEnv* env, jobject obj); -ScopedGlobalRef newGlobalRef(JNIEnv *env, jthrowable obj); +ScopedGlobalRef newGlobalRef(JNIEnv* env, jthrowable obj); } // namespace vanillajni } // namespace yoga } // namespace facebook diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/corefunctions.h b/ReactAndroid/src/main/jni/first-party/yogajni/jni/corefunctions.h index 8e0bb171a8e50f..e6f2650e09fea2 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/corefunctions.h +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/corefunctions.h @@ -28,26 +28,26 @@ namespace vanillajni { * that is passed to the "on load" JNI hook. * @return an integer value to return from the "on load" hook. */ -jint ensureInitialized(JNIEnv **env, JavaVM *vm); +jint ensureInitialized(JNIEnv** env, JavaVM* vm); /** * Returns a JNIEnv* suitable for the current thread. If the current thread is * not attached to the Java VM, this method aborts execution. */ -JNIEnv *getCurrentEnv(); +JNIEnv* getCurrentEnv(); /** * Logs an error message and aborts the current process. */ -void logErrorMessageAndDie(const char *message); +void logErrorMessageAndDie(const char* message); /** * Checks whether there is a pending JNI exception. If so, it logs an error * message and aborts the current process. Otherwise it does nothing. */ -void assertNoPendingJniException(JNIEnv *env); +void assertNoPendingJniException(JNIEnv* env); -void assertNoPendingJniExceptionIf(JNIEnv *env, bool condition); +void assertNoPendingJniExceptionIf(JNIEnv* env, bool condition); } // namespace vanillajni } // namespace yoga diff --git a/ReactAndroid/src/main/jni/third-party/glog/config.h b/ReactAndroid/src/main/jni/third-party/glog/config.h index 294a18f240bc3b..ab05c5a7e192e3 100644 --- a/ReactAndroid/src/main/jni/third-party/glog/config.h +++ b/ReactAndroid/src/main/jni/third-party/glog/config.h @@ -122,7 +122,7 @@ #define HAVE___SYNC_VAL_COMPARE_AND_SWAP 1 /* Define to the sub-directory in which libtool stores uninstalled libraries. - */ + */ #define LT_OBJDIR ".libs/" /* Name of package */ @@ -173,8 +173,9 @@ /* Puts following code inside the Google namespace */ #define _START_GOOGLE_NAMESPACE_ namespace google { -/* TODO(vjn/dreiss): revisit these when use the android-21 (or newer) NDK - * platform. */ + + +/* TODO(vjn/dreiss): revisit these when use the android-21 (or newer) NDK platform. */ #undef HAVE_SYSCALL_H #undef HAVE_SYS_SYSCALL_H #undef OS_LINUX diff --git a/ReactAndroid/src/main/jni/third-party/libevent/evconfig-private.h b/ReactAndroid/src/main/jni/third-party/libevent/evconfig-private.h index e0f6db2a929c4e..f6b08e353e841a 100644 --- a/ReactAndroid/src/main/jni/third-party/libevent/evconfig-private.h +++ b/ReactAndroid/src/main/jni/third-party/libevent/evconfig-private.h @@ -6,23 +6,23 @@ /* Enable extensions on AIX 3, Interix. */ #ifndef _ALL_SOURCE -#define _ALL_SOURCE 1 +# define _ALL_SOURCE 1 #endif /* Enable GNU extensions on systems that have them. */ #ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 +# define _GNU_SOURCE 1 #endif /* Enable threading extensions on Solaris. */ #ifndef _POSIX_PTHREAD_SEMANTICS -#define _POSIX_PTHREAD_SEMANTICS 1 +# define _POSIX_PTHREAD_SEMANTICS 1 #endif /* Enable extensions on HP NonStop. */ #ifndef _TANDEM_SOURCE -#define _TANDEM_SOURCE 1 +# define _TANDEM_SOURCE 1 #endif /* Enable general extensions on Solaris. */ #ifndef __EXTENSIONS__ -#define __EXTENSIONS__ 1 +# define __EXTENSIONS__ 1 #endif /* Number of bits in a file offset, on hosts where this is settable. */ diff --git a/ReactCommon/jsi/jsi/JSIDynamic.h b/ReactCommon/jsi/jsi/JSIDynamic.h index 97ee8d3014444a..110dd13999f437 100644 --- a/ReactCommon/jsi/jsi/JSIDynamic.h +++ b/ReactCommon/jsi/jsi/JSIDynamic.h @@ -14,12 +14,12 @@ namespace facebook { namespace jsi { facebook::jsi::Value valueFromDynamic( - facebook::jsi::Runtime &runtime, - const folly::dynamic &dyn); + facebook::jsi::Runtime& runtime, + const folly::dynamic& dyn); folly::dynamic dynamicFromValue( - facebook::jsi::Runtime &runtime, - const facebook::jsi::Value &value); + facebook::jsi::Runtime& runtime, + const facebook::jsi::Value& value); } // namespace jsi } // namespace facebook diff --git a/ReactCommon/jsi/jsi/decorator.h b/ReactCommon/jsi/jsi/decorator.h index 8aa819e0b244b4..baece80fe71d0f 100644 --- a/ReactCommon/jsi/jsi/decorator.h +++ b/ReactCommon/jsi/jsi/decorator.h @@ -24,15 +24,15 @@ namespace jsi { // should be the decorated runtime, not the plain one. class DecoratedHostFunction { public: - DecoratedHostFunction(Runtime &drt, HostFunctionType plainHF) + DecoratedHostFunction(Runtime& drt, HostFunctionType plainHF) : drt_(drt), plainHF_(std::move(plainHF)) {} - Runtime &decoratedRuntime() { + Runtime& decoratedRuntime() { return drt_; } Value - operator()(Runtime &, const Value &thisVal, const Value *args, size_t count) { + operator()(Runtime&, const Value& thisVal, const Value* args, size_t count) { return plainHF_(decoratedRuntime(), thisVal, args, count); } @@ -40,7 +40,7 @@ class DecoratedHostFunction { template friend class RuntimeDecorator; - Runtime &drt_; + Runtime& drt_; HostFunctionType plainHF_; }; @@ -56,25 +56,25 @@ class DecoratedHostFunction { // as it is not used. class DecoratedHostObject : public HostObject { public: - DecoratedHostObject(Runtime &drt, std::shared_ptr plainHO) + DecoratedHostObject(Runtime& drt, std::shared_ptr plainHO) : drt_(drt), plainHO_(plainHO) {} // The derived class methods can call this to get a reference to the // decorated runtime, since the rt passed to the callback will be // the plain runtime. - Runtime &decoratedRuntime() { + Runtime& decoratedRuntime() { return drt_; } - Value get(Runtime &, const PropNameID &name) override { + Value get(Runtime&, const PropNameID& name) override { return plainHO_->get(decoratedRuntime(), name); } - void set(Runtime &, const PropNameID &name, const Value &value) override { + void set(Runtime&, const PropNameID& name, const Value& value) override { plainHO_->set(decoratedRuntime(), name, value); } - std::vector getPropertyNames(Runtime &) override { + std::vector getPropertyNames(Runtime&) override { return plainHO_->getPropertyNames(decoratedRuntime()); } @@ -82,7 +82,7 @@ class DecoratedHostObject : public HostObject { template friend class RuntimeDecorator; - Runtime &drt_; + Runtime& drt_; std::shared_ptr plainHO_; }; @@ -99,7 +99,7 @@ class DecoratedHostObject : public HostObject { template class RuntimeDecorator : public Base, private jsi::Instrumentation { public: - Plain &plain() { + Plain& plain() { static_assert( std::is_base_of::value, "RuntimeDecorator's Plain type must derive from jsi::Runtime"); @@ -108,22 +108,22 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { "RuntimeDecorator's Base type must derive from jsi::Runtime"); return plain_; } - const Plain &plain() const { + const Plain& plain() const { return plain_; } Value evaluateJavaScript( - const std::shared_ptr &buffer, - const std::string &sourceURL) override { + const std::shared_ptr& buffer, + const std::string& sourceURL) override { return plain().evaluateJavaScript(buffer, sourceURL); } std::shared_ptr prepareJavaScript( - const std::shared_ptr &buffer, + const std::shared_ptr& buffer, std::string sourceURL) override { return plain().prepareJavaScript(buffer, std::move(sourceURL)); } Value evaluatePreparedJavaScript( - const std::shared_ptr &js) override { + const std::shared_ptr& js) override { return plain().evaluatePreparedJavaScript(js); } bool drainMicrotasks(int maxMicrotasksHint) override { @@ -138,7 +138,7 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { bool isInspectable() override { return plain().isInspectable(); }; - Instrumentation &instrumentation() override { + Instrumentation& instrumentation() override { return *this; } @@ -149,47 +149,47 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { // Runtime. Note that the ctor and dtor do not access through the // reference, so passing a reference to an object before its // lifetime has started is ok. - RuntimeDecorator(Plain &plain) : plain_(plain) {} + RuntimeDecorator(Plain& plain) : plain_(plain) {} - Runtime::PointerValue *cloneSymbol(const Runtime::PointerValue *pv) override { + Runtime::PointerValue* cloneSymbol(const Runtime::PointerValue* pv) override { return plain_.cloneSymbol(pv); }; - Runtime::PointerValue *cloneBigInt(const Runtime::PointerValue *pv) override { + Runtime::PointerValue* cloneBigInt(const Runtime::PointerValue* pv) override { return plain_.cloneBigInt(pv); }; - Runtime::PointerValue *cloneString(const Runtime::PointerValue *pv) override { + Runtime::PointerValue* cloneString(const Runtime::PointerValue* pv) override { return plain_.cloneString(pv); }; - Runtime::PointerValue *cloneObject(const Runtime::PointerValue *pv) override { + Runtime::PointerValue* cloneObject(const Runtime::PointerValue* pv) override { return plain_.cloneObject(pv); }; - Runtime::PointerValue *clonePropNameID( - const Runtime::PointerValue *pv) override { + Runtime::PointerValue* clonePropNameID( + const Runtime::PointerValue* pv) override { return plain_.clonePropNameID(pv); }; - PropNameID createPropNameIDFromAscii(const char *str, size_t length) + PropNameID createPropNameIDFromAscii(const char* str, size_t length) override { return plain_.createPropNameIDFromAscii(str, length); }; - PropNameID createPropNameIDFromUtf8(const uint8_t *utf8, size_t length) + PropNameID createPropNameIDFromUtf8(const uint8_t* utf8, size_t length) override { return plain_.createPropNameIDFromUtf8(utf8, length); }; - PropNameID createPropNameIDFromString(const String &str) override { + PropNameID createPropNameIDFromString(const String& str) override { return plain_.createPropNameIDFromString(str); }; - PropNameID createPropNameIDFromSymbol(const Symbol &sym) override { + PropNameID createPropNameIDFromSymbol(const Symbol& sym) override { return plain_.createPropNameIDFromSymbol(sym); }; - std::string utf8(const PropNameID &id) override { + std::string utf8(const PropNameID& id) override { return plain_.utf8(id); }; - bool compare(const PropNameID &a, const PropNameID &b) override { + bool compare(const PropNameID& a, const PropNameID& b) override { return plain_.compare(a, b); }; - std::string symbolToString(const Symbol &sym) override { + std::string symbolToString(const Symbol& sym) override { return plain_.symbolToString(sym); } @@ -199,26 +199,26 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { BigInt createBigIntFromUint64(uint64_t value) override { return plain_.createBigIntFromUint64(value); } - bool bigintIsInt64(const BigInt &b) override { + bool bigintIsInt64(const BigInt& b) override { return plain_.bigintIsInt64(b); } - bool bigintIsUint64(const BigInt &b) override { + bool bigintIsUint64(const BigInt& b) override { return plain_.bigintIsUint64(b); } - uint64_t truncate(const BigInt &b) override { + uint64_t truncate(const BigInt& b) override { return plain_.truncate(b); } - String bigintToString(const BigInt &bigint, int radix) override { + String bigintToString(const BigInt& bigint, int radix) override { return plain_.bigintToString(bigint, radix); } - String createStringFromAscii(const char *str, size_t length) override { + String createStringFromAscii(const char* str, size_t length) override { return plain_.createStringFromAscii(str, length); }; - String createStringFromUtf8(const uint8_t *utf8, size_t length) override { + String createStringFromUtf8(const uint8_t* utf8, size_t length) override { return plain_.createStringFromUtf8(utf8, length); }; - std::string utf8(const String &s) override { + std::string utf8(const String& s) override { return plain_.utf8(s); } @@ -230,74 +230,74 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { return plain_.createObject( std::make_shared(*this, std::move(ho))); }; - std::shared_ptr getHostObject(const jsi::Object &o) override { + std::shared_ptr getHostObject(const jsi::Object& o) override { std::shared_ptr dho = plain_.getHostObject(o); - return static_cast(*dho).plainHO_; + return static_cast(*dho).plainHO_; }; - HostFunctionType &getHostFunction(const jsi::Function &f) override { - HostFunctionType &dhf = plain_.getHostFunction(f); + HostFunctionType& getHostFunction(const jsi::Function& f) override { + HostFunctionType& dhf = plain_.getHostFunction(f); // This will fail if a cpp file including this header is not compiled // with RTTI. return dhf.target()->plainHF_; }; - bool hasNativeState(const Object &o) override { + bool hasNativeState(const Object& o) override { return plain_.hasNativeState(o); } - std::shared_ptr getNativeState(const Object &o) override { + std::shared_ptr getNativeState(const Object& o) override { return plain_.getNativeState(o); } - void setNativeState(const Object &o, std::shared_ptr state) + void setNativeState(const Object& o, std::shared_ptr state) override { plain_.setNativeState(o, state); } - Value getProperty(const Object &o, const PropNameID &name) override { + Value getProperty(const Object& o, const PropNameID& name) override { return plain_.getProperty(o, name); }; - Value getProperty(const Object &o, const String &name) override { + Value getProperty(const Object& o, const String& name) override { return plain_.getProperty(o, name); }; - bool hasProperty(const Object &o, const PropNameID &name) override { + bool hasProperty(const Object& o, const PropNameID& name) override { return plain_.hasProperty(o, name); }; - bool hasProperty(const Object &o, const String &name) override { + bool hasProperty(const Object& o, const String& name) override { return plain_.hasProperty(o, name); }; void setPropertyValue( - const Object &o, - const PropNameID &name, - const Value &value) override { + const Object& o, + const PropNameID& name, + const Value& value) override { plain_.setPropertyValue(o, name, value); }; - void setPropertyValue(const Object &o, const String &name, const Value &value) + void setPropertyValue(const Object& o, const String& name, const Value& value) override { plain_.setPropertyValue(o, name, value); }; - bool isArray(const Object &o) const override { + bool isArray(const Object& o) const override { return plain_.isArray(o); }; - bool isArrayBuffer(const Object &o) const override { + bool isArrayBuffer(const Object& o) const override { return plain_.isArrayBuffer(o); }; - bool isFunction(const Object &o) const override { + bool isFunction(const Object& o) const override { return plain_.isFunction(o); }; - bool isHostObject(const jsi::Object &o) const override { + bool isHostObject(const jsi::Object& o) const override { return plain_.isHostObject(o); }; - bool isHostFunction(const jsi::Function &f) const override { + bool isHostFunction(const jsi::Function& f) const override { return plain_.isHostFunction(f); }; - Array getPropertyNames(const Object &o) override { + Array getPropertyNames(const Object& o) override { return plain_.getPropertyNames(o); }; - WeakObject createWeakObject(const Object &o) override { + WeakObject createWeakObject(const Object& o) override { return plain_.createWeakObject(o); }; - Value lockWeakObject(const WeakObject &wo) override { + Value lockWeakObject(const WeakObject& wo) override { return plain_.lockWeakObject(wo); }; @@ -308,64 +308,64 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { std::shared_ptr buffer) override { return plain_.createArrayBuffer(std::move(buffer)); }; - size_t size(const Array &a) override { + size_t size(const Array& a) override { return plain_.size(a); }; - size_t size(const ArrayBuffer &ab) override { + size_t size(const ArrayBuffer& ab) override { return plain_.size(ab); }; - uint8_t *data(const ArrayBuffer &ab) override { + uint8_t* data(const ArrayBuffer& ab) override { return plain_.data(ab); }; - Value getValueAtIndex(const Array &a, size_t i) override { + Value getValueAtIndex(const Array& a, size_t i) override { return plain_.getValueAtIndex(a, i); }; - void setValueAtIndexImpl(const Array &a, size_t i, const Value &value) + void setValueAtIndexImpl(const Array& a, size_t i, const Value& value) override { plain_.setValueAtIndexImpl(a, i, value); }; Function createFunctionFromHostFunction( - const PropNameID &name, + const PropNameID& name, unsigned int paramCount, HostFunctionType func) override { return plain_.createFunctionFromHostFunction( name, paramCount, DecoratedHostFunction(*this, std::move(func))); }; Value call( - const Function &f, - const Value &jsThis, - const Value *args, + const Function& f, + const Value& jsThis, + const Value* args, size_t count) override { return plain_.call(f, jsThis, args, count); }; - Value callAsConstructor(const Function &f, const Value *args, size_t count) + Value callAsConstructor(const Function& f, const Value* args, size_t count) override { return plain_.callAsConstructor(f, args, count); }; // Private data for managing scopes. - Runtime::ScopeState *pushScope() override { + Runtime::ScopeState* pushScope() override { return plain_.pushScope(); } - void popScope(Runtime::ScopeState *ss) override { + void popScope(Runtime::ScopeState* ss) override { plain_.popScope(ss); } - bool strictEquals(const Symbol &a, const Symbol &b) const override { + bool strictEquals(const Symbol& a, const Symbol& b) const override { return plain_.strictEquals(a, b); }; - bool strictEquals(const BigInt &a, const BigInt &b) const override { + bool strictEquals(const BigInt& a, const BigInt& b) const override { return plain_.strictEquals(a, b); }; - bool strictEquals(const String &a, const String &b) const override { + bool strictEquals(const String& a, const String& b) const override { return plain_.strictEquals(a, b); }; - bool strictEquals(const Object &a, const Object &b) const override { + bool strictEquals(const Object& a, const Object& b) const override { return plain_.strictEquals(a, b); }; - bool instanceOf(const Object &o, const Function &f) override { + bool instanceOf(const Object& o, const Function& f) override { return plain_.instanceOf(o, f); }; @@ -401,39 +401,39 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { plain().instrumentation().startHeapSampling(samplingInterval); } - void stopHeapSampling(std::ostream &os) override { + void stopHeapSampling(std::ostream& os) override { plain().instrumentation().stopHeapSampling(os); } - void createSnapshotToFile(const std::string &path) override { + void createSnapshotToFile(const std::string& path) override { plain().instrumentation().createSnapshotToFile(path); } - void createSnapshotToStream(std::ostream &os) override { + void createSnapshotToStream(std::ostream& os) override { plain().instrumentation().createSnapshotToStream(os); } std::string flushAndDisableBridgeTrafficTrace() override { - return const_cast(plain()) + return const_cast(plain()) .instrumentation() .flushAndDisableBridgeTrafficTrace(); } void writeBasicBlockProfileTraceToFile( - const std::string &fileName) const override { - const_cast(plain()) + const std::string& fileName) const override { + const_cast(plain()) .instrumentation() .writeBasicBlockProfileTraceToFile(fileName); } /// Dump external profiler symbols to the given file name. - void dumpProfilerSymbolsToFile(const std::string &fileName) const override { - const_cast(plain()).instrumentation().dumpProfilerSymbolsToFile( + void dumpProfilerSymbolsToFile(const std::string& fileName) const override { + const_cast(plain()).instrumentation().dumpProfilerSymbolsToFile( fileName); } private: - Plain &plain_; + Plain& plain_; }; namespace detail { @@ -443,12 +443,12 @@ namespace detail { template struct BeforeCaller { - static void before(T &) {} + static void before(T&) {} }; template struct AfterCaller { - static void after(T &) {} + static void after(T&) {} }; // decltype((void)&...) is either SFINAE, or void. @@ -457,14 +457,14 @@ struct AfterCaller { // default above exists, and that is used instead. template struct BeforeCaller { - static void before(T &t) { + static void before(T& t) { t.before(); } }; template struct AfterCaller { - static void after(T &t) { + static void after(T& t) { t.after(); } }; @@ -475,36 +475,36 @@ struct AfterCaller { // example. template struct BeforeCaller> { - static void before(std::tuple &tuple) { + static void before(std::tuple& tuple) { all_before<0, T...>(tuple); } private: template - static void all_before(std::tuple &tuple) { + static void all_before(std::tuple& tuple) { detail::BeforeCaller::before(std::get(tuple)); all_before(tuple); } template - static void all_before(std::tuple &) {} + static void all_before(std::tuple&) {} }; template struct AfterCaller> { - static void after(std::tuple &tuple) { + static void after(std::tuple& tuple) { all_after<0, T...>(tuple); } private: template - static void all_after(std::tuple &tuple) { + static void all_after(std::tuple& tuple) { all_after(tuple); detail::AfterCaller::after(std::get(tuple)); } template - static void all_after(std::tuple &) {} + static void all_after(std::tuple&) {} }; } // namespace detail @@ -521,22 +521,22 @@ class WithRuntimeDecorator : public RuntimeDecorator { // The reference arguments to the ctor are stored, but not used by // the ctor, and there is no ctor, so they can be passed members of // the derived class. - WithRuntimeDecorator(Plain &plain, With &with) : RD(plain), with_(with) {} + WithRuntimeDecorator(Plain& plain, With& with) : RD(plain), with_(with) {} Value evaluateJavaScript( - const std::shared_ptr &buffer, - const std::string &sourceURL) override { + const std::shared_ptr& buffer, + const std::string& sourceURL) override { Around around{with_}; return RD::evaluateJavaScript(buffer, sourceURL); } std::shared_ptr prepareJavaScript( - const std::shared_ptr &buffer, + const std::shared_ptr& buffer, std::string sourceURL) override { Around around{with_}; return RD::prepareJavaScript(buffer, std::move(sourceURL)); } Value evaluatePreparedJavaScript( - const std::shared_ptr &js) override { + const std::shared_ptr& js) override { Around around{with_}; return RD::evaluatePreparedJavaScript(js); } @@ -561,67 +561,67 @@ class WithRuntimeDecorator : public RuntimeDecorator { // Instrumentation is not accessible because RuntimeDecorator uses private // to inherit from Instrumentation. // TODO(T40821815) Consider removing this workaround when updating MSVC - jsi::Instrumentation &instrumentation() override { + jsi::Instrumentation& instrumentation() override { Around around{with_}; return RD::instrumentation(); } protected: - Runtime::PointerValue *cloneSymbol(const Runtime::PointerValue *pv) override { + Runtime::PointerValue* cloneSymbol(const Runtime::PointerValue* pv) override { Around around{with_}; return RD::cloneSymbol(pv); }; - Runtime::PointerValue *cloneString(const Runtime::PointerValue *pv) override { + Runtime::PointerValue* cloneString(const Runtime::PointerValue* pv) override { Around around{with_}; return RD::cloneString(pv); }; - Runtime::PointerValue *cloneObject(const Runtime::PointerValue *pv) override { + Runtime::PointerValue* cloneObject(const Runtime::PointerValue* pv) override { Around around{with_}; return RD::cloneObject(pv); }; - Runtime::PointerValue *clonePropNameID( - const Runtime::PointerValue *pv) override { + Runtime::PointerValue* clonePropNameID( + const Runtime::PointerValue* pv) override { Around around{with_}; return RD::clonePropNameID(pv); }; - PropNameID createPropNameIDFromAscii(const char *str, size_t length) + PropNameID createPropNameIDFromAscii(const char* str, size_t length) override { Around around{with_}; return RD::createPropNameIDFromAscii(str, length); }; - PropNameID createPropNameIDFromUtf8(const uint8_t *utf8, size_t length) + PropNameID createPropNameIDFromUtf8(const uint8_t* utf8, size_t length) override { Around around{with_}; return RD::createPropNameIDFromUtf8(utf8, length); }; - PropNameID createPropNameIDFromString(const String &str) override { + PropNameID createPropNameIDFromString(const String& str) override { Around around{with_}; return RD::createPropNameIDFromString(str); }; - std::string utf8(const PropNameID &id) override { + std::string utf8(const PropNameID& id) override { Around around{with_}; return RD::utf8(id); }; - bool compare(const PropNameID &a, const PropNameID &b) override { + bool compare(const PropNameID& a, const PropNameID& b) override { Around around{with_}; return RD::compare(a, b); }; - std::string symbolToString(const Symbol &sym) override { + std::string symbolToString(const Symbol& sym) override { Around around{with_}; return RD::symbolToString(sym); }; - String createStringFromAscii(const char *str, size_t length) override { + String createStringFromAscii(const char* str, size_t length) override { Around around{with_}; return RD::createStringFromAscii(str, length); }; - String createStringFromUtf8(const uint8_t *utf8, size_t length) override { + String createStringFromUtf8(const uint8_t* utf8, size_t length) override { Around around{with_}; return RD::createStringFromUtf8(utf8, length); }; - std::string utf8(const String &s) override { + std::string utf8(const String& s) override { Around around{with_}; return RD::utf8(s); } @@ -634,74 +634,74 @@ class WithRuntimeDecorator : public RuntimeDecorator { Around around{with_}; return RD::createObject(std::move(ho)); }; - std::shared_ptr getHostObject(const jsi::Object &o) override { + std::shared_ptr getHostObject(const jsi::Object& o) override { Around around{with_}; return RD::getHostObject(o); }; - HostFunctionType &getHostFunction(const jsi::Function &f) override { + HostFunctionType& getHostFunction(const jsi::Function& f) override { Around around{with_}; return RD::getHostFunction(f); }; - Value getProperty(const Object &o, const PropNameID &name) override { + Value getProperty(const Object& o, const PropNameID& name) override { Around around{with_}; return RD::getProperty(o, name); }; - Value getProperty(const Object &o, const String &name) override { + Value getProperty(const Object& o, const String& name) override { Around around{with_}; return RD::getProperty(o, name); }; - bool hasProperty(const Object &o, const PropNameID &name) override { + bool hasProperty(const Object& o, const PropNameID& name) override { Around around{with_}; return RD::hasProperty(o, name); }; - bool hasProperty(const Object &o, const String &name) override { + bool hasProperty(const Object& o, const String& name) override { Around around{with_}; return RD::hasProperty(o, name); }; void setPropertyValue( - const Object &o, - const PropNameID &name, - const Value &value) override { + const Object& o, + const PropNameID& name, + const Value& value) override { Around around{with_}; RD::setPropertyValue(o, name, value); }; - void setPropertyValue(const Object &o, const String &name, const Value &value) + void setPropertyValue(const Object& o, const String& name, const Value& value) override { Around around{with_}; RD::setPropertyValue(o, name, value); }; - bool isArray(const Object &o) const override { + bool isArray(const Object& o) const override { Around around{with_}; return RD::isArray(o); }; - bool isArrayBuffer(const Object &o) const override { + bool isArrayBuffer(const Object& o) const override { Around around{with_}; return RD::isArrayBuffer(o); }; - bool isFunction(const Object &o) const override { + bool isFunction(const Object& o) const override { Around around{with_}; return RD::isFunction(o); }; - bool isHostObject(const jsi::Object &o) const override { + bool isHostObject(const jsi::Object& o) const override { Around around{with_}; return RD::isHostObject(o); }; - bool isHostFunction(const jsi::Function &f) const override { + bool isHostFunction(const jsi::Function& f) const override { Around around{with_}; return RD::isHostFunction(f); }; - Array getPropertyNames(const Object &o) override { + Array getPropertyNames(const Object& o) override { Around around{with_}; return RD::getPropertyNames(o); }; - WeakObject createWeakObject(const Object &o) override { + WeakObject createWeakObject(const Object& o) override { Around around{with_}; return RD::createWeakObject(o); }; - Value lockWeakObject(const WeakObject &wo) override { + Value lockWeakObject(const WeakObject& wo) override { Around around{with_}; return RD::lockWeakObject(wo); }; @@ -714,30 +714,30 @@ class WithRuntimeDecorator : public RuntimeDecorator { std::shared_ptr buffer) override { return RD::createArrayBuffer(std::move(buffer)); }; - size_t size(const Array &a) override { + size_t size(const Array& a) override { Around around{with_}; return RD::size(a); }; - size_t size(const ArrayBuffer &ab) override { + size_t size(const ArrayBuffer& ab) override { Around around{with_}; return RD::size(ab); }; - uint8_t *data(const ArrayBuffer &ab) override { + uint8_t* data(const ArrayBuffer& ab) override { Around around{with_}; return RD::data(ab); }; - Value getValueAtIndex(const Array &a, size_t i) override { + Value getValueAtIndex(const Array& a, size_t i) override { Around around{with_}; return RD::getValueAtIndex(a, i); }; - void setValueAtIndexImpl(const Array &a, size_t i, const Value &value) + void setValueAtIndexImpl(const Array& a, size_t i, const Value& value) override { Around around{with_}; RD::setValueAtIndexImpl(a, i, value); }; Function createFunctionFromHostFunction( - const PropNameID &name, + const PropNameID& name, unsigned int paramCount, HostFunctionType func) override { Around around{with_}; @@ -745,43 +745,43 @@ class WithRuntimeDecorator : public RuntimeDecorator { name, paramCount, std::move(func)); }; Value call( - const Function &f, - const Value &jsThis, - const Value *args, + const Function& f, + const Value& jsThis, + const Value* args, size_t count) override { Around around{with_}; return RD::call(f, jsThis, args, count); }; - Value callAsConstructor(const Function &f, const Value *args, size_t count) + Value callAsConstructor(const Function& f, const Value* args, size_t count) override { Around around{with_}; return RD::callAsConstructor(f, args, count); }; // Private data for managing scopes. - Runtime::ScopeState *pushScope() override { + Runtime::ScopeState* pushScope() override { Around around{with_}; return RD::pushScope(); } - void popScope(Runtime::ScopeState *ss) override { + void popScope(Runtime::ScopeState* ss) override { Around around{with_}; RD::popScope(ss); } - bool strictEquals(const Symbol &a, const Symbol &b) const override { + bool strictEquals(const Symbol& a, const Symbol& b) const override { Around around{with_}; return RD::strictEquals(a, b); }; - bool strictEquals(const String &a, const String &b) const override { + bool strictEquals(const String& a, const String& b) const override { Around around{with_}; return RD::strictEquals(a, b); }; - bool strictEquals(const Object &a, const Object &b) const override { + bool strictEquals(const Object& a, const Object& b) const override { Around around{with_}; return RD::strictEquals(a, b); }; - bool instanceOf(const Object &o, const Function &f) override { + bool instanceOf(const Object& o, const Function& f) override { Around around{with_}; return RD::instanceOf(o, f); }; @@ -789,17 +789,17 @@ class WithRuntimeDecorator : public RuntimeDecorator { private: // Wrap an RAII type around With& to guarantee after always happens. struct Around { - Around(With &with) : with_(with) { + Around(With& with) : with_(with) { detail::BeforeCaller::before(with_); } ~Around() { detail::AfterCaller::after(with_); } - With &with_; + With& with_; }; - With &with_; + With& with_; }; } // namespace jsi diff --git a/ReactCommon/jsi/jsi/instrumentation.h b/ReactCommon/jsi/jsi/instrumentation.h index d7bc50a0a7a598..e841af07df8f1d 100644 --- a/ReactCommon/jsi/jsi/instrumentation.h +++ b/ReactCommon/jsi/jsi/instrumentation.h @@ -87,17 +87,17 @@ class JSI_EXPORT Instrumentation { /// Turns off the heap sampling profiler previously enabled via /// \c startHeapSampling. Writes the output of the sampling heap profiler to /// \p os. The output is a JSON formatted string. - virtual void stopHeapSampling(std::ostream &os) = 0; + virtual void stopHeapSampling(std::ostream& os) = 0; /// Captures the heap to a file /// /// \param path to save the heap capture - virtual void createSnapshotToFile(const std::string &path) = 0; + virtual void createSnapshotToFile(const std::string& path) = 0; /// Captures the heap to an output stream /// /// \param os output stream to write to. - virtual void createSnapshotToStream(std::ostream &os) = 0; + virtual void createSnapshotToStream(std::ostream& os) = 0; /// If the runtime has been created to trace to a temp file, flush /// any unwritten parts of the trace of bridge traffic to the file, @@ -107,10 +107,10 @@ class JSI_EXPORT Instrumentation { /// Write basic block profile trace to the given file name. virtual void writeBasicBlockProfileTraceToFile( - const std::string &fileName) const = 0; + const std::string& fileName) const = 0; /// Dump external profiler symbols to the given file name. - virtual void dumpProfilerSymbolsToFile(const std::string &fileName) const = 0; + virtual void dumpProfilerSymbolsToFile(const std::string& fileName) const = 0; }; } // namespace jsi diff --git a/ReactCommon/jsi/jsi/jsi-inl.h b/ReactCommon/jsi/jsi/jsi-inl.h index 6165500e50a877..4ce00adb883c59 100644 --- a/ReactCommon/jsi/jsi/jsi-inl.h +++ b/ReactCommon/jsi/jsi/jsi-inl.h @@ -11,54 +11,54 @@ namespace facebook { namespace jsi { namespace detail { -inline Value toValue(Runtime &, std::nullptr_t) { +inline Value toValue(Runtime&, std::nullptr_t) { return Value::null(); } -inline Value toValue(Runtime &, bool b) { +inline Value toValue(Runtime&, bool b) { return Value(b); } -inline Value toValue(Runtime &, double d) { +inline Value toValue(Runtime&, double d) { return Value(d); } -inline Value toValue(Runtime &, float f) { +inline Value toValue(Runtime&, float f) { return Value(static_cast(f)); } -inline Value toValue(Runtime &, int i) { +inline Value toValue(Runtime&, int i) { return Value(i); } -inline Value toValue(Runtime &runtime, const char *str) { +inline Value toValue(Runtime& runtime, const char* str) { return String::createFromAscii(runtime, str); } -inline Value toValue(Runtime &runtime, const std::string &str) { +inline Value toValue(Runtime& runtime, const std::string& str) { return String::createFromUtf8(runtime, str); } template -inline Value toValue(Runtime &runtime, const T &other) { +inline Value toValue(Runtime& runtime, const T& other) { static_assert( std::is_base_of::value, "This type cannot be converted to Value"); return Value(runtime, other); } -inline Value toValue(Runtime &runtime, const Value &value) { +inline Value toValue(Runtime& runtime, const Value& value) { return Value(runtime, value); } -inline Value &&toValue(Runtime &, Value &&value) { +inline Value&& toValue(Runtime&, Value&& value) { return std::move(value); } -inline PropNameID toPropNameID(Runtime &runtime, const char *name) { +inline PropNameID toPropNameID(Runtime& runtime, const char* name) { return PropNameID::forAscii(runtime, name); } -inline PropNameID toPropNameID(Runtime &runtime, const std::string &name) { +inline PropNameID toPropNameID(Runtime& runtime, const std::string& name) { return PropNameID::forUtf8(runtime, name); } -inline PropNameID &&toPropNameID(Runtime &, PropNameID &&name) { +inline PropNameID&& toPropNameID(Runtime&, PropNameID&& name) { return std::move(name); } /// Helper to throw while still compiling with exceptions turned off. template -[[noreturn]] inline void throwOrDie(Args &&...args) { +[[noreturn]] inline void throwOrDie(Args&&... args) { std::rethrow_exception( std::make_exception_ptr(E{std::forward(args)...})); } @@ -66,130 +66,130 @@ template } // namespace detail template -inline T Runtime::make(Runtime::PointerValue *pv) { +inline T Runtime::make(Runtime::PointerValue* pv) { return T(pv); } -inline Runtime::PointerValue *Runtime::getPointerValue(jsi::Pointer &pointer) { +inline Runtime::PointerValue* Runtime::getPointerValue(jsi::Pointer& pointer) { return pointer.ptr_; } -inline const Runtime::PointerValue *Runtime::getPointerValue( - const jsi::Pointer &pointer) { +inline const Runtime::PointerValue* Runtime::getPointerValue( + const jsi::Pointer& pointer) { return pointer.ptr_; } -inline const Runtime::PointerValue *Runtime::getPointerValue( - const jsi::Value &value) { +inline const Runtime::PointerValue* Runtime::getPointerValue( + const jsi::Value& value) { return value.data_.pointer.ptr_; } -inline Value Object::getProperty(Runtime &runtime, const char *name) const { +inline Value Object::getProperty(Runtime& runtime, const char* name) const { return getProperty(runtime, String::createFromAscii(runtime, name)); } -inline Value Object::getProperty(Runtime &runtime, const String &name) const { +inline Value Object::getProperty(Runtime& runtime, const String& name) const { return runtime.getProperty(*this, name); } -inline Value Object::getProperty(Runtime &runtime, const PropNameID &name) +inline Value Object::getProperty(Runtime& runtime, const PropNameID& name) const { return runtime.getProperty(*this, name); } -inline bool Object::hasProperty(Runtime &runtime, const char *name) const { +inline bool Object::hasProperty(Runtime& runtime, const char* name) const { return hasProperty(runtime, String::createFromAscii(runtime, name)); } -inline bool Object::hasProperty(Runtime &runtime, const String &name) const { +inline bool Object::hasProperty(Runtime& runtime, const String& name) const { return runtime.hasProperty(*this, name); } -inline bool Object::hasProperty(Runtime &runtime, const PropNameID &name) +inline bool Object::hasProperty(Runtime& runtime, const PropNameID& name) const { return runtime.hasProperty(*this, name); } template -void Object::setProperty(Runtime &runtime, const char *name, T &&value) const { +void Object::setProperty(Runtime& runtime, const char* name, T&& value) const { setProperty( runtime, String::createFromAscii(runtime, name), std::forward(value)); } template -void Object::setProperty(Runtime &runtime, const String &name, T &&value) +void Object::setProperty(Runtime& runtime, const String& name, T&& value) const { setPropertyValue( runtime, name, detail::toValue(runtime, std::forward(value))); } template -void Object::setProperty(Runtime &runtime, const PropNameID &name, T &&value) +void Object::setProperty(Runtime& runtime, const PropNameID& name, T&& value) const { setPropertyValue( runtime, name, detail::toValue(runtime, std::forward(value))); } -inline Array Object::getArray(Runtime &runtime) const & { +inline Array Object::getArray(Runtime& runtime) const& { assert(runtime.isArray(*this)); (void)runtime; // when assert is disabled we need to mark this as used return Array(runtime.cloneObject(ptr_)); } -inline Array Object::getArray(Runtime &runtime) && { +inline Array Object::getArray(Runtime& runtime) && { assert(runtime.isArray(*this)); (void)runtime; // when assert is disabled we need to mark this as used - Runtime::PointerValue *value = ptr_; + Runtime::PointerValue* value = ptr_; ptr_ = nullptr; return Array(value); } -inline ArrayBuffer Object::getArrayBuffer(Runtime &runtime) const & { +inline ArrayBuffer Object::getArrayBuffer(Runtime& runtime) const& { assert(runtime.isArrayBuffer(*this)); (void)runtime; // when assert is disabled we need to mark this as used return ArrayBuffer(runtime.cloneObject(ptr_)); } -inline ArrayBuffer Object::getArrayBuffer(Runtime &runtime) && { +inline ArrayBuffer Object::getArrayBuffer(Runtime& runtime) && { assert(runtime.isArrayBuffer(*this)); (void)runtime; // when assert is disabled we need to mark this as used - Runtime::PointerValue *value = ptr_; + Runtime::PointerValue* value = ptr_; ptr_ = nullptr; return ArrayBuffer(value); } -inline Function Object::getFunction(Runtime &runtime) const & { +inline Function Object::getFunction(Runtime& runtime) const& { assert(runtime.isFunction(*this)); return Function(runtime.cloneObject(ptr_)); } -inline Function Object::getFunction(Runtime &runtime) && { +inline Function Object::getFunction(Runtime& runtime) && { assert(runtime.isFunction(*this)); (void)runtime; // when assert is disabled we need to mark this as used - Runtime::PointerValue *value = ptr_; + Runtime::PointerValue* value = ptr_; ptr_ = nullptr; return Function(value); } template -inline bool Object::isHostObject(Runtime &runtime) const { +inline bool Object::isHostObject(Runtime& runtime) const { return runtime.isHostObject(*this) && std::dynamic_pointer_cast(runtime.getHostObject(*this)); } template <> -inline bool Object::isHostObject(Runtime &runtime) const { +inline bool Object::isHostObject(Runtime& runtime) const { return runtime.isHostObject(*this); } template -inline std::shared_ptr Object::getHostObject(Runtime &runtime) const { +inline std::shared_ptr Object::getHostObject(Runtime& runtime) const { assert(isHostObject(runtime)); return std::static_pointer_cast(runtime.getHostObject(*this)); } template -inline std::shared_ptr Object::asHostObject(Runtime &runtime) const { +inline std::shared_ptr Object::asHostObject(Runtime& runtime) const { if (!isHostObject(runtime)) { detail::throwOrDie( "Object is not a HostObject of desired type"); @@ -199,73 +199,73 @@ inline std::shared_ptr Object::asHostObject(Runtime &runtime) const { template <> inline std::shared_ptr Object::getHostObject( - Runtime &runtime) const { + Runtime& runtime) const { assert(runtime.isHostObject(*this)); return runtime.getHostObject(*this); } template -inline bool Object::hasNativeState(Runtime &runtime) const { +inline bool Object::hasNativeState(Runtime& runtime) const { return runtime.hasNativeState(*this) && std::dynamic_pointer_cast(runtime.getNativeState(*this)); } template <> -inline bool Object::hasNativeState(Runtime &runtime) const { +inline bool Object::hasNativeState(Runtime& runtime) const { return runtime.hasNativeState(*this); } template -inline std::shared_ptr Object::getNativeState(Runtime &runtime) const { +inline std::shared_ptr Object::getNativeState(Runtime& runtime) const { assert(hasNativeState(runtime)); return std::static_pointer_cast(runtime.getNativeState(*this)); } inline void Object::setNativeState( - Runtime &runtime, + Runtime& runtime, std::shared_ptr state) const { runtime.setNativeState(*this, state); } -inline Array Object::getPropertyNames(Runtime &runtime) const { +inline Array Object::getPropertyNames(Runtime& runtime) const { return runtime.getPropertyNames(*this); } -inline Value WeakObject::lock(Runtime &runtime) const { +inline Value WeakObject::lock(Runtime& runtime) const { return runtime.lockWeakObject(*this); } template -void Array::setValueAtIndex(Runtime &runtime, size_t i, T &&value) const { +void Array::setValueAtIndex(Runtime& runtime, size_t i, T&& value) const { setValueAtIndexImpl( runtime, i, detail::toValue(runtime, std::forward(value))); } -inline Value Array::getValueAtIndex(Runtime &runtime, size_t i) const { +inline Value Array::getValueAtIndex(Runtime& runtime, size_t i) const { return runtime.getValueAtIndex(*this, i); } inline Function Function::createFromHostFunction( - Runtime &runtime, - const jsi::PropNameID &name, + Runtime& runtime, + const jsi::PropNameID& name, unsigned int paramCount, jsi::HostFunctionType func) { return runtime.createFunctionFromHostFunction( name, paramCount, std::move(func)); } -inline Value Function::call(Runtime &runtime, const Value *args, size_t count) +inline Value Function::call(Runtime& runtime, const Value* args, size_t count) const { return runtime.call(*this, Value::undefined(), args, count); } -inline Value Function::call(Runtime &runtime, std::initializer_list args) +inline Value Function::call(Runtime& runtime, std::initializer_list args) const { return call(runtime, args.begin(), args.size()); } template -inline Value Function::call(Runtime &runtime, Args &&...args) const { +inline Value Function::call(Runtime& runtime, Args&&... args) const { // A more awesome version of this would be able to create raw values // which can be used directly without wrapping and unwrapping, but // this will do for now. @@ -273,25 +273,25 @@ inline Value Function::call(Runtime &runtime, Args &&...args) const { } inline Value Function::callWithThis( - Runtime &runtime, - const Object &jsThis, - const Value *args, + Runtime& runtime, + const Object& jsThis, + const Value* args, size_t count) const { return runtime.call(*this, Value(runtime, jsThis), args, count); } inline Value Function::callWithThis( - Runtime &runtime, - const Object &jsThis, + Runtime& runtime, + const Object& jsThis, std::initializer_list args) const { return callWithThis(runtime, jsThis, args.begin(), args.size()); } template inline Value Function::callWithThis( - Runtime &runtime, - const Object &jsThis, - Args &&...args) const { + Runtime& runtime, + const Object& jsThis, + Args&&... args) const { // A more awesome version of this would be able to create raw values // which can be used directly without wrapping and unwrapping, but // this will do for now. @@ -300,50 +300,50 @@ inline Value Function::callWithThis( } template -inline Array Array::createWithElements(Runtime &runtime, Args &&...args) { +inline Array Array::createWithElements(Runtime& runtime, Args&&... args) { return createWithElements( runtime, {detail::toValue(runtime, std::forward(args))...}); } template inline std::vector PropNameID::names( - Runtime &runtime, - Args &&...args) { + Runtime& runtime, + Args&&... args) { return names({detail::toPropNameID(runtime, std::forward(args))...}); } template inline std::vector PropNameID::names( - PropNameID (&&propertyNames)[N]) { + PropNameID(&&propertyNames)[N]) { std::vector result; result.reserve(N); - for (auto &name : propertyNames) { + for (auto& name : propertyNames) { result.push_back(std::move(name)); } return result; } inline Value Function::callAsConstructor( - Runtime &runtime, - const Value *args, + Runtime& runtime, + const Value* args, size_t count) const { return runtime.callAsConstructor(*this, args, count); } inline Value Function::callAsConstructor( - Runtime &runtime, + Runtime& runtime, std::initializer_list args) const { return callAsConstructor(runtime, args.begin(), args.size()); } template -inline Value Function::callAsConstructor(Runtime &runtime, Args &&...args) +inline Value Function::callAsConstructor(Runtime& runtime, Args&&... args) const { return callAsConstructor( runtime, {detail::toValue(runtime, std::forward(args))...}); } -String BigInt::toString(Runtime &runtime, int radix) const { +String BigInt::toString(Runtime& runtime, int radix) const { return runtime.bigintToString(*this, radix); } diff --git a/ReactCommon/jsi/jsi/jsi.h b/ReactCommon/jsi/jsi/jsi.h index 1405133adf6ab4..ec7fd7723f5402 100644 --- a/ReactCommon/jsi/jsi/jsi.h +++ b/ReactCommon/jsi/jsi/jsi.h @@ -39,7 +39,7 @@ class JSI_EXPORT Buffer { public: virtual ~Buffer(); virtual size_t size() const = 0; - virtual const uint8_t *data() const = 0; + virtual const uint8_t* data() const = 0; }; class JSI_EXPORT StringBuffer : public Buffer { @@ -48,8 +48,8 @@ class JSI_EXPORT StringBuffer : public Buffer { size_t size() const override { return s_.size(); } - const uint8_t *data() const override { - return reinterpret_cast(s_.data()); + const uint8_t* data() const override { + return reinterpret_cast(s_.data()); } private: @@ -65,7 +65,7 @@ class JSI_EXPORT MutableBuffer { public: virtual ~MutableBuffer(); virtual size_t size() const = 0; - virtual uint8_t *data() = 0; + virtual uint8_t* data() = 0; }; /// PreparedJavaScript is a base class representing JavaScript which is in a @@ -109,7 +109,7 @@ class JSError; /// can be any value - it will not necessarily be coerced to an object or /// or set to the global object. using HostFunctionType = std::function< - Value(Runtime &rt, const Value &thisVal, const Value *args, size_t count)>; + Value(Runtime& rt, const Value& thisVal, const Value* args, size_t count)>; /// An object which implements this interface can be registered as an /// Object with the JS runtime. @@ -130,18 +130,18 @@ class JSI_EXPORT HostObject { // it will call this method. If it throws an exception, the call // will throw a JS \c Error object. By default this returns undefined. // \return the value for the property. - virtual Value get(Runtime &, const PropNameID &name); + virtual Value get(Runtime&, const PropNameID& name); // When JS wants to set a property with a given name on the HostObject, // it will call this method. If it throws an exception, the call will // throw a JS \c Error object. By default this throws a type error exception // mimicking the behavior of a frozen object in strict mode. - virtual void set(Runtime &, const PropNameID &name, const Value &value); + virtual void set(Runtime&, const PropNameID& name, const Value& value); // When JS wants a list of property names for the HostObject, it will // call this method. If it throws an exception, the call will throw a // JS \c Error object. The default implementation returns empty vector. - virtual std::vector getPropertyNames(Runtime &rt); + virtual std::vector getPropertyNames(Runtime& rt); }; /// Native state (and destructor) that can be attached to any JS object @@ -184,8 +184,8 @@ class JSI_EXPORT Runtime { /// call a global function than using the JSI APIs to read the function /// property from the global object and then calling it explicitly. virtual Value evaluateJavaScript( - const std::shared_ptr &buffer, - const std::string &sourceURL) = 0; + const std::shared_ptr& buffer, + const std::string& sourceURL) = 0; /// Prepares to evaluate the given JavaScript \c buffer by processing it into /// a form optimized for execution. This may include pre-parsing, compiling, @@ -199,7 +199,7 @@ class JSI_EXPORT Runtime { /// As with evaluateJavaScript(), using JavaScript code should be avoided /// when the JSI API is sufficient. virtual std::shared_ptr prepareJavaScript( - const std::shared_ptr &buffer, + const std::shared_ptr& buffer, std::string sourceURL) = 0; /// Evaluates a PreparedJavaScript. If evaluation causes an error, a @@ -207,7 +207,7 @@ class JSI_EXPORT Runtime { /// As with evaluateJavaScript(), using JavaScript code should be avoided /// when the JSI API is sufficient. virtual Value evaluatePreparedJavaScript( - const std::shared_ptr &js) = 0; + const std::shared_ptr& js) = 0; /// Drain the JavaScript VM internal Microtask (a.k.a. Job in ECMA262) queue. /// @@ -258,7 +258,7 @@ class JSI_EXPORT Runtime { /// \return an interface to extract metrics from this \c Runtime. The default /// implementation of this function returns an \c Instrumentation instance /// which returns no metrics. - virtual Instrumentation &instrumentation(); + virtual Instrumentation& instrumentation(); protected: friend class Pointer; @@ -287,113 +287,113 @@ class JSI_EXPORT Runtime { virtual ~PointerValue() = default; }; - virtual PointerValue *cloneSymbol(const Runtime::PointerValue *pv) = 0; - virtual PointerValue *cloneBigInt(const Runtime::PointerValue *pv) = 0; - virtual PointerValue *cloneString(const Runtime::PointerValue *pv) = 0; - virtual PointerValue *cloneObject(const Runtime::PointerValue *pv) = 0; - virtual PointerValue *clonePropNameID(const Runtime::PointerValue *pv) = 0; + virtual PointerValue* cloneSymbol(const Runtime::PointerValue* pv) = 0; + virtual PointerValue* cloneBigInt(const Runtime::PointerValue* pv) = 0; + virtual PointerValue* cloneString(const Runtime::PointerValue* pv) = 0; + virtual PointerValue* cloneObject(const Runtime::PointerValue* pv) = 0; + virtual PointerValue* clonePropNameID(const Runtime::PointerValue* pv) = 0; virtual PropNameID createPropNameIDFromAscii( - const char *str, + const char* str, size_t length) = 0; virtual PropNameID createPropNameIDFromUtf8( - const uint8_t *utf8, + const uint8_t* utf8, size_t length) = 0; - virtual PropNameID createPropNameIDFromString(const String &str) = 0; - virtual PropNameID createPropNameIDFromSymbol(const Symbol &sym) = 0; - virtual std::string utf8(const PropNameID &) = 0; - virtual bool compare(const PropNameID &, const PropNameID &) = 0; + virtual PropNameID createPropNameIDFromString(const String& str) = 0; + virtual PropNameID createPropNameIDFromSymbol(const Symbol& sym) = 0; + virtual std::string utf8(const PropNameID&) = 0; + virtual bool compare(const PropNameID&, const PropNameID&) = 0; - virtual std::string symbolToString(const Symbol &) = 0; + virtual std::string symbolToString(const Symbol&) = 0; virtual BigInt createBigIntFromInt64(int64_t) = 0; virtual BigInt createBigIntFromUint64(uint64_t) = 0; - virtual bool bigintIsInt64(const BigInt &) = 0; - virtual bool bigintIsUint64(const BigInt &) = 0; - virtual uint64_t truncate(const BigInt &) = 0; - virtual String bigintToString(const BigInt &, int) = 0; + virtual bool bigintIsInt64(const BigInt&) = 0; + virtual bool bigintIsUint64(const BigInt&) = 0; + virtual uint64_t truncate(const BigInt&) = 0; + virtual String bigintToString(const BigInt&, int) = 0; - virtual String createStringFromAscii(const char *str, size_t length) = 0; - virtual String createStringFromUtf8(const uint8_t *utf8, size_t length) = 0; - virtual std::string utf8(const String &) = 0; + virtual String createStringFromAscii(const char* str, size_t length) = 0; + virtual String createStringFromUtf8(const uint8_t* utf8, size_t length) = 0; + virtual std::string utf8(const String&) = 0; // \return a \c Value created from a utf8-encoded JSON string. The default // implementation creates a \c String and invokes JSON.parse. - virtual Value createValueFromJsonUtf8(const uint8_t *json, size_t length); + virtual Value createValueFromJsonUtf8(const uint8_t* json, size_t length); virtual Object createObject() = 0; virtual Object createObject(std::shared_ptr ho) = 0; - virtual std::shared_ptr getHostObject(const jsi::Object &) = 0; - virtual HostFunctionType &getHostFunction(const jsi::Function &) = 0; + virtual std::shared_ptr getHostObject(const jsi::Object&) = 0; + virtual HostFunctionType& getHostFunction(const jsi::Function&) = 0; - virtual bool hasNativeState(const jsi::Object &) = 0; - virtual std::shared_ptr getNativeState(const jsi::Object &) = 0; + virtual bool hasNativeState(const jsi::Object&) = 0; + virtual std::shared_ptr getNativeState(const jsi::Object&) = 0; virtual void setNativeState( - const jsi::Object &, + const jsi::Object&, std::shared_ptr state) = 0; - virtual Value getProperty(const Object &, const PropNameID &name) = 0; - virtual Value getProperty(const Object &, const String &name) = 0; - virtual bool hasProperty(const Object &, const PropNameID &name) = 0; - virtual bool hasProperty(const Object &, const String &name) = 0; + virtual Value getProperty(const Object&, const PropNameID& name) = 0; + virtual Value getProperty(const Object&, const String& name) = 0; + virtual bool hasProperty(const Object&, const PropNameID& name) = 0; + virtual bool hasProperty(const Object&, const String& name) = 0; virtual void setPropertyValue( - const Object &, - const PropNameID &name, - const Value &value) = 0; + const Object&, + const PropNameID& name, + const Value& value) = 0; virtual void - setPropertyValue(const Object &, const String &name, const Value &value) = 0; + setPropertyValue(const Object&, const String& name, const Value& value) = 0; - virtual bool isArray(const Object &) const = 0; - virtual bool isArrayBuffer(const Object &) const = 0; - virtual bool isFunction(const Object &) const = 0; - virtual bool isHostObject(const jsi::Object &) const = 0; - virtual bool isHostFunction(const jsi::Function &) const = 0; - virtual Array getPropertyNames(const Object &) = 0; + virtual bool isArray(const Object&) const = 0; + virtual bool isArrayBuffer(const Object&) const = 0; + virtual bool isFunction(const Object&) const = 0; + virtual bool isHostObject(const jsi::Object&) const = 0; + virtual bool isHostFunction(const jsi::Function&) const = 0; + virtual Array getPropertyNames(const Object&) = 0; - virtual WeakObject createWeakObject(const Object &) = 0; - virtual Value lockWeakObject(const WeakObject &) = 0; + virtual WeakObject createWeakObject(const Object&) = 0; + virtual Value lockWeakObject(const WeakObject&) = 0; virtual Array createArray(size_t length) = 0; virtual ArrayBuffer createArrayBuffer( std::shared_ptr buffer) = 0; - virtual size_t size(const Array &) = 0; - virtual size_t size(const ArrayBuffer &) = 0; - virtual uint8_t *data(const ArrayBuffer &) = 0; - virtual Value getValueAtIndex(const Array &, size_t i) = 0; + virtual size_t size(const Array&) = 0; + virtual size_t size(const ArrayBuffer&) = 0; + virtual uint8_t* data(const ArrayBuffer&) = 0; + virtual Value getValueAtIndex(const Array&, size_t i) = 0; virtual void - setValueAtIndexImpl(const Array &, size_t i, const Value &value) = 0; + setValueAtIndexImpl(const Array&, size_t i, const Value& value) = 0; virtual Function createFunctionFromHostFunction( - const PropNameID &name, + const PropNameID& name, unsigned int paramCount, HostFunctionType func) = 0; virtual Value call( - const Function &, - const Value &jsThis, - const Value *args, + const Function&, + const Value& jsThis, + const Value* args, size_t count) = 0; virtual Value - callAsConstructor(const Function &, const Value *args, size_t count) = 0; + callAsConstructor(const Function&, const Value* args, size_t count) = 0; // Private data for managing scopes. struct ScopeState; - virtual ScopeState *pushScope(); - virtual void popScope(ScopeState *); + virtual ScopeState* pushScope(); + virtual void popScope(ScopeState*); - virtual bool strictEquals(const Symbol &a, const Symbol &b) const = 0; - virtual bool strictEquals(const BigInt &a, const BigInt &b) const = 0; - virtual bool strictEquals(const String &a, const String &b) const = 0; - virtual bool strictEquals(const Object &a, const Object &b) const = 0; + virtual bool strictEquals(const Symbol& a, const Symbol& b) const = 0; + virtual bool strictEquals(const BigInt& a, const BigInt& b) const = 0; + virtual bool strictEquals(const String& a, const String& b) const = 0; + virtual bool strictEquals(const Object& a, const Object& b) const = 0; - virtual bool instanceOf(const Object &o, const Function &f) = 0; + virtual bool instanceOf(const Object& o, const Function& f) = 0; // These exist so derived classes can access the private parts of // Value, Symbol, String, and Object, which are all friends of Runtime. template - static T make(PointerValue *pv); - static PointerValue *getPointerValue(Pointer &pointer); - static const PointerValue *getPointerValue(const Pointer &pointer); - static const PointerValue *getPointerValue(const Value &value); + static T make(PointerValue* pv); + static PointerValue* getPointerValue(Pointer& pointer); + static const PointerValue* getPointerValue(const Pointer& pointer); + static const PointerValue* getPointerValue(const Value& value); friend class ::FBJSRuntime; template @@ -403,7 +403,7 @@ class JSI_EXPORT Runtime { // Base class for pointer-storing types. class JSI_EXPORT Pointer { protected: - explicit Pointer(Pointer &&other) : ptr_(other.ptr_) { + explicit Pointer(Pointer&& other) : ptr_(other.ptr_) { other.ptr_ = nullptr; } @@ -413,14 +413,14 @@ class JSI_EXPORT Pointer { } } - Pointer &operator=(Pointer &&other); + Pointer& operator=(Pointer&& other); friend class Runtime; friend class Value; - explicit Pointer(Runtime::PointerValue *ptr) : ptr_(ptr) {} + explicit Pointer(Runtime::PointerValue* ptr) : ptr_(ptr) {} - typename Runtime::PointerValue *ptr_; + typename Runtime::PointerValue* ptr_; }; /// Represents something that can be a JS property key. Movable, not copyable. @@ -428,71 +428,71 @@ class JSI_EXPORT PropNameID : public Pointer { public: using Pointer::Pointer; - PropNameID(Runtime &runtime, const PropNameID &other) + PropNameID(Runtime& runtime, const PropNameID& other) : Pointer(runtime.clonePropNameID(other.ptr_)) {} - PropNameID(PropNameID &&other) = default; - PropNameID &operator=(PropNameID &&other) = default; + PropNameID(PropNameID&& other) = default; + PropNameID& operator=(PropNameID&& other) = default; /// Create a JS property name id from ascii values. The data is /// copied. - static PropNameID forAscii(Runtime &runtime, const char *str, size_t length) { + static PropNameID forAscii(Runtime& runtime, const char* str, size_t length) { return runtime.createPropNameIDFromAscii(str, length); } /// Create a property name id from a nul-terminated C ascii name. The data is /// copied. - static PropNameID forAscii(Runtime &runtime, const char *str) { + static PropNameID forAscii(Runtime& runtime, const char* str) { return forAscii(runtime, str, strlen(str)); } /// Create a PropNameID from a C++ string. The string is copied. - static PropNameID forAscii(Runtime &runtime, const std::string &str) { + static PropNameID forAscii(Runtime& runtime, const std::string& str) { return forAscii(runtime, str.c_str(), str.size()); } /// Create a PropNameID from utf8 values. The data is copied. /// Results are undefined if \p utf8 contains invalid code points. static PropNameID - forUtf8(Runtime &runtime, const uint8_t *utf8, size_t length) { + forUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) { return runtime.createPropNameIDFromUtf8(utf8, length); } /// Create a PropNameID from utf8-encoded octets stored in a /// std::string. The string data is transformed and copied. /// Results are undefined if \p utf8 contains invalid code points. - static PropNameID forUtf8(Runtime &runtime, const std::string &utf8) { + static PropNameID forUtf8(Runtime& runtime, const std::string& utf8) { return runtime.createPropNameIDFromUtf8( - reinterpret_cast(utf8.data()), utf8.size()); + reinterpret_cast(utf8.data()), utf8.size()); } /// Create a PropNameID from a JS string. - static PropNameID forString(Runtime &runtime, const jsi::String &str) { + static PropNameID forString(Runtime& runtime, const jsi::String& str) { return runtime.createPropNameIDFromString(str); } /// Create a PropNameID from a JS symbol. - static PropNameID forSymbol(Runtime &runtime, const jsi::Symbol &sym) { + static PropNameID forSymbol(Runtime& runtime, const jsi::Symbol& sym) { return runtime.createPropNameIDFromSymbol(sym); } // Creates a vector of PropNameIDs constructed from given arguments. template - static std::vector names(Runtime &runtime, Args &&...args); + static std::vector names(Runtime& runtime, Args&&... args); // Creates a vector of given PropNameIDs. template - static std::vector names(PropNameID (&&propertyNames)[N]); + static std::vector names(PropNameID(&&propertyNames)[N]); /// Copies the data in a PropNameID as utf8 into a C++ string. - std::string utf8(Runtime &runtime) const { + std::string utf8(Runtime& runtime) const { return runtime.utf8(*this); } static bool compare( - Runtime &runtime, - const jsi::PropNameID &a, - const jsi::PropNameID &b) { + Runtime& runtime, + const jsi::PropNameID& a, + const jsi::PropNameID& b) { return runtime.compare(a, b); } @@ -509,17 +509,17 @@ class JSI_EXPORT Symbol : public Pointer { public: using Pointer::Pointer; - Symbol(Symbol &&other) = default; - Symbol &operator=(Symbol &&other) = default; + Symbol(Symbol&& other) = default; + Symbol& operator=(Symbol&& other) = default; /// \return whether a and b refer to the same symbol. - static bool strictEquals(Runtime &runtime, const Symbol &a, const Symbol &b) { + static bool strictEquals(Runtime& runtime, const Symbol& a, const Symbol& b) { return runtime.strictEquals(a, b); } /// Converts a Symbol into a C++ string as JS .toString would. The output /// will look like \c Symbol(description) . - std::string toString(Runtime &runtime) const { + std::string toString(Runtime& runtime) const { return runtime.symbolToString(*this); } @@ -532,55 +532,55 @@ class JSI_EXPORT BigInt : public Pointer { public: using Pointer::Pointer; - BigInt(BigInt &&other) = default; - BigInt &operator=(BigInt &&other) = default; + BigInt(BigInt&& other) = default; + BigInt& operator=(BigInt&& other) = default; /// Create a BigInt representing the signed 64-bit \p value. - static BigInt fromInt64(Runtime &runtime, int64_t value) { + static BigInt fromInt64(Runtime& runtime, int64_t value) { return runtime.createBigIntFromInt64(value); } /// Create a BigInt representing the unsigned 64-bit \p value. - static BigInt fromUint64(Runtime &runtime, uint64_t value) { + static BigInt fromUint64(Runtime& runtime, uint64_t value) { return runtime.createBigIntFromUint64(value); } /// \return whether a === b. - static bool strictEquals(Runtime &runtime, const BigInt &a, const BigInt &b) { + static bool strictEquals(Runtime& runtime, const BigInt& a, const BigInt& b) { return runtime.strictEquals(a, b); } /// \returns This bigint truncated to a signed 64-bit integer. - int64_t getInt64(Runtime &runtime) const { + int64_t getInt64(Runtime& runtime) const { return runtime.truncate(*this); } /// \returns Whether this bigint can be losslessly converted to int64_t. - bool isInt64(Runtime &runtime) const { + bool isInt64(Runtime& runtime) const { return runtime.bigintIsInt64(*this); } /// \returns This bigint truncated to a signed 64-bit integer. Throws a /// JSIException if the truncation is lossy. - int64_t asInt64(Runtime &runtime) const; + int64_t asInt64(Runtime& runtime) const; /// \returns This bigint truncated to an unsigned 64-bit integer. - uint64_t getUint64(Runtime &runtime) const { + uint64_t getUint64(Runtime& runtime) const { return runtime.truncate(*this); } /// \returns Whether this bigint can be losslessly converted to uint64_t. - bool isUint64(Runtime &runtime) const { + bool isUint64(Runtime& runtime) const { return runtime.bigintIsUint64(*this); } /// \returns This bigint truncated to an unsigned 64-bit integer. Throws a /// JSIException if the truncation is lossy. - uint64_t asUint64(Runtime &runtime) const; + uint64_t asUint64(Runtime& runtime) const; /// \returns this BigInt converted to a String in base \p radix. Throws a /// JSIException if radix is not in the [2, 36] range. - inline String toString(Runtime &runtime, int radix = 10) const; + inline String toString(Runtime& runtime, int radix = 10) const; friend class Runtime; friend class Value; @@ -591,25 +591,25 @@ class JSI_EXPORT String : public Pointer { public: using Pointer::Pointer; - String(String &&other) = default; - String &operator=(String &&other) = default; + String(String&& other) = default; + String& operator=(String&& other) = default; /// Create a JS string from ascii values. The string data is /// copied. static String - createFromAscii(Runtime &runtime, const char *str, size_t length) { + createFromAscii(Runtime& runtime, const char* str, size_t length) { return runtime.createStringFromAscii(str, length); } /// Create a JS string from a nul-terminated C ascii string. The /// string data is copied. - static String createFromAscii(Runtime &runtime, const char *str) { + static String createFromAscii(Runtime& runtime, const char* str) { return createFromAscii(runtime, str, strlen(str)); } /// Create a JS string from a C++ string. The string data is /// copied. - static String createFromAscii(Runtime &runtime, const std::string &str) { + static String createFromAscii(Runtime& runtime, const std::string& str) { return createFromAscii(runtime, str.c_str(), str.size()); } @@ -617,25 +617,25 @@ class JSI_EXPORT String : public Pointer { /// transformed and copied. Results are undefined if \p utf8 contains invalid /// code points. static String - createFromUtf8(Runtime &runtime, const uint8_t *utf8, size_t length) { + createFromUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) { return runtime.createStringFromUtf8(utf8, length); } /// Create a JS string from utf8-encoded octets stored in a /// std::string. The string data is transformed and copied. Results are /// undefined if \p utf8 contains invalid code points. - static String createFromUtf8(Runtime &runtime, const std::string &utf8) { + static String createFromUtf8(Runtime& runtime, const std::string& utf8) { return runtime.createStringFromUtf8( - reinterpret_cast(utf8.data()), utf8.length()); + reinterpret_cast(utf8.data()), utf8.length()); } /// \return whether a and b contain the same characters. - static bool strictEquals(Runtime &runtime, const String &a, const String &b) { + static bool strictEquals(Runtime& runtime, const String& a, const String& b) { return runtime.strictEquals(a, b); } /// Copies the data in a JS string as utf8 into a C++ string. - std::string utf8(Runtime &runtime) const { + std::string utf8(Runtime& runtime) const { return runtime.utf8(*this); } @@ -651,88 +651,88 @@ class JSI_EXPORT Object : public Pointer { public: using Pointer::Pointer; - Object(Object &&other) = default; - Object &operator=(Object &&other) = default; + Object(Object&& other) = default; + Object& operator=(Object&& other) = default; /// Creates a new Object instance, like '{}' in JS. - Object(Runtime &runtime) : Object(runtime.createObject()) {} + Object(Runtime& runtime) : Object(runtime.createObject()) {} static Object createFromHostObject( - Runtime &runtime, + Runtime& runtime, std::shared_ptr ho) { return runtime.createObject(ho); } /// \return whether this and \c obj are the same JSObject or not. - static bool strictEquals(Runtime &runtime, const Object &a, const Object &b) { + static bool strictEquals(Runtime& runtime, const Object& a, const Object& b) { return runtime.strictEquals(a, b); } /// \return the result of `this instanceOf ctor` in JS. - bool instanceOf(Runtime &rt, const Function &ctor) const { + bool instanceOf(Runtime& rt, const Function& ctor) const { return rt.instanceOf(*this, ctor); } /// \return the property of the object with the given ascii name. /// If the name isn't a property on the object, returns the /// undefined value. - Value getProperty(Runtime &runtime, const char *name) const; + Value getProperty(Runtime& runtime, const char* name) const; /// \return the property of the object with the String name. /// If the name isn't a property on the object, returns the /// undefined value. - Value getProperty(Runtime &runtime, const String &name) const; + Value getProperty(Runtime& runtime, const String& name) const; /// \return the property of the object with the given JS PropNameID /// name. If the name isn't a property on the object, returns the /// undefined value. - Value getProperty(Runtime &runtime, const PropNameID &name) const; + Value getProperty(Runtime& runtime, const PropNameID& name) const; /// \return true if and only if the object has a property with the /// given ascii name. - bool hasProperty(Runtime &runtime, const char *name) const; + bool hasProperty(Runtime& runtime, const char* name) const; /// \return true if and only if the object has a property with the /// given String name. - bool hasProperty(Runtime &runtime, const String &name) const; + bool hasProperty(Runtime& runtime, const String& name) const; /// \return true if and only if the object has a property with the /// given PropNameID name. - bool hasProperty(Runtime &runtime, const PropNameID &name) const; + bool hasProperty(Runtime& runtime, const PropNameID& name) const; /// Sets the property value from a Value or anything which can be /// used to make one: nullptr_t, bool, double, int, const char*, /// String, or Object. template - void setProperty(Runtime &runtime, const char *name, T &&value) const; + void setProperty(Runtime& runtime, const char* name, T&& value) const; /// Sets the property value from a Value or anything which can be /// used to make one: nullptr_t, bool, double, int, const char*, /// String, or Object. template - void setProperty(Runtime &runtime, const String &name, T &&value) const; + void setProperty(Runtime& runtime, const String& name, T&& value) const; /// Sets the property value from a Value or anything which can be /// used to make one: nullptr_t, bool, double, int, const char*, /// String, or Object. template - void setProperty(Runtime &runtime, const PropNameID &name, T &&value) const; + void setProperty(Runtime& runtime, const PropNameID& name, T&& value) const; /// \return true iff JS \c Array.isArray() would return \c true. If /// so, then \c getArray() will succeed. - bool isArray(Runtime &runtime) const { + bool isArray(Runtime& runtime) const { return runtime.isArray(*this); } /// \return true iff the Object is an ArrayBuffer. If so, then \c /// getArrayBuffer() will succeed. - bool isArrayBuffer(Runtime &runtime) const { + bool isArrayBuffer(Runtime& runtime) const { return runtime.isArrayBuffer(*this); } /// \return true iff the Object is callable. If so, then \c /// getFunction will succeed. - bool isFunction(Runtime &runtime) const { + bool isFunction(Runtime& runtime) const { return runtime.isFunction(*this); } @@ -740,112 +740,112 @@ class JSI_EXPORT Object : public Pointer { /// and the HostObject passed is of type \c T. If returns \c true then /// \c getHostObject will succeed. template - bool isHostObject(Runtime &runtime) const; + bool isHostObject(Runtime& runtime) const; /// \return an Array instance which refers to the same underlying /// object. If \c isArray() would return false, this will assert. - Array getArray(Runtime &runtime) const &; + Array getArray(Runtime& runtime) const&; /// \return an Array instance which refers to the same underlying /// object. If \c isArray() would return false, this will assert. - Array getArray(Runtime &runtime) &&; + Array getArray(Runtime& runtime) &&; /// \return an Array instance which refers to the same underlying /// object. If \c isArray() would return false, this will throw /// JSIException. - Array asArray(Runtime &runtime) const &; + Array asArray(Runtime& runtime) const&; /// \return an Array instance which refers to the same underlying /// object. If \c isArray() would return false, this will throw /// JSIException. - Array asArray(Runtime &runtime) &&; + Array asArray(Runtime& runtime) &&; /// \return an ArrayBuffer instance which refers to the same underlying /// object. If \c isArrayBuffer() would return false, this will assert. - ArrayBuffer getArrayBuffer(Runtime &runtime) const &; + ArrayBuffer getArrayBuffer(Runtime& runtime) const&; /// \return an ArrayBuffer instance which refers to the same underlying /// object. If \c isArrayBuffer() would return false, this will assert. - ArrayBuffer getArrayBuffer(Runtime &runtime) &&; + ArrayBuffer getArrayBuffer(Runtime& runtime) &&; /// \return a Function instance which refers to the same underlying /// object. If \c isFunction() would return false, this will assert. - Function getFunction(Runtime &runtime) const &; + Function getFunction(Runtime& runtime) const&; /// \return a Function instance which refers to the same underlying /// object. If \c isFunction() would return false, this will assert. - Function getFunction(Runtime &runtime) &&; + Function getFunction(Runtime& runtime) &&; /// \return a Function instance which refers to the same underlying /// object. If \c isFunction() would return false, this will throw /// JSIException. - Function asFunction(Runtime &runtime) const &; + Function asFunction(Runtime& runtime) const&; /// \return a Function instance which refers to the same underlying /// object. If \c isFunction() would return false, this will throw /// JSIException. - Function asFunction(Runtime &runtime) &&; + Function asFunction(Runtime& runtime) &&; /// \return a shared_ptr which refers to the same underlying /// \c HostObject that was used to create this object. If \c isHostObject /// is false, this will assert. Note that this does a type check and will /// assert if the underlying HostObject isn't of type \c T template - std::shared_ptr getHostObject(Runtime &runtime) const; + std::shared_ptr getHostObject(Runtime& runtime) const; /// \return a shared_ptr which refers to the same underlying /// \c HostObject that was used to create this object. If \c isHostObject /// is false, this will throw. template - std::shared_ptr asHostObject(Runtime &runtime) const; + std::shared_ptr asHostObject(Runtime& runtime) const; /// \return whether this object has native state of type T previously set by /// \c setNativeState. template - bool hasNativeState(Runtime &runtime) const; + bool hasNativeState(Runtime& runtime) const; /// \return a shared_ptr to the state previously set by \c setNativeState. /// If \c hasNativeState is false, this will assert. Note that this does a /// type check and will assert if the native state isn't of type \c T template - std::shared_ptr getNativeState(Runtime &runtime) const; + std::shared_ptr getNativeState(Runtime& runtime) const; /// Set the internal native state property of this object, overwriting any old /// value. Creates a new shared_ptr to the object managed by \p state, which /// will live until the value at this property becomes unreachable. /// /// Throws a type error if this object is a proxy or host object. - void setNativeState(Runtime &runtime, std::shared_ptr state) + void setNativeState(Runtime& runtime, std::shared_ptr state) const; /// \return same as \c getProperty(name).asObject(), except with /// a better exception message. - Object getPropertyAsObject(Runtime &runtime, const char *name) const; + Object getPropertyAsObject(Runtime& runtime, const char* name) const; /// \return similar to \c /// getProperty(name).getObject().getFunction(), except it will /// throw JSIException instead of asserting if the property is /// not an object, or the object is not callable. - Function getPropertyAsFunction(Runtime &runtime, const char *name) const; + Function getPropertyAsFunction(Runtime& runtime, const char* name) const; /// \return an Array consisting of all enumerable property names in /// the object and its prototype chain. All values in the return /// will be isString(). (This is probably not optimal, but it /// works. I only need it in one place.) - Array getPropertyNames(Runtime &runtime) const; + Array getPropertyNames(Runtime& runtime) const; protected: void setPropertyValue( - Runtime &runtime, - const String &name, - const Value &value) const { + Runtime& runtime, + const String& name, + const Value& value) const { return runtime.setPropertyValue(*this, name, value); } void setPropertyValue( - Runtime &runtime, - const PropNameID &name, - const Value &value) const { + Runtime& runtime, + const PropNameID& name, + const Value& value) const { return runtime.setPropertyValue(*this, name, value); } @@ -860,18 +860,18 @@ class JSI_EXPORT WeakObject : public Pointer { public: using Pointer::Pointer; - WeakObject(WeakObject &&other) = default; - WeakObject &operator=(WeakObject &&other) = default; + WeakObject(WeakObject&& other) = default; + WeakObject& operator=(WeakObject&& other) = default; /// Create a WeakObject from an Object. - WeakObject(Runtime &runtime, const Object &o) + WeakObject(Runtime& runtime, const Object& o) : WeakObject(runtime.createWeakObject(o)) {} /// \return a Value representing the underlying Object if it is still valid; /// otherwise returns \c undefined. Note that this method has nothing to do /// with threads or concurrency. The name is based on std::weak_ptr::lock() /// which serves a similar purpose. - Value lock(Runtime &runtime) const; + Value lock(Runtime& runtime) const; friend class Runtime; }; @@ -880,79 +880,79 @@ class JSI_EXPORT WeakObject : public Pointer { /// with integral indices. class JSI_EXPORT Array : public Object { public: - Array(Array &&) = default; + Array(Array&&) = default; /// Creates a new Array instance, with \c length undefined elements. - Array(Runtime &runtime, size_t length) : Array(runtime.createArray(length)) {} + Array(Runtime& runtime, size_t length) : Array(runtime.createArray(length)) {} - Array &operator=(Array &&) = default; + Array& operator=(Array&&) = default; /// \return the size of the Array, according to its length property. /// (C++ naming convention) - size_t size(Runtime &runtime) const { + size_t size(Runtime& runtime) const { return runtime.size(*this); } /// \return the size of the Array, according to its length property. /// (JS naming convention) - size_t length(Runtime &runtime) const { + size_t length(Runtime& runtime) const { return size(runtime); } /// \return the property of the array at index \c i. If there is no /// such property, returns the undefined value. If \c i is out of /// range [ 0..\c length ] throws a JSIException. - Value getValueAtIndex(Runtime &runtime, size_t i) const; + Value getValueAtIndex(Runtime& runtime, size_t i) const; /// Sets the property of the array at index \c i. The argument /// value behaves as with Object::setProperty(). If \c i is out of /// range [ 0..\c length ] throws a JSIException. template - void setValueAtIndex(Runtime &runtime, size_t i, T &&value) const; + void setValueAtIndex(Runtime& runtime, size_t i, T&& value) const; /// There is no current API for changing the size of an array once /// created. We'll probably need that eventually. /// Creates a new Array instance from provided values template - static Array createWithElements(Runtime &, Args &&...args); + static Array createWithElements(Runtime&, Args&&... args); /// Creates a new Array instance from initializer list. static Array createWithElements( - Runtime &runtime, + Runtime& runtime, std::initializer_list elements); private: friend class Object; friend class Value; - void setValueAtIndexImpl(Runtime &runtime, size_t i, const Value &value) + void setValueAtIndexImpl(Runtime& runtime, size_t i, const Value& value) const { return runtime.setValueAtIndexImpl(*this, i, value); } - Array(Runtime::PointerValue *value) : Object(value) {} + Array(Runtime::PointerValue* value) : Object(value) {} }; /// Represents a JSArrayBuffer class JSI_EXPORT ArrayBuffer : public Object { public: - ArrayBuffer(ArrayBuffer &&) = default; - ArrayBuffer &operator=(ArrayBuffer &&) = default; + ArrayBuffer(ArrayBuffer&&) = default; + ArrayBuffer& operator=(ArrayBuffer&&) = default; - ArrayBuffer(Runtime &runtime, std::shared_ptr buffer) + ArrayBuffer(Runtime& runtime, std::shared_ptr buffer) : ArrayBuffer(runtime.createArrayBuffer(std::move(buffer))) {} /// \return the size of the ArrayBuffer, according to its byteLength property. /// (C++ naming convention) - size_t size(Runtime &runtime) const { + size_t size(Runtime& runtime) const { return runtime.size(*this); } - size_t length(Runtime &runtime) const { + size_t length(Runtime& runtime) const { return runtime.size(*this); } - uint8_t *data(Runtime &runtime) const { + uint8_t* data(Runtime& runtime) const { return runtime.data(*this); } @@ -960,14 +960,14 @@ class JSI_EXPORT ArrayBuffer : public Object { friend class Object; friend class Value; - ArrayBuffer(Runtime::PointerValue *value) : Object(value) {} + ArrayBuffer(Runtime::PointerValue* value) : Object(value) {} }; /// Represents a JS Object which is guaranteed to be Callable. class JSI_EXPORT Function : public Object { public: - Function(Function &&) = default; - Function &operator=(Function &&) = default; + Function(Function&&) = default; + Function& operator=(Function&&) = default; /// Create a function which, when invoked, calls C++ code. If the /// function throws an exception, a JS Error will be created and @@ -976,8 +976,8 @@ class JSI_EXPORT Function : public Object { /// \param paramCount the length property for the function, which /// may not be the number of arguments the function is passed. static Function createFromHostFunction( - Runtime &runtime, - const jsi::PropNameID &name, + Runtime& runtime, + const jsi::PropNameID& name, unsigned int paramCount, jsi::HostFunctionType func); @@ -987,7 +987,7 @@ class JSI_EXPORT Function : public Object { /// \b Note: as with Function.prototype.apply, \c this may not always be /// \c undefined in the function itself. If the function is non-strict, /// \c this will be set to the global object. - Value call(Runtime &runtime, const Value *args, size_t count) const; + Value call(Runtime& runtime, const Value* args, size_t count) const; /// Calls the function with a \c std::initializer_list of Value /// arguments. The \c this value of the JS function will not be set by the @@ -996,7 +996,7 @@ class JSI_EXPORT Function : public Object { /// \b Note: as with Function.prototype.apply, \c this may not always be /// \c undefined in the function itself. If the function is non-strict, /// \c this will be set to the global object. - Value call(Runtime &runtime, std::initializer_list args) const; + Value call(Runtime& runtime, std::initializer_list args) const; /// Calls the function with any number of arguments similarly to /// Object::setProperty(). The \c this value of the JS function will not be @@ -1006,49 +1006,49 @@ class JSI_EXPORT Function : public Object { /// \c undefined in the function itself. If the function is non-strict, /// \c this will be set to the global object. template - Value call(Runtime &runtime, Args &&...args) const; + Value call(Runtime& runtime, Args&&... args) const; /// Calls the function with \c count \c args and \c jsThis value passed /// as the \c this value. Value callWithThis( - Runtime &Runtime, - const Object &jsThis, - const Value *args, + Runtime& Runtime, + const Object& jsThis, + const Value* args, size_t count) const; /// Calls the function with a \c std::initializer_list of Value /// arguments and \c jsThis passed as the \c this value. Value callWithThis( - Runtime &runtime, - const Object &jsThis, + Runtime& runtime, + const Object& jsThis, std::initializer_list args) const; /// Calls the function with any number of arguments similarly to /// Object::setProperty(), and with \c jsThis passed as the \c this value. template - Value callWithThis(Runtime &runtime, const Object &jsThis, Args &&...args) + Value callWithThis(Runtime& runtime, const Object& jsThis, Args&&... args) const; /// Calls the function as a constructor with \c count \c args. Equivalent /// to calling `new Func` where `Func` is the js function reqresented by /// this. - Value callAsConstructor(Runtime &runtime, const Value *args, size_t count) + Value callAsConstructor(Runtime& runtime, const Value* args, size_t count) const; /// Same as above `callAsConstructor`, except use an initializer_list to /// supply the arguments. - Value callAsConstructor(Runtime &runtime, std::initializer_list args) + Value callAsConstructor(Runtime& runtime, std::initializer_list args) const; /// Same as above `callAsConstructor`, but automatically converts/wraps /// any argument with a jsi Value. template - Value callAsConstructor(Runtime &runtime, Args &&...args) const; + Value callAsConstructor(Runtime& runtime, Args&&... args) const; /// Returns whether this was created with Function::createFromHostFunction. /// If true then you can use getHostFunction to get the underlying /// HostFunctionType. - bool isHostFunction(Runtime &runtime) const { + bool isHostFunction(Runtime& runtime) const { return runtime.isHostFunction(*this); } @@ -1059,7 +1059,7 @@ class JSI_EXPORT Function : public Object { /// Note: The reference returned is borrowed from the JS object underlying /// \c this, and thus only lasts as long as the object underlying /// \c this does. - HostFunctionType &getHostFunction(Runtime &runtime) const { + HostFunctionType& getHostFunction(Runtime& runtime) const { assert(isHostFunction(runtime)); return runtime.getHostFunction(*this); } @@ -1068,7 +1068,7 @@ class JSI_EXPORT Function : public Object { friend class Object; friend class Value; - Function(Runtime::PointerValue *value) : Object(value) {} + Function(Runtime::PointerValue* value) : Object(value) {} }; /// Represents any JS Value (undefined, null, boolean, number, symbol, @@ -1099,7 +1099,7 @@ class JSI_EXPORT Value { /// Moves a Symbol, String, or Object rvalue into a new JS value. template - /* implicit */ Value(T &&other) : Value(kindOf(other)) { + /* implicit */ Value(T&& other) : Value(kindOf(other)) { static_assert( std::is_base_of::value || std::is_base_of::value || @@ -1112,41 +1112,41 @@ class JSI_EXPORT Value { /// Value("foo") will treat foo as a bool. This makes doing that a /// compile error. template - Value(const char *) { + Value(const char*) { static_assert( !std::is_same::value, "Value cannot be constructed directly from const char*"); } - Value(Value &&value); + Value(Value&& value); /// Copies a Symbol lvalue into a new JS value. - Value(Runtime &runtime, const Symbol &sym) : Value(SymbolKind) { + Value(Runtime& runtime, const Symbol& sym) : Value(SymbolKind) { new (&data_.pointer) Symbol(runtime.cloneSymbol(sym.ptr_)); } /// Copies a BigInt lvalue into a new JS value. - Value(Runtime &runtime, const BigInt &bigint) : Value(BigIntKind) { + Value(Runtime& runtime, const BigInt& bigint) : Value(BigIntKind) { new (&data_.pointer) BigInt(runtime.cloneBigInt(bigint.ptr_)); } /// Copies a String lvalue into a new JS value. - Value(Runtime &runtime, const String &str) : Value(StringKind) { + Value(Runtime& runtime, const String& str) : Value(StringKind) { new (&data_.pointer) String(runtime.cloneString(str.ptr_)); } /// Copies a Object lvalue into a new JS value. - Value(Runtime &runtime, const Object &obj) : Value(ObjectKind) { + Value(Runtime& runtime, const Object& obj) : Value(ObjectKind) { new (&data_.pointer) Object(runtime.cloneObject(obj.ptr_)); } /// Creates a JS value from another Value lvalue. - Value(Runtime &runtime, const Value &value); + Value(Runtime& runtime, const Value& value); /// Value(rt, "foo") will treat foo as a bool. This makes doing /// that a compile error. template - Value(Runtime &, const char *) { + Value(Runtime&, const char*) { static_assert( !std::is_same::value, "Value cannot be constructed directly from const char*"); @@ -1165,15 +1165,15 @@ class JSI_EXPORT Value { // \return a \c Value created from a utf8-encoded JSON string. static Value - createFromJsonUtf8(Runtime &runtime, const uint8_t *json, size_t length) { + createFromJsonUtf8(Runtime& runtime, const uint8_t* json, size_t length) { return runtime.createValueFromJsonUtf8(json, length); } /// \return according to the Strict Equality Comparison algorithm, see: /// https://262.ecma-international.org/11.0/#sec-strict-equality-comparison - static bool strictEquals(Runtime &runtime, const Value &a, const Value &b); + static bool strictEquals(Runtime& runtime, const Value& a, const Value& b); - Value &operator=(Value &&other) { + Value& operator=(Value&& other) { this->~Value(); new (this) Value(std::move(other)); return *this; @@ -1232,14 +1232,14 @@ class JSI_EXPORT Value { double asNumber() const; /// \return the Symbol value, or asserts if not a symbol. - Symbol getSymbol(Runtime &runtime) const & { + Symbol getSymbol(Runtime& runtime) const& { assert(isSymbol()); return Symbol(runtime.cloneSymbol(data_.pointer.ptr_)); } /// \return the Symbol value, or asserts if not a symbol. /// Can be used on rvalue references to avoid cloning more symbols. - Symbol getSymbol(Runtime &) && { + Symbol getSymbol(Runtime&) && { assert(isSymbol()); auto ptr = data_.pointer.ptr_; data_.pointer.ptr_ = nullptr; @@ -1248,18 +1248,18 @@ class JSI_EXPORT Value { /// \return the Symbol value, or throws JSIException if not a /// symbol - Symbol asSymbol(Runtime &runtime) const &; - Symbol asSymbol(Runtime &runtime) &&; + Symbol asSymbol(Runtime& runtime) const&; + Symbol asSymbol(Runtime& runtime) &&; /// \return the BigInt value, or asserts if not a bigint. - BigInt getBigInt(Runtime &runtime) const & { + BigInt getBigInt(Runtime& runtime) const& { assert(isBigInt()); return BigInt(runtime.cloneBigInt(data_.pointer.ptr_)); } /// \return the BigInt value, or asserts if not a bigint. /// Can be used on rvalue references to avoid cloning more bigints. - BigInt getBigInt(Runtime &) && { + BigInt getBigInt(Runtime&) && { assert(isBigInt()); auto ptr = data_.pointer.ptr_; data_.pointer.ptr_ = nullptr; @@ -1268,18 +1268,18 @@ class JSI_EXPORT Value { /// \return the BigInt value, or throws JSIException if not a /// bigint - BigInt asBigInt(Runtime &runtime) const &; - BigInt asBigInt(Runtime &runtime) &&; + BigInt asBigInt(Runtime& runtime) const&; + BigInt asBigInt(Runtime& runtime) &&; /// \return the String value, or asserts if not a string. - String getString(Runtime &runtime) const & { + String getString(Runtime& runtime) const& { assert(isString()); return String(runtime.cloneString(data_.pointer.ptr_)); } /// \return the String value, or asserts if not a string. /// Can be used on rvalue references to avoid cloning more strings. - String getString(Runtime &) && { + String getString(Runtime&) && { assert(isString()); auto ptr = data_.pointer.ptr_; data_.pointer.ptr_ = nullptr; @@ -1288,18 +1288,18 @@ class JSI_EXPORT Value { /// \return the String value, or throws JSIException if not a /// string. - String asString(Runtime &runtime) const &; - String asString(Runtime &runtime) &&; + String asString(Runtime& runtime) const&; + String asString(Runtime& runtime) &&; /// \return the Object value, or asserts if not an object. - Object getObject(Runtime &runtime) const & { + Object getObject(Runtime& runtime) const& { assert(isObject()); return Object(runtime.cloneObject(data_.pointer.ptr_)); } /// \return the Object value, or asserts if not an object. /// Can be used on rvalue references to avoid cloning more objects. - Object getObject(Runtime &) && { + Object getObject(Runtime&) && { assert(isObject()); auto ptr = data_.pointer.ptr_; data_.pointer.ptr_ = nullptr; @@ -1308,11 +1308,11 @@ class JSI_EXPORT Value { /// \return the Object value, or throws JSIException if not an /// object. - Object asObject(Runtime &runtime) const &; - Object asObject(Runtime &runtime) &&; + Object asObject(Runtime& runtime) const&; + Object asObject(Runtime& runtime) &&; // \return a String like JS .toString() would do. - String toString(Runtime &runtime) const; + String toString(Runtime& runtime) const; private: friend class Runtime; @@ -1347,16 +1347,16 @@ class JSI_EXPORT Value { Value(ValueKind kind) : kind_(kind) {} - constexpr static ValueKind kindOf(const Symbol &) { + constexpr static ValueKind kindOf(const Symbol&) { return SymbolKind; } - constexpr static ValueKind kindOf(const BigInt &) { + constexpr static ValueKind kindOf(const BigInt&) { return BigIntKind; } - constexpr static ValueKind kindOf(const String &) { + constexpr static ValueKind kindOf(const String&) { return StringKind; } - constexpr static ValueKind kindOf(const Object &) { + constexpr static ValueKind kindOf(const Object&) { return ObjectKind; } @@ -1386,26 +1386,26 @@ class JSI_EXPORT Value { /// locking, provided that the lock (if any) is managed with RAII helpers. class JSI_EXPORT Scope { public: - explicit Scope(Runtime &rt) : rt_(rt), prv_(rt.pushScope()) {} + explicit Scope(Runtime& rt) : rt_(rt), prv_(rt.pushScope()) {} ~Scope() { rt_.popScope(prv_); }; - Scope(const Scope &) = delete; - Scope(Scope &&) = delete; + Scope(const Scope&) = delete; + Scope(Scope&&) = delete; - Scope &operator=(const Scope &) = delete; - Scope &operator=(Scope &&) = delete; + Scope& operator=(const Scope&) = delete; + Scope& operator=(Scope&&) = delete; template - static auto callInNewScope(Runtime &rt, F f) -> decltype(f()) { + static auto callInNewScope(Runtime& rt, F f) -> decltype(f()) { Scope s(rt); return f(); } private: - Runtime &rt_; - Runtime::ScopeState *prv_; + Runtime& rt_; + Runtime::ScopeState* prv_; }; /// Base class for jsi exceptions @@ -1415,9 +1415,9 @@ class JSI_EXPORT JSIException : public std::exception { JSIException(std::string what) : what_(std::move(what)){}; public: - JSIException(const JSIException &) = default; + JSIException(const JSIException&) = default; - virtual const char *what() const noexcept override { + virtual const char* what() const noexcept override { return what_.c_str(); } @@ -1433,7 +1433,7 @@ class JSI_EXPORT JSINativeException : public JSIException { public: JSINativeException(std::string what) : JSIException(std::move(what)) {} - JSINativeException(const JSINativeException &) = default; + JSINativeException(const JSINativeException&) = default; virtual ~JSINativeException(); }; @@ -1444,39 +1444,39 @@ class JSI_EXPORT JSINativeException : public JSIException { class JSI_EXPORT JSError : public JSIException { public: /// Creates a JSError referring to provided \c value - JSError(Runtime &r, Value &&value); + JSError(Runtime& r, Value&& value); /// Creates a JSError referring to new \c Error instance capturing current /// JavaScript stack. The error message property is set to given \c message. - JSError(Runtime &rt, std::string message); + JSError(Runtime& rt, std::string message); /// Creates a JSError referring to new \c Error instance capturing current /// JavaScript stack. The error message property is set to given \c message. - JSError(Runtime &rt, const char *message) + JSError(Runtime& rt, const char* message) : JSError(rt, std::string(message)){}; /// Creates a JSError referring to a JavaScript Object having message and /// stack properties set to provided values. - JSError(Runtime &rt, std::string message, std::string stack); + JSError(Runtime& rt, std::string message, std::string stack); /// Creates a JSError referring to provided value and what string /// set to provided message. This argument order is a bit weird, /// but necessary to avoid ambiguity with the above. - JSError(std::string what, Runtime &rt, Value &&value); + JSError(std::string what, Runtime& rt, Value&& value); - JSError(const JSError &) = default; + JSError(const JSError&) = default; virtual ~JSError(); - const std::string &getStack() const { + const std::string& getStack() const { return stack_; } - const std::string &getMessage() const { + const std::string& getMessage() const { return message_; } - const jsi::Value &value() const { + const jsi::Value& value() const { assert(value_); return *value_; } @@ -1485,7 +1485,7 @@ class JSI_EXPORT JSError : public JSIException { // This initializes the value_ member and does some other // validation, so it must be called by every branch through the // constructors. - void setValue(Runtime &rt, Value &&value); + void setValue(Runtime& rt, Value&& value); // This needs to be on the heap, because throw requires the object // be copyable, and Value is not. diff --git a/ReactCommon/jsi/jsi/jsilib.h b/ReactCommon/jsi/jsi/jsilib.h index 2a4ff9c4911b4f..c94de89f6a766a 100644 --- a/ReactCommon/jsi/jsi/jsilib.h +++ b/ReactCommon/jsi/jsi/jsilib.h @@ -14,20 +14,20 @@ namespace jsi { class FileBuffer : public Buffer { public: - FileBuffer(const std::string &path); + FileBuffer(const std::string& path); ~FileBuffer() override; size_t size() const override { return size_; } - const uint8_t *data() const override { + const uint8_t* data() const override { return data_; } private: size_t size_; - uint8_t *data_; + uint8_t* data_; }; // A trivial implementation of PreparedJavaScript that simply stores the source @@ -43,14 +43,14 @@ class SourceJavaScriptPreparation final : public jsi::PreparedJavaScript, std::string sourceURL) : buf_(std::move(buf)), sourceURL_(std::move(sourceURL)) {} - const std::string &sourceURL() const { + const std::string& sourceURL() const { return sourceURL_; } size_t size() const override { return buf_->size(); } - const uint8_t *data() const override { + const uint8_t* data() const override { return buf_->data(); } }; diff --git a/ReactCommon/jsi/jsi/test/testlib.h b/ReactCommon/jsi/jsi/test/testlib.h index a1a5fce545c157..9f30fb2d77de5e 100644 --- a/ReactCommon/jsi/jsi/test/testlib.h +++ b/ReactCommon/jsi/jsi/test/testlib.h @@ -27,15 +27,15 @@ class JSITestBase : public ::testing::TestWithParam { public: JSITestBase() : factory(GetParam()), runtime(factory()), rt(*runtime) {} - Value eval(const char *code) { + Value eval(const char* code) { return rt.global().getPropertyAsFunction(rt, "eval").call(rt, code); } - Function function(const std::string &code) { + Function function(const std::string& code) { return eval(("(" + code + ")").c_str()).getObject(rt).getFunction(rt); } - bool checkValue(const Value &value, const std::string &jsValue) { + bool checkValue(const Value& value, const std::string& jsValue) { return function("function(value) { return value == " + jsValue + "; }") .call(rt, std::move(value)) .getBool(); @@ -43,7 +43,7 @@ class JSITestBase : public ::testing::TestWithParam { RuntimeFactory factory; std::unique_ptr runtime; - Runtime &rt; + Runtime& rt; }; } // namespace jsi } // namespace facebook diff --git a/ReactCommon/jsi/jsi/threadsafe.h b/ReactCommon/jsi/jsi/threadsafe.h index efdb45c70437cb..cb10a335f6c3d7 100644 --- a/ReactCommon/jsi/jsi/threadsafe.h +++ b/ReactCommon/jsi/jsi/threadsafe.h @@ -19,7 +19,7 @@ class ThreadSafeRuntime : public Runtime { public: virtual void lock() const = 0; virtual void unlock() const = 0; - virtual Runtime &getUnsafeRuntime() = 0; + virtual Runtime& getUnsafeRuntime() = 0; }; namespace detail { @@ -27,7 +27,7 @@ namespace detail { template struct WithLock { L lock; - WithLock(R &r) : lock(r) {} + WithLock(R& r) : lock(r) {} void before() { lock.lock(); } @@ -49,14 +49,14 @@ class ThreadSafeRuntimeImpl final : public WithRuntimeDecorator, R, ThreadSafeRuntime> { public: template - ThreadSafeRuntimeImpl(Args &&...args) + ThreadSafeRuntimeImpl(Args&&... args) : WithRuntimeDecorator, R, ThreadSafeRuntime>( unsafe_, lock_), unsafe_(std::forward(args)...), lock_(unsafe_) {} - R &getUnsafeRuntime() override { + R& getUnsafeRuntime() override { return WithRuntimeDecorator, R, ThreadSafeRuntime>::plain(); } diff --git a/ReactCommon/react/renderer/debug/flags.h b/ReactCommon/react/renderer/debug/flags.h index cd31dca6422252..0239bf6b0c77ff 100644 --- a/ReactCommon/react/renderer/debug/flags.h +++ b/ReactCommon/react/renderer/debug/flags.h @@ -17,11 +17,11 @@ // // Enables verbose logging for the LayoutAnimations subsystem. -// #define LAYOUT_ANIMATION_VERBOSE_LOGGING 1 +//#define LAYOUT_ANIMATION_VERBOSE_LOGGING 1 // Logs information before running `assert` in LayoutAnimations. More useful on // Android vs other platforms. -// #define VERBOSE_LAYOUT_ANIMATION_ASSERTS 1 +//#define VERBOSE_LAYOUT_ANIMATION_ASSERTS 1 // Enables some Shadow Tree introspection features (maintains a StubViewTree, // and logs prev/next tree and mutations if there are any discrepancies). If you @@ -38,13 +38,13 @@ // Enables *very* verbose, noisy logs in the differ. Useful for debugging // specifically the differ, but not much else. -// #define DEBUG_LOGS_DIFFER +//#define DEBUG_LOGS_DIFFER // Uncomment to enable verbose StubViewTree debug logs. This ensures that errors // are logged to console before the `assert` is fired. More useful on Android vs // other platforms. -// #define STUB_VIEW_TREE_VERBOSE 1 +//#define STUB_VIEW_TREE_VERBOSE 1 // Verbose logging for certain Yoga-related things in the RN codebase (not Yoga // codebase). Useful for debugging layout. -// #define RN_DEBUG_YOGA_LOGGER 1 +//#define RN_DEBUG_YOGA_LOGGER 1 diff --git a/ReactCommon/react/utils/ManagedObjectWrapper.h b/ReactCommon/react/utils/ManagedObjectWrapper.h index 1198f2345b4fa8..3af8b158eb663c 100644 --- a/ReactCommon/react/utils/ManagedObjectWrapper.h +++ b/ReactCommon/react/utils/ManagedObjectWrapper.h @@ -35,7 +35,7 @@ namespace detail { */ void wrappedManagedObjectDeleter(void *cfPointer) noexcept; -} // namespace detail +} /* * `wrapManagedObject` and `unwrapManagedObject` are wrapper functions that diff --git a/ReactCommon/yoga/yoga/BitUtils.h b/ReactCommon/yoga/yoga/BitUtils.h index ec0df0a255cfe9..a60ea7609cada3 100644 --- a/ReactCommon/yoga/yoga/BitUtils.h +++ b/ReactCommon/yoga/yoga/BitUtils.h @@ -9,8 +9,8 @@ #ifdef __cplusplus -#include #include +#include #include "YGEnums.h" namespace facebook { @@ -40,13 +40,13 @@ constexpr Enum getEnumData(int flags, size_t index) { } template -void setEnumData(uint32_t &flags, size_t index, int newValue) { +void setEnumData(uint32_t& flags, size_t index, int newValue) { flags = (flags & ~mask(bitWidthFn(), index)) | ((newValue << index) & (mask(bitWidthFn(), index))); } template -void setEnumData(uint8_t &flags, size_t index, int newValue) { +void setEnumData(uint8_t& flags, size_t index, int newValue) { flags = (flags & ~static_cast(mask(bitWidthFn(), index))) | ((newValue << index) & (static_cast(mask(bitWidthFn(), index)))); @@ -56,7 +56,7 @@ constexpr bool getBooleanData(int flags, size_t index) { return (flags >> index) & 1; } -inline void setBooleanData(uint8_t &flags, size_t index, bool value) { +inline void setBooleanData(uint8_t& flags, size_t index, bool value) { if (value) { flags |= 1 << index; } else { diff --git a/ReactCommon/yoga/yoga/CompactValue.h b/ReactCommon/yoga/yoga/CompactValue.h index ae367b688490da..e489fbb614d4dc 100644 --- a/ReactCommon/yoga/yoga/CompactValue.h +++ b/ReactCommon/yoga/yoga/CompactValue.h @@ -22,11 +22,11 @@ #else #include #endif +#include "YGValue.h" +#include "YGMacros.h" #include #include #include -#include "YGMacros.h" -#include "YGValue.h" static_assert( std::numeric_limits::is_iec559, @@ -58,7 +58,7 @@ namespace detail { class YOGA_EXPORT CompactValue { friend constexpr bool operator==(CompactValue, CompactValue) noexcept; - public: +public: static constexpr auto LOWER_BOUND = 1.08420217e-19f; static constexpr auto UPPER_BOUND_POINT = 36893485948395847680.0f; static constexpr auto UPPER_BOUND_PERCENT = 18446742974197923840.0f; @@ -104,7 +104,7 @@ class YOGA_EXPORT CompactValue { constexpr CompactValue() noexcept : repr_(0x7FC00000) {} - CompactValue(const YGValue &x) noexcept : repr_(uint32_t{0}) { + CompactValue(const YGValue& x) noexcept : repr_(uint32_t{0}) { switch (x.unit) { case YGUnitUndefined: *this = ofUndefined(); @@ -149,11 +149,9 @@ class YOGA_EXPORT CompactValue { repr_ != ZERO_BITS_PERCENT && std::isnan(asFloat(repr_))); } - bool isAuto() const noexcept { - return repr_ == AUTO_BITS; - } + bool isAuto() const noexcept { return repr_ == AUTO_BITS; } - private: +private: uint32_t repr_; static constexpr uint32_t BIAS = 0x20000000; @@ -167,9 +165,7 @@ class YOGA_EXPORT CompactValue { constexpr CompactValue(uint32_t data) noexcept : repr_(data) {} - VISIBLE_FOR_TESTING uint32_t repr() { - return repr_; - } + VISIBLE_FOR_TESTING uint32_t repr() { return repr_; } static uint32_t asU32(float f) { #ifdef __cpp_lib_bit_cast diff --git a/ReactCommon/yoga/yoga/Utils.h b/ReactCommon/yoga/yoga/Utils.h index 8a81fcd32ce9c9..52a0954b749030 100644 --- a/ReactCommon/yoga/yoga/Utils.h +++ b/ReactCommon/yoga/yoga/Utils.h @@ -9,9 +9,9 @@ #ifdef __cplusplus -#include "CompactValue.h" #include "YGNode.h" #include "Yoga-internal.h" +#include "CompactValue.h" // This struct is an helper model to hold the data for step 4 of flexbox algo, // which is collecting the flex items in a line. @@ -56,11 +56,11 @@ struct YGCollectFlexItemsRowValues { float crossDim; }; -bool YGValueEqual(const YGValue &a, const YGValue &b); +bool YGValueEqual(const YGValue& a, const YGValue& b); inline bool YGValueEqual( facebook::yoga::detail::CompactValue a, facebook::yoga::detail::CompactValue b) { - return YGValueEqual((YGValue)a, (YGValue)b); + return YGValueEqual((YGValue) a, (YGValue) b); } // This custom float equality function returns true if either absolute @@ -82,8 +82,8 @@ float YGFloatMin(const float a, const float b); // at the comments of YGFloatsEqual function). template bool YGFloatArrayEqual( - const std::array &val1, - const std::array &val2) { + const std::array& val1, + const std::array& val2) { bool areEqual = true; for (std::size_t i = 0; i < size && areEqual; ++i) { areEqual = YGFloatsEqual(val1[i], val2[i]); @@ -119,7 +119,7 @@ inline YGFloatOptional YGResolveValue( inline YGFloatOptional YGResolveValue( facebook::yoga::detail::CompactValue value, float ownerSize) { - return YGResolveValue((YGValue)value, ownerSize); + return YGResolveValue((YGValue) value, ownerSize); } inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) { diff --git a/ReactCommon/yoga/yoga/YGConfig.h b/ReactCommon/yoga/yoga/YGConfig.h index 0fc6b3122c4179..e15cc1225334e0 100644 --- a/ReactCommon/yoga/yoga/YGConfig.h +++ b/ReactCommon/yoga/yoga/YGConfig.h @@ -17,16 +17,16 @@ struct YOGA_EXPORT YGConfig { YGConfigRef config, YGNodeRef node, YGLogLevel level, - void *context, - const char *format, + void* context, + const char* format, va_list args); using CloneWithContextFn = YGNodeRef (*)( YGNodeRef node, YGNodeRef owner, int childIndex, - void *cloneContext); + void* cloneContext); - private: +private: union { CloneWithContextFn withContext; YGCloneNodeFunc noContext; @@ -38,7 +38,7 @@ struct YOGA_EXPORT YGConfig { bool cloneNodeUsesContext_; bool loggerUsesContext_; - public: +public: bool useWebDefaults = false; bool useLegacyStretchBehaviour = false; bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false; @@ -46,10 +46,10 @@ struct YOGA_EXPORT YGConfig { float pointScaleFactor = 1.0f; std::array()> experimentalFeatures = {}; - void *context = nullptr; + void* context = nullptr; YGConfig(YGLogger logger); - void log(YGConfig *, YGNode *, YGLogLevel, void *, const char *, va_list); + void log(YGConfig*, YGNode*, YGLogLevel, void*, const char*, va_list); void setLogger(YGLogger logger) { logger_.noContext = logger; loggerUsesContext_ = false; @@ -58,15 +58,13 @@ struct YOGA_EXPORT YGConfig { logger_.withContext = logger; loggerUsesContext_ = true; } - void setLogger(std::nullptr_t) { - setLogger(YGLogger{nullptr}); - } + void setLogger(std::nullptr_t) { setLogger(YGLogger{nullptr}); } YGNodeRef cloneNode( YGNodeRef node, YGNodeRef owner, int childIndex, - void *cloneContext); + void* cloneContext); void setCloneNodeCallback(YGCloneNodeFunc cloneNode) { cloneNodeCallback_.noContext = cloneNode; cloneNodeUsesContext_ = false; diff --git a/ReactCommon/yoga/yoga/YGFloatOptional.h b/ReactCommon/yoga/yoga/YGFloatOptional.h index ccef0086243582..6af7bbafbfbdcb 100644 --- a/ReactCommon/yoga/yoga/YGFloatOptional.h +++ b/ReactCommon/yoga/yoga/YGFloatOptional.h @@ -14,21 +14,17 @@ #include "Yoga-internal.h" struct YGFloatOptional { - private: +private: float value_ = std::numeric_limits::quiet_NaN(); - public: +public: explicit constexpr YGFloatOptional(float value) : value_(value) {} constexpr YGFloatOptional() = default; // returns the wrapped value, or a value x with YGIsUndefined(x) == true - constexpr float unwrap() const { - return value_; - } + constexpr float unwrap() const { return value_; } - bool isUndefined() const { - return std::isnan(value_); - } + bool isUndefined() const { return std::isnan(value_); } }; // operators take YGFloatOptional by value, as it is a 32bit value diff --git a/ReactCommon/yoga/yoga/YGLayout.h b/ReactCommon/yoga/yoga/YGLayout.h index 1d56bfa4c7864f..e95efbcc2446cd 100644 --- a/ReactCommon/yoga/yoga/YGLayout.h +++ b/ReactCommon/yoga/yoga/YGLayout.h @@ -20,13 +20,13 @@ struct YGLayout { std::array border = {}; std::array padding = {}; - private: +private: static constexpr size_t directionOffset = 0; static constexpr size_t hadOverflowOffset = directionOffset + facebook::yoga::detail::bitWidthFn(); uint8_t flags = 0; - public: +public: uint32_t computedFlexBasisGeneration = 0; YGFloatOptional computedFlexBasis = {}; @@ -61,9 +61,7 @@ struct YGLayout { } bool operator==(YGLayout layout) const; - bool operator!=(YGLayout layout) const { - return !(*this == layout); - } + bool operator!=(YGLayout layout) const { return !(*this == layout); } }; #endif diff --git a/ReactCommon/yoga/yoga/YGMacros.h b/ReactCommon/yoga/yoga/YGMacros.h index 9d2d8dacd52ffd..ee143c29ffa2a2 100644 --- a/ReactCommon/yoga/yoga/YGMacros.h +++ b/ReactCommon/yoga/yoga/YGMacros.h @@ -50,8 +50,7 @@ constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9 namespace detail { template -constexpr int n() -{ +constexpr int n() { return sizeof...(xs); } } // namespace detail @@ -63,7 +62,7 @@ constexpr int n() #define YG_ENUM_DECL(NAME, ...) \ typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \ - WIN_EXPORT const char *NAME##ToString(NAME); + WIN_EXPORT const char* NAME##ToString(NAME); #ifdef __cplusplus #define YG_ENUM_SEQ_DECL(NAME, ...) \ @@ -73,8 +72,7 @@ constexpr int n() namespace yoga { \ namespace enums { \ template <> \ - constexpr int count() \ - { \ + constexpr int count() { \ return detail::n<__VA_ARGS__>(); \ } \ } \ diff --git a/ReactCommon/yoga/yoga/YGNode.h b/ReactCommon/yoga/yoga/YGNode.h index 4fce455008abf5..90bc93ddd0d0b0 100644 --- a/ReactCommon/yoga/yoga/YGNode.h +++ b/ReactCommon/yoga/yoga/YGNode.h @@ -9,25 +9,25 @@ #ifdef __cplusplus -#include #include +#include #include "BitUtils.h" #include "CompactValue.h" #include "YGConfig.h" #include "YGLayout.h" -#include "YGMacros.h" #include "YGStyle.h" +#include "YGMacros.h" #include "Yoga-internal.h" YGConfigRef YGConfigGetDefault(); struct YOGA_EXPORT YGNode { using MeasureWithContextFn = - YGSize (*)(YGNode *, float, YGMeasureMode, float, YGMeasureMode, void *); - using BaselineWithContextFn = float (*)(YGNode *, float, float, void *); - using PrintWithContextFn = void (*)(YGNode *, void *); + YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*); + using BaselineWithContextFn = float (*)(YGNode*, float, float, void*); + using PrintWithContextFn = void (*)(YGNode*, void*); - private: +private: static constexpr size_t hasNewLayout_ = 0; static constexpr size_t isReferenceBaseline_ = 1; static constexpr size_t isDirty_ = 2; @@ -37,7 +37,7 @@ struct YOGA_EXPORT YGNode { static constexpr size_t printUsesContext_ = 6; static constexpr size_t useWebDefaults_ = 7; - void *context_ = nullptr; + void* context_ = nullptr; uint8_t flags = 1; uint8_t reserved_ = 0; union { @@ -80,11 +80,11 @@ struct YOGA_EXPORT YGNode { // them (potentially incorrect) or ignore them (danger of leaks). Only ever // use this after checking that there are no children. // DO NOT CHANGE THE VISIBILITY OF THIS METHOD! - YGNode &operator=(YGNode &&) = default; + YGNode& operator=(YGNode&&) = default; using CompactValue = facebook::yoga::detail::CompactValue; - public: +public: YGNode() : YGNode{YGConfigGetDefault()} {} explicit YGNode(const YGConfigRef config) : config_{config} { if (config->useWebDefaults) { @@ -93,32 +93,26 @@ struct YOGA_EXPORT YGNode { }; ~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree - YGNode(YGNode &&); + YGNode(YGNode&&); // Does not expose true value semantics, as children are not cloned eagerly. // Should we remove this? - YGNode(const YGNode &node) = default; + YGNode(const YGNode& node) = default; // for RB fabric - YGNode(const YGNode &node, YGConfigRef config); + YGNode(const YGNode& node, YGConfigRef config); // assignment means potential leaks of existing children, or alternatively // freeing unowned memory, double free, or freeing stack memory. - YGNode &operator=(const YGNode &) = delete; + YGNode& operator=(const YGNode&) = delete; // Getters - void *getContext() const { - return context_; - } + void* getContext() const { return context_; } - uint8_t &reserved() { - return reserved_; - } - uint8_t reserved() const { - return reserved_; - } + uint8_t& reserved() { return reserved_; } + uint8_t reserved() const { return reserved_; } - void print(void *); + void print(void*); bool getHasNewLayout() const { return facebook::yoga::detail::getBooleanData(flags, hasNewLayout_); @@ -128,43 +122,29 @@ struct YOGA_EXPORT YGNode { return facebook::yoga::detail::getEnumData(flags, nodeType_); } - bool hasMeasureFunc() const noexcept { - return measure_.noContext != nullptr; - } + bool hasMeasureFunc() const noexcept { return measure_.noContext != nullptr; } - YGSize measure(float, YGMeasureMode, float, YGMeasureMode, void *); + YGSize measure(float, YGMeasureMode, float, YGMeasureMode, void*); bool hasBaselineFunc() const noexcept { return baseline_.noContext != nullptr; } - float baseline(float width, float height, void *layoutContext); + float baseline(float width, float height, void* layoutContext); - YGDirtiedFunc getDirtied() const { - return dirtied_; - } + YGDirtiedFunc getDirtied() const { return dirtied_; } // For Performance reasons passing as reference. - YGStyle &getStyle() { - return style_; - } + YGStyle& getStyle() { return style_; } - const YGStyle &getStyle() const { - return style_; - } + const YGStyle& getStyle() const { return style_; } // For Performance reasons passing as reference. - YGLayout &getLayout() { - return layout_; - } + YGLayout& getLayout() { return layout_; } - const YGLayout &getLayout() const { - return layout_; - } + const YGLayout& getLayout() const { return layout_; } - uint32_t getLineIndex() const { - return lineIndex_; - } + uint32_t getLineIndex() const { return lineIndex_; } bool isReferenceBaseline() { return facebook::yoga::detail::getBooleanData(flags, isReferenceBaseline_); @@ -174,25 +154,19 @@ struct YOGA_EXPORT YGNode { // the YogaTree that a YGNode belongs to. This method will return the parent // of the YGNode when a YGNode only belongs to one YogaTree or nullptr when // the YGNode is shared between two or more YogaTrees. - YGNodeRef getOwner() const { - return owner_; - } + YGNodeRef getOwner() const { return owner_; } // Deprecated, use getOwner() instead. - YGNodeRef getParent() const { - return getOwner(); - } + YGNodeRef getParent() const { return getOwner(); } - const YGVector &getChildren() const { - return children_; - } + const YGVector& getChildren() const { return children_; } // Applies a callback to all children, after cloning them if they are not // owned. template - void iterChildrenAfterCloningIfNeeded(T callback, void *cloneContext) { + void iterChildrenAfterCloningIfNeeded(T callback, void* cloneContext) { int i = 0; - for (YGNodeRef &child : children_) { + for (YGNodeRef& child : children_) { if (child->getOwner() != this) { child = config_->cloneNode(child, this, i, cloneContext); child->setOwner(this); @@ -203,13 +177,9 @@ struct YOGA_EXPORT YGNode { } } - YGNodeRef getChild(uint32_t index) const { - return children_.at(index); - } + YGNodeRef getChild(uint32_t index) const { return children_.at(index); } - YGConfigRef getConfig() const { - return config_; - } + YGConfigRef getConfig() const { return config_; } bool isDirty() const { return facebook::yoga::detail::getBooleanData(flags, isDirty_); @@ -224,22 +194,22 @@ struct YOGA_EXPORT YGNode { } static CompactValue computeEdgeValueForColumn( - const YGStyle::Edges &edges, + const YGStyle::Edges& edges, YGEdge edge, CompactValue defaultValue); static CompactValue computeEdgeValueForRow( - const YGStyle::Edges &edges, + const YGStyle::Edges& edges, YGEdge rowEdge, YGEdge edge, CompactValue defaultValue); static CompactValue computeRowGap( - const YGStyle::Gutters &gutters, + const YGStyle::Gutters& gutters, CompactValue defaultValue); static CompactValue computeColumnGap( - const YGStyle::Gutters &gutters, + const YGStyle::Gutters& gutters, CompactValue defaultValue); // Methods related to positions, margin, padding and border @@ -279,9 +249,7 @@ struct YOGA_EXPORT YGNode { const float widthSize) const; // Setters - void setContext(void *context) { - context_ = context; - } + void setContext(void* context) { context_ = context; } void setPrintFunc(YGPrintFunc printFunc) { print_.noContext = printFunc; @@ -291,9 +259,7 @@ struct YOGA_EXPORT YGNode { print_.withContext = printFunc; facebook::yoga::detail::setBooleanData(flags, printUsesContext_, true); } - void setPrintFunc(std::nullptr_t) { - setPrintFunc(YGPrintFunc{nullptr}); - } + void setPrintFunc(std::nullptr_t) { setPrintFunc(YGPrintFunc{nullptr}); } void setHasNewLayout(bool hasNewLayout) { facebook::yoga::detail::setBooleanData(flags, hasNewLayout_, hasNewLayout); @@ -322,40 +288,26 @@ struct YOGA_EXPORT YGNode { return setBaselineFunc(YGBaselineFunc{nullptr}); } - void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { - dirtied_ = dirtiedFunc; - } + void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtied_ = dirtiedFunc; } - void setStyle(const YGStyle &style) { - style_ = style; - } + void setStyle(const YGStyle& style) { style_ = style; } - void setLayout(const YGLayout &layout) { - layout_ = layout; - } + void setLayout(const YGLayout& layout) { layout_ = layout; } - void setLineIndex(uint32_t lineIndex) { - lineIndex_ = lineIndex; - } + void setLineIndex(uint32_t lineIndex) { lineIndex_ = lineIndex; } void setIsReferenceBaseline(bool isReferenceBaseline) { facebook::yoga::detail::setBooleanData( flags, isReferenceBaseline_, isReferenceBaseline); } - void setOwner(YGNodeRef owner) { - owner_ = owner; - } + void setOwner(YGNodeRef owner) { owner_ = owner; } - void setChildren(const YGVector &children) { - children_ = children; - } + void setChildren(const YGVector& children) { children_ = children; } // TODO: rvalue override for setChildren - YG_DEPRECATED void setConfig(YGConfigRef config) { - config_ = config; - } + YG_DEPRECATED void setConfig(YGConfigRef config) { config_ = config; } void setDirty(bool isDirty); void setLayoutLastOwnerDirection(YGDirection direction); @@ -392,7 +344,7 @@ struct YOGA_EXPORT YGNode { bool removeChild(YGNodeRef child); void removeChild(uint32_t index); - void cloneChildrenIfNeeded(void *); + void cloneChildrenIfNeeded(void*); void markDirtyAndPropogate(); float resolveFlexGrow() const; float resolveFlexShrink() const; diff --git a/ReactCommon/yoga/yoga/YGNodePrint.h b/ReactCommon/yoga/yoga/YGNodePrint.h index 2fdafe1335b20a..83b3f860e4b5b5 100644 --- a/ReactCommon/yoga/yoga/YGNodePrint.h +++ b/ReactCommon/yoga/yoga/YGNodePrint.h @@ -19,7 +19,7 @@ namespace facebook { namespace yoga { void YGNodeToString( - std::string &str, + std::string& str, YGNodeRef node, YGPrintOptions options, uint32_t level); diff --git a/ReactCommon/yoga/yoga/YGStyle.h b/ReactCommon/yoga/yoga/YGStyle.h index 40fbad0b250c87..858b7cd1b4ab63 100644 --- a/ReactCommon/yoga/yoga/YGStyle.h +++ b/ReactCommon/yoga/yoga/YGStyle.h @@ -13,12 +13,12 @@ #include #include #include -#include "BitUtils.h" #include "CompactValue.h" #include "YGEnums.h" #include "YGFloatOptional.h" #include "Yoga-internal.h" #include "Yoga.h" +#include "BitUtils.h" class YOGA_EXPORT YGStyle { template @@ -26,19 +26,19 @@ class YOGA_EXPORT YGStyle { facebook::yoga::detail::Values()>; using CompactValue = facebook::yoga::detail::CompactValue; - public: +public: using Dimensions = Values; using Edges = Values; using Gutters = Values; template struct BitfieldRef { - YGStyle &style; + YGStyle& style; size_t offset; operator T() const { return facebook::yoga::detail::getEnumData(style.flags, offset); } - BitfieldRef &operator=(T x) { + BitfieldRef& operator=(T x) { facebook::yoga::detail::setEnumData(style.flags, offset, x); return *this; } @@ -46,11 +46,9 @@ class YOGA_EXPORT YGStyle { template struct Ref { - YGStyle &style; - operator T() const { - return style.*Prop; - } - Ref &operator=(T value) { + YGStyle& style; + operator T() const { return style.*Prop; } + Ref& operator=(T value) { style.*Prop = value; return *this; } @@ -59,34 +57,24 @@ class YOGA_EXPORT YGStyle { template YGStyle::*Prop> struct IdxRef { struct Ref { - YGStyle &style; + YGStyle& style; Idx idx; - operator CompactValue() const { - return (style.*Prop)[idx]; - } - operator YGValue() const { - return (style.*Prop)[idx]; - } - Ref &operator=(CompactValue value) { + operator CompactValue() const { return (style.*Prop)[idx]; } + operator YGValue() const { return (style.*Prop)[idx]; } + Ref& operator=(CompactValue value) { (style.*Prop)[idx] = value; return *this; } }; - YGStyle &style; - IdxRef &operator=(const Values &values) { + YGStyle& style; + IdxRef& operator=(const Values& values) { style.*Prop = values; return *this; } - operator const Values &() const { - return style.*Prop; - } - Ref operator[](Idx idx) { - return {style, idx}; - } - CompactValue operator[](Idx idx) const { - return (style.*Prop)[idx]; - } + operator const Values&() const { return style.*Prop; } + Ref operator[](Idx idx) { return {style, idx}; } + CompactValue operator[](Idx idx) const { return (style.*Prop)[idx]; } }; YGStyle() { @@ -95,7 +83,7 @@ class YOGA_EXPORT YGStyle { } ~YGStyle() = default; - private: +private: static constexpr size_t directionOffset = 0; static constexpr size_t flexdirectionOffset = directionOffset + facebook::yoga::detail::bitWidthFn(); @@ -133,7 +121,7 @@ class YOGA_EXPORT YGStyle { // Yoga specific properties, not compatible with flexbox specification YGFloatOptional aspectRatio_ = {}; - public: +public: // for library users needing a type using ValueRepr = std::remove_reference::type; @@ -141,9 +129,7 @@ class YOGA_EXPORT YGStyle { return facebook::yoga::detail::getEnumData( flags, directionOffset); } - BitfieldRef direction() { - return {*this, directionOffset}; - } + BitfieldRef direction() { return {*this, directionOffset}; } YGFlexDirection flexDirection() const { return facebook::yoga::detail::getEnumData( @@ -165,24 +151,18 @@ class YOGA_EXPORT YGStyle { return facebook::yoga::detail::getEnumData( flags, alignContentOffset); } - BitfieldRef alignContent() { - return {*this, alignContentOffset}; - } + BitfieldRef alignContent() { return {*this, alignContentOffset}; } YGAlign alignItems() const { return facebook::yoga::detail::getEnumData( flags, alignItemsOffset); } - BitfieldRef alignItems() { - return {*this, alignItemsOffset}; - } + BitfieldRef alignItems() { return {*this, alignItemsOffset}; } YGAlign alignSelf() const { return facebook::yoga::detail::getEnumData(flags, alignSelfOffset); } - BitfieldRef alignSelf() { - return {*this, alignSelfOffset}; - } + BitfieldRef alignSelf() { return {*this, alignSelfOffset}; } YGPositionType positionType() const { return facebook::yoga::detail::getEnumData( @@ -195,120 +175,66 @@ class YOGA_EXPORT YGStyle { YGWrap flexWrap() const { return facebook::yoga::detail::getEnumData(flags, flexWrapOffset); } - BitfieldRef flexWrap() { - return {*this, flexWrapOffset}; - } + BitfieldRef flexWrap() { return {*this, flexWrapOffset}; } YGOverflow overflow() const { return facebook::yoga::detail::getEnumData( flags, overflowOffset); } - BitfieldRef overflow() { - return {*this, overflowOffset}; - } + BitfieldRef overflow() { return {*this, overflowOffset}; } YGDisplay display() const { return facebook::yoga::detail::getEnumData(flags, displayOffset); } - BitfieldRef display() { - return {*this, displayOffset}; - } + BitfieldRef display() { return {*this, displayOffset}; } - YGFloatOptional flex() const { - return flex_; - } - Ref flex() { - return {*this}; - } + YGFloatOptional flex() const { return flex_; } + Ref flex() { return {*this}; } - YGFloatOptional flexGrow() const { - return flexGrow_; - } - Ref flexGrow() { - return {*this}; - } + YGFloatOptional flexGrow() const { return flexGrow_; } + Ref flexGrow() { return {*this}; } - YGFloatOptional flexShrink() const { - return flexShrink_; - } - Ref flexShrink() { - return {*this}; - } + YGFloatOptional flexShrink() const { return flexShrink_; } + Ref flexShrink() { return {*this}; } - CompactValue flexBasis() const { - return flexBasis_; - } - Ref flexBasis() { - return {*this}; - } + CompactValue flexBasis() const { return flexBasis_; } + Ref flexBasis() { return {*this}; } - const Edges &margin() const { - return margin_; - } - IdxRef margin() { - return {*this}; - } + const Edges& margin() const { return margin_; } + IdxRef margin() { return {*this}; } - const Edges &position() const { - return position_; - } - IdxRef position() { - return {*this}; - } + const Edges& position() const { return position_; } + IdxRef position() { return {*this}; } - const Edges &padding() const { - return padding_; - } - IdxRef padding() { - return {*this}; - } + const Edges& padding() const { return padding_; } + IdxRef padding() { return {*this}; } - const Edges &border() const { - return border_; - } - IdxRef border() { - return {*this}; - } + const Edges& border() const { return border_; } + IdxRef border() { return {*this}; } - const Gutters &gap() const { - return gap_; - } - IdxRef gap() { - return {*this}; - } + const Gutters& gap() const { return gap_; } + IdxRef gap() { return {*this}; } - const Dimensions &dimensions() const { - return dimensions_; - } - IdxRef dimensions() { - return {*this}; - } + const Dimensions& dimensions() const { return dimensions_; } + IdxRef dimensions() { return {*this}; } - const Dimensions &minDimensions() const { - return minDimensions_; - } + const Dimensions& minDimensions() const { return minDimensions_; } IdxRef minDimensions() { return {*this}; } - const Dimensions &maxDimensions() const { - return maxDimensions_; - } + const Dimensions& maxDimensions() const { return maxDimensions_; } IdxRef maxDimensions() { return {*this}; } // Yoga specific properties, not compatible with flexbox specification - YGFloatOptional aspectRatio() const { - return aspectRatio_; - } - Ref aspectRatio() { - return {*this}; - } + YGFloatOptional aspectRatio() const { return aspectRatio_; } + Ref aspectRatio() { return {*this}; } }; -YOGA_EXPORT bool operator==(const YGStyle &lhs, const YGStyle &rhs); -YOGA_EXPORT inline bool operator!=(const YGStyle &lhs, const YGStyle &rhs) { +YOGA_EXPORT bool operator==(const YGStyle& lhs, const YGStyle& rhs); +YOGA_EXPORT inline bool operator!=(const YGStyle& lhs, const YGStyle& rhs) { return !(lhs == rhs); } diff --git a/ReactCommon/yoga/yoga/YGValue.h b/ReactCommon/yoga/yoga/YGValue.h index 1d0ac7acbeed61..11beb3ec8b74ac 100644 --- a/ReactCommon/yoga/yoga/YGValue.h +++ b/ReactCommon/yoga/yoga/YGValue.h @@ -23,7 +23,7 @@ YG_EXTERN_C_BEGIN // Not defined in MSVC++ #ifndef NAN static const uint32_t __nan = 0x7fc00000; -#define NAN (*(const float *)__nan) +#define NAN (*(const float*) __nan) #endif #define YGUndefined NAN @@ -45,7 +45,7 @@ YG_EXTERN_C_END #ifdef __cplusplus -inline bool operator==(const YGValue &lhs, const YGValue &rhs) { +inline bool operator==(const YGValue& lhs, const YGValue& rhs) { if (lhs.unit != rhs.unit) { return false; } @@ -62,11 +62,11 @@ inline bool operator==(const YGValue &lhs, const YGValue &rhs) { return false; } -inline bool operator!=(const YGValue &lhs, const YGValue &rhs) { +inline bool operator!=(const YGValue& lhs, const YGValue& rhs) { return !(lhs == rhs); } -inline YGValue operator-(const YGValue &value) { +inline YGValue operator-(const YGValue& value) { return {-value.value, value.unit}; } diff --git a/ReactCommon/yoga/yoga/Yoga-internal.h b/ReactCommon/yoga/yoga/Yoga-internal.h index b50b3c3db0b415..9444bb5d1db768 100644 --- a/ReactCommon/yoga/yoga/Yoga-internal.h +++ b/ReactCommon/yoga/yoga/Yoga-internal.h @@ -25,7 +25,7 @@ void YGNodeCalculateLayoutWithContext( float availableWidth, float availableHeight, YGDirection ownerDirection, - void *layoutContext); + void* layoutContext); YG_EXTERN_C_END @@ -40,7 +40,7 @@ inline bool isUndefined(double value) { return std::isnan(value); } -void throwLogicalErrorWithMessage(const char *message); +void throwLogicalErrorWithMessage(const char* message); } // namespace yoga } // namespace facebook @@ -105,23 +105,19 @@ namespace detail { template class Values { - private: +private: std::array values_; - public: +public: Values() = default; - Values(const Values &other) = default; + Values(const Values& other) = default; - explicit Values(const YGValue &defaultValue) noexcept { + explicit Values(const YGValue& defaultValue) noexcept { values_.fill(defaultValue); } - const CompactValue &operator[](size_t i) const noexcept { - return values_[i]; - } - CompactValue &operator[](size_t i) noexcept { - return values_[i]; - } + const CompactValue& operator[](size_t i) const noexcept { return values_[i]; } + CompactValue& operator[](size_t i) noexcept { return values_[i]; } template YGValue get() const noexcept { @@ -129,16 +125,16 @@ class Values { } template - void set(YGValue &value) noexcept { + void set(YGValue& value) noexcept { std::get(values_) = value; } template - void set(YGValue &&value) noexcept { + void set(YGValue&& value) noexcept { set(value); } - bool operator==(const Values &other) const noexcept { + bool operator==(const Values& other) const noexcept { for (size_t i = 0; i < Size; ++i) { if (values_[i] != other.values_[i]) { return false; @@ -147,7 +143,7 @@ class Values { return true; } - Values &operator=(const Values &other) = default; + Values& operator=(const Values& other) = default; }; } // namespace detail } // namespace yoga diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index 5176da76b5b81c..7fbf269d5bae55 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -29,10 +29,10 @@ typedef struct YGSize { float height; } YGSize; -typedef struct YGConfig *YGConfigRef; +typedef struct YGConfig* YGConfigRef; -typedef struct YGNode *YGNodeRef; -typedef const struct YGNode *YGNodeConstRef; +typedef struct YGNode* YGNodeRef; +typedef const struct YGNode* YGNodeConstRef; typedef YGSize (*YGMeasureFunc)( YGNodeRef node, @@ -48,7 +48,7 @@ typedef int (*YGLogger)( YGConfigRef config, YGNodeRef node, YGLogLevel level, - const char *format, + const char* format, va_list args); typedef YGNodeRef ( *YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex); @@ -64,11 +64,15 @@ WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc( WIN_EXPORT void YGNodeFreeRecursive(YGNodeRef node); WIN_EXPORT void YGNodeReset(YGNodeRef node); -WIN_EXPORT void -YGNodeInsertChild(YGNodeRef node, YGNodeRef child, uint32_t index); +WIN_EXPORT void YGNodeInsertChild( + YGNodeRef node, + YGNodeRef child, + uint32_t index); -WIN_EXPORT void -YGNodeSwapChild(YGNodeRef node, YGNodeRef child, uint32_t index); +WIN_EXPORT void YGNodeSwapChild( + YGNodeRef node, + YGNodeRef child, + uint32_t index); WIN_EXPORT void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child); WIN_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node); @@ -76,8 +80,10 @@ WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index); WIN_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node); WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node); WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeRef node); -WIN_EXPORT void -YGNodeSetChildren(YGNodeRef owner, const YGNodeRef children[], uint32_t count); +WIN_EXPORT void YGNodeSetChildren( + YGNodeRef owner, + const YGNodeRef children[], + uint32_t count); WIN_EXPORT void YGNodeSetIsReferenceBaseline( YGNodeRef node, @@ -126,8 +132,8 @@ WIN_EXPORT bool YGNodeCanUseCachedMeasurement( WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeRef srcNode); -WIN_EXPORT void *YGNodeGetContext(YGNodeRef node); -WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void *context); +WIN_EXPORT void* YGNodeGetContext(YGNodeRef node); +WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void* context); void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled); bool YGNodeHasMeasureFunc(YGNodeRef node); WIN_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc); @@ -194,29 +200,41 @@ WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(YGNodeRef node, float flexBasis); WIN_EXPORT void YGNodeStyleSetFlexBasisAuto(YGNodeRef node); WIN_EXPORT YGValue YGNodeStyleGetFlexBasis(YGNodeConstRef node); -WIN_EXPORT void -YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float position); -WIN_EXPORT void -YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float position); +WIN_EXPORT void YGNodeStyleSetPosition( + YGNodeRef node, + YGEdge edge, + float position); +WIN_EXPORT void YGNodeStyleSetPositionPercent( + YGNodeRef node, + YGEdge edge, + float position); WIN_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge); WIN_EXPORT void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float margin); -WIN_EXPORT void -YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float margin); +WIN_EXPORT void YGNodeStyleSetMarginPercent( + YGNodeRef node, + YGEdge edge, + float margin); WIN_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge); WIN_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge); -WIN_EXPORT void -YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float padding); -WIN_EXPORT void -YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float padding); +WIN_EXPORT void YGNodeStyleSetPadding( + YGNodeRef node, + YGEdge edge, + float padding); +WIN_EXPORT void YGNodeStyleSetPaddingPercent( + YGNodeRef node, + YGEdge edge, + float padding); WIN_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge); WIN_EXPORT void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, float border); WIN_EXPORT float YGNodeStyleGetBorder(YGNodeConstRef node, YGEdge edge); -WIN_EXPORT void -YGNodeStyleSetGap(YGNodeRef node, YGGutter gutter, float gapLength); +WIN_EXPORT void YGNodeStyleSetGap( + YGNodeRef node, + YGGutter gutter, + float gapLength); WIN_EXPORT float YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter); WIN_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float width); @@ -281,11 +299,15 @@ WIN_EXPORT float YGNodeLayoutGetBorder(YGNodeRef node, YGEdge edge); WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeRef node, YGEdge edge); WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger); -WIN_EXPORT void YGAssert(bool condition, const char *message); -WIN_EXPORT void -YGAssertWithNode(YGNodeRef node, bool condition, const char *message); -WIN_EXPORT void -YGAssertWithConfig(YGConfigRef config, bool condition, const char *message); +WIN_EXPORT void YGAssert(bool condition, const char* message); +WIN_EXPORT void YGAssertWithNode( + YGNodeRef node, + bool condition, + const char* message); +WIN_EXPORT void YGAssertWithConfig( + YGConfigRef config, + bool condition, + const char* message); // Set this to number of pixels in 1 point to round calculation results If you // want to avoid rounding - set PointScaleFactor to 0 WIN_EXPORT void YGConfigSetPointScaleFactor( @@ -328,8 +350,8 @@ WIN_EXPORT void YGConfigSetCloneNodeFunc( // Export only for C# WIN_EXPORT YGConfigRef YGConfigGetDefault(void); -WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void *context); -WIN_EXPORT void *YGConfigGetContext(YGConfigRef config); +WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context); +WIN_EXPORT void* YGConfigGetContext(YGConfigRef config); WIN_EXPORT float YGRoundValueToPixelGrid( double value, @@ -347,8 +369,8 @@ YG_EXTERN_C_END // Calls f on each node in the tree including the given node argument. void YGTraversePreOrder( YGNodeRef node, - std::function &&f); + std::function&& f); -void YGNodeSetChildren(YGNodeRef owner, const std::vector &children); +void YGNodeSetChildren(YGNodeRef owner, const std::vector& children); #endif diff --git a/ReactCommon/yoga/yoga/event/event.h b/ReactCommon/yoga/yoga/event/event.h index 658c564b77fdd0..fb81b8faa0d4b4 100644 --- a/ReactCommon/yoga/yoga/event/event.h +++ b/ReactCommon/yoga/yoga/event/event.h @@ -7,11 +7,11 @@ #pragma once -#include -#include -#include #include #include +#include +#include +#include struct YGConfig; struct YGNode; @@ -49,7 +49,7 @@ struct LayoutData { measureCallbackReasonsCount; }; -const char *LayoutPassReasonToString(const LayoutPassReason value); +const char* LayoutPassReasonToString(const LayoutPassReason value); struct YOGA_EXPORT Event { enum Type { @@ -64,67 +64,67 @@ struct YOGA_EXPORT Event { NodeBaselineEnd, }; class Data; - using Subscriber = void(const YGNode &, Type, Data); + using Subscriber = void(const YGNode&, Type, Data); using Subscribers = std::vector>; template struct TypedData {}; class Data { - const void *data_; + const void* data_; - public: + public: template - Data(const TypedData &data) : data_{&data} {} + Data(const TypedData& data) : data_{&data} {} template - const TypedData &get() const { - return *static_cast *>(data_); + const TypedData& get() const { + return *static_cast*>(data_); }; }; static void reset(); - static void subscribe(std::function &&subscriber); + static void subscribe(std::function&& subscriber); template - static void publish(const YGNode &node, const TypedData &eventData = {}) { + static void publish(const YGNode& node, const TypedData& eventData = {}) { publish(node, E, Data{eventData}); } template - static void publish(const YGNode *node, const TypedData &eventData = {}) { + static void publish(const YGNode* node, const TypedData& eventData = {}) { publish(*node, eventData); } - private: - static void publish(const YGNode &, Type, const Data &); +private: + static void publish(const YGNode&, Type, const Data&); }; template <> struct Event::TypedData { - YGConfig *config; + YGConfig* config; }; template <> struct Event::TypedData { - YGConfig *config; + YGConfig* config; }; template <> struct Event::TypedData { - void *layoutContext; + void* layoutContext; }; template <> struct Event::TypedData { - void *layoutContext; - LayoutData *layoutData; + void* layoutContext; + LayoutData* layoutData; }; template <> struct Event::TypedData { - void *layoutContext; + void* layoutContext; float width; YGMeasureMode widthMeasureMode; float height; @@ -137,7 +137,7 @@ struct Event::TypedData { template <> struct Event::TypedData { LayoutType layoutType; - void *layoutContext; + void* layoutContext; }; } // namespace yoga diff --git a/ReactCommon/yoga/yoga/log.h b/ReactCommon/yoga/yoga/log.h index 844a1ddbca8655..b9bfea4f390f7e 100644 --- a/ReactCommon/yoga/yoga/log.h +++ b/ReactCommon/yoga/yoga/log.h @@ -21,17 +21,17 @@ namespace detail { struct Log { static void log( - YGNode *node, + YGNode* node, YGLogLevel level, - void *, - const char *message, + void*, + const char* message, ...) noexcept; static void log( - YGConfig *config, + YGConfig* config, YGLogLevel level, - void *, - const char *format, + void*, + const char* format, ...) noexcept; };