зеркало из https://github.com/mozilla/pjs.git
A bunch of changes, some experimental.
Support for jsGet_ and jsSet_ prefixes to methods for explicit getter and setter definition. Addition of "importClass" and "importPackage" top-level functions. The beginnings of a history object accessible from the shell.
This commit is contained in:
Родитель
487d9ea921
Коммит
aadce49c83
|
@ -89,7 +89,6 @@ function processFile(f) {
|
||||||
|
|
||||||
// main script: process each file in arguments list
|
// main script: process each file in arguments list
|
||||||
|
|
||||||
print("here");
|
|
||||||
for (var i=0; i < arguments.length; i++) {
|
for (var i=0; i < arguments.length; i++) {
|
||||||
var filename = String(arguments[i]);
|
var filename = String(arguments[i]);
|
||||||
print("Checking " + filename + "...");
|
print("Checking " + filename + "...");
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mozilla.javascript;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ImporterTopLevel
|
||||||
|
*
|
||||||
|
* 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:
|
||||||
|
* <pre>
|
||||||
|
* Scriptable scope = cx.initStandardObjects(new ImporterTopLevel());
|
||||||
|
* </pre>
|
||||||
|
* Then JavaScript code will have access to the following methods:
|
||||||
|
* <ul>
|
||||||
|
* <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
|
||||||
|
* searching for unqualified names as classes qualified
|
||||||
|
* by the given package.
|
||||||
|
* </ul>
|
||||||
|
* The following code from the shell illustrates this use:
|
||||||
|
* <pre>
|
||||||
|
* js> importClass(java.io.File)
|
||||||
|
* js> f = new File('help.txt')
|
||||||
|
* help.txt
|
||||||
|
* js> importPackage(java.util)
|
||||||
|
* js> v = new Vector()
|
||||||
|
* []
|
||||||
|
*
|
||||||
|
* @author Norris Boyd
|
||||||
|
*/
|
||||||
|
public class ImporterTopLevel extends ScriptableObject {
|
||||||
|
|
||||||
|
public ImporterTopLevel() {
|
||||||
|
String[] names = { "importClass", "importPackage" };
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.defineFunctionProperties(names, ImporterTopLevel.class,
|
||||||
|
ScriptableObject.DONTENUM);
|
||||||
|
} catch (PropertyException e) {
|
||||||
|
throw new Error(); // should never happen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClassName() {
|
||||||
|
return "global";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get(String name, Scriptable start) {
|
||||||
|
Object result = super.get(name, start);
|
||||||
|
if (result == NOT_FOUND && importedPackages != null) {
|
||||||
|
for (int i=0; i < importedPackages.size(); i++) {
|
||||||
|
Object o = importedPackages.elementAt(i);
|
||||||
|
NativeJavaPackage p = (NativeJavaPackage) o;
|
||||||
|
Object v = p.get(name, start);
|
||||||
|
if (v != NOT_FOUND) {
|
||||||
|
if (result == NOT_FOUND)
|
||||||
|
result = v;
|
||||||
|
else
|
||||||
|
throw new EvaluatorException("Ambiguous import: " +
|
||||||
|
result + " and " + v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void importClass(Object cl) {
|
||||||
|
if (!(cl instanceof NativeJavaClass))
|
||||||
|
throw new EvaluatorException("not a class");// TODO: better msg
|
||||||
|
String s = ((NativeJavaClass) cl).getClassObject().getName();
|
||||||
|
String n = s.substring(s.lastIndexOf('.')+1);
|
||||||
|
if (this.has(n, this))
|
||||||
|
throw new EvaluatorException("property " + n +
|
||||||
|
" is already defined");
|
||||||
|
this.defineProperty(n, cl, DONTENUM);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void importPackage(Object pkg) {
|
||||||
|
if (importedPackages == null)
|
||||||
|
importedPackages = new Vector();
|
||||||
|
if (!(pkg instanceof NativeJavaPackage))
|
||||||
|
throw new EvaluatorException("not a package");// TODO: better msg
|
||||||
|
importedPackages.addElement(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector importedPackages;
|
||||||
|
}
|
|
@ -178,8 +178,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
/**
|
/**
|
||||||
* See ECMA 15.4.1,2
|
* See ECMA 15.4.1,2
|
||||||
*/
|
*/
|
||||||
public static Object js_Array(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
if (!inNewExpr) {
|
if (!inNewExpr) {
|
||||||
|
@ -205,11 +205,11 @@ public class NativeArray extends ScriptableObject {
|
||||||
private static final int lengthAttr = ScriptableObject.DONTENUM |
|
private static final int lengthAttr = ScriptableObject.DONTENUM |
|
||||||
ScriptableObject.PERMANENT;
|
ScriptableObject.PERMANENT;
|
||||||
|
|
||||||
public long js_getLength() {
|
public long jsGet_length() {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void js_setLength(Object val) {
|
public void jsSet_length(Object val) {
|
||||||
/* XXX do we satisfy this?
|
/* XXX do we satisfy this?
|
||||||
* 15.4.5.1 [[Put]](P, V):
|
* 15.4.5.1 [[Put]](P, V):
|
||||||
* 1. Call the [[CanPut]] method of A with name P.
|
* 1. Call the [[CanPut]] method of A with name P.
|
||||||
|
@ -258,9 +258,9 @@ public class NativeArray extends ScriptableObject {
|
||||||
static double getLengthProperty(Scriptable obj) {
|
static double getLengthProperty(Scriptable obj) {
|
||||||
// These will both give numeric lengths within Uint32 range.
|
// These will both give numeric lengths within Uint32 range.
|
||||||
if (obj instanceof NativeString)
|
if (obj instanceof NativeString)
|
||||||
return (double)((NativeString)obj).js_getLength();
|
return (double)((NativeString)obj).jsGet_length();
|
||||||
if (obj instanceof NativeArray)
|
if (obj instanceof NativeArray)
|
||||||
return (double)((NativeArray)obj).js_getLength();
|
return (double)((NativeArray)obj).jsGet_length();
|
||||||
return ScriptRuntime.toUint32(ScriptRuntime
|
return ScriptRuntime.toUint32(ScriptRuntime
|
||||||
.getProp(obj, "length", obj));
|
.getProp(obj, "length", obj));
|
||||||
}
|
}
|
||||||
|
@ -309,8 +309,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String js_toString(Context cx, Scriptable thisObj,
|
public static String jsFunction_toString(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
return toStringHelper(cx, thisObj,
|
return toStringHelper(cx, thisObj,
|
||||||
cx.getLanguageVersion() == cx.VERSION_1_2);
|
cx.getLanguageVersion() == cx.VERSION_1_2);
|
||||||
|
@ -393,8 +393,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
/**
|
/**
|
||||||
* See ECMA 15.4.4.3
|
* See ECMA 15.4.4.3
|
||||||
*/
|
*/
|
||||||
public static String js_join(Context cx, Scriptable thisObj,
|
public static String jsFunction_join(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuffer result = new StringBuffer();
|
||||||
String separator;
|
String separator;
|
||||||
|
@ -421,8 +421,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
/**
|
/**
|
||||||
* See ECMA 15.4.4.4
|
* See ECMA 15.4.4.4
|
||||||
*/
|
*/
|
||||||
public static Scriptable js_reverse(Context cx, Scriptable thisObj,
|
public static Scriptable jsFunction_reverse(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
long len = (long)getLengthProperty(thisObj);
|
long len = (long)getLengthProperty(thisObj);
|
||||||
|
|
||||||
|
@ -440,8 +440,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
/**
|
/**
|
||||||
* See ECMA 15.4.4.5
|
* See ECMA 15.4.4.5
|
||||||
*/
|
*/
|
||||||
public static Scriptable js_sort(Context cx, Scriptable thisObj,
|
public static Scriptable jsFunction_sort(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
long length = (long)getLengthProperty(thisObj);
|
long length = (long)getLengthProperty(thisObj);
|
||||||
|
@ -605,8 +605,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
* Non-ECMA methods.
|
* Non-ECMA methods.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static Object js_push(Context cx, Scriptable thisObj,
|
public static Object jsFunction_push(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
double length = getLengthProperty(thisObj);
|
double length = getLengthProperty(thisObj);
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
@ -630,8 +630,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
return new Long((long)length);
|
return new Long((long)length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_pop(Context cx, Scriptable thisObj, Object[] args,
|
public static Object jsFunction_pop(Context cx, Scriptable thisObj,
|
||||||
Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
Object result;
|
Object result;
|
||||||
double length = getLengthProperty(thisObj);
|
double length = getLengthProperty(thisObj);
|
||||||
|
@ -653,8 +653,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_shift(Context cx, Scriptable thisObj, Object[] args,
|
public static Object jsFunction_shift(Context cx, Scriptable thisObj,
|
||||||
Function funOjb)
|
Object[] args, Function funOjb)
|
||||||
{
|
{
|
||||||
Object result;
|
Object result;
|
||||||
double length = getLengthProperty(thisObj);
|
double length = getLengthProperty(thisObj);
|
||||||
|
@ -684,8 +684,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_unshift(Context cx, Scriptable thisObj,
|
public static Object jsFunction_unshift(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funOjb)
|
Object[] args, Function funOjb)
|
||||||
{
|
{
|
||||||
Object result;
|
Object result;
|
||||||
double length = (double)getLengthProperty(thisObj);
|
double length = (double)getLengthProperty(thisObj);
|
||||||
|
@ -713,8 +713,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
return new Long((long)length);
|
return new Long((long)length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_splice(Context cx, Scriptable thisObj,
|
public static Object jsFunction_splice(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
/* create an empty Array to return. */
|
/* create an empty Array to return. */
|
||||||
Scriptable scope = getTopLevelScope(funObj);
|
Scriptable scope = getTopLevelScope(funObj);
|
||||||
|
@ -820,8 +820,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
/*
|
/*
|
||||||
* Python-esque sequence operations.
|
* Python-esque sequence operations.
|
||||||
*/
|
*/
|
||||||
public static Scriptable js_concat(Context cx, Scriptable thisObj,
|
public static Scriptable jsFunction_concat(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
/* Concat tries to keep the definition of an array as general
|
/* Concat tries to keep the definition of an array as general
|
||||||
* as possible; if it finds that an object has a numeric
|
* as possible; if it finds that an object has a numeric
|
||||||
|
@ -873,8 +873,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Scriptable js_slice(Context cx, Scriptable thisObj,
|
public static Scriptable jsFunction_slice(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
Scriptable scope = getTopLevelScope(funObj);
|
Scriptable scope = getTopLevelScope(funObj);
|
||||||
Scriptable result = ScriptRuntime.newObject(cx, scope, "Array", null);
|
Scriptable result = ScriptRuntime.newObject(cx, scope, "Array", null);
|
||||||
|
|
|
@ -47,8 +47,8 @@ public class NativeBoolean extends ScriptableObject {
|
||||||
return super.getDefaultValue(typeHint);
|
return super.getDefaultValue(typeHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object Boolean(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
boolean b = args.length >= 1
|
boolean b = args.length >= 1
|
||||||
? ScriptRuntime.toBoolean(args[0])
|
? ScriptRuntime.toBoolean(args[0])
|
||||||
|
@ -62,11 +62,11 @@ public class NativeBoolean extends ScriptableObject {
|
||||||
return b ? Boolean.TRUE : Boolean.FALSE;
|
return b ? Boolean.TRUE : Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String jsFunction_toString() {
|
||||||
return booleanValue ? "true" : "false";
|
return booleanValue ? "true" : "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean valueOf() {
|
public boolean jsFunction_valueOf() {
|
||||||
return booleanValue;
|
return booleanValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,8 @@ public final class NativeCall extends ScriptableObject {
|
||||||
return "Call";
|
return "Call";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_Call(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
if (!inNewExpr) {
|
if (!inNewExpr) {
|
||||||
Object[] errArgs = { "Call" };
|
Object[] errArgs = { "Call" };
|
||||||
|
|
|
@ -63,8 +63,8 @@ public class NativeClosure extends ScriptableObject implements Function {
|
||||||
return proto.construct(cx, getParentScope(), args);
|
return proto.construct(cx, getParentScope(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_Closure(Context cx, Object[] args,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
Function ctorObj, boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
Object[] msgArgs = { "Closure" };
|
Object[] msgArgs = { "Closure" };
|
||||||
throw Context.reportRuntimeError(
|
throw Context.reportRuntimeError(
|
||||||
|
|
|
@ -779,8 +779,8 @@ public class NativeDate extends ScriptableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the javascript constructor */
|
/* the javascript constructor */
|
||||||
public static Object js_Date(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
// if called as a function, just return a string
|
// if called as a function, just return a string
|
||||||
// representing the current time.
|
// representing the current time.
|
||||||
|
@ -860,7 +860,7 @@ public class NativeDate extends ScriptableObject {
|
||||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||||
};
|
};
|
||||||
|
|
||||||
public String js_toString() {
|
public String jsFunction_toString() {
|
||||||
/* all for want of printf. All of this garbage seems necessary
|
/* all for want of printf. All of this garbage seems necessary
|
||||||
* because Java carefully avoids providing non-localized
|
* because Java carefully avoids providing non-localized
|
||||||
* string formatting. We need to avoid localization to ensure
|
* string formatting. We need to avoid localization to ensure
|
||||||
|
@ -872,7 +872,7 @@ public class NativeDate extends ScriptableObject {
|
||||||
return date_format(this.date);
|
return date_format(this.date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_toLocaleString() {
|
public String jsFunction_toLocaleString() {
|
||||||
if (this.date != this.date)
|
if (this.date != this.date)
|
||||||
return js_NaN_date_str;
|
return js_NaN_date_str;
|
||||||
|
|
||||||
|
@ -883,7 +883,7 @@ public class NativeDate extends ScriptableObject {
|
||||||
return localeDateFormatter.format(tempdate);
|
return localeDateFormatter.format(tempdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_toUTCString() {
|
public String jsFunction_toUTCString() {
|
||||||
if (this.date != this.date)
|
if (this.date != this.date)
|
||||||
return js_NaN_date_str;
|
return js_NaN_date_str;
|
||||||
|
|
||||||
|
@ -932,7 +932,7 @@ public class NativeDate extends ScriptableObject {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double js_valueOf() {
|
public double jsFunction_valueOf() {
|
||||||
return this.date;
|
return this.date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
|
|
||||||
public String decompile(int indent, boolean toplevel, boolean justbody) {
|
public String decompile(int indent, boolean toplevel, boolean justbody) {
|
||||||
if (source == null)
|
if (source == null)
|
||||||
return "function " + js_getName() +
|
return "function " + jsGet_name() +
|
||||||
"() {\n\t[native code]\n}\n";
|
"() {\n\t[native code]\n}\n";
|
||||||
|
|
||||||
// Spew tokens in source, for debugging.
|
// Spew tokens in source, for debugging.
|
||||||
|
@ -820,8 +820,8 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_toString(Context cx, Scriptable thisObj,
|
public static Object jsFunction_toString(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
||||||
if (!(val instanceof NativeFunction)) {
|
if (!(val instanceof NativeFunction)) {
|
||||||
|
@ -837,8 +837,8 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
return ((NativeFunction) val).decompile(indent, true, false);
|
return ((NativeFunction) val).decompile(indent, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Scriptable js_Function(Context cx, Object[] args,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
Function ctorObj, boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
int arglen = args.length;
|
int arglen = args.length;
|
||||||
StringBuffer funArgs = new StringBuffer();
|
StringBuffer funArgs = new StringBuffer();
|
||||||
|
@ -892,12 +892,12 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
*
|
*
|
||||||
* A proposed ECMA extension for round 2.
|
* A proposed ECMA extension for round 2.
|
||||||
*/
|
*/
|
||||||
public static Object js_apply(Context cx, Scriptable thisObj,
|
public static Object jsFunction_apply(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
if (args.length != 2)
|
if (args.length != 2)
|
||||||
return js_call(cx, thisObj, args, funObj);
|
return jsFunction_call(cx, thisObj, args, funObj);
|
||||||
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
||||||
Scriptable newThis = args[0] == null
|
Scriptable newThis = args[0] == null
|
||||||
? null
|
? null
|
||||||
|
@ -911,8 +911,8 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
*
|
*
|
||||||
* A proposed ECMA extension for round 2.
|
* A proposed ECMA extension for round 2.
|
||||||
*/
|
*/
|
||||||
public static Object js_call(Context cx, Scriptable thisObj,
|
public static Object jsFunction_call(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
||||||
|
@ -931,7 +931,7 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int js_getLength() {
|
public int jsGet_length() {
|
||||||
Context cx = Context.getContext();
|
Context cx = Context.getContext();
|
||||||
if (cx.getLanguageVersion() != Context.VERSION_1_2)
|
if (cx.getLanguageVersion() != Context.VERSION_1_2)
|
||||||
return argCount;
|
return argCount;
|
||||||
|
@ -941,11 +941,11 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
return activation.getOriginalArguments().length;
|
return activation.getOriginalArguments().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int js_getArity() {
|
public int jsGet_arity() {
|
||||||
return argCount;
|
return argCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_getName() {
|
public String jsGet_name() {
|
||||||
if (names != null && names[0].length() > 0)
|
if (names != null && names[0].length() > 0)
|
||||||
return names[0];
|
return names[0];
|
||||||
|
|
||||||
|
|
|
@ -47,9 +47,6 @@ public class NativeJavaPackage extends ScriptableObject {
|
||||||
"java.text",
|
"java.text",
|
||||||
"java.text.resources",
|
"java.text.resources",
|
||||||
"java.applet",
|
"java.applet",
|
||||||
"netscape.security",
|
|
||||||
"netscape.plugin",
|
|
||||||
"netscape.application",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Scriptable init(Scriptable scope)
|
public static Scriptable init(Scriptable scope)
|
||||||
|
|
|
@ -59,8 +59,8 @@ public class NativeNumber extends ScriptableObject {
|
||||||
return "Number";
|
return "Number";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object Number(Context cx, Object[] args, Function funObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function funObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
double d = args.length >= 1
|
double d = args.length >= 1
|
||||||
? ScriptRuntime.toNumber(args[0])
|
? ScriptRuntime.toNumber(args[0])
|
||||||
|
@ -72,17 +72,20 @@ public class NativeNumber extends ScriptableObject {
|
||||||
// Number(val) converts val to a number value.
|
// Number(val) converts val to a number value.
|
||||||
return new Double(d);
|
return new Double(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(Object base) {
|
public String toString() {
|
||||||
if (base == Undefined.instance)
|
return jsFunction_toString(Undefined.instance);
|
||||||
return ScriptRuntime.numberToString(doubleValue, 10);
|
|
||||||
else
|
|
||||||
return ScriptRuntime.numberToString(doubleValue,
|
|
||||||
ScriptRuntime.toInt32(base));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double valueOf() {
|
public String jsFunction_toString(Object base) {
|
||||||
return doubleValue;
|
int i = base == Undefined.instance
|
||||||
|
? 10
|
||||||
|
: ScriptRuntime.toInt32(base);
|
||||||
|
return ScriptRuntime.numberToString(doubleValue, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double jsFunction_valueOf() {
|
||||||
|
return doubleValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final double defaultValue = +0.0;
|
private static final double defaultValue = +0.0;
|
||||||
|
|
|
@ -38,8 +38,8 @@ public class NativeObject extends ScriptableObject {
|
||||||
return "Object";
|
return "Object";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_Object(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
if (!inNewExpr) {
|
if (!inNewExpr) {
|
||||||
|
@ -57,13 +57,13 @@ public class NativeObject extends ScriptableObject {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
Context cx = Context.getContext();
|
Context cx = Context.getContext();
|
||||||
if (cx != null)
|
if (cx != null)
|
||||||
return js_toString(cx, this, null, null);
|
return jsFunction_toString(cx, this, null, null);
|
||||||
else
|
else
|
||||||
return "[object " + getClassName() + "]";
|
return "[object " + getClassName() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String js_toString(Context cx, Scriptable thisObj,
|
public static String jsFunction_toString(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (cx.getLanguageVersion() != cx.VERSION_1_2)
|
if (cx.getLanguageVersion() != cx.VERSION_1_2)
|
||||||
return "[object " + thisObj.getClassName() + "]";
|
return "[object " + thisObj.getClassName() + "]";
|
||||||
|
@ -118,8 +118,8 @@ public class NativeObject extends ScriptableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_valueOf(Context cx, Scriptable thisObj,
|
public static Object jsFunction_valueOf(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
return thisObj;
|
return thisObj;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,8 @@ public class NativeScript extends NativeFunction implements Script {
|
||||||
* The Java method defining the JavaScript Script constructor.
|
* The Java method defining the JavaScript Script constructor.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static Object js_Script(Context cx, Object[] args,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
Function ctorObj, boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
String source = args.length == 0
|
String source = args.length == 0
|
||||||
? ""
|
? ""
|
||||||
|
@ -95,19 +95,19 @@ public class NativeScript extends NativeFunction implements Script {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Scriptable js_compile(String source) {
|
public Scriptable jsFunction_compile(String source) {
|
||||||
script = compile(null, source);
|
script = compile(null, source);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object js_exec() throws JavaScriptException {
|
public Object jsFunction_exec() throws JavaScriptException {
|
||||||
Object[] msgArgs = { "exec" };
|
Object[] msgArgs = { "exec" };
|
||||||
throw Context.reportRuntimeError(
|
throw Context.reportRuntimeError(
|
||||||
Context.getMessage("msg.cant.call.indirect", msgArgs));
|
Context.getMessage("msg.cant.call.indirect", msgArgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_toString(Context cx, Scriptable thisObj,
|
public static Object jsFunction_toString(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
Script thisScript = ((NativeScript) thisObj).script;
|
Script thisScript = ((NativeScript) thisObj).script;
|
||||||
if (thisScript == null)
|
if (thisScript == null)
|
||||||
|
@ -119,7 +119,7 @@ public class NativeScript extends NativeFunction implements Script {
|
||||||
/*
|
/*
|
||||||
* Override method in NativeFunction to avoid ever returning "anonymous"
|
* Override method in NativeFunction to avoid ever returning "anonymous"
|
||||||
*/
|
*/
|
||||||
public String js_getName() {
|
public String jsGet_name() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,8 +97,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
return s.toString();
|
return s.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_String(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
String s = args.length >= 1
|
String s = args.length >= 1
|
||||||
? ScriptRuntime.toString(args[0])
|
? ScriptRuntime.toString(args[0])
|
||||||
|
@ -116,11 +116,11 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ECMA 15.5.4.2: 'the toString function is not generic.' */
|
/* ECMA 15.5.4.2: 'the toString function is not generic.' */
|
||||||
public String js_toString() {
|
public String jsFunction_toString() {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_valueOf() {
|
public String jsFunction_valueOf() {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,8 +143,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
*
|
*
|
||||||
* See ECMA 15.5.4.[4,5]
|
* See ECMA 15.5.4.[4,5]
|
||||||
*/
|
*/
|
||||||
public static String js_charAt(Context cx, Scriptable thisObj,
|
public static String jsFunction_charAt(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
args = ScriptRuntime.padArguments(args, 1);
|
args = ScriptRuntime.padArguments(args, 1);
|
||||||
|
@ -160,8 +160,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
return target.substring((int)pos, (int)pos + 1);
|
return target.substring((int)pos, (int)pos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double js_charCodeAt(Context cx, Scriptable thisObj,
|
public static double jsFunction_charCodeAt(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
args = ScriptRuntime.padArguments(args, 1);
|
args = ScriptRuntime.padArguments(args, 1);
|
||||||
|
@ -181,8 +181,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
* See ECMA 15.5.4.6. Uses Java String.indexOf()
|
* See ECMA 15.5.4.6. Uses Java String.indexOf()
|
||||||
* OPT to add - BMH searching from jsstr.c.
|
* OPT to add - BMH searching from jsstr.c.
|
||||||
*/
|
*/
|
||||||
public static int js_indexOf(Context cx, Scriptable thisObj,
|
public static int jsFunction_indexOf(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (args.length < 2)
|
if (args.length < 2)
|
||||||
args = ScriptRuntime.padArguments(args, 2);
|
args = ScriptRuntime.padArguments(args, 2);
|
||||||
|
@ -205,8 +205,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
* See ECMA 15.5.4.7
|
* See ECMA 15.5.4.7
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static int js_lastIndexOf(Context cx, Scriptable thisObj,
|
public static int jsFunction_lastIndexOf(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (args.length < 2)
|
if (args.length < 2)
|
||||||
args = ScriptRuntime.padArguments(args, 2);
|
args = ScriptRuntime.padArguments(args, 2);
|
||||||
|
@ -350,8 +350,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
* a limit argument and accepts a regular expression as the split
|
* a limit argument and accepts a regular expression as the split
|
||||||
* argument.
|
* argument.
|
||||||
*/
|
*/
|
||||||
public static Object js_split(Context cx, Scriptable thisObj,
|
public static Object jsFunction_split(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
String target = ScriptRuntime.toString(thisObj);
|
String target = ScriptRuntime.toString(thisObj);
|
||||||
|
|
||||||
|
@ -446,8 +446,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
*
|
*
|
||||||
* See ECMA 15.5.4.[9,10]
|
* See ECMA 15.5.4.[9,10]
|
||||||
*/
|
*/
|
||||||
public static String js_substring(Context cx, Scriptable thisObj,
|
public static String jsFunction_substring(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
args = ScriptRuntime.padArguments(args, 1);
|
args = ScriptRuntime.padArguments(args, 1);
|
||||||
|
@ -490,29 +490,29 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
*
|
*
|
||||||
* See ECMA 15.5.4.[11,12]
|
* See ECMA 15.5.4.[11,12]
|
||||||
*/
|
*/
|
||||||
public static String js_toLowerCase(Context cx, Scriptable thisObj,
|
public static String jsFunction_toLowerCase(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
String target = ScriptRuntime.toString(thisObj);
|
String target = ScriptRuntime.toString(thisObj);
|
||||||
return target.toLowerCase();
|
return target.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String js_toUpperCase(Context cx, Scriptable thisObj,
|
public static String jsFunction_toUpperCase(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
String target = ScriptRuntime.toString(thisObj);
|
String target = ScriptRuntime.toString(thisObj);
|
||||||
return target.toUpperCase();
|
return target.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double js_getLength() {
|
public double jsGet_length() {
|
||||||
return (double) string.length();
|
return (double) string.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-ECMA methods.
|
* Non-ECMA methods.
|
||||||
*/
|
*/
|
||||||
public static String js_substr(Context cx, Scriptable thisObj,
|
public static String jsFunction_substr(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
String target = ScriptRuntime.toString(thisObj);
|
String target = ScriptRuntime.toString(thisObj);
|
||||||
|
|
||||||
|
@ -548,8 +548,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
/**
|
/**
|
||||||
* Python-esque sequence operations.
|
* Python-esque sequence operations.
|
||||||
*/
|
*/
|
||||||
public static String js_concat(Context cx, Scriptable thisObj,
|
public static String jsFunction_concat(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuffer result = new StringBuffer();
|
||||||
result.append(ScriptRuntime.toString(thisObj));
|
result.append(ScriptRuntime.toString(thisObj));
|
||||||
|
@ -560,8 +560,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String js_slice(Context cx, Scriptable thisObj,
|
public static String jsFunction_slice(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
String target = ScriptRuntime.toString(thisObj);
|
String target = ScriptRuntime.toString(thisObj);
|
||||||
|
|
||||||
|
@ -615,55 +615,55 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_bold() {
|
public String jsFunction_bold() {
|
||||||
return tagify("B", null, null);
|
return tagify("B", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_italics() {
|
public String jsFunction_italics() {
|
||||||
return tagify("I", null, null);
|
return tagify("I", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_fixed() {
|
public String jsFunction_fixed() {
|
||||||
return tagify("TT", null, null);
|
return tagify("TT", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_strike() {
|
public String jsFunction_strike() {
|
||||||
return tagify("STRIKE", null, null);
|
return tagify("STRIKE", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_small() {
|
public String jsFunction_small() {
|
||||||
return tagify("SMALL", null, null);
|
return tagify("SMALL", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_big() {
|
public String jsFunction_big() {
|
||||||
return tagify("BIG", null, null);
|
return tagify("BIG", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_blink() {
|
public String jsFunction_blink() {
|
||||||
return tagify("BLINK", null, null);
|
return tagify("BLINK", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_sup() {
|
public String jsFunction_sup() {
|
||||||
return tagify("SUP", null, null);
|
return tagify("SUP", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_sub() {
|
public String jsFunction_sub() {
|
||||||
return tagify("SUB", null, null);
|
return tagify("SUB", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_fontsize(String value) {
|
public String jsFunction_fontsize(String value) {
|
||||||
return tagify("FONT SIZE", "FONT", value);
|
return tagify("FONT SIZE", "FONT", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_fontcolor(String value) {
|
public String jsFunction_fontcolor(String value) {
|
||||||
return tagify("FONT COLOR", "FONT", value);
|
return tagify("FONT COLOR", "FONT", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_link(String value) {
|
public String jsFunction_link(String value) {
|
||||||
return tagify("A HREF", "A", value);
|
return tagify("A HREF", "A", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_anchor(String value) {
|
public String jsFunction_anchor(String value) {
|
||||||
return tagify("A NAME", "A", value);
|
return tagify("A NAME", "A", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -675,22 +675,22 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_match(Context cx, Scriptable thisObj,
|
public static Object jsFunction_match(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
return checkReProxy(cx).match(cx, thisObj, args, funObj);
|
return checkReProxy(cx).match(cx, thisObj, args, funObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_search(Context cx, Scriptable thisObj,
|
public static Object jsFunction_search(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
return checkReProxy(cx).search(cx, thisObj, args, funObj);
|
return checkReProxy(cx).search(cx, thisObj, args, funObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_replace(Context cx, Scriptable thisObj,
|
public static Object jsFunction_replace(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
return checkReProxy(cx).replace(cx, thisObj, args, funObj);
|
return checkReProxy(cx).replace(cx, thisObj, args, funObj);
|
||||||
|
|
|
@ -31,7 +31,8 @@ public class NativeWith implements Scriptable {
|
||||||
public static void init(Scriptable scope) {
|
public static void init(Scriptable scope) {
|
||||||
NativeWith w = new NativeWith();
|
NativeWith w = new NativeWith();
|
||||||
w.setPrototype(ScriptableObject.getObjectPrototype(scope));
|
w.setPrototype(ScriptableObject.getObjectPrototype(scope));
|
||||||
Method[] m = FunctionObject.findMethods(NativeWith.class, "With");
|
Method[] m = FunctionObject.findMethods(NativeWith.class,
|
||||||
|
"jsConstructor");
|
||||||
FunctionObject f = new FunctionObject("With", m[0], scope);
|
FunctionObject f = new FunctionObject("With", m[0], scope);
|
||||||
f.addAsConstructor(scope, w);
|
f.addAsConstructor(scope, w);
|
||||||
}
|
}
|
||||||
|
@ -120,8 +121,8 @@ public class NativeWith implements Scriptable {
|
||||||
return prototype.hasInstance(value);
|
return prototype.hasInstance(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object With(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
Object[] msgArgs = { "With" };
|
Object[] msgArgs = { "With" };
|
||||||
throw Context.reportRuntimeError(
|
throw Context.reportRuntimeError(
|
||||||
|
|
|
@ -119,7 +119,6 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
* @param start the object in which the lookup began
|
* @param start the object in which the lookup began
|
||||||
* @return the value of the property (may be null), or NOT_FOUND
|
* @return the value of the property (may be null), or NOT_FOUND
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Object get(String name, Scriptable start) {
|
public Object get(String name, Scriptable start) {
|
||||||
int hashCode;
|
int hashCode;
|
||||||
if (name == lastName) {
|
if (name == lastName) {
|
||||||
|
@ -127,7 +126,7 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
return lastValue;
|
return lastValue;
|
||||||
hashCode = lastHash;
|
hashCode = lastHash;
|
||||||
} else {
|
} else {
|
||||||
hashCode = name.hashCode();
|
hashCode = name.hashCode();
|
||||||
}
|
}
|
||||||
int slotIndex = getSlot(name, hashCode);
|
int slotIndex = getSlot(name, hashCode);
|
||||||
if (slotIndex == SLOT_NOT_FOUND)
|
if (slotIndex == SLOT_NOT_FOUND)
|
||||||
|
@ -593,50 +592,43 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
* methods are used to initialize a class in the following manner.<p>
|
* methods are used to initialize a class in the following manner.<p>
|
||||||
*
|
*
|
||||||
* First, the zero-parameter constructor of the class is called to
|
* First, the zero-parameter constructor of the class is called to
|
||||||
* create the prototypical instance. If no such constructor exists,
|
* create the prototype. If no such constructor exists,
|
||||||
* a ClassDefinitionException is thrown. <p>
|
* a ClassDefinitionException is thrown. <p>
|
||||||
*
|
*
|
||||||
* Next, all methods are scanned. If any method
|
* Next, all methods are scanned for special prefixes that indicate that they
|
||||||
* begins with a special prefix, then only methods with
|
* have special meaning for defining JavaScript objects.
|
||||||
* special prefixes are considered for defining functions
|
* These special prefixes are
|
||||||
* and properties. These special prefixes are
|
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><code>js_</code> for a JavaScript property or function, as
|
|
||||||
* determined by the name of the method
|
|
||||||
* <li><code>jsFunction_</code> for a JavaScript function
|
* <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
|
* is a property of the constructor
|
||||||
* <li><code>jsProperty_</code> for a JavaScript property
|
* <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
|
||||||
|
* is the constructor
|
||||||
* </ul><p>
|
* </ul><p>
|
||||||
*
|
*
|
||||||
* If no methods begin with any of these prefixes, all methods
|
* If the method's name begins with "jsFunction_", a JavaScript function
|
||||||
* are added as JavaScript functions or properties except
|
* is created with a name formed from the rest of the Java method name
|
||||||
* those with names matching the names of methods in
|
* following "jsFunction_". So a Java method named "jsFunction_foo" will
|
||||||
* <code>org.mozilla.javascript.Function</code>
|
* define a JavaScript method "foo". Calling this JavaScript function
|
||||||
* or any of its supertypes. This means that
|
* will cause the Java method to be called. The parameters of the method
|
||||||
* <code>call</code>, which is a method in Function, and
|
* must be of number and types as defined by the FunctionObject class.
|
||||||
* <code>get</code>, which is a method in Scriptable
|
* The JavaScript function is then added as a property
|
||||||
* (which Function extends), are both excluded from
|
* of the prototype. <p>
|
||||||
* defining JavaScript methods.<p>
|
*
|
||||||
*
|
* If the method's name begins with "jsStaticFunction_", it is handled
|
||||||
* If after removing any prefixes, a method's name matches the name of
|
* similarly except that the resulting JavaScript function is added as a
|
||||||
* the class (determined by calling <code>getClassName()</code>
|
* property of the constructor object. The Java method must be static.
|
||||||
* on the prototypical instance), it is considered to define the
|
*
|
||||||
* JavaScript constructor.<p>
|
* If the method's name begins with "jsGet_" or "jsSet_", the method is
|
||||||
*
|
|
||||||
* If the method's name begins with "get" or "set" after
|
|
||||||
* any prefix other than "jsFunction_" is removed, the method is
|
|
||||||
* considered to define a property. Accesses to the defined property
|
* considered to define a property. Accesses to the defined property
|
||||||
* will result in calls to these getter and setter methods. If no
|
* will result in calls to these getter and setter methods. If no
|
||||||
* setter is defined, the property is defined as READONLY.<p>
|
* setter is defined, the property is defined as READONLY.<p>
|
||||||
*
|
*
|
||||||
* Otherwise, a JavaScript function is created that will call the
|
* If the method's name is "jsConstructor", the method is
|
||||||
* given method. This function is then added as a property
|
* considered to define the body of the constructor. Only one
|
||||||
* of the prototypical instance. So if a JavaScript
|
* method of this name may be defined.
|
||||||
* function beginning with "get" or "set" is desired, it must be
|
|
||||||
* prefixed with "jsFunction_" to distinquish it from a method
|
|
||||||
* defining a property.<p>
|
|
||||||
*
|
|
||||||
* If no method is found that can serve as constructor, a Java
|
* If no method is found that can serve as constructor, a Java
|
||||||
* constructor will be selected to serve as the JavaScript
|
* constructor will be selected to serve as the JavaScript
|
||||||
* constructor in the following manner. If the class has only one
|
* constructor in the following manner. If the class has only one
|
||||||
|
@ -644,7 +636,7 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
* the JavaScript constructor. If the the class has two constructors,
|
* the JavaScript constructor. If the the class has two constructors,
|
||||||
* one must be the zero-argument constructor (otherwise an
|
* one must be the zero-argument constructor (otherwise an
|
||||||
* ClassDefinitionException would have already been thrown
|
* ClassDefinitionException would have already been thrown
|
||||||
* when the prototypical instance was to be created). In this case
|
* when the prototype was to be created). In this case
|
||||||
* the Java constructor with one or more parameters will be used
|
* the Java constructor with one or more parameters will be used
|
||||||
* to define the JavaScript constructor. If the class has three
|
* to define the JavaScript constructor. If the class has three
|
||||||
* or more constructors, an ClassDefinitionException
|
* or more constructors, an ClassDefinitionException
|
||||||
|
@ -669,8 +661,7 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
* @exception InvocationTargetException if an exception is thrown
|
* @exception InvocationTargetException if an exception is thrown
|
||||||
* during execution of methods of the named class
|
* during execution of methods of the named class
|
||||||
* @exception ClassDefinitionException if an appropriate
|
* @exception ClassDefinitionException if an appropriate
|
||||||
* constructor cannot be found to create the prototypical
|
* constructor cannot be found to create the prototype
|
||||||
* instance
|
|
||||||
* @exception PropertyException if getter and setter
|
* @exception PropertyException if getter and setter
|
||||||
* methods do not conform to the requirements of the
|
* methods do not conform to the requirements of the
|
||||||
* defineProperty method
|
* defineProperty method
|
||||||
|
@ -709,8 +700,7 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
* @exception InvocationTargetException if an exception is thrown
|
* @exception InvocationTargetException if an exception is thrown
|
||||||
* during execution of methods of the named class
|
* during execution of methods of the named class
|
||||||
* @exception ClassDefinitionException if an appropriate
|
* @exception ClassDefinitionException if an appropriate
|
||||||
* constructor cannot be found to create the prototypical
|
* constructor cannot be found to create the prototype
|
||||||
* instance
|
|
||||||
* @exception PropertyException if getter and setter
|
* @exception PropertyException if getter and setter
|
||||||
* methods do not conform to the requirements of the
|
* methods do not conform to the requirements of the
|
||||||
* defineProperty method
|
* defineProperty method
|
||||||
|
@ -763,13 +753,29 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
// Find out whether there are any methods that begin with
|
// Find out whether there are any methods that begin with
|
||||||
// "js". If so, then only methods that begin with special
|
// "js". If so, then only methods that begin with special
|
||||||
// prefixes will be defined as JavaScript entities.
|
// prefixes will be defined as JavaScript entities.
|
||||||
|
// The prefixes "js_" and "jsProperty_" are deprecated.
|
||||||
final String genericPrefix = "js_";
|
final String genericPrefix = "js_";
|
||||||
final String functionPrefix = "jsFunction_";
|
final String functionPrefix = "jsFunction_";
|
||||||
final String staticFunctionPrefix = "jsStaticFunction_";
|
final String staticFunctionPrefix = "jsStaticFunction_";
|
||||||
final String propertyPrefix = "jsProperty_";
|
final String propertyPrefix = "jsProperty_";
|
||||||
|
final String getterPrefix = "jsGet_";
|
||||||
|
final String setterPrefix = "jsSet_";
|
||||||
|
|
||||||
boolean hasPrefix = false;
|
Method[] ctorMeths = FunctionObject.findMethods(clazz,
|
||||||
|
"jsConstructor");
|
||||||
Member ctorMember = null;
|
Member ctorMember = null;
|
||||||
|
if (ctorMeths != null) {
|
||||||
|
if (ctorMeths.length > 1) {
|
||||||
|
Object[] args = { ctorMeths[0], ctorMeths[1] };
|
||||||
|
throw new ClassDefinitionException(
|
||||||
|
Context.getMessage("msg.multiple.ctors", args));
|
||||||
|
}
|
||||||
|
ctorMember = ctorMeths[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: look for functions with the same name as the class
|
||||||
|
// and consider them constructors.
|
||||||
|
boolean hasPrefix = false;
|
||||||
for (int i=0; i < methods.length; i++) {
|
for (int i=0; i < methods.length; i++) {
|
||||||
String name = methods[i].getName();
|
String name = methods[i].getName();
|
||||||
String prefix = null;
|
String prefix = null;
|
||||||
|
@ -781,8 +787,6 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
prefix = functionPrefix;
|
prefix = functionPrefix;
|
||||||
else if (name.startsWith(staticFunctionPrefix))
|
else if (name.startsWith(staticFunctionPrefix))
|
||||||
prefix = staticFunctionPrefix;
|
prefix = staticFunctionPrefix;
|
||||||
else if (name.startsWith(propertyPrefix))
|
|
||||||
prefix = propertyPrefix;
|
|
||||||
if (prefix != null) {
|
if (prefix != null) {
|
||||||
hasPrefix = true;
|
hasPrefix = true;
|
||||||
name = name.substring(prefix.length());
|
name = name.substring(prefix.length());
|
||||||
|
@ -816,9 +820,11 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
FunctionObject ctor = new FunctionObject(className, ctorMember, scope);
|
FunctionObject ctor = new FunctionObject(className, ctorMember, scope);
|
||||||
ctor.addAsConstructor(scope, proto);
|
ctor.addAsConstructor(scope, proto);
|
||||||
|
|
||||||
|
if (!hasPrefix && exclusionList == null)
|
||||||
|
exclusionList = getExclusionList();
|
||||||
Method finishInit = null;
|
Method finishInit = null;
|
||||||
for (int i=0; i < methods.length; i++) {
|
for (int i=0; i < methods.length; i++) {
|
||||||
if (methods[i].getDeclaringClass() != clazz)
|
if (!hasPrefix && methods[i].getDeclaringClass() != clazz)
|
||||||
continue;
|
continue;
|
||||||
String name = methods[i].getName();
|
String name = methods[i].getName();
|
||||||
if (name.equals("finishInit")) {
|
if (name.equals("finishInit")) {
|
||||||
|
@ -836,13 +842,10 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
String prefix = null;
|
String prefix = null;
|
||||||
if (hasPrefix) {
|
if (hasPrefix) {
|
||||||
if (name.startsWith(genericPrefix)) {
|
if (name.startsWith(genericPrefix)) {
|
||||||
name = name.substring(genericPrefix.length());
|
|
||||||
prefix = genericPrefix;
|
prefix = genericPrefix;
|
||||||
} else if (name.startsWith(functionPrefix)) {
|
} else if (name.startsWith(functionPrefix)) {
|
||||||
name = name.substring(functionPrefix.length());
|
|
||||||
prefix = functionPrefix;
|
prefix = functionPrefix;
|
||||||
} else if (name.startsWith(staticFunctionPrefix)) {
|
} else if (name.startsWith(staticFunctionPrefix)) {
|
||||||
name = name.substring(staticFunctionPrefix.length());
|
|
||||||
prefix = staticFunctionPrefix;
|
prefix = staticFunctionPrefix;
|
||||||
if (!Modifier.isStatic(methods[i].getModifiers())) {
|
if (!Modifier.isStatic(methods[i].getModifiers())) {
|
||||||
throw new ClassDefinitionException(
|
throw new ClassDefinitionException(
|
||||||
|
@ -851,16 +854,47 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
} else if (name.startsWith(propertyPrefix)) {
|
} else if (name.startsWith(propertyPrefix)) {
|
||||||
name = name.substring(propertyPrefix.length());
|
name = name.substring(propertyPrefix.length());
|
||||||
prefix = propertyPrefix;
|
prefix = propertyPrefix;
|
||||||
|
} else if (name.startsWith(getterPrefix)) {
|
||||||
|
prefix = getterPrefix;
|
||||||
|
} else if (name.startsWith(setterPrefix)) {
|
||||||
|
prefix = setterPrefix;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
name = name.substring(prefix.length());
|
||||||
} else if (exclusionList.get(name) != null)
|
} else if (exclusionList.get(name) != null)
|
||||||
continue;
|
continue;
|
||||||
if (methods[i] == ctorMember) {
|
if (methods[i] == ctorMember) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((name.startsWith("get") || name.startsWith("set"))
|
if (prefix != null && prefix.equals(setterPrefix))
|
||||||
&& name.length() > 3 &&
|
continue; // deal with set when we see get
|
||||||
|
if (prefix != null && prefix.equals(getterPrefix)) {
|
||||||
|
if (!(proto instanceof ScriptableObject)) {
|
||||||
|
Object[] args = { proto.getClass().toString(), name };
|
||||||
|
throw new PropertyException(
|
||||||
|
Context.getMessage("msg.extend.scriptable", args));
|
||||||
|
}
|
||||||
|
Method[] setter = FunctionObject.findMethods(
|
||||||
|
clazz,
|
||||||
|
setterPrefix + name);
|
||||||
|
if (setter != null && setter.length != 1) {
|
||||||
|
Object[] errArgs = { name, clazz.getName() };
|
||||||
|
throw new PropertyException(
|
||||||
|
Context.getMessage("msg.no.overload", errArgs));
|
||||||
|
}
|
||||||
|
int attr = ScriptableObject.PERMANENT |
|
||||||
|
ScriptableObject.DONTENUM |
|
||||||
|
(setter != null ? 0
|
||||||
|
: ScriptableObject.READONLY);
|
||||||
|
Method m = setter == null ? null : setter[0];
|
||||||
|
((ScriptableObject) proto).defineProperty(name, null,
|
||||||
|
methods[i], m,
|
||||||
|
attr);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((name.startsWith("get") || name.startsWith("set")) &&
|
||||||
|
name.length() > 3 &&
|
||||||
!(hasPrefix && (prefix.equals(functionPrefix) ||
|
!(hasPrefix && (prefix.equals(functionPrefix) ||
|
||||||
prefix.equals(staticFunctionPrefix))))
|
prefix.equals(staticFunctionPrefix))))
|
||||||
{
|
{
|
||||||
|
|
|
@ -203,7 +203,7 @@ public class NativeRegExp extends ScriptableObject implements Function {
|
||||||
boolean test, Function funObj)
|
boolean test, Function funObj)
|
||||||
{
|
{
|
||||||
if (!(thisObj instanceof NativeRegExp)) {
|
if (!(thisObj instanceof NativeRegExp)) {
|
||||||
Object[] errArgs = { ((NativeFunction) funObj).js_getName() };
|
Object[] errArgs = { ((NativeFunction) funObj).jsGet_name() };
|
||||||
throw Context.reportRuntimeError(
|
throw Context.reportRuntimeError(
|
||||||
ScriptRuntime.getMessage("msg.incompat.call", errArgs));
|
ScriptRuntime.getMessage("msg.incompat.call", errArgs));
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.mozilla.javascript.debug.SourceTextManagerImpl;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class Main extends ScriptableObject {
|
public class Main extends ImporterTopLevel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point.
|
* Main entry point.
|
||||||
|
@ -108,6 +108,10 @@ public class Main extends ScriptableObject {
|
||||||
global.defineProperty("environment", environment,
|
global.defineProperty("environment", environment,
|
||||||
ScriptableObject.DONTENUM);
|
ScriptableObject.DONTENUM);
|
||||||
|
|
||||||
|
global.history = (NativeArray) cx.newArray(global, 0);
|
||||||
|
global.defineProperty("history", global.history,
|
||||||
|
ScriptableObject.DONTENUM);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: enable debugger
|
TODO: enable debugger
|
||||||
if (global.debug) {
|
if (global.debug) {
|
||||||
|
@ -428,7 +432,7 @@ public class Main extends ScriptableObject {
|
||||||
thread.start();
|
thread.start();
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate JavaScript source.
|
* Evaluate JavaScript source.
|
||||||
*
|
*
|
||||||
|
@ -472,6 +476,8 @@ public class Main extends ScriptableObject {
|
||||||
if (result != cx.getUndefinedValue()) {
|
if (result != cx.getUndefinedValue()) {
|
||||||
System.err.println(cx.toString(result));
|
System.err.println(cx.toString(result));
|
||||||
}
|
}
|
||||||
|
NativeArray h = global.history;
|
||||||
|
h.put((int)h.jsGet_length(), h, source);
|
||||||
}
|
}
|
||||||
catch (WrappedException we) {
|
catch (WrappedException we) {
|
||||||
// Some form of exception was caught by JavaScript and
|
// Some form of exception was caught by JavaScript and
|
||||||
|
@ -579,6 +585,7 @@ public class Main extends ScriptableObject {
|
||||||
boolean debug = false;
|
boolean debug = false;
|
||||||
boolean processStdin = true;
|
boolean processStdin = true;
|
||||||
boolean showDebuggerUI = false;
|
boolean showDebuggerUI = false;
|
||||||
|
NativeArray history;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mozilla.javascript;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ImporterTopLevel
|
||||||
|
*
|
||||||
|
* 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:
|
||||||
|
* <pre>
|
||||||
|
* Scriptable scope = cx.initStandardObjects(new ImporterTopLevel());
|
||||||
|
* </pre>
|
||||||
|
* Then JavaScript code will have access to the following methods:
|
||||||
|
* <ul>
|
||||||
|
* <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
|
||||||
|
* searching for unqualified names as classes qualified
|
||||||
|
* by the given package.
|
||||||
|
* </ul>
|
||||||
|
* The following code from the shell illustrates this use:
|
||||||
|
* <pre>
|
||||||
|
* js> importClass(java.io.File)
|
||||||
|
* js> f = new File('help.txt')
|
||||||
|
* help.txt
|
||||||
|
* js> importPackage(java.util)
|
||||||
|
* js> v = new Vector()
|
||||||
|
* []
|
||||||
|
*
|
||||||
|
* @author Norris Boyd
|
||||||
|
*/
|
||||||
|
public class ImporterTopLevel extends ScriptableObject {
|
||||||
|
|
||||||
|
public ImporterTopLevel() {
|
||||||
|
String[] names = { "importClass", "importPackage" };
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.defineFunctionProperties(names, ImporterTopLevel.class,
|
||||||
|
ScriptableObject.DONTENUM);
|
||||||
|
} catch (PropertyException e) {
|
||||||
|
throw new Error(); // should never happen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClassName() {
|
||||||
|
return "global";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get(String name, Scriptable start) {
|
||||||
|
Object result = super.get(name, start);
|
||||||
|
if (result == NOT_FOUND && importedPackages != null) {
|
||||||
|
for (int i=0; i < importedPackages.size(); i++) {
|
||||||
|
Object o = importedPackages.elementAt(i);
|
||||||
|
NativeJavaPackage p = (NativeJavaPackage) o;
|
||||||
|
Object v = p.get(name, start);
|
||||||
|
if (v != NOT_FOUND) {
|
||||||
|
if (result == NOT_FOUND)
|
||||||
|
result = v;
|
||||||
|
else
|
||||||
|
throw new EvaluatorException("Ambiguous import: " +
|
||||||
|
result + " and " + v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void importClass(Object cl) {
|
||||||
|
if (!(cl instanceof NativeJavaClass))
|
||||||
|
throw new EvaluatorException("not a class");// TODO: better msg
|
||||||
|
String s = ((NativeJavaClass) cl).getClassObject().getName();
|
||||||
|
String n = s.substring(s.lastIndexOf('.')+1);
|
||||||
|
if (this.has(n, this))
|
||||||
|
throw new EvaluatorException("property " + n +
|
||||||
|
" is already defined");
|
||||||
|
this.defineProperty(n, cl, DONTENUM);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void importPackage(Object pkg) {
|
||||||
|
if (importedPackages == null)
|
||||||
|
importedPackages = new Vector();
|
||||||
|
if (!(pkg instanceof NativeJavaPackage))
|
||||||
|
throw new EvaluatorException("not a package");// TODO: better msg
|
||||||
|
importedPackages.addElement(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector importedPackages;
|
||||||
|
}
|
|
@ -178,8 +178,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
/**
|
/**
|
||||||
* See ECMA 15.4.1,2
|
* See ECMA 15.4.1,2
|
||||||
*/
|
*/
|
||||||
public static Object js_Array(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
if (!inNewExpr) {
|
if (!inNewExpr) {
|
||||||
|
@ -205,11 +205,11 @@ public class NativeArray extends ScriptableObject {
|
||||||
private static final int lengthAttr = ScriptableObject.DONTENUM |
|
private static final int lengthAttr = ScriptableObject.DONTENUM |
|
||||||
ScriptableObject.PERMANENT;
|
ScriptableObject.PERMANENT;
|
||||||
|
|
||||||
public long js_getLength() {
|
public long jsGet_length() {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void js_setLength(Object val) {
|
public void jsSet_length(Object val) {
|
||||||
/* XXX do we satisfy this?
|
/* XXX do we satisfy this?
|
||||||
* 15.4.5.1 [[Put]](P, V):
|
* 15.4.5.1 [[Put]](P, V):
|
||||||
* 1. Call the [[CanPut]] method of A with name P.
|
* 1. Call the [[CanPut]] method of A with name P.
|
||||||
|
@ -258,9 +258,9 @@ public class NativeArray extends ScriptableObject {
|
||||||
static double getLengthProperty(Scriptable obj) {
|
static double getLengthProperty(Scriptable obj) {
|
||||||
// These will both give numeric lengths within Uint32 range.
|
// These will both give numeric lengths within Uint32 range.
|
||||||
if (obj instanceof NativeString)
|
if (obj instanceof NativeString)
|
||||||
return (double)((NativeString)obj).js_getLength();
|
return (double)((NativeString)obj).jsGet_length();
|
||||||
if (obj instanceof NativeArray)
|
if (obj instanceof NativeArray)
|
||||||
return (double)((NativeArray)obj).js_getLength();
|
return (double)((NativeArray)obj).jsGet_length();
|
||||||
return ScriptRuntime.toUint32(ScriptRuntime
|
return ScriptRuntime.toUint32(ScriptRuntime
|
||||||
.getProp(obj, "length", obj));
|
.getProp(obj, "length", obj));
|
||||||
}
|
}
|
||||||
|
@ -309,8 +309,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String js_toString(Context cx, Scriptable thisObj,
|
public static String jsFunction_toString(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
return toStringHelper(cx, thisObj,
|
return toStringHelper(cx, thisObj,
|
||||||
cx.getLanguageVersion() == cx.VERSION_1_2);
|
cx.getLanguageVersion() == cx.VERSION_1_2);
|
||||||
|
@ -393,8 +393,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
/**
|
/**
|
||||||
* See ECMA 15.4.4.3
|
* See ECMA 15.4.4.3
|
||||||
*/
|
*/
|
||||||
public static String js_join(Context cx, Scriptable thisObj,
|
public static String jsFunction_join(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuffer result = new StringBuffer();
|
||||||
String separator;
|
String separator;
|
||||||
|
@ -421,8 +421,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
/**
|
/**
|
||||||
* See ECMA 15.4.4.4
|
* See ECMA 15.4.4.4
|
||||||
*/
|
*/
|
||||||
public static Scriptable js_reverse(Context cx, Scriptable thisObj,
|
public static Scriptable jsFunction_reverse(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
long len = (long)getLengthProperty(thisObj);
|
long len = (long)getLengthProperty(thisObj);
|
||||||
|
|
||||||
|
@ -440,8 +440,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
/**
|
/**
|
||||||
* See ECMA 15.4.4.5
|
* See ECMA 15.4.4.5
|
||||||
*/
|
*/
|
||||||
public static Scriptable js_sort(Context cx, Scriptable thisObj,
|
public static Scriptable jsFunction_sort(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
long length = (long)getLengthProperty(thisObj);
|
long length = (long)getLengthProperty(thisObj);
|
||||||
|
@ -605,8 +605,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
* Non-ECMA methods.
|
* Non-ECMA methods.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static Object js_push(Context cx, Scriptable thisObj,
|
public static Object jsFunction_push(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
double length = getLengthProperty(thisObj);
|
double length = getLengthProperty(thisObj);
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
@ -630,8 +630,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
return new Long((long)length);
|
return new Long((long)length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_pop(Context cx, Scriptable thisObj, Object[] args,
|
public static Object jsFunction_pop(Context cx, Scriptable thisObj,
|
||||||
Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
Object result;
|
Object result;
|
||||||
double length = getLengthProperty(thisObj);
|
double length = getLengthProperty(thisObj);
|
||||||
|
@ -653,8 +653,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_shift(Context cx, Scriptable thisObj, Object[] args,
|
public static Object jsFunction_shift(Context cx, Scriptable thisObj,
|
||||||
Function funOjb)
|
Object[] args, Function funOjb)
|
||||||
{
|
{
|
||||||
Object result;
|
Object result;
|
||||||
double length = getLengthProperty(thisObj);
|
double length = getLengthProperty(thisObj);
|
||||||
|
@ -684,8 +684,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_unshift(Context cx, Scriptable thisObj,
|
public static Object jsFunction_unshift(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funOjb)
|
Object[] args, Function funOjb)
|
||||||
{
|
{
|
||||||
Object result;
|
Object result;
|
||||||
double length = (double)getLengthProperty(thisObj);
|
double length = (double)getLengthProperty(thisObj);
|
||||||
|
@ -713,8 +713,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
return new Long((long)length);
|
return new Long((long)length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_splice(Context cx, Scriptable thisObj,
|
public static Object jsFunction_splice(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
/* create an empty Array to return. */
|
/* create an empty Array to return. */
|
||||||
Scriptable scope = getTopLevelScope(funObj);
|
Scriptable scope = getTopLevelScope(funObj);
|
||||||
|
@ -820,8 +820,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
/*
|
/*
|
||||||
* Python-esque sequence operations.
|
* Python-esque sequence operations.
|
||||||
*/
|
*/
|
||||||
public static Scriptable js_concat(Context cx, Scriptable thisObj,
|
public static Scriptable jsFunction_concat(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
/* Concat tries to keep the definition of an array as general
|
/* Concat tries to keep the definition of an array as general
|
||||||
* as possible; if it finds that an object has a numeric
|
* as possible; if it finds that an object has a numeric
|
||||||
|
@ -873,8 +873,8 @@ public class NativeArray extends ScriptableObject {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Scriptable js_slice(Context cx, Scriptable thisObj,
|
public static Scriptable jsFunction_slice(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
Scriptable scope = getTopLevelScope(funObj);
|
Scriptable scope = getTopLevelScope(funObj);
|
||||||
Scriptable result = ScriptRuntime.newObject(cx, scope, "Array", null);
|
Scriptable result = ScriptRuntime.newObject(cx, scope, "Array", null);
|
||||||
|
|
|
@ -47,8 +47,8 @@ public class NativeBoolean extends ScriptableObject {
|
||||||
return super.getDefaultValue(typeHint);
|
return super.getDefaultValue(typeHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object Boolean(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
boolean b = args.length >= 1
|
boolean b = args.length >= 1
|
||||||
? ScriptRuntime.toBoolean(args[0])
|
? ScriptRuntime.toBoolean(args[0])
|
||||||
|
@ -62,11 +62,11 @@ public class NativeBoolean extends ScriptableObject {
|
||||||
return b ? Boolean.TRUE : Boolean.FALSE;
|
return b ? Boolean.TRUE : Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String jsFunction_toString() {
|
||||||
return booleanValue ? "true" : "false";
|
return booleanValue ? "true" : "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean valueOf() {
|
public boolean jsFunction_valueOf() {
|
||||||
return booleanValue;
|
return booleanValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,8 @@ public final class NativeCall extends ScriptableObject {
|
||||||
return "Call";
|
return "Call";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_Call(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
if (!inNewExpr) {
|
if (!inNewExpr) {
|
||||||
Object[] errArgs = { "Call" };
|
Object[] errArgs = { "Call" };
|
||||||
|
|
|
@ -779,8 +779,8 @@ public class NativeDate extends ScriptableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the javascript constructor */
|
/* the javascript constructor */
|
||||||
public static Object js_Date(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
// if called as a function, just return a string
|
// if called as a function, just return a string
|
||||||
// representing the current time.
|
// representing the current time.
|
||||||
|
@ -860,7 +860,7 @@ public class NativeDate extends ScriptableObject {
|
||||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||||
};
|
};
|
||||||
|
|
||||||
public String js_toString() {
|
public String jsFunction_toString() {
|
||||||
/* all for want of printf. All of this garbage seems necessary
|
/* all for want of printf. All of this garbage seems necessary
|
||||||
* because Java carefully avoids providing non-localized
|
* because Java carefully avoids providing non-localized
|
||||||
* string formatting. We need to avoid localization to ensure
|
* string formatting. We need to avoid localization to ensure
|
||||||
|
@ -872,7 +872,7 @@ public class NativeDate extends ScriptableObject {
|
||||||
return date_format(this.date);
|
return date_format(this.date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_toLocaleString() {
|
public String jsFunction_toLocaleString() {
|
||||||
if (this.date != this.date)
|
if (this.date != this.date)
|
||||||
return js_NaN_date_str;
|
return js_NaN_date_str;
|
||||||
|
|
||||||
|
@ -883,7 +883,7 @@ public class NativeDate extends ScriptableObject {
|
||||||
return localeDateFormatter.format(tempdate);
|
return localeDateFormatter.format(tempdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_toUTCString() {
|
public String jsFunction_toUTCString() {
|
||||||
if (this.date != this.date)
|
if (this.date != this.date)
|
||||||
return js_NaN_date_str;
|
return js_NaN_date_str;
|
||||||
|
|
||||||
|
@ -932,7 +932,7 @@ public class NativeDate extends ScriptableObject {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double js_valueOf() {
|
public double jsFunction_valueOf() {
|
||||||
return this.date;
|
return this.date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
|
|
||||||
public String decompile(int indent, boolean toplevel, boolean justbody) {
|
public String decompile(int indent, boolean toplevel, boolean justbody) {
|
||||||
if (source == null)
|
if (source == null)
|
||||||
return "function " + js_getName() +
|
return "function " + jsGet_name() +
|
||||||
"() {\n\t[native code]\n}\n";
|
"() {\n\t[native code]\n}\n";
|
||||||
|
|
||||||
// Spew tokens in source, for debugging.
|
// Spew tokens in source, for debugging.
|
||||||
|
@ -820,8 +820,8 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_toString(Context cx, Scriptable thisObj,
|
public static Object jsFunction_toString(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
||||||
if (!(val instanceof NativeFunction)) {
|
if (!(val instanceof NativeFunction)) {
|
||||||
|
@ -837,8 +837,8 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
return ((NativeFunction) val).decompile(indent, true, false);
|
return ((NativeFunction) val).decompile(indent, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Scriptable js_Function(Context cx, Object[] args,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
Function ctorObj, boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
int arglen = args.length;
|
int arglen = args.length;
|
||||||
StringBuffer funArgs = new StringBuffer();
|
StringBuffer funArgs = new StringBuffer();
|
||||||
|
@ -892,12 +892,12 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
*
|
*
|
||||||
* A proposed ECMA extension for round 2.
|
* A proposed ECMA extension for round 2.
|
||||||
*/
|
*/
|
||||||
public static Object js_apply(Context cx, Scriptable thisObj,
|
public static Object jsFunction_apply(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
if (args.length != 2)
|
if (args.length != 2)
|
||||||
return js_call(cx, thisObj, args, funObj);
|
return jsFunction_call(cx, thisObj, args, funObj);
|
||||||
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
||||||
Scriptable newThis = args[0] == null
|
Scriptable newThis = args[0] == null
|
||||||
? null
|
? null
|
||||||
|
@ -911,8 +911,8 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
*
|
*
|
||||||
* A proposed ECMA extension for round 2.
|
* A proposed ECMA extension for round 2.
|
||||||
*/
|
*/
|
||||||
public static Object js_call(Context cx, Scriptable thisObj,
|
public static Object jsFunction_call(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
|
||||||
|
@ -931,7 +931,7 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int js_getLength() {
|
public int jsGet_length() {
|
||||||
Context cx = Context.getContext();
|
Context cx = Context.getContext();
|
||||||
if (cx.getLanguageVersion() != Context.VERSION_1_2)
|
if (cx.getLanguageVersion() != Context.VERSION_1_2)
|
||||||
return argCount;
|
return argCount;
|
||||||
|
@ -941,11 +941,11 @@ public class NativeFunction extends ScriptableObject implements Function {
|
||||||
return activation.getOriginalArguments().length;
|
return activation.getOriginalArguments().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int js_getArity() {
|
public int jsGet_arity() {
|
||||||
return argCount;
|
return argCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_getName() {
|
public String jsGet_name() {
|
||||||
if (names != null && names[0].length() > 0)
|
if (names != null && names[0].length() > 0)
|
||||||
return names[0];
|
return names[0];
|
||||||
|
|
||||||
|
|
|
@ -47,9 +47,6 @@ public class NativeJavaPackage extends ScriptableObject {
|
||||||
"java.text",
|
"java.text",
|
||||||
"java.text.resources",
|
"java.text.resources",
|
||||||
"java.applet",
|
"java.applet",
|
||||||
"netscape.security",
|
|
||||||
"netscape.plugin",
|
|
||||||
"netscape.application",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Scriptable init(Scriptable scope)
|
public static Scriptable init(Scriptable scope)
|
||||||
|
|
|
@ -59,8 +59,8 @@ public class NativeNumber extends ScriptableObject {
|
||||||
return "Number";
|
return "Number";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object Number(Context cx, Object[] args, Function funObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function funObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
double d = args.length >= 1
|
double d = args.length >= 1
|
||||||
? ScriptRuntime.toNumber(args[0])
|
? ScriptRuntime.toNumber(args[0])
|
||||||
|
@ -72,17 +72,20 @@ public class NativeNumber extends ScriptableObject {
|
||||||
// Number(val) converts val to a number value.
|
// Number(val) converts val to a number value.
|
||||||
return new Double(d);
|
return new Double(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(Object base) {
|
public String toString() {
|
||||||
if (base == Undefined.instance)
|
return jsFunction_toString(Undefined.instance);
|
||||||
return ScriptRuntime.numberToString(doubleValue, 10);
|
|
||||||
else
|
|
||||||
return ScriptRuntime.numberToString(doubleValue,
|
|
||||||
ScriptRuntime.toInt32(base));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double valueOf() {
|
public String jsFunction_toString(Object base) {
|
||||||
return doubleValue;
|
int i = base == Undefined.instance
|
||||||
|
? 10
|
||||||
|
: ScriptRuntime.toInt32(base);
|
||||||
|
return ScriptRuntime.numberToString(doubleValue, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double jsFunction_valueOf() {
|
||||||
|
return doubleValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final double defaultValue = +0.0;
|
private static final double defaultValue = +0.0;
|
||||||
|
|
|
@ -38,8 +38,8 @@ public class NativeObject extends ScriptableObject {
|
||||||
return "Object";
|
return "Object";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_Object(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
if (!inNewExpr) {
|
if (!inNewExpr) {
|
||||||
|
@ -57,13 +57,13 @@ public class NativeObject extends ScriptableObject {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
Context cx = Context.getContext();
|
Context cx = Context.getContext();
|
||||||
if (cx != null)
|
if (cx != null)
|
||||||
return js_toString(cx, this, null, null);
|
return jsFunction_toString(cx, this, null, null);
|
||||||
else
|
else
|
||||||
return "[object " + getClassName() + "]";
|
return "[object " + getClassName() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String js_toString(Context cx, Scriptable thisObj,
|
public static String jsFunction_toString(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (cx.getLanguageVersion() != cx.VERSION_1_2)
|
if (cx.getLanguageVersion() != cx.VERSION_1_2)
|
||||||
return "[object " + thisObj.getClassName() + "]";
|
return "[object " + thisObj.getClassName() + "]";
|
||||||
|
@ -118,8 +118,8 @@ public class NativeObject extends ScriptableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_valueOf(Context cx, Scriptable thisObj,
|
public static Object jsFunction_valueOf(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
return thisObj;
|
return thisObj;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,8 @@ public class NativeScript extends NativeFunction implements Script {
|
||||||
* The Java method defining the JavaScript Script constructor.
|
* The Java method defining the JavaScript Script constructor.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static Object js_Script(Context cx, Object[] args,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
Function ctorObj, boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
String source = args.length == 0
|
String source = args.length == 0
|
||||||
? ""
|
? ""
|
||||||
|
@ -95,19 +95,19 @@ public class NativeScript extends NativeFunction implements Script {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Scriptable js_compile(String source) {
|
public Scriptable jsFunction_compile(String source) {
|
||||||
script = compile(null, source);
|
script = compile(null, source);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object js_exec() throws JavaScriptException {
|
public Object jsFunction_exec() throws JavaScriptException {
|
||||||
Object[] msgArgs = { "exec" };
|
Object[] msgArgs = { "exec" };
|
||||||
throw Context.reportRuntimeError(
|
throw Context.reportRuntimeError(
|
||||||
Context.getMessage("msg.cant.call.indirect", msgArgs));
|
Context.getMessage("msg.cant.call.indirect", msgArgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_toString(Context cx, Scriptable thisObj,
|
public static Object jsFunction_toString(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
Script thisScript = ((NativeScript) thisObj).script;
|
Script thisScript = ((NativeScript) thisObj).script;
|
||||||
if (thisScript == null)
|
if (thisScript == null)
|
||||||
|
@ -119,7 +119,7 @@ public class NativeScript extends NativeFunction implements Script {
|
||||||
/*
|
/*
|
||||||
* Override method in NativeFunction to avoid ever returning "anonymous"
|
* Override method in NativeFunction to avoid ever returning "anonymous"
|
||||||
*/
|
*/
|
||||||
public String js_getName() {
|
public String jsGet_name() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,8 +97,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
return s.toString();
|
return s.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_String(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
String s = args.length >= 1
|
String s = args.length >= 1
|
||||||
? ScriptRuntime.toString(args[0])
|
? ScriptRuntime.toString(args[0])
|
||||||
|
@ -116,11 +116,11 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ECMA 15.5.4.2: 'the toString function is not generic.' */
|
/* ECMA 15.5.4.2: 'the toString function is not generic.' */
|
||||||
public String js_toString() {
|
public String jsFunction_toString() {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_valueOf() {
|
public String jsFunction_valueOf() {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,8 +143,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
*
|
*
|
||||||
* See ECMA 15.5.4.[4,5]
|
* See ECMA 15.5.4.[4,5]
|
||||||
*/
|
*/
|
||||||
public static String js_charAt(Context cx, Scriptable thisObj,
|
public static String jsFunction_charAt(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
args = ScriptRuntime.padArguments(args, 1);
|
args = ScriptRuntime.padArguments(args, 1);
|
||||||
|
@ -160,8 +160,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
return target.substring((int)pos, (int)pos + 1);
|
return target.substring((int)pos, (int)pos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double js_charCodeAt(Context cx, Scriptable thisObj,
|
public static double jsFunction_charCodeAt(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
args = ScriptRuntime.padArguments(args, 1);
|
args = ScriptRuntime.padArguments(args, 1);
|
||||||
|
@ -181,8 +181,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
* See ECMA 15.5.4.6. Uses Java String.indexOf()
|
* See ECMA 15.5.4.6. Uses Java String.indexOf()
|
||||||
* OPT to add - BMH searching from jsstr.c.
|
* OPT to add - BMH searching from jsstr.c.
|
||||||
*/
|
*/
|
||||||
public static int js_indexOf(Context cx, Scriptable thisObj,
|
public static int jsFunction_indexOf(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (args.length < 2)
|
if (args.length < 2)
|
||||||
args = ScriptRuntime.padArguments(args, 2);
|
args = ScriptRuntime.padArguments(args, 2);
|
||||||
|
@ -205,8 +205,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
* See ECMA 15.5.4.7
|
* See ECMA 15.5.4.7
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static int js_lastIndexOf(Context cx, Scriptable thisObj,
|
public static int jsFunction_lastIndexOf(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (args.length < 2)
|
if (args.length < 2)
|
||||||
args = ScriptRuntime.padArguments(args, 2);
|
args = ScriptRuntime.padArguments(args, 2);
|
||||||
|
@ -350,8 +350,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
* a limit argument and accepts a regular expression as the split
|
* a limit argument and accepts a regular expression as the split
|
||||||
* argument.
|
* argument.
|
||||||
*/
|
*/
|
||||||
public static Object js_split(Context cx, Scriptable thisObj,
|
public static Object jsFunction_split(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
String target = ScriptRuntime.toString(thisObj);
|
String target = ScriptRuntime.toString(thisObj);
|
||||||
|
|
||||||
|
@ -446,8 +446,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
*
|
*
|
||||||
* See ECMA 15.5.4.[9,10]
|
* See ECMA 15.5.4.[9,10]
|
||||||
*/
|
*/
|
||||||
public static String js_substring(Context cx, Scriptable thisObj,
|
public static String jsFunction_substring(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
args = ScriptRuntime.padArguments(args, 1);
|
args = ScriptRuntime.padArguments(args, 1);
|
||||||
|
@ -490,29 +490,29 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
*
|
*
|
||||||
* See ECMA 15.5.4.[11,12]
|
* See ECMA 15.5.4.[11,12]
|
||||||
*/
|
*/
|
||||||
public static String js_toLowerCase(Context cx, Scriptable thisObj,
|
public static String jsFunction_toLowerCase(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
String target = ScriptRuntime.toString(thisObj);
|
String target = ScriptRuntime.toString(thisObj);
|
||||||
return target.toLowerCase();
|
return target.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String js_toUpperCase(Context cx, Scriptable thisObj,
|
public static String jsFunction_toUpperCase(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
String target = ScriptRuntime.toString(thisObj);
|
String target = ScriptRuntime.toString(thisObj);
|
||||||
return target.toUpperCase();
|
return target.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double js_getLength() {
|
public double jsGet_length() {
|
||||||
return (double) string.length();
|
return (double) string.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-ECMA methods.
|
* Non-ECMA methods.
|
||||||
*/
|
*/
|
||||||
public static String js_substr(Context cx, Scriptable thisObj,
|
public static String jsFunction_substr(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
String target = ScriptRuntime.toString(thisObj);
|
String target = ScriptRuntime.toString(thisObj);
|
||||||
|
|
||||||
|
@ -548,8 +548,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
/**
|
/**
|
||||||
* Python-esque sequence operations.
|
* Python-esque sequence operations.
|
||||||
*/
|
*/
|
||||||
public static String js_concat(Context cx, Scriptable thisObj,
|
public static String jsFunction_concat(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuffer result = new StringBuffer();
|
||||||
result.append(ScriptRuntime.toString(thisObj));
|
result.append(ScriptRuntime.toString(thisObj));
|
||||||
|
@ -560,8 +560,8 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String js_slice(Context cx, Scriptable thisObj,
|
public static String jsFunction_slice(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
{
|
{
|
||||||
String target = ScriptRuntime.toString(thisObj);
|
String target = ScriptRuntime.toString(thisObj);
|
||||||
|
|
||||||
|
@ -615,55 +615,55 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_bold() {
|
public String jsFunction_bold() {
|
||||||
return tagify("B", null, null);
|
return tagify("B", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_italics() {
|
public String jsFunction_italics() {
|
||||||
return tagify("I", null, null);
|
return tagify("I", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_fixed() {
|
public String jsFunction_fixed() {
|
||||||
return tagify("TT", null, null);
|
return tagify("TT", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_strike() {
|
public String jsFunction_strike() {
|
||||||
return tagify("STRIKE", null, null);
|
return tagify("STRIKE", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_small() {
|
public String jsFunction_small() {
|
||||||
return tagify("SMALL", null, null);
|
return tagify("SMALL", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_big() {
|
public String jsFunction_big() {
|
||||||
return tagify("BIG", null, null);
|
return tagify("BIG", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_blink() {
|
public String jsFunction_blink() {
|
||||||
return tagify("BLINK", null, null);
|
return tagify("BLINK", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_sup() {
|
public String jsFunction_sup() {
|
||||||
return tagify("SUP", null, null);
|
return tagify("SUP", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_sub() {
|
public String jsFunction_sub() {
|
||||||
return tagify("SUB", null, null);
|
return tagify("SUB", null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_fontsize(String value) {
|
public String jsFunction_fontsize(String value) {
|
||||||
return tagify("FONT SIZE", "FONT", value);
|
return tagify("FONT SIZE", "FONT", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_fontcolor(String value) {
|
public String jsFunction_fontcolor(String value) {
|
||||||
return tagify("FONT COLOR", "FONT", value);
|
return tagify("FONT COLOR", "FONT", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_link(String value) {
|
public String jsFunction_link(String value) {
|
||||||
return tagify("A HREF", "A", value);
|
return tagify("A HREF", "A", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String js_anchor(String value) {
|
public String jsFunction_anchor(String value) {
|
||||||
return tagify("A NAME", "A", value);
|
return tagify("A NAME", "A", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -675,22 +675,22 @@ public class NativeString extends ScriptableObject implements Wrapper {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_match(Context cx, Scriptable thisObj,
|
public static Object jsFunction_match(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
return checkReProxy(cx).match(cx, thisObj, args, funObj);
|
return checkReProxy(cx).match(cx, thisObj, args, funObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_search(Context cx, Scriptable thisObj,
|
public static Object jsFunction_search(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
return checkReProxy(cx).search(cx, thisObj, args, funObj);
|
return checkReProxy(cx).search(cx, thisObj, args, funObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object js_replace(Context cx, Scriptable thisObj,
|
public static Object jsFunction_replace(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws JavaScriptException
|
throws JavaScriptException
|
||||||
{
|
{
|
||||||
return checkReProxy(cx).replace(cx, thisObj, args, funObj);
|
return checkReProxy(cx).replace(cx, thisObj, args, funObj);
|
||||||
|
|
|
@ -31,7 +31,8 @@ public class NativeWith implements Scriptable {
|
||||||
public static void init(Scriptable scope) {
|
public static void init(Scriptable scope) {
|
||||||
NativeWith w = new NativeWith();
|
NativeWith w = new NativeWith();
|
||||||
w.setPrototype(ScriptableObject.getObjectPrototype(scope));
|
w.setPrototype(ScriptableObject.getObjectPrototype(scope));
|
||||||
Method[] m = FunctionObject.findMethods(NativeWith.class, "With");
|
Method[] m = FunctionObject.findMethods(NativeWith.class,
|
||||||
|
"jsConstructor");
|
||||||
FunctionObject f = new FunctionObject("With", m[0], scope);
|
FunctionObject f = new FunctionObject("With", m[0], scope);
|
||||||
f.addAsConstructor(scope, w);
|
f.addAsConstructor(scope, w);
|
||||||
}
|
}
|
||||||
|
@ -120,8 +121,8 @@ public class NativeWith implements Scriptable {
|
||||||
return prototype.hasInstance(value);
|
return prototype.hasInstance(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object With(Context cx, Object[] args, Function ctorObj,
|
public static Object jsConstructor(Context cx, Object[] args,
|
||||||
boolean inNewExpr)
|
Function ctorObj, boolean inNewExpr)
|
||||||
{
|
{
|
||||||
Object[] msgArgs = { "With" };
|
Object[] msgArgs = { "With" };
|
||||||
throw Context.reportRuntimeError(
|
throw Context.reportRuntimeError(
|
||||||
|
|
|
@ -119,7 +119,6 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
* @param start the object in which the lookup began
|
* @param start the object in which the lookup began
|
||||||
* @return the value of the property (may be null), or NOT_FOUND
|
* @return the value of the property (may be null), or NOT_FOUND
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Object get(String name, Scriptable start) {
|
public Object get(String name, Scriptable start) {
|
||||||
int hashCode;
|
int hashCode;
|
||||||
if (name == lastName) {
|
if (name == lastName) {
|
||||||
|
@ -127,7 +126,7 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
return lastValue;
|
return lastValue;
|
||||||
hashCode = lastHash;
|
hashCode = lastHash;
|
||||||
} else {
|
} else {
|
||||||
hashCode = name.hashCode();
|
hashCode = name.hashCode();
|
||||||
}
|
}
|
||||||
int slotIndex = getSlot(name, hashCode);
|
int slotIndex = getSlot(name, hashCode);
|
||||||
if (slotIndex == SLOT_NOT_FOUND)
|
if (slotIndex == SLOT_NOT_FOUND)
|
||||||
|
@ -593,50 +592,43 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
* methods are used to initialize a class in the following manner.<p>
|
* methods are used to initialize a class in the following manner.<p>
|
||||||
*
|
*
|
||||||
* First, the zero-parameter constructor of the class is called to
|
* First, the zero-parameter constructor of the class is called to
|
||||||
* create the prototypical instance. If no such constructor exists,
|
* create the prototype. If no such constructor exists,
|
||||||
* a ClassDefinitionException is thrown. <p>
|
* a ClassDefinitionException is thrown. <p>
|
||||||
*
|
*
|
||||||
* Next, all methods are scanned. If any method
|
* Next, all methods are scanned for special prefixes that indicate that they
|
||||||
* begins with a special prefix, then only methods with
|
* have special meaning for defining JavaScript objects.
|
||||||
* special prefixes are considered for defining functions
|
* These special prefixes are
|
||||||
* and properties. These special prefixes are
|
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><code>js_</code> for a JavaScript property or function, as
|
|
||||||
* determined by the name of the method
|
|
||||||
* <li><code>jsFunction_</code> for a JavaScript function
|
* <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
|
* is a property of the constructor
|
||||||
* <li><code>jsProperty_</code> for a JavaScript property
|
* <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
|
||||||
|
* is the constructor
|
||||||
* </ul><p>
|
* </ul><p>
|
||||||
*
|
*
|
||||||
* If no methods begin with any of these prefixes, all methods
|
* If the method's name begins with "jsFunction_", a JavaScript function
|
||||||
* are added as JavaScript functions or properties except
|
* is created with a name formed from the rest of the Java method name
|
||||||
* those with names matching the names of methods in
|
* following "jsFunction_". So a Java method named "jsFunction_foo" will
|
||||||
* <code>org.mozilla.javascript.Function</code>
|
* define a JavaScript method "foo". Calling this JavaScript function
|
||||||
* or any of its supertypes. This means that
|
* will cause the Java method to be called. The parameters of the method
|
||||||
* <code>call</code>, which is a method in Function, and
|
* must be of number and types as defined by the FunctionObject class.
|
||||||
* <code>get</code>, which is a method in Scriptable
|
* The JavaScript function is then added as a property
|
||||||
* (which Function extends), are both excluded from
|
* of the prototype. <p>
|
||||||
* defining JavaScript methods.<p>
|
*
|
||||||
*
|
* If the method's name begins with "jsStaticFunction_", it is handled
|
||||||
* If after removing any prefixes, a method's name matches the name of
|
* similarly except that the resulting JavaScript function is added as a
|
||||||
* the class (determined by calling <code>getClassName()</code>
|
* property of the constructor object. The Java method must be static.
|
||||||
* on the prototypical instance), it is considered to define the
|
*
|
||||||
* JavaScript constructor.<p>
|
* If the method's name begins with "jsGet_" or "jsSet_", the method is
|
||||||
*
|
|
||||||
* If the method's name begins with "get" or "set" after
|
|
||||||
* any prefix other than "jsFunction_" is removed, the method is
|
|
||||||
* considered to define a property. Accesses to the defined property
|
* considered to define a property. Accesses to the defined property
|
||||||
* will result in calls to these getter and setter methods. If no
|
* will result in calls to these getter and setter methods. If no
|
||||||
* setter is defined, the property is defined as READONLY.<p>
|
* setter is defined, the property is defined as READONLY.<p>
|
||||||
*
|
*
|
||||||
* Otherwise, a JavaScript function is created that will call the
|
* If the method's name is "jsConstructor", the method is
|
||||||
* given method. This function is then added as a property
|
* considered to define the body of the constructor. Only one
|
||||||
* of the prototypical instance. So if a JavaScript
|
* method of this name may be defined.
|
||||||
* function beginning with "get" or "set" is desired, it must be
|
|
||||||
* prefixed with "jsFunction_" to distinquish it from a method
|
|
||||||
* defining a property.<p>
|
|
||||||
*
|
|
||||||
* If no method is found that can serve as constructor, a Java
|
* If no method is found that can serve as constructor, a Java
|
||||||
* constructor will be selected to serve as the JavaScript
|
* constructor will be selected to serve as the JavaScript
|
||||||
* constructor in the following manner. If the class has only one
|
* constructor in the following manner. If the class has only one
|
||||||
|
@ -644,7 +636,7 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
* the JavaScript constructor. If the the class has two constructors,
|
* the JavaScript constructor. If the the class has two constructors,
|
||||||
* one must be the zero-argument constructor (otherwise an
|
* one must be the zero-argument constructor (otherwise an
|
||||||
* ClassDefinitionException would have already been thrown
|
* ClassDefinitionException would have already been thrown
|
||||||
* when the prototypical instance was to be created). In this case
|
* when the prototype was to be created). In this case
|
||||||
* the Java constructor with one or more parameters will be used
|
* the Java constructor with one or more parameters will be used
|
||||||
* to define the JavaScript constructor. If the class has three
|
* to define the JavaScript constructor. If the class has three
|
||||||
* or more constructors, an ClassDefinitionException
|
* or more constructors, an ClassDefinitionException
|
||||||
|
@ -669,8 +661,7 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
* @exception InvocationTargetException if an exception is thrown
|
* @exception InvocationTargetException if an exception is thrown
|
||||||
* during execution of methods of the named class
|
* during execution of methods of the named class
|
||||||
* @exception ClassDefinitionException if an appropriate
|
* @exception ClassDefinitionException if an appropriate
|
||||||
* constructor cannot be found to create the prototypical
|
* constructor cannot be found to create the prototype
|
||||||
* instance
|
|
||||||
* @exception PropertyException if getter and setter
|
* @exception PropertyException if getter and setter
|
||||||
* methods do not conform to the requirements of the
|
* methods do not conform to the requirements of the
|
||||||
* defineProperty method
|
* defineProperty method
|
||||||
|
@ -709,8 +700,7 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
* @exception InvocationTargetException if an exception is thrown
|
* @exception InvocationTargetException if an exception is thrown
|
||||||
* during execution of methods of the named class
|
* during execution of methods of the named class
|
||||||
* @exception ClassDefinitionException if an appropriate
|
* @exception ClassDefinitionException if an appropriate
|
||||||
* constructor cannot be found to create the prototypical
|
* constructor cannot be found to create the prototype
|
||||||
* instance
|
|
||||||
* @exception PropertyException if getter and setter
|
* @exception PropertyException if getter and setter
|
||||||
* methods do not conform to the requirements of the
|
* methods do not conform to the requirements of the
|
||||||
* defineProperty method
|
* defineProperty method
|
||||||
|
@ -763,13 +753,29 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
// Find out whether there are any methods that begin with
|
// Find out whether there are any methods that begin with
|
||||||
// "js". If so, then only methods that begin with special
|
// "js". If so, then only methods that begin with special
|
||||||
// prefixes will be defined as JavaScript entities.
|
// prefixes will be defined as JavaScript entities.
|
||||||
|
// The prefixes "js_" and "jsProperty_" are deprecated.
|
||||||
final String genericPrefix = "js_";
|
final String genericPrefix = "js_";
|
||||||
final String functionPrefix = "jsFunction_";
|
final String functionPrefix = "jsFunction_";
|
||||||
final String staticFunctionPrefix = "jsStaticFunction_";
|
final String staticFunctionPrefix = "jsStaticFunction_";
|
||||||
final String propertyPrefix = "jsProperty_";
|
final String propertyPrefix = "jsProperty_";
|
||||||
|
final String getterPrefix = "jsGet_";
|
||||||
|
final String setterPrefix = "jsSet_";
|
||||||
|
|
||||||
boolean hasPrefix = false;
|
Method[] ctorMeths = FunctionObject.findMethods(clazz,
|
||||||
|
"jsConstructor");
|
||||||
Member ctorMember = null;
|
Member ctorMember = null;
|
||||||
|
if (ctorMeths != null) {
|
||||||
|
if (ctorMeths.length > 1) {
|
||||||
|
Object[] args = { ctorMeths[0], ctorMeths[1] };
|
||||||
|
throw new ClassDefinitionException(
|
||||||
|
Context.getMessage("msg.multiple.ctors", args));
|
||||||
|
}
|
||||||
|
ctorMember = ctorMeths[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: look for functions with the same name as the class
|
||||||
|
// and consider them constructors.
|
||||||
|
boolean hasPrefix = false;
|
||||||
for (int i=0; i < methods.length; i++) {
|
for (int i=0; i < methods.length; i++) {
|
||||||
String name = methods[i].getName();
|
String name = methods[i].getName();
|
||||||
String prefix = null;
|
String prefix = null;
|
||||||
|
@ -781,8 +787,6 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
prefix = functionPrefix;
|
prefix = functionPrefix;
|
||||||
else if (name.startsWith(staticFunctionPrefix))
|
else if (name.startsWith(staticFunctionPrefix))
|
||||||
prefix = staticFunctionPrefix;
|
prefix = staticFunctionPrefix;
|
||||||
else if (name.startsWith(propertyPrefix))
|
|
||||||
prefix = propertyPrefix;
|
|
||||||
if (prefix != null) {
|
if (prefix != null) {
|
||||||
hasPrefix = true;
|
hasPrefix = true;
|
||||||
name = name.substring(prefix.length());
|
name = name.substring(prefix.length());
|
||||||
|
@ -816,9 +820,11 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
FunctionObject ctor = new FunctionObject(className, ctorMember, scope);
|
FunctionObject ctor = new FunctionObject(className, ctorMember, scope);
|
||||||
ctor.addAsConstructor(scope, proto);
|
ctor.addAsConstructor(scope, proto);
|
||||||
|
|
||||||
|
if (!hasPrefix && exclusionList == null)
|
||||||
|
exclusionList = getExclusionList();
|
||||||
Method finishInit = null;
|
Method finishInit = null;
|
||||||
for (int i=0; i < methods.length; i++) {
|
for (int i=0; i < methods.length; i++) {
|
||||||
if (methods[i].getDeclaringClass() != clazz)
|
if (!hasPrefix && methods[i].getDeclaringClass() != clazz)
|
||||||
continue;
|
continue;
|
||||||
String name = methods[i].getName();
|
String name = methods[i].getName();
|
||||||
if (name.equals("finishInit")) {
|
if (name.equals("finishInit")) {
|
||||||
|
@ -836,13 +842,10 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
String prefix = null;
|
String prefix = null;
|
||||||
if (hasPrefix) {
|
if (hasPrefix) {
|
||||||
if (name.startsWith(genericPrefix)) {
|
if (name.startsWith(genericPrefix)) {
|
||||||
name = name.substring(genericPrefix.length());
|
|
||||||
prefix = genericPrefix;
|
prefix = genericPrefix;
|
||||||
} else if (name.startsWith(functionPrefix)) {
|
} else if (name.startsWith(functionPrefix)) {
|
||||||
name = name.substring(functionPrefix.length());
|
|
||||||
prefix = functionPrefix;
|
prefix = functionPrefix;
|
||||||
} else if (name.startsWith(staticFunctionPrefix)) {
|
} else if (name.startsWith(staticFunctionPrefix)) {
|
||||||
name = name.substring(staticFunctionPrefix.length());
|
|
||||||
prefix = staticFunctionPrefix;
|
prefix = staticFunctionPrefix;
|
||||||
if (!Modifier.isStatic(methods[i].getModifiers())) {
|
if (!Modifier.isStatic(methods[i].getModifiers())) {
|
||||||
throw new ClassDefinitionException(
|
throw new ClassDefinitionException(
|
||||||
|
@ -851,16 +854,47 @@ public abstract class ScriptableObject implements Scriptable {
|
||||||
} else if (name.startsWith(propertyPrefix)) {
|
} else if (name.startsWith(propertyPrefix)) {
|
||||||
name = name.substring(propertyPrefix.length());
|
name = name.substring(propertyPrefix.length());
|
||||||
prefix = propertyPrefix;
|
prefix = propertyPrefix;
|
||||||
|
} else if (name.startsWith(getterPrefix)) {
|
||||||
|
prefix = getterPrefix;
|
||||||
|
} else if (name.startsWith(setterPrefix)) {
|
||||||
|
prefix = setterPrefix;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
name = name.substring(prefix.length());
|
||||||
} else if (exclusionList.get(name) != null)
|
} else if (exclusionList.get(name) != null)
|
||||||
continue;
|
continue;
|
||||||
if (methods[i] == ctorMember) {
|
if (methods[i] == ctorMember) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((name.startsWith("get") || name.startsWith("set"))
|
if (prefix != null && prefix.equals(setterPrefix))
|
||||||
&& name.length() > 3 &&
|
continue; // deal with set when we see get
|
||||||
|
if (prefix != null && prefix.equals(getterPrefix)) {
|
||||||
|
if (!(proto instanceof ScriptableObject)) {
|
||||||
|
Object[] args = { proto.getClass().toString(), name };
|
||||||
|
throw new PropertyException(
|
||||||
|
Context.getMessage("msg.extend.scriptable", args));
|
||||||
|
}
|
||||||
|
Method[] setter = FunctionObject.findMethods(
|
||||||
|
clazz,
|
||||||
|
setterPrefix + name);
|
||||||
|
if (setter != null && setter.length != 1) {
|
||||||
|
Object[] errArgs = { name, clazz.getName() };
|
||||||
|
throw new PropertyException(
|
||||||
|
Context.getMessage("msg.no.overload", errArgs));
|
||||||
|
}
|
||||||
|
int attr = ScriptableObject.PERMANENT |
|
||||||
|
ScriptableObject.DONTENUM |
|
||||||
|
(setter != null ? 0
|
||||||
|
: ScriptableObject.READONLY);
|
||||||
|
Method m = setter == null ? null : setter[0];
|
||||||
|
((ScriptableObject) proto).defineProperty(name, null,
|
||||||
|
methods[i], m,
|
||||||
|
attr);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((name.startsWith("get") || name.startsWith("set")) &&
|
||||||
|
name.length() > 3 &&
|
||||||
!(hasPrefix && (prefix.equals(functionPrefix) ||
|
!(hasPrefix && (prefix.equals(functionPrefix) ||
|
||||||
prefix.equals(staticFunctionPrefix))))
|
prefix.equals(staticFunctionPrefix))))
|
||||||
{
|
{
|
||||||
|
|
|
@ -203,7 +203,7 @@ public class NativeRegExp extends ScriptableObject implements Function {
|
||||||
boolean test, Function funObj)
|
boolean test, Function funObj)
|
||||||
{
|
{
|
||||||
if (!(thisObj instanceof NativeRegExp)) {
|
if (!(thisObj instanceof NativeRegExp)) {
|
||||||
Object[] errArgs = { ((NativeFunction) funObj).js_getName() };
|
Object[] errArgs = { ((NativeFunction) funObj).jsGet_name() };
|
||||||
throw Context.reportRuntimeError(
|
throw Context.reportRuntimeError(
|
||||||
ScriptRuntime.getMessage("msg.incompat.call", errArgs));
|
ScriptRuntime.getMessage("msg.incompat.call", errArgs));
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.mozilla.javascript.debug.SourceTextManagerImpl;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class Main extends ScriptableObject {
|
public class Main extends ImporterTopLevel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point.
|
* Main entry point.
|
||||||
|
@ -108,6 +108,10 @@ public class Main extends ScriptableObject {
|
||||||
global.defineProperty("environment", environment,
|
global.defineProperty("environment", environment,
|
||||||
ScriptableObject.DONTENUM);
|
ScriptableObject.DONTENUM);
|
||||||
|
|
||||||
|
global.history = (NativeArray) cx.newArray(global, 0);
|
||||||
|
global.defineProperty("history", global.history,
|
||||||
|
ScriptableObject.DONTENUM);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: enable debugger
|
TODO: enable debugger
|
||||||
if (global.debug) {
|
if (global.debug) {
|
||||||
|
@ -428,7 +432,7 @@ public class Main extends ScriptableObject {
|
||||||
thread.start();
|
thread.start();
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate JavaScript source.
|
* Evaluate JavaScript source.
|
||||||
*
|
*
|
||||||
|
@ -472,6 +476,8 @@ public class Main extends ScriptableObject {
|
||||||
if (result != cx.getUndefinedValue()) {
|
if (result != cx.getUndefinedValue()) {
|
||||||
System.err.println(cx.toString(result));
|
System.err.println(cx.toString(result));
|
||||||
}
|
}
|
||||||
|
NativeArray h = global.history;
|
||||||
|
h.put((int)h.jsGet_length(), h, source);
|
||||||
}
|
}
|
||||||
catch (WrappedException we) {
|
catch (WrappedException we) {
|
||||||
// Some form of exception was caught by JavaScript and
|
// Some form of exception was caught by JavaScript and
|
||||||
|
@ -579,6 +585,7 @@ public class Main extends ScriptableObject {
|
||||||
boolean debug = false;
|
boolean debug = false;
|
||||||
boolean processStdin = true;
|
boolean processStdin = true;
|
||||||
boolean showDebuggerUI = false;
|
boolean showDebuggerUI = false;
|
||||||
|
NativeArray history;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче