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>RangeError</tt>.</p>
026  * <p>An instance of the this class is thrown when a numeric value is not in its legal 
027  * range. For example, setting the length of an array to a negative number causes a 
028  * <tt>RangeError</tt> to be thrown.</p>
029  * <p>In JS, to throw a value or object as a <tt>RuntimeException</tt>, see {@link js.Js#err(Object)}.</p>
030  *
031  * @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>
032  * @see js.Js#err(Object)
033  * 
034  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be 
035  * generated into the target codes. Re-compilers must exit with error on the operations of 
036  * accessing that kind of class objects.
037  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored 
038  * and <tt>instanceof</tt> to it always <tt>true</tt>.
039  */
040 public class JsRangeError extends JsGlobal.RangeError.Prototype
041 {
042     /**
043      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
044      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
045      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
046      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
047      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
048      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
049      * either circumstance, the field names must be exactly same as the member names, as 
050      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
051      * based on the field names.</p>
052      *
053      * @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>
054      * 
055      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created 
056      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
057      * of class objects.
058      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in 
059      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
060      * <pre>q.m</pre>
061      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier 
062      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
063      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
064      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
065      * <pre>m</pre>
066      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report 
067      * error on the access to <b>opaque</b> fields declared by this class under any other 
068      * circumstances.
069      */
070     public static class Member extends JsGlobal.RangeError.Prototype.Member
071     {
072         /**
073          * <p>Internally constructs a member based on a qualifying member.</p>
074          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
075          * or <b>internal</b> classes or class members.</p>
076          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
077          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
078          * declared in the declaring class of this constructor itself or its subclasses. 
079          * Under this circumstance, the field names must be exactly same as the member 
080          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
081          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly 
082          * to their names appending to the name resolved from the specified qualifying 
083          * member with a dot in between.</p>
084          * @param q A qualifying member
085          * @param mid The ID of the member to construct
086          * @since 1.0
087          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
088          */
089         public Member(JsObject.Member q, Mid mid) {
090             super(q, mid);
091         }
092         /**
093          * <p>Internally constructs a member without a qualifying member.</p>
094          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
095          * or <b>internal</b> classes or class members.</p>
096          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
097          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
098          * declared in <b>opaque</b> types other than the declaring class of this constructor 
099          * itself and its subclasses. Under this circumstance, the field names must be 
100          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b> 
101          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
102          * @param mid The ID of the member to construct
103          * @since 1.0
104          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
105          */
106         public Member(Mid mid) {
107             super(mid);
108         }
109         /**
110          * <p>Evaluates the property, represented by the current member instance, of the 
111          * argument object.</p>
112          * @param o The argument object
113          * @return The value of the current member based on the object argument.
114          * @since 1.0
115          * @javascript Re-compilers must convert the instance invocation of this method into 
116          * the JavaScript expression: 
117          * <pre>o.m</pre>
118          * where <tt>m</tt> is the identifier name resolved from the current member 
119          * instance of the invocation.
120          */
121         @Override
122         public JsRangeError with(ObjectLike o) {
123             return new JsRangeError(super.with(o));
124         }
125 
126         /**
127          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the 
128          * name of this field, qualified by the current member instance of the field, and 
129          * to access the property of the name on an object.</p>
130          * <p>The <tt>constructor</tt> property of an object is a reference to the function 
131          * that was the constructor for that object.</p>
132          * <p>A common use of the <tt>constructor</tt> property is to determine the type of unknown 
133          * objects. Given an unknown value, you can use the {@link js.Js#typeof(Object)} operation 
134          * to determine whether it is a primitive value or an object. If it is an object, you can 
135          * use the <tt>constructor</tt> property to determine what type of object it is.</p>
136          * <p>Note, however, that while this technique works for the objects built into core 
137          * JavaScript, it is not guaranteed to work with host objects such as the <tt>window</tt> 
138          * object of client-side JavaScript. The default implementation of the <tt>toString()</tt> 
139          * method provides another way to determine the type of an unknown object.</p>
140          * @since 1.0
141          * @javascript Re-compilers must resolve the member of this instance field to the 
142          * identifier of the field name appending to the identifier resolved from its 
143          * qualifying member with a dot in between.
144          */
145         public final JsFunction.Member<JsRangeError> constructor = new JsFunction.Member<JsRangeError>(this, Members.constructor, Generic.get(JsRangeError.class));
146     }
147 
148     /**
149      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it 
150      * with the wrapping constructor.</p>
151      * @param var The argument of an <b>opaque</b> object.
152      * @since 1.0
153      * @javascript Re-compilers must ignore the construction operation of this constructor, 
154      * that is, replacing it with its only argument.
155      */
156     public JsRangeError(JsObject var) {
157         super(var);
158     }
159 
160     /**
161      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
162      * without a qualifying member and to access the property of the name on an object.</p>
163      * <p>The <tt>constructor</tt> property of an object is a reference to the function 
164      * that was the constructor for that object.</p>
165      * <p>A common use of the <tt>constructor</tt> property is to determine the type of unknown 
166      * objects. Given an unknown value, you can use the {@link js.Js#typeof(Object)} operation 
167      * to determine whether it is a primitive value or an object. If it is an object, you can 
168      * use the <tt>constructor</tt> property to determine what type of object it is.</p>
169      * <p>Note, however, that while this technique works for the objects built into core 
170      * JavaScript, it is not guaranteed to work with host objects such as the <tt>window</tt> 
171      * object of client-side JavaScript. The default implementation of the <tt>toString()</tt> 
172      * method provides another way to determine the type of an unknown object.</p>
173      * @since 1.0
174      * @javascript Re-compilers must resolve the member of this static field to the 
175      * identifier of the field name.
176      */
177     public static final JsFunction.Member<JsRangeError> constructor = new JsFunction.Member<JsRangeError>(Members.constructor, Generic.get(JsRangeError.class));
178 
179     /**
180      * <p>Returns the primitive value associated with the current instance, if there is one. 
181      * This invocation simply returns the instance itself for the current instance is an 
182      * object and there is no primitive value for it.</p>
183      * @return The current object itself.
184      * @since 1.0
185      * @javascript Re-compilers must convert the instance invocation of this method directly 
186      * into a JavaScript invocation on its current object instance without changing the 
187      * method name, but expanding variable arguments, if any, into comma-separated values. 
188      */
189     @Override
190     public JsRangeError valueOf() {
191         return new JsRangeError((JsObject)var().valueOf());
192     }
193 }