source: webkit/trunk/JavaScriptCore/API/JSBase.h@ 15437

Last change on this file since 15437 was 15437, checked in by ggaren, 19 years ago

JavaScriptCore:

Reviewed by Maciej.


  • Implemented ref-counting of JSContexts by splitting into two datatypes: JSGlobalContext, which you can create/retain/release, and JSContext, which you can't.


Internally, you retain a JSGlobalContext/ExecState by retaining its
interpreter, which, in the case of a global ExecState, owns it.


  • Also made ~Interpreter() protected to catch places where Interpreter is manually deleted. (Can't make it private because some crazy fool decided it would be a good idea to subclass Interpreter in other frameworks. I pity da fool.)
  • API/APICast.h: (toJS): Added cast for new JSGlobalContext
  • API/JSStringRef.h: Changed vague "you must" language to more specific (but, ultimately, equally vague) "behavior is undefined if you don't" language. (KJS::Interpreter::Interpreter): Factored more common initialization into init()
  • kjs/interpreter.h: (KJS::Interpreter::ref): new (KJS::Interpreter::deref): new (KJS::Interpreter::refCount): new
  • kjs/testkjs.cpp: (doIt): Ref-count the interpreter.

JavaScriptGlue:

Reviewed by Maciej.


  • Updated JSInterpreter to work with Interpreter ref-counting in JavaScriptCore.

(JSInterpreter::JSInterpreter::~JSInterpreter): Now protected to catch
manual delete.

WebCore:

Reviewed by Maciej.

  • Updated ScriptInterpreter to work with Interpreter ref-counting in JavaScriptCore.

(KJS::ScriptInterpreter::~ScriptInterpreter): Now protected to catch
manual delete.

File size: 5.3 KB
Line 
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#include <stdbool.h>
31
32/* JavaScript engine interface */
33
34/*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */
35typedef const struct __JSContext* JSContextRef;
36
37/*! @typedef JSGlobalContextRef A global JavaScript execution context. A JSGlobalContext is a JSContext. */
38typedef struct __JSContext* JSGlobalContextRef;
39
40/*! @typedef JSString A UTF16 character buffer. The fundamental string representation in JavaScript. */
41typedef struct __JSString* JSStringRef;
42
43/*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */
44typedef struct __JSClass* JSClassRef;
45
46/*! @typedef JSPropertyListRef A JavaScript property list. Used for listing the properties in an object so they can be enumerated. */
47typedef struct __JSPropertyList* JSPropertyListRef;
48
49/*! @typedef JSPropertyEnumeratorRef A JavaScript property enumerator. Used for enumerating the properties in an object. */
50typedef struct __JSPropertyEnumerator* JSPropertyEnumeratorRef;
51
52
53/* JavaScript data types */
54
55/*! @typedef JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them. */
56typedef const struct __JSValue* JSValueRef;
57
58/*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */
59typedef struct __JSValue* JSObjectRef;
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65/* Script Evaluation */
66
67/*!
68@function
69@abstract Evaluates a string of JavaScript.
70@param context The execution context to use.
71@param script A JSString containing the script to evaluate.
72@param thisObject The object to use as "this," or NULL to use the global object as "this."
73@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.
74@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.
75@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.
76@result The JSValue that results from evaluating script, or NULL if an exception is thrown.
77*/
78JSValueRef JSEvaluateScript(JSContextRef context, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
79
80/*!
81@function JSCheckScriptSyntax
82@abstract Checks for syntax errors in a string of JavaScript.
83@param context The execution context to use.
84@param script A JSString containing the script to check for syntax errors.
85@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.
86@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.
87@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.
88@result true if the script is syntactically correct, otherwise false.
89*/
90bool JSCheckScriptSyntax(JSContextRef context, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
91
92/*!
93@function
94@abstract Performs a JavaScript garbage collection.
95@discussion JavaScript values that are on the machine stack, in a register,
96 protected by JSValueProtect, set as the global object of an execution context,
97 or reachable from any such value will not be collected.
98
99 You are not required to call this function; the JavaScript engine will garbage
100 collect as needed.
101*/
102void JSGarbageCollect(void);
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif // JSBase_h
Note: See TracBrowser for help on using the repository browser.