KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > js > rhino > Context


1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * The contents of this file are subject to the Netscape Public
4  * License Version 1.1 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of
6  * the License at http://www.mozilla.org/NPL/
7  *
8  * Software distributed under the License is distributed on an "AS
9  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10  * implied. See the License for the specific language governing
11  * rights and limitations under the License.
12  *
13  * The Original Code is Rhino code, released
14  * May 6, 1999.
15  *
16  * The Initial Developer of the Original Code is Netscape
17  * Communications Corporation. Portions created by Netscape are
18  * Copyright (C) 1997-2000 Netscape Communications Corporation. All
19  * Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * Patrick Beard
24  * Norris Boyd
25  * Igor Bukanov
26  * Brendan Eich
27  * Roger Lawrence
28  * Mike McCabe
29  * Ian D. Stewart
30  * Andi Vajda
31  * Andrew Wason
32  * Kemal Bayram
33  *
34  * Alternatively, the contents of this file may be used under the
35  * terms of the GNU Public License (the "GPL"), in which case the
36  * provisions of the GPL are applicable instead of those above.
37  * If you wish to allow use of your version of this file only
38  * under the terms of the GPL and not to allow others to use your
39  * version of this file under the NPL, indicate your decision by
40  * deleting the provisions above and replace them with the notice
41  * and other provisions required by the GPL. If you do not delete
42  * the provisions above, a recipient may use your version of this
43  * file under either the NPL or the GPL.
44  */

45 // Modified by Google
46

47 // API class
48

49 package com.google.gwt.dev.js.rhino;
50
51 import java.beans.PropertyChangeEvent JavaDoc;
52 import java.beans.PropertyChangeListener JavaDoc;
53 import java.lang.reflect.Method JavaDoc;
54 import java.text.MessageFormat JavaDoc;
55 import java.util.Hashtable JavaDoc;
56 import java.util.Locale JavaDoc;
57 import java.util.ResourceBundle JavaDoc;
58
59 /**
60  * This class represents the runtime context of an executing script.
61  *
62  * Before executing a script, an instance of Context must be created
63  * and associated with the thread that will be executing the script.
64  * The Context will be used to store information about the executing
65  * of the script such as the call stack. Contexts are associated with
66  * the current thread using the <a HREF="#enter()">enter()</a> method.<p>
67  *
68  * The behavior of the execution engine may be altered through methods
69  * such as <a HREF="#setLanguageVersion>setLanguageVersion</a> and
70  * <a HREF="#setErrorReporter>setErrorReporter</a>.<p>
71  *
72  * Different forms of script execution are supported. Scripts may be
73  * evaluated from the source directly, or first compiled and then later
74  * executed. Interactive execution is also supported.<p>
75  *
76  * Some aspects of script execution, such as type conversions and
77  * object creation, may be accessed directly through methods of
78  * Context.
79  *
80  * @see Scriptable
81  * @author Norris Boyd
82  * @author Brendan Eich
83  */

