Projects
Essentials
lightspark
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 63
View file
lightspark.spec
Changed
@@ -24,7 +24,7 @@ %endif Name: lightspark -Version: 0.7.2.99+git20150305.1754 +Version: 0.7.2.99+git20150322.1346 Release: 0 Summary: Modern, free, open-source flash player implementation License: LGPL-3.0+
View file
lightspark.tar.xz/CMakeLists.txt
Changed
@@ -244,6 +244,9 @@ IF(${LLVM_STRING_VERSION} VERSION_GREATER 3.4) ADD_DEFINITIONS(-DLLVM_35) ENDIF(${LLVM_STRING_VERSION} VERSION_GREATER 3.4) +IF(${LLVM_STRING_VERSION} VERSION_GREATER 3.5) + ADD_DEFINITIONS(-DLLVM_36) +ENDIF(${LLVM_STRING_VERSION} VERSION_GREATER 3.5) INCLUDE(FindZLIB REQUIRED) INCLUDE(FindFreetype REQUIRED) IF(NOT(ENABLE_GLES2))
View file
lightspark.tar.xz/conf/FindLLVM.cmake
Changed
@@ -201,11 +201,19 @@ UNSET(LLVM_LIBS_CORE_ONLY) UNSET(LLVM_SYSTEM_LIBS_FAILED) MESSAGE(STATUS "LLVM core libs: " ${LLVM_LIBS_CORE}) + IF(${LLVM_STRING_VERSION} VERSION_GREATER 3.5) + IF(APPLE AND UNIVERSAL) + FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "engine native x86 PowerPC ARM" LLVM_LIBS_JIT LLVM_LIBS_JIT_OBJECTS ) + ELSE(APPLE AND UNIVERSAL) + FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "engine native" LLVM_LIBS_JIT LLVM_LIBS_JIT_OBJECTS ) + ENDIF(APPLE AND UNIVERSAL) + ELSE(${LLVM_STRING_VERSION} VERSION_GREATER 3.5) IF(APPLE AND UNIVERSAL) FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "jit native x86 PowerPC ARM" LLVM_LIBS_JIT LLVM_LIBS_JIT_OBJECTS ) ELSE(APPLE AND UNIVERSAL) FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "jit native" LLVM_LIBS_JIT LLVM_LIBS_JIT_OBJECTS ) ENDIF(APPLE AND UNIVERSAL) + ENDIF(${LLVM_STRING_VERSION} VERSION_GREATER 3.5) MESSAGE(STATUS "LLVM JIT libs: " ${LLVM_LIBS_JIT}) MESSAGE(STATUS "LLVM JIT objs: " ${LLVM_LIBS_JIT_OBJECTS})
View file
lightspark.tar.xz/src/asobject.cpp
Changed
@@ -187,7 +187,7 @@ c->prototype->setVariableByQName("hasOwnProperty","",Class<IFunction>::getFunction(hasOwnProperty),DYNAMIC_TRAIT); c->prototype->setVariableByQName("isPrototypeOf","",Class<IFunction>::getFunction(isPrototypeOf),DYNAMIC_TRAIT); c->prototype->setVariableByQName("propertyIsEnumerable","",Class<IFunction>::getFunction(propertyIsEnumerable),DYNAMIC_TRAIT); - + } void ASObject::buildTraits(ASObject* o) @@ -205,6 +205,8 @@ { case T_NULL: case T_UNDEFINED: + if (!this->isConstructed() && !this->is<Class_base>()) + return true; return false; case T_NUMBER: case T_INTEGER: @@ -229,6 +231,8 @@ return x->toString()==toString(); } } + if (r->is<ObjectConstructor>()) + return this == r->getClass(); LOG(LOG_CALLS,_("Equal comparison between type ")<<getObjectType()<< _(" and type ") << r->getObjectType()); if(classdef) @@ -865,8 +869,13 @@ /* If typename is a builtin type, we coerce obj. * It it's not it must be a user defined class, * so we try to find the class it is derived from and create an apropriate uninitialized instance */ - - type = Type::getBuiltinType(typemname); + if (typemname->ns.size() >= 1 && typemname->ns[0].getImpl().name == "__AS3__.vec") + { + QName qname(getSys()->getStringFromUniqueId(typemname->name_s_id),typemname->ns[0].getImpl().name); + type = Template<Vector>::getTemplateInstance(qname,context).getPtr(); + } + if (type == NULL) + type = Type::getBuiltinType(typemname); if (type == NULL) type = Type::getTypeFromMultiname(typemname,context); if(type==NULL) @@ -1764,7 +1773,7 @@ ret->setVar(obj); } -tiny_string ASObject::getClassName() +tiny_string ASObject::getClassName() const { if (getClass()) return getClass()->getQualifiedClassName();
View file
lightspark.tar.xz/src/asobject.h
Changed
@@ -441,7 +441,7 @@ tiny_string call_toJSON(); /* Helper function for calling getClass()->getQualifiedClassName() */ - virtual tiny_string getClassName(); + virtual tiny_string getClassName() const; ASFUNCTION(generator); @@ -493,6 +493,8 @@ void setProxyProperty(const multiname& name); /* applies proxy namespace settings to name for internal usage */ void applyProxyProperty(multiname &name); + + void dumpVariables() { Variables.dumpVariables(); } }; class Number;
View file
lightspark.tar.xz/src/backends/security.cpp
Changed
@@ -1023,7 +1023,8 @@ //Policy files must have on of the following content-types to be valid: //text/*, application/xml or application/xhtml+xml - tiny_string contentType = downloader->getHeader("content-type"); + std::list<tiny_string> contenttypelist = downloader->getHeader("content-type").split(';'); + tiny_string contentType = contenttypelist.size() == 0 ? "" : contenttypelist.front(); if(ok && (subtype == HTTP || subtype == HTTPS) && contentType.substr(0, 5) != "text/" && contentType != "application/xml" &&
View file
lightspark.tar.xz/src/scripting/abc.cpp
Changed
@@ -24,7 +24,9 @@ #include "compat.h" #include <llvm/ExecutionEngine/ExecutionEngine.h> +#ifndef LLVM_36 #include <llvm/ExecutionEngine/JIT.h> +#endif #include <llvm/PassManager.h> #ifdef HAVE_IR_DATALAYOUT_H # include <llvm/IR/Module.h> @@ -237,9 +239,6 @@ builtin->registerBuiltin("QName","",Class<ASQName>::getRef()); builtin->registerBuiltin("uint","",Class<UInteger>::getRef()); builtin->registerBuiltin("Vector","__AS3__.vec",_MR(Template<Vector>::getTemplate())); - //Some instances must be included, they are not created by AS3 code - builtin->registerBuiltin("Vector$Object","__AS3__.vec",Template<Vector>::getTemplateInstance(Class<ASObject>::getClass())); - builtin->registerBuiltin("Vector$Number","__AS3__.vec",Template<Vector>::getTemplateInstance(Class<Number>::getClass())); builtin->registerBuiltin("Error","",Class<ASError>::getRef()); builtin->registerBuiltin("SecurityError","",Class<SecurityError>::getRef()); builtin->registerBuiltin("ArgumentError","",Class<ArgumentError>::getRef()); @@ -495,6 +494,7 @@ // TODO stub classes, not yet implemented, but needed in tests builtin->registerBuiltin("Worker","flash.system",Class<ASObject>::getStubClass(QName("Worker","flash.system"))); + builtin->registerBuiltin("PerspectiveProjection","flash.geom",Class<ASObject>::getStubClass(QName("PerspectiveProjection","flash.geom"))); //If needed add AIR definitions if(getSys()->flashMode==SystemState::AIR) @@ -507,6 +507,9 @@ Class<ASObject>::getStubClass(QName("FileStream","flash.filestream"))); } + Class_object::getRef()->getClass()->prototype = _MNR(new_objectPrototype()); + Class_object::getRef()->getClass()->initStandardProps(); + getSys()->systemDomain->registerGlobalScope(builtin); } @@ -766,6 +769,16 @@ { multiname_info* p=&constant_pool.multinames[m->param_types[i]]; name += "$"; + tiny_string nsname; + if (p->ns < constant_pool.namespaces.size()) + { + // 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); + if (nsname != "") + name += nsname+"$"; + } name += getString(p->name); } ret->ns.push_back(nsNameAndKind(this, td->ns)); @@ -1552,7 +1565,11 @@ #endif llvm::InitializeNativeTarget(); th->module=new llvm::Module(llvm::StringRef("abc jit"),th->llvm_context()); +#ifdef LLVM_36 + llvm::EngineBuilder eb(std::unique_ptr<llvm::Module>(th->module)); +#else llvm::EngineBuilder eb(th->module); +#endif eb.setEngineKind(llvm::EngineKind::JIT); #ifdef LLVM_31 eb.setTargetOptions(Opts); @@ -1562,6 +1579,9 @@ assert_and_throw(th->ex); th->FPM=new llvm::FunctionPassManager(th->module); +#ifdef LLVM_36 + th->FPM->add(new llvm::DataLayoutPass()); +#else #ifdef LLVM_35 th->FPM->add(new llvm::DataLayoutPass(*th->ex->getDataLayout())); #elif defined HAVE_DATALAYOUT_H || defined HAVE_IR_DATALAYOUT_H @@ -1569,6 +1589,7 @@ #else th->FPM->add(new llvm::TargetData(*th->ex->getTargetData())); #endif +#endif #ifdef EXPENSIVE_DEBUG //This is pretty heavy, do not enable in release th->FPM->add(llvm::createVerifierPass()); @@ -1948,7 +1969,7 @@ LOG(LOG_CALLS,_("Next slot has flags ") << (t->kind>>4)); if(t->kind&traits_info::Metadata) - { + { for(unsigned int i=0;i<t->metadata_count;i++) { metadata_info& minfo = metadata[t->metadata[i]];
View file
lightspark.tar.xz/src/scripting/abc_opcodes.cpp
Changed
@@ -382,6 +382,7 @@ !obj->is<Null>() && !obj->is<Undefined>() && !obj->is<IFunction>() && + !obj->is<Function_object>() && obj->getClass() && obj->getClass() != Class_object::getClass()) obj->getClass()->setupDeclaredTraits(obj); @@ -733,7 +734,7 @@ /* Instantiate the template to obtain a class */ - std::vector<Type*> t(m); + std::vector<const Type*> t(m); for(int i=0;i<m;++i) { if(args[i]->is<Class_base>()) @@ -1493,7 +1494,7 @@ void ABCVm::initProperty(ASObject* obj, ASObject* value, multiname* name) { checkDeclaredTraits(obj); - + //Allow to set contant traits obj->setVariableByMultiname(*name,value,ASObject::CONST_ALLOWED); @@ -2106,6 +2107,9 @@ if(ret->super) ret->prototype->prevPrototype=ret->super->prototype; ret->addPrototypeGetter(); + ret->constructorprop = _NR<ObjectConstructor>(new_objectConstructor(ret)); + ret->constructorprop->incRef(); + ret->addConstructorGetter(); //add implemented interfaces for(unsigned int i=0;i<th->context->instances[n].interface_count;i++)
View file
lightspark.tar.xz/src/scripting/class.cpp
Changed
@@ -48,6 +48,13 @@ return new (c->memoryAccount) Function_object(c, p); } +ObjectConstructor* lightspark::new_objectConstructor(Class_base* cls) +{ + return new (cls->memoryAccount) ObjectConstructor(cls); +} + + + Class_inherit::Class_inherit(const QName& name, MemoryAccount* m):Class_base(name, m),tag(NULL),bindedToRoot(false) { this->incRef(); //create on reference for the classes map @@ -179,13 +186,7 @@ ret->setSuper(superClass); ret->prototype = _MNR(new_objectPrototype()); - ret->prototype->prevPrototype=ret->super->prototype; - ret->incRef(); - ret->prototype->setVariableByQName("constructor","",ret,DYNAMIC_TRAIT); - ret->addPrototypeGetter(); - ret->addLengthGetter(); - - ret->setDeclaredMethodByQName("toString","",Class<IFunction>::getFunction(Class_base::_toString),NORMAL_METHOD,false); + ret->initStandardProps(); getSys()->customClasses.insert(ret); ret->incRef(); return _MR(ret); @@ -205,12 +206,7 @@ *retAddr=ret; ret->prototype = _MNR(new_objectPrototype()); ASObject::sinit(ret); - - ret->setDeclaredMethodByQName("toString","",Class<IFunction>::getFunction(Class_base::_toString),NORMAL_METHOD,false); - ret->incRef(); - ret->prototype->setVariableByQName("constructor","",ret,DYNAMIC_TRAIT); - ret->addPrototypeGetter(); - ret->addLengthGetter(); + ret->initStandardProps(); } else ret=static_cast<Class<ASObject>*>(*retAddr);
View file
lightspark.tar.xz/src/scripting/class.h
Changed
@@ -72,6 +72,7 @@ Prototype* new_objectPrototype(); Prototype* new_functionPrototype(Class_base* functionClass, _NR<Prototype> p); Function_object* new_functionObject(_NR<ASObject> p); +ObjectConstructor* new_objectConstructor(Class_base* cls); template<class T,std::size_t N> struct newWithOptionalClass @@ -149,13 +150,7 @@ ret->prototype = _MNR(new_objectPrototype()); T::sinit(ret); - ret->setDeclaredMethodByQName("toString","",Class<IFunction>::getFunction(Class_base::_toString),NORMAL_METHOD,false); - ret->incRef(); - ret->prototype->setVariableByQName("constructor","",ret,DYNAMIC_TRAIT); - if(ret->super) - ret->prototype->prevPrototype=ret->super->prototype; - ret->addPrototypeGetter(); - ret->addLengthGetter(); + ret->initStandardProps(); } else ret=static_cast<Class<T>*>(*retAddr); @@ -340,9 +335,9 @@ private: /* the Template<T>* this class was generated from */ const Template_base* templ; - std::vector<Type*> types; + std::vector<const Type*> types; public: - TemplatedClass(const QName& name, const std::vector<Type*>& _types, Template_base* _templ, MemoryAccount* m) + TemplatedClass(const QName& name, const std::vector<const Type*>& _types, Template_base* _templ, MemoryAccount* m) : Class<T>(name, m), templ(_templ), types(_types) { } @@ -374,10 +369,14 @@ return templ; } - const std::vector<Type*> getTypes() const + std::vector<const Type*> getTypes() const { return types; } + void addType(const Type* type) + { + types.push_back(type); + } ASObject* coerce(ASObject* o) const { @@ -386,8 +385,8 @@ o->decRef(); return getSys()->getNullRef(); } - else if ((o->is<Vector>() && o->as<Vector>()->sameType(types)) || - o->is<Null>()) + else if ((o->is<Vector>() && o->as<Vector>()->sameType(this->class_name)) || + o->is<Null>()) { // Vector.<x> can be coerced to Vector.<y> // only if x and y are the same type @@ -397,7 +396,7 @@ { o->decRef(); throwError<TypeError>(kCheckTypeFailedError, o->getClassName(), - Class<T>::getQualifiedClassName()); + Class<T>::getQualifiedClassName()); return NULL; // not reached } } @@ -410,7 +409,7 @@ public: Template(QName name) : Template_base(name) {}; - QName getQName(const std::vector<Type*>& types) + QName getQName(const std::vector<const Type*>& types) { //This is the naming scheme that the ABC compiler uses, //and we need to stay in sync here @@ -423,7 +422,7 @@ return ret; } - Class_base* applyType(const std::vector<Type*>& types) + Class_base* applyType(const std::vector<const Type*>& types) { QName instantiatedQName = getQName(types); @@ -441,21 +440,61 @@ ret->addPrototypeGetter(); } else + { + TemplatedClass<T>* tmp = static_cast<TemplatedClass<T>*>(it->second); + if (tmp->getTypes().size() == 0) + tmp->addType(types[0]); + ret= tmp; + } + + ret->incRef(); + return ret; + } + Class_base* applyTypeByQName(const QName& qname) + { + const std::vector<const Type*> types; + std::map<QName, Class_base*>::iterator it=getSys()->instantiatedTemplates.find(qname); + Class<T>* ret=NULL; + if(it==getSys()->instantiatedTemplates.end()) //This class is not yet in the map, create it + { + MemoryAccount* memoryAccount = getSys()->allocateMemoryAccount(qname.name); + ret=new (getSys()->unaccountedMemory) TemplatedClass<T>(qname,types,this,memoryAccount); + getSys()->instantiatedTemplates.insert(std::make_pair(qname,ret)); + ret->prototype = _MNR(new_objectPrototype()); + T::sinit(ret); + if(ret->super) + ret->prototype->prevPrototype=ret->super->prototype; + ret->addPrototypeGetter(); + } + else ret=static_cast<TemplatedClass<T>*>(it->second); ret->incRef(); return ret; } - static Ref<Class_base> getTemplateInstance(Type* type) + static Ref<Class_base> getTemplateInstance(const Type* type) { - std::vector<Type*> t(1,type); + std::vector<const Type*> t(1,type); Template<T>* templ=getTemplate(); Ref<Class_base> ret=_MR(templ->applyType(t)); templ->decRef(); return ret; } + static Ref<Class_base> getTemplateInstance(const QName& qname, ABCContext* context) + { + Template<T>* templ=getTemplate(); + Ref<Class_base> ret=_MR(templ->applyTypeByQName(qname)); + ret->context = context; + templ->decRef(); + return ret; + } + static T* getInstanceS(const Type* type) + { + return static_cast<T*>(getTemplateInstance(type).getPtr()->getInstance(true,NULL,0)); + } + static Template<T>* getTemplate(const QName& name) { std::map<QName, Template_base*>::iterator it=getSys()->templates.find(name);
View file
lightspark.tar.xz/src/scripting/flash/display/BitmapData.cpp
Changed
@@ -563,11 +563,11 @@ } } - Vector *result = Class<Vector>::getInstanceS(Class<Vector>::getClass()); + Vector *result = Template<Vector>::getInstanceS(Template<Vector>::getTemplateInstance(Class<Number>::getClass()).getPtr()); int channelOrder[4] = {2, 1, 0, 3}; // red, green, blue, alpha for (int j=0; j<4; j++) { - Vector *histogram = Class<Vector>::getInstanceS(Class<Number>::getClass()); + Vector *histogram = Template<Vector>::getInstanceS(Class<Number>::getClass()); for (int level=0; level<256; level++) { histogram->append(abstract_d(counts[channelOrder[j]][level])); @@ -656,7 +656,7 @@ if (rect.isNull()) throwError<TypeError>(kNullPointerError, "rect"); - Vector *result = Class<Vector>::getInstanceS(Class<UInteger>::getClass()); + Vector *result = Template<Vector>::getInstanceS(Class<UInteger>::getClass()); vector<uint32_t> pixelvec = th->pixels->getPixelVector(rect->getRect()); vector<uint32_t>::const_iterator it; for (it=pixelvec.begin(); it!=pixelvec.end(); ++it)
View file
lightspark.tar.xz/src/scripting/flash/display/GraphicsPath.cpp
Changed
@@ -79,9 +79,9 @@ void GraphicsPath::ensureValid() { if (commands.isNull()) - commands = _MNR(Class<Vector>::getInstanceS(Class<Integer>::getClass())); + commands = _MNR(Template<Vector>::getInstanceS(Class<Integer>::getClass())); if (data.isNull()) - data = _MNR(Class<Vector>::getInstanceS(Class<Number>::getClass())); + data = _MNR(Template<Vector>::getInstanceS(Class<Number>::getClass())); } ASFUNCTIONBODY(GraphicsPath, curveTo)
View file
lightspark.tar.xz/src/scripting/flash/display/flashdisplay.cpp
Changed
@@ -1187,7 +1187,7 @@ { uint32_t dest=getFrameIdByLabel(args[0]->toString(), sceneName); if(dest==FRAME_NOT_FOUND) - throw Class<ArgumentError>::getInstanceS("gotoAndPlay/Stop: label not found"); + throwError<ArgumentError>(kInvalidArgumentError,stop ? "gotoAndStop: label not found" : "gotoAndPlay: label not found"); next_FP = dest; } @@ -1202,7 +1202,7 @@ { LOG(LOG_ERROR, next_FP << "= next_FP >= state.max_FP = " << getFramesLoaded()); /* spec says we should throw an error, but then YT breaks */ - //throw Class<ArgumentError>::getInstanceS("gotoAndPlay/Stop: frame not found"); + //throwError<ArgumentError>(kInvalidArgumentError,stop ? "gotoAndStop: frame not found" : "gotoAndPlay: frame not found"); next_FP = getFramesLoaded()-1; } } @@ -2222,7 +2222,7 @@ ASFUNCTIONBODY(Stage,_getStageVideos) { LOG(LOG_NOT_IMPLEMENTED, "Accelerated rendering through StageVideo not implemented, SWF should fall back to Video"); - return Class<Vector>::getInstanceS(Class<StageVideo>::getClass()); + return Template<Vector>::getInstanceS(Class<StageVideo>::getClass()); } _NR<InteractiveObject> Stage::getFocusTarget()
View file
lightspark.tar.xz/src/scripting/flash/utils/flashutils.cpp
Changed
@@ -148,11 +148,9 @@ ASObject* target; ASObject* o=ABCVm::getCurrentApplicationDomain(getVm()->currentCallContext)->getVariableAndTargetByMultiname(name,target); - //TODO: should raise an exception, for now just return undefined if(o==NULL) { - LOG(LOG_ERROR,_("Definition for '") << name << _("' not found.")); - return getSys()->getUndefinedRef(); + throwError<ReferenceError>(kClassNotFoundError, tmp); } assert_and_throw(o->getObjectType()==T_CLASS);
View file
lightspark.tar.xz/src/scripting/toplevel/Vector.cpp
Changed
@@ -94,7 +94,7 @@ c->prototype->setVariableByQName("unshift",AS3,Class<IFunction>::getFunction(unshift),DYNAMIC_TRAIT); } -Vector::Vector(Class_base* c, Type *vtype):ASObject(c),vec_type(vtype),fixed(false),vec(reporter_allocator<ASObject*>(c->memoryAccount)) +Vector::Vector(Class_base* c, const Type *vtype):ASObject(c),vec_type(vtype),fixed(false),vec(reporter_allocator<ASObject*>(c->memoryAccount)) { } @@ -114,18 +114,16 @@ ASObject::finalize(); } -void Vector::setTypes(const std::vector<Type*>& types) +void Vector::setTypes(const std::vector<const Type *> &types) { assert(vec_type == NULL); - assert_and_throw(types.size() == 1); - vec_type = types[0]; + if(types.size() == 1) + vec_type = types[0]; } - -bool Vector::sameType(const std::vector<Type*>& types) const +bool Vector::sameType(const QName& classname) const { - return (types.size() == 1) && ((types[0] == vec_type) || - (vec_type == Type::anyType) || - (types[0] == Type::anyType)); + tiny_string clsname = this->getClass()->getQualifiedClassName(); + return (clsname.startsWith(classname.getQualifiedName().raw_buf())); } ASObject* Vector::generator(TemplatedClass<Vector>* o_class, ASObject* const* args, const unsigned int argslen) @@ -134,7 +132,7 @@ assert_and_throw(args[0]->getClass()); assert_and_throw(o_class->getTypes().size() == 1); - Type* type = o_class->getTypes()[0]; + const Type* type = o_class->getTypes()[0]; if(args[0]->getClass() == Class<Array>::getClass()) {
View file
lightspark.tar.xz/src/scripting/toplevel/Vector.h
Changed
@@ -28,7 +28,7 @@ template<class T> class TemplatedClass; class Vector: public ASObject { - Type* vec_type; + const Type* vec_type; bool fixed; std::vector<ASObject*, reporter_allocator<ASObject*>> vec; int capIndex(int i) const; @@ -36,21 +36,21 @@ { private: IFunction* comparator; - Type* vec_type; + const Type* vec_type; public: - sortComparatorWrapper(IFunction* c, Type* v):comparator(c),vec_type(v){} + sortComparatorWrapper(IFunction* c, const Type* v):comparator(c),vec_type(v){} bool operator()(ASObject* d1, ASObject* d2); }; public: - Vector(Class_base* c, Type *vtype=NULL); + Vector(Class_base* c, const Type *vtype=NULL); ~Vector(); void finalize(); static void sinit(Class_base* c); static void buildTraits(ASObject* o) {}; static ASObject* generator(TemplatedClass<Vector>* o_class, ASObject* const* args, const unsigned int argslen); - void setTypes(const std::vector<Type*>& types); - bool sameType(const std::vector<Type*>& types) const; + void setTypes(const std::vector<const Type*>& types); + bool sameType(const QName& classname) const; //Overloads tiny_string toString(bool debugMsg=false); @@ -81,7 +81,6 @@ //TODO: do we need to implement generator? ASFUNCTION(_constructor); - ASFUNCTION(_applytype); ASFUNCTION(push); ASFUNCTION(_concat);
View file
lightspark.tar.xz/src/scripting/toplevel/toplevel.cpp
Changed
@@ -552,6 +552,13 @@ ret=getSys()->getUndefinedRef(); return ret; } +bool Function::isEqual(ASObject* r) +{ + Function* f=dynamic_cast<Function*>(r); + if(f==NULL) + return false; + return (val==f->val) && (closure_this==f->closure_this); +} bool Null::isEqual(ASObject* r) { @@ -775,6 +782,23 @@ } } +void Class_base::initStandardProps() +{ + incRef(); + constructorprop = _NR<ObjectConstructor>(new_objectConstructor(this)); + constructorprop->incRef(); + addConstructorGetter(); + + setDeclaredMethodByQName("toString","",Class<IFunction>::getFunction(Class_base::_toString),NORMAL_METHOD,false); + incRef(); + prototype->setVariableByQName("constructor","",this,DYNAMIC_TRAIT); + + if(super) + prototype->prevPrototype=super->prototype; + addPrototypeGetter(); + addLengthGetter(); +} + ASObject* Class_base::coerce(ASObject* o) const { @@ -788,6 +812,9 @@ else throwError<TypeError>(kCheckTypeFailedError, o->getClassName(), getQualifiedClassName()); } + if (o->is<ObjectConstructor>()) + return o; + //o->getClass() == NULL for primitive types //those are handled in overloads Class<Number>::coerce etc. if(!o->getClass() || !o->getClass()->isSubClass(this)) @@ -805,6 +832,11 @@ return Class<ASString>::getInstanceS(ret); } +void Class_base::addConstructorGetter() +{ + setDeclaredMethodByQName("constructor","",Class<IFunction>::getFunction(_getter_constructorprop),GETTER_METHOD,false); +} + void Class_base::addPrototypeGetter() { setDeclaredMethodByQName("prototype","",Class<IFunction>::getFunction(_getter_prototype),GETTER_METHOD,false); @@ -821,6 +853,20 @@ LOG(LOG_ERROR,_("Class destroyed without cleanUp called")); } +ASObject* Class_base::_getter_constructorprop(ASObject* obj, ASObject* const* args, const unsigned int argslen) +{ + Class_base* th = NULL; + if(obj->is<Class_base>()) + th = obj->as<Class_base>(); + else + th = obj->getClass(); + if(argslen != 0) + throw Class<ArgumentError>::getInstanceS("Arguments provided in getter"); + ASObject* ret=th->constructorprop.getPtr(); + ret->incRef(); + return ret; +} + ASObject* Class_base::_getter_prototype(ASObject* obj, ASObject* const* args, const unsigned int argslen) { if(!obj->is<Class_base>()) @@ -1191,7 +1237,7 @@ int kind=t.kind&0xf; multiname* mname=context->getMultiname(t.name,NULL); if (mname->name_type!=multiname::NAME_STRING || - (mname->ns.size()==1 && !mname->ns[0].hasEmptyName()) || + (mname->ns.size()==1 && (!mname->ns[0].hasEmptyName() || mname->ns[0].getImpl().kind == PRIVATE_NAMESPACE)) || mname->ns.size() > 1) continue; @@ -1899,6 +1945,11 @@ //Thus we make sure that everything is in order when getFunction() below is called ret->addPrototypeGetter(); IFunction::sinit(ret); + ret->constructorprop = _NR<ObjectConstructor>(new_objectConstructor(ret)); + ret->constructorprop->incRef(); + + ret->addConstructorGetter(); + ret->setDeclaredMethodByQName("prototype","",Class<IFunction>::getFunction(IFunction::_getter_prototype),GETTER_METHOD,true); ret->setDeclaredMethodByQName("prototype","",Class<IFunction>::getFunction(IFunction::_setter_prototype),SETTER_METHOD,true); } @@ -2297,8 +2348,15 @@ ObjectPrototype::ObjectPrototype(Class_base* c) : ASObject(c) { + traitsInitialized = true; + constructorCalled = true; +} +bool ObjectPrototype::isEqual(ASObject* r) +{ + if (r->is<ObjectPrototype>()) + return this->getClass() == r->getClass(); + return ASObject::isEqual(r); } - void ObjectPrototype::finalize() { ASObject::finalize(); @@ -2314,6 +2372,27 @@ return prevPrototype->getObj()->getVariableByMultiname(name, opt); } + +ObjectConstructor::ObjectConstructor(Class_base* c) : ASObject(c) +{ + Class<ASObject>::getRef()->prototype->incRef(); + this->prototype = Class<ASObject>::getRef()->prototype.getPtr(); +} + +_NR<ASObject> ObjectConstructor::getVariableByMultiname(const multiname& name, GET_VARIABLE_OPTION opt) +{ + if (name.normalizedName() == "prototype") + { + prototype->getObj()->incRef(); + return _NR<ASObject>(prototype->getObj()); + } + return getClass()->getVariableByMultiname(name, opt); +} +bool ObjectConstructor::isEqual(ASObject* r) +{ + return this == r || getClass() == r; +} + FunctionPrototype::FunctionPrototype(Class_base* c, _NR<Prototype> p) : Function(c, ASNop) { prevPrototype=p;
View file
lightspark.tar.xz/src/scripting/toplevel/toplevel.h
Changed
@@ -136,6 +136,7 @@ }; class Prototype; +class ObjectConstructor; class Class_base: public ASObject, public Type { @@ -158,9 +159,11 @@ protected: void copyBorrowedTraitsFromSuper(); ASFUNCTION(_toString); + void initStandardProps(); public: variables_map borrowedVariables; ASPROPERTY_GETTER(_NR<Prototype>,prototype); + ASPROPERTY_GETTER(_NR<ObjectConstructor>,constructorprop); _NR<Class_base> super; //We need to know what is the context we are referring to ABCContext* context; @@ -175,11 +178,13 @@ //TODO: move in Class_inherit bool use_protected:1; public: + void addConstructorGetter(); void addPrototypeGetter(); void addLengthGetter(); void setupDeclaredTraits(ASObject *target); void handleConstruction(ASObject* target, ASObject* const* args, unsigned int argslen, bool buildAndLink); void setConstructor(IFunction* c); + bool hasConstructor() { return constructor != NULL; } Class_base(const QName& name, MemoryAccount* m); //Special constructor for Class_object Class_base(const Class_object*); @@ -198,7 +203,7 @@ */ bool isSubClass(const Class_base* cls, bool considerInterfaces=true) const; tiny_string getQualifiedClassName() const; - tiny_string getName() const { return class_name.name; } + tiny_string getName() const { return (class_name.ns.empty() ? class_name.name : class_name.ns +"$"+ class_name.name); } tiny_string toString(); virtual ASObject* generator(ASObject* const* args, const unsigned int argslen); ASObject *describeType() const; @@ -233,7 +238,7 @@ QName template_name; public: Template_base(QName name); - virtual Class_base* applyType(const std::vector<Type*>& t)=0; + virtual Class_base* applyType(const std::vector<const Type*>& t)=0; }; class Class_object: public Class_base @@ -285,8 +290,24 @@ void decRef() { ASObject::decRef(); } ASObject* getObj() { return this; } _NR<ASObject> getVariableByMultiname(const multiname& name, GET_VARIABLE_OPTION opt=NONE); + bool isEqual(ASObject* r); +}; + +/* Special object used as constructor property for classes + * It has its own prototype object, but everything else is forwarded to the class object + */ +class ObjectConstructor: public ASObject +{ + Prototype* prototype; +public: + ObjectConstructor(Class_base* c); + void incRef() { getClass()->incRef(); } + void decRef() { getClass()->decRef(); } + _NR<ASObject> getVariableByMultiname(const multiname& name, GET_VARIABLE_OPTION opt=NONE); + bool isEqual(ASObject* r); }; + /* Special object returned when new func() syntax is used. * This object looks for properties on the prototype object that is passed in the constructor */ @@ -368,6 +389,8 @@ * Implements the IFunction interface for functions implemented * in c-code. */ +class FunctionPrototype; + class Function : public IFunction { friend class Class<IFunction>; @@ -384,13 +407,7 @@ method_info* getMethodInfo() const { return NULL; } public: ASObject* call(ASObject* obj, ASObject* const* args, uint32_t num_args); - bool isEqual(ASObject* r) - { - Function* f=dynamic_cast<Function*>(r); - if(f==NULL) - return false; - return (val==f->val) && (closure_this==f->closure_this); - } + bool isEqual(ASObject* r); }; /* Special object used as prototype for the Function class
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
.