Skip to content

Commit 5b1f8ac

Browse files
author
zhourenjian
committed
Add window["j2s.object.native"]=true; support for unpolluted native JavaScript object, so Java2Script library can co-exist with other JavaScript libraries, like YUI, jQuery, ...
1. new Object(); in Java will be compiled into JavaScript as "new JavaObject();" 2. If there is no window["j2s.object.native"] = true; line, JavaObject === Object, and everything is the same as before. 3. In native Object mode, Function, DOM class, Object's prototype are not modified. But String, Array, Number, Boolean's prototype are modified. More information, please visit http://groups.google.com/group/java2script/browse_thread/thread/3d6deb9c3c0a0cda
1 parent 8cbc456 commit 5b1f8ac

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTScriptVisitor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ public boolean visit(ClassInstanceCreation node) {
463463
String fqName = getTypeStringName(node.getType());
464464
if ("String".equals(fqName) || "java.lang.String".equals(fqName)) {
465465
buffer.append(" String.instantialize");
466+
} else if ("Object".equals(fqName) || "java.lang.Object".equals(fqName)) {
467+
// For discussion, please visit http://groups.google.com/group/java2script/browse_thread/thread/3d6deb9c3c0a0cda
468+
buffer.append(" new JavaObject");
466469
} else {
467470
buffer.append(" new ");
468471
if (fqName != null) {
@@ -2876,6 +2879,13 @@ public boolean visit(TypeLiteral node) {
28762879
} else if (type.isArrayType()) {
28772880
buffer.append("Array");
28782881
return false;
2882+
} else {
2883+
ITypeBinding resolveBinding = type.resolveBinding();
2884+
String name = resolveBinding.getName();
2885+
if ("Object".equals(name) || "java.lang.Object".equals(name)) {
2886+
buffer.append("JavaObject");
2887+
return false;
2888+
}
28792889
}
28802890
type.accept(this);
28812891
return false;

0 commit comments

Comments
 (0)