Atom VectorClass::applyTypeArgs(int argc, Atom* argv) { Toplevel* toplevel = this->toplevel(); //Vector only takes 1 type argument AvmAssert(argc==1); if (argc != 1) { toplevel->typeErrorClass()->throwError(kWrongTypeArgCountError, traits()->formatClassName(), core()->toErrorString(1), core()->toErrorString(argc)); } Atom const typeAtom = argv[0]; ClassClosure* parameterizedType; if (ISNULL(typeAtom)) { parameterizedType = toplevel->objectVectorClass; } else { if (atomKind(typeAtom) != kObjectType) toplevel->throwVerifyError(kCorruptABCError); ScriptObject* typeObj = AvmCore::atomToScriptObject(typeAtom); if (typeObj == toplevel->intClass) { parameterizedType = toplevel->intVectorClass; } else if (typeObj == toplevel->uintClass) { parameterizedType = toplevel->uintVectorClass; } else if (typeObj == toplevel->numberClass) { parameterizedType = toplevel->doubleVectorClass; } else { // if we have an object, we must have an itraits (otherwise the typearg is not a Class) Traits* typeTraits = typeObj->vtable->traits->itraits; if (!typeTraits) toplevel->throwVerifyError(kCorruptABCError); ClassClosure* typeClass = (ClassClosure*)typeObj; Domain* typeDomain = typeObj->traits()->pool->domain; if ((parameterizedType = typeDomain->getParameterizedType(typeClass)) == NULL) { Stringp fullname = VectorClass::makeVectorClassName(core(), typeTraits); VTable* vt = this->vtable->newParameterizedVTable(typeTraits, fullname); ObjectVectorClass* parameterizedVector = new (vt->gc(), vt->getExtraSize()) ObjectVectorClass(vt); parameterizedVector->index_type = typeClass; parameterizedVector->setDelegate(toplevel->classClass->prototypePtr()); // Is this right? Should each instantiation get its own prototype? parameterizedVector->setPrototypePtr(toplevel->objectVectorClass->prototypePtr()); typeDomain->addParameterizedType(typeClass, parameterizedVector); parameterizedType = parameterizedVector; } } } return parameterizedType->atom(); }
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; }