use of net.sourceforge.htmlunit.corejs.javascript.Scriptable in project htmlunit-core-js by HtmlUnit.
the class NativeObjectTest method assignNull.
/**
* @throws Exception if the test fails
*/
@Test
public void assignNull() throws Exception {
final String script = "function test() {\n" + " var copy = Object.assign({}, null);\n" + " output += copy.a;\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("undefined", result);
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of net.sourceforge.htmlunit.corejs.javascript.Scriptable in project htmlunit-core-js by HtmlUnit.
the class NativeObjectTest method assign.
/**
* @throws Exception if the test fails
*/
@Test
public void assign() throws Exception {
final String script = "function test() {\n" + " var obj = { a: 1 };\n" + " var copy = Object.assign({}, obj);\n" + " output += copy.a;\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("1", result);
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of net.sourceforge.htmlunit.corejs.javascript.Scriptable in project htmlunit-core-js by HtmlUnit.
the class ParserTest method test.
private static void test(final String script, final Object expected) {
final ContextAction<Object> action = new ContextAction<Object>() {
@Override
public Object run(final Context cx) {
try {
Scriptable scope = cx.initSafeStandardObjects();
ScriptableObject.defineClass(scope, MyHostObject.class);
final Object o = cx.evaluateString(scope, script, "test_script", 1, null);
assertEquals(expected, o);
return o;
} catch (final Exception 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 PrimitiveTypeScopeResolutionTest method testWithTwoScopes.
private static void testWithTwoScopes(final String scriptScope1, final String scriptScope2) {
final ContextAction<Object> action = new ContextAction<Object>() {
@Override
public Object run(final Context cx) {
final Scriptable scope1 = cx.initSafeStandardObjects(new MySimpleScriptableObject("scope1"));
final Scriptable scope2 = cx.initSafeStandardObjects(new MySimpleScriptableObject("scope2"));
cx.evaluateString(scope2, scriptScope2, "source2", 1, null);
scope1.put("scope2", scope1, scope2);
return cx.evaluateString(scope1, scriptScope1, "source1", 1, null);
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of net.sourceforge.htmlunit.corejs.javascript.Scriptable in project htmlunit-core-js by HtmlUnit.
the class ScriptRuntimeTest method test.
private static void test(final String script, final Object expected) {
final ContextAction<Object> action = new ContextAction<Object>() {
@Override
public Object run(final Context cx) {
try {
Scriptable scope = cx.initSafeStandardObjects();
final Object o = cx.evaluateString(scope, script, "test_script", 1, null);
assertEquals(expected, o);
return o;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
};
Utils.runWithAllOptimizationLevels(action);
}
Aggregations