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

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

Reviewed by Maciej.


  • Added automatic prototype creation for classes.


A class stores a weak reference to a prototype, which is cleared when
the prototype is garbage collected, to avoid a reference cycle.


We now have an attributes field in JSClassDefinition, that currently is
used only to override automatic prototype creation when you want to manage your
own prototypes, but can be extended in the future for other nefarious purposes.


Similarly, we have JSObjectMake and JSObjectMakeWithPrototype, the latter
allowing you to manage your own prototypes.


JSObjectMakeConstructor is more interesting now, able to make a constructor
on your behalf if you just give it a class.


  • Removed bogus old code from minidom.js.


  • Tweaked the headerdocs.


  • Added more GC testing, which caught some leaks, and tested more funny edge cases in lookup, which caught a lookup bug. Removed some testing we used to do with MyObject because it was redundant with the new, cool stuff.


While fixing the lookup bug I retracted this change:


"If a static setProperty callback returns 'false', to indicate that the
property was not set, we no longer forward the set request up the class
chain, because that's almost certainly not what the programmer expected."

Returning false when setting a static property is a little silly, but you can see
it being useful when shadowing a base class's static properties, and, regardless
of usefullness, this is the defined behavior of the setProperty callback.


  • Plus a little ASCII art, for the kids.
File size: 5.2 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 OpaqueJSContext* JSContextRef;
36
37/*! @typedef JSGlobalContextRef A global JavaScript execution context. A JSGlobalContext is a JSContext. */
38typedef struct OpaqueJSContext* JSGlobalContextRef;
39
40/*! @typedef JSString A UTF16 character buffer. The fundamental string representation in JavaScript. */
41typedef struct OpaqueJSString* JSStringRef;
42
43/*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */
44typedef struct OpaqueJSClass* JSClassRef;
45
46/*! @typedef JSPropertyNameArrayRef An array of JavaScript property names. */
47typedef struct OpaqueJSPropertyNameArray* JSPropertyNameArrayRef;
48
49/*! @typedef JSPropertyNameAccumulatorRef An ordered set used to collect the names of a JavaScript object's properties. */
50typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
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 OpaqueJSValue* JSValueRef;
57
58/*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */
59typedef struct OpaqueJSValue* 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 ctx 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 ctx, 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 ctx 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 ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
91
92/*!
93@function
94@abstract Performs a JavaScript garbage collection.
95@param ctx The execution context to use.
96@discussion JavaScript values that are on the machine stack, in a register,
97 protected by JSValueProtect, set as the global object of an execution context,
98 or reachable from any such value will not be collected.
99
100 You are not required to call this function; the JavaScript engine will garbage
101 collect as needed.
102*/
103void JSGarbageCollect(JSContextRef ctx);
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif // JSBase_h
Note: See TracBrowser for help on using the repository browser.