js/jsd/jsdebug.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     3  * This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /*
     8  * Header for JavaScript Debugging support - All public functions
     9  */
    11 #ifndef jsdebug_h___
    12 #define jsdebug_h___
    14 #include "jstypes.h"
    15 #include "js/TypeDecls.h"
    17 extern "C" {
    19 /*
    20  * The linkage of JSD API functions differs depending on whether the file is
    21  * used within the JSD library or not.  Any source file within the JSD
    22  * libraray should define EXPORT_JSD_API whereas any client of the library
    23  * should not.
    24  */
    25 #ifdef EXPORT_JSD_API
    26 #define JSD_PUBLIC_API(t)    JS_EXPORT_API(t)
    27 #define JSD_PUBLIC_DATA(t)   JS_EXPORT_DATA(t)
    28 #else
    29 #define JSD_PUBLIC_API(t)    JS_IMPORT_API(t)
    30 #define JSD_PUBLIC_DATA(t)   JS_IMPORT_DATA(t)
    31 #endif
    33 #define JSD_FRIEND_API(t)    JSD_PUBLIC_API(t)
    34 #define JSD_FRIEND_DATA(t)   JSD_PUBLIC_DATA(t)
    36 /***************************************************************************/
    37 /* Opaque typedefs for handles */
    39 typedef struct JSDContext        JSDContext;
    40 typedef struct JSDScript         JSDScript;
    41 typedef struct JSDSourceText     JSDSourceText;
    42 typedef struct JSDThreadState    JSDThreadState;
    43 typedef struct JSDStackFrameInfo JSDStackFrameInfo;
    44 typedef struct JSDValue          JSDValue;
    45 typedef struct JSDProperty       JSDProperty;
    46 typedef struct JSDObject         JSDObject;
    48 /***************************************************************************/
    49 /* High Level calls */
    51 /*
    52 * callback stuff for calls in EXE to be accessed by this code
    53 * when it lives in an explicitly loaded DLL
    54 */
    56 /*
    57 * This callback allows JSD to inform the embedding when JSD has been
    58 * turned on or off. This is especially useful in the Java-based debugging
    59 * system used in mozilla because the debugger applet controls starting
    60 * up the JSD system.
    61 */
    62 typedef void
    63 (* JSD_SetContextProc)(JSDContext* jsdc, void* user);
    65 /* This struct could have more fields in future versions */
    66 typedef struct
    67 {
    68     unsigned              size;       /* size of this struct (init before use)*/
    69     JSD_SetContextProc setContext;
    70 } JSD_UserCallbacks;
    72 /*
    73 * Used by an embedding to tell JSD what JSRuntime to use and to set
    74 * callbacks without starting up JSD. This assumes only one JSRuntime
    75 * will be used. This exists to support the mozilla Java-based debugger
    76 * system.
    77 */
    78 extern JSD_PUBLIC_API(void)
    79 JSD_SetUserCallbacks(JSRuntime*         jsrt,
    80                      JSD_UserCallbacks* callbacks,
    81                      void*              user);
    83 /*
    84 * Startup JSD.
    85 * This version of the init function requires that JSD_SetUserCallbacks()
    86 * has been previously called (with a non-nullptr callback struct pointer)
    87 */
    88 extern JSD_PUBLIC_API(JSDContext*)
    89 JSD_DebuggerOn(void);
    91 /*
    92 * Startup JSD on a particular JSRuntime with (optional) callbacks
    93 */
    94 extern JSD_PUBLIC_API(JSDContext*)
    95 JSD_DebuggerOnForUser(JSRuntime*         jsrt,
    96                       JSD_UserCallbacks* callbacks,
    97                       void*              user);
    99 /*
   100  * Startup JSD in an application that uses compartments. Debugger
   101  * objects will be allocated in the same compartment as scopeobj.
   102  */
   103 extern JSD_PUBLIC_API(JSDContext*)
   104 JSD_DebuggerOnForUserWithCompartment(JSRuntime*         jsrt,
   105                                      JSD_UserCallbacks* callbacks,
   106                                      void*              user,
   107                                      JSObject*          scopeobj);
   109 /*
   110 * Shutdown JSD for this JSDContext
   111 */
   112 extern JSD_PUBLIC_API(void)
   113 JSD_DebuggerOff(JSDContext* jsdc);
   115 /*
   116  * Pause JSD for this JSDContext
   117  */
   118 extern JSD_PUBLIC_API(void)
   119 JSD_DebuggerPause(JSDContext* jsdc);
   121 /*
   122  * Unpause JSD for this JSDContext
   123  */
   124 extern JSD_PUBLIC_API(void)
   125 JSD_DebuggerUnpause(JSDContext* jsdc);
   127 /*
   128 * Get the Major Version (initial JSD release used major version = 1)
   129 */
   130 extern JSD_PUBLIC_API(unsigned)
   131 JSD_GetMajorVersion(void);
   133 /*
   134 * Get the Minor Version (initial JSD release used minor version = 0)
   135 */
   136 extern JSD_PUBLIC_API(unsigned)
   137 JSD_GetMinorVersion(void);
   139 /*
   140 * Returns the default JSD global associated with a given JSDContext.
   141 */
   142 extern JSD_PUBLIC_API(JSObject*)
   143 JSD_GetDefaultGlobal(JSDContext* jsdc);
   145 /*
   146 * Returns a JSRuntime this context is associated with
   147 */
   148 extern JSD_PUBLIC_API(JSRuntime*)
   149 JSD_GetJSRuntime(JSDContext* jsdc);
   151 /*
   152 * Set the private data for this context, returns previous value
   153 */
   154 extern JSD_PUBLIC_API(void *)
   155 JSD_SetContextPrivate(JSDContext *jsdc, void *data);
   157 /*
   158 * Get the private data for this context
   159 */
   160 extern JSD_PUBLIC_API(void *)
   161 JSD_GetContextPrivate(JSDContext *jsdc);
   163 /*
   164 * Clear profile data for all scripts
   165 */
   166 extern JSD_PUBLIC_API(void)
   167 JSD_ClearAllProfileData(JSDContext* jsdc);
   169 /*
   170 * Context flags.
   171 */
   173 /* Include native frames in JSDThreadStates. */
   174 #define JSD_INCLUDE_NATIVE_FRAMES 0x01
   175 /*
   176 * Normally, if a script has a 0 in JSD_SCRIPT_PROFILE_BIT it is included in
   177 * profile data, otherwise it is not profiled.  Setting the JSD_PROFILE_WHEN_SET
   178 * flag reverses this convention.
   179 */
   180 #define JSD_PROFILE_WHEN_SET      0x02
   181 /*
   182 * Normally, when the script in the top frame of a thread state has a 1 in
   183 * JSD_SCRIPT_DEBUG_BIT, the execution hook is ignored.  Setting the
   184 * JSD_DEBUG_WHEN_SET flag reverses this convention.
   185 */
   186 #define JSD_DEBUG_WHEN_SET        0x04
   187 /*
   188 * When this flag is set the internal call hook will collect profile data.
   189 */
   190 #define JSD_COLLECT_PROFILE_DATA  0x08
   191 /*
   192 * When this flag is set, stack frames that are disabled for debugging
   193 * will not appear in the call stack chain.
   194 */
   195 #define JSD_HIDE_DISABLED_FRAMES  0x10
   196 /*
   197 * When this flag is set, the debugger will only check the
   198 * JSD_SCRIPT_DEBUG_BIT on the top (most recent) stack frame.  This
   199 * makes it possible to stop in an enabled frame which was called from
   200 * a stack that contains a disabled frame.
   201 *
   202 * When this flag is *not* set, any stack that contains a disabled frame
   203 * will not be debugged (the execution hook will not be invoked.)
   204 *
   205 * This only applies when the reason for calling the hook would have
   206 * been JSD_HOOK_INTERRUPTED or JSD_HOOK_THROW.  JSD_HOOK_BREAKPOINT,
   207 * JSD_HOOK_DEBUG_REQUESTED, and JSD_HOOK_DEBUGGER_KEYWORD always stop,
   208 * regardless of this setting, as long as the top frame is not disabled.
   209 *
   210 * If JSD_HIDE_DISABLED_FRAMES is set, this is effectively set as well.
   211 */
   212 #define JSD_MASK_TOP_FRAME_ONLY   0x20
   214 /*
   215 * 0x40 was formerly used to hook into object creation.
   216 */
   217 #define JSD_DISABLE_OBJECT_TRACE_RETIRED 0x40
   220 extern JSD_PUBLIC_API(void)
   221 JSD_SetContextFlags (JSDContext* jsdc, uint32_t flags);
   223 extern JSD_PUBLIC_API(uint32_t)
   224 JSD_GetContextFlags (JSDContext* jsdc);     
   226 /*
   227 * Notify JSD that this JSContext is 'in use'. This allows JSD to hook the
   228 * ErrorReporter. For the most part this is done automatically whenever
   229 * events like script loading happen. But, it is a good idea to call this
   230 * from the embedding when new contexts come into use.
   231 */
   232 extern JSD_PUBLIC_API(void)
   233 JSD_JSContextInUse(JSDContext* jsdc, JSContext* context);
   235 /*
   236 * Find the JSDContext (if any) associated with the JSRuntime of a
   237 * given JSContext.
   238 */
   239 extern JSD_PUBLIC_API(JSDContext*)
   240 JSD_JSDContextForJSContext(JSContext* context);
   242 /***************************************************************************/
   243 /* Script functions */
   245 /*
   246 * Lock the entire script subsystem. This grabs a highlevel lock that
   247 * protects the JSD internal information about scripts. It is important
   248 * to wrap script related calls in this lock in multithreaded situations
   249 * -- i.e. where the debugger is running on a different thread than the
   250 * interpreter -- or when multiple debugger threads may be accessing this
   251 * subsystem. It is safe (and best) to use this locking even if the
   252 * environment might not be multi-threaded. Safely nestable.
   253 */
   254 extern JSD_PUBLIC_API(void)
   255 JSD_LockScriptSubsystem(JSDContext* jsdc);
   257 /*
   258 * Unlock the entire script subsystem -- see JSD_LockScriptSubsystem
   259 */
   260 extern JSD_PUBLIC_API(void)
   261 JSD_UnlockScriptSubsystem(JSDContext* jsdc);
   263 /*
   264 * Iterate through all the active scripts for this JSDContext.
   265 * NOTE: must initialize iterp to nullptr to start iteration.
   266 * NOTE: must lock and unlock the subsystem
   267 * example:
   268 *
   269 *  JSDScript jsdscript;
   270 *  JSDScript iter = nullptr;
   271 *
   272 *  JSD_LockScriptSubsystem(jsdc);
   273 *  while((jsdscript = JSD_IterateScripts(jsdc, &iter)) != nullptr) {
   274 *     *** use jsdscript here ***
   275 *  }
   276 *  JSD_UnlockScriptSubsystem(jsdc);
   277 */
   278 extern JSD_PUBLIC_API(JSDScript*)
   279 JSD_IterateScripts(JSDContext* jsdc, JSDScript **iterp);
   281 /*
   282 * Get the number of times this script has been called.
   283 */
   284 extern JSD_PUBLIC_API(unsigned)
   285 JSD_GetScriptCallCount(JSDContext* jsdc, JSDScript *script);
   287 /*
   288 * Get the max number of times this script called itself, directly or indirectly.
   289 */
   290 extern JSD_PUBLIC_API(unsigned)
   291 JSD_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script);
   293 /*
   294 * Get the shortest execution time recorded.
   295 */
   296 extern JSD_PUBLIC_API(double)
   297 JSD_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script);
   299 /*
   300 * Get the longest execution time recorded.
   301 */
   302 extern JSD_PUBLIC_API(double)
   303 JSD_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script);
   305 /*
   306 * Get the total amount of time spent in this script.
   307 */
   308 extern JSD_PUBLIC_API(double)
   309 JSD_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script);
   311 /*
   312 * Get the shortest execution time recorded, excluding time spent in called
   313 * functions.
   314 */
   315 extern JSD_PUBLIC_API(double)
   316 JSD_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
   318 /*
   319 * Get the longest execution time recorded, excluding time spent in called
   320 * functions.
   321 */
   322 extern JSD_PUBLIC_API(double)
   323 JSD_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
   325 /*
   326 * Get the total amount of time spent in this script, excluding time spent
   327 * in called functions.
   328 */
   329 extern JSD_PUBLIC_API(double)
   330 JSD_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script);
   332 /*
   333 * Clear profile data for this script.
   334 */
   335 extern JSD_PUBLIC_API(void)
   336 JSD_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script);
   338 /*
   339 * Get the JSScript for a JSDScript
   340 */
   341 extern JSD_PUBLIC_API(JSScript*)
   342 JSD_GetJSScript(JSDContext* jsdc, JSDScript *script);
   344 /*
   345 * Get the JSFunction for a JSDScript
   346 */
   347 extern JSD_PUBLIC_API(JSFunction*)
   348 JSD_GetJSFunction(JSDContext* jsdc, JSDScript *script);
   350 /*
   351 * Determines whether or not to collect profile information for this
   352 * script.  The context flag JSD_PROFILE_WHEN_SET decides the logic.
   353 */
   354 #define JSD_SCRIPT_PROFILE_BIT 0x01
   355 /*
   356 * Determines whether or not to ignore breakpoints, etc. in this script.
   357 * The context flag JSD_DEBUG_WHEN_SET decides the logic.
   358 */
   359 #define JSD_SCRIPT_DEBUG_BIT   0x02
   360 /*
   361  * Determines whether to invoke the onScriptDestroy callback for this
   362  * script. The default is for this to be true if the onScriptCreated
   363  * callback was invoked for this script.
   364  */
   365 #define JSD_SCRIPT_CALL_DESTROY_HOOK_BIT 0x04
   367 extern JSD_PUBLIC_API(uint32_t)
   368 JSD_GetScriptFlags(JSDContext *jsdc, JSDScript* jsdscript);
   370 extern JSD_PUBLIC_API(void)
   371 JSD_SetScriptFlags(JSDContext *jsdc, JSDScript* jsdscript, uint32_t flags);
   373 /*
   374 * Set the private data for this script, returns previous value
   375 */
   376 extern JSD_PUBLIC_API(void *)
   377 JSD_SetScriptPrivate(JSDScript* jsdscript, void *data);
   379 /*
   380 * Get the private data for this script
   381 */
   382 extern JSD_PUBLIC_API(void *)
   383 JSD_GetScriptPrivate(JSDScript* jsdscript);
   385 /*
   386 * Determine if this script is still loaded in the interpreter
   387 */
   388 extern JSD_PUBLIC_API(bool)
   389 JSD_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript);
   391 /*
   392 * Get the filename associated with this script
   393 */
   394 extern JSD_PUBLIC_API(const char*)
   395 JSD_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript);
   397 /*
   398 * Get the function name associated with this script (nullptr if not a
   399 * function). If the function does not have a name the result is the
   400 * string "anonymous".
   401 * *** new for gecko 2.0 ****
   402 */
   403 extern JSD_PUBLIC_API(JSString *)
   404 JSD_GetScriptFunctionId(JSDContext* jsdc, JSDScript *jsdscript);
   406 /*
   407 * Get the base linenumber of the sourcefile from which this script was loaded.
   408 * This is one-based -- i.e. the first line of a file is line '1'. This may
   409 * return 0 if this infomation is unknown.
   410 */
   411 extern JSD_PUBLIC_API(unsigned)
   412 JSD_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript);
   414 /*
   415 * Get the count of source lines associated with this script (1 or greater)
   416 */
   417 extern JSD_PUBLIC_API(unsigned)
   418 JSD_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript);
   420 /*
   421 * Declaration of callback for notification of script creation and destruction.
   422 * 'creating' is true if creating new script, false if destroying existing
   423 * script (callback called just before actual destruction).
   424 * 'callerdata' is what was passed to JSD_SetScriptHook to set the hook.
   425 */
   426 typedef void
   427 (* JSD_ScriptHookProc)(JSDContext* jsdc,
   428                        JSDScript*  jsdscript,
   429                        bool        creating,
   430                        void*       callerdata);
   432 /*
   433 * Set a hook to be called when scripts are created or destroyed (loaded or
   434 * unloaded).
   435 * 'callerdata' can be whatever you want it to be.
   436 */
   437 extern JSD_PUBLIC_API(bool)
   438 JSD_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata);
   440 /*
   441 * Get the current script hook.
   442 */
   443 extern JSD_PUBLIC_API(bool)
   444 JSD_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata);
   446 /*
   447 * Get a 'Program Counter' value for a given line. This represents the location
   448 * of the first bit of executable code for this line of source. This 'pc' should 
   449 * be considered an opaque handle.
   450 * 0 is returned for invalid scripts, or lines that lie outside the script.
   451 * If no code is on the given line, then the returned pc represents the first
   452 * code within the script (if any) after the given line.
   453 * This function can be used to set breakpoints -- see JSD_SetExecutionHook
   454 */
   455 extern JSD_PUBLIC_API(uintptr_t)
   456 JSD_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, unsigned line);
   458 /*
   459 * Get the source line number for a given 'Program Counter' location.
   460 * Returns 0 if no source line information is appropriate (or available) for
   461 * the given pc.
   462 */
   463 extern JSD_PUBLIC_API(unsigned)
   464 JSD_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, uintptr_t pc);
   466 /*
   467  * Get a list of lines and the corresponding earliest PC for each (see
   468  * JSD_GetClosestPC). Lines with no PCs associated will not be returned.
   469  * nullptr may be passed for either lines or pcs to avoid filling anything in
   470  * for that argument.
   471  */
   472 extern JSD_PUBLIC_API(bool)
   473 JSD_GetLinePCs(JSDContext* jsdc, JSDScript* jsdscript,
   474                unsigned startLine, unsigned maxLines,
   475                unsigned* count, unsigned** lines, uintptr_t** pcs);
   477 /* these are only used in cases where scripts are created outside of JS*/
   479 /*
   480 * Direct call to notify JSD that a script has been created.
   481 * Embeddings that use the normal jsapi script functions need not call this.
   482 * Any embedding that follows the (discouraged!) practice of contructing script
   483 * structures manually should call this function to inform JSD. (older ssjs
   484 * systems do this).
   485 */
   486 extern JSD_PUBLIC_API(void)
   487 JSD_ScriptCreated(JSDContext* jsdc,
   488                   JSContext   *cx,
   489                   const char  *filename,    /* URL this script loads from */
   490                   unsigned       lineno,       /* line where this script starts */
   491                   JSScript    *script,
   492                   JSFunction  *fun);
   494 /*
   495 * see JSD_ScriptCreated
   496 */
   497 extern JSD_PUBLIC_API(void)
   498 JSD_ScriptDestroyed(JSDContext* jsdc,
   499                     JSFreeOp    *fop,
   500                     JSScript    *script);
   502 /***************************************************************************/
   503 /* Source Text functions */
   505 /*
   506 * In some embeddings (e.g. mozilla) JavaScript source code from a 'file' may be
   507 * execute before the entire 'file' has even been loaded. This system supports
   508 * access to such incrmentally loaded source. It also allows for the possibility
   509 * that source loading may fail or be aborted (though the source that did load
   510 * may still be usable). Remember that this source is the entire 'file'
   511 * contents and that the JavaScript code may only be part of that source.
   512 *
   513 * For any given URL there can only be one source text item (the most recently
   514 * loaded).
   515 */
   517 /* these coorespond to netscape.jsdebug.SourceTextItem.java values -
   518 *  change in both places if anywhere
   519 */
   521 typedef enum
   522 {
   523     JSD_SOURCE_INITED       = 0, /* initialized, but contains no source yet */
   524     JSD_SOURCE_PARTIAL      = 1, /* some source loaded, more expected */
   525     JSD_SOURCE_COMPLETED    = 2, /* all source finished loading */
   526     JSD_SOURCE_ABORTED      = 3, /* user aborted loading, some may be loaded */
   527     JSD_SOURCE_FAILED       = 4, /* loading failed, some may be loaded */
   528     JSD_SOURCE_CLEARED      = 5  /* text has been cleared by debugger */
   529 } JSDSourceStatus;
   531 /*
   532 * Lock the entire source text subsystem. This grabs a highlevel lock that
   533 * protects the JSD internal information about sources. It is important to
   534 * wrap source text related calls in this lock in multithreaded situations
   535 * -- i.e. where the debugger is running on a different thread than the
   536 * interpreter (or the loader of sources) -- or when multiple debugger
   537 * threads may be accessing this subsystem. It is safe (and best) to use
   538 * this locking even if the environment might not be multi-threaded.
   539 * Safely Nestable.
   540 */
   541 extern JSD_PUBLIC_API(void)
   542 JSD_LockSourceTextSubsystem(JSDContext* jsdc);
   544 /*
   545 * Unlock the entire source text subsystem. see JSD_LockSourceTextSubsystem.
   546 */
   547 extern JSD_PUBLIC_API(void)
   548 JSD_UnlockSourceTextSubsystem(JSDContext* jsdc);
   550 /*
   551 * Iterate the source test items. Use the same pattern of calls shown in
   552 * the example for JSD_IterateScripts - NOTE that the SourceTextSubsystem.
   553 * must be locked before and unlocked after iterating.
   554 */
   555 extern JSD_PUBLIC_API(JSDSourceText*)
   556 JSD_IterateSources(JSDContext* jsdc, JSDSourceText **iterp);
   558 /*
   559 * Find the source text item for the given URL (or filename - or whatever
   560 * string the given embedding uses to describe source locations).
   561 * Returns nullptr if not found.
   562 */
   563 extern JSD_PUBLIC_API(JSDSourceText*)
   564 JSD_FindSourceForURL(JSDContext* jsdc, const char* url);
   566 /*
   567 * Get the URL string associated with the given source text item
   568 */
   569 extern JSD_PUBLIC_API(const char*)
   570 JSD_GetSourceURL(JSDContext* jsdc, JSDSourceText* jsdsrc);
   572 /*
   573 * Get the actual source text. This gives access to the actual storage of
   574 * the source - it sHould *not* be written to.
   575 * The buffer is NOT zero terminated (nor is it guaranteed to have space to
   576 * hold a zero terminating char).
   577 * XXX this is 8-bit character data. Unicode source is not yet supported.
   578 */
   579 extern JSD_PUBLIC_API(bool)
   580 JSD_GetSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc,
   581                   const char** ppBuf, int* pLen);
   583 /*
   584 * Clear the text -- delete the text and set the status to JSD_SOURCE_CLEARED.
   585 * This is useful if source is done loading and the debugger wishes to store
   586 * the text data itself (e.g. in a Java String). This allows avoidance of
   587 * storing the same text in multiple places.
   588 */
   589 extern JSD_PUBLIC_API(void)
   590 JSD_ClearSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc);
   592 /*
   593 * Return the status of the source text item. see JSDSourceStatus enum.
   594 */
   595 extern JSD_PUBLIC_API(JSDSourceStatus)
   596 JSD_GetSourceStatus(JSDContext* jsdc, JSDSourceText* jsdsrc);
   598 /*
   599 * Has the source been altered since the last call to JSD_SetSourceDirty?
   600 * Use of JSD_IsSourceDirty and JSD_SetSourceDirty is still supported, but
   601 * discouraged in favor of the JSD_GetSourceAlterCount system. This dirty
   602 * scheme ASSUMES that there is only one consumer of the data.
   603 */
   604 extern JSD_PUBLIC_API(bool)
   605 JSD_IsSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc);
   607 /*
   608 * Clear the dirty flag
   609 */
   610 extern JSD_PUBLIC_API(void)
   611 JSD_SetSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc, bool dirty);
   613 /*
   614 * Each time a source text item is altered this value is incremented. Any
   615 * consumer can store this value when they retieve other data about the
   616 * source text item and then check later to see if the current value is
   617 * different from their stored value. Thus they can know if they have stale
   618 * data or not. NOTE: this value is not gauranteed to start at any given number.
   619 */
   620 extern JSD_PUBLIC_API(unsigned)
   621 JSD_GetSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
   623 /*
   624 * Force an increment in the alter count for a source text item. This is
   625 * normally automatic when the item changes, but a give consumer may want to
   626 * force this to amke an item appear to have changed even if it has not.
   627 */
   628 extern JSD_PUBLIC_API(unsigned)
   629 JSD_IncrementSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc);
   631 /*
   632 * Destroy *all* the source text items
   633 * (new for server-side USE WITH CARE)
   634 */
   635 extern JSD_PUBLIC_API(void)
   636 JSD_DestroyAllSources( JSDContext* jsdc );
   638 /* functions for adding source items */
   640 /*
   641 * Add a new item for a given URL. If an item already exists for the given URL
   642 * then the old item is removed.
   643 * 'url' may not be nullptr.
   644 */
   645 extern JSD_PUBLIC_API(JSDSourceText*)
   646 JSD_NewSourceText(JSDContext* jsdc, const char* url);
   648 /*
   649 * Append text (or change status -- e.g. set completed) for a source text
   650 * item. Text need not be zero terminated. Callers should consider the returned
   651 * JSDSourceText to be the 'current' item for future use. This may return
   652 * nullptr if called after this item has been replaced by a call to
   653 * JSD_NewSourceText.
   654 */
   655 extern JSD_PUBLIC_API(JSDSourceText*)
   656 JSD_AppendSourceText(JSDContext*     jsdc,
   657                      JSDSourceText*  jsdsrc,
   658                      const char*     text,       /* *not* zero terminated */
   659                      size_t          length,
   660                      JSDSourceStatus status);
   662 /*
   663 * Unicode varient of JSD_AppendSourceText.
   664 *
   665 * NOTE: At this point text is stored in 8bit ASCII so this function just
   666 * extracts the bottom 8bits from each jschar. At some future point we may
   667 * switch to storing and exposing 16bit Unicode.
   668 */
   669 extern JSD_PUBLIC_API(JSDSourceText*)
   670 JSD_AppendUCSourceText(JSDContext*     jsdc,
   671                        JSDSourceText*  jsdsrc,
   672                        const jschar*   text,       /* *not* zero terminated */
   673                        size_t          length,
   674                        JSDSourceStatus status);
   675 /*
   676  * Convienence function for adding complete source of url in one call.
   677  * same as:
   678  *   JSDSourceText* jsdsrc;
   679  *   JSD_LOCK_SOURCE_TEXT(jsdc);
   680  *   jsdsrc = jsd_NewSourceText(jsdc, url);
   681  *   if(jsdsrc)
   682  *       jsdsrc = jsd_AppendSourceText(jsdc, jsdsrc,
   683  *                                     text, length, JSD_SOURCE_PARTIAL);
   684  *   if(jsdsrc)
   685  *       jsdsrc = jsd_AppendSourceText(jsdc, jsdsrc,
   686  *                                     nullptr, 0, JSD_SOURCE_COMPLETED);
   687  *   JSD_UNLOCK_SOURCE_TEXT(jsdc);
   688  *   return jsdsrc ? true : false;
   689  */
   690 extern JSD_PUBLIC_API(bool)
   691 JSD_AddFullSourceText(JSDContext* jsdc,
   692                       const char* text,       /* *not* zero terminated */
   693                       size_t      length,
   694                       const char* url);
   696 /***************************************************************************/
   697 /* Execution/Interrupt Hook functions */
   699 /* possible 'type' params for JSD_ExecutionHookProc */
   700 #define JSD_HOOK_INTERRUPTED            0
   701 #define JSD_HOOK_BREAKPOINT             1
   702 #define JSD_HOOK_DEBUG_REQUESTED        2
   703 #define JSD_HOOK_DEBUGGER_KEYWORD       3
   704 #define JSD_HOOK_THROW                  4
   706 /* legal return values for JSD_ExecutionHookProc */
   707 #define JSD_HOOK_RETURN_HOOK_ERROR      0
   708 #define JSD_HOOK_RETURN_CONTINUE        1
   709 #define JSD_HOOK_RETURN_ABORT           2
   710 #define JSD_HOOK_RETURN_RET_WITH_VAL    3
   711 #define JSD_HOOK_RETURN_THROW_WITH_VAL  4
   712 #define JSD_HOOK_RETURN_CONTINUE_THROW  5
   714 /*
   715 * Implement a callback of this form in order to hook execution.
   716 */
   717 typedef unsigned
   718 (* JSD_ExecutionHookProc)(JSDContext*     jsdc,
   719                           JSDThreadState* jsdthreadstate,
   720                           unsigned        type,
   721                           void*           callerdata,
   722                           JS::Value*      rval);
   724 /* possible 'type' params for JSD_CallHookProc */
   725 #define JSD_HOOK_TOPLEVEL_START  0   /* about to evaluate top level script */
   726 #define JSD_HOOK_TOPLEVEL_END    1   /* done evaluting top level script    */
   727 #define JSD_HOOK_FUNCTION_CALL   2   /* about to call a function           */
   728 #define JSD_HOOK_FUNCTION_RETURN 3   /* done calling function              */
   730 /*
   731 * Implement a callback of this form in order to hook function call/returns.
   732 * Return true from a TOPLEVEL_START or FUNCTION_CALL type call hook if you
   733 * want to hear about the TOPLEVEL_END or FUNCTION_RETURN too.  Return value is
   734 * ignored to TOPLEVEL_END and FUNCTION_RETURN type hooks.
   735 */
   736 typedef bool
   737 (* JSD_CallHookProc)(JSDContext*     jsdc,
   738                      JSDThreadState* jsdthreadstate,
   739                      unsigned           type,
   740                      void*           callerdata);
   742 /*
   743 * Set Hook to be called whenever the given pc is about to be executed --
   744 * i.e. for 'trap' or 'breakpoint'
   745 */
   746 extern JSD_PUBLIC_API(bool)
   747 JSD_SetExecutionHook(JSDContext*           jsdc,
   748                      JSDScript*            jsdscript,
   749                      uintptr_t             pc,
   750                      JSD_ExecutionHookProc hook,
   751                      void*                 callerdata);
   753 /*
   754 * Clear the hook for this pc
   755 */
   756 extern JSD_PUBLIC_API(bool)
   757 JSD_ClearExecutionHook(JSDContext*          jsdc,
   758                        JSDScript*           jsdscript,
   759                        uintptr_t            pc);
   761 /*
   762 * Clear all the pc specific hooks for this script
   763 */
   764 extern JSD_PUBLIC_API(bool)
   765 JSD_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript);
   767 /*
   768 * Clear all the pc specific hooks for the entire JSRuntime associated with
   769 * this JSDContext
   770 */
   771 extern JSD_PUBLIC_API(bool)
   772 JSD_ClearAllExecutionHooks(JSDContext* jsdc);
   774 /*
   775 * Set a hook to be called before the next instruction is executed. Depending
   776 * on the threading situation and whether or not an JS code is currently
   777 * executing the hook might be called before this call returns, or at some
   778 * future time. The hook will continue to be called as each instruction
   779 * executes until cleared.
   780 */
   781 extern JSD_PUBLIC_API(bool)
   782 JSD_SetInterruptHook(JSDContext*           jsdc,
   783                      JSD_ExecutionHookProc hook,
   784                      void*                 callerdata);
   786 /*
   787 * Call the interrupt hook at least once per source line
   788 */
   789 extern JSD_PUBLIC_API(bool)
   790 JSD_EnableSingleStepInterrupts(JSDContext* jsdc, JSDScript *jsdscript, bool enable);
   792 /*
   793 * Clear the current interrupt hook.
   794 */
   795 extern JSD_PUBLIC_API(bool)
   796 JSD_ClearInterruptHook(JSDContext* jsdc);
   798 /*
   799 * Set the hook that should be called whenever a JSD_ErrorReporter hook
   800 * returns JSD_ERROR_REPORTER_DEBUG.
   801 */
   802 extern JSD_PUBLIC_API(bool)
   803 JSD_SetDebugBreakHook(JSDContext*           jsdc,
   804                       JSD_ExecutionHookProc hook,
   805                       void*                 callerdata);
   807 /*
   808 * Clear the debug break hook
   809 */
   810 extern JSD_PUBLIC_API(bool)
   811 JSD_ClearDebugBreakHook(JSDContext* jsdc);
   813 /*
   814 * Set the hook that should be called when the 'debugger' keyword is
   815 * encountered by the JavaScript interpreter during execution.
   816 */
   817 extern JSD_PUBLIC_API(bool)
   818 JSD_SetDebuggerHook(JSDContext*           jsdc,
   819                     JSD_ExecutionHookProc hook,
   820                     void*                 callerdata);
   822 /*
   823 * Clear the 'debugger' keyword hook
   824 */
   825 extern JSD_PUBLIC_API(bool)
   826 JSD_ClearDebuggerHook(JSDContext* jsdc);
   828 /*
   829 * Set the hook that should be called when a JS exception is thrown.
   830 * NOTE: the 'do default' return value is: JSD_HOOK_RETURN_CONTINUE_THROW
   831 */
   832 extern JSD_PUBLIC_API(bool)
   833 JSD_SetThrowHook(JSDContext*           jsdc,
   834                  JSD_ExecutionHookProc hook,
   835                  void*                 callerdata);
   836 /*
   837 * Clear the throw hook
   838 */
   839 extern JSD_PUBLIC_API(bool)
   840 JSD_ClearThrowHook(JSDContext* jsdc);
   842 /*
   843 * Set the hook that should be called when a toplevel script begins or completes.
   844 */
   845 extern JSD_PUBLIC_API(bool)
   846 JSD_SetTopLevelHook(JSDContext*      jsdc,
   847                     JSD_CallHookProc hook,
   848                     void*            callerdata);
   849 /*
   850 * Clear the toplevel call hook
   851 */
   852 extern JSD_PUBLIC_API(bool)
   853 JSD_ClearTopLevelHook(JSDContext* jsdc);
   855 /*
   856 * Set the hook that should be called when a function call or return happens.
   857 */
   858 extern JSD_PUBLIC_API(bool)
   859 JSD_SetFunctionHook(JSDContext*      jsdc,
   860                     JSD_CallHookProc hook,
   861                     void*            callerdata);
   862 /*
   863 * Clear the function call hook
   864 */
   865 extern JSD_PUBLIC_API(bool)
   866 JSD_ClearFunctionHook(JSDContext* jsdc);
   868 /***************************************************************************/
   869 /* Stack Frame functions */
   871 /*
   872 * Get the count of call stack frames for the given JSDThreadState
   873 */
   874 extern JSD_PUBLIC_API(unsigned)
   875 JSD_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
   877 /*
   878 * Get the 'current' call stack frame for the given JSDThreadState
   879 */
   880 extern JSD_PUBLIC_API(JSDStackFrameInfo*)
   881 JSD_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
   883 /*
   884 * Get the JSContext for the given JSDThreadState
   885 */
   886 extern JSD_PUBLIC_API(JSContext*)
   887 JSD_GetJSContext(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
   889 /*
   890 * Get the calling call stack frame for the given frame
   891 */
   892 extern JSD_PUBLIC_API(JSDStackFrameInfo*)
   893 JSD_GetCallingStackFrame(JSDContext* jsdc,
   894                          JSDThreadState* jsdthreadstate,
   895                          JSDStackFrameInfo* jsdframe);
   897 /*
   898 * Get the script for the given call stack frame
   899 */
   900 extern JSD_PUBLIC_API(JSDScript*)
   901 JSD_GetScriptForStackFrame(JSDContext* jsdc,
   902                            JSDThreadState* jsdthreadstate,
   903                            JSDStackFrameInfo* jsdframe);
   905 /*
   906 * Get the 'Program Counter' for the given call stack frame
   907 */
   908 extern JSD_PUBLIC_API(uintptr_t)
   909 JSD_GetPCForStackFrame(JSDContext* jsdc,
   910                        JSDThreadState* jsdthreadstate,
   911                        JSDStackFrameInfo* jsdframe);
   913 /*
   914 * Get the JavaScript Call Object for the given call stack frame.
   915 * *** new for version 1.1 ****
   916 */
   917 extern JSD_PUBLIC_API(JSDValue*)
   918 JSD_GetCallObjectForStackFrame(JSDContext* jsdc,
   919                                JSDThreadState* jsdthreadstate,
   920                                JSDStackFrameInfo* jsdframe);
   922 /*
   923 * Get the head of the scope chain for the given call stack frame.
   924 * the chain can be traversed using JSD_GetValueParent.
   925 * *** new for version 1.1 ****
   926 */
   927 extern JSD_PUBLIC_API(JSDValue*)
   928 JSD_GetScopeChainForStackFrame(JSDContext* jsdc,
   929                                JSDThreadState* jsdthreadstate,
   930                                JSDStackFrameInfo* jsdframe);
   932 /*
   933 * Get the 'this' Object for the given call stack frame.
   934 * *** new for version 1.1 ****
   935 */
   936 extern JSD_PUBLIC_API(JSDValue*)
   937 JSD_GetThisForStackFrame(JSDContext* jsdc,
   938                          JSDThreadState* jsdthreadstate,
   939                          JSDStackFrameInfo* jsdframe);
   941 /*
   942 * Get the name of the function executing in this stack frame.  Especially useful
   943 * for native frames (without script objects.)
   944 * *** new for gecko 2.0 ****
   945 */
   946 extern JSD_PUBLIC_API(JSString *)
   947 JSD_GetIdForStackFrame(JSDContext* jsdc,
   948                        JSDThreadState* jsdthreadstate,
   949                        JSDStackFrameInfo* jsdframe);
   951 /*
   952 * True if stack frame represents a frame created as a result of a debugger
   953 * evaluation.
   954 */
   955 extern JSD_PUBLIC_API(bool)
   956 JSD_IsStackFrameDebugger(JSDContext* jsdc,
   957                          JSDThreadState* jsdthreadstate,
   958                          JSDStackFrameInfo* jsdframe);
   960 /*
   961 * True if stack frame is constructing a new object.
   962 */
   963 extern JSD_PUBLIC_API(bool)
   964 JSD_IsStackFrameConstructing(JSDContext* jsdc,
   965                              JSDThreadState* jsdthreadstate,
   966                              JSDStackFrameInfo* jsdframe);
   968 /*
   969 * Evaluate the given unicode source code in the context of the given stack frame.
   970 * returns true and puts result in rval on success, false on failure.
   971 * NOTE: The ErrorReporter hook might be called if this fails.
   972 */
   973 extern JSD_PUBLIC_API(bool)
   974 JSD_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
   975                                  JSDThreadState* jsdthreadstate,
   976                                  JSDStackFrameInfo* jsdframe,
   977                                  const jschar *bytes, unsigned length,
   978                                  const char *filename, unsigned lineno,
   979                                  JS::MutableHandleValue rval);
   981 /*
   982 * Same as above, but does not eat exceptions.
   983 */
   984 extern JSD_PUBLIC_API(bool)
   985 JSD_AttemptUCScriptInStackFrame(JSDContext* jsdc,
   986                                 JSDThreadState* jsdthreadstate,
   987                                 JSDStackFrameInfo* jsdframe,
   988                                 const jschar *bytes, unsigned length,
   989                                 const char *filename, unsigned lineno,
   990                                 JS::MutableHandleValue rval);
   992 /* single byte character version of JSD_EvaluateUCScriptInStackFrame */
   993 extern JSD_PUBLIC_API(bool)
   994 JSD_EvaluateScriptInStackFrame(JSDContext* jsdc,
   995                                JSDThreadState* jsdthreadstate,
   996                                JSDStackFrameInfo* jsdframe,
   997                                const char *bytes, unsigned length,
   998                                const char *filename, unsigned lineno, JS::MutableHandleValue rval);
  1000 /*
  1001 * Same as above, but does not eat exceptions.
  1002 */
  1003 extern JSD_PUBLIC_API(bool)
  1004 JSD_AttemptScriptInStackFrame(JSDContext* jsdc,
  1005                               JSDThreadState* jsdthreadstate,
  1006                               JSDStackFrameInfo* jsdframe,
  1007                               const char *bytes, unsigned length,
  1008                               const char *filename, unsigned lineno, JS::MutableHandleValue rval);
  1010 /*
  1011 * Convert the given JS::Value to a string
  1012 * NOTE: The ErrorReporter hook might be called if this fails.
  1013 */
  1014 extern JSD_PUBLIC_API(JSString*)
  1015 JSD_ValToStringInStackFrame(JSDContext* jsdc,
  1016                             JSDThreadState* jsdthreadstate,
  1017                             JSDStackFrameInfo* jsdframe,
  1018                             JS::Value val);
  1020 /*
  1021 * Get the JSDValue currently being thrown as an exception (may be nullptr).
  1022 * NOTE: must eventually release by calling JSD_DropValue (if not nullptr)
  1023 * *** new for version 1.1 ****
  1024 */
  1025 extern JSD_PUBLIC_API(JSDValue*)
  1026 JSD_GetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate);
  1028 /*
  1029 * Set the JSDValue currently being thrown as an exception.
  1030 * *** new for version 1.1 ****
  1031 */
  1032 extern JSD_PUBLIC_API(bool)
  1033 JSD_SetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate, 
  1034                  JSDValue* jsdval);
  1036 /***************************************************************************/
  1037 /* Error Reporter functions */
  1039 /*
  1040 * XXX The ErrorReporter Hook scheme is going to change soon to more
  1041 *     Fully support exceptions.
  1042 */
  1044 /* legal return values for JSD_ErrorReporter */
  1045 #define JSD_ERROR_REPORTER_PASS_ALONG   0 /* pass along to regular reporter */
  1046 #define JSD_ERROR_REPORTER_RETURN       1 /* don't pass to error reporter */
  1047 #define JSD_ERROR_REPORTER_DEBUG        2 /* force call to DebugBreakHook */
  1048 #define JSD_ERROR_REPORTER_CLEAR_RETURN 3 /* clear exception and don't pass */
  1050 /*
  1051 * Implement a callback of this form in order to hook the ErrorReporter
  1052 */
  1053 typedef unsigned
  1054 (* JSD_ErrorReporter)(JSDContext*     jsdc,
  1055                       JSContext*      cx,
  1056                       const char*     message,
  1057                       JSErrorReport*  report,
  1058                       void*           callerdata);
  1060 /* Set ErrorReporter hook */
  1061 extern JSD_PUBLIC_API(bool)
  1062 JSD_SetErrorReporter(JSDContext*       jsdc,
  1063                      JSD_ErrorReporter reporter,
  1064                      void*             callerdata);
  1066 /* Get Current ErrorReporter hook */
  1067 extern JSD_PUBLIC_API(bool)
  1068 JSD_GetErrorReporter(JSDContext*        jsdc,
  1069                      JSD_ErrorReporter* reporter,
  1070                      void**             callerdata);
  1072 /***************************************************************************/
  1073 /* Generic locks that callers can use for their own purposes */
  1075 struct JSDStaticLock;
  1077 /*
  1078 * Is Locking and GetThread supported in this build?
  1079 */
  1080 extern JSD_PUBLIC_API(bool)
  1081 JSD_IsLockingAndThreadIdSupported();
  1083 /*
  1084 * Create a reentrant/nestable lock
  1085 */
  1086 extern JSD_PUBLIC_API(JSDStaticLock*)
  1087 JSD_CreateLock();
  1089 /*
  1090 * Aquire lock for this thread (or block until available). Increments a
  1091 * counter if this thread already owns the lock.
  1092 */
  1093 extern JSD_PUBLIC_API(void)
  1094 JSD_Lock(JSDStaticLock* lock);
  1096 /*
  1097 * Release lock for this thread (or decrement the counter if JSD_Lock
  1098 * was previous called more than once).
  1099 */
  1100 extern JSD_PUBLIC_API(void)
  1101 JSD_Unlock(JSDStaticLock* lock);
  1103 /*
  1104 * For debugging only if not (JS_THREADSAFE AND DEBUG) then returns true
  1105 *    So JSD_IsLocked(lock) may not equal !JSD_IsUnlocked(lock)
  1106 */
  1107 extern JSD_PUBLIC_API(bool)
  1108 JSD_IsLocked(JSDStaticLock* lock);
  1110 /*
  1111 * See above...
  1112 */
  1113 extern JSD_PUBLIC_API(bool)
  1114 JSD_IsUnlocked(JSDStaticLock* lock);
  1116 /*
  1117 * return an ID uniquely identifying this thread.
  1118 */
  1119 extern JSD_PUBLIC_API(void*)
  1120 JSD_CurrentThread();
  1122 /***************************************************************************/
  1123 /* Value and Property Functions  --- All NEW for 1.1 --- */
  1125 /*
  1126 * NOTE: JSDValue and JSDProperty objects are reference counted. This allows
  1127 * for rooting these objects AND any underlying garbage collected JS::Values.
  1128 * ALL JSDValue and JSDProperty objects returned by the functions below
  1129 * MUST eventually be released using the appropriate JSD_Dropxxx function.
  1130 */
  1132 /*
  1133 * Create a new JSDValue to wrap the given JS::Value
  1134 * NOTE: must eventually release by calling JSD_DropValue (if not nullptr)
  1135 * *** new for version 1.1 ****
  1136 */
  1137 extern JSD_PUBLIC_API(JSDValue*)
  1138 JSD_NewValue(JSDContext* jsdc, JS::Value val);
  1140 /*
  1141 * Release the JSDValue. After this call the object MUST not be referenced again!
  1142 * *** new for version 1.1 ****
  1143 */
  1144 extern JSD_PUBLIC_API(void)
  1145 JSD_DropValue(JSDContext* jsdc, JSDValue* jsdval);
  1147 /*
  1148 * Get the JS::Value wrapped by this JSDValue
  1149 * *** new for version 1.1 ****
  1150 */
  1151 extern JSD_PUBLIC_API(JS::Value)
  1152 JSD_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval);
  1154 /*
  1155 * Clear all property and association information about the given JSDValue.
  1156 * Such information will be lazily regenerated when later accessed. This
  1157 * function must be called to make changes to the properties of an object
  1158 * visible to the accessor functions below (if the properties et.al. have
  1159 * changed since a previous call to those accessors).
  1160 * *** new for version 1.1 ****
  1161 */
  1162 extern JSD_PUBLIC_API(void)
  1163 JSD_RefreshValue(JSDContext* jsdc, JSDValue* jsdval);
  1165 /**************************************************/
  1167 /*
  1168 * Does the JSDValue wrap a JSObject?
  1169 * *** new for version 1.1 ****
  1170 */
  1171 extern JSD_PUBLIC_API(bool)
  1172 JSD_IsValueObject(JSDContext* jsdc, JSDValue* jsdval);
  1174 /*
  1175 * Does the JSDValue wrap a number (int or double)?
  1176 * *** new for version 1.1 ****
  1177 */
  1178 extern JSD_PUBLIC_API(bool)
  1179 JSD_IsValueNumber(JSDContext* jsdc, JSDValue* jsdval);
  1181 /*
  1182 * Does the JSDValue wrap an int?
  1183 * *** new for version 1.1 ****
  1184 */
  1185 extern JSD_PUBLIC_API(bool)
  1186 JSD_IsValueInt(JSDContext* jsdc, JSDValue* jsdval);
  1188 /*
  1189 * Does the JSDValue wrap a double?
  1190 * *** new for version 1.1 ****
  1191 */
  1192 extern JSD_PUBLIC_API(bool)
  1193 JSD_IsValueDouble(JSDContext* jsdc, JSDValue* jsdval);
  1195 /*
  1196 * Does the JSDValue wrap a JSString?
  1197 * *** new for version 1.1 ****
  1198 */
  1199 extern JSD_PUBLIC_API(bool)
  1200 JSD_IsValueString(JSDContext* jsdc, JSDValue* jsdval);
  1202 /*
  1203 * Does the JSDValue wrap a bool?
  1204 * *** new for version 1.1 ****
  1205 */
  1206 extern JSD_PUBLIC_API(bool)
  1207 JSD_IsValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
  1209 /*
  1210 * Does the JSDValue wrap a JSVAL_NULL?
  1211 * *** new for version 1.1 ****
  1212 */
  1213 extern JSD_PUBLIC_API(bool)
  1214 JSD_IsValueNull(JSDContext* jsdc, JSDValue* jsdval);
  1216 /*
  1217 * Does the JSDValue wrap a JSVAL_VOID?
  1218 * *** new for version 1.1 ****
  1219 */
  1220 extern JSD_PUBLIC_API(bool)
  1221 JSD_IsValueVoid(JSDContext* jsdc, JSDValue* jsdval);
  1223 /*
  1224 * Does the JSDValue wrap a primative (not a JSObject)?
  1225 * *** new for version 1.1 ****
  1226 */
  1227 extern JSD_PUBLIC_API(bool)
  1228 JSD_IsValuePrimitive(JSDContext* jsdc, JSDValue* jsdval);
  1230 /*
  1231 * Does the JSDValue wrap a function?
  1232 * *** new for version 1.1 ****
  1233 */
  1234 extern JSD_PUBLIC_API(bool)
  1235 JSD_IsValueFunction(JSDContext* jsdc, JSDValue* jsdval);
  1237 /*
  1238 * Does the JSDValue wrap a native function?
  1239 * *** new for version 1.1 ****
  1240 */
  1241 extern JSD_PUBLIC_API(bool)
  1242 JSD_IsValueNative(JSDContext* jsdc, JSDValue* jsdval);
  1244 /**************************************************/
  1246 /*
  1247 * Return bool value (does NOT do conversion).
  1248 * *** new for version 1.1 ****
  1249 */
  1250 extern JSD_PUBLIC_API(bool)
  1251 JSD_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval);
  1253 /*
  1254 * Return int32_t value (does NOT do conversion).
  1255 * *** new for version 1.1 ****
  1256 */
  1257 extern JSD_PUBLIC_API(int32_t)
  1258 JSD_GetValueInt(JSDContext* jsdc, JSDValue* jsdval);
  1260 /*
  1261 * Return double value (does NOT do conversion).
  1262 * *** new for version 1.1 ****
  1263 */
  1264 extern JSD_PUBLIC_API(double)
  1265 JSD_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval);
  1267 /*
  1268 * Return JSString value (DOES do conversion if necessary).
  1269 * NOTE that the JSString returned is not protected from garbage
  1270 * collection. It should be immediately read or wrapped using
  1271 * JSD_NewValue(jsdc,STRING_TO_JSVAL(str)) if necessary.
  1272 * *** new for version 1.1 ****
  1273 */
  1274 extern JSD_PUBLIC_API(JSString*)
  1275 JSD_GetValueString(JSDContext* jsdc, JSDValue* jsdval);
  1277 /*
  1278 * Return name of function IFF JSDValue represents a function.
  1279 * *** new for gecko 2.0 ****
  1280 */
  1281 extern JSD_PUBLIC_API(JSString *)
  1282 JSD_GetValueFunctionId(JSDContext* jsdc, JSDValue* jsdval);
  1284 /*
  1285 * Return function object IFF JSDValue represents a function or an object
  1286 * wrapping a function.
  1287 * *** new for version 1.1 ****
  1288 */
  1289 extern JSD_PUBLIC_API(JSFunction*)
  1290 JSD_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval);
  1292 /**************************************************/
  1294 /*
  1295 * Return the number of properties for the JSDValue.
  1296 * *** new for version 1.1 ****
  1297 */
  1298 extern JSD_PUBLIC_API(unsigned)
  1299 JSD_GetCountOfProperties(JSDContext* jsdc, JSDValue* jsdval);
  1301 /*
  1302 * Iterate through the properties of the JSDValue.
  1303 * Use form similar to that shown for JSD_IterateScripts (no locking required).
  1304 * NOTE: each JSDProperty returned must eventually be released by calling
  1305 * JSD_DropProperty.
  1306 * *** new for version 1.1 ****
  1307 */
  1308 extern JSD_PUBLIC_API(JSDProperty*)
  1309 JSD_IterateProperties(JSDContext* jsdc, JSDValue* jsdval, JSDProperty **iterp);
  1311 /* 
  1312 * Get the JSDProperty for the property of this JSDVal with this name.
  1313 * NOTE: must eventually release by calling JSD_DropProperty (if not nullptr)
  1314 * *** new for version 1.1 ****
  1315 */
  1316 extern JSD_PUBLIC_API(JSDProperty*)
  1317 JSD_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name);
  1319 /*
  1320 * Get the prototype object for this JSDValue.
  1321 * NOTE: must eventually release by calling JSD_DropValue (if not nullptr)
  1322 * *** new for version 1.1 ****
  1323 */
  1324 extern JSD_PUBLIC_API(JSDValue*)
  1325 JSD_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval);
  1327 /*
  1328 * Get the parent object for this JSDValue.
  1329 * NOTE: must eventually release by calling JSD_DropValue (if not nullptr)
  1330 * *** new for version 1.1 ****
  1331 */
  1332 extern JSD_PUBLIC_API(JSDValue*)
  1333 JSD_GetValueParent(JSDContext* jsdc, JSDValue* jsdval);
  1335 /*
  1336 * Get the ctor object for this JSDValue (or likely its prototype's ctor).
  1337 * NOTE: must eventually release by calling JSD_DropValue (if not nullptr)
  1338 * *** new for version 1.1 ****
  1339 */
  1340 extern JSD_PUBLIC_API(JSDValue*)
  1341 JSD_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval);
  1343 /*
  1344 * Get the name of the class for this object.
  1345 * *** new for version 1.1 ****
  1346 */
  1347 extern JSD_PUBLIC_API(const char*)
  1348 JSD_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval);
  1350 /*
  1351 * Get the script for the given value if the given value represents a
  1352 * scripted function.  Otherwise, return null.
  1353 */
  1354 extern JSD_PUBLIC_API(JSDScript*)
  1355 JSD_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval);
  1357 /**************************************************/
  1359 /* possible or'd together bitflags returned by JSD_GetPropertyFlags
  1361  * XXX these must stay the same as the JSPD_ flags in js/OldDebugAPI.h
  1362  */
  1363 #define JSDPD_ENUMERATE  JSPD_ENUMERATE    /* visible to for/in loop */
  1364 #define JSDPD_READONLY   JSPD_READONLY     /* assignment is error */
  1365 #define JSDPD_PERMANENT  JSPD_PERMANENT    /* property cannot be deleted */
  1366 #define JSDPD_ALIAS      JSPD_ALIAS        /* property has an alias id */
  1367 #define JSDPD_EXCEPTION  JSPD_EXCEPTION    /* exception occurred looking up */
  1368                                            /* proprety, value is exception  */
  1369 #define JSDPD_ERROR      JSPD_ERROR        /* native getter returned false */
  1370                                            /* without throwing an exception */
  1371 /* this is not one of the JSPD_ flags in js/OldDebugAPI.h  - don't overlap! */
  1372 #define JSDPD_HINTED     0x800             /* found via explicit lookup */
  1374 /*
  1375 * Release this JSDProperty
  1376 * *** new for version 1.1 ****
  1377 */
  1378 extern JSD_PUBLIC_API(void)
  1379 JSD_DropProperty(JSDContext* jsdc, JSDProperty* jsdprop);
  1381 /*
  1382 * Get the JSDValue represeting the name of this property (int or string)
  1383 * NOTE: must eventually release by calling JSD_DropValue
  1384 * *** new for version 1.1 ****
  1385 */
  1386 extern JSD_PUBLIC_API(JSDValue*)
  1387 JSD_GetPropertyName(JSDContext* jsdc, JSDProperty* jsdprop);
  1389 /*
  1390 * Get the JSDValue represeting the current value of this property
  1391 * NOTE: must eventually release by calling JSD_DropValue (if not nullptr)
  1392 * *** new for version 1.1 ****
  1393 */
  1394 extern JSD_PUBLIC_API(JSDValue*)
  1395 JSD_GetPropertyValue(JSDContext* jsdc, JSDProperty* jsdprop);
  1397 /*
  1398 * Get the JSDValue represeting the alias of this property (if JSDPD_ALIAS set)
  1399 * NOTE: must eventually release by calling JSD_DropValue (if not nullptr)
  1400 * *** new for version 1.1 ****
  1401 */
  1402 extern JSD_PUBLIC_API(JSDValue*)
  1403 JSD_GetPropertyAlias(JSDContext* jsdc, JSDProperty* jsdprop);
  1405 /*
  1406 * Get the flags for this property
  1407 * *** new for version 1.1 ****
  1408 */
  1409 extern JSD_PUBLIC_API(unsigned)
  1410 JSD_GetPropertyFlags(JSDContext* jsdc, JSDProperty* jsdprop);
  1412 /***************************************************************************/
  1413 /* Object Functions  --- All NEW for 1.1 --- */
  1415 /*
  1416 * JSDObjects exist to allow a means of iterating through all JSObjects in the
  1417 * engine. They are created and destroyed as the wrapped JSObjects are created
  1418 * and destroyed in the engine. JSDObjects additionally track the location in
  1419 * the JavaScript source where their wrapped JSObjects were created and the name
  1420 * and location of the (non-native) constructor used.
  1422 * NOTE: JSDObjects are NOT reference counted. The have only weak links to
  1423 * jsObjects - thus they do not inhibit garbage collection of JSObjects. If
  1424 * you need a JSDObject to safely persist then wrap it in a JSDValue (using
  1425 * jsd_GetValueForObject).
  1426 */
  1428 /*
  1429 * Lock the entire Object subsystem -- see JSD_UnlockObjectSubsystem
  1430 * *** new for version 1.1 ****
  1431 */
  1432 extern JSD_PUBLIC_API(void)
  1433 JSD_LockObjectSubsystem(JSDContext* jsdc);
  1435 /*
  1436 * Unlock the entire Object subsystem -- see JSD_LockObjectSubsystem
  1437 * *** new for version 1.1 ****
  1438 */
  1439 extern JSD_PUBLIC_API(void)
  1440 JSD_UnlockObjectSubsystem(JSDContext* jsdc);
  1442 /*
  1443 * Iterate through the known objects
  1444 * Use form similar to that shown for JSD_IterateScripts.
  1445 * NOTE: the ObjectSubsystem must be locked before and unlocked after iterating.
  1446 * *** new for version 1.1 ****
  1447 */
  1448 extern JSD_PUBLIC_API(JSDObject*)
  1449 JSD_IterateObjects(JSDContext* jsdc, JSDObject** iterp);
  1451 /*
  1452 * Get the JSObject represented by this JSDObject
  1453 * *** new for version 1.1 ****
  1454 */
  1455 extern JSD_PUBLIC_API(JSObject*)
  1456 JSD_GetWrappedObject(JSDContext* jsdc, JSDObject* jsdobj);
  1458 /*
  1459 * Get the URL of the line of source that caused this object to be created.
  1460 * May be nullptr.
  1461 * *** new for version 1.1 ****
  1462 */
  1463 extern JSD_PUBLIC_API(const char*)
  1464 JSD_GetObjectNewURL(JSDContext* jsdc, JSDObject* jsdobj);
  1466 /*
  1467 * Get the line number of the line of source that caused this object to be
  1468 * created. May be 0 indicating that the line number is unknown.
  1469 * *** new for version 1.1 ****
  1470 */
  1471 extern JSD_PUBLIC_API(unsigned)
  1472 JSD_GetObjectNewLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
  1474 /*
  1475 * Get the URL of the line of source of the constructor for this object.
  1476 * May be nullptr.
  1477 * *** new for version 1.1 ****
  1478 */
  1479 extern JSD_PUBLIC_API(const char*)
  1480 JSD_GetObjectConstructorURL(JSDContext* jsdc, JSDObject* jsdobj);
  1482 /*
  1483 * Get the line number of the line of source of the constructor for this object.
  1484 * created. May be 0 indicating that the line number is unknown.
  1485 * *** new for version 1.1 ****
  1486 */
  1487 extern JSD_PUBLIC_API(unsigned)
  1488 JSD_GetObjectConstructorLineNumber(JSDContext* jsdc, JSDObject* jsdobj);
  1490 /*
  1491 * Get the name of the constructor for this object.
  1492 * May be nullptr.
  1493 * *** new for version 1.1 ****
  1494 */
  1495 extern JSD_PUBLIC_API(const char*)
  1496 JSD_GetObjectConstructorName(JSDContext* jsdc, JSDObject* jsdobj);
  1498 /*
  1499 * Get JSDObject representing this JSObject.
  1500 * May return nullptr.
  1501 * *** new for version 1.1 ****
  1502 */
  1503 extern JSD_PUBLIC_API(JSDObject*)
  1504 JSD_GetJSDObjectForJSObject(JSDContext* jsdc, JSObject* jsobj);
  1506 /*
  1507 * Get JSDObject representing this JSDValue.
  1508 * May return nullptr.
  1509 * *** new for version 1.1 ****
  1510 */
  1511 extern JSD_PUBLIC_API(JSDObject*)
  1512 JSD_GetObjectForValue(JSDContext* jsdc, JSDValue* jsdval);
  1514 /*
  1515 * Create a JSDValue to wrap (and root) this JSDObject.
  1516 * NOTE: must eventually release by calling JSD_DropValue (if not nullptr)
  1517 * *** new for version 1.1 ****
  1518 */
  1519 extern JSD_PUBLIC_API(JSDValue*)
  1520 JSD_GetValueForObject(JSDContext* jsdc, JSDObject* jsdobj);
  1522 } // extern "C"
  1524 #endif /* jsdebug_h___ */

mercurial