зеркало из 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);
|
return GetOuterObject(cx, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSObject*
|
void
|
||||||
js::NonNullObject(JSContext* cx, const Value& v)
|
js::ReportNotObject(JSContext* cx, const Value& v)
|
||||||
{
|
{
|
||||||
if (v.isPrimitive()) {
|
MOZ_ASSERT(!v.isObject());
|
||||||
|
|
||||||
RootedValue value(cx, v);
|
RootedValue value(cx, v);
|
||||||
UniquePtr<char[], JS::FreePolicy> bytes =
|
UniquePtr<char[], JS::FreePolicy> bytes =
|
||||||
DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, value, nullptr);
|
DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, value, nullptr);
|
||||||
if (!bytes)
|
if (bytes)
|
||||||
return nullptr;
|
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT, bytes.get());
|
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT, bytes.get());
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return &v.toObject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
|
@ -292,12 +289,9 @@ js::ToPropertyDescriptor(JSContext* cx, HandleValue descval, bool checkAccessors
|
||||||
MutableHandle<PropertyDescriptor> desc)
|
MutableHandle<PropertyDescriptor> desc)
|
||||||
{
|
{
|
||||||
// step 2
|
// step 2
|
||||||
if (!descval.isObject()) {
|
RootedObject obj(cx, NonNullObject(cx, descval));
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT,
|
if (!obj)
|
||||||
InformalValueTypeName(descval));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
RootedObject obj(cx, &descval.toObject());
|
|
||||||
|
|
||||||
// step 3
|
// step 3
|
||||||
desc.clear();
|
desc.clear();
|
||||||
|
|
|
@ -1270,8 +1270,21 @@ XDRObjectLiteral(XDRState<mode>* xdr, MutableHandleObject obj);
|
||||||
extern bool
|
extern bool
|
||||||
ReportGetterOnlyAssignment(JSContext* cx, bool strict);
|
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*
|
extern const char*
|
||||||
InformalValueTypeName(const Value& v);
|
InformalValueTypeName(const Value& v);
|
||||||
|
|
|
@ -125,13 +125,6 @@ GetOrCreateFunctionScript(JSContext* cx, HandleFunction fun)
|
||||||
return fun->nonLazyScript();
|
return fun->nonLazyScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
js::ReportObjectRequired(JSContext* cx)
|
|
||||||
{
|
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_NONNULL_OBJECT, "value");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ValueToIdentifier(JSContext* cx, HandleValue v, MutableHandleId id)
|
ValueToIdentifier(JSContext* cx, HandleValue v, MutableHandleId id)
|
||||||
{
|
{
|
||||||
|
@ -2243,7 +2236,6 @@ Debugger::updateObservesAsmJSOnDebuggees(IsObserving observing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*** Allocations Tracking *************************************************************************/
|
/*** Allocations Tracking *************************************************************************/
|
||||||
|
|
||||||
|
@ -2645,11 +2637,9 @@ const Class Debugger::jsclass = {
|
||||||
/* static */ Debugger*
|
/* static */ Debugger*
|
||||||
Debugger::fromThisValue(JSContext* cx, const CallArgs& args, const char* fnname)
|
Debugger::fromThisValue(JSContext* cx, const CallArgs& args, const char* fnname)
|
||||||
{
|
{
|
||||||
if (!args.thisv().isObject()) {
|
JSObject* thisobj = NonNullObject(cx, args.thisv());
|
||||||
ReportObjectRequired(cx);
|
if (!thisobj)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
JSObject* thisobj = &args.thisv().toObject();
|
|
||||||
if (thisobj->getClass() != &Debugger::jsclass) {
|
if (thisobj->getClass() != &Debugger::jsclass) {
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||||
"Debugger", fnname, thisobj->getClass()->name);
|
"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. */
|
/* Check that the arguments, if any, are cross-compartment wrappers. */
|
||||||
for (unsigned i = 0; i < args.length(); i++) {
|
for (unsigned i = 0; i < args.length(); i++) {
|
||||||
const Value& arg = args[i];
|
JSObject* argobj = NonNullObject(cx, args[i]);
|
||||||
if (!arg.isObject())
|
if (!argobj)
|
||||||
return ReportObjectRequired(cx);
|
return false;
|
||||||
JSObject* argobj = &arg.toObject();
|
|
||||||
if (!argobj->is<CrossCompartmentWrapperObject>()) {
|
if (!argobj->is<CrossCompartmentWrapperObject>()) {
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_DEBUG_CCW_REQUIRED,
|
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_DEBUG_CCW_REQUIRED,
|
||||||
"Debugger");
|
"Debugger");
|
||||||
|
@ -4565,11 +4554,9 @@ Debugger::wrapScript(JSContext* cx, HandleScript script)
|
||||||
static JSObject*
|
static JSObject*
|
||||||
DebuggerScript_check(JSContext* cx, const Value& v, const char* clsname, const char* fnname)
|
DebuggerScript_check(JSContext* cx, const Value& v, const char* clsname, const char* fnname)
|
||||||
{
|
{
|
||||||
if (!v.isObject()) {
|
JSObject* thisobj = NonNullObject(cx, v);
|
||||||
ReportObjectRequired(cx);
|
if (!thisobj)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
JSObject* thisobj = &v.toObject();
|
|
||||||
if (thisobj->getClass() != &DebuggerScript_class) {
|
if (thisobj->getClass() != &DebuggerScript_class) {
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||||
clsname, fnname, thisobj->getClass()->name);
|
clsname, fnname, thisobj->getClass()->name);
|
||||||
|
@ -5592,12 +5579,9 @@ DebuggerSource_construct(JSContext* cx, unsigned argc, Value* vp)
|
||||||
static NativeObject*
|
static NativeObject*
|
||||||
DebuggerSource_checkThis(JSContext* cx, const CallArgs& args, const char* fnname)
|
DebuggerSource_checkThis(JSContext* cx, const CallArgs& args, const char* fnname)
|
||||||
{
|
{
|
||||||
if (!args.thisv().isObject()) {
|
JSObject* thisobj = NonNullObject(cx, args.thisv());
|
||||||
ReportObjectRequired(cx);
|
if (!thisobj)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
JSObject* thisobj = &args.thisv().toObject();
|
|
||||||
if (thisobj->getClass() != &DebuggerSource_class) {
|
if (thisobj->getClass() != &DebuggerSource_class) {
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||||
"Debugger.Source", fnname, thisobj->getClass()->name);
|
"Debugger.Source", fnname, thisobj->getClass()->name);
|
||||||
|
@ -5890,11 +5874,9 @@ const Class DebuggerFrame_class = {
|
||||||
static NativeObject*
|
static NativeObject*
|
||||||
CheckThisFrame(JSContext* cx, const CallArgs& args, const char* fnname, bool checkLive)
|
CheckThisFrame(JSContext* cx, const CallArgs& args, const char* fnname, bool checkLive)
|
||||||
{
|
{
|
||||||
if (!args.thisv().isObject()) {
|
JSObject* thisobj = NonNullObject(cx, args.thisv());
|
||||||
ReportObjectRequired(cx);
|
if (!thisobj)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
JSObject* thisobj = &args.thisv().toObject();
|
|
||||||
if (thisobj->getClass() != &DebuggerFrame_class) {
|
if (thisobj->getClass() != &DebuggerFrame_class) {
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||||
"Debugger.Frame", fnname, thisobj->getClass()->name);
|
"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();
|
int32_t i = args.callee().as<JSFunction>().getExtendedSlot(0).toInt32();
|
||||||
|
|
||||||
/* Check that the this value is an Arguments object. */
|
/* Check that the this value is an Arguments object. */
|
||||||
if (!args.thisv().isObject()) {
|
RootedObject argsobj(cx, NonNullObject(cx, args.thisv()));
|
||||||
ReportObjectRequired(cx);
|
if (!argsobj)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
RootedObject argsobj(cx, &args.thisv().toObject());
|
|
||||||
if (argsobj->getClass() != &DebuggerArguments_class) {
|
if (argsobj->getClass() != &DebuggerArguments_class) {
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||||
"Arguments", "getArgument", argsobj->getClass()->name);
|
"Arguments", "getArgument", argsobj->getClass()->name);
|
||||||
|
@ -6660,11 +6640,9 @@ const Class DebuggerObject_class = {
|
||||||
static NativeObject*
|
static NativeObject*
|
||||||
DebuggerObject_checkThis(JSContext* cx, const CallArgs& args, const char* fnname)
|
DebuggerObject_checkThis(JSContext* cx, const CallArgs& args, const char* fnname)
|
||||||
{
|
{
|
||||||
if (!args.thisv().isObject()) {
|
JSObject* thisobj = NonNullObject(cx, args.thisv());
|
||||||
ReportObjectRequired(cx);
|
if (!thisobj)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
JSObject* thisobj = &args.thisv().toObject();
|
|
||||||
if (thisobj->getClass() != &DebuggerObject_class) {
|
if (thisobj->getClass() != &DebuggerObject_class) {
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||||
"Debugger.Object", fnname, thisobj->getClass()->name);
|
"Debugger.Object", fnname, thisobj->getClass()->name);
|
||||||
|
@ -7608,11 +7586,9 @@ static NativeObject*
|
||||||
DebuggerEnv_checkThis(JSContext* cx, const CallArgs& args, const char* fnname,
|
DebuggerEnv_checkThis(JSContext* cx, const CallArgs& args, const char* fnname,
|
||||||
bool requireDebuggee = true)
|
bool requireDebuggee = true)
|
||||||
{
|
{
|
||||||
if (!args.thisv().isObject()) {
|
JSObject* thisobj = NonNullObject(cx, args.thisv());
|
||||||
ReportObjectRequired(cx);
|
if (!thisobj)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
JSObject* thisobj = &args.thisv().toObject();
|
|
||||||
if (thisobj->getClass() != &DebuggerEnv_class) {
|
if (thisobj->getClass() != &DebuggerEnv_class) {
|
||||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO,
|
||||||
"Debugger.Environment", fnname, thisobj->getClass()->name);
|
"Debugger.Environment", fnname, thisobj->getClass()->name);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче