diff --git a/ReactCommon/jsi/JSCRuntime.cpp b/ReactCommon/jsi/JSCRuntime.cpp index 00c0ec63bd4..484fd40f0f1 100644 --- a/ReactCommon/jsi/JSCRuntime.cpp +++ b/ReactCommon/jsi/JSCRuntime.cpp @@ -8,11 +8,11 @@ #include "JSCRuntime.h" #include -#include +#include #include +#include #include #include -#include #include #include #include @@ -28,8 +28,8 @@ class ArgsConverter; class JSCRuntime; struct Lock { - void lock(const jsc::JSCRuntime&) const {} - void unlock(const jsc::JSCRuntime&) const {} + void lock(const jsc::JSCRuntime &) const {} + void unlock(const jsc::JSCRuntime &) const {} }; class JSCRuntime : public jsi::Runtime { @@ -45,18 +45,18 @@ class JSCRuntime : public jsi::Runtime { std::string sourceURL) override; jsi::Value evaluatePreparedJavaScript( - const std::shared_ptr& js) override; + const std::shared_ptr &js) override; jsi::Value evaluateJavaScript( const std::shared_ptr &buffer, - const std::string& sourceURL) override; + const std::string &sourceURL) override; jsi::Object global() override; std::string description() override; bool isInspectable() override; - void setDescription(const std::string& desc); + void setDescription(const std::string &desc); // Please don't use the following two functions, only exposed for // integration efforts. @@ -68,29 +68,32 @@ class JSCRuntime : public jsi::Runtime { jsi::Value createValue(JSValueRef value) const; // Value->JSValueRef (similar to above) - JSValueRef valueRef(const jsi::Value& value); + JSValueRef valueRef(const jsi::Value &value); protected: friend class detail::ArgsConverter; class JSCSymbolValue final : public PointerValue { #ifndef NDEBUG - JSCSymbolValue(JSGlobalContextRef ctx, - const std::atomic& ctxInvalid, - JSValueRef sym, std::atomic& counter); + JSCSymbolValue( + JSGlobalContextRef ctx, + const std::atomic &ctxInvalid, + JSValueRef sym, + std::atomic &counter); #else - JSCSymbolValue(JSGlobalContextRef ctx, - const std::atomic& ctxInvalid, - JSValueRef sym); + JSCSymbolValue( + JSGlobalContextRef ctx, + const std::atomic &ctxInvalid, + JSValueRef sym); #endif void invalidate() override; JSGlobalContextRef ctx_; - const std::atomic& ctxInvalid_; + const std::atomic &ctxInvalid_; // There is no C type in the JSC API to represent Symbol, so this stored // a JSValueRef which contains the Symbol. JSValueRef sym_; #ifndef NDEBUG - std::atomic& counter_; + std::atomic &counter_; #endif protected: friend class JSCRuntime; @@ -98,7 +101,7 @@ class JSCRuntime : public jsi::Runtime { class JSCStringValue final : public PointerValue { #ifndef NDEBUG - JSCStringValue(JSStringRef str, std::atomic& counter); + JSCStringValue(JSStringRef str, std::atomic &counter); #else JSCStringValue(JSStringRef str); #endif @@ -106,7 +109,7 @@ class JSCRuntime : public jsi::Runtime { JSStringRef str_; #ifndef NDEBUG - std::atomic& counter_; + std::atomic &counter_; #endif protected: friend class JSCRuntime; @@ -115,111 +118,111 @@ class JSCRuntime : public jsi::Runtime { class JSCObjectValue final : public PointerValue { JSCObjectValue( JSGlobalContextRef ctx, - const std::atomic& ctxInvalid, + const std::atomic &ctxInvalid, JSObjectRef obj #ifndef NDEBUG , - std::atomic& counter + std::atomic &counter #endif - ); + ); void invalidate() override; JSGlobalContextRef ctx_; - const std::atomic& ctxInvalid_; + const std::atomic &ctxInvalid_; JSObjectRef obj_; #ifndef NDEBUG - std::atomic& counter_; + std::atomic &counter_; #endif protected: friend class JSCRuntime; }; - PointerValue* cloneSymbol(const Runtime::PointerValue* pv) override; - PointerValue* cloneString(const Runtime::PointerValue* pv) override; - PointerValue* cloneObject(const Runtime::PointerValue* pv) override; - PointerValue* clonePropNameID(const Runtime::PointerValue* pv) override; + PointerValue *cloneSymbol(const Runtime::PointerValue *pv) override; + PointerValue *cloneString(const Runtime::PointerValue *pv) override; + PointerValue *cloneObject(const Runtime::PointerValue *pv) override; + PointerValue *clonePropNameID(const Runtime::PointerValue *pv) override; - jsi::PropNameID createPropNameIDFromAscii(const char* str, size_t length) + jsi::PropNameID createPropNameIDFromAscii(const char *str, size_t length) override; - jsi::PropNameID createPropNameIDFromUtf8(const uint8_t* utf8, size_t length) + jsi::PropNameID createPropNameIDFromUtf8(const uint8_t *utf8, size_t length) override; - jsi::PropNameID createPropNameIDFromString(const jsi::String& str) override; - std::string utf8(const jsi::PropNameID&) override; - bool compare(const jsi::PropNameID&, const jsi::PropNameID&) override; + jsi::PropNameID createPropNameIDFromString(const jsi::String &str) override; + std::string utf8(const jsi::PropNameID &) override; + bool compare(const jsi::PropNameID &, const jsi::PropNameID &) override; - std::string symbolToString(const jsi::Symbol&) override; + std::string symbolToString(const jsi::Symbol &) override; - jsi::String createStringFromAscii(const char* str, size_t length) override; - jsi::String createStringFromUtf8(const uint8_t* utf8, size_t length) override; - std::string utf8(const jsi::String&) override; + jsi::String createStringFromAscii(const char *str, size_t length) override; + jsi::String createStringFromUtf8(const uint8_t *utf8, size_t length) override; + std::string utf8(const jsi::String &) override; jsi::Object createObject() override; jsi::Object createObject(std::shared_ptr ho) override; virtual std::shared_ptr getHostObject( - const jsi::Object&) override; - jsi::HostFunctionType& getHostFunction(const jsi::Function&) override; + const jsi::Object &) override; + jsi::HostFunctionType &getHostFunction(const jsi::Function &) override; - jsi::Value getProperty(const jsi::Object&, const jsi::String& name) override; - jsi::Value getProperty(const jsi::Object&, const jsi::PropNameID& name) + jsi::Value getProperty(const jsi::Object &, const jsi::String &name) override; + jsi::Value getProperty(const jsi::Object &, const jsi::PropNameID &name) override; - bool hasProperty(const jsi::Object&, const jsi::String& name) override; - bool hasProperty(const jsi::Object&, const jsi::PropNameID& name) override; + bool hasProperty(const jsi::Object &, const jsi::String &name) override; + bool hasProperty(const jsi::Object &, const jsi::PropNameID &name) override; void setPropertyValue( - jsi::Object&, - const jsi::String& name, - const jsi::Value& value) override; + jsi::Object &, + const jsi::String &name, + const jsi::Value &value) override; void setPropertyValue( - jsi::Object&, - const jsi::PropNameID& name, - const jsi::Value& value) override; - bool isArray(const jsi::Object&) const override; - bool isArrayBuffer(const jsi::Object&) const override; - bool isFunction(const jsi::Object&) const override; - bool isHostObject(const jsi::Object&) const override; - bool isHostFunction(const jsi::Function&) const override; - jsi::Array getPropertyNames(const jsi::Object&) override; + jsi::Object &, + const jsi::PropNameID &name, + const jsi::Value &value) override; + bool isArray(const jsi::Object &) const override; + bool isArrayBuffer(const jsi::Object &) const override; + bool isFunction(const jsi::Object &) const override; + bool isHostObject(const jsi::Object &) const override; + bool isHostFunction(const jsi::Function &) const override; + jsi::Array getPropertyNames(const jsi::Object &) override; // TODO: revisit this implementation - jsi::WeakObject createWeakObject(const jsi::Object&) override; - jsi::Value lockWeakObject(const jsi::WeakObject&) override; + jsi::WeakObject createWeakObject(const jsi::Object &) override; + jsi::Value lockWeakObject(const jsi::WeakObject &) override; jsi::Array createArray(size_t length) override; - size_t size(const jsi::Array&) override; - size_t size(const jsi::ArrayBuffer&) override; - uint8_t* data(const jsi::ArrayBuffer&) override; - jsi::Value getValueAtIndex(const jsi::Array&, size_t i) override; - void setValueAtIndexImpl(jsi::Array&, size_t i, const jsi::Value& value) + size_t size(const jsi::Array &) override; + size_t size(const jsi::ArrayBuffer &) override; + uint8_t *data(const jsi::ArrayBuffer &) override; + jsi::Value getValueAtIndex(const jsi::Array &, size_t i) override; + void setValueAtIndexImpl(jsi::Array &, size_t i, const jsi::Value &value) override; jsi::Function createFunctionFromHostFunction( - const jsi::PropNameID& name, + const jsi::PropNameID &name, unsigned int paramCount, jsi::HostFunctionType func) override; jsi::Value call( - const jsi::Function&, - const jsi::Value& jsThis, - const jsi::Value* args, + const jsi::Function &, + const jsi::Value &jsThis, + const jsi::Value *args, size_t count) override; jsi::Value callAsConstructor( - const jsi::Function&, - const jsi::Value* args, + const jsi::Function &, + const jsi::Value *args, size_t count) override; - bool strictEquals(const jsi::Symbol& a, const jsi::Symbol& b) const override; - bool strictEquals(const jsi::String& a, const jsi::String& b) const override; - bool strictEquals(const jsi::Object& a, const jsi::Object& b) const override; - bool instanceOf(const jsi::Object& o, const jsi::Function& f) override; + bool strictEquals(const jsi::Symbol &a, const jsi::Symbol &b) const override; + bool strictEquals(const jsi::String &a, const jsi::String &b) const override; + bool strictEquals(const jsi::Object &a, const jsi::Object &b) const override; + bool instanceOf(const jsi::Object &o, const jsi::Function &f) override; private: // Basically convenience casts - static JSValueRef symbolRef(const jsi::Symbol& str); - static JSStringRef stringRef(const jsi::String& str); - static JSStringRef stringRef(const jsi::PropNameID& sym); - static JSObjectRef objectRef(const jsi::Object& obj); + static JSValueRef symbolRef(const jsi::Symbol &str); + static JSStringRef stringRef(const jsi::String &str); + static JSStringRef stringRef(const jsi::PropNameID &sym); + static JSObjectRef objectRef(const jsi::Object &obj); #ifdef RN_FABRIC_ENABLED - static JSObjectRef objectRef(const jsi::WeakObject& obj); + static JSObjectRef objectRef(const jsi::WeakObject &obj); #endif // Factory methods for creating String/Object @@ -229,14 +232,14 @@ class JSCRuntime : public jsi::Runtime { jsi::Object createObject(JSObjectRef objectRef) const; // Used by factory methods and clone methods - jsi::Runtime::PointerValue* makeSymbolValue(JSValueRef sym) const; - jsi::Runtime::PointerValue* makeStringValue(JSStringRef str) const; - jsi::Runtime::PointerValue* makeObjectValue(JSObjectRef obj) const; + jsi::Runtime::PointerValue *makeSymbolValue(JSValueRef sym) const; + jsi::Runtime::PointerValue *makeStringValue(JSStringRef str) const; + jsi::Runtime::PointerValue *makeObjectValue(JSObjectRef obj) const; void checkException(JSValueRef exc); void checkException(JSValueRef res, JSValueRef exc); - void checkException(JSValueRef exc, const char* msg); - void checkException(JSValueRef res, JSValueRef exc, const char* msg); + void checkException(JSValueRef exc, const char *msg); + void checkException(JSValueRef res, JSValueRef exc, const char *msg); JSGlobalContextRef ctx_; std::atomic ctxInvalid_; @@ -333,7 +336,7 @@ JSStringRef getIsArrayString() { // std::string utility namespace { -std::string to_string(void* value) { +std::string to_string(void *value) { std::ostringstream ss; ss << value; return ss.str(); @@ -381,9 +384,9 @@ std::shared_ptr JSCRuntime::prepareJavaScript( } jsi::Value JSCRuntime::evaluatePreparedJavaScript( - const std::shared_ptr& js) { + const std::shared_ptr &js) { assert( - dynamic_cast(js.get()) && + dynamic_cast(js.get()) && "preparedJavaScript must be a SourceJavaScriptPreparation"); auto sourceJs = std::static_pointer_cast(js); @@ -392,9 +395,9 @@ jsi::Value JSCRuntime::evaluatePreparedJavaScript( jsi::Value JSCRuntime::evaluateJavaScript( const std::shared_ptr &buffer, - const std::string& sourceURL) { + const std::string &sourceURL) { std::string tmp( - reinterpret_cast(buffer->data()), buffer->size()); + reinterpret_cast(buffer->data()), buffer->size()); JSStringRef sourceRef = JSStringCreateWithUTF8CString(tmp.c_str()); JSStringRef sourceURLRef = nullptr; if (!sourceURL.empty()) { @@ -431,19 +434,19 @@ namespace { bool smellsLikeES6Symbol(JSGlobalContextRef ctx, JSValueRef ref) { // Empirically, an es6 Symbol is not an object, but its type is // object. This makes no sense, but we'll run with it. - return (!JSValueIsObject(ctx, ref) && - JSValueGetType(ctx, ref) == kJSTypeObject); + return ( + !JSValueIsObject(ctx, ref) && JSValueGetType(ctx, ref) == kJSTypeObject); } -} +} // namespace JSCRuntime::JSCSymbolValue::JSCSymbolValue( JSGlobalContextRef ctx, - const std::atomic& ctxInvalid, + const std::atomic &ctxInvalid, JSValueRef sym #ifndef NDEBUG , - std::atomic& counter + std::atomic &counter #endif ) : ctx_(ctx), @@ -475,7 +478,7 @@ void JSCRuntime::JSCSymbolValue::invalidate() { #ifndef NDEBUG JSCRuntime::JSCStringValue::JSCStringValue( JSStringRef str, - std::atomic& counter) + std::atomic &counter) : str_(JSStringRetain(str)), counter_(counter) { // Since std::atomic returns a copy instead of a reference when calling // operator+= we must do this explicitly in the constructor @@ -483,8 +486,7 @@ JSCRuntime::JSCStringValue::JSCStringValue( } #else JSCRuntime::JSCStringValue::JSCStringValue(JSStringRef str) - : str_(JSStringRetain(str)) { -} + : str_(JSStringRetain(str)) {} #endif void JSCRuntime::JSCStringValue::invalidate() { @@ -501,11 +503,11 @@ void JSCRuntime::JSCStringValue::invalidate() { JSCRuntime::JSCObjectValue::JSCObjectValue( JSGlobalContextRef ctx, - const std::atomic& ctxInvalid, + const std::atomic &ctxInvalid, JSObjectRef obj #ifndef NDEBUG , - std::atomic& counter + std::atomic &counter #endif ) : ctx_(ctx), @@ -554,47 +556,47 @@ void JSCRuntime::JSCObjectValue::invalidate() { delete this; } -jsi::Runtime::PointerValue* JSCRuntime::cloneSymbol( - const jsi::Runtime::PointerValue* pv) { +jsi::Runtime::PointerValue *JSCRuntime::cloneSymbol( + const jsi::Runtime::PointerValue *pv) { if (!pv) { return nullptr; } - const JSCSymbolValue* symbol = static_cast(pv); + const JSCSymbolValue *symbol = static_cast(pv); return makeSymbolValue(symbol->sym_); } -jsi::Runtime::PointerValue* JSCRuntime::cloneString( - const jsi::Runtime::PointerValue* pv) { +jsi::Runtime::PointerValue *JSCRuntime::cloneString( + const jsi::Runtime::PointerValue *pv) { if (!pv) { return nullptr; } - const JSCStringValue* string = static_cast(pv); + const JSCStringValue *string = static_cast(pv); return makeStringValue(string->str_); } -jsi::Runtime::PointerValue* JSCRuntime::cloneObject( - const jsi::Runtime::PointerValue* pv) { +jsi::Runtime::PointerValue *JSCRuntime::cloneObject( + const jsi::Runtime::PointerValue *pv) { if (!pv) { return nullptr; } - const JSCObjectValue* object = static_cast(pv); + const JSCObjectValue *object = static_cast(pv); assert( object->ctx_ == ctx_ && "Don't try to clone an object backed by a different Runtime"); return makeObjectValue(object->obj_); } -jsi::Runtime::PointerValue* JSCRuntime::clonePropNameID( - const jsi::Runtime::PointerValue* pv) { +jsi::Runtime::PointerValue *JSCRuntime::clonePropNameID( + const jsi::Runtime::PointerValue *pv) { if (!pv) { return nullptr; } - const JSCStringValue* string = static_cast(pv); + const JSCStringValue *string = static_cast(pv); return makeStringValue(string->str_); } jsi::PropNameID JSCRuntime::createPropNameIDFromAscii( - const char* str, + const char *str, size_t length) { // For system JSC this must is identical to a string std::string tmp(str, length); @@ -605,51 +607,49 @@ jsi::PropNameID JSCRuntime::createPropNameIDFromAscii( } jsi::PropNameID JSCRuntime::createPropNameIDFromUtf8( - const uint8_t* utf8, + const uint8_t *utf8, size_t length) { - std::string tmp(reinterpret_cast(utf8), length); + std::string tmp(reinterpret_cast(utf8), length); JSStringRef strRef = JSStringCreateWithUTF8CString(tmp.c_str()); auto res = createPropNameID(strRef); JSStringRelease(strRef); return res; } -jsi::PropNameID JSCRuntime::createPropNameIDFromString(const jsi::String& str) { +jsi::PropNameID JSCRuntime::createPropNameIDFromString(const jsi::String &str) { return createPropNameID(stringRef(str)); } -std::string JSCRuntime::utf8(const jsi::PropNameID& sym) { +std::string JSCRuntime::utf8(const jsi::PropNameID &sym) { return JSStringToSTLString(stringRef(sym)); } -bool JSCRuntime::compare(const jsi::PropNameID& a, const jsi::PropNameID& b) { +bool JSCRuntime::compare(const jsi::PropNameID &a, const jsi::PropNameID &b) { return JSStringIsEqual(stringRef(a), stringRef(b)); } -std::string JSCRuntime::symbolToString(const jsi::Symbol& sym) { - return jsi::Value(*this, sym) - .toString(*this) - .utf8(*this); +std::string JSCRuntime::symbolToString(const jsi::Symbol &sym) { + return jsi::Value(*this, sym).toString(*this).utf8(*this); } -jsi::String JSCRuntime::createStringFromAscii(const char* str, size_t length) { +jsi::String JSCRuntime::createStringFromAscii(const char *str, size_t length) { // Yes we end up double casting for semantic reasons (UTF8 contains ASCII, // not the other way around) return this->createStringFromUtf8( - reinterpret_cast(str), length); + reinterpret_cast(str), length); } jsi::String JSCRuntime::createStringFromUtf8( - const uint8_t* str, + const uint8_t *str, size_t length) { - std::string tmp(reinterpret_cast(str), length); + std::string tmp(reinterpret_cast(str), length); JSStringRef stringRef = JSStringCreateWithUTF8CString(tmp.c_str()); auto result = createString(stringRef); JSStringRelease(stringRef); return result; } -std::string JSCRuntime::utf8(const jsi::String& str) { +std::string JSCRuntime::utf8(const jsi::String &str) { return JSStringToSTLString(stringRef(str)); } @@ -661,11 +661,11 @@ jsi::Object JSCRuntime::createObject() { namespace detail { struct HostObjectProxyBase { HostObjectProxyBase( - JSCRuntime& rt, - const std::shared_ptr& sho) + JSCRuntime &rt, + const std::shared_ptr &sho) : runtime(rt), hostObject(sho) {} - JSCRuntime& runtime; + JSCRuntime &runtime; std::shared_ptr hostObject; }; } // namespace detail @@ -681,25 +681,25 @@ jsi::Object JSCRuntime::createObject(std::shared_ptr ho) { JSContextRef ctx, JSObjectRef object, JSStringRef propName, - JSValueRef* exception) { - auto proxy = static_cast(JSObjectGetPrivate(object)); - auto& rt = proxy->runtime; + JSValueRef *exception) { + auto proxy = static_cast(JSObjectGetPrivate(object)); + auto &rt = proxy->runtime; jsi::PropNameID sym = rt.createPropNameID(propName); jsi::Value ret; try { ret = proxy->hostObject->get(rt, sym); - } catch (const jsi::JSError& error) { + } catch (const jsi::JSError &error) { *exception = rt.valueRef(error.value()); return JSValueMakeUndefined(ctx); - } catch (const std::exception& ex) { + } catch (const std::exception &ex) { auto excValue = rt.global() .getPropertyAsFunction(rt, "Error") .call( rt, - std::string("Exception in HostObject::get(propName:") - + JSStringToSTLString(propName) - + std::string("): ") + ex.what()); + std::string("Exception in HostObject::get(propName:") + + JSStringToSTLString(propName) + std::string("): ") + + ex.what()); *exception = rt.valueRef(excValue); return JSValueMakeUndefined(ctx); } catch (...) { @@ -708,41 +708,41 @@ jsi::Object JSCRuntime::createObject(std::shared_ptr ho) { .getPropertyAsFunction(rt, "Error") .call( rt, - std::string("Exception in HostObject::get(propName:") - + JSStringToSTLString(propName) - + std::string("): ")); + std::string("Exception in HostObject::get(propName:") + + JSStringToSTLString(propName) + + std::string("): ")); *exception = rt.valueRef(excValue); return JSValueMakeUndefined(ctx); } return rt.valueRef(ret); } - #define JSC_UNUSED(x) (void) (x); +#define JSC_UNUSED(x) (void)(x); static bool setProperty( JSContextRef ctx, JSObjectRef object, JSStringRef propName, JSValueRef value, - JSValueRef* exception) { + JSValueRef *exception) { JSC_UNUSED(ctx); - auto proxy = static_cast(JSObjectGetPrivate(object)); - auto& rt = proxy->runtime; + auto proxy = static_cast(JSObjectGetPrivate(object)); + auto &rt = proxy->runtime; jsi::PropNameID sym = rt.createPropNameID(propName); try { proxy->hostObject->set(rt, sym, rt.createValue(value)); - } catch (const jsi::JSError& error) { + } catch (const jsi::JSError &error) { *exception = rt.valueRef(error.value()); return false; - } catch (const std::exception& ex) { + } catch (const std::exception &ex) { auto excValue = rt.global() .getPropertyAsFunction(rt, "Error") .call( rt, - std::string("Exception in HostObject::set(propName:") - + JSStringToSTLString(propName) - + std::string("): ") + ex.what()); + std::string("Exception in HostObject::set(propName:") + + JSStringToSTLString(propName) + std::string("): ") + + ex.what()); *exception = rt.valueRef(excValue); return false; } catch (...) { @@ -751,9 +751,9 @@ jsi::Object JSCRuntime::createObject(std::shared_ptr ho) { .getPropertyAsFunction(rt, "Error") .call( rt, - std::string("Exception in HostObject::set(propName:") - + JSStringToSTLString(propName) - + std::string("): ")); + std::string("Exception in HostObject::set(propName:") + + JSStringToSTLString(propName) + + std::string("): ")); *exception = rt.valueRef(excValue); return false; } @@ -768,18 +768,18 @@ jsi::Object JSCRuntime::createObject(std::shared_ptr ho) { JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames) noexcept { JSC_UNUSED(ctx); - auto proxy = static_cast(JSObjectGetPrivate(object)); - auto& rt = proxy->runtime; + auto proxy = static_cast(JSObjectGetPrivate(object)); + auto &rt = proxy->runtime; auto names = proxy->hostObject->getPropertyNames(rt); - for (auto& name : names) { + for (auto &name : names) { JSPropertyNameAccumulatorAddName(propertyNames, stringRef(name)); } } - #undef JSC_UNUSED +#undef JSC_UNUSED static void finalize(JSObjectRef obj) { - auto hostObject = static_cast(JSObjectGetPrivate(obj)); + auto hostObject = static_cast(JSObjectGetPrivate(obj)); JSObjectSetPrivate(obj, nullptr); delete hostObject; } @@ -804,19 +804,19 @@ jsi::Object JSCRuntime::createObject(std::shared_ptr ho) { } std::shared_ptr JSCRuntime::getHostObject( - const jsi::Object& obj) { + const jsi::Object &obj) { // We are guaranteed at this point to have isHostObject(obj) == true // so the private data should be HostObjectMetadata JSObjectRef object = objectRef(obj); auto metadata = - static_cast(JSObjectGetPrivate(object)); + static_cast(JSObjectGetPrivate(object)); assert(metadata); return metadata->hostObject; } jsi::Value JSCRuntime::getProperty( - const jsi::Object& obj, - const jsi::String& name) { + const jsi::Object &obj, + const jsi::String &name) { JSObjectRef objRef = objectRef(obj); JSValueRef exc = nullptr; JSValueRef res = JSObjectGetProperty(ctx_, objRef, stringRef(name), &exc); @@ -825,8 +825,8 @@ jsi::Value JSCRuntime::getProperty( } jsi::Value JSCRuntime::getProperty( - const jsi::Object& obj, - const jsi::PropNameID& name) { + const jsi::Object &obj, + const jsi::PropNameID &name) { JSObjectRef objRef = objectRef(obj); JSValueRef exc = nullptr; JSValueRef res = JSObjectGetProperty(ctx_, objRef, stringRef(name), &exc); @@ -834,22 +834,22 @@ jsi::Value JSCRuntime::getProperty( return createValue(res); } -bool JSCRuntime::hasProperty(const jsi::Object& obj, const jsi::String& name) { +bool JSCRuntime::hasProperty(const jsi::Object &obj, const jsi::String &name) { JSObjectRef objRef = objectRef(obj); return JSObjectHasProperty(ctx_, objRef, stringRef(name)); } bool JSCRuntime::hasProperty( - const jsi::Object& obj, - const jsi::PropNameID& name) { + const jsi::Object &obj, + const jsi::PropNameID &name) { JSObjectRef objRef = objectRef(obj); return JSObjectHasProperty(ctx_, objRef, stringRef(name)); } void JSCRuntime::setPropertyValue( - jsi::Object& object, - const jsi::PropNameID& name, - const jsi::Value& value) { + jsi::Object &object, + const jsi::PropNameID &name, + const jsi::Value &value) { JSValueRef exc = nullptr; JSObjectSetProperty( ctx_, @@ -862,9 +862,9 @@ void JSCRuntime::setPropertyValue( } void JSCRuntime::setPropertyValue( - jsi::Object& object, - const jsi::String& name, - const jsi::Value& value) { + jsi::Object &object, + const jsi::String &name, + const jsi::Value &value) { JSValueRef exc = nullptr; JSObjectSetProperty( ctx_, @@ -876,7 +876,7 @@ void JSCRuntime::setPropertyValue( checkException(exc); } -bool JSCRuntime::isArray(const jsi::Object& obj) const { +bool JSCRuntime::isArray(const jsi::Object &obj) const { #if !defined(_JSC_FAST_IS_ARRAY) JSObjectRef global = JSContextGetGlobalObject(ctx_); JSStringRef arrayString = getArrayString(); @@ -902,37 +902,37 @@ bool JSCRuntime::isArray(const jsi::Object& obj) const { #endif } -bool JSCRuntime::isArrayBuffer(const jsi::Object& /*obj*/) const { +bool JSCRuntime::isArrayBuffer(const jsi::Object & /*obj*/) const { // TODO: T23270523 - This would fail on builds that use our custom JSC // auto typedArrayType = JSValueGetTypedArrayType(ctx_, objectRef(obj), // nullptr); return typedArrayType == kJSTypedArrayTypeArrayBuffer; throw std::runtime_error("Unsupported"); } -uint8_t* JSCRuntime::data(const jsi::ArrayBuffer& /*obj*/) { +uint8_t *JSCRuntime::data(const jsi::ArrayBuffer & /*obj*/) { // TODO: T23270523 - This would fail on builds that use our custom JSC // return static_cast( // JSObjectGetArrayBufferBytesPtr(ctx_, objectRef(obj), nullptr)); throw std::runtime_error("Unsupported"); } -size_t JSCRuntime::size(const jsi::ArrayBuffer& /*obj*/) { +size_t JSCRuntime::size(const jsi::ArrayBuffer & /*obj*/) { // TODO: T23270523 - This would fail on builds that use our custom JSC // return JSObjectGetArrayBufferByteLength(ctx_, objectRef(obj), nullptr); throw std::runtime_error("Unsupported"); } -bool JSCRuntime::isFunction(const jsi::Object& obj) const { +bool JSCRuntime::isFunction(const jsi::Object &obj) const { return JSObjectIsFunction(ctx_, objectRef(obj)); } -bool JSCRuntime::isHostObject(const jsi::Object& obj) const { +bool JSCRuntime::isHostObject(const jsi::Object &obj) const { auto cls = hostObjectClass; return cls != nullptr && JSValueIsObjectOfClass(ctx_, objectRef(obj), cls); } // Very expensive -jsi::Array JSCRuntime::getPropertyNames(const jsi::Object& obj) { +jsi::Array JSCRuntime::getPropertyNames(const jsi::Object &obj) { JSPropertyNameArrayRef names = JSObjectCopyPropertyNames(ctx_, objectRef(obj)); size_t len = JSPropertyNameArrayGetCount(names); @@ -946,7 +946,7 @@ jsi::Array JSCRuntime::getPropertyNames(const jsi::Object& obj) { return result; } -jsi::WeakObject JSCRuntime::createWeakObject(const jsi::Object& obj) { +jsi::WeakObject JSCRuntime::createWeakObject(const jsi::Object &obj) { #ifdef RN_FABRIC_ENABLED // TODO: revisit this implementation JSObjectRef objRef = objectRef(obj); @@ -956,7 +956,7 @@ jsi::WeakObject JSCRuntime::createWeakObject(const jsi::Object& obj) { #endif } -jsi::Value JSCRuntime::lockWeakObject(const jsi::WeakObject& obj) { +jsi::Value JSCRuntime::lockWeakObject(const jsi::WeakObject &obj) { #ifdef RN_FABRIC_ENABLED // TODO: revisit this implementation JSObjectRef objRef = objectRef(obj); @@ -981,12 +981,12 @@ jsi::Array JSCRuntime::createArray(size_t length) { return createObject(obj).getArray(*this); } -size_t JSCRuntime::size(const jsi::Array& arr) { +size_t JSCRuntime::size(const jsi::Array &arr) { return static_cast( getProperty(arr, createPropNameID(getLengthString())).getNumber()); } -jsi::Value JSCRuntime::getValueAtIndex(const jsi::Array& arr, size_t i) { +jsi::Value JSCRuntime::getValueAtIndex(const jsi::Array &arr, size_t i) { JSValueRef exc = nullptr; auto res = JSObjectGetPropertyAtIndex(ctx_, objectRef(arr), (int)i, &exc); checkException(exc); @@ -994,11 +994,12 @@ jsi::Value JSCRuntime::getValueAtIndex(const jsi::Array& arr, size_t i) { } void JSCRuntime::setValueAtIndexImpl( - jsi::Array& arr, + jsi::Array &arr, size_t i, - const jsi::Value& value) { + const jsi::Value &value) { JSValueRef exc = nullptr; - JSObjectSetPropertyAtIndex(ctx_, objectRef(arr), (int)i, valueRef(value), &exc); + JSObjectSetPropertyAtIndex( + ctx_, objectRef(arr), (int)i, valueRef(value), &exc); checkException(exc); } @@ -1011,7 +1012,7 @@ class HostFunctionProxy { HostFunctionProxy(jsi::HostFunctionType hostFunction) : hostFunction_(hostFunction) {} - jsi::HostFunctionType& getHostFunction() { + jsi::HostFunctionType &getHostFunction() { return hostFunction_; } @@ -1021,7 +1022,7 @@ class HostFunctionProxy { } // namespace jsi::Function JSCRuntime::createFunctionFromHostFunction( - const jsi::PropNameID& name, + const jsi::PropNameID &name, unsigned int paramCount, jsi::HostFunctionType func) { class HostFunctionMetadata : public HostFunctionProxy { @@ -1030,8 +1031,8 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction( // We need to set up the prototype chain properly here. In theory we // could set func.prototype.prototype = Function.prototype to get the // same result. Not sure which approach is better. - HostFunctionMetadata* metadata = - static_cast(JSObjectGetPrivate(object)); + HostFunctionMetadata *metadata = + static_cast(JSObjectGetPrivate(object)); JSValueRef exc = nullptr; JSObjectSetProperty( @@ -1079,7 +1080,7 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction( JSObjectSetPrototype(ctx, object, funcProto); } - static JSValueRef makeError(JSCRuntime& rt, const std::string& desc) { + static JSValueRef makeError(JSCRuntime &rt, const std::string &desc) { jsi::Value value = rt.global().getPropertyAsFunction(rt, "Error").call(rt, desc); return rt.valueRef(value); @@ -1091,14 +1092,14 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction( JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], - JSValueRef* exception) { - HostFunctionMetadata* metadata = - static_cast(JSObjectGetPrivate(function)); - JSCRuntime& rt = *(metadata->runtime); + JSValueRef *exception) { + HostFunctionMetadata *metadata = + static_cast(JSObjectGetPrivate(function)); + JSCRuntime &rt = *(metadata->runtime); const unsigned maxStackArgCount = 8; jsi::Value stackArgs[maxStackArgCount]; std::unique_ptr heapArgs; - jsi::Value* args; + jsi::Value *args; if (argumentCount > maxStackArgCount) { heapArgs = std::make_unique(argumentCount); for (size_t i = 0; i < argumentCount; i++) { @@ -1116,10 +1117,10 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction( try { res = rt.valueRef( metadata->hostFunction_(rt, thisVal, args, argumentCount)); - } catch (const jsi::JSError& error) { + } catch (const jsi::JSError &error) { *exception = rt.valueRef(error.value()); res = JSValueMakeUndefined(ctx); - } catch (const std::exception& ex) { + } catch (const std::exception &ex) { std::string exceptionString("Exception in HostFunction: "); exceptionString += ex.what(); *exception = makeError(rt, exceptionString); @@ -1133,14 +1134,14 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction( } static void finalize(JSObjectRef object) { - HostFunctionMetadata* metadata = - static_cast(JSObjectGetPrivate(object)); + HostFunctionMetadata *metadata = + static_cast(JSObjectGetPrivate(object)); JSObjectSetPrivate(object, nullptr); delete metadata; } HostFunctionMetadata( - JSCRuntime* rt, + JSCRuntime *rt, jsi::HostFunctionType hf, unsigned ac, JSStringRef n) @@ -1149,7 +1150,7 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction( argCount(ac), name(JSStringRetain(n)) {} - JSCRuntime* runtime; + JSCRuntime *runtime; unsigned argCount; JSStringRef name; }; @@ -1176,8 +1177,8 @@ namespace detail { class ArgsConverter { public: - ArgsConverter(JSCRuntime& rt, const jsi::Value* args, size_t count) { - JSValueRef* destination = inline_; + ArgsConverter(JSCRuntime &rt, const jsi::Value *args, size_t count) { + JSValueRef *destination = inline_; if (count > maxStackArgs) { outOfLine_ = std::make_unique(count); destination = outOfLine_.get(); @@ -1188,7 +1189,7 @@ class ArgsConverter { } } - operator JSValueRef*() { + operator JSValueRef *() { return outOfLine_ ? outOfLine_.get() : inline_; } @@ -1199,22 +1200,22 @@ class ArgsConverter { }; } // namespace detail -bool JSCRuntime::isHostFunction(const jsi::Function& obj) const { +bool JSCRuntime::isHostFunction(const jsi::Function &obj) const { auto cls = hostFunctionClass; return cls != nullptr && JSValueIsObjectOfClass(ctx_, objectRef(obj), cls); } -jsi::HostFunctionType& JSCRuntime::getHostFunction(const jsi::Function& obj) { +jsi::HostFunctionType &JSCRuntime::getHostFunction(const jsi::Function &obj) { // We know that isHostFunction(obj) is true here, so its safe to proceed auto proxy = - static_cast(JSObjectGetPrivate(objectRef(obj))); + static_cast(JSObjectGetPrivate(objectRef(obj))); return proxy->getHostFunction(); } jsi::Value JSCRuntime::call( - const jsi::Function& f, - const jsi::Value& jsThis, - const jsi::Value* args, + const jsi::Function &f, + const jsi::Value &jsThis, + const jsi::Value *args, size_t count) { JSValueRef exc = nullptr; auto res = JSObjectCallAsFunction( @@ -1229,8 +1230,8 @@ jsi::Value JSCRuntime::call( } jsi::Value JSCRuntime::callAsConstructor( - const jsi::Function& f, - const jsi::Value* args, + const jsi::Function &f, + const jsi::Value *args, size_t count) { JSValueRef exc = nullptr; auto res = JSObjectCallAsConstructor( @@ -1243,25 +1244,25 @@ jsi::Value JSCRuntime::callAsConstructor( return createValue(res); } -bool JSCRuntime::strictEquals(const jsi::Symbol& a, const jsi::Symbol& b) +bool JSCRuntime::strictEquals(const jsi::Symbol &a, const jsi::Symbol &b) const { JSValueRef exc = nullptr; bool ret = JSValueIsEqual(ctx_, symbolRef(a), symbolRef(b), &exc); - const_cast(this)->checkException(exc); + const_cast(this)->checkException(exc); return ret; } -bool JSCRuntime::strictEquals(const jsi::String& a, const jsi::String& b) +bool JSCRuntime::strictEquals(const jsi::String &a, const jsi::String &b) const { return JSStringIsEqual(stringRef(a), stringRef(b)); } -bool JSCRuntime::strictEquals(const jsi::Object& a, const jsi::Object& b) +bool JSCRuntime::strictEquals(const jsi::Object &a, const jsi::Object &b) const { return objectRef(a) == objectRef(b); } -bool JSCRuntime::instanceOf(const jsi::Object& o, const jsi::Function& f) { +bool JSCRuntime::instanceOf(const jsi::Object &o, const jsi::Function &f) { JSValueRef exc = nullptr; bool res = JSValueIsInstanceOfConstructor(ctx_, objectRef(o), objectRef(f), &exc); @@ -1269,7 +1270,7 @@ bool JSCRuntime::instanceOf(const jsi::Object& o, const jsi::Function& f) { return res; } -jsi::Runtime::PointerValue* JSCRuntime::makeSymbolValue( +jsi::Runtime::PointerValue *JSCRuntime::makeSymbolValue( JSValueRef symbolRef) const { #ifndef NDEBUG return new JSCSymbolValue(ctx_, ctxInvalid_, symbolRef, symbolCounter_); @@ -1285,7 +1286,7 @@ JSStringRef getEmptyString() { } } // namespace -jsi::Runtime::PointerValue* JSCRuntime::makeStringValue( +jsi::Runtime::PointerValue *JSCRuntime::makeStringValue( JSStringRef stringRef) const { if (!stringRef) { stringRef = getEmptyString(); @@ -1309,7 +1310,7 @@ jsi::PropNameID JSCRuntime::createPropNameID(JSStringRef str) { return make(makeStringValue(str)); } -jsi::Runtime::PointerValue* JSCRuntime::makeObjectValue( +jsi::Runtime::PointerValue *JSCRuntime::makeObjectValue( JSObjectRef objectRef) const { if (!objectRef) { objectRef = JSObjectMake(ctx_, nullptr, nullptr); @@ -1350,7 +1351,7 @@ jsi::Value JSCRuntime::createValue(JSValueRef value) const { } } -JSValueRef JSCRuntime::valueRef(const jsi::Value& value) { +JSValueRef JSCRuntime::valueRef(const jsi::Value &value) { // I would rather switch on value.kind_ if (value.isUndefined()) { return JSValueMakeUndefined(ctx_); @@ -1372,26 +1373,26 @@ JSValueRef JSCRuntime::valueRef(const jsi::Value& value) { } } -JSValueRef JSCRuntime::symbolRef(const jsi::Symbol& sym) { - return static_cast(getPointerValue(sym))->sym_; +JSValueRef JSCRuntime::symbolRef(const jsi::Symbol &sym) { + return static_cast(getPointerValue(sym))->sym_; } -JSStringRef JSCRuntime::stringRef(const jsi::String& str) { - return static_cast(getPointerValue(str))->str_; +JSStringRef JSCRuntime::stringRef(const jsi::String &str) { + return static_cast(getPointerValue(str))->str_; } -JSStringRef JSCRuntime::stringRef(const jsi::PropNameID& sym) { - return static_cast(getPointerValue(sym))->str_; +JSStringRef JSCRuntime::stringRef(const jsi::PropNameID &sym) { + return static_cast(getPointerValue(sym))->str_; } -JSObjectRef JSCRuntime::objectRef(const jsi::Object& obj) { - return static_cast(getPointerValue(obj))->obj_; +JSObjectRef JSCRuntime::objectRef(const jsi::Object &obj) { + return static_cast(getPointerValue(obj))->obj_; } #ifdef RN_FABRIC_ENABLED -JSObjectRef JSCRuntime::objectRef(const jsi::WeakObject& obj) { +JSObjectRef JSCRuntime::objectRef(const jsi::WeakObject &obj) { // TODO: revisit this implementation - return static_cast(getPointerValue(obj))->obj_; + return static_cast(getPointerValue(obj))->obj_; } #endif @@ -1407,7 +1408,7 @@ void JSCRuntime::checkException(JSValueRef res, JSValueRef exc) { } } -void JSCRuntime::checkException(JSValueRef exc, const char* msg) { +void JSCRuntime::checkException(JSValueRef exc, const char *msg) { if (JSC_UNLIKELY(exc)) { throw jsi::JSError(std::string(msg), *this, createValue(exc)); } @@ -1416,7 +1417,7 @@ void JSCRuntime::checkException(JSValueRef exc, const char* msg) { void JSCRuntime::checkException( JSValueRef res, JSValueRef exc, - const char* msg) { + const char *msg) { if (JSC_UNLIKELY(!res)) { throw jsi::JSError(std::string(msg), *this, createValue(exc)); }