Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a66fb74e4e | ||
|
|
c46072a78b |
32
mozilla/js/rhino/CHANGELOG
Normal file
32
mozilla/js/rhino/CHANGELOG
Normal file
@@ -0,0 +1,32 @@
|
||||
This file version: $Id: CHANGELOG,v 1.1.1.1 2007-02-05 13:34:43 inonit%inonit.com Exp $
|
||||
|
||||
Changes since Rhino 1.6R5
|
||||
=========================
|
||||
- Added org.mozilla.javascript.PolicySecurityController as a concrete
|
||||
implementation of an org.mozilla.javascript.SecurityController and the
|
||||
preferred way of integrating with Java security architecture.
|
||||
- When no security controller is in use, generated classes and scripts run in
|
||||
the ProtectionDomain of Rhino classes.
|
||||
- Wrapped access to system properties and creation of class loaders into
|
||||
AccessController.doPrivileged() to nicely play in secured environments.
|
||||
- Added implementation of __defineGetter__ and __defineSetter__ to match
|
||||
SpiderMonkey. __lookupGetter__ and __lookupSetter__ are not
|
||||
implemented, nor are the JS get and set keywords. Also see #224334.
|
||||
- Fixed #318305: ScriptOrFnNode class reports bad end line number
|
||||
- Fixed #352319: Rhino threw a ClassCastException when a continuation captured
|
||||
from a catch() block was restarted.
|
||||
- Fixed #340561: <Function>.prototype should not be DontEnum
|
||||
- Fixed #342807: Could set line number/source file in thrown JavaScript Error
|
||||
- Fixed #350580: importPackage Ambiguous import error fix
|
||||
- Fixed #351664: Rethrown JavaScriptException's toString() returns
|
||||
"[object Error]"
|
||||
- Fixed #353300: Rhino now implements the ECMA-262 mandatory
|
||||
String.localeCompare
|
||||
- Fixed #353002: Outdated Information on BSF, Update Requested, Text Suggestion
|
||||
Enclosed
|
||||
- Fixed #358058: JavaScript debugger's text source editor allows tab key
|
||||
presses
|
||||
- Fixed #359411: LazilyLoadedCtor is not serializable
|
||||
- Fixed #360568: Make swing debugger easier to subclass and extend
|
||||
- Fixed #361574: Typo in Parser.java
|
||||
- Fixed #361616: toLocaleUpperCase/toLocaleLowerCase is not supported
|
||||
@@ -1,851 +0,0 @@
|
||||
The majority of Rhino is MPL 1.1 / GPL 2.0 dual licensed:
|
||||
|
||||
The Mozilla Public License (http://www.mozilla.org/MPL/MPL-1.1.txt):
|
||||
============================================================================
|
||||
MOZILLA PUBLIC LICENSE
|
||||
Version 1.1
|
||||
|
||||
---------------
|
||||
|
||||
1. Definitions.
|
||||
|
||||
1.0.1. "Commercial Use" means distribution or otherwise making the
|
||||
Covered Code available to a third party.
|
||||
|
||||
1.1. "Contributor" means each entity that creates or contributes to
|
||||
the creation of Modifications.
|
||||
|
||||
1.2. "Contributor Version" means the combination of the Original
|
||||
Code, prior Modifications used by a Contributor, and the Modifications
|
||||
made by that particular Contributor.
|
||||
|
||||
1.3. "Covered Code" means the Original Code or Modifications or the
|
||||
combination of the Original Code and Modifications, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.4. "Electronic Distribution Mechanism" means a mechanism generally
|
||||
accepted in the software development community for the electronic
|
||||
transfer of data.
|
||||
|
||||
1.5. "Executable" means Covered Code in any form other than Source
|
||||
Code.
|
||||
|
||||
1.6. "Initial Developer" means the individual or entity identified
|
||||
as the Initial Developer in the Source Code notice required by Exhibit
|
||||
A.
|
||||
|
||||
1.7. "Larger Work" means a work which combines Covered Code or
|
||||
portions thereof with code not governed by the terms of this License.
|
||||
|
||||
1.8. "License" means this document.
|
||||
|
||||
1.8.1. "Licensable" means having the right to grant, to the maximum
|
||||
extent possible, whether at the time of the initial grant or
|
||||
subsequently acquired, any and all of the rights conveyed herein.
|
||||
|
||||
1.9. "Modifications" means any addition to or deletion from the
|
||||
substance or structure of either the Original Code or any previous
|
||||
Modifications. When Covered Code is released as a series of files, a
|
||||
Modification is:
|
||||
A. Any addition to or deletion from the contents of a file
|
||||
containing Original Code or previous Modifications.
|
||||
|
||||
B. Any new file that contains any part of the Original Code or
|
||||
previous Modifications.
|
||||
|
||||
1.10. "Original Code" means Source Code of computer software code
|
||||
which is described in the Source Code notice required by Exhibit A as
|
||||
Original Code, and which, at the time of its release under this
|
||||
License is not already Covered Code governed by this License.
|
||||
|
||||
1.10.1. "Patent Claims" means any patent claim(s), now owned or
|
||||
hereafter acquired, including without limitation, method, process,
|
||||
and apparatus claims, in any patent Licensable by grantor.
|
||||
|
||||
1.11. "Source Code" means the preferred form of the Covered Code for
|
||||
making modifications to it, including all modules it contains, plus
|
||||
any associated interface definition files, scripts used to control
|
||||
compilation and installation of an Executable, or source code
|
||||
differential comparisons against either the Original Code or another
|
||||
well known, available Covered Code of the Contributor's choice. The
|
||||
Source Code can be in a compressed or archival form, provided the
|
||||
appropriate decompression or de-archiving software is widely available
|
||||
for no charge.
|
||||
|
||||
1.12. "You" (or "Your") means an individual or a legal entity
|
||||
exercising rights under, and complying with all of the terms of, this
|
||||
License or a future version of this License issued under Section 6.1.
|
||||
For legal entities, "You" includes any entity which controls, is
|
||||
controlled by, or is under common control with You. For purposes of
|
||||
this definition, "control" means (a) the power, direct or indirect,
|
||||
to cause the direction or management of such entity, whether by
|
||||
contract or otherwise, or (b) ownership of more than fifty percent
|
||||
(50%) of the outstanding shares or beneficial ownership of such
|
||||
entity.
|
||||
|
||||
2. Source Code License.
|
||||
|
||||
2.1. The Initial Developer Grant.
|
||||
The Initial Developer hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license, subject to third party intellectual property
|
||||
claims:
|
||||
(a) under intellectual property rights (other than patent or
|
||||
trademark) Licensable by Initial Developer to use, reproduce,
|
||||
modify, display, perform, sublicense and distribute the Original
|
||||
Code (or portions thereof) with or without Modifications, and/or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patents Claims infringed by the making, using or
|
||||
selling of Original Code, to make, have made, use, practice,
|
||||
sell, and offer for sale, and/or otherwise dispose of the
|
||||
Original Code (or portions thereof).
|
||||
|
||||
(c) the licenses granted in this Section 2.1(a) and (b) are
|
||||
effective on the date Initial Developer first distributes
|
||||
Original Code under the terms of this License.
|
||||
|
||||
(d) Notwithstanding Section 2.1(b) above, no patent license is
|
||||
granted: 1) for code that You delete from the Original Code; 2)
|
||||
separate from the Original Code; or 3) for infringements caused
|
||||
by: i) the modification of the Original Code or ii) the
|
||||
combination of the Original Code with other software or devices.
|
||||
|
||||
2.2. Contributor Grant.
|
||||
Subject to third party intellectual property claims, each Contributor
|
||||
hereby grants You a world-wide, royalty-free, non-exclusive license
|
||||
|
||||
(a) under intellectual property rights (other than patent or
|
||||
trademark) Licensable by Contributor, to use, reproduce, modify,
|
||||
display, perform, sublicense and distribute the Modifications
|
||||
created by such Contributor (or portions thereof) either on an
|
||||
unmodified basis, with other Modifications, as Covered Code
|
||||
and/or as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims infringed by the making, using, or
|
||||
selling of Modifications made by that Contributor either alone
|
||||
and/or in combination with its Contributor Version (or portions
|
||||
of such combination), to make, use, sell, offer for sale, have
|
||||
made, and/or otherwise dispose of: 1) Modifications made by that
|
||||
Contributor (or portions thereof); and 2) the combination of
|
||||
Modifications made by that Contributor with its Contributor
|
||||
Version (or portions of such combination).
|
||||
|
||||
(c) the licenses granted in Sections 2.2(a) and 2.2(b) are
|
||||
effective on the date Contributor first makes Commercial Use of
|
||||
the Covered Code.
|
||||
|
||||
(d) Notwithstanding Section 2.2(b) above, no patent license is
|
||||
granted: 1) for any code that Contributor has deleted from the
|
||||
Contributor Version; 2) separate from the Contributor Version;
|
||||
3) for infringements caused by: i) third party modifications of
|
||||
Contributor Version or ii) the combination of Modifications made
|
||||
by that Contributor with other software (except as part of the
|
||||
Contributor Version) or other devices; or 4) under Patent Claims
|
||||
infringed by Covered Code in the absence of Modifications made by
|
||||
that Contributor.
|
||||
|
||||
3. Distribution Obligations.
|
||||
|
||||
3.1. Application of License.
|
||||
The Modifications which You create or to which You contribute are
|
||||
governed by the terms of this License, including without limitation
|
||||
Section 2.2. The Source Code version of Covered Code may be
|
||||
distributed only under the terms of this License or a future version
|
||||
of this License released under Section 6.1, and You must include a
|
||||
copy of this License with every copy of the Source Code You
|
||||
distribute. You may not offer or impose any terms on any Source Code
|
||||
version that alters or restricts the applicable version of this
|
||||
License or the recipients' rights hereunder. However, You may include
|
||||
an additional document offering the additional rights described in
|
||||
Section 3.5.
|
||||
|
||||
3.2. Availability of Source Code.
|
||||
Any Modification which You create or to which You contribute must be
|
||||
made available in Source Code form under the terms of this License
|
||||
either on the same media as an Executable version or via an accepted
|
||||
Electronic Distribution Mechanism to anyone to whom you made an
|
||||
Executable version available; and if made available via Electronic
|
||||
Distribution Mechanism, must remain available for at least twelve (12)
|
||||
months after the date it initially became available, or at least six
|
||||
(6) months after a subsequent version of that particular Modification
|
||||
has been made available to such recipients. You are responsible for
|
||||
ensuring that the Source Code version remains available even if the
|
||||
Electronic Distribution Mechanism is maintained by a third party.
|
||||
|
||||
3.3. Description of Modifications.
|
||||
You must cause all Covered Code to which You contribute to contain a
|
||||
file documenting the changes You made to create that Covered Code and
|
||||
the date of any change. You must include a prominent statement that
|
||||
the Modification is derived, directly or indirectly, from Original
|
||||
Code provided by the Initial Developer and including the name of the
|
||||
Initial Developer in (a) the Source Code, and (b) in any notice in an
|
||||
Executable version or related documentation in which You describe the
|
||||
origin or ownership of the Covered Code.
|
||||
|
||||
3.4. Intellectual Property Matters
|
||||
(a) Third Party Claims.
|
||||
If Contributor has knowledge that a license under a third party's
|
||||
intellectual property rights is required to exercise the rights
|
||||
granted by such Contributor under Sections 2.1 or 2.2,
|
||||
Contributor must include a text file with the Source Code
|
||||
distribution titled "LEGAL" which describes the claim and the
|
||||
party making the claim in sufficient detail that a recipient will
|
||||
know whom to contact. If Contributor obtains such knowledge after
|
||||
the Modification is made available as described in Section 3.2,
|
||||
Contributor shall promptly modify the LEGAL file in all copies
|
||||
Contributor makes available thereafter and shall take other steps
|
||||
(such as notifying appropriate mailing lists or newsgroups)
|
||||
reasonably calculated to inform those who received the Covered
|
||||
Code that new knowledge has been obtained.
|
||||
|
||||
(b) Contributor APIs.
|
||||
If Contributor's Modifications include an application programming
|
||||
interface and Contributor has knowledge of patent licenses which
|
||||
are reasonably necessary to implement that API, Contributor must
|
||||
also include this information in the LEGAL file.
|
||||
|
||||
(c) Representations.
|
||||
Contributor represents that, except as disclosed pursuant to
|
||||
Section 3.4(a) above, Contributor believes that Contributor's
|
||||
Modifications are Contributor's original creation(s) and/or
|
||||
Contributor has sufficient rights to grant the rights conveyed by
|
||||
this License.
|
||||
|
||||
3.5. Required Notices.
|
||||
You must duplicate the notice in Exhibit A in each file of the Source
|
||||
Code. If it is not possible to put such notice in a particular Source
|
||||
Code file due to its structure, then You must include such notice in a
|
||||
location (such as a relevant directory) where a user would be likely
|
||||
to look for such a notice. If You created one or more Modification(s)
|
||||
You may add your name as a Contributor to the notice described in
|
||||
Exhibit A. You must also duplicate this License in any documentation
|
||||
for the Source Code where You describe recipients' rights or ownership
|
||||
rights relating to Covered Code. You may choose to offer, and to
|
||||
charge a fee for, warranty, support, indemnity or liability
|
||||
obligations to one or more recipients of Covered Code. However, You
|
||||
may do so only on Your own behalf, and not on behalf of the Initial
|
||||
Developer or any Contributor. You must make it absolutely clear than
|
||||
any such warranty, support, indemnity or liability obligation is
|
||||
offered by You alone, and You hereby agree to indemnify the Initial
|
||||
Developer and every Contributor for any liability incurred by the
|
||||
Initial Developer or such Contributor as a result of warranty,
|
||||
support, indemnity or liability terms You offer.
|
||||
|
||||
3.6. Distribution of Executable Versions.
|
||||
You may distribute Covered Code in Executable form only if the
|
||||
requirements of Section 3.1-3.5 have been met for that Covered Code,
|
||||
and if You include a notice stating that the Source Code version of
|
||||
the Covered Code is available under the terms of this License,
|
||||
including a description of how and where You have fulfilled the
|
||||
obligations of Section 3.2. The notice must be conspicuously included
|
||||
in any notice in an Executable version, related documentation or
|
||||
collateral in which You describe recipients' rights relating to the
|
||||
Covered Code. You may distribute the Executable version of Covered
|
||||
Code or ownership rights under a license of Your choice, which may
|
||||
contain terms different from this License, provided that You are in
|
||||
compliance with the terms of this License and that the license for the
|
||||
Executable version does not attempt to limit or alter the recipient's
|
||||
rights in the Source Code version from the rights set forth in this
|
||||
License. If You distribute the Executable version under a different
|
||||
license You must make it absolutely clear that any terms which differ
|
||||
from this License are offered by You alone, not by the Initial
|
||||
Developer or any Contributor. You hereby agree to indemnify the
|
||||
Initial Developer and every Contributor for any liability incurred by
|
||||
the Initial Developer or such Contributor as a result of any such
|
||||
terms You offer.
|
||||
|
||||
3.7. Larger Works.
|
||||
You may create a Larger Work by combining Covered Code with other code
|
||||
not governed by the terms of this License and distribute the Larger
|
||||
Work as a single product. In such a case, You must make sure the
|
||||
requirements of this License are fulfilled for the Covered Code.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation.
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Code due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description
|
||||
must be included in the LEGAL file described in Section 3.4 and must
|
||||
be included with all distributions of the Source Code. Except to the
|
||||
extent prohibited by statute or regulation, such description must be
|
||||
sufficiently detailed for a recipient of ordinary skill to be able to
|
||||
understand it.
|
||||
|
||||
5. Application of this License.
|
||||
|
||||
This License applies to code to which the Initial Developer has
|
||||
attached the notice in Exhibit A and to related Covered Code.
|
||||
|
||||
6. Versions of the License.
|
||||
|
||||
6.1. New Versions.
|
||||
Netscape Communications Corporation ("Netscape") may publish revised
|
||||
and/or new versions of the License from time to time. Each version
|
||||
will be given a distinguishing version number.
|
||||
|
||||
6.2. Effect of New Versions.
|
||||
Once Covered Code has been published under a particular version of the
|
||||
License, You may always continue to use it under the terms of that
|
||||
version. You may also choose to use such Covered Code under the terms
|
||||
of any subsequent version of the License published by Netscape. No one
|
||||
other than Netscape has the right to modify the terms applicable to
|
||||
Covered Code created under this License.
|
||||
|
||||
6.3. Derivative Works.
|
||||
If You create or use a modified version of this License (which you may
|
||||
only do in order to apply it to code which is not already Covered Code
|
||||
governed by this License), You must (a) rename Your license so that
|
||||
the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
|
||||
"MPL", "NPL" or any confusingly similar phrase do not appear in your
|
||||
license (except to note that your license differs from this License)
|
||||
and (b) otherwise make it clear that Your version of the license
|
||||
contains terms which differ from the Mozilla Public License and
|
||||
Netscape Public License. (Filling in the name of the Initial
|
||||
Developer, Original Code or Contributor in the notice described in
|
||||
Exhibit A shall not of themselves be deemed to be modifications of
|
||||
this License.)
|
||||
|
||||
7. DISCLAIMER OF WARRANTY.
|
||||
|
||||
COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
||||
WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
|
||||
DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
|
||||
THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
|
||||
IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
|
||||
YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
|
||||
COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
|
||||
OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
|
||||
ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
|
||||
|
||||
8. TERMINATION.
|
||||
|
||||
8.1. This License and the rights granted hereunder will terminate
|
||||
automatically if You fail to comply with terms herein and fail to cure
|
||||
such breach within 30 days of becoming aware of the breach. All
|
||||
sublicenses to the Covered Code which are properly granted shall
|
||||
survive any termination of this License. Provisions which, by their
|
||||
nature, must remain in effect beyond the termination of this License
|
||||
shall survive.
|
||||
|
||||
8.2. If You initiate litigation by asserting a patent infringement
|
||||
claim (excluding declatory judgment actions) against Initial Developer
|
||||
or a Contributor (the Initial Developer or Contributor against whom
|
||||
You file such action is referred to as "Participant") alleging that:
|
||||
|
||||
(a) such Participant's Contributor Version directly or indirectly
|
||||
infringes any patent, then any and all rights granted by such
|
||||
Participant to You under Sections 2.1 and/or 2.2 of this License
|
||||
shall, upon 60 days notice from Participant terminate prospectively,
|
||||
unless if within 60 days after receipt of notice You either: (i)
|
||||
agree in writing to pay Participant a mutually agreeable reasonable
|
||||
royalty for Your past and future use of Modifications made by such
|
||||
Participant, or (ii) withdraw Your litigation claim with respect to
|
||||
the Contributor Version against such Participant. If within 60 days
|
||||
of notice, a reasonable royalty and payment arrangement are not
|
||||
mutually agreed upon in writing by the parties or the litigation claim
|
||||
is not withdrawn, the rights granted by Participant to You under
|
||||
Sections 2.1 and/or 2.2 automatically terminate at the expiration of
|
||||
the 60 day notice period specified above.
|
||||
|
||||
(b) any software, hardware, or device, other than such Participant's
|
||||
Contributor Version, directly or indirectly infringes any patent, then
|
||||
any rights granted to You by such Participant under Sections 2.1(b)
|
||||
and 2.2(b) are revoked effective as of the date You first made, used,
|
||||
sold, distributed, or had made, Modifications made by that
|
||||
Participant.
|
||||
|
||||
8.3. If You assert a patent infringement claim against Participant
|
||||
alleging that such Participant's Contributor Version directly or
|
||||
indirectly infringes any patent where such claim is resolved (such as
|
||||
by license or settlement) prior to the initiation of patent
|
||||
infringement litigation, then the reasonable value of the licenses
|
||||
granted by such Participant under Sections 2.1 or 2.2 shall be taken
|
||||
into account in determining the amount or value of any payment or
|
||||
license.
|
||||
|
||||
8.4. In the event of termination under Sections 8.1 or 8.2 above,
|
||||
all end user license agreements (excluding distributors and resellers)
|
||||
which have been validly granted by You or any distributor hereunder
|
||||
prior to termination shall survive termination.
|
||||
|
||||
9. LIMITATION OF LIABILITY.
|
||||
|
||||
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
|
||||
(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
|
||||
DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
|
||||
OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
|
||||
ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
|
||||
CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
|
||||
WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
|
||||
COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
|
||||
INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
|
||||
LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
|
||||
RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
|
||||
PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
|
||||
EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
|
||||
THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
|
||||
|
||||
10. U.S. GOVERNMENT END USERS.
|
||||
|
||||
The Covered Code is a "commercial item," as that term is defined in
|
||||
48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
|
||||
software" and "commercial computer software documentation," as such
|
||||
terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
|
||||
C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
|
||||
all U.S. Government End Users acquire Covered Code with only those
|
||||
rights set forth herein.
|
||||
|
||||
11. MISCELLANEOUS.
|
||||
|
||||
This License represents the complete agreement concerning subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. This License shall be governed by
|
||||
California law provisions (except to the extent applicable law, if
|
||||
any, provides otherwise), excluding its conflict-of-law provisions.
|
||||
With respect to disputes in which at least one party is a citizen of,
|
||||
or an entity chartered or registered to do business in the United
|
||||
States of America, any litigation relating to this License shall be
|
||||
subject to the jurisdiction of the Federal Courts of the Northern
|
||||
District of California, with venue lying in Santa Clara County,
|
||||
California, with the losing party responsible for costs, including
|
||||
without limitation, court costs and reasonable attorneys' fees and
|
||||
expenses. The application of the United Nations Convention on
|
||||
Contracts for the International Sale of Goods is expressly excluded.
|
||||
Any law or regulation which provides that the language of a contract
|
||||
shall be construed against the drafter shall not apply to this
|
||||
License.
|
||||
|
||||
12. RESPONSIBILITY FOR CLAIMS.
|
||||
|
||||
As between Initial Developer and the Contributors, each party is
|
||||
responsible for claims and damages arising, directly or indirectly,
|
||||
out of its utilization of rights under this License and You agree to
|
||||
work with Initial Developer and Contributors to distribute such
|
||||
responsibility on an equitable basis. Nothing herein is intended or
|
||||
shall be deemed to constitute any admission of liability.
|
||||
|
||||
13. MULTIPLE-LICENSED CODE.
|
||||
|
||||
Initial Developer may designate portions of the Covered Code as
|
||||
"Multiple-Licensed". "Multiple-Licensed" means that the Initial
|
||||
Developer permits you to utilize portions of the Covered Code under
|
||||
Your choice of the NPL or the alternative licenses, if any, specified
|
||||
by the Initial Developer in the file described in Exhibit A.
|
||||
|
||||
EXHIBIT A -Mozilla Public License.
|
||||
|
||||
``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 ______________________________________.
|
||||
|
||||
The Initial Developer of the Original Code is ________________________.
|
||||
Portions created by ______________________ are Copyright (C) ______
|
||||
_______________________. All Rights Reserved.
|
||||
|
||||
Contributor(s): ______________________________________.
|
||||
|
||||
Alternatively, the contents of this file may be used under the terms
|
||||
of the _____ license (the "[___] License"), in which case the
|
||||
provisions of [______] License are applicable instead of those
|
||||
above. If you wish to allow use of your version of this file only
|
||||
under the terms of the [____] License and not to allow others to use
|
||||
your version of this file under the MPL, indicate your decision by
|
||||
deleting the provisions above and replace them with the notice and
|
||||
other provisions required by the [___] License. If you do not delete
|
||||
the provisions above, a recipient may use your version of this file
|
||||
under either the MPL or the [___] License."
|
||||
|
||||
[NOTE: The text of this Exhibit A may differ slightly from the text of
|
||||
the notices in the Source Code files of the Original Code. You should
|
||||
use the text of this Exhibit A rather than the text found in the
|
||||
Original Code Source Code for Your Modifications.]
|
||||
============================================================================
|
||||
|
||||
============================================================================
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
============================================================================
|
||||
|
||||
Additionally, some files (currently the contents of
|
||||
toolsrc/org/mozilla/javascript/tools/debugger/treetable/) are available
|
||||
only under the following license:
|
||||
|
||||
============================================================================
|
||||
* Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Sun Microsystems nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
============================================================================
|
||||
@@ -37,7 +37,6 @@ apiClasses=\
|
||||
src/org/mozilla/javascript/ClassCache.java,\
|
||||
src/org/mozilla/javascript/ClassShutter.java,\
|
||||
src/org/mozilla/javascript/CompilerEnvirons.java,\
|
||||
src/org/mozilla/javascript/ContinuationPending.java,\
|
||||
src/org/mozilla/javascript/Context.java,\
|
||||
src/org/mozilla/javascript/ContextAction.java,\
|
||||
src/org/mozilla/javascript/ContextFactory.java,\
|
||||
|
||||
@@ -36,15 +36,14 @@
|
||||
|
||||
name: rhino
|
||||
Name: Rhino
|
||||
version: 1_7R3pre
|
||||
version: 1_6R6pre
|
||||
# See Context#getImplementationVersion() for format of this!
|
||||
implementation.version: Rhino 1.7 release 3 PRERELEASE ${implementation.date}
|
||||
implementation.version: Rhino 1.6 release 6 Pre ${implementation.date}
|
||||
|
||||
build.dir: build
|
||||
rhino.jar: js.jar
|
||||
small-rhino.jar: smalljs.jar
|
||||
rhino-14.jar: js-14.jar
|
||||
small-rhino-14.jar: smalljs-14.jar
|
||||
|
||||
dist.name: rhino${version}
|
||||
dist.dir: ${build.dir}/${dist.name}
|
||||
|
||||
@@ -53,10 +52,10 @@ classes: ${build.dir}/classes
|
||||
|
||||
# compilation settings
|
||||
debug: on
|
||||
target-jvm: 1.5
|
||||
source-level: 1.5
|
||||
target-jvm: 1.3
|
||||
source-level: 1.3
|
||||
|
||||
# jar generation settings
|
||||
# jar generation settings
|
||||
jar-compression: true
|
||||
|
||||
# optional external packages
|
||||
|
||||
@@ -35,11 +35,8 @@
|
||||
|
||||
|
||||
<!--
|
||||
Build file for Rhino using Ant (see http://jakarta.apache.org/ant/index.html)
|
||||
Requires Ant version 1.2 or later
|
||||
|
||||
Compilation currently requires JDK 1.5 or later. Can cross-compile to
|
||||
support JDK 1.4.
|
||||
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=".">
|
||||
@@ -81,24 +78,14 @@
|
||||
<ant antfile="deprecatedsrc/build.xml" target="compile"/>
|
||||
</target>
|
||||
|
||||
<target name="graph" depends="init">
|
||||
<ant antfile="src/build.xml" target="graph"/>
|
||||
</target>
|
||||
|
||||
<target name="shell" depends="compile">
|
||||
<ant antfile="src/build.xml" target="shell"/>
|
||||
</target>
|
||||
|
||||
<target name="copy-source" depends="init">
|
||||
<ant antfile="src/build.xml" target="copy-source"/>
|
||||
<ant antfile="toolsrc/build.xml" target="copy-source"/>
|
||||
<ant antfile="testsrc/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"/>
|
||||
<copy todir="${dist.dir}" file="LICENSE.txt"/>
|
||||
</target>
|
||||
|
||||
<target name="xmlimplsrc-compile" if="xmlimplsrc-present?">
|
||||
@@ -114,55 +101,16 @@
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="compile-all">
|
||||
<property name="jarfile" location="${dist.dir}/${rhino.jar}"/>
|
||||
<jar jarfile="${jarfile}"
|
||||
<jar jarfile="${dist.dir}/${rhino.jar}"
|
||||
basedir="${classes}"
|
||||
manifest="src/manifest"
|
||||
compress="${jar-compression}"
|
||||
compress="${jar-compression}"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name="console" depends="jar">
|
||||
<property name="jarfile" location="${dist.dir}/${rhino.jar}"/>
|
||||
<java jar="${jarfile}"
|
||||
fork="true">
|
||||
<arg line="-version 170"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="retrotranslator" depends="retrotranslator-check,retrotranslator-download">
|
||||
<taskdef name="retrotranslator" classpath="build/download/Retrotranslator-1.2.3-bin/retrotranslator-transformer-1.2.3.jar"
|
||||
classname="net.sf.retrotranslator.transformer.RetrotranslatorTask"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="retrotranslator-check">
|
||||
<condition property="retrotranslator.available">
|
||||
<and>
|
||||
<available file="build/download/Retrotranslator-1.2.3-bin/retrotranslator-transformer-1.2.3.jar"/>
|
||||
<available file="build/download/Retrotranslator-1.2.3-bin/retrotranslator-runtime-1.2.3.jar"/>
|
||||
<available file="build/download/Retrotranslator-1.2.3-bin/backport-util-concurrent-3.1.jar"/>
|
||||
</and>
|
||||
</condition>
|
||||
</target>
|
||||
|
||||
<target name="retrotranslator-download" unless="retrotranslator.available">
|
||||
<mkdir dir="build/download"/>
|
||||
<get src="http://downloads.sourceforge.net/retrotranslator/Retrotranslator-1.2.3-bin.zip" dest="build/download/Retrotranslator-1.2.3-bin.zip" usetimestamp="true"/>
|
||||
<unzip src="build/download/Retrotranslator-1.2.3-bin.zip" dest="build/download"/>
|
||||
</target>
|
||||
|
||||
<target name="retrojar" depends="jar,retrotranslator">
|
||||
<retrotranslator
|
||||
srcjar="${jarfile}"
|
||||
destjar="${dist.dir}/${rhino-14.jar}"
|
||||
embed="org.mozilla.javascript"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name="smalljar" depends="compile">
|
||||
<property name="smalljarfile" location="${dist.dir}/${small-rhino.jar}"/>
|
||||
<jar basedir="${classes}" destfile="${smalljarfile}"
|
||||
|
||||
<jar basedir="${classes}" destfile="${dist.dir}/${small-rhino.jar}"
|
||||
compress="${jar-compression}">
|
||||
<include name="org/mozilla/javascript/*.class"/>
|
||||
|
||||
@@ -184,14 +132,6 @@
|
||||
|
||||
</target>
|
||||
|
||||
<target name="retrosmalljar" depends="smalljar,retrotranslator">
|
||||
<retrotranslator
|
||||
srcjar="${smalljarfile}"
|
||||
destjar="${dist.dir}/${small-rhino-14.jar}"
|
||||
embed="org.mozilla.javascript"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name="copy-examples" depends="init">
|
||||
<mkdir dir="${dist.dir}/examples"/>
|
||||
<copy todir="${dist.dir}/examples">
|
||||
@@ -213,40 +153,33 @@
|
||||
<target name="copy-all" depends="copy-source,copy-examples,copy-misc">
|
||||
</target>
|
||||
|
||||
<target name="javadoc" depends="init">
|
||||
<mkdir dir="${dist.dir}/javadoc"/>
|
||||
<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" />
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="javadoc" depends="copy-docs">
|
||||
<mkdir dir="${dist.dir}/docs/apidocs"/>
|
||||
<javadoc sourcefiles="${apiClasses}"
|
||||
sourcepath="src"
|
||||
destdir="${dist.dir}/javadoc"
|
||||
destdir="${dist.dir}/docs/apidocs"
|
||||
overview="${dist.dir}/docs/api.html"
|
||||
version="true"
|
||||
author="true"
|
||||
windowtitle="${Name}" />
|
||||
</target>
|
||||
|
||||
<target name="dev-javadoc" depends="init">
|
||||
<mkdir dir="${dist.dir}/javadoc"/>
|
||||
<javadoc sourcepath="src"
|
||||
destdir="${dist.dir}/javadoc"
|
||||
version="true"
|
||||
package="true"
|
||||
author="true"
|
||||
windowtitle="${Name}">
|
||||
<fileset
|
||||
dir="."
|
||||
includes="**/*.java"
|
||||
excludes="**/deprecatedsrc/**/*.java"
|
||||
/>
|
||||
</javadoc>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="deepclean,jar,retrojar,copy-all,javadoc">
|
||||
<target name="dist" depends="deepclean,jar,copy-all,javadoc">
|
||||
<delete file="${dist.file}" />
|
||||
<zip destfile="${dist.file}">
|
||||
<fileset dir="${build.dir}" includes="${dist.name}/**"/>
|
||||
</zip>
|
||||
</target>
|
||||
|
||||
<target name="source-zip" depends="copy-source,copy-examples,javadoc">
|
||||
<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}">
|
||||
@@ -254,18 +187,16 @@
|
||||
<include name="build.xml"/>
|
||||
<include name="*.properties"/>
|
||||
<include name="examples/**"/>
|
||||
<include name="docs/**"/>
|
||||
<exclude name="docs/apidocs/**"/>
|
||||
</zipfileset>
|
||||
</zip>
|
||||
</target>
|
||||
|
||||
<target name="compile-debugger">
|
||||
<ant antfile="toolsrc/build.xml" target="compile-debugger"/>
|
||||
</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="${build.dir}"/>
|
||||
<delete quiet="true" dir="${classes}"/>
|
||||
</target>
|
||||
|
||||
<target name="deepclean" depends="properties">
|
||||
@@ -273,47 +204,46 @@
|
||||
<delete quiet="true" file="${dist.file}"/>
|
||||
<delete quiet="true" file="${dist.source-only-zip}"/>
|
||||
</target>
|
||||
|
||||
|
||||
<!--
|
||||
The next two targets run the JavaScript Test Library tests. Note that these tests are quite extensive and take a long time
|
||||
to run. They are not documented in the 'help' target for now.
|
||||
The next two targets run the JavaScript Test Library tests. Note that these tests are quite extensive and take a long time
|
||||
to run. They are not documented in the 'help' target for now.
|
||||
-->
|
||||
|
||||
|
||||
<!--
|
||||
Run the tests using JUnit. Beware that if you are using Ant from the command-line, there are some difficulties you may
|
||||
encounter setting this up correctly; see http://ant.apache.org/faq.html#delegating-classloader
|
||||
|
||||
IDEs that use Ant as the build system probably handle this fine.
|
||||
Run the tests using JUnit. Beware that if you are using Ant from the command-line, there are some difficulties you may
|
||||
encounter setting this up correctly; see http://ant.apache.org/faq.html#delegating-classloader
|
||||
|
||||
IDEs that use Ant as the build system probably handle this fine.
|
||||
-->
|
||||
<target name="junit-all" depends="compile">
|
||||
<ant antfile="testsrc/build.xml" target="junit-coveragereport"/>
|
||||
<ant antfile="testsrc/build.xml" target="junit"/>
|
||||
</target>
|
||||
|
||||
|
||||
<!--
|
||||
Run the tests using the Java port of jsdriver.pl. Note that running this port
|
||||
from the command-line may be more useful running this Ant target, as running
|
||||
from the command line allows configuration options, such as running with a
|
||||
non-default optimization level, or running only a subset of the tests.
|
||||
Run the tests using the Java port of jsdriver.pl. Note that running this port from the command-line
|
||||
may be more useful running this Ant target, as running from the command line allows configuration options,
|
||||
such as running with a non-default optimization level, or running only a subset of the tests.
|
||||
-->
|
||||
<target name="jsdriver-run" depends="compile">
|
||||
<ant antfile="testsrc/build.xml" target="jsdriver" />
|
||||
<target name="jsdriver-all" depends="compile">
|
||||
<ant antfile="testsrc/build.xml" target="jsdriver" />
|
||||
</target>
|
||||
|
||||
|
||||
<!--
|
||||
Compile the JsDriver test driver.
|
||||
Target just for development of the test code.
|
||||
-->
|
||||
<target name="jsdriver" depends="compile">
|
||||
<ant antfile="testsrc/build.xml" target="clean" />
|
||||
<ant antfile="testsrc/build.xml" target="compile" />
|
||||
<target name="_test-recompile" depends="compile">
|
||||
<ant antfile="testsrc/build.xml" target="clean" />
|
||||
<ant antfile="testsrc/build.xml" target="compile" />
|
||||
</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
|
||||
into ${classes} directory
|
||||
excluding deprecated code
|
||||
|
||||
compile-all compile all classes and copy all property files
|
||||
@@ -333,7 +263,7 @@
|
||||
from the doc directory for details.
|
||||
|
||||
javadoc generate Rhino API documentation
|
||||
in ${dist.dir}/javadoc
|
||||
in ${dist.dir}/docs/apidocs
|
||||
|
||||
source-zip create ${dist.source-only-zip} with all Rhino
|
||||
source files necessary to recreate ${dist.file}
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<target name="compile">
|
||||
<javac srcdir="deprecatedsrc"
|
||||
destdir="${classes}"
|
||||
includes="org/mozilla/javascript/*.java"
|
||||
includes="org/**/*.java"
|
||||
deprecation="on"
|
||||
debug="${debug}"
|
||||
target="${target-jvm}"
|
||||
|
||||
@@ -1,367 +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-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ethan Hugg
|
||||
*
|
||||
* 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.xml.impl.xmlbeans;
|
||||
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class LogicalEquality
|
||||
{
|
||||
public static boolean nodesEqual(XmlCursor xmlOne, XmlCursor xmlTwo)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
if (xmlOne.isStartdoc())
|
||||
{
|
||||
xmlOne.toFirstContentToken();
|
||||
}
|
||||
|
||||
if (xmlTwo.isStartdoc())
|
||||
{
|
||||
xmlTwo.toFirstContentToken();
|
||||
}
|
||||
|
||||
if (xmlOne.currentTokenType() == xmlTwo.currentTokenType())
|
||||
{
|
||||
if (xmlOne.isEnddoc())
|
||||
{
|
||||
// Both empty
|
||||
result = true;
|
||||
}
|
||||
else if (xmlOne.isAttr())
|
||||
{
|
||||
result = attributesEqual(xmlOne, xmlTwo);
|
||||
}
|
||||
else if (xmlOne.isText())
|
||||
{
|
||||
result = textNodesEqual(xmlOne, xmlTwo);
|
||||
}
|
||||
else if (xmlOne.isComment())
|
||||
{
|
||||
result = commentsEqual(xmlOne, xmlTwo);
|
||||
}
|
||||
else if (xmlOne.isProcinst())
|
||||
{
|
||||
result = processingInstructionsEqual(xmlOne, xmlTwo);
|
||||
}
|
||||
else if (xmlOne.isStart())
|
||||
{
|
||||
// Compare root elements
|
||||
result = elementsEqual(xmlOne, xmlTwo);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean elementsEqual(XmlCursor xmlOne, XmlCursor xmlTwo)
|
||||
{
|
||||
boolean result = true;
|
||||
|
||||
if (!qnamesEqual(xmlOne.getName(), xmlTwo.getName()))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// These filter out empty text nodes.
|
||||
nextToken(xmlOne);
|
||||
nextToken(xmlTwo);
|
||||
|
||||
do
|
||||
{
|
||||
if (xmlOne.currentTokenType() != xmlTwo.currentTokenType())
|
||||
{
|
||||
// Not same token
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
else if (xmlOne.isEnd())
|
||||
{
|
||||
// Done with this element, step over end
|
||||
break;
|
||||
}
|
||||
else if (xmlOne.isEnddoc())
|
||||
{
|
||||
// Shouldn't get here
|
||||
break;
|
||||
}
|
||||
else if (xmlOne.isAttr())
|
||||
{
|
||||
// This one will move us to the first non-attr token.
|
||||
result = attributeListsEqual(xmlOne, xmlTwo);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xmlOne.isText())
|
||||
{
|
||||
result = textNodesEqual(xmlOne, xmlTwo);
|
||||
}
|
||||
else if (xmlOne.isComment())
|
||||
{
|
||||
result = commentsEqual(xmlOne, xmlTwo);
|
||||
}
|
||||
else if (xmlOne.isProcinst())
|
||||
{
|
||||
result = processingInstructionsEqual(xmlOne, xmlTwo);
|
||||
}
|
||||
else if (xmlOne.isStart())
|
||||
{
|
||||
result = elementsEqual(xmlOne, xmlTwo);
|
||||
}
|
||||
else
|
||||
{
|
||||
//XML.log("Unknown token type" + xmlOne.currentTokenType());
|
||||
}
|
||||
|
||||
// These filter out empty text nodes.
|
||||
nextToken(xmlOne);
|
||||
nextToken(xmlTwo);
|
||||
}
|
||||
}
|
||||
while(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param xmlOne
|
||||
* @param xmlTwo
|
||||
* @return
|
||||
*/
|
||||
private static boolean attributeListsEqual(XmlCursor xmlOne, XmlCursor xmlTwo)
|
||||
{
|
||||
boolean result = true;
|
||||
TreeMap mapOne = loadAttributeMap(xmlOne);
|
||||
TreeMap mapTwo = loadAttributeMap(xmlTwo);
|
||||
|
||||
if (mapOne.size() != mapTwo.size())
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Set keysOne = mapOne.keySet();
|
||||
Set keysTwo = mapTwo.keySet();
|
||||
Iterator itOne = keysOne.iterator();
|
||||
Iterator itTwo = keysTwo.iterator();
|
||||
|
||||
while (result && itOne.hasNext())
|
||||
{
|
||||
String valueOne = (String) itOne.next();
|
||||
String valueTwo = (String) itTwo.next();
|
||||
|
||||
if (!valueOne.equals(valueTwo))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
javax.xml.namespace.QName qnameOne = (javax.xml.namespace.QName) mapOne.get(valueOne);
|
||||
javax.xml.namespace.QName qnameTwo = (javax.xml.namespace.QName) mapTwo.get(valueTwo);
|
||||
|
||||
if (!qnamesEqual(qnameOne, qnameTwo))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param xml
|
||||
* @return
|
||||
*/
|
||||
private static TreeMap loadAttributeMap(XmlCursor xml)
|
||||
{
|
||||
TreeMap result = new TreeMap();
|
||||
|
||||
while (xml.isAttr())
|
||||
{
|
||||
result.put(xml.getTextValue(), xml.getName());
|
||||
nextToken(xml);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param xmlOne
|
||||
* @param xmlTwo
|
||||
* @return
|
||||
*/
|
||||
private static boolean attributesEqual(XmlCursor xmlOne, XmlCursor xmlTwo)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
if (xmlOne.isAttr() && xmlTwo.isAttr())
|
||||
{
|
||||
if (qnamesEqual(xmlOne.getName(), xmlTwo.getName()))
|
||||
{
|
||||
if (xmlOne.getTextValue().equals(xmlTwo.getTextValue()))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param xmlOne
|
||||
* @param xmlTwo
|
||||
* @return
|
||||
*/
|
||||
private static boolean textNodesEqual(XmlCursor xmlOne, XmlCursor xmlTwo)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
if (xmlOne.isText() && xmlTwo.isText())
|
||||
{
|
||||
if (xmlOne.getChars().equals(xmlTwo.getChars()))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param xmlOne
|
||||
* @param xmlTwo
|
||||
* @return
|
||||
*/
|
||||
private static boolean commentsEqual(XmlCursor xmlOne, XmlCursor xmlTwo)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
if (xmlOne.isComment() && xmlTwo.isComment())
|
||||
{
|
||||
if (xmlOne.getTextValue().equals(xmlTwo.getTextValue()))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param xmlOne
|
||||
* @param xmlTwo
|
||||
* @return
|
||||
*/
|
||||
private static boolean processingInstructionsEqual(XmlCursor xmlOne, XmlCursor xmlTwo)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
if (xmlOne.isProcinst() && xmlTwo.isProcinst())
|
||||
{
|
||||
if (qnamesEqual(xmlOne.getName(), xmlTwo.getName()))
|
||||
{
|
||||
if (xmlOne.getTextValue().equals(xmlTwo.getTextValue()))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param qnameOne
|
||||
* @param qnameTwo
|
||||
* @return
|
||||
*/
|
||||
private static boolean qnamesEqual(javax.xml.namespace.QName qnameOne, javax.xml.namespace.QName qnameTwo)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
if (qnameOne.getNamespaceURI().equals(qnameTwo.getNamespaceURI()))
|
||||
{
|
||||
if (qnameOne.getLocalPart().equals(qnameTwo.getLocalPart()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* filter out empty textNodes here
|
||||
*
|
||||
* @param xml
|
||||
*/
|
||||
private static void nextToken(XmlCursor xml)
|
||||
{
|
||||
do
|
||||
{
|
||||
xml.toNextToken();
|
||||
|
||||
if (!xml.isText())
|
||||
{
|
||||
// Not a text node
|
||||
break;
|
||||
}
|
||||
else if (xml.getChars().trim().length() > 0)
|
||||
{
|
||||
// Text node is not empty
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
@@ -1,335 +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-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ethan Hugg
|
||||
* Terry Lucas
|
||||
* Milen Nankov
|
||||
*
|
||||
* 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.xml.impl.xmlbeans;
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
/**
|
||||
* Class Namespace
|
||||
*
|
||||
*/
|
||||
class Namespace extends IdScriptableObject
|
||||
{
|
||||
static final long serialVersionUID = -5765755238131301744L;
|
||||
|
||||
private static final Object NAMESPACE_TAG = "Namespace";
|
||||
|
||||
private XMLLibImpl lib;
|
||||
private String prefix;
|
||||
private String uri;
|
||||
|
||||
public Namespace(XMLLibImpl lib, String uri)
|
||||
{
|
||||
super(lib.globalScope(), lib.namespacePrototype);
|
||||
|
||||
if (uri == null)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
this.lib = lib;
|
||||
this.prefix = (uri.length() == 0) ? "" : null;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
|
||||
public Namespace(XMLLibImpl lib, String prefix, String uri)
|
||||
{
|
||||
super(lib.globalScope(), lib.namespacePrototype);
|
||||
|
||||
if (uri == null)
|
||||
throw new IllegalArgumentException();
|
||||
if (uri.length() == 0) {
|
||||
// prefix should be "" for empty uri
|
||||
if (prefix == null)
|
||||
throw new IllegalArgumentException();
|
||||
if (prefix.length() != 0)
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
this.lib = lib;
|
||||
this.prefix = prefix;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public void exportAsJSClass(boolean sealed)
|
||||
{
|
||||
exportAsJSClass(MAX_PROTOTYPE_ID, lib.globalScope(), sealed);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String uri()
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String prefix()
|
||||
{
|
||||
return prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
return uri();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String toLocaleString ()
|
||||
{
|
||||
return toString();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (!(obj instanceof Namespace)) return false;
|
||||
return equals((Namespace)obj);
|
||||
}
|
||||
|
||||
protected Object equivalentValues(Object value)
|
||||
{
|
||||
if (!(value instanceof Namespace)) return Scriptable.NOT_FOUND;
|
||||
boolean result = equals((Namespace)value);
|
||||
return result ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
private boolean equals(Namespace n)
|
||||
{
|
||||
return uri().equals(n.uri());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getClassName ()
|
||||
{
|
||||
return "Namespace";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param hint
|
||||
* @return
|
||||
*/
|
||||
public Object getDefaultValue (Class hint)
|
||||
{
|
||||
return uri();
|
||||
}
|
||||
|
||||
// #string_id_map#
|
||||
private static final int
|
||||
Id_prefix = 1,
|
||||
Id_uri = 2,
|
||||
MAX_INSTANCE_ID = 2;
|
||||
|
||||
protected int getMaxInstanceId()
|
||||
{
|
||||
return super.getMaxInstanceId() + MAX_INSTANCE_ID;
|
||||
}
|
||||
|
||||
protected int findInstanceIdInfo(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2004-07-20 19:50:50 CEST
|
||||
L0: { id = 0; String X = null;
|
||||
int s_length = s.length();
|
||||
if (s_length==3) { X="uri";id=Id_uri; }
|
||||
else if (s_length==6) { X="prefix";id=Id_prefix; }
|
||||
if (X!=null && X!=s && !X.equals(s)) id = 0;
|
||||
}
|
||||
// #/generated#
|
||||
|
||||
if (id == 0) return super.findInstanceIdInfo(s);
|
||||
|
||||
int attr;
|
||||
switch (id) {
|
||||
case Id_prefix:
|
||||
case Id_uri:
|
||||
attr = PERMANENT | READONLY;
|
||||
break;
|
||||
default: throw new IllegalStateException();
|
||||
}
|
||||
return instanceIdInfo(attr, super.getMaxInstanceId() + id);
|
||||
}
|
||||
// #/string_id_map#
|
||||
|
||||
protected String getInstanceIdName(int id)
|
||||
{
|
||||
switch (id - super.getMaxInstanceId()) {
|
||||
case Id_prefix: return "prefix";
|
||||
case Id_uri: return "uri";
|
||||
}
|
||||
return super.getInstanceIdName(id);
|
||||
}
|
||||
|
||||
protected Object getInstanceIdValue(int id)
|
||||
{
|
||||
switch (id - super.getMaxInstanceId()) {
|
||||
case Id_prefix:
|
||||
if (prefix == null) return Undefined.instance;
|
||||
return prefix;
|
||||
case Id_uri:
|
||||
return uri;
|
||||
}
|
||||
return super.getInstanceIdValue(id);
|
||||
}
|
||||
|
||||
|
||||
// #string_id_map#
|
||||
private static final int
|
||||
Id_constructor = 1,
|
||||
Id_toString = 2,
|
||||
Id_toSource = 3,
|
||||
MAX_PROTOTYPE_ID = 3;
|
||||
|
||||
protected int findPrototypeId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2004-08-21 12:07:01 CEST
|
||||
L0: { id = 0; String X = null; int c;
|
||||
int s_length = s.length();
|
||||
if (s_length==8) {
|
||||
c=s.charAt(3);
|
||||
if (c=='o') { X="toSource";id=Id_toSource; }
|
||||
else if (c=='t') { X="toString";id=Id_toString; }
|
||||
}
|
||||
else if (s_length==11) { X="constructor";id=Id_constructor; }
|
||||
if (X!=null && X!=s && !X.equals(s)) id = 0;
|
||||
}
|
||||
// #/generated#
|
||||
return id;
|
||||
}
|
||||
// #/string_id_map#
|
||||
|
||||
protected void initPrototypeId(int id)
|
||||
{
|
||||
String s;
|
||||
int arity;
|
||||
switch (id) {
|
||||
case Id_constructor: arity=2; s="constructor"; break;
|
||||
case Id_toString: arity=0; s="toString"; break;
|
||||
case Id_toSource: arity=0; s="toSource"; break;
|
||||
default: throw new IllegalArgumentException(String.valueOf(id));
|
||||
}
|
||||
initPrototypeMethod(NAMESPACE_TAG, id, s, arity);
|
||||
}
|
||||
|
||||
public Object execIdCall(IdFunctionObject f,
|
||||
Context cx,
|
||||
Scriptable scope,
|
||||
Scriptable thisObj,
|
||||
Object[] args)
|
||||
{
|
||||
if (!f.hasTag(NAMESPACE_TAG)) {
|
||||
return super.execIdCall(f, cx, scope, thisObj, args);
|
||||
}
|
||||
int id = f.methodId();
|
||||
switch (id) {
|
||||
case Id_constructor:
|
||||
return jsConstructor(cx, (thisObj == null), args);
|
||||
case Id_toString:
|
||||
return realThis(thisObj, f).toString();
|
||||
case Id_toSource:
|
||||
return realThis(thisObj, f).js_toSource();
|
||||
}
|
||||
throw new IllegalArgumentException(String.valueOf(id));
|
||||
}
|
||||
|
||||
private Namespace realThis(Scriptable thisObj, IdFunctionObject f)
|
||||
{
|
||||
if(!(thisObj instanceof Namespace))
|
||||
throw incompatibleCallError(f);
|
||||
return (Namespace)thisObj;
|
||||
}
|
||||
|
||||
private Object jsConstructor(Context cx, boolean inNewExpr, Object[] args)
|
||||
{
|
||||
if (!inNewExpr && args.length == 1) {
|
||||
return lib.castToNamespace(cx, args[0]);
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
return lib.constructNamespace(cx);
|
||||
} else if (args.length == 1) {
|
||||
return lib.constructNamespace(cx, args[0]);
|
||||
} else {
|
||||
return lib.constructNamespace(cx, args[0], args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private String js_toSource()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append('(');
|
||||
toSourceImpl(prefix, uri, sb);
|
||||
sb.append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static void toSourceImpl(String prefix, String uri, StringBuffer sb)
|
||||
{
|
||||
sb.append("new Namespace(");
|
||||
if (uri.length() == 0) {
|
||||
if (!"".equals(prefix)) throw new IllegalArgumentException(prefix);
|
||||
} else {
|
||||
sb.append('\'');
|
||||
if (prefix != null) {
|
||||
sb.append(ScriptRuntime.escapeString(prefix, '\''));
|
||||
sb.append("', '");
|
||||
}
|
||||
sb.append(ScriptRuntime.escapeString(uri, '\''));
|
||||
sb.append('\'');
|
||||
}
|
||||
sb.append(')');
|
||||
}
|
||||
}
|
||||
@@ -1,350 +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-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Milen Nankov
|
||||
*
|
||||
* 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.xml.impl.xmlbeans;
|
||||
|
||||
import java.util.*;
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
class NamespaceHelper
|
||||
{
|
||||
private XMLLibImpl lib;
|
||||
private final Map prefixToURI = new HashMap();
|
||||
private final Map uriToPrefix = new HashMap();
|
||||
// A set of URIs that are used without explicit namespace declaration in scope.
|
||||
private final Set undeclared = new HashSet();
|
||||
|
||||
private NamespaceHelper(XMLLibImpl lib)
|
||||
{
|
||||
this.lib = lib;
|
||||
// Insert the default namespace
|
||||
prefixToURI.put("", "");
|
||||
Set prefixes = new HashSet();
|
||||
prefixes.add("");
|
||||
uriToPrefix.put("", prefixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Declared a new namespace
|
||||
*
|
||||
* @param prefix
|
||||
* @param uri
|
||||
* @param declarations
|
||||
*/
|
||||
private void declareNamespace(String prefix, String uri, ObjArray declarations)
|
||||
{
|
||||
Set prefixes = (Set)uriToPrefix.get(uri);
|
||||
if(prefixes == null)
|
||||
{
|
||||
prefixes = new HashSet();
|
||||
uriToPrefix.put(uri, prefixes);
|
||||
}
|
||||
|
||||
if(!prefixes.contains(prefix))
|
||||
{
|
||||
String oldURI = (String)prefixToURI.get(prefix);
|
||||
|
||||
// Add the new mapping
|
||||
prefixes.add(prefix);
|
||||
prefixToURI.put(prefix, uri);
|
||||
if(declarations != null)
|
||||
declarations.add(new Namespace(lib, prefix, uri));
|
||||
|
||||
if(oldURI != null)
|
||||
{
|
||||
// Update the existing mapping
|
||||
prefixes = (Set)uriToPrefix.get(oldURI);
|
||||
prefixes.remove(prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the internal state of this NamespaceHelper to reflect the
|
||||
* existance of the XML token pointed to by the cursor.
|
||||
*/
|
||||
private void processName(XmlCursor cursor, ObjArray declarations)
|
||||
{
|
||||
javax.xml.namespace.QName qname = cursor.getName();
|
||||
String uri = qname.getNamespaceURI();
|
||||
Set prefixes = (Set)uriToPrefix.get(uri);
|
||||
if(prefixes == null || prefixes.size() == 0)
|
||||
{
|
||||
undeclared.add(uri);
|
||||
if(declarations != null)
|
||||
declarations.add(new Namespace(lib, uri));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the internal state of this NamespaceHelper with the
|
||||
* namespace information of the element pointed to by the cursor.
|
||||
*/
|
||||
private void update(XmlCursor cursor, ObjArray declarations)
|
||||
{
|
||||
// Process the Namespace declarations
|
||||
cursor.push();
|
||||
while(cursor.toNextToken().isAnyAttr())
|
||||
{
|
||||
if(cursor.isNamespace())
|
||||
{
|
||||
javax.xml.namespace.QName name = cursor.getName();
|
||||
String prefix = name.getLocalPart();
|
||||
String uri = name.getNamespaceURI();
|
||||
|
||||
declareNamespace(prefix, uri, declarations);
|
||||
}
|
||||
}
|
||||
cursor.pop();
|
||||
|
||||
// Process the element
|
||||
processName(cursor, declarations);
|
||||
|
||||
// Process the attributes
|
||||
cursor.push();
|
||||
boolean hasNext = cursor.toFirstAttribute();
|
||||
while(hasNext)
|
||||
{
|
||||
processName(cursor, declarations);
|
||||
hasNext = cursor.toNextAttribute();
|
||||
}
|
||||
cursor.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Object[] array of Namespace objects in scope at the cursor.
|
||||
*/
|
||||
public static Object[] inScopeNamespaces(XMLLibImpl lib, XmlCursor cursor)
|
||||
{
|
||||
ObjArray namespaces = new ObjArray();
|
||||
NamespaceHelper helper = new NamespaceHelper(lib);
|
||||
|
||||
cursor.push();
|
||||
|
||||
int depth = 0;
|
||||
while(cursor.hasPrevToken())
|
||||
{
|
||||
if(cursor.isContainer())
|
||||
{
|
||||
cursor.push();
|
||||
depth++;
|
||||
}
|
||||
|
||||
cursor.toParent();
|
||||
}
|
||||
|
||||
for(int i = 0; i < depth; i++)
|
||||
{
|
||||
cursor.pop();
|
||||
helper.update(cursor, null);
|
||||
}
|
||||
|
||||
Iterator i = helper.prefixToURI.entrySet().iterator();
|
||||
while(i.hasNext())
|
||||
{
|
||||
Map.Entry entry = (Map.Entry)i.next();
|
||||
Namespace ns = new Namespace(lib, (String)entry.getKey(),
|
||||
(String)entry.getValue());
|
||||
namespaces.add(ns);
|
||||
}
|
||||
|
||||
i = helper.undeclared.iterator();
|
||||
while(i.hasNext())
|
||||
{
|
||||
Namespace ns = new Namespace(lib, (String)i.next());
|
||||
namespaces.add(ns);
|
||||
}
|
||||
|
||||
cursor.pop();
|
||||
|
||||
return namespaces.toArray();
|
||||
}
|
||||
|
||||
static Namespace getNamespace(XMLLibImpl lib, XmlCursor cursor,
|
||||
Object[] inScopeNamespaces)
|
||||
{
|
||||
String uri;
|
||||
String prefix;
|
||||
|
||||
if (cursor.isProcinst()) {
|
||||
uri = "";
|
||||
prefix = "";
|
||||
} else {
|
||||
javax.xml.namespace.QName qname = cursor.getName();
|
||||
uri = qname.getNamespaceURI();
|
||||
prefix = qname.getPrefix();
|
||||
}
|
||||
|
||||
if (inScopeNamespaces == null)
|
||||
return new Namespace(lib, prefix, uri);
|
||||
|
||||
Namespace result = null;
|
||||
for (int i = 0; i != inScopeNamespaces.length; ++i) {
|
||||
Namespace ns = (Namespace)inScopeNamespaces[i];
|
||||
if(ns == null) continue;
|
||||
|
||||
String nsURI = ns.uri();
|
||||
if(nsURI.equals(uri))
|
||||
{
|
||||
if(prefix.equals(ns.prefix()))
|
||||
{
|
||||
result = ns;
|
||||
break;
|
||||
}
|
||||
|
||||
if(result == null ||
|
||||
(result.prefix() == null &&
|
||||
ns.prefix() != null))
|
||||
result = ns;
|
||||
}
|
||||
}
|
||||
|
||||
if(result == null)
|
||||
result = new Namespace(lib, prefix, uri);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of Namespace objects that are declared in the container pointed to by the cursor.
|
||||
*/
|
||||
public static Object[] namespaceDeclarations(XMLLibImpl lib, XmlCursor cursor)
|
||||
{
|
||||
ObjArray declarations = new ObjArray();
|
||||
NamespaceHelper helper = new NamespaceHelper(lib);
|
||||
|
||||
cursor.push();
|
||||
|
||||
int depth = 0;
|
||||
while(cursor.hasPrevToken())
|
||||
{
|
||||
if(cursor.isContainer())
|
||||
{
|
||||
cursor.push();
|
||||
depth++;
|
||||
}
|
||||
|
||||
cursor.toParent();
|
||||
}
|
||||
|
||||
for(int i = 0; i < depth - 1; i++)
|
||||
{
|
||||
cursor.pop();
|
||||
helper.update(cursor, null);
|
||||
}
|
||||
|
||||
if(depth > 0)
|
||||
{
|
||||
cursor.pop();
|
||||
helper.update(cursor, declarations);
|
||||
}
|
||||
|
||||
cursor.pop();
|
||||
|
||||
return declarations.toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Prefix to URI map of all namespaces in scope at the cursor.
|
||||
*/
|
||||
public static Map getAllNamespaces(XMLLibImpl lib, XmlCursor cursor)
|
||||
{
|
||||
NamespaceHelper helper = new NamespaceHelper(lib);
|
||||
|
||||
cursor.push();
|
||||
|
||||
int depth = 0;
|
||||
while(cursor.hasPrevToken())
|
||||
{
|
||||
if(cursor.isContainer())
|
||||
{
|
||||
cursor.push();
|
||||
depth++;
|
||||
}
|
||||
|
||||
cursor.toParent();
|
||||
}
|
||||
|
||||
for(int i = 0; i < depth; i++)
|
||||
{
|
||||
cursor.pop();
|
||||
helper.update(cursor, null);
|
||||
}
|
||||
|
||||
cursor.pop();
|
||||
|
||||
return helper.prefixToURI;
|
||||
}
|
||||
|
||||
public static void getNamespaces(XmlCursor cursor, Map prefixToURI)
|
||||
{
|
||||
cursor.push();
|
||||
while(cursor.toNextToken().isAnyAttr())
|
||||
{
|
||||
if(cursor.isNamespace())
|
||||
{
|
||||
javax.xml.namespace.QName name = cursor.getName();
|
||||
String prefix = name.getLocalPart();
|
||||
String uri = name.getNamespaceURI();
|
||||
|
||||
prefixToURI.put(prefix, uri);
|
||||
}
|
||||
}
|
||||
cursor.pop();
|
||||
}
|
||||
|
||||
public static void removeNamespace(XmlCursor cursor, String prefix)
|
||||
{
|
||||
cursor.push();
|
||||
while(cursor.toNextToken().isAnyAttr())
|
||||
{
|
||||
if(cursor.isNamespace())
|
||||
{
|
||||
javax.xml.namespace.QName name = cursor.getName();
|
||||
if(name.getLocalPart().equals(prefix))
|
||||
{
|
||||
cursor.removeXml();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
cursor.pop();
|
||||
}
|
||||
}
|
||||
@@ -1,321 +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-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ethan Hugg
|
||||
* Terry Lucas
|
||||
* Milen Nankov
|
||||
*
|
||||
* 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.xml.impl.xmlbeans;
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
/**
|
||||
* Class QName
|
||||
*
|
||||
*/
|
||||
final class QName extends IdScriptableObject
|
||||
{
|
||||
static final long serialVersionUID = 416745167693026750L;
|
||||
|
||||
private static final Object QNAME_TAG = "QName";
|
||||
|
||||
XMLLibImpl lib;
|
||||
private String prefix;
|
||||
private String localName;
|
||||
private String uri;
|
||||
|
||||
QName(XMLLibImpl lib, String uri, String localName, String prefix)
|
||||
{
|
||||
super(lib.globalScope(), lib.qnamePrototype);
|
||||
if (localName == null) throw new IllegalArgumentException();
|
||||
this.lib = lib;
|
||||
this.uri = uri;
|
||||
this.prefix = prefix;
|
||||
this.localName = localName;
|
||||
}
|
||||
|
||||
void exportAsJSClass(boolean sealed)
|
||||
{
|
||||
exportAsJSClass(MAX_PROTOTYPE_ID, lib.globalScope(), sealed);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
if (uri == null)
|
||||
{
|
||||
result = "*::".concat(localName);
|
||||
}
|
||||
else if(uri.length() == 0)
|
||||
{
|
||||
result = localName;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = uri + "::" + localName;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String localName()
|
||||
{
|
||||
return localName;
|
||||
}
|
||||
|
||||
String prefix()
|
||||
{
|
||||
return (prefix == null) ? prefix : "";
|
||||
}
|
||||
|
||||
String uri()
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(!(obj instanceof QName)) return false;
|
||||
return equals((QName)obj);
|
||||
}
|
||||
|
||||
protected Object equivalentValues(Object value)
|
||||
{
|
||||
if(!(value instanceof QName)) return Scriptable.NOT_FOUND;
|
||||
boolean result = equals((QName)value);
|
||||
return result ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
private boolean equals(QName q)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if (uri == null) {
|
||||
result = q.uri == null && localName.equals(q.localName);
|
||||
} else {
|
||||
result = uri.equals(q.uri) && localName.equals(q.localName);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getClassName ()
|
||||
{
|
||||
return "QName";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param hint
|
||||
* @return
|
||||
*/
|
||||
public Object getDefaultValue (Class hint)
|
||||
{
|
||||
return toString();
|
||||
}
|
||||
|
||||
// #string_id_map#
|
||||
private static final int
|
||||
Id_localName = 1,
|
||||
Id_uri = 2,
|
||||
MAX_INSTANCE_ID = 2;
|
||||
|
||||
protected int getMaxInstanceId()
|
||||
{
|
||||
return super.getMaxInstanceId() + MAX_INSTANCE_ID;
|
||||
}
|
||||
|
||||
protected int findInstanceIdInfo(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2004-07-18 12:32:51 CEST
|
||||
L0: { id = 0; String X = null;
|
||||
int s_length = s.length();
|
||||
if (s_length==3) { X="uri";id=Id_uri; }
|
||||
else if (s_length==9) { X="localName";id=Id_localName; }
|
||||
if (X!=null && X!=s && !X.equals(s)) id = 0;
|
||||
}
|
||||
// #/generated#
|
||||
|
||||
if (id == 0) return super.findInstanceIdInfo(s);
|
||||
|
||||
int attr;
|
||||
switch (id) {
|
||||
case Id_localName:
|
||||
case Id_uri:
|
||||
attr = PERMANENT | READONLY;
|
||||
break;
|
||||
default: throw new IllegalStateException();
|
||||
}
|
||||
return instanceIdInfo(attr, super.getMaxInstanceId() + id);
|
||||
}
|
||||
// #/string_id_map#
|
||||
|
||||
protected String getInstanceIdName(int id)
|
||||
{
|
||||
switch (id - super.getMaxInstanceId()) {
|
||||
case Id_localName: return "localName";
|
||||
case Id_uri: return "uri";
|
||||
}
|
||||
return super.getInstanceIdName(id);
|
||||
}
|
||||
|
||||
protected Object getInstanceIdValue(int id)
|
||||
{
|
||||
switch (id - super.getMaxInstanceId()) {
|
||||
case Id_localName: return localName;
|
||||
case Id_uri: return uri;
|
||||
}
|
||||
return super.getInstanceIdValue(id);
|
||||
}
|
||||
|
||||
// #string_id_map#
|
||||
private static final int
|
||||
Id_constructor = 1,
|
||||
Id_toString = 2,
|
||||
Id_toSource = 3,
|
||||
MAX_PROTOTYPE_ID = 3;
|
||||
|
||||
protected int findPrototypeId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2004-08-21 12:45:13 CEST
|
||||
L0: { id = 0; String X = null; int c;
|
||||
int s_length = s.length();
|
||||
if (s_length==8) {
|
||||
c=s.charAt(3);
|
||||
if (c=='o') { X="toSource";id=Id_toSource; }
|
||||
else if (c=='t') { X="toString";id=Id_toString; }
|
||||
}
|
||||
else if (s_length==11) { X="constructor";id=Id_constructor; }
|
||||
if (X!=null && X!=s && !X.equals(s)) id = 0;
|
||||
}
|
||||
// #/generated#
|
||||
return id;
|
||||
}
|
||||
// #/string_id_map#
|
||||
|
||||
protected void initPrototypeId(int id)
|
||||
{
|
||||
String s;
|
||||
int arity;
|
||||
switch (id) {
|
||||
case Id_constructor: arity=2; s="constructor"; break;
|
||||
case Id_toString: arity=0; s="toString"; break;
|
||||
case Id_toSource: arity=0; s="toSource"; break;
|
||||
default: throw new IllegalArgumentException(String.valueOf(id));
|
||||
}
|
||||
initPrototypeMethod(QNAME_TAG, id, s, arity);
|
||||
}
|
||||
|
||||
public Object execIdCall(IdFunctionObject f,
|
||||
Context cx,
|
||||
Scriptable scope,
|
||||
Scriptable thisObj,
|
||||
Object[] args)
|
||||
{
|
||||
if (!f.hasTag(QNAME_TAG)) {
|
||||
return super.execIdCall(f, cx, scope, thisObj, args);
|
||||
}
|
||||
int id = f.methodId();
|
||||
switch (id) {
|
||||
case Id_constructor:
|
||||
return jsConstructor(cx, (thisObj == null), args);
|
||||
case Id_toString:
|
||||
return realThis(thisObj, f).toString();
|
||||
case Id_toSource:
|
||||
return realThis(thisObj, f).js_toSource();
|
||||
}
|
||||
throw new IllegalArgumentException(String.valueOf(id));
|
||||
}
|
||||
|
||||
private QName realThis(Scriptable thisObj, IdFunctionObject f)
|
||||
{
|
||||
if(!(thisObj instanceof QName))
|
||||
throw incompatibleCallError(f);
|
||||
return (QName)thisObj;
|
||||
}
|
||||
|
||||
private Object jsConstructor(Context cx, boolean inNewExpr, Object[] args)
|
||||
{
|
||||
if (!inNewExpr && args.length == 1) {
|
||||
return lib.castToQName(cx, args[0]);
|
||||
}
|
||||
if (args.length == 0) {
|
||||
return lib.constructQName(cx, Undefined.instance);
|
||||
} else if (args.length == 1) {
|
||||
return lib.constructQName(cx, args[0]);
|
||||
} else {
|
||||
return lib.constructQName(cx, args[0], args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private String js_toSource()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append('(');
|
||||
toSourceImpl(uri, localName, prefix, sb);
|
||||
sb.append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void toSourceImpl(String uri, String localName,
|
||||
String prefix, StringBuffer sb)
|
||||
{
|
||||
sb.append("new QName(");
|
||||
if (uri == null && prefix == null) {
|
||||
if (!"*".equals(localName)) {
|
||||
sb.append("null, ");
|
||||
}
|
||||
} else {
|
||||
Namespace.toSourceImpl(prefix, uri, sb);
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append('\'');
|
||||
sb.append(ScriptRuntime.escapeString(localName, '\''));
|
||||
sb.append("')");
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,269 +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-2000
|
||||
* 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 ***** */
|
||||
|
||||
package org.mozilla.javascript.xml.impl.xmlbeans;
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
class XMLCtor extends IdFunctionObject
|
||||
{
|
||||
static final long serialVersionUID = -8708195078359817341L;
|
||||
|
||||
private static final Object XMLCTOR_TAG = "XMLCtor";
|
||||
|
||||
private XMLLibImpl lib;
|
||||
|
||||
XMLCtor(XML xml, Object tag, int id, int arity)
|
||||
{
|
||||
super(xml, tag, id, arity);
|
||||
this.lib = xml.lib;
|
||||
activatePrototypeMap(MAX_FUNCTION_ID);
|
||||
}
|
||||
|
||||
private void writeSetting(Scriptable target)
|
||||
{
|
||||
for (int i = 1; i <= MAX_INSTANCE_ID; ++i) {
|
||||
int id = super.getMaxInstanceId() + i;
|
||||
String name = getInstanceIdName(id);
|
||||
Object value = getInstanceIdValue(id);
|
||||
ScriptableObject.putProperty(target, name, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void readSettings(Scriptable source)
|
||||
{
|
||||
for (int i = 1; i <= MAX_INSTANCE_ID; ++i) {
|
||||
int id = super.getMaxInstanceId() + i;
|
||||
String name = getInstanceIdName(id);
|
||||
Object value = ScriptableObject.getProperty(source, name);
|
||||
if (value == Scriptable.NOT_FOUND) {
|
||||
continue;
|
||||
}
|
||||
switch (i) {
|
||||
case Id_ignoreComments:
|
||||
case Id_ignoreProcessingInstructions:
|
||||
case Id_ignoreWhitespace:
|
||||
case Id_prettyPrinting:
|
||||
if (!(value instanceof Boolean)) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case Id_prettyIndent:
|
||||
if (!(value instanceof Number)) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
setInstanceIdValue(id, value);
|
||||
}
|
||||
}
|
||||
|
||||
// #string_id_map#
|
||||
|
||||
private static final int
|
||||
Id_ignoreComments = 1,
|
||||
Id_ignoreProcessingInstructions = 2,
|
||||
Id_ignoreWhitespace = 3,
|
||||
Id_prettyIndent = 4,
|
||||
Id_prettyPrinting = 5,
|
||||
|
||||
MAX_INSTANCE_ID = 5;
|
||||
|
||||
protected int getMaxInstanceId()
|
||||
{
|
||||
return super.getMaxInstanceId() + MAX_INSTANCE_ID;
|
||||
}
|
||||
|
||||
protected int findInstanceIdInfo(String s) {
|
||||
int id;
|
||||
// #generated# Last update: 2004-07-19 13:03:52 CEST
|
||||
L0: { id = 0; String X = null; int c;
|
||||
L: switch (s.length()) {
|
||||
case 12: X="prettyIndent";id=Id_prettyIndent; break L;
|
||||
case 14: c=s.charAt(0);
|
||||
if (c=='i') { X="ignoreComments";id=Id_ignoreComments; }
|
||||
else if (c=='p') { X="prettyPrinting";id=Id_prettyPrinting; }
|
||||
break L;
|
||||
case 16: X="ignoreWhitespace";id=Id_ignoreWhitespace; break L;
|
||||
case 28: X="ignoreProcessingInstructions";id=Id_ignoreProcessingInstructions; break L;
|
||||
}
|
||||
if (X!=null && X!=s && !X.equals(s)) id = 0;
|
||||
}
|
||||
// #/generated#
|
||||
|
||||
if (id == 0) return super.findInstanceIdInfo(s);
|
||||
|
||||
int attr;
|
||||
switch (id) {
|
||||
case Id_ignoreComments:
|
||||
case Id_ignoreProcessingInstructions:
|
||||
case Id_ignoreWhitespace:
|
||||
case Id_prettyIndent:
|
||||
case Id_prettyPrinting:
|
||||
attr = PERMANENT | DONTENUM;
|
||||
break;
|
||||
default: throw new IllegalStateException();
|
||||
}
|
||||
return instanceIdInfo(attr, super.getMaxInstanceId() + id);
|
||||
}
|
||||
|
||||
// #/string_id_map#
|
||||
|
||||
protected String getInstanceIdName(int id)
|
||||
{
|
||||
switch (id - super.getMaxInstanceId()) {
|
||||
case Id_ignoreComments: return "ignoreComments";
|
||||
case Id_ignoreProcessingInstructions: return "ignoreProcessingInstructions";
|
||||
case Id_ignoreWhitespace: return "ignoreWhitespace";
|
||||
case Id_prettyIndent: return "prettyIndent";
|
||||
case Id_prettyPrinting: return "prettyPrinting";
|
||||
}
|
||||
return super.getInstanceIdName(id);
|
||||
}
|
||||
|
||||
protected Object getInstanceIdValue(int id)
|
||||
{
|
||||
switch (id - super.getMaxInstanceId()) {
|
||||
case Id_ignoreComments:
|
||||
return ScriptRuntime.wrapBoolean(lib.ignoreComments);
|
||||
case Id_ignoreProcessingInstructions:
|
||||
return ScriptRuntime.wrapBoolean(lib.ignoreProcessingInstructions);
|
||||
case Id_ignoreWhitespace:
|
||||
return ScriptRuntime.wrapBoolean(lib.ignoreWhitespace);
|
||||
case Id_prettyIndent:
|
||||
return ScriptRuntime.wrapInt(lib.prettyIndent);
|
||||
case Id_prettyPrinting:
|
||||
return ScriptRuntime.wrapBoolean(lib.prettyPrinting);
|
||||
}
|
||||
return super.getInstanceIdValue(id);
|
||||
}
|
||||
|
||||
protected void setInstanceIdValue(int id, Object value)
|
||||
{
|
||||
switch (id - super.getMaxInstanceId()) {
|
||||
case Id_ignoreComments:
|
||||
lib.ignoreComments = ScriptRuntime.toBoolean(value);
|
||||
return;
|
||||
case Id_ignoreProcessingInstructions:
|
||||
lib.ignoreProcessingInstructions = ScriptRuntime.toBoolean(value);
|
||||
return;
|
||||
case Id_ignoreWhitespace:
|
||||
lib.ignoreWhitespace = ScriptRuntime.toBoolean(value);
|
||||
return;
|
||||
case Id_prettyIndent:
|
||||
lib.prettyIndent = ScriptRuntime.toInt32(value);
|
||||
return;
|
||||
case Id_prettyPrinting:
|
||||
lib.prettyPrinting = ScriptRuntime.toBoolean(value);
|
||||
return;
|
||||
}
|
||||
super.setInstanceIdValue(id, value);
|
||||
}
|
||||
|
||||
// #string_id_map#
|
||||
private static final int
|
||||
Id_defaultSettings = 1,
|
||||
Id_settings = 2,
|
||||
Id_setSettings = 3,
|
||||
MAX_FUNCTION_ID = 3;
|
||||
|
||||
protected int findPrototypeId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2004-07-19 13:03:52 CEST
|
||||
L0: { id = 0; String X = null;
|
||||
int s_length = s.length();
|
||||
if (s_length==8) { X="settings";id=Id_settings; }
|
||||
else if (s_length==11) { X="setSettings";id=Id_setSettings; }
|
||||
else if (s_length==15) { X="defaultSettings";id=Id_defaultSettings; }
|
||||
if (X!=null && X!=s && !X.equals(s)) id = 0;
|
||||
}
|
||||
// #/generated#
|
||||
return id;
|
||||
}
|
||||
// #/string_id_map#
|
||||
|
||||
protected void initPrototypeId(int id)
|
||||
{
|
||||
String s;
|
||||
int arity;
|
||||
switch (id) {
|
||||
case Id_defaultSettings: arity=0; s="defaultSettings"; break;
|
||||
case Id_settings: arity=0; s="settings"; break;
|
||||
case Id_setSettings: arity=1; s="setSettings"; break;
|
||||
default: throw new IllegalArgumentException(String.valueOf(id));
|
||||
}
|
||||
initPrototypeMethod(XMLCTOR_TAG, id, s, arity);
|
||||
}
|
||||
|
||||
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
|
||||
Scriptable thisObj, Object[] args)
|
||||
{
|
||||
if (!f.hasTag(XMLCTOR_TAG)) {
|
||||
return super.execIdCall(f, cx, scope, thisObj, args);
|
||||
}
|
||||
int id = f.methodId();
|
||||
switch (id) {
|
||||
case Id_defaultSettings: {
|
||||
lib.defaultSettings();
|
||||
Scriptable obj = cx.newObject(scope);
|
||||
writeSetting(obj);
|
||||
return obj;
|
||||
}
|
||||
case Id_settings: {
|
||||
Scriptable obj = cx.newObject(scope);
|
||||
writeSetting(obj);
|
||||
return obj;
|
||||
}
|
||||
case Id_setSettings: {
|
||||
if (args.length == 0
|
||||
|| args[0] == null
|
||||
|| args[0] == Undefined.instance)
|
||||
{
|
||||
lib.defaultSettings();
|
||||
} else if (args[0] instanceof Scriptable) {
|
||||
readSettings((Scriptable)args[0]);
|
||||
}
|
||||
return Undefined.instance;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(String.valueOf(id));
|
||||
}
|
||||
}
|
||||
@@ -1,754 +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-2000
|
||||
* 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 ***** */
|
||||
|
||||
package org.mozilla.javascript.xml.impl.xmlbeans;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
import org.mozilla.javascript.xml.*;
|
||||
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
import org.apache.xmlbeans.XmlObject;
|
||||
|
||||
public final class XMLLibImpl extends XMLLib implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Scriptable globalScope;
|
||||
|
||||
XML xmlPrototype;
|
||||
XMLList xmlListPrototype;
|
||||
Namespace namespacePrototype;
|
||||
QName qnamePrototype;
|
||||
|
||||
|
||||
// Environment settings...
|
||||
boolean ignoreComments;
|
||||
boolean ignoreProcessingInstructions;
|
||||
boolean ignoreWhitespace;
|
||||
boolean prettyPrinting;
|
||||
int prettyIndent;
|
||||
|
||||
Scriptable globalScope()
|
||||
{
|
||||
return globalScope;
|
||||
}
|
||||
|
||||
private XMLLibImpl(Scriptable globalScope)
|
||||
{
|
||||
this.globalScope = globalScope;
|
||||
defaultSettings();
|
||||
}
|
||||
|
||||
public static void init(Context cx, Scriptable scope, boolean sealed)
|
||||
{
|
||||
// To force LinkageError if XmlObject is not available
|
||||
XmlObject.class.getName();
|
||||
|
||||
XMLLibImpl lib = new XMLLibImpl(scope);
|
||||
XMLLib bound = lib.bindToScope(scope);
|
||||
if (bound == lib) {
|
||||
lib.exportToScope(sealed);
|
||||
}
|
||||
}
|
||||
|
||||
private void exportToScope(boolean sealed)
|
||||
{
|
||||
xmlPrototype = XML.createEmptyXML(this);
|
||||
xmlListPrototype = new XMLList(this);
|
||||
namespacePrototype = new Namespace(this, "", "");
|
||||
qnamePrototype = new QName(this, "", "", "");
|
||||
|
||||
xmlPrototype.exportAsJSClass(sealed);
|
||||
xmlListPrototype.exportAsJSClass(sealed);
|
||||
namespacePrototype.exportAsJSClass(sealed);
|
||||
qnamePrototype.exportAsJSClass(sealed);
|
||||
}
|
||||
|
||||
void defaultSettings()
|
||||
{
|
||||
ignoreComments = true;
|
||||
ignoreProcessingInstructions = true;
|
||||
ignoreWhitespace = true;
|
||||
prettyPrinting = true;
|
||||
prettyIndent = 2;
|
||||
}
|
||||
|
||||
XMLName toAttributeName(Context cx, Object nameValue)
|
||||
{
|
||||
String uri;
|
||||
String localName;
|
||||
|
||||
if (nameValue instanceof String) {
|
||||
uri = "";
|
||||
localName = (String)nameValue;
|
||||
} else if (nameValue instanceof XMLName) {
|
||||
XMLName xmlName = (XMLName)nameValue;
|
||||
if (!xmlName.isAttributeName()) {
|
||||
xmlName.setAttributeName();
|
||||
}
|
||||
return xmlName;
|
||||
} else if (nameValue instanceof QName) {
|
||||
QName qname = (QName)nameValue;
|
||||
uri = qname.uri();
|
||||
localName = qname.localName();
|
||||
} else if (nameValue instanceof Boolean
|
||||
|| nameValue instanceof Number
|
||||
|| nameValue == Undefined.instance
|
||||
|| nameValue == null)
|
||||
{
|
||||
throw badXMLName(nameValue);
|
||||
} else {
|
||||
uri = "";
|
||||
localName = ScriptRuntime.toString(nameValue);
|
||||
}
|
||||
XMLName xmlName = XMLName.formProperty(uri, localName);
|
||||
xmlName.setAttributeName();
|
||||
return xmlName;
|
||||
}
|
||||
|
||||
private static RuntimeException badXMLName(Object value)
|
||||
{
|
||||
String msg;
|
||||
if (value instanceof Number) {
|
||||
msg = "Can not construct XML name from number: ";
|
||||
} else if (value instanceof Boolean) {
|
||||
msg = "Can not construct XML name from boolean: ";
|
||||
} else if (value == Undefined.instance || value == null) {
|
||||
msg = "Can not construct XML name from ";
|
||||
} else {
|
||||
throw new IllegalArgumentException(value.toString());
|
||||
}
|
||||
return ScriptRuntime.typeError(msg+ScriptRuntime.toString(value));
|
||||
}
|
||||
|
||||
XMLName toXMLName(Context cx, Object nameValue)
|
||||
{
|
||||
XMLName result;
|
||||
|
||||
if (nameValue instanceof XMLName) {
|
||||
result = (XMLName)nameValue;
|
||||
} else if (nameValue instanceof QName) {
|
||||
QName qname = (QName)nameValue;
|
||||
result = XMLName.formProperty(qname.uri(), qname.localName());
|
||||
} else if (nameValue instanceof String) {
|
||||
result = toXMLNameFromString(cx, (String)nameValue);
|
||||
} else if (nameValue instanceof Boolean
|
||||
|| nameValue instanceof Number
|
||||
|| nameValue == Undefined.instance
|
||||
|| nameValue == null)
|
||||
{
|
||||
throw badXMLName(nameValue);
|
||||
} else {
|
||||
String name = ScriptRuntime.toString(nameValue);
|
||||
result = toXMLNameFromString(cx, name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* If value represents Uint32 index, make it available through
|
||||
* ScriptRuntime.lastUint32Result(cx) and return null.
|
||||
* Otherwise return the same value as toXMLName(cx, value).
|
||||
*/
|
||||
XMLName toXMLNameOrIndex(Context cx, Object value)
|
||||
{
|
||||
XMLName result;
|
||||
|
||||
if (value instanceof XMLName) {
|
||||
result = (XMLName)value;
|
||||
} else if (value instanceof String) {
|
||||
String str = (String)value;
|
||||
long test = ScriptRuntime.testUint32String(str);
|
||||
if (test >= 0) {
|
||||
ScriptRuntime.storeUint32Result(cx, test);
|
||||
result = null;
|
||||
} else {
|
||||
result = toXMLNameFromString(cx, str);
|
||||
}
|
||||
} else if (value instanceof Number) {
|
||||
double d = ((Number)value).doubleValue();
|
||||
long l = (long)d;
|
||||
if (l == d && 0 <= l && l <= 0xFFFFFFFFL) {
|
||||
ScriptRuntime.storeUint32Result(cx, l);
|
||||
result = null;
|
||||
} else {
|
||||
throw badXMLName(value);
|
||||
}
|
||||
} else if (value instanceof QName) {
|
||||
QName qname = (QName)value;
|
||||
String uri = qname.uri();
|
||||
boolean number = false;
|
||||
result = null;
|
||||
if (uri != null && uri.length() == 0) {
|
||||
// Only in this case qname.toString() can resemble uint32
|
||||
long test = ScriptRuntime.testUint32String(uri);
|
||||
if (test >= 0) {
|
||||
ScriptRuntime.storeUint32Result(cx, test);
|
||||
number = true;
|
||||
}
|
||||
}
|
||||
if (!number) {
|
||||
result = XMLName.formProperty(uri, qname.localName());
|
||||
}
|
||||
} else if (value instanceof Boolean
|
||||
|| value == Undefined.instance
|
||||
|| value == null)
|
||||
{
|
||||
throw badXMLName(value);
|
||||
} else {
|
||||
String str = ScriptRuntime.toString(value);
|
||||
long test = ScriptRuntime.testUint32String(str);
|
||||
if (test >= 0) {
|
||||
ScriptRuntime.storeUint32Result(cx, test);
|
||||
result = null;
|
||||
} else {
|
||||
result = toXMLNameFromString(cx, str);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
XMLName toXMLNameFromString(Context cx, String name)
|
||||
{
|
||||
if (name == null)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
int l = name.length();
|
||||
if (l != 0) {
|
||||
char firstChar = name.charAt(0);
|
||||
if (firstChar == '*') {
|
||||
if (l == 1) {
|
||||
return XMLName.formStar();
|
||||
}
|
||||
} else if (firstChar == '@') {
|
||||
XMLName xmlName = XMLName.formProperty("", name.substring(1));
|
||||
xmlName.setAttributeName();
|
||||
return xmlName;
|
||||
}
|
||||
}
|
||||
|
||||
String uri = getDefaultNamespaceURI(cx);
|
||||
|
||||
return XMLName.formProperty(uri, name);
|
||||
}
|
||||
|
||||
Namespace constructNamespace(Context cx, Object uriValue)
|
||||
{
|
||||
String prefix;
|
||||
String uri;
|
||||
|
||||
if (uriValue instanceof Namespace) {
|
||||
Namespace ns = (Namespace)uriValue;
|
||||
prefix = ns.prefix();
|
||||
uri = ns.uri();
|
||||
} else if (uriValue instanceof QName) {
|
||||
QName qname = (QName)uriValue;
|
||||
uri = qname.uri();
|
||||
if (uri != null) {
|
||||
prefix = qname.prefix();
|
||||
} else {
|
||||
uri = qname.toString();
|
||||
prefix = null;
|
||||
}
|
||||
} else {
|
||||
uri = ScriptRuntime.toString(uriValue);
|
||||
prefix = (uri.length() == 0) ? "" : null;
|
||||
}
|
||||
|
||||
return new Namespace(this, prefix, uri);
|
||||
}
|
||||
|
||||
Namespace castToNamespace(Context cx, Object namescapeObj)
|
||||
{
|
||||
if (namescapeObj instanceof Namespace) {
|
||||
return (Namespace)namescapeObj;
|
||||
}
|
||||
return constructNamespace(cx, namescapeObj);
|
||||
}
|
||||
|
||||
Namespace constructNamespace(Context cx)
|
||||
{
|
||||
return new Namespace(this, "", "");
|
||||
}
|
||||
|
||||
public Namespace constructNamespace(Context cx, Object prefixValue,
|
||||
Object uriValue)
|
||||
{
|
||||
String prefix;
|
||||
String uri;
|
||||
|
||||
if (uriValue instanceof QName) {
|
||||
QName qname = (QName)uriValue;
|
||||
uri = qname.uri();
|
||||
if (uri == null) {
|
||||
uri = qname.toString();
|
||||
}
|
||||
} else {
|
||||
uri = ScriptRuntime.toString(uriValue);
|
||||
}
|
||||
|
||||
if (uri.length() == 0) {
|
||||
if (prefixValue == Undefined.instance) {
|
||||
prefix = "";
|
||||
} else {
|
||||
prefix = ScriptRuntime.toString(prefixValue);
|
||||
if (prefix.length() != 0) {
|
||||
throw ScriptRuntime.typeError(
|
||||
"Illegal prefix '"+prefix+"' for 'no namespace'.");
|
||||
}
|
||||
}
|
||||
} else if (prefixValue == Undefined.instance) {
|
||||
prefix = "";
|
||||
} else if (!isXMLName(cx, prefixValue)) {
|
||||
prefix = "";
|
||||
} else {
|
||||
prefix = ScriptRuntime.toString(prefixValue);
|
||||
}
|
||||
|
||||
return new Namespace(this, prefix, uri);
|
||||
}
|
||||
|
||||
String getDefaultNamespaceURI(Context cx)
|
||||
{
|
||||
String uri = "";
|
||||
if (cx == null) {
|
||||
cx = Context.getCurrentContext();
|
||||
}
|
||||
if (cx != null) {
|
||||
Object ns = ScriptRuntime.searchDefaultNamespace(cx);
|
||||
if (ns != null) {
|
||||
if (ns instanceof Namespace) {
|
||||
uri = ((Namespace)ns).uri();
|
||||
} else {
|
||||
// Should not happen but for now it could
|
||||
// due to bad searchDefaultNamespace implementation.
|
||||
}
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
Namespace getDefaultNamespace(Context cx)
|
||||
{
|
||||
if (cx == null) {
|
||||
cx = Context.getCurrentContext();
|
||||
if (cx == null) {
|
||||
return namespacePrototype;
|
||||
}
|
||||
}
|
||||
|
||||
Namespace result;
|
||||
Object ns = ScriptRuntime.searchDefaultNamespace(cx);
|
||||
if (ns == null) {
|
||||
result = namespacePrototype;
|
||||
} else {
|
||||
if (ns instanceof Namespace) {
|
||||
result = (Namespace)ns;
|
||||
} else {
|
||||
// Should not happen but for now it could
|
||||
// due to bad searchDefaultNamespace implementation.
|
||||
result = namespacePrototype;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QName castToQName(Context cx, Object qnameValue)
|
||||
{
|
||||
if (qnameValue instanceof QName) {
|
||||
return (QName)qnameValue;
|
||||
}
|
||||
return constructQName(cx, qnameValue);
|
||||
}
|
||||
|
||||
QName constructQName(Context cx, Object nameValue)
|
||||
{
|
||||
QName result;
|
||||
|
||||
if (nameValue instanceof QName) {
|
||||
QName qname = (QName)nameValue;
|
||||
result = new QName(this, qname.uri(), qname.localName(),
|
||||
qname.prefix());
|
||||
} else {
|
||||
String localName = ScriptRuntime.toString(nameValue);
|
||||
result = constructQNameFromString(cx, localName);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimized version of constructQName for String type
|
||||
*/
|
||||
QName constructQNameFromString(Context cx, String localName)
|
||||
{
|
||||
if (localName == null)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
String uri;
|
||||
String prefix;
|
||||
|
||||
if ("*".equals(localName)) {
|
||||
uri = null;
|
||||
prefix = null;
|
||||
} else {
|
||||
Namespace ns = getDefaultNamespace(cx);
|
||||
uri = ns.uri();
|
||||
prefix = ns.prefix();
|
||||
}
|
||||
|
||||
return new QName(this, uri, localName, prefix);
|
||||
}
|
||||
|
||||
QName constructQName(Context cx, Object namespaceValue, Object nameValue)
|
||||
{
|
||||
String uri;
|
||||
String localName;
|
||||
String prefix;
|
||||
|
||||
if (nameValue instanceof QName) {
|
||||
QName qname = (QName)nameValue;
|
||||
localName = qname.localName();
|
||||
} else {
|
||||
localName = ScriptRuntime.toString(nameValue);
|
||||
}
|
||||
|
||||
Namespace ns;
|
||||
if (namespaceValue == Undefined.instance) {
|
||||
if ("*".equals(localName)) {
|
||||
ns = null;
|
||||
} else {
|
||||
ns = getDefaultNamespace(cx);
|
||||
}
|
||||
} else if (namespaceValue == null) {
|
||||
ns = null;
|
||||
} else if (namespaceValue instanceof Namespace) {
|
||||
ns = (Namespace)namespaceValue;
|
||||
} else {
|
||||
ns = constructNamespace(cx, namespaceValue);
|
||||
}
|
||||
|
||||
if (ns == null) {
|
||||
uri = null;
|
||||
prefix = null;
|
||||
} else {
|
||||
uri = ns.uri();
|
||||
prefix = ns.prefix();
|
||||
}
|
||||
|
||||
return new QName(this, uri, localName, prefix);
|
||||
}
|
||||
|
||||
Object addXMLObjects(Context cx, XMLObject obj1, XMLObject obj2)
|
||||
{
|
||||
XMLList listToAdd = new XMLList(this);
|
||||
|
||||
if (obj1 instanceof XMLList) {
|
||||
XMLList list1 = (XMLList)obj1;
|
||||
if (list1.length() == 1) {
|
||||
listToAdd.addToList(list1.item(0));
|
||||
} else {
|
||||
// Might be xmlFragment + xmlFragment + xmlFragment + ...;
|
||||
// then the result will be an XMLList which we want to be an
|
||||
// rValue and allow it to be assigned to an lvalue.
|
||||
listToAdd = new XMLList(this, obj1);
|
||||
}
|
||||
} else {
|
||||
listToAdd.addToList(obj1);
|
||||
}
|
||||
|
||||
if (obj2 instanceof XMLList) {
|
||||
XMLList list2 = (XMLList)obj2;
|
||||
for (int i = 0; i < list2.length(); i++) {
|
||||
listToAdd.addToList(list2.item(i));
|
||||
}
|
||||
} else if (obj2 instanceof XML) {
|
||||
listToAdd.addToList(obj2);
|
||||
}
|
||||
|
||||
return listToAdd;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// Overriding XMLLib methods
|
||||
//
|
||||
//
|
||||
|
||||
/**
|
||||
* See E4X 13.1.2.1.
|
||||
*/
|
||||
public boolean isXMLName(Context cx, Object nameObj)
|
||||
{
|
||||
String name;
|
||||
try {
|
||||
name = ScriptRuntime.toString(nameObj);
|
||||
} catch (EcmaError ee) {
|
||||
if ("TypeError".equals(ee.getName())) {
|
||||
return false;
|
||||
}
|
||||
throw ee;
|
||||
}
|
||||
|
||||
// See http://w3.org/TR/xml-names11/#NT-NCName
|
||||
int length = name.length();
|
||||
if (length != 0) {
|
||||
if (isNCNameStartChar(name.charAt(0))) {
|
||||
for (int i = 1; i != length; ++i) {
|
||||
if (!isNCNameChar(name.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isNCNameStartChar(int c)
|
||||
{
|
||||
if ((c & ~0x7F) == 0) {
|
||||
// Optimize for ASCII and use A..Z < _ < a..z
|
||||
if (c >= 'a') {
|
||||
return c <= 'z';
|
||||
} else if (c >= 'A') {
|
||||
if (c <= 'Z') {
|
||||
return true;
|
||||
}
|
||||
return c == '_';
|
||||
}
|
||||
} else if ((c & ~0x1FFF) == 0) {
|
||||
return (0xC0 <= c && c <= 0xD6)
|
||||
|| (0xD8 <= c && c <= 0xF6)
|
||||
|| (0xF8 <= c && c <= 0x2FF)
|
||||
|| (0x370 <= c && c <= 0x37D)
|
||||
|| 0x37F <= c;
|
||||
}
|
||||
return (0x200C <= c && c <= 0x200D)
|
||||
|| (0x2070 <= c && c <= 0x218F)
|
||||
|| (0x2C00 <= c && c <= 0x2FEF)
|
||||
|| (0x3001 <= c && c <= 0xD7FF)
|
||||
|| (0xF900 <= c && c <= 0xFDCF)
|
||||
|| (0xFDF0 <= c && c <= 0xFFFD)
|
||||
|| (0x10000 <= c && c <= 0xEFFFF);
|
||||
}
|
||||
|
||||
private static boolean isNCNameChar(int c)
|
||||
{
|
||||
if ((c & ~0x7F) == 0) {
|
||||
// Optimize for ASCII and use - < . < 0..9 < A..Z < _ < a..z
|
||||
if (c >= 'a') {
|
||||
return c <= 'z';
|
||||
} else if (c >= 'A') {
|
||||
if (c <= 'Z') {
|
||||
return true;
|
||||
}
|
||||
return c == '_';
|
||||
} else if (c >= '0') {
|
||||
return c <= '9';
|
||||
} else {
|
||||
return c == '-' || c == '.';
|
||||
}
|
||||
} else if ((c & ~0x1FFF) == 0) {
|
||||
return isNCNameStartChar(c) || c == 0xB7
|
||||
|| (0x300 <= c && c <= 0x36F);
|
||||
}
|
||||
return isNCNameStartChar(c) || (0x203F <= c && c <= 0x2040);
|
||||
}
|
||||
|
||||
XMLName toQualifiedName(Context cx, Object namespaceValue,
|
||||
Object nameValue)
|
||||
{
|
||||
// This is duplication of constructQName(cx, namespaceValue, nameValue)
|
||||
// but for XMLName
|
||||
|
||||
String uri;
|
||||
String localName;
|
||||
|
||||
if (nameValue instanceof QName) {
|
||||
QName qname = (QName)nameValue;
|
||||
localName = qname.localName();
|
||||
} else {
|
||||
localName = ScriptRuntime.toString(nameValue);
|
||||
}
|
||||
|
||||
Namespace ns;
|
||||
if (namespaceValue == Undefined.instance) {
|
||||
if ("*".equals(localName)) {
|
||||
ns = null;
|
||||
} else {
|
||||
ns = getDefaultNamespace(cx);
|
||||
}
|
||||
} else if (namespaceValue == null) {
|
||||
ns = null;
|
||||
} else if (namespaceValue instanceof Namespace) {
|
||||
ns = (Namespace)namespaceValue;
|
||||
} else {
|
||||
ns = constructNamespace(cx, namespaceValue);
|
||||
}
|
||||
|
||||
if (ns == null) {
|
||||
uri = null;
|
||||
} else {
|
||||
uri = ns.uri();
|
||||
}
|
||||
|
||||
return XMLName.formProperty(uri, localName);
|
||||
}
|
||||
|
||||
public Ref nameRef(Context cx, Object name,
|
||||
Scriptable scope, int memberTypeFlags)
|
||||
{
|
||||
if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) == 0) {
|
||||
// should only be called foir cases like @name or @[expr]
|
||||
throw Kit.codeBug();
|
||||
}
|
||||
XMLName xmlName = toAttributeName(cx, name);
|
||||
return xmlPrimaryReference(cx, xmlName, scope);
|
||||
}
|
||||
|
||||
public Ref nameRef(Context cx, Object namespace, Object name,
|
||||
Scriptable scope, int memberTypeFlags)
|
||||
{
|
||||
XMLName xmlName = toQualifiedName(cx, namespace, name);
|
||||
if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0) {
|
||||
if (!xmlName.isAttributeName()) {
|
||||
xmlName.setAttributeName();
|
||||
}
|
||||
}
|
||||
return xmlPrimaryReference(cx, xmlName, scope);
|
||||
}
|
||||
|
||||
private Ref xmlPrimaryReference(Context cx, XMLName xmlName,
|
||||
Scriptable scope)
|
||||
{
|
||||
XMLObjectImpl xmlObj;
|
||||
XMLObjectImpl firstXmlObject = null;
|
||||
for (;;) {
|
||||
// XML object can only present on scope chain as a wrapper
|
||||
// of XMLWithScope
|
||||
if (scope instanceof XMLWithScope) {
|
||||
xmlObj = (XMLObjectImpl)scope.getPrototype();
|
||||
if (xmlObj.hasXMLProperty(xmlName)) {
|
||||
break;
|
||||
}
|
||||
if (firstXmlObject == null) {
|
||||
firstXmlObject = xmlObj;
|
||||
}
|
||||
}
|
||||
scope = scope.getParentScope();
|
||||
if (scope == null) {
|
||||
xmlObj = firstXmlObject;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// xmlObj == null corresponds to undefined as the target of
|
||||
// the reference
|
||||
if (xmlObj != null) {
|
||||
xmlName.initXMLObject(xmlObj);
|
||||
}
|
||||
return xmlName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes the reserved characters in a value of an attribute
|
||||
*
|
||||
* @param value Unescaped text
|
||||
* @return The escaped text
|
||||
*/
|
||||
public String escapeAttributeValue(Object value)
|
||||
{
|
||||
String text = ScriptRuntime.toString(value);
|
||||
|
||||
if (text.length() == 0) return "";
|
||||
|
||||
XmlObject xo = XmlObject.Factory.newInstance();
|
||||
|
||||
XmlCursor cursor = xo.newCursor();
|
||||
cursor.toNextToken();
|
||||
cursor.beginElement("a");
|
||||
cursor.insertAttributeWithValue("a", text);
|
||||
cursor.dispose();
|
||||
|
||||
String elementText = xo.toString();
|
||||
int begin = elementText.indexOf('"');
|
||||
int end = elementText.lastIndexOf('"');
|
||||
return elementText.substring(begin + 1, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes the reserved characters in a value of a text node
|
||||
*
|
||||
* @param value Unescaped text
|
||||
* @return The escaped text
|
||||
*/
|
||||
public String escapeTextValue(Object value)
|
||||
{
|
||||
if (value instanceof XMLObjectImpl) {
|
||||
return ((XMLObjectImpl)value).toXMLString(0);
|
||||
}
|
||||
|
||||
String text = ScriptRuntime.toString(value);
|
||||
|
||||
if (text.length() == 0) return text;
|
||||
|
||||
XmlObject xo = XmlObject.Factory.newInstance();
|
||||
|
||||
XmlCursor cursor = xo.newCursor();
|
||||
cursor.toNextToken();
|
||||
cursor.beginElement("a");
|
||||
cursor.insertChars(text);
|
||||
cursor.dispose();
|
||||
|
||||
String elementText = xo.toString();
|
||||
int begin = elementText.indexOf('>') + 1;
|
||||
int end = elementText.lastIndexOf('<');
|
||||
return (begin < end) ? elementText.substring(begin, end) : "";
|
||||
}
|
||||
|
||||
public Object toDefaultXmlNamespace(Context cx, Object uriValue)
|
||||
{
|
||||
return constructNamespace(cx, uriValue);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,171 +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-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Bukanov
|
||||
* Milen Nankov
|
||||
*
|
||||
* 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.xml.impl.xmlbeans;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Kit;
|
||||
import org.mozilla.javascript.Ref;
|
||||
import org.mozilla.javascript.ScriptRuntime;
|
||||
import org.mozilla.javascript.Undefined;
|
||||
|
||||
class XMLName extends Ref
|
||||
{
|
||||
static final long serialVersionUID = 3832176310755686977L;
|
||||
|
||||
private String uri;
|
||||
private String localName;
|
||||
private boolean isAttributeName;
|
||||
private boolean isDescendants;
|
||||
private XMLObjectImpl xmlObject;
|
||||
|
||||
private XMLName(String uri, String localName)
|
||||
{
|
||||
this.uri = uri;
|
||||
this.localName = localName;
|
||||
}
|
||||
|
||||
static XMLName formStar()
|
||||
{
|
||||
return new XMLName(null, "*");
|
||||
}
|
||||
|
||||
static XMLName formProperty(String uri, String localName)
|
||||
{
|
||||
return new XMLName(uri, localName);
|
||||
}
|
||||
|
||||
void initXMLObject(XMLObjectImpl xmlObject)
|
||||
{
|
||||
if (xmlObject == null) throw new IllegalArgumentException();
|
||||
if (this.xmlObject != null) throw new IllegalStateException();
|
||||
this.xmlObject = xmlObject;
|
||||
}
|
||||
|
||||
String uri()
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
String localName()
|
||||
{
|
||||
return localName;
|
||||
}
|
||||
|
||||
boolean isAttributeName()
|
||||
{
|
||||
return isAttributeName;
|
||||
}
|
||||
|
||||
void setAttributeName()
|
||||
{
|
||||
if (isAttributeName) throw new IllegalStateException();
|
||||
isAttributeName = true;
|
||||
}
|
||||
|
||||
boolean isDescendants()
|
||||
{
|
||||
return isDescendants;
|
||||
}
|
||||
|
||||
void setIsDescendants()
|
||||
{
|
||||
if (isDescendants) throw new IllegalStateException();
|
||||
isDescendants = true;
|
||||
}
|
||||
|
||||
public boolean has(Context cx)
|
||||
{
|
||||
if (xmlObject == null) {
|
||||
return false;
|
||||
}
|
||||
return xmlObject.hasXMLProperty(this);
|
||||
}
|
||||
|
||||
public Object get(Context cx)
|
||||
{
|
||||
if (xmlObject == null) {
|
||||
throw ScriptRuntime.undefReadError(Undefined.instance,
|
||||
toString());
|
||||
}
|
||||
return xmlObject.getXMLProperty(this);
|
||||
}
|
||||
|
||||
public Object set(Context cx, Object value)
|
||||
{
|
||||
if (xmlObject == null) {
|
||||
throw ScriptRuntime.undefWriteError(Undefined.instance,
|
||||
toString(),
|
||||
value);
|
||||
}
|
||||
// Assignment to descendants causes parse error on bad reference
|
||||
// and this should not be called
|
||||
if (isDescendants) throw Kit.codeBug();
|
||||
xmlObject.putXMLProperty(this, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean delete(Context cx)
|
||||
{
|
||||
if (xmlObject == null) {
|
||||
return true;
|
||||
}
|
||||
xmlObject.deleteXMLProperty(this);
|
||||
return !xmlObject.hasXMLProperty(this);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
//return qname.localName();
|
||||
StringBuffer buff = new StringBuffer();
|
||||
if (isDescendants) buff.append("..");
|
||||
if (isAttributeName) buff.append('@');
|
||||
if (uri == null) {
|
||||
buff.append('*');
|
||||
if(localName().equals("*")) {
|
||||
return buff.toString();
|
||||
}
|
||||
} else {
|
||||
buff.append('"').append(uri()).append('"');
|
||||
}
|
||||
buff.append(':').append(localName());
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,724 +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-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Bukanov
|
||||
* Ethan Hugg
|
||||
* Terry Lucas
|
||||
* Milen Nankov
|
||||
*
|
||||
* 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.xml.impl.xmlbeans;
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
import org.mozilla.javascript.xml.*;
|
||||
|
||||
/**
|
||||
* This abstract class describes what all XML objects (XML, XMLList) should have in common.
|
||||
*
|
||||
* @see XML
|
||||
*/
|
||||
abstract class XMLObjectImpl extends XMLObject
|
||||
{
|
||||
private static final Object XMLOBJECT_TAG = "XMLObject";
|
||||
|
||||
protected final XMLLibImpl lib;
|
||||
protected boolean prototypeFlag;
|
||||
|
||||
protected XMLObjectImpl(XMLLibImpl lib, XMLObject prototype)
|
||||
{
|
||||
super(lib.globalScope(), prototype);
|
||||
this.lib = lib;
|
||||
}
|
||||
|
||||
/**
|
||||
* ecmaHas(cx, id) calls this after resolving when id to XMLName
|
||||
* and checking it is not Uint32 index.
|
||||
*/
|
||||
abstract boolean hasXMLProperty(XMLName name);
|
||||
|
||||
/**
|
||||
* ecmaGet(cx, id) calls this after resolving when id to XMLName
|
||||
* and checking it is not Uint32 index.
|
||||
*/
|
||||
abstract Object getXMLProperty(XMLName name);
|
||||
|
||||
/**
|
||||
* ecmaPut(cx, id, value) calls this after resolving when id to XMLName
|
||||
* and checking it is not Uint32 index.
|
||||
*/
|
||||
abstract void putXMLProperty(XMLName name, Object value);
|
||||
|
||||
/**
|
||||
* ecmaDelete(cx, id) calls this after resolving when id to XMLName
|
||||
* and checking it is not Uint32 index.
|
||||
*/
|
||||
abstract void deleteXMLProperty(XMLName name);
|
||||
|
||||
/**
|
||||
* Test XML equality with target the target.
|
||||
*/
|
||||
abstract boolean equivalentXml(Object target);
|
||||
|
||||
// Methods from section 12.4.4 in the spec
|
||||
abstract XML addNamespace(Namespace ns);
|
||||
abstract XML appendChild(Object xml);
|
||||
abstract XMLList attribute(XMLName xmlName);
|
||||
abstract XMLList attributes();
|
||||
abstract XMLList child(long index);
|
||||
abstract XMLList child(XMLName xmlName);
|
||||
abstract int childIndex();
|
||||
abstract XMLList children();
|
||||
abstract XMLList comments();
|
||||
abstract boolean contains(Object xml);
|
||||
abstract Object copy();
|
||||
abstract XMLList descendants(XMLName xmlName);
|
||||
abstract Object[] inScopeNamespaces();
|
||||
abstract XML insertChildAfter(Object child, Object xml);
|
||||
abstract XML insertChildBefore(Object child, Object xml);
|
||||
abstract boolean hasOwnProperty(XMLName xmlName);
|
||||
abstract boolean hasComplexContent();
|
||||
abstract boolean hasSimpleContent();
|
||||
abstract int length();
|
||||
abstract String localName();
|
||||
abstract QName name();
|
||||
abstract Object namespace(String prefix);
|
||||
abstract Object[] namespaceDeclarations();
|
||||
abstract Object nodeKind();
|
||||
abstract void normalize();
|
||||
abstract Object parent();
|
||||
abstract XML prependChild(Object xml);
|
||||
abstract Object processingInstructions(XMLName xmlName);
|
||||
abstract boolean propertyIsEnumerable(Object member);
|
||||
abstract XML removeNamespace(Namespace ns);
|
||||
abstract XML replace(long index, Object xml);
|
||||
abstract XML replace(XMLName name, Object xml);
|
||||
abstract XML setChildren(Object xml);
|
||||
abstract void setLocalName(String name);
|
||||
abstract void setName(QName xmlName);
|
||||
abstract void setNamespace(Namespace ns);
|
||||
abstract XMLList text();
|
||||
public abstract String toString();
|
||||
abstract String toSource(int indent);
|
||||
abstract String toXMLString(int indent);
|
||||
abstract Object valueOf();
|
||||
|
||||
/**
|
||||
* Extension to access native implementation from scripts
|
||||
*/
|
||||
abstract org.apache.xmlbeans.XmlObject getXmlObject();
|
||||
|
||||
protected abstract Object jsConstructor(Context cx, boolean inNewExpr,
|
||||
Object[] args);
|
||||
|
||||
|
||||
final Object getMethod(String id)
|
||||
{
|
||||
return super.get(id, this);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// Methods overriding ScriptableObject
|
||||
//
|
||||
//
|
||||
|
||||
public final Object getDefaultValue(Class hint)
|
||||
{
|
||||
return toString();
|
||||
}
|
||||
|
||||
public void delete(String name)
|
||||
{
|
||||
throw new IllegalArgumentException("String: [" + name + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
* XMLObject always compare with any value and equivalentValues
|
||||
* never returns {@link Scriptable#NOT_FOUND} for them but rather
|
||||
* calls equivalentXml(value) and wrap the result as Boolean.
|
||||
*/
|
||||
protected final Object equivalentValues(Object value)
|
||||
{
|
||||
boolean result = equivalentXml(value);
|
||||
return result ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// Methods overriding XMLObject
|
||||
//
|
||||
//
|
||||
|
||||
public final XMLLib lib()
|
||||
{
|
||||
return lib;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ECMAScript [[Has]]
|
||||
*/
|
||||
public final boolean ecmaHas(Context cx, Object id)
|
||||
{
|
||||
if (cx == null) cx = Context.getCurrentContext();
|
||||
XMLName xmlName = lib.toXMLNameOrIndex(cx, id);
|
||||
if (xmlName == null) {
|
||||
long index = ScriptRuntime.lastUint32Result(cx);
|
||||
// XXX Fix this cast
|
||||
return has((int)index, this);
|
||||
}
|
||||
return hasXMLProperty(xmlName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ECMAScript [[Get]]
|
||||
*/
|
||||
public final Object ecmaGet(Context cx, Object id)
|
||||
{
|
||||
if (cx == null) cx = Context.getCurrentContext();
|
||||
XMLName xmlName = lib.toXMLNameOrIndex(cx, id);
|
||||
if (xmlName == null) {
|
||||
long index = ScriptRuntime.lastUint32Result(cx);
|
||||
// XXX Fix this cast
|
||||
Object result = get((int)index, this);
|
||||
if (result == Scriptable.NOT_FOUND) {
|
||||
result = Undefined.instance;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return getXMLProperty(xmlName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ECMAScript [[Put]]
|
||||
*/
|
||||
public final void ecmaPut(Context cx, Object id, Object value)
|
||||
{
|
||||
if (cx == null) cx = Context.getCurrentContext();
|
||||
XMLName xmlName = lib.toXMLNameOrIndex(cx, id);
|
||||
if (xmlName == null) {
|
||||
long index = ScriptRuntime.lastUint32Result(cx);
|
||||
// XXX Fix this cast
|
||||
put((int)index, this, value);
|
||||
return;
|
||||
}
|
||||
putXMLProperty(xmlName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ECMAScript [[Delete]].
|
||||
*/
|
||||
public final boolean ecmaDelete(Context cx, Object id)
|
||||
{
|
||||
if (cx == null) cx = Context.getCurrentContext();
|
||||
XMLName xmlName = lib.toXMLNameOrIndex(cx, id);
|
||||
if (xmlName == null) {
|
||||
long index = ScriptRuntime.lastUint32Result(cx);
|
||||
// XXX Fix this
|
||||
delete((int)index);
|
||||
return true;
|
||||
}
|
||||
deleteXMLProperty(xmlName);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Ref memberRef(Context cx, Object elem, int memberTypeFlags)
|
||||
{
|
||||
XMLName xmlName;
|
||||
if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0) {
|
||||
xmlName = lib.toAttributeName(cx, elem);
|
||||
} else {
|
||||
if ((memberTypeFlags & Node.DESCENDANTS_FLAG) == 0) {
|
||||
// Code generation would use ecma(Get|Has|Delete|Set) for
|
||||
// normal name idenrifiers so one ATTRIBUTE_FLAG
|
||||
// or DESCENDANTS_FLAG has to be set
|
||||
throw Kit.codeBug();
|
||||
}
|
||||
xmlName = lib.toXMLName(cx, elem);
|
||||
}
|
||||
if ((memberTypeFlags & Node.DESCENDANTS_FLAG) != 0) {
|
||||
xmlName.setIsDescendants();
|
||||
}
|
||||
xmlName.initXMLObject(this);
|
||||
return xmlName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic reference to implement x::ns, x.@ns::y, x..@ns::y etc.
|
||||
*/
|
||||
public Ref memberRef(Context cx, Object namespace, Object elem,
|
||||
int memberTypeFlags)
|
||||
{
|
||||
XMLName xmlName = lib.toQualifiedName(cx, namespace, elem);
|
||||
if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0) {
|
||||
if (!xmlName.isAttributeName()) {
|
||||
xmlName.setAttributeName();
|
||||
}
|
||||
}
|
||||
if ((memberTypeFlags & Node.DESCENDANTS_FLAG) != 0) {
|
||||
xmlName.setIsDescendants();
|
||||
}
|
||||
xmlName.initXMLObject(this);
|
||||
return xmlName;
|
||||
}
|
||||
|
||||
public NativeWith enterWith(Scriptable scope)
|
||||
{
|
||||
return new XMLWithScope(lib, scope, this);
|
||||
}
|
||||
|
||||
public NativeWith enterDotQuery(Scriptable scope)
|
||||
{
|
||||
XMLWithScope xws = new XMLWithScope(lib, scope, this);
|
||||
xws.initAsDotQuery();
|
||||
return xws;
|
||||
}
|
||||
|
||||
public final Object addValues(Context cx, boolean thisIsLeft,
|
||||
Object value)
|
||||
{
|
||||
if (value instanceof XMLObject) {
|
||||
XMLObject v1, v2;
|
||||
if (thisIsLeft) {
|
||||
v1 = this;
|
||||
v2 = (XMLObject)value;
|
||||
} else {
|
||||
v1 = (XMLObject)value;
|
||||
v2 = this;
|
||||
}
|
||||
return lib.addXMLObjects(cx, v1, v2);
|
||||
}
|
||||
if (value == Undefined.instance) {
|
||||
// both "xml + undefined" and "undefined + xml" gives String(xml)
|
||||
return ScriptRuntime.toString(this);
|
||||
}
|
||||
|
||||
return super.addValues(cx, thisIsLeft, value);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// IdScriptableObject machinery
|
||||
//
|
||||
//
|
||||
|
||||
final void exportAsJSClass(boolean sealed)
|
||||
{
|
||||
prototypeFlag = true;
|
||||
exportAsJSClass(MAX_PROTOTYPE_ID, lib.globalScope(), sealed);
|
||||
}
|
||||
|
||||
// #string_id_map#
|
||||
private final static int
|
||||
Id_constructor = 1,
|
||||
|
||||
Id_addNamespace = 2,
|
||||
Id_appendChild = 3,
|
||||
Id_attribute = 4,
|
||||
Id_attributes = 5,
|
||||
Id_child = 6,
|
||||
Id_childIndex = 7,
|
||||
Id_children = 8,
|
||||
Id_comments = 9,
|
||||
Id_contains = 10,
|
||||
Id_copy = 11,
|
||||
Id_descendants = 12,
|
||||
Id_inScopeNamespaces = 13,
|
||||
Id_insertChildAfter = 14,
|
||||
Id_insertChildBefore = 15,
|
||||
Id_hasOwnProperty = 16,
|
||||
Id_hasComplexContent = 17,
|
||||
Id_hasSimpleContent = 18,
|
||||
Id_length = 19,
|
||||
Id_localName = 20,
|
||||
Id_name = 21,
|
||||
Id_namespace = 22,
|
||||
Id_namespaceDeclarations = 23,
|
||||
Id_nodeKind = 24,
|
||||
Id_normalize = 25,
|
||||
Id_parent = 26,
|
||||
Id_prependChild = 27,
|
||||
Id_processingInstructions = 28,
|
||||
Id_propertyIsEnumerable = 29,
|
||||
Id_removeNamespace = 30,
|
||||
Id_replace = 31,
|
||||
Id_setChildren = 32,
|
||||
Id_setLocalName = 33,
|
||||
Id_setName = 34,
|
||||
Id_setNamespace = 35,
|
||||
Id_text = 36,
|
||||
Id_toString = 37,
|
||||
Id_toSource = 38,
|
||||
Id_toXMLString = 39,
|
||||
Id_valueOf = 40,
|
||||
|
||||
Id_getXmlObject = 41,
|
||||
|
||||
MAX_PROTOTYPE_ID = 41;
|
||||
|
||||
protected int findPrototypeId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2004-11-10 15:38:11 CET
|
||||
L0: { id = 0; String X = null; int c;
|
||||
L: switch (s.length()) {
|
||||
case 4: c=s.charAt(0);
|
||||
if (c=='c') { X="copy";id=Id_copy; }
|
||||
else if (c=='n') { X="name";id=Id_name; }
|
||||
else if (c=='t') { X="text";id=Id_text; }
|
||||
break L;
|
||||
case 5: X="child";id=Id_child; break L;
|
||||
case 6: c=s.charAt(0);
|
||||
if (c=='l') { X="length";id=Id_length; }
|
||||
else if (c=='p') { X="parent";id=Id_parent; }
|
||||
break L;
|
||||
case 7: c=s.charAt(0);
|
||||
if (c=='r') { X="replace";id=Id_replace; }
|
||||
else if (c=='s') { X="setName";id=Id_setName; }
|
||||
else if (c=='v') { X="valueOf";id=Id_valueOf; }
|
||||
break L;
|
||||
case 8: switch (s.charAt(4)) {
|
||||
case 'K': X="nodeKind";id=Id_nodeKind; break L;
|
||||
case 'a': X="contains";id=Id_contains; break L;
|
||||
case 'd': X="children";id=Id_children; break L;
|
||||
case 'e': X="comments";id=Id_comments; break L;
|
||||
case 'r': X="toString";id=Id_toString; break L;
|
||||
case 'u': X="toSource";id=Id_toSource; break L;
|
||||
} break L;
|
||||
case 9: switch (s.charAt(2)) {
|
||||
case 'c': X="localName";id=Id_localName; break L;
|
||||
case 'm': X="namespace";id=Id_namespace; break L;
|
||||
case 'r': X="normalize";id=Id_normalize; break L;
|
||||
case 't': X="attribute";id=Id_attribute; break L;
|
||||
} break L;
|
||||
case 10: c=s.charAt(0);
|
||||
if (c=='a') { X="attributes";id=Id_attributes; }
|
||||
else if (c=='c') { X="childIndex";id=Id_childIndex; }
|
||||
break L;
|
||||
case 11: switch (s.charAt(0)) {
|
||||
case 'a': X="appendChild";id=Id_appendChild; break L;
|
||||
case 'c': X="constructor";id=Id_constructor; break L;
|
||||
case 'd': X="descendants";id=Id_descendants; break L;
|
||||
case 's': X="setChildren";id=Id_setChildren; break L;
|
||||
case 't': X="toXMLString";id=Id_toXMLString; break L;
|
||||
} break L;
|
||||
case 12: switch (s.charAt(0)) {
|
||||
case 'a': X="addNamespace";id=Id_addNamespace; break L;
|
||||
case 'g': X="getXmlObject";id=Id_getXmlObject; break L;
|
||||
case 'p': X="prependChild";id=Id_prependChild; break L;
|
||||
case 's': c=s.charAt(3);
|
||||
if (c=='L') { X="setLocalName";id=Id_setLocalName; }
|
||||
else if (c=='N') { X="setNamespace";id=Id_setNamespace; }
|
||||
break L;
|
||||
} break L;
|
||||
case 14: X="hasOwnProperty";id=Id_hasOwnProperty; break L;
|
||||
case 15: X="removeNamespace";id=Id_removeNamespace; break L;
|
||||
case 16: c=s.charAt(0);
|
||||
if (c=='h') { X="hasSimpleContent";id=Id_hasSimpleContent; }
|
||||
else if (c=='i') { X="insertChildAfter";id=Id_insertChildAfter; }
|
||||
break L;
|
||||
case 17: c=s.charAt(3);
|
||||
if (c=='C') { X="hasComplexContent";id=Id_hasComplexContent; }
|
||||
else if (c=='c') { X="inScopeNamespaces";id=Id_inScopeNamespaces; }
|
||||
else if (c=='e') { X="insertChildBefore";id=Id_insertChildBefore; }
|
||||
break L;
|
||||
case 20: X="propertyIsEnumerable";id=Id_propertyIsEnumerable; break L;
|
||||
case 21: X="namespaceDeclarations";id=Id_namespaceDeclarations; break L;
|
||||
case 22: X="processingInstructions";id=Id_processingInstructions; break L;
|
||||
}
|
||||
if (X!=null && X!=s && !X.equals(s)) id = 0;
|
||||
}
|
||||
// #/generated#
|
||||
return id;
|
||||
}
|
||||
// #/string_id_map#
|
||||
|
||||
protected void initPrototypeId(int id)
|
||||
{
|
||||
String s;
|
||||
int arity;
|
||||
switch (id) {
|
||||
case Id_constructor: {
|
||||
IdFunctionObject ctor;
|
||||
if (this instanceof XML) {
|
||||
ctor = new XMLCtor((XML)this, XMLOBJECT_TAG, id, 1);
|
||||
} else {
|
||||
ctor = new IdFunctionObject(this, XMLOBJECT_TAG, id, 1);
|
||||
}
|
||||
initPrototypeConstructor(ctor);
|
||||
return;
|
||||
}
|
||||
|
||||
case Id_addNamespace: arity=1; s="addNamespace"; break;
|
||||
case Id_appendChild: arity=1; s="appendChild"; break;
|
||||
case Id_attribute: arity=1; s="attribute"; break;
|
||||
case Id_attributes: arity=0; s="attributes"; break;
|
||||
case Id_child: arity=1; s="child"; break;
|
||||
case Id_childIndex: arity=0; s="childIndex"; break;
|
||||
case Id_children: arity=0; s="children"; break;
|
||||
case Id_comments: arity=0; s="comments"; break;
|
||||
case Id_contains: arity=1; s="contains"; break;
|
||||
case Id_copy: arity=0; s="copy"; break;
|
||||
case Id_descendants: arity=1; s="descendants"; break;
|
||||
case Id_hasComplexContent: arity=0; s="hasComplexContent"; break;
|
||||
case Id_hasOwnProperty: arity=1; s="hasOwnProperty"; break;
|
||||
case Id_hasSimpleContent: arity=0; s="hasSimpleContent"; break;
|
||||
case Id_inScopeNamespaces: arity=0; s="inScopeNamespaces"; break;
|
||||
case Id_insertChildAfter: arity=2; s="insertChildAfter"; break;
|
||||
case Id_insertChildBefore: arity=2; s="insertChildBefore"; break;
|
||||
case Id_length: arity=0; s="length"; break;
|
||||
case Id_localName: arity=0; s="localName"; break;
|
||||
case Id_name: arity=0; s="name"; break;
|
||||
case Id_namespace: arity=1; s="namespace"; break;
|
||||
case Id_namespaceDeclarations:
|
||||
arity=0; s="namespaceDeclarations"; break;
|
||||
case Id_nodeKind: arity=0; s="nodeKind"; break;
|
||||
case Id_normalize: arity=0; s="normalize"; break;
|
||||
case Id_parent: arity=0; s="parent"; break;
|
||||
case Id_prependChild: arity=1; s="prependChild"; break;
|
||||
case Id_processingInstructions:
|
||||
arity=1; s="processingInstructions"; break;
|
||||
case Id_propertyIsEnumerable:
|
||||
arity=1; s="propertyIsEnumerable"; break;
|
||||
case Id_removeNamespace: arity=1; s="removeNamespace"; break;
|
||||
case Id_replace: arity=2; s="replace"; break;
|
||||
case Id_setChildren: arity=1; s="setChildren"; break;
|
||||
case Id_setLocalName: arity=1; s="setLocalName"; break;
|
||||
case Id_setName: arity=1; s="setName"; break;
|
||||
case Id_setNamespace: arity=1; s="setNamespace"; break;
|
||||
case Id_text: arity=0; s="text"; break;
|
||||
case Id_toString: arity=0; s="toString"; break;
|
||||
case Id_toSource: arity=1; s="toSource"; break;
|
||||
case Id_toXMLString: arity=1; s="toXMLString"; break;
|
||||
case Id_valueOf: arity=0; s="valueOf"; break;
|
||||
|
||||
case Id_getXmlObject: arity=0; s="getXmlObject"; break;
|
||||
default: throw new IllegalArgumentException(String.valueOf(id));
|
||||
}
|
||||
initPrototypeMethod(XMLOBJECT_TAG, id, s, arity);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param f
|
||||
* @param cx
|
||||
* @param scope
|
||||
* @param thisObj
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
|
||||
Scriptable thisObj, Object[] args)
|
||||
{
|
||||
if (!f.hasTag(XMLOBJECT_TAG)) {
|
||||
return super.execIdCall(f, cx, scope, thisObj, args);
|
||||
}
|
||||
int id = f.methodId();
|
||||
if (id == Id_constructor) {
|
||||
return jsConstructor(cx, thisObj == null, args);
|
||||
}
|
||||
|
||||
// All (XML|XMLList).prototype methods require thisObj to be XML
|
||||
if (!(thisObj instanceof XMLObjectImpl))
|
||||
throw incompatibleCallError(f);
|
||||
XMLObjectImpl realThis = (XMLObjectImpl)thisObj;
|
||||
|
||||
switch (id) {
|
||||
case Id_addNamespace: {
|
||||
Namespace ns = lib.castToNamespace(cx, arg(args, 0));
|
||||
return realThis.addNamespace(ns);
|
||||
}
|
||||
case Id_appendChild:
|
||||
return realThis.appendChild(arg(args, 0));
|
||||
case Id_attribute: {
|
||||
XMLName xmlName = lib.toAttributeName(cx, arg(args, 0));
|
||||
return realThis.attribute(xmlName);
|
||||
}
|
||||
case Id_attributes:
|
||||
return realThis.attributes();
|
||||
case Id_child: {
|
||||
XMLName xmlName = lib.toXMLNameOrIndex(cx, arg(args, 0));
|
||||
if (xmlName == null) {
|
||||
long index = ScriptRuntime.lastUint32Result(cx);
|
||||
return realThis.child(index);
|
||||
} else {
|
||||
return realThis.child(xmlName);
|
||||
}
|
||||
}
|
||||
case Id_childIndex:
|
||||
return ScriptRuntime.wrapInt(realThis.childIndex());
|
||||
case Id_children:
|
||||
return realThis.children();
|
||||
case Id_comments:
|
||||
return realThis.comments();
|
||||
case Id_contains:
|
||||
return ScriptRuntime.wrapBoolean(
|
||||
realThis.contains(arg(args, 0)));
|
||||
case Id_copy:
|
||||
return realThis.copy();
|
||||
case Id_descendants: {
|
||||
XMLName xmlName = (args.length == 0)
|
||||
? XMLName.formStar()
|
||||
: lib.toXMLName(cx, args[0]);
|
||||
return realThis.descendants(xmlName);
|
||||
}
|
||||
case Id_inScopeNamespaces: {
|
||||
Object[] array = realThis.inScopeNamespaces();
|
||||
return cx.newArray(scope, array);
|
||||
}
|
||||
case Id_insertChildAfter:
|
||||
return realThis.insertChildAfter(arg(args, 0), arg(args, 1));
|
||||
case Id_insertChildBefore:
|
||||
return realThis.insertChildBefore(arg(args, 0), arg(args, 1));
|
||||
case Id_hasOwnProperty: {
|
||||
XMLName xmlName = lib.toXMLName(cx, arg(args, 0));
|
||||
return ScriptRuntime.wrapBoolean(
|
||||
realThis.hasOwnProperty(xmlName));
|
||||
}
|
||||
case Id_hasComplexContent:
|
||||
return ScriptRuntime.wrapBoolean(realThis.hasComplexContent());
|
||||
case Id_hasSimpleContent:
|
||||
return ScriptRuntime.wrapBoolean(realThis.hasSimpleContent());
|
||||
case Id_length:
|
||||
return ScriptRuntime.wrapInt(realThis.length());
|
||||
case Id_localName:
|
||||
return realThis.localName();
|
||||
case Id_name:
|
||||
return realThis.name();
|
||||
case Id_namespace: {
|
||||
String prefix = (args.length > 0)
|
||||
? ScriptRuntime.toString(args[0]) : null;
|
||||
return realThis.namespace(prefix);
|
||||
}
|
||||
case Id_namespaceDeclarations: {
|
||||
Object[] array = realThis.namespaceDeclarations();
|
||||
return cx.newArray(scope, array);
|
||||
}
|
||||
case Id_nodeKind:
|
||||
return realThis.nodeKind();
|
||||
case Id_normalize:
|
||||
realThis.normalize();
|
||||
return Undefined.instance;
|
||||
case Id_parent:
|
||||
return realThis.parent();
|
||||
case Id_prependChild:
|
||||
return realThis.prependChild(arg(args, 0));
|
||||
case Id_processingInstructions: {
|
||||
XMLName xmlName = (args.length > 0)
|
||||
? lib.toXMLName(cx, args[0])
|
||||
: XMLName.formStar();
|
||||
return realThis.processingInstructions(xmlName);
|
||||
}
|
||||
case Id_propertyIsEnumerable: {
|
||||
return ScriptRuntime.wrapBoolean(
|
||||
realThis.propertyIsEnumerable(arg(args, 0)));
|
||||
}
|
||||
case Id_removeNamespace: {
|
||||
Namespace ns = lib.castToNamespace(cx, arg(args, 0));
|
||||
return realThis.removeNamespace(ns);
|
||||
}
|
||||
case Id_replace: {
|
||||
XMLName xmlName = lib.toXMLNameOrIndex(cx, arg(args, 0));
|
||||
Object arg1 = arg(args, 1);
|
||||
if (xmlName == null) {
|
||||
long index = ScriptRuntime.lastUint32Result(cx);
|
||||
return realThis.replace(index, arg1);
|
||||
} else {
|
||||
return realThis.replace(xmlName, arg1);
|
||||
}
|
||||
}
|
||||
case Id_setChildren:
|
||||
return realThis.setChildren(arg(args, 0));
|
||||
case Id_setLocalName: {
|
||||
String localName;
|
||||
Object arg = arg(args, 0);
|
||||
if (arg instanceof QName) {
|
||||
localName = ((QName)arg).localName();
|
||||
} else {
|
||||
localName = ScriptRuntime.toString(arg);
|
||||
}
|
||||
realThis.setLocalName(localName);
|
||||
return Undefined.instance;
|
||||
}
|
||||
case Id_setName: {
|
||||
Object arg = (args.length != 0) ? args[0] : Undefined.instance;
|
||||
QName qname;
|
||||
if (arg instanceof QName) {
|
||||
qname = (QName)arg;
|
||||
if (qname.uri() == null) {
|
||||
qname = lib.constructQNameFromString(cx, qname.localName());
|
||||
} else {
|
||||
// E4X 13.4.4.35 requires to always construct QName
|
||||
qname = lib.constructQName(cx, qname);
|
||||
}
|
||||
} else {
|
||||
qname = lib.constructQName(cx, arg);
|
||||
}
|
||||
realThis.setName(qname);
|
||||
return Undefined.instance;
|
||||
}
|
||||
case Id_setNamespace: {
|
||||
Namespace ns = lib.castToNamespace(cx, arg(args, 0));
|
||||
realThis.setNamespace(ns);
|
||||
return Undefined.instance;
|
||||
}
|
||||
case Id_text:
|
||||
return realThis.text();
|
||||
case Id_toString:
|
||||
return realThis.toString();
|
||||
case Id_toSource: {
|
||||
int indent = ScriptRuntime.toInt32(args, 0);
|
||||
return realThis.toSource(indent);
|
||||
}
|
||||
case Id_toXMLString: {
|
||||
int indent = ScriptRuntime.toInt32(args, 0);
|
||||
return realThis.toXMLString(indent);
|
||||
}
|
||||
case Id_valueOf:
|
||||
return realThis.valueOf();
|
||||
|
||||
case Id_getXmlObject: {
|
||||
org.apache.xmlbeans.XmlObject xmlObject = realThis.getXmlObject();
|
||||
return Context.javaToJS(xmlObject, scope);
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(String.valueOf(id));
|
||||
}
|
||||
|
||||
private static Object arg(Object[] args, int i)
|
||||
{
|
||||
return (i < args.length) ? args[i] : Undefined.instance;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,125 +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
|
||||
* Ethan Hugg
|
||||
* Terry Lucas
|
||||
* Milen Nankov
|
||||
*
|
||||
* 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.xml.impl.xmlbeans;
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
import org.mozilla.javascript.xml.*;
|
||||
|
||||
final class XMLWithScope extends NativeWith
|
||||
{
|
||||
private static final long serialVersionUID = -696429282095170887L;
|
||||
|
||||
private XMLLibImpl lib;
|
||||
private int _currIndex;
|
||||
private XMLList _xmlList;
|
||||
private XMLObject _dqPrototype;
|
||||
|
||||
XMLWithScope(XMLLibImpl lib, Scriptable parent, XMLObject prototype)
|
||||
{
|
||||
super(parent, prototype);
|
||||
this.lib = lib;
|
||||
}
|
||||
|
||||
void initAsDotQuery()
|
||||
{
|
||||
XMLObject prototype = (XMLObject)getPrototype();
|
||||
// XMLWithScope also handles the .(xxx) DotQuery for XML
|
||||
// basically DotQuery is a for/in/with statement and in
|
||||
// the following 3 statements we setup to signal it's
|
||||
// DotQuery,
|
||||
// the index and the object being looped over. The
|
||||
// xws.setPrototype is the scope of the object which is
|
||||
// is a element of the lhs (XMLList).
|
||||
_currIndex = 0;
|
||||
_dqPrototype = prototype;
|
||||
if (prototype instanceof XMLList) {
|
||||
XMLList xl = (XMLList)prototype;
|
||||
if (xl.length() > 0) {
|
||||
setPrototype((Scriptable)(xl.get(0, null)));
|
||||
}
|
||||
}
|
||||
// Always return the outer-most type of XML lValue of
|
||||
// XML to left of dotQuery.
|
||||
_xmlList = new XMLList(lib);
|
||||
}
|
||||
|
||||
protected Object updateDotQuery(boolean value)
|
||||
{
|
||||
// Return null to continue looping
|
||||
|
||||
XMLObject seed = _dqPrototype;
|
||||
XMLList xmlL = _xmlList;
|
||||
|
||||
if (seed instanceof XMLList) {
|
||||
// We're a list so keep testing each element of the list if the
|
||||
// result on the top of stack is true then that element is added
|
||||
// to our result list. If false, we try the next element.
|
||||
XMLList orgXmlL = (XMLList)seed;
|
||||
|
||||
int idx = _currIndex;
|
||||
|
||||
if (value) {
|
||||
xmlL.addToList(orgXmlL.get(idx, null));
|
||||
}
|
||||
|
||||
// More elements to test?
|
||||
if (++idx < orgXmlL.length()) {
|
||||
// Yes, set our new index, get the next element and
|
||||
// reset the expression to run with this object as
|
||||
// the WITH selector.
|
||||
_currIndex = idx;
|
||||
setPrototype((Scriptable)(orgXmlL.get(idx, null)));
|
||||
|
||||
// continue looping
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
// If we're not a XMLList then there's no looping
|
||||
// just return DQPrototype if the result is true.
|
||||
if (value) {
|
||||
xmlL.addToList(seed);
|
||||
}
|
||||
}
|
||||
|
||||
return xmlL;
|
||||
}
|
||||
}
|
||||
195
mozilla/js/rhino/docs/RhinoDebugger.html
Normal file
195
mozilla/js/rhino/docs/RhinoDebugger.html
Normal file
@@ -0,0 +1,195 @@
|
||||
<!-- ***** 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">
|
||||
<META NAME="Generator" CONTENT="Microsoft Word 97">
|
||||
<TITLE>1</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
|
||||
<OL>
|
||||
|
||||
<B><FONT FACE="Arial" SIZE=5 COLOR="#000080"><LI>Using the Rhino JavaScript Debugger</LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The Mozilla Rhino JavaScript engine includes a source-level debugger for debugging JavaScript scripts. The debugger is itself a Java program which you may run as</P>
|
||||
</FONT><FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY">java org.mozilla.javascript.tools.debugger.JSDebugger [options] [filename.js] [script-arguments]</P>
|
||||
</FONT><FONT SIZE=2><P ALIGN="JUSTIFY">where the options are the same as the shell.</P>
|
||||
<OL>
|
||||
|
||||
<LI><A NAME="_Toc502165108"></FONT><B><FONT FACE="Arial" SIZE=4 COLOR="#000080">Features</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The Rhino JavaScript Debugger can debug scripts running in multiple threads and provides facilities to set and clear breakpoints, control execution, view variables, and evaluate arbitrary JavaScript code in the current scope of an executing script.</P>
|
||||
<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>
|
||||
<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->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>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">You may select the <B><I>File->Run</B></I> menu item on the menu bar to execute JavaScript scripts contained in files. This action will display a file-selection dialog box prompting you for the location of a script to execute. The loaded script will be run in a new thread and control will be given to the debugger on its first instruction.</P>
|
||||
<LI><A NAME="_Toc502165111"></FONT><B><FONT FACE="Arial" COLOR="#000080">Controlling Execution</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The debugger provides the following facilities for you to control the execution of scripts you are debugging:</P>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Step Into</LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">To single step entering any function calls, you may do any of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Select the <B><I>Debug->Step Into </B></I>menu item on the menu bar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the <B><I>Step Into</B></I> button on the toolbar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the F11 key on the keyboard</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">Execution will resume. If the current line in the script contains a function call control will return to the debugger upon entry into the function. Otherwise control will return to the debugger at the next line in the current function.</P>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Step Over</LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">To single step to the next line in the current function, you may do any of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Select the <B><I>Debug->Step Over</B></I> menu item on the menu bar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the <B><I>Step Over</B></I> button on the toolbar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the F7 key on the keyboard</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">Execution will resume but control will return to the debugger at the next line in the current function or top-level script.</P>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Step Out</LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">To continue execution until the current function returns you may do any of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Select the <B><I>Debug->Step Out</B></I> menu item on the menu bar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the <B><I>Step Out</B></I> button on the toolbar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the F8 key on the keyboard</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">Execution will resume until the current function returns or a breakpoint is hit.</P>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Go</LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">To resume execution of a script you may do any of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Select the <B><I>Debug->Go</B></I> menu item on the menu bar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the <B><I>Go</B></I> button on the toolbar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the F5 key on the keyboard</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">Execution will resume until a breakpoint is hit or the script completes.</P>
|
||||
<P ALIGN="JUSTIFY"> </P>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Break</LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">To stop all running scripts and give control to the debugger you may do any of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Select the <B><I>Debug->Break</B></I> menu item on the menu bar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the <B><I>Break</B></I> button on the toolbar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the Pause/Break key on the keyboard</LI></P></UL>
|
||||
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
<LI><A NAME="_Toc502165112"></FONT><B><FONT FACE="Arial" COLOR="#000080">Moving Up and Down the Stack</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The lower-left (dockable) pane in the debugger main window contains a combo-box labeled "Context:" which displays the current stack of the executing script. You may move up and down the stack by selecting an entry in the combo-box. When you select a stack frame the variables and watch windows are updated to reflect the names and values of the variables visible at that scope.</P>
|
||||
<LI><A NAME="_Toc502165113"></FONT><B><FONT FACE="Arial" COLOR="#000080">Setting and Clearing Breakpoints</A></LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The main desktop of the debugger contains file windows which display the contents of each script you are debugging. You may set a breakpoint in a script by doing one of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Place the cursor on the line at which you want to set a breakpoint and right-click with the mouse. This action will display a pop-up menu. Select the <B><I>Set Breakpoint</B></I> menu item. </LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Simply single-click on the line number of the line at which you want to set a breakpoint.</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">If the selected line contains executable code a red dot will appear next to the line number and a breakpoint will be set at that location.</P>
|
||||
<P ALIGN="JUSTIFY">You may set clear breakpoint in a script by doing one of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Place the cursor on the line at which you want to clear a breakpoint and right-click with the mouse. This action will display a pop-up menu. Select the <B><I>Clear Breakpoint</B></I> menu item. </LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Simply single-click on the red dot or the line number of the line at which you want to clear a breakpoint.</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">The red dot will disappear and the breakpoint at that location will be cleared.</P>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
<LI><A NAME="_Toc502165114"></FONT><B><FONT FACE="Arial" COLOR="#000080">Viewing Variables</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The lower-left (dockable) pane in the debugger main window contains a tab-pane with two tabs, labeled "this" and "Locals". Each pane contains a tree-table which displays the properties of the current object and currently visible local variables, respectively. </P>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>This</LI></OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The properties of the current object are displayed in the <B><I>this</B></I> table. If a property is itself a JavaScript object the property may be expanded to show its sub-properties. The <B><I>this</B></I> table is updated each time control returns to the debugger or when you change the stack location in the <B><I>Context:</B></I> window.</P>
|
||||
<LI><A NAME="_Toc502165115"></FONT><B><FONT FACE="Arial" COLOR="#000080">Locals</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The local variables of the current function are displayed in the <B><I>Locals</B></I> table. If a variable is itself a JavaScript object the variable may be expanded to show its sub-properties. The <B><I>Locals</B></I> table is updated each time control returns to the debugger or when you change the stack location in the <B><I>Context:</B></I> window</P>
|
||||
<LI><A NAME="_Toc502165116"></FONT><B><FONT FACE="Arial" COLOR="#000080">Watch Window</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">You may enter arbitrary JavaScript expressions in the <B><I>Watch:</B></I> table located in the lower-right (dockable) pane in the debugger main window. The expressions you enter are reevaluated in the current scope and their current values displayed each time control returns to the debugger or when you change the stack location in the <B><I>Context:</B></I> window.</P>
|
||||
<LI><A NAME="_Toc502165117"></FONT><B><FONT FACE="Arial" COLOR="#000080">Evaluation Window</A></LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The <B><I>Evaluate</B></I> pane located in the lower-right (dockable) pane in the debugger main window contains an editable command line where you may enter arbitrary JavaScript code. The code is evaluated in the context of the current stack frame. The window maintains a history of the commands you have entered. You may move backward or forward through the history by pressing the Up/Down arrow keys on the keyboard. </P>
|
||||
</FONT></BODY>
|
||||
</HTML>
|
||||
528
mozilla/js/rhino/docs/ScriptingJava.html
Normal file
528
mozilla/js/rhino/docs/ScriptingJava.html
Normal file
@@ -0,0 +1,528 @@
|
||||
<!-- ***** 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> 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> java
|
||||
[JavaPackage java]
|
||||
</pre>
|
||||
|
||||
<p>We can access Java classes simply by stepping down the
|
||||
package hierarchy:</p>
|
||||
|
||||
<pre>
|
||||
js> 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> importPackage(java.io)
|
||||
js> 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> 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> 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> f = new java.io.File("test.txt")
|
||||
test.txt
|
||||
js> f.exists()
|
||||
true
|
||||
js> f.getName()
|
||||
test.txt
|
||||
</pre>
|
||||
|
||||
<p>Static methods and fields can be accessed from the class object
|
||||
itself:</p>
|
||||
|
||||
<pre>
|
||||
js> java.lang.Math.PI
|
||||
3.141592653589793
|
||||
js> 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> 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> 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> f.name
|
||||
test.txt
|
||||
js> 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> o.g(3,4)
|
||||
js:"<stdin>", 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> obj = { run: function () { print("\nrunning"); } }
|
||||
[object Object]
|
||||
js> 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> 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> t = new java.lang.Thread(r)
|
||||
Thread[Thread-2,5,main]
|
||||
js> t.start()
|
||||
js>
|
||||
|
||||
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> t = java.lang.Thread(function () { print("\nrunning"); });
|
||||
Thread[Thread-0,5,main]
|
||||
js> t.start()
|
||||
js>
|
||||
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> var frame = new Packages.javax.swing.JFrame();
|
||||
js> frame.addWindowListener(function(event, methodName) {
|
||||
if (methodName == "windowClosing") {
|
||||
print("Calling System.exit()..."); java.lang.System.exit(0);
|
||||
}
|
||||
});
|
||||
js> frame.setSize(100, 100);
|
||||
js> frame.visible = true;
|
||||
true
|
||||
js> 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> 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> 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> a[0] = 104
|
||||
104
|
||||
js> a[1] = 105
|
||||
105
|
||||
js> 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> javaString = new java.lang.String("Java")
|
||||
Java
|
||||
js> jsString = "JavaScript"
|
||||
JavaScript
|
||||
js> javaString.length()
|
||||
4
|
||||
js> 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> 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>
|
||||
169
mozilla/js/rhino/docs/api.html
Normal file
169
mozilla/js/rhino/docs/api.html
Normal file
@@ -0,0 +1,169 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">
|
||||
<title>JavaScript API</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
|
||||
<h1 align="center">
|
||||
Rhino API Reference.</h1>
|
||||
|
||||
<h4>
|
||||
The Control API</h4>
|
||||
These APIs provide methods for controlling the actions of JavaScript in
|
||||
a host environment.
|
||||
<ul>
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/Context.html">Context</a> - Represents
|
||||
the runtime context of an executing script. Has methods to associate the
|
||||
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>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/Script.html">Script</a> - The result of
|
||||
compiling a JavaScript script. Also encapsulates script execution.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/ErrorReporter.html">ErrorReporter</a> -
|
||||
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>
|
||||
- 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
|
||||
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>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/serialize/ScriptableOutputStream.html">ScriptableOutputStream</a> - This stream can be used to serialize JavaScript objects and functions.
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/serialize/ScriptableInputStream.html">ScriptableInputStream</a> - This stream can be used to deserialize JavaScript objects and functions.
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<h4>
|
||||
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>.
|
||||
It is also helpful to understand some of the implementation of the <a href="runtime.html">runtime</a>.
|
||||
<ul>
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/Scriptable.html">Scriptable</a> - All JavaScript
|
||||
objects must implement this interface. Provides methods to access properties
|
||||
and attributes of those properties, as well as other services required
|
||||
of JavaScript objects.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/Function.html">Function</a> - All JavaScript
|
||||
functions must implement this interface. Extends Scriptable, adding methods
|
||||
to support invocation.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/ScriptableObject.html">ScriptableObject</a>
|
||||
- A default implementation of Scriptable that may be extended. Implements
|
||||
property and attribute storage and lookup and other default JavaScript
|
||||
object behavior.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/FunctionObject.html">FunctionObject</a>
|
||||
- An implementation of Function that allows Java methods and constructors
|
||||
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>
|
||||
</ul>
|
||||
|
||||
<h4>
|
||||
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>
|
||||
|
||||
<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>
|
||||
|
||||
<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>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/EvaluatorException.html">EvaluatorException</a>
|
||||
- An exception thrown when an error is detected during the compilation or execution of
|
||||
a script. The default error reporter will throw EvaluatorExceptions when
|
||||
an error is encountered.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="overview-summary.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
74
mozilla/js/rhino/docs/bsf.html
Normal file
74
mozilla/js/rhino/docs/bsf.html
Normal file
@@ -0,0 +1,74 @@
|
||||
<!-- ***** 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>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Rhino and BSF</h1>
|
||||
|
||||
<h2>What is BSF?</h2>
|
||||
<p>
|
||||
The <a href="http://jakarta.apache.org/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
|
||||
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>Now that the Apache Jakarta Bean Scripting Framework (BSF), version 2.4.0, has been officially released, you can use Rhino easily with BSF. See <a href="http://jakarta.apache.org/bsf/index.html">http://jakarta.apache.org/bsf/index.html</a>.
|
||||
</p>
|
||||
<p><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
78
mozilla/js/rhino/docs/changes.html
Normal file
78
mozilla/js/rhino/docs/changes.html
Normal file
@@ -0,0 +1,78 @@
|
||||
<!-- ***** 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">
|
||||
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
|
||||
<meta name="Author" content="Igor Bukanov">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Change Log</title>
|
||||
|
||||
<link rel="up" href="./" title="Rhino project page">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p class="crumbs"><em>You are here:</em> <a href="./">Rhino project page</a> > <strong>Change Log</strong></p>
|
||||
|
||||
<h1 style="text-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>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
283
mozilla/js/rhino/docs/debugger.html
Normal file
283
mozilla/js/rhino/docs/debugger.html
Normal file
@@ -0,0 +1,283 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.7 [en] (WinNT; I) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java, Debugger">
|
||||
<title>Rhino Debugger</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<script src="owner.js">
|
||||
|
||||
</script>
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Rhino JavaScript Debugger</h1></center>
|
||||
Christopher Oliver
|
||||
<br><script>document.write(owner());</script>
|
||||
|
||||
<br>6/28/2001
|
||||
<center>
|
||||
<hr WIDTH="100%"></center>
|
||||
The Rhino JavaScript debugger is a GUI that allows debugging of interpreted
|
||||
JavaScript scripts run in Rhino. Note that this debugger <i>will not</i>
|
||||
work with JavaScript scripts run in the mozilla browser since Rhino is
|
||||
not the engine used in such environments.
|
||||
<p><img SRC="jsdebug.jpg" height=460 width=600>
|
||||
<p>Current limitations:
|
||||
<ul>
|
||||
<li>
|
||||
Requires JDK 1.2 or greater</li>
|
||||
|
||||
<li>
|
||||
Requires js.jar from rhinoTip.zip</li>
|
||||
|
||||
<li>
|
||||
No breakpoint menu</li>
|
||||
</ul>
|
||||
<b><font face="Arial"><font color="#000080"><font size=+2>Using the Rhino
|
||||
JavaScript Debugger</font></font></font></b>
|
||||
<p><font size=-1>The Mozilla Rhino JavaScript engine includes a source-level
|
||||
debugger for debugging JavaScript scripts. The debugger is itself a Java
|
||||
program which you may run as</font>
|
||||
<ol><font face="Arial"><font size=-1>java org.mozilla.javascript.tools.debugger.Main
|
||||
[options] [filename.js] [script-arguments]</font></font></ol>
|
||||
<font size=-1>where the options are the same as the shell.</font>
|
||||
<p><font size=-1>The Rhino JavaScript Debugger can debug scripts running
|
||||
in multiple threads and provides facilities to set and clear breakpoints,
|
||||
control execution, view variables, and evaluate arbitrary JavaScript code
|
||||
in the current scope of an executing script.</font>
|
||||
<p><a NAME="_Toc502165109"></a><b><font face="Arial"><font color="#000080"><font size=-1>Console
|
||||
Window</font></font></font></b>
|
||||
<br><font size=-1>The debugger redirects the <font face="Arial">System.out</font>,
|
||||
<font face="Arial">System.in</font>,
|
||||
and <font face="Arial">System.err</font> 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.</font>
|
||||
<br><a NAME="_Toc502165110"></a><b><font face="Arial"><font color="#000080"><font size=-1>Opening
|
||||
Scripts</font></font></font></b>
|
||||
<br><font size=-1>You may select the <b><i>File->Open</i></b> 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.</font>
|
||||
<br><a NAME="_RunningScripts"></a><b><font face="Arial"><font color="#000080"><font size=-1>Running
|
||||
Scripts</font></font></font></b>
|
||||
<br><font size=-1>You may select the <b><i>File->Run</i></b> menu item
|
||||
on the menu bar to execute JavaScript scripts contained in files. This
|
||||
action will display a file-selection dialog box prompting you for the location
|
||||
of a script to execute. The loaded script will be run in a new thread and
|
||||
control will be given to the debugger on its first instruction.</font>
|
||||
<p><a NAME="_Toc502165111"></a><b><font face="Arial"><font color="#000080"><font size=+1>Controlling
|
||||
Execution</font></font></font></b>
|
||||
<br><font size=-1>The debugger provides the following facilities for you
|
||||
to control the execution of scripts you are debugging:</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Step Into</font></font></b>
|
||||
<br><font size=-1>To single step entering any function calls, you may do
|
||||
any of the following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Select the <b><i>Debug->Step Into </i></b>menu item on the
|
||||
menu bar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the <b><i>Step Into</i></b> button on the toolbar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the F11 key on the keyboard</font></li>
|
||||
</ul>
|
||||
<font size=-1>Execution will resume. If the current line in the script
|
||||
contains a function call control will return to the debugger upon entry
|
||||
into the function. Otherwise control will return to the debugger at the
|
||||
next line in the current function.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Step Over</font></font></b>
|
||||
<br><font size=-1>To single step to the next line in the current function,
|
||||
you may do any of the following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Select the <b><i>Debug->Step Over</i></b> menu item on the
|
||||
menu bar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the <b><i>Step Over</i></b> button on the toolbar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the F7 key on the keyboard</font></li>
|
||||
</ul>
|
||||
<font size=-1>Execution will resume but control will return to the debugger
|
||||
at the next line in the current function or top-level script.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Step Out</font></font></b>
|
||||
<br><font size=-1>To continue execution until the current function returns
|
||||
you may do any of the following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Select the <b><i>Debug->Step Out</i></b> menu item on the
|
||||
menu bar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the <b><i>Step Out</i></b> button on the toolbar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the F8 key on the keyboard</font></li>
|
||||
</ul>
|
||||
<font size=-1>Execution will resume until the current function returns
|
||||
or a breakpoint is hit.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Go</font></font></b>
|
||||
<br><font size=-1>To resume execution of a script you may do any of the
|
||||
following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Select the <b><i>Debug->Go</i></b> menu item on the menu
|
||||
bar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the <b><i>Go</i></b> button on the toolbar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the F5 key on the keyboard</font></li>
|
||||
</ul>
|
||||
<font size=-1>Execution will resume until a breakpoint is hit or the script
|
||||
completes.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Break</font></font></b>
|
||||
<br><font size=-1>To stop all running scripts and give control to the debugger
|
||||
you may do any of the following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Select the <b><i>Debug->Break</i></b> menu item on the menu
|
||||
bar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the <b><i>Break</i></b> button on the toolbar</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
|
||||
is exception is thrown select the <b><i>Debug->Break on Exceptions</i></b>
|
||||
checkbox from the menu bar. 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
|
||||
contains a combo-box labeled "Context:" which displays the current stack
|
||||
of the executing script. You may move up and down the stack by selecting
|
||||
an entry in the combo-box. When you select a stack frame the variables
|
||||
and watch windows are updated to reflect the names and values of the variables
|
||||
visible at that scope.</font>
|
||||
<p><a NAME="_Toc502165113"></a><b><font face="Arial"><font color="#000080">Setting
|
||||
and Clearing Breakpoints</font></font></b>
|
||||
<br><font size=-1>The main desktop of the debugger contains file windows
|
||||
which display the contents of each script you are debugging. You may set
|
||||
a breakpoint in a script by doing one of the following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Place the cursor on the line at which you want to set a breakpoint
|
||||
and right-click with the mouse. This action will display a pop-up menu.
|
||||
Select the <b><i>Set Breakpoint</i></b> menu item.</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Simply single-click on the line number of the line at which
|
||||
you want to set a breakpoint.</font></li>
|
||||
</ul>
|
||||
<font size=-1>If the selected line contains executable code a red dot will
|
||||
appear next to the line number and a breakpoint will be set at that location.</font>
|
||||
<p><font size=-1>You may clear breakpoint in a script by doing one of the
|
||||
following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Place the cursor on the line at which you want to clear a
|
||||
breakpoint and right-click with the mouse. This action will display a pop-up
|
||||
menu. Select the <b><i>Clear Breakpoint</i></b> menu item.</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Simply single-click on the red dot or the line number of
|
||||
the line at which you want to clear a breakpoint.</font></li>
|
||||
</ul>
|
||||
<font size=-1>The red dot will disappear and the breakpoint at that location
|
||||
will be cleared.</font>
|
||||
<p><a NAME="_Toc502165114"></a><b><font face="Arial"><font color="#000080"><font size=+1>Viewing
|
||||
Variables</font></font></font></b>
|
||||
<br><font size=-1>The lower-left (dockable) pane in the debugger main window
|
||||
contains a tab-pane with two tabs, labeled "this" and "Locals". Each pane
|
||||
contains a tree-table which displays the properties of the current object
|
||||
and currently visible local variables, respectively.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">This</font></font></b>
|
||||
<br><font size=-1>The properties of the current object are displayed in
|
||||
the
|
||||
<b><i>this</i></b> table. If a property is itself a JavaScript object
|
||||
the property may be expanded to show its sub-properties. The <b><i>this</i></b>
|
||||
table is updated each time control returns to the debugger or when you
|
||||
change the stack location in the <b><i>Context:</i></b> window.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Locals</font></font></b>
|
||||
<br><font size=-1>The local variables of the current function are displayed
|
||||
in the <b><i>Locals</i></b> table. If a variable is itself a JavaScript
|
||||
object the variable may be expanded to show its sub-properties. The <b><i>Locals</i></b>
|
||||
table is updated each time control returns to the debugger or when you
|
||||
change the stack location in the <b><i>Context:</i></b> window</font>
|
||||
<p><a NAME="_Toc502165116"></a><b><font face="Arial"><font color="#000080">Watch
|
||||
Window</font></font></b>
|
||||
<br><font size=-1>You may enter arbitrary JavaScript expressions in the
|
||||
<b><i>Watch:</i></b>
|
||||
table located in the lower-right (dockable) pane in the debugger main window.
|
||||
The expressions you enter are re-evaluated in the current scope and their
|
||||
current values displayed each time control returns to the debugger or when
|
||||
you change the stack location in the <b><i>Context:</i></b> window.</font>
|
||||
<p><a NAME="_Toc502165117"></a><b><font face="Arial"><font color="#000080">Evaluation
|
||||
Window</font></font></b>
|
||||
<br><font size=-1>The <b><i>Evaluate</i></b> pane located in the lower-right
|
||||
(dockable) pane in the debugger main window contains an editable command
|
||||
line where you may enter arbitrary JavaScript code. The code is evaluated
|
||||
in the context of the current stack frame. The window maintains a history
|
||||
of the commands you have entered. You may move backward or forward through
|
||||
the history by pressing the Up/Down arrow keys on the keyboard.</font>
|
||||
</body>
|
||||
</html>
|
||||
182
mozilla/js/rhino/docs/doc.html
Normal file
182
mozilla/js/rhino/docs/doc.html
Normal file
@@ -0,0 +1,182 @@
|
||||
<!-- ***** 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">
|
||||
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
|
||||
<title>Rhino Documentation</title>
|
||||
|
||||
<link rel="up" href="./" title="Rhino project page">
|
||||
<link rel="section" href="#general" title="General">
|
||||
<link rel="section" href="#scripts" title="Writing Scripts">
|
||||
<link rel="section" href="#javaScript" title="JavaScript Tools">
|
||||
<link rel="section" href="#embedding" title="Embedding Rhino">
|
||||
|
||||
<style type="text/css">
|
||||
h1 { text-align: center; }
|
||||
th { text-align: left; font-weight: normal; width: 220px; }
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<p class="crumbs"><em>You are here:</em> <a href="./">Rhino project page</a> > <strong>Rhino Documentation</strong></p>
|
||||
|
||||
<h1> Rhino Documentation</h1>
|
||||
|
||||
<h2><a name="general" id="general">General</a></h2>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th><a href="overview.html">Overview</a></th>
|
||||
<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>
|
||||
<tr>
|
||||
<th><a href="changes.html">Change log</a></th>
|
||||
<td>Recent Rhino Changes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><a href="opt.html">Optimization</a></th>
|
||||
<td>Details on the various optimization levels.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><a href="faq.html">FAQ</a></th>
|
||||
<td>Answers to frequently asked questions about Rhino.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><a class="ex-ref" 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>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2><a name="scripts" id="scripts">Writing Scripts</a></h2>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th><a href="ScriptingJava.html">Scripting Java</a></th>
|
||||
<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>
|
||||
<tr>
|
||||
<th><a href="perf.html">Performance Hints</a></th>
|
||||
<td>Some tips on writing faster JavaScript code.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2><a name="javascript" id="javascript">JavaScript Tools</a></h2>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th><a href="shell.html">JavaScript Shell</a></th>
|
||||
<td>Interactive or batch execution of scripts.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><a href="debugger.html">JavaScript Debugger</a></th>
|
||||
<td>Debugging scripts running in Rhino.</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="../js/tests/library.html">Testing</a></th>
|
||||
<td>Running the JavaScript test suite.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2><a name="embedding" id="embedding">Embedding Rhino</a></h2>
|
||||
<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/">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
|
||||
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>
|
||||
<tr>
|
||||
<th><a href="runtime.html">Runtime</a></th>
|
||||
<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>
|
||||
<tr>
|
||||
<th><a href="examples.html">Examples</a></th>
|
||||
<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
|
||||
<abbr title="Bean Scripting Framework">BSF</abbr></a></th>
|
||||
<td>How to use Rhino with apps that support
|
||||
<dfn>BSF (Bean Scripting Framework)</dfn> from the Apache Jakarta project.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
203
mozilla/js/rhino/docs/download.html
Normal file
203
mozilla/js/rhino/docs/download.html
Normal file
@@ -0,0 +1,203 @@
|
||||
<!-- ***** 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">
|
||||
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
<meta name="Author" content="Igor Bukanov">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Rhino Downloads</title>
|
||||
|
||||
<link rel="up" href="./" title="Rhino project page">
|
||||
<link rel="section" href="#binaries" title="Rhino Binaries">
|
||||
<link rel="section" href="#source" title="Getting source code for Rhino">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p class="crumbs"><em>You are here:</em> <a href="./">Rhino project page</a> > <strong>Rhino Downloads</strong></p>
|
||||
|
||||
<h1>Rhino Downloads</h1>
|
||||
<p>Rhino is available for download both in source and compiled form. </p>
|
||||
|
||||
<h2><a name="binaries" id="binaries">Binaries</a></h2>
|
||||
<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 <code class="filename">js.jar</code>
|
||||
with all Rhino classes, documentation, examples and sources.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Rhino 1.6R5 is the last qualified release. It includes support for
|
||||
<a class="ex-ref"
|
||||
href="http://www.ecma-international.org/publications/standards/Ecma-357.htm">ECMAScript for XML</a> (E4X). To implement E4X runtime Rhino uses <a class="ex-ref"
|
||||
href="http://xmlbeans.apache.org/">XMLBeans</a> library and if you
|
||||
would like to use E4X you need to add <code class="filename">xbean.jar</code>
|
||||
from XMLBeans distribution to your class path.</p>
|
||||
|
||||
<table class="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Release</th>
|
||||
<th scope="col">Release Date</th>
|
||||
<th scope="col">Change log</th>
|
||||
<th scope="col">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 <code class="filename">js.jar</code> for XSLT
|
||||
or for IBM's <dfn>Bean Scripting Framework (BSF)</dfn>, 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>
|
||||
|
||||
<h2><a name="source" id="source">Source</a></h2>
|
||||
<p>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://developer.mozilla.org/en/docs/Mozilla_Source_Code_Via_CVS">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</p>
|
||||
|
||||
<pre class="code"> cvs co mozilla/js/rhino
|
||||
</pre>
|
||||
|
||||
<p>to get the tip source.</p>
|
||||
<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 class="ex-ref" 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>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
312
mozilla/js/rhino/docs/embedding-engine.html
Normal file
312
mozilla/js/rhino/docs/embedding-engine.html
Normal file
@@ -0,0 +1,312 @@
|
||||
<!-- ***** 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="Generator" content="Microsoft Word 97">
|
||||
<meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">
|
||||
<title>Embedding ‘Scripting Host’ in Business Applications</title>
|
||||
</head>
|
||||
<body link="#0000FF">
|
||||
<b><font face="Arial"><font size=-1>Embedding
|
||||
‘Scripting Host’ in Business Applications</font></font></b>
|
||||
<p><b><font face="Arial"><font size=-1>Madhukumar Seshadri, <a href="http://www.cognizant.com)/">www.cognizant.com</a></font></font></b>
|
||||
<br>
|
||||
<br>
|
||||
<p><font face="Arial"><font size=-1>With web browsers, continuing to rule
|
||||
the human interface for applications, creating value by being ubiquitous,
|
||||
few adoptions of rich technology that’s getting brewed underneath, will
|
||||
help designing business applications even though most of the current ones
|
||||
are made with bird’s eye of the underlying technologies.</font></font>
|
||||
<p><font face="Arial"><font size=-1>JavaScript is a scripting language
|
||||
invented and developed by Netscape. The language was primarily designed
|
||||
for creating lightweight programming for web browser extensions by exposing
|
||||
the Document Object Model of an HTML page to the scripts. JavaScript is
|
||||
becoming object oriented and getting adopted for server-side scripting.</font></font>
|
||||
<p><font face="Arial"><font size=-1>JavaScript is also becoming a standard
|
||||
in the scripting world as Netscape is working closely with ECMA (European
|
||||
Computer Manufacturers Association) to make it as a standard scripting
|
||||
language for the script world. The standards are published as ECMA Script.</font></font>
|
||||
<p><font face="Arial"><font size=-1>JavaScript originally designed for
|
||||
exposing the DOM (Document Object Model) standardized by World Wide Web
|
||||
consortium (W3C), to help web page designers to control and manipulate
|
||||
the pages dynamically. ‘JavaScript’ engines were embedded in the browsers
|
||||
and they execute those portions of the code embedded in the HTML pages.</font></font>
|
||||
<p><font face="Arial"><font size=-1>In short, JavaScript engine embedded
|
||||
in the browser allowed extensions or manipulations for DOM Object run time
|
||||
for the HTML page by executing the ‘scripts’ associated with them. In other
|
||||
words, browser exposes its DOM object for the page to scripts for extensions
|
||||
and dynamic manipulations of the same, using a language that the script
|
||||
interpreter understands.</font></font>
|
||||
<p><font face="Arial"><font size=-1>Can I do the same for my application
|
||||
by exposing my custom business objects written in my middle-tier? Can I
|
||||
allow user to my write JavaScript extensions for my objects and also be
|
||||
host for executing those scripts?</font></font>
|
||||
<p><font face="Arial"><font size=-1>JavaScript host runs times are available
|
||||
as binaries written in major languages. Check out <a href="http://www.mozilla.org/js">www.mozilla.org/js</a>.
|
||||
Spider Monkey and Rhino are open source JavaScripting engines available
|
||||
from mozilla.</font></font>
|
||||
<p><font face="Arial"><font size=-1>Microsoft implementation of ECMA Script
|
||||
(ECMA Script is based on core JavaScript, created by Netscape) is called
|
||||
JScript. Microsoft binaries of jscript engine can be downloaded from http://msdn.microsoft.com/scripting/.</font></font>
|
||||
<p><font face="Arial"><font size=-1>This document doesn’t explain the JavaScript
|
||||
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>,
|
||||
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>
|
||||
<ul>
|
||||
<li>
|
||||
<font face="Arial"><font size=-1>Execute a plain ‘JavaScript’ code and
|
||||
use static Java object</font></font></li>
|
||||
|
||||
<li>
|
||||
<font face="Arial"><font size=-1>Instantiate external objects (written
|
||||
in Java) from the script and use them within the script</font></font></li>
|
||||
</ul>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
<p><font face="Arial"><font size=-1>Let us write a simple Javscript to
|
||||
test the above set goals,</font></font>
|
||||
<p><font face="Arial"><font size=-1><b>Fig 1</b> – jshosttest.js</font></font>
|
||||
<p><b><i><font face="Arial"><font size=-1>/* Test 1 */</font></font></i></b>
|
||||
<br><b><i><font face="Arial"><font size=-1>/* Use a static Java Object
|
||||
in the script */</font></font></i></b>
|
||||
<p><font face="Arial"><font size=-1>function test1() {</font></font>
|
||||
<br><font face="Arial"><font size=-1> var str;</font></font>
|
||||
<br><font face="Arial"><font size=-1> str = '"Hello World";</font></font>
|
||||
<br><font face="Arial"><font size=-1> return str;</font></font>
|
||||
<br><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>var str = test1( );</font></font>
|
||||
<br><font face="Arial"><font size=-1>//out is expected to be Java Object
|
||||
exposed to the script scope</font></font>
|
||||
<br><font face="Arial"><font size=-1>out.println ("JavaScript - Test 1
|
||||
- " + str);</font></font>
|
||||
<p><b><i><font face="Arial"><font size=-1>/* Test 2 */</font></font></i></b>
|
||||
<p><b><i><font face="Arial"><font size=-1>/* Instantiate a Javaobject for
|
||||
this scope and use it */</font></font></i></b>
|
||||
<p><font face="Arial"><font size=-1>function test2(){</font></font>
|
||||
<br><font face="Arial"><font size=-1> // create a Java
|
||||
string buffer object from JavaScript and use its java instance</font></font>
|
||||
<br><font face="Arial"><font size=-1> // This uses an
|
||||
another Java object created for creating new objects within Java and</font></font>
|
||||
<br><font face="Arial"><font size=-1> // brings the same
|
||||
for JavaScript execution scope</font></font>
|
||||
<br><font face="Arial"><font size=-1> // Refer _create.java
|
||||
for more information</font></font>
|
||||
<br><font face="Arial"><font size=-1> create.getInstance("java.lang.StringBuffer","buffer");</font></font>
|
||||
<br><font face="Arial"><font size=-1> //JavaScript refers
|
||||
the java object instance as ‘buffer’</font></font>
|
||||
<br><font face="Arial"><font size=-1> out.println(buffer.toString());</font></font>
|
||||
<br> <font face="Arial"><font size=-1>buffer.append("I
|
||||
am a javaobject dynamically created and executed in JavaScript");</font></font>
|
||||
<br> <font face="Arial"><font size=-1>return buffer.toString();</font></font>
|
||||
<br><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>var str = test2();</font></font>
|
||||
<br><font face="Arial"><font size=-1>out.println("From JavaScript - Test
|
||||
2 " + str);</font></font>
|
||||
<p><font face="Arial"><font size=-1>Let us write a simple Javahost Object
|
||||
using the Rhino engine to execute the above script,</font></font>
|
||||
<p><b><font face="Arial"><font size=-1>Fig 2.1 - JSHost.java</font></font></b>
|
||||
<p><font face="Arial"><font size=-1>/**</font></font>
|
||||
<br><font face="Arial"><font size=-1>* @author Madhukumar Seshadri</font></font>
|
||||
<br><font face="Arial"><font size=-1>* @version</font></font>
|
||||
<br><font face="Arial"><font size=-1>*/</font></font>
|
||||
<p><font face="Arial"><font size=-1>import org.mozilla.javascript.*;</font></font>
|
||||
<br><font face="Arial"><font size=-1>import java.io.*;</font></font>
|
||||
<br><font face="Arial"><font size=-1>import java.lang.*;</font></font>
|
||||
<br><i><font face="Arial"><font size=-1>// import com.xxx.xxx.*;</font></font></i>
|
||||
<p><font face="Arial"><font size=-1>public class JSHost extends Object
|
||||
{</font></font>
|
||||
<br><font face="Arial"><font size=-1> /** Creates new
|
||||
JSHost */</font></font>
|
||||
<br><font face="Arial"><font size=-1> public JSHost()
|
||||
{</font></font>
|
||||
<br><font face="Arial"><font size=-1> }</font></font>
|
||||
<p><i><font face="Arial"><font size=-1> /*** Executes
|
||||
.js file ***/</font></font></i>
|
||||
<br><font face="Arial"><font size=-1> public Object executeJS
|
||||
(String jsfname){</font></font>
|
||||
<br><font face="Arial"><font size=-1> //You can also
|
||||
use evaluateReader</font></font>
|
||||
<br><font face="Arial"><font size=-1> File fp = new File(jsfname);</font></font>
|
||||
<br><font face="Arial"><font size=-1> String str_buff
|
||||
=null;</font></font>
|
||||
<br><font face="Arial"><font size=-1> try {</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
FileReader fr = new FileReader(jsfname);</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
int length = (int) fp.length();</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
char cbuff[] = new char[(char)length];</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
fr.read(cbuff);</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
str_buff = new String(cbuff);</font></font>
|
||||
<br><font face="Arial"><font size=-1> } catch(Exception
|
||||
e) {</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
e.printStackTrace();</font></font>
|
||||
<br><font face="Arial"><font size=-1> }</font></font>
|
||||
<p><font face="Arial"><font size=-1> //Execute the .js
|
||||
file content</font></font>
|
||||
<br><font face="Arial"><font size=-1> return executeJSSource(str_buff);</font></font>
|
||||
<br><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><i><font face="Arial"><font size=-1>/*** Executes javascript source
|
||||
***/</font></font></i>
|
||||
<br><font face="Arial"><font size=-1>public Object executeJSSource (String
|
||||
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>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>
|
||||
<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,
|
||||
scope);</font></font>
|
||||
<br><font face="Arial"><font size=-1>scope.put("out", scope, jObj1);</font></font>
|
||||
<p><i><font face="Arial"><font size=-1>//------------ For Test 2 - Instantiate
|
||||
Create Object and get that in scope</font></font></i>
|
||||
<br><i><font face="Arial"><font size=-1>//Allow JScript to create Java
|
||||
Objects</font></font></i>
|
||||
<br><i><font face="Arial"><font size=-1>//Bring the _create object to context</font></font></i>
|
||||
<br><font face="Arial"><font size=-1>_create create = new _create( );</font></font>
|
||||
<br><i><font face="Arial"><font size=-1>//Register this context and scope
|
||||
to this create object instance</font></font></i>
|
||||
<br><font face="Arial"><font size=-1>create.registerContext(context,scope);</font></font>
|
||||
<br><font face="Arial"><font size=-1>//Scriptable jObj2 = Context.toObject(_create,
|
||||
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>any = context.evaluateString(scope,
|
||||
jsbuff, "", 1, null);</font></font>
|
||||
<br><i><font face="Arial"><font size=-1>//Exit the Context</font></font></i>
|
||||
<br><font face="Arial"><font size=-1>context.exit( );</font></font>
|
||||
<br><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>catch ( JavaScriptException jse) {</font></font>
|
||||
<br><font face="Arial"><font size=-1>jse.printStackTrace();</font></font>
|
||||
<br><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>return any;</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<br>
|
||||
<br>
|
||||
<p><font face="Arial"><font size=-1>Let us write a class for creating new
|
||||
Java objects and bringing them to this script execution scope,</font></font>
|
||||
<p><b><font face="Arial"><font size=-1>Fig 2.2 – _create.java</font></font></b>
|
||||
<p><i><font face="Arial"><font size=-1>/**</font></font></i>
|
||||
<p><i><font face="Arial"><font size=-1>* @author Madhukumar</font></font></i>
|
||||
<p><i><font face="Arial"><font size=-1>*/</font></font></i>
|
||||
<p><font face="Arial"><font size=-1>import java.lang.Class;</font></font>
|
||||
<p><font face="Arial"><font size=-1>import org.mozilla.javascript.*;</font></font>
|
||||
<p><font face="Arial"><font size=-1>public class _create extends Object
|
||||
{</font></font>
|
||||
<p><font face="Arial"><font size=-1>static Context ptr = null;</font></font>
|
||||
<p><font face="Arial"><font size=-1>static Scriptable scope =null;</font></font>
|
||||
<p><font face="Arial"><font size=-1>public _create () { }</font></font>
|
||||
<p><font face="Arial"><font size=-1>public void registerContext(Context
|
||||
cptr, Scriptable sc){</font></font>
|
||||
<p><font face="Arial"><font size=-1>ptr = cptr;</font></font>
|
||||
<p><font face="Arial"><font size=-1>scope = sc;</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>public void getInstance(String classname,String
|
||||
jsclassname) {</font></font>
|
||||
<p><font face="Arial"><font size=-1>Object any=null;</font></font>
|
||||
<p><font face="Arial"><font size=-1>try {</font></font>
|
||||
<p><font face="Arial"><font size=-1>Class thisclass = Class.forName(classname);</font></font>
|
||||
<p><font face="Arial"><font size=-1>any = thisclass.newInstance();</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>catch(Exception e){</font></font>
|
||||
<p><font face="Arial"><font size=-1>e.printStackTrace();</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>if( ptr != null) {</font></font>
|
||||
<p><font face="Arial"><font size=-1>if (scope !=null) {</font></font>
|
||||
<p><i><font face="Arial"><font size=-1>//register created object for this
|
||||
execution scope</font></font></i>
|
||||
<p><font face="Arial"><font size=-1>scope.put(jsclassname,scope,any);</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<br>
|
||||
<br>
|
||||
<p><font face="Arial"><font size=-1>It is time to test the code, so let
|
||||
us write a small object that will use the JSHost object,</font></font>
|
||||
<p><b><font face="Arial"><font size=-1>Fig 3 - JSHosttest.java</font></font></b>
|
||||
<p><font face="Arial"><font size=-1>/**</font></font>
|
||||
<p><font face="Arial"><font size=-1>* @author Madhukumar</font></font>
|
||||
<p><font face="Arial"><font size=-1>* @version</font></font>
|
||||
<p><font face="Arial"><font size=-1>*/</font></font>
|
||||
<p><font face="Arial"><font size=-1>public class JSHosttest extends Object
|
||||
{</font></font>
|
||||
<p><font face="Arial"><font size=-1>/** Creates new JSHostTest*/</font></font>
|
||||
<p><font face="Arial"><font size=-1>public JSHosttest() {</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>public static void main (String args[]){</font></font>
|
||||
<p><font face="Arial"><font size=-1>if (args.length < 1) {</font></font>
|
||||
<p><font face="Arial"><font size=-1>System.out.println("Usage - Java JSHosttest.class
|
||||
<js source file>");</font></font>
|
||||
<p><font face="Arial"><font size=-1>return;</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>JSHost jsh = new JSHost();</font></font>
|
||||
<p><font face="Arial"><font size=-1>System.out.println("Executing JavaScript
|
||||
file - " + args[0]);</font></font>
|
||||
<p><font face="Arial"><font size=-1>Object result = jsh.executeJS(args[0]);</font></font>
|
||||
<p><font face="Arial"><font size=-1>if (result instanceof String){</font></font>
|
||||
<p><font face="Arial"><font size=-1>System.out.println("Results - " + result);</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<br>
|
||||
<br>
|
||||
<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>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
||||
128
mozilla/js/rhino/docs/examples.html
Normal file
128
mozilla/js/rhino/docs/examples.html
Normal file
@@ -0,0 +1,128 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]">
|
||||
<title>Rhino Examples</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Rhino Examples</h1></center>
|
||||
Examples have been provided that show how to control the JavaScript engine
|
||||
and to implement scriptable host objects. All the examples are in the cvs
|
||||
tree at <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/">mozilla/js/rhino/examples</a></tt>.
|
||||
<br>
|
||||
<h2>
|
||||
Sample Scripts</h2>
|
||||
The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/unique.js">unique.js</a></tt>
|
||||
script allows printing unique lines from a file.
|
||||
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/liveConnect.js">liveConnect.js</a></tt>
|
||||
script shows a sample usage of LiveConnect (Java-to-JavaScript connectivity).
|
||||
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/jsdoc.js">jsdoc.js</a></tt>
|
||||
script is a JavaScript analog to Java's <tt>javadoc</tt>. It makes heavy
|
||||
use of regular expressions.
|
||||
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/checkParam.js">checkParam.js</a></tt>
|
||||
script is a useful tool to check that <tt>@param</tt> tags in Java documentation
|
||||
comments match the parameters in the corresponding Java method.
|
||||
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/enum.js">enum.js</a></tt>
|
||||
script is a good example of using a JavaAdapter to implement a Java interface
|
||||
using a JavaScript object.
|
||||
<p>The <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/NervousText.js">NervousText.js</a>
|
||||
script is a JavaScript implementation of the famous NervousText applet
|
||||
using JavaScript compiled to Java classes using <a href="jsc.html">jsc</a>.
|
||||
It can be run in the HTML page <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/NervousText.html">NervousText.html</a>.
|
||||
<br>
|
||||
<h2>
|
||||
Controlling the JavaScript Engine</h2>
|
||||
|
||||
<h4>
|
||||
The RunScript class</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript.java">RunScript.java</a></tt>
|
||||
is a simple program that executes a script from the command line.
|
||||
<h4>
|
||||
The Control class</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Control.java">Control.java</a></tt>
|
||||
is a program that executes a simple script and then manipulates the result.
|
||||
<h4>
|
||||
JavaScript Shell</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Shell.java">Shell.java</a></tt>
|
||||
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>
|
||||
is a program that creates a single global scope object and then shares
|
||||
it across multiple threads. Sharing the global scope allows both information
|
||||
to be shared across threads, and amortizes the cost of Context.initStandardObjects
|
||||
by only performing that expensive operation once.
|
||||
<br>
|
||||
<h2>
|
||||
Implementing Host Objects</h2>
|
||||
First check out the <a href="tutorial.html">tutorial</a>
|
||||
if you haven't already.
|
||||
<h4>
|
||||
The Foo class - Extending ScriptableObject</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Foo.java">Foo.java</a></tt>
|
||||
is a simple JavaScript host object that includes a property with an associated
|
||||
action and a variable argument method.
|
||||
<br>
|
||||
<h4>
|
||||
The Matrix class - Implementing Scriptable</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Matrix.java">Matrix.java</a></tt>
|
||||
provides a simple multidimensional array by implementing the Scriptable
|
||||
interface.
|
||||
<br>
|
||||
<h4>
|
||||
The File class - An advanced example</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/File.java">File.java</a></tt>
|
||||
extends ScriptableObject to provide a means of reading and writing files
|
||||
from JavaScript. A more involved example of host object definition.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
86
mozilla/js/rhino/docs/faq.html
Normal file
86
mozilla/js/rhino/docs/faq.html
Normal file
@@ -0,0 +1,86 @@
|
||||
<!-- ***** 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">
|
||||
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
<meta http-equiv="Content-Script-Type" content="text/javascript">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Rhino FAQ</title>
|
||||
|
||||
<link rel="up" href="./" title="Rhino project page">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript" src="owner.js"></script>
|
||||
|
||||
<p class="crumbs"><em>You are here:</em> <a href="./">Rhino project page</a> >
|
||||
<strong>Rhino FAQ</strong></p>
|
||||
|
||||
<h1 style="text-align: center;">Frequently Asked Questions about Rhino</h1>
|
||||
<script type="text/javascript">document.write(owner());</script>
|
||||
|
||||
<dl>
|
||||
|
||||
<dt>How do I create a Java array from JavaScript?</dt>
|
||||
<dd>You must use Java reflection. For instance, to create an array
|
||||
of java.lang.String of length five, do
|
||||
<pre class="code">
|
||||
var stringArray = java.lang.reflect.Array.newInstance(java.lang.String, 5);
|
||||
</pre>
|
||||
<p>Then if you wish to assign the string "hi" to the first element, simply
|
||||
execute <var>stringArray[0] = "hi"</var>.</p>
|
||||
<p>Creating arrays of primitive types is slightly different: you must use
|
||||
the TYPE field. For example, creating an array of seven ints can be done
|
||||
with the code</p>
|
||||
<pre class="code">
|
||||
var intArray = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, 7);
|
||||
</pre><br><br></dd>
|
||||
|
||||
<dt>When I try to execute a script I get the exception <code>Required security context missing</code>. What's going on?</dt>
|
||||
<dd>You've likely missed placing the
|
||||
<code class="filename">Security.properties</code> file in your class path at
|
||||
<code class="filename">org.mozilla.javascript.resources</code>.</dd>
|
||||
|
||||
</dl>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
100
mozilla/js/rhino/docs/footprint.html
Normal file
100
mozilla/js/rhino/docs/footprint.html
Normal file
@@ -0,0 +1,100 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.51 [en] (WinNT; U) [Netscape]">
|
||||
<title>Small Footprint</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<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.
|
||||
<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, nor do you use PolicySecurityController 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>
|
||||
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.
|
||||
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
90
mozilla/js/rhino/docs/help.html
Normal file
90
mozilla/js/rhino/docs/help.html
Normal file
@@ -0,0 +1,90 @@
|
||||
<!-- ***** 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">
|
||||
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
<meta http-equiv="Content-Script-Type" content="text/javascript">
|
||||
<title>Help with Rhino</title>
|
||||
<script type="text/javascript" src="owner.js"></script>
|
||||
<style type="text/css">
|
||||
h1 { text-align: center; }
|
||||
</style>
|
||||
|
||||
<link rel="up" href="./" title="Rhino project page">
|
||||
<link rel="section" href="#newsgroups" title="Newsgroup and Mail Gateway">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p class="crumbs"><em>You are here:</em> <a href="./">Rhino project page</a> > <strong>Help with Rhino</strong></p>
|
||||
|
||||
<h1>Help with Rhino</h1>
|
||||
|
||||
<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>
|
||||
|
||||
<h2><a name="newsgroups" id="newsgroups">Newsgroup and Mail Gateway</a></h2>
|
||||
<p>
|
||||
The <a href="news://news.mozilla.org/mozilla.dev.tech.js-engine">mozilla.dev.tech.js-engine</a>
|
||||
newsgroup answers questions about both Rhino and the C implementation of
|
||||
JavaScript. Click <a href="https://lists.mozilla.org/listinfo/dev-tech-js-engine">here</a> to subscribe/unsubscribe.
|
||||
</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>
|
||||
|
||||
<h2>Bug System</h2>
|
||||
<p>
|
||||
Use <a href="https://bugzilla.mozilla.org/enter_bug.cgi?product=Rhino">Bugzilla</a>
|
||||
to enter bugs against Rhino. Note that Rhino has its own product category.
|
||||
</p>
|
||||
|
||||
<h2>Module Owner</h2>
|
||||
<p>
|
||||
The module owner, <script type="text/javascript">document.write(owner());</script>, can
|
||||
be mailed for help as well, although he may copy his response to the newsgroup
|
||||
to help others.
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
45
mozilla/js/rhino/docs/history.html
Normal file
45
mozilla/js/rhino/docs/history.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<!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.72 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
<title>Rhino History</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center><b><font size=+3>Rhino History</font></b></center>
|
||||
|
||||
<p>Rhino gets its name from the animal on the cover of the <a href="http://www.ora.com/">O'Reilly</a>
|
||||
book about JavaScript.
|
||||
<p>The Rhino project was started at Netscape in Fall 1997. At the time,
|
||||
Netscape was planning to produce a version of Navigator written entirely
|
||||
in Java and so it needed an implementation of JavaScript written in Java.
|
||||
When Netscape stopped work on "Javagator", as it was called, somehow Rhino
|
||||
escaped the axe (rumor had it that the executives "forgot" it existed).
|
||||
Since then, a couple of major companies (including Sun) have licensed Rhino
|
||||
for use in their products and paid Netscape to do so, allowing us to continue
|
||||
work on it. Now Rhino is planned to be part of several server products
|
||||
from Netscape as well.
|
||||
<p>Originally, Rhino compiled all JavaScript code to Java bytecodes in
|
||||
generated classfiles. This produced the best performance (often beating
|
||||
the C implementation of JavaScript when run on a JIT), but suffered from
|
||||
two faults. First, compilation time was long since generating Java bytecodes
|
||||
and loading the generated classes was a heavyweight process. Also, the
|
||||
implementation effectively leaked memory since most JVMs don't really collect
|
||||
unused classes or the strings that are interned as a result of loading
|
||||
a class file.
|
||||
<p>So in Fall of 1998, Rhino added an interpretive mode. The classfile
|
||||
generation code was moved to an optional, dynamically-loaded package. Compilation
|
||||
is faster and when scripts are no longer in use they can be collected like
|
||||
any other Java object.
|
||||
<p>Rhino was released to mozilla.org in April of 1998. Originally Rhino
|
||||
classfile generation had been held back from release. However the licensees
|
||||
of Rhino have now agreed to release all of Rhino to open source, including
|
||||
class file generation. Since its release to open source, Rhino has found
|
||||
a variety of <a href="users.html">uses</a> and an increasing
|
||||
number of people have contributed to the code.
|
||||
<p>
|
||||
<hr WIDTH="100%"><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- ***** BEGIN LICENSE BLOCK *****
|
||||
- Version: MPL 1.1/GPL 2.0
|
||||
-
|
||||
@@ -33,45 +32,35 @@
|
||||
-
|
||||
- ***** END LICENSE BLOCK ***** -->
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html lang="en">
|
||||
<head>
|
||||
<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
|
||||
|
||||
<!--
|
||||
Build file for Rhino using Ant (see http://jakarta.apache.org/ant/index.html)
|
||||
Requires Ant version 1.2
|
||||
-->
|
||||
<project name="toolsrc" default="compile" basedir="..">
|
||||
|
||||
<target name="properties">
|
||||
<property file="build.properties"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="properties">
|
||||
<javac srcdir="toolsrc"
|
||||
destdir="${classes}"
|
||||
includes="org/**/*.java"
|
||||
deprecation="on"
|
||||
debug="${debug}"
|
||||
target="${target-jvm}"
|
||||
source="${source-level}"
|
||||
>
|
||||
</javac>
|
||||
<copy todir="${classes}">
|
||||
<fileset dir="toolsrc" includes="org/**/*.properties" />
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="copy-source" depends="properties">
|
||||
<mkdir dir="${dist.dir}/toolsrc"/>
|
||||
<copy todir="${dist.dir}/toolsrc">
|
||||
<fileset dir="toolsrc"
|
||||
includes="**/*.java,**/*.properties,**/*.xml" />
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="clean" depends="properties">
|
||||
<delete includeEmptyDirs="true">
|
||||
<fileset dir="${classes}"
|
||||
includes="org/mozilla/javascript/tools/**"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
</body>
|
||||
</html>
|
||||
100
mozilla/js/rhino/docs/javaone.html
Normal file
100
mozilla/js/rhino/docs/javaone.html
Normal file
@@ -0,0 +1,100 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.6 [en] (WinNT; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Followup to JavaOne</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Followup to JavaOne session on Rhino</h1></center>
|
||||
This page is intended to follow up on the <a href="http://www.javasoft.com/javaone/">JavaOne</a>
|
||||
session on <a href="http://industry.java.sun.com/javaone/99/event/0,1768,629,00.html">"Rhino:
|
||||
JavaScript for the Java Platform"</a>. I hope it will be useful whether
|
||||
or not you actually attended the talk.
|
||||
<br>
|
||||
<h2>
|
||||
Slides</h2>
|
||||
<a href="http://industry.java.sun.com/javaone/99/pdfs/e629.pdf">Slides</a>
|
||||
(PDF file, 1112246 bytes) can be downloaded from Sun's site.
|
||||
<br>
|
||||
<br>
|
||||
<h2>
|
||||
More on Q & A</h2>
|
||||
Following the talk there was an excellent question and answer session where
|
||||
many attendees asked good questions and offered useful suggestions. I'll
|
||||
follow up on some of those here. I'll start a thread on the newsgroup <a href="news://news.mozilla.org/netscape.public.mozilla.jseng">netscape.public.mozilla.jseng</a>
|
||||
so people can ask addition questions or comments there.
|
||||
<h3>
|
||||
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>
|
||||
class that allows embedders to choose which classes are exposed to scripts.
|
||||
<h3>
|
||||
Easier "importing" of Java classes</h3>
|
||||
Another attendee suggested that the current method of referring to Java
|
||||
classes (like <tt>java.lang.String</tt> or <tt>Packages.org.mozilla.javascript.Context</tt>)
|
||||
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>
|
||||
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.
|
||||
<p>There are a few drawbacks to this implemenation. First, there is a runtime
|
||||
cost associated with every lookup of a top-level variable. The problem
|
||||
is that it's not possible to use the Java runtime to determine the set
|
||||
of classes from a given package. Instead, importing the package "java.util"
|
||||
saves the package name in a special list and every access to the global
|
||||
scope that fails to find a matching variable causes the runtime to see
|
||||
if there is a class by that name in the "java.util" package. Even for lookups
|
||||
that succeed there is an additional method call.
|
||||
<p>Another drawback to this implementation is namespace pollution: now
|
||||
"importClass" and "importPackage" have special meaning. It's still possible
|
||||
to substitute your own variables for these functions, but it's still possible
|
||||
that program behavior could change.
|
||||
<p>So I'm interested in people's opinion: Is this benefit worth the costs?
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
116
mozilla/js/rhino/docs/jsc.html
Normal file
116
mozilla/js/rhino/docs/jsc.html
Normal file
@@ -0,0 +1,116 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">
|
||||
<title>JavaScript Compiler</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
JavaScript Compiler</h1></center>
|
||||
The JavaScript compiler translates JavaScript source into Java class files.
|
||||
The resulting Java class files can then be loaded and executed at another
|
||||
time, providing a convenient method for transfering JavaScript, and for
|
||||
avoiding translation cost.
|
||||
<p>Note that the top-level functions available to the shell (such as <tt>print</tt>)
|
||||
are <i>not</i> available to compiled scripts when they are run outside
|
||||
the shell.
|
||||
<br>
|
||||
<h2>
|
||||
Invoking the Compiler</h2>
|
||||
<tt>java org.mozilla.javascript.tools.jsc.Main</tt> [<i>options</i>] <i>file1</i><tt>.js</tt>
|
||||
[<i>file2</i><tt>.js</tt>...]
|
||||
<p>where <i>options</i> are:
|
||||
<p><tt>-extends <i>java-class-name</i></tt>
|
||||
<blockquote>Specifies that a java class extending the Java class <i>java-class-name</i>
|
||||
should be generated from the incoming JavaScript source file. Each global
|
||||
function in the source file is made a method of the generated class, overriding
|
||||
any methods in the base class by the same name.</blockquote>
|
||||
<tt>-implements <i>java-intf-name</i></tt>
|
||||
<blockquote>Specifies that a java class implementing the Java interface
|
||||
<i><tt>java-intf-name</tt></i>
|
||||
should be generated from the incoming JavaScript source file. Each global
|
||||
function in the source file is made a method of the generated class, implementing
|
||||
any methods in the interface by the same name.</blockquote>
|
||||
<tt>-debug</tt>
|
||||
<br><tt>-g</tt>
|
||||
<ul>Specifies that debug information should be generated. May not be combined
|
||||
with optimization at an <i>optLevel</i> greater than zero.</ul>
|
||||
<tt>-nosource</tt>
|
||||
<ul>Does not save the source in the class file. Functions and scripts compiled
|
||||
this way cannot be decompiled. This option can be used to avoid distributing
|
||||
source or simply to save space in the resulting class file.</ul>
|
||||
<tt>-o </tt><i>outputFile</i>
|
||||
<ul>Writes the class file to the given file (which should end in <tt>.class</tt>).
|
||||
The string <i>outputFile</i> must be a writable filename.</ul>
|
||||
<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
|
||||
-1 and 9. See <a href="opt.html">Optimization</a> for more details. If
|
||||
<i>optLevel</i>
|
||||
is greater than zero, <tt>-debug</tt> may not be specified.</ul>
|
||||
<tt>-package</tt> <i>packageName</i>
|
||||
<ul>Specifies the package to generate the class into. The string <i>packageName</i>
|
||||
must be composed of valid identifier characters optionally separated by
|
||||
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
|
||||
Versions</a> for more information on language versions.</ul>
|
||||
|
||||
<h2>
|
||||
Examples</h2>
|
||||
<tt>$ cat test.js</tt>
|
||||
<br><tt>java.lang.System.out.println("hi, mom!");</tt>
|
||||
<br><tt>$ java org.mozilla.javascript.tools.jsc.Main test.js</tt>
|
||||
<br><tt>$ ls *.class</tt>
|
||||
<br><tt>test.class</tt>
|
||||
<br><tt>$ java test</tt>
|
||||
<br><tt>hi, mom!</tt>
|
||||
<p><tt>$ java org.mozilla.javascript.tools.jsc.Main -extends java.applet.Applet
|
||||
\</tt>
|
||||
<br><tt> -implements java.lang.Runnable NervousText.js</tt>
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
BIN
mozilla/js/rhino/docs/jsdebug.jpg
Normal file
BIN
mozilla/js/rhino/docs/jsdebug.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
136
mozilla/js/rhino/docs/limits.html
Normal file
136
mozilla/js/rhino/docs/limits.html
Normal file
@@ -0,0 +1,136 @@
|
||||
<!-- ***** 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">
|
||||
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
|
||||
<title>JavaScript Requirements and Limitations</title>
|
||||
|
||||
<link rel="up" href="./" title="Rhino project page">
|
||||
<link rel="section" href="#requirements" title="Requirements">
|
||||
<link rel="section" href="#limitations" title="Limitations">
|
||||
<link rel="section" href="#platforms" title="Platforms and JITs">
|
||||
<link rel="section" href="#liveconnect" title="LiveConnect">
|
||||
<link rel="section" href="#jsobject" title="JSObject">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<p class="crumbs"><em>You are here:</em> <a href="./">Rhino project page</a> > <strong>JavaScript Requirements and Limitations</strong></p>
|
||||
|
||||
<h1 style="text-align: center;">Requirements and Limitations</h1>
|
||||
|
||||
<h2><a name="requirements" id="requirements">Requirements</a></h2>
|
||||
<p>Rhino requires version 1.1 or greater of Java.</p>
|
||||
<p>To use the JavaAdapter feature or an optimization level of 0 or greater,
|
||||
Rhino must be running under a security manager that allows the definition
|
||||
of class loaders.</p>
|
||||
|
||||
<h2><a name="limitations" id="limitations">Limitations</a></h2>
|
||||
|
||||
<h3><a name="platforms" id="platforms">Platforms and JITs</a></h3>
|
||||
<p>Many platforms and JREs have problems converting decimal numbers to and
|
||||
from strings. These errors are usually boundary case errors and will show
|
||||
up as test failures in section 7.7.3.</p>
|
||||
<p>Windows versions of the Symantec JIT prior to 3.00.029(i) will report
|
||||
internal errors for some generated class files.</p>
|
||||
<p>On the Symantec JIT and the AIX JVM, accessing a static field of a class
|
||||
that has not yet loaded may not give the correct value of the field. For
|
||||
example, accessing
|
||||
<code class="filename">java.io.File.separatorChar</code> before <code class="filename">java.io.File</code>
|
||||
has been loaded will return a value of 0. (This is a bug in the JIT;
|
||||
accessing the field should cause the class to be loaded.)</p>
|
||||
<p>The AIX Java version "JDK 1.1.6 IBM build a116-19980924 (JIT enabled:
|
||||
jitc)" core dumps running several classes generated by Rhino. It also has
|
||||
errors in java.lang.Math.pow that are reflected as failures in the
|
||||
JavaScript Math object's pow method.</p>
|
||||
<p>IBM Java for Linux version "JDK 1.1.8 IBM build l118-19991013 (JIT
|
||||
enabled: jitc)" has errors in java.lang.Math.pow that are reflected
|
||||
as test failures in the JavaScript Math object's pow method.</p>
|
||||
<p>Solaris JDK 1.1.6 has errors in java.lang.Math.atan2 that are reflected
|
||||
as test failures in the JavaScript Math object's atan2 method.</p>
|
||||
|
||||
<h3><a name="liveconnect" id="liveconnect">LiveConnect</a></h3>
|
||||
<p>If a JavaObject's field's name collides with that of a method, the value
|
||||
of that field is retrieved lazily, and can be counter-intuitively affected
|
||||
by later assignments:</p>
|
||||
|
||||
<pre class="code">
|
||||
javaObj.fieldAndMethod = 5;
|
||||
var field = javaObj.fieldAndMethod;
|
||||
javaObj.fieldAndMethod = 7;
|
||||
<span class="remark">// now, field == 7</span>
|
||||
</pre>
|
||||
|
||||
<p>You can work around this by forcing the field value to be converted to
|
||||
a JavaScript type when you take its value:</p>
|
||||
|
||||
<pre class="code">
|
||||
javaObj.fieldAndMethod = 5;
|
||||
var field = javaObj.fieldAndMethod + 0; <span class="remark">// force conversion now</span>
|
||||
javaObj.fieldAndMethod = 7;
|
||||
<span class="remark">// now, field == 5</span>
|
||||
</pre>
|
||||
|
||||
<h3><a name="jsobject" id="jsobject">JSObject</a></h3>
|
||||
<p>Rhino does <strong>NOT</strong> support the
|
||||
<code class="filename">netscape.javascript.JSObject</code> class.</p>
|
||||
|
||||
<h3>Date object</h3>
|
||||
<p>The JavaScript Date object depends on time facilities of the underlying
|
||||
Java runtime to determine daylight savings time dates. Earlier JRE versions
|
||||
may report a date for the daylight savings changeover that is a week off.
|
||||
JRE 1.1.6 reports the correct date.</p>
|
||||
<p>Under the 1.1.6 JRE, evaluating <code class="command">(new Date(1998, 9, 25, 2)).toString()</code>
|
||||
returns:</p>
|
||||
<pre class="code"> Sun Oct 25 02:00:00 GMT-0800 (PST) 1998
|
||||
</pre>
|
||||
<p>Earlier versions may return:</p>
|
||||
<pre class="code"> Sun Oct 25 02:00:00 GMT-0700 (PDT) 1998
|
||||
</pre>
|
||||
<p>(the JRE doesn't report the changeover until Nov. 1.)</p>
|
||||
<p>The Microsoft SDK 3.1 for Java also exhibits this problem.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
BIN
mozilla/js/rhino/docs/lookup.gif
Normal file
BIN
mozilla/js/rhino/docs/lookup.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
107
mozilla/js/rhino/docs/opt.html
Normal file
107
mozilla/js/rhino/docs/opt.html
Normal file
@@ -0,0 +1,107 @@
|
||||
<!-- ***** 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">
|
||||
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
|
||||
<title>Optimization</title>
|
||||
|
||||
<link rel="up" href="./" title="Rhino project page">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p class="crumbs"><em>You are here:</em> <a href="./">Rhino project page</a> > <strong>Optimization</strong></p>
|
||||
|
||||
<h1 style="text-align: center;">Optimization</h1>
|
||||
|
||||
<h2>Optimization settings</h2>
|
||||
|
||||
<p>The currently supported optimization settings are:</p>
|
||||
|
||||
<p><b>-1</b></p>
|
||||
|
||||
<p>Interpretive mode is always used. The compilation time is minimized at the
|
||||
expense of runtime performance. No class files are generated, which may improve
|
||||
memory usage depending on your system. Another benefit of the interpreted mode
|
||||
is that the interpreter performs tail-call elimination of recursive functions.
|
||||
Also, you must use this optimization level if your code uses Continuation
|
||||
objects.
|
||||
<p>
|
||||
<p>If the optimization package is not available, then optimization
|
||||
acts as if it is always -1.</p>
|
||||
|
||||
<p><b>0</b></p>
|
||||
|
||||
<p>No optimizations are performed. The bytecode compiler runs fastest
|
||||
in this mode, but the generated byte code is less efficient.</p>
|
||||
|
||||
<p><b>1-9</b></p>
|
||||
|
||||
<p>All optimizations are performed. Simple data & type
|
||||
flow analysis is performed to determine which JavaScript variables can
|
||||
be allocated to Java VM registers, and which variables are used only as
|
||||
Numbers. Local common sub-expressions are collapsed (currently this only
|
||||
happens for property lookup, but in the future more expressions may be
|
||||
optimized). All local variables and parameters are allocated to Java VM
|
||||
registers. Function call targets are speculatively pre-cached (based on
|
||||
the name used in the source) so that dispatching can be direct, pending
|
||||
runtime confirmation of the actual target. Arguments are passed as
|
||||
Object/Number pairs to reduce conversion overhead.</p>
|
||||
|
||||
<p>Note:</p>
|
||||
|
||||
<ol>
|
||||
<li>Some language features (indirect calls to eval, use
|
||||
of the arguments property of function objects) were previously not supported
|
||||
in higher optimization levels. These features have been removed from the
|
||||
language in ECMA, so higher optimization levels are now conformant.</li>
|
||||
|
||||
<li>Future versions may allocate more aggressive
|
||||
optimizations to higher optimization levels. For compatibility with future
|
||||
versions, use level 1. For maximal optimization, use level 9, but retest
|
||||
your application when upgrading to new versions.</li>
|
||||
</ol>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
197
mozilla/js/rhino/docs/overview.html
Normal file
197
mozilla/js/rhino/docs/overview.html
Normal file
@@ -0,0 +1,197 @@
|
||||
<!-- ***** 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">
|
||||
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<title>JavaScript Overview</title>
|
||||
|
||||
<link rel="up" href="./" title="Rhino project page">
|
||||
<link rel="section" href="#language" title="Language">
|
||||
<link rel="section" href="#deprec" title="Deprecated Language Features">
|
||||
<link rel="section" href="#versions" title="JavaScript Language Versions">
|
||||
<link rel="section" href="#security" title="Security">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<p class="crumbs"><em>You are here:</em> <a href="./">Rhino project page</a> > <strong>JavaScript Overview</strong></p>
|
||||
|
||||
<h1 style="text-align: center;">Rhino Overview</h1>
|
||||
|
||||
<h2>Overview of Rhino</h2>
|
||||
|
||||
<p>Most people who have used JavaScript before have done so by adding scripts
|
||||
to their HTML web pages. However, Rhino is an implementation of the core
|
||||
language only and doesn't contain objects or methods for manipulating HTML
|
||||
documents.</p>
|
||||
<p>Rhino contains</p>
|
||||
|
||||
<ul>
|
||||
<li>All the features of JavaScript 1.5</li>
|
||||
<li>Allows direct scripting of Java</li>
|
||||
<li>A JavaScript shell for executing JavaScript scripts</li>
|
||||
<li>A JavaScript compiler to transform JavaScript source files into Java class
|
||||
files</li>
|
||||
</ul>
|
||||
|
||||
<h2><a name="language" id="language">Language</a></h2>
|
||||
<p>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 class="ex-ref" href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">downloaded</a>
|
||||
or obtained by mail from</p>
|
||||
|
||||
<address>ECMA,<br>
|
||||
114 Rue du Rhône,<br>
|
||||
CH1204 Geneva,
|
||||
<br>Switzerland.</address>
|
||||
|
||||
<p>Rhino 1.6 also implements ECMA-357 <i>ECMAScript for XML (E4X)</i>.
|
||||
See the <a class="ex-ref" 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>
|
||||
|
||||
<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 <code class="filename">enum.js</code> example for more
|
||||
information.</p>
|
||||
<p>Numerous books and tutorials on JavaScript are available.</p>
|
||||
|
||||
<h3><a name="deprec" id="deprec">Deprecated Language Features</a></h3>
|
||||
<p>Several language features introduced in JavaScript 1.2 are now deprecated.
|
||||
These features allow "computational reflection": that is, the ability for
|
||||
a script to determine and influence aspects of the way it is evaluated.
|
||||
These features are generally not broadly useful, yet they impose significant
|
||||
constraints on implementations that hamper or prevent optimization. The
|
||||
deprecated features are the <tt>__proto__</tt> and <tt>__parent__</tt>
|
||||
properties, and the constructors <tt>With</tt>, <tt>Closure</tt>, and <tt>Call</tt>.
|
||||
Attempts to invoke these constructors with the language version 1.4 will
|
||||
result in an error. For other versions, a warning will be generated.</p>
|
||||
|
||||
<h3>Internationalization</h3>
|
||||
<p>The messages reported by the JavaScript engine are by default retrieved
|
||||
from the property file <code class="filename">org/mozilla/javascript/resources/Messages.properties</code>.
|
||||
If other properties files with extensions corresponding to the current
|
||||
locale exist, they will be used instead.</p>
|
||||
|
||||
<h3><a name="versions" id="versions">JavaScript Language Versions</a></h3>
|
||||
<p>Some behavior in the JavaScript engine is dependent on the
|
||||
language version. In browser embeddings, this language version is selected
|
||||
using the LANGUAGE attribute of the SCRIPT tag with values such as
|
||||
"JavaScript1.2". <p>Version 1.3 and greater are ECMA conformant.</p>
|
||||
<p><b>Operators <tt>==</tt> and <tt>!=</tt></b></p>
|
||||
<p>Version 1.2 only uses strict equality for the == and != operators. In
|
||||
version 1.3 and greater, == and != have the same meanings as ECMA. The
|
||||
operators === and !== use strict equality in all versions.</p>
|
||||
<p><b>ToBoolean</b></p>
|
||||
<p><tt>Boolean(new Boolean(false))</tt> is false for all versions before
|
||||
1.3. It is true (and thus ECMA conformant) for version 1.3 and greater.
|
||||
<p><b>Array.prototype.toString and Object.prototype.toString</b>
|
||||
<p>Version 1.2 only returns array or object literal notation ("[1,2,3]"
|
||||
or "{a:1, b:2}" for example). In version 1.3 and greater these functions
|
||||
are ECMA conformant.</p>
|
||||
<p><b>Array constructor</b></p>
|
||||
<p><code>Array(i)</code> for a number argument <var>i</var> constructs an
|
||||
array with a single element equal to <var>i</var> for version 1.2 only.
|
||||
Otherwise the ECMA conformant version is used (an array is constructed
|
||||
with no elements but with length property equal to <var>i</var>).</p>
|
||||
<p><b>String.prototype.substring</b></p>
|
||||
<p>For version 1.2 only, the two arguments are not swapped if the first
|
||||
argument is less than the second one. All other versions are ECMA compliant.
|
||||
<p><b>String.prototype.split</b></p>
|
||||
<p>For version 1.2 only, split performs the Perl4 special case when given
|
||||
a single space character as an argument (skips leading whitespace, and
|
||||
splits on whitespace). All other versions split on the space character
|
||||
proper as specified by ECMA.</p>
|
||||
|
||||
<h2><a name="security" id="security">Security</a></h2>
|
||||
<p>The security features in Rhino provide the ability to track the origin
|
||||
of a piece of code (and any pieces of code that it may in turn generate).
|
||||
These features allow for the implementation of a traditional URL-based
|
||||
security policy for JavaScript as in Netscape Navigator. Embeddings that
|
||||
trust the JavaScript code they execute may ignore the security features.</p>
|
||||
|
||||
<p>Embeddings that run untrusted JavaScript code must do two things to
|
||||
enable the security features. First, every <code>Context</code> that is
|
||||
created must be supplied an instance of an object that implements the
|
||||
<tt>SecuritySupport</tt> interface. This will provide Rhino the support
|
||||
functionality it needs to perform security-related tasks.</p>
|
||||
|
||||
<p>Second, the value of the property
|
||||
<code class="filename">security.requireSecurityDomain</code>
|
||||
should be changed to <var>true</var> in the resource bundle <code class="filename">org.mozilla.javascript.resources.Security</code>.
|
||||
The value of this property can be determined at runtime by calling the
|
||||
<code>isSecurityDomainRequired</code>
|
||||
method of <code>Context</code>. Setting this property to true requires that
|
||||
any calls that compile or evaluate JavaScript must supply a security domain
|
||||
object of any object type that will be used to identify JavaScript code.
|
||||
In a typical client embedding, this object might be a string with the URL
|
||||
of the server that supplied the script, or an object that contains a
|
||||
representation of the signers of a piece of code for certificate-based
|
||||
security policies.</p>
|
||||
|
||||
<p>When JavaScript code attempts a restricted action, the security domain
|
||||
can be retrieved in the following manner. The class context should be
|
||||
obtained from the security manager (see <code class="command">java.lang.SecurityManager.getClassContext()</code>).
|
||||
Then, the class of the code that called to request the restricted action
|
||||
can be obtained by looking an appropriate index into the class context
|
||||
array. If the caller is JavaScript the class obtained may be one of two
|
||||
types. First, it may be the class of the interpreter if interpretive mode
|
||||
is in effect. Second, it may be a generated class if classfile generation
|
||||
is supported. An embedding can distinguish the two cases by calling
|
||||
<code class="command">isInterpreterClass()</code>
|
||||
in the <code class="filename">Context</code> class. If it is the
|
||||
interpreter class, call the getInterpreterSecurityDomain() method of
|
||||
Context to obtain the security domain of the currently executing
|
||||
interpreted script or function. Otherwise, it must be a generated class,
|
||||
and an embedding can call <code class="command">getSecurityDomain()</code>
|
||||
in the class implementing <code>SecuritySupport</code>. When the class was
|
||||
defined and loaded, the appropriate security domain was associated with
|
||||
it, and can be retrieved by calling this method. Once the security domain
|
||||
has been determined, an embedding can perform whatever checks are
|
||||
appropriate to determine whether access should be allowed.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,6 +1,4 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
@@ -13,8 +11,7 @@
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
* The Original Code is Rhino code, released May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
@@ -22,7 +19,6 @@
|
||||
* 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
|
||||
@@ -36,15 +32,18 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
package org.mozilla.javascript.tools.shell;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
|
||||
/**
|
||||
* Defines action to perform in response to quit command.
|
||||
*/
|
||||
public interface QuitAction
|
||||
function owner()
|
||||
{
|
||||
public void quit(Context cx, int exitCode);
|
||||
return email("Norris Boyd", "nboyd", "atg.com");
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
154
mozilla/js/rhino/docs/perf.html
Normal file
154
mozilla/js/rhino/docs/perf.html
Normal file
@@ -0,0 +1,154 @@
|
||||
<!-- ***** 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">
|
||||
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
|
||||
<title>Performance Hints</title>
|
||||
|
||||
<link rel="up" href="./" title="Rhino project page">
|
||||
<link rel="section" href="#varstatements" title="Var statements">
|
||||
<link rel="section" href="#arrays" title="Arrays">
|
||||
<link rel="section" href="#eval" title="eval">
|
||||
<link rel="section" href="#with" title="with">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<p class="crumbs"><em>You are here:</em> <a href="./">Rhino project page</a> > <strong>Performance Hints</strong></p>
|
||||
|
||||
<h1 style="text-align: center;">Performance Hints</h1>
|
||||
|
||||
<h3><a name="varstatements" id="varstatements"><code>var</code> Statements</a></h3>
|
||||
|
||||
<p>Use <code>var</code> statements when possible. Not only is it good
|
||||
programming practice, it can speed up your code by allowing the compiler
|
||||
to generate special code to access the variables. For example, you could
|
||||
rewrite</p>
|
||||
|
||||
<pre class="code">
|
||||
function sum(a) {
|
||||
result = 0;
|
||||
for (i=0; i < a.length; i++)
|
||||
result += a[i];
|
||||
return result;
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>as</p>
|
||||
|
||||
<pre class="code">
|
||||
function sum(a) {
|
||||
var result = 0;
|
||||
for (var i=0; i < a.length; i++)
|
||||
result += a[i];
|
||||
return result;
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>This is not equivalent code because the second version does
|
||||
not modify global variables <code>result</code> and <code>i</code>.
|
||||
However, if you don't intend for any other function to access these
|
||||
variables, then storing them globally is probably wrong anyway
|
||||
(what if you called another function that had a loop like the one
|
||||
in <code>sum</code>!).</p>
|
||||
|
||||
<h3><a name="arrays" id="arrays">Arrays</a></h3>
|
||||
|
||||
<p>Use the forms of the Array constructor that specify a size or
|
||||
take a list of initial elements. For example, the code</p>
|
||||
|
||||
<pre class="code">
|
||||
var a = new Array();
|
||||
for (var i=0; i < n; i++)
|
||||
a[i] = i;
|
||||
</pre>
|
||||
|
||||
<p>could be sped up by changing the constructor call to
|
||||
<code>new Array(n)</code>. A constructor call like that indicates
|
||||
to the runtime that a Java array should be used for the first
|
||||
<var>n</var> entries of the array. Similarly,<br><br>
|
||||
<code>new Array("a", "b", "c")</code><br>
|
||||
or<br>
|
||||
<code>["a", "b", "c"]</code><br><br>
|
||||
will cause a 3-element Java array to be allocated to hold the
|
||||
contents of the JavaScript array.</p>
|
||||
|
||||
<h3><a name="eval" id="eval"><code>eval</code> and <code>new Function</code></a></h3>
|
||||
|
||||
<p>Avoid calling <code>eval</code> when possible. Calls to
|
||||
<code>eval</code> are slow because the script being executed must
|
||||
be compiled. Constructing a new function object can be slow for
|
||||
the same reason, while function expressions are more efficient
|
||||
because the function can be compiled. For example, the code</p>
|
||||
|
||||
<pre class="code">
|
||||
function MyObject(a) {
|
||||
this.s = a;
|
||||
this.toString = new Function("return this.s");
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>could be written more efficiently as</p>
|
||||
|
||||
<pre class="code">
|
||||
function MyObject(a) {
|
||||
this.s = a;
|
||||
this.toString = function () { return this.s }
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>Beginning with Rhino 1.4 Release 2, code passed to eval and
|
||||
new Function will be interpreted rather than compiled to class
|
||||
files.</p>
|
||||
|
||||
<h3><a name="with" id="with"><code>with</code></a></h3>
|
||||
|
||||
<p>Using the <code>with</code> statement prevents the compiler
|
||||
from generating code for fast access to local variables. You're
|
||||
probably better off explicitly accessing any properties of the
|
||||
object.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
196
mozilla/js/rhino/docs/rhino15R1.html
Normal file
196
mozilla/js/rhino/docs/rhino15R1.html
Normal file
@@ -0,0 +1,196 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>What's New in Rhino 1.5</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
What's New in Rhino 1.5 Release 1</h1></center>
|
||||
|
||||
<h2>
|
||||
ECMA 262 Edition 3 Conformance</h2>
|
||||
Rhino 1.5 implements JavaScript 1.5, which conforms to ECMA 262 Edition
|
||||
3 (sometimes referred to as "ECMAScript"). Edition 3 standardized several
|
||||
features of JavaScript that were present in JavaScript 1.4, including:
|
||||
<ul>
|
||||
<li>
|
||||
regular expressions</li>
|
||||
|
||||
<li>
|
||||
<tt>switch</tt> statements</li>
|
||||
|
||||
<li>
|
||||
<tt>do</tt>...<tt>while</tt> loops</li>
|
||||
|
||||
<li>
|
||||
statement labels and labelled <tt>break</tt> and <tt>continue</tt></li>
|
||||
|
||||
<li>
|
||||
object literals</li>
|
||||
|
||||
<li>
|
||||
nested functions</li>
|
||||
|
||||
<li>
|
||||
exception handling</li>
|
||||
|
||||
<li>
|
||||
the <tt>instanceof</tt> operator</li>
|
||||
|
||||
<li>
|
||||
the <tt>in</tt> operator</li>
|
||||
</ul>
|
||||
In addition, new features were added to Edition 3 and JavaScript 1.5, including:
|
||||
<ul>
|
||||
<li>
|
||||
Perl 5 regular expressions, including operators like greedy quantifiers</li>
|
||||
|
||||
<li>
|
||||
errors as exceptions</li>
|
||||
|
||||
<li>
|
||||
number formatting (<tt>Number.prototype.toFixed</tt>, <tt>Number.prototype.toExponential</tt>,
|
||||
and <tt>Number.prototype.toGeneral</tt>)</li>
|
||||
</ul>
|
||||
|
||||
<h2>
|
||||
Changes since Rhino 1.4 Release 3</h2>
|
||||
Other significant changes to Rhino since the initial release to open source
|
||||
(1.4 Release 3) are listed below. Bug fixes won't be mentioned here, just
|
||||
API changes or significant functionality changes.
|
||||
<h3>
|
||||
Compilation mode</h3>
|
||||
Rhino has two modes of execution available. Interpretive mode has an interpreter
|
||||
loop implemented in Java. Compilation mode compiles JavaScript code to
|
||||
Java bytecodes in class files. This compilation can be done as part of
|
||||
script evaluation using the same APIs already available for the interpreter,
|
||||
or in a separate compile-time step. The code for the interpreter is located
|
||||
in the <tt>org.mozilla.javascript.optimizer</tt> package.
|
||||
<br>
|
||||
<h3>
|
||||
JavaScript Compiler</h3>
|
||||
The distribution now contains an extra class that can be invoked from the
|
||||
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>.
|
||||
<br>
|
||||
<h3>
|
||||
LiveConnect 3</h3>
|
||||
Rhino now supports the LiveConnect 3 specification, or LC3. The most notable
|
||||
change is support for overloaded method resolution. See <a href="http://www.mozilla.org/js/liveconnect/lc3_proposal.html">LiveConnect
|
||||
Release 3 Goals/Features</a>.
|
||||
<br>
|
||||
<h3>
|
||||
JavaBeans properties reflected as Java properties</h3>
|
||||
Java classes with getFoo/setFoo methods will have a "foo" property in the
|
||||
JavaScript reflection. Boolean methods are also reflected.
|
||||
<br>
|
||||
<h3>
|
||||
Dynamic scope support</h3>
|
||||
Rhino 1.5 implements support for dynamic scopes, which are particularly
|
||||
useful for multithreaded environments like server embeddings.
|
||||
<br>
|
||||
<h3>
|
||||
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>
|
||||
for details.
|
||||
<br>
|
||||
<h3>
|
||||
Support for the Java 2 <tt>-jar</tt> option</h3>
|
||||
It's now possible to start the shell using the new <tt>-jar</tt> option
|
||||
in Java 2.
|
||||
<br>
|
||||
<h3>
|
||||
Shell changes</h3>
|
||||
Two changes here: addition of the "environment" and "history" top-level
|
||||
variables.
|
||||
<br>
|
||||
<h3>
|
||||
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>
|
||||
interface that allows embedders to choose which classes are exposed to
|
||||
scripts.
|
||||
<br>
|
||||
<h3>
|
||||
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>
|
||||
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
|
||||
action.
|
||||
<p>I've checked in changes that fix this problem. If a SecuritySupport
|
||||
class is specified when a Context is created, uses of JavaAdapter will
|
||||
will delegate class creation to the SecuritySupport class.
|
||||
<br>
|
||||
<h3>
|
||||
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>
|
||||
for more information on its operation.
|
||||
<br>
|
||||
<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>
|
||||
for more information on its operation.
|
||||
<br>
|
||||
<h3>
|
||||
Listeners for Context</h3>
|
||||
Context now supports property change listeners for a couple of its properties.
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><br>
|
||||
<a href="index.html">back to top</a></h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
118
mozilla/js/rhino/docs/rhino15R2.html
Normal file
118
mozilla/js/rhino/docs/rhino15R2.html
Normal file
@@ -0,0 +1,118 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Rhino 1.5 Release 2</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
What's New in Rhino 1.5 Release 2</h1></center>
|
||||
This is a log of significant changes since the release of Rhino 1.5 Release
|
||||
1.
|
||||
<br>
|
||||
<h2>
|
||||
Graphical debugger</h2>
|
||||
Thanks to a contribution by Christopher Oliver, Rhino now has a graphical
|
||||
debugger. See <a href="debugger.html">Rhino Debugger</a> for more details.
|
||||
<br>
|
||||
<h2>
|
||||
Footprint reductions</h2>
|
||||
Igor Bukanov has provided a wealth of changes to reduce the number and
|
||||
size of objects required by Rhino. In particular, he introduced a new way
|
||||
to represent the built-in objects like Date and RegExp that reduces the
|
||||
amount of memory required and speeds up <tt>Context.initStandardObjects</tt>.
|
||||
<br>
|
||||
<h2>
|
||||
Interpreted mode performance improvements</h2>
|
||||
Igor Bukanov also made a number of improvements to interpreter mode performance.
|
||||
<br>
|
||||
<h2>
|
||||
JS/CORBA Adapter</h2>
|
||||
Matthias Radestock wrote a module that allows JavaScript code to interact
|
||||
with CORBA. See <a href="http://sourceforge.net/projects/jscorba">http://sourceforge.net/projects/jscorba</a>
|
||||
for more details.
|
||||
<br>
|
||||
<h2>
|
||||
Directory restructuring and Ant buildfile</h2>
|
||||
I've restructured the the Rhino directory and written an <a href="http://jakarta.apache.org/ant/index.html">Ant</a>
|
||||
buildfile. This should make building easier and more consistent with other
|
||||
open source Java projects.
|
||||
<br>
|
||||
<h2>
|
||||
FlattenedObject deprecated</h2>
|
||||
I wrote FlattenedObject to provide a means for dealing with JavaScript
|
||||
<br>objects in prototype chains. Where Scriptable defines the primitive
|
||||
<br>operations, FlattenedObject defines the aggregate operations of
|
||||
<br>manipulating properties that may be defined in an object or in an object
|
||||
<br>reachable by a succession of getPrototype calls.
|
||||
<p>However, I now believe that I designed FlattenedObject poorly. Perhaps
|
||||
<br>it should have been a clue that I was never satisfied with the name:
|
||||
if
|
||||
<br>it's hard to express the name of the object it may mean the function
|
||||
the
|
||||
<br>object is supposed to fulfill is not well defined either. The problem
|
||||
is
|
||||
<br>that it is inefficient since it requires an extra object creation,
|
||||
and
|
||||
<br>balky because of that extra level of wrapping.
|
||||
<p>So I've checked in changes that deprecate FlattenedObject. I've
|
||||
<br>introduced new static methods in ScriptableObject (thanks to
|
||||
<br>beard@netscape.com for the idea) that replace the functionality. These
|
||||
<br>methods perform the get, put, and delete operations on a Scriptable
|
||||
<br>object passed in without the overhead of creating a new object.
|
||||
<h2>
|
||||
WrapHandler interface</h2>
|
||||
Embeddings that wish to provide their own custom wrappings for Java objects
|
||||
may implement this interface and
|
||||
<br>call Context.setWrapHandler. See WrapHandler javadoc.
|
||||
<br>
|
||||
<h2>
|
||||
ClassOutput interface</h2>
|
||||
An interface embedders can implement in order to control the placement
|
||||
of generated class bytecodes. See the javadoc.
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><br>
|
||||
<a href="index.html">back to top</a></h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
97
mozilla/js/rhino/docs/rhino15R3.html
Normal file
97
mozilla/js/rhino/docs/rhino15R3.html
Normal file
@@ -0,0 +1,97 @@
|
||||
<!-- ***** 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="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">
|
||||
|
||||
<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
|
||||
2.
|
||||
<p> </p>
|
||||
<h3> </h3>
|
||||
<h3>Serialization</h3>
|
||||
See the <a href="serialization.html">serialization documentation</a>
|
||||
.<br>
|
||||
<br>
|
||||
<h3>Class writer API changes</h3>
|
||||
Courtesy of Kemal Bayram.<br>
|
||||
<br>
|
||||
"The biggest change I've made is the replacement of ClassOutput with<br>
|
||||
ClassRepository that has the single method:<br>
|
||||
<br>
|
||||
public boolean storeClass(String className, byte[] classBytes,<br>
|
||||
|
||||
boolean isTopLevel) throws IOException;<br>
|
||||
<br>
|
||||
This interface allows any arbitary storage method, such as a<br>
|
||||
Hashtable/Map. In addition it also allows you to specify whether a<br>
|
||||
class should be loaded, via returning true or false. You can still
|
||||
use<br>
|
||||
ClassOutput as I've coded an internal wrapper.<br>
|
||||
<br>
|
||||
With this interface it has also been possible to strip out the file<br>
|
||||
saving code from Codegen and OptClassNameHelper. The file<br>
|
||||
saving code is now an inner class FileClassRepository in Context. As<br>
|
||||
a consequence of this I've stripped out some methods from ClassNameHelper.<br>
|
||||
The resulting code is much more cleaner then before hand and everything<br>
|
||||
still works as per usual.<br>
|
||||
<br>
|
||||
Other small additions are:<br>
|
||||
o Annonymous functions are now named class$1 instead of class1<br>
|
||||
o get/setClassName added to ClassNameHelper exposed in Context.
|
||||
"<br>
|
||||
<br>
|
||||
<h3>Bunches of bug fixes and optimizations from Igor Bukanov and others</h3>
|
||||
See the CVS logs<br>
|
||||
<h3>
|
||||
<hr width="100%"><br>
|
||||
<a href="index.html">back to top</a>
|
||||
</h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
235
mozilla/js/rhino/docs/rhino15R4-debugger.html
Normal file
235
mozilla/js/rhino/docs/rhino15R4-debugger.html
Normal file
@@ -0,0 +1,235 @@
|
||||
<!-- ***** 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>
|
||||
251
mozilla/js/rhino/docs/rhino15R4.html
Normal file
251
mozilla/js/rhino/docs/rhino15R4.html
Normal file
@@ -0,0 +1,251 @@
|
||||
<!-- ***** 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> -
|
||||
--> 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>
|
||||
75
mozilla/js/rhino/docs/rhino15R41.html
Normal file
75
mozilla/js/rhino/docs/rhino15R41.html
Normal file
@@ -0,0 +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 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>
|
||||
197
mozilla/js/rhino/docs/rhino15R5.html
Normal file
197
mozilla/js/rhino/docs/rhino15R5.html
Normal file
@@ -0,0 +1,197 @@
|
||||
<!-- ***** 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))) == uneval(x)</tt> and in many cases more useful notion <tt>eval(uneval(x)) == 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> var x = { a: 1, b: 2, c: [1,2,3,4,5], f: function test() { return 1; }, o: { property1: "Test", proeprty2: new Date()}}
|
||||
js> 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> 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> 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&target_milestone=1.5R5&bug_status=RESOLVED&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>
|
||||
187
mozilla/js/rhino/docs/rhino16R1.html
Normal file
187
mozilla/js/rhino/docs/rhino16R1.html
Normal file
@@ -0,0 +1,187 @@
|
||||
<!-- ***** 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>
|
||||
442
mozilla/js/rhino/docs/rhino16R2.html
Normal file
442
mozilla/js/rhino/docs/rhino16R2.html
Normal file
@@ -0,0 +1,442 @@
|
||||
<!-- ***** 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&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=2004-11-29&chfieldto=2005-08-21&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>
|
||||
|
||||
<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" => 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> 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>
|
||||
103
mozilla/js/rhino/docs/rhino16R3.html
Executable file
103
mozilla/js/rhino/docs/rhino16R3.html
Executable file
@@ -0,0 +1,103 @@
|
||||
<!-- ***** 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>
|
||||
BIN
mozilla/js/rhino/docs/rhino50.jpg
Normal file
BIN
mozilla/js/rhino/docs/rhino50.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
172
mozilla/js/rhino/docs/runtime.html
Normal file
172
mozilla/js/rhino/docs/runtime.html
Normal file
@@ -0,0 +1,172 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]">
|
||||
<title>JavaScript Runtime</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
The JavaScript Runtime</h1></center>
|
||||
|
||||
<h3>
|
||||
Interpretation</h3>
|
||||
Beginning with Rhino 1.4 Release 2, an interpretive mode is supported.
|
||||
When scripts are compiled in interpretive mode, an internal representation
|
||||
of the compiled form is created and stored rather than generating a Java
|
||||
class. Execution proceeds by evaluating this compiled form using support
|
||||
routines in Rhino.
|
||||
<h3>
|
||||
Compilation to Java Bytecodes</h3>
|
||||
For improved performance, Rhino may compile JavaScript scripts to Java
|
||||
bytecodes. The generated bytecodes in turn depend upon runtime support
|
||||
routines. Each JavaScript script or function is compiled to a separate
|
||||
class.
|
||||
<p>Compilation of JavaScript source to class files is supported. It is
|
||||
possible to specify the class files as well as the packages to generate
|
||||
into.
|
||||
<h3>
|
||||
Types and Values</h3>
|
||||
There are six fundamental types in JavaScript. These types are implemented
|
||||
with the following Java types and values:
|
||||
<br>
|
||||
<br>
|
||||
<center><table BORDER COLS=2 WIDTH="75%" >
|
||||
<tr>
|
||||
<td><i>JavaScript fundamental type</i></td>
|
||||
|
||||
<td><i>Java type</i></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Undefined</td>
|
||||
|
||||
<td>A singleton object defined by <tt>Context.getUndefinedType()</tt></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Null</td>
|
||||
|
||||
<td><tt>null</tt></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Boolean</td>
|
||||
|
||||
<td><tt>java.lang.Boolean</tt></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number</td>
|
||||
|
||||
<td><tt>java.lang.Number</tt>, that is, any of <tt>java.lang.Byte</tt>,<tt>
|
||||
java.lang.Short</tt>,<tt> java.lang.Integer</tt>,<tt> java.lang.Float</tt>,
|
||||
or <tt>java.lang.Double. Not java.lang.Long, since a double representation
|
||||
of a long may lose precision.</tt></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>String</td>
|
||||
|
||||
<td><tt>java.lang.String</tt></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Object</td>
|
||||
|
||||
<td><tt>org.mozilla.javascript.Scriptable</tt></td>
|
||||
</tr>
|
||||
</table></center>
|
||||
|
||||
<p>In addition, ECMA refers to objects that implement [[Call]] as functions.
|
||||
These object types are represented by implementing the Function interface.
|
||||
<p>Since JavaScript is a dynamically typed language, the static Java type
|
||||
of a JavaScript value is <tt>java.lang.Object</tt>.
|
||||
<p>The behavior of the JavaScript engine is undefined if a value of any
|
||||
type other than the ones described above is introduced into JavaScript.
|
||||
(This caveat does not apply to scripts that use LiveConnect; the Java values
|
||||
are wrapped and unwrapped as appropriate to conform to the above type constraints.)
|
||||
<br>
|
||||
<h3>
|
||||
Property Access</h3>
|
||||
Properties in JavaScript objects may be accessed using either string or
|
||||
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>
|
||||
(<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
|
||||
invoke the appropriate overloaded form. For example, evaluating the expression
|
||||
<tt>obj["3"]</tt>
|
||||
will invoke the get(int, Scriptable) method even though the property name
|
||||
was presented in the script as a string. Similarly, values of numbers that
|
||||
do not fix in integers (like 1.1 and 0x100000000) must be converted to
|
||||
strings.
|
||||
<br>
|
||||
<h3>
|
||||
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>.
|
||||
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>
|
||||
and
|
||||
<a href="apidocs/org/mozilla/javascript/FunctionObject.html">FunctionObject</a>,
|
||||
such as <tt>defineProperty</tt> and <tt>defineFunctionProperties</tt>.
|
||||
<br>
|
||||
<br>
|
||||
<h3>
|
||||
Contexts and Threads</h3>
|
||||
Every thread that executes JavaScript must have an associated Context.
|
||||
Multiple threads (with multiple associated Contexts) may act upon the same
|
||||
set of objects. Any host objects that are defined are responsible for any
|
||||
sychronization required to run safely from multiple threads.
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
BIN
mozilla/js/rhino/docs/scopes.gif
Normal file
BIN
mozilla/js/rhino/docs/scopes.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
227
mozilla/js/rhino/docs/scopes.html
Normal file
227
mozilla/js/rhino/docs/scopes.html
Normal file
@@ -0,0 +1,227 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.72 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Scopes and Contexts</title>
|
||||
</head>
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<script src="owner.js"></script>
|
||||
<center>
|
||||
<h1> Scopes and Contexts</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>Before using Rhino in a concurrent environment, it is important to understand
|
||||
the distinction between Contexts and scopes. Both are required to execute
|
||||
scripts, but they play different roles. Simple embeddings of Rhino probably
|
||||
won't need any of the information here, but more complicated embeddings can
|
||||
gain performance and flexibility from the techniques described below. <br>
|
||||
</p>
|
||||
<h2> Contexts</h2>
|
||||
The Rhino Context object is used to store thread-specific information about
|
||||
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>
|
||||
Once you are done with execution, simply exit the Context:
|
||||
<pre>
|
||||
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
|
||||
the thread.
|
||||
<p>Remember to put the <tt>exit()</tt> call in a <tt>finally</tt> block if
|
||||
you're executing code that could throw an exception. <br>
|
||||
</p>
|
||||
<h2> Scopes</h2>
|
||||
A scope is a set of JavaScript objects. Execution of scripts requires a scope
|
||||
for top-level script variable storage as well as a place to find standard
|
||||
objects like <tt>Function</tt> and <tt>Object</tt>.
|
||||
<p>It's important to understand that a scope is independent of the Context
|
||||
that created it. You can create a scope using one Context and then evaluate
|
||||
a script using that scope and another Context (either by exiting the current
|
||||
context and entering another, or by executing on a different thread). You
|
||||
can even execute scripts on multiple threads simultaneously in the same scope.
|
||||
Rhino guarantees that accesses to properties of JavaScript objects are atomic
|
||||
across threads, but doesn't make any more guarantees for scripts executing
|
||||
in the same scope at the same time. If two scripts use the same scope simultaneously,
|
||||
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>
|
||||
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
|
||||
are ways to share a scope created this way among multiple scopes and threads.
|
||||
<br>
|
||||
|
||||
<h2> Name Lookup</h2>
|
||||
So how are scopes used to look up names? In general, variables are looked
|
||||
up by starting at the current variable object (which is different depending
|
||||
on what code is being executed in the program), traversing its prototype chain,
|
||||
and then traversing the parent chain. In the diagram below, the order in
|
||||
which the six objects are traversed is indicated.
|
||||
<center>
|
||||
<p><img src="lookup.gif" height="194" width="500">
|
||||
<br>
|
||||
<i><font size="-1">Order of lookups in a two-deep scope chain with prototypes.</font></i></p>
|
||||
</center>
|
||||
|
||||
<p>For a more concrete example, let's consider the following script: </p>
|
||||
<blockquote><tt>var g = 7;</tt> <br>
|
||||
<tt>function f(a) {</tt> <br>
|
||||
<tt> var v = 8;</tt> <br>
|
||||
<tt> x = v + a;</tt> <br>
|
||||
<tt>}</tt> <br>
|
||||
<tt>f(6);</tt></blockquote>
|
||||
We have a top-level variable <tt>g</tt>, and the call to <tt>f</tt> will
|
||||
create a new top-level variable <tt>x</tt>. All top-level variables are properties
|
||||
of the scope object. When we start executing <tt>f</tt>, the scope chain
|
||||
will start with the function's activation object and will end with the top-level
|
||||
scope (see diagram below). The activation object has two properties, 'a'
|
||||
for the argument, and 'v' for the variable. The top-level scope has properties
|
||||
for the variable <tt>g</tt> and the function <tt>f</tt>.
|
||||
<center>
|
||||
<p><img src="scopes.gif" height="496" width="820">
|
||||
<br>
|
||||
<i><font size="-1">An example scope chain for a simple script.</font></i></p>
|
||||
</center>
|
||||
|
||||
<p>When the statement <tt>x = v + a;</tt> is executed, the scope chain is
|
||||
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.
|
||||
|
||||
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
|
||||
until either the object is found or the end of the prototype chain is reached.
|
||||
<p>So to share information across multiple scopes, we first create the object
|
||||
we wish to share. Typically this object will have been created with <tt>initStandardObjects</tt>
|
||||
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
|
||||
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.
|
||||
Let's call this scope the <i>instance scope</i>. Any top-level functions or
|
||||
variables defined in the script will end up as properties of the instance
|
||||
scope. Uses of standard objects like <tt>Function</tt>, <tt>String</tt>, or
|
||||
<tt>RegExp</tt> will find the definitions in the shared scope. Multiple
|
||||
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>
|
||||
</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
|
||||
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">
|
||||
DynamicScopes example</a>
|
||||
illustrates all the points discussed above. <br>
|
||||
<br>
|
||||
</p>
|
||||
<h2> More on Scopes</h2>
|
||||
The key things to determine in setting up scopes for your application are
|
||||
<br>
|
||||
(1) What scope should global variables be created in when your script executes
|
||||
an assignment to an undefined variable, and <br>
|
||||
(2) What variables should your script have access to when it references a
|
||||
variable?
|
||||
<p>The answer to (1) determines which scope should be the ultimate parent
|
||||
scope: Rhino follows the parent chain up to the top and places the variable
|
||||
there. After you've constructed your parent scope chain, the answer to question
|
||||
(2) may indicate that there are additional scopes that need to be searched
|
||||
that are not in your parent scope chain. You can add these as prototypes
|
||||
of scopes in your parent scope chain. When Rhino looks up a variable, it
|
||||
starts in the current scope, walks the prototype chain, then goes to the
|
||||
parent scope and its prototype chain, until there are no more parent scopes
|
||||
left. <br>
|
||||
</p>
|
||||
<h3>
|
||||
<hr width="100%"><br>
|
||||
<a href="index.html">back to top</a>
|
||||
</h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
BIN
mozilla/js/rhino/docs/scriptjava-frame.jpg
Normal file
BIN
mozilla/js/rhino/docs/scriptjava-frame.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 53 B |
305
mozilla/js/rhino/docs/scriptjava.html
Normal file
305
mozilla/js/rhino/docs/scriptjava.html
Normal file
@@ -0,0 +1,305 @@
|
||||
<!-- ***** 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">
|
||||
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<meta http-equiv="Content-Style-Type" content="text/css">
|
||||
<meta http-equiv="Content-Script-Type" content="text/javascript">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Scripting Java</title>
|
||||
|
||||
<link rel="up" href="./" title="Rhino project page">
|
||||
<link rel="section" href="#rhinoshell" title="Rhino Shell">
|
||||
<link rel="section" href="#liveconnect" title="LiveConnect">
|
||||
<link rel="section" href="#accessing" title="Accessing JavaBean">
|
||||
<link rel="section" href="#importingclasses" title="Importing classes & packages">
|
||||
<link rel="section" href="#extending" title="Extending Java Classes">
|
||||
<link rel="section" href="#javaadapter" title="JavaAdapter constructor">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p class="crumbs"><em>You are here:</em> <a href="./">Rhino project page</a> > <strong>Scripting Java</strong></p>
|
||||
|
||||
<h1 style="text-align: center;">Scripting Java</h1>
|
||||
<address class="author">Norris Boyd</address>
|
||||
|
||||
<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
|
||||
make calls into Java.</p>
|
||||
|
||||
<h2><a name="rhinoshell" id="rhinoshell">Rhino Shell</a></h2>
|
||||
<p>The Rhino shell allows you to run scripts from files or interactively at
|
||||
a command line.</p>
|
||||
<p>If you download the zip file for rhino, it will contain a single JAR
|
||||
file, <code class="filename">js.jar</code>. If you add the JAR file to
|
||||
your class path, you can start the Rhino shell using the command</p>
|
||||
|
||||
<pre class="code"> java org.mozilla.javascript.tools.shell.Main
|
||||
</pre>
|
||||
|
||||
<p>or if you have Java 2 (JDK 1.2 or greater), you can avoid changing your
|
||||
classpath and simply use the command</p>
|
||||
|
||||
<pre class="code"> java -jar js.jar</pre>
|
||||
|
||||
<p>Unfortunately the <code>-jar</code> option to <code class="command">java</code>
|
||||
will overwrite your existing classpath. The shell's interactive mode
|
||||
is a good way to begin exploring Rhino.</p>
|
||||
<p class="note">Earlier versions of Rhino have two JAR files, js.jar and
|
||||
jstools.jar, and don't support the -jar option. Both JAR files must be
|
||||
added to the class path to start the shell.</p>
|
||||
<p>You can execute a JavaScript file by putting the file name as an argument
|
||||
to the shell class:</p>
|
||||
<pre> java org.mozilla.javascript.tools.shell.Main myScript.js</pre>
|
||||
<p>There are a number of options for evaluating scripts using the shell. See
|
||||
the <a href="shell.html">command description</a> for more information.</p>
|
||||
|
||||
<h2><a name="liveconnect" id="liveconnect">LiveConnect: Communicating with Java
|
||||
from JavaScript</a></h2>
|
||||
<p>If you are planning to script Java using Rhino, you'll want to use
|
||||
LiveConnect, which allows you to create Java classes and call Java methods
|
||||
from within JavaScript. For example, here's a log from an interactive session.
|
||||
If you type it in, you'll see a window with a button filling it.</p>
|
||||
|
||||
<div class="figure" style="text-align: center;"><img src="scriptjavaframe.jpg" height="100" width="200" alt=""><br>
|
||||
A Java frame created from the Rhino shell.</div>
|
||||
|
||||
<pre class="code">
|
||||
$ 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,resizable,title=JavaScript]
|
||||
js> frame.show()
|
||||
js> frame.setSize(new Dimension(200,100))
|
||||
js> button = new Button("OK")
|
||||
java.awt.Button[button0,0,0,0x0,invalid,label=OK]
|
||||
js> frame.add(button)
|
||||
java.awt.Button[button0,0,0,0x0,invalid,label=OK]
|
||||
js> frame.show()
|
||||
js> quit()
|
||||
$
|
||||
</pre>
|
||||
|
||||
<p>If you wish to load classes from JavaScript that aren't in the
|
||||
<code>java</code> package, you'll need to prefix the package name
|
||||
with "<code>Packages.</code>". For example:</p>
|
||||
|
||||
<pre class="code">
|
||||
$ java org.mozilla.javascript.tools.shell.Main
|
||||
js> cx = Packages.org.mozilla.javascript.Context.currentContext
|
||||
org.mozilla.javascript.Context@25980b44
|
||||
js> cx.evaluateString(this, "3+2", null, 0, null)
|
||||
5.0
|
||||
js> quit()
|
||||
$
|
||||
</pre>
|
||||
|
||||
<h2><a name="accessing" id="accessing">Accessing JavaBean Properties</a></h2>
|
||||
<p>Java classes can define JavaBean properties using getter and setter methods.
|
||||
For example, the following class defines two properties:</p>
|
||||
|
||||
<pre class="code">
|
||||
public class Me {
|
||||
public int getAge() { return age; }
|
||||
public void setAge(int anAge) { age = anAge;
|
||||
}
|
||||
public String getSex() { return "male"; }
|
||||
private int age;
|
||||
};
|
||||
</pre>
|
||||
|
||||
<p>The two properties defined are <var>age</var> and <var>sex</var>.
|
||||
The <var>sex</var> property is read-only: it has no setter.</p>
|
||||
|
||||
<p>Using Rhino we can access the bean properties as if they where
|
||||
JavaScript properties. We can also continue to call the methods that
|
||||
define the property.</p>
|
||||
|
||||
<pre class="code">
|
||||
js> me = new Packages.Me();
|
||||
Me@93
|
||||
js> me.getSex()
|
||||
male
|
||||
js> me.sex
|
||||
male
|
||||
js> me.age = 33;
|
||||
33
|
||||
js> me.age
|
||||
33
|
||||
js> me.getAge()
|
||||
33
|
||||
js>
|
||||
</pre>
|
||||
|
||||
<p>Since the <var>sex</var> property is read-only, we are not allowed to write
|
||||
to it.</p>
|
||||
<p class="note">JavaBean reflection is not available in versions of Rhino before
|
||||
1.5.</p>
|
||||
|
||||
<h2><a name="importingclasses" id="importingclasses">Importing Java Classes
|
||||
and Packages</a></h2>
|
||||
<p>Above we saw the use of the <code>importPackage</code> function
|
||||
to import all the classes from a particular Java package. There is
|
||||
also <code>importClass</code>, which imports a single class:</p>
|
||||
|
||||
<pre class="code">
|
||||
$ java org.mozilla.javascript.tools.shell.Main
|
||||
js> importClass(Packages.org.mozilla.javascript.Context)
|
||||
js> cx = Context.enter()
|
||||
org.mozilla.javascript.Context@25980d62
|
||||
js> cx.evaluateString(this, "3+2", null, 0, null)
|
||||
5.0
|
||||
js> quit()
|
||||
$
|
||||
</pre>
|
||||
|
||||
<h2><a name="extending" id="extending">Extending Java Classes and
|
||||
Implementing Java Interfaces with JavaScript</a></h2>
|
||||
|
||||
<p>Starting from the example above of creating a Java frame using JavaScript,
|
||||
we can add a listener for the button. Once we call <code>addActionListener</code>
|
||||
we can then click on the button to get the current date printed out:</p>
|
||||
|
||||
<pre class="code">
|
||||
$ 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,resizable,title=JavaScript]
|
||||
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()
|
||||
Wed Mar 15 15:42:20 GMT-0800 (PST) 2000
|
||||
js> o = { actionPerformed: printDate }
|
||||
[object Object]
|
||||
js> o.actionPerformed()
|
||||
Wed Mar 15 15:42:39 GMT-0800 (PST) 2000
|
||||
js> buttonListener = java.awt.event.ActionListener(o)
|
||||
adapter0@6acc0f66
|
||||
js> button.addActionListener(buttonListener)
|
||||
js> Wed Mar 15 15:43:05 GMT-0800 (PST) 2000
|
||||
Wed Mar 15 15:43:05 GMT-0800 (PST) 2000
|
||||
Wed Mar 15 15:43:08 GMT-0800 (PST) 2000
|
||||
quit()
|
||||
$
|
||||
</pre>
|
||||
|
||||
<p>When we type
|
||||
<code class="command">buttonListener = java.awt.event.ActionListener(o)</code>,
|
||||
Rhino actually creates a new Java class that implements
|
||||
<code>ActionListener</code> and forwards calls from that class to
|
||||
the JavaScript object. So when you click on the button, the
|
||||
<code>printDate</code> method is called.</p>
|
||||
|
||||
<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
|
||||
<code>printDate</code> directly to <code>addActionListener</code>
|
||||
and simplifies example:</p>
|
||||
|
||||
<pre class="code">
|
||||
$ 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>
|
||||
|
||||
<h2><a name="javaadapter" id="javaadapter">JavaAdapter constructor</a></h2>
|
||||
|
||||
<p>Another way to create a JavaAdapter is to call the JavaAdapter constructor
|
||||
explicitly. Using the JavaAdapter constructor gives you additional features
|
||||
that cannot be had by "constructing" a Java interface as was done above.</p>
|
||||
|
||||
<p>Instead of writing</p>
|
||||
|
||||
<pre class="code">buttonListener = java.awt.event.ActionListener(o)
|
||||
</pre>
|
||||
|
||||
<p>above we can also write</p>
|
||||
|
||||
<pre class="code">
|
||||
buttonListener = new JavaAdapter(java.awt.event.ActionListener, o)
|
||||
</pre>
|
||||
|
||||
<p>which is equivalent. If we also wanted to extend class <code>Foo</code>,
|
||||
while also implementing <code>java.lang.Runnable</code>, we would write</p>
|
||||
|
||||
<pre class="code">
|
||||
buttonListener = new JavaAdapter(Packages.Foo,
|
||||
java.awt.event.ActionListener,
|
||||
java.lang.Runnable, o)
|
||||
</pre>
|
||||
|
||||
<p>In general the syntax is</p>
|
||||
|
||||
<pre class="code">
|
||||
new JavaAdapter(<var>java-class</var>, [<var>java-class</var>,...] <var>javascript-object</var>)
|
||||
</pre>
|
||||
|
||||
<p>where at most one <code>java-class</code> is a Java class and the
|
||||
remaining <code>java-class</code>es are interfaces. The result will be
|
||||
a Java adapter that extends any specified Java class, implements the
|
||||
Java interfaces, and forwards any calls to the methods of the
|
||||
<i>javascript-object</i>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
BIN
mozilla/js/rhino/docs/scriptjavaframe.jpg
Normal file
BIN
mozilla/js/rhino/docs/scriptjavaframe.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
156
mozilla/js/rhino/docs/serialization.html
Normal file
156
mozilla/js/rhino/docs/serialization.html
Normal file
@@ -0,0 +1,156 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.72 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Serialization</title>
|
||||
</head>
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<script src="owner.js"></script>
|
||||
<center>
|
||||
<h1>Serialization</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>Beginning with Rhino 1.5 Release 3 it is possible to serialize JavaScript
|
||||
objects, including functions and scripts. However, serialization of
|
||||
code in compilation mode has some significant limitations.. Serialization
|
||||
provides a way to save the state of an object and write it out to a file
|
||||
or send it across a network connection. <br>
|
||||
</p>
|
||||
<h2>Simple serialization example</h2>
|
||||
The Rhino shell has two new top-level functions, serialize and deserialize.
|
||||
They're intended mainly as examples of the use of serialization:<br>
|
||||
<pre>$ java org.mozilla.javascript.tools.shell.Main<br>js> function f() { return 3; }<br>js> serialize(f, "f.ser")<br>js> quit()<br><br>$ java org.mozilla.javascript.tools.shell.Main<br>js> f = deserialize("f.ser")<br><br>function f() {<br> return 3;<br>}<br><br>js> f()<br>3<br>js></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
Here we see a simple case of a function being serialized to a file and then
|
||||
read into a new instance of Rhino and called. <br>
|
||||
<br>
|
||||
<h2>Rhino serialization APIs</h2>
|
||||
Two new classes, ScriptableOutputStream and ScriptableInputStream, were introduced
|
||||
to handle serialization of Rhino classes. These classes extend ObjectOutputStream
|
||||
and ObjectInputStream respectively. Writing an object to a file can be done
|
||||
in a few lines of Java code:<br>
|
||||
<pre>FileOutputStream fos = new FileOutputStream(filename);<br>ScriptableOutputStream out = new ScriptableOutputStream(fos, scope);<br>out.writeObject(obj);<br>out.close();</pre>
|
||||
<p>Here filename is the file to write to, obj is the object or function to
|
||||
write, and scope is the top-level scope containing obj. </p>
|
||||
<p>Reading the serialized object back into memory is similarly simple:</p>
|
||||
<pre>FileInputStream fis = new FileInputStream(filename);<br>ObjectInputStream in = new ScriptableInputStream(fis, scope);<br>Object deserialized = in.readObject();<br>in.close();<br></pre>
|
||||
<p>Again, we need the scope to create our serialization stream class. </p>
|
||||
<p>So why do we need these specialized stream classes instead of simply using
|
||||
ObjectOutputStream and ObjectInputStream? To understand the answer we must
|
||||
know what goes on behind the scenes when Rhino serializes objects. </p>
|
||||
<h2>How Rhino serialization works</h2>
|
||||
By default, Java serialization of an object also serializes objects that
|
||||
are referred to by that object. Upon deserialization the initial object and
|
||||
the objects it refers to are all created and the references between the objects
|
||||
are resolved. <br>
|
||||
<br>
|
||||
However, for JavaScript this creates a problem. JavaScript objects contain
|
||||
references to prototypes and to parent scopes. Default serialization would
|
||||
serialize the object or function we desired but would also serialize Object.prototype
|
||||
or even possibly the entire top-level scope and everything it refers to!
|
||||
We want to be able to serialize a JavaScript object and then deserialize
|
||||
it into a new scope and have all of the references from the deserialized
|
||||
object to prototypes and parent scopes resolved correctly to refer to objects
|
||||
in the new scope. <br>
|
||||
<br>
|
||||
ScriptableOutputStream takes a scope as a parameter to its constructor. If
|
||||
in the process of serialization it encounters a reference to the scope it
|
||||
will serialize a marker that will be resolved to the new scope upon deserialization.
|
||||
It is also possible to add names of objects to a list in the ScriptableOutputStream
|
||||
object. These objects will also be saved as markers upon serialization and
|
||||
resolved in the new scope upon deserialization. Use the addExcludedName method
|
||||
of ScriptableOutputStream to add new names. By default, ScriptableOutputStream
|
||||
excludes all the names defined using Context.initStandardObjects.<br>
|
||||
<br>
|
||||
If you are using Rhino serialization in an environment where you always define,
|
||||
say, a constructor "Foo", you should add the following code before calling
|
||||
writeObject:<br>
|
||||
<pre>out.addExcludedName("Foo");<br>out.addExcludedName("Foo.prototype");<br></pre>
|
||||
This code will prevent Foo and Foo.prototype from being serialized and will
|
||||
cause references to Foo or Foo.prototype to be resolved to the objects in
|
||||
the new scope upon deserialization. Exceptions will be thrown if Foo or Foo.prototype
|
||||
cannot be found the scopes used in either ScriptableOutputStream or ScriptableInputStream.<br>
|
||||
<br>
|
||||
<h2>Rhino serialization in compilation mode</h2>
|
||||
Serialization works well with objects and with functions and scripts in
|
||||
interpretive mode. However, you can run into problems with serialization
|
||||
of compiled functions and scripts:<br>
|
||||
<pre>$ cat test.js<br>function f() { return 3; }<br>serialize(f, "f.ser");<br>g = deserialize("f.ser");<br>print(g());<br>$ java org.mozilla.javascript.tools.shell.Main -opt -1 test.js<br>3<br>$ java org.mozilla.javascript.tools.shell.Main test.js<br>js: uncaught JavaScript exception: java.lang.ClassNotFoundException: c1<br></pre>
|
||||
<p>The problem is that Java serialization has no built-in way to serialize
|
||||
Java classes themselves. (It might be possible to save the Java bytecodes
|
||||
in an array and then load the class upon deserialization, but at best that
|
||||
would eat up a lot of memory for just this feature.) One way around this
|
||||
is to compile the functions using the jsc tool: </p>
|
||||
<pre>$ cat f.js<br>function f() { return 3; }<br>$ java -classpath js.jar org.mozilla.javascript.tools.jsc.Main f.js<br>$ cat test2.js<br>loadClass("f");<br>serialize(f, "f.ser");<br>g = deserialize("f.ser");<br>print(g());<br>$ java -classpath 'js.jar;.' org.mozilla.javascript.tools.shell.Main test2.js<br>3<br></pre>
|
||||
<p> Now the function f is compiled to a Java class, but that class is
|
||||
then made available in the classpath so serialization works. This isn't that
|
||||
interesting an example since compiling a function to a class and then loading
|
||||
it accomplishes the same as serializing an interpreted function, but it becomes
|
||||
more relevant if you wish to serialize JavaScript objects that have references
|
||||
to compiled functions. </p>
|
||||
<h3>
|
||||
<hr width="100%"><br>
|
||||
<a href="index.html">back to top</a>
|
||||
</h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
308
mozilla/js/rhino/docs/shell.html
Normal file
308
mozilla/js/rhino/docs/shell.html
Normal file
@@ -0,0 +1,308 @@
|
||||
<!-- ***** 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="GENERATOR" content="Mozilla/4.7 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
<title>JavaScript Shell</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
JavaScript Shell</h1></center>
|
||||
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>
|
||||
<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>
|
||||
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.
|
||||
|
||||
<h2>
|
||||
Predefined Properties</h2>
|
||||
Scripts executing in the shell have access to some additional properties
|
||||
of the top-level object.
|
||||
<br>
|
||||
<h4>
|
||||
arguments</h4>
|
||||
|
||||
<blockquote>The <tt>arguments</tt> object is an array containing the strings
|
||||
of all the arguments given at the command line when the shell was invoked.</blockquote>
|
||||
|
||||
<h4>
|
||||
help()</h4>
|
||||
|
||||
<blockquote>Executing the help function will print usage and help messages.</blockquote>
|
||||
|
||||
<h4>
|
||||
defineClass(<i>className</i>)</h4>
|
||||
|
||||
<blockquote>Define an extension using the Java class named with the string
|
||||
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>
|
||||
|
||||
<blockquote>Load JavaScript source files named by string arguments. If
|
||||
multiple arguments are given, each file is read in and executed in turn.</blockquote>
|
||||
|
||||
<h4>
|
||||
loadClass(<i>className</i>)</h4>
|
||||
|
||||
<blockquote>Load and execute the class named by the string argument <i>className</i>.
|
||||
The class must be a class that implements the Script interface, as will
|
||||
any script compiled by <a href="jsc.html">jsc</a>.</blockquote>
|
||||
|
||||
<h4>
|
||||
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>
|
||||
|
||||
<blockquote>Quit shell. The shell will also quit in interactive mode if
|
||||
an end-of-file character is typed at the prompt.</blockquote>
|
||||
|
||||
<h4>
|
||||
version([<i>number</i>])</h4>
|
||||
|
||||
<blockquote>Get or set JavaScript version number. If no argument is supplied,
|
||||
the current version number is returned. If an argument is supplied, it
|
||||
is expected to be one of <tt>100</tt>, <tt>110</tt>, <tt>120</tt>, <tt>130,</tt>
|
||||
or <tt>140</tt> to indicate JavaScript version 1.0, 1.1, 1.2, 1.3, or 1.4
|
||||
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>
|
||||
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>
|
||||
</html>
|
||||
390
mozilla/js/rhino/docs/tutorial.html
Normal file
390
mozilla/js/rhino/docs/tutorial.html
Normal file
@@ -0,0 +1,390 @@
|
||||
<!-- ***** 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="Generator" content="Microsoft Word 97">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]">
|
||||
<title>Embedding Rhino</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center><font size=+4>Tutorial: Embedding Rhino</font></center>
|
||||
|
||||
<p>Embedding Rhino can be done simply with good results. With more effort
|
||||
on the part of the embedder, the objects exposed to scripts can be customized
|
||||
further.
|
||||
<p>This tutorial leads you through the steps from a simple embedding to
|
||||
more customized, complex embeddings. Fully compilable examples are provided
|
||||
along the way.
|
||||
<p>The examples live in the <tt>rhino/examples</tt> directory in the distribution
|
||||
and in <tt>mozilla/js/rhino/examples</tt> in cvs. This document will link
|
||||
to them using <a href="http://lxr.mozilla.org/">lxr</a>.
|
||||
<p>In this document, JavaScript code will be in <font color="#006600">green</font>,
|
||||
Java code will be in <font color="#006600">green</font>, and shell logs
|
||||
will be in <font color="#663366">purple</font>.
|
||||
<h3>
|
||||
<font size=+3>Contents</font></h3>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#RunScript">RunScript: A simple embedding</a></font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#EnteringContext">Entering a Context</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#initializing">Initializing standard objects</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Collecting">Collecting the arguments</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Evaluating">Evaluating a script</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Print">Print the result</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Exit">Exit the Context</a></font></li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Expose">Expose Java APIs</a></font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#UseJava">Use Java APIs</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#ImplementingInterfaces">Implementing interfaces</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#AddJava">Add Java objects</a></font></li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#UsingJSObjs">Using JavaScript objects from Java</a></font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#UsingJSvars">Using JavaScript variables</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#CallingJSfuns">Calling JavaScript functions</a></font></li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#JavaScriptHostObjects">JavaScript host objects</a></font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#DefiningHostObjects">Defining Host Objects</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Counter">Counter example</a></font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#CounterCtors">Counter's constructors</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#classname">Class name</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Dynamic">Dynamic properties</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#DefiningMethods">Defining JavaScript "methods"</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#AddingCounter">Adding Counter to RunScript</a></font></li>
|
||||
</ul>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="RunScript"></a><font size=+3>RunScript: A simple embedding</font>
|
||||
<p>About the simplest embedding of Rhino possible is the <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript.java">RunScript
|
||||
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)"
|
||||
-1
|
||||
$ java RunScript 'function f(x){return x+1} f(7)'
|
||||
8</font></pre>
|
||||
</blockquote>
|
||||
Note that you'll have to have both the Rhino classes and the RunScript
|
||||
example class file in the classpath. Let's step through the body of <tt>main</tt>
|
||||
one line at time.
|
||||
<p><a NAME="EnteringContext"></a><font size=+2>Entering a Context</font>
|
||||
<p>The code
|
||||
<blockquote>
|
||||
<pre><font color="#006600">Context cx = Context.enter();</font></pre>
|
||||
</blockquote>
|
||||
Creates and enters a <tt>Context. </tt>A <tt>Context</tt> stores information
|
||||
about the execution environment of a script.
|
||||
<br>
|
||||
<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>
|
||||
</blockquote>
|
||||
Initializes the standard objects (<tt>Object</tt>,
|
||||
<tt>Function</tt>, etc.)
|
||||
This must be done before scripts can be executed. The <tt>null</tt> parameter
|
||||
tells <tt>initStandardObjects</tt> to create and return a scope object
|
||||
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 < args.length; i++) {
|
||||
s += args[i];
|
||||
}
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p><br><a NAME="Evaluating"></a><font size=+2>Evaluating a script</font>
|
||||
<p>The code
|
||||
<blockquote>
|
||||
<pre><font color="#006600">Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);</font></pre>
|
||||
</blockquote>
|
||||
uses the Context <tt>cx</tt> to evaluate a string. Evaluation of the script
|
||||
looks up variables in <tt>scope</tt>, and errors will be reported with
|
||||
the filename <tt><cmd></tt> and line number 1.
|
||||
<br>
|
||||
<p><a NAME="Print"></a><font size=+2>Print the result</font>
|
||||
<p>The code
|
||||
<blockquote>
|
||||
<pre><font color="#006600">System.out.println(cx.toString(result));</font></pre>
|
||||
</blockquote>
|
||||
prints the result of evaluating the script (contained in the variable <tt>result</tt>).
|
||||
<tt>result</tt>
|
||||
could be a string, JavaScript object, or other values..The
|
||||
<tt>toString</tt>
|
||||
method converts any JavaScript value to a string.
|
||||
<br>
|
||||
<p><a NAME="Exit"></a><font size=+2>Exit the Context</font>
|
||||
<p>The code
|
||||
<blockquote>
|
||||
<pre style="color: #006600">
|
||||
} finally {
|
||||
Context.exit();
|
||||
}
|
||||
</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>.
|
||||
<br>
|
||||
<dir> </dir>
|
||||
<a NAME="Expose"></a><font size=+3>Expose Java APIs</font>
|
||||
<p><a NAME="UseJava"></a><font size=+2>Use Java APIs</font>
|
||||
<p>No additional code in the embedding needed! The JavaScript feature called
|
||||
<i>LiveConnect</i>
|
||||
allows JavaScript programs to interact with Java objects:
|
||||
<dir><tt><font color="#663366">$ java RunScript 'java.lang.System.out.println(3)'</font></tt>
|
||||
<br><tt><font color="#663366">3.0</font></tt>
|
||||
<br><tt><font color="#663366">undefined</font></tt></dir>
|
||||
<a NAME="ImplementingInterfaces"></a><font size=+2>Implementing interfaces</font>
|
||||
<p>Using Rhino, JavaScript objects can implement arbitrary Java interfaces.
|
||||
There's no Java code to write--it's part of Rhino's LiveConnect implementation.
|
||||
For example, we can see how to implement java.lang.Runnable in a Rhino
|
||||
shell session:
|
||||
<blockquote>
|
||||
<pre><font color="#663366">js> obj = { run: function() { print('hi'); } }
|
||||
[object Object]
|
||||
js> obj.run()
|
||||
hi
|
||||
js> r = new java.lang.Runnable(obj);
|
||||
[object Object]
|
||||
js> t = new java.lang.Thread(r)
|
||||
Thread[Thread-0,5,main]
|
||||
js> t.start()
|
||||
hi</font></pre>
|
||||
</blockquote>
|
||||
<a NAME="AddJava"></a><font size=+2>Add Java objects</font>
|
||||
<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>
|
||||
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>
|
||||
<br><tt><font color="#663366">42.0</font></tt>
|
||||
<br><tt><font color="#663366">undefined</font></tt></dir>
|
||||
|
||||
<p><br><a NAME="UsingJSObjs"></a><font size=+3>Using JavaScript objects
|
||||
from Java</font>
|
||||
<p>After evaluating a script it's possible to query the scope for variables
|
||||
and functions, extracting values and calling JavaScript functions. This
|
||||
is illustrated in the <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript3.java">RunScript3</a>
|
||||
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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<p>Custom host objects can implement special JavaScript features like dynamic
|
||||
properties.
|
||||
<p><a NAME="Counter"></a><font size=+2>Counter example</font>
|
||||
<p>The <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Counter.java">Counter
|
||||
example</a> is a simple host object. We'll go through it method by method
|
||||
below.
|
||||
<p>It's easy to try out new host object classes in the shell using its
|
||||
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
|
||||
js> defineClass("Counter")
|
||||
js> c = new Counter(7)
|
||||
[object Counter]
|
||||
js> c.count
|
||||
7
|
||||
js> c.count
|
||||
8
|
||||
js> c.count
|
||||
9
|
||||
js> c.resetCount()
|
||||
js> c.count
|
||||
0
|
||||
</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.
|
||||
For the counter example, no initialization work is needed, so the implementation
|
||||
is empty.
|
||||
<dir><tt><font color="#006600">public Counter () { }</font></tt></dir>
|
||||
The method <tt>jsConstructor</tt> defines the JavaScript constructor that
|
||||
was called with the expression <tt>new Counter(7)</tt> in the JavaScript
|
||||
code above.
|
||||
<dir><tt><font color="#006600">public void jsConstructor(int a) { count
|
||||
= a; }</font></tt></dir>
|
||||
<a NAME="classname"></a><font size=+2>Class name</font>
|
||||
<p>The class name is defined by the <tt>getClassName</tt> method. This
|
||||
is used to determine the name of the constructor.
|
||||
<dir><tt><font color="#006600">public String getClassName() { return "Counter";
|
||||
}</font></tt></dir>
|
||||
<a NAME="Dynamic"></a><font size=+2>Dynamic properties</font>
|
||||
<p>Dynamic properties are defined by methods beginning with <tt>jsGet_</tt>
|
||||
or <tt>jsSet_</tt>. The method <tt>jsGet_count</tt> defines the <i>count</i>
|
||||
property.
|
||||
<dir><tt><font color="#006600">public int jsGet_count() { return count++;
|
||||
}</font></tt></dir>
|
||||
The expression <tt>c.count</tt> in the JavaScript code above results in
|
||||
a call to this method.
|
||||
<p><a NAME="DefiningMethods"></a><font size=+2>Defining JavaScript "methods"</font>
|
||||
<p>Methods can be defined using the <tt>jsFunction_ prefix</tt>. Here we
|
||||
define <tt>resetCount</tt> for JavaScript.
|
||||
<dir><tt><font color="#006600">public void jsFunction_resetCount() { count
|
||||
= 0; }</font></tt></dir>
|
||||
The call <tt>c.resetCount()</tt> above calls this method.
|
||||
<p><a NAME="AddingCounter"></a><font size=+2>Adding Counter to RunScript</font>
|
||||
<p>Now take a look at the <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript4.java">RunScript4
|
||||
example</a>. It's the same as RunScript except for two additions. The method
|
||||
<tt>ScriptableObject.defineClass</tt>
|
||||
uses a Java class to define the Counter "class" in the top-level scope:
|
||||
<dir><tt><font color="#006600">ScriptableObject.defineClass(scope, Counter.class);</font></tt></dir>
|
||||
Now we can reference the <tt>Counter</tt> object from our script:
|
||||
<dir><tt><font color="#663366">$ java RunScript4 'c = new Counter(3); c.count;
|
||||
c.count;'</font></tt>
|
||||
<br><tt><font color="#663366">4</font></tt></dir>
|
||||
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>
|
||||
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>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
112
mozilla/js/rhino/docs/users.html
Normal file
112
mozilla/js/rhino/docs/users.html
Normal file
@@ -0,0 +1,112 @@
|
||||
<!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.72 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Using Rhino</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<script src="owner.js"></script>
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
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 <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
|
||||
faster and better, and our customers get a more efficient, reliable, and
|
||||
standards based product as a result," said Rob Clark, Director of Product
|
||||
Development at Attachmate. Attachmate integrates Netscape's Java-based
|
||||
JavaScript 1.5 Interpreter into its 100% Pure Java certified web-to-host
|
||||
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
|
||||
JavaScript 1.5 with Java implementation fit right in with only a couple
|
||||
of lines of initialization code and one line of code to export our standard
|
||||
objects by name. Also, we were pleased to find we could take embedded scripting
|
||||
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>
|
||||
<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.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>.
|
||||
Abraham Backus says that he's happy with Rhino because "I've always wanted
|
||||
this kind of JavaScript support."
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><br>
|
||||
<a href="index.html">back to top</a></h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -39,8 +39,6 @@
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
public class Counter extends ScriptableObject {
|
||||
private static final long serialVersionUID = 438270592527335642L;
|
||||
|
||||
// The zero-argument constructor used by Rhino runtime to create instances
|
||||
public Counter() { }
|
||||
|
||||
@@ -48,7 +46,6 @@ public class Counter extends ScriptableObject {
|
||||
public void jsConstructor(int a) { count = a; }
|
||||
|
||||
// The class name is defined by the getClassName method
|
||||
@Override
|
||||
public String getClassName() { return "Counter"; }
|
||||
|
||||
// The method jsGet_count defines the count property.
|
||||
|
||||
@@ -47,7 +47,6 @@ public class DynamicScopes {
|
||||
|
||||
static class MyFactory extends ContextFactory
|
||||
{
|
||||
@Override
|
||||
protected boolean hasFeature(Context cx, int featureIndex)
|
||||
{
|
||||
if (featureIndex == Context.FEATURE_DYNAMIC_SCOPE) {
|
||||
@@ -108,7 +107,7 @@ public class DynamicScopes {
|
||||
useDynamicScope = true;
|
||||
runScripts(cx, script);
|
||||
} finally {
|
||||
Context.exit();
|
||||
cx.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Define a simple JavaScript File object.
|
||||
@@ -72,10 +71,6 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class File extends ScriptableObject {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2549960399774237828L;
|
||||
/**
|
||||
* The zero-parameter constructor.
|
||||
*
|
||||
@@ -113,7 +108,6 @@ public class File extends ScriptableObject {
|
||||
/**
|
||||
* Returns the name of this JavaScript class, "File".
|
||||
*/
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return "File";
|
||||
}
|
||||
@@ -141,12 +135,14 @@ public class File extends ScriptableObject {
|
||||
public Object jsFunction_readLines()
|
||||
throws IOException
|
||||
{
|
||||
List<String> list = new ArrayList<String>();
|
||||
Vector v = new Vector();
|
||||
String s;
|
||||
while ((s = jsFunction_readLine()) != null) {
|
||||
list.add(s);
|
||||
v.addElement(s);
|
||||
}
|
||||
String[] lines = list.toArray(new String[list.size()]);
|
||||
Object[] lines = new Object[v.size()];
|
||||
v.copyInto(lines);
|
||||
|
||||
Scriptable scope = ScriptableObject.getTopLevelScope(this);
|
||||
Context cx = Context.getCurrentContext();
|
||||
return cx.newObject(scope, "Array", lines);
|
||||
@@ -239,7 +235,6 @@ public class File extends ScriptableObject {
|
||||
*
|
||||
* Close the file when this object is collected.
|
||||
*/
|
||||
@Override
|
||||
protected void finalize() {
|
||||
try {
|
||||
jsFunction_close();
|
||||
|
||||
@@ -79,7 +79,6 @@ import org.mozilla.javascript.*;
|
||||
*/
|
||||
|
||||
public class Foo extends ScriptableObject {
|
||||
private static final long serialVersionUID = -3833489808933339159L;
|
||||
|
||||
/**
|
||||
* The zero-parameter constructor.
|
||||
@@ -107,7 +106,6 @@ public class Foo extends ScriptableObject {
|
||||
/**
|
||||
* Returns the name of this JavaScript class, "Foo".
|
||||
*/
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return "Foo";
|
||||
}
|
||||
@@ -145,6 +143,8 @@ public class Foo extends ScriptableObject {
|
||||
* @return computes the string values and types of 'this' and
|
||||
* of each of the supplied arguments and returns them in a string.
|
||||
*
|
||||
* @exception ThreadAssociationException if the current
|
||||
* thread is not associated with a Context
|
||||
* @see org.mozilla.javascript.ScriptableObject#getTopLevelScope
|
||||
*/
|
||||
public static Object jsFunction_varargs(Context cx, Scriptable thisObj,
|
||||
|
||||
@@ -36,8 +36,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Matrix: An example host object class that implements the Scriptable interface.
|
||||
@@ -52,20 +51,21 @@ import java.util.ArrayList;
|
||||
* Here's a shell session showing the Matrix object in action:
|
||||
* <pre>
|
||||
* js> defineClass("Matrix")
|
||||
* js> var m = new Matrix(2); // A constructor call, see "Matrix(int dimension)"
|
||||
* js> m // Object.toString will call "Matrix.getClassName()"
|
||||
* [object Matrix]
|
||||
* js> m = new Matrix(2); <i>A constructor call, see <a href="#Matrix">Matrix</a> below.</i>
|
||||
* [object Matrix] <i>The "Matrix" here comes from <a href"#getClassName">getClassName</a>.</i>
|
||||
* js> version(120); <i>switch to JavaScript1.2 to see arrays better</i>
|
||||
* 0
|
||||
* js> m[0][0] = 3;
|
||||
* 3
|
||||
* js> uneval(m[0]); // an array was created automatically!
|
||||
* js> m[0]; <i>an array was created automatically!</i>
|
||||
* [3]
|
||||
* js> uneval(m[1]); // array is created even if we don't set a value
|
||||
* js> m[1]; <i>array is created even if we don't set a value</i>
|
||||
* []
|
||||
* js> m.dim; // we can access the "dim" property
|
||||
* js> m.dim; <i>we can access the "dim" property</i>
|
||||
* 2
|
||||
* js> m.dim = 3;
|
||||
* 3
|
||||
* js> m.dim; // but not modify the "dim" property
|
||||
* js> m.dim; <i>but not modify it</i>
|
||||
* 2
|
||||
* </pre>
|
||||
*
|
||||
@@ -94,7 +94,7 @@ public class Matrix implements Scriptable {
|
||||
"Dimension of Matrix must be greater than zero");
|
||||
}
|
||||
dim = dimension;
|
||||
list = new ArrayList<Object>();
|
||||
v = new Vector();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,16 +146,15 @@ public class Matrix implements Scriptable {
|
||||
/**
|
||||
* Get the indexed property.
|
||||
* <p>
|
||||
* Look up the element in the associated list and return
|
||||
* Look up the element in the associated vector and return
|
||||
* it if it exists. If it doesn't exist, create it.<p>
|
||||
* @param index the index of the integral property
|
||||
* @param start the object where the lookup began
|
||||
*/
|
||||
public Object get(int index, Scriptable start) {
|
||||
while (index >= list.size()) {
|
||||
list.add(null);
|
||||
}
|
||||
Object result = list.get(index);
|
||||
if (index >= v.size())
|
||||
v.setSize(index+1);
|
||||
Object result = v.elementAt(index);
|
||||
if (result != null)
|
||||
return result;
|
||||
if (dim > 2) {
|
||||
@@ -168,7 +167,7 @@ public class Matrix implements Scriptable {
|
||||
Scriptable scope = ScriptableObject.getTopLevelScope(start);
|
||||
result = cx.newArray(scope, 0);
|
||||
}
|
||||
list.set(index, result);
|
||||
v.setElementAt(result, index);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -249,7 +248,7 @@ public class Matrix implements Scriptable {
|
||||
* Use the convenience method from Context that takes care of calling
|
||||
* toString, etc.
|
||||
*/
|
||||
public Object getDefaultValue(Class<?> typeHint) {
|
||||
public Object getDefaultValue(Class typeHint) {
|
||||
return "[object Matrix]";
|
||||
}
|
||||
|
||||
@@ -275,6 +274,6 @@ public class Matrix implements Scriptable {
|
||||
* Some private data for this class.
|
||||
*/
|
||||
private int dim;
|
||||
private List<Object> list;
|
||||
private Vector v;
|
||||
private Scriptable prototype, parent;
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ import org.mozilla.javascript.*;
|
||||
* on that context.
|
||||
*/
|
||||
public class PrimitiveWrapFactory extends WrapFactory {
|
||||
@Override
|
||||
|
||||
public Object wrap(Context cx, Scriptable scope, Object obj,
|
||||
Class<?> staticType)
|
||||
Class staticType)
|
||||
{
|
||||
if (obj instanceof String || obj instanceof Number ||
|
||||
obj instanceof Boolean)
|
||||
|
||||
@@ -67,7 +67,7 @@ public class RunScript {
|
||||
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
|
||||
|
||||
// Convert the result to a string and print it.
|
||||
System.err.println(Context.toString(result));
|
||||
System.err.println(cx.toString(result));
|
||||
|
||||
} finally {
|
||||
// Exit from the context.
|
||||
|
||||
@@ -59,7 +59,7 @@ public class RunScript2 {
|
||||
s += args[i];
|
||||
}
|
||||
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
|
||||
System.err.println(Context.toString(result));
|
||||
System.err.println(cx.toString(result));
|
||||
} finally {
|
||||
Context.exit();
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class RunScript3 {
|
||||
s += args[i];
|
||||
}
|
||||
|
||||
// Now evaluate the string we've collected. We'll ignore the result.
|
||||
// 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"
|
||||
|
||||
@@ -68,7 +68,7 @@ public class RunScript4 {
|
||||
s += args[i];
|
||||
}
|
||||
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
|
||||
System.err.println(Context.toString(result));
|
||||
System.err.println(cx.toString(result));
|
||||
} finally {
|
||||
Context.exit();
|
||||
}
|
||||
|
||||
@@ -48,9 +48,6 @@ import java.io.*;
|
||||
*/
|
||||
public class Shell extends ScriptableObject
|
||||
{
|
||||
private static final long serialVersionUID = -5638074146250193112L;
|
||||
|
||||
@Override
|
||||
public String getClassName()
|
||||
{
|
||||
return "global";
|
||||
@@ -83,10 +80,8 @@ public class Shell extends ScriptableObject
|
||||
|
||||
// Set up "arguments" in the global scope to contain the command
|
||||
// line arguments after the name of the script to execute
|
||||
Object[] array;
|
||||
if (args.length == 0) {
|
||||
array = new Object[0];
|
||||
} else {
|
||||
Object[] array = args;
|
||||
if (args.length > 0) {
|
||||
int length = args.length - 1;
|
||||
array = new Object[length];
|
||||
System.arraycopy(args, 1, array, 0, length);
|
||||
@@ -116,7 +111,7 @@ public class Shell extends ScriptableObject
|
||||
if (arg.equals("-version")) {
|
||||
if (++i == args.length)
|
||||
usage(arg);
|
||||
double d = Context.toNumber(args[i]);
|
||||
double d = cx.toNumber(args[i]);
|
||||
if (d != d)
|
||||
usage(arg);
|
||||
cx.setLanguageVersion((int) d);
|
||||
@@ -133,7 +128,7 @@ public class Shell extends ScriptableObject
|
||||
private static void usage(String s) {
|
||||
p("Didn't understand \"" + s + "\".");
|
||||
p("Valid arguments are:");
|
||||
p("-version 100|110|120|130|140|150|160|170");
|
||||
p("-version 100|110|120|130|140|150");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
@@ -205,9 +200,9 @@ public class Shell extends ScriptableObject
|
||||
public static double version(Context cx, Scriptable thisObj,
|
||||
Object[] args, Function funObj)
|
||||
{
|
||||
double result = cx.getLanguageVersion();
|
||||
double result = (double) cx.getLanguageVersion();
|
||||
if (args.length > 0) {
|
||||
double d = Context.toNumber(args[0]);
|
||||
double d = cx.toNumber(args[0]);
|
||||
cx.setLanguageVersion((int) d);
|
||||
}
|
||||
return result;
|
||||
@@ -224,7 +219,7 @@ public class Shell extends ScriptableObject
|
||||
{
|
||||
Shell shell = (Shell)getTopLevelScope(thisObj);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
shell.processSource(cx, Context.toString(args[i]));
|
||||
shell.processSource(cx, cx.toString(args[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,8 +267,8 @@ public class Shell extends ScriptableObject
|
||||
Object result = cx.evaluateString(this, source,
|
||||
sourceName, startline,
|
||||
null);
|
||||
if (result != Context.getUndefinedValue()) {
|
||||
System.err.println(Context.toString(result));
|
||||
if (result != cx.getUndefinedValue()) {
|
||||
System.err.println(cx.toString(result));
|
||||
}
|
||||
}
|
||||
catch (WrappedException we) {
|
||||
|
||||
@@ -39,55 +39,28 @@ 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="..">
|
||||
|
||||
|
||||
<property file="build.properties"/>
|
||||
|
||||
<available property="jdk15"
|
||||
classname="java.lang.reflect.ParameterizedType" />
|
||||
|
||||
<target name="compile" depends="compile-most,compile-jdk15">
|
||||
</target>
|
||||
|
||||
<target name="shell" depends="compile">
|
||||
<java classname="org.mozilla.javascript.tools.shell.Main"
|
||||
classpath="${classes}"
|
||||
fork="true">
|
||||
<arg line="-version 170"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="compile-most">
|
||||
<target name="compile">
|
||||
<javac srcdir="src"
|
||||
destdir="${classes}"
|
||||
includes="org/**/*.java"
|
||||
excludes="org/**/jdk15/*.java"
|
||||
deprecation="on"
|
||||
debug="${debug}"
|
||||
target="${target-jvm}"
|
||||
source="${source-level}"
|
||||
>
|
||||
target="${target-jvm}"
|
||||
source="${source-level}"
|
||||
>
|
||||
</javac>
|
||||
<copy todir="${classes}">
|
||||
<fileset dir="src" includes="org/**/*.properties" />
|
||||
<filterset>
|
||||
<filter token="IMPLEMENTATION.VERSION"
|
||||
value="${implementation.version}"/>
|
||||
</filterset>
|
||||
<filter token="IMPLEMENTATION.VERSION"
|
||||
value="${implementation.version}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="compile-jdk15" if="jdk15">
|
||||
<javac srcdir="src"
|
||||
destdir="${classes}"
|
||||
includes="org/**/jdk15/*.java"
|
||||
deprecation="on"
|
||||
debug="${debug}"
|
||||
target="${target-jvm}"
|
||||
source="${source-level}"
|
||||
>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="copy-source">
|
||||
<mkdir dir="${dist.dir}/src"/>
|
||||
<copy todir="${dist.dir}/src">
|
||||
|
||||
@@ -54,20 +54,6 @@ import java.io.*;
|
||||
* @author Roger Lawrence
|
||||
*/
|
||||
public class ClassFileWriter {
|
||||
|
||||
/**
|
||||
* Thrown for cases where the error in generating the class file is
|
||||
* due to a program size constraints rather than a likely bug in the
|
||||
* compiler.
|
||||
*/
|
||||
public static class ClassFileFormatException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1263998431033790599L;
|
||||
|
||||
ClassFileFormatException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a ClassFileWriter for a class.
|
||||
@@ -109,7 +95,7 @@ public class ClassFileWriter {
|
||||
*/
|
||||
public void addInterface(String interfaceName) {
|
||||
short interfaceIndex = itsConstantPool.addClass(interfaceName);
|
||||
itsInterfaces.add(Short.valueOf(interfaceIndex));
|
||||
itsInterfaces.add(new Short(interfaceIndex));
|
||||
}
|
||||
|
||||
public static final short
|
||||
@@ -299,6 +285,8 @@ public class ClassFileWriter {
|
||||
*
|
||||
* @param maxLocals the maximum number of local variable slots
|
||||
* (a.k.a. Java registers) used by the method
|
||||
* @param vars the array of the variables for the method,
|
||||
* or null if none
|
||||
*/
|
||||
public void stopMethod(short maxLocals) {
|
||||
if (itsCurrentMethod == null)
|
||||
@@ -336,13 +324,6 @@ public class ClassFileWriter {
|
||||
lineNumberTableLength +
|
||||
variableTableLength;
|
||||
|
||||
if (attrLength > 65536) {
|
||||
// See http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html,
|
||||
// section 4.10, "The amount of code per non-native, non-abstract
|
||||
// method is limited to 65536 bytes...
|
||||
throw new ClassFileFormatException(
|
||||
"generated bytecode for method exceeds 64K limit.");
|
||||
}
|
||||
byte[] codeAttribute = new byte[attrLength];
|
||||
int index = 0;
|
||||
int codeAttrIndex = itsConstantPool.addUtf8("Code");
|
||||
@@ -356,6 +337,7 @@ public class ClassFileWriter {
|
||||
itsCodeBufferTop);
|
||||
index += itsCodeBufferTop;
|
||||
|
||||
|
||||
if (itsExceptionTableTop > 0) {
|
||||
index = putInt16(itsExceptionTableTop, codeAttribute, index);
|
||||
for (int i = 0; i < itsExceptionTableTop; i++) {
|
||||
@@ -588,7 +570,7 @@ public class ClassFileWriter {
|
||||
case ByteCode.DSTORE :
|
||||
case ByteCode.ASTORE :
|
||||
if (!(0 <= theOperand && theOperand < 65536))
|
||||
throw new ClassFileFormatException("out of range variable");
|
||||
throw new IllegalArgumentException("out of range variable");
|
||||
if (theOperand >= 256) {
|
||||
addToCodeBuffer(ByteCode.WIDE);
|
||||
addToCodeBuffer(theOpCode);
|
||||
@@ -619,17 +601,7 @@ public class ClassFileWriter {
|
||||
* @param k the constant
|
||||
*/
|
||||
public void addLoadConstant(int k) {
|
||||
switch (k) {
|
||||
case 0: add(ByteCode.ICONST_0); break;
|
||||
case 1: add(ByteCode.ICONST_1); break;
|
||||
case 2: add(ByteCode.ICONST_2); break;
|
||||
case 3: add(ByteCode.ICONST_3); break;
|
||||
case 4: add(ByteCode.ICONST_4); break;
|
||||
case 5: add(ByteCode.ICONST_5); break;
|
||||
default:
|
||||
add(ByteCode.LDC, itsConstantPool.addConstant(k));
|
||||
break;
|
||||
}
|
||||
add(ByteCode.LDC, itsConstantPool.addConstant(k));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -686,9 +658,9 @@ public class ClassFileWriter {
|
||||
|
||||
if (theOpCode == ByteCode.IINC) {
|
||||
if (!(0 <= theOperand1 && theOperand1 < 65536))
|
||||
throw new ClassFileFormatException("out of range variable");
|
||||
throw new IllegalArgumentException("out of range variable");
|
||||
if (!(0 <= theOperand2 && theOperand2 < 65536))
|
||||
throw new ClassFileFormatException("out of range increment");
|
||||
throw new IllegalArgumentException("out of range increment");
|
||||
|
||||
if (theOperand1 > 255 || theOperand2 < -128 || theOperand2 > 127) {
|
||||
addToCodeBuffer(ByteCode.WIDE);
|
||||
@@ -1102,7 +1074,7 @@ public class ClassFileWriter {
|
||||
+" "+low+" "+high);
|
||||
}
|
||||
if (low > high)
|
||||
throw new ClassFileFormatException("Bad bounds: "+low+' '+ high);
|
||||
throw new IllegalArgumentException("Bad bounds: "+low+' '+ high);
|
||||
|
||||
int newStack = itsStackTop + stackChange(ByteCode.TABLESWITCH);
|
||||
if (newStack < 0 || Short.MAX_VALUE < newStack) badStack(newStack);
|
||||
@@ -1180,7 +1152,7 @@ public class ClassFileWriter {
|
||||
if (!(0 <= caseOffset && caseOffset + 4 <= itsCodeBufferTop)) {
|
||||
// caseIndex >= -1 does not guarantee that caseOffset >= 0 due
|
||||
// to a possible overflow.
|
||||
throw new ClassFileFormatException(
|
||||
throw new IllegalArgumentException(
|
||||
"Too big case index: "+caseIndex);
|
||||
}
|
||||
// ALERT: perhaps check against case bounds?
|
||||
@@ -1277,7 +1249,7 @@ public class ClassFileWriter {
|
||||
// -1 to get delta from instruction start
|
||||
int offset = pc - (fixupSite - 1);
|
||||
if ((short)offset != offset) {
|
||||
throw new ClassFileFormatException
|
||||
throw new RuntimeException
|
||||
("Program too complex: too big jump offset");
|
||||
}
|
||||
codeBuffer[fixupSite] = (byte)(offset >> 8);
|
||||
@@ -1299,10 +1271,6 @@ public class ClassFileWriter {
|
||||
return itsStackTop;
|
||||
}
|
||||
|
||||
public void setStackTop(short n) {
|
||||
itsStackTop = n;
|
||||
}
|
||||
|
||||
public void adjustStackTop(int delta) {
|
||||
int newStack = itsStackTop + delta;
|
||||
if (newStack < 0 || Short.MAX_VALUE < newStack) badStack(newStack);
|
||||
@@ -3014,7 +2982,6 @@ final class FieldOrMethodRef
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (!(obj instanceof FieldOrMethodRef)) { return false; }
|
||||
@@ -3024,7 +2991,6 @@ final class FieldOrMethodRef
|
||||
&& type.equals(x.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
if (hashCode == -1) {
|
||||
|
||||
@@ -60,7 +60,7 @@ final class Arguments extends IdScriptableObject
|
||||
setPrototype(ScriptableObject.getObjectPrototype(parent));
|
||||
|
||||
args = activation.originalArgs;
|
||||
lengthObj = Integer.valueOf(args.length);
|
||||
lengthObj = new Integer(args.length);
|
||||
|
||||
NativeFunction f = activation.function;
|
||||
calleeObj = f;
|
||||
@@ -75,13 +75,11 @@ final class Arguments extends IdScriptableObject
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName()
|
||||
{
|
||||
return "Object";
|
||||
return "Arguments";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(int index, Scriptable start)
|
||||
{
|
||||
if (0 <= index && index < args.length) {
|
||||
@@ -92,7 +90,6 @@ final class Arguments extends IdScriptableObject
|
||||
return super.has(index, start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(int index, Scriptable start)
|
||||
{
|
||||
if (0 <= index && index < args.length) {
|
||||
@@ -130,7 +127,6 @@ final class Arguments extends IdScriptableObject
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(int index, Scriptable start, Object value)
|
||||
{
|
||||
if (0 <= index && index < args.length) {
|
||||
@@ -144,7 +140,7 @@ final class Arguments extends IdScriptableObject
|
||||
synchronized (this) {
|
||||
if (args[index] != NOT_FOUND) {
|
||||
if (args == activation.originalArgs) {
|
||||
args = args.clone();
|
||||
args = (Object[])args.clone();
|
||||
}
|
||||
args[index] = value;
|
||||
return;
|
||||
@@ -155,14 +151,13 @@ final class Arguments extends IdScriptableObject
|
||||
super.put(index, start, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(int index)
|
||||
{
|
||||
if (0 <= index && index < args.length) {
|
||||
synchronized (this) {
|
||||
if (args[index] != NOT_FOUND) {
|
||||
if (args == activation.originalArgs) {
|
||||
args = args.clone();
|
||||
args = (Object[])args.clone();
|
||||
}
|
||||
args[index] = NOT_FOUND;
|
||||
return;
|
||||
@@ -181,17 +176,15 @@ final class Arguments extends IdScriptableObject
|
||||
|
||||
MAX_INSTANCE_ID = 3;
|
||||
|
||||
@Override
|
||||
protected int getMaxInstanceId()
|
||||
{
|
||||
return MAX_INSTANCE_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int findInstanceIdInfo(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2007-05-09 08:15:04 EDT
|
||||
// #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);
|
||||
@@ -200,7 +193,6 @@ final class Arguments extends IdScriptableObject
|
||||
else if (c=='r') { X="caller";id=Id_caller; }
|
||||
}
|
||||
if (X!=null && X!=s && !X.equals(s)) id = 0;
|
||||
break L0;
|
||||
}
|
||||
// #/generated#
|
||||
|
||||
@@ -220,7 +212,6 @@ final class Arguments extends IdScriptableObject
|
||||
|
||||
// #/string_id_map#
|
||||
|
||||
@Override
|
||||
protected String getInstanceIdName(int id)
|
||||
{
|
||||
switch (id) {
|
||||
@@ -231,7 +222,6 @@ final class Arguments extends IdScriptableObject
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getInstanceIdValue(int id)
|
||||
{
|
||||
switch (id) {
|
||||
@@ -252,7 +242,6 @@ final class Arguments extends IdScriptableObject
|
||||
return super.getInstanceIdValue(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setInstanceIdValue(int id, Object value)
|
||||
{
|
||||
switch (id) {
|
||||
@@ -265,7 +254,6 @@ final class Arguments extends IdScriptableObject
|
||||
super.setInstanceIdValue(id, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
Object[] getIds(boolean getAll)
|
||||
{
|
||||
Object[] ids = super.getIds(getAll);
|
||||
@@ -294,7 +282,7 @@ final class Arguments extends IdScriptableObject
|
||||
int offset = 0;
|
||||
for (int i = 0; i != args.length; ++i) {
|
||||
if (present == null || !present[i]) {
|
||||
ids[offset] = Integer.valueOf(i);
|
||||
ids[offset] = new Integer(i);
|
||||
++offset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,13 +51,12 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
|
||||
static final long serialVersionUID = 5311394446546053859L;
|
||||
|
||||
private static final Object FUNCTION_TAG = "Function";
|
||||
private static final Object FUNCTION_TAG = new Object();
|
||||
|
||||
static void init(Scriptable scope, boolean sealed)
|
||||
{
|
||||
BaseFunction obj = new BaseFunction();
|
||||
// Function.prototype attributes: see ECMA 15.3.3.1
|
||||
obj.prototypePropertyAttributes = DONTENUM | READONLY | PERMANENT;
|
||||
obj.isPrototypePropertyImmune = true;
|
||||
obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
|
||||
}
|
||||
|
||||
@@ -70,7 +69,6 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
super(scope, prototype);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return "Function";
|
||||
}
|
||||
@@ -89,7 +87,6 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
* value's prototype chain
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean hasInstance(Scriptable instance)
|
||||
{
|
||||
Object protoProp = ScriptableObject.getProperty(this, "prototype");
|
||||
@@ -111,17 +108,15 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
|
||||
MAX_INSTANCE_ID = 5;
|
||||
|
||||
@Override
|
||||
protected int getMaxInstanceId()
|
||||
{
|
||||
return MAX_INSTANCE_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int findInstanceIdInfo(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2007-05-09 08:15:15 EDT
|
||||
// #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;
|
||||
@@ -133,7 +128,6 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
break L;
|
||||
}
|
||||
if (X!=null && X!=s && !X.equals(s)) id = 0;
|
||||
break L0;
|
||||
}
|
||||
// #/generated#
|
||||
// #/string_id_map#
|
||||
@@ -148,7 +142,8 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
attr = DONTENUM | READONLY | PERMANENT;
|
||||
break;
|
||||
case Id_prototype:
|
||||
attr = prototypePropertyAttributes;
|
||||
attr = (isPrototypePropertyImmune)
|
||||
? READONLY | PERMANENT : PERMANENT;
|
||||
break;
|
||||
case Id_arguments:
|
||||
attr = DONTENUM | PERMANENT;
|
||||
@@ -158,7 +153,6 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
return instanceIdInfo(attr, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInstanceIdName(int id)
|
||||
{
|
||||
switch (id) {
|
||||
@@ -171,7 +165,6 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
return super.getInstanceIdName(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getInstanceIdValue(int id)
|
||||
{
|
||||
switch (id) {
|
||||
@@ -184,11 +177,10 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
return super.getInstanceIdValue(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setInstanceIdValue(int id, Object value)
|
||||
{
|
||||
if (id == Id_prototype) {
|
||||
if ((prototypePropertyAttributes & READONLY) == 0) {
|
||||
if (!isPrototypePropertyImmune) {
|
||||
prototypeProperty = (value != null)
|
||||
? value : UniqueTag.NULL_VALUE;
|
||||
}
|
||||
@@ -203,7 +195,6 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
super.setInstanceIdValue(id, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillConstructorProperties(IdFunctionObject ctor)
|
||||
{
|
||||
// Fix up bootstrapping problem: getPrototype of the IdFunctionObject
|
||||
@@ -213,7 +204,6 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
super.fillConstructorProperties(ctor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initPrototypeId(int id)
|
||||
{
|
||||
String s;
|
||||
@@ -229,22 +219,6 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
initPrototypeMethod(FUNCTION_TAG, id, s, arity);
|
||||
}
|
||||
|
||||
static boolean isApply(IdFunctionObject f) {
|
||||
return f.hasTag(FUNCTION_TAG) && f.methodId() == Id_apply;
|
||||
}
|
||||
|
||||
static boolean isApplyOrCall(IdFunctionObject f) {
|
||||
if(f.hasTag(FUNCTION_TAG)) {
|
||||
switch(f.methodId()) {
|
||||
case Id_apply:
|
||||
case Id_call:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
|
||||
Scriptable thisObj, Object[] args)
|
||||
{
|
||||
@@ -301,11 +275,11 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
*/
|
||||
public void setImmunePrototypeProperty(Object value)
|
||||
{
|
||||
if ((prototypePropertyAttributes & READONLY) != 0) {
|
||||
if (isPrototypePropertyImmune) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
prototypeProperty = (value != null) ? value : UniqueTag.NULL_VALUE;
|
||||
prototypePropertyAttributes = DONTENUM | PERMANENT | READONLY;
|
||||
isPrototypePropertyImmune = true;
|
||||
}
|
||||
|
||||
protected Scriptable getClassPrototype()
|
||||
@@ -511,24 +485,17 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
ErrorReporter reporter;
|
||||
reporter = DefaultErrorReporter.forEval(cx.getErrorReporter());
|
||||
|
||||
Evaluator evaluator = Context.createInterpreter();
|
||||
if (evaluator == null) {
|
||||
throw new JavaScriptException("Interpreter not present",
|
||||
filename, linep[0]);
|
||||
}
|
||||
|
||||
// Compile with explicit interpreter instance to force interpreter
|
||||
// mode.
|
||||
return cx.compileFunction(global, source, evaluator, reporter,
|
||||
return cx.compileFunction(global, source, new Interpreter(), reporter,
|
||||
sourceURI, 1, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int findPrototypeId(String s)
|
||||
{
|
||||
int id;
|
||||
// #string_id_map#
|
||||
// #generated# Last update: 2007-05-09 08:15:15 EDT
|
||||
// #generated# Last update: 2004-03-17 13:23:22 CET
|
||||
L0: { id = 0; String X = null; int c;
|
||||
L: switch (s.length()) {
|
||||
case 4: X="call";id=Id_call; break L;
|
||||
@@ -540,7 +507,6 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
case 11: X="constructor";id=Id_constructor; break L;
|
||||
}
|
||||
if (X!=null && X!=s && !X.equals(s)) id = 0;
|
||||
break L0;
|
||||
}
|
||||
// #/generated#
|
||||
return id;
|
||||
@@ -558,7 +524,6 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
// #/string_id_map#
|
||||
|
||||
private Object prototypeProperty;
|
||||
// For function object instances, attribute is PERMANENT; see ECMA 15.3.5.2
|
||||
private int prototypePropertyAttributes = PERMANENT;
|
||||
private boolean isPrototypePropertyImmune;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Bukanov, igor@fastmail.fm
|
||||
* 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
|
||||
@@ -39,9 +38,7 @@
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.io.Serializable;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Cache of generated classes and data structures to access Java runtime
|
||||
@@ -51,14 +48,20 @@ import java.io.Serializable;
|
||||
*
|
||||
* @since Rhino 1.5 Release 5
|
||||
*/
|
||||
public class ClassCache implements Serializable
|
||||
public class ClassCache
|
||||
{
|
||||
private static final long serialVersionUID = -8866246036237312215L;
|
||||
private static final Object AKEY = "ClassCache";
|
||||
private static final Object AKEY = new Object();
|
||||
|
||||
private volatile boolean cachingIsEnabled = true;
|
||||
private transient HashMap<Class<?>,JavaMembers> classTable;
|
||||
private transient HashMap<JavaAdapter.JavaAdapterSignature,Class<?>> classAdapterCache;
|
||||
private transient HashMap<Class<?>,Object> interfaceAdapterCache;
|
||||
|
||||
Hashtable classTable = new Hashtable();
|
||||
|
||||
Hashtable javaAdapterGeneratedClasses = new Hashtable();
|
||||
|
||||
ScriptableObject scope;
|
||||
|
||||
private Hashtable interfaceAdapterCache;
|
||||
|
||||
private int generatedClassSerial;
|
||||
|
||||
/**
|
||||
@@ -76,11 +79,11 @@ public class ClassCache implements Serializable
|
||||
*/
|
||||
public static ClassCache get(Scriptable scope)
|
||||
{
|
||||
ClassCache cache = (ClassCache)
|
||||
ScriptableObject.getTopScopeValue(scope, AKEY);
|
||||
ClassCache cache;
|
||||
cache = (ClassCache)ScriptableObject.getTopScopeValue(scope, AKEY);
|
||||
if (cache == null) {
|
||||
throw new RuntimeException("Can't find top level scope for " +
|
||||
"ClassCache.get");
|
||||
// XXX warn somehow about wrong cache usage ?
|
||||
cache = new ClassCache();
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
@@ -90,7 +93,7 @@ public class ClassCache implements Serializable
|
||||
* 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 previous ClassCache objects were embedded into
|
||||
* @return true if no prevous ClassCache objects were embedded into
|
||||
* the scope and this ClassCache were successfully associated
|
||||
* or false otherwise.
|
||||
*
|
||||
@@ -102,7 +105,8 @@ public class ClassCache implements Serializable
|
||||
// Can only associate cache with top level scope
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (this == topScope.associateValue(AKEY, this)) {
|
||||
if(this == topScope.associateValue(AKEY, this)) {
|
||||
scope = topScope;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -113,8 +117,8 @@ public class ClassCache implements Serializable
|
||||
*/
|
||||
public synchronized void clearCaches()
|
||||
{
|
||||
classTable = null;
|
||||
classAdapterCache = null;
|
||||
classTable = new Hashtable();
|
||||
javaAdapterGeneratedClasses = new Hashtable();
|
||||
interfaceAdapterCache = null;
|
||||
}
|
||||
|
||||
@@ -153,25 +157,7 @@ public class ClassCache implements Serializable
|
||||
clearCaches();
|
||||
cachingIsEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map from classes to associated JavaMembers objects
|
||||
*/
|
||||
Map<Class<?>,JavaMembers> getClassCacheMap() {
|
||||
if (classTable == null) {
|
||||
classTable = new HashMap<Class<?>,JavaMembers>();
|
||||
}
|
||||
return classTable;
|
||||
}
|
||||
|
||||
Map<JavaAdapter.JavaAdapterSignature,Class<?>> getInterfaceAdapterCacheMap()
|
||||
{
|
||||
if (classAdapterCache == null) {
|
||||
classAdapterCache = new HashMap<JavaAdapter.JavaAdapterSignature,Class<?>>();
|
||||
}
|
||||
return classAdapterCache;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* The method always returns false.
|
||||
@@ -186,8 +172,8 @@ public class ClassCache implements Serializable
|
||||
* @deprecated
|
||||
* The method does nothing.
|
||||
* Invoker optimization is no longer used by Rhino.
|
||||
* On modern JDK like 1.4 or 1.5 the disadvantages of the optimization
|
||||
* like increased memory usage or longer initialization time overweight
|
||||
* 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.
|
||||
*/
|
||||
@@ -204,18 +190,23 @@ public class ClassCache implements Serializable
|
||||
return ++generatedClassSerial;
|
||||
}
|
||||
|
||||
Object getInterfaceAdapter(Class<?> cl)
|
||||
Object getInterfaceAdapter(Class cl)
|
||||
{
|
||||
return interfaceAdapterCache == null
|
||||
? null
|
||||
: interfaceAdapterCache.get(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)
|
||||
synchronized void cacheInterfaceAdapter(Class cl, Object iadapter)
|
||||
{
|
||||
if (cachingIsEnabled) {
|
||||
if (interfaceAdapterCache == null) {
|
||||
interfaceAdapterCache = new HashMap<Class<?>,Object>();
|
||||
interfaceAdapterCache = new Hashtable();
|
||||
}
|
||||
interfaceAdapterCache.put(cl, iadapter);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -23,8 +23,6 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Bukanov, igor@fastmail.fm
|
||||
* Bob Jervis
|
||||
* Steve Yegge
|
||||
*
|
||||
* 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
|
||||
@@ -40,9 +38,7 @@
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.mozilla.javascript.ast.ErrorCollector;
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class CompilerEnvirons
|
||||
{
|
||||
@@ -57,10 +53,6 @@ public class CompilerEnvirons
|
||||
xmlAvailable = true;
|
||||
optimizationLevel = 0;
|
||||
generatingSource = true;
|
||||
strictMode = false;
|
||||
warningAsError = false;
|
||||
generateObserverCount = false;
|
||||
allowSharpComments = false;
|
||||
}
|
||||
|
||||
public void initFromContext(Context cx)
|
||||
@@ -74,9 +66,6 @@ public class CompilerEnvirons
|
||||
= cx.hasFeature(Context.FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER);
|
||||
allowMemberExprAsFunctionName
|
||||
= cx.hasFeature(Context.FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME);
|
||||
strictMode
|
||||
= cx.hasFeature(Context.FEATURE_STRICT_MODE);
|
||||
warningAsError = cx.hasFeature(Context.FEATURE_WARNING_AS_ERROR);
|
||||
xmlAvailable
|
||||
= cx.hasFeature(Context.FEATURE_E4X);
|
||||
|
||||
@@ -84,9 +73,6 @@ public class CompilerEnvirons
|
||||
|
||||
generatingSource = cx.isGeneratingSource();
|
||||
activationNames = cx.activationNames;
|
||||
|
||||
// Observer code generation in compiled code :
|
||||
generateObserverCount = cx.generateObserverCount;
|
||||
}
|
||||
|
||||
public final ErrorReporter getErrorReporter()
|
||||
@@ -136,10 +122,6 @@ public class CompilerEnvirons
|
||||
reservedKeywordAsIdentifier = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension to ECMA: if 'function <name>' is not followed
|
||||
* by '(', assume <name> starts a {@code memberExpr}
|
||||
*/
|
||||
public final boolean isAllowMemberExprAsFunctionName()
|
||||
{
|
||||
return allowMemberExprAsFunctionName;
|
||||
@@ -176,29 +158,6 @@ public class CompilerEnvirons
|
||||
return generatingSource;
|
||||
}
|
||||
|
||||
public boolean getWarnTrailingComma() {
|
||||
return warnTrailingComma;
|
||||
}
|
||||
|
||||
public void setWarnTrailingComma(boolean warn) {
|
||||
warnTrailingComma = warn;
|
||||
}
|
||||
|
||||
public final boolean isStrictMode()
|
||||
{
|
||||
return strictMode;
|
||||
}
|
||||
|
||||
public void setStrictMode(boolean strict)
|
||||
{
|
||||
strictMode = strict;
|
||||
}
|
||||
|
||||
public final boolean reportWarningAsError()
|
||||
{
|
||||
return warningAsError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether or not source information should be generated.
|
||||
* <p>
|
||||
@@ -213,99 +172,6 @@ public class CompilerEnvirons
|
||||
this.generatingSource = generatingSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true iff code will be generated with callbacks to enable
|
||||
* instruction thresholds
|
||||
*/
|
||||
public boolean isGenerateObserverCount() {
|
||||
return generateObserverCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on or off generation of code with callbacks to
|
||||
* track the count of executed instructions.
|
||||
* Currently only affects JVM byte code generation: this slows down the
|
||||
* generated code, but code generated without the callbacks will not
|
||||
* be counted toward instruction thresholds. Rhino's interpretive
|
||||
* mode does instruction counting without inserting callbacks, so
|
||||
* there is no requirement to compile code differently.
|
||||
* @param generateObserverCount if true, generated code will contain
|
||||
* calls to accumulate an estimate of the instructions executed.
|
||||
*/
|
||||
public void setGenerateObserverCount(boolean generateObserverCount) {
|
||||
this.generateObserverCount = generateObserverCount;
|
||||
}
|
||||
|
||||
public boolean isRecordingComments() {
|
||||
return recordingComments;
|
||||
}
|
||||
|
||||
public void setRecordingComments(boolean record) {
|
||||
recordingComments = record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on or off full error recovery. In this mode, parse errors do not
|
||||
* throw an exception, and the parser attempts to build a full syntax tree
|
||||
* from the input. Useful for IDEs and other frontends.
|
||||
*/
|
||||
public void setRecoverFromErrors(boolean recover) {
|
||||
recoverFromErrors = recover;
|
||||
}
|
||||
|
||||
public boolean recoverFromErrors() {
|
||||
return recoverFromErrors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the parser in "IDE" mode. This enables some slightly more expensive
|
||||
* computations, such as figuring out helpful error bounds.
|
||||
*/
|
||||
public void setIdeMode(boolean ide) {
|
||||
ideMode = ide;
|
||||
}
|
||||
|
||||
public boolean isIdeMode() {
|
||||
return ideMode;
|
||||
}
|
||||
|
||||
public Set<String> getActivationNames() {
|
||||
return activationNames;
|
||||
}
|
||||
|
||||
public void setActivationNames(Set<String> activationNames) {
|
||||
this.activationNames = activationNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mozilla sources use the C preprocessor.
|
||||
*/
|
||||
public void setAllowSharpComments(boolean allow) {
|
||||
allowSharpComments = allow;
|
||||
}
|
||||
|
||||
public boolean getAllowSharpComments() {
|
||||
return allowSharpComments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code CompilerEnvirons} suitable for using Rhino
|
||||
* in an IDE environment. Most features are enabled by default.
|
||||
* The {@link ErrorReporter} is set to an {@link ErrorCollector}.
|
||||
*/
|
||||
public static CompilerEnvirons ideEnvirons() {
|
||||
CompilerEnvirons env = new CompilerEnvirons();
|
||||
env.setRecoverFromErrors(true);
|
||||
env.setRecordingComments(true);
|
||||
env.setStrictMode(true);
|
||||
env.setWarnTrailingComma(true);
|
||||
env.setLanguageVersion(170);
|
||||
env.setReservedKeywordAsIdentifier(true);
|
||||
env.setIdeMode(true);
|
||||
env.setErrorReporter(new ErrorCollector());
|
||||
return env;
|
||||
}
|
||||
|
||||
private ErrorReporter errorReporter;
|
||||
|
||||
private int languageVersion;
|
||||
@@ -316,13 +182,6 @@ public class CompilerEnvirons
|
||||
private boolean xmlAvailable;
|
||||
private int optimizationLevel;
|
||||
private boolean generatingSource;
|
||||
private boolean strictMode;
|
||||
private boolean warningAsError;
|
||||
private boolean generateObserverCount;
|
||||
private boolean recordingComments;
|
||||
private boolean recoverFromErrors;
|
||||
private boolean warnTrailingComma;
|
||||
private boolean ideMode;
|
||||
private boolean allowSharpComments;
|
||||
Set<String> activationNames;
|
||||
Hashtable activationNames;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,109 +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):
|
||||
* Bob Jervis
|
||||
*
|
||||
* 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;
|
||||
|
||||
public interface ConstProperties {
|
||||
/**
|
||||
* Sets a named const property in this object.
|
||||
* <p>
|
||||
* The property is specified by a string name
|
||||
* as defined for <code>Scriptable.get</code>.
|
||||
* <p>
|
||||
* The possible values that may be passed in are as defined for
|
||||
* <code>Scriptable.get</code>. A class that implements this method may choose
|
||||
* to ignore calls to set certain properties, in which case those
|
||||
* properties are effectively read-only.<p>
|
||||
* For properties defined in a prototype chain,
|
||||
* use <code>putProperty</code> in ScriptableObject. <p>
|
||||
* Note that if a property <i>a</i> is defined in the prototype <i>p</i>
|
||||
* of an object <i>o</i>, then evaluating <code>o.a = 23</code> will cause
|
||||
* <code>set</code> to be called on the prototype <i>p</i> with
|
||||
* <i>o</i> as the <i>start</i> parameter.
|
||||
* To preserve JavaScript semantics, it is the Scriptable
|
||||
* object's responsibility to modify <i>o</i>. <p>
|
||||
* This design allows properties to be defined in prototypes and implemented
|
||||
* in terms of getters and setters of Java values without consuming slots
|
||||
* in each instance.<p>
|
||||
* <p>
|
||||
* The values that may be set are limited to the following:
|
||||
* <UL>
|
||||
* <LI>java.lang.Boolean objects</LI>
|
||||
* <LI>java.lang.String objects</LI>
|
||||
* <LI>java.lang.Number objects</LI>
|
||||
* <LI>org.mozilla.javascript.Scriptable objects</LI>
|
||||
* <LI>null</LI>
|
||||
* <LI>The value returned by Context.getUndefinedValue()</LI>
|
||||
* </UL><p>
|
||||
* Arbitrary Java objects may be wrapped in a Scriptable by first calling
|
||||
* <code>Context.toObject</code>. This allows the property of a JavaScript
|
||||
* object to contain an arbitrary Java object as a value.<p>
|
||||
* Note that <code>has</code> will be called by the runtime first before
|
||||
* <code>set</code> is called to determine in which object the
|
||||
* property is defined.
|
||||
* Note that this method is not expected to traverse the prototype chain,
|
||||
* which is different from the ECMA [[Put]] operation.
|
||||
* @param name the name of the property
|
||||
* @param start the object whose property is being set
|
||||
* @param value value to set the property to
|
||||
* @see org.mozilla.javascript.Scriptable#has(String, Scriptable)
|
||||
* @see org.mozilla.javascript.Scriptable#get(String, Scriptable)
|
||||
* @see org.mozilla.javascript.ScriptableObject#putProperty(Scriptable, String, Object)
|
||||
* @see org.mozilla.javascript.Context#toObject(Object, Scriptable)
|
||||
*/
|
||||
public void putConst(String name, Scriptable start, Object value);
|
||||
|
||||
/**
|
||||
* Reserves a definition spot for a const. This will set up a definition
|
||||
* of the const property, but set its value to undefined. The semantics of
|
||||
* the start parameter is the same as for putConst.
|
||||
* @param name The name of the property.
|
||||
* @param start The object whose property is being reserved.
|
||||
*/
|
||||
public void defineConst(String name, Scriptable start);
|
||||
|
||||
/**
|
||||
* Returns true if the named property is defined as a const on this object.
|
||||
* @param name
|
||||
* @return true if the named property is defined as a const, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean isConst(String name);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -51,6 +51,7 @@ public interface ContextAction
|
||||
* 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);
|
||||
|
||||
@@ -40,15 +40,11 @@
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
/**
|
||||
* Factory class that Rhino runtime uses to create new {@link Context}
|
||||
* instances. A <code>ContextFactory</code> can also notify listeners
|
||||
* about context creation and release.
|
||||
* Factory class that Rhino runtime use to create new {@link Context}
|
||||
* instances or to notify about Context execution.
|
||||
* <p>
|
||||
* When the Rhino runtime needs to create new {@link Context} instance during
|
||||
* 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)}.
|
||||
@@ -81,6 +77,9 @@ import java.security.PrivilegedAction;
|
||||
* 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);
|
||||
@@ -121,9 +120,7 @@ import java.security.PrivilegedAction;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // Override {@link #doTopCall(Callable,
|
||||
Context, Scriptable,
|
||||
Scriptable, Object[])}
|
||||
* // Override {@link #doTopCall(Callable, Context, Scriptable scope, Scriptable thisObj, Object[] args)}
|
||||
* protected Object doTopCall(Callable callable,
|
||||
* Context cx, Scriptable scope,
|
||||
* Scriptable thisObj, Object[] args)
|
||||
@@ -200,7 +197,7 @@ public class ContextFactory
|
||||
* @see #getGlobal()
|
||||
* @see #hasExplicitGlobal()
|
||||
*/
|
||||
public synchronized static void initGlobal(ContextFactory factory)
|
||||
public static void initGlobal(ContextFactory factory)
|
||||
{
|
||||
if (factory == null) {
|
||||
throw new IllegalArgumentException();
|
||||
@@ -223,7 +220,7 @@ public class ContextFactory
|
||||
*/
|
||||
protected Context makeContext()
|
||||
{
|
||||
return new Context(this);
|
||||
return new Context();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,69 +275,14 @@ public class ContextFactory
|
||||
|
||||
case Context.FEATURE_STRICT_EVAL:
|
||||
return false;
|
||||
|
||||
|
||||
case Context.FEATURE_LOCATION_INFORMATION_IN_ERROR:
|
||||
return false;
|
||||
|
||||
case Context.FEATURE_STRICT_MODE:
|
||||
return false;
|
||||
|
||||
case Context.FEATURE_WARNING_AS_ERROR:
|
||||
return false;
|
||||
|
||||
case Context.FEATURE_ENHANCED_JAVA_ACCESS:
|
||||
return false;
|
||||
}
|
||||
// It is a bug to call the method with unknown featureIndex
|
||||
throw new IllegalArgumentException(String.valueOf(featureIndex));
|
||||
}
|
||||
|
||||
private boolean isDom3Present() {
|
||||
Class<?> nodeClass = Kit.classOrNull("org.w3c.dom.Node");
|
||||
if (nodeClass == null) return false;
|
||||
// Check to see whether DOM3 is present; use a new method defined in
|
||||
// DOM3 that is vital to our implementation
|
||||
try {
|
||||
nodeClass.getMethod("getUserData", new Class<?>[] { String.class });
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a default
|
||||
* {@link org.mozilla.javascript.xml.XMLLib.Factory XMLLib.Factory}
|
||||
* to be used by the <code>Context</code> instances produced by this
|
||||
* factory. See {@link Context#getE4xImplementationFactory} for details.
|
||||
*
|
||||
* May return null, in which case E4X functionality is not supported in
|
||||
* Rhino.
|
||||
*
|
||||
* The default implementation now prefers the DOM3 E4X implementation.
|
||||
*/
|
||||
protected org.mozilla.javascript.xml.XMLLib.Factory
|
||||
getE4xImplementationFactory()
|
||||
{
|
||||
// Must provide default implementation, rather than abstract method,
|
||||
// so that past implementors of ContextFactory do not fail at runtime
|
||||
// upon invocation of this method.
|
||||
// Note that the default implementation returns null if we
|
||||
// neither have XMLBeans nor a DOM3 implementation present.
|
||||
|
||||
if (isDom3Present()) {
|
||||
return org.mozilla.javascript.xml.XMLLib.Factory.create(
|
||||
"org.mozilla.javascript.xmlimpl.XMLLibImpl"
|
||||
);
|
||||
} else if (Kit.classOrNull("org.apache.xmlbeans.XmlCursor") != null) {
|
||||
return org.mozilla.javascript.xml.XMLLib.Factory.create(
|
||||
"org.mozilla.javascript.xml.impl.xmlbeans.XMLLibImpl"
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create class loader for generated classes.
|
||||
@@ -350,13 +292,9 @@ public class ContextFactory
|
||||
* is installed.
|
||||
* Application can override the method to provide custom class loading.
|
||||
*/
|
||||
protected GeneratedClassLoader createClassLoader(final ClassLoader parent)
|
||||
protected GeneratedClassLoader createClassLoader(ClassLoader parent)
|
||||
{
|
||||
return AccessController.doPrivileged(new PrivilegedAction<DefiningClassLoader>() {
|
||||
public DefiningClassLoader run(){
|
||||
return new DefiningClassLoader(parent);
|
||||
}
|
||||
});
|
||||
return new DefiningClassLoader(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,7 +349,8 @@ public class ContextFactory
|
||||
* This can be used to customize {@link Context} without introducing
|
||||
* additional subclasses.
|
||||
*/
|
||||
protected void observeInstructionCount(Context cx, int instructionCount) {
|
||||
protected void observeInstructionCount(Context cx, int instructionCount)
|
||||
{
|
||||
}
|
||||
|
||||
protected void onContextCreated(Context cx)
|
||||
@@ -459,7 +398,7 @@ public class ContextFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* The method is used only to implement
|
||||
* The method is used only to imlement
|
||||
* Context.disableStaticContextListening()
|
||||
*/
|
||||
final void disableContextListening()
|
||||
@@ -513,85 +452,37 @@ public class ContextFactory
|
||||
{
|
||||
return Context.call(this, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a context associated with the current thread, creating one if need
|
||||
* be. The Context stores the execution state of the JavaScript engine, so
|
||||
* it is required that the context be entered before execution may begin.
|
||||
* Once a thread has entered a Context, then getCurrentContext() may be
|
||||
* called to find the context that is associated with the current thread.
|
||||
* <p>
|
||||
* Calling <code>enterContext()</code> will return either the Context
|
||||
* currently associated with the thread, or will create a new context and
|
||||
* associate it with the current thread. Each call to
|
||||
* <code>enterContext()</code> must have a matching call to
|
||||
* {@link Context#exit()}.
|
||||
* <pre>
|
||||
* Context cx = contextFactory.enterContext();
|
||||
* try {
|
||||
* ...
|
||||
* cx.evaluateString(...);
|
||||
* } finally {
|
||||
* Context.exit();
|
||||
* }
|
||||
* </pre>
|
||||
* Instead of using <tt>enterContext()</tt>, <tt>exit()</tt> pair consider
|
||||
* using {@link #call(ContextAction)} which guarantees proper association
|
||||
* of Context instances with the current thread.
|
||||
* With this method the above example becomes:
|
||||
* <pre>
|
||||
* ContextFactory.call(new ContextAction() {
|
||||
* public Object run(Context cx) {
|
||||
* ...
|
||||
* cx.evaluateString(...);
|
||||
* return null;
|
||||
* }
|
||||
* });
|
||||
* </pre>
|
||||
* @return a Context associated with the current thread
|
||||
* @see Context#getCurrentContext()
|
||||
* @see Context#exit()
|
||||
* @see #call(ContextAction)
|
||||
*/
|
||||
public Context enterContext()
|
||||
{
|
||||
return enterContext(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #enterContext()} instead
|
||||
* 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 enterContext(null);
|
||||
return enter(null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link Context#exit()} instead.
|
||||
*/
|
||||
public final void exit()
|
||||
{
|
||||
Context.exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Context associated with the current thread, using the given
|
||||
* Context if need be.
|
||||
* <p>
|
||||
* The same as <code>enterContext()</code> except that <code>cx</code>
|
||||
* is associated with the current thread and returned if the current thread
|
||||
* has no associated context and <code>cx</code> is not associated with any
|
||||
* other thread.
|
||||
* @param cx a Context to associate with the thread if possible
|
||||
* 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
|
||||
* @see #enterContext()
|
||||
* @see #call(ContextAction)
|
||||
* @throws IllegalStateException if <code>cx</code> is already associated
|
||||
* with a different thread
|
||||
*/
|
||||
public final Context enterContext(Context cx)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
package org.mozilla.javascript;
|
||||
|
||||
|
||||
/**
|
||||
* Exception thrown by
|
||||
* {@link org.mozilla.javascript.Context#executeScriptWithContinuations(Script, Scriptable)}
|
||||
* and {@link org.mozilla.javascript.Context#callFunctionWithContinuations(Callable, Scriptable, Object[])}
|
||||
* when execution encounters a continuation captured by
|
||||
* {@link org.mozilla.javascript.Context#captureContinuation()}.
|
||||
* Exception will contain the captured state needed to restart the continuation
|
||||
* with {@link org.mozilla.javascript.Context#resumeContinuation(Object, Scriptable, Object)}.
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
public class ContinuationPending extends RuntimeException {
|
||||
private static final long serialVersionUID = 4956008116771118856L;
|
||||
private NativeContinuation continuationState;
|
||||
private Object applicationState;
|
||||
|
||||
/**
|
||||
* Construct a ContinuationPending exception. Internal call only;
|
||||
* users of the API should get continuations created on their behalf by
|
||||
* calling {@link org.mozilla.javascript.Context#executeScriptWithContinuations(Script, Scriptable)}
|
||||
* and {@link org.mozilla.javascript.Context#callFunctionWithContinuations(Callable, Scriptable, Object[])}
|
||||
* @param continuationState Internal Continuation object
|
||||
*/
|
||||
ContinuationPending(NativeContinuation continuationState) {
|
||||
this.continuationState = continuationState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get continuation object. The only
|
||||
* use for this object is to be passed to
|
||||
* {@link org.mozilla.javascript.Context#resumeContinuation(Object, Scriptable, Object)}.
|
||||
* @return continuation object
|
||||
*/
|
||||
public Object getContinuation() {
|
||||
return continuationState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return internal continuation state
|
||||
*/
|
||||
NativeContinuation getContinuationState() {
|
||||
return continuationState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an arbitrary object that applications can use to associate
|
||||
* their state with the continuation.
|
||||
* @param applicationState arbitrary application state
|
||||
*/
|
||||
public void setApplicationState(Object applicationState) {
|
||||
this.applicationState = applicationState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return arbitrary application state
|
||||
*/
|
||||
public Object getApplicationState() {
|
||||
return applicationState;
|
||||
}
|
||||
}
|
||||
@@ -1157,9 +1157,7 @@ class DToA {
|
||||
// while(*--s == '0') ;
|
||||
// s++;
|
||||
int bl = buf.length();
|
||||
while(bl-->0 && buf.charAt(bl) == '0') {
|
||||
// empty
|
||||
}
|
||||
while(bl-->0 && buf.charAt(bl) == '0');
|
||||
buf.setLength(bl + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
* Contributor(s):
|
||||
* Mike Ang
|
||||
* Igor Bukanov
|
||||
* Bob Jervis
|
||||
* Mike McCabe
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
@@ -41,8 +40,6 @@
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import org.mozilla.javascript.ast.FunctionNode;
|
||||
|
||||
/**
|
||||
* The following class save decompilation information about the source.
|
||||
* Source information is returned from the parser as a String
|
||||
@@ -356,15 +353,6 @@ public class Decompiler
|
||||
|
||||
while (i < length) {
|
||||
switch(source.charAt(i)) {
|
||||
case Token.GET:
|
||||
case Token.SET:
|
||||
result.append(source.charAt(i) == Token.GET ? "get " : "set ");
|
||||
++i;
|
||||
i = printSourceString(source, i + 1, false, result);
|
||||
// Now increment one more to get past the FUNCTION token
|
||||
++i;
|
||||
break;
|
||||
|
||||
case Token.NAME:
|
||||
case Token.REGEXP: // re-wrapped in '/'s in parser...
|
||||
i = printSourceString(source, i + 1, false, result);
|
||||
@@ -592,10 +580,6 @@ public class Decompiler
|
||||
result.append("var ");
|
||||
break;
|
||||
|
||||
case Token.LET:
|
||||
result.append("let ");
|
||||
break;
|
||||
|
||||
case Token.SEMI:
|
||||
result.append(';');
|
||||
if (Token.EOL != getNext(source, length, i)) {
|
||||
@@ -750,14 +734,6 @@ public class Decompiler
|
||||
result.append("void ");
|
||||
break;
|
||||
|
||||
case Token.CONST:
|
||||
result.append("const ");
|
||||
break;
|
||||
|
||||
case Token.YIELD:
|
||||
result.append("yield ");
|
||||
break;
|
||||
|
||||
case Token.NOT:
|
||||
result.append('!');
|
||||
break;
|
||||
@@ -820,8 +796,7 @@ public class Decompiler
|
||||
|
||||
default:
|
||||
// If we don't know how to decompile it, raise an exception.
|
||||
throw new RuntimeException("Token: " +
|
||||
Token.name(source.charAt(i)));
|
||||
throw new RuntimeException();
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
@@ -75,19 +75,8 @@ class DefaultErrorReporter implements ErrorReporter
|
||||
String lineText, int lineOffset)
|
||||
{
|
||||
if (forEval) {
|
||||
// Assume error message strings that start with "TypeError: "
|
||||
// should become TypeError exceptions. A bit of a hack, but we
|
||||
// don't want to change the ErrorReporter interface.
|
||||
String error = "SyntaxError";
|
||||
final String TYPE_ERROR_NAME = "TypeError";
|
||||
final String DELIMETER = ": ";
|
||||
final String prefix = TYPE_ERROR_NAME + DELIMETER;
|
||||
if (message.startsWith(prefix)) {
|
||||
error = TYPE_ERROR_NAME;
|
||||
message = message.substring(prefix.length());
|
||||
}
|
||||
throw ScriptRuntime.constructError(error, message, sourceURI,
|
||||
line, lineText, lineOffset);
|
||||
throw ScriptRuntime.constructError(
|
||||
"SyntaxError", message, sourceURI, line, lineText, lineOffset);
|
||||
}
|
||||
if (chainedReporter != null) {
|
||||
chainedReporter.error(
|
||||
|
||||
@@ -55,7 +55,7 @@ public class DefiningClassLoader extends ClassLoader
|
||||
this.parentLoader = parentLoader;
|
||||
}
|
||||
|
||||
public Class<?> defineClass(String name, byte[] data) {
|
||||
public Class defineClass(String name, byte[] data) {
|
||||
// Use our own protection domain for the generated classes.
|
||||
// TODO: we might want to use a separate protection domain for classes
|
||||
// compiled from scripts, based on where the script was loaded from.
|
||||
@@ -63,15 +63,14 @@ public class DefiningClassLoader extends ClassLoader
|
||||
SecurityUtilities.getProtectionDomain(getClass()));
|
||||
}
|
||||
|
||||
public void linkClass(Class<?> cl) {
|
||||
public void linkClass(Class cl) {
|
||||
resolveClass(cl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> loadClass(String name, boolean resolve)
|
||||
public Class loadClass(String name, boolean resolve)
|
||||
throws ClassNotFoundException
|
||||
{
|
||||
Class<?> cl = findLoadedClass(name);
|
||||
Class cl = findLoadedClass(name);
|
||||
if (cl == null) {
|
||||
if (parentLoader != null) {
|
||||
cl = parentLoader.loadClass(name);
|
||||
|
||||
@@ -89,7 +89,7 @@ public class Delegator implements Function {
|
||||
protected Delegator newInstance()
|
||||
{
|
||||
try {
|
||||
return this.getClass().newInstance();
|
||||
return (Delegator)this.getClass().newInstance();
|
||||
} catch (Exception ex) {
|
||||
throw Context.throwAsScriptRuntimeEx(ex);
|
||||
}
|
||||
@@ -119,49 +119,49 @@ public class Delegator implements Function {
|
||||
return obj.getClassName();
|
||||
}
|
||||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#get(String, Scriptable)
|
||||
* @see org.mozilla.javascript.Scriptable#get
|
||||
*/
|
||||
public Object get(String name, Scriptable start) {
|
||||
return obj.get(name,start);
|
||||
}
|
||||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#get(int, Scriptable)
|
||||
* @see org.mozilla.javascript.Scriptable#get
|
||||
*/
|
||||
public Object get(int index, Scriptable start) {
|
||||
return obj.get(index,start);
|
||||
}
|
||||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#has(String, Scriptable)
|
||||
* @see org.mozilla.javascript.Scriptable#has
|
||||
*/
|
||||
public boolean has(String name, Scriptable start) {
|
||||
return obj.has(name,start);
|
||||
}
|
||||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#has(int, Scriptable)
|
||||
* @see org.mozilla.javascript.Scriptable#has
|
||||
*/
|
||||
public boolean has(int index, Scriptable start) {
|
||||
return obj.has(index,start);
|
||||
}
|
||||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#put(String, Scriptable, Object)
|
||||
* @see org.mozilla.javascript.Scriptable#put
|
||||
*/
|
||||
public void put(String name, Scriptable start, Object value) {
|
||||
obj.put(name,start,value);
|
||||
}
|
||||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#put(int, Scriptable, Object)
|
||||
* @see org.mozilla.javascript.Scriptable#put
|
||||
*/
|
||||
public void put(int index, Scriptable start, Object value) {
|
||||
obj.put(index,start,value);
|
||||
}
|
||||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#delete(String)
|
||||
* @see org.mozilla.javascript.Scriptable#delete
|
||||
*/
|
||||
public void delete(String name) {
|
||||
obj.delete(name);
|
||||
}
|
||||
/**
|
||||
* @see org.mozilla.javascript.Scriptable#delete(int)
|
||||
* @see org.mozilla.javascript.Scriptable#delete
|
||||
*/
|
||||
public void delete(int index) {
|
||||
obj.delete(index);
|
||||
@@ -208,7 +208,7 @@ public class Delegator implements Function {
|
||||
*
|
||||
* @see org.mozilla.javascript.Scriptable#getDefaultValue
|
||||
*/
|
||||
public Object getDefaultValue(Class<?> hint) {
|
||||
public Object getDefaultValue(Class hint) {
|
||||
return (hint == null ||
|
||||
hint == ScriptRuntime.ScriptableClass ||
|
||||
hint == ScriptRuntime.FunctionClass) ?
|
||||
|
||||
@@ -57,7 +57,7 @@ public class EcmaError extends RhinoException
|
||||
* Errors internal to the JavaScript engine will simply throw a
|
||||
* RuntimeException.
|
||||
*
|
||||
* @param sourceName the name of the source responsible for the error
|
||||
* @param sourceName the name of the source reponsible for the error
|
||||
* @param lineNumber the line number of the source
|
||||
* @param columnNumber the columnNumber of the source (may be zero if
|
||||
* unknown)
|
||||
@@ -84,7 +84,6 @@ public class EcmaError extends RhinoException
|
||||
sourceName, lineNumber, lineSource, columnNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String details()
|
||||
{
|
||||
return errorName+": "+errorMessage;
|
||||
@@ -112,7 +111,7 @@ public class EcmaError extends RhinoException
|
||||
*
|
||||
* See ECMA edition 3, 15.11.7.10.
|
||||
*
|
||||
* @return an implementation-defined string describing the error.
|
||||
* @return an implemenation-defined string describing the error.
|
||||
*/
|
||||
public String getErrorMessage()
|
||||
{
|
||||
|
||||
@@ -1,120 +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.
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import org.mozilla.javascript.ast.ScriptNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstraction of evaluation, which can be implemented either by an
|
||||
* interpreter or compiler.
|
||||
*/
|
||||
public interface Evaluator {
|
||||
|
||||
/**
|
||||
* Compile the script or function from intermediate representation
|
||||
* tree into an executable form.
|
||||
*
|
||||
* @param compilerEnv Compiler environment
|
||||
* @param tree parse tree
|
||||
* @param encodedSource encoding of the source code for decompilation
|
||||
* @param returnFunction if true, compiling a function
|
||||
* @return an opaque object that can be passed to either
|
||||
* createFunctionObject or createScriptObject, depending on the
|
||||
* value of returnFunction
|
||||
*/
|
||||
public Object compile(CompilerEnvirons compilerEnv,
|
||||
ScriptNode tree,
|
||||
String encodedSource,
|
||||
boolean returnFunction);
|
||||
|
||||
/**
|
||||
* Create a function object.
|
||||
*
|
||||
* @param cx Current context
|
||||
* @param scope scope of the function
|
||||
* @param bytecode opaque object returned by compile
|
||||
* @param staticSecurityDomain security domain
|
||||
* @return Function object that can be called
|
||||
*/
|
||||
public Function createFunctionObject(Context cx, Scriptable scope,
|
||||
Object bytecode, Object staticSecurityDomain);
|
||||
|
||||
/**
|
||||
* Create a script object.
|
||||
*
|
||||
* @param bytecode opaque object returned by compile
|
||||
* @param staticSecurityDomain security domain
|
||||
* @return Script object that can be evaluated
|
||||
*/
|
||||
public Script createScriptObject(Object bytecode,
|
||||
Object staticSecurityDomain);
|
||||
|
||||
/**
|
||||
* Capture stack information from the given exception.
|
||||
* @param ex an exception thrown during execution
|
||||
*/
|
||||
public void captureStackInfo(RhinoException ex);
|
||||
|
||||
/**
|
||||
* Get the source position information by examining the stack.
|
||||
* @param cx Context
|
||||
* @param linep Array object of length >= 1; getSourcePositionFromStack
|
||||
* will assign the line number to linep[0].
|
||||
* @return the name of the file or other source container
|
||||
*/
|
||||
public String getSourcePositionFromStack(Context cx, int[] linep);
|
||||
|
||||
/**
|
||||
* Given a native stack trace, patch it with script-specific source
|
||||
* and line information
|
||||
* @param ex exception
|
||||
* @param nativeStackTrace the native stack trace
|
||||
* @return patched stack trace
|
||||
*/
|
||||
public String getPatchedStack(RhinoException ex,
|
||||
String nativeStackTrace);
|
||||
|
||||
/**
|
||||
* Get the script stack for the given exception
|
||||
* @param ex exception from execution
|
||||
* @return list of strings for the stack trace
|
||||
*/
|
||||
public List<String> getScriptStack(RhinoException ex);
|
||||
|
||||
/**
|
||||
* Mark the given script to indicate it was created by a call to
|
||||
* eval() or to a Function constructor.
|
||||
* @param script script to mark as from eval
|
||||
*/
|
||||
public void setEvalScriptFlag(Script script);
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class EvaluatorException extends RhinoException
|
||||
* RuntimeException.
|
||||
*
|
||||
* @param detail the error message
|
||||
* @param sourceName the name of the source responsible for the error
|
||||
* @param sourceName the name of the source reponsible for the error
|
||||
* @param lineNumber the line number of the source
|
||||
* @param columnNumber the columnNumber of the source (may be zero if
|
||||
* unknown)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
* Roger Lawrence
|
||||
*
|
||||
* 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
|
||||
@@ -38,56 +39,50 @@
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
/**
|
||||
* A wrapper for runtime exceptions.
|
||||
*
|
||||
* Used by the JavaScript runtime to wrap and propagate exceptions that occur
|
||||
* during runtime.
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
public class WrappedException extends EvaluatorException
|
||||
{
|
||||
static final long serialVersionUID = -1551979216966520648L;
|
||||
public class FunctionNode extends ScriptOrFnNode {
|
||||
|
||||
/**
|
||||
* @see Context#throwAsScriptRuntimeEx(Throwable e)
|
||||
*/
|
||||
public WrappedException(Throwable exception)
|
||||
{
|
||||
super("Wrapped "+exception.toString());
|
||||
this.exception = exception;
|
||||
Kit.initCause(this, exception);
|
||||
public FunctionNode(String name) {
|
||||
super(Token.FUNCTION);
|
||||
functionName = name;
|
||||
}
|
||||
|
||||
int[] linep = { 0 };
|
||||
String sourceName = Context.getSourcePositionFromStack(linep);
|
||||
int lineNumber = linep[0];
|
||||
if (sourceName != null) {
|
||||
initSourceName(sourceName);
|
||||
}
|
||||
if (lineNumber != 0) {
|
||||
initLineNumber(lineNumber);
|
||||
}
|
||||
public String getFunctionName() {
|
||||
return functionName;
|
||||
}
|
||||
|
||||
public boolean requiresActivation() {
|
||||
return itsNeedsActivation;
|
||||
}
|
||||
|
||||
public boolean getIgnoreDynamicScope() {
|
||||
return itsIgnoreDynamicScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wrapped exception.
|
||||
* There are three types of functions that can be defined. The first
|
||||
* is a function statement. This is a function appearing as a top-level
|
||||
* statement (i.e., not nested inside some other statement) in either a
|
||||
* script or a function.
|
||||
*
|
||||
* @return the exception that was presented as a argument to the
|
||||
* constructor when this object was created
|
||||
* The second is a function expression, which is a function appearing in
|
||||
* an expression except for the third type, which is...
|
||||
*
|
||||
* The third type is a function expression where the expression is the
|
||||
* top-level expression in an expression statement.
|
||||
*
|
||||
* The three types of functions have different treatment and must be
|
||||
* distinquished.
|
||||
*/
|
||||
public Throwable getWrappedException()
|
||||
{
|
||||
return exception;
|
||||
public static final int FUNCTION_STATEMENT = 1;
|
||||
public static final int FUNCTION_EXPRESSION = 2;
|
||||
public static final int FUNCTION_EXPRESSION_STATEMENT = 3;
|
||||
|
||||
public int getFunctionType() {
|
||||
return itsFunctionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getWrappedException()} instead.
|
||||
*/
|
||||
public Object unwrap()
|
||||
{
|
||||
return getWrappedException();
|
||||
}
|
||||
|
||||
private Throwable exception;
|
||||
String functionName;
|
||||
boolean itsNeedsActivation;
|
||||
int itsFunctionType;
|
||||
boolean itsIgnoreDynamicScope;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class FunctionObject extends BaseFunction
|
||||
Scriptable scope)
|
||||
{
|
||||
if (methodOrConstructor instanceof Constructor) {
|
||||
member = new MemberBox((Constructor<?>) methodOrConstructor);
|
||||
member = new MemberBox((Constructor) methodOrConstructor);
|
||||
isStatic = true; // well, doesn't take a 'this'
|
||||
} else {
|
||||
member = new MemberBox((Method) methodOrConstructor);
|
||||
@@ -126,7 +126,7 @@ public class FunctionObject extends BaseFunction
|
||||
}
|
||||
String methodName = member.getName();
|
||||
this.functionName = name;
|
||||
Class<?>[] types = member.argTypes;
|
||||
Class[] types = member.argTypes;
|
||||
int arity = types.length;
|
||||
if (arity == 4 && (types[1].isArray() || types[2].isArray())) {
|
||||
// Either variable args or an error.
|
||||
@@ -170,14 +170,14 @@ public class FunctionObject extends BaseFunction
|
||||
|
||||
if (member.isMethod()) {
|
||||
Method method = member.method();
|
||||
Class<?> returnType = method.getReturnType();
|
||||
Class returnType = method.getReturnType();
|
||||
if (returnType == Void.TYPE) {
|
||||
hasVoidReturn = true;
|
||||
} else {
|
||||
returnTypeTag = getTypeTag(returnType);
|
||||
}
|
||||
} else {
|
||||
Class<?> ctorType = member.getDeclaringClass();
|
||||
Class ctorType = member.getDeclaringClass();
|
||||
if (!ScriptRuntime.ScriptableClass.isAssignableFrom(ctorType)) {
|
||||
throw Context.reportRuntimeError1(
|
||||
"msg.bad.ctor.return", ctorType.getName());
|
||||
@@ -192,7 +192,7 @@ public class FunctionObject extends BaseFunction
|
||||
* or {@link #JAVA_UNSUPPORTED_TYPE} if the convertion is not
|
||||
* possible
|
||||
*/
|
||||
public static int getTypeTag(Class<?> type)
|
||||
public static int getTypeTag(Class type)
|
||||
{
|
||||
if (type == ScriptRuntime.StringClass)
|
||||
return JAVA_STRING_TYPE;
|
||||
@@ -224,7 +224,7 @@ public class FunctionObject extends BaseFunction
|
||||
case JAVA_INT_TYPE:
|
||||
if (arg instanceof Integer)
|
||||
return arg;
|
||||
return Integer.valueOf(ScriptRuntime.toInt32(arg));
|
||||
return new Integer(ScriptRuntime.toInt32(arg));
|
||||
case JAVA_BOOLEAN_TYPE:
|
||||
if (arg instanceof Boolean)
|
||||
return arg;
|
||||
@@ -235,7 +235,9 @@ public class FunctionObject extends BaseFunction
|
||||
return arg;
|
||||
return new Double(ScriptRuntime.toNumber(arg));
|
||||
case JAVA_SCRIPTABLE_TYPE:
|
||||
return ScriptRuntime.toObjectOrNull(cx, arg, scope);
|
||||
if (arg instanceof Scriptable)
|
||||
return arg;
|
||||
return ScriptRuntime.toObject(cx, scope, arg);
|
||||
case JAVA_OBJECT_TYPE:
|
||||
return arg;
|
||||
default:
|
||||
@@ -248,7 +250,6 @@ public class FunctionObject extends BaseFunction
|
||||
* (number of parameters of the method, or 1 if the method is a "varargs"
|
||||
* form).
|
||||
*/
|
||||
@Override
|
||||
public int getArity() {
|
||||
return parmsLength < 0 ? 1 : parmsLength;
|
||||
}
|
||||
@@ -256,12 +257,10 @@ public class FunctionObject extends BaseFunction
|
||||
/**
|
||||
* Return the same value as {@link #getArity()}.
|
||||
*/
|
||||
@Override
|
||||
public int getLength() {
|
||||
return getArity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFunctionName()
|
||||
{
|
||||
return (functionName == null) ? "" : functionName;
|
||||
@@ -304,7 +303,7 @@ public class FunctionObject extends BaseFunction
|
||||
* @return the public methods declared in the specified class
|
||||
* @see Class#getDeclaredMethods()
|
||||
*/
|
||||
static Method[] getMethodList(Class<?> clazz) {
|
||||
static Method[] getMethodList(Class clazz) {
|
||||
Method[] methods = null;
|
||||
try {
|
||||
// getDeclaredMethods may be rejected by the security manager
|
||||
@@ -378,10 +377,10 @@ public class FunctionObject extends BaseFunction
|
||||
/**
|
||||
* @deprecated Use {@link #getTypeTag(Class)}
|
||||
* and {@link #convertArg(Context, Scriptable, Object, int)}
|
||||
* for type conversion.
|
||||
* for type convertion.
|
||||
*/
|
||||
public static Object convertArg(Context cx, Scriptable scope,
|
||||
Object arg, Class<?> desired)
|
||||
Object arg, Class desired)
|
||||
{
|
||||
int tag = getTypeTag(desired);
|
||||
if (tag == JAVA_UNSUPPORTED_TYPE) {
|
||||
@@ -400,7 +399,6 @@ public class FunctionObject extends BaseFunction
|
||||
* @see org.mozilla.javascript.Function#call(
|
||||
* Context, Scriptable, Scriptable, Object[])
|
||||
*/
|
||||
@Override
|
||||
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
|
||||
Object[] args)
|
||||
{
|
||||
@@ -423,7 +421,7 @@ public class FunctionObject extends BaseFunction
|
||||
|
||||
} else {
|
||||
if (!isStatic) {
|
||||
Class<?> clazz = member.getDeclaringClass();
|
||||
Class clazz = member.getDeclaringClass();
|
||||
if (!clazz.isInstance(thisObj)) {
|
||||
boolean compatible = false;
|
||||
if (thisObj == scope) {
|
||||
@@ -455,7 +453,7 @@ public class FunctionObject extends BaseFunction
|
||||
Object converted = convertArg(cx, scope, arg, typeTags[i]);
|
||||
if (arg != converted) {
|
||||
if (invokeArgs == args) {
|
||||
invokeArgs = args.clone();
|
||||
invokeArgs = (Object[])args.clone();
|
||||
}
|
||||
invokeArgs[i] = converted;
|
||||
}
|
||||
@@ -502,7 +500,6 @@ public class FunctionObject extends BaseFunction
|
||||
* Return null to indicate that the call method should be used to create
|
||||
* new objects.
|
||||
*/
|
||||
@Override
|
||||
public Scriptable createObject(Context cx, Scriptable scope) {
|
||||
if (member.isCtor() || parmsLength == VARARGS_CTOR) {
|
||||
return null;
|
||||
@@ -532,7 +529,7 @@ public class FunctionObject extends BaseFunction
|
||||
{
|
||||
in.defaultReadObject();
|
||||
if (parmsLength > 0) {
|
||||
Class<?>[] types = member.argTypes;
|
||||
Class[] types = member.argTypes;
|
||||
typeTags = new byte[parmsLength];
|
||||
for (int i = 0; i != parmsLength; ++i) {
|
||||
typeTags[i] = (byte)getTypeTag(types[i]);
|
||||
@@ -540,7 +537,7 @@ public class FunctionObject extends BaseFunction
|
||||
}
|
||||
if (member.isMethod()) {
|
||||
Method method = member.method();
|
||||
Class<?> returnType = method.getReturnType();
|
||||
Class returnType = method.getReturnType();
|
||||
if (returnType == Void.TYPE) {
|
||||
hasVoidReturn = true;
|
||||
} else {
|
||||
|
||||
@@ -53,14 +53,14 @@ public interface GeneratedClassLoader {
|
||||
* @param data class byte code
|
||||
* @return new class object
|
||||
*/
|
||||
public Class<?> defineClass(String name, byte[] data);
|
||||
public Class defineClass(String name, byte[] data);
|
||||
|
||||
/**
|
||||
* Link the given class.
|
||||
*
|
||||
* @param cl Class instance returned from the previous call to
|
||||
* {@link #defineClass(String, byte[])}
|
||||
* @see java.lang.ClassLoader
|
||||
* @see java.lang.ClassLoader#resolveClass(Class)
|
||||
*/
|
||||
public void linkClass(Class<?> cl);
|
||||
public void linkClass(Class cl);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,279 +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):
|
||||
* Mike Ang
|
||||
* Igor Bukanov
|
||||
* Yuh-Ruey Chen
|
||||
* Ethan Hugg
|
||||
* Bob Jervis
|
||||
* Terry Lucas
|
||||
* Mike McCabe
|
||||
* Milen Nankov
|
||||
* Norris Boyd
|
||||
* Steve Yegge
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Additional interpreter-specific codes
|
||||
*/
|
||||
abstract class Icode {
|
||||
|
||||
static final int
|
||||
|
||||
// Stack: ... value1 -> ... value1 value1
|
||||
Icode_DUP = -1,
|
||||
|
||||
// Stack: ... value2 value1 -> ... value2 value1 value2 value1
|
||||
Icode_DUP2 = -2,
|
||||
|
||||
// Stack: ... value2 value1 -> ... value1 value2
|
||||
Icode_SWAP = -3,
|
||||
|
||||
// Stack: ... value1 -> ...
|
||||
Icode_POP = -4,
|
||||
|
||||
// Store stack top into return register and then pop it
|
||||
Icode_POP_RESULT = -5,
|
||||
|
||||
// To jump conditionally and pop additional stack value
|
||||
Icode_IFEQ_POP = -6,
|
||||
|
||||
// various types of ++/--
|
||||
Icode_VAR_INC_DEC = -7,
|
||||
Icode_NAME_INC_DEC = -8,
|
||||
Icode_PROP_INC_DEC = -9,
|
||||
Icode_ELEM_INC_DEC = -10,
|
||||
Icode_REF_INC_DEC = -11,
|
||||
|
||||
// load/save scope from/to local
|
||||
Icode_SCOPE_LOAD = -12,
|
||||
Icode_SCOPE_SAVE = -13,
|
||||
|
||||
Icode_TYPEOFNAME = -14,
|
||||
|
||||
// helper for function calls
|
||||
Icode_NAME_AND_THIS = -15,
|
||||
Icode_PROP_AND_THIS = -16,
|
||||
Icode_ELEM_AND_THIS = -17,
|
||||
Icode_VALUE_AND_THIS = -18,
|
||||
|
||||
// Create closure object for nested functions
|
||||
Icode_CLOSURE_EXPR = -19,
|
||||
Icode_CLOSURE_STMT = -20,
|
||||
|
||||
// Special calls
|
||||
Icode_CALLSPECIAL = -21,
|
||||
|
||||
// To return undefined value
|
||||
Icode_RETUNDEF = -22,
|
||||
|
||||
// Exception handling implementation
|
||||
Icode_GOSUB = -23,
|
||||
Icode_STARTSUB = -24,
|
||||
Icode_RETSUB = -25,
|
||||
|
||||
// To indicating a line number change in icodes.
|
||||
Icode_LINE = -26,
|
||||
|
||||
// To store shorts and ints inline
|
||||
Icode_SHORTNUMBER = -27,
|
||||
Icode_INTNUMBER = -28,
|
||||
|
||||
// To create and populate array to hold values for [] and {} literals
|
||||
Icode_LITERAL_NEW = -29,
|
||||
Icode_LITERAL_SET = -30,
|
||||
|
||||
// Array literal with skipped index like [1,,2]
|
||||
Icode_SPARE_ARRAYLIT = -31,
|
||||
|
||||
// Load index register to prepare for the following index operation
|
||||
Icode_REG_IND_C0 = -32,
|
||||
Icode_REG_IND_C1 = -33,
|
||||
Icode_REG_IND_C2 = -34,
|
||||
Icode_REG_IND_C3 = -35,
|
||||
Icode_REG_IND_C4 = -36,
|
||||
Icode_REG_IND_C5 = -37,
|
||||
Icode_REG_IND1 = -38,
|
||||
Icode_REG_IND2 = -39,
|
||||
Icode_REG_IND4 = -40,
|
||||
|
||||
// Load string register to prepare for the following string operation
|
||||
Icode_REG_STR_C0 = -41,
|
||||
Icode_REG_STR_C1 = -42,
|
||||
Icode_REG_STR_C2 = -43,
|
||||
Icode_REG_STR_C3 = -44,
|
||||
Icode_REG_STR1 = -45,
|
||||
Icode_REG_STR2 = -46,
|
||||
Icode_REG_STR4 = -47,
|
||||
|
||||
// Version of getvar/setvar that read var index directly from bytecode
|
||||
Icode_GETVAR1 = -48,
|
||||
Icode_SETVAR1 = -49,
|
||||
|
||||
// Load unefined
|
||||
Icode_UNDEF = -50,
|
||||
Icode_ZERO = -51,
|
||||
Icode_ONE = -52,
|
||||
|
||||
// entrance and exit from .()
|
||||
Icode_ENTERDQ = -53,
|
||||
Icode_LEAVEDQ = -54,
|
||||
|
||||
Icode_TAIL_CALL = -55,
|
||||
|
||||
// Clear local to allow GC its context
|
||||
Icode_LOCAL_CLEAR = -56,
|
||||
|
||||
// Literal get/set
|
||||
Icode_LITERAL_GETTER = -57,
|
||||
Icode_LITERAL_SETTER = -58,
|
||||
|
||||
// const
|
||||
Icode_SETCONST = -59,
|
||||
Icode_SETCONSTVAR = -60,
|
||||
Icode_SETCONSTVAR1 = -61,
|
||||
|
||||
// Generator opcodes (along with Token.YIELD)
|
||||
Icode_GENERATOR = -62,
|
||||
Icode_GENERATOR_END = -63,
|
||||
|
||||
Icode_DEBUGGER = -64,
|
||||
|
||||
// Last icode
|
||||
MIN_ICODE = -64;
|
||||
|
||||
static String bytecodeName(int bytecode)
|
||||
{
|
||||
if (!validBytecode(bytecode)) {
|
||||
throw new IllegalArgumentException(String.valueOf(bytecode));
|
||||
}
|
||||
|
||||
if (!Token.printICode) {
|
||||
return String.valueOf(bytecode);
|
||||
}
|
||||
|
||||
if (validTokenCode(bytecode)) {
|
||||
return Token.name(bytecode);
|
||||
}
|
||||
|
||||
switch (bytecode) {
|
||||
case Icode_DUP: return "DUP";
|
||||
case Icode_DUP2: return "DUP2";
|
||||
case Icode_SWAP: return "SWAP";
|
||||
case Icode_POP: return "POP";
|
||||
case Icode_POP_RESULT: return "POP_RESULT";
|
||||
case Icode_IFEQ_POP: return "IFEQ_POP";
|
||||
case Icode_VAR_INC_DEC: return "VAR_INC_DEC";
|
||||
case Icode_NAME_INC_DEC: return "NAME_INC_DEC";
|
||||
case Icode_PROP_INC_DEC: return "PROP_INC_DEC";
|
||||
case Icode_ELEM_INC_DEC: return "ELEM_INC_DEC";
|
||||
case Icode_REF_INC_DEC: return "REF_INC_DEC";
|
||||
case Icode_SCOPE_LOAD: return "SCOPE_LOAD";
|
||||
case Icode_SCOPE_SAVE: return "SCOPE_SAVE";
|
||||
case Icode_TYPEOFNAME: return "TYPEOFNAME";
|
||||
case Icode_NAME_AND_THIS: return "NAME_AND_THIS";
|
||||
case Icode_PROP_AND_THIS: return "PROP_AND_THIS";
|
||||
case Icode_ELEM_AND_THIS: return "ELEM_AND_THIS";
|
||||
case Icode_VALUE_AND_THIS: return "VALUE_AND_THIS";
|
||||
case Icode_CLOSURE_EXPR: return "CLOSURE_EXPR";
|
||||
case Icode_CLOSURE_STMT: return "CLOSURE_STMT";
|
||||
case Icode_CALLSPECIAL: return "CALLSPECIAL";
|
||||
case Icode_RETUNDEF: return "RETUNDEF";
|
||||
case Icode_GOSUB: return "GOSUB";
|
||||
case Icode_STARTSUB: return "STARTSUB";
|
||||
case Icode_RETSUB: return "RETSUB";
|
||||
case Icode_LINE: return "LINE";
|
||||
case Icode_SHORTNUMBER: return "SHORTNUMBER";
|
||||
case Icode_INTNUMBER: return "INTNUMBER";
|
||||
case Icode_LITERAL_NEW: return "LITERAL_NEW";
|
||||
case Icode_LITERAL_SET: return "LITERAL_SET";
|
||||
case Icode_SPARE_ARRAYLIT: return "SPARE_ARRAYLIT";
|
||||
case Icode_REG_IND_C0: return "REG_IND_C0";
|
||||
case Icode_REG_IND_C1: return "REG_IND_C1";
|
||||
case Icode_REG_IND_C2: return "REG_IND_C2";
|
||||
case Icode_REG_IND_C3: return "REG_IND_C3";
|
||||
case Icode_REG_IND_C4: return "REG_IND_C4";
|
||||
case Icode_REG_IND_C5: return "REG_IND_C5";
|
||||
case Icode_REG_IND1: return "LOAD_IND1";
|
||||
case Icode_REG_IND2: return "LOAD_IND2";
|
||||
case Icode_REG_IND4: return "LOAD_IND4";
|
||||
case Icode_REG_STR_C0: return "REG_STR_C0";
|
||||
case Icode_REG_STR_C1: return "REG_STR_C1";
|
||||
case Icode_REG_STR_C2: return "REG_STR_C2";
|
||||
case Icode_REG_STR_C3: return "REG_STR_C3";
|
||||
case Icode_REG_STR1: return "LOAD_STR1";
|
||||
case Icode_REG_STR2: return "LOAD_STR2";
|
||||
case Icode_REG_STR4: return "LOAD_STR4";
|
||||
case Icode_GETVAR1: return "GETVAR1";
|
||||
case Icode_SETVAR1: return "SETVAR1";
|
||||
case Icode_UNDEF: return "UNDEF";
|
||||
case Icode_ZERO: return "ZERO";
|
||||
case Icode_ONE: return "ONE";
|
||||
case Icode_ENTERDQ: return "ENTERDQ";
|
||||
case Icode_LEAVEDQ: return "LEAVEDQ";
|
||||
case Icode_TAIL_CALL: return "TAIL_CALL";
|
||||
case Icode_LOCAL_CLEAR: return "LOCAL_CLEAR";
|
||||
case Icode_LITERAL_GETTER: return "LITERAL_GETTER";
|
||||
case Icode_LITERAL_SETTER: return "LITERAL_SETTER";
|
||||
case Icode_SETCONST: return "SETCONST";
|
||||
case Icode_SETCONSTVAR: return "SETCONSTVAR";
|
||||
case Icode_SETCONSTVAR1: return "SETCONSTVAR1";
|
||||
case Icode_GENERATOR: return "GENERATOR";
|
||||
case Icode_GENERATOR_END: return "GENERATOR_END";
|
||||
case Icode_DEBUGGER: return "DEBUGGER";
|
||||
}
|
||||
|
||||
// icode without name
|
||||
throw new IllegalStateException(String.valueOf(bytecode));
|
||||
}
|
||||
|
||||
static boolean validIcode(int icode)
|
||||
{
|
||||
return MIN_ICODE <= icode && icode <= -1;
|
||||
}
|
||||
|
||||
static boolean validTokenCode(int token)
|
||||
{
|
||||
return Token.FIRST_BYTECODE_TOKEN <= token
|
||||
&& token <= Token.LAST_BYTECODE_TOKEN;
|
||||
}
|
||||
|
||||
static boolean validBytecode(int bytecode)
|
||||
{
|
||||
return validIcode(bytecode) || validTokenCode(bytecode);
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,6 @@ public class IdFunctionObject extends BaseFunction
|
||||
addAsProperty(getParentScope());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scriptable getPrototype()
|
||||
{
|
||||
// Lazy initialization of prototype: for native functions this
|
||||
@@ -122,14 +121,12 @@ public class IdFunctionObject extends BaseFunction
|
||||
return proto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
|
||||
Object[] args)
|
||||
{
|
||||
return idcall.execIdCall(this, cx, scope, thisObj, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scriptable createObject(Context cx, Scriptable scope)
|
||||
{
|
||||
if (useCallAsConstructor) {
|
||||
@@ -142,7 +139,6 @@ public class IdFunctionObject extends BaseFunction
|
||||
throw ScriptRuntime.typeError1("msg.not.ctor", functionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
String decompile(int indent, int flags)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
@@ -165,16 +161,13 @@ public class IdFunctionObject extends BaseFunction
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArity()
|
||||
{
|
||||
return arity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() { return getArity(); }
|
||||
|
||||
@Override
|
||||
public String getFunctionName()
|
||||
{
|
||||
return (functionName == null) ? "" : functionName;
|
||||
|
||||
@@ -349,7 +349,6 @@ public abstract class IdScriptableObject extends ScriptableObject
|
||||
super.put(name, this, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(String name, Scriptable start)
|
||||
{
|
||||
int info = findInstanceIdInfo(name);
|
||||
@@ -370,7 +369,6 @@ public abstract class IdScriptableObject extends ScriptableObject
|
||||
return super.has(name, start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String name, Scriptable start)
|
||||
{
|
||||
int info = findInstanceIdInfo(name);
|
||||
@@ -387,7 +385,6 @@ public abstract class IdScriptableObject extends ScriptableObject
|
||||
return super.get(name, start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(String name, Scriptable start, Object value)
|
||||
{
|
||||
int info = findInstanceIdInfo(name);
|
||||
@@ -422,7 +419,6 @@ public abstract class IdScriptableObject extends ScriptableObject
|
||||
super.put(name, start, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String name)
|
||||
{
|
||||
int info = findInstanceIdInfo(name);
|
||||
@@ -449,7 +445,6 @@ public abstract class IdScriptableObject extends ScriptableObject
|
||||
super.delete(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAttributes(String name)
|
||||
{
|
||||
int info = findInstanceIdInfo(name);
|
||||
@@ -466,7 +461,6 @@ public abstract class IdScriptableObject extends ScriptableObject
|
||||
return super.getAttributes(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttributes(String name, int attributes)
|
||||
{
|
||||
ScriptableObject.checkValidAttributes(attributes);
|
||||
@@ -489,7 +483,6 @@ public abstract class IdScriptableObject extends ScriptableObject
|
||||
super.setAttributes(name, attributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
Object[] getIds(boolean getAll)
|
||||
{
|
||||
Object[] result = super.getIds(getAll);
|
||||
@@ -695,7 +688,7 @@ public abstract class IdScriptableObject extends ScriptableObject
|
||||
* </pre>
|
||||
* Note that although such function can be implemented universally via
|
||||
* java.lang.Class.isInstance(), it would be much more slower.
|
||||
* @param f function that is attempting to convert 'this'
|
||||
* @param readOnly specify if the function f does not change state of
|
||||
* object.
|
||||
* @return Scriptable object suitable for a check by the instanceof
|
||||
* operator.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user