forked from Jacopo/lightspark
/
flashsystem.cpp
133 lines (107 loc) · 3.97 KB
/
flashsystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**************************************************************************
Lightspark, a free flash player implementation
Copyright (C) 2009,2010 Alessandro Pignotti (a.pignotti@sssup.it)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "flashsystem.h"
#include "abc.h"
#include "class.h"
using namespace lightspark;
REGISTER_CLASS_NAME(ApplicationDomain);
REGISTER_CLASS_NAME(Capabilities);
REGISTER_CLASS_NAME(Security);
void Capabilities::sinit(Class_base* c)
{
c->setConstructor(Class<IFunction>::getFunction(_constructor));
c->setGetterByQName("language","",Class<IFunction>::getFunction(_getLanguage));
c->setVariableByQName("version","",Class<ASString>::getInstanceS("UNIX 10,0,0,0"));
}
ASFUNCTIONBODY(Capabilities,_constructor)
{
obj->setVariableByQName("playerType","",Class<ASString>::getInstanceS("AVMPlus"));
return NULL;
}
ASFUNCTIONBODY(Capabilities,_getLanguage)
{
return Class<ASString>::getInstanceS("en");
}
void ApplicationDomain::sinit(Class_base* c)
{
c->setConstructor(Class<IFunction>::getFunction(_constructor));
c->setGetterByQName("currentDomain","",Class<IFunction>::getFunction(_getCurrentDomain));
}
void ApplicationDomain::buildTraits(ASObject* o)
{
o->setVariableByQName("hasDefinition","",Class<IFunction>::getFunction(hasDefinition));
o->setVariableByQName("getDefinition","",Class<IFunction>::getFunction(getDefinition));
}
ASFUNCTIONBODY(ApplicationDomain,_constructor)
{
return NULL;
}
ASFUNCTIONBODY(ApplicationDomain,_getCurrentDomain)
{
return Class<ApplicationDomain>::getInstanceS();
}
ASFUNCTIONBODY(ApplicationDomain,hasDefinition)
{
assert(args && argslen==1);
const tiny_string& tmp=args[0]->toString();
tiny_string name,ns;
stringToQName(tmp,name,ns);
LOG(LOG_CALLS,"Looking for definition of " << ns << " :: " << name);
objAndLevel o=getGlobal()->getVariableByQName(name,ns);
if(o.obj==NULL)
return abstract_b(false);
else
{
//Check if the object has to be defined
if(o.obj->getObjectType()==T_DEFINABLE)
{
LOG(LOG_CALLS,"We got an object not yet valid");
Definable* d=static_cast<Definable*>(o.obj);
d->define(getGlobal());
o=getGlobal()->getVariableByQName(name,ns);
}
if(o.obj->getObjectType()!=T_CLASS)
return abstract_b(false);
LOG(LOG_CALLS,"Found definition for " << ns << " :: " << name);
return abstract_b(true);
}
}
ASFUNCTIONBODY(ApplicationDomain,getDefinition)
{
assert(args && argslen==1);
const tiny_string& tmp=args[0]->toString();
tiny_string name,ns;
stringToQName(tmp,name,ns);
LOG(LOG_CALLS,"Looking for definition of " << ns << " :: " << name);
objAndLevel o=getGlobal()->getVariableByQName(name,ns);
assert(o.obj);
//Check if the object has to be defined
if(o.obj->getObjectType()==T_DEFINABLE)
{
throw UnsupportedException("Defininable in ApplicationDomain::getDefinition");
/* LOG(LOG_CALLS,"We got an object not yet valid");
Definable* d=static_cast<Definable*>(o.obj);
d->define(sys->currentVm->last_context->Global);
o=sys->currentVm->last_context->Global->getVariableByQName(name,ns,owner);*/
}
assert(o.obj->getObjectType()==T_CLASS);
LOG(LOG_CALLS,"Getting definition for " << ns << " :: " << name);
return o.obj;
}
void Security::sinit(Class_base* c)
{
c->setConstructor(NULL);
c->setVariableByQName("allowDomain","",Class<IFunction>::getFunction(undefinedFunction));
}