]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /* |
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 | |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | */ | |
25 | ||
26 | #ifndef JSBase_h | |
27 | #define JSBase_h | |
28 | ||
9dae56ea | 29 | #ifndef __cplusplus |
b37bf2e1 | 30 | #include <stdbool.h> |
9dae56ea | 31 | #endif |
b37bf2e1 | 32 | |
93a37866 A |
33 | #ifdef __OBJC__ |
34 | #import <Foundation/Foundation.h> | |
35 | #endif | |
36 | ||
37 | /* Define WTF_PLATFORM_IOS without Platform.h for JSBasePrivate.h */ | |
38 | ||
39 | #ifndef WTF_PLATFORM_IOS | |
40 | #include <TargetConditionals.h> | |
41 | #if (defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) | |
42 | #define WTF_PLATFORM_IOS 1 | |
43 | #endif | |
44 | #if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR | |
45 | #define WTF_PLATFORM_IOS 1 | |
46 | #endif | |
47 | #endif // WTF_PLATFORM_IOS | |
48 | ||
b37bf2e1 A |
49 | /* JavaScript engine interface */ |
50 | ||
9dae56ea A |
51 | /*! @typedef JSContextGroupRef A group that associates JavaScript contexts with one another. Contexts in the same group may share and exchange JavaScript objects. */ |
52 | typedef const struct OpaqueJSContextGroup* JSContextGroupRef; | |
53 | ||
b37bf2e1 A |
54 | /*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */ |
55 | typedef const struct OpaqueJSContext* JSContextRef; | |
56 | ||
57 | /*! @typedef JSGlobalContextRef A global JavaScript execution context. A JSGlobalContext is a JSContext. */ | |
58 | typedef struct OpaqueJSContext* JSGlobalContextRef; | |
59 | ||
60 | /*! @typedef JSStringRef A UTF16 character buffer. The fundamental string representation in JavaScript. */ | |
61 | typedef struct OpaqueJSString* JSStringRef; | |
62 | ||
63 | /*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */ | |
64 | typedef struct OpaqueJSClass* JSClassRef; | |
65 | ||
66 | /*! @typedef JSPropertyNameArrayRef An array of JavaScript property names. */ | |
67 | typedef struct OpaqueJSPropertyNameArray* JSPropertyNameArrayRef; | |
68 | ||
69 | /*! @typedef JSPropertyNameAccumulatorRef An ordered set used to collect the names of a JavaScript object's properties. */ | |
70 | typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef; | |
71 | ||
72 | ||
73 | /* JavaScript data types */ | |
74 | ||
75 | /*! @typedef JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them. */ | |
76 | typedef const struct OpaqueJSValue* JSValueRef; | |
77 | ||
78 | /*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */ | |
79 | typedef struct OpaqueJSValue* JSObjectRef; | |
80 | ||
81 | /* JavaScript symbol exports */ | |
14957cd0 | 82 | /* These rules should stay the same as in WebKit2/Shared/API/c/WKBase.h */ |
b37bf2e1 A |
83 | |
84 | #undef JS_EXPORT | |
f9bf01c6 | 85 | #if defined(JS_NO_EXPORT) |
14957cd0 | 86 | #define JS_EXPORT |
f9bf01c6 | 87 | #elif defined(__GNUC__) && !defined(__CC_ARM) && !defined(__ARMCC__) |
14957cd0 A |
88 | #define JS_EXPORT __attribute__((visibility("default"))) |
89 | #elif defined(WIN32) || defined(_WIN32) || defined(_WIN32_WCE) || defined(__CC_ARM) || defined(__ARMCC__) | |
93a37866 | 90 | #if defined(BUILDING_JavaScriptCore) || defined(STATICALLY_LINKED_WITH_JavaScriptCore) |
14957cd0 | 91 | #define JS_EXPORT __declspec(dllexport) |
b37bf2e1 | 92 | #else |
14957cd0 A |
93 | #define JS_EXPORT __declspec(dllimport) |
94 | #endif | |
95 | #else /* !defined(JS_NO_EXPORT) */ | |
96 | #define JS_EXPORT | |
97 | #endif /* defined(JS_NO_EXPORT) */ | |
98 | ||
99 | /* JS tests uses WTF but has no config.h, so we need to set the export defines here. */ | |
100 | #ifndef WTF_EXPORT_PRIVATE | |
101 | #define WTF_EXPORT_PRIVATE JS_EXPORT | |
b37bf2e1 A |
102 | #endif |
103 | ||
104 | #ifdef __cplusplus | |
105 | extern "C" { | |
106 | #endif | |
107 | ||
108 | /* Script Evaluation */ | |
109 | ||
110 | /*! | |
9dae56ea | 111 | @function JSEvaluateScript |
b37bf2e1 A |
112 | @abstract Evaluates a string of JavaScript. |
113 | @param ctx The execution context to use. | |
114 | @param script A JSString containing the script to evaluate. | |
115 | @param thisObject The object to use as "this," or NULL to use the global object as "this." | |
116 | @param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. | |
117 | @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. | |
118 | @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. | |
119 | @result The JSValue that results from evaluating script, or NULL if an exception is thrown. | |
120 | */ | |
121 | JS_EXPORT JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); | |
122 | ||
123 | /*! | |
124 | @function JSCheckScriptSyntax | |
125 | @abstract Checks for syntax errors in a string of JavaScript. | |
126 | @param ctx The execution context to use. | |
127 | @param script A JSString containing the script to check for syntax errors. | |
128 | @param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. | |
129 | @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. | |
130 | @param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception. | |
131 | @result true if the script is syntactically correct, otherwise false. | |
132 | */ | |
133 | JS_EXPORT bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); | |
134 | ||
135 | /*! | |
9dae56ea | 136 | @function JSGarbageCollect |
b37bf2e1 | 137 | @abstract Performs a JavaScript garbage collection. |
9dae56ea | 138 | @param ctx The execution context to use. |
b37bf2e1 A |
139 | @discussion JavaScript values that are on the machine stack, in a register, |
140 | protected by JSValueProtect, set as the global object of an execution context, | |
9dae56ea A |
141 | or reachable from any such value will not be collected. |
142 | ||
b37bf2e1 | 143 | During JavaScript execution, you are not required to call this function; the |
9dae56ea A |
144 | JavaScript engine will garbage collect as needed. JavaScript values created |
145 | within a context group are automatically destroyed when the last reference | |
146 | to the context group is released. | |
b37bf2e1 A |
147 | */ |
148 | JS_EXPORT void JSGarbageCollect(JSContextRef ctx); | |
149 | ||
150 | #ifdef __cplusplus | |
151 | } | |
152 | #endif | |
153 | ||
93a37866 A |
154 | /* Enable the Objective-C API for platforms with a modern runtime. */ |
155 | #if !defined(JSC_OBJC_API_ENABLED) | |
156 | #define JSC_OBJC_API_ENABLED (defined(__clang__) && defined(__APPLE__) && (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 && !defined(__i386__)) || ((defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || (defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR))) | |
157 | #endif | |
158 | ||
9dae56ea | 159 | #endif /* JSBase_h */ |