1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=99:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is Mozilla Communicator client code, released
20 * The Initial Developer of the Original Code is
21 * Netscape Communications Corporation.
22 * Portions created by the Initial Developer are Copyright (C) 1998
23 * the Initial Developer. All Rights Reserved.
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
52 extern JS_PUBLIC_API(JSCrossCompartmentCall *)
53 JS_EnterCrossCompartmentCallScript(JSContext *cx, JSScript *target);
60 class JS_PUBLIC_API(AutoEnterScriptCompartment)
62 JSCrossCompartmentCall *call;
65 AutoEnterScriptCompartment() : call(NULL) {}
67 bool enter(JSContext *cx, JSScript *target);
69 bool entered() const { return call != NULL; }
71 ~AutoEnterScriptCompartment() {
72 if (call && call != reinterpret_cast<JSCrossCompartmentCall*>(1))
73 JS_LeaveCrossCompartmentCall(call);
82 extern JS_PUBLIC_API(JSScript *)
83 JS_GetScriptFromObject(JSObject *scriptObject);
85 extern JS_PUBLIC_API(JSString *)
86 JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, uintN indent);
89 * Currently, we only support runtime-wide debugging. In the future, we should
90 * be able to support compartment-wide debugging.
92 extern JS_PUBLIC_API(void)
93 JS_SetRuntimeDebugMode(JSRuntime *rt, JSBool debug);
96 * Debug mode is a compartment-wide mode that enables a debugger to attach
97 * to and interact with running methodjit-ed frames. In particular, it causes
98 * every function to be compiled as if an eval was present (so eval-in-frame)
99 * can work, and it ensures that functions can be re-JITed for other debug
100 * features. In general, it is not safe to interact with frames that were live
101 * before debug mode was enabled. For this reason, it is also not safe to
102 * enable debug mode while frames are live.
105 /* Get current state of debugging mode. */
106 extern JS_PUBLIC_API(JSBool)
107 JS_GetDebugMode(JSContext *cx);
110 * Turn on/off debugging mode for a single compartment. This must be
111 * called from the main thread and the compartment must be associated
112 * with the main thread.
114 JS_FRIEND_API(JSBool)
115 JS_SetDebugModeForCompartment(JSContext *cx, JSCompartment *comp, JSBool debug);
118 * Turn on/off debugging mode for a context's compartment.
120 JS_FRIEND_API(JSBool)
121 JS_SetDebugMode(JSContext *cx, JSBool debug);
123 /* Turn on single step mode. Requires debug mode. */
124 extern JS_FRIEND_API(JSBool)
125 js_SetSingleStepMode(JSContext *cx, JSScript *script, JSBool singleStep);
127 /* Turn on single step mode. */
128 extern JS_PUBLIC_API(JSBool)
129 JS_SetSingleStepMode(JSContext *cx, JSScript *script, JSBool singleStep);
132 * Unexported library-private helper used to unpatch all traps in a script.
133 * Returns script->code if script has no traps, else a JS_malloc'ed copy of
134 * script->code which the caller must JS_free, or null on JS_malloc OOM.
137 js_UntrapScriptCode(JSContext *cx, JSScript *script);
139 /* The closure argument will be marked. */
140 extern JS_PUBLIC_API(JSBool)
141 JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
142 JSTrapHandler handler, jsval closure);
144 extern JS_PUBLIC_API(JSOp)
145 JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc);
147 extern JS_PUBLIC_API(void)
148 JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
149 JSTrapHandler *handlerp, jsval *closurep);
151 extern JS_PUBLIC_API(void)
152 JS_ClearScriptTraps(JSContext *cx, JSScript *script);
154 extern JS_PUBLIC_API(void)
155 JS_ClearAllTraps(JSContext *cx);
157 extern JS_PUBLIC_API(JSTrapStatus)
158 JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval);
160 extern JS_PUBLIC_API(JSBool)
161 JS_SetInterrupt(JSRuntime *rt, JSInterruptHook handler, void *closure);
163 extern JS_PUBLIC_API(JSBool)
164 JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep);
166 /************************************************************************/
168 extern JS_PUBLIC_API(JSBool)
169 JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id,
170 JSWatchPointHandler handler, JSObject *closure);
172 extern JS_PUBLIC_API(JSBool)
173 JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id,
174 JSWatchPointHandler *handlerp, JSObject **closurep);
176 extern JS_PUBLIC_API(JSBool)
177 JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj);
179 extern JS_PUBLIC_API(JSBool)
180 JS_ClearAllWatchPoints(JSContext *cx);
182 #ifdef JS_HAS_OBJ_WATCHPOINT
184 * Hide these non-API function prototypes by testing whether the internal
185 * header file "jsversion.h" has been included.
188 js_TraceWatchPoints(JSTracer *trc, JSObject *obj);
191 js_SweepWatchPoints(JSContext *cx);
196 js_watch_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp);
201 IsWatchedProperty(JSContext *cx, const Shape *shape);
207 #endif /* JS_HAS_OBJ_WATCHPOINT */
209 /************************************************************************/
211 extern JS_PUBLIC_API(uintN)
212 JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
214 extern JS_PUBLIC_API(jsbytecode *)
215 JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno);
217 extern JS_PUBLIC_API(jsbytecode *)
218 JS_EndPC(JSContext *cx, JSScript *script);
220 extern JS_PUBLIC_API(uintN)
221 JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun);
223 extern JS_PUBLIC_API(JSBool)
224 JS_FunctionHasLocalNames(JSContext *cx, JSFunction *fun);
227 * N.B. The mark is in the context temp pool and thus the caller must take care
228 * to call JS_ReleaseFunctionLocalNameArray in a LIFO manner (wrt to any other
229 * call that may use the temp pool.
231 extern JS_PUBLIC_API(jsuword *)
232 JS_GetFunctionLocalNameArray(JSContext *cx, JSFunction *fun, void **markp);
234 extern JS_PUBLIC_API(JSAtom *)
235 JS_LocalNameToAtom(jsuword w);
237 extern JS_PUBLIC_API(JSString *)
238 JS_AtomKey(JSAtom *atom);
240 extern JS_PUBLIC_API(void)
241 JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark);
243 extern JS_PUBLIC_API(JSScript *)
244 JS_GetFunctionScript(JSContext *cx, JSFunction *fun);
246 extern JS_PUBLIC_API(JSNative)
247 JS_GetFunctionNative(JSContext *cx, JSFunction *fun);
249 extern JS_PUBLIC_API(JSPrincipals *)
250 JS_GetScriptPrincipals(JSContext *cx, JSScript *script);
253 * Stack Frame Iterator
255 * Used to iterate through the JS stack frames to extract
256 * information from the frames.
259 extern JS_PUBLIC_API(JSStackFrame *)
260 JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp);
262 extern JS_PUBLIC_API(JSScript *)
263 JS_GetFrameScript(JSContext *cx, JSStackFrame *fp);
265 extern JS_PUBLIC_API(jsbytecode *)
266 JS_GetFramePC(JSContext *cx, JSStackFrame *fp);
269 * Get the closest scripted frame below fp. If fp is null, start from cx->fp.
271 extern JS_PUBLIC_API(JSStackFrame *)
272 JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp);
275 * Return a weak reference to fp's principals. A null return does not denote
276 * an error, it means there are no principals.
278 extern JSPrincipals *
279 js_StackFramePrincipals(JSContext *cx, JSStackFrame *fp);
282 js_EvalFramePrincipals(JSContext *cx, JSObject *callee, JSStackFrame *caller);
284 extern JS_PUBLIC_API(void *)
285 JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp);
287 extern JS_PUBLIC_API(void)
288 JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation);
290 extern JS_PUBLIC_API(void *)
291 JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp);
293 extern JS_PUBLIC_API(JSBool)
294 JS_IsScriptFrame(JSContext *cx, JSStackFrame *fp);
296 /* this is deprecated, use JS_GetFrameScopeChain instead */
297 extern JS_PUBLIC_API(JSObject *)
298 JS_GetFrameObject(JSContext *cx, JSStackFrame *fp);
300 extern JS_PUBLIC_API(JSObject *)
301 JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp);
303 extern JS_PUBLIC_API(JSObject *)
304 JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp);
306 extern JS_PUBLIC_API(JSBool)
307 JS_GetFrameThis(JSContext *cx, JSStackFrame *fp, jsval *thisv);
309 extern JS_PUBLIC_API(JSFunction *)
310 JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp);
312 extern JS_PUBLIC_API(JSObject *)
313 JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp);
315 /* XXXrginda Initially published with typo */
316 #define JS_IsContructorFrame JS_IsConstructorFrame
317 extern JS_PUBLIC_API(JSBool)
318 JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp);
320 extern JS_PUBLIC_API(JSBool)
321 JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp);
323 extern JS_PUBLIC_API(jsval)
324 JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp);
326 extern JS_PUBLIC_API(void)
327 JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval);
330 * Return fp's callee function object (fp->callee) if it has one. Note that
331 * this API cannot fail. A null return means "no callee": fp is a global or
332 * eval-from-global frame, not a call frame.
334 * This API began life as an infallible getter, but now it can return either:
336 * 1. An optimized closure that was compiled assuming the function could not
337 * escape and be called from sites the compiler could not see.
339 * 2. A "joined function object", an optimization whereby SpiderMonkey avoids
340 * creating fresh function objects for every evaluation of a function
341 * expression that is used only once by a consumer that either promises to
342 * clone later when asked for the value or that cannot leak the value.
344 * Because Mozilla's Gecko embedding of SpiderMonkey (and no doubt other
345 * embeddings) calls this API in potentially performance-sensitive ways (e.g.
346 * in nsContentUtils::GetDocumentFromCaller), we are leaving this API alone. It
347 * may now return an unwrapped non-escaping optimized closure, or a joined
348 * function object. Such optimized objects may work well if called from the
349 * correct context, never mutated or compared for identity, etc.
351 * However, if you really need to get the same callee object that JS code would
352 * see, which means undoing the optimizations, where an undo attempt can fail,
353 * then use JS_GetValidFrameCalleeObject.
355 extern JS_PUBLIC_API(JSObject *)
356 JS_GetFrameCalleeObject(JSContext *cx, JSStackFrame *fp);
359 * Return fp's callee function object after running the deferred closure
360 * cloning "method read barrier". This API can fail! If the frame has no
361 * callee, this API returns true with JSVAL_IS_VOID(*vp).
363 extern JS_PUBLIC_API(JSBool)
364 JS_GetValidFrameCalleeObject(JSContext *cx, JSStackFrame *fp, jsval *vp);
366 /************************************************************************/
368 extern JS_PUBLIC_API(const char *)
369 JS_GetScriptFilename(JSContext *cx, JSScript *script);
371 extern JS_PUBLIC_API(uintN)
372 JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script);
374 extern JS_PUBLIC_API(uintN)
375 JS_GetScriptLineExtent(JSContext *cx, JSScript *script);
377 extern JS_PUBLIC_API(JSVersion)
378 JS_GetScriptVersion(JSContext *cx, JSScript *script);
380 /************************************************************************/
383 * Hook setters for script creation and destruction, see jsprvtd.h for the
384 * typedefs. These macros provide binary compatibility and newer, shorter
387 #define JS_SetNewScriptHook JS_SetNewScriptHookProc
388 #define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc
390 extern JS_PUBLIC_API(void)
391 JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata);
393 extern JS_PUBLIC_API(void)
394 JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
397 /************************************************************************/
399 extern JS_PUBLIC_API(JSBool)
400 JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
401 const jschar *chars, uintN length,
402 const char *filename, uintN lineno,
405 extern JS_PUBLIC_API(JSBool)
406 JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
407 const char *bytes, uintN length,
408 const char *filename, uintN lineno,
411 /************************************************************************/
413 typedef struct JSPropertyDesc {
414 jsval id; /* primary id, atomized string, or int */
415 jsval value; /* property value */
416 uint8 flags; /* flags, see below */
417 uint8 spare; /* unused */
418 uint16 slot; /* argument/variable slot */
419 jsval alias; /* alias id if JSPD_ALIAS flag */
422 #define JSPD_ENUMERATE 0x01 /* visible to for/in loop */
423 #define JSPD_READONLY 0x02 /* assignment is error */
424 #define JSPD_PERMANENT 0x04 /* property cannot be deleted */
425 #define JSPD_ALIAS 0x08 /* property has an alias id */
426 #define JSPD_ARGUMENT 0x10 /* argument to function */
427 #define JSPD_VARIABLE 0x20 /* local variable in function */
428 #define JSPD_EXCEPTION 0x40 /* exception occurred fetching the property, */
429 /* value is exception */
430 #define JSPD_ERROR 0x80 /* native getter returned JS_FALSE without */
431 /* throwing an exception */
433 typedef struct JSPropertyDescArray {
434 uint32 length; /* number of elements in array */
435 JSPropertyDesc *array; /* alloc'd by Get, freed by Put */
436 } JSPropertyDescArray;
438 typedef struct JSScopeProperty JSScopeProperty;
440 extern JS_PUBLIC_API(JSScopeProperty *)
441 JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp);
443 extern JS_PUBLIC_API(JSBool)
444 JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *shape,
447 extern JS_PUBLIC_API(JSBool)
448 JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda);
450 extern JS_PUBLIC_API(void)
451 JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda);
453 /************************************************************************/
455 extern JS_PUBLIC_API(JSBool)
456 JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure);
458 extern JS_PUBLIC_API(JSBool)
459 JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure);
461 extern JS_PUBLIC_API(JSBool)
462 JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
464 extern JS_PUBLIC_API(JSBool)
465 JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
467 extern JS_PUBLIC_API(JSBool)
468 JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure);
470 extern JS_PUBLIC_API(JSBool)
471 JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure);
473 /************************************************************************/
475 extern JS_PUBLIC_API(size_t)
476 JS_GetObjectTotalSize(JSContext *cx, JSObject *obj);
478 extern JS_PUBLIC_API(size_t)
479 JS_GetFunctionTotalSize(JSContext *cx, JSFunction *fun);
481 extern JS_PUBLIC_API(size_t)
482 JS_GetScriptTotalSize(JSContext *cx, JSScript *script);
485 * Get the top-most running script on cx starting from fp, or from the top of
486 * cx's frame stack if fp is null, and return its script filename flags. If
487 * the script has a null filename member, return JSFILENAME_NULL.
489 extern JS_PUBLIC_API(uint32)
490 JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp);
493 * Get the script filename flags for the script. If the script doesn't have a
494 * filename, return JSFILENAME_NULL.
496 extern JS_PUBLIC_API(uint32)
497 JS_GetScriptFilenameFlags(JSScript *script);
500 * Associate flags with a script filename prefix in rt, so that any subsequent
501 * script compilation will inherit those flags if the script's filename is the
502 * same as prefix, or if prefix is a substring of the script's filename.
504 * The API defines only one flag bit, JSFILENAME_SYSTEM, leaving the remaining
505 * 31 bits up to the API client to define. The union of all 32 bits must not
506 * be a legal combination, however, in order to preserve JSFILENAME_NULL as a
507 * unique value. API clients may depend on JSFILENAME_SYSTEM being a set bit
508 * in JSFILENAME_NULL -- a script with a null filename member is presumed to
509 * be a "system" script.
511 extern JS_PUBLIC_API(JSBool)
512 JS_FlagScriptFilenamePrefix(JSRuntime *rt, const char *prefix, uint32 flags);
514 #define JSFILENAME_NULL 0xffffffff /* null script filename */
515 #define JSFILENAME_SYSTEM 0x00000001 /* "system" script, see below */
516 #define JSFILENAME_PROTECTED 0x00000002 /* scripts need protection */
519 * Return true if obj is a "system" object, that is, one created by
520 * JS_NewSystemObject with the system flag set and not JS_NewObject.
522 * What "system" means is up to the API client, but it can be used to implement
523 * access control policies based on script filenames and their prefixes, using
524 * JS_FlagScriptFilenamePrefix and JS_GetTopScriptFilenameFlags.
526 extern JS_PUBLIC_API(JSBool)
527 JS_IsSystemObject(JSContext *cx, JSObject *obj);
530 * Mark an object as being a system object. This should be called immediately
531 * after allocating the object. A system object is an object for which
532 * JS_IsSystemObject returns true.
534 extern JS_PUBLIC_API(JSBool)
535 JS_MakeSystemObject(JSContext *cx, JSObject *obj);
537 /************************************************************************/
539 extern JS_PUBLIC_API(JSObject *)
540 JS_UnwrapObject(JSContext *cx, JSObject *obj);
542 /************************************************************************/
544 extern JS_FRIEND_API(void)
545 js_RevertVersion(JSContext *cx);
547 extern JS_PUBLIC_API(const JSDebugHooks *)
548 JS_GetGlobalDebugHooks(JSRuntime *rt);
550 extern JS_PUBLIC_API(JSDebugHooks *)
551 JS_SetContextDebugHooks(JSContext *cx, const JSDebugHooks *hooks);
553 /* Disable debug hooks for this context. */
554 extern JS_PUBLIC_API(JSDebugHooks *)
555 JS_ClearContextDebugHooks(JSContext *cx);
557 extern JS_PUBLIC_API(JSBool)
560 extern JS_PUBLIC_API(void)
563 extern JS_PUBLIC_API(JSBool)
564 JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj);
568 extern JS_FRIEND_API(JSBool)
569 js_StopCallgrind(JSContext *cx, uintN argc, jsval *vp);
571 extern JS_FRIEND_API(JSBool)
572 js_StartCallgrind(JSContext *cx, uintN argc, jsval *vp);
574 extern JS_FRIEND_API(JSBool)
575 js_DumpCallgrind(JSContext *cx, uintN argc, jsval *vp);
577 #endif /* MOZ_CALLGRIND */
581 extern JS_FRIEND_API(JSBool)
582 js_StartVtune(JSContext *cx, uintN argc, jsval *vp);
584 extern JS_FRIEND_API(JSBool)
585 js_StopVtune(JSContext *cx, uintN argc, jsval *vp);
587 extern JS_FRIEND_API(JSBool)
588 js_PauseVtune(JSContext *cx, uintN argc, jsval *vp);
590 extern JS_FRIEND_API(JSBool)
591 js_ResumeVtune(JSContext *cx, uintN argc, jsval *vp);
593 #endif /* MOZ_VTUNE */
596 extern JS_FRIEND_API(JSBool)
597 js_InitEthogram(JSContext *cx, uintN argc, jsval *vp);
598 extern JS_FRIEND_API(JSBool)
599 js_ShutdownEthogram(JSContext *cx, uintN argc, jsval *vp);
600 #endif /* MOZ_TRACEVIS */
602 #ifdef MOZ_TRACE_JSCALLS
603 typedef void (*JSFunctionCallback)(const JSFunction *fun,
609 * The callback is expected to be quick and noninvasive. It should not
610 * trigger interrupts, turn on debugging, or produce uncaught JS
611 * exceptions. The state of the stack and registers in the context
612 * cannot be relied upon, since this callback may be invoked directly
613 * from either JIT. The 'entering' field means we are entering a
614 * function if it is positive, leaving a function if it is zero or
617 extern JS_PUBLIC_API(void)
618 JS_SetFunctionCallback(JSContext *cx, JSFunctionCallback fcb);
620 extern JS_PUBLIC_API(JSFunctionCallback)
621 JS_GetFunctionCallback(JSContext *cx);
622 #endif /* MOZ_TRACE_JSCALLS */
626 #endif /* jsdbgapi_h___ */