1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Mozilla Communicator client code, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
43 * JS public API typedefs.
51 /* Scalar typedefs. */
52 typedef JSInt32 jsint
;
53 typedef JSUint32 jsuint
;
54 typedef float64 jsdouble
;
55 typedef JSInt32 jsrefcount
; /* PRInt32 if JS_THREADSAFE, see jslock.h */
58 typedef wchar_t jschar
;
60 typedef JSUint16 jschar
;
65 * Run-time version enumeration. See jsversion.h for compile-time counterparts
66 * to these values that may be selected by the JS_VERSION macro, and tested by
69 typedef enum JSVersion
{
75 JSVERSION_ECMA_3
= 148,
80 JSVERSION_ECMA_5
= 185,
81 JSVERSION_DEFAULT
= 0,
82 JSVERSION_UNKNOWN
= -1,
83 JSVERSION_LATEST
= JSVERSION_ECMA_5
86 #define JSVERSION_IS_ECMA(version) \
87 ((version) == JSVERSION_DEFAULT || (version) >= JSVERSION_1_3)
89 /* Result of typeof operator enumeration. */
91 JSTYPE_VOID
, /* undefined */
92 JSTYPE_OBJECT
, /* object */
93 JSTYPE_FUNCTION
, /* function */
94 JSTYPE_STRING
, /* string */
95 JSTYPE_NUMBER
, /* number */
96 JSTYPE_BOOLEAN
, /* boolean */
97 JSTYPE_NULL
, /* null */
98 JSTYPE_XML
, /* xml object */
102 /* Dense index into cached prototypes and class atoms for standard objects. */
103 typedef enum JSProtoKey
{
104 #define JS_PROTO(name,code,init) JSProto_##name = code,
105 #include "jsproto.tbl"
110 /* js_CheckAccess mode enumeration. */
111 typedef enum JSAccessMode
{
112 JSACC_PROTO
= 0, /* XXXbe redundant w.r.t. id */
113 JSACC_PARENT
= 1, /* XXXbe redundant w.r.t. id */
116 * enum value #2 formerly called JSACC_IMPORT,
117 * gap preserved for ABI compatibility.
120 JSACC_WATCH
= 3, /* a watchpoint on object foo for id 'bar' */
121 JSACC_READ
= 4, /* a "get" of foo.bar */
122 JSACC_WRITE
= 8, /* a "set" of foo.bar = baz */
126 #define JSACC_TYPEMASK (JSACC_WRITE - 1)
129 * This enum type is used to control the behavior of a JSObject property
130 * iterator function that has type JSNewEnumerate.
132 typedef enum JSIterateOp
{
133 /* Create new iterator state over enumerable properties. */
136 /* Create new iterator state over all properties. */
137 JSENUMERATE_INIT_ALL
,
142 /* Destroy iterator state. */
146 /* Struct typedefs. */
147 typedef struct JSClass JSClass
;
148 typedef struct JSConstDoubleSpec JSConstDoubleSpec
;
149 typedef struct JSContext JSContext
;
150 typedef struct JSErrorReport JSErrorReport
;
151 typedef struct JSFunction JSFunction
;
152 typedef struct JSFunctionSpec JSFunctionSpec
;
153 typedef struct JSTracer JSTracer
;
154 typedef struct JSIdArray JSIdArray
;
155 typedef struct JSPropertyDescriptor JSPropertyDescriptor
;
156 typedef struct JSPropertySpec JSPropertySpec
;
157 typedef struct JSObjectMap JSObjectMap
;
158 typedef struct JSRuntime JSRuntime
;
159 typedef struct JSScript JSScript
;
160 typedef struct JSStackFrame JSStackFrame
;
161 typedef struct JSXDRState JSXDRState
;
162 typedef struct JSExceptionState JSExceptionState
;
163 typedef struct JSLocaleCallbacks JSLocaleCallbacks
;
164 typedef struct JSSecurityCallbacks JSSecurityCallbacks
;
165 typedef struct JSONParser JSONParser
;
166 typedef struct JSCompartment JSCompartment
;
167 typedef struct JSCrossCompartmentCall JSCrossCompartmentCall
;
168 typedef struct JSStructuredCloneWriter JSStructuredCloneWriter
;
169 typedef struct JSStructuredCloneReader JSStructuredCloneReader
;
170 typedef struct JSStructuredCloneCallbacks JSStructuredCloneCallbacks
;
173 typedef class JSWrapper JSWrapper
;
174 typedef class JSCrossCompartmentWrapper JSCrossCompartmentWrapper
;
177 /* JSClass (and js::ObjectOps where appropriate) function pointer typedefs. */
180 * Add, delete, or get a property named by id in obj. Note the jsid id
181 * type -- id may be a string (Unicode property identifier) or an int (element
182 * index). The *vp out parameter, on success, is the new property value after
183 * an add or get. After a successful delete, *vp is JSVAL_FALSE iff
184 * obj[id] can't be deleted (because it's permanent).
187 (* JSPropertyOp
)(JSContext
*cx
, JSObject
*obj
, jsid id
, jsval
*vp
);
190 * Set a property named by id in obj, treating the assignment as strict
191 * mode code if strict is true. Note the jsid id type -- id may be a string
192 * (Unicode property identifier) or an int (element index). The *vp out
193 * parameter, on success, is the new property value after the
197 (* JSStrictPropertyOp
)(JSContext
*cx
, JSObject
*obj
, jsid id
, JSBool strict
, jsval
*vp
);
200 * This function type is used for callbacks that enumerate the properties of
201 * a JSObject. The behavior depends on the value of enum_op:
204 * A new, opaque iterator state should be allocated and stored in *statep.
205 * (You can use PRIVATE_TO_JSVAL() to tag the pointer to be stored).
207 * The number of properties that will be enumerated should be returned as
208 * an integer jsval in *idp, if idp is non-null, and provided the number of
209 * enumerable properties is known. If idp is non-null and the number of
210 * enumerable properties can't be computed in advance, *idp should be set
213 * JSENUMERATE_INIT_ALL
214 * Used identically to JSENUMERATE_INIT, but exposes all properties of the
215 * object regardless of enumerability.
218 * A previously allocated opaque iterator state is passed in via statep.
219 * Return the next jsid in the iteration using *idp. The opaque iterator
220 * state pointed at by statep is destroyed and *statep is set to JSVAL_NULL
221 * if there are no properties left to enumerate.
223 * JSENUMERATE_DESTROY
224 * Destroy the opaque iterator state previously allocated in *statep by a
225 * call to this function when enum_op was JSENUMERATE_INIT or
226 * JSENUMERATE_INIT_ALL.
228 * The return value is used to indicate success, with a value of JS_FALSE
229 * indicating failure.
232 (* JSNewEnumerateOp
)(JSContext
*cx
, JSObject
*obj
, JSIterateOp enum_op
,
233 jsval
*statep
, jsid
*idp
);
236 * The old-style JSClass.enumerate op should define all lazy properties not
237 * yet reflected in obj.
240 (* JSEnumerateOp
)(JSContext
*cx
, JSObject
*obj
);
243 * Resolve a lazy property named by id in obj by defining it directly in obj.
244 * Lazy properties are those reflected from some peer native property space
245 * (e.g., the DOM attributes for a given node reflected as obj) on demand.
247 * JS looks for a property in an object, and if not found, tries to resolve
248 * the given id. If resolve succeeds, the engine looks again in case resolve
249 * defined obj[id]. If no such property exists directly in obj, the process
250 * is repeated with obj's prototype, etc.
252 * NB: JSNewResolveOp provides a cheaper way to resolve lazy properties.
255 (* JSResolveOp
)(JSContext
*cx
, JSObject
*obj
, jsid id
);
258 * Like JSResolveOp, but flags provide contextual information as follows:
260 * JSRESOLVE_QUALIFIED a qualified property id: obj.id or obj[id], not id
261 * JSRESOLVE_ASSIGNING obj[id] is on the left-hand side of an assignment
262 * JSRESOLVE_DETECTING 'if (o.p)...' or similar detection opcode sequence
263 * JSRESOLVE_DECLARING var, const, or function prolog declaration opcode
264 * JSRESOLVE_CLASSNAME class name used when constructing
266 * The *objp out parameter, on success, should be null to indicate that id
267 * was not resolved; and non-null, referring to obj or one of its prototypes,
268 * if id was resolved.
270 * This hook instead of JSResolveOp is called via the JSClass.resolve member
271 * if JSCLASS_NEW_RESOLVE is set in JSClass.flags.
273 * Setting JSCLASS_NEW_RESOLVE and JSCLASS_NEW_RESOLVE_GETS_START further
274 * extends this hook by passing in the starting object on the prototype chain
275 * via *objp. Thus a resolve hook implementation may define the property id
276 * being resolved in the object in which the id was first sought, rather than
277 * in a prototype object whose class led to the resolve hook being called.
279 * When using JSCLASS_NEW_RESOLVE_GETS_START, the resolve hook must therefore
280 * null *objp to signify "not resolved". With only JSCLASS_NEW_RESOLVE and no
281 * JSCLASS_NEW_RESOLVE_GETS_START, the hook can assume *objp is null on entry.
282 * This is not good practice, but enough existing hook implementations count
283 * on it that we can't break compatibility by passing the starting object in
284 * *objp without a new JSClass flag.
287 (* JSNewResolveOp
)(JSContext
*cx
, JSObject
*obj
, jsid id
, uintN flags
,
291 * Convert obj to the given type, returning true with the resulting value in
292 * *vp on success, and returning false on error or exception.
295 (* JSConvertOp
)(JSContext
*cx
, JSObject
*obj
, JSType type
, jsval
*vp
);
298 * Delegate typeof to an object so it can cloak a primitive or another object.
301 (* JSTypeOfOp
)(JSContext
*cx
, JSObject
*obj
);
304 * Finalize obj, which the garbage collector has determined to be unreachable
305 * from other live objects or from GC roots. Obviously, finalizers must never
306 * store a reference to obj.
309 (* JSFinalizeOp
)(JSContext
*cx
, JSObject
*obj
);
312 * Used by JS_AddExternalStringFinalizer and JS_RemoveExternalStringFinalizer
313 * to extend and reduce the set of string types finalized by the GC.
316 (* JSStringFinalizeOp
)(JSContext
*cx
, JSString
*str
);
319 * JSClass.checkAccess type: check whether obj[id] may be accessed per mode,
320 * returning false on error/exception, true on success with obj[id]'s last-got
321 * value in *vp, and its attributes in *attrsp. As for JSPropertyOp above, id
322 * is either a string or an int jsval.
325 (* JSCheckAccessOp
)(JSContext
*cx
, JSObject
*obj
, jsid id
, JSAccessMode mode
,
329 * Encode or decode an object, given an XDR state record representing external
330 * data. See jsxdrapi.h.
333 (* JSXDRObjectOp
)(JSXDRState
*xdr
, JSObject
**objp
);
336 * Check whether v is an instance of obj. Return false on error or exception,
337 * true on success with JS_TRUE in *bp if v is an instance of obj, JS_FALSE in
341 (* JSHasInstanceOp
)(JSContext
*cx
, JSObject
*obj
, const jsval
*v
, JSBool
*bp
);
344 * Deprecated function type for JSClass.mark. All new code should define
345 * JSTraceOp instead to ensure the traversal of traceable things stored in
346 * the native structures.
349 (* JSMarkOp
)(JSContext
*cx
, JSObject
*obj
, void *arg
);
352 * Function type for trace operation of the class called to enumerate all
353 * traceable things reachable from obj's private data structure. For each such
354 * thing, a trace implementation must call
356 * JS_CallTracer(trc, thing, kind);
358 * or one of its convenience macros as described in jsapi.h.
360 * JSTraceOp implementation can assume that no other threads mutates object
361 * state. It must not change state of the object or corresponding native
362 * structures. The only exception for this rule is the case when the embedding
363 * needs a tight integration with GC. In that case the embedding can check if
364 * the traversal is a part of the marking phase through calling
365 * JS_IsGCMarkingTracer and apply a special code like emptying caches or
366 * marking its native structures.
368 * To define the tracer for a JSClass, the implementation must add
369 * JSCLASS_MARK_IS_TRACE to class flags and use JS_CLASS_TRACE(method)
370 * macro below to convert JSTraceOp to JSMarkOp when initializing or
371 * assigning JSClass.mark field.
374 (* JSTraceOp
)(JSTracer
*trc
, JSObject
*obj
);
376 #if defined __GNUC__ && __GNUC__ >= 4 && !defined __cplusplus
377 # define JS_CLASS_TRACE(method) \
378 (__builtin_types_compatible_p(JSTraceOp, __typeof(&(method))) \
379 ? (JSMarkOp)(method) \
380 : js_WrongTypeForClassTracer)
382 extern JSMarkOp js_WrongTypeForClassTracer
;
385 # define JS_CLASS_TRACE(method) ((JSMarkOp)(method))
389 * Tracer callback, called for each traceable thing directly referenced by a
390 * particular object or runtime structure. It is the callback responsibility
391 * to ensure the traversal of the full object graph via calling eventually
392 * JS_TraceChildren on the passed thing. In this case the callback must be
393 * prepared to deal with cycles in the traversal graph.
395 * kind argument is one of JSTRACE_OBJECT, JSTRACE_STRING or a tag denoting
396 * internal implementation-specific traversal kind. In the latter case the only
397 * operations on thing that the callback can do is to call JS_TraceChildren or
398 * DEBUG-only JS_PrintTraceThingInfo.
401 (* JSTraceCallback
)(JSTracer
*trc
, void *thing
, uint32 kind
);
404 * DEBUG only callback that JSTraceOp implementation can provide to return
405 * a string describing the reference traced with JS_CallTracer.
408 (* JSTraceNamePrinter
)(JSTracer
*trc
, char *buf
, size_t bufsize
);
411 (* JSEqualityOp
)(JSContext
*cx
, JSObject
*obj
, const jsval
*v
, JSBool
*bp
);
414 * Typedef for native functions called by the JS VM.
416 * See jsapi.h, the JS_CALLEE, JS_THIS, etc. macros.
420 (* JSNative
)(JSContext
*cx
, uintN argc
, jsval
*vp
);
422 /* Callbacks and their arguments. */
424 typedef enum JSContextOp
{
430 * The possible values for contextOp when the runtime calls the callback are:
431 * JSCONTEXT_NEW JS_NewContext successfully created a new JSContext
432 * instance. The callback can initialize the instance as
433 * required. If the callback returns false, the instance
434 * will be destroyed and JS_NewContext returns null. In
435 * this case the callback is not called again.
436 * JSCONTEXT_DESTROY One of JS_DestroyContext* methods is called. The
437 * callback may perform its own cleanup and must always
439 * Any other value For future compatibility the callback must do nothing
440 * and return true in this case.
443 (* JSContextCallback
)(JSContext
*cx
, uintN contextOp
);
445 #ifndef JS_THREADSAFE
447 (* JSHeartbeatCallback
)(JSRuntime
*rt
);
450 typedef enum JSGCStatus
{
458 (* JSGCCallback
)(JSContext
*cx
, JSGCStatus status
);
461 * Generic trace operation that calls JS_CallTracer on each traceable thing
465 (* JSTraceDataOp
)(JSTracer
*trc
, void *data
);
468 (* JSOperationCallback
)(JSContext
*cx
);
471 * Deprecated form of JSOperationCallback.
474 (* JSBranchCallback
)(JSContext
*cx
, JSScript
*script
);
477 (* JSErrorReporter
)(JSContext
*cx
, const char *message
, JSErrorReport
*report
);
480 * Possible exception types. These types are part of a JSErrorFormatString
481 * structure. They define which error to throw in case of a runtime error.
482 * JSEXN_NONE marks an unthrowable error.
484 typedef enum JSExnType
{
497 typedef struct JSErrorFormatString
{
498 /* The error format string (UTF-8 if js_CStringsAreUTF8). */
501 /* The number of arguments to expand in the formatted error message. */
504 /* One of the JSExnType constants above. */
506 } JSErrorFormatString
;
508 typedef const JSErrorFormatString
*
509 (* JSErrorCallback
)(void *userRef
, const char *locale
,
510 const uintN errorNumber
);
513 #define JS_ARGUMENT_FORMATTER_DEFINED 1
516 (* JSArgumentFormatter
)(JSContext
*cx
, const char *format
, JSBool fromJS
,
517 jsval
**vpp
, va_list *app
);
521 (* JSLocaleToUpperCase
)(JSContext
*cx
, JSString
*src
, jsval
*rval
);
524 (* JSLocaleToLowerCase
)(JSContext
*cx
, JSString
*src
, jsval
*rval
);
527 (* JSLocaleCompare
)(JSContext
*cx
, JSString
*src1
, JSString
*src2
,
531 (* JSLocaleToUnicode
)(JSContext
*cx
, const char *src
, jsval
*rval
);
534 * Security protocol types.
536 typedef struct JSPrincipals JSPrincipals
;
539 * XDR-encode or -decode a principals instance, based on whether xdr->mode is
540 * JSXDR_ENCODE, in which case *principalsp should be encoded; or JSXDR_DECODE,
541 * in which case implementations must return a held (via JSPRINCIPALS_HOLD),
542 * non-null *principalsp out parameter. Return true on success, false on any
543 * error, which the implementation must have reported.
546 (* JSPrincipalsTranscoder
)(JSXDRState
*xdr
, JSPrincipals
**principalsp
);
549 * Return a weak reference to the principals associated with obj, possibly via
550 * the immutable parent chain leading from obj to a top-level container (e.g.,
551 * a window object in the DOM level 0). If there are no principals associated
552 * with obj, return null. Therefore null does not mean an error was reported;
553 * in no event should an error be reported or an exception be thrown by this
554 * callback's implementation.
556 typedef JSPrincipals
*
557 (* JSObjectPrincipalsFinder
)(JSContext
*cx
, JSObject
*obj
);
560 * Used to check if a CSP instance wants to disable eval() and friends.
561 * See js_CheckCSPPermitsJSAction() in jsobj.
564 (* JSCSPEvalChecker
)(JSContext
*cx
);
567 * Callback used to ask the embedding for the cross compartment wrapper handler
568 * that implements the desired prolicy for this kind of object in the
569 * destination compartment.
572 (* JSWrapObjectCallback
)(JSContext
*cx
, JSObject
*obj
, JSObject
*proto
, JSObject
*parent
,
576 * Callback used by the wrap hook to ask the embedding to prepare an object
577 * for wrapping in a context. This might include unwrapping other wrappers
578 * or even finding a more suitable object for the new compartment.
581 (* JSPreWrapCallback
)(JSContext
*cx
, JSObject
*scope
, JSObject
*obj
, uintN flags
);
584 JSCOMPARTMENT_NEW
, /* XXX Does it make sense to have a NEW? */
585 JSCOMPARTMENT_DESTROY
589 (* JSCompartmentCallback
)(JSContext
*cx
, JSCompartment
*compartment
, uintN compartmentOp
);
592 * Read structured data from the reader r. This hook is used to read a value
593 * previously serialized by a call to the WriteStructuredCloneOp hook.
595 * tag and data are the pair of uint32 values from the header. The callback may
596 * use the JS_Read* APIs to read any other relevant parts of the object from
597 * the reader r. closure is any value passed to the JS_ReadStructuredClone
598 * function. Return the new object on success, NULL on error/exception.
600 typedef JSObject
*(*ReadStructuredCloneOp
)(JSContext
*cx
, JSStructuredCloneReader
*r
,
601 uint32 tag
, uint32 data
, void *closure
);
604 * Structured data serialization hook. The engine can write primitive values,
605 * Objects, Arrays, Dates, RegExps, TypedArrays, and ArrayBuffers. Any other
606 * type of object requires application support. This callback must first use
607 * the JS_WriteUint32Pair API to write an object header, passing a value
608 * greater than JS_SCTAG_USER to the tag parameter. Then it can use the
609 * JS_Write* APIs to write any other relevant parts of the value v to the
610 * writer w. closure is any value passed to the JS_WriteStructuredCLone function.
612 * Return true on success, false on error/exception.
614 typedef JSBool (*WriteStructuredCloneOp
)(JSContext
*cx
, JSStructuredCloneWriter
*w
,
615 JSObject
*obj
, void *closure
);
618 * This is called when JS_WriteStructuredClone finds that the object to be
619 * written is recursive. To follow HTML5, the application must throw a
620 * DATA_CLONE_ERR DOMException. errorid is always JS_SCERR_RECURSION.
622 typedef void (*StructuredCloneErrorOp
)(JSContext
*cx
, uint32 errorid
);
626 #endif /* jspubtd_h___ */