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