001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package js.core;
021 
022 import js.ObjectLike;
023 
024 /**
025  * <p>An <b>opaque</b> class representing JavaScript <tt>TypeError</tt>.</p>
026  * <p>In JavaScript, an instance of the <tt>TypeError</tt> class is thrown when a value is not 
027  * of the type expected. This happens most often when you attempt to access a property of a 
028  * <tt>null</tt> or <tt>undefined</tt> value. It can also occur if you invoke a method defined 
029  * by one class on an object that is an instance of some other class, or if you use the <tt>new</tt> 
030  * operator with a value that is not a constructor function, for example. JavaScript implementations 
031  * are also permitted to throw <tt>TypeError</tt> objects when a built-in function or method 
032  * is called with more arguments than expected.</p>
033  * <p>In JS, to throw a value or object as a <tt>RuntimeException</tt>, see {@link js.Js#err(Object)}.</p>
034  *
035  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
036  * @see js.Js#err(Object)
037  * 
038  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be 
039  * generated into the target codes. Re-compilers must exit with error on the operations of 
040  * accessing that kind of class objects.
041  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored 
042  * and <tt>instanceof</tt> to it always <tt>true</tt>.
043  */
044 public class JsTypeError extends JsGlobal.TypeError.Prototype
045 {
046     /**
047      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
048      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
049      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
050      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
051      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
052      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
053      * either circumstance, the field names must be exactly same as the member names, as 
054      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
055      * based on the field names.</p>
056      *
057      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
058      * 
059      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created 
060      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
061      * of class objects.
062      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in 
063      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
064      * <pre>q.m</pre>
065      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier 
066      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
067      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
068      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
069      * <pre>m</pre>
070      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report 
071      * error on the access to <b>opaque</b> fields declared by this class under any other 
072      * circumstances.
073      */
074     public static class Member extends JsGlobal.TypeError.Prototype.Member
075     {
076         /**
077          * <p>Internally constructs a member based on a qualifying member.</p>
078          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
079          * or <b>internal</b> classes or class members.</p>
080          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
081          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
082          * declared in the declaring class of this constructor itself or its subclasses. 
083          * Under this circumstance, the field names must be exactly same as the member 
084          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
085          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly 
086          * to their names appending to the name resolved from the specified qualifying 
087          * member with a dot in between.</p>
088          * @param q A qualifying member
089          * @param mid The ID of the member to construct
090          * @since 1.0
091          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
092          */
093         public Member(JsObject.Member q, Mid mid) {
094             super(q, mid);
095         }
096         /**
097          * <p>Internally constructs a member without a qualifying member.</p>
098          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
099          * or <b>internal</b> classes or class members.</p>
100          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
101          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
102          * declared in <b>opaque</b> types other than the declaring class of this constructor 
103          * itself and its subclasses. Under this circumstance, the field names must be 
104          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b> 
105          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
106          * @param mid The ID of the member to construct
107          * @since 1.0
108          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
109          */
110         public Member(Mid mid) {
111             super(mid);
112         }
113         /**
114          * <p>Evaluates the property, represented by the current member instance, of the 
115          * argument object.</p>
116          * @param o The argument object
117          * @return The value of the current member based on the object argument.
118          * @since 1.0
119          * @javascript Re-compilers must convert the instance invocation of this method into 
120          * the JavaScript expression: 
121          * <pre>o.m</pre>
122          * where <tt>m</tt> is the identifier name resolved from the current member 
123          * instance of the invocation.
124          */
125         @Override
126         public JsTypeError with(ObjectLike o) {
127             return new JsTypeError(super.with(o));
128         }
129 
130         /**
131          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the 
132          * name of this field, qualified by the current member instance of the field, and 
133          * to access the property of the name on an object.</p>
134          * <p>The <tt>constructor</tt> property of an object is a reference to the function 
135          * that was the constructor for that object.</p>
136          * <p>A common use of the <tt>constructor</tt> property is to determine the type of unknown 
137          * objects. Given an unknown value, you can use the {@link js.Js#typeof(Object)} operation 
138          * to determine whether it is a primitive value or an object. If it is an object, you can 
139          * use the <tt>constructor</tt> property to determine what type of object it is.</p>
140          * <p>Note, however, that while this technique works for the objects built into core 
141          * JavaScript, it is not guaranteed to work with host objects such as the <tt>window</tt> 
142          * object of client-side JavaScript. The default implementation of the <tt>toString()</tt> 
143          * method provides another way to determine the type of an unknown object.</p>
144          * @since 1.0
145          * @javascript Re-compilers must resolve the member of this instance field to the 
146          * identifier of the field name appending to the identifier resolved from its 
147          * qualifying member with a dot in between.
148          */
149         public final JsFunction.Member<JsTypeError> constructor = new JsFunction.Member<JsTypeError>(this, Members.constructor, Generic.get(JsTypeError.class));
150     }
151 
152     /**
153      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it 
154      * with the wrapping constructor.</p>
155      * @param var The argument of an <b>opaque</b> object.
156      * @since 1.0
157      * @javascript Re-compilers must ignore the construction operation of this constructor, 
158      * that is, replacing it with its only argument.
159      */
160     public JsTypeError(JsObject var) {
161         super(var);
162     }
163 
164     /**
165      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
166      * without a qualifying member and to access the property of the name on an object.</p>
167      * <p>The <tt>constructor</tt> property of an object is a reference to the function 
168      * that was the constructor for that object.</p>
169      * <p>A common use of the <tt>constructor</tt> property is to determine the type of unknown 
170      * objects. Given an unknown value, you can use the {@link js.Js#typeof(Object)} operation 
171      * to determine whether it is a primitive value or an object. If it is an object, you can 
172      * use the <tt>constructor</tt> property to determine what type of object it is.</p>
173      * <p>Note, however, that while this technique works for the objects built into core 
174      * JavaScript, it is not guaranteed to work with host objects such as the <tt>window</tt> 
175      * object of client-side JavaScript. The default implementation of the <tt>toString()</tt> 
176      * method provides another way to determine the type of an unknown object.</p>
177      * @since 1.0
178      * @javascript Re-compilers must resolve the member of this static field to the 
179      * identifier of the field name.
180      */
181     public static final JsFunction.Member<JsTypeError> constructor = new JsFunction.Member<JsTypeError>(Members.constructor, Generic.get(JsTypeError.class));
182 
183     /**
184      * <p>Returns the primitive value associated with the current instance, if there is one. 
185      * This invocation simply returns the instance itself for the current instance is an 
186      * object and there is no primitive value for it.</p>
187      * @return The current object itself.
188      * @since 1.0
189      * @javascript Re-compilers must convert the instance invocation of this method directly 
190      * into a JavaScript invocation on its current object instance without changing the 
191      * method name, but expanding variable arguments, if any, into comma-separated values. 
192      */
193     @Override
194     public JsTypeError valueOf() {
195         return new JsTypeError((JsObject)var().valueOf());
196     }
197 }