Compare commits

..

5 Commits

Author SHA1 Message Date
beard%netscape.com
d30ae9fd55 commented out code that sets prototype of JavaAdapter instance, which broke calls to Java methods, toString(), etc.
git-svn-id: svn://10.0.0.236/branches/ClassGen_BRANCH@48180 18797224-902f-48f8-a5cc-f745e15eee43
1999-09-18 07:55:31 +00:00
norris%netscape.com
14b0e9035d Avoid throwing exception for NervousText.
git-svn-id: svn://10.0.0.236/branches/ClassGen_BRANCH@48005 18797224-902f-48f8-a5cc-f745e15eee43
1999-09-17 20:18:27 +00:00
beard%netscape.com
0e53f7d205 copy all of the arguments, instead of 1..(args.length-1)
git-svn-id: svn://10.0.0.236/branches/ClassGen_BRANCH@47891 18797224-902f-48f8-a5cc-f745e15eee43
1999-09-17 01:06:22 +00:00
norris%netscape.com
b6c0881d76 Changes for the NervousText applet example.
git-svn-id: svn://10.0.0.236/branches/ClassGen_BRANCH@46577 18797224-902f-48f8-a5cc-f745e15eee43
1999-09-09 17:57:58 +00:00
(no author)
7144ca2ee4 This commit was manufactured by cvs2svn to create branch 'ClassGen_BRANCH'.
git-svn-id: svn://10.0.0.236/branches/ClassGen_BRANCH@44416 18797224-902f-48f8-a5cc-f745e15eee43
1999-08-25 01:05:43 +00:00
250 changed files with 6087 additions and 36941 deletions

View File

@@ -1,34 +1,18 @@
#! gmake
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
# 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 License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
# implied. See the License for the specific language governing
# rights and limitations under the License.
# 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 Original Code is Rhino code, released
# May 6, 1998.
#
# The Initial Developer of the Original Code is Netscape
# 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.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU Public License (the "GPL"), in which case the
# provisions of the GPL are applicable instead of those above.
# If you wish to allow use of your version of this file only
# under the terms of the GPL and not to allow others to use your
# version of this file under the NPL, indicate your decision by
# deleting the provisions above and replace them with the notice
# and other provisions required by the GPL. If you do not delete
# the provisions above, a recipient may use your version of this
# file under either the NPL or the GPL.
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
#
# Makefile for javascript in java.
@@ -97,17 +81,17 @@ EXPORTS = CLASSDIR=$(CLASSDIR) JAVAC=$(JAVAC) JFLAGS=$(JFLAGS) SHELL=$(SHELL) \
helpmessage : FORCE
@echo 'Targets include:'
@echo ' all - make jars, examples'
@echo ' jars - make js.jar, jstools.jar'
@echo ' fast - quick-and-dirty "make jars", for development'
@echo ' examples - build the .class files in the examples directory'
@echo ' check - perform checks on the source.'
@echo ' clean - remove intermediate files'
@echo ' clobber - make clean, and remove .jar files'
@echo ' zip - make a distribution .zip file'
@echo ' zip-source - make a distribution .zip file, with source'
@echo ' tar - make a distribution .tar.gz file'
@echo ' tar-source - make a distribution .tar.gz, with source'
@echo '\tall - make jars, examples'
@echo '\tjars - make js.jar, jstools.jar'
@echo '\tfast - quick-and-dirty "make jars", for development'
@echo '\texamples - build the .class files in the examples directory'
@echo '\tcheck - perform checks on the source.'
@echo '\tclean - remove intermediate files'
@echo '\tclobber - make clean, and remove .jar files'
@echo '\tzip - make a distribution .zip file'
@echo '\tzip-source - make a distribution .zip file, with source'
@echo '\ttar - make a distribution .tar.gz file'
@echo '\ttar-source - make a distribution .tar.gz, with source'
@echo
@echo 'Define OS_TARGET to "WINNT" to build on Windows NT with GNU make.'
@echo

View File

@@ -1,37 +1,4 @@
<html>
<!--
- The contents of this file are subject to the Netscape Public
- License Version 1.1 (the "License"); you may not use this file
- except in compliance with the License. You may obtain a copy of
- the License at http://www.mozilla.org/NPL/
-
- Software distributed under the License is distributed on an "AS
- IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- implied. See the License for the specific language governing
- rights and limitations under the License.
-
- The Original Code is Rhino code, released
- May 6, 1999.
-
- The Initial Developer of the Original Code is Netscape
- Communications Corporation. Portions created by Netscape are
- Copyright (C) 1998-1999 Netscape Communications Corporation. All
- Rights Reserved.
-
- Contributor(s):
- Norris Boyd
-
- Alternatively, the contents of this file may be used under the
- terms of the GNU Public License (the "GPL"), in which case the
- provisions of the GPL are applicable instead of those above.
- If you wish to allow use of your version of this file only
- under the terms of the GPL and not to allow others to use your
- version of this file under the NPL, indicate your decision by
- deleting the provisions above and replace them with the notice
- and other provisions required by the GPL. If you do not delete
- the provisions above, a recipient may use your version of this
- file under either the NPL or the GPL.
-->
<body>
<h1>
<span CLASS=LXRSHORTDESC>

View File

@@ -1,35 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1998.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
import org.mozilla.javascript.*;
@@ -72,31 +56,36 @@ public class Control {
// ignore
}
Scriptable obj = (Scriptable) scope.get("obj", scope);
FlattenedObject global = new FlattenedObject(scope);
FlattenedObject f = (FlattenedObject) global.getProperty("obj");
// Should print "obj == result" (Since the result of an assignment
// expression is the value that was assigned)
System.out.println("obj " + (obj == result ? "==" : "!=") +
System.out.println("obj " + (f.getObject() == result ? "==" : "!=") +
" result");
// Should print "obj.a == 1"
System.out.println("obj.a == " + obj.get("a", obj));
// Should print "f.a == 1"
System.out.println("f.a == " + f.getProperty("a"));
Scriptable b = (Scriptable) obj.get("b", obj);
FlattenedObject b = (FlattenedObject) f.getProperty("b");
// Should print "obj.b[0] == x"
System.out.println("obj.b[0] == " + b.get(0, b));
// Should print "f.b[0] == x"
System.out.println("f.b[0] == " + b.getProperty(new Integer(0)));
// Should print "obj.b[1] == y"
System.out.println("obj.b[1] == " + b.get(1, b));
// Should print "f.b[1] == y"
System.out.println("f.b[1] == " + b.getProperty(new Integer(1)));
try {
// Should print {a:1, b:["x", "y"]}
Function fn = (Function) ScriptableObject.getProperty(obj, "toString");
System.out.println(fn.call(cx, scope, obj, new Object[0]));
System.out.println(f.callMethod("toString", new Object[0]));
} catch (PropertyException e) {
// ignore
} catch (NotAFunctionException e) {
// ignore
} catch (JavaScriptException e) {
// ignore
}
}
cx.exit();
}

View File

@@ -1,55 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
import org.mozilla.javascript.*;
public class Counter extends ScriptableObject {
// The zero-argument constructor used by Rhino runtime to create instances
public Counter() { }
// Method jsConstructor defines the JavaScript constructor
public void jsConstructor(int a) { count = a; }
// The class name is defined by the getClassName method
public String getClassName() { return "Counter"; }
// The method jsGet_count defines the count property.
public int jsGet_count() { return count++; }
// Methods can be defined using the jsFunction_ prefix. Here we define
// resetCount for JavaScript.
public void jsFunction_resetCount() { count = 0; }
private int count;
}

View File

