Projects
Essentials
lightspark
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 105
View file
lightspark.spec
Changed
@@ -20,7 +20,7 @@ %bcond_without librtmp Name: lightspark -Version: 0.7.2.99+git20160410.1631 +Version: 0.7.2.99+git20160417.1917 Release: 0 Summary: Modern, free, open-source flash player implementation License: LGPL-3.0+
View file
0002-Fix-build-with-newer-LLVM.patch
Changed
@@ -57,7 +57,7 @@ - llvm::Function::ArgumentListType::iterator it=llvmf->getArgumentList().begin(); //The first and only argument to this function is the call_context* - llvm::Value* context=it; -+ llvm::Value* context = (llvm::Value*)llvmf->getArgumentList().begin(); ++ llvm::Value* context = llvmf->getArgumentList().begin(); //let's give access to local data storage value=Builder.CreateStructGEP(
View file
lightspark.tar.xz/src/asobject.cpp
Changed
@@ -42,13 +42,13 @@ if(this->is<Class_base>()) { ret = "[class "; - ret+=this->as<Class_base>()->class_name.getQualifiedName().raw_buf(); + ret+=this->as<Class_base>()->class_name.getQualifiedName(getSystemState()).raw_buf(); ret+="]"; } else if(getClass()) { ret="[object "; - ret+=getClass()->class_name.name.raw_buf(); + ret+=getClass()->class_name.getQualifiedName(getSystemState()).raw_buf(); ret+="]"; } else if(this->is<Undefined>()) @@ -122,7 +122,7 @@ case T_UINTEGER: return as<UInteger>()->toString(); case T_STRING: - return as<ASString>()->data; + return as<ASString>()->getData(); default: //everything else is an Object regarding to the spec return toPrimitive(STRING_HINT)->toString(); @@ -892,7 +892,7 @@ obj = type->coerce(obj); } else if(mainObj->is<Class_base>() && - mainObj->as<Class_base>()->class_name.getQualifiedName() == typemname->qualifiedString(mainObj->getSystemState())) + mainObj->as<Class_base>()->class_name.getQualifiedName(mainObj->getSystemState()) == typemname->qualifiedString(mainObj->getSystemState())) { // avoid recursive construction //obj = mainObj->getSystemState()->getNullRef(); @@ -951,13 +951,13 @@ if (obj->is<Class_base>()) { ret="[object "; - ret+=static_cast<Class_base*>(obj)->class_name.name; + ret+=obj->getSystemState()->getStringFromUniqueId(static_cast<Class_base*>(obj)->class_name.nameId); ret+="]"; } else if(obj->getClass()) { ret="[object "; - ret+=obj->getClass()->class_name.name; + ret+=obj->getSystemState()->getStringFromUniqueId(obj->getClass()->class_name.nameId); ret+="]"; } else
View file
lightspark.tar.xz/src/backends/extscriptobject.cpp
Changed
@@ -314,7 +314,7 @@ { conv.str(""); conv << ids[i]->getInt(); - if(asobj->hasPropertyByMultiname(QName(conv.str(),""),true,true)) + if(asobj->hasPropertyByMultiname(QName(getSys()->getUniqueStringId(conv.str()),BUILTIN_STRINGS::EMPTY),true,true)) { LOG(LOG_NOT_IMPLEMENTED,"ExtVariant::getASObject: duplicate property " << conv.str()); continue;
View file
lightspark.tar.xz/src/scripting/abc.cpp
Changed
@@ -130,9 +130,16 @@ using namespace lightspark; DEFINE_AND_INITIALIZE_TLS(is_vm_thread); +#ifndef NDEBUG +bool inStartupOrClose=true; +#endif bool lightspark::isVmThread() { +#ifndef NDEBUG + return inStartupOrClose || GPOINTER_TO_INT(tls_get(&is_vm_thread)); +#else return GPOINTER_TO_INT(tls_get(&is_vm_thread)); +#endif } DoABCTag::DoABCTag(RECORDHEADER h, std::istream& in):ControlTag(h) @@ -720,9 +727,9 @@ ret=m->cached; if(midx==0) { - ret->name_s_id=root->getSystemState()->getUniqueStringId("any"); + ret->name_s_id=BUILTIN_STRINGS::ANY; ret->name_type=multiname::NAME_STRING; - ret->ns.emplace_back(root->getSystemState(),"",NAMESPACE); + ret->ns.emplace_back(root->getSystemState(),BUILTIN_STRINGS::EMPTY,NAMESPACE); ret->isAttribute=false; return ret; } @@ -735,7 +742,7 @@ ret->ns.emplace_back(this, m->ns); if (m->name) { - ret->name_s_id=root->getSystemState()->getUniqueStringId(getString(m->name)); + ret->name_s_id=getString(m->name); ret->name_type=multiname::NAME_STRING; } break; @@ -753,7 +760,7 @@ if (m->name) { - ret->name_s_id=root->getSystemState()->getUniqueStringId(getString(m->name)); + ret->name_s_id=getString(m->name); ret->name_type=multiname::NAME_STRING; } break; @@ -774,7 +781,7 @@ case 0x10: //RTQNameA { ret->name_type=multiname::NAME_STRING; - ret->name_s_id=root->getSystemState()->getUniqueStringId(getString(m->name)); + ret->name_s_id=getString(m->name); break; } case 0x11: //RTQNameL @@ -788,7 +795,7 @@ multiname_info* td=&constant_pool.multinames[m->type_definition]; //builds a name by concating the templateName$TypeName1$TypeName2... //this naming scheme is defined by the ABC compiler - tiny_string name = getString(td->name); + tiny_string name = root->getSystemState()->getStringFromUniqueId(getString(td->name)); for(size_t i=0;i<m->param_types.size();++i) { multiname_info* p=&constant_pool.multinames[m->param_types[i]]; @@ -799,11 +806,11 @@ // TODO there's no documentation about how to handle derived classes // We just prepend the namespace to the template class, so we can find it when needed namespace_info nsi = constant_pool.namespaces[p->ns]; - nsname = getString(nsi.name); + nsname = root->getSystemState()->getStringFromUniqueId(getString(nsi.name)); if (nsname != "") name += nsname+"$"; } - name += getString(p->name); + name += root->getSystemState()->getStringFromUniqueId(getString(p->name)); } ret->ns.emplace_back(this, td->ns); ret->name_s_id=root->getSystemState()->getUniqueStringId(name); @@ -928,7 +935,7 @@ if(instances[i].isInterface()) LOG(LOG_CALLS,_("\tInterface")); if(instances[i].isProtectedNs()) - LOG(LOG_CALLS,_("\tProtectedNS ") << getString(constant_pool.namespaces[instances[i].protectedNs].name)); + LOG(LOG_CALLS,_("\tProtectedNS ") << root->getSystemState()->getStringFromUniqueId(getString(constant_pool.namespaces[instances[i].protectedNs].name))); if(instances[i].supername) LOG(LOG_CALLS,_("Super ") << *getMultiname(instances[i].supername,NULL)); if(instances[i].interface_count) @@ -1581,7 +1588,9 @@ /* set TLS variable for isVmThread() */ tls_set(&is_vm_thread, GINT_TO_POINTER(1)); - +#ifndef NDEBUG + inStartupOrClose= false; +#endif if(th->m_sys->useJit) { #ifdef LLVM_31 @@ -1733,6 +1742,9 @@ th->ex->clearAllGlobalMappings(); delete th->module; } +#ifndef NDEBUG + inStartupOrClose= true; +#endif } /* This breaks the lock on all enqueued events to prevent deadlocking */ @@ -1765,7 +1777,7 @@ //invoked on the client object multiname headerName(NULL); headerName.name_type=multiname::NAME_STRING; - headerName.ns.emplace_back(m_sys,"",NAMESPACE); + headerName.ns.emplace_back(m_sys,BUILTIN_STRINGS::EMPTY,NAMESPACE); tiny_string headerNameString; if(!message->readUTF(headerNameString)) return; @@ -1832,7 +1844,7 @@ multiname onResultName(NULL); onResultName.name_type=multiname::NAME_STRING; onResultName.name_s_id=m_sys->getUniqueStringId("onResult"); - onResultName.ns.emplace_back(m_sys,"",NAMESPACE); + onResultName.ns.emplace_back(m_sys,BUILTIN_STRINGS::EMPTY,NAMESPACE); _NR<ASObject> callback = responder->getVariableByMultiname(onResultName); if(!callback.isNull() && callback->getObjectType() == T_FUNCTION) { @@ -1861,10 +1873,10 @@ tiny_string ABCVm::getDefaultXMLNamespace() { - return currentCallContext->defaultNamespaceUri == NULL ? tiny_string() : currentCallContext->defaultNamespaceUri->data; + return m_sys->getStringFromUniqueId(currentCallContext->defaultNamespaceUri); } -const tiny_string& ABCContext::getString(unsigned int s) const +uint32_t ABCContext::getString(unsigned int s) const { return constant_pool.strings[s]; } @@ -1995,7 +2007,7 @@ case 0x08: //Namespace { assert_and_throw(constant_pool.namespaces[index].name); - Namespace* ret = Class<Namespace>::getInstanceS(root->getSystemState(),getString(constant_pool.namespaces[index].name)); + Namespace* ret = Class<Namespace>::getInstanceS(root->getSystemState(),root->getSystemState()->getStringFromUniqueId(getString(constant_pool.namespaces[index].name))); if (constant_pool.namespaces[index].kind != 0) ret->nskind =(NS_KIND)(int)(constant_pool.namespaces[index].kind); return ret; @@ -2044,9 +2056,9 @@ for(unsigned int i=0;i<t->metadata_count;i++) { metadata_info& minfo = metadata[t->metadata[i]]; - LOG(LOG_CALLS,"Metadata: " << getString(minfo.name)); + LOG(LOG_CALLS,"Metadata: " << root->getSystemState()->getStringFromUniqueId(getString(minfo.name))); for(unsigned int j=0;j<minfo.item_count;++j) - LOG(LOG_CALLS," : " << getString(minfo.items[j].key) << " " << getString(minfo.items[j].value)); + LOG(LOG_CALLS," : " << root->getSystemState()->getStringFromUniqueId(getString(minfo.items[j].key)) << " " << root->getSystemState()->getStringFromUniqueId(getString(minfo.items[j].value))); } } @@ -2061,13 +2073,12 @@ return; ASObject* ret; - QName className(obj->getSystemState()->getStringFromUniqueId(mname->name_s_id),mname->ns[0].getImpl(obj->getSystemState()).name); + QName className(mname->name_s_id,mname->ns[0].getImpl(obj->getSystemState()).nameId); //check if this class has the 'interface' flag, i.e. it is an interface if((instances[t->classi].flags)&0x04) { - MemoryAccount* memoryAccount = obj->getSystemState()->allocateMemoryAccount(className.name); - Class_inherit* ci=new (obj->getSystemState()->unaccountedMemory) Class_inherit(className, memoryAccount); + Class_inherit* ci=new (obj->getSystemState()->unaccountedMemory) Class_inherit(className, obj->getSystemState()->unaccountedMemory); ci->isInterface = true; ci->setDeclaredMethodByQName("toString",AS3,Class<IFunction>::getFunction(obj->getSystemState(),Class_base::_toString),NORMAL_METHOD,false); LOG(LOG_CALLS,_("Building class traits")); @@ -2121,8 +2132,7 @@ } else { - MemoryAccount* memoryAccount = obj->getSystemState()->allocateMemoryAccount(className.name); - Class_inherit* c=new (obj->getSystemState()->unaccountedMemory) Class_inherit(className, memoryAccount); + Class_inherit* c=new (obj->getSystemState()->unaccountedMemory) Class_inherit(className, obj->getSystemState()->unaccountedMemory); c->context = this; if(instances[t->classi].supername)
View file
lightspark.tar.xz/src/scripting/abc.h
Changed
@@ -165,7 +165,7 @@ _R<RootMovieClip> root; method_info* get_method(unsigned int m); - const tiny_string& getString(unsigned int s) const; + uint32_t getString(unsigned int s) const; //Qname getQname(unsigned int m, call_context* th=NULL) const; static multiname* s_getMultiname(ABCContext*, ASObject* rt1, ASObject* rt2, int m); static multiname* s_getMultiname_i(call_context*, uint32_t i , int m);
View file
lightspark.tar.xz/src/scripting/abc_codesynt.cpp
Changed
@@ -1858,7 +1858,7 @@ return f; string method_name="method"; - method_name+=context->getString(info.name).raw_buf(); + method_name+=sys->getStringFromUniqueId(context->getString(info.name)).raw_buf(); if(!body) { LOG(LOG_CALLS,_("Method ") << method_name << _(" should be intrinsic"));;
View file
lightspark.tar.xz/src/scripting/abc_fast_interpreter.cpp
Changed
@@ -1587,8 +1587,15 @@ //index of the scope stack uint32_t t=data->uints[0]; LOG(LOG_CALLS, "getScopeAtIndex " << t); - assert(t<context->scope_stack.size()); - ASObject* obj=context->scope_stack[t].object.getPtr(); + ASObject* obj; + uint32_t parentsize = context->parent_scope_stack.isNull() ? 0 :context->parent_scope_stack->scope.size(); + if (!context->parent_scope_stack.isNull() && t<parentsize) + obj = context->parent_scope_stack->scope[t].object.getPtr(); + else + { + assert_and_throw(t-parentsize <context->scope_stack.size()); + obj=context->scope_stack[t-parentsize].object.getPtr(); + } obj->incRef(); context->runtime_stack_push(obj); instructionPointer+=4;
View file
lightspark.tar.xz/src/scripting/abc_opcodes.cpp
Changed
@@ -414,7 +414,7 @@ } if (obj->is<Class_base>()) { - tiny_string clsname = obj->as<Class_base>()->class_name.getQualifiedName(); + tiny_string clsname = obj->as<Class_base>()->class_name.getQualifiedName(th->context->root->getSystemState()); obj->decRef(); throwError<TypeError>(kCallNotFoundError, name->qualifiedString(th->context->root->getSystemState()), clsname); } @@ -501,6 +501,7 @@ { ASObject* t=th->runtime_stack_pop(); LOG(LOG_CALLS, _("pushWith ") << t ); + t->incRef(); th->scope_stack.emplace_back(scope_entry(_MR(t), true)); } @@ -508,13 +509,20 @@ { ASObject* t=th->runtime_stack_pop(); LOG(LOG_CALLS, _("pushScope ") << t ); + t->incRef(); th->scope_stack.emplace_back(scope_entry(_MR(t), false)); } Global* ABCVm::getGlobalScope(call_context* th) { - assert_and_throw(th->scope_stack.size() > 0); - ASObject* ret=th->scope_stack[0].object.getPtr(); + ASObject* ret; + if (!th->parent_scope_stack.isNull() && th->parent_scope_stack->scope.size() > 0) + ret =th->parent_scope_stack->scope[0].object.getPtr(); + else + { + assert_and_throw(th->scope_stack.size() > 0); + ret =th->scope_stack[0].object.getPtr(); + } assert_and_throw(ret->is<Global>()); LOG(LOG_CALLS,_("getGlobalScope: ") << ret); ret->incRef(); @@ -813,12 +821,19 @@ // Register the type name in the global scope. The type name // is later used by the coerce opcode. - _R<ASObject> global = th->scope_stack[0].object; + ASObject* global; + if (!th->parent_scope_stack.isNull() && th->parent_scope_stack->scope.size() > 0) + global =th->parent_scope_stack->scope[0].object.getPtr(); + else + { + assert_and_throw(th->scope_stack.size() > 0); + global =th->scope_stack[0].object.getPtr(); + } QName qname = o_class->class_name; if (!global->hasPropertyByMultiname(qname, false, false)) { o_class->incRef(); - global->setVariableByQName(qname.name,nsNameAndKind(global->getSystemState(),qname.ns,NAMESPACE),o_class,DECLARED_TRAIT); + global->setVariableByQName(global->getSystemState()->getStringFromUniqueId(qname.nameId),nsNameAndKind(global->getSystemState(),qname.nsStringId,NAMESPACE),o_class,DECLARED_TRAIT); } for(int i=0;i<m;++i) @@ -1403,14 +1418,14 @@ assert_and_throw(th->context->getMultinameRTData(n)==0); multiname* name=th->context->getMultiname(n,NULL); LOG(LOG_CALLS, "getLex: " << *name ); - vector<scope_entry>::reverse_iterator it=th->scope_stack.rbegin(); + vector<scope_entry>::reverse_iterator it; // o will be a reference owned by this function (or NULL). At // the end the reference will be handed over to the runtime // stack. ASObject* o = NULL; //Find out the current 'this', when looking up over it, we have to consider all of it - for(;it!=th->scope_stack.rend();++it) + for(it=th->scope_stack.rbegin();it!=th->scope_stack.rend();++it) { // XML_STRICT flag tells getVariableByMultiname to // ignore non-existing properties in XML obejcts @@ -1429,6 +1444,28 @@ break; } } + if(o==NULL && !th->parent_scope_stack.isNull()) // check parent scope stack + { + for(it=th->parent_scope_stack->scope.rbegin();it!=th->parent_scope_stack->scope.rend();++it) + { + // XML_STRICT flag tells getVariableByMultiname to + // ignore non-existing properties in XML obejcts + // (normally it would return an empty XMLList if the + // property does not exist). + ASObject::GET_VARIABLE_OPTION opt=ASObject::XML_STRICT; + if(!it->considerDynamic) + opt=(ASObject::GET_VARIABLE_OPTION)(opt | ASObject::SKIP_IMPL); + + checkDeclaredTraits(it->object.getPtr()); + _NR<ASObject> prop=it->object->getVariableByMultiname(*name, opt); + if(!prop.isNull()) + { + prop->incRef(); + o=prop.getPtr(); + break; + } + } + } if(o==NULL) { @@ -1473,10 +1510,10 @@ { LOG(LOG_CALLS, _("findProperty ") << *name ); - vector<scope_entry>::reverse_iterator it=th->scope_stack.rbegin(); + vector<scope_entry>::reverse_iterator it; bool found=false; ASObject* ret=NULL; - for(;it!=th->scope_stack.rend();++it) + for(it =th->scope_stack.rbegin();it!=th->scope_stack.rend();++it) { found=it->object->hasPropertyByMultiname(*name, it->considerDynamic, true); @@ -1487,6 +1524,20 @@ break; } } + if(!found && !th->parent_scope_stack.isNull()) // check parent scope stack + { + for(it=th->parent_scope_stack->scope.rbegin();it!=th->parent_scope_stack->scope.rend();++it) + { + found=it->object->hasPropertyByMultiname(*name, it->considerDynamic, true); + + if(found) + { + //We have to return the object, not the property + ret=it->object.getPtr(); + break; + } + } + } if(!found) { //try to find a global object where this is defined @@ -1495,7 +1546,15 @@ if(o) ret=target; else //else push the current global object - ret=th->scope_stack[0].object.getPtr(); + { + if (!th->parent_scope_stack.isNull() && th->parent_scope_stack->scope.size() > 0) + ret =th->parent_scope_stack->scope[0].object.getPtr(); + else + { + assert_and_throw(th->scope_stack.size() > 0); + ret =th->scope_stack[0].object.getPtr(); + } + } } //TODO: make this a regular assert @@ -1508,11 +1567,11 @@ { LOG(LOG_CALLS, "findPropStrict " << *name ); - vector<scope_entry>::reverse_iterator it=th->scope_stack.rbegin(); + vector<scope_entry>::reverse_iterator it; bool found=false; ASObject* ret=NULL; - for(;it!=th->scope_stack.rend();++it) + for(it =th->scope_stack.rbegin();it!=th->scope_stack.rend();++it) { found=it->object->hasPropertyByMultiname(*name, it->considerDynamic, true); if(found) @@ -1522,6 +1581,19 @@ break; } } + if(!found && !th->parent_scope_stack.isNull()) // check parent scope stack + { + for(it =th->parent_scope_stack->scope.rbegin();it!=th->parent_scope_stack->scope.rend();++it) + { + found=it->object->hasPropertyByMultiname(*name, it->considerDynamic, true); + if(found) + { + //We have to return the object, not the property + ret=it->object.getPtr(); + break; + } + } + } if(!found) { ASObject* target; @@ -2008,7 +2080,7 @@ tiny_string ns_uri = ""; if (name->ns.size() > 0) { - ns_uri = name->ns[0].getImpl(th->context->root->getSystemState()).name; + ns_uri = th->context->root->getSystemState()->getStringFromUniqueId(name->ns[0].getImpl(th->context->root->getSystemState()).nameId); if (ns_uri.empty() && name->ns.size() == 1) ns_uri="*"; } @@ -2020,7 +2092,7 @@ tiny_string ns_uri = ""; if (name->ns.size() > 0) { - ns_uri = name->ns[0].getImpl(th->context->root->getSystemState()).name; + ns_uri = th->context->root->getSystemState()->getStringFromUniqueId(name->ns[0].getImpl(th->context->root->getSystemState()).nameId); if (ns_uri.empty() && name->ns.size() == 1) ns_uri="*"; } @@ -2167,7 +2239,7 @@ ASObject* baseClass=th->runtime_stack_pop(); assert_and_throw(mname->ns.size()==1); - QName className(th->context->root->getSystemState()->getStringFromUniqueId(mname->name_s_id),mname->ns[0].getImpl(th->context->root->getSystemState()).name); + QName className(mname->name_s_id,mname->ns[0].getImpl(th->context->root->getSystemState()).nameId); Class_inherit* ret = NULL; auto i = th->context->root->applicationDomain->classesBeingDefined.cbegin(); @@ -2200,8 +2272,7 @@ return; } - MemoryAccount* memoryAccount = th->context->root->applicationDomain->getSystemState()->allocateMemoryAccount(className.name); - ret=new (th->context->root->applicationDomain->getSystemState()->unaccountedMemory) Class_inherit(className, memoryAccount); + ret=new (th->context->root->getSystemState()->unaccountedMemory) Class_inherit(className, th->context->root->getSystemState()->unaccountedMemory); LOG(LOG_CALLS,"add classes defined:"<<*mname<<" "<<th->context); //Add the class to the ones being currently defined in this context @@ -2252,7 +2323,10 @@ ret->setDeclaredMethodByQName("toString",AS3,Class<IFunction>::getFunction(ret->getSystemState(),Class_base::_toString),NORMAL_METHOD,false); - ret->class_scope=th->scope_stack; + if (!th->parent_scope_stack.isNull()) + ret->class_scope = th->parent_scope_stack->scope; + for (auto it = th->scope_stack.begin(); it != th->scope_stack.end(); it++) + ret->class_scope.push_back(*it); LOG(LOG_CALLS,_("Building class traits")); for(unsigned int i=0;i<th->context->classes[n].trait_count;i++) @@ -2340,7 +2414,11 @@ method_info* m=&th->context->methods[th->context->classes[n].cinit]; SyntheticFunction* cinit=Class<IFunction>::getSyntheticFunction(ret->getSystemState(),m); //cinit must inherit the current scope - cinit->acquireScope(th->scope_stack); + if (!th->parent_scope_stack.isNull()) + cinit->acquireScope(th->parent_scope_stack->scope); + for (auto it = th->scope_stack.begin(); it != th->scope_stack.end(); it++) + cinit->addToScope(*it); + ASObject* ret2=NULL; try { @@ -2504,8 +2582,12 @@ method_info* m=&th->context->methods[n]; SyntheticFunction* f=Class<IFunction>::getSyntheticFunction(th->context->root->applicationDomain->getSystemState(),m); - f->func_scope=th->scope_stack; - + f->func_scope = _R<scope_entry_list>(new scope_entry_list()); + if (!th->parent_scope_stack.isNull()) + f->func_scope->scope=th->parent_scope_stack->scope; + for (auto it = th->scope_stack.begin(); it != th->scope_stack.end(); it++) + f->addToScope(*it); + //Bind the function to null, as this is not a class method f->bind(NullRef,-1); //Create the prototype object @@ -2515,7 +2597,8 @@ ASObject* ABCVm::getScopeObject(call_context* th, int n) { - ASObject* ret=th->scope_stack[n+th->initialScopeStack].object.getPtr(); + assert_and_throw(th->scope_stack.size() > (size_t)n); + ASObject* ret=th->scope_stack[(size_t)n].object.getPtr(); ret->incRef(); LOG(LOG_CALLS, _("getScopeObject: ") << ret ); return ret; @@ -2523,9 +2606,8 @@ ASObject* ABCVm::pushString(call_context* th, int n) { - const tiny_string s=th->context->getString(n); - LOG(LOG_CALLS, _("pushString ") << s ); - return abstract_s(th->context->root->applicationDomain->getSystemState(),s); + LOG(LOG_CALLS, _("pushString ") << th->context->root->getSystemState()->getStringFromUniqueId(th->context->getString(n)) ); + return abstract_s(th->context->root->applicationDomain->getSystemState(),th->context->getString(n)); } ASObject* ABCVm::newCatch(call_context* th, int n) @@ -2616,8 +2698,8 @@ { const namespace_info& ns_info=th->context->constant_pool.namespaces[n]; assert(ns_info.kind == NAMESPACE); - LOG(LOG_CALLS, _("pushNamespace ") << th->context->getString(ns_info.name) ); - return Class<Namespace>::getInstanceS(th->context->root->getSystemState(),th->context->getString(ns_info.name)); + LOG(LOG_CALLS, _("pushNamespace ") << th->context->root->getSystemState()->getStringFromUniqueId(th->context->getString(ns_info.name)) ); + return Class<Namespace>::getInstanceS(th->context->root->getSystemState(),th->context->root->getSystemState()->getStringFromUniqueId(th->context->getString(ns_info.name))); } /* @spec-checked avm2overview */ @@ -2626,7 +2708,7 @@ if(!th->mi->hasDXNS()) throw Class<VerifyError>::getInstanceS(th->context->root->getSystemState(),"dxns without SET_DXNS"); - th->defaultNamespaceUri = _NR<ASString>(abstract_s(th->context->root->applicationDomain->getSystemState(),th->context->getString(n))); + th->defaultNamespaceUri = th->context->getString(n); } /* @spec-checked avm2overview */ @@ -2635,6 +2717,6 @@ if(!th->mi->hasDXNS()) throw Class<VerifyError>::getInstanceS(th->context->root->getSystemState(),"dxnslate without SET_DXNS"); - th->defaultNamespaceUri = _NR<ASString>(abstract_s(th->context->root->applicationDomain->getSystemState(),o->toString())); + th->defaultNamespaceUri = th->context->root->getSystemState()->getUniqueStringId(o->toString()); o->decRef(); }
View file
lightspark.tar.xz/src/scripting/abc_optimizer.cpp
Changed
@@ -134,7 +134,7 @@ const std::vector<InferenceData>& scopeStack, const multiname* name, InferenceData& inferredData) { //We try to find out the position on the scope stack where the name is found - uint32_t totalScopeStackLen = f->func_scope.size() + scopeStack.size(); + uint32_t totalScopeStackLen = f->func_scope->scope.size() + scopeStack.size(); bool found=false; //Traverse in reverse order the scope stack. Stops at the first any/unknown type. @@ -170,7 +170,7 @@ //TODO: We can also push directly those objects since they are fixed std::cerr << "End of local stack" << std::endl; //Now look in the objects that are stored in the function save scope stack - for(auto it=f->func_scope.rbegin();it!=f->func_scope.rend();++it) + for(auto it=f->func_scope->scope.rbegin();it!=f->func_scope->scope.rend();++it) { totalScopeStackLen--; if(it->considerDynamic) @@ -334,6 +334,8 @@ void ABCVm::optimizeFunction(SyntheticFunction* function) { method_info* mi=function->mi; + SystemState* sys = function->getSystemState(); + ActivationType activationType(mi); istringstream code(mi->body->code); @@ -701,7 +703,7 @@ case 0x20: { //pushnull - ASObject* ret=function->getSystemState()->getNullRef(); + ASObject* ret=sys->getNullRef(); //We don't really need a reference to it ret->decRef(); curBlock->pushStack(InferenceData(ret)); @@ -730,7 +732,7 @@ code.read((char*)&t,1); out << (uint8_t)opcode; out << t; - curBlock->pushStack(Class<Integer>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Integer>::getClass(sys)); break; } case 0x25: @@ -742,21 +744,21 @@ code >> t; out << (uint8_t)opcode; writeInt32(out, t); - curBlock->pushStack(Class<Integer>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Integer>::getClass(sys)); break; } case 0x26: { //pushtrue out << (uint8_t)opcode; - curBlock->pushStack(Class<Boolean>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Boolean>::getClass(sys)); break; } case 0x27: { //pushfalse out << (uint8_t)opcode; - curBlock->pushStack(Class<Boolean>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Boolean>::getClass(sys)); break; } case 0x28: @@ -811,7 +813,7 @@ s32 val=mi->context->constant_pool.integer[t]; out << (uint8_t)opcode; writeInt32(out, val); - curBlock->pushStack(Class<Integer>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Integer>::getClass(sys)); break; } case 0x2e: @@ -822,7 +824,7 @@ u32 val=mi->context->constant_pool.uinteger[t]; out << (uint8_t)opcode; writeInt32(out, val); - curBlock->pushStack(Class<Integer>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Integer>::getClass(sys)); break; } case 0x2f: @@ -833,7 +835,7 @@ double val=mi->context->constant_pool.doubles[t]; out << (uint8_t)opcode; writeDouble(out, val); - curBlock->pushStack(Class<Number>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Number>::getClass(sys)); break; } case 0x30: @@ -864,7 +866,7 @@ out << (uint8_t)opcode; writeInt32(out,t); writeInt32(out,t2); - curBlock->pushStack(Class<Boolean>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Boolean>::getClass(sys)); break; } //Alchemy opcodes @@ -877,7 +879,7 @@ //li32 out << (uint8_t)opcode; curBlock->popStack(1); - curBlock->pushStack(Class<Integer>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Integer>::getClass(sys)); break; } case 0x3a: @@ -1256,7 +1258,7 @@ int numRT=mi->context->getMultinameRTData(t); curBlock->popStack(numRT+1); - curBlock->pushStack(Class<Boolean>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Boolean>::getClass(sys)); break; } case 0x6c: @@ -1320,7 +1322,7 @@ out << (uint8_t)opcode; curBlock->popStack(1); - curBlock->pushStack(Class<ASString>::getClass(function->getSystemState())); + curBlock->pushStack(Class<ASString>::getClass(sys)); break; } case 0x73: @@ -1329,7 +1331,7 @@ out << (uint8_t)opcode; curBlock->popStack(1); - curBlock->pushStack(Class<Integer>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Integer>::getClass(sys)); break; } case 0x74: @@ -1338,7 +1340,7 @@ out << (uint8_t)opcode; curBlock->popStack(1); - curBlock->pushStack(Class<UInteger>::getClass(function->getSystemState())); + curBlock->pushStack(Class<UInteger>::getClass(sys)); break; } case 0x75: @@ -1347,7 +1349,7 @@ out << (uint8_t)opcode; curBlock->popStack(1); - curBlock->pushStack(Class<Number>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Number>::getClass(sys)); break; } case 0x76: @@ -1356,7 +1358,7 @@ out << (uint8_t)opcode; curBlock->popStack(1); - curBlock->pushStack(Class<Boolean>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Boolean>::getClass(sys)); break; } case 0x78: @@ -1449,7 +1451,7 @@ //decrement out << (uint8_t)opcode; curBlock->popStack(1); - curBlock->pushStack(Class<Number>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Number>::getClass(sys)); break; } case 0x92: @@ -1468,7 +1470,7 @@ //not out << (uint8_t)opcode; curBlock->popStack(1); - curBlock->pushStack(Class<Boolean>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Boolean>::getClass(sys)); break; } case 0x97: @@ -1482,7 +1484,7 @@ //negate_i out << (uint8_t)opcode; curBlock->popStack(1); - curBlock->pushStack(Class<Integer>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Integer>::getClass(sys)); break; } case 0xa0: @@ -1505,7 +1507,7 @@ //modulo out << (uint8_t)opcode; curBlock->popStack(2); - curBlock->pushStack(Class<Number>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Number>::getClass(sys)); break; } case 0xa5: @@ -1529,7 +1531,7 @@ //multiply_i out << (uint8_t)opcode; curBlock->popStack(2); - curBlock->pushStack(Class<Integer>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Integer>::getClass(sys)); break; } case 0xab: @@ -1553,7 +1555,7 @@ //in out << (uint8_t)opcode; curBlock->popStack(2); - curBlock->pushStack(Class<Boolean>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Boolean>::getClass(sys)); break; } case 0xb2: @@ -1568,7 +1570,7 @@ if(numRT) throw ParseException("Bad code in optimizer"); curBlock->popStack(1); - curBlock->pushStack(Class<Boolean>::getClass(function->getSystemState())); + curBlock->pushStack(Class<Boolean>::getClass(sys)); break; } case 0xc2:
View file
lightspark.tar.xz/src/scripting/abctypes.cpp
Changed
@@ -18,6 +18,7 @@ **************************************************************************/ #include "scripting/abctypes.h" +#include "swf.h" using namespace std; using namespace lightspark; @@ -113,7 +114,7 @@ { u30 size; in >> size; - v.val=tiny_string(in,size); + v.val = getSys()->getUniqueStringId(tiny_string(in,size)); return in; }
View file
lightspark.tar.xz/src/scripting/abctypes.h
Changed
@@ -96,9 +96,9 @@ { friend std::istream& operator>>(std::istream& in, string_info& v); private: - tiny_string val; + uint32_t val; public: - operator const tiny_string&() const{return val;} + operator uint32_t() const{return val;} }; struct namespace_info
View file
lightspark.tar.xz/src/scripting/abcutils.h
Changed
@@ -39,7 +39,11 @@ { } }; - +class scope_entry_list: public RefCountable +{ +public: + std::vector<scope_entry> scope; +}; struct call_context { #include "packed_begin.h" @@ -55,6 +59,7 @@ uint32_t locals_size; uint32_t max_stack; int32_t argarrayposition; // position of argument array in locals ( -1 if no argument array needed) + _NR<scope_entry_list> parent_scope_stack; std::vector<scope_entry> scope_stack; method_info* mi; /* This is the function's inClass that is currently executing. It is used @@ -64,8 +69,7 @@ /* Current namespace set by 'default xml namespace = ...'. * Defaults to empty string according to ECMA-357 13.1.1.1 */ - _NR<ASString> defaultNamespaceUri; - int initialScopeStack; + uint32_t defaultNamespaceUri; ~call_context(); static void handleError(int errorcode); inline void runtime_stack_clear()
View file
lightspark.tar.xz/src/scripting/class.cpp
Changed
@@ -221,9 +221,8 @@ if(*retAddr==NULL) { //Create the class - QName name(ClassName<ASObject>::name,ClassName<ASObject>::ns); - MemoryAccount* memoryAccount = s->allocateMemoryAccount(name.name); - ret=new (s->unaccountedMemory) Class<ASObject>(name, memoryAccount); + QName name(s->getUniqueStringId(ClassName<ASObject>::name),s->getUniqueStringId(ClassName<ASObject>::ns)); + ret=new (s->unaccountedMemory) Class<ASObject>(name, s->unaccountedMemory); ret->setSystemState(s); ret->incRef(); *retAddr=ret;
View file
lightspark.tar.xz/src/scripting/class.h
Changed
@@ -177,9 +177,8 @@ if(*retAddr==NULL) { //Create the class - QName name(ClassName<T>::name,ClassName<T>::ns); - MemoryAccount* memoryAccount = sys->allocateMemoryAccount(name.name); - ret=new (sys->unaccountedMemory) Class<T>(name, memoryAccount); + QName name(sys->getUniqueStringId(ClassName<T>::name),sys->getUniqueStringId(ClassName<T>::ns)); + ret=new (sys->unaccountedMemory) Class<T>(name, sys->unaccountedMemory); ret->setSystemState(sys); ret->incRef(); *retAddr=ret; @@ -345,9 +344,8 @@ if(*retAddr==NULL) { //Create the class - QName name(ClassName<T>::name,ClassName<T>::ns); - MemoryAccount* memoryAccount = sys->allocateMemoryAccount(name.name); - ret=new (sys->unaccountedMemory) InterfaceClass<T>(name, memoryAccount); + QName name(sys->getUniqueStringId(ClassName<T>::name),sys->getUniqueStringId(ClassName<T>::ns)); + ret=new (sys->unaccountedMemory) InterfaceClass<T>(name, sys->unaccountedMemory); ret->isInterface = true; ret->incRef(); *retAddr=ret; @@ -450,34 +448,34 @@ public: Template(QName name) : Template_base(name) {}; - QName getQName(const std::vector<const Type*>& types) + QName getQName(SystemState* sys, const std::vector<const Type*>& types) { //This is the naming scheme that the ABC compiler uses, //and we need to stay in sync here - QName ret(ClassName<T>::name, ClassName<T>::ns); + tiny_string name = ClassName<T>::name; for(size_t i=0;i<types.size();++i) { - ret.name += "$"; - ret.name += types[i]->getName(); + name += "$"; + name += types[i]->getName(); } + QName ret(sys->getUniqueStringId(name),sys->getUniqueStringId(ClassName<T>::ns)); return ret; } Class_base* applyType(const std::vector<const Type*>& types,_NR<ApplicationDomain> applicationDomain) { - QName instantiatedQName = getQName(types); _NR<ApplicationDomain> appdomain = applicationDomain; // if type is a builtin class, it is handled in the systemDomain if (appdomain.isNull() || (types.size() > 0 && !dynamic_cast<const Class_inherit*>(types[0]))) appdomain = getSys()->systemDomain; + QName instantiatedQName = getQName(appdomain->getSystemState(),types); std::map<QName, Class_base*>::iterator it=appdomain->instantiatedTemplates.find(instantiatedQName); Class<T>* ret=NULL; if(it==appdomain->instantiatedTemplates.end()) //This class is not yet in the map, create it { - MemoryAccount* memoryAccount = appdomain->getSystemState()->allocateMemoryAccount(instantiatedQName.name); - ret=new (appdomain->getSystemState()->unaccountedMemory) TemplatedClass<T>(instantiatedQName,types,this,memoryAccount); + ret=new (appdomain->getSystemState()->unaccountedMemory) TemplatedClass<T>(instantiatedQName,types,this,appdomain->getSystemState()->unaccountedMemory); appdomain->instantiatedTemplates.insert(std::make_pair(instantiatedQName,ret)); ret->prototype = _MNR(new_objectPrototype(appdomain->getSystemState())); T::sinit(ret); @@ -504,8 +502,7 @@ Class<T>* ret=NULL; if(it==appdomain->instantiatedTemplates.end()) //This class is not yet in the map, create it { - MemoryAccount* memoryAccount = appdomain->getSystemState()->allocateMemoryAccount(qname.name); - ret=new (appdomain->getSystemState()->unaccountedMemory) TemplatedClass<T>(qname,types,this,memoryAccount); + ret=new (appdomain->getSystemState()->unaccountedMemory) TemplatedClass<T>(qname,types,this,appdomain->getSystemState()->unaccountedMemory); appdomain->instantiatedTemplates.insert(std::make_pair(qname,ret)); ret->prototype = _MNR(new_objectPrototype(appdomain->getSystemState())); T::sinit(ret); @@ -560,7 +557,7 @@ static Template<T>* getTemplate(SystemState* sys) { - return getTemplate(sys,QName(ClassName<T>::name,ClassName<T>::ns)); + return getTemplate(sys,QName(sys->getUniqueStringId(ClassName<T>::name),sys->getUniqueStringId(ClassName<T>::ns))); } };
View file
lightspark.tar.xz/src/scripting/flash/utils/ByteArray.cpp
Changed
@@ -508,7 +508,7 @@ assert_and_throw(args[0]->getObjectType()==T_STRING); ASString* str=Class<ASString>::cast(args[0]); th->lock(); - th->writeUTF(str->data); + th->writeUTF(str->getData()); th->unlock(); return NULL; } @@ -521,9 +521,9 @@ assert_and_throw(args[0]->getObjectType()==T_STRING); ASString* str=Class<ASString>::cast(args[0]); th->lock(); - th->getBuffer(th->position+str->data.numBytes(),true); - memcpy(th->bytes+th->position,str->data.raw_buf(),str->data.numBytes()); - th->position+=str->data.numBytes(); + th->getBuffer(th->position+str->getData().numBytes(),true); + memcpy(th->bytes+th->position,str->getData().raw_buf(),str->getData().numBytes()); + th->position+=str->getData().numBytes(); th->unlock(); return NULL;
View file
lightspark.tar.xz/src/scripting/flash/xml/flashxml.cpp
Changed
@@ -353,7 +353,7 @@ XMLDocument* th=Class<XMLDocument>::cast(obj); assert_and_throw(argslen==1 && args[0]->getObjectType()==T_STRING); ASString* str=Class<ASString>::cast(args[0]); - th->parseXMLImpl(str->data); + th->parseXMLImpl(str->getData()); return NULL; }
View file
lightspark.tar.xz/src/scripting/toplevel/ASString.cpp
Changed
@@ -29,27 +29,27 @@ using namespace std; using namespace lightspark; -ASString::ASString(Class_base* c):ASObject(c) +ASString::ASString(Class_base* c):ASObject(c),hasId(true),datafilled(true),stringId(BUILTIN_STRINGS::EMPTY) { type=T_STRING; } -ASString::ASString(Class_base* c,const string& s) : ASObject(c),data(s) +ASString::ASString(Class_base* c,const string& s) : ASObject(c),data(s),hasId(false),datafilled(true),stringId(BUILTIN_STRINGS::EMPTY) { type=T_STRING; } -ASString::ASString(Class_base* c,const tiny_string& s) : ASObject(c),data(s) +ASString::ASString(Class_base* c,const tiny_string& s) : ASObject(c),data(s),hasId(false),datafilled(true),stringId(BUILTIN_STRINGS::EMPTY) { type=T_STRING; } -ASString::ASString(Class_base* c,const Glib::ustring& s) : ASObject(c),data(s) +ASString::ASString(Class_base* c,const Glib::ustring& s) : ASObject(c),data(s),hasId(false),datafilled(true),stringId(BUILTIN_STRINGS::EMPTY) { type=T_STRING; } -ASString::ASString(Class_base* c,const char* s) : ASObject(c),data(s, /*copy:*/true) +ASString::ASString(Class_base* c,const char* s) : ASObject(c),data(s, /*copy:*/true),hasId(false),datafilled(true),stringId(BUILTIN_STRINGS::EMPTY) { type=T_STRING; } @@ -57,6 +57,9 @@ ASString::ASString(Class_base* c,const char* s, uint32_t len) : ASObject(c) { data = std::string(s,len); + hasId = false; + stringId = BUILTIN_STRINGS::EMPTY; + datafilled=true; type=T_STRING; } @@ -64,7 +67,12 @@ { ASString* th=static_cast<ASString*>(obj); if(args && argslen==1) + { th->data=args[0]->toString(); + th->hasId = false; + th->stringId = BUILTIN_STRINGS::EMPTY; + th->datafilled = true; + } return NULL; } @@ -72,7 +80,7 @@ { // fast path if obj is ASString if (obj->is<ASString>()) - return abstract_i(obj->getSystemState(),obj->as<ASString>()->data.numChars()); + return abstract_i(obj->getSystemState(),obj->as<ASString>()->getData().numChars()); return abstract_i(obj->getSystemState(),obj->toString().numChars()); } @@ -453,16 +461,11 @@ return abstract_s(obj->getSystemState(),data.substr(start,end-start)); } -tiny_string ASString::toString_priv() const -{ - return data; -} - number_t ASString::toNumber() { assert_and_throw(implEnable); - const char *s = data.raw_buf(); + const char *s = getData().raw_buf(); while (*s && isEcmaSpace(g_utf8_get_char(s))) s = g_utf8_next_char(s); @@ -529,7 +532,7 @@ int32_t ASString::toInt() { assert_and_throw(implEnable); - return Integer::stringToASInteger(data.raw_buf(), 0); + return Integer::stringToASInteger(getData().raw_buf(), 0); } uint32_t ASString::toUInt() @@ -547,8 +550,8 @@ { if (!this->isConstructed()) return !r->isConstructed(); - const ASString* s=static_cast<const ASString*>(r); - return s->data==data; + ASString* s=static_cast<ASString*>(r); + return s->hasId && hasId ? s->stringId == stringId : s->getData()==getData(); } case T_INTEGER: case T_UINTEGER: @@ -573,7 +576,7 @@ if(getObjectType()==T_STRING && rprim->getObjectType()==T_STRING) { ASString* rstr=static_cast<ASString*>(rprim.getPtr()); - return (data<rstr->data)?TTRUE:TFALSE; + return (getData()<rstr->getData())?TTRUE:TFALSE; } number_t a=toNumber(); number_t b=rprim->toNumber(); @@ -589,12 +592,12 @@ if (out->getObjectEncoding() == ObjectEncoding::AMF0) { out->writeByte(amf0_string_marker); - out->writeStringAMF0(data); + out->writeStringAMF0(getData()); } else { out->writeByte(string_marker); - out->writeStringVR(stringMap, data); + out->writeStringVR(stringMap, getData()); } } @@ -635,11 +638,11 @@ // fast path if obj is ASString if (obj->is<ASString>()) { - int maxIndex=obj->as<ASString>()->data.numChars(); + int maxIndex=obj->as<ASString>()->getData().numChars(); if(index<0 || index>=maxIndex || std::isinf(index)) return abstract_s(obj->getSystemState()); - return abstract_s(obj->getSystemState(), tiny_string::fromChar(obj->as<ASString>()->data.charAt(index)) ); + return abstract_s(obj->getSystemState(), tiny_string::fromChar(obj->as<ASString>()->getData().charAt(index)) ); } tiny_string data = obj->toString(); @@ -657,9 +660,9 @@ // fast path if obj is ASString if (obj->is<ASString>()) { - if(index<0 || index>=obj->as<ASString>()->data.numChars() || std::isinf(index) || std::isnan(index)) + if(index<0 || index>=obj->as<ASString>()->getData().numChars() || std::isinf(index) || std::isnan(index)) return abstract_d(obj->getSystemState(),Number::NaN); - return abstract_i(obj->getSystemState(),obj->as<ASString>()->data.charAt(index)); + return abstract_i(obj->getSystemState(),obj->as<ASString>()->getData().charAt(index)); } tiny_string data = obj->toString(); if(index<0 || index>=data.numChars() || std::isinf(index) || std::isnan(index)) @@ -750,7 +753,8 @@ ASString* ret=abstract_s(obj->getSystemState()); for(uint32_t i=0;i<argslen;i++) { - ret->data += tiny_string::fromChar(args[i]->toUInt16()); + ret->hasId = false; + ret->getData() += tiny_string::fromChar(args[i]->toUInt16()); } return ret; } @@ -803,14 +807,14 @@ do { tiny_string replaceWithTmp = replaceWith; - int rc=pcre_exec(pcreRE, &extra, ret->data.raw_buf(), ret->data.numBytes(), offset, 0, ovector, (capturingGroups+1)*3); + int rc=pcre_exec(pcreRE, &extra, ret->getData().raw_buf(), ret->getData().numBytes(), offset, 0, ovector, (capturingGroups+1)*3); if(rc<0) { //No matches or error pcre_free(pcreRE); return ret; } - prevsubstring += ret->data.substr_bytes(offset,ovector[0]-offset); + prevsubstring += ret->getData().substr_bytes(offset,ovector[0]-offset); if(type==FUNC) { //Get the replace for this match @@ -853,23 +857,24 @@ replaceWithTmp.replace(ipos,1,""); break; case '&': - replaceWithTmp.replace(ipos-1,2,ret->data.substr_bytes(ovector[0], ovector[1]-ovector[0])); + replaceWithTmp.replace(ipos-1,2,ret->getData().substr_bytes(ovector[0], ovector[1]-ovector[0])); break; case '`': replaceWithTmp.replace(ipos-1,2,prevsubstring); break; case '\'': - replaceWithTmp.replace(ipos-1,2,ret->data.substr_bytes(ovector[1],ret->data.numBytes()-ovector[1])); + replaceWithTmp.replace(ipos-1,2,ret->getData().substr_bytes(ovector[1],ret->getData().numBytes()-ovector[1])); break; } continue; } - group = (i >= rc) ? "" : ret->data.substr_bytes(ovector[i*2], ovector[i*2+1]-ovector[i*2]); + group = (i >= rc) ? "" : ret->getData().substr_bytes(ovector[i*2], ovector[i*2+1]-ovector[i*2]); replaceWithTmp.replace(pos, ipos-pos, group); } } - prevsubstring += ret->data.substr_bytes(ovector[0],ovector[1]-ovector[0]); - ret->data.replace_bytes(ovector[0],ovector[1]-ovector[0],replaceWithTmp); + prevsubstring += ret->getData().substr_bytes(ovector[0],ovector[1]-ovector[0]); + ret->hasId = false; + ret->getData().replace_bytes(ovector[0],ovector[1]-ovector[0],replaceWithTmp); offset=ovector[0]+replaceWithTmp.numBytes(); if (ovector[0] == ovector[1]) offset+=1; @@ -882,10 +887,11 @@ else { const tiny_string& s=args[0]->toString(); - int index=ret->data.find(s,0); + int index=ret->getData().find(s,0); if(index==-1) //No result return ret; - ret->data.replace(index,s.numChars(),replaceWith); + ret->hasId = false; + ret->getData().replace(index,s.numChars(),replaceWith); } return ret; @@ -896,7 +902,10 @@ tiny_string data = obj->toString(); ASString* ret=abstract_s(obj->getSystemState(),data); for(unsigned int i=0;i<argslen;i++) - ret->data+=args[i]->toString().raw_buf(); + { + ret->hasId = false; + ret->getData()+=args[i]->toString().raw_buf(); + } return ret; }
View file
lightspark.tar.xz/src/scripting/toplevel/ASString.h
Changed
@@ -34,10 +34,12 @@ { friend ASString* abstract_s(SystemState* sys); friend ASString* abstract_s(SystemState* sys, const char* s, uint32_t len); + friend ASString* abstract_s(SystemState* sys, const char* s); friend ASString* abstract_s(SystemState* sys, const tiny_string& s); + friend ASString* abstract_s(SystemState* sys, uint32_t stringId); private: - tiny_string toString_priv() const; number_t parseStringInfinite(const char *s, char **end) const; + tiny_string data; public: ASString(Class_base* c); ASString(Class_base* c, const std::string& s); @@ -45,7 +47,25 @@ ASString(Class_base* c, const Glib::ustring& s); ASString(Class_base* c, const char* s); ASString(Class_base* c, const char* s, uint32_t len); - tiny_string data; + bool hasId; + bool datafilled; + uint32_t stringId; + inline tiny_string& getData() + { + if (!datafilled) + { + data = getSystemState()->getStringFromUniqueId(stringId); + datafilled = true; + } + return data; + } + inline bool isEmpty() const + { + if (hasId) + return stringId == BUILTIN_STRINGS::EMPTY; + return data.empty(); + } + static void sinit(Class_base* c); static void buildTraits(ASObject* o); ASFUNCTION(_constructor); @@ -78,10 +98,10 @@ void serialize(ByteArray* out, std::map<tiny_string, uint32_t>& stringMap, std::map<const ASObject*, uint32_t>& objMap, std::map<const Class_base*, uint32_t>& traitsMap); - std::string toDebugString() { return std::string("\"") + std::string(data) + "\""; } + std::string toDebugString() { return std::string("\"") + std::string(getData()) + "\""; } static bool isEcmaSpace(uint32_t c); static bool isEcmaLineTerminator(uint32_t c); - inline void finalize() { data.clear(); } + inline void finalize() { data.clear(); hasId = true, datafilled=true; stringId = BUILTIN_STRINGS::EMPTY; } }; template<>
View file
lightspark.tar.xz/src/scripting/toplevel/Boolean.cpp
Changed
@@ -46,7 +46,7 @@ case T_BOOLEAN: return o->as<Boolean>()->val; case T_NUMBER: - return (o->as<Number>()->val != 0) && !std::isnan(o->as<Number>()->val); + return (o->as<Number>()->val != 0.0) && !std::isnan(o->as<Number>()->val); case T_INTEGER: return o->as<Integer>()->val != 0; case T_UINTEGER: @@ -54,7 +54,7 @@ case T_STRING: if (!o->isConstructed()) return false; - return !o->as<ASString>()->data.empty(); + return !o->as<ASString>()->isEmpty(); case T_FUNCTION: case T_ARRAY: case T_OBJECT:
View file
lightspark.tar.xz/src/scripting/toplevel/Vector.cpp
Changed
@@ -123,7 +123,7 @@ bool Vector::sameType(const Class_base *cls) const { tiny_string clsname = this->getClass()->getQualifiedClassName(); - return (clsname.startsWith(cls->class_name.getQualifiedName().raw_buf())); + return (clsname.startsWith(cls->class_name.getQualifiedName(getSystemState()).raw_buf())); } ASObject* Vector::generator(TemplatedClass<Vector>* o_class, ASObject* const* args, const unsigned int argslen)
View file
lightspark.tar.xz/src/scripting/toplevel/XML.cpp
Changed
@@ -308,7 +308,7 @@ XMLVector ret; multiname mname(NULL); name->applyProxyProperty(mname); - th->getDescendantsByQName(name->toString(),mname.isQName() ? mname.ns[0].getImpl(obj->getSystemState()).name : "",mname.isAttribute,ret); + th->getDescendantsByQName(name->toString(),mname.isQName() ? obj->getSystemState()->getStringFromUniqueId(mname.ns[0].getImpl(obj->getSystemState()).nameId) : "",mname.isAttribute,ret); return Class<XMLList>::getInstanceS(obj->getSystemState(),ret,th->getChildrenlist(),multiname(NULL)); } @@ -375,8 +375,8 @@ tiny_string tmpns; if(argslen > 0 && args[0]->is<ASQName>()) { - tmpns= args[0]->as<ASQName>()->getURI(); - attrname = args[0]->as<ASQName>()->getLocalName(); + tmpns= obj->getSystemState()->getStringFromUniqueId(args[0]->as<ASQName>()->getURI()); + attrname = obj->getSystemState()->getStringFromUniqueId(args[0]->as<ASQName>()->getLocalName()); } @@ -746,7 +746,7 @@ XMLVector ret; th->childrenImpl(ret, "*"); multiname mname(NULL); - mname.name_s_id=obj->getSystemState()->getUniqueStringId("*"); + mname.name_s_id=BUILTIN_STRINGS::STRING_WILDCARD; mname.name_type=multiname::NAME_STRING; mname.ns.emplace_back(obj->getSystemState(),"",NAMESPACE); XMLList* retObj=Class<XMLList>::getInstanceS(obj->getSystemState(),ret,th->getChildrenlist(),mname); @@ -886,7 +886,7 @@ } else if (newNamespace->is<ASQName>()) { - ns_uri = newNamespace->as<ASQName>()->getURI(); + ns_uri = obj->getSystemState()->getStringFromUniqueId(newNamespace->as<ASQName>()->getURI()); } else ns_uri = newNamespace->toString(); @@ -974,7 +974,7 @@ tiny_string new_name; if(newName->is<ASQName>()) { - new_name=newName->as<ASQName>()->getLocalName(); + new_name=obj->getSystemState()->getStringFromUniqueId(newName->as<ASQName>()->getLocalName()); } else { @@ -1010,8 +1010,8 @@ if(newName->is<ASQName>()) { ASQName *qname=newName->as<ASQName>(); - localname=qname->getLocalName(); - ns_uri=qname->getURI(); + localname=obj->getSystemState()->getStringFromUniqueId(qname->getLocalName()); + ns_uri=obj->getSystemState()->getStringFromUniqueId(qname->getURI()); } else if (!newName->is<Undefined>()) { @@ -1047,7 +1047,7 @@ else if(newNamespace->is<ASQName>()) { ASQName *qname=newNamespace->as<ASQName>(); - ns_uri=qname->getURI(); + ns_uri=obj->getSystemState()->getStringFromUniqueId(qname->getURI()); for (uint32_t i = 0; i < th->namespacedefs.size(); i++) { bool b; @@ -1255,12 +1255,12 @@ while (i < name.ns.size()) { nsNameAndKindImpl ns=name.ns[i].getImpl(getSystemState()); - if (ns.kind==NAMESPACE && ns.name != AS3) + if (ns.kind==NAMESPACE && ns.nameId != getSystemState()->getUniqueStringId(AS3)) { - if (ns.name.empty()) + if (ns.nameId == BUILTIN_STRINGS::EMPTY) namespace_uri +=getVm(getSystemState())->getDefaultXMLNamespace(); else - namespace_uri +=ns.name; + namespace_uri +=getSystemState()->getStringFromUniqueId(ns.nameId); namespace_uri += "|"; } i++; @@ -1319,12 +1319,12 @@ while (i < name.ns.size()) { nsNameAndKindImpl ns=name.ns[i].getImpl(getSystemState()); - if (ns.kind==NAMESPACE && ns.name != AS3) + if (ns.kind==NAMESPACE && ns.nameId != getSystemState()->getUniqueStringId(AS3)) { - if (ns.name.empty()) + if (ns.nameId == BUILTIN_STRINGS::EMPTY) namespace_uri +=getVm(getSystemState())->getDefaultXMLNamespace(); else - namespace_uri +=ns.name; + namespace_uri +=getSystemState()->getStringFromUniqueId(ns.nameId); namespace_uri += "|"; } i++; @@ -1450,7 +1450,7 @@ nsNameAndKindImpl ns=name.ns[0].getImpl(getSystemState()); if (ns.kind==NAMESPACE) { - ns_uri=ns.name; + ns_uri=getSystemState()->getStringFromUniqueId(ns.nameId); ns_prefix=getNamespacePrefixByURI(ns_uri); } } @@ -1654,7 +1654,7 @@ { nsNameAndKindImpl ns=name.ns[0].getImpl(getSystemState()); assert_and_throw(ns.kind==NAMESPACE); - ns_uri=ns.name; + ns_uri=getSystemState()->getStringFromUniqueId(ns.nameId); ns_prefix=getNamespacePrefixByURI(ns_uri); } @@ -1721,7 +1721,7 @@ { nsNameAndKindImpl ns=name.ns[0].getImpl(getSystemState()); assert_and_throw(ns.kind==NAMESPACE); - ns_uri=ns.name; + ns_uri=getSystemState()->getStringFromUniqueId(ns.nameId); ns_prefix=getNamespacePrefixByURI(ns_uri); } if (ns_uri.empty() && ns_prefix.empty()) @@ -1758,7 +1758,7 @@ { nsNameAndKindImpl ns=name.ns[0].getImpl(getSystemState()); assert_and_throw(ns.kind==NAMESPACE); - ns_uri=ns.name; + ns_uri=getSystemState()->getStringFromUniqueId(ns.nameId); } if (!childrenlist.isNull() && childrenlist->nodes.size() > 0) { @@ -2669,7 +2669,7 @@ for(itattr = srcnode.attributes_begin();itattr!=srcnode.attributes_end();++itattr) { tiny_string aname = tiny_string(itattr->name(),true); - if(aname == "xmlns" || aname.substr_bytes(0,6) == "xmlns:") + if(aname == "xmlns" || (aname.numBytes() >= 6 && aname.substr_bytes(0,6) == "xmlns:")) continue; _NR<XML> tmp = _MR<XML>(Class<XML>::getInstanceSNoArgs(node->getSystemState())); node->incRef(); @@ -2779,8 +2779,8 @@ name.name_type=multiname::NAME_STRING; if (propertyName->is<ASQName>()) { - name.name_s_id=obj->getSystemState()->getUniqueStringId(propertyName->as<ASQName>()->getLocalName()); - name.ns.emplace_back(obj->getSystemState(),propertyName->as<ASQName>()->getURI(),NAMESPACE); + name.name_s_id=propertyName->as<ASQName>()->getLocalName(); + name.ns.emplace_back(obj->getSystemState(),obj->getSystemState()->getStringFromUniqueId(propertyName->as<ASQName>()->getURI()),NAMESPACE); } else if (propertyName->toString() == "*") {
View file
lightspark.tar.xz/src/scripting/toplevel/XMLList.cpp
Changed
@@ -642,7 +642,7 @@ { nsNameAndKindImpl ns=name.ns[0].getImpl(getSystemState()); if (ns.kind==NAMESPACE) - namespace_uri=ns.name; + namespace_uri=getSystemState()->getStringFromUniqueId(ns.nameId); } // namespace set by "default xml namespace = ..."
View file
lightspark.tar.xz/src/scripting/toplevel/toplevel.cpp
Changed
@@ -163,7 +163,14 @@ if(argslen==0 || args[0]->is<Null>() || args[0]->is<Undefined>()) { //get the current global object - newObj=getVm(obj->getSystemState())->currentCallContext->scope_stack[0].object->as<Global>(); + call_context* cc = getVm(obj->getSystemState())->currentCallContext; + if (!cc->parent_scope_stack.isNull() && cc->parent_scope_stack->scope.size() > 0) + newObj =cc->parent_scope_stack->scope[0].object.getPtr(); + else + { + assert_and_throw(cc->scope_stack.size() > 0); + newObj =cc->scope_stack[0].object.getPtr(); + } newObj->incRef(); } else @@ -198,7 +205,14 @@ if(argslen==0 || args[0]->is<Null>() || args[0]->is<Undefined>()) { //get the current global object - newObj=getVm(obj->getSystemState())->currentCallContext->scope_stack[0].object->as<Global>(); + call_context* cc = getVm(obj->getSystemState())->currentCallContext; + if (!cc->parent_scope_stack.isNull() && cc->parent_scope_stack->scope.size() > 0) + newObj =cc->parent_scope_stack->scope[0].object.getPtr(); + else + { + assert_and_throw(cc->scope_stack.size() > 0); + newObj =cc->scope_stack[0].object.getPtr(); + } newObj->incRef(); } else @@ -253,7 +267,7 @@ return XML::createFromNode(root); } -SyntheticFunction::SyntheticFunction(Class_base* c,method_info* m):IFunction(c),mi(m),val(NULL) +SyntheticFunction::SyntheticFunction(Class_base* c,method_info* m):IFunction(c),mi(m),val(NULL),func_scope(NullRef) { if(mi) length = mi->numArgs(); @@ -366,16 +380,10 @@ cc.stack_index=0; cc.context=mi->context; //cc.code= new istringstream(mi->body->code); - cc.scope_stack=func_scope; - cc.initialScopeStack=func_scope.size(); + cc.parent_scope_stack=func_scope; cc.exec_pos=0; call_context* saved_cc = getVm(getSystemState())->currentCallContext; - if (saved_cc) - { - if (!saved_cc->defaultNamespaceUri.isNull()) - saved_cc->defaultNamespaceUri->incRef(); - cc.defaultNamespaceUri = saved_cc->defaultNamespaceUri; - } + cc.defaultNamespaceUri = saved_cc ? saved_cc->defaultNamespaceUri : (uint32_t)BUILTIN_STRINGS::EMPTY; /* Set the current global object, each script in each DoABCTag has its own */ getVm(getSystemState())->currentCallContext = &cc; @@ -489,8 +497,6 @@ cc.runtime_stack_clear(); cc.runtime_stack_push(excobj); cc.scope_stack.clear(); - cc.scope_stack=func_scope; - cc.initialScopeStack=func_scope.size(); break; } } @@ -741,9 +747,9 @@ if(!typeObject) { - if (mn->ns.size() >= 1 && mn->ns[0].getImpl(context->root->getSystemState()).name == "__AS3__.vec") + if (mn->ns.size() >= 1 && mn->ns[0].getImpl(context->root->getSystemState()).nameId == BUILTIN_STRINGS::STRING_AS3VECTOR) { - QName qname(getSys()->getStringFromUniqueId(mn->name_s_id),mn->ns[0].getImpl(context->root->getSystemState()).name); + QName qname(mn->name_s_id,mn->ns[0].getImpl(context->root->getSystemState()).nameId); typeObject = Template<Vector>::getTemplateInstance(context->root->getSystemState(),qname,context,context->root->applicationDomain).getPtr(); } } @@ -757,9 +763,9 @@ type=T_CLASS; } -Class_base::Class_base(const Class_object*):ASObject((MemoryAccount*)NULL),protected_ns(getSys(),"",NAMESPACE),constructor(NULL), +Class_base::Class_base(const Class_object*):ASObject((MemoryAccount*)NULL),protected_ns(getSys(),BUILTIN_STRINGS::EMPTY,NAMESPACE),constructor(NULL), borrowedVariables(NULL), - context(NULL),class_name("Class",""),memoryAccount(NULL),length(1),class_index(-1),isFinal(false),isSealed(false),isInterface(false),isReusable(false),isProxy(false),use_protected(false) + context(NULL),class_name(BUILTIN_STRINGS::STRING_CLASS,BUILTIN_STRINGS::EMPTY),memoryAccount(NULL),length(1),class_index(-1),isFinal(false),isSealed(false),isInterface(false),isReusable(false),isProxy(false),use_protected(false) { type=T_CLASS; //We have tested that (Class is Class == true) so the classdef is 'this' @@ -827,7 +833,7 @@ if(o->is<Class_base>()) { /* classes can be cast to the type 'Object' or 'Class' */ if(this == Class<ASObject>::getClass(o->getSystemState()) - || (class_name.name=="Class" && class_name.ns=="")) + || (class_name.nameId==BUILTIN_STRINGS::STRING_CLASS && class_name.nsStringId==BUILTIN_STRINGS::EMPTY)) return o; /* 'this' is the type of a class */ else throwError<TypeError>(kCheckTypeFailedError, o->getClassName(), getQualifiedClassName()); @@ -855,7 +861,7 @@ Class_base* th = obj->as<Class_base>(); tiny_string ret; ret = "[class "; - ret += th->class_name.name; + ret += obj->getSystemState()->getStringFromUniqueId(th->class_name.nameId); ret += "]"; return abstract_s(obj->getSystemState(),ret); } @@ -929,7 +935,7 @@ tiny_string Class_base::toString() { tiny_string ret="[class "; - ret+=class_name.name; + ret+=getSystemState()->getStringFromUniqueId(class_name.nameId); ret+="]"; return ret; } @@ -1150,7 +1156,7 @@ tiny_string Class_base::getQualifiedClassName() const { if(class_index==-1) - return class_name.getQualifiedName(); + return class_name.getQualifiedName(getSystemState()); else { assert_and_throw(context); @@ -1161,6 +1167,13 @@ } } +tiny_string Class_base::getName() const +{ + return (class_name.nsStringId == BUILTIN_STRINGS::EMPTY ? + this->getSystemState()->getStringFromUniqueId(class_name.nameId) + : this->getSystemState()->getStringFromUniqueId(class_name.nsStringId) +"$"+ this->getSystemState()->getStringFromUniqueId(class_name.nameId)); +} + ASObject *Class_base::describeType() const { pugi::xml_document p; @@ -1389,18 +1402,18 @@ { pugi::xml_node metadata_node=root.append_child("metadata"); metadata_info& minfo = context->metadata[trait.metadata[i]]; - metadata_node.append_attribute("name").set_value(context->getString(minfo.name).raw_buf()); + metadata_node.append_attribute("name").set_value(context->root->getSystemState()->getStringFromUniqueId(context->getString(minfo.name)).raw_buf()); for(unsigned int j=0;j<minfo.item_count;++j) { pugi::xml_node arg_node=metadata_node.append_child("arg"); - arg_node.append_attribute("key").set_value(context->getString(minfo.items[j].key).raw_buf()); - arg_node.append_attribute("value").set_value(context->getString(minfo.items[j].value).raw_buf()); + arg_node.append_attribute("key").set_value(context->root->getSystemState()->getStringFromUniqueId(context->getString(minfo.items[j].key)).raw_buf()); + arg_node.append_attribute("value").set_value(context->root->getSystemState()->getStringFromUniqueId(context->getString(minfo.items[j].value)).raw_buf()); } } } -void Class_base::initializeProtectedNamespace(const tiny_string& name, const namespace_info& ns) +void Class_base::initializeProtectedNamespace(uint32_t nameId, const namespace_info& ns) { Class_inherit* cur=dynamic_cast<Class_inherit*>(super.getPtr()); nsNameAndKind* baseNs=NULL; @@ -1414,9 +1427,9 @@ cur=dynamic_cast<Class_inherit*>(cur->super.getPtr()); } if(baseNs==NULL) - protected_ns=nsNameAndKind(getSystemState(),name,(NS_KIND)(int)ns.kind); + protected_ns=nsNameAndKind(getSystemState(),nameId,(NS_KIND)(int)ns.kind); else - protected_ns=nsNameAndKind(getSystemState(),name,baseNs->nsId,(NS_KIND)(int)ns.kind); + protected_ns=nsNameAndKind(getSystemState(),nameId,baseNs->nsId,(NS_KIND)(int)ns.kind); } variable* Class_base::findBorrowedSettable(const multiname& name, bool* has_getter) @@ -1454,8 +1467,8 @@ void ASQName::setByXML(XML* node) { uri_is_null=false; - local_name = node->getName(); - uri=node->getNamespaceURI(); + local_name = getSystemState()->getUniqueStringId(node->getName()); + uri=getSystemState()->getUniqueStringId(node->getNamespaceURI()); } void ASQName::sinit(Class_base* c) @@ -1476,9 +1489,9 @@ if(argslen==0) { - th->local_name=""; + th->local_name=BUILTIN_STRINGS::EMPTY; th->uri_is_null=false; - th->uri=getVm(obj->getSystemState())->getDefaultXMLNamespace(); + th->uri=obj->getSystemState()->getUniqueStringId(getVm(obj->getSystemState())->getDefaultXMLNamespace()); return NULL; } if(argslen==1) @@ -1505,28 +1518,28 @@ } } else if(nameval->getObjectType()==T_UNDEFINED) - th->local_name=""; + th->local_name=BUILTIN_STRINGS::EMPTY; else - th->local_name=nameval->toString(); + th->local_name=obj->getSystemState()->getUniqueStringId(nameval->toString()); // Set uri th->uri_is_null=false; if(!namespaceval || namespaceval->getObjectType()==T_UNDEFINED) { - if(th->local_name=="*") + if(th->local_name==BUILTIN_STRINGS::STRING_WILDCARD) { th->uri_is_null=true; - th->uri=""; + th->uri=BUILTIN_STRINGS::EMPTY; } else { - th->uri=getVm(obj->getSystemState())->getDefaultXMLNamespace(); + th->uri=obj->getSystemState()->getUniqueStringId(getVm(obj->getSystemState())->getDefaultXMLNamespace()); } } else if(namespaceval->getObjectType()==T_NULL) { th->uri_is_null=true; - th->uri=""; + th->uri=BUILTIN_STRINGS::EMPTY; } else { @@ -1537,7 +1550,7 @@ th->uri=q->uri; } else - th->uri=namespaceval->toString(); + th->uri=obj->getSystemState()->getUniqueStringId(namespaceval->toString()); } return NULL; @@ -1552,9 +1565,9 @@ if(argslen==0) { - th->local_name=""; + th->local_name=BUILTIN_STRINGS::EMPTY; th->uri_is_null=false; - th->uri=getVm(getSys())->getDefaultXMLNamespace(); + th->uri=th->getSystemState()->getUniqueStringId(getVm(getSys())->getDefaultXMLNamespace()); return th; } if(argslen==1) @@ -1581,28 +1594,28 @@ } } else if(nameval->getObjectType()==T_UNDEFINED) - th->local_name=""; + th->local_name=BUILTIN_STRINGS::EMPTY; else - th->local_name=nameval->toString(); + th->local_name=th->getSystemState()->getUniqueStringId(nameval->toString()); // Set uri th->uri_is_null=false; if(!namespaceval || namespaceval->getObjectType()==T_UNDEFINED) { - if(th->local_name=="*") + if(th->local_name==BUILTIN_STRINGS::STRING_WILDCARD) { th->uri_is_null=true; - th->uri=""; + th->uri=BUILTIN_STRINGS::EMPTY; } else { - th->uri=getVm(getSys())->getDefaultXMLNamespace(); + th->uri=th->getSystemState()->getUniqueStringId(getVm(th->getSystemState())->getDefaultXMLNamespace()); } } else if(namespaceval->getObjectType()==T_NULL) { th->uri_is_null=true; - th->uri=""; + th->uri=BUILTIN_STRINGS::EMPTY; } else { @@ -1613,7 +1626,7 @@ th->uri=q->uri; } else - th->uri=namespaceval->toString(); + th->uri=th->getSystemState()->getUniqueStringId(namespaceval->toString()); } return th; } @@ -1624,13 +1637,13 @@ if(th->uri_is_null) return obj->getSystemState()->getNullRef(); else - return abstract_s(obj->getSystemState(),th->uri); + return abstract_s(obj->getSystemState(),obj->getSystemState()->getStringFromUniqueId(th->uri)); } ASFUNCTIONBODY(ASQName,_getLocalName) { ASQName* th=static_cast<ASQName*>(obj); - return abstract_s(obj->getSystemState(),th->local_name); + return abstract_s(obj->getSystemState(),obj->getSystemState()->getStringFromUniqueId(th->local_name)); } ASFUNCTIONBODY(ASQName,_toString) @@ -1657,10 +1670,10 @@ tiny_string s; if(uri_is_null) s = "*::"; - else if(uri!="") - s = uri + "::"; + else if(uri!=BUILTIN_STRINGS::EMPTY) + s = getSystemState()->getStringFromUniqueId(uri) + "::"; - return s + local_name; + return s + getSystemState()->getStringFromUniqueId(local_name); } uint32_t ASQName::nextNameIndex(uint32_t cur_index) @@ -1703,9 +1716,9 @@ if (uri_is_null) return _MR(getSystemState()->getNullRef()); else - return _MR(abstract_s(getSystemState(),this->uri)); + return _MR(abstract_s(getSystemState(),getSystemState()->getStringFromUniqueId(this->uri))); case 2: - return _MR(abstract_s(getSystemState(),this->local_name)); + return _MR(abstract_s(getSystemState(),getSystemState()->getStringFromUniqueId(this->local_name))); default: return ASObject::nextName(index-2); } @@ -1779,7 +1792,7 @@ !(static_cast<ASQName*>(urival)->uri_is_null)) { ASQName* q=static_cast<ASQName*>(urival); - th->uri=q->uri; + th->uri=q->getSystemState()->getStringFromUniqueId(q->uri); } else { @@ -1797,7 +1810,7 @@ !(static_cast<ASQName*>(urival)->uri_is_null)) { ASQName* q=static_cast<ASQName*>(urival); - th->uri=q->uri; + th->uri=q->getSystemState()->getStringFromUniqueId(q->uri); } else { @@ -1867,7 +1880,7 @@ !(static_cast<ASQName*>(urival)->uri_is_null)) { ASQName* q=static_cast<ASQName*>(urival); - th->uri=q->uri; + th->uri=th->getSystemState()->getStringFromUniqueId(q->uri); } else { @@ -1885,7 +1898,7 @@ !(static_cast<ASQName*>(urival)->uri_is_null)) { ASQName* q=static_cast<ASQName*>(urival); - th->uri=q->uri; + th->uri=th->getSystemState()->getStringFromUniqueId(q->uri); } else { @@ -2064,8 +2077,7 @@ if(*retAddr==NULL) { //Create the class - MemoryAccount* memoryAccount = s->allocateMemoryAccount(ClassName<IFunction>::name); - ret=new (s->unaccountedMemory) Class<IFunction>(memoryAccount); + ret=new (s->unaccountedMemory) Class<IFunction>(s->unaccountedMemory); ret->setSystemState(s); //This function is called from Class<ASObject>::getRef(), //so the Class<ASObject> we obtain will not have any @@ -2262,7 +2274,7 @@ if(args[0]->getObjectType() == T_STRING) { ASString* str = static_cast<ASString*>(args[0]); - Log::print(str->data); + Log::print(str->getData()); } else Log::print(args[0]->toString()); @@ -2280,7 +2292,7 @@ if(args[i]->getObjectType() == T_STRING) { ASString* str = static_cast<ASString*>(args[i]); - s << str->data; + s << str->getData(); } else s << args[i]->toString(); @@ -2296,7 +2308,7 @@ if(obj->getObjectType()==lightspark::T_QNAME) { ASQName *q=static_cast<ASQName*>(obj); - name=q->getLocalName(); + name=obj->getSystemState()->getStringFromUniqueId(q->getLocalName()); } else if(obj->getObjectType()==lightspark::T_UNDEFINED || obj->getObjectType()==lightspark::T_NULL)
View file
lightspark.tar.xz/src/scripting/toplevel/toplevel.h
Changed
@@ -49,7 +49,7 @@ class Void; class Class_object; class ApplicationDomain; - +extern bool isVmThread(); // Enum used during early binding in abc_optimizer.cpp enum EARLY_BIND_STATUS { NOT_BINDED=0, CANNOT_BIND=1, BINDED }; @@ -147,7 +147,7 @@ mutable std::vector<multiname> interfaces; mutable std::vector<Class_base*> interfaces_added; nsNameAndKind protected_ns; - void initializeProtectedNamespace(const tiny_string& name, const namespace_info& ns); + void initializeProtectedNamespace(uint32_t nameId, const namespace_info& ns); IFunction* constructor; void describeTraits(pugi::xml_node &root, std::vector<traits_info>& traits) const; void describeMetadata(pugi::xml_node &node, const traits_info& trait) const; @@ -166,7 +166,10 @@ public: inline ASObject* getObjectFromFreeList() { - SpinlockLocker l(referencedObjectsMutex); +#ifndef NDEBUG + // all ASObjects must be created in the VM thread + assert_and_throw(isVmThread()); +#endif ASObject* ret = NULL; if (!freelist.empty()) { @@ -178,7 +181,10 @@ } inline ASObject* getObjectFromFreeList2() { - SpinlockLocker l(referencedObjectsMutex); +#ifndef NDEBUG + // all ASObjects must be created in the VM thread + assert_and_throw(isVmThread()); +#endif ASObject* ret = NULL; if (!freelist2.empty()) { @@ -191,8 +197,11 @@ inline void pushObjectToFreeList(ASObject *obj) { +#ifndef NDEBUG + // all ASObjects must be created in the VM thread + assert_and_throw(isVmThread()); +#endif assert(obj->getRefCount() == 0); - SpinlockLocker l(referencedObjectsMutex); if (obj->reusableListNumber == 0) freelist.push_back(obj); else @@ -246,7 +255,7 @@ */ bool isSubClass(const Class_base* cls, bool considerInterfaces=true) const; tiny_string getQualifiedClassName() const; - tiny_string getName() const { return (class_name.ns.empty() ? class_name.name : class_name.ns +"$"+ class_name.name); } + tiny_string getName() const; tiny_string toString(); virtual ASObject* generator(ASObject* const* args, const unsigned int argslen); ASObject *describeType() const; @@ -538,6 +547,7 @@ ret->val = val; ret->length = length; ret->inClass = inClass; + func_scope->incRef(); ret->func_scope = func_scope; ret->functionname = functionname; } @@ -551,12 +561,12 @@ inline void finalize() { IFunction::finalize(); - func_scope.clear(); + func_scope.reset(); val = NULL; mi = NULL; } - std::vector<scope_entry> func_scope; + _NR<scope_entry_list> func_scope; bool isEqual(ASObject* r) { SyntheticFunction* sf=dynamic_cast<SyntheticFunction*>(r); @@ -568,12 +578,17 @@ } void acquireScope(const std::vector<scope_entry>& scope) { - assert_and_throw(func_scope.empty()); - func_scope=scope; + if (func_scope.isNull()) + func_scope = _NR<scope_entry_list>(new scope_entry_list()); + + assert_and_throw(func_scope->scope.empty()); + func_scope->scope=scope; } void addToScope(const scope_entry& s) { - func_scope.emplace_back(s); + if (func_scope.isNull()) + func_scope = _NR<scope_entry_list>(new scope_entry_list()); + func_scope->scope.emplace_back(s); } }; @@ -584,7 +599,7 @@ class Class<IFunction>: public Class_base { private: - Class<IFunction>(MemoryAccount* m):Class_base(QName("Function",""),m){} + Class<IFunction>(MemoryAccount* m):Class_base(QName(BUILTIN_STRINGS::STRING_FUNCTION,BUILTIN_STRINGS::EMPTY),m){} ASObject* getInstance(bool construct, ASObject* const* args, const unsigned int argslen, Class_base* realClass); IFunction* getNopFunction(); public: @@ -685,8 +700,8 @@ friend class Namespace; private: bool uri_is_null; - tiny_string uri; - tiny_string local_name; + uint32_t uri; + uint32_t local_name; public: ASQName(Class_base* c); void setByXML(XML* node); @@ -696,8 +711,8 @@ ASFUNCTION(_getURI); ASFUNCTION(_getLocalName); ASFUNCTION(_toString); - tiny_string getURI() const { return uri; } - tiny_string getLocalName() const { return local_name; } + uint32_t getURI() const { return uri; } + uint32_t getLocalName() const { return local_name; } bool isEqual(ASObject* o); tiny_string toString();
View file
lightspark.tar.xz/src/swf.cpp
Changed
@@ -175,7 +175,7 @@ } //See BUILTIN_STRINGS enum -static const char* builtinStrings[] = {"", "any", "void", "prototype" }; +static const char* builtinStrings[] = {"", "any", "void", "prototype", "Function", "__AS3__.vec","Class","*" }; extern uint32_t asClassCount; @@ -197,7 +197,7 @@ (void)tmp; // silence warning about unused variable } //Forge the empty namespace and make sure it gets id 0 - nsNameAndKindImpl emptyNs("", NAMESPACE); + nsNameAndKindImpl emptyNs(BUILTIN_STRINGS::EMPTY, NAMESPACE); uint32_t nsId; uint32_t baseId; getUniqueNamespaceId(emptyNs, 0, nsId, baseId); @@ -354,7 +354,7 @@ f << varName << endl << varValue << endl; /* That does occur in the wild */ - if(params->hasPropertyByMultiname(QName(varName,""), true, true)) + if(params->hasPropertyByMultiname(QName(getUniqueStringId(varName),BUILTIN_STRINGS::EMPTY), true, true)) LOG(LOG_ERROR,"Flash parameters has duplicate key '" << varName << "' - ignoring"); else params->setVariableByQName(varName,"", @@ -403,7 +403,7 @@ std::list< std::pair<tiny_string, tiny_string> >::iterator it; for (it=queries.begin(); it!=queries.end(); ++it) { - if(outParams->hasPropertyByMultiname(QName(it->first,""), true, true)) + if(outParams->hasPropertyByMultiname(QName(outParams->getSystemState()->getUniqueStringId(it->first),BUILTIN_STRINGS::EMPTY), true, true)) LOG(LOG_ERROR,"URL query parameters has duplicate key '" << it->first << "' - ignoring"); else outParams->setVariableByQName(it->first,"", @@ -2037,9 +2037,9 @@ return; tiny_string clsname; - if (!classname.ns.empty()) - clsname = classname.ns + "."; - clsname += classname.name; + if (!classname.nsStringId != BUILTIN_STRINGS::EMPTY) + clsname = getSystemState()->getStringFromUniqueId(classname.nsStringId) + "."; + clsname += getSystemState()->getStringFromUniqueId(classname.nameId); auto it=classesToBeBound.begin(); for(;it!=classesToBeBound.end();++it)
View file
lightspark.tar.xz/src/swf.h
Changed
@@ -154,9 +154,6 @@ void plot(uint32_t max, cairo_t *cr); }; -enum BUILTIN_STRINGS { EMPTY=0, ANY, VOID, PROTOTYPE, LAST_BUILTIN_STRING }; -enum BUILTIN_NAMESPACES { EMPTY_NS=0 }; - class SystemState: public ITickJob, public InvalidateQueue { private:
View file
lightspark.tar.xz/src/swftypes.cpp
Changed
@@ -41,7 +41,7 @@ { assert_and_throw(ns.size()>=1); assert_and_throw(name_type==NAME_STRING); - const tiny_string nsName=ns[0].getImpl(sys).name; + const tiny_string nsName=sys->getStringFromUniqueId(ns[0].getImpl(sys).nameId); const tiny_string& name=sys->getStringFromUniqueId(name_s_id); if(nsName.empty()) return name; @@ -133,14 +133,14 @@ case T_QNAME: { ASQName* qname=static_cast<ASQName*>(n); - name_s_id=n->getSystemState()->getUniqueStringId(qname->local_name); + name_s_id=qname->local_name; name_type = NAME_STRING; } break; case T_STRING: { ASString* o=static_cast<ASString*>(n); - name_s_id=n->getSystemState()->getUniqueStringId(o->data); + name_s_id=o->hasId ? o->stringId : n->getSystemState()->getUniqueStringId(o->getData()); name_type = NAME_STRING; } break; @@ -230,7 +230,7 @@ std::ostream& lightspark::operator<<(std::ostream& s, const QName& r) { - s << r.ns << ':' << r.name; + s << getSys()->getStringFromUniqueId(r.nsStringId) << ':' << getSys()->getStringFromUniqueId(r.nameId); return s; } @@ -273,7 +273,7 @@ prefix=""; break; } - s << prefix << r.getImpl(getSys()).name; + s << prefix << getSys()->getStringFromUniqueId(r.getImpl(getSys()).nameId); return s; } @@ -1348,18 +1348,32 @@ { ASString* ret= Class<ASString>::getInstanceSNoArgs(sys); ret->data = std::string(s,len); + ret->hasId = false; + ret->datafilled=true; return ret; } ASString* lightspark::abstract_s(SystemState *sys, const char* s) { ASString* ret= Class<ASString>::getInstanceSNoArgs(sys); ret->data = s; + ret->hasId = false; + ret->datafilled=true; return ret; } ASString* lightspark::abstract_s(SystemState *sys, const tiny_string& s) { ASString* ret= Class<ASString>::getInstanceSNoArgs(sys); ret->data = s; + ret->hasId = false; + ret->datafilled=true; + return ret; +} +ASString* lightspark::abstract_s(SystemState *sys, uint32_t stringId) +{ + ASString* ret= Class<ASString>::getInstanceSNoArgs(sys); + ret->stringId = stringId; + ret->hasId = true; + ret->datafilled=false; return ret; } @@ -1420,15 +1434,15 @@ { } -tiny_string QName::getQualifiedName() const +tiny_string QName::getQualifiedName(SystemState *sys) const { tiny_string ret; - if(!ns.empty()) + if(nsStringId != BUILTIN_STRINGS::EMPTY) { - ret+=ns; + ret+=sys->getStringFromUniqueId(nsStringId); ret+="::"; } - ret+=name; + ret+=sys->getStringFromUniqueId(nameId); return ret; } @@ -1436,8 +1450,8 @@ { multiname ret(NULL); ret.name_type = multiname::NAME_STRING; - ret.name_s_id = getSys()->getUniqueStringId(name); - ret.ns.emplace_back(getSys(),ns, NAMESPACE); + ret.name_s_id = nameId; + ret.ns.emplace_back(getSys(),nsStringId, NAMESPACE); ret.isAttribute = false; return ret; } @@ -1469,40 +1483,46 @@ nsNameAndKind::nsNameAndKind(SystemState* sys,const tiny_string& _name, NS_KIND _kind) { - nsNameAndKindImpl tmp(_name, _kind); + nsNameAndKindImpl tmp(sys->getUniqueStringId(_name), _kind); sys->getUniqueNamespaceId(tmp, nsRealId, nsId); nameIsEmpty=_name.empty(); } nsNameAndKind::nsNameAndKind(SystemState* sys,const char* _name, NS_KIND _kind) { - nsNameAndKindImpl tmp(_name, _kind); + nsNameAndKindImpl tmp(sys->getUniqueStringId(_name), _kind); sys->getUniqueNamespaceId(tmp, nsRealId, nsId); nameIsEmpty=(_name[0]=='\0'); } -nsNameAndKind::nsNameAndKind(SystemState* sys,const tiny_string& _name, uint32_t _baseId, NS_KIND _kind) +nsNameAndKind::nsNameAndKind(SystemState* sys,uint32_t _nameId, NS_KIND _kind) +{ + nsNameAndKindImpl tmp(_nameId, _kind); + sys->getUniqueNamespaceId(tmp, nsRealId, nsId); + nameIsEmpty=_nameId == BUILTIN_STRINGS::EMPTY; +} +nsNameAndKind::nsNameAndKind(SystemState* sys, uint32_t _nameId, uint32_t _baseId, NS_KIND _kind) { assert(_kind==PROTECTED_NAMESPACE); nsId=_baseId; - nsNameAndKindImpl tmp(_name, _kind, nsId); + nsNameAndKindImpl tmp(_nameId, _kind, nsId); uint32_t tmpId; sys->getUniqueNamespaceId(tmp, nsRealId, tmpId); assert(tmpId==_baseId); - nameIsEmpty=_name.empty(); + nameIsEmpty=_nameId == BUILTIN_STRINGS::EMPTY; } nsNameAndKind::nsNameAndKind(ABCContext* c, uint32_t nsContextIndex) { const namespace_info& ns=c->constant_pool.namespaces[nsContextIndex]; - const tiny_string& nsName=c->getString(ns.name); - nsNameAndKindImpl tmp(nsName, (NS_KIND)(int)ns.kind); + uint32_t nsNameId=c->getString(ns.name); + nsNameAndKindImpl tmp(nsNameId, (NS_KIND)(int)ns.kind); //Give an id hint, in case the namespace is created in the map c->root->getSystemState()->getUniqueNamespaceId(tmp, c->namespaceBaseId+nsContextIndex, nsRealId, nsId); //Special handling for private namespaces, they are always compared by id if(ns.kind==PRIVATE_NAMESPACE) nsId=c->namespaceBaseId+nsContextIndex; - nameIsEmpty=nsName.empty(); + nameIsEmpty=nsNameId==BUILTIN_STRINGS::EMPTY; } const nsNameAndKindImpl& nsNameAndKind::getImpl(SystemState* sys) const @@ -1510,27 +1530,8 @@ return sys->getNamespaceFromUniqueId(nsRealId); } -nsNameAndKindImpl::nsNameAndKindImpl(const tiny_string& _name, NS_KIND _kind, uint32_t b) - : name(_name),kind(_kind),baseId(b) -{ - if (kind != NAMESPACE && - kind != PACKAGE_NAMESPACE && - kind != PACKAGE_INTERNAL_NAMESPACE && - kind != PROTECTED_NAMESPACE && - kind != EXPLICIT_NAMESPACE && - kind != STATIC_PROTECTED_NAMESPACE && - kind != PRIVATE_NAMESPACE) - { - //I have seen empty namespace with kind 0. For other - //namespaces we should not get here. - if (!name.empty()) - LOG(LOG_ERROR, "Invalid namespace kind, converting to public namespace"); - kind = NAMESPACE; - } -} - -nsNameAndKindImpl::nsNameAndKindImpl(const char* _name, NS_KIND _kind, uint32_t b) - : name(_name),kind(_kind),baseId(b) +nsNameAndKindImpl::nsNameAndKindImpl(uint32_t _nameId, NS_KIND _kind, uint32_t b) + : nameId(_nameId),kind(_kind),baseId(b) { if (kind != NAMESPACE && kind != PACKAGE_NAMESPACE && @@ -1542,7 +1543,7 @@ { //I have seen empty namespace with kind 0. For other //namespaces we should not get here. - if (!name.empty()) + if (nameId != BUILTIN_STRINGS::EMPTY) LOG(LOG_ERROR, "Invalid namespace kind, converting to public namespace"); kind = NAMESPACE; }
View file
lightspark.tar.xz/src/swftypes.h
Changed
@@ -40,6 +40,9 @@ namespace lightspark { +enum BUILTIN_STRINGS { EMPTY=0, ANY, VOID, PROTOTYPE, STRING_FUNCTION,STRING_AS3VECTOR,STRING_CLASS,STRING_WILDCARD,LAST_BUILTIN_STRING }; +enum BUILTIN_NAMESPACES { EMPTY_NS=0 }; + enum SWFOBJECT_TYPE { T_OBJECT=0, T_INTEGER=1, T_NUMBER=2, T_FUNCTION=3, T_UNDEFINED=4, T_NULL=5, T_STRING=6, /*UNUSED=7,*/ T_BOOLEAN=8, T_ARRAY=9, T_CLASS=10, T_QNAME=11, T_NAMESPACE=12, T_UINTEGER=13, T_PROXY=14, T_TEMPLATE=15}; @@ -89,17 +92,17 @@ class QName { public: - tiny_string ns; - tiny_string name; - QName(const tiny_string& _name, const tiny_string& _ns):ns(_ns),name(_name){} + uint32_t nsStringId; + uint32_t nameId; + QName(uint32_t _nameId, uint32_t _nsId):nsStringId(_nsId),nameId(_nameId){} bool operator<(const QName& r) const { - if(ns==r.ns) - return name<r.name; + if(nsStringId==r.nsStringId) + return nameId<r.nameId; else - return ns<r.ns; + return nsStringId<r.nsStringId; } - tiny_string getQualifiedName() const; + tiny_string getQualifiedName(SystemState* sys) const; operator multiname() const; }; @@ -287,22 +290,21 @@ struct nsNameAndKindImpl { - tiny_string name; + uint32_t nameId; NS_KIND kind; uint32_t baseId; - nsNameAndKindImpl(const tiny_string& _name, NS_KIND _kind, uint32_t b=-1); - nsNameAndKindImpl(const char* _name, NS_KIND _kind, uint32_t b=-1); + nsNameAndKindImpl(uint32_t _nameId, NS_KIND _kind, uint32_t b=-1); bool operator<(const nsNameAndKindImpl& r) const { if(kind==r.kind) - return name < r.name; + return nameId < r.nameId; else return kind < r.kind; } bool operator>(const nsNameAndKindImpl& r) const { if(kind==r.kind) - return name > r.name; + return nameId > r.nameId; else return kind > r.kind; } @@ -315,12 +317,13 @@ bool nameIsEmpty; nsNameAndKind(SystemState *sys, const tiny_string& _name, NS_KIND _kind); nsNameAndKind(SystemState* sys,const char* _name, NS_KIND _kind); + nsNameAndKind(SystemState* sys,uint32_t _nameId, NS_KIND _kind); nsNameAndKind(ABCContext * c, uint32_t nsContextIndex); /* * Special constructor for protected namespace, which have * different representationId */ - nsNameAndKind(SystemState* sys,const tiny_string& _name, uint32_t _baseId, NS_KIND _kind); + nsNameAndKind(SystemState* sys,uint32_t _nameId, uint32_t _baseId, NS_KIND _kind); /* * Special version to create the empty bultin namespace */ @@ -1338,6 +1341,7 @@ ASString* abstract_s(SystemState *sys, const char* s, uint32_t len); ASString* abstract_s(SystemState *sys, const char* s); ASString* abstract_s(SystemState *sys, const tiny_string& s); +ASString* abstract_s(SystemState *sys, uint32_t stringId); void stringToQName(const tiny_string& tmp, tiny_string& name, tiny_string& ns);
View file
lightspark.tar.xz/src/tiny_string.cpp
Changed
@@ -243,13 +243,19 @@ bool tiny_string::operator<(const tiny_string& r) const { //don't check trailing \0 - return memcmp(buf,r.buf,std::min(stringSize,r.stringSize))<0; + int ret = memcmp(buf,r.buf,std::min(stringSize,r.stringSize)); + if (ret == 0) + return stringSize < r.stringSize; + return ret < 0; } bool tiny_string::operator>(const tiny_string& r) const { //don't check trailing \0 - return memcmp(buf,r.buf,std::min(stringSize,r.stringSize))>0; + int ret = memcmp(buf,r.buf,std::min(stringSize,r.stringSize)); + if (ret == 0) + return stringSize > r.stringSize; + return ret > 0; } bool tiny_string::operator==(const tiny_string& r) const
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.