blob: d2928983d4f915d9947a657254aa8fa61d2a333d [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
ggarene66ccee2006-07-12 08:12:08 +000031#include <stdbool.h>
32
mjs1cf94d12006-06-29 23:32:47 +000033/*!
ggarene66ccee2006-07-12 08:12:08 +000034@enum JSType
ggaren554ad6f2006-07-08 02:02:47 +000035@abstract A constant identifying the type of a JSValue.
36@constant kJSTypeUndefined The unique undefined value.
37@constant kJSTypeNull The unique null value.
38@constant kJSTypeBoolean A primitive boolean value, one of true or false.
39@constant kJSTypeNumber A primitive number value.
40@constant kJSTypeString A primitive string value.
41@constant kJSTypeObject An object value (meaning that this JSValueRef is a JSObjectRef).
mjs1cf94d12006-06-29 23:32:47 +000042*/
ggaren2593cdc2006-06-21 21:09:19 +000043typedef enum {
44 kJSTypeUndefined,
45 kJSTypeNull,
46 kJSTypeBoolean,
47 kJSTypeNumber,
48 kJSTypeString,
49 kJSTypeObject
ggarene66ccee2006-07-12 08:12:08 +000050} JSType;
ggaren2593cdc2006-06-21 21:09:19 +000051
52#ifdef __cplusplus
53extern "C" {
54#endif
55
mjs1cf94d12006-06-29 23:32:47 +000056/*!
ggaren554ad6f2006-07-08 02:02:47 +000057@function
ggarene66ccee2006-07-12 08:12:08 +000058@abstract Returns a JavaScript value's type.
mjs127f8592006-07-17 08:14:39 +000059@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +000060@param value The JSValue whose type you want to obtain.
ggarene66ccee2006-07-12 08:12:08 +000061@result A value of type JSType that identifies value's type.
mjs1cf94d12006-06-29 23:32:47 +000062*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +000063JS_EXPORT JSType JSValueGetType(JSContextRef ctx, JSValueRef value);
ggaren2593cdc2006-06-21 21:09:19 +000064
mjs1cf94d12006-06-29 23:32:47 +000065/*!
ggaren554ad6f2006-07-08 02:02:47 +000066@function
67@abstract Tests whether a JavaScript value's type is the undefined type.
mjs127f8592006-07-17 08:14:39 +000068@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +000069@param value The JSValue to test.
70@result true if value's type is the undefined type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +000071*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +000072JS_EXPORT bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +000073
74/*!
ggaren554ad6f2006-07-08 02:02:47 +000075@function
76@abstract Tests whether a JavaScript value's type is the null type.
mjs127f8592006-07-17 08:14:39 +000077@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +000078@param value The JSValue to test.
79@result true if value's type is the null type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +000080*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +000081JS_EXPORT bool JSValueIsNull(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +000082
83/*!
ggaren554ad6f2006-07-08 02:02:47 +000084@function
85@abstract Tests whether a JavaScript value's type is the boolean type.
mjs127f8592006-07-17 08:14:39 +000086@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +000087@param value The JSValue to test.
88@result true if value's type is the boolean type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +000089*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +000090JS_EXPORT bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +000091
92/*!
ggaren554ad6f2006-07-08 02:02:47 +000093@function
94@abstract Tests whether a JavaScript value's type is the number type.
mjs127f8592006-07-17 08:14:39 +000095@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +000096@param value The JSValue to test.
97@result true if value's type is the number type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +000098*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +000099JS_EXPORT bool JSValueIsNumber(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +0000100
101/*!
ggaren554ad6f2006-07-08 02:02:47 +0000102@function
103@abstract Tests whether a JavaScript value's type is the string type.
mjs127f8592006-07-17 08:14:39 +0000104@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000105@param value The JSValue to test.
106@result true if value's type is the string type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +0000107*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000108JS_EXPORT bool JSValueIsString(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +0000109
110/*!
ggaren554ad6f2006-07-08 02:02:47 +0000111@function
112@abstract Tests whether a JavaScript value's type is the object type.
mjs127f8592006-07-17 08:14:39 +0000113@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000114@param value The JSValue to test.
115@result true if value's type is the object type, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +0000116*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000117JS_EXPORT bool JSValueIsObject(JSContextRef ctx, JSValueRef value);
ggaren554ad6f2006-07-08 02:02:47 +0000118
119/*!
120@function
ggaren0503a4b2006-07-18 04:33:46 +0000121@abstract Tests whether a JavaScript value is an object with a given class in its class chain.
122@param ctx The execution context to use.
123@param value The JSValue to test.
124@param jsClass The JSClass to test against.
125@result true if value is an object and has jsClass in its class chain, otherwise false.
ggaren554ad6f2006-07-08 02:02:47 +0000126*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000127JS_EXPORT bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass);
ggaren2593cdc2006-06-21 21:09:19 +0000128
christian@webkit.orgc48b89d2008-06-16 13:48:51 +0000129/* Comparing values */
mjs1cf94d12006-06-29 23:32:47 +0000130
131/*!
ggaren554ad6f2006-07-08 02:02:47 +0000132@function
ggaren81d8be02006-07-13 08:56:52 +0000133@abstract Tests whether two JavaScript values are equal, as compared by the JS == operator.
mjs127f8592006-07-17 08:14:39 +0000134@param ctx The execution context to use.
ggaren81d8be02006-07-13 08:56:52 +0000135@param a The first value to test.
136@param b The second value to test.
137@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.
138@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 +0000139*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000140JS_EXPORT bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception);
mjs1cf94d12006-06-29 23:32:47 +0000141
142/*!
ggaren554ad6f2006-07-08 02:02:47 +0000143@function
144@abstract Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
mjs127f8592006-07-17 08:14:39 +0000145@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000146@param a The first value to test.
147@param b The second value to test.
148@result true if the two values are strict equal, otherwise false.
mjs1cf94d12006-06-29 23:32:47 +0000149*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000150JS_EXPORT bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b);
mjs1cf94d12006-06-29 23:32:47 +0000151
152/*!
ggaren554ad6f2006-07-08 02:02:47 +0000153@function
ggaren292e70e2006-07-15 04:10:31 +0000154@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 +0000155@param ctx The execution context to use.
ggaren292e70e2006-07-15 04:10:31 +0000156@param value The JSValue to test.
ggaren@apple.com38e14992008-01-16 05:23:06 +0000157@param constructor The constructor to test against.
ggaren292e70e2006-07-15 04:10:31 +0000158@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.
159@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 +0000160*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000161JS_EXPORT bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception);
ggaren2593cdc2006-06-21 21:09:19 +0000162
christian@webkit.orgc48b89d2008-06-16 13:48:51 +0000163/* Creating values */
mjs1cf94d12006-06-29 23:32:47 +0000164
165/*!
ggaren554ad6f2006-07-08 02:02:47 +0000166@function
mjs127f8592006-07-17 08:14:39 +0000167@abstract Creates a JavaScript value of the undefined type.
168@param ctx The execution context to use.
169@result The unique undefined value.
mjs1cf94d12006-06-29 23:32:47 +0000170*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000171JS_EXPORT JSValueRef JSValueMakeUndefined(JSContextRef ctx);
mjs1cf94d12006-06-29 23:32:47 +0000172
173/*!
ggaren554ad6f2006-07-08 02:02:47 +0000174@function
mjs127f8592006-07-17 08:14:39 +0000175@abstract Creates a JavaScript value of the null type.
176@param ctx The execution context to use.
177@result The unique null value.
mjs1cf94d12006-06-29 23:32:47 +0000178*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000179JS_EXPORT JSValueRef JSValueMakeNull(JSContextRef ctx);
mjs1cf94d12006-06-29 23:32:47 +0000180
181/*!
ggaren554ad6f2006-07-08 02:02:47 +0000182@function
183@abstract Creates a JavaScript value of the boolean type.
mjs127f8592006-07-17 08:14:39 +0000184@param ctx The execution context to use.
ggarene66ccee2006-07-12 08:12:08 +0000185@param boolean The bool to assign to the newly created JSValue.
186@result A JSValue of the boolean type, representing the value of boolean.
mjs1cf94d12006-06-29 23:32:47 +0000187*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000188JS_EXPORT JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool boolean);
mjs1cf94d12006-06-29 23:32:47 +0000189
190/*!
ggaren554ad6f2006-07-08 02:02:47 +0000191@function
192@abstract Creates a JavaScript value of the number type.
mjs127f8592006-07-17 08:14:39 +0000193@param ctx The execution context to use.
ggarene66ccee2006-07-12 08:12:08 +0000194@param number The double to assign to the newly created JSValue.
195@result A JSValue of the number type, representing the value of number.
mjs1cf94d12006-06-29 23:32:47 +0000196*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000197JS_EXPORT JSValueRef JSValueMakeNumber(JSContextRef ctx, double number);
mjs1cf94d12006-06-29 23:32:47 +0000198
199/*!
ggaren554ad6f2006-07-08 02:02:47 +0000200@function
201@abstract Creates a JavaScript value of the string type.
mjs127f8592006-07-17 08:14:39 +0000202@param ctx The execution context to use.
ggarene66ccee2006-07-12 08:12:08 +0000203@param string The JSString to assign to the newly created JSValue. The
ggarene76694c2006-07-11 05:37:00 +0000204 newly created JSValue retains string, and releases it upon garbage collection.
ggarene66ccee2006-07-12 08:12:08 +0000205@result A JSValue of the string type, representing the value of string.
mjs1cf94d12006-06-29 23:32:47 +0000206*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000207JS_EXPORT JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string);
ggaren2593cdc2006-06-21 21:09:19 +0000208
christian@webkit.orgc48b89d2008-06-16 13:48:51 +0000209/* Converting to primitive values */
mjs1cf94d12006-06-29 23:32:47 +0000210
211/*!
ggaren554ad6f2006-07-08 02:02:47 +0000212@function
213@abstract Converts a JavaScript value to boolean and returns the resulting boolean.
mjs127f8592006-07-17 08:14:39 +0000214@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000215@param value The JSValue to convert.
ggaren292e70e2006-07-15 04:10:31 +0000216@result The boolean result of conversion.
mjs1cf94d12006-06-29 23:32:47 +0000217*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000218JS_EXPORT bool JSValueToBoolean(JSContextRef ctx, JSValueRef value);
mjs1cf94d12006-06-29 23:32:47 +0000219
220/*!
ggaren554ad6f2006-07-08 02:02:47 +0000221@function
222@abstract Converts a JavaScript value to number and returns the resulting number.
mjs127f8592006-07-17 08:14:39 +0000223@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000224@param value The JSValue to convert.
ggaren81d8be02006-07-13 08:56:52 +0000225@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.
226@result The numeric result of conversion, or NaN if an exception is thrown.
mjs1cf94d12006-06-29 23:32:47 +0000227*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000228JS_EXPORT double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
mjs1cf94d12006-06-29 23:32:47 +0000229
230/*!
ggaren554ad6f2006-07-08 02:02:47 +0000231@function
ggarene66ccee2006-07-12 08:12:08 +0000232@abstract Converts a JavaScript value to string and copies the result into a JavaScript string.
mjs127f8592006-07-17 08:14:39 +0000233@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000234@param value The JSValue to convert.
ggaren81d8be02006-07-13 08:56:52 +0000235@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 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 +0000237*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000238JS_EXPORT JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
mjs1cf94d12006-06-29 23:32:47 +0000239
240/*!
ggaren554ad6f2006-07-08 02:02:47 +0000241@function
242@abstract Converts a JavaScript value to object and returns the resulting object.
mjs127f8592006-07-17 08:14:39 +0000243@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000244@param value The JSValue to convert.
ggaren81d8be02006-07-13 08:56:52 +0000245@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 +0000246@result The JSObject result of conversion, or NULL if an exception is thrown.
mjs1cf94d12006-06-29 23:32:47 +0000247*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000248JS_EXPORT JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
ggaren2593cdc2006-06-21 21:09:19 +0000249
christian@webkit.orgc48b89d2008-06-16 13:48:51 +0000250/* Garbage collection */
ggaren699a47c2006-07-05 18:07:57 +0000251/*!
ggaren554ad6f2006-07-08 02:02:47 +0000252@function
ggaren0503a4b2006-07-18 04:33:46 +0000253@abstract Protects a JavaScript value from garbage collection.
254@param ctx The execution context to use.
255@param value The JSValue to protect.
256@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.
257
258A 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 +0000259*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000260JS_EXPORT void JSValueProtect(JSContextRef ctx, JSValueRef value);
ggaren699a47c2006-07-05 18:07:57 +0000261
262/*!
ggaren554ad6f2006-07-08 02:02:47 +0000263@function
264@abstract Unprotects a JavaScript value from garbage collection.
mjs127f8592006-07-17 08:14:39 +0000265@param ctx The execution context to use.
ggaren554ad6f2006-07-08 02:02:47 +0000266@param value The JSValue to unprotect.
267@discussion A value may be protected multiple times and must be unprotected an
268 equal number of times before becoming eligible for garbage collection.
ggaren699a47c2006-07-05 18:07:57 +0000269*/
alp@webkit.orgd8bfe3d2007-11-28 04:31:51 +0000270JS_EXPORT void JSValueUnprotect(JSContextRef ctx, JSValueRef value);
ggaren699a47c2006-07-05 18:07:57 +0000271
ggaren2593cdc2006-06-21 21:09:19 +0000272#ifdef __cplusplus
273}
274#endif
275
christian@webkit.orgc48b89d2008-06-16 13:48:51 +0000276#endif /* JSValueRef_h */