2009-06-10 18:29:44 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2010-06-10 10:48:59 -07:00
|
|
|
* vim: set ts=8 sw=4 et tw=99:
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* JS debugging API.
|
|
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
#include "jstypes.h"
|
2009-03-18 11:38:16 -07:00
|
|
|
#include "jsstdint.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsutil.h" /* Added by JSIFY */
|
2008-03-24 01:06:39 -07:00
|
|
|
#include "jsclist.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jscntxt.h"
|
2008-09-05 10:19:17 -07:00
|
|
|
#include "jsversion.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsdbgapi.h"
|
2007-11-29 06:49:42 -08:00
|
|
|
#include "jsemit.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsfun.h"
|
|
|
|
#include "jsgc.h"
|
|
|
|
#include "jsinterp.h"
|
|
|
|
#include "jslock.h"
|
|
|
|
#include "jsobj.h"
|
|
|
|
#include "jsopcode.h"
|
2007-11-29 06:49:42 -08:00
|
|
|
#include "jsparse.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsscope.h"
|
|
|
|
#include "jsscript.h"
|
2009-06-08 13:35:43 -07:00
|
|
|
#include "jsstaticcheck.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsstr.h"
|
|
|
|
|
2009-07-13 14:55:04 -07:00
|
|
|
#include "jsatominlines.h"
|
2010-03-30 14:42:48 -07:00
|
|
|
#include "jsobjinlines.h"
|
2009-12-01 12:49:15 -08:00
|
|
|
#include "jsscopeinlines.h"
|
2009-07-13 14:55:04 -07:00
|
|
|
|
2008-06-20 02:55:49 -07:00
|
|
|
#include "jsautooplen.h"
|
|
|
|
|
2010-01-22 14:49:18 -08:00
|
|
|
using namespace js;
|
|
|
|
|
2008-03-24 01:06:39 -07:00
|
|
|
typedef struct JSTrap {
|
|
|
|
JSCList links;
|
|
|
|
JSScript *script;
|
|
|
|
jsbytecode *pc;
|
|
|
|
JSOp op;
|
|
|
|
JSTrapHandler handler;
|
2010-04-30 17:34:54 -07:00
|
|
|
jsval closure;
|
2008-03-24 01:06:39 -07:00
|
|
|
} JSTrap;
|
|
|
|
|
|
|
|
#define DBG_LOCK(rt) JS_ACQUIRE_LOCK((rt)->debuggerLock)
|
|
|
|
#define DBG_UNLOCK(rt) JS_RELEASE_LOCK((rt)->debuggerLock)
|
|
|
|
#define DBG_LOCK_EVAL(rt,expr) (DBG_LOCK(rt), (expr), DBG_UNLOCK(rt))
|
2008-01-16 12:42:50 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* NB: FindTrap must be called with rt->debuggerLock acquired.
|
|
|
|
*/
|
|
|
|
static JSTrap *
|
|
|
|
FindTrap(JSRuntime *rt, JSScript *script, jsbytecode *pc)
|
|
|
|
{
|
|
|
|
JSTrap *trap;
|
|
|
|
|
|
|
|
for (trap = (JSTrap *)rt->trapList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&trap->links != &rt->trapList;
|
2007-03-22 10:30:00 -07:00
|
|
|
trap = (JSTrap *)trap->links.next) {
|
|
|
|
if (trap->script == script && trap->pc == pc)
|
|
|
|
return trap;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-24 01:06:39 -07:00
|
|
|
jsbytecode *
|
|
|
|
js_UntrapScriptCode(JSContext *cx, JSScript *script)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-24 01:06:39 -07:00
|
|
|
jsbytecode *code;
|
|
|
|
JSRuntime *rt;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSTrap *trap;
|
|
|
|
|
2008-03-24 01:06:39 -07:00
|
|
|
code = script->code;
|
|
|
|
rt = cx->runtime;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
for (trap = (JSTrap *)rt->trapList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&trap->links !=
|
|
|
|
&rt->trapList;
|
2008-03-24 01:06:39 -07:00
|
|
|
trap = (JSTrap *)trap->links.next) {
|
2008-05-03 21:20:23 -07:00
|
|
|
if (trap->script == script &&
|
|
|
|
(size_t)(trap->pc - script->code) < script->length) {
|
2008-03-24 01:06:39 -07:00
|
|
|
if (code == script->code) {
|
2008-04-24 11:59:14 -07:00
|
|
|
jssrcnote *sn, *notes;
|
|
|
|
size_t nbytes;
|
|
|
|
|
|
|
|
nbytes = script->length * sizeof(jsbytecode);
|
2009-09-09 16:52:55 -07:00
|
|
|
notes = script->notes();
|
2008-04-24 11:59:14 -07:00
|
|
|
for (sn = notes; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn))
|
|
|
|
continue;
|
|
|
|
nbytes += (sn - notes + 1) * sizeof *sn;
|
|
|
|
|
2009-07-27 21:10:12 -07:00
|
|
|
code = (jsbytecode *) cx->malloc(nbytes);
|
2008-03-24 01:06:39 -07:00
|
|
|
if (!code)
|
|
|
|
break;
|
2008-04-24 11:59:14 -07:00
|
|
|
memcpy(code, script->code, nbytes);
|
2009-03-24 05:07:35 -07:00
|
|
|
JS_PURGE_GSN_CACHE(cx);
|
2008-03-24 01:06:39 -07:00
|
|
|
}
|
|
|
|
code[trap->pc - script->code] = trap->op;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
return code;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
|
2010-04-30 17:34:54 -07:00
|
|
|
JSTrapHandler handler, jsval closure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSTrap *junk, *trap, *twin;
|
|
|
|
JSRuntime *rt;
|
|
|
|
uint32 sample;
|
|
|
|
|
2009-10-18 17:41:24 -07:00
|
|
|
if (script == JSScript::emptyScript()) {
|
|
|
|
JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, js_GetErrorMessage,
|
|
|
|
NULL, JSMSG_READ_ONLY, "empty script");
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-22 18:11:51 -07:00
|
|
|
JS_ASSERT((JSOp) *pc != JSOP_TRAP);
|
2007-03-22 10:30:00 -07:00
|
|
|
junk = NULL;
|
|
|
|
rt = cx->runtime;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
trap = FindTrap(rt, script, pc);
|
|
|
|
if (trap) {
|
|
|
|
JS_ASSERT(trap->script == script && trap->pc == pc);
|
|
|
|
JS_ASSERT(*pc == JSOP_TRAP);
|
|
|
|
} else {
|
|
|
|
sample = rt->debuggerMutations;
|
|
|
|
DBG_UNLOCK(rt);
|
2009-07-27 21:10:12 -07:00
|
|
|
trap = (JSTrap *) cx->malloc(sizeof *trap);
|
2008-04-29 14:24:01 -07:00
|
|
|
if (!trap)
|
|
|
|
return JS_FALSE;
|
2010-04-30 17:34:54 -07:00
|
|
|
trap->closure = JSVAL_NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
DBG_LOCK(rt);
|
|
|
|
twin = (rt->debuggerMutations != sample)
|
|
|
|
? FindTrap(rt, script, pc)
|
|
|
|
: NULL;
|
|
|
|
if (twin) {
|
|
|
|
junk = trap;
|
|
|
|
trap = twin;
|
|
|
|
} else {
|
|
|
|
JS_APPEND_LINK(&trap->links, &rt->trapList);
|
|
|
|
++rt->debuggerMutations;
|
|
|
|
trap->script = script;
|
|
|
|
trap->pc = pc;
|
|
|
|
trap->op = (JSOp)*pc;
|
|
|
|
*pc = JSOP_TRAP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
trap->handler = handler;
|
|
|
|
trap->closure = closure;
|
|
|
|
DBG_UNLOCK(rt);
|
2009-11-12 14:13:25 -08:00
|
|
|
if (junk)
|
2009-07-27 21:10:12 -07:00
|
|
|
cx->free(junk);
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSOp)
|
|
|
|
JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc)
|
|
|
|
{
|
2008-02-17 17:32:12 -08:00
|
|
|
JSRuntime *rt;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSTrap *trap;
|
2008-02-17 17:32:12 -08:00
|
|
|
JSOp op;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-17 17:32:12 -08:00
|
|
|
rt = cx->runtime;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
trap = FindTrap(rt, script, pc);
|
|
|
|
op = trap ? trap->op : (JSOp) *pc;
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
return op;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DestroyTrapAndUnlock(JSContext *cx, JSTrap *trap)
|
|
|
|
{
|
|
|
|
++cx->runtime->debuggerMutations;
|
|
|
|
JS_REMOVE_LINK(&trap->links);
|
|
|
|
*trap->pc = (jsbytecode)trap->op;
|
|
|
|
DBG_UNLOCK(cx->runtime);
|
2009-07-27 21:10:12 -07:00
|
|
|
cx->free(trap);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
|
2010-04-30 17:34:54 -07:00
|
|
|
JSTrapHandler *handlerp, jsval *closurep)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSTrap *trap;
|
|
|
|
|
|
|
|
DBG_LOCK(cx->runtime);
|
|
|
|
trap = FindTrap(cx->runtime, script, pc);
|
|
|
|
if (handlerp)
|
|
|
|
*handlerp = trap ? trap->handler : NULL;
|
|
|
|
if (closurep)
|
2010-04-30 17:34:54 -07:00
|
|
|
*closurep = trap ? trap->closure : JSVAL_NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (trap)
|
|
|
|
DestroyTrapAndUnlock(cx, trap);
|
|
|
|
else
|
|
|
|
DBG_UNLOCK(cx->runtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_ClearScriptTraps(JSContext *cx, JSScript *script)
|
|
|
|
{
|
|
|
|
JSRuntime *rt;
|
|
|
|
JSTrap *trap, *next;
|
|
|
|
uint32 sample;
|
|
|
|
|
|
|
|
rt = cx->runtime;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
for (trap = (JSTrap *)rt->trapList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&trap->links != &rt->trapList;
|
2007-03-22 10:30:00 -07:00
|
|
|
trap = next) {
|
|
|
|
next = (JSTrap *)trap->links.next;
|
|
|
|
if (trap->script == script) {
|
|
|
|
sample = rt->debuggerMutations;
|
|
|
|
DestroyTrapAndUnlock(cx, trap);
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
if (rt->debuggerMutations != sample + 1)
|
|
|
|
next = (JSTrap *)rt->trapList.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_ClearAllTraps(JSContext *cx)
|
|
|
|
{
|
|
|
|
JSRuntime *rt;
|
|
|
|
JSTrap *trap, *next;
|
|
|
|
uint32 sample;
|
|
|
|
|
|
|
|
rt = cx->runtime;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
for (trap = (JSTrap *)rt->trapList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&trap->links != &rt->trapList;
|
2007-03-22 10:30:00 -07:00
|
|
|
trap = next) {
|
|
|
|
next = (JSTrap *)trap->links.next;
|
|
|
|
sample = rt->debuggerMutations;
|
|
|
|
DestroyTrapAndUnlock(cx, trap);
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
if (rt->debuggerMutations != sample + 1)
|
|
|
|
next = (JSTrap *)rt->trapList.next;
|
|
|
|
}
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
}
|
|
|
|
|
2009-11-12 14:13:25 -08:00
|
|
|
/*
|
|
|
|
* NB: js_MarkTraps does not acquire cx->runtime->debuggerLock, since the
|
|
|
|
* debugger should never be racing with the GC (i.e., the debugger must
|
|
|
|
* respect the request model).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
js_MarkTraps(JSTracer *trc)
|
|
|
|
{
|
|
|
|
JSRuntime *rt = trc->context->runtime;
|
|
|
|
|
|
|
|
for (JSTrap *trap = (JSTrap *) rt->trapList.next;
|
|
|
|
&trap->links != &rt->trapList;
|
|
|
|
trap = (JSTrap *) trap->links.next) {
|
2010-07-14 23:19:36 -07:00
|
|
|
MarkValue(trc, Valueify(trap->closure), "trap->closure");
|
2009-11-12 14:13:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_PUBLIC_API(JSTrapStatus)
|
|
|
|
JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval)
|
|
|
|
{
|
|
|
|
JSTrap *trap;
|
|
|
|
jsint op;
|
|
|
|
JSTrapStatus status;
|
|
|
|
|
|
|
|
DBG_LOCK(cx->runtime);
|
|
|
|
trap = FindTrap(cx->runtime, script, pc);
|
|
|
|
JS_ASSERT(!trap || trap->handler);
|
|
|
|
if (!trap) {
|
|
|
|
op = (JSOp) *pc;
|
|
|
|
DBG_UNLOCK(cx->runtime);
|
|
|
|
|
|
|
|
/* Defend against "pc for wrong script" API usage error. */
|
|
|
|
JS_ASSERT(op != JSOP_TRAP);
|
|
|
|
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/* If the API was abused, we must fail for want of the real op. */
|
|
|
|
if (op == JSOP_TRAP)
|
|
|
|
return JSTRAP_ERROR;
|
|
|
|
|
|
|
|
/* Assume a race with a debugger thread and try to carry on. */
|
|
|
|
*rval = INT_TO_JSVAL(op);
|
|
|
|
return JSTRAP_CONTINUE;
|
|
|
|
#else
|
|
|
|
/* Always fail if single-threaded (must be an API usage error). */
|
|
|
|
return JSTRAP_ERROR;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
DBG_UNLOCK(cx->runtime);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It's important that we not use 'trap->' after calling the callback --
|
|
|
|
* the callback might remove the trap!
|
|
|
|
*/
|
|
|
|
op = (jsint)trap->op;
|
|
|
|
status = trap->handler(cx, script, pc, rval, trap->closure);
|
|
|
|
if (status == JSTRAP_CONTINUE) {
|
|
|
|
/* By convention, return the true op to the interpreter in rval. */
|
|
|
|
*rval = INT_TO_JSVAL(op);
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-11-13 09:04:23 -08:00
|
|
|
#ifdef JS_TRACER
|
|
|
|
static void
|
|
|
|
JITInhibitingHookChange(JSRuntime *rt, bool wasInhibited)
|
|
|
|
{
|
|
|
|
if (wasInhibited) {
|
|
|
|
if (!rt->debuggerInhibitsJIT()) {
|
|
|
|
for (JSCList *cl = rt->contextList.next; cl != &rt->contextList; cl = cl->next)
|
|
|
|
js_ContextFromLinkField(cl)->updateJITEnabled();
|
|
|
|
}
|
|
|
|
} else if (rt->debuggerInhibitsJIT()) {
|
|
|
|
for (JSCList *cl = rt->contextList.next; cl != &rt->contextList; cl = cl->next)
|
|
|
|
js_ContextFromLinkField(cl)->jitEnabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LeaveTraceRT(JSRuntime *rt)
|
|
|
|
{
|
|
|
|
JSThreadData *data = js_CurrentThreadData(rt);
|
|
|
|
JSContext *cx = data ? data->traceMonitor.tracecx : NULL;
|
|
|
|
JS_UNLOCK_GC(rt);
|
|
|
|
|
|
|
|
if (cx)
|
2010-01-22 14:49:18 -08:00
|
|
|
LeaveTrace(cx);
|
2009-11-13 09:04:23 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_PUBLIC_API(JSBool)
|
2010-04-30 17:34:54 -07:00
|
|
|
JS_SetInterrupt(JSRuntime *rt, JSInterruptHook hook, void *closure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-11-13 09:04:23 -08:00
|
|
|
#ifdef JS_TRACER
|
2010-04-08 05:54:18 -07:00
|
|
|
{
|
|
|
|
AutoLockGC lock(rt);
|
|
|
|
bool wasInhibited = rt->debuggerInhibitsJIT();
|
2009-11-13 09:04:23 -08:00
|
|
|
#endif
|
2010-04-30 17:34:54 -07:00
|
|
|
rt->globalDebugHooks.interruptHook = hook;
|
|
|
|
rt->globalDebugHooks.interruptHookData = closure;
|
2009-11-13 09:04:23 -08:00
|
|
|
#ifdef JS_TRACER
|
2010-04-08 05:54:18 -07:00
|
|
|
JITInhibitingHookChange(rt, wasInhibited);
|
|
|
|
}
|
2009-11-13 09:04:23 -08:00
|
|
|
LeaveTraceRT(rt);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
2010-04-30 17:34:54 -07:00
|
|
|
JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *hoop, void **closurep)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-11-13 09:04:23 -08:00
|
|
|
#ifdef JS_TRACER
|
2010-04-08 05:54:18 -07:00
|
|
|
AutoLockGC lock(rt);
|
2009-11-13 09:04:23 -08:00
|
|
|
bool wasInhibited = rt->debuggerInhibitsJIT();
|
|
|
|
#endif
|
2010-04-30 17:34:54 -07:00
|
|
|
if (hoop)
|
|
|
|
*hoop = rt->globalDebugHooks.interruptHook;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (closurep)
|
2010-04-30 17:34:54 -07:00
|
|
|
*closurep = rt->globalDebugHooks.interruptHookData;
|
|
|
|
rt->globalDebugHooks.interruptHook = 0;
|
|
|
|
rt->globalDebugHooks.interruptHookData = 0;
|
2009-11-13 09:04:23 -08:00
|
|
|
#ifdef JS_TRACER
|
|
|
|
JITInhibitingHookChange(rt, wasInhibited);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
typedef struct JSWatchPoint {
|
|
|
|
JSCList links;
|
|
|
|
JSObject *object; /* weak link, see js_FinalizeObject */
|
|
|
|
JSScopeProperty *sprop;
|
2010-07-14 23:19:36 -07:00
|
|
|
PropertyOp setter;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSWatchPointHandler handler;
|
2009-09-07 00:35:27 -07:00
|
|
|
JSObject *closure;
|
2007-03-22 10:30:00 -07:00
|
|
|
uintN flags;
|
|
|
|
} JSWatchPoint;
|
|
|
|
|
|
|
|
#define JSWP_LIVE 0x1 /* live because set and not cleared */
|
|
|
|
#define JSWP_HELD 0x2 /* held while running handler/setter */
|
|
|
|
|
2009-12-01 12:49:15 -08:00
|
|
|
static bool
|
|
|
|
IsWatchedProperty(JSContext *cx, JSScopeProperty *sprop);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* NB: DropWatchPointAndUnlock releases cx->runtime->debuggerLock in all cases.
|
|
|
|
*/
|
|
|
|
static JSBool
|
|
|
|
DropWatchPointAndUnlock(JSContext *cx, JSWatchPoint *wp, uintN flag)
|
|
|
|
{
|
2009-12-01 12:49:15 -08:00
|
|
|
JSBool ok;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSScopeProperty *sprop;
|
2008-01-04 17:28:29 -08:00
|
|
|
JSScope *scope;
|
2010-07-14 23:19:36 -07:00
|
|
|
PropertyOp setter;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
ok = JS_TRUE;
|
|
|
|
wp->flags &= ~flag;
|
|
|
|
if (wp->flags != 0) {
|
|
|
|
DBG_UNLOCK(cx->runtime);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove wp from the list, then if there are no other watchpoints for
|
|
|
|
* wp->sprop in any scope, restore wp->sprop->setter from wp.
|
|
|
|
*/
|
|
|
|
++cx->runtime->debuggerMutations;
|
|
|
|
JS_REMOVE_LINK(&wp->links);
|
|
|
|
sprop = wp->sprop;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Passing null for the scope parameter tells js_GetWatchedSetter to find
|
|
|
|
* any watch point for sprop, and not to lock or unlock rt->debuggerLock.
|
|
|
|
* If js_ChangeNativePropertyAttrs fails, propagate failure after removing
|
|
|
|
* wp->closure's root and freeing wp.
|
|
|
|
*/
|
|
|
|
setter = js_GetWatchedSetter(cx->runtime, NULL, sprop);
|
|
|
|
DBG_UNLOCK(cx->runtime);
|
|
|
|
if (!setter) {
|
2008-01-04 17:28:29 -08:00
|
|
|
JS_LOCK_OBJ(cx, wp->object);
|
2010-04-08 11:22:04 -07:00
|
|
|
scope = wp->object->scope();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
2009-12-01 12:49:15 -08:00
|
|
|
* If the property wasn't found on wp->object, or it isn't still being
|
|
|
|
* watched, then someone else must have deleted or unwatched it, and we
|
|
|
|
* don't need to change the property attributes.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2009-12-01 12:49:15 -08:00
|
|
|
JSScopeProperty *wprop = scope->lookup(sprop->id);
|
|
|
|
if (wprop &&
|
2010-03-08 14:44:59 -08:00
|
|
|
wprop->hasSetterValue() == sprop->hasSetterValue() &&
|
2009-12-01 12:49:15 -08:00
|
|
|
IsWatchedProperty(cx, wprop)) {
|
2010-03-08 14:44:59 -08:00
|
|
|
sprop = scope->changeProperty(cx, wprop, 0, wprop->attributes(),
|
2010-02-24 17:40:28 -08:00
|
|
|
wprop->getter(), wp->setter);
|
2008-01-04 17:28:29 -08:00
|
|
|
if (!sprop)
|
|
|
|
ok = JS_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-12-01 12:49:15 -08:00
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-27 21:10:12 -07:00
|
|
|
cx->free(wp);
|
2007-03-22 10:30:00 -07:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-04-16 23:53:37 -07:00
|
|
|
* NB: js_TraceWatchPoints does not acquire cx->runtime->debuggerLock, since
|
2007-03-22 10:30:00 -07:00
|
|
|
* the debugger should never be racing with the GC (i.e., the debugger must
|
|
|
|
* respect the request model).
|
|
|
|
*/
|
|
|
|
void
|
2007-09-07 14:02:20 -07:00
|
|
|
js_TraceWatchPoints(JSTracer *trc, JSObject *obj)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSRuntime *rt;
|
|
|
|
JSWatchPoint *wp;
|
|
|
|
|
2007-04-16 23:53:37 -07:00
|
|
|
rt = trc->context->runtime;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&wp->links != &rt->watchPointList;
|
2007-03-22 10:30:00 -07:00
|
|
|
wp = (JSWatchPoint *)wp->links.next) {
|
2007-09-07 14:02:20 -07:00
|
|
|
if (wp->object == obj) {
|
2009-07-28 02:00:35 -07:00
|
|
|
wp->sprop->trace(trc);
|
2010-04-30 16:03:37 -07:00
|
|
|
if (wp->sprop->hasSetterValue() && wp->setter)
|
|
|
|
JS_CALL_OBJECT_TRACER(trc, CastAsObject(wp->setter), "wp->setter");
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_CALL_OBJECT_TRACER(trc, wp->closure, "wp->closure");
|
2007-09-07 14:02:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
js_SweepWatchPoints(JSContext *cx)
|
|
|
|
{
|
|
|
|
JSRuntime *rt;
|
|
|
|
JSWatchPoint *wp, *next;
|
|
|
|
uint32 sample;
|
|
|
|
|
|
|
|
rt = cx->runtime;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&wp->links != &rt->watchPointList;
|
2007-09-07 14:02:20 -07:00
|
|
|
wp = next) {
|
|
|
|
next = (JSWatchPoint *)wp->links.next;
|
2009-12-13 23:55:17 -08:00
|
|
|
if (js_IsAboutToBeFinalized(wp->object)) {
|
2007-09-07 14:02:20 -07:00
|
|
|
sample = rt->debuggerMutations;
|
|
|
|
|
|
|
|
/* Ignore failures. */
|
|
|
|
DropWatchPointAndUnlock(cx, wp, JSWP_LIVE);
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
if (rt->debuggerMutations != sample + 1)
|
|
|
|
next = (JSWatchPoint *)rt->watchPointList.next;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-09-07 14:02:20 -07:00
|
|
|
DBG_UNLOCK(rt);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-09-07 14:02:20 -07:00
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* NB: FindWatchPoint must be called with rt->debuggerLock acquired.
|
|
|
|
*/
|
|
|
|
static JSWatchPoint *
|
2010-06-02 16:01:36 -07:00
|
|
|
FindWatchPoint(JSRuntime *rt, JSScope *scope, jsid id)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSWatchPoint *wp;
|
|
|
|
|
|
|
|
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&wp->links != &rt->watchPointList;
|
2007-03-22 10:30:00 -07:00
|
|
|
wp = (JSWatchPoint *)wp->links.next) {
|
2010-04-08 11:22:04 -07:00
|
|
|
if (wp->object->scope() == scope && wp->sprop->id == id)
|
2007-03-22 10:30:00 -07:00
|
|
|
return wp;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSScopeProperty *
|
2010-06-02 16:01:36 -07:00
|
|
|
js_FindWatchPoint(JSRuntime *rt, JSScope *scope, jsid id)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSWatchPoint *wp;
|
|
|
|
JSScopeProperty *sprop;
|
|
|
|
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
wp = FindWatchPoint(rt, scope, id);
|
|
|
|
sprop = wp ? wp->sprop : NULL;
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
return sprop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Secret handshake with DropWatchPointAndUnlock: if (!scope), we know our
|
|
|
|
* caller has acquired rt->debuggerLock, so we don't have to.
|
|
|
|
*/
|
2010-07-14 23:19:36 -07:00
|
|
|
PropertyOp
|
2007-03-22 10:30:00 -07:00
|
|
|
js_GetWatchedSetter(JSRuntime *rt, JSScope *scope,
|
|
|
|
const JSScopeProperty *sprop)
|
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
PropertyOp setter;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSWatchPoint *wp;
|
|
|
|
|
|
|
|
setter = NULL;
|
|
|
|
if (scope)
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&wp->links != &rt->watchPointList;
|
2007-03-22 10:30:00 -07:00
|
|
|
wp = (JSWatchPoint *)wp->links.next) {
|
2010-04-08 11:22:04 -07:00
|
|
|
if ((!scope || wp->object->scope() == scope) && wp->sprop == sprop) {
|
2007-03-22 10:30:00 -07:00
|
|
|
setter = wp->setter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scope)
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
return setter;
|
|
|
|
}
|
|
|
|
|
2008-09-06 15:21:43 -07:00
|
|
|
JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_watch_set(JSContext *cx, JSObject *obj, jsid id, Value *vp)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-03 17:52:26 -08:00
|
|
|
JSRuntime *rt = cx->runtime;
|
2007-03-22 10:30:00 -07:00
|
|
|
DBG_LOCK(rt);
|
2010-03-03 17:52:26 -08:00
|
|
|
for (JSWatchPoint *wp = (JSWatchPoint *)rt->watchPointList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&wp->links != &rt->watchPointList;
|
2007-03-22 10:30:00 -07:00
|
|
|
wp = (JSWatchPoint *)wp->links.next) {
|
2010-03-03 17:52:26 -08:00
|
|
|
JSScopeProperty *sprop = wp->sprop;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (wp->object == obj && SPROP_USERID(sprop) == id &&
|
|
|
|
!(wp->flags & JSWP_HELD)) {
|
|
|
|
wp->flags |= JSWP_HELD;
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
|
|
|
|
JS_LOCK_OBJ(cx, obj);
|
2010-07-14 23:19:36 -07:00
|
|
|
jsid propid = sprop->id;
|
|
|
|
jsid userid = SPROP_USERID(sprop);
|
2010-03-03 17:52:26 -08:00
|
|
|
JSScope *scope = obj->scope();
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_UNLOCK_OBJ(cx, obj);
|
|
|
|
|
|
|
|
/* NB: wp is held, so we can safely dereference it still. */
|
2010-03-03 17:52:26 -08:00
|
|
|
if (!wp->handler(cx, obj, propid,
|
2007-03-22 10:30:00 -07:00
|
|
|
SPROP_HAS_VALID_SLOT(sprop, scope)
|
2010-07-14 23:19:36 -07:00
|
|
|
? Jsvalify(obj->getSlotMT(cx, sprop->slot))
|
2007-03-22 10:30:00 -07:00
|
|
|
: JSVAL_VOID,
|
2010-07-14 23:19:36 -07:00
|
|
|
Jsvalify(vp), wp->closure)) {
|
2010-03-03 17:52:26 -08:00
|
|
|
DBG_LOCK(rt);
|
|
|
|
DropWatchPointAndUnlock(cx, wp, JSWP_HELD);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a pseudo-frame for the setter invocation so that any
|
|
|
|
* stack-walking security code under the setter will correctly
|
|
|
|
* identify the guilty party. So that the watcher appears to
|
|
|
|
* be active to obj_eval and other such code, point frame.pc
|
|
|
|
* at the JSOP_STOP at the end of the script.
|
|
|
|
*
|
|
|
|
* The pseudo-frame is not created for fast natives as they
|
|
|
|
* are treated as interpreter frame extensions and always
|
|
|
|
* trusted.
|
|
|
|
*/
|
|
|
|
JSObject *closure = wp->closure;
|
2010-07-14 23:19:36 -07:00
|
|
|
Class *clasp = closure->getClass();
|
2010-03-03 17:52:26 -08:00
|
|
|
JSFunction *fun;
|
|
|
|
JSScript *script;
|
|
|
|
if (clasp == &js_FunctionClass) {
|
|
|
|
fun = GET_FUNCTION_PRIVATE(cx, closure);
|
|
|
|
script = FUN_SCRIPT(fun);
|
|
|
|
} else if (clasp == &js_ScriptClass) {
|
|
|
|
fun = NULL;
|
|
|
|
script = (JSScript *) closure->getPrivate();
|
|
|
|
} else {
|
|
|
|
fun = NULL;
|
|
|
|
script = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uintN vplen = 2;
|
|
|
|
if (fun)
|
|
|
|
vplen += fun->minArgs() + (fun->isInterpreted() ? 0 : fun->u.n.extra);
|
|
|
|
uintN nfixed = script ? script->nfixed : 0;
|
|
|
|
|
|
|
|
/* Destructor pops frame. */
|
|
|
|
JSFrameRegs regs;
|
|
|
|
ExecuteFrameGuard frame;
|
|
|
|
|
|
|
|
if (fun && !fun->isFastNative()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2010-03-03 17:52:26 -08:00
|
|
|
* Get a pointer to new frame/slots. This memory is not
|
|
|
|
* "claimed", so the code before pushExecuteFrame must not
|
|
|
|
* reenter the interpreter.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-03-03 17:52:26 -08:00
|
|
|
JSStackFrame *down = js_GetTopStackFrame(cx);
|
|
|
|
if (!cx->stack().getExecuteFrame(cx, down, vplen, nfixed, frame)) {
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
DropWatchPointAndUnlock(cx, wp, JSWP_HELD);
|
|
|
|
return JS_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-03 17:52:26 -08:00
|
|
|
/* Initialize slots/frame. */
|
2010-07-14 23:19:36 -07:00
|
|
|
Value *vp = frame.getvp();
|
|
|
|
MakeValueRangeGCSafe(vp, vplen);
|
|
|
|
vp[0].setObject(*closure);
|
|
|
|
vp[1].setNull(); // satisfy LeaveTree assert
|
2010-03-03 17:52:26 -08:00
|
|
|
JSStackFrame *fp = frame.getFrame();
|
|
|
|
PodZero(fp);
|
2010-07-14 23:19:36 -07:00
|
|
|
MakeValueRangeGCSafe(fp->slots(), nfixed);
|
2010-03-03 17:52:26 -08:00
|
|
|
fp->script = script;
|
|
|
|
fp->fun = fun;
|
|
|
|
fp->argv = vp + 2;
|
2010-08-12 21:47:46 -07:00
|
|
|
fp->scopeChain = closure->getParent();
|
2010-08-12 15:46:03 -07:00
|
|
|
fp->setArgsObj(NULL);
|
2010-03-03 18:10:13 -08:00
|
|
|
|
|
|
|
/* Initialize regs. */
|
|
|
|
regs.pc = script ? script->code : NULL;
|
|
|
|
regs.sp = fp->slots() + nfixed;
|
2010-03-03 17:52:26 -08:00
|
|
|
|
|
|
|
/* Officially push |fp|. |frame|'s destructor pops. */
|
2010-03-03 18:10:13 -08:00
|
|
|
cx->stack().pushExecuteFrame(cx, frame, regs, NULL);
|
2010-03-03 17:52:26 -08:00
|
|
|
|
|
|
|
/* Now that fp has been pushed, get the call object. */
|
|
|
|
if (script && fun && fun->isHeavyweight() &&
|
|
|
|
!js_GetCallObject(cx, fp)) {
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
DropWatchPointAndUnlock(cx, wp, JSWP_HELD);
|
|
|
|
return JS_FALSE;
|
2007-09-18 00:34:54 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-03 17:52:26 -08:00
|
|
|
|
|
|
|
JSBool ok = !wp->setter ||
|
|
|
|
(sprop->hasSetterValue()
|
2010-07-14 23:19:36 -07:00
|
|
|
? InternalCall(cx, obj,
|
|
|
|
ObjectValue(*CastAsObject(wp->setter)),
|
|
|
|
1, vp, vp)
|
2010-06-16 14:13:28 -07:00
|
|
|
: callJSPropertyOpSetter(cx, wp->setter, obj, userid, vp));
|
2010-03-03 17:52:26 -08:00
|
|
|
|
|
|
|
/* Evil code can cause us to have an arguments object. */
|
|
|
|
if (frame.getFrame())
|
|
|
|
frame.getFrame()->putActivationObjects(cx);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
DBG_LOCK(rt);
|
|
|
|
return DropWatchPointAndUnlock(cx, wp, JSWP_HELD) && ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-06-25 12:12:19 -07:00
|
|
|
JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_watch_set_wrapper(JSContext *cx, JSObject *obj, uintN argc, Value *argv,
|
|
|
|
Value *rval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSObject *funobj;
|
|
|
|
JSFunction *wrapper;
|
2010-07-14 23:19:36 -07:00
|
|
|
jsid userid;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
funobj = &argv[-2].toObject();
|
2008-03-28 15:27:36 -07:00
|
|
|
wrapper = GET_FUNCTION_PRIVATE(cx, funobj);
|
2010-07-14 23:19:36 -07:00
|
|
|
userid = ATOM_TO_JSID(wrapper->atom);
|
2007-03-22 10:30:00 -07:00
|
|
|
*rval = argv[0];
|
|
|
|
return js_watch_set(cx, obj, userid, rval);
|
|
|
|
}
|
|
|
|
|
2009-12-01 12:49:15 -08:00
|
|
|
static bool
|
|
|
|
IsWatchedProperty(JSContext *cx, JSScopeProperty *sprop)
|
|
|
|
{
|
2010-03-08 14:44:59 -08:00
|
|
|
if (sprop->hasSetterValue()) {
|
2010-02-24 17:40:28 -08:00
|
|
|
JSObject *funobj = sprop->setterObject();
|
2010-04-30 16:03:37 -07:00
|
|
|
if (!funobj || !funobj->isFunction())
|
2010-03-01 09:07:40 -08:00
|
|
|
return false;
|
2009-12-01 12:49:15 -08:00
|
|
|
|
2010-03-01 09:07:40 -08:00
|
|
|
JSFunction *fun = GET_FUNCTION_PRIVATE(cx, funobj);
|
2009-12-01 12:49:15 -08:00
|
|
|
return FUN_NATIVE(fun) == js_watch_set_wrapper;
|
|
|
|
}
|
2010-02-24 17:40:28 -08:00
|
|
|
return sprop->setterOp() == js_watch_set;
|
2009-12-01 12:49:15 -08:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
PropertyOp
|
|
|
|
js_WrapWatchedSetter(JSContext *cx, jsid id, uintN attrs, PropertyOp setter)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSAtom *atom;
|
2008-03-29 03:34:29 -07:00
|
|
|
JSFunction *wrapper;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!(attrs & JSPROP_SETTER))
|
|
|
|
return &js_watch_set; /* & to silence schoolmarmish MSVC */
|
|
|
|
|
|
|
|
if (JSID_IS_ATOM(id)) {
|
|
|
|
atom = JSID_TO_ATOM(id);
|
|
|
|
} else if (JSID_IS_INT(id)) {
|
2010-07-14 23:19:36 -07:00
|
|
|
if (!js_ValueToStringId(cx, IdToValue(id), &id))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NULL;
|
2008-01-23 05:17:47 -08:00
|
|
|
atom = JSID_TO_ATOM(id);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
atom = NULL;
|
|
|
|
}
|
2010-04-20 00:49:40 -07:00
|
|
|
|
2008-03-29 03:34:29 -07:00
|
|
|
wrapper = js_NewFunction(cx, NULL, js_watch_set_wrapper, 1, 0,
|
2010-04-30 16:03:37 -07:00
|
|
|
setter ? CastAsObject(setter)->getParent() : NULL, atom);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!wrapper)
|
|
|
|
return NULL;
|
2010-04-30 16:03:37 -07:00
|
|
|
return CastAsPropertyOp(FUN_OBJECT(wrapper));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id,
|
2007-03-22 10:30:00 -07:00
|
|
|
JSWatchPointHandler handler, void *closure)
|
|
|
|
{
|
2009-11-04 10:42:41 -08:00
|
|
|
JSObject *origobj;
|
2010-07-14 23:19:36 -07:00
|
|
|
Value v;
|
2009-11-04 10:42:41 -08:00
|
|
|
uintN attrs;
|
2007-03-22 10:30:00 -07:00
|
|
|
jsid propid;
|
|
|
|
JSObject *pobj;
|
|
|
|
JSProperty *prop;
|
|
|
|
JSScopeProperty *sprop;
|
|
|
|
JSRuntime *rt;
|
|
|
|
JSBool ok;
|
|
|
|
JSWatchPoint *wp;
|
2010-07-14 23:19:36 -07:00
|
|
|
PropertyOp watcher;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-11-04 10:42:41 -08:00
|
|
|
origobj = obj;
|
2010-06-01 15:59:02 -07:00
|
|
|
obj = obj->wrappedObject(cx);
|
2009-11-04 10:42:41 -08:00
|
|
|
OBJ_TO_INNER_OBJECT(cx, obj);
|
|
|
|
if (!obj)
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_FALSE;
|
|
|
|
|
2010-05-28 01:03:06 -07:00
|
|
|
AutoValueRooter idroot(cx);
|
2010-07-14 23:19:36 -07:00
|
|
|
if (JSID_IS_INT(id)) {
|
|
|
|
propid = id;
|
2009-01-23 00:50:35 -08:00
|
|
|
} else {
|
2010-07-14 23:19:36 -07:00
|
|
|
if (!js_ValueToStringId(cx, IdToValue(id), &propid))
|
2009-01-23 00:50:35 -08:00
|
|
|
return JS_FALSE;
|
2009-07-11 15:41:32 -07:00
|
|
|
propid = js_CheckForStringIndex(propid);
|
2010-07-14 23:19:36 -07:00
|
|
|
idroot.set(IdToValue(propid));
|
2009-01-23 00:50:35 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-11-04 10:42:41 -08:00
|
|
|
/*
|
|
|
|
* If, by unwrapping and innerizing, we changed the object, check
|
|
|
|
* again to make sure that we're allowed to set a watch point.
|
|
|
|
*/
|
2010-06-17 05:32:26 -07:00
|
|
|
if (origobj != obj && !CheckAccess(cx, obj, propid, JSACC_WATCH, &v, &attrs))
|
2009-11-04 10:42:41 -08:00
|
|
|
return JS_FALSE;
|
|
|
|
|
2010-03-31 22:13:51 -07:00
|
|
|
if (!obj->isNative()) {
|
2009-11-04 10:42:41 -08:00
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_WATCH,
|
2010-04-07 16:09:49 -07:00
|
|
|
obj->getClass()->name);
|
2009-11-04 10:42:41 -08:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!js_LookupProperty(cx, obj, propid, &pobj, &prop))
|
|
|
|
return JS_FALSE;
|
|
|
|
sprop = (JSScopeProperty *) prop;
|
|
|
|
rt = cx->runtime;
|
|
|
|
if (!sprop) {
|
|
|
|
/* Check for a deleted symbol watchpoint, which holds its property. */
|
2010-04-08 11:22:04 -07:00
|
|
|
sprop = js_FindWatchPoint(rt, obj->scope(), propid);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!sprop) {
|
|
|
|
/* Make a new property in obj so we can watch for the first set. */
|
2010-07-14 23:19:36 -07:00
|
|
|
if (!js_DefineNativeProperty(cx, obj, propid, UndefinedValue(), NULL, NULL,
|
2009-08-26 14:28:36 -07:00
|
|
|
JSPROP_ENUMERATE, 0, 0, &prop)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
sprop = (JSScopeProperty *) prop;
|
|
|
|
}
|
|
|
|
} else if (pobj != obj) {
|
|
|
|
/* Clone the prototype property so we can watch the right object. */
|
2010-05-28 01:03:06 -07:00
|
|
|
AutoValueRooter valroot(cx);
|
2010-07-14 23:19:36 -07:00
|
|
|
PropertyOp getter, setter;
|
2007-03-22 10:30:00 -07:00
|
|
|
uintN attrs, flags;
|
|
|
|
intN shortid;
|
|
|
|
|
2010-03-31 22:13:51 -07:00
|
|
|
if (pobj->isNative()) {
|
2010-05-28 01:03:06 -07:00
|
|
|
valroot.set(SPROP_HAS_VALID_SLOT(sprop, pobj->scope())
|
|
|
|
? pobj->lockedGetSlot(sprop->slot)
|
2010-07-14 23:19:36 -07:00
|
|
|
: UndefinedValue());
|
2010-02-24 17:40:28 -08:00
|
|
|
getter = sprop->getter();
|
|
|
|
setter = sprop->setter();
|
2010-03-08 14:44:59 -08:00
|
|
|
attrs = sprop->attributes();
|
2010-02-05 16:11:13 -08:00
|
|
|
flags = sprop->getFlags();
|
2007-03-22 10:30:00 -07:00
|
|
|
shortid = sprop->shortid;
|
2010-05-28 01:03:06 -07:00
|
|
|
JS_UNLOCK_OBJ(cx, pobj);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2010-05-28 01:03:06 -07:00
|
|
|
if (!pobj->getProperty(cx, propid, valroot.addr()) ||
|
2010-06-05 14:24:54 -07:00
|
|
|
!pobj->getAttributes(cx, propid, &attrs)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
getter = setter = NULL;
|
|
|
|
flags = 0;
|
|
|
|
shortid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recall that obj is native, whether or not pobj is native. */
|
2010-05-28 01:03:06 -07:00
|
|
|
if (!js_DefineNativeProperty(cx, obj, propid, valroot.value(),
|
|
|
|
getter, setter, attrs, flags,
|
|
|
|
shortid, &prop)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
sprop = (JSScopeProperty *) prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, prop/sprop exists in obj, obj is locked, and we must
|
2010-06-05 14:24:54 -07:00
|
|
|
* unlock the object before returning.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
ok = JS_TRUE;
|
|
|
|
DBG_LOCK(rt);
|
2010-04-08 11:22:04 -07:00
|
|
|
wp = FindWatchPoint(rt, obj->scope(), propid);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!wp) {
|
|
|
|
DBG_UNLOCK(rt);
|
2010-03-08 14:44:59 -08:00
|
|
|
watcher = js_WrapWatchedSetter(cx, propid, sprop->attributes(), sprop->setter());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!watcher) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-07-27 21:10:12 -07:00
|
|
|
wp = (JSWatchPoint *) cx->malloc(sizeof *wp);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!wp) {
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
wp->handler = NULL;
|
|
|
|
wp->closure = NULL;
|
|
|
|
wp->object = obj;
|
2010-02-24 17:40:28 -08:00
|
|
|
wp->setter = sprop->setter();
|
2007-03-22 10:30:00 -07:00
|
|
|
wp->flags = JSWP_LIVE;
|
|
|
|
|
|
|
|
/* XXXbe nest in obj lock here */
|
2010-03-08 14:44:59 -08:00
|
|
|
sprop = js_ChangeNativePropertyAttrs(cx, obj, sprop, 0, sprop->attributes(),
|
2010-02-24 17:40:28 -08:00
|
|
|
sprop->getter(), watcher);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!sprop) {
|
|
|
|
/* Self-link so DropWatchPointAndUnlock can JS_REMOVE_LINK it. */
|
|
|
|
JS_INIT_CLIST(&wp->links);
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
DropWatchPointAndUnlock(cx, wp, JSWP_LIVE);
|
|
|
|
ok = JS_FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
wp->sprop = sprop;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that wp is fully initialized, append it to rt's wp list.
|
|
|
|
* Because obj is locked we know that no other thread could have added
|
|
|
|
* a watchpoint for (obj, propid).
|
|
|
|
*/
|
|
|
|
DBG_LOCK(rt);
|
2010-04-08 11:22:04 -07:00
|
|
|
JS_ASSERT(!FindWatchPoint(rt, obj->scope(), propid));
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_APPEND_LINK(&wp->links, &rt->watchPointList);
|
|
|
|
++rt->debuggerMutations;
|
|
|
|
}
|
|
|
|
wp->handler = handler;
|
2009-09-07 00:35:27 -07:00
|
|
|
wp->closure = reinterpret_cast<JSObject*>(closure);
|
2007-03-22 10:30:00 -07:00
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
|
|
|
|
out:
|
2010-06-05 14:24:54 -07:00
|
|
|
JS_UNLOCK_OBJ(cx, obj);
|
2007-03-22 10:30:00 -07:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id,
|
2007-03-22 10:30:00 -07:00
|
|
|
JSWatchPointHandler *handlerp, void **closurep)
|
|
|
|
{
|
|
|
|
JSRuntime *rt;
|
|
|
|
JSWatchPoint *wp;
|
|
|
|
|
|
|
|
rt = cx->runtime;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&wp->links != &rt->watchPointList;
|
2007-03-22 10:30:00 -07:00
|
|
|
wp = (JSWatchPoint *)wp->links.next) {
|
|
|
|
if (wp->object == obj && SPROP_USERID(wp->sprop) == id) {
|
|
|
|
if (handlerp)
|
|
|
|
*handlerp = wp->handler;
|
|
|
|
if (closurep)
|
|
|
|
*closurep = wp->closure;
|
|
|
|
return DropWatchPointAndUnlock(cx, wp, JSWP_LIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
if (handlerp)
|
|
|
|
*handlerp = NULL;
|
|
|
|
if (closurep)
|
|
|
|
*closurep = NULL;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
JSRuntime *rt;
|
|
|
|
JSWatchPoint *wp, *next;
|
|
|
|
uint32 sample;
|
|
|
|
|
|
|
|
rt = cx->runtime;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&wp->links != &rt->watchPointList;
|
2007-03-22 10:30:00 -07:00
|
|
|
wp = next) {
|
|
|
|
next = (JSWatchPoint *)wp->links.next;
|
|
|
|
if (wp->object == obj) {
|
|
|
|
sample = rt->debuggerMutations;
|
|
|
|
if (!DropWatchPointAndUnlock(cx, wp, JSWP_LIVE))
|
|
|
|
return JS_FALSE;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
if (rt->debuggerMutations != sample + 1)
|
|
|
|
next = (JSWatchPoint *)rt->watchPointList.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ClearAllWatchPoints(JSContext *cx)
|
|
|
|
{
|
|
|
|
JSRuntime *rt;
|
|
|
|
JSWatchPoint *wp, *next;
|
|
|
|
uint32 sample;
|
|
|
|
|
|
|
|
rt = cx->runtime;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
2008-08-26 01:46:34 -07:00
|
|
|
&wp->links != &rt->watchPointList;
|
2007-03-22 10:30:00 -07:00
|
|
|
wp = next) {
|
|
|
|
next = (JSWatchPoint *)wp->links.next;
|
|
|
|
sample = rt->debuggerMutations;
|
|
|
|
if (!DropWatchPointAndUnlock(cx, wp, JSWP_LIVE))
|
|
|
|
return JS_FALSE;
|
|
|
|
DBG_LOCK(rt);
|
|
|
|
if (rt->debuggerMutations != sample + 1)
|
|
|
|
next = (JSWatchPoint *)rt->watchPointList.next;
|
|
|
|
}
|
|
|
|
DBG_UNLOCK(rt);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
JS_PUBLIC_API(uintN)
|
|
|
|
JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc)
|
|
|
|
{
|
|
|
|
return js_PCToLineNumber(cx, script, pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(jsbytecode *)
|
|
|
|
JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno)
|
|
|
|
{
|
|
|
|
return js_LineNumberToPC(script, lineno);
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_PUBLIC_API(uintN)
|
|
|
|
JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun)
|
|
|
|
{
|
|
|
|
return fun->nargs;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_FunctionHasLocalNames(JSContext *cx, JSFunction *fun)
|
|
|
|
{
|
|
|
|
return fun->hasLocalNames();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(jsuword *)
|
|
|
|
JS_GetFunctionLocalNameArray(JSContext *cx, JSFunction *fun, void **markp)
|
|
|
|
{
|
|
|
|
*markp = JS_ARENA_MARK(&cx->tempPool);
|
|
|
|
return js_GetLocalNameArray(cx, fun, &cx->tempPool);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSAtom *)
|
|
|
|
JS_LocalNameToAtom(jsuword w)
|
|
|
|
{
|
|
|
|
return JS_LOCAL_NAME_TO_ATOM(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_AtomKey(JSAtom *atom)
|
|
|
|
{
|
|
|
|
return ATOM_TO_STRING(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark)
|
|
|
|
{
|
|
|
|
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_PUBLIC_API(JSScript *)
|
|
|
|
JS_GetFunctionScript(JSContext *cx, JSFunction *fun)
|
|
|
|
{
|
2008-03-29 03:34:29 -07:00
|
|
|
return FUN_SCRIPT(fun);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSNative)
|
|
|
|
JS_GetFunctionNative(JSContext *cx, JSFunction *fun)
|
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
return Jsvalify(FUN_NATIVE(fun));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-01 21:33:52 -07:00
|
|
|
JS_PUBLIC_API(JSFastNative)
|
|
|
|
JS_GetFunctionFastNative(JSContext *cx, JSFunction *fun)
|
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
return Jsvalify(FUN_FAST_NATIVE(fun));
|
2007-08-01 21:33:52 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_PUBLIC_API(JSPrincipals *)
|
|
|
|
JS_GetScriptPrincipals(JSContext *cx, JSScript *script)
|
|
|
|
{
|
|
|
|
return script->principals;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stack Frame Iterator
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(JSStackFrame *)
|
|
|
|
JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp)
|
|
|
|
{
|
2008-12-09 08:38:32 -08:00
|
|
|
*iteratorp = (*iteratorp == NULL) ? js_GetTopStackFrame(cx) : (*iteratorp)->down;
|
2007-03-22 10:30:00 -07:00
|
|
|
return *iteratorp;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSScript *)
|
|
|
|
JS_GetFrameScript(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
|
|
|
return fp->script;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(jsbytecode *)
|
|
|
|
JS_GetFramePC(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2010-03-03 18:10:13 -08:00
|
|
|
return fp->pc(cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSStackFrame *)
|
|
|
|
JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2008-12-09 08:38:32 -08:00
|
|
|
return js_GetScriptedCaller(cx, fp);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSPrincipals *)
|
|
|
|
JS_StackFramePrincipals(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2008-09-05 16:24:53 -07:00
|
|
|
JSSecurityCallbacks *callbacks;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-05 16:24:53 -07:00
|
|
|
if (fp->fun) {
|
|
|
|
callbacks = JS_GetSecurityCallbacks(cx);
|
|
|
|
if (callbacks && callbacks->findObjectPrincipals) {
|
2009-08-24 17:09:44 -07:00
|
|
|
if (FUN_OBJECT(fp->fun) != fp->callee())
|
|
|
|
return callbacks->findObjectPrincipals(cx, fp->callee());
|
2008-03-28 15:27:36 -07:00
|
|
|
/* FALL THROUGH */
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (fp->script)
|
|
|
|
return fp->script->principals;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-16 17:41:39 -08:00
|
|
|
JSPrincipals *
|
|
|
|
js_EvalFramePrincipals(JSContext *cx, JSObject *callee, JSStackFrame *caller)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSPrincipals *principals, *callerPrincipals;
|
2008-09-05 16:24:53 -07:00
|
|
|
JSSecurityCallbacks *callbacks;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-05 16:24:53 -07:00
|
|
|
callbacks = JS_GetSecurityCallbacks(cx);
|
2010-02-16 17:41:39 -08:00
|
|
|
if (callbacks && callbacks->findObjectPrincipals)
|
|
|
|
principals = callbacks->findObjectPrincipals(cx, callee);
|
|
|
|
else
|
2007-03-22 10:30:00 -07:00
|
|
|
principals = NULL;
|
|
|
|
if (!caller)
|
|
|
|
return principals;
|
|
|
|
callerPrincipals = JS_StackFramePrincipals(cx, caller);
|
|
|
|
return (callerPrincipals && principals &&
|
|
|
|
callerPrincipals->subsume(callerPrincipals, principals))
|
|
|
|
? principals
|
|
|
|
: callerPrincipals;
|
|
|
|
}
|
|
|
|
|
2010-02-16 17:41:39 -08:00
|
|
|
JS_PUBLIC_API(JSPrincipals *)
|
|
|
|
JS_EvalFramePrincipals(JSContext *cx, JSStackFrame *fp, JSStackFrame *caller)
|
|
|
|
{
|
|
|
|
return js_EvalFramePrincipals(cx, fp->callee(), caller);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_PUBLIC_API(void *)
|
|
|
|
JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
|
|
|
if (fp->annotation && fp->script) {
|
|
|
|
JSPrincipals *principals = JS_StackFramePrincipals(cx, fp);
|
|
|
|
|
|
|
|
if (principals && principals->globalPrivilegesEnabled(cx, principals)) {
|
|
|
|
/*
|
|
|
|
* Give out an annotation only if privileges have not been revoked
|
|
|
|
* or disabled globally.
|
|
|
|
*/
|
|
|
|
return fp->annotation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation)
|
|
|
|
{
|
|
|
|
fp->annotation = annotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void *)
|
|
|
|
JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
|
|
|
JSPrincipals *principals;
|
|
|
|
|
|
|
|
principals = JS_StackFramePrincipals(cx, fp);
|
|
|
|
if (!principals)
|
|
|
|
return NULL;
|
|
|
|
return principals->getPrincipalArray(cx, principals);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_IsNativeFrame(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
|
|
|
return !fp->script;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is deprecated, use JS_GetFrameScopeChain instead */
|
|
|
|
JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetFrameObject(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2010-08-12 21:47:46 -07:00
|
|
|
return fp->scopeChain;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2010-03-03 17:52:26 -08:00
|
|
|
JS_ASSERT(cx->stack().contains(fp));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Force creation of argument and call objects if not yet created */
|
|
|
|
(void) JS_GetFrameCallObject(cx, fp);
|
|
|
|
return js_GetScopeChain(cx, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2010-03-03 17:52:26 -08:00
|
|
|
JS_ASSERT(cx->stack().contains(fp));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (! fp->fun)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Force creation of argument object if not yet created */
|
|
|
|
(void) js_GetArgsObject(cx, fp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX ill-defined: null return here means error was reported, unlike a
|
|
|
|
* null returned above or in the #else
|
|
|
|
*/
|
2009-02-18 23:57:24 -08:00
|
|
|
return js_GetCallObject(cx, fp);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetFrameThis(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2010-08-10 17:21:11 -07:00
|
|
|
if (fp->isDummyFrame())
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return fp->getThisObject(cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSFunction *)
|
|
|
|
JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
|
|
|
return fp->fun;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2008-09-08 02:47:12 -07:00
|
|
|
if (!fp->fun)
|
|
|
|
return NULL;
|
2007-08-01 21:33:52 -07:00
|
|
|
|
2010-03-31 22:13:51 -07:00
|
|
|
JS_ASSERT(fp->callee()->isFunction());
|
2009-09-05 08:59:11 -07:00
|
|
|
JS_ASSERT(fp->callee()->getPrivate() == fp->fun);
|
2009-08-24 17:09:44 -07:00
|
|
|
return fp->callee();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
|
|
|
return (fp->flags & JSFRAME_CONSTRUCTING) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetFrameCalleeObject(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2009-08-24 17:09:44 -07:00
|
|
|
return fp->callee();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-01 09:58:03 -07:00
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetValidFrameCalleeObject(JSContext *cx, JSStackFrame *fp, jsval *vp)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
|
|
|
|
if (!fp->getValidCalleeObject(cx, &v))
|
|
|
|
return false;
|
|
|
|
*vp = Jsvalify(v);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
|
|
|
return (fp->flags & JSFRAME_DEBUGGER) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(jsval)
|
|
|
|
JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
return Jsvalify(fp->rval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval)
|
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
fp->rval = Valueify(rval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
JS_PUBLIC_API(const char *)
|
|
|
|
JS_GetScriptFilename(JSContext *cx, JSScript *script)
|
|
|
|
{
|
|
|
|
return script->filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(uintN)
|
|
|
|
JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script)
|
|
|
|
{
|
|
|
|
return script->lineno;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(uintN)
|
|
|
|
JS_GetScriptLineExtent(JSContext *cx, JSScript *script)
|
|
|
|
{
|
|
|
|
return js_GetScriptLineExtent(script);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSVersion)
|
|
|
|
JS_GetScriptVersion(JSContext *cx, JSScript *script)
|
|
|
|
{
|
2007-07-05 13:37:47 -07:00
|
|
|
return (JSVersion) (script->version & JSVERSION_MASK);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata)
|
|
|
|
{
|
2007-06-14 23:44:18 -07:00
|
|
|
rt->globalDebugHooks.newScriptHook = hook;
|
|
|
|
rt->globalDebugHooks.newScriptHookData = callerdata;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
|
|
|
|
void *callerdata)
|
|
|
|
{
|
2007-06-14 23:44:18 -07:00
|
|
|
rt->globalDebugHooks.destroyScriptHook = hook;
|
|
|
|
rt->globalDebugHooks.destroyScriptHookData = callerdata;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
|
|
|
|
const jschar *chars, uintN length,
|
|
|
|
const char *filename, uintN lineno,
|
|
|
|
jsval *rval)
|
|
|
|
{
|
2009-06-08 13:35:43 -07:00
|
|
|
JS_ASSERT_NOT_ON_TRACE(cx);
|
|
|
|
|
2010-07-26 06:35:38 -07:00
|
|
|
JSObject *scobj = JS_GetFrameScopeChain(cx, fp);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!scobj)
|
2010-07-26 06:35:38 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-03 23:57:12 -08:00
|
|
|
/*
|
|
|
|
* NB: This function breaks the assumption that the compiler can see all
|
2009-04-05 21:17:22 -07:00
|
|
|
* calls and properly compute a static level. In order to get around this,
|
|
|
|
* we use a static level that will cause us not to attempt to optimize
|
2009-02-03 23:57:12 -08:00
|
|
|
* variable references made by this frame.
|
|
|
|
*/
|
2010-07-26 06:35:38 -07:00
|
|
|
JSScript *script = Compiler::compileScript(cx, scobj, fp, JS_StackFramePrincipals(cx, fp),
|
|
|
|
TCF_COMPILE_N_GO, chars, length, NULL,
|
|
|
|
filename, lineno, NULL,
|
|
|
|
UpvarCookie::UPVAR_LEVEL_LIMIT);
|
2009-06-04 18:58:47 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!script)
|
2010-07-26 06:35:38 -07:00
|
|
|
return false;
|
2009-06-04 18:58:47 -07:00
|
|
|
|
2010-07-26 06:35:38 -07:00
|
|
|
bool ok = !!Execute(cx, scobj, script, fp, JSFRAME_DEBUGGER | JSFRAME_EVAL, Valueify(rval));
|
2009-06-04 18:58:47 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
js_DestroyScript(cx, script);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
|
|
|
|
const char *bytes, uintN length,
|
|
|
|
const char *filename, uintN lineno,
|
|
|
|
jsval *rval)
|
|
|
|
{
|
|
|
|
jschar *chars;
|
|
|
|
JSBool ok;
|
|
|
|
size_t len = length;
|
|
|
|
|
|
|
|
chars = js_InflateString(cx, bytes, &len);
|
|
|
|
if (!chars)
|
|
|
|
return JS_FALSE;
|
|
|
|
length = (uintN) len;
|
|
|
|
ok = JS_EvaluateUCInStackFrame(cx, fp, chars, length, filename, lineno,
|
|
|
|
rval);
|
2009-07-27 21:10:12 -07:00
|
|
|
cx->free(chars);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/* XXXbe this all needs to be reworked to avoid requiring JSScope types. */
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSScopeProperty *)
|
|
|
|
JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp)
|
|
|
|
{
|
|
|
|
JSScopeProperty *sprop;
|
|
|
|
JSScope *scope;
|
|
|
|
|
|
|
|
sprop = *iteratorp;
|
2010-04-08 11:22:04 -07:00
|
|
|
scope = obj->scope();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* XXXbe minor(?) incompatibility: iterate in reverse definition order */
|
2009-12-01 12:49:15 -08:00
|
|
|
sprop = sprop ? sprop->parent : scope->lastProperty();
|
2007-03-22 10:30:00 -07:00
|
|
|
*iteratorp = sprop;
|
|
|
|
return sprop;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *sprop,
|
|
|
|
JSPropertyDesc *pd)
|
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
pd->id = IdToJsval(sprop->id);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-26 18:01:54 -07:00
|
|
|
JSBool wasThrowing = cx->throwing;
|
2010-03-29 19:47:40 -07:00
|
|
|
AutoValueRooter lastException(cx, cx->exception);
|
2009-11-12 14:13:25 -08:00
|
|
|
cx->throwing = JS_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
if (!js_GetProperty(cx, obj, sprop->id, Valueify(&pd->value))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!cx->throwing) {
|
|
|
|
pd->flags = JSPD_ERROR;
|
|
|
|
pd->value = JSVAL_VOID;
|
|
|
|
} else {
|
|
|
|
pd->flags = JSPD_EXCEPTION;
|
2010-07-14 23:19:36 -07:00
|
|
|
pd->value = Jsvalify(cx->exception);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pd->flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cx->throwing = wasThrowing;
|
2009-11-12 14:13:25 -08:00
|
|
|
if (wasThrowing)
|
|
|
|
cx->exception = lastException.value();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-08 14:44:59 -08:00
|
|
|
pd->flags |= (sprop->enumerable() ? JSPD_ENUMERATE : 0)
|
|
|
|
| (!sprop->writable() ? JSPD_READONLY : 0)
|
|
|
|
| (!sprop->configurable() ? JSPD_PERMANENT : 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
pd->spare = 0;
|
2010-02-24 17:40:28 -08:00
|
|
|
if (sprop->getter() == js_GetCallArg) {
|
2008-03-29 08:48:41 -07:00
|
|
|
pd->slot = sprop->shortid;
|
|
|
|
pd->flags |= JSPD_ARGUMENT;
|
2010-02-24 17:40:28 -08:00
|
|
|
} else if (sprop->getter() == js_GetCallVar) {
|
2008-03-29 08:48:41 -07:00
|
|
|
pd->slot = sprop->shortid;
|
|
|
|
pd->flags |= JSPD_VARIABLE;
|
|
|
|
} else {
|
|
|
|
pd->slot = 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
pd->alias = JSVAL_VOID;
|
2009-11-12 14:13:25 -08:00
|
|
|
|
2010-04-08 11:22:04 -07:00
|
|
|
JSScope *scope = obj->scope();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (SPROP_HAS_VALID_SLOT(sprop, scope)) {
|
2009-11-12 14:13:25 -08:00
|
|
|
JSScopeProperty *aprop;
|
2009-12-01 12:49:15 -08:00
|
|
|
for (aprop = scope->lastProperty(); aprop; aprop = aprop->parent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aprop != sprop && aprop->slot == sprop->slot) {
|
2010-07-14 23:19:36 -07:00
|
|
|
pd->alias = IdToJsval(aprop->id);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda)
|
|
|
|
{
|
|
|
|
JSScope *scope;
|
|
|
|
uint32 i, n;
|
|
|
|
JSPropertyDesc *pd;
|
|
|
|
JSScopeProperty *sprop;
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
Class *clasp = obj->getClass();
|
2010-03-31 22:13:51 -07:00
|
|
|
if (!obj->isNative() || (clasp->flags & JSCLASS_NEW_ENUMERATE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
|
|
|
JSMSG_CANT_DESCRIBE_PROPS, clasp->name);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
if (!clasp->enumerate(cx, obj))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
/* have no props, or object's scope has not mutated from that of proto */
|
2010-04-08 11:22:04 -07:00
|
|
|
scope = obj->scope();
|
2009-07-21 14:25:11 -07:00
|
|
|
if (scope->entryCount == 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
pda->length = 0;
|
|
|
|
pda->array = NULL;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-04-22 23:22:42 -07:00
|
|
|
n = scope->entryCount;
|
2009-07-27 21:10:12 -07:00
|
|
|
pd = (JSPropertyDesc *) cx->malloc((size_t)n * sizeof(JSPropertyDesc));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!pd)
|
|
|
|
return JS_FALSE;
|
|
|
|
i = 0;
|
2009-12-01 12:49:15 -08:00
|
|
|
for (sprop = scope->lastProperty(); sprop; sprop = sprop->parent) {
|
2010-07-14 23:19:36 -07:00
|
|
|
if (!js_AddRoot(cx, Valueify(&pd[i].id), NULL))
|
2007-03-22 10:30:00 -07:00
|
|
|
goto bad;
|
2010-07-14 23:19:36 -07:00
|
|
|
if (!js_AddRoot(cx, Valueify(&pd[i].value), NULL))
|
2007-03-22 10:30:00 -07:00
|
|
|
goto bad;
|
|
|
|
if (!JS_GetPropertyDesc(cx, obj, sprop, &pd[i]))
|
|
|
|
goto bad;
|
2010-07-14 23:19:36 -07:00
|
|
|
if ((pd[i].flags & JSPD_ALIAS) && !js_AddRoot(cx, Valueify(&pd[i].alias), NULL))
|
2007-03-22 10:30:00 -07:00
|
|
|
goto bad;
|
|
|
|
if (++i == n)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pda->length = i;
|
|
|
|
pda->array = pd;
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
pda->length = i + 1;
|
|
|
|
pda->array = pd;
|
|
|
|
JS_PutPropertyDescArray(cx, pda);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda)
|
|
|
|
{
|
|
|
|
JSPropertyDesc *pd;
|
|
|
|
uint32 i;
|
|
|
|
|
|
|
|
pd = pda->array;
|
|
|
|
for (i = 0; i < pda->length; i++) {
|
|
|
|
js_RemoveRoot(cx->runtime, &pd[i].id);
|
|
|
|
js_RemoveRoot(cx->runtime, &pd[i].value);
|
|
|
|
if (pd[i].flags & JSPD_ALIAS)
|
|
|
|
js_RemoveRoot(cx->runtime, &pd[i].alias);
|
|
|
|
}
|
2009-07-27 21:10:12 -07:00
|
|
|
cx->free(pd);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2010-06-10 10:48:59 -07:00
|
|
|
static bool
|
|
|
|
SetupFakeFrame(JSContext *cx, ExecuteFrameGuard &frame, JSFrameRegs ®s, JSObject *scopeobj)
|
|
|
|
{
|
|
|
|
JSFunction *fun = GET_FUNCTION_PRIVATE(cx, scopeobj);
|
|
|
|
JS_ASSERT(fun->minArgs() == 0 && !fun->isInterpreted() && fun->u.n.extra == 0);
|
|
|
|
|
|
|
|
const uintN vplen = 2;
|
|
|
|
const uintN nfixed = 0;
|
|
|
|
if (!cx->stack().getExecuteFrame(cx, js_GetTopStackFrame(cx), vplen, nfixed, frame))
|
|
|
|
return false;
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
Value *vp = frame.getvp();
|
2010-06-10 10:48:59 -07:00
|
|
|
PodZero(vp, vplen);
|
2010-07-14 23:19:36 -07:00
|
|
|
vp[0].setObject(*scopeobj);
|
|
|
|
vp[1].setNull(); // satisfy LeaveTree assert
|
2010-06-10 10:48:59 -07:00
|
|
|
|
|
|
|
JSStackFrame *fp = frame.getFrame();
|
|
|
|
PodZero(fp);
|
|
|
|
fp->fun = fun;
|
|
|
|
fp->argv = vp + 2;
|
2010-08-12 21:47:46 -07:00
|
|
|
fp->scopeChain = scopeobj->getGlobal();
|
2010-06-10 10:48:59 -07:00
|
|
|
|
|
|
|
regs.pc = NULL;
|
|
|
|
regs.sp = fp->slots();
|
|
|
|
|
|
|
|
cx->stack().pushExecuteFrame(cx, frame, regs, NULL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_GetPropertyByIdWithFakeFrame(JSContext *cx, JSObject *obj, JSObject *scopeobj, jsid id,
|
|
|
|
jsval *vp)
|
|
|
|
{
|
|
|
|
ExecuteFrameGuard frame;
|
|
|
|
JSFrameRegs regs;
|
|
|
|
|
|
|
|
if (!SetupFakeFrame(cx, frame, regs, scopeobj))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool ok = JS_GetPropertyById(cx, obj, id, vp);
|
|
|
|
frame.getFrame()->putActivationObjects(cx);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_SetPropertyByIdWithFakeFrame(JSContext *cx, JSObject *obj, JSObject *scopeobj, jsid id,
|
|
|
|
jsval *vp)
|
|
|
|
{
|
|
|
|
ExecuteFrameGuard frame;
|
|
|
|
JSFrameRegs regs;
|
|
|
|
|
|
|
|
if (!SetupFakeFrame(cx, frame, regs, scopeobj))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool ok = JS_SetPropertyById(cx, obj, id, vp);
|
|
|
|
frame.getFrame()->putActivationObjects(cx);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_CallFunctionValueWithFakeFrame(JSContext *cx, JSObject *obj, JSObject *scopeobj, jsval funval,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
ExecuteFrameGuard frame;
|
|
|
|
JSFrameRegs regs;
|
|
|
|
|
|
|
|
if (!SetupFakeFrame(cx, frame, regs, scopeobj))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool ok = JS_CallFunctionValue(cx, obj, funval, argc, argv, rval);
|
|
|
|
frame.getFrame()->putActivationObjects(cx);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_PUBLIC_API(JSBool)
|
2010-04-30 17:34:54 -07:00
|
|
|
JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler handler, void *closure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-06-14 23:44:18 -07:00
|
|
|
rt->globalDebugHooks.debuggerHandler = handler;
|
|
|
|
rt->globalDebugHooks.debuggerHandlerData = closure;
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure)
|
|
|
|
{
|
2007-06-14 23:44:18 -07:00
|
|
|
rt->globalDebugHooks.sourceHandler = handler;
|
|
|
|
rt->globalDebugHooks.sourceHandlerData = closure;
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure)
|
|
|
|
{
|
2007-06-14 23:44:18 -07:00
|
|
|
rt->globalDebugHooks.executeHook = hook;
|
|
|
|
rt->globalDebugHooks.executeHookData = closure;
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure)
|
|
|
|
{
|
2009-11-13 09:04:23 -08:00
|
|
|
#ifdef JS_TRACER
|
2010-04-08 05:54:18 -07:00
|
|
|
{
|
|
|
|
AutoLockGC lock(rt);
|
|
|
|
bool wasInhibited = rt->debuggerInhibitsJIT();
|
2009-11-13 09:04:23 -08:00
|
|
|
#endif
|
2010-04-08 05:54:18 -07:00
|
|
|
rt->globalDebugHooks.callHook = hook;
|
|
|
|
rt->globalDebugHooks.callHookData = closure;
|
2009-11-13 09:04:23 -08:00
|
|
|
#ifdef JS_TRACER
|
2010-04-08 05:54:18 -07:00
|
|
|
JITInhibitingHookChange(rt, wasInhibited);
|
|
|
|
}
|
2009-11-13 09:04:23 -08:00
|
|
|
if (hook)
|
|
|
|
LeaveTraceRT(rt);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
2010-04-30 17:34:54 -07:00
|
|
|
JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-06-14 23:44:18 -07:00
|
|
|
rt->globalDebugHooks.throwHook = hook;
|
|
|
|
rt->globalDebugHooks.throwHookData = closure;
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure)
|
|
|
|
{
|
2007-06-14 23:44:18 -07:00
|
|
|
rt->globalDebugHooks.debugErrorHook = hook;
|
|
|
|
rt->globalDebugHooks.debugErrorHookData = closure;
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
JS_PUBLIC_API(size_t)
|
|
|
|
JS_GetObjectTotalSize(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
size_t nbytes;
|
|
|
|
JSScope *scope;
|
|
|
|
|
|
|
|
nbytes = sizeof *obj;
|
2009-11-09 16:57:47 -08:00
|
|
|
if (obj->dslots) {
|
2010-07-14 23:19:36 -07:00
|
|
|
nbytes += (obj->dslots[-1].toPrivateUint32() - JS_INITIAL_NSLOTS + 1)
|
2007-03-22 10:30:00 -07:00
|
|
|
* sizeof obj->dslots[0];
|
|
|
|
}
|
2010-03-31 22:13:51 -07:00
|
|
|
if (obj->isNative()) {
|
2010-04-08 11:22:04 -07:00
|
|
|
scope = obj->scope();
|
2010-01-26 22:50:17 -08:00
|
|
|
if (!scope->isSharedEmpty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nbytes += sizeof *scope;
|
|
|
|
nbytes += SCOPE_CAPACITY(scope) * sizeof(JSScopeProperty *);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
GetAtomTotalSize(JSContext *cx, JSAtom *atom)
|
|
|
|
{
|
|
|
|
size_t nbytes;
|
|
|
|
|
2007-08-11 13:25:16 -07:00
|
|
|
nbytes = sizeof(JSAtom *) + sizeof(JSDHashEntryStub);
|
2010-07-14 23:19:36 -07:00
|
|
|
nbytes += sizeof(JSString);
|
|
|
|
nbytes += (ATOM_TO_STRING(atom)->flatLength() + 1) * sizeof(jschar);
|
2007-03-22 10:30:00 -07:00
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(size_t)
|
2008-03-28 15:27:36 -07:00
|
|
|
JS_GetFunctionTotalSize(JSContext *cx, JSFunction *fun)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
size_t nbytes;
|
|
|
|
|
2008-03-29 03:34:29 -07:00
|
|
|
nbytes = sizeof *fun;
|
2008-04-02 00:46:12 -07:00
|
|
|
nbytes += JS_GetObjectTotalSize(cx, FUN_OBJECT(fun));
|
2008-03-29 03:34:29 -07:00
|
|
|
if (FUN_INTERPRETED(fun))
|
|
|
|
nbytes += JS_GetScriptTotalSize(cx, fun->u.i.script);
|
|
|
|
if (fun->atom)
|
|
|
|
nbytes += GetAtomTotalSize(cx, fun->atom);
|
2007-03-22 10:30:00 -07:00
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "jsemit.h"
|
|
|
|
|
|
|
|
JS_PUBLIC_API(size_t)
|
|
|
|
JS_GetScriptTotalSize(JSContext *cx, JSScript *script)
|
|
|
|
{
|
|
|
|
size_t nbytes, pbytes;
|
|
|
|
jsatomid i;
|
|
|
|
jssrcnote *sn, *notes;
|
2007-07-08 02:03:34 -07:00
|
|
|
JSObjectArray *objarray;
|
2007-03-22 10:30:00 -07:00
|
|
|
JSPrincipals *principals;
|
|
|
|
|
|
|
|
nbytes = sizeof *script;
|
2008-08-20 22:18:42 -07:00
|
|
|
if (script->u.object)
|
|
|
|
nbytes += JS_GetObjectTotalSize(cx, script->u.object);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nbytes += script->length * sizeof script->code[0];
|
|
|
|
nbytes += script->atomMap.length * sizeof script->atomMap.vector[0];
|
|
|
|
for (i = 0; i < script->atomMap.length; i++)
|
|
|
|
nbytes += GetAtomTotalSize(cx, script->atomMap.vector[i]);
|
|
|
|
|
|
|
|
if (script->filename)
|
|
|
|
nbytes += strlen(script->filename) + 1;
|
|
|
|
|
2009-09-09 16:52:55 -07:00
|
|
|
notes = script->notes();
|
2007-03-22 10:30:00 -07:00
|
|
|
for (sn = notes; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn))
|
|
|
|
continue;
|
|
|
|
nbytes += (sn - notes + 1) * sizeof *sn;
|
|
|
|
|
2007-07-08 02:03:34 -07:00
|
|
|
if (script->objectsOffset != 0) {
|
2009-09-09 16:52:55 -07:00
|
|
|
objarray = script->objects();
|
2007-07-08 02:03:34 -07:00
|
|
|
i = objarray->length;
|
|
|
|
nbytes += sizeof *objarray + i * sizeof objarray->vector[0];
|
|
|
|
do {
|
|
|
|
nbytes += JS_GetObjectTotalSize(cx, objarray->vector[--i]);
|
|
|
|
} while (i != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (script->regexpsOffset != 0) {
|
2009-09-09 16:52:55 -07:00
|
|
|
objarray = script->regexps();
|
2007-07-08 02:03:34 -07:00
|
|
|
i = objarray->length;
|
|
|
|
nbytes += sizeof *objarray + i * sizeof objarray->vector[0];
|
|
|
|
do {
|
|
|
|
nbytes += JS_GetObjectTotalSize(cx, objarray->vector[--i]);
|
|
|
|
} while (i != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (script->trynotesOffset != 0) {
|
|
|
|
nbytes += sizeof(JSTryNoteArray) +
|
2009-09-09 16:52:55 -07:00
|
|
|
script->trynotes()->length * sizeof(JSTryNote);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
principals = script->principals;
|
|
|
|
if (principals) {
|
|
|
|
JS_ASSERT(principals->refcount);
|
|
|
|
pbytes = sizeof *principals;
|
|
|
|
if (principals->refcount > 1)
|
|
|
|
pbytes = JS_HOWMANY(pbytes, principals->refcount);
|
|
|
|
nbytes += pbytes;
|
|
|
|
}
|
2008-03-28 15:27:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(uint32)
|
|
|
|
JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
|
|
|
if (!fp)
|
2008-12-09 08:38:32 -08:00
|
|
|
fp = js_GetTopStackFrame(cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (fp) {
|
2007-08-01 21:33:52 -07:00
|
|
|
if (fp->script)
|
2007-03-22 10:30:00 -07:00
|
|
|
return JS_GetScriptFilenameFlags(fp->script);
|
|
|
|
fp = fp->down;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(uint32)
|
|
|
|
JS_GetScriptFilenameFlags(JSScript *script)
|
|
|
|
{
|
|
|
|
JS_ASSERT(script);
|
|
|
|
if (!script->filename)
|
|
|
|
return JSFILENAME_NULL;
|
|
|
|
return js_GetScriptFilenameFlags(script->filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_FlagScriptFilenamePrefix(JSRuntime *rt, const char *prefix, uint32 flags)
|
|
|
|
{
|
|
|
|
if (!js_SaveScriptFilenameRT(rt, prefix, flags))
|
|
|
|
return JS_FALSE;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_IsSystemObject(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
2009-08-27 22:53:26 -07:00
|
|
|
return obj->isSystem();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-04 16:32:10 -07:00
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_MakeSystemObject(JSContext *cx, JSObject *obj)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-04 16:32:10 -07:00
|
|
|
obj->setSystem();
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-06-14 23:44:18 -07:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2009-11-13 09:04:23 -08:00
|
|
|
JS_PUBLIC_API(const JSDebugHooks *)
|
2007-06-14 23:44:18 -07:00
|
|
|
JS_GetGlobalDebugHooks(JSRuntime *rt)
|
|
|
|
{
|
|
|
|
return &rt->globalDebugHooks;
|
|
|
|
}
|
|
|
|
|
2010-01-20 12:54:34 -08:00
|
|
|
const JSDebugHooks js_NullDebugHooks = {};
|
|
|
|
|
2007-06-14 23:44:18 -07:00
|
|
|
JS_PUBLIC_API(JSDebugHooks *)
|
2009-11-13 09:04:23 -08:00
|
|
|
JS_SetContextDebugHooks(JSContext *cx, const JSDebugHooks *hooks)
|
2007-06-14 23:44:18 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(hooks);
|
2010-01-20 12:54:34 -08:00
|
|
|
if (hooks != &cx->runtime->globalDebugHooks && hooks != &js_NullDebugHooks)
|
2010-01-22 14:49:18 -08:00
|
|
|
LeaveTrace(cx);
|
2009-11-13 09:04:23 -08:00
|
|
|
|
|
|
|
#ifdef JS_TRACER
|
2010-04-08 05:54:18 -07:00
|
|
|
AutoLockGC lock(cx->runtime);
|
2009-11-13 09:04:23 -08:00
|
|
|
#endif
|
|
|
|
JSDebugHooks *old = const_cast<JSDebugHooks *>(cx->debugHooks);
|
2007-06-14 23:44:18 -07:00
|
|
|
cx->debugHooks = hooks;
|
2009-11-13 09:04:23 -08:00
|
|
|
#ifdef JS_TRACER
|
|
|
|
cx->updateJITEnabled();
|
|
|
|
#endif
|
2007-06-14 23:44:18 -07:00
|
|
|
return old;
|
|
|
|
}
|
2008-01-16 12:42:50 -08:00
|
|
|
|
2010-01-20 12:54:34 -08:00
|
|
|
JS_PUBLIC_API(JSDebugHooks *)
|
|
|
|
JS_ClearContextDebugHooks(JSContext *cx)
|
|
|
|
{
|
|
|
|
return JS_SetContextDebugHooks(cx, &js_NullDebugHooks);
|
|
|
|
}
|
|
|
|
|
2008-01-16 12:42:50 -08:00
|
|
|
#ifdef MOZ_SHARK
|
|
|
|
|
2008-03-24 01:06:39 -07:00
|
|
|
#include <CHUD/CHUD.h>
|
|
|
|
|
2008-01-19 15:33:08 -08:00
|
|
|
JS_PUBLIC_API(JSBool)
|
2008-03-02 23:10:18 -08:00
|
|
|
JS_StartChudRemote()
|
2008-01-16 12:42:50 -08:00
|
|
|
{
|
2008-03-02 23:10:18 -08:00
|
|
|
if (chudIsRemoteAccessAcquired() &&
|
2008-01-16 12:42:50 -08:00
|
|
|
(chudStartRemotePerfMonitor("Mozilla") == chudSuccess)) {
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-01-19 15:33:08 -08:00
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_StopChudRemote()
|
2008-01-16 12:42:50 -08:00
|
|
|
{
|
|
|
|
if (chudIsRemoteAccessAcquired() &&
|
|
|
|
(chudStopRemotePerfMonitor() == chudSuccess)) {
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-01-19 15:33:08 -08:00
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ConnectShark()
|
2008-01-16 12:42:50 -08:00
|
|
|
{
|
|
|
|
if (!chudIsInitialized() && (chudInitialize() != chudSuccess))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
if (chudAcquireRemoteAccess() != chudSuccess)
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-01-19 15:33:08 -08:00
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DisconnectShark()
|
2008-01-16 12:42:50 -08:00
|
|
|
{
|
|
|
|
if (chudIsRemoteAccessAcquired() && (chudReleaseRemoteAccess() != chudSuccess))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
2008-01-19 15:33:08 -08:00
|
|
|
js_StartShark(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
2008-01-16 12:42:50 -08:00
|
|
|
{
|
2008-01-19 15:33:08 -08:00
|
|
|
if (!JS_StartChudRemote()) {
|
2008-01-16 12:42:50 -08:00
|
|
|
JS_ReportError(cx, "Error starting CHUD.");
|
2009-05-15 15:59:00 -07:00
|
|
|
return JS_FALSE;
|
2008-01-16 12:42:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
2008-01-19 15:33:08 -08:00
|
|
|
js_StopShark(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
2008-01-16 12:42:50 -08:00
|
|
|
{
|
2008-01-19 15:33:08 -08:00
|
|
|
if (!JS_StopChudRemote()) {
|
2008-01-16 12:42:50 -08:00
|
|
|
JS_ReportError(cx, "Error stopping CHUD.");
|
2009-05-15 15:59:00 -07:00
|
|
|
return JS_FALSE;
|
2008-01-16 12:42:50 -08:00
|
|
|
}
|
2008-03-02 23:10:18 -08:00
|
|
|
|
2008-01-16 12:42:50 -08:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
2008-01-19 15:33:08 -08:00
|
|
|
js_ConnectShark(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
2008-01-16 12:42:50 -08:00
|
|
|
{
|
2008-01-19 15:33:08 -08:00
|
|
|
if (!JS_ConnectShark()) {
|
2008-01-16 12:42:50 -08:00
|
|
|
JS_ReportError(cx, "Error connecting to Shark.");
|
2009-05-15 15:59:00 -07:00
|
|
|
return JS_FALSE;
|
2008-01-16 12:42:50 -08:00
|
|
|
}
|
2008-03-02 23:10:18 -08:00
|
|
|
|
2008-01-16 12:42:50 -08:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
2008-01-19 15:33:08 -08:00
|
|
|
js_DisconnectShark(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
2008-01-16 12:42:50 -08:00
|
|
|
{
|
2008-01-19 15:33:08 -08:00
|
|
|
if (!JS_DisconnectShark()) {
|
2008-01-16 12:42:50 -08:00
|
|
|
JS_ReportError(cx, "Error disconnecting from Shark.");
|
2009-05-15 15:59:00 -07:00
|
|
|
return JS_FALSE;
|
2008-01-16 12:42:50 -08:00
|
|
|
}
|
2008-03-02 23:10:18 -08:00
|
|
|
|
2008-01-16 12:42:50 -08:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MOZ_SHARK */
|
2008-07-08 15:58:08 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_CALLGRIND
|
|
|
|
|
|
|
|
#include <valgrind/callgrind.h>
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_StartCallgrind(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
2009-05-15 15:59:00 -07:00
|
|
|
CALLGRIND_START_INSTRUMENTATION;
|
2008-07-08 15:58:08 -07:00
|
|
|
CALLGRIND_ZERO_STATS;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_StopCallgrind(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
CALLGRIND_STOP_INSTRUMENTATION;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_DumpCallgrind(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
JSString *str;
|
|
|
|
char *cstr;
|
|
|
|
|
|
|
|
if (argc > 0 && JSVAL_IS_STRING(argv[0])) {
|
|
|
|
str = JSVAL_TO_STRING(argv[0]);
|
2009-06-10 18:29:44 -07:00
|
|
|
cstr = js_DeflateString(cx, str->chars(), str->length());
|
2008-07-08 15:58:08 -07:00
|
|
|
if (cstr) {
|
|
|
|
CALLGRIND_DUMP_STATS_AT(cstr);
|
2009-07-27 21:10:12 -07:00
|
|
|
cx->free(cstr);
|
2008-07-08 15:58:08 -07:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CALLGRIND_DUMP_STATS;
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MOZ_CALLGRIND */
|
2008-07-29 15:19:26 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_VTUNE
|
|
|
|
#include <VTuneApi.h>
|
|
|
|
|
|
|
|
static const char *vtuneErrorMessages[] = {
|
|
|
|
"unknown, error #0",
|
|
|
|
"invalid 'max samples' field",
|
|
|
|
"invalid 'samples per buffer' field",
|
|
|
|
"invalid 'sample interval' field",
|
|
|
|
"invalid path",
|
|
|
|
"sample file in use",
|
|
|
|
"invalid 'number of events' field",
|
|
|
|
"unknown, error #7",
|
|
|
|
"internal error",
|
|
|
|
"bad event name",
|
|
|
|
"VTStopSampling called without calling VTStartSampling",
|
|
|
|
"no events selected for event-based sampling",
|
|
|
|
"events selected cannot be run together",
|
|
|
|
"no sampling parameters",
|
|
|
|
"sample database already exists",
|
|
|
|
"sampling already started",
|
|
|
|
"time-based sampling not supported",
|
|
|
|
"invalid 'sampling parameters size' field",
|
|
|
|
"invalid 'event size' field",
|
|
|
|
"sampling file already bound",
|
|
|
|
"invalid event path",
|
|
|
|
"invalid license",
|
|
|
|
"invalid 'global options' field",
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_StartVtune(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
2009-05-15 15:59:00 -07:00
|
|
|
VTUNE_EVENT events[] = {
|
|
|
|
{ 1000000, 0, 0, 0, "CPU_CLK_UNHALTED.CORE" },
|
|
|
|
{ 1000000, 0, 0, 0, "INST_RETIRED.ANY" },
|
2008-07-29 15:19:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
U32 n_events = sizeof(events) / sizeof(VTUNE_EVENT);
|
|
|
|
char *default_filename = "mozilla-vtune.tb5";
|
|
|
|
JSString *str;
|
|
|
|
U32 status;
|
|
|
|
|
2009-05-15 15:59:00 -07:00
|
|
|
VTUNE_SAMPLING_PARAMS params =
|
2008-07-29 15:19:26 -07:00
|
|
|
sizeof(VTUNE_SAMPLING_PARAMS),
|
|
|
|
sizeof(VTUNE_EVENT),
|
|
|
|
0, 0, /* Reserved fields */
|
|
|
|
1, /* Initialize in "paused" state */
|
|
|
|
0, /* Max samples, or 0 for "continuous" */
|
|
|
|
4096, /* Samples per buffer */
|
|
|
|
0.1, /* Sampling interval in ms */
|
|
|
|
1, /* 1 for event-based sampling, 0 for time-based */
|
|
|
|
|
|
|
|
n_events,
|
|
|
|
events,
|
|
|
|
default_filename,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (argc > 0 && JSVAL_IS_STRING(argv[0])) {
|
|
|
|
str = JSVAL_TO_STRING(argv[0]);
|
2009-06-10 18:29:44 -07:00
|
|
|
params.tb5Filename = js_DeflateString(cx, str->chars(), str->length());
|
2008-07-29 15:19:26 -07:00
|
|
|
}
|
2009-05-15 15:59:00 -07:00
|
|
|
|
2008-07-29 15:19:26 -07:00
|
|
|
status = VTStartSampling(¶ms);
|
|
|
|
|
|
|
|
if (params.tb5Filename != default_filename)
|
2009-07-27 21:10:12 -07:00
|
|
|
cx->free(params.tb5Filename);
|
2009-05-15 15:59:00 -07:00
|
|
|
|
|
|
|
if (status != 0) {
|
2008-07-29 15:19:26 -07:00
|
|
|
if (status == VTAPI_MULTIPLE_RUNS)
|
|
|
|
VTStopSampling(0);
|
|
|
|
if (status < sizeof(vtuneErrorMessages))
|
2009-05-15 15:59:00 -07:00
|
|
|
JS_ReportError(cx, "Vtune setup error: %s",
|
2008-07-29 15:19:26 -07:00
|
|
|
vtuneErrorMessages[status]);
|
|
|
|
else
|
2009-05-15 15:59:00 -07:00
|
|
|
JS_ReportError(cx, "Vtune setup error: %d",
|
|
|
|
status);
|
2008-07-29 15:19:26 -07:00
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_StopVtune(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
U32 status = VTStopSampling(1);
|
|
|
|
if (status) {
|
|
|
|
if (status < sizeof(vtuneErrorMessages))
|
2009-05-15 15:59:00 -07:00
|
|
|
JS_ReportError(cx, "Vtune shutdown error: %s",
|
2008-07-29 15:19:26 -07:00
|
|
|
vtuneErrorMessages[status]);
|
|
|
|
else
|
2009-05-15 15:59:00 -07:00
|
|
|
JS_ReportError(cx, "Vtune shutdown error: %d",
|
2008-07-29 15:19:26 -07:00
|
|
|
status);
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_PauseVtune(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
VTPause();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_ResumeVtune(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
VTResume();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MOZ_VTUNE */
|
2009-07-30 11:48:02 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_TRACEVIS
|
|
|
|
/*
|
|
|
|
* Ethogram - Javascript wrapper for TraceVis state
|
|
|
|
*
|
2009-08-05 12:39:10 -07:00
|
|
|
* ethology: The scientific study of animal behavior,
|
2009-07-30 11:48:02 -07:00
|
|
|
* especially as it occurs in a natural environment.
|
|
|
|
* ethogram: A pictorial catalog of the behavioral patterns of
|
|
|
|
* an organism or a species.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#include "jstracer.h"
|
|
|
|
|
|
|
|
#define ETHOGRAM_BUF_SIZE 65536
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
ethogram_construct(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval);
|
|
|
|
static void
|
|
|
|
ethogram_finalize(JSContext *cx, JSObject *obj);
|
|
|
|
|
|
|
|
static JSClass ethogram_class = {
|
|
|
|
"Ethogram",
|
|
|
|
JSCLASS_HAS_PRIVATE,
|
|
|
|
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, ethogram_finalize,
|
|
|
|
JSCLASS_NO_OPTIONAL_MEMBERS
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EthogramEvent {
|
|
|
|
TraceVisState s;
|
|
|
|
TraceVisExitReason r;
|
|
|
|
int ts;
|
|
|
|
int tus;
|
|
|
|
JSString *filename;
|
|
|
|
int lineno;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
compare_strings(const void *k1, const void *k2)
|
|
|
|
{
|
|
|
|
return strcmp((const char *) k1, (const char *) k2) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
class EthogramEventBuffer {
|
|
|
|
private:
|
|
|
|
EthogramEvent mBuf[ETHOGRAM_BUF_SIZE];
|
|
|
|
int mReadPos;
|
|
|
|
int mWritePos;
|
|
|
|
JSObject *mFilenames;
|
|
|
|
int mStartSecond;
|
|
|
|
|
|
|
|
struct EthogramScriptEntry {
|
|
|
|
char *filename;
|
|
|
|
JSString *jsfilename;
|
|
|
|
|
|
|
|
EthogramScriptEntry *next;
|
|
|
|
};
|
|
|
|
EthogramScriptEntry *mScripts;
|
|
|
|
|
|
|
|
public:
|
|
|
|
friend JSBool
|
|
|
|
ethogram_construct(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval);
|
|
|
|
|
|
|
|
inline void push(TraceVisState s, TraceVisExitReason r, char *filename, int lineno) {
|
|
|
|
mBuf[mWritePos].s = s;
|
|
|
|
mBuf[mWritePos].r = r;
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
FILETIME now;
|
|
|
|
GetSystemTimeAsFileTime(&now);
|
|
|
|
unsigned long long raw_us = 0.1 *
|
|
|
|
(((unsigned long long) now.dwHighDateTime << 32ULL) |
|
|
|
|
(unsigned long long) now.dwLowDateTime);
|
|
|
|
unsigned int sec = raw_us / 1000000L;
|
|
|
|
unsigned int usec = raw_us % 1000000L;
|
|
|
|
mBuf[mWritePos].ts = sec - mStartSecond;
|
|
|
|
mBuf[mWritePos].tus = usec;
|
|
|
|
#else
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
mBuf[mWritePos].ts = tv.tv_sec - mStartSecond;
|
|
|
|
mBuf[mWritePos].tus = tv.tv_usec;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
JSString *jsfilename = findScript(filename);
|
|
|
|
mBuf[mWritePos].filename = jsfilename;
|
|
|
|
mBuf[mWritePos].lineno = lineno;
|
|
|
|
|
|
|
|
mWritePos = (mWritePos + 1) % ETHOGRAM_BUF_SIZE;
|
|
|
|
if (mWritePos == mReadPos) {
|
|
|
|
mReadPos = (mWritePos + 1) % ETHOGRAM_BUF_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline EthogramEvent *pop() {
|
|
|
|
EthogramEvent *e = &mBuf[mReadPos];
|
|
|
|
mReadPos = (mReadPos + 1) % ETHOGRAM_BUF_SIZE;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isEmpty() {
|
|
|
|
return (mReadPos == mWritePos);
|
|
|
|
}
|
|
|
|
|
|
|
|
EthogramScriptEntry *addScript(JSContext *cx, JSObject *obj, char *filename, JSString *jsfilename) {
|
|
|
|
JSHashNumber hash = JS_HashString(filename);
|
|
|
|
JSHashEntry **hep = JS_HashTableRawLookup(traceVisScriptTable, hash, filename);
|
|
|
|
if (*hep != NULL)
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
JS_HashTableRawAdd(traceVisScriptTable, hep, hash, filename, this);
|
|
|
|
|
|
|
|
EthogramScriptEntry * entry = (EthogramScriptEntry *) JS_malloc(cx, sizeof(EthogramScriptEntry));
|
|
|
|
if (entry == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
entry->next = mScripts;
|
|
|
|
mScripts = entry;
|
|
|
|
entry->filename = filename;
|
|
|
|
entry->jsfilename = jsfilename;
|
|
|
|
|
|
|
|
return mScripts;
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeScripts(JSContext *cx) {
|
|
|
|
EthogramScriptEntry *se = mScripts;
|
|
|
|
while (se != NULL) {
|
|
|
|
char *filename = se->filename;
|
|
|
|
|
|
|
|
JSHashNumber hash = JS_HashString(filename);
|
|
|
|
JSHashEntry **hep = JS_HashTableRawLookup(traceVisScriptTable, hash, filename);
|
|
|
|
JSHashEntry *he = *hep;
|
|
|
|
if (he) {
|
|
|
|
/* we hardly knew he */
|
|
|
|
JS_HashTableRawRemove(traceVisScriptTable, hep, he);
|
|
|
|
}
|
|
|
|
|
|
|
|
EthogramScriptEntry *se_head = se;
|
|
|
|
se = se->next;
|
|
|
|
JS_free(cx, se_head);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString *findScript(char *filename) {
|
|
|
|
EthogramScriptEntry *se = mScripts;
|
|
|
|
while (se != NULL) {
|
|
|
|
if (compare_strings(se->filename, filename))
|
|
|
|
return (se->jsfilename);
|
|
|
|
se = se->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *filenames() {
|
|
|
|
return mFilenames;
|
|
|
|
}
|
|
|
|
|
|
|
|
int length() {
|
|
|
|
if (mWritePos < mReadPos)
|
|
|
|
return (mWritePos + ETHOGRAM_BUF_SIZE) - mReadPos;
|
|
|
|
else
|
|
|
|
return mWritePos - mReadPos;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static char jstv_empty[] = "<null>";
|
|
|
|
|
|
|
|
inline char *
|
|
|
|
jstv_Filename(JSStackFrame *fp)
|
|
|
|
{
|
|
|
|
while (fp && fp->script == NULL)
|
|
|
|
fp = fp->down;
|
|
|
|
return (fp && fp->script && fp->script->filename)
|
|
|
|
? (char *)fp->script->filename
|
|
|
|
: jstv_empty;
|
|
|
|
}
|
|
|
|
inline uintN
|
|
|
|
jstv_Lineno(JSContext *cx, JSStackFrame *fp)
|
|
|
|
{
|
2010-06-03 05:40:31 -07:00
|
|
|
while (fp && fp->pc(cx) == NULL)
|
2009-07-30 11:48:02 -07:00
|
|
|
fp = fp->down;
|
2010-06-03 05:40:31 -07:00
|
|
|
return (fp && fp->pc(cx)) ? js_FramePCToLineNumber(cx, fp) : 0;
|
2009-07-30 11:48:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Collect states here and distribute to a matching buffer, if any */
|
|
|
|
JS_FRIEND_API(void)
|
2010-02-16 13:41:40 -08:00
|
|
|
js::StoreTraceVisState(JSContext *cx, TraceVisState s, TraceVisExitReason r)
|
2009-07-30 11:48:02 -07:00
|
|
|
{
|
|
|
|
JSStackFrame *fp = cx->fp;
|
|
|
|
|
|
|
|
char *script_file = jstv_Filename(fp);
|
|
|
|
JSHashNumber hash = JS_HashString(script_file);
|
|
|
|
|
|
|
|
JSHashEntry **hep = JS_HashTableRawLookup(traceVisScriptTable, hash, script_file);
|
|
|
|
/* update event buffer, flag if overflowed */
|
|
|
|
JSHashEntry *he = *hep;
|
|
|
|
if (he) {
|
|
|
|
EthogramEventBuffer *p;
|
|
|
|
p = (EthogramEventBuffer *) he->value;
|
|
|
|
|
|
|
|
p->push(s, r, script_file, jstv_Lineno(cx, fp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
ethogram_construct(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
EthogramEventBuffer *p;
|
|
|
|
|
|
|
|
p = (EthogramEventBuffer *) JS_malloc(cx, sizeof(EthogramEventBuffer));
|
|
|
|
|
|
|
|
p->mReadPos = p->mWritePos = 0;
|
|
|
|
p->mScripts = NULL;
|
|
|
|
p->mFilenames = JS_NewArrayObject(cx, 0, NULL);
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
FILETIME now;
|
|
|
|
GetSystemTimeAsFileTime(&now);
|
|
|
|
unsigned long long raw_us = 0.1 *
|
|
|
|
(((unsigned long long) now.dwHighDateTime << 32ULL) |
|
|
|
|
(unsigned long long) now.dwLowDateTime);
|
|
|
|
unsigned int s = raw_us / 1000000L;
|
|
|
|
p->mStartSecond = s;
|
|
|
|
#else
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
p->mStartSecond = tv.tv_sec;
|
|
|
|
#endif
|
|
|
|
jsval filenames = OBJECT_TO_JSVAL(p->filenames());
|
|
|
|
if (!JS_DefineProperty(cx, obj, "filenames", filenames,
|
|
|
|
NULL, NULL, JSPROP_READONLY|JSPROP_PERMANENT))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
if (!JS_IsConstructing(cx)) {
|
|
|
|
obj = JS_NewObject(cx, ðogram_class, NULL, NULL);
|
|
|
|
if (!obj)
|
|
|
|
return JS_FALSE;
|
|
|
|
*rval = OBJECT_TO_JSVAL(obj);
|
|
|
|
}
|
|
|
|
JS_SetPrivate(cx, obj, p);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ethogram_finalize(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
EthogramEventBuffer *p;
|
|
|
|
p = (EthogramEventBuffer *) JS_GetInstancePrivate(cx, obj, ðogram_class, NULL);
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->removeScripts(cx);
|
|
|
|
|
|
|
|
JS_free(cx, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
ethogram_addScript(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
JSString *str;
|
|
|
|
char *filename = NULL;
|
|
|
|
if (argc > 0 && JSVAL_IS_STRING(argv[0])) {
|
|
|
|
str = JSVAL_TO_STRING(argv[0]);
|
|
|
|
filename = js_DeflateString(cx,
|
|
|
|
str->chars(),
|
|
|
|
str->length());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* silently ignore no args */
|
|
|
|
if (!filename)
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
EthogramEventBuffer *p = (EthogramEventBuffer *) JS_GetInstancePrivate(cx, obj, ðogram_class, argv);
|
|
|
|
|
|
|
|
p->addScript(cx, obj, filename, str);
|
|
|
|
JS_CallFunctionName(cx, p->filenames(), "push", 1, argv, rval);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
ethogram_getAllEvents(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
EthogramEventBuffer *p;
|
|
|
|
|
|
|
|
p = (EthogramEventBuffer *) JS_GetInstancePrivate(cx, obj, ðogram_class, argv);
|
|
|
|
if (!p)
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
if (p->isEmpty()) {
|
|
|
|
*rval = JSVAL_NULL;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *rarray = JS_NewArrayObject(cx, 0, NULL);
|
|
|
|
if (rarray == NULL) {
|
|
|
|
*rval = JSVAL_NULL;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rval = OBJECT_TO_JSVAL(rarray);
|
|
|
|
|
|
|
|
for (int i = 0; !p->isEmpty(); i++) {
|
|
|
|
|
|
|
|
JSObject *x = JS_NewObject(cx, NULL, NULL, NULL);
|
|
|
|
if (x == NULL)
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
EthogramEvent *e = p->pop();
|
|
|
|
|
|
|
|
jsval state = INT_TO_JSVAL(e->s);
|
|
|
|
jsval reason = INT_TO_JSVAL(e->r);
|
|
|
|
jsval ts = INT_TO_JSVAL(e->ts);
|
|
|
|
jsval tus = INT_TO_JSVAL(e->tus);
|
|
|
|
|
|
|
|
jsval filename = STRING_TO_JSVAL(e->filename);
|
|
|
|
jsval lineno = INT_TO_JSVAL(e->lineno);
|
|
|
|
|
|
|
|
if (!JS_SetProperty(cx, x, "state", &state))
|
|
|
|
return JS_FALSE;
|
|
|
|
if (!JS_SetProperty(cx, x, "reason", &reason))
|
|
|
|
return JS_FALSE;
|
|
|
|
if (!JS_SetProperty(cx, x, "ts", &ts))
|
|
|
|
return JS_FALSE;
|
|
|
|
if (!JS_SetProperty(cx, x, "tus", &tus))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
if (!JS_SetProperty(cx, x, "filename", &filename))
|
|
|
|
return JS_FALSE;
|
|
|
|
if (!JS_SetProperty(cx, x, "lineno", &lineno))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
jsval element = OBJECT_TO_JSVAL(x);
|
|
|
|
JS_SetElement(cx, rarray, i, &element);
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
|
|
|
ethogram_getNextEvent(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
EthogramEventBuffer *p;
|
|
|
|
|
|
|
|
p = (EthogramEventBuffer *) JS_GetInstancePrivate(cx, obj, ðogram_class, argv);
|
|
|
|
if (!p)
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
JSObject *x = JS_NewObject(cx, NULL, NULL, NULL);
|
|
|
|
if (x == NULL)
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
if (p->isEmpty()) {
|
|
|
|
*rval = JSVAL_NULL;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
EthogramEvent *e = p->pop();
|
|
|
|
jsval state = INT_TO_JSVAL(e->s);
|
|
|
|
jsval reason = INT_TO_JSVAL(e->r);
|
|
|
|
jsval ts = INT_TO_JSVAL(e->ts);
|
|
|
|
jsval tus = INT_TO_JSVAL(e->tus);
|
|
|
|
|
|
|
|
jsval filename = STRING_TO_JSVAL(e->filename);
|
|
|
|
jsval lineno = INT_TO_JSVAL(e->lineno);
|
|
|
|
|
|
|
|
if (!JS_SetProperty(cx, x, "state", &state))
|
|
|
|
return JS_FALSE;
|
|
|
|
if (!JS_SetProperty(cx, x, "reason", &reason))
|
|
|
|
return JS_FALSE;
|
|
|
|
if (!JS_SetProperty(cx, x, "ts", &ts))
|
|
|
|
return JS_FALSE;
|
|
|
|
if (!JS_SetProperty(cx, x, "tus", &tus))
|
|
|
|
return JS_FALSE;
|
|
|
|
if (!JS_SetProperty(cx, x, "filename", &filename))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
if (!JS_SetProperty(cx, x, "lineno", &lineno))
|
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
*rval = OBJECT_TO_JSVAL(x);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSFunctionSpec ethogram_methods[] = {
|
|
|
|
{"addScript", ethogram_addScript, 1},
|
|
|
|
{"getAllEvents", ethogram_getAllEvents, 0},
|
|
|
|
{"getNextEvent", ethogram_getNextEvent, 0},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An |Ethogram| organizes the output of a collection of files that should be
|
|
|
|
* monitored together. A single object gets events for the group.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_InitEthogram(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
if (!traceVisScriptTable) {
|
|
|
|
traceVisScriptTable = JS_NewHashTable(8, JS_HashString, compare_strings,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_InitClass(cx, JS_GetGlobalObject(cx), NULL, ðogram_class,
|
|
|
|
ethogram_construct, 0, NULL, ethogram_methods,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSBool)
|
|
|
|
js_ShutdownEthogram(JSContext *cx, JSObject *obj,
|
|
|
|
uintN argc, jsval *argv, jsval *rval)
|
|
|
|
{
|
|
|
|
if (traceVisScriptTable)
|
|
|
|
JS_HashTableDestroy(traceVisScriptTable);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MOZ_TRACEVIS */
|