Compare commits

..

2 Commits

Author SHA1 Message Date
igor%mir2.org
96154ba631 cosmetics: end-of-line whitespace removal again
git-svn-id: svn://10.0.0.236/branches/less_static@115249 18797224-902f-48f8-a5cc-f745e15eee43
2002-02-22 23:28:28 +00:00
(no author)
771cbc6bfd This commit was manufactured by cvs2svn to create branch 'less_static'.
git-svn-id: svn://10.0.0.236/branches/less_static@113702 18797224-902f-48f8-a5cc-f745e15eee43
2002-02-05 13:47:17 +00:00
267 changed files with 49390 additions and 64673 deletions

222
mozilla/js/rhino/Makefile Normal file
View File

@@ -0,0 +1,222 @@
#! 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/
#
# 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.
#
# Makefile for javascript in java.
#
# This makefile is intended for packaging releases, and probably isn't
# suitable for production use - it doesn't attempt to do understand
# java dependencies beyond the package level.
#
# The makefiles for the subdirectories included in this package are
# intended to be called by this makefile with the proper CLASSDIR,
# PATH_PREFIX etc. variables. Makefiles in subdirectories are
# actually executed in the toplevel directory, with the PATH_PREFIX
# variable set to the subdirectory where the makefile is located.
#
# Initial version courtesy Mike Ang.
# Next version by Mike McCabe
# Don't include SHELL define (per GNU manual recommendation) because it
# breaks WinNT (with GNU make) builds.
# SHELL = /bin/sh
# Some things we might want to tweek.
CLASSDIR = classes
PACKAGE_NAME = org.mozilla.javascript
PACKAGE_PATH = org/mozilla/javascript
# jar filenames and the directories that build them.
JS_JAR = js.jar
JS_DIR = $(PACKAGE_PATH)
JSTOOLS_JAR = jstools.jar
JSTOOLS_DIR = $(PACKAGE_PATH)/tools
JARS = $(JS_JAR) $(JSTOOLS_JAR)
# It's not polite to store toplevel files in a tarball or zip files.
# What is the name of the toplevel directory to store files in?
# XXX we should probably add versioning to this.
DIST_DIR = jsjava
# XXX test this with sj
# JAVAC = mgcj
JAVAC=javac
# We don't define JFLAGS but we do export it to child
# builds in case it's defined by the environment.
# To build optimized (with javac) say 'make JFLAGS=-O'
GZIP = gzip
ZIP = zip
UNZIP = unzip
# JFLAGS="-O -g:none"
# Shouldn't need to change anything below here.
# For Windows NT builds (under GNU make).
ifeq ($(OS_TARGET), WINNT)
CLASSPATHSEP = '\\;'
else
CLASSPATHSEP = :
endif
# Make compatibility - use these instead of gmake 'export VARIABLE'
EXPORTS = CLASSDIR=$(CLASSDIR) JAVAC=$(JAVAC) JFLAGS=$(JFLAGS) SHELL=$(SHELL) \
PACKAGE_PATH=$(PACKAGE_PATH) PACKAGE_NAME=$(PACKAGE_NAME)
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
@echo 'Define OS_TARGET to "WINNT" to build on Windows NT with GNU make.'
@echo
@echo 'The make-based build system does not include graphical'
@echo 'debugger or Bean Scripting Framework support. To build with'
@echo 'these, use the Ant build tool.'
@echo
@echo 'Ant is available at http://jakarta.apache.org/ant/'
all : jars examples
jars : $(JARS)
fast : fast_$(JS_JAR) $(JSTOOLS_JAR)
# Always call the sub-Makefile - which may decide that the jar is up to date.
$(JS_JAR) : FORCE
$(MAKE) -f $(JS_DIR)/Makefile JAR=$(@) $(EXPORTS) \
PATH_PREFIX=$(JS_DIR) \
CLASSPATH=.
fast_$(JS_JAR) :
$(MAKE) -f $(JS_DIR)/Makefile JAR=$(JS_JAR) $(EXPORTS) \
PATH_PREFIX=$(JS_DIR) \
CLASSPATH=. \
fast
$(JSTOOLS_JAR) : $(JS_JAR) FORCE
$(MAKE) -f $(JSTOOLS_DIR)/Makefile JAR=$(@) $(EXPORTS) \
PATH_PREFIX=$(JSTOOLS_DIR) \
CLASSPATH=./$(JS_JAR)$(CLASSPATHSEP).
examples : $(JS_JAR) FORCE
$(MAKE) -f examples/Makefile $(EXPORTS) \
PATH_PREFIX=examples \
CLASSPATH=./$(JS_JAR)
# We ask the subdirs to update their MANIFESTs
MANIFEST : FORCE
$(MAKE) -f $(JS_DIR)/Makefile JAR=$(JS_JAR) $(EXPORTS) \
PATH_PREFIX=$(JS_DIR) $(JS_DIR)/MANIFEST
$(MAKE) -f $(JSTOOLS_DIR)/Makefile JAR=$(JSTOOLS_JAR) $(EXPORTS) \
PATH_PREFIX=$(JSTOOLS_DIR) $(JSTOOLS_DIR)/MANIFEST
$(MAKE) -f examples/Makefile $(EXPORTS) \
PATH_PREFIX=examples examples/MANIFEST
# so ls below always has something to work on
touch MANIFEST
# examples/Makefile doesn't get included in the
# MANIFEST file, (which is used to create the non-source distribution) so
# we include it here.
cat examples/MANIFEST $(JS_DIR)/MANIFEST \
$(JSTOOLS_DIR)/MANIFEST \
| xargs ls MANIFEST README.html \
$(JARS) \
Makefile examples/Makefile \
> $(@)
# Make a MANIFEST file containing only the binaries and documentation.
# This could be abstracted further...
MANIFEST_binonly : MANIFEST
cat examples/MANIFEST \
| xargs ls $(JARS) README.html MANIFEST > MANIFEST
# A subroutine - not intended to be called from outside the makefile.
do_zip :
# Make sure we get a fresh one
- rm -r $(DIST_DIR)
- mkdir $(DIST_DIR)
- rm $(DIST_DIR).zip
cat MANIFEST | xargs $(ZIP) -0 -q $(DIST_DIR).zip
mv $(DIST_DIR).zip $(DIST_DIR)
cd $(DIST_DIR) ; \
$(UNZIP) -q $(DIST_DIR).zip ; \
rm $(DIST_DIR).zip
$(ZIP) -r -9 -q $(DIST_DIR).zip $(DIST_DIR)
- rm -r $(DIST_DIR)
zip : check jars examples MANIFEST_binonly do_zip
zip-source : check jars examples MANIFEST do_zip
# A subroutine - not intended to be called from outside the makefile.
do_tar :
- rm -r $(DIST_DIR)
- mkdir $(DIST_DIR)
- rm $(DIST_DIR).tar $(DIST_DIR).tar.gz
cat MANIFEST | xargs tar cf $(DIST_DIR).tar
mv $(DIST_DIR).tar $(DIST_DIR)
cd $(DIST_DIR) ; \
tar xf $(DIST_DIR).tar ; \
rm $(DIST_DIR).tar
tar cf $(DIST_DIR).tar $(DIST_DIR)
- rm -r $(DIST_DIR)
$(GZIP) -9 $(DIST_DIR).tar
tar: check jars examples MANIFEST_binonly do_tar
tar-source : check jars examples MANIFEST do_tar
# These commands just get passed to the respective sub-Makefiles.
clean clobber check:
$(MAKE) -f $(JS_DIR)/Makefile $(EXPORTS) JAR=$(JS_JAR) \
PATH_PREFIX=$(JS_DIR) $(@)
$(MAKE) -f $(JSTOOLS_DIR)/Makefile $(EXPORTS) JAR=$(JSTOOLS_JAR) \
PATH_PREFIX=$(JSTOOLS_DIR) $(@)
$(MAKE) -f examples/Makefile $(EXPORTS) PATH_PREFIX=examples $(@)
#emulate .PHONY
FORCE :

View File

@@ -1,39 +1,37 @@
<html>
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 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 the Initial Developer are Copyright (C) 1998-1999
- the Initial Developer. All Rights Reserved.
-
-
- 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 General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
- 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>
@@ -42,7 +40,7 @@ Rhino: JavaScript in Java<p>
</h1>
<span CLASS=LXRLONGDESC>
Rhino is an implementation of JavaScript in Java. Documentation can be found
<a href="http://www.mozilla.org/rhino/index.html">here</a>.
<a href="http://www.mozilla.org/js/rhino/rhino.html">here</a>.
</span>
</body>
</html>

View File

@@ -1,65 +1,22 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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 the Initial Developer are Copyright (C) 1997-1999
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# the GNU General Public License Version 2 or later (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
# MPL, indicate your decision by deleting the provisions above and replacing
# 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 MPL or the GPL.
#
# ***** END LICENSE BLOCK *****
apiClasses=\
src/org/mozilla/javascript/Callable.java,\
src/org/mozilla/javascript/ClassCache.java,\
src/org/mozilla/javascript/ClassShutter.java,\
src/org/mozilla/javascript/CompilerEnvirons.java,\
src/org/mozilla/javascript/ClassDefinitionException.java,\
src/org/mozilla/javascript/ClassOutput.java,\
src/org/mozilla/javascript/Context.java,\
src/org/mozilla/javascript/ContextAction.java,\
src/org/mozilla/javascript/ContextFactory.java,\
src/org/mozilla/javascript/GeneratedClassLoader.java,\
src/org/mozilla/javascript/ContextListener.java,\
src/org/mozilla/javascript/EcmaError.java,\
src/org/mozilla/javascript/ErrorReporter.java,\
src/org/mozilla/javascript/EvaluatorException.java,\
src/org/mozilla/javascript/Function.java,\
src/org/mozilla/javascript/FunctionObject.java,\
src/org/mozilla/javascript/GeneratedClassLoader.java,\
src/org/mozilla/javascript/ImporterTopLevel.java,\
src/org/mozilla/javascript/JavaScriptException.java,\
src/org/mozilla/javascript/RefCallable.java,\
src/org/mozilla/javascript/RhinoException.java,\
src/org/mozilla/javascript/NotAFunctionException.java,\
src/org/mozilla/javascript/PropertyException.java,\
src/org/mozilla/javascript/Script.java,\
src/org/mozilla/javascript/Scriptable.java,\
src/org/mozilla/javascript/ScriptableObject.java,\
src/org/mozilla/javascript/SecurityController.java,\
src/org/mozilla/javascript/WrapFactory.java,\
src/org/mozilla/javascript/WrappedException.java,\
src/org/mozilla/javascript/SecuritySupport.java,\
src/org/mozilla/javascript/WrapHandler.java,\
src/org/mozilla/javascript/Wrapper.java,\
src/org/mozilla/javascript/Synchronizer.java,\
src/org/mozilla/javascript/optimizer/ClassCompiler.java,\
src/org/mozilla/javascript/debug/DebuggableScript.java,\
src/org/mozilla/javascript/serialize/ScriptableInputStream.java,\
src/org/mozilla/javascript/serialize/ScriptableOutputStream.java

View File

@@ -1,64 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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 the Initial Developer are Copyright (C) 1997-1999
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Igor Bukanov
#
# Alternatively, the contents of this file may be used under the terms of
# the GNU General Public License Version 2 or later (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
# MPL, indicate your decision by deleting the provisions above and replacing
# 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 MPL or the GPL.
#
# ***** END LICENSE BLOCK *****
name: rhino
Name: Rhino
version: 1_6R5
# See Context#getImplementationVersion() for format of this!
implementation.version: Rhino 1.6 release 5 ${implementation.date}
build.dir: build
rhino.jar: js.jar
small-rhino.jar: smalljs.jar
dist.name: rhino${version}
dist.dir: ${build.dir}/${dist.name}
# compilation destionation
classes: ${build.dir}/classes
# compilation settings
debug: on
target-jvm: 1.1
source-level: 1.3
# jar generation settings
jar-compression: true
# optional external packages
xmlbeans: .
xbean.jar: ${xmlbeans}/lib/xbean.jar
jsr173.jar: ${xmlbeans}/lib/jsr173_1.0_api.jar

View File

