зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1170307 - Inline the common path of NonNullObject; use it instead of ReportObjectRequired in the Debugger. r=shu.
--HG-- extra : rebase_source : ae247e5b84d9d9988dc28e2eec2cdcd5bf3c8f8b extra : amend_source : 0f951eeac1aca42a6a74c09441cf34b248f41935
This commit is contained in:
Родитель
b1d20cf484
Коммит
832040440f
|
@ -92,19 +92,16 @@ JS_ObjectToOuterObject(JSContext* cx, HandleObject obj)
|
|||
return GetOuterObject(cx, obj);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
js::NonNullObject(JSContext* cx, const Value& v)
|
||||
void
|
||||
js::ReportNotObject(JSContext* cx, const Value& v)
|
||||
{
|
||||
if (v.isPrimitive()) {
|
||||
RootedValue value(cx, v);
|
||||
UniquePtr<char[], JS::FreePolicy> bytes =
|
||||
DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, value, nullptr);
|
||||
if (!bytes)
|
||||
return nullptr;
|
||||
MOZ_ASSERT(!v.isObject());
|
||||
|
||||
RootedValue value(cx, v);
|
||||
UniquePtr<char[], JS::FreePolicy> bytes =
|
||||
DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, value, nullptr);
|
||||
if (bytes)
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT, bytes.get());
|
||||
return nullptr;
|
||||
}
|
||||
return &v.toObject();
|
||||
}
|
||||
|
||||
const char*
|
||||
|
@ -292,12 +289,9 @@ js::ToPropertyDescriptor(JSContext* cx, HandleValue descval, bool checkAccessors
|
|||
MutableHandle<PropertyDescriptor> desc)
|
||||
{
|
||||
// step 2
|
||||
if (!descval.isObject()) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT,
|
||||
InformalValueTypeName(descval));
|
||||
RootedObject obj(cx, NonNullObject(cx, descval));
|
||||
if (!obj)
|
||||
return false;
|
||||
}
|
||||
RootedObject obj(cx, &descval.toObject());
|
||||
|
||||
// step 3
|
||||
desc.clear();
|
||||
|
|
|
@ -1270,8 +1270,21 @@ XDRObjectLiteral(XDRState<mode>* xdr, MutableHandleObject obj);
|
|||
extern bool
|
||||
ReportGetterOnlyAssignment(JSContext* cx, bool strict);
|
||||
|
||||
extern JSObject*
|
||||
NonNullObject(JSContext* cx, const Value& v);
|
||||
/*
|
||||
* Report a TypeError: "so-and-so is not an object".
|
||||
* Using NotNullObject is usually less code.
|
||||
*/
|
||||
extern void
|
||||
ReportNotObject(JSContext* cx, const Value& v);
|
||||
|
||||
inline JSObject*
|
||||
NonNullObject(JSContext* cx, const Value& v)
|
||||
{
|
||||
if (v.isObject())
|
||||
return &v.toObject();
|
||||
ReportNotObject(cx, v);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
extern const char*
|
||||
InformalValueTypeName(const Value& v);
|
||||
|
|
|
@ -125,13 +125,6 @@ GetOrCreateFunctionScript(JSContext* cx, HandleFunction fun)
|
|||
return fun->nonLazyScript();
|
||||
}
|
||||
|
||||
bool
|
||||
js::ReportObjectRequired(JSContext* cx)
|
||||
{
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT, "value");
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
ValueToIdentifier(JSContext* cx, HandleValue v, MutableHandleId id)
|
||||
{
|
||||
|
@ -2243,7 +2236,6 @@ Debugger::updateObservesAsmJSOnDebuggees(IsObserving observing)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*** Allocations Tracking *************************************************************************/
|
||||
|
||||
|
@ -2645,11 +2637,9 @@ const Class Debugger::jsclass = {
|
|||
/* static */ Debugger*
|
||||
Debugger::fromThisValue(JSContext* cx, const CallArgs& args, const char* fnname)
|
||||
{
|
||||
if (!args.thisv().isObject()) {
|
||||
ReportObjectRequired(cx);
|
||||
JSObject* thisobj = NonNullObject(cx, args.thisv());
|
||||
if (!thisobj)
|
||||
return nullptr;
|
||||
}
|
||||
JSObject* thisobj = &args.thisv().toObject();
|
||||
if (thisobj->getClass() != &Debugger::jsclass) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
"Debugger", fnname, thisobj->getClass()->name);
|
||||
|
@ -3206,10 +3196,9 @@ Debugger::construct(JSContext* cx, unsigned argc, Value* vp)
|
|||
|
||||
/* Check that the arguments, if any, are cross-compartment wrappers. */
|
||||
for (unsigned i = 0; i < args.length(); i++) {
|
||||
const Value& arg = args[i];
|
||||
if (!arg.isObject())
|
||||
return ReportObjectRequired(cx);
|
||||
JSObject* argobj = &arg.toObject();
|
||||
JSObject* argobj = NonNullObject(cx, args[i]);
|
||||
if (!argobj)
|
||||
return false;
|
||||
if (!argobj->is<CrossCompartmentWrapperObject>()) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_DEBUG_CCW_REQUIRED,
|
||||
"Debugger");
|
||||
|
@ -4565,11 +4554,9 @@ Debugger::wrapScript(JSContext* cx, HandleScript script)
|
|||
static JSObject*
|
||||
DebuggerScript_check(JSContext* cx, const Value& v, const char* clsname, const char* fnname)
|
||||
{
|
||||
if (!v.isObject()) {
|
||||
ReportObjectRequired(cx);
|
||||
JSObject* thisobj = NonNullObject(cx, v);
|
||||
if (!thisobj)
|
||||
return nullptr;
|
||||
}
|
||||
JSObject* thisobj = &v.toObject();
|
||||
if (thisobj->getClass() != &DebuggerScript_class) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
clsname, fnname, thisobj->getClass()->name);
|
||||
|
@ -5592,12 +5579,9 @@ DebuggerSource_construct(JSContext* cx, unsigned argc, Value* vp)
|
|||
static NativeObject*
|
||||
DebuggerSource_checkThis(JSContext* cx, const CallArgs& args, const char* fnname)
|
||||
{
|
||||
if (!args.thisv().isObject()) {
|
||||
ReportObjectRequired(cx);
|
||||
JSObject* thisobj = NonNullObject(cx, args.thisv());
|
||||
if (!thisobj)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSObject* thisobj = &args.thisv().toObject();
|
||||
if (thisobj->getClass() != &DebuggerSource_class) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
"Debugger.Source", fnname, thisobj->getClass()->name);
|
||||
|
@ -5890,11 +5874,9 @@ const Class DebuggerFrame_class = {
|
|||
static NativeObject*
|
||||
CheckThisFrame(JSContext* cx, const CallArgs& args, const char* fnname, bool checkLive)
|
||||
{
|
||||
if (!args.thisv().isObject()) {
|
||||
ReportObjectRequired(cx);
|
||||
JSObject* thisobj = NonNullObject(cx, args.thisv());
|
||||
if (!thisobj)
|
||||
return nullptr;
|
||||
}
|
||||
JSObject* thisobj = &args.thisv().toObject();
|
||||
if (thisobj->getClass() != &DebuggerFrame_class) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
"Debugger.Frame", fnname, thisobj->getClass()->name);
|
||||
|
@ -6113,11 +6095,9 @@ DebuggerArguments_getArg(JSContext* cx, unsigned argc, Value* vp)
|
|||
int32_t i = args.callee().as<JSFunction>().getExtendedSlot(0).toInt32();
|
||||
|
||||
/* Check that the this value is an Arguments object. */
|
||||
if (!args.thisv().isObject()) {
|
||||
ReportObjectRequired(cx);
|
||||
RootedObject argsobj(cx, NonNullObject(cx, args.thisv()));
|
||||
if (!argsobj)
|
||||
return false;
|
||||
}
|
||||
RootedObject argsobj(cx, &args.thisv().toObject());
|
||||
if (argsobj->getClass() != &DebuggerArguments_class) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
"Arguments", "getArgument", argsobj->getClass()->name);
|
||||
|
@ -6660,11 +6640,9 @@ const Class DebuggerObject_class = {
|
|||
static NativeObject*
|
||||
DebuggerObject_checkThis(JSContext* cx, const CallArgs& args, const char* fnname)
|
||||
{
|
||||
if (!args.thisv().isObject()) {
|
||||
ReportObjectRequired(cx);
|
||||
JSObject* thisobj = NonNullObject(cx, args.thisv());
|
||||
if (!thisobj)
|
||||
return nullptr;
|
||||
}
|
||||
JSObject* thisobj = &args.thisv().toObject();
|
||||
if (thisobj->getClass() != &DebuggerObject_class) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
"Debugger.Object", fnname, thisobj->getClass()->name);
|
||||
|
@ -7608,11 +7586,9 @@ static NativeObject*
|
|||
DebuggerEnv_checkThis(JSContext* cx, const CallArgs& args, const char* fnname,
|
||||
bool requireDebuggee = true)
|
||||
{
|
||||
if (!args.thisv().isObject()) {
|
||||
ReportObjectRequired(cx);
|
||||
JSObject* thisobj = NonNullObject(cx, args.thisv());
|
||||
if (!thisobj)
|
||||
return nullptr;
|
||||
}
|
||||
JSObject* thisobj = &args.thisv().toObject();
|
||||
if (thisobj->getClass() != &DebuggerEnv_class) {
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||
"Debugger.Environment", fnname, thisobj->getClass()->name);
|
||||
|
|
Загрузка…
Ссылка в новой задаче