summaryrefslogtreecommitdiffstats
path: root/src/dom/js/jsdbgapi.c
diff options
context:
space:
mode:
authorBob Jamison <ishmalius@gmail.com>2007-03-05 10:34:59 +0000
committerishmal <ishmal@users.sourceforge.net>2007-03-05 10:34:59 +0000
commit33837efd4b94c4ebb80f95b3d9dbb6efd5499a98 (patch)
treede482d7687b3bffa97cc78608ba75a8ad7e52b60 /src/dom/js/jsdbgapi.c
parentAdding optional dialog preview. Implments RFE [ 1435276 ] switch preview on/o... (diff)
downloadinkscape-33837efd4b94c4ebb80f95b3d9dbb6efd5499a98.tar.gz
inkscape-33837efd4b94c4ebb80f95b3d9dbb6efd5499a98.zip
update JS
(bzr r2555)
Diffstat (limited to 'src/dom/js/jsdbgapi.c')
-rw-r--r--src/dom/js/jsdbgapi.c215
1 files changed, 180 insertions, 35 deletions
diff --git a/src/dom/js/jsdbgapi.c b/src/dom/js/jsdbgapi.c
index 8713a86b9..cddbd4808 100644
--- a/src/dom/js/jsdbgapi.c
+++ b/src/dom/js/jsdbgapi.c
@@ -278,14 +278,18 @@ DropWatchPoint(JSContext *cx, JSWatchPoint *wp)
}
void
-js_MarkWatchPoints(JSRuntime *rt)
+js_MarkWatchPoints(JSContext *cx)
{
+ JSRuntime *rt;
JSWatchPoint *wp;
+ rt = cx->runtime;
for (wp = (JSWatchPoint *)rt->watchPointList.next;
wp != (JSWatchPoint *)&rt->watchPointList;
wp = (JSWatchPoint *)wp->links.next) {
MARK_SCOPE_PROPERTY(wp->sprop);
+ if (wp->sprop->attrs & JSPROP_SETTER)
+ JS_MarkGCThing(cx, wp->setter, "wp->setter", NULL);
}
}
@@ -335,7 +339,7 @@ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
JSRuntime *rt;
JSWatchPoint *wp;
JSScopeProperty *sprop;
- jsval userid;
+ jsval propid, userid;
JSScope *scope;
JSBool ok;
@@ -346,11 +350,14 @@ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
sprop = wp->sprop;
if (wp->object == obj && SPROP_USERID(sprop) == id) {
JS_LOCK_OBJ(cx, obj);
- userid = SPROP_USERID(sprop);
+ propid = ID_TO_VALUE(sprop->id);
+ userid = (sprop->flags & SPROP_HAS_SHORTID)
+ ? INT_TO_JSVAL(sprop->shortid)
+ : propid;
scope = OBJ_SCOPE(obj);
JS_UNLOCK_OBJ(cx, obj);
HoldWatchPoint(wp);
- ok = wp->handler(cx, obj, userid,
+ ok = wp->handler(cx, obj, propid,
SPROP_HAS_VALID_SLOT(sprop, scope)
? OBJ_GET_SLOT(cx, obj, wp->sprop->slot)
: JSVAL_VOID,
@@ -361,14 +368,58 @@ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
* stack-walking security code in the setter will correctly
* identify the guilty party.
*/
- JSObject *funobj = (JSObject *) wp->closure;
- JSFunction *fun = (JSFunction *) JS_GetPrivate(cx, funobj);
+ JSObject *closure;
+ JSClass *clasp;
+ JSFunction *fun;
+ JSScript *script;
+ uintN nslots;
+ jsval smallv[5];
+ jsval *argv;
JSStackFrame frame;
+ closure = (JSObject *) wp->closure;
+ clasp = OBJ_GET_CLASS(cx, closure);
+ if (clasp == &js_FunctionClass) {
+ fun = (JSFunction *) JS_GetPrivate(cx, closure);
+ script = FUN_SCRIPT(fun);
+ } else if (clasp == &js_ScriptClass) {
+ fun = NULL;
+ script = (JSScript *) JS_GetPrivate(cx, closure);
+ } else {
+ fun = NULL;
+ script = NULL;
+ }
+
+ nslots = 2;
+ if (fun) {
+ nslots += fun->nargs;
+ if (FUN_NATIVE(fun))
+ nslots += fun->extra;
+ }
+
+ if (nslots <= sizeof (smallv) / sizeof (smallv[0])) {
+ argv = smallv;
+ } else {
+ argv = JS_malloc(cx, nslots * sizeof(jsval));
+ if (!argv) {
+ DropWatchPoint(cx, wp);
+ return JS_FALSE;
+ }
+ }
+
+ argv[0] = OBJECT_TO_JSVAL(closure);
+ argv[1] = JSVAL_NULL;
+ memset(argv + 2, 0, (nslots - 2) * sizeof(jsval));
+
memset(&frame, 0, sizeof(frame));
- frame.script = FUN_SCRIPT(fun);
+ frame.script = script;
+ if (script)
+ frame.pc = script->code;
frame.fun = fun;
+ frame.argv = argv + 2;
frame.down = cx->fp;
+ frame.scopeChain = OBJ_GET_PARENT(cx, closure);
+
cx->fp = &frame;
ok = !wp->setter ||
((sprop->attrs & JSPROP_SETTER)
@@ -376,6 +427,8 @@ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
1, vp, vp)
: wp->setter(cx, OBJ_THIS_OBJECT(cx, obj), userid, vp));
cx->fp = frame.down;
+ if (argv != smallv)
+ JS_free(cx, argv);
}
return DropWatchPoint(cx, wp);
}
@@ -393,6 +446,7 @@ js_watch_set_wrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval userid;
funobj = JSVAL_TO_OBJECT(argv[-2]);
+ JS_ASSERT(OBJ_GET_CLASS(cx, funobj) == &js_FunctionClass);
wrapper = (JSFunction *) JS_GetPrivate(cx, funobj);
userid = ATOM_KEY(wrapper->atom);
*rval = argv[0];
@@ -408,12 +462,14 @@ js_WrapWatchedSetter(JSContext *cx, jsid id, uintN attrs, JSPropertyOp setter)
if (!(attrs & JSPROP_SETTER))
return &js_watch_set; /* & to silence schoolmarmish MSVC */
- if (!JSVAL_IS_INT(id)) {
- atom = (JSAtom *)id;
- } else {
- atom = js_AtomizeInt(cx, JSVAL_TO_INT(id), 0);
+ if (JSID_IS_ATOM(id)) {
+ atom = JSID_TO_ATOM(id);
+ } else if (JSID_IS_INT(id)) {
+ atom = js_AtomizeInt(cx, JSID_TO_INT(id), 0);
if (!atom)
return NULL;
+ } else {
+ atom = NULL;
}
wrapper = js_NewFunction(cx, NULL, js_watch_set_wrapper, 1, 0,
OBJ_GET_PARENT(cx, (JSObject *)setter),
@@ -444,13 +500,13 @@ JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
}
if (JSVAL_IS_INT(id)) {
- propid = (jsid)id;
+ propid = INT_JSVAL_TO_JSID(id);
atom = NULL;
} else {
atom = js_ValueToStringAtom(cx, id);
if (!atom)
return JS_FALSE;
- propid = (jsid)atom;
+ propid = ATOM_TO_JSID(atom);
}
if (!js_LookupProperty(cx, obj, propid, &pobj, &prop))
@@ -473,7 +529,8 @@ JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
/* Clone the prototype property so we can watch the right object. */
jsval value;
JSPropertyOp getter, setter;
- uintN attrs;
+ uintN attrs, flags;
+ intN shortid;
if (OBJ_IS_NATIVE(pobj)) {
value = SPROP_HAS_VALID_SLOT(sprop, OBJ_SCOPE(pobj))
@@ -482,18 +539,23 @@ JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
getter = sprop->getter;
setter = sprop->setter;
attrs = sprop->attrs;
+ flags = sprop->flags;
+ shortid = sprop->shortid;
} else {
- if (!OBJ_GET_PROPERTY(cx, pobj, id, &value)) {
+ if (!OBJ_GET_PROPERTY(cx, pobj, id, &value) ||
+ !OBJ_GET_ATTRIBUTES(cx, pobj, id, prop, &attrs)) {
OBJ_DROP_PROPERTY(cx, pobj, prop);
return JS_FALSE;
}
- getter = setter = JS_PropertyStub;
- attrs = JSPROP_ENUMERATE;
+ getter = setter = NULL;
+ flags = 0;
+ shortid = 0;
}
OBJ_DROP_PROPERTY(cx, pobj, prop);
- if (!js_DefineProperty(cx, obj, propid, value, getter, setter, attrs,
- &prop)) {
+ /* Recall that obj is native, whether or not pobj is native. */
+ if (!js_DefineNativeProperty(cx, obj, propid, value, getter, setter,
+ attrs, flags, shortid, &prop)) {
return JS_FALSE;
}
sprop = (JSScopeProperty *) prop;
@@ -524,10 +586,8 @@ JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
JS_free(cx, wp);
goto out;
}
- JS_APPEND_LINK(&wp->links, &rt->watchPointList);
wp->object = obj;
- wp->sprop = sprop;
- JS_ASSERT(sprop->setter != js_watch_set);
+ JS_ASSERT(sprop->setter != js_watch_set || pobj != obj);
wp->setter = sprop->setter;
wp->nrefs = 1;
@@ -535,10 +595,16 @@ JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
sprop = js_ChangeNativePropertyAttrs(cx, obj, sprop, 0, sprop->attrs,
sprop->getter, watcher);
if (!sprop) {
+ /* Self-link wp->links so DropWatchPoint can JS_REMOVE_LINK it. */
+ JS_INIT_CLIST(&wp->links);
DropWatchPoint(cx, wp);
ok = JS_FALSE;
goto out;
}
+ wp->sprop = sprop;
+
+ /* Now that wp is fully initialized, append it to rt's wp list. */
+ JS_APPEND_LINK(&wp->links, &rt->watchPointList);
}
wp->handler = handler;
wp->closure = closure;
@@ -628,6 +694,12 @@ JS_GetFunctionScript(JSContext *cx, JSFunction *fun)
return FUN_SCRIPT(fun);
}
+JS_PUBLIC_API(JSNative)
+JS_GetFunctionNative(JSContext *cx, JSFunction *fun)
+{
+ return FUN_NATIVE(fun);
+}
+
JS_PUBLIC_API(JSPrincipals *)
JS_GetScriptPrincipals(JSContext *cx, JSScript *script)
{
@@ -673,12 +745,16 @@ JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp)
JS_PUBLIC_API(JSPrincipals *)
JS_StackFramePrincipals(JSContext *cx, JSStackFrame *fp)
{
- if (fp->fun && cx->findObjectPrincipals) {
- JSObject *callee = JSVAL_TO_OBJECT(fp->argv[-2]);
+ if (fp->fun) {
+ JSRuntime *rt = cx->runtime;
+
+ if (rt->findObjectPrincipals) {
+ JSObject *callee = JSVAL_TO_OBJECT(fp->argv[-2]);
- if (fp->fun->object != callee)
- return cx->findObjectPrincipals(cx, callee);
- /* FALL THROUGH */
+ if (fp->fun->object != callee)
+ return rt->findObjectPrincipals(cx, callee);
+ /* FALL THROUGH */
+ }
}
if (fp->script)
return fp->script->principals;
@@ -688,11 +764,24 @@ JS_StackFramePrincipals(JSContext *cx, JSStackFrame *fp)
JS_PUBLIC_API(JSPrincipals *)
JS_EvalFramePrincipals(JSContext *cx, JSStackFrame *fp, JSStackFrame *caller)
{
- if (cx->findObjectPrincipals)
- return cx->findObjectPrincipals(cx, JSVAL_TO_OBJECT(fp->argv[-2]));
+ JSRuntime *rt;
+ JSObject *callee;
+ JSPrincipals *principals, *callerPrincipals;
+
+ rt = cx->runtime;
+ if (rt->findObjectPrincipals) {
+ callee = JSVAL_TO_OBJECT(fp->argv[-2]);
+ principals = rt->findObjectPrincipals(cx, callee);
+ } else {
+ principals = NULL;
+ }
if (!caller)
- return NULL;
- return JS_StackFramePrincipals(cx, caller);
+ return principals;
+ callerPrincipals = JS_StackFramePrincipals(cx, caller);
+ return (callerPrincipals && principals &&
+ callerPrincipals->subsume(callerPrincipals, principals))
+ ? principals
+ : callerPrincipals;
}
JS_PUBLIC_API(void *)
@@ -796,6 +885,12 @@ JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp)
return (fp->flags & JSFRAME_CONSTRUCTING) != 0;
}
+JS_PUBLIC_API(JSObject *)
+JS_GetFrameCalleeObject(JSContext *cx, JSStackFrame *fp)
+{
+ return fp->argv ? JSVAL_TO_OBJECT(fp->argv[-2]) : NULL;
+}
+
JS_PUBLIC_API(JSBool)
JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp)
{
@@ -837,7 +932,7 @@ JS_GetScriptLineExtent(JSContext *cx, JSScript *script)
JS_PUBLIC_API(JSVersion)
JS_GetScriptVersion(JSContext *cx, JSScript *script)
{
- return script->version;
+ return script->version & JSVERSION_MASK;
}
/***************************************************************************/
@@ -865,7 +960,7 @@ JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
const char *filename, uintN lineno,
jsval *rval)
{
- uint32 flags;
+ uint32 flags, options;
JSScript *script;
JSBool ok;
@@ -875,10 +970,13 @@ JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
*/
flags = fp->flags;
fp->flags |= JSFRAME_DEBUGGER | JSFRAME_EVAL;
+ options = cx->options;
+ cx->options = options | JSOPTION_COMPILE_N_GO;
script = JS_CompileUCScriptForPrincipals(cx, fp->scopeChain,
JS_StackFramePrincipals(cx, fp),
bytes, length, filename, lineno);
fp->flags = flags;
+ cx->options = options;
if (!script)
return JS_FALSE;
@@ -890,14 +988,15 @@ JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
JS_PUBLIC_API(JSBool)
JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
- const char *bytes, uintN length,
+ const char *bytes, uintN nbytes,
const char *filename, uintN lineno,
jsval *rval)
{
+ size_t length = nbytes;
jschar *chars;
JSBool ok;
- chars = js_InflateString(cx, bytes, length);
+ chars = js_InflateString(cx, bytes, &length);
if (!chars)
return JS_FALSE;
ok = JS_EvaluateUCInStackFrame(cx, fp, chars, length, filename, lineno,
@@ -1258,3 +1357,49 @@ JS_GetScriptTotalSize(JSContext *cx, JSScript *script)
return nbytes;
}
+
+JS_PUBLIC_API(uint32)
+JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp)
+{
+ if (!fp)
+ fp = cx->fp;
+ while (fp) {
+ if (fp->script) {
+ 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)
+{
+ return (*js_GetGCThingFlags(obj) & GCF_SYSTEM) != 0;
+}
+
+JS_PUBLIC_API(void)
+JS_FlagSystemObject(JSContext *cx, JSObject *obj)
+{
+ uint8 *flagp;
+
+ flagp = js_GetGCThingFlags(obj);
+ *flagp |= GCF_SYSTEM;
+}