84
85 public class Context {
86     public static final String JavaDoc languageVersionProperty = "language version";
87     public static final String JavaDoc errorReporterProperty = "error reporter";
88
89     /**
90      * Create a new Context.
91      *
92      * Note that the Context must be associated with a thread before
93      * it can be used to execute a script.
94      *
95      * @see org.mozilla.javascript.Context#enter
96      */

97     public Context() {
98         setLanguageVersion(VERSION_DEFAULT);
99     }
100
101     /**
102      * Get a context associated with the current thread, creating
103      * one if need be.
104      *
105      * The Context stores the execution state of the JavaScript
106      * engine, so it is required that the context be entered
107      * before execution may begin. Once a thread has entered
108      * a Context, then getCurrentContext() may be called to find
109      * the context that is associated with the current thread.
110      * <p>
111      * Calling <code>enter()</code> will
112      * return either the Context currently associated with the
113      * thread, or will create a new context and associate it
114      * with the current thread. Each call to <code>enter()</code>
115      * must have a matching call to <code>exit()</code>. For example,
116      * <pre>
117      * Context cx = Context.enter();
118      * try {
119      * ...
120      * cx.evaluateString(...);
121      * }
122      * finally { Context.exit(); }
123      * </pre>
124      * @return a Context associated with the current thread
125      * @see org.mozilla.javascript.Context#getCurrentContext
126      * @see org.mozilla.javascript.Context#exit
127      */

128     public static Context enter() {
129         return enter(null);
130     }
131
132     /**
133      * Get a Context associated with the current thread, using
134      * the given Context if need be.
135      * <p>
136      * The same as <code>enter()</code> except that <code>cx</code>
137      * is associated with the current thread and returned if
138      * the current thread has no associated context and <code>cx</code>
139      * is not associated with any other thread.
140      * @param cx a Context to associate with the thread if possible
141      * @return a Context associated with the current thread
142      */

143     public static Context enter(Context cx) {
144
145         Context old = getCurrentContext();
146
147         if (cx == null) {
148             if (old != null) {
149                 cx = old;
150             } else {
151                 cx = new Context();
152                 setThreadContext(cx);
153             }
154         } else {
155             if (cx.enterCount != 0) {
156                 // The suplied context must be the context for
157
// the current thread if it is already entered
158
if (cx != old) {
159                     throw new RuntimeException JavaDoc
160                         ("Cannot enter Context active on another thread");
161                 }
162             } else {
163                 if (old != null) {
164                     cx = old;
165                 } else {
166                     setThreadContext(cx);
167                 }
168             }
169         }
170
171         ++cx.enterCount;
172
173         return cx;
174      }
175
176     /**
177      * Exit a block of code requiring a Context.
178      *
179      * Calling <code>exit()</code> will remove the association between
180      * the current thread and a Context if the prior call to
181      * <code>enter()</code> on this thread newly associated a Context
182      * with this thread.
183      * Once the current thread no longer has an associated Context,
184      * it cannot be used to execute JavaScript until it is again associated
185      * with a Context.
186      *
187      * @see org.mozilla.javascript.Context#enter
188      */

189     public static void exit() {
190         boolean released = false;
191         Context cx = getCurrentContext();
192         if (cx == null) {
193             throw new RuntimeException JavaDoc
194                 ("Calling Context.exit without previous Context.enter");
195         }
196         if (Context.check && cx.enterCount < 1) Context.codeBug();
197         --cx.enterCount;
198         if (cx.enterCount == 0) {
199             released = true;
200             setThreadContext(null);
201         }
202     }
203
204     /**
205      * Get the current Context.
206      *
207      * The current Context is per-thread; this method looks up
208      * the Context associated with the current thread. <p>
209      *
210      * @return the Context associated with the current thread, or
211      * null if no context is associated with the current
212      * thread.
213      * @see org.mozilla.javascript.Context#enter
214      * @see org.mozilla.javascript.Context#exit
215      */

216     public static Context getCurrentContext() {
217         if (threadLocalCx != null) {
218             try {
219                 return (Context)threadLocalGet.invoke(threadLocalCx, (Object JavaDoc[]) null);
220             } catch (Exception JavaDoc ex) { }
221         }
222         Thread JavaDoc t = Thread.currentThread();
223         return (Context) threadContexts.get(t);
224     }
225
226     private static void setThreadContext(Context cx) {
227         if (threadLocalCx != null) {
228             try {
229                 threadLocalSet.invoke(threadLocalCx, new Object JavaDoc[] { cx });
230                 return;
231             } catch (Exception JavaDoc ex) { }
232         }
233         Thread JavaDoc t = Thread.currentThread();
234         if (cx != null) {
235             threadContexts.put(t, cx);
236         } else {
237             threadContexts.remove(t);
238         }
239     }
240
241     /**
242      * Language versions
243      *
244      * All integral values are reserved for future version numbers.
245      */

246
247     /**
248      * The unknown version.
249      */

250     public static final int VERSION_UNKNOWN = -1;
251
252     /**
253      * The default version.
254      */

255     public static final int VERSION_DEFAULT = 0;
256
257     /**
258      * JavaScript 1.0
259      */

260     public static final int VERSION_1_0 = 100;
261
262     /**
263      * JavaScript 1.1
264      */

265     public static final int VERSION_1_1 = 110;
266
267     /**
268      * JavaScript 1.2
269      */

270     public static final int VERSION_1_2 = 120;
271
272     /**
273      * JavaScript 1.3
274      */

275     public static final int VERSION_1_3 = 130;
276
277     /**
278      * JavaScript 1.4
279      */

280     public static final int VERSION_1_4 = 140;
281
282     /**
283      * JavaScript 1.5
284      */

285     public static final int VERSION_1_5 = 150;
286
287     /**
288      * Get the current language version.
289      * <p>
290      * The language version number affects JavaScript semantics as detailed
291      * in the overview documentation.
292      *
293      * @return an integer that is one of VERSION_1_0, VERSION_1_1, etc.
294      */

295     public int getLanguageVersion() {
296        return version;
297     }
298
299     /**
300      * Set the language version.
301      *
302      * <p>
303      * Setting the language version will affect functions and scripts compiled
304      * subsequently. See the overview documentation for version-specific
305      * behavior.
306      *
307      * @param version the version as specified by VERSION_1_0, VERSION_1_1, etc.
308      */

309     public void setLanguageVersion(int version) {
310         this.version = version;
311     }
312
313     /**
314      * Get the implementation version.
315      *
316      * <p>
317      * The implementation version is of the form
318      * <pre>
319      * "<i>name langVer</i> <code>release</code> <i>relNum date</i>"
320      * </pre>
321      * where <i>name</i> is the name of the product, <i>langVer</i> is
322      * the language version, <i>relNum</i> is the release number, and
323      * <i>date</i> is the release date for that specific
324      * release in the form "yyyy mm dd".
325      *
326      * @return a string that encodes the product, language version, release
327      * number, and date.
328      */

329      public String JavaDoc getImplementationVersion() {
330         return "Rhino 1.5 release 4.1 2003 04 21";
331      }
332
333     /**
334      * Get the current error reporter.
335      *
336      * @see org.mozilla.javascript.ErrorReporter
337      */

338     public ErrorReporter getErrorReporter() {
339         return errorReporter;
340     }
341
342     /**
343      * Change the current error reporter.
344      *
345      * @return the previous error reporter
346      * @see org.mozilla.javascript.ErrorReporter
347      */

348     public ErrorReporter setErrorReporter(ErrorReporter reporter) {
349         errorReporter = reporter;
350         return reporter;
351     }
352
353     /**
354      * Get the current locale. Returns the default locale if none has
355      * been set.
356      *
357      * @see java.util.Locale
358      */

359
360     public Locale JavaDoc getLocale() {
361         if (locale == null)
362             locale = Locale.getDefault();
363         return locale;
364     }
365
366     /**
367      * Set the current locale.
368      *
369      * @see java.util.Locale
370      */

371     public Locale JavaDoc setLocale(Locale JavaDoc loc) {
372         Locale JavaDoc result = locale;
373         locale = loc;
374         return result;
375     }
376
377     /**
378      * Notify any registered listeners that a bounded property has changed
379      * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)
380      * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)
381      * @see java.beans.PropertyChangeListener
382      * @see java.beans.PropertyChangeEvent
383      * @param property the bound property
384      * @param oldValue the old value
385      * @param newVale the new value
386      */

387     void firePropertyChange(String JavaDoc property, Object JavaDoc oldValue,
388                             Object JavaDoc newValue)
389     {
390         Object JavaDoc[] array = listeners;
391         if (array != null) {
392             firePropertyChangeImpl(array, property, oldValue, newValue);
393         }
394     }
395
396     private void firePropertyChangeImpl(Object JavaDoc[] array, String JavaDoc property,
397                                         Object JavaDoc oldValue, Object JavaDoc newValue)
398     {
399         for (int i = array.length; i-- != 0;) {
400             Object JavaDoc obj = array[i];
401             if (obj instanceof PropertyChangeListener JavaDoc) {
402                 PropertyChangeListener JavaDoc l = (PropertyChangeListener JavaDoc)obj;
403                 l.propertyChange(new PropertyChangeEvent JavaDoc(
404                     this, property, oldValue, newValue));
405             }
406     }
407     }
408
409     /**
410      * Report a warning using the error reporter for the current thread.
411      *
412      * @param message the warning message to report
413      * @param sourceName a string describing the source, such as a filename
414      * @param lineno the starting line number
415      * @param lineSource the text of the line (may be null)
416      * @param lineOffset the offset into lineSource where problem was detected
417      * @see org.mozilla.javascript.ErrorReporter
418      */

419     public static void reportWarning(String JavaDoc message, String JavaDoc sourceName,
420                                      int lineno, String JavaDoc lineSource,
421                                      int lineOffset)
422     {
423         Context cx = Context.getContext();
424         cx.getErrorReporter().warning(message, sourceName, lineno,
425                                       lineSource, lineOffset);
426     }
427
428     /**
429      * Report a warning using the error reporter for the current thread.
430      *
431      * @param message the warning message to report
432      * @see org.mozilla.javascript.ErrorReporter
433      */

434     /*
435     public static void reportWarning(String message) {
436         int[] linep = { 0 };
437         String filename = getSourcePositionFromStack(linep);
438         Context.reportWarning(message, filename, linep[0], null, 0);
439     }
440     */

441
442     /**
443      * Report an error using the error reporter for the current thread.
444      *
445      * @param message the error message to report
446      * @param sourceName a string describing the source, such as a filename
447      * @param lineno the starting line number
448      * @param lineSource the text of the line (may be null)
449      * @param lineOffset the offset into lineSource where problem was detected
450      * @see org.mozilla.javascript.ErrorReporter
451      */

452     public static void reportError(String JavaDoc message, String JavaDoc sourceName,
453                                    int lineno, String JavaDoc lineSource,
454                                    int lineOffset)
455     {
456         Context cx = getCurrentContext();
457         if (cx != null) {
458             cx.errorCount++;
459             cx.getErrorReporter().error(message, sourceName, lineno,
460                                         lineSource, lineOffset);
461         } else {
462             throw new EvaluatorException(message);
463         }
464     }
465
466     /**
467      * Report an error using the error reporter for the current thread.
468      *
469      * @param message the error message to report
470      * @see org.mozilla.javascript.ErrorReporter
471      */

472     /*
473     public static void reportError(String message) {
474         int[] linep = { 0 };
475         String filename = getSourcePositionFromStack(linep);
476         Context.reportError(message, filename, linep[0], null, 0);
477     }
478     */

479
480     /**
481      * Report a runtime error using the error reporter for the current thread.
482      *
483      * @param message the error message to report
484      * @param sourceName a string describing the source, such as a filename
485      * @param lineno the starting line number
486      * @param lineSource the text of the line (may be null)
487      * @param lineOffset the offset into lineSource where problem was detected
488      * @return a runtime exception that will be thrown to terminate the
489      * execution of the script
490      * @see org.mozilla.javascript.ErrorReporter
491      */

492     /*
493     public static EvaluatorException reportRuntimeError(String message,
494                                                       String sourceName,
495                                                       int lineno,
496                                                       String lineSource,
497                                                       int lineOffset)
498     {
499         Context cx = getCurrentContext();
500         if (cx != null) {
501             cx.errorCount++;
502             return cx.getErrorReporter().
503                             runtimeError(message, sourceName, lineno,
504                                          lineSource, lineOffset);
505         } else {
506             throw new EvaluatorException(message);
507         }
508     }
509
510     static EvaluatorException reportRuntimeError0(String messageId) {
511         return reportRuntimeError(getMessage0(messageId));
512     }
513
514     static EvaluatorException reportRuntimeError1
515         (String messageId, Object arg1)
516     {
517         return reportRuntimeError(getMessage1(messageId, arg1));
518     }
519
520     static EvaluatorException reportRuntimeError2
521         (String messageId, Object arg1, Object arg2)
522     {
523         return reportRuntimeError(getMessage2(messageId, arg1, arg2));
524     }
525
526     static EvaluatorException reportRuntimeError3
527         (String messageId, Object arg1, Object arg2, Object arg3)
528     {
529         return reportRuntimeError(getMessage3(messageId, arg1, arg2, arg3));
530     }
531     */

532
533     /**
534      * Report a runtime error using the error reporter for the current thread.
535      *
536      * @param message the error message to report
537      * @see org.mozilla.javascript.ErrorReporter
538      */

539     /*
540     public static EvaluatorException reportRuntimeError(String message) {
541         int[] linep = { 0 };
542         String filename = getSourcePositionFromStack(linep);
543         return Context.reportRuntimeError(message, filename, linep[0], null, 0);
544     }
545     */

546
547     /**
548      * Get a value corresponding to a key.
549      * <p>
550      * Since the Context is associated with a thread it can be
551      * used to maintain values that can be later retrieved using
552      * the current thread.
553      * <p>
554      * Note that the values are maintained with the Context, so
555      * if the Context is disassociated from the thread the values
556      * cannot be retreived. Also, if private data is to be maintained
557      * in this manner the key should be a java.lang.Object
558      * whose reference is not divulged to untrusted code.
559      * @param key the key used to lookup the value
560      * @return a value previously stored using putThreadLocal.
561      */

562     public final Object JavaDoc getThreadLocal(Object JavaDoc key) {
563         if (hashtable == null)
564             return null;
565         return hashtable.get(key);
566     }
567
568     /**
569      * Put a value that can later be retrieved using a given key.
570      * <p>
571      * @param key the key used to index the value
572      * @param value the value to save
573      */

574     public void putThreadLocal(Object JavaDoc key, Object JavaDoc value) {
575         if (hashtable == null)
576             hashtable = new Hashtable JavaDoc();
577         hashtable.put(key, value);
578     }
579
580     /**
581      * Remove values from thread-local storage.
582      * @param key the key for the entry to remove.
583      * @since 1.5 release 2
584      */

585     public void removeThreadLocal(Object JavaDoc key) {
586         if (hashtable == null)
587             return;
588         hashtable.remove(key);
589     }
590
591     /**
592      * Return whether functions are compiled by this context using
593      * dynamic scope.
594      * <p>
595      * If functions are compiled with dynamic scope, then they execute
596      * in the scope of their caller, rather than in their parent scope.
597      * This is useful for sharing functions across multiple scopes.
598      * @since 1.5 Release 1
599      */

600     public final boolean hasCompileFunctionsWithDynamicScope() {
601         return compileFunctionsWithDynamicScopeFlag;
602     }
603
604     /**
605      * Set whether functions compiled by this context should use
606      * dynamic scope.
607      * <p>
608      * @param flag if true, compile functions with dynamic scope
609      * @since 1.5 Release 1
610      */

611     public void setCompileFunctionsWithDynamicScope(boolean flag) {
612         compileFunctionsWithDynamicScopeFlag = flag;
613     }
614
615     /**
616      * if hasFeature(FEATURE_NON_ECMA_GET_YEAR) returns true,
617      * Date.prototype.getYear subtructs 1900 only if 1900 <= date < 2000
618      * in deviation with Ecma B.2.4
619      */

620     public static final int FEATURE_NON_ECMA_GET_YEAR = 1;
621
622     /**
623      * if hasFeature(FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME) returns true,
624      * allow 'function <MemberExpression>(...) { ... }' to be syntax sugar for
625      * '<MemberExpression> = function(...) { ... }', when <MemberExpression>
626      * is not simply identifier.
627      * See Ecma-262, section 11.2 for definition of <MemberExpression>
628      */

629     public static final int FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME = 2;
630
631     /**
632      * if hasFeature(RESERVED_KEYWORD_AS_IDENTIFIER) returns true,
633      * treat future reserved keyword (see Ecma-262, section 7.5.3) as ordinary
634      * identifiers but warn about this usage
635      */

636     public static final int FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER = 3;
637
638     /**
639      * if hasFeature(FEATURE_TO_STRING_AS_SOURCE) returns true,
640      * calling toString on JS objects gives JS source with code to create an
641      * object with all enumeratable fields of the original object instead of
642      * printing "[object <object-type>]".
643      * By default {@link #hasFeature(int)} returns true only if
644      * the current JS version is set to {@link #VERSION_1_2}.
645      */

646     public static final int FEATURE_TO_STRING_AS_SOURCE = 4;
647
648     /**
649      * Controls certain aspects of script semantics.
650      * Should be overwritten to alter default behavior.
651      * @param featureIndex feature index to check
652      * @return true if the <code>featureIndex</code> feature is turned on
653      * @see #FEATURE_NON_ECMA_GET_YEAR
654      * @see #FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME
655      * @see #FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER
656      * @see #FEATURE_TO_STRING_AS_SOURCE
657      */

658     public boolean hasFeature(int featureIndex) {
659         switch (featureIndex) {
660             case FEATURE_NON_ECMA_GET_YEAR:
661                /*
662                 * During the great date rewrite of 1.3, we tried to track the
663                 * evolving ECMA standard, which then had a definition of
664                 * getYear which always subtracted 1900. Which we
665                 * implemented, not realizing that it was incompatible with
666                 * the old behavior... now, rather than thrash the behavior
667                 * yet again, we've decided to leave it with the - 1900
668                 * behavior and point people to the getFullYear method. But
669                 * we try to protect existing scripts that have specified a
670                 * version...
671                 */

672                 return (version == Context.VERSION_1_0
673                         || version == Context.VERSION_1_1
674                         || version == Context.VERSION_1_2);
675
676             case FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME:
677                 return false;
678
679             case FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER:
680                 return false;
681
682             case FEATURE_TO_STRING_AS_SOURCE:
683                 return version == VERSION_1_2;
684         }
685         // It is a bug to call the method with unknown featureIndex
686
throw new IllegalArgumentException JavaDoc();
687     }
688
689     /********** end of API **********/
690
691     static String JavaDoc getMessage0(String JavaDoc messageId) {
692         return getMessage(messageId, null);
693     }
694
695     static String JavaDoc getMessage1(String JavaDoc messageId, Object JavaDoc arg1) {
696         Object JavaDoc[] arguments = {arg1};
697         return getMessage(messageId, arguments);
698     }
699
700     static String JavaDoc getMessage2(String JavaDoc messageId, Object JavaDoc arg1, Object JavaDoc arg2) {
701         Object JavaDoc[] arguments = {arg1, arg2};
702         return getMessage(messageId, arguments);
703     }
704
705     static String JavaDoc getMessage3
706         (String JavaDoc messageId, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3) {
707         Object JavaDoc[] arguments = {arg1, arg2, arg3};
708         return getMessage(messageId, arguments);
709     }
710     /**
711      * Internal method that reports an error for missing calls to
712      * enter().
713      */

714     static Context getContext() {
715         Context cx = getCurrentContext();
716         if (cx == null) {
717             throw new RuntimeException JavaDoc(
718                 "No Context associated with current Thread");
719         }
720         return cx;
721     }
722
723     /* OPT there's a noticable delay for the first error! Maybe it'd
724      * make sense to use a ListResourceBundle instead of a properties
725      * file to avoid (synchronized) text parsing.
726      */

727     // bruce: removed referenced to the initial "java" package name
728
// that used to be there due to a build artifact
729
static final String JavaDoc defaultResource =
730       "com.google.gwt.dev.js.rhino.Messages";
731     
732
733     static String JavaDoc getMessage(String JavaDoc messageId, Object JavaDoc[] arguments) {
734         Context cx = getCurrentContext();
735         Locale JavaDoc locale = cx != null ? cx.getLocale() : Locale.getDefault();
736
737         // ResourceBundle does cacheing.
738
ResourceBundle JavaDoc rb = ResourceBundle.getBundle(defaultResource, locale);
739
740         String JavaDoc formatString;
741         try {
742             formatString = rb.getString(messageId);
743         } catch (java.util.MissingResourceException JavaDoc mre) {
744             throw new RuntimeException JavaDoc
745                 ("no message resource found for message property "+ messageId);
746         }
747
748         /*
749          * It's OK to format the string, even if 'arguments' is null;
750          * we need to format it anyway, to make double ''s collapse to
751          * single 's.
752          */

753         // TODO: MessageFormat is not available on pJava
754
MessageFormat JavaDoc formatter = new MessageFormat JavaDoc(formatString);
755         return formatter.format(arguments);
756     }
757
758     // debug flags
759
static final boolean printTrees = true;
760     static final boolean printICode = true;
761
762     final boolean isVersionECMA1() {
763         return version == VERSION_DEFAULT || version >= VERSION_1_3;
764     }
765
766
767 // Rudimentary support for Design-by-Contract
768
static void codeBug() {
769         throw new RuntimeException JavaDoc("FAILED ASSERTION");
770     }
771
772     static final boolean check = true;
773
774     private static Hashtable JavaDoc threadContexts = new Hashtable JavaDoc(11);
775     private static Object JavaDoc threadLocalCx;
776     private static Method JavaDoc threadLocalGet;
777     private static Method JavaDoc threadLocalSet;
778
779     int version;
780     int errorCount;
781
782     private ErrorReporter errorReporter;
783     private Locale JavaDoc locale;
784     private boolean generatingDebug;
785     private boolean generatingDebugChanged;
786     private boolean generatingSource=true;
787     private boolean compileFunctionsWithDynamicScopeFlag;
788     private int enterCount;
789     private Object JavaDoc[] listeners;
790     private Hashtable JavaDoc hashtable;
791     private ClassLoader JavaDoc applicationClassLoader;
792
793     /**
794      * This is the list of names of objects forcing the creation of
795      * function activation records.
796      */

797     private Hashtable JavaDoc activationNames;
798
799     // For instruction counting (interpreter only)
800
int instructionCount;
801     int instructionThreshold;
802 }
803
Popular Tags