Bug 1112943 - Cache Debugger.Source.text. (r=jimb)

This commit is contained in:
Shu-yu Guo 2014-12-18 13:25:50 -08:00
parent 84af0f95d9
commit cd1faae46b

View File

@ -90,6 +90,7 @@ extern const Class DebuggerSource_class;
enum {
JSSLOT_DEBUGSOURCE_OWNER,
JSSLOT_DEBUGSOURCE_TEXT,
JSSLOT_DEBUGSOURCE_COUNT
};
@ -4848,7 +4849,7 @@ DebuggerSource_construct(JSContext *cx, unsigned argc, Value *vp)
return false;
}
static JSObject *
static NativeObject *
DebuggerSource_checkThis(JSContext *cx, const CallArgs &args, const char *fnname)
{
if (!args.thisv().isObject()) {
@ -4863,18 +4864,20 @@ DebuggerSource_checkThis(JSContext *cx, const CallArgs &args, const char *fnname
return nullptr;
}
NativeObject *nthisobj = &thisobj->as<NativeObject>();
if (!GetSourceReferent(thisobj)) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
"Debugger.Frame", fnname, "prototype object");
return nullptr;
}
return thisobj;
return nthisobj;
}
#define THIS_DEBUGSOURCE_REFERENT(cx, argc, vp, fnname, args, obj, sourceObject) \
CallArgs args = CallArgsFromVp(argc, vp); \
RootedObject obj(cx, DebuggerSource_checkThis(cx, args, fnname)); \
RootedNativeObject obj(cx, DebuggerSource_checkThis(cx, args, fnname)); \
if (!obj) \
return false; \
RootedScriptSource sourceObject(cx, GetSourceReferent(obj)); \
@ -4885,6 +4888,12 @@ static bool
DebuggerSource_getText(JSContext *cx, unsigned argc, Value *vp)
{
THIS_DEBUGSOURCE_REFERENT(cx, argc, vp, "(get text)", args, obj, sourceObject);
Value textv = obj->getReservedSlot(JSSLOT_DEBUGSOURCE_TEXT);
if (!textv.isUndefined()) {
MOZ_ASSERT(textv.isString());
args.rval().set(textv);
return true;
}
ScriptSource *ss = sourceObject->source();
bool hasSourceData = ss->hasSourceData();
@ -4897,6 +4906,7 @@ DebuggerSource_getText(JSContext *cx, unsigned argc, Value *vp)
return false;
args.rval().setString(str);
obj->setReservedSlot(JSSLOT_DEBUGSOURCE_TEXT, args.rval());
return true;
}