251119.1 · 4b8a4a59c4e1b7b988b809dedffd89a7662aa785
Add support for JSI version 21 (#17)
* Add support for JSI version 21
* Add the missed change
* Add NodeApiJSIRuntime.h with format
* Change for removing auto
reading declarations
@@ -20,9 +20,6 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") # Turn on Error Handling in MSVC, otherwise objects are not destructed # when they go out of scope due to exceptions. list(APPEND jsi_compile_flags "/EHsc")- list(APPEND jsi_compile_flags "/Zi")- list(APPEND jsi_compile_flags "/Qspectre")- list(APPEND jsi_compile_flags "/sdl") endif() target_compile_options(jsi PRIVATE ${jsi_compile_flags})
@@ -11,6 +11,9 @@ https://github.com/facebook/hermes repo. | Version | Commit Hash | Commit Description |--------:|:-------------------------------------------|------------------------------------------------------+| 21 | `606a4249fea27b072118c791431e799287cacf7c` | Move dumpOpcodeStats() to jsi::Instrumentation, remove IHermesExtra+| | `195afcf8232db8df27f5b2a09c420a6962068c7c` | Add deleteProperty API +| | `7f716de439a5ae83eedc137c6e4f2a1d43a576eb` | Add Value override for has/get/setProperty | 20 | `3eeb01121b52dbe6f9fd67c623a87e08ae9d5197` | Add UUID struct to JSI | | `8d1641f1918ed97b2f69e02ec9f420aa70701331` | Add JSI castInterface API | | `34b807b919c5dacafdf23cd8f855d8f78acf810f` | Adds setRuntimeData and getRuntimeData JSI APIs
@@ -112,11 +112,11 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { return plain_; } - #if JSI_VERSION >= 20+#if JSI_VERSION >= 20 ICast* castInterface(const UUID& interfaceUUID) override { return plain().castInterface(interfaceUUID); }- #endif+#endif Value evaluateJavaScript( const std::shared_ptr<const Buffer>& buffer,@@ -147,10 +147,10 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { } std::string description() override { return plain().description();- };+ } bool isInspectable() override { return plain().isInspectable();- };+ } Instrumentation& instrumentation() override { return *this; }@@ -174,26 +174,26 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { #endif Runtime::PointerValue* cloneString(const Runtime::PointerValue* pv) override { return plain_.cloneString(pv);- };+ } Runtime::PointerValue* cloneObject(const Runtime::PointerValue* pv) override { return plain_.cloneObject(pv);- };+ } Runtime::PointerValue* clonePropNameID( const Runtime::PointerValue* pv) override { return plain_.clonePropNameID(pv);- };+ } PropNameID createPropNameIDFromAscii(const char* str, size_t length) override { return plain_.createPropNameIDFromAscii(str, length);- };+ } PropNameID createPropNameIDFromUtf8(const uint8_t* utf8, size_t length) override { return plain_.createPropNameIDFromUtf8(utf8, length);- };+ } PropNameID createPropNameIDFromString(const String& str) override { return plain_.createPropNameIDFromString(str);- };+ } #if JSI_VERSION >= 19 PropNameID createPropNameIDFromUtf16(const char16_t* utf16, size_t length) override {@@ -203,14 +203,14 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { #if JSI_VERSION >= 5 PropNameID createPropNameIDFromSymbol(const Symbol& sym) override { return plain_.createPropNameIDFromSymbol(sym);- };+ } #endif std::string utf8(const PropNameID& id) override { return plain_.utf8(id);- };+ } bool compare(const PropNameID& a, const PropNameID& b) override { return plain_.compare(a, b);- };+ } std::string symbolToString(const Symbol& sym) override { return plain_.symbolToString(sym);@@ -239,10 +239,10 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { String createStringFromAscii(const char* str, size_t length) override { return plain_.createStringFromAscii(str, length);- };+ } String createStringFromUtf8(const uint8_t* utf8, size_t length) override { return plain_.createStringFromUtf8(utf8, length);- };+ } #if JSI_VERSION >= 19 String createStringFromUtf16(const char16_t* utf16, size_t length) override { return plain_.createStringFromUtf16(utf16, length);@@ -287,22 +287,22 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { Object createObject() override { return plain_.createObject();- };+ } Object createObject(std::shared_ptr<HostObject> ho) override { return plain_.createObject( std::make_shared<DecoratedHostObject>(*this, std::move(ho)));- };+ } std::shared_ptr<HostObject> getHostObject(const jsi::Object& o) override { std::shared_ptr<HostObject> dho = plain_.getHostObject(o); return static_cast<DecoratedHostObject&>(*dho).plainHO_;- };+ } 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<DecoratedHostFunction>()->plainHF_;- };+ } #if JSI_VERSION >= 7 bool hasNativeState(const Object& o) override {@@ -335,80 +335,113 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { Value getProperty(const Object& o, const PropNameID& name) override { return plain_.getProperty(o, name);- };+ } Value getProperty(const Object& o, const String& name) override { return plain_.getProperty(o, name);- };+ }++#if JSI_VERSION >= 21+ Value getProperty(const Object& o, const Value& name) override {+ return plain_.getProperty(o, name);+ }+#endif+ bool hasProperty(const Object& o, const PropNameID& name) override { return plain_.hasProperty(o, name);- };+ } bool hasProperty(const Object& o, const String& name) override { return plain_.hasProperty(o, name);- };+ }++#if JSI_VERSION >= 21+ bool hasProperty(const Object& o, const Value& name) override {+ return plain_.hasProperty(o, name);+ }+#endif+ void setPropertyValue( JSI_CONST_10 Object& o, const PropNameID& name, const Value& value) override { plain_.setPropertyValue(o, name, value);- };+ } void setPropertyValue( JSI_CONST_10 Object& o, const String& name, const Value& value) override { plain_.setPropertyValue(o, name, value);- };+ }++#if JSI_VERSION >= 21+ void setPropertyValue(const Object& o, const Value& name, const Value& value)+ override {+ plain_.setPropertyValue(o, name, value);+ }++ void deleteProperty(const Object& object, const PropNameID& name) override {+ plain_.deleteProperty(object, name);+ }++ void deleteProperty(const Object& object, const String& name) override {+ plain_.deleteProperty(object, name);+ }++ void deleteProperty(const Object& object, const Value& name) override {+ plain_.deleteProperty(object, name);+ }+#endif bool isArray(const Object& o) const override { return plain_.isArray(o);- };+ } bool isArrayBuffer(const Object& o) const override { return plain_.isArrayBuffer(o);- };+ } bool isFunction(const Object& o) const override { return plain_.isFunction(o);- };+ } bool isHostObject(const jsi::Object& o) const override { return plain_.isHostObject(o);- };+ } bool isHostFunction(const jsi::Function& f) const override { return plain_.isHostFunction(f);- };+ } Array getPropertyNames(const Object& o) override { return plain_.getPropertyNames(o);- };+ } WeakObject createWeakObject(const Object& o) override { return plain_.createWeakObject(o);- };+ } Value lockWeakObject(JSI_NO_CONST_3 JSI_CONST_10 WeakObject& wo) override { return plain_.lockWeakObject(wo);- };+ } Array createArray(size_t length) override { return plain_.createArray(length);- };+ } #if JSI_VERSION >= 9 ArrayBuffer createArrayBuffer( std::shared_ptr<MutableBuffer> buffer) override { return plain_.createArrayBuffer(std::move(buffer));- };+ } #endif size_t size(const Array& a) override { return plain_.size(a);- };+ } size_t size(const ArrayBuffer& ab) override { return plain_.size(ab);- };+ } uint8_t* data(const ArrayBuffer& ab) override { return plain_.data(ab);- };+ } Value getValueAtIndex(const Array& a, size_t i) override { return plain_.getValueAtIndex(a, i);- };+ } void setValueAtIndexImpl(JSI_CONST_10 Array& a, size_t i, const Value& value) override { plain_.setValueAtIndexImpl(a, i, value);- };+ } Function createFunctionFromHostFunction( const PropNameID& name,@@ -416,20 +449,20 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { HostFunctionType func) override { return plain_.createFunctionFromHostFunction( name, paramCount, DecoratedHostFunction(*this, std::move(func)));- };+ } Value call( 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) override { return plain_.callAsConstructor(f, args, count);- };+ } - #if JSI_VERSION >= 20+#if JSI_VERSION >= 20 void setRuntimeDataImpl( const UUID& uuid, const void* data,@@ -440,7 +473,7 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { const void* getRuntimeDataImpl(const UUID& uuid) override { return plain_.getRuntimeDataImpl(uuid); }- #endif+#endif // Private data for managing scopes. Runtime::ScopeState* pushScope() override {@@ -452,22 +485,22 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { bool strictEquals(const Symbol& a, const Symbol& b) const override { return plain_.strictEquals(a, b);- };+ } #if JSI_VERSION >= 6 bool strictEquals(const BigInt& a, const BigInt& b) const override { return plain_.strictEquals(a, b);- };+ } #endif 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 { return plain_.strictEquals(a, b);- };+ } bool instanceOf(const Object& o, const Function& f) override { return plain_.instanceOf(o, f);- };+ } // jsi::Instrumentation methods @@ -542,6 +575,12 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation { .writeBasicBlockProfileTraceToFile(fileName); } +#if JSI_VERSION >= 21+ void dumpOpcodeStats(std::ostream& os) const override {+ const_cast<Plain&>(plain()).instrumentation().dumpOpcodeStats(os);+ }+#endif+ /// Dump external profiler symbols to the given file name. void dumpProfilerSymbolsToFile(const std::string& fileName) const override { const_cast<Plain&>(plain()).instrumentation().dumpProfilerSymbolsToFile(@@ -639,12 +678,12 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { // the derived class. WithRuntimeDecorator(Plain& plain, With& with) : RD(plain), with_(with) {} - #if JSI_VERSION >= 20+#if JSI_VERSION >= 20 ICast* castInterface(const UUID& interfaceUUID) override { Around around{with_}; return RD::castInterface(interfaceUUID); }- #endif+#endif Value evaluateJavaScript( const std::shared_ptr<const Buffer>& buffer,@@ -682,11 +721,11 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { std::string description() override { Around around{with_}; return RD::description();- };+ } bool isInspectable() override { Around around{with_}; return RD::isInspectable();- };+ } // The jsi:: prefix is necessary because MSVC compiler complains C2247: // Instrumentation is not accessible because RuntimeDecorator uses private@@ -701,37 +740,37 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { Runtime::PointerValue* cloneSymbol(const Runtime::PointerValue* pv) override { Around around{with_}; return RD::cloneSymbol(pv);- };+ } #if JSI_VERSION >= 6 Runtime::PointerValue* cloneBigInt(const Runtime::PointerValue* pv) override { Around around{with_}; return RD::cloneBigInt(pv);- };+ } #endif Runtime::PointerValue* cloneString(const Runtime::PointerValue* pv) override { Around around{with_}; return RD::cloneString(pv);- };+ } Runtime::PointerValue* cloneObject(const Runtime::PointerValue* pv) override { Around around{with_}; return RD::cloneObject(pv);- };+ } Runtime::PointerValue* clonePropNameID( const Runtime::PointerValue* pv) override { Around around{with_}; return RD::clonePropNameID(pv);- };+ } 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) override { Around around{with_}; return RD::createPropNameIDFromUtf8(utf8, length);- };+ } #if JSI_VERSION >= 19 PropNameID createPropNameIDFromUtf16(const char16_t* utf16, size_t length) override {@@ -742,62 +781,62 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { PropNameID createPropNameIDFromString(const String& str) override { Around around{with_}; return RD::createPropNameIDFromString(str);- };+ } #if JSI_VERSION >= 5 PropNameID createPropNameIDFromSymbol(const Symbol& sym) override { Around around{with_}; return RD::createPropNameIDFromSymbol(sym);- };+ } #endif std::string utf8(const PropNameID& id) override { Around around{with_}; return RD::utf8(id);- };+ } bool compare(const PropNameID& a, const PropNameID& b) override { Around around{with_}; return RD::compare(a, b);- };+ } std::string symbolToString(const Symbol& sym) override { Around around{with_}; return RD::symbolToString(sym);- };+ } #if JSI_VERSION >= 8 BigInt createBigIntFromInt64(int64_t i) override { Around around{with_}; return RD::createBigIntFromInt64(i);- };+ } BigInt createBigIntFromUint64(uint64_t i) override { Around around{with_}; return RD::createBigIntFromUint64(i);- };+ } bool bigintIsInt64(const BigInt& bi) override { Around around{with_}; return RD::bigintIsInt64(bi);- };+ } bool bigintIsUint64(const BigInt& bi) override { Around around{with_}; return RD::bigintIsUint64(bi);- };+ } uint64_t truncate(const BigInt& bi) override { Around around{with_}; return RD::truncate(bi);- };+ } String bigintToString(const BigInt& bi, int i) override { Around around{with_}; return RD::bigintToString(bi, i);- };+ } #endif 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 { Around around{with_}; return RD::createStringFromUtf8(utf8, length);- };+ } #if JSI_VERSION >= 19 String createStringFromUtf16(const char16_t* utf16, size_t length) override { Around around{with_};@@ -843,7 +882,7 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { Value createValueFromJsonUtf8(const uint8_t* json, size_t length) override { Around around{with_}; return RD::createValueFromJsonUtf8(json, length);- };+ } #if JSI_VERSION >= 18 Object createObjectWithPrototype(const Value& prototype) override {@@ -855,34 +894,34 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { Object createObject() override { Around around{with_}; return RD::createObject();- };+ } Object createObject(std::shared_ptr<HostObject> ho) override { Around around{with_}; return RD::createObject(std::move(ho));- };+ } std::shared_ptr<HostObject> getHostObject(const jsi::Object& o) override { Around around{with_}; return RD::getHostObject(o);- };+ } HostFunctionType& getHostFunction(const jsi::Function& f) override { Around around{with_}; return RD::getHostFunction(f);- };+ } #if JSI_VERSION >= 7 bool hasNativeState(const Object& o) override { Around around{with_}; return RD::hasNativeState(o);- };+ } std::shared_ptr<NativeState> getNativeState(const Object& o) override { Around around{with_}; return RD::getNativeState(o);- };+ } void setNativeState(const Object& o, std::shared_ptr<NativeState> state) override { Around around{with_}; RD::setNativeState(o, state);- };+ } #endif #if JSI_VERSION >= 17@@ -900,99 +939,137 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { 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 { Around around{with_}; return RD::getProperty(o, name);- };+ }++#if JSI_VERSION >= 21+ Value getProperty(const Object& o, const Value& name) override {+ Around around{with_};+ return RD::getProperty(o, name);+ }+#endif+ 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 { Around around{with_}; return RD::hasProperty(o, name);- };+ }++#if JSI_VERSION >= 21+ bool hasProperty(const Object& o, const Value& name) override {+ Around around{with_};+ return RD::hasProperty(o, name);+ }+#endif+ void setPropertyValue( JSI_CONST_10 Object& o, const PropNameID& name, const Value& value) override { Around around{with_}; RD::setPropertyValue(o, name, value);- };+ } void setPropertyValue( JSI_CONST_10 Object& o, const String& name, const Value& value) override { Around around{with_}; RD::setPropertyValue(o, name, value);- };+ }+#if JSI_VERSION >= 21+ void setPropertyValue(const Object& o, const Value& name, const Value& value)+ override {+ Around around{with_};+ RD::setPropertyValue(o, name, value);+ }++ void deleteProperty(const Object& object, const PropNameID& name) override {+ Around around{with_};+ RD::deleteProperty(object, name);+ }++ void deleteProperty(const Object& object, const String& name) override {+ Around around{with_};+ RD::deleteProperty(object, name);+ }++ void deleteProperty(const Object& object, const Value& name) override {+ Around around{with_};+ RD::deleteProperty(object, name);+ }+#endif bool isArray(const Object& o) const override { Around around{with_}; return RD::isArray(o);- };+ } bool isArrayBuffer(const Object& o) const override { Around around{with_}; return RD::isArrayBuffer(o);- };+ } bool isFunction(const Object& o) const override { Around around{with_}; return RD::isFunction(o);- };+ } bool isHostObject(const jsi::Object& o) const override { Around around{with_}; return RD::isHostObject(o);- };+ } bool isHostFunction(const jsi::Function& f) const override { Around around{with_}; return RD::isHostFunction(f);- };+ } Array getPropertyNames(const Object& o) override { Around around{with_}; return RD::getPropertyNames(o);- };+ } WeakObject createWeakObject(const Object& o) override { Around around{with_}; return RD::createWeakObject(o);- };+ } Value lockWeakObject(JSI_NO_CONST_3 JSI_CONST_10 WeakObject& wo) override { Around around{with_}; return RD::lockWeakObject(wo);- };+ } Array createArray(size_t length) override { Around around{with_}; return RD::createArray(length);- };+ } #if JSI_VERSION >= 9 ArrayBuffer createArrayBuffer( std::shared_ptr<MutableBuffer> buffer) override { return RD::createArrayBuffer(std::move(buffer));- };+ } #endif size_t size(const Array& a) override { Around around{with_}; return RD::size(a);- };+ } size_t size(const ArrayBuffer& ab) override { Around around{with_}; return RD::size(ab);- };+ } uint8_t* data(const ArrayBuffer& ab) override { Around around{with_}; return RD::data(ab);- };+ } Value getValueAtIndex(const Array& a, size_t i) override { Around around{with_}; return RD::getValueAtIndex(a, i);- };+ } void setValueAtIndexImpl(JSI_CONST_10 Array& a, size_t i, const Value& value) override { Around around{with_}; RD::setValueAtIndexImpl(a, i, value);- };+ } Function createFunctionFromHostFunction( const PropNameID& name,@@ -1001,7 +1078,7 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { Around around{with_}; return RD::createFunctionFromHostFunction( name, paramCount, std::move(func));- };+ } Value call( const Function& f, const Value& jsThis,@@ -1009,12 +1086,12 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { 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) override { Around around{with_}; return RD::callAsConstructor(f, args, count);- };+ } // Private data for managing scopes. Runtime::ScopeState* pushScope() override {@@ -1029,38 +1106,38 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { bool strictEquals(const Symbol& a, const Symbol& b) const override { Around around{with_}; return RD::strictEquals(a, b);- };+ } #if JSI_VERSION >= 6 bool strictEquals(const BigInt& a, const BigInt& b) const override { Around around{with_}; return RD::strictEquals(a, b);- };+ } #endif 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 { Around around{with_}; return RD::strictEquals(a, b);- };+ } bool instanceOf(const Object& o, const Function& f) override { Around around{with_}; return RD::instanceOf(o, f);- };+ } #if JSI_VERSION >= 11 void setExternalMemoryPressure(const jsi::Object& obj, size_t amount) override { Around around{with_}; RD::setExternalMemoryPressure(obj, amount);- };+ } #endif - #if JSI_VERSION >= 20+#if JSI_VERSION >= 20 void setRuntimeDataImpl( const UUID& uuid, const void* data,@@ -1073,7 +1150,7 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> { Around around{with_}; return RD::getRuntimeDataImpl(uuid); }- #endif+#endif private: // Wrap an RAII type around With& to guarantee after always happens.
@@ -0,0 +1,189 @@+/*+ * Copyright (c) Meta Platforms, Inc. and affiliates.+ *+ * This source code is licensed under the MIT license found in the+ * LICENSE file in the root directory of this source tree.+ */++#pragma once++#include <jsi/jsi.h>++struct SHUnit;+struct SHRuntime;+using SHUnitCreator = SHUnit* (*)();+namespace hermes::vm {+class GCExecTrace;+}++namespace facebook::hermes {++namespace sampling_profiler {+class Profile;+}++namespace debugger {+class Debugger;+}++/// Interface for Hermes-specific runtime methods.The actual implementations of+/// the pure virtual methods are provided by Hermes API.+class JSI_EXPORT IHermes : public jsi::ICast {+ public:+ static constexpr jsi::UUID uuid{+ 0xe85cfa22,+ 0xdfae,+ 0x11ef,+ 0xa6f7,+ 0x325096b39f47};++ struct DebugFlags {+ // Looking for the .lazy flag? It's no longer necessary.+ // Source is evaluated lazily by default. See+ // RuntimeConfig::CompilationMode.+ };++ /// Evaluate the given code in an unoptimized form, used for debugging.+ /// This will be no-op if the implementation does not have debugger enabled.+ virtual void debugJavaScript(+ const std::string& src,+ const std::string& sourceURL,+ const DebugFlags& debugFlags) = 0;++ /// Return a ICast pointer to an object that be cast into the interface+ /// IHermesRootAPI. This root API object has static lifetime.+ virtual ICast* getHermesRootAPI() = 0;++ /// Dump sampled stack trace for a given runtime to a data structure that can+ /// be used by third parties.+ virtual sampling_profiler::Profile dumpSampledTraceToProfile() = 0;++ /// Serialize the sampled stack to the format expected by DevTools'+ /// Profiler.stop return type.+ virtual void sampledTraceToStreamInDevToolsFormat(std::ostream& stream) = 0;++ /// Resets the timezone offset cache used by Hermes for performance+ /// optimization. Hermes maintains a cached timezone offset to accelerate date+ /// and time calculations. However, this cache does not automatically detect+ /// changes to the system timezone. When the system timezone changes, the+ /// integration layer (e.g., React Native) must call this method to invalidate+ /// the cache and ensure correct time calculations.+ ///+ /// \note Call this method immediately after detecting any timezone change in+ /// the integrator.+ virtual void resetTimezoneCache() = 0;++ /// Load a new segment into the Runtime.+ /// The \param context must be a valid RequireContext retrieved from JS+ /// using `require.context`.+ virtual void loadSegment(+ std::unique_ptr<const jsi::Buffer> buffer,+ const jsi::Value& context) = 0;++ /// Gets a guaranteed unique id for an Object (or, respectively, String+ /// or PropNameId), which is assigned at allocation time and is+ /// static throughout that object's (or string's, or PropNameID's)+ /// lifetime.+ virtual uint64_t getUniqueID(const jsi::Object& o) const = 0;+ virtual uint64_t getUniqueID(const jsi::BigInt& s) const = 0;+ virtual uint64_t getUniqueID(const jsi::String& s) const = 0;+ virtual uint64_t getUniqueID(const jsi::PropNameID& pni) const = 0;+ virtual uint64_t getUniqueID(const jsi::Symbol& sym) const = 0;++ /// Same as the other \c getUniqueID, except it can return 0 for some values.+ /// 0 means there is no ID associated with the value.+ virtual uint64_t getUniqueID(const jsi::Value& val) const = 0;++ /// From an ID retrieved from \p getUniqueID, go back to the object.+ /// NOTE: This is much slower in general than the reverse operation, and takes+ /// up more memory. Don't use this unless it's absolutely necessary.+ /// \return a jsi::Object if a matching object is found, else returns null.+ virtual jsi::Value getObjectForID(uint64_t id) = 0;++ /// Get a structure representing the execution history (currently just of+ /// GC, but will be generalized as necessary), to aid in debugging+ /// non-deterministic execution.+ virtual const ::hermes::vm::GCExecTrace& getGCExecTrace() const = 0;++ /// Get IO tracking (aka HBC page access) info as a JSON string.+ /// See hermes::vm::Runtime::getIOTrackingInfoJSON() for conditions+ /// needed for there to be useful output.+ virtual std::string getIOTrackingInfoJSON() = 0;++ /// \return a reference to the Debugger for this Runtime.+ virtual debugger::Debugger& getDebugger() = 0;++ /// Register this runtime and thread for sampling profiler. Before using the+ /// runtime on another thread, invoke this function again from the new thread+ /// to make the sampling profiler target the new thread (and forget the old+ /// thread).+ virtual void registerForProfiling() = 0;+ /// Unregister this runtime for sampling profiler.+ virtual void unregisterForProfiling() = 0;++ /// Define methods to interrupt JS execution and set time limits.+ /// All JS compiled to bytecode via prepareJS, or evaluateJS, will support+ /// interruption and time limit monitoring if the runtime is configured with+ /// AsyncBreakCheckInEval. If JS prepared in other ways is executed, care must+ /// be taken to ensure that it is compiled in a mode that supports it (i.e.,+ /// the emitted code contains async break checks).++ /// Asynchronously terminates the current execution. This can be called on+ /// any thread.+ virtual void asyncTriggerTimeout() = 0;++ /// Register this runtime for execution time limit monitoring, with a time+ /// limit of \p timeoutInMs milliseconds.+ /// See compilation notes above.+ virtual void watchTimeLimit(uint32_t timeoutInMs) = 0;+ /// Unregister this runtime for execution time limit monitoring.+ virtual void unwatchTimeLimit() = 0;++ /// Same as \c evaluate JavaScript but with a source map, which will be+ /// applied to exception traces and debug information.+ ///+ /// This is an experimental Hermes-specific API. In the future it may be+ /// renamed, moved or combined with another API, but the provided+ /// functionality will continue to be available in some form.+ virtual jsi::Value evaluateJavaScriptWithSourceMap(+ const std::shared_ptr<const jsi::Buffer>& buffer,+ const std::shared_ptr<const jsi::Buffer>& sourceMapBuf,+ const std::string& sourceURL) = 0;++ /// Associate the SHUnit returned by \p shUnitCreator with this runtime and+ /// run its initialization code. The unit will be freed when the runtime is+ /// destroyed.+ virtual jsi::Value evaluateSHUnit(SHUnitCreator shUnitCreator) = 0;++ /// Retrieve the underlying SHRuntime.+ virtual SHRuntime* getSHRuntime() noexcept = 0;++ /// Returns the underlying low level Hermes VM runtime instance.+ /// This function is considered unsafe and unstable.+ /// Direct use of a vm::Runtime should be avoided as the lower level APIs are+ /// unsafe and they can change without notice.+ virtual void* getVMRuntimeUnsafe() const = 0;++ protected:+ ~IHermes() = default;+};++/// Interface for provide Hermes backend specific methods.+class IHermesSHUnit : public jsi::ICast {+ public:+ static constexpr jsi::UUID uuid{+ 0x52a2d522,+ 0xcbc6,+ 0x4236,+ 0x8d5d,+ 0x2636c320ed65,+ };++ /// Get the unit creating function pointer which can be passed to+ /// evaluateSHUnit() for evaluation.+ virtual SHUnitCreator getSHUnitCreator() const = 0;++ protected:+ ~IHermesSHUnit() = default;+};+} // namespace facebook::hermes
@@ -137,6 +137,11 @@ class JSI_EXPORT Instrumentation { virtual void writeBasicBlockProfileTraceToFile( const std::string& fileName) const = 0; +#if JSI_VERSION >= 21+ /// Write the opcode stats to the given stream.+ virtual void dumpOpcodeStats(std::ostream& os) const = 0;+#endif+ /// Dump external profiler symbols to the given file name. virtual void dumpProfilerSymbolsToFile(const std::string& fileName) const = 0; };
@@ -121,6 +121,12 @@ inline Value Object::getProperty(Runtime& runtime, const PropNameID& name) return runtime.getProperty(*this, name); } +#if JSI_VERSION >= 21+inline Value Object::getProperty(Runtime& runtime, const Value& name) const {+ return runtime.getProperty(*this, name);+}+#endif+ inline bool Object::hasProperty(Runtime& runtime, const char* name) const { return hasProperty(runtime, String::createFromAscii(runtime, name)); }@@ -134,6 +140,12 @@ inline bool Object::hasProperty(Runtime& runtime, const PropNameID& name) return runtime.hasProperty(*this, name); } +#if JSI_VERSION >= 21+inline bool Object::hasProperty(Runtime& runtime, const Value& name) const {+ return runtime.hasProperty(*this, name);+}+#endif+ template <typename T> void Object::setProperty(Runtime& runtime, const char* name, T&& value) JSI_CONST_10 {@@ -155,6 +167,31 @@ void Object::setProperty(Runtime& runtime, const PropNameID& name, T&& value) runtime, name, detail::toValue(runtime, std::forward<T>(value))); } +#if JSI_VERSION >= 21+template <typename T>+void Object::setProperty(Runtime& runtime, const Value& name, T&& value) const {+ setPropertyValue(+ runtime, name, detail::toValue(runtime, std::forward<T>(value)));+}++inline void Object::deleteProperty(Runtime& runtime, const char* name) const {+ deleteProperty(runtime, String::createFromAscii(runtime, name));+}++inline void Object::deleteProperty(Runtime& runtime, const String& name) const {+ runtime.deleteProperty(*this, name);+}++inline void Object::deleteProperty(Runtime& runtime, const PropNameID& name)+ const {+ runtime.deleteProperty(*this, name);+}++inline void Object::deleteProperty(Runtime& runtime, const Value& name) const {+ runtime.deleteProperty(*this, name);+}+#endif+ inline Array Object::getArray(Runtime& runtime) const& { assert(runtime.isArray(*this)); (void)runtime; // when assert is disabled we need to mark this as used
@@ -358,6 +358,12 @@ Instrumentation& Runtime::instrumentation() { std::abort(); } +#if JSI_VERSION >= 21+ void dumpOpcodeStats(std::ostream&) const override {+ std::abort();+ }+#endif+ void dumpProfilerSymbolsToFile(const std::string&) const override { std::abort(); }@@ -465,6 +471,39 @@ Object Runtime::createObjectWithPrototype(const Value& prototype) { } #endif +#if JSI_VERSION >= 21+void Runtime::deleteProperty(const Object& object, const PropNameID& name) {+ auto nameStr = String::createFromUtf16(*this, name.utf16(*this));+ auto deleteFn = global()+ .getPropertyAsObject(*this, "Reflect")+ .getPropertyAsFunction(*this, "deleteProperty");+ auto res = deleteFn.call(*this, object, nameStr).getBool();+ if (!res) {+ throw JSError(*this, "Failed to delete property");+ }+}++void Runtime::deleteProperty(const Object& object, const String& name) {+ auto deleteFn = global()+ .getPropertyAsObject(*this, "Reflect")+ .getPropertyAsFunction(*this, "deleteProperty");+ auto res = deleteFn.call(*this, object, name).getBool();+ if (!res) {+ throw JSError(*this, "Failed to delete property");+ }+}++void Runtime::deleteProperty(const Object& object, const Value& name) {+ auto deleteFn = global()+ .getPropertyAsObject(*this, "Reflect")+ .getPropertyAsFunction(*this, "deleteProperty");+ auto res = deleteFn.call(*this, object, name).getBool();+ if (!res) {+ throw JSError(*this, "Failed to delete property");+ }+}+#endif+ #if JSI_VERSION >= 20 void Runtime::setRuntimeDataImpl( const UUID& uuid,@@ -523,6 +562,35 @@ const void* Runtime::getRuntimeDataImpl(const UUID& uuid) { } #endif +#if JSI_VERSION >= 21+Value Runtime::getProperty(const Object& object, const Value& name) {+ auto getFn = global()+ .getPropertyAsObject(*this, "Reflect")+ .getPropertyAsFunction(*this, "get");+ return getFn.call(*this, object, name);+}++bool Runtime::hasProperty(const Object& object, const Value& name) {+ auto hasFn = global()+ .getPropertyAsObject(*this, "Reflect")+ .getPropertyAsFunction(*this, "has");+ return hasFn.call(*this, object, name).getBool();+}++void Runtime::setPropertyValue(+ const Object& object,+ const Value& name,+ const Value& value) {+ auto setFn = global()+ .getPropertyAsObject(*this, "Reflect")+ .getPropertyAsFunction(*this, "set");+ auto setResult = setFn.call(*this, object, name, value).getBool();+ if (!setResult) {+ throw JSError(*this, "Failed to set the property");+ }+}+#endif+ Pointer& Pointer::operator=(Pointer&& other) JSI_NOEXCEPT_15 { if (ptr_) { ptr_->invalidate();
@@ -28,7 +28,7 @@ #ifndef JSI_VERSION // Use the latest version by default-#define JSI_VERSION 20+#define JSI_VERSION 21 #endif #if JSI_VERSION >= 3@@ -320,9 +320,9 @@ class JSI_EXPORT Runtime { public: virtual ~Runtime(); - #if JSI_VERSION >= 20+#if JSI_VERSION >= 20 ICast* castInterface(const UUID& interfaceUUID) override;- #endif+#endif /// Evaluates the given JavaScript \c buffer. \c sourceURL is used /// to annotate the stack trace if there is an exception. The@@ -421,8 +421,8 @@ class JSI_EXPORT Runtime { /// implementation of this function returns an \c Instrumentation instance /// which returns no metrics. virtual Instrumentation& instrumentation();- - #if JSI_VERSION >= 20++#if JSI_VERSION >= 20 /// Stores the pointer \p data with the \p uuid in the runtime. This can be /// used to store some custom data within the runtime. When the runtime is /// destroyed, or if an entry at an existing key is overwritten, the runtime@@ -432,7 +432,7 @@ class JSI_EXPORT Runtime { /// Returns the data associated with the \p uuid in the runtime. If there's no /// data associated with the uuid, return a null pointer. std::shared_ptr<void> getRuntimeData(const UUID& uuid);- #endif+#endif protected: friend class Pointer;@@ -450,8 +450,8 @@ class JSI_EXPORT Runtime { friend class Value; friend class Scope; friend class JSError;- - #if JSI_VERSION >= 20++#if JSI_VERSION >= 20 /// Stores the pointer \p data with the \p uuid in the runtime. This can be /// used to store some custom data within the runtime. When the runtime is /// destroyed, or if an entry at an existing key is overwritten, the runtime@@ -464,7 +464,7 @@ class JSI_EXPORT Runtime { /// Returns the data associated with the \p uuid in the runtime. If there's no /// data associated with the uuid, return a null pointer. virtual const void* getRuntimeDataImpl(const UUID& uuid);- #endif+#endif // Potential optimization: avoid the cloneFoo() virtual dispatch, // and instead just fix the number of fields, and copy them, since@@ -553,8 +553,18 @@ class JSI_EXPORT Runtime { virtual Value getProperty(const Object&, const PropNameID& name) = 0; virtual Value getProperty(const Object&, const String& name) = 0;++#if JSI_VERSION >= 21+ virtual Value getProperty(const Object&, const Value& name);+#endif+ virtual bool hasProperty(const Object&, const PropNameID& name) = 0; virtual bool hasProperty(const Object&, const String& name) = 0;++#if JSI_VERSION >= 21+ virtual bool hasProperty(const Object&, const Value& name);+#endif+ virtual void setPropertyValue( JSI_CONST_10 Object&, const PropNameID& name,@@ -564,6 +574,15 @@ class JSI_EXPORT Runtime { const String& name, const Value& value) = 0; +#if JSI_VERSION >= 21+ virtual void+ setPropertyValue(const Object&, const Value& name, const Value& value);++ virtual void deleteProperty(const Object&, const PropNameID& name);+ virtual void deleteProperty(const Object&, const String& name);+ virtual void deleteProperty(const Object&, const Value& name);+#endif+ virtual bool isArray(const Object&) const = 0; virtual bool isArrayBuffer(const Object&) const = 0; virtual bool isFunction(const Object&) const = 0;@@ -1014,7 +1033,7 @@ class JSI_EXPORT Object : public Pointer { Object& operator=(Object&& other) = default; /// Creates a new Object instance, like '{}' in JS.- Object(Runtime& runtime) : Object(runtime.createObject()) {}+ explicit Object(Runtime& runtime) : Object(runtime.createObject()) {} static Object createFromHostObject( Runtime& runtime,@@ -1066,6 +1085,14 @@ class JSI_EXPORT Object : public Pointer { /// undefined value. Value getProperty(Runtime& runtime, const PropNameID& name) const; +#if JSI_VERSION >= 21+ /// \return the Property of the object with the given JS Value name. If the+ /// name isn't a property on the object, returns the undefined value.This+ /// attempts to convert the JS Value to convert to a property key. If the+ /// conversion fails, this method may throw.+ Value getProperty(Runtime& runtime, const Value& name) const;+#endif+ /// \return true if and only if the object has a property with the /// given ascii name. bool hasProperty(Runtime& runtime, const char* name) const;@@ -1078,6 +1105,12 @@ class JSI_EXPORT Object : public Pointer { /// given PropNameID name. bool hasProperty(Runtime& runtime, const PropNameID& name) const; +#if JSI_VERSION >= 21+ /// \return true if and only if the object has a property with the given+ /// JS Value name. This attempts to convert the JS Value to convert to a+ /// property key. If the conversion fails, this method may throw.+ bool hasProperty(Runtime& runtime, const Value& name) const;+#endif /// 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.@@ -1098,6 +1131,32 @@ class JSI_EXPORT Object : public Pointer { void setProperty(Runtime& runtime, const PropNameID& name, T&& value) JSI_CONST_10; +#if JSI_VERSION >= 21+ /// 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. This takes a JS Value as the property name, and+ /// attempts to convert to a property key. If the conversion fails, this+ /// method may throw.+ template <typename T>+ void setProperty(Runtime& runtime, const Value& name, T&& value) const;++ /// Delete the property with the given ascii name. Throws if the deletion+ /// failed.+ void deleteProperty(Runtime& runtime, const char* name) const;++ /// Delete the property with the given String name. Throws if the deletion+ /// failed.+ void deleteProperty(Runtime& runtime, const String& name) const;++ /// Delete the property with the given PropNameID name. Throws if the deletion+ /// failed.+ void deleteProperty(Runtime& runtime, const PropNameID& name) const;++ /// Delete the property with the given Value name. Throws if the deletion+ /// failed.+ void deleteProperty(Runtime& runtime, const Value& name) const;+#endif+ /// \return true iff JS \c Array.isArray() would return \c true. If /// so, then \c getArray() will succeed. bool isArray(Runtime& runtime) const {@@ -1243,6 +1302,13 @@ class JSI_EXPORT Object : public Pointer { return runtime.setPropertyValue(*this, name, value); } +#if JSI_VERSION >= 21+ void setPropertyValue(Runtime& runtime, const Value& name, const Value& value)+ const {+ return runtime.setPropertyValue(*this, name, value);+ }+#endif+ friend class Runtime; friend class Value; };@@ -1942,7 +2008,7 @@ U* castInterface(T* ptr) { return static_cast<U*>(ptr->castInterface(U::uuid)); } return nullptr;-};+} /// Helper function to cast the object managed by the shared_ptr \p ptr into an /// interface specified by \c U. If the cast is successful, return a shared_ptr
@@ -181,6 +181,57 @@ TEST_P(JSITest, ObjectTest) { Array names = obj.getPropertyNames(rt); EXPECT_EQ(names.size(rt), 1); EXPECT_EQ(names.getValueAtIndex(rt, 0).getString(rt).utf8(rt), "a");++ // This Runtime Decorator is used to test the default implementation of+ // Runtime::has/get/setProperty with Value overload+ class RD : public RuntimeDecorator<Runtime, Runtime> {+ public:+ explicit RD(Runtime& rt) : RuntimeDecorator(rt) {}++ Value getProperty(const Object& object, const Value& name) override {+ return Runtime::getProperty(object, name);+ }++ bool hasProperty(const Object& object, const Value& name) override {+ return Runtime::hasProperty(object, name);+ }++ void setPropertyValue(+ const Object& object,+ const Value& name,+ const Value& value) override {+ Runtime::setPropertyValue(object, name, value);+ }+ };++ RD rd = RD(rt);++ obj = eval("const obj = {}; obj;").getObject(rd);+ auto propVal = Value(123);+ obj.setProperty(rd, propVal, 456);+ EXPECT_TRUE(obj.hasProperty(rd, propVal));+ auto getRes = obj.getProperty(rd, propVal);+ EXPECT_EQ(getRes.getNumber(), 456);++ /// The property is non-writable so it should fail+ obj = eval(+ "Object.defineProperty(obj, '456', {"+ " value: 10,"+ " writable: false,});")+ .getObject(rd);+ auto unwritableProp = Value(456);+ EXPECT_THROW(obj.setProperty(rd, unwritableProp, 1), JSError);++ auto badObjKey = eval(+ "var badObj = {"+ " toString: function() {"+ " throw new Error('something went wrong');"+ " }"+ "};"+ "badObj;");+ EXPECT_THROW(obj.setProperty(rd, badObjKey, 123), JSError);+ EXPECT_THROW(obj.hasProperty(rd, badObjKey), JSError);+ EXPECT_THROW(obj.getProperty(rd, badObjKey), JSError); } TEST_P(JSITest, HostObjectTest) {@@ -1914,8 +1965,68 @@ TEST_P(JSITest, CastInterface) { auto randomUuid = UUID{0xf2cd96cf, 0x455e, 0x42d9, 0x850a, 0x13e2cde59b8b}; auto ptr = rd.castInterface(randomUuid); - // ptr is of type facebook::jsi::ICast* , requires force the correct overload- EXPECT_EQ(static_cast<void*>(ptr), static_cast<void*>(nullptr));+ // Use == instead of EXPECT_EQ to avoid ambiguous operator usage due to the+ // type of 'ptr'.+ EXPECT_TRUE(ptr == nullptr);+}++TEST_P(JSITest, DeleteProperty) {+ // This Runtime Decorator is used to test the default implementation of+ // Runtime::deleteProperty+ class RD : public RuntimeDecorator<Runtime, Runtime> {+ public:+ explicit RD(Runtime& rt) : RuntimeDecorator(rt) {}++ void deleteProperty(const Object& object, const PropNameID& name) override {+ Runtime::deleteProperty(object, name);+ }+ void deleteProperty(const Object& object, const String& name) override {+ Runtime::deleteProperty(object, name);+ }+ void deleteProperty(const Object& object, const Value& name) override {+ Runtime::deleteProperty(object, name);+ }+ };+ RD rd = RD(rt);+ auto obj = eval("obj = {1:2, foo: 'bar', 3: 4, salt:'pepper'}").getObject(rd);++ auto prop = PropNameID::forAscii(rd, "1");+ auto hasRes = obj.hasProperty(rd, prop);+ EXPECT_TRUE(hasRes);+ obj.deleteProperty(rd, prop);+ hasRes = obj.hasProperty(rd, prop);+ EXPECT_FALSE(hasRes);++ auto str = String::createFromAscii(rd, "foo");+ hasRes = obj.hasProperty(rd, str);+ EXPECT_TRUE(hasRes);+ obj.deleteProperty(rd, str);+ hasRes = obj.hasProperty(rd, str);+ EXPECT_FALSE(hasRes);++ auto valProp = Value(3);+ hasRes = obj.hasProperty(rd, "3");+ EXPECT_TRUE(hasRes);+ obj.deleteProperty(rd, valProp);+ auto getRes = obj.getProperty(rd, "3");+ EXPECT_TRUE(getRes.isUndefined());++ hasRes = obj.hasProperty(rd, "salt");+ EXPECT_TRUE(hasRes);+ obj.deleteProperty(rd, "salt");+ hasRes = obj.hasProperty(rd, "salt");+ EXPECT_FALSE(hasRes);++ obj = eval(+ "const obj = {};"+ "Object.defineProperty(obj, 'prop', {"+ " value: 10,"+ " configurable: false,});"+ "obj;")+ .getObject(rd);+ EXPECT_THROW(obj.deleteProperty(rd, "prop"), JSError);+ hasRes = obj.hasProperty(rd, "prop");+ EXPECT_TRUE(hasRes); } INSTANTIATE_TEST_CASE_P(
@@ -269,9 +269,20 @@ class NodeApiJsiRuntime : public jsi::Runtime { override; jsi::Value getProperty(const jsi::Object &obj, const jsi::String &name) override;++#if JSI_VERSION >= 21+ jsi::Value getProperty(const jsi::Object &obj, const jsi::Value &name)+ override;+#endif+ bool hasProperty(const jsi::Object &obj, const jsi::PropNameID &name) override; bool hasProperty(const jsi::Object &obj, const jsi::String &name) override;++#if JSI_VERSION >= 21+ bool hasProperty(const jsi::Object &obj, const jsi::Value &name) override;+#endif+ void setPropertyValue( JSI_CONST_10 jsi::Object &obj, const jsi::PropNameID &name,@@ -281,6 +292,19 @@ class NodeApiJsiRuntime : public jsi::Runtime { const jsi::String &name, const jsi::Value &value) override; +#if JSI_VERSION >= 21+ void setPropertyValue(+ const jsi::Object &obj,+ const jsi::Value &name,+ const jsi::Value &value) override;++ void deleteProperty(const jsi::Object &obj, const jsi::PropNameID &name)+ override;+ void deleteProperty(const jsi::Object &obj, const jsi::String &name) override;++ void deleteProperty(const jsi::Object &obj, const jsi::Value &name) override;+#endif+ bool isArray(const jsi::Object &obj) const override; bool isArrayBuffer(const jsi::Object &obj) const override; bool isFunction(const jsi::Object &obj) const override;@@ -921,6 +945,7 @@ class NodeApiJsiRuntime : public jsi::Runtime { napi_value getProperty(napi_value object, napi_value propertyId) const; void setProperty(napi_value object, napi_value propertyId, napi_value value) const;+ bool deleteProperty(napi_value object, napi_value propertyId) const; void setProperty( napi_value object, napi_value propertyId,@@ -1741,6 +1766,15 @@ jsi::Value NodeApiJsiRuntime::getProperty( return toJsiValue(getProperty(getNodeApiValue(obj), getNodeApiValue(name))); } +#if JSI_VERSION >= 21+jsi::Value NodeApiJsiRuntime::getProperty(+ const jsi::Object &obj,+ const jsi::Value &name) {+ NodeApiScope scope{*this};+ return toJsiValue(getProperty(getNodeApiValue(obj), getNodeApiValue(name)));+}+#endif+ bool NodeApiJsiRuntime::hasProperty( const jsi::Object &obj, const jsi::PropNameID &name) {@@ -1755,6 +1789,15 @@ bool NodeApiJsiRuntime::hasProperty( return hasProperty(getNodeApiValue(obj), getNodeApiValue(name)); } +#if JSI_VERSION >= 21+bool NodeApiJsiRuntime::hasProperty(+ const jsi::Object &obj,+ const jsi::Value &name) {+ NodeApiScope scope{*this};+ return hasProperty(getNodeApiValue(obj), getNodeApiValue(name));+}+#endif+ void NodeApiJsiRuntime::setPropertyValue( JSI_CONST_10 jsi::Object &obj, const jsi::PropNameID &name,@@ -1773,6 +1816,47 @@ void NodeApiJsiRuntime::setPropertyValue( getNodeApiValue(obj), getNodeApiValue(name), getNodeApiValue(value)); } +#if JSI_VERSION >= 21+void NodeApiJsiRuntime::setPropertyValue(+ const jsi::Object &obj,+ const jsi::Value &name,+ const jsi::Value &value) {+ NodeApiScope scope{*this};+ setProperty(+ getNodeApiValue(obj), getNodeApiValue(name), getNodeApiValue(value));+}++void NodeApiJsiRuntime::deleteProperty(+ const jsi::Object &obj,+ const jsi::PropNameID &name) {+ NodeApiScope scope{*this};+ bool res = deleteProperty(getNodeApiValue(obj), getNodeApiValue(name));+ if (!res) {+ throw jsi::JSError(*this, "Failed to delete property");+ }+}++void NodeApiJsiRuntime::deleteProperty(+ const jsi::Object &obj,+ const jsi::String &name) {+ NodeApiScope scope{*this};+ bool res = deleteProperty(getNodeApiValue(obj), getNodeApiValue(name));+ if (!res) {+ throw jsi::JSError(*this, "Failed to delete property");+ }+}++void NodeApiJsiRuntime::deleteProperty(+ const jsi::Object &obj,+ const jsi::Value &name) {+ NodeApiScope scope{*this};+ bool res = deleteProperty(getNodeApiValue(obj), getNodeApiValue(name));+ if (!res) {+ throw jsi::JSError(*this, "Failed to delete property");+ }+}+#endif+ bool NodeApiJsiRuntime::isArray(const jsi::Object &obj) const { NodeApiScope scope{*this}; return isArray(getNodeApiValue(obj));@@ -2391,7 +2475,7 @@ NodeApiJsiRuntime::PropNameIDView::PropNameIDView( NodeApiJsiRuntime * /*runtime*/, napi_value propertyId) noexcept : propertyId_{make<jsi::PropNameID>(- new(std::addressof(pointerStore_)) NodeApiStackOnlyPointerValue(+ new (std::addressof(pointerStore_)) NodeApiStackOnlyPointerValue( propertyId, NodeApiPointerValueKind::StringPropNameID))} {} @@ -2862,6 +2946,14 @@ void NodeApiJsiRuntime::setProperty( CHECK_NAPI(jsrApi_->napi_set_property(env_, object, propertyId, value)); } +// Deletes object property value.+bool NodeApiJsiRuntime::deleteProperty(napi_value object, napi_value propertyId)+ const {+ bool result{};+ CHECK_NAPI(jsrApi_->napi_delete_property(env_, object, propertyId, &result));+ return result;+}+ // Sets object property value with the provided property accessibility // attributes. void NodeApiJsiRuntime::setProperty(