~invernizzi/lightspark/readme-update

« back to all changes in this revision

Viewing changes to swftypes.cpp

  • Committer: Alessandro
  • Date: 2010-04-06 16:24:35 UTC
  • mto: This revision was merged to the branch mainline in revision 577.
  • Revision ID: git-v1:b56d8176917df919e844bd4bd01cb0639c2d9a82
Make use of exceptions

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "swf.h"
33
33
#include "geometry.h"
34
34
#include "class.h"
 
35
#include "exceptions.h"
35
36
 
36
37
using namespace std;
37
38
using namespace lightspark;
89
90
        if(hasPropertyByQName("valueOf",""))
90
91
        {
91
92
                if(r->hasPropertyByQName("valueOf","")==false)
92
 
                        abort();
 
93
                        throw RunTimeException("Missing valueof for second operand",sys->getOrigin().raw_buf());
93
94
 
94
95
                objAndLevel obj1=getVariableByQName("valueOf","");
95
96
                objAndLevel obj2=r->getVariableByQName("valueOf","");
110
111
        LOG(LOG_NOT_IMPLEMENTED,"Less than comparison between type "<<getObjectType()<< " and type " << r->getObjectType());
111
112
        if(prototype)
112
113
                LOG(LOG_NOT_IMPLEMENTED,"Type " << prototype->class_name);
113
 
        abort();
 
114
        throw RunTimeException("Not handled less comparison for objects",sys->getOrigin().raw_buf());
114
115
        return false;
115
116
}
116
117
 
231
232
        }
232
233
}
233
234
 
234
 
bool Integer::isLess(ASObject* o)
235
 
{
236
 
        if(o->getObjectType()==T_INTEGER)
237
 
        {
238
 
                const Integer* i=static_cast<const Integer*>(o);
239
 
                return val < i->toInt();
240
 
        }
241
 
        else if(o->getObjectType()==T_NUMBER)
242
 
        {
243
 
                const Number* i=static_cast<const Number*>(o);
244
 
                return val < i->toNumber();
245
 
        }
246
 
        else if(o->getObjectType()==T_STRING)
247
 
        {
248
 
                const ASString* s=static_cast<const ASString*>(o->implementation);
249
 
                //Check if the string may be converted to integer
250
 
                //TODO: check whole string?
251
 
                if(isdigit(s->data[0]))
252
 
                {
253
 
                        int val2=atoi(s->data.c_str());
254
 
                        return val < val2;
255
 
                }
256
 
                else
257
 
                        return false;
258
 
        }
259
 
        else
260
 
                return ASObject::isLess(o);
261
 
}
262
 
 
263
 
bool Integer::isEqual(ASObject* o)
264
 
{
265
 
        if(o->getObjectType()==T_INTEGER)
266
 
                return val==o->toInt();
267
 
        else if(o->getObjectType()==T_UINTEGER)
268
 
        {
269
 
                //CHECK: somehow wrong
270
 
                return val==o->toInt();
271
 
        }
272
 
        else if(o->getObjectType()==T_NUMBER)
273
 
                return val==o->toInt();
274
 
        else
275
 
        {
276
 
                return ASObject::isEqual(o);
277
 
        }
278
 
}
279
 
 
280
235
bool ASObject::isEqual(ASObject* r)
281
236
{
282
237
        assert(ref_count>0);
314
269
        if(hasPropertyByQName("valueOf",""))
315
270
        {
316
271
                if(r->hasPropertyByQName("valueOf","")==false)
317
 
                        abort();
 
272
                        throw RunTimeException("Not handled less comparison for objects",sys->getOrigin().raw_buf());
318
273
 
319
274
                objAndLevel obj1=getVariableByQName("valueOf","");
320
275
                objAndLevel obj2=r->getVariableByQName("valueOf","");
351
306
                if(implementation->toInt(ret))
352
307
                        return ret;
353
308
        }
354
 
        LOG(LOG_ERROR,"Cannot convert object of type " << getObjectType() << " to Int");
355
 
        cout << "imanager " << iManager->available.size() << endl;
356
 
        cout << "dmanager " << dManager->available.size() << endl;
357
 
        abort();
 
309
        LOG(LOG_ERROR,"Cannot convert object of type " << getObjectType() << " to int");
 
310
        throw RunTimeException("Cannot converto object to int",sys->getOrigin().raw_buf());
358
311
        return 0;
359
312
}
360
313
 
367
320
                        return ret;
368
321
        }
369
322
        LOG(LOG_ERROR,"Cannot convert object of type " << getObjectType() << " to float");
370
 
        abort();
 
323
        throw RunTimeException("Cannot converto object to float",sys->getOrigin().raw_buf());
371
324
        return 0;
372
325
}
373
326
 
