Bug 880041 (part 6) - Use JSObject::{is,as} for MapIteratorObject. r=sfink.

--HG--
extra : rebase_source : 32577e3ec9c0aebc94dfedd46e7af29d8475c927
This commit is contained in:
Nicholas Nethercote 2013-06-16 17:27:16 -07:00
parent a548ec558b
commit a388bcd855
2 changed files with 9 additions and 18 deletions

View File

@ -849,9 +849,11 @@ HashableValue::mark(JSTracer *trc) const
/*** MapIterator *********************************************************************************/
class js::MapIteratorObject : public JSObject
class MapIteratorObject : public JSObject
{
public:
static Class class_;
enum { TargetSlot, KindSlot, RangeSlot, SlotCount };
static const JSFunctionSpec methods[];
static MapIteratorObject *create(JSContext *cx, HandleObject mapobj, ValueMap *data,
@ -866,14 +868,7 @@ class js::MapIteratorObject : public JSObject
static JSBool next(JSContext *cx, unsigned argc, Value *vp);
};
inline js::MapIteratorObject &
JSObject::asMapIterator()
{
JS_ASSERT(isMapIterator());
return *static_cast<js::MapIteratorObject *>(this);
}
Class js::MapIteratorClass = {
Class MapIteratorObject::class_ = {
"Map Iterator",
JSCLASS_IMPLEMENTS_BARRIERS |
JSCLASS_HAS_RESERVED_SLOTS(MapIteratorObject::SlotCount),
@ -913,7 +908,7 @@ GlobalObject::initMapIteratorProto(JSContext *cx, Handle<GlobalObject *> global)
if (!base)
return false;
Rooted<JSObject*> proto(cx,
NewObjectWithGivenProto(cx, &MapIteratorClass, base, global));
NewObjectWithGivenProto(cx, &MapIteratorObject::class_, base, global));
if (!proto)
return false;
proto->setSlot(MapIteratorObject::RangeSlot, PrivateValue(NULL));
@ -936,7 +931,7 @@ MapIteratorObject::create(JSContext *cx, HandleObject mapobj, ValueMap *data,
if (!range)
return NULL;
JSObject *iterobj = NewObjectWithGivenProto(cx, &MapIteratorClass, proto, global);
JSObject *iterobj = NewObjectWithGivenProto(cx, &class_, proto, global);
if (!iterobj) {
js_delete(range);
return NULL;
@ -950,19 +945,19 @@ MapIteratorObject::create(JSContext *cx, HandleObject mapobj, ValueMap *data,
void
MapIteratorObject::finalize(FreeOp *fop, JSObject *obj)
{
fop->delete_(obj->asMapIterator().range());
fop->delete_(obj->as<MapIteratorObject>().range());
}
bool
MapIteratorObject::is(const Value &v)
{
return v.isObject() && v.toObject().hasClass(&MapIteratorClass);
return v.isObject() && v.toObject().hasClass(&class_);
}
bool
MapIteratorObject::next_impl(JSContext *cx, CallArgs args)
{
MapIteratorObject &thisobj = args.thisv().toObject().asMapIterator();
MapIteratorObject &thisobj = args.thisv().toObject().as<MapIteratorObject>();
ValueMap::Range *range = thisobj.range();
if (!range)
return js_ThrowStopIteration(cx);

View File

@ -212,7 +212,6 @@ extern Class ErrorClass;
extern Class GeneratorClass;
extern Class IntlClass;
extern Class JSONClass;
extern Class MapIteratorClass;
extern Class MathClass;
extern Class NumberClass;
extern Class ObjectClass;
@ -234,7 +233,6 @@ class DebugScopeObject;
class DeclEnvObject;
class GlobalObject;
class MapObject;
class MapIteratorObject;
class NestedScopeObject;
class NewObjectCache;
class NormalArgumentsObject;
@ -979,7 +977,6 @@ class JSObject : public js::ObjectImpl
inline bool isFunction() const { return hasClass(&js::FunctionClass); }
inline bool isGenerator() const { return hasClass(&js::GeneratorClass); }
inline bool isGlobal() const;
inline bool isMapIterator() const { return hasClass(&js::MapIteratorClass); }
inline bool isObject() const { return hasClass(&js::ObjectClass); }
inline bool isPrimitive() const { return isNumber() || isString() || isBoolean(); }
inline bool isPropertyIterator() const;
@ -1021,7 +1018,6 @@ class JSObject : public js::ObjectImpl
inline js::DebugScopeObject &asDebugScope();
inline js::GlobalObject &asGlobal();
inline js::MapObject &asMap();
inline js::MapIteratorObject &asMapIterator();
inline js::NestedScopeObject &asNestedScope();
inline js::NumberObject &asNumber();
inline js::PropertyIteratorObject &asPropertyIterator();