use of net.sourceforge.htmlunit.corejs.javascript.Scriptable in project htmlunit-core-js by HtmlUnit.
the class HostExceptionsTest method doTest.
private static void doTest(final String jsExpression) throws Exception {
final String script = "var foo = new MyScriptable(); try { " + jsExpression + "} catch(e) {}";
final ContextAction<Object> action = new ContextAction<Object>() {
@Override
public Object run(final Context cx) {
final Scriptable scope = cx.initSafeStandardObjects();
try {
ScriptableObject.defineClass(scope, MyScriptable.class);
} catch (final Exception e) {
throw new RuntimeException();
}
cx.evaluateString(scope, script, "test.js", 0, null);
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of net.sourceforge.htmlunit.corejs.javascript.Scriptable in project htmlunit-core-js by HtmlUnit.
the class LookupSetterTest method test.
private void test(final String expected, final String src) throws Exception {
final ContextAction<Object> action = new ContextAction<Object>() {
@Override
public Object run(final Context cx) {
try {
final Scriptable scope = cx.initSafeStandardObjects(new TopScope());
ScriptableObject.defineClass(scope, Foo.class);
cx.evaluateString(scope, defineSetterAndGetterX, "initX", 1, null);
Object result = String.valueOf(cx.evaluateString(scope, src, "test", 1, null));
assertEquals(expected, result);
return null;
} catch (final Exception e) {
if (e instanceof RuntimeException)
throw (RuntimeException) e;
throw new RuntimeException(e);
}
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of net.sourceforge.htmlunit.corejs.javascript.Scriptable in project htmlunit-core-js by HtmlUnit.
the class NativeErrorTest method stack.
/**
* @throws Exception if the test fails
*/
@Test
public void stack() throws Exception {
final String script = "function test() {\n" + " try {\n" + " null.method();\n" + " } catch (e) {\n" + " if (e.stack)\n" + " output += e.stack.indexOf('\tat test.js:3 (test)') != -1;\n" + " else\n" + " output += 'undefined';\n" + " }\n" + "}\n" + "var output = '';\n" + "test();\n" + "output";
final ContextAction<Object> action = new ContextAction<Object>() {
@Override
public Object run(final Context cx) {
final Scriptable scope = cx.initSafeStandardObjects();
final Object result = cx.evaluateString(scope, script, "test.js", 1, null);
assertEquals("true", result);
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of net.sourceforge.htmlunit.corejs.javascript.Scriptable in project htmlunit-core-js by HtmlUnit.
the class NativeErrorTest method stackNewError.
/**
* @throws Exception if the test fails
*/
@Test
public void stackNewError() throws Exception {
final ContextFactory cf = new ContextFactory();
final String script = "function test() {\n" + " try {\n" + " throw new Error();\n" + " } catch (e) {\n" + " if (e.stack)\n" + " output += typeof e.stack;\n" + " else\n" + " output += 'undefined';\n" + " }\n" + "}\n" + "var output = '';\n" + "test();\n" + "output";
final ContextAction<Object> action = new ContextAction<Object>() {
@Override
public Object run(final Context cx) {
final Scriptable scope = cx.initSafeStandardObjects();
final Object result = cx.evaluateString(scope, script, "test.js", 1, null);
assertEquals("string", result);
return null;
}
};
Utils.runWithAllOptimizationLevels(cf, action);
}
use of net.sourceforge.htmlunit.corejs.javascript.Scriptable in project htmlunit-core-js by HtmlUnit.
the class NativeGlobalTest method doTest.
private static void doTest(final double expected, final String src) throws Exception {
final ContextAction<Object> action = new ContextAction<Object>() {
@Override
public Object run(final Context cx) {
cx.setLanguageVersion(Context.VERSION_ES6);
final Scriptable scope = cx.initSafeStandardObjects();
Object result = cx.evaluateString(scope, src, "test.js", 0, null);
assertEquals(expected, result);
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
Aggregations