Mercurial > projects > dmdscript-tango
comparison dmdscript_tango/derror.d @ 0:55c2951c07be
initial, files origin, premoved tree
author | saaadel |
---|---|
date | Sun, 24 Jan 2010 12:34:47 +0200 |
parents | |
children | 8363a4bf6a8f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:55c2951c07be |
---|---|
1 | |
2 /* Digital Mars DMDScript source code. | |
3 * Copyright (c) 2000-2002 by Chromium Communications | |
4 * D version Copyright (c) 2004-2006 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 | |
22 module dmdscript.derror; | |
23 | |
24 import dmdscript.script; | |
25 import dmdscript.dobject; | |
26 import dmdscript.dfunction; | |
27 import dmdscript.value; | |
28 import dmdscript.threadcontext; | |
29 import dmdscript.dnative; | |
30 import dmdscript.text; | |
31 import dmdscript.property; | |
32 | |
33 | |
34 // Comes from MAKE_HRESULT(SEVERITY_ERROR, FACILITY_CONTROL, 0) | |
35 const uint FACILITY = 0x800A0000; | |
36 | |
37 /* ===================== Derror_constructor ==================== */ | |
38 | |
39 class Derror_constructor : Dfunction | |
40 { | |
41 this(ThreadContext *tc) | |
42 { | |
43 super(1, tc.Dfunction_prototype); | |
44 } | |
45 | |
46 void* Construct(CallContext *cc, Value *ret, Value[] arglist) | |
47 { | |
48 // ECMA 15.7.2 | |
49 Dobject o; | |
50 Value* m; | |
51 Value* n; | |
52 Value vemptystring; | |
53 | |
54 vemptystring.putVstring(null); | |
55 switch (arglist.length) | |
56 { | |
57 case 0: // ECMA doesn't say what we do if m is undefined | |
58 m = &vemptystring; | |
59 n = &vundefined; | |
60 break; | |
61 case 1: | |
62 m = &arglist[0]; | |
63 if (m.isNumber()) | |
64 { | |
65 n = m; | |
66 m = &vemptystring; | |
67 } | |
68 else | |
69 n = &vundefined; | |
70 break; | |
71 default: | |
72 m = &arglist[0]; | |
73 n = &arglist[1]; | |
74 break; | |
75 } | |
76 o = new Derror(m, n); | |
77 ret.putVobject(o); | |
78 return null; | |
79 } | |
80 | |
81 void* Call(CallContext *cc, Dobject othis, Value* ret, Value[] arglist) | |
82 { | |
83 // ECMA v3 15.11.1 | |
84 return Construct(cc, ret, arglist); | |
85 } | |
86 } | |
87 | |
88 | |
89 /* ===================== Derror_prototype_toString =============== */ | |
90 | |
91 void* Derror_prototype_toString(Dobject pthis, CallContext *cc, Dobject othis, Value *ret, Value[] arglist) | |
92 { | |
93 // ECMA v3 15.11.4.3 | |
94 // Return implementation defined string | |
95 Value* v; | |
96 | |
97 //writef("Error.prototype.toString()\n"); | |
98 v = othis.Get(TEXT_message); | |
99 if (!v) | |
100 v = &vundefined; | |
101 ret.putVstring(v.toString()); | |
102 return null; | |
103 } | |
104 | |
105 /* ===================== Derror_prototype ==================== */ | |
106 | |
107 class Derror_prototype : Derror | |
108 { | |
109 this(ThreadContext *tc) | |
110 { | |
111 super(tc.Dobject_prototype); | |
112 Dobject f = tc.Dfunction_prototype; | |
113 //d_string m = d_string_ctor(DTEXT("Error.prototype.message")); | |
114 | |
115 Put(TEXT_constructor, tc.Derror_constructor, DontEnum); | |
116 | |
117 static NativeFunctionData nfd[] = | |
118 [ | |
119 { &TEXT_toString, &Derror_prototype_toString, 0 }, | |
120 ]; | |
121 | |
122 DnativeFunction.init(this, nfd, 0); | |
123 | |
124 Put(TEXT_name, TEXT_Error, 0); | |
125 Put(TEXT_message, TEXT_, 0); | |
126 Put(TEXT_description, TEXT_, 0); | |
127 Put(TEXT_number, cast(d_number)(/*FACILITY |*/ 0), 0); | |
128 } | |
129 } | |
130 | |
131 | |
132 /* ===================== Derror ==================== */ | |
133 | |
134 class Derror : Dobject | |
135 { | |
136 this(Value* m, Value* v2) | |
137 { | |
138 super(getPrototype()); | |
139 classname = TEXT_Error; | |
140 | |
141 d_string msg; | |
142 msg = m.toString(); | |
143 Put(TEXT_message, msg, 0); | |
144 Put(TEXT_description, msg, 0); | |
145 if (m.isString()) | |
146 { | |
147 } | |
148 else if (m.isNumber()) | |
149 { d_number n = m.toNumber(); | |
150 n = cast(d_number)(/*FACILITY |*/ cast(int)n); | |
151 Put(TEXT_number, n, 0); | |
152 } | |
153 if (v2.isString()) | |
154 { | |
155 Put(TEXT_description, v2.toString(), 0); | |
156 Put(TEXT_message, v2.toString(), 0); | |
157 } | |
158 else if (v2.isNumber()) | |
159 { d_number n = v2.toNumber(); | |
160 n = cast(d_number)(/*FACILITY |*/ cast(int)n); | |
161 Put(TEXT_number, n, 0); | |
162 } | |
163 } | |
164 | |
165 this(Dobject prototype) | |
166 { | |
167 super(prototype); | |
168 classname = TEXT_Error; | |
169 } | |
170 | |
171 static Dfunction getConstructor() | |
172 { | |
173 ThreadContext *tc = ThreadContext.getThreadContext(); | |
174 assert(tc); | |
175 return tc.Derror_constructor; | |
176 } | |
177 | |
178 static Dobject getPrototype() | |
179 { | |
180 ThreadContext *tc = ThreadContext.getThreadContext(); | |
181 assert(tc); | |
182 return tc.Derror_prototype; | |
183 } | |
184 | |
185 static void init(ThreadContext *tc) | |
186 { | |
187 tc.Derror_constructor = new Derror_constructor(tc); | |
188 tc.Derror_prototype = new Derror_prototype(tc); | |
189 | |
190 tc.Derror_constructor.Put(TEXT_prototype, tc.Derror_prototype, DontEnum | DontDelete | ReadOnly); | |
191 } | |
192 } | |
193 |