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