1 // Copyright 2022-present 650 Industries. All rights reserved. 2 3 #import <Foundation/Foundation.h> 4 5 #ifdef __cplusplus 6 #import <jsi/jsi.h> 7 8 namespace jsi = facebook::jsi; 9 #endif // __cplusplus 10 11 @class EXJavaScriptRuntime; 12 @class EXJavaScriptValue; 13 14 /** 15 The property descriptor options for the property being defined or modified. 16 */ 17 typedef NS_OPTIONS(NSInteger, EXJavaScriptObjectPropertyDescriptor) { 18 /** 19 If set, the type of this property descriptor may be changed and if the property may be deleted from the corresponding object. 20 */ 21 EXJavaScriptObjectPropertyDescriptorConfigurable = 1 << 0, 22 /** 23 If set, the property shows up during enumeration of the properties on the corresponding object. 24 */ 25 EXJavaScriptObjectPropertyDescriptorEnumerable = 1 << 1, 26 /** 27 If set, the value associated with the property may be changed with an assignment operator. 28 */ 29 EXJavaScriptObjectPropertyDescriptorWritable = 1 << 2, 30 } NS_SWIFT_NAME(JavaScriptObjectPropertyDescriptor); 31 32 NS_SWIFT_NAME(JavaScriptObject) 33 @interface EXJavaScriptObject : NSObject 34 35 // Some parts of the interface must be hidden for Swift – it can't import any C++ code. 36 #ifdef __cplusplus 37 - (nonnull instancetype)initWith:(std::shared_ptr<jsi::Object>)jsObjectPtr 38 runtime:(nonnull EXJavaScriptRuntime *)runtime; 39 40 /** 41 Returns the pointer to the underlying object. 42 */ 43 - (nonnull jsi::Object *)get; 44 #endif // __cplusplus 45 46 #pragma mark - Accessing object properties 47 48 /** 49 \return a bool whether the object has a property with the given name. 50 */ 51 - (BOOL)hasProperty:(nonnull NSString *)name; 52 53 /** 54 \return the property of the object with the given name. 55 If the name isn't a property on the object, returns the `undefined` value. 56 */ 57 - (nonnull EXJavaScriptValue *)getProperty:(nonnull NSString *)name; 58 59 /** 60 \return an array consisting of all enumerable property names in the object and its prototype chain. 61 */ 62 - (nonnull NSArray<NSString *> *)getPropertyNames; 63 64 #pragma mark - Modifying object properties 65 66 /** 67 Sets the value for the property with the given name. 68 */ 69 - (void)setProperty:(nonnull NSString *)name value:(nullable id)value; 70 71 /** 72 Defines a new property or modifies an existing property on the object. Calls `Object.defineProperty` under the hood. 73 */ 74 - (void)defineProperty:(nonnull NSString *)name value:(nullable id)value options:(EXJavaScriptObjectPropertyDescriptor)options; 75 76 @end 77