Bug 1271653 - Global environment functions should assert that referent is global;r=jimb

This commit is contained in:
Eddy Bruel 2016-06-06 18:26:29 +02:00
Родитель e72edaf704
Коммит 817579cd0f
2 изменённых файлов: 29 добавлений и 16 удалений

Просмотреть файл

@ -8662,6 +8662,9 @@ DebuggerObject_forceLexicalInitializationByName(JSContext *cx, unsigned argc, Va
if (!args.requireAtLeast(cx, "Debugger.Object.prototype.forceLexicalInitializationByName", 1))
return false;
if (!DebuggerObject::requireGlobal(cx, object))
return false;
RootedId id(cx);
if (!ValueToIdentifier(cx, args[0], &id))
return false;
@ -8681,6 +8684,9 @@ DebuggerObject_executeInGlobal(JSContext* cx, unsigned argc, Value* vp)
if (!args.requireAtLeast(cx, "Debugger.Object.prototype.executeInGlobal", 1))
return false;
if (!DebuggerObject::requireGlobal(cx, object))
return false;
AutoStableStringChars stableChars(cx);
if (!ValueToStableChars(cx, "Debugger.Object.prototype.executeInGlobal", args[0],
stableChars))
@ -8703,6 +8709,9 @@ DebuggerObject_executeInGlobalWithBindings(JSContext* cx, unsigned argc, Value*
if (!args.requireAtLeast(cx, "Debugger.Object.prototype.executeInGlobalWithBindings", 2))
return false;
if (!DebuggerObject::requireGlobal(cx, object))
return false;
AutoStableStringChars stableChars(cx);
if (!ValueToStableChars(cx, "Debugger.Object.prototype.executeInGlobalWithBindings", args[0],
stableChars))
@ -8871,6 +8880,14 @@ DebuggerObject::isDebuggeeFunction(JSContext* cx, Handle<DebuggerObject*> object
dbg->observesGlobal(&referent->as<JSFunction>().global());
}
/* static */ bool
DebuggerObject::isGlobal(JSContext* cx, Handle<DebuggerObject*> object)
{
RootedObject referent(cx, object->referent());
return referent->is<GlobalObject>();
}
/* static */ bool
DebuggerObject::className(JSContext* cx, Handle<DebuggerObject*> object,
MutableHandleString result)
@ -9282,9 +9299,6 @@ DebuggerObject::call(JSContext* cx, Handle<DebuggerObject*> object, HandleValue
DebuggerObject::forceLexicalInitializationByName(JSContext* cx, Handle<DebuggerObject*> object,
HandleId id, bool& result)
{
if (!DebuggerObject::requireGlobalObject(cx, object))
return false;
if (!JSID_IS_STRING(id)) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
JSMSG_NOT_EXPECTED_TYPE, "Debugger.Object.prototype.forceLexicalInitializationByName",
@ -9292,11 +9306,11 @@ DebuggerObject::forceLexicalInitializationByName(JSContext* cx, Handle<DebuggerO
return false;
}
MOZ_ASSERT(isGlobal(cx, object));
RootedObject referent(cx, object->referent());
RootedObject globalLexical(cx, &referent->as<GlobalObject>().lexicalScope());
Rooted<GlobalObject*> referent(cx, &object->referent()->as<GlobalObject>());
RootedObject globalLexical(cx, &referent->lexicalScope());
RootedObject pobj(cx);
RootedShape shape(cx);
if (!LookupProperty(cx, globalLexical, id, &pobj, &shape))
@ -9319,14 +9333,12 @@ DebuggerObject::executeInGlobal(JSContext* cx, Handle<DebuggerObject*> object,
mozilla::Range<const char16_t> chars, HandleObject bindings,
const EvalOptions& options, MutableHandleValue result)
{
if (!DebuggerObject::requireGlobalObject(cx, object))
return false;
MOZ_ASSERT(isGlobal(cx, object));
RootedObject referent(cx, object->referent());
Rooted<GlobalObject*> referent(cx, &object->referent()->as<GlobalObject>());
Debugger* dbg = object->owner();
RootedObject globalLexical(cx, &referent->as<GlobalObject>().lexicalScope());
RootedObject globalLexical(cx, &referent->lexicalScope());
return DebuggerGenericEval(cx, chars, bindings, options, result, dbg, globalLexical,
nullptr);
}
@ -9407,11 +9419,11 @@ DebuggerObject::unwrap(JSContext* cx, Handle<DebuggerObject*> object,
}
/* static */ bool
DebuggerObject::requireGlobalObject(JSContext* cx, Handle<DebuggerObject*> object)
DebuggerObject::requireGlobal(JSContext* cx, Handle<DebuggerObject*> object)
{
RootedObject referent(cx, object->referent());
if (!DebuggerObject::isGlobal(cx, object)) {
RootedObject referent(cx, object->referent());
if (!referent->is<GlobalObject>()) {
const char* isWrapper = "";
const char* isWindowProxy = "";

Просмотреть файл

@ -1053,6 +1053,7 @@ class DebuggerObject : public NativeObject
static bool isFunction(JSContext* cx, Handle<DebuggerObject*> object);
static bool isDebuggeeFunction(JSContext* cx, Handle<DebuggerObject*> object);
static bool isGlobal(JSContext* cx, Handle<DebuggerObject*> object);
static bool className(JSContext* cx, Handle<DebuggerObject*> object,
MutableHandleString result);
static bool name(JSContext* cx, Handle<DebuggerObject*> object, MutableHandleString result);
@ -1101,6 +1102,8 @@ class DebuggerObject : public NativeObject
static bool unwrap(JSContext* cx, Handle<DebuggerObject*> object,
MutableHandle<DebuggerObject*> result);
static bool requireGlobal(JSContext* cx, Handle<DebuggerObject*> object);
private:
enum {
OWNER_SLOT
@ -1114,8 +1117,6 @@ class DebuggerObject : public NativeObject
#endif // SPIDERMONKEY_PROMISE
static const JSFunctionSpec methods_[];
static bool requireGlobalObject(JSContext* cx, Handle<DebuggerObject*> object);
JSObject* referent() const {
JSObject* obj = (JSObject*) getPrivate();
MOZ_ASSERT(obj);