提交 37ff0669 编写于 作者: A allwin

8011888: sa.js: TypeError: [object JSAdapter] has no such function "__has__"

Reviewed-by: sla, sundar, kmo
Contributed-by: yunda.mly@taobao.com
上级 b8291346
...@@ -35,8 +35,9 @@ sapkg.c1 = sapkg.hotspot.c1; ...@@ -35,8 +35,9 @@ sapkg.c1 = sapkg.hotspot.c1;
sapkg.code = sapkg.hotspot.code; sapkg.code = sapkg.hotspot.code;
sapkg.compiler = sapkg.hotspot.compiler; sapkg.compiler = sapkg.hotspot.compiler;
// 'debugger' is a JavaScript keyword :-( // 'debugger' is a JavaScript keyword, but ES5 relaxes the
// sapkg.debugger = sapkg.hotspot.debugger; // restriction of using keywords as property name
sapkg.debugger = sapkg.hotspot.debugger;
sapkg.interpreter = sapkg.hotspot.interpreter; sapkg.interpreter = sapkg.hotspot.interpreter;
sapkg.jdi = sapkg.hotspot.jdi; sapkg.jdi = sapkg.hotspot.jdi;
...@@ -116,27 +117,36 @@ function main(globals, jvmarg) { ...@@ -116,27 +117,36 @@ function main(globals, jvmarg) {
return args; return args;
} }
// Handle __has__ specially to avoid metacircularity problems
// when called from __get__.
// Calling
// this.__has__(name)
// will in turn call
// this.__call__('__has__', name)
// which is not handled below
function __has__(name) {
if (typeof(name) == 'number') {
return so["has(int)"](name);
} else {
if (name == '__wrapped__') {
return true;
} else if (so["has(java.lang.String)"](name)) {
return true;
} else if (name.equals('toString')) {
return true;
} else {
return false;
}
}
}
if (so instanceof sapkg.utilities.soql.ScriptObject) { if (so instanceof sapkg.utilities.soql.ScriptObject) {
return new JSAdapter() { return new JSAdapter() {
__getIds__: function() { __getIds__: function() {
return so.getIds(); return so.getIds();
}, },
__has__ : function(name) { __has__ : __has__,
if (typeof(name) == 'number') {
return so["has(int)"](name);
} else {
if (name == '__wrapped__') {
return true;
} else if (so["has(java.lang.String)"](name)) {
return true;
} else if (name.equals('toString')) {
return true;
} else {
return false;
}
}
},
__delete__ : function(name) { __delete__ : function(name) {
if (typeof(name) == 'number') { if (typeof(name) == 'number') {
...@@ -147,7 +157,8 @@ function main(globals, jvmarg) { ...@@ -147,7 +157,8 @@ function main(globals, jvmarg) {
}, },
__get__ : function(name) { __get__ : function(name) {
if (! this.__has__(name)) { // don't call this.__has__(name); see comments above function __has__
if (! __has__.call(this, name)) {
return undefined; return undefined;
} }
if (typeof(name) == 'number') { if (typeof(name) == 'number') {
...@@ -162,7 +173,7 @@ function main(globals, jvmarg) { ...@@ -162,7 +173,7 @@ function main(globals, jvmarg) {
var args = prepareArgsArray(arguments); var args = prepareArgsArray(arguments);
var r; var r;
try { try {
r = value.call(args); r = value.call(Java.to(args, 'java.lang.Object[]'));
} catch (e) { } catch (e) {
println("call to " + name + " failed!"); println("call to " + name + " failed!");
throw e; throw e;
...@@ -204,6 +215,18 @@ function main(globals, jvmarg) { ...@@ -204,6 +215,18 @@ function main(globals, jvmarg) {
} }
// define "writeln" and "write" if not defined // define "writeln" and "write" if not defined
if (typeof(println) == 'undefined') {
println = function (str) {
java.lang.System.out.println(String(str));
}
}
if (typeof(print) == 'undefined') {
print = function (str) {
java.lang.System.out.print(String(str));
}
}
if (typeof(writeln) == 'undefined') { if (typeof(writeln) == 'undefined') {
writeln = println; writeln = println;
} }
...@@ -235,7 +258,7 @@ function main(globals, jvmarg) { ...@@ -235,7 +258,7 @@ function main(globals, jvmarg) {
this.jclasses = function() { this.jclasses = function() {
forEachKlass(function (clazz) { forEachKlass(function (clazz) {
writeln(clazz.getName().asString() + " @" + clazz.getHandle().toString()); writeln(clazz.getName().asString() + " @" + clazz.getAddress().toString());
}); });
} }
registerCommand("classes", "classes", "jclasses"); registerCommand("classes", "classes", "jclasses");
...@@ -490,14 +513,14 @@ function systemLoader() { ...@@ -490,14 +513,14 @@ function systemLoader() {
function forEachKlass(callback) { function forEachKlass(callback) {
var VisitorClass = sapkg.memory.SystemDictionary.ClassVisitor; var VisitorClass = sapkg.memory.SystemDictionary.ClassVisitor;
var visitor = new VisitorClass() { visit: callback }; var visitor = new VisitorClass() { visit: callback };
sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary$ClassVisitor)"](visitor); sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary.ClassVisitor)"](visitor);
} }
// iterate system dictionary for each 'Klass' and initiating loader // iterate system dictionary for each 'Klass' and initiating loader
function forEachKlassAndLoader(callback) { function forEachKlassAndLoader(callback) {
var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor; var VisitorClass = sapkg.memory.SystemDictionary.ClassAndLoaderVisitor;
var visitor = new VisitorClass() { visit: callback }; var visitor = new VisitorClass() { visit: callback };
sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary$ClassAndLoaderVisitor)"](visitor); sa.sysDict["classesDo(sun.jvm.hotspot.memory.SystemDictionary.ClassAndLoaderVisitor)"](visitor);
} }
// iterate system dictionary for each primitive array klass // iterate system dictionary for each primitive array klass
...@@ -522,7 +545,12 @@ function obj2oop(obj) { ...@@ -522,7 +545,12 @@ function obj2oop(obj) {
// iterates Java heap for each Oop // iterates Java heap for each Oop
function forEachOop(callback) { function forEachOop(callback) {
sa.objHeap.iterate(new sapkg.oops.HeapVisitor() { doObj: callback }); function empty() { }
sa.objHeap.iterate(new sapkg.oops.HeapVisitor() {
prologue: empty,
doObj: callback,
epilogue: empty
});
} }
// iterates Java heap for each Oop of given 'klass'. // iterates Java heap for each Oop of given 'klass'.
...@@ -536,8 +564,14 @@ function forEachOopOfKlass(callback, klass, includeSubtypes) { ...@@ -536,8 +564,14 @@ function forEachOopOfKlass(callback, klass, includeSubtypes) {
if (includeSubtypes == undefined) { if (includeSubtypes == undefined) {
includeSubtypes = true; includeSubtypes = true;
} }
function empty() { }
sa.objHeap.iterateObjectsOfKlass( sa.objHeap.iterateObjectsOfKlass(
new sapkg.oops.HeapVisitor() { doObj: callback }, new sapkg.oops.HeapVisitor() {
prologue: empty,
doObj: callback,
epilogue: empty
},
klass, includeSubtypes); klass, includeSubtypes);
} }
...@@ -746,9 +780,9 @@ while (tmp.itr.hasNext()) { ...@@ -746,9 +780,9 @@ while (tmp.itr.hasNext()) {
// ignore; // ignore;
continue; continue;
} else { } else {
// some type names have ':'. replace to make it as a // some type names have ':', '<', '>', '*', ' '. replace to make it as a
// JavaScript identifier // JavaScript identifier
tmp.name = tmp.name.replace(':', '_').replace('<', '_').replace('>', '_').replace('*', '_').replace(' ', '_'); tmp.name = ("" + tmp.name).replace(/[:<>* ]/g, '_');
eval("function read" + tmp.name + "(addr) {" + eval("function read" + tmp.name + "(addr) {" +
" return readVMType('" + tmp.name + "', addr);}"); " return readVMType('" + tmp.name + "', addr);}");
eval("function print" + tmp.name + "(addr) {" + eval("function print" + tmp.name + "(addr) {" +
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册