2013-04-16 20:47:10 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-04-17 08:50:41 +00:00
|
|
|
|
2013-08-17 22:50:18 +00:00
|
|
|
#include "jsfriendapi.h"
|
2010-03-04 05:02:55 +00:00
|
|
|
#include "jsd_xpc.h"
|
2013-11-13 00:43:34 +00:00
|
|
|
#include "xpcpublic.h"
|
2001-04-17 08:50:41 +00:00
|
|
|
|
2013-01-27 20:35:12 +00:00
|
|
|
#include "js/GCAPI.h"
|
2013-08-27 02:05:20 +00:00
|
|
|
#include "js/OldDebugAPI.h"
|
2013-01-27 20:35:12 +00:00
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
#include "nsIXPConnect.h"
|
2010-06-10 18:11:40 +00:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
2001-04-17 08:50:41 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2001-10-30 13:41:32 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsIJSRuntimeService.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsIThreadInternal.h"
|
2013-03-17 07:55:16 +00:00
|
|
|
#include "nsTArray.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2001-04-21 07:21:27 +00:00
|
|
|
#include "nsMemory.h"
|
2001-04-17 08:50:41 +00:00
|
|
|
#include "jsdebug.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2012-04-30 20:58:38 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2012-06-13 03:45:08 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2001-04-17 08:50:41 +00:00
|
|
|
|
2006-06-26 10:36:28 +00:00
|
|
|
/* XXX DOM dependency */
|
2002-01-29 08:32:23 +00:00
|
|
|
#include "nsIScriptContext.h"
|
2013-11-13 00:43:34 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-09-04 21:06:55 +00:00
|
|
|
#include "nsDOMJSUtils.h"
|
2013-04-04 09:27:37 +00:00
|
|
|
#include "SandboxPrivate.h"
|
|
|
|
#include "nsJSPrincipals.h"
|
2013-04-18 15:36:05 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-12-12 01:51:58 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2001-04-20 03:54:05 +00:00
|
|
|
|
2013-06-12 21:17:55 +00:00
|
|
|
using mozilla::AutoSafeJSContext;
|
2013-06-12 21:17:56 +00:00
|
|
|
using mozilla::AutoPushJSContext;
|
2013-12-12 01:51:58 +00:00
|
|
|
using mozilla::dom::AutoSystemCaller;
|
2013-06-12 21:17:55 +00:00
|
|
|
|
2003-07-26 22:37:11 +00:00
|
|
|
/*
|
2002-01-12 00:56:35 +00:00
|
|
|
* defining CAUTIOUS_SCRIPTHOOK makes jsds disable GC while calling out to the
|
2003-07-26 22:37:11 +00:00
|
|
|
* script hook. This was a hack to avoid some js engine problems that should
|
|
|
|
* be fixed now (see Mozilla bug 77636).
|
2002-01-12 00:56:35 +00:00
|
|
|
*/
|
2003-07-26 22:37:11 +00:00
|
|
|
#undef CAUTIOUS_SCRIPTHOOK
|
2001-08-28 22:02:07 +00:00
|
|
|
|
2001-07-03 22:19:04 +00:00
|
|
|
#ifdef DEBUG_verbose
|
|
|
|
# define DEBUG_COUNT(name, count) \
|
|
|
|
{ if ((count % 10) == 0) printf (name ": %i\n", count); }
|
2013-04-25 03:54:24 +00:00
|
|
|
# define DEBUG_CREATE(name, count) {count++; DEBUG_COUNT ("+++++ " name,count)}
|
|
|
|
# define DEBUG_DESTROY(name, count) {count--; DEBUG_COUNT ("----- " name,count)}
|
2001-07-03 22:19:04 +00:00
|
|
|
#else
|
2001-07-05 09:06:24 +00:00
|
|
|
# define DEBUG_CREATE(name, count)
|
|
|
|
# define DEBUG_DESTROY(name, count)
|
2001-07-03 22:19:04 +00:00
|
|
|
#endif
|
|
|
|
|
2002-01-29 08:32:23 +00:00
|
|
|
#define ASSERT_VALID_CONTEXT { if (!mCx) return NS_ERROR_NOT_AVAILABLE; }
|
|
|
|
#define ASSERT_VALID_EPHEMERAL { if (!mValid) return NS_ERROR_NOT_AVAILABLE; }
|
2001-05-01 21:33:43 +00:00
|
|
|
|
2001-05-21 06:00:12 +00:00
|
|
|
#define JSDSERVICE_CID \
|
|
|
|
{ /* f1299dc2-1dd1-11b2-a347-ee6b7660e048 */ \
|
|
|
|
0xf1299dc2, \
|
|
|
|
0x1dd1, \
|
|
|
|
0x11b2, \
|
|
|
|
{0xa3, 0x47, 0xee, 0x6b, 0x76, 0x60, 0xe0, 0x48} \
|
|
|
|
}
|
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
#define JSDASO_CID \
|
|
|
|
{ /* 2fd6b7f6-eb8c-4f32-ad26-113f2c02d0fe */ \
|
|
|
|
0x2fd6b7f6, \
|
|
|
|
0xeb8c, \
|
|
|
|
0x4f32, \
|
|
|
|
{0xad, 0x26, 0x11, 0x3f, 0x2c, 0x02, 0xd0, 0xfe} \
|
|
|
|
}
|
|
|
|
|
2003-04-18 20:12:11 +00:00
|
|
|
#define JSDS_MAJOR_VERSION 1
|
2003-08-14 22:49:09 +00:00
|
|
|
#define JSDS_MINOR_VERSION 2
|
2003-04-18 20:12:11 +00:00
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
#define NS_CATMAN_CTRID "@mozilla.org/categorymanager;1"
|
|
|
|
#define NS_JSRT_CTRID "@mozilla.org/js/xpc/RuntimeService;1"
|
|
|
|
|
|
|
|
#define AUTOREG_CATEGORY "xpcom-autoregistration"
|
|
|
|
#define APPSTART_CATEGORY "app-startup"
|
2003-05-28 22:34:20 +00:00
|
|
|
#define JSD_AUTOREG_ENTRY "JSDebugger Startup Observer"
|
2006-02-28 17:36:58 +00:00
|
|
|
#define JSD_STARTUP_ENTRY "JSDebugger Startup Observer"
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2012-02-17 22:35:20 +00:00
|
|
|
static void
|
2013-01-27 20:35:12 +00:00
|
|
|
jsds_GCSliceCallbackProc (JSRuntime *rt, JS::GCProgress progress, const JS::GCDescription &desc);
|
2001-05-01 21:33:43 +00:00
|
|
|
|
2001-04-25 21:54:59 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* global vars
|
2003-04-18 20:12:11 +00:00
|
|
|
******************************************************************************/
|
2001-04-25 21:54:59 +00:00
|
|
|
|
2003-04-18 20:12:11 +00:00
|
|
|
const char implementationString[] = "Mozilla JavaScript Debugger Service";
|
2001-04-20 03:54:05 +00:00
|
|
|
|
2001-09-05 21:29:59 +00:00
|
|
|
const char jsdServiceCtrID[] = "@mozilla.org/js/jsd/debugger-service;1";
|
2006-02-28 17:36:58 +00:00
|
|
|
const char jsdARObserverCtrID[] = "@mozilla.org/js/jsd/app-start-observer;2";
|
|
|
|
const char jsdASObserverCtrID[] = "service,@mozilla.org/js/jsd/app-start-observer;2";
|
2001-04-17 08:50:41 +00:00
|
|
|
|
2001-05-04 22:14:04 +00:00
|
|
|
#ifdef DEBUG_verbose
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t gScriptCount = 0;
|
|
|
|
uint32_t gValueCount = 0;
|
|
|
|
uint32_t gPropertyCount = 0;
|
|
|
|
uint32_t gContextCount = 0;
|
|
|
|
uint32_t gFrameCount = 0;
|
2001-05-04 22:14:04 +00:00
|
|
|
#endif
|
2001-05-01 21:33:43 +00:00
|
|
|
|
2012-02-17 22:35:20 +00:00
|
|
|
static jsdService *gJsds = 0;
|
2013-01-27 20:35:12 +00:00
|
|
|
static JS::GCSliceCallback gPrevGCSliceCallback = jsds_GCSliceCallbackProc;
|
2012-02-17 22:35:20 +00:00
|
|
|
static bool gGCRunning = false;
|
2001-07-03 22:19:04 +00:00
|
|
|
|
2001-05-01 21:33:43 +00:00
|
|
|
static struct DeadScript {
|
|
|
|
PRCList links;
|
|
|
|
JSDContext *jsdc;
|
|
|
|
jsdIScript *script;
|
2012-07-30 14:20:58 +00:00
|
|
|
} *gDeadScripts = nullptr;
|
2001-07-03 22:19:04 +00:00
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
enum PatternType {
|
|
|
|
ptIgnore = 0U,
|
|
|
|
ptStartsWith = 1U,
|
|
|
|
ptEndsWith = 2U,
|
|
|
|
ptContains = 3U,
|
|
|
|
ptEquals = 4U
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct FilterRecord {
|
|
|
|
PRCList links;
|
|
|
|
jsdIFilter *filterObject;
|
2009-01-08 04:42:15 +00:00
|
|
|
nsCString urlPattern;
|
2001-10-30 13:41:32 +00:00
|
|
|
PatternType patternType;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t startLine;
|
|
|
|
uint32_t endLine;
|
2012-07-30 14:20:58 +00:00
|
|
|
} *gFilters = nullptr;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
static struct LiveEphemeral *gLiveValues = nullptr;
|
|
|
|
static struct LiveEphemeral *gLiveProperties = nullptr;
|
|
|
|
static struct LiveEphemeral *gLiveContexts = nullptr;
|
|
|
|
static struct LiveEphemeral *gLiveStackFrames = nullptr;
|
2001-07-03 22:19:04 +00:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* utility functions for ephemeral lists
|
|
|
|
*******************************************************************************/
|
2002-01-29 08:32:23 +00:00
|
|
|
already_AddRefed<jsdIEphemeral>
|
|
|
|
jsds_FindEphemeral (LiveEphemeral **listHead, void *key)
|
|
|
|
{
|
|
|
|
if (!*listHead)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2002-01-29 08:32:23 +00:00
|
|
|
|
|
|
|
LiveEphemeral *lv_record =
|
2007-07-08 07:08:04 +00:00
|
|
|
reinterpret_cast<LiveEphemeral *>
|
|
|
|
(PR_NEXT_LINK(&(*listHead)->links));
|
2002-01-29 08:32:23 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (lv_record->key == key)
|
|
|
|
{
|
2013-04-22 11:15:59 +00:00
|
|
|
nsCOMPtr<jsdIEphemeral> ret = lv_record->value;
|
|
|
|
return ret.forget();
|
2002-01-29 08:32:23 +00:00
|
|
|
}
|
2007-07-08 07:08:04 +00:00
|
|
|
lv_record = reinterpret_cast<LiveEphemeral *>
|
|
|
|
(PR_NEXT_LINK(&lv_record->links));
|
2002-01-29 08:32:23 +00:00
|
|
|
}
|
|
|
|
while (lv_record != *listHead);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2002-01-29 08:32:23 +00:00
|
|
|
}
|
2001-07-03 22:19:04 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
jsds_InvalidateAllEphemerals (LiveEphemeral **listHead)
|
|
|
|
{
|
|
|
|
LiveEphemeral *lv_record =
|
2007-07-08 07:08:04 +00:00
|
|
|
reinterpret_cast<LiveEphemeral *>
|
|
|
|
(PR_NEXT_LINK(&(*listHead)->links));
|
2010-12-21 01:12:00 +00:00
|
|
|
do
|
2001-07-03 22:19:04 +00:00
|
|
|
{
|
|
|
|
LiveEphemeral *next =
|
2007-07-08 07:08:04 +00:00
|
|
|
reinterpret_cast<LiveEphemeral *>
|
|
|
|
(PR_NEXT_LINK(&lv_record->links));
|
2001-07-03 22:19:04 +00:00
|
|
|
lv_record->value->Invalidate();
|
|
|
|
lv_record = next;
|
|
|
|
}
|
2010-12-21 01:12:00 +00:00
|
|
|
while (*listHead);
|
2001-07-03 22:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsds_InsertEphemeral (LiveEphemeral **listHead, LiveEphemeral *item)
|
|
|
|
{
|
|
|
|
if (*listHead) {
|
|
|
|
/* if the list exists, add to it */
|
|
|
|
PR_APPEND_LINK(&item->links, &(*listHead)->links);
|
|
|
|
} else {
|
|
|
|
/* otherwise create the list */
|
|
|
|
PR_INIT_CLIST(&item->links);
|
|
|
|
*listHead = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsds_RemoveEphemeral (LiveEphemeral **listHead, LiveEphemeral *item)
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
LiveEphemeral *next = reinterpret_cast<LiveEphemeral *>
|
|
|
|
(PR_NEXT_LINK(&item->links));
|
2001-07-03 22:19:04 +00:00
|
|
|
|
|
|
|
if (next == item)
|
|
|
|
{
|
|
|
|
/* if the current item is also the next item, we're the only element,
|
|
|
|
* null out the list head */
|
|
|
|
NS_ASSERTION (*listHead == item,
|
|
|
|
"How could we not be the head of a one item list?");
|
2012-07-30 14:20:58 +00:00
|
|
|
*listHead = nullptr;
|
2001-07-03 22:19:04 +00:00
|
|
|
}
|
|
|
|
else if (item == *listHead)
|
|
|
|
{
|
|
|
|
/* otherwise, if we're currently the list head, change it */
|
|
|
|
*listHead = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_REMOVE_AND_INIT_LINK(&item->links);
|
|
|
|
}
|
2001-04-25 18:20:47 +00:00
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* utility functions for filters
|
|
|
|
*******************************************************************************/
|
|
|
|
void
|
2009-12-13 17:11:39 +00:00
|
|
|
jsds_FreeFilter (FilterRecord *rec)
|
2001-10-30 13:41:32 +00:00
|
|
|
{
|
2009-12-13 17:11:39 +00:00
|
|
|
NS_IF_RELEASE (rec->filterObject);
|
|
|
|
PR_Free (rec);
|
2001-10-30 13:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copies appropriate |filter| attributes into |rec|.
|
|
|
|
* False return indicates failure, the contents of |rec| will not be changed.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2001-10-30 13:41:32 +00:00
|
|
|
jsds_SyncFilter (FilterRecord *rec, jsdIFilter *filter)
|
|
|
|
{
|
|
|
|
NS_ASSERTION (rec, "jsds_SyncFilter without rec");
|
|
|
|
NS_ASSERTION (filter, "jsds_SyncFilter without filter");
|
2013-05-22 21:42:43 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t startLine;
|
2013-05-22 21:42:43 +00:00
|
|
|
nsresult rv = filter->GetStartLine(&startLine);
|
2001-10-30 13:41:32 +00:00
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t endLine;
|
2001-10-30 13:41:32 +00:00
|
|
|
rv = filter->GetStartLine(&endLine);
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString urlPattern;
|
2009-01-08 04:42:15 +00:00
|
|
|
rv = filter->GetUrlPattern (urlPattern);
|
2001-10-30 13:41:32 +00:00
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t len = urlPattern.Length();
|
2009-01-08 04:42:15 +00:00
|
|
|
if (len) {
|
2001-10-30 13:41:32 +00:00
|
|
|
if (urlPattern[0] == '*') {
|
|
|
|
/* pattern starts with a *, shift all chars once to the left,
|
|
|
|
* including the trailing null. */
|
2009-01-08 04:42:15 +00:00
|
|
|
urlPattern = Substring(urlPattern, 1, len);
|
2001-10-30 13:41:32 +00:00
|
|
|
|
|
|
|
if (urlPattern[len - 2] == '*') {
|
|
|
|
/* pattern is in the format "*foo*", overwrite the final * with
|
|
|
|
* a null. */
|
2009-01-08 04:42:15 +00:00
|
|
|
urlPattern.Truncate(len - 2);
|
2001-10-30 13:41:32 +00:00
|
|
|
rec->patternType = ptContains;
|
|
|
|
} else {
|
|
|
|
/* pattern is in the format "*foo", just make a note of the
|
|
|
|
* new length. */
|
|
|
|
rec->patternType = ptEndsWith;
|
|
|
|
}
|
|
|
|
} else if (urlPattern[len - 1] == '*') {
|
|
|
|
/* pattern is in the format "foo*", overwrite the final * with a
|
|
|
|
* null. */
|
2009-01-08 04:42:15 +00:00
|
|
|
urlPattern.Truncate(len - 1);
|
2001-10-30 13:41:32 +00:00
|
|
|
rec->patternType = ptStartsWith;
|
|
|
|
} else {
|
|
|
|
/* pattern is in the format "foo". */
|
|
|
|
rec->patternType = ptEquals;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rec->patternType = ptIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we got everything we need without failing, now copy it into rec. */
|
|
|
|
|
|
|
|
if (rec->filterObject != filter) {
|
|
|
|
NS_IF_RELEASE(rec->filterObject);
|
|
|
|
NS_ADDREF(filter);
|
|
|
|
rec->filterObject = filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec->startLine = startLine;
|
|
|
|
rec->endLine = endLine;
|
|
|
|
|
|
|
|
rec->urlPattern = urlPattern;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterRecord *
|
|
|
|
jsds_FindFilter (jsdIFilter *filter)
|
|
|
|
{
|
|
|
|
if (!gFilters)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
|
|
|
FilterRecord *current = gFilters;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (current->filterObject == filter)
|
|
|
|
return current;
|
2007-07-08 07:08:04 +00:00
|
|
|
current = reinterpret_cast<FilterRecord *>
|
|
|
|
(PR_NEXT_LINK(¤t->links));
|
2001-10-30 13:41:32 +00:00
|
|
|
} while (current != gFilters);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2001-10-30 13:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* returns true if the hook should be executed. */
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2001-10-30 13:41:32 +00:00
|
|
|
jsds_FilterHook (JSDContext *jsdc, JSDThreadState *state)
|
|
|
|
{
|
|
|
|
JSDStackFrameInfo *frame = JSD_GetStackFrame (jsdc, state);
|
2002-01-24 09:20:51 +00:00
|
|
|
|
|
|
|
if (!frame) {
|
|
|
|
NS_WARNING("No frame in threadstate");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2002-01-24 09:20:51 +00:00
|
|
|
}
|
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
JSDScript *script = JSD_GetScriptForStackFrame (jsdc, state, frame);
|
2002-02-14 07:57:30 +00:00
|
|
|
if (!script)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t pc = JSD_GetPCForStackFrame (jsdc, state, frame);
|
2002-01-24 09:20:51 +00:00
|
|
|
|
2011-11-11 19:35:06 +00:00
|
|
|
nsCString url(JSD_GetScriptFilename (jsdc, script));
|
2009-01-08 04:42:15 +00:00
|
|
|
if (url.IsEmpty()) {
|
2002-02-14 07:57:30 +00:00
|
|
|
NS_WARNING ("Script with no filename");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2002-01-24 09:20:51 +00:00
|
|
|
}
|
|
|
|
|
2002-02-14 07:57:30 +00:00
|
|
|
if (!gFilters)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2002-02-14 07:57:30 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t currentLine = JSD_GetClosestLine (jsdc, script, pc);
|
|
|
|
uint32_t len = 0;
|
2001-10-30 13:41:32 +00:00
|
|
|
FilterRecord *currentFilter = gFilters;
|
|
|
|
do {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t flags = 0;
|
2010-07-11 12:38:58 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
currentFilter->filterObject->GetFlags(&flags);
|
2001-10-30 13:41:32 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Error getting flags for filter");
|
2010-07-11 12:38:58 +00:00
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
if (flags & jsdIFilter::FLAG_ENABLED) {
|
2013-05-22 21:42:43 +00:00
|
|
|
/* If there is no start line, or the start line is before
|
|
|
|
* or equal to the current */
|
|
|
|
if ((!currentFilter->startLine ||
|
2001-10-30 13:41:32 +00:00
|
|
|
currentFilter->startLine <= currentLine) &&
|
|
|
|
/* and there is no end line, or the end line is after
|
|
|
|
* or equal to the current */
|
|
|
|
(!currentFilter->endLine ||
|
|
|
|
currentFilter->endLine >= currentLine)) {
|
|
|
|
/* then we're going to have to compare the url. */
|
|
|
|
if (currentFilter->patternType == ptIgnore)
|
2008-09-08 20:41:09 +00:00
|
|
|
return !!(flags & jsdIFilter::FLAG_PASS);
|
2002-02-14 07:57:30 +00:00
|
|
|
|
|
|
|
if (!len)
|
2009-01-08 04:42:15 +00:00
|
|
|
len = url.Length();
|
|
|
|
nsCString urlPattern = currentFilter->urlPattern;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t patternLength = urlPattern.Length();
|
2009-01-08 04:42:15 +00:00
|
|
|
if (len >= patternLength) {
|
2001-10-30 13:41:32 +00:00
|
|
|
switch (currentFilter->patternType) {
|
|
|
|
case ptEquals:
|
2009-01-08 04:42:15 +00:00
|
|
|
if (urlPattern.Equals(url))
|
2008-09-08 20:41:09 +00:00
|
|
|
return !!(flags & jsdIFilter::FLAG_PASS);
|
2001-10-30 13:41:32 +00:00
|
|
|
break;
|
|
|
|
case ptStartsWith:
|
2009-01-08 04:42:15 +00:00
|
|
|
if (urlPattern.Equals(Substring(url, 0, patternLength)))
|
2008-09-08 20:41:09 +00:00
|
|
|
return !!(flags & jsdIFilter::FLAG_PASS);
|
2001-10-30 13:41:32 +00:00
|
|
|
break;
|
|
|
|
case ptEndsWith:
|
2009-01-08 04:42:15 +00:00
|
|
|
if (urlPattern.Equals(Substring(url, len - patternLength)))
|
2008-09-08 20:41:09 +00:00
|
|
|
return !!(flags & jsdIFilter::FLAG_PASS);
|
2001-10-30 13:41:32 +00:00
|
|
|
break;
|
|
|
|
case ptContains:
|
2009-01-08 04:42:15 +00:00
|
|
|
{
|
|
|
|
nsACString::const_iterator start, end;
|
|
|
|
url.BeginReading(start);
|
|
|
|
url.EndReading(end);
|
|
|
|
if (FindInReadable(currentFilter->urlPattern, start, end))
|
|
|
|
return !!(flags & jsdIFilter::FLAG_PASS);
|
|
|
|
}
|
2001-10-30 13:41:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-08-14 14:09:00 +00:00
|
|
|
NS_ERROR("Invalid pattern type");
|
2001-10-30 13:41:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-08 07:08:04 +00:00
|
|
|
currentFilter = reinterpret_cast<FilterRecord *>
|
|
|
|
(PR_NEXT_LINK(¤tFilter->links));
|
2001-10-30 13:41:32 +00:00
|
|
|
} while (currentFilter != gFilters);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* c callbacks
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2008-09-06 22:21:43 +00:00
|
|
|
static void
|
2012-02-17 22:35:20 +00:00
|
|
|
jsds_NotifyPendingDeadScripts (JSRuntime *rt)
|
2001-06-28 07:46:36 +00:00
|
|
|
{
|
Bug 421303 Crash [@ jsds_ScriptHookProc] r=caillon a=dsicore If we reach ~jsdService, that means our client doesn't care about us, so we can (and should) drop all references to any callbacks (if they cared, they'd have kept us alive!*). I think jsdService::Off should clear all the hooks, the strange magic of not clearing it isn't really a great idea. So for Off, we'll now clear the ScriptHook too (consumers who use off should really drop any references they have to our objects...). I'm still on the fence on this point, I suspect we can actually move it from ::Off to ~jsdService (it must be cleared at some point, otherwise if jsd_xpc's library manages to get unloaded, the function pointer would be invalid, which would be *BAD*). jsds_NotifyPendingDeadScripts needs to clear gDeadScripts whether or not there's a service or hooks, so it does. Because it's a static callback and because of the scary way GC works, I'd rather ensure (deathgrip) that jsds is available (and consistent!) for the duration of the function call. The code already handles the lack of a hook, so there's no reason to do magical returns.... The real problem which mayhemer found was that jsdService::Off was returning early (failure) because gGCStatus wasn't JSGC_END when called from ~jsdService from JS_GC from the cyclecollector, so we make sure that ~jsdService forces ::Off to act as if it is JSGC_END (after ensuring that there are no callbacks available). * a pure javascript (xpcom component, not DOM hosted!) version of a jsdService consumer means that jsdService will need to talk to the CycleCollector eventually (this is another bug for the future).
2008-03-11 00:13:48 +00:00
|
|
|
jsdService *jsds = gJsds;
|
|
|
|
|
|
|
|
nsCOMPtr<jsdIScriptHook> hook;
|
|
|
|
if (jsds) {
|
|
|
|
NS_ADDREF(jsds);
|
|
|
|
jsds->GetScriptHook (getter_AddRefs(hook));
|
2012-07-30 14:20:58 +00:00
|
|
|
jsds->DoPause(nullptr, true);
|
Bug 421303 Crash [@ jsds_ScriptHookProc] r=caillon a=dsicore If we reach ~jsdService, that means our client doesn't care about us, so we can (and should) drop all references to any callbacks (if they cared, they'd have kept us alive!*). I think jsdService::Off should clear all the hooks, the strange magic of not clearing it isn't really a great idea. So for Off, we'll now clear the ScriptHook too (consumers who use off should really drop any references they have to our objects...). I'm still on the fence on this point, I suspect we can actually move it from ::Off to ~jsdService (it must be cleared at some point, otherwise if jsd_xpc's library manages to get unloaded, the function pointer would be invalid, which would be *BAD*). jsds_NotifyPendingDeadScripts needs to clear gDeadScripts whether or not there's a service or hooks, so it does. Because it's a static callback and because of the scary way GC works, I'd rather ensure (deathgrip) that jsds is available (and consistent!) for the duration of the function call. The code already handles the lack of a hook, so there's no reason to do magical returns.... The real problem which mayhemer found was that jsdService::Off was returning early (failure) because gGCStatus wasn't JSGC_END when called from ~jsdService from JS_GC from the cyclecollector, so we make sure that ~jsdService forces ::Off to act as if it is JSGC_END (after ensuring that there are no callbacks available). * a pure javascript (xpcom component, not DOM hosted!) version of a jsdService consumer means that jsdService will need to talk to the CycleCollector eventually (this is another bug for the future).
2008-03-11 00:13:48 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 21:10:01 +00:00
|
|
|
DeadScript *deadScripts = gDeadScripts;
|
2012-07-30 14:20:58 +00:00
|
|
|
gDeadScripts = nullptr;
|
2008-03-05 21:10:01 +00:00
|
|
|
while (deadScripts) {
|
|
|
|
DeadScript *ds = deadScripts;
|
|
|
|
/* get next deleted script */
|
|
|
|
deadScripts = reinterpret_cast<DeadScript *>
|
|
|
|
(PR_NEXT_LINK(&ds->links));
|
|
|
|
if (deadScripts == ds)
|
2012-07-30 14:20:58 +00:00
|
|
|
deadScripts = nullptr;
|
2008-03-05 21:10:01 +00:00
|
|
|
|
2002-01-12 00:56:35 +00:00
|
|
|
if (hook)
|
|
|
|
{
|
2001-06-28 07:46:36 +00:00
|
|
|
/* tell the user this script has been destroyed */
|
2001-08-28 22:02:07 +00:00
|
|
|
#ifdef CAUTIOUS_SCRIPTHOOK
|
2004-05-13 06:04:09 +00:00
|
|
|
JS_UNKEEP_ATOMS(rt);
|
2001-08-28 22:02:07 +00:00
|
|
|
#endif
|
2001-06-28 07:46:36 +00:00
|
|
|
hook->OnScriptDestroyed (ds->script);
|
2001-08-28 22:02:07 +00:00
|
|
|
#ifdef CAUTIOUS_SCRIPTHOOK
|
2004-05-13 06:04:09 +00:00
|
|
|
JS_KEEP_ATOMS(rt);
|
2001-08-28 22:02:07 +00:00
|
|
|
#endif
|
2002-01-12 00:56:35 +00:00
|
|
|
}
|
2008-03-05 21:10:01 +00:00
|
|
|
|
|
|
|
/* take it out of the circular list */
|
2002-01-12 00:56:35 +00:00
|
|
|
PR_REMOVE_LINK(&ds->links);
|
2008-03-05 21:10:01 +00:00
|
|
|
|
2002-01-12 00:56:35 +00:00
|
|
|
/* addref came from the FromPtr call in jsds_ScriptHookProc */
|
|
|
|
NS_RELEASE(ds->script);
|
|
|
|
/* free the struct! */
|
|
|
|
PR_Free(ds);
|
2002-07-12 21:28:29 +00:00
|
|
|
}
|
|
|
|
|
Bug 421303 Crash [@ jsds_ScriptHookProc] r=caillon a=dsicore If we reach ~jsdService, that means our client doesn't care about us, so we can (and should) drop all references to any callbacks (if they cared, they'd have kept us alive!*). I think jsdService::Off should clear all the hooks, the strange magic of not clearing it isn't really a great idea. So for Off, we'll now clear the ScriptHook too (consumers who use off should really drop any references they have to our objects...). I'm still on the fence on this point, I suspect we can actually move it from ::Off to ~jsdService (it must be cleared at some point, otherwise if jsd_xpc's library manages to get unloaded, the function pointer would be invalid, which would be *BAD*). jsds_NotifyPendingDeadScripts needs to clear gDeadScripts whether or not there's a service or hooks, so it does. Because it's a static callback and because of the scary way GC works, I'd rather ensure (deathgrip) that jsds is available (and consistent!) for the duration of the function call. The code already handles the lack of a hook, so there's no reason to do magical returns.... The real problem which mayhemer found was that jsdService::Off was returning early (failure) because gGCStatus wasn't JSGC_END when called from ~jsdService from JS_GC from the cyclecollector, so we make sure that ~jsdService forces ::Off to act as if it is JSGC_END (after ensuring that there are no callbacks available). * a pure javascript (xpcom component, not DOM hosted!) version of a jsdService consumer means that jsdService will need to talk to the CycleCollector eventually (this is another bug for the future).
2008-03-11 00:13:48 +00:00
|
|
|
if (jsds) {
|
2012-07-30 14:20:58 +00:00
|
|
|
jsds->DoUnPause(nullptr, true);
|
Bug 421303 Crash [@ jsds_ScriptHookProc] r=caillon a=dsicore If we reach ~jsdService, that means our client doesn't care about us, so we can (and should) drop all references to any callbacks (if they cared, they'd have kept us alive!*). I think jsdService::Off should clear all the hooks, the strange magic of not clearing it isn't really a great idea. So for Off, we'll now clear the ScriptHook too (consumers who use off should really drop any references they have to our objects...). I'm still on the fence on this point, I suspect we can actually move it from ::Off to ~jsdService (it must be cleared at some point, otherwise if jsd_xpc's library manages to get unloaded, the function pointer would be invalid, which would be *BAD*). jsds_NotifyPendingDeadScripts needs to clear gDeadScripts whether or not there's a service or hooks, so it does. Because it's a static callback and because of the scary way GC works, I'd rather ensure (deathgrip) that jsds is available (and consistent!) for the duration of the function call. The code already handles the lack of a hook, so there's no reason to do magical returns.... The real problem which mayhemer found was that jsdService::Off was returning early (failure) because gGCStatus wasn't JSGC_END when called from ~jsdService from JS_GC from the cyclecollector, so we make sure that ~jsdService forces ::Off to act as if it is JSGC_END (after ensuring that there are no callbacks available). * a pure javascript (xpcom component, not DOM hosted!) version of a jsdService consumer means that jsdService will need to talk to the CycleCollector eventually (this is another bug for the future).
2008-03-11 00:13:48 +00:00
|
|
|
NS_RELEASE(jsds);
|
|
|
|
}
|
2001-06-28 07:46:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-17 22:35:20 +00:00
|
|
|
static void
|
2013-01-27 20:35:12 +00:00
|
|
|
jsds_GCSliceCallbackProc (JSRuntime *rt, JS::GCProgress progress, const JS::GCDescription &desc)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
2013-01-27 20:35:12 +00:00
|
|
|
if (progress == JS::GC_CYCLE_END || progress == JS::GC_SLICE_END) {
|
2012-02-17 22:35:20 +00:00
|
|
|
NS_ASSERTION(gGCRunning, "GC slice callback was missed");
|
|
|
|
|
2008-03-05 21:10:01 +00:00
|
|
|
while (gDeadScripts)
|
2012-02-17 22:35:20 +00:00
|
|
|
jsds_NotifyPendingDeadScripts (rt);
|
2008-03-05 21:10:01 +00:00
|
|
|
|
2012-02-17 22:35:20 +00:00
|
|
|
gGCRunning = false;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(!gGCRunning, "should not re-enter GC");
|
|
|
|
gGCRunning = true;
|
2011-01-31 23:00:52 +00:00
|
|
|
}
|
2012-02-17 22:35:20 +00:00
|
|
|
|
|
|
|
if (gPrevGCSliceCallback)
|
|
|
|
(*gPrevGCSliceCallback)(rt, progress, desc);
|
2001-04-25 18:20:47 +00:00
|
|
|
}
|
|
|
|
|
2012-02-28 23:11:11 +00:00
|
|
|
static unsigned
|
2002-01-29 05:56:02 +00:00
|
|
|
jsds_ErrorHookProc (JSDContext *jsdc, JSContext *cx, const char *message,
|
|
|
|
JSErrorReport *report, void *callerdata)
|
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool running = false;
|
2002-01-29 05:56:02 +00:00
|
|
|
|
|
|
|
nsCOMPtr<jsdIErrorHook> hook;
|
|
|
|
gJsds->GetErrorHook(getter_AddRefs(hook));
|
|
|
|
if (!hook)
|
|
|
|
return JSD_ERROR_REPORTER_PASS_ALONG;
|
2002-04-26 20:57:35 +00:00
|
|
|
|
|
|
|
if (running)
|
|
|
|
return JSD_ERROR_REPORTER_PASS_ALONG;
|
2013-09-19 07:54:01 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
running = true;
|
2013-09-19 07:54:01 +00:00
|
|
|
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
nsCOMPtr<jsdIValue> val;
|
2002-01-29 05:56:02 +00:00
|
|
|
if (JS_IsExceptionPending(cx)) {
|
2013-09-19 07:54:01 +00:00
|
|
|
JS::RootedValue jv(cx);
|
2002-01-29 05:56:02 +00:00
|
|
|
JS_GetPendingException(cx, &jv);
|
|
|
|
JSDValue *jsdv = JSD_NewValue (jsdc, jv);
|
2013-07-10 09:56:21 +00:00
|
|
|
val = dont_AddRef(jsdValue::FromPtr(jsdc, jsdv));
|
2002-01-29 05:56:02 +00:00
|
|
|
}
|
2013-09-19 07:54:01 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString fileName;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t line;
|
|
|
|
uint32_t pos;
|
|
|
|
uint32_t flags;
|
|
|
|
uint32_t errnum;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool rval;
|
2002-01-29 05:56:02 +00:00
|
|
|
if (report) {
|
2009-01-08 04:42:15 +00:00
|
|
|
fileName.Assign(report->filename);
|
2002-01-29 05:56:02 +00:00
|
|
|
line = report->lineno;
|
|
|
|
pos = report->tokenptr - report->linebuf;
|
|
|
|
flags = report->flags;
|
|
|
|
errnum = report->errorNumber;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line = 0;
|
|
|
|
pos = 0;
|
|
|
|
flags = 0;
|
|
|
|
errnum = 0;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds->DoPause(nullptr, true);
|
2009-01-08 04:42:15 +00:00
|
|
|
hook->OnError (nsDependentCString(message), fileName, line, pos, flags, errnum, val, &rval);
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds->DoUnPause(nullptr, true);
|
2002-01-29 05:56:02 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
running = false;
|
2002-01-29 05:56:02 +00:00
|
|
|
if (!rval)
|
|
|
|
return JSD_ERROR_REPORTER_DEBUG;
|
|
|
|
|
|
|
|
return JSD_ERROR_REPORTER_PASS_ALONG;
|
|
|
|
}
|
|
|
|
|
2013-08-08 22:53:04 +00:00
|
|
|
static bool
|
2001-09-01 18:03:53 +00:00
|
|
|
jsds_CallHookProc (JSDContext* jsdc, JSDThreadState* jsdthreadstate,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned type, void* callerdata)
|
2001-09-01 18:03:53 +00:00
|
|
|
{
|
2002-01-29 05:56:02 +00:00
|
|
|
nsCOMPtr<jsdICallHook> hook;
|
2001-09-01 18:03:53 +00:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case JSD_HOOK_TOPLEVEL_START:
|
|
|
|
case JSD_HOOK_TOPLEVEL_END:
|
|
|
|
gJsds->GetTopLevelHook(getter_AddRefs(hook));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JSD_HOOK_FUNCTION_CALL:
|
|
|
|
case JSD_HOOK_FUNCTION_RETURN:
|
|
|
|
gJsds->GetFunctionHook(getter_AddRefs(hook));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ASSERTION (0, "Unknown hook type.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hook)
|
2013-08-07 06:59:54 +00:00
|
|
|
return true;
|
2001-09-01 18:03:53 +00:00
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
if (!jsds_FilterHook (jsdc, jsdthreadstate))
|
2013-08-07 06:59:54 +00:00
|
|
|
return false;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2001-09-01 18:03:53 +00:00
|
|
|
JSDStackFrameInfo *native_frame = JSD_GetStackFrame (jsdc, jsdthreadstate);
|
|
|
|
nsCOMPtr<jsdIStackFrame> frame =
|
2013-07-10 09:56:21 +00:00
|
|
|
dont_AddRef(jsdStackFrame::FromPtr(jsdc, jsdthreadstate, native_frame));
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds->DoPause(nullptr, true);
|
2001-09-01 18:03:53 +00:00
|
|
|
hook->OnCall(frame, type);
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds->DoUnPause(nullptr, true);
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
jsdStackFrame::InvalidateAll();
|
2001-09-01 18:03:53 +00:00
|
|
|
|
2013-08-07 06:59:54 +00:00
|
|
|
return true;
|
2001-09-01 18:03:53 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t
|
2001-05-04 22:14:04 +00:00
|
|
|
jsds_ExecutionHookProc (JSDContext* jsdc, JSDThreadState* jsdthreadstate,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned type, void* callerdata, jsval* rval)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
2001-05-04 22:14:04 +00:00
|
|
|
nsCOMPtr<jsdIExecutionHook> hook(0);
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t hook_rv = JSD_HOOK_RETURN_CONTINUE;
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
nsCOMPtr<jsdIValue> js_rv;
|
2001-04-25 18:20:47 +00:00
|
|
|
|
2001-05-04 22:14:04 +00:00
|
|
|
switch (type)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
2001-05-04 22:14:04 +00:00
|
|
|
case JSD_HOOK_INTERRUPTED:
|
|
|
|
gJsds->GetInterruptHook(getter_AddRefs(hook));
|
|
|
|
break;
|
|
|
|
case JSD_HOOK_DEBUG_REQUESTED:
|
2002-01-29 05:56:02 +00:00
|
|
|
gJsds->GetDebugHook(getter_AddRefs(hook));
|
2001-05-04 22:14:04 +00:00
|
|
|
break;
|
|
|
|
case JSD_HOOK_DEBUGGER_KEYWORD:
|
|
|
|
gJsds->GetDebuggerHook(getter_AddRefs(hook));
|
|
|
|
break;
|
|
|
|
case JSD_HOOK_BREAKPOINT:
|
2002-02-07 00:59:55 +00:00
|
|
|
{
|
|
|
|
/* we can't pause breakpoints the way we pause the other
|
|
|
|
* execution hooks (at least, not easily.) Instead we bail
|
|
|
|
* here if the service is paused. */
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t level;
|
2002-02-07 00:59:55 +00:00
|
|
|
gJsds->GetPauseDepth(&level);
|
|
|
|
if (!level)
|
|
|
|
gJsds->GetBreakpointHook(getter_AddRefs(hook));
|
|
|
|
}
|
2001-05-04 22:14:04 +00:00
|
|
|
break;
|
|
|
|
case JSD_HOOK_THROW:
|
|
|
|
{
|
2001-09-01 18:03:53 +00:00
|
|
|
hook_rv = JSD_HOOK_RETURN_CONTINUE_THROW;
|
2001-05-04 22:14:04 +00:00
|
|
|
gJsds->GetThrowHook(getter_AddRefs(hook));
|
|
|
|
if (hook) {
|
|
|
|
JSDValue *jsdv = JSD_GetException (jsdc, jsdthreadstate);
|
2013-07-10 09:56:21 +00:00
|
|
|
js_rv = dont_AddRef(jsdValue::FromPtr (jsdc, jsdv));
|
2001-05-04 22:14:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_ASSERTION (0, "Unknown hook type.");
|
2001-04-25 18:20:47 +00:00
|
|
|
}
|
|
|
|
|
2001-05-04 22:14:04 +00:00
|
|
|
if (!hook)
|
2001-09-01 18:03:53 +00:00
|
|
|
return hook_rv;
|
2001-04-25 18:20:47 +00:00
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
if (!jsds_FilterHook (jsdc, jsdthreadstate))
|
|
|
|
return JSD_HOOK_RETURN_CONTINUE;
|
|
|
|
|
2001-07-03 22:19:04 +00:00
|
|
|
JSDStackFrameInfo *native_frame = JSD_GetStackFrame (jsdc, jsdthreadstate);
|
|
|
|
nsCOMPtr<jsdIStackFrame> frame =
|
2013-07-10 09:56:21 +00:00
|
|
|
dont_AddRef(jsdStackFrame::FromPtr(jsdc, jsdthreadstate, native_frame));
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds->DoPause(nullptr, true);
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
jsdIValue *inout_rv = js_rv;
|
|
|
|
NS_IF_ADDREF(inout_rv);
|
|
|
|
hook->OnExecute (frame, type, &inout_rv, &hook_rv);
|
|
|
|
js_rv = inout_rv;
|
2002-06-19 22:40:19 +00:00
|
|
|
NS_IF_RELEASE(inout_rv);
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds->DoUnPause(nullptr, true);
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
jsdStackFrame::InvalidateAll();
|
2001-07-03 22:19:04 +00:00
|
|
|
|
2001-05-04 22:14:04 +00:00
|
|
|
if (hook_rv == JSD_HOOK_RETURN_RET_WITH_VAL ||
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
hook_rv == JSD_HOOK_RETURN_THROW_WITH_VAL) {
|
2007-06-20 05:56:13 +00:00
|
|
|
*rval = JSVAL_VOID;
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
if (js_rv) {
|
|
|
|
JSDValue *jsdv;
|
2007-06-20 05:56:13 +00:00
|
|
|
if (NS_SUCCEEDED(js_rv->GetJSDValue (&jsdv)))
|
|
|
|
*rval = JSD_GetValueWrappedJSVal(jsdc, jsdv);
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
}
|
2001-04-25 18:20:47 +00:00
|
|
|
}
|
2001-05-04 22:14:04 +00:00
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
return hook_rv;
|
|
|
|
}
|
|
|
|
|
2008-09-06 22:21:43 +00:00
|
|
|
static void
|
2013-08-08 22:53:04 +00:00
|
|
|
jsds_ScriptHookProc (JSDContext* jsdc, JSDScript* jsdscript, bool creating,
|
2001-04-25 18:20:47 +00:00
|
|
|
void* callerdata)
|
|
|
|
{
|
2001-08-28 22:02:07 +00:00
|
|
|
#ifdef CAUTIOUS_SCRIPTHOOK
|
2013-06-12 21:17:55 +00:00
|
|
|
JSRuntime *rt = JS_GetRuntime(nsContentUtils::GetSafeJSContext());
|
2001-08-28 22:02:07 +00:00
|
|
|
#endif
|
|
|
|
|
2001-05-01 21:33:43 +00:00
|
|
|
if (creating) {
|
2009-06-05 01:00:56 +00:00
|
|
|
nsCOMPtr<jsdIScriptHook> hook;
|
|
|
|
gJsds->GetScriptHook(getter_AddRefs(hook));
|
|
|
|
|
2002-01-12 00:56:35 +00:00
|
|
|
/* a script is being created */
|
|
|
|
if (!hook) {
|
|
|
|
/* nobody cares, just exit */
|
2001-05-01 21:33:43 +00:00
|
|
|
return;
|
2002-01-12 00:56:35 +00:00
|
|
|
}
|
2001-05-01 21:33:43 +00:00
|
|
|
|
|
|
|
nsCOMPtr<jsdIScript> script =
|
2013-07-10 09:56:21 +00:00
|
|
|
dont_AddRef(jsdScript::FromPtr(jsdc, jsdscript));
|
2001-08-28 22:02:07 +00:00
|
|
|
#ifdef CAUTIOUS_SCRIPTHOOK
|
2004-05-13 06:04:09 +00:00
|
|
|
JS_UNKEEP_ATOMS(rt);
|
2001-08-28 22:02:07 +00:00
|
|
|
#endif
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds->DoPause(nullptr, true);
|
2001-05-04 22:14:04 +00:00
|
|
|
hook->OnScriptCreated (script);
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds->DoUnPause(nullptr, true);
|
2001-08-28 22:02:07 +00:00
|
|
|
#ifdef CAUTIOUS_SCRIPTHOOK
|
2004-05-13 06:04:09 +00:00
|
|
|
JS_KEEP_ATOMS(rt);
|
2001-08-28 22:02:07 +00:00
|
|
|
#endif
|
2001-05-01 21:33:43 +00:00
|
|
|
} else {
|
2002-01-12 00:56:35 +00:00
|
|
|
/* a script is being destroyed. even if there is no registered hook
|
|
|
|
* we'll still need to invalidate the jsdIScript record, in order
|
|
|
|
* to remove the reference held in the JSDScript private data. */
|
|
|
|
nsCOMPtr<jsdIScript> jsdis =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<jsdIScript *>(JSD_GetScriptPrivate(jsdscript));
|
2002-01-12 00:56:35 +00:00
|
|
|
if (!jsdis)
|
|
|
|
return;
|
2009-06-05 01:00:56 +00:00
|
|
|
|
2001-05-01 21:33:43 +00:00
|
|
|
jsdis->Invalidate();
|
2009-06-05 01:00:56 +00:00
|
|
|
|
2012-02-17 22:35:20 +00:00
|
|
|
if (!gGCRunning) {
|
2009-06-05 01:00:56 +00:00
|
|
|
nsCOMPtr<jsdIScriptHook> hook;
|
|
|
|
gJsds->GetScriptHook(getter_AddRefs(hook));
|
|
|
|
if (!hook)
|
|
|
|
return;
|
|
|
|
|
2001-05-01 21:33:43 +00:00
|
|
|
/* if GC *isn't* running, we can tell the user about the script
|
|
|
|
* delete now. */
|
2001-08-28 22:02:07 +00:00
|
|
|
#ifdef CAUTIOUS_SCRIPTHOOK
|
2004-05-13 06:04:09 +00:00
|
|
|
JS_UNKEEP_ATOMS(rt);
|
2001-08-28 22:02:07 +00:00
|
|
|
#endif
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds->DoPause(nullptr, true);
|
2002-01-12 00:56:35 +00:00
|
|
|
hook->OnScriptDestroyed (jsdis);
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds->DoUnPause(nullptr, true);
|
2001-08-28 22:02:07 +00:00
|
|
|
#ifdef CAUTIOUS_SCRIPTHOOK
|
2004-05-13 06:04:09 +00:00
|
|
|
JS_KEEP_ATOMS(rt);
|
2001-08-28 22:02:07 +00:00
|
|
|
#endif
|
2001-05-01 21:33:43 +00:00
|
|
|
} else {
|
|
|
|
/* if a GC *is* running, we've got to wait until it's done before
|
|
|
|
* we can execute any JS, so we queue the notification in a PRCList
|
|
|
|
* until GC tells us it's done. See jsds_GCCallbackProc(). */
|
|
|
|
DeadScript *ds = PR_NEW(DeadScript);
|
2002-01-12 00:56:35 +00:00
|
|
|
if (!ds)
|
2001-05-01 21:33:43 +00:00
|
|
|
return; /* NS_ERROR_OUT_OF_MEMORY */
|
|
|
|
|
|
|
|
ds->jsdc = jsdc;
|
|
|
|
ds->script = jsdis;
|
2002-01-12 00:56:35 +00:00
|
|
|
NS_ADDREF(ds->script);
|
2001-05-01 21:33:43 +00:00
|
|
|
if (gDeadScripts)
|
|
|
|
/* if the queue exists, add to it */
|
|
|
|
PR_APPEND_LINK(&ds->links, &gDeadScripts->links);
|
|
|
|
else {
|
|
|
|
/* otherwise create the queue */
|
|
|
|
PR_INIT_CLIST(&ds->links);
|
|
|
|
gDeadScripts = ds;
|
|
|
|
}
|
|
|
|
}
|
2002-01-12 00:56:35 +00:00
|
|
|
}
|
2001-04-25 18:20:47 +00:00
|
|
|
}
|
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* reflected jsd data structures
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
/* Contexts */
|
2001-05-04 22:14:04 +00:00
|
|
|
/*
|
2013-07-19 02:23:32 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(jsdContext, jsdIContext, jsdIEphemeral);
|
2001-04-17 08:50:41 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdContext::GetJSDContext(JSDContext **_rval)
|
|
|
|
{
|
|
|
|
*_rval = mCx;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-05-04 22:14:04 +00:00
|
|
|
*/
|
2001-04-17 08:50:41 +00:00
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
/* Objects */
|
2013-07-19 02:23:32 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(jsdObject, jsdIObject)
|
2001-04-20 03:54:05 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdObject::GetJSDContext(JSDContext **_rval)
|
|
|
|
{
|
|
|
|
*_rval = mCx;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdObject::GetJSDObject(JSDObject **_rval)
|
|
|
|
{
|
|
|
|
*_rval = mObject;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdObject::GetCreatorURL(nsACString &_rval)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
2009-01-08 04:42:15 +00:00
|
|
|
_rval.Assign(JSD_GetObjectNewURL(mCx, mObject));
|
2001-04-25 18:20:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdObject::GetCreatorLine(uint32_t *_rval)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
|
|
|
*_rval = JSD_GetObjectNewLineNumber(mCx, mObject);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdObject::GetConstructorURL(nsACString &_rval)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
2009-01-08 04:42:15 +00:00
|
|
|
_rval.Assign(JSD_GetObjectConstructorURL(mCx, mObject));
|
2001-04-25 18:20:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdObject::GetConstructorLine(uint32_t *_rval)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
|
|
|
*_rval = JSD_GetObjectConstructorLineNumber(mCx, mObject);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdObject::GetValue(jsdIValue **_rval)
|
|
|
|
{
|
|
|
|
JSDValue *jsdv = JSD_GetValueForObject (mCx, mObject);
|
|
|
|
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
/* Properties */
|
2013-07-19 02:23:32 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(jsdProperty, jsdIProperty, jsdIEphemeral)
|
2001-07-03 22:19:04 +00:00
|
|
|
|
|
|
|
jsdProperty::jsdProperty (JSDContext *aCx, JSDProperty *aProperty) :
|
|
|
|
mCx(aCx), mProperty(aProperty)
|
|
|
|
{
|
|
|
|
DEBUG_CREATE ("jsdProperty", gPropertyCount);
|
|
|
|
mValid = (aCx && aProperty);
|
|
|
|
mLiveListEntry.value = this;
|
|
|
|
jsds_InsertEphemeral (&gLiveProperties, &mLiveListEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdProperty::~jsdProperty ()
|
|
|
|
{
|
|
|
|
DEBUG_DESTROY ("jsdProperty", gPropertyCount);
|
|
|
|
if (mValid)
|
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdProperty::Invalidate()
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2011-10-17 14:59:28 +00:00
|
|
|
mValid = false;
|
2001-07-03 22:19:04 +00:00
|
|
|
jsds_RemoveEphemeral (&gLiveProperties, &mLiveListEntry);
|
|
|
|
JSD_DropProperty (mCx, mProperty);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsdProperty::InvalidateAll()
|
|
|
|
{
|
|
|
|
if (gLiveProperties)
|
|
|
|
jsds_InvalidateAllEphemerals (&gLiveProperties);
|
|
|
|
}
|
2001-04-20 03:54:05 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdProperty::GetJSDContext(JSDContext **_rval)
|
|
|
|
{
|
|
|
|
*_rval = mCx;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdProperty::GetJSDProperty(JSDProperty **_rval)
|
|
|
|
{
|
|
|
|
*_rval = mProperty;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-03 22:19:04 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdProperty::GetIsValid(bool *_rval)
|
2001-07-03 22:19:04 +00:00
|
|
|
{
|
|
|
|
*_rval = mValid;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-21 07:21:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdProperty::GetAlias(jsdIValue **_rval)
|
|
|
|
{
|
|
|
|
JSDValue *jsdv = JSD_GetPropertyValue (mCx, mProperty);
|
|
|
|
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdProperty::GetFlags(uint32_t *_rval)
|
2001-04-21 07:21:27 +00:00
|
|
|
{
|
|
|
|
*_rval = JSD_GetPropertyFlags (mCx, mProperty);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdProperty::GetName(jsdIValue **_rval)
|
|
|
|
{
|
|
|
|
JSDValue *jsdv = JSD_GetPropertyName (mCx, mProperty);
|
|
|
|
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdProperty::GetValue(jsdIValue **_rval)
|
|
|
|
{
|
|
|
|
JSDValue *jsdv = JSD_GetPropertyValue (mCx, mProperty);
|
|
|
|
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
/* Scripts */
|
2013-07-19 02:23:32 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(jsdScript, jsdIScript, jsdIEphemeral)
|
2001-07-03 22:19:04 +00:00
|
|
|
|
2010-11-24 16:56:43 +00:00
|
|
|
static NS_IMETHODIMP
|
2013-08-22 22:43:47 +00:00
|
|
|
AssignToJSString(JSDContext *aCx, nsACString *x, JSString *str_)
|
2010-11-24 16:56:43 +00:00
|
|
|
{
|
2013-08-22 22:43:47 +00:00
|
|
|
if (!str_) {
|
2010-11-24 16:56:43 +00:00
|
|
|
x->SetLength(0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-08-22 22:43:47 +00:00
|
|
|
JS::RootedString str(JSD_GetJSRuntime(aCx), str_);
|
2013-06-12 21:17:55 +00:00
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoCompartment ac(cx, JSD_GetDefaultGlobal(aCx)); // Just in case.
|
2012-11-09 17:45:25 +00:00
|
|
|
size_t length = JS_GetStringEncodingLength(cx, str);
|
2010-11-24 16:56:43 +00:00
|
|
|
if (length == size_t(-1))
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-08-22 15:56:38 +00:00
|
|
|
x->SetLength(uint32_t(length));
|
|
|
|
if (x->Length() != uint32_t(length))
|
2010-11-24 16:56:43 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2012-11-09 17:45:25 +00:00
|
|
|
JS_EncodeStringToBuffer(cx, str, x->BeginWriting(), length);
|
2010-11-24 16:56:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
jsdScript::jsdScript (JSDContext *aCx, JSDScript *aScript) : mValid(false),
|
2002-01-12 00:56:35 +00:00
|
|
|
mTag(0),
|
2001-07-03 22:19:04 +00:00
|
|
|
mCx(aCx),
|
|
|
|
mScript(aScript),
|
|
|
|
mFileName(0),
|
|
|
|
mFunctionName(0),
|
|
|
|
mBaseLineNumber(0),
|
2002-01-12 00:56:35 +00:00
|
|
|
mLineExtent(0),
|
|
|
|
mPPLineMap(0),
|
2010-10-15 18:36:56 +00:00
|
|
|
mFirstPC(0)
|
2001-07-03 22:19:04 +00:00
|
|
|
{
|
|
|
|
DEBUG_CREATE ("jsdScript", gScriptCount);
|
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
if (mScript) {
|
2001-07-03 22:19:04 +00:00
|
|
|
/* copy the script's information now, so we have it later, when it
|
|
|
|
* gets destroyed. */
|
|
|
|
JSD_LockScriptSubsystem(mCx);
|
|
|
|
mFileName = new nsCString(JSD_GetScriptFilename(mCx, mScript));
|
2010-11-24 16:56:43 +00:00
|
|
|
mFunctionName = new nsCString();
|
|
|
|
if (mFunctionName) {
|
2011-01-29 21:40:29 +00:00
|
|
|
JSString *str = JSD_GetScriptFunctionId(mCx, mScript);
|
2010-11-24 16:56:43 +00:00
|
|
|
if (str)
|
2012-11-09 17:45:25 +00:00
|
|
|
AssignToJSString(mCx, mFunctionName, str);
|
2010-11-24 16:56:43 +00:00
|
|
|
}
|
2001-07-03 22:19:04 +00:00
|
|
|
mBaseLineNumber = JSD_GetScriptBaseLineNumber(mCx, mScript);
|
|
|
|
mLineExtent = JSD_GetScriptLineExtent(mCx, mScript);
|
2002-01-12 00:56:35 +00:00
|
|
|
mFirstPC = JSD_GetClosestPC(mCx, mScript, 0);
|
2001-07-03 22:19:04 +00:00
|
|
|
JSD_UnlockScriptSubsystem(mCx);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mValid = true;
|
2001-07-03 22:19:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdScript::~jsdScript ()
|
|
|
|
{
|
|
|
|
DEBUG_DESTROY ("jsdScript", gScriptCount);
|
2011-06-01 10:07:00 +00:00
|
|
|
delete mFileName;
|
|
|
|
delete mFunctionName;
|
2002-01-12 00:56:35 +00:00
|
|
|
|
|
|
|
if (mPPLineMap)
|
|
|
|
PR_Free(mPPLineMap);
|
|
|
|
|
2001-07-03 22:19:04 +00:00
|
|
|
/* Invalidate() needs to be called to release an owning reference to
|
|
|
|
* ourselves, so if we got here without being invalidated, something
|
|
|
|
* has gone wrong with our ref count. */
|
|
|
|
NS_ASSERTION (!mValid, "Script destroyed without being invalidated.");
|
2002-01-12 00:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This method populates a line <-> pc map for a pretty printed version of this
|
|
|
|
* script. It does this by decompiling, and then recompiling the script. The
|
|
|
|
* resulting script is scanned for the line map, and then left as GC fodder.
|
|
|
|
*/
|
|
|
|
PCMapEntry *
|
|
|
|
jsdScript::CreatePPLineMap()
|
2013-05-12 13:13:22 +00:00
|
|
|
{
|
2013-06-12 21:17:55 +00:00
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoCompartment ac(cx, JSD_GetDefaultGlobal (mCx)); // Just in case.
|
2014-01-16 17:48:58 +00:00
|
|
|
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
2013-05-12 13:13:22 +00:00
|
|
|
if (!obj)
|
|
|
|
return nullptr;
|
|
|
|
JS::RootedFunction fun(cx, JSD_GetJSFunction (mCx, mScript));
|
|
|
|
JS::RootedScript script(cx); /* In JSD compartment */
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t baseLine;
|
2013-05-12 13:13:22 +00:00
|
|
|
JS::RootedString jsstr(cx);
|
2011-01-28 02:31:48 +00:00
|
|
|
size_t length;
|
|
|
|
const jschar *chars;
|
2013-05-12 13:13:22 +00:00
|
|
|
|
2002-01-12 00:56:35 +00:00
|
|
|
if (fun) {
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs;
|
2010-12-14 21:24:00 +00:00
|
|
|
|
2011-01-28 02:31:48 +00:00
|
|
|
{
|
2012-08-22 01:42:53 +00:00
|
|
|
JSAutoCompartment ac(cx, JS_GetFunctionObject(fun));
|
2010-12-14 21:24:00 +00:00
|
|
|
nargs = JS_GetFunctionArgumentCount(cx, fun);
|
|
|
|
if (nargs > 12)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-12-14 21:24:00 +00:00
|
|
|
jsstr = JS_DecompileFunctionBody (cx, fun, 4);
|
|
|
|
if (!jsstr)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-12-14 21:24:00 +00:00
|
|
|
|
2011-01-28 02:31:48 +00:00
|
|
|
if (!(chars = JS_GetStringCharsAndLength(cx, jsstr, &length)))
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-01-28 02:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Anchor<JSString *> kungFuDeathGrip(jsstr);
|
2013-09-24 15:21:22 +00:00
|
|
|
static const char *const argnames[] = {
|
|
|
|
"arg1", "arg2", "arg3", "arg4",
|
|
|
|
"arg5", "arg6", "arg7", "arg8",
|
|
|
|
"arg9", "arg10", "arg11", "arg12"
|
|
|
|
};
|
2013-11-19 11:41:42 +00:00
|
|
|
JS::CompileOptions options(cx);
|
|
|
|
options.setFileAndLine("x-jsd:ppbuffer?type=function", 3);
|
2010-12-03 08:24:17 +00:00
|
|
|
fun = JS_CompileUCFunction (cx, obj, "ppfun", nargs, argnames, chars,
|
2013-11-19 11:41:42 +00:00
|
|
|
length, options);
|
2002-01-12 00:56:35 +00:00
|
|
|
if (!fun || !(script = JS_GetFunctionScript(cx, fun)))
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2002-01-12 00:56:35 +00:00
|
|
|
baseLine = 3;
|
|
|
|
} else {
|
2011-01-28 02:31:48 +00:00
|
|
|
script = JSD_GetJSScript(mCx, mScript);
|
|
|
|
JSString *jsstr;
|
2010-12-14 21:24:00 +00:00
|
|
|
|
2011-01-28 02:31:48 +00:00
|
|
|
{
|
2012-08-27 20:32:51 +00:00
|
|
|
JSAutoCompartment ac(cx, script);
|
2010-12-14 21:24:00 +00:00
|
|
|
|
2011-02-03 13:06:21 +00:00
|
|
|
jsstr = JS_DecompileScript (cx, script, "ppscript", 4);
|
2010-12-14 21:24:00 +00:00
|
|
|
if (!jsstr)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2002-01-12 00:56:35 +00:00
|
|
|
|
2011-01-28 02:31:48 +00:00
|
|
|
if (!(chars = JS_GetStringCharsAndLength(cx, jsstr, &length)))
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-01-28 02:31:48 +00:00
|
|
|
}
|
2010-12-03 08:24:17 +00:00
|
|
|
|
2011-01-28 02:31:48 +00:00
|
|
|
JS::Anchor<JSString *> kungFuDeathGrip(jsstr);
|
2013-11-19 11:41:42 +00:00
|
|
|
JS::CompileOptions options(cx);
|
|
|
|
options.setFileAndLine("x-jsd:ppbuffer?type=script", 1);
|
|
|
|
script = JS_CompileUCScript(cx, obj, chars, length, options);
|
2011-09-02 06:46:00 +00:00
|
|
|
if (!script)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2002-01-12 00:56:35 +00:00
|
|
|
baseLine = 1;
|
|
|
|
}
|
2009-01-04 18:59:17 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t scriptExtent = JS_GetScriptLineExtent (cx, script);
|
2002-01-14 21:59:34 +00:00
|
|
|
jsbytecode* firstPC = JS_LineNumberToPC (cx, script, 0);
|
2002-01-12 00:56:35 +00:00
|
|
|
/* allocate worst case size of map (number of lines in script + 1
|
|
|
|
* for our 0 record), we'll shrink it with a realloc later. */
|
2009-01-04 18:59:17 +00:00
|
|
|
PCMapEntry *lineMap =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<PCMapEntry *>
|
|
|
|
(PR_Malloc((scriptExtent + 1) * sizeof (PCMapEntry)));
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t lineMapSize = 0;
|
2009-01-06 20:34:56 +00:00
|
|
|
|
2009-01-04 18:59:17 +00:00
|
|
|
if (lineMap) {
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t line = baseLine; line < scriptExtent + baseLine; ++line) {
|
2002-01-14 21:59:34 +00:00
|
|
|
jsbytecode* pc = JS_LineNumberToPC (cx, script, line);
|
|
|
|
if (line == JS_PCToLineNumber (cx, script, pc)) {
|
2009-01-06 20:34:56 +00:00
|
|
|
lineMap[lineMapSize].line = line;
|
|
|
|
lineMap[lineMapSize].pc = pc - firstPC;
|
|
|
|
++lineMapSize;
|
2002-01-12 00:56:35 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-06 20:34:56 +00:00
|
|
|
if (scriptExtent != lineMapSize) {
|
2009-01-04 18:59:17 +00:00
|
|
|
lineMap =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<PCMapEntry *>
|
2009-01-04 18:59:17 +00:00
|
|
|
(PR_Realloc(mPPLineMap = lineMap,
|
2009-01-06 20:34:56 +00:00
|
|
|
lineMapSize * sizeof(PCMapEntry)));
|
|
|
|
if (!lineMap) {
|
2009-01-04 18:59:17 +00:00
|
|
|
PR_Free(mPPLineMap);
|
2009-01-06 20:34:56 +00:00
|
|
|
lineMapSize = 0;
|
|
|
|
}
|
2002-01-12 00:56:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-06 20:34:56 +00:00
|
|
|
mPCMapSize = lineMapSize;
|
2009-01-04 18:59:17 +00:00
|
|
|
return mPPLineMap = lineMap;
|
2002-01-12 00:56:35 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
|
|
|
jsdScript::PPPcToLine (uint32_t aPC)
|
2002-01-12 00:56:35 +00:00
|
|
|
{
|
|
|
|
if (!mPPLineMap && !CreatePPLineMap())
|
|
|
|
return 0;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2002-01-12 00:56:35 +00:00
|
|
|
for (i = 1; i < mPCMapSize; ++i) {
|
|
|
|
if (mPPLineMap[i].pc > aPC)
|
|
|
|
return mPPLineMap[i - 1].line;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mPPLineMap[mPCMapSize - 1].line;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
|
|
|
jsdScript::PPLineToPc (uint32_t aLine)
|
2002-01-12 00:56:35 +00:00
|
|
|
{
|
|
|
|
if (!mPPLineMap && !CreatePPLineMap())
|
|
|
|
return 0;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2002-01-12 00:56:35 +00:00
|
|
|
for (i = 1; i < mPCMapSize; ++i) {
|
|
|
|
if (mPPLineMap[i].line > aLine)
|
|
|
|
return mPPLineMap[i - 1].pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mPPLineMap[mPCMapSize - 1].pc;
|
2001-07-03 22:19:04 +00:00
|
|
|
}
|
2001-04-17 08:50:41 +00:00
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::GetJSDContext(JSDContext **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = mCx;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::GetJSDScript(JSDScript **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-17 08:50:41 +00:00
|
|
|
*_rval = mScript;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-27 09:24:14 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::GetVersion (int32_t *_rval)
|
2002-02-27 09:24:14 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-06-12 21:17:55 +00:00
|
|
|
AutoSafeJSContext cx;
|
2013-05-12 13:13:22 +00:00
|
|
|
JS::RootedScript script(cx, JSD_GetJSScript(mCx, mScript));
|
2012-08-27 20:32:51 +00:00
|
|
|
JSAutoCompartment ac(cx, script);
|
2012-08-22 15:56:38 +00:00
|
|
|
*_rval = static_cast<int32_t>(JS_GetScriptVersion(cx, script));
|
2002-02-27 09:24:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-12 00:56:35 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::GetTag(uint32_t *_rval)
|
2002-01-12 00:56:35 +00:00
|
|
|
{
|
|
|
|
if (!mTag)
|
|
|
|
mTag = ++jsdScript::LastTag;
|
|
|
|
|
|
|
|
*_rval = mTag;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-01 21:33:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::Invalidate()
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2011-10-17 14:59:28 +00:00
|
|
|
mValid = false;
|
2001-05-01 21:33:43 +00:00
|
|
|
|
|
|
|
/* release the addref we do in FromPtr */
|
2007-07-08 07:08:04 +00:00
|
|
|
jsdIScript *script = static_cast<jsdIScript *>
|
|
|
|
(JSD_GetScriptPrivate(mScript));
|
2001-05-01 21:33:43 +00:00
|
|
|
NS_ASSERTION (script == this, "That's not my script!");
|
|
|
|
NS_RELEASE(script);
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetScriptPrivate(mScript, nullptr);
|
2001-06-28 07:46:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-12 00:56:35 +00:00
|
|
|
void
|
|
|
|
jsdScript::InvalidateAll ()
|
|
|
|
{
|
|
|
|
JSDContext *cx;
|
2007-06-20 05:56:13 +00:00
|
|
|
if (NS_FAILED(gJsds->GetJSDContext (&cx)))
|
|
|
|
return;
|
|
|
|
|
2002-01-12 00:56:35 +00:00
|
|
|
JSDScript *script;
|
2013-09-19 19:26:36 +00:00
|
|
|
JSDScript *iter = nullptr;
|
2002-01-12 00:56:35 +00:00
|
|
|
|
|
|
|
JSD_LockScriptSubsystem(cx);
|
2013-09-19 19:26:36 +00:00
|
|
|
while((script = JSD_IterateScripts(cx, &iter)) != nullptr) {
|
2002-01-24 13:17:04 +00:00
|
|
|
nsCOMPtr<jsdIScript> jsdis =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<jsdIScript *>(JSD_GetScriptPrivate(script));
|
2002-01-12 00:56:35 +00:00
|
|
|
if (jsdis)
|
|
|
|
jsdis->Invalidate();
|
|
|
|
}
|
|
|
|
JSD_UnlockScriptSubsystem(cx);
|
|
|
|
}
|
|
|
|
|
2001-06-28 07:46:36 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdScript::GetIsValid(bool *_rval)
|
2001-06-28 07:46:36 +00:00
|
|
|
{
|
|
|
|
*_rval = mValid;
|
2001-05-01 21:33:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-02-27 09:24:14 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::SetFlags(uint32_t flags)
|
2002-02-27 09:24:14 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
JSD_SetScriptFlags(mCx, mScript, flags);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::GetFlags(uint32_t *_rval)
|
2002-02-27 09:24:14 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_GetScriptFlags(mCx, mScript);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdScript::GetFileName(nsACString &_rval)
|
2001-04-17 08:50:41 +00:00
|
|
|
{
|
2009-01-08 04:42:15 +00:00
|
|
|
_rval.Assign(*mFileName);
|
2001-04-17 08:50:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdScript::GetFunctionName(nsACString &_rval)
|
2001-04-17 08:50:41 +00:00
|
|
|
{
|
2009-01-08 04:42:15 +00:00
|
|
|
_rval.Assign(*mFunctionName);
|
2001-04-17 08:50:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-26 13:30:40 +00:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
jsdScript::GetParameterNames(uint32_t* count, char16_t*** paramNames)
|
2009-10-26 13:30:40 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-06-12 21:17:55 +00:00
|
|
|
AutoSafeJSContext cx;
|
2013-05-12 13:13:22 +00:00
|
|
|
JS::RootedFunction fun(cx, JSD_GetJSFunction (mCx, mScript));
|
2011-01-29 00:54:42 +00:00
|
|
|
if (!fun) {
|
|
|
|
*count = 0;
|
2012-07-30 14:20:58 +00:00
|
|
|
*paramNames = nullptr;
|
2011-01-29 00:54:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-10-26 13:30:40 +00:00
|
|
|
|
2012-08-22 01:42:53 +00:00
|
|
|
JSAutoCompartment ac(cx, JS_GetFunctionObject(fun));
|
2009-10-26 13:30:40 +00:00
|
|
|
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs;
|
2011-01-29 00:54:42 +00:00
|
|
|
if (!JS_FunctionHasLocalNames(cx, fun) ||
|
2010-08-12 00:24:39 +00:00
|
|
|
(nargs = JS_GetFunctionArgumentCount(cx, fun)) == 0) {
|
2009-10-26 13:30:40 +00:00
|
|
|
*count = 0;
|
2012-07-30 14:20:58 +00:00
|
|
|
*paramNames = nullptr;
|
2009-10-26 13:30:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t **ret =
|
|
|
|
static_cast<char16_t**>(NS_Alloc(nargs * sizeof(char16_t*)));
|
2009-10-26 13:30:40 +00:00
|
|
|
if (!ret)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2010-07-15 06:19:36 +00:00
|
|
|
void *mark;
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t *names = JS_GetFunctionLocalNameArray(cx, fun, &mark);
|
2009-10-26 13:30:40 +00:00
|
|
|
if (!names) {
|
|
|
|
NS_Free(ret);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
2012-02-28 23:11:11 +00:00
|
|
|
for (unsigned i = 0; i < nargs; ++i) {
|
2010-07-15 06:19:36 +00:00
|
|
|
JSAtom *atom = JS_LocalNameToAtom(names[i]);
|
2009-10-26 13:30:40 +00:00
|
|
|
if (!atom) {
|
|
|
|
ret[i] = 0;
|
|
|
|
} else {
|
2010-07-15 06:19:36 +00:00
|
|
|
JSString *str = JS_AtomKey(atom);
|
2010-12-03 08:24:17 +00:00
|
|
|
ret[i] = NS_strndup(JS_GetInternedStringChars(str), JS_GetStringLength(str));
|
2009-10-26 13:30:40 +00:00
|
|
|
if (!ret[i]) {
|
|
|
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, ret);
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-15 06:19:36 +00:00
|
|
|
JS_ReleaseFunctionLocalNameArray(cx, mark);
|
2009-10-26 13:30:40 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2010-07-15 06:19:36 +00:00
|
|
|
*count = nargs;
|
2009-10-26 13:30:40 +00:00
|
|
|
*paramNames = ret;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-17 22:22:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::GetFunctionObject(jsdIValue **_rval)
|
|
|
|
{
|
2013-08-22 22:43:47 +00:00
|
|
|
JS::RootedFunction fun(JSD_GetJSRuntime(mCx), JSD_GetJSFunction(mCx, mScript));
|
2002-12-17 22:22:30 +00:00
|
|
|
if (!fun)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2013-05-05 21:13:03 +00:00
|
|
|
|
2013-06-12 21:17:55 +00:00
|
|
|
AutoSafeJSContext jsContext;
|
2013-05-05 21:13:03 +00:00
|
|
|
JS::RootedObject obj(jsContext, JS_GetFunctionObject(fun));
|
2002-12-17 22:22:30 +00:00
|
|
|
if (!obj)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
JSDContext *cx;
|
2007-06-20 05:56:13 +00:00
|
|
|
if (NS_FAILED(gJsds->GetJSDContext (&cx)))
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2002-12-17 22:22:30 +00:00
|
|
|
|
|
|
|
JSDValue *jsdv = JSD_NewValue(cx, OBJECT_TO_JSVAL(obj));
|
|
|
|
if (!jsdv)
|
2007-06-20 05:56:13 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-12-17 22:22:30 +00:00
|
|
|
|
|
|
|
*_rval = jsdValue::FromPtr(cx, jsdv);
|
|
|
|
if (!*_rval) {
|
|
|
|
JSD_DropValue(cx, jsdv);
|
2007-06-20 05:56:13 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-12-17 22:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-12 00:56:35 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::GetFunctionSource(nsAString & aFunctionSource)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-06-12 21:17:55 +00:00
|
|
|
AutoSafeJSContext cx_;
|
|
|
|
JSContext *cx = cx_; // Appease the type system with Maybe<>s below.
|
2013-05-05 21:13:03 +00:00
|
|
|
JS::RootedFunction fun(cx, JSD_GetJSFunction (mCx, mScript));
|
2006-06-12 22:39:55 +00:00
|
|
|
|
2002-01-12 00:56:35 +00:00
|
|
|
JSString *jsstr;
|
2012-08-22 01:42:53 +00:00
|
|
|
mozilla::Maybe<JSAutoCompartment> ac;
|
2010-11-04 01:04:22 +00:00
|
|
|
if (fun) {
|
2012-08-22 01:42:53 +00:00
|
|
|
ac.construct(cx, JS_GetFunctionObject(fun));
|
2002-01-12 00:56:35 +00:00
|
|
|
jsstr = JS_DecompileFunction (cx, fun, 4);
|
2010-11-04 01:04:22 +00:00
|
|
|
} else {
|
2013-05-05 21:13:03 +00:00
|
|
|
JS::RootedScript script(cx, JSD_GetJSScript (mCx, mScript));
|
2012-08-27 20:32:51 +00:00
|
|
|
ac.construct(cx, script);
|
2002-01-12 00:56:35 +00:00
|
|
|
jsstr = JS_DecompileScript (cx, script, "ppscript", 4);
|
|
|
|
}
|
|
|
|
if (!jsstr)
|
|
|
|
return NS_ERROR_FAILURE;
|
2006-06-12 22:39:55 +00:00
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
size_t length;
|
|
|
|
const jschar *chars = JS_GetStringCharsZAndLength(cx, jsstr, &length);
|
|
|
|
if (!chars)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
aFunctionSource = nsDependentString(chars, length);
|
2002-01-12 00:56:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::GetBaseLineNumber(uint32_t *_rval)
|
2001-04-17 08:50:41 +00:00
|
|
|
{
|
2001-06-28 07:46:36 +00:00
|
|
|
*_rval = mBaseLineNumber;
|
2001-04-17 08:50:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::GetLineExtent(uint32_t *_rval)
|
2001-04-17 08:50:41 +00:00
|
|
|
{
|
2001-06-28 07:46:36 +00:00
|
|
|
*_rval = mLineExtent;
|
2001-04-20 03:54:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-27 09:24:14 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::GetCallCount(uint32_t *_rval)
|
2002-02-27 09:24:14 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_GetScriptCallCount (mCx, mScript);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::GetMaxRecurseDepth(uint32_t *_rval)
|
2002-02-27 09:24:14 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_GetScriptMaxRecurseDepth (mCx, mScript);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::GetMinExecutionTime(double *_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_GetScriptMinExecutionTime (mCx, mScript);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::GetMaxExecutionTime(double *_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_GetScriptMaxExecutionTime (mCx, mScript);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::GetTotalExecutionTime(double *_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_GetScriptTotalExecutionTime (mCx, mScript);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-02 15:53:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::GetMinOwnExecutionTime(double *_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_GetScriptMinOwnExecutionTime (mCx, mScript);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::GetMaxOwnExecutionTime(double *_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_GetScriptMaxOwnExecutionTime (mCx, mScript);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::GetTotalOwnExecutionTime(double *_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_GetScriptTotalOwnExecutionTime (mCx, mScript);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-27 09:24:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::ClearProfileData()
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
JSD_ClearScriptProfileData(mCx, mScript);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::PcToLine(uint32_t aPC, uint32_t aPcmap, uint32_t *_rval)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2002-01-12 00:56:35 +00:00
|
|
|
if (aPcmap == PCMAP_SOURCETEXT) {
|
|
|
|
*_rval = JSD_GetClosestLine (mCx, mScript, mFirstPC + aPC);
|
|
|
|
} else if (aPcmap == PCMAP_PRETTYPRINT) {
|
|
|
|
*_rval = PPPcToLine(aPC);
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::LineToPc(uint32_t aLine, uint32_t aPcmap, uint32_t *_rval)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2002-01-12 00:56:35 +00:00
|
|
|
if (aPcmap == PCMAP_SOURCETEXT) {
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t pc = JSD_GetClosestPC (mCx, mScript, aLine);
|
2002-01-12 00:56:35 +00:00
|
|
|
*_rval = pc - mFirstPC;
|
|
|
|
} else if (aPcmap == PCMAP_PRETTYPRINT) {
|
|
|
|
*_rval = PPLineToPc(aLine);
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-16 23:18:35 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdScript::EnableSingleStepInterrupts(bool enable)
|
2010-11-16 23:18:35 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
|
|
|
|
/* Must have set interrupt hook before enabling */
|
|
|
|
if (enable && !jsdService::GetService()->CheckInterruptHook())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2011-01-31 23:01:08 +00:00
|
|
|
return (JSD_EnableSingleStepInterrupts(mCx, mScript, enable) ? NS_OK : NS_ERROR_FAILURE);
|
2010-11-16 23:18:35 +00:00
|
|
|
}
|
|
|
|
|
2011-03-03 18:11:54 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::GetExecutableLines(uint32_t aPcmap, uint32_t aStartLine, uint32_t aMaxLines,
|
|
|
|
uint32_t* aCount, uint32_t** aExecutableLines)
|
2011-03-03 18:11:54 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
if (aPcmap == PCMAP_SOURCETEXT) {
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t start = JSD_GetClosestPC(mCx, mScript, 0);
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned lastLine = JSD_GetScriptBaseLineNumber(mCx, mScript)
|
2011-03-03 18:11:54 +00:00
|
|
|
+ JSD_GetScriptLineExtent(mCx, mScript) - 1;
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t end = JSD_GetClosestPC(mCx, mScript, lastLine + 1);
|
2011-03-03 18:11:54 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
*aExecutableLines = static_cast<uint32_t*>(NS_Alloc((end - start + 1) * sizeof(uint32_t)));
|
2013-09-19 19:26:36 +00:00
|
|
|
if (!JSD_GetLinePCs(mCx, mScript, aStartLine, aMaxLines, aCount, aExecutableLines,
|
|
|
|
nullptr))
|
2011-03-03 18:11:54 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPcmap == PCMAP_PRETTYPRINT) {
|
|
|
|
if (!mPPLineMap) {
|
|
|
|
if (!CreatePPLineMap())
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsTArray<uint32_t> lines;
|
|
|
|
uint32_t i;
|
2011-03-03 18:11:54 +00:00
|
|
|
|
|
|
|
for (i = 0; i < mPCMapSize; ++i) {
|
|
|
|
if (mPPLineMap[i].line >= aStartLine)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < mPCMapSize && lines.Length() < aMaxLines; ++i) {
|
|
|
|
lines.AppendElement(mPPLineMap[i].line);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCount)
|
|
|
|
*aCount = lines.Length();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
*aExecutableLines = static_cast<uint32_t*>(NS_Alloc(lines.Length() * sizeof(uint32_t)));
|
2011-03-03 18:11:54 +00:00
|
|
|
if (!*aExecutableLines)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
for (i = 0; i < lines.Length(); ++i)
|
|
|
|
(*aExecutableLines)[i] = lines[i];
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::IsLineExecutable(uint32_t aLine, uint32_t aPcmap, bool *_rval)
|
2001-10-30 13:41:32 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2002-01-12 00:56:35 +00:00
|
|
|
if (aPcmap == PCMAP_SOURCETEXT) {
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t pc = JSD_GetClosestPC (mCx, mScript, aLine);
|
2002-01-12 00:56:35 +00:00
|
|
|
*_rval = (aLine == JSD_GetClosestLine (mCx, mScript, pc));
|
|
|
|
} else if (aPcmap == PCMAP_PRETTYPRINT) {
|
|
|
|
if (!mPPLineMap && !CreatePPLineMap())
|
2009-01-04 18:59:17 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2011-10-17 14:59:28 +00:00
|
|
|
*_rval = false;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mPCMapSize; ++i) {
|
2002-01-12 00:56:35 +00:00
|
|
|
if (mPPLineMap[i].line >= aLine) {
|
|
|
|
*_rval = (mPPLineMap[i].line == aLine);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::SetBreakpoint(uint32_t aPC)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t pc = mFirstPC + aPC;
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetExecutionHook (mCx, mScript, pc, jsds_ExecutionHookProc, nullptr);
|
2001-04-25 18:20:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdScript::ClearBreakpoint(uint32_t aPC)
|
2001-04-25 18:20:47 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t pc = mFirstPC + aPC;
|
2001-04-25 18:20:47 +00:00
|
|
|
JSD_ClearExecutionHook (mCx, mScript, pc);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdScript::ClearAllBreakpoints()
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-05-13 21:08:06 +00:00
|
|
|
JSD_LockScriptSubsystem(mCx);
|
2001-04-25 18:20:47 +00:00
|
|
|
JSD_ClearAllExecutionHooksForScript (mCx, mScript);
|
2001-05-13 21:08:06 +00:00
|
|
|
JSD_UnlockScriptSubsystem(mCx);
|
2001-04-25 18:20:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-29 08:32:23 +00:00
|
|
|
/* Contexts */
|
2013-07-19 02:23:32 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(jsdContext, jsdIContext, jsdIEphemeral)
|
2002-01-29 08:32:23 +00:00
|
|
|
|
|
|
|
jsdIContext *
|
|
|
|
jsdContext::FromPtr (JSDContext *aJSDCx, JSContext *aJSCx)
|
|
|
|
{
|
2009-01-04 08:06:51 +00:00
|
|
|
if (!aJSDCx || !aJSCx)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-01-04 08:06:51 +00:00
|
|
|
|
2002-01-29 08:32:23 +00:00
|
|
|
nsCOMPtr<jsdIContext> jsdicx;
|
|
|
|
nsCOMPtr<jsdIEphemeral> eph =
|
2007-07-08 07:08:04 +00:00
|
|
|
jsds_FindEphemeral (&gLiveContexts, static_cast<void *>(aJSCx));
|
2002-01-29 08:32:23 +00:00
|
|
|
if (eph)
|
|
|
|
{
|
|
|
|
jsdicx = do_QueryInterface(eph);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-04 08:06:51 +00:00
|
|
|
nsCOMPtr<nsISupports> iscx;
|
2013-10-28 11:52:27 +00:00
|
|
|
if (JS::ContextOptionsRef(aJSCx).privateIsNSISupports())
|
2009-01-04 08:06:51 +00:00
|
|
|
iscx = static_cast<nsISupports *>(JS_GetContextPrivate(aJSCx));
|
2002-01-29 08:32:23 +00:00
|
|
|
jsdicx = new jsdContext (aJSDCx, aJSCx, iscx);
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
jsdIContext *ctx = nullptr;
|
2009-01-04 08:06:51 +00:00
|
|
|
jsdicx.swap(ctx);
|
|
|
|
return ctx;
|
2002-01-29 08:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
jsdContext::jsdContext (JSDContext *aJSDCx, JSContext *aJSCx,
|
2013-11-13 00:43:34 +00:00
|
|
|
nsISupports *aISCx) : mValid(true),
|
|
|
|
mScriptDisabledForWindowWithID(0),
|
|
|
|
mTag(0),
|
2002-01-29 08:32:23 +00:00
|
|
|
mJSDCx(aJSDCx),
|
|
|
|
mJSCx(aJSCx), mISCx(aISCx)
|
|
|
|
{
|
|
|
|
DEBUG_CREATE ("jsdContext", gContextCount);
|
|
|
|
mLiveListEntry.value = this;
|
2007-07-08 07:08:04 +00:00
|
|
|
mLiveListEntry.key = static_cast<void *>(aJSCx);
|
2002-01-29 08:32:23 +00:00
|
|
|
jsds_InsertEphemeral (&gLiveContexts, &mLiveListEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdContext::~jsdContext()
|
|
|
|
{
|
|
|
|
DEBUG_DESTROY ("jsdContext", gContextCount);
|
|
|
|
if (mValid)
|
|
|
|
{
|
|
|
|
/* call Invalidate() to take ourselves out of the live list */
|
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdContext::GetIsValid(bool *_rval)
|
2002-01-29 08:32:23 +00:00
|
|
|
{
|
|
|
|
*_rval = mValid;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdContext::Invalidate()
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2011-10-17 14:59:28 +00:00
|
|
|
mValid = false;
|
2002-01-29 08:32:23 +00:00
|
|
|
jsds_RemoveEphemeral (&gLiveContexts, &mLiveListEntry);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsdContext::InvalidateAll()
|
|
|
|
{
|
|
|
|
if (gLiveContexts)
|
|
|
|
jsds_InvalidateAllEphemerals (&gLiveContexts);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdContext::GetJSContext(JSContext **_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = mJSCx;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-28 11:52:27 +00:00
|
|
|
/* Simulate the old options API in terms of the new one for backwards
|
|
|
|
* compatibility */
|
|
|
|
|
|
|
|
#define JSOPTION_EXTRA_WARNINGS JS_BIT(0)
|
|
|
|
#define JSOPTION_WERROR JS_BIT(1)
|
|
|
|
#define JSOPTION_VAROBJFIX JS_BIT(2)
|
|
|
|
#define JSOPTION_PRIVATE_IS_NSISUPPORTS JS_BIT(3)
|
|
|
|
#define JSOPTION_DONT_REPORT_UNCAUGHT JS_BIT(8)
|
|
|
|
#define JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT JS_BIT(11)
|
|
|
|
#define JSOPTION_NO_SCRIPT_RVAL JS_BIT(12)
|
|
|
|
#define JSOPTION_STRICT_MODE JS_BIT(17)
|
|
|
|
#define JSOPTION_MASK JS_BITMASK(20)
|
|
|
|
|
2002-02-20 05:45:57 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdContext::GetOptions(uint32_t *_rval)
|
2002-02-20 05:45:57 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-10-28 11:52:27 +00:00
|
|
|
*_rval = (JS::ContextOptionsRef(mJSCx).extraWarnings() ? JSOPTION_EXTRA_WARNINGS : 0)
|
|
|
|
| (JS::ContextOptionsRef(mJSCx).werror() ? JSOPTION_WERROR : 0)
|
|
|
|
| (JS::ContextOptionsRef(mJSCx).varObjFix() ? JSOPTION_VAROBJFIX : 0)
|
|
|
|
| (JS::ContextOptionsRef(mJSCx).privateIsNSISupports() ? JSOPTION_PRIVATE_IS_NSISUPPORTS : 0)
|
|
|
|
| (JS::ContextOptionsRef(mJSCx).dontReportUncaught() ? JSOPTION_DONT_REPORT_UNCAUGHT : 0)
|
|
|
|
| (JS::ContextOptionsRef(mJSCx).noDefaultCompartmentObject() ? JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT : 0)
|
|
|
|
| (JS::ContextOptionsRef(mJSCx).noScriptRval() ? JSOPTION_NO_SCRIPT_RVAL : 0)
|
2014-02-26 09:25:36 +00:00
|
|
|
| (JS::ContextOptionsRef(mJSCx).strictMode() ? JSOPTION_STRICT_MODE : 0);
|
2002-02-20 05:45:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdContext::SetOptions(uint32_t options)
|
2002-02-20 05:45:57 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
|
|
|
|
/* don't let users change this option, they'd just be shooting themselves
|
|
|
|
* in the foot. */
|
2013-10-28 11:52:27 +00:00
|
|
|
if (JS::ContextOptionsRef(mJSCx).privateIsNSISupports() !=
|
|
|
|
(options & JSOPTION_PRIVATE_IS_NSISUPPORTS))
|
2002-02-20 05:45:57 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2013-10-28 11:52:27 +00:00
|
|
|
JS::ContextOptionsRef(mJSCx).setExtraWarnings(options & JSOPTION_EXTRA_WARNINGS)
|
|
|
|
.setWerror(options & JSOPTION_WERROR)
|
|
|
|
.setVarObjFix(options & JSOPTION_VAROBJFIX)
|
|
|
|
.setDontReportUncaught(options & JSOPTION_DONT_REPORT_UNCAUGHT)
|
|
|
|
.setNoDefaultCompartmentObject(options & JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT)
|
|
|
|
.setNoScriptRval(options & JSOPTION_NO_SCRIPT_RVAL)
|
2014-02-26 09:25:36 +00:00
|
|
|
.setStrictMode(options & JSOPTION_STRICT_MODE);
|
2002-02-20 05:45:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdContext::GetPrivateData(nsISupports **_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-10-28 11:52:27 +00:00
|
|
|
if (JS::ContextOptionsRef(mJSCx).privateIsNSISupports())
|
2002-02-20 05:45:57 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
*_rval = static_cast<nsISupports*>(JS_GetContextPrivate(mJSCx));
|
2002-02-20 05:45:57 +00:00
|
|
|
NS_IF_ADDREF(*_rval);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*_rval = nullptr;
|
2002-02-20 05:45:57 +00:00
|
|
|
}
|
2013-10-28 11:52:27 +00:00
|
|
|
|
2002-02-20 05:45:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-10-28 11:52:27 +00:00
|
|
|
|
2002-01-29 08:32:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdContext::GetWrappedContext(nsISupports **_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2009-01-04 08:06:51 +00:00
|
|
|
NS_IF_ADDREF(*_rval = mISCx);
|
2002-01-29 08:32:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdContext::GetTag(uint32_t *_rval)
|
2002-01-29 08:32:23 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
if (!mTag)
|
|
|
|
mTag = ++jsdContext::LastTag;
|
|
|
|
|
|
|
|
*_rval = mTag;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdContext::GetGlobalObject (jsdIValue **_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-09-04 21:06:55 +00:00
|
|
|
JSObject *glob = GetDefaultScopeFromJSContext(mJSCx);
|
2002-01-29 08:32:23 +00:00
|
|
|
JSDValue *jsdv = JSD_NewValue (mJSDCx, OBJECT_TO_JSVAL(glob));
|
|
|
|
if (!jsdv)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
*_rval = jsdValue::FromPtr (mJSDCx, jsdv);
|
|
|
|
if (!*_rval)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdContext::GetScriptsEnabled (bool *_rval)
|
2002-01-29 08:32:23 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-11-13 00:43:34 +00:00
|
|
|
*_rval = IsScriptEnabled();
|
2004-02-09 22:48:53 +00:00
|
|
|
return NS_OK;
|
2002-01-29 08:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdContext::SetScriptsEnabled (bool _rval)
|
2002-01-29 08:32:23 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-11-13 00:43:34 +00:00
|
|
|
if (_rval == IsScriptEnabled())
|
|
|
|
return NS_OK;
|
2009-01-04 08:06:51 +00:00
|
|
|
|
2013-11-13 00:43:34 +00:00
|
|
|
nsCOMPtr<nsIScriptContext> scx = do_QueryInterface(mISCx);
|
|
|
|
NS_ENSURE_TRUE(scx && scx->GetWindowProxy(), NS_ERROR_NO_INTERFACE);
|
|
|
|
nsCOMPtr<nsPIDOMWindow> piWin = do_QueryInterface(scx->GetGlobalObject());
|
|
|
|
NS_ENSURE_TRUE(piWin, NS_ERROR_NO_INTERFACE);
|
|
|
|
uint64_t currentWindowID = piWin->WindowID();
|
2002-01-29 08:32:23 +00:00
|
|
|
|
2013-11-13 00:43:34 +00:00
|
|
|
if (_rval) {
|
|
|
|
if (mScriptDisabledForWindowWithID != currentWindowID) {
|
|
|
|
NS_WARNING("Please stop abusing JSD and fix your code!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
xpc::Scriptability::Get(scx->GetWindowProxy()).Unblock();
|
|
|
|
piWin->ResumeTimeouts();
|
|
|
|
mScriptDisabledForWindowWithID = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
piWin->SuspendTimeouts();
|
|
|
|
xpc::Scriptability::Get(scx->GetWindowProxy()).Block();
|
|
|
|
mScriptDisabledForWindowWithID = currentWindowID;
|
|
|
|
}
|
2004-02-09 22:48:53 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2002-01-29 08:32:23 +00:00
|
|
|
}
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
/* Stack Frames */
|
2013-07-19 02:23:32 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(jsdStackFrame, jsdIStackFrame, jsdIEphemeral)
|
2001-04-20 03:54:05 +00:00
|
|
|
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
jsdStackFrame::jsdStackFrame (JSDContext *aCx, JSDThreadState *aThreadState,
|
|
|
|
JSDStackFrameInfo *aStackFrameInfo) :
|
|
|
|
mCx(aCx), mThreadState(aThreadState), mStackFrameInfo(aStackFrameInfo)
|
|
|
|
{
|
|
|
|
DEBUG_CREATE ("jsdStackFrame", gFrameCount);
|
|
|
|
mValid = (aCx && aThreadState && aStackFrameInfo);
|
|
|
|
if (mValid) {
|
|
|
|
mLiveListEntry.key = aStackFrameInfo;
|
|
|
|
mLiveListEntry.value = this;
|
|
|
|
jsds_InsertEphemeral (&gLiveStackFrames, &mLiveListEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdStackFrame::~jsdStackFrame()
|
|
|
|
{
|
|
|
|
DEBUG_DESTROY ("jsdStackFrame", gFrameCount);
|
|
|
|
if (mValid)
|
|
|
|
{
|
|
|
|
/* call Invalidate() to take ourselves out of the live list */
|
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdIStackFrame *
|
|
|
|
jsdStackFrame::FromPtr (JSDContext *aCx, JSDThreadState *aThreadState,
|
|
|
|
JSDStackFrameInfo *aStackFrameInfo)
|
|
|
|
{
|
|
|
|
if (!aStackFrameInfo)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
|
|
|
|
jsdIStackFrame *rv;
|
|
|
|
nsCOMPtr<jsdIStackFrame> frame;
|
|
|
|
|
|
|
|
nsCOMPtr<jsdIEphemeral> eph =
|
|
|
|
jsds_FindEphemeral (&gLiveStackFrames,
|
2007-07-08 07:08:04 +00:00
|
|
|
reinterpret_cast<void *>(aStackFrameInfo));
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
|
|
|
|
if (eph)
|
|
|
|
{
|
|
|
|
frame = do_QueryInterface(eph);
|
|
|
|
rv = frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rv = new jsdStackFrame (aCx, aThreadState, aStackFrameInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(rv);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdStackFrame::Invalidate()
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2011-10-17 14:59:28 +00:00
|
|
|
mValid = false;
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
jsds_RemoveEphemeral (&gLiveStackFrames, &mLiveListEntry);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsdStackFrame::InvalidateAll()
|
|
|
|
{
|
|
|
|
if (gLiveStackFrames)
|
|
|
|
jsds_InvalidateAllEphemerals (&gLiveStackFrames);
|
|
|
|
}
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdStackFrame::GetJSDContext(JSDContext **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = mCx;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdStackFrame::GetJSDThreadState(JSDThreadState **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = mThreadState;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdStackFrame::GetJSDStackFrameInfo(JSDStackFrameInfo **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = mStackFrameInfo;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-03 22:19:04 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdStackFrame::GetIsValid(bool *_rval)
|
2001-07-03 22:19:04 +00:00
|
|
|
{
|
|
|
|
*_rval = mValid;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdStackFrame::GetCallingFrame(jsdIStackFrame **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSDStackFrameInfo *sfi = JSD_GetCallingStackFrame (mCx, mThreadState,
|
|
|
|
mStackFrameInfo);
|
|
|
|
*_rval = jsdStackFrame::FromPtr (mCx, mThreadState, sfi);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-29 08:32:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdStackFrame::GetExecutionContext(jsdIContext **_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
JSContext *cx = JSD_GetJSContext (mCx, mThreadState);
|
|
|
|
*_rval = jsdContext::FromPtr (mCx, cx);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-14 07:57:30 +00:00
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdStackFrame::GetFunctionName(nsACString &_rval)
|
2002-02-14 07:57:30 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2011-01-29 21:40:29 +00:00
|
|
|
JSString *str = JSD_GetIdForStackFrame(mCx, mThreadState, mStackFrameInfo);
|
2010-11-24 16:56:43 +00:00
|
|
|
if (str)
|
2012-11-09 17:45:25 +00:00
|
|
|
return AssignToJSString(mCx, &_rval, str);
|
2010-11-24 16:56:43 +00:00
|
|
|
|
|
|
|
_rval.Assign("anonymous");
|
2002-02-14 07:57:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdStackFrame::GetIsDebugger(bool *_rval)
|
2002-02-14 07:57:30 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_IsStackFrameDebugger (mCx, mThreadState, mStackFrameInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdStackFrame::GetIsConstructing(bool *_rval)
|
2002-02-14 07:57:30 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
*_rval = JSD_IsStackFrameConstructing (mCx, mThreadState, mStackFrameInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdStackFrame::GetScript(jsdIScript **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSDScript *script = JSD_GetScriptForStackFrame (mCx, mThreadState,
|
|
|
|
mStackFrameInfo);
|
|
|
|
*_rval = jsdScript::FromPtr (mCx, script);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdStackFrame::GetPc(uint32_t *_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2002-01-12 00:56:35 +00:00
|
|
|
JSDScript *script = JSD_GetScriptForStackFrame (mCx, mThreadState,
|
|
|
|
mStackFrameInfo);
|
|
|
|
if (!script)
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t pcbase = JSD_GetClosestPC(mCx, script, 0);
|
2002-01-12 00:56:35 +00:00
|
|
|
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t pc = JSD_GetPCForStackFrame (mCx, mThreadState, mStackFrameInfo);
|
2002-02-27 09:24:14 +00:00
|
|
|
if (pc)
|
|
|
|
*_rval = pc - pcbase;
|
|
|
|
else
|
|
|
|
*_rval = pcbase;
|
2001-04-17 08:50:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-23 19:12:56 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdStackFrame::GetLine(uint32_t *_rval)
|
2001-04-23 19:12:56 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-23 19:12:56 +00:00
|
|
|
JSDScript *script = JSD_GetScriptForStackFrame (mCx, mThreadState,
|
|
|
|
mStackFrameInfo);
|
2002-02-14 07:57:30 +00:00
|
|
|
if (script) {
|
2012-01-11 08:23:05 +00:00
|
|
|
uintptr_t pc = JSD_GetPCForStackFrame (mCx, mThreadState, mStackFrameInfo);
|
2002-02-14 07:57:30 +00:00
|
|
|
*_rval = JSD_GetClosestLine (mCx, script, pc);
|
|
|
|
} else {
|
2010-08-16 19:35:04 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2002-02-14 07:57:30 +00:00
|
|
|
}
|
2001-04-23 19:12:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdStackFrame::GetCallee(jsdIValue **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSDValue *jsdv = JSD_GetCallObjectForStackFrame (mCx, mThreadState,
|
|
|
|
mStackFrameInfo);
|
|
|
|
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdStackFrame::GetScope(jsdIValue **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSDValue *jsdv = JSD_GetScopeChainForStackFrame (mCx, mThreadState,
|
|
|
|
mStackFrameInfo);
|
|
|
|
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdStackFrame::GetThisValue(jsdIValue **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSDValue *jsdv = JSD_GetThisForStackFrame (mCx, mThreadState,
|
|
|
|
mStackFrameInfo);
|
|
|
|
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdStackFrame::Eval (const nsAString &bytes, const nsACString &fileName,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t line, jsdIValue **result, bool *_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2003-05-01 18:50:58 +00:00
|
|
|
|
|
|
|
if (bytes.IsEmpty())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2004-02-19 02:44:03 +00:00
|
|
|
// get pointer to buffer contained in |bytes|
|
|
|
|
nsAString::const_iterator h;
|
|
|
|
bytes.BeginReading(h);
|
2007-07-08 07:08:04 +00:00
|
|
|
const jschar *char_bytes = reinterpret_cast<const jschar *>(h.get());
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2002-01-29 06:15:58 +00:00
|
|
|
JSExceptionState *estate = 0;
|
2001-04-20 03:54:05 +00:00
|
|
|
|
2013-06-12 21:17:56 +00:00
|
|
|
AutoPushJSContext cx(JSD_GetJSContext (mCx, mThreadState));
|
2006-06-12 22:39:55 +00:00
|
|
|
|
2013-03-06 16:41:43 +00:00
|
|
|
JS::RootedValue jv(cx);
|
2006-06-12 22:39:55 +00:00
|
|
|
|
2002-01-29 06:15:58 +00:00
|
|
|
estate = JS_SaveExceptionState (cx);
|
|
|
|
JS_ClearPendingException (cx);
|
|
|
|
|
|
|
|
*_rval = JSD_AttemptUCScriptInStackFrame (mCx, mThreadState,
|
|
|
|
mStackFrameInfo,
|
|
|
|
char_bytes, bytes.Length(),
|
2009-01-08 04:42:15 +00:00
|
|
|
PromiseFlatCString(fileName).get(),
|
|
|
|
line, &jv);
|
2002-01-29 06:15:58 +00:00
|
|
|
if (!*_rval) {
|
|
|
|
if (JS_IsExceptionPending(cx))
|
2013-09-19 07:54:01 +00:00
|
|
|
JS_GetPendingException (cx, &jv);
|
2002-01-29 06:15:58 +00:00
|
|
|
else
|
2010-07-15 06:19:36 +00:00
|
|
|
jv = JSVAL_NULL;
|
2002-01-29 06:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_RestoreExceptionState (cx, estate);
|
2006-06-12 22:39:55 +00:00
|
|
|
|
2002-02-16 10:53:52 +00:00
|
|
|
JSDValue *jsdv = JSD_NewValue (mCx, jv);
|
|
|
|
if (!jsdv)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
*result = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
if (!*result)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-04-20 03:54:05 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-04 22:14:04 +00:00
|
|
|
/* Values */
|
2013-07-19 02:23:32 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(jsdValue, jsdIValue, jsdIEphemeral)
|
2002-01-29 08:32:23 +00:00
|
|
|
jsdIValue *
|
|
|
|
jsdValue::FromPtr (JSDContext *aCx, JSDValue *aValue)
|
|
|
|
{
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
/* value will be dropped by te jsdValue destructor. */
|
|
|
|
|
2002-01-29 08:32:23 +00:00
|
|
|
if (!aValue)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2002-01-29 08:32:23 +00:00
|
|
|
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
jsdIValue *rv = new jsdValue (aCx, aValue);
|
2002-01-29 08:32:23 +00:00
|
|
|
NS_IF_ADDREF(rv);
|
|
|
|
return rv;
|
|
|
|
}
|
2001-07-03 22:19:04 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
jsdValue::jsdValue (JSDContext *aCx, JSDValue *aValue) : mValid(true),
|
2001-07-03 22:19:04 +00:00
|
|
|
mCx(aCx),
|
|
|
|
mValue(aValue)
|
|
|
|
{
|
|
|
|
DEBUG_CREATE ("jsdValue", gValueCount);
|
|
|
|
mLiveListEntry.value = this;
|
|
|
|
jsds_InsertEphemeral (&gLiveValues, &mLiveListEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdValue::~jsdValue()
|
|
|
|
{
|
|
|
|
DEBUG_DESTROY ("jsdValue", gValueCount);
|
|
|
|
if (mValid)
|
|
|
|
/* call Invalidate() to take ourselves out of the live list */
|
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdValue::GetIsValid(bool *_rval)
|
2001-07-03 22:19:04 +00:00
|
|
|
{
|
|
|
|
*_rval = mValid;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdValue::Invalidate()
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2011-10-17 14:59:28 +00:00
|
|
|
mValid = false;
|
2001-07-03 22:19:04 +00:00
|
|
|
jsds_RemoveEphemeral (&gLiveValues, &mLiveListEntry);
|
|
|
|
JSD_DropValue (mCx, mValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsdValue::InvalidateAll()
|
|
|
|
{
|
|
|
|
if (gLiveValues)
|
|
|
|
jsds_InvalidateAllEphemerals (&gLiveValues);
|
|
|
|
}
|
2001-04-20 03:54:05 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdValue::GetJSDContext(JSDContext **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = mCx;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdValue::GetJSDValue (JSDValue **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = mValue;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdValue::GetIsNative (bool *_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = JSD_IsValueNative (mCx, mValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdValue::GetIsNumber (bool *_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = JSD_IsValueNumber (mCx, mValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdValue::GetIsPrimitive (bool *_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = JSD_IsValuePrimitive (mCx, mValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdValue::GetJsType (uint32_t *_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-08-22 22:43:47 +00:00
|
|
|
JS::RootedValue val(JSD_GetJSRuntime(mCx), JSD_GetValueWrappedJSVal (mCx, mValue));
|
2001-08-28 22:02:07 +00:00
|
|
|
|
|
|
|
if (JSVAL_IS_NULL(val))
|
|
|
|
*_rval = TYPE_NULL;
|
|
|
|
else if (JSVAL_IS_BOOLEAN(val))
|
2001-05-04 22:14:04 +00:00
|
|
|
*_rval = TYPE_BOOLEAN;
|
2001-08-28 22:02:07 +00:00
|
|
|
else if (JSVAL_IS_DOUBLE(val))
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = TYPE_DOUBLE;
|
2001-08-28 22:02:07 +00:00
|
|
|
else if (JSVAL_IS_INT(val))
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = TYPE_INT;
|
2001-08-28 22:02:07 +00:00
|
|
|
else if (JSVAL_IS_STRING(val))
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = TYPE_STRING;
|
2001-08-28 22:02:07 +00:00
|
|
|
else if (JSVAL_IS_VOID(val))
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = TYPE_VOID;
|
2001-08-28 22:02:07 +00:00
|
|
|
else if (JSD_IsValueFunction (mCx, mValue))
|
|
|
|
*_rval = TYPE_FUNCTION;
|
2012-05-11 15:46:26 +00:00
|
|
|
else if (!JSVAL_IS_PRIMITIVE(val))
|
2001-08-28 22:02:07 +00:00
|
|
|
*_rval = TYPE_OBJECT;
|
2001-04-20 03:54:05 +00:00
|
|
|
else
|
2001-08-03 05:14:21 +00:00
|
|
|
NS_ASSERTION (0, "Value has no discernible type.");
|
2001-04-20 03:54:05 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdValue::GetJsPrototype (jsdIValue **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSDValue *jsdv = JSD_GetValuePrototype (mCx, mValue);
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdValue::GetJsParent (jsdIValue **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSDValue *jsdv = JSD_GetValueParent (mCx, mValue);
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdValue::GetJsClassName(nsACString &_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2009-01-08 04:42:15 +00:00
|
|
|
_rval.Assign(JSD_GetValueClassName(mCx, mValue));
|
2002-02-27 09:24:14 +00:00
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdValue::GetJsConstructor (jsdIValue **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSDValue *jsdv = JSD_GetValueConstructor (mCx, mValue);
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdValue::GetJsFunctionName(nsACString &_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2012-11-09 17:45:25 +00:00
|
|
|
return AssignToJSString(mCx, &_rval, JSD_GetValueFunctionId(mCx, mValue));
|
2001-04-20 03:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdValue::GetBooleanValue(bool *_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = JSD_GetValueBoolean (mCx, mValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdValue::GetDoubleValue(double *_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2010-07-15 06:19:36 +00:00
|
|
|
*_rval = JSD_GetValueDouble (mCx, mValue);
|
2001-04-20 03:54:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdValue::GetIntValue(int32_t *_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
*_rval = JSD_GetValueInt (mCx, mValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdValue::GetObjectValue(jsdIObject **_rval)
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSDObject *obj;
|
|
|
|
obj = JSD_GetObjectForValue (mCx, mValue);
|
|
|
|
*_rval = jsdObject::FromPtr (mCx, obj);
|
2002-01-29 08:32:23 +00:00
|
|
|
if (!*_rval)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-04-20 03:54:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdValue::GetStringValue(nsACString &_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-06-12 21:17:55 +00:00
|
|
|
AutoSafeJSContext cx;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSString *jstr_val = JSD_GetValueString(mCx, mValue);
|
2004-03-23 05:13:09 +00:00
|
|
|
if (jstr_val) {
|
2010-12-03 08:24:17 +00:00
|
|
|
size_t length;
|
|
|
|
const jschar *chars = JS_GetStringCharsZAndLength(cx, jstr_val, &length);
|
|
|
|
if (!chars)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsDependentString depStr(chars, length);
|
|
|
|
CopyUTF16toUTF8(depStr, _rval);
|
2002-02-27 09:24:14 +00:00
|
|
|
} else {
|
2009-01-08 04:42:15 +00:00
|
|
|
_rval.Truncate();
|
2002-02-27 09:24:14 +00:00
|
|
|
}
|
2001-04-20 03:54:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-23 19:12:56 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdValue::GetPropertyCount (int32_t *_rval)
|
2001-04-23 19:12:56 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-05-04 22:14:04 +00:00
|
|
|
if (JSD_IsValueObject(mCx, mValue))
|
|
|
|
*_rval = JSD_GetCountOfProperties (mCx, mValue);
|
|
|
|
else
|
|
|
|
*_rval = -1;
|
2001-04-23 19:12:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdValue::GetProperties (jsdIProperty ***propArray, uint32_t *length)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2012-07-30 14:20:58 +00:00
|
|
|
*propArray = nullptr;
|
2005-07-01 05:12:47 +00:00
|
|
|
if (length)
|
|
|
|
*length = 0;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t prop_count = JSD_IsValueObject(mCx, mValue)
|
2004-11-10 21:58:00 +00:00
|
|
|
? JSD_GetCountOfProperties (mCx, mValue)
|
|
|
|
: 0;
|
2005-07-01 05:12:47 +00:00
|
|
|
NS_ENSURE_TRUE(prop_count, NS_OK);
|
2001-05-04 22:14:04 +00:00
|
|
|
|
2004-11-10 21:58:00 +00:00
|
|
|
jsdIProperty **pa_temp =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<jsdIProperty **>
|
|
|
|
(nsMemory::Alloc(sizeof (jsdIProperty *) *
|
2004-11-10 21:58:00 +00:00
|
|
|
prop_count));
|
2005-07-01 05:12:47 +00:00
|
|
|
NS_ENSURE_TRUE(pa_temp, NS_ERROR_OUT_OF_MEMORY);
|
2001-04-21 07:21:27 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i = 0;
|
2013-09-19 19:26:36 +00:00
|
|
|
JSDProperty *iter = nullptr;
|
2001-04-21 07:21:27 +00:00
|
|
|
JSDProperty *prop;
|
|
|
|
while ((prop = JSD_IterateProperties (mCx, mValue, &iter))) {
|
|
|
|
pa_temp[i] = jsdProperty::FromPtr (mCx, prop);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION (prop_count == i, "property count mismatch");
|
|
|
|
|
|
|
|
/* if caller doesn't care about length, don't bother telling them */
|
|
|
|
*propArray = pa_temp;
|
|
|
|
if (length)
|
|
|
|
*length = prop_count;
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdValue::GetProperty (const nsACString &name, jsdIProperty **_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2013-06-12 21:17:55 +00:00
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoCompartment ac(cx, JSD_GetDefaultGlobal (mCx)); // Just in case.
|
2006-06-12 22:39:55 +00:00
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
/* not rooting this */
|
2009-01-08 04:42:15 +00:00
|
|
|
JSString *jstr_name = JS_NewStringCopyZ(cx, PromiseFlatCString(name).get());
|
2006-06-12 22:39:55 +00:00
|
|
|
if (!jstr_name)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2001-04-20 03:54:05 +00:00
|
|
|
|
|
|
|
JSDProperty *prop = JSD_GetValueProperty (mCx, mValue, jstr_name);
|
|
|
|
|
|
|
|
*_rval = jsdProperty::FromPtr (mCx, prop);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdValue::Refresh()
|
|
|
|
{
|
2002-01-29 08:32:23 +00:00
|
|
|
ASSERT_VALID_EPHEMERAL;
|
2001-04-20 03:54:05 +00:00
|
|
|
JSD_RefreshValue (mCx, mValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-07 00:59:55 +00:00
|
|
|
NS_IMETHODIMP
|
2014-01-09 17:39:36 +00:00
|
|
|
jsdValue::GetWrappedValue(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval)
|
2002-02-07 00:59:55 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
|
2014-01-09 17:39:36 +00:00
|
|
|
aRetval.set(JSD_GetValueWrappedJSVal(mCx, mValue));
|
|
|
|
if (!JS_WrapValue(aCx, aRetval))
|
2011-12-18 10:07:22 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2002-02-07 00:59:55 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-08 01:19:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdValue::GetScript(jsdIScript **_rval)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_EPHEMERAL;
|
|
|
|
JSDScript *script = JSD_GetScriptForValue(mCx, mValue);
|
|
|
|
*_rval = jsdScript::FromPtr(mCx, script);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* debugger service implementation
|
|
|
|
******************************************************************************/
|
2012-04-30 20:58:38 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(jsdService)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(jsdIDebuggerService)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, jsdIDebuggerService)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-04-02 16:48:59 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_10(jsdService,
|
|
|
|
mErrorHook, mBreakpointHook, mDebugHook,
|
|
|
|
mDebuggerHook, mInterruptHook, mScriptHook,
|
|
|
|
mThrowHook, mTopLevelHook, mFunctionHook,
|
|
|
|
mActivationCallback)
|
2012-04-30 20:58:38 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(jsdService)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(jsdService)
|
2001-04-17 08:50:41 +00:00
|
|
|
|
2002-01-12 00:56:35 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::GetJSDContext(JSDContext **_rval)
|
|
|
|
{
|
|
|
|
*_rval = mCx;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-14 07:57:30 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::GetFlags (uint32_t *_rval)
|
2002-02-14 07:57:30 +00:00
|
|
|
{
|
2006-02-27 04:17:08 +00:00
|
|
|
ASSERT_VALID_CONTEXT;
|
2002-02-14 07:57:30 +00:00
|
|
|
*_rval = JSD_GetContextFlags (mCx);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::SetFlags (uint32_t flags)
|
2002-02-14 07:57:30 +00:00
|
|
|
{
|
2006-02-27 04:17:08 +00:00
|
|
|
ASSERT_VALID_CONTEXT;
|
2002-02-14 07:57:30 +00:00
|
|
|
JSD_SetContextFlags (mCx, flags);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2003-04-18 20:12:11 +00:00
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdService::GetImplementationString(nsACString &aImplementationString)
|
2003-04-18 20:12:11 +00:00
|
|
|
{
|
2009-01-08 04:42:15 +00:00
|
|
|
aImplementationString.AssignLiteral(implementationString);
|
2003-04-18 20:12:11 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::GetImplementationMajor(uint32_t *_rval)
|
2003-04-18 20:12:11 +00:00
|
|
|
{
|
|
|
|
*_rval = JSDS_MAJOR_VERSION;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::GetImplementationMinor(uint32_t *_rval)
|
2003-04-18 20:12:11 +00:00
|
|
|
{
|
|
|
|
*_rval = JSDS_MINOR_VERSION;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-06-28 07:46:36 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdService::GetIsOn (bool *_rval)
|
2001-04-17 08:50:41 +00:00
|
|
|
{
|
2001-06-28 07:46:36 +00:00
|
|
|
*_rval = mOn;
|
|
|
|
return NS_OK;
|
2001-04-17 08:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-25 18:20:47 +00:00
|
|
|
jsdService::On (void)
|
2010-10-30 16:13:02 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::AsyncOn (jsdIActivationCallback *activationCallback)
|
2001-04-17 08:50:41 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2007-07-01 19:25:10 +00:00
|
|
|
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-04-17 08:50:41 +00:00
|
|
|
|
2010-10-30 16:13:02 +00:00
|
|
|
mActivationCallback = activationCallback;
|
2001-04-17 08:50:41 +00:00
|
|
|
|
2011-11-09 21:11:39 +00:00
|
|
|
return xpc->SetDebugModeWhenPossible(true, true);
|
2010-10-30 16:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
jsdService::RecompileForDebugMode (JSContext *cx, JSCompartment *comp, bool mode) {
|
2010-10-30 19:07:46 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "wrong thread");
|
2011-02-12 01:12:00 +00:00
|
|
|
/* XPConnect now does this work itself, so this IDL entry point is no longer used. */
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2011-01-21 06:10:54 +00:00
|
|
|
}
|
2010-10-30 19:07:46 +00:00
|
|
|
|
2011-01-21 06:10:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::DeactivateDebugger ()
|
|
|
|
{
|
|
|
|
if (!mCx)
|
|
|
|
return NS_OK;
|
2010-10-30 16:13:02 +00:00
|
|
|
|
2011-01-21 06:10:54 +00:00
|
|
|
jsdContext::InvalidateAll();
|
|
|
|
jsdScript::InvalidateAll();
|
|
|
|
jsdValue::InvalidateAll();
|
|
|
|
jsdProperty::InvalidateAll();
|
2011-02-08 01:34:15 +00:00
|
|
|
jsdStackFrame::InvalidateAll();
|
2011-01-21 06:10:54 +00:00
|
|
|
ClearAllBreakpoints();
|
2010-10-30 19:07:46 +00:00
|
|
|
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetErrorReporter (mCx, nullptr, nullptr);
|
|
|
|
JSD_SetScriptHook (mCx, nullptr, nullptr);
|
2011-01-21 06:10:54 +00:00
|
|
|
JSD_ClearThrowHook (mCx);
|
|
|
|
JSD_ClearInterruptHook (mCx);
|
|
|
|
JSD_ClearDebuggerHook (mCx);
|
|
|
|
JSD_ClearDebugBreakHook (mCx);
|
|
|
|
JSD_ClearTopLevelHook (mCx);
|
|
|
|
JSD_ClearFunctionHook (mCx);
|
2013-05-05 21:13:03 +00:00
|
|
|
|
2011-01-21 06:10:54 +00:00
|
|
|
JSD_DebuggerOff (mCx);
|
2010-10-30 16:13:02 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mCx = nullptr;
|
|
|
|
mRuntime = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mOn = false;
|
2011-01-21 06:10:54 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-05-21 06:00:12 +00:00
|
|
|
}
|
2001-04-25 18:20:47 +00:00
|
|
|
|
2011-01-21 06:10:54 +00:00
|
|
|
|
2001-05-21 06:00:12 +00:00
|
|
|
NS_IMETHODIMP
|
2010-10-30 16:13:02 +00:00
|
|
|
jsdService::ActivateDebugger (JSRuntime *rt)
|
2001-05-21 06:00:12 +00:00
|
|
|
{
|
2001-06-28 07:46:36 +00:00
|
|
|
if (mOn)
|
|
|
|
return (rt == mRuntime) ? NS_OK : NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
|
|
|
mRuntime = rt;
|
|
|
|
|
2012-02-17 22:35:20 +00:00
|
|
|
if (gPrevGCSliceCallback == jsds_GCSliceCallbackProc)
|
2001-04-25 21:54:59 +00:00
|
|
|
/* condition indicates that the callback proc has not been set yet */
|
2013-01-27 20:35:12 +00:00
|
|
|
gPrevGCSliceCallback = JS::SetGCSliceCallback (rt, jsds_GCSliceCallbackProc);
|
2001-05-21 07:18:10 +00:00
|
|
|
|
2013-09-19 19:26:36 +00:00
|
|
|
mCx = JSD_DebuggerOnForUser (rt, nullptr, nullptr);
|
2001-04-25 18:20:47 +00:00
|
|
|
if (!mCx)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-06-28 07:46:36 +00:00
|
|
|
|
2013-06-12 21:17:55 +00:00
|
|
|
AutoSafeJSContext cx;
|
2013-05-22 21:42:43 +00:00
|
|
|
JS::RootedObject glob(cx, JSD_GetDefaultGlobal (mCx));
|
2013-06-12 21:17:55 +00:00
|
|
|
JSAutoCompartment ac(cx, glob);
|
2001-09-06 01:34:44 +00:00
|
|
|
|
|
|
|
/* init xpconnect on the debugger's context in case xpconnect tries to
|
|
|
|
* use it for stuff. */
|
2007-07-01 19:25:10 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2013-05-05 21:13:03 +00:00
|
|
|
|
2001-09-06 01:34:44 +00:00
|
|
|
xpc->InitClasses (cx, glob);
|
2011-02-11 21:22:58 +00:00
|
|
|
|
|
|
|
/* Start watching for script creation/destruction and manage jsdScript
|
|
|
|
* objects accordingly
|
|
|
|
*/
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetScriptHook (mCx, jsds_ScriptHookProc, nullptr);
|
2011-02-11 21:22:58 +00:00
|
|
|
|
2001-06-28 07:46:36 +00:00
|
|
|
/* If any of these mFooHook objects are installed, do the required JSD
|
|
|
|
* hookup now. See also, jsdService::SetFooHook().
|
|
|
|
*/
|
2002-01-29 05:56:02 +00:00
|
|
|
if (mErrorHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetErrorReporter (mCx, jsds_ErrorHookProc, nullptr);
|
2001-06-28 07:46:36 +00:00
|
|
|
if (mThrowHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetThrowHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2002-01-12 00:56:35 +00:00
|
|
|
/* can't ignore script callbacks, as we need to |Release| the wrapper
|
|
|
|
* stored in private data when a script is deleted. */
|
2001-06-28 07:46:36 +00:00
|
|
|
if (mInterruptHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetInterruptHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2001-06-28 07:46:36 +00:00
|
|
|
if (mDebuggerHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetDebuggerHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2002-01-29 05:56:02 +00:00
|
|
|
if (mDebugHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetDebugBreakHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2001-09-01 18:03:53 +00:00
|
|
|
if (mTopLevelHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetTopLevelHook (mCx, jsds_CallHookProc, nullptr);
|
2001-09-01 18:03:53 +00:00
|
|
|
else
|
2001-10-30 13:41:32 +00:00
|
|
|
JSD_ClearTopLevelHook (mCx);
|
2001-09-01 18:03:53 +00:00
|
|
|
if (mFunctionHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetFunctionHook (mCx, jsds_CallHookProc, nullptr);
|
2001-09-01 18:03:53 +00:00
|
|
|
else
|
2001-10-30 13:41:32 +00:00
|
|
|
JSD_ClearFunctionHook (mCx);
|
2011-10-17 14:59:28 +00:00
|
|
|
mOn = true;
|
2001-05-21 06:00:12 +00:00
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
#ifdef DEBUG
|
2002-01-29 08:32:23 +00:00
|
|
|
printf ("+++ JavaScript debugging hooks installed.\n");
|
2001-10-30 13:41:32 +00:00
|
|
|
#endif
|
2010-10-30 16:13:02 +00:00
|
|
|
|
2011-05-25 08:46:51 +00:00
|
|
|
nsCOMPtr<jsdIActivationCallback> activationCallback;
|
|
|
|
mActivationCallback.swap(activationCallback);
|
|
|
|
if (activationCallback)
|
|
|
|
return activationCallback->OnDebuggerActivated();
|
2010-10-30 16:13:02 +00:00
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::Off (void)
|
|
|
|
{
|
2001-10-30 13:41:32 +00:00
|
|
|
if (!mOn)
|
|
|
|
return NS_OK;
|
|
|
|
|
2001-06-28 07:46:36 +00:00
|
|
|
if (!mCx || !mRuntime)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
if (gDeadScripts) {
|
2012-02-17 22:35:20 +00:00
|
|
|
if (gGCRunning)
|
2001-06-28 07:46:36 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
Bug 421303 Crash [@ jsds_ScriptHookProc] r=caillon a=dsicore If we reach ~jsdService, that means our client doesn't care about us, so we can (and should) drop all references to any callbacks (if they cared, they'd have kept us alive!*). I think jsdService::Off should clear all the hooks, the strange magic of not clearing it isn't really a great idea. So for Off, we'll now clear the ScriptHook too (consumers who use off should really drop any references they have to our objects...). I'm still on the fence on this point, I suspect we can actually move it from ::Off to ~jsdService (it must be cleared at some point, otherwise if jsd_xpc's library manages to get unloaded, the function pointer would be invalid, which would be *BAD*). jsds_NotifyPendingDeadScripts needs to clear gDeadScripts whether or not there's a service or hooks, so it does. Because it's a static callback and because of the scary way GC works, I'd rather ensure (deathgrip) that jsds is available (and consistent!) for the duration of the function call. The code already handles the lack of a hook, so there's no reason to do magical returns.... The real problem which mayhemer found was that jsdService::Off was returning early (failure) because gGCStatus wasn't JSGC_END when called from ~jsdService from JS_GC from the cyclecollector, so we make sure that ~jsdService forces ::Off to act as if it is JSGC_END (after ensuring that there are no callbacks available). * a pure javascript (xpcom component, not DOM hosted!) version of a jsdService consumer means that jsdService will need to talk to the CycleCollector eventually (this is another bug for the future).
2008-03-11 00:13:48 +00:00
|
|
|
|
2011-01-31 23:00:52 +00:00
|
|
|
while (gDeadScripts)
|
2013-06-12 21:17:55 +00:00
|
|
|
jsds_NotifyPendingDeadScripts (JS_GetRuntime(nsContentUtils::GetSafeJSContext()));
|
2001-10-30 13:41:32 +00:00
|
|
|
}
|
2001-07-03 22:19:04 +00:00
|
|
|
|
2011-01-21 06:10:54 +00:00
|
|
|
DeactivateDebugger();
|
2001-10-30 13:41:32 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2003-10-10 04:31:15 +00:00
|
|
|
printf ("+++ JavaScript debugging hooks removed.\n");
|
2001-10-30 13:41:32 +00:00
|
|
|
#endif
|
|
|
|
|
2010-10-30 16:13:02 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2011-11-09 21:11:39 +00:00
|
|
|
xpc->SetDebugModeWhenPossible(false, true);
|
2010-10-30 16:13:02 +00:00
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-07 00:59:55 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::GetPauseDepth(uint32_t *_rval)
|
2002-02-07 00:59:55 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_rval);
|
|
|
|
*_rval = mPauseLevel;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::Pause(uint32_t *_rval)
|
2011-11-09 21:11:39 +00:00
|
|
|
{
|
|
|
|
return DoPause(_rval, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::DoPause(uint32_t *_rval, bool internalCall)
|
2001-10-30 13:41:32 +00:00
|
|
|
{
|
2006-06-20 15:54:44 +00:00
|
|
|
if (!mCx)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
if (++mPauseLevel == 1) {
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetErrorReporter (mCx, nullptr, nullptr);
|
2001-10-30 13:41:32 +00:00
|
|
|
JSD_ClearThrowHook (mCx);
|
|
|
|
JSD_ClearInterruptHook (mCx);
|
|
|
|
JSD_ClearDebuggerHook (mCx);
|
|
|
|
JSD_ClearDebugBreakHook (mCx);
|
|
|
|
JSD_ClearTopLevelHook (mCx);
|
|
|
|
JSD_ClearFunctionHook (mCx);
|
2009-12-12 21:35:04 +00:00
|
|
|
JSD_DebuggerPause (mCx);
|
2011-11-09 21:11:39 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!internalCall) {
|
|
|
|
rv = xpc->SetDebugModeWhenPossible(false, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2001-10-30 13:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_rval)
|
|
|
|
*_rval = mPauseLevel;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::UnPause(uint32_t *_rval)
|
2011-11-09 21:11:39 +00:00
|
|
|
{
|
|
|
|
return DoUnPause(_rval, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::DoUnPause(uint32_t *_rval, bool internalCall)
|
2001-10-30 13:41:32 +00:00
|
|
|
{
|
2006-06-20 15:54:44 +00:00
|
|
|
if (!mCx)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
if (mPauseLevel == 0)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2002-02-14 07:57:30 +00:00
|
|
|
/* check mOn before we muck with this stuff, it's possible the debugger
|
|
|
|
* was turned off while we were paused.
|
|
|
|
*/
|
|
|
|
if (--mPauseLevel == 0 && mOn) {
|
2009-12-12 21:35:04 +00:00
|
|
|
JSD_DebuggerUnpause (mCx);
|
2002-01-29 05:56:02 +00:00
|
|
|
if (mErrorHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetErrorReporter (mCx, jsds_ErrorHookProc, nullptr);
|
2001-10-30 13:41:32 +00:00
|
|
|
if (mThrowHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetThrowHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2001-10-30 13:41:32 +00:00
|
|
|
if (mInterruptHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetInterruptHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2001-10-30 13:41:32 +00:00
|
|
|
if (mDebuggerHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetDebuggerHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2002-01-29 05:56:02 +00:00
|
|
|
if (mDebugHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetDebugBreakHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2001-10-30 13:41:32 +00:00
|
|
|
if (mTopLevelHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetTopLevelHook (mCx, jsds_CallHookProc, nullptr);
|
2001-10-30 13:41:32 +00:00
|
|
|
else
|
|
|
|
JSD_ClearTopLevelHook (mCx);
|
|
|
|
if (mFunctionHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetFunctionHook (mCx, jsds_CallHookProc, nullptr);
|
2001-10-30 13:41:32 +00:00
|
|
|
else
|
|
|
|
JSD_ClearFunctionHook (mCx);
|
2011-11-09 21:11:39 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!internalCall) {
|
|
|
|
rv = xpc->SetDebugModeWhenPossible(true, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2001-10-30 13:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_rval)
|
|
|
|
*_rval = mPauseLevel;
|
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-29 08:32:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::EnumerateContexts (jsdIContextEnumerator *enumerator)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_CONTEXT;
|
|
|
|
|
|
|
|
if (!enumerator)
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-09-19 19:26:36 +00:00
|
|
|
JSContext *iter = nullptr;
|
2002-01-29 08:32:23 +00:00
|
|
|
JSContext *cx;
|
|
|
|
|
|
|
|
while ((cx = JS_ContextIterator (mRuntime, &iter)))
|
|
|
|
{
|
|
|
|
nsCOMPtr<jsdIContext> jsdicx =
|
2013-07-10 09:56:21 +00:00
|
|
|
dont_AddRef(jsdContext::FromPtr(mCx, cx));
|
2002-01-29 08:32:23 +00:00
|
|
|
if (jsdicx)
|
|
|
|
{
|
|
|
|
if (NS_FAILED(enumerator->EnumerateContext(jsdicx)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
NS_IMETHODIMP
|
2001-05-21 07:18:10 +00:00
|
|
|
jsdService::EnumerateScripts (jsdIScriptEnumerator *enumerator)
|
|
|
|
{
|
2001-06-28 07:46:36 +00:00
|
|
|
ASSERT_VALID_CONTEXT;
|
|
|
|
|
2001-05-21 07:18:10 +00:00
|
|
|
JSDScript *script;
|
2013-09-19 19:26:36 +00:00
|
|
|
JSDScript *iter = nullptr;
|
2001-05-21 07:18:10 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
JSD_LockScriptSubsystem(mCx);
|
2002-01-29 08:32:23 +00:00
|
|
|
while((script = JSD_IterateScripts(mCx, &iter))) {
|
2002-01-12 00:56:35 +00:00
|
|
|
nsCOMPtr<jsdIScript> jsdis =
|
2013-07-10 09:56:21 +00:00
|
|
|
dont_AddRef(jsdScript::FromPtr(mCx, script));
|
2002-01-12 00:56:35 +00:00
|
|
|
rv = enumerator->EnumerateScript (jsdis);
|
2001-10-30 13:41:32 +00:00
|
|
|
if (NS_FAILED(rv))
|
2001-05-21 07:18:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
JSD_UnlockScriptSubsystem(mCx);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-08-03 05:14:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::GC (void)
|
|
|
|
{
|
|
|
|
ASSERT_VALID_CONTEXT;
|
2012-03-28 10:13:30 +00:00
|
|
|
JSRuntime *rt = JSD_GetJSRuntime (mCx);
|
|
|
|
JS_GC(rt);
|
2001-08-03 05:14:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-02-27 09:24:14 +00:00
|
|
|
|
2007-04-25 13:43:18 +00:00
|
|
|
NS_IMETHODIMP
|
2009-01-08 04:42:15 +00:00
|
|
|
jsdService::DumpHeap(const nsACString &fileName)
|
2007-04-25 13:43:18 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_CONTEXT;
|
|
|
|
#ifndef DEBUG
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#else
|
|
|
|
nsresult rv = NS_OK;
|
2009-01-08 04:42:15 +00:00
|
|
|
FILE *file = !fileName.IsEmpty() ? fopen(PromiseFlatCString(fileName).get(), "w") : stdout;
|
2007-04-25 13:43:18 +00:00
|
|
|
if (!file) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
} else {
|
2013-09-19 19:26:36 +00:00
|
|
|
if (!JS_DumpHeap(JS_GetRuntime(nsContentUtils::GetSafeJSContext()),
|
|
|
|
file, nullptr, JSTRACE_OBJECT, nullptr, (size_t)-1, nullptr))
|
2007-04-25 13:43:18 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
if (file != stdout)
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-02-27 09:24:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::ClearProfileData ()
|
|
|
|
{
|
|
|
|
ASSERT_VALID_CONTEXT;
|
|
|
|
JSD_ClearAllProfileData (mCx);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-08-03 05:14:21 +00:00
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::InsertFilter (jsdIFilter *filter, jsdIFilter *after)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER (filter);
|
|
|
|
if (jsds_FindFilter (filter))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2009-03-12 11:31:34 +00:00
|
|
|
FilterRecord *rec = PR_NEWZAP (FilterRecord);
|
2004-03-26 07:27:05 +00:00
|
|
|
if (!rec)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
|
|
|
if (!jsds_SyncFilter (rec, filter)) {
|
|
|
|
PR_Free (rec);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gFilters) {
|
|
|
|
if (!after) {
|
|
|
|
/* insert at head of list */
|
|
|
|
PR_INSERT_LINK(&rec->links, &gFilters->links);
|
|
|
|
gFilters = rec;
|
|
|
|
} else {
|
|
|
|
/* insert somewhere in the list */
|
|
|
|
FilterRecord *afterRecord = jsds_FindFilter (after);
|
|
|
|
if (!afterRecord) {
|
|
|
|
jsds_FreeFilter(rec);
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
PR_INSERT_AFTER(&rec->links, &afterRecord->links);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (after) {
|
|
|
|
/* user asked to insert into the middle of an empty list, bail. */
|
|
|
|
jsds_FreeFilter(rec);
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
PR_INIT_CLIST(&rec->links);
|
|
|
|
gFilters = rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::AppendFilter (jsdIFilter *filter)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER (filter);
|
|
|
|
if (jsds_FindFilter (filter))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2009-03-12 11:31:34 +00:00
|
|
|
FilterRecord *rec = PR_NEWZAP (FilterRecord);
|
2001-10-30 13:41:32 +00:00
|
|
|
|
|
|
|
if (!jsds_SyncFilter (rec, filter)) {
|
|
|
|
PR_Free (rec);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gFilters) {
|
|
|
|
PR_INSERT_BEFORE(&rec->links, &gFilters->links);
|
|
|
|
} else {
|
|
|
|
PR_INIT_CLIST(&rec->links);
|
|
|
|
gFilters = rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::RemoveFilter (jsdIFilter *filter)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(filter);
|
|
|
|
FilterRecord *rec = jsds_FindFilter (filter);
|
|
|
|
if (!rec)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
if (gFilters == rec) {
|
2007-07-08 07:08:04 +00:00
|
|
|
gFilters = reinterpret_cast<FilterRecord *>
|
|
|
|
(PR_NEXT_LINK(&rec->links));
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
/* If we're the only filter left, null out the list head. */
|
|
|
|
if (gFilters == rec)
|
2012-07-30 14:20:58 +00:00
|
|
|
gFilters = nullptr;
|
Bug 151803, "Debugger is leaking JSDValues", r=peterv, sr=jst
Stop caching jsdIValues, it doesn't seem to be worth the lookup cost. This has the side effect of plugging the leak, as described in the bug.
also...
* Convert a few raw pointers to nsCOMPtrs
* Fix a bug where removing the last filter did not null out the list head,
causing a crash the next time filters were used.
* Track live jsdStackFrames, so we can invalidate them all when execution
continues. Without this, only the top frame is properly invalidated, and any
other frame accessed after a continue will do Bad Things.
* Add some debugging prints to GetInitAtService, which seems to be failing at
random times.
2002-06-19 21:56:23 +00:00
|
|
|
}
|
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
|
|
|
|
PR_REMOVE_LINK(&rec->links);
|
|
|
|
jsds_FreeFilter (rec);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::SwapFilters (jsdIFilter *filter_a, jsdIFilter *filter_b)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(filter_a);
|
|
|
|
NS_ENSURE_ARG_POINTER(filter_b);
|
|
|
|
|
|
|
|
FilterRecord *rec_a = jsds_FindFilter (filter_a);
|
|
|
|
if (!rec_a)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
if (filter_a == filter_b) {
|
|
|
|
/* just a refresh */
|
|
|
|
if (!jsds_SyncFilter (rec_a, filter_a))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterRecord *rec_b = jsds_FindFilter (filter_b);
|
|
|
|
if (!rec_b) {
|
|
|
|
/* filter_b is not in the list, replace filter_a with filter_b. */
|
|
|
|
if (!jsds_SyncFilter (rec_a, filter_b))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
} else {
|
|
|
|
/* both filters are in the list, swap. */
|
|
|
|
if (!jsds_SyncFilter (rec_a, filter_b))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (!jsds_SyncFilter (rec_b, filter_a))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::EnumerateFilters (jsdIFilterEnumerator *enumerator)
|
|
|
|
{
|
|
|
|
if (!gFilters)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
FilterRecord *current = gFilters;
|
|
|
|
do {
|
|
|
|
jsds_SyncFilter (current, current->filterObject);
|
|
|
|
/* SyncFilter failure would be bad, but what would we do about it? */
|
|
|
|
if (enumerator) {
|
|
|
|
nsresult rv = enumerator->EnumerateFilter (current->filterObject);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
2007-07-08 07:08:04 +00:00
|
|
|
current = reinterpret_cast<FilterRecord *>
|
|
|
|
(PR_NEXT_LINK (¤t->links));
|
2001-10-30 13:41:32 +00:00
|
|
|
} while (current != gFilters);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::RefreshFilters ()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return EnumerateFilters(nullptr);
|
2001-10-30 13:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::ClearFilters ()
|
|
|
|
{
|
|
|
|
if (!gFilters)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
FilterRecord *current = reinterpret_cast<FilterRecord *>
|
|
|
|
(PR_NEXT_LINK (&gFilters->links));
|
2001-10-30 13:41:32 +00:00
|
|
|
do {
|
2007-07-08 07:08:04 +00:00
|
|
|
FilterRecord *next = reinterpret_cast<FilterRecord *>
|
|
|
|
(PR_NEXT_LINK (¤t->links));
|
2001-10-30 13:41:32 +00:00
|
|
|
PR_REMOVE_AND_INIT_LINK(¤t->links);
|
|
|
|
jsds_FreeFilter(current);
|
|
|
|
current = next;
|
|
|
|
} while (current != gFilters);
|
|
|
|
|
|
|
|
jsds_FreeFilter(current);
|
2012-07-30 14:20:58 +00:00
|
|
|
gFilters = nullptr;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-21 07:18:10 +00:00
|
|
|
NS_IMETHODIMP
|
2001-04-25 18:20:47 +00:00
|
|
|
jsdService::ClearAllBreakpoints (void)
|
|
|
|
{
|
2001-06-28 07:46:36 +00:00
|
|
|
ASSERT_VALID_CONTEXT;
|
|
|
|
|
2001-05-13 21:08:06 +00:00
|
|
|
JSD_LockScriptSubsystem(mCx);
|
2001-04-25 18:20:47 +00:00
|
|
|
JSD_ClearAllExecutionHooks (mCx);
|
2001-05-13 21:08:06 +00:00
|
|
|
JSD_UnlockScriptSubsystem(mCx);
|
2001-04-25 18:20:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-07 00:59:55 +00:00
|
|
|
NS_IMETHODIMP
|
2014-01-09 17:39:36 +00:00
|
|
|
jsdService::WrapValue(JS::Handle<JS::Value> value, jsdIValue **_rval)
|
2002-02-07 00:59:55 +00:00
|
|
|
{
|
|
|
|
ASSERT_VALID_CONTEXT;
|
2009-10-17 14:40:44 +00:00
|
|
|
JSDValue *jsdv = JSD_NewValue(mCx, value);
|
2002-02-07 00:59:55 +00:00
|
|
|
if (!jsdv)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::EnterNestedEventLoop (jsdINestCallback *callback, uint32_t *_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
// Nesting event queues is a thing of the past. Now, we just spin the
|
|
|
|
// current event loop.
|
2013-04-18 15:36:05 +00:00
|
|
|
nsresult rv = NS_OK;
|
2013-12-12 01:51:58 +00:00
|
|
|
AutoSystemCaller asc;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t nestLevel = ++mNestedLoopLevel;
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
|
|
|
|
|
2013-04-18 15:36:05 +00:00
|
|
|
if (callback) {
|
|
|
|
DoPause(nullptr, true);
|
|
|
|
rv = callback->OnNest();
|
|
|
|
DoUnPause(nullptr, true);
|
|
|
|
}
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2013-04-18 15:36:05 +00:00
|
|
|
while (NS_SUCCEEDED(rv) && mNestedLoopLevel >= nestLevel) {
|
|
|
|
if (!NS_ProcessNextEvent(thread))
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
2001-04-20 03:54:05 +00:00
|
|
|
}
|
2013-04-18 15:36:05 +00:00
|
|
|
|
2001-04-20 03:54:05 +00:00
|
|
|
NS_ASSERTION (mNestedLoopLevel <= nestLevel,
|
|
|
|
"nested event didn't unwind properly");
|
|
|
|
if (mNestedLoopLevel == nestLevel)
|
|
|
|
--mNestedLoopLevel;
|
|
|
|
|
|
|
|
*_rval = mNestedLoopLevel;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdService::ExitNestedEventLoop (uint32_t *_rval)
|
2001-04-20 03:54:05 +00:00
|
|
|
{
|
|
|
|
if (mNestedLoopLevel > 0)
|
|
|
|
--mNestedLoopLevel;
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*_rval = mNestedLoopLevel;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
/* hook attribute get/set functions */
|
|
|
|
|
2002-01-29 05:56:02 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::SetErrorHook (jsdIErrorHook *aHook)
|
|
|
|
{
|
|
|
|
mErrorHook = aHook;
|
|
|
|
|
|
|
|
/* if the debugger isn't initialized, that's all we can do for now. The
|
2010-10-30 16:13:02 +00:00
|
|
|
* ActivateDebugger() method will do the rest when the coast is clear.
|
2002-01-29 05:56:02 +00:00
|
|
|
*/
|
|
|
|
if (!mCx || mPauseLevel)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (aHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetErrorReporter (mCx, jsds_ErrorHookProc, nullptr);
|
2002-01-29 05:56:02 +00:00
|
|
|
else
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetErrorReporter (mCx, nullptr, nullptr);
|
2002-01-29 05:56:02 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::GetErrorHook (jsdIErrorHook **aHook)
|
|
|
|
{
|
|
|
|
*aHook = mErrorHook;
|
|
|
|
NS_IF_ADDREF(*aHook);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-25 18:20:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::SetBreakpointHook (jsdIExecutionHook *aHook)
|
|
|
|
{
|
|
|
|
mBreakpointHook = aHook;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::GetBreakpointHook (jsdIExecutionHook **aHook)
|
|
|
|
{
|
|
|
|
*aHook = mBreakpointHook;
|
|
|
|
NS_IF_ADDREF(*aHook);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-29 05:56:02 +00:00
|
|
|
jsdService::SetDebugHook (jsdIExecutionHook *aHook)
|
2001-04-17 08:50:41 +00:00
|
|
|
{
|
2002-01-29 05:56:02 +00:00
|
|
|
mDebugHook = aHook;
|
2001-06-28 07:46:36 +00:00
|
|
|
|
|
|
|
/* if the debugger isn't initialized, that's all we can do for now. The
|
2010-10-30 16:13:02 +00:00
|
|
|
* ActivateDebugger() method will do the rest when the coast is clear.
|
2001-06-28 07:46:36 +00:00
|
|
|
*/
|
2001-10-30 13:41:32 +00:00
|
|
|
if (!mCx || mPauseLevel)
|
2001-06-28 07:46:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
if (aHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetDebugBreakHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2001-04-17 08:50:41 +00:00
|
|
|
else
|
2001-04-25 18:20:47 +00:00
|
|
|
JSD_ClearDebugBreakHook (mCx);
|
2001-04-17 08:50:41 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-01-29 05:56:02 +00:00
|
|
|
jsdService::GetDebugHook (jsdIExecutionHook **aHook)
|
2001-04-17 08:50:41 +00:00
|
|
|
{
|
2002-01-29 05:56:02 +00:00
|
|
|
*aHook = mDebugHook;
|
2001-04-17 08:50:41 +00:00
|
|
|
NS_IF_ADDREF(*aHook);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::SetDebuggerHook (jsdIExecutionHook *aHook)
|
|
|
|
{
|
|
|
|
mDebuggerHook = aHook;
|
2001-06-28 07:46:36 +00:00
|
|
|
|
|
|
|
/* if the debugger isn't initialized, that's all we can do for now. The
|
2010-10-30 16:13:02 +00:00
|
|
|
* ActivateDebugger() method will do the rest when the coast is clear.
|
2001-06-28 07:46:36 +00:00
|
|
|
*/
|
2001-10-30 13:41:32 +00:00
|
|
|
if (!mCx || mPauseLevel)
|
2001-06-28 07:46:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
if (aHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetDebuggerHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2001-04-17 08:50:41 +00:00
|
|
|
else
|
2001-04-25 18:20:47 +00:00
|
|
|
JSD_ClearDebuggerHook (mCx);
|
2001-04-17 08:50:41 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::GetDebuggerHook (jsdIExecutionHook **aHook)
|
|
|
|
{
|
|
|
|
*aHook = mDebuggerHook;
|
|
|
|
NS_IF_ADDREF(*aHook);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::SetInterruptHook (jsdIExecutionHook *aHook)
|
|
|
|
{
|
|
|
|
mInterruptHook = aHook;
|
2001-06-28 07:46:36 +00:00
|
|
|
|
|
|
|
/* if the debugger isn't initialized, that's all we can do for now. The
|
2010-10-30 16:13:02 +00:00
|
|
|
* ActivateDebugger() method will do the rest when the coast is clear.
|
2001-06-28 07:46:36 +00:00
|
|
|
*/
|
2001-10-30 13:41:32 +00:00
|
|
|
if (!mCx || mPauseLevel)
|
2001-06-28 07:46:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2001-04-17 08:50:41 +00:00
|
|
|
if (aHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetInterruptHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2001-04-17 08:50:41 +00:00
|
|
|
else
|
2001-04-25 18:20:47 +00:00
|
|
|
JSD_ClearInterruptHook (mCx);
|
2001-04-17 08:50:41 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::GetInterruptHook (jsdIExecutionHook **aHook)
|
|
|
|
{
|
|
|
|
*aHook = mInterruptHook;
|
|
|
|
NS_IF_ADDREF(*aHook);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::SetScriptHook (jsdIScriptHook *aHook)
|
|
|
|
{
|
|
|
|
mScriptHook = aHook;
|
2001-06-28 07:46:36 +00:00
|
|
|
|
|
|
|
/* if the debugger isn't initialized, that's all we can do for now. The
|
2010-10-30 16:13:02 +00:00
|
|
|
* ActivateDebugger() method will do the rest when the coast is clear.
|
2001-06-28 07:46:36 +00:00
|
|
|
*/
|
2001-10-30 13:41:32 +00:00
|
|
|
if (!mCx || mPauseLevel)
|
2001-06-28 07:46:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2001-04-21 07:21:27 +00:00
|
|
|
if (aHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetScriptHook (mCx, jsds_ScriptHookProc, nullptr);
|
2002-01-12 00:56:35 +00:00
|
|
|
/* we can't unset it if !aHook, because we still need to see script
|
|
|
|
* deletes in order to Release the jsdIScripts held in JSDScript
|
|
|
|
* private data. */
|
2001-04-17 08:50:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::GetScriptHook (jsdIScriptHook **aHook)
|
|
|
|
{
|
|
|
|
*aHook = mScriptHook;
|
|
|
|
NS_IF_ADDREF(*aHook);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-04 22:14:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::SetThrowHook (jsdIExecutionHook *aHook)
|
|
|
|
{
|
|
|
|
mThrowHook = aHook;
|
2001-06-28 07:46:36 +00:00
|
|
|
|
|
|
|
/* if the debugger isn't initialized, that's all we can do for now. The
|
2010-10-30 16:13:02 +00:00
|
|
|
* ActivateDebugger() method will do the rest when the coast is clear.
|
2001-06-28 07:46:36 +00:00
|
|
|
*/
|
2001-10-30 13:41:32 +00:00
|
|
|
if (!mCx || mPauseLevel)
|
2001-06-28 07:46:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2001-05-04 22:14:04 +00:00
|
|
|
if (aHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetThrowHook (mCx, jsds_ExecutionHookProc, nullptr);
|
2001-05-04 22:14:04 +00:00
|
|
|
else
|
|
|
|
JSD_ClearThrowHook (mCx);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::GetThrowHook (jsdIExecutionHook **aHook)
|
|
|
|
{
|
|
|
|
*aHook = mThrowHook;
|
|
|
|
NS_IF_ADDREF(*aHook);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-01 18:03:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::SetTopLevelHook (jsdICallHook *aHook)
|
|
|
|
{
|
|
|
|
mTopLevelHook = aHook;
|
|
|
|
|
|
|
|
/* if the debugger isn't initialized, that's all we can do for now. The
|
2010-10-30 16:13:02 +00:00
|
|
|
* ActivateDebugger() method will do the rest when the coast is clear.
|
2001-09-01 18:03:53 +00:00
|
|
|
*/
|
2001-10-30 13:41:32 +00:00
|
|
|
if (!mCx || mPauseLevel)
|
2001-09-01 18:03:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (aHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetTopLevelHook (mCx, jsds_CallHookProc, nullptr);
|
2001-09-01 18:03:53 +00:00
|
|
|
else
|
2001-10-30 13:41:32 +00:00
|
|
|
JSD_ClearTopLevelHook (mCx);
|
2001-09-01 18:03:53 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::GetTopLevelHook (jsdICallHook **aHook)
|
|
|
|
{
|
|
|
|
*aHook = mTopLevelHook;
|
|
|
|
NS_IF_ADDREF(*aHook);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::SetFunctionHook (jsdICallHook *aHook)
|
|
|
|
{
|
|
|
|
mFunctionHook = aHook;
|
|
|
|
|
|
|
|
/* if the debugger isn't initialized, that's all we can do for now. The
|
2010-10-30 16:13:02 +00:00
|
|
|
* ActivateDebugger() method will do the rest when the coast is clear.
|
2001-09-01 18:03:53 +00:00
|
|
|
*/
|
2001-10-30 13:41:32 +00:00
|
|
|
if (!mCx || mPauseLevel)
|
2001-09-01 18:03:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (aHook)
|
2013-09-19 19:26:36 +00:00
|
|
|
JSD_SetFunctionHook (mCx, jsds_CallHookProc, nullptr);
|
2001-09-01 18:03:53 +00:00
|
|
|
else
|
2001-10-30 13:41:32 +00:00
|
|
|
JSD_ClearFunctionHook (mCx);
|
2001-09-01 18:03:53 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdService::GetFunctionHook (jsdICallHook **aHook)
|
|
|
|
{
|
|
|
|
*aHook = mFunctionHook;
|
|
|
|
NS_IF_ADDREF(*aHook);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-11-06 12:59:21 +00:00
|
|
|
/* virtual */
|
|
|
|
jsdService::~jsdService()
|
|
|
|
{
|
|
|
|
ClearFilters();
|
2012-07-30 14:20:58 +00:00
|
|
|
mErrorHook = nullptr;
|
|
|
|
mBreakpointHook = nullptr;
|
|
|
|
mDebugHook = nullptr;
|
|
|
|
mDebuggerHook = nullptr;
|
|
|
|
mInterruptHook = nullptr;
|
|
|
|
mScriptHook = nullptr;
|
|
|
|
mThrowHook = nullptr;
|
|
|
|
mTopLevelHook = nullptr;
|
|
|
|
mFunctionHook = nullptr;
|
2002-11-06 12:59:21 +00:00
|
|
|
Off();
|
2012-07-30 14:20:58 +00:00
|
|
|
gJsds = nullptr;
|
2002-11-06 12:59:21 +00:00
|
|
|
}
|
|
|
|
|
2001-04-25 21:54:59 +00:00
|
|
|
jsdService *
|
|
|
|
jsdService::GetService ()
|
|
|
|
{
|
|
|
|
if (!gJsds)
|
|
|
|
gJsds = new jsdService();
|
|
|
|
|
|
|
|
NS_IF_ADDREF(gJsds);
|
|
|
|
return gJsds;
|
|
|
|
}
|
|
|
|
|
2003-09-07 22:37:27 +00:00
|
|
|
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(jsdService, jsdService::GetService)
|
2001-04-17 08:50:41 +00:00
|
|
|
|
2001-10-30 13:41:32 +00:00
|
|
|
/* app-start observer. turns on the debugger at app-start. this is inserted
|
|
|
|
* and/or removed from the app-start category by the jsdService::initAtStartup
|
|
|
|
* property.
|
|
|
|
*/
|
2012-06-13 03:45:08 +00:00
|
|
|
class jsdASObserver MOZ_FINAL : public nsIObserver
|
2001-10-30 13:41:32 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 02:23:32 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2001-10-30 13:41:32 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2003-08-14 22:49:09 +00:00
|
|
|
jsdASObserver () {}
|
2001-10-30 13:41:32 +00:00
|
|
|
};
|
|
|
|
|
2013-07-19 02:23:32 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(jsdASObserver, nsIObserver)
|
2001-10-30 13:41:32 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdASObserver::Observe (nsISupports *aSubject, const char *aTopic,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t *aData)
|
2001-10-30 13:41:32 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2002-11-06 12:59:21 +00:00
|
|
|
// Hmm. Why is the app-startup observer called multiple times?
|
|
|
|
//NS_ASSERTION(!gJsds, "app startup observer called twice");
|
|
|
|
nsCOMPtr<jsdIDebuggerService> jsds = do_GetService(jsdServiceCtrID, &rv);
|
2007-07-01 19:25:10 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-11-06 12:59:21 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool on;
|
2001-10-30 13:41:32 +00:00
|
|
|
rv = jsds->GetIsOn(&on);
|
|
|
|
if (NS_FAILED(rv) || on)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIJSRuntimeService> rts = do_GetService(NS_JSRT_CTRID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
JSRuntime *rt;
|
|
|
|
rts->GetRuntime (&rt);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2010-10-30 16:13:02 +00:00
|
|
|
rv = jsds->ActivateDebugger(rt);
|
2003-08-14 22:49:09 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2010-07-24 02:33:49 +00:00
|
|
|
return NS_OK;
|
2001-10-30 13:41:32 +00:00
|
|
|
}
|
|
|
|
|
2003-09-07 22:37:27 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(jsdASObserver)
|
2010-06-10 18:11:40 +00:00
|
|
|
NS_DEFINE_NAMED_CID(JSDSERVICE_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(JSDASO_CID);
|
|
|
|
|
|
|
|
static const mozilla::Module::CIDEntry kJSDCIDs[] = {
|
2013-09-19 19:26:36 +00:00
|
|
|
{ &kJSDSERVICE_CID, false, nullptr, jsdServiceConstructor },
|
|
|
|
{ &kJSDASO_CID, false, nullptr, jsdASObserverConstructor },
|
|
|
|
{ nullptr }
|
2010-06-10 18:11:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const mozilla::Module::ContractIDEntry kJSDContracts[] = {
|
|
|
|
{ jsdServiceCtrID, &kJSDSERVICE_CID },
|
|
|
|
{ jsdARObserverCtrID, &kJSDASO_CID },
|
2013-09-19 19:26:36 +00:00
|
|
|
{ nullptr }
|
2010-06-10 18:11:40 +00:00
|
|
|
};
|
2001-10-30 13:41:32 +00:00
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
static const mozilla::Module kJSDModule = {
|
|
|
|
mozilla::Module::kVersion,
|
|
|
|
kJSDCIDs,
|
|
|
|
kJSDContracts
|
2001-04-17 08:50:41 +00:00
|
|
|
};
|
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
NSMODULE_DEFN(JavaScript_Debugger) = &kJSDModule;
|
2001-05-04 22:14:04 +00:00
|
|
|
|
2013-04-04 09:27:37 +00:00
|
|
|
void
|
|
|
|
global_finalize(JSFreeOp *aFop, JSObject *aObj)
|
|
|
|
{
|
|
|
|
nsIScriptObjectPrincipal *sop =
|
|
|
|
static_cast<nsIScriptObjectPrincipal *>(js::GetObjectPrivate(aObj));
|
|
|
|
MOZ_ASSERT(sop);
|
|
|
|
static_cast<SandboxPrivate *>(sop)->ForgetGlobalObject();
|
|
|
|
NS_IF_RELEASE(sop);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *
|
2013-09-11 12:49:05 +00:00
|
|
|
CreateJSDGlobal(JSContext *aCx, const JSClass *aClasp)
|
2013-04-04 09:27:37 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPrincipal> nullPrin = do_CreateInstance("@mozilla.org/nullprincipal;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
|
|
|
|
JSPrincipals *jsPrin = nsJSPrincipals::get(nullPrin);
|
2013-08-02 01:38:47 +00:00
|
|
|
JS::RootedObject global(aCx, JS_NewGlobalObject(aCx, aClasp, jsPrin, JS::DontFireOnNewGlobalHook));
|
2013-04-04 09:27:37 +00:00
|
|
|
NS_ENSURE_TRUE(global, nullptr);
|
|
|
|
|
|
|
|
// We have created a new global let's attach a private to it
|
|
|
|
// that implements nsIGlobalObject.
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> sbp =
|
|
|
|
new SandboxPrivate(nullPrin, global);
|
|
|
|
JS_SetPrivate(global, sbp.forget().get());
|
|
|
|
|
2013-08-02 01:38:47 +00:00
|
|
|
JS_FireOnNewGlobalObject(aCx, global);
|
|
|
|
|
2013-04-04 09:27:37 +00:00
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
2001-05-21 06:00:12 +00:00
|
|
|
/********************************************************************************
|
|
|
|
********************************************************************************
|
|
|
|
* graveyard
|
|
|
|
*/
|
2001-05-04 22:14:04 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Thread States */
|
2013-07-19 02:23:32 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(jsdThreadState, jsdIThreadState);
|
2001-05-04 22:14:04 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdThreadState::GetJSDContext(JSDContext **_rval)
|
|
|
|
{
|
|
|
|
*_rval = mCx;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdThreadState::GetJSDThreadState(JSDThreadState **_rval)
|
|
|
|
{
|
|
|
|
*_rval = mThreadState;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
jsdThreadState::GetFrameCount (uint32_t *_rval)
|
2001-05-04 22:14:04 +00:00
|
|
|
{
|
|
|
|
*_rval = JSD_GetCountOfStackFrames (mCx, mThreadState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdThreadState::GetTopFrame (jsdIStackFrame **_rval)
|
|
|
|
{
|
|
|
|
JSDStackFrameInfo *sfi = JSD_GetStackFrame (mCx, mThreadState);
|
|
|
|
|
|
|
|
*_rval = jsdStackFrame::FromPtr (mCx, mThreadState, sfi);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdThreadState::GetPendingException(jsdIValue **_rval)
|
|
|
|
{
|
|
|
|
JSDValue *jsdv = JSD_GetException (mCx, mThreadState);
|
|
|
|
|
|
|
|
*_rval = jsdValue::FromPtr (mCx, jsdv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
jsdThreadState::SetPendingException(jsdIValue *aException)
|
|
|
|
{
|
|
|
|
JSDValue *jsdv;
|
|
|
|
|
|
|
|
nsresult rv = aException->GetJSDValue (&jsdv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (!JSD_SetException (mCx, mThreadState, jsdv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|