예제 #1
0
파일: ObjectClass.cpp 프로젝트: bsdf/trx
 void ObjectClass::initPrototype()
 {
     // patch global.__proto__ = Object.prototype
     Toplevel* toplevel = this->toplevel();
     toplevel->global()->setDelegate(prototypePtr());                // global.__proto__ = Object.prototype
     this->setDelegate(toplevel->classClass()->prototypePtr());        // Object.__proto__ = Class.prototype
 }
예제 #2
0
    ClassClosure *SamplerScript::getType(Toplevel* ss_toplevel, SamplerObjectType sot, const void *ptr)
    {
        Toplevel* tl;

        switch (sotGetKind(sot))
        {
            case kSOT_String:
            {
                // toplevel can be null here if there was no CodeContext active
                // when the sample was taken (ie, string was allocated from C++ code).
                // in that case, use the TL from the SamplerScript itself... it isn't
                // technically the right one to use, but is adequate for our purposes here
                // (it will return a stringClass or namespaceClass that will be valid
                // for the sampler)
                tl = sotGetToplevel(sot);
                if (!tl) tl = ss_toplevel;
                return tl->stringClass();
            }
            case kSOT_Namespace:
            {
                tl = sotGetToplevel(sot);
                if (!tl) tl = ss_toplevel;
                return tl->namespaceClass();
            }
            default:
                AvmAssert(0);
            case kSOT_Object:
                break;
        }

        VTable* vt = sotGetVTable(sot);
        tl = vt->toplevel();
        AvmCore* core = tl->core();

        ClassClosure *type;
        ScriptObject* obj = (ScriptObject*)ptr;
        if (obj && AvmCore::istype(obj->atom(), core->traits.class_itraits))
        {
            type = tl->classClass();
        }
        else if (obj && AvmCore::istype(obj->atom(), core->traits.function_itraits))
        {
            type = tl->functionClass();
        }
        else if (obj && obj->traits()->isActivationTraits())
        {
            type = tl->objectClass;
        }
        else
        {
            // fallback answer
            type = tl->objectClass;

            // note that note all types will have an init method,
            // so those types may get reported as "objectClass" rather
            // than something more specific. However, it's not clear
            // that the Sampler ever really cared about reporting those
            // objects well in the first place (eg activation or catch objects),
            // so it doesn't seem we're a lot worse off than before.
            ScopeChain* sc = NULL;
            if (vt->init)
                sc = vt->init->scope();

            if (sc && sc->getSize() <= 1)
            {
                if(sc->getSize() == 1)
                    type = tl->classClass();
            }
            else if (sc)
            {
                Atom ccAtom = sc->getScope(sc->getSize()-1);
                if(AvmCore::isObject(ccAtom))
                {
                    type = (ClassClosure*) AvmCore::atomToScriptObject(ccAtom);
                    if(!AvmCore::istype(type->atom(), core->traits.class_itraits))
                    {
                        // obj is a ClassClosure
                        type = tl->classClass();
                    }
                }
            }
        }
        AvmAssert(AvmCore::istype(type->atom(), core->traits.class_itraits));
        return type;
    }