]>
git.saurik.com Git - apple/javascriptcore.git/blob - API/JSValueRef.h
2 * Copyright (C) 2006 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <JavaScriptCore/JSBase.h>
30 #include <JavaScriptCore/WebKitAvailability.h>
38 @abstract A constant identifying the type of a JSValue.
39 @constant kJSTypeUndefined The unique undefined value.
40 @constant kJSTypeNull The unique null value.
41 @constant kJSTypeBoolean A primitive boolean value, one of true or false.
42 @constant kJSTypeNumber A primitive number value.
43 @constant kJSTypeString A primitive string value.
44 @constant kJSTypeObject An object value (meaning that this JSValueRef is a JSObjectRef).
61 @abstract Returns a JavaScript value's type.
62 @param ctx The execution context to use.
63 @param value The JSValue whose type you want to obtain.
64 @result A value of type JSType that identifies value's type.
66 JS_EXPORT JSType
JSValueGetType ( JSContextRef ctx
, JSValueRef
);
70 @abstract Tests whether a JavaScript value's type is the undefined type.
71 @param ctx The execution context to use.
72 @param value The JSValue to test.
73 @result true if value's type is the undefined type, otherwise false.
75 JS_EXPORT
bool JSValueIsUndefined ( JSContextRef ctx
, JSValueRef value
);
79 @abstract Tests whether a JavaScript value's type is the null type.
80 @param ctx The execution context to use.
81 @param value The JSValue to test.
82 @result true if value's type is the null type, otherwise false.
84 JS_EXPORT
bool JSValueIsNull ( JSContextRef ctx
, JSValueRef value
);
88 @abstract Tests whether a JavaScript value's type is the boolean type.
89 @param ctx The execution context to use.
90 @param value The JSValue to test.
91 @result true if value's type is the boolean type, otherwise false.
93 JS_EXPORT
bool JSValueIsBoolean ( JSContextRef ctx
, JSValueRef value
);
97 @abstract Tests whether a JavaScript value's type is the number type.
98 @param ctx The execution context to use.
99 @param value The JSValue to test.
100 @result true if value's type is the number type, otherwise false.
102 JS_EXPORT
bool JSValueIsNumber ( JSContextRef ctx
, JSValueRef value
);
106 @abstract Tests whether a JavaScript value's type is the string type.
107 @param ctx The execution context to use.
108 @param value The JSValue to test.
109 @result true if value's type is the string type, otherwise false.
111 JS_EXPORT
bool JSValueIsString ( JSContextRef ctx
, JSValueRef value
);
115 @abstract Tests whether a JavaScript value's type is the object type.
116 @param ctx The execution context to use.
117 @param value The JSValue to test.
118 @result true if value's type is the object type, otherwise false.
120 JS_EXPORT
bool JSValueIsObject ( JSContextRef ctx
, JSValueRef value
);
124 @abstract Tests whether a JavaScript value is an object with a given class in its class chain.
125 @param ctx The execution context to use.
126 @param value The JSValue to test.
127 @param jsClass The JSClass to test against.
128 @result true if value is an object and has jsClass in its class chain, otherwise false.
130 JS_EXPORT
bool JSValueIsObjectOfClass ( JSContextRef ctx
, JSValueRef value
, JSClassRef jsClass
);
134 @abstract Tests whether a JavaScript value is an array.
135 @param ctx The execution context to use.
136 @param value The JSValue to test.
137 @result true if value is an array, otherwise false.
139 JS_EXPORT
bool JSValueIsArray ( JSContextRef ctx
, JSValueRef value
) CF_AVAILABLE ( 10 _11
, 9 _0
);
143 @abstract Tests whether a JavaScript value is a date.
144 @param ctx The execution context to use.
145 @param value The JSValue to test.
146 @result true if value is a date, otherwise false.
148 JS_EXPORT
bool JSValueIsDate ( JSContextRef ctx
, JSValueRef value
) CF_AVAILABLE ( 10 _11
, 9 _0
);
150 /* Comparing values */
154 @abstract Tests whether two JavaScript values are equal, as compared by the JS == operator.
155 @param ctx The execution context to use.
156 @param a The first value to test.
157 @param b The second value to test.
158 @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.
159 @result true if the two values are equal, false if they are not equal or an exception is thrown.
161 JS_EXPORT
bool JSValueIsEqual ( JSContextRef ctx
, JSValueRef a
, JSValueRef b
, JSValueRef
* exception
);
165 @abstract Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
166 @param ctx The execution context to use.
167 @param a The first value to test.
168 @param b The second value to test.
169 @result true if the two values are strict equal, otherwise false.
171 JS_EXPORT
bool JSValueIsStrictEqual ( JSContextRef ctx
, JSValueRef a
, JSValueRef b
);
175 @abstract Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the JS instanceof operator.
176 @param ctx The execution context to use.
177 @param value The JSValue to test.
178 @param constructor The constructor to test against.
179 @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.
180 @result true if value is an object constructed by constructor, as compared by the JS instanceof operator, otherwise false.
182 JS_EXPORT
bool JSValueIsInstanceOfConstructor ( JSContextRef ctx
, JSValueRef value
, JSObjectRef constructor
, JSValueRef
* exception
);
184 /* Creating values */
188 @abstract Creates a JavaScript value of the undefined type.
189 @param ctx The execution context to use.
190 @result The unique undefined value.
192 JS_EXPORT JSValueRef
JSValueMakeUndefined ( JSContextRef ctx
);
196 @abstract Creates a JavaScript value of the null type.
197 @param ctx The execution context to use.
198 @result The unique null value.
200 JS_EXPORT JSValueRef
JSValueMakeNull ( JSContextRef ctx
);
204 @abstract Creates a JavaScript value of the boolean type.
205 @param ctx The execution context to use.
206 @param boolean The bool to assign to the newly created JSValue.
207 @result A JSValue of the boolean type, representing the value of boolean.
209 JS_EXPORT JSValueRef
JSValueMakeBoolean ( JSContextRef ctx
, bool boolean
);
213 @abstract Creates a JavaScript value of the number type.
214 @param ctx The execution context to use.
215 @param number The double to assign to the newly created JSValue.
216 @result A JSValue of the number type, representing the value of number.
218 JS_EXPORT JSValueRef
JSValueMakeNumber ( JSContextRef ctx
, double number
);
222 @abstract Creates a JavaScript value of the string type.
223 @param ctx The execution context to use.
224 @param string The JSString to assign to the newly created JSValue. The
225 newly created JSValue retains string, and releases it upon garbage collection.
226 @result A JSValue of the string type, representing the value of string.
228 JS_EXPORT JSValueRef
JSValueMakeString ( JSContextRef ctx
, JSStringRef string
);
230 /* Converting to and from JSON formatted strings */
234 @abstract Creates a JavaScript value from a JSON formatted string.
235 @param ctx The execution context to use.
236 @param string The JSString containing the JSON string to be parsed.
237 @result A JSValue containing the parsed value, or NULL if the input is invalid.
239 JS_EXPORT JSValueRef
JSValueMakeFromJSONString ( JSContextRef ctx
, JSStringRef string
) CF_AVAILABLE ( 10 _7
, 7 _0
);
243 @abstract Creates a JavaScript string containing the JSON serialized representation of a JS value.
244 @param ctx The execution context to use.
245 @param value The value to serialize.
246 @param indent The number of spaces to indent when nesting. If 0, the resulting JSON will not contains newlines. The size of the indent is clamped to 10 spaces.
247 @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.
248 @result A JSString with the result of serialization, or NULL if an exception is thrown.
250 JS_EXPORT JSStringRef
JSValueCreateJSONString ( JSContextRef ctx
, JSValueRef value
, unsigned indent
, JSValueRef
* exception
) CF_AVAILABLE ( 10 _7
, 7 _0
);
252 /* Converting to primitive values */
256 @abstract Converts a JavaScript value to boolean and returns the resulting boolean.
257 @param ctx The execution context to use.
258 @param value The JSValue to convert.
259 @result The boolean result of conversion.
261 JS_EXPORT
bool JSValueToBoolean ( JSContextRef ctx
, JSValueRef value
);
265 @abstract Converts a JavaScript value to number and returns the resulting number.
266 @param ctx The execution context to use.
267 @param value The JSValue to convert.
268 @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.
269 @result The numeric result of conversion, or NaN if an exception is thrown.
271 JS_EXPORT
double JSValueToNumber ( JSContextRef ctx
, JSValueRef value
, JSValueRef
* exception
);
275 @abstract Converts a JavaScript value to string and copies the result into a JavaScript string.
276 @param ctx The execution context to use.
277 @param value The JSValue to convert.
278 @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.
279 @result A JSString with the result of conversion, or NULL if an exception is thrown. Ownership follows the Create Rule.
281 JS_EXPORT JSStringRef
JSValueToStringCopy ( JSContextRef ctx
, JSValueRef value
, JSValueRef
* exception
);
285 @abstract Converts a JavaScript value to object and returns the resulting object.
286 @param ctx The execution context to use.
287 @param value The JSValue to convert.
288 @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.
289 @result The JSObject result of conversion, or NULL if an exception is thrown.
291 JS_EXPORT JSObjectRef
JSValueToObject ( JSContextRef ctx
, JSValueRef value
, JSValueRef
* exception
);
293 /* Garbage collection */
296 @abstract Protects a JavaScript value from garbage collection.
297 @param ctx The execution context to use.
298 @param value The JSValue to protect.
299 @discussion Use this method when you want to store a JSValue in a global or on the heap, where the garbage collector will not be able to discover your reference to it.
301 A value may be protected multiple times and must be unprotected an equal number of times before becoming eligible for garbage collection.
303 JS_EXPORT
void JSValueProtect ( JSContextRef ctx
, JSValueRef value
);
307 @abstract Unprotects a JavaScript value from garbage collection.
308 @param ctx The execution context to use.
309 @param value The JSValue to unprotect.
310 @discussion A value may be protected multiple times and must be unprotected an
311 equal number of times before becoming eligible for garbage collection.
313 JS_EXPORT
void JSValueUnprotect ( JSContextRef ctx
, JSValueRef value
);
319 #endif /* JSValueRef_h */