diff --git a/js/src/builtin/MapObject.cpp b/js/src/builtin/MapObject.cpp index d26a0f24b58..cd9194150ed 100644 --- a/js/src/builtin/MapObject.cpp +++ b/js/src/builtin/MapObject.cpp @@ -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(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 global) if (!base) return false; Rooted 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().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(); ValueMap::Range *range = thisobj.range(); if (!range) return js_ThrowStopIteration(cx); diff --git a/js/src/jsobj.h b/js/src/jsobj.h index 71d1aa2aa3b..321cdcee7e8 100644 --- a/js/src/jsobj.h +++ b/js/src/jsobj.h @@ -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();