Bug 914128 - Remove OBJECT_FLAG_EMULATES_UNDEFINED, rewrite code to check the clasp instead. r=bhackett

This commit is contained in:
Jan de Mooij 2013-09-27 10:02:55 +02:00
Родитель b9ac6c8dd3
Коммит 11faf30a5a
7 изменённых файлов: 48 добавлений и 46 удалений

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

@ -206,9 +206,7 @@ MaybeEmulatesUndefined(JSContext *cx, MDefinition *op)
if (!types)
return true;
if (!types->maybeObject())
return false;
return types->hasObjectFlags(cx, types::OBJECT_FLAG_EMULATES_UNDEFINED);
return types->maybeEmulatesUndefined();
}
static bool

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

@ -2747,14 +2747,6 @@ JS_NewObject(JSContext *cx, const JSClass *jsclasp, JSObject *protoArg, JSObject
JS_ASSERT(!(clasp->flags & JSCLASS_IS_GLOBAL));
JSObject *obj = NewObjectWithClassProto(cx, clasp, proto, parent);
if (obj) {
TypeObjectFlags flags = 0;
if (clasp->emulatesUndefined())
flags |= OBJECT_FLAG_EMULATES_UNDEFINED;
if (flags)
MarkTypeObjectFlags(cx, obj, flags);
}
JS_ASSERT_IF(obj, obj->getParent());
return obj;
}

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

@ -30,9 +30,7 @@ inline bool
EmulatesUndefined(JSObject *obj)
{
JSObject *actual = MOZ_LIKELY(!obj->is<WrapperObject>()) ? obj : UncheckedUnwrap(obj);
bool emulatesUndefined = actual->getClass()->emulatesUndefined();
MOZ_ASSERT_IF(emulatesUndefined, obj->type()->flags & types::OBJECT_FLAG_EMULATES_UNDEFINED);
return emulatesUndefined;
return actual->getClass()->emulatesUndefined();
}
} /* namespace js */

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

@ -1035,12 +1035,8 @@ TemporaryTypeSet::getKnownClass()
unsigned count = getObjectCount();
for (unsigned i = 0; i < count; i++) {
const Class *nclasp;
if (JSObject *object = getSingleObject(i))
nclasp = object->getClass();
else if (TypeObject *object = getTypeObject(i))
nclasp = object->clasp;
else
const Class *nclasp = getObjectClass(i);
if (!nclasp)
continue;
if (clasp && clasp != nclasp)
@ -1069,15 +1065,8 @@ TemporaryTypeSet::isDOMClass()
unsigned count = getObjectCount();
for (unsigned i = 0; i < count; i++) {
const Class *clasp;
if (JSObject *object = getSingleObject(i))
clasp = object->getClass();
else if (TypeObject *object = getTypeObject(i))
clasp = object->clasp;
else
continue;
if (!(clasp->flags & JSCLASS_IS_DOMJSCLASS))
const Class *clasp = getObjectClass(i);
if (clasp && !(clasp->flags & JSCLASS_IS_DOMJSCLASS))
return false;
}
@ -1095,15 +1084,30 @@ TemporaryTypeSet::maybeCallable()
unsigned count = getObjectCount();
for (unsigned i = 0; i < count; i++) {
const Class *clasp;
if (JSObject *object = getSingleObject(i))
clasp = object->getClass();
else if (TypeObject *object = getTypeObject(i))
clasp = object->clasp;
else
continue;
const Class *clasp = getObjectClass(i);
if (clasp && clasp->isCallable())
return true;
}
if (clasp->isCallable())
return false;
}
bool
TemporaryTypeSet::maybeEmulatesUndefined()
{
if (!maybeObject())
return false;
if (unknownObject())
return true;
unsigned count = getObjectCount();
for (unsigned i = 0; i < count; i++) {
// The object emulates undefined if clasp->emulatesUndefined() or if
// it's a WrapperObject, see EmulatesUndefined. Since all wrappers are
// proxies, we can just check for that.
const Class *clasp = getObjectClass(i);
if (clasp && (clasp->emulatesUndefined() || IsProxyClass(clasp)))
return true;
}
@ -2715,8 +2719,6 @@ TypeObject::print()
fprintf(stderr, " packed");
if (!hasAnyFlags(OBJECT_FLAG_LENGTH_OVERFLOW))
fprintf(stderr, " noLengthOverflow");
if (hasAnyFlags(OBJECT_FLAG_EMULATES_UNDEFINED))
fprintf(stderr, " emulatesUndefined");
if (hasAnyFlags(OBJECT_FLAG_ITERATED))
fprintf(stderr, " iterated");
if (interpretedFunction)
@ -3462,9 +3464,6 @@ JSObject::makeLazyType(JSContext *cx, HandleObject obj)
if (obj->lastProperty()->hasObjectFlag(BaseShape::ITERATED_SINGLETON))
type->flags |= OBJECT_FLAG_ITERATED;
if (obj->getClass()->emulatesUndefined())
type->flags |= OBJECT_FLAG_EMULATES_UNDEFINED;
/*
* Adjust flags for objects which will have the wrong flags set by just
* looking at the class prototype key.

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

@ -397,8 +397,9 @@ enum {
/* For a global object, whether flags were set on the RegExpStatics. */
OBJECT_FLAG_REGEXP_FLAGS_SET = 0x00200000,
/* Whether any objects emulate undefined; see EmulatesUndefined. */
OBJECT_FLAG_EMULATES_UNDEFINED = 0x00400000,
/*
* UNUSED FLAG = 0x00400000,
*/
/*
* For the function on a run-once script, whether the function has actually
@ -503,6 +504,9 @@ class TypeSet
inline TypeObject *getTypeObject(unsigned i) const;
inline bool getTypeOrSingleObject(JSContext *cx, unsigned i, TypeObject **obj) const;
/* The Class of an object in this set. */
inline const Class *getObjectClass(unsigned i) const;
void setOwnProperty(bool configurable) {
flags |= TYPE_FLAG_OWN_PROPERTY;
if (configurable)
@ -677,6 +681,9 @@ class TemporaryTypeSet : public TypeSet
/* Whether clasp->isCallable() is true for one or more objects in this set. */
bool maybeCallable();
/* Whether clasp->emulatesUndefined() is true for one or more objects in this set. */
bool maybeEmulatesUndefined();
/* Get the single value which can appear in this type set, otherwise NULL. */
JSObject *getSingleton();

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

@ -1417,6 +1417,16 @@ TypeSet::getTypeOrSingleObject(JSContext *cx, unsigned i, TypeObject **result) c
return true;
}
inline const Class *
TypeSet::getObjectClass(unsigned i) const
{
if (JSObject *object = getSingleObject(i))
return object->getClass();
if (TypeObject *object = getTypeObject(i))
return object->clasp;
return NULL;
}
/////////////////////////////////////////////////////////////////////
// TypeObject
/////////////////////////////////////////////////////////////////////

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

@ -363,8 +363,6 @@ inline void
JSObject::setType(js::types::TypeObject *newType)
{
JS_ASSERT(newType);
JS_ASSERT_IF(getClass()->emulatesUndefined(),
newType->hasAnyFlags(js::types::OBJECT_FLAG_EMULATES_UNDEFINED));
JS_ASSERT(!hasSingletonType());
type_ = newType;
}