blob: 7a7bf93a17afa3f8e5b85164fe8818c8e21d8a76 [file] [log] [blame]
ggaren2593cdc2006-06-21 21:09:19 +00001/*
2 * Copyright (C) 2006 Apple Computer, 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 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
ggaren554ad6f2006-07-08 02:02:47 +000023 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ggaren2593cdc2006-06-21 21:09:19 +000024 */
25
26#ifndef JSValueRef_h
27#define JSValueRef_h
28
ggarene76694c2006-07-11 05:37:00 +000029#include <JavaScriptCore/JSBase.h>
ggaren2593cdc2006-06-21 21:09:19 +000030
hausmann@webkit.org030c82a2008-06-16 21:21:41 +000031#ifndef __cplusplus
ggarene66ccee2006-07-12 08:12:08 +000032#include <stdbool.h>
hausmann@webkit.org030c82a2008-06-16 21:21:41 +000033#endif
ggarene66ccee2006-07-12 08:12:08 +000034
mjs1cf94d12006-06-29 23:32:47 +000035/*!
ggarene66ccee2006-07-12 08:12:08 +000036@enum JSType
ggaren554ad6f2006-07-08 02:02:47 +000037@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).
mjs1cf94d12006-06-29 23:32:47 +000044*/
ggaren2593cdc2006-06-21 21:09:19 +000045typedef enum {
46 kJSTypeUndefined,
47 kJSTypeNull,
48 kJSTypeBoolean,
49 kJSTypeNumber,
50 kJSTypeString,
51 kJSTypeObject
ggarene66ccee2006-07-12 08:12:08 +000052} JSType;
ggaren2593cdc2006-06-21 21:09:19 +000053
54#ifdef __cplusplus
55extern "C" {
56#endif
57
mjs1cf94d12006-06-29 23:32:47 +000058/*!
ggaren554ad6f2006-07-08 02:02:47 +000059@function
ggarene66ccee2006-07-12 08:12:08 +000060@abstract Returns a JavaScript value's type.
mjs127f8592006-07-17 08:14:39 +000061@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +000062@param value The JSValue whose type you want to obtain.
ggarene66ccee2006-07-12 08:12:08 +000063@result A value of type JSType that identifies value's type.
mjs1cf94d12006-06-29 23:32:47 +000064*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +000065JS_EXPORT JSType JSValueGetType(JSContextRef ctx, JSValueRef value);
ggaren2593cdc2006-06-21 21:09:19 +000066
mjs1cf94d12006-06-29 23:32:47 +000067/*!
ggaren554ad6f2006-07-08 02:02:47 +000068@function
69@abstract Tests whether a JavaScript value's type is the undefined type.
mjs127f8592006-07-17 08:14:39 +000070@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +000071@param value The JSValue to test.
72@result true if value's type is the undefined type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +000073*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +000074JS_EXPORT bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +000075
76/*!
ggaren554ad6f2006-07-08 02:02:47 +000077@function
78@abstract Tests whether a JavaScript value's type is the null type.
mjs127f8592006-07-17 08:14:39 +000079@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +000080@param value The JSValue to test.
81@result true if value's type is the null type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +000082*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +000083JS_EXPORT bool JSValueIsNull(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +000084
85/*!
ggaren554ad6f2006-07-08 02:02:47 +000086@function
87@abstract Tests whether a JavaScript value's type is the boolean type.
mjs127f8592006-07-17 08:14:39 +000088@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +000089@param value The JSValue to test.
90@result true if value's type is the boolean type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +000091*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +000092JS_EXPORT bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +000093
94/*!
ggaren554ad6f2006-07-08 02:02:47 +000095@function
96@abstract Tests whether a JavaScript value's type is the number type.
mjs127f8592006-07-17 08:14:39 +000097@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +000098@param value The JSValue to test.
99@result true if value's type is the number type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +0000100*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000101JS_EXPORT bool JSValueIsNumber(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +0000102
103/*!
ggaren554ad6f2006-07-08 02:02:47 +0000104@function
105@abstract Tests whether a JavaScript value's type is the string type.
mjs127f8592006-07-17 08:14:39 +0000106@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000107@param value The JSValue to test.
108@result true if value's type is the string type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +0000109*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000110JS_EXPORT bool JSValueIsString(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +0000111
112/*!
ggaren554ad6f2006-07-08 02:02:47 +0000113@function
114@abstract Tests whether a JavaScript value's type is the object type.
mjs127f8592006-07-17 08:14:39 +0000115@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000116@param value The JSValue to test.
117@result true if value's type is the object type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +0000118*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000119JS_EXPORT bool JSValueIsObject(JSContextRef ctx, JSValueRef value);
ggaren554ad6f2006-07-08 02:02:47 +0000120
121/*!
122@function
ggaren0503a4b2006-07-18 04:33:46 +0000123@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.
ggaren554ad6f2006-07-08 02:02:47 +0000128*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000129JS_EXPORT bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass);
ggaren2593cdc2006-06-21 21:09:19 +0000130
christian@webkit.orgc48b89d2008-06-16 13:48:51 +0000131/* Comparing values */
mjs1cf94d12006-06-29 23:32:47 +0000132
133/*!
ggaren554ad6f2006-07-08 02:02:47 +0000134@function
ggaren81d8be02006-07-13 08:56:52 +0000135@abstract Tests whether two JavaScript values are equal, as compared by the JS == operator.
mjs127f8592006-07-17 08:14:39 +0000136@param ctx The execution context to use.
ggaren81d8be02006-07-13 08:56:52 +0000137@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.
mjs1cf94d12006-06-29 23:32:47 +0000141*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000142JS_EXPORT bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception);
mjs1cf94d12006-06-29 23:32:47 +0000143
144/*!
ggaren554ad6f2006-07-08 02:02:47 +0000145@function
146@abstract Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
mjs127f8592006-07-17 08:14:39 +0000147@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000148@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.
mjs1cf94d12006-06-29 23:32:47 +0000151*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000152JS_EXPORT bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b);
mjs1cf94d12006-06-29 23:32:47 +0000153
154/*!
ggaren554ad6f2006-07-08 02:02:47 +0000155@function
ggaren292e70e2006-07-15 04:10:31 +0000156@abstract Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the JS instanceof operator.
mjs127f8592006-07-17 08:14:39 +0000157@param ctx The execution context to use.
ggaren292e70e2006-07-15 04:10:31 +0000158@param value The JSValue to test.
ggaren@apple.com38e14992008-01-16 05:23:06 +0000159@param constructor The constructor to test against.
ggaren292e70e2006-07-15 04:10:31 +0000160@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.
mjs1cf94d12006-06-29 23:32:47 +0000162*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000163JS_EXPORT bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception);
ggaren2593cdc2006-06-21 21:09:19 +0000164
christian@webkit.orgc48b89d2008-06-16 13:48:51 +0000165/* Creating values */
mjs1cf94d12006-06-29 23:32:47 +0000166
167/*!
ggaren554ad6f2006-07-08 02:02:47 +0000168@function
mjs127f8592006-07-17 08:14:39 +0000169@abstract Creates a JavaScript value of the undefined type.
170@param ctx The execution context to use.
171@result The unique undefined value.
mjs1cf94d12006-06-29 23:32:47 +0000172*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000173JS_EXPORT JSValueRef JSValueMakeUndefined(JSContextRef ctx);
mjs1cf94d12006-06-29 23:32:47 +0000174
175/*!
ggaren554ad6f2006-07-08 02:02:47 +0000176@function
mjs127f8592006-07-17 08:14:39 +0000177@abstract Creates a JavaScript value of the null type.
178@param ctx The execution context to use.
179@result The unique null value.
mjs1cf94d12006-06-29 23:32:47 +0000180*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000181JS_EXPORT JSValueRef JSValueMakeNull(JSContextRef ctx);
mjs1cf94d12006-06-29 23:32:47 +0000182
183/*!
ggaren554ad6f2006-07-08 02:02:47 +0000184@function
185@abstract Creates a JavaScript value of the boolean type.
mjs127f8592006-07-17 08:14:39 +0000186@param ctx The execution context to use.
ggarene66ccee2006-07-12 08:12:08 +0000187@param boolean The bool to assign to the newly created JSValue.
188@result A JSValue of the boolean type, representing the value of boolean.
mjs1cf94d12006-06-29 23:32:47 +0000189*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000190JS_EXPORT JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool boolean);
mjs1cf94d12006-06-29 23:32:47 +0000191
192/*!
ggaren554ad6f2006-07-08 02:02:47 +0000193@function
194@abstract Creates a JavaScript value of the number type.
mjs127f8592006-07-17 08:14:39 +0000195@param ctx The execution context to use.
ggarene66ccee2006-07-12 08:12:08 +0000196@param number The double to assign to the newly created JSValue.
197@result A JSValue of the number type, representing the value of number.
mjs1cf94d12006-06-29 23:32:47 +0000198*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000199JS_EXPORT JSValueRef JSValueMakeNumber(JSContextRef ctx, double number);
mjs1cf94d12006-06-29 23:32:47 +0000200
201/*!
ggaren554ad6f2006-07-08 02:02:47 +0000202@function
203@abstract Creates a JavaScript value of the string type.
mjs127f8592006-07-17 08:14:39 +0000204@param ctx The execution context to use.
ggarene66ccee2006-07-12 08:12:08 +0000205@param string The JSString to assign to the newly created JSValue. The
ggarene76694c2006-07-11 05:37:00 +0000206 newly created JSValue retains string, and releases it upon garbage collection.
ggarene66ccee2006-07-12 08:12:08 +0000207@result A JSValue of the string type, representing the value of string.
mjs1cf94d12006-06-29 23:32:47 +0000208*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000209JS_EXPORT JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string);
ggaren2593cdc2006-06-21 21:09:19 +0000210
christian@webkit.orgc48b89d2008-06-16 13:48:51 +0000211/* Converting to primitive values */
mjs1cf94d12006-06-29 23:32:47 +0000212
213/*!
ggaren554ad6f2006-07-08 02:02:47 +0000214@function
215@abstract Converts a JavaScript value to boolean and returns the resulting boolean.
mjs127f8592006-07-17 08:14:39 +0000216@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000217@param value The JSValue to convert.
ggaren292e70e2006-07-15 04:10:31 +0000218@result The boolean result of conversion.
mjs1cf94d12006-06-29 23:32:47 +0000219*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000220JS_EXPORT bool JSValueToBoolean(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +0000221
222/*!
ggaren554ad6f2006-07-08 02:02:47 +0000223@function
224@abstract Converts a JavaScript value to number and returns the resulting number.
mjs127f8592006-07-17 08:14:39 +0000225@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000226@param value The JSValue to convert.
ggaren81d8be02006-07-13 08:56:52 +0000227@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.
mjs1cf94d12006-06-29 23:32:47 +0000229*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000230JS_EXPORT double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
mjs1cf94d12006-06-29 23:32:47 +0000231
232/*!
ggaren554ad6f2006-07-08 02:02:47 +0000233@function
ggarene66ccee2006-07-12 08:12:08 +0000234@abstract Converts a JavaScript value to string and copies the result into a JavaScript string.
mjs127f8592006-07-17 08:14:39 +0000235@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000236@param value The JSValue to convert.
ggaren81d8be02006-07-13 08:56:52 +0000237@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.
mjs1cf94d12006-06-29 23:32:47 +0000239*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000240JS_EXPORT JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
mjs1cf94d12006-06-29 23:32:47 +0000241
242/*!
ggaren554ad6f2006-07-08 02:02:47 +0000243@function
244@abstract Converts a JavaScript value to object and returns the resulting object.
mjs127f8592006-07-17 08:14:39 +0000245@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000246@param value The JSValue to convert.
ggaren81d8be02006-07-13 08:56:52 +0000247@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.
ggaren292e70e2006-07-15 04:10:31 +0000248@result The JSObject result of conversion, or NULL if an exception is thrown.
mjs1cf94d12006-06-29 23:32:47 +0000249*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000250JS_EXPORT JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
ggaren2593cdc2006-06-21 21:09:19 +0000251
christian@webkit.orgc48b89d2008-06-16 13:48:51 +0000252/* Garbage collection */
ggaren699a47c2006-07-05 18:07:57 +0000253/*!
ggaren554ad6f2006-07-08 02:02:47 +0000254@function
ggaren0503a4b2006-07-18 04:33:46 +0000255@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.
259
260A value may be protected multiple times and must be unprotected an equal number of times before becoming eligible for garbage collection.
ggaren699a47c2006-07-05 18:07:57 +0000261*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000262JS_EXPORT void JSValueProtect(JSContextRef ctx, JSValueRef value);
ggaren699a47c2006-07-05 18:07:57 +0000263
264/*!
ggaren554ad6f2006-07-08 02:02:47 +0000265@function
266@abstract Unprotects a JavaScript value from garbage collection.
mjs127f8592006-07-17 08:14:39 +0000267@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000268@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.
ggaren699a47c2006-07-05 18:07:57 +0000271*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000272JS_EXPORT void JSValueUnprotect(JSContextRef ctx, JSValueRef value);
ggaren699a47c2006-07-05 18:07:57 +0000273
ggaren2593cdc2006-06-21 21:09:19 +0000274#ifdef __cplusplus
275}
276#endif
277
christian@webkit.orgc48b89d2008-06-16 13:48:51 +0000278#endif /* JSValueRef_h */