@@ -1,178 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
import org.mozilla.javascript.*;
/**
* Example of controlling the JavaScript with multiple scopes and threads.
*/
public class DynamicScopes {
/**
* Main entry point.
*
* Set up the shared scope and then spawn new threads that execute
* relative to that shared scope. Try compiling functions with and
* without dynamic scope to see the effect.
*
* The expected output is
* <pre>
* sharedScope
* sharedScope
* sharedScope
* thread0
* thread1
* thread2
* </pre>
* The final three lines may be permuted in any order depending on
* thread scheduling.
*/
public static void main(String[] args)
throws JavaScriptException
{
Context cx = Context.enter();
try {
cx.setCompileFunctionsWithDynamicScope(false);
runScripts(cx);
cx.setCompileFunctionsWithDynamicScope(true);
runScripts(cx);
} finally {
cx.exit();
}
}
static void runScripts(Context cx)
throws JavaScriptException
{
// Initialize the standard objects (Object, Function, etc.)
// This must be done before scripts can be executed. The call
// returns a new scope that we will share.
Scriptable scope = cx.initStandardObjects(null);
// Now we can evaluate a script and functions will be compiled to
// use dynamic scope if the Context is so initialized.
String source = "var x = 'sharedScope';" +
"function f() { return x; }";
cx.evaluateString(scope, source, "MySource", 1, null);
// Now we spawn some threads that execute a script that calls the
// function 'f'. The scope chain looks like this:
// <pre>
// ------------------
// | shared scope |
// ------------------
// ^
// |
// ------------------
// | per-thread scope |
// ------------------
// ^
// |
// ------------------
// | f's activation |
// ------------------
// </pre>
// Both the shared scope and the per-thread scope have variables 'x'
// defined in them. If 'f' is compiled with dynamic scope enabled,
// the 'x' from the per-thread scope will be used. Otherwise, the 'x'
// from the shared scope will be used. The 'x' defined in 'g' (which
// calls 'f') should not be seen by 'f'.
final int threadCount = 3;
Thread[] t = new Thread[threadCount];
for (int i=0; i < threadCount; i++) {
String script = "function g() { var x = 'local'; return f(); }" +
"java.lang.System.out.println(g());";
t[i] = new Thread(new PerThread(scope, script,
"thread" + i));
}
for (int i=0; i < threadCount; i++)
t[i].start();
// Don't return in this thread until all the spawned threads have
// completed.
for (int i=0; i < threadCount; i++) {
try {
t[i].join();
} catch (InterruptedException e) {
}
}
}
static class PerThread implements Runnable {
PerThread(Scriptable scope, String script, String x) {
this.scope = scope;
this.script = script;
this.x = x;
}
public void run() {
// We need a new Context for this thread.
Context cx = Context.enter();
try {
// We can share the scope.
Scriptable threadScope = cx.newObject(scope);
threadScope.setPrototype(scope);
// We want "threadScope" to be a new top-level
// scope, so set its parent scope to null. This
// means that any variables created by assignments
// will be properties of "threadScope".
threadScope.setParentScope(null);
// Create a JavaScript property of the thread scope named
// 'x' and save a value for it.
threadScope.put("x", threadScope, x);
cx.evaluateString(threadScope, script, "threadScript", 1, null);
}
catch (NotAFunctionException jse) {
// ignore
}
catch (PropertyException jse) {
// ignore
}
catch (JavaScriptException jse) {
// ignore
}
finally {
Context.exit();
}
}
private Scriptable scope;
private String script;
private String x;
}
}

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1998.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
import org.mozilla.javascript.*;
@@ -47,6 +30,7 @@ import java.util.Vector;
* Example of use of the File object:
* <pre>
* js> defineClass("File")
* js> var file = new File("myfile.txt");
* js> file = new File("myfile.txt");
* [object File]
* js> file.writeLine("one"); <i>only now is file actually opened</i>
@@ -87,9 +71,8 @@ public class File extends ScriptableObject {
* Otherwise System.in or System.out is assumed as appropriate
* to the use.
*/
public static Scriptable jsConstructor(Context cx, Object[] args,
Function ctorObj,
boolean inNewExpr)
public static Scriptable js_File(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr)
{
File result = new File();
if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
@@ -114,7 +97,7 @@ public class File extends ScriptableObject {
*
* Used to define the "name" property.
*/
public String jsGet_name() {
public String js_getName() {
return name;
}
@@ -131,12 +114,12 @@ public class File extends ScriptableObject {
* @exception JavaScriptException if a JavaScript exception occurred
* while creating the result array
*/
public Object jsFunction_readLines()
public Object js_readLines()
throws IOException, JavaScriptException
{
Vector v = new Vector();
String s;
while ((s = jsFunction_readLine()) != null) {
while ((s = js_readLine()) != null) {
v.addElement(s);
}
Object[] lines = new Object[v.size()];
@@ -164,7 +147,7 @@ public class File extends ScriptableObject {
* associated with this object, or EOFException if the object
* reached the end of the file
*/
public String jsFunction_readLine() throws IOException {
public String js_readLine() throws IOException {
return getReader().readLine();
}
@@ -175,7 +158,22 @@ public class File extends ScriptableObject {
* associated with this object, or EOFException if the object
* reached the end of the file
*/
public String jsFunction_readChar() throws IOException {
public String js_readChar() throws IOException {
int i = getReader().read();
if (i == -1)
return null;
char[] charArray = { (char) i };
return new String(charArray);
}
/**
* Read a block.
*
* @exception IOException if an error occurred while accessing the file
* associated with this object, or EOFException if the object
* reached the end of the file
*/
public String js_readBlock() throws IOException {
int i = getReader().read();
if (i == -1)
return null;
@@ -193,8 +191,8 @@ public class File extends ScriptableObject {
* @exception IOException if an error occurred while accessing the file
* associated with this object
*/
public static void jsFunction_write(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
public static void js_write(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
throws IOException
{
write0(thisObj, args, false);
@@ -208,14 +206,14 @@ public class File extends ScriptableObject {
* associated with this object
*
*/
public static void jsFunction_writeLine(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
public static void js_writeLine(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
throws IOException
{
write0(thisObj, args, true);
}
public int jsGet_lineNumber()
public int js_getLineNumber()
throws FileNotFoundException
{
return getReader().getLineNumber();
@@ -228,7 +226,7 @@ public class File extends ScriptableObject {
* @exception IOException if an error occurred while accessing the file
* associated with this object
*/
public void jsFunction_close() throws IOException {
public void js_close() throws IOException {
if (reader != null) {
reader.close();
reader = null;
@@ -245,7 +243,7 @@ public class File extends ScriptableObject {
*/
public void finalize() {
try {
jsFunction_close();
js_close();
}
catch (IOException e) {
}
@@ -253,6 +251,11 @@ public class File extends ScriptableObject {
/**
* Get the Java reader.
*
* Note that we use the name "jsFunction_getReader" because if we
* used just "js_getReader" we'd be defining a readonly property
* named "reader".
*
*/
public Object jsFunction_getReader() {
if (reader == null)

View File

@@ -1,35 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1998.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
import org.mozilla.javascript.*;

View File

@@ -1,34 +1,18 @@
#! gmake
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
# 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 License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
# implied. See the License for the specific language governing
# rights and limitations under the License.
# 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 Original Code is Rhino code, released
# May 6, 1998.
#
# The Initial Developer of the Original Code is Netscape
# 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.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU Public License (the "GPL"), in which case the
# provisions of the GPL are applicable instead of those above.
# If you wish to allow use of your version of this file only
# under the terms of the GPL and not to allow others to use your
# version of this file under the NPL, indicate your decision by
# deleting the provisions above and replace them with the notice
# and other provisions required by the GPL. If you do not delete
# the provisions above, a recipient may use your version of this
# file under either the NPL or the GPL.
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
#
# Makefile for the examples directory.

View File

@@ -1,35 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1998.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
import org.mozilla.javascript.*;

View File

@@ -1,7 +0,0 @@
<html>
<body>
This is the NervousText applet in javascript:
<applet code=NervousText.class width=200 height=50 >
</applet>
</body>
</html>

View File

@@ -1,75 +0,0 @@
// The Java "NervousText" example ported to JavaScript.
// Compile using java org.mozilla.tools.jsc.Main -extends java.applet.Applet -implements java.lang.Runnable NervousText.js
/*
Adapted from Java code by
Daniel Wyszynski
Center for Applied Large-Scale Computing (CALC)
04-12-95
Test of text animation.
kwalrath: Changed string; added thread suspension. 5-9-95
*/
var Font = java.awt.Font;
var Thread = java.lang.Thread;
var separated;
var s = null;
var killme = null;
var i;
var x_coord = 0, y_coord = 0;
var num;
var speed=35;
var counter =0;
var threadSuspended = false; //added by kwalrath
function init() {
resize(150,50);
setFont(new Font("TimesRoman",Font.BOLD,36));
s = getParameter("text");
if (s == null) {
s = "Rhino";
}
separated = s.split('');
}
function start() {
if(killme == null)
{
killme = new java.lang.Thread(java.lang.Runnable(this));
killme.start();
}
}
function stop() {
killme = null;
}
function run() {
while (killme != null) {
try {Thread.sleep(100);} catch (e){}
repaint();
}
killme = null;
}
function paint(g) {
for(i=0;i<separated.length;i++)
{
x_coord = Math.random()*10+15*i;
y_coord = Math.random()*10+36;
g.drawChars(separated, i,1,x_coord,y_coord);
}
}
/* Added by kwalrath. */
function mouseDown(evt, x, y) {
if (threadSuspended) {
killme.resume();
}
else {
killme.suspend();
}
threadSuspended = !threadSuspended;
return true;
}

View File

@@ -1,35 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1998.
*
* The Initial Developer of the Original Code is Netscape
* 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.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
import org.mozilla.javascript.*;

View File

@@ -1,63 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
import org.mozilla.javascript.*;
/**
* RunScript2: Like RunScript, but reflects the System.out into JavaScript.
*
* @author Norris Boyd
*/
public class RunScript2 {
public static void main(String args[])
throws JavaScriptException
{
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects(null);
// Add a global variable "out" that is a JavaScript reflection
// of System.out
Scriptable jsArgs = Context.toObject(System.out, scope);
scope.put("out", scope, jsArgs);
String s = "";
for (int i=0; i < args.length; i++)
s += args[i];
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
System.err.println(cx.toString(result));
Context.exit();
}
}

View File

@@ -1,63 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
import org.mozilla.javascript.*;
/**
* RunScript3: Execute scripts in an environment that includes the
* example Counter class.
*
* @author Norris Boyd
*/
public class RunScript3 {
public static void main(String args[])
throws Exception
{
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects(null);
// Use the Counter class to define a Counter constructor
// and prototype in JavaScript.
ScriptableObject.defineClass(scope, Counter.class);
String s = "";
for (int i=0; i < args.length; i++)
s += args[i];
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
System.err.println(cx.toString(result));
Context.exit();
}
}

View File

@@ -1,35 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1998.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
import org.mozilla.javascript.*;
@@ -126,7 +110,7 @@ public class Shell extends ScriptableObject {
* This method must be implemented in all concrete classes
* extending ScriptableObject.
*
* @see org.mozilla.javascript.Scriptable#getClassName
* @see com.netscape.javascript.Scriptable#getClassName
*/
public String getClassName() {
return "global";

View File

@@ -1,38 +1,3 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/**
* checkParam.js
*

View File

@@ -1,38 +1,3 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Patrick Beard
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/*
enum.js

View File

@@ -1,39 +1,3 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roland Pennings
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/**
* Process a JavaScript source file and process special comments
* to produce an HTML file of documentation, similar to javadoc.

View File

@@ -1,38 +1,3 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/**
* liveConnect.js: a simple demonstration of JavaScript-to-Java connectivity
*/

View File

@@ -1,38 +1,3 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
// unique.js: read the contents of a file and print out the unique lines
defineClass("File")

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.classfile;

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.classfile;

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -60,8 +43,7 @@ class Arguments extends ScriptableObject {
ScriptableObject.DONTENUM);
defineProperty("callee", callee, ScriptableObject.DONTENUM);
hasCaller = (activation.funObj.version <= Context.VERSION_1_3 &&
activation.funObj.version != Context.VERSION_DEFAULT);
hasCaller = activation.funObj.version <= Context.VERSION_1_3;
}
public String getClassName() {

View File

@@ -1,37 +1,20 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Waldemar Horwat
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,36 +1,20 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Andi Vajda
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -54,8 +35,4 @@ public interface ClassNameHelper {
public void setTargetExtends(Class extendsClass);
public void setTargetImplements(Class[] implementsClasses);
public ClassOutput getClassOutput();
public void setClassOutput(ClassOutput classOutput);
}

View File

@@ -1,56 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Andi Vajda
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
package org.mozilla.javascript;
// API class
import java.io.*;
/**
* This interface is implemented by classes interested in the bytecode
* generated by the rhino compiler for script objects.
*
* @see Context
* @author Andi Vajda
*/
public interface ClassOutput {
/**
* @param className the name of the class for which bytecode is ready.
* @return a stream into which to write bytecode.
* @since 1.5 Release 2
*/
public OutputStream getOutputStream(String className)
throws IOException;

View File

@@ -1,44 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Patrick Beard
* Norris Boyd
* Brendan Eich
* Roger Lawrence
* Mike McCabe
* Ian D. Stewart
* Andi Vajda
* Andrew Wason
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class
@@ -54,7 +29,6 @@ import java.util.Locale;
import java.util.ResourceBundle;
import java.text.MessageFormat;
import java.lang.reflect.*;
import org.mozilla.javascript.debug.*;
/**
* This class represents the runtime context of an executing script.
@@ -96,6 +70,7 @@ public final class Context {
*/
public Context() {
setLanguageVersion(VERSION_DEFAULT);
this.generatingDebug = true;
optimizationLevel = codegenClass != null ? 0 : -1;
}
@@ -262,11 +237,6 @@ public final class Context {
*/
public static final int VERSION_1_4 = 140;
/**
* JavaScript 1.5
*/
public static final int VERSION_1_5 = 150;
/**
* Get the current language version.
* <p>
@@ -315,7 +285,7 @@ public final class Context {
* number, and date.
*/
public String getImplementationVersion() {
return "JavaScript-Java 1.5 release 1 2000 03 15";
return "JavaScript-Java 1.4 release 3 1999 04 05";
}
/**
@@ -324,6 +294,9 @@ public final class Context {
* @see org.mozilla.javascript.ErrorReporter
*/
public ErrorReporter getErrorReporter() {
if (debug_errorReporterHook != null) {
return debug_errorReporterHook;
}
if (errorReporter == null) {
errorReporter = new DefaultErrorReporter();
}
@@ -337,6 +310,8 @@ public final class Context {
* @see org.mozilla.javascript.ErrorReporter
*/
public ErrorReporter setErrorReporter(ErrorReporter reporter) {
if (null != debug_errorReporterHook)
return debug_errorReporterHook.setErrorReporter(reporter);
ErrorReporter result = errorReporter;
if (listeners != null && errorReporter != reporter) {
firePropertyChange(errorReporterProperty, errorReporter,
@@ -570,7 +545,6 @@ public final class Context {
public ScriptableObject initStandardObjects(ScriptableObject scope,
boolean sealed)
{
final String omj = "org.mozilla.javascript.";
try {
if (scope == null)
scope = new NativeObject();
@@ -588,32 +562,19 @@ public final class Context {
// Set the prototype of the object passed in if need be
if (scope.getPrototype() == null)
scope.setPrototype(objectProto);
// must precede NativeGlobal since it's needed therein
ScriptableObject.defineClass(scope, NativeError.class, sealed);
ScriptableObject.defineClass(scope, NativeGlobal.class, sealed);
String[] classes = { "NativeArray", "Array",
"NativeString", "String",
"NativeBoolean", "Boolean",
"NativeNumber", "Number",
"NativeDate", "Date",
"NativeMath", "Math",
"NativeCall", "Call",
"NativeWith", "With",
"regexp.NativeRegExp", "RegExp",
"NativeScript", "Script",
String[] classes = { "NativeGlobal", "NativeArray",
"NativeString", "NativeBoolean",
"NativeNumber", "NativeDate",
"NativeMath", "NativeCall",
"NativeClosure", "NativeWith",
"regexp.NativeRegExp", "NativeScript"
};
for (int i=0; i < classes.length; i+=2) {
for (int i=0; i < classes.length; i++) {
try {
if (sealed) {
Class c = Class.forName(omj + classes[i]);
ScriptableObject.defineClass(scope, c, sealed);
} else {
String s = omj + classes[i];
new LazilyLoadedCtor(scope, classes[i+1], s,
ScriptableObject.DONTENUM);
}
Class c = Class.forName("org.mozilla.javascript." +
classes[i]);
ScriptableObject.defineClass(scope, c, sealed);
} catch (ClassNotFoundException e) {
continue;
}
@@ -630,10 +591,6 @@ public final class Context {
try {
Class adapterClass = Class.forName(adapterName);
ScriptableObject.defineClass(scope, adapterClass, sealed);
// This creates the Packages and java package roots.
Class c = Class.forName(omj + "NativeJavaPackage");
ScriptableObject.defineClass(scope, c, sealed);
} catch (ClassNotFoundException e) {
// If the class is not found, proceed without it.
} catch (SecurityException e) {
@@ -643,6 +600,9 @@ public final class Context {
// java.util.PropertyPermission
// org.mozilla.javascript.JavaAdapter read
}
// This creates the Packages and java package roots.
NativeJavaPackage.init(scope);
}
// All of these exceptions should not occur since we are initializing
// from known classes
@@ -760,16 +720,17 @@ public final class Context {
Reader in = new StringReader(source);
// no source name or source text manager, because we're just
// going to throw away the result.
TokenStream ts = new TokenStream(in, null, null, 1);
TokenStream ts = new TokenStream(in, null, 1);
// Temporarily set error reporter to always be the exception-throwing
// DefaultErrorReporter. (This is why the method is synchronized...)
DeepErrorReporterHook hook = setErrorReporterHook(null);
ErrorReporter currentReporter =
setErrorReporter(new DefaultErrorReporter());
boolean errorseen = false;
try {
IRFactory irf = new IRFactory(ts, null);
IRFactory irf = new IRFactory(ts);
Parser p = new Parser(irf);
p.parse(ts);
} catch (IOException ioe) {
@@ -779,7 +740,9 @@ public final class Context {
} finally {
// Restore the old error reporter.
setErrorReporter(currentReporter);
setErrorReporterHook(hook);
}
// Return false only if an error occurred as a result of reading past
// the end of the file, i.e. if the source could be fixed by
// appending more source.
@@ -822,7 +785,8 @@ public final class Context {
* Compile a JavaScript function.
* <p>
* The function source must be a function definition as defined by
* ECMA (e.g., "function f(a) { return a; }").
* ECMA (e.g., "function f(a) { return a; }"). As an extension to the
* ECMA grammar, the function name is optional.
*
* @param scope the scope to compile relative to
* @param source the function definition source
@@ -1144,7 +1108,8 @@ public final class Context {
* @return new JavaScript object
*/
public static Scriptable toObject(Object value, Scriptable scope,
Class staticType) {
Class staticType)
{
if (value == null && staticType != null)
return null;
return ScriptRuntime.toObject(scope, value, staticType);
@@ -1279,30 +1244,6 @@ public final class Context {
nameHelper.setTargetPackage(targetPackage);
}
/**
* Get the current interface to write class bytes into.
*
* @see ClassOutput
* @since 1.5 Release 2
*/
public ClassOutput getClassOutput() {
return nameHelper == null ? null : nameHelper.getClassOutput();
}
/**
* Set the interface to write class bytes into.
* Unless setTargetClassFileName() has been called classOutput will be
* used each time the javascript compiler has generated the bytecode for a
* script class.
*
* @see ClassOutput
* @since 1.5 Release 2
*/
public void setClassOutput(ClassOutput classOutput) {
if (nameHelper != null)
nameHelper.setClassOutput(classOutput);
}
/**
* Return true if a security domain is required on calls to
* compile and evaluate scripts.
@@ -1339,28 +1280,266 @@ public final class Context {
}
/**
* Set the class that the generated target will extend.
*
* @param extendsClass the class it extends
* TODO: doc this and below
*/
public void setTargetExtends(Class extendsClass) {
public void setTargetExtends(Class extendsClass)
{
if (nameHelper != null) {
nameHelper.setTargetExtends(extendsClass);
}
}
/**
* Set the interfaces that the generated target will implement.
*
* @param implementsClasses an array of Class objects, one for each
* interface the target will extend
*/
public void setTargetImplements(Class[] implementsClasses) {
public void setTargetImplements(Class[] implementsClasses)
{
if (nameHelper != null) {
nameHelper.setTargetImplements(implementsClasses);
}
}
/**** debugger oriented portion of API ****/
/**
* Get the current source text hook (for debugging).
*
* @return the current hook
* @see org.mozilla.javascript.SourceTextManager
* @see org.mozilla.javascript.Context#setSourceTextManager
*/
public SourceTextManager getSourceTextManager() {
return debug_stm;
}
/**
* Set the current source text hook (for debugging).
* <p>
* When using the org.mozilla.javascript.debug system to debug within the
* context of a particular embedding if the Context has this hook set
* then all parsed JavaScript source will be passed to the hook. In
* some embeddings of JavaScript it may be better to not use this
* low level hook and instead have the embedding itself feed the
* source text to the SourceTextManager.
*
* @param debug_stm new hook
* @return the previous hook
* @see org.mozilla.javascript.SourceTextManager
*/
public SourceTextManager setSourceTextManager(SourceTextManager debug_stm) {
SourceTextManager result = this.debug_stm;
this.debug_stm = debug_stm;
return result;
}
/**
* Get the current script hook (for debugging).
*
* @return the current hook
* @see org.mozilla.javascript.DeepScriptHook
* @see org.mozilla.javascript.Context#setScriptHook
*/
public DeepScriptHook getScriptHook() {
return debug_scriptHook;
}
/**
* Set the current script hook (for debugging).
* <p>
* At debugLevel >= 3 the script hook is called when
* compiled scripts (and functions) are loaded and unloaded.
*
* @param hook new hook
* @return the previous hook
* @see org.mozilla.javascript.DeepScriptHook
*/
public DeepScriptHook setScriptHook(DeepScriptHook hook) {
DeepScriptHook result = debug_scriptHook;
debug_scriptHook = hook;
return result;
}
/**
* Get the current call hook (for debugging).
*
* @return the current hook
* @see org.mozilla.javascript.DeepCallHook
* @see org.mozilla.javascript.Context#setCallHook
*/
public DeepCallHook getCallHook() {
return debug_callHook;
}
/**
* Set the current call hook (for debugging).
* <p>
* At debugLevel >= 3 the call hook is called when
* compiled scripts and functions make function calls.
*
* @param hook new hook
* @return the previous hook
* @see org.mozilla.javascript.DeepCallHook
*/
public DeepCallHook setCallHook(DeepCallHook hook) {
DeepCallHook result = debug_callHook;
debug_callHook = hook;
return result;
}
/**
* Get the current execute hook (for debugging).
*
* @return the current hook
* @see org.mozilla.javascript.DeepExecuteHook
* @see org.mozilla.javascript.Context#setExecuteHook
*/
public DeepExecuteHook getExecuteHook() {
return debug_executeHook;
}
/**
* Set the current execute hook (for debugging).
* <p>
* At debugLevel >= 3 the execute hook is called when
* top level compiled scripts (non-functions) are executed.
*
* @param hook new hook
* @return the previous hook
* @see org.mozilla.javascript.DeepExecuteHook
*/
public DeepExecuteHook setExecuteHook(DeepExecuteHook hook) {
DeepExecuteHook result = debug_executeHook;
debug_executeHook = hook;
return result;
}
/**
* Get the current new object hook (for debugging).
*
* @return the current hook
* @see org.mozilla.javascript.DeepNewObjectHook
* @see org.mozilla.javascript.Context#setNewObjectHook
*/
public DeepNewObjectHook getNewObjectHook() {
return debug_newObjectHook;
}
/**
* Set the current new object hook (for debugging).
* <p>
* At debugLevel >= 3 the new object hook is called when
* JavaScript objects are created by compiled scripts
* and functions; i.e. when constructor functions run.
*
* @param hook new hook
* @return the previous hook
* @see org.mozilla.javascript.DeepNewObjectHook
*/
public DeepNewObjectHook setNewObjectHook(DeepNewObjectHook hook) {
DeepNewObjectHook result = debug_newObjectHook;
debug_newObjectHook = hook;
return result;
}
/**
* Get the current byte code hook (for debugging).
*
* @return the current hook
* @see org.mozilla.javascript.DeepBytecodeHook
* @see org.mozilla.javascript.Context#setBytecodeHook
*/
public DeepBytecodeHook getBytecodeHook() {
return debug_bytecodeHook;
}
/**
* Set the current byte code hook (for debugging).
* <p>
* At debugLevel >= 6 generated scripts and functions
* support setting traps and interrupts on a per statement
* basis. If a trap or interrupt is encountered while
* running in this Context, then this hook is called to
* handle it.
*
* @param hook new hook
* @return the previous hook
* @see org.mozilla.javascript.DeepBytecodeHook
*/
public DeepBytecodeHook setBytecodeHook(DeepBytecodeHook hook) {
DeepBytecodeHook result = debug_bytecodeHook;
debug_bytecodeHook = hook;
return result;
}
/**
* Get the current error reporter hook (for debugging).
*
* @return the current hook
* @see org.mozilla.javascript.DeepErrorReporterHook
* @see org.mozilla.javascript.Context#setErrorReporter
*/
public DeepErrorReporterHook getErrorReporterHook() {
return debug_errorReporterHook;
}
/**
* Set the current error reporter hook (for debugging).
* <p>
* This hook allows a debugger to trap error reports before
* there are sent to the error reporter. This is not meant to
* be used in place of the normal error reporting system.
*
* @param hook new hook
* @return the previous hook
* @see org.mozilla.javascript.DeepErrorReporterHook
* @see org.mozilla.javascript.ErrorReporter
* @see org.mozilla.javascript.Context#setErrorReporter
*/
public DeepErrorReporterHook setErrorReporterHook(DeepErrorReporterHook hook) {
DeepErrorReporterHook result = debug_errorReporterHook;
debug_errorReporterHook = hook;
return result;
}
/**
* Get the current debug level (for debugging).
*
* @return the current debug level
* @see org.mozilla.javascript.Context#setDebugLevel
*/
public int getDebugLevel() {
return debugLevel;
}
/**
* Set the current debug level (for debugging).
* <p>
* Set the debug level. Note that a non-zero debug level will
* force the optimization level to 0.
* <p>
* Currently supported debug levels:
* <pre>
* debugLevel == 0 - all debug support off (except error reporter hooks)
* debugLevel >= 1 - name of source file stored in NativeFunction
* debugLevel >= 3 - load/unload hooks called
* - base/end lineno info stored in NativeFunction
* - call, new object, and execute hooks called
* debugLevel >= 6 - interrupts and traps supported
*
* </pre>
*
* @param debugLevel new debugLevel
* @return the previous debug level
*/
public int setDebugLevel(int debugLevel) {
int result = this.debugLevel;
if (debugLevel < 0)
debugLevel = 0;
else if (debugLevel > 9)
debugLevel = 9;
if (debugLevel > 0)
setOptimizationLevel(0);
this.debugLevel = (byte) debugLevel;
return result;
}
/**
* Get a value corresponding to a key.
* <p>
@@ -1393,108 +1572,7 @@ public final class Context {
hashtable = new Hashtable();
hashtable.put(key, value);
}
/**
* Return whether functions are compiled by this context using
* dynamic scope.
* <p>
* If functions are compiled with dynamic scope, then they execute
* in the scope of their caller, rather than in their parent scope.
* This is useful for sharing functions across multiple scopes.
* @since 1.5 Release 1
*/
public boolean hasCompileFunctionsWithDynamicScope() {
return compileFunctionsWithDynamicScopeFlag;
}
/**
* Set whether functions compiled by this context should use
* dynamic scope.
* <p>
* @param flag if true, compile functions with dynamic scope
* @since 1.5 Release 1
*/
public void setCompileFunctionsWithDynamicScope(boolean flag) {
compileFunctionsWithDynamicScopeFlag = flag;
}
/**
* Set whether to cache some values statically.
* <p>
* By default, the engine will cache some values statically
* (reflected Java classes, for instance). This can speed
* execution dramatically, but increases the memory footprint.
* Also, with caching enabled, references may be held to
* objects past the lifetime of any real usage.
* <p>
* If caching is enabled and this method is called with a
* <code>false</code> argument, the caches will be emptied.
* So one strategy could be to clear the caches at times
* appropriate to the application.
* <p>
* Caching is enabled by default.
*
* @param cachingEnabled if true, caching is enabled
* @since 1.5 Release 1
*/
public static void setCachingEnabled(boolean cachingEnabled) {
if (isCachingEnabled && !cachingEnabled) {
// Caching is being turned off. Empty caches.
FunctionObject.methodsCache = null;
JavaMembers.classTable = new Hashtable();
}
isCachingEnabled = cachingEnabled;
}
/**
*/
public void setWrapHandler(WrapHandler wrapHandler) {
this.wrapHandler = wrapHandler;
}
public WrapHandler getWrapHandler() {
return wrapHandler;
}
/**** debugger oriented portion of API ****/
public void setBreakNextLine(boolean inLineStepMode) {
this.inLineStepMode = inLineStepMode;
}
public boolean getBreakNextLine() {
return inLineStepMode;
}
public void setDebugger(Debugger debugger) {
this.debugger = debugger;
}
public Debugger getDebugger() {
return debugger;
}
public Frame getFrame(int frameNumber) {
return (Frame) frameStack.elementAt(frameStack.size() - frameNumber - 1);
}
public int getFrameCount() {
return frameStack.size();
}
void pushFrame(Frame frame) {
if (frameStack == null)
frameStack = new java.util.Stack();
frameStack.push(frame);
}
void popFrame() {
frameStack.pop();
}
private java.util.Stack frameStack;
/********** end of API **********/
/**
@@ -1573,7 +1651,7 @@ public final class Context {
boolean returnFunction)
throws IOException
{
TokenStream ts = new TokenStream(in, scope, sourceName, lineno);
TokenStream ts = new TokenStream(in, sourceName, lineno);
return compile(scope, ts, securityDomain, returnFunction);
}
@@ -1582,9 +1660,9 @@ public final class Context {
static {
try {
codegenClass = Class.forName(
"org.mozilla.javascript.optimizer.Codegen");
"com.netscape.javascript.optimizer.Codegen");
Class nameHelperClass = Class.forName(
"org.mozilla.javascript.optimizer.OptClassNameHelper");
"com.netscape.javascript.optimizer.OptClassNameHelper");
nameHelper = (ClassNameHelper)nameHelperClass.newInstance();
} catch (ClassNotFoundException x) {
// ...must be running lite, that's ok
@@ -1624,13 +1702,13 @@ public final class Context {
: getCompiler();
errorCount = 0;
IRFactory irf = compiler.createIRFactory(ts, nameHelper, scope);
IRFactory irf = compiler.createIRFactory(ts, nameHelper);
Parser p = new Parser(irf);
Node tree = (Node) p.parse(ts);
if (tree == null)
return null;
tree = compiler.transform(tree, ts, scope);
tree = compiler.transform(tree, ts);
if (printTrees)
System.out.println(tree.toStringTree());
@@ -1646,7 +1724,6 @@ public final class Context {
Object result = compiler.compile(this, scope, tree, securityDomain,
securitySupport, nameHelper);
return errorCount == 0 ? result : null;
}
@@ -1685,13 +1762,6 @@ public final class Context {
open = close = colon = -1;
}
}
// Not found; so we should try the interpreter data.
Context cx = getCurrentContext();
if (cx.interpreterLine > 0 && cx.interpreterSourceFile != null) {
linep[0] = cx.interpreterLine;
return cx.interpreterSourceFile;
}
return null;
}
@@ -1773,9 +1843,11 @@ public final class Context {
requireSecurityDomain = s.equals("true");
} catch (java.util.MissingResourceException mre) {
requireSecurityDomain = true;
} catch (SecurityException se) {
requireSecurityDomain = true;
}
/*
throw new SecurityException("Resource \"" + securityResourceName +
"\" not found.");
*/
}
}
static final boolean useJSObject = false;
@@ -1794,7 +1866,6 @@ public final class Context {
int version;
int errorCount;
static boolean isCachingEnabled = true;
private SecuritySupport securitySupport;
private ErrorReporter errorReporter;
@@ -1804,16 +1875,17 @@ public final class Context {
private Locale locale;
private boolean generatingDebug;
private boolean generatingSource=true;
private boolean compileFunctionsWithDynamicScopeFlag;
private int optimizationLevel;
WrapHandler wrapHandler;
Debugger debugger;
boolean inLineStepMode;
private SourceTextManager debug_stm;
private DeepScriptHook debug_scriptHook;
private DeepCallHook debug_callHook;
private DeepExecuteHook debug_executeHook;
private DeepNewObjectHook debug_newObjectHook;
private DeepBytecodeHook debug_bytecodeHook;
private DeepErrorReporterHook debug_errorReporterHook;
private byte debugLevel;
private int enterCount;
private ListenerCollection listeners;
private Hashtable hashtable;
// For the interpreter to indicate line/source for error reports.
int interpreterLine;
String interpreterSourceFile;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,75 @@
/* -*- 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) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
/**
* This interface supports low-level per statement debug hooks
* <p>
* This interface can be implemented and used to do statement level
* interrupting and trapping of executing scripts.
* org.mozilla.javascript.debug.IDebugManager uses this system and provides
* a higher level abstraction more appropriate as a debugger API.
*
* @see org.mozilla.javascript.Context#setBytecodeHook
* @see org.mozilla.javascript.debug.IDebugManager
* @author John Bandhauer
*/
public interface DeepBytecodeHook
{
/**
* Possible hook return values.
*/
/**
* The executing script should continue.
*/
public static final int CONTINUE = 0;
/**
* The executing script should throw the object passed back in
* retVal[0]. This must be an object derived from java.lang.Throwable.
*/
public static final int THROW = 1;
/**
* The executing script should immediately return the object passed
* back in retVal[0].
*/
public static final int RETURN_VALUE = 2;
/**
* Handle trap.
*
* @param cx current context
* @param pc current program counter
* @param retVal single Object array to hold return value or exception
* @return one of {CONTINUE | THROW | RETURN_VALUE}
*/
public int trapped(Context cx, int pc, Object[] retVal);
/**
* Handle interrupt.
*
* @param cx current context
* @param pc current program counter
* @param retVal single Object array to hold return value or exception
* @return one of {CONTINUE | THROW | RETURN_VALUE}
*/
public int interrupted(Context cx, int pc, Object[] retVal);
}

View File

@@ -0,0 +1,59 @@
/* -*- 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) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
/**
* This interface supports low-level call debug hooks
* <p>
* This interface can be implemented and used to hook JavaScript
* function calls. org.mozilla.javascript.debug.IDebugManager uses this
* system and provides a higher level abstraction more appropriate
* as a debugger API.
*
* @see org.mozilla.javascript.Context#setCallHook
* @see org.mozilla.javascript.debug.IDebugManager
* @author John Bandhauer
*/
public interface DeepCallHook
{
/**
* Notification that a function is about to be called.
*
* @param cx current context
* @param fun function to be called
* @param thisArg the 'this' of the object
* @param args constructor arguments array
* @return arbitrary object which is subsequently passed to postCall
* @see org.mozilla.javascript.debug.NativeDelegate#callDebug
*/
public Object preCall(Context cx, Object fun, Object thisArg, Object[] args);
/**
* Notification that a call returned.
*
* @param cx current context
* @param ref value returned from previous call to preCall
* @param retVal value returned by the callee (null if exception thrown)
* @param e exception thrown by callee (null if none thrown)
* @see org.mozilla.javascript.debug.NativeDelegate#callDebug
*/
public void postCall(Context cx, Object ref, Object retVal,
JavaScriptException e);
}

View File

@@ -0,0 +1,53 @@
/* -*- 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) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
/**
* This interface supports low-level error reporter hooks.
* <p>
* This interface can be implemented and used to hook calls to the
* error reporter. org.mozilla.javascript.debug.IDebugManager uses this
* system and provides a higher level abstraction more appropriate
* as a debugger API.
*
* @see org.mozilla.javascript.Context#setErrorReporterHook
* @see org.mozilla.javascript.debug.IDebugManager
* @author John Bandhauer
*/
public interface DeepErrorReporterHook extends ErrorReporter
{
/**
* Change the current error reporter.
*
* @return the previous error reporter
* @see org.mozilla.javascript.ErrorReporter
* @see org.mozilla.javascript.Context#setErrorReporter
*/
public ErrorReporter setErrorReporter(ErrorReporter reporter);
/**
* Get the current error reporter.
*
* @see org.mozilla.javascript.ErrorReporter
* @see org.mozilla.javascript.Context#getErrorReporter
*/
public ErrorReporter getErrorReporter();
}

View File

@@ -0,0 +1,58 @@
/* -*- 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) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
/**
* This interface supports low-level execute debug hooks.
* <p>
* This interface can be implemented and used to hook JavaScript
* script execution. org.mozilla.javascript.debug.IDebugManager uses this
* system and provides a higher level abstraction more appropriate
* as a debugger API.
*
* @see org.mozilla.javascript.Context#setExecuteHook
* @see org.mozilla.javascript.debug.IDebugManager
* @author John Bandhauer
*/
public interface DeepExecuteHook
{
/**
* Notification that a top-level script is about to be executed.
*
* @param cx current context
* @param fun script
* @param scope scope
* @return arbitrary object which is subsequently passed to postExecute
* @see org.mozilla.javascript.debug.NativeDelegate#executeDebug
*/
public Object preExecute(Context cx, NativeFunction fun, Scriptable scope);
/**
* Notification that a top-level script execution returned.
*
* @param cx current context
* @param ref value returned from previous call to preExecute
* @param retVal value returned by the script (null if exception thrown)
* @param e exception thrown by script (null if none thrown)
* @see org.mozilla.javascript.debug.NativeDelegate#executeDebug
*/
public void postExecute(Context cx, Object ref, Object retVal,
JavaScriptException e);
}

View File

@@ -0,0 +1,59 @@
/* -*- 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) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
/**
* This interface supports low-level new object debug hooks.
* <p>
* This interface can be implemented and used to hook JavaScript
* object creation; i.e. calls for JavaScript constructor
* functions. org.mozilla.javascript.debug.IDebugManager uses this
* system and provides a higher level abstraction more appropriate
* as a debugger API.
*
* @see org.mozilla.javascript.Context#setNewObjectHook
* @see org.mozilla.javascript.debug.IDebugManager
* @author John Bandhauer
*/
public interface DeepNewObjectHook
{
/**
* Notification that a constructor is about to be called.
*
* @param cx current context
* @param fun constructor function
* @param args constructor arguments array
* @return arbitrary object which is subsequently passed to postNewObject
* @see org.mozilla.javascript.debug.NativeDelegate#newObjectDebug
*/
public Object preNewObject(Context cx, Object fun, Object[] args);
/**
* Notification that a constructor returned.
*
* @param cx current context
* @param ref value returned from previous call to preNewObject
* @param retVal value returned by the constructor (null if exception thrown)
* @param e exception thrown by constructor (null if none thrown)
* @see org.mozilla.javascript.debug.NativeDelegate#newObjectDebug
*/
public void postNewObject(Context cx, Object ref, Scriptable retVal,
Exception e);
}

View File

@@ -0,0 +1,57 @@
/* -*- 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) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
/**
* This interface supports low-level script load/unload debug hooks.
* <p>
* This interface can be implemented and used to hook script loading
* and unloading. org.mozilla.javascript.debug.IDebugManager uses this
* system and provides a higher level abstraction more appropriate
* as a debugger API.
*
* @see org.mozilla.javascript.Context#setScriptHook
* @see org.mozilla.javascript.debug.IDebugManager
* @author John Bandhauer
*/
public interface DeepScriptHook
{
/**
* Notification that a script is being loaded.
*
* @param cx current context
* @param obj script or function being loaded
*/
public void loadingScript(Context cx, NativeFunction obj);
/**
* Notification that a script is being unloaded.
* <p>
* NOTE: this currently happens as part of the Java garbage
* collection process; i.e. it is called by the finalize method
* of the script and is thus likely to be called on a system
* thread. Also, this is thus not likely to be called if there are
* any outstanding references to the script.
*
* @param cx context which originally loaded the script
* @param obj script or function being unloaded
*/
public void unloadingScript(Context cx, NativeFunction obj);
}

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,152 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
// API class
package org.mozilla.javascript;
/**
* The class of exceptions raised by the engine as described in
* ECMA edition 3. See section 15.11.6 in particular.
*/
public class EcmaError extends RuntimeException {
/**
* Create an exception with the specified detail message.
*
* Errors internal to the JavaScript engine will simply throw a
* RuntimeException.
*
* @param nativeError the NativeError object constructed for this error
* @param sourceName the name of the source reponsible for the error
* @param lineNumber the line number of the source
* @param columnNumber the columnNumber of the source (may be zero if
* unknown)
* @param lineSource the source of the line containing the error (may be
* null if unknown)
*/
public EcmaError(NativeError nativeError, String sourceName,
int lineNumber, int columnNumber, String lineSource)
{
super("EcmaError");
errorObject = nativeError;
this.sourceName = sourceName;
this.lineNumber = lineNumber;
this.columnNumber = columnNumber;
this.lineSource = lineSource;
}
/**
* Return a string representation of the error, which currently consists
* of the name of the error together with the message.
*/
public String toString() {
if (sourceName != null && lineNumber > 0)
return errorObject.toString() + " (" + sourceName +
"; line " + lineNumber + ")";
else
return errorObject.toString();
}
/**
* Gets the name of the error.
*
* ECMA edition 3 defines the following
* errors: EvalError, RangeError, ReferenceError,
* SyntaxError, TypeError, and URIError. Additional error names
* may be added in the future.
*
* See ECMA edition 3, 15.11.7.9.
*
* @return the name of the error.
*/
public String getName() {
return errorObject.getName();
}
/**
* Gets the message corresponding to the error.
*
* See ECMA edition 3, 15.11.7.10.
*
* @return an implemenation-defined string describing the error.
*/
public String getMessage() {
return errorObject.getMessage();
}
/**
* Get the name of the source containing the error, or null
* if that information is not available.
*/
public String getSourceName() {
return sourceName;
}
/**
* Returns the line number of the statement causing the error,
* or zero if not available.
*/
public int getLineNumber() {
return lineNumber;
}
/**
* Get the error object corresponding to this exception.
*/
public Scriptable getErrorObject() {
return errorObject;
}
/**
* The column number of the location of the error, or zero if unknown.
*/
public int getColumnNumber() {
return columnNumber;
}
/**
* The source of the line causing the error, or zero if unknown.
*/
public String getLineSource() {
return lineSource;
}
private NativeError errorObject;
private String sourceName;
private int lineNumber;
private int columnNumber;
private String lineSource;
}

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
@@ -52,5 +35,4 @@ public class EvaluatorException extends RuntimeException {
public EvaluatorException(String detail) {
super(detail);
}
}

View File

@@ -1,39 +1,23 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class
package org.mozilla.javascript;
import java.util.Hashtable;
@@ -42,13 +26,19 @@ import java.util.Enumeration;
/**
* Manipulate a Scriptable object as if its prototype chain were flattened.
* <p>
* This class has been deprecated in favor of the static methods
* <code>getProperty</code>, <code>putProperty</code>, and
* <code>deleteProperty</code>. Those methods provide the
* same functionality without the confusing and inefficient need to construct
* a new object instance.
* Compared to the Scriptable interface, FlattenedObject provides a view of
* Scriptable objects that is easier to use and more closely matches a script
* writer's view of a JavaScript object. <p>
*
* @see org.mozilla.javascript.ScriptableObject
* A FlattenedObject is "flattened" in the sense that multiple objects in a
* prototype chain appear to have their properties all appear in the
* FlattenedObject. <p>
*
* Another convenience provided by Flattened object is the ability to access
* properties by a single java.lang.Object id. This id is then converted into
* a String or an int before methods of the Scriptable object are called.
*
* @see org.mozilla.javascript.Scriptable
*
* @author Norris Boyd
*/
@@ -59,7 +49,6 @@ public class FlattenedObject {
* Construct a new FlattenedObject.
*
* @param object the object to be viewed with flattened properties
* @deprecated
*/
public FlattenedObject(Scriptable object) {
this.obj = object;
@@ -67,7 +56,6 @@ public class FlattenedObject {
/**
* Get the associated Scriptable object.
* @deprecated
*/
public Scriptable getObject() {
return obj;
@@ -87,7 +75,6 @@ public class FlattenedObject {
* @return true if and only if the property exists in the prototype
* chain
* @see org.mozilla.javascript.Scriptable#has
* @deprecated As of 1.5R2, replaced by ScriptableObject.getProperty
*/
public boolean hasProperty(Object id) {
String stringId = ScriptRuntime.toString(id);
@@ -114,7 +101,6 @@ public class FlattenedObject {
* @return the value of the property or the undefined value
* @see org.mozilla.javascript.Scriptable#get
* @see org.mozilla.javascript.Context#getUndefinedValue
* @deprecated As of 1.5R2, replaced by ScriptableObject.getProperty
*/
public Object getProperty(Object id) {
String s = ScriptRuntime.getStringId(id);
@@ -145,7 +131,6 @@ public class FlattenedObject {
* a Number
* @param value the value of the property
* @see org.mozilla.javascript.Scriptable#put
* @deprecated As of 1.5R2, replaced by ScriptableObject.putProperty
*/
public void putProperty(Object id, Object value) {
String s = ScriptRuntime.getStringId(id);
@@ -176,7 +161,6 @@ public class FlattenedObject {
* a Number
* @return true if the property didn't exist, or existed and was removed
* @see org.mozilla.javascript.Scriptable#delete
* @deprecated as of 1.5R2, replaced by ScriptableObject.deleteProperty
*/
public boolean deleteProperty(Object id) {
String s = ScriptRuntime.getStringId(id);
@@ -206,7 +190,6 @@ public class FlattenedObject {
* array will be unique respective to equals().)
*
* @see org.mozilla.javascript.Scriptable#getIds
* @deprecated
*/
public Object[] getIds() {
Hashtable h = new Hashtable(11);
@@ -240,7 +223,6 @@ public class FlattenedObject {
* @exception JavaScriptException if an uncaught JavaScript exception
* occurred while executing the function
* @see org.mozilla.javascript.Function#call
* @deprecated
*/
public Object call(Context cx, Scriptable thisObj, Object[] args)
throws NotAFunctionException,
@@ -249,7 +231,7 @@ public class FlattenedObject {
if (!(obj instanceof Function)) {
throw new NotAFunctionException();
}
return ScriptRuntime.call(cx, obj, thisObj, args, (Function) obj);
return ScriptRuntime.call(cx, obj, thisObj, args);
}
/**
@@ -263,7 +245,6 @@ public class FlattenedObject {
* @exception JavaScriptException if an uncaught JavaScript exception
* occurred while executing the constructor
* @see org.mozilla.javascript.Function#construct
* @deprecated
*/
public Scriptable construct(Context cx, Object[] args)
throws NotAFunctionException,
@@ -298,7 +279,6 @@ public class FlattenedObject {
* @exception JavaScriptException if an uncaught JavaScript exception
* occurred while executing the method
* @see org.mozilla.javascript.Function#call
* @deprecated
*/
public Object callMethod(Object id, Object[] args)
throws PropertyException,

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class
@@ -53,7 +36,7 @@ public interface Function extends Scriptable {
* length greater than 0.
*
* @param cx the current Context for this thread
* @param scope the scope to execute the function relative to. This is
* @param scope the scope to execute the function relative to. This
* set to the value returned by getParentScope() except
* when the function is called from a closure.
* @param thisObj the JavaScript <code>this</code> object

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -60,35 +42,7 @@ public class FunctionNode extends Node {
public boolean setRequiresActivation(boolean b) {
return itsNeedsActivation = b;
}
/**
* There are three types of functions that can be defined. The first
* is a function statement. This is a function appearing as a top-level
* statement (i.e., not nested inside some other statement) in either a
* script or a function.
*
* The second is a function expression, which is a function appearing in
* an expression except for the third type, which is...
*
* The third type is a function expression where the expression is the
* top-level expression in an expression statement.
*
* The three types of functions have different treatment and must be
* distinquished.
*/
public static final byte FUNCTION_STATEMENT = 1;
public static final byte FUNCTION_EXPRESSION = 2;
public static final byte FUNCTION_EXPRESSION_STATEMENT = 3;
public byte getFunctionType() {
return itsFunctionType;
}
public void setFunctionType(byte functionType) {
itsFunctionType = functionType;
}
protected VariableTable itsVariableTable;
protected boolean itsNeedsActivation;
protected byte itsFunctionType;
}

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Ted Neward
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class
@@ -52,11 +34,9 @@ public class FunctionObject extends NativeFunction {
*
* The first form is a member with zero or more parameters
* of the following types: Object, String, boolean, Scriptable,
* byte, short, int, float, or double. The Long type is not supported
* because the double representation of a long (which is the
* EMCA-mandated storage type for Numbers) may lose precision.
* If the member is a Method, the return value must be void or one
* of the types allowed for parameters.<p>
* byte, short, int, long, float, or double. If the member is
* a Method, the return value must be void or one of the types
* allowed for parameters.<p>
*
* The runtime will perform appropriate conversions based
* upon the type of the parameter. A parameter type of
@@ -188,9 +168,7 @@ public class FunctionObject extends NativeFunction {
} else if (type == Double.TYPE) {
hasConversions = true;
types[i] = ScriptRuntime.DoubleClass;
}
// Note that long is not supported; see comments above
else {
} else {
Object[] errArgs = { methodName };
throw Context.reportRuntimeError(
Context.getMessage("msg.bad.parms", errArgs));
@@ -209,9 +187,6 @@ public class FunctionObject extends NativeFunction {
setParentScope(scope);
setPrototype(getFunctionPrototype(scope));
Context cx = Context.getCurrentContext();
useDynamicScope = cx != null &&
cx.hasCompileFunctionsWithDynamicScope();
}
/**
@@ -297,79 +272,22 @@ public class FunctionObject extends NativeFunction {
* @see java.lang.Class#getMethods
*/
public static Method[] findMethods(Class clazz, String name) {
return findMethods(getMethodList(clazz), name);
}
static Method[] findMethods(Method[] methods, String name) {
// Usually we're just looking for a single method, so optimize
// for that case.
Vector v = null;
Method first = null;
Vector v = new Vector(5);
Method[] methods = clazz.getMethods();
for (int i=0; i < methods.length; i++) {
if (methods[i] == null)
continue;
if (methods[i].getName().equals(name)) {
if (first == null) {
first = methods[i];
} else {
if (v == null) {
v = new Vector(5);
v.addElement(first);
}
v.addElement(methods[i]);
}
if (methods[i].getDeclaringClass() == clazz &&
methods[i].getName().equals(name)){
v.addElement(methods[i]);
}
}
if (v == null) {
if (first == null)
return null;
Method[] single = { first };
return single;
if (v.size() == 0) {
return null;
}
Method[] result = new Method[v.size()];
v.copyInto(result);
return result;
}
static Method[] getMethodList(Class clazz) {
Method[] cached = methodsCache; // get once to avoid synchronization
if (cached != null && cached[0].getDeclaringClass() == clazz)
return cached;
Method[] methods = null;
try {
// getDeclaredMethods may be rejected by the security manager
// but getMethods is more expensive
if (!sawSecurityException)
methods = clazz.getDeclaredMethods();
} catch (SecurityException e) {
// If we get an exception once, give up on getDeclaredMethods
sawSecurityException = true;
}
if (methods == null) {
methods = clazz.getMethods();
}
int count = 0;
for (int i=0; i < methods.length; i++) {
if (sawSecurityException
? methods[i].getDeclaringClass() != clazz
: !Modifier.isPublic(methods[i].getModifiers()))
{
methods[i] = null;
} else {
count++;
}
}
Method[] result = new Method[count];
int j=0;
for (int i=0; i < methods.length; i++) {
if (methods[i] != null)
result[j++] = methods[i];
}
if (result.length > 0 && Context.isCachingEnabled)
methodsCache = result;
return result;
}
/**
* Define this function as a JavaScript constructor.
* <p>
@@ -415,7 +333,7 @@ public class FunctionObject extends NativeFunction {
}
static public Object convertArg(Scriptable scope,
Object arg, Class desired)
Object arg, Class desired)
{
if (desired == ScriptRuntime.BooleanClass
|| desired == Boolean.TYPE)
@@ -431,10 +349,6 @@ public class FunctionObject extends NativeFunction {
return new Double(ScriptRuntime.toNumber(arg));
else if (desired == ScriptRuntime.ScriptableClass)
return ScriptRuntime.toObject(scope, arg);
else if (desired == ScriptRuntime.ObjectClass)
return arg;
// Note that the long type is not supported; see the javadoc for
// the constructor for this class
else {
Object[] errArgs = { desired.getName() };
throw Context.reportRuntimeError(
@@ -449,8 +363,8 @@ public class FunctionObject extends NativeFunction {
* Implements Function.call.
*
* @see org.mozilla.javascript.Function#call
* @exception JavaScriptException if the underlying Java method or
* constructor threw an exception
* @exception JavaScriptException if the underlying Java method or constructor
* threw an exception
*/
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args)
@@ -463,15 +377,19 @@ public class FunctionObject extends NativeFunction {
// OPT: cache "clazz"?
Class clazz = method != null ? method.getDeclaringClass()
: ctor.getDeclaringClass();
while (!clazz.isInstance(thisObj)) {
thisObj = thisObj.getPrototype();
if (thisObj == null || !useDynamicScope) {
// Couldn't find an object to call this on.
Object[] errArgs = { names[0] };
String msg = Context.getMessage("msg.incompat.call", errArgs);
throw NativeGlobal.constructError(cx, "TypeError", msg, scope);
}
Scriptable p = thisObj;
while (p != null && !clazz.isInstance(p)) {
// Walk up the prototype chain to find an object to call the
// method on
p = p.getPrototype();
}
if (p == null) {
// Couldn't find an object to call this on.
Object[] errArgs = { names[0] };
throw Context.reportRuntimeError(
Context.getMessage("msg.incompat.call", errArgs));
}
thisObj = p;
}
Object[] invokeArgs;
int i;
@@ -550,26 +468,6 @@ public class FunctionObject extends NativeFunction {
result.setParentScope(parent);
}
return result;
} else if (method != null && !isStatic) {
Scriptable result;
try {
result = (Scriptable) method.getDeclaringClass().newInstance();
} catch (IllegalAccessException e) {
throw WrappedException.wrapException(e);
} catch (InstantiationException e) {
throw WrappedException.wrapException(e);
}
result.setPrototype(getClassPrototype());
result.setParentScope(getParentScope());
Object val = call(cx, scope, result, args);
if (val != null && val != Undefined.instance &&
val instanceof Scriptable)
{
return (Scriptable) val;
}
return result;
}
@@ -597,8 +495,6 @@ public class FunctionObject extends NativeFunction {
Throwable target = e.getTargetException();
if (target instanceof EvaluatorException)
throw (EvaluatorException) target;
if (target instanceof EcmaError)
throw (EcmaError) target;
Scriptable scope = thisObj == null ? this : thisObj;
throw JavaScriptException.wrapException(scope, target);
}
@@ -620,10 +516,6 @@ public class FunctionObject extends NativeFunction {
private static final short VARARGS_METHOD = -1;
private static final short VARARGS_CTOR = -2;
private static boolean sawSecurityException;
static Method[] methodsCache;
Method method;
Constructor ctor;
@@ -632,5 +524,4 @@ public class FunctionObject extends NativeFunction {
private short lengthPropertyValue;
private boolean hasVoidReturn;
private boolean isStatic;
private boolean useDynamicScope;
}

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -39,14 +22,16 @@ package org.mozilla.javascript;
* This class allows the creation of nodes, and follows the Factory pattern.
*
* @see Node
* @see NodeFactory
* @see ASTFactory
* @author Mike McCabe
* @author Norris Boyd
*/
public class IRFactory {
public IRFactory(TokenStream ts, Scriptable scope) {
public IRFactory(TokenStream ts) {
this.ts = ts;
this.scope = scope;
}
/**
@@ -212,13 +197,9 @@ public class IRFactory {
public Object createFunction(String name, Object args, Object statements,
String sourceName, int baseLineno,
int endLineno, Object source,
boolean isExpr)
int endLineno, Object source)
{
FunctionNode f = (FunctionNode) createFunctionNode(name, args,
statements);
f.setFunctionType(isExpr ? FunctionNode.FUNCTION_EXPRESSION
: FunctionNode.FUNCTION_STATEMENT);
Node f = (Node) createFunctionNode(name, args, statements);
f.putProp(Node.SOURCENAME_PROP, sourceName);
f.putProp(Node.BASE_LINENO_PROP, new Integer(baseLineno));
f.putProp(Node.END_LINENO_PROP, new Integer(endLineno));
@@ -228,12 +209,6 @@ public class IRFactory {
result.putProp(Node.FUNCTION_PROP, f);
return result;
}
public void setFunctionExpressionStatement(Object o) {
Node n = (Node) o;
FunctionNode f = (FunctionNode) n.getProp(Node.FUNCTION_PROP);
f.setFunctionType(FunctionNode.FUNCTION_EXPRESSION_STATEMENT);
}
/**
* Add a child to the back of the given node. This function
@@ -731,6 +706,7 @@ public class IRFactory {
childNode.removeChild(left);
childNode.removeChild(right);
} else {
reportError("msg.del.nonref");
return new Node(TokenStream.PRIMARY,
new Integer(TokenStream.TRUE));
}
@@ -853,8 +829,6 @@ public class IRFactory {
return createSetProp(nodeType, nodeOp, left.getFirstChild(),
id, right, convert, postfix);
default:
// TODO: This should be a ReferenceError--but that's a runtime
// exception. Should we compile an exception into the code?
reportError("msg.bad.lhs.assign");
return left;
}
@@ -946,11 +920,8 @@ public class IRFactory {
public static boolean hasSideEffects(Node exprTree) {
switch (exprTree.getType()) {
case TokenStream.INC:
case TokenStream.DEC:
case TokenStream.SETPROP:
case TokenStream.SETELEM:
case TokenStream.SETNAME:
case TokenStream.CALL:
case TokenStream.NEW:
return true;
@@ -989,20 +960,13 @@ public class IRFactory {
if (nodeOp == TokenStream.NOP)
return new Node(type, obj, id, expr);
/*
* If the RHS expression could modify the LHS we have
* to construct a temporary to hold the LHS context
* prior to running the expression. Ditto, if the id
* expression has side-effects.
*
* XXX If the hasSideEffects tests take too long, we
* could make this an optimizer-only transform
* and always do the temp assignment otherwise.
*
if the RHS expression could modify the LHS we have
to construct a temporary to hold the LHS context
prior to running the expression
*/
Node tmp1, tmp2, opLeft;
if (hasSideEffects(expr)
|| hasSideEffects(id)
|| (obj.getType() != TokenStream.NAME)) {
if (hasSideEffects(expr) || (obj.getType() != TokenStream.NAME)) {
tmp1 = createNewTemp(obj);
Node useTmp1 = createUseTemp(tmp1);
@@ -1032,25 +996,14 @@ public class IRFactory {
}
private void reportError(String msgResource) {
if (scope != null)
throw NativeGlobal.constructError(
Context.getContext(), "SyntaxError",
ScriptRuntime.getMessage(msgResource, null),
scope);
else {
String message = Context.getMessage(msgResource, null);
Context.reportError(message, ts.getSourceName(), ts.getLineno(),
ts.getLine(), ts.getOffset());
}
String message = Context.getMessage(msgResource, null);
Context.reportError(message, ts.getSourceName(), ts.getLineno(),
ts.getLine(), ts.getOffset());
}
// Only needed to get file/line information. Could create an interface
// that TokenStream implements if we want to make the connection less
// direct.
private TokenStream ts;
// Only needed to pass to the Erorr exception constructors
private Scriptable scope;
}

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* 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.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class
@@ -116,8 +99,7 @@ public class ImporterTopLevel extends ScriptableObject {
}
String s = ((NativeJavaClass) cl).getClassObject().getName();
String n = s.substring(s.lastIndexOf('.')+1);
Object val = this.get(n, this);
if (val != NOT_FOUND && val != cl) {
if (this.has(n, this)) {
String[] args = { n };
throw Context.reportRuntimeError(
Context.getMessage("msg.prop.defined", args));
@@ -141,4 +123,4 @@ public class ImporterTopLevel extends ScriptableObject {
}
private Vector importedPackages;
}
}

View File

@@ -1,53 +1,29 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
import java.util.*;
import org.mozilla.javascript.debug.DebuggableScript;
class InterpretedFunction extends NativeFunction implements DebuggableScript {
class InterpretedFunction extends NativeFunction {
InterpretedFunction(InterpreterData theData, Context cx)
{
itsData = theData;
init(cx);
}
void init(Context cx)
{
// probably too much copying going on from theData to the InterpretedFunction object
// should pass them as parameters - unless we need them in the data block anyway?
@@ -58,56 +34,22 @@ class InterpretedFunction extends NativeFunction implements DebuggableScript {
argCount = (short)itsData.itsVariableTable.getParameterCount();
source = itsData.itsSource;
nestedFunctions = itsData.itsNestedFunctions;
if (cx != null)
version = (short)cx.getLanguageVersion();
}
InterpretedFunction(InterpretedFunction theOther,
Scriptable theScope, Context cx)
{
itsData = theOther.itsData;
itsClosure = theScope;
init(cx);
version = (short)cx.getLanguageVersion();
}
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
itsData.itsCX = cx;
if (itsClosure != null)
scope = itsClosure;
else if (!itsData.itsUseDynamicScope)
scope = getParentScope();
if (itsData.itsNeedsActivation)
scope = ScriptRuntime.initVarObj(cx, scope, this, thisObj, args);
itsData.itsCX = cx;
itsData.itsScope = scope;
itsData.itsThisObj = thisObj;
itsData.itsInArgs = args;
return Interpreter.interpret(itsData, this);
return Interpreter.interpret(itsData);
}
public Scriptable getScriptable() {
return this;
}
public String getSourceName() {
return itsData.itsSourceFile;
}
public Enumeration getLineNumbers() {
return itsData.itsLineNumberTable.keys();
}
public boolean placeBreakpoint(int line) { // XXX throw exn?
return itsData.placeBreakpoint(line);
}
public boolean removeBreakpoint(int line) {
return itsData.removeBreakpoint(line);
}
InterpreterData itsData;
Scriptable itsClosure;
}

View File

@@ -1,45 +1,24 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
import org.mozilla.javascript.debug.*;
import java.util.*;
public class InterpretedScript extends NativeScript implements DebuggableScript {
public class InterpretedScript extends NativeScript {
InterpretedScript(InterpreterData theData, Context cx)
{
@@ -62,35 +41,15 @@ public class InterpretedScript extends NativeScript implements DebuggableScript
Scriptable thisObj, Object[] args)
throws JavaScriptException
{
scope = ScriptRuntime.initScript(cx, scope, this, thisObj,
itsData.itsFromEvalCode);
scope = ScriptRuntime.initScript(cx, scope, this, thisObj);
itsData.itsCX = cx;
itsData.itsScope = scope;
itsData.itsThisObj = thisObj;
itsData.itsInArgs = args;
return Interpreter.interpret(itsData, this);
return Interpreter.interpret(itsData);
}
public Scriptable getScriptable() {
return this;
}
public String getSourceName() {
return itsData.itsSourceFile;
}
public Enumeration getLineNumbers() {
return itsData.itsLineNumberTable.keys();
}
public boolean placeBreakpoint(int line) { // XXX throw exn?
return itsData.placeBreakpoint(line);
}
public boolean removeBreakpoint(int line) {
return itsData.removeBreakpoint(line);
}
InterpreterData itsData;
}

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Patrick Beard
* Norris Boyd
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -41,20 +22,18 @@ import java.io.*;
import java.util.Vector;
import java.util.Enumeration;
import org.mozilla.javascript.debug.*;
public class Interpreter extends LabelTable {
public static final boolean printICode = false;
public IRFactory createIRFactory(TokenStream ts,
ClassNameHelper nameHelper, Scriptable scope)
ClassNameHelper nameHelper)
{
return new IRFactory(ts, scope);
return new IRFactory(ts);
}
public Node transform(Node tree, TokenStream ts, Scriptable scope) {
return (new NodeTransformer()).transform(tree, null, ts, scope);
public Node transform(Node tree, TokenStream ts) {
return (new NodeTransformer()).transform(tree, null, ts);
}
public Object compile(Context cx, Scriptable scope, Node tree,
@@ -64,13 +43,11 @@ public class Interpreter extends LabelTable {
throws IOException
{
version = cx.getLanguageVersion();
itsData = new InterpreterData(0, 0, 0, securityDomain,
cx.hasCompileFunctionsWithDynamicScope());
itsData = new InterpreterData(0, 0, 0, securityDomain);
if (tree instanceof FunctionNode) {
FunctionNode f = (FunctionNode) tree;
InterpretedFunction result =
generateFunctionICode(cx, scope, f, securityDomain);
result.itsData.itsFunctionType = f.getFunctionType();
createFunctionObject(result, scope);
return result;
}
@@ -104,7 +81,7 @@ public class Interpreter extends LabelTable {
Node left = regexp.getFirstChild();
Node right = regexp.getLastChild();
result[i] = rep.newRegExp(cx, scope, left.getString(),
(left != right) ? right.getString() : null, false);
(left != right) ? right.getString() : null);
regexp.putProp(Node.REGEXP_PROP, new Integer(i));
}
return result;
@@ -130,10 +107,7 @@ public class Interpreter extends LabelTable {
itsData.itsRegExpLiterals = regExpLiterals;
if (printICode) dumpICode(itsData);
InterpretedScript result = new InterpretedScript(itsData, cx);
if (cx.debugger != null)
cx.debugger.handleCompilationDone(cx, result, null);
return result;
return new InterpretedScript(itsData, cx);
}
private void generateNestedFunctions(Scriptable scope,
@@ -144,10 +118,7 @@ public class Interpreter extends LabelTable {
for (short i = 0; i < itsFunctionList.size(); i++) {
FunctionNode def = (FunctionNode)itsFunctionList.elementAt(i);
Interpreter jsi = new Interpreter();
jsi.itsSourceFile = itsSourceFile;
jsi.itsData = new InterpreterData(0, 0, 0, securityDomain,
cx.hasCompileFunctionsWithDynamicScope());
jsi.itsData.itsFunctionType = def.getFunctionType();
jsi.itsData = new InterpreterData(0, 0, 0, securityDomain);
jsi.itsInFunctionFlag = true;
itsNestedFunctions[i] = jsi.generateFunctionICode(cx, scope, def,
securityDomain);
@@ -168,24 +139,17 @@ public class Interpreter extends LabelTable {
regExpLiterals = generateRegExpLiterals(cx, scope, regexps);
VariableTable varTable = theFunction.getVariableTable();
boolean needsActivation = theFunction.requiresActivation() ||
cx.isGeneratingDebug();
generateICodeFromTree(theFunction.getLastChild(),
varTable, needsActivation,
varTable, theFunction.requiresActivation(),
securityDomain);
itsData.itsName = theFunction.getFunctionName();
itsData.itsSourceFile = (String) theFunction.getProp(
Node.SOURCENAME_PROP);
itsData.itsSource = (String)theFunction.getProp(Node.SOURCE_PROP);
itsData.itsNestedFunctions = itsNestedFunctions;
itsData.itsRegExpLiterals = regExpLiterals;
if (printICode) dumpICode(itsData);
InterpretedFunction result = new InterpretedFunction(itsData, cx);
if (cx.debugger != null)
cx.debugger.handleCompilationDone(cx, result, null);
return result;
return new InterpretedFunction(itsData, cx);
}
boolean itsInFunctionFlag;
@@ -199,30 +163,12 @@ public class Interpreter extends LabelTable {
int itsLineNumber = 0;
InterpretedFunction[] itsNestedFunctions = null;
private int updateLineNumber(Node node, int iCodeTop)
private void updateLineNumber(Node node)
{
Object datum = node.getDatum();
if (datum == null || !(datum instanceof Number))
return iCodeTop;
short lineNumber = ((Number) datum).shortValue();
if (lineNumber != itsLineNumber) {
itsLineNumber = lineNumber;
if (itsData.itsLineNumberTable == null &&
Context.getCurrentContext().isGeneratingDebug())
{
itsData.itsLineNumberTable = new java.util.Hashtable();
}
if (itsData.itsLineNumberTable != null) {
itsData.itsLineNumberTable.put(new Integer(lineNumber),
new Integer(iCodeTop));
}
iCodeTop = addByte((byte) TokenStream.LINE, iCodeTop);
iCodeTop = addByte((byte)(lineNumber >> 8), iCodeTop);
iCodeTop = addByte((byte)(lineNumber & 0xff), iCodeTop);
}
return iCodeTop;
return;
itsLineNumber = ((Number) datum).shortValue();
}
private void badTree(Node node)
@@ -257,7 +203,7 @@ public class Interpreter extends LabelTable {
break;
case TokenStream.SCRIPT :
iCodeTop = updateLineNumber(node, iCodeTop);
updateLineNumber(node);
while (child != null) {
if (child.getType() != TokenStream.FUNCTION)
iCodeTop = generateICode(child, iCodeTop);
@@ -266,7 +212,7 @@ public class Interpreter extends LabelTable {
break;
case TokenStream.CASE :
iCodeTop = updateLineNumber(node, iCodeTop);
updateLineNumber(node);
child = child.getNextSibling();
while (child != null) {
iCodeTop = generateICode(child, iCodeTop);
@@ -281,7 +227,7 @@ public class Interpreter extends LabelTable {
case TokenStream.BLOCK :
case TokenStream.VOID :
case TokenStream.NOP :
iCodeTop = updateLineNumber(node, iCodeTop);
updateLineNumber(node);
while (child != null) {
iCodeTop = generateICode(child, iCodeTop);
child = child.getNextSibling();
@@ -297,7 +243,7 @@ public class Interpreter extends LabelTable {
break;
case TokenStream.SWITCH : {
iCodeTop = updateLineNumber(node, iCodeTop);
updateLineNumber(node);
iCodeTop = generateICode(child, iCodeTop);
int theLocalSlot = itsData.itsMaxLocals++;
iCodeTop = addByte((byte) TokenStream.NEWTEMP, iCodeTop);
@@ -391,20 +337,9 @@ public class Interpreter extends LabelTable {
case TokenStream.NEW :
case TokenStream.CALL : {
if (itsSourceFile != null && (itsData.itsSourceFile == null || ! itsSourceFile.equals(itsData.itsSourceFile)))
itsData.itsSourceFile = itsSourceFile;
iCodeTop = addByte((byte)TokenStream.SOURCEFILE, iCodeTop);
int childCount = 0;
short nameIndex = -1;
while (child != null) {
iCodeTop = generateICode(child, iCodeTop);
if (nameIndex == -1) {
if (child.getType() == TokenStream.NAME)
nameIndex = (short)(itsData.itsStringTableIndex - 1);
else if (child.getType() == TokenStream.GETPROP)
nameIndex = (short)(itsData.itsStringTableIndex - 1);
}
child = child.getNextSibling();
childCount++;
}
@@ -415,11 +350,8 @@ public class Interpreter extends LabelTable {
iCodeTop = addByte((byte)(itsLineNumber & 0xff), iCodeTop);
iCodeTop = addString(itsSourceFile, iCodeTop);
}
else {
else
iCodeTop = addByte((byte) type, iCodeTop);
iCodeTop = addByte((byte)(nameIndex >> 8), iCodeTop);
iCodeTop = addByte((byte)(nameIndex & 0xFF), iCodeTop);
}
itsStackDepth -= (childCount - 1); // always a result value
// subtract from child count to account for [thisObj &] fun
@@ -431,8 +363,6 @@ public class Interpreter extends LabelTable {
iCodeTop = addByte((byte)(childCount & 0xff), iCodeTop);
if (childCount > itsData.itsMaxArgs)
itsData.itsMaxArgs = childCount;
iCodeTop = addByte((byte)TokenStream.SOURCEFILE, iCodeTop);
}
break;
@@ -672,7 +602,7 @@ public class Interpreter extends LabelTable {
}
else {
iCodeTop = addByte((byte) TokenStream.GETVAR, iCodeTop);
iCodeTop = addByte((byte) index, iCodeTop);
iCodeTop = addByte((byte)index, iCodeTop);
iCodeTop = addByte((byte) TokenStream.TYPEOF, iCodeTop);
}
itsStackDepth++;
@@ -791,7 +721,7 @@ public class Interpreter extends LabelTable {
case TokenStream.POP :
case TokenStream.POPV :
iCodeTop = updateLineNumber(node, iCodeTop);
updateLineNumber(node);
case TokenStream.ENTERWITH :
iCodeTop = generateICode(child, iCodeTop);
iCodeTop = addByte((byte) type, iCodeTop);
@@ -849,20 +779,12 @@ public class Interpreter extends LabelTable {
if (itsStackDepth > itsData.itsMaxStack)
itsData.itsMaxStack = itsStackDepth;
}
/*
When the following child is the catchTarget,
the current child is the goto at the end of
the try statemets, we need to emit the endtry
before that goto.
*/
if (child.getNextSibling() == catchTarget)
iCodeTop = addByte((byte) TokenStream.ENDTRY,
iCodeTop);
iCodeTop = generateICode(child, iCodeTop);
lastChild = child;
child = child.getNextSibling();
}
itsStackDepth = 0;
iCodeTop = addByte((byte) TokenStream.ENDTRY, iCodeTop);
if (finallyTarget != null) {
// normal flow goes around the finally handler stublet
int skippy = acquireLabel();
@@ -892,14 +814,14 @@ public class Interpreter extends LabelTable {
break;
case TokenStream.THROW :
iCodeTop = updateLineNumber(node, iCodeTop);
updateLineNumber(node);
iCodeTop = generateICode(child, iCodeTop);
iCodeTop = addByte((byte) TokenStream.THROW, iCodeTop);
itsStackDepth--;
break;
case TokenStream.RETURN :
iCodeTop = updateLineNumber(node, iCodeTop);
updateLineNumber(node);
if (child != null)
iCodeTop = generateICode(child, iCodeTop);
else {
@@ -1141,7 +1063,7 @@ public class Interpreter extends LabelTable {
for (int pc = 0; pc < iCodeLength; ) {
out.print("[" + pc + "] ");
switch ((int)(iCode[pc] & 0xff)) {
switch (iCode[pc]) {
case TokenStream.SCOPE :
case TokenStream.GETPROTO :
case TokenStream.GETPARENT :
@@ -1199,7 +1121,6 @@ public class Interpreter extends LabelTable {
case TokenStream.FALSE :
case TokenStream.TRUE :
case TokenStream.UNDEFINED :
case TokenStream.SOURCEFILE :
out.println(TokenStream.tokenToName(iCode[pc] & 0xff));
break;
case TokenStream.GOSUB :
@@ -1256,13 +1177,11 @@ public class Interpreter extends LabelTable {
case TokenStream.CLOSURE :
case TokenStream.NEW :
case TokenStream.CALL : {
int count = (iCode[pc + 3] << 8) | (iCode[pc + 4] & 0xFF);
int count = (iCode[pc + 1] << 8) | (iCode[pc + 2] & 0xFF);
out.println(
TokenStream.tokenToName(iCode[pc] & 0xff) +
" " + count + " \"" +
getString(theData.itsStringTable, iCode,
pc + 1) + "\"");
pc += 4;
" " + count);
pc += 2;
}
break;
case TokenStream.NUMBER :
@@ -1287,13 +1206,6 @@ public class Interpreter extends LabelTable {
"\"");
pc += 2;
break;
case TokenStream.LINE : {
int line = (iCode[pc + 1] << 8) | (iCode[pc + 2] & 0xFF);
out.println(
TokenStream.tokenToName(iCode[pc] & 0xff) + " : " + line);
pc += 2;
}
break;
default :
out.close();
throw new RuntimeException("Unknown icode : "
@@ -1315,19 +1227,11 @@ public class Interpreter extends LabelTable {
{
fn.setPrototype(ScriptableObject.getClassPrototype(scope, "Function"));
fn.setParentScope(scope);
InterpreterData id = fn.itsData;
if (id.itsName.length() == 0)
return;
if ((id.itsFunctionType == FunctionNode.FUNCTION_STATEMENT &&
fn.itsClosure == null) ||
(id.itsFunctionType == FunctionNode.FUNCTION_EXPRESSION_STATEMENT &&
fn.itsClosure != null))
{
ScriptRuntime.setProp(scope, fn.itsData.itsName, fn, scope);
}
if (fn.itsData.itsName.length() > 0)
ScriptRuntime.setName(scope, fn, scope, fn.itsData.itsName);
}
public static Object interpret(InterpreterData theData, Scriptable fnOrScript)
public static Object interpret(InterpreterData theData)
throws JavaScriptException
{
Object lhs;
@@ -1342,18 +1246,18 @@ public class Interpreter extends LabelTable {
local = new Object[theData.itsMaxLocals];
Object[] vars = null;
final Scriptable undefined = Undefined.instance;
int i = theData.itsVariableTable.size();
if (i > 0) {
vars = new Object[i];
for (i = 0; i < theData.itsVariableTable.getParameterCount(); i++) {
if (i >= theData.itsInArgs.length)
vars[i] = undefined;
vars[i] = Undefined.instance;
else
vars[i] = theData.itsInArgs[i];
}
for ( ; i < vars.length; i++)
vars[i] = undefined;
vars[i] = Undefined.instance;
}
Context cx = theData.itsCX;
@@ -1370,7 +1274,7 @@ public class Interpreter extends LabelTable {
int count;
int slot;
String name = null;
String name;
Object[] outArgs;
@@ -1382,13 +1286,7 @@ public class Interpreter extends LabelTable {
int[] finallyStack = null;
Scriptable[] scopeStack = null;
int tryStackTop = 0;
InterpreterFrame frame = null;
if (cx.debugger != null) {
frame = new InterpreterFrame(scope, theData, fnOrScript);
cx.pushFrame(frame);
}
if (theData.itsMaxTryDepth > 0) {
catchStack = new int[theData.itsMaxTryDepth];
finallyStack = new int[theData.itsMaxTryDepth];
@@ -1402,13 +1300,11 @@ public class Interpreter extends LabelTable {
*/
Object savedSecurityDomain = cx.interpreterSecurityDomain;
cx.interpreterSecurityDomain = theData.securityDomain;
Object result = undefined;
Scriptable theThisObj = theData.itsThisObj;
Object result = Undefined.instance;
while (pc < iCodeLength) {
try {
switch ((int)(iCode[pc] & 0xff)) {
switch (iCode[pc]) {
case TokenStream.ENDTRY :
tryStackTop--;
break;
@@ -1451,13 +1347,13 @@ public class Interpreter extends LabelTable {
case TokenStream.INSTANCEOF :
rhs = stack[stackTop--];
lhs = stack[stackTop];
stack[stackTop] = new Boolean(
ScriptRuntime.instanceOf(scope, lhs, rhs));
stack[stackTop]
= new Boolean(ScriptRuntime.instanceOf(lhs, rhs));
break;
case TokenStream.EQ :
rhs = stack[stackTop--];
lhs = stack[stackTop];
stack[stackTop] = ScriptRuntime.eqB(lhs, rhs);
stack[stackTop] = ScriptRuntime.eqB(rhs, lhs);
break;
case TokenStream.NE :
rhs = stack[stackTop--];
@@ -1689,43 +1585,30 @@ public class Interpreter extends LabelTable {
lhs = stack[stackTop];
stack[stackTop] = ScriptRuntime.callSpecial(
cx, lhs, rhs, outArgs,
theThisObj, scope, name, i);
theData.itsThisObj,
scope, name, i);
pc += 6;
break;
case TokenStream.CALL :
count = (iCode[pc + 3] << 8) | (iCode[pc + 4] & 0xFF);
count = (iCode[pc + 1] << 8) | (iCode[pc + 2] & 0xFF);
outArgs = new Object[count];
for (i = count - 1; i >= 0; i--)
outArgs[i] = stack[stackTop--];
rhs = stack[stackTop--];
lhs = stack[stackTop];
if (lhs == undefined) {
lhs = getString(theData.itsStringTable, iCode,
pc + 1);
}
Scriptable calleeScope = scope;
if (theData.itsNeedsActivation) {
calleeScope = ScriptableObject.getTopLevelScope(scope);
}
stack[stackTop] = ScriptRuntime.call(cx, lhs, rhs,
outArgs,
calleeScope);
pc += 4;
stack[stackTop] = ScriptRuntime.call(cx, lhs,
rhs, outArgs);
pc += 2;
break;
case TokenStream.NEW :
count = (iCode[pc + 3] << 8) | (iCode[pc + 4] & 0xFF);
count = (iCode[pc + 1] << 8) | (iCode[pc + 2] & 0xFF);
outArgs = new Object[count];
for (i = count - 1; i >= 0; i--)
outArgs[i] = stack[stackTop--];
lhs = stack[stackTop];
if (lhs == undefined) {
lhs = getString(theData.itsStringTable, iCode,
pc + 1);
}
stack[stackTop] = ScriptRuntime.newObject(cx, lhs,
outArgs,
scope);
pc += 4;
outArgs, scope);
pc += 2;
break;
case TokenStream.TYPEOF :
lhs = stack[stackTop];
@@ -1794,7 +1677,7 @@ public class Interpreter extends LabelTable {
stack[++stackTop] = null;
break;
case TokenStream.THIS :
stack[++stackTop] = theThisObj;
stack[++stackTop] = theData.itsThisObj;
break;
case TokenStream.FALSE :
stack[++stackTop] = Boolean.FALSE;
@@ -1863,13 +1746,9 @@ public class Interpreter extends LabelTable {
stack[++stackTop] = scope;
break;
case TokenStream.CLOSURE :
i = (iCode[pc + 1] << 8) | (iCode[pc + 2] & 0xFF);
stack[++stackTop]
= new InterpretedFunction(
theData.itsNestedFunctions[i],
scope, cx);
createFunctionObject(
(InterpretedFunction)stack[stackTop], scope);
i = (iCode[pc + 1] << 8) | (iCode[pc + 2] & 0xFF);
stack[++stackTop] = new NativeClosure(cx, scope,
theData.itsNestedFunctions[i]);
pc += 2;
break;
case TokenStream.OBJECT :
@@ -1877,21 +1756,6 @@ public class Interpreter extends LabelTable {
stack[++stackTop] = theData.itsRegExpLiterals[i];
pc += 2;
break;
case TokenStream.SOURCEFILE :
cx.interpreterSourceFile = theData.itsSourceFile;
break;
case TokenStream.LINE :
case TokenStream.BREAKPOINT :
i = (iCode[pc + 1] << 8) | (iCode[pc + 2] & 0xFF);
cx.interpreterLine = i;
frame.setLineNumber(i);
if ((iCode[pc] & 0xff) == TokenStream.BREAKPOINT ||
cx.inLineStepMode)
{
cx.getDebugger().handleBreakpointHit(cx);
}
pc += 2;
break;
default :
dumpICode(theData);
throw new RuntimeException("Unknown icode : "
@@ -1899,39 +1763,7 @@ public class Interpreter extends LabelTable {
}
pc++;
}
catch (EcmaError ee) {
if (cx.debugger != null)
cx.debugger.handleExceptionThrown(cx, ee.getErrorObject());
// an offical ECMA error object,
// handle as if it were a JavaScriptException
stackTop = 0;
cx.interpreterSecurityDomain = null;
if (tryStackTop > 0) {
pc = catchStack[--tryStackTop];
scope = scopeStack[tryStackTop];
if (pc == 0) {
pc = finallyStack[tryStackTop];
if (pc == 0) {
if (frame != null)
cx.popFrame();
throw ee;
}
}
stack[0] = ee.getErrorObject();
} else {
if (frame != null)
cx.popFrame();
throw ee;
}
// We caught an exception; restore this function's
// security domain.
cx.interpreterSecurityDomain = theData.securityDomain;
}
catch (JavaScriptException jsx) {
if (cx.debugger != null) {
cx.debugger.handleExceptionThrown(cx,
ScriptRuntime.unwrapJavaScriptException(jsx));
}
stackTop = 0;
cx.interpreterSecurityDomain = null;
if (tryStackTop > 0) {
@@ -1939,55 +1771,45 @@ public class Interpreter extends LabelTable {
scope = scopeStack[tryStackTop];
if (pc == 0) {
pc = finallyStack[tryStackTop];
if (pc == 0) {
if (frame != null)
cx.popFrame();
if (pc == 0)
throw jsx;
}
stack[0] = jsx;
} else {
stack[0] = ScriptRuntime.unwrapJavaScriptException(jsx);
}
} else {
if (frame != null)
cx.popFrame();
throw jsx;
else
stack[0] = ScriptRuntime.unwrapJavaScriptException(jsx);
}
else
throw jsx;
// We caught an exception; restore this function's
// security domain.
cx.interpreterSecurityDomain = theData.securityDomain;
}
/* debug only, will be going soon
catch (ArrayIndexOutOfBoundsException oob) {
System.out.println("OOB @ " + pc + " " + oob + " in " + theData.itsName + " " + oob.getMessage());
throw oob;
}
*/
catch (RuntimeException jx) {
if (cx.debugger != null)
cx.debugger.handleExceptionThrown(cx, jx);
cx.interpreterSecurityDomain = null;
if (tryStackTop > 0) {
stackTop = 0;
stack[0] = jx;
pc = finallyStack[--tryStackTop];
scope = scopeStack[tryStackTop];
if (pc == 0) {
if (frame != null)
cx.popFrame();
throw jx;
}
} else {
if (frame != null)
cx.popFrame();
throw jx;
if (pc == 0) throw jx;
}
else
throw jx;
// We caught an exception; restore this function's
// security domain.
cx.interpreterSecurityDomain = theData.securityDomain;
}
}
cx.interpreterSecurityDomain = savedSecurityDomain;
if (frame != null)
cx.popFrame();
return result;
}
private int version;
private boolean inLineStepMode;
private Debugger debugger;
}

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -44,8 +27,7 @@ class InterpreterData {
static final int INITIAL_NUMBERTABLE_SIZE = 64;
InterpreterData(int lastICodeTop, int lastStringTableIndex,
int lastNumberTableIndex, Object securityDomain,
boolean useDynamicScope)
int lastNumberTableIndex, Object securityDomain)
{
itsICodeTop = lastICodeTop == 0
? INITIAL_MAX_ICODE_LENGTH
@@ -60,54 +42,16 @@ class InterpreterData {
? INITIAL_NUMBERTABLE_SIZE
: lastNumberTableIndex * 2];
itsUseDynamicScope = useDynamicScope;
if (securityDomain == null && Context.isSecurityDomainRequired())
throw new SecurityException("Required security context missing");
this.securityDomain = securityDomain;
}
public boolean placeBreakpoint(int line) { // XXX throw exn?
int offset = getOffset(line);
if (offset != -1 && (itsICode[offset] == TokenStream.LINE ||
itsICode[offset] == TokenStream.BREAKPOINT))
{
itsICode[offset] = (byte) TokenStream.BREAKPOINT;
return true;
}
return false;
}
public boolean removeBreakpoint(int line) {
int offset = getOffset(line);
if (offset != -1 && itsICode[offset] == TokenStream.BREAKPOINT)
{
itsICode[offset] = (byte) TokenStream.LINE;
return true;
}
return false;
}
private int getOffset(int line) {
Object offset = itsLineNumberTable.get(new Integer(line));
if (offset != null && offset instanceof Integer) {
int i = ((Integer)offset).intValue();
if (i >= 0 && i < itsICode.length)
{
return i;
}
}
return -1;
}
VariableTable itsVariableTable;
String itsName;
String itsSource;
String itsSourceFile;
boolean itsNeedsActivation;
boolean itsFromEvalCode;
boolean itsUseDynamicScope;
byte itsFunctionType;
String[] itsStringTable;
int itsStringTableIndex;
@@ -126,8 +70,6 @@ class InterpreterData {
int itsMaxArgs;
int itsMaxStack;
int itsMaxTryDepth;
java.util.Hashtable itsLineNumberTable;
Object securityDomain;

View File

@@ -1,77 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
package org.mozilla.javascript;
import java.util.Vector;
import org.mozilla.javascript.debug.*;
class InterpreterFrame implements Frame {
InterpreterFrame(Scriptable scope, InterpreterData data, Scriptable obj) {
this.scope = scope;
this.data = data;
this.lineNumber = -1;
this.obj = obj;
}
public Scriptable getVariableObject() {
return scope;
}
public String getSourceName() {
return data.itsSourceFile;
}
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
public int getLineNumber() {
return lineNumber;
}
public DebuggableScript getScript() {
if (obj instanceof DebuggableScript)
return (DebuggableScript) obj;
return null;
}
private Scriptable scope;
private InterpreterData data;
private Scriptable obj;
private int lineNumber;
}

View File

@@ -1,41 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Patrick Beard
* Norris Boyd
* Mike McCabe
* Matthias Radestock
* Andi Vajda
* Andrew Wason
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -46,27 +24,10 @@ import java.io.*;
import java.util.*;
public class JavaAdapter extends ScriptableObject {
public boolean equals(Object obj) {
return super.equals(obj);
}
public String getClassName() {
return "JavaAdapter";
}
public static Object convertResult(Object result, String classname)
throws ClassNotFoundException
{
Class c = ScriptRuntime.loadClassName(classname);
if (result == Undefined.instance &&
(c != ScriptRuntime.ObjectClass &&
c != ScriptRuntime.StringClass))
{
// Avoid an error for an undefined value; return null instead.
return null;
}
return NativeJavaObject.coerceType(c, result);
}
public static Object js_JavaAdapter(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr)
@@ -89,37 +50,32 @@ public class JavaAdapter extends ScriptableObject {
}
intfs[interfaceCount++] = c;
}
StringBuffer sb = new StringBuffer("adapter");
sb.append(serial++);
Class[] interfaces = new Class[interfaceCount];
System.arraycopy(intfs, 0, interfaces, 0, interfaceCount);
Scriptable obj = (Scriptable) args[args.length - 1];
ClassSignature sig = new ClassSignature(superClass, interfaces, obj);
Class adapterClass = (Class) generatedClasses.get(sig);
if (adapterClass == null) {
String adapterName = "adapter" + serial++;
adapterClass = createAdapterClass(cx, obj, adapterName,
superClass, interfaces,
null, null);
generatedClasses.put(sig, adapterClass);
}
Class[] ctorParms = { Scriptable.class };
Object[] ctorArgs = { obj };
Class adapterClass = createAdapterClass(cx, obj, sb.toString(),
superClass, interfaces,
null, null);
Class[] ctorParms = { FlattenedObject.class };
Object[] ctorArgs = { new FlattenedObject(obj) };
Object v = adapterClass.getConstructor(ctorParms).newInstance(ctorArgs);
return cx.toObject(v, ScriptableObject.getTopLevelScope(ctorObj));
}
public static Class createAdapterClass(Context cx, Scriptable jsObj,
String adapterName, Class superClass,
String name, Class superClass,
Class[] interfaces,
String scriptClassName,
ClassNameHelper nameHelper)
throws ClassNotFoundException
{
ClassFileWriter cfw = new ClassFileWriter(adapterName,
ClassFileWriter cfw = new ClassFileWriter(name,
superClass.getName(),
"<adapter>");
cfw.addField("o", "Lorg/mozilla/javascript/FlattenedObject;",
ClassFileWriter.ACC_PRIVATE);
cfw.addField("self", "Lorg/mozilla/javascript/Scriptable;",
(short) (ClassFileWriter.ACC_PUBLIC |
ClassFileWriter.ACC_FINAL));
@@ -129,15 +85,13 @@ public class JavaAdapter extends ScriptableObject {
cfw.addInterface(interfaces[i].getName());
}
String superName = superClass.getName().replace('.', '/');
generateCtor(cfw, adapterName, superName);
generateCtor(cfw, name, superClass);
if (scriptClassName != null)
generateEmptyCtor(cfw, adapterName, superName, scriptClassName);
generateEmptyCtor(cfw, name, superClass, scriptClassName);
Hashtable generatedOverrides = new Hashtable();
Hashtable generatedMethods = new Hashtable();
// generate methods to satisfy all specified interfaces.
// if abstract class was specified, then generate appropriate overrides.
for (int i = 0; i < interfacesCount; i++) {
Method[] methods = interfaces[i].getMethods();
for (int j = 0; j < methods.length; j++) {
@@ -147,20 +101,19 @@ public class JavaAdapter extends ScriptableObject {
continue;
// make sure to generate only one instance of a particular
// method/signature.
String methodName = method.getName();
String methodKey = methodName + getMethodSignature(method);
String methodKey = getMethodSignature(method);
if (! generatedOverrides.containsKey(methodKey)) {
generateMethod(cfw, adapterName, methodName,
method.getParameterTypes(),
method.getReturnType());
generatedOverrides.put(methodKey, Boolean.TRUE);
generatedMethods.put(methodName, Boolean.TRUE);
generateOverride(cfw, name, method);
generatedOverrides.put(methodKey, methodKey);
}
}
}
// Now, go through the superclasses methods, checking for abstract
// methods or additional methods to override.
FlattenedObject obj = jsObj != null
? new FlattenedObject(jsObj)
: null;
// generate any additional overrides that the object might contain.
Method[] methods = superClass.getMethods();
@@ -172,60 +125,22 @@ public class JavaAdapter extends ScriptableObject {
// if a method is marked abstract, must implement it or the
// resulting class won't be instantiable. otherwise, if the object
// has a property of the same name, then an override is intended.
boolean isAbstractMethod = Modifier.isAbstract(mods);
if (isAbstractMethod ||
(jsObj != null && jsObj.has(method.getName(), jsObj)))
if (Modifier.isAbstract(mods) ||
(obj != null && obj.hasProperty(method.getName())))
{
// make sure to generate only one instance of a particular
// method/signature.
String methodName = method.getName();
String methodSignature = getMethodSignature(method);
String methodKey = methodName + methodSignature;
String methodKey = getMethodSignature(method);
if (! generatedOverrides.containsKey(methodKey)) {
generateMethod(cfw, adapterName, methodName,
method.getParameterTypes(),
method.getReturnType());
generatedOverrides.put(methodKey, Boolean.TRUE);
generatedMethods.put(methodName, Boolean.TRUE);
}
// if a method was overridden, generate a "super$method"
// which lets the delegate call the superclass' version.
if (!isAbstractMethod) {
generateSuper(cfw, adapterName, superName,
methodName, methodSignature,
method.getParameterTypes(),
method.getReturnType());
generateOverride(cfw, name, method);
generatedOverrides.put(methodKey, method);
}
}
}
// Generate Java methods, fields for remaining properties that
// are not overrides.
Object[] ids = jsObj.getIds();
for (int j=0; j < ids.length; j++) {
if (!(ids[j] instanceof String))
continue;
String id = (String) ids[j];
if (generatedMethods.containsKey(id))
continue;
Object f = jsObj.get(id, jsObj);
int length;
if (f instanceof Scriptable) {
Scriptable p = (Scriptable) f;
if (!(p instanceof Function))
continue;
length = (int) Context.toNumber(
ScriptableObject.getProperty(p, "length"));
} else if (f instanceof FunctionNode) {
length = ((FunctionNode) f).getVariableTable().getParameterCount();
} else {
continue;
}
Class[] parms = new Class[length];
for (int k=0; k < length; k++)
parms[k] = Object.class;
generateMethod(cfw, adapterName, id, parms, Object.class);
}
// TODO: generate Java methods, fields for remaining properties that
// are not overrides? Probably not necessary to generate methods
// that aren't overrides.
ByteArrayOutputStream out = new ByteArrayOutputStream(512);
try {
@@ -236,103 +151,86 @@ public class JavaAdapter extends ScriptableObject {
}
byte[] bytes = out.toByteArray();
if (nameHelper != null)
if (nameHelper != null && nameHelper.getGeneratingDirectory() != null)
{
if (nameHelper.getGeneratingDirectory() != null) {
try {
int lastDot = adapterName.lastIndexOf('.');
if (lastDot != -1)
adapterName = adapterName.substring(lastDot+1);
String filename = nameHelper.getTargetClassFileName(adapterName);
FileOutputStream file = new FileOutputStream(filename);
file.write(bytes);
file.close();
}
catch (IOException iox) {
throw WrappedException.wrapException(iox);
}
return null;
} else {
try {
ClassOutput classOutput = nameHelper.getClassOutput();
if (classOutput != null) {
OutputStream cOut =
classOutput.getOutputStream(adapterName);
cOut.write(bytes);
cOut.close();
}
} catch (IOException iox) {
throw WrappedException.wrapException(iox);
}
try {
int lastDot = name.lastIndexOf('.');
if (lastDot != -1)
name = name.substring(lastDot+1);
String filename = nameHelper.getTargetClassFileName(name);
FileOutputStream file = new FileOutputStream(filename);
file.write(bytes);
file.close();
}
catch (IOException iox) {
throw WrappedException.wrapException(iox);
}
return null;
}
SecuritySupport ss = cx.getSecuritySupport();
if (ss != null) {
Object securityDomain = cx.getSecurityDomainForStackDepth(-1);
return ss.defineClass(adapterName, bytes, securityDomain);
return ss.defineClass(name, bytes, securityDomain);
} else {
if (classLoader == null)
classLoader = new MyClassLoader();
classLoader.defineClass(adapterName, bytes);
return classLoader.loadClass(adapterName, true);
classLoader.defineClass(name, bytes);
return classLoader.loadClass(name, true);
}
}
/**
* Utility method, which dynamically binds a Context to the current thread,
* if none already exists.
*/
public static Object callMethod(Scriptable object, String methodId,
public static Object callMethod(FlattenedObject object, Object methodId,
Object[] args)
{
if (object.has(methodId, object)) {
try {
Context cx = Context.enter();
Object fun = object.get(methodId, object);
return ScriptRuntime.call(cx, fun, object, args, object);
} catch (JavaScriptException ex) {
// TODO: could occur
} finally {
Context.exit();
}
}
Context cx = Context.enter();
try {
if (object.hasProperty(methodId))
return object.callMethod(methodId, args);
} catch (PropertyException ex) {
// shouldn't occur
} catch (NotAFunctionException ex) {
// TODO: could occur
} catch (JavaScriptException ex) {
// TODO: could occur
/*
} catch (Exception ex) {
// TODO: wouldn't it be better to let the exception propagate
// up so that it could be dealt with by the calling code?
ex.printStackTrace(System.err);
throw new Error(ex.getMessage());
*/
} finally {
Context.exit();
}
return Context.getUndefinedValue();
}
public static Scriptable toObject(Object value, Scriptable scope,
Class staticType)
{
Context.enter();
try {
return Context.toObject(value, scope, staticType);
} finally {
Context.exit();
}
}
private static void generateCtor(ClassFileWriter cfw, String adapterName,
String superName)
private static void generateCtor(ClassFileWriter cfw, String name,
Class superClass)
{
cfw.startMethod("<init>",
"(Lorg/mozilla/javascript/Scriptable;)V",
"(Lorg/mozilla/javascript/FlattenedObject;)V",
ClassFileWriter.ACC_PUBLIC);
// Invoke base class constructor
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.INVOKESPECIAL, superName, "<init>", "()", "V");
cfw.add(ByteCode.INVOKESPECIAL,
superClass.getName().replace('.', '/'),
"<init>", "()", "V");
// Save parameter in instance variable "self"
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_1); // first arg
cfw.add(ByteCode.PUTFIELD, adapterName, "self",
"Lorg/mozilla/javascript/Scriptable;");
/*
// Set the prototype of the js object to be a LiveConnect
// wrapper of the generated class's object
// wapper of the generated class's object
cfw.add(ByteCode.ALOAD_1); // first arg
cfw.add(ByteCode.INVOKEVIRTUAL,
"org/mozilla/javascript/FlattenedObject",
"getObject", "()",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/ScriptRuntime",
@@ -340,19 +238,40 @@ public class JavaAdapter extends ScriptableObject {
"(Lorg/mozilla/javascript/Scriptable;" +
"Ljava/lang/Object;)",
"V");
*/
// Save parameter in instance variable
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_1); // first arg
cfw.add(ByteCode.PUTFIELD, name, "o",
"Lorg/mozilla/javascript/FlattenedObject;");
// Store Scriptable object in "self", a public instance variable,
// so scripts can read it.
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_1); // first arg
cfw.add(ByteCode.INVOKEVIRTUAL,
"org/mozilla/javascript/FlattenedObject",
"getObject", "()",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.PUTFIELD, name, "self",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.RETURN);
cfw.stopMethod((short)20, null); // TODO: magic number "20"
}
private static void generateEmptyCtor(ClassFileWriter cfw, String adapterName,
String superName, String scriptClassName)
private static void generateEmptyCtor(ClassFileWriter cfw, String name,
Class superClass,
String scriptClassName)
{
cfw.startMethod("<init>", "()V", ClassFileWriter.ACC_PUBLIC);
// Invoke base class constructor
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.INVOKESPECIAL, superName, "<init>", "()", "V");
cfw.add(ByteCode.INVOKESPECIAL,
superClass.getName().replace('.', '/'),
"<init>", "()", "V");
// Load script class
cfw.add(ByteCode.NEW, scriptClassName);
@@ -364,18 +283,33 @@ public class JavaAdapter extends ScriptableObject {
"org/mozilla/javascript/ScriptRuntime",
"runScript",
"(Lorg/mozilla/javascript/Script;)",
"Lorg/mozilla/javascript/Scriptable;");
"Lorg/mozilla/javascript/FlattenedObject;");
cfw.add(ByteCode.ASTORE_1);
// Save the Scriptable in instance variable "self"
// Save the FlattenedObject in instance variable
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_1); // the Scriptable
cfw.add(ByteCode.PUTFIELD, adapterName, "self",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.ALOAD_1); // the FlattenedObject
cfw.add(ByteCode.PUTFIELD, name, "o",
"Lorg/mozilla/javascript/FlattenedObject;");
// Store Scriptable object in "self", a public instance variable,
// so scripts can read it.
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.ALOAD_1); // the FlattenedObject
cfw.add(ByteCode.INVOKEVIRTUAL,
"org/mozilla/javascript/FlattenedObject",
"getObject", "()",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.PUTFIELD, name, "self",
"Lorg/mozilla/javascript/Scriptable;");
// Set the prototype of the js object to be a LiveConnect
// wrapper of the generated class's object
cfw.add(ByteCode.ALOAD_1); // the Scriptable
// wapper of the generated class's object
cfw.add(ByteCode.ALOAD_1); // the FlattenedObject
cfw.add(ByteCode.INVOKEVIRTUAL,
"org/mozilla/javascript/FlattenedObject",
"getObject", "()",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/ScriptRuntime",
@@ -508,25 +442,51 @@ public class JavaAdapter extends ScriptableObject {
throw new RuntimeException("Unexpected return type " +
retType.toString());
}
} else {
String retTypeStr = retType.getName();
cfw.addLoadConstant(retTypeStr);
} else if (retType.equals(String.class)) {
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/JavaAdapter",
"convertResult",
"org/mozilla/javascript/Context",
"toString", "(Ljava/lang/Object;)",
"Ljava/lang/String;");
cfw.add(ByteCode.ARETURN);
} else if (retType.equals(Scriptable.class)) {
cfw.add(ByteCode.ALOAD_0); // load 'this' to find scope from
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/Context",
"toObject",
"(Ljava/lang/Object;" +
"Ljava/lang/String;)",
"Ljava/lang/Object;");
"Lorg/mozilla/javascript/Scriptable;)",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.ARETURN);
} else {
// If it is a wrapped type, cast to Wrapper and call unwrap()
cfw.add(ByteCode.DUP);
cfw.add(ByteCode.INSTANCEOF, "org/mozilla/javascript/Wrapper");
// skip 3 for IFEQ, 3 for CHECKCAST, and 5 for INVOKEINTERFACE
cfw.add(ByteCode.IFEQ, 11);
cfw.add(ByteCode.CHECKCAST, "org/mozilla/javascript/Wrapper");
cfw.add(ByteCode.INVOKEINTERFACE,
"org/mozilla/javascript/Wrapper",
"unwrap", "()", "Ljava/lang/Object;");
// If Undefined, return null
cfw.add(ByteCode.DUP);
cfw.add(ByteCode.INSTANCEOF, "org/mozilla/javascript/Undefined");
// skip 3 for IFEQ, 1 for ACONST_NULL, 1 for ARETURN
cfw.add(ByteCode.IFEQ, 5);
cfw.add(ByteCode.ACONST_NULL);
cfw.add(ByteCode.ARETURN);
// Now cast to return type
cfw.add(ByteCode.CHECKCAST, retTypeStr.replace('.', '/'));
String retTypeStr = retType.getName().replace('.', '/');
cfw.add(ByteCode.CHECKCAST, retTypeStr);
cfw.add(ByteCode.ARETURN);
}
}
private static void generateMethod(ClassFileWriter cfw, String genName,
String methodName, Class[] parms,
Class returnType)
private static void generateOverride(ClassFileWriter cfw, String genName,
Method m)
{
Class[] parms = m.getParameterTypes();
StringBuffer sb = new StringBuffer();
sb.append('(');
short arrayLocal = 1; // includes this.
@@ -539,11 +499,11 @@ public class JavaAdapter extends ScriptableObject {
arrayLocal += 1;
}
sb.append(')');
appendTypeString(sb, returnType);
appendTypeString(sb, m.getReturnType());
String methodSignature = sb.toString();
// System.out.println("generating " + m.getName() + methodSignature);
// System.out.flush();
cfw.startMethod(methodName, methodSignature,
cfw.startMethod(m.getName(), methodSignature,
ClassFileWriter.ACC_PUBLIC);
cfw.add(ByteCode.BIPUSH, (byte) parms.length); // > 255 parms?
cfw.add(ByteCode.ANEWARRAY, "java/lang/Object");
@@ -577,13 +537,13 @@ public class JavaAdapter extends ScriptableObject {
// Get argument Class
cfw.addLoadConstant(parms[i].getName());
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/ScriptRuntime",
"loadClassName",
"java/lang/Class",
"forName",
"(Ljava/lang/String;)",
"Ljava/lang/Class;");
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/JavaAdapter",
"org/mozilla/javascript/Context",
"toObject",
"(Ljava/lang/Object;" +
"Lorg/mozilla/javascript/Scriptable;" +
@@ -594,10 +554,10 @@ public class JavaAdapter extends ScriptableObject {
}
cfw.add(ByteCode.ALOAD_0); // this
cfw.add(ByteCode.GETFIELD, genName, "self",
"Lorg/mozilla/javascript/Scriptable;");
cfw.add(ByteCode.GETFIELD, genName, "o",
"Lorg/mozilla/javascript/FlattenedObject;");
cfw.addLoadConstant(methodName);
cfw.addLoadConstant(m.getName());
cfw.add(ByteCode.ALOAD, arrayLocal);
// go through utility method, which creates a Context to run the
@@ -605,11 +565,11 @@ public class JavaAdapter extends ScriptableObject {
cfw.add(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/JavaAdapter",
"callMethod",
"(Lorg/mozilla/javascript/Scriptable;" +
"Ljava/lang/String;[Ljava/lang/Object;)",
"(Lorg/mozilla/javascript/FlattenedObject;" +
"Ljava/lang/Object;[Ljava/lang/Object;)",
"Ljava/lang/Object;");
Class retType = returnType;
Class retType = m.getReturnType();
if (retType.equals(Void.TYPE)) {
cfw.add(ByteCode.POP);
cfw.add(ByteCode.RETURN);
@@ -618,119 +578,6 @@ public class JavaAdapter extends ScriptableObject {
}
cfw.stopMethod((short)(scopeLocal + 1), null);
}
/**
* Generates code to push typed parameters onto the operand stack
* prior to a direct Java method call.
*/
private static int generatePushParam(ClassFileWriter cfw, int paramOffset,
Class paramType)
{
String typeName = paramType.getName();
switch (typeName.charAt(0)) {
case 'z':
case 'b':
case 'c':
case 's':
case 'i':
// load an int value, convert to double.
cfw.add(ByteCode.ILOAD, paramOffset++);
break;
case 'l':
// load a long, convert to double.
cfw.add(ByteCode.LLOAD, paramOffset);
paramOffset += 2;
break;
case 'f':
// load a float, convert to double.
cfw.add(ByteCode.FLOAD, paramOffset++);
break;
case 'd':
cfw.add(ByteCode.DLOAD, paramOffset);
paramOffset += 2;
break;
}
return paramOffset;
}
/**
* Generates code to return a Java type, after calling a Java method
* that returns the same type.
* Generates the appropriate RETURN bytecode.
*/
private static void generatePopResult(ClassFileWriter cfw,
Class retType)
{
if (retType.isPrimitive()) {
String typeName = retType.getName();
switch (typeName.charAt(0)) {
case 'b':
case 'c':
case 's':
case 'i':
case 'z':
cfw.add(ByteCode.IRETURN);
break;
case 'l':
cfw.add(ByteCode.LRETURN);
break;
case 'f':
cfw.add(ByteCode.FRETURN);
break;
case 'd':
cfw.add(ByteCode.DRETURN);
break;
}
} else {
cfw.add(ByteCode.ARETURN);
}
}
/**
* Generates a method called "super$methodName()" which can be called
* from JavaScript that is equivalent to calling "super.methodName()"
* from Java. Eventually, this may be supported directly in JavaScript.
*/
private static void generateSuper(ClassFileWriter cfw,
String genName, String superName,
String methodName, String methodSignature,
Class[] parms, Class returnType)
{
cfw.startMethod("super$" + methodName, methodSignature,
ClassFileWriter.ACC_PUBLIC);
// push "this"
cfw.add(ByteCode.ALOAD, 0);
// push the rest of the parameters.
int paramOffset = 1;
for (int i = 0; i < parms.length; i++) {
if (parms[i].isPrimitive()) {
paramOffset = generatePushParam(cfw, paramOffset, parms[i]);
} else {
cfw.add(ByteCode.ALOAD, paramOffset++);
}
}
// split the method signature at the right parentheses.
int rightParen = methodSignature.indexOf(')');
// call the superclass implementation of the method.
cfw.add(ByteCode.INVOKESPECIAL,
superName,
methodName,
methodSignature.substring(0, rightParen + 1),
methodSignature.substring(rightParen + 1));
// now, handle the return type appropriately.
Class retType = returnType;
if (!retType.equals(Void.TYPE)) {
generatePopResult(cfw, retType);
} else {
cfw.add(ByteCode.RETURN);
}
cfw.stopMethod((short)(paramOffset + 1), null);
}
/**
* Returns a fully qualified method name concatenated with its signature.
@@ -738,6 +585,7 @@ public class JavaAdapter extends ScriptableObject {
private static String getMethodSignature(Method method) {
Class[] parms = method.getParameterTypes();
StringBuffer sb = new StringBuffer();
sb.append(method.getName());
sb.append('(');
for (int i = 0; i < parms.length; i++) {
Class type = parms[i];
@@ -783,67 +631,18 @@ public class JavaAdapter extends ScriptableObject {
Class clazz = findLoadedClass(name);
if (clazz == null) {
ClassLoader loader = getClass().getClassLoader();
try {
if (loader != null)
return loader.loadClass(name);
clazz = findSystemClass(name);
} catch (ClassNotFoundException e) {
return ScriptRuntime.loadClassName(name);
}
if (loader != null)
return loader.loadClass(name);
clazz = findSystemClass(name);
}
if (resolve)
resolveClass(clazz);
return clazz;
}
}
/**
* Provides a key with which to distinguish previously generated
* adapter classes stored in a hash table.
*/
static class ClassSignature {
Class mSuperClass;
Class[] mInterfaces;
Object[] mProperties;
ClassSignature(Class superClass, Class[] interfaces, Scriptable jsObj) {
mSuperClass = superClass;
mInterfaces = interfaces;
mProperties = jsObj.getIds();
}
public boolean equals(Object obj) {
if (obj instanceof ClassSignature) {
ClassSignature sig = (ClassSignature) obj;
if (mSuperClass == sig.mSuperClass) {
Class[] interfaces = sig.mInterfaces;
if (mInterfaces != interfaces) {
if (mInterfaces == null || interfaces == null)
return false;
if (mInterfaces.length != interfaces.length)
return false;
for (int i = 0; i < interfaces.length; i++)
if (mInterfaces[i] != interfaces[i])
return false;
}
Object[] properties = sig.mProperties;
if (mProperties.length != properties.length)
return false;
for (int i = 0; i < properties.length; i++)
if (!mProperties[i].equals(properties[i]))
return false;
return true;
}
}
return false;
}
public int hashCode() {
return mSuperClass.hashCode();
}
}
private java.util.Hashtable loaded;
}
private static int serial;
private static MyClassLoader classLoader;
private static Hashtable generatedClasses = new Hashtable(7);
}

View File

@@ -1,39 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
* Kurt Westerfeld
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -63,7 +43,8 @@ class JavaMembers {
Object obj = ht.get(name);
if (obj != null) {
return true;
} else {
}
else {
Member member = this.findExplicitFunction(name, isStatic);
return member != null;
}
@@ -85,33 +66,25 @@ class JavaMembers {
return Scriptable.NOT_FOUND;
}
if (member instanceof Scriptable)
return member; // why is this here?
return member;
Field field = (Field) member;
Object rval;
Class type;
try {
if (member instanceof BeanProperty) {
BeanProperty bp = (BeanProperty) member;
rval = bp.getter.invoke(javaObject, ScriptRuntime.emptyArgs);
type = bp.getter.getReturnType();
} else {
Field field = (Field) member;
rval = field.get(isStatic ? null : javaObject);
type = field.getType();
}
rval = field.get(isStatic ? null : javaObject);
} catch (IllegalAccessException accEx) {
throw new RuntimeException("unexpected IllegalAccessException "+
"accessing Java field");
} catch (InvocationTargetException e) {
throw new WrappedException(e.getTargetException());
}
// Need to wrap the object before we return it.
Class fieldType = field.getType();
scope = ScriptableObject.getTopLevelScope(scope);
return NativeJavaObject.wrap(scope, rval, type);
return NativeJavaObject.wrap(scope, rval, fieldType);
}
Member findExplicitFunction(String name, boolean isStatic) {
Hashtable ht = isStatic ? staticMembers : members;
int sigStart = name.indexOf('(');
Object member = null;
Member[] methodsOrCtors = null;
NativeJavaMethod method = null;
boolean isCtor = (isStatic && sigStart == 0);
@@ -147,9 +120,11 @@ class JavaMembers {
return null;
}
Object getExplicitFunction(Scriptable scope, String name,
Object javaObject, boolean isStatic)
{
Object getExplicitFunction(Scriptable scope,
String name,
Object javaObject,
boolean isStatic) {
Hashtable ht = isStatic ? staticMembers : members;
Object member = null;
Member methodOrCtor = this.findExplicitFunction(name, isStatic);
@@ -161,10 +136,12 @@ class JavaMembers {
if (methodOrCtor instanceof Constructor) {
NativeJavaConstructor fun =
new NativeJavaConstructor((Constructor)methodOrCtor);
fun.setParentScope(scope);
fun.setPrototype(prototype);
member = fun;
ht.put(name, fun);
} else {
}
else {
String trueName = methodOrCtor.getName();
member = ht.get(trueName);
@@ -172,6 +149,7 @@ class JavaMembers {
((NativeJavaMethod)member).getMethods().length > 1 ) {
NativeJavaMethod fun =
new NativeJavaMethod((Method)methodOrCtor, name);
fun.setParentScope(scope);
fun.setPrototype(prototype);
ht.put(name, fun);
member = fun;
@@ -195,51 +173,26 @@ class JavaMembers {
if (member == null)
throw reportMemberNotFound(name);
if (member instanceof FieldAndMethods) {
FieldAndMethods fam = (FieldAndMethods) ht.get(name);
member = fam.getField();
member = ((FieldAndMethods) ht.get(name)).getField();
}
// Is this a bean property "set"?
if (member instanceof BeanProperty) {
try {
Method method = ((BeanProperty) member).setter;
if (method == null)
throw reportMemberNotFound(name);
Class[] types = method.getParameterTypes();
Object[] params = { NativeJavaObject.coerceType(types[0], value) };
method.invoke(javaObject, params);
} catch (IllegalAccessException accessEx) {
throw new RuntimeException("unexpected IllegalAccessException " +
"accessing Java field");
} catch (InvocationTargetException e) {
throw new WrappedException(e.getTargetException());
}
}
else {
Field field = null;
try {
field = (Field) member;
if (field == null) {
Object[] args = {name};
throw Context.reportRuntimeError(
Context.getMessage("msg.java.internal.private", args));
}
field.set(javaObject, NativeJavaObject.coerceType(field.getType(),
value));
} catch (ClassCastException e) {
Object errArgs[] = { name };
throw Context.reportRuntimeError(Context.getMessage
("msg.java.method.assign",
errArgs));
} catch (IllegalAccessException accessEx) {
throw new RuntimeException("unexpected IllegalAccessException "+
"accessing Java field");
} catch (IllegalArgumentException argEx) {
Object errArgs[] = { value.getClass().getName(), field,
javaObject.getClass().getName() };
throw Context.reportRuntimeError(Context.getMessage(
"msg.java.internal.field.type", errArgs));
}
Field field = null;
try {
field = (Field) member;
field.set(javaObject, NativeJavaObject.coerceType(field.getType(),
value));
} catch (ClassCastException e) {
Object errArgs[] = { name };
throw Context.reportRuntimeError(Context.getMessage
("msg.java.method.assign",
errArgs));
} catch (IllegalAccessException accessEx) {
throw new RuntimeException("unexpected IllegalAccessException "+
"accessing Java field");
} catch (IllegalArgumentException argEx) {
Object errArgs[] = { value.getClass().getName(), field,
javaObject.getClass().getName() };
throw Context.reportRuntimeError(Context.getMessage(
"msg.java.internal.field.type", errArgs));
}
}
@@ -256,8 +209,8 @@ class JavaMembers {
Class getReflectedClass() {
return cl;
}
void reflectField(Scriptable scope, Field field) {
void reflectField(Field field) {
int mods = field.getModifiers();
if (!Modifier.isPublic(mods))
return;
@@ -268,21 +221,33 @@ class JavaMembers {
if (member != null) {
if (member instanceof NativeJavaMethod) {
NativeJavaMethod method = (NativeJavaMethod) member;
Hashtable fmht = isStatic ? staticFieldAndMethods
: fieldAndMethods;
if (fmht == null) {
fmht = new Hashtable(11);
if (isStatic)
staticFieldAndMethods = fmht;
else
fieldAndMethods = fmht;
}
FieldAndMethods fam = new FieldAndMethods(method.getMethods(),
field,
null);
fam.setPrototype(ScriptableObject.getFunctionPrototype(scope));
getFieldAndMethodsTable(isStatic).put(name, fam);
field);
fmht.put(name, fam);
ht.put(name, fam);
return;
}
if (member instanceof Field) {
Field oldField = (Field) member;
// If this newly reflected field shadows an inherited field,
// then replace it. Otherwise, since access to the field
// would be ambiguous from Java, no field should be reflected.
// For now, the first field found wins, unless another field
// explicitly shadows it.
// beard:
// If an exception is thrown here, then JDirect classes on MRJ can't be used. JDirect
// classes implement multiple interfaces that each have a static "libraryInstance" field.
if (false) {
throw new RuntimeException("cannot have multiple Java " +
"fields with same name");
}
// If this newly reflected field shadows an inherited field, then replace it. Otherwise,
// since access to the field would be ambiguous from Java, no field should be reflected.
// For now, the first field found wins, unless another field explicitly shadows it.
if (oldField.getDeclaringClass().isAssignableFrom(field.getDeclaringClass()))
ht.put(name, field);
return;
@@ -302,13 +267,13 @@ class JavaMembers {
NativeJavaMethod fun = (NativeJavaMethod) ht.get(name);
if (fun == null) {
fun = new NativeJavaMethod();
if (scope != null)
fun.setPrototype(ScriptableObject.getFunctionPrototype(scope));
fun.setParentScope(scope);
fun.setPrototype(ScriptableObject.getFunctionPrototype(scope));
ht.put(name, fun);
fun.add(method);
} else {
fun.add(method);
}
else
fun.add(method);
}
void reflect(Scriptable scope, Class cl) {
@@ -318,145 +283,20 @@ class JavaMembers {
Method[] methods = cl.getMethods();
for (int i = 0; i < methods.length; i++)
reflectMethod(scope, methods[i]);
Field[] fields = cl.getFields();
for (int i = 0; i < fields.length; i++)
reflectField(scope, fields[i]);
reflectField(fields[i]);
makeBeanProperties(scope, false);
makeBeanProperties(scope, true);
ctors = cl.getConstructors();
}
Hashtable getFieldAndMethodsTable(boolean isStatic) {
Hashtable fmht = isStatic ? staticFieldAndMethods
: fieldAndMethods;
if (fmht == null) {
fmht = new Hashtable(11);
if (isStatic)
staticFieldAndMethods = fmht;
else
fieldAndMethods = fmht;
}
return fmht;
}
void makeBeanProperties(Scriptable scope, boolean isStatic) {
Hashtable ht = isStatic ? staticMembers : members;
Hashtable toAdd = new Hashtable();
// Now, For each member, make "bean" properties.
for (Enumeration e = ht.keys(); e.hasMoreElements(); ) {
// Is this a getter?
String name = (String) e.nextElement();
boolean memberIsGetMethod = name.startsWith("get");
boolean memberIsIsMethod = name.startsWith("is");
if (memberIsGetMethod || memberIsIsMethod) {
// Double check name component.
String nameComponent = name.substring(memberIsGetMethod ? 3 : 2);
if (nameComponent.length() == 0)
continue;
// Make the bean property name.
String beanPropertyName = nameComponent;
if (nameComponent.length() > 1 &&
Character.isUpperCase(nameComponent.charAt(0)) &&
!Character.isUpperCase(nameComponent.charAt(1)))
{
beanPropertyName = Character.toLowerCase(nameComponent.charAt(0)) +
nameComponent.substring(1);
}
// If we already have a member by this name, don't do this
// property.
if (ht.containsKey(beanPropertyName))
continue;
// Get the method by this name.
Object method = ht.get(name);
if (!(method instanceof NativeJavaMethod))
continue;
NativeJavaMethod getJavaMethod = (NativeJavaMethod) method;
// Grab and inspect the getter method; does it have an empty parameter list,
// with a return value (eg. a getSomething() or isSomething())?
Class[] params;
Method[] getMethods = getJavaMethod.getMethods();
Class type;
if (getMethods != null &&
getMethods.length == 1 &&
(type = getMethods[0].getReturnType()) != null &&
(params = getMethods[0].getParameterTypes()) != null &&
params.length == 0)
{
// Make sure the method static-ness is preserved for this property.
if (isStatic && !Modifier.isStatic(getMethods[0].getModifiers()))
continue;
// We have a getter. Now, do we have a setter?
Method setMethod = null;
String setter = "set" + nameComponent;
if (ht.containsKey(setter)) {
// Is this value a method?
method = ht.get(setter);
if (method instanceof NativeJavaMethod) {
//
// Note: it may be preferable to allow NativeJavaMethod.findFunction()
// to find the appropriate setter; unfortunately, it requires an
// instance of the target arg to determine that.
//
// Make two passes: one to find a method with direct type assignment,
// and one to find a widening conversion.
NativeJavaMethod setJavaMethod = (NativeJavaMethod) method;
Method[] setMethods = setJavaMethod.getMethods();
for (int pass = 1; pass <= 2 && setMethod == null; ++pass) {
for (int i = 0; i < setMethods.length; ++i) {
if (setMethods[i].getReturnType() == void.class &&
(!isStatic || Modifier.isStatic(setMethods[i].getModifiers())) &&
(params = setMethods[i].getParameterTypes()) != null &&
params.length == 1 ) {
if ((pass == 1 && params[0] == type) ||
(pass == 2 && params[0].isAssignableFrom(type))) {
setMethod = setMethods[i];
break;
}
}
}
}
}
}
// Make the property.
BeanProperty bp = new BeanProperty(getMethods[0], setMethod);
toAdd.put(beanPropertyName, bp);
}
}
}
// Add the new bean properties.
for (Enumeration e = toAdd.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
Object value = toAdd.get(key);
ht.put(key, value);
}
}
Hashtable getFieldAndMethodsObjects(Scriptable scope, Object javaObject,
boolean isStatic)
{
Hashtable getFieldAndMethodsObjects(Object javaObject, boolean isStatic) {
Hashtable ht = isStatic ? staticFieldAndMethods : fieldAndMethods;
if (ht == null)
return null;
int len = ht.size();
Hashtable result = new Hashtable(Math.max(len,1));
Hashtable result = new Hashtable(len);
Enumeration e = ht.elements();
while (len-- > 0) {
FieldAndMethods fam = (FieldAndMethods) e.nextElement();
@@ -475,8 +315,7 @@ class JavaMembers {
Class staticType)
{
Class cl = dynamicType;
Hashtable ct = classTable; // use local reference to avoid synchronize
JavaMembers members = (JavaMembers) ct.get(cl);
JavaMembers members = (JavaMembers) classTable.get(cl);
if (members != null)
return members;
if (staticType != null && staticType != dynamicType &&
@@ -484,34 +323,26 @@ class JavaMembers {
Modifier.isPublic(staticType.getModifiers()))
{
cl = staticType;
// We can use the static type, and that is OK, but we'll trace
// back the java class chain here to look for something more suitable.
for (Class parentType = dynamicType;
parentType != null && parentType != ScriptRuntime.ObjectClass;
parentType = parentType.getSuperclass())
{
if (Modifier.isPublic(parentType.getModifiers())) {
cl = parentType;
break;
}
}
synchronized (classTable) {
members = (JavaMembers) classTable.get(cl);
if (members != null)
return members;
try {
members = new JavaMembers(scope, cl);
} catch (SecurityException e) {
// Reflection may fail for objects that are in a restricted
// access package (e.g. sun.*). If we get a security
// exception, try again with the static type. Otherwise,
// rethrow the exception.
if (cl != staticType)
members = new JavaMembers(scope, staticType);
else
throw e;
}
classTable.put(cl, members);
return members;
}
try {
members = new JavaMembers(scope, cl);
} catch (SecurityException e) {
// Reflection may fail for objects that are in a restricted
// access package (e.g. sun.*). If we get a security
// exception, try again with the static type. Otherwise,
// rethrow the exception.
if (cl != staticType)
members = new JavaMembers(scope, staticType);
else
throw e;
}
if (Context.isCachingEnabled)
ct.put(cl, members);
return members;
}
RuntimeException reportMemberNotFound(String memberName) {
@@ -522,7 +353,7 @@ class JavaMembers {
errArgs));
}
static Hashtable classTable = new Hashtable();
private static Hashtable classTable = new Hashtable();
private Class cl;
private Hashtable members;
@@ -532,21 +363,12 @@ class JavaMembers {
private Constructor[] ctors;
}
class BeanProperty {
BeanProperty(Method getter, Method setter) {
this.getter = getter;
this.setter = setter;
}
Method getter;
Method setter;
}
class FieldAndMethods extends NativeJavaMethod {
FieldAndMethods(Method[] methods, Field field, String name) {
FieldAndMethods(Method[] methods, Field field) {
super(methods);
this.field = field;
this.name = name;
}
void setJavaObject(Object javaObject) {
@@ -554,42 +376,37 @@ class FieldAndMethods extends NativeJavaMethod {
}
String getName() {
if (field == null)
return name;
return field.getName();
}
Field getField() {
return field;
}
public Object getDefaultValue(Class hint) {
if (hint == ScriptRuntime.FunctionClass)
return this;
Object rval;
Class type;
try {
rval = field.get(javaObject);
type = field.getType();
} catch (IllegalAccessException accEx) {
Object[] args = {getName()};
throw Context.reportRuntimeError(Context.getMessage
("msg.java.internal.private", args));
("msg.java.internal.private", null));
}
rval = NativeJavaObject.wrap(this, rval, type);
rval = NativeJavaObject.wrap(this, rval, field.getType());
if (rval instanceof Scriptable) {
rval = ((Scriptable) rval).getDefaultValue(hint);
((Scriptable)rval).setParentScope(this);
((Scriptable)rval).setPrototype(parent.getPrototype());
}
return rval;
}
public Object clone() {
FieldAndMethods result = new FieldAndMethods(methods, field, name);
FieldAndMethods result = new FieldAndMethods(methods, field);
result.javaObject = javaObject;
return result;
}
private Field field;
private Object javaObject;
private String name;
}

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,99 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
package org.mozilla.javascript;
import java.lang.reflect.*;
/**
* Avoid loading classes unless they are used.
*
* <p> This improves startup time and average memory usage.
*/
class LazilyLoadedCtor {
LazilyLoadedCtor(ScriptableObject scope, String ctorName,
String className, int attributes)
throws PropertyException
{
this.className = className;
this.ctorName = ctorName;
Class cl = getClass();
Method[] getter = FunctionObject.findMethods(cl, "getProperty");
Method[] setter = FunctionObject.findMethods(cl, "setProperty");
scope.defineProperty(this.ctorName, this, getter[0], setter[0],
attributes);
}
public Object getProperty(ScriptableObject obj) {
try {
synchronized (obj) {
if (!isReplaced)
ScriptableObject.defineClass(obj, Class.forName(className));
isReplaced = true;
}
}
catch (ClassNotFoundException e) {
throw WrappedException.wrapException(e);
}
catch (InstantiationException e) {
throw WrappedException.wrapException(e);
}
catch (IllegalAccessException e) {
throw WrappedException.wrapException(e);
}
catch (InvocationTargetException e) {
throw WrappedException.wrapException(e);
}
catch (ClassDefinitionException e) {
throw WrappedException.wrapException(e);
}
catch (PropertyException e) {
throw WrappedException.wrapException(e);
}
return obj.get(ctorName, obj);
}
public Object setProperty(ScriptableObject obj, Object val) {
synchronized (obj) {
isReplaced = true;
return val;
}
}
private String ctorName;
private String className;
private boolean isReplaced;
}

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -69,52 +52,33 @@ final class LineBuffer {
}
int read() throws IOException {
for(;;) {
if (end == offset && !fill())
return -1;
if (end == offset && !fill())
return -1;
// Do only a bitmask + branch per character, at the cost of
// three branches per low-bits-only character.
if ((buffer[offset] & '\ufff0') == 0) {
if (buffer[offset] == '\r') {
// if the next character is a newline, skip past it.
if ((offset + 1) < end) {
if (buffer[offset + 1] == '\n')
offset++;
} else {
// set a flag for fill(), in case the first char of the
// next fill is a newline.
lastWasCR = true;
}
}
else if (buffer[offset] != '\n') {
return (int) buffer[offset++];
}
offset++;
prevStart = lineStart;
lineStart = offset;
lineno++;
return '\n';
}
// Do only a bitmask + branch per character, at the cost of
// three branches per low-bits-only (or 2028/9) character.
if ((buffer[offset] & '\udfd0') == 0) {
if (buffer[offset] == '\r') {
// if the next character is a newline, skip past it.
if ((offset + 1) < end) {
if (buffer[offset + 1] == '\n')
offset++;
} else {
// set a flag for fill(), in case the first char of the
// next fill is a newline.
lastWasCR = true;
}
}
else
if ((buffer[offset] != '\n')
&& (buffer[offset] != '\u2028')
&& (buffer[offset] != '\u2029'))
{
if (Character.getType(buffer[offset])
== Character.FORMAT) {
hadCFSinceStringStart = true;
offset++;
continue;
}
return (int) buffer[offset++];
}
offset++;
prevStart = lineStart;
lineStart = offset;
lineno++;
return '\n';
}
if ((buffer[offset] >= 128)
&& (Character.getType(buffer[offset]) == Character.FORMAT)) {
hadCFSinceStringStart = true;
offset++;
}
else
break;
}
return (int) buffer[offset++];
}
@@ -233,21 +197,14 @@ final class LineBuffer {
// (which we want to include) is at the end of the last one, so
// we just go to StringBuffer mode.
stringSoFar = new StringBuffer();
stringSoFar.append(otherBuffer, otherEnd - 1, 1);
stringStart = -1; // Set sentinel value.
hadCFSinceStringStart = ((otherBuffer[otherEnd - 1] >= 128)
&& Character.getType(otherBuffer[otherEnd - 1])
== Character.FORMAT);
} else {
// Support restarting strings
stringSoFar = null;
stringStart = offset - 1;
hadCFSinceStringStart = ((buffer[stringStart] >= 128)
&& Character.getType(buffer[stringStart]) == Character.FORMAT);
}
}
// Get a string consisting of the characters seen since the last
@@ -281,23 +238,6 @@ final class LineBuffer {
stringStart = -1;
stringSoFar = null;
if (hadCFSinceStringStart) {
char c[] = result.toCharArray();
StringBuffer x = null;
for (int i = 0; i < c.length; i++) {
if (Character.getType(c[i]) == Character.FORMAT) {
if (x == null) {
x = new StringBuffer();
x.append(c, 0, i);
}
}
else
if (x != null) x.append(c[i]);
}
if (x != null) result = x.toString();
}
return result;
}
@@ -405,8 +345,6 @@ final class LineBuffer {
private int stringStart = -1;
private StringBuffer stringSoFar = null;
private boolean hadCFSinceStringStart = false;
}

View File

@@ -1,39 +1,21 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "MozPL"); you may not use this file except in
* compliance with the MozPL. You may obtain a copy of the MozPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* Software distributed under the MozPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the MozPL
* for the specific language governing rights and limitations under the
* MozPL.
*
* The Original Code is ListenerCollection, released
* May 15, 1998.
*
* The Initial Developer of the Original Code is Ian D. Stewart.
* Portions created by Ian D. Stewart are Copyright (C) 1998, 1999
* The Initial Developer of this code under the MozPL is Ian D. Stewart.
* Portions created by Ian D. Stewart are Copyright (C) 1998, 1999
* Ian D. Stewart.
* Rights Reserved.
*
* Contributor(s):
* Ian D. Stewart
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* All Rights Reserved.
*/
/* This class provides a series of methods for accessing event listeners. */
package org.mozilla.javascript;

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,34 +1,18 @@
#! gmake
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
# 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 License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
# implied. See the License for the specific language governing
# rights and limitations under the License.
# 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 Original Code is Rhino code, released
# May 6, 1998.
#
# The Initial Developer of the Original Code is Netscape
# 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.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU Public License (the "GPL"), in which case the
# provisions of the GPL are applicable instead of those above.
# If you wish to allow use of your version of this file only
# under the terms of the GPL and not to allow others to use your
# version of this file under the NPL, indicate your decision by
# deleting the provisions above and replace them with the notice
# and other provisions required by the GPL. If you do not delete
# the provisions above, a recipient may use your version of this
# file under either the NPL or the GPL.
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
#
# Makefile the core javascript classes.
@@ -51,7 +35,6 @@ SOURCES = \
$(PATH_PREFIX)/DeepNewObjectHook.java \
$(PATH_PREFIX)/DeepScriptHook.java \
$(PATH_PREFIX)/DefaultErrorReporter.java \
$(PATH_PREFIX)/EcmaError.java \
$(PATH_PREFIX)/ErrorReporter.java \
$(PATH_PREFIX)/EvaluatorException.java \
$(PATH_PREFIX)/FlattenedObject.java \
@@ -69,15 +52,14 @@ SOURCES = \
$(PATH_PREFIX)/JavaScriptException.java \
$(PATH_PREFIX)/Label.java \
$(PATH_PREFIX)/LabelTable.java \
$(PATH_PREFIX)/LazilyLoadedCtor.java \
$(PATH_PREFIX)/LineBuffer.java \
$(PATH_PREFIX)/ListenerCollection.java \
$(PATH_PREFIX)/LocalVariable.java \
$(PATH_PREFIX)/NativeArray.java \
$(PATH_PREFIX)/NativeBoolean.java \
$(PATH_PREFIX)/NativeCall.java \
$(PATH_PREFIX)/NativeClosure.java \
$(PATH_PREFIX)/NativeDate.java \
$(PATH_PREFIX)/NativeError.java \
$(PATH_PREFIX)/NativeFunction.java \
$(PATH_PREFIX)/NativeGlobal.java \
$(PATH_PREFIX)/NativeJavaArray.java \
@@ -97,7 +79,7 @@ SOURCES = \
$(PATH_PREFIX)/NotAFunctionException.java \
$(PATH_PREFIX)/Parser.java \
$(PATH_PREFIX)/PreorderNodeIterator.java \
$(PATH_PREFIX)/PropertyException.java \
$(PATH_PREFIX)/PropertyException.java \
$(PATH_PREFIX)/RegExpProxy.java \
$(PATH_PREFIX)/Script.java \
$(PATH_PREFIX)/ScriptRuntime.java \
@@ -116,21 +98,6 @@ SOURCES = \
$(PATH_PREFIX)/regexp/NativeRegExpCtor.java \
$(PATH_PREFIX)/regexp/RegExpImpl.java \
$(PATH_PREFIX)/regexp/SubString.java \
$(PATH_PREFIX)/optimizer/Block.java \
$(PATH_PREFIX)/optimizer/Codegen.java \
$(PATH_PREFIX)/optimizer/DataFlowBitSet.java \
$(PATH_PREFIX)/optimizer/FatBlock.java \
$(PATH_PREFIX)/optimizer/JavaScriptClassLoader.java\
$(PATH_PREFIX)/optimizer/OptClassNameHelper.java\
$(PATH_PREFIX)/optimizer/OptFunctionNode.java \
$(PATH_PREFIX)/optimizer/OptIRFactory.java \
$(PATH_PREFIX)/optimizer/OptLocalVariable.java \
$(PATH_PREFIX)/optimizer/OptRuntime.java \
$(PATH_PREFIX)/optimizer/OptTransformer.java \
$(PATH_PREFIX)/optimizer/OptVariableTable.java \
$(PATH_PREFIX)/optimizer/Optimizer.java \
$(PATH_PREFIX)/optimizer/StmtNodeIterator.java \
$(PATH_PREFIX)/optimizer/TypeEvent.java \
$(PATH_PREFIX)/../classfile/ByteCode.java \
$(PATH_PREFIX)/../classfile/ClassFileWriter.java\
$(NULL)
@@ -144,7 +111,7 @@ RESOURCES = $(RESOURCEDIR)/*.properties
# (use org/mozilla/classfile explicitly for now; should be replaced
# with something parameterized, but jar doesn't understand ..)
CLASSES = $(PATH_PREFIX)/*.class $(PATH_PREFIX)/regexp/*.class \
$(PATH_PREFIX)/optimizer/*.class org/mozilla/classfile/*.class
org/mozilla/classfile/*.class
# A class or set of classes as visible from the top level. For want
# of ${subst ,,}. This variable is only used to trigger dependency
@@ -190,9 +157,8 @@ $(FASTTARGET) : $(SOURCES)
cd $(CLASSDIR) ; \
jar cf ../$(JAR) $(CLASSES) $(RESOURCES)
clean :
- cd $(CLASSDIR)
- rm $(CLASSES)
clean :
- cd $(CLASSDIR) && rm $(CLASSES) $(RESOURCES)
- rm $(PATH_PREFIX)/message.ids \
$(PATH_PREFIX)/property.ids \
$(PATH_PREFIX)/MANIFEST
@@ -211,8 +177,12 @@ MESSAGE_PREFIX = msg\.
# Find all the msg.* strings in the source, and condense them to a sorted list,
# excluding duplicates.
# We cheat here and also look at messages in the optimizer subdir.
# (regexp subdir sources are already included in $(SOURCES)
MORE_SOURCES = $(SOURCES) $(PATH_PREFIX)/optimizer/*.java
$(PATH_PREFIX)/message.ids : $(SOURCES)
grep '$(MESSAGE_PREFIX)' $(SOURCES) |\
grep '$(MESSAGE_PREFIX)' $(MORE_SOURCES) |\
sed -e 's/.*\"\($(MESSAGE_PREFIX)\)\([^\"]*\).*/\1\2/' | \
sort | uniq > $(PATH_PREFIX)/message.ids

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -210,20 +192,14 @@ public class NativeArray extends ScriptableObject {
// Only use 1 arg as first element for version 1.2; for
// any other version (including 1.3) follow ECMA and use it as
// a length.
if (cx.getLanguageVersion() == cx.VERSION_1_2) {
return new NativeArray(args);
}
else {
if ((args.length > 1) || (!(args[0] instanceof Number)))
return new NativeArray(args);
else {
long len = ScriptRuntime.toUint32(args[0]);
if (len != (((Number)(args[0])).doubleValue()))
throw Context.reportRuntimeError(Context.getMessage
("msg.arraylength.bad", null));
return new NativeArray(len);
}
if (args.length == 1 && args[0] instanceof Number &&
cx.getLanguageVersion() != cx.VERSION_1_2)
{
return new NativeArray(ScriptRuntime.toUint32(args[0]));
}
// initialize array with arguments
return new NativeArray(args);
}
private static final int lengthAttr = ScriptableObject.DONTENUM |
@@ -241,14 +217,7 @@ public class NativeArray extends ScriptableObject {
* ?
*/
if (!(val instanceof Number))
throw Context.reportRuntimeError(Context.getMessage
("msg.arraylength.bad", null));
long longVal = ScriptRuntime.toUint32(val);
if (longVal != (((Number)val).doubleValue()))
throw Context.reportRuntimeError(Context.getMessage
("msg.arraylength.bad", null));
if (longVal < length) {
// remove all properties between longVal and length
@@ -500,7 +469,7 @@ public class NativeArray extends ScriptableObject {
working[i] = getElem(thisObj, i);
}
qsort(cx, compare, working, 0, (int)length - 1, funObj);
qsort(cx, compare, working, 0, (int)length - 1);
// copy the working array back into thisObj
for (int i=0; i<length; i++) {
@@ -511,7 +480,7 @@ public class NativeArray extends ScriptableObject {
}
private static double qsortCompare(Context cx, Object jsCompare, Object x,
Object y, Scriptable scope)
Object y)
throws JavaScriptException
{
Object undef = Undefined.instance;
@@ -543,14 +512,14 @@ public class NativeArray extends ScriptableObject {
// args));
// for now, just ignore it:
double d = ScriptRuntime.
toNumber(ScriptRuntime.call(cx, jsCompare, null, args, scope));
toNumber(ScriptRuntime.call(cx, jsCompare, null, args));
return (d == d) ? d : 0;
}
}
private static void qsort(Context cx, Object jsCompare, Object[] working,
int lo, int hi, Scriptable scope)
int lo, int hi)
throws JavaScriptException
{
Object pivot;
@@ -565,14 +534,13 @@ public class NativeArray extends ScriptableObject {
while (i < j) {
for(;;) {
b = j;
if (qsortCompare(cx, jsCompare, working[j], pivot,
scope) <= 0)
if (qsortCompare(cx, jsCompare, working[j], pivot) <= 0)
break;
j--;
}
working[a] = working[b];
while (i < j && qsortCompare(cx, jsCompare, working[a],
pivot, scope) <= 0)
pivot) <= 0)
{
i++;
a = i;
@@ -581,10 +549,10 @@ public class NativeArray extends ScriptableObject {
}
working[a] = pivot;
if (i - lo < hi - i) {
qsort(cx, jsCompare, working, lo, i - 1, scope);
qsort(cx, jsCompare, working, lo, i - 1);
lo = i + 1;
} else {
qsort(cx, jsCompare, working, i + 1, hi, scope);
qsort(cx, jsCompare, working, i + 1, hi);
hi = i - 1;
}
}
@@ -609,14 +577,13 @@ public class NativeArray extends ScriptableObject {
for(;;) {
b = j;
if (qsortCompare(cx, jsCompare, getElem(target, j),
pivot, target) <= 0)
pivot) <= 0)
break;
j--;
}
setElem(target, a, getElem(target, b));
while (i < j && qsortCompare(cx, jsCompare,
getElem(target, a),
pivot, target) <= 0)
getElem(target, a), pivot) <= 0)
{
i++;
a = i;

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -51,6 +34,16 @@ public final class NativeCall extends ScriptableObject {
this(cx, scope, funObj, thisObj);
this.originalArgs = args;
// initialize references to nested functions
NativeFunction[] fns = funObj.nestedFunctions;
if (fns != null) {
for (int i=0; i < fns.length; i++) {
NativeFunction f = fns[i];
if (f.names != null)
super.put(f.names[0], this, f);
}
}
// initialize values of arguments
String[] names = funObj.names;
if (names != null) {

View File

@@ -0,0 +1,103 @@
/* -*- 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) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
/**
* This class implements the closure object.
*
* @author Norris Boyd
*/
public class NativeClosure extends ScriptableObject implements Function {
public NativeClosure() {
}
public NativeClosure(Context cx, Scriptable scope, NativeFunction f) {
setPrototype(f);
setParentScope(scope);
String name = f.names != null ? f.names[0] : "";
if (name != null && name.length() > 0) {
scope.put(name, scope, scope.getParentScope() == null
? (Object) f : this);
}
}
public String getClassName() {
return "Closure";
}
public Object getDefaultValue(Class typeHint) {
if (typeHint == ScriptRuntime.FunctionClass)
return prototype;
return super.getDefaultValue(typeHint);
}
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
Function proto = checkProto();
return proto.call(cx, getParentScope(), thisObj, args);
}
public Scriptable construct(Context cx, Scriptable scope, Object[] args)
throws JavaScriptException
{
Function proto = checkProto();
return proto.construct(cx, getParentScope(), args);
}
public static Object jsConstructor(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr)
{
Object[] msgArgs = { "Closure" };
throw Context.reportRuntimeError(
Context.getMessage("msg.cant.call.indirect", msgArgs));
}
public static Object newClosureSpecial(Context cx, Scriptable varObj,
Object[] args, Function ctorObj)
{
ScriptRuntime.checkDeprecated(cx, "Closure");
NativeFunction f = args.length > 0 &&
args[0] instanceof NativeFunction
? (NativeFunction) args[0]
: null;
NativeClosure result = f != null
? new NativeClosure(cx, varObj, f)
: new NativeClosure();
Scriptable scope = getTopLevelScope(ctorObj);
result.setPrototype(args.length == 0
? getObjectPrototype(scope)
: ScriptRuntime.toObject(scope, args[0]));
result.setParentScope(varObj);
return result;
}
private Function checkProto() {
Scriptable proto = getPrototype();
if (!(proto instanceof Function)) {
throw Context.reportRuntimeError(Context.getMessage
("msg.closure.proto", null));
}
return (Function) proto;
}
}

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -222,14 +204,7 @@ public class NativeDate extends ScriptableObject {
if (d < (step = 31))
return 0;
// Originally coded as step += (InLeapYear(t) ? 29 : 28);
// but some jits always returned 28!
if (InLeapYear(t))
step += 29;
else
step += 28;
step += (InLeapYear(t) ? 29 : 28);
if (d < step)
return 1;
if (d < (step += 31))
@@ -257,17 +232,11 @@ public class NativeDate extends ScriptableObject {
int d, step, next;
d = DayWithinYear(t);
if (d <= (next = 30))
return d + 1;
step = next;
// Originally coded as next += (InLeapYear(t) ? 29 : 28);
// but some jits always returned 28!
if (InLeapYear(t))
next += 29;
else
next += 28;
next += (InLeapYear(t) ? 29 : 28);
if (d <= next)
return d - step;
step = next;
@@ -298,7 +267,6 @@ public class NativeDate extends ScriptableObject {
if (d <= (next += 30))
return d - step;
step = next;
return d - step;
}
@@ -1113,10 +1081,9 @@ public class NativeDate extends ScriptableObject {
private static NativeDate checkInstance(Scriptable obj,
Function funObj) {
if (obj == null || !(obj instanceof NativeDate)) {
Context cx = Context.getCurrentContext();
Object[] args = { ((NativeFunction) funObj).names[0] };
String msg = Context.getMessage("msg.incompat.call", args);
throw NativeGlobal.constructError(cx, "TypeError", msg, funObj);
throw Context.reportRuntimeError(
Context.getMessage("msg.incompat.call", args));
}
return (NativeDate) obj;
}
@@ -1420,7 +1387,7 @@ public class NativeDate extends ScriptableObject {
Object argz[] = { "zzz" };
Class clazz = Class.forName("java.text.SimpleDateFormat");
java.lang.reflect.Constructor conztruct =
clazz.getConstructor(paramz);
clazz.getDeclaredConstructor(paramz);
timeZoneFormatter =
(java.text.DateFormat) conztruct.newInstance(argz);
} catch (Exception e) {

View File

@@ -1,82 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
package org.mozilla.javascript;
/**
*
* The class of error objects
*
* ECMA 15.11
*/
public class NativeError extends ScriptableObject {
public NativeError() {
}
public String getClassName() {
return "Error";
}
public String toString() {
return getName() + ": " + getMessage();
}
public String jsFunction_toString() {
return toString();
}
public String getName() {
return ScriptRuntime.toString(
ScriptRuntime.getProp(this, "name", this));
}
public String getMessage() {
return ScriptRuntime.toString(
ScriptRuntime.getProp(this, "message", this));
}
public static void finishInit(Scriptable scope, FunctionObject ctor,
Scriptable proto)
throws PropertyException
{
((ScriptableObject) proto).defineProperty("message", "",
ScriptableObject.EMPTY);
((ScriptableObject) proto).defineProperty("name", "Error",
ScriptableObject.EMPTY);
}
}

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -73,17 +54,12 @@ public class NativeFunction extends ScriptableObject implements Function {
return result;
if (s.equals("prototype")) {
NativeObject obj = new NativeObject();
obj.setPrototype(getObjectPrototype(this));
final int attr = ScriptableObject.DONTENUM |
ScriptableObject.READONLY |
ScriptableObject.PERMANENT;
obj.defineProperty("constructor", this, attr);
// put the prototype property into the object now, then in the
// wacky case of a user defining a function Object(), we don't
// get an infinite loop trying to find the prototype.
put(s, this, obj);
Scriptable proto = getObjectPrototype(this);
if (proto != obj) // not the one we just made, it must remain grounded
obj.setPrototype(proto);
put(s, this, obj);
return obj;
}
if (s.equals("arguments")) {
@@ -115,15 +91,20 @@ public class NativeFunction extends ScriptableObject implements Function {
*
*/
public boolean hasInstance(Scriptable instance) {
Object protoProp = ScriptableObject.getProperty(this, "prototype");
if (protoProp instanceof Scriptable && protoProp != Undefined.instance) {
return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp);
FlattenedObject flat = new FlattenedObject(this);
Object protoProp = flat.getProperty("prototype");
try {
protoProp = ((FlattenedObject)protoProp).getObject();
} catch (ClassCastException e) {
Object[] args = { names[0] };
throw Context.reportRuntimeError(Context.getMessage
("msg.instanceof.bad.prototype", args));
}
Object[] args = { names[0] };
String m = ScriptRuntime.getMessage("msg.instanceof.bad.prototype",
args);
throw NativeGlobal.constructError(Context.getContext(), "TypeError",
m, instance);
return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp);
}
/**
@@ -138,9 +119,7 @@ public class NativeFunction extends ScriptableObject implements Function {
protected Scriptable getClassPrototype() {
Object protoVal = get("prototype", this);
if (protoVal == null
|| !(protoVal instanceof Scriptable)
|| (protoVal == Undefined.instance))
if (protoVal == null || !(protoVal instanceof Scriptable))
protoVal = getClassPrototype(this, "Object");
return (Scriptable) protoVal;
}
@@ -264,7 +243,7 @@ public class NativeFunction extends ScriptableObject implements Function {
if (!justbody) {
result.append("function ");
/* version != 1.2 Function constructor behavior - if
/* version < 1.2 Function constructor behavior - if
* there's no function name in the source info, and
* the names[0] entry is the empty string, then it must
* have been created by the Function constructor;
@@ -276,7 +255,7 @@ public class NativeFunction extends ScriptableObject implements Function {
if (nextIs(i, TokenStream.LP)
&& this.version != Context.VERSION_1_2
&& this.names != null
&& this.names[0].equals("anonymous"))
&& this.names[0].length() == 0)
result.append("anonymous");
i++;
} else {
@@ -848,11 +827,7 @@ public class NativeFunction extends ScriptableObject implements Function {
if (!(val instanceof NativeFunction)) {
Object[] errArgs = { "toString" };
String message = Context.getMessage("msg.incompat.call", errArgs);
throw NativeGlobal.constructError(cx, "TypeError", message, funObj);
}
if (val instanceof NativeJavaMethod) {
return "\nfunction " + ((NativeFunction) val).jsGet_name() +
"() {/*\n" + val.toString() + "*/}\n";
throw Context.reportRuntimeError(message);
}
int indent = 0;
@@ -904,7 +879,8 @@ public class NativeFunction extends ScriptableObject implements Function {
if (fn.names == null)
fn.names = new String[1];
fn.names[0] = "anonymous";
fn.names[0] = "";
fn.setPrototype(getFunctionPrototype(global));
fn.setParentScope(global);
@@ -924,22 +900,10 @@ public class NativeFunction extends ScriptableObject implements Function {
return jsFunction_call(cx, thisObj, args, funObj);
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
Scriptable newThis = args[0] == null
? ScriptableObject.getTopLevelScope(thisObj)
? null
: ScriptRuntime.toObject(funObj, args[0]);
Object[] newArgs;
if (args.length > 1) {
if ((args[1] instanceof NativeArray)
|| (args[1] instanceof Arguments))
newArgs = cx.getElements((Scriptable) args[1]);
else
throw NativeGlobal.constructError(
cx, "TypeError",
ScriptRuntime.getMessage("msg.arg.isnt.array", null),
thisObj);
}
else
newArgs = new Object[0];
return ScriptRuntime.call(cx, val, newThis, newArgs, newThis);
Object[] newArgs = cx.getElements((Scriptable) args[1]);
return ScriptRuntime.call(cx, val, newThis, newArgs);
}
/**
@@ -954,23 +918,22 @@ public class NativeFunction extends ScriptableObject implements Function {
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
if (args.length == 0) {
Scriptable s = ScriptRuntime.toObject(funObj, val);
Scriptable scope = s.getParentScope();
return ScriptRuntime.call(cx, val, scope, ScriptRuntime.emptyArgs,
scope);
return ScriptRuntime.call(cx, val, s.getParentScope(),
ScriptRuntime.emptyArgs);
} else {
Scriptable newThis = args[0] == null
? ScriptableObject.getTopLevelScope(thisObj)
? null
: ScriptRuntime.toObject(funObj, args[0]);
Object[] newArgs = new Object[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
return ScriptRuntime.call(cx, val, newThis, newArgs, newThis);
return ScriptRuntime.call(cx, val, newThis, newArgs);
}
}
public int jsGet_length() {
Context cx = Context.getContext();
if (cx != null && cx.getLanguageVersion() != Context.VERSION_1_2)
if (cx.getLanguageVersion() != Context.VERSION_1_2)
return argCount;
NativeCall activation = getActivation(cx);
if (activation == null)
@@ -983,14 +946,14 @@ public class NativeFunction extends ScriptableObject implements Function {
}
public String jsGet_name() {
if (names == null)
if (names != null && names[0].length() > 0)
return names[0];
Context cx = Context.getCurrentContext();
if (cx != null && cx.getLanguageVersion() == Context.VERSION_1_2) {
return "";
if (names[0].equals("anonymous")) {
Context cx = Context.getCurrentContext();
if (cx != null && cx.getLanguageVersion() == Context.VERSION_1_2)
return "";
}
return names[0];
return "anonymous";
}
private NativeCall getActivation(Context cx) {

View File

@@ -1,44 +1,25 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
import java.io.StringReader;
import java.io.IOException;
import java.lang.reflect.Method;
/**
* This class implements the global native object (function and value
@@ -52,9 +33,7 @@ import java.lang.reflect.Method;
public class NativeGlobal {
public static void init(Scriptable scope)
throws PropertyException,
NotAFunctionException,
JavaScriptException
throws PropertyException
{
String names[] = { "eval",
@@ -63,11 +42,7 @@ public class NativeGlobal {
"escape",
"unescape",
"isNaN",
"isFinite",
"decodeURI",
"decodeURIComponent",
"encodeURI",
"encodeURIComponent"
"isFinite"
};
// We can downcast here because Context.initStandardObjects
@@ -82,31 +57,6 @@ public class NativeGlobal {
ScriptableObject.DONTENUM);
global.defineProperty("undefined", Undefined.instance,
ScriptableObject.DONTENUM);
String[] errorMethods = { "ConversionError",
"EvalError",
"RangeError",
"ReferenceError",
"SyntaxError",
"TypeError",
"URIError"
};
Method[] m = FunctionObject.findMethods(NativeGlobal.class,
"CommonError");
Context cx = Context.getContext();
/*
Each error constructor gets its own Error object as a prototype,
with the 'name' property set to the name of the error.
*/
for (int i = 0; i < errorMethods.length; i++) {
String name = errorMethods[i];
FunctionObject ctor = new FunctionObject(name, m[0], global);
global.defineProperty(name, ctor, ScriptableObject.DONTENUM);
Scriptable errorProto = cx.newObject(scope, "Error");
errorProto.put("name", errorProto, name);
ctor.put("prototype", ctor, errorProto);
}
}
/**
@@ -386,9 +336,9 @@ public class NativeGlobal {
Object[] args, Function funObj)
throws JavaScriptException
{
Object[] a = { "eval" };
String m = ScriptRuntime.getMessage("msg.cant.call.indirect", a);
throw NativeGlobal.constructError(cx, "EvalError", m, funObj);
Object[] msgArgs = { "eval" };
throw Context.reportRuntimeError(
Context.getMessage("msg.cant.call.indirect", msgArgs));
}
/**
@@ -426,7 +376,7 @@ public class NativeGlobal {
// mode.
int oldOptLevel = cx.getOptimizationLevel();
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(scope, in, filename, linep[0],
Script script = cx.compileReader(null, in, filename, linep[0],
securityDomain);
cx.setOptimizationLevel(oldOptLevel);
@@ -440,7 +390,6 @@ public class NativeGlobal {
}
InterpretedScript is = (InterpretedScript) script;
is.itsData.itsFromEvalCode = true;
Object result = is.call(cx, scope, (Scriptable) thisArg, null);
return result;
@@ -449,310 +398,6 @@ public class NativeGlobal {
// should never happen since we just made the Reader from a String
throw new RuntimeException("unexpected io exception");
}
}
/**
* The NativeError functions
*
* See ECMA 15.11.6
*/
public static EcmaError constructError(Context cx,
String error,
String message,
Object scope)
{
int[] linep = { 0 };
String filename = cx.getSourcePositionFromStack(linep);
return constructError(cx, error, message, scope,
filename, linep[0], 0, null);
}
/**
* The NativeError functions
*
* See ECMA 15.11.6
*/
public static EcmaError constructError(Context cx,
String error,
String message,
Object scope,
String sourceName,
int lineNumber,
int columnNumber,
String lineSource)
{
Scriptable scopeObject;
try {
scopeObject = (Scriptable) scope;
}
catch (ClassCastException x) {
throw new RuntimeException(x.toString());
}
Object args[] = { message };
try {
Object errorObject = cx.newObject(scopeObject, error, args);
return new EcmaError((NativeError)errorObject, sourceName,
lineNumber, columnNumber, lineSource);
}
catch (PropertyException x) {
throw new RuntimeException(x.toString());
}
catch (JavaScriptException x) {
throw new RuntimeException(x.toString());
}
catch (NotAFunctionException x) {
throw new RuntimeException(x.toString());
}
}
/**
* The implementation of all the ECMA error constructors (SyntaxError,
* TypeError, etc.)
*/
public static Object CommonError(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr)
{
Scriptable newInstance = new NativeError();
newInstance.setPrototype((Scriptable)(ctorObj.get("prototype", ctorObj)));
newInstance.setParentScope(cx.ctorScope);
if (args.length > 0)
newInstance.put("message", newInstance, args[0]);
return newInstance;
}
/*
* ECMA 3, 15.1.3 URI Handling Function Properties
*
* The following are implementations of the algorithms
* given in the ECMA specification for the hidden functions
* 'Encode' and 'Decode'.
*/
private static String encode(Context cx, String str, String unescapedSet)
{
int j, k = 0, L;
char C, C2;
int V;
char utf8buf[] = new char[6];
StringBuffer R;
R = new StringBuffer();
while (k < str.length()) {
C = str.charAt(k);
if (unescapedSet.indexOf(C) != -1) {
R.append(C);
} else {
if ((C >= 0xDC00) && (C <= 0xDFFF)) {
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
}
if ((C < 0xD800) || (C > 0xDBFF))
V = C;
else {
k++;
if (k == str.length()) {
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
}
C2 = str.charAt(k);
if ((C2 < 0xDC00) || (C2 > 0xDFFF)) {
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
}
V = ((C - 0xD800) << 10) + (C2 - 0xDC00) + 0x10000;
}
L = oneUcs4ToUtf8Char(utf8buf, V);
for (j = 0; j < L; j++) {
R.append('%');
if (utf8buf[j] < 16)
R.append('0');
R.append(Integer.toHexString(utf8buf[j]));
}
}
k++;
}
return R.toString();
}
private static boolean isHex(char c) {
return ((c >= '0' && c <= '9')
|| (c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F'));
}
private static int unHex(char c) {
if (c >= '0' && c <= '9')
return c - '0';
else
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
else
return c - 'A' +10;
}
private static String decode(Context cx, String str, String reservedSet)
{
int start, k = 0;
char C, H;
int V;
int B;
char[] octets = new char[6];
StringBuffer R;
int j, n;
R = new StringBuffer();
while (k < str.length()) {
C = str.charAt(k);
if (C == '%') {
start = k;
if ((k + 2) >= str.length())
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
if (!isHex(str.charAt(k + 1)) || !isHex(str.charAt(k + 2)))
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
B = unHex(str.charAt(k + 1)) * 16 + unHex(str.charAt(k + 2));
k += 2;
if ((B & 0x80) == 0)
C = (char)B;
else {
n = 1;
while ((B & (0x80 >>> n)) != 0) n++;
if ((n == 1) || (n > 6))
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
octets[0] = (char)B;
if ((k + 3 * (n - 1)) >= str.length())
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
for (j = 1; j < n; j++) {
k++;
if (str.charAt(k) != '%')
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
if (!isHex(str.charAt(k + 1))
|| !isHex(str.charAt(k + 2)))
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
B = unHex(str.charAt(k + 1)) * 16
+ unHex(str.charAt(k + 2));
if ((B & 0xC0) != 0x80)
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
k += 2;
octets[j] = (char)B;
}
V = utf8ToOneUcs4Char(octets, n);
if (V >= 0x10000) {
V -= 0x10000;
if (V > 0xFFFFF)
throw cx.reportRuntimeError(
cx.getMessage("msg.bad.uri", null));
C = (char)((V & 0x3FF) + 0xDC00);
H = (char)((V >>> 10) + 0xD800);
R.append(H);
}
else
C = (char)V;
}
if (reservedSet.indexOf(C) != -1) {
for (int x = 0; x < (k - start + 1); x++)
R.append(str.charAt(start + x));
}
else
R.append(C);
}
else
R.append(C);
k++;
}
return R.toString();
}
private static String uriReservedPlusPound = ";/?:@&=+$,#";
private static String uriUnescaped =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";
public static String decodeURI(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
String str = ScriptRuntime.toString(args[0]);
return decode(cx, str, uriReservedPlusPound);
}
public static String decodeURIComponent(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
String str = ScriptRuntime.toString(args[0]);
return decode(cx, str, "");
}
public static Object encodeURI(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
String str = ScriptRuntime.toString(args[0]);
return encode(cx, str, uriReservedPlusPound + uriUnescaped);
}
public static String encodeURIComponent(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
String str = ScriptRuntime.toString(args[0]);
return encode(cx, str, uriUnescaped);
}
/* Convert one UCS-4 char and write it into a UTF-8 buffer, which must be
* at least 6 bytes long. Return the number of UTF-8 bytes of data written.
*/
private static int oneUcs4ToUtf8Char(char[] utf8Buffer, int ucs4Char)
{
int utf8Length = 1;
// JS_ASSERT(ucs4Char <= 0x7FFFFFFF);
if ((ucs4Char < 0x80) && (ucs4Char >= 0))
utf8Buffer[0] = (char)ucs4Char;
else {
int i;
int a = ucs4Char >>> 11;
utf8Length = 2;
while (a != 0) {
a >>>= 5;
utf8Length++;
}
i = utf8Length;
while (--i > 0) {
utf8Buffer[i] = (char)((ucs4Char & 0x3F) | 0x80);
ucs4Char >>>= 6;
}
utf8Buffer[0] = (char)(0x100 - (1 << (8-utf8Length)) + ucs4Char);
}
return utf8Length;
}
/* Convert a utf8 character sequence into a UCS-4 character and return that
* character. It is assumed that the caller already checked that the sequence is valid.
*/
private static int utf8ToOneUcs4Char(char[] utf8Buffer, int utf8Length)
{
int ucs4Char;
int k = 0;
// JS_ASSERT(utf8Length >= 1 && utf8Length <= 6);
if (utf8Length == 1) {
ucs4Char = utf8Buffer[0];
// JS_ASSERT(!(ucs4Char & 0x80));
} else {
// JS_ASSERT((*utf8Buffer & (0x100 - (1 << (7-utf8Length)))) == (0x100 - (1 << (8-utf8Length))));
ucs4Char = utf8Buffer[k++] & ((1<<(7-utf8Length))-1);
while (--utf8Length > 0) {
// JS_ASSERT((*utf8Buffer & 0xC0) == 0x80);
ucs4Char = ucs4Char<<6 | (utf8Buffer[k++] & 0x3F);
}
}
return ucs4Char;
}
}

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -84,17 +65,7 @@ public class NativeJavaArray extends NativeJavaObject {
public Object get(String id, Scriptable start) {
if (id.equals("length"))
return new Integer(length);
Object result = super.get(id, start);
if (result == NOT_FOUND &&
!ScriptRuntime.hasProp(getPrototype(), id))
{
Object errArgs[] = { array.getClass().getName(),
id };
throw Context.reportRuntimeError(
Context.getMessage("msg.java.member.not.found",
errArgs));
}
return result;
return super.get(id, start);
}
public Object get(int index, Scriptable start) {

View File

@@ -1,39 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
* Kurt Westerfeld
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -61,8 +41,7 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
public NativeJavaClass(Scriptable scope, Class cl) {
super(scope, cl, JavaMembers.lookupClass(scope, cl, cl));
fieldAndMethods = members.getFieldAndMethodsObjects(this, javaObject,
true);
fieldAndMethods = members.getFieldAndMethodsObjects(javaObject, false);
}
public String getClassName() {
@@ -96,14 +75,12 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
// experimental: look for nested classes by appending $name to current class' name.
try {
String nestedName = getClassObject().getName() + '$' + name;
Class nestedClass = ScriptRuntime.loadClassName(nestedName);
Class nestedClass = Class.forName(nestedName);
Scriptable nestedValue = wrap(ScriptableObject.getTopLevelScope(this), nestedClass);
nestedValue.setParentScope(this);
result = nestedValue;
} catch (ClassNotFoundException ex) {
throw members.reportMemberNotFound(name);
} catch (IllegalArgumentException e) {
throw members.reportMemberNotFound(name);
}
}
@@ -141,21 +118,6 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
Object[] args)
throws JavaScriptException
{
// If it looks like a "cast" of an object to this class type,
// walk the prototype chain to see if there's a wrapper of a
// object that's an instanceof this class.
if (args.length == 1 && args[0] instanceof Scriptable) {
Class c = getClassObject();
Scriptable p = (Scriptable) args[0];
do {
if (p instanceof Wrapper) {
Object o = ((Wrapper) p).unwrap();
if (c.isInstance(o))
return p;
}
p = p.getPrototype();
} while (p != null);
}
return construct(cx, scope, args);
}
@@ -183,7 +145,7 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
} else {
Scriptable topLevel = ScriptableObject.getTopLevelScope(this);
String msg = "";
try {
try {
// trying to construct an interface; use JavaAdapter to
// construct a new class on the fly that implements this
// interface.
@@ -196,12 +158,10 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
}
} catch (Exception ex) {
// fall through to error
String m = ex.getMessage();
if (m != null)
msg = m;
msg = ex.getMessage();
}
Object[] errArgs = { msg, classObject.getName() };
throw Context.reportRuntimeError(Context.getMessage
Object[] errArgs = { msg, classObject.getName() };
throw Context.reportRuntimeError(Context.getMessage
("msg.cant.instantiate",
errArgs));
}

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -76,7 +57,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
names[0] = method.getName();
} else if (!names[0].equals(method.getName())) {
throw new RuntimeException("internal method name mismatch");
}
}
// XXX a more intelligent growth algorithm would be nice
int len = methods == null ? 0 : methods.length;
Method[] newMeths = new Method[len + 1];
@@ -154,17 +135,6 @@ public class NativeJavaMethod extends NativeFunction implements Function {
return "(" + javaSignature(paramTypes) + ")";
}
}
public String toString() {
StringBuffer sb = new StringBuffer();
for (int i=0; i < methods.length; i++) {
sb.append(javaSignature(methods[i].getReturnType()));
sb.append(' ');
sb.append(signature(methods[i]));
sb.append('\n');
}
return sb.toString();
}
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args)
@@ -194,23 +164,21 @@ public class NativeJavaMethod extends NativeFunction implements Function {
args[i] = NativeJavaObject.coerceType(paramTypes[i], args[i]);
}
Object javaObject;
if (Modifier.isStatic(meth.getModifiers())) {
javaObject = null; // don't need an object
} else {
Scriptable o = thisObj;
while (!(o instanceof NativeJavaObject)) {
o = o.getPrototype();
if (o == null) {
Object errArgs[] = { names[0] };
throw Context.reportRuntimeError(
Context.getMessage("msg.nonjava.method", errArgs));
}
try {
javaObject = ((NativeJavaObject) thisObj).unwrap();
}
catch (ClassCastException e) {
if (Modifier.isStatic(meth.getModifiers())) {
javaObject = null; // don't need it anyway
} else {
Object errArgs[] = { names[0] };
throw Context.reportRuntimeError(
Context.getMessage("msg.nonjava.method", errArgs));
}
javaObject = ((NativeJavaObject) o).unwrap();
}
try {
if (debug) {
printDebug("Calling ", meth, args);
printDebug("Calling", meth, args);
}
Object retval = meth.invoke(javaObject, args);
@@ -231,10 +199,18 @@ public class NativeJavaMethod extends NativeFunction implements Function {
" class = " + actualType);
}
// XXX set prototype && parent
if (wrapped == Undefined.instance)
return wrapped;
if (wrapped == null && staticType == Void.TYPE)
return Undefined.instance;
if (retval != wrapped && wrapped instanceof Scriptable) {
Scriptable s = (Scriptable)wrapped;
if (s.getPrototype() == null)
s.setPrototype(parent.getPrototype());
if (s.getParentScope() == null)
s.setParentScope(parent.getParentScope());
}
return wrapped;
} catch (IllegalAccessException accessEx) {
throw Context.reportRuntimeError(accessEx.getMessage());
@@ -287,8 +263,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
int j;
for (j = 0; j < paramTypes.length; j++) {
if (!NativeJavaObject.canConvert(args[j], paramTypes[j])) {
if (debug) printDebug("Rejecting (args can't convert) ",
member, args);
if (debug) printDebug("Rejecting ", member, args);
break;
}
}
@@ -316,22 +291,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
bestFitTypes = paramTypes;
}
else {
if (preference == PREFERENCE_EQUAL &&
Modifier.isStatic(bestFit.getModifiers()) &&
bestFit.getDeclaringClass().isAssignableFrom(
member.getDeclaringClass()))
{
// On some JVMs, Class.getMethods will return all
// static methods of the class heirarchy, even if
// a derived class's parameters match exactly.
// We want to call the dervied class's method.
if (debug) printDebug("Rejecting (overridden static)",
member, args);
bestFit = member;
bestFitTypes = paramTypes;
} else {
if (debug) printDebug("Rejecting ", member, args);
}
if (debug) printDebug("Rejecting ", member, args);
}
}
}
@@ -426,8 +386,8 @@ public class NativeJavaMethod extends NativeFunction implements Function {
* PREFERENCE_SECOND_ARG, or PREFERENCE_AMBIGUOUS.
*/
public static int preferSignature(Object[] args,
Class[] sig1, Class[] sig2)
{
Class[] sig1, Class[] sig2) {
int preference = 0;
for (int j = 0; j < args.length; j++) {

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -70,7 +51,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
Class dynamicType = javaObject != null ? javaObject.getClass()
: staticType;
members = JavaMembers.lookupClass(scope, dynamicType, staticType);
fieldAndMethods = members.getFieldAndMethodsObjects(this, javaObject, false);
fieldAndMethods = members.getFieldAndMethodsObjects(javaObject, false);
}
public boolean has(String name, Scriptable start) {
@@ -84,9 +65,8 @@ public class NativeJavaObject implements Scriptable, Wrapper {
public Object get(String name, Scriptable start) {
if (fieldAndMethods != null) {
Object result = fieldAndMethods.get(name);
if (result != null) {
if (result != null)
return result;
}
}
// TODO: passing 'this' as the scope is bogus since it has
// no parent scope
@@ -117,17 +97,13 @@ public class NativeJavaObject implements Scriptable, Wrapper {
}
public Scriptable getPrototype() {
if (prototype == null && javaObject.getClass() == ScriptRuntime.StringClass) {
if (javaObject.getClass() == ScriptRuntime.StringClass) {
return ScriptableObject.getClassPrototype(parent, "String");
}
return prototype;
return null;
}
/**
* Sets the prototype of the object.
*/
public void setPrototype(Scriptable m) {
prototype = m;
public void setPrototype(Scriptable prototype) {
}
/**
@@ -152,12 +128,6 @@ public class NativeJavaObject implements Scriptable, Wrapper {
{
if (obj == null)
return obj;
Context cx = Context.getCurrentContext();
if (cx != null && cx.wrapHandler != null) {
Object result = cx.wrapHandler.wrap(scope, obj, staticType);
if (result != null)
return result;
}
Class cls = obj.getClass();
if (staticType != null && staticType.isPrimitive()) {
if (staticType == Void.TYPE)
@@ -172,17 +142,17 @@ public class NativeJavaObject implements Scriptable, Wrapper {
return obj;
if (Context.useJSObject && jsObjectClass != null &&
staticType != jsObjectClass && jsObjectClass.isInstance(obj))
{
try {
return jsObjectGetScriptable.invoke(obj, ScriptRuntime.emptyArgs);
{
try {
return jsObjectGetScriptable.invoke(obj, ScriptRuntime.emptyArgs);
}
catch (InvocationTargetException e) {
// Just abandon conversion from JSObject
}
catch (IllegalAccessException e) {
// Just abandon conversion from JSObject
}
}
catch (InvocationTargetException e) {
// Just abandon conversion from JSObject
}
catch (IllegalAccessException e) {
// Just abandon conversion from JSObject
}
}
return new NativeJavaObject(scope, obj, staticType);
}
@@ -217,8 +187,8 @@ public class NativeJavaObject implements Scriptable, Wrapper {
if (converter == null) {
Object[] errArgs = { converterName, javaObject.getClass().getName() };
throw Context.reportRuntimeError(
Context.getMessage("msg.java.conversion.implicit_method",
errArgs));
Context.getMessage("msg.java.conversion.implicit_method",
errArgs));
}
return callConverter(converter);
}
@@ -237,7 +207,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
// fall through to error message
}
throw Context.reportRuntimeError(
Context.getMessage("msg.default.value", null));
Context.getMessage("msg.default.value", null));
}
@@ -396,12 +366,6 @@ public class NativeJavaObject implements Scriptable, Wrapper {
jsObjectClass.isAssignableFrom(to)) {
result = 1;
}
else if (fromObj instanceof NativeArray && to.isArray()) {
// This is a native array conversion to a java array
// Array conversions are all equal, and preferable to object
// and string conversion, per LC3.
result = 1;
}
else if (to == ScriptRuntime.ObjectClass) {
result = 2;
}
@@ -501,7 +465,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
if (value != null && value.getClass() == type) {
return value;
}
switch (NativeJavaObject.getJSTypeCode(value)) {
case JSTYPE_NULL:
@@ -647,25 +611,6 @@ public class NativeJavaObject implements Scriptable, Wrapper {
else if (type.isInstance(value)) {
return value;
}
else if (type.isArray() && value instanceof NativeArray) {
// Make a new java array, and coerce the JS array components
// to the target (component) type.
NativeArray array = (NativeArray) value;
long length = array.jsGet_length();
Class arrayType = type.getComponentType();
Object Result = Array.newInstance(arrayType, (int)length);
for (int i = 0 ; i < length ; ++i) {
try {
Array.set(Result, i, coerceType(arrayType,
array.get(i, array)));
}
catch (EvaluatorException ee) {
reportConversionError(value, type);
}
}
return Result;
}
else {
reportConversionError(value, type);
}
@@ -691,7 +636,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
} catch (IllegalArgumentException argEx) {
throw new EvaluatorException("JSObject constructor doesn't want [Scriptable]!");
} catch (InvocationTargetException e) {
throw WrappedException.wrapException(e.getTargetException());
throw WrappedException.wrapException(e);
} catch (IllegalAccessException accessEx) {
throw new EvaluatorException("JSObject constructor is protected/private!");
}
@@ -707,8 +652,8 @@ public class NativeJavaObject implements Scriptable, Wrapper {
}
return new Character((char)toInteger(value,
ScriptRuntime.CharacterClass,
(double)Character.MIN_VALUE,
(double)Character.MAX_VALUE));
Character.MIN_VALUE,
Character.MAX_VALUE));
}
// Double, Float
@@ -754,8 +699,8 @@ public class NativeJavaObject implements Scriptable, Wrapper {
else {
return new Integer((int)toInteger(value,
ScriptRuntime.IntegerClass,
(double)Integer.MIN_VALUE,
(double)Integer.MAX_VALUE));
Integer.MIN_VALUE,
Integer.MAX_VALUE));
}
}
@@ -764,19 +709,10 @@ public class NativeJavaObject implements Scriptable, Wrapper {
return value;
}
else {
/* Long values cannot be expressed exactly in doubles.
* We thus use the largest and smallest double value that
* has a value expressible as a long value. We build these
* numerical values from their hexidecimal representations
* to avoid any problems caused by attempting to parse a
* decimal representation.
*/
final double max = Double.longBitsToDouble(0x43dfffffffffffffL);
final double min = Double.longBitsToDouble(0xc3e0000000000000L);
return new Long(toInteger(value,
ScriptRuntime.LongClass,
min,
max));
Long.MIN_VALUE,
Long.MAX_VALUE));
}
}
@@ -787,8 +723,8 @@ public class NativeJavaObject implements Scriptable, Wrapper {
else {
return new Short((short)toInteger(value,
ScriptRuntime.ShortClass,
(double)Short.MIN_VALUE,
(double)Short.MAX_VALUE));
Short.MIN_VALUE,
Short.MAX_VALUE));
}
}
@@ -799,8 +735,8 @@ public class NativeJavaObject implements Scriptable, Wrapper {
else {
return new Byte((byte)toInteger(value,
ScriptRuntime.ByteClass,
(double)Byte.MIN_VALUE,
(double)Byte.MAX_VALUE));
Byte.MIN_VALUE,
Byte.MAX_VALUE));
}
}
@@ -825,6 +761,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
}
}
else {
double result = Double.NaN;
Method meth;
try {
meth = value.getClass().getMethod("doubleValue", null);
@@ -852,7 +789,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
}
}
static long toInteger(Object value, Class type, double min, double max) {
static long toInteger(Object value, Class type, long min, long max) {
double d = toDouble(value);
if (Double.isInfinite(d) || Double.isNaN(d)) {
@@ -867,7 +804,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
d = Math.ceil(d);
}
if (d < min || d > max) {
if (d < (double)min || d > (double)max) {
// Convert to string first, for more readable message
reportConversionError(ScriptRuntime.toString(value), type);
}
@@ -875,11 +812,8 @@ public class NativeJavaObject implements Scriptable, Wrapper {
}
static void reportConversionError(Object value, Class type) {
Object[] args = { value.toString(),
NativeJavaMethod.javaSignature(type)
};
throw Context.reportRuntimeError(
Context.getMessage("msg.conversion.not.allowed", args));
Object[] args = {value, type};
throw Context.reportRuntimeError(Context.getMessage("msg.conversion.not.allowed", args));
}
public static void initJSObject() {
@@ -901,11 +835,6 @@ public class NativeJavaObject implements Scriptable, Wrapper {
}
}
/**
* The prototype of this object.
*/
protected Scriptable prototype;
/**
* The parent scope of this object.
*/

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Frank Mitchell
* Mike Shaver
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -93,10 +74,9 @@ public class NativeJavaPackage extends ScriptableObject {
NativeJavaObject.initJSObject();
Method[] m = FunctionObject.findMethods(NativeJavaPackage.class,
"jsFunction_getClass");
FunctionObject f = new FunctionObject("getClass", m[0], global);
global.defineProperty("getClass", f, ScriptableObject.DONTENUM);
String[] methods = { "getClass" };
global.defineFunctionProperties(methods, NativeJavaPackage.class,
ScriptableObject.DONTENUM);
// I think I'm supposed to return the prototype, but I don't have one.
return packages;
@@ -144,18 +124,13 @@ public class NativeJavaPackage extends ScriptableObject {
}
public void put(int index, Scriptable start, Object value) {
throw Context.reportRuntimeError(
Context.getMessage("msg.pkg.int", null));
// Can't add properties to Java packages. Sorry.
}
public Object get(String id, Scriptable start) {
return getPkgProperty(id, start, true);
}
public Object get(int index, Scriptable start) {
return NOT_FOUND;
}
synchronized Object getPkgProperty(String name, Scriptable start,
boolean createPkg)
{
@@ -172,7 +147,7 @@ public class NativeJavaPackage extends ScriptableObject {
try {
if (ss != null && !ss.visibleToScripts(newPackage))
throw new ClassNotFoundException();
Class newClass = ScriptRuntime.loadClassName(newPackage);
Class newClass = Class.forName(newPackage);
newValue = NativeJavaClass.wrap(getTopLevelScope(this), newClass);
newValue.setParentScope(this);
newValue.setPrototype(this.prototype);
@@ -194,6 +169,10 @@ public class NativeJavaPackage extends ScriptableObject {
return newValue;
}
public Object get(int index, Scriptable start) {
return NOT_FOUND;
}
public Object getDefaultValue(Class ignored) {
return toString();
}
@@ -202,10 +181,8 @@ public class NativeJavaPackage extends ScriptableObject {
return "[JavaPackage " + packageName + "]";
}
public static Scriptable jsFunction_getClass(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
public static Scriptable getClass(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
if (args.length > 0 && args[0] instanceof NativeJavaObject) {
NativeJavaObject nativeJavaObj = (NativeJavaObject) args[0];

View File

@@ -1,35 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -48,8 +32,8 @@ public class NativeMath extends ScriptableObject {
m.setPrototype(getObjectPrototype(scope));
m.setParentScope(scope);
String[] names = { "atan", "atan2", "ceil",
"cos", "floor", "random",
String[] names = { "acos", "asin", "atan", "atan2", "ceil",
"cos", "floor", "log", "random",
"sin", "sqrt", "tan" };
m.defineFunctionProperties(names, java.lang.Math.class,
@@ -57,19 +41,11 @@ public class NativeMath extends ScriptableObject {
// These functions exist in java.lang.Math, but
// are overloaded. Define our own wrappers.
String[] localNames = { "acos", "asin", "abs", "exp", "max", "min",
"round", "pow", "log" };
String[] localNames = { "abs", "exp", "max", "min", "round", "pow" };
m.defineFunctionProperties(localNames, NativeMath.class,
ScriptableObject.DONTENUM);
/*
have to fix up the length property for max & min
which are varargs form, but need to have a length of 2
*/
((FunctionObject)m.get("max", scope)).setLength((short)2);
((FunctionObject)m.get("min", scope)).setLength((short)2);
final int attr = ScriptableObject.DONTENUM |
ScriptableObject.PERMANENT |
ScriptableObject.READONLY;
@@ -90,7 +66,7 @@ public class NativeMath extends ScriptableObject {
return m;
}
public NativeMath() {
}
@@ -98,7 +74,7 @@ public class NativeMath extends ScriptableObject {
return "Math";
}
public static double abs(double d) {
public double abs(double d) {
if (d == 0.0)
return 0.0; // abs(-0.0) should be 0.0, but -0.0 < 0.0 == false
else if (d < 0.0)
@@ -107,51 +83,15 @@ public class NativeMath extends ScriptableObject {
return d;
}
public static double acos(double d) {
if ((d != d)
|| (d > 1.0)
|| (d < -1.0))
return Double.NaN;
return Math.acos(d);
public double max(double x, double y) {
return Math.max(x, y);
}
public static double asin(double d) {
if ((d != d)
|| (d > 1.0)
|| (d < -1.0))
return Double.NaN;
return Math.asin(d);
public double min(double x, double y) {
return Math.min(x, y);
}
public static double max(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
double result = Double.NEGATIVE_INFINITY;
if (args.length == 0)
return result;
for (int i = 0; i < args.length; i++) {
double d = ScriptRuntime.toNumber(args[i]);
if (d != d) return d;
result = Math.max(result, d);
}
return result;
}
public static double min(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
double result = Double.POSITIVE_INFINITY;
if (args.length == 0)
return result;
for (int i = 0; i < args.length; i++) {
double d = ScriptRuntime.toNumber(args[i]);
if (d != d) return d;
result = Math.min(result, d);
}
return result;
}
public static double round(double d) {
public double round(double d) {
if (d != d)
return d; // NaN
if (d == Double.POSITIVE_INFINITY || d == Double.NEGATIVE_INFINITY)
@@ -166,33 +106,17 @@ public class NativeMath extends ScriptableObject {
return (double) l;
}
public static double pow(double x, double y) {
public double pow(double x, double y) {
if (y == 0)
return 1.0; // Java's pow(NaN, 0) = NaN; we need 1
if ((x == 0) && (y < 0)) {
Double d = new Double(x);
if (d.equals(new Double(0))) // x is +0
return Double.POSITIVE_INFINITY; // Java is -Infinity
/* if x is -0 and y is an odd integer, -Infinity */
if (((int)y == y) && (((int)y & 0x1) == 1))
return Double.NEGATIVE_INFINITY;
return Double.POSITIVE_INFINITY;
}
return Math.pow(x, y);
}
public static double exp(double d) {
public double exp(double d) {
if (d == Double.POSITIVE_INFINITY)
return d;
if (d == Double.NEGATIVE_INFINITY)
return 0.0;
return Math.exp(d);
}
public static double log(double x) {
if (x < 0)
return Double.NaN; // Java's log(<0) = -Infinity; we need NaN
return Math.log(x);
}
}

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -61,8 +43,6 @@ public class NativeNumber extends ScriptableObject {
ctor.defineProperty(names[i], new Double(values[i]), attr);
}
}
private static final int MAX_PRECISION = 100;
/**
* Zero-parameter constructor: just used to create Number.prototype
@@ -108,55 +88,6 @@ public class NativeNumber extends ScriptableObject {
return doubleValue;
}
public String jsFunction_toLocaleString(Object arg) {
return toString();
}
public String jsFunction_toFixed(Object arg) {
/* We allow a larger range of precision than
ECMA requires; this is permitted by ECMA. */
return num_to(arg, DToA.DTOSTR_FIXED, DToA.DTOSTR_FIXED,
-20, MAX_PRECISION, 0);
}
public String jsFunction_toExponential(Object arg) {
/* We allow a larger range of precision than
ECMA requires; this is permitted by ECMA. */
return num_to(arg, DToA.DTOSTR_STANDARD_EXPONENTIAL,
DToA.DTOSTR_EXPONENTIAL, 0, MAX_PRECISION, 1);
}
public String jsFunction_toPrecision(Object arg) {
/* We allow a larger range of precision than
ECMA requires; this is permitted by ECMA. */
return num_to(arg, DToA.DTOSTR_STANDARD,
DToA.DTOSTR_PRECISION, 1, MAX_PRECISION, 0);
}
private String num_to(Object arg, int zeroArgMode,
int oneArgMode, int precisionMin, int precisionMax, int precisionOffset)
{
int precision;
if (arg == Undefined.instance) {
precision = 0;
oneArgMode = zeroArgMode;
} else {
precision = ScriptRuntime.toInt32(arg);
if (precision < precisionMin || precision > precisionMax) {
Object args[] = new Object[1];
args[0] = Integer.toString(precision);
throw NativeGlobal.constructError(
Context.getCurrentContext(), "RangeError",
ScriptRuntime.getMessage("msg.bad.precision", args),
this);
}
}
StringBuffer result = new StringBuffer();
DToA.JS_dtostr(result, oneArgMode, precision + precisionOffset, doubleValue);
return result.toString();
}
private static final double defaultValue = +0.0;
private double doubleValue;
}

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -141,53 +123,6 @@ public class NativeObject extends ScriptableObject {
{
return thisObj;
}
public static Object jsFunction_hasOwnProperty(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
{
if (args.length != 0)
if (thisObj.has(ScriptRuntime.toString(args[0]), thisObj))
return Boolean.TRUE;
return Boolean.FALSE;
}
public static Object jsFunction_propertyIsEnumerable(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
{
try {
if (args.length != 0) {
String name = ScriptRuntime.toString(args[0]);
if (thisObj.has(name, thisObj)) {
int a = ((ScriptableObject)thisObj).getAttributes(name, thisObj);
if ((a & ScriptableObject.DONTENUM) == 0)
return Boolean.TRUE;
}
}
}
catch (PropertyException x) {
}
catch (ClassCastException x) {
}
return Boolean.FALSE;
}
public static Object jsFunction_isPrototypeOf(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
if (args.length != 0 && args[0] instanceof Scriptable) {
Scriptable v = (Scriptable) args[0];
do {
v = v.getPrototype();
if (v == thisObj)
return Boolean.TRUE;
} while (v != null);
}
return Boolean.FALSE;
}
}

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Tom Beauvais
* Norris Boyd
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -683,27 +664,7 @@ public class NativeString extends ScriptableObject implements Wrapper {
return tagify("A NAME", "A", value);
}
public static Object jsFunction_equals(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
String target = ScriptRuntime.toString(thisObj);
String strOther = ScriptRuntime.toString(args[0]);
return new Boolean(target.equals(strOther));
}
public static Object jsFunction_equalsIgnoreCase(Context cx,
Scriptable thisObj,
Object[] args,
Function funObj)
{
String target = ScriptRuntime.toString(thisObj);
String strOther = ScriptRuntime.toString(args[0]);
return new Boolean(target.equalsIgnoreCase(strOther));
}
/**
/**
* Unwrap this NativeString as a j.l.String for LiveConnect use.
*/

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -58,20 +39,18 @@ public class NodeTransformer {
return new NodeTransformer();
}
public IRFactory createIRFactory(TokenStream ts, Scriptable scope) {
return new IRFactory(ts, scope);
public IRFactory createIRFactory(TokenStream ts) {
return new IRFactory(ts);
}
public Node transform(Node tree, Node enclosing, TokenStream ts,
Scriptable scope)
{
public Node transform(Node tree, Node enclosing, TokenStream ts) {
loops = new Stack();
loopEnds = new Stack();
inFunction = tree.getType() == TokenStream.FUNCTION;
if (!inFunction) {
addVariables(tree, getVariableTable(tree));
}
irFactory = createIRFactory(ts, scope);
irFactory = createIRFactory(ts);
// to save against upchecks if no finally blocks are used.
boolean hasFinally = false;
@@ -109,8 +88,7 @@ public class NodeTransformer {
node.getProp(Node.FUNCTION_PROP);
addParameters(fnNode);
NodeTransformer inner = newInstance();
fnNode = (FunctionNode)
inner.transform(fnNode, tree, ts, scope);
fnNode = (FunctionNode) inner.transform(fnNode, tree, ts);
node.putProp(Node.FUNCTION_PROP, fnNode);
Vector fns = (Vector) tree.getProp(Node.FUNCTION_PROP);
if (fns == null) {
@@ -137,7 +115,7 @@ public class NodeTransformer {
String message = Context.getMessage("msg.dup.label",
errArgs);
reportMessage(Context.getContext(), message, node,
tree, true, scope);
tree, true);
break typeswitch;
}
}
@@ -369,7 +347,7 @@ public class NodeTransformer {
("msg.undef.label", errArgs);
}
reportMessage(Context.getContext(), message, node,
tree, true, scope);
tree, true);
node.setType(TokenStream.NOP);
break;
}
@@ -485,7 +463,7 @@ public class NodeTransformer {
break;
String name = node.getString();
if (name.equals("arguments")) {
// Use of "arguments" requires an activation object.
// Use of "arguments" requires a an activation object.
((FunctionNode) tree).setRequiresActivation(true);
}
VariableTable vars = getVariableTable(tree);
@@ -503,32 +481,15 @@ public class NodeTransformer {
protected void addVariables(Node tree, VariableTable vars) {
// OPT: a whole pass to collect variables seems expensive.
// Could special case to go into statements only.
boolean inFunction = tree.getType() == TokenStream.FUNCTION;
PreorderNodeIterator iterator = tree.getPreorderIterator();
Hashtable ht = null;
Node node;
while ((node = iterator.nextNode()) != null) {
int nodeType = node.getType();
if (inFunction && nodeType == TokenStream.FUNCTION &&
node != tree)
{
// In a function with both "var x" and "function x",
// disregard the var statement, independent of order.
String name = node.getString();
if (name == null)
continue;
vars.removeLocal(name);
if (ht == null)
ht = new Hashtable();
ht.put(name, Boolean.TRUE);
}
if (nodeType != TokenStream.VAR)
if (node.getType() != TokenStream.VAR)
continue;
ShallowNodeIterator i = node.getChildIterator();
while (i.hasMoreElements()) {
Node n = i.nextNode();
if (ht == null || ht.get(n.getString()) == null)
vars.addLocal(n.getString());
vars.addLocal(n.getString());
}
}
}
@@ -580,7 +541,7 @@ public class NodeTransformer {
if (left.getType() == TokenStream.NAME) {
VariableTable vars = getVariableTable(tree);
String name = left.getString();
if (inFunction && vars.get(name) != null && !inWithStatement()) {
if (inFunction && vars.get(name) != null) {
// call to a var. Transform to Call(GetVar("a"), b, c)
left.setType(TokenStream.GETVAR);
// fall through to code to add GetParent
@@ -646,17 +607,15 @@ public class NodeTransformer {
*/
private boolean isSpecialCallName(Node tree, Node node) {
Node left = node.getFirstChild();
boolean isSpecial = false;
if (left.getType() == TokenStream.NAME) {
String name = left.getString();
isSpecial = name.equals("eval") || name.equals("With");
} else {
if (left.getType() == TokenStream.GETPROP) {
String name = left.getLastChild().getString();
isSpecial = name.equals("exec");
}
}
if (isSpecial) {
String name = "";
if (left.getType() == TokenStream.NAME)
name = left.getString();
else
if (left.getType() == TokenStream.GETPROP)
name = left.getLastChild().getString();
if (name.equals("eval") || name.equals("Closure") ||
name.equals("With") || name.equals("exec"))
{
// Calls to these functions require activation objects.
if (inFunction)
((FunctionNode) tree).setRequiresActivation(true);
@@ -682,8 +641,7 @@ public class NodeTransformer {
}
protected void reportMessage(Context cx, String msg, Node stmt,
Node tree, boolean isError,
Scriptable scope)
Node tree, boolean isError)
{
Object obj = stmt.getDatum();
int lineno = 0;
@@ -692,14 +650,8 @@ public class NodeTransformer {
Object prop = tree == null
? null
: tree.getProp(Node.SOURCENAME_PROP);
if (isError) {
if (scope != null)
throw NativeGlobal.constructError(
cx, "SyntaxError", msg, scope,
(String) prop, lineno, 0, null);
else
cx.reportError(msg, (String) prop, lineno, null, 0);
}
if (isError)
cx.reportError(msg, (String) prop, lineno, null, 0);
else
cx.reportWarning(msg, (String) prop, lineno, null, 0);
}

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Mike Ang
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -47,6 +29,7 @@ import java.io.IOException;
* in the jsref package.
*
* @see TokenStream
* @see NodeFactory
*
* @author Mike McCabe
* @author Brendan Eich
@@ -71,9 +54,16 @@ class Parser {
private void reportError(TokenStream ts, String messageId)
throws JavaScriptException
{
this.ok = false;
ts.reportSyntaxError(messageId, null);
if (this.ok) {
this.ok = false;
// Only report the error if the TokenStream hasn't had a chance to.
if ((ts.flags & ts.TSF_ERROR) == 0) {
String message = Context.getMessage(messageId, null);
Context.reportError(message, ts.getSourceName(), ts.getLineno(),
ts.getLine(), ts.getOffset());
}
}
/* Throw an exception to unwind the recursive descent parse.
* We use JavaScriptException here even though it is really
* a different use of the exception than it is usually used
@@ -83,7 +73,9 @@ class Parser {
}
/*
* Build a parse tree from the given TokenStream.
* Build a parse tree from the given TokenStream. Creates a tree
* by making calls to the NodeFactory object that was used to
* construct the Parser.
*
* @param ts the TokenStream to parse
*
@@ -105,7 +97,7 @@ class Parser {
* we've collected all the source */
Object tempBlock = nf.createLeaf(TokenStream.BLOCK);
while (true) {
while (this.ok) {
ts.flags |= ts.TSF_REGEXP;
tt = ts.getToken();
ts.flags &= ~ts.TSF_REGEXP;
@@ -116,7 +108,7 @@ class Parser {
if (tt == ts.FUNCTION) {
try {
nf.addChildToBack(tempBlock, function(ts, source, false));
nf.addChildToBack(tempBlock, function(ts, source));
/* function doesn't add its own final EOL,
* because it gets SEMI + EOL from Statement when it's
* a nested function; so we need to explicitly add an
@@ -126,7 +118,6 @@ class Parser {
wellTerminated(ts, ts.FUNCTION);
} catch (JavaScriptException e) {
this.ok = false;
break;
}
} else {
ts.ungetToken(tt);
@@ -134,10 +125,9 @@ class Parser {
}
}
if (!this.ok) {
if (this.ok == false)
// XXX ts.clearPushback() call here?
return null;
}
Object pn = nf.createScript(tempBlock, ts.getSourceName(),
baseLineno, ts.getLineno(),
@@ -154,31 +144,15 @@ class Parser {
private Object parseFunctionBody(TokenStream ts, Source source)
throws IOException
{
Object pn;
int oldflags = ts.flags;
ts.flags &= ~(TokenStream.TSF_RETURN_EXPR
| TokenStream.TSF_RETURN_VOID);
ts.flags |= TokenStream.TSF_FUNCTION;
Object pn = nf.createBlock(ts.getLineno());
try {
int tt;
while((tt = ts.peekToken()) > ts.EOF && tt != ts.RC) {
if (tt == TokenStream.FUNCTION) {
ts.getToken();
nf.addChildToBack(pn, function(ts, source, false));
/* function doesn't add its own final EOL,
* because it gets SEMI + EOL from Statement when it's
* a nested function; so we need to explicitly add an
* EOL here.
*/
source.append((char)ts.EOL);
wellTerminated(ts, ts.FUNCTION);
} else {
nf.addChildToBack(pn, statement(ts, source));
}
}
} catch (JavaScriptException e) {
this.ok = false;
pn = statements(ts, source);
} finally {
// also in finally block:
// flushNewLines, clearPushback.
@@ -189,7 +163,7 @@ class Parser {
return pn;
}
private Object function(TokenStream ts, Source source, boolean isExpr)
private Object function(TokenStream ts, Source source)
throws IOException, JavaScriptException
{
String name = null;
@@ -248,8 +222,7 @@ class Parser {
return nf.createFunction(name, args, body,
ts.getSourceName(),
baseLineno, ts.getLineno(),
source.buf.toString(),
isExpr);
source.buf.toString());
}
private Object statements(TokenStream ts, Source source)
@@ -285,6 +258,7 @@ class Parser {
{
int tt = ts.peekTokenSameLine();
if (tt == ts.ERROR) {
reportError(ts, "msg.scanner.caught.error");
return false;
}
@@ -348,7 +322,8 @@ class Parser {
* Whether the "catch (e: e instanceof Exception) { ... }" syntax
* is implemented.
*/
private static final boolean implementsCatchCond = false;
private Object statementHelper(TokenStream ts, Source source)
throws IOException, JavaScriptException
{
@@ -569,13 +544,9 @@ class Parser {
catchblocks = nf.createLeaf(TokenStream.BLOCK);
boolean sawDefaultCatch = false;
int peek = ts.peekToken();
if (peek == ts.CATCH) {
while (ts.matchToken(ts.CATCH)) {
if (sawDefaultCatch) {
reportError(ts, "msg.catch.unreachable");
}
source.append((char)ts.CATCH);
mustMatchToken(ts, ts.LP, "msg.no.paren.catch");
source.append((char)ts.LP);
@@ -585,11 +556,9 @@ class Parser {
source.addString(ts.NAME, varName);
Object catchCond = null;
if (ts.matchToken(ts.IF)) {
source.append((char)ts.IF);
if (implementsCatchCond && ts.matchToken(ts.COLON)) {
source.append((char)ts.COLON);
catchCond = expr(ts, source, false);
} else {
sawDefaultCatch = true;
}
mustMatchToken(ts, ts.RP, "msg.bad.catchcond");
@@ -602,8 +571,7 @@ class Parser {
nf.createCatch(varName, catchCond,
statements(ts, source),
ts.getLineno()));
mustMatchToken(ts, ts.RC, "msg.no.brace.after.body");
ts.matchToken(ts.RC);
source.append((char)ts.RC);
source.append((char)ts.EOL);
}
@@ -703,7 +671,8 @@ class Parser {
tt = ts.peekTokenSameLine();
ts.flags &= ~ts.TSF_REGEXP;
if (tt != ts.EOF && tt != ts.EOL && tt != ts.SEMI && tt != ts.RC) {
if (tt != ts.EOF && tt != ts.EOL
&& tt != ts.SEMI && tt != ts.RC) {
lineno = ts.getLineno();
retExpr = expr(ts, source, false);
if (ts.getLineno() == lineno)
@@ -713,6 +682,10 @@ class Parser {
ts.flags |= ts.TSF_RETURN_VOID;
}
if ((ts.flags & (ts.TSF_RETURN_EXPR | ts.TSF_RETURN_VOID))
== (ts.TSF_RETURN_EXPR | ts.TSF_RETURN_VOID))
reportError(ts, "msg.fn.retval");
// XXX ASSERT pn
pn = nf.createReturn(retExpr, lineno);
break;
@@ -725,6 +698,7 @@ class Parser {
break;
case ts.ERROR:
reportError(ts, "msg.scanner.caught.error");
// Fall thru, to have a node for error recovery to work on
case ts.EOL:
case ts.SEMI:
@@ -763,11 +737,8 @@ class Parser {
return pn;
}
if (lastExprType == ts.FUNCTION)
nf.setFunctionExpressionStatement(pn);
pn = nf.createExprStatement(pn, lineno);
/*
* Check explicitly against (multi-line) function
* statement.
@@ -1055,6 +1026,7 @@ class Parser {
return nf.createUnary(ts.DELPROP, unaryExpr(ts, source));
case ts.ERROR:
reportError(ts, "msg.scanner.caught.error");
break;
default:
@@ -1188,6 +1160,8 @@ class Parser {
break;
}
}
if (tt == ts.ERROR)
reportError(ts, "msg.scanner.caught.error");
return pn;
}
@@ -1206,7 +1180,7 @@ class Parser {
switch(tt) {
case ts.FUNCTION:
return function(ts, source, true);
return function(ts, source);
case ts.LB:
{
@@ -1349,6 +1323,7 @@ class Parser {
case ts.ERROR:
/* the scanner or one of its subroutines reported the error. */
reportError(ts, "msg.scanner.caught.error");
break;
default:

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class

View File

@@ -1,38 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;
@@ -50,8 +31,7 @@ public interface RegExpProxy {
public boolean isRegExp(Object obj);
public Object newRegExp(Context cx, Scriptable scope, String source,
String global, boolean flat);
public Object newRegExp(Context cx, Scriptable scope, String source, String global);
public Object match(Context cx, Scriptable thisObj, Object[] args,
Function funObj)

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class

File diff suppressed because it is too large Load Diff

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class
@@ -45,12 +28,12 @@ package org.mozilla.javascript;
* Host system implementors may find it easier to extend the ScriptableObject
* class rather than implementing Scriptable when writing host objects.
* <p>
* There are many static methods defined in ScriptableObject that perform
* the multiple calls to the Scriptable interface needed in order to
* manipulate properties in prototype chains.
* There are many convenience methods defined in FlattenedObject that make
* accessing objects easier.
* <p>
*
* @see org.mozilla.javascript.ScriptableObject
* @see org.mozilla.javascript.FlattenedObject
* @author Norris Boyd
* @author Nick Thompson
* @author Brendan Eich
@@ -137,7 +120,7 @@ public interface Scriptable {
* @param start the object in which the lookup began
* @return true if and only if the named property is found in the object
* @see org.mozilla.javascript.Scriptable#get
* @see org.mozilla.javascript.ScriptableObject#getProperty
* @see org.mozilla.javascript.FlattenedObject#hasProperty
*/
public boolean has(String name, Scriptable start);
@@ -153,7 +136,7 @@ public interface Scriptable {
* @param start the object in which the lookup began
* @return true if and only if the indexed property is found in the object
* @see org.mozilla.javascript.Scriptable#get
* @see org.mozilla.javascript.ScriptableObject#getProperty
* @see org.mozilla.javascript.FlattenedObject#hasProperty
*/
public boolean has(int index, Scriptable start);
@@ -167,8 +150,8 @@ public interface Scriptable {
* <code>get</code>. A class that implements this method may choose
* to ignore calls to set certain properties, in which case those
* properties are effectively read-only.<p>
* For properties defined in a prototype chain,
* use <code>putProperty</code> in ScriptableObject. <p>
* For a more convenient (and less efficient) form of this method,
* see <code>putProperty</code> in FlattenedObject. <p>
* Note that if a property <i>a</i> is defined in the prototype <i>p</i>
* of an object <i>o</i>, then evaluating <code>o.a = 23</code> will cause
* <code>set</code> to be called on the prototype <i>p</i> with
@@ -178,16 +161,6 @@ public interface Scriptable {
* This design allows properties to be defined in prototypes and implemented
* in terms of getters and setters of Java values without consuming slots
* in each instance.<p>
* <p>
* The values that may be set are limited to the following:
* <UL>
* <LI>java.lang.Boolean objects</LI>
* <LI>java.lang.String objects</LI>
* <LI>java.lang.Number objects</LI>
* <LI>org.mozilla.javascript.Scriptable objects</LI>
* <LI>null</LI>
* <LI>The value returned by Context.getUndefinedValue()</LI>
* </UL><p>
* Note that <code>has</code> will be called by the runtime first before
* <code>set</code> is called to determine in which object the
* property is defined.
@@ -198,7 +171,7 @@ public interface Scriptable {
* @param value value to set the property to
* @see org.mozilla.javascript.Scriptable#has
* @see org.mozilla.javascript.Scriptable#get
* @see org.mozilla.javascript.ScriptableObject#putProperty
* @see org.mozilla.javascript.FlattenedObject#putProperty
*/
public void put(String name, Scriptable start, Object value);
@@ -217,7 +190,7 @@ public interface Scriptable {
* @see org.mozilla.javascript.Scriptable#has
* @see org.mozilla.javascript.Scriptable#get
* @see org.mozilla.javascript.Scriptable#put(String,Scriptable,Object)
* @see org.mozilla.javascript.ScriptaleObject#putProperty
* @see org.mozilla.javascript.FlattenedObject#putProperty
*/
public void put(int index, Scriptable start, Object value);
@@ -235,11 +208,11 @@ public interface Scriptable {
* The property is specified by a String name
* as defined for <code>get</code>.
* <p>
* To delete properties defined in a prototype chain,
* see deleteProperty in ScriptableObject.
* For a more convenient form of this method,
* see deleteProperty in FlattenedObject.
* @param name the identifier for the property
* @see org.mozilla.javascript.Scriptable#get
* @see org.mozilla.javascript.ScriptableObject#deleteProperty
* @see org.mozilla.javascript.FlattenedObject#deleteProperty
*/
public void delete(String name);
@@ -249,15 +222,15 @@ public interface Scriptable {
* The property is specified by an integral index
* as defined for <code>get</code>.
* <p>
* To delete properties defined in a prototype chain,
* see deleteProperty in ScriptableObject.
* For a more convenient form of this method,
* see deleteProperty in FlattenedObject.
*
* Identical to <code>delete(String)</code> except that
* an integral index is used to select the property.
*
* @param index the numeric index for the property
* @see org.mozilla.javascript.Scriptable#get
* @see org.mozilla.javascript.ScriptableObject#deleteProperty
* @see org.mozilla.javascript.FlattenedObject#deleteProperty
*/
public void delete(int index);

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class
@@ -246,21 +228,11 @@ public abstract class ScriptableObject implements Scriptable {
break;
}
}
Object v = getterSlot.setter.invoke(start, arg);
if (getterSlot.setterReturnsValue) {
slots[slotIndex].value = v;
if (!(v instanceof Method))
slots[slotIndex].flags = 0;
}
getterSlot.setter.invoke(start, arg);
return;
}
Object[] args = { this, actualArg };
Object v = getterSlot.setter.invoke(getterSlot.delegateTo, args);
if (getterSlot.setterReturnsValue) {
slots[slotIndex].value = v;
if (!(v instanceof Method))
slots[slotIndex].flags = 0;
}
getterSlot.setter.invoke(getterSlot.delegateTo, args);
return;
}
catch (InvocationTargetException e) {
@@ -524,17 +496,17 @@ public abstract class ScriptableObject implements Scriptable {
*/
public Object getDefaultValue(Class typeHint) {
Object val;
FlattenedObject f = new FlattenedObject(this);
Context cx = null;
try {
for (int i=0; i < 2; i++) {
if (typeHint == ScriptRuntime.StringClass ? i == 0 : i == 1) {
Object v = getProperty(this, "toString");
if (!(v instanceof Function))
Function fun = getFunctionProperty(f, "toString");
if (fun == null)
continue;
Function fun = (Function) v;
if (cx == null)
cx = Context.getContext();
val = fun.call(cx, fun.getParentScope(), this,
val = fun.call(cx, fun.getParentScope(), f.getObject(),
ScriptRuntime.emptyArgs);
} else {
String hint;
@@ -563,17 +535,16 @@ public abstract class ScriptableObject implements Scriptable {
hint = "number";
else {
Object[] args = { typeHint.toString() };
throw Context.reportRuntimeError(
Context.getMessage("msg.invalid.type", args));
throw Context.reportRuntimeError(Context.getMessage
("msg.invalid.type", args));
}
Object v = getProperty(this, "valueOf");
if (!(v instanceof Function))
Function fun = getFunctionProperty(f, "valueOf");
if (fun == null)
continue;
Function fun = (Function) v;
Object[] args = { hint };
if (cx == null)
cx = Context.getContext();
val = fun.call(cx, fun.getParentScope(), this, args);
val = fun.call(cx, fun.getParentScope(), f.getObject(), args);
}
if (val != null && (val == Undefined.instance ||
!(val instanceof Scriptable) ||
@@ -582,13 +553,6 @@ public abstract class ScriptableObject implements Scriptable {
{
return val;
}
if (val instanceof NativeJavaObject) {
// Let a wrapped java.lang.String pass for a primitive
// string.
Object u = ((Wrapper) val).unwrap();
if (u instanceof String)
return u;
}
}
// fall through to error
}
@@ -597,10 +561,8 @@ public abstract class ScriptableObject implements Scriptable {
}
Object arg = typeHint == null ? "undefined" : typeHint.toString();
Object[] args = { arg };
throw NativeGlobal.constructError(
Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.default.value", args),
this);
throw Context.reportRuntimeError(Context.getMessage
("msg.default.value", args));
}
/**
@@ -754,7 +716,7 @@ public abstract class ScriptableObject implements Scriptable {
InvocationTargetException, ClassDefinitionException,
PropertyException
{
Method[] methods = FunctionObject.getMethodList(clazz);
Method[] methods = clazz.getMethods();
for (int i=0; i < methods.length; i++) {
if (!methods[i].getName().equals("init"))
continue;
@@ -907,6 +869,7 @@ public abstract class ScriptableObject implements Scriptable {
"jsStaticFunction must be used with static method.");
}
} else if (name.startsWith(propertyPrefix)) {
name = name.substring(propertyPrefix.length());
prefix = propertyPrefix;
} else if (name.startsWith(getterPrefix)) {
prefix = getterPrefix;
@@ -1193,7 +1156,6 @@ public abstract class ScriptableObject implements Scriptable {
slot.delegateTo = delegateTo;
slot.getter = getter;
slot.setter = setter;
slot.setterReturnsValue = setter != null && setter.getReturnType() != Void.TYPE;
slot.value = null;
slot.attributes = (short) attributes;
slot.flags = flags;
@@ -1326,146 +1288,7 @@ public abstract class ScriptableObject implements Scriptable {
public boolean isSealed() {
return count == -1;
}
/**
* Gets a named property from an object or any object in its prototype chain.
* <p>
* Searches the prototype chain for a property named <code>name</code>.
* <p>
* @param obj a JavaScript object
* @param name a property name
* @return the value of a property with name <code>name</code> found in
* <code>obj</code> or any object in its prototype chain, or
* <code>Scriptable.NOT_FOUND</code> if not found
*/
public static Object getProperty(Scriptable obj, String name) {
Scriptable start = obj;
Object result;
do {
result = obj.get(name, start);
if (result != Scriptable.NOT_FOUND)
break;
obj = obj.getPrototype();
} while (obj != null);
return result;
}
/**
* Gets an indexed property from an object or any object in its prototype chain.
* <p>
* Searches the prototype chain for a property with integral index
* <code>index</code>. Note that if you wish to look for properties with numerical
* but non-integral indicies, you should use getProperty(Scriptable,String) with
* the string value of the index.
* <p>
* @param obj a JavaScript object
* @param index an integral index
* @return the value of a property with index <code>index</code> found in
* <code>obj</code> or any object in its prototype chain, or
* <code>Scriptable.NOT_FOUND</code> if not found
*/
public static Object getProperty(Scriptable obj, int index) {
Scriptable start = obj;
Object result;
do {
result = obj.get(index, start);
if (result != Scriptable.NOT_FOUND)
break;
obj = obj.getPrototype();
} while (obj != null);
return result;
}
/**
* Puts a named property in an object or in an object in its prototype chain.
* <p>
* Seaches for the named property in the prototype chain. If it is found,
* the value of the property is changed. If it is not found, a new
* property is added in <code>obj</code>.
* @param obj a JavaScript object
* @param name a property name
* @param value any JavaScript value accepted by Scriptable.put
*/
public static void putProperty(Scriptable obj, String name, Object value) {
Scriptable base = getBase(obj, name);
if (base == null)
base = obj;
base.put(name, obj, value);
}
/**
* Puts an indexed property in an object or in an object in its prototype chain.
* <p>
* Seaches for the indexed property in the prototype chain. If it is found,
* the value of the property is changed. If it is not found, a new
* property is added in <code>obj</code>.
* @param obj a JavaScript object
* @param index a property index
* @param value any JavaScript value accepted by Scriptable.put
*/
public static void putProperty(Scriptable obj, int index, Object value) {
Scriptable base = getBase(obj, index);
if (base == null)
base = obj;
base.put(index, obj, value);
}
/**
* Removes the property from an object or its prototype chain.
* <p>
* Searches for a property with <code>name</code> in obj or
* its prototype chain. If it is found, the object's delete
* method is called.
* @param obj a JavaScript object
* @param name a property name
* @return true if the property doesn't exist or was successfully removed
*/
public static boolean deleteProperty(Scriptable obj, String name) {
Scriptable base = getBase(obj, name);
if (base == null)
return true;
base.delete(name);
return base.get(name, obj) == NOT_FOUND;
}
/**
* Removes the property from an object or its prototype chain.
* <p>
* Searches for a property with <code>index</code> in obj or
* its prototype chain. If it is found, the object's delete
* method is called.
* @param obj a JavaScript object
* @param index a property index
* @return true if the property doesn't exist or was successfully removed
*/
public static boolean deleteProperty(Scriptable obj, int index) {
Scriptable base = getBase(obj, index);
if (base == null)
return true;
base.delete(index);
return base.get(index, obj) == NOT_FOUND;
}
private static Scriptable getBase(Scriptable obj, String s) {
Scriptable m = obj;
while (m != null) {
if (m.has(s, obj))
return m;
m = m.getPrototype();
}
return null;
}
private static Scriptable getBase(Scriptable obj, int index) {
Scriptable m = obj;
while (m != null) {
if (m.has(index, obj))
return m;
m = m.getPrototype();
}
return null;
}
/**
* Adds a property attribute to all properties.
*/
@@ -1615,6 +1438,16 @@ public abstract class ScriptableObject implements Scriptable {
slots = newSlots;
}
private Function getFunctionProperty(FlattenedObject f, String name) {
Object val = f.getProperty(name);
if (val == null || !(val instanceof FlattenedObject))
return null;
Scriptable s = ((FlattenedObject) val).getObject();
if (s instanceof Function)
return (Function) s;
return null;
}
private static Hashtable getExclusionList() {
if (exclusionList != null)
return exclusionList;
@@ -1691,7 +1524,6 @@ class GetterSlot extends Slot {
Object delegateTo; // OPT: merge with "value"
Method getter;
Method setter;
boolean setterReturnsValue;
}

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// API class

View File

@@ -1,37 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
package org.mozilla.javascript;

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* John Bandhauer
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// DEBUG API class

View File

@@ -1,36 +1,19 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
* 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 License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
* 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 Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* John Bandhauer
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
* Copyright (C) 1997-1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// DEBUG API class

Some files were not shown because too many files have changed in this diff Show More