Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
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 - Internal ONLY declarations |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef jsd_h___ |
michael@0 | 12 | #define jsd_h___ |
michael@0 | 13 | |
michael@0 | 14 | /* |
michael@0 | 15 | * NOTE: This is a *private* header file and should only be included by |
michael@0 | 16 | * the sources in js/jsd. Defining EXPORT_JSD_API in an outside module |
michael@0 | 17 | * using jsd would be bad. |
michael@0 | 18 | */ |
michael@0 | 19 | #define EXPORT_JSD_API 1 /* if used, must be set before include of jsdebug.h */ |
michael@0 | 20 | |
michael@0 | 21 | /* |
michael@0 | 22 | * These can be controled by the makefile, but this allows a place to set |
michael@0 | 23 | * the values always used in the mozilla client, but perhaps done differently |
michael@0 | 24 | * in other embeddings. |
michael@0 | 25 | */ |
michael@0 | 26 | #ifdef MOZILLA_CLIENT |
michael@0 | 27 | #define JSD_THREADSAFE 1 |
michael@0 | 28 | /* define JSD_HAS_DANGEROUS_THREAD 1 */ |
michael@0 | 29 | #define JSD_USE_NSPR_LOCKS 1 |
michael@0 | 30 | #endif /* MOZILLA_CLIENT */ |
michael@0 | 31 | |
michael@0 | 32 | #include "jsapi.h" |
michael@0 | 33 | #include "jshash.h" |
michael@0 | 34 | #include "jsclist.h" |
michael@0 | 35 | #include "jsdebug.h" |
michael@0 | 36 | #include "js/OldDebugAPI.h" |
michael@0 | 37 | #include "jsd_lock.h" |
michael@0 | 38 | |
michael@0 | 39 | #include <stdio.h> |
michael@0 | 40 | #include <stdlib.h> |
michael@0 | 41 | #include <string.h> |
michael@0 | 42 | |
michael@0 | 43 | #define JSD_MAJOR_VERSION 1 |
michael@0 | 44 | #define JSD_MINOR_VERSION 1 |
michael@0 | 45 | |
michael@0 | 46 | /***************************************************************************/ |
michael@0 | 47 | /* handy macros */ |
michael@0 | 48 | #undef CHECK_BIT_FLAG |
michael@0 | 49 | #define CHECK_BIT_FLAG(f,b) ((f)&(b)) |
michael@0 | 50 | #undef SET_BIT_FLAG |
michael@0 | 51 | #define SET_BIT_FLAG(f,b) ((f)|=(b)) |
michael@0 | 52 | #undef CLEAR_BIT_FLAG |
michael@0 | 53 | #define CLEAR_BIT_FLAG(f,b) ((f)&=(~(b))) |
michael@0 | 54 | |
michael@0 | 55 | #define JSD_IS_DEBUG_ENABLED(jsdc,jsdscript) \ |
michael@0 | 56 | (!(((jsdc->flags & JSD_DEBUG_WHEN_SET) ? 1 : 0) ^ \ |
michael@0 | 57 | ((jsdscript->flags & JSD_SCRIPT_DEBUG_BIT) ? 1 : 0))) |
michael@0 | 58 | #define JSD_IS_PROFILE_ENABLED(jsdc,jsdscript) \ |
michael@0 | 59 | ((jsdc->flags & JSD_COLLECT_PROFILE_DATA) && \ |
michael@0 | 60 | (!(((jsdc->flags & JSD_PROFILE_WHEN_SET) ? 1 : 0) ^ \ |
michael@0 | 61 | ((jsdscript->flags & JSD_SCRIPT_PROFILE_BIT) ? 1 : 0)))) |
michael@0 | 62 | |
michael@0 | 63 | |
michael@0 | 64 | /***************************************************************************/ |
michael@0 | 65 | /* These are not exposed in jsdebug.h - typedef here for consistency */ |
michael@0 | 66 | |
michael@0 | 67 | typedef struct JSDExecHook JSDExecHook; |
michael@0 | 68 | typedef struct JSDAtom JSDAtom; |
michael@0 | 69 | typedef struct JSDProfileData JSDProfileData; |
michael@0 | 70 | /***************************************************************************/ |
michael@0 | 71 | /* Our structures */ |
michael@0 | 72 | |
michael@0 | 73 | /* |
michael@0 | 74 | * XXX What I'm calling a JSDContext is really more of a JSDTaskState. |
michael@0 | 75 | */ |
michael@0 | 76 | |
michael@0 | 77 | struct JSDContext |
michael@0 | 78 | { |
michael@0 | 79 | JSCList links; /* we are part of a JSCList */ |
michael@0 | 80 | bool inited; |
michael@0 | 81 | void* data; |
michael@0 | 82 | uint32_t flags; |
michael@0 | 83 | JSD_ScriptHookProc scriptHook; |
michael@0 | 84 | void* scriptHookData; |
michael@0 | 85 | JSD_ExecutionHookProc interruptHook; |
michael@0 | 86 | void* interruptHookData; |
michael@0 | 87 | JSRuntime* jsrt; |
michael@0 | 88 | JSD_ErrorReporter errorReporter; |
michael@0 | 89 | void* errorReporterData; |
michael@0 | 90 | JSCList threadsStates; |
michael@0 | 91 | JSD_ExecutionHookProc debugBreakHook; |
michael@0 | 92 | void* debugBreakHookData; |
michael@0 | 93 | JSD_ExecutionHookProc debuggerHook; |
michael@0 | 94 | void* debuggerHookData; |
michael@0 | 95 | JSD_ExecutionHookProc throwHook; |
michael@0 | 96 | void* throwHookData; |
michael@0 | 97 | JSD_CallHookProc functionHook; |
michael@0 | 98 | void* functionHookData; |
michael@0 | 99 | JSD_CallHookProc toplevelHook; |
michael@0 | 100 | void* toplevelHookData; |
michael@0 | 101 | JS::Heap<JSObject*> glob; |
michael@0 | 102 | JSD_UserCallbacks userCallbacks; |
michael@0 | 103 | void* user; |
michael@0 | 104 | JSCList scripts; |
michael@0 | 105 | JSHashTable* scriptsTable; |
michael@0 | 106 | JSCList sources; |
michael@0 | 107 | JSCList removedSources; |
michael@0 | 108 | unsigned sourceAlterCount; |
michael@0 | 109 | JSHashTable* atoms; |
michael@0 | 110 | JSCList objectsList; |
michael@0 | 111 | JSHashTable* objectsTable; |
michael@0 | 112 | JSDProfileData* callingFunctionPData; |
michael@0 | 113 | int64_t lastReturnTime; |
michael@0 | 114 | #ifdef JSD_THREADSAFE |
michael@0 | 115 | JSDStaticLock* scriptsLock; |
michael@0 | 116 | JSDStaticLock* sourceTextLock; |
michael@0 | 117 | JSDStaticLock* objectsLock; |
michael@0 | 118 | JSDStaticLock* atomsLock; |
michael@0 | 119 | JSDStaticLock* threadStatesLock; |
michael@0 | 120 | #endif /* JSD_THREADSAFE */ |
michael@0 | 121 | #ifdef JSD_HAS_DANGEROUS_THREAD |
michael@0 | 122 | void* dangerousThread; |
michael@0 | 123 | #endif /* JSD_HAS_DANGEROUS_THREAD */ |
michael@0 | 124 | |
michael@0 | 125 | }; |
michael@0 | 126 | |
michael@0 | 127 | struct JSDScript |
michael@0 | 128 | { |
michael@0 | 129 | JSCList links; /* we are part of a JSCList */ |
michael@0 | 130 | JSDContext* jsdc; /* JSDContext for this jsdscript */ |
michael@0 | 131 | JSScript* script; /* script we are wrapping */ |
michael@0 | 132 | unsigned lineBase; /* we cache this */ |
michael@0 | 133 | unsigned lineExtent; /* we cache this */ |
michael@0 | 134 | JSCList hooks; /* JSCList of JSDExecHooks for this script */ |
michael@0 | 135 | char* url; |
michael@0 | 136 | uint32_t flags; |
michael@0 | 137 | void* data; |
michael@0 | 138 | |
michael@0 | 139 | JSDProfileData *profileData; |
michael@0 | 140 | }; |
michael@0 | 141 | |
michael@0 | 142 | struct JSDProfileData |
michael@0 | 143 | { |
michael@0 | 144 | JSDProfileData* caller; |
michael@0 | 145 | int64_t lastCallStart; |
michael@0 | 146 | int64_t runningTime; |
michael@0 | 147 | unsigned callCount; |
michael@0 | 148 | unsigned recurseDepth; |
michael@0 | 149 | unsigned maxRecurseDepth; |
michael@0 | 150 | double minExecutionTime; |
michael@0 | 151 | double maxExecutionTime; |
michael@0 | 152 | double totalExecutionTime; |
michael@0 | 153 | double minOwnExecutionTime; |
michael@0 | 154 | double maxOwnExecutionTime; |
michael@0 | 155 | double totalOwnExecutionTime; |
michael@0 | 156 | }; |
michael@0 | 157 | |
michael@0 | 158 | struct JSDSourceText |
michael@0 | 159 | { |
michael@0 | 160 | JSCList links; /* we are part of a JSCList */ |
michael@0 | 161 | char* url; |
michael@0 | 162 | char* text; |
michael@0 | 163 | unsigned textLength; |
michael@0 | 164 | unsigned textSpace; |
michael@0 | 165 | bool dirty; |
michael@0 | 166 | JSDSourceStatus status; |
michael@0 | 167 | unsigned alterCount; |
michael@0 | 168 | bool doingEval; |
michael@0 | 169 | }; |
michael@0 | 170 | |
michael@0 | 171 | struct JSDExecHook |
michael@0 | 172 | { |
michael@0 | 173 | JSCList links; /* we are part of a JSCList */ |
michael@0 | 174 | JSDScript* jsdscript; |
michael@0 | 175 | uintptr_t pc; |
michael@0 | 176 | JSD_ExecutionHookProc hook; |
michael@0 | 177 | void* callerdata; |
michael@0 | 178 | }; |
michael@0 | 179 | |
michael@0 | 180 | #define TS_HAS_DISABLED_FRAME 0x01 |
michael@0 | 181 | |
michael@0 | 182 | struct JSDThreadState |
michael@0 | 183 | { |
michael@0 | 184 | JSCList links; /* we are part of a JSCList */ |
michael@0 | 185 | JSContext* context; |
michael@0 | 186 | void* thread; |
michael@0 | 187 | JSCList stack; |
michael@0 | 188 | unsigned stackDepth; |
michael@0 | 189 | unsigned flags; |
michael@0 | 190 | }; |
michael@0 | 191 | |
michael@0 | 192 | struct JSDStackFrameInfo |
michael@0 | 193 | { |
michael@0 | 194 | JSCList links; /* we are part of a JSCList */ |
michael@0 | 195 | JSDThreadState* jsdthreadstate; |
michael@0 | 196 | JSDScript* jsdscript; |
michael@0 | 197 | uintptr_t pc; |
michael@0 | 198 | bool isConstructing; |
michael@0 | 199 | JSAbstractFramePtr frame; |
michael@0 | 200 | }; |
michael@0 | 201 | |
michael@0 | 202 | #define GOT_PROTO ((short) (1 << 0)) |
michael@0 | 203 | #define GOT_PROPS ((short) (1 << 1)) |
michael@0 | 204 | #define GOT_PARENT ((short) (1 << 2)) |
michael@0 | 205 | #define GOT_CTOR ((short) (1 << 3)) |
michael@0 | 206 | |
michael@0 | 207 | struct JSDValue |
michael@0 | 208 | { |
michael@0 | 209 | JS::Heap<JS::Value> val; |
michael@0 | 210 | int nref; |
michael@0 | 211 | JSCList props; |
michael@0 | 212 | JS::Heap<JSString*> string; |
michael@0 | 213 | JS::Heap<JSString*> funName; |
michael@0 | 214 | const char* className; |
michael@0 | 215 | JSDValue* proto; |
michael@0 | 216 | JSDValue* parent; |
michael@0 | 217 | JSDValue* ctor; |
michael@0 | 218 | unsigned flags; |
michael@0 | 219 | }; |
michael@0 | 220 | |
michael@0 | 221 | struct JSDProperty |
michael@0 | 222 | { |
michael@0 | 223 | JSCList links; /* we are part of a JSCList */ |
michael@0 | 224 | int nref; |
michael@0 | 225 | JSDValue* val; |
michael@0 | 226 | JSDValue* name; |
michael@0 | 227 | JSDValue* alias; |
michael@0 | 228 | unsigned flags; |
michael@0 | 229 | }; |
michael@0 | 230 | |
michael@0 | 231 | struct JSDAtom |
michael@0 | 232 | { |
michael@0 | 233 | char* str; /* must be first element in struct for compare */ |
michael@0 | 234 | int refcount; |
michael@0 | 235 | }; |
michael@0 | 236 | |
michael@0 | 237 | struct JSDObject |
michael@0 | 238 | { |
michael@0 | 239 | JSCList links; /* we are part of a JSCList */ |
michael@0 | 240 | JSObject* obj; |
michael@0 | 241 | JSDAtom* newURL; |
michael@0 | 242 | unsigned newLineno; |
michael@0 | 243 | JSDAtom* ctorURL; |
michael@0 | 244 | unsigned ctorLineno; |
michael@0 | 245 | JSDAtom* ctorName; |
michael@0 | 246 | }; |
michael@0 | 247 | |
michael@0 | 248 | /***************************************************************************/ |
michael@0 | 249 | /* Code validation support */ |
michael@0 | 250 | |
michael@0 | 251 | #ifdef DEBUG |
michael@0 | 252 | extern void JSD_ASSERT_VALID_CONTEXT(JSDContext* jsdc); |
michael@0 | 253 | extern void JSD_ASSERT_VALID_SCRIPT(JSDScript* jsdscript); |
michael@0 | 254 | extern void JSD_ASSERT_VALID_SOURCE_TEXT(JSDSourceText* jsdsrc); |
michael@0 | 255 | extern void JSD_ASSERT_VALID_THREAD_STATE(JSDThreadState* jsdthreadstate); |
michael@0 | 256 | extern void JSD_ASSERT_VALID_STACK_FRAME(JSDStackFrameInfo* jsdframe); |
michael@0 | 257 | extern void JSD_ASSERT_VALID_EXEC_HOOK(JSDExecHook* jsdhook); |
michael@0 | 258 | extern void JSD_ASSERT_VALID_VALUE(JSDValue* jsdval); |
michael@0 | 259 | extern void JSD_ASSERT_VALID_PROPERTY(JSDProperty* jsdprop); |
michael@0 | 260 | extern void JSD_ASSERT_VALID_OBJECT(JSDObject* jsdobj); |
michael@0 | 261 | #else |
michael@0 | 262 | #define JSD_ASSERT_VALID_CONTEXT(x) ((void)0) |
michael@0 | 263 | #define JSD_ASSERT_VALID_SCRIPT(x) ((void)0) |
michael@0 | 264 | #define JSD_ASSERT_VALID_SOURCE_TEXT(x) ((void)0) |
michael@0 | 265 | #define JSD_ASSERT_VALID_THREAD_STATE(x)((void)0) |
michael@0 | 266 | #define JSD_ASSERT_VALID_STACK_FRAME(x) ((void)0) |
michael@0 | 267 | #define JSD_ASSERT_VALID_EXEC_HOOK(x) ((void)0) |
michael@0 | 268 | #define JSD_ASSERT_VALID_VALUE(x) ((void)0) |
michael@0 | 269 | #define JSD_ASSERT_VALID_PROPERTY(x) ((void)0) |
michael@0 | 270 | #define JSD_ASSERT_VALID_OBJECT(x) ((void)0) |
michael@0 | 271 | #endif |
michael@0 | 272 | |
michael@0 | 273 | /***************************************************************************/ |
michael@0 | 274 | /* higher level functions */ |
michael@0 | 275 | |
michael@0 | 276 | extern JSDContext* |
michael@0 | 277 | jsd_DebuggerOnForUser(JSRuntime* jsrt, |
michael@0 | 278 | JSD_UserCallbacks* callbacks, |
michael@0 | 279 | void* user, |
michael@0 | 280 | JSObject* scopeobj); |
michael@0 | 281 | |
michael@0 | 282 | extern JSDContext* |
michael@0 | 283 | jsd_DebuggerOn(void); |
michael@0 | 284 | |
michael@0 | 285 | extern void |
michael@0 | 286 | jsd_DebuggerOff(JSDContext* jsdc); |
michael@0 | 287 | |
michael@0 | 288 | extern void |
michael@0 | 289 | jsd_DebuggerPause(JSDContext* jsdc, bool forceAllHooksOff); |
michael@0 | 290 | |
michael@0 | 291 | extern void |
michael@0 | 292 | jsd_DebuggerUnpause(JSDContext* jsdc); |
michael@0 | 293 | |
michael@0 | 294 | extern void |
michael@0 | 295 | jsd_SetUserCallbacks(JSRuntime* jsrt, JSD_UserCallbacks* callbacks, void* user); |
michael@0 | 296 | |
michael@0 | 297 | extern JSDContext* |
michael@0 | 298 | jsd_JSDContextForJSContext(JSContext* context); |
michael@0 | 299 | |
michael@0 | 300 | extern void* |
michael@0 | 301 | jsd_SetContextPrivate(JSDContext* jsdc, void *data); |
michael@0 | 302 | |
michael@0 | 303 | extern void* |
michael@0 | 304 | jsd_GetContextPrivate(JSDContext* jsdc); |
michael@0 | 305 | |
michael@0 | 306 | extern void |
michael@0 | 307 | jsd_ClearAllProfileData(JSDContext* jsdc); |
michael@0 | 308 | |
michael@0 | 309 | extern bool |
michael@0 | 310 | jsd_SetErrorReporter(JSDContext* jsdc, |
michael@0 | 311 | JSD_ErrorReporter reporter, |
michael@0 | 312 | void* callerdata); |
michael@0 | 313 | |
michael@0 | 314 | extern bool |
michael@0 | 315 | jsd_GetErrorReporter(JSDContext* jsdc, |
michael@0 | 316 | JSD_ErrorReporter* reporter, |
michael@0 | 317 | void** callerdata); |
michael@0 | 318 | |
michael@0 | 319 | /***************************************************************************/ |
michael@0 | 320 | /* Script functions */ |
michael@0 | 321 | |
michael@0 | 322 | extern bool |
michael@0 | 323 | jsd_InitScriptManager(JSDContext *jsdc); |
michael@0 | 324 | |
michael@0 | 325 | extern void |
michael@0 | 326 | jsd_DestroyScriptManager(JSDContext* jsdc); |
michael@0 | 327 | |
michael@0 | 328 | extern JSDScript* |
michael@0 | 329 | jsd_FindJSDScript(JSDContext* jsdc, |
michael@0 | 330 | JSScript *script); |
michael@0 | 331 | |
michael@0 | 332 | extern JSDScript* |
michael@0 | 333 | jsd_FindOrCreateJSDScript(JSDContext *jsdc, |
michael@0 | 334 | JSContext *cx, |
michael@0 | 335 | JSScript *script, |
michael@0 | 336 | JSAbstractFramePtr frame); |
michael@0 | 337 | |
michael@0 | 338 | extern JSDProfileData* |
michael@0 | 339 | jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script); |
michael@0 | 340 | |
michael@0 | 341 | extern uint32_t |
michael@0 | 342 | jsd_GetScriptFlags(JSDContext *jsdc, JSDScript *script); |
michael@0 | 343 | |
michael@0 | 344 | extern void |
michael@0 | 345 | jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32_t flags); |
michael@0 | 346 | |
michael@0 | 347 | extern unsigned |
michael@0 | 348 | jsd_GetScriptCallCount(JSDContext* jsdc, JSDScript *script); |
michael@0 | 349 | |
michael@0 | 350 | extern unsigned |
michael@0 | 351 | jsd_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script); |
michael@0 | 352 | |
michael@0 | 353 | extern double |
michael@0 | 354 | jsd_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script); |
michael@0 | 355 | |
michael@0 | 356 | extern double |
michael@0 | 357 | jsd_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script); |
michael@0 | 358 | |
michael@0 | 359 | extern double |
michael@0 | 360 | jsd_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script); |
michael@0 | 361 | |
michael@0 | 362 | extern double |
michael@0 | 363 | jsd_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script); |
michael@0 | 364 | |
michael@0 | 365 | extern double |
michael@0 | 366 | jsd_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script); |
michael@0 | 367 | |
michael@0 | 368 | extern double |
michael@0 | 369 | jsd_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script); |
michael@0 | 370 | |
michael@0 | 371 | extern void |
michael@0 | 372 | jsd_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script); |
michael@0 | 373 | |
michael@0 | 374 | extern JSScript * |
michael@0 | 375 | jsd_GetJSScript (JSDContext *jsdc, JSDScript *script); |
michael@0 | 376 | |
michael@0 | 377 | extern JSFunction * |
michael@0 | 378 | jsd_GetJSFunction (JSDContext *jsdc, JSDScript *script); |
michael@0 | 379 | |
michael@0 | 380 | extern JSDScript* |
michael@0 | 381 | jsd_IterateScripts(JSDContext* jsdc, JSDScript **iterp); |
michael@0 | 382 | |
michael@0 | 383 | extern void * |
michael@0 | 384 | jsd_SetScriptPrivate (JSDScript *jsdscript, void *data); |
michael@0 | 385 | |
michael@0 | 386 | extern void * |
michael@0 | 387 | jsd_GetScriptPrivate (JSDScript *jsdscript); |
michael@0 | 388 | |
michael@0 | 389 | extern bool |
michael@0 | 390 | jsd_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript); |
michael@0 | 391 | |
michael@0 | 392 | extern const char* |
michael@0 | 393 | jsd_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript); |
michael@0 | 394 | |
michael@0 | 395 | extern JSString* |
michael@0 | 396 | jsd_GetScriptFunctionId(JSDContext* jsdc, JSDScript *jsdscript); |
michael@0 | 397 | |
michael@0 | 398 | extern unsigned |
michael@0 | 399 | jsd_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript); |
michael@0 | 400 | |
michael@0 | 401 | extern unsigned |
michael@0 | 402 | jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript); |
michael@0 | 403 | |
michael@0 | 404 | extern bool |
michael@0 | 405 | jsd_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata); |
michael@0 | 406 | |
michael@0 | 407 | extern bool |
michael@0 | 408 | jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata); |
michael@0 | 409 | |
michael@0 | 410 | extern uintptr_t |
michael@0 | 411 | jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, unsigned line); |
michael@0 | 412 | |
michael@0 | 413 | extern unsigned |
michael@0 | 414 | jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, uintptr_t pc); |
michael@0 | 415 | |
michael@0 | 416 | extern bool |
michael@0 | 417 | jsd_GetLinePCs(JSDContext* jsdc, JSDScript* jsdscript, |
michael@0 | 418 | unsigned startLine, unsigned maxLines, |
michael@0 | 419 | unsigned* count, unsigned** lines, uintptr_t** pcs); |
michael@0 | 420 | |
michael@0 | 421 | extern void |
michael@0 | 422 | jsd_NewScriptHookProc( |
michael@0 | 423 | JSContext *cx, |
michael@0 | 424 | const char *filename, /* URL this script loads from */ |
michael@0 | 425 | unsigned lineno, /* line where this script starts */ |
michael@0 | 426 | JSScript *script, |
michael@0 | 427 | JSFunction *fun, |
michael@0 | 428 | void* callerdata); |
michael@0 | 429 | |
michael@0 | 430 | extern void |
michael@0 | 431 | jsd_DestroyScriptHookProc( |
michael@0 | 432 | JSFreeOp *fop, |
michael@0 | 433 | JSScript *script, |
michael@0 | 434 | void* callerdata); |
michael@0 | 435 | |
michael@0 | 436 | /* Script execution hook functions */ |
michael@0 | 437 | |
michael@0 | 438 | extern bool |
michael@0 | 439 | jsd_SetExecutionHook(JSDContext* jsdc, |
michael@0 | 440 | JSDScript* jsdscript, |
michael@0 | 441 | uintptr_t pc, |
michael@0 | 442 | JSD_ExecutionHookProc hook, |
michael@0 | 443 | void* callerdata); |
michael@0 | 444 | |
michael@0 | 445 | extern bool |
michael@0 | 446 | jsd_ClearExecutionHook(JSDContext* jsdc, |
michael@0 | 447 | JSDScript* jsdscript, |
michael@0 | 448 | uintptr_t pc); |
michael@0 | 449 | |
michael@0 | 450 | extern bool |
michael@0 | 451 | jsd_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript); |
michael@0 | 452 | |
michael@0 | 453 | extern bool |
michael@0 | 454 | jsd_ClearAllExecutionHooks(JSDContext* jsdc); |
michael@0 | 455 | |
michael@0 | 456 | extern void |
michael@0 | 457 | jsd_ScriptCreated(JSDContext* jsdc, |
michael@0 | 458 | JSContext *cx, |
michael@0 | 459 | const char *filename, /* URL this script loads from */ |
michael@0 | 460 | unsigned lineno, /* line where this script starts */ |
michael@0 | 461 | JSScript *script, |
michael@0 | 462 | JSFunction *fun); |
michael@0 | 463 | |
michael@0 | 464 | extern void |
michael@0 | 465 | jsd_ScriptDestroyed(JSDContext* jsdc, |
michael@0 | 466 | JSFreeOp *fop, |
michael@0 | 467 | JSScript *script); |
michael@0 | 468 | |
michael@0 | 469 | /***************************************************************************/ |
michael@0 | 470 | /* Source Text functions */ |
michael@0 | 471 | |
michael@0 | 472 | extern JSDSourceText* |
michael@0 | 473 | jsd_IterateSources(JSDContext* jsdc, JSDSourceText **iterp); |
michael@0 | 474 | |
michael@0 | 475 | extern JSDSourceText* |
michael@0 | 476 | jsd_FindSourceForURL(JSDContext* jsdc, const char* url); |
michael@0 | 477 | |
michael@0 | 478 | extern const char* |
michael@0 | 479 | jsd_GetSourceURL(JSDContext* jsdc, JSDSourceText* jsdsrc); |
michael@0 | 480 | |
michael@0 | 481 | extern bool |
michael@0 | 482 | jsd_GetSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc, |
michael@0 | 483 | const char** ppBuf, int* pLen); |
michael@0 | 484 | |
michael@0 | 485 | extern void |
michael@0 | 486 | jsd_ClearSourceText(JSDContext* jsdc, JSDSourceText* jsdsrc); |
michael@0 | 487 | |
michael@0 | 488 | extern JSDSourceStatus |
michael@0 | 489 | jsd_GetSourceStatus(JSDContext* jsdc, JSDSourceText* jsdsrc); |
michael@0 | 490 | |
michael@0 | 491 | extern bool |
michael@0 | 492 | jsd_IsSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc); |
michael@0 | 493 | |
michael@0 | 494 | extern void |
michael@0 | 495 | jsd_SetSourceDirty(JSDContext* jsdc, JSDSourceText* jsdsrc, bool dirty); |
michael@0 | 496 | |
michael@0 | 497 | extern unsigned |
michael@0 | 498 | jsd_GetSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc); |
michael@0 | 499 | |
michael@0 | 500 | extern unsigned |
michael@0 | 501 | jsd_IncrementSourceAlterCount(JSDContext* jsdc, JSDSourceText* jsdsrc); |
michael@0 | 502 | |
michael@0 | 503 | extern JSDSourceText* |
michael@0 | 504 | jsd_NewSourceText(JSDContext* jsdc, const char* url); |
michael@0 | 505 | |
michael@0 | 506 | extern JSDSourceText* |
michael@0 | 507 | jsd_AppendSourceText(JSDContext* jsdc, |
michael@0 | 508 | JSDSourceText* jsdsrc, |
michael@0 | 509 | const char* text, /* *not* zero terminated */ |
michael@0 | 510 | size_t length, |
michael@0 | 511 | JSDSourceStatus status); |
michael@0 | 512 | |
michael@0 | 513 | extern JSDSourceText* |
michael@0 | 514 | jsd_AppendUCSourceText(JSDContext* jsdc, |
michael@0 | 515 | JSDSourceText* jsdsrc, |
michael@0 | 516 | const jschar* text, /* *not* zero terminated */ |
michael@0 | 517 | size_t length, |
michael@0 | 518 | JSDSourceStatus status); |
michael@0 | 519 | |
michael@0 | 520 | /* convienence function for adding complete source of url in one call */ |
michael@0 | 521 | extern bool |
michael@0 | 522 | jsd_AddFullSourceText(JSDContext* jsdc, |
michael@0 | 523 | const char* text, /* *not* zero terminated */ |
michael@0 | 524 | size_t length, |
michael@0 | 525 | const char* url); |
michael@0 | 526 | |
michael@0 | 527 | extern void |
michael@0 | 528 | jsd_DestroyAllSources(JSDContext* jsdc); |
michael@0 | 529 | |
michael@0 | 530 | extern char* |
michael@0 | 531 | jsd_BuildNormalizedURL(const char* url_string); |
michael@0 | 532 | |
michael@0 | 533 | extern void |
michael@0 | 534 | jsd_StartingEvalUsingFilename(JSDContext* jsdc, const char* url); |
michael@0 | 535 | |
michael@0 | 536 | extern void |
michael@0 | 537 | jsd_FinishedEvalUsingFilename(JSDContext* jsdc, const char* url); |
michael@0 | 538 | |
michael@0 | 539 | /***************************************************************************/ |
michael@0 | 540 | /* Interrupt Hook functions */ |
michael@0 | 541 | |
michael@0 | 542 | extern bool |
michael@0 | 543 | jsd_SetInterruptHook(JSDContext* jsdc, |
michael@0 | 544 | JSD_ExecutionHookProc hook, |
michael@0 | 545 | void* callerdata); |
michael@0 | 546 | |
michael@0 | 547 | extern bool |
michael@0 | 548 | jsd_ClearInterruptHook(JSDContext* jsdc); |
michael@0 | 549 | |
michael@0 | 550 | extern bool |
michael@0 | 551 | jsd_EnableSingleStepInterrupts(JSDContext* jsdc, |
michael@0 | 552 | JSDScript* jsdscript, |
michael@0 | 553 | bool enable); |
michael@0 | 554 | |
michael@0 | 555 | extern bool |
michael@0 | 556 | jsd_SetDebugBreakHook(JSDContext* jsdc, |
michael@0 | 557 | JSD_ExecutionHookProc hook, |
michael@0 | 558 | void* callerdata); |
michael@0 | 559 | |
michael@0 | 560 | extern bool |
michael@0 | 561 | jsd_ClearDebugBreakHook(JSDContext* jsdc); |
michael@0 | 562 | |
michael@0 | 563 | extern bool |
michael@0 | 564 | jsd_SetDebuggerHook(JSDContext* jsdc, |
michael@0 | 565 | JSD_ExecutionHookProc hook, |
michael@0 | 566 | void* callerdata); |
michael@0 | 567 | |
michael@0 | 568 | extern bool |
michael@0 | 569 | jsd_ClearDebuggerHook(JSDContext* jsdc); |
michael@0 | 570 | |
michael@0 | 571 | extern JSTrapStatus |
michael@0 | 572 | jsd_CallExecutionHook(JSDContext* jsdc, |
michael@0 | 573 | JSContext* cx, |
michael@0 | 574 | unsigned type, |
michael@0 | 575 | JSD_ExecutionHookProc hook, |
michael@0 | 576 | void* hookData, |
michael@0 | 577 | jsval* rval); |
michael@0 | 578 | |
michael@0 | 579 | extern bool |
michael@0 | 580 | jsd_CallCallHook (JSDContext* jsdc, |
michael@0 | 581 | JSContext* cx, |
michael@0 | 582 | unsigned type, |
michael@0 | 583 | JSD_CallHookProc hook, |
michael@0 | 584 | void* hookData); |
michael@0 | 585 | |
michael@0 | 586 | extern bool |
michael@0 | 587 | jsd_SetThrowHook(JSDContext* jsdc, |
michael@0 | 588 | JSD_ExecutionHookProc hook, |
michael@0 | 589 | void* callerdata); |
michael@0 | 590 | extern bool |
michael@0 | 591 | jsd_ClearThrowHook(JSDContext* jsdc); |
michael@0 | 592 | |
michael@0 | 593 | extern JSTrapStatus |
michael@0 | 594 | jsd_DebuggerHandler(JSContext *cx, JSScript *script, jsbytecode *pc, |
michael@0 | 595 | jsval *rval, void *closure); |
michael@0 | 596 | |
michael@0 | 597 | extern JSTrapStatus |
michael@0 | 598 | jsd_ThrowHandler(JSContext *cx, JSScript *script, jsbytecode *pc, |
michael@0 | 599 | jsval *rval, void *closure); |
michael@0 | 600 | |
michael@0 | 601 | extern bool |
michael@0 | 602 | jsd_SetFunctionHook(JSDContext* jsdc, |
michael@0 | 603 | JSD_CallHookProc hook, |
michael@0 | 604 | void* callerdata); |
michael@0 | 605 | |
michael@0 | 606 | extern bool |
michael@0 | 607 | jsd_ClearFunctionHook(JSDContext* jsdc); |
michael@0 | 608 | |
michael@0 | 609 | extern bool |
michael@0 | 610 | jsd_SetTopLevelHook(JSDContext* jsdc, |
michael@0 | 611 | JSD_CallHookProc hook, |
michael@0 | 612 | void* callerdata); |
michael@0 | 613 | |
michael@0 | 614 | extern bool |
michael@0 | 615 | jsd_ClearTopLevelHook(JSDContext* jsdc); |
michael@0 | 616 | |
michael@0 | 617 | /***************************************************************************/ |
michael@0 | 618 | /* Stack Frame functions */ |
michael@0 | 619 | |
michael@0 | 620 | extern unsigned |
michael@0 | 621 | jsd_GetCountOfStackFrames(JSDContext* jsdc, JSDThreadState* jsdthreadstate); |
michael@0 | 622 | |
michael@0 | 623 | extern JSDStackFrameInfo* |
michael@0 | 624 | jsd_GetStackFrame(JSDContext* jsdc, JSDThreadState* jsdthreadstate); |
michael@0 | 625 | |
michael@0 | 626 | extern JSContext* |
michael@0 | 627 | jsd_GetJSContext(JSDContext* jsdc, JSDThreadState* jsdthreadstate); |
michael@0 | 628 | |
michael@0 | 629 | extern JSDStackFrameInfo* |
michael@0 | 630 | jsd_GetCallingStackFrame(JSDContext* jsdc, |
michael@0 | 631 | JSDThreadState* jsdthreadstate, |
michael@0 | 632 | JSDStackFrameInfo* jsdframe); |
michael@0 | 633 | |
michael@0 | 634 | extern JSDScript* |
michael@0 | 635 | jsd_GetScriptForStackFrame(JSDContext* jsdc, |
michael@0 | 636 | JSDThreadState* jsdthreadstate, |
michael@0 | 637 | JSDStackFrameInfo* jsdframe); |
michael@0 | 638 | |
michael@0 | 639 | extern uintptr_t |
michael@0 | 640 | jsd_GetPCForStackFrame(JSDContext* jsdc, |
michael@0 | 641 | JSDThreadState* jsdthreadstate, |
michael@0 | 642 | JSDStackFrameInfo* jsdframe); |
michael@0 | 643 | |
michael@0 | 644 | extern JSDValue* |
michael@0 | 645 | jsd_GetCallObjectForStackFrame(JSDContext* jsdc, |
michael@0 | 646 | JSDThreadState* jsdthreadstate, |
michael@0 | 647 | JSDStackFrameInfo* jsdframe); |
michael@0 | 648 | |
michael@0 | 649 | extern JSDValue* |
michael@0 | 650 | jsd_GetScopeChainForStackFrame(JSDContext* jsdc, |
michael@0 | 651 | JSDThreadState* jsdthreadstate, |
michael@0 | 652 | JSDStackFrameInfo* jsdframe); |
michael@0 | 653 | |
michael@0 | 654 | extern bool |
michael@0 | 655 | jsd_IsStackFrameDebugger(JSDContext* jsdc, |
michael@0 | 656 | JSDThreadState* jsdthreadstate, |
michael@0 | 657 | JSDStackFrameInfo* jsdframe); |
michael@0 | 658 | |
michael@0 | 659 | extern bool |
michael@0 | 660 | jsd_IsStackFrameConstructing(JSDContext* jsdc, |
michael@0 | 661 | JSDThreadState* jsdthreadstate, |
michael@0 | 662 | JSDStackFrameInfo* jsdframe); |
michael@0 | 663 | |
michael@0 | 664 | extern JSDValue* |
michael@0 | 665 | jsd_GetThisForStackFrame(JSDContext* jsdc, |
michael@0 | 666 | JSDThreadState* jsdthreadstate, |
michael@0 | 667 | JSDStackFrameInfo* jsdframe); |
michael@0 | 668 | |
michael@0 | 669 | extern JSString* |
michael@0 | 670 | jsd_GetIdForStackFrame(JSDContext* jsdc, |
michael@0 | 671 | JSDThreadState* jsdthreadstate, |
michael@0 | 672 | JSDStackFrameInfo* jsdframe); |
michael@0 | 673 | |
michael@0 | 674 | extern JSDThreadState* |
michael@0 | 675 | jsd_NewThreadState(JSDContext* jsdc, JSContext *cx); |
michael@0 | 676 | |
michael@0 | 677 | extern void |
michael@0 | 678 | jsd_DestroyThreadState(JSDContext* jsdc, JSDThreadState* jsdthreadstate); |
michael@0 | 679 | |
michael@0 | 680 | extern bool |
michael@0 | 681 | jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc, |
michael@0 | 682 | JSDThreadState* jsdthreadstate, |
michael@0 | 683 | JSDStackFrameInfo* jsdframe, |
michael@0 | 684 | const jschar *bytes, unsigned length, |
michael@0 | 685 | const char *filename, unsigned lineno, |
michael@0 | 686 | bool eatExceptions, JS::MutableHandleValue rval); |
michael@0 | 687 | |
michael@0 | 688 | extern bool |
michael@0 | 689 | jsd_EvaluateScriptInStackFrame(JSDContext* jsdc, |
michael@0 | 690 | JSDThreadState* jsdthreadstate, |
michael@0 | 691 | JSDStackFrameInfo* jsdframe, |
michael@0 | 692 | const char *bytes, unsigned length, |
michael@0 | 693 | const char *filename, unsigned lineno, |
michael@0 | 694 | bool eatExceptions, JS::MutableHandleValue rval); |
michael@0 | 695 | |
michael@0 | 696 | extern JSString* |
michael@0 | 697 | jsd_ValToStringInStackFrame(JSDContext* jsdc, |
michael@0 | 698 | JSDThreadState* jsdthreadstate, |
michael@0 | 699 | JSDStackFrameInfo* jsdframe, |
michael@0 | 700 | jsval val); |
michael@0 | 701 | |
michael@0 | 702 | extern bool |
michael@0 | 703 | jsd_IsValidThreadState(JSDContext* jsdc, |
michael@0 | 704 | JSDThreadState* jsdthreadstate); |
michael@0 | 705 | |
michael@0 | 706 | extern bool |
michael@0 | 707 | jsd_IsValidFrameInThreadState(JSDContext* jsdc, |
michael@0 | 708 | JSDThreadState* jsdthreadstate, |
michael@0 | 709 | JSDStackFrameInfo* jsdframe); |
michael@0 | 710 | |
michael@0 | 711 | extern JSDValue* |
michael@0 | 712 | jsd_GetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate); |
michael@0 | 713 | |
michael@0 | 714 | extern bool |
michael@0 | 715 | jsd_SetException(JSDContext* jsdc, JSDThreadState* jsdthreadstate, |
michael@0 | 716 | JSDValue* jsdval); |
michael@0 | 717 | |
michael@0 | 718 | /***************************************************************************/ |
michael@0 | 719 | /* Locking support */ |
michael@0 | 720 | |
michael@0 | 721 | /* protos are in js_lock.h for: |
michael@0 | 722 | * jsd_CreateLock |
michael@0 | 723 | * jsd_Lock |
michael@0 | 724 | * jsd_Unlock |
michael@0 | 725 | * jsd_IsLocked |
michael@0 | 726 | * jsd_CurrentThread |
michael@0 | 727 | */ |
michael@0 | 728 | |
michael@0 | 729 | #ifdef JSD_THREADSAFE |
michael@0 | 730 | |
michael@0 | 731 | /* the system-wide lock */ |
michael@0 | 732 | extern JSDStaticLock* _jsd_global_lock; |
michael@0 | 733 | #define JSD_LOCK() \ |
michael@0 | 734 | JS_BEGIN_MACRO \ |
michael@0 | 735 | if(!_jsd_global_lock) \ |
michael@0 | 736 | _jsd_global_lock = jsd_CreateLock(); \ |
michael@0 | 737 | MOZ_ASSERT(_jsd_global_lock); \ |
michael@0 | 738 | jsd_Lock(_jsd_global_lock); \ |
michael@0 | 739 | JS_END_MACRO |
michael@0 | 740 | |
michael@0 | 741 | #define JSD_UNLOCK() \ |
michael@0 | 742 | JS_BEGIN_MACRO \ |
michael@0 | 743 | MOZ_ASSERT(_jsd_global_lock); \ |
michael@0 | 744 | jsd_Unlock(_jsd_global_lock); \ |
michael@0 | 745 | JS_END_MACRO |
michael@0 | 746 | |
michael@0 | 747 | /* locks for the subsystems of a given context */ |
michael@0 | 748 | #define JSD_INIT_LOCKS(jsdc) \ |
michael@0 | 749 | ( (nullptr != (jsdc->scriptsLock = jsd_CreateLock())) && \ |
michael@0 | 750 | (nullptr != (jsdc->sourceTextLock = jsd_CreateLock())) && \ |
michael@0 | 751 | (nullptr != (jsdc->atomsLock = jsd_CreateLock())) && \ |
michael@0 | 752 | (nullptr != (jsdc->objectsLock = jsd_CreateLock())) && \ |
michael@0 | 753 | (nullptr != (jsdc->threadStatesLock = jsd_CreateLock())) ) |
michael@0 | 754 | |
michael@0 | 755 | #define JSD_LOCK_SCRIPTS(jsdc) jsd_Lock(jsdc->scriptsLock) |
michael@0 | 756 | #define JSD_UNLOCK_SCRIPTS(jsdc) jsd_Unlock(jsdc->scriptsLock) |
michael@0 | 757 | |
michael@0 | 758 | #define JSD_LOCK_SOURCE_TEXT(jsdc) jsd_Lock(jsdc->sourceTextLock) |
michael@0 | 759 | #define JSD_UNLOCK_SOURCE_TEXT(jsdc) jsd_Unlock(jsdc->sourceTextLock) |
michael@0 | 760 | |
michael@0 | 761 | #define JSD_LOCK_ATOMS(jsdc) jsd_Lock(jsdc->atomsLock) |
michael@0 | 762 | #define JSD_UNLOCK_ATOMS(jsdc) jsd_Unlock(jsdc->atomsLock) |
michael@0 | 763 | |
michael@0 | 764 | #define JSD_LOCK_OBJECTS(jsdc) jsd_Lock(jsdc->objectsLock) |
michael@0 | 765 | #define JSD_UNLOCK_OBJECTS(jsdc) jsd_Unlock(jsdc->objectsLock) |
michael@0 | 766 | |
michael@0 | 767 | #define JSD_LOCK_THREADSTATES(jsdc) jsd_Lock(jsdc->threadStatesLock) |
michael@0 | 768 | #define JSD_UNLOCK_THREADSTATES(jsdc) jsd_Unlock(jsdc->threadStatesLock) |
michael@0 | 769 | |
michael@0 | 770 | #else /* !JSD_THREADSAFE */ |
michael@0 | 771 | |
michael@0 | 772 | #define JSD_LOCK() ((void)0) |
michael@0 | 773 | #define JSD_UNLOCK() ((void)0) |
michael@0 | 774 | |
michael@0 | 775 | #define JSD_INIT_LOCKS(jsdc) 1 |
michael@0 | 776 | |
michael@0 | 777 | #define JSD_LOCK_SCRIPTS(jsdc) ((void)0) |
michael@0 | 778 | #define JSD_UNLOCK_SCRIPTS(jsdc) ((void)0) |
michael@0 | 779 | |
michael@0 | 780 | #define JSD_LOCK_SOURCE_TEXT(jsdc) ((void)0) |
michael@0 | 781 | #define JSD_UNLOCK_SOURCE_TEXT(jsdc) ((void)0) |
michael@0 | 782 | |
michael@0 | 783 | #define JSD_LOCK_ATOMS(jsdc) ((void)0) |
michael@0 | 784 | #define JSD_UNLOCK_ATOMS(jsdc) ((void)0) |
michael@0 | 785 | |
michael@0 | 786 | #define JSD_LOCK_OBJECTS(jsdc) ((void)0) |
michael@0 | 787 | #define JSD_UNLOCK_OBJECTS(jsdc) ((void)0) |
michael@0 | 788 | |
michael@0 | 789 | #define JSD_LOCK_THREADSTATES(jsdc) ((void)0) |
michael@0 | 790 | #define JSD_UNLOCK_THREADSTATES(jsdc) ((void)0) |
michael@0 | 791 | |
michael@0 | 792 | #endif /* JSD_THREADSAFE */ |
michael@0 | 793 | |
michael@0 | 794 | /* NOTE: These are intended for ASSERTs. Thus we supply checks for both |
michael@0 | 795 | * LOCKED and UNLOCKED (rather that just LOCKED and !LOCKED) so that in |
michael@0 | 796 | * the DEBUG non-Threadsafe case we can have an ASSERT that always succeeds |
michael@0 | 797 | * without having to special case things in the code. |
michael@0 | 798 | */ |
michael@0 | 799 | #if defined(JSD_THREADSAFE) && defined(DEBUG) |
michael@0 | 800 | #define JSD_SCRIPTS_LOCKED(jsdc) (jsd_IsLocked(jsdc->scriptsLock)) |
michael@0 | 801 | #define JSD_SOURCE_TEXT_LOCKED(jsdc) (jsd_IsLocked(jsdc->sourceTextLock)) |
michael@0 | 802 | #define JSD_ATOMS_LOCKED(jsdc) (jsd_IsLocked(jsdc->atomsLock)) |
michael@0 | 803 | #define JSD_OBJECTS_LOCKED(jsdc) (jsd_IsLocked(jsdc->objectsLock)) |
michael@0 | 804 | #define JSD_THREADSTATES_LOCKED(jsdc) (jsd_IsLocked(jsdc->threadStatesLock)) |
michael@0 | 805 | #define JSD_SCRIPTS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->scriptsLock)) |
michael@0 | 806 | #define JSD_SOURCE_TEXT_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->sourceTextLock)) |
michael@0 | 807 | #define JSD_ATOMS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->atomsLock)) |
michael@0 | 808 | #define JSD_OBJECTS_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->objectsLock)) |
michael@0 | 809 | #define JSD_THREADSTATES_UNLOCKED(jsdc) (!jsd_IsLocked(jsdc->threadStatesLock)) |
michael@0 | 810 | #else |
michael@0 | 811 | #define JSD_SCRIPTS_LOCKED(jsdc) 1 |
michael@0 | 812 | #define JSD_SOURCE_TEXT_LOCKED(jsdc) 1 |
michael@0 | 813 | #define JSD_ATOMS_LOCKED(jsdc) 1 |
michael@0 | 814 | #define JSD_OBJECTS_LOCKED(jsdc) 1 |
michael@0 | 815 | #define JSD_THREADSTATES_LOCKED(jsdc) 1 |
michael@0 | 816 | #define JSD_SCRIPTS_UNLOCKED(jsdc) 1 |
michael@0 | 817 | #define JSD_SOURCE_TEXT_UNLOCKED(jsdc) 1 |
michael@0 | 818 | #define JSD_ATOMS_UNLOCKED(jsdc) 1 |
michael@0 | 819 | #define JSD_OBJECTS_UNLOCKED(jsdc) 1 |
michael@0 | 820 | #define JSD_THREADSTATES_UNLOCKED(jsdc) 1 |
michael@0 | 821 | #endif /* defined(JSD_THREADSAFE) && defined(DEBUG) */ |
michael@0 | 822 | |
michael@0 | 823 | /***************************************************************************/ |
michael@0 | 824 | /* Threading support */ |
michael@0 | 825 | |
michael@0 | 826 | #ifdef JSD_THREADSAFE |
michael@0 | 827 | |
michael@0 | 828 | #define JSD_CURRENT_THREAD() jsd_CurrentThread() |
michael@0 | 829 | |
michael@0 | 830 | #else /* !JSD_THREADSAFE */ |
michael@0 | 831 | |
michael@0 | 832 | #define JSD_CURRENT_THREAD() ((void*)0) |
michael@0 | 833 | |
michael@0 | 834 | #endif /* JSD_THREADSAFE */ |
michael@0 | 835 | |
michael@0 | 836 | /***************************************************************************/ |
michael@0 | 837 | /* Dangerous thread support */ |
michael@0 | 838 | |
michael@0 | 839 | #ifdef JSD_HAS_DANGEROUS_THREAD |
michael@0 | 840 | |
michael@0 | 841 | #define JSD_IS_DANGEROUS_THREAD(jsdc) \ |
michael@0 | 842 | (JSD_CURRENT_THREAD() == jsdc->dangerousThread) |
michael@0 | 843 | |
michael@0 | 844 | #else /* !JSD_HAS_DANGEROUS_THREAD */ |
michael@0 | 845 | |
michael@0 | 846 | #define JSD_IS_DANGEROUS_THREAD(jsdc) 0 |
michael@0 | 847 | |
michael@0 | 848 | #endif /* JSD_HAS_DANGEROUS_THREAD */ |
michael@0 | 849 | |
michael@0 | 850 | /***************************************************************************/ |
michael@0 | 851 | /* Value and Property Functions */ |
michael@0 | 852 | |
michael@0 | 853 | extern JSDValue* |
michael@0 | 854 | jsd_NewValue(JSDContext* jsdc, jsval val); |
michael@0 | 855 | |
michael@0 | 856 | extern void |
michael@0 | 857 | jsd_DropValue(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 858 | |
michael@0 | 859 | extern jsval |
michael@0 | 860 | jsd_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 861 | |
michael@0 | 862 | extern void |
michael@0 | 863 | jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 864 | |
michael@0 | 865 | /**************************************************/ |
michael@0 | 866 | |
michael@0 | 867 | extern bool |
michael@0 | 868 | jsd_IsValueObject(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 869 | |
michael@0 | 870 | extern bool |
michael@0 | 871 | jsd_IsValueNumber(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 872 | |
michael@0 | 873 | extern bool |
michael@0 | 874 | jsd_IsValueInt(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 875 | |
michael@0 | 876 | extern bool |
michael@0 | 877 | jsd_IsValueDouble(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 878 | |
michael@0 | 879 | extern bool |
michael@0 | 880 | jsd_IsValueString(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 881 | |
michael@0 | 882 | extern bool |
michael@0 | 883 | jsd_IsValueBoolean(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 884 | |
michael@0 | 885 | extern bool |
michael@0 | 886 | jsd_IsValueNull(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 887 | |
michael@0 | 888 | extern bool |
michael@0 | 889 | jsd_IsValueVoid(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 890 | |
michael@0 | 891 | extern bool |
michael@0 | 892 | jsd_IsValuePrimitive(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 893 | |
michael@0 | 894 | extern bool |
michael@0 | 895 | jsd_IsValueFunction(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 896 | |
michael@0 | 897 | extern bool |
michael@0 | 898 | jsd_IsValueNative(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 899 | |
michael@0 | 900 | /**************************************************/ |
michael@0 | 901 | |
michael@0 | 902 | extern bool |
michael@0 | 903 | jsd_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 904 | |
michael@0 | 905 | extern int32_t |
michael@0 | 906 | jsd_GetValueInt(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 907 | |
michael@0 | 908 | extern double |
michael@0 | 909 | jsd_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 910 | |
michael@0 | 911 | extern JSString* |
michael@0 | 912 | jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 913 | |
michael@0 | 914 | extern JSString* |
michael@0 | 915 | jsd_GetValueFunctionId(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 916 | |
michael@0 | 917 | extern JSFunction* |
michael@0 | 918 | jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 919 | |
michael@0 | 920 | /**************************************************/ |
michael@0 | 921 | |
michael@0 | 922 | extern unsigned |
michael@0 | 923 | jsd_GetCountOfProperties(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 924 | |
michael@0 | 925 | extern JSDProperty* |
michael@0 | 926 | jsd_IterateProperties(JSDContext* jsdc, JSDValue* jsdval, JSDProperty **iterp); |
michael@0 | 927 | |
michael@0 | 928 | extern JSDProperty* |
michael@0 | 929 | jsd_GetValueProperty(JSDContext* jsdc, JSDValue* jsdval, JSString* name); |
michael@0 | 930 | |
michael@0 | 931 | extern JSDValue* |
michael@0 | 932 | jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 933 | |
michael@0 | 934 | extern JSDValue* |
michael@0 | 935 | jsd_GetValueParent(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 936 | |
michael@0 | 937 | extern JSDValue* |
michael@0 | 938 | jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 939 | |
michael@0 | 940 | extern const char* |
michael@0 | 941 | jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 942 | |
michael@0 | 943 | extern JSDScript* |
michael@0 | 944 | jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 945 | |
michael@0 | 946 | /**************************************************/ |
michael@0 | 947 | |
michael@0 | 948 | extern void |
michael@0 | 949 | jsd_DropProperty(JSDContext* jsdc, JSDProperty* jsdprop); |
michael@0 | 950 | |
michael@0 | 951 | extern JSDValue* |
michael@0 | 952 | jsd_GetPropertyName(JSDContext* jsdc, JSDProperty* jsdprop); |
michael@0 | 953 | |
michael@0 | 954 | extern JSDValue* |
michael@0 | 955 | jsd_GetPropertyValue(JSDContext* jsdc, JSDProperty* jsdprop); |
michael@0 | 956 | |
michael@0 | 957 | extern JSDValue* |
michael@0 | 958 | jsd_GetPropertyAlias(JSDContext* jsdc, JSDProperty* jsdprop); |
michael@0 | 959 | |
michael@0 | 960 | extern unsigned |
michael@0 | 961 | jsd_GetPropertyFlags(JSDContext* jsdc, JSDProperty* jsdprop); |
michael@0 | 962 | |
michael@0 | 963 | /**************************************************/ |
michael@0 | 964 | /* Stepping Functions */ |
michael@0 | 965 | |
michael@0 | 966 | extern void * |
michael@0 | 967 | jsd_FunctionCallHook(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, |
michael@0 | 968 | bool before, bool *ok, void *closure); |
michael@0 | 969 | |
michael@0 | 970 | extern void * |
michael@0 | 971 | jsd_TopLevelCallHook(JSContext *cx, JSAbstractFramePtr frame, bool isConstructing, |
michael@0 | 972 | bool before, bool *ok, void *closure); |
michael@0 | 973 | |
michael@0 | 974 | /**************************************************/ |
michael@0 | 975 | /* Object Functions */ |
michael@0 | 976 | |
michael@0 | 977 | extern bool |
michael@0 | 978 | jsd_InitObjectManager(JSDContext* jsdc); |
michael@0 | 979 | |
michael@0 | 980 | extern void |
michael@0 | 981 | jsd_DestroyObjectManager(JSDContext* jsdc); |
michael@0 | 982 | |
michael@0 | 983 | extern void |
michael@0 | 984 | jsd_DestroyObjects(JSDContext* jsdc); |
michael@0 | 985 | |
michael@0 | 986 | extern void |
michael@0 | 987 | jsd_Constructing(JSDContext* jsdc, JSContext *cx, JSObject *obj, |
michael@0 | 988 | JSAbstractFramePtr frame); |
michael@0 | 989 | |
michael@0 | 990 | extern JSDObject* |
michael@0 | 991 | jsd_IterateObjects(JSDContext* jsdc, JSDObject** iterp); |
michael@0 | 992 | |
michael@0 | 993 | extern JSObject* |
michael@0 | 994 | jsd_GetWrappedObject(JSDContext* jsdc, JSDObject* jsdobj); |
michael@0 | 995 | |
michael@0 | 996 | extern const char* |
michael@0 | 997 | jsd_GetObjectNewURL(JSDContext* jsdc, JSDObject* jsdobj); |
michael@0 | 998 | |
michael@0 | 999 | extern unsigned |
michael@0 | 1000 | jsd_GetObjectNewLineNumber(JSDContext* jsdc, JSDObject* jsdobj); |
michael@0 | 1001 | |
michael@0 | 1002 | extern const char* |
michael@0 | 1003 | jsd_GetObjectConstructorURL(JSDContext* jsdc, JSDObject* jsdobj); |
michael@0 | 1004 | |
michael@0 | 1005 | extern unsigned |
michael@0 | 1006 | jsd_GetObjectConstructorLineNumber(JSDContext* jsdc, JSDObject* jsdobj); |
michael@0 | 1007 | |
michael@0 | 1008 | extern const char* |
michael@0 | 1009 | jsd_GetObjectConstructorName(JSDContext* jsdc, JSDObject* jsdobj); |
michael@0 | 1010 | |
michael@0 | 1011 | extern JSDObject* |
michael@0 | 1012 | jsd_GetJSDObjectForJSObject(JSDContext* jsdc, JSObject* jsobj); |
michael@0 | 1013 | |
michael@0 | 1014 | extern JSDObject* |
michael@0 | 1015 | jsd_GetObjectForValue(JSDContext* jsdc, JSDValue* jsdval); |
michael@0 | 1016 | |
michael@0 | 1017 | /* |
michael@0 | 1018 | * returns new refcounted JSDValue |
michael@0 | 1019 | */ |
michael@0 | 1020 | extern JSDValue* |
michael@0 | 1021 | jsd_GetValueForObject(JSDContext* jsdc, JSDObject* jsdobj); |
michael@0 | 1022 | |
michael@0 | 1023 | /**************************************************/ |
michael@0 | 1024 | /* Atom Functions */ |
michael@0 | 1025 | |
michael@0 | 1026 | extern bool |
michael@0 | 1027 | jsd_CreateAtomTable(JSDContext* jsdc); |
michael@0 | 1028 | |
michael@0 | 1029 | extern void |
michael@0 | 1030 | jsd_DestroyAtomTable(JSDContext* jsdc); |
michael@0 | 1031 | |
michael@0 | 1032 | extern JSDAtom* |
michael@0 | 1033 | jsd_AddAtom(JSDContext* jsdc, const char* str); |
michael@0 | 1034 | |
michael@0 | 1035 | extern JSDAtom* |
michael@0 | 1036 | jsd_CloneAtom(JSDContext* jsdc, JSDAtom* atom); |
michael@0 | 1037 | |
michael@0 | 1038 | extern void |
michael@0 | 1039 | jsd_DropAtom(JSDContext* jsdc, JSDAtom* atom); |
michael@0 | 1040 | |
michael@0 | 1041 | #define JSD_ATOM_TO_STRING(a) ((const char*)((a)->str)) |
michael@0 | 1042 | |
michael@0 | 1043 | struct AutoSaveExceptionState { |
michael@0 | 1044 | AutoSaveExceptionState(JSContext *cx) : mCx(cx) { |
michael@0 | 1045 | mState = JS_SaveExceptionState(cx); |
michael@0 | 1046 | } |
michael@0 | 1047 | ~AutoSaveExceptionState() { |
michael@0 | 1048 | JS_RestoreExceptionState(mCx, mState); |
michael@0 | 1049 | } |
michael@0 | 1050 | JSContext *mCx; |
michael@0 | 1051 | JSExceptionState *mState; |
michael@0 | 1052 | }; |
michael@0 | 1053 | |
michael@0 | 1054 | #endif /* jsd_h___ */ |