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