| 1 | /* |
| 2 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #ifndef JSObjectRefPrivate_h |
| 27 | #define JSObjectRefPrivate_h |
| 28 | |
| 29 | #include <JavaScriptCore/JSObjectRef.h> |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | /*! |
| 36 | @function |
| 37 | @abstract Sets a private property on an object. This private property cannot be accessed from within JavaScript. |
| 38 | @param ctx The execution context to use. |
| 39 | @param object The JSObject whose private property you want to set. |
| 40 | @param propertyName A JSString containing the property's name. |
| 41 | @param value A JSValue to use as the property's value. This may be NULL. |
| 42 | @result true if object can store private data, otherwise false. |
| 43 | @discussion This API allows you to store JS values directly an object in a way that will be ensure that they are kept alive without exposing them to JavaScript code and without introducing the reference cycles that may occur when using JSValueProtect. |
| 44 | |
| 45 | The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private properties. |
| 46 | */ |
| 47 | JS_EXPORT bool JSObjectSetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value); |
| 48 | |
| 49 | /*! |
| 50 | @function |
| 51 | @abstract Gets a private property from an object. |
| 52 | @param ctx The execution context to use. |
| 53 | @param object The JSObject whose private property you want to get. |
| 54 | @param propertyName A JSString containing the property's name. |
| 55 | @result The property's value if object has the property, otherwise NULL. |
| 56 | */ |
| 57 | JS_EXPORT JSValueRef JSObjectGetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); |
| 58 | |
| 59 | /*! |
| 60 | @function |
| 61 | @abstract Deletes a private property from an object. |
| 62 | @param ctx The execution context to use. |
| 63 | @param object The JSObject whose private property you want to delete. |
| 64 | @param propertyName A JSString containing the property's name. |
| 65 | @result true if object can store private data, otherwise false. |
| 66 | @discussion The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data. |
| 67 | */ |
| 68 | JS_EXPORT bool JSObjectDeletePrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); |
| 69 | |
| 70 | JS_EXPORT JSObjectRef JSObjectGetProxyTarget(JSObjectRef); |
| 71 | |
| 72 | JS_EXPORT JSGlobalContextRef JSObjectGetGlobalContext(JSObjectRef object); |
| 73 | |
| 74 | /*! |
| 75 | @function |
| 76 | @abstract Creates a JavaScript promise object by invoking the provided executor. |
| 77 | @param ctx The execution context to use. |
| 78 | @param resolve A pointer to a JSObjectRef in which to store the resolve function for the new promise. Pass NULL if you do not care to store the resolve callback. |
| 79 | @param reject A pointer to a JSObjectRef in which to store the reject function for the new promise. Pass NULL if you do not care to store the reject callback. |
| 80 | @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. |
| 81 | @result A JSObject that is a promise or NULL if an exception occurred. |
| 82 | */ |
| 83 | JS_EXPORT JSObjectRef JSObjectMakeDeferredPromise(JSContextRef ctx, JSObjectRef* resolve, JSObjectRef* reject, JSValueRef* exception) JSC_API_AVAILABLE(macos(JSC_MAC_TBA), ios(JSC_IOS_TBA)); |
| 84 | |
| 85 | /*! |
| 86 | @function |
| 87 | @abstract Tests whether an object has a given property using a JSValueRef as the property key. |
| 88 | @param object The JSObject to test. |
| 89 | @param propertyKey A JSValueRef containing the property key to use when looking up the property. |
| 90 | @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. |
| 91 | @result true if the object has a property whose name matches propertyKey, otherwise false. |
| 92 | @discussion This function is the same as performing "propertyKey in object" from JavaScript. |
| 93 | */ |
| 94 | JS_EXPORT bool JSObjectHasPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macos(JSC_MAC_TBA), ios(JSC_IOS_TBA)); |
| 95 | |
| 96 | /*! |
| 97 | @function |
| 98 | @abstract Gets a property from an object using a JSValueRef as the property key. |
| 99 | @param ctx The execution context to use. |
| 100 | @param object The JSObject whose property you want to get. |
| 101 | @param propertyKey A JSValueRef containing the property key to use when looking up the property. |
| 102 | @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. |
| 103 | @result The property's value if object has the property key, otherwise the undefined value. |
| 104 | @discussion This function is the same as performing "object[propertyKey]" from JavaScript. |
| 105 | */ |
| 106 | JS_EXPORT JSValueRef JSObjectGetPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macos(JSC_MAC_TBA), ios(JSC_IOS_TBA)); |
| 107 | |
| 108 | /*! |
| 109 | @function |
| 110 | @abstract Sets a property on an object using a JSValueRef as the property key. |
| 111 | @param ctx The execution context to use. |
| 112 | @param object The JSObject whose property you want to set. |
| 113 | @param propertyKey A JSValueRef containing the property key to use when looking up the property. |
| 114 | @param value A JSValueRef to use as the property's value. |
| 115 | @param attributes A logically ORed set of JSPropertyAttributes to give to the property. |
| 116 | @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. |
| 117 | @discussion This function is the same as performing "object[propertyKey] = value" from JavaScript. |
| 118 | */ |
| 119 | JS_EXPORT void JSObjectSetPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception) JSC_API_AVAILABLE(macos(JSC_MAC_TBA), ios(JSC_IOS_TBA)); |
| 120 | |
| 121 | /*! |
| 122 | @function |
| 123 | @abstract Deletes a property from an object using a JSValueRef as the property key. |
| 124 | @param ctx The execution context to use. |
| 125 | @param object The JSObject whose property you want to delete. |
| 126 | @param propertyKey A JSValueRef containing the property key to use when looking up the property. |
| 127 | @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. |
| 128 | @result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set). |
| 129 | @discussion This function is the same as performing "delete object[propertyKey]" from JavaScript. |
| 130 | */ |
| 131 | JS_EXPORT bool JSObjectDeletePropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macos(JSC_MAC_TBA), ios(JSC_IOS_TBA)); |
| 132 | |
| 133 | /*! |
| 134 | @function |
| 135 | @abstract Creates a JavaScript value of the symbol type. |
| 136 | @param ctx The execution context to use. |
| 137 | @param description A description of the newly created symbol value. |
| 138 | @result A unique JSValue of the symbol type, whose description matches the one provided. |
| 139 | */ |
| 140 | JS_EXPORT JSValueRef JSValueMakeSymbol(JSContextRef ctx, JSStringRef description) JSC_API_AVAILABLE(macos(JSC_MAC_TBA), ios(JSC_IOS_TBA)); |
| 141 | |
| 142 | /*! |
| 143 | @function |
| 144 | @abstract Tests whether a JavaScript value's type is the symbol type. |
| 145 | @param ctx The execution context to use. |
| 146 | @param value The JSValue to test. |
| 147 | @result true if value's type is the symbol type, otherwise false. |
| 148 | */ |
| 149 | JS_EXPORT bool JSValueIsSymbol(JSContextRef ctx, JSValueRef value) JSC_API_AVAILABLE(macos(JSC_MAC_TBA), ios(JSC_IOS_TBA)); |
| 150 | |
| 151 | #ifdef __cplusplus |
| 152 | } |
| 153 | #endif |
| 154 | |
| 155 | #endif // JSObjectRefPrivate_h |
| 156 | |