Added setters for properties of CompilerEnvirons.java so it can be initialized

without having Context object.
This commit is contained in:
igor%mir2.org 2004-01-16 16:09:07 +00:00
parent 7cb00076c5
commit 0fc143dd7c
2 changed files with 55 additions and 10 deletions

View File

@ -38,7 +38,7 @@
package org.mozilla.javascript;
public final class CompilerEnvirons
public class CompilerEnvirons
{
public void initFromContext(Context cx, ErrorReporter syntaxErrorReporter)
{
@ -104,21 +104,43 @@ public final class CompilerEnvirons
return languageVersion;
}
public void setLanguageVersion(int languageVersion)
{
Context.checkLanguageVersion(languageVersion);
this.languageVersion = languageVersion;
}
public final boolean isGenerateDebugInfo()
{
return generateDebugInfo;
}
public void setGenerateDebugInfo(boolean flag)
{
this.generateDebugInfo = flag;
}
public final boolean isUseDynamicScope()
{
return useDynamicScope;
}
public void setUseDynamicScope(boolean flag)
{
this.useDynamicScope = flag;
}
public final int getOptimizationLevel()
{
return optimizationLevel;
}
public void setOptimizationLevel(int level)
{
Context.checkOptimizationLevel(level);
this.optimizationLevel = level;
}
private ErrorReporter syntaxErrorReporter;
private int syntaxErrorCount;

View File

@ -454,7 +454,8 @@ public class Context
*
* @return an integer that is one of VERSION_1_0, VERSION_1_1, etc.
*/
public int getLanguageVersion() {
public int getLanguageVersion()
{
return version;
}
@ -468,7 +469,9 @@ public class Context
*
* @param version the version as specified by VERSION_1_0, VERSION_1_1, etc.
*/
public void setLanguageVersion(int version) {
public void setLanguageVersion(int version)
{
checkLanguageVersion(version);
Object listeners = propertyListeners;
if (listeners != null && version != this.version) {
firePropertyChangeImpl(listeners, languageVersionProperty,
@ -478,6 +481,21 @@ public class Context
this.version = version;
}
static void checkLanguageVersion(int version)
{
switch (version) {
case VERSION_DEFAULT:
case VERSION_1_0:
case VERSION_1_1:
case VERSION_1_2:
case VERSION_1_3:
case VERSION_1_4:
case VERSION_1_5:
return;
}
throw new IllegalArgumentException("Bad language version: "+version);
}
/**
* Get the implementation version.
*
@ -1528,7 +1546,8 @@ public class Context
* @since 1.3
*
*/
public int getOptimizationLevel() {
public int getOptimizationLevel()
{
return optimizationLevel;
}
@ -1549,17 +1568,21 @@ public class Context
* @since 1.3
*
*/
public void setOptimizationLevel(int optimizationLevel) {
if (optimizationLevel < 0) {
optimizationLevel = -1;
} else if (optimizationLevel > 9) {
optimizationLevel = 9;
}
public void setOptimizationLevel(int optimizationLevel)
{
checkOptimizationLevel(optimizationLevel);
if (codegenClass == null)
optimizationLevel = -1;
this.optimizationLevel = optimizationLevel;
}
static void checkOptimizationLevel(int optimizationLevel)
{
if (!(-1 <= optimizationLevel && optimizationLevel <= 9))
throw new IllegalArgumentException(
"Optimization level outside [-1..9]: "+optimizationLevel);
}
/**
* Set the security controller for this context.
* <p> SecurityController may only be set if it is currently null.