8022483: Nashorn compatibility issues in jhat's OQL feature
Reviewed-by: lagergren, attila, hannesw
--- a/jdk/src/share/classes/com/sun/tools/hat/resources/hat.js Wed Aug 07 19:06:29 2013 +0800
+++ b/jdk/src/share/classes/com/sun/tools/hat/resources/hat.js Wed Aug 07 18:16:25 2013 +0530
@@ -151,7 +151,7 @@
while (tmp != null) {
res[res.length] = tmp;
tmp = tmp.superclass;
- }
+ }
return res;
}
@@ -263,16 +263,19 @@
if (name == 'class') {
return wrapJavaValue(instance.clazz);
- } else if (name == 'toString') {
- return function() {
- return instance.toString();
- }
} else if (name == 'wrapped-object') {
return instance;
}
return undefined;
- }
+ },
+ __call__: function(name) {
+ if (name == 'toString') {
+ return instance.toString();
+ } else {
+ return undefined;
+ }
+ }
}
}
@@ -297,7 +300,7 @@
return true;
}
}
- return theJavaClassProto[name] != undefined;
+ return false;
},
__get__ : function(name) {
for (var i in fields) {
@@ -305,7 +308,7 @@
return wrapJavaValue(fields[i].value);
}
}
- return theJavaClassProto[name];
+ return undefined;
}
}
@@ -322,7 +325,12 @@
this.name = jclass.name;
this.fields = jclass.fields;
this['wrapped-object'] = jclass;
- this.__proto__ = this.statics;
+ }
+
+ for (var i in theJavaClassProto) {
+ if (typeof theJavaClassProto[i] == 'function') {
+ JavaClassWrapper.prototype[i] = theJavaClassProto[i];
+ }
}
// returns wrapper for Java object arrays
@@ -334,32 +342,35 @@
__getIds__ : function() {
var res = new Array(elements.length);
for (var i = 0; i < elements.length; i++) {
- res[i] = i;
+ res[i] = String(i);
}
return res;
},
__has__: function(name) {
- return (typeof(name) == 'number' &&
- name >= 0 && name < elements.length) ||
+ return (name >= 0 && name < elements.length) ||
name == 'length' || name == 'class' ||
name == 'toString' || name == 'wrapped-object';
},
__get__ : function(name) {
- if (typeof(name) == 'number' &&
- name >= 0 && name < elements.length) {
+ if (name >= 0 && name < elements.length) {
return wrapJavaValue(elements[name]);
} else if (name == 'length') {
return elements.length;
} else if (name == 'class') {
return wrapJavaValue(array.clazz);
- } else if (name == 'toString') {
- return function() { return array.toString(); }
} else if (name == 'wrapped-object') {
return array;
} else {
return undefined;
}
- }
+ },
+ __call__: function(name) {
+ if (name == 'toString') {
+ return array.toString();
+ } else {
+ return undefined;
+ }
+ }
}
}
@@ -373,26 +384,22 @@
__getIds__ : function() {
var r = new Array(array.length);
for (var i = 0; i < array.length; i++) {
- r[i] = i;
+ r[i] = String(i);
}
return r;
},
__has__: function(name) {
- return (typeof(name) == 'number' &&
- name >= 0 && name < array.length) ||
+ return (name >= 0 && name < array.length) ||
name == 'length' || name == 'class' ||
name == 'toString' || name == 'wrapped-object';
},
__get__: function(name) {
- if (typeof(name) == 'number' &&
- name >= 0 && name < array.length) {
+ if (name >= 0 && name < array.length) {
return elements[name];
}
if (name == 'length') {
return array.length;
- } else if (name == 'toString') {
- return function() { return array.valueString(true); }
} else if (name == 'wrapped-object') {
return array;
} else if (name == 'class') {
@@ -400,7 +407,14 @@
} else {
return undefined;
}
- }
+ },
+ __call__: function(name) {
+ if (name == 'toString') {
+ return array.valueString(true);
+ } else {
+ return undefined;
+ }
+ }
}
}
return javaObject(thing);
@@ -673,34 +687,33 @@
__getIds__ : function() {
var res = new Array(path.length);
for (var i = 0; i < path.length; i++) {
- res[i] = i;
+ res[i] = String(i);
}
return res;
},
__has__ : function (name) {
- return (typeof(name) == 'number' &&
- name >= 0 && name < path.length) ||
+ return (name >= 0 && name < path.length) ||
name == 'length' || name == 'toHtml' ||
name == 'toString';
},
__get__ : function(name) {
- if (typeof(name) == 'number' &&
- name >= 0 && name < path.length) {
+ if (name >= 0 && name < path.length) {
return path[name];
} else if (name == 'length') {
return path.length;
- } else if (name == 'toHtml') {
- return function() {
- return computeDescription(true);
- }
- } else if (name == 'toString') {
- return function() {
- return computeDescription(false);
- }
} else {
return undefined;
}
},
+ __call__: function(name) {
+ if (name == 'toHtml') {
+ return computeDescription(true);
+ } else if (name == 'toString') {
+ return computeDescription(false);
+ } else {
+ return undefined;
+ }
+ }
};
}
@@ -1005,22 +1018,8 @@
return "<a href='/object/" + id + "'>" +
name + "@" + id + "</a>";
}
- } else if ((typeof(obj) == 'object') || (obj instanceof JSAdapter)) {
- if (obj instanceof java.lang.Object) {
- // script wrapped Java object
- obj = wrapIterator(obj);
- // special case for enumeration
- if (obj instanceof java.util.Enumeration) {
- var res = "[ ";
- while (obj.hasMoreElements()) {
- res += toHtml(obj.nextElement()) + ", ";
- }
- res += "]";
- return res;
- } else {
- return obj;
- }
- } else if (obj instanceof Array) {
+ } else if (obj instanceof Object) {
+ if (Array.isArray(obj)) {
// script array
var res = "[ ";
for (var i in obj) {
@@ -1047,8 +1046,19 @@
}
}
} else {
- // JavaScript primitive value
- return obj;
+ // a Java object
+ obj = wrapIterator(obj);
+ // special case for enumeration
+ if (obj instanceof java.util.Enumeration) {
+ var res = "[ ";
+ while (obj.hasMoreElements()) {
+ res += toHtml(obj.nextElement()) + ", ";
+ }
+ res += "]";
+ return res;
+ } else {
+ return obj;
+ }
}
}
--- a/jdk/src/share/classes/com/sun/tools/hat/resources/oqlhelp.html Wed Aug 07 19:06:29 2013 +0800
+++ b/jdk/src/share/classes/com/sun/tools/hat/resources/oqlhelp.html Wed Aug 07 18:16:25 2013 +0530
@@ -79,7 +79,7 @@
<li>select all Strings of length 100 or more
<pre>
<code>
- select s from java.lang.String s where s.count >= 100
+ select s from java.lang.String s where s.value.length >= 100
</code>
</pre>
<li>select all int arrays of length 256 or more
@@ -92,7 +92,7 @@
<pre>
<code>
select s.value.toString() from java.lang.String s
- where /java/(s.value.toString())
+ where /java/.test(s.value.toString())
</code>
</pre>
<li>show path value of all File objects
@@ -219,7 +219,6 @@
<pre>
<code>
select heap.findClass("java.lang.System").statics.props
- select heap.findClass("java.lang.System").props
</code>
</pre>
<li>get number of fields of java.lang.String class
@@ -237,7 +236,7 @@
<li>select all classes that have name pattern java.net.*
<pre>
<code>
- select <a href="#filter">filter</a>(heap.classes(), "/java.net./(it.name)")
+ select <a href="#filter">filter</a>(heap.classes(), "/java.net./.test(it.name)")
</code>
</pre>
</ul>
@@ -536,7 +535,7 @@
Example: print number of classes that have specific name pattern
<pre>
<code>
- select count(<a href="#classes">heap.classes()</a>, "/java.io./(it.name)")
+ select count(<a href="#classes">heap.classes()</a>, "/java.io./.test(it.name)")
</code>
</pre>
@@ -559,14 +558,14 @@
<li>show all classes that have java.io.* name pattern
<pre>
<code>
- select filter(<a href="#classes">heap.classes</a>(), "/java.io./(it.name)")
+ select filter(<a href="#classes">heap.classes</a>(), "/java.io./.test(it.name)")
</code>
</pre>
<li> show all referrers of URL object where the referrer is not from
java.net package
<pre>
<code>
- select filter(<a href="#referrers">referrers</a>(u), "! /java.net./(<a href="#classof">classof</a>(it).name)")
+ select filter(<a href="#referrers">referrers</a>(u), "! /java.net./.test(<a href="#classof">classof</a>(it).name)")
from java.net.URL u
</code>
</pre>
@@ -619,13 +618,13 @@
<li>find the maximum length of any String instance
<pre>
<code>
- select max(map(heap.objects('java.lang.String', false), 'it.count'))
+ select max(map(heap.objects('java.lang.String', false), 'it.value.length'))
</code>
</pre>
<li>find string instance that has the maximum length
<pre>
<code>
- select max(heap.objects('java.lang.String'), 'lhs.count > rhs.count')
+ select max(heap.objects('java.lang.String'), 'lhs.value.length > rhs.value.length')
</code>
</pre>
</ul>
@@ -775,7 +774,7 @@
<pre>
<code>
- select <a href="#map">map</a>(<a href="#filter">filter(<a href="#findClass">heap.findClass</a>('java.lang.System').props.table, 'it != null'),
+ select <a href="#map">map</a>(<a href="#filter">filter(<a href="#findClass">heap.findClass</a>('java.lang.System').statics.props.table, 'it != null'),
function (it) {
var res = "";
while (it != null) {