cosmetics: end-of-line whitespace removal

This commit is contained in:
igor%mir2.org 2002-02-11 01:33:23 +00:00
Родитель e19dc64c61
Коммит 5da4f07e74
118 изменённых файлов: 2758 добавлений и 2820 удалений

Просмотреть файл

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<!--
Build file for Rhino using Ant (see http://jakarta.apache.org/ant/index.html)
Requires Ant version 1.2
-->
<project name="src" default="build" basedir=".">
<target name="properties">
<property name="nest" value=".."/>
<property name="nest" value=".."/>
</target>
<target name="compile" depends="properties">
<javac srcdir="."
destdir="${nest}/${build.dest}"
destdir="${nest}/${build.dest}"
includes="org/**/*.java"
deprecation="on"
debug="${debug}">

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
@ -37,9 +37,9 @@ package org.mozilla.classfile;
/**
* This class provides opcode values expected by the JVM in Java class files.
*
*
* It also provides tables for internal use by the ClassFileWriter.
*
*
* @author Roger Lawrence
*/
public class ByteCode {
@ -279,9 +279,9 @@ public class ByteCode {
PUTFIELD_QUICK_W = (byte)0xE4,
IMPDEP1 = (byte)0xFE,
IMPDEP2 = (byte)0xFF;
/**
/**
* Types for the NEWARRAY opcode.
*/
public static final byte
@ -297,7 +297,7 @@ public class ByteCode {
/**
* Number of bytes of operands generated after the opcode.
*/
static final byte[] extra = {
static final byte[] extra = {
/* NOP */ 0,
/* ACONST_NULL */ 0,
/* ICONST_M1 */ 0,
@ -559,7 +559,7 @@ public class ByteCode {
/**
* Number of operands accompanying the opcode.
*/
static final byte[] opcodeCount = {
static final byte[] opcodeCount = {
/* NOP */ 0,
/* ACONST_NULL */ 0,
/* ICONST_M1 */ 0,
@ -821,7 +821,7 @@ public class ByteCode {
/**
* The effect on the operand stack of a given opcode.
*/
static final byte[] stackChange = {
static final byte[] stackChange = {
/* NOP */ 0,
/* ACONST_NULL */ 1,
/* ICONST_M1 */ 1,

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
@ -42,27 +42,27 @@ import java.util.*;
/**
* ClassFileWriter
*
* A ClassFileWriter is used to write a Java class file. Methods are
* provided to create fields and methods, and within methods to write
*
* A ClassFileWriter is used to write a Java class file. Methods are
* provided to create fields and methods, and within methods to write
* Java bytecodes.
*
*
* @author Roger Lawrence
*/
public class ClassFileWriter extends LabelTable {
/**
* Construct a ClassFileWriter for a class.
*
*
* @param className the name of the class to write, including
* full package qualification.
* @param superClassName the name of the superclass of the class
* to write, including full package qualification.
* @param sourceFileName the name of the source file to use for
* full package qualification.
* @param superClassName the name of the superclass of the class
* to write, including full package qualification.
* @param sourceFileName the name of the source file to use for
* producing debug information, or null if debug information
* is not desired
*/
public ClassFileWriter(String className, String superClassName,
public ClassFileWriter(String className, String superClassName,
String sourceFileName)
{
itsConstantPool = new ConstantPool();
@ -72,16 +72,16 @@ public class ClassFileWriter extends LabelTable {
itsSourceFileNameIndex = itsConstantPool.addUtf8(sourceFileName);
itsFlags = ACC_PUBLIC;
}
/**
* Add an interface implemented by this class.
*
* This method may be called multiple times for classes that
*
* This method may be called multiple times for classes that
* implement multiple interfaces.
*
* @param interfaceName a name of an interface implemented
* by the class being written, including full package
* qualification.
*
* @param interfaceName a name of an interface implemented
* by the class being written, including full package
* qualification.
*/
public void addInterface(String interfaceName) {
short interfaceIndex = itsConstantPool.addClass(interfaceName);
@ -102,8 +102,8 @@ public class ClassFileWriter extends LabelTable {
/**
* Set the class's flags.
*
* Flags must be a set of the following flags, bitwise or'd
*
* Flags must be a set of the following flags, bitwise or'd
* together:
* ACC_PUBLIC
* ACC_PRIVATE
@ -119,14 +119,14 @@ public class ClassFileWriter extends LabelTable {
public static String fullyQualifiedForm(String name) {
return name.replace('.', '/');
}
}
/**
* Add a field to the class.
*
*
* @param fieldName the name of the field
* @param type the type of the field using ...
* @param flags the attributes of the field, such as ACC_PUBLIC, etc.
* @param flags the attributes of the field, such as ACC_PUBLIC, etc.
* bitwise or'd together
*/
public void addField(String fieldName, String type, short flags) {
@ -135,17 +135,17 @@ public class ClassFileWriter extends LabelTable {
itsFields.addElement(
new ClassFileField(fieldNameIndex, typeIndex, flags));
}
/**
* Add a field to the class.
*
*
* @param fieldName the name of the field
* @param type the type of the field using ...
* @param flags the attributes of the field, such as ACC_PUBLIC, etc.
* @param flags the attributes of the field, such as ACC_PUBLIC, etc.
* bitwise or'd together
* @param value an initial integral value
*/
public void addField(String fieldName, String type, short flags,
public void addField(String fieldName, String type, short flags,
int value)
{
short fieldNameIndex = itsConstantPool.addUtf8(fieldName);
@ -158,17 +158,17 @@ public class ClassFileWriter extends LabelTable {
itsFields.addElement(
new ClassFileField(fieldNameIndex, typeIndex, flags, cvAttr));
}
/**
* Add a field to the class.
*
*
* @param fieldName the name of the field
* @param type the type of the field using ...
* @param flags the attributes of the field, such as ACC_PUBLIC, etc.
* @param flags the attributes of the field, such as ACC_PUBLIC, etc.
* bitwise or'd together
* @param value an initial long value
*/
public void addField(String fieldName, String type, short flags,
public void addField(String fieldName, String type, short flags,
long value)
{
short fieldNameIndex = itsConstantPool.addUtf8(fieldName);
@ -181,17 +181,17 @@ public class ClassFileWriter extends LabelTable {
itsFields.addElement(
new ClassFileField(fieldNameIndex, typeIndex, flags, cvAttr));
}
/**
* Add a field to the class.
*
*
* @param fieldName the name of the field
* @param type the type of the field using ...
* @param flags the attributes of the field, such as ACC_PUBLIC, etc.
* @param flags the attributes of the field, such as ACC_PUBLIC, etc.
* bitwise or'd together
* @param value an initial double value
*/
public void addField(String fieldName, String type, short flags,
public void addField(String fieldName, String type, short flags,
double value)
{
short fieldNameIndex = itsConstantPool.addUtf8(fieldName);
@ -203,33 +203,33 @@ public class ClassFileWriter extends LabelTable {
cvAttr[3] = itsConstantPool.addConstant(value);
itsFields.addElement(
new ClassFileField(fieldNameIndex, typeIndex, flags, cvAttr));
}
}
/**
* Add a method and begin adding code.
*
*
* This method must be called before other methods for adding code,
* exception tables, etc. can be invoked.
*
*
* @param methodName the name of the method
* @param type a string representing the type
* @param flags the attributes of the field, such as ACC_PUBLIC, etc.
* @param flags the attributes of the field, such as ACC_PUBLIC, etc.
* bitwise or'd together
*/
public void startMethod(String methodName, String type, short flags) {
short methodNameIndex = itsConstantPool.addUtf8(methodName);
short typeIndex = itsConstantPool.addUtf8(type);
itsCurrentMethod = new ClassFileMethod(methodNameIndex, typeIndex,
itsCurrentMethod = new ClassFileMethod(methodNameIndex, typeIndex,
flags);
itsMethods.addElement(itsCurrentMethod);
}
/**
* Complete generation of the method.
*
* After this method is called, no more code can be added to the
*
* After this method is called, no more code can be added to the
* method begun with <code>startMethod</code>.
*
*
* @param maxLocals the maximum number of local variable slots
* (a.k.a. Java registers) used by the method
* @param vars the VariableTable of the variables for the method,
@ -253,7 +253,7 @@ public class ClassFileWriter extends LabelTable {
// 4 bytes for each entry
lineNumberTableLength = 6 + 2 + (itsLineNumberTableTop * 4);
}
int variableTableLength = 0;
if (vars != null) {
// 6 bytes for the attribute header
@ -269,7 +269,7 @@ public class ClassFileWriter extends LabelTable {
4 + // code_length
itsCodeBufferTop +
2 + // exception_table_length
(itsExceptionTableTop * 8) +
(itsExceptionTableTop * 8) +
2 + // attributes_count
lineNumberTableLength +
variableTableLength;
@ -292,14 +292,14 @@ public class ClassFileWriter extends LabelTable {
codeAttribute[index++] = (byte)(itsCodeBufferTop >> 16);
codeAttribute[index++] = (byte)(itsCodeBufferTop >> 8);
codeAttribute[index++] = (byte)itsCodeBufferTop;
System.arraycopy(itsCodeBuffer, 0, codeAttribute, index,
System.arraycopy(itsCodeBuffer, 0, codeAttribute, index,
itsCodeBufferTop);
index += itsCodeBufferTop;
if (itsExceptionTableTop > 0) {
codeAttribute[index++] = (byte)(itsExceptionTableTop >> 8);
codeAttribute[index++] = (byte)(itsExceptionTableTop);
codeAttribute[index++] = (byte)(itsExceptionTableTop);
for (int i = 0; i < itsExceptionTableTop; i++) {
short startPC = itsExceptionTable[i].getStartPC(itsLabelTable);
codeAttribute[index++] = (byte)(startPC >> 8);
@ -313,13 +313,13 @@ public class ClassFileWriter extends LabelTable {
short catchType = itsExceptionTable[i].getCatchType();
codeAttribute[index++] = (byte)(catchType >> 8);
codeAttribute[index++] = (byte)(catchType);
}
}
}
else {
codeAttribute[index++] = (byte)(0); // exception table length
codeAttribute[index++] = (byte)(0);
}
int attributeCount = 0;
if (itsLineNumberTable != null)
attributeCount++;
@ -327,7 +327,7 @@ public class ClassFileWriter extends LabelTable {
attributeCount++;
codeAttribute[index++] = (byte)(0); // (hibyte) attribute count...
codeAttribute[index++] = (byte)(attributeCount); // (lobyte) attribute count
if (itsLineNumberTable != null) {
int lineNumberTableAttrIndex
= itsConstantPool.addUtf8("LineNumberTable");
@ -347,7 +347,7 @@ public class ClassFileWriter extends LabelTable {
codeAttribute[index++] = (byte)itsLineNumberTable[i];
}
}
if (vars != null) {
int variableTableAttrIndex
= itsConstantPool.addUtf8("LocalVariableTable");
@ -363,36 +363,36 @@ public class ClassFileWriter extends LabelTable {
codeAttribute[index++] = (byte)varCount;
for (int i = 0; i < varCount; i++) {
LocalVariable lvar = vars.getVariable(i);
// start pc
int startPc = lvar.getStartPC();
codeAttribute[index++] = (byte)(startPc >> 8);
codeAttribute[index++] = (byte)startPc;
// length
int length = itsCodeBufferTop - startPc;
codeAttribute[index++] = (byte)(length >> 8);
codeAttribute[index++] = (byte)length;
// name index
int nameIndex
= itsConstantPool.addUtf8(lvar.getName());
codeAttribute[index++] = (byte)(nameIndex >> 8);
codeAttribute[index++] = (byte)nameIndex;
// descriptor index
int descriptorIndex = itsConstantPool.addUtf8(
lvar.isNumber()
lvar.isNumber()
? "D"
: "Ljava/lang/Object;");
codeAttribute[index++] = (byte)(descriptorIndex >> 8);
codeAttribute[index++] = (byte)descriptorIndex;
// index
int jreg = lvar.getJRegister();
codeAttribute[index++] = (byte)(jreg >> 8);
codeAttribute[index++] = (byte)jreg;
}
codeAttribute[index++] = (byte)jreg;
}
}
itsCurrentMethod.setCodeAttribute(codeAttribute);
@ -409,7 +409,7 @@ public class ClassFileWriter extends LabelTable {
/**
* Add the single-byte opcode to the current method.
*
*
* @param theOpCode the opcode of the bytecode
*/
public void add(byte theOpCode) {
@ -433,7 +433,7 @@ public class ClassFileWriter extends LabelTable {
/**
* Add a single-operand opcode to the current method.
*
*
* @param theOpCode the opcode of the bytecode
* @param theOperand the operand of the bytecode
*/
@ -491,8 +491,8 @@ public class ClassFileWriter extends LabelTable {
int theLabel = theOperand & 0x7FFFFFFF;
int targetPC = itsLabelTable[theLabel].getPC();
if (DEBUGLABELS) {
System.out.println("Fixing branch to " +
theLabel + " at " + targetPC +
System.out.println("Fixing branch to " +
theLabel + " at " + targetPC +
" from " + branchPC);
}
if (targetPC != -1) {
@ -602,37 +602,37 @@ public class ClassFileWriter extends LabelTable {
throw new RuntimeException("Unexpected opcode for 1 operand");
}
}
/**
* Generate the load constant bytecode for the given integer.
*
*
* @param k the constant
*/
public void addLoadConstant(int k) {
add(ByteCode.LDC, itsConstantPool.addConstant(k));
}
/**
* Generate the load constant bytecode for the given long.
*
*
* @param k the constant
*/
public void addLoadConstant(long k) {
add(ByteCode.LDC2_W, itsConstantPool.addConstant(k));
}
/**
* Generate the load constant bytecode for the given float.
*
*
* @param k the constant
*/
public void addLoadConstant(float k) {
add(ByteCode.LDC, itsConstantPool.addConstant(k));
}
/**
* Generate the load constant bytecode for the given double.
*
*
* @param k the constant
*/
public void addLoadConstant(double k) {
@ -641,7 +641,7 @@ public class ClassFileWriter extends LabelTable {
/**
* Generate the load constant bytecode for the given string.
*
*
* @param k the constant
*/
public void addLoadConstant(String k) {
@ -650,7 +650,7 @@ public class ClassFileWriter extends LabelTable {
/**
* Add the given two-operand bytecode to the current method.
*
*
* @param theOpCode the opcode of the bytecode
* @param theOperand1 the first operand of the bytecode
* @param theOperand2 the second operand of the bytecode
@ -741,9 +741,9 @@ public class ClassFileWriter extends LabelTable {
}
if (itsStackTop > itsMaxStack) itsMaxStack = itsStackTop;
}
public void add(byte theOpCode, String className, String fieldName,
public void add(byte theOpCode, String className, String fieldName,
String fieldType)
{
if (DEBUGCODE)
@ -780,7 +780,7 @@ public class ClassFileWriter extends LabelTable {
System.out.println("After " + Integer.toHexString(theOpCode & 0xFF) + " stack = " + itsStackTop);
}
}
public void add(byte theOpCode, String className, String methodName,
String parametersType, String returnType)
{
@ -836,7 +836,7 @@ public class ClassFileWriter extends LabelTable {
System.out.println("After " + Integer.toHexString(theOpCode & 0xFF) + " stack = " + itsStackTop);
}
}
public int markLabel(int theLabel) {
return super.markLabel(theLabel, (short)itsCodeBufferTop);
}
@ -853,7 +853,7 @@ public class ClassFileWriter extends LabelTable {
/**
* Get the current offset into the code of the current method.
*
*
* @return an integer representing the offset
*/
public int getCurrentCodeOffset() {
@ -897,7 +897,7 @@ public class ClassFileWriter extends LabelTable {
itsCodeBuffer[itsCodeBufferTop++] = b;
}
}
public void addExceptionHandler(int startLabel, int endLabel,
int handlerLabel, String catchClassName)
{
@ -907,9 +907,9 @@ public class ClassFileWriter extends LabelTable {
throw new RuntimeException("Bad endLabel");
if ((handlerLabel & 0x80000000) != 0x80000000)
throw new RuntimeException("Bad handlerLabel");
/*
* If catchClassName is null, use 0 for the catch_type_index; which
* If catchClassName is null, use 0 for the catch_type_index; which
* means catch everything. (Even when the verifier has let you throw
* something other than a Throwable.)
*/
@ -921,7 +921,7 @@ public class ClassFileWriter extends LabelTable {
catchClassName == null
? 0
: itsConstantPool.addClass(catchClassName));
if (itsExceptionTable == null) {
itsExceptionTable = new ExceptionTableEntry[ExceptionTableSize];
itsExceptionTable[0] = newEntry;
@ -937,7 +937,7 @@ public class ClassFileWriter extends LabelTable {
}
itsExceptionTable[itsExceptionTableTop++] = newEntry;
}
}
public void addLineNumberEntry(short lineNumber) {
@ -965,15 +965,15 @@ public class ClassFileWriter extends LabelTable {
/**
* Write the class file to the OutputStream.
*
*
* @param oStream the stream to write to
* @throws IOException if writing to the stream produces an exception
*/
public void write(OutputStream oStream)
public void write(OutputStream oStream)
throws IOException
{
DataOutputStream out = new DataOutputStream(oStream);
short sourceFileAttributeNameIndex = 0;
if (itsSourceFileNameIndex != 0)
sourceFileAttributeNameIndex
@ -983,7 +983,7 @@ public class ClassFileWriter extends LabelTable {
itsConstantPool.write(out);
out.writeShort(itsFlags);
out.writeShort(itsThisClassIndex);
out.writeShort(itsSuperClassIndex);
out.writeShort(itsSuperClassIndex);
out.writeShort(itsInterfaces.size());
for (int i = 0; i < itsInterfaces.size(); i++) {
out.writeShort(((Short)(itsInterfaces.elementAt(i))).shortValue());
@ -1005,7 +1005,7 @@ public class ClassFileWriter extends LabelTable {
else
out.writeShort(0); // no attributes
}
/*
Really weird. Returns an int with # parameters in hi 16 bits, and
# slots occupied by parameters in the low 16 bits. If Java really
@ -1076,7 +1076,7 @@ public class ClassFileWriter extends LabelTable {
private byte itsCodeBuffer[];
private int itsCodeBufferTop;
private ConstantPool itsConstantPool;
private short itsSourceFileAttributeIndex;
@ -1086,7 +1086,7 @@ public class ClassFileWriter extends LabelTable {
private short itsMaxStack;
private short itsMaxLocals;
private Vector itsMethods = new Vector();
private Vector itsFields = new Vector();
private Vector itsInterfaces = new Vector();
@ -1099,8 +1099,8 @@ public class ClassFileWriter extends LabelTable {
}
class ExceptionTableEntry {
ExceptionTableEntry(int startLabel, int endLabel,
ExceptionTableEntry(int startLabel, int endLabel,
int handlerLabel, short catchType)
{
itsStartLabel = startLabel;
@ -1108,7 +1108,7 @@ class ExceptionTableEntry {
itsHandlerLabel = handlerLabel;
itsCatchType = catchType;
}
short getStartPC(Label labelTable[])
{
short pc = labelTable[itsStartLabel & 0x7FFFFFFF].getPC();
@ -1116,7 +1116,7 @@ class ExceptionTableEntry {
throw new RuntimeException("start label not defined");
return pc;
}
short getEndPC(Label labelTable[])
{
short pc = labelTable[itsEndLabel & 0x7FFFFFFF].getPC();
@ -1124,7 +1124,7 @@ class ExceptionTableEntry {
throw new RuntimeException("end label not defined");
return pc;
}
short getHandlerPC(Label labelTable[])
{
short pc = labelTable[itsHandlerLabel & 0x7FFFFFFF].getPC();
@ -1132,12 +1132,12 @@ class ExceptionTableEntry {
throw new RuntimeException("handler label not defined");
return pc;
}
short getCatchType()
{
return itsCatchType;
}
private int itsStartLabel;
private int itsEndLabel;
private int itsHandlerLabel;
@ -1191,12 +1191,12 @@ class ClassFileMethod {
itsTypeIndex = typeIndex;
itsFlags = flags;
}
void setCodeAttribute(byte codeAttribute[])
{
itsCodeAttribute = codeAttribute;
}
void write(DataOutputStream out) throws IOException
{
out.writeShort(itsFlags);
@ -1252,7 +1252,7 @@ class ConstantPool {
itsPool[itsTop++] = (byte)k;
return (short)(itsTopIndex++);
}
short addConstant(long k)
{
ensure(9);
@ -1269,7 +1269,7 @@ class ConstantPool {
itsTopIndex += 2;
return index;
}
short addConstant(float k)
{
ensure(5);
@ -1281,7 +1281,7 @@ class ConstantPool {
itsPool[itsTop++] = (byte)bits;
return (short)(itsTopIndex++);
}
short addConstant(double k)
{
ensure(9);
@ -1299,7 +1299,7 @@ class ConstantPool {
itsTopIndex += 2;
return index;
}
short addConstant(String k)
{
Utf8StringIndexPair theIndex = (Utf8StringIndexPair)(itsUtf8Hash.get(k));
@ -1316,7 +1316,7 @@ class ConstantPool {
}
return theIndex.itsStringIndex;
}
short addUtf8(String contents)
{
Utf8StringIndexPair theIndex = (Utf8StringIndexPair)(itsUtf8Hash.get(contents));
@ -1445,20 +1445,20 @@ class ConstantPool {
private Hashtable itsFieldRefHash = new Hashtable();
private Hashtable itsMethodRefHash = new Hashtable();
private Hashtable itsClassHash = new Hashtable();
private int itsTop;
private int itsTopIndex;
private byte itsPool[];
}
class Utf8StringIndexPair {
Utf8StringIndexPair(short utf8Index, short stringIndex)
{
itsUtf8Index = utf8Index;
itsStringIndex = stringIndex;
}
short itsUtf8Index;
short itsStringIndex;
}

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,13 +16,13 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Patrick Beard
* Igor Bukanov
*
*
* 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.
@ -51,7 +51,7 @@ public class DefiningClassLoader extends ClassLoader {
try {
if (getContextClassLoaderMethod != null) {
return (ClassLoader) getContextClassLoaderMethod.invoke(
Thread.currentThread(),
Thread.currentThread(),
new Object[0]);
}
} catch (IllegalAccessException e) {
@ -61,7 +61,7 @@ public class DefiningClassLoader extends ClassLoader {
}
return DefiningClassLoader.class.getClassLoader();
}
public Class defineClass(String name, byte data[]) {
return super.defineClass(name, data, 0, data.length);
}
@ -90,10 +90,10 @@ public class DefiningClassLoader extends ClassLoader {
// in the class initializer, which doesn't allow us to
// catch possible security exceptions.
Class threadClass = Class.forName("java.lang.Thread");
// We'd like to use "getContextClassLoader", but
// that's only available on Java2.
getContextClassLoaderMethod =
threadClass.getDeclaredMethod("getContextClassLoader",
// We'd like to use "getContextClassLoader", but
// that's only available on Java2.
getContextClassLoaderMethod =
threadClass.getDeclaredMethod("getContextClassLoader",
new Class[0]);
} catch (ClassNotFoundException e) {
// ignore exceptions; we'll use Class.forName instead.

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -99,7 +99,7 @@ class Arguments extends ScriptableObject {
public void put(String name, Scriptable start, Object value) {
if (name.equals("caller")) {
// Set "hasCaller" to false so that we won't look up a
// Set "hasCaller" to false so that we won't look up a
// computed value.
hasCaller = false;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Igor Bukanov
* Roger Lawrence
@ -52,11 +52,11 @@ public class BaseFunction extends IdScriptable implements Function {
obj.prototypePropertyAttrs = DONTENUM | READONLY | PERMANENT;
obj.addAsPrototype(MAX_PROTOTYPE_ID, cx, scope, sealed);
}
protected void fillConstructorProperties
(Context cx, IdFunction ctor, boolean sealed)
{
// Fix up bootstrapping problem: getPrototype of the IdFunction
// Fix up bootstrapping problem: getPrototype of the IdFunction
// can not return Function.prototype because Function object is not
// yet defined.
ctor.setPrototype(this);
@ -103,23 +103,23 @@ public class BaseFunction extends IdScriptable implements Function {
}
return super.getIdDefaultAttributes(id);
}
protected boolean hasIdValue(int id) {
if (id == Id_prototype) {
return prototypeProperty != NOT_FOUND;
}
else if (id == Id_arguments) {
// Should after delete Function.arguments its activation still
// be available during Function call?
// be available during Function call?
// This code assumes it should not: after default set/deleteIdValue
// hasIdValue/getIdValue would not be called again
// To handle the opposite case, set/deleteIdValue should be
// To handle the opposite case, set/deleteIdValue should be
// overwritten as well
return null != getActivation(Context.getContext());
}
return super.hasIdValue(id);
}
protected Object getIdValue(int id) {
switch (id) {
case Id_length: return wrap_int(getLength());
@ -130,7 +130,7 @@ public class BaseFunction extends IdScriptable implements Function {
}
return super.getIdValue(id);
}
protected void setIdValue(int id, Object value) {
if (id == Id_prototype) {
prototypeProperty = (value != null) ? value : NULL_TAG;
@ -161,7 +161,7 @@ public class BaseFunction extends IdScriptable implements Function {
}
public Object execMethod(int methodId, IdFunction f, Context cx,
Scriptable scope, Scriptable thisObj,
Scriptable scope, Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
@ -185,7 +185,7 @@ public class BaseFunction extends IdScriptable implements Function {
/**
* Make value as DontEnum, DontDelete, ReadOnly
* prototype property of this Function object
* prototype property of this Function object
*/
public void setImmunePrototypeProperty(Object value) {
prototypeProperty = (value != null) ? value : NULL_TAG;
@ -194,7 +194,7 @@ public class BaseFunction extends IdScriptable implements Function {
protected Scriptable getClassPrototype() {
Object protoVal = getPrototypeProperty();
if (protoVal == null
if (protoVal == null
|| !(protoVal instanceof Scriptable)
|| (protoVal == Undefined.instance))
protoVal = getClassPrototype(this, "Object");
@ -271,7 +271,7 @@ public class BaseFunction extends IdScriptable implements Function {
private Object getPrototypeProperty() {
Object result = prototypeProperty;
if (result == null) {
if (result == null) {
synchronized (this) {
result = prototypeProperty;
if (result == null) {
@ -294,7 +294,7 @@ public class BaseFunction extends IdScriptable implements Function {
// wacky case of a user defining a function Object(), we don't
// get an infinite loop trying to find the prototype.
prototypeProperty = obj;
Scriptable proto = getObjectPrototype(this);
Scriptable proto = getObjectPrototype(this);
if (proto != obj) {
// not the one we just made, it must remain grounded
obj.setPrototype(proto);
@ -306,22 +306,22 @@ public class BaseFunction extends IdScriptable implements Function {
// way of getting it that doesn't add to the invocation cost.
// TODO: add warning, error based on version
NativeCall activation = getActivation(Context.getContext());
return activation == null
? null
return activation == null
? null
: activation.get("arguments", activation);
}
NativeCall getActivation(Context cx) {
NativeCall activation = cx.currentActivation;
while (activation != null) {
if (activation.getFunctionObject() == this)
if (activation.getFunctionObject() == this)
return activation;
activation = activation.caller;
}
return null;
}
private static Object jsConstructor(Context cx, Scriptable scope,
private static Object jsConstructor(Context cx, Scriptable scope,
Object[] args)
{
int arglen = args.length;
@ -347,7 +347,7 @@ public class BaseFunction extends IdScriptable implements Function {
}
Object securityDomain = cx.getSecurityDomainForStackDepth(4);
Scriptable global = ScriptableObject.getTopLevelScope(scope);
// Compile the function with opt level of -1 to force interpreter
// mode.
int oldOptLevel = cx.getOptimizationLevel();
@ -355,7 +355,7 @@ public class BaseFunction extends IdScriptable implements Function {
NativeFunction fn;
try {
fn = (NativeFunction) cx.compileFunction(global, source,
filename, linep[0],
filename, linep[0],
securityDomain);
}
finally { cx.setOptimizationLevel(oldOptLevel); }
@ -395,11 +395,11 @@ public class BaseFunction extends IdScriptable implements Function {
: ScriptRuntime.toObject(cx, scope, args[0]);
Object[] newArgs;
if (args.length > 1) {
if ((args[1] instanceof NativeArray)
if ((args[1] instanceof NativeArray)
|| (args[1] instanceof Arguments))
newArgs = cx.getElements((Scriptable) args[1]);
else
throw NativeGlobal.typeError0("msg.arg.isnt.array", thisObj);
throw NativeGlobal.typeError0("msg.arg.isnt.array", thisObj);
}
else
newArgs = ScriptRuntime.emptyArgs;
@ -419,8 +419,8 @@ public class BaseFunction extends IdScriptable implements Function {
if (args.length == 0) {
Scriptable s = ScriptRuntime.toObject(cx, scope, val);
Scriptable topScope = s.getParentScope();
return ScriptRuntime.call(cx, val,
topScope, ScriptRuntime.emptyArgs,
return ScriptRuntime.call(cx, val,
topScope, ScriptRuntime.emptyArgs,
topScope);
} else {
Scriptable newThis = args[0] == null
@ -443,7 +443,7 @@ public class BaseFunction extends IdScriptable implements Function {
case Id_prototype: return "prototype";
case Id_arguments: return "arguments";
}
if (prototypeFlag) {
switch (id) {
case Id_constructor: return "constructor";
@ -463,7 +463,7 @@ public class BaseFunction extends IdScriptable implements Function {
Id_name = 3,
Id_prototype = 4,
Id_arguments = 5,
MAX_INSTANCE_ID = 5;
protected int mapNameToId(String s) {
@ -506,14 +506,14 @@ public class BaseFunction extends IdScriptable implements Function {
Id_toString = MAX_INSTANCE_ID + 2,
Id_apply = MAX_INSTANCE_ID + 3,
Id_call = MAX_INSTANCE_ID + 4,
MAX_PROTOTYPE_ID = MAX_INSTANCE_ID + 4;
// #/string_id_map#
protected String functionName;
private Object prototypeProperty;
private Object prototypeProperty;
private int prototypePropertyAttrs = DONTENUM;
private boolean prototypeFlag;

Просмотреть файл

@ -19,7 +19,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Waldemar Horwat
*
* Alternatively, the contents of this file may be used under the
@ -61,7 +61,7 @@ final class BinaryDigitReader {
if (digitPos == 0) {
if (start == end)
return -1;
char c = digits.charAt(start++);
if ('0' <= c && c <= '9')
digit = c - '0';

Просмотреть файл

@ -19,7 +19,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the

Просмотреть файл

@ -45,16 +45,16 @@ public interface ClassNameHelper {
public void setTargetPackage(String targetPackage);
public void setTargetExtends(Class extendsClass);
public void setTargetImplements(Class[] implementsClasses);
public ClassRepository getClassRepository();
public void setClassRepository(ClassRepository repository);
public String getClassName();
public void setClassName(String initialName);
public void reset();
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Andi Vajda
*
* Alternatively, the contents of this file may be used under the
@ -45,7 +45,7 @@ import java.io.*;
* @see Context
* @author Andi Vajda
*/
public interface ClassOutput {
public interface ClassOutput {
/**
* @param className the name of the class for which bytecode is ready.
* @param isTopLevel if true, represents the top-level script being compiled

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Kemal Bayram
*
* Alternatively, the contents of this file may be used under the
@ -43,13 +43,13 @@ import java.io.*;
* @see Context
* @author Kemal Bayram
*/
public interface ClassRepository {
public interface ClassRepository {
/**
* @param className the name of the class.
* @param classBytes a byte array of the generated class.
* @param isTopLevel if true, represents the top-level script being compiled.
* @return true if the class should be loaded, false otherwise.
* @return true if the class should be loaded, false otherwise.
*/
public boolean storeClass(String className, byte[] classBytes,
public boolean storeClass(String className, byte[] classBytes,
boolean isTopLevel) throws IOException;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -38,16 +38,16 @@
package org.mozilla.javascript;
/**
* Embeddings that wish to
* Embeddings that wish to
* @see org.mozilla.javascript.Context#addContextListener
*/
public interface ContextListener {
public void contextCreated(Context cx);
public void contextEntered(Context cx);
public void contextExited(Context cx);
public void contextReleased(Context cx);
}

Просмотреть файл

@ -50,14 +50,14 @@ class DToA {
static char BASEDIGIT(int digit) {
return (char)((digit >= 10) ? 'a' - 10 + digit : '0' + digit);
}
static final int
DTOSTR_STANDARD = 0, /* Either fixed or exponential format; round-trip */
DTOSTR_STANDARD_EXPONENTIAL = 1, /* Always exponential format; round-trip */
DTOSTR_FIXED = 2, /* Round to <precision> digits after the decimal point; exponential if number is large */
DTOSTR_EXPONENTIAL = 3, /* Always exponential format; <precision> significant digits */
DTOSTR_PRECISION = 4; /* Either fixed or exponential format; <precision> significant digits */
static final int Frac_mask = 0xfffff;
static final int Exp_shift = 20;
@ -79,13 +79,13 @@ class DToA {
static final int Int_max = 14;
static final int n_bigtens = 5;
static final double tens[] = {
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
1e20, 1e21, 1e22
};
static final double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
static int lo0bits(int y)
@ -261,7 +261,7 @@ class DToA {
int[] e = new int[1];
int[] bbits = new int[1];
b = d2b(df, e, bbits);
// JS_ASSERT(e < 0);
/* At this point df = b * 2^e. e must be less than zero because 0 < df < 1. */
@ -378,27 +378,27 @@ class DToA {
long dBits = Double.doubleToLongBits(d);
return (int)(dBits >> 32);
}
static double setWord0(double d, int i)
{
long dBits = Double.doubleToLongBits(d);
dBits = ((long)i << 32) | (dBits & 0x0FFFFFFFFL);
return Double.longBitsToDouble(dBits);
}
static int word1(double d)
{
long dBits = Double.doubleToLongBits(d);
return (int)(dBits);
}
/* Return b * 5^k. k must be nonnegative. */
// XXXX the C version built a cache of these
static BigInteger pow5mult(BigInteger b, int k)
{
return b.multiply(BigInteger.valueOf(5).pow(k));
}
static boolean roundOff(StringBuffer buf)
{
char lastCh;
@ -411,10 +411,10 @@ class DToA {
buf.append((char)(lastCh + 1));
return false;
}
/* Always emits at least one digit. */
/* If biasUp is set, then rounding in modes 2 and 3 will round away from zero
* when the number is exactly halfway between two representable values. For example,
* when the number is exactly halfway between two representable values. For example,
* rounding 2.5 to zero digits after the decimal point will return 3 and not 2.
* 2.49 will still round to 2, and 2.51 will still round to 3. */
/* bufsize should be at least 20 for modes 0 and 1. For the other modes,
@ -488,7 +488,7 @@ class DToA {
buf.append('0'); /* copy "0" to buffer */
return 1;
}
b = d2b(d, be, bbits);
if ((i = (int)(word0(d) >>> Exp_shift1 & (Exp_mask>>Exp_shift1))) != 0) {
d2 = setWord0(d, (word0(d) & Frac_mask1) | Exp_11);
@ -691,7 +691,7 @@ class DToA {
lastCh = '0';
break;
}
}
}
buf.append((char)(lastCh + 1));
return k + 1;
}
@ -721,7 +721,7 @@ class DToA {
lastCh = '0';
break;
}
}
}
buf.append((char)(lastCh + 1));
return k + 1;
}
@ -787,7 +787,7 @@ class DToA {
lastCh = '0';
break;
}
}
}
buf.append((char)(lastCh + 1));
}
break;
@ -888,7 +888,7 @@ class DToA {
S_hiWord = (S_hiWord << 8);
if (idx < S_bytes.length)
S_hiWord |= (S_bytes[idx] & 0xFF);
}
}
if ((i = (((s5 != 0) ? 32 - hi0bits(S_hiWord) : 1) + s2) & 0x1f) != 0)
i = 32 - i;
/* i is the number of leading zero bits in the most significant word of S*2^s2. */
@ -959,9 +959,9 @@ class DToA {
/* mlo/S = maximum acceptable error, divided by 10^k, if the output is less than d. */
/* mhi/S = maximum acceptable error, divided by 10^k, if the output is greater than d. */
for(i = 1;;i++) {
for(i = 1;;i++) {
BigInteger[] divResult = b.divideAndRemainder(S);
b = divResult[1];
b = divResult[1];
dig = (char)(divResult[0].intValue() + '0');
/* Do we yet have the shortest decimal string
* that will round to d?
@ -986,8 +986,8 @@ class DToA {
buf.append(dig);
return k + 1;
}
if ((j < 0)
|| ((j == 0)
if ((j < 0)
|| ((j == 0)
&& (mode == 0)
&& ((word1(d) & 1) == 0)
)) {
@ -1019,7 +1019,7 @@ class DToA {
if (roundOff(buf)) {
k++;
buf.append('1');
}
}
return k + 1;
}
buf.append((char)(dig + 1));
@ -1041,7 +1041,7 @@ class DToA {
for(i = 1;; i++) {
// (char)(dig = quorem(b,S) + '0');
BigInteger[] divResult = b.divideAndRemainder(S);
b = divResult[1];
b = divResult[1];
dig = (char)(divResult[0].intValue() + '0');
buf.append(dig);
if (i >= ilim)
@ -1066,7 +1066,7 @@ class DToA {
k++;
buf.append('1');
return k + 1;
}
}
}
else {
/* Strip trailing zeros */
@ -1158,7 +1158,7 @@ class DToA {
buffer.append('0');
} while (buffer.length() != p);
}
if (exponentialNotation) {
/* Insert a decimal point if more than one significand digit */
if (nDigits != 1) {

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -40,7 +40,7 @@ package org.mozilla.javascript;
import org.mozilla.javascript.debug.*;
public class DebuggableEngineImpl implements DebuggableEngine {
public DebuggableEngineImpl(Context cx) {
this.cx = cx;
}
@ -52,16 +52,16 @@ public class DebuggableEngineImpl implements DebuggableEngine {
* The engine will call the attached debugger's handleBreakpointHit
* method on the next line it executes if isLineStep is true.
* May be used from another thread to interrupt execution.
*
*
* @param isLineStep if true, break next line
*/
public void setBreakNextLine(boolean isLineStep) {
cx.inLineStepMode = isLineStep;
}
/**
* Return the value of the breakNextLine flag.
* @return true if the engine will break on execution of the
* @return true if the engine will break on execution of the
* next line.
*/
public boolean getBreakNextLine() {
@ -76,7 +76,7 @@ public class DebuggableEngineImpl implements DebuggableEngine {
public void setDebugger(Debugger debugger) {
cx.debugger = debugger;
}
/**
* Return the current debugger.
* @return the debugger, or null if none is attached.
@ -84,7 +84,7 @@ public class DebuggableEngineImpl implements DebuggableEngine {
public Debugger getDebugger() {
return cx.debugger;
}
/**
* Return the number of frames in current execution.
* @return the count of current frames
@ -92,7 +92,7 @@ public class DebuggableEngineImpl implements DebuggableEngine {
public int getFrameCount() {
return cx.frameStack == null ? 0 : cx.frameStack.size();
}
/**
* Return a frame from the current execution.
* Frames are numbered starting from 0 for the innermost
@ -100,12 +100,12 @@ public class DebuggableEngineImpl implements DebuggableEngine {
* @param frameNumber the number of the frame in the range
* [0,frameCount-1]
* @return the relevant DebugFrame, or null if frameNumber is out
* of range or the engine isn't currently saving
* of range or the engine isn't currently saving
* frames
*/
public DebugFrame getFrame(int frameNumber) {
return (DebugFrame) cx.frameStack.elementAt(cx.frameStack.size() - frameNumber - 1);
}
private Context cx;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -55,7 +55,7 @@ class DefaultErrorReporter implements ErrorReporter {
}
public EvaluatorException runtimeError(String message, String sourceName,
int line, String lineSource,
int line, String lineSource,
int lineOffset)
{
return new EvaluatorException(message);

Просмотреть файл

@ -18,9 +18,9 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roger Lawrence
*
*
* 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.
@ -38,7 +38,7 @@
package org.mozilla.javascript;
/**
* The class of exceptions raised by the engine as described in
* The class of exceptions raised by the engine as described in
* ECMA edition 3. See section 15.11.6 in particular.
*/
public class EcmaError extends RuntimeException {
@ -54,11 +54,11 @@ public class EcmaError extends RuntimeException {
* @param lineNumber the line number of the source
* @param columnNumber the columnNumber of the source (may be zero if
* unknown)
* @param lineSource the source of the line containing the error (may be
* @param lineSource the source of the line containing the error (may be
* null if unknown)
*/
public EcmaError(NativeError nativeError, String sourceName,
int lineNumber, int columnNumber, String lineSource)
public EcmaError(NativeError nativeError, String sourceName,
int lineNumber, int columnNumber, String lineSource)
{
super("EcmaError");
errorObject = nativeError;
@ -67,9 +67,9 @@ public class EcmaError extends RuntimeException {
this.columnNumber = columnNumber;
this.lineSource = lineSource;
}
/**
* Return a string representation of the error, which currently consists
* Return a string representation of the error, which currently consists
* of the name of the error together with the message.
*/
public String toString() {
@ -89,34 +89,34 @@ public class EcmaError extends RuntimeException {
buf.append(')');
return buf.toString();
}
/**
* Gets the name of the error.
*
*
* ECMA edition 3 defines the following
* errors: EvalError, RangeError, ReferenceError,
* errors: EvalError, RangeError, ReferenceError,
* SyntaxError, TypeError, and URIError. Additional error names
* may be added in the future.
*
*
* See ECMA edition 3, 15.11.7.9.
*
* @return the name of the error.
*
* @return the name of the error.
*/
public String getName() {
return errorObject.getName();
}
/**
* Gets the message corresponding to the error.
*
*
* See ECMA edition 3, 15.11.7.10.
*
*
* @return an implemenation-defined string describing the error.
*/
public String getMessage() {
return errorObject.getMessage();
}
/**
* Get the name of the source containing the error, or null
* if that information is not available.
@ -124,7 +124,7 @@ public class EcmaError extends RuntimeException {
public String getSourceName() {
return sourceName;
}
/**
* Returns the line number of the statement causing the error,
* or zero if not available.
@ -132,28 +132,28 @@ public class EcmaError extends RuntimeException {
public int getLineNumber() {
return lineNumber;
}
/**
* Get the error object corresponding to this exception.
*/
public Scriptable getErrorObject() {
return errorObject;
}
/**
* The column number of the location of the error, or zero if unknown.
*/
public int getColumnNumber() {
return columnNumber;
}
/**
* The source of the line causing the error, or zero if unknown.
*/
public String getLineSource() {
return lineSource;
}
private NativeError errorObject;
private String sourceName;
private int lineNumber;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -97,7 +97,7 @@ public interface ErrorReporter {
* @param lineOffset the offset into lineSource where problem was detected
* @return an EvaluatorException that will be thrown.
*/
EvaluatorException runtimeError(String message, String sourceName,
int line, String lineSource,
EvaluatorException runtimeError(String message, String sourceName,
int line, String lineSource,
int lineOffset);
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
@ -60,7 +60,7 @@ public class FunctionNode extends Node {
public boolean setRequiresActivation(boolean b) {
return itsNeedsActivation = b;
}
public boolean getCheckThis() {
return itsCheckThis;
}
@ -68,26 +68,26 @@ public class FunctionNode extends Node {
public void setCheckThis(boolean b) {
itsCheckThis = b;
}
/**
* There are three types of functions that can be defined. The first
* is a function statement. This is a function appearing as a top-level
* statement (i.e., not nested inside some other statement) in either a
* script or a function.
*
*
* The second is a function expression, which is a function appearing in
* an expression except for the third type, which is...
*
* The third type is a function expression where the expression is the
*
* The third type is a function expression where the expression is the
* top-level expression in an expression statement.
*
* The three types of functions have different treatment and must be
*
* The three types of functions have different treatment and must be
* distinquished.
*/
public static final byte FUNCTION_STATEMENT = 1;
public static final byte FUNCTION_EXPRESSION = 2;
public static final byte FUNCTION_EXPRESSION_STATEMENT = 3;
public byte getFunctionType() {
return itsFunctionType;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Igor Bukanov
* David C. Navas
@ -60,9 +60,9 @@ public class FunctionObject extends NativeFunction {
* The first form is a member with zero or more parameters
* of the following types: Object, String, boolean, Scriptable,
* byte, short, int, float, or double. The Long type is not supported
* because the double representation of a long (which is the
* because the double representation of a long (which is the
* EMCA-mandated storage type for Numbers) may lose precision.
* If the member is a Method, the return value must be void or one
* If the member is a Method, the return value must be void or one
* of the types allowed for parameters.<p>
*
* The runtime will perform appropriate conversions based
@ -172,11 +172,11 @@ public class FunctionObject extends NativeFunction {
type != Byte.TYPE &&
type != Short.TYPE &&
type != Integer.TYPE &&
type != Float.TYPE &&
type != Float.TYPE &&
type != Double.TYPE)
{
// Note that long is not supported.
throw Context.reportRuntimeError1("msg.bad.parms",
throw Context.reportRuntimeError1("msg.bad.parms",
methodName);
}
}
@ -192,7 +192,7 @@ public class FunctionObject extends NativeFunction {
setParentScope(scope);
setPrototype(getFunctionPrototype(scope));
Context cx = Context.getCurrentContext();
useDynamicScope = cx != null &&
useDynamicScope = cx != null &&
cx.hasCompileFunctionsWithDynamicScope();
}
@ -244,7 +244,7 @@ public class FunctionObject extends NativeFunction {
public static Method[] findMethods(Class clazz, String name) {
return findMethods(getMethodList(clazz), name);
}
static Method[] findMethods(Method[] methods, String name) {
// Usually we're just looking for a single method, so optimize
// for that case.
@ -284,7 +284,7 @@ public class FunctionObject extends NativeFunction {
try {
// getDeclaredMethods may be rejected by the security manager
// but getMethods is more expensive
if (!sawSecurityException)
if (!sawSecurityException)
methods = clazz.getDeclaredMethods();
} catch (SecurityException e) {
// If we get an exception once, give up on getDeclaredMethods
@ -295,7 +295,7 @@ public class FunctionObject extends NativeFunction {
}
int count = 0;
for (int i=0; i < methods.length; i++) {
if (sawSecurityException
if (sawSecurityException
? methods[i].getDeclaringClass() != clazz
: !Modifier.isPublic(methods[i].getModifiers()))
{
@ -337,7 +337,7 @@ public class FunctionObject extends NativeFunction {
setImmunePrototypeProperty(prototype);
prototype.setParentScope(this);
final int attr = ScriptableObject.DONTENUM |
ScriptableObject.PERMANENT |
ScriptableObject.READONLY;
@ -352,20 +352,20 @@ public class FunctionObject extends NativeFunction {
static public Object convertArg(Context cx, Scriptable scope,
Object arg, Class desired)
{
if (desired == ScriptRuntime.StringClass)
if (desired == ScriptRuntime.StringClass)
return ScriptRuntime.toString(arg);
if (desired == ScriptRuntime.IntegerClass ||
if (desired == ScriptRuntime.IntegerClass ||
desired == Integer.TYPE)
{
return new Integer(ScriptRuntime.toInt32(arg));
}
if (desired == ScriptRuntime.BooleanClass ||
if (desired == ScriptRuntime.BooleanClass ||
desired == Boolean.TYPE)
{
return ScriptRuntime.toBoolean(arg) ? Boolean.TRUE
return ScriptRuntime.toBoolean(arg) ? Boolean.TRUE
: Boolean.FALSE;
}
if (desired == ScriptRuntime.DoubleClass ||
if (desired == ScriptRuntime.DoubleClass ||
desired == Double.TYPE)
{
return new Double(ScriptRuntime.toNumber(arg));
@ -374,7 +374,7 @@ public class FunctionObject extends NativeFunction {
return ScriptRuntime.toObject(cx, scope, arg);
if (desired == ScriptRuntime.ObjectClass)
return arg;
// Note that the long type is not supported; see the javadoc for
// the constructor for this class
throw Context.reportRuntimeError1
@ -388,7 +388,7 @@ public class FunctionObject extends NativeFunction {
* Implements Function.call.
*
* @see org.mozilla.javascript.Function#call
* @exception JavaScriptException if the underlying Java method or
* @exception JavaScriptException if the underlying Java method or
* constructor threw an exception
*/
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
@ -506,8 +506,8 @@ public class FunctionObject extends NativeFunction {
return super.construct(cx, scope, args);
}
private final Object doInvoke(Object thisObj, Object[] args)
private final Object doInvoke(Object thisObj, Object[] args)
throws IllegalAccessException, InvocationTargetException
{
Invoker master = invokerMaster;
@ -520,7 +520,7 @@ public class FunctionObject extends NativeFunction {
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
}
return method.invoke(thisObj, args);
}
@ -557,15 +557,15 @@ public class FunctionObject extends NativeFunction {
throw WrappedException.wrapException(e);
}
}
boolean isVarArgsMethod() {
boolean isVarArgsMethod() {
return parmsLength == VARARGS_METHOD;
}
boolean isVarArgsConstructor() {
boolean isVarArgsConstructor() {
return parmsLength == VARARGS_CTOR;
}
static void setCachingEnabled(boolean enabled) {
if (!enabled) {
methodsCache = null;
@ -588,14 +588,14 @@ public class FunctionObject extends NativeFunction {
return null;
}
private static final String
private static final String
INVOKER_MASTER_CLASS = "org.mozilla.javascript.optimizer.InvokerImpl";
static Invoker invokerMaster = newInvokerMaster();
private static final short VARARGS_METHOD = -1;
private static final short VARARGS_CTOR = -2;
private static boolean sawSecurityException;
static Method[] methodsCache;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -43,7 +43,7 @@ package org.mozilla.javascript;
* @author Norris Boyd
*/
public class IRFactory {
public IRFactory(TokenStream ts, Scriptable scope) {
this.ts = ts;
this.scope = scope;
@ -52,7 +52,7 @@ public class IRFactory {
/**
* Script (for associating file/url names with toplevel scripts.)
*/
public Object createScript(Object body, String sourceName,
public Object createScript(Object body, String sourceName,
int baseLineno, int endLineno, Object source)
{
Node result = new Node(TokenStream.SCRIPT, sourceName);
@ -137,12 +137,12 @@ public class IRFactory {
{
if (catchCond == null)
catchCond = new Node(TokenStream.PRIMARY, TokenStream.TRUE);
Node result = new Node(TokenStream.CATCH, (Node)createName(varName),
Node result = new Node(TokenStream.CATCH, (Node)createName(varName),
(Node)catchCond, (Node)stmts);
result.setDatum(new Integer(lineno));
return result;
}
/**
* Throw
*/
@ -205,9 +205,9 @@ public class IRFactory {
public Object createBlock(int lineno) {
return new Node(TokenStream.BLOCK, lineno);
}
public Object createFunctionNode(String name, Object args,
Object statements)
public Object createFunctionNode(String name, Object args,
Object statements)
{
if (name == null)
name = "";
@ -215,11 +215,11 @@ public class IRFactory {
}
public Object createFunction(String name, Object args, Object statements,
String sourceName, int baseLineno,
String sourceName, int baseLineno,
int endLineno, Object source,
boolean isExpr)
{
FunctionNode f = (FunctionNode) createFunctionNode(name, args,
FunctionNode f = (FunctionNode) createFunctionNode(name, args,
statements);
f.setFunctionType(isExpr ? FunctionNode.FUNCTION_EXPRESSION
: FunctionNode.FUNCTION_STATEMENT);
@ -232,7 +232,7 @@ public class IRFactory {
result.putProp(Node.FUNCTION_PROP, f);
return result;
}
public void setFunctionExpressionStatement(Object o) {
Node n = (Node) o;
FunctionNode f = (FunctionNode) n.getProp(Node.FUNCTION_PROP);
@ -431,12 +431,12 @@ public class IRFactory {
Node GOTOToEnd = new Node(TokenStream.GOTO);
GOTOToEnd.putProp(Node.TARGET_PROP, endTarget);
pn.addChildToBack(GOTOToEnd);
if (hasCatch) {
/*
*
Given
try {
throw 3;
} catch (e: e instanceof Object) {
@ -471,11 +471,11 @@ public class IRFactory {
pn.putProp(Node.TARGET_PROP, catchTarget);
// mark it
pn.addChildToBack(catchTarget);
// get the exception object and store it in a temp
Node exn = createNewLocal(new Node(TokenStream.VOID));
pn.addChildToBack(new Node(TokenStream.POP, exn));
Node endCatch = new Node(TokenStream.TARGET);
// add [jsr finally?] goto end to each catch block
@ -484,42 +484,42 @@ public class IRFactory {
while (cb != null) {
Node catchStmt = new Node(TokenStream.BLOCK);
int catchLineNo = cb.getInt();
Node name = cb.getFirstChild();
Node cond = name.getNextSibling();
Node catchBlock = cond.getNextSibling();
cb.removeChild(name);
cb.removeChild(cond);
cb.removeChild(catchBlock);
Node newScope = createNewLocal(new Node(TokenStream.NEWSCOPE));
Node initScope = new Node(TokenStream.SETPROP, newScope,
new Node(TokenStream.STRING,
name.getString()),
Node initScope = new Node(TokenStream.SETPROP, newScope,
new Node(TokenStream.STRING,
name.getString()),
createUseLocal(exn));
catchStmt.addChildToBack(new Node(TokenStream.POP, initScope));
catchBlock.addChildToBack(new Node(TokenStream.LEAVEWITH));
Node GOTOToEndCatch = new Node(TokenStream.GOTO);
GOTOToEndCatch.putProp(Node.TARGET_PROP, endCatch);
catchBlock.addChildToBack(GOTOToEndCatch);
Node ifStmt = (Node) createIf(cond, catchBlock, null, catchLineNo);
// Try..catch produces "with" code in order to limit
// Try..catch produces "with" code in order to limit
// the scope of the exception object.
// OPT: We should be able to figure out the correct
// scoping at compile-time and avoid the
// runtime overhead.
Node withStmt = (Node) createWith(createUseLocal(newScope),
Node withStmt = (Node) createWith(createUseLocal(newScope),
ifStmt, catchLineNo);
catchStmt.addChildToBack(withStmt);
pn.addChildToBack(catchStmt);
// move to next cb
// move to next cb
cb = cb.getNextSibling();
}
// Generate code to rethrow if no catch clause was executed
Node rethrow = new Node(TokenStream.THROW, createUseLocal(exn));
pn.addChildToBack(rethrow);
@ -585,7 +585,7 @@ public class IRFactory {
Node elem = null;
int i = 0;
for (Node cursor = ((Node) obj).getFirstChild(); cursor != null;) {
// Move cursor to cursor.next before elem.next can be
// Move cursor to cursor.next before elem.next can be
// altered in new Node constructor
elem = cursor;
cursor = cursor.getNextSibling();
@ -751,7 +751,7 @@ public class IRFactory {
if (!hasSideEffects(childNode)
&& (nodeOp == TokenStream.POST)
&& (childType == TokenStream.NAME
&& (childType == TokenStream.NAME
|| childType == TokenStream.GETPROP
|| childType == TokenStream.GETELEM))
{
@ -842,7 +842,7 @@ public class IRFactory {
return createSetProp(nodeType, nodeOp, left.getFirstChild(),
id, right, convert, postfix);
default:
// TODO: This should be a ReferenceError--but that's a runtime
// TODO: This should be a ReferenceError--but that's a runtime
// exception. Should we compile an exception into the code?
reportError("msg.bad.lhs.assign");
return left;
@ -1015,7 +1015,7 @@ public class IRFactory {
return result;
}
private void reportError(String msgResource) {
if (scope != null)
@ -1025,16 +1025,16 @@ public class IRFactory {
scope);
else {
String message = Context.getMessage0(msgResource);
Context.reportError(message, ts.getSourceName(), ts.getLineno(),
Context.reportError(message, ts.getSourceName(), ts.getLineno(),
ts.getLine(), ts.getOffset());
}
}
// Only needed to get file/line information. Could create an interface
// that TokenStream implements if we want to make the connection less
// direct.
private TokenStream ts;
// Only needed to pass to the Erorr exception constructors
private Scriptable scope;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Igor Bukanov
*
* Alternatively, the contents of this file may be used under the
@ -50,19 +50,19 @@ public class IdFunction extends BaseFunction
this.master = master;
this.methodId = id;
}
public final int functionType() {
return functionType;
}
public void setFunctionType(int type) {
functionType = type;
}
public Scriptable getPrototype() {
// Lazy initialization of prototype: for native functions this
// may not be called at all
Scriptable proto = super.getPrototype();
Scriptable proto = super.getPrototype();
if (proto == null) {
proto = getFunctionPrototype(getParentScope());
setPrototype(proto);
@ -70,7 +70,7 @@ public class IdFunction extends BaseFunction
return proto;
}
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
@ -88,7 +88,7 @@ public class IdFunction extends BaseFunction
if (functionType != FUNCTION_ONLY) {
// It is program error not to return Scriptable from constructor
Scriptable result = (Scriptable)master.execMethod(methodId, this,
cx, scope,
cx, scope,
null, args);
postConstruction(result);
return result;
@ -117,29 +117,29 @@ public class IdFunction extends BaseFunction
sb.append(justbody ? "]\n" : "] }\n");
return sb.toString();
}
public int getArity() {
int arity = master.methodArity(methodId);
if (arity < 0) {
if (arity < 0) {
throw onBadMethodId(master, methodId);
}
return arity;
}
public int getLength() { return getArity(); }
/** Prepare to be used as constructor .
** @param scope constructor scope
** @param prototype DontEnum, DontDelete, ReadOnly prototype property
** @param prototype DontEnum, DontDelete, ReadOnly prototype property
** of the constructor */
public void initAsConstructor(Scriptable scope, Scriptable prototype) {
setFunctionType(FUNCTION_AND_CONSTRUCTOR);
setParentScope(scope);
setImmunePrototypeProperty(prototype);
}
static RuntimeException onBadMethodId(IdFunctionMaster master, int id) {
// It is program error to call id-like methods for unknown or
// It is program error to call id-like methods for unknown or
// non-function id
return new RuntimeException("BAD FUNCTION ID="+id+" MASTER="+master);
}

Просмотреть файл

@ -66,7 +66,7 @@ public abstract class IdScriptable extends ScriptableObject
public IdScriptable() {
activateIdMap(maxInstanceId());
}
public boolean has(String name, Scriptable start) {
if (maxId != 0) {
int id = mapNameToId(name);
@ -82,7 +82,7 @@ public abstract class IdScriptable extends ScriptableObject
int maxId = this.maxId;
L:if (maxId != 0) {
Object[] data = idMapData;
if (data == null) {
if (data == null) {
int id = mapNameToId(name);
if (id != 0) {
return getIdValue(id);
@ -112,7 +112,7 @@ public abstract class IdScriptable extends ScriptableObject
int id = mapNameToId(name);
if (id != 0) {
Object[] data = idMapData;
if (data == null) {
if (data == null) {
return getIdValue(id);
}
else {
@ -208,7 +208,7 @@ public abstract class IdScriptable extends ScriptableObject
/**
* Redefine ScriptableObject.defineProperty to allow changing
* values/attributes of id-based properties unless
* values/attributes of id-based properties unless
* getIdDefaultAttributes contains the READONLY attribute.
* @see #getIdDefaultAttributes
* @see org.mozilla.javascript.ScriptableObject#defineProperty
@ -235,11 +235,11 @@ public abstract class IdScriptable extends ScriptableObject
Object[] getIds(boolean getAll) {
Object[] result = super.getIds(getAll);
if (maxId != 0) {
Object[] ids = null;
int count = 0;
for (int id = maxId; id != 0; --id) {
if (hasValue(id)) {
if (getAll || (getAttributes(id) & DONTENUM) == 0) {
@ -279,8 +279,8 @@ public abstract class IdScriptable extends ScriptableObject
*/
protected abstract String getIdName(int id);
/** Get default attributes for id.
** Default implementation return DONTENUM that is the standard attribute
/** Get default attributes for id.
** Default implementation return DONTENUM that is the standard attribute
** for core EcmaScript function. Typically descendants need to overwrite
** this for non-function attributes like length to return
** DONTENUM | READONLY | PERMANENT or DONTENUM | PERMANENT
@ -295,7 +295,7 @@ public abstract class IdScriptable extends ScriptableObject
return true;
}
/** Get id value.
/** Get id value.
** If id value is constant, descendant can call cacheIdValue to store
** value in the permanent cache.
** Default implementation creates IdFunction instance for given id
@ -308,7 +308,7 @@ public abstract class IdScriptable extends ScriptableObject
}
/**
* Set id value.
* Set id value.
* IdScriptable never calls this method if result of
* <code>getIdDefaultAttributes(id)</code> contains READONLY attribute.
* Descendants can overwrite this method to provide custom handler for
@ -319,10 +319,10 @@ public abstract class IdScriptable extends ScriptableObject
ensureIdData()[id - 1] = (value != null) ? value : NULL_TAG;
}
}
/**
* Store value in permanent cache unless value was already assigned to id.
* After this call IdScriptable never calls hasIdValue and getIdValue
* After this call IdScriptable never calls hasIdValue and getIdValue
* for the given id.
*/
protected Object cacheIdValue(int id, Object value) {
@ -338,9 +338,9 @@ public abstract class IdScriptable extends ScriptableObject
}
return value;
}
/**
* Delete value represented by id so hasIdValue return false.
* Delete value represented by id so hasIdValue return false.
* IdScriptable never calls this method if result of
* <code>getIdDefaultAttributes(id)</code> contains PERMANENT attribute.
* Descendants can overwrite this method to provide custom handler for
@ -351,7 +351,7 @@ public abstract class IdScriptable extends ScriptableObject
ensureIdData()[id - 1] = NOT_FOUND;
}
}
/** 'thisObj' will be null if invoked as constructor, in which case
** instance of Scriptable should be returned. */
public Object execMethod(int methodId, IdFunction function,
@ -362,60 +362,60 @@ public abstract class IdScriptable extends ScriptableObject
throw IdFunction.onBadMethodId(this, methodId);
}
/** Get arity or defined argument count for method with given id.
/** Get arity or defined argument count for method with given id.
** Should return -1 if methodId is not known or can not be used
** with execMethod call. */
public int methodArity(int methodId) {
return -1;
}
/** Activate id support with the given maximum id */
protected void activateIdMap(int maxId) {
this.maxId = maxId;
}
/** Sets whether newly constructed function objects should be sealed */
protected void setSealFunctionsFlag(boolean sealed) {
setSetupFlag(SEAL_FUNCTIONS_FLAG, sealed);
}
/**
* Set parameters of function properties.
/**
* Set parameters of function properties.
* Currently only determines whether functions should use dynamic scope.
* @param cx context to read function parameters.
*
*
* @see org.mozilla.javascript.Context#hasCompileFunctionsWithDynamicScope
*/
protected void setFunctionParametrs(Context cx) {
setSetupFlag(USE_DYNAMIC_SCOPE_FLAG,
cx.hasCompileFunctionsWithDynamicScope());
}
private void setSetupFlag(int flag, boolean value) {
setupFlags = (byte)(value ? setupFlags | flag : setupFlags & ~flag);
}
/**
* Prepare this object to serve as the prototype property of constructor
/**
* Prepare this object to serve as the prototype property of constructor
* object with name <code>getClassName()<code> defined in
* <code>scope</code>.
* @param maxId maximum id available in prototype object
* @param cx current context
* @param scope object to define constructor in.
* @param sealed indicates whether object and all its properties should
* be sealed
*/
public void addAsPrototype(int maxId, Context cx, Scriptable scope,
boolean sealed)
* @param sealed indicates whether object and all its properties should
* be sealed
*/
public void addAsPrototype(int maxId, Context cx, Scriptable scope,
boolean sealed)
{
activateIdMap(maxId);
setSealFunctionsFlag(sealed);
setFunctionParametrs(cx);
int constructorId = mapNameToId("constructor");
if (constructorId == 0) {
// It is a bug to call this function without id for constructor
// It is a bug to call this function without id for constructor
throw new RuntimeException("No id for constructor property");
}
@ -451,7 +451,7 @@ public abstract class IdScriptable extends ScriptableObject
defineProperty(obj, getIdName(id), f, DONTENUM);
}
/**
/**
* Utility method for converting target object into native this.
* Possible usage would be to have a private function like realThis:
* <pre>
@ -479,7 +479,7 @@ public abstract class IdScriptable extends ScriptableObject
thisObj = thisObj.getPrototype();
if (thisObj != null) { return thisObj; }
}
throw NativeGlobal.typeError1("msg.incompat.call",
throw NativeGlobal.typeError1("msg.incompat.call",
f.getFunctionName(), f);
}
@ -512,7 +512,7 @@ public abstract class IdScriptable extends ScriptableObject
protected final Object wrap_boolean(boolean x) {
return x ? Boolean.TRUE : Boolean.FALSE;
}
private boolean hasValue(int id) {
Object value;
Object[] data = idMapData;
@ -527,12 +527,12 @@ public abstract class IdScriptable extends ScriptableObject
// Must be called only from synchronized (this)
private Object[] ensureIdData() {
Object[] data = idMapData;
if (data == null) {
if (data == null) {
idMapData = data = new Object[CACHE_NAMES ? maxId * 2 : maxId];
}
return data;
}
private int getAttributes(int id) {
int attributes = getIdDefaultAttributes(id) | extraIdAttributes;
byte[] array = attributesArray;
@ -545,7 +545,7 @@ public abstract class IdScriptable extends ScriptableObject
private void setAttributes(int id, int attributes) {
int defaultAttrs = getIdDefaultAttributes(id);
if ((attributes & defaultAttrs) != defaultAttrs) {
// It is a bug to set attributes to less restrictive values
// It is a bug to set attributes to less restrictive values
// then given by defaultAttrs
throw new RuntimeException("Attempt to unset default attributes");
}
@ -574,7 +574,7 @@ public abstract class IdScriptable extends ScriptableObject
private static final int USE_DYNAMIC_SCOPE_FLAG = 1 << 0;
private static final int SEAL_FUNCTIONS_FLAG = 1 << 1;
private byte setupFlags;
private byte extraIdAttributes;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Matthias Radestock
*
@ -42,20 +42,20 @@ import java.util.Vector;
/**
* Class ImporterTopLevel
*
* This class defines a ScriptableObject that can be instantiated
*
* This class defines a ScriptableObject that can be instantiated
* as a top-level ("global") object to provide functionality similar
* to Java's "import" statement.
* <p>
* This class can be used to create a top-level scope using the following code:
* This class can be used to create a top-level scope using the following code:
* <pre>
* Scriptable scope = new ImporterTopLevel(cx);
* </pre>
* Then JavaScript code will have access to the following methods:
* <ul>
* <li>importClass - will "import" a class by making its unqualified name
* <li>importClass - will "import" a class by making its unqualified name
* available as a property of the top-level scope
* <li>importPackage - will "import" all the classes of the package by
* <li>importPackage - will "import" all the classes of the package by
* searching for unqualified names as classes qualified
* by the given package.
* </ul>
@ -67,11 +67,11 @@ import java.util.Vector;
* js> importPackage(java.util)
* js> v = new Vector()
* []
*
*
* @author Norris Boyd
*/
public class ImporterTopLevel extends ScriptableObject {
/**
* @deprecated
*/
@ -83,7 +83,7 @@ public class ImporterTopLevel extends ScriptableObject {
cx.initStandardObjects(this);
init();
}
private void init() {
String[] names = { "importClass", "importPackage" };
@ -95,18 +95,18 @@ public class ImporterTopLevel extends ScriptableObject {
}
}
public String getClassName() {
public String getClassName() {
return "global";
}
public Object get(String name, Scriptable start) {
Object result = super.get(name, start);
if (result != NOT_FOUND)
if (result != NOT_FOUND)
return result;
if (name.equals("_packages_"))
if (name.equals("_packages_"))
return result;
Object plist = ScriptableObject.getProperty(start,"_packages_");
if (plist == NOT_FOUND)
if (plist == NOT_FOUND)
return result;
Object[] elements;
Context cx = Context.enter();
@ -128,7 +128,7 @@ public class ImporterTopLevel extends ScriptableObject {
}
return result;
}
public static void importClass(Context cx, Scriptable thisObj,
Object[] args, Function funObj) {
for (int i=0; i<args.length; i++) {
@ -147,7 +147,7 @@ public class ImporterTopLevel extends ScriptableObject {
thisObj.put(n,thisObj,cl);
}
}
public static void importPackage(Context cx, Scriptable thisObj,
Object[] args, Function funObj) {
Scriptable importedPackages;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
@ -38,14 +38,14 @@ package org.mozilla.javascript;
import java.io.Serializable;
import org.mozilla.javascript.debug.DebuggableScript;
class InterpretedFunction extends NativeFunction
implements DebuggableScript, Serializable
class InterpretedFunction extends NativeFunction
implements DebuggableScript, Serializable
{
static final long serialVersionUID = -6235150451107527319L;
InterpretedFunction(Context cx,
InterpreterData theData,
InterpreterData theData,
String[] argNames, short argCount)
{
itsData = theData;
@ -53,7 +53,7 @@ class InterpretedFunction extends NativeFunction
this.argCount = argCount;
init(cx);
}
void init(Context cx)
{
functionName = itsData.itsName;
@ -62,7 +62,7 @@ class InterpretedFunction extends NativeFunction
if (cx != null)
version = (short)cx.getLanguageVersion();
}
InterpretedFunction(InterpretedFunction theOther,
Scriptable theScope, Context cx)
{
@ -72,19 +72,19 @@ class InterpretedFunction extends NativeFunction
itsClosure = theScope;
init(cx);
}
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
{
if (itsClosure != null)
scope = itsClosure;
else if (!itsData.itsUseDynamicScope)
scope = getParentScope();
if (itsData.itsCheckThis)
if (itsData.itsCheckThis)
thisObj = ScriptRuntime.getThis(thisObj);
if (itsData.itsNeedsActivation) {
scope = ScriptRuntime.initVarObj(cx, scope, this, thisObj, args);
}
@ -98,32 +98,32 @@ class InterpretedFunction extends NativeFunction
}
}
}
public boolean isFunction() {
return true;
}
public Scriptable getScriptable() {
return this;
}
public String getSourceName() {
return itsData.itsSourceFile;
}
public int[] getLineNumbers() {
public int[] getLineNumbers() {
return itsData.itsLineNumberTable.getKeys();
}
public boolean placeBreakpoint(int line) { // XXX throw exn?
return itsData.placeBreakpoint(line);
}
public boolean removeBreakpoint(int line) {
return itsData.removeBreakpoint(line);
}
InterpreterData itsData;
Scriptable itsClosure;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
@ -42,7 +42,7 @@ import java.util.*;
public class InterpretedScript extends NativeScript implements DebuggableScript {
InterpretedScript(Context cx,
InterpreterData theData,
InterpreterData theData,
String[] argNames, short argCount)
{
itsData = theData;
@ -50,48 +50,48 @@ public class InterpretedScript extends NativeScript implements DebuggableScript
this.argCount = argCount;
functionName = "";
nestedFunctions = itsData.itsNestedFunctions;
version = (short)cx.getLanguageVersion();
version = (short)cx.getLanguageVersion();
}
public Object exec(Context cx, Scriptable scope)
throws JavaScriptException
{
return call(cx, scope, scope, null);
return call(cx, scope, scope, null);
}
public Object call(Context cx, Scriptable scope,
public Object call(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
throws JavaScriptException
{
scope = ScriptRuntime.initScript(cx, scope, this, thisObj,
scope = ScriptRuntime.initScript(cx, scope, this, thisObj,
itsData.itsFromEvalCode);
return Interpreter.interpret(cx, scope, thisObj, args, this, itsData);
return Interpreter.interpret(cx, scope, thisObj, args, this, itsData);
}
public boolean isFunction() {
return false;
}
public Scriptable getScriptable() {
return this;
}
public String getSourceName() {
return itsData.itsSourceFile;
}
public int[] getLineNumbers() {
return itsData.itsLineNumberTable.getKeys();
}
public boolean placeBreakpoint(int line) { // XXX throw exn?
return itsData.placeBreakpoint(line);
}
public boolean removeBreakpoint(int line) {
return itsData.removeBreakpoint(line);
}
InterpreterData itsData;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
@ -41,16 +41,16 @@ import java.io.Serializable;
class InterpreterData implements Serializable {
static final long serialVersionUID = 4815333329084415557L;
static final int INITIAL_MAX_ICODE_LENGTH = 1024;
static final int INITIAL_STRINGTABLE_SIZE = 64;
static final int INITIAL_NUMBERTABLE_SIZE = 64;
InterpreterData(int lastICodeTop, int lastStringTableIndex,
InterpreterData(int lastICodeTop, int lastStringTableIndex,
Object securityDomain,
boolean useDynamicScope, boolean checkThis)
{
itsICodeTop = lastICodeTop == 0
itsICodeTop = lastICodeTop == 0
? INITIAL_MAX_ICODE_LENGTH
: lastICodeTop * 2;
itsICode = new byte[itsICodeTop];
@ -65,7 +65,7 @@ class InterpreterData implements Serializable {
Context.checkSecurityDomainRequired();
this.securityDomain = securityDomain;
}
public boolean placeBreakpoint(int line) { // XXX throw exn?
int offset = getOffset(line);
if (offset != -1 && (itsICode[offset] == (byte)TokenStream.LINE ||
@ -76,7 +76,7 @@ class InterpreterData implements Serializable {
}
return false;
}
public boolean removeBreakpoint(int line) {
int offset = getOffset(line);
if (offset != -1 && itsICode[offset] == (byte) TokenStream.BREAKPOINT)
@ -86,15 +86,15 @@ class InterpreterData implements Serializable {
}
return false;
}
private int getOffset(int line) {
int offset = itsLineNumberTable.getInt(line, -1);
if (0 <= offset && offset <= itsICode.length) {
return offset;
}
return -1;
}
}
String itsName;
String itsSource;
String itsSourceFile;
@ -109,19 +109,19 @@ class InterpreterData implements Serializable {
double[] itsDoubleTable;
int itsDoubleTableIndex;
InterpretedFunction[] itsNestedFunctions;
Object[] itsRegExpLiterals;
byte[] itsICode;
int itsICodeTop;
int itsMaxLocals;
int itsMaxArgs;
int itsMaxStack;
int itsMaxTryDepth;
UintMap itsLineNumberTable;
Object securityDomain;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -40,7 +40,7 @@ import java.util.Vector;
import org.mozilla.javascript.debug.*;
class InterpreterFrame implements DebugFrame {
InterpreterFrame(Scriptable scope, InterpreterData data, Scriptable obj) {
this.scope = scope;
this.data = data;
@ -51,25 +51,25 @@ class InterpreterFrame implements DebugFrame {
public Scriptable getVariableObject() {
return scope;
}
public String getSourceName() {
return data.itsSourceFile;
}
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
public int getLineNumber() {
return lineNumber;
}
public DebuggableScript getScript() {
if (obj instanceof DebuggableScript)
return (DebuggableScript) obj;
return null;
}
private Scriptable scope;
private InterpreterData data;
private Scriptable obj;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Patrick Beard
* Norris Boyd
* Mike McCabe
@ -50,17 +50,17 @@ public class JavaAdapter extends ScriptableObject {
public boolean equals(Object obj) {
return super.equals(obj);
}
public String getClassName() {
return "JavaAdapter";
}
public static Object convertResult(Object result, String classname)
throws ClassNotFoundException
throws ClassNotFoundException
{
Class c = ScriptRuntime.loadClassName(classname);
if (result == Undefined.instance &&
(c != ScriptRuntime.ObjectClass &&
if (result == Undefined.instance &&
(c != ScriptRuntime.ObjectClass &&
c != ScriptRuntime.StringClass))
{
// Avoid an error for an undefined value; return null instead.
@ -82,9 +82,9 @@ public class JavaAdapter extends ScriptableObject {
return self.get(adapter);
}
public static Object jsConstructor(Context cx, Object[] args,
public static Object jsConstructor(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr)
throws InstantiationException, NoSuchMethodException,
throws InstantiationException, NoSuchMethodException,
IllegalAccessException, InvocationTargetException,
ClassNotFoundException, NoSuchFieldException
{
@ -93,7 +93,7 @@ public class JavaAdapter extends ScriptableObject {
int interfaceCount = 0;
for (int i=0; i < args.length-1; i++) {
if (!(args[i] instanceof NativeJavaClass)) {
throw NativeGlobal.constructError(cx, "TypeError",
throw NativeGlobal.constructError(cx, "TypeError",
"expected java class object", ctorObj);
}
Class c = ((NativeJavaClass) args[i]).getClassObject();
@ -102,7 +102,7 @@ public class JavaAdapter extends ScriptableObject {
String msg = "Only one class may be extended by a " +
"JavaAdapter. Had " + superClass.getName() +
" and " + c.getName();
throw NativeGlobal.constructError(cx, "TypeError", msg,
throw NativeGlobal.constructError(cx, "TypeError", msg,
ctorObj);
}
superClass = c;
@ -110,14 +110,14 @@ public class JavaAdapter extends ScriptableObject {
intfs[interfaceCount++] = c;
}
}
if (superClass == null)
superClass = Object.class;
Class[] interfaces = new Class[interfaceCount];
System.arraycopy(intfs, 0, interfaces, 0, interfaceCount);
Scriptable obj = (Scriptable) args[args.length - 1];
ClassSignature sig = new ClassSignature(superClass, interfaces, obj);
Class adapterClass = (Class) generatedClasses.get(sig);
if (adapterClass == null) {
@ -125,12 +125,12 @@ public class JavaAdapter extends ScriptableObject {
synchronized (generatedClasses) {
adapterName = "adapter" + serial++;
}
adapterClass = createAdapterClass(cx, obj, adapterName,
superClass, interfaces,
adapterClass = createAdapterClass(cx, obj, adapterName,
superClass, interfaces,
null, null);
generatedClasses.put(sig, adapterClass);
}
Class[] ctorParms = { Scriptable.class };
Object[] ctorArgs = { obj };
Object adapter = adapterClass.getConstructor(ctorParms).newInstance(ctorArgs);
@ -138,9 +138,9 @@ public class JavaAdapter extends ScriptableObject {
}
// Needed by NativeJavaObject de-serializer
public static Object createAdapterClass(Class superClass,
Class[] interfaces,
public static Object createAdapterClass(Class superClass,
Class[] interfaces,
Scriptable obj, Scriptable self)
throws ClassNotFoundException
{
@ -152,8 +152,8 @@ public class JavaAdapter extends ScriptableObject {
adapterName = "adapter" + serial++;
}
try {
adapterClass = createAdapterClass(Context.enter(), obj,
adapterName, superClass,
adapterClass = createAdapterClass(Context.enter(), obj,
adapterName, superClass,
interfaces, null, null);
generatedClasses.put(sig, adapterClass);
} finally {
@ -161,7 +161,7 @@ public class JavaAdapter extends ScriptableObject {
}
}
try {
try {
Class[] ctorParms = { Scriptable.class, Scriptable.class };
Object[] ctorArgs = { obj, self };
@ -177,35 +177,35 @@ public class JavaAdapter extends ScriptableObject {
public static Class createAdapterClass(Context cx, Scriptable jsObj,
String adapterName, Class superClass,
Class[] interfaces,
Class[] interfaces,
String scriptClassName,
ClassNameHelper nameHelper)
throws ClassNotFoundException
{
ClassFileWriter cfw = new ClassFileWriter(adapterName,
superClass.getName(),
ClassFileWriter cfw = new ClassFileWriter(adapterName,
superClass.getName(),
"<adapter>");
cfw.addField("delegee", "Lorg/mozilla/javascript/Scriptable;",
(short) (ClassFileWriter.ACC_PUBLIC |
(short) (ClassFileWriter.ACC_PUBLIC |
ClassFileWriter.ACC_FINAL));
cfw.addField("self", "Lorg/mozilla/javascript/Scriptable;",
(short) (ClassFileWriter.ACC_PUBLIC |
(short) (ClassFileWriter.ACC_PUBLIC |
ClassFileWriter.ACC_FINAL));
int interfacesCount = interfaces == null ? 0 : interfaces.length;
for (int i=0; i < interfacesCount; i++) {
if (interfaces[i] != null)
cfw.addInterface(interfaces[i].getName());
}
String superName = superClass.getName().replace('.', '/');
generateCtor(cfw, adapterName, superName);
generateSerialCtor(cfw, adapterName, superName);
if (scriptClassName != null)
generateEmptyCtor(cfw, adapterName, superName, scriptClassName);
Hashtable generatedOverrides = new Hashtable();
Hashtable generatedMethods = new Hashtable();
// generate methods to satisfy all specified interfaces.
for (int i = 0; i < interfacesCount; i++) {
Method[] methods = interfaces[i].getMethods();
@ -219,7 +219,7 @@ public class JavaAdapter extends ScriptableObject {
}
if (!ScriptableObject.hasProperty(jsObj, method.getName())) {
try {
superClass.getMethod(method.getName(),
superClass.getMethod(method.getName(),
method.getParameterTypes());
// The class we're extending implements this method and
// the JavaScript object doesn't have an override. See
@ -229,7 +229,7 @@ public class JavaAdapter extends ScriptableObject {
// Not implemented by superclass; fall through
}
}
// make sure to generate only one instance of a particular
// make sure to generate only one instance of a particular
// method/signature.
String methodName = method.getName();
String methodKey = methodName + getMethodSignature(method);
@ -243,7 +243,7 @@ public class JavaAdapter extends ScriptableObject {
}
}
// Now, go through the superclasses methods, checking for abstract
// Now, go through the superclasses methods, checking for abstract
// methods or additional methods to override.
// generate any additional overrides that the object might contain.
@ -253,14 +253,14 @@ public class JavaAdapter extends ScriptableObject {
int mods = method.getModifiers();
if (Modifier.isStatic(mods) || Modifier.isFinal(mods))
continue;
// if a method is marked abstract, must implement it or the
// resulting class won't be instantiable. otherwise, if the object
// if a method is marked abstract, must implement it or the
// resulting class won't be instantiable. otherwise, if the object
// has a property of the same name, then an override is intended.
boolean isAbstractMethod = Modifier.isAbstract(mods);
if (isAbstractMethod ||
if (isAbstractMethod ||
(jsObj != null && ScriptableObject.hasProperty(jsObj,method.getName())))
{
// make sure to generate only one instance of a particular
// make sure to generate only one instance of a particular
// method/signature.
String methodName = method.getName();
String methodSignature = getMethodSignature(method);
@ -282,13 +282,13 @@ public class JavaAdapter extends ScriptableObject {
}
}
}
// Generate Java methods, fields for remaining properties that
// are not overrides.
for (Scriptable o=jsObj; o != null; o = (Scriptable)o.getPrototype()) {
Object[] ids = jsObj.getIds();
for (int j=0; j < ids.length; j++) {
if (!(ids[j] instanceof String))
if (!(ids[j] instanceof String))
continue;
String id = (String) ids[j];
if (generatedMethods.containsKey(id))
@ -308,10 +308,10 @@ public class JavaAdapter extends ScriptableObject {
continue;
}
Class[] parms = new Class[length];
for (int k=0; k < length; k++)
for (int k=0; k < length; k++)
parms[k] = Object.class;
generateMethod(cfw, adapterName, id, parms, Object.class);
}
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream(512);
try {
@ -321,10 +321,10 @@ public class JavaAdapter extends ScriptableObject {
throw new RuntimeException("unexpected IOException");
}
byte[] bytes = out.toByteArray();
if (nameHelper != null) {
try {
if (!nameHelper.getClassRepository().storeClass(adapterName,
if (!nameHelper.getClassRepository().storeClass(adapterName,
bytes, true))
{
return null;
@ -340,18 +340,18 @@ public class JavaAdapter extends ScriptableObject {
Class result = ss.defineClass(adapterName, bytes, securityDomain);
if (result != null)
return result;
}
}
DefiningClassLoader classLoader = new DefiningClassLoader();
classLoader.defineClass(adapterName, bytes);
return classLoader.loadClass(adapterName, true);
}
/**
* Utility method which dynamically binds a Context to the current thread,
* Utility method which dynamically binds a Context to the current thread,
* if none already exists.
*/
public static Object callMethod(Scriptable object, Object thisObj,
String methodId, Object[] args)
String methodId, Object[] args)
{
try {
Context cx = Context.enter();
@ -359,7 +359,7 @@ public class JavaAdapter extends ScriptableObject {
if (fun == Scriptable.NOT_FOUND) {
// This method used to swallow the exception from calling
// an undefined method. People have come to depend on this
// somewhat dubious behavior. It allows people to avoid
// somewhat dubious behavior. It allows people to avoid
// implementing listener methods that they don't care about,
// for instance.
return Undefined.instance;
@ -371,7 +371,7 @@ public class JavaAdapter extends ScriptableObject {
Context.exit();
}
}
public static Scriptable toObject(Object value, Scriptable scope,
Class staticType)
{
@ -382,22 +382,22 @@ public class JavaAdapter extends ScriptableObject {
Context.exit();
}
}
private static void generateCtor(ClassFileWriter cfw, String adapterName,
String superName)
private static void generateCtor(ClassFileWriter cfw, String adapterName,
String superName)
{
cfw.startMethod("<init>",
cfw.startMethod("<init>",
"(Lorg/mozilla/javascript/Scriptable;)V",
ClassFileWriter.ACC_PUBLIC);
// Invoke base class constructor
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.INVOKESPECIAL, superName, "<init>", "()", "V");
// Save parameter in instance variable "delegee"
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_1); // first arg
cfw.add(ByteCode.PUTFIELD, adapterName, "delegee",
cfw.add(ByteCode.PUTFIELD, adapterName, "delegee",
"Lorg/mozilla/javascript/Scriptable;");
// create a wrapper object to be used as "this" in method calls
@ -409,59 +409,59 @@ public class JavaAdapter extends ScriptableObject {
"(Lorg/mozilla/javascript/Scriptable;" +
"Ljava/lang/Object;)",
"Lorg/mozilla/javascript/Scriptable;");
// save the wrapper
cfw.add(ByteCode.ASTORE_1);
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_1); // first arg
cfw.add(ByteCode.PUTFIELD, adapterName, "self",
cfw.add(ByteCode.PUTFIELD, adapterName, "self",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.RETURN);
cfw.stopMethod((short)20, null); // TODO: magic number "20"
}
private static void generateSerialCtor(ClassFileWriter cfw, String adapterName,
String superName)
private static void generateSerialCtor(ClassFileWriter cfw, String adapterName,
String superName)
{
cfw.startMethod("<init>",
cfw.startMethod("<init>",
"(Lorg/mozilla/javascript/Scriptable;Lorg/mozilla/javascript/Scriptable;)V",
ClassFileWriter.ACC_PUBLIC);
// Invoke base class constructor
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.INVOKESPECIAL, superName, "<init>", "()", "V");
// Save parameter in instance variable "delegee"
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_1); // first arg
cfw.add(ByteCode.PUTFIELD, adapterName, "delegee",
cfw.add(ByteCode.PUTFIELD, adapterName, "delegee",
"Lorg/mozilla/javascript/Scriptable;");
// save self
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_2); // second arg
cfw.add(ByteCode.PUTFIELD, adapterName, "self",
cfw.add(ByteCode.PUTFIELD, adapterName, "self",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.RETURN);
cfw.stopMethod((short)20, null); // TODO: magic number "20"
}
private static void generateEmptyCtor(ClassFileWriter cfw, String adapterName,
String superName, String scriptClassName)
private static void generateEmptyCtor(ClassFileWriter cfw, String adapterName,
String superName, String scriptClassName)
{
cfw.startMethod("<init>", "()V", ClassFileWriter.ACC_PUBLIC);
// Invoke base class constructor
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.INVOKESPECIAL, superName, "<init>", "()", "V");
// Load script class
cfw.add(ByteCode.NEW, scriptClassName);
cfw.add(ByteCode.DUP);
cfw.add(ByteCode.INVOKESPECIAL, scriptClassName, "<init>", "()", "V");
// Run script and save resulting scope
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/ScriptRuntime",
@ -469,13 +469,13 @@ public class JavaAdapter extends ScriptableObject {
"(Lorg/mozilla/javascript/Script;)",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.ASTORE_1);
// Save the Scriptable in instance variable "delegee"
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_1); // the Scriptable
cfw.add(ByteCode.PUTFIELD, adapterName, "delegee",
cfw.add(ByteCode.PUTFIELD, adapterName, "delegee",
"Lorg/mozilla/javascript/Scriptable;");
// create a wrapper object to be used as "this" in method calls
cfw.add(ByteCode.ALOAD_1); // the Scriptable
cfw.add(ByteCode.ALOAD_0); // this
@ -489,7 +489,7 @@ public class JavaAdapter extends ScriptableObject {
cfw.add(ByteCode.ASTORE_1);
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_1); // first arg
cfw.add(ByteCode.PUTFIELD, adapterName, "self",
cfw.add(ByteCode.PUTFIELD, adapterName, "self",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.RETURN);
@ -497,32 +497,32 @@ public class JavaAdapter extends ScriptableObject {
}
/**
* Generates code to create a java.lang.Boolean, java.lang.Character or a
* java.lang.Double to wrap the specified primitive parameter. Leaves the
* Generates code to create a java.lang.Boolean, java.lang.Character or a
* java.lang.Double to wrap the specified primitive parameter. Leaves the
* wrapper object on the top of the stack.
*/
private static int generateWrapParam(ClassFileWriter cfw, int paramOffset,
Class paramType)
private static int generateWrapParam(ClassFileWriter cfw, int paramOffset,
Class paramType)
{
if (paramType.equals(Boolean.TYPE)) {
// wrap boolean values with java.lang.Boolean.
cfw.add(ByteCode.NEW, "java/lang/Boolean");
cfw.add(ByteCode.DUP);
cfw.add(ByteCode.ILOAD, paramOffset++);
cfw.add(ByteCode.INVOKESPECIAL, "java/lang/Boolean",
cfw.add(ByteCode.INVOKESPECIAL, "java/lang/Boolean",
"<init>", "(Z)", "V");
} else
if (paramType.equals(Character.TYPE)) {
// Create a string of length 1 using the character parameter.
cfw.add(ByteCode.NEW, "java/lang/String");
cfw.add(ByteCode.DUP);
cfw.add(ByteCode.ICONST_1);
cfw.add(ByteCode.ICONST_1);
cfw.add(ByteCode.NEWARRAY, ByteCode.T_CHAR);
cfw.add(ByteCode.DUP);
cfw.add(ByteCode.ICONST_0);
cfw.add(ByteCode.ILOAD, paramOffset++);
cfw.add(ByteCode.CASTORE);
cfw.add(ByteCode.INVOKESPECIAL, "java/lang/String",
cfw.add(ByteCode.CASTORE);
cfw.add(ByteCode.INVOKESPECIAL, "java/lang/String",
"<init>", "([C)", "V");
} else {
// convert all numeric values to java.lang.Double.
@ -553,7 +553,7 @@ public class JavaAdapter extends ScriptableObject {
paramOffset += 2;
break;
}
cfw.add(ByteCode.INVOKESPECIAL, "java/lang/Double",
cfw.add(ByteCode.INVOKESPECIAL, "java/lang/Double",
"<init>", "(D)", "V");
}
return paramOffset;
@ -565,33 +565,33 @@ public class JavaAdapter extends ScriptableObject {
* May need to map between char and java.lang.String as well.
* Generates the appropriate RETURN bytecode.
*/
private static void generateReturnResult(ClassFileWriter cfw,
Class retType)
private static void generateReturnResult(ClassFileWriter cfw,
Class retType)
{
// wrap boolean values with java.lang.Boolean, convert all other
// wrap boolean values with java.lang.Boolean, convert all other
// primitive values to java.lang.Double.
if (retType.equals(Boolean.TYPE)) {
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/Context",
"toBoolean", "(Ljava/lang/Object;)",
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/Context",
"toBoolean", "(Ljava/lang/Object;)",
"Z");
cfw.add(ByteCode.IRETURN);
} else if (retType.equals(Character.TYPE)) {
// characters are represented as strings in JavaScript.
// characters are represented as strings in JavaScript.
// return the first character.
// first convert the value to a string if possible.
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/Context",
"toString", "(Ljava/lang/Object;)",
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/Context",
"toString", "(Ljava/lang/Object;)",
"Ljava/lang/String;");
cfw.add(ByteCode.ICONST_0);
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/String", "charAt",
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/String", "charAt",
"(I)", "C");
cfw.add(ByteCode.IRETURN);
} else if (retType.isPrimitive()) {
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/Context",
"toNumber", "(Ljava/lang/Object;)",
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/Context",
"toNumber", "(Ljava/lang/Object;)",
"D");
String typeName = retType.getName();
switch (typeName.charAt(0)) {
@ -613,17 +613,17 @@ public class JavaAdapter extends ScriptableObject {
cfw.add(ByteCode.DRETURN);
break;
default:
throw new RuntimeException("Unexpected return type " +
throw new RuntimeException("Unexpected return type " +
retType.toString());
}
} else {
String retTypeStr = retType.getName();
cfw.addLoadConstant(retTypeStr);
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/JavaAdapter",
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/JavaAdapter",
"convertResult",
"(Ljava/lang/Object;" +
"Ljava/lang/String;)",
"Ljava/lang/String;)",
"Ljava/lang/Object;");
// Now cast to return type
cfw.add(ByteCode.CHECKCAST, retTypeStr.replace('.', '/'));
@ -631,9 +631,9 @@ public class JavaAdapter extends ScriptableObject {
}
}
private static void generateMethod(ClassFileWriter cfw, String genName,
private static void generateMethod(ClassFileWriter cfw, String genName,
String methodName, Class[] parms,
Class returnType)
Class returnType)
{
StringBuffer sb = new StringBuffer();
sb.append('(');
@ -651,12 +651,12 @@ public class JavaAdapter extends ScriptableObject {
String methodSignature = sb.toString();
// System.out.println("generating " + m.getName() + methodSignature);
// System.out.flush();
cfw.startMethod(methodName, methodSignature,
cfw.startMethod(methodName, methodSignature,
ClassFileWriter.ACC_PUBLIC);
cfw.add(ByteCode.BIPUSH, (byte) parms.length); // > 255 parms?
cfw.add(ByteCode.ANEWARRAY, "java/lang/Object");
cfw.add(ByteCode.ASTORE, arrayLocal);
// allocate a local variable to store the scope used to wrap native objects.
short scopeLocal = (short) (arrayLocal + 1);
boolean loadedScope = false;
@ -668,49 +668,49 @@ public class JavaAdapter extends ScriptableObject {
if (parms[i].isPrimitive()) {
paramOffset = generateWrapParam(cfw, paramOffset, parms[i]);
} else {
// An arbitary Java object; call Context.toObject to wrap in
// An arbitary Java object; call Context.toObject to wrap in
// a Scriptable object
cfw.add(ByteCode.ALOAD, paramOffset++);
if (! loadedScope) {
// load this.self into a local the first time it's needed.
// it will provide the scope needed by Context.toObject().
cfw.add(ByteCode.ALOAD_0);
cfw.add(ByteCode.GETFIELD, genName, "delegee",
cfw.add(ByteCode.GETFIELD, genName, "delegee",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.ASTORE, scopeLocal);
loadedScope = true;
}
cfw.add(ByteCode.ALOAD, scopeLocal);
// Get argument Class
// Get argument Class
cfw.addLoadConstant(parms[i].getName());
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/ScriptRuntime",
"loadClassName",
"(Ljava/lang/String;)",
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/ScriptRuntime",
"loadClassName",
"(Ljava/lang/String;)",
"Ljava/lang/Class;");
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/JavaAdapter",
"toObject",
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/JavaAdapter",
"toObject",
"(Ljava/lang/Object;" +
"Lorg/mozilla/javascript/Scriptable;" +
"Ljava/lang/Class;)",
"Ljava/lang/Class;)",
"Lorg/mozilla/javascript/Scriptable;");
}
cfw.add(ByteCode.AASTORE);
}
cfw.add(ByteCode.ALOAD_0);
cfw.add(ByteCode.GETFIELD, genName, "delegee",
cfw.add(ByteCode.GETFIELD, genName, "delegee",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.ALOAD_0);
cfw.add(ByteCode.GETFIELD, genName, "self",
cfw.add(ByteCode.GETFIELD, genName, "self",
"Lorg/mozilla/javascript/Scriptable;");
cfw.addLoadConstant(methodName);
cfw.add(ByteCode.ALOAD, arrayLocal);
// go through utility method, which creates a Context to run the
// go through utility method, which creates a Context to run the
// method in.
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/JavaAdapter",
@ -732,8 +732,8 @@ public class JavaAdapter extends ScriptableObject {
* Generates code to push typed parameters onto the operand stack
* prior to a direct Java method call.
*/
private static int generatePushParam(ClassFileWriter cfw, int paramOffset,
Class paramType)
private static int generatePushParam(ClassFileWriter cfw, int paramOffset,
Class paramType)
{
String typeName = paramType.getName();
switch (typeName.charAt(0)) {
@ -767,8 +767,8 @@ public class JavaAdapter extends ScriptableObject {
* that returns the same type.
* Generates the appropriate RETURN bytecode.
*/
private static void generatePopResult(ClassFileWriter cfw,
Class retType)
private static void generatePopResult(ClassFileWriter cfw,
Class retType)
{
if (retType.isPrimitive()) {
String typeName = retType.getName();
@ -805,9 +805,9 @@ public class JavaAdapter extends ScriptableObject {
String methodName, String methodSignature,
Class[] parms, Class returnType)
{
cfw.startMethod("super$" + methodName, methodSignature,
cfw.startMethod("super$" + methodName, methodSignature,
ClassFileWriter.ACC_PUBLIC);
// push "this"
cfw.add(ByteCode.ALOAD, 0);
@ -820,10 +820,10 @@ public class JavaAdapter extends ScriptableObject {
cfw.add(ByteCode.ALOAD, paramOffset++);
}
}
// split the method signature at the right parentheses.
int rightParen = methodSignature.indexOf(')');
// call the superclass implementation of the method.
cfw.add(ByteCode.INVOKESPECIAL,
superName,
@ -831,7 +831,7 @@ public class JavaAdapter extends ScriptableObject {
methodSignature.substring(0, rightParen + 1),
methodSignature.substring(rightParen + 1));
// now, handle the return type appropriately.
// now, handle the return type appropriately.
Class retType = returnType;
if (!retType.equals(Void.TYPE)) {
generatePopResult(cfw, retType);
@ -840,7 +840,7 @@ public class JavaAdapter extends ScriptableObject {
}
cfw.stopMethod((short)(paramOffset + 1), null);
}
/**
* Returns a fully qualified method name concatenated with its signature.
*/
@ -856,8 +856,8 @@ public class JavaAdapter extends ScriptableObject {
appendTypeString(sb, method.getReturnType());
return sb.toString();
}
private static StringBuffer appendTypeString(StringBuffer sb, Class type)
private static StringBuffer appendTypeString(StringBuffer sb, Class type)
{
while (type.isArray()) {
sb.append('[');
@ -880,7 +880,7 @@ public class JavaAdapter extends ScriptableObject {
}
return sb;
}
/**
* Provides a key with which to distinguish previously generated
* adapter classes stored in a hash table.
@ -889,13 +889,13 @@ public class JavaAdapter extends ScriptableObject {
Class mSuperClass;
Class[] mInterfaces;
Object[] mProperties; // JDK1.2: Use HashSet
ClassSignature(Class superClass, Class[] interfaces, Scriptable jsObj) {
mSuperClass = superClass;
mInterfaces = interfaces;
mProperties = ScriptableObject.getPropertyIds(jsObj);
}
public boolean equals(Object obj) {
if (obj instanceof ClassSignature) {
ClassSignature sig = (ClassSignature) obj;
@ -921,12 +921,12 @@ public class JavaAdapter extends ScriptableObject {
}
return false;
}
public int hashCode() {
return mSuperClass.hashCode();
}
}
private static int serial;
private static Hashtable generatedClasses = new Hashtable(7);
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
@ -79,7 +79,7 @@ class JavaMembers {
member = staticMembers.get(name);
}
if (member == null) {
member = this.getExplicitFunction(scope, name,
member = this.getExplicitFunction(scope, name,
javaObject, isStatic);
if (member == null)
return Scriptable.NOT_FOUND;
@ -145,7 +145,7 @@ class JavaMembers {
if (methodsOrCtors != null) {
for (int i = 0; i < methodsOrCtors.length; i++) {
String nameWithSig =
String nameWithSig =
NativeJavaMethod.signature(methodsOrCtors[i]);
if (name.equals(nameWithSig)) {
return methodsOrCtors[i];
@ -156,19 +156,19 @@ class JavaMembers {
return null;
}
Object getExplicitFunction(Scriptable scope, String name,
Object javaObject, boolean isStatic)
Object getExplicitFunction(Scriptable scope, String name,
Object javaObject, boolean isStatic)
{
Hashtable ht = isStatic ? staticMembers : members;
Object member = null;
Member methodOrCtor = this.findExplicitFunction(name, isStatic);
if (methodOrCtor != null) {
Scriptable prototype =
Scriptable prototype =
ScriptableObject.getFunctionPrototype(scope);
if (methodOrCtor instanceof Constructor) {
NativeJavaConstructor fun =
NativeJavaConstructor fun =
new NativeJavaConstructor((Constructor)methodOrCtor);
fun.setPrototype(prototype);
member = fun;
@ -179,7 +179,7 @@ class JavaMembers {
if (member instanceof NativeJavaMethod &&
((NativeJavaMethod)member).getMethods().length > 1 ) {
NativeJavaMethod fun =
NativeJavaMethod fun =
new NativeJavaMethod((Method)methodOrCtor, name);
fun.setPrototype(prototype);
ht.put(name, fun);
@ -192,7 +192,7 @@ class JavaMembers {
}
public void put(Scriptable scope, String name, Object javaObject,
public void put(Scriptable scope, String name, Object javaObject,
Object value, boolean isStatic)
{
Hashtable ht = isStatic ? staticMembers : members;
@ -207,9 +207,9 @@ class JavaMembers {
FieldAndMethods fam = (FieldAndMethods) ht.get(name);
member = fam.getField();
}
// Is this a bean property "set"?
if (member instanceof BeanProperty) {
if (member instanceof BeanProperty) {
try {
Method method = ((BeanProperty) member).setter;
if (method == null)
@ -243,7 +243,7 @@ class JavaMembers {
"accessing Java field");
} catch (IllegalArgumentException argEx) {
throw Context.reportRuntimeError3(
"msg.java.internal.field.type",
"msg.java.internal.field.type",
value.getClass().getName(), field,
javaObject.getClass().getName());
}
@ -259,11 +259,11 @@ class JavaMembers {
result[i] = keys.nextElement();
return result;
}
Class getReflectedClass() {
return cl;
}
void reflectField(Scriptable scope, Field field) {
int mods = field.getModifiers();
if (!Modifier.isPublic(mods))
@ -285,10 +285,10 @@ class JavaMembers {
}
if (member instanceof Field) {
Field oldField = (Field) member;
// If this newly reflected field shadows an inherited field,
// then replace it. Otherwise, since access to the field
// If this newly reflected field shadows an inherited field,
// then replace it. Otherwise, since access to the field
// would be ambiguous from Java, no field should be reflected.
// For now, the first field found wins, unless another field
// For now, the first field found wins, unless another field
// explicitly shadows it.
if (oldField.getDeclaringClass().isAssignableFrom(field.getDeclaringClass()))
ht.put(name, field);
@ -325,17 +325,17 @@ class JavaMembers {
Method[] methods = cl.getMethods();
for (int i = 0; i < methods.length; i++)
reflectMethod(scope, methods[i]);
Field[] fields = cl.getFields();
for (int i = 0; i < fields.length; i++)
reflectField(scope, fields[i]);
makeBeanProperties(scope, false);
makeBeanProperties(scope, true);
ctors = cl.getConstructors();
}
Hashtable getFieldAndMethodsTable(boolean isStatic) {
Hashtable fmht = isStatic ? staticFieldAndMethods
: fieldAndMethods;
@ -346,17 +346,17 @@ class JavaMembers {
else
fieldAndMethods = fmht;
}
return fmht;
}
void makeBeanProperties(Scriptable scope, boolean isStatic) {
Hashtable ht = isStatic ? staticMembers : members;
Hashtable toAdd = new Hashtable();
// Now, For each member, make "bean" properties.
for (Enumeration e = ht.keys(); e.hasMoreElements(); ) {
// Is this a getter?
String name = (String) e.nextElement();
boolean memberIsGetMethod = name.startsWith("get");
@ -364,63 +364,63 @@ class JavaMembers {
if (memberIsGetMethod || memberIsIsMethod) {
// Double check name component.
String nameComponent = name.substring(memberIsGetMethod ? 3 : 2);
if (nameComponent.length() == 0)
if (nameComponent.length() == 0)
continue;
// Make the bean property name.
String beanPropertyName = nameComponent;
if (Character.isUpperCase(nameComponent.charAt(0))) {
if (nameComponent.length() == 1) {
beanPropertyName = nameComponent.substring(0, 1).toLowerCase();
} else if (!Character.isUpperCase(nameComponent.charAt(1))) {
beanPropertyName = Character.toLowerCase(nameComponent.charAt(0)) +
beanPropertyName = Character.toLowerCase(nameComponent.charAt(0)) +
nameComponent.substring(1);
}
}
// If we already have a member by this name, don't do this
// property.
if (ht.containsKey(beanPropertyName))
continue;
// Get the method by this name.
Object method = ht.get(name);
if (!(method instanceof NativeJavaMethod))
continue;
NativeJavaMethod getJavaMethod = (NativeJavaMethod) method;
// Grab and inspect the getter method; does it have an empty parameter list,
// with a return value (eg. a getSomething() or isSomething())?
Class[] params;
Method[] getMethods = getJavaMethod.getMethods();
Class type;
if (getMethods != null &&
getMethods.length == 1 &&
if (getMethods != null &&
getMethods.length == 1 &&
(type = getMethods[0].getReturnType()) != null &&
(params = getMethods[0].getParameterTypes()) != null &&
params.length == 0)
{
(params = getMethods[0].getParameterTypes()) != null &&
params.length == 0)
{
// Make sure the method static-ness is preserved for this property.
if (isStatic && !Modifier.isStatic(getMethods[0].getModifiers()))
continue;
// We have a getter. Now, do we have a setter?
Method setMethod = null;
String setter = "set" + nameComponent;
if (ht.containsKey(setter)) {
if (ht.containsKey(setter)) {
// Is this value a method?
method = ht.get(setter);
if (method instanceof NativeJavaMethod) {
//
// Note: it may be preferable to allow NativeJavaMethod.findFunction()
// to find the appropriate setter; unfortunately, it requires an
// instance of the target arg to determine that.
//
// Make two passes: one to find a method with direct type assignment,
// Make two passes: one to find a method with direct type assignment,
// and one to find a widening conversion.
NativeJavaMethod setJavaMethod = (NativeJavaMethod) method;
Method[] setMethods = setJavaMethod.getMethods();
@ -428,11 +428,11 @@ class JavaMembers {
for (int i = 0; i < setMethods.length; ++i) {
if (setMethods[i].getReturnType() == void.class &&
(!isStatic || Modifier.isStatic(setMethods[i].getModifiers())) &&
(params = setMethods[i].getParameterTypes()) != null &&
params.length == 1 ) {
(params = setMethods[i].getParameterTypes()) != null &&
params.length == 1 ) {
if ((pass == 1 && params[0] == type) ||
(pass == 2 && params[0].isAssignableFrom(type))) {
(pass == 2 && params[0].isAssignableFrom(type))) {
setMethod = setMethods[i];
break;
}
@ -441,14 +441,14 @@ class JavaMembers {
}
}
}
// Make the property.
BeanProperty bp = new BeanProperty(getMethods[0], setMethod);
toAdd.put(beanPropertyName, bp);
}
}
}
}
// Add the new bean properties.
for (Enumeration e = toAdd.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
@ -458,7 +458,7 @@ class JavaMembers {
}
Hashtable getFieldAndMethodsObjects(Scriptable scope, Object javaObject,
boolean isStatic)
boolean isStatic)
{
Hashtable ht = isStatic ? staticFieldAndMethods : fieldAndMethods;
if (ht == null)
@ -498,7 +498,7 @@ class JavaMembers {
{
// We can use the static type, and that is OK, but we'll trace
// back the java class chain here to look for something more suitable.
for (Class parentType = dynamicType;
for (Class parentType = dynamicType;
parentType != null && parentType != ScriptRuntime.ObjectClass;
parentType = parentType.getSuperclass())
{
@ -512,16 +512,16 @@ class JavaMembers {
try {
members = new JavaMembers(scope, cl);
} catch (SecurityException e) {
// Reflection may fail for objects that are in a restricted
// Reflection may fail for objects that are in a restricted
// access package (e.g. sun.*). If we get a security
// exception, try again with the static type. Otherwise,
// exception, try again with the static type. Otherwise,
// rethrow the exception.
if (cl != staticType)
members = new JavaMembers(scope, staticType);
else
throw e;
}
if (Context.isCachingEnabled)
if (Context.isCachingEnabled)
ct.put(cl, members);
return members;
}
@ -571,7 +571,7 @@ class FieldAndMethods extends NativeJavaMethod {
Field getField() {
return field;
}
public Object getDefaultValue(Class hint) {
if (hint == ScriptRuntime.FunctionClass)
return this;
@ -596,7 +596,7 @@ class FieldAndMethods extends NativeJavaMethod {
result.javaObject = javaObject;
return result;
}
private Field field;
private Object javaObject;
private String name;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -92,9 +92,9 @@ public class JavaScriptException extends Exception {
* wrapping the original Java exception object.
*
* We would prefer to go through a getter to encapsulate the value,
* however that causes the bizarre error "nanosecond timeout value
* out of range" on the MS JVM.
* @serial
* however that causes the bizarre error "nanosecond timeout value
* out of range" on the MS JVM.
* @serial
*/
Object value;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
@ -36,7 +36,7 @@
package org.mozilla.javascript;
public class Label {
private static final int FIXUPTABLE_SIZE = 8;
private static final boolean DEBUG = true;
@ -50,7 +50,7 @@ public class Label {
{
return itsPC;
}
public void fixGotos(byte theCodeBuffer[])
{
if (DEBUG) {
@ -83,7 +83,7 @@ public class Label {
if (itsFixupTable == null) {
itsFixupTableTop = 1;
itsFixupTable = new int[FIXUPTABLE_SIZE];
itsFixupTable[0] = fixupSite;
itsFixupTable[0] = fixupSite;
}
else {
if (itsFixupTableTop == itsFixupTable.length) {
@ -92,7 +92,7 @@ public class Label {
System.arraycopy(itsFixupTable, 0, newTable, 0, oldLength);
itsFixupTable = newTable;
}
itsFixupTable[itsFixupTableTop++] = fixupSite;
itsFixupTable[itsFixupTableTop++] = fixupSite;
}
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
@ -38,7 +38,7 @@ package org.mozilla.javascript;
public class LabelTable {
private static final boolean DEBUGLABELS = false;
private static final int LabelTableSize = 32;
protected Label itsLabelTable[];
protected int itsLabelTableTop;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
@ -67,12 +67,12 @@ final class LineBuffer {
this.in = in;
this.lineno = lineno;
}
int read() throws IOException {
for(;;) {
if (end == offset && !fill())
return -1;
int c = buffer[offset];
++offset;
@ -113,9 +113,9 @@ final class LineBuffer {
// in the process of a fill(), and leave it there. But
// the scanner never calls peek() or a failed match()
// followed by unread()... this would violate 1-character
// lookahead.
// lookahead.
if (Context.check && offset == 0 && !hitEOF) Context.codeBug();
if (offset == 0) // Same as if (hitEOF)
return;
offset--;
@ -134,9 +134,9 @@ final class LineBuffer {
}
else {
// swap prev character with format one so possible call to
// startString can assume that previous non-format char is at
// startString can assume that previous non-format char is at
// offset - 1. Note it causes getLine to return not exactly the
// source LineBuffer read, but it is used only in error reporting
// source LineBuffer read, but it is used only in error reporting
// and should not be a problem.
if (offset != 0) {
char tmp = buffer[offset];
@ -152,7 +152,7 @@ final class LineBuffer {
++offset;
}
int peek() throws IOException {
for (;;) {
if (end == offset && !fill()) {
@ -166,7 +166,7 @@ final class LineBuffer {
if (c < 128 || !formatChar(c)) {
return c;
}
skipFormatChar();
}
}
@ -269,7 +269,7 @@ final class LineBuffer {
// (which we want to include) is at the end of the last one, so
// we just go to StringBuffer mode.
stringSoFar = new StringBuffer();
stringStart = -1; // Set sentinel value.
c = otherBuffer[otherEnd - 1];
stringSoFar.append(c);
@ -304,17 +304,17 @@ final class LineBuffer {
if (stringStart >= 0) {
// String mark is valid, and in this buffer.
result = new String(buffer, stringStart,
result = new String(buffer, stringStart,
offset - stringStart - loseCR);
} else {
// Exclude cr as well as nl of newline. If offset is 0, then
// hopefully fill() did the right thing.
result = (stringSoFar.append(buffer, 0, offset - loseCR)).toString();
}
stringStart = -1;
stringSoFar = null;
if (hadCFSinceStringStart) {
char c[] = result.toCharArray();
StringBuffer x = null;
@ -328,11 +328,11 @@ final class LineBuffer {
else
if (x != null) x.append(c[i]);
}
if (x != null) result = x.toString();
if (x != null) result = x.toString();
}
return result;
}
}
private boolean fill() throws IOException {
// fill should be caled only for emty buffer
@ -380,7 +380,7 @@ final class LineBuffer {
// set lineStart to a sentinel value, unless this is the first
// time around.
prevStart = lineStart = (otherBuffer == null) ? 0 : buffer.length + 1;
offset = 0;
end = in.read(buffer, 0, buffer.length);
if (end < 0) {
@ -417,7 +417,7 @@ final class LineBuffer {
int getLineno() { return lineno; }
boolean eof() { return hitEOF; }
private static boolean formatChar(int c) {
return Character.getType((char)c) == Character.FORMAT;
}
@ -443,7 +443,7 @@ final class LineBuffer {
private int lineStart = 0;
private int otherStart = 0;
private int prevStart = 0;
private boolean lastWasCR = false;
private boolean hitEOF = false;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
@ -36,20 +36,20 @@
package org.mozilla.javascript;
public class LocalVariable {
public LocalVariable(String name, boolean isParameter) {
itsName = name;
itsIsParameter = isParameter;
itsIsParameter = isParameter;
}
public void setIndex(int index){ itsIndex = index; }
public int getIndex() { return itsIndex; }
public void setIsParameter() { itsIsParameter = true; }
public boolean isParameter() { return itsIsParameter; }
public String getName() { return itsName; }
/**
* Return the starting PC where this variable is live, or -1
* if it is not a Java register.
@ -74,6 +74,6 @@ public class LocalVariable {
private String itsName;
private int itsIndex = -1;
private boolean itsIsParameter;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Mike McCabe
* Igor Bukanov
@ -110,14 +110,14 @@ public class NativeArray extends IdScriptable {
}
return super.getIdValue(id);
}
protected void setIdValue(int id, Object value) {
if (id == Id_length) {
jsSet_length(value); return;
}
super.setIdValue(id, value);
}
public int methodArity(int methodId) {
if (prototypeFlag) {
switch (methodId) {
@ -200,15 +200,15 @@ public class NativeArray extends IdScriptable {
return dense[index] != NOT_FOUND;
return super.has(index, start);
}
// if id is an array index (ECMA 15.4.0), return the number,
// if id is an array index (ECMA 15.4.0), return the number,
// otherwise return -1L
private static long toArrayIndex(String id) {
double d = ScriptRuntime.toNumber(id);
if (d == d) {
long index = ScriptRuntime.toUint32(d);
if (index == d && index != 4294967295L) {
// Assume that ScriptRuntime.toString(index) is the same
// Assume that ScriptRuntime.toString(index) is the same
// as java.lang.Long.toString(index) for long
if (Long.toString(index).equals(id)) {
return index;
@ -265,7 +265,7 @@ public class NativeArray extends IdScriptable {
if (N == 0) { return superIds; }
int shift = superIds.length;
Object[] ids = new Object[shift + N];
// Make a copy of dense to be immune to removing
// Make a copy of dense to be immune to removing
// of array elems from other thread when calculating presentCount
System.arraycopy(dense, 0, ids, shift, N);
int presentCount = 0;
@ -285,7 +285,7 @@ public class NativeArray extends IdScriptable {
System.arraycopy(superIds, 0, ids, 0, shift);
return ids;
}
public Object getDefaultValue(Class hint) {
if (hint == ScriptRuntime.NumberClass) {
Context cx = Context.getContext();
@ -298,7 +298,7 @@ public class NativeArray extends IdScriptable {
/**
* See ECMA 15.4.1,2
*/
private static Object jsConstructor(Context cx, Scriptable scope,
private static Object jsConstructor(Context cx, Scriptable scope,
Object[] args, IdFunction ctorObj,
boolean inNewExpr)
throws JavaScriptException
@ -351,7 +351,7 @@ public class NativeArray extends IdScriptable {
// assume that the representation is sparse
Object[] e = getIds(); // will only find in object itself
for (int i=0; i < e.length; i++) {
Object id = e[i];
Object id = e[i];
if (id instanceof String) {
// > MAXINT will appear as string
String strId = (String)id;
@ -438,19 +438,19 @@ public class NativeArray extends IdScriptable {
Object[] args)
throws JavaScriptException
{
return toStringHelper(cx, thisObj,
return toStringHelper(cx, thisObj,
cx.getLanguageVersion() == cx.VERSION_1_2,
false);
}
private static String jsFunction_toLocaleString(Context cx,
private static String jsFunction_toLocaleString(Context cx,
Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
return toStringHelper(cx, thisObj, false, true);
}
private static String toStringHelper(Context cx, Scriptable thisObj,
boolean toSource, boolean toLocale)
throws JavaScriptException
@ -507,14 +507,14 @@ public class NativeArray extends IdScriptable {
try {
// stop recursion.
cx.iterating.put(thisObj, Boolean.TRUE);
if (toLocale && elem != Undefined.instance &&
elem != null)
if (toLocale && elem != Undefined.instance &&
elem != null)
{
Scriptable obj = ScriptRuntime.
toObject(cx, thisObj, elem);
Object tls = ScriptRuntime.
getProp(obj, "toLocaleString", thisObj);
elem = ScriptRuntime.call(cx, tls, elem,
elem = ScriptRuntime.call(cx, tls, elem,
ScriptRuntime.emptyArgs);
}
result.append(ScriptRuntime.toString(elem));
@ -539,7 +539,7 @@ public class NativeArray extends IdScriptable {
* See ECMA 15.4.4.3
*/
private static String jsFunction_join(Context cx, Scriptable thisObj,
Object[] args)
Object[] args)
{
StringBuffer result = new StringBuffer();
String separator;
@ -566,9 +566,9 @@ public class NativeArray extends IdScriptable {
/**
* See ECMA 15.4.4.4
*/
private static Scriptable jsFunction_reverse(Context cx,
Scriptable thisObj,
Object[] args)
private static Scriptable jsFunction_reverse(Context cx,
Scriptable thisObj,
Object[] args)
{
long len = (long)getLengthProperty(thisObj);
@ -587,7 +587,7 @@ public class NativeArray extends IdScriptable {
* See ECMA 15.4.4.5
*/
private static Scriptable jsFunction_sort(Context cx, Scriptable scope,
Scriptable thisObj,
Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
@ -597,7 +597,7 @@ public class NativeArray extends IdScriptable {
Object compare;
Object[] cmpBuf;
if (args.length > 0 && Undefined.instance != args[0]) {
// sort with given compare function
compare = args[0];
@ -634,7 +634,7 @@ public class NativeArray extends IdScriptable {
// Return true only if x > y
private static boolean isBigger(Context cx, Scriptable scope,
Object x, Object y,
Object cmp, Object[] cmpBuf)
Object cmp, Object[] cmpBuf)
throws JavaScriptException
{
if (check) {
@ -653,7 +653,7 @@ public class NativeArray extends IdScriptable {
} else if (undef == x) {
return true; // y != undef here, so x > y
}
if (cmp == null) {
// if no cmp function supplied, sort lexicographically
String a = ScriptRuntime.toString(x);
@ -677,8 +677,8 @@ public class NativeArray extends IdScriptable {
return d > 0;
}
}
/** Heapsort implementation.
/** Heapsort implementation.
* See "Introduction to Algorithms" by Cormen, Leiserson, Rivest for details.
* Adjusted for zero based indexes.
*/
@ -688,14 +688,14 @@ public class NativeArray extends IdScriptable {
throws JavaScriptException
{
if (check && length <= 1) Context.codeBug();
// Build heap
for (int i = length / 2; i != 0;) {
--i;
Object pivot = array[i];
heapify(cx, scope, pivot, array, i, length, cmp, cmpBuf);
}
// Sort heap
for (int i = length; i != 1;) {
--i;
@ -704,7 +704,7 @@ public class NativeArray extends IdScriptable {
heapify(cx, scope, pivot, array, 0, i, cmp, cmpBuf);
}
}
/** pivot and child heaps of i should be made into heap starting at i,
* original array[i] is never used to have less array access during sorting.
*/
@ -721,7 +721,7 @@ public class NativeArray extends IdScriptable {
Object childVal = array[child];
if (child + 1 < end) {
Object nextVal = array[child + 1];
if (isBigger(cx, scope, nextVal, childVal, cmp, cmpBuf)) {
if (isBigger(cx, scope, nextVal, childVal, cmp, cmpBuf)) {
++child; childVal = nextVal;
}
}
@ -733,7 +733,7 @@ public class NativeArray extends IdScriptable {
}
array[i] = pivot;
}
/** Version of heapsort that call getElem/setElem on target to query/assign
* array elements instead of Java array access
*/
@ -743,14 +743,14 @@ public class NativeArray extends IdScriptable {
throws JavaScriptException
{
if (check && length <= 1) Context.codeBug();
// Build heap
for (long i = length / 2; i != 0;) {
--i;
Object pivot = getElem(target, i);
heapify_extended(cx, scope, pivot, target, i, length, cmp, cmpBuf);
}
// Sort heap
for (long i = length; i != 1;) {
--i;
@ -759,7 +759,7 @@ public class NativeArray extends IdScriptable {
heapify_extended(cx, scope, pivot, target, 0, i, cmp, cmpBuf);
}
}
private static void heapify_extended(Context cx, Scriptable scope,
Object pivot, Scriptable target,
long i, long end,
@ -774,7 +774,7 @@ public class NativeArray extends IdScriptable {
Object childVal = getElem(target, child);
if (child + 1 < end) {
Object nextVal = getElem(target, child + 1);
if (isBigger(cx, scope, nextVal, childVal, cmp, cmpBuf)) {
if (isBigger(cx, scope, nextVal, childVal, cmp, cmpBuf)) {
++child; childVal = nextVal;
}
}
@ -786,7 +786,7 @@ public class NativeArray extends IdScriptable {
}
setElem(target, i, pivot);
}
/**
* Non-ECMA methods.
*/
@ -1005,7 +1005,7 @@ public class NativeArray extends IdScriptable {
/*
* Python-esque sequence operations.
*/
private static Scriptable jsFunction_concat(Context cx, Scriptable scope,
private static Scriptable jsFunction_concat(Context cx, Scriptable scope,
Scriptable thisObj,
Object[] args)
{
@ -1132,8 +1132,8 @@ public class NativeArray extends IdScriptable {
protected int mapNameToId(String s) {
if (s.equals("length")) { return Id_length; }
else if (prototypeFlag) {
return toPrototypeId(s);
else if (prototypeFlag) {
return toPrototypeId(s);
}
return 0;
}
@ -1196,8 +1196,8 @@ public class NativeArray extends IdScriptable {
private long length;
private Object[] dense;
private static final int maximumDenseLength = 10000;
private boolean prototypeFlag;
private static final boolean check = true && Context.check;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Igor Bukanov
* Mike McCabe
@ -128,7 +128,7 @@ final class NativeBoolean extends IdScriptable {
if (id == Id_toString) return "toString";
if (id == Id_valueOf) return "valueOf";
}
return null;
return null;
}
// #string_id_map#

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -51,43 +51,43 @@ public final class NativeCall extends IdScriptable {
obj.addAsPrototype(MAX_PROTOTYPE_ID, cx, scope, sealed);
}
NativeCall(Context cx, Scriptable scope, NativeFunction funObj,
NativeCall(Context cx, Scriptable scope, NativeFunction funObj,
Scriptable thisObj, Object[] args)
{
this.funObj = funObj;
this.thisObj = thisObj;
setParentScope(scope);
// leave prototype null
// save current activation
this.caller = cx.currentActivation;
cx.currentActivation = this;
this.originalArgs = (args == null) ? ScriptRuntime.emptyArgs : args;
// initialize values of arguments
String[] argNames = funObj.argNames;
if (argNames != null) {
for (int i=0; i < funObj.argCount; i++) {
Object val = i < args.length ? args[i]
Object val = i < args.length ? args[i]
: Undefined.instance;
super.put(argNames[i], this, val);
}
}
// initialize "arguments" property
super.put("arguments", this, new Arguments(this));
}
private NativeCall() {
}
public String getClassName() {
return "Call";
}
private static Object jsConstructor(Context cx, Object[] args,
private static Object jsConstructor(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr)
{
if (!inNewExpr) {
@ -98,7 +98,7 @@ public final class NativeCall extends IdScriptable {
result.setPrototype(getObjectPrototype(ctorObj));
return result;
}
NativeCall getActivation(Function f) {
NativeCall x = this;
do {
@ -108,7 +108,7 @@ public final class NativeCall extends IdScriptable {
} while (x != null);
return null;
}
public Function getFunctionObject() {
return funObj;
}
@ -116,15 +116,15 @@ public final class NativeCall extends IdScriptable {
public Object[] getOriginalArguments() {
return originalArgs;
}
public NativeCall getCaller() {
return caller;
}
public Scriptable getThisObj() {
return thisObj;
}
public int methodArity(int methodId) {
if (prototypeFlag) {
if (methodId == Id_constructor) return 1;
@ -149,9 +149,9 @@ public final class NativeCall extends IdScriptable {
if (prototypeFlag) {
if (id == Id_constructor) return "constructor";
}
return null;
return null;
}
protected int mapNameToId(String s) {
if (!prototypeFlag) { return 0; }
return s.equals("constructor") ? Id_constructor : 0;

Просмотреть файл

@ -53,13 +53,13 @@ final class NativeDate extends IdScriptable {
static void init(Context cx, Scriptable scope, boolean sealed) {
NativeDate obj = new NativeDate();
obj.prototypeFlag = true;
// Set the value of the prototype Date to NaN ('invalid date');
obj.date = ScriptRuntime.NaN;
obj.addAsPrototype(MAX_PROTOTYPE_ID, cx, scope, sealed);
}
private NativeDate() {
if (thisTimeZone == null) {
// j.u.TimeZone is synchronized, so setting class statics from it
@ -92,7 +92,7 @@ final class NativeDate extends IdScriptable {
switch (methodId) {
case ConstructorId_UTC: return 1;
case ConstructorId_parse: return 1;
case Id_constructor: return 1;
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toTimeString: return 0;
case Id_toDateString: return 0;
@ -148,10 +148,10 @@ final class NativeDate extends IdScriptable {
{
if (prototypeFlag) {
switch (methodId) {
case ConstructorId_UTC:
case ConstructorId_UTC:
return wrap_double(jsStaticFunction_UTC(args));
case ConstructorId_parse:
case ConstructorId_parse:
return wrap_double(jsStaticFunction_parse
(ScriptRuntime.toString(args, 0)));
@ -194,10 +194,10 @@ final class NativeDate extends IdScriptable {
return jsFunction_NaN_date_str;
}
case Id_valueOf:
case Id_valueOf:
return wrap_double(realThis(thisObj, f, true).date);
case Id_getTime:
case Id_getTime:
return wrap_double(realThis(thisObj, f, true).date);
case Id_getYear: {
@ -223,7 +223,7 @@ final class NativeDate extends IdScriptable {
if (t == t) { t = MonthFromTime(LocalTime(t)); }
return wrap_double(t);
}
case Id_getUTCMonth: {
double t = realThis(thisObj, f, true).date;
if (t == t) { t = MonthFromTime(t); }
@ -240,7 +240,7 @@ final class NativeDate extends IdScriptable {
double t = realThis(thisObj, f, true).date;
if (t == t) { t = DateFromTime(t); }
return wrap_double(t);
}
}
case Id_getDay: {
double t = realThis(thisObj, f, true).date;
@ -252,13 +252,13 @@ final class NativeDate extends IdScriptable {
double t = realThis(thisObj, f, true).date;
if (t == t) { t = WeekDay(t); }
return wrap_double(t);
}
}
case Id_getHours: {
double t = realThis(thisObj, f, true).date;
if (t == t) { t = HourFromTime(LocalTime(t)); }
return wrap_double(t);
}
}
case Id_getUTCHours: {
double t = realThis(thisObj, f, true).date;
@ -270,13 +270,13 @@ final class NativeDate extends IdScriptable {
double t = realThis(thisObj, f, true).date;
if (t == t) { t = MinFromTime(LocalTime(t)); }
return wrap_double(t);
}
}
case Id_getUTCMinutes: {
double t = realThis(thisObj, f, true).date;
if (t == t) { t = MinFromTime(t); }
return wrap_double(t);
}
}
case Id_getSeconds: {
double t = realThis(thisObj, f, true).date;
@ -289,7 +289,7 @@ final class NativeDate extends IdScriptable {
if (t == t) { t = SecFromTime(t); }
return wrap_double(t);
}
case Id_getMilliseconds: {
double t = realThis(thisObj, f, true).date;
if (t == t) { t = msFromTime(LocalTime(t)); }
@ -301,74 +301,74 @@ final class NativeDate extends IdScriptable {
if (t == t) { t = msFromTime(t); }
return wrap_double(t);
}
case Id_getTimezoneOffset: {
double t = realThis(thisObj, f, true).date;
if (t == t) { t = jsFunction_getTimezoneOffset(t); }
return wrap_double(t);
}
case Id_setTime:
case Id_setTime:
return wrap_double(realThis(thisObj, f, true).
jsFunction_setTime(ScriptRuntime.toNumber(args, 0)));
case Id_setMilliseconds:
case Id_setMilliseconds:
return wrap_double(realThis(thisObj, f, false).
makeTime(args, 1, true));
case Id_setUTCMilliseconds:
case Id_setUTCMilliseconds:
return wrap_double(realThis(thisObj, f, false).
makeTime(args, 1, false));
case Id_setSeconds:
case Id_setSeconds:
return wrap_double(realThis(thisObj, f, false).
makeTime(args, 2, true));
case Id_setUTCSeconds:
case Id_setUTCSeconds:
return wrap_double(realThis(thisObj, f, false).
makeTime(args, 2, false));
case Id_setMinutes:
case Id_setMinutes:
return wrap_double(realThis(thisObj, f, false).
makeTime(args, 3, true));
case Id_setUTCMinutes:
case Id_setUTCMinutes:
return wrap_double(realThis(thisObj, f, false).
makeTime(args, 3, false));
case Id_setHours:
case Id_setHours:
return wrap_double(realThis(thisObj, f, false).
makeTime(args, 4, true));
case Id_setUTCHours:
case Id_setUTCHours:
return wrap_double(realThis(thisObj, f, false).
makeTime(args, 4, false));
case Id_setDate:
case Id_setDate:
return wrap_double(realThis(thisObj, f, false).
makeDate(args, 1, true));
case Id_setUTCDate:
case Id_setUTCDate:
return wrap_double(realThis(thisObj, f, false).
makeDate(args, 1, false));
case Id_setMonth:
case Id_setMonth:
return wrap_double(realThis(thisObj, f, false).
makeDate(args, 2, true));
case Id_setUTCMonth:
case Id_setUTCMonth:
return wrap_double(realThis(thisObj, f, false).
makeDate(args, 2, false));
case Id_setFullYear:
case Id_setFullYear:
return wrap_double(realThis(thisObj, f, false).
makeDate(args, 3, true));
case Id_setUTCFullYear:
case Id_setUTCFullYear:
return wrap_double(realThis(thisObj, f, false).
makeDate(args, 3, false));
case Id_setYear:
case Id_setYear:
return wrap_double(realThis(thisObj, f, false).
jsFunction_setYear(ScriptRuntime.toNumber(args, 0)));
}
@ -377,7 +377,7 @@ final class NativeDate extends IdScriptable {
return super.execMethod(methodId, f, cx, scope, thisObj, args);
}
private NativeDate realThis(Scriptable thisObj, IdFunction f,
private NativeDate realThis(Scriptable thisObj, IdFunction f,
boolean readOnly)
{
while (!(thisObj instanceof NativeDate)) {
@ -1268,7 +1268,7 @@ final class NativeDate extends IdScriptable {
if (result >= 1900 && result < 2000) {
result -= 1900;
}
}
}
else {
result -= 1900;
}
@ -1466,7 +1466,7 @@ final class NativeDate extends IdScriptable {
switch (id) {
case ConstructorId_UTC: return "UTC";
case ConstructorId_parse: return "parse";
case Id_constructor: return "constructor";
case Id_constructor: return "constructor";
case Id_toString: return "toString";
case Id_toTimeString: return "toTimeString";
case Id_toDateString: return "toDateString";
@ -1512,7 +1512,7 @@ final class NativeDate extends IdScriptable {
case Id_setYear: return "setYear";
}
}
return null;
return null;
}
// #string_id_map#

Просмотреть файл

@ -18,10 +18,10 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Igor Bukanov
* Roger Lawrence
*
*
* 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.
@ -52,7 +52,7 @@ final class NativeError extends IdScriptable {
obj.nameValue = "Error";
obj.addAsPrototype(MAX_PROTOTYPE_ID, cx, scope, sealed);
}
protected int getIdDefaultAttributes(int id) {
if (id == Id_message || id == Id_name) { return EMPTY; }
return super.getIdDefaultAttributes(id);
@ -113,18 +113,18 @@ final class NativeError extends IdScriptable {
return (NativeError)thisObj;
}
private static Object jsConstructor(Context cx, Object[] args,
private static Object jsConstructor(Context cx, Object[] args,
Function funObj, boolean inNewExpr)
{
NativeError result = new NativeError();
if (args.length >= 1)
if (args.length >= 1)
result.messageValue = ScriptRuntime.toString(args[0]);
result.setPrototype(getClassPrototype(funObj, "Error"));
return result;
}
public String getClassName() {
return "Error";
public String getClassName() {
return "Error";
}
public String toString() {
@ -135,18 +135,18 @@ final class NativeError extends IdScriptable {
name = Undefined.instance;
return name + ": " + getMessage();
}
public String getName() {
Object val = nameValue;
return ScriptRuntime.toString(val != NOT_FOUND ? val
return ScriptRuntime.toString(val != NOT_FOUND ? val
: Undefined.instance);
}
public String getMessage() {
Object val = messageValue;
return ScriptRuntime.toString(val != NOT_FOUND ? val
return ScriptRuntime.toString(val != NOT_FOUND ? val
: Undefined.instance);
}
}
protected int maxInstanceId() { return MAX_INSTANCE_ID; }
@ -157,15 +157,15 @@ final class NativeError extends IdScriptable {
if (id == Id_constructor) return "constructor";
if (id == Id_toString) return "toString";
}
return null;
return null;
}
// #string_id_map#
private static final int
Id_message = 1,
Id_name = 2,
MAX_INSTANCE_ID = 2;
protected int mapNameToId(String s) {
@ -197,11 +197,11 @@ final class NativeError extends IdScriptable {
private static final int
Id_constructor = MAX_INSTANCE_ID + 1,
Id_toString = MAX_INSTANCE_ID + 2,
MAX_PROTOTYPE_ID = MAX_INSTANCE_ID + 2;
// #/string_id_map#
private Object messageValue = NOT_FOUND;
private Object nameValue = NOT_FOUND;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Igor Bukanov
* Roger Lawrence
@ -88,12 +88,12 @@ public class NativeFunction extends BaseFunction {
public String decompile(Context cx, int indent, boolean justbody) {
StringBuffer result = new StringBuffer();
decompile(indent, true, justbody, result);
return result.toString();
return result.toString();
}
private void decompile(int indent, boolean toplevel, boolean justbody,
StringBuffer result)
StringBuffer result)
{
if (source == null) {
if (!justbody) {
@ -174,7 +174,7 @@ public class NativeFunction extends BaseFunction {
*/
if (nextIs(i, TokenStream.LP)
&& this.version != Context.VERSION_1_2
&& this.functionName != null
&& this.functionName != null
&& this.functionName.equals("anonymous"))
result.append("anonymous");
i++;
@ -304,11 +304,11 @@ public class NativeFunction extends BaseFunction {
String message;
if (functionName != null && functionName.length() > 0) {
message = Context.getMessage2
("msg.no.function.ref.found.in",
("msg.no.function.ref.found.in",
new Integer((int)source.charAt(i)), functionName);
} else {
message = Context.getMessage1
("msg.no.function.ref.found",
("msg.no.function.ref.found",
new Integer((int)source.charAt(i)));
}
throw Context.reportRuntimeError(message);
@ -720,9 +720,9 @@ public class NativeFunction extends BaseFunction {
result.append(" % ");
break;
default:
default:
// If we don't know how to decompile it, raise an exception.
throw new RuntimeException("Unknown token " +
throw new RuntimeException("Unknown token " +
source.charAt(i));
}
i++;

Просмотреть файл

@ -431,7 +431,7 @@ public class NativeGlobal implements IdFunctionMaster {
buf[destination] = c;
++destination;
}
s = new String(buf, 0, destination);
s = new String(buf, 0, destination);
}
return s;
}
@ -488,8 +488,8 @@ public class NativeGlobal implements IdFunctionMaster {
if (filename == null) {
filename = "";
linep[0] = 1;
}
}
}
}
filename += "(eval)";
try {

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
@ -87,13 +87,13 @@ public class NativeJavaArray extends NativeJavaObject {
if (id.equals("length"))
return new Integer(length);
Object result = super.get(id, start);
if (result == NOT_FOUND &&
!ScriptRuntime.hasProp(getPrototype(), id))
if (result == NOT_FOUND &&
!ScriptRuntime.hasProp(getPrototype(), id))
{
throw Context.reportRuntimeError2(
"msg.java.member.not.found", array.getClass().getName(), id);
}
return result;
return result;
}
public Object get(int index, Scriptable start) {
@ -107,7 +107,7 @@ public class NativeJavaArray extends NativeJavaObject {
if (!id.equals("length"))
super.put(id, start, value);
}
public void put(int index, Scriptable start, Object value) {
if (0 <= index && index < length) {
Array.set(array, index, NativeJavaObject.coerceType(cls, value));
@ -117,7 +117,7 @@ public class NativeJavaArray extends NativeJavaObject {
}
public Object getDefaultValue(Class hint) {
if (hint == null || hint == ScriptRuntime.StringClass)
if (hint == null || hint == ScriptRuntime.StringClass)
return array.toString();
if (hint == ScriptRuntime.BooleanClass)
return Boolean.TRUE;
@ -125,7 +125,7 @@ public class NativeJavaArray extends NativeJavaObject {
return ScriptRuntime.NaNobj;
return this;
}
public Object[] getIds() {
Object[] result = new Object[length];
int i = length;
@ -143,7 +143,7 @@ public class NativeJavaArray extends NativeJavaObject {
public Scriptable getPrototype() {
if (prototype == null) {
prototype =
prototype =
ScriptableObject.getClassPrototype(this.getParentScope(),
"Array");
}
@ -154,9 +154,9 @@ public class NativeJavaArray extends NativeJavaObject {
int length;
Class cls;
Scriptable prototype;
public void writeExternal(ObjectOutput out)
throws IOException
public void writeExternal(ObjectOutput out)
throws IOException
{
super.writeExternal(out);
@ -165,9 +165,9 @@ public class NativeJavaArray extends NativeJavaObject {
out.writeObject(cls.getName());
out.writeObject(prototype);
}
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException
{
super.readExternal(in);
@ -175,5 +175,5 @@ public class NativeJavaArray extends NativeJavaObject {
length = in.readInt();
cls = Class.forName((String)in.readObject());
prototype = (Scriptable)in.readObject();
}
}
}

Просмотреть файл

@ -18,13 +18,13 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
* Kurt Westerfeld
* 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.
@ -63,18 +63,18 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
public NativeJavaClass(Scriptable scope, Class cl) {
super(scope, cl, JavaMembers.lookupClass(scope, cl, cl));
fieldAndMethods = members.getFieldAndMethodsObjects(this, javaObject,
fieldAndMethods = members.getFieldAndMethodsObjects(this, javaObject,
true);
}
public String getClassName() {
return "JavaClass";
}
public boolean has(String name, Scriptable start) {
return members.has(name, true);
}
public Object get(String name, Scriptable start) {
// When used as a constructor, ScriptRuntime.newObject() asks
// for our prototype to create an object of the correct type.
@ -83,15 +83,15 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
if (name.equals("prototype"))
return null;
Object result = Scriptable.NOT_FOUND;
if (fieldAndMethods != null) {
result = fieldAndMethods.get(name);
if (result != null)
return result;
}
if (members.has(name, true)) {
result = members.get(this, name, javaObject, true);
} else {
@ -108,7 +108,7 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
throw members.reportMemberNotFound(name);
}
}
return result;
}
@ -119,8 +119,8 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
public Object[] getIds() {
return members.getIds(true);
}
public Class getClassObject() {
public Class getClassObject() {
return (Class) super.unwrap();
}
@ -144,7 +144,7 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
throws JavaScriptException
{
// If it looks like a "cast" of an object to this class type,
// walk the prototype chain to see if there's a wrapper of a
// walk the prototype chain to see if there's a wrapper of a
// object that's an instanceof this class.
if (args.length == 1 && args[0] instanceof Scriptable) {
Class c = getClassObject();
@ -166,8 +166,8 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
{
Class classObject = getClassObject();
int modifiers = classObject.getModifiers();
if (! (Modifier.isInterface(modifiers) ||
Modifier.isAbstract(modifiers)))
if (! (Modifier.isInterface(modifiers) ||
Modifier.isAbstract(modifiers)))
{
Constructor[] ctors = members.getConstructors();
Member member = NativeJavaMethod.findFunction(ctors, args);
@ -179,20 +179,20 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
}
// Found the constructor, so try invoking it.
return NativeJavaClass.constructSpecific(cx, scope,
return NativeJavaClass.constructSpecific(cx, scope,
this, ctor, args);
} else {
Scriptable topLevel = ScriptableObject.getTopLevelScope(this);
String msg = "";
try {
// trying to construct an interface; use JavaAdapter to
// construct a new class on the fly that implements this
// trying to construct an interface; use JavaAdapter to
// construct a new class on the fly that implements this
// interface.
Object v = topLevel.get("JavaAdapter", topLevel);
if (v != NOT_FOUND) {
Function f = (Function) v;
Object[] adapterArgs = { this, args[0] };
return (Scriptable) f.construct(cx, topLevel,
return (Scriptable) f.construct(cx, topLevel,
adapterArgs);
}
} catch (Exception ex) {
@ -206,9 +206,9 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
}
}
public static Scriptable constructSpecific(Context cx,
Scriptable scope,
Scriptable thisObj,
public static Scriptable constructSpecific(Context cx,
Scriptable scope,
Scriptable thisObj,
Constructor ctor,
Object[] args)
throws JavaScriptException
@ -222,15 +222,15 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
}
try {
// we need to force this to be wrapped, because construct _has_
// to return a scriptable
return
(Scriptable) NativeJavaObject.wrap(topLevel,
// to return a scriptable
return
(Scriptable) NativeJavaObject.wrap(topLevel,
ctor.newInstance(args),
classObject);
} catch (InstantiationException instEx) {
throw Context.reportRuntimeError2(
"msg.cant.instantiate",
"msg.cant.instantiate",
instEx.getMessage(), classObject.getName());
} catch (IllegalArgumentException argEx) {
String signature = NativeJavaMethod.scriptSignature(args);
@ -252,14 +252,14 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
/**
* Determines if prototype is a wrapped Java object and performs
* a Java "instanceof".
* Exception: if value is an instance of NativeJavaClass, it isn't
* considered an instance of the Java class; this forestalls any
* name conflicts between java.lang.Class's methods and the
* Exception: if value is an instance of NativeJavaClass, it isn't
* considered an instance of the Java class; this forestalls any
* name conflicts between java.lang.Class's methods and the
* static methods exposed by a JavaNativeClass.
*/
public boolean hasInstance(Scriptable value) {
if (value instanceof Wrapper &&
if (value instanceof Wrapper &&
!(value instanceof NativeJavaClass)) {
Object instance = ((Wrapper)value).unwrap();
@ -274,18 +274,18 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
// beard: need a scope for finding top-level prototypes.
private Scriptable parent;
public void writeExternal(ObjectOutput out) throws IOException {
public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal(out);
out.writeObject(parent);
}
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException
{
super.readExternal(in);
parent = (Scriptable)in.readObject();
fieldAndMethods = members.getFieldAndMethodsObjects(this, javaObject,
fieldAndMethods = members.getFieldAndMethodsObjects(this, javaObject,
true);
}
}
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
@ -40,11 +40,11 @@ package org.mozilla.javascript;
import java.lang.reflect.*;
/**
* This class reflects a single Java constructor into the JavaScript
* This class reflects a single Java constructor into the JavaScript
* environment. It satisfies a request for an overloaded constructor,
* as introduced in LiveConnect 3.
* All NativeJavaConstructors behave as JSRef `bound' methods, in that they
* always construct the same NativeJavaClass regardless of any reparenting
* always construct the same NativeJavaClass regardless of any reparenting
* that may occur.
*
* @author Frank Mitchell
@ -69,7 +69,7 @@ public class NativeJavaConstructor extends NativeFunction implements Function {
throw new RuntimeException("No constructor defined for call");
}
return NativeJavaClass.constructSpecific(cx, scope,
return NativeJavaClass.constructSpecific(cx, scope,
this, constructor, args);
}
@ -78,7 +78,7 @@ public class NativeJavaConstructor extends NativeFunction implements Function {
}
Constructor getConstructor() {
return constructor;
return constructor;
}
Constructor constructor;

Просмотреть файл

@ -18,11 +18,11 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
*
*
* 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.
@ -74,7 +74,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
functionName = method.getName();
} else if (!functionName.equals(method.getName())) {
throw new RuntimeException("internal method name mismatch");
}
}
// XXX a more intelligent growth algorithm would be nice
int len = methods == null ? 0 : methods.length;
Method[] newMeths = new Method[len + 1];
@ -152,7 +152,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
return "(" + javaSignature(paramTypes) + ")";
}
}
public String decompile(Context cx, int indent, boolean justbody) {
StringBuffer sb = new StringBuffer();
if (!justbody) {
@ -165,7 +165,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
sb.append(justbody ? "*/\n" : "*/}\n");
return sb.toString();
}
public String toString() {
StringBuffer sb = new StringBuffer();
toString(sb);
@ -218,7 +218,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
"msg.nonjava.method", functionName);
}
}
javaObject = ((Wrapper) o).unwrap();
javaObject = ((Wrapper) o).unwrap();
}
try {
if (debug) {
@ -234,9 +234,9 @@ public class NativeJavaMethod extends NativeFunction implements Function {
Class staticType = meth.getReturnType();
if (debug) {
Class actualType = (retval == null) ? null
Class actualType = (retval == null) ? null
: retval.getClass();
System.err.println(" ----- Returned " + retval +
System.err.println(" ----- Returned " + retval +
" actual = " + actualType +
" expect = " + staticType);
}
@ -244,9 +244,9 @@ public class NativeJavaMethod extends NativeFunction implements Function {
Object wrapped = NativeJavaObject.wrap(scope, retval, staticType);
if (debug) {
Class actualType = (wrapped == null) ? null
Class actualType = (wrapped == null) ? null
: wrapped.getClass();
System.err.println(" ----- Wrapped as " + wrapped +
System.err.println(" ----- Wrapped as " + wrapped +
" class = " + actualType);
}
@ -257,7 +257,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
return wrapped;
} catch (IllegalAccessException accessEx) {
throw Context.reportRuntimeError(
"While attempting to call \"" + meth.getName() +
"While attempting to call \"" + meth.getName() +
"\" in class \"" + meth.getDeclaringClass().getName() +
"\" receieved " + accessEx.toString());
} catch (InvocationTargetException e) {
@ -265,8 +265,8 @@ public class NativeJavaMethod extends NativeFunction implements Function {
}
}
static Object retryIllegalAccessInvoke(Method method, Object obj,
Object[] args,
static Object retryIllegalAccessInvoke(Method method, Object obj,
Object[] args,
IllegalAccessException illegalAccess)
throws IllegalAccessException, InvocationTargetException
{
@ -290,11 +290,11 @@ public class NativeJavaMethod extends NativeFunction implements Function {
/**
* Due to a bug in Sun's VM, public methods in private
* classes are not accessible by default (Sun Bug #4071593).
* We have to explicitly set the method accessible
* via method.setAccessible(true) but we have to use
* reflection because the setAccessible() in Method is
* not available under jdk 1.1. We wait until a failure
* to retry to avoid the overhead of this call on cases
* We have to explicitly set the method accessible
* via method.setAccessible(true) but we have to use
* reflection because the setAccessible() in Method is
* not available under jdk 1.1. We wait until a failure
* to retry to avoid the overhead of this call on cases
* that don't require it.
*/
if (method_setAccessible != null) {
@ -310,7 +310,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
throw illegalAccess;
}
/**
/**
* Find the correct function to call given the set of methods
* or constructors and the arguments.
* If no function can be found to call, return null.
@ -319,8 +319,8 @@ public class NativeJavaMethod extends NativeFunction implements Function {
if (methodsOrCtors.length == 0)
return null;
boolean hasMethods = methodsOrCtors[0] instanceof Method;
if (Context.useJSObject &&
NativeJavaObject.jsObjectClass != null)
if (Context.useJSObject &&
NativeJavaObject.jsObjectClass != null)
{
try {
for (int i = 0; i < args.length; i++) {
@ -354,7 +354,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
int j;
for (j = 0; j < paramTypes.length; j++) {
if (!NativeJavaObject.canConvert(args[j], paramTypes[j])) {
if (debug) printDebug("Rejecting (args can't convert) ",
if (debug) printDebug("Rejecting (args can't convert) ",
member, args);
break;
}
@ -366,9 +366,9 @@ public class NativeJavaMethod extends NativeFunction implements Function {
}
}
else {
int preference =
NativeJavaMethod.preferSignature(args,
paramTypes,
int preference =
NativeJavaMethod.preferSignature(args,
paramTypes,
bestFitTypes);
if (preference == PREFERENCE_AMBIGUOUS) {
if (debug) printDebug("Deferring ", member, args);
@ -386,7 +386,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
if (preference == PREFERENCE_EQUAL &&
Modifier.isStatic(bestFit.getModifiers()) &&
bestFit.getDeclaringClass().isAssignableFrom(
member.getDeclaringClass()))
member.getDeclaringClass()))
{
// On some JVMs, Class.getMethods will return all
// static methods of the class heirarchy, even if
@ -402,20 +402,20 @@ public class NativeJavaMethod extends NativeFunction implements Function {
}
}
}
if (ambiguousMethods == null)
return bestFit;
// Compare ambiguous methods with best fit, in case
// Compare ambiguous methods with best fit, in case
// the current best fit removes the ambiguities.
for (int i = ambiguousMethods.size() - 1; i >= 0 ; i--) {
Member member = (Member)ambiguousMethods.elementAt(i);
Class paramTypes[] = hasMethods
? ((Method) member).getParameterTypes()
: ((Constructor) member).getParameterTypes();
int preference =
NativeJavaMethod.preferSignature(args,
paramTypes,
int preference =
NativeJavaMethod.preferSignature(args,
paramTypes,
bestFitTypes);
if (preference == PREFERENCE_FIRST_ARG) {
@ -455,31 +455,31 @@ public class NativeJavaMethod extends NativeFunction implements Function {
String errMsg;
if (isCtor) {
Object errArgs[] = {
bestFit.getName(),
Object errArgs[] = {
bestFit.getName(),
NativeJavaMethod.scriptSignature(args),
buf.toString()
};
errMsg =
errMsg =
Context.getMessage("msg.constructor.ambiguous", errArgs);
}
else {
Object errArgs[] = {
bestFit.getDeclaringClass().getName(),
bestFit.getName(),
Object errArgs[] = {
bestFit.getDeclaringClass().getName(),
bestFit.getName(),
NativeJavaMethod.scriptSignature(args),
buf.toString()
};
errMsg = Context.getMessage("msg.method.ambiguous", errArgs);
}
throw
throw
Context.reportRuntimeError(errMsg);
}
return bestFit;
}
/** Types are equal */
static final int PREFERENCE_EQUAL = 0;
static final int PREFERENCE_FIRST_ARG = 1;
@ -489,11 +489,11 @@ public class NativeJavaMethod extends NativeFunction implements Function {
/**
* Determine which of two signatures is the closer fit.
* Returns one of PREFERENCE_EQUAL, PREFERENCE_FIRST_ARG,
* Returns one of PREFERENCE_EQUAL, PREFERENCE_FIRST_ARG,
* PREFERENCE_SECOND_ARG, or PREFERENCE_AMBIGUOUS.
*/
public static int preferSignature(Object[] args,
Class[] sig1, Class[] sig2)
public static int preferSignature(Object[] args,
Class[] sig1, Class[] sig2)
{
int preference = 0;
@ -506,7 +506,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
}
preference |=
NativeJavaMethod.preferConversion(args[j],
NativeJavaMethod.preferConversion(args[j],
type1,
type2);
@ -520,18 +520,18 @@ public class NativeJavaMethod extends NativeFunction implements Function {
/**
* Determine which of two types is the easier conversion.
* Returns one of PREFERENCE_EQUAL, PREFERENCE_FIRST_ARG,
* Returns one of PREFERENCE_EQUAL, PREFERENCE_FIRST_ARG,
* PREFERENCE_SECOND_ARG, or PREFERENCE_AMBIGUOUS.
*/
public static int preferConversion(Object fromObj,
public static int preferConversion(Object fromObj,
Class toClass1, Class toClass2) {
int rank1 =
int rank1 =
NativeJavaObject.getConversionWeight(fromObj, toClass1);
int rank2 =
int rank2 =
NativeJavaObject.getConversionWeight(fromObj, toClass2);
if (rank1 == NativeJavaObject.CONVERSION_NONTRIVIAL &&
if (rank1 == NativeJavaObject.CONVERSION_NONTRIVIAL &&
rank2 == NativeJavaObject.CONVERSION_NONTRIVIAL) {
if (toClass1.isAssignableFrom(toClass2)) {
@ -553,7 +553,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
}
Method[] getMethods() {
return methods;
return methods;
}
// Utility to call Class.getMethod and get null instead of thrown exceptions
@ -571,7 +571,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
private static void printDebug(String msg, Member member, Object[] args) {
if (debug) {
System.err.println(" ----- " + msg +
System.err.println(" ----- " + msg +
member.getDeclaringClass().getName() +
"." + signature(member) +
" for arguments (" + scriptSignature(args) + ")");
@ -579,7 +579,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
}
Method methods[];
private static final Method method_setAccessible
= getMethod(Method.class,
"setAccessible", new Class[] { Boolean.TYPE });

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Igor Bukanov
* Frank Mitchell
@ -60,16 +60,16 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
public NativeJavaObject() {
}
public NativeJavaObject(Scriptable scope, Object javaObject,
JavaMembers members)
public NativeJavaObject(Scriptable scope, Object javaObject,
JavaMembers members)
{
this.parent = scope;
this.javaObject = javaObject;
this.members = members;
}
public NativeJavaObject(Scriptable scope, Object javaObject,
Class staticType)
public NativeJavaObject(Scriptable scope, Object javaObject,
Class staticType)
{
this.parent = scope;
this.javaObject = javaObject;
@ -79,15 +79,15 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
members = JavaMembers.lookupClass(scope, dynamicType, staticType);
fieldAndMethods = members.getFieldAndMethodsObjects(this, javaObject, false);
}
public boolean has(String name, Scriptable start) {
return members.has(name, false);
}
public boolean has(int index, Scriptable start) {
return false;
}
public Object get(String name, Scriptable start) {
if (fieldAndMethods != null) {
Object result = fieldAndMethods.get(name);
@ -95,7 +95,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
return result;
}
}
// TODO: passing 'this' as the scope is bogus since it has
// TODO: passing 'this' as the scope is bogus since it has
// no parent scope
return members.get(this, name, javaObject, false);
}
@ -103,9 +103,9 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
public Object get(int index, Scriptable start) {
throw members.reportMemberNotFound(Integer.toString(index));
}
public void put(String name, Scriptable start, Object value) {
// We could be asked to modify the value of a property in the
// We could be asked to modify the value of a property in the
// prototype. Since we can't add a property to a Java object,
// we modify it in the prototype rather than copy it down.
if (prototype == null || members.has(name, false))
@ -122,13 +122,13 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
// This is an instance of a Java class, so always return false
return false;
}
public void delete(String name) {
}
public void delete(int index) {
}
public Scriptable getPrototype() {
if (prototype == null && javaObject.getClass() == ScriptRuntime.StringClass) {
return ScriptableObject.getClassPrototype(parent, "String");
@ -160,8 +160,8 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
public Object[] getIds() {
return members.getIds(false);
}
public static Object wrap(Scriptable scope, Object obj, Class staticType)
public static Object wrap(Scriptable scope, Object obj, Class staticType)
{
if (obj == null)
return obj;
@ -183,8 +183,8 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
return NativeJavaArray.wrap(scope, obj);
if (obj instanceof Scriptable)
return obj;
if (Context.useJSObject && jsObjectClass != null &&
staticType != jsObjectClass && jsObjectClass.isInstance(obj))
if (Context.useJSObject && jsObjectClass != null &&
staticType != jsObjectClass && jsObjectClass.isInstance(obj))
{
try {
return jsObjectGetScriptable.invoke(obj, ScriptRuntime.emptyArgs);
@ -277,10 +277,10 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
/**
* Derive a ranking based on how "natural" the conversion is.
* The special value CONVERSION_NONE means no conversion is possible,
* and CONVERSION_NONTRIVIAL signals that more type conformance testing
* The special value CONVERSION_NONE means no conversion is possible,
* and CONVERSION_NONTRIVIAL signals that more type conformance testing
* is required.
* Based on
* Based on
* <a href="http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html">
* "preferred method conversions" from Live Connect 3</a>
*/
@ -292,7 +292,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
switch (fromCode) {
case JSTYPE_UNDEFINED:
if (to == ScriptRuntime.StringClass ||
if (to == ScriptRuntime.StringClass ||
to == ScriptRuntime.ObjectClass) {
result = 1;
}
@ -365,7 +365,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
if (to == ScriptRuntime.ClassClass) {
result = 1;
}
else if (Context.useJSObject && jsObjectClass != null &&
else if (Context.useJSObject && jsObjectClass != null &&
jsObjectClass.isAssignableFrom(to)) {
result = 2;
}
@ -383,7 +383,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
result = 2;
}
else if (to.isPrimitive() && to != Boolean.TYPE) {
result =
result =
(fromCode == JSTYPE_JAVA_ARRAY) ?
CONVERSION_NONTRIVIAL :
2 + NativeJavaObject.getSizeRank(to);
@ -401,13 +401,13 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
case JSTYPE_OBJECT:
// Other objects takes #1-#3 spots
if (Context.useJSObject && jsObjectClass != null &&
if (Context.useJSObject && jsObjectClass != null &&
jsObjectClass.isAssignableFrom(to)) {
result = 1;
}
else if (fromObj instanceof NativeArray && to.isArray()) {
// This is a native array conversion to a java array
// Array conversions are all equal, and preferable to object
// Array conversions are all equal, and preferable to object
// and string conversion, per LC3.
result = 1;
}
@ -424,7 +424,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
}
return result;
}
static int getSizeRank(Class aType) {
@ -510,7 +510,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
if (value != null && value.getClass() == type) {
return value;
}
switch (NativeJavaObject.getJSTypeCode(value)) {
case JSTYPE_NULL:
@ -521,7 +521,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
return null;
case JSTYPE_UNDEFINED:
if (type == ScriptRuntime.StringClass ||
if (type == ScriptRuntime.StringClass ||
type == ScriptRuntime.ObjectClass) {
return "undefined";
}
@ -532,8 +532,8 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
case JSTYPE_BOOLEAN:
// Under LC3, only JS Booleans can be coerced into a Boolean value
if (type == Boolean.TYPE ||
type == ScriptRuntime.BooleanClass ||
if (type == Boolean.TYPE ||
type == ScriptRuntime.BooleanClass ||
type == ScriptRuntime.ObjectClass) {
return value;
}
@ -552,7 +552,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
else if (type == ScriptRuntime.ObjectClass) {
return coerceToNumber(Double.TYPE, value);
}
else if ((type.isPrimitive() && type != Boolean.TYPE) ||
else if ((type.isPrimitive() && type != Boolean.TYPE) ||
ScriptRuntime.NumberClass.isAssignableFrom(type)) {
return coerceToNumber(type, value);
}
@ -566,11 +566,11 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
type == ScriptRuntime.ObjectClass) {
return value;
}
else if (type == Character.TYPE ||
else if (type == Character.TYPE ||
type == ScriptRuntime.CharacterClass) {
// Special case for converting a single char string to a
// Special case for converting a single char string to a
// character
// Placed here because it applies *only* to JS strings,
// Placed here because it applies *only* to JS strings,
// not other JS objects converted to strings
if (((String)value).length() == 1) {
return new Character(((String)value).charAt(0));
@ -579,7 +579,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
return coerceToNumber(type, value);
}
}
else if ((type.isPrimitive() && type != Boolean.TYPE) ||
else if ((type.isPrimitive() && type != Boolean.TYPE) ||
ScriptRuntime.NumberClass.isAssignableFrom(type)) {
return coerceToNumber(type, value);
}
@ -589,8 +589,8 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
break;
case JSTYPE_JAVA_CLASS:
if (Context.useJSObject && jsObjectClass != null &&
(type == ScriptRuntime.ObjectClass ||
if (Context.useJSObject && jsObjectClass != null &&
(type == ScriptRuntime.ObjectClass ||
jsObjectClass.isAssignableFrom(type))) {
return coerceToJSObject(type, (Scriptable)value);
}
@ -639,8 +639,8 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
break;
case JSTYPE_OBJECT:
if (Context.useJSObject && jsObjectClass != null &&
(type == ScriptRuntime.ObjectClass ||
if (Context.useJSObject && jsObjectClass != null &&
(type == ScriptRuntime.ObjectClass ||
jsObjectClass.isAssignableFrom(type))) {
return coerceToJSObject(type, (Scriptable)value);
}
@ -657,7 +657,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
return value;
}
else if (type.isArray() && value instanceof NativeArray) {
// Make a new java array, and coerce the JS array components
// Make a new java array, and coerce the JS array components
// to the target (component) type.
NativeArray array = (NativeArray) value;
long length = array.jsGet_length();
@ -665,7 +665,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
Object Result = Array.newInstance(arrayType, (int)length);
for (int i = 0 ; i < length ; ++i) {
try {
Array.set(Result, i, coerceType(arrayType,
Array.set(Result, i, coerceType(arrayType,
array.get(i, array)));
}
catch (EvaluatorException ee) {
@ -720,14 +720,14 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
if (valueClass == ScriptRuntime.CharacterClass) {
return value;
}
return new Character((char)toInteger(value,
return new Character((char)toInteger(value,
ScriptRuntime.CharacterClass,
(double)Character.MIN_VALUE,
(double)Character.MAX_VALUE));
}
// Double, Float
if (type == ScriptRuntime.ObjectClass ||
if (type == ScriptRuntime.ObjectClass ||
type == ScriptRuntime.DoubleClass || type == Double.TYPE) {
return valueClass == ScriptRuntime.DoubleClass
? value
@ -751,7 +751,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
}
else if (absNumber > (double)Float.MAX_VALUE) {
return new Float((number > 0.0) ?
Float.POSITIVE_INFINITY :
Float.POSITIVE_INFINITY :
Float.NEGATIVE_INFINITY);
}
else {
@ -767,7 +767,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
return value;
}
else {
return new Integer((int)toInteger(value,
return new Integer((int)toInteger(value,
ScriptRuntime.IntegerClass,
(double)Integer.MIN_VALUE,
(double)Integer.MAX_VALUE));
@ -780,15 +780,15 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
}
else {
/* Long values cannot be expressed exactly in doubles.
* We thus use the largest and smallest double value that
* has a value expressible as a long value. We build these
* We thus use the largest and smallest double value that
* has a value expressible as a long value. We build these
* numerical values from their hexidecimal representations
* to avoid any problems caused by attempting to parse a
* decimal representation.
*/
final double max = Double.longBitsToDouble(0x43dfffffffffffffL);
final double min = Double.longBitsToDouble(0xc3e0000000000000L);
return new Long(toInteger(value,
return new Long(toInteger(value,
ScriptRuntime.LongClass,
min,
max));
@ -800,7 +800,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
return value;
}
else {
return new Short((short)toInteger(value,
return new Short((short)toInteger(value,
ScriptRuntime.ShortClass,
(double)Short.MIN_VALUE,
(double)Short.MAX_VALUE));
@ -812,7 +812,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
return value;
}
else {
return new Byte((byte)toInteger(value,
return new Byte((byte)toInteger(value,
ScriptRuntime.ByteClass,
(double)Byte.MIN_VALUE,
(double)Byte.MAX_VALUE));
@ -891,7 +891,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
static void reportConversionError(Object value, Class type) {
throw Context.reportRuntimeError2
("msg.conversion.not.allowed",
("msg.conversion.not.allowed",
value.toString(), NativeJavaMethod.javaSignature(type));
}
@ -903,7 +903,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
jsObjectClass = Class.forName("netscape.javascript.JSObject");
Class ctorParms[] = { ScriptRuntime.ScriptableClass };
jsObjectCtor = jsObjectClass.getConstructor(ctorParms);
jsObjectGetScriptable = jsObjectClass.getMethod("getScriptable",
jsObjectGetScriptable = jsObjectClass.getMethod("getScriptable",
new Class[0]);
} catch (ClassNotFoundException classEx) {
// jsObjectClass already null
@ -911,7 +911,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
// jsObjectClass already null
}
}
/**
* The prototype of this object.
*/
@ -929,13 +929,13 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
static Class jsObjectClass;
static Constructor jsObjectCtor;
static Method jsObjectGetScriptable;
public void writeExternal(ObjectOutput out)
public void writeExternal(ObjectOutput out)
throws IOException
{
out.writeObject(prototype);
out.writeObject(parent);
out.writeObject(staticType != null ? staticType.getClass().getName()
out.writeObject(staticType != null ? staticType.getClass().getName()
: null);
if (javaObject != null) {
@ -950,7 +950,7 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
for (int i=0; i < interfaces.length; i++)
interfaceNames[i] = interfaces[i].getName();
out.writeObject(interfaceNames);
try {
@ -969,8 +969,8 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
out.writeObject(null);
}
}
public void readExternal(ObjectInput in)
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException
{
prototype = (Scriptable)in.readObject();
@ -984,22 +984,22 @@ public class NativeJavaObject implements Scriptable, Wrapper, Externalizable {
String[] interfaceNames = (String[])in.readObject();
Class[] interfaces = new Class[interfaceNames.length];
for (int i=0; i < interfaceNames.length; i++)
interfaces[i] = Class.forName(interfaceNames[i]);
javaObject = JavaAdapter.createAdapterClass(superclass, interfaces,
javaObject = JavaAdapter.createAdapterClass(superclass, interfaces,
(Scriptable)in.readObject(), (Scriptable)in.readObject());
} else {
javaObject = in.readObject();
}
Class dynamicType = javaObject != null ? javaObject.getClass()
Class dynamicType = javaObject != null ? javaObject.getClass()
: staticType;
members = JavaMembers.lookupClass(parent, dynamicType, staticType);
fieldAndMethods = members.getFieldAndMethodsObjects(this, javaObject,
fieldAndMethods = members.getFieldAndMethodsObjects(this, javaObject,
false);
}
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
@ -40,10 +40,10 @@ package org.mozilla.javascript;
import java.lang.reflect.*;
/**
* This class reflects Java packages into the JavaScript environment. We
* lazily reflect classes and subpackages, and use a caching/sharing
* This class reflects Java packages into the JavaScript environment. We
* lazily reflect classes and subpackages, and use a caching/sharing
* system to ensure that members reflected into one JavaPackage appear
* in all other references to the same package (as with Packages.java.lang
* in all other references to the same package (as with Packages.java.lang
* and java.lang).
*
* @author Mike Shaver
@ -68,7 +68,7 @@ public class NativeJavaPackage extends ScriptableObject {
"java.applet",
};
public static Scriptable init(Scriptable scope)
public static Scriptable init(Scriptable scope)
throws PropertyException
{
NativeJavaPackage packages = new NativeJavaPackage("");
@ -93,8 +93,8 @@ public class NativeJavaPackage extends ScriptableObject {
if (Context.useJSObject)
NativeJavaObject.initJSObject();
Method[] m = FunctionObject.findMethods(NativeJavaPackage.class,
Method[] m = FunctionObject.findMethods(NativeJavaPackage.class,
"jsFunction_getClass");
FunctionObject f = new FunctionObject("getClass", m[0], global);
global.defineProperty("getClass", f, ScriptableObject.DONTENUM);
@ -116,8 +116,8 @@ public class NativeJavaPackage extends ScriptableObject {
if (cached != null && cached instanceof NativeJavaPackage) {
pkg = (NativeJavaPackage) cached;
} else {
String newPackage = packageName.length() == 0
? id
String newPackage = packageName.length() == 0
? id
: packageName + "." + id;
pkg = new NativeJavaPackage(newPackage);
pkg.setParentScope(this);
@ -157,14 +157,14 @@ public class NativeJavaPackage extends ScriptableObject {
}
synchronized Object getPkgProperty(String name, Scriptable start,
boolean createPkg)
boolean createPkg)
{
Object cached = super.get(name, start);
if (cached != NOT_FOUND)
return cached;
String newPackage = packageName.length() == 0
? name
? name
: packageName + "." + name;
Context cx = Context.getContext();
SecuritySupport ss = cx.getSecuritySupport();
@ -187,7 +187,7 @@ public class NativeJavaPackage extends ScriptableObject {
}
}
if (newValue != null) {
// Make it available for fast lookup and sharing of
// Make it available for fast lookup and sharing of
// lazily-reflected constructors and static members.
super.put(name, start, newValue);
}
@ -201,16 +201,16 @@ public class NativeJavaPackage extends ScriptableObject {
public String toString() {
return "[JavaPackage " + packageName + "]";
}
public static Scriptable jsFunction_getClass(Context cx,
public static Scriptable jsFunction_getClass(Context cx,
Scriptable thisObj,
Object[] args,
Object[] args,
Function funObj)
{
if (args.length > 0 && args[0] instanceof Wrapper) {
Scriptable result = getTopLevelScope(thisObj);
Class cl = ((Wrapper) args[0]).unwrap().getClass();
// Evaluate the class name by getting successive properties of
// Evaluate the class name by getting successive properties of
// the string to find the appropriate NativeJavaClass object
String name = "Packages." + cl.getName();
int offset = 0;
@ -220,7 +220,7 @@ public class NativeJavaPackage extends ScriptableObject {
? name.substring(offset)
: name.substring(offset, index);
Object prop = result.get(propName, result);
if (!(prop instanceof Scriptable))
if (!(prop instanceof Scriptable))
break; // fall through to error
result = (Scriptable) prop;
if (index == -1)

Просмотреть файл

@ -86,14 +86,14 @@ final class NativeNumber extends IdScriptable {
super.fillConstructorProperties(cx, ctor, sealed);
}
public int methodArity(int methodId) {
if (prototypeFlag) {
switch (methodId) {
case Id_constructor: return 1;
case Id_toString: return 1;
case Id_valueOf: return 0;
case Id_toLocaleString: return 1;
case Id_constructor: return 1;
case Id_toString: return 1;
case Id_valueOf: return 0;
case Id_toLocaleString: return 1;
case Id_toFixed: return 1;
case Id_toExponential: return 1;
case Id_toPrecision: return 1;
@ -223,16 +223,16 @@ final class NativeNumber extends IdScriptable {
protected String getIdName(int id) {
if (prototypeFlag) {
switch (id) {
case Id_constructor: return "constructor";
case Id_toString: return "toString";
case Id_valueOf: return "valueOf";
case Id_toLocaleString: return "toLocaleString";
case Id_constructor: return "constructor";
case Id_toString: return "toString";
case Id_valueOf: return "valueOf";
case Id_toLocaleString: return "toLocaleString";
case Id_toFixed: return "toFixed";
case Id_toExponential: return "toExponential";
case Id_toPrecision: return "toPrecision";
}
}
return null;
return null;
}
// #string_id_map#

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Mike McCabe
@ -70,15 +70,15 @@ public class NativeScript extends NativeFunction implements Script {
private void scopeInit(Context cx, Scriptable scope, boolean sealed) {
// prototypeIdShift != 0 serves as indicator of prototype instance
// and as id offset to take into account ids present in each instance
// of the base class NativeFunction.
// of the base class NativeFunction.
// Not to depend on the assumption NativeFunction.maxInstanceId() != 0,
// 1 is added super.maxInstanceId() to make sure that
// 1 is added super.maxInstanceId() to make sure that
// prototypeIdShift != 0 in the NativeScript prototype.
// In a similar way the following methods use
// In a similar way the following methods use
// methodId - prototypeIdShift + 1, not methodId - prototypeIdShift
// to unshift prototype id to [1 .. MAX_PROTOTYPE_ID] interval
prototypeIdShift = super.maxInstanceId() + 1;
addAsPrototype(MAX_PROTOTYPE_ID + prototypeIdShift - 1,
addAsPrototype(MAX_PROTOTYPE_ID + prototypeIdShift - 1,
cx, scope, sealed);
}
@ -111,7 +111,7 @@ public class NativeScript extends NativeFunction implements Script {
}
public Object execMethod(int methodId, IdFunction f, Context cx,
Scriptable scope, Scriptable thisObj,
Scriptable scope, Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
@ -136,7 +136,7 @@ public class NativeScript extends NativeFunction implements Script {
return super.execMethod(methodId, f, cx, scope, thisObj, args);
}
private NativeScript realThis(Scriptable thisObj, IdFunction f,
private NativeScript realThis(Scriptable thisObj, IdFunction f,
boolean readOnly)
{
while (!(thisObj instanceof NativeScript)) {
@ -149,7 +149,7 @@ public class NativeScript extends NativeFunction implements Script {
* The Java method defining the JavaScript Script constructor.
*
*/
private static Object jsConstructor(Context cx, Scriptable scope,
private static Object jsConstructor(Context cx, Scriptable scope,
Object[] args)
{
String source = args.length == 0
@ -168,9 +168,9 @@ public class NativeScript extends NativeFunction implements Script {
filename = "<Script object>";
linep[0] = 1;
}
Object securityDomain =
Object securityDomain =
cx.getSecurityDomainForStackDepth(5);
return cx.compileReader(scope, reader, filename, linep[0],
return cx.compileReader(scope, reader, filename, linep[0],
securityDomain);
}
catch (IOException e) {
@ -195,7 +195,7 @@ public class NativeScript extends NativeFunction implements Script {
Scriptable scope = getTopLevelScope(this);
return cx.decompileScript(thisScript, scope, 0);
}
/*
* Override method in NativeFunction to avoid ever returning "anonymous"
*/
@ -242,11 +242,11 @@ public class NativeScript extends NativeFunction implements Script {
protected int mapNameToId(String s) {
if (prototypeIdShift != 0) {
int id = toPrototypeId(s);
if (id != 0) {
if (id != 0) {
// Shift [1, MAX_PROTOTYPE_ID] to
// [super.maxInstanceId() + 1,
// super.maxInstanceId() + MAX_PROTOTYPE_ID]
return id + prototypeIdShift - 1;
return id + prototypeIdShift - 1;
}
}
return super.mapNameToId(s);

Просмотреть файл

@ -138,7 +138,7 @@ final class NativeString extends IdScriptable {
{
if (prototypeFlag) {
switch (methodId) {
case ConstructorId_fromCharCode:
case ConstructorId_fromCharCode:
return jsStaticFunction_fromCharCode(args);
case Id_constructor:
@ -150,11 +150,11 @@ final class NativeString extends IdScriptable {
case Id_valueOf:
return realThis(thisObj, f).jsFunction_valueOf();
case Id_charAt:
case Id_charAt:
return jsFunction_charAt
(ScriptRuntime.toString(thisObj), args);
case Id_charCodeAt:
case Id_charCodeAt:
return wrap_double(jsFunction_charCodeAt
(ScriptRuntime.toString(thisObj), args));
@ -162,11 +162,11 @@ final class NativeString extends IdScriptable {
return wrap_int(jsFunction_indexOf
(ScriptRuntime.toString(thisObj), args));
case Id_lastIndexOf:
case Id_lastIndexOf:
return wrap_int(jsFunction_lastIndexOf
(ScriptRuntime.toString(thisObj), args));
case Id_split:
case Id_split:
return jsFunction_split
(cx, scope, ScriptRuntime.toString(thisObj), args);
@ -182,7 +182,7 @@ final class NativeString extends IdScriptable {
return jsFunction_toUpperCase
(ScriptRuntime.toString(thisObj));
case Id_substr:
case Id_substr:
return jsFunction_substr
(ScriptRuntime.toString(thisObj), args);
@ -223,7 +223,7 @@ final class NativeString extends IdScriptable {
case Id_fontsize:
return realThis(thisObj, f).
tagify("font size", "font",
tagify("font size", "font",
ScriptRuntime.toString(args, 0));
case Id_fontcolor:
@ -775,7 +775,7 @@ final class NativeString extends IdScriptable {
protected String getIdName(int id) {
if (id == Id_length) { return "length"; }
if (prototypeFlag) {
switch (id) {
case ConstructorId_fromCharCode: return "fromCharCode";
@ -821,12 +821,12 @@ final class NativeString extends IdScriptable {
ConstructorId_fromCharCode = -1,
Id_length = 1,
MAX_INSTANCE_ID = 1;
protected int mapNameToId(String s) {
if (s.equals("length")) { return Id_length; }
else if (prototypeFlag) {
return toPrototypeId(s);
else if (prototypeFlag) {
return toPrototypeId(s);
}
return 0;
}
@ -937,7 +937,7 @@ final class NativeString extends IdScriptable {
private static final String defaultValue = "";
private String string;
private boolean prototypeFlag;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -43,8 +43,8 @@ import java.lang.reflect.Method;
* It simply delegates every action to its prototype except
* for operations on its parent.
*/
public final class NativeWith implements Scriptable, IdFunctionMaster {
public final class NativeWith implements Scriptable, IdFunctionMaster {
static void init(Context cx, Scriptable scope, boolean sealed) {
NativeWith obj = new NativeWith();
obj.prototypeFlag = true;
@ -52,10 +52,10 @@ public final class NativeWith implements Scriptable, IdFunctionMaster {
IdFunction ctor = new IdFunction(obj, "constructor", Id_constructor);
ctor.initAsConstructor(scope, obj);
if (sealed) { ctor.sealObject(); }
obj.setParentScope(ctor);
obj.setPrototype(ScriptableObject.getObjectPrototype(scope));
ScriptableObject.defineProperty(scope, "With", ctor,
ScriptableObject.DONTENUM);
}
@ -145,7 +145,7 @@ public final class NativeWith implements Scriptable, IdFunctionMaster {
}
public Object execMethod(int methodId, IdFunction function, Context cx,
Scriptable scope, Scriptable thisObj,
Scriptable scope, Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
@ -157,7 +157,7 @@ public final class NativeWith implements Scriptable, IdFunctionMaster {
}
throw IdFunction.onBadMethodId(this, methodId);
}
public int methodArity(int methodId) {
if (prototypeFlag) {
if (methodId == Id_constructor) { return 0; }
@ -165,15 +165,15 @@ public final class NativeWith implements Scriptable, IdFunctionMaster {
return -1;
}
public static Object newWithSpecial(Context cx, Object[] args,
public static Object newWithSpecial(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr)
{
if (!inNewExpr) {
throw Context.reportRuntimeError1("msg.only.from.new", "With");
}
ScriptRuntime.checkDeprecated(cx, "With");
Scriptable scope = ScriptableObject.getTopLevelScope(ctorObj);
NativeWith thisObj = new NativeWith();
thisObj.setPrototype(args.length == 0
@ -183,8 +183,8 @@ public final class NativeWith implements Scriptable, IdFunctionMaster {
thisObj.setParentScope(scope);
return thisObj;
}
private static final int
private static final int
Id_constructor = 1;
private Scriptable prototype;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Mike McCabe
@ -317,7 +317,7 @@ public class Node implements Cloneable {
RIGHT = 2;
private static String propNames[];
private static final String propToString(int propType) {
if (Context.printTrees && propNames == null) {
// If Context.printTrees is false, the compiler
@ -392,7 +392,7 @@ public class Node implements Cloneable {
props = new UintMap(2);
props.put(propType, prop);
}
public void removeProp(int propType) {
if (props != null) {
props.remove(propType);
@ -493,7 +493,7 @@ public class Node implements Cloneable {
public String toStringTree() {
return toStringTreeHelper(0);
}
private String toStringTreeHelper(int level) {
if (Context.printTrees) {
@ -504,7 +504,7 @@ public class Node implements Cloneable {
s.append(toString());
s.append('\n');
for (Node cursor = getFirstChild(); cursor != null;
cursor = cursor.getNextSibling())
cursor = cursor.getNextSibling())
{
Node n = cursor;
if (cursor.getType() == TokenStream.FUNCTION) {

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Mike McCabe
@ -49,7 +49,7 @@ import java.util.Vector;
*/
public class NodeTransformer {
/**
* Return new instance of this class. So that derived classes
* can override methods of the transformer.
@ -57,13 +57,13 @@ public class NodeTransformer {
public NodeTransformer newInstance() {
return new NodeTransformer();
}
public IRFactory createIRFactory(TokenStream ts, Scriptable scope) {
return new IRFactory(ts, scope);
}
public Node transform(Node tree, Node enclosing, TokenStream ts,
Scriptable scope)
Scriptable scope)
{
loops = new Stack();
loopEnds = new Stack();
@ -104,8 +104,8 @@ public class NodeTransformer {
FunctionNode fnNode = (FunctionNode)
node.getProp(Node.FUNCTION_PROP);
if (inFunction) {
// Functions containing other functions require
// activation objects
// Functions containing other functions require
// activation objects
((FunctionNode) tree).setRequiresActivation(true);
// Nested functions must check their 'this' value to
@ -115,7 +115,7 @@ public class NodeTransformer {
}
addParameters(fnNode);
NodeTransformer inner = newInstance();
fnNode = (FunctionNode)
fnNode = (FunctionNode)
inner.transform(fnNode, tree, ts, scope);
node.putProp(Node.FUNCTION_PROP, fnNode);
Vector fns = (Vector) tree.getProp(Node.FUNCTION_PROP);
@ -141,7 +141,7 @@ public class NodeTransformer {
if (id.equals(otherId)) {
String message = Context.getMessage1(
"msg.dup.label", id);
reportMessage(Context.getContext(), message, node,
reportMessage(Context.getContext(), message, node,
tree, true, scope);
break typeswitch;
}
@ -165,11 +165,11 @@ public class NodeTransformer {
break;
parent.addChildAfter(breakTarget, next);
node.putProp(Node.BREAK_PROP, breakTarget);
if (next.getType() == TokenStream.LOOP) {
node.putProp(Node.CONTINUE_PROP,
node.putProp(Node.CONTINUE_PROP,
next.getProp(Node.CONTINUE_PROP));
}
}
loops.push(node);
loopEnds.push(breakTarget);
@ -337,7 +337,7 @@ public class NodeTransformer {
int propType = type == TokenStream.BREAK
? Node.BREAK_PROP
: Node.CONTINUE_PROP;
Node target = loop == null
Node target = loop == null
? null
: (Node) loop.getProp(propType);
if (loop == null || target == null) {
@ -358,7 +358,7 @@ public class NodeTransformer {
message = Context.getMessage
("msg.undef.label", errArgs);
}
reportMessage(Context.getContext(), message, node,
reportMessage(Context.getContext(), message, node,
tree, true, scope);
node.setType(TokenStream.NOP);
break;
@ -455,18 +455,18 @@ public class NodeTransformer {
}
break;
}
case TokenStream.GETPROP:
if (inFunction) {
Node n = node.getFirstChild().getNextSibling();
String name = n == null ? "" : n.getString();
Context cx = Context.getCurrentContext();
if ((cx != null && cx.isActivationNeeded(name)) ||
(name.equals("length") &&
Context.getContext().getLanguageVersion() ==
(name.equals("length") &&
Context.getContext().getLanguageVersion() ==
Context.VERSION_1_2))
{
// Use of "arguments" or "length" in 1.2 requires
// Use of "arguments" or "length" in 1.2 requires
// an activation object.
((FunctionNode) tree).setRequiresActivation(true);
}
@ -505,9 +505,9 @@ public class NodeTransformer {
while ((node = iterator.nextNode()) != null) {
int nodeType = node.getType();
if (inFunction && nodeType == TokenStream.FUNCTION &&
node != tree &&
((FunctionNode) node.getProp(Node.FUNCTION_PROP)).getFunctionType() ==
FunctionNode.FUNCTION_EXPRESSION_STATEMENT)
node != tree &&
((FunctionNode) node.getProp(Node.FUNCTION_PROP)).getFunctionType() ==
FunctionNode.FUNCTION_EXPRESSION_STATEMENT)
{
// In a function with both "var x" and "function x",
// disregard the var statement, independent of order.
@ -522,7 +522,7 @@ public class NodeTransformer {
if (nodeType != TokenStream.VAR)
continue;
for (Node cursor = node.getFirstChild(); cursor != null;
cursor = cursor.getNextSibling())
cursor = cursor.getNextSibling())
{
if (ht == null || ht.get(cursor.getString()) == null)
vars.addLocal(cursor.getString());
@ -535,7 +535,7 @@ public class NodeTransformer {
vars.getVariable(name) == null)
{
// A function expression needs to have its name as a variable
// (if it isn't already allocated as a variable). See
// (if it isn't already allocated as a variable). See
// ECMA Ch. 13. We add code to the beginning of the function
// to initialize a local variable of the function's name
// to the function value.
@ -557,14 +557,14 @@ public class NodeTransformer {
{
// Add parameters
for (Node cursor = args.getFirstChild(); cursor != null;
cursor = cursor.getNextSibling())
cursor = cursor.getNextSibling())
{
String arg = cursor.getString();
vars.addParameter(arg);
}
}
}
protected void visitNew(Node node, Node tree) {
}
@ -597,8 +597,8 @@ public class NodeTransformer {
if (left.getType() == TokenStream.NAME) {
VariableTable vars = getVariableTable(tree);
String name = left.getString();
if (inFunction && vars.getVariable(name) != null &&
!inWithStatement())
if (inFunction && vars.getVariable(name) != null &&
!inWithStatement())
{
// call to a var. Transform to Call(GetVar("a"), b, c)
left.setType(TokenStream.GETVAR);
@ -660,7 +660,7 @@ public class NodeTransformer {
}
/**
* Return true if the node is a call to a function that requires
* Return true if the node is a call to a function that requires
* access to the enclosing activation object.
*/
private boolean isSpecialCallName(Node tree, Node node) {
@ -699,8 +699,8 @@ public class NodeTransformer {
}
return result;
}
protected void reportMessage(Context cx, String msg, Node stmt,
protected void reportMessage(Context cx, String msg, Node stmt,
Node tree, boolean isError,
Scriptable scope)
{
@ -708,19 +708,19 @@ public class NodeTransformer {
int lineno = 0;
if (obj != null && obj instanceof Integer)
lineno = ((Integer) obj).intValue();
Object prop = tree == null
Object prop = tree == null
? null
: tree.getProp(Node.SOURCENAME_PROP);
if (isError) {
if (scope != null)
throw NativeGlobal.constructError(
cx, "SyntaxError", msg, scope,
cx, "SyntaxError", msg, scope,
(String) prop, lineno, 0, null);
else
cx.reportError(msg, (String) prop, lineno, null, 0);
}
else
cx.reportWarning(msg, (String) prop, lineno, null, 0);
cx.reportWarning(msg, (String) prop, lineno, null, 0);
}
protected Stack loops;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Mike Ang
* Mike McCabe
*
@ -65,15 +65,15 @@ class Parser {
ts.ungetToken(tt); // In case the parser decides to continue
}
}
private void reportError(TokenStream ts, String messageId)
private void reportError(TokenStream ts, String messageId)
throws JavaScriptException
{
this.ok = false;
ts.reportSyntaxError(messageId, null);
/* Throw an exception to unwind the recursive descent parse.
* We use JavaScriptException here even though it is really
/* Throw an exception to unwind the recursive descent parse.
* We use JavaScriptException here even though it is really
* a different use of the exception than it is usually used
* for.
*/
@ -81,7 +81,7 @@ class Parser {
}
/*
* Build a parse tree from the given TokenStream.
* Build a parse tree from the given TokenStream.
*
* @param ts the TokenStream to parse
*
@ -173,7 +173,7 @@ class Parser {
return pn;
}
private Object function(TokenStream ts, boolean isExpr)
throws IOException, JavaScriptException
{
@ -206,27 +206,27 @@ class Parser {
if (Context.getContext().hasFeature
(Context.FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME))
{
// Note that memberExpr can not start with '(' like
// Note that memberExpr can not start with '(' like
// in (1+2).toString, because 'function (' already
// processed as anonymous function
memberExprNode = memberExpr(ts, false);
}
mustMatchToken(ts, ts.LP, "msg.no.paren.parms");
}
if (memberExprNode != null) {
// transform 'function' <memberExpr> to <memberExpr> = function
// even in the decompilated source
sourceAdd((char)ts.ASSIGN);
sourceAdd((char)ts.NOP);
}
// save a reference to the function in the enclosing source.
sourceAdd((char) ts.FUNCTION);
sourceAdd((char)functionNumber);
++functionNumber;
// Save current source top to restore it on exit not to include
// Save current source top to restore it on exit not to include
// function to parent source
int savedSourceTop = sourceTop;
int savedFunctionNumber = functionNumber;
@ -275,17 +275,17 @@ class Parser {
sourceTop = savedSourceTop;
functionNumber = savedFunctionNumber;
}
Object pn = nf.createFunction(name, args, body,
ts.getSourceName(),
baseLineno, ts.getLineno(),
source,
source,
isExpr || memberExprNode != null);
if (memberExprNode != null) {
pn = nf.createBinary(ts.ASSIGN, ts.NOP, memberExprNode, pn);
}
// Add EOL but only if function is not part of expression, in which
// Add EOL but only if function is not part of expression, in which
// case it gets SEMI + EOL from Statement.
if (!isExpr) {
if (memberExprNode != null) {
@ -296,7 +296,7 @@ class Parser {
sourceAdd((char)ts.EOL);
wellTerminated(ts, ts.FUNCTION);
}
return pn;
}
@ -375,7 +375,7 @@ class Parser {
return label;
}
private Object statement(TokenStream ts)
private Object statement(TokenStream ts)
throws IOException
{
try {
@ -386,17 +386,17 @@ class Parser {
int t;
do {
t = ts.getToken();
} while (t != TokenStream.SEMI && t != TokenStream.EOL &&
} while (t != TokenStream.SEMI && t != TokenStream.EOL &&
t != TokenStream.EOF && t != TokenStream.ERROR);
return nf.createExprStatement(nf.createName("error"), lineno);
}
}
/**
* Whether the "catch (e: e instanceof Exception) { ... }" syntax
* is implemented.
*/
private Object statementHelper(TokenStream ts)
throws IOException, JavaScriptException
{
@ -480,7 +480,7 @@ class Parser {
case_statements = nf.createLeaf(TokenStream.BLOCK);
while ((tt = ts.peekToken()) != ts.RC && tt != ts.CASE &&
tt != ts.DEFAULT && tt != ts.EOF)
tt != ts.DEFAULT && tt != ts.EOF)
{
nf.addChildToBack(case_statements, statement(ts));
}
@ -629,7 +629,7 @@ class Parser {
mustMatchToken(ts, ts.NAME, "msg.bad.catchcond");
String varName = ts.getString();
sourceAddString(ts.NAME, varName);
Object catchCond = null;
if (ts.matchToken(ts.IF)) {
sourceAdd((char)ts.IF);
@ -643,10 +643,10 @@ class Parser {
mustMatchToken(ts, ts.LC, "msg.no.brace.catchblock");
sourceAdd((char)ts.LC);
sourceAdd((char)ts.EOL);
nf.addChildToBack(catchblocks,
nf.createCatch(varName, catchCond,
statements(ts),
nf.addChildToBack(catchblocks,
nf.createCatch(varName, catchCond,
statements(ts),
ts.getLineno()));
mustMatchToken(ts, ts.RC, "msg.no.brace.after.body");
@ -817,7 +817,7 @@ class Parser {
}
pn = nf.createExprStatement(pn, lineno);
/*
* Check explicitly against (multi-line) function
* statement.
@ -1129,7 +1129,7 @@ class Parser {
return pn;
}
return nf.createName("err"); // Only reached on error. Try to continue.
}
private Object argumentList(TokenStream ts, Object listNode)
@ -1147,7 +1147,7 @@ class Parser {
first = false;
nf.addChildToBack(listNode, assignExpr(ts, false));
} while (ts.matchToken(ts.COMMA));
mustMatchToken(ts, ts.RP, "msg.no.paren.arg");
}
sourceAdd((char)ts.RP);
@ -1160,7 +1160,7 @@ class Parser {
int tt;
Object pn;
/* Check for new expressions. */
ts.flags |= ts.TSF_REGEXP;
tt = ts.peekToken();
@ -1184,7 +1184,7 @@ class Parser {
* "too many constructor arguments" - how many
* do we claim to support?
*/
/* Experimental syntax: allow an object literal to follow a new expression,
* which will mean a kind of anonymous class built with the JavaAdapter.
* the object literal will be passed as an additional argument to the constructor.
@ -1196,7 +1196,7 @@ class Parser {
} else {
pn = primaryExpr(ts);
}
return memberExprTail(ts, allowCallSyntax, pn);
}
@ -1231,7 +1231,7 @@ class Parser {
pn = nf.createUnary(ts.CALL, pn);
sourceAdd((char)ts.LP);
/* Add the arguments to pn, if any are supplied. */
pn = argumentList(ts, pn);
lastExprEndLine = ts.getLineno();
@ -1410,7 +1410,7 @@ class Parser {
}
return null; // should never reach here
}
/**
* The following methods save decompilation information about the source.
* Source information is returned from the parser as a String
@ -1493,7 +1493,7 @@ class Parser {
* constant pool UTF-8 encoding, so a Double could take
* up to 12 bytes.
*/
long lbits = (long)n;
if (lbits != n) {
// if it's floating point, save as a Double bit pattern.
@ -1509,7 +1509,7 @@ class Parser {
// we can ignore negative values, bc they're already prefixed
// by UNARYOP SUB
if (Context.check && lbits < 0) Context.codeBug();
// will it fit in a char?
// this gives a short encoding for integer values up to 2^16.
if (lbits <= Character.MAX_VALUE) {
@ -1538,13 +1538,13 @@ class Parser {
System.arraycopy(sourceBuffer, 0, tmp, 0, sourceTop);
sourceBuffer = tmp;
}
private String sourceToString(int offset) {
if (Context.check && (offset < 0 || sourceTop < offset))
Context.codeBug();
return new String(sourceBuffer, offset, sourceTop - offset);
}
private int lastExprEndLine; // Hack to handle function expr termination.
private IRFactory nf;
private ErrorReporter er;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Igor Bukanov
@ -53,7 +53,7 @@ public class PreorderNodeIterator {
}
public Node getCurrentParent() {
// Should not be used when stackTop == 0,
// Should not be used when stackTop == 0,
// i.e. with start or its siblings
return stack[stackTop - 1];
}
@ -86,7 +86,7 @@ public class PreorderNodeIterator {
}
public void replaceCurrent(Node newNode) {
// Should not be used when stackTop == 0,
// Should not be used when stackTop == 0,
// i.e. with start or its siblings
Node parent = stack[stackTop - 1];
if (cachedPrev != null && cachedPrev.next == current) {
@ -99,7 +99,7 @@ public class PreorderNodeIterator {
}
current = newNode;
}
private void stackPush(Node n) {
int N = stackTop;
if (N == 0) {
@ -122,5 +122,5 @@ public class PreorderNodeIterator {
//cache previous sibling of current not to search for it when
//replacing current
private Node cachedPrev;
private Node cachedPrev;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -56,7 +56,7 @@ public class PropertyException extends Exception {
}
static PropertyException withMessage2
(String messageId, Object arg1, Object arg2)
(String messageId, Object arg1, Object arg2)
{
return new PropertyException
(Context.getMessage2(messageId, arg1, arg2));

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
@ -40,29 +40,29 @@ package org.mozilla.javascript;
/**
* A proxy for the regexp package, so that the regexp package can be
* loaded optionally.
*
*
* @author Norris Boyd
*/
public interface RegExpProxy {
public boolean isRegExp(Object obj);
public Object newRegExp(Context cx, Scriptable scope, String source,
public Object newRegExp(Context cx, Scriptable scope, String source,
String global, boolean flat);
public Object match(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
throws JavaScriptException;
public Object search(Context cx, Scriptable scope,
public Object search(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
throws JavaScriptException;
public Object replace(Context cx, Scriptable scope,
public Object replace(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
throws JavaScriptException;
public int find_split(Scriptable scope, String target, String separator,
Object re, int[] ip, int[] matchlen,
public int find_split(Scriptable scope, String target, String separator,
Object re, int[] ip, int[] matchlen,
boolean[] matched, String[][] parensp);
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the

Просмотреть файл

@ -21,7 +21,7 @@
* Contributor(s):
* Patrick Beard
* Norris Boyd
* Igor Bukanov
* Igor Bukanov
* Roger Lawrence
* Frank Mitchell
* Andrew Wason
@ -123,7 +123,7 @@ public class ScriptRuntime {
* See ECMA 9.3.
*/
public static double toNumber(Object val) {
if (val == null)
if (val == null)
return +0.0;
if (val instanceof Scriptable) {
val = ((Scriptable) val).getDefaultValue(NumberClass);
@ -143,7 +143,7 @@ public class ScriptRuntime {
public static double toNumber(Object[] args, int index) {
return (index < args.length) ? toNumber(args[index]) : NaN;
}
// This definition of NaN is identical to that in java.lang.Double
// except that it is not final. This is a workaround for a bug in
// the Microsoft VM, versions 2.01 and 3.0P1, that causes some uses
@ -438,7 +438,7 @@ public class ScriptRuntime {
public static String toString(double val) {
return numberToString(val, 10);
}
public static String numberToString(double d, int base) {
if (d != d)
return "NaN";
@ -461,7 +461,7 @@ public class ScriptRuntime {
DToA.JS_dtostr(result, DToA.DTOSTR_STANDARD, 0, d);
return result.toString();
}
}
// ALERT: should it be deprecated ?
@ -475,13 +475,13 @@ public class ScriptRuntime {
{
return toObject(Context.getContext(), scope, val, staticClass);
}
/**
* Convert the value to an object.
*
* See ECMA 9.9.
*/
public static Scriptable toObject(Context cx, Scriptable scope, Object val)
public static Scriptable toObject(Context cx, Scriptable scope, Object val)
{
return toObject(cx, scope, val, null);
}
@ -851,15 +851,15 @@ public class ScriptRuntime {
return value;
}
// Return -1L if str is not an index or the index value as lower 32
// Return -1L if str is not an index or the index value as lower 32
// bits of the result
private static long indexFromString(String str) {
// It must be a string.
// The length of the decimal string representation of
// The length of the decimal string representation of
// Integer.MAX_VALUE, 2147483647
final int MAX_VALUE_LENGTH = 10;
int len = str.length();
if (len > 0) {
int i = 0;
@ -867,13 +867,13 @@ public class ScriptRuntime {
int c = str.charAt(0);
if (c == '-') {
if (len > 1) {
c = str.charAt(1);
i = 1;
c = str.charAt(1);
i = 1;
negate = true;
}
}
c -= '0';
if (0 <= c && c <= 9
if (0 <= c && c <= 9
&& len <= (negate ? MAX_VALUE_LENGTH + 1 : MAX_VALUE_LENGTH))
{
// Use negative numbers to accumulate index to handle
@ -896,7 +896,7 @@ public class ScriptRuntime {
if (i == len &&
(oldIndex > (Integer.MIN_VALUE / 10) ||
(oldIndex == (Integer.MIN_VALUE / 10) &&
c <= (negate ? -(Integer.MIN_VALUE % 10)
c <= (negate ? -(Integer.MIN_VALUE % 10)
: (Integer.MAX_VALUE % 10)))))
{
return 0xFFFFFFFFL & (negate ? index : -index);
@ -951,9 +951,9 @@ public class ScriptRuntime {
s = null;
} else {
index = 0;
}
}
}
Scriptable start = obj instanceof Scriptable
? (Scriptable) obj
: toObject(scope, obj);
@ -1210,11 +1210,11 @@ public class ScriptRuntime {
throws JavaScriptException
{
Scriptable scope = null;
if (fun instanceof Scriptable)
if (fun instanceof Scriptable)
scope = ((Scriptable) fun).getParentScope();
return call(cx, fun, thisArg, args, scope);
}
public static Object call(Context cx, Object fun, Object thisArg,
Object[] args, Scriptable scope)
throws JavaScriptException
@ -1238,7 +1238,7 @@ public class ScriptRuntime {
}
private static Object callOrNewSpecial(Context cx, Scriptable scope,
Object fun, Object jsThis,
Object fun, Object jsThis,
Object thisArg,
Object[] args, boolean isCall,
String filename, int lineNumber)
@ -1250,7 +1250,7 @@ public class ScriptRuntime {
if (name.length() == 4) {
if (name.equals("eval")) {
if (f.master.getClass() == NativeGlobal.class) {
return NativeGlobal.evalSpecial(cx, scope,
return NativeGlobal.evalSpecial(cx, scope,
thisArg, args,
filename, lineNumber);
}
@ -1734,7 +1734,7 @@ public class ScriptRuntime {
*
* This is a new JS 1.3 language feature. The in operator mirrors
* the operation of the for .. in construct, and tests whether the
* rhs has the property given by the lhs. It is different from the
* rhs has the property given by the lhs. It is different from the
* for .. in construct in that:
* <BR> - it doesn't perform ToObject on the right hand side
* <BR> - it returns true for DontEnum properties.
@ -1821,7 +1821,7 @@ public class ScriptRuntime {
// Statements
// ------------------
private static final String GLOBAL_CLASS =
private static final String GLOBAL_CLASS =
"org.mozilla.javascript.tools.shell.Global";
private static ScriptableObject getGlobal(Context cx) {
@ -1851,12 +1851,12 @@ public class ScriptRuntime {
Context cx = Context.enter();
ScriptableObject global = getGlobal(cx);
// get the command line arguments and define "arguments"
// get the command line arguments and define "arguments"
// array in the top-level object
Scriptable argsObj = cx.newArray(global, args);
global.defineProperty("arguments", argsObj,
ScriptableObject.DONTENUM);
try {
Class cl = loadClassName(scriptClassName);
Script script = (Script) cl.newInstance();
@ -1912,7 +1912,7 @@ public class ScriptRuntime {
if (so != null && !fromEvalCode)
so.defineProperty(name, Undefined.instance,
ScriptableObject.PERMANENT);
else
else
varScope.put(name, varScope, Undefined.instance);
}
}
@ -2011,7 +2011,7 @@ public class ScriptRuntime {
result.setParentScope(scope);
String fnName = result.getFunctionName();
if (setName && fnName != null && fnName.length() != 0 &&
if (setName && fnName != null && fnName.length() != 0 &&
!fnName.equals("anonymous"))
{
setProp(scope, fnName, result, scope);
@ -2040,7 +2040,7 @@ public class ScriptRuntime {
}
public static String getMessage2
(String messageId, Object arg1, Object arg2)
(String messageId, Object arg1, Object arg2)
{
return Context.getMessage2(messageId, arg1, arg2);
}
@ -2063,7 +2063,7 @@ public class ScriptRuntime {
cx.currentActivation = activation;
}
public static Class loadClassName(String className)
public static Class loadClassName(String className)
throws ClassNotFoundException
{
try {
@ -2079,7 +2079,7 @@ public class ScriptRuntime {
// thread than the current thread.
// So fall through...
}
return Class.forName(className);
return Class.forName(className);
}
static boolean hasProp(Scriptable start, String name) {

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -46,7 +46,7 @@ package org.mozilla.javascript;
* class rather than implementing Scriptable when writing host objects.
* <p>
* There are many static methods defined in ScriptableObject that perform
* the multiple calls to the Scriptable interface needed in order to
* the multiple calls to the Scriptable interface needed in order to
* manipulate properties in prototype chains.
* <p>
*
@ -160,7 +160,7 @@ public interface Scriptable {
/**
* Sets a named property in this object.
* <p>
* The property is specified by a string name
* The property is specified by a string name
* as defined for <code>get</code>.
* <p>
* The possible values that may be passed in are as defined for
@ -186,11 +186,11 @@ public interface Scriptable {
* <LI>java.lang.Number objects</LI>
* <LI>org.mozilla.javascript.Scriptable objects</LI>
* <LI>null</LI>
* <LI>The value returned by Context.getUndefinedValue()</LI>
* </UL><p>
* <LI>The value returned by Context.getUndefinedValue()</LI>
* </UL><p>
* Arbitrary Java objects may be wrapped in a Scriptable by first calling
* <code>Context.toObject</code>. This allows the property of a JavaScript
* object to contain an arbitrary Java object as a value.<p>
* object to contain an arbitrary Java object as a value.<p>
* Note that <code>has</code> will be called by the runtime first before
* <code>set</code> is called to determine in which object the
* property is defined.

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Igor Bukanov
* Roger Lawrence
@ -146,8 +146,8 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
if (name == slot.stringKey) {
// Cache match, check if it was not deleted
if (slot.wasDeleted == 0) { return slot.value; }
}
}
int hashCode = name.hashCode();
slot = getSlot(name, hashCode, false);
if (slot == null) {
@ -157,17 +157,17 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
return getByGetter((GetterSlot) slot, name, start);
}
// Here stringKey.equals(name) holds, but it can be that
// Here stringKey.equals(name) holds, but it can be that
// slot.stringKey != name. To make last name cache work, need
// to change the key
slot.stringKey = name;
// Update cache.
// Update cache.
lastAccess = slot;
return slot.value;
}
private Object getByGetter(GetterSlot slot,
private Object getByGetter(GetterSlot slot,
String name, Scriptable start)
{
try {
@ -193,9 +193,9 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
catch (IllegalAccessException e) {
throw WrappedException.wrapException(e);
}
}
/**
* Returns the value of the indexed property or NOT_FOUND.
*
@ -209,7 +209,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
return Scriptable.NOT_FOUND;
return slot.value;
}
/**
* Sets the value of the named property, creating it if need be.
*
@ -290,7 +290,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
catch (IllegalAccessException e) {
throw WrappedException.wrapException(e);
}
if (slot.setterReturnsValue) {
slot.value = setterResult;
if (!(setterResult instanceof Method)) {
@ -495,7 +495,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
* <p>Any properties with the attribute DONTENUM are not listed. <p>
*
* @return an array of java.lang.Objects with an entry for every
* listed property. Properties accessed via an integer index will
* listed property. Properties accessed via an integer index will
* have a corresponding
* Integer entry in the returned array. Properties accessed by
* a String will have a String entry in the returned array.
@ -503,14 +503,14 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
public Object[] getIds() {
return getIds(false);
}
/**
* Returns an array of ids for the properties of the object.
*
* <p>All properties, even those with attribute DONTENUM, are listed. <p>
*
* @return an array of java.lang.Objects with an entry for every
* listed property. Properties accessed via an integer index will
* listed property. Properties accessed via an integer index will
* have a corresponding
* Integer entry in the returned array. Properties accessed by
* a String will have a String entry in the returned array.
@ -518,7 +518,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
public Object[] getAllIds() {
return getIds(true);
}
/**
* Implements the [[DefaultValue]] internal method.
*
@ -557,19 +557,19 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
hint = "object";
else if (typeHint == ScriptRuntime.FunctionClass)
hint = "function";
else if (typeHint == ScriptRuntime.BooleanClass ||
else if (typeHint == ScriptRuntime.BooleanClass ||
typeHint == Boolean.TYPE)
hint = "boolean";
else if (typeHint == ScriptRuntime.NumberClass ||
typeHint == ScriptRuntime.ByteClass ||
typeHint == ScriptRuntime.ByteClass ||
typeHint == Byte.TYPE ||
typeHint == ScriptRuntime.ShortClass ||
typeHint == ScriptRuntime.ShortClass ||
typeHint == Short.TYPE ||
typeHint == ScriptRuntime.IntegerClass ||
typeHint == ScriptRuntime.IntegerClass ||
typeHint == Integer.TYPE ||
typeHint == ScriptRuntime.FloatClass ||
typeHint == ScriptRuntime.FloatClass ||
typeHint == Float.TYPE ||
typeHint == ScriptRuntime.DoubleClass ||
typeHint == ScriptRuntime.DoubleClass ||
typeHint == Double.TYPE)
hint = "number";
else {
@ -593,17 +593,17 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
return val;
}
if (val instanceof NativeJavaObject) {
// Let a wrapped java.lang.String pass for a primitive
// Let a wrapped java.lang.String pass for a primitive
// string.
Object u = ((Wrapper) val).unwrap();
if (u instanceof String)
return u;
}
}
// fall through to error
// fall through to error
}
catch (JavaScriptException jse) {
// fall through to error
// fall through to error
}
Object arg = (typeHint == null) ? "undefined" : typeHint.toString();
throw NativeGlobal.typeError1("msg.default.value", arg, this);
@ -633,7 +633,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
* <pre>
* static void init(Context cx, Scriptable scope, boolean sealed);</pre>
*
* or its compatibility form
* or its compatibility form
* <pre>
* static void init(Scriptable scope);</pre>
*
@ -651,35 +651,35 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
* These special prefixes are
* <ul>
* <li><code>jsFunction_</code> for a JavaScript function
* <li><code>jsStaticFunction_</code> for a JavaScript function that
* <li><code>jsStaticFunction_</code> for a JavaScript function that
* is a property of the constructor
* <li><code>jsGet_</code> for a getter of a JavaScript property
* <li><code>jsSet_</code> for a setter of a JavaScript property
* <li><code>jsConstructor</code> for a JavaScript function that
* <li><code>jsConstructor</code> for a JavaScript function that
* is the constructor
* </ul><p>
*
* If the method's name begins with "jsFunction_", a JavaScript function
* is created with a name formed from the rest of the Java method name
* If the method's name begins with "jsFunction_", a JavaScript function
* is created with a name formed from the rest of the Java method name
* following "jsFunction_". So a Java method named "jsFunction_foo" will
* define a JavaScript method "foo". Calling this JavaScript function
* define a JavaScript method "foo". Calling this JavaScript function
* will cause the Java method to be called. The parameters of the method
* must be of number and types as defined by the FunctionObject class.
* The JavaScript function is then added as a property
* of the prototype. <p>
*
*
* If the method's name begins with "jsStaticFunction_", it is handled
* similarly except that the resulting JavaScript function is added as a
* similarly except that the resulting JavaScript function is added as a
* property of the constructor object. The Java method must be static.
*
*
* If the method's name begins with "jsGet_" or "jsSet_", the method is
* considered to define a property. Accesses to the defined property
* will result in calls to these getter and setter methods. If no
* setter is defined, the property is defined as READONLY.<p>
*
* If the method's name is "jsConstructor", the method is
* considered to define the body of the constructor. Only one
* method of this name may be defined.
* considered to define the body of the constructor. Only one
* method of this name may be defined.
* If no method is found that can serve as constructor, a Java
* constructor will be selected to serve as the JavaScript
* constructor in the following manner. If the class has only one
@ -728,22 +728,22 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
{
defineClass(scope, clazz, false);
}
/**
* Defines JavaScript objects from a Java class, optionally
* Defines JavaScript objects from a Java class, optionally
* allowing sealing.
*
* Similar to <code>defineClass(Scriptable scope, Class clazz)</code>
* except that sealing is allowed. An object that is sealed cannot have
* except that sealing is allowed. An object that is sealed cannot have
* properties added or removed. Note that sealing is not allowed in
* the current ECMA/ISO language specification, but is likely for
* the next version.
*
*
* @param scope The scope in which to define the constructor
* @param clazz The Java class to use to define the JavaScript objects
* and properties. The class must implement Scriptable.
* @param sealed whether or not to create sealed standard objects that
* cannot be modified.
* cannot be modified.
* @exception IllegalAccessException if access is not available
* to a reflected class member
* @exception InstantiationException if unable to instantiate
@ -757,7 +757,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
* defineProperty method
* @since 1.4R3
*/
public static void defineClass(Scriptable scope, Class clazz,
public static void defineClass(Scriptable scope, Class clazz,
boolean sealed)
throws IllegalAccessException, InstantiationException,
InvocationTargetException, ClassDefinitionException,
@ -775,7 +775,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
parmTypes[2] == Boolean.TYPE &&
Modifier.isStatic(method.getModifiers()))
{
Object args[] = { Context.getContext(), scope,
Object args[] = { Context.getContext(), scope,
sealed ? Boolean.TRUE : Boolean.FALSE };
method.invoke(null, args);
return;
@ -788,7 +788,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
method.invoke(null, args);
return;
}
}
// If we got here, there isn't an "init" method with the right
@ -808,7 +808,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
Context.getMessage1("msg.zero.arg.ctor", clazz.getName()));
}
Scriptable proto = (Scriptable)
Scriptable proto = (Scriptable)
protoCtor.newInstance(ScriptRuntime.emptyArgs);
proto.setPrototype(getObjectPrototype(scope));
String className = proto.getClassName();
@ -831,7 +831,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
if (ctorMeths != null) {
if (ctorMeths.length > 1) {
throw new ClassDefinitionException(
Context.getMessage2("msg.multiple.ctors",
Context.getMessage2("msg.multiple.ctors",
ctorMeths[0], ctorMeths[1]));
}
ctorMember = ctorMeths[0];
@ -864,7 +864,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
if (name.equals(className)) {
if (ctorMember != null) {
throw new ClassDefinitionException(
Context.getMessage2("msg.multiple.ctors",
Context.getMessage2("msg.multiple.ctors",
ctorMember, methods[i]));
}
ctorMember = methods[i];
@ -1032,7 +1032,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
Object[] finishArgs = { scope, ctor, proto };
finishInit.invoke(null, finishArgs);
}
if (sealed) {
ctor.sealObject();
ctor.addPropertyAttribute(READONLY);
@ -1067,11 +1067,11 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
/**
* Utility method to add properties to arbitrary Scriptable object.
* If destination is instance of ScriptableObject, calls
* defineProperty there, otherwise calls put in destination
* If destination is instance of ScriptableObject, calls
* defineProperty there, otherwise calls put in destination
* ignoring attributes
*/
public static void defineProperty(Scriptable destination,
public static void defineProperty(Scriptable destination,
String propertyName, Object value,
int attributes)
{
@ -1083,7 +1083,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
destination.put(propertyName, destination, value);
}
}
/**
* Define a JavaScript property with getter and setter side effects.
*
@ -1138,7 +1138,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
* the given attributes.<p>
*
* Several forms of getters or setters are allowed. In all cases the
* type of the value parameter can be any one of the following types:
* type of the value parameter can be any one of the following types:
* Object, String, boolean, Scriptable, byte, short, int, long, float,
* or double. The runtime will perform appropriate conversions based
* upon the type of the parameter (see description in FunctionObject).
@ -1213,7 +1213,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
throw PropertyException.withMessage0("msg.setter.parms");
}
}
GetterSlot slot = new GetterSlot();
slot.delegateTo = delegateTo;
slot.getter = getter;
@ -1225,9 +1225,9 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
Slot inserted = addSlot(propertyName, propertyName.hashCode(), slot);
if (inserted != slot) {
throw new RuntimeException("Property already exists");
throw new RuntimeException("Property already exists");
}
}
/**
@ -1330,25 +1330,25 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
} while (next != null);
return obj;
}
/**
* Seal this object.
*
*
* A sealed object may not have properties added or removed. Once
* an object is sealed it may not be unsealed.
*
*
* @since 1.4R3
*/
public void sealObject() {
count = -1;
}
/**
* Return true if this object is sealed.
*
* It is an error to attempt to add or remove properties to
*
* It is an error to attempt to add or remove properties to
* a sealed object.
*
*
* @return true if sealed, false otherwise.
* @since 1.4R3
*/
@ -1361,10 +1361,10 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
* <p>
* Searches the prototype chain for a property named <code>name</code>.
* <p>
* @param obj a JavaScript object
* @param name a property name
* @return the value of a property with name <code>name</code> found in
* <code>obj</code> or any object in its prototype chain, or
* @param obj a JavaScript object
* @param name a property name
* @return the value of a property with name <code>name</code> found in
* <code>obj</code> or any object in its prototype chain, or
* <code>Scriptable.NOT_FOUND</code> if not found
* @since 1.5R2
*/
@ -1379,19 +1379,19 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
} while (obj != null);
return result;
}
/**
* Gets an indexed property from an object or any object in its prototype chain.
* <p>
* Searches the prototype chain for a property with integral index
* Searches the prototype chain for a property with integral index
* <code>index</code>. Note that if you wish to look for properties with numerical
* but non-integral indicies, you should use getProperty(Scriptable,String) with
* the string value of the index.
* <p>
* @param obj a JavaScript object
* @param index an integral index
* @return the value of a property with index <code>index</code> found in
* <code>obj</code> or any object in its prototype chain, or
* @param obj a JavaScript object
* @param index an integral index
* @return the value of a property with index <code>index</code> found in
* <code>obj</code> or any object in its prototype chain, or
* <code>Scriptable.NOT_FOUND</code> if not found
* @since 1.5R2
*/
@ -1406,15 +1406,15 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
} while (obj != null);
return result;
}
/**
* Returns whether a named property is defined in an object or any object
* Returns whether a named property is defined in an object or any object
* in its prototype chain.
* <p>
* Searches the prototype chain for a property named <code>name</code>.
* <p>
* @param obj a JavaScript object
* @param name a property name
* @param obj a JavaScript object
* @param name a property name
* @return the true if property was found
* @since 1.5R2
*/
@ -1427,15 +1427,15 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
} while (obj != null);
return false;
}
/**
* Returns whether an indexed property is defined in an object or any object
* Returns whether an indexed property is defined in an object or any object
* in its prototype chain.
* <p>
* Searches the prototype chain for a property with index <code>index</code>.
* <p>
* @param obj a JavaScript object
* @param index a property index
* @param obj a JavaScript object
* @param index a property index
* @return the true if property was found
* @since 1.5R2
*/
@ -1455,9 +1455,9 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
* Seaches for the named property in the prototype chain. If it is found,
* the value of the property is changed. If it is not found, a new
* property is added in <code>obj</code>.
* @param obj a JavaScript object
* @param obj a JavaScript object
* @param name a property name
* @param value any JavaScript value accepted by Scriptable.put
* @param value any JavaScript value accepted by Scriptable.put
* @since 1.5R2
*/
public static void putProperty(Scriptable obj, String name, Object value) {
@ -1473,9 +1473,9 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
* Seaches for the indexed property in the prototype chain. If it is found,
* the value of the property is changed. If it is not found, a new
* property is added in <code>obj</code>.
* @param obj a JavaScript object
* @param obj a JavaScript object
* @param index a property index
* @param value any JavaScript value accepted by Scriptable.put
* @param value any JavaScript value accepted by Scriptable.put
* @since 1.5R2
*/
public static void putProperty(Scriptable obj, int index, Object value) {
@ -1490,7 +1490,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
* <p>
* Searches for a property with <code>name</code> in obj or
* its prototype chain. If it is found, the object's delete
* method is called.
* method is called.
* @param obj a JavaScript object
* @param name a property name
* @return true if the property doesn't exist or was successfully removed
@ -1503,13 +1503,13 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
base.delete(name);
return base.get(name, obj) == NOT_FOUND;
}
/**
* Removes the property from an object or its prototype chain.
* <p>
* Searches for a property with <code>index</code> in obj or
* its prototype chain. If it is found, the object's delete
* method is called.
* method is called.
* @param obj a JavaScript object
* @param index a property index
* @return true if the property doesn't exist or was successfully removed
@ -1522,7 +1522,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
base.delete(index);
return base.get(index, obj) == NOT_FOUND;
}
/**
* Returns an array of all ids from an object and its prototypes.
* <p>
@ -1549,7 +1549,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
}
return result;
}
/**
* Call a method of an object.
* <p>
@ -1558,7 +1558,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
* @param args the arguments for the call
* @exception JavaScriptException thrown if there were errors in the call
*/
public static Object callMethod(Scriptable obj, String methodName,
public static Object callMethod(Scriptable obj, String methodName,
Object[] args)
throws JavaScriptException
{
@ -1572,7 +1572,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
Context.exit();
}
}
private static Scriptable getBase(Scriptable obj, String s) {
Scriptable m = obj;
while (m != null) {
@ -1592,7 +1592,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
}
return null;
}
/**
* Adds a property attribute to all properties.
*/
@ -1608,7 +1608,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
slot.attributes |= attribute;
}
}
private Slot getSlot(String id, int index, boolean shouldDelete) {
Slot[] slots = this.slots;
if (slots == null)
@ -1619,8 +1619,8 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
Slot slot = slots[i];
if (slot == null)
return null;
if (slot != REMOVED && slot.intKey == index &&
(slot.stringKey == id || (id != null &&
if (slot != REMOVED && slot.intKey == index &&
(slot.stringKey == id || (id != null &&
id.equals(slot.stringKey))))
{
if (shouldDelete) {
@ -1661,8 +1661,8 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
}
if (slot == REMOVED) {
sawRemoved = true;
} else if (slot.intKey == index &&
(slot.stringKey == id ||
} else if (slot.intKey == index &&
(slot.stringKey == id ||
(id != null && id.equals(slot.stringKey))))
{
return slot;
@ -1671,8 +1671,8 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
i = 0;
} while (i != start);
if (Context.check && !sawRemoved) Context.codeBug();
// Table could be full, but with some REMOVED elements.
// Call to addSlot will use a slot currently taken by
// Table could be full, but with some REMOVED elements.
// Call to addSlot will use a slot currently taken by
// a REMOVED.
return addSlot(id, index, null);
}
@ -1688,9 +1688,9 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
private synchronized Slot addSlot(String id, int index, Slot newSlot) {
if (count == -1)
throw Context.reportRuntimeError0("msg.add.sealed");
if (slots == null) { slots = new Slot[5]; }
return addSlotImpl(id, index, newSlot);
}
@ -1712,9 +1712,9 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
count++;
return slot;
}
if (slot.intKey == index &&
(slot.stringKey == id || (id != null &&
id.equals(slot.stringKey))))
if (slot.intKey == index &&
(slot.stringKey == id || (id != null &&
id.equals(slot.stringKey))))
{
return slot;
}
@ -1776,7 +1776,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
exclusionList = result;
return result;
}
Object[] getIds(boolean getAll) {
Slot[] s = slots;
Object[] a = ScriptRuntime.emptyArgs;
@ -1802,18 +1802,18 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
return result;
}
private void readObject(ObjectInputStream in)
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
in.defaultReadObject();
lastAccess = REMOVED;
}
/**
* The prototype of this object.
*/
protected Scriptable prototype;
/**
* The parent scope of this object.
*/
@ -1822,7 +1822,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
private static final Object HAS_STATIC_ACCESSORS = Void.TYPE;
private static final Slot REMOVED = new Slot();
private static Hashtable exclusionList = null;
private Slot[] slots;
private int count;
@ -1832,7 +1832,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
private static class Slot implements Serializable {
static final int HAS_GETTER = 0x01;
static final int HAS_SETTER = 0x02;
int intKey;
String stringKey;
Object value;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -42,21 +42,21 @@ package org.mozilla.javascript;
* <p>
* Three main pieces of functionality are required to implement
* security for JavaScript. First, it must be possible to define
* classes with an associated security context. (This security
* classes with an associated security context. (This security
* context may be any object that has meaning to an embedding;
* for a client-side JavaScript embedding this would typically
* be an origin URL and/or a digital certificate.) Next it
* be an origin URL and/or a digital certificate.) Next it
* must be possible to get the current class context so that
* the implementation can determine securely which class is
* requesting a privileged action. And finally, it must be
* requesting a privileged action. And finally, it must be
* possible to map a class back into a security context so that
* additional classes may be defined with that security context.
* <p>
* These three pieces of functionality are encapsulated in the
* SecuritySupport class.
* <p>
* Additionally, an embedding may provide filtering on the
* Java classes that are visible to scripts through the
* Additionally, an embedding may provide filtering on the
* Java classes that are visible to scripts through the
* <code>visibleToScripts</code> method.
*
* @see org.mozilla.javascript.Context
@ -69,7 +69,7 @@ public interface SecuritySupport {
/**
* Define and load a Java class.
* <p>
* In embeddings that care about security, the securityDomain
* In embeddings that care about security, the securityDomain
* must be associated with the defined class such that a call to
* <code>getSecurityDomain</code> with that class will return this security
* context.
@ -82,12 +82,12 @@ public interface SecuritySupport {
* null here. This value propagated from the values passed
* into methods of Context that evaluate scripts.
*/
public Class defineClass(String name, byte[] data,
public Class defineClass(String name, byte[] data,
Object securityDomain);
/**
* Get the current class Context.
* <p>
* <p>
* This functionality is supplied by SecurityManager.getClassContext,
* but only one SecurityManager may be instantiated in a single JVM
* at any one time. So implementations that care about security must
@ -99,48 +99,48 @@ public interface SecuritySupport {
* a new, shorter array to return.
*/
public Class[] getClassContext();
/**
* Return the security context associated with the given class.
* Return the security context associated with the given class.
* <p>
* If <code>cl</code> is a class defined through a call to
* SecuritySupport.defineClass, then return the security
* If <code>cl</code> is a class defined through a call to
* SecuritySupport.defineClass, then return the security
* context from that call. Otherwise return null.
* @param cl a class potentially defined by defineClass
* @return a security context object previously passed to defineClass
*/
public Object getSecurityDomain(Class cl);
/**
* Return true iff the Java class with the given name should be exposed
* to scripts.
* <p>
* An embedding may filter which Java classes are exposed through
* An embedding may filter which Java classes are exposed through
* LiveConnect to JavaScript scripts.
* <p>
* Due to the fact that there is no package reflection in Java,
* this method will also be called with package names. There
* is no way for Rhino to tell if "Packages.a.b" is a package name
* is no way for Rhino to tell if "Packages.a.b" is a package name
* or a class that doesn't exist. What Rhino does is attempt
* to load each segment of "Packages.a.b.c": It first attempts to
* to load each segment of "Packages.a.b.c": It first attempts to
* load class "a", then attempts to load class "a.b", then
* finally attempts to load class "a.b.c". On a Rhino installation
* finally attempts to load class "a.b.c". On a Rhino installation
* without any SecuritySupport set, and without any of the
* above classes, the expression "Packages.a.b.c" will result in
* above classes, the expression "Packages.a.b.c" will result in
* a [JavaPackage a.b.c] and not an error.
* <p>
* With SecuritySupport supplied, Rhino will first call
* With SecuritySupport supplied, Rhino will first call
* visibleToScripts before attempting to look up the class name. If
* visibleToScripts returns false, the class name lookup is not
* visibleToScripts returns false, the class name lookup is not
* performed and subsequent Rhino execution assumes the class is
* not present. So for "java.lang.System.out.println" the lookup
* not present. So for "java.lang.System.out.println" the lookup
* of "java.lang.System" is skipped and thus Rhino assumes that
* "java.lang.System" doesn't exist. So then for "java.lang.System.out",
* Rhino attempts to load the class "java.lang.System.out" because
* Rhino attempts to load the class "java.lang.System.out" because
* it assumes that "java.lang.System" is a package name.
* <p>
* @param fullClassName the full name of the class (including the package
* name, with '.' as a delimiter). For example the
* name, with '.' as a delimiter). For example the
* standard string class is "java.lang.String"
* @return whether or not to reveal this class to scripts
*/

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roger Lawrence
* Mike McCabe
*
@ -247,13 +247,13 @@ public class TokenStream {
NEWLOCAL = 144,
USELOCAL = 145,
SCRIPT = 146, // top-level node for entire script
/**
* For the interpreted mode indicating a line number change in icodes.
*/
LINE = 147,
SOURCEFILE = 148,
// For debugger
BREAKPOINT = 149,
@ -468,7 +468,7 @@ public class TokenStream {
private int stringToKeyword(String name) {
// #string_id_map#
// The following assumes that EOF == 0
final int
final int
Id_break = BREAK,
Id_case = CASE,
Id_continue = CONTINUE,
@ -530,7 +530,7 @@ public class TokenStream {
Id_transient = RESERVED,
Id_try = TRY,
Id_volatile = RESERVED;
int id;
String s = name;
// #generated# Last update: 2001-06-01 17:45:01 CEST
@ -644,8 +644,8 @@ public class TokenStream {
this.sourceName = sourceName;
flags = 0;
}
public Scriptable getScope() {
public Scriptable getScope() {
return scope;
}
@ -712,7 +712,7 @@ public class TokenStream {
&& 0 <= xDigitToInt(s.charAt(i + 3))
&& 0 <= xDigitToInt(s.charAt(i + 4))
&& 0 <= xDigitToInt(s.charAt(i + 5)))
return false;
}
@ -742,7 +742,7 @@ public class TokenStream {
public static boolean isJSSpace(int c) {
return (c == '\u0020' || c == '\u0009'
|| c == '\u000C' || c == '\u000B'
|| c == '\u00A0'
|| c == '\u00A0'
|| Character.getType((char)c) == Character.SPACE_SEPARATOR);
}
@ -750,7 +750,7 @@ public class TokenStream {
return (c == '\n' || c == '\r'
|| c == 0x2028 || c == 0x2029);
}
public int getToken() throws IOException {
int c;
tokenno++;
@ -782,7 +782,7 @@ public class TokenStream {
isUnicodeEscapeStart = true;
else
c = '\\';
// always unread the 'u' or whatever, we need
// always unread the 'u' or whatever, we need
// to start the string below at the <backslash>.
in.unread();
}
@ -790,13 +790,13 @@ public class TokenStream {
Character.isJavaIdentifierStart((char)c)) {
in.startString();
boolean containsEscape = isUnicodeEscapeStart;
boolean containsEscape = isUnicodeEscapeStart;
do {
c = in.read();
if (c == '\\') {
c = in.read();
containsEscape = (c == 'u');
}
}
} while (Character.isJavaIdentifierPart((char)c));
in.unread();
@ -805,11 +805,11 @@ public class TokenStream {
String str = in.getString();
// OPT we shouldn't have to make a string (object!) to
// check if it's a keyword.
// strictly speaking we should probably push-back
// all the bad characters if the <backslash>uXXXX
// sequence is malformed. But since there isn't a
// correct context(is there?) for a bad Unicode
// all the bad characters if the <backslash>uXXXX
// sequence is malformed. But since there isn't a
// correct context(is there?) for a bad Unicode
// escape sequence after an identifier, we can report
// an error here.
if (containsEscape) {
@ -1084,7 +1084,7 @@ public class TokenStream {
}
}
}
if (stringBuf != null)
stringBuf.append((char) c);
c = in.read();
@ -1245,7 +1245,7 @@ public class TokenStream {
return getToken();
}
if (in.match('*')) {
while ((c = in.read()) != -1 &&
while ((c = in.read()) != -1 &&
!(c == '*' && in.match('/'))) {
; // empty loop body
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
@ -47,8 +47,8 @@ public class VariableTable {
public int getParameterCount(){
return varStart;
}
public LocalVariable createLocalVariable(String name, boolean isParameter)
public LocalVariable createLocalVariable(String name, boolean isParameter)
{
return new LocalVariable(name, isParameter);
}
@ -77,7 +77,7 @@ public class VariableTable {
return ((LocalVariable)(itsVariables.elementAt(index))).getName();
}
public String[] getAllNames() {
public String[] getAllNames() {
int N = size();
String[] result = null;
if (N != 0) {
@ -126,7 +126,7 @@ public class VariableTable {
itsVariables.addElement(lVar);
itsVariableNames.put(vName, new Integer(index));
}
// This should only be called very early in compilation
public void removeLocal(String name) {
Integer i = (Integer) itsVariableNames.get(name);
@ -146,12 +146,12 @@ public class VariableTable {
itsVariableNames = ht;
}
}
// a list of the formal parameters and local variables
protected Vector itsVariables = new Vector();
protected Vector itsVariables = new Vector();
// mapping from name to index in list
protected Hashtable itsVariableNames = new Hashtable(11);
protected Hashtable itsVariableNames = new Hashtable(11);
protected int varStart; // index in list of first variable

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Marshall Cline
*
* Alternatively, the contents of this file may be used under the
@ -47,7 +47,7 @@ public interface WrapHandler {
/**
* Wrap the object.
* <p>
* The value returned must be one of
* The value returned must be one of
* <UL>
* <LI>java.lang.Boolean</LI>
* <LI>java.lang.String</LI>
@ -56,7 +56,7 @@ public interface WrapHandler {
* <LI>The value returned by Context.getUndefinedValue()</LI>
* <LI>null</LI>
* <p>
* If null is returned, the value obj will be wrapped as if
* If null is returned, the value obj will be wrapped as if
* no WrapHandler had been called.
* </UL>
* @param scope the scope of the executing script

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -39,8 +39,8 @@ package org.mozilla.javascript;
/**
* Objects that can wrap other values for reflection in the JS environment
* will implement Wrapper.
*
* will implement Wrapper.
*
* Wrapper defines a single method that can be called to unwrap the object.
*/
@ -48,7 +48,7 @@ public interface Wrapper {
/**
* Unwrap the object by returning the wrapped value.
*
*
* @return a wrapped value
*/
public Object unwrap();

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -42,10 +42,10 @@ import org.mozilla.javascript.*;
public interface DebugFrame {
public Scriptable getVariableObject();
public String getSourceName();
public int getLineNumber();
public DebuggableScript getScript();
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
@ -39,10 +39,10 @@ import java.io.*;
public class DebugReader extends Reader {
public DebugReader(Reader reader) {
this.reader = new BufferedReader(reader);
this.reader = new BufferedReader(reader);
this.saved = new StringBuffer();
}
public StringBuffer getSaved() {
return saved;
}
@ -56,14 +56,14 @@ public class DebugReader extends Reader {
public int read(char cbuf[]) throws IOException {
int i = reader.read(cbuf);
if (i != -1)
if (i != -1)
saved.append(cbuf, 0, i);
return i;
}
public int read(char cbuf[], int off, int len) throws IOException {
int i = reader.read(cbuf, off, len);
if (i > 0)
if (i > 0)
saved.append(cbuf, off, i);
return i;
}
@ -93,9 +93,9 @@ public class DebugReader extends Reader {
}
protected void finalize() throws Throwable {
reader = null;
reader = null;
}
private BufferedReader reader;
private StringBuffer saved;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -47,37 +47,37 @@ public interface DebuggableEngine {
* The engine will call the attached debugger's handleBreakpointHit
* method on the next line it executes if isLineStep is true.
* May be used from another thread to interrupt execution.
*
*
* @param isLineStep if true, break next line
*/
public void setBreakNextLine(boolean isLineStep);
/**
* Return the value of the breakNextLine flag.
* @return true if the engine will break on execution of the
* @return true if the engine will break on execution of the
* next line.
*/
public boolean getBreakNextLine();
/**
* Set the associated debugger.
* @param debugger the debugger to be used on callbacks from
* the engine.
*/
public void setDebugger(Debugger debugger);
/**
* Return the current debugger.
* @return the debugger, or null if none is attached.
*/
public Debugger getDebugger();
/**
* Return the number of frames in current execution.
* @return the count of current frames
*/
public int getFrameCount();
/**
* Return a frame from the current execution.
* Frames are numbered starting from 0 for the innermost
@ -85,7 +85,7 @@ public interface DebuggableEngine {
* @param frameNumber the number of the frame in the range
* [0,frameCount-1]
* @return the relevant Frame, or null if frameNumber is out
* of range or the engine isn't currently saving
* of range or the engine isn't currently saving
* frames
*/
public DebugFrame getFrame(int frameNumber);

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -42,18 +42,18 @@ import org.mozilla.javascript.*;
import java.util.Enumeration;
/**
* This interface exposes debugging information from executable
* This interface exposes debugging information from executable
* code (either functions or top-level scripts).
*/
public interface DebuggableScript {
/**
* Returns true if this is a function, false if it is a script.
*/
public boolean isFunction();
/**
* Get the Scriptable object (Function or Script) that is
* Get the Scriptable object (Function or Script) that is
* described by this DebuggableScript object.
*/
public Scriptable getScriptable();
@ -63,19 +63,19 @@ public interface DebuggableScript {
* of the script.
*/
public String getSourceName();
/**
* Get array containing the line numbers that
* Get array containing the line numbers that
* can have breakpoints placed on them.
*/
public int[] getLineNumbers();
/**
* Place a breakpoint at the given line.
* @return true if the breakpoint was successfully set.
*/
public boolean placeBreakpoint(int line);
/**
* Remove a breakpoint from the given line.
* @return true if there was a breakpoint at the given line.

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
@ -40,12 +40,12 @@ package org.mozilla.javascript.debug;
import org.mozilla.javascript.Context;
public interface Debugger {
void handleCompilationDone(Context cx, DebuggableScript fnOrScript,
void handleCompilationDone(Context cx, DebuggableScript fnOrScript,
StringBuffer source);
void handleBreakpointHit(Context cx);
void handleExceptionThrown(Context cx, Object exception);
}

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,11 +16,11 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* 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.
@ -241,13 +241,13 @@ public class Block {
break;
}
}
void markAnyTypeVariables(VariableTable theVariables)
{
for (int i = 0; i < theVariables.size(); i++)
if (itsLiveOnEntrySet.test(i))
((OptLocalVariable)theVariables.getVariable(i)).assignType(TypeEvent.AnyType);
}
void markVolatileVariables(VariableTable theVariables)
@ -458,7 +458,7 @@ public class Block {
}
}
break;
case TokenStream.SETPROP : {
Node baseChild = n.getFirstChild();
Node nameChild = baseChild.getNextSibling();
@ -491,11 +491,11 @@ public class Block {
}
return result;
}
// a total misnomer for now. To start with we're only trying to find
// duplicate getProp calls on 'this' that can be merged
void localCSE(Node parent, Node n, Hashtable theCSETable, OptFunctionNode theFunction)
{
{
switch (n.getType()) {
default : {
Node child = n.getFirstChild();
@ -529,11 +529,11 @@ public class Block {
if (rhs != null) localCSE(n, rhs, theCSETable, theFunction);
if (nameChild.getType() == TokenStream.STRING) {
theCSETable.remove(nameChild.getString());
// System.out.println("clear at SETPROP " + ((StringNode)nameChild).getString());
// System.out.println("clear at SETPROP " + ((StringNode)nameChild).getString());
}
else {
theCSETable.clear();
// System.out.println("clear all at SETPROP");
// System.out.println("clear all at SETPROP");
}
}
break;
@ -567,13 +567,13 @@ public class Block {
theCSETable.put(theName, theCSE);
}
else
theCSE = (Node)cse;
theCSE = (Node)cse;
Node nextChild = n.getNextSibling();
parent.removeChild(n);
Node cseUse = itsIRFactory.createUseLocal(theCSE);
if (nextChild == null)
parent.addChildToBack(cseUse);
else
else
parent.addChildBefore(cseUse, nextChild);
}
}
@ -589,8 +589,8 @@ public class Block {
if (lhsIndex != null) localCSE(n, lhsIndex, theCSETable, theFunction);
if (rhs != null) localCSE(n, rhs, theCSETable, theFunction);
theCSETable.clear();
//System.out.println("clear all at SETELEM");
}
//System.out.println("clear all at SETELEM");
}
break;
case TokenStream.CALL : {
Node child = n.getFirstChild();
@ -598,15 +598,15 @@ public class Block {
localCSE(n, child, theCSETable, theFunction);
child = child.getNextSibling();
}
theCSETable.clear();
//System.out.println("clear all at CALL");
theCSETable.clear();
//System.out.println("clear all at CALL");
}
break;
}
}
private IRFactory itsIRFactory;
Hashtable localCSE(Hashtable theCSETable, OptFunctionNode theFunction)
{
itsIRFactory = new IRFactory(null, null);
@ -637,7 +637,7 @@ public class Block {
if (n != null)
changed |= findDefPoints(n);
}
return changed;
}
@ -692,5 +692,5 @@ class CSEHolder {
Node getPropParent;
Node getPropChild;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,11 +16,11 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* 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.
@ -38,28 +38,28 @@
package org.mozilla.javascript.optimizer;
class DataFlowBitSet {
private int itsBits[];
int itsSize;
DataFlowBitSet(int size)
{
itsSize = size;
itsBits = new int[(size >> 5) + 1];
}
int size()
{
return itsSize;
}
void set(int n)
{
if ((n < 0) || (n >= itsSize))
throw new RuntimeException("DataFlowBitSet bad index " + n);
itsBits[n >> 5] |= 1 << (n & 31);
}
boolean test(int n)
{
if ((n < 0) || (n >= itsSize))

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,11 +16,11 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* 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.
@ -48,11 +48,11 @@ public class FatBlock {
{
itsShadowOfFormerSelf = new Block(startNodeIndex, endNodeIndex, statementNodes);
}
public Node getEndNode()
{ return itsShadowOfFormerSelf.getEndNode(); }
public Block getSlimmerSelf()
public Block getSlimmerSelf()
{ return itsShadowOfFormerSelf; }
private Block[] reduceToArray(Hashtable h)
@ -76,17 +76,17 @@ public class FatBlock {
itsShadowOfFormerSelf.setPredecessorList(reduceToArray(itsPredecessors));
return itsShadowOfFormerSelf;
}
public void addSuccessor(FatBlock b) { itsSuccessors.put(b, b); }
public void addPredecessor(FatBlock b) { itsPredecessors.put(b, b); }
// all the Blocks that come immediately after this
private Hashtable itsSuccessors = new Hashtable(4);
private Hashtable itsSuccessors = new Hashtable(4);
// all the Blocks that come immediately before this
private Hashtable itsPredecessors = new Hashtable(4);
private Block itsShadowOfFormerSelf;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* David C. Navas
*
@ -46,28 +46,28 @@ import org.mozilla.classfile.ClassFileWriter;
import org.mozilla.classfile.DefiningClassLoader;
/**
* Avoid cost of java.lang.reflect.Method.invoke() by compiling a class to
* Avoid cost of java.lang.reflect.Method.invoke() by compiling a class to
* perform the method call directly.
*/
public class InvokerImpl extends Invoker {
public Invoker createInvoker(Method method, Class[] types) {
Invoker result = (Invoker)invokersCache.get(method);
if (result != null) { return result; }
int classNum = 0;
synchronized (this) {
classNum = ++classNumber;
}
String className = "inv" + classNum;
ClassFileWriter cfw = new ClassFileWriter(className,
ClassFileWriter cfw = new ClassFileWriter(className,
"org.mozilla.javascript.Invoker", "");
cfw.setFlags((short)(ClassFileWriter.ACC_PUBLIC |
cfw.setFlags((short)(ClassFileWriter.ACC_PUBLIC |
ClassFileWriter.ACC_FINAL));
// Add our instantiator!
cfw.startMethod("<init>", "()V", ClassFileWriter.ACC_PUBLIC);
cfw.add(ByteCode.ALOAD_0);
@ -78,12 +78,12 @@ public class InvokerImpl extends Invoker {
cfw.stopMethod((short)1, null); // one argument -- this???
// Add the invoke() method call
cfw.startMethod("invoke",
cfw.startMethod("invoke",
"(Ljava/lang/Object;[Ljava/lang/Object;)"+
"Ljava/lang/Object;",
(short)(ClassFileWriter.ACC_PUBLIC |
(short)(ClassFileWriter.ACC_PUBLIC |
ClassFileWriter.ACC_FINAL));
// If we return a primitive type, then do something special!
String declaringClassName = method.getDeclaringClass().getName
().replace('.', '/');
@ -92,7 +92,7 @@ public class InvokerImpl extends Invoker {
String invokeSpecialType = null;
boolean returnsVoid = false;
boolean returnsBoolean = false;
if (returnType.isPrimitive()) {
if (returnType == Boolean.TYPE) {
returnsBoolean = true;
@ -125,30 +125,30 @@ public class InvokerImpl extends Invoker {
cfw.add(ByteCode.DUP);
invokeSpecialType = "(B)";
} else if (returnType == Character.TYPE) {
cfw.add(ByteCode.NEW, invokeSpecial
cfw.add(ByteCode.NEW, invokeSpecial
= "java/lang/Character");
cfw.add(ByteCode.DUP);
invokeSpecialType = "(C)";
}
}
// handle setup of call to virtual function (if calling non-static)
if (!java.lang.reflect.Modifier.isStatic(method.getModifiers())) {
cfw.add(ByteCode.ALOAD_1);
cfw.add(ByteCode.CHECKCAST, declaringClassName);
}
// Handle parameters!
StringBuffer params = new StringBuffer(2 + ((types!=null)?(20 *
types.length):0));
params.append('(');
if (types != null) {
for(int i = 0; i < types.length; i++) {
Class type = types[i];
cfw.add(ByteCode.ALOAD_2);
if (i <= 5) {
cfw.add((byte) (ByteCode.ICONST_0 + i));
} else if (i <= Byte.MAX_VALUE) {
@ -158,57 +158,57 @@ public class InvokerImpl extends Invoker {
} else {
cfw.addLoadConstant((int)i);
}
cfw.add(ByteCode.AALOAD);
if (type.isPrimitive()) {
// Convert enclosed type back to primitive.
if (type == Boolean.TYPE) {
cfw.add(ByteCode.CHECKCAST, "java/lang/Boolean");
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Boolean",
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Boolean",
"booleanValue", "()", "Z");
params.append('Z');
} else if (type == Integer.TYPE) {
cfw.add(ByteCode.CHECKCAST, "java/lang/Number");
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Number",
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Number",
"intValue", "()", "I");
params.append('I');
} else if (type == Short.TYPE) {
cfw.add(ByteCode.CHECKCAST, "java/lang/Number");
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Number",
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Number",
"shortValue", "()", "S");
params.append('S');
} else if (type == Character.TYPE) {
cfw.add(ByteCode.CHECKCAST, "java/lang/Character");
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Character",
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Character",
"charValue", "()", "C");
params.append('C');
} else if (type == Double.TYPE) {
cfw.add(ByteCode.CHECKCAST, "java/lang/Number");
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Number",
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Number",
"doubleValue", "()", "D");
params.append('D');
} else if (type == Float.TYPE) {
cfw.add(ByteCode.CHECKCAST, "java/lang/Number");
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Number",
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Number",
"floatValue", "()", "F");
params.append('F');
} else if (type == Byte.TYPE) {
cfw.add(ByteCode.CHECKCAST, "java/lang/Byte");
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Byte",
cfw.add(ByteCode.INVOKEVIRTUAL, "java/lang/Byte",
"byteValue", "()", "B");
params.append('B');
}
} else {
String typeName = type.getName().replace('.', '/');
cfw.add(ByteCode.CHECKCAST, typeName);
if (!type.isArray()) {
params.append('L');
}
params.append(typeName);
if (!type.isArray()) {
params.append(';');
}
@ -216,10 +216,10 @@ public class InvokerImpl extends Invoker {
}
}
params.append(')');
// Call actual function!
if (!java.lang.reflect.Modifier.isStatic(method.getModifiers())) {
cfw.add(ByteCode.INVOKEVIRTUAL, declaringClassName,
cfw.add(ByteCode.INVOKEVIRTUAL, declaringClassName,
method.getName(), params.toString(),
(invokeSpecialType!=null?invokeSpecialType.substring(1,2)
:returnType.isArray()?
@ -227,7 +227,7 @@ public class InvokerImpl extends Invoker {
:"L".concat
(returnType.getName().replace('.', '/').concat(";"))));
} else {
cfw.add(ByteCode.INVOKESTATIC, declaringClassName,
cfw.add(ByteCode.INVOKESTATIC, declaringClassName,
method.getName(), params.toString(),
(invokeSpecialType!=null?invokeSpecialType.substring(1,2)
:returnType.isArray()?
@ -235,7 +235,7 @@ public class InvokerImpl extends Invoker {
:"L".concat
(returnType.getName().replace('.', '/').concat(";"))));
}
// Handle return value
if (returnsVoid) {
cfw.add(ByteCode.ACONST_NULL);
@ -264,28 +264,28 @@ public class InvokerImpl extends Invoker {
cfw.add(ByteCode.ARETURN);
}
cfw.stopMethod((short)3, null); // three arguments, including the this pointer???
// Add class to our classloader.
java.io.ByteArrayOutputStream bos =
java.io.ByteArrayOutputStream bos =
new java.io.ByteArrayOutputStream(550);
try {
cfw.write(bos);
}
catch (IOException ioe) {
throw new RuntimeException("unexpected IOException" + ioe.toString());
}
try {
byte[] bytes = bos.toByteArray();
classLoader.defineClass(className, bytes);
Class c = classLoader.loadClass(className, true);
result = (Invoker)c.newInstance();
if (false) {
System.out.println("Generated method delegate for: " + method.getName()
+ " on " + method.getDeclaringClass().getName() + " :: " + params.toString()
System.out.println("Generated method delegate for: " + method.getName()
+ " on " + method.getDeclaringClass().getName() + " :: " + params.toString()
+ " :: " + types);
}
} catch (ClassNotFoundException e) {
@ -299,7 +299,7 @@ public class InvokerImpl extends Invoker {
invokersCache.put(method, result);
return result;
}
public Object invoke(Object that, Object [] args) {
return null;
}

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,13 +16,13 @@
* 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.
@ -52,8 +52,8 @@ public class OptClassNameHelper implements ClassNameHelper {
classNames = null;
}
public synchronized String getJavaScriptClassName(String functionName,
boolean primary)
public synchronized String getJavaScriptClassName(String functionName,
boolean primary)
{
StringBuffer s = new StringBuffer();
if (packageName != null && packageName.length() > 0) {
@ -77,7 +77,7 @@ public class OptClassNameHelper implements ClassNameHelper {
s.append(globalSerial++);
}
}
// We wish to produce unique class names between calls to reset()
// we disregard case since we may write the class names to file
// systems that are case insensitive
@ -106,15 +106,15 @@ public class OptClassNameHelper implements ClassNameHelper {
public Class getTargetExtends() {
return targetExtends;
}
public void setTargetExtends(Class extendsClass) {
targetExtends = extendsClass;
}
public Class[] getTargetImplements() {
return targetImplements;
}
public void setTargetImplements(Class[] implementsClasses) {
targetImplements = implementsClasses;
}
@ -123,7 +123,7 @@ public class OptClassNameHelper implements ClassNameHelper {
return initialName;
}
public void setClassName(String initialName) {
public void setClassName(String initialName) {
if (initialName != null) {
this.initialName = initialName;
appendFunctionName = true;
@ -153,12 +153,12 @@ public class OptClassNameHelper implements ClassNameHelper {
private Class[] targetImplements;
private ClassRepository classRepository;
private Hashtable classNames;
static class DefaultRepository implements ClassRepository {
public boolean storeClass(String name, byte[] bytes, boolean tl) {
return true;
}
}
private static ClassRepository defaultRepository = new DefaultRepository();
}

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,11 +16,11 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* 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.
@ -42,7 +42,7 @@ import java.util.*;
public class OptFunctionNode extends FunctionNode {
public OptFunctionNode(String name, Node left, Node right,
ClassNameHelper nameHelper)
ClassNameHelper nameHelper)
{
super(name, left, right);
itsVariableTable = new OptVariableTable();
@ -113,7 +113,7 @@ public class OptFunctionNode extends FunctionNode {
int localCount = getIntProp(Node.LOCALCOUNT_PROP, 0);
putIntProp(Node.LOCALCOUNT_PROP, localCount + 1);
}
private String itsClassName;
private boolean itsIsTargetOfDirectCall;
private boolean itsContainsCalls;

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,11 +16,11 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* 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.
@ -45,19 +45,19 @@ import org.mozilla.javascript.*;
* @author Norris Boyd
*/
public class OptIRFactory extends IRFactory {
public OptIRFactory(TokenStream ts, ClassNameHelper nameHelper, Scriptable scope) {
super(ts, scope);
this.nameHelper = nameHelper;
}
public Object createFunctionNode(String name, Object args,
Object statements)
public Object createFunctionNode(String name, Object args,
Object statements)
{
if (name == null)
name = "";
OptFunctionNode result = new OptFunctionNode(name, (Node) args,
(Node) statements,
OptFunctionNode result = new OptFunctionNode(name, (Node) args,
(Node) statements,
nameHelper);
return result;
}

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,11 +16,11 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* 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.
@ -39,38 +39,38 @@ package org.mozilla.javascript.optimizer;
import org.mozilla.javascript.*;
public class OptLocalVariable extends LocalVariable {
public OptLocalVariable(String name, boolean isParameter) {
super(name, isParameter);
// If the variable is a parameter, it could have any type.
// If it is from a "var" statement, its typeEvent will be set
// when we see the setVar node.
// when we see the setVar node.
int typeEvent = isParameter ? TypeEvent.AnyType : TypeEvent.NoType;
itsTypeUnion = new TypeEvent(typeEvent);
}
public String toString() {
return "LocalVariable : '" + getName()
+ "', index = " + getIndex()
+ ", LiveAcrossCall = " + itsLiveAcrossCall
+ ", isNumber = " + itsIsNumber
+ ", isParameter = " + isParameter()
+ ", isParameter = " + isParameter()
+ ", JRegister = " + itsJRegister;
}
public void setIsNumber() { itsIsNumber = true; }
public boolean isNumber() { return itsIsNumber; }
public void markLiveAcrossCall() { itsLiveAcrossCall = true; }
public void clearLiveAcrossCall() { itsLiveAcrossCall = false; }
public boolean isLiveAcrossCall() { return itsLiveAcrossCall; }
public void assignJRegister(short aJReg) { itsJRegister = aJReg; }
public short getJRegister() { return itsJRegister; }
public boolean assignType(int aType) { return itsTypeUnion.add(aType); }
public int getTypeUnion() { return itsTypeUnion.getEvent(); }
/**
* Get the offset into the bytecode where the variable becomes live.
* Used for generating the local variable table.
@ -78,7 +78,7 @@ public class OptLocalVariable extends LocalVariable {
public int getStartPC() {
return initPC;
}
/**
* Set the offset into the bytecode where the variable becomes live.
* Used for generating the local variable table.
@ -86,13 +86,13 @@ public class OptLocalVariable extends LocalVariable {
public void setStartPC(int pc) {
initPC = pc;
}
private short itsJRegister = -1; // unassigned
private boolean itsLiveAcrossCall;
private boolean itsIsNumber;
private TypeEvent itsTypeUnion; // the union of all assigned types
private int initPC;
}

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,12 +16,12 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Hannes Wallnoefer
*
*
* 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.
@ -40,13 +40,13 @@ package org.mozilla.javascript.optimizer;
import org.mozilla.javascript.*;
public final class OptRuntime extends ScriptRuntime {
/**
* No instances should be created.
*/
private OptRuntime() {
private OptRuntime() {
}
public static Object getElem(Object obj, double dblIndex, Scriptable scope)
{
int index = (int) dblIndex;
@ -242,7 +242,7 @@ public final class OptRuntime extends ScriptRuntime {
do {
prop = m.get(id, obj);
if (prop != Scriptable.NOT_FOUND) {
thisArg = obj;
thisArg = obj;
break search;
}
m = m.getPrototype();
@ -256,12 +256,12 @@ public final class OptRuntime extends ScriptRuntime {
ScriptRuntime.getMessage("msg.is.not.defined", errorArgs),
scope);
}
while (thisArg instanceof NativeWith)
thisArg = thisArg.getPrototype();
if (thisArg instanceof NativeCall)
thisArg = ScriptableObject.getTopLevelScope(thisArg);
Function function;
try {
function = (Function) prop;
@ -274,7 +274,7 @@ public final class OptRuntime extends ScriptRuntime {
return function.call(cx, scope, thisArg, args);
}
public static Object thisGet(Scriptable thisObj, String id,
Scriptable scope)
{
@ -297,12 +297,12 @@ public final class OptRuntime extends ScriptRuntime {
}
return Undefined.instance;
}
public static Object[] padStart(Object[] currentArgs, int count) {
Object[] result = new Object[currentArgs.length + count];
System.arraycopy(currentArgs, 0, result, count, currentArgs.length);
return result;
}
}

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,11 +16,11 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* 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.
@ -50,30 +50,30 @@ import java.util.Vector;
class OptTransformer extends NodeTransformer {
private Hashtable theFnClassNameList;
OptTransformer(Hashtable theFnClassNameList) {
OptTransformer(Hashtable theFnClassNameList) {
this.theFnClassNameList = theFnClassNameList;
}
public NodeTransformer newInstance() {
return new OptTransformer((Hashtable) theFnClassNameList.clone());
}
}
public IRFactory createIRFactory(TokenStream ts, Scriptable scope) {
return new IRFactory(ts, scope);
}
public Node transform(Node tree, Node enclosing, TokenStream ts,
Scriptable scope) {
// Collect all of the contained functions into a hashtable
// so that the call optimizer can access the class name & parameter
// count for any call it encounters
collectContainedFunctions(tree.getFirstChild());
return super.transform(tree, enclosing, ts, scope);
}
protected VariableTable createVariableTable() {
return new OptVariableTable();
}
@ -83,7 +83,7 @@ class OptTransformer extends NodeTransformer {
Context cx = Context.getCurrentContext();
int optLevel = cx.getOptimizationLevel();
Node left = node.getFirstChild();
// count the arguments
int argCount = 0;
Node arg = left.getNextSibling();
@ -102,7 +102,7 @@ class OptTransformer extends NodeTransformer {
}
}
}
return argCount;
}
@ -118,7 +118,7 @@ class OptTransformer extends NodeTransformer {
super.visitCall(node, tree);
}
/*
* Optimize a call site by converting call("a", b, c) into :
*
@ -141,9 +141,9 @@ class OptTransformer extends NodeTransformer {
// Refuse to directCall any function with more
// than 32 parameters - prevent code explosion
// for wacky test cases
if (varTable.getParameterCount() > 32)
if (varTable.getParameterCount() > 32)
return;
if (argCount == varTable.getParameterCount()) {
callNode.putProp(Node.DIRECTCALL_PROP, theFunction);
((OptFunctionNode)containingTree)
@ -186,5 +186,5 @@ class OptTransformer extends NodeTransformer {
}
}
}
}

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,11 +16,11 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* 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.
@ -65,10 +65,10 @@ public class OptVariableTable extends VariableTable {
jReg += 3; // 3 is 1 for Object parm and 2 for double parm
}
}
public LocalVariable createLocalVariable(String name, boolean isParameter)
public LocalVariable createLocalVariable(String name, boolean isParameter)
{
return new OptLocalVariable(name, isParameter);
}
}

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,11 +16,11 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* 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.
@ -81,7 +81,7 @@ public class Optimizer {
pw.println(Block.toString(theBlocks, theStatementNodes));
}
OptVariableTable vars = (OptVariableTable)
OptVariableTable vars = (OptVariableTable)
theFunction.getVariableTable();
if (vars != null) {
@ -99,10 +99,10 @@ public class Optimizer {
localCSE(theBlocks, theFunction);
if (!theFunction.requiresActivation()) {
/*
* Now that we know which local vars are in fact always
* Numbers, we re-write the tree to take advantage of
* that. Any arithmetic or assignment op involving just
* Number typed vars is marked so that the codegen will
* Now that we know which local vars are in fact always
* Numbers, we re-write the tree to take advantage of
* that. Any arithmetic or assignment op involving just
* Number typed vars is marked so that the codegen will
* generate non-object code.
*/
parameterUsedInNumberContext = false;
@ -302,7 +302,7 @@ public class Optimizer {
for (int i = 0; i < theBlocks.length; i++) {
theBlocks[i].markVolatileVariables(theVariables);
}
theBlocks[0].markAnyTypeVariables(theVariables);
}
@ -776,7 +776,7 @@ public class Optimizer {
/* at this point n has two children or more */
int lt = lChild.getType();
int rt = rChild.getType();
Node replace = null;
/* two or more children */
@ -800,12 +800,12 @@ public class Optimizer {
ScriptRuntime.numberToString(rChild.getDouble(), 10));
}
else if (lt == TokenStream.NUMBER && rt == TokenStream.STRING) {
// num + string
// num + string
replace = new Node(TokenStream.STRING,
ScriptRuntime.numberToString(lChild.getDouble(), 10) +
rChild.getString());
}
// can't do anything if we don't know both types - since
// can't do anything if we don't know both types - since
// 0 + object is supposed to call toString on the object and do
// string concantenation rather than addition
break;
@ -825,7 +825,7 @@ public class Optimizer {
else if (rt == TokenStream.NUMBER && rChild.getDouble() == 0) {
//second 0: x - 0 -> +x
// can not make simply x because x - 0 must be number
replace = new Node(TokenStream.UNARYOP,
replace = new Node(TokenStream.UNARYOP,
lChild, TokenStream.ADD);
}
break;
@ -957,13 +957,13 @@ public class Optimizer {
}
break;
}//switch
if (replace != null) {
parent.replaceChild(n, replace);
}
}
private static final int ALWAYS_TRUE_BOOLEAN = 1;
private static final int ALWAYS_FALSE_BOOLEAN = -1;
@ -973,7 +973,7 @@ public class Optimizer {
int type = node.getType();
if (type == TokenStream.PRIMARY) {
int id = node.getInt();
if (id == TokenStream.FALSE || id == TokenStream.NULL
if (id == TokenStream.FALSE || id == TokenStream.NULL
|| id == TokenStream.UNDEFINED)
{
result = ALWAYS_FALSE_BOOLEAN;
@ -1007,7 +1007,7 @@ public class Optimizer {
switch (n.getType()) {
case TokenStream.SETVAR : {
String name = n.getFirstChild().getString();
OptLocalVariable theVar = (OptLocalVariable)
OptLocalVariable theVar = (OptLocalVariable)
theVariables.getVariable(name);
if (theVar != null)
n.putProp(Node.VARIABLE_PROP, theVar);
@ -1015,7 +1015,7 @@ public class Optimizer {
break;
case TokenStream.GETVAR : {
String name = n.getString();
OptLocalVariable theVar = (OptLocalVariable)
OptLocalVariable theVar = (OptLocalVariable)
theVariables.getVariable(name);
if (theVar != null)
n.putProp(Node.VARIABLE_PROP, theVar);

Просмотреть файл

@ -1,14 +1,14 @@
/*
/*
* 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.
*
@ -16,11 +16,11 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* 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.
@ -43,7 +43,7 @@ import org.mozilla.javascript.*;
import java.util.Stack;
public class StmtNodeIterator {
public StmtNodeIterator(Node start)
{
itsStart = start;
@ -52,7 +52,7 @@ public class StmtNodeIterator {
private Node findFirstInterestingNode(Node theNode)
{
if (theNode == null) return null;
if ((theNode.getType() == TokenStream.BLOCK)
|| (theNode.getType() == TokenStream.LOOP)
|| (theNode.getType() == TokenStream.FUNCTION)) {
@ -72,8 +72,8 @@ public class StmtNodeIterator {
{
if (itsCurrentNode == null)
return itsCurrentNode = findFirstInterestingNode(itsStart);
itsCurrentNode = itsCurrentNode.getNext();
itsCurrentNode = itsCurrentNode.getNext();
if (itsCurrentNode == null) {
while ( ! itsStack.isEmpty()) {
Node n = (Node)(itsStack.pop());
@ -86,7 +86,7 @@ public class StmtNodeIterator {
else
return itsCurrentNode = findFirstInterestingNode(itsCurrentNode);
}
private Stack itsStack = new Stack();
private Node itsStart;
private Node itsCurrentNode;

Просмотреть файл

@ -1,62 +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
*
* 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;
public class TypeEvent {
public static final int EventBitLength = 2;
public static final int
AnyType = (1 << EventBitLength) - 1,
NumberType = 0x1,
NoType = 0x0;
public TypeEvent(int theEvent)
{
itsEvent = theEvent;
}
public boolean add(int anOther)
{
return ((itsEvent |= anOther) != anOther);
}
public int getEvent() { return itsEvent; }
private int itsEvent;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Norris Boyd
* Brendan Eich
* Matthias Radestock
@ -69,7 +69,7 @@ public class NativeRegExp extends IdScriptable implements Function {
private static final boolean debug = false;
public static void init(Context cx, Scriptable scope, boolean sealed) {
NativeRegExp proto = new NativeRegExp();
proto.prototypeFlag = true;
proto.activateIdMap(MAX_PROTOTYPE_ID);
@ -85,7 +85,7 @@ public class NativeRegExp extends IdScriptable implements Function {
ctor.setParentScope(scope);
ctor.setImmunePrototypeProperty(proto);
if (sealed) {
proto.sealObject();
ctor.sealObject();
@ -94,12 +94,12 @@ public class NativeRegExp extends IdScriptable implements Function {
defineProperty(scope, "RegExp", ctor, ScriptableObject.DONTENUM);
}
public NativeRegExp(Context cx, Scriptable scope, String source,
public NativeRegExp(Context cx, Scriptable scope, String source,
String global, boolean flat) {
init(cx, scope, source, global, flat);
}
public void init(Context cx, Scriptable scope, String source,
public void init(Context cx, Scriptable scope, String source,
String global, boolean flat) {
this.source = source;
flags = 0;
@ -133,13 +133,13 @@ public class NativeRegExp extends IdScriptable implements Function {
len = REOP_FLATLEN_MAX;
}
RENode ren2 = new RENode(state, len == 1 ? REOP_FLAT1 : REOP_FLAT,
new Integer(index));
new Integer(index));
ren2.flags = RENode.NONEMPTY;
if (len > 1) {
ren2.kid2 = index + len;
} else {
ren2.flags |= RENode.SINGLE;
ren2.chr = state.source[index];
ren2.chr = state.source[index];
}
index += len;
sourceLen -= len;
@ -188,7 +188,7 @@ public class NativeRegExp extends IdScriptable implements Function {
scope);
}
NativeRegExp thatObj = (NativeRegExp) args[0];
source = thatObj.source;
source = thatObj.source;
lastIndex = thatObj.lastIndex;
parenCount = thatObj.parenCount;
flags = thatObj.flags;
@ -220,7 +220,7 @@ public class NativeRegExp extends IdScriptable implements Function {
public NativeRegExp() {
}
private static RegExpImpl getImpl(Context cx) {
return (RegExpImpl) ScriptRuntime.getRegExpProxy(cx);
}
@ -245,10 +245,10 @@ public class NativeRegExp extends IdScriptable implements Function {
}
int i = ((flags & GLOB) != 0) ? lastIndex : 0;
int indexp[] = { i };
Object rval = executeRegExp(cx, scopeObj,
Object rval = executeRegExp(cx, scopeObj,
reImpl, str, indexp, matchType);
if ((flags & GLOB) != 0) {
lastIndex = (rval == null || rval == Undefined.instance)
lastIndex = (rval == null || rval == Undefined.instance)
? 0 : indexp[0];
}
return rval;
@ -497,14 +497,14 @@ public class NativeRegExp extends IdScriptable implements Function {
int index = ((Integer) ren.kid).intValue();
int len = ren.kid2 - index;
for (int i = 0; i < len; i++)
System.out.print("\\u" +
System.out.print("\\u" +
Integer.toHexString(source[index+i]));
System.out.println();
break;
}
case REOP_UCFLAT1:
System.out.print("\\u" +
System.out.print("\\u" +
Integer.toHexString(ren.chr));
System.out.println();
break;
@ -514,7 +514,7 @@ public class NativeRegExp extends IdScriptable implements Function {
int len = ren.kid2 - index;
System.out.print(" [");
for (int i = 0; i < len; i++)
System.out.print("\\u" +
System.out.print("\\u" +
Integer.toHexString(source[index+i]));
System.out.println("]");
break;
@ -1075,7 +1075,7 @@ public class NativeRegExp extends IdScriptable implements Function {
*/
if ((state.cx.getLanguageVersion() != Context.VERSION_DEFAULT)
&& (state.cx.getLanguageVersion() <= Context.VERSION_1_4)) {
switch (c) {
switch (c) {
case '0':
state.index = index;
num = doOctal(state);
@ -1106,7 +1106,7 @@ public class NativeRegExp extends IdScriptable implements Function {
ocp = --index; /* skip beyond the '\' */
doFlat = true;
skipCommon = true;
break;
break;
}
/* more than 1 digit, or a number greater than
the count of parentheses => it's an octal */
@ -1122,7 +1122,7 @@ public class NativeRegExp extends IdScriptable implements Function {
ren = new RENode(state, REOP_BACKREF, null);
ren.num = num - 1; /* \1 is numbered 0, etc. */
/* Avoid common chr- and flags-setting
/* Avoid common chr- and flags-setting
code after switch. */
ren.flags = RENode.NONEMPTY;
skipCommon = true;
@ -1145,14 +1145,14 @@ public class NativeRegExp extends IdScriptable implements Function {
index--;
ren = new RENode(state, REOP_BACKREF, null);
ren.num = num - 1; /* \1 is numbered 0, etc. */
/* Avoid common chr- and flags-setting
/* Avoid common chr- and flags-setting
code after switch. */
ren.flags = RENode.NONEMPTY;
skipCommon = true;
}
}
break;
case 'x':
ocp = index;
if (++index < source.length && isHex(c = source[index])) {
@ -1163,8 +1163,8 @@ public class NativeRegExp extends IdScriptable implements Function {
} else {
if ((state.cx.getLanguageVersion()
!= Context.VERSION_DEFAULT)
&& (state.cx.getLanguageVersion()
<= Context.VERSION_1_4))
&& (state.cx.getLanguageVersion()
<= Context.VERSION_1_4))
index--; /* back up so index points to last hex char */
else { /* ecma 2 requires pairs of hex digits. */
index = ocp;
@ -1345,15 +1345,15 @@ public class NativeRegExp extends IdScriptable implements Function {
else
return false;
}
int greedyRecurse(GreedyState grState, int index, int previousKid) {
int kidMatch;
int match;
int num;
/*
* when the kid match fails, we reset the parencount and run any
* when the kid match fails, we reset the parencount and run any
* previously succesful kid in order to restablish it's paren
* contents.
*/
@ -1364,7 +1364,7 @@ public class NativeRegExp extends IdScriptable implements Function {
kidMatch = matchRENodes(grState.state, grState.kid, grState.next, index);
grState.state.complete = -1;
grState.state.goForBroke = oldBroke;
if (kidMatch == -1) {
grState.state.parenCount = num;
if (previousKid != -1)
@ -1393,7 +1393,7 @@ public class NativeRegExp extends IdScriptable implements Function {
}
grState.state.parenCount = num;
matchRENodes(grState.state, grState.kid, grState.next, index);
match = matchRENodes(grState.state, grState.next, grState.stop, kidMatch);
if (match != -1) {
if (grState.stop == null) {
@ -1441,7 +1441,7 @@ public class NativeRegExp extends IdScriptable implements Function {
state.complete = match;
return index;
}
if (match != -1)
if (match != -1)
return index;
kidMatch = matchRENodes(state, (RENode)ren.kid, ren.next, index);
@ -1451,11 +1451,11 @@ public class NativeRegExp extends IdScriptable implements Function {
if (kidMatch == index) return kidMatch; /* no point pursuing an empty match forever */
return matchNonGreedyKid(state, ren, kidCount, maxKid, kidMatch);
}
boolean isLineTerminator(char c) {
return TokenStream.isJSLineTerminator(c);
}
int matchRENodes(MatchState state, RENode ren, RENode stop, int index) {
int num;
char[] input = state.input;
@ -1494,7 +1494,7 @@ public class NativeRegExp extends IdScriptable implements Function {
index = kidMatch;
}
if (num == ren.max)
// Have matched the exact count required,
// Have matched the exact count required,
// need to match the rest of the regexp.
break;
if ((ren.flags & RENode.MINIMAL) == 0) {
@ -1502,7 +1502,7 @@ public class NativeRegExp extends IdScriptable implements Function {
index, lastKid);
if (kidMatch == -1) {
if (lastKid != -1) {
index = matchRENodes(state, (RENode)ren.kid,
index = matchRENodes(state, (RENode)ren.kid,
ren.next, lastKid);
if (state.goForBroke && (state.complete != -1))
return state.complete;
@ -1513,7 +1513,7 @@ public class NativeRegExp extends IdScriptable implements Function {
return state.complete;
index = kidMatch;
}
}
}
else {
index = matchNonGreedyKid(state, ren, num,
ren.max, index);
@ -1521,16 +1521,16 @@ public class NativeRegExp extends IdScriptable implements Function {
return -1;
if (state.goForBroke && (state.complete != -1))
return state.complete;
}
}
}
break;
case REOP_PLUS: {
int kidMatch = matchRENodes(state, (RENode)ren.kid,
int kidMatch = matchRENodes(state, (RENode)ren.kid,
ren.next, index);
if (kidMatch == -1)
return -1;
if ((ren.flags & RENode.MINIMAL) == 0) {
kidMatch = matchGreedyKid(state, ren, stop, 1,
kidMatch = matchGreedyKid(state, ren, stop, 1,
kidMatch, index);
if (kidMatch == -1) {
index = matchRENodes(state,(RENode)ren.kid,
@ -1552,7 +1552,7 @@ public class NativeRegExp extends IdScriptable implements Function {
if (index == -1) return -1;
}
break;
case REOP_STAR:
case REOP_STAR:
if ((ren.flags & RENode.MINIMAL) == 0) {
int kidMatch = matchGreedyKid(state, ren, stop, 0, index, -1);
if (kidMatch != -1) {
@ -1673,8 +1673,8 @@ public class NativeRegExp extends IdScriptable implements Function {
return state.noMoreInput();
}
if (ren.bitmap == null) {
char[] source = (ren.s != null)
? ren.s
char[] source = (ren.s != null)
? ren.s
: this.source.toCharArray();
ren.buildBitmap(state, source, ((state.flags & FOLD) != 0));
}
@ -1873,7 +1873,7 @@ public class NativeRegExp extends IdScriptable implements Function {
int matchRegExp(MatchState state, RENode ren, int index) {
// have to include the position beyond the last character
// in order to detect end-of-input/line condition
for (int i = index; i <= state.input.length; i++) {
for (int i = index; i <= state.input.length; i++) {
state.skipped = i - index;
state.parenCount = 0;
int result = matchRENodes(state, ren, null, i);
@ -1887,7 +1887,7 @@ public class NativeRegExp extends IdScriptable implements Function {
* indexp is assumed to be an array of length 1
*/
Object executeRegExp(Context cx, Scriptable scopeObj, RegExpImpl res,
String str, int indexp[], int matchType)
String str, int indexp[], int matchType)
{
NativeRegExp re = this;
/*
@ -1930,7 +1930,7 @@ public class NativeRegExp extends IdScriptable implements Function {
int i = index - state.cpbegin;
indexp[0] = i;
int matchlen = i - (start + state.skipped);
int ep = index;
int ep = index;
index -= matchlen;
Object result;
Scriptable obj;
@ -2045,15 +2045,15 @@ public class NativeRegExp extends IdScriptable implements Function {
switch (id) {
case Id_lastIndex:
return ScriptableObject.PERMANENT;
case Id_source:
case Id_global:
case Id_ignoreCase:
case Id_multiline:
case Id_source:
case Id_global:
case Id_ignoreCase:
case Id_multiline:
return ScriptableObject.PERMANENT | ScriptableObject.READONLY;
}
return super.getIdDefaultAttributes(id);
}
protected Object getIdValue(int id) {
switch (id) {
case Id_lastIndex: return wrap_long(0xffffffffL & lastIndex);
@ -2064,7 +2064,7 @@ public class NativeRegExp extends IdScriptable implements Function {
}
return super.getIdValue(id);
}
protected void setIdValue(int id, Object value) {
if (id == Id_lastIndex) {
setLastIndex(ScriptRuntime.toInt32(value));
@ -2076,7 +2076,7 @@ public class NativeRegExp extends IdScriptable implements Function {
void setLastIndex(int value) {
lastIndex = value;
}
public int methodArity(int methodId) {
if (prototypeFlag) {
switch (methodId) {
@ -2091,7 +2091,7 @@ public class NativeRegExp extends IdScriptable implements Function {
}
public Object execMethod(int methodId, IdFunction f, Context cx,
Scriptable scope, Scriptable thisObj,
Scriptable scope, Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
@ -2099,16 +2099,16 @@ public class NativeRegExp extends IdScriptable implements Function {
switch (methodId) {
case Id_compile:
return realThis(thisObj, f, false).compile(cx, scope, args);
case Id_toString:
return realThis(thisObj, f, true).toString();
case Id_exec:
return realThis(thisObj, f, false).exec(cx, scope, args);
case Id_test:
return realThis(thisObj, f, false).test(cx, scope, args);
case Id_prefix:
return realThis(thisObj, f, false).prefix(cx, scope, args);
}
@ -2116,7 +2116,7 @@ public class NativeRegExp extends IdScriptable implements Function {
return super.execMethod(methodId, f, cx, scope, thisObj, args);
}
private NativeRegExp realThis(Scriptable thisObj, IdFunction f,
private NativeRegExp realThis(Scriptable thisObj, IdFunction f,
boolean readOnly)
{
while (!(thisObj instanceof NativeRegExp)) {
@ -2133,7 +2133,7 @@ public class NativeRegExp extends IdScriptable implements Function {
case Id_ignoreCase: return "ignoreCase";
case Id_multiline: return "multiline";
}
if (prototypeFlag) {
switch (id) {
case Id_compile: return "compile";
@ -2156,7 +2156,7 @@ public class NativeRegExp extends IdScriptable implements Function {
Id_global = 3,
Id_ignoreCase = 4,
Id_multiline = 5,
MAX_INSTANCE_ID = 5;
protected int mapNameToId(String s) {
@ -2206,7 +2206,7 @@ public class NativeRegExp extends IdScriptable implements Function {
Id_exec = MAX_INSTANCE_ID + 3,
Id_test = MAX_INSTANCE_ID + 4,
Id_prefix = MAX_INSTANCE_ID + 5,
MAX_PROTOTYPE_ID = MAX_INSTANCE_ID + 5;
// #/string_id_map#
@ -2257,16 +2257,16 @@ class RENode implements Serializable {
this.op = op;
this.kid = kid;
}
private void calcBMSize(char[] s, int index, int cp2, boolean fold) {
int maxc = 0;
while (index < cp2) {
char c = s[index++];
if (c == '\\') {
if (index + 5 <= cp2 && s[index] == 'u'
&& NativeRegExp.isHex(s[index+1])
&& NativeRegExp.isHex(s[index+1])
&& NativeRegExp.isHex(s[index+2])
&& NativeRegExp.isHex(s[index+3])
&& NativeRegExp.isHex(s[index+3])
&& NativeRegExp.isHex(s[index+4]))
{
int x = (((((NativeRegExp.unHex(s[index+0]) << 4) +
@ -2276,11 +2276,11 @@ class RENode implements Serializable {
c = (char) x;
index += 5;
} else {
/*
/*
* For the not whitespace, not word or not digit cases
* we widen the range to the complete unicode range.
*/
if ((s[index] == 'S')
if ((s[index] == 'S')
|| (s[index] == 'W') || (s[index] == 'D')) {
maxc = 65535;
break; /* leave now, it can't get worse */
@ -2311,10 +2311,10 @@ class RENode implements Serializable {
if (c > maxc)
maxc = c;
}
bmsize = (short)((maxc + NativeRegExp.JS_BITS_PER_BYTE)
bmsize = (short)((maxc + NativeRegExp.JS_BITS_PER_BYTE)
/ NativeRegExp.JS_BITS_PER_BYTE);
}
private void matchBit(int c, int fill) {
int i = (c) >> 3;
byte b = (byte) (c & 7);
@ -2335,7 +2335,7 @@ class RENode implements Serializable {
int end = kid2;
byte fill = 0;
int i,n,ocp;
boolean not = false;
kid2 = 0;
if (s[index] == '^') {
@ -2343,7 +2343,7 @@ class RENode implements Serializable {
kid2 = -1;
index++;
}
calcBMSize(s, index, end, fold);
bitmap = new byte[bmsize];
if (not) {
@ -2355,7 +2355,7 @@ class RENode implements Serializable {
int nchars = bmsize * NativeRegExp.JS_BITS_PER_BYTE;
int lastc = nchars;
boolean inrange = false;
while (index < end) {
int c = s[index++];
if (c == '\\') {
@ -2474,7 +2474,7 @@ class RENode implements Serializable {
case 'u':
if (s.length > index+3
&& NativeRegExp.isHex(s[index+0])
&& NativeRegExp.isHex(s[index+1])
&& NativeRegExp.isHex(s[index+1])
&& NativeRegExp.isHex(s[index+2])
&& NativeRegExp.isHex(s[index+3])) {
n = (((((NativeRegExp.unHex(s[index+0]) << 4) +

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
@ -55,7 +55,7 @@ public class NativeRegExpCtor extends NativeFunction {
public NativeRegExpCtor() {
functionName = "RegExp";
}
public String getClassName() {
return "Function";
}
@ -86,7 +86,7 @@ public class NativeRegExpCtor extends NativeFunction {
protected int getIdDefaultAttributes(int id) {
int shifted = id - idBase;
if (1 <= shifted && shifted <= MAX_INSTANCE_ID) {
if (1 <= shifted && shifted <= MAX_INSTANCE_ID) {
switch (shifted) {
case Id_multiline:
case Id_STAR:
@ -98,14 +98,14 @@ public class NativeRegExpCtor extends NativeFunction {
}
return super.getIdDefaultAttributes(id);
}
private static String stringResult(Object obj) {
return (obj == null) ? "" : obj.toString();
}
protected Object getIdValue(int id) {
int shifted = id - idBase;
if (1 <= shifted && shifted <= MAX_INSTANCE_ID) {
if (1 <= shifted && shifted <= MAX_INSTANCE_ID) {
RegExpImpl impl = getImpl();
switch (shifted) {
case Id_multiline:
@ -113,7 +113,7 @@ public class NativeRegExpCtor extends NativeFunction {
return wrap_boolean(impl.multiline);
case Id_input:
case Id_UNDERSCORE:
case Id_UNDERSCORE:
return stringResult(impl.input);
case Id_lastMatch:
@ -138,7 +138,7 @@ public class NativeRegExpCtor extends NativeFunction {
}
return super.getIdValue(id);
}
protected void setIdValue(int id, Object value) {
switch (id - idBase) {
case Id_multiline:
@ -147,8 +147,8 @@ public class NativeRegExpCtor extends NativeFunction {
return;
case Id_input:
case Id_UNDERSCORE:
getImpl().input = ScriptRuntime.toString(value);
case Id_UNDERSCORE:
getImpl().input = ScriptRuntime.toString(value);
return;
}
super.setIdValue(id, value);
@ -156,7 +156,7 @@ public class NativeRegExpCtor extends NativeFunction {
protected String getIdName(int id) {
int shifted = id - idBase;
if (1 <= shifted && shifted <= MAX_INSTANCE_ID) {
if (1 <= shifted && shifted <= MAX_INSTANCE_ID) {
switch (shifted) {
case Id_multiline: return "multiline";
case Id_STAR: return "$*";
@ -185,11 +185,11 @@ public class NativeRegExpCtor extends NativeFunction {
}
protected int maxInstanceId() {
// Note: check for idBase == 0 can not be done in constructor,
// Note: check for idBase == 0 can not be done in constructor,
// because IdScriptable calls maxInstanceId in its constructor
// before NativeRegExpCtor constructor gets chance to run any code
if (idBase == 0) { idBase = super.maxInstanceId(); }
return idBase + MAX_INSTANCE_ID;
return idBase + MAX_INSTANCE_ID;
}
// #string_id_map#
@ -212,9 +212,9 @@ public class NativeRegExpCtor extends NativeFunction {
Id_rightContext = 11,
Id_QUOTE = 12, // #string=$'#
DOLLAR_ID_BASE = 12;
private static final int
Id_DOLLAR_1 = DOLLAR_ID_BASE + 1, // #string=$1#
Id_DOLLAR_2 = DOLLAR_ID_BASE + 2, // #string=$2#
@ -264,8 +264,8 @@ public class NativeRegExpCtor extends NativeFunction {
// #/generated#
// #/string_id_map#
return (id != 0) ? idBase + id : super.mapNameToId(s);
return (id != 0) ? idBase + id : super.mapNameToId(s);
}
private static int idBase;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
@ -38,25 +38,25 @@ import org.mozilla.javascript.*;
import java.util.Vector;
/**
*
*
*/
public class RegExpImpl implements RegExpProxy {
public RegExpImpl() {
parens = new Vector(9);
}
public boolean isRegExp(Object obj) {
return obj instanceof NativeRegExp;
}
public Object newRegExp(Context cx, Scriptable scope, String source,
public Object newRegExp(Context cx, Scriptable scope, String source,
String global, boolean flat)
{
return new NativeRegExp(cx, scope, source, global, flat);
}
public Object match(Context cx, Scriptable scope,
public Object match(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
throws JavaScriptException
{
@ -80,7 +80,7 @@ public class RegExpImpl implements RegExpProxy {
return matchOrReplace(cx, scope, thisObj, args, this, mdata, false);
}
public Object replace(Context cx, Scriptable scope,
public Object replace(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
throws JavaScriptException
{
@ -138,7 +138,7 @@ public class RegExpImpl implements RegExpProxy {
* Analog of C match_or_replace.
*/
private static Object matchOrReplace(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args,
Scriptable thisObj, Object[] args,
RegExpImpl reImpl,
GlobData data, boolean forceFlat)
throws JavaScriptException
@ -148,7 +148,7 @@ public class RegExpImpl implements RegExpProxy {
String str = ScriptRuntime.toString(thisObj);
data.str = str;
Scriptable topScope = ScriptableObject.getTopLevelScope(scope);
if (args.length == 0)
re = new NativeRegExp(cx, topScope, "", "", false);
else
@ -162,7 +162,7 @@ public class RegExpImpl implements RegExpProxy {
opt = ScriptRuntime.toString(args[data.optarg]);
} else {
opt = null;
}
}
re = new NativeRegExp(cx, topScope, src, opt, forceFlat);
}
data.regexp = re;
@ -193,25 +193,25 @@ public class RegExpImpl implements RegExpProxy {
}
} else {
result = re.executeRegExp(cx, scope, reImpl, str, indexp,
((data.mode == GlobData.GLOB_REPLACE)
? NativeRegExp.TEST
((data.mode == GlobData.GLOB_REPLACE)
? NativeRegExp.TEST
: NativeRegExp.MATCH));
}
return result;
}
public int find_split(Scriptable scope, String target, String separator,
Object reObj, int[] ip, int[] matchlen,
}
public int find_split(Scriptable scope, String target, String separator,
Object reObj, int[] ip, int[] matchlen,
boolean[] matched, String[][] parensp)
{
int i = ip[0];
int length = target.length();
int result;
Context cx = Context.getCurrentContext();
int version = cx.getLanguageVersion();
NativeRegExp re = (NativeRegExp) reObj;
again:
@ -273,7 +273,7 @@ public class RegExpImpl implements RegExpProxy {
}
return result;
}
/**
* Analog of REGEXP_PAREN_SUBSTRING in C jsregexp.h.
* Assumes zero-based; i.e., for $3, i==2
@ -300,8 +300,8 @@ abstract class GlobData {
static final int GLOB_REPLACE = 2;
static final int GLOB_SEARCH = 3;
abstract void doGlobal(Context cx, Scriptable scope, int count,
RegExpImpl reImpl)
abstract void doGlobal(Context cx, Scriptable scope, int count,
RegExpImpl reImpl)
throws JavaScriptException;
byte mode; /* input: return index, match object, or void */
@ -318,8 +318,8 @@ class MatchData extends GlobData {
/*
* Analog of match_glob() in jsstr.c
*/
void doGlobal(Context cx, Scriptable scope, int count, RegExpImpl reImpl)
throws JavaScriptException
void doGlobal(Context cx, Scriptable scope, int count, RegExpImpl reImpl)
throws JavaScriptException
{
MatchData mdata;
Object v;
@ -347,7 +347,7 @@ class ReplaceData extends GlobData {
/*
* Analog of replace_glob() in jsstr.c
*/
void doGlobal(Context cx, Scriptable scope, int count, RegExpImpl reImpl)
void doGlobal(Context cx, Scriptable scope, int count, RegExpImpl reImpl)
throws JavaScriptException
{
ReplaceData rdata = this;
@ -356,7 +356,7 @@ class ReplaceData extends GlobData {
char[] leftArray = lc.charArray;
int leftIndex = rdata.leftIndex;
int leftlen = reImpl.lastMatch.index - leftIndex;
rdata.leftIndex = reImpl.lastMatch.index + reImpl.lastMatch.length;
int replen = findReplen(cx, reImpl);
@ -380,7 +380,7 @@ class ReplaceData extends GlobData {
static SubString dollarStr = new SubString("$");
static SubString interpretDollar(Context cx, RegExpImpl res,
static SubString interpretDollar(Context cx, RegExpImpl res,
char[] da, int dp, int bp, int[] skip)
{
char[] ca;

Просмотреть файл

@ -18,7 +18,7 @@
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
@ -39,7 +39,7 @@ class SubString {
public SubString()
{
}
public SubString(String str)
{
index = 0;

Просмотреть файл

@ -487,7 +487,7 @@ msg.nonjava.method =\
msg.java.member.not.found =\
Java class "{0}" has no public instance field or method named "{1}".
msg.pkg.int =\
Java package names may not be numbers.

Просмотреть файл

@ -19,7 +19,7 @@
# Copyright (C) 1997-1999 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Contributor(s):
# Norris Boyd
#
# Alternatively, the contents of this file may be used under the

Просмотреть файл

@ -39,9 +39,9 @@ import java.io.*;
import org.mozilla.javascript.*;
/**
* Class ScriptableInputStream is used to read in a JavaScript
* Class ScriptableInputStream is used to read in a JavaScript
* object or function previously serialized with a ScriptableOutputStream.
* References to names in the exclusion list
* References to names in the exclusion list
* replaced with references to the top-level scope specified during
* creation of the ScriptableInputStream.
*
@ -51,11 +51,11 @@ import org.mozilla.javascript.*;
public class ScriptableInputStream extends ObjectInputStream {
/**
* Create a ScriptableInputStream.
* Create a ScriptableInputStream.
* @param in the InputStream to read from.
* @param scope the top-level scope to create the object in.
*/
public ScriptableInputStream(InputStream in, Scriptable scope)
public ScriptableInputStream(InputStream in, Scriptable scope)
throws IOException
{
super(in);
@ -63,7 +63,7 @@ public class ScriptableInputStream extends ObjectInputStream {
enableResolveObject(true);
}
protected Object resolveObject(Object obj)
protected Object resolveObject(Object obj)
throws IOException
{
if (obj instanceof ScriptableOutputStream.PendingLookup) {

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше