Loading...
Searching...
No Matches
JSValueRef.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006-2019 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. ``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.
24 */
25
26#ifndef JSValueRef_h
27#define JSValueRef_h
28
31
32#ifndef __cplusplus
33#include <stdbool.h>
34#endif
35
36/*!
37@enum JSType
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).
45@constant kJSTypeSymbol A primitive symbol value.
46*/
56
57/*!
58 @enum JSTypedArrayType
59 @abstract A constant identifying the Typed Array type of a JSObjectRef.
60 @constant kJSTypedArrayTypeInt8Array Int8Array
61 @constant kJSTypedArrayTypeInt16Array Int16Array
62 @constant kJSTypedArrayTypeInt32Array Int32Array
63 @constant kJSTypedArrayTypeUint8Array Uint8Array
64 @constant kJSTypedArrayTypeUint8ClampedArray Uint8ClampedArray
65 @constant kJSTypedArrayTypeUint16Array Uint16Array
66 @constant kJSTypedArrayTypeUint32Array Uint32Array
67 @constant kJSTypedArrayTypeFloat32Array Float32Array
68 @constant kJSTypedArrayTypeFloat64Array Float64Array
69 @constant kJSTypedArrayTypeBigInt64Array BigInt64Array
70 @constant kJSTypedArrayTypeBigUint64Array BigUint64Array
71 @constant kJSTypedArrayTypeArrayBuffer ArrayBuffer
72 @constant kJSTypedArrayTypeNone Not a Typed Array
73
74 */
90
91#ifdef __cplusplus
92extern "C" {
93#endif
94
95/*!
96@function
97@abstract Returns a JavaScript value's type.
98@param ctx The execution context to use.
99@param value The JSValue whose type you want to obtain.
100@result A value of type JSType that identifies value's type.
101*/
103
104/*!
105@function
106@abstract Tests whether a JavaScript value's type is the undefined 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 undefined type, otherwise false.
110*/
112
113/*!
114@function
115@abstract Tests whether a JavaScript value's type is the null 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 null type, otherwise false.
119*/
121
122/*!
123@function
124@abstract Tests whether a JavaScript value's type is the boolean type.
125@param ctx The execution context to use.
126@param value The JSValue to test.
127@result true if value's type is the boolean type, otherwise false.
128*/
130
131/*!
132@function
133@abstract Tests whether a JavaScript value's type is the number type.
134@param ctx The execution context to use.
135@param value The JSValue to test.
136@result true if value's type is the number type, otherwise false.
137*/
139
140/*!
141@function
142@abstract Tests whether a JavaScript value's type is the string type.
143@param ctx The execution context to use.
144@param value The JSValue to test.
145@result true if value's type is the string type, otherwise false.
146*/
148
149/*!
150@function
151@abstract Tests whether a JavaScript value's type is the symbol type.
152@param ctx The execution context to use.
153@param value The JSValue to test.
154@result true if value's type is the symbol type, otherwise false.
155*/
157
158/*!
159@function
160@abstract Tests whether a JavaScript value's type is the object type.
161@param ctx The execution context to use.
162@param value The JSValue to test.
163@result true if value's type is the object type, otherwise false.
164*/
166
167
168/*!
169@function
170@abstract Tests whether a JavaScript value is an object with a given class in its class chain.
171@param ctx The execution context to use.
172@param value The JSValue to test.
173@param jsClass The JSClass to test against.
174@result true if value is an object and has jsClass in its class chain, otherwise false.
175*/
177
178/*!
179@function
180@abstract Tests whether a JavaScript value is an array.
181@param ctx The execution context to use.
182@param value The JSValue to test.
183@result true if value is an array, otherwise false.
184*/
186
187/*!
188@function
189@abstract Tests whether a JavaScript value is a date.
190@param ctx The execution context to use.
191@param value The JSValue to test.
192@result true if value is a date, otherwise false.
193*/
195
196/*!
197@function
198@abstract Returns a JavaScript value's Typed Array type.
199@param ctx The execution context to use.
200@param value The JSValue whose Typed Array type to return.
201@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.
202@result A value of type JSTypedArrayType that identifies value's Typed Array type, or kJSTypedArrayTypeNone if the value is not a Typed Array object.
203 */
205
206/* Comparing values */
207
208/*!
209@function
210@abstract Tests whether two JavaScript values are equal, as compared by the JS == operator.
211@param ctx The execution context to use.
212@param a The first value to test.
213@param b The second value to test.
214@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.
215@result true if the two values are equal, false if they are not equal or an exception is thrown.
216*/
218
219/*!
220@function
221@abstract Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
222@param ctx The execution context to use.
223@param a The first value to test.
224@param b The second value to test.
225@result true if the two values are strict equal, otherwise false.
226*/
228
229/*!
230@function
231@abstract Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the JS instanceof operator.
232@param ctx The execution context to use.
233@param value The JSValue to test.
234@param constructor The constructor to test against.
235@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.
236@result true if value is an object constructed by constructor, as compared by the JS instanceof operator, otherwise false.
237*/
239
240/* Creating values */
241
242/*!
243@function
244@abstract Creates a JavaScript value of the undefined type.
245@param ctx The execution context to use.
246@result The unique undefined value.
247*/
249
250/*!
251@function
252@abstract Creates a JavaScript value of the null type.
253@param ctx The execution context to use.
254@result The unique null value.
255*/
257
258/*!
259@function
260@abstract Creates a JavaScript value of the boolean type.
261@param ctx The execution context to use.
262@param boolean The bool to assign to the newly created JSValue.
263@result A JSValue of the boolean type, representing the value of boolean.
264*/
266
267/*!
268@function
269@abstract Creates a JavaScript value of the number type.
270@param ctx The execution context to use.
271@param number The double to assign to the newly created JSValue.
272@result A JSValue of the number type, representing the value of number.
273*/
275
276/*!
277@function
278@abstract Creates a JavaScript value of the string type.
279@param ctx The execution context to use.
280@param string The JSString to assign to the newly created JSValue. The
281 newly created JSValue retains string, and releases it upon garbage collection.
282@result A JSValue of the string type, representing the value of string.
283*/
285
286/*!
287 @function
288 @abstract Creates a JavaScript value of the symbol type.
289 @param ctx The execution context to use.
290 @param description A description of the newly created symbol value.
291 @result A unique JSValue of the symbol type, whose description matches the one provided.
292 */
294
295/* Converting to and from JSON formatted strings */
296
297/*!
298 @function
299 @abstract Creates a JavaScript value from a JSON formatted string.
300 @param ctx The execution context to use.
301 @param string The JSString containing the JSON string to be parsed.
302 @result A JSValue containing the parsed value, or NULL if the input is invalid.
303 */
305
306/*!
307 @function
308 @abstract Creates a JavaScript string containing the JSON serialized representation of a JS value.
309 @param ctx The execution context to use.
310 @param value The value to serialize.
311 @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.
312 @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.
313 @result A JSString with the result of serialization, or NULL if an exception is thrown.
314 */
315JS_EXPORT JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef value, unsigned indent, JSValueRef* exception) JSC_API_AVAILABLE(macos(10.7), ios(7.0));
316
317/* Converting to primitive values */
318
319/*!
320@function
321@abstract Converts a JavaScript value to boolean and returns the resulting boolean.
322@param ctx The execution context to use.
323@param value The JSValue to convert.
324@result The boolean result of conversion.
325*/
327
328/*!
329@function
330@abstract Converts a JavaScript value to number and returns the resulting number.
331@param ctx The execution context to use.
332@param value The JSValue to convert.
333@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.
334@result The numeric result of conversion, or NaN if an exception is thrown.
335*/
337
338/*!
339@function
340@abstract Converts a JavaScript value to string and copies the result into a JavaScript string.
341@param ctx The execution context to use.
342@param value The JSValue to convert.
343@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.
344@result A JSString with the result of conversion, or NULL if an exception is thrown. Ownership follows the Create Rule.
345*/
347
348/*!
349@function
350@abstract Converts a JavaScript value to object and returns the resulting object.
351@param ctx The execution context to use.
352@param value The JSValue to convert.
353@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.
354@result The JSObject result of conversion, or NULL if an exception is thrown.
355*/
357
358/* Garbage collection */
359/*!
360@function
361@abstract Protects a JavaScript value from garbage collection.
362@param ctx The execution context to use.
363@param value The JSValue to protect.
364@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.
365
366A value may be protected multiple times and must be unprotected an equal number of times before becoming eligible for garbage collection.
367*/
369
370/*!
371@function
372@abstract Unprotects a JavaScript value from garbage collection.
373@param ctx The execution context to use.
374@param value The JSValue to unprotect.
375@discussion A value may be protected multiple times and must be unprotected an
376 equal number of times before becoming eligible for garbage collection.
377*/
379
380#ifdef __cplusplus
381}
382#endif
383
384#endif /* JSValueRef_h */
struct OpaqueJSClass * JSClassRef
Definition JSBase.h:52
struct OpaqueJSString * JSStringRef
Definition JSBase.h:49
struct OpaqueJSValue * JSObjectRef
Definition JSBase.h:69
const struct OpaqueJSValue * JSValueRef
Definition JSBase.h:66
#define JS_EXPORT
Definition JSBase.h:93
const struct OpaqueJSContext * JSContextRef
Definition JSBase.h:43
JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string) JSC_API_AVAILABLE(macos(10.7)
Creates a JavaScript value from a JSON formatted string.
JSTypedArrayType JSValueGetTypedArrayType(JSContextRef ctx, JSValueRef value, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.12)
Returns a JavaScript value's Typed Array type.
bool JSValueIsNumber(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the number type.
JSValueRef JSValueMakeNull(JSContextRef ctx)
Creates a JavaScript value of the null type.
JSValueRef JSValueMakeSymbol(JSContextRef ctx, JSStringRef description) JSC_API_AVAILABLE(macos(10.15)
Creates a JavaScript value of the symbol type.
double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef *exception)
Converts a JavaScript value to number and returns the resulting number.
bool JSValueIsSymbol(JSContextRef ctx, JSValueRef value) JSC_API_AVAILABLE(macos(10.15)
Tests whether a JavaScript value's type is the symbol type.
bool JSValueIsNull(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the null type.
JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef value, unsigned indent, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.7)
Creates a JavaScript string containing the JSON serialized representation of a JS value.
JSValueRef JSValueMakeUndefined(JSContextRef ctx)
Creates a JavaScript value of the undefined type.
void JSValueUnprotect(JSContextRef ctx, JSValueRef value)
Unprotects a JavaScript value from garbage collection.
bool JSValueIsObject(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the object type.
bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef *exception)
Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the ...
bool JSValueIsArray(JSContextRef ctx, JSValueRef value) JSC_API_AVAILABLE(macos(10.11)
Tests whether a JavaScript value is an array.
bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the undefined type.
JSValueRef JSValueMakeNumber(JSContextRef ctx, double number)
Creates a JavaScript value of the number type.
bool JSValueIsDate(JSContextRef ctx, JSValueRef value) JSC_API_AVAILABLE(macos(10.11)
Tests whether a JavaScript value is a date.
bool JSValueIsString(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the string type.
ios(10.0))
bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass)
Tests whether a JavaScript value is an object with a given class in its class chain.
bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b)
Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef *exception)
Converts a JavaScript value to object and returns the resulting object.
JSType
A constant identifying the type of a JSValue.
Definition JSValueRef.h:47
@ kJSTypeNull
Definition JSValueRef.h:49
@ kJSTypeString
Definition JSValueRef.h:52
@ kJSTypeBoolean
Definition JSValueRef.h:50
@ kJSTypeObject
Definition JSValueRef.h:53
@ JSC_API_AVAILABLE
Definition JSValueRef.h:54
@ kJSTypeNumber
Definition JSValueRef.h:51
@ kJSTypeUndefined
Definition JSValueRef.h:48
JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef *exception)
Converts a JavaScript value to string and copies the result into a JavaScript string.
bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef *exception)
Tests whether two JavaScript values are equal, as compared by the JS == operator.
JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
Creates a JavaScript value of the string type.
bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
Converts a JavaScript value to boolean and returns the resulting boolean.
bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the boolean type.
JSTypedArrayType
A constant identifying the Typed Array type of a JSObjectRef.
Definition JSValueRef.h:75
@ kJSTypedArrayTypeUint16Array
Definition JSValueRef.h:81
@ kJSTypedArrayTypeInt32Array
Definition JSValueRef.h:78
@ kJSTypedArrayTypeInt16Array
Definition JSValueRef.h:77
@ kJSTypedArrayTypeNone
Definition JSValueRef.h:86
@ kJSTypedArrayTypeInt8Array
Definition JSValueRef.h:76
@ kJSTypedArrayTypeArrayBuffer
Definition JSValueRef.h:85
@ kJSTypedArrayTypeUint32Array
Definition JSValueRef.h:82
@ kJSTypedArrayTypeBigUint64Array
Definition JSValueRef.h:88
@ kJSTypedArrayTypeUint8ClampedArray
Definition JSValueRef.h:80
@ kJSTypedArrayTypeBigInt64Array
Definition JSValueRef.h:87
@ kJSTypedArrayTypeFloat32Array
Definition JSValueRef.h:83
@ kJSTypedArrayTypeUint8Array
Definition JSValueRef.h:79
@ kJSTypedArrayTypeFloat64Array
Definition JSValueRef.h:84
void JSValueProtect(JSContextRef ctx, JSValueRef value)
Protects a JavaScript value from garbage collection.
JSType JSValueGetType(JSContextRef ctx, JSValueRef value)
Returns a JavaScript value's type.
JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool boolean)
Creates a JavaScript value of the boolean type.