/*static*/ ClassClosure* FASTCALL ClassClosure::createClassClosure(VTable* cvtable) { ClassClosure* cc = new (cvtable->gc(), MMgc::kExact, cvtable->getExtraSize()) ClassClosure(cvtable, calcCreateInstanceProc(cvtable)); AvmAssert(cc->prototypePtr() == NULL); cc->createVanillaPrototype(); return cc; }
EventObject* ProgressEventObject::Clone(EventObject*pObj) { if (NULL == pObj) { ClassClosure *pClass = toplevel()->getBuiltinExtensionClass(abcclass_flash_events_ProgressEvent); pObj = (EventObject *)pClass->createInstance(pClass->ivtable(), pClass->prototype); } register ProgressEventObject *pEvent = (ProgressEventObject *)pObj; pEvent->m_bytesLoaded = m_bytesLoaded; pEvent->m_bytesToal = m_bytesToal; return EventObject::Clone(pObj); }
EventObject* FocusEventObject::Clone(EventObject*pObj) { if (NULL == pObj) { ClassClosure *pClass = toplevel()->getBuiltinExtensionClass(abcclass_flash_events_FocusEvent); pObj = (EventObject *)pClass->createInstance(pClass->ivtable(), pClass->prototype); } register FocusEventObject *pEvent = (FocusEventObject *)pObj; pEvent->m_pRelatedObject = m_pRelatedObject; pEvent->m_shiftKey = m_shiftKey; pEvent->m_keyCode = m_keyCode; return EventObject::Clone(pObj); }
/** * Object.prototype.toString() */ Stringp ObjectClass::_toString(Atom thisAtom) { AvmCore* core = this->core(); if (core->istype(thisAtom, CLASS_TYPE)) { ClassClosure *cc = (ClassClosure *)AvmCore::atomToScriptObject(thisAtom); Traits* t = cc->ivtable()->traits; Stringp s = core->concatStrings(core->newString("[class "), t->name); return core->concatStrings(s, core->newString("]")); } else { Traits* t = toplevel()->toTraits(thisAtom); Stringp s = core->concatStrings(core->newString("[object "), t->name); return core->concatStrings(s, core->newString("]")); } }
EventObject* KeyboardEventObject::Clone(EventObject*pObj) { if (NULL == pObj) { ClassClosure *pClass = toplevel()->getBuiltinExtensionClass(abcclass_flash_events_KeyboardEvent); pObj = (EventObject *)pClass->createInstance(pClass->ivtable(), pClass->prototype); } register KeyboardEventObject *pEvent = (KeyboardEventObject *)pObj; pEvent->m_charCode = m_charCode; pEvent->m_keyCode = m_keyCode; pEvent->m_keyLocation = m_keyLocation; pEvent->m_ctrlKey = m_ctrlKey; pEvent->m_altKey = m_altKey; pEvent->m_shiftKey = m_shiftKey; return EventObject::Clone(pObj); }
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; }