2013-04-16 13:47:10 -07: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 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* JavaScript Debugging support - Script support
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jsd.h"
|
2010-12-23 13:41:57 -08:00
|
|
|
#include "jsfriendapi.h"
|
2007-03-22 10:30:00 -07: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
|
|
|
|
void JSD_ASSERT_VALID_SCRIPT(JSDScript* jsdscript)
|
|
|
|
{
|
|
|
|
JS_ASSERT(jsdscript);
|
|
|
|
JS_ASSERT(jsdscript->script);
|
|
|
|
}
|
|
|
|
void JSD_ASSERT_VALID_EXEC_HOOK(JSDExecHook* jsdhook)
|
|
|
|
{
|
|
|
|
JS_ASSERT(jsdhook);
|
|
|
|
JS_ASSERT(jsdhook->hook);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LIVEWIRE
|
|
|
|
static JSBool
|
|
|
|
HasFileExtention(const char* name, const char* ext)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int len = strlen(ext);
|
|
|
|
const char* p = strrchr(name,'.');
|
|
|
|
if( !p )
|
|
|
|
return JS_FALSE;
|
|
|
|
p++;
|
|
|
|
for(i = 0; i < len; i++ )
|
|
|
|
{
|
|
|
|
JS_ASSERT(islower(ext[i]));
|
|
|
|
if( 0 == p[i] || tolower(p[i]) != ext[i] )
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
if( 0 != p[i] )
|
|
|
|
return JS_FALSE;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
#endif /* LIVEWIRE */
|
|
|
|
|
|
|
|
static JSDScript*
|
|
|
|
_newJSDScript(JSDContext* jsdc,
|
|
|
|
JSContext *cx,
|
2011-12-07 13:41:27 -08:00
|
|
|
JSScript *script)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSDScript* jsdscript;
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned lineno;
|
2007-03-22 10:30:00 -07:00
|
|
|
const char* raw_filename;
|
|
|
|
|
|
|
|
JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
|
|
|
|
|
|
|
/* these are inlined javascript: urls and we can't handle them now */
|
2012-02-28 15:11:11 -08:00
|
|
|
lineno = (unsigned) JS_GetScriptBaseLineNumber(cx, script);
|
2007-03-22 10:30:00 -07:00
|
|
|
if( lineno == 0 )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
jsdscript = (JSDScript*) calloc(1, sizeof(JSDScript));
|
|
|
|
if( ! jsdscript )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
raw_filename = JS_GetScriptFilename(cx,script);
|
|
|
|
|
|
|
|
JS_HashTableAdd(jsdc->scriptsTable, (void *)script, (void *)jsdscript);
|
|
|
|
JS_APPEND_LINK(&jsdscript->links, &jsdc->scripts);
|
|
|
|
jsdscript->jsdc = jsdc;
|
2011-12-07 13:41:27 -08:00
|
|
|
jsdscript->script = script;
|
2007-03-22 10:30:00 -07:00
|
|
|
jsdscript->lineBase = lineno;
|
2012-02-28 15:11:11 -08:00
|
|
|
jsdscript->lineExtent = (unsigned)NOT_SET_YET;
|
2007-03-22 10:30:00 -07:00
|
|
|
jsdscript->data = NULL;
|
|
|
|
#ifndef LIVEWIRE
|
|
|
|
jsdscript->url = (char*) jsd_BuildNormalizedURL(raw_filename);
|
|
|
|
#else
|
|
|
|
jsdscript->app = LWDBG_GetCurrentApp();
|
|
|
|
if( jsdscript->app && raw_filename )
|
|
|
|
{
|
|
|
|
jsdscript->url = jsdlw_BuildAppRelativeFilename(jsdscript->app, raw_filename);
|
|
|
|
if( function )
|
|
|
|
{
|
2010-11-08 04:17:31 -08:00
|
|
|
JSString* funid = JS_GetFunctionId(function);
|
|
|
|
char* funbytes;
|
|
|
|
const char* funnanme;
|
|
|
|
if( fuinid )
|
|
|
|
{
|
|
|
|
funbytes = JS_EncodeString(cx, funid);
|
|
|
|
funname = funbytes ? funbytes : "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
funbytes = NULL;
|
|
|
|
funname = "anonymous";
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
jsdscript->lwscript =
|
2010-11-08 04:17:31 -08:00
|
|
|
LWDBG_GetScriptOfFunction(jsdscript->app,funname);
|
|
|
|
JS_Free(cx, funbytes);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* also, make sure this file is added to filelist if is .js file */
|
|
|
|
if( HasFileExtention(raw_filename,"js") ||
|
|
|
|
HasFileExtention(raw_filename,"sjs") )
|
|
|
|
{
|
|
|
|
jsdlw_PreLoadSource(jsdc, jsdscript->app, raw_filename, JS_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jsdscript->lwscript = LWDBG_GetCurrentTopLevelScript();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
JS_INIT_CLIST(&jsdscript->hooks);
|
|
|
|
|
|
|
|
return jsdscript;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_destroyJSDScript(JSDContext* jsdc,
|
|
|
|
JSDScript* jsdscript)
|
|
|
|
{
|
|
|
|
JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
|
|
|
|
|
|
|
/* destroy all hooks */
|
|
|
|
jsd_ClearAllExecutionHooksForScript(jsdc, jsdscript);
|
|
|
|
|
|
|
|
JS_REMOVE_LINK(&jsdscript->links);
|
|
|
|
if(jsdscript->url)
|
|
|
|
free(jsdscript->url);
|
|
|
|
|
|
|
|
if (jsdscript->profileData)
|
|
|
|
free(jsdscript->profileData);
|
|
|
|
|
2007-12-23 15:47:36 -08:00
|
|
|
free(jsdscript);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
#ifdef JSD_DUMP
|
|
|
|
#ifndef XP_WIN
|
|
|
|
void
|
|
|
|
OutputDebugString (char *buf)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s", buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
_dumpJSDScript(JSDContext* jsdc, JSDScript* jsdscript, const char* leadingtext)
|
|
|
|
{
|
|
|
|
const char* name;
|
2010-11-24 08:56:43 -08:00
|
|
|
JSString* fun;
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned base;
|
|
|
|
unsigned extent;
|
2007-03-22 10:30:00 -07:00
|
|
|
char Buf[256];
|
2010-11-24 08:56:43 -08:00
|
|
|
size_t n;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
name = jsd_GetScriptFilename(jsdc, jsdscript);
|
2011-01-29 13:40:29 -08:00
|
|
|
fun = jsd_GetScriptFunctionId(jsdc, jsdscript);
|
2007-03-22 10:30:00 -07:00
|
|
|
base = jsd_GetScriptBaseLineNumber(jsdc, jsdscript);
|
|
|
|
extent = jsd_GetScriptLineExtent(jsdc, jsdscript);
|
2010-11-24 08:56:43 -08: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 00:24:17 -08:00
|
|
|
n += JS_PutEscapedFlatString(Buf + n, sizeof(Buf) - n,
|
|
|
|
JS_ASSERT_STRING_IS_FLAT(fun), 0);
|
2010-11-24 08:56:43 -08:00
|
|
|
Buf[sizeof(Buf) - 1] = '\0';
|
|
|
|
}
|
|
|
|
if (n + 1 < sizeof(Buf))
|
|
|
|
snprintf(Buf + n, sizeof(Buf) - n, ", %d-%d\n", base, base + extent - 1);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
OutputDebugString( Buf );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_dumpJSDScriptList( JSDContext* jsdc )
|
|
|
|
{
|
|
|
|
JSDScript* iterp = NULL;
|
|
|
|
JSDScript* jsdscript = NULL;
|
|
|
|
|
|
|
|
OutputDebugString( "*** JSDScriptDump\n" );
|
|
|
|
while( NULL != (jsdscript = jsd_IterateScripts(jsdc, &iterp)) )
|
|
|
|
_dumpJSDScript( jsdc, jsdscript, " script: " );
|
|
|
|
}
|
|
|
|
#endif /* JSD_DUMP */
|
|
|
|
|
|
|
|
/***************************************************************************/
|
2008-09-06 15:21:43 -07:00
|
|
|
static JSHashNumber
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_hash_script(const void *key)
|
|
|
|
{
|
2010-12-04 02:05:45 -08:00
|
|
|
return ((JSHashNumber)(ptrdiff_t) key) >> 2; /* help lame MSVC1.5 on Win16 */
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-06 15:21:43 -07:00
|
|
|
static void *
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_alloc_script_table(void *priv, size_t size)
|
|
|
|
{
|
|
|
|
return malloc(size);
|
|
|
|
}
|
|
|
|
|
2008-09-06 15:21:43 -07:00
|
|
|
static void
|
2009-06-18 02:12:56 -07:00
|
|
|
jsd_free_script_table(void *priv, void *item, size_t size)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2008-09-06 15:21:43 -07:00
|
|
|
static JSHashEntry *
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_alloc_script_entry(void *priv, const void *item)
|
|
|
|
{
|
|
|
|
return (JSHashEntry*) malloc(sizeof(JSHashEntry));
|
|
|
|
}
|
|
|
|
|
2008-09-06 15:21:43 -07:00
|
|
|
static void
|
2012-02-28 15:11:11 -08:00
|
|
|
jsd_free_script_entry(void *priv, JSHashEntry *he, unsigned flag)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (flag == HT_FREE_ENTRY)
|
|
|
|
{
|
|
|
|
_destroyJSDScript((JSDContext*) priv, (JSDScript*) he->value);
|
|
|
|
free(he);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSHashAllocOps script_alloc_ops = {
|
|
|
|
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
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
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 02:05:45 -08:00
|
|
|
return !!jsdc->scriptsTable;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsd_DestroyScriptManager(JSDContext* jsdc)
|
|
|
|
{
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
if (jsdc->scriptsTable)
|
|
|
|
JS_HashTableDestroy(jsdc->scriptsTable);
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDScript*
|
|
|
|
jsd_FindJSDScript( JSDContext* jsdc,
|
|
|
|
JSScript *script )
|
|
|
|
{
|
|
|
|
JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
|
|
|
return (JSDScript*) JS_HashTableLookup(jsdc->scriptsTable, (void *)script);
|
2009-03-14 07:57:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSDScript *
|
|
|
|
jsd_FindOrCreateJSDScript(JSDContext *jsdc,
|
|
|
|
JSContext *cx,
|
|
|
|
JSScript *script,
|
2013-01-25 00:49:29 -08:00
|
|
|
JSAbstractFramePtr frame)
|
2009-03-14 07:57:31 -07:00
|
|
|
{
|
|
|
|
JSDScript *jsdscript;
|
|
|
|
JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
|
|
|
|
|
|
|
jsdscript = jsd_FindJSDScript(jsdc, script);
|
|
|
|
if (jsdscript)
|
|
|
|
return jsdscript;
|
|
|
|
|
2009-04-02 15:01:15 -07:00
|
|
|
/* Fallback for unknown scripts: create a new script. */
|
2013-01-25 00:49:29 -08:00
|
|
|
if (!frame) {
|
|
|
|
JSBrokenFrameIterator iter(cx);
|
|
|
|
if (!iter.done())
|
|
|
|
frame = iter.abstractFramePtr();
|
|
|
|
}
|
|
|
|
if (frame)
|
2011-12-07 13:41:27 -08:00
|
|
|
jsdscript = _newJSDScript(jsdc, cx, script);
|
2009-03-14 07:57:31 -07:00
|
|
|
|
|
|
|
return jsdscript;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
JSDProfileData*
|
|
|
|
jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (!script->profileData)
|
|
|
|
script->profileData = (JSDProfileData*)calloc(1, sizeof(JSDProfileData));
|
|
|
|
|
|
|
|
return script->profileData;
|
|
|
|
}
|
|
|
|
|
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-08 19:54:10 -08:00
|
|
|
uint32_t
|
2007-03-22 10:30:00 -07: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-08 19:54:10 -08:00
|
|
|
jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32_t flags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
script->flags = flags;
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetScriptCallCount(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->callCount;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetScriptMaxRecurseDepth(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->maxRecurseDepth;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-24 14:19:52 -08:00
|
|
|
double
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetScriptMinExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->minExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-24 14:19:52 -08:00
|
|
|
double
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetScriptMaxExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->maxExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-24 14:19:52 -08:00
|
|
|
double
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetScriptTotalExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->totalExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-24 14:19:52 -08:00
|
|
|
double
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetScriptMinOwnExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->minOwnExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-24 14:19:52 -08:00
|
|
|
double
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetScriptMaxOwnExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->maxOwnExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-02-24 14:19:52 -08:00
|
|
|
double
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetScriptTotalOwnExecutionTime(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
return script->profileData->totalOwnExecutionTime;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsd_ClearScriptProfileData(JSDContext* jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
if (script->profileData)
|
|
|
|
{
|
|
|
|
free(script->profileData);
|
|
|
|
script->profileData = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSScript *
|
|
|
|
jsd_GetJSScript (JSDContext *jsdc, JSDScript *script)
|
|
|
|
{
|
|
|
|
return script->script;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSFunction *
|
|
|
|
jsd_GetJSFunction (JSDContext *jsdc, JSDScript *script)
|
|
|
|
{
|
2011-12-07 13:41:27 -08:00
|
|
|
return JS_GetScriptFunction(jsdc->dumbContext, script->script);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSDScript*
|
|
|
|
jsd_IterateScripts(JSDContext* jsdc, JSDScript **iterp)
|
|
|
|
{
|
|
|
|
JSDScript *jsdscript = *iterp;
|
|
|
|
|
|
|
|
JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
|
|
|
|
|
|
|
if( !jsdscript )
|
|
|
|
jsdscript = (JSDScript *)jsdc->scripts.next;
|
|
|
|
if( jsdscript == (JSDScript *)&jsdc->scripts )
|
|
|
|
return NULL;
|
|
|
|
*iterp = (JSDScript*) jsdscript->links.next;
|
|
|
|
return jsdscript;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
jsd_SetScriptPrivate(JSDScript *jsdscript, void *data)
|
|
|
|
{
|
|
|
|
void *rval = jsdscript->data;
|
|
|
|
jsdscript->data = data;
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
jsd_GetScriptPrivate(JSDScript *jsdscript)
|
|
|
|
{
|
|
|
|
return jsdscript->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_IsActiveScript(JSDContext* jsdc, JSDScript *jsdscript)
|
|
|
|
{
|
|
|
|
JSDScript *current;
|
|
|
|
|
|
|
|
JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
|
|
|
|
|
|
|
|
for( current = (JSDScript *)jsdc->scripts.next;
|
|
|
|
current != (JSDScript *)&jsdc->scripts;
|
|
|
|
current = (JSDScript *)current->links.next )
|
|
|
|
{
|
|
|
|
if(jsdscript == current)
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
jsd_GetScriptFilename(JSDContext* jsdc, JSDScript *jsdscript)
|
|
|
|
{
|
|
|
|
return jsdscript->url;
|
|
|
|
}
|
|
|
|
|
2010-11-24 08:56:43 -08:00
|
|
|
JSString*
|
2011-01-29 13:40:29 -08:00
|
|
|
jsd_GetScriptFunctionId(JSDContext* jsdc, JSDScript *jsdscript)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-11-24 08:56:43 -08:00
|
|
|
JSString* str;
|
2011-12-07 13:41:27 -08:00
|
|
|
JSFunction *fun = jsd_GetJSFunction(jsdc, jsdscript);
|
2010-11-24 08:56:43 -08:00
|
|
|
|
2011-12-07 13:41:27 -08:00
|
|
|
if( ! fun )
|
2007-03-22 10:30:00 -07:00
|
|
|
return NULL;
|
2011-12-07 13:41:27 -08:00
|
|
|
str = JS_GetFunctionId(fun);
|
2010-12-23 13:41:57 -08:00
|
|
|
|
|
|
|
/* For compatibility we return "anonymous", not an empty string here. */
|
|
|
|
return str ? str : JS_GetAnonymousString(jsdc->jsrt);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetScriptBaseLineNumber(JSDContext* jsdc, JSDScript *jsdscript)
|
|
|
|
{
|
|
|
|
return jsdscript->lineBase;
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript)
|
|
|
|
{
|
|
|
|
if( NOT_SET_YET == (int)jsdscript->lineExtent )
|
|
|
|
jsdscript->lineExtent = JS_GetScriptLineExtent(jsdc->dumbContext, jsdscript->script);
|
|
|
|
return jsdscript->lineExtent;
|
|
|
|
}
|
|
|
|
|
2012-01-11 00:23:05 -08:00
|
|
|
uintptr_t
|
2012-02-28 15:11:11 -08:00
|
|
|
jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, unsigned line)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 00:23:05 -08:00
|
|
|
uintptr_t pc;
|
2012-08-27 13:32:51 -07:00
|
|
|
JSCompartment *oldCompartment;
|
2011-01-27 18:31:48 -08:00
|
|
|
|
2011-08-28 07:48:00 -07:00
|
|
|
if( !jsdscript )
|
|
|
|
return 0;
|
2010-10-15 11:36:56 -07:00
|
|
|
#ifdef LIVEWIRE
|
2011-08-28 07:48:00 -07:00
|
|
|
if( jsdscript->lwscript )
|
2010-10-15 11:36:56 -07:00
|
|
|
{
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned newline;
|
2010-10-15 11:36:56 -07:00
|
|
|
jsdlw_RawToProcessedLineNumber(jsdc, jsdscript, line, &newline);
|
|
|
|
if( line != newline )
|
|
|
|
line = newline;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-27 13:32:51 -07:00
|
|
|
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
|
2012-01-11 00:23:05 -08:00
|
|
|
pc = (uintptr_t) JS_LineNumberToPC(jsdc->dumbContext, jsdscript->script, line );
|
2012-08-27 13:32:51 -07:00
|
|
|
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
|
2011-01-27 18:31:48 -08:00
|
|
|
return pc;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned
|
2012-01-11 00:23:05 -08:00
|
|
|
jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, uintptr_t pc)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-27 13:32:51 -07:00
|
|
|
JSCompartment* oldCompartment;
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned first = jsdscript->lineBase;
|
|
|
|
unsigned last = first + jsd_GetScriptLineExtent(jsdc, jsdscript) - 1;
|
|
|
|
unsigned line = 0;
|
2011-01-27 18:31:48 -08:00
|
|
|
|
2012-08-27 13:32:51 -07:00
|
|
|
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
|
2011-01-27 18:31:48 -08:00
|
|
|
if (pc)
|
|
|
|
line = JS_PCToLineNumber(jsdc->dumbContext, jsdscript->script, (jsbytecode*)pc);
|
2012-08-27 13:32:51 -07:00
|
|
|
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if( line < first )
|
|
|
|
return first;
|
|
|
|
if( line > last )
|
|
|
|
return last;
|
|
|
|
|
|
|
|
#ifdef LIVEWIRE
|
|
|
|
if( jsdscript && jsdscript->lwscript )
|
|
|
|
{
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned newline;
|
2007-03-22 10:30:00 -07:00
|
|
|
jsdlw_ProcessedToRawLineNumber(jsdc, jsdscript, line, &newline);
|
|
|
|
line = newline;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2011-03-03 10:11:54 -08:00
|
|
|
JSBool
|
|
|
|
jsd_GetLinePCs(JSDContext* jsdc, JSDScript* jsdscript,
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned startLine, unsigned maxLines,
|
|
|
|
unsigned* count, unsigned** retLines, uintptr_t** retPCs)
|
2011-03-03 10:11:54 -08:00
|
|
|
{
|
2012-08-27 13:32:51 -07:00
|
|
|
JSCompartment* oldCompartment;
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned first = jsdscript->lineBase;
|
|
|
|
unsigned last = first + jsd_GetScriptLineExtent(jsdc, jsdscript) - 1;
|
2011-03-03 10:11:54 -08:00
|
|
|
JSBool ok;
|
|
|
|
jsbytecode **pcs;
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned i;
|
2011-03-03 10:11:54 -08:00
|
|
|
|
|
|
|
if (last < startLine)
|
|
|
|
return JS_TRUE;
|
|
|
|
|
2012-08-27 13:32:51 -07:00
|
|
|
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
|
2011-03-03 10:11:54 -08:00
|
|
|
|
|
|
|
ok = JS_GetLinePCs(jsdc->dumbContext, jsdscript->script,
|
|
|
|
startLine, maxLines,
|
|
|
|
count, retLines, &pcs);
|
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
if (retPCs) {
|
|
|
|
for (i = 0; i < *count; ++i) {
|
|
|
|
(*retPCs)[i] = (*pcs)[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_free(jsdc->dumbContext, pcs);
|
|
|
|
}
|
|
|
|
|
2012-08-27 13:32:51 -07:00
|
|
|
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
|
2011-03-03 10:11:54 -08:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JSBool
|
|
|
|
jsd_SetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc hook, void* callerdata)
|
|
|
|
{
|
|
|
|
JSD_LOCK();
|
|
|
|
jsdc->scriptHook = hook;
|
|
|
|
jsdc->scriptHookData = callerdata;
|
|
|
|
JSD_UNLOCK();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata)
|
|
|
|
{
|
|
|
|
JSD_LOCK();
|
|
|
|
if( hook )
|
|
|
|
*hook = jsdc->scriptHook;
|
|
|
|
if( callerdata )
|
|
|
|
*callerdata = jsdc->scriptHookData;
|
|
|
|
JSD_UNLOCK();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-16 15:18:35 -08:00
|
|
|
JSBool
|
|
|
|
jsd_EnableSingleStepInterrupts(JSDContext* jsdc, JSDScript* jsdscript, JSBool enable)
|
|
|
|
{
|
2012-08-27 13:32:51 -07:00
|
|
|
JSCompartment* oldCompartment;
|
2010-11-16 15:18:35 -08:00
|
|
|
JSBool rv;
|
2012-08-27 13:32:51 -07:00
|
|
|
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
|
2010-11-16 15:18:35 -08:00
|
|
|
JSD_LOCK();
|
|
|
|
rv = JS_SetSingleStepMode(jsdc->dumbContext, jsdscript->script, enable);
|
|
|
|
JSD_UNLOCK();
|
2012-08-27 13:32:51 -07:00
|
|
|
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
|
2010-11-16 15:18:35 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/***************************************************************************/
|
|
|
|
|
2008-09-06 15:21:43 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_NewScriptHookProc(
|
|
|
|
JSContext *cx,
|
|
|
|
const char *filename, /* URL this script loads from */
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned lineno, /* line where this script starts */
|
2007-03-22 10:30:00 -07:00
|
|
|
JSScript *script,
|
|
|
|
JSFunction *fun,
|
|
|
|
void* callerdata )
|
|
|
|
{
|
|
|
|
JSDScript* jsdscript = NULL;
|
|
|
|
JSDContext* jsdc = (JSDContext*) callerdata;
|
|
|
|
JSD_ScriptHookProc hook;
|
|
|
|
void* hookData;
|
|
|
|
|
|
|
|
JSD_ASSERT_VALID_CONTEXT(jsdc);
|
|
|
|
|
|
|
|
if( JSD_IS_DANGEROUS_THREAD(jsdc) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
2011-12-07 13:41:27 -08:00
|
|
|
jsdscript = _newJSDScript(jsdc, cx, script);
|
2007-03-22 10:30:00 -07:00
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
if( ! jsdscript )
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef JSD_DUMP
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
_dumpJSDScript(jsdc, jsdscript, "***NEW Script: ");
|
|
|
|
_dumpJSDScriptList( jsdc );
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
#endif /* JSD_DUMP */
|
|
|
|
|
|
|
|
/* local in case jsdc->scriptHook gets cleared on another thread */
|
|
|
|
JSD_LOCK();
|
|
|
|
hook = jsdc->scriptHook;
|
2012-08-17 10:23:21 -07:00
|
|
|
if( hook )
|
|
|
|
jsdscript->flags = jsdscript->flags | JSD_SCRIPT_CALL_DESTROY_HOOK_BIT;
|
2007-03-22 10:30:00 -07:00
|
|
|
hookData = jsdc->scriptHookData;
|
|
|
|
JSD_UNLOCK();
|
|
|
|
|
|
|
|
if( hook )
|
|
|
|
hook(jsdc, jsdscript, JS_TRUE, hookData);
|
2010-10-30 09:13:02 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-06 15:21:43 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_DestroyScriptHookProc(
|
2012-04-27 11:49:57 -07:00
|
|
|
JSFreeOp *fop,
|
2007-03-22 10:30:00 -07:00
|
|
|
JSScript *script,
|
|
|
|
void* callerdata )
|
|
|
|
{
|
|
|
|
JSDScript* jsdscript = NULL;
|
|
|
|
JSDContext* jsdc = (JSDContext*) callerdata;
|
|
|
|
JSD_ScriptHookProc hook;
|
|
|
|
void* hookData;
|
|
|
|
|
|
|
|
JSD_ASSERT_VALID_CONTEXT(jsdc);
|
|
|
|
|
|
|
|
if( JSD_IS_DANGEROUS_THREAD(jsdc) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
jsdscript = jsd_FindJSDScript(jsdc, script);
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
|
|
|
|
if( ! jsdscript )
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef JSD_DUMP
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
_dumpJSDScript(jsdc, jsdscript, "***DESTROY Script: ");
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
#endif /* JSD_DUMP */
|
|
|
|
|
|
|
|
/* local in case hook gets cleared on another thread */
|
|
|
|
JSD_LOCK();
|
2012-08-17 10:23:21 -07:00
|
|
|
hook = (jsdscript->flags & JSD_SCRIPT_CALL_DESTROY_HOOK_BIT) ? jsdc->scriptHook : NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
hookData = jsdc->scriptHookData;
|
|
|
|
JSD_UNLOCK();
|
|
|
|
|
|
|
|
if( hook )
|
|
|
|
hook(jsdc, jsdscript, JS_FALSE, hookData);
|
|
|
|
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
JS_HashTableRemove(jsdc->scriptsTable, (void *)script);
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
|
|
|
|
#ifdef JSD_DUMP
|
|
|
|
JSD_LOCK_SCRIPTS(jsdc);
|
|
|
|
_dumpJSDScriptList(jsdc);
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
#endif /* JSD_DUMP */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
static JSDExecHook*
|
2012-01-11 00:23:05 -08:00
|
|
|
_findHook(JSDContext* jsdc, JSDScript* jsdscript, uintptr_t pc)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSDExecHook* jsdhook;
|
|
|
|
JSCList* list = &jsdscript->hooks;
|
|
|
|
|
|
|
|
for( jsdhook = (JSDExecHook*)list->next;
|
|
|
|
jsdhook != (JSDExecHook*)list;
|
|
|
|
jsdhook = (JSDExecHook*)jsdhook->links.next )
|
|
|
|
{
|
|
|
|
if (jsdhook->pc == pc)
|
|
|
|
return jsdhook;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
_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);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
list = &jsdscript->hooks;
|
|
|
|
|
|
|
|
for( current = (JSDExecHook*)list->next;
|
|
|
|
current != (JSDExecHook*)list;
|
|
|
|
current = (JSDExecHook*)current->links.next )
|
|
|
|
{
|
|
|
|
if(current == jsdhook)
|
|
|
|
{
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSD_UNLOCK_SCRIPTS(jsdc);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-06 15:21:43 -07:00
|
|
|
JSTrapStatus
|
2007-03-22 10:30:00 -07:00
|
|
|
jsd_TrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
|
2010-04-30 17:34:54 -07:00
|
|
|
jsval closure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-04-30 17:34:54 -07:00
|
|
|
JSDExecHook* jsdhook = (JSDExecHook*) JSVAL_TO_PRIVATE(closure);
|
2007-03-22 10:30:00 -07:00
|
|
|
JSD_ExecutionHookProc hook;
|
|
|
|
void* hookData;
|
|
|
|
JSDContext* jsdc;
|
|
|
|
JSDScript* jsdscript;
|
|
|
|
|
|
|
|
JSD_LOCK();
|
|
|
|
|
|
|
|
if( NULL == (jsdc = jsd_JSDContextForJSContext(cx)) ||
|
|
|
|
! _isActiveHook(jsdc, script, jsdhook) )
|
|
|
|
{
|
|
|
|
JSD_UNLOCK();
|
|
|
|
return JSTRAP_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSD_ASSERT_VALID_EXEC_HOOK(jsdhook);
|
2012-01-11 00:23:05 -08:00
|
|
|
JS_ASSERT(!jsdhook->pc || jsdhook->pc == (uintptr_t)pc);
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_ASSERT(jsdhook->jsdscript->script == script);
|
|
|
|
JS_ASSERT(jsdhook->jsdscript->jsdc == jsdc);
|
|
|
|
|
|
|
|
hook = jsdhook->hook;
|
|
|
|
hookData = jsdhook->callerdata;
|
|
|
|
jsdscript = jsdhook->jsdscript;
|
|
|
|
|
|
|
|
/* do not use jsdhook-> after this point */
|
|
|
|
JSD_UNLOCK();
|
|
|
|
|
|
|
|
if( ! jsdc || ! jsdc->inited )
|
|
|
|
return JSTRAP_CONTINUE;
|
|
|
|
|
|
|
|
if( JSD_IS_DANGEROUS_THREAD(jsdc) )
|
|
|
|
return JSTRAP_CONTINUE;
|
|
|
|
|
|
|
|
#ifdef LIVEWIRE
|
2012-01-11 00:23:05 -08:00
|
|
|
if( ! jsdlw_UserCodeAtPC(jsdc, jsdscript, (uintptr_t)pc) )
|
2007-03-22 10:30:00 -07:00
|
|
|
return JSTRAP_CONTINUE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return jsd_CallExecutionHook(jsdc, cx, JSD_HOOK_BREAKPOINT,
|
|
|
|
hook, hookData, rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_SetExecutionHook(JSDContext* jsdc,
|
|
|
|
JSDScript* jsdscript,
|
2012-01-11 00:23:05 -08:00
|
|
|
uintptr_t pc,
|
2007-03-22 10:30:00 -07:00
|
|
|
JSD_ExecutionHookProc hook,
|
|
|
|
void* callerdata)
|
|
|
|
{
|
|
|
|
JSDExecHook* jsdhook;
|
2011-01-27 18:31:48 -08:00
|
|
|
JSBool rv;
|
2012-08-27 13:32:51 -07:00
|
|
|
JSCompartment* oldCompartment;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
JSD_LOCK();
|
2013-04-23 04:58:24 -07:00
|
|
|
|
|
|
|
if ( JS_GetScriptIsSelfHosted(jsdscript->script) )
|
|
|
|
{
|
|
|
|
JSD_UNLOCK();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if( ! hook )
|
|
|
|
{
|
|
|
|
jsd_ClearExecutionHook(jsdc, jsdscript, pc);
|
|
|
|
JSD_UNLOCK();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdhook = _findHook(jsdc, jsdscript, pc);
|
|
|
|
if( jsdhook )
|
|
|
|
{
|
|
|
|
jsdhook->hook = hook;
|
|
|
|
jsdhook->callerdata = callerdata;
|
2008-02-09 20:16:54 -08:00
|
|
|
JSD_UNLOCK();
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
/* else... */
|
|
|
|
|
|
|
|
jsdhook = (JSDExecHook*)calloc(1, sizeof(JSDExecHook));
|
2008-02-09 20:16:54 -08:00
|
|
|
if( ! jsdhook ) {
|
|
|
|
JSD_UNLOCK();
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_FALSE;
|
2008-02-09 20:16:54 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
jsdhook->jsdscript = jsdscript;
|
|
|
|
jsdhook->pc = pc;
|
|
|
|
jsdhook->hook = hook;
|
|
|
|
jsdhook->callerdata = callerdata;
|
|
|
|
|
2012-08-27 13:32:51 -07:00
|
|
|
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
|
2011-01-27 18:31:48 -08:00
|
|
|
|
|
|
|
rv = JS_SetTrap(jsdc->dumbContext, jsdscript->script,
|
|
|
|
(jsbytecode*)pc, jsd_TrapHandler,
|
|
|
|
PRIVATE_TO_JSVAL(jsdhook));
|
|
|
|
|
2012-08-27 13:32:51 -07:00
|
|
|
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
|
2011-01-27 18:31:48 -08:00
|
|
|
|
|
|
|
if ( ! rv ) {
|
2007-03-22 10:30:00 -07:00
|
|
|
free(jsdhook);
|
2008-02-09 20:16:54 -08:00
|
|
|
JSD_UNLOCK();
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_APPEND_LINK(&jsdhook->links, &jsdscript->hooks);
|
|
|
|
JSD_UNLOCK();
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_ClearExecutionHook(JSDContext* jsdc,
|
|
|
|
JSDScript* jsdscript,
|
2012-01-11 00:23:05 -08:00
|
|
|
uintptr_t pc)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-27 13:32:51 -07:00
|
|
|
JSCompartment* oldCompartment;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSDExecHook* jsdhook;
|
|
|
|
|
|
|
|
JSD_LOCK();
|
|
|
|
|
|
|
|
jsdhook = _findHook(jsdc, jsdscript, pc);
|
|
|
|
if( ! jsdhook )
|
|
|
|
{
|
|
|
|
JSD_UNLOCK();
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-27 13:32:51 -07:00
|
|
|
oldCompartment = JS_EnterCompartmentOfScript(jsdc->dumbContext, jsdscript->script);
|
2011-01-27 18:31:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_ClearTrap(jsdc->dumbContext, jsdscript->script,
|
|
|
|
(jsbytecode*)pc, NULL, NULL );
|
|
|
|
|
2012-08-27 13:32:51 -07:00
|
|
|
JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
|
2011-01-27 18:31:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_REMOVE_LINK(&jsdhook->links);
|
|
|
|
free(jsdhook);
|
|
|
|
|
|
|
|
JSD_UNLOCK();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_ClearAllExecutionHooksForScript(JSDContext* jsdc, JSDScript* jsdscript)
|
|
|
|
{
|
|
|
|
JSDExecHook* jsdhook;
|
|
|
|
JSCList* list = &jsdscript->hooks;
|
|
|
|
|
|
|
|
JSD_LOCK();
|
|
|
|
|
|
|
|
while( (JSDExecHook*)list != (jsdhook = (JSDExecHook*)list->next) )
|
|
|
|
{
|
|
|
|
JS_REMOVE_LINK(&jsdhook->links);
|
|
|
|
free(jsdhook);
|
|
|
|
}
|
|
|
|
|
2011-01-27 18:31:48 -08:00
|
|
|
/* No cross-compartment call here because we may be in the middle of GC */
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_ClearScriptTraps(jsdc->dumbContext, jsdscript->script);
|
|
|
|
JSD_UNLOCK();
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool
|
|
|
|
jsd_ClearAllExecutionHooks(JSDContext* jsdc)
|
|
|
|
{
|
|
|
|
JSDScript* jsdscript;
|
|
|
|
JSDScript* iterp = NULL;
|
|
|
|
|
|
|
|
JSD_LOCK();
|
|
|
|
while( NULL != (jsdscript = jsd_IterateScripts(jsdc, &iterp)) )
|
|
|
|
jsd_ClearAllExecutionHooksForScript(jsdc, jsdscript);
|
|
|
|
JSD_UNLOCK();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsd_ScriptCreated(JSDContext* jsdc,
|
|
|
|
JSContext *cx,
|
|
|
|
const char *filename, /* URL this script loads from */
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned lineno, /* line where this script starts */
|
2007-03-22 10:30:00 -07:00
|
|
|
JSScript *script,
|
|
|
|
JSFunction *fun)
|
|
|
|
{
|
|
|
|
jsd_NewScriptHookProc(cx, filename, lineno, script, fun, jsdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jsd_ScriptDestroyed(JSDContext* jsdc,
|
2012-04-27 11:49:57 -07:00
|
|
|
JSFreeOp *fop,
|
2007-03-22 10:30:00 -07:00
|
|
|
JSScript *script)
|
|
|
|
{
|
2012-04-27 11:49:57 -07:00
|
|
|
jsd_DestroyScriptHookProc(fop, script, jsdc);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|