]>
git.saurik.com Git - apple/javascriptcore.git/blob - API/JSValueRef.h
1 // -*- mode: c++; c-basic-offset: 4 -*-
3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <JavaScriptCore/JSBase.h>
36 @abstract A constant identifying the type of a JSValue.
37 @constant kJSTypeUndefined The unique undefined value.
38 @constant kJSTypeNull The unique null value.
39 @constant kJSTypeBoolean A primitive boolean value, one of true or false.
40 @constant kJSTypeNumber A primitive number value.
41 @constant kJSTypeString A primitive string value.
42 @constant kJSTypeObject An object value (meaning that this JSValueRef is a JSObjectRef).
59 @abstract Returns a JavaScript value's type.
60 @param ctx The execution context to use.
61 @param value The JSValue whose type you want to obtain.
62 @result A value of type JSType that identifies value's type.
64 JS_EXPORT JSType
JSValueGetType ( JSContextRef ctx
, JSValueRef value
);
68 @abstract Tests whether a JavaScript value's type is the undefined type.
69 @param ctx The execution context to use.
70 @param value The JSValue to test.
71 @result true if value's type is the undefined type, otherwise false.
73 JS_EXPORT
bool JSValueIsUndefined ( JSContextRef ctx
, JSValueRef value
);
77 @abstract Tests whether a JavaScript value's type is the null type.
78 @param ctx The execution context to use.
79 @param value The JSValue to test.
80 @result true if value's type is the null type, otherwise false.
82 JS_EXPORT
bool JSValueIsNull ( JSContextRef ctx
, JSValueRef value
);
86 @abstract Tests whether a JavaScript value's type is the boolean type.
87 @param ctx The execution context to use.
88 @param value The JSValue to test.
89 @result true if value's type is the boolean type, otherwise false.
91 JS_EXPORT
bool JSValueIsBoolean ( JSContextRef ctx
, JSValueRef value
);
95 @abstract Tests whether a JavaScript value's type is the number type.
96 @param ctx The execution context to use.
97 @param value The JSValue to test.
98 @result true if value's type is the number type, otherwise false.
100 JS_EXPORT
bool JSValueIsNumber ( JSContextRef ctx
, JSValueRef value
);
104 @abstract Tests whether a JavaScript value's type is the string type.
105 @param ctx The execution context to use.
106 @param value The JSValue to test.
107 @result true if value's type is the string type, otherwise false.
109 JS_EXPORT
bool JSValueIsString ( JSContextRef ctx
, JSValueRef value
);
113 @abstract Tests whether a JavaScript value's type is the object type.
114 @param ctx The execution context to use.
115 @param value The JSValue to test.
116 @result true if value's type is the object type, otherwise false.
118 JS_EXPORT
bool JSValueIsObject ( JSContextRef ctx
, JSValueRef value
);
122 @abstract Tests whether a JavaScript value is an object with a given class in its class chain.
123 @param ctx The execution context to use.
124 @param value The JSValue to test.
125 @param jsClass The JSClass to test against.
126 @result true if value is an object and has jsClass in its class chain, otherwise false.
128 JS_EXPORT
bool JSValueIsObjectOfClass ( JSContextRef ctx
, JSValueRef value
, JSClassRef jsClass
);
134 @abstract Tests whether two JavaScript values are equal, as compared by the JS == operator.
135 @param ctx The execution context to use.
136 @param a The first value to test.
137 @param b The second value to test.
138 @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.
139 @result true if the two values are equal, false if they are not equal or an exception is thrown.
141 JS_EXPORT
bool JSValueIsEqual ( JSContextRef ctx
, JSValueRef a
, JSValueRef b
, JSValueRef
* exception
);
145 @abstract Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
146 @param ctx The execution context to use.
147 @param a The first value to test.
148 @param b The second value to test.
149 @result true if the two values are strict equal, otherwise false.
151 JS_EXPORT
bool JSValueIsStrictEqual ( JSContextRef ctx
, JSValueRef a
, JSValueRef b
);
155 @abstract Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the JS instanceof operator.
156 @param ctx The execution context to use.
157 @param value The JSValue to test.
158 @param constructor The constructor to test against.
159 @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.
160 @result true if value is an object constructed by constructor, as compared by the JS instanceof operator, otherwise false.
162 JS_EXPORT
bool JSValueIsInstanceOfConstructor ( JSContextRef ctx
, JSValueRef value
, JSObjectRef constructor
, JSValueRef
* exception
);
168 @abstract Creates a JavaScript value of the undefined type.
169 @param ctx The execution context to use.
170 @result The unique undefined value.
172 JS_EXPORT JSValueRef
JSValueMakeUndefined ( JSContextRef ctx
);
176 @abstract Creates a JavaScript value of the null type.
177 @param ctx The execution context to use.
178 @result The unique null value.
180 JS_EXPORT JSValueRef
JSValueMakeNull ( JSContextRef ctx
);
184 @abstract Creates a JavaScript value of the boolean type.
185 @param ctx The execution context to use.
186 @param boolean The bool to assign to the newly created JSValue.
187 @result A JSValue of the boolean type, representing the value of boolean.
189 JS_EXPORT JSValueRef
JSValueMakeBoolean ( JSContextRef ctx
, bool boolean
);
193 @abstract Creates a JavaScript value of the number type.
194 @param ctx The execution context to use.
195 @param number The double to assign to the newly created JSValue.
196 @result A JSValue of the number type, representing the value of number.
198 JS_EXPORT JSValueRef
JSValueMakeNumber ( JSContextRef ctx
, double number
);
202 @abstract Creates a JavaScript value of the string type.
203 @param ctx The execution context to use.
204 @param string The JSString to assign to the newly created JSValue. The
205 newly created JSValue retains string, and releases it upon garbage collection.
206 @result A JSValue of the string type, representing the value of string.
208 JS_EXPORT JSValueRef
JSValueMakeString ( JSContextRef ctx
, JSStringRef string
);
210 // Converting to primitive values
214 @abstract Converts a JavaScript value to boolean and returns the resulting boolean.
215 @param ctx The execution context to use.
216 @param value The JSValue to convert.
217 @result The boolean result of conversion.
219 JS_EXPORT
bool JSValueToBoolean ( JSContextRef ctx
, JSValueRef value
);
223 @abstract Converts a JavaScript value to number and returns the resulting number.
224 @param ctx The execution context to use.
225 @param value The JSValue to convert.
226 @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.
227 @result The numeric result of conversion, or NaN if an exception is thrown.
229 JS_EXPORT
double JSValueToNumber ( JSContextRef ctx
, JSValueRef value
, JSValueRef
* exception
);
233 @abstract Converts a JavaScript value to string and copies the result into a JavaScript string.
234 @param ctx The execution context to use.
235 @param value The JSValue to convert.
236 @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.
237 @result A JSString with the result of conversion, or NULL if an exception is thrown. Ownership follows the Create Rule.
239 JS_EXPORT JSStringRef
JSValueToStringCopy ( JSContextRef ctx
, JSValueRef value
, JSValueRef
* exception
);
243 @abstract Converts a JavaScript value to object and returns the resulting object.
244 @param ctx The execution context to use.
245 @param value The JSValue to convert.
246 @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.
247 @result The JSObject result of conversion, or NULL if an exception is thrown.
249 JS_EXPORT JSObjectRef
JSValueToObject ( JSContextRef ctx
, JSValueRef value
, JSValueRef
* exception
);
251 // Garbage collection
254 @abstract Protects a JavaScript value from garbage collection.
255 @param ctx The execution context to use.
256 @param value The JSValue to protect.
257 @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.
259 A value may be protected multiple times and must be unprotected an equal number of times before becoming eligible for garbage collection.
261 JS_EXPORT
void JSValueProtect ( JSContextRef ctx
, JSValueRef value
);
265 @abstract Unprotects a JavaScript value from garbage collection.
266 @param ctx The execution context to use.
267 @param value The JSValue to unprotect.
268 @discussion A value may be protected multiple times and must be unprotected an
269 equal number of times before becoming eligible for garbage collection.
271 JS_EXPORT
void JSValueUnprotect ( JSContextRef ctx
, JSValueRef value
);
277 #endif // JSValueRef_h