This commit is contained in:
nboyd%atg.com 2008-08-08 21:00:04 +00:00
Родитель 6467991e86
Коммит d958b4706c
1 изменённых файлов: 61 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,61 @@
/**
*
*/
package org.mozilla.javascript.tests;
import junit.framework.TestCase;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextAction;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.EvaluatorException;
/**
* @author Norris Boyd
*/
public class StrictModeApiTest extends TestCase {
private ScriptableObject global;
private ContextFactory contextFactory;
static class MyContextFactory extends ContextFactory {
@Override
protected boolean hasFeature(Context cx, int featureIndex) {
switch (featureIndex) {
case Context.FEATURE_STRICT_MODE:
case Context.FEATURE_STRICT_VARS:
case Context.FEATURE_STRICT_EVAL:
case Context.FEATURE_WARNING_AS_ERROR:
return true;
}
return super.hasFeature(cx, featureIndex);
}
};
public void testAccessingFields() {
contextFactory = new MyContextFactory();
Context cx = contextFactory.enterContext();
try {
global = cx.initStandardObjects();
try {
runScript("({}.nonexistent)");
fail();
} catch (EvaluatorException e) {
assertTrue(e.getMessage().startsWith("Reference to undefined property"));
}
} finally {
Context.exit();
}
}
private Object runScript(final String scriptSourceText) {
return this.contextFactory.call(new ContextAction() {
public Object run(Context context) {
Script script = context.compileString(scriptSourceText, "", 1, null);
return script.exec(context, global);
}
});
}
}