1370fa39dSKudo Chien // Copyright 2022-present 650 Industries. All rights reserved. 2370fa39dSKudo Chien 3370fa39dSKudo Chien #import <Foundation/Foundation.h> 4370fa39dSKudo Chien 5370fa39dSKudo Chien #ifdef __cplusplus 6370fa39dSKudo Chien #import <jsi/jsi.h> 7370fa39dSKudo Chien 8370fa39dSKudo Chien namespace jsi = facebook::jsi; 9370fa39dSKudo Chien #endif // __cplusplus 10370fa39dSKudo Chien 11370fa39dSKudo Chien @class EXJavaScriptRuntime; 129bc9ec42STomasz Sapeta @class EXJavaScriptValue; 1378516026STomasz Sapeta @class EXJavaScriptWeakObject; 149bc9ec42STomasz Sapeta 159bc9ec42STomasz Sapeta /** 169bc9ec42STomasz Sapeta The property descriptor options for the property being defined or modified. 179bc9ec42STomasz Sapeta */ 189bc9ec42STomasz Sapeta typedef NS_OPTIONS(NSInteger, EXJavaScriptObjectPropertyDescriptor) { 199bc9ec42STomasz Sapeta /** 209bc9ec42STomasz Sapeta If set, the type of this property descriptor may be changed and if the property may be deleted from the corresponding object. 219bc9ec42STomasz Sapeta */ 229bc9ec42STomasz Sapeta EXJavaScriptObjectPropertyDescriptorConfigurable = 1 << 0, 239bc9ec42STomasz Sapeta /** 249bc9ec42STomasz Sapeta If set, the property shows up during enumeration of the properties on the corresponding object. 259bc9ec42STomasz Sapeta */ 269bc9ec42STomasz Sapeta EXJavaScriptObjectPropertyDescriptorEnumerable = 1 << 1, 279bc9ec42STomasz Sapeta /** 289bc9ec42STomasz Sapeta If set, the value associated with the property may be changed with an assignment operator. 299bc9ec42STomasz Sapeta */ 309bc9ec42STomasz Sapeta EXJavaScriptObjectPropertyDescriptorWritable = 1 << 2, 319bc9ec42STomasz Sapeta } NS_SWIFT_NAME(JavaScriptObjectPropertyDescriptor); 32370fa39dSKudo Chien 33370fa39dSKudo Chien NS_SWIFT_NAME(JavaScriptObject) 34370fa39dSKudo Chien @interface EXJavaScriptObject : NSObject 35370fa39dSKudo Chien 36370fa39dSKudo Chien // Some parts of the interface must be hidden for Swift – it can't import any C++ code. 37370fa39dSKudo Chien #ifdef __cplusplus 38370fa39dSKudo Chien - (nonnull instancetype)initWith:(std::shared_ptr<jsi::Object>)jsObjectPtr 39370fa39dSKudo Chien runtime:(nonnull EXJavaScriptRuntime *)runtime; 40370fa39dSKudo Chien 41370fa39dSKudo Chien /** 42370fa39dSKudo Chien Returns the pointer to the underlying object. 43370fa39dSKudo Chien */ 44370fa39dSKudo Chien - (nonnull jsi::Object *)get; 45*fa88aeb8STomasz Sapeta 46*fa88aeb8STomasz Sapeta /** 47*fa88aeb8STomasz Sapeta Returns the shared pointer to the underlying object. 48*fa88aeb8STomasz Sapeta */ 49*fa88aeb8STomasz Sapeta - (std::shared_ptr<jsi::Object>)getShared; 50370fa39dSKudo Chien #endif // __cplusplus 51370fa39dSKudo Chien 529bc9ec42STomasz Sapeta #pragma mark - Accessing object properties 53370fa39dSKudo Chien 54370fa39dSKudo Chien /** 559bc9ec42STomasz Sapeta \return a bool whether the object has a property with the given name. 56370fa39dSKudo Chien */ 579bc9ec42STomasz Sapeta - (BOOL)hasProperty:(nonnull NSString *)name; 58370fa39dSKudo Chien 59370fa39dSKudo Chien /** 609bc9ec42STomasz Sapeta \return the property of the object with the given name. 619bc9ec42STomasz Sapeta If the name isn't a property on the object, returns the `undefined` value. 62370fa39dSKudo Chien */ 639bc9ec42STomasz Sapeta - (nonnull EXJavaScriptValue *)getProperty:(nonnull NSString *)name; 649bc9ec42STomasz Sapeta 659bc9ec42STomasz Sapeta /** 669bc9ec42STomasz Sapeta \return an array consisting of all enumerable property names in the object and its prototype chain. 679bc9ec42STomasz Sapeta */ 689bc9ec42STomasz Sapeta - (nonnull NSArray<NSString *> *)getPropertyNames; 699bc9ec42STomasz Sapeta 709bc9ec42STomasz Sapeta #pragma mark - Modifying object properties 719bc9ec42STomasz Sapeta 729bc9ec42STomasz Sapeta /** 739bc9ec42STomasz Sapeta Sets the value for the property with the given name. 749bc9ec42STomasz Sapeta */ 759bc9ec42STomasz Sapeta - (void)setProperty:(nonnull NSString *)name value:(nullable id)value; 769bc9ec42STomasz Sapeta 779bc9ec42STomasz Sapeta /** 78ce45e284STomasz Sapeta Defines a new property or modifies an existing property on the object using the property descriptor. 79ce45e284STomasz Sapeta */ 80ce45e284STomasz Sapeta - (void)defineProperty:(nonnull NSString *)name descriptor:(nonnull EXJavaScriptObject *)descriptor; 81ce45e284STomasz Sapeta 82ce45e284STomasz Sapeta /** 839bc9ec42STomasz Sapeta Defines a new property or modifies an existing property on the object. Calls `Object.defineProperty` under the hood. 849bc9ec42STomasz Sapeta */ 859bc9ec42STomasz Sapeta - (void)defineProperty:(nonnull NSString *)name value:(nullable id)value options:(EXJavaScriptObjectPropertyDescriptor)options; 86370fa39dSKudo Chien 8778516026STomasz Sapeta #pragma mark - WeakObject 8878516026STomasz Sapeta 8978516026STomasz Sapeta - (nonnull EXJavaScriptWeakObject *)createWeak; 9078516026STomasz Sapeta 9178516026STomasz Sapeta #pragma mark - Deallocator 9278516026STomasz Sapeta 9378516026STomasz Sapeta - (void)setObjectDeallocator:(void (^ _Nonnull)(void))deallocatorBlock; 9478516026STomasz Sapeta 95370fa39dSKudo Chien @end 96