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 module dmdscript.dboolean;
|
|
22
|
|
23 import dmdscript.script;
|
|
24 import dmdscript.dobject;
|
|
25 import dmdscript.value;
|
|
26 import dmdscript.threadcontext;
|
|
27 import dmdscript.dfunction;
|
|
28 import dmdscript.text;
|
|
29 import dmdscript.property;
|
|
30 import dmdscript.errmsgs;
|
|
31 import dmdscript.dnative;
|
|
32
|
|
33 /* ===================== Dboolean_constructor ==================== */
|
|
34
|
|
35 class Dboolean_constructor : Dfunction
|
|
36 {
|
|
37 this(ThreadContext *tc)
|
|
38 {
|
|
39 super(1, tc.Dfunction_prototype);
|
|
40 name = "Boolean";
|
|
41 }
|
|
42
|
|
43 void *Construct(CallContext *cc, Value *ret, Value[] arglist)
|
|
44 {
|
|
45 // ECMA 15.6.2
|
|
46 d_boolean b;
|
|
47 Dobject o;
|
|
48
|
|
49 b = (arglist.length) ? arglist[0].toBoolean() : false;
|
|
50 o = new Dboolean(b);
|
|
51 ret.putVobject(o);
|
|
52 return null;
|
|
53 }
|
|
54
|
|
55 void *Call(CallContext *cc, Dobject othis, Value* ret, Value[] arglist)
|
|
56 {
|
|
57 // ECMA 15.6.1
|
|
58 d_boolean b;
|
|
59
|
|
60 b = (arglist.length) ? arglist[0].toBoolean() : false;
|
|
61 ret.putVboolean(b);
|
|
62 return null;
|
|
63 }
|
|
64 }
|
|
65
|
|
66
|
|
67 /* ===================== Dboolean_prototype_toString =============== */
|
|
68
|
|
69 void* Dboolean_prototype_toString(Dobject pthis, CallContext *cc, Dobject othis, Value *ret, Value[] arglist)
|
|
70 {
|
|
71 // othis must be a Boolean
|
|
72 if (!othis.isClass(TEXT_Boolean))
|
|
73 {
|
|
74 ErrInfo errinfo;
|
|
75
|
|
76 ret.putVundefined();
|
|
77 return Dobject.RuntimeError(&errinfo, errmsgtbl[ERR_FUNCTION_WANTS_BOOL],
|
|
78 TEXT_toString,
|
|
79 othis.classname);
|
|
80 }
|
|
81 else
|
|
82 { Value *v;
|
|
83
|
|
84 v = &(cast(Dboolean)othis).value;
|
|
85 ret.putVstring(v.toString());
|
|
86 }
|
|
87 return null;
|
|
88 }
|
|
89
|
|
90 /* ===================== Dboolean_prototype_valueOf =============== */
|
|
91
|
|
92 void* Dboolean_prototype_valueOf(Dobject pthis, CallContext *cc, Dobject othis, Value *ret, Value[] arglist)
|
|
93 {
|
|
94 //FuncLog f("Boolean.prototype.valueOf()");
|
|
95 //logflag = 1;
|
|
96
|
|
97 // othis must be a Boolean
|
|
98 if (!othis.isClass(TEXT_Boolean))
|
|
99 {
|
|
100 ErrInfo errinfo;
|
|
101
|
|
102 ret.putVundefined();
|
|
103 return Dobject.RuntimeError(&errinfo, errmsgtbl[ERR_FUNCTION_WANTS_BOOL],
|
|
104 TEXT_valueOf,
|
|
105 othis.classname);
|
|
106 }
|
|
107 else
|
|
108 { Value *v;
|
|
109
|
|
110 v = &(cast(Dboolean)othis).value;
|
|
111 Value.copy(ret, v);
|
|
112 }
|
|
113 return null;
|
|
114 }
|
|
115
|
|
116 /* ===================== Dboolean_prototype ==================== */
|
|
117
|
|
118 class Dboolean_prototype : Dboolean
|
|
119 {
|
|
120 this(ThreadContext *tc)
|
|
121 {
|
|
122 super(tc.Dobject_prototype);
|
|
123 Dobject f = tc.Dfunction_prototype;
|
|
124
|
|
125 Put(TEXT_constructor, tc.Dboolean_constructor, DontEnum);
|
|
126
|
|
127 static NativeFunctionData nfd[] =
|
|
128 [
|
|
129 { &TEXT_toString, &Dboolean_prototype_toString, 0 },
|
|
130 { &TEXT_valueOf, &Dboolean_prototype_valueOf, 0 },
|
|
131 ];
|
|
132
|
|
133 DnativeFunction.init(this, nfd, DontEnum);
|
|
134 }
|
|
135 }
|
|
136
|
|
137
|
|
138 /* ===================== Dboolean ==================== */
|
|
139
|
|
140 class Dboolean : Dobject
|
|
141 {
|
|
142 this(d_boolean b)
|
|
143 {
|
|
144 super(Dboolean.getPrototype());
|
|
145 value.putVboolean(b);
|
|
146 classname = TEXT_Boolean;
|
|
147 }
|
|
148
|
|
149 this(Dobject prototype)
|
|
150 {
|
|
151 super(prototype);
|
|
152 value.putVboolean(false);
|
|
153 classname = TEXT_Boolean;
|
|
154 }
|
|
155
|
|
156 static Dfunction getConstructor()
|
|
157 {
|
|
158 ThreadContext *tc = ThreadContext.getThreadContext();
|
|
159 assert(tc);
|
|
160 return tc.Dboolean_constructor;
|
|
161 }
|
|
162
|
|
163 static Dobject getPrototype()
|
|
164 {
|
|
165 ThreadContext *tc = ThreadContext.getThreadContext();
|
|
166 assert(tc);
|
|
167 return tc.Dboolean_prototype;
|
|
168 }
|
|
169
|
|
170 static void init(ThreadContext *tc)
|
|
171 {
|
|
172 tc.Dboolean_constructor = new Dboolean_constructor(tc);
|
|
173 tc.Dboolean_prototype = new Dboolean_prototype(tc);
|
|
174
|
|
175 tc.Dboolean_constructor.Put(TEXT_prototype, tc.Dboolean_prototype, DontEnum | DontDelete | ReadOnly);
|
|
176 }
|
|
177 }
|
|
178
|