mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 21:35:39 +00:00
Work on bug 238649: no more support for ClassNameHelper and friends
This commit is contained in:
parent
72cb4322da
commit
d62ad77af5
@ -71,8 +71,6 @@ Requires Ant version 1.2 or later
|
||||
<jar basedir="${classes}" destfile="${dist.dir}/${small-rhino.jar}"
|
||||
compress="${jar-compression}">
|
||||
<include name="org/mozilla/javascript/*.class"/>
|
||||
<exclude name="org/mozilla/javascript/ClassNameHelper*.class"/>
|
||||
<exclude name="org/mozilla/javascript/ClassRepository*.class"/>
|
||||
<exclude name="org/mozilla/javascript/JavaAdapter*.class"/>
|
||||
<exclude name="org/mozilla/javascript/Token.class"/>
|
||||
|
||||
|
@ -22,8 +22,8 @@ Most embeddings won't need any of the classes in <tt>org.mozilla.javascript.tool
|
||||
Optimizer</h3>
|
||||
<p>
|
||||
It is possible to run Rhino with interpreter mode only, allowing you to remove
|
||||
classes for classfile generation that include all the classes from
|
||||
<tt>org.mozilla.javascript.optimizer</tt> package and <tt>ClassNameHelper</tt>, <tt>ClassRepository</tt> classes from <tt>org.mozilla.javascript</tt> package.
|
||||
code for classfile generation that include all the classes from
|
||||
<tt>org.mozilla.javascript.optimizer</tt> package.
|
||||
|
||||
<h3>JavaAdapter</h3>
|
||||
<p>
|
||||
|
@ -1,91 +0,0 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
* Roger Lawrence
|
||||
* Andi Vajda
|
||||
* Kemal Bayram
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @deprectated To generate class files from script sources, use
|
||||
* {@link org.mozilla.javascript.optimizer.ClassCompiler}.
|
||||
*/
|
||||
|
||||
public abstract class ClassNameHelper {
|
||||
|
||||
public static ClassNameHelper get(Context cx) {
|
||||
ClassNameHelper helper = savedNameHelper;
|
||||
if (helper == null && !helperNotAvailable) {
|
||||
Class nameHelperClass = Kit.classOrNull(
|
||||
"org.mozilla.javascript.optimizer.OptClassNameHelper");
|
||||
// nameHelperClass == null if running lite
|
||||
if (nameHelperClass != null) {
|
||||
helper = (ClassNameHelper)Kit.newInstanceOrNull(
|
||||
nameHelperClass);
|
||||
}
|
||||
if (helper != null) {
|
||||
savedNameHelper = helper;
|
||||
} else {
|
||||
helperNotAvailable = true;
|
||||
}
|
||||
}
|
||||
return helper;
|
||||
}
|
||||
|
||||
public abstract String getTargetClassFileName();
|
||||
|
||||
public abstract void setTargetClassFileName(String classFileName);
|
||||
|
||||
public abstract String getTargetPackage();
|
||||
|
||||
public abstract void setTargetPackage(String targetPackage);
|
||||
|
||||
public abstract void setTargetExtends(Class extendsClass);
|
||||
|
||||
public abstract void setTargetImplements(Class[] implementsClasses);
|
||||
|
||||
public abstract ClassRepository getClassRepository();
|
||||
|
||||
public abstract void setClassRepository(ClassRepository repository);
|
||||
|
||||
public abstract String getClassName();
|
||||
|
||||
public abstract void setClassName(String initialName);
|
||||
|
||||
private static ClassNameHelper savedNameHelper;
|
||||
private static boolean helperNotAvailable;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Kemal Bayram
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @deprectated To generate class files from script sources, use
|
||||
* {@link org.mozilla.javascript.optimizer.ClassCompiler}.
|
||||
*/
|
||||
public interface ClassRepository {
|
||||
|
||||
public boolean storeClass(String className, byte[] classBytes,
|
||||
boolean isTopLevel) throws IOException;
|
||||
}
|
@ -61,63 +61,16 @@ public class Codegen extends Interpreter
|
||||
boolean returnFunction,
|
||||
Object securityDomain)
|
||||
{
|
||||
Context cx = Context.getCurrentContext();
|
||||
OptClassNameHelper
|
||||
nameHelper = (OptClassNameHelper)ClassNameHelper.get(cx);
|
||||
Class[] interfaces = nameHelper.getTargetImplements();
|
||||
Class superClass = nameHelper.getTargetExtends();
|
||||
boolean isPrimary = (interfaces == null && superClass == null);
|
||||
String mainClassName = nameHelper.getScriptClassName(isPrimary);
|
||||
int serial;
|
||||
synchronized (globalLock) {
|
||||
serial = ++globalSerialClassCounter;
|
||||
}
|
||||
String mainClassName = "org.mozilla.javascript.gen.c"+serial;
|
||||
|
||||
byte[] mainClassBytes = compileToClassFile(compilerEnv, mainClassName,
|
||||
scriptOrFn, encodedSource,
|
||||
returnFunction);
|
||||
|
||||
boolean onlySave = false;
|
||||
ClassRepository repository = nameHelper.getClassRepository();
|
||||
if (repository != null) {
|
||||
try {
|
||||
if (!repository.storeClass(mainClassName, mainClassBytes,
|
||||
true))
|
||||
{
|
||||
onlySave = true;
|
||||
}
|
||||
} catch (IOException iox) {
|
||||
throw Context.throwAsScriptRuntimeEx(iox);
|
||||
}
|
||||
|
||||
if (!isPrimary) {
|
||||
String adapterClassName = nameHelper.getScriptClassName(true);
|
||||
int functionCount = scriptOrFn.getFunctionCount();
|
||||
ObjToIntMap functionNames = new ObjToIntMap(functionCount);
|
||||
for (int i = 0; i != functionCount; ++i) {
|
||||
FunctionNode ofn = scriptOrFn.getFunctionNode(i);
|
||||
String name = ofn.getFunctionName();
|
||||
if (name != null && name.length() != 0) {
|
||||
functionNames.put(name, ofn.getParamCount());
|
||||
}
|
||||
}
|
||||
if (superClass == null) {
|
||||
superClass = ScriptRuntime.ObjectClass;
|
||||
}
|
||||
byte[] classFile = JavaAdapter.createAdapterCode(
|
||||
functionNames, adapterClassName,
|
||||
superClass, interfaces,
|
||||
mainClassName);
|
||||
try {
|
||||
if (!repository.storeClass(adapterClassName, classFile,
|
||||
true))
|
||||
{
|
||||
onlySave = true;
|
||||
}
|
||||
} catch (IOException iox) {
|
||||
throw Context.throwAsScriptRuntimeEx(iox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (onlySave) { return null; }
|
||||
|
||||
Exception e = null;
|
||||
Class result = null;
|
||||
GeneratedClassLoader
|
||||
@ -135,6 +88,7 @@ public class Codegen extends Interpreter
|
||||
throw new RuntimeException("Malformed optimizer package " + e);
|
||||
|
||||
if (returnFunction) {
|
||||
Context cx = Context.getCurrentContext();
|
||||
NativeFunction f;
|
||||
try {
|
||||
Constructor ctor = result.getConstructors()[0];
|
||||
@ -163,7 +117,7 @@ public class Codegen extends Interpreter
|
||||
ScriptOrFnNode scriptOrFn,
|
||||
String debugSource)
|
||||
{
|
||||
// Not supported
|
||||
throw new RuntimeException("NOT SUPPORTED");
|
||||
}
|
||||
|
||||
byte[] compileToClassFile(CompilerEnvirons compilerEnv,
|
||||
@ -1065,6 +1019,9 @@ public class Codegen extends Interpreter
|
||||
= "(Lorg/mozilla/javascript/Scriptable;"
|
||||
+"Lorg/mozilla/javascript/Context;I)V";
|
||||
|
||||
private static final Object globalLock = new Object();
|
||||
private static int globalSerialClassCounter;
|
||||
|
||||
private CompilerEnvirons compilerEnv;
|
||||
|
||||
private ObjArray directCallTargets;
|
||||
|
@ -1,136 +0,0 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
* Roger Lawrence
|
||||
* Andi Vajda
|
||||
* Kemal Bayram
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
|
||||
package org.mozilla.javascript.optimizer;
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
public class OptClassNameHelper extends ClassNameHelper {
|
||||
|
||||
public OptClassNameHelper() {
|
||||
setClassName(null);
|
||||
}
|
||||
|
||||
synchronized String getScriptClassName(boolean primary)
|
||||
{
|
||||
StringBuffer s = new StringBuffer();
|
||||
if (packageName != null && packageName.length() > 0) {
|
||||
s.append(packageName);
|
||||
s.append('.');
|
||||
}
|
||||
s.append(initialName);
|
||||
if (explicitInitialName) {
|
||||
if (!primary) {
|
||||
s.append(++serial);
|
||||
}
|
||||
} else {
|
||||
s.append(globalSerial++);
|
||||
}
|
||||
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public String getTargetClassFileName() {
|
||||
throw new IllegalArgumentException(
|
||||
"The method depends on removed deprecated future.");
|
||||
}
|
||||
|
||||
public void setTargetClassFileName(String classFileName) {
|
||||
throw new IllegalArgumentException(
|
||||
"The method depends on removed deprecated future.");
|
||||
}
|
||||
|
||||
public String getTargetPackage() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void setTargetPackage(String targetPackage) {
|
||||
this.packageName = targetPackage;
|
||||
}
|
||||
|
||||
public Class getTargetExtends() {
|
||||
return targetExtends;
|
||||
}
|
||||
|
||||
public void setTargetExtends(Class extendsClass) {
|
||||
targetExtends = extendsClass;
|
||||
}
|
||||
|
||||
public Class[] getTargetImplements() {
|
||||
return targetImplements;
|
||||
}
|
||||
|
||||
public void setTargetImplements(Class[] implementsClasses) {
|
||||
targetImplements = implementsClasses;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return initialName;
|
||||
}
|
||||
|
||||
public void setClassName(String initialName) {
|
||||
if (initialName != null) {
|
||||
this.initialName = initialName;
|
||||
explicitInitialName = true;
|
||||
} else {
|
||||
packageName = "org.mozilla.javascript.gen";
|
||||
this.initialName = "c";
|
||||
classRepository = null;
|
||||
explicitInitialName = false;
|
||||
}
|
||||
serial = 0;
|
||||
}
|
||||
|
||||
public ClassRepository getClassRepository() {
|
||||
return classRepository;
|
||||
}
|
||||
|
||||
public void setClassRepository(ClassRepository classRepository) {
|
||||
this.classRepository = classRepository;
|
||||
}
|
||||
|
||||
private boolean explicitInitialName;
|
||||
private String packageName;
|
||||
private String initialName;
|
||||
private int globalSerial=1;
|
||||
private int serial;
|
||||
private Class targetExtends;
|
||||
private Class[] targetImplements;
|
||||
private ClassRepository classRepository;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user