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

--HG--
extra : rebase_source : 676539d76be0aee1c5450aacefed27a4f45efc81
This commit is contained in:
Nicholas Nethercote 2013-06-17 16:23:11 -07:00
parent 377234dc90
commit 79d447002d
34 changed files with 99 additions and 103 deletions

View File

@ -234,7 +234,7 @@ EvalKernel(JSContext *cx, const CallArgs &args, EvalType evalType, AbstractFrame
{
JS_ASSERT((evalType == INDIRECT_EVAL) == !caller);
JS_ASSERT((evalType == INDIRECT_EVAL) == !pc);
JS_ASSERT_IF(evalType == INDIRECT_EVAL, scopeobj->isGlobal());
JS_ASSERT_IF(evalType == INDIRECT_EVAL, scopeobj->is<GlobalObject>());
AssertInnerizedScopeChain(cx, *scopeobj);
Rooted<GlobalObject*> scopeObjGlobal(cx, &scopeobj->global());

View File

@ -706,7 +706,7 @@ InitCollatorClass(JSContext *cx, HandleObject Intl, Handle<GlobalObject*> global
if (!ctor)
return NULL;
RootedObject proto(cx, global->asGlobal().getOrCreateCollatorPrototype(cx));
RootedObject proto(cx, global->as<GlobalObject>().getOrCreateCollatorPrototype(cx));
if (!proto)
return NULL;
if (!LinkConstructorAndPrototype(cx, ctor, proto))
@ -1185,7 +1185,7 @@ InitNumberFormatClass(JSContext *cx, HandleObject Intl, Handle<GlobalObject*> gl
if (!ctor)
return NULL;
RootedObject proto(cx, global->asGlobal().getOrCreateNumberFormatPrototype(cx));
RootedObject proto(cx, global->as<GlobalObject>().getOrCreateNumberFormatPrototype(cx));
if (!proto)
return NULL;
if (!LinkConstructorAndPrototype(cx, ctor, proto))
@ -1634,7 +1634,7 @@ InitDateTimeFormatClass(JSContext *cx, HandleObject Intl, Handle<GlobalObject*>
if (!ctor)
return NULL;
RootedObject proto(cx, global->asGlobal().getOrCreateDateTimeFormatPrototype(cx));
RootedObject proto(cx, global->as<GlobalObject>().getOrCreateDateTimeFormatPrototype(cx));
if (!proto)
return NULL;
if (!LinkConstructorAndPrototype(cx, ctor, proto))
@ -2026,8 +2026,8 @@ static const JSFunctionSpec intl_static_methods[] = {
JSObject *
js_InitIntlClass(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isGlobal());
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
JS_ASSERT(obj->is<GlobalObject>());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
// The constructors above need to be able to determine whether they've been
// called with this being "the standard built-in Intl object". The global

View File

@ -1058,7 +1058,7 @@ InitClass(JSContext *cx, Handle<GlobalObject*> global, Class *clasp, JSProtoKey
JSObject *
MapObject::initClass(JSContext *cx, JSObject *obj)
{
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject proto(cx,
InitClass(cx, global, &class_, JSProto_Map, construct, properties, methods));
if (proto) {
@ -1594,7 +1594,7 @@ const JSFunctionSpec SetObject::methods[] = {
JSObject *
SetObject::initClass(JSContext *cx, JSObject *obj)
{
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject proto(cx,
InitClass(cx, global, &class_, JSProto_Set, construct, properties, methods));
if (proto) {

View File

@ -199,7 +199,7 @@ ParallelArrayObject::initClass(JSContext *cx, HandleObject obj)
}
}
Rooted<GlobalObject *> global(cx, &obj->asGlobal());
Rooted<GlobalObject *> global(cx, &obj->as<GlobalObject>());
RootedObject proto(cx, global->createBlankPrototype(cx, &protoClass));
if (!proto)

View File

@ -493,7 +493,7 @@ js_InitRegExpClass(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject proto(cx, global->createBlankPrototype(cx, &RegExpObject::class_));
if (!proto)

View File

@ -527,7 +527,7 @@ frontend::CompileFunctionBody(JSContext *cx, MutableHandleFunction fun, CompileO
*/
BytecodeEmitter funbce(/* parent = */ NULL, &parser, funbox, script,
/* insideEval = */ false, /* evalCaller = */ NullPtr(),
fun->environment() && fun->environment()->isGlobal(),
fun->environment() && fun->environment()->is<GlobalObject>(),
options.lineno);
if (!funbce.init())
return false;

View File

@ -1185,9 +1185,9 @@ Parser<ParseHandler>::newFunction(GenericParseContext *pc, HandleAtom atom,
/*
* Find the global compilation context in order to pre-set the newborn
* function's parent slot to pc->sc->asGlobal()->scopeChain. If the global
* context is a compile-and-go one, we leave the pre-set parent intact;
* otherwise we clear parent and proto.
* function's parent slot to pc->sc->as<GlobalObject>()->scopeChain. If the
* global context is a compile-and-go one, we leave the pre-set parent
* intact; otherwise we clear parent and proto.
*/
while (pc->parent)
pc = pc->parent;

View File

@ -4788,7 +4788,7 @@ static bool
TryAttachGlobalNameStub(JSContext *cx, HandleScript script, ICGetName_Fallback *stub,
HandleObject global, HandlePropertyName name)
{
JS_ASSERT(global->isGlobal());
JS_ASSERT(global->is<GlobalObject>());
RootedId id(cx, NameToId(name));
@ -4826,7 +4826,7 @@ TryAttachScopeNameStub(JSContext *cx, HandleScript script, ICGetName_Fallback *s
if (!shapes.append(scopeChain->lastProperty()))
return false;
if (scopeChain->isGlobal()) {
if (scopeChain->is<GlobalObject>()) {
shape = scopeChain->nativeLookup(cx, id);
if (shape)
break;

View File

@ -5976,11 +5976,11 @@ IonBuilder::pushTypeBarrier(MInstruction *ins, types::StackTypeSet *observed, bo
bool
IonBuilder::getStaticName(HandleObject staticObject, HandlePropertyName name, bool *psucceeded)
{
JS_ASSERT(staticObject->isGlobal() || staticObject->is<CallObject>());
JS_ASSERT(staticObject->is<GlobalObject>() || staticObject->is<CallObject>());
*psucceeded = true;
if (staticObject->isGlobal()) {
if (staticObject->is<GlobalObject>()) {
// Optimize undefined, NaN, and Infinity.
if (name == cx->names().undefined)
return pushConstant(UndefinedValue());
@ -6092,7 +6092,7 @@ IonBuilder::setStaticName(HandleObject staticObject, HandlePropertyName name)
{
RootedId id(cx, NameToId(name));
JS_ASSERT(staticObject->isGlobal() || staticObject->is<CallObject>());
JS_ASSERT(staticObject->is<GlobalObject>() || staticObject->is<CallObject>());
MDefinition *value = current->peek(-1);
@ -6136,7 +6136,7 @@ IonBuilder::setStaticName(HandleObject staticObject, HandlePropertyName name)
// Note: we do not use a post barrier when writing to the global object.
// Slots in the global object will be treated as roots during a minor GC.
if (!staticObject->isGlobal() && NeedsPostBarrier(info(), value))
if (!staticObject->is<GlobalObject>() && NeedsPostBarrier(info(), value))
current->add(MPostWriteBarrier::New(obj, value));
// If the property has a known type, we may be able to optimize typed stores by not
@ -8294,7 +8294,7 @@ IonBuilder::hasStaticScopeObject(ScopeCoordinate sc, MutableHandleObject pcall)
scope->setFoldedUnchecked();
JSObject *environment = script()->function()->environment();
while (environment && !environment->isGlobal()) {
while (environment && !environment->is<GlobalObject>()) {
if (environment->is<CallObject>() &&
!environment->as<CallObject>().isForEval() &&
environment->as<CallObject>().callee().nonLazyScript() == outerScript)

View File

@ -2715,7 +2715,7 @@ SetElementIC::reset()
bool
BindNameIC::attachGlobal(JSContext *cx, IonScript *ion, JSObject *scopeChain)
{
JS_ASSERT(scopeChain->isGlobal());
JS_ASSERT(scopeChain->is<GlobalObject>());
MacroAssembler masm(cx);
RepatchStubAppender attacher(*this);
@ -2745,7 +2745,7 @@ GenerateScopeChainGuard(MacroAssembler &masm, JSObject *scopeObj,
if (!script->funHasExtensibleScope)
return;
}
} else if (scopeObj->isGlobal()) {
} else if (scopeObj->is<GlobalObject>()) {
// If this is the last object on the scope walk, and the property we've
// found is not configurable, then we don't need a shape guard because
// the shape cannot be removed.
@ -2766,7 +2766,7 @@ GenerateScopeChainGuards(MacroAssembler &masm, JSObject *scopeChain, JSObject *h
// Walk up the scope chain. Note that IsCacheableScopeChain guarantees the
// |tobj == holder| condition terminates the loop.
while (true) {
JS_ASSERT(IsCacheableNonGlobalScope(tobj) || tobj->isGlobal());
JS_ASSERT(IsCacheableNonGlobalScope(tobj) || tobj->is<GlobalObject>());
GenerateScopeChainGuard(masm, tobj, outputReg, NULL, failures);
if (tobj == holder)
@ -2848,7 +2848,7 @@ BindNameIC::update(JSContext *cx, size_t cacheIndex, HandleObject scopeChain)
HandlePropertyName name = cache.name();
RootedObject holder(cx);
if (scopeChain->isGlobal()) {
if (scopeChain->is<GlobalObject>()) {
holder = scopeChain;
} else {
if (!LookupNameWithGlobalDefault(cx, name, scopeChain, &holder))
@ -2858,7 +2858,7 @@ BindNameIC::update(JSContext *cx, size_t cacheIndex, HandleObject scopeChain)
// Stop generating new stubs once we hit the stub count limit, see
// GetPropertyCache.
if (cache.canAttachStub()) {
if (scopeChain->isGlobal()) {
if (scopeChain->is<GlobalObject>()) {
if (!cache.attachGlobal(cx, ion, scopeChain))
return NULL;
} else if (IsCacheableScopeChain(scopeChain, holder)) {
@ -2918,7 +2918,7 @@ IsCacheableNameReadSlot(JSContext *cx, HandleObject scopeChain, HandleObject obj
if (obj != holder)
return false;
if (obj->isGlobal()) {
if (obj->is<GlobalObject>()) {
// Support only simple property lookups.
if (!IsCacheableGetPropReadSlot(obj, holder, shape) &&
!IsCacheableNoProperty(obj, holder, shape, pc, output))
@ -2933,11 +2933,11 @@ IsCacheableNameReadSlot(JSContext *cx, HandleObject scopeChain, HandleObject obj
RootedObject obj2(cx, scopeChain);
while (obj2) {
if (!IsCacheableNonGlobalScope(obj2) && !obj2->isGlobal())
if (!IsCacheableNonGlobalScope(obj2) && !obj2->is<GlobalObject>())
return false;
// Stop once we hit the global or target obj.
if (obj2->isGlobal() || obj2 == obj)
if (obj2->is<GlobalObject>() || obj2 == obj)
break;
obj2 = obj2->enclosingScope();
@ -2973,7 +2973,7 @@ IsCacheableNameCallGetter(JSObject *scopeChain, JSObject *obj, JSObject *holder,
if (obj != scopeChain)
return false;
if (!obj->isGlobal())
if (!obj->is<GlobalObject>())
return false;
return IsCacheableGetPropCallNative(obj, holder, shape) ||

View File

@ -2002,7 +2002,7 @@ JS_ResolveStandardClass(JSContext *cx, HandleObject obj, HandleId id, JSBool *re
* If this standard class is anonymous, then we don't want to resolve
* by name.
*/
JS_ASSERT(obj->isGlobal());
JS_ASSERT(obj->is<GlobalObject>());
if (stdnm->clasp->flags & JSCLASS_IS_ANONYMOUS)
return true;
@ -2119,7 +2119,7 @@ JS_GetGlobalForObject(JSContext *cx, JSObject *obj)
extern JS_PUBLIC_API(JSBool)
JS_IsGlobalObject(JSObject *obj)
{
return obj->isGlobal();
return obj->is<GlobalObject>();
}
JS_PUBLIC_API(JSObject *)
@ -4428,7 +4428,7 @@ JS_ClearNonGlobalObject(JSContext *cx, JSObject *objArg)
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj);
JS_ASSERT(!obj->isGlobal());
JS_ASSERT(!obj->is<GlobalObject>());
if (!obj->isNative())
return;
@ -4815,7 +4815,7 @@ JS_CloneFunctionObject(JSContext *cx, JSObject *funobjArg, JSObject *parentArg)
return NULL;
}
if (fun->isInterpreted() && (fun->nonLazyScript()->enclosingStaticScope() ||
(fun->nonLazyScript()->compileAndGo && !parent->isGlobal())))
(fun->nonLazyScript()->compileAndGo && !parent->is<GlobalObject>())))
{
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_CLONE_FUNOBJ_SCOPE);
return NULL;
@ -6667,7 +6667,7 @@ JS_NewRegExpObject(JSContext *cx, JSObject *objArg, char *bytes, size_t length,
if (!chars)
return NULL;
RegExpStatics *res = obj->asGlobal().getRegExpStatics();
RegExpStatics *res = obj->as<GlobalObject>().getRegExpStatics();
RegExpObject *reobj = RegExpObject::create(cx, res, chars, length,
RegExpFlag(flags), NULL);
js_free(chars);
@ -6680,7 +6680,7 @@ JS_NewUCRegExpObject(JSContext *cx, JSObject *objArg, jschar *chars, size_t leng
RootedObject obj(cx, objArg);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
RegExpStatics *res = obj->asGlobal().getRegExpStatics();
RegExpStatics *res = obj->as<GlobalObject>().getRegExpStatics();
return RegExpObject::create(cx, res, chars, length,
RegExpFlag(flags), NULL);
}
@ -6693,7 +6693,7 @@ JS_SetRegExpInput(JSContext *cx, JSObject *objArg, JSString *input, JSBool multi
CHECK_REQUEST(cx);
assertSameCompartment(cx, input);
obj->asGlobal().getRegExpStatics()->reset(cx, input, !!multiline);
obj->as<GlobalObject>().getRegExpStatics()->reset(cx, input, !!multiline);
}
JS_PUBLIC_API(void)
@ -6704,7 +6704,7 @@ JS_ClearRegExpStatics(JSContext *cx, JSObject *objArg)
CHECK_REQUEST(cx);
JS_ASSERT(obj);
obj->asGlobal().getRegExpStatics()->clear();
obj->as<GlobalObject>().getRegExpStatics()->clear();
}
JS_PUBLIC_API(JSBool)
@ -6716,7 +6716,7 @@ JS_ExecuteRegExp(JSContext *cx, JSObject *objArg, JSObject *reobjArg, jschar *ch
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
RegExpStatics *res = obj->asGlobal().getRegExpStatics();
RegExpStatics *res = obj->as<GlobalObject>().getRegExpStatics();
RootedValue val(cx);
if (!ExecuteRegExpLegacy(cx, res, reobj->as<RegExpObject>(), NullPtr(), chars, length, indexp,

View File

@ -2793,7 +2793,7 @@ js_InitArrayClass(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject proto(cx, global->getOrCreateObjectPrototype(cx));
if (!proto)

View File

@ -140,7 +140,7 @@ js_InitBooleanClass(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject booleanProto (cx, global->createBlankPrototype(cx, &BooleanObject::class_));
if (!booleanProto)

View File

@ -48,7 +48,7 @@ NewObjectCache::lookup(Class *clasp, gc::Cell *key, gc::AllocKind kind, EntryInd
inline bool
NewObjectCache::lookupProto(Class *clasp, JSObject *proto, gc::AllocKind kind, EntryIndex *pentry)
{
JS_ASSERT(!proto->isGlobal());
JS_ASSERT(!proto->is<GlobalObject>());
return lookup(clasp, proto, kind, pentry);
}

View File

@ -3138,7 +3138,7 @@ js_InitDateClass(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject dateProto(cx, global->createBlankPrototype(cx, &DateClass));
if (!dateProto)

View File

@ -830,10 +830,10 @@ InitErrorClass(JSContext *cx, Handle<GlobalObject*> global, int type, HandleObje
JSObject *
js_InitExceptionClasses(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isGlobal());
JS_ASSERT(obj->is<GlobalObject>());
JS_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject objectProto(cx, global->getOrCreateObjectPrototype(cx));
if (!objectProto)

View File

@ -1845,7 +1845,7 @@ GlobalObject::initIteratorClasses(JSContext *cx, Handle<GlobalObject *> global)
JSObject *
js_InitIteratorClasses(JSContext *cx, HandleObject obj)
{
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
if (!GlobalObject::initIteratorClasses(cx, global))
return NULL;
return global->getIteratorPrototype();

View File

@ -1127,7 +1127,7 @@ js_InitNumberClass(JSContext *cx, HandleObject obj)
/* XXX must do at least once per new thread, so do it per JSContext... */
FIX_FPU();
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject numberProto(cx, global->createBlankPrototype(cx, &NumberObject::class_));
if (!numberProto)

View File

@ -1282,7 +1282,7 @@ void
NewObjectCache::fillProto(EntryIndex entry, Class *clasp, js::TaggedProto proto,
gc::AllocKind kind, JSObject *obj)
{
JS_ASSERT_IF(proto.isObject(), !proto.toObject()->isGlobal());
JS_ASSERT_IF(proto.isObject(), !proto.toObject()->is<GlobalObject>());
JS_ASSERT(obj->getTaggedProto() == proto);
return fill(entry, clasp, proto.raw(), kind, obj);
}
@ -1304,7 +1304,8 @@ js::NewObjectWithGivenProto(JSContext *cx, js::Class *clasp,
if (proto.isObject() &&
newKind == GenericObject &&
!cx->compartment()->objectMetadataCallback &&
(!parent || parent == proto.toObject()->getParent()) && !proto.toObject()->isGlobal())
(!parent || parent == proto.toObject()->getParent()) &&
!proto.toObject()->is<GlobalObject>())
{
if (cache.lookupProto(clasp, proto.toObject(), allocKind, &entry)) {
JSObject *obj = cache.newObjectFromHit(cx, entry, GetInitialHeap(newKind, clasp));
@ -1361,12 +1362,12 @@ js::NewObjectWithClassProtoCommon(JSContext *cx, js::Class *clasp, JSObject *pro
NewObjectCache &cache = cx->runtime()->newObjectCache;
NewObjectCache::EntryIndex entry = -1;
if (parentArg->isGlobal() &&
if (parentArg->is<GlobalObject>() &&
protoKey != JSProto_Null &&
newKind == GenericObject &&
!cx->compartment()->objectMetadataCallback)
{
if (cache.lookupGlobal(clasp, &parentArg->asGlobal(), allocKind, &entry)) {
if (cache.lookupGlobal(clasp, &parentArg->as<GlobalObject>(), allocKind, &entry)) {
JSObject *obj = cache.newObjectFromHit(cx, entry, GetInitialHeap(newKind, clasp));
if (obj)
return obj;
@ -1388,7 +1389,7 @@ js::NewObjectWithClassProtoCommon(JSContext *cx, js::Class *clasp, JSObject *pro
return NULL;
if (entry != -1 && !obj->hasDynamicSlots())
cache.fillGlobal(entry, clasp, &parent->asGlobal(), allocKind, obj);
cache.fillGlobal(entry, clasp, &parent->as<GlobalObject>(), allocKind, obj);
return obj;
}
@ -2134,7 +2135,7 @@ DefineStandardSlot(JSContext *cx, HandleObject obj, JSProtoKey key, JSAtom *atom
* property is not yet present, force it into a new one bound to a
* reserved slot. Otherwise, go through the normal property path.
*/
JS_ASSERT(obj->isGlobal());
JS_ASSERT(obj->is<GlobalObject>());
JS_ASSERT(obj->isNative());
if (!obj->nativeLookup(cx, id)) {
@ -2158,7 +2159,7 @@ static void
SetClassObject(JSObject *obj, JSProtoKey key, JSObject *cobj, JSObject *proto)
{
JS_ASSERT(!obj->getParent());
if (!obj->isGlobal())
if (!obj->is<GlobalObject>())
return;
obj->setReservedSlot(key, ObjectOrNullValue(cobj));
@ -2169,7 +2170,7 @@ static void
ClearClassObject(JSObject *obj, JSProtoKey key)
{
JS_ASSERT(!obj->getParent());
if (!obj->isGlobal())
if (!obj->is<GlobalObject>())
return;
obj->setSlot(key, UndefinedValue());
@ -2228,7 +2229,9 @@ js::DefineConstructorAndPrototype(JSContext *cx, HandleObject obj, JSProtoKey ke
* of obj (the global object) is has a reserved slot indexed by key;
* and (c) key is not the null key.
*/
if (!(clasp->flags & JSCLASS_IS_ANONYMOUS) || !obj->isGlobal() || key == JSProto_Null) {
if (!(clasp->flags & JSCLASS_IS_ANONYMOUS) || !obj->is<GlobalObject>() ||
key == JSProto_Null)
{
uint32_t attrs = (clasp->flags & JSCLASS_IS_ANONYMOUS)
? JSPROP_READONLY | JSPROP_PERMANENT
: 0;
@ -2522,7 +2525,7 @@ JSObject::growSlots(JSContext *cx, HandleObject obj, uint32_t oldCount, uint32_t
Debug_SetSlotRangeToCrashOnTouch(obj->slots + oldCount, newCount - oldCount);
/* Changes in the slots of global objects can trigger recompilation. */
if (changed && obj->isGlobal())
if (changed && obj->is<GlobalObject>())
types::MarkObjectStateChange(cx, obj);
return true;
@ -2567,7 +2570,7 @@ JSObject::shrinkSlots(JSContext *cx, HandleObject obj, uint32_t oldCount, uint32
obj->slots = newslots;
/* Watch for changes in global object slots, as for growSlots. */
if (changed && obj->isGlobal())
if (changed && obj->is<GlobalObject>())
types::MarkObjectStateChange(cx, obj);
}
@ -2991,7 +2994,7 @@ bool
js_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, MutableHandleObject objp)
{
RootedObject global(cx, &obj->global());
if (!global->isGlobal()) {
if (!global->is<GlobalObject>()) {
objp.set(NULL);
return true;
}
@ -3756,7 +3759,7 @@ js::LookupNameWithGlobalDefault(JSContext *cx, HandlePropertyName name, HandleOb
RootedShape prop(cx);
RootedObject scope(cx, scopeChain);
for (; !scope->isGlobal(); scope = scope->enclosingScope()) {
for (; !scope->is<GlobalObject>(); scope = scope->enclosingScope()) {
if (!JSObject::lookupGeneric(cx, scope, id, &pobj, &prop))
return false;
if (prop)
@ -4298,7 +4301,7 @@ baseops::SetPropertyHelper(JSContext *cx, HandleObject obj, HandleObject receive
/* We should never add properties to lexical blocks. */
JS_ASSERT(!obj->is<BlockObject>());
if (obj->isGlobal() &&
if (obj->is<GlobalObject>() &&
(defineHow & DNP_UNQUALIFIED) &&
!MaybeReportUndeclaredVarAssignment(cx, JSID_TO_STRING(id)))
{
@ -4953,7 +4956,7 @@ js_GetObjectSlotName(JSTracer *trc, char *buf, size_t bufsize)
if (!shape) {
const char *slotname = NULL;
if (obj->isGlobal()) {
if (obj->is<GlobalObject>()) {
#define TEST_SLOT_MATCHES_PROTOTYPE(name,code,init) \
if ((code) == slot) { slotname = js_##name##_str; goto found; }
JS_FOR_EACH_PROTOTYPE(TEST_SLOT_MATCHES_PROTOTYPE)

View File

@ -896,8 +896,8 @@ class JSObject : public js::ObjectImpl
* specific types of objects may provide additional operations. To access,
* these addition operations, callers should use the pattern:
*
* if (obj.isX()) {
* XObject &x = obj.asX();
* if (obj.is<XObject>()) {
* XObject &x = obj.as<XObject>();
* x.foo();
* }
*
@ -913,7 +913,7 @@ class JSObject : public js::ObjectImpl
* [[Class]] property of object defined by the spec (for this, see
* js::ObjectClassIs).
*
* SpiderMonkey has not been completely switched to the isX/asX/XObject
* SpiderMonkey has not been completely switched to the is/as/XObject
* pattern so in some cases there is no XObject class and the engine
* instead pokes directly at reserved slots and getPrivate. In such cases,
* consider adding the missing XObject class.
@ -939,7 +939,6 @@ class JSObject : public js::ObjectImpl
inline bool isDate() const { return hasClass(&js::DateClass); }
inline bool isError() const { return hasClass(&js::ErrorClass); }
inline bool isFunction() const { return hasClass(&js::FunctionClass); }
inline bool isGlobal() const;
inline bool isObject() const { return hasClass(&js::ObjectClass); }
using js::ObjectImpl::isProxy;
inline bool isRegExpStatics() const { return hasClass(&js::RegExpStaticsClass); }
@ -950,8 +949,6 @@ class JSObject : public js::ObjectImpl
inline bool isFunctionProxy() const { return hasClass(&js::FunctionProxyClass); }
inline bool isCrossCompartmentWrapper() const;
inline js::GlobalObject &asGlobal();
static inline js::ThingRootKind rootKind() { return js::THING_ROOT_OBJECT; }
#ifdef DEBUG

View File

@ -281,7 +281,7 @@ JSObject::canRemoveLastProperty()
inline const js::HeapSlot *
JSObject::getRawSlots()
{
JS_ASSERT(isGlobal());
JS_ASSERT(is<js::GlobalObject>());
return slots;
}

View File

@ -890,7 +890,7 @@ static const JSFunctionSpec json_static_methods[] = {
JSObject *
js_InitJSONClass(JSContext *cx, HandleObject obj)
{
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
/*
* JSON requires that Boolean.prototype.valueOf be created and stashed in a

View File

@ -3592,7 +3592,7 @@ js_InitStringClass(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
Rooted<JSString*> empty(cx, cx->runtime()->emptyString);
RootedObject proto(cx, global->createBlankPrototype(cx, &StringObject::class_));

View File

@ -3814,7 +3814,7 @@ JSObject *
js_InitTypedArrayClasses(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
/* Idempotency required: we initialize several things, possibly lazily. */
RootedObject stop(cx);

View File

@ -418,7 +418,7 @@ js_InitWeakMapClass(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->asGlobal());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject weakMapProto(cx, global->createBlankPrototype(cx, &WeakMapObject::class_));
if (!weakMapProto)

View File

@ -1914,13 +1914,13 @@ Debugger::unwrapDebuggeeArgument(JSContext *cx, const Value &v)
return NULL;
/* If that didn't produce a global object, it's an error. */
if (!obj->isGlobal()) {
if (!obj->is<GlobalObject>()) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_UNEXPECTED_TYPE,
"argument", "not a global object");
return NULL;
}
return &obj->asGlobal();
return &obj->as<GlobalObject>();
}
JSBool
@ -4131,7 +4131,7 @@ js::EvaluateInEnv(JSContext *cx, Handle<Env*> env, HandleValue thisv, AbstractFr
return false;
script->isActiveEval = true;
ExecuteType type = !frame && env->isGlobal() ? EXECUTE_DEBUG_GLOBAL : EXECUTE_DEBUG;
ExecuteType type = !frame && env->is<GlobalObject>() ? EXECUTE_DEBUG_GLOBAL : EXECUTE_DEBUG;
return ExecuteKernel(cx, script, *env, thisv, type, frame, rval.address());
}
@ -4142,7 +4142,7 @@ DebuggerGenericEval(JSContext *cx, const char *fullMethodName,
{
/* Either we're specifying the frame, or a global. */
JS_ASSERT_IF(iter, !scope);
JS_ASSERT_IF(!iter, scope && scope->isGlobal());
JS_ASSERT_IF(!iter, scope && scope->is<GlobalObject>());
/* Check the first argument, the eval code string. */
if (!code.isString()) {
@ -4969,11 +4969,11 @@ DebuggerObject_makeDebuggeeValue(JSContext *cx, unsigned argc, Value *vp)
static bool
RequireGlobalObject(JSContext *cx, HandleValue dbgobj, HandleObject obj)
{
if (!obj->isGlobal()) {
if (!obj->is<GlobalObject>()) {
/* Help the poor programmer by pointing out wrappers around globals. */
if (obj->isWrapper()) {
JSObject *unwrapped = js::UncheckedUnwrap(obj);
if (unwrapped->isGlobal()) {
if (unwrapped->is<GlobalObject>()) {
js_ReportValueErrorFlags(cx, JSREPORT_ERROR, JSMSG_DEBUG_WRAPPER_IN_WAY,
JSDVG_SEARCH_STACK, dbgobj, NullPtr(),
"a global object", NULL);
@ -5411,7 +5411,7 @@ JS_DefineDebuggerObject(JSContext *cx, JSObject *obj_)
objectProto(cx),
envProto(cx);
objProto = obj->asGlobal().getOrCreateObjectPrototype(cx);
objProto = obj->as<GlobalObject>().getOrCreateObjectPrototype(cx);
if (!objProto)
return false;

View File

@ -33,7 +33,7 @@ js_InitObjectClass(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isNative());
return obj->asGlobal().getOrCreateObjectPrototype(cx);
return obj->as<GlobalObject>().getOrCreateObjectPrototype(cx);
}
JSObject *
@ -41,7 +41,7 @@ js_InitFunctionClass(JSContext *cx, HandleObject obj)
{
JS_ASSERT(obj->isNative());
return obj->asGlobal().getOrCreateFunctionPrototype(cx);
return obj->as<GlobalObject>().getOrCreateFunctionPrototype(cx);
}
static JSBool
@ -424,7 +424,7 @@ GlobalObject::create(JSContext *cx, Class *clasp)
if (!obj)
return NULL;
Rooted<GlobalObject *> global(cx, &obj->asGlobal());
Rooted<GlobalObject *> global(cx, &obj->as<GlobalObject>());
cx->compartment()->initGlobal(*global);

View File

@ -468,17 +468,11 @@ typedef HashSet<GlobalObject *, DefaultHasher<GlobalObject *>, SystemAllocPolicy
} // namespace js
template<>
inline bool
JSObject::isGlobal() const
JSObject::is<js::GlobalObject>() const
{
return !!(js::GetObjectClass(const_cast<JSObject*>(this))->flags & JSCLASS_IS_GLOBAL);
}
js::GlobalObject &
JSObject::asGlobal()
{
JS_ASSERT(isGlobal());
return *static_cast<js::GlobalObject *>(this);
}
#endif /* vm_GlobalObject_h */

View File

@ -59,7 +59,7 @@ ComputeImplicitThis(JSContext *cx, HandleObject obj, MutableHandleValue vp)
{
vp.setUndefined();
if (obj->isGlobal())
if (obj->is<GlobalObject>())
return true;
if (IsCacheableNonGlobalScope(obj))
@ -334,7 +334,7 @@ SetNameOperation(JSContext *cx, JSScript *script, jsbytecode *pc, HandleObject s
* undeclared global variable. To do this, we call SetPropertyHelper
* directly and pass DNP_UNQUALIFIED.
*/
if (scope->isGlobal()) {
if (scope->is<GlobalObject>()) {
JS_ASSERT(!scope->getOps()->setProperty);
RootedId id(cx, NameToId(name));
return baseops::SetPropertyHelper(cx, scope, scope, id, DNP_UNQUALIFIED, &valCopy, strict);
@ -354,7 +354,7 @@ DefVarOrConstOperation(JSContext *cx, HandleObject varobj, HandlePropertyName dn
return false;
/* Steps 8c, 8d. */
if (!prop || (obj2 != varobj && varobj->isGlobal())) {
if (!prop || (obj2 != varobj && varobj->is<GlobalObject>())) {
RootedValue value(cx, UndefinedValue());
if (!JSObject::defineProperty(cx, varobj, dn, value, JS_PropertyStub,
JS_StrictPropertyStub, attrs)) {

View File

@ -612,7 +612,7 @@ js::Execute(JSContext *cx, HandleScript script, JSObject &scopeChainArg, Value *
JSObject *s = scopeChain;
do {
assertSameCompartment(cx, s);
JS_ASSERT_IF(!s->enclosingScope(), s->isGlobal());
JS_ASSERT_IF(!s->enclosingScope(), s->is<GlobalObject>());
} while ((s = s->enclosingScope()));
#endif
@ -3346,7 +3346,7 @@ js::DefFunOperation(JSContext *cx, HandleScript script, HandleObject scopeChain,
/* Step 5e. */
JS_ASSERT(parent->isNative());
if (parent->isGlobal()) {
if (parent->is<GlobalObject>()) {
if (shape->configurable()) {
return JSObject::defineProperty(cx, parent, name, rval, JS_PropertyStub,
JS_StrictPropertyStub, attrs);

View File

@ -98,7 +98,7 @@ RegExpObjectBuilder::clone(Handle<RegExpObject *> other, Handle<RegExpObject *>
* the clone -- if the |RegExpStatics| provides more flags we'll
* need a different |RegExpShared|.
*/
RegExpStatics *res = proto->getParent()->asGlobal().getRegExpStatics();
RegExpStatics *res = proto->getParent()->as<GlobalObject>().getRegExpStatics();
RegExpFlag origFlags = other->getFlags();
RegExpFlag staticsFlags = res->getFlags();
if ((origFlags & staticsFlags) != staticsFlags) {

View File

@ -652,7 +652,7 @@ JSRuntime::initSelfHosting(JSContext *cx)
return false;
JS_SetGlobalObject(cx, selfHostingGlobal_);
JSAutoCompartment ac(cx, cx->global());
Rooted<GlobalObject*> shg(cx, &selfHostingGlobal_->asGlobal());
Rooted<GlobalObject*> shg(cx, &selfHostingGlobal_->as<GlobalObject>());
/*
* During initialization of standard classes for the self-hosting global,
* all self-hosted functions are ignored. Thus, we don't create cyclic

View File

@ -1373,7 +1373,7 @@ NewObjectCache::invalidateEntriesForShape(JSContext *cx, HandleShape shape, Hand
EntryIndex entry;
if (lookupGlobal(clasp, global, kind, &entry))
PodZero(&entries[entry]);
if (!proto->isGlobal() && lookupProto(clasp, proto, kind, &entry))
if (!proto->is<GlobalObject>() && lookupProto(clasp, proto, kind, &entry))
PodZero(&entries[entry]);
if (lookupType(clasp, type, kind, &entry))
PodZero(&entries[entry]);

View File

@ -352,10 +352,12 @@ StackFrame::epilogue(JSContext *cx)
* indirect eval frames scoped to an object carrying the introduced
* bindings.
*/
if (isDebuggerFrame())
JS_ASSERT(scopeChain()->isGlobal() || scopeChain()->enclosingScope()->isGlobal());
else
JS_ASSERT(scopeChain()->isGlobal());
if (isDebuggerFrame()) {
JS_ASSERT(scopeChain()->is<GlobalObject>() ||
scopeChain()->enclosingScope()->is<GlobalObject>());
} else {
JS_ASSERT(scopeChain()->is<GlobalObject>());
}
}
return;
}