Mercurial > projects > dmdscript-tango
comparison dmdscript_tango/protoerror.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.protoerror; | |
23 | |
24 import dmdscript.script; | |
25 import dmdscript.dobject; | |
26 import dmdscript.value; | |
27 import dmdscript.threadcontext; | |
28 import dmdscript.text; | |
29 import dmdscript.dfunction; | |
30 import dmdscript.property; | |
31 | |
32 int foo; // cause this module to be linked in | |
33 | |
34 /* ===================== D0_constructor ==================== */ | |
35 | |
36 class D0_constructor : Dfunction | |
37 { | |
38 d_string text_d1; | |
39 Dobject function(d_string) newD0; | |
40 | |
41 this(ThreadContext *tc, d_string text_d1, Dobject function(d_string) newD0) | |
42 { | |
43 super(1, tc.Dfunction_prototype); | |
44 this.text_d1 = text_d1; | |
45 this.newD0 = newD0; | |
46 } | |
47 | |
48 void *Construct(CallContext *cc, Value *ret, Value[] arglist) | |
49 { | |
50 // ECMA 15.11.7.2 | |
51 Value* m; | |
52 Dobject o; | |
53 tchar[] s; | |
54 | |
55 m = (arglist.length) ? &arglist[0] : &vundefined; | |
56 // ECMA doesn't say what we do if m is undefined | |
57 if (m.isUndefined()) | |
58 s = text_d1; | |
59 else | |
60 s = m.toString(); | |
61 o = (*newD0)(s); | |
62 ret.putVobject(o); | |
63 return null; | |
64 } | |
65 | |
66 void *Call(CallContext *cc, Dobject othis, Value* ret, Value[] arglist) | |
67 { | |
68 // ECMA v3 15.11.7.1 | |
69 return Construct(cc, ret, arglist); | |
70 } | |
71 } | |
72 | |
73 | |
74 template proto(alias TEXT_D1) | |
75 { | |
76 | |
77 /* ===================== D0_prototype ==================== */ | |
78 | |
79 class D0_prototype : D0 | |
80 { | |
81 this(ThreadContext *tc) | |
82 { | |
83 super(tc.Derror_prototype); | |
84 | |
85 tchar[] s; | |
86 | |
87 Put(TEXT_constructor, tc.ctorTable[TEXT_D1], DontEnum); | |
88 Put(TEXT_name, TEXT_D1, 0); | |
89 s = TEXT_D1 ~ ".prototype.message"; | |
90 Put(TEXT_message, s, 0); | |
91 Put(TEXT_description, s, 0); | |
92 Put(TEXT_number, cast(d_number)0, 0); | |
93 } | |
94 } | |
95 | |
96 /* ===================== D0 ==================== */ | |
97 | |
98 class D0 : Dobject | |
99 { | |
100 ErrInfo errinfo; | |
101 | |
102 this(Dobject prototype) | |
103 { | |
104 super(prototype); | |
105 classname = TEXT_Error; | |
106 } | |
107 | |
108 this(tchar[] m) | |
109 { | |
110 this(D0.getPrototype()); | |
111 Put(TEXT_message, m, 0); | |
112 Put(TEXT_description, m, 0); | |
113 Put(TEXT_number, cast(d_number)0, 0); | |
114 errinfo.message = m; | |
115 } | |
116 | |
117 this(ErrInfo *perrinfo) | |
118 { | |
119 this(perrinfo.message); | |
120 errinfo = *perrinfo; | |
121 Put(TEXT_number, cast(d_number)perrinfo.code, 0); | |
122 } | |
123 | |
124 void getErrInfo(ErrInfo *perrinfo, int linnum) | |
125 { | |
126 if (linnum && errinfo.linnum == 0) | |
127 errinfo.linnum = linnum; | |
128 if (perrinfo) | |
129 *perrinfo = errinfo; | |
130 //writefln("getErrInfo(linnum = %d), errinfo.linnum = %d", linnum, errinfo.linnum); | |
131 } | |
132 | |
133 static Dfunction getConstructor() | |
134 { | |
135 ThreadContext *tc = ThreadContext.getThreadContext(); | |
136 assert(tc); | |
137 return tc.ctorTable[TEXT_D1]; | |
138 } | |
139 | |
140 static Dobject getPrototype() | |
141 { | |
142 ThreadContext *tc = ThreadContext.getThreadContext(); | |
143 assert(tc); | |
144 return tc.protoTable[TEXT_D1]; | |
145 } | |
146 | |
147 static Dobject newD0(d_string s) | |
148 { | |
149 return new D0(s); | |
150 } | |
151 | |
152 static void init(ThreadContext *tc) | |
153 { | |
154 Dfunction constructor = new D0_constructor(tc, TEXT_D1, &newD0); | |
155 tc.ctorTable[TEXT_D1] = constructor; | |
156 | |
157 Dobject prototype = new D0_prototype(tc); | |
158 tc.protoTable[TEXT_D1] = prototype; | |
159 | |
160 constructor.Put(TEXT_prototype, prototype, DontEnum | DontDelete | ReadOnly); | |
161 } | |
162 } | |
163 } | |
164 | |
165 alias proto!(TEXT_SyntaxError) syntaxerror; | |
166 alias proto!(TEXT_EvalError) evalerror; | |
167 alias proto!(TEXT_ReferenceError) referenceerror; | |
168 alias proto!(TEXT_RangeError) rangeerror; | |
169 alias proto!(TEXT_TypeError) typeerror; | |
170 alias proto!(TEXT_URIError) urierror; | |
171 | |
172 /********************************** | |
173 * Register initializer for each class. | |
174 */ | |
175 | |
176 static this() | |
177 { | |
178 ThreadContext.initTable ~= &syntaxerror.D0.init; | |
179 ThreadContext.initTable ~= &evalerror.D0.init; | |
180 ThreadContext.initTable ~= &referenceerror.D0.init; | |
181 ThreadContext.initTable ~= &rangeerror.D0.init; | |
182 ThreadContext.initTable ~= &typeerror.D0.init; | |
183 ThreadContext.initTable ~= &urierror.D0.init; | |
184 } |