use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.
the class ExecutionListenerCompilerTest method setup.
@Before
public void setup() {
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
return super.parse(request);
}
});
setupContext();
getContext().initialize(ProxyLanguage.ID);
langauge = ProxyLanguage.get(null);
counter = 0;
}
use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.
the class LazyAccessInspectDebugTest method testReadWithSideEffects.
// @formatter:off The default formatting makes unnecessarily big indents and illogical line breaks
// CheckStyle: stop line length check
@Test
public void testReadWithSideEffects() throws Exception {
final AtomicInteger readLazyCount = new AtomicInteger(0);
InspectorTester tester = InspectorTester.start(true);
tester.sendMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
tester.sendMessage("{\"id\":2,\"method\":\"Debugger.enable\"}");
assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":1}\n" + "{\"result\":{},\"id\":2}\n"));
tester.sendMessage("{\"id\":3,\"method\":\"Runtime.runIfWaitingForDebugger\"}");
assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":3}\n" + "{\"method\":\"Runtime.executionContextCreated\",\"params\":{\"context\":{\"origin\":\"\",\"name\":\"test\",\"id\":1}}}\n"));
ProxyLanguage.setDelegate(new ReadWithSideEffectsLanguage(readLazyCount));
Source source = Source.newBuilder(ProxyLanguage.ID, "1", "ReadWithSideEffects.test").build();
String sourceURI = InspectorTester.getStringURI(source.getURI());
String hash = new Script(0, null, DebuggerTester.getSourceImpl(source)).getHash();
tester.eval(source);
long id = tester.getContextId();
int endLine = source.getLineCount() - 1;
int endColumn = source.getLineLength(1);
assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.scriptParsed\",\"params\":{\"endLine\":" + endLine + ",\"scriptId\":\"0\",\"endColumn\":" + endColumn + ",\"startColumn\":0,\"startLine\":0,\"length\":" + source.getLength() + ",\"executionContextId\":" + id + ",\"url\":\"" + sourceURI + "\",\"hash\":\"" + hash + "\"}}\n"));
assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.paused\",\"params\":{\"reason\":\"other\",\"hitBreakpoints\":[]," + "\"callFrames\":[{\"callFrameId\":\"0\",\"functionName\":\"TestRootNode\"," + "\"scopeChain\":[{\"name\":\"TestRootNode\",\"type\":\"local\",\"object\":{\"description\":\"TestRootNode\",\"type\":\"object\",\"objectId\":\"1\"}}," + "{\"name\":\"top\",\"type\":\"global\",\"object\":{\"description\":\"top\",\"type\":\"object\",\"objectId\":\"2\"}}]," + "\"this\":null," + "\"functionLocation\":{\"scriptId\":\"0\",\"columnNumber\":0,\"lineNumber\":0}," + "\"location\":{\"scriptId\":\"0\",\"columnNumber\":0,\"lineNumber\":0}," + "\"url\":\"" + sourceURI + "\"" + "}]}}\n"));
// Ask for local variables
tester.sendMessage("{\"id\":1,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"1\"}}");
assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[{\"isOwn\":true,\"enumerable\":true," + "\"name\":\"o\",\"value\":{\"description\":\"Object LazyReadObject\",\"className\":\"Object\",\"type\":\"object\",\"objectId\":\"3\"},\"configurable\":true,\"writable\":true}]," + "\"internalProperties\":[]},\"id\":1}\n"));
// Ask for properties of 'o':
tester.sendMessage("{\"id\":2,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"3\"}}");
assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[" + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"readReady\",\"value\":{\"description\":\"42\",\"type\":\"number\",\"value\":42},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"get\":{\"description\":\"\",\"className\":\"Function\",\"type\":\"function\",\"objectId\":\"5\"},\"enumerable\":true,\"name\":\"readLazy\",\"configurable\":true,\"writable\":false}]," + "\"internalProperties\":[]},\"id\":2}\n"));
// The lazy value was not read yet:
assertEquals(0, readLazyCount.get());
// Invoke the lazy read (getter):
tester.sendMessage("{\"id\":10,\"method\":\"Runtime.callFunctionOn\",\"params\":" + "{\"objectId\":\"3\"," + INVOKE_GETTER1 + "," + "\"arguments\":[{\"value\":\"[\\\"readLazy\\\"]\"}]," + "\"silent\":true}}");
assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":{\"description\":\"43\",\"type\":\"number\",\"value\":43}},\"id\":10}\n"));
// The lazy value was read now:
assertEquals(1, readLazyCount.get());
// Test an alternate getter function:
tester.sendMessage("{\"id\":11,\"method\":\"Runtime.callFunctionOn\",\"params\":" + "{\"objectId\":\"3\"," + INVOKE_GETTER2 + "," + "\"arguments\":[{\"value\":\"readLazy\"}]," + "\"silent\":true}}");
assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":{\"description\":\"43\",\"type\":\"number\",\"value\":43}},\"id\":11}\n"));
assertEquals(2, readLazyCount.get());
// Test lazy scope property:
tester.sendMessage("{\"id\":20,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"2\"}}");
assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[{\"isOwn\":true,\"enumerable\":true,\"name\":\"readReady\",\"value\":{\"description\":\"42\",\"type\":\"number\",\"value\":42},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"get\":{\"description\":\"\",\"className\":\"Function\",\"type\":\"function\",\"objectId\":\"7\"},\"enumerable\":true,\"name\":\"readLazy\",\"configurable\":true,\"writable\":false}]," + "\"internalProperties\":[]},\"id\":20}\n"));
assertEquals(2, readLazyCount.get());
// Invoke the lazy read (getter):
tester.sendMessage("{\"id\":21,\"method\":\"Runtime.callFunctionOn\",\"params\":" + "{\"objectId\":\"2\"," + INVOKE_GETTER3 + "," + "\"arguments\":[{\"value\":\"[\\\"readLazy\\\"]\"}]," + "\"silent\":true}}");
assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":{\"description\":\"43\",\"type\":\"number\",\"value\":43}},\"id\":21}\n"));
// The lazy value was read now:
assertEquals(3, readLazyCount.get());
tester.sendMessage("{\"id\":100,\"method\":\"Debugger.resume\"}");
assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":100}\n" + "{\"method\":\"Debugger.resumed\"}\n"));
// Reset the delegate so that we can GC the tested Engine
ProxyLanguage.setDelegate(new ProxyLanguage());
tester.finish();
}
use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.
the class InspectorReceiverTest method testOtherReceiver1.
/**
* Test one scope with "other" receiver.
*/
@Test
public void testOtherReceiver1() throws Exception {
ProxyLanguage.setDelegate(new TestReceiverLanguage());
Source source = Source.create(ProxyLanguage.ID, "other\n" + "a 1 b 2 other 3");
String sourceURI = InspectorTester.getStringURI(source.getURI());
InspectorTester tester = InspectorTester.start(true);
tester.sendMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
assertEquals("{\"result\":{},\"id\":1}", tester.getMessages(true).trim());
tester.sendMessage("{\"id\":2,\"method\":\"Debugger.enable\"}");
assertEquals("{\"result\":{},\"id\":2}", tester.getMessages(true).trim());
tester.sendMessage("{\"id\":3,\"method\":\"Runtime.runIfWaitingForDebugger\"}");
assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":3}\n" + "{\"method\":\"Runtime.executionContextCreated\",\"params\":{\"context\":{\"origin\":\"\",\"name\":\"test\",\"id\":1}}}\n"));
tester.eval(source);
long id = tester.getContextId();
assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.scriptParsed\",\"params\":{\"endLine\":1,\"scriptId\":\"0\",\"endColumn\":15,\"startColumn\":0,\"startLine\":0,\"length\":" + source.getLength() + "," + "\"executionContextId\":" + id + ",\"url\":\"" + sourceURI + "\",\"hash\":\"e2e9dccce61f3a14f6c3f3abffffffffffffffff\"}}\n" + "{\"method\":\"Debugger.paused\",\"params\":{\"reason\":\"other\",\"hitBreakpoints\":[]," + "\"callFrames\":[{\"callFrameId\":\"0\",\"functionName\":\"\"," + "\"scopeChain\":[{\"name\":\"0\",\"type\":\"block\",\"object\":{\"description\":\"0\",\"type\":\"object\",\"objectId\":\"1\"}}]," + "\"this\":null," + "\"location\":{\"scriptId\":\"0\",\"columnNumber\":0,\"lineNumber\":0}," + "\"url\":\"" + sourceURI + "\"}]}}\n"));
// Scope's variables contain the "other" receiver:
tester.sendMessage("{\"id\":4,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"1\"}}");
assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[{\"isOwn\":true,\"enumerable\":true,\"name\":\"other\",\"value\":{\"description\":\"3\",\"type\":\"object\",\"value\":\"3\"},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"a\",\"value\":{\"description\":\"1\",\"type\":\"object\",\"value\":\"1\"},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"b\",\"value\":{\"description\":\"2\",\"type\":\"object\",\"value\":\"2\"},\"configurable\":true,\"writable\":false}],\"internalProperties\":[]},\"id\":4}\n"));
tester.sendMessage("{\"id\":5,\"method\":\"Debugger.resume\"}");
assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":5}\n" + "{\"method\":\"Debugger.resumed\"}\n"));
// Reset the delegate so that we can GC the tested Engine
ProxyLanguage.setDelegate(new ProxyLanguage());
tester.finish();
}
use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.
the class InspectorReceiverTest method testThisReceiver2.
/**
* Test multiple scopes, just one with "this" receiver.
*/
@Test
public void testThisReceiver2() throws Exception {
ProxyLanguage.setDelegate(new TestReceiverLanguage());
Source source = Source.create(ProxyLanguage.ID, "this\n" + "a 1 b 2\n" + "c 4 d 5 this 3\n" + "a 6 b 7");
String sourceURI = InspectorTester.getStringURI(source.getURI());
InspectorTester tester = InspectorTester.start(true);
tester.sendMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
assertEquals("{\"result\":{},\"id\":1}", tester.getMessages(true).trim());
tester.sendMessage("{\"id\":2,\"method\":\"Debugger.enable\"}");
assertEquals("{\"result\":{},\"id\":2}", tester.getMessages(true).trim());
tester.sendMessage("{\"id\":3,\"method\":\"Runtime.runIfWaitingForDebugger\"}");
assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":3}\n" + "{\"method\":\"Runtime.executionContextCreated\",\"params\":{\"context\":{\"origin\":\"\",\"name\":\"test\",\"id\":1}}}\n"));
tester.eval(source);
long id = tester.getContextId();
assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.scriptParsed\",\"params\":{\"endLine\":3,\"scriptId\":\"0\",\"endColumn\":7,\"startColumn\":0,\"startLine\":0,\"length\":" + source.getLength() + "," + "\"executionContextId\":" + id + ",\"url\":\"" + sourceURI + "\",\"hash\":\"f64d15f3ef714d0af24593dbffffffffffffffff\"}}\n" + "{\"method\":\"Debugger.paused\",\"params\":{\"reason\":\"other\",\"hitBreakpoints\":[]," + "\"callFrames\":[{\"callFrameId\":\"0\",\"functionName\":\"\"," + "\"scopeChain\":[{\"name\":\"0\",\"type\":\"block\",\"object\":{\"description\":\"0\",\"type\":\"object\",\"objectId\":\"1\"}}," + "{\"name\":\"1\",\"type\":\"block\",\"object\":{\"description\":\"1\",\"type\":\"object\",\"objectId\":\"2\"}}," + "{\"name\":\"2\",\"type\":\"block\",\"object\":{\"description\":\"2\",\"type\":\"object\",\"objectId\":\"3\"}}]," + "\"this\":{\"description\":\"3\",\"type\":\"object\",\"value\":\"3\"}," + "\"location\":{\"scriptId\":\"0\",\"columnNumber\":0,\"lineNumber\":0}," + "\"url\":\"" + sourceURI + "\"}]}}\n"));
// Scope's variables do not contain "this":
tester.sendMessage("{\"id\":4,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"1\"}}");
assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[{\"isOwn\":true,\"enumerable\":true,\"name\":\"a\",\"value\":{\"description\":\"1\",\"type\":\"object\",\"value\":\"1\"},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"b\",\"value\":{\"description\":\"2\",\"type\":\"object\",\"value\":\"2\"},\"configurable\":true,\"writable\":false}],\"internalProperties\":[]},\"id\":4}\n"));
tester.sendMessage("{\"id\":5,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"2\"}}");
assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[{\"isOwn\":true,\"enumerable\":true,\"name\":\"c\",\"value\":{\"description\":\"4\",\"type\":\"object\",\"value\":\"4\"},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"d\",\"value\":{\"description\":\"5\",\"type\":\"object\",\"value\":\"5\"},\"configurable\":true,\"writable\":false}],\"internalProperties\":[]},\"id\":5}\n"));
tester.sendMessage("{\"id\":10,\"method\":\"Debugger.resume\"}");
assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":10}\n" + "{\"method\":\"Debugger.resumed\"}\n"));
// Reset the delegate so that we can GC the tested Engine
ProxyLanguage.setDelegate(new ProxyLanguage());
tester.finish();
}
use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.
the class InspectorReceiverTest method testThisReceiver1.
// @formatter:off The default formatting makes unnecessarily big indents and illogical line breaks
// CheckStyle: stop line length check
/**
* Test one scope with "this" receiver.
*/
@Test
public void testThisReceiver1() throws Exception {
ProxyLanguage.setDelegate(new TestReceiverLanguage());
Source source = Source.create(ProxyLanguage.ID, "this\n" + "a 1 b 2 this 3");
String sourceURI = InspectorTester.getStringURI(source.getURI());
InspectorTester tester = InspectorTester.start(true);
tester.sendMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
assertEquals("{\"result\":{},\"id\":1}", tester.getMessages(true).trim());
tester.sendMessage("{\"id\":2,\"method\":\"Debugger.enable\"}");
assertEquals("{\"result\":{},\"id\":2}", tester.getMessages(true).trim());
tester.sendMessage("{\"id\":3,\"method\":\"Runtime.runIfWaitingForDebugger\"}");
assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":3}\n" + "{\"method\":\"Runtime.executionContextCreated\",\"params\":{\"context\":{\"origin\":\"\",\"name\":\"test\",\"id\":1}}}\n"));
tester.eval(source);
long id = tester.getContextId();
assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.scriptParsed\",\"params\":{\"endLine\":1,\"scriptId\":\"0\",\"endColumn\":14,\"startColumn\":0,\"startLine\":0,\"length\":" + source.getLength() + "," + "\"executionContextId\":" + id + ",\"url\":\"" + sourceURI + "\",\"hash\":\"f64d15f3ffda6a1affffffffffffffffffffffff\"}}\n" + "{\"method\":\"Debugger.paused\",\"params\":{\"reason\":\"other\",\"hitBreakpoints\":[]," + "\"callFrames\":[{\"callFrameId\":\"0\",\"functionName\":\"\"," + "\"scopeChain\":[{\"name\":\"0\",\"type\":\"block\",\"object\":{\"description\":\"0\",\"type\":\"object\",\"objectId\":\"1\"}}]," + "\"this\":{\"description\":\"3\",\"type\":\"object\",\"value\":\"3\"}," + "\"location\":{\"scriptId\":\"0\",\"columnNumber\":0,\"lineNumber\":0}," + "\"url\":\"" + sourceURI + "\"}]}}\n"));
// Scope's variables do not contain "this":
tester.sendMessage("{\"id\":4,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"1\"}}");
assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[{\"isOwn\":true,\"enumerable\":true,\"name\":\"a\",\"value\":{\"description\":\"1\",\"type\":\"object\",\"value\":\"1\"},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"b\",\"value\":{\"description\":\"2\",\"type\":\"object\",\"value\":\"2\"},\"configurable\":true,\"writable\":false}],\"internalProperties\":[]},\"id\":4}\n"));
tester.sendMessage("{\"id\":5,\"method\":\"Debugger.resume\"}");
assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":5}\n" + "{\"method\":\"Debugger.resumed\"}\n"));
// Reset the delegate so that we can GC the tested Engine
ProxyLanguage.setDelegate(new ProxyLanguage());
tester.finish();
}
Aggregations