2013-04-17 00:47:10 +04: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:
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1998-11-05 11:57:24 +03:00
|
|
|
* JavaScript Debugging support - Script support
|
|
|
|
*/
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
#include "jsd.h"
|
2010-12-24 00:41:57 +03:00
|
|
|
#include "jsfriendapi.h"
|
2013-06-13 01:17:55 +04:00
|
|
|
#include "nsCxPusher.h"
|
|
|
|
|
|
|
|
using mozilla::AutoSafeJSContext;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/* Comment this out to disable (NT specific) dumping as we go */
|
|
|
|
/*
|
|
|
|
** #ifdef DEBUG
|
|
|
|
** #define JSD_DUMP 1
|
|
|
|
** #endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NOT_SET_YET -1
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1998-11-05 11:57:24 +03:00
|
|
|
void JSD_ASSERT_VALID_SCRIPT(JSDScript* jsdscript)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(jsdscript);
|
|
|
|
MOZ_ASSERT(jsdscript->script);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
1998-11-05 11:57:24 +03:00
|
|
|
void JSD_ASSERT_VALID_EXEC_HOOK(JSDExecHook* jsdhook)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(jsdhook);
|
|
|
|
MOZ_ASSERT(jsdhook->hook);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static JSDScript*
|
1998-11-05 11:57:24 +03:00
|
|
|
_newJSDScript(JSDContext* jsdc,
|
1998-03-28 05:44:41 +03:00
|
|
|
JSContext *cx,
|
2013-05-12 17:13:22 +04:00
|
|
|
JSScript *script_)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2013-05-12 17:13:22 +04:00
|
|
|
JS::RootedScript script(cx, script_);
|
2013-05-06 21:17:38 +04:00
|
|
|
if ( JS_GetScriptIsSelfHosted(script) )
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
2013-05-06 21:17:38 +04:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
JSDScript* jsdscript;
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned lineno;
|
1998-11-05 11:57:24 +03:00
|
|
|
const char* raw_filename;
|
|
|
|
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/* these are inlined javascript: urls and we can't handle them now */
|
2012-02-29 03:11:11 +04:00
|
|
|
lineno = (unsigned) JS_GetScriptBaseLineNumber(cx, script);
|
1998-03-28 05:44:41 +03:00
|
|
|
if( lineno == 0 )
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
jsdscript = (JSDScript*) calloc(1, sizeof(JSDScript));
|
1998-03-28 05:44:41 +03:00
|
|
|
if( ! jsdscript )
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
1998-11-05 11:57:24 +03:00
|
|
|
|
2014-02-25 19:43:14 +04:00
|
|
|
raw_filename = JS_GetScriptFilename(script);
|
2002-02-27 12:24:14 +03:00
|
|
|
|
|
|
|
JS_HashTableAdd(jsdc->scriptsTable, (void *)script, (void *)jsdscript);
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_APPEND_LINK(&jsdscript->links, &jsdc->scripts);
|
1998-03-28 05:44:41 +03:00
|
|
|
jsdscript->jsdc = jsdc;
|
2011-12-08 01:41:27 +04:00
|
|
|
jsdscript->script = script;
|
1998-03-28 05:44:41 +03:00
|
|
|
jsdscript->lineBase = lineno;
|
2012-02-29 03:11:11 +04:00
|
|
|
jsdscript->lineExtent = (unsigned)NOT_SET_YET;
|
2013-09-19 23:26:36 +04:00
|
|
|
jsdscript->data = nullptr;
|
1998-11-05 11:57:24 +03:00
|
|
|
jsdscript->url = (char*) jsd_BuildNormalizedURL(raw_filename);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_INIT_CLIST(&jsdscript->hooks);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
return jsdscript;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-11-05 11:57:24 +03:00
|
|
|
_destroyJSDScript(JSDContext* jsdc,
|
|
|
|
JSDScript* jsdscript)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
1998-11-05 11:57:24 +03:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
/* destroy all hooks */
|
|
|
|
jsd_ClearAllExecutionHooksForScript(jsdc, jsdscript);
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_REMOVE_LINK(&jsdscript->links);
|
|
|
|
if(jsdscript->url)
|
|
|
|
free(jsdscript->url);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2002-02-27 12:24:14 +03:00
|
|
|
if (jsdscript->profileData)
|
|
|
|
free(jsdscript->profileData);
|
|
|
|
|
2007-12-24 02:47:36 +03:00
|
|
|
free(jsdscript);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
#ifdef JSD_DUMP
|
2001-04-14 22:57:00 +04:00
|
|
|
#ifndef XP_WIN
|
|
|
|
void
|
|
|
|
OutputDebugString (char *buf)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s", buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
static void
|
1998-11-05 11:57:24 +03:00
|
|
|
_dumpJSDScript(JSDContext* jsdc, JSDScript* jsdscript, const char* leadingtext)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
|
|
|
const char* name;
|
2010-11-24 19:56:43 +03:00
|
|
|
JSString* fun;
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned base;
|
|
|
|
unsigned extent;
|
1998-03-28 05:44:41 +03:00
|
|
|
char Buf[256];
|
2010-11-24 19:56:43 +03:00
|
|
|
size_t n;
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
name = jsd_GetScriptFilename(jsdc, jsdscript);
|
2011-01-30 00:40:29 +03:00
|
|
|
fun = jsd_GetScriptFunctionId(jsdc, jsdscript);
|
1998-03-28 05:44:41 +03:00
|
|
|
base = jsd_GetScriptBaseLineNumber(jsdc, jsdscript);
|
|
|
|
extent = jsd_GetScriptLineExtent(jsdc, jsdscript);
|
2010-11-24 19:56:43 +03:00
|
|
|
n = size_t(snprintf(Buf, sizeof(Buf), "%sscript=%08X, %s, ",
|
|
|
|
leadingtext, (unsigned) jsdscript->script,
|
|
|
|
name ? name : "no URL"));
|
|
|
|
if (n + 1 < sizeof(Buf)) {
|
|
|
|
if (fun) {
|
|
|
|
n += size_t(snprintf(Buf + n, sizeof(Buf) - n, "%s", "no fun"));
|
|
|
|
} else {
|
2010-12-03 11:24:17 +03:00
|
|
|
n += JS_PutEscapedFlatString(Buf + n, sizeof(Buf) - n,
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT_STRING_IS_FLAT(fun), 0);
|
2010-11-24 19:56:43 +03:00
|
|
|
Buf[sizeof(Buf) - 1] = '\0';
|
|
|
|
}
|
|
|
|
if (n + 1 < sizeof(Buf))
|
|
|
|
snprintf(Buf + n, sizeof(Buf) - n, ", %d-%d\n", base, base + extent - 1);
|
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
OutputDebugString( Buf );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-11-05 11:57:24 +03:00
|
|
|
_dumpJSDScriptList( JSDContext* jsdc )
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2013-09-19 23:26:36 +04:00
|
|
|
JSDScript* iterp = nullptr;
|
|
|
|
JSDScript* jsdscript = nullptr;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
OutputDebugString( "*** JSDScriptDump\n" );
|
2013-09-19 23:26:36 +04:00
|
|
|
while( nullptr != (jsdscript = jsd_IterateScripts(jsdc, &iterp)) )
|
1998-11-05 11:57:24 +03:00
|
|
|
_dumpJSDScript( jsdc, jsdscript, " script: " );
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
#endif /* JSD_DUMP */
|
|
|
|
|
|
|
|
/***************************************************************************/
|
2008-09-07 02:21:43 +04:00
|
|
|
static JSHashNumber
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_hash_script(const void *key)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2010-12-04 13:05:45 +03:00
|
|
|
return ((JSHashNumber)(ptrdiff_t) key) >> 2; /* help lame MSVC1.5 on Win16 */
|
2002-02-27 12:24:14 +03:00
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2008-09-07 02:21:43 +04:00
|
|
|
static void *
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_alloc_script_table(void *priv, size_t size)
|
|
|
|
{
|
|
|
|
return malloc(size);
|
|
|
|
}
|
1998-11-05 11:57:24 +03:00
|
|
|
|
2008-09-07 02:21:43 +04:00
|
|
|
static void
|
2009-06-18 13:12:56 +04:00
|
|
|
jsd_free_script_table(void *priv, void *item, size_t size)
|
2002-02-27 12:24:14 +03:00
|
|
|
{
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2008-09-07 02:21:43 +04:00
|
|
|
static JSHashEntry *
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_alloc_script_entry(void *priv, const void *item)
|
|
|
|
{
|
|
|
|
return (JSHashEntry*) malloc(sizeof(JSHashEntry));
|
|
|
|
}
|
|
|
|
|
2008-09-07 02:21:43 +04:00
|
|
|
static void
|
2012-02-29 03:11:11 +04:00
|
|
|
jsd_free_script_entry(void *priv, JSHashEntry *he, unsigned flag)
|
2002-02-27 12:24:14 +03:00
|
|
|
{
|
|
|
|
if (flag == HT_FREE_ENTRY)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2002-02-27 12:24:14 +03:00
|
|
|
_destroyJSDScript((JSDContext*) priv, (JSDScript*) he->value);
|
|
|
|
free(he);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 19:21:22 +04:00
|
|
|
static const JSHashAllocOps script_alloc_ops = {
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_alloc_script_table, jsd_free_script_table,
|
|
|
|
jsd_alloc_script_entry, jsd_free_script_entry
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef JSD_SCRIPT_HASH_SIZE
|
|
|
|
#define JSD_SCRIPT_HASH_SIZE 1024
|
|
|
|
#endif
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_InitScriptManager(JSDContext* jsdc)
|
|
|
|
{
|
|
|
|
JS_INIT_CLIST(&jsdc->scripts);
|
|
|
|
jsdc->scriptsTable = JS_NewHashTable(JSD_SCRIPT_HASH_SIZE, jsd_hash_script,
|
|
|
|
JS_CompareValues, JS_CompareValues,
|
|
|
|
&script_alloc_ops, (void*) jsdc);
|
2010-12-04 13:05:45 +03:00
|
|
|
return !!jsdc->scriptsTable;
|
2002-02-27 12:24:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsd_DestroyScriptManager(JSDContext* jsdc)
|
|
|
|
{
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
if (jsdc->scriptsTable)
|
|
|
|
JS_HashTableDestroy(jsdc->scriptsTable);
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
}
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
JSDScript*
|
|
|
|
jsd_FindJSDScript( JSDContext* jsdc,
|
|
|
|
JSScript *script )
|
|
|
|
{
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
2002-02-27 12:24:14 +03:00
|
|
|
return (JSDScript*) JS_HashTableLookup(jsdc->scriptsTable, (void *)script);
|
2009-03-14 17:57:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
JSDScript *
|
|
|
|
jsd_FindOrCreateJSDScript(JSDContext *jsdc,
|
|
|
|
JSContext *cx,
|
2013-05-12 17:13:22 +04:00
|
|
|
JSScript *script_,
|
2013-01-25 12:49:29 +04:00
|
|
|
JSAbstractFramePtr frame)
|
2009-03-14 17:57:31 +03:00
|
|
|
{
|
2013-05-12 17:13:22 +04:00
|
|
|
JS::RootedScript script(cx, script_);
|
2009-03-14 17:57:31 +03:00
|
|
|
JSDScript *jsdscript;
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
2009-03-14 17:57:31 +03:00
|
|
|
|
|
|
|
jsdscript = jsd_FindJSDScript(jsdc, script);
|
|
|
|
if (jsdscript)
|
|
|
|
return jsdscript;
|
|
|
|
|
2009-04-03 02:01:15 +04:00
|
|
|
/* Fallback for unknown scripts: create a new script. */
|
2013-01-25 12:49:29 +04:00
|
|
|
if (!frame) {
|
|
|
|
JSBrokenFrameIterator iter(cx);
|
|
|
|
if (!iter.done())
|
|
|
|
frame = iter.abstractFramePtr();
|
|
|
|
}
|
|
|
|
if (frame)
|
2011-12-08 01:41:27 +04:00
|
|
|
jsdscript = _newJSDScript(jsdc, cx, script);
|
2009-03-14 17:57:31 +03:00
|
|
|
|
|
|
|
return jsdscript;
|
|
|
|
}
|
2002-02-27 12:24:14 +03:00
|
|
|
|
|
|
|
JSDProfileData*
|
|
|
|
jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (!script->profileData)
|
|
|
|
script->profileData = (JSDProfileData*)calloc(1, sizeof(JSDProfileData));
|
|
|
|
|
|
|
|
return script->profileData;
|
|
|
|
}
|
1998-11-05 11:57:24 +03:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
uint32_t
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_GetScriptFlags(JSDContext *jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
return script->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 07:54:10 +04:00
|
|
|
jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32_t flags)
|
2002-02-27 12:24:14 +03:00
|
|
|
{
|
|
|
|
script->flags = flags;
|
|
|
|
}
|
|
|
|
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_GetScriptCallCount(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->callCount;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->maxRecurseDepth;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-25 02:19:52 +04:00
|
|
|
double
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->minExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-25 02:19:52 +04:00
|
|
|
double
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->maxExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-25 02:19:52 +04:00
|
|
|
double
|
2002-02-27 12:24:14 +03:00
|
|
|
jsd_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->totalExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-25 02:19:52 +04:00
|
|
|
double
|
2005-08-02 19:53:59 +04:00
|
|
|
jsd_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->minOwnExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-25 02:19:52 +04:00
|
|
|
double
|
2005-08-02 19:53:59 +04:00
|
|
|
jsd_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->maxOwnExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-25 02:19:52 +04:00
|
|
|
double
|
2005-08-02 19:53:59 +04:00
|
|
|
jsd_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->totalOwnExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2002-02-27 12:24:14 +03:00
|
|
|
void
|
|
|
|
jsd_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
1998-11-05 11:57:24 +03:00
|
|
|
{
|
2002-02-27 12:24:14 +03:00
|
|
|
free(script->profileData);
|
2013-09-19 23:26:36 +04:00
|
|
|
script->profileData = nullptr;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
2002-02-27 12:24:14 +03:00
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2002-01-12 03:56:35 +03:00
|
|
|
JSScript *
|
|
|
|
jsd_GetJSScript (JSDContext *jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
return script->script;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSFunction *
|
|
|
|
jsd_GetJSFunction (JSDContext *jsdc, JSDScript *script)
|
|
|
|
{
|
2014-01-09 20:13:25 +04:00
|
|
|
AutoSafeJSContext cx;
|
2013-06-13 01:17:55 +04:00
|
|
|
return JS_GetScriptFunction(cx, script->script);
|
2002-01-12 03:56:35 +03:00
|
|
|
}
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
JSDScript*
|
|
|
|
jsd_IterateScripts(JSDContext* jsdc, JSDScript **iterp)
|
|
|
|
{
|
|
|
|
JSDScript *jsdscript = *iterp;
|
|
|
|
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
1998-11-05 11:57:24 +03:00
|
|
|
|
|
|
|
if( !jsdscript )
|
|
|
|
jsdscript = (JSDScript *)jsdc->scripts.next;
|
|
|
|
if( jsdscript == (JSDScript *)&jsdc->scripts )
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
1998-11-05 11:57:24 +03:00
|
|
|
*iterp = (JSDScript*) jsdscript->links.next;
|
1998-03-28 05:44:41 +03:00
|
|
|
return jsdscript;
|
|
|
|
}
|
|
|
|
|
2001-04-20 07:45:39 +04:00
|
|
|
void *
|
|
|
|
jsd_SetScriptPrivate(JSDScript *jsdscript, void *data)
|
|
|
|
{
|
|
|
|
void *rval = jsdscript->data;
|
|
|
|
jsdscript->data = data;
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
jsd_GetScriptPrivate(JSDScript *jsdscript)
|
|
|
|
{
|
|
|
|
return jsdscript->data;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
1998-11-05 11:57:24 +03:00
|
|
|
jsd_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript)
|
|
|
|
{
|
|
|
|
JSDScript *current;
|
|
|
|
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
1998-11-05 11:57:24 +03:00
|
|
|
|
|
|
|
for( current = (JSDScript *)jsdc->scripts.next;
|
|
|
|
current != (JSDScript *)&jsdc->scripts;
|
|
|
|
current = (JSDScript *)current->links.next )
|
|
|
|
{
|
|
|
|
if(jsdscript == current)
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-11-05 11:57:24 +03:00
|
|
|
}
|
2013-08-07 10:59:54 +04:00
|
|
|
return false;
|
1998-11-05 11:57:24 +03:00
|
|
|
}
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
const char*
|
|
|
|
jsd_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript)
|
|
|
|
{
|
|
|
|
return jsdscript->url;
|
|
|
|
}
|
|
|
|
|
2010-11-24 19:56:43 +03:00
|
|
|
JSString*
|
2011-01-30 00:40:29 +03:00
|
|
|
jsd_GetScriptFunctionId(JSDContext* jsdc, JSDScript *jsdscript)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2010-11-24 19:56:43 +03:00
|
|
|
JSString* str;
|
2011-12-08 01:41:27 +04:00
|
|
|
JSFunction *fun = jsd_GetJSFunction(jsdc, jsdscript);
|
2010-11-24 19:56:43 +03:00
|
|
|
|
2011-12-08 01:41:27 +04:00
|
|
|
if( ! fun )
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
2011-12-08 01:41:27 +04:00
|
|
|
str = JS_GetFunctionId(fun);
|
2010-12-24 00:41:57 +03:00
|
|
|
|
|
|
|
/* For compatibility we return "anonymous", not an empty string here. */
|
|
|
|
return str ? str : JS_GetAnonymousString(jsdc->jsrt);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript)
|
|
|
|
{
|
|
|
|
return jsdscript->lineBase;
|
|
|
|
}
|
|
|
|
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript)
|
|
|
|
{
|
2013-06-13 01:17:55 +04:00
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JSAutoCompartment ac(cx, jsdc->glob); // Just in case.
|
2001-04-20 07:45:39 +04:00
|
|
|
if( NOT_SET_YET == (int)jsdscript->lineExtent )
|
2013-06-13 01:17:55 +04:00
|
|
|
jsdscript->lineExtent = JS_GetScriptLineExtent(cx, jsdscript->script);
|
1998-03-28 05:44:41 +03:00
|
|
|
return jsdscript->lineExtent;
|
|
|
|
}
|
|
|
|
|
2012-01-11 12:23:05 +04:00
|
|
|
uintptr_t
|
2012-02-29 03:11:11 +04:00
|
|
|
jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, unsigned line)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2012-01-11 12:23:05 +04:00
|
|
|
uintptr_t pc;
|
2011-01-28 05:31:48 +03:00
|
|
|
|
2011-08-28 18:48:00 +04:00
|
|
|
if( !jsdscript )
|
|
|
|
return 0;
|
2010-10-15 22:36:56 +04:00
|
|
|
|
2013-06-13 01:17:55 +04:00
|
|
|
AutoSafeJSContext cx;
|
2013-06-13 01:17:54 +04:00
|
|
|
JSAutoCompartment ac(cx, jsdscript->script);
|
|
|
|
pc = (uintptr_t) JS_LineNumberToPC(cx, jsdscript->script, line );
|
2011-01-28 05:31:48 +03:00
|
|
|
return pc;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned
|
2012-01-11 12:23:05 +04:00
|
|
|
jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, uintptr_t pc)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned first = jsdscript->lineBase;
|
|
|
|
unsigned last = first + jsd_GetScriptLineExtent(jsdc, jsdscript) - 1;
|
|
|
|
unsigned line = 0;
|
2011-01-28 05:31:48 +03:00
|
|
|
|
2013-06-13 01:17:54 +04:00
|
|
|
if (pc) {
|
2013-06-13 01:17:55 +04:00
|
|
|
AutoSafeJSContext cx;
|
2013-06-13 01:17:54 +04:00
|
|
|
JSAutoCompartment ac(cx, jsdscript->script);
|
2013-06-13 01:17:55 +04:00
|
|
|
line = JS_PCToLineNumber(cx, jsdscript->script, (jsbytecode*)pc);
|
2013-06-13 01:17:54 +04:00
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
if( line < first )
|
|
|
|
return first;
|
|
|
|
if( line > last )
|
|
|
|
return last;
|
1998-11-05 11:57:24 +03:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
2011-03-03 21:11:54 +03:00
|
|
|
jsd_GetLinePCs(JSDContext* jsdc, JSDScript* jsdscript,
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned startLine, unsigned maxLines,
|
|
|
|
unsigned* count, unsigned** retLines, uintptr_t** retPCs)
|
2011-03-03 21:11:54 +03:00
|
|
|
{
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned first = jsdscript->lineBase;
|
|
|
|
unsigned last = first + jsd_GetScriptLineExtent(jsdc, jsdscript) - 1;
|
2013-08-09 02:53:04 +04:00
|
|
|
bool ok;
|
2011-03-03 21:11:54 +03:00
|
|
|
jsbytecode **pcs;
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned i;
|
2011-03-03 21:11:54 +03:00
|
|
|
|
|
|
|
if (last < startLine)
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
2011-03-03 21:11:54 +03:00
|
|
|
|
2013-06-13 01:17:55 +04:00
|
|
|
AutoSafeJSContext cx;
|
2013-06-13 01:17:54 +04:00
|
|
|
JSAutoCompartment ac(cx, jsdscript->script);
|
2011-03-03 21:11:54 +03:00
|
|
|
|
2013-06-13 01:17:55 +04:00
|
|
|
ok = JS_GetLinePCs(cx, jsdscript->script,
|
2011-03-03 21:11:54 +03:00
|
|
|
startLine, maxLines,
|
|
|
|
count, retLines, &pcs);
|
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
if (retPCs) {
|
|
|
|
for (i = 0; i < *count; ++i) {
|
|
|
|
(*retPCs)[i] = (*pcs)[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 01:17:55 +04:00
|
|
|
JS_free(cx, pcs);
|
2011-03-03 21:11:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata)
|
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK();
|
1998-03-28 05:44:41 +03:00
|
|
|
jsdc->scriptHook = hook;
|
|
|
|
jsdc->scriptHookData = callerdata;
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK();
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
1998-11-05 11:57:24 +03:00
|
|
|
jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK();
|
|
|
|
if( hook )
|
|
|
|
*hook = jsdc->scriptHook;
|
|
|
|
if( callerdata )
|
|
|
|
*callerdata = jsdc->scriptHookData;
|
|
|
|
JSD_UNLOCK();
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-11-05 11:57:24 +03:00
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
|
|
|
jsd_EnableSingleStepInterrupts(JSDContext* jsdc, JSDScript* jsdscript, bool enable)
|
2010-11-17 02:18:35 +03:00
|
|
|
{
|
2013-08-09 02:53:04 +04:00
|
|
|
bool rv;
|
2013-06-13 01:17:55 +04:00
|
|
|
AutoSafeJSContext cx;
|
2014-04-02 18:28:03 +04:00
|
|
|
JS::RootedScript script(cx, jsdscript->script);
|
|
|
|
JSAutoCompartment ac(cx, script);
|
2010-11-17 02:18:35 +03:00
|
|
|
JSD_LOCK();
|
2014-04-02 18:28:03 +04:00
|
|
|
rv = JS_SetSingleStepMode(cx, script, enable);
|
2010-11-17 02:18:35 +03:00
|
|
|
JSD_UNLOCK();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
/***************************************************************************/
|
|
|
|
|
2008-09-07 02:21:43 +04:00
|
|
|
void
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_NewScriptHookProc(
|
|
|
|
JSContext *cx,
|
|
|
|
const char *filename, /* URL this script loads from */
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned lineno, /* line where this script starts */
|
1998-03-28 05:44:41 +03:00
|
|
|
JSScript *script,
|
|
|
|
JSFunction *fun,
|
|
|
|
void* callerdata )
|
|
|
|
{
|
2013-09-19 23:26:36 +04:00
|
|
|
JSDScript* jsdscript = nullptr;
|
1998-03-28 05:44:41 +03:00
|
|
|
JSDContext* jsdc = (JSDContext*) callerdata;
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_ScriptHookProc hook;
|
|
|
|
void* hookData;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
JSD_ASSERT_VALID_CONTEXT(jsdc);
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
if( JSD_IS_DANGEROUS_THREAD(jsdc) )
|
|
|
|
return;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
2011-12-08 01:41:27 +04:00
|
|
|
jsdscript = _newJSDScript(jsdc, cx, script);
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
if( ! jsdscript )
|
|
|
|
return;
|
1998-11-05 11:57:24 +03:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
#ifdef JSD_DUMP
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
_dumpJSDScript(jsdc, jsdscript, "***NEW Script: ");
|
|
|
|
_dumpJSDScriptList( jsdc );
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
#endif /* JSD_DUMP */
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
/* local in case jsdc->scriptHook gets cleared on another thread */
|
|
|
|
JSD_LOCK();
|
|
|
|
hook = jsdc->scriptHook;
|
2012-08-17 21:23:21 +04:00
|
|
|
if( hook )
|
|
|
|
jsdscript->flags = jsdscript->flags | JSD_SCRIPT_CALL_DESTROY_HOOK_BIT;
|
1998-11-05 11:57:24 +03:00
|
|
|
hookData = jsdc->scriptHookData;
|
|
|
|
JSD_UNLOCK();
|
|
|
|
|
|
|
|
if( hook )
|
2013-08-07 10:59:54 +04:00
|
|
|
hook(jsdc, jsdscript, true, hookData);
|
2010-10-30 20:13:02 +04:00
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
|
2008-09-07 02:21:43 +04:00
|
|
|
void
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_DestroyScriptHookProc(
|
2012-04-27 22:49:57 +04:00
|
|
|
JSFreeOp *fop,
|
2013-05-12 17:13:22 +04:00
|
|
|
JSScript *script_,
|
1998-03-28 05:44:41 +03:00
|
|
|
void* callerdata )
|
|
|
|
{
|
2013-09-19 23:26:36 +04:00
|
|
|
JSDScript* jsdscript = nullptr;
|
1998-03-28 05:44:41 +03:00
|
|
|
JSDContext* jsdc = (JSDContext*) callerdata;
|
2013-06-13 01:17:55 +04:00
|
|
|
// NB: We're called during GC, so we can't push a cx. Root directly with
|
|
|
|
// the runtime.
|
|
|
|
JS::RootedScript script(jsdc->jsrt, script_);
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_ScriptHookProc hook;
|
|
|
|
void* hookData;
|
2013-05-12 17:13:22 +04:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
JSD_ASSERT_VALID_CONTEXT(jsdc);
|
1998-11-05 11:57:24 +03:00
|
|
|
|
|
|
|
if( JSD_IS_DANGEROUS_THREAD(jsdc) )
|
|
|
|
return;
|
2013-05-12 17:13:22 +04:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
jsdscript = jsd_FindJSDScript(jsdc, script);
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
if( ! jsdscript )
|
|
|
|
return;
|
1998-11-05 11:57:24 +03:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
#ifdef JSD_DUMP
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
_dumpJSDScript(jsdc, jsdscript, "***DESTROY Script: ");
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
#endif /* JSD_DUMP */
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
/* local in case hook gets cleared on another thread */
|
|
|
|
JSD_LOCK();
|
2013-09-19 23:26:36 +04:00
|
|
|
hook = (jsdscript->flags & JSD_SCRIPT_CALL_DESTROY_HOOK_BIT) ? jsdc->scriptHook
|
|
|
|
: nullptr;
|
1998-11-05 11:57:24 +03:00
|
|
|
hookData = jsdc->scriptHookData;
|
|
|
|
JSD_UNLOCK();
|
|
|
|
|
|
|
|
if( hook )
|
2013-08-07 10:59:54 +04:00
|
|
|
hook(jsdc, jsdscript, false, hookData);
|
1998-11-05 11:57:24 +03:00
|
|
|
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
2002-02-27 12:24:14 +03:00
|
|
|
JS_HashTableRemove(jsdc->scriptsTable, (void *)script);
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
#ifdef JSD_DUMP
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
_dumpJSDScriptList(jsdc);
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
#endif /* JSD_DUMP */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
static JSDExecHook*
|
2012-01-11 12:23:05 +04:00
|
|
|
_findHook(JSDContext* jsdc, JSDScript* jsdscript, uintptr_t pc)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
|
|
|
JSDExecHook* jsdhook;
|
1998-11-05 11:57:24 +03:00
|
|
|
JSCList* list = &jsdscript->hooks;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
for( jsdhook = (JSDExecHook*)list->next;
|
1998-03-28 05:44:41 +03:00
|
|
|
jsdhook != (JSDExecHook*)list;
|
1998-11-05 11:57:24 +03:00
|
|
|
jsdhook = (JSDExecHook*)jsdhook->links.next )
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
|
|
|
if (jsdhook->pc == pc)
|
|
|
|
return jsdhook;
|
|
|
|
}
|
2013-09-19 23:26:36 +04:00
|
|
|
return nullptr;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
1998-11-05 11:57:24 +03:00
|
|
|
_isActiveHook(JSDContext* jsdc, JSScript *script, JSDExecHook* jsdhook)
|
|
|
|
{
|
|
|
|
JSDExecHook* current;
|
|
|
|
JSCList* list;
|
|
|
|
JSDScript* jsdscript;
|
|
|
|
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
jsdscript = jsd_FindJSDScript(jsdc, script);
|
|
|
|
if( ! jsdscript)
|
|
|
|
{
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
2013-08-07 10:59:54 +04:00
|
|
|
return false;
|
1998-11-05 11:57:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
list = &jsdscript->hooks;
|
|
|
|
|
|
|
|
for( current = (JSDExecHook*)list->next;
|
|
|
|
current != (JSDExecHook*)list;
|
|
|
|
current = (JSDExecHook*)current->links.next )
|
|
|
|
{
|
|
|
|
if(current == jsdhook)
|
|
|
|
{
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-11-05 11:57:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
2013-08-07 10:59:54 +04:00
|
|
|
return false;
|
1998-11-05 11:57:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-07 02:21:43 +04:00
|
|
|
JSTrapStatus
|
2013-05-12 17:13:22 +04:00
|
|
|
jsd_TrapHandler(JSContext *cx, JSScript *script_, jsbytecode *pc, jsval *rval,
|
2010-05-01 04:34:54 +04:00
|
|
|
jsval closure)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
2013-05-12 17:13:22 +04:00
|
|
|
JS::RootedScript script(cx, script_);
|
2010-05-01 04:34:54 +04:00
|
|
|
JSDExecHook* jsdhook = (JSDExecHook*) JSVAL_TO_PRIVATE(closure);
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_ExecutionHookProc hook;
|
|
|
|
void* hookData;
|
1998-03-28 05:44:41 +03:00
|
|
|
JSDContext* jsdc;
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK();
|
|
|
|
|
2013-09-19 23:26:36 +04:00
|
|
|
if( nullptr == (jsdc = jsd_JSDContextForJSContext(cx)) ||
|
1998-11-05 11:57:24 +03:00
|
|
|
! _isActiveHook(jsdc, script, jsdhook) )
|
|
|
|
{
|
|
|
|
JSD_UNLOCK();
|
1998-03-28 05:44:41 +03:00
|
|
|
return JSTRAP_CONTINUE;
|
1998-11-05 11:57:24 +03:00
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
JSD_ASSERT_VALID_EXEC_HOOK(jsdhook);
|
2014-02-18 10:24:15 +04:00
|
|
|
MOZ_ASSERT(!jsdhook->pc || jsdhook->pc == (uintptr_t)pc);
|
|
|
|
MOZ_ASSERT(jsdhook->jsdscript->script == script);
|
|
|
|
MOZ_ASSERT(jsdhook->jsdscript->jsdc == jsdc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
hook = jsdhook->hook;
|
|
|
|
hookData = jsdhook->callerdata;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
/* do not use jsdhook-> after this point */
|
|
|
|
JSD_UNLOCK();
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
if( ! jsdc || ! jsdc->inited )
|
|
|
|
return JSTRAP_CONTINUE;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
if( JSD_IS_DANGEROUS_THREAD(jsdc) )
|
|
|
|
return JSTRAP_CONTINUE;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
return jsd_CallExecutionHook(jsdc, cx, JSD_HOOK_BREAKPOINT,
|
|
|
|
hook, hookData, rval);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_SetExecutionHook(JSDContext* jsdc,
|
|
|
|
JSDScript* jsdscript,
|
2012-01-11 12:23:05 +04:00
|
|
|
uintptr_t pc,
|
1998-03-28 05:44:41 +03:00
|
|
|
JSD_ExecutionHookProc hook,
|
|
|
|
void* callerdata)
|
|
|
|
{
|
|
|
|
JSDExecHook* jsdhook;
|
2013-08-09 02:53:04 +04:00
|
|
|
bool rv;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK();
|
1998-03-28 05:44:41 +03:00
|
|
|
if( ! hook )
|
1998-11-05 11:57:24 +03:00
|
|
|
{
|
|
|
|
jsd_ClearExecutionHook(jsdc, jsdscript, pc);
|
|
|
|
JSD_UNLOCK();
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-11-05 11:57:24 +03:00
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
jsdhook = _findHook(jsdc, jsdscript, pc);
|
1998-03-28 05:44:41 +03:00
|
|
|
if( jsdhook )
|
|
|
|
{
|
|
|
|
jsdhook->hook = hook;
|
|
|
|
jsdhook->callerdata = callerdata;
|
2008-02-10 07:16:54 +03:00
|
|
|
JSD_UNLOCK();
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
/* else... */
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
jsdhook = (JSDExecHook*)calloc(1, sizeof(JSDExecHook));
|
2008-02-10 07:16:54 +03:00
|
|
|
if( ! jsdhook ) {
|
|
|
|
JSD_UNLOCK();
|
2013-08-07 10:59:54 +04:00
|
|
|
return false;
|
2008-02-10 07:16:54 +03:00
|
|
|
}
|
1998-03-28 05:44:41 +03:00
|
|
|
jsdhook->jsdscript = jsdscript;
|
|
|
|
jsdhook->pc = pc;
|
|
|
|
jsdhook->hook = hook;
|
|
|
|
jsdhook->callerdata = callerdata;
|
|
|
|
|
2013-06-13 01:17:54 +04:00
|
|
|
{
|
2013-06-13 01:17:55 +04:00
|
|
|
AutoSafeJSContext cx;
|
2013-06-13 01:17:54 +04:00
|
|
|
JSAutoCompartment ac(cx, jsdscript->script);
|
2014-03-20 13:32:37 +04:00
|
|
|
JS::RootedScript script(cx, jsdscript->script);
|
|
|
|
JS::RootedValue hookValue(cx, PRIVATE_TO_JSVAL(jsdhook));
|
|
|
|
rv = JS_SetTrap(cx, script, (jsbytecode*)pc, jsd_TrapHandler, hookValue);
|
2013-06-13 01:17:54 +04:00
|
|
|
}
|
2011-01-28 05:31:48 +03:00
|
|
|
|
|
|
|
if ( ! rv ) {
|
1998-11-05 11:57:24 +03:00
|
|
|
free(jsdhook);
|
2008-02-10 07:16:54 +03:00
|
|
|
JSD_UNLOCK();
|
2013-08-07 10:59:54 +04:00
|
|
|
return false;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_APPEND_LINK(&jsdhook->links, &jsdscript->hooks);
|
|
|
|
JSD_UNLOCK();
|
|
|
|
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_ClearExecutionHook(JSDContext* jsdc,
|
|
|
|
JSDScript* jsdscript,
|
2012-01-11 12:23:05 +04:00
|
|
|
uintptr_t pc)
|
1998-03-28 05:44:41 +03:00
|
|
|
{
|
|
|
|
JSDExecHook* jsdhook;
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK();
|
|
|
|
|
|
|
|
jsdhook = _findHook(jsdc, jsdscript, pc);
|
1998-03-28 05:44:41 +03:00
|
|
|
if( ! jsdhook )
|
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK();
|
2013-08-07 10:59:54 +04:00
|
|
|
return false;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2013-06-13 01:17:54 +04:00
|
|
|
{
|
2013-06-13 01:17:55 +04:00
|
|
|
AutoSafeJSContext cx;
|
2013-06-13 01:17:54 +04:00
|
|
|
JSAutoCompartment ac(cx, jsdscript->script);
|
2013-06-13 01:17:55 +04:00
|
|
|
JS_ClearTrap(cx, jsdscript->script,
|
2013-09-19 23:26:36 +04:00
|
|
|
(jsbytecode*)pc, nullptr, nullptr);
|
2013-06-13 01:17:54 +04:00
|
|
|
}
|
2011-01-28 05:31:48 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_REMOVE_LINK(&jsdhook->links);
|
|
|
|
free(jsdhook);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK();
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript)
|
|
|
|
{
|
|
|
|
JSDExecHook* jsdhook;
|
1998-11-05 11:57:24 +03:00
|
|
|
JSCList* list = &jsdscript->hooks;
|
|
|
|
JSD_LOCK();
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
while( (JSDExecHook*)list != (jsdhook = (JSDExecHook*)list->next) )
|
|
|
|
{
|
1998-11-05 11:57:24 +03:00
|
|
|
JS_REMOVE_LINK(&jsdhook->links);
|
|
|
|
free(jsdhook);
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2013-06-13 01:17:55 +04:00
|
|
|
JS_ClearScriptTraps(jsdc->jsrt, jsdscript->script);
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK();
|
|
|
|
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
bool
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_ClearAllExecutionHooks(JSDContext* jsdc)
|
|
|
|
{
|
|
|
|
JSDScript* jsdscript;
|
2013-09-19 23:26:36 +04:00
|
|
|
JSDScript* iterp = nullptr;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_LOCK();
|
2013-09-19 23:26:36 +04:00
|
|
|
while( nullptr != (jsdscript = jsd_IterateScripts(jsdc, &iterp)) )
|
1998-03-28 05:44:41 +03:00
|
|
|
jsd_ClearAllExecutionHooksForScript(jsdc, jsdscript);
|
1998-11-05 11:57:24 +03:00
|
|
|
JSD_UNLOCK();
|
2013-08-07 10:59:54 +04:00
|
|
|
return true;
|
1998-03-28 05:44:41 +03:00
|
|
|
}
|
|
|
|
|
1998-11-05 11:57:24 +03:00
|
|
|
void
|
|
|
|
jsd_ScriptCreated(JSDContext* jsdc,
|
|
|
|
JSContext *cx,
|
|
|
|
const char *filename, /* URL this script loads from */
|
2012-02-29 03:11:11 +04:00
|
|
|
unsigned lineno, /* line where this script starts */
|
1998-11-05 11:57:24 +03:00
|
|
|
JSScript *script,
|
|
|
|
JSFunction *fun)
|
|
|
|
{
|
|
|
|
jsd_NewScriptHookProc(cx, filename, lineno, script, fun, jsdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsd_ScriptDestroyed(JSDContext* jsdc,
|
2012-04-27 22:49:57 +04:00
|
|
|
JSFreeOp *fop,
|
1998-11-05 11:57:24 +03:00
|
|
|
JSScript *script)
|
|
|
|
{
|
2012-04-27 22:49:57 +04:00
|
|
|
jsd_DestroyScriptHookProc(fop, script, jsdc);
|
1998-11-05 11:57:24 +03:00
|
|
|
}
|