0
|
1
|
|
2 /* Digital Mars DMDScript source code.
|
|
3 * Copyright (c) 2000-2002 by Chromium Communications
|
|
4 * D version Copyright (c) 2004-2005 by Digital Mars
|
|
5 * All Rights Reserved
|
|
6 * written by Walter Bright
|
|
7 * www.digitalmars.com
|
|
8 * Use at your own risk. There is no warranty, express or implied.
|
|
9 * License for redistribution is by the GNU General Public License in gpl.txt.
|
|
10 *
|
|
11 * A binary, non-exclusive license for commercial use can be
|
|
12 * purchased from www.digitalmars.com/dscript/buy.html.
|
|
13 *
|
|
14 * DMDScript is implemented in the D Programming Language,
|
|
15 * www.digitalmars.com/d/
|
|
16 *
|
|
17 * For a C++ implementation of DMDScript, including COM support,
|
|
18 * see www.digitalmars.com/dscript/cppscript.html.
|
|
19 */
|
|
20
|
|
21
|
3
|
22 module dmdscript_tango.darguments;
|
0
|
23
|
3
|
24 import dmdscript_tango.script;
|
|
25 import dmdscript_tango.dobject;
|
|
26 import dmdscript_tango.identifier;
|
|
27 import dmdscript_tango.value;
|
|
28 import dmdscript_tango.text;
|
|
29 import dmdscript_tango.property;
|
0
|
30
|
|
31 // The purpose of Darguments is to implement "value sharing"
|
|
32 // per ECMA 10.1.8 between the activation object and the
|
|
33 // arguments object.
|
|
34 // We implement it by forwarding the property calls from the
|
|
35 // arguments object to the activation object.
|
|
36
|
|
37 class Darguments : Dobject
|
|
38 {
|
|
39 Dobject actobj; // activation object
|
|
40 Identifier*[] parameters;
|
|
41
|
|
42 int isDarguments() { return true; }
|
|
43
|
|
44 this(Dobject caller, Dobject callee, Dobject actobj,
|
|
45 Identifier*[] parameters, Value[] arglist)
|
|
46
|
|
47 {
|
|
48 super(Dobject.getPrototype());
|
|
49
|
|
50 this.actobj = actobj;
|
|
51 this.parameters = parameters;
|
|
52
|
|
53 if (caller)
|
|
54 Put(TEXT_caller, caller, DontEnum);
|
|
55 else
|
|
56 Put(TEXT_caller, &vnull, DontEnum);
|
|
57
|
|
58 Put(TEXT_callee, callee, DontEnum);
|
|
59 Put(TEXT_length, arglist.length, DontEnum);
|
|
60
|
|
61 for (uint a = 0; a < arglist.length; a++)
|
|
62 {
|
|
63 Put(a, &arglist[a], DontEnum);
|
|
64 }
|
|
65 }
|
|
66
|
|
67 Value* Get(d_string PropertyName)
|
|
68 {
|
|
69 d_uint32 index;
|
|
70
|
|
71 return (StringToIndex(PropertyName, index) && index < parameters.length)
|
|
72 ? actobj.Get(index)
|
|
73 : Dobject.Get(PropertyName);
|
|
74 }
|
|
75
|
|
76 Value* Get(d_uint32 index)
|
|
77 {
|
|
78 return (index < parameters.length)
|
|
79 ? actobj.Get(index)
|
|
80 : Dobject.Get(index);
|
|
81 }
|
|
82
|
|
83 Value* Get(d_uint32 index, Value* vindex)
|
|
84 {
|
|
85 return (index < parameters.length)
|
|
86 ? actobj.Get(index, vindex)
|
|
87 : Dobject.Get(index, vindex);
|
|
88 }
|
|
89
|
|
90 Value* Put(d_string PropertyName, Value* value, uint attributes)
|
|
91 {
|
|
92 d_uint32 index;
|
|
93
|
|
94 if (StringToIndex(PropertyName, index) && index < parameters.length)
|
|
95 return actobj.Put(PropertyName, value, attributes);
|
|
96 else
|
|
97 return Dobject.Put(PropertyName, value, attributes);
|
|
98 }
|
|
99
|
|
100 Value* Put(Identifier* key, Value* value, uint attributes)
|
|
101 {
|
|
102 d_uint32 index;
|
|
103
|
|
104 if (StringToIndex(key.value.string, index) && index < parameters.length)
|
|
105 return actobj.Put(key, value, attributes);
|
|
106 else
|
|
107 return Dobject.Put(key, value, attributes);
|
|
108 }
|
|
109
|
|
110 Value* Put(d_string PropertyName, Dobject o, uint attributes)
|
|
111 {
|
|
112 d_uint32 index;
|
|
113
|
|
114 if (StringToIndex(PropertyName, index) && index < parameters.length)
|
|
115 return actobj.Put(PropertyName, o, attributes);
|
|
116 else
|
|
117 return Dobject.Put(PropertyName, o, attributes);
|
|
118 }
|
|
119
|
|
120 Value* Put(d_string PropertyName, d_number n, uint attributes)
|
|
121 {
|
|
122 d_uint32 index;
|
|
123
|
|
124 if (StringToIndex(PropertyName, index) && index < parameters.length)
|
|
125 return actobj.Put(PropertyName, n, attributes);
|
|
126 else
|
|
127 return Dobject.Put(PropertyName, n, attributes);
|
|
128 }
|
|
129
|
|
130 Value* Put(d_uint32 index, Value* vindex, Value* value, uint attributes)
|
|
131 {
|
|
132 if (index < parameters.length)
|
|
133 return actobj.Put(index, vindex, value, attributes);
|
|
134 else
|
|
135 return Dobject.Put(index, vindex, value, attributes);
|
|
136 }
|
|
137
|
|
138 Value* Put(d_uint32 index, Value* value, uint attributes)
|
|
139 {
|
|
140 if (index < parameters.length)
|
|
141 return actobj.Put(index, value, attributes);
|
|
142 else
|
|
143 return Dobject.Put(index, value, attributes);
|
|
144 }
|
|
145
|
|
146 int CanPut(d_string PropertyName)
|
|
147 {
|
|
148 d_uint32 index;
|
|
149
|
|
150 return (StringToIndex(PropertyName, index) && index < parameters.length)
|
|
151 ? actobj.CanPut(PropertyName)
|
|
152 : Dobject.CanPut(PropertyName);
|
|
153 }
|
|
154
|
|
155 int HasProperty(d_string PropertyName)
|
|
156 {
|
|
157 d_uint32 index;
|
|
158
|
|
159 return (StringToIndex(PropertyName, index) && index < parameters.length)
|
|
160 ? actobj.HasProperty(PropertyName)
|
|
161 : Dobject.HasProperty(PropertyName);
|
|
162 }
|
|
163
|
|
164 int Delete(d_string PropertyName)
|
|
165 {
|
|
166 d_uint32 index;
|
|
167
|
|
168 return (StringToIndex(PropertyName, index) && index < parameters.length)
|
|
169 ? actobj.Delete(PropertyName)
|
|
170 : Dobject.Delete(PropertyName);
|
|
171 }
|
|
172 }
|
|
173
|