mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1271653 - Implement a C++ interface for global/allocationSite/errorMessageName;r=jimb
This commit is contained in:
parent
b36a748d2f
commit
9ca9e93794
@ -8128,13 +8128,6 @@ DebuggerObject_getBoundArguments(JSContext* cx, unsigned argc, Value* vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
null(CallArgs& args)
|
||||
{
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef SPIDERMONKEY_PROMISE
|
||||
static bool
|
||||
DebuggerObject_getIsPromise(JSContext* cx, unsigned argc, Value* vp)
|
||||
@ -8281,39 +8274,26 @@ DebuggerObject_getPromiseDependentPromises(JSContext* cx, unsigned argc, Value*
|
||||
static bool
|
||||
DebuggerObject_getGlobal(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "get global", args, dbg, obj);
|
||||
THIS_DEBUGOBJECT(cx, argc, vp, "get global", args, object)
|
||||
|
||||
RootedValue v(cx, ObjectValue(obj->global()));
|
||||
if (!dbg->wrapDebuggeeValue(cx, &v))
|
||||
RootedObject result(cx);
|
||||
if (!DebuggerObject::global(cx, object, &result))
|
||||
return false;
|
||||
args.rval().set(v);
|
||||
|
||||
args.rval().setObject(*result);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ SavedFrame*
|
||||
Debugger::getObjectAllocationSite(JSObject& obj)
|
||||
{
|
||||
JSObject* metadata = GetAllocationMetadata(&obj);
|
||||
if (!metadata)
|
||||
return nullptr;
|
||||
|
||||
MOZ_ASSERT(!metadata->is<WrapperObject>());
|
||||
return SavedFrame::isSavedFrameAndNotProto(*metadata)
|
||||
? &metadata->as<SavedFrame>()
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
static bool
|
||||
DebuggerObject_getAllocationSite(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get allocationSite", args, obj);
|
||||
THIS_DEBUGOBJECT(cx, argc, vp, "get allocationSite", args, object)
|
||||
|
||||
RootedObject allocSite(cx, Debugger::getObjectAllocationSite(*obj));
|
||||
if (!allocSite)
|
||||
return null(args);
|
||||
if (!cx->compartment()->wrap(cx, &allocSite))
|
||||
RootedObject result(cx);
|
||||
if (!DebuggerObject::allocationSite(cx, object, &result))
|
||||
return false;
|
||||
args.rval().setObject(*allocSite);
|
||||
|
||||
args.rval().setObjectOrNull(result);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -8323,33 +8303,16 @@ DebuggerObject_getAllocationSite(JSContext* cx, unsigned argc, Value* vp)
|
||||
static bool
|
||||
DebuggerObject_getErrorMessageName(JSContext *cx, unsigned argc, Value* vp)
|
||||
{
|
||||
THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get errorMessageName", args, referent);
|
||||
THIS_DEBUGOBJECT(cx, argc, vp, "get errorMessageName", args, object)
|
||||
|
||||
JSObject* obj = referent;
|
||||
if (IsCrossCompartmentWrapper(obj))
|
||||
obj = CheckedUnwrap(obj);
|
||||
|
||||
if (!obj) {
|
||||
JS_ReportError(cx, "Permission denied to access object");
|
||||
RootedString result(cx);
|
||||
if (!DebuggerObject::errorMessageName(cx, object, &result))
|
||||
return false;
|
||||
}
|
||||
|
||||
JSErrorReport* report = nullptr;
|
||||
if (obj->is<ErrorObject>())
|
||||
report = obj->as<ErrorObject>().getErrorReport();
|
||||
|
||||
if (report) {
|
||||
const JSErrorFormatString* efs = GetErrorMessage(nullptr, report->errorNumber);
|
||||
if (efs) {
|
||||
RootedString str(cx, JS_NewStringCopyZ(cx, efs->name));
|
||||
if (!cx->compartment()->wrap(cx, &str))
|
||||
return false;
|
||||
args.rval().setString(str);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
args.rval().setUndefined();
|
||||
if (result)
|
||||
args.rval().setString(result);
|
||||
else
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -8923,6 +8886,16 @@ DebuggerObject::className(JSContext* cx, Handle<DebuggerObject*> object,
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
DebuggerObject::global(JSContext* cx, Handle<DebuggerObject*> object, MutableHandleObject result)
|
||||
{
|
||||
RootedObject referent(cx, object->referent());
|
||||
Debugger* dbg = object->owner();
|
||||
|
||||
result.set(&referent->global());
|
||||
return dbg->wrapDebuggeeObject(cx, result);
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
DebuggerObject::name(JSContext* cx, Handle<DebuggerObject*> object, MutableHandleString result)
|
||||
{
|
||||
@ -9027,6 +9000,67 @@ DebuggerObject::boundArguments(JSContext* cx, Handle<DebuggerObject*> object,
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ SavedFrame*
|
||||
Debugger::getObjectAllocationSite(JSObject& obj)
|
||||
{
|
||||
JSObject* metadata = GetAllocationMetadata(&obj);
|
||||
if (!metadata)
|
||||
return nullptr;
|
||||
|
||||
MOZ_ASSERT(!metadata->is<WrapperObject>());
|
||||
return SavedFrame::isSavedFrameAndNotProto(*metadata)
|
||||
? &metadata->as<SavedFrame>()
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
DebuggerObject::allocationSite(JSContext* cx, Handle<DebuggerObject*> object,
|
||||
MutableHandleObject result)
|
||||
{
|
||||
RootedObject referent(cx, object->referent());
|
||||
|
||||
RootedObject allocSite(cx, Debugger::getObjectAllocationSite(*referent));
|
||||
if (!cx->compartment()->wrap(cx, &allocSite))
|
||||
return false;
|
||||
|
||||
result.set(allocSite);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
DebuggerObject::errorMessageName(JSContext* cx, Handle<DebuggerObject*> object,
|
||||
MutableHandleString result)
|
||||
{
|
||||
RootedObject referent(cx, object->referent());
|
||||
|
||||
JSObject* obj = referent;
|
||||
if (IsCrossCompartmentWrapper(obj))
|
||||
obj = CheckedUnwrap(obj);
|
||||
|
||||
if (!obj) {
|
||||
JS_ReportError(cx, "Permission denied to access object");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj->is<ErrorObject>()) {
|
||||
JSErrorReport* report = obj->as<ErrorObject>().getErrorReport();
|
||||
if (report) {
|
||||
const JSErrorFormatString* efs = GetErrorMessage(nullptr, report->errorNumber);
|
||||
if (efs) {
|
||||
RootedString str(cx, JS_NewStringCopyZ(cx, efs->name));
|
||||
if (!cx->compartment()->wrap(cx, &str))
|
||||
return false;
|
||||
|
||||
result.set(str);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.set(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
DebuggerObject::isExtensible(JSContext* cx, Handle<DebuggerObject*> object, bool& result)
|
||||
{
|
||||
|
@ -1059,6 +1059,7 @@ class DebuggerObject : public NativeObject
|
||||
static bool isGlobal(JSContext* cx, Handle<DebuggerObject*> object);
|
||||
static bool className(JSContext* cx, Handle<DebuggerObject*> object,
|
||||
MutableHandleString result);
|
||||
static bool global(JSContext* cx, Handle<DebuggerObject*> object, MutableHandleObject result);
|
||||
static bool name(JSContext* cx, Handle<DebuggerObject*> object, MutableHandleString result);
|
||||
static bool displayName(JSContext* cx, Handle<DebuggerObject*> object,
|
||||
MutableHandleString result);
|
||||
@ -1071,6 +1072,10 @@ class DebuggerObject : public NativeObject
|
||||
MutableHandleValue result);
|
||||
static bool boundArguments(JSContext* cx, Handle<DebuggerObject*> object,
|
||||
MutableHandle<ValueVector> result);
|
||||
static bool allocationSite(JSContext* cx, Handle<DebuggerObject*> object,
|
||||
MutableHandleObject result);
|
||||
static bool errorMessageName(JSContext* cx, Handle<DebuggerObject*> object,
|
||||
MutableHandleString result);
|
||||
|
||||
static bool isExtensible(JSContext* cx, Handle<DebuggerObject*> object, bool& result);
|
||||
static bool isSealed(JSContext* cx, Handle<DebuggerObject*> object, bool& result);
|
||||
|
Loading…
Reference in New Issue
Block a user