Ejemplo n.º 1
0
 @Test
 public void testComplexStack() {
   try {
     eval(
         "",
         "var x = { one: function() { bar() } };",
         "var y = { two: x.one };",
         "function foo() {",
         " throw TypeError();",
         "}",
         "function bar() {",
         "  foo();",
         "}",
         "",
         "try {",
         "  (function(){y.two();})();",
         "} catch(e) {",
         "  print(e.stack);",
         "  throw e;",
         "}");
     throw new AssertionError("Should have thrown");
   } catch (ThrowException e) {
     JSObject o = (JSObject) e.getValue();
     String stack = (String) o.get(getContext(), "stack");
     assertThat(stack.contains("TypeError\n")).isTrue();
     assertThat(stack.contains("at foo (<eval>:5)")).isTrue();
     assertThat(stack.contains("at bar (<eval>:8)")).isTrue();
     assertThat(stack.contains("at Object.one (<eval>:2)")).isTrue();
     assertThat(stack.contains("at <anonymous> (<eval>:12)")).isTrue();
     assertThat(stack.contains("at <eval> (<eval>:12)")).isTrue();
   }
 }
Ejemplo n.º 2
0
 @Test
 public void testDeleteOper() {
   check("var x = {a:'lol'}; var result = delete x.a;", true);
   JSObject x = (JSObject) getContext().resolve("x").getValue(getContext());
   assertThat(x.get(getContext(), "a")).isEqualTo(Types.UNDEFINED);
 }