📄 jsdbgapi.c
字号:
{ JSObject *funobj; JSFunction *wrapper; 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]; return js_watch_set(cx, obj, userid, rval);}JSPropertyOpjs_WrapWatchedSetter(JSContext *cx, jsid id, uintN attrs, JSPropertyOp setter){ JSAtom *atom; JSFunction *wrapper; 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)) { 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), atom); if (!wrapper) return NULL; return (JSPropertyOp) wrapper->object;}JS_PUBLIC_API(JSBool)JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id, JSWatchPointHandler handler, void *closure){ JSAtom *atom; jsid propid; JSObject *pobj; JSProperty *prop; JSScopeProperty *sprop; JSRuntime *rt; JSBool ok; JSWatchPoint *wp; JSPropertyOp watcher; if (!OBJ_IS_NATIVE(obj)) { JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_WATCH, OBJ_GET_CLASS(cx, obj)->name); return JS_FALSE; } if (JSVAL_IS_INT(id)) { propid = INT_JSVAL_TO_JSID(id); atom = NULL; } else { atom = js_ValueToStringAtom(cx, id); if (!atom) return JS_FALSE; propid = ATOM_TO_JSID(atom); } 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. */ sprop = js_FindWatchPoint(rt, OBJ_SCOPE(obj), propid); if (!sprop) { /* Make a new property in obj so we can watch for the first set. */ if (!js_DefineProperty(cx, obj, propid, JSVAL_VOID, NULL, NULL, JSPROP_ENUMERATE, &prop)) { return JS_FALSE; } sprop = (JSScopeProperty *) prop; } } else if (pobj != obj) { /* Clone the prototype property so we can watch the right object. */ jsval value; JSPropertyOp getter, setter; uintN attrs, flags; intN shortid; if (OBJ_IS_NATIVE(pobj)) { value = SPROP_HAS_VALID_SLOT(sprop, OBJ_SCOPE(pobj)) ? LOCKED_OBJ_GET_SLOT(pobj, sprop->slot) : JSVAL_VOID; getter = sprop->getter; setter = sprop->setter; attrs = sprop->attrs; flags = sprop->flags; shortid = sprop->shortid; } else { 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 = NULL; flags = 0; shortid = 0; } OBJ_DROP_PROPERTY(cx, pobj, 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; } /* * At this point, prop/sprop exists in obj, obj is locked, and we must * OBJ_DROP_PROPERTY(cx, obj, prop) before returning. */ ok = JS_TRUE; wp = FindWatchPoint(rt, OBJ_SCOPE(obj), propid); if (!wp) { watcher = js_WrapWatchedSetter(cx, propid, sprop->attrs, sprop->setter); if (!watcher) { ok = JS_FALSE; goto out; } wp = (JSWatchPoint *) JS_malloc(cx, sizeof *wp); if (!wp) { ok = JS_FALSE; goto out; } wp->handler = NULL; wp->closure = NULL; ok = js_AddRoot(cx, &wp->closure, "wp->closure"); if (!ok) { JS_free(cx, wp); goto out; } wp->object = obj; JS_ASSERT(sprop->setter != js_watch_set || pobj != obj); wp->setter = sprop->setter; wp->flags = JSWP_LIVE; /* XXXbe nest in obj lock here */ sprop = js_ChangeNativePropertyAttrs(cx, obj, sprop, 0, sprop->attrs, sprop->getter, watcher); if (!sprop) { /* Self-link so DropWatchPoint can JS_REMOVE_LINK it. */ JS_INIT_CLIST(&wp->links); DropWatchPoint(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). */ JS_ASSERT(!FindWatchPoint(rt, OBJ_SCOPE(obj), propid)); JS_APPEND_LINK(&wp->links, &rt->watchPointList); } wp->handler = handler; wp->closure = closure;out: OBJ_DROP_PROPERTY(cx, obj, prop); return ok;}JS_PUBLIC_API(JSBool)JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsval id, JSWatchPointHandler *handlerp, void **closurep){ JSRuntime *rt; JSWatchPoint *wp; rt = cx->runtime; for (wp = (JSWatchPoint *)rt->watchPointList.next; wp != (JSWatchPoint *)&rt->watchPointList; 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 DropWatchPoint(cx, wp, JSWP_LIVE); } } 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; rt = cx->runtime; for (wp = (JSWatchPoint *)rt->watchPointList.next; wp != (JSWatchPoint *)&rt->watchPointList; wp = next) { next = (JSWatchPoint *)wp->links.next; if (wp->object == obj && !DropWatchPoint(cx, wp, JSWP_LIVE)) return JS_FALSE; } return JS_TRUE;}JS_PUBLIC_API(JSBool)JS_ClearAllWatchPoints(JSContext *cx){ JSRuntime *rt; JSWatchPoint *wp, *next; rt = cx->runtime; for (wp = (JSWatchPoint *)rt->watchPointList.next; wp != (JSWatchPoint *)&rt->watchPointList; wp = next) { next = (JSWatchPoint *)wp->links.next; if (!DropWatchPoint(cx, wp, JSWP_LIVE)) return JS_FALSE; } 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);}JS_PUBLIC_API(JSScript *)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){ return script->principals;}/************************************************************************//* * Stack Frame Iterator */JS_PUBLIC_API(JSStackFrame *)JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp){ *iteratorp = (*iteratorp == NULL) ? cx->fp : (*iteratorp)->down; 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){ return fp->pc;}JS_PUBLIC_API(JSStackFrame *)JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp){ if (!fp) fp = cx->fp; while ((fp = fp->down) != NULL) { if (fp->script) return fp; } return NULL;}JS_PUBLIC_API(JSPrincipals *)JS_StackFramePrincipals(JSContext *cx, JSStackFrame *fp){ if (fp->fun) { JSRuntime *rt = cx->runtime; if (rt->findObjectPrincipals) { JSObject *callee = JSVAL_TO_OBJECT(fp->argv[-2]); if (fp->fun->object != callee) return rt->findObjectPrincipals(cx, callee); /* FALL THROUGH */ } } if (fp->script) return fp->script->principals; return NULL;}JS_PUBLIC_API(JSPrincipals *)JS_EvalFramePrincipals(JSContext *cx, JSStackFrame *fp, JSStackFrame *caller){ 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 principals; callerPrincipals = JS_StackFramePrincipals(cx, caller); return (callerPrincipals && principals && callerPrincipals->subsume(callerPrincipals, principals)) ? principals : callerPrincipals;}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){ return fp->scopeChain;}JS_PUBLIC_API(JSObject *)JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp){ /* 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){ 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 */ return js_GetCallObject(cx, fp, NULL);}JS_PUBLIC_API(JSObject *)JS_GetFrameThis(JSContext *cx, JSStackFrame *fp){ return fp->thisp;}JS_PUBLIC_API(JSFunction *)JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp){ return fp->fun;}JS_PUBLIC_API(JSObject *)JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp){ return fp->argv && fp->fun ? JSVAL_TO_OBJECT(fp->argv[-2]) : NULL;}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){ return fp->argv ? JSVAL_TO_OBJECT(fp->argv[-2]) : NULL;}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){ return fp->rval;}JS_PUBLIC_API(void)JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval){ fp->rval = rval;}/************************************************************************/JS_PUBLIC_API(const char *)JS_GetScriptFilename(JSContext *cx, JSScript *script){ return script->filename;}JS_PUBLIC_API(uintN)JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -