1 | // -*- mode: c++; c-basic-offset: 4 -*-
|
---|
2 | /*
|
---|
3 | * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | * 1. Redistributions of source code must retain the above copyright
|
---|
9 | * notice, this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer in the
|
---|
12 | * documentation and/or other materials provided with the distribution.
|
---|
13 | *
|
---|
14 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
---|
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
---|
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
---|
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef JSBase_h
|
---|
28 | #define JSBase_h
|
---|
29 |
|
---|
30 | /* JS runtime interface types */
|
---|
31 | typedef struct __JSContext* JSContextRef;
|
---|
32 | typedef struct __JSCharBuffer* JSCharBufferRef;
|
---|
33 | typedef struct __JSClass* JSClassRef;
|
---|
34 | typedef struct __JSPropertyList* JSPropertyListRef;
|
---|
35 | typedef struct __JSPropertyEnumerator* JSPropertyEnumeratorRef;
|
---|
36 |
|
---|
37 | /* Base type of all JS values, and polymorphic functions on them */
|
---|
38 | typedef void* JSValueRef;
|
---|
39 |
|
---|
40 | typedef struct __JSObject* JSObjectRef;
|
---|
41 |
|
---|
42 | #ifdef __cplusplus
|
---|
43 | extern "C" {
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | // Returns true for successful execution, false for uncaught exception.
|
---|
47 | // returnValue will contain value of last evaluated statement or exception value.
|
---|
48 | /*!
|
---|
49 | @function JSEvaluate
|
---|
50 | Evaluates a string of JavaScript code
|
---|
51 | @param context execution context to use
|
---|
52 | @param thisValue object to use as the "this" value, or NULL to use the global object as "this"
|
---|
53 | @param script a string containing the script source code
|
---|
54 | @param sourceURL URL to the file containing the source, or NULL - this is only used for error reporting
|
---|
55 | @param startingLineNumber starting line number in the source at sourceURL - this is only used for error reporting
|
---|
56 | @param returnValue result of evaluation if successful, or value of exception
|
---|
57 | @result true if evaluation succeeded, false if an uncaught exception or error occured
|
---|
58 | */
|
---|
59 | bool JSEvaluate(JSContextRef context, JSValueRef thisValue, JSCharBufferRef script, JSCharBufferRef sourceURL, int startingLineNumber, JSValueRef* returnValue);
|
---|
60 |
|
---|
61 | /*!
|
---|
62 | @function JSCheckSyntax
|
---|
63 | Checks for syntax errors in a string of JavaScript code
|
---|
64 | @param context execution context to use
|
---|
65 | @param script a string containing the script source code
|
---|
66 | @result true if the script is syntactically correct, false otherwise
|
---|
67 |
|
---|
68 | */
|
---|
69 | bool JSCheckSyntax(JSContextRef context, JSCharBufferRef script);
|
---|
70 |
|
---|
71 | // Garbage collection
|
---|
72 | /*!
|
---|
73 | @function JSGCProtect
|
---|
74 | Protect a JavaScript value from garbage collection; a value may be
|
---|
75 | protected multiple times and must be unprotected an equal number of
|
---|
76 | times to become collectable again.
|
---|
77 | */
|
---|
78 | void JSGCProtect(JSValueRef value);
|
---|
79 |
|
---|
80 | /*!
|
---|
81 | @function JSGCProtect
|
---|
82 | Stop protecting a JavaScript value from garbage collection; a value may be
|
---|
83 | protected multiple times and must be unprotected an equal number of
|
---|
84 | times to become collectable again.
|
---|
85 | */
|
---|
86 | void JSGCUnprotect(JSValueRef value);
|
---|
87 |
|
---|
88 | /*!
|
---|
89 | @function JSGCCollect
|
---|
90 | Immediately perform a JavaScript garbage collection. JavaScript
|
---|
91 | values that are on the machine stack, in a register, protected, set
|
---|
92 | as the global object of any interpreter, or reachable from any such
|
---|
93 | value will not be collected. It is not normally necessary to call
|
---|
94 | this function directly; the JS runtime will garbage collect as
|
---|
95 | needed.
|
---|
96 | */
|
---|
97 | void JSGCCollect(void);
|
---|
98 |
|
---|
99 | #ifdef __cplusplus
|
---|
100 | }
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | #endif // JSBase_h
|
---|