Ultralight C API 1.3.0
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*/
47typedef enum {
54 kJSTypeSymbol JSC_API_AVAILABLE(macos(10.15), ios(13.0))
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 kJSTypedArrayTypeArrayBuffer ArrayBuffer
70 @constant kJSTypedArrayTypeNone Not a Typed Array
71
72 */
73typedef enum {
85} JSTypedArrayType JSC_API_AVAILABLE(macos(10.12), ios(10.0));
86
87#ifdef __cplusplus
88extern "C" {
89#endif
90
91/*!
92@function
93@abstract Returns a JavaScript value's type.
94@param ctx The execution context to use.
95@param value The JSValue whose type you want to obtain.
96@result A value of type JSType that identifies value's type.
97*/
99
100/*!
101@function
102@abstract Tests whether a JavaScript value's type is the undefined type.
103@param ctx The execution context to use.
104@param value The JSValue to test.
105@result true if value's type is the undefined type, otherwise false.
106*/
108
109/*!
110@function
111@abstract Tests whether a JavaScript value's type is the null type.
112@param ctx The execution context to use.
113@param value The JSValue to test.
114@result true if value's type is the null type, otherwise false.
115*/
117
118/*!
119@function
120@abstract Tests whether a JavaScript value's type is the boolean type.
121@param ctx The execution context to use.
122@param value The JSValue to test.
123@result true if value's type is the boolean type, otherwise false.
124*/
126
127/*!
128@function
129@abstract Tests whether a JavaScript value's type is the number type.
130@param ctx The execution context to use.
131@param value The JSValue to test.
132@result true if value's type is the number type, otherwise false.
133*/
135
136/*!
137@function
138@abstract Tests whether a JavaScript value's type is the string type.
139@param ctx The execution context to use.
140@param value The JSValue to test.
141@result true if value's type is the string type, otherwise false.
142*/
144
145/*!
146@function
147@abstract Tests whether a JavaScript value's type is the symbol type.
148@param ctx The execution context to use.
149@param value The JSValue to test.
150@result true if value's type is the symbol type, otherwise false.
151*/
153
154/*!
155@function
156@abstract Tests whether a JavaScript value's type is the object type.
157@param ctx The execution context to use.
158@param value The JSValue to test.
159@result true if value's type is the object type, otherwise false.
160*/
162
163
164/*!
165@function
166@abstract Tests whether a JavaScript value is an object with a given class in its class chain.
167@param ctx The execution context to use.
168@param value The JSValue to test.
169@param jsClass The JSClass to test against.
170@result true if value is an object and has jsClass in its class chain, otherwise false.
171*/
173
174/*!
175@function
176@abstract Tests whether a JavaScript value is an array.
177@param ctx The execution context to use.
178@param value The JSValue to test.
179@result true if value is an array, otherwise false.
180*/
182
183/*!
184@function
185@abstract Tests whether a JavaScript value is a date.
186@param ctx The execution context to use.
187@param value The JSValue to test.
188@result true if value is a date, otherwise false.
189*/
191
192/*!
193@function
194@abstract Returns a JavaScript value's Typed Array type.
195@param ctx The execution context to use.
196@param value The JSValue whose Typed Array type to return.
197@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.
198@result A value of type JSTypedArrayType that identifies value's Typed Array type, or kJSTypedArrayTypeNone if the value is not a Typed Array object.
199 */
201
202/* Comparing values */
203
204/*!
205@function
206@abstract Tests whether two JavaScript values are equal, as compared by the JS == operator.
207@param ctx The execution context to use.
208@param a The first value to test.
209@param b The second value to test.
210@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.
211@result true if the two values are equal, false if they are not equal or an exception is thrown.
212*/
214
215/*!
216@function
217@abstract Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
218@param ctx The execution context to use.
219@param a The first value to test.
220@param b The second value to test.
221@result true if the two values are strict equal, otherwise false.
222*/
224
225/*!
226@function
227@abstract Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the JS instanceof operator.
228@param ctx The execution context to use.
229@param value The JSValue to test.
230@param constructor The constructor to test against.
231@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.
232@result true if value is an object constructed by constructor, as compared by the JS instanceof operator, otherwise false.
233*/
235
236/* Creating values */
237
238/*!
239@function
240@abstract Creates a JavaScript value of the undefined type.
241@param ctx The execution context to use.
242@result The unique undefined value.
243*/
245
246/*!
247@function
248@abstract Creates a JavaScript value of the null type.
249@param ctx The execution context to use.
250@result The unique null value.
251*/
253
254/*!
255@function
256@abstract Creates a JavaScript value of the boolean type.
257@param ctx The execution context to use.
258@param boolean The bool to assign to the newly created JSValue.
259@result A JSValue of the boolean type, representing the value of boolean.
260*/
262
263/*!
264@function
265@abstract Creates a JavaScript value of the number type.
266@param ctx The execution context to use.
267@param number The double to assign to the newly created JSValue.
268@result A JSValue of the number type, representing the value of number.
269*/
271
272/*!
273@function
274@abstract Creates a JavaScript value of the string type.
275@param ctx The execution context to use.
276@param string The JSString to assign to the newly created JSValue. The
277 newly created JSValue retains string, and releases it upon garbage collection.
278@result A JSValue of the string type, representing the value of string.
279*/
281
282/*!
283 @function
284 @abstract Creates a JavaScript value of the symbol type.
285 @param ctx The execution context to use.
286 @param description A description of the newly created symbol value.
287 @result A unique JSValue of the symbol type, whose description matches the one provided.
288 */
290
291/* Converting to and from JSON formatted strings */
292
293/*!
294 @function
295 @abstract Creates a JavaScript value from a JSON formatted string.
296 @param ctx The execution context to use.
297 @param string The JSString containing the JSON string to be parsed.
298 @result A JSValue containing the parsed value, or NULL if the input is invalid.
299 */
301
302/*!
303 @function
304 @abstract Creates a JavaScript string containing the JSON serialized representation of a JS value.
305 @param ctx The execution context to use.
306 @param value The value to serialize.
307 @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.
308 @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.
309 @result A JSString with the result of serialization, or NULL if an exception is thrown.
310 */
311JS_EXPORT JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef value, unsigned indent, JSValueRef* exception) JSC_API_AVAILABLE(macos(10.7), ios(7.0));
312
313/* Converting to primitive values */
314
315/*!
316@function
317@abstract Converts a JavaScript value to boolean and returns the resulting boolean.
318@param ctx The execution context to use.
319@param value The JSValue to convert.
320@result The boolean result of conversion.
321*/
323
324/*!
325@function
326@abstract Converts a JavaScript value to number and returns the resulting number.
327@param ctx The execution context to use.
328@param value The JSValue to convert.
329@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.
330@result The numeric result of conversion, or NaN if an exception is thrown.
331*/
333
334/*!
335@function
336@abstract Converts a JavaScript value to string and copies the result into a JavaScript string.
337@param ctx The execution context to use.
338@param value The JSValue to convert.
339@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.
340@result A JSString with the result of conversion, or NULL if an exception is thrown. Ownership follows the Create Rule.
341*/
343
344/*!
345@function
346@abstract Converts a JavaScript value to object and returns the resulting object.
347@param ctx The execution context to use.
348@param value The JSValue to convert.
349@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.
350@result The JSObject result of conversion, or NULL if an exception is thrown.
351*/
353
354/* Garbage collection */
355/*!
356@function
357@abstract Protects a JavaScript value from garbage collection.
358@param ctx The execution context to use.
359@param value The JSValue to protect.
360@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.
361
362A value may be protected multiple times and must be unprotected an equal number of times before becoming eligible for garbage collection.
363*/
365
366/*!
367@function
368@abstract Unprotects a JavaScript value from garbage collection.
369@param ctx The execution context to use.
370@param value The JSValue to unprotect.
371@discussion A value may be protected multiple times and must be unprotected an
372 equal number of times before becoming eligible for garbage collection.
373*/
375
376#ifdef __cplusplus
377}
378#endif
379
380#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:73
@ kJSTypedArrayTypeUint16Array
Definition JSValueRef.h:79
@ kJSTypedArrayTypeInt32Array
Definition JSValueRef.h:76
@ kJSTypedArrayTypeInt16Array
Definition JSValueRef.h:75
@ kJSTypedArrayTypeNone
Definition JSValueRef.h:84
@ kJSTypedArrayTypeInt8Array
Definition JSValueRef.h:74
@ kJSTypedArrayTypeArrayBuffer
Definition JSValueRef.h:83
@ kJSTypedArrayTypeUint32Array
Definition JSValueRef.h:80
@ kJSTypedArrayTypeUint8ClampedArray
Definition JSValueRef.h:78
@ kJSTypedArrayTypeFloat32Array
Definition JSValueRef.h:81
@ kJSTypedArrayTypeUint8Array
Definition JSValueRef.h:77
@ kJSTypedArrayTypeFloat64Array
Definition JSValueRef.h:82
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.