@@ -1,243 +1,131 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0
The contents of this file are subject to the Mozilla 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/MPL/
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 the Initial Developer are Copyright (C) 1997-1999
the Initial Developer. All Rights Reserved.
Contributor(s):
Norris Boyd
Igor Bukanov
David P. Caldwell
Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 2 or later (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
MPL, indicate your decision by deleting the provisions above and replacing
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 MPL or the GPL.
***** END LICENSE BLOCK ***** -->
<!--
<!--
Build file for Rhino using Ant (see http://jakarta.apache.org/ant/index.html)
Requires Ant version 1.2 or later
-->
<project name="Rhino" default="help" basedir=".">
<project name="Rhino" default="default" basedir=".">
<target name="properties">
<!-- Allow user to override default settings from build.properties -->
<property file="build.local.properties" />
<tstamp>
<!-- Specify date part of Context#getImplementationVersion() -->
<format property="implementation.date" pattern="yyyy MM dd"/>
</tstamp>
<property file="build.properties"/>
<property name="name" value="rhino"/>
<property name="Name" value="Rhino"/>
<property name="version" value="1_5R4pre"/>
<property name="rhino.jar" value="js.jar"/>
<property name="debug" value="off"/>
<property name="src.dir" value="src"/>
<property name="toolsrc.dir" value="toolsrc"/>
<property name="src.examples" value="examples"/>
<property name="build.dir" value="./build"/>
<property name="build.dest" value="${build.dir}/classes"/>
<property name="dist.name" value="rhino${version}"/>
<property name="dist.dir" value="${build.dir}/${dist.name}"/>
<property name="dist.src" value="${dist.dir}/src"/>
<property name="dist.toolsrc" value="${dist.dir}/toolsrc"/>
<property name="dist.examples" value="${dist.dir}/examples"/>
<property name="dist.docs" value="${dist.dir}/docs"/>
<property name="dist.apidocs" value="${dist.docs}/apidocs"/>
<property name="dist.file" value="rhino${version}.zip"/>
<property name="dist.source-only-zip" value="rhino${version}-sources.zip"/>
<property file="apiClasses.properties"/>
<property name="xmlimplsrc-build-file"
location="xmlimplsrc/build.xml"/>
<available property="xmlimplsrc-present?"
file="${xmlimplsrc-build-file}" />
<property name="docsrc.dir" value="docs"/>
<property name="dist.docsrc.dir" value="${src.dir}/docs"/>
</target>
<target name="init" depends="properties">
</target>
<target name="prepare" depends="init">
<mkdir dir="${build.dir}"/>
<mkdir dir="${classes}"/>
<mkdir dir="${build.dest}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${dist.src}"/>
<mkdir dir="${dist.toolsrc}"/>
<mkdir dir="${dist.examples}"/>
<mkdir dir="${dist.docs}"/>
<mkdir dir="${dist.apidocs}"/>
</target>
<target name="compile" depends="init">
<ant antfile="src/build.xml" target="compile"/>
<ant antfile="toolsrc/build.xml" target="compile"/>
<antcall target="xmlimplsrc-compile" />
<target name="compile-src" depends="prepare">
<ant dir="${src.dir}"/>
</target>
<target name="compile-all" depends="compile">
<ant antfile="deprecatedsrc/build.xml" target="compile"/>
<target name="compile-toolsrc" depends="prepare">
<ant dir="${toolsrc.dir}"/>
</target>
<target name="copy-source" depends="init">
<ant antfile="src/build.xml" target="copy-source"/>
<ant antfile="toolsrc/build.xml" target="copy-source"/>
<antcall target="xmlimplsrc-copy-source" />
<ant antfile="deprecatedsrc/build.xml" target="copy-source"/>
<copy todir="${dist.dir}" file="build.xml"/>
<copy todir="${dist.dir}" file="build.properties"/>
<copy todir="${dist.dir}" file="apiClasses.properties"/>
<target name="compile" depends="compile-src,compile-toolsrc"/>
<target name="jar" depends="compile">
<jar jarfile="${dist.dir}/${rhino.jar}"
basedir="${build.dest}"
manifest="${src.dir}/manifest" />
</target>
<target name="xmlimplsrc-compile" if="xmlimplsrc-present?">
<echo>Calling ${xmlimplsrc-build-file}</echo>
<!-- Ignore compilation errors under JDK less then 1.4 -->
<property name="xmlimpl.compile.failonerror" value="no"/>
<ant antfile="${xmlimplsrc-build-file}" target="compile"/>
<target name="jar-src" depends="compile-src">
<jar jarfile="${dist.dir}/${rhino.jar}"
basedir="${build.dest}"
manifest="${src.dir}/manifest" />
</target>
<target name="xmlimplsrc-copy-source" if="xmlimplsrc-present?">
<echo>Calling ${xmlimplsrc-build-file}</echo>
<ant antfile="${xmlimplsrc-build-file}" target="copy-source"/>
</target>
<target name="jar" depends="compile-all">
<jar jarfile="${dist.dir}/${rhino.jar}"
basedir="${classes}"
manifest="src/manifest"
compress="${jar-compression}"
/>
</target>
<target name="smalljar" depends="compile">
<jar basedir="${classes}" destfile="${dist.dir}/${small-rhino.jar}"
compress="${jar-compression}">
<include name="org/mozilla/javascript/*.class"/>
<include name="org/mozilla/javascript/debug/*.class"/>
<include name="org/mozilla/javascript/resources/*.properties"/>
<include name="org/mozilla/javascript/xml/*.class"/>
<include name="org/mozilla/javascript/continuations/*.class"/>
<include name="org/mozilla/javascript/jdk13/*.class"/>
<!-- exclude classes that defines only int constants -->
<exclude name="org/mozilla/javascript/Token.class"/>
<!-- exclude classes that uses class generation library -->
<exclude name="org/mozilla/javascript/JavaAdapter*.class"/>
<include name="org/mozilla/javascript/regexp/*.class"
unless="no-regexp"/>
</jar>
</target>
<target name="copy-examples" depends="init">
<mkdir dir="${dist.dir}/examples"/>
<copy todir="${dist.dir}/examples">
<fileset dir="examples" includes="**/*.java,**/*.js,**/*.html" />
<target name="copy-examples" depends="prepare">
<copy todir="${dist.examples}">
<fileset dir="${src.examples}" includes="*.java,*.js,*.html" />
</copy>
</target>
<target name="copy-misc" depends="init">
<target name="copy-misc" depends="prepare">
<tstamp/>
<filter token="datestamp" value="${TODAY}"/>
<copy todir="${dist.dir}" filtering="yes">
<fileset dir=".">
<patternset>
<include name="build.xml"/>
<include name="apiClasses.properties"/>
<include name="build-date"/>
</patternset>
</fileset>
</copy>
</target>
<target name="copy-all" depends="copy-source,copy-examples,copy-misc">
<target name="copy-all" depends="copy-examples,copy-misc">
</target>
<target name="copy-docs" depends="init">
<echo message="copy from docs"/>
<mkdir dir="${dist.dir}/docs"/>
<copy todir="${dist.dir}/docs">
<fileset dir="docs" includes="**/*.html,**/*.jpg,**/*.gif,**/*.js" />
<target name="copy-docs" depends="prepare">
<echo message="copy from ${docsrc.dir}"/>
<copy todir="${dist.docs}">
<fileset dir="${docsrc.dir}"
includes="**/*.html,**/*.jpg,**/*.gif" />
</copy>
</target>
<target name="javadoc" depends="copy-docs">
<mkdir dir="${dist.dir}/docs/apidocs"/>
<target name="javadoc" depends="compile,copy-docs">
<javadoc sourcefiles="${apiClasses}"
sourcepath="src"
destdir="${dist.dir}/docs/apidocs"
overview="${dist.dir}/docs/api.html"
sourcepath="${src.dir}"
destdir="${dist.apidocs}"
overview="${dist.docs}/api.html"
version="true"
author="true"
public="true"
windowtitle="${Name}" />
</target>
<target name="dist" depends="deepclean,jar,copy-all,javadoc">
<target name="dist" depends="copy-all,javadoc,jar">
<delete file="${dist.file}" />
<zip destfile="${dist.file}">
<fileset dir="${build.dir}" includes="${dist.name}/**"/>
</zip>
<zip zipfile="${dist.file}"
basedir="${build.dir}"
includes="**"
excludes="classes/**" />
</target>
<target name="source-zip" depends="copy-source,copy-examples,copy-docs">
<delete file="${dist.source-only-zip}" />
<zip destfile="${dist.source-only-zip}">
<zipfileset prefix="${dist.name}" dir="${dist.dir}">
<include name="*src/**"/>
<include name="build.xml"/>
<include name="*.properties"/>
<include name="examples/**"/>
<include name="docs/**"/>
<exclude name="docs/apidocs/**"/>
</zipfileset>
</zip>
<target name="default">
<echo>
**** Building core only; for full distribution build, try "ant dist".
</echo>
<antcall target="jar-src"/>
</target>
<target name="clean" depends="properties">
<delete quiet="true" file="${dist.dir}/${rhino.jar}"/>
<delete quiet="true" file="${dist.dir}/${small-rhino.jar}"/>
<delete quiet="true" dir="${classes}"/>
</target>
<target name="deepclean" depends="properties">
<delete quiet="true" dir="${build.dir}"/>
<delete quiet="true" file="${dist.file}"/>
<delete quiet="true" file="${dist.source-only-zip}"/>
</target>
<target name="help" depends="properties">
<echo>The following targets are available with this build file:
clean remove all compiled classes and copied property files
compile compile classes and copy all property files
into ${classes} directory
excluding deprecated code
compile-all compile all classes and copy all property files
into ${classes} directory
including deprecated code
deepclean remove all generated files and directories
dist create ${dist.file} with full Rhino distribution
help print this help
jar create ${rhino.jar} in ${dist.dir}
smalljar create ${small-rhino.jar} in ${dist.dir} with
minimalist set of Rhino classes. See footprint.html
from the doc directory for details.
javadoc generate Rhino API documentation
in ${dist.dir}/docs/apidocs
source-zip create ${dist.source-only-zip} with all Rhino
source files necessary to recreate ${dist.file}
</echo>
</target>
</project>

View File

@@ -1,61 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<project name="src" default="compile" basedir="..">
<property file="build.properties"/>
<target name="compile">
<javac srcdir="deprecatedsrc"
destdir="${classes}"
includes="org/**/*.java"
deprecation="on"
debug="${debug}"
target="${target-jvm}"
source="${source-level}"
>
</javac>
</target>
<target name="copy-source">
<mkdir dir="${dist.dir}/deprecatedsrc"/>
<copy todir="${dist.dir}/deprecatedsrc">
<fileset dir="deprecatedsrc"
includes="**/*.java,**/*.properties,**/*.xml,manifest"/>
</copy>
</target>
</project>

View File

@@ -1,53 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
// API class
package org.mozilla.javascript;
/**
* @deprecated The exception is no longer thrown by Rhino runtime as
* {@link EvaluatorException} is used instead.
*/
public class ClassDefinitionException extends RuntimeException
{
static final long serialVersionUID = -5637830967241712746L;
public ClassDefinitionException(String detail) {
super(detail);
}
}

View File

@@ -1,52 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Igor Bukanov
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
// API class
package org.mozilla.javascript;
/**
* @deprecated The exception is no longer thrown by Rhino runtime as
* {@link EvaluatorException} is used instead.
*/
public class NotAFunctionException extends RuntimeException
{
static final long serialVersionUID = 6461524852170711724L;
public NotAFunctionException() { }
}

View File

@@ -1,54 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
// API class
package org.mozilla.javascript;
/**
* @deprecated This exception is no longer thrown by Rhino runtime.
*/
public class PropertyException extends RuntimeException
{
static final long serialVersionUID = -8221564865490676219L;
public PropertyException(String detail) {
super(detail);
}
}

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
@@ -53,7 +19,7 @@
<OL>
<LI><A NAME="_Toc502165109"></FONT><B><FONT FACE="Arial" COLOR="#000080">Console Window</A></LI>
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The debugger redirects the </FONT><FONT FACE="Arial" SIZE=2>System.out</FONT><FONT SIZE=2>, </FONT><FONT FACE="Arial" SIZE=2>System.in</FONT><FONT SIZE=2>, and </FONT><FONT FACE="Arial" SIZE=2>System.err</FONT><FONT SIZE=2> streams to an internal Error console window which provides an editable command line for you to enter JavaScript code and view system output. The console window maintains a history of the commands you have entered. You may move backward and forward through the history list by pressing the Up/Down arrow keys on the keyboard.</P>
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The debugger redirects the </FONT><FONT FACE="Arial" SIZE=2>System.out</FONT><FONT SIZE=2>, </FONT><FONT FACE="Arial" SIZE=2>System.in</FONT><FONT SIZE=2>, and </FONT><FONT FACE="Arial" SIZE=2>System.err</FONT><FONT SIZE=2> streams to an internal JavaScript console window which provides an editable command line for you to enter JavaScript code and view system output. The console window maintains a history of the commands you have entered. You may move backward and forward through the history list by pressing the Up/Down arrow keys on the keyboard.</P>
<LI><A NAME="_Toc502165110"></FONT><B><FONT FACE="Arial" COLOR="#000080">Opening Scripts</A></LI>
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">You may select the <B><I>File-&gt;Open</B></I> menu item on the menu bar to load JavaScript scripts contained in files. This action will display a file-selection dialog box prompting you for the location of a script to load. The selected file will be compiled and displayed in a new window.</P>
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Running Scripts</LI>

View File

@@ -1,528 +0,0 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<title>Scripting Java</title>
</head>
<body>
<h1>Scripting Java</h1>
<p>This paper shows how to use Rhino to reach beyond JavaScript into
Java <a href="#ref1">[1]</a>. Scripting Java has many uses. It allows
us to write powerful scripts quickly by making use of the many Java
libraries available. We can test Java classes by writing scripts. We
can also aid our Java development by using scripting for <em>exploratory
programming</em>. Exploratory programming is the process of
learning about what a library or API can do by writing quick programs
that use it. As we will see, scripting makes this process easier.</p>
<p>Note that the ECMA standard doesn't cover communication with
Java (or with any external object system for that matter). All the
functionality covered in this chapter should thus be considered an
extension.</p>
<h2>Accessing Java packages and classes</h2>
<p>Every piece of Java code is part of a class. Every Java
class is part of a package. In JavaScript, however, scripts exist outside of
any package hierarchy. How then, do we access classes in Java packages?</p>
<p>Rhino defines a top-level variable named <code>Packages</code>. The
properties of the <code>Packages</code>
variable are all the top-level Java packages, such as <code>java</code> and
<code>com</code>. For example,
we can access the value of the <code>java</code>package:</p>
<pre>
js&gt; Packages.java
[JavaPackage java]
</pre>
<p>As a handy shortcut, Rhino defines a top-level variable <code>java</code>
that is equivalent to <code>Packages.java</code>.
So the previous example could be even shorter:</p>
<pre>
js&gt; java
[JavaPackage java]
</pre>
<p>We can access Java classes simply by stepping down the
package hierarchy:</p>
<pre>
js&gt; java.io.File
[JavaClass java.io.File]
</pre>
<p>If your scripts access a lot of different Java classes it
can get awkward to use the full package name of the class every time. Rhino
provides a top-level function <code>importPackage</code> that serves the same
purpose as Java's <code>import</code> declaration. For example, we could
import all of the classes in the <code>java.io</code>package and
access class <code>java.io.File</code>
using just the name <code>File</code>:</p>
<pre>
js&gt; importPackage(java.io)
js&gt; File
[JavaClass java.io.File]
</pre>
<p>Here <code>importPackage(java.io)</code> makes all the classes in
the <code>java.io</code> package (such as <code>File</code>)
available at the top level. It's equivalent in effect to the Java
declaration <code>import java.io.*;</code>.</p>
<p>It's important to note that Java imports <code>java.lang.*</code>
implicitly, while Rhino does not. The reason is that JavaScript has
its own top-level objects <code>Boolean</code>, <code>Math</code>,
<code>Number</code>, <code>Object</code>, and <code>String</code> that
are different from the classes by those names defined in the
<code>java.lang</code> package. Because of this conflict, it's a good
idea not to use <code>importPackage</code> on the
<code>java.lang</code> package.</p>
<p>One thing to be careful of is Rhino's handling of errors in
specifying Java package or class names. If <code>java.MyClass</code>
is accessed, Rhino attempts to load a class named
<code>java.MyClass</code>. If that load fails, it assumes that
<code>java.MyClass</code> is a package name, and no error is
reported:</p>
<pre>
js&gt; java.MyClass
[JavaPackage java.MyClass]
</pre>
<p>Only if you attempt to use this object as a class will an
error be reported.</p>
<h2>Working with Java objects</h2>
<p>Now that we can access Java classes, the next logical step is to
create an object. This works just as in Java, with the use of the
<code>new</code> operator:</p>
<pre>
js&gt; new java.util.Date()
Thu Jan 24 16:18:17 EST 2002
</pre>
<p>If we store the new object in a JavaScript variable, we can then
call methods on it:</p>
<pre>
js&gt; f = new java.io.File("test.txt")
test.txt
js&gt; f.exists()
true
js&gt; f.getName()
test.txt
</pre>
<p>Static methods and fields can be accessed from the class object
itself:</p>
<pre>
js&gt; java.lang.Math.PI
3.141592653589793
js&gt; java.lang.Math.cos(0)
1
</pre>
<p>In JavaScript, unlike Java, the method by itself is an
object and can be evaluated as well as being called. If we just view the method
object by itself we can see the various overloaded forms of the method:</p>
<pre>
js&gt; f.listFiles
function listFiles() {/*
java.io.File[] listFiles()
java.io.File[] listFiles(java.io.FilenameFilter)
java.io.File[] listFiles(java.io.FileFilter)
*/}
</pre>
<p>This output shows that the <code>File</code> class defines three
overloaded methods <code>listFiles</code>: one that takes no
arguments, another with a <code>FilenameFilter</code> argument, and a
third with a <code>FileFilter</code> argument. All the methods return
an array of <code>File</code> objects. Being able to view the
parameters and return type of Java methods is particularly useful in
exploratory programming where we might be investigating a method and
are unsure of the parameter or return types. </p>
<p>Another useful feature for exploratory programming is the ability
to see all the methods and fields defined for an object. Using the
JavaScript <code>for..in</code> construct, we can print out all these
values:</p>
<pre>
js&gt; for (i in f) { print(i) }
exists
parentFile
mkdir
toString
wait
<em>[44 others]</em>
</pre>
<p>Note that not only the methods of the <code>File</code> class are
listed, but also the methods inherited from the base class
<code>java.lang.Object</code> (like <code>wait</code>). This makes it
easier to work with objects in deeply nested inheritance hierarchies
since you can see all the methods that are available for that
object.</p>
<p>Rhino provides another convenience by allowing properties of
JavaBeans to be accessed directly by their property names. A JavaBean
property <code>foo</code> is defined by the methods
<code>getFoo</code> and <code>setFoo</code>. Additionally, a boolean
property of the same name can be defined by an <code>isFoo</code>
method <a href="#ref2">[2]</a>. For example, the following code
actually calls the <code>File</code> object's <code>getName</code> and
<code>isDirectory</code> methods.</p>
<pre>
js&gt; f.name
test.txt
js&gt; f.directory
false
</pre>
<h2>Calling overloaded methods</h2>
<p>The process of choosing a method to call based upon the types of
the arguments is called <em>overload resolution</em>. In Java,
overload resolution is performed at compile time, while in Rhino it
occurs at runtime. This difference is inevitable given JavaScript's
use of dynamic typing as was discussed in Chapter 2: since the type of
a variable is not known until runtime, only then can overload
resolution occur.</p>
<p>As an example, consider the following Java class that defines a
number of overloaded methods and calls them.</p>
<pre>
public class Overload {
public String f(Object o) { return "f(Object)"; }
public String f(String s) { return "f(String)"; }
public String f(int i) { return "f(int)"; }
public String g(String s, int i) { return "g(String,int)"; }
public String g(int i, String s) { return "g(int,String)"; }
public static void main(String[] args) {
Overload o = new Overload();
Object[] a = new Object[] { new Integer(3), "hi", Overload.class };
for (int i = 0; i != a.length; ++i)
System.out.println(o.f(a[i]));
}
}
</pre>
<p>When we compile and execute the program, it produces the output</p>
<pre>
f(Object)
f(Object)
f(Object)
</pre>
<p>However, if we write a similar script</p>
<pre>
var o = new Packages.Overload();
var a = [ 3, "hi", Packages.Overload ];
for (var i = 0; i != a.length; ++i)
print(o.f(a[i]));
</pre>
<p>and execute it, we get the output</p>
<pre>
f(int)
f(String)
f(Object)
</pre>
<p>Because Rhino selects an overloaded method at runtime, it calls the
more specific type that matches the argument. Meanwhile Java selects
the overloaded method purely on the type of the argument at compile
time. </p>
<p>Although this has the benefit of selecting a method that may be a
better match for each call, it does have an impact on performance
since more work is done at each call. In practice this performance
cost hasn't been noticeable in real applications.</p>
<p>Because overload resolution occurs at runtime, it can fail at
runtime. For example, if we call <code>Overload</code>'s method
<code>g</code> with two integers we get an error because neither form
of the method is closer to the argument types than the other:</p>
<pre>
js&gt; o.g(3,4)
js:"&lt;stdin&gt;", line 2: The choice of Java method Overload.g
matching JavaScript argument types (number,number) is ambiguous;
candidate methods are:
class java.lang.String g(java.lang.String,int)
class java.lang.String g(int,java.lang.String)
</pre>
<p>A more precise definition of overloading semantics can be
found at <a
href="http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html">http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html</a>.</p>
<h2>Implementing Java interfaces</h2>
<p>Now that we can access Java classes, create Java objects, and
access fields, methods, and properties of those objects, we have a
great deal of power at our fingertips. However, there are a few
instances where that is not enough: many APIs in Java work by
providing interfaces that clients must implement. One example of this
is the <code>Thread</code> class: its constructor takes a
<code>Runnable</code> that contains a single method <code>run</code>
that will be called when the new thread is started. </p>
<p>To address this need, Rhino provides the ability to create new Java
objects that implement interfaces. First we must define a JavaScript
object with function properties whose names match the methods required
by the Java interface. To implement a <code>Runnable</code>, we need
only define a single method <code>run</code> with no parameters. If
you remember from Chapter 3, it is possible to define a JavaScript
object with the <code>{propertyName: value}</code> notation. We can
use that syntax here in combination with a function expression to
define a JavaScript object with a <code>run</code> method:</p>
<pre>
js&gt; obj = { run: function () { print("\nrunning"); } }
[object Object]
js&gt; obj.run()
running
</pre>
<p>Now we can create an object implementing the <code>Runnable</code> interface
by constructing a <code>Runnable</code>:</p>
<pre>
js&gt; r = new java.lang.Runnable(obj);
[object JavaObject]
</pre>
<p>In Java it is not possible to use the <code>new</code> operator on
an interface because there is no implementation available. Here Rhino
gets the implementation from the JavaScript object
<code>obj</code>. Now that we have an object implementing
<code>Runnable</code>, we can create a <code>Thread</code> and run
it. The function we defined for <code>run </code>will be called on a
new thread.</p>
<pre>
js&gt; t = new java.lang.Thread(r)
Thread[Thread-2,5,main]
js&gt; t.start()
js&gt;
running
</pre>
<p>The final <code>js</code> prompt and the output from the new thread
may appear in either order, depending on thread scheduling.</p>
<p>Behind the scenes, Rhino generates the bytecode for a new Java
class that implements <code>Runnable</code> and forwards all calls to
its <code>run</code> method over to an associated JavaScript
object. The object that implements this class is called a <em>Java
adapter</em>. Because the forwarding to JavaScript occurs at runtime,
it is possible to delay defining the methods implementing an interface
until they are called. While omitting a required method is bad
practice for programming in the large, it's useful for small scripts
and for exploratory programming.</p>
<h2>The <code>JavaAdapter</code> constructor</h2>
<p>In the previous section we created Java adapters using the
<code>new</code> operator with Java interfaces. This approach has its
limitations: it's not possible to implement multiple interfaces, nor
can we extend non-abstract classes. For these reasons there is a
<code>JavaAdapter</code> constructor. </p>
<p>The syntax of the <code>JavaAdapter</code> constructor is</p>
<pre>
new JavaAdapter(javaIntfOrClass, [javaIntf, ..., javaIntf,] javascriptObject)
</pre>
<p>Here <code>javaIntfOrClass</code> is an interface to implement or a
class to extend and <code>javaIntf</code> are aditional interfaces to
implement. The <code>javascriptObject</code> is the JavaScript object
containing the methods that will be called from the Java adapter. </p>
<p>In practice there's little need to call the
<code>JavaAdapter</code> constructor directly. Most of the time the
previous syntaxes using the <code>new</code> operator will be
sufficient.</p>
<h2>JavaScript functions as Java interfaces</h2>
<p>Often we need to implement an interface with only one method, like in the
previous <code>Runnable</code> example or when providing various event
listener implementations. To facilitate this Rhino allows to pass
JavaScript function when such interface is expected. The
function is called as the implementation of interface method.</p>
<p>Here is the simplified <code>Runnable</code> example:</p>
<pre>
js&gt; t = java.lang.Thread(function () { print("\nrunning"); });
Thread[Thread-0,5,main]
js&gt; t.start()
js&gt;
running
</pre>
Rhino also allows to use JavaScript function as implementation of Java
interface with more then method if all the methods has the same
signature. When calling the function, Rhino passes method's name as
the additional argument. Function can
use it to distinguish on behalf of which method it was called:
<pre>
js&gt; var frame = new Packages.javax.swing.JFrame();
js&gt; frame.addWindowListener(function(event, methodName) {
if (methodName == "windowClosing") {
print("Calling System.exit()..."); java.lang.System.exit(0);
}
});
js&gt; frame.setSize(100, 100);
js&gt; frame.visible = true;
true
js&gt; Calling System.exit()...
</pre>
<h2>Creating Java arrays</h2>
<p>Rhino provides no special syntax for creating Java arrays. You
must use the <code>java.lang.reflect.Array</code> class for this
purpose. To create an array of five Java strings you would make the
following call:</p>
<pre>
js&gt; a = java.lang.reflect.Array.newInstance(java.lang.String, 5);
[Ljava.lang.String;@7ffe01
</pre>
<p>To create an array of primitive types, we must use the special TYPE
field defined in the associated object class in the
<code>java.lang</code> package. For example, to create an array of
bytes, we must use the special field
<code>java.lang.Byte.TYPE</code>:</p>
<pre>
js&gt; a = java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 2);
[C@7a84e4
</pre>
<p>The resulting value can then be used anywhere a Java array
of that type is allowed.</p>
<pre>
js&gt; a[0] = 104
104
js&gt; a[1] = 105
105
js&gt; new java.lang.String(a)
hi
</pre>
<h2>Java strings and JavaScript strings</h2>
<p>It's important to keep in mind that Java strings and JavaScript
strings are <strong>not</strong> the same. Java strings are instances
of the type <code>java.lang.String</code> and have all the methods
defined by that class. JavaScript strings have methods defined by
<code>String.prototype</code>. The most common stumbling block is
<code>length</code>, which is a method of Java strings and a dynamic
property of JavaScript strings:</p>
<pre>
js&gt; javaString = new java.lang.String("Java")
Java
js&gt; jsString = "JavaScript"
JavaScript
js&gt; javaString.length()
4
js&gt; jsString.length
10
</pre>
<p>Rhino provides some help in reducing the differences between the
two types. First, you can pass a JavaScript string to a Java method
that requires a Java string and Rhino will perform the conversion. We
actually saw this feature in action on the call to the
<code>java.lang.String</code> constructor in the preceding
example.</p>
<p>Rhino also makes the JavaScript methods available to Java strings
if the java.lang.String class doesn't already define them. For
example:</p>
<pre>
js&gt; javaString.match(/a.*/)
ava
</pre>
<hr align=left size=1 width="33%">
<p><a name="ref1">[1]</a>
The ability to call Java from JavaScript was first implemented as part
of a Netscape browser technology called
<em>LiveConnect</em>. However, since that technology also
encompassed communication with browser plugins, and since the way of
calling JavaScript from Java in Rhino is entirely different, that term
won't be used in this paper.</p>
<p><a name="ref2">[2]</a>
For more information on JavaBeans, see <em>Developing Java Beans</em>
by Robert Englander.</p>
</body>
</html>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -42,9 +8,9 @@
</head>
<body bgcolor="#FFFFFF">
<h1 align="center">
Rhino API Reference.</h1>
<center>
<h1>
Rhino API Reference.</h1></center>
<h4>
The Control API</h4>
@@ -58,8 +24,9 @@ JavaScript evaluation engine with a Java thread, set attributes of the
engine, and compile and evaluate scripts.</li>
<li>
<a href="org/mozilla/javascript/ContextFactory.html">ContextFactory</a>
- Allows embeddings to customize creation of Context instances and monitor entering and releasing of Contexts. </li>
<a href="org/mozilla/javascript/ContextListener.html">ContextListener</a>
- Allows embeddings to be notified of the creation, entering, exiting,
and releasing of Contexts. </li>
<li>
<a href="org/mozilla/javascript/Script.html">Script</a> - The result of
@@ -71,27 +38,24 @@ This interface can be implemented to control the actions the JavaScript
engine takes when it encounters errors.</li>
<li>
<a href="org/mozilla/javascript/SecurityController.html">SecurityController</a>
<a href="org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
- Optional support routines that must be provided by embeddings implementing
security controls on scripts.</li>
<li>
<a href="org/mozilla/javascript/ClassShutter.html">ClassShutter</a>
- Embeddings that wish to filter Java classes that are visible to scripts
through the LiveConnect, should implement this interface.</li>
<li>
<a href="org/mozilla/javascript/Wrapper.html">Wrapper</a> - Interface implemented
by objects wrapping other objects. Provides a method for recovering the
wrapped value.</li>
<li>
<a href="org/mozilla/javascript/WrapFactory.html">WrapFactory</a> - Class
embedders can extend in order to control the way Java objects are wrapped
<a href="org/mozilla/javascript/WrapHandler.html">WrapHandler</a> - Interface
embedders can implement in order to control the way Java objects are wrapped
for use by JavaScript.</li>
<li>
<a href="org/mozilla/javascript/optimizer/ClassCompiler.html">ClassCompiler</a> - Class that provies API for compiling scripts into JVM class files.</li>
<a href="org/mozilla/javascript/ClassOutput.html">ClassOutput</a> - Interface
embedders can implement in order to control the placement of generated
class bytecodes.</li>
<li>
<a href="org/mozilla/javascript/serialize/ScriptableOutputStream.html">ScriptableOutputStream</a> - This stream can be used to serialize JavaScript objects and functions.
@@ -107,7 +71,7 @@ for use by JavaScript.</li>
The Host Object API</h4>
These APIs provide support for adding objects specific to a particular
embedding of JavaScript in a host environment. Note that if you just want
to script existing Java classes, you should just use <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:LiveConnect_Overview">LiveConnect</a>. See also <a href="http://www.mozilla.org/js/liveconnect/">LiveConnect 3.0 specs</a>.
to script existing Java classes, you should just use <a href="http://developer.netscape.com/library/documentation/communicator/jsguide4/livecon.htm">LiveConnect</a>.
It is also helpful to understand some of the implementation of the <a href="runtime.html">runtime</a>.
<ul>
<li>
@@ -134,7 +98,7 @@ to be used as JavaScript function objects.</li>
<li>
<a href="org/mozilla/javascript/ImporterTopLevel.html">ImporterTopLevel</a>
- Allows embeddings to use the JavaImporter constructor.</li>
- Allows embeddings to use the importClass and importPackage functions.</li>
</ul>
<h4>
@@ -142,23 +106,27 @@ Exceptions</h4>
These exceptions are thrown by JavaScript.
<ul>
<li>
<a href="org/mozilla/javascript/RhinoException.html">RhinoException</a>
- Common root for all exception explicitly thrown by Rhino engine.</li>
<a href="org/mozilla/javascript/JavaScriptException.html">JavaScriptException</a>
- Thrown from within JavaScript by the JavaScript 'throw' statement. It wrapps the JavaScript value from 'throw' statement.</li>
- Thrown from within JavaScript by the JavaScript 'throw' statement, or
by LiveConnect calls from JavaScript into Java. Wraps a JavaScript value.</li>
<li>
<a href="org/mozilla/javascript/WrappedException.html">EcmaError</a>
- Thrown by Rhino runtime when particular runtime operation a scripts tries to execute is not allowed. The exception is thrown, for example, when a script attempts to check properties of <tt>undefined</tt>or <tt>null</tt> or refer to a name that can not be found in the current scope chain.</li>
<a href="org/mozilla/javascript/ClassDefinitionException.html">ClassDefinitionException</a>
- Thrown if errors are detected while attempting to define a host object
from a Java class.</li>
<li>
<a href="org/mozilla/javascript/WrappedException.html">WrappedException</a>
- Thrown by LiveConnect implementation from JavaScript when called Java method exits with an exception. It wraps the original Java exception.</li>
<a href="org/mozilla/javascript/PropertyException.html">PropertyException</a>
- Thrown if errors are detected while attempting to define a property of
a host object from a Java class or method, or if a property is not found.</li>
<li>
<a href="org/mozilla/javascript/NotAFunctionException.html">NotAFunctionException</a>
- Thrown when attempting to call an object that is not a function.</li>
<li>
<a href="org/mozilla/javascript/EvaluatorException.html">EvaluatorException</a>
- An exception thrown when an error is detected during the compilation or execution of
- An exception thrown when an error is detected during the execution of
a script. The default error reporter will throw EvaluatorExceptions when
an error is encountered.</li>
</ul>

View File

@@ -1,78 +1,43 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="KeyWords" content="Rhino, JavaScript, Java, BSF, Apache">
<title>Rhino and BSF</title>
<style>
BODY { background-color: white }
H1 { text-align: center }
P { text-align: justify }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]">
<meta name="KeyWords" content="Rhino, JavaScript, Java, BSF, Apache">
<title>Rhino and BSF</title>
</head>
<body>
<body bgcolor="#FFFFFF">
<script src="owner.js"></script>
<h1>Rhino and BSF</h1>
<center>
<h1>
Using Rhino with BSF and Apache</h1></center>
<script>document.write(owner());</script>
<h2>What is BSF?</h2>
<p>
The <a href="http://jakarta.apache.org/bsf/">Bean
<br><script>
var d = new Date(document.lastModified);
document.write((d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear());
document.write('<br>');
</script>
<hr WIDTH="100%">
<br>The <a href="http://oss.software.ibm.com/developerworks/projects/bsf">Bean
Scripting Framework</a> (or BSF) was originally developed by IBM and now
published as open source as a project at the Apache Software Foundation. It provides a framework for using a number of
published as open source. It provides a framework for using a number of
scripting languages with Java. Rhino is one of the supported languages.
</p>
<p>This framework has been embedded in a number of open source projects,
including the XSL processor <a href="http://xml.apache.org/xalan-j/">Xalan</a>
and the XML/Java build tool <a href="http://ant.apache.org/">Ant</a>.
See <a href="http://xml.apache.org/xalan-j/extensions.html">Xalan-Java
Extensions</a> for more information on adding JavaScript to XSL and the description of the optional Script task in the
<a href="http://ant.apache.org/manual/">Apache Ant Manual</a> for using scripting in Ant build files.
</p>
<h2 id="bsf-issue">Using BSF with Rhino</h2>
<p>If you use BSF 2.3.0 Release candidate 1 (released 2002-11-12) or earlier versions, you have to use Rhino 1.5R2 or Rhino 1.5R3 (see Rhino <a href="download.html">download</a> page).
</p>
<p>
If you want to use later releases of Rhino, then as of time of writing, 2004-11-29, you have to either build BSF from <a href="http://jakarta.apache.org/site/cvsindex.html">Apache's CVS</a> or use pre-built binaries since BSF project has not yet released an official version incorporating all the necessary changes to work with Rhino 1.5R4 or later.
</p>
including the XSL processor <a href="http://xml.apache.org/xalan/index.html">Xalan</a>
and the XML/Java build tool <a href="http://jakarta.apache.org/ant/index.html">Ant</a>.
<p>You can download a version of <tt>bsf.jar</tt> from <a href="http://oss.software.ibm.com/developerworks/projects/bsf">http://oss.software.ibm.com/developerworks/projects/bsf</a>
that includes the <tt>com.ibm.bsf.engines.javascript.JavaScriptEngine</tt>
class. The current version is 2.2 release candidate at the time of this
writing. This version thus supports JavaScript through Rhino when used
with the <tt>js.jar</tt> file from either <tt>rhino15R1.zip</tt> or <tt>rhinoTip.zip</tt>.
<p>See <a href="http://xml.apache.org/xalan/extensions.html#ex-basic">Xalan-Java
Extensions</a> for more information on adding JavaScript to XSL and the
<a href="http://jakarta.apache.org/ant/jakarta-ant/docs/#script">Script
task</a> for using scripting in Ant build files.
<p><a href="index.html">back to top</a>
</body>
</html>

View File

@@ -1,75 +1,24 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE doctype PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Cygwin (vers 1st September 2004), see www.w3.org">
<meta http-equiv="Content-Type" content=
"text/html; charset=us-ascii">
<meta name="Author" content="Igor Bukanov">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Change Log</title>
<style type="text/css">
P { text-align: justify; }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Change Log</title>
</head>
<body bgcolor="#FFFFFF">
<h1 align="center">Change Log for Rhino</h1>
<h2>Change logs for previous Rhino releases</h2>
<ul>
<li><a href="rhino16R2.html">Rhino 1.6R2</a>, released
2005-09-19</li>
<li><a href="rhino16R1.html">Rhino 1.6R1</a>, released
2004-11-29</li>
<li><a href="rhino15R5.html">Rhino 1.5R5</a>, released
2004-03-25</li>
<li><a href="rhino15R41.html">Rhino 1.5R4.1</a>, released
2003-04-21</li>
<li><a href="rhino15R4.html">Rhino 1.5R4</a>, released
2003-02-10</li>
<li><a href="rhino15R3.html">Rhino 1.5R3</a>, released
2002-01-27</li>
<li><a href="rhino15R2.html">Rhino 1.5R2</a>, released
2001-07-27</li>
<li><a href="rhino15R1.html">Rhino 1.5R1</a>, released
2000-09-10</li>
</ul>
<hr width="100%">
<br>
<a href="index.html">back to top</a>
<center>
<h1>
Change Log for Significant Rhino Changes</h1></center>
This is a log of significant changes since the release of Rhino 1.5 Release
3.
<p><i>None yet!</i>
<h3>
<hr WIDTH="100%"><br>
<a href="index.html">back to top</a></h3>
</body>
</html>

View File

@@ -0,0 +1,98 @@
<html>
<head>
<title>Debugger API for Rhino</title>
</head>
<body bgcolor="#FFFFFF">
<h1><center>Debugger API for Rhino</center></h1>
<p>
<font color="red"><center>This release of the Debugger API should be considered to be of Beta quality.</center></font>
<p>
The Debugger API for Rhino consists of a set of Java interfaces
which describes a high level debugger API and a default implementation of that
API.
<p>
Most of the API is in the <code>com.netscape.javascript.debug</code> package. It is built
upon low-level support built into the core engine in <code>com.netscape.javascript</code>.
<p>
The <code>com.netscape.javascript.debug</code> package includes an implementation of the Debugger API
interfaces outlined below. The class <code>com.netscape.javascript.debug.DebugManager.java</code>
implements the <a href="com/netscape/javascript/debug/IDebugManager.html">IDebugManager</a>
interface and <code>com.netscape.javascript.debug.SourceTextManagerImpl.java</code> implements
the <a href="com/netscape/javascript/SourceTextManager.html">SourceTextManager</a> interface.
<p>
The class <code>com.netscape.javascript.tools.shell.Main.java</code> provides an
example which invokes the Debugger API.
<p>
<hr>
<p>
The core interface of the API is <a href="com/netscape/javascript/debug/IDebugManager.html">IDebugManager</a>.
This interface provide the central point for interacting with the debug system.
It supports the setting of the following hooks:
<ul>
<li><a href="com/netscape/javascript/debug/IInterruptHook.html">IInterruptHook</a> for immediate interrupt.
<li><a href="com/netscape/javascript/debug/IInstructionHook.html">IInstructionHook</a> for breakpoints.
<li><a href="com/netscape/javascript/debug/IDebugBreakHook.html">IDebugBreakHook</a> for breaking on errors.
<li><a href="com/netscape/javascript/debug/IErrorReporter.html">IErrorReporter</a> for hooking into the error reporter system.
<li><a href="com/netscape/javascript/debug/IScriptHook.html">IScriptHook</a> for notification of script and function load and unload.
</ul>
Customers of the Debugger API can provide implementations of these hook
interfaces which can be passed to the <i>IDebugManager</i> in order receive
notification of the various events within the core JavaScript engine.
<p>
When hooks are called they are passed appropriate objects which are implemented
by the Debugger API to describe such things as <i>stack frames</i>,
<i> program counter locations</i>, etc. The interfaces for these objects are:
<ul>
<li><a href="com/netscape/javascript/debug/IThreadState.html">IThreadState</a> representing the state of the stopped thread.
<li><a href="com/netscape/javascript/debug/IStackFrame.html">IStackFrame</a> representing a stack frame.
<li><a href="com/netscape/javascript/debug/IPC.html">IPC</a> representing a program counter location.
<li><a href="com/netscape/javascript/debug/IScript.html">IScript</a> representing a compiled JavaScript script or function.
<li><a href="com/netscape/javascript/debug/ISourceLocation.html">ISourceLocation</a> representing a location in the souce code.
</ul>
<p>
<hr>
<p>
<a href="com/netscape/javascript/SourceTextManager.html">SourceTextManager</a>
is an interface used to supply a centralized location from which a debugger
client can access JavaScript source. It supports capturing source as it is
parsed by <i>Rhino</i>. Alternately, source can be fed to it by the
embedding; e.g. in a browser embedding where the JavaScript code is just a
part of the html source the browser can feed the entire source to the
<i>SourceTextManager</i> so that a debugger can 'see' the whole source and
not just the part that is fed to the JavaScript compiler.
<p>
<a href="com/netscape/javascript/SourceTextItem.html">SourceTextItem</a> is an
interface representing a single 'block' of source code text (typically this
is an entire source file). This may be pure JavaScript source, or may include
JavaScript source embedded in html or whatever. The point is that this is the
text that a debugger should show to a user while debugging the JavaScript code.
This interface supports incrementally updated content. This is specifically
useful in browser embeddings where text is received in blocks. In fact, in a
browser it is possible that some of the source on a page may be compiled
and run even before the entire content of the page has been received from a
server.
<p>
<hr>
<p>
<a href="com/netscape/javascript/debug/ILaunchableDebugger.html">ILaunchableDebugger</a>
is an interface that abstractly represents a debugger user interface. It is
defined to allow an embedding to request that a debugger be launched without
requiring that the embedding be coupled at compile time to a particular debugger
implementation.
<p>
<hr>
<h3>Limitations and unimplemented features</h3>
<ul>
<li>Data Watchpoints are not implemented.
<li>Catching exceptions thrown in JavaScript code is not implemented.
<li>Per context hooking is not implemented.
<li>Setting the debug level to any non-zero value forces the optimization level to zero.
<li>Tracking of calls to plain Java methods from JavaScript is not implemented.
<li>Running at debug level >= 6 causes JIT errors with the Symantec JVM (but no other JVMs)
<li>The Debug API has not been rigorously tested.
</ul>
<p>
<hr WIDTH="100%">
<br><A HREF="overview-summary.html">back to top</A>
</body>
</html>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -190,7 +156,6 @@ bar</font></li>
<li>
<font size=-1>Press the Pause/Break key on the keyboard</font></li>
</ul>
<a NAME="_RunningScripts"></a><b><font face="Arial"><font color="#000080"><font size=-1>Break
on Exceptions</font></font></font></b>
<br><font size=-1>To give control to the debugger whenever a JavaScript
@@ -198,13 +163,6 @@ is exception is thrown select the <b><i>Debug->Break on Exceptions</i></b>
checkbox from the menu bar.&nbsp; Whenever a JavaScript exception is thrown
by a script a message dialog will be displayed and control will be given
to the debugger at the location the exception is raised.</font>
<p><a NAME="_BreakOnFunctionEnter"></a><b><font face="Arial"><font color="#000080"><font size=-1>Break on Function Enter</font></font></font></b>
<br><font size=-1>Selecting <b><i>Debug->Break on Function Enter</i></b> will give control to the debugger whenever the execution is entered into a function or script.</font>
<p><a NAME="_BreakOnFunctionExit"></a><b><font face="Arial"><font color="#000080"><font size=-1>Break on Function Exit</font></font></font></b>
<br><font size=-1>Selecting <b><i>Debug->Break on Function Return</i></b> will give control to the debugger whenever the execution is about to return from a function or script.</font>
<p><a NAME="_Toc502165112"></a><b><font face="Arial"><font color="#000080">Moving
Up and Down the Stack</font></font></b>
<br><font size=-1>The lower-left (dockable) pane in the debugger main window

View File

@@ -1,165 +1,166 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Rhino Documentation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Rhino Documentation</title>
</head>
<style>
h1 { text-align: center }
th { text-align: left; font-weight: normal; width: 220px }
hr { width: 100% }
</style>
<body>
<body bgcolor="#ffffff">
<center>
<h1> Rhino Documentation</h1>
<h3>General</h3>
<table>
<tbody>
<tr>
<th><a href="overview.html">Overview</a></th>
<td>An overview of the JavaScript language and of Rhino.</td>
</center>
<b><i><font size="+1">General</font></i></b>
<table width="100%">
<tbody>
<tr>
<td><a href="overview.html">Overview</a>
</td>
<td>An overview of the JavaScript language and of Rhino.</td>
</tr>
<tr>
<th><a href="limits.html">Requirements and Limitations</a></th>
<td>What you must have to run Rhino; what Rhino cannot do.</td>
<tr>
<td><a href="limits.html">Requirements and Limitations</a>
</td>
<td>What you must have to run Rhino; what Rhino cannot do.</td>
</tr>
<tr>
<th><a href="changes.html">Change log</a></th>
<td>Recent Rhino Changes</td>
<tr>
<td><a href="rhino15R3.html">What's new in 1.5R3</a>
</td>
<td>Changes since 1.5R2.</td>
</tr>
<tr>
<th><a href="opt.html">Optimization</a></th>
<td>Details on the various optimization levels.</td>
<tr>
<td><a href="debugger.html">Rhino Debugger</a>
</td>
<td>A debugger for debugging JavaScript running in Rhino.</td>
</tr>
<tr>
<th><a href="faq.html">FAQ</a></th>
<td>Answers to frequently asked questions about Rhino.</td>
<tr>
<td><a href="opt.html">Optimization</a>
</td>
<td>Details on the various optimization levels.</td>
</tr>
<tr>
<th><a href="http://www.ociweb.com/jnb/archive/jnbMar2001.html">Scripting Languages for Java</a></th>
<td>An article comparing and contrasting Rhino and Jython.</td>
<tr>
<td><a href="http://sourceforge.net/projects/jscorba">JS/CORBA Adapter</a>
</td>
<td>Provides a mechanism for arbitrary JavaScript objects to interact
with each other transparently in a distributed JavaScript system using CORBA.</td>
</tr>
</tbody>
<tr>
<td><a href="bsf.html">Using Rhino with BSF and Apache</a>
</td>
<td>How to use Rhino with apps that support BSF.</td>
</tr>
<tr>
<td><a href="changes.html">Recent Changes</a>
</td>
<td>Describes recent changes to Rhino.</td>
</tr>
<tr>
<td><a href="faq.html">FAQ</a>
</td>
<td>Answers to frequently asked questions about Rhino.</td>
</tr>
<tr>
<td><a href="http://industry.java.sun.com/javaone/99/event/0,1768,629,00.html">
1999 JavaOne session on Rhino</a>
</td>
<td>A talk on Rhino with slides. Also see the <a href="javaone.html">followup</a>
.</td>
</tr>
<tr>
<td valign="Top"><a href="http://www.ociweb.com/jnb/archive/jnbMar2001.html">
Scripting Languages for Java</a>
<br>
</td>
<td valign="Top">An article comparing and contrasting Rhino and Jython.<br>
</td>
</tr>
</tbody>
</table>
<h3>Writing Scripts</h3>
<table>
<tbody>
<tr>
<th><a href="ScriptingJava.html">Scripting Java</a></th>
<td>How to use Rhino to script Java classes.</td>
<p><b><i><font size="+1">Writing Scripts</font></i></b>
<table width="100%">
<tbody>
<tr>
<td><a href="scriptjava.html">Scripting Java</a>
</td>
<td>How to use Rhino to script Java classes.</td>
</tr>
<tr>
<th><a href="scriptjava.html">Scripting Java</a></th>
<td>How to use Rhino to script Java classes (an older treatment).</td>
<tr>
<td><a href="perf.html">Performance Hints</a>
</td>
<td>Some tips on writing faster JavaScript code.</td>
</tr>
<tr>
<th><a href="perf.html">Performance Hints</a></th>
<td>Some tips on writing faster JavaScript code.</td>
<tr>
<td><a href="tools.html">Tools</a>
</td>
<td>Some tools for developing JavaScript scripts.</td>
</tr>
</tbody>
</tbody>
</table>
<h3>JavaScript Tools</h3>
<table>
<tbody>
<tr>
<th><a href="shell.html">JavaScript Shell</a></th>
<td>Interactive or batch execution of scripts.</td>
</p>
<p><b><i><font size="+1">Embedding Rhino</font></i></b>
<table width="100%">
<tbody>
<tr>
<td><a href="tutorial.html">Embedding tutorial</a>
</td>
<td>A short tutorial on how to embed Rhino into your application.</td>
</tr>
<tr>
<th><a href="debugger.html">JavaScript Debugger</a></th>
<td>Debugging scripts running in Rhino.</td>
<tr>
<td><a href="apidocs/index.html">API javadoc Reference</a>
</td>
<td>An annotated outline of the programming interface to Rhino (tip only).</td>
</tr>
<tr>
<th><a href="jsc.html">JavaScript Compiler</a></th>
<td>Compiling scripts into Java class files.</td>
</tr>
<tr>
<th><a href="http://www.mozilla.org/js/tests/library.html">Testing</a></th>
<td>Running the JavaScript test suite.</td>
</tr>
</tbody>
</table>
<h3>Embedding Rhino</h3>
<table>
<tbody>
<tr>
<th><a href="tutorial.html">Embedding tutorial</a></th>
<td>A short tutorial on how to embed Rhino into your application.</td>
</tr>
<tr>
<th><a href="apidocs/index.html">API javadoc Reference</a></th>
<td>An annotated outline of the programming interface to Rhino (tip only).</td>
</tr>
<tr>
<th><a href="scopes.html">Scopes and Contexts</a></th>
<td>Describes how to use scopes and contexts for the best performance
<tr>
<td><a href="scopes.html">Scopes and Contexts</a>
</td>
<td>Describes how to use scopes and contexts for the best performance
and flexibility, with an eye toward multithreaded environments.</td>
</tr>
<tr>
<th><a href="serialization.html">Serialization</a></th>
<td>How to serialize JavaScript objects and functions in Rhino.</td>
<tr>
<td><a href="serialization.html">Serialization</a>
</td>
<td>How to serialize JavaScript objects and functions in Rhino.</td>
</tr>
<tr>
<th><a href="runtime.html">Runtime</a></th>
<td>A brief description of the JavaScript runtime.</td>
<tr>
<td><a href="runtime.html">Runtime</a>
</td>
<td>A brief description of the JavaScript runtime.</td>
</tr>
<tr>
<th><a href="footprint.html">Small Footprint</a></th>
<td>Hints for those interested in small-footprint embeddings.</td>
<tr>
<td><a href="footprint.html">Small Footprint</a>
</td>
<td>Hints for those interested in small-footprint embeddings.</td>
</tr>
<tr>
<th><a href="examples.html">Examples</a></th>
<td>A set of examples showing how to control the JavaScript engine and
<tr>
<td><a href="examples.html">Examples</a>
</td>
<td>A set of examples showing how to control the JavaScript engine and
build JavaScript host objects.</td>
</tr>
<tr>
<th><a href="bsf.html">Using Rhino with BSF</a></th>
<td>How to use Rhino with apps that support BSF (Bean Scripting Framework) from the Apache Jakarta project.</td>
<tr>
<td><font color="#000000"><a href="http://www.mozilla.org/js/tests/library.html">
Testing</a>
</font></td>
<td>How to run the JavaScript test suite.</td>
</tr>
</tbody>
</tbody>
</table>
<h3><hr><a href="index.html">back to top</a></h3>
</p>
<h3>
<hr width="100%"><a href="index.html">back to top</a>
</h3>
</body>
</html>

View File

@@ -1,179 +1,88 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Author" content="Igor Bukanov">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
<title>Rhino Downloads</title>
</head>
<body>
<body>
<center><b><font size="+3">Rhino Downloads</font></b></center>
<p>Rhino is available for download both in source and compiled form. </p>
<h3> Binaries</h3>
<p>
You can download binary distributions of Rhino from <a
href="ftp://ftp.mozilla.org/pub/mozilla.org/js/"> ftp://ftp.mozilla.org/pub/mozilla.org/js/</a>
. These zip files includes precompiled <tt>js.jar</tt> with all Rhino classes, documentation, examples and sources.
</p>
<p>
Rhino 1.6R5 is the last qualified release. It includes support for <a
href="http://www.ecma-international.org/publications/standards/Ecma-357.htm">ECMAScript for XML</a> (E4X). To implement E4X runtime Rhino uses <a
href="http://xmlbeans.apache.org/">XMLBeans</a> library and if you would like to use E4X you need to add <tt>xbean.jar</tt> from XMLBeans distribution to your class path.</p>
<table border=1 cellpadding=2 cellspacing=0>
<thead>
<tr>
<th>Release</th>
<th>Release Date</th>
<th>Change log</th>
<th>Download link</th>
</tr>
</thead>
<tbody>
<tr>
<td>Rhino 1.6R5</td>
<td>2006-11-19</td>
<td>Same code as 1.6R4, but relicensed under MPL/GPL.</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_6R5.zip">rhino1_6R5.zip</a></td>
</tr>
<tr>
<td>Rhino 1.6R4</td>
<td>2006-09-10</td>
<td><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=343976">bug 343976</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_6R4.zip">rhino1_6R4.zip</a></td>
</tr>
<tr>
<td>Rhino 1.6R3</td>
<td>2006-07-24</td>
<td><a href="rhino16R3.html">Changes in 1.6R3</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_6R3.zip">rhino1_6R3.zip</a></td>
</tr>
<tr>
<td>Rhino 1.6R2</td>
<td>2005-09-19</td>
<td><a href="rhino16R2.html">Changes in 1.6R2</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_6R2.zip">rhino1_6R2.zip</a></td>
</tr>
<tr>
<td>Rhino 1.6R1</td>
<td>2004-11-29</td>
<td><a href="rhino16R1.html">Changes in 1.6R1</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_6R1.zip">rhino1_6R1.zip</a></td>
</tr>
<tr>
<td>Rhino 1.5R5</td>
<td>2004-03-25</td>
<td><a href="rhino15R5.html">Changes in 1.5R5</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_5R5.zip">rhino1_5R5.zip</a></td>
</tr>
<tr>
<td>Rhino 1.5R4.1</td>
<td>2003-04-21</td>
<td><a href="rhino15R41.html">Changes in 1.5R4.1</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino15R41.zip">rhino15R41.zip</a></td>
</tr>
<tr>
<td>Rhino 1.5R4</td>
<td>2003-02-10</td>
<td><a href="rhino15R4.html">Changes in 1.5R4</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino15R4.zip">rhino15R4.zip</a></td>
</tr>
<tr>
<td>Rhino 1.5R3</td>
<td>2002-01-27</td>
<td><a href="rhino15R3.html">Changes in 1.5R3</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino15R3.zip">rhino15R3.zip</a></td>
</tr>
<tr>
<td>Rhino 1.5R2</td>
<td>2001-07-27</td>
<td><a href="rhino15R2.html">Changes in 1.5R2</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/older-packages/rhino15R2.zip">rhino15R2.zip</a></td>
</tr>
<tr>
<td>Rhino 1.5R1</td>
<td>2000-09-10</td>
<td><a href="rhino15R1.html">Changes in 1.5R1</a></td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/older-packages/rhino15R1.zip">rhino15R1.zip</a></td>
</tr>
<tr>
<td>Rhino 1.4R3</td>
<td>1999-05-10</td>
<td>Initial public release</td>
<td><a href="ftp://ftp.mozilla.org/pub/mozilla.org/js/older-packages/rhino14R3.zip">rhino14R3.zip</a></td>
</tr>
</tbody>
</table>
<p>If you are looking for <tt>js.jar</tt> for XSLT or for IBM's Bean
Scripting Framework (BSF), please read the following <a href="bsf.html#bsf-issue">note</a> and then download one of the zip files above and unzip it. </p>
You can download binaries (JAR files) from <a href="ftp://ftp.mozilla.org/pub/js/">
ftp://ftp.mozilla.org/pub/js/</a>
. Rhino 1.5 Release 2 is the last qualified release. It is also possible to
download the latest rhino build that reflects newer features and bug fixes,
but has not been fully qualified. These zip files also include the source.
<p>If you are looking for <tt>js.jar</tt> for XSLT or for IBM's Bean Scripting
Framework (BSF), download one of the zip files below and unzip it. </p>
<ul>
<li> <a href="ftp://ftp.mozilla.org/pub/js/rhino15R3-rc2.zip">Rhino 1.5R3
(release candidate 2).</a>
</li>
<ul>
<li> <i><font size="-1"><a href="rhino15R3.html">Description of changes
from 1.5R2</a>
</font></i>.</li>
</ul>
<li> <a href="ftp://ftp.mozilla.org/pub/js/rhino15R2.zip">Rhino 1.5R2.</a>
</li>
<ul>
<li> <i><font size="-1"><a href="rhino15R2.html">Description of changes
from 1.5R1</a>
</font></i>.</li>
</ul>
<li> <a href="ftp://ftp.mozilla.org/pub/js/rhino15R1.zip">Rhino 1.5R1.</a>
</li>
<ul>
<li> <i><font size="-1"><a href="rhino15R1.html">Description of changes
from 1.4R3</a>
</font></i>.</li>
</ul>
<li> <a href="ftp://ftp.mozilla.org/pub/js/rhino14R3.zip">Rhino 1.4 Release
3</a>
.</li>
<li> <a href="ftp://ftp.mozilla.org/pub/js/rhinoLatest.zip">Latest Rhino
builds</a>
.</li>
<ul>
<li> <i><font size="-1"><a href="changes.html">Description of changes from
1.5R3</a>
</font></i>.</li>
</ul>
</ul>
<h3> Source</h3>
The source code for Rhino is available under <a href="http://www.mozilla.org/MPL/">MPL</a> 1.1/GPL 2.0 license. In addition to getting the
source from the zip files above, the source code for Rhino can be found in the
CVS tree at mozilla/js/rhino. See <a
href="http://www.mozilla.org/cvs.html">source code via cvs</a> for details on
how to set up CVS, define your CVSROOT, and login. Once you've done that, just
execute the command
The source code for Rhino is available under <a href="http://www.mozilla.org/NPL/">
NPL 1.1</a>
. In addition to getting the source from the zip files above, the source
code for Rhino can be found in the CVS tree at mozilla/js/rhino. See&nbsp;
<a href="http://www.mozilla.org/cvs.html">source code via cvs</a>
for details on how to set up CVS, define your CVSROOT, and login. Once you've
done that, just execute the command
<pre>&nbsp;&nbsp;&nbsp; cvs co mozilla/js/rhino</pre>
to get the tip source.
<p>The current tip can also be viewed using LXR at <a
href="http://lxr.mozilla.org/mozilla/source/js/rhino/">
http://lxr.mozilla.org/mozilla/source/js/rhino/</a> . See also <a href="changes.html">change log</a> for the current tip.</p>
<p>
Rhino uses <a href="http://ant.apache.org/">Ant</a> as its build system and running <tt>ant</tt> command at the top directory of Rhino distribution should print the list of available build targets.
</p>
<hr width="100%"><a href="index.html">back to top</a> <br>
&nbsp; <br>
to get the tip source.
<p>The current tip can also be viewed using LXR at <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/">
http://lxr.mozilla.org/mozilla/source/js/rhino/</a>
. </p>
<p> </p>
<hr width="100%"><a href="index.html">back to top</a>
<br>
&nbsp;
</body>
</html>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -86,7 +52,7 @@ JScript. Microsoft binaries of jscript engine can be downloaded from http://msdn
language in detail but explains how these scripting engines can be used
as host to expose business objects in the middle-tier and how the user
of these applications can extend it if needed using JavaScript.</font></font>
<p><font face="Arial"><font size=-1>The scripting engine Rhino (<a href="./)">www.mozilla.org/rhino)</a>,
<p><font face="Arial"><font size=-1>The scripting engine Rhino (<a href="http://www.mozilla.org/js)">www.mozilla.org/rhino)</a>,
a javascript engine purely written in Java is one that I am going to use
for the testing the above.</font></font>
<p><font face="Arial"><font size=-1>Let us set some simple goals,</font></font>
@@ -195,10 +161,10 @@ jsbuff){</font></font>
<br><font face="Arial"><font size=-1>Object any=null;</font></font>
<br><font face="Arial"><font size=-1>try{</font></font>
<br><i><font face="Arial"><font size=-1>//Enter the Context</font></font></i>
<br><font face="Arial"><font size=-1><i>// Refer </i><u><font color="#0000FF">http://www.mozilla.org/rhino/tutorial.html</font></u></font></font>
<br><font face="Arial"><font size=-1><i>// Refer </i><u><font color="#0000FF">http://www.mozilla.org/js/rhino/tutorial.html</font></u></font></font>
<br><font face="Arial"><font size=-1>Context context = Context.enter();</font></font>
<br><i><font face="Arial"><font size=-1>// Get the execution scope</font></font></i>
<br><font face="Arial"><font size=-1>Scriptable scope = context.initStandardObjects();</font></font>
<br><font face="Arial"><font size=-1>Scriptable scope = context.initStandardObjects(null);</font></font>
<p><i><font face="Arial"><font size=-1>//----------- For Test 1 - Get System.out
in scope</font></font></i>
<br><font face="Arial"><font size=-1>//Scriptable jObj1 = Context.toObject(System.out,
@@ -217,7 +183,7 @@ to this create object instance</font></font></i>
scope);</font></font>
<br><font face="Arial"><font size=-1>scope.put("create",scope,create);</font></font>
<br><i><font face="Arial"><font size=-1>//Evaluate (or execute js)</font></font></i>
<br><font face="Arial"><font size=-1><i>//Refer </i><u><font color="#0000FF">http://www.mozilla.org/rhino/tutorial.html</font></u></font></font>
<br><font face="Arial"><font size=-1><i>//Refer </i><u><font color="#0000FF">http://www.mozilla.org/js/rhino/tutorial.html</font></u></font></font>
<br><font face="Arial"><font size=-1>any = context.evaluateString(scope,
jsbuff, "", 1, null);</font></font>
<br><i><font face="Arial"><font size=-1>//Exit the Context</font></font></i>
@@ -300,8 +266,8 @@ file - " + args[0]);</font></font>
<br>&nbsp;
<br>&nbsp;
<p><font face="Arial"><font size=-1>For more explanations on the code execution,
please refer embedding tutorial <a href="http://www.mozilla.org/rhino/tutorial.html">http://www.mozilla.org/rhino/tutorial.html</a>
and for all documentation and examples on Rhino visit <a href="doc.html">http://www.mozilla.org/rhino/doc.html</a>.</font></font>
please refer embedding tutorial <a href="http://www.mozilla.org/js/rhino/tutorial.html">http://www.mozilla.org/js/rhino/tutorial.html</a>
and for all documentation and examples on Rhino visit <a href="http://www.mozilla.org/rhino/doc.html">http://www.mozilla.org/rhino/doc.html</a>.</font></font>
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -87,11 +53,6 @@ is a program that executes JavaScript programs; it is a simplified version
of the shell in the <tt>tools</tt> package. The programs may be specified
as files on the command line or by typing interactively while the shell
is running.
<h4>PrimitiveWrapFactory</h4>
<a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/PrimitiveWrap
Factory.java">PrimitiveWrapFactory.java</a> is an example of a WrapFactory that
can be used to control the wrapping behavior of the Rhino engine on calls to Jav
a methods.<br>
<h4>
<b>Multithreaded Script Execution</b></h4>
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/DynamicScopes.java">DynamicScopes.java</a></tt>
@@ -102,7 +63,7 @@ by only performing that expensive operation once.
<br>&nbsp;
<h2>
Implementing Host Objects</h2>
First check out the <a href="tutorial.html">tutorial</a>
First check out the <a href="http://www.mozilla.org/rhino/tutorial.html">tutorial</a>
if you haven't already.
<h4>
The Foo class - Extending ScriptableObject</h4>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -46,53 +12,35 @@
<h1>
Small Footprint</h1></center>
A few changes can be made to reduce the footprint of Rhino for embeddings
where space is at a premium. On a recent build, the length of js.jar was 603,127 bytes corresponding to 1,171,708 bytes of all uncompressed Rhino classes with debug information included.
With various changes js.jar size can be reduced to 204,689 bytes corresponding to 424,774 bytes of uncompressed classes.
<h3>Tools</h3>
<p>
Most embeddings won't need any of the classes in <tt>org.mozilla.javascript.tools</tt> or any of its sub-packages.
where space is at a premium. On a recent build, Rhino consumed 355,883
bytes of space for uncompressed class files. With various changes that
number can be reduced to 281,455 bytes.
<br>&nbsp;
<h3>
Optimizer</h3>
<p>
It is possible to run Rhino with interpreter mode only, allowing you to remove
code for classfile generation that include all the classes from
<tt>org.mozilla.javascript.optimizer</tt> package.
<h3>JavaAdapter</h3>
<p>
Implementing the JavaAdapter functionality requires the ability to generate
classes on the fly. Removing <tt>org.mozilla.javascript.JavaAdapter</tt> will disable this functionality, but Rhino will otherwise run correctly.
<h3>Class generation library</h3>
<p>
If you do not include Optimizer or JavaAdapter, then you do not need Rhino library for class file generation and you can remove all the classes from in <tt>org.mozilla.classfile</tt> package.
<h3>Regular Expressions</h3>
<p>
Tools</h3>
Most embeddings won't need any of the classes in <tt>org.mozilla.javascript.tools</tt>
or any of its subpackages.
<br>&nbsp;
<h3>
Regular Expressions</h3>
The package <tt>org.mozilla.javascript.regexp</tt> can be removed. Rhino
will continue to run, although it will not be able to execute any regular
expression matches. This change saves 47,984 bytes of class files.
<h3>Debug information</h3>
<p>
Debug information in Rhino classes consumes about 25% of code size and if you can live without that, you can recompile Rhino to remove it.
<h2>smalljs.jar</h2>
<p>
Ant build script in Rhino supports smalljar target that will generate
smalljs.jar that does not include Tools, Optimizer, JavaAdapter and Class
generation library, Regular Expressions, E4X implementataion and deprecated
files. To build such minimalist jar without debug information, run the
following command from the top directory of Rhino distribution:
<pre>
ant clean
ant -Ddebug=off -Dno-regexp=true -Dno-e4x=true smalljar
</pre>
If you omit <tt>-Dno-regexp=true</tt>, then the resulting smalljs.jar will
include Regular Expression support. Similarly omitting <tt>-Dno-e4x=true</tt>
results in smalljs.jar that includes runtime support for E4X.
expression matches. This change saves 37,792 bytes of class files.
<br>&nbsp;
<h3>
JavaAdapter</h3>
Implementing the JavaAdapter functionality requires the ability to generate
classes on the fly. Removing <tt>org.mozilla.javascript.JavaAdapter</tt> and all
the classes in package <tt>org.mozilla.classfile</tt> will disable this
functionality, but Rhino will otherwise run correctly. These changes save
36,636 bytes.
<br>&nbsp;
<h3>
Optimizer</h3>
It is possible to run Rhino with interpreter mode only, allowing you to remove
classes for classfile generation. Remove the classes in packages
<tt>org.mozilla.classfile</tt> and <tt>org.mozilla.javascript.optimizer</tt>.
<br>&nbsp;
<p>
<hr WIDTH="100%">
<br><a href="index.html">back to top</a>

View File

@@ -1,82 +1,41 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Help with Rhino</title>
<script src="owner.js"></script>
<style>
h1 { text-align: center }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
<title>Help with Rhino</title>
</head>
<body>
<h1>Help with Rhino</h1>
<center><b><font size=+3>Help with Rhino</font></b></center>
<script src="owner.js"></script>
<p>Have a question that you can't find answer to in the <a href="doc.html">documentation</a>?
Here are some additional resources for help:
</p>
<h3>Newsgroup and Mail Gateway</h3>
<p>
<br>&nbsp;
<h3>
<font size=+1>Newsgroup and Mail Gateway</font></h3>
The <a href="news:netscape.public.mozilla.jseng">netscape.public.mozilla.jseng</a>
newsgroup answers questions about both Rhino and the C implementation of
JavaScript. You can get to the newsgroup through a mail gateway. Send a
message with the subject "subscribe" to <a href="mailto:mozilla-jseng-request@mozilla.org?subject=subscribe">mozilla-jseng-request@mozilla.org</a>.
To post messages, send mail to <a href="mailto:mozilla-jseng@mozilla.org">mozilla-jseng@mozilla.org</a>.
To unsubscribe, mail with "unsubscribe" in the subject to <a href="mailto:mozilla-jseng-request@mozilla.org?subject=unsubscribe">mozilla-jseng-request@mozilla.org</a>.
</p>
<p>
To view archived messages, try <a href="http://groups.google.com/groups?q=netscape.public.mozilla.jseng&hl=en&lr=&safe=off&site=groups">Google groups</a> or
other newsgroup services.
</p>
<h3>Bug System</h3>
<p>
<h3>
Bug System</h3>
Use <a href="http://bugzilla.mozilla.org/enter_bug.cgi?product=Rhino">Bugzilla</a>
to enter bugs against Rhino. Note that Rhino has its own product category.
</p>
<h3>Module Owner</h3>
<p>
The module owner,&nbsp;<script>document.write(owner());</script>, can
<br>&nbsp;
<h3>
Module Owner</h3>
The module owner,&nbsp;<script>document.write(owner());</script>
, can
be mailed for help as well, although he may copy his response to the newsgroup
to help others.
</p>
<p>
<hr WIDTH="100%"><a href="index.html">back to top</a>
<br>&nbsp;

View File

@@ -1,66 +1,75 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Rhino - JavaScript for Java</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">
<meta name="KeyWords" content="Rhino, JavaScript, Java, Mozilla">
<title>Rhino - JavaScript for Java</title>
</head>
<body>
<h1>Rhino: JavaScript for Java</h1>
<p style="text-align:center"><img src="rhino50.jpg" height="200" width="398" alt="">
<p>Rhino is an open-source implementation of JavaScript written
entirely in Java. It is typically embedded into Java applications to provide
scripting to end users.
<dl>
<dt><a href="download.html">Downloads</a>
<dd>How to get source and binaries.
<dt><a href="doc.html">Documentation</a>
<dd>Information on Rhino for script writers and embedders.
<dt><a href="history.html">History</a>
<dd>The ancestry of the beast.
<dt><a href="help.html">Help</a>
<dd>Some resources if you get stuck.
<dt><a href="users.html">Users</a>
<dd>How people are using Rhino.
</dl>
<address>Module owner: <a href="mailto:nboyd@atg.com">Norris Boyd</a></address>
<p class="note">Rhino image courtesy of Paul Houle.
<p class="remark">Add reference to
http://www.javaworld.com/jw-08-1999/jw-08-howto.html
and
http://www.javaworld.com/javaworld/jw-09-1999/jw-09-howto.html
<center>
<h1>
Rhino: JavaScript for Java</h1></center>
<center><img SRC="rhino50.jpg" height=200 width=398></center>
<hr WIDTH="100%">Rhino is an open-source implementation of JavaScript written
entirely in Java. It is typically embedded into Java applications to provide
scripting to end users.
<table WIDTH="100%" >
<tr>
<td>
<div align=right><b><a href="download.html">Downloads</a></b></div>
</td>
<td>How to get source and binaries.</td>
</tr>
<tr>
<td>
<div align=right><b><a href="doc.html">Documentation</a></b></div>
</td>
<td>Information on Rhino for script writers and embedders.</td>
</tr>
<!--
<tr>
<td>
<div align=right><b><a href="users.html">Users</a></b></div>
</td>
<td>How people are using Rhino.</td>
</tr>
-->
<tr>
<td>
<div align=right><b><a href="history.html">History</a></b></div>
</td>
<td>The ancestry of the beast.</td>
</tr>
<tr>
<td>
<div align=right><b><a href="help.html">Help</a></b></div>
</td>
<td>Some resources if you get stuck.</td>
</tr>
</table>
<hr WIDTH="100%"><font size=-1>Module owner&nbsp;</font><script src="owner.js"></script>
<script>document.write(owner());</script>
<br><font size=-1>Rhino image courtesy of Paul Houle.</font><!---
Add reference to
http://www.javaworld.com/jw-08-1999/jw-08-howto.html
and
http://www.javaworld.com/javaworld/jw-09-1999/jw-09-howto.html
--->
</body>
</html>
</html>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -67,7 +33,7 @@ so people can ask addition questions or comments there.
Java classes visible to scripts</h3>
One attendee raised the point that many embeddings may not want scripts
to be able to access all Java classes. This is an excellent point, and
I've implemented an addition to the <a href="apidocs/org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
I've implemented an addition to the <a href="../js/rhino/org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
class that allows embedders to choose which classes are exposed to scripts.
<h3>
Easier "importing" of Java classes</h3>
@@ -76,7 +42,7 @@ classes (like <tt>java.lang.String</tt> or <tt>Packages.org.mozilla.javascript.C
could be improved. I've implemented a set of changes that make importing
easier, but I'm not convinced that adding them is the right thing to do
due to some drawbacks.
<p>To see what I've done, take a look at the javadoc for the <a href="apidocs/org/mozilla/javascript/ImporterTopLevel.html">ImporterTopLevel</a>
<p>To see what I've done, take a look at the javadoc for the <a href="../js/rhino/org/mozilla/javascript/ImporterTopLevel.html">ImporterTopLevel</a>
class. You'll see that it's now possible to make function calls to "import"
Java classes so that they can be referred to without qualification. I didn't
use the word "import" because that's a keyword in JavaScript.

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -93,7 +59,7 @@ periods.</ul>
<tt>-version </tt><i>versionNumber</i>
<ul>Specifies the language version to compile with. The string <i>versionNumber</i>
must be one of <tt>100</tt>, <tt>110</tt>, <tt>120</tt>, <tt>130</tt>,
<tt>140</tt>, <tt>150</tt>, or <tt>160</tt>. See <a href="overview.html#versions">JavaScript Language
or <tt>140</tt>. See <a href="overview.html#versions">JavaScript Language
Versions</a> for more information on language versions.</ul>
<h2>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -115,6 +81,6 @@ Earlier versions may return:
<p>The Microsoft SDK 3.1 for Java also exhibits this problem.
<p>
<hr WIDTH="100%">
<br><a href="#">back to top</a>
<br><a href="rhino.html">back to top</a>
</body>
</html>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -58,7 +24,8 @@ documents.
All the features of JavaScript 1.5</li>
<li>
Allows direct scripting of Java</li>
<a href="http://developer.netscape.com/library/documentation/communicator/jsguide4/livecon.htm">LiveConnect</a>
-- allows direct scripting of Java</li>
<li>
A JavaScript shell for executing JavaScript scripts</li>
@@ -73,10 +40,8 @@ Language</h3>
The JavaScript language itself is standardized by Standard ECMA-262 <i>ECMAScript:
A general purpose, cross-platform programming language</i>. Rhino 1.5 implements
JavaScript 1.5, which conforms to Edition 3 of the Standard. The Standard
may be <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">downloaded</a> or
may be <a href="http://www.ecma.ch/stand/ecma-262.htm">downloaded</a> or
obtained by mail from ECMA, 114 Rue du Rh&ocirc;ne, CH1204 Geneva, Switzerland.
<p>Rhino 1.6 also implements ECMA-357 <i>ECMAScript for XML (E4X)</i>. See the <a href="http://www.ecma-international.org/publications/standards/Ecma-357.htm">specification</a> for more information on the standard, and <a href="rhino16R1.html#E4X">Rhino version 1.6R1</a> for details on the implementation in Rhino.
<p>In addition, Rhino has implemented JavaAdapters, which allows JavaScript
to implement any Java interface or extend any Java class with a JavaScript
object. See the <tt>enum.js</tt> example for more information.

View File

@@ -1,49 +1,3 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
function owner()
{
return email("Norris Boyd", "nboyd", "atg.com");
function owner() {
return '<a href="mailto:nboyd'+'@'+ 'atg.com">Norris Boyd</a>'
}
function email(name, prefix, suffix)
{
return "<a href='mailto:"+prefix+"@"+suffix+"'>"+name+"</a>";
}
function write_email(name, prefix, suffix)
{
document.write(email(name, prefix, suffix));
}

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -114,7 +80,7 @@ command line. This is <tt>jsc</tt>, the JavaScript compiler. This tool
can be used to create Java classes from JavaScript. Options exist to allow
creation of Java classes that implement arbitrary interfaces and extend
arbitrary base classes, allowing JavaScript scripts to implement important
protocols like applets and servlets. See <a href="jsc.html">http://www.mozilla.org/rhino/jsc.html</a>.
protocols like applets and servlets. See <a href="http://www.mozilla.org/rhino/jsc.html">http://www.mozilla.org/rhino/jsc.html</a>.
<br>&nbsp;
<h3>
LiveConnect 3</h3>
@@ -136,7 +102,7 @@ useful for multithreaded environments like server embeddings.
New semantics for <tt>ScriptableObject.defineClass</tt></h3>
The old rules for defining JavaScript objects using a Java class were getting
baroque. Those rules are still supported, but a cleaner definition is now
supported. See the <a href="apidocs/org/mozilla/javascript/ScriptableObject.html#defineClass(org.mozilla.javascript.Scriptable, java.lang.Class)">javadoc</a>
supported. See the <a href="http://www.mozilla.org/js/rhino/org/mozilla/javascript/ScriptableObject.html#defineClass(org.mozilla.javascript.Scriptable, java.lang.Class)">javadoc</a>
for details.
<br>&nbsp;
<h3>
@@ -153,7 +119,7 @@ variables.
Java classes visible to scripts</h3>
An attendee at JavaOne raised the point that many embeddings may not want
scripts to be able to access all Java classes. This is an excellent point,
and I've implemented an addition to the <a href="apidocs/org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
and I've implemented an addition to the <a href="../js/rhino/org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
interface that allows embedders to choose which classes are exposed to
scripts.
<br>&nbsp;
@@ -161,7 +127,7 @@ scripts.
SecuritySupport and JavaAdapter</h3>
Andrew Wason pointed a problem with the new JavaAdapter feature (which
allows JavaScript objects to implement arbitrary Java interfaces by generating
class files). It didn't support the <a href="apidocs/org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
class files). It didn't support the <a href="../js/rhino/org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
interface, which allows Rhino to delegate the creation of classes from
byte arrays to a routine provided by the embedding. This ability is important
from a security standpoint because class creation is considered a privileged
@@ -174,14 +140,14 @@ will delegate class creation to the SecuritySupport class.
Context.exit()</h3>
Context.exit() has been changed from an instance method to a static method.
This makes it match the Context.enter() method, which is also static. See
the <a href="apidocs/org/mozilla/javascript/Context.html#exit()">javadoc</a>
the <a href="http://www.mozilla.org/js/rhino/org/mozilla/javascript/Context.html#exit()">javadoc</a>
for more information on its operation.
<br>&nbsp;
<h3>
Context.enter(Context)</h3>
A new overloaded form of Context.enter has been added. Without the addition
of this method it was not possible to attach an existing context to a thread.
See the <a href="apidocs/org/mozilla/javascript/Context.html#enter(org.mozilla.javascript.Context)">javadoc</a>
See the <a href="http://www.mozilla.org/js/rhino/org/mozilla/javascript/Context.html#enter(org.mozilla.javascript.Context)">javadoc</a>
for more information on its operation.
<br>&nbsp;
<h3>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>

View File

@@ -1,235 +0,0 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Igor Bukanov">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Debug API changes</title>
</head>
<body bgcolor="#ffffff">
<h2 align="center">Debug API changes in Rhino 1.5 Release 4</h2>
<p>
The main difference between the old and new API is that the application needs to implement both org.mozilla.javascript.debugger.Debugger and
org.mozilla.javascript.debugger.DebugFrame interfaces to receive debug
information during script execution. See the API documentation for these
classes for details:
<br>
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/src/org/mozilla/javascript/debug/DebugFrame.java">http://lxr.mozilla.org/mozilla/source/js/rhino/src/org/mozilla/javascript/debug/DebugFrame.java</a>
<br><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/src/org/mozilla/javascript/debug/Debugger.java">http://lxr.mozilla.org/mozilla/source/js/rhino/src/org/mozilla/javascript/debug/Debugger.java</a>
</tt>
<p>
In addition the org.mozilla.javascript.debugger.DebuggableEngine interface and the getDebuggableEngine method in org.mozilla.javascript.Context are replaced by 3 Context methods: setDebugger, getDebugger and getDebuggerContextData to set/get debugger and its Context data in the current thread Context:<br>
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/src/org/mozilla/javascript/Context.java">http://lxr.mozilla.org/mozilla/source/js/rhino/src/org/mozilla/javascript/Context.java</a></tt>
<p>The following gives few examples how to update your current application to the new API.
<p>
1. Setting and querying a Debugger implementation
<p>
Old API:
<pre>
cx.getDebuggableEngine.setDebugger(debugger);
cx.getDebuggableEngine.getDebugger();
</pre>
New API:
<pre>
cx.setDebugger(debugger);
cx.getDebugger();
</pre>
<p>
2. Monitoring execution of each line in the script
<p>
Old implementation:
<pre>
public MyDebugger implement Debugger {
public void handleCompilationDone(Context cx,
DebuggableScript fnOrScript,
StringBuffer source)
{
}
void handleBreakpointHit(Context cx)
{
DebugFrame frame = cx.getDebuggableEngine().getFrame(0);
System.out.println("New line:" + frame.getLineNumber());
}
void handleExceptionThrown(Context cx, Object exception)
{
}
}
...
cx.getDebuggableEngine.setDebugger(new MyDebugger());
cx.getDebuggableEngine.setBreakNextLine(true);
</pre>
New implementation:
<pre>
public MyDebugger implement Debugger
{
public void handleCompilationDone(Context cx,
DebuggableScript fnOrScript,
StringBuffer source)
{
}
public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript)
{
return new MyDebugFrame();
}
}
class MyDebugFrame implements DebugFrame
{
public void onEnter(Context cx, Scriptable activation,
Scriptable thisObj, Object[] args)
{
}
public void onExceptionThrown(Context cx, Throwable ex)
{
}
public void onExit(Context cx, boolean byThrow,
Object resultOrException)
{
}
public void onLineChange(Context cx, int lineNumber)
{
System.out.println("New line:" + frame.getLineNumber());
}
}
...
cx.setDebugger(new MyDebugger());
</pre>
Note the in the new implementation the application can monitor function enter/exit by customizing enterFrame and onExit in the above code.
<p>
3. Breakpoint handling
<p>
Old implementation:
<pre>
public MyDebugger implement Debugger {
public void handleCompilationDone(Context cx, DebuggableScript fnOrScript,
StringBuffer source)
{
int breakpointLine = ...;
fnOrScript.placeBreakpoint(breakpointLine);
}
void handleBreakpointHit(Context cx) {
DebugFrame frame = cx.getDebuggableEngine().getFrame(0);
System.out.println("Breakpoint hit: "+frame.getSourceName()+":"+frame.getLineNumber());
}
void handleExceptionThrown(Context cx, Object exception)
{
}
}
...
cx.getDebuggableEngine.setDebugger(new MyDebugger());
</pre>
New implementation:
<pre>
public MyDebugger implement Debugger
{
public void handleCompilationDone(Context cx,
DebuggableScript fnOrScript,
StringBuffer source)
{
}
public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript)
{
return new MyDebugFrame(fnOrScript);
}
}
class MyDebugFrame implements DebugFrame
{
DebuggableScript fnOrScript;
MyDebugFrame(DebuggableScript fnOrScript)
{
this.fnOrScript = fnOrScript;
}
public void onEnter(Context cx, Scriptable activation,
Scriptable thisObj, Object[] args)
{
System.out.println("Frame entered");
}
public void onLineChange(Context cx, int lineNumber)
{
if (isBreakpoint(lineNumber)) {
System.out.println("Breakpoint hit: "+fnOrScript.getSourceName()+":"+lineNumber);
}
}
public void onExceptionThrown(Context cx, Throwable ex)
{
}
public void onExit(Context cx, boolean byThrow,
Object resultOrException)
{
System.out.println("Frame exit, result="+resultOrException);
}
private boolean isBreakpoint(int lineNumber)
{
...
}
}
...
cx.setDebugger(new MyDebugger());
</pre>
Here debugger during execution needs to decide if a particular line has breakpoint on it set or not during script execution, not at the moment of script initialization.
<p>See also Rhino Debugger that fully explore the new API:<br><tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/toolsrc/org/mozilla/javascript/tools/debugger/Main.java">http://lxr.mozilla.org/mozilla/source/js/rhino/toolsrc/org/mozilla/javascript/tools/debugger/Main.java</a></tt>. The debugger changes includes support for debugging eval and Function scripts and loading script sources from their URL if debugger was not installed during scripts initialization.
<hr width="100%"><br>
<a href="index.html">back to top</a></h3>
</body></html>

View File

@@ -1,251 +0,0 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en"><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
<meta name="KeyWords" content="Rhino, JavaScript, Java"><title>Change Log</title></head>
<body bgcolor="#ffffff">
<h1 align="center">
Rhino Change Log</h1>
This is a log of changes since the release of Rhino 1.5 Release 3.
<h3>Rhino debug API changes</h3>
A new, incompatible Rhino debug API gives an option to monitor
entering/leaving of script functions while decreasing the amount of code to
implement the API in the Rhino core. Details are available <a href="rhino15R4-debugger.html">here</a>. With the new API <a href="debugger.html">Rhino Debugger</a> provides options to break on function enter/exit, can debug scripts defined by eval and Function construction and scripts loaded prior the debugger were started.
<h3>WrapFactory introduced, WrapHandler deprecated</h3>
A design flaw in the WrapHandler interface (a call to a Java contructor from
JavaScript would result in a call to wrap the result, which would then be
cast to a Scriptable) inspired the deprecation of that interface and the
introduction of a new class, WrapFactory, that contains a new method called
on the result of a constructor call and can be customized by application if necessary.
<p>
In addition, WrapFactory has the new <tt>setJavaPrimitiveWrap</tt> method to control if instances of Java <tt>String</tt> and <tt>Number</tt> class should be wrapped to special script objects as any other Java objects so a script can access any method <tt>String</tt> and <tt>Number</tt>, or they should be converted to JavaScript primitive strings and numbers.
<h3>New security interfaces</h3>
<p>
Igor Bukanov contributed a new security implementation that allows integration with Java2 security model and prevents scripts to escape the security sandbox via eval/Function schemes.
<p>
Due to this changes SecuritySupport interface is replaced by ClassShutter and SecurityController, where ClassShutter controls which classes are visible to scripts via LiveConnect and SecurityController provides permission management. For compatibility SecuritySupport is still available as a deprecated interface but only its visibleToScripts method is used as an alias for ClassShutter.visibleToScripts. See API documentation for new classes for details.
<p>
An implementation of SecurityController that uses java policy settings to restrict script permissions based on its URL is available with Rhino shell. See the <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/JavaPolicySecurity.java">JavaPolicySecurity</a> source for details. To activate it, set the <tt>rhino.use_java_policy_security</tt> system property to true when invoking Rhino shell together with installing a security manager.
<h3>Serialization chages</h3>
Due to changes in Rhino implementation and bug fixes in serialization support runtime data serialized in Rhino 1.5 Release 3 can not be read back in the Release 4.
<h3>Regular expressions improvements</h3>
Roger Lawrence provided new regular expressions implementation which fully confirms to EcmaScript 262 standard and faster.
<h3>Scripting of classes from any class loader</h3>
Christopher Oliver contributed code to allow to use the <tt>Packages</tt> object as a constructor taking a class loader argument so a script can access classes defined by that class loader. For example, to access classes from foo.jar file in the current directory, the following can be used:
<pre>
// create class loader
var loader = new java.net.URLClassLoader([new java.net.URL("file:./foo.jar")]);
// create its LiveConnect wrapper
var fooJar = new Packages(loader);
// create an instance of the class For from foo.jar
var obj = new fooJar.Foo(1, 2, 3);
obj.someMethod();
</pre>
<h3>Shell function to run external processes.</h3>
A new <tt>runCommand</tt> function is added to <a href="shell.html">Rhino Shell</a> to run external priocesses. For details, see JavaDoc for <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Global.java">org.mozilla.javascript.tools.shell.Global#runCommand</a>.
<h3>Resolved Bugzilla reports</h3>
The following Rhino reports in <a href="http://bugzilla.mozilla.org/">Bugzilla</a> where resolved for Rhino 1.5 Release 4.
<p>
<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=61579">61579</a> -
context.decompileScript doesn't work.
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=72021">72021</a> -
The ScriptRuntime class tries to convert even the String values to JavaNativeObject
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=83051">83051</a> -
A function defined under a with block can't be invoked outside it
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=104089">104089</a> -
Cannot reattach context to its thread because of the bug in Context class
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=105438">105438</a> -
SourceName and lineNumbers of syntax errors in Javascript files not dispalyed.
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=106548">106548</a> -
/^.*?$/ will not match anything
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=114583">114583</a> -
script compile/decompile bug
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=114969">114969</a> -
[], [^] are valid RegExp conditions
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=115717">115717</a> -
java.lang.ArrayIndexOutOfBoundsException on with/try/finally
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=120194">120194</a> -
JS toInt32(x) conversion doesn't match ECMAScript definition
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=122167">122167</a> -
string.replace() placeholder '$1' not working
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=123439">123439</a> -
Backreferences /(a)? etc./ must hold |undefined| if not used
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=124508">124508</a> -
regexp.lastIndex should be integer-valued double, not uint32
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=124900">124900</a> -
arguments object storing duplicate parameter values
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=125562">125562</a> -
Regexp performance improvement
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=126317">126317</a> -
Crash on re.exec(str) if re.lastIndex set to certain values
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=126722">126722</a> -
(undefined === null) evaluating to true in Rhino compiled mode
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=128468">128468</a> -
java.io.NotSerializableException: org.mozilla.javascript.NativeError
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=129365">129365</a> -
Incorrect licensing in dtoa.java
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=132217">132217</a> -
delete on global function should not delete the function
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=136893">136893</a> -
Rhino treatment of |for(i in undefined)|, |for(i in null)|
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=137181">137181</a> -
delete on an arguments[i] not working correctly
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=145791">145791</a> -
ECMA conformance: Function.prototype.apply(), Function.prototype.call()
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=149285">149285</a> -
Complier does not report the correct line number on SyntaxError:Invalid assignment left-hand side.
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=151337">151337</a> -
EcmaError.getLineSource() returns 0x0 characters.
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=153223">153223</a> -
New RegExp engine in Rhino
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=154693">154693</a> -
Interpreted mode doesn't grok different functions on different objects
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=156510">156510</a> -
for (i in undefined) {} should not throw TypeError
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=157196">157196</a> -
ScriptableObject needs custom serialization implementation
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=157509">157509</a> -
No error on invalid usage of \ in identifiers
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=158159">158159</a> -
Should Rhino support octal escape sequences in regexps?
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=159334">159334</a> -
The javascript functions size is limited by a bug
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=164947">164947</a> -
Debugging unique.js produce a stack trace and erratic results
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=166530">166530</a> -
ClassCostException in FunctionObject static initializer
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=169830">169830</a> -
Array.concat(function) doesn't add function to the array
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=173180">173180</a> -
Rhino UTF-8 decoder accepts overlong sequences
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=173906">173906</a> -
Dynamic scope not working correctly with optimzation level >= 1
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=175383">175383</a> -
ArrayIndexOutOfBoundsException in string.replace()
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=177314">177314</a> -
Rhino should allow '\400' to mean ' 0'
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=179068">179068</a> -
String literals in Rhino are limited to 64K
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=179366">179366</a> -
--&gt; after whitespace after line start should mean comments to line end
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=181654">181654</a> -
Calling toString for an object derived from the Error class throws TypeError
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=181834">181834</a> -
wrong scope used for inner functions when compiling functions with dynamic scopes (interpreted only)
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=181909">181909</a> -
some regression tests for Error invalid
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=182028">182028</a> -
Calling has() in get() of a ScriptableObject causes getter function to not be called
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=184107">184107</a> -
with(...) { function f ...} should set f in the global scope
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=184111">184111</a> -
ArrayOutOfBounds Exception thrown when using Rhino Javascript Debugger
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=185165">185165</a> -
Decompilation of "\\" gives broken "\"
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=189183">189183</a> -
Debugger source frame window layering fix
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=189898">189898</a> -
Broken String.replace: "XaXY".replace("XY", "--") gives --aXY
<hr width="100%"><br>
<a href="index.html">back to top</a></h3>
</body></html>

View File

@@ -1,75 +0,0 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Igor Bukanov">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Rhino 1.5 Release 4.1 Change Log</title>
</head>
<body bgcolor="#ffffff">
<h1 align="center">Rhino 1.5 Release 4.1 Change Log</h1>
1.5R4.1 is a bug fix release to address mostly regressions from 1.5R3 found in 1.5R4. The only visible API change compared with 1.5R4 is two new methods in <tt>org.mozilla.javascript.Context</tt>, <tt>getApplicationClassLoader()</tt> and <tt>setApplicationClassLoader(ClasssLoader)</tt>. They allow to control the class loader Rhino uses when accessing application classes.
<p>
For differences between 1.5R4 and 1.5R3, see <a href="rhino15R4.html">1.5R4 change log</a>.
<h3>Resolved Bugzilla reports</h3>
The following Rhino reports in <a href="http://bugzilla.mozilla.org/">Bugzilla</a> where resolved for Rhino 1.5 Release 4.
<p>
<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=96270">96270</a> -
Unable to create java objects from within a javascript.
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=193168">193168</a> -
Rhino debugger in v1.5R4 fails to update script source when a script is reloaded.
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=193555">193555</a> -
1.5R4 regression: function expression has no access to its name.
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=196017">196017</a> -
1.5R4 regression: script can not find classes on some versions of JDK.
<br><a href="http://bugzilla.mozilla.org/show_bug.cgi?id=200551">200551</a> -
JavaAdapter not loading a class if js.jar installed in jre/lib/ext directory.
<hr width="100%"><br>
<a href="index.html">back to top</a></h3>
</body></html>

View File

@@ -1,197 +0,0 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Author" content="Igor Bukanov">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Change Log</title>
</head>
<body bgcolor="#ffffff">
<h1 align="center">
Rhino 1.5R5 Change Log</h1>
This is a log of significant changes in Rhino 1.5 Release 5.
<h3>Wrapping of JavaScript functions as Java interfaces</h3>
<p>
Rhino allows to pass a JavaScript function to a Java method expecting an interface which either has a single method or all its methods have the same number of parameters and each corresponding parameter has the same type.
The JavaScript function will be called whenever interface's method is called from Java. The function will receive all Java arguments properly converted into JS types and as the last parameter Rhino will pass interface method's name.
</p>
<p>
The feature allows to simplify code that previously had to create explicit JavaAdapter objects. For example, one can write now:
<pre>
var button = new javax.swing.JButton("My Button");
button.addActionListener(function(e) {
java.lang.System.out.println("Button click:"+e);
});
var frame = new javax.swing.JFrame("My Frame");
frame.addWindowListener(function(e, methodName) {
java.lang.System.out.println("Window event:"+e);
if (methodName == "windowClosing") {
java.lang.System.exit(0);
}
});
</pre>
instead of
<pre>
var button = new javax.swing.JButton("My Button");
button.addActionListener(new java.awt.event.WindowListener({
windowClosing : function(e) {
java.lang.System.out.println("Window event:"+e);
java.lang.System.exit(0);
},
windowActivated : function(e) {
java.lang.System.out.println("Window event:"+e);
},
// similar code for the rest of WindowListener methods
});
var frame = new javax.swing.JFrame("My Frame");
frame.addWindowListener(function(e, methodName) {
</pre>
which was necessary in the previous version of Rhino.
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=223435">Bugzilla 223435</a>.
</p>
<h3>uneval() and toSource()</h3>
<p>
Rhino fully supports <tt>uneval()</tt> function and <tt>toSource()</tt> method which are extensions to ECMAScript available in <a href="http://www.mozilla.org/js/">SpiderMonkey</a>. They return a string that can be passed to the <tt>eval()</tt> function to reconstruct the original value when possible. It is guaranteed that <tt>uneval(eval(uneval(x)))&nbsp;==&nbsp;uneval(x)</tt> and in many cases more useful notion <tt>eval(uneval(x))&nbsp;==&nbsp;deep_copy_of_x</tt> holds.
</p>
<p>
For example, here is an extract from a <a href="shell.html">Rhino shell</a> session:
</p>
<pre>
js&gt; var x = { a: 1, b: 2, c: [1,2,3,4,5], f: function test() { return 1; }, o: { property1: "Test", proeprty2: new Date()}}
js&gt; uneval(x)
({c:[1, 2, 3, 4, 5], o:{property1:"Test", proeprty2:(new Date(1076585338601))}, f:(function test() {return 1;}), a:1, b:2})
js&gt; x.toSource()
({c:[1, 2, 3, 4, 5], o:{property1:"Test", proeprty2:(new Date(1076585338601))}, f:(function test() {return 1;}), a:1, b:2})
js&gt; uneval(x.propertyThatDoesNotExist)
undefined
</pre>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=225465">Bugzilla 225465</a>.
</p>
<h3>seal() and changes in semantic of sealed objects</h3>
<p>
Rhino supports <tt>seal(object)</tt> function which is another ECMAScript extension from SpiderMonkey. The function makes the object immune to changes and any attempt to add, modify or delete a property of such object will throw an exception. Previously sealing was only possible through the Java <tt>sealObject()</tt> method in <tt>org.mozilla.javascript.ScriptableObject</tt> and before Rhino 1.5R5 it was possible to modify existing properties of sealed objects.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=203013">Bugzilla 203013</a>.
</p>
<h3>Exception changes</h3>
<p>
In Rhino 1.5R5 all exceptions generated during execution of a script provide information about script's source name and line number that triggered the exception. The exception class <tt>org.mozilla.javascript.JavaScriptException</tt> is used now only to represent exceptions explicitly thrown by the JavaScript <b>throw</b> statement, it never wraps exceptions thrown in a Java method invoked by the script. Such exceptions are always wrapped as <tt>org.mozilla.javascript.WrappedException</tt>.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=217584">Bugzilla 217584</a>, <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=219055">Bugzilla 219055</a>
and <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=225817">Bugzilla 225817</a>
</p>
<h3>Compiled scripts are scope independent</h3>
<p>
Previously Rhino required a scope object in the <tt>compileReader</tt> method of <tt>org.mozilla.javascript.Context</tt> to compile a script into <tt>org.mozilla.javascript.Script</tt> instances. Under some circumstances it was possible that the scope object would be stored in the compiled form of the script. It made impossible in such cases to reuse of the compiled form to execute the script against different scopes and lead to potential memory leaks.
<p>
</p>Rhino 1.5R5 fixes such misbehavior and <tt>compileReader</tt> and newly introduced <tt>compileString</tt> no longer take the scope argument. For compatibility the old form of <tt>compileReader</tt> is kept as a deprecated method.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=218440">Bugzilla 218440</a>.
</p>
<h3>Callable interface</h3>
<p>
All <tt>org.mozilla.javascript.Script</tt> and <tt>org.mozilla.javascript.Function</tt> instances in Rhino now implement the new interface <tt>org.mozilla.javascript.Callable</tt> which together with the new <tt>call</tt> method in <tt>org.mozilla.javascript.Context</tt> gives a simple way to call scripts and functions without explicit calls to <tt>Context.enter()</tt> and <tt>Context.exit()</tt>.
</p>
<p>
The <tt>Callable</tt> interface allows to set the value of JavaScript <b>this</b> during script execution to arbitrary <tt>org.mozilla.javascript.Scriptable</tt> instance overriding default bahaviour of using the scope object for the value of <b>this</b>.
</p>
<p>Rhino interpreter uses <tt>Callable</tt> to pass references to scripts and functions to <tt>org.mozilla.javascript.SecurityController</tt> directly without wrapping script code into an additional proxy <tt>Script</tt> object. It allows to optimize an implementation of <tt>callWithDomain</tt> method in <tt>org.mozilla.javascript.SecurityController</tt>.
</p>
<p>
For compatibility applications extending the previous version of <tt>SecurityController</tt> are fully supported but the new applications should override <tt>callWithDomain</tt> method, not <tt>execWithDomain</tt>.
</p>
<h3>No static caching</h3>
<p>
Rhino no longer caches generated classes and information about reflected Java classes in static objects. Instead such caches are stored in a top scope object and initialized by default during call to <tt>initStandardObjects</tt> of <tt>org.mozilla.javascript.Context</tt>. This can be overridden with the explicit call to the <tt>associate</tt> method of <tt>org.mozilla.javascript.ClassCache</tt> if cache sharing is desired.
</p>
<p>The cached objects no longer holds references to scope objects so even an application using multiple calls to <tt>Context.initStandardObjects</tt> and single shared <tt>ClassCache</tt> instance would not leak references to runtime library instantiations as it was the case with the previous Rhino for all applications.
</p>
The change allows to instantiate multiple Rhino runtime instances which would not interfere with each other and prevents memory leaks through ever growing caches. </p>
<h3>API for compiling scripts into class files</h3>
<p>The new class <tt>org.mozilla.javascript.optimizer.ClassCompiler</tt> provides a simple API to compile JavaScript source into set of Java class files with the given set of compilation options. <a href="jsc.html">JavaScript Compiler</a> was upgraded to use new API and the old API were deprecated.
</p>
<h3>API for Context sealing</h3>
<p>The new methods <tt>seal(Object)</tt>, <tt>unseal(Object)</tt> and <tt>isSealed()</tt> in <tt>org.mozilla.javascript.Context</tt> allows to make <tt>Context</tt> instances immune from changes. Rhino embeddings that needs to run potentially untrusted scripts may use the new functionality to proprly implement the sandbox for such scripts without too restrictive <tt>org.mozilla.javascript.ClassShutter</tt> implementation.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=236117">Bugzilla 236117</a>.
</p>
<h3>Optimizer generates only one class per script </h3>
<p>
In Rhino 1.5R5 the default optimization mode generates only one Java class for script and all its functions while previously the optimizer generated additional class for each function definition in the script. It improves loading time for scripts and decreases memory usage especially for scripts with many function definitions.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=198086">Bugzilla 198086</a>.
</p>
<h3>Improved support for huge scripts</h3>
<p>
The interpreted mode contains significantly less restrictions on size and complexity of the scripts and if the remaining restrictions are not satisfied, Rhino will report an exception instead of generating corrupted internal byte code for interpreting.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=225831">Bugzilla 225831</a>.
</p>
<h2>Resolved Bugzilla reports</h2>
<p>
The full list of Bugzilla reports addressed in Rhino 1.5R5 can be obtained with the following Bugzilla query:
<br>
<a href="http://bugzilla.mozilla.org/buglist.cgi?product=Rhino&target_milestone=1.5R5&bug_status=RESOLVED&bug_status=VERIFIED">http://bugzilla.mozilla.org/buglist.cgi?product=Rhino&amp;target_milestone=1.5R5&amp;bug_status=RESOLVED&amp;bug_status=VERIFIED</a>
<br>
which searches <a href="http://bugzilla.mozilla.org/">bugzilla.mozilla.org</a> for all resolved or verified bugs with the product set to Rhino and the target milestone set to 1.5R5.
</p>
<hr width="100%"><br>
<a href="index.html">back to top</a></h3>
</body></html>

View File

@@ -1,187 +0,0 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Author" content="Igor Bukanov">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Change Log</title>
<style>
P { text-align: justify; }
</style>
</head>
<body bgcolor="#ffffff">
<h1 align="center">
Change Log for Rhino</h1>
<h2>Rhino 1.6R1, released 2004-11-29</h2>
<h3>Release overview</h3>
<p>
Rhino 1.6R1 is the new major release of Rhino. It supports ECMAScript for XML (E4X) as specified by <a href="http://www.ecma-international.org/publications/standards/Ecma-357.htm">ECMA 357</a> standard. E4X is a set of language extensions adding native XML support for JavaScript without affecting the existing code base. <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/E4X/e4x_example.js">E4X example</a> demonstrates various E4X constructions and their usage in JavaScript code.
</p>
<p>
This version of Rhino should be binary compatible with the current embeddings that use only public <a href="apidocs/index.html">API</a> unless the code use the previously deprected classes as documented <a href="#Rhino1.5R1-deprecation-removal">below</a>. Please report any incompatibility issues to <a href="http://bugzilla.mozilla.org/enter_bug.cgi?product=Rhino">Bugzilla</a>.
</p>
</h3>
<a NAME="E4X"></a>
<h3>E4X implementation</h3>
<p>
The E4X code was donated to the Rhino project by <a href="http://www.bea.com/">BEA</a> and developed by staff from <a href="http://www.bea.com/">BEA</a> and <a href="http://www.agiledelta.com/">AgileDelta</a>.
</p>
<p>
It uses <a href="http://xmlbeans.apache.org/">XMLBeans</a> library to implement E4X runtime. The implementation was tested against versions 1.0.2 and 1.0.3 of XMLBeans. Please make sure that <tt>xbean.jar</tt> is avaialble on the classpath if you use E4X in your scripts.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=242805">Bugzilla 242805</a> for details. See also <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=270779">Bugzilla 270779</a>
for the list of known issues with E4X implementation in Rhino 1.6R1.
</p>
<h3>Other changes</h3>
<h4>Common root for Rhino execeptions</h4>
<p>
Now all Rhino execption classes are derived from <a href="apidocs/org/mozilla/javascript/RhinoException.html"><tt>org.mozilla.javascript.RhinoException</tt></a> which extends <tt>java.lang.RuntimeException</tt>.
The class gives the uniform way to access information about the script origin of the exception and simplifies execption handling in Rhino embeddings.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=244492">Bugzilla 244492</a> for details.
</p>
<h4>Removal of code complexity limits in the interpreter</h4>
<p>
The interpreter mode in Rhino does not limit any longer the script size or code complexity. It should be possible to execute any script as long as JVM resources allow so.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=244014">Bugzilla 244014</a> and <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=256339">Bugzilla 256339</a> for details.
</p>
<h4>Tail call elimination in the interpreter</h4>
<p>
The interpreter mode in Rhino implements tail call elimination to avoid excessive stack space consumption when a function returns result of a call to another function.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=257128">Bugzilla 257128</a>.
</p>
<h4>Support for continuations in the interpreter</h4>
<p>
The interpreter mode in Rhino supports continuations. The code is based on the ideas from the original implementation of continuations by Christopher Oliver and
<a href="http://sisc.sourceforge.net/">SISC</a> project. To use the
continuations make sure that the interpreter mode is selected through <a
href="apidocs/org/mozilla/javascript/Context.html#setOptimizationLevel(int)">setting</a>
the optimization level to -1 or by adding <tt>-opt -1</tt> to the command line
of <a href="shell.html">Rhino shell</a>.
</p>
<p>
Please note that the details of implementation and Java and JavaScript API for continuations may change in future in incompatible way.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=258844">Bugzilla 258844</a>.
</p>
<h4>JavaImporter constructor</h4>
<p>
<tt>JavaImporter</tt> is a new global constructor that allows to omit explicit package names when scripting Java:
</p>
<pre>
var SwingGui = JavaImporter(Packages.javax.swing,
Packages.javax.swing.event,
Packages.javax.swing.border,
java.awt.event,
java.awt.Point,
java.awt.Rectangle,
java.awt.Dimension);
...
with (SwingGui) {
var mybutton = new JButton(test);
var mypoint = new Point(10, 10);
var myframe = new JFrame();
...
}
</pre>
<p>
Previously such functionality was available only to embeddings that used <a href="apidocs/org/mozilla/javascript/ImporterTopLevel.html"><tt>org.mozilla.javascript.ImporterTopLevel</tt></a> class as the top level scope. The class provides additional <tt>importPackage()</tt> and <tt>importClass()</tt> global functions for scripts but their extensive usage has tendency to pollute the global name space with names of Java classes and prevents loaded classes from garbage collection.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=245882">Bugzilla 245882</a> for details.
</p>
<h4>Context customization API</h4>
<a href="apidocs/org/mozilla/javascript/ContextFactory.html"><tt>org.mozilla.javascript.ContextFactory</tt></a> provides new API for customization of <tt>org.mozilla.javascript.Context</tt> and ensures that application-specific Context subclasses will always be used when Rhino runtime needs to create Context instances.
</p>
<p>
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=255595">Bugzilla 245882</a> for details.
</p>
<h4>Support for Date.now()</h4>
<p>
<tt>Date.now()</tt> function which is a SpiderMonkey extension to ECMAScript standard is available now in Rhino. The function returns number of milliseconds passed since 1970-01-01 00:00:00 UTC.
</p>
<h4><a name="Rhino1.5R1-deprecation-removal"></a>Removal of deprecated classes</h4>
<p>
The following classes that were deprecated in Rhino 1.5R5 are no longer available in Rhino 1.6R1:
<ul>
<li><tt>org.mozilla.javascript.ClassNameHelper</tt></li>
<li><tt>org.mozilla.javascript.ClassRepository</tt></li>
</ul>
See documentation for <a href="apidocs/org/mozilla/javascript/optimizer/ClassCompiler.html"><tt>org.mozilla.javascript.optimizer.ClassCompiler</tt></a> that provides replacement for ClassNameHelper and ClassRepository.
</p>
<h2>Change logs for previous Rhino releases</h2>
<ul>
<li><a href="rhino15R5.html">Rhino 1.5R5</a></li>
<li><a href="rhino15R41.html">Rhino 1.5R4.1</a></li>
<li><a href="rhino15R4.html">Rhino 1.5R4</a></li>
<li><a href="rhino15R3.html">Rhino 1.5R3</a></li>
<li><a href="rhino15R2.html">Rhino 1.5R2</a></li>
<li><a href="rhino15R1.html">Rhino 1.5R1</a></li>
</ul>
<hr width="100%"><br>
<a href="index.html">back to top</a></h3>
</body></html>

View File

@@ -1,442 +0,0 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Author" content="Igor Bukanov">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Change Log</title>
<style>
P { text-align: justify; }
</style>
</head>
<body style="background-color: rgb(255, 255, 255);">
<h1 align="center">
Change Log for Rhino</h1>
<h2>Rhino 1.6R2, released 2005-09-19</h2>
<h3>Release overview</h3>
<p>
Rhino 1.6R2 is a new maintenance release of Rhino. New to Rhino 1.6Rx
is support for ECMAScript for XML (E4X). See <a href="rhino16R2.html">Change Log for Rhino 1.6R1</a>
for more details. </p>
<p>
This version of Rhino should be binary compatible with the current
embeddings that use only public <a href="apidocs/index.html">API</a>
unless the code use the previously deprected classes as documented <a href="#Rhino1.5R1-deprecation-removal">below</a>.
Please report any incompatibility issues to <a href="http://bugzilla.mozilla.org/enter_bug.cgi?product=Rhino">Bugzilla</a>.
</p>
<h3>Bugs marked fixed in Rhino 1.6R2 (<a href="https://bugzilla.mozilla.org/buglist.cgi?query_format=advanced&amp;short_desc_type=allwordssubstr&amp;short_desc=&amp;product=Rhino&amp;long_desc_type=substring&amp;long_desc=&amp;bug_file_loc_type=allwordssubstr&amp;bug_file_loc=&amp;status_whiteboard_type=allwordssubstr&amp;status_whiteboard=&amp;keywords_type=allwords&amp;keywords=&amp;resolution=FIXED&amp;emailassigned_to1=1&amp;emailtype1=exact&amp;email1=&amp;emailassigned_to2=1&amp;emailreporter2=1&amp;emailqa_contact2=1&amp;emailtype2=exact&amp;email2=&amp;bugidtype=include&amp;bug_id=&amp;votes=&amp;chfieldfrom=2004-11-29&amp;chfieldto=2005-08-21&amp;chfield=resolution&amp;chfieldvalue=FIXED&amp;cmdtype=doit&amp;order=Reuse+same+sort+as+last+time&amp;field0-0-0=noop&amp;type0-0-0=noop&amp;value0-0-0=">query</a>)</h3>
<table x:str="" style="border-collapse: collapse; table-layout: fixed; width: 378pt;" border="0" cellpadding="0" cellspacing="0" width="504">
<tbody>
<tr style="height: 12.75pt;" height="17">
<td class="xl24" style="height: 12.75pt; width: 48pt; font-weight: bold;" height="17" width="64">ID</td>
<td class="xl24" style="width: 330pt; font-weight: bold;" width="440">Summary</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=238649">238649</a></td>
<td class="xl25" style="width: 330pt;" width="440">Removal of deprecated features after 1.5R5</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=243057">243057</a></td>
<td class="xl25" style="width: 330pt;" width="440">enhancement - ability to assign to Java function
result a...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=252122">252122</a></td>
<td class="xl25" style="width: 330pt;" width="440">double expansion of error message</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=255595">255595</a></td>
<td class="xl25" style="width: 330pt;" width="440">Factory class for Context creation</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=258844">258844</a></td>
<td class="xl25" style="width: 330pt;" width="440">Continuation support in interpreter</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=264637">264637</a></td>
<td class="xl25" style="width: 330pt;" width="440">InterpretedFunction memory footprint could be
lighter</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=271401">271401</a></td>
<td class="xl25" style="width: 330pt;" width="440">JS prototypes for superclasses with
ScriptableObject.defi...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=274467">274467</a></td>
<td class="xl25" style="width: 330pt;" width="440">Add JavaScript stack trace to exceptions</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=274996">274996</a></td>
<td class="xl25" style="width: 330pt;" width="440">Exceptions with multiple interpreters on stack
may lead t...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=277537">277537</a></td>
<td class="xl25" style="width: 330pt;" width="440">isXMLName() should be properly implemented</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=277935">277935</a></td>
<td class="xl25" style="width: 330pt;" width="440">Assignments to descendants like "msg..s =
something" =&gt; f...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=278701">278701</a></td>
<td class="xl25" style="width: 330pt;" width="440">Minimised windows don't indicate that
breakpoints have be...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=280047">280047</a></td>
<td class="xl25" style="width: 330pt;" width="440">Not implementing Scriptable in Undefined</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=280629">280629</a></td>
<td class="xl25" style="width: 330pt;" width="440">When using the debugger within another program
the only w...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=281067">281067</a></td>
<td class="xl25" style="width: 330pt;" width="440">ThreadLocal in Context prevents class unloading</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=281247">281247</a></td>
<td class="xl25" style="width: 330pt;" width="440">JDK compatibility via special class</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=281537">281537</a></td>
<td class="xl25" style="width: 330pt;" width="440">ScriptRuntime.toNumber warns on Undefined</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=282447">282447</a></td>
<td class="xl25" style="width: 330pt;" width="440">NPE trying to report error when trying to
convert null to...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=282595">282595</a></td>
<td class="xl25" style="width: 330pt;" width="440">Patch for BeanProperties to work with several
setters for...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=286251">286251</a></td>
<td class="xl25" style="width: 330pt;" width="440">initFunction can be called twice</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=289294">289294</a></td>
<td class="xl25" style="width: 330pt;" width="440">Infinite loop during a script compilation</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=289603">289603</a></td>
<td class="xl25" style="width: 330pt;" width="440">Update rhino-n.tests to eliminate spidermonkey
only tests</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=290034">290034</a></td>
<td class="xl25" style="width: 330pt;" width="440">Cannot catch in JavaScript the original
exception thrown ...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=291591">291591</a></td>
<td class="xl25" style="width: 330pt;" width="440">Rhino has differing behaviour to spidermonkey,
and does n...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=292324">292324</a></td>
<td class="xl25" style="width: 330pt;" width="440">ArrayIndexOutOfBoundsException while compiling a
script</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=298786">298786</a></td>
<td class="xl25" style="width: 330pt;" width="440">Infinite loop when compiling with optimization</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=299539">299539</a></td>
<td class="xl25" style="width: 330pt;" width="440">Bad bytecode for function assignments</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=299613">299613</a></td>
<td class="xl25" style="width: 330pt;" width="440">Runtime support for function-results-as-lvalue</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=302501">302501</a></td>
<td class="xl25" style="width: 330pt;" width="440">constructor property shouldn't be readonly</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=303572">303572</a></td>
<td class="xl25" style="width: 330pt;" width="440">Need access to underlying RhinoException in
rethrown erro...</td>
</tr>
<tr>
<td><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=305323">305323</a></td>
<td>Rhino fails to select the appropriate overloaded method</td>
</tr>
<tr>
<td><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=305753">305753</a></td>
<td>&nbsp;NativeJavaMethod objects have incorrect parent when using...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=306258">306258</a></td>
<td class="xl25" style="width: 330pt;" width="440">Can not compile using Ant scripts under JDK 1.5</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=306268">306268</a></td>
<td class="xl25" style="width: 330pt;" width="440">Decompilation of E4X dot query is broken</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=306308">306308</a></td>
<td class="xl25" style="width: 330pt;" width="440">JS function as Java interface via reflect.Proxy</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=306419">306419</a></td>
<td class="xl25" style="width: 330pt;" width="440">Add serialVersionUID to Serializable</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=306584">306584</a></td>
<td class="xl25" style="width: 330pt;" width="440">Crashes parsing .jsp page with javascripts</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=303460">303460</a></td>
<td class="xl25" style="width: 330pt;" width="440">Enhance Rhino's shell to execute compiled script .class f...</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=306825">306825</a></td>
<td class="xl25" style="width: 330pt;" width="440">Allow to use shell.Global in servlets</td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td class="xl26" style="height: 12.75pt; width: 48pt; text-align: left;" x:num="" height="17" width="64"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=309029"></a>309029</td>
<td class="xl25" style="width: 330pt;" width="440">Exception when evaluating recursive function</td>
</tr>
</tbody>
</table>
<h2>Change logs for previous Rhino releases</h2>
<ul>
<li><a href="rhino16R1.html">Rhino 1.6R1</a></li>
<li><a href="rhino15R5.html">Rhino 1.5R5</a></li>
<li><a href="rhino15R41.html">Rhino 1.5R4.1</a></li>
<li><a href="rhino15R4.html">Rhino 1.5R4</a></li>
<li><a href="rhino15R3.html">Rhino 1.5R3</a></li>
<li><a href="rhino15R2.html">Rhino 1.5R2</a></li>
<li><a href="rhino15R1.html">Rhino 1.5R1</a></li>
</ul>
<hr width="100%"><br>
<a href="index.html">back to top</a>
</body>
</html>

View File

@@ -1,103 +0,0 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Author" content="Igor Bukanov">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Change Log</title>
<style>
P { text-align: justify; }
</style>
</head>
<body style="background-color: rgb(255, 255, 255);">
<h1 align="center">
Change Log for Rhino</h1>
<h2>Rhino 1.6R3, released 2006-07-24</h2>
<h3>Release overview</h3>
<p>
Rhino 1.6R3 is a new maintenance release of Rhino. New to Rhino 1.6Rx
is support for ECMAScript for XML (E4X). See <a href="rhino16R2.html">Change Log for Rhino 1.6R1</a>
for more details. </p>
<p>
This version of Rhino should be binary compatible with the current
embeddings that use only public <a href="apidocs/index.html">API</a>
unless the code use the previously deperected classes as documented <a href="#Rhino1.5R1-deprecation-removal">below</a>.
Please report any incompatibilitiy issues to <a href="http://bugzilla.mozilla.org/enter_bug.cgi?product=Rhino">Bugzilla</a>.
</p>
<h3>Bugs marked fixed in Rhino 1.6R3 (<a href="https://bugzilla.mozilla.org/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=&product=Rhino&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&status_whiteboard_type=allwordssubstr&status_whiteboard=&keywords_type=allwords&keywords=&resolution=FIXED&emailassigned_to1=1&emailtype1=exact&email1=&emailassigned_to2=1&emailreporter2=1&emailqa_contact2=1&emailtype2=exact&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=2005-08-22&chfieldto=2006-07-24&chfield=resolution&chfieldvalue=FIXED&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=">query</a>)</h3>
<h2>Change logs for previous Rhino releases</h2>
<ul>
<li><a href="rhino16R2.html">Rhino 1.6R2</a></li>
<li><a href="rhino16R1.html">Rhino 1.6R1</a></li>
<li><a href="rhino15R5.html">Rhino 1.5R5</a></li>
<li><a href="rhino15R41.html">Rhino 1.5R4.1</a></li>
<li><a href="rhino15R4.html">Rhino 1.5R4</a></li>
<li><a href="rhino15R3.html">Rhino 1.5R3</a></li>
<li><a href="rhino15R2.html">Rhino 1.5R2</a></li>
<li><a href="rhino15R1.html">Rhino 1.5R1</a></li>
</ul>
<hr width="100%"><br>
<a href="index.html">back to top</a>
</body>
</html>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -131,7 +97,7 @@ numeric identifiers. Conceptually, all accessors are converted to strings
in order to perform the lookup of the property in the object. However,
this is not the implementation used in practice because a number to string
conversion is too expensive to be performed on every array access.
<p>Instead, every property accessor method in <a href="apidocs/org/mozilla/javascript/Scriptable.html">Scriptable</a>
<p>Instead, every property accessor method in <a href="org/mozilla/javascript/Scriptable.html">Scriptable</a>
(<tt>has</tt>, <tt>get</tt>, <tt>set</tt>, <tt>remove</tt>, <tt>getAttributes</tt>,
and <tt>setAttributes</tt>) has overloaded forms that take either a <tt>String</tt>
or an <tt>int</tt> argument. It is the responsibility of the caller to
@@ -147,14 +113,14 @@ Defining Host Objects</h3>
Host objects are JavaScript objects that provide special access to the
host environment. For example, in a browser environment, the Window and
Document objects are host objects.
<p>The easiest way to define new host objects is by using <a href="apidocs/org/mozilla/javascript/ScriptableObject.html#defineClass(org.mozilla.javascript.Scriptable, java.lang.Class)">ScriptableObject.defineClass()</a>.
<p>The easiest way to define new host objects is by using <a href="org/mozilla/javascript/ScriptableObject.html#defineClass(org.mozilla.javascript.Scriptable, java.lang.Class)">ScriptableObject.defineClass()</a>.
This method defines a set of JavaScript objects using a Java class. Several
of the <a href="examples.html">examples</a> define host objects this way.
<p>If the services provided by defineClass are insufficient, try other
methods of
<a href="apidocs/org/mozilla/javascript/ScriptableObject.html">ScriptableObject</a>
<a href="org/mozilla/javascript/ScriptableObject.html">ScriptableObject</a>
and
<a href="apidocs/org/mozilla/javascript/FunctionObject.html">FunctionObject</a>,
<a href="org/mozilla/javascript/FunctionObject.html">FunctionObject</a>,
such as <tt>defineProperty</tt> and <tt>defineFunctionProperties</tt>.
<br>&nbsp;
<br>&nbsp;

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -73,13 +39,9 @@ the execution environment. There should be one and only one Context associated
with each thread that will be executing JavaScript.
<p>To associate the current thread with a Context, simply call the <tt>enter</tt>
method of Context: </p>
<pre>
Context cx = Context.enter();
</pre>
<pre>&nbsp;&nbsp;&nbsp; Context cx = Context.enter();</pre>
Once you are done with execution, simply exit the Context:
<pre>
Context.exit();
</pre>
<pre>&nbsp;&nbsp;&nbsp; Context.exit();</pre>
These calls will work properly even if there is already a Context associated
with the current thread. That context will be returned and an internal counter
incremented. Only when the counter reaches zero will it be disassociated from
@@ -103,9 +65,7 @@ the scripts are responsible for coordinating any accesses to shared variables.
</p>
<p>A top-level scope is created by calling <tt>Context.initStandardObjects</tt>
to create all the standard objects: </p>
<pre>
ScriptableObject scope = cx.initStandardObjects();
</pre>
<pre>&nbsp;&nbsp;&nbsp; Scriptable scope = cx.initStandardObjects(null);</pre>
The easiest way to embed Rhino is just to create a new scope this way whenever
you need one. However, <tt>initStandardObjects</tt> is an expensive method
to call and it allocates a fair amount of memory. We'll see below that there
@@ -148,8 +108,9 @@ for the variable <tt>g</tt> and the function <tt>f</tt>.
traversed looking for a 'x' property. When none is found, a new property 'x'
is created in the top-level scope. </p>
<h2> Sharing Scopes</h2>
JavaScript is a language that uses delegation rather than traditional class-based inheritance. This is a large topic in itself, but for our purposes it gives us an easy way to share a set of read-only variables across multiple scopes.
JavaScript is a language that uses delegation rather than traditional class-based
inheritance. This is a large topic in itself, but for our purposes it gives
us an easy way to share a set of read-only variables across multiple scopes.
To do this we set an object's prototype. When accessing a property of an object
in JavaScript, the object is first searched for a property with the given
name. If none is found, the object's prototype is searched. This continues
@@ -159,12 +120,9 @@ we wish to share. Typically this object will have been created with <tt>initStan
and may also have additional objects specific to the embedding. Then all
we need to do is create a new object and call its <tt>setPrototype</tt> method
to set the prototype to the shared object, and the parent of the new scope
to null:
<pre> Scriptable newScope = cx.newObject(sharedScope);
newScope.setPrototype(sharedScope);
newScope.setParentScope(null);
</pre>
The call to <tt>newObject</tt> simply creates a new JavaScript object with
to null: </p>
<pre>&nbsp;&nbsp;&nbsp; Scriptable newScope = cx.newObject(sharedScope);<br>&nbsp;&nbsp;&nbsp; newScope.setPrototype(sharedScope);<br>&nbsp;&nbsp;&nbsp; newScope.setParentScope(null);<br></pre>
The call to <tt>newObject</tt> simply creates a new JavaScript object with
no properties. It uses the <tt>sharedScope</tt> passed in to initialize the
prototype with the standard <tt>Object.prototype</tt> value.
<p>We can now use <tt>newScope</tt> as a scope for calls to evaluate scripts.
@@ -176,24 +134,15 @@ instance scopes can be defined and have their own variables for scripts yet
share the definitions in the shared scope. These multiple instance scopes
can be used concurrently. <br>
&nbsp; </p>
<h2>Sealed shared scopes</h2>
<p>The ECMAScript standard defines that scripts can add properties to all standard library objects and in many cases it is also possible to change or delete their properties as well. Such behavior may not be suitable with shared scopes since if a script by mistake adds a property to a library object from the shared scope, that object would not be garbage collected until there re active references to the shared scope potentially leading to memory leaks. In addition if a script alters some of the standard objects, the library may not work properly for other scripts. Such bugs are hard to debug and to remove a possibility for them to occur one can use seal the shared scope and all its objects.
<p>
A notion of a sealed object is a JavaScript extension supported by Rhino and it means that properties can not be added/deleted to the object and the existing object properties can not be changed. Any attempt to modify sealed object throws an exception. To seal all objects in the standard library pass <tt>true</tt> for the sealed argument when calling <tt>Context.initStandardObjects(ScriptableObject, boolean)</tt>:
<pre> ScriptableObject sealedSharedScope = cx.initStandardObjects(null, true);</pre>
This seals only all standard library objects, it does not seal the shared scope itself thus after calling <tt>initStandardObjects</tt>, <tt>sealedSharedScope</tt> cab be farther populated with application-specific objects and functions. Then after a custom initialization is done, one can seal the shared scope by calling <tt>ScriptableObject.sealObject()</tt>:
<pre> sealedSharedScope.sealObject();</pre>
Note that currently one needs to explicitly seal any additional properties he adds to the sealed shared scope since although after calling <tt>sealedSharedScope.sealObject();</tt> it would no be possible to set the additional properties to different values, one still would be able to alter the objects themselves.
<h2> Dynamic Scopes</h2>
There's one problem with the setup outlined above. Calls to functions in
JavaScript use <i>static scope</i>, which means that variables are first looked
up in the function and then, if not found there, in the lexically enclosing
scope. This causes problems if functions you define in your shared scope
need access to variables you define in your instance scope.
<p>With Rhino 1.6, it is possible to use <i>dynamic scope</i>. With dynamic scope, functions look at the top-level scope of the currently executed script
rather than their lexical scope. So we can store information
<p>With Rhino 1.5, it is possible to compile functions to use <i>dynamic
scope</i>. With dynamic scope, functions look at the top-level scope of the
calling function rather than their lexical scope. So we can store information
that varies across scopes in the instance scope yet still share functions
that manipulate that information reside in the shared scope. </p>
<p>The <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/DynamicScopes.java">

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -42,12 +8,21 @@
<title>Scripting Java</title>
</head>
<body bgcolor="#FFFFFF">
<script src="owner.js"></script>
<center>
<h1>
Scripting Java</h1>
<p>Norris Boyd</p>
</center>
Scripting Java</h1></center>
<script>document.write(owner());</script>
<br><script>
var d = new Date(document.lastModified);
document.write((d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear());
document.write('<br>');
</script>
<center>
<hr WIDTH="100%"></center>
<p>It's possible to use Rhino just for scripting Java. You don't have to
write any additional Java code; just use the existing Rhino shell and then
@@ -61,7 +36,7 @@ a command line.
file, <tt>js.jar</tt>. If you add the JAR file to your class path, you
can start the Rhino shell using the command
<pre>&nbsp;&nbsp;&nbsp; java org.mozilla.javascript.tools.shell.Main</pre>
or if you have Java 2 (JDK 1.2 or greater), you can avoid changing your classpath
or if you have Java 2 (JDK 1.2), you can avoid changing your classpath
and simply use the command
<pre>&nbsp;&nbsp;&nbsp; java -jar js.jar</pre>
Unfortunately the <tt>-jar</tt> option to <tt>java</tt> will overwrite
@@ -104,7 +79,7 @@ If you wish to load classes from JavaScript that aren't in the <tt>java</tt>
package, you'll need to prefix the package name with "<tt>Packages.</tt>".
For example:
<pre>$ java org.mozilla.javascript.tools.shell.Main
js> cx = Packages.org.mozilla.javascript.Context.currentContext
js> cx = Packages.org.mozilla.javascript.Context.enter()
org.mozilla.javascript.Context@25980b44
js> cx.evaluateString(this, "3+2", null, 0, null)
5.0
@@ -192,27 +167,7 @@ When we type <tt>buttonListener = java.awt.event.ActionListener(o)</tt>,
Rhino actually creates a new Java class that implements <tt>ActionListener</tt>
and forwards calls from that class to the JavaScript object. So when you
click on the button, the <tt>printDate</tt> method is called.
<p>
Starting from the release 1.5R5 Rhino allows to pass JavaScript functions directly to Java methods if the corresponding argument is Java interface and it either has the single method or all its methods has the same number of arguments and corresponding arguments has the same types. It allows to pass <tt>printDate</tt> directly to <tt>addActionListener</tt> and simplifies example:
<pre>$ java org.mozilla.javascript.tools.shell.Main
js> importPackage(java.awt);
js> frame = new Frame("JavaScript")
java.awt.Frame[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,title=JavaScript,resizable,normal]
js> button = new Button("OK")
java.awt.Button[button0,0,0,0x0,invalid,label=OK]
js> frame.setSize(new Dimension(200,100))
js> frame.add(button)
java.awt.Button[button0,0,0,0x0,invalid,label=OK]
js> frame.show()
js> function printDate() { print(new Date()) }
js> printDate()
Mon Oct 27 2003 10:35:44 GMT+0100 (CET)
js> button.addActionListener(printDate)
js> Mon Oct 27 2003 10:36:09 GMT+0100 (CET)
Mon Oct 27 2003 10:36:10 GMT+0100 (CET)
quit()
$</pre>
<br>&nbsp;
<h2>
JavaAdapter constructor</h2>
Another way to create a JavaAdapter is to call the JavaAdapter constructor

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -49,42 +15,24 @@ The JavaScript shell provides a simple way to run scripts in batch mode
or an interactive environment for exploratory programming.
<h2>
Invoking the Shell</h2>
<tt>java org.mozilla.javascript.tools.shell.Main [<i>options</i>]
<i>script-filename-or-url</i> [<i>script-arguments</i>]</tt>
<p>where <tt><i>options</i></tt> are:
<p>
<tt>-e <i>script-source</i></tt>
<tt>java org.mozilla.javascript.tools.shell.Main</tt> [<i>options</i>]
<i>file</i><tt>.js
[<i>script-arguments</i>]</tt>
<p>where <i>options</i> are:
<p><tt>-e </tt><i>script-source</i>
<blockquote>Executes <i>script-source</i> as a JavaScript script.</blockquote>
<tt>-f <i>script-filename-or-url</i></tt>
<blockquote>Reads <i>script-filename-or-url</i> content and execute it as a JavaScript script.</blockquote>
<tt>-opt <i>optLevel</i></tt>
<br><tt>-O <i>optLevel</i></tt>
<blockquote>
Optimizes at level <i>optLevel</i>, which must be an integer between
0 and 9. See <a href="opt.html">Optimization</a> for more details.
</blockquote>
<tt>-version <i>versionNumber</i></tt>
<blockquote>
Specifies the language version to compile with. The string <i>versionNumber</i>
<tt>-f </tt><i>script-filename</i>
<blockquote>Reads filename specified by <i>script-filename</i> and executes
it as a JavaScript script.</blockquote>
<tt>-opt </tt><i>optLevel</i>
<br><tt>-O</tt> <i>optLevel</i>
<ul>Optimizes at level <i>optLevel</i>, which must be an integer between
0 and 9. See <a href="opt.html">Optimization</a> for more details.</ul>
<tt>-version </tt><i>versionNumber</i>
<ul>Specifies the language version to compile with. The string <i>versionNumber</i>
must be one of <tt>100</tt>, <tt>110</tt>, <tt>120</tt>, <tt>130</tt>,
or <tt>140</tt>. See <a href="overview.html#versions">JavaScript Language
Versions</a> for more information on language versions.
</blockquote>
<tt>-strict</tt>
<blockquote>
Enable strict mode.
</blockquote>
<tt>-continuations</tt>
<blockquote>
Enable experiments support for continuations and set the optimization level to -1 to force interpretation mode.
</blockquote>
If the shell is invoked with the system property rhino.use_java_policy_security set to true and with a security manager installed, the shell restricts scripts permissions based on their URLs according to Java policy settings. This is available only if JVM implements Java2 security model.
Versions</a> for more information on language versions.</ul>
<h2>
Predefined Properties</h2>
@@ -109,11 +57,6 @@ defineClass(<i>className</i>)</h4>
argument <i>className</i>. Uses ScriptableObject.defineClass() to define
the extension.</blockquote>
<h4>
deserialize(<i>filename</i>)</h4>
<blockquote>Restore from the specified file an object previously written by a call to <tt>serialize</tt>.</blockquote>
<h4>
load([<i>filename</i>, ...])</h4>
@@ -133,44 +76,6 @@ print([<i>expr</i> ...])</h4>
<blockquote>Evaluate and print expressions. Evaluates each expression,
converts the result to a string, and prints it.</blockquote>
<h4>
readFile(<i>path</i> [, <i>characterCoding</i>)</h4>
<blockquote>Read given file and convert its bytes to a string using the
specified character coding or default character coding if explicit coding
argument is not given.</blockquote>
<h4>
readUrl(<i>url</i> [, <i>characterCoding</i>)</h4>
<blockquote>Open an input connection to the given string url, read all its
bytes and convert them to a string using the specified character coding or
default character coding if explicit coding argument is not given.</blockquote>
<h4>
runCommand(<i>commandName</i>, [<i>arg</i>, ...] [<i>options</i>])</h4>
<blockquote>Execute the specified command with the given argument and options
as a separate process and return the exit status of the process. For details, see JavaDoc for <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/toolsrc/org/mozilla/javascript/tools/shell/Global.java">org.mozilla.javascript.tools.shell.Global#runCommand</a>.</blockquote>
<h4>
seal(<i>object</i>)</h4>
<blockquote>Seal the specified object so any attempt to add, delete or modify its properties would throw an exception.</blockquote>
<h4>
serialize(<i>object</i>, <i>filename</i>)</h4>
<blockquote>Serialize the given object to the specified file.</blockquote>
<h4>
spawn(<i>functionOrScript</i>)</h4>
<blockquote>Run the given function or script in a different thread.</blockquote>
<h4>
sync(<i>function</i>)</h4>
<blockquote>creates a synchronized function (in the sense of a Java synchronized method) from an existing function. The new function synchronizes on the <code>this</code> object of its invocation.</blockquote>
<h4>
quit()</h4>
@@ -188,120 +93,35 @@ respectively.</blockquote>
<h2>
Example</h2>
<h4>Invocation</h4>
Here the shell is invoked three times from the command line. (The system
command prompt is shown as <tt>$</tt>.) The first invocation executes a
script specified on the command line itself. The next invocation has no
arguments, so the shell goes into interactive mode, reading and evaluating
each line as it is typed in. Finally, the last invocation executes a script
from a file and accesses arguments to the script itself.
<pre>
$ java org.mozilla.javascript.tools.shell.Main -e print('hi')
hi
$ java org.mozilla.javascript.tools.shell.Main
js> print('hi')
hi
js> 6*7
42
js> function f() {
return a;
}
js> var a = 34;
js> f()
34
js> quit()
$ cat echo.js
for (i in arguments) {
print(arguments[i])
}
$ java org.mozilla.javascript.tools.shell.Main echo.js foo bar
foo
bar
$
</pre>
<h4>spawn and sync</h4>
The following example creates 2 threads via <tt>spawn</tt> and uses <tt>sync</tt> to create a synchronized version of the function <tt>test</tt>.
<pre>
js> function test(x) {
print("entry");
java.lang.Thread.sleep(x*1000);
print("exit");
}
js> var o = { f : sync(test) };
js> spawn(function() {o.f(5);});
Thread[Thread-0,5,main]
entry
js> spawn(function() {o.f(5);});
Thread[Thread-1,5,main]
js>
exit
entry
exit
</pre>
<h4>runCommand</h4>
Here is few examples of invoking <tt>runCommand</tt> under Linux.
<pre>
js> runCommand('date')
Thu Jan 23 16:49:36 CET 2003
0
// Using input option to provide process input
js> runCommand("sort", {input: "c\na\nb"})
a
b
c
0
js> // Demo of output and err options
js> var opt={input: "c\na\nb", output: 'Sort Output:\n'}
js> runCommand("sort", opt)
0
js> print(opt.output)
Sort Output:
a
b
c
js> var opt={input: "c\na\nb", output: 'Sort Output:\n', err: ''}
js> runCommand("sort", "--bad-arg", opt)
2
js> print(opt.err)
/bin/sort: unrecognized option `--bad-arg'
Try `/bin/sort --help' for more information.
js> runCommand("bad_command", "--bad-arg", opt)
js: "<stdin>", line 18: uncaught JavaScript exception: java.io.IOException: bad_command: not found
js> // Passing explicit environment to the system shell
js> runCommand("sh", "-c", "echo $env1 $env2", { env: {env1: 100, env2: 200}})
100 200
0
js> // Use args option to provide additional command arguments
js> var arg_array = [1, 2, 3, 4];
js> runCommand("echo", { args: arg_array})
1 2 3 4
0
</pre>
<p><tt>$ java org.mozilla.javascript.tools.shell.Main -e print('hi')</tt>
<p><tt>hi</tt>
<p><tt>$ java org.mozilla.javascript.tools.shell.Main</tt>
<p><tt>js> print('hi')</tt>
<br><tt>hi</tt>
<br><tt>js> 6*7</tt>
<br><tt>42</tt>
<br><tt>js> function f() {</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return a;</tt>
<br><tt>}</tt>
<br><tt>js> var a = 34;</tt>
<br><tt>js> f()</tt>
<br><tt>34</tt>
<br><tt>js> quit()</tt>
<p><tt>$ cat echo.js</tt>
<br><tt>for (i in arguments) {</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(arguments[i])</tt>
<br><tt>}</tt>
<br><tt>$ java org.mozilla.javascript.tools.shell.Main echo.js foo bar</tt>
<p><tt>foo</tt>
<br><tt>bar</tt>
<p><tt>$</tt>
<p>
Examples for Windows are similar:
<pre>
js> // Invoke shell command
js> runCommand("cmd", "/C", "date /T")
27.08.2005
0
js> // Run sort collectiong the output
js> var opt={input: "c\na\nb", output: 'Sort Output:\n'}
js> runCommand("sort", opt)
0
js> print(opt.output)
Sort Output:
a
b
c
js> // Invoke notepad and wait until it exits
js> runCommand("notepad")
0
</pre>
<hr WIDTH="100%">
<br><a href="index.html">back to top</a>
</body>

View File

@@ -0,0 +1,31 @@
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.7 [en]C-NSCP (WinNT; U) [Netscape]">
<title>JavaScript Tools</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<h1>
JavaScript Tools</h1></center>
<h2>
JavaScript shell</h2>
The <a href="shell.html">JavaScript shell</a> allows for interactive and
batch execution of JavaScript scripts.
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<h2>
JavaScript compiler</h2>
The <a href="jsc.html">JavaScript compiler</a> translates JavaScript source
into Java class files.
<br>&nbsp;
<p>
<hr WIDTH="100%">
<br><a href="index.html">back to top</a>
</body>
</html>

View File

@@ -1,37 +1,3 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
@@ -144,7 +110,7 @@ example</a>. All it does it read a script from the command line, execute
it, and print a result.
<p>Here's an example use of RunScript from a shell command line:
<blockquote>
<pre><font color="#663366">$ java RunScript "Math.cos(Math.PI)"
<pre><font color="#663366">$ java RunScript 'Math.cos(Math.PI)'
-1
$ java RunScript 'function f(x){return x+1} f(7)'
8</font></pre>
@@ -163,7 +129,7 @@ about the execution environment of a script.
<p><a NAME="initializing"></a><font size=+2>Initializing standard objects</font>
<p>The code
<blockquote>
<pre><font color="#006600">Scriptable scope = cx.initStandardObjects();</font></pre>
<pre><font color="#006600">Scriptable scope = cx.initStandardObjects(null);</font></pre>
</blockquote>
Initializes the standard objects (<tt>Object</tt>,
<tt>Function</tt>, etc.)
@@ -173,14 +139,10 @@ that we use in later calls.
<p><a NAME="Collecting"></a><font size=+2>Collecting the arguments</font>
<p>This code is standard Java and not specific to Rhino. It just collects
all the arguments and concatenates them together.
<blockquote>
<pre style="color: #006600">
String s = "";
for (int i=0; i &lt; args.length; i++) {
s += args[i];
}
</pre>
</blockquote>
<blockquote><tt><font color="#006600">String s = "";</font></tt>
<br><tt><font color="#006600">for (int i=0; i &lt; args.length; i++)</font></tt>
<br><tt><font color="#006600">&nbsp;&nbsp;&nbsp; s += args[i];</font></tt></blockquote>
<p><br><a NAME="Evaluating"></a><font size=+2>Evaluating a script</font>
<p>The code
<blockquote>
@@ -204,15 +166,11 @@ method converts any JavaScript value to a string.
<p><a NAME="Exit"></a><font size=+2>Exit the Context</font>
<p>The code
<blockquote>
<pre style="color: #006600">
} finally {
Context.exit();
}
</pre>
<pre><font color="#006600">Context.exit();</font></pre>
</blockquote>
exits the Context. This removes the association between the Context and
the current thread and is an essential cleanup action. There should be
a call to <tt>exit</tt> for every call to <tt>enter</tt>. To make sure that it is called even if an exception is thrown, it is put into the finally block corresponding to the try block starting after <tt>Context.enter()</tt>.
a call to <tt>exit</tt> for every call to <tt>enter</tt>.
<br>&nbsp;
<dir>&nbsp;</dir>
<a NAME="Expose"></a><font size=+3>Expose Java APIs</font>
@@ -244,8 +202,9 @@ hi</font></pre>
<p>The next example is <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript2.java">RunScript2</a>.
This is the same as RunScript, but with the addition of two extra lines
of code:
<dir><tt><font color="#006600">Object wrappedOut = Context.javaToJS(System.out, scope);</font></tt>
<br><tt><font color="#006600">ScriptableObject.putProperty(scope, "out", wrappedOut);</font></tt></dir>
<dir><tt><font color="#006600">Scriptable jsArgs = Context.toObject(System.out,
scope);</font></tt>
<br><tt><font color="#006600">scope.put("out", scope, jsArgs);</font></tt></dir>
These lines add a global variable <tt>out</tt> that is a JavaScript reflection
of the <tt>System.out</tt> variable:
<dir><tt><font color="#663366">$ java RunScript2 'out.println(42)'</font></tt>
@@ -260,45 +219,40 @@ is illustrated in the <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/ex
example. This example adds the ability to print the value of variable <tt>x</tt>
and the result of calling function <tt>f</tt>. Both <tt>x</tt> and <tt>f</tt>
are expected to be defined by the evaluated script. For example,
<blockquote>
<pre style="color: #663366">
$ java RunScript3 'x = 7'
x = 7
f is undefined or not a function.
$ java RunScript3 'function f(a) { return a; }'
x is not defined.
f('my args') = my arg
</pre>
</blockquote>
<blockquote><tt><font color="#663366">$ java RunScript3 'x = 7'</font></tt>
<br><tt><font color="#663366">x = 7</font></tt>
<br><tt><font color="#663366">f is undefined or not a function.</font></tt>
<br><tt><font color="#663366">$ java RunScript3 'function f(a) { return
a; }'</font></tt>
<br><tt><font color="#663366">x is not defined.</font></tt>
<br><tt><font color="#663366">f('my args') = my arg</font></tt>
<br><tt><font color="#663366"></font></tt>&nbsp;</blockquote>
<a NAME="UsingJSvars"></a><font size=+2>Using JavaScript variables</font>
<p>To print out the value of <tt>x</tt>, we add the following code.
<blockquote>
<pre style="color: #006600">
Object x = scope.get("x", scope);
if (x == Scriptable.NOT_FOUND) {
System.out.println("x is not defined.");
} else {
System.out.println("x = " + Context.toString(x));
}
</pre>
</blockquote>
<dir><tt><font color="#006600">Object x = scope.get("x", scope);</font></tt>
<br><tt><font color="#006600">if (x == Scriptable.NOT_FOUND)</font></tt>
<br><tt><font color="#006600">&nbsp;&nbsp;&nbsp; System.out.println("x
is not defined.");</font></tt>
<br><tt><font color="#006600">else</font></tt>
<br><tt><font color="#006600">&nbsp;&nbsp;&nbsp; System.out.println("x
= " + Context.toString(x));</font></tt>
<br><tt><font color="#006600"></font></tt>&nbsp;</dir>
<a NAME="CallingJSfuns"></a><font size=+2>Calling JavaScript functions</font>
<p>To get the function <tt>f</tt>, call it, and print the result, we add
this code:
<blockquote>
<pre style="color: #006600">
Object fObj = scope.get("f", scope);
if (!(fObj instanceof Function)) {
System.out.println("f is undefined or not a function.");
} else {
Object functionArgs[] = { "my arg" };
Function f = (Function)fObj;
Object result = f.call(cx, scope, scope, functionArgs);
String report = "f('my args') = " + Context.toString(result);
System.out.println(report);
}
</pre>
</blockquote>
<dir><tt><font color="#006600">Object f = scope.get("f", scope);</font></tt>
<br><tt><font color="#006600">if (!(f instanceof Function))</font></tt>
<br><tt><font color="#006600">&nbsp;&nbsp;&nbsp; System.out.println("f
is undefined or not a function.");</font></tt>
<br><tt><font color="#006600">else {</font></tt>
<br><tt><font color="#006600">&nbsp;&nbsp;&nbsp; Object functionArgs[]
= { "my arg" };</font></tt>
<br><tt><font color="#006600">&nbsp;&nbsp;&nbsp; Object result = ((Function)
f).call(cx, scope, scope, functionArgs);</font></tt>
<br><tt><font color="#006600">&nbsp;&nbsp;&nbsp; System.out.println("f('my
args') = " + Context.toString(result));</font></tt>
<br><tt><font color="#006600">}</font></tt></dir>
<p><br><a NAME="JavaScriptHostObjects"></a><font size=+3>JavaScript host
objects</font>
<p><a NAME="DefiningHostObjects"></a><font size=+2>Defining Host Objects</font>
@@ -313,8 +267,7 @@ built-in <tt>defineClass</tt> function. We'll see how to add it to RunScript
later. (Note that because the <tt>java -jar</tt> option preempts the rest
of the classpath, we can't use that and access the <tt>Counter</tt> class.)
<blockquote>
<pre style="color: #663366">
$ java -cp 'js.jar;examples' org.mozilla.javascript.tools.shell.Main
<pre><font color="#663366">$ java -cp 'js.jar;examples' org.mozilla.javascript.tools.shell.Main
js> defineClass("Counter")
js> c = new Counter(7)
[object Counter]
@@ -326,8 +279,7 @@ js> c.count
9
js> c.resetCount()
js> c.count
0
</pre>
0</font></pre>
</blockquote>
<a NAME="CounterCtors"></a><font size=+2>Counter's constructors</font>
<p>The zero-argument constructor is used by Rhino runtime to create instances.
@@ -371,20 +323,14 @@ c.count;'</font></tt>
It also creates a new instance of the <tt>Counter</tt> object from within
our Java code, constructing it with the value 7, and assigning it to the
top-level variable <tt>myCounter</tt>:
<blockquote>
<pre style="color: #006600">
Object[] arg = { new Integer(7) };
Scriptable myCounter = cx.newObject(scope, "Counter", arg);
scope.put("myCounter", scope, myCounter);
</pre>
</blockquote>
<dir><tt><font color="#006600">Object[] arg = { new Integer(7) };</font></tt>
<br><tt><font color="#006600">Scriptable myCounter = cx.newObject(scope,
"Counter", arg);</font></tt>
<br><tt><font color="#006600">scope.put("myCounter", scope, myCounter);</font></tt></dir>
Now we can reference the <tt>myCounter</tt> object from our script:
<blockquote>
<pre style="color: #663366">
$ java RunScript3 'RunScript4 'myCounter.count; myCounter.count'
8
</pre>
</blockquote>
<dir><tt><font color="#663366">$ java RunScript3 'RunScript4 'myCounter.count;
myCounter.count'</font></tt>
<br><tt><font color="#663366">8</font></tt></dir>
</body>
</html>

View File

@@ -16,8 +16,8 @@ How are people using Rhino?</h1></center>
Here's a partial list of the ways people are using Rhino in their projects.
The initial list was collected by Netscape marketing, so Rhino is referred
to as Netscape Java-based JavaScript. We'd love to hear how you're using
Rhino--just mail&nbsp;<script>document.write(owner());</script>.
Rhino--just mail&nbsp;<script>document.write(owner());</script>
.
<p><a href="http://www.attachmate.com">Attachmate</a>
<br>"Netscape JavaScript 1.5 with Java implementation was a perfect solution
for developing our MacroRecorder because it made our development process
@@ -29,11 +29,6 @@ thin clients, called e-Vantage Viewers. The Netscape Java-based JavaScript
interpreter is used in a MacroRecorder feature that allows browser-based
users to efficiently navigate host applications on mainframe and midrange
systems.
<p><a href="http://www.avivasolutions.com/">Aviva Solutions</a>
<br>
Aviva for Java is a mainframe connectivity product. To overcome the limitations of the arcane mainframe user interface, it is customary to provide scripting capabilities in such products, so that repetitive user actions can be automated. Aviva for Java is a Java applet. As such, its size, security and compatibility requirements are strict. Rhino has been found to be the perfect scripting engine: pure Java, works perfectly in an applet environment, regardless of the VM vendor or version, it is light and in the same time very powerful. JavaScript as the scripting language makes perfect sense in a browser environment.
<p><a href="http://www.bristowhill.com/">Bristow Hill Software</a>
<br>"We thought it would require lots of work to add scripting capability
to Bristow Hill Server Pages, but we were delighted to find that Netscape
@@ -44,55 +39,23 @@ and compile it down to Java classes which could be used directly for greater
speed in production. Netscape's JavaScript engine is rock solid and standards
compliant, and my only regret is that we didn't start using it sooner,"
said Don Anderson, President of Bristow Hill Software.
<p><a href="http://www.celcorp.com/webrecorder.html">Celware WebRecorder</a>
<br>WebRecorder allows developers and analysts to quickly and easily automate Web navigation and data extraction from Web pages. Users can model and parameterize navigations and extractions, then wrap them in business processes for execution from a client application. Scripting via Rhino allows users to create the business logic in these processes. It also allows their processes to integrate Web access with any other kind of system or data the Java platform can reach.
<p><a href="http://www.discoverymachine.com">Discovery Machine</a>
<br>Discovery Machine's Expertise Encoding and Execution Workshop (E3W) allows experts to easily and seamlessly encode their knowledge and processes into immediately usable, executable graphical software that can then be shared, modified, and leveraged. In this environment, knowledge engineers can work with subject-matter experts as well as software engineers to develop models of expertise. At all points in the process, experts can understand and modify the models, even when models are fully operational. We were easily able to embed Rhino and immediately extend our language with Rhino's high-quality JavaScript interpreter.
<p><a href="http://httpunit.sourceforge.net/">HttpUnit</a>
<br>"Automated testing is a great way to ensure that code being maintained works. The Extreme Programming (XP) methodology relies heavily on it, and practitioners have available to them a range of testing frameworks, most of which work by making direct calls to the code being tested. But what if you want to test a web application? Or what if you simply want to use a web-site as part of a distributed application?
<p>
In either case, you need to be able to bypass the browser and access your site from a program. HttpUnit makes this easy. Written in Java, HttpUnit emulates the relevant portions of browser behavior, including form submission, JavaScript, basic http authentication, cookies and automatic page redirection, and allows Java test code to examine returned pages either as text, an XML DOM, or containers of forms, tables, and links. When combined with a framework such as JUnit, it is fairly easy to write tests that very quickly verify the functioning of a web site."
<p><a href="http://htmlunit.sourceforge.net/">HtmlUnit</a>
<br> HtmlUnit is a java unit testing framework for testing web based applications. </br>
<p><a href="http://www.icesoft.com/">ICEsoft Technologies</a>
<br>ICEsoft Technologies adds JavaScript support to their browser products using Rhino.
<p><a href="http://sourceforge.net/projects/jscorba">JS/CORBA Adapter</a>
<br>The JS/CORBA Adapter provides a mechanism for arbitrary Javascript objects to interact with each other transparently in a distributed Javascript system using CORBA.
<p><a href="http://www.lombardisoftware.com">Lombardi Software</a>
<br>Lombardi Software's TeamWorks BPM platform uses Rhino for all
embedded scripting.
<p><a href="http://www.magoosoft.com">Magoo Software</a>
<br>"We've just released version 1.5 of MagooClient, an XML messaging client, with Rhino inside. The availability of Rhino 1.6R1 with E4X marks a significant breakthrough in the way that people work with XML content. Instead of merely editing, users can add their own custom logic to perform calculations, implement validation rules that test relationships between elements and crucially, add callouts to external Web Services to populate XML documents. There have been several attempts at this type of rich XML client in the past but none offer the familiarity, simplicity and adherence to standards offered by Rhino/JavaScript/E4X." -- John McGuire, CTO Magoo Software.
<p><a href="http://homepage.mac.com/pcbeard/JShell/">JShell</a>
<p><a href="http://www.icesoft.no/">ICEsoft</a>
<br>ICEsoft adds JavaScript support to their <a href="http://www.icesoft.no/ICEBrowser/">ICE
Browser</a> using Rhino.
<p><a href="http://www.vmeng.com/beard/JShell/Release_Notes.html">JShell</a>
<br>Rhino is used as the scripting language for the open source command
shell JShell written by Patrick Beard.
<p><a href="http://www.runitsoft.com/">RUnit Software</a>
<br>RUnit Software uses Rhino as part of
solutions for business-process automation, for example
when the automation involves communicating with a
web-interface.
<p><a href="http://www.seppia.org/">Seppia</a>
<br>"Seppia is a simple technology to build and deploy any Java application.
It gains from the synergy of Java and JavaScript and a minimum set of clear
rules to organize their interaction. Seppia allows developers to create
stand-alone applications from constituent parts.
Each part is a module: a unit of function integrating seamlessly JavaScript
files, jar files and other resources.
Seppia uses Mozilla Rhino to empower its JavaScript engine.
Seppia will challenge the way you think of Java-based component computing."
<p><a href="http://www.softcom.com">Softcom</a>
<br>The tight integration of Netscape's Java-based JavaScript 1.5 with
Softcom's Java-based RealPlayer plugin, RJ, enables Softcom to quickly
produce dynamic interactive video applications for our media/entertainment,
retail and professional education clients, helping us to synchronize the
full interactivity of the Web and e-commerce with streaming video, said
Chris O'Brien, president and COO of Softcom. For the enhanced Oscarcast
recently produced for E! Online during the Academy Awards, Softcom used
RJ to embed Netscape's JavaScript 1.5 in the RealPlayer, successfully integrating
interactive chat and Java games, along with streaming video, within the
RealPlayer.
<p><a href="http://www.tdiinc.com/">Technology Deployment International</a>
<br>"Technology Deployment International selected the Java-based Netscape
JavaScript engine to incorporate into the workflow module of our eBusiness
@@ -101,12 +64,6 @@ into any workstep of their application," said Dr. Kelvin Liu, VP eBMS Developmen
Technology Deployment International. "It has been easy to embed, the support
we received from the engineering team has been outstanding, and the performance
of the JavaScript code is almost identical to the equivalent Java."
<p><a href="http://www.xmoon.org">XMoon</a>
<br>XMoon is a dynamic OO (Object Oriented) opensource extension released under LGPL License for Jakarta Struts, powerful and easy to use.
XMoon lets you develop business logic classes following a fully Java compatible scripting language allowing execution of Java code at runtime without any access to a compiler.
<p><a href="http://www.xypoint.com/">XYPOINT</a>
<br>XYPOINT uses Rhino for automating test cases of their Java classes
used in their service <a href="http://www.webwirelessnow.com/">WebWirelessNow</a>.

View File

@@ -1,39 +1,36 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.*;
@@ -41,7 +38,7 @@ import org.mozilla.javascript.*;
* Example of controlling the JavaScript execution engine.
*
* We evaluate a script and then manipulate the result.
*
*
*/
public class Control {
@@ -53,47 +50,55 @@ public class Control {
* Then set up the execution environment and begin to
* execute scripts.
*/
public static void main(String[] args)
{
public static void main(String[] args) {
Context cx = Context.enter();
// Set version to JavaScript1.2 so that we get object-literal style
// printing instead of "[object Object]"
cx.setLanguageVersion(Context.VERSION_1_2);
// Initialize the standard objects (Object, Function, etc.)
// This must be done before scripts can be executed.
Scriptable scope = cx.initStandardObjects(null);
// Now we can evaluate a script. Let's create a new object
// using the object literal notation.
Object result = null;
try {
// Set version to JavaScript1.2 so that we get object-literal style
// printing instead of "[object Object]"
cx.setLanguageVersion(Context.VERSION_1_2);
// Initialize the standard objects (Object, Function, etc.)
// This must be done before scripts can be executed.
Scriptable scope = cx.initStandardObjects();
// Now we can evaluate a script. Let's create a new object
// using the object literal notation.
Object result = cx.evaluateString(scope, "obj = {a:1, b:['x','y']}",
result = cx.evaluateString(scope, "obj = {a:1, b:['x','y']}",
"MySource", 1, null);
}
catch (JavaScriptException jse) {
// ignore
}
Scriptable obj = (Scriptable) scope.get("obj", scope);
Scriptable obj = (Scriptable) scope.get("obj", scope);
// Should print "obj == result" (Since the result of an assignment
// expression is the value that was assigned)
System.out.println("obj " + (obj == result ? "==" : "!=") +
" result");
// Should print "obj == result" (Since the result of an assignment
// expression is the value that was assigned)
System.out.println("obj " + (obj == result ? "==" : "!=") +
" result");
// Should print "obj.a == 1"
System.out.println("obj.a == " + obj.get("a", obj));
// Should print "obj.a == 1"
System.out.println("obj.a == " + obj.get("a", obj));
Scriptable b = (Scriptable) obj.get("b", obj);
Scriptable b = (Scriptable) obj.get("b", obj);
// Should print "obj.b[0] == x"
System.out.println("obj.b[0] == " + b.get(0, b));
// Should print "obj.b[0] == x"
System.out.println("obj.b[0] == " + b.get(0, b));
// Should print "obj.b[1] == y"
System.out.println("obj.b[1] == " + b.get(1, b));
// Should print "obj.b[1] == y"
System.out.println("obj.b[1] == " + b.get(1, b));
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]));
} finally {
Context.exit();
}
} catch (JavaScriptException e) {
// ignore
}
cx.exit();
}
}

View File

@@ -1,40 +1,37 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
* 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):
* Norris Boyd
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.*;
@@ -42,17 +39,17 @@ public class Counter extends ScriptableObject {
// The zero-argument constructor used by Rhino runtime to create instances
public Counter() { }
// Method jsConstructor defines the JavaScript constructor
// 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.
// 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.
// 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,40 +1,37 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
* 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):
* Norris Boyd
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.*;
@@ -52,31 +49,27 @@ import org.mozilla.javascript.*;
*/
public class CounterTest {
public static void main(String[] args) throws Exception
{
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects();
ScriptableObject.defineClass(scope, Counter.class);
public static void main(String[] args) throws Exception
{
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects(null);
ScriptableObject.defineClass(scope, Counter.class);
Scriptable testCounter = cx.newObject(scope, "Counter");
Scriptable testCounter = cx.newObject(scope, "Counter");
Object count = ScriptableObject.getProperty(testCounter, "count");
System.out.println("count = " + count);
Object count = ScriptableObject.getProperty(testCounter, "count");
System.out.println("count = " + count);
count = ScriptableObject.getProperty(testCounter, "count");
System.out.println("count = " + count);
count = ScriptableObject.getProperty(testCounter, "count");
System.out.println("count = " + count);
ScriptableObject.callMethod(testCounter, "resetCount", new Object[0]);
System.out.println("resetCount");
ScriptableObject.callMethod(testCounter,
"resetCount",
new Object[0]);
System.out.println("resetCount");
count = ScriptableObject.getProperty(testCounter, "count");
System.out.println("count = " + count);
count = ScriptableObject.getProperty(testCounter, "count");
System.out.println("count = " + count);
} finally {
Context.exit();
}
}
Context.exit();
}
}

View File

@@ -1,40 +1,37 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-2000
* the Initial Developer. All Rights Reserved.
* 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
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.*;
@@ -43,119 +40,86 @@ import org.mozilla.javascript.*;
*/
public class DynamicScopes {
static boolean useDynamicScope;
static class MyFactory extends ContextFactory
{
protected boolean hasFeature(Context cx, int featureIndex)
{
if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE) {
return useDynamicScope;
}
return super.hasFeature(cx, featureIndex);
}
}
static {
ContextFactory.initGlobal(new MyFactory());
}
/**
* Main entry point.
*
* Set up the shared scope and then spawn new threads that execute
* relative to that shared scope. Try to run functions with and
* relative to that shared scope. Try compiling functions with and
* without dynamic scope to see the effect.
*
*
* The expected output is
* <pre>
* sharedScope
* nested:sharedScope
* sharedScope
* nested:sharedScope
* sharedScope
* nested:sharedScope
* thread0
* nested:thread0
* thread1
* nested:thread1
* thread2
* nested:thread2
* </pre>
* The final three lines may be permuted in any order depending on
* thread scheduling.
*/
public static void main(String[] args)
public static void main(String[] args)
throws JavaScriptException
{
Context cx = Context.enter();
try {
// Precompile source only once
String source = ""
+"var x = 'sharedScope';\n"
+"function f() { return x; }\n"
// Dynamic scope works with nested function too
+"function initClosure(prefix) {\n"
+" return function test() { return prefix+x; }\n"
+"}\n"
+"var closure = initClosure('nested:');\n"
+"";
Script script = cx.compileString(source, "sharedScript", 1, null);
useDynamicScope = false;
runScripts(cx, script);
useDynamicScope = true;
runScripts(cx, script);
cx.setCompileFunctionsWithDynamicScope(false);
runScripts(cx);
cx.setCompileFunctionsWithDynamicScope(true);
runScripts(cx);
} finally {
cx.exit();
}
}
static void runScripts(Context cx, Script script)
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.
ScriptableObject sharedScope = cx.initStandardObjects(null, true);
Scriptable scope = cx.initStandardObjects(null);
// Now we can execute the precompiled script against the scope
// to define x variable and f function in the shared scope.
script.exec(cx, sharedScope);
// 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
// Now we spawn some threads that execute a script that calls the
// function 'f'. The scope chain looks like this:
// <pre>
// ------------------ ------------------
// | per-thread scope | -prototype-> | shared scope |
// ------------------ ------------------
// ------------------
// | shared scope |
// ------------------
// ^
// |
// parentScope
// ------------------
// | 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,
// 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 source2 = ""
+"function g() { var x = 'local'; return f(); }\n"
+"java.lang.System.out.println(g());\n"
+"function g2() { var x = 'local'; return closure(); }\n"
+"java.lang.System.out.println(g2());\n"
+"";
t[i] = new Thread(new PerThread(sharedScope, source2,
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
// Don't return in this thread until all the spawned threads have
// completed.
for (int i=0; i < threadCount; i++) {
try {
@@ -164,39 +128,49 @@ public class DynamicScopes {
}
}
}
static class PerThread implements Runnable {
PerThread(Scriptable sharedScope, String source, String x) {
this.sharedScope = sharedScope;
this.source = source;
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(sharedScope);
threadScope.setPrototype(sharedScope);
// We want "threadScope" to be a new top-level
// scope, so set its parent scope to null. This
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, source, "threadScript", 1, null);
} finally {
cx.evaluateString(threadScope, script, "threadScript", 1, null);
}
catch (NotAFunctionException jse) {
// ignore
}
catch (PropertyException jse) {
// ignore
}
catch (JavaScriptException jse) {
// ignore
}
finally {
Context.exit();
}
}
private Scriptable sharedScope;
private String source;
private Scriptable scope;
private String script;
private String x;
}

View File

@@ -1,223 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John Schneider
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
print("----------------------------------------");
// Use the XML constructor to parse an string into an XML object
var John = "<employee><name>John</name><age>25</age></employee>";
var Sue ="<employee><name>Sue</name><age>32</age></employee>";
var tagName = "employees";
var employees = new XML("<" + tagName +">" + John + Sue + "</" + tagName +">");
print("The employees XML object constructed from a string is:\n" + employees);
print("----------------------------------------");
// Use an XML literal to create an XML object
var order = <order>
<customer>
<firstname>John</firstname>
<lastname>Doe</lastname>
</customer>
<item>
<description>Big Screen Television</description>
<price>1299.99</price>
<quantity>1</quantity>
</item>
</order>
// Construct the full customer name
var name = order.customer.firstname + " " + order.customer.lastname;
// Calculate the total price
var total = order.item.price * order.item.quantity;
print("The order XML object constructed using a literal is:\n" + order);
print("The total price of " + name + "'s order is " + total);
print("----------------------------------------");
// construct a new XML object using expando and super-expando properties
var order = <order/>;
order.customer.name = "Fred Jones";
order.customer.address.street = "123 Long Lang";
order.customer.address.city = "Underwood";
order.customer.address.state = "CA";
order.item[0] = "";
order.item[0].description = "Small Rodents";
order.item[0].quantity = 10;
order.item[0].price = 6.95;
print("The order custructed using expandos and super-expandos is:\n" + order);
// append a new item to the order
order.item += <item><description>Catapult</description><price>139.95</price></item>;
print("----------------------------------------");
print("The order after appending a new item is:\n" + order);
print("----------------------------------------");
// dynamically construct an XML element using embedded expressions
var tagname = "name";
var attributename = "id";
var attributevalue = 5;
var content = "Fred";
var x = <{tagname} {attributename}={attributevalue}>{content}</{tagname}>;
print("The dynamically computed element value is:\n" + x.toXMLString());
print("----------------------------------------");
// Create a SOAP message
var message = <soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<m:GetLastTradePrice xmlns:m="http://mycompany.com/stocks">
<symbol>DIS</symbol>
</m:GetLastTradePrice>
</soap:Body>
</soap:Envelope>
// declare the SOAP and stocks namespaces
var soap = new Namespace("http://schemas.xmlsoap.org/soap/envelope/");
var stock = new Namespace ("http://mycompany.com/stocks");
// extract the soap encoding style and body from the soap message
var encodingStyle = message.@soap::encodingStyle;
print("The encoding style of the soap message is specified by:\n" + encodingStyle);
// change the stock symbol
message.soap::Body.stock::GetLastTradePrice.symbol = "MYCO";
var body = message.soap::Body;
print("The body of the soap message is:\n" + body);
print("----------------------------------------");
// create an manipulate an XML object using the default xml namespace
default xml namespace = "http://default.namespace.com";
var x = <x/>;
x.a = "one";
x.b = "two";
x.c = <c xmlns="http://some.other.namespace.com">three</c>;
print("XML object constructed using the default xml namespace:\n" + x);
default xml namespace="";
print("----------------------------------------");
var order = <order id = "123456" timestamp="Mon Mar 10 2003 16:03:25 GMT-0800 (PST)">
<customer>
<firstname>John</firstname>
<lastname>Doe</lastname>
</customer>
<item id="3456">
<description>Big Screen Television</description>
<price>1299.99</price>
<quantity>1</quantity>
</item>
<item id = "56789">
<description>DVD Player</description>
<price>399.99</price>
<quantity>1</quantity>
</item>
</order>;
// get the customer element from the orderprint("The customer is:\n" + order.customer);
// get the id attribute from the order
print("The order id is:" + order.@id);
// get all the child elements from the order element
print("The children of the order are:\n" + order.*);
// get the list of all item descriptions
print("The order descriptions are:\n" + order.item.description);
// get second item by numeric index
print("The second item is:\n" + order.item[1]);
// get the list of all child elements in all item elements
print("The children of the items are:\n" + order.item.*);
// get the second child element from the order by index
print("The second child of the order is:\n" + order.*[1]);
// calculate the total price of the order
var totalprice = 0;
for each (i in order.item) {
totalprice += i.price * i.quantity;
}
print("The total price of the order is: " + totalprice);
print("----------------------------------------");
var e = <employees>
<employee id="1"><name>Joe</name><age>20</age></employee>
<employee id="2"><name>Sue</name><age>30</age></employee>
</employees>;
// get all the names in e
print("All the employee names are:\n" + e..name);
// employees with name Joe
print("The employee named Joe is:\n" + e.employee.(name == "Joe"));
// employees with id's 1 & 2
print("Employees with ids 1 & 2:\n" + e.employee.(@id == 1 || @id == 2));
// name of employee with id 1
print("Name of the the employee with ID=1: " + e.employee.(@id == 1).name);
print("----------------------------------------");

View File

@@ -1,40 +1,37 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-2000
* the Initial Developer. All Rights Reserved.
* 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
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.*;
import java.io.*;
@@ -67,7 +64,7 @@ import java.util.Vector;
* be wrapped as JavaScript exceptions when called from JavaScript,
* and may be caught within JavaScript.
*
* @author Norris Boyd
* @author Norris Boyd
*/
public class File extends ScriptableObject {
@@ -91,7 +88,7 @@ public class File extends ScriptableObject {
* to the use.
*/
public static Scriptable jsConstructor(Context cx, Object[] args,
Function ctorObj,
Function ctorObj,
boolean inNewExpr)
{
File result = new File();
@@ -131,9 +128,11 @@ public class File extends ScriptableObject {
*
* @exception IOException if an error occurred while accessing the file
* associated with this object
* @exception JavaScriptException if a JavaScript exception occurred
* while creating the result array
*/
public Object jsFunction_readLines()
throws IOException
throws IOException, JavaScriptException
{
Vector v = new Vector();
String s;
@@ -144,8 +143,17 @@ public class File extends ScriptableObject {
v.copyInto(lines);
Scriptable scope = ScriptableObject.getTopLevelScope(this);
Context cx = Context.getCurrentContext();
return cx.newObject(scope, "Array", lines);
Scriptable result;
try {
Context cx = Context.getCurrentContext();
result = cx.newObject(scope, "Array", lines);
} catch (PropertyException e) {
throw Context.reportRuntimeError(e.getMessage());
} catch (NotAFunctionException e) {
throw Context.reportRuntimeError(e.getMessage());
}
return result;
}
/**
@@ -253,7 +261,7 @@ public class File extends ScriptableObject {
// in a Scriptable object so that it can be manipulated by
// JavaScript.
Scriptable parent = ScriptableObject.getTopLevelScope(this);
return Context.javaToJS(reader, parent);
return Context.toObject(reader, parent);
}
/**
@@ -266,7 +274,7 @@ public class File extends ScriptableObject {
if (writer == null)
return null;
Scriptable parent = ScriptableObject.getTopLevelScope(this);
return Context.javaToJS(writer, parent);
return Context.toObject(writer, parent);
}
/**

View File

@@ -1,39 +1,36 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.*;

View File

@@ -0,0 +1,59 @@
#! 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/
#
# 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.
#
# Makefile for the examples directory.
#
# This Makefile just calls $(JAVAC) on all the .java files. This
# Makefile is intended to be called from the toplevel Makefile.
#
JSFILES = $(PATH_PREFIX)/*.js
SOURCES = $(PATH_PREFIX)/*.java
CLASSES = $(PATH_PREFIX)/*.class
$(CLASSES) : $(SOURCES)
$(JAVAC) $(JFLAGS) $(SOURCES)
clean :
- rm $(CLASSES) $(PATH_PREFIX)/MANIFEST
clobber : clean
check :
$(PATH_PREFIX)/MANIFEST : $(SOURCES) $(CLASSES) $(JSFILES)
ls $(SOURCES) $(CLASSES) $(JSFILES) \
> $(@)
# Emulate .PHONY
FORCE :

View File

@@ -1,39 +1,36 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.*;
import java.util.Vector;
@@ -262,7 +259,7 @@ public class Matrix implements Scriptable {
public boolean hasInstance(Scriptable value) {
Scriptable proto = value.getPrototype();
while (proto != null) {
if (proto.equals(this))
if (proto.equals(this))
return true;
proto = proto.getPrototype();
}

View File

@@ -1,53 +1,7 @@
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0
-
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 the Initial Developer are Copyright (C) 1997-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- the GNU General Public License Version 2 or later (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
- MPL, indicate your decision by deleting the provisions above and replacing
- 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 MPL or the GPL.
-
- ***** END LICENSE BLOCK ***** -->
<html>
<body>
This is the NervousText applet in javascript:
<applet archive="js.jar" code=NervousText width=200 height=50 >
<applet code=NervousText.class width=200 height=50 >
</applet>
<hr>
The test assumes that applet code is generated with:
<pre>
java -classpath js.jar org.mozilla.javascript.tools.jsc.Main \
-extends java.applet.Applet \
-implements java.lang.Runnable \
NervousText.js
</pre>
and the resulting 2 classes, NervousText.class extending java.applet.Applet and implementing java.lang.Runnable and NervousText1.class which represents compiled JavaScript code, are placed in the same directory as NervousText.html.
<p>
The test also assumes that js.jar from Rhino distribution is available in the same directory.
</body>
</html>

View File

@@ -1,44 +1,10 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
// The Java "NervousText" example ported to JavaScript.
// Compile using java org.mozilla.javascript.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
Daniel Wyszynski
Center for Applied Large-Scale Computing (CALC)
04-12-95
Test of text animation.
@@ -57,7 +23,7 @@ var counter =0;
var threadSuspended = false; //added by kwalrath
function init() {
this.resize(150,50);
this.resize(150,50);
this.setFont(new Font("TimesRoman",Font.BOLD,36));
s = this.getParameter("text");
if (s == null) {
@@ -67,7 +33,7 @@ function init() {
}
function start() {
if(killme == null)
if(killme == null)
{
killme = new java.lang.Thread(java.lang.Runnable(this));
killme.start();
@@ -94,7 +60,7 @@ function paint(g) {
g.drawChars(separated, i,1,x_coord,y_coord);
}
}
/* Added by kwalrath. */
function mouseDown(evt, x, y) {
if (threadSuspended) {

View File

@@ -1,72 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
import org.mozilla.javascript.*;
/**
* An example WrapFactory that can be used to avoid wrapping of Java types
* that can be converted to ECMA primitive values.
* So java.lang.String is mapped to ECMA string, all java.lang.Numbers are
* mapped to ECMA numbers, and java.lang.Booleans are mapped to ECMA booleans
* instead of being wrapped as objects. Additionally java.lang.Character is
* converted to ECMA string with length 1.
* Other types have the default behavior.
* <p>
* Note that calling "new java.lang.String('foo')" in JavaScript with this
* wrap factory enabled will still produce a wrapped Java object since the
* WrapFactory.wrapNewObject method is not overridden.
* <p>
* The PrimitiveWrapFactory is enabled on a Context by calling setWrapFactory
* on that context.
*/
public class PrimitiveWrapFactory extends WrapFactory {
public Object wrap(Context cx, Scriptable scope, Object obj,
Class staticType)
{
if (obj instanceof String || obj instanceof Number ||
obj instanceof Boolean)
{
return obj;
} else if (obj instanceof Character) {
char[] a = { ((Character)obj).charValue() };
return new String(a);
}
return super.wrap(cx, scope, obj, staticType);
}
}

View File

@@ -1,78 +1,73 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
* 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):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.*;
/**
* RunScript: simplest example of controlling execution of Rhino.
*
* Collects its arguments from the command line, executes the
*
* Collects its arguments from the command line, executes the
* script, and prints the result.
*
*
* @author Norris Boyd
*/
public class RunScript {
public static void main(String args[])
public static void main(String args[])
throws JavaScriptException
{
// Creates and enters a Context. The Context stores information
// about the execution environment of a script.
Context cx = Context.enter();
try {
// Initialize the standard objects (Object, Function, etc.)
// This must be done before scripts can be executed. Returns
// a scope object that we use in later calls.
Scriptable scope = cx.initStandardObjects();
// Collect the arguments into a single string.
String s = "";
for (int i=0; i < args.length; i++) {
s += args[i];
}
// Now evaluate the string we've colected.
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
// Convert the result to a string and print it.
System.err.println(cx.toString(result));
} finally {
// Exit from the context.
Context.exit();
}
// Initialize the standard objects (Object, Function, etc.)
// This must be done before scripts can be executed. Returns
// a scope object that we use in later calls.
Scriptable scope = cx.initStandardObjects(null);
// Collect the arguments into a single string.
String s = "";
for (int i=0; i < args.length; i++)
s += args[i];
// Now evaluate the string we've colected.
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
// Convert the result to a string and print it.
System.err.println(cx.toString(result));
// Exit from the context.
Context.exit();
}
}

View File

@@ -1,68 +1,62 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
* 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):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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[])
public static void main(String args[])
throws JavaScriptException
{
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects();
Scriptable scope = cx.initStandardObjects(null);
// Add a global variable "out" that is a JavaScript reflection
// of System.out
Object jsOut = Context.javaToJS(System.out, scope);
ScriptableObject.putProperty(scope, "out", jsOut);
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));
} finally {
Context.exit();
}
// 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,88 +1,80 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
* 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):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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: Example of using JavaScript objects
*
* Collects its arguments from the command line, executes the
*
* Collects its arguments from the command line, executes the
* script, and then ...
*
*
* @author Norris Boyd
*/
public class RunScript3 {
public static void main(String args[])
public static void main(String args[])
throws JavaScriptException
{
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects();
Scriptable scope = cx.initStandardObjects(null);
// Collect the arguments into a single string.
String s = "";
for (int i=0; i < args.length; i++)
s += args[i];
// Now evaluate the string we've colected. We'll ignore the result.
cx.evaluateString(scope, s, "<cmd>", 1, null);
// Collect the arguments into a single string.
String s = "";
for (int i=0; i < args.length; i++) {
s += args[i];
}
// Print the value of variable "x"
Object x = scope.get("x", scope);
if (x == Scriptable.NOT_FOUND)
System.out.println("x is not defined.");
else
System.out.println("x = " + Context.toString(x));
// Now evaluate the string we've colected. We'll ignore the result.
cx.evaluateString(scope, s, "<cmd>", 1, null);
// Print the value of variable "x"
Object x = scope.get("x", scope);
if (x == Scriptable.NOT_FOUND) {
System.out.println("x is not defined.");
} else {
System.out.println("x = " + Context.toString(x));
}
// Call function "f('my arg')" and print its result.
Object fObj = scope.get("f", scope);
if (!(fObj instanceof Function)) {
System.out.println("f is undefined or not a function.");
} else {
Object functionArgs[] = { "my arg" };
Function f = (Function)fObj;
Object result = f.call(cx, scope, scope, functionArgs);
String report = "f('my args') = " + Context.toString(result);
System.out.println(report);
}
} finally {
Context.exit();
// Call function "f('my arg')" and print its result.
Object f = scope.get("f", scope);
if (!(f instanceof Function))
System.out.println("f is undefined or not a function.");
else {
Object functionArgs[] = { "my arg" };
Object result = ((Function) f).call(cx, scope, scope, functionArgs);
System.out.println("f('my args') = " + Context.toString(result));
}
Context.exit();
}
}

View File

@@ -1,77 +1,70 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
* 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):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.*;
/**
* RunScript4: Execute scripts in an environment that includes the
* example Counter class.
*
*
* @author Norris Boyd
*/
public class RunScript4 {
public static void main(String args[])
throws Exception
public static void main(String args[])
throws Exception
{
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects();
Scriptable scope = cx.initStandardObjects(null);
// Use the Counter class to define a Counter constructor
// and prototype in JavaScript.
ScriptableObject.defineClass(scope, Counter.class);
// Use the Counter class to define a Counter constructor
// and prototype in JavaScript.
ScriptableObject.defineClass(scope, Counter.class);
// Create an instance of Counter and assign it to
// the top-level variable "myCounter". This is
// equivalent to the JavaScript code
// myCounter = new Counter(7);
Object[] arg = { new Integer(7) };
Scriptable myCounter = cx.newObject(scope, "Counter", arg);
scope.put("myCounter", scope, myCounter);
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));
} finally {
Context.exit();
}
// Create an instance of Counter and assign it to
// the top-level variable "myCounter". This is
// equivalent to the JavaScript code
// myCounter = new Counter(7);
Object[] arg = { new Integer(7) };
Scriptable myCounter = cx.newObject(scope, "Counter", arg);
scope.put("myCounter", scope, myCounter);
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,39 +1,36 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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):
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.*;
import java.io.*;
@@ -46,12 +43,7 @@ import java.io.*;
*
* @author Norris Boyd
*/
public class Shell extends ScriptableObject
{
public String getClassName()
{
return "global";
}
public class Shell extends ScriptableObject {
/**
* Main entry point.
@@ -64,36 +56,42 @@ public class Shell extends ScriptableObject
public static void main(String args[]) {
// Associate a new Context with this thread
Context cx = Context.enter();
// A bit of shorthand: since Shell extends ScriptableObject,
// we can make it the global object.
global = new Shell();
// Initialize the standard objects (Object, Function, etc.)
// This must be done before scripts can be executed.
cx.initStandardObjects(global);
// Define some global functions particular to the shell. Note
// that these functions are not part of ECMA.
String[] names = { "print", "quit", "version", "load", "help" };
try {
// Initialize the standard objects (Object, Function, etc.)
// This must be done before scripts can be executed.
Shell shell = new Shell();
cx.initStandardObjects(shell);
// Define some global functions particular to the shell. Note
// that these functions are not part of ECMA.
String[] names = { "print", "quit", "version", "load", "help" };
shell.defineFunctionProperties(names, Shell.class,
ScriptableObject.DONTENUM);
args = processOptions(cx, args);
// Set up "arguments" in the global scope to contain the command
// line arguments after the name of the script to execute
Object[] array = args;
if (args.length > 0) {
int length = args.length - 1;
array = new Object[length];
System.arraycopy(args, 1, array, 0, length);
}
Scriptable argsObj = cx.newArray(shell, array);
shell.defineProperty("arguments", argsObj,
ScriptableObject.DONTENUM);
shell.processSource(cx, args.length == 0 ? null : args[0]);
} finally {
Context.exit();
global.defineFunctionProperties(names, Shell.class,
ScriptableObject.DONTENUM);
} catch (PropertyException e) {
throw new Error(e.getMessage());
}
args = processOptions(cx, args);
// Set up "arguments" in the global scope to contain the command
// line arguments after the name of the script to execute
Object[] array = args;
if (args.length > 0) {
int length = args.length - 1;
array = new Object[length];
System.arraycopy(args, 1, array, 0, length);
}
Scriptable argsObj = cx.newArray(global, array);
global.defineProperty("arguments", argsObj,
ScriptableObject.DONTENUM);
processSource(cx, args.length == 0 ? null : args[0]);
cx.exit();
}
/**
@@ -122,13 +120,25 @@ public class Shell extends ScriptableObject
return new String[0];
}
/**
* Return name of this class, the global object.
*
* This method must be implemented in all concrete classes
* extending ScriptableObject.
*
* @see org.mozilla.javascript.Scriptable#getClassName
*/
public String getClassName() {
return "global";
}
/**
* Print a usage message.
*/
private static void usage(String s) {
public static void usage(String s) {
p("Didn't understand \"" + s + "\".");
p("Valid arguments are:");
p("-version 100|110|120|130|140|150");
p("-version 100|110|120|130");
System.exit(1);
}
@@ -137,7 +147,7 @@ public class Shell extends ScriptableObject
*
* This method is defined as a JavaScript function.
*/
public void help() {
public static void help(String s) {
p("");
p("Command Description");
p("======= ===========");
@@ -187,8 +197,7 @@ public class Shell extends ScriptableObject
*
* This method is defined as a JavaScript function.
*/
public void quit()
{
public static void quit() {
quitting = true;
}
@@ -217,9 +226,8 @@ public class Shell extends ScriptableObject
public static void load(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
Shell shell = (Shell)getTopLevelScope(thisObj);
for (int i = 0; i < args.length; i++) {
shell.processSource(cx, cx.toString(args[i]));
for (int i=0; i < args.length; i++) {
processSource(cx, cx.toString(args[i]));
}
}
@@ -231,8 +239,7 @@ public class Shell extends ScriptableObject
* @param filename the name of the file to compile, or null
* for interactive mode.
*/
private void processSource(Context cx, String filename)
{
public static void processSource(Context cx, String filename) {
if (filename == null) {
BufferedReader in = new BufferedReader
(new InputStreamReader(System.in));
@@ -264,7 +271,7 @@ public class Shell extends ScriptableObject
if (cx.stringIsCompilableUnit(source))
break;
}
Object result = cx.evaluateString(this, source,
Object result = cx.evaluateString(global, source,
sourceName, startline,
null);
if (result != cx.getUndefinedValue()) {
@@ -308,7 +315,7 @@ public class Shell extends ScriptableObject
// Here we evalute the entire contents of the file as
// a script. Text is printed only if the print() function
// is called.
cx.evaluateReader(this, in, filename, 1, null);
cx.evaluateReader(global, in, filename, 1, null);
}
catch (WrappedException we) {
System.err.println(we.getWrappedException().toString());
@@ -339,6 +346,7 @@ public class Shell extends ScriptableObject
System.out.println(s);
}
private boolean quitting;
static Shell global;
static boolean quitting;
}

View File

@@ -1,111 +1,63 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* SwingApplication.js - a translation into JavaScript of
* SwingApplication.java, a java.sun.com Swing example.
*
*
* @author Roger E Critchlow, Jr.
*/
var swingNames = JavaImporter();
importPackage(Packages.javax.swing);
importPackage(Packages.java.awt);
importPackage(Packages.java.awt.event);
swingNames.importPackage(Packages.javax.swing);
swingNames.importPackage(Packages.java.awt);
swingNames.importPackage(Packages.java.awt.event);
function createComponents()
{
with (swingNames) {
var labelPrefix = "Number of button clicks: ";
var numClicks = 0;
var label = new JLabel(labelPrefix + numClicks);
var button = new JButton("I'm a Swing button!");
button.mnemonic = KeyEvent.VK_I;
// Since Rhino 1.5R5 JS functions can be passed to Java method if
// corresponding argument type is Java interface with single method
// or all its methods have the same number of arguments and the
// corresponding arguments has the same type. See also comments for
// frame.addWindowListener bellow
button.addActionListener(function() {
numClicks += 1;
label.setText(labelPrefix + numClicks);
});
label.setLabelFor(button);
/*
* An easy way to put space between a top-level container
* and its contents is to put the contents in a JPanel
* that has an "empty" border.
*/
var pane = new JPanel();
pane.border = BorderFactory.createEmptyBorder(30, //top
30, //left
10, //bottom
30); //right
pane.setLayout(new GridLayout(0, 1));
pane.add(button);
pane.add(label);
return pane;
}
}
with (swingNames) {
try {
UIManager.
setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (e) { }
//Create the top-level container and add contents to it.
var frame = new swingNames.JFrame("SwingApplication");
frame.getContentPane().add(createComponents(), BorderLayout.CENTER);
// Pass JS function as implementation of WindowListener. It is allowed since
// all methods in WindowListener have the same signature. To distinguish
// between methods Rhino passes to JS function the name of corresponding
// method as the last argument
frame.addWindowListener(function(event, methodName) {
if (methodName == "windowClosing") {
java.lang.System.exit(0);
function createComponents() {
var labelPrefix = "Number of button clicks: ";
var numClicks = 0;
var label = new JLabel(labelPrefix + numClicks);
var button = new JButton("I'm a Swing button!");
button.setMnemonic(KeyEvent.VK_I);
button.addActionListener(new ActionListener({
actionPerformed : function() {
numClicks += 1;
label.setText(labelPrefix + numClicks);
}
});
}));
label.setLabelFor(button);
//Finish setting up the frame, and show it.
frame.pack();
frame.setVisible(true);
/*
* An easy way to put space between a top-level container
* and its contents is to put the contents in a JPanel
* that has an "empty" border.
*/
var pane = new JPanel();
pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
10, //bottom
30) //right
);
pane.setLayout(new GridLayout(0, 1));
pane.add(button);
pane.add(label);
return pane;
}
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (e) { }
//Create the top-level container and add contents to it.
var frame = new JFrame("SwingApplication");
frame.getContentPane().add(createComponents(), BorderLayout.CENTER);
//Finish setting up the frame, and show it.
frame.addWindowListener(new WindowAdapter({
windowClosing : function() {
java.lang.System.exit(0);
}
}) );
frame.pack();
frame.setVisible(true);

View File

@@ -1,47 +1,44 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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
*
* The files given as arguments on the command line are assumed to be
* Java source code files. This program checks to see that the @param
* tags in the documentation comments match with the parameters for
* tags in the documentation comments match with the parameters for
* the associated Java methods.
* <p>
* Any errors found are reported.
@@ -57,12 +54,12 @@ function stringEndsWith(str, suffix) {
/**
* Perform processing once the end of a documentation comment is seen.
*
* Look for a parameter list following the end of the comment and
* Look for a parameter list following the end of the comment and
* collect the parameters and compare to the @param entries.
* Report any discrepancies.
* @param f the current file
* @param a an array of parameters from @param comments
* @param line the string containing the comment end (in case the
* @param line the string containing the comment end (in case the
* parameters are on the same line)
*/
function processCommentEnd(f, a, line) {
@@ -75,14 +72,14 @@ function processCommentEnd(f, a, line) {
var m = line.match(/\(([^\)]+)\)/);
var args = m ? m[1].split(",") : [];
if (a.length != args.length) {
print('"' + f.name +
print('"' + f.name +
'"; line ' + f.lineNumber +
' mismatch: had a different number' +
' of @param entries and parameters.');
} else {
for (var i=0; i < a.length; i++) {
if (!stringEndsWith(args[i], a[i])) {
print('"' + f.name +
print('"' + f.name +
'"; line ' + f.lineNumber +
' mismatch: had "' + a[i] +
'" and "' + args[i] + '".');
@@ -91,9 +88,9 @@ function processCommentEnd(f, a, line) {
}
}
}
/**
* Process the given file, looking for mismatched @param lists and
* Process the given file, looking for mismatched @param lists and
* parameter lists.
* @param f the file to process
*/
@@ -107,11 +104,11 @@ function processFile(f) {
if (line.match(/@param/)) {
while (m = line.match(/@param[ ]+([^ ]+)/)) {
a[i++] = m[1];
line = f.readLine();
line = f.readLine();
if (line == null)
break outer;
}
}
}
if (i != 0 && line.match(/\*\//)) {
processCommentEnd(f, a, line);
i = 0;
@@ -119,7 +116,7 @@ function processFile(f) {
}
}
if (i != 0) {
print('"' + f.name +
print('"' + f.name +
'"; line ' + f.lineNumber +
' missing parameters at end of file.');
}

View File

@@ -1,68 +1,69 @@
/* -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla 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/MPL/
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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
* Patrick Beard
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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.
*/
/*
Implementing the interface java.util.Enumeration passing the object
with JavaScript implementation directly to the constructor.
This is a shorthand for JavaAdapter constructor:
enum.js
Implementing the interface java.util.Enumeration using the new syntax.
Note that this syntax is experimental only, and hasn't been approved
by ECMA.
The same functionality can be had without the new syntax using the
uglier syntax:
elements = new JavaAdapter(java.util.Enumeration, {
index: 0,
elements: array,
hasMoreElements: function ...
nextElement: function ...
var elements = new JavaAdapter(java.util.Enumeration, {
index: 0, elements: array,
hasMoreElements: function ...
nextElement: function ...
});
by Patrick C. Beard.
*/
// an array to enumerate.
var array = [0, 1, 2];
// create an array enumeration.
var elements = new java.util.Enumeration({
index: 0,
elements: array,
hasMoreElements: function() {
return (this.index < this.elements.length);
},
nextElement: function() {
return this.elements[this.index++];
var elements = new java.util.Enumeration() {
index: 0, elements: array,
hasMoreElements: function() {
return (this.index < this.elements.length);
},
nextElement: function() {
return this.elements[this.index++];
}
});
};
// now print out the array by enumerating through the Enumeration
while (elements.hasMoreElements())

View File

@@ -1,41 +1,38 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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
* Norris Boyd
* Roland Pennings
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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
@@ -43,7 +40,7 @@
* @author Norris Boyd
* @see rhinotip.jar
* @lastmodified xx
* @version 1.2 Roland Pennings: Allow multiple files for a function.
* @version 1.2 Roland Pennings: Allow multiple files for a function.
* @version 1.3 Roland Pennings: Removes ../.. from the input directory name
*/
defineClass("File")
@@ -64,7 +61,7 @@ var debug = 0;
/**
* Process JavaScript source file <code>f</code>, writing jsdoc to
* Process JavaScript source file <code>f</code>, writing jsdoc to
* file <code>out</code>.
* @param f input file
* @param fname name of the input file (without the path)
@@ -75,11 +72,11 @@ function processFile(f, fname, inputdir, out) {
var s;
var firstLine = true;
indexFileArray[fname] = "";
// write the header of the output file
out.writeLine('<HTML><HEADER><TITLE>' + fname + '</TITLE><BODY>');
if (inputdir != null) {
outstr = '<a name=\"_top_\"></a><pre><a href=\"' + indexFile + '\">Index Files</a> ';
outstr = '<a name=\"_top_\"></a><pre><a href=\"' + indexFile + '\">Index Files</a> ';
outstr += '<a href=\"' + indexFunction + '\">Index Functions</a></pre><hr>';
out.writeLine(outstr);
}
@@ -101,7 +98,7 @@ function processFile(f, fname, inputdir, out) {
// Strip leading whitespace and "*".
comment += s.replace(/^\s*\*/, "");
s = f.readLine();
} while (s != null);
} while (s != null);
if (debug)
print("Found comment " + comment);
@@ -119,7 +116,7 @@ function processFile(f, fname, inputdir, out) {
// match the beginning of the function
// NB we also match functions without a comment!
// if we have two comments one after another only the last one will be taken
m = s.match(/^\s*function\s+((\w+)|(\w+)(\s+))\(([^)]*)\)/);
m = s.match(/^\s*function\s+((\w+)|(\w+)(\s+))\(([^)]*)\)/);
if (m != null)
{
// Found a function start
@@ -129,8 +126,8 @@ function processFile(f, fname, inputdir, out) {
// can write out a table of contents first.
functionDocArray[functionDocArray.length] = {name:m[1], text:htmlText};
// Store the function also in the indexFunctionArray
// so we can have a separate file with the function table of contents
// Store the function also in the indexFunctionArray
// so we can have a seperate file with the function table of contents
if (indexFunctionArray[m[1]]) {
// print("ERROR: function: " + m[1] + " is defined more than once!");
// Allow multiple files for a function
@@ -138,26 +135,26 @@ function processFile(f, fname, inputdir, out) {
filename = filename + "|" + fname;
// print("filename = " + filename);
}
}
}
else {
indexFunctionArray[m[1]] = {filename:fname};
}
//reset comment
//reset comment
comment = "";
}
}
// match a method being bound to a prototype
m = s.match(/^\s*(\w*)\.prototype\.(\w*)\s*=\s*function\s*\(([^)]*)\)/);
if (m != null)
{
// Found a method being bound to a prototype.
// Found a method being bound to a prototype.
var htmlText = processPrototypeMethod(m[1], m[2], m[3], comment);
// Save the text in a global variable, so we
// can write out a table of contents first.
functionDocArray[functionDocArray.length] = {name:m[1]+".prototype."+m[2], text:htmlText};
// Store the function also in the indexFunctionArray
// so we can have a separate file with the function table of contents
// Store the function also in the indexFunctionArray
// so we can have a seperate file with the function table of contents
if (indexFunctionArray[m[1]]) {
// print("ERROR: function: " + m[1] + " is defined more than once!");
// Allow multiple files for a function
@@ -165,15 +162,15 @@ function processFile(f, fname, inputdir, out) {
filename = filename + "|" + fname;
// print("filename = " + filename);
}
}
}
else {
indexFunctionArray[m[1]] = {filename:fname};
}
//reset comment
//reset comment
comment = "";
}
}
firstLine = false;
}
@@ -196,7 +193,7 @@ function processFile(f, fname, inputdir, out) {
out.writeLine('</BODY></HTML>');
// Now clean up the doc array
functionDocArray = [];
functionDocArray = [];
}
/**
@@ -218,7 +215,7 @@ function processFunction(name, args, comment) {
}
/**
* Process a method being bound to a prototype.
* Process a method being bound to a prototype.
* @param proto the name of the prototype
* @param name the name of the function
* @param args the args of the function as a single string
@@ -247,11 +244,11 @@ function processPrototypeMethod(proto, name, args, comment) {
function processComment(comment,firstLine,fname) {
var tags = {};
// Use the "lambda" form of regular expression replace,
// where the replacement object is a function rather
// than a string. The function is called with the
// where the replacement object is a function rather
// than a string. The function is called with the
// matched text and any parenthetical matches as
// arguments, and the result of the function used as the
// replacement text.
// replacement text.
// Here we use the function to build up the "tags" object,
// which has a property for each "@" tag that is the name
// of the tag, and whose value is an array of the
@@ -263,9 +260,9 @@ function processComment(comment,firstLine,fname) {
tags[name] = a;
return "";
});
// if we have a comment at the beginning of a file
// store the comment for the index file
// store the comment for the index file
if (firstLine) {
indexFileArray[fname] = comment;
}
@@ -277,7 +274,7 @@ function processComment(comment,firstLine,fname) {
var params = "";
for (var i=0; i < array.length; i++) {
var m = array[i].match(/(\w+)\s+(.*)/);
params += '<TR><TD><I>'+m[1]+'</I></TD>' +
params += '<TR><TD><I>'+m[1]+'</I></TD>' +
'<TD>'+m[2]+'</TD></TR>';
}
out += '<TABLE WIDTH="90%" BORDER=1>';
@@ -329,7 +326,7 @@ function processComment(comment,firstLine,fname) {
out += '<DT><B>Last modified:</B><DD>';
out += '<script><!--\n';
out += 'document.writeln(document.lastModified);\n';
out += '// ---></script>\n';
out += '// ---></script>\n';
out += '</DL><P>';
}
@@ -341,9 +338,9 @@ function processComment(comment,firstLine,fname) {
* Create an html output file
* @param outputdir directory to put the file
* @param htmlfile name of the file
*/
*/
function CreateOutputFile(outputdir,htmlfile)
{
{
if (outputdir==null)
{
var outname = htmlfile;
@@ -358,18 +355,18 @@ function CreateOutputFile(outputdir,htmlfile)
}
/**
* Process a javascript file. Puts the generated HTML file in the outdir
* Process a javascript file. Puts the generated HTML file in the outdir
* @param filename name of the javascript file
* @inputdir input directory of the file (default null)
*/
function processJSFile(filename,inputdir)
function processJSFile(filename,inputdir)
{
if (debug) print("filename = " + filename + " inputdir = " + inputdir);
if (!filename.match(/\.js$/)) {
print("Expected filename to end in '.js'; had instead " +
if (!filename.match(/\.js$/)) {
print("Expected filename to end in '.js'; had instead " +
filename + ". I don't treat the file.");
} else {
} else {
if (inputdir==null)
{
var inname = filename;
@@ -382,12 +379,12 @@ function processJSFile(filename,inputdir)
print("Processing file " + inname);
var f = new File(inname);
// create the output file
var htmlfile = filename.replace(/\.js$/, ".html");
var out = CreateOutputFile(outputdir,htmlfile);
processFile(f, filename, inputdir, out);
out.close();
}
@@ -401,7 +398,7 @@ function GenerateIndex(dirname)
{
// construct the files index file
var out = CreateOutputFile(outputdir,indexFile);
// write the beginning of the file
out.writeLine('<HTML><HEADER><TITLE>File Index - directory: ' + dirname + '</TITLE><BODY>');
out.writeLine('<H1>File Index - directory: ' + dirname + '</H1>\n');
@@ -415,7 +412,7 @@ function GenerateIndex(dirname)
// sort the index file array
var SortedFileArray = [];
for (var fname in indexFileArray)
SortedFileArray.push(fname);
SortedFileArray.push(fname);
SortedFileArray.sort();
for (var i=0; i < SortedFileArray.length; i++) {
@@ -430,10 +427,10 @@ function GenerateIndex(dirname)
}
out.writeLine('</TABLE></BODY></HTML>');
out.close();
// construct the functions index file
var out = CreateOutputFile(outputdir,indexFunction);
// write the beginning of the file
out.writeLine('<HTML><HEADER><TITLE>Function Index - directory: ' + dirname + '</TITLE><BODY>');
out.writeLine('<H1>Function Index - directory: ' + dirname + '</H1>\n');
@@ -441,11 +438,11 @@ function GenerateIndex(dirname)
out.writeLine('<TR BGCOLOR=0xdddddddd>');
out.writeLine('<TD><B>Function</B></TD>');
out.writeLine('<TD><B>Files</B></TD></TR>');
// sort the function array
var SortedFunctionArray = [];
for (var functionname in indexFunctionArray)
SortedFunctionArray.push(functionname);
SortedFunctionArray.push(functionname);
SortedFunctionArray.sort();
for (var j=0; j < SortedFunctionArray.length; j++) {
@@ -479,10 +476,10 @@ function PrintOptions()
// Main Script
// first read the arguments
// first read the arguments
if (! arguments)
PrintOptions();
for (var i=0; i < arguments.length; i++) {
if (debug) print("argument: + \'" + arguments[i] + "\'");
if (arguments[i].match(/^\-/)) {
@@ -492,7 +489,7 @@ for (var i=0; i < arguments.length; i++) {
outputdir = String(arguments[i+1]);
if (debug) print("outputdir: + \'" + outputdir + "\'");
i++;
i++;
}
else if (String(arguments[i])=="-i"){
// process all files in an input directory
@@ -513,16 +510,16 @@ if (debug) print("inputdir: + \'" + arguments[i+1] + "\'");
FileList.push(String(arguments[i]));
}
}
}
// first handle the single files
for (var i in FileList)
for (var i in FileList)
processJSFile(FileList[i],null);
// then handle the input directories
for (var j in DirList) {
var inputdir = String(DirList[j]);
print("Process input directory: " + inputdir);
// clean up index arrays
@@ -531,13 +528,13 @@ for (var j in DirList) {
// for the directory name get rid of ../../ or ..\..\
inputDirName = inputdir.replace(/\.\.\/|\.\.\\/g,"");
indexFile = indexFileName + "_" + inputDirName + ".html";
indexFunction = indexFunctionName + "_" + inputDirName + ".html";
print("indexFile = " + indexFile);
print("indexFunction = " + indexFunction);
// read the files in the directory
var DirFile = new java.io.File(inputdir);
var lst = DirFile.list();
@@ -546,7 +543,7 @@ print("indexFunction = " + indexFunction);
for (var i=0; i < lst.length; i++)
{
processJSFile(String(lst[i]),inputdir);
}
}
// generate the index files for the input directory
GenerateIndex(inputDirName);

View File

@@ -1,47 +1,44 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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
*/
// Create a new StringBuffer. Note that the class name must be fully qualified
// by its package. Packages other than "java" must start with "Packages", i.e.,
// by its package. Packages other than "java" must start with "Packages", i.e.,
// "Packages.javax.servlet...".
var sb = new java.lang.StringBuffer();
@@ -54,4 +51,4 @@ sb.append(true);
// Now print it out. (The toString() method of sb is automatically called
// to convert the buffer to a string.)
// Should print "hi, mom3.0true".
print(sb);
print(sb);

View File

@@ -1,46 +1,43 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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")
// "arguments[0]" refers to the first argument at the command line to the
// "arguments[0]" refers to the first argument at the command line to the
// script, if present. If not present, "arguments[0]" will be undefined,
// which will cause f to read from System.in.
var f = new File(arguments[0]);
@@ -53,4 +50,4 @@ while ((line = f.readLine()) != null) {
}
for (i in o) {
print(i);
}
}

View File

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -1 +0,0 @@
org.mozilla.javascript.jdkscript.RhinoScriptEngineFactory

View File

@@ -1,80 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0
The contents of this file are subject to the Mozilla 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/MPL/
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 the Initial Developer are Copyright (C) 1997-1999
the Initial Developer. All Rights Reserved.
Contributor(s):
Norris Boyd
Igor Bukanov
Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 2 or later (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
MPL, indicate your decision by deleting the provisions above and replacing
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 MPL or the GPL.
***** END LICENSE BLOCK ***** -->
<!--
<!--
Build file for Rhino using Ant (see http://jakarta.apache.org/ant/index.html)
Requires Ant version 1.2
-->
<project name="src" default="compile" basedir="..">
<project name="src" default="build" basedir=".">
<property file="build.properties"/>
<target name="properties">
<property name="nest" value=".."/>
</target>
<target name="compile">
<javac srcdir="src"
destdir="${classes}"
<target name="compile" depends="properties">
<javac srcdir="."
destdir="${nest}/${build.dest}"
includes="org/**/*.java"
deprecation="on"
debug="${debug}"
target="${target-jvm}"
source="${source-level}"
>
debug="${debug}">
</javac>
<copy todir="${classes}">
<fileset dir="src" includes="org/**/*.properties" />
<filterset>
<filter token="IMPLEMENTATION.VERSION"
value="${implementation.version}"/>
</filterset>
</target>
<target name="copy-properties">
<copy todir="${nest}/${build.dest}">
<fileset dir="." includes="org/**/*.properties" />
</copy>
</target>
<target name="copy-source">
<mkdir dir="${dist.dir}/src"/>
<copy todir="${dist.dir}/src">
<fileset dir="src"
includes="**/*.java,**/*.properties,**/*.xml,manifest"/>
<copy todir="${nest}/${dist.src}">
<fileset dir="."
includes="org/**/*.java,org/**/*.properties,build.xml,manifest"/>
</copy>
</target>
<target name="clean">
<delete includeEmptyDirs="true">
<fileset dir="${classes}"
excludes="org/mozilla/javascript/tools/**"/>
</delete>
</target>
<target name="build" depends="compile,copy-properties,copy-source"/>
</project>

View File

@@ -1,3 +1,2 @@
Manifest-Version: 1.0
Main-Class: org.mozilla.javascript.tools.shell.Main
Class-Path: xbean.jar

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,107 @@
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Roger Lawrence
* Patrick Beard
* Igor Bukanov
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* 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.classfile;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
/**
* Load generated classes.
*
* @author Norris Boyd
*/
public class DefiningClassLoader extends ClassLoader {
public static ClassLoader getContextClassLoader() {
try {
if (getContextClassLoaderMethod != null) {
return (ClassLoader) getContextClassLoaderMethod.invoke(
Thread.currentThread(),
new Object[0]);
}
} catch (IllegalAccessException e) {
// fall through...
} catch (InvocationTargetException e) {
// fall through...
}
return DefiningClassLoader.class.getClassLoader();
}
public Class defineClass(String name, byte data[]) {
return super.defineClass(name, data, 0, data.length);
}
public Class loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
Class clazz = findLoadedClass(name);
if (clazz == null) {
ClassLoader loader = getContextClassLoader();
if (loader != null) {
clazz = loader.loadClass(name);
} else {
clazz = findSystemClass(name);
}
}
if (resolve)
resolveClass(clazz);
return clazz;
}
private static Method getContextClassLoaderMethod;
static {
try {
// Don't use "Thread.class": that performs the lookup
// in the class initializer, which doesn't allow us to
// catch possible security exceptions.
Class threadClass = Class.forName("java.lang.Thread");
// We'd like to use "getContextClassLoader", but
// that's only available on Java2.
getContextClassLoaderMethod =
threadClass.getDeclaredMethod("getContextClassLoader",
new Class[0]);
} catch (ClassNotFoundException e) {
// ignore exceptions; we'll use Class.forName instead.
} catch (NoSuchMethodException e) {
// ignore exceptions; we'll use Class.forName instead.
} catch (SecurityException e) {
// ignore exceptions; we'll use Class.forName instead.
}
}
}

View File

@@ -1,41 +1,37 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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
* Igor Bukanov
* Contributor(s):
* Norris Boyd
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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;
@@ -47,266 +43,98 @@ package org.mozilla.javascript;
* @see org.mozilla.javascript.NativeCall
* @author Norris Boyd
*/
final class Arguments extends IdScriptableObject
{
static final long serialVersionUID = 4275508002492040609L;
class Arguments extends ScriptableObject {
public Arguments(NativeCall activation)
{
public Arguments(NativeCall activation) {
this.activation = activation;
Scriptable parent = activation.getParentScope();
setParentScope(parent);
setPrototype(ScriptableObject.getObjectPrototype(parent));
args = activation.originalArgs;
lengthObj = new Integer(args.length);
args = activation.getOriginalArguments();
int length = args.length;
Object callee = activation.funObj;
NativeFunction f = activation.function;
calleeObj = f;
defineProperty("length", new Integer(length),
ScriptableObject.DONTENUM);
defineProperty("callee", callee, ScriptableObject.DONTENUM);
int version = f.getLanguageVersion();
if (version <= Context.VERSION_1_3
&& version != Context.VERSION_DEFAULT)
{
callerObj = null;
} else {
callerObj = NOT_FOUND;
}
hasCaller = (activation.funObj.version <= Context.VERSION_1_3 &&
activation.funObj.version != Context.VERSION_DEFAULT);
}
public String getClassName()
{
public String getClassName() {
return "Arguments";
}
public boolean has(int index, Scriptable start)
{
if (0 <= index && index < args.length) {
if (args[index] != NOT_FOUND) {
return true;
}
}
return super.has(index, start);
public boolean has(String name, Scriptable start) {
return (hasCaller && name.equals("caller")) || super.has(name, start);
}
public Object get(int index, Scriptable start)
{
public boolean has(int index, Scriptable start) {
Object[] args = activation.getOriginalArguments();
return (0 <= index && index < args.length) || super.has(index, start);
}
public Object get(String name, Scriptable start) {
if (hasCaller && name.equals("caller")) {
NativeCall caller = activation.caller;
if (caller == null || caller.originalArgs == null)
return null;
return caller.get("arguments", caller);
}
return super.get(name, start);
}
public Object get(int index, Scriptable start) {
if (0 <= index && index < args.length) {
Object value = args[index];
if (value != NOT_FOUND) {
if (sharedWithActivation(index)) {
NativeFunction f = activation.function;
String argName = f.getParamOrVarName(index);
value = activation.get(argName, activation);
if (value == NOT_FOUND) Kit.codeBug();
}
return value;
}
NativeFunction f = activation.funObj;
if (index < f.argCount)
return activation.get(f.argNames[index], activation);
return args[index];
}
return super.get(index, start);
}
private boolean sharedWithActivation(int index)
{
NativeFunction f = activation.function;
int definedCount = f.getParamCount();
if (index < definedCount) {
// Check if argument is not hidden by later argument with the same
// name as hidden arguments are not shared with activation
if (index < definedCount - 1) {
String argName = f.getParamOrVarName(index);
for (int i = index + 1; i < definedCount; i++) {
if (argName.equals(f.getParamOrVarName(i))) {
return false;
}
}
}
return true;
public void put(String name, Scriptable start, Object value) {
if (name.equals("caller")) {
// Set "hasCaller" to false so that we won't look up a
// computed value.
hasCaller = false;
}
return false;
super.put(name, start, value);
}
public void put(int index, Scriptable start, Object value)
{
public void put(int index, Scriptable start, Object value) {
if (0 <= index && index < args.length) {
if (args[index] != NOT_FOUND) {
if (sharedWithActivation(index)) {
String argName;
argName = activation.function.getParamOrVarName(index);
activation.put(argName, activation, value);
return;
}
synchronized (this) {
if (args[index] != NOT_FOUND) {
if (args == activation.originalArgs) {
args = (Object[])args.clone();
}
args[index] = value;
return;
}
}
}
NativeFunction f = activation.funObj;
if (index < f.argCount)
activation.put(f.argNames[index], activation, value);
else
args[index] = value;
return;
}
super.put(index, start, value);
}
public void delete(int index)
{
public void delete(String name) {
if (name.equals("caller"))
hasCaller = false;
super.delete(name);
}
public void delete(int index) {
if (0 <= index && index < args.length) {
synchronized (this) {
if (args[index] != NOT_FOUND) {
if (args == activation.originalArgs) {
args = (Object[])args.clone();
}
args[index] = NOT_FOUND;
return;
}
}
NativeFunction f = activation.funObj;
if (index < f.argCount)
activation.delete(f.argNames[index]);
else
args[index] = Undefined.instance;
}
super.delete(index);
}
// #string_id_map#
private static final int
Id_callee = 1,
Id_length = 2,
Id_caller = 3,
MAX_INSTANCE_ID = 3;
protected int getMaxInstanceId()
{
return MAX_INSTANCE_ID;
}
protected int findInstanceIdInfo(String s)
{
int id;
// #generated# Last update: 2002-04-09 20:46:33 CEST
L0: { id = 0; String X = null; int c;
if (s.length()==6) {
c=s.charAt(5);
if (c=='e') { X="callee";id=Id_callee; }
else if (c=='h') { X="length";id=Id_length; }
else if (c=='r') { X="caller";id=Id_caller; }
}
if (X!=null && X!=s && !X.equals(s)) id = 0;
}
// #/generated#
if (id == 0) return super.findInstanceIdInfo(s);
int attr;
switch (id) {
case Id_callee:
case Id_caller:
case Id_length:
attr = DONTENUM;
break;
default: throw new IllegalStateException();
}
return instanceIdInfo(attr, id);
}
// #/string_id_map#
protected String getInstanceIdName(int id)
{
switch (id) {
case Id_callee: return "callee";
case Id_length: return "length";
case Id_caller: return "caller";
}
return null;
}
protected Object getInstanceIdValue(int id)
{
switch (id) {
case Id_callee: return calleeObj;
case Id_length: return lengthObj;
case Id_caller: {
Object value = callerObj;
if (value == UniqueTag.NULL_VALUE) { value = null; }
else if (value == null) {
NativeCall caller = activation.parentActivationCall;
if (caller != null) {
value = caller.get("arguments", caller);
} else {
value = null;
}
}
return value;
}
}
return super.getInstanceIdValue(id);
}
protected void setInstanceIdValue(int id, Object value)
{
switch (id) {
case Id_callee: calleeObj = value; return;
case Id_length: lengthObj = value; return;
case Id_caller:
callerObj = (value != null) ? value : UniqueTag.NULL_VALUE;
return;
}
super.setInstanceIdValue(id, value);
}
Object[] getIds(boolean getAll)
{
Object[] ids = super.getIds(getAll);
if (getAll && args.length != 0) {
boolean[] present = null;
int extraCount = args.length;
for (int i = 0; i != ids.length; ++i) {
Object id = ids[i];
if (id instanceof Integer) {
int index = ((Integer)id).intValue();
if (0 <= index && index < args.length) {
if (present == null) {
present = new boolean[args.length];
}
if (!present[index]) {
present[index] = true;
extraCount--;
}
}
}
}
if (extraCount != 0) {
Object[] tmp = new Object[extraCount + ids.length];
System.arraycopy(ids, 0, tmp, extraCount, ids.length);
ids = tmp;
int offset = 0;
for (int i = 0; i != args.length; ++i) {
if (present == null || !present[i]) {
ids[offset] = new Integer(i);
++offset;
}
}
if (offset != extraCount) Kit.codeBug();
}
}
return ids;
}
// Fields to hold caller, callee and length properties,
// where NOT_FOUND value tags deleted properties.
// In addition if callerObj == NULL_VALUE, it tags null for scripts, as
// initial callerObj == null means access to caller arguments available
// only in JS <= 1.3 scripts
private Object callerObj;
private Object calleeObj;
private Object lengthObj;
private NativeCall activation;
// Initially args holds activation.getOriginalArgs(), but any modification
// of its elements triggers creation of a copy. If its element holds NOT_FOUND,
// it indicates deleted index, in which case super class is queried.
private Object[] args;
private boolean hasCaller;
}

View File

@@ -1,43 +1,40 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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.
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
* 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
* Igor Bukanov
* Roger Lawrence
* Mike McCabe
* Contributor(s):
* Norris Boyd
* Igor Bukanov
* Roger Lawrence
* Mike McCabe
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
* 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;
@@ -46,27 +43,23 @@ package org.mozilla.javascript;
* See ECMA 15.3.
* @author Norris Boyd
*/
public class BaseFunction extends IdScriptableObject implements Function
{
public class BaseFunction extends IdScriptable implements Function {
static final long serialVersionUID = 5311394446546053859L;
private static final Object FUNCTION_TAG = new Object();
static void init(Scriptable scope, boolean sealed)
{
static void init(Context cx, Scriptable scope, boolean sealed) {
BaseFunction obj = new BaseFunction();
obj.isPrototypePropertyImmune = true;
obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
obj.prototypeFlag = true;
obj.functionName = "";
obj.prototypePropertyAttrs = DONTENUM | READONLY | PERMANENT;
obj.addAsPrototype(MAX_PROTOTYPE_ID, cx, scope, sealed);
}
public BaseFunction()
protected void fillConstructorProperties
(Context cx, IdFunction ctor, boolean sealed)
{
}
public BaseFunction(Scriptable scope, Scriptable prototype)
{
super(scope, prototype);
// Fix up bootstrapping problem: getPrototype of the IdFunction
// can not return Function.prototype because Function object is not
// yet defined.
ctor.setPrototype(this);
}
public String getClassName() {
@@ -87,209 +80,125 @@ public class BaseFunction extends IdScriptableObject implements Function
* value's prototype chain
*
*/
public boolean hasInstance(Scriptable instance)
{
public boolean hasInstance(Scriptable instance) {
Object protoProp = ScriptableObject.getProperty(this, "prototype");
if (protoProp instanceof Scriptable) {
if (protoProp instanceof Scriptable && protoProp != Undefined.instance)
{
return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp);
}
throw ScriptRuntime.typeError1("msg.instanceof.bad.prototype",
getFunctionName());
throw NativeGlobal.typeError1
("msg.instanceof.bad.prototype", functionName, instance);
}
// #string_id_map#
private static final int
Id_length = 1,
Id_arity = 2,
Id_name = 3,
Id_prototype = 4,
Id_arguments = 5,
MAX_INSTANCE_ID = 5;
protected int getMaxInstanceId()
{
return MAX_INSTANCE_ID;
}
protected int findInstanceIdInfo(String s)
{
int id;
// #generated# Last update: 2001-05-20 00:12:12 GMT+02:00
L0: { id = 0; String X = null; int c;
L: switch (s.length()) {
case 4: X="name";id=Id_name; break L;
case 5: X="arity";id=Id_arity; break L;
case 6: X="length";id=Id_length; break L;
case 9: c=s.charAt(0);
if (c=='a') { X="arguments";id=Id_arguments; }
else if (c=='p') { X="prototype";id=Id_prototype; }
break L;
}
if (X!=null && X!=s && !X.equals(s)) id = 0;
}
// #/generated#
// #/string_id_map#
if (id == 0) return super.findInstanceIdInfo(s);
int attr;
protected int getIdDefaultAttributes(int id) {
switch (id) {
case Id_length:
case Id_arity:
case Id_name:
attr = DONTENUM | READONLY | PERMANENT;
break;
case Id_prototype:
attr = (isPrototypePropertyImmune)
? DONTENUM | READONLY | PERMANENT
: DONTENUM;
break;
case Id_arguments:
attr = DONTENUM | PERMANENT;
break;
default: throw new IllegalStateException();
case Id_length:
case Id_arity:
case Id_name:
return DONTENUM | READONLY | PERMANENT;
case Id_prototype:
return prototypePropertyAttrs;
case Id_arguments:
return EMPTY;
}
return instanceIdInfo(attr, id);
return super.getIdDefaultAttributes(id);
}
protected String getInstanceIdName(int id)
{
switch (id) {
case Id_length: return "length";
case Id_arity: return "arity";
case Id_name: return "name";
case Id_prototype: return "prototype";
case Id_arguments: return "arguments";
}
return super.getInstanceIdName(id);
}
protected Object getInstanceIdValue(int id)
{
switch (id) {
case Id_length: return ScriptRuntime.wrapInt(getLength());
case Id_arity: return ScriptRuntime.wrapInt(getArity());
case Id_name: return getFunctionName();
case Id_prototype: return getPrototypeProperty();
case Id_arguments: return getArguments();
}
return super.getInstanceIdValue(id);
}
protected void setInstanceIdValue(int id, Object value)
{
protected boolean hasIdValue(int id) {
if (id == Id_prototype) {
if (!isPrototypePropertyImmune) {
prototypeProperty = (value != null)
? value : UniqueTag.NULL_VALUE;
}
return prototypeProperty != NOT_FOUND;
}
else if (id == Id_arguments) {
// Should after delete Function.arguments its activation still
// be available during Function call?
// This code assumes it should not: after default set/deleteIdValue
// hasIdValue/getIdValue would not be called again
// To handle the opposite case, set/deleteIdValue should be
// overwritten as well
return null != getActivation(Context.getContext());
}
return super.hasIdValue(id);
}
protected Object getIdValue(int id) {
switch (id) {
case Id_length: return wrap_int(getLength());
case Id_arity: return wrap_int(getArity());
case Id_name: return getFunctionName();
case Id_prototype: return getPrototypeProperty();
case Id_arguments: return getArguments();
}
return super.getIdValue(id);
}
protected void setIdValue(int id, Object value) {
if (id == Id_prototype) {
prototypeProperty = (value != null) ? value : NULL_TAG;
return;
} else if (id == Id_arguments) {
if (value == NOT_FOUND) {
// This should not be called since "arguments" is PERMANENT
Kit.codeBug();
}
super.setIdValue(id, value);
}
protected void deleteIdValue(int id) {
if (id == Id_prototype) {
prototypeProperty = NOT_FOUND;
return;
}
super.deleteIdValue(id);
}
public int methodArity(int methodId) {
if (prototypeFlag) {
switch (methodId) {
case Id_constructor:
case Id_toString:
case Id_apply:
case Id_call:
return 1;
}
defaultPut("arguments", value);
}
super.setInstanceIdValue(id, value);
return super.methodArity(methodId);
}
protected void fillConstructorProperties(IdFunctionObject ctor)
public Object execMethod(int methodId, IdFunction f, Context cx,
Scriptable scope, Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
// Fix up bootstrapping problem: getPrototype of the IdFunctionObject
// can not return Function.prototype because Function object is not
// yet defined.
ctor.setPrototype(this);
super.fillConstructorProperties(ctor);
}
if (prototypeFlag) {
switch (methodId) {
case Id_constructor:
return jsConstructor(cx, scope, args);
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=1; s="constructor"; break;
case Id_toString: arity=1; s="toString"; break;
case Id_toSource: arity=1; s="toSource"; break;
case Id_apply: arity=2; s="apply"; break;
case Id_call: arity=1; s="call"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(FUNCTION_TAG, id, s, arity);
}
case Id_toString:
return jsFunction_toString(cx, thisObj, args);
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(FUNCTION_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case Id_constructor:
return jsConstructor(cx, scope, args);
case Id_apply:
return jsFunction_apply(cx, scope, thisObj, args);
case Id_toString: {
BaseFunction realf = realFunction(thisObj, f);
int indent = ScriptRuntime.toInt32(args, 0);
return realf.decompile(indent, 0);
}
case Id_toSource: {
BaseFunction realf = realFunction(thisObj, f);
int indent = 0;
int flags = Decompiler.TO_SOURCE_FLAG;
if (args.length != 0) {
indent = ScriptRuntime.toInt32(args[0]);
if (indent >= 0) {
flags = 0;
} else {
indent = 0;
}
case Id_call:
return jsFunction_call(cx, scope, thisObj, args);
}
return realf.decompile(indent, flags);
}
case Id_apply:
case Id_call:
return ScriptRuntime.applyOrCall(id == Id_apply,
cx, scope, thisObj, args);
}
throw new IllegalArgumentException(String.valueOf(id));
}
private BaseFunction realFunction(Scriptable thisObj, IdFunctionObject f)
{
Object x = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
if (x instanceof BaseFunction) {
return (BaseFunction)x;
}
throw ScriptRuntime.typeError1("msg.incompat.call",
f.getFunctionName());
return super.execMethod(methodId, f, cx, scope, thisObj, args);
}
/**
* Make value as DontEnum, DontDelete, ReadOnly
* prototype property of this Function object
* prototype property of this Function object
*/
public void setImmunePrototypeProperty(Object value)
{
if (isPrototypePropertyImmune) {
throw new IllegalStateException();
}
prototypeProperty = (value != null) ? value : UniqueTag.NULL_VALUE;
isPrototypePropertyImmune = true;
public void setImmunePrototypeProperty(Object value) {
prototypeProperty = (value != null) ? value : NULL_TAG;
prototypePropertyAttrs = DONTENUM | READONLY | PERMANENT;
}
protected Scriptable getClassPrototype()
{
protected Scriptable getClassPrototype() {
Object protoVal = getPrototypeProperty();
if (protoVal instanceof Scriptable) {
return (Scriptable) protoVal;
}
return getClassPrototype(this, "Object");
if (protoVal == null
|| !(protoVal instanceof Scriptable)
|| (protoVal == Undefined.instance))
protoVal = getClassPrototype(this, "Object");
return (Scriptable) protoVal;
}
/**
@@ -297,56 +206,23 @@ public class BaseFunction extends IdScriptableObject implements Function
*/
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args)
throws JavaScriptException
{
return Undefined.instance;
}
public Scriptable construct(Context cx, Scriptable scope, Object[] args)
{
Scriptable result = createObject(cx, scope);
if (result != null) {
Object val = call(cx, scope, result, args);
if (val instanceof Scriptable) {
result = (Scriptable)val;
}
} else {
Object val = call(cx, scope, null, args);
if (!(val instanceof Scriptable)) {
// It is program error not to return Scriptable from
// the call method if createObject returns null.
throw new IllegalStateException(
"Bad implementaion of call as constructor, name="
+getFunctionName()+" in "+getClass().getName());
}
result = (Scriptable)val;
if (result.getPrototype() == null) {
result.setPrototype(getClassPrototype());
}
if (result.getParentScope() == null) {
Scriptable parent = getParentScope();
if (result != parent) {
result.setParentScope(parent);
}
}
}
return result;
}
/**
* Creates new script object.
* The default implementation of {@link #construct} uses the method to
* to get the value for <tt>thisObj</tt> argument when invoking
* {@link #call}.
* The methos is allowed to return <tt>null</tt> to indicate that
* {@link #call} will create a new object itself. In this case
* {@link #construct} will set scope and prototype on the result
* {@link #call} unless they are already set.
*/
public Scriptable createObject(Context cx, Scriptable scope)
throws JavaScriptException
{
Scriptable newInstance = new NativeObject();
newInstance.setPrototype(getClassPrototype());
newInstance.setParentScope(getParentScope());
Object val = call(cx, scope, newInstance, args);
if (val instanceof Scriptable && val != Undefined.instance) {
return (Scriptable) val;
}
return newInstance;
}
@@ -354,14 +230,16 @@ public class BaseFunction extends IdScriptableObject implements Function
* Decompile the source information associated with this js
* function/script back into a string.
*
* @param indent How much to indent the decompiled result.
* @param cx Current context
*
* @param flags Flags specifying format of decompilation output.
* @param indent How much to indent the decompiled result
*
* @param justbody Whether the decompilation should omit the
* function header and trailing brace.
*/
String decompile(int indent, int flags)
{
public String decompile(Context cx, int indent, boolean justbody) {
StringBuffer sb = new StringBuffer();
boolean justbody = (0 != (flags & Decompiler.ONLY_BODY_FLAG));
if (!justbody) {
sb.append("function ");
sb.append(getFunctionName());
@@ -380,14 +258,20 @@ public class BaseFunction extends IdScriptableObject implements Function
public int getLength() { return 0; }
public String getFunctionName()
{
return "";
public String getFunctionName() {
if (functionName == null)
return "";
if (functionName.equals("anonymous")) {
Context cx = Context.getCurrentContext();
if (cx != null && cx.getLanguageVersion() == Context.VERSION_1_2)
return "";
}
return functionName;
}
final Object getPrototypeProperty() {
private Object getPrototypeProperty() {
Object result = prototypeProperty;
if (result == null) {
if (result == null) {
synchronized (this) {
result = prototypeProperty;
if (result == null) {
@@ -396,115 +280,219 @@ public class BaseFunction extends IdScriptableObject implements Function
}
}
}
else if (result == UniqueTag.NULL_VALUE) { result = null; }
else if (result == NULL_TAG) { result = null; }
return result;
}
private void setupDefaultPrototype()
{
private void setupDefaultPrototype() {
NativeObject obj = new NativeObject();
final int attr = ScriptableObject.DONTENUM;
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.
prototypeProperty = obj;
Scriptable proto = getObjectPrototype(this);
Scriptable proto = getObjectPrototype(this);
if (proto != obj) {
// not the one we just made, it must remain grounded
obj.setPrototype(proto);
}
}
private Object getArguments()
{
// <Function name>.arguments is deprecated, so we use a slow
// way of getting it that doesn't add to the invocation cost.
// TODO: add warning, error based on version
Object value = defaultGet("arguments");
if (value != NOT_FOUND) {
// Should after changing <Function name>.arguments its
// activation still be available during Function call?
// This code assumes it should not:
// defaultGet("arguments") != NOT_FOUND
// means assigned arguments
return value;
}
Context cx = Context.getContext();
NativeCall activation = ScriptRuntime.findFunctionActivation(cx, this);
return (activation == null)
? null
: activation.get("arguments", activation);
private Object getArguments() {
// <Function name>.arguments is deprecated, so we use a slow
// way of getting it that doesn't add to the invocation cost.
// TODO: add warning, error based on version
NativeCall activation = getActivation(Context.getContext());
return activation == null
? null
: activation.get("arguments", activation);
}
private static Object jsConstructor(Context cx, Scriptable scope,
NativeCall getActivation(Context cx) {
NativeCall activation = cx.currentActivation;
while (activation != null) {
if (activation.getFunctionObject() == this)
return activation;
activation = activation.caller;
}
return null;
}
private static Object jsConstructor(Context cx, Scriptable scope,
Object[] args)
{
int arglen = args.length;
StringBuffer sourceBuf = new StringBuffer();
StringBuffer funArgs = new StringBuffer();
sourceBuf.append("function ");
/* version != 1.2 Function constructor behavior -
* print 'anonymous' as the function name if the
* version (under which the function was compiled) is
* less than 1.2... or if it's greater than 1.2, because
* we need to be closer to ECMA.
*/
if (cx.getLanguageVersion() != Context.VERSION_1_2) {
sourceBuf.append("anonymous");
}
sourceBuf.append('(');
/* Collect the arguments into a string. */
// Append arguments as coma separated strings
for (int i = 0; i < arglen - 1; i++) {
if (i > 0) {
sourceBuf.append(',');
}
sourceBuf.append(ScriptRuntime.toString(args[i]));
int i;
for (i = 0; i < arglen - 1; i++) {
if (i > 0)
funArgs.append(',');
funArgs.append(ScriptRuntime.toString(args[i]));
}
sourceBuf.append(") {");
if (arglen != 0) {
// append function body
String funBody = ScriptRuntime.toString(args[arglen - 1]);
sourceBuf.append(funBody);
}
sourceBuf.append('}');
String source = sourceBuf.toString();
String funBody = arglen == 0 ? "" : ScriptRuntime.toString(args[i]);
int[] linep = new int[1];
String source = "function (" + funArgs.toString() + ") {" +
funBody + "}";
int[] linep = { 0 };
String filename = Context.getSourcePositionFromStack(linep);
if (filename == null) {
filename = "<eval'ed string>";
linep[0] = 1;
}
String sourceURI = ScriptRuntime.
makeUrlForGeneratedScript(false, filename, linep[0]);
Object securityDomain = cx.getSecurityDomainForStackDepth(4);
Scriptable global = ScriptableObject.getTopLevelScope(scope);
ErrorReporter reporter;
reporter = DefaultErrorReporter.forEval(cx.getErrorReporter());
// Compile with explicit interpreter instance to force interpreter
// Compile the function with opt level of -1 to force interpreter
// mode.
return cx.compileFunction(global, source, new Interpreter(), reporter,
sourceURI, 1, null);
int oldOptLevel = cx.getOptimizationLevel();
cx.setOptimizationLevel(-1);
NativeFunction fn;
try {
fn = (NativeFunction) cx.compileFunction(global, source,
filename, linep[0],
securityDomain);
}
finally { cx.setOptimizationLevel(oldOptLevel); }
fn.functionName = "anonymous";
fn.setPrototype(getFunctionPrototype(global));
fn.setParentScope(global);
return fn;
}
protected int findPrototypeId(String s)
private static Object jsFunction_toString(Context cx, Scriptable thisObj,
Object[] args)
{
int id;
int indent = ScriptRuntime.toInt32(args, 0);
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
if (val instanceof BaseFunction) {
return ((BaseFunction)val).decompile(cx, indent, false);
}
throw NativeGlobal.typeError1("msg.incompat.call", "toString", thisObj);
}
/**
* Function.prototype.apply
*
* A proposed ECMA extension for round 2.
*/
private static Object jsFunction_apply(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
throws JavaScriptException
{
if (args.length != 2)
return jsFunction_call(cx, scope, thisObj, args);
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
Scriptable newThis = args[0] == null
? ScriptableObject.getTopLevelScope(thisObj)
: ScriptRuntime.toObject(scope, 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.typeError0("msg.arg.isnt.array", thisObj);
}
else
newArgs = ScriptRuntime.emptyArgs;
return ScriptRuntime.call(cx, val, newThis, newArgs, newThis);
}
/**
* Function.prototype.call
*
* A proposed ECMA extension for round 2.
*/
private static Object jsFunction_call(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
throws JavaScriptException
{
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
if (args.length == 0) {
Scriptable s = ScriptRuntime.toObject(scope, val);
Scriptable topScope = s.getParentScope();
return ScriptRuntime.call(cx, val,
topScope, ScriptRuntime.emptyArgs,
topScope);
} else {
Scriptable newThis = args[0] == null
? ScriptableObject.getTopLevelScope(thisObj)
: ScriptRuntime.toObject(scope, 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);
}
}
protected int maxInstanceId() { return MAX_INSTANCE_ID; }
protected String getIdName(int id) {
switch (id) {
case Id_length: return "length";
case Id_arity: return "arity";
case Id_name: return "name";
case Id_prototype: return "prototype";
case Id_arguments: return "arguments";
}
if (prototypeFlag) {
switch (id) {
case Id_constructor: return "constructor";
case Id_toString: return "toString";
case Id_apply: return "apply";
case Id_call: return "call";
}
}
return null;
}
// #string_id_map#
// #generated# Last update: 2004-03-17 13:23:22 CET
private static final int
Id_length = 1,
Id_arity = 2,
Id_name = 3,
Id_prototype = 4,
Id_arguments = 5,
MAX_INSTANCE_ID = 5;
protected int mapNameToId(String s) {
int id;
// #generated# Last update: 2001-05-20 00:12:12 GMT+02:00
L0: { id = 0; String X = null; int c;
L: switch (s.length()) {
case 4: X="name";id=Id_name; break L;
case 5: X="arity";id=Id_arity; break L;
case 6: X="length";id=Id_length; break L;
case 9: c=s.charAt(0);
if (c=='a') { X="arguments";id=Id_arguments; }
else if (c=='p') { X="prototype";id=Id_prototype; }
break L;
}
if (X!=null && X!=s && !X.equals(s)) id = 0;
}
// #/generated#
// #/string_id_map#
if (id != 0 || !prototypeFlag) { return id; }
// #string_id_map#
// #generated# Last update: 2001-05-20 00:12:12 GMT+02:00
L0: { id = 0; String X = null;
L: switch (s.length()) {
case 4: X="call";id=Id_call; break L;
case 5: X="apply";id=Id_apply; break L;
case 8: c=s.charAt(3);
if (c=='o') { X="toSource";id=Id_toSource; }
else if (c=='t') { X="toString";id=Id_toString; }
break L;
case 8: X="toString";id=Id_toString; break L;
case 11: X="constructor";id=Id_constructor; break L;
}
if (X!=null && X!=s && !X.equals(s)) id = 0;
@@ -514,17 +502,20 @@ public class BaseFunction extends IdScriptableObject implements Function
}
private static final int
Id_constructor = 1,
Id_toString = 2,
Id_toSource = 3,
Id_apply = 4,
Id_call = 5,
MAX_PROTOTYPE_ID = 5;
Id_constructor = MAX_INSTANCE_ID + 1,
Id_toString = MAX_INSTANCE_ID + 2,
Id_apply = MAX_INSTANCE_ID + 3,
Id_call = MAX_INSTANCE_ID + 4,
MAX_PROTOTYPE_ID = MAX_INSTANCE_ID + 4;
// #/string_id_map#
protected String functionName;
private Object prototypeProperty;
private boolean isPrototypePropertyImmune;
private Object prototypeProperty;
private int prototypePropertyAttrs = DONTENUM;
private boolean prototypeFlag;
}

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.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):
* 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.
*/
package org.mozilla.javascript;
final class BinaryDigitReader {
int lgBase; // Logarithm of base of number
int digit; // Current digit value in radix given by base
int digitPos; // Bit position of last bit extracted from digit
String digits; // String containing the digits
int start; // Index of the first remaining digit
int end; // Index past the last remaining digit
BinaryDigitReader(int base, String digits, int start, int end) {
lgBase = 0;
while (base != 1) {
lgBase++;
base >>= 1;
}
digitPos = 0;
this.digits = digits;
this.start = start;
this.end = end;
}
/* Return the next binary digit from the number or -1 if done */
int getNextBinaryDigit()
{
if (digitPos == 0) {
if (start == end)
return -1;
char c = digits.charAt(start++);
if ('0' <= c && c <= '9')
digit = c - '0';
else if ('a' <= c && c <= 'z')
digit = c - 'a' + 10;
else digit = c - 'A' + 10;
digitPos = lgBase;
}
return digit >> --digitPos & 1;
}
}

View File

@@ -1,59 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Igor Bukanov, igor@fastmail.fm
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.javascript;
/**
* Generic notion of callable object that can execute some script-related code
* upon request with specified values for script scope and this objects.
*/
public interface Callable
{
/**
* Perform the call.
*
* @param cx the current Context for this thread
* @param scope the scope to use to resolve properties.
* @param thisObj the JavaScript <code>this</code> object
* @param args the array of arguments
* @return the result of the call
*/
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args);
}

View File

@@ -1,214 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Igor Bukanov, igor@fastmail.fm
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.javascript;
import java.util.Hashtable;
/**
* Cache of generated classes and data structures to access Java runtime
* from JavaScript.
*
* @author Igor Bukanov
*
* @since Rhino 1.5 Release 5
*/
public class ClassCache
{
private static final Object AKEY = new Object();
private volatile boolean cachingIsEnabled = true;
Hashtable classTable = new Hashtable();
Hashtable javaAdapterGeneratedClasses = new Hashtable();
ScriptableObject scope;
private Hashtable interfaceAdapterCache;
private int generatedClassSerial;
/**
* Search for ClassCache object in the given scope.
* The method first calls
* {@link ScriptableObject#getTopLevelScope(Scriptable scope)}
* to get the top most scope and then tries to locate associated
* ClassCache object in the prototype chain of the top scope.
*
* @param scope scope to search for ClassCache object.
* @return previously associated ClassCache object or a new instance of
* ClassCache if no ClassCache object was found.
*
* @see #associate(ScriptableObject topScope)
*/
public static ClassCache get(Scriptable scope)
{
ClassCache cache;
cache = (ClassCache)ScriptableObject.getTopScopeValue(scope, AKEY);
if (cache == null) {
// XXX warn somehow about wrong cache usage ?
cache = new ClassCache();
}
return cache;
}
/**
* Associate ClassCache object with the given top-level scope.
* The ClassCache object can only be associated with the given scope once.
*
* @param topScope scope to associate this ClassCache object with.
* @return true if no prevous ClassCache objects were embedded into
* the scope and this ClassCache were successfully associated
* or false otherwise.
*
* @see #get(Scriptable scope)
*/
public boolean associate(ScriptableObject topScope)
{
if (topScope.getParentScope() != null) {
// Can only associate cache with top level scope
throw new IllegalArgumentException();
}
if(this == topScope.associateValue(AKEY, this)) {
scope = topScope;
return true;
}
return false;
}
/**
* Empty caches of generated Java classes and Java reflection information.
*/
public synchronized void clearCaches()
{
classTable = new Hashtable();
javaAdapterGeneratedClasses = new Hashtable();
interfaceAdapterCache = null;
}
/**
* Check if generated Java classes and Java reflection information
* is cached.
*/
public final boolean isCachingEnabled()
{
return cachingIsEnabled;
}
/**
* Set whether to cache some values.
* <p>
* By default, the engine will cache the results of
* <tt>Class.getMethods()</tt> and similar calls.
* 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.
* <p>
* Caching is enabled by default.
*
* @param enabled if true, caching is enabled
*
* @see #clearCaches()
*/
public synchronized void setCachingEnabled(boolean enabled)
{
if (enabled == cachingIsEnabled)
return;
if (!enabled)
clearCaches();
cachingIsEnabled = enabled;
}
/**
* @deprecated
* The method always returns false.
* @see #setInvokerOptimizationEnabled(boolean enabled)
*/
public boolean isInvokerOptimizationEnabled()
{
return false;
}
/**
* @deprecated
* The method does nothing.
* Invoker optimization is no longer used by Rhino.
* On modern JDK like 1.4 or 1.5 the disadvatages of the optimization
* like incresed memory usage or longer initialization time overweight
* small speed increase that can be gained using generated proxy class
* to replace reflection.
*/
public synchronized void setInvokerOptimizationEnabled(boolean enabled)
{
}
/**
* Internal engine method to return serial number for generated classes
* to ensure name uniqueness.
*/
public final synchronized int newClassSerialNumber()
{
return ++generatedClassSerial;
}
Object getInterfaceAdapter(Class cl)
{
Object result;
Hashtable cache = interfaceAdapterCache;
if (cache == null) {
result = null;
} else {
result = cache.get(cl);
}
return result;
}
synchronized void cacheInterfaceAdapter(Class cl, Object iadapter)
{
if (cachingIsEnabled) {
if (interfaceAdapterCache == null) {
interfaceAdapterCache = new Hashtable();
}
interfaceAdapterCache.put(cl, iadapter);
}
}
}

View File

@@ -0,0 +1,48 @@
/* -*- 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):
*
* 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;
/**
* Thrown if errors are detected while attempting to define a host object
* from a Java class.
*/
public class ClassDefinitionException extends Exception {
public ClassDefinitionException(String detail) {
super(detail);
}
}

View File

@@ -0,0 +1,60 @@
/* -*- 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
* Roger Lawrence
* Andi Vajda
* Kemal Bayram
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
package org.mozilla.javascript;
public interface ClassNameHelper {
public String getTargetPackage();
public void setTargetPackage(String targetPackage);
public void setTargetExtends(Class extendsClass);
public void setTargetImplements(Class[] implementsClasses);
public ClassRepository getClassRepository();
public void setClassRepository(ClassRepository repository);
public String getClassName();
public void setClassName(String initialName);
public void reset();
}

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.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.
* @param isTopLevel if true, represents the top-level script being compiled
* @return a stream into which to write bytecode.
* @since 1.5 Release 2
*/
public OutputStream getOutputStream(String className, boolean isTopLevel)
throws IOException;

View File

@@ -0,0 +1,55 @@
/* -*- 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):
* Kemal Bayram
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
package org.mozilla.javascript;
import java.io.*;
/**
* This interface provides a means to store generated class and to
* allow selective class loading.
*
* @see Context
* @author Kemal Bayram
*/
public interface ClassRepository {
/**
* @param className the name of the class.
* @param classBytes a byte array of the generated class.
* @param isTopLevel if true, represents the top-level script being compiled.
* @return true if the class should be loaded, false otherwise.
*/
public boolean storeClass(String className, byte[] classBytes,
boolean isTopLevel) throws IOException;
}

View File

@@ -1,89 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Norris Boyd
* Igor Bukanov
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
// API class
package org.mozilla.javascript;
/**
Embeddings that wish to filter Java classes that are visible to scripts
through the LiveConnect, should implement this interface.
@see Context#setClassShutter(ClassShutter)
@since 1.5 Release 4
@author Norris Boyd
*/
public interface ClassShutter {
/**
* Return true iff the Java class with the given name should be exposed
* to scripts.
* <p>
* An embedding may filter which Java classes are exposed through
* LiveConnect to JavaScript scripts.
* <p>
* Due to the fact that there is no package reflection in Java,
* this method will also be called with package names. There
* is no way for Rhino to tell if "Packages.a.b" is a package name
* or a class that doesn't exist. What Rhino does is attempt
* to load each segment of "Packages.a.b.c": It first attempts to
* load class "a", then attempts to load class "a.b", then
* finally attempts to load class "a.b.c". On a Rhino installation
* without any ClassShutter set, and without any of the
* above classes, the expression "Packages.a.b.c" will result in
* a [JavaPackage a.b.c] and not an error.
* <p>
* With ClassShutter supplied, Rhino will first call
* visibleToScripts before attempting to look up the class name. If
* visibleToScripts returns false, the class name lookup is not
* performed and subsequent Rhino execution assumes the class is
* not present. So for "java.lang.System.out.println" the lookup
* of "java.lang.System" is skipped and thus Rhino assumes that
* "java.lang.System" doesn't exist. So then for "java.lang.System.out",
* Rhino attempts to load the class "java.lang.System.out" because
* it assumes that "java.lang.System" is a package name.
* <p>
* @param fullClassName the full name of the class (including the package
* name, with '.' as a delimiter). For example the
* standard string class is "java.lang.String"
* @return whether or not to reveal this class to scripts
*/
public boolean visibleToScripts(String fullClassName);
}

View File

@@ -1,187 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Igor Bukanov, igor@fastmail.fm
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.javascript;
import java.util.Hashtable;
public class CompilerEnvirons
{
public CompilerEnvirons()
{
errorReporter = DefaultErrorReporter.instance;
languageVersion = Context.VERSION_DEFAULT;
generateDebugInfo = true;
useDynamicScope = false;
reservedKeywordAsIdentifier = false;
allowMemberExprAsFunctionName = false;
xmlAvailable = true;
optimizationLevel = 0;
generatingSource = true;
}
public void initFromContext(Context cx)
{
setErrorReporter(cx.getErrorReporter());
this.languageVersion = cx.getLanguageVersion();
useDynamicScope = cx.compileFunctionsWithDynamicScopeFlag;
generateDebugInfo = (!cx.isGeneratingDebugChanged()
|| cx.isGeneratingDebug());
reservedKeywordAsIdentifier
= cx.hasFeature(Context.FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER);
allowMemberExprAsFunctionName
= cx.hasFeature(Context.FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME);
xmlAvailable
= cx.hasFeature(Context.FEATURE_E4X);
optimizationLevel = cx.getOptimizationLevel();
generatingSource = cx.isGeneratingSource();
activationNames = cx.activationNames;
}
public final ErrorReporter getErrorReporter()
{
return errorReporter;
}
public void setErrorReporter(ErrorReporter errorReporter)
{
if (errorReporter == null) throw new IllegalArgumentException();
this.errorReporter = errorReporter;
}
public final int getLanguageVersion()
{
return languageVersion;
}
public void setLanguageVersion(int languageVersion)
{
Context.checkLanguageVersion(languageVersion);
this.languageVersion = languageVersion;
}
public final boolean isGenerateDebugInfo()
{
return generateDebugInfo;
}
public void setGenerateDebugInfo(boolean flag)
{
this.generateDebugInfo = flag;
}
public final boolean isUseDynamicScope()
{
return useDynamicScope;
}
public final boolean isReservedKeywordAsIdentifier()
{
return reservedKeywordAsIdentifier;
}
public void setReservedKeywordAsIdentifier(boolean flag)
{
reservedKeywordAsIdentifier = flag;
}
public final boolean isAllowMemberExprAsFunctionName()
{
return allowMemberExprAsFunctionName;
}
public void setAllowMemberExprAsFunctionName(boolean flag)
{
allowMemberExprAsFunctionName = flag;
}
public final boolean isXmlAvailable()
{
return xmlAvailable;
}
public void setXmlAvailable(boolean flag)
{
xmlAvailable = flag;
}
public final int getOptimizationLevel()
{
return optimizationLevel;
}
public void setOptimizationLevel(int level)
{
Context.checkOptimizationLevel(level);
this.optimizationLevel = level;
}
public final boolean isGeneratingSource()
{
return generatingSource;
}
/**
* Specify whether or not source information should be generated.
* <p>
* Without source information, evaluating the "toString" method
* on JavaScript functions produces only "[native code]" for
* the body of the function.
* Note that code generated without source is not fully ECMA
* conformant.
*/
public void setGeneratingSource(boolean generatingSource)
{
this.generatingSource = generatingSource;
}
private ErrorReporter errorReporter;
private int languageVersion;
private boolean generateDebugInfo;
private boolean useDynamicScope;
private boolean reservedKeywordAsIdentifier;
private boolean allowMemberExprAsFunctionName;
private boolean xmlAvailable;
private int optimizationLevel;
private boolean generatingSource;
Hashtable activationNames;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,59 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Igor Bukanov, igor@fastmail.fm
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
// API class
package org.mozilla.javascript;
/**
* Interface to represent arbitrary action that requires to have Context
* object associated with the current thread for its execution.
*/
public interface ContextAction
{
/**
* Execute action using the supplied Context instance.
* When Rhino runtime calls the method, <tt>cx</tt> will be associated
* with the current thread as active context.
*
* @see Context#call(ContextAction)
* @see ContextFactory#call(ContextAction)
*/
public Object run(Context cx);
}

View File

@@ -1,485 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Igor Bukanov, igor@fastmail.fm
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (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
* MPL, indicate your decision by deleting the provisions above and replacing
* 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 MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */
// API class
package org.mozilla.javascript;
/**
* Factory class that Rhino runtime use to create new {@link Context}
* instances or to notify about Context execution.
* <p>
* When Rhino runtime needs to create new {@link Context} instance during
* execution of {@link Context#enter()} or {@link Context}, it will call
* {@link #makeContext()} of the current global ContextFactory.
* See {@link #getGlobal()} and {@link #initGlobal(ContextFactory)}.
* <p>
* It is also possible to use explicit ContextFactory instances for Context
* creation. This is useful to have a set of independent Rhino runtime
* instances under single JVM. See {@link #call(ContextAction)}.
* <p>
* The following example demonstrates Context customization to terminate
* scripts running more then 10 seconds and to provide better compatibility
* with JavaScript code using MSIE-specific features.
* <pre>
* import org.mozilla.javascript.*;
*
* class MyFactory extends ContextFactory
* {
*
* // Custom {@link Context} to store execution time.
* private static class MyContext extends Context
* {
* long startTime;
* }
*
* static {
* // Initialize GlobalFactory with custom factory
* ContextFactory.initGlobal(new MyFactory());
* }
*
* // Override {@link #makeContext()}
* protected Context makeContext()
* {
* MyContext cx = new MyContext();
* // Use pure interpreter mode to allow for
* // {@link #observeInstructionCount(Context, int)} to work
* cx.setOptimizationLevel(-1);
* // Make Rhino runtime to call observeInstructionCount
* // each 10000 bytecode instructions
* cx.setInstructionObserverThreshold(10000);
* return cx;
* }
*
* // Override {@link #hasFeature(Context, int)}
* public boolean hasFeature(Context cx, int featureIndex)
* {
* // Turn on maximum compatibility with MSIE scripts
* switch (featureIndex) {
* case {@link Context#FEATURE_NON_ECMA_GET_YEAR}:
* return true;
*
* case {@link Context#FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME}:
* return true;
*
* case {@link Context#FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER}:
* return true;
*
* case {@link Context#FEATURE_PARENT_PROTO_PROPRTIES}:
* return false;
* }
* return super.hasFeature(cx, featureIndex);
* }
*
* // Override {@link #observeInstructionCount(Context, int)}
* protected void observeInstructionCount(Context cx, int instructionCount)
* {
* MyContext mcx = (MyContext)cx;
* long currentTime = System.currentTimeMillis();
* if (currentTime - mcx.startTime > 10*1000) {
* // More then 10 seconds from Context creation time:
* // it is time to stop the script.
* // Throw Error instance to ensure that script will never
* // get control back through catch or finally.
* throw new Error();
* }
* }
*
* // Override {@link #doTopCall(Callable, Context, Scriptable scope, Scriptable thisObj, Object[] args)}
* protected Object doTopCall(Callable callable,
* Context cx, Scriptable scope,
* Scriptable thisObj, Object[] args)
* {
* MyContext mcx = (MyContext)cx;
* mcx.startTime = System.currentTimeMillis();
*
* return super.doTopCall(callable, cx, scope, thisObj, args);
* }
*
* }
*
* </pre>
*/
public class ContextFactory
{
private static volatile boolean hasCustomGlobal;
private static ContextFactory global = new ContextFactory();
private volatile boolean sealed;
private final Object listenersLock = new Object();
private volatile Object listeners;
private boolean disabledListening;
private ClassLoader applicationClassLoader;
/**
* Listener of {@link Context} creation and release events.
*/
public interface Listener
{
/**
* Notify about newly created {@link Context} object.
*/
public void contextCreated(Context cx);
/**
* Notify that the specified {@link Context} instance is no longer
* associated with the current thread.
*/
public void contextReleased(Context cx);
}
/**
* Get global ContextFactory.
*
* @see #hasExplicitGlobal()
* @see #initGlobal(ContextFactory)
*/
public static ContextFactory getGlobal()
{
return global;
}
/**
* Check if global factory was set.
* Return true to indicate that {@link #initGlobal(ContextFactory)} was
* already called and false to indicate that the global factory was not
* explicitly set.
*
* @see #getGlobal()
* @see #initGlobal(ContextFactory)
*/
public static boolean hasExplicitGlobal()
{
return hasCustomGlobal;
}
/**
* Set global ContextFactory.
* The method can only be called once.
*
* @see #getGlobal()
* @see #hasExplicitGlobal()
*/
public static void initGlobal(ContextFactory factory)
{
if (factory == null) {
throw new IllegalArgumentException();
}
if (hasCustomGlobal) {
throw new IllegalStateException();
}
hasCustomGlobal = true;
global = factory;
}
/**
* Create new {@link Context} instance to be associated with the current
* thread.
* This is a callback method used by Rhino to create {@link Context}
* instance when it is necessary to associate one with the current
* execution thread. <tt>makeContext()</tt> is allowed to call
* {@link Context#seal(Object)} on the result to prevent
* {@link Context} changes by hostile scripts or applets.
*/
protected Context makeContext()
{
return new Context();
}
/**
* Implementation of {@link Context#hasFeature(int featureIndex)}.
* This can be used to customize {@link Context} without introducing
* additional subclasses.
*/
protected boolean hasFeature(Context cx, int featureIndex)
{
int version;
switch (featureIndex) {
case Context.FEATURE_NON_ECMA_GET_YEAR:
/*
* During the great date rewrite of 1.3, we tried to track the
* evolving ECMA standard, which then had a definition of
* getYear which always subtracted 1900. Which we
* implemented, not realizing that it was incompatible with
* the old behavior... now, rather than thrash the behavior
* yet again, we've decided to leave it with the - 1900
* behavior and point people to the getFullYear method. But
* we try to protect existing scripts that have specified a
* version...
*/
version = cx.getLanguageVersion();
return (version == Context.VERSION_1_0
|| version == Context.VERSION_1_1
|| version == Context.VERSION_1_2);
case Context.FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME:
return false;
case Context.FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER:
return false;
case Context.FEATURE_TO_STRING_AS_SOURCE:
version = cx.getLanguageVersion();
return version == Context.VERSION_1_2;
case Context.FEATURE_PARENT_PROTO_PROPRTIES:
return true;
case Context.FEATURE_E4X:
version = cx.getLanguageVersion();
return (version == Context.VERSION_DEFAULT
|| version >= Context.VERSION_1_6);
case Context.FEATURE_DYNAMIC_SCOPE:
return false;
case Context.FEATURE_STRICT_VARS:
return false;
case Context.FEATURE_STRICT_EVAL:
return false;
}
// It is a bug to call the method with unknown featureIndex
throw new IllegalArgumentException(String.valueOf(featureIndex));
}
/**
* Create class loader for generated classes.
* This method creates an instance of the default implementation
* of {@link GeneratedClassLoader}. Rhino uses this interface to load
* generated JVM classes when no {@link SecurityController}
* is installed.
* Application can override the method to provide custom class loading.
*/
protected GeneratedClassLoader createClassLoader(ClassLoader parent)
{
return new DefiningClassLoader(parent);
}
/**
* Get ClassLoader to use when searching for Java classes.
* Unless it was explicitly initialized with
* {@link #initApplicationClassLoader(ClassLoader)} the method returns
* null to indicate that Thread.getContextClassLoader() should be used.
*/
public final ClassLoader getApplicationClassLoader()
{
return applicationClassLoader;
}
/**
* Set explicit class loader to use when searching for Java classes.
*
* @see #getApplicationClassLoader()
*/
public final void initApplicationClassLoader(ClassLoader loader)
{
if (loader == null)
throw new IllegalArgumentException("loader is null");
if (!Kit.testIfCanLoadRhinoClasses(loader))
throw new IllegalArgumentException(
"Loader can not resolve Rhino classes");
if (this.applicationClassLoader != null)
throw new IllegalStateException(
"applicationClassLoader can only be set once");
checkNotSealed();
this.applicationClassLoader = loader;
}
/**
* Execute top call to script or function.
* When the runtime is about to execute a script or function that will
* create the first stack frame with scriptable code, it calls this method
* to perform the real call. In this way execution of any script
* happens inside this function.
*/
protected Object doTopCall(Callable callable,
Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
return callable.call(cx, scope, thisObj, args);
}
/**
* Implementation of
* {@link Context#observeInstructionCount(int instructionCount)}.
* This can be used to customize {@link Context} without introducing
* additional subclasses.
*/
protected void observeInstructionCount(Context cx, int instructionCount)
{
}
protected void onContextCreated(Context cx)
{
Object listeners = this.listeners;
for (int i = 0; ; ++i) {
Listener l = (Listener)Kit.getListener(listeners, i);
if (l == null)
break;
l.contextCreated(cx);
}
}
protected void onContextReleased(Context cx)
{
Object listeners = this.listeners;
for (int i = 0; ; ++i) {
Listener l = (Listener)Kit.getListener(listeners, i);
if (l == null)
break;
l.contextReleased(cx);
}
}
public final void addListener(Listener listener)
{
checkNotSealed();
synchronized (listenersLock) {
if (disabledListening) {
throw new IllegalStateException();
}
listeners = Kit.addListener(listeners, listener);
}
}
public final void removeListener(Listener listener)
{
checkNotSealed();
synchronized (listenersLock) {
if (disabledListening) {
throw new IllegalStateException();
}
listeners = Kit.removeListener(listeners, listener);
}
}
/**
* The method is used only to imlement
* Context.disableStaticContextListening()
*/
final void disableContextListening()
{
checkNotSealed();
synchronized (listenersLock) {
disabledListening = true;
listeners = null;
}
}
/**
* Checks if this is a sealed ContextFactory.
* @see #seal()
*/
public final boolean isSealed()
{
return sealed;
}
/**
* Seal this ContextFactory so any attempt to modify it like to add or
* remove its listeners will throw an exception.
* @see #isSealed()
*/
public final void seal()
{
checkNotSealed();
sealed = true;
}
protected final void checkNotSealed()
{
if (sealed) throw new IllegalStateException();
}
/**
* Call {@link ContextAction#run(Context cx)}
* using the {@link Context} instance associated with the current thread.
* If no Context is associated with the thread, then
* {@link #makeContext()} will be called to construct
* new Context instance. The instance will be temporary associated
* with the thread during call to {@link ContextAction#run(Context)}.
*
* @see ContextFactory#call(ContextAction)
* @see Context#call(ContextFactory factory, Callable callable,
* Scriptable scope, Scriptable thisObj,
* Object[] args)
*/
public final Object call(ContextAction action)
{
return Context.call(this, action);
}
/**
* Same as {@link Context#enter()} with the difference that if a new context
* needs to be created, then this context factory is used to create it
* instead of the global context factory.
* @return a Context associated with the current thread
*/
public final Context enter()
{
return enter(null);
}
/**
* Same as {@link Context#enter(Context)} with the difference that if a new
* context needs to be created, then this context factory is used to create
* it instead of the global context factory.
* @return a Context associated with the current thread
*/
public final Context enter(Context cx)
{
return Context.enter(cx, this);
}
/**
* Same as {@link Context#exit()}, although if you used {@link #enter()} or
* {@link #enter(Context)} methods on this object, you should use this exit
* method instead of the static one in {@link Context}.
*/
public final void exit()
{
Context.exit(this);
}
}

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