598
551
void variables_map::killObjVar(const multiname& mname, int level)
599
552
{
600
553
        nameAndLevel name("",level);
601
 
        if(mname.name_type==multiname::NAME_INT)
602
 
                name.name=tiny_string(mname.name_i);
603
 
        else if(mname.name_type==multiname::NAME_NUMBER)
604
 
                name.name=tiny_string(mname.name_d);
605
 
        else if(mname.name_type==multiname::NAME_STRING)
606
 
                name.name=mname.name_s;
607
 
        else
608
 
                abort();
 
554
        switch(mname.name_type)
 
555
        {
 
556
                case multiname::NAME_INT:
 
557
                        name.name=tiny_string(mname.name_i);
 
558
                        break;
 
559
                case multiname::NAME_NUMBER:
 
560
                        name.name=tiny_string(mname.name_d);
 
561
                        break;
 
562
                case multiname::NAME_STRING:
 
563
                        name.name=mname.name_s;
 
564
                        break;
 
565
                default:
 
566
                        assert("Unexpected name kind" && false);
 
567
        }
 
568
 
609
569
 
610
570
        const pair<var_iterator, var_iterator> ret=Variables.equal_range(name);
611
571
        assert(ret.first!=ret.second);
626
586
                }
627
587
        }
628
588
 
629
 
        abort();
 
589
        throw RunTimeException("Variable to kill not found",sys->getOrigin().raw_buf());
630
590
}
631
591
 
632
592
obj_var* variables_map::findObjVar(const multiname& mname, int& level, bool create, bool searchPreviusLevels)
633
593
{
634
594
        nameAndLevel name("",level);
635
 
        if(mname.name_type==multiname::NAME_INT)
636
 
                name.name=tiny_string(mname.name_i);
637
 
        else if(mname.name_type==multiname::NAME_NUMBER)
638
 
                name.name=tiny_string(mname.name_d);
639
 
        else if(mname.name_type==multiname::NAME_STRING)
640
 
                name.name=mname.name_s;
641
 
        else
642
 
                abort();
 
595
        switch(mname.name_type)
 
596
        {
 
597
                case multiname::NAME_INT:
 
598
                        name.name=tiny_string(mname.name_i);
 
599
                        break;
 
600
                case multiname::NAME_NUMBER:
 
601
                        name.name=tiny_string(mname.name_d);
 
602
                        break;
 
603
                case multiname::NAME_STRING:
 
604
                        name.name=mname.name_s;
 
605
                        break;
 
606
                default:
 
607
                        assert("Unexpected name kind" && false);
 
608
        }
643
609
 
644
610
        const var_iterator ret_begin=Variables.lower_bound(name);
645
611
        //This actually look for the first different name, if we accept also previous levels
890
856
                if(cur==name)
891
857
                {
892
858
                        if(it->second.second.getter)
893
 
                                abort();
 
859
                                throw UnsupportedException("Getters are not supported in getVariableByString",sys->getOrigin().raw_buf()); 
894
860
                        return it->second.second.var;
895
861
                }
896
862
        }
1681
1647
        if(HasScale)
1682
1648
        {
1683
1649
                int NScaleBits=UB(5,bs);
1684
 
                //if(NScaleBits==1)
1685
 
                //      __asm__("int $3");
1686
 
                FB tmp=FB(NScaleBits,bs);
1687
 
                v.ScaleX=tmp;
1688
 
                //if(v.ScaleX==0)
1689
 
                //      abort();
 
1650
                v.ScaleX=FB(NScaleBits,bs);
1690
1651
                v.ScaleY=FB(NScaleBits,bs);
1691
1652
        }
1692
1653
        int HasRotate=UB(1,bs);
1833
1794
        }
1834
1795
 
1835
1796
        //Name not present, no good
1836
 
        abort();
 
1797
        throw RunTimeException("initSlot on missing variable",sys->getOrigin().raw_buf());
1837
1798
}
1838
1799
 
1839
1800
void variables_map::setSlot(unsigned int n,ASObject* o)
1842
1803
        {
1843
1804
                assert(slots_vars[n-1]!=Variables.end());
1844
1805
                if(slots_vars[n-1]->second.second.setter)
1845
 
                        abort();
 
1806
                        throw UnsupportedException("setSlot has setters",sys->getOrigin().raw_buf());
1846
1807
                slots_vars[n-1]->second.second.var->decRef();
1847
1808
                slots_vars[n-1]->second.second.var=o;
1848
1809
        }
1849
1810
        else
1850
 
        {
1851
 
                LOG(LOG_ERROR,"Setting slot out of range");
1852
 
                abort();
1853
 
                //slots_vars.resize(n);
1854
 
                //slots[n-1]=o;
1855
 
        }
 
1811
                throw RunTimeException("setSlot out of bounds",sys->getOrigin().raw_buf());
1856
1812
}
1857
1813
 
1858
1814
obj_var* variables_map::getValueAt(unsigned int index, int& level)
1869
1825
                return &it->second.second;
1870
1826
        }
1871
1827
        else
1872
 
        {
1873
 
                LOG(LOG_ERROR,"Index too big");
1874
 
                abort();
1875
 
        }
 
1828
                throw RunTimeException("getValueAt out of bounds",sys->getOrigin().raw_buf());
1876
1829
}
1877
1830
 
1878
1831
ASObject* ASObject::getValueAt(int index)
1909
1862
                return tiny_string(it->first.name);
1910
1863
        }
1911
1864
        else
1912
 
        {
1913
 
                LOG(LOG_ERROR,"Index too big");
1914
 
                abort();
1915
 
        }
 
1865
                throw RunTimeException("getNameAt out of bounds",sys->getOrigin().raw_buf());
1916
1866
}
1917
1867
 
1918
1868
unsigned int ASObject::numVariables()