Changes of Revision 63

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