js/jsd/jsd_xpc.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 #ifndef JSDSERVICE_H___
michael@0 8 #define JSDSERVICE_H___
michael@0 9
michael@0 10 #include "jsdIDebuggerService.h"
michael@0 11 #include "jsdebug.h"
michael@0 12 #include "nsString.h"
michael@0 13 #include "nsCOMPtr.h"
michael@0 14 #include "nspr.h"
michael@0 15 #include "nsCycleCollectionParticipant.h"
michael@0 16 #include "mozilla/Attributes.h"
michael@0 17
michael@0 18 // #if defined(DEBUG_rginda_l)
michael@0 19 // # define DEBUG_verbose
michael@0 20 // #endif
michael@0 21
michael@0 22 struct LiveEphemeral {
michael@0 23 /* link in a chain of live values list */
michael@0 24 PRCList links;
michael@0 25 jsdIEphemeral *value;
michael@0 26 void *key;
michael@0 27 };
michael@0 28
michael@0 29 struct PCMapEntry {
michael@0 30 uint32_t pc, line;
michael@0 31 };
michael@0 32
michael@0 33 /*******************************************************************************
michael@0 34 * reflected jsd data structures
michael@0 35 *******************************************************************************/
michael@0 36
michael@0 37 class jsdObject MOZ_FINAL : public jsdIObject
michael@0 38 {
michael@0 39 public:
michael@0 40 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 41 NS_DECL_JSDIOBJECT
michael@0 42
michael@0 43 /* you'll normally use use FromPtr() instead of directly constructing one */
michael@0 44 jsdObject (JSDContext *aCx, JSDObject *aObject) :
michael@0 45 mCx(aCx), mObject(aObject)
michael@0 46 {
michael@0 47 }
michael@0 48
michael@0 49 static jsdIObject *FromPtr (JSDContext *aCx,
michael@0 50 JSDObject *aObject)
michael@0 51 {
michael@0 52 if (!aObject)
michael@0 53 return nullptr;
michael@0 54
michael@0 55 jsdIObject *rv = new jsdObject (aCx, aObject);
michael@0 56 NS_IF_ADDREF(rv);
michael@0 57 return rv;
michael@0 58 }
michael@0 59
michael@0 60 private:
michael@0 61 jsdObject(); /* no implementation */
michael@0 62 jsdObject(const jsdObject&); /* no implementation */
michael@0 63
michael@0 64 JSDContext *mCx;
michael@0 65 JSDObject *mObject;
michael@0 66 };
michael@0 67
michael@0 68
michael@0 69 class jsdProperty : public jsdIProperty
michael@0 70 {
michael@0 71 public:
michael@0 72 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 73 NS_DECL_JSDIPROPERTY
michael@0 74 NS_DECL_JSDIEPHEMERAL
michael@0 75
michael@0 76 jsdProperty (JSDContext *aCx, JSDProperty *aProperty);
michael@0 77 virtual ~jsdProperty ();
michael@0 78
michael@0 79 static jsdIProperty *FromPtr (JSDContext *aCx,
michael@0 80 JSDProperty *aProperty)
michael@0 81 {
michael@0 82 if (!aProperty)
michael@0 83 return nullptr;
michael@0 84
michael@0 85 jsdIProperty *rv = new jsdProperty (aCx, aProperty);
michael@0 86 NS_IF_ADDREF(rv);
michael@0 87 return rv;
michael@0 88 }
michael@0 89
michael@0 90 static void InvalidateAll();
michael@0 91
michael@0 92 private:
michael@0 93 jsdProperty(); /* no implementation */
michael@0 94 jsdProperty(const jsdProperty&); /* no implementation */
michael@0 95
michael@0 96 bool mValid;
michael@0 97 LiveEphemeral mLiveListEntry;
michael@0 98 JSDContext *mCx;
michael@0 99 JSDProperty *mProperty;
michael@0 100 };
michael@0 101
michael@0 102 class jsdScript : public jsdIScript
michael@0 103 {
michael@0 104 public:
michael@0 105 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 106 NS_DECL_JSDISCRIPT
michael@0 107 NS_DECL_JSDIEPHEMERAL
michael@0 108
michael@0 109 /* you'll normally use use FromPtr() instead of directly constructing one */
michael@0 110 jsdScript (JSDContext *aCx, JSDScript *aScript);
michael@0 111 virtual ~jsdScript();
michael@0 112
michael@0 113 static jsdIScript *FromPtr (JSDContext *aCx, JSDScript *aScript)
michael@0 114 {
michael@0 115 if (!aScript)
michael@0 116 return nullptr;
michael@0 117
michael@0 118 void *data = JSD_GetScriptPrivate (aScript);
michael@0 119 jsdIScript *rv;
michael@0 120
michael@0 121 if (data) {
michael@0 122 rv = static_cast<jsdIScript *>(data);
michael@0 123 } else {
michael@0 124 rv = new jsdScript (aCx, aScript);
michael@0 125 NS_IF_ADDREF(rv); /* addref for the SetScriptPrivate, released in
michael@0 126 * Invalidate() */
michael@0 127 JSD_SetScriptPrivate (aScript, static_cast<void *>(rv));
michael@0 128 }
michael@0 129
michael@0 130 NS_IF_ADDREF(rv); /* addref for return value */
michael@0 131 return rv;
michael@0 132 }
michael@0 133
michael@0 134 static void InvalidateAll();
michael@0 135
michael@0 136 private:
michael@0 137 static uint32_t LastTag;
michael@0 138
michael@0 139 jsdScript(); /* no implementation */
michael@0 140 jsdScript (const jsdScript&); /* no implementation */
michael@0 141 PCMapEntry* CreatePPLineMap();
michael@0 142 uint32_t PPPcToLine(uint32_t aPC);
michael@0 143 uint32_t PPLineToPc(uint32_t aLine);
michael@0 144
michael@0 145 bool mValid;
michael@0 146 uint32_t mTag;
michael@0 147 JSDContext *mCx;
michael@0 148 JSDScript *mScript;
michael@0 149 nsCString *mFileName;
michael@0 150 nsCString *mFunctionName;
michael@0 151 uint32_t mBaseLineNumber, mLineExtent;
michael@0 152 PCMapEntry *mPPLineMap;
michael@0 153 uint32_t mPCMapSize;
michael@0 154 uintptr_t mFirstPC;
michael@0 155 };
michael@0 156
michael@0 157 uint32_t jsdScript::LastTag = 0;
michael@0 158
michael@0 159 class jsdContext : public jsdIContext
michael@0 160 {
michael@0 161 public:
michael@0 162 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 163 NS_DECL_JSDICONTEXT
michael@0 164 NS_DECL_JSDIEPHEMERAL
michael@0 165
michael@0 166 jsdContext (JSDContext *aJSDCx, JSContext *aJSCx, nsISupports *aISCx);
michael@0 167 virtual ~jsdContext();
michael@0 168
michael@0 169 static void InvalidateAll();
michael@0 170 static jsdIContext *FromPtr (JSDContext *aJSDCx, JSContext *aJSCx);
michael@0 171 private:
michael@0 172 static uint32_t LastTag;
michael@0 173
michael@0 174 jsdContext (); /* no implementation */
michael@0 175 jsdContext (const jsdContext&); /* no implementation */
michael@0 176
michael@0 177 bool mValid;
michael@0 178 // The API exposed by JSD here is problematic, because it allows for per-
michael@0 179 // JSContext script disabling, which no longer exists in the platform.
michael@0 180 // The only consumer here in practice is Firebug, which makes sure to re-
michael@0 181 // enable any disabled script before navigation. But if some other consumer
michael@0 182 // were to disable script, navigate, and try to re-enable it, we'd end up
michael@0 183 // with an unmatched UnblockScript call, which violates platform invariants.
michael@0 184 // So we make a half-hearted attempt to detect this by storing the Window ID
michael@0 185 // of the scope for which we disabled script.
michael@0 186 uint64_t mScriptDisabledForWindowWithID;
michael@0 187 bool IsScriptEnabled() { return !mScriptDisabledForWindowWithID; }
michael@0 188 LiveEphemeral mLiveListEntry;
michael@0 189 uint32_t mTag;
michael@0 190 JSDContext *mJSDCx;
michael@0 191 JSContext *mJSCx;
michael@0 192 nsCOMPtr<nsISupports> mISCx;
michael@0 193 };
michael@0 194
michael@0 195 uint32_t jsdContext::LastTag = 0;
michael@0 196
michael@0 197 class jsdStackFrame : public jsdIStackFrame
michael@0 198 {
michael@0 199 public:
michael@0 200 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 201 NS_DECL_JSDISTACKFRAME
michael@0 202 NS_DECL_JSDIEPHEMERAL
michael@0 203
michael@0 204 /* you'll normally use use FromPtr() instead of directly constructing one */
michael@0 205 jsdStackFrame (JSDContext *aCx, JSDThreadState *aThreadState,
michael@0 206 JSDStackFrameInfo *aStackFrameInfo);
michael@0 207 virtual ~jsdStackFrame();
michael@0 208
michael@0 209 static void InvalidateAll();
michael@0 210 static jsdIStackFrame* FromPtr (JSDContext *aCx,
michael@0 211 JSDThreadState *aThreadState,
michael@0 212 JSDStackFrameInfo *aStackFrameInfo);
michael@0 213
michael@0 214 private:
michael@0 215 jsdStackFrame(); /* no implementation */
michael@0 216 jsdStackFrame(const jsdStackFrame&); /* no implementation */
michael@0 217
michael@0 218 bool mValid;
michael@0 219 LiveEphemeral mLiveListEntry;
michael@0 220 JSDContext *mCx;
michael@0 221 JSDThreadState *mThreadState;
michael@0 222 JSDStackFrameInfo *mStackFrameInfo;
michael@0 223 };
michael@0 224
michael@0 225 class jsdValue : public jsdIValue
michael@0 226 {
michael@0 227 public:
michael@0 228 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 229 NS_DECL_JSDIVALUE
michael@0 230 NS_DECL_JSDIEPHEMERAL
michael@0 231
michael@0 232 /* you'll normally use use FromPtr() instead of directly constructing one */
michael@0 233 jsdValue (JSDContext *aCx, JSDValue *aValue);
michael@0 234 virtual ~jsdValue();
michael@0 235
michael@0 236 static jsdIValue *FromPtr (JSDContext *aCx, JSDValue *aValue);
michael@0 237 static void InvalidateAll();
michael@0 238
michael@0 239 private:
michael@0 240 jsdValue(); /* no implementation */
michael@0 241 jsdValue (const jsdScript&); /* no implementation */
michael@0 242
michael@0 243 bool mValid;
michael@0 244 LiveEphemeral mLiveListEntry;
michael@0 245 JSDContext *mCx;
michael@0 246 JSDValue *mValue;
michael@0 247 };
michael@0 248
michael@0 249 /******************************************************************************
michael@0 250 * debugger service
michael@0 251 ******************************************************************************/
michael@0 252
michael@0 253 class jsdService : public jsdIDebuggerService
michael@0 254 {
michael@0 255 public:
michael@0 256 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 257 NS_DECL_JSDIDEBUGGERSERVICE
michael@0 258
michael@0 259 NS_DECL_CYCLE_COLLECTION_CLASS(jsdService)
michael@0 260
michael@0 261 jsdService() : mOn(false), mPauseLevel(0),
michael@0 262 mNestedLoopLevel(0), mCx(0), mRuntime(0), mErrorHook(0),
michael@0 263 mBreakpointHook(0), mDebugHook(0), mDebuggerHook(0),
michael@0 264 mInterruptHook(0), mScriptHook(0), mThrowHook(0),
michael@0 265 mTopLevelHook(0), mFunctionHook(0),
michael@0 266 mWarnedAboutDeprecation(false),
michael@0 267 mDeprecationAcknowledged(false)
michael@0 268 {
michael@0 269 }
michael@0 270
michael@0 271 virtual ~jsdService();
michael@0 272
michael@0 273 static jsdService *GetService ();
michael@0 274
michael@0 275 bool CheckInterruptHook() { return !!mInterruptHook; }
michael@0 276
michael@0 277 nsresult DoPause(uint32_t *_rval, bool internalCall);
michael@0 278 nsresult DoUnPause(uint32_t *_rval, bool internalCall);
michael@0 279
michael@0 280 private:
michael@0 281 bool mOn;
michael@0 282 uint32_t mPauseLevel;
michael@0 283 uint32_t mNestedLoopLevel;
michael@0 284 JSDContext *mCx;
michael@0 285 JSRuntime *mRuntime;
michael@0 286
michael@0 287 nsCOMPtr<jsdIErrorHook> mErrorHook;
michael@0 288 nsCOMPtr<jsdIExecutionHook> mBreakpointHook;
michael@0 289 nsCOMPtr<jsdIExecutionHook> mDebugHook;
michael@0 290 nsCOMPtr<jsdIExecutionHook> mDebuggerHook;
michael@0 291 nsCOMPtr<jsdIExecutionHook> mInterruptHook;
michael@0 292 nsCOMPtr<jsdIScriptHook> mScriptHook;
michael@0 293 nsCOMPtr<jsdIExecutionHook> mThrowHook;
michael@0 294 nsCOMPtr<jsdICallHook> mTopLevelHook;
michael@0 295 nsCOMPtr<jsdICallHook> mFunctionHook;
michael@0 296 nsCOMPtr<jsdIActivationCallback> mActivationCallback;
michael@0 297
michael@0 298 // True if we have ever printed a warning about JSD being deprecated.
michael@0 299 // We only ever print the warning once.
michael@0 300 bool mWarnedAboutDeprecation;
michael@0 301
michael@0 302 // True if the next call to asyncOn should not produce a warning,
michael@0 303 // because the consumer called jsdIDebuggerService::acknowledgeDeprecation.
michael@0 304 bool mDeprecationAcknowledged;
michael@0 305 };
michael@0 306
michael@0 307 #endif /* JSDSERVICE_H___ */
michael@0 308
michael@0 309
michael@0 310 /* graveyard */
michael@0 311
michael@0 312 #if 0
michael@0 313
michael@0 314 class jsdContext : public jsdIContext
michael@0 315 {
michael@0 316 public:
michael@0 317 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 318 NS_DECL_JSDICONTEXT
michael@0 319
michael@0 320 /* you'll normally use use FromPtr() instead of directly constructing one */
michael@0 321 jsdContext (JSDContext *aCx) : mCx(aCx)
michael@0 322 {
michael@0 323 printf ("++++++ jsdContext\n");
michael@0 324 }
michael@0 325
michael@0 326 static jsdIContext *FromPtr (JSDContext *aCx)
michael@0 327 {
michael@0 328 if (!aCx)
michael@0 329 return nullptr;
michael@0 330
michael@0 331 void *data = JSD_GetContextPrivate (aCx);
michael@0 332 jsdIContext *rv;
michael@0 333
michael@0 334 if (data) {
michael@0 335 rv = static_cast<jsdIContext *>(data);
michael@0 336 } else {
michael@0 337 rv = new jsdContext (aCx);
michael@0 338 NS_IF_ADDREF(rv); // addref for the SetContextPrivate
michael@0 339 JSD_SetContextPrivate (aCx, static_cast<void *>(rv));
michael@0 340 }
michael@0 341
michael@0 342 NS_IF_ADDREF(rv); // addref for the return value
michael@0 343 return rv;
michael@0 344 }
michael@0 345
michael@0 346 virtual ~jsdContext() { printf ("------ ~jsdContext\n"); }
michael@0 347 private:
michael@0 348 jsdContext(); /* no implementation */
michael@0 349 jsdContext(const jsdContext&); /* no implementation */
michael@0 350
michael@0 351 JSDContext *mCx;
michael@0 352 };
michael@0 353
michael@0 354 class jsdThreadState : public jsdIThreadState
michael@0 355 {
michael@0 356 public:
michael@0 357 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 358 NS_DECL_JSDITHREADSTATE
michael@0 359
michael@0 360 /* you'll normally use use FromPtr() instead of directly constructing one */
michael@0 361 jsdThreadState (JSDContext *aCx, JSDThreadState *aThreadState) :
michael@0 362 mCx(aCx), mThreadState(aThreadState)
michael@0 363 {
michael@0 364 }
michael@0 365
michael@0 366 /* XXX These things are only valid for a short period of time, they reflect
michael@0 367 * state in the js engine that will go away after stepping past wherever
michael@0 368 * we were stopped at when this was created. We could keep a list of every
michael@0 369 * instance of this we've created, and "invalidate" them before we let the
michael@0 370 * engine continue. The next time we need a threadstate, we can search the
michael@0 371 * list to find an invalidated one, and just reuse it.
michael@0 372 */
michael@0 373 static jsdIThreadState *FromPtr (JSDContext *aCx,
michael@0 374 JSDThreadState *aThreadState)
michael@0 375 {
michael@0 376 if (!aThreadState)
michael@0 377 return nullptr;
michael@0 378
michael@0 379 jsdIThreadState *rv = new jsdThreadState (aCx, aThreadState);
michael@0 380 NS_IF_ADDREF(rv);
michael@0 381 return rv;
michael@0 382 }
michael@0 383
michael@0 384 private:
michael@0 385 jsdThreadState(); /* no implementation */
michael@0 386 jsdThreadState(const jsdThreadState&); /* no implementation */
michael@0 387
michael@0 388 JSDContext *mCx;
michael@0 389 JSDThreadState *mThreadState;
michael@0 390 };
michael@0 391
michael@0 392 #endif

mercurial