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