mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Work for bug 261278: splitting STRICT_MODE into STRICT_VARS and STRICT_EVAL to allow for better compatibility in future if strictness would be exetended to other areas.
This commit is contained in:
parent
9a1de340f9
commit
20d9c33ab6
@ -231,19 +231,28 @@ public class Context
|
||||
public static final int FEATURE_DYNAMIC_SCOPE = 7;
|
||||
|
||||
/**
|
||||
* Control if strict mode is enabled.
|
||||
* With strict mode enabled Rhino reports runtime errors in the following
|
||||
* cases:
|
||||
* <ul>
|
||||
* <li> Assignment to non-existing names which typically indicates missed
|
||||
* <b>var</b> declaration.
|
||||
* <li> Passing non-string arguments to the eval function.
|
||||
* </ul>
|
||||
* Control if strict variable mode is enabled.
|
||||
* When the feature is on Rhino reports runtime errors if assignment
|
||||
* to a global variable that does not exist is executed. When the feature
|
||||
* is off such assignments creates new variable in the global scope as
|
||||
* required by ECMA 262.
|
||||
* <p>
|
||||
* By default {@link #hasFeature(int)} returns false.
|
||||
* @since 1.6 Release 1
|
||||
*/
|
||||
public static final int FEATURE_STRICT_MODE = 8;
|
||||
public static final int FEATURE_STRICT_VARS = 8;
|
||||
|
||||
/**
|
||||
* Control if strict eval mode is enabled.
|
||||
* When the feature is on Rhino reports runtime errors if non-string
|
||||
* argument is passed to the eval function. When the feature is off
|
||||
* eval simply return non-string argument as is without performing any
|
||||
* evaluation as required by ECMA 262.
|
||||
* <p>
|
||||
* By default {@link #hasFeature(int)} returns false.
|
||||
* @since 1.6 Release 1
|
||||
*/
|
||||
public static final int FEATURE_STRICT_EVAL = 9;
|
||||
|
||||
public static final String languageVersionProperty = "language version";
|
||||
public static final String errorReporterProperty = "error reporter";
|
||||
@ -2159,7 +2168,8 @@ public class Context
|
||||
* @see #FEATURE_PARENT_PROTO_PROPRTIES
|
||||
* @see #FEATURE_E4X
|
||||
* @see #FEATURE_DYNAMIC_SCOPE
|
||||
* @see #FEATURE_STRICT_MODE
|
||||
* @see #FEATURE_STRICT_VARS
|
||||
* @see #FEATURE_STRICT_EVAL
|
||||
*/
|
||||
public boolean hasFeature(int featureIndex)
|
||||
{
|
||||
|
@ -266,7 +266,10 @@ public class ContextFactory
|
||||
case Context.FEATURE_DYNAMIC_SCOPE:
|
||||
return false;
|
||||
|
||||
case Context.FEATURE_STRICT_MODE:
|
||||
case Context.FEATURE_STRICT_VARS:
|
||||
return false;
|
||||
|
||||
case Context.FEATURE_STRICT_EVAL:
|
||||
return false;
|
||||
}
|
||||
// It is a bug to call the method with unknown featureIndex
|
||||
|
@ -1740,7 +1740,7 @@ public class ScriptRuntime {
|
||||
// "newname = 7;", where 'newname' has not yet
|
||||
// been defined, creates a new property in the
|
||||
// top scope unless strict mode is specified.
|
||||
if (cx.hasFeature(Context.FEATURE_STRICT_MODE)) {
|
||||
if (cx.hasFeature(Context.FEATURE_STRICT_VARS)) {
|
||||
throw Context.reportRuntimeError1("msg.assn.create.strict", id);
|
||||
}
|
||||
// Find the top scope by walking up the scope chain.
|
||||
@ -2175,7 +2175,7 @@ public class ScriptRuntime {
|
||||
return Undefined.instance;
|
||||
Object x = args[0];
|
||||
if (!(x instanceof String)) {
|
||||
if (cx.hasFeature(Context.FEATURE_STRICT_MODE)) {
|
||||
if (cx.hasFeature(Context.FEATURE_STRICT_EVAL)) {
|
||||
throw Context.reportRuntimeError0("msg.eval.nonstring.strict");
|
||||
}
|
||||
String message = ScriptRuntime.getMessage0("msg.eval.nonstring");
|
||||
|
@ -48,7 +48,8 @@ public class ShellContextFactory extends ContextFactory
|
||||
protected boolean hasFeature(Context cx, int featureIndex)
|
||||
{
|
||||
switch (featureIndex) {
|
||||
case Context.FEATURE_STRICT_MODE:
|
||||
case Context.FEATURE_STRICT_VARS:
|
||||
case Context.FEATURE_STRICT_EVAL:
|
||||
return strictMode;
|
||||
}
|
||||
return super.hasFeature(cx, featureIndex);
|
||||
|
Loading…
Reference in New Issue
Block a user