Fix for AVATAR_JS-154, Java object inspection, Java object REPL completion based on Java reflected methods

This commit is contained in:
jfdenise 2014-01-13 15:58:09 +01:00
parent 5f31700c43
commit ab5c8857b7
2 changed files with 42 additions and 2 deletions

View File

@ -276,6 +276,7 @@
<apply-diff src="lib" mod="src/main/js/lib" name="repl.js"/>
<apply-diff src="lib" mod="src/main/js/lib" name="string_decoder.js"/>
<apply-diff src="lib" mod="src/main/js/lib" name="tls.js"/>
<apply-diff src="lib" mod="src/main/js/lib" name="util.js"/>
<!-- tests -->
<apply-diff src="test" mod="${test.dir}" name="common.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-buffer.js"/>
@ -375,6 +376,7 @@
<apply-patch-file target="src/main/js/lib" dir="lib" name="repl.js"/>
<apply-patch-file target="src/main/js/lib" dir="lib" name="string_decoder.js"/>
<apply-patch-file target="src/main/js/lib" dir="lib" name="tls.js"/>
<apply-patch-file target="src/main/js/lib" dir="lib" name="util.js"/>
<!-- tests -->
<apply-patch-file target="${test.dir}" dir="test" name="common.js"/>
<apply-patch-file target="${test.dir}/simple" dir="test/simple" name="test-buffer.js"/>

View File

@ -1,6 +1,44 @@
--- ../node/lib/repl.js 2013-12-16 17:07:31.000000000 +0100
+++ src/main/js/lib/repl.js 2013-12-16 16:16:00.000000000 +0100
@@ -923,5 +923,5 @@
+++ ./src/main/js/lib/repl.js 2014-01-13 15:40:15.000000000 +0100
@@ -236,6 +236,8 @@
// First we attempt to eval as expression with parens.
// This catches '{a : 1}' properly.
+
+ try { // do not break for invalid execution
self.eval('(' + evalCmd + ')',
self.context,
'repl',
@@ -251,6 +253,9 @@
finish(null, ret);
}
});
+ } catch(err) {
+ finish(err);
+ }
} else {
finish(null);
@@ -565,7 +570,18 @@
if (obj != null) {
if (typeof obj === 'object' || typeof obj === 'function') {
+ try {
memberGroups.push(Object.getOwnPropertyNames(obj));
+ } catch(err) {
+ if ((typeof(obj) == 'object' || typeof(obj) == 'function') && !(obj instanceof Object)) { // Completion on java
+ var arr = obj.class.getMethods()
+ var methods = [];
+ for (var m in arr) {
+ methods.push(arr[m].name);
+ }
+ memberGroups.push(methods);
+ }
+ }
}
// works for non-objects
try {
@@ -923,5 +939,5 @@
// "strict mode" syntax errors
!e.match(/^SyntaxError: .*strict mode.*/i) &&
// JSON.parse() error