]>
git.saurik.com Git - apple/javascriptcore.git/blob - API/JSValueRef.h
2 * Copyright (C) 2006 Apple Computer, 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 COMPUTER, 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 COMPUTER, 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>
37 @abstract A constant identifying the type of a JSValue.
38 @constant kJSTypeUndefined The unique undefined value.
39 @constant kJSTypeNull The unique null value.
40 @constant kJSTypeBoolean A primitive boolean value, one of true or false.
41 @constant kJSTypeNumber A primitive number value.
42 @constant kJSTypeString A primitive string value.
43 @constant kJSTypeObject An object value (meaning that this JSValueRef is a JSObjectRef).
60 @abstract Returns a JavaScript value's type.
61 @param ctx The execution context to use.
62 @param value The JSValue whose type you want to obtain.
63 @result A value of type JSType that identifies value's type.
65 JS_EXPORT JSType
JSValueGetType ( JSContextRef ctx
, JSValueRef value
);
69 @abstract Tests whether a JavaScript value's type is the undefined type.
70 @param ctx The execution context to use.
71 @param value The JSValue to test.
72 @result true if value's type is the undefined type, otherwise false.
74 JS_EXPORT
bool JSValueIsUndefined ( JSContextRef ctx
, JSValueRef value
);
78 @abstract Tests whether a JavaScript value's type is the null type.
79 @param ctx The execution context to use.
80 @param value The JSValue to test.
81 @result true if value's type is the null type, otherwise false.
83 JS_EXPORT
bool JSValueIsNull ( JSContextRef ctx
, JSValueRef value
);
87 @abstract Tests whether a JavaScript value's type is the boolean type.
88 @param ctx The execution context to use.
89 @param value The JSValue to test.
90 @result true if value's type is the boolean type, otherwise false.
92 JS_EXPORT
bool JSValueIsBoolean ( JSContextRef ctx
, JSValueRef value
);
96 @abstract Tests whether a JavaScript value's type is the number type.
97 @param ctx The execution context to use.
98 @param value The JSValue to test.
99 @result true if value's type is the number type, otherwise false.
101 JS_EXPORT
bool JSValueIsNumber ( JSContextRef ctx
, JSValueRef value
);
105 @abstract Tests whether a JavaScript value's type is the string type.
106 @param ctx The execution context to use.
107 @param value The JSValue to test.
108 @result true if value's type is the string type, otherwise false.
110 JS_EXPORT
bool JSValueIsString ( JSContextRef ctx
, JSValueRef value
);
114 @abstract Tests whether a JavaScript value's type is the object type.
115 @param ctx The execution context to use.
116 @param value The JSValue to test.
117 @result true if value's type is the object type, otherwise false.
119 JS_EXPORT
bool JSValueIsObject ( JSContextRef ctx
, JSValueRef value
);
123 @abstract Tests whether a JavaScript value is an object with a given class in its class chain.
124 @param ctx The execution context to use.
125 @param value The JSValue to test.
126 @param jsClass The JSClass to test against.
127 @result true if value is an object and has jsClass in its class chain, otherwise false.
129 JS_EXPORT
bool JSValueIsObjectOfClass ( JSContextRef ctx
, JSValueRef value
, JSClassRef jsClass
);
131 /* Comparing values */
135 @abstract Tests whether two JavaScript values are equal, as compared by the JS == operator.
136 @param ctx The execution context to use.
137 @param a The first value to test.
138 @param b The second value to test.
139 @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.
140 @result true if the two values are equal, false if they are not equal or an exception is thrown.
142 JS_EXPORT
bool JSValueIsEqual ( JSContextRef ctx
, JSValueRef a
, JSValueRef b
, JSValueRef
* exception
);
146 @abstract Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
147 @param ctx The execution context to use.
148 @param a The first value to test.
149 @param b The second value to test.
150 @result true if the two values are strict equal, otherwise false.
152 JS_EXPORT
bool JSValueIsStrictEqual ( JSContextRef ctx
, JSValueRef a
, JSValueRef b
);
156 @abstract Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the JS instanceof operator.
157 @param ctx The execution context to use.
158 @param value The JSValue to test.
159 @param constructor The constructor to test against.
160 @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.
161 @result true if value is an object constructed by constructor, as compared by the JS instanceof operator, otherwise false.
163 JS_EXPORT
bool JSValueIsInstanceOfConstructor ( JSContextRef ctx
, JSValueRef value
, JSObjectRef constructor
, JSValueRef
* exception
);
165 /* Creating values */
169 @abstract Creates a JavaScript value of the undefined type.
170 @param ctx The execution context to use.
171 @result The unique undefined value.
173 JS_EXPORT JSValueRef
JSValueMakeUndefined ( JSContextRef ctx
);
177 @abstract Creates a JavaScript value of the null type.
178 @param ctx The execution context to use.
179 @result The unique null value.
181 JS_EXPORT JSValueRef
JSValueMakeNull ( JSContextRef ctx
);
185 @abstract Creates a JavaScript value of the boolean type.
186 @param ctx The execution context to use.
187 @param boolean The bool to assign to the newly created JSValue.
188 @result A JSValue of the boolean type, representing the value of boolean.
190 JS_EXPORT JSValueRef
JSValueMakeBoolean ( JSContextRef ctx
, bool boolean
);
194 @abstract Creates a JavaScript value of the number type.
195 @param ctx The execution context to use.
196 @param number The double to assign to the newly created JSValue.
197 @result A JSValue of the number type, representing the value of number.
199 JS_EXPORT JSValueRef
JSValueMakeNumber ( JSContextRef ctx
, double number
);
203 @abstract Creates a JavaScript value of the string type.
204 @param ctx The execution context to use.
205 @param string The JSString to assign to the newly created JSValue. The
206 newly created JSValue retains string, and releases it upon garbage collection.
207 @result A JSValue of the string type, representing the value of string.
209 JS_EXPORT JSValueRef
JSValueMakeString ( JSContextRef ctx
, JSStringRef string
);
211 /* Converting to primitive values */
215 @abstract Converts a JavaScript value to boolean and returns the resulting boolean.
216 @param ctx The execution context to use.
217 @param value The JSValue to convert.
218 @result The boolean result of conversion.
220 JS_EXPORT
bool JSValueToBoolean ( JSContextRef ctx
, JSValueRef value
);
224 @abstract Converts a JavaScript value to number and returns the resulting number.
225 @param ctx The execution context to use.
226 @param value The JSValue to convert.
227 @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.
228 @result The numeric result of conversion, or NaN if an exception is thrown.
230 JS_EXPORT
double JSValueToNumber ( JSContextRef ctx
, JSValueRef value
, JSValueRef
* exception
);
234 @abstract Converts a JavaScript value to string and copies the result into a JavaScript string.
235 @param ctx The execution context to use.
236 @param value The JSValue to convert.
237 @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.
238 @result A JSString with the result of conversion, or NULL if an exception is thrown. Ownership follows the Create Rule.
240 JS_EXPORT JSStringRef
JSValueToStringCopy ( JSContextRef ctx
, JSValueRef value
, JSValueRef
* exception
);
244 @abstract Converts a JavaScript value to object and returns the resulting object.
245 @param ctx The execution context to use.
246 @param value The JSValue to convert.
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 The JSObject result of conversion, or NULL if an exception is thrown.
250 JS_EXPORT JSObjectRef
JSValueToObject ( JSContextRef ctx
, JSValueRef value
, JSValueRef
* exception
);
252 /* Garbage collection */
255 @abstract Protects a JavaScript value from garbage collection.
256 @param ctx The execution context to use.
257 @param value The JSValue to protect.
258 @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.
260 A value may be protected multiple times and must be unprotected an equal number of times before becoming eligible for garbage collection.
262 JS_EXPORT
void JSValueProtect ( JSContextRef ctx
, JSValueRef value
);
266 @abstract Unprotects a JavaScript value from garbage collection.
267 @param ctx The execution context to use.
268 @param value The JSValue to unprotect.
269 @discussion A value may be protected multiple times and must be unprotected an
270 equal number of times before becoming eligible for garbage collection.
272 JS_EXPORT
void JSValueUnprotect ( JSContextRef ctx
, JSValueRef value
);
278 #endif /* JSValueRef_h */