Compare commits
10 Commits
SQL_ADDON_
...
EXP_DEBUGG
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4ffa41ca0 | ||
|
|
71eac19bd9 | ||
|
|
c91ef3e25d | ||
|
|
d912f6c544 | ||
|
|
f066ed34eb | ||
|
|
75c0a6d536 | ||
|
|
6374a47cb5 | ||
|
|
87a77bdb54 | ||
|
|
01bdc9a81a | ||
|
|
cf3aa1ee61 |
@@ -1,19 +0,0 @@
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = \
|
||||
base \
|
||||
pgsql \
|
||||
build
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += \
|
||||
sqltest \
|
||||
tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,11 +0,0 @@
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
DIRS = \
|
||||
public \
|
||||
src \
|
||||
resources
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,19 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
MODULE = sql
|
||||
|
||||
XPIDLSRCS = \
|
||||
mozISqlConnection.idl \
|
||||
mozISqlRequest.idl \
|
||||
mozISqlDataSource.idl \
|
||||
mozISqlInputStream.idl \
|
||||
mozISqlRequestObserver.idl \
|
||||
mozISqlResult.idl \
|
||||
mozISqlResultEnumerator.idl \
|
||||
mozISqlService.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,124 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozISqlResult;
|
||||
interface mozISqlRequest;
|
||||
interface mozISqlRequestObserver;
|
||||
|
||||
/**
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
[scriptable, uuid(f16397a4-1ecb-4e08-84f8-27750c04b779)]
|
||||
interface mozISqlConnection : nsISupports
|
||||
{
|
||||
|
||||
readonly attribute AString serverVersion;
|
||||
|
||||
/**
|
||||
* The most recent error message.
|
||||
*/
|
||||
readonly attribute AString errorMessage;
|
||||
|
||||
/**
|
||||
* The ID of the most recently added record.
|
||||
*/
|
||||
readonly attribute long lastID;
|
||||
|
||||
/**
|
||||
* Set up the connection.
|
||||
*
|
||||
* @param aHost The host name.
|
||||
* @param aPort The port at which the host is listening.
|
||||
* @param aDatabase The real database name to connect to.
|
||||
* @param aUsername The username to connect as.
|
||||
* @param aPassword The password to use in authentification phase.
|
||||
*/
|
||||
void init(in AString aHost,
|
||||
in long aPort,
|
||||
in AString aDatabase,
|
||||
in AString aUsername,
|
||||
in AString aPassword);
|
||||
|
||||
/**
|
||||
* Execute the query synchronously and return database result.
|
||||
*
|
||||
* @param aQuery The query to execute.
|
||||
*/
|
||||
mozISqlResult executeQuery(in AString aQuery);
|
||||
|
||||
/**
|
||||
* Execute the update synchronously and return number of updated rows.
|
||||
*
|
||||
* @param aUpdate The update to execute.
|
||||
*/
|
||||
long executeUpdate(in AString aUpdate);
|
||||
|
||||
mozISqlRequest asyncExecuteQuery(in AString aQuery,
|
||||
in nsISupports aContext,
|
||||
in mozISqlRequestObserver aObserver);
|
||||
|
||||
mozISqlRequest asyncExecuteUpdate(in AString aQuery,
|
||||
in nsISUpports aContext,
|
||||
in mozISqlRequestObserver aObserver);
|
||||
|
||||
/**
|
||||
* Begin transaction.
|
||||
*/
|
||||
void beginTransaction();
|
||||
|
||||
/**
|
||||
* Commit transaction.
|
||||
*/
|
||||
void commitTransaction();
|
||||
|
||||
/**
|
||||
* Rollback transaction.
|
||||
*/
|
||||
void rollbackTransaction();
|
||||
|
||||
/**
|
||||
* Get primary keys.
|
||||
*
|
||||
* @param aSchema The schema.
|
||||
* @param aTable The table name.
|
||||
*/
|
||||
mozISqlResult getPrimaryKeys(in AString aSchema, in AString aTable);
|
||||
|
||||
};
|
||||
@@ -1,65 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIRDFResource;
|
||||
|
||||
/**
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
[scriptable, uuid(3c0a954f-b595-46a4-932c-3660f55e2e10)]
|
||||
interface mozISqlDataSource : nsISupports
|
||||
{
|
||||
|
||||
/**
|
||||
* Retrieve the RDF resource associated with the specified row.
|
||||
*
|
||||
* @param aRowIndex The row index.
|
||||
*/
|
||||
|
||||
nsIRDFResource getResourceAtIndex(in long aRowIndex);
|
||||
|
||||
/**
|
||||
* Retrieve the index associated with specified RDF resource.
|
||||
*
|
||||
* @param aResource The resource.
|
||||
*/
|
||||
long getIndexOfResource(in nsIRDFResource aResource);
|
||||
|
||||
};
|
||||
@@ -1,52 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/**
|
||||
* @status UNDER_DEVELOPMENT
|
||||
*/
|
||||
|
||||
[scriptable, uuid(555f2485-ba82-4c5c-9dd2-d801104dc09e)]
|
||||
interface mozISqlInputStream : nsISupports
|
||||
{
|
||||
|
||||
AString getColumnHeader(in long aColumnIndex);
|
||||
|
||||
void setColumnHeader(in long aColumnIndex, in AString aLabel);
|
||||
|
||||
};
|
||||
@@ -1,77 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozISqlConnection;
|
||||
interface mozISqlRequestObserver;
|
||||
interface mozISqlResult;
|
||||
|
||||
/**
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
[scriptable, uuid(f67cb817-5e07-49ff-aacc-5c80585c5031)]
|
||||
interface mozISqlRequest : nsISupports
|
||||
{
|
||||
readonly attribute AString errorMessage;
|
||||
|
||||
readonly attribute mozISqlResult result;
|
||||
|
||||
readonly attribute long affectedRows;
|
||||
|
||||
readonly attribute long lastID;
|
||||
|
||||
|
||||
readonly attribute AString query;
|
||||
|
||||
readonly attribute nsISupports ctxt;
|
||||
|
||||
readonly attribute mozISqlRequestObserver observer;
|
||||
|
||||
|
||||
const long STATUS_NONE = 0;
|
||||
const long STATUS_EXECUTED = 1;
|
||||
const long STATUS_COMPLETE = 2;
|
||||
const long STATUS_ERROR = 3;
|
||||
const long STATUS_CANCELLED = 4;
|
||||
|
||||
readonly attribute long status;
|
||||
|
||||
void cancel();
|
||||
|
||||
};
|
||||
@@ -1,56 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozISqlRequest;
|
||||
|
||||
/**
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
[scriptable, uuid(9e950bc0-e252-41ef-ac6f-3e3c4acd9dd8)]
|
||||
interface mozISqlRequestObserver : nsISupports
|
||||
{
|
||||
|
||||
void onStartRequest(in mozISqlRequest aRequest,
|
||||
in nsISupports aContext);
|
||||
|
||||
void onStopRequest(in mozISqlRequest aRequest,
|
||||
in nsISupports aContext);
|
||||
|
||||
};
|
||||
@@ -1,87 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozISqlConnection;
|
||||
interface mozISqlResultEnumerator;
|
||||
interface mozISqlInputStream;
|
||||
|
||||
/**
|
||||
* @status UNDER_DEVELOPMENT
|
||||
*/
|
||||
|
||||
[scriptable, uuid(08c220b0-7140-456a-89e9-c94609a7392d)]
|
||||
interface mozISqlResult : nsISupports
|
||||
{
|
||||
|
||||
readonly attribute mozISqlConnection connection;
|
||||
|
||||
readonly attribute AString query;
|
||||
|
||||
readonly attribute AString tableName;
|
||||
|
||||
readonly attribute long rowCount;
|
||||
|
||||
readonly attribute long columnCount;
|
||||
|
||||
AString getColumnName(in long aColumnIndex);
|
||||
|
||||
long getColumnIndex(in AString aColumnName);
|
||||
|
||||
const long TYPE_STRING = 1;
|
||||
const long TYPE_INT = 2;
|
||||
const long TYPE_FLOAT = 3;
|
||||
const long TYPE_DECIMAL = 4;
|
||||
const long TYPE_DATE = 5;
|
||||
const long TYPE_TIME = 6;
|
||||
const long TYPE_DATETIME = 7;
|
||||
const long TYPE_BOOL = 8;
|
||||
|
||||
long getColumnType(in long aColumnIndex);
|
||||
|
||||
AString getColumnTypeAsString(in long aColumnIndex);
|
||||
|
||||
long getColumnDisplaySize(in long aColumnIndex);
|
||||
|
||||
mozISqlResultEnumerator enumerate();
|
||||
|
||||
mozISqlInputStream open();
|
||||
|
||||
void reload();
|
||||
|
||||
};
|
||||
@@ -1,126 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIVariant;
|
||||
|
||||
/**
|
||||
* @status UNDER_DEVELOPMENT
|
||||
*/
|
||||
|
||||
[scriptable, uuid(dcc0d29e-2b44-460e-b39f-89121ff8b963)]
|
||||
interface mozISqlResultEnumerator : nsISupports
|
||||
{
|
||||
|
||||
readonly attribute AString errorMessage;
|
||||
|
||||
boolean next();
|
||||
|
||||
boolean previous();
|
||||
|
||||
void beforeFirst();
|
||||
|
||||
void first();
|
||||
|
||||
void last();
|
||||
|
||||
void relative(in long aRows);
|
||||
|
||||
void absolute(in long aRowIndex);
|
||||
|
||||
|
||||
boolean isNull(in long aColumnIndex);
|
||||
|
||||
nsIVariant getVariant(in long aColumnIndex);
|
||||
|
||||
AString getString(in long aColumnIndex);
|
||||
|
||||
long getInt(in long aColumnIndex);
|
||||
|
||||
float getFloat(in long aColumnIndex);
|
||||
|
||||
float getDecimal(in long aColumnIndex);
|
||||
|
||||
long long getDate(in long aColumnIndex);
|
||||
|
||||
boolean getBool(in long aColumnIndex);
|
||||
|
||||
|
||||
void setNull(in long aColumnIndex);
|
||||
|
||||
void setDefault(in long aColumnIndex);
|
||||
|
||||
void copy(in long aColumnIndex);
|
||||
|
||||
void setVariant(in long aColumnIndex, in nsIVariant aValue);
|
||||
|
||||
void setString(in long aColumnIndex, in AString aValue);
|
||||
|
||||
void setInt(in long aColumnIndex, in long aValue);
|
||||
|
||||
void setFloat(in long aColumnIndex, in float aValue);
|
||||
|
||||
void setDecimal(in long aColumnIndex, in float aValue);
|
||||
|
||||
void setDate(in long aColumnIndex, in long long aValue);
|
||||
|
||||
void setBool(in long aColumnIndex, in boolean aValue);
|
||||
|
||||
|
||||
void setNullValues();
|
||||
|
||||
void setDefaultValues();
|
||||
|
||||
void copyValues();
|
||||
|
||||
|
||||
boolean canInsert();
|
||||
|
||||
boolean canUpdate();
|
||||
|
||||
boolean canDelete();
|
||||
|
||||
long insertRow();
|
||||
|
||||
long updateRow();
|
||||
|
||||
long deleteRow();
|
||||
|
||||
readonly attribute AString currentCondition;
|
||||
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jan Varga <varga@utcru.sk>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozISqlConnection;
|
||||
|
||||
/**
|
||||
* @status UNDER_DEVELOPMENT
|
||||
*/
|
||||
|
||||
[scriptable, uuid(1ceb35b7-daa8-4ce4-ac67-125fb17cb019)]
|
||||
interface mozISqlService : nsISupports
|
||||
{
|
||||
|
||||
readonly attribute AString errorMessage;
|
||||
|
||||
void addAlias(in ACString aURI,
|
||||
in AString aName,
|
||||
in AString aType,
|
||||
in AString aHostname,
|
||||
in long aPort,
|
||||
in AString aDatabase);
|
||||
|
||||
boolean hasAlias(in ACString aURI);
|
||||
|
||||
void getAlias(in ACString aURI,
|
||||
out AString aName,
|
||||
out AString aType,
|
||||
out AString aHostname,
|
||||
out long aPort,
|
||||
out AString aDatabase);
|
||||
|
||||
void updateAlias(in ACString aURI,
|
||||
in AString aName,
|
||||
in AString aType,
|
||||
in AString aHostname,
|
||||
in long aPort,
|
||||
in AString aDatabase);
|
||||
|
||||
void removeAlias(in ACString aURI);
|
||||
|
||||
mozISqlConnection getConnection(in ACString aURI);
|
||||
|
||||
mozISqlConnection getNewConnection(in ACString aURI);
|
||||
|
||||
};
|
||||
@@ -1,6 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,39 +0,0 @@
|
||||
var sqlService = null;
|
||||
|
||||
var name;
|
||||
var type;
|
||||
var hostname;
|
||||
var port;
|
||||
var database;
|
||||
|
||||
function init() {
|
||||
sqlService = Components.classes["@mozilla.org/sql/service;1"]
|
||||
.getService(Components.interfaces.mozISqlService);
|
||||
|
||||
name = document.getElementById("name");
|
||||
type = document.getElementById("type");
|
||||
hostname = document.getElementById("hostname");
|
||||
port = document.getElementById("port");
|
||||
database = document.getElementById("database");
|
||||
|
||||
if (window.arguments) {
|
||||
// get original values
|
||||
var uri = window.arguments[0];
|
||||
sqlService.getAlias(uri, name, type, hostname, port, database);
|
||||
}
|
||||
}
|
||||
|
||||
function onAccept() {
|
||||
if (window.arguments) {
|
||||
// update an existing alias
|
||||
var uri = window.arguments[0];
|
||||
sqlService.updateAlias(uri, name.value, type.value, hostname.value,
|
||||
port.value, database.value);
|
||||
}
|
||||
else {
|
||||
// add a new database
|
||||
var uri = "urn:aliases:" + name.value;
|
||||
sqlService.addAlias(uri, name.value, type.value, hostname.value,
|
||||
port.value, database.value);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
|
||||
|
||||
<!DOCTYPE dialog SYSTEM "chrome://sql/locale/aliasDialog.dtd">
|
||||
|
||||
<dialog id="aliasDialog"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&window.title;"
|
||||
width="250" height="180"
|
||||
buttons="accept,cancel" buttonpack="center"
|
||||
ondialogaccept="return onAccept(event);"
|
||||
onload="init()">
|
||||
|
||||
<script type="application/x-javascript" src="aliasDialog.js"/>
|
||||
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<label value="&name.label;"/>
|
||||
<textbox id="name"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="&type.label;"/>
|
||||
<textbox id="type"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="&hostname.label;"/>
|
||||
<textbox id="hostname"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="&port.label;"/>
|
||||
<textbox id="port"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="&database.label;"/>
|
||||
<textbox id="database"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
||||
</dialog>
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
|
||||
|
||||
<!-- list all the packages being supplied by this jar -->
|
||||
<RDF:Seq about="urn:mozilla:package:root">
|
||||
<RDF:li resource="urn:mozilla:package:sql"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- package information -->
|
||||
<RDF:Description about="urn:mozilla:package:sql"
|
||||
chrome:displayName="SQL support"
|
||||
chrome:author="mozilla.org"
|
||||
chrome:authorURL="http://www.mozilla.org/projects/sql/index.html"
|
||||
chrome:name="sql"
|
||||
chrome:extension="true"
|
||||
chrome:settingsURL="chrome://sql/content/sqlSettings.xul"
|
||||
chrome:description="Allow applications to directly connect to SQL databases.">
|
||||
</RDF:Description>
|
||||
|
||||
</RDF:RDF>
|
||||
@@ -1,36 +0,0 @@
|
||||
var sqlService = null;
|
||||
|
||||
function getSqlService() {
|
||||
if (! sqlService)
|
||||
sqlService = Components.classes["@mozilla.org/sql/service;1"]
|
||||
.getService(Components.interfaces.mozISqlService);
|
||||
return sqlService;
|
||||
}
|
||||
|
||||
function getSelectedAlias() {
|
||||
var tree = document.getElementById("aliasesTree");
|
||||
return tree.builderView.getResourceAtIndex(tree.currentIndex).Value;
|
||||
}
|
||||
|
||||
function updateButtons() {
|
||||
var tree = document.getElementById("aliasesTree");
|
||||
const buttons = ["updateButton", "removeButton"];
|
||||
for (i = 0; i < buttons.length; i++)
|
||||
document.getElementById(buttons[i]).disabled = tree.currentIndex < 0;
|
||||
}
|
||||
|
||||
function addAlias() {
|
||||
window.openDialog("aliasDialog.xul", "addAlias", "chrome,modal=yes,resizable=no,centerscreen");
|
||||
}
|
||||
|
||||
function updateAlias() {
|
||||
var alias = getSelectedAlias();
|
||||
window.openDialog("aliasDialog.xul", "updateDatabase", "chrome,modal=yes,resizable=no,centerscreen", alias);
|
||||
}
|
||||
|
||||
function removeAlias() {
|
||||
var sqlService = getSqlService();
|
||||
var alias = getSelectedAlias();
|
||||
sqlService.removeAlias(alias);
|
||||
updateButtons();
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
|
||||
<!DOCTYPE dialog SYSTEM "chrome://sql/locale/sqlSettings.dtd">
|
||||
|
||||
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&header.label;"
|
||||
width="450" height="350">
|
||||
|
||||
<script type="application/x-javascript" src="sqlSettings.js"/>
|
||||
|
||||
<groupbox flex="1">
|
||||
<caption label="&aliases.label;"/>
|
||||
<hbox flex="1">
|
||||
<tree id="aliasesTree" flex="1"
|
||||
seltype="single"
|
||||
datasources="rdf:sql" ref="SQL:AliasesRoot" flags="dont-build-content"
|
||||
onselect="updateButtons()">
|
||||
<treecols>
|
||||
<treecol id="nameCol" flex="1" label="&nameCol.label;"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#name"
|
||||
sortActive="true" sortDirection="ascending"/>
|
||||
<treecol id="typeCol" flex="1" label="&typeCol.label;"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#type"/>
|
||||
<treecol id="hostnameCol" flex="1" label="&hostnameCol.label;"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#hostname"/>
|
||||
<treecol id="portCol" flex="1" label="&portCol.label;"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#port"/>
|
||||
<treecol id="databaseCol" flex="1" label="&databaseCol.label;"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#database"/>
|
||||
</treecols>
|
||||
<template>
|
||||
<treechildren>
|
||||
<treeitem uri="rdf:*">
|
||||
<treerow>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#name"/>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#type"/>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#hostname"/>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#port"/>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#database"/>
|
||||
</treerow>
|
||||
</treeitem>
|
||||
</treechildren>
|
||||
</template>
|
||||
</tree>
|
||||
<vbox>
|
||||
<button id="addButton" label="&add.label;" oncommand="addAlias()"/>
|
||||
<button id="updateButton" label="&update.label;" disabled="true" oncommand="updateAlias()"/>
|
||||
<button id="removeButton" label="&remove.label;" disabled="true" oncommand="removeAlias()"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
</groupbox>
|
||||
|
||||
</dialog>
|
||||
@@ -1,9 +0,0 @@
|
||||
sql.jar:
|
||||
content/sql/contents.rdf (content/contents.rdf)
|
||||
content/sql/sqlSettings.xul (content/sqlSettings.xul)
|
||||
content/sql/sqlSettings.js (content/sqlSettings.js)
|
||||
content/sql/aliasDialog.xul (content/aliasDialog.xul)
|
||||
content/sql/aliasDialog.js (content/aliasDialog.js)
|
||||
locale/en-US/sql/contents.rdf (locale/en-US/contents.rdf)
|
||||
locale/en-US/sql/sqlSettings.dtd (locale/en-US/sqlSettings.dtd)
|
||||
locale/en-US/sql/aliasDialog.dtd (locale/en-US/aliasDialog.dtd)
|
||||
@@ -1,7 +0,0 @@
|
||||
<!ENTITY window.title "Alias">
|
||||
|
||||
<!ENTITY name.label "Name:">
|
||||
<!ENTITY type.label "Type:">
|
||||
<!ENTITY hostname.label "Hostname:">
|
||||
<!ENTITY port.label "Port:">
|
||||
<!ENTITY database.label "Database:">
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
|
||||
|
||||
<!-- list all the locales being supplied by this package -->
|
||||
<RDF:Seq about="urn:mozilla:locale:root">
|
||||
<RDF:li resource="urn:mozilla:locale:en-US"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- locale information -->
|
||||
<RDF:Description about="urn:mozilla:locale:en-US"
|
||||
chrome:displayName="English(US)"
|
||||
chrome:author="mozilla.org"
|
||||
chrome:name="en-US"
|
||||
chrome:previewURL="http://www.mozilla.org/locales/en-US.gif">
|
||||
<chrome:packages>
|
||||
<RDF:Seq about="urn:mozilla:locale:en-US:packages">
|
||||
<RDF:li resource="urn:mozilla:locale:en-US:sql"/>
|
||||
</RDF:Seq>
|
||||
</chrome:packages>
|
||||
</RDF:Description>
|
||||
|
||||
</RDF:RDF>
|
||||
@@ -1,12 +0,0 @@
|
||||
<!ENTITY header.label "SQL support">
|
||||
|
||||
<!ENTITY aliases.label "Aliases">
|
||||
<!ENTITY nameCol.label "Name">
|
||||
<!ENTITY typeCol.label "Type">
|
||||
<!ENTITY hostnameCol.label "Hostname">
|
||||
<!ENTITY portCol.label "Port">
|
||||
<!ENTITY databaseCol.label "Database">
|
||||
|
||||
<!ENTITY add.label "Add alias">
|
||||
<!ENTITY update.label "Update alias">
|
||||
<!ENTITY remove.label "Remove alias">
|
||||
@@ -1,33 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = sql
|
||||
LIBRARY_NAME = sqlbase_s
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
unicharutil \
|
||||
locale \
|
||||
necko \
|
||||
rdf \
|
||||
windowwatcher \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
mozSqlConnection.cpp \
|
||||
mozSqlRequest.cpp \
|
||||
mozSqlResult.cpp \
|
||||
mozSqlService.cpp
|
||||
|
||||
EXPORTS = \
|
||||
mozSqlConnection.h \
|
||||
mozSqlRequest.h \
|
||||
mozSqlResult.h \
|
||||
mozSqlService.h
|
||||
|
||||
FORCE_STATIC_LIB=1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,237 +0,0 @@
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "mozSqlRequest.h"
|
||||
#include "mozSqlConnection.h"
|
||||
|
||||
mozSqlConnection::mozSqlConnection()
|
||||
: mLock(nsnull),
|
||||
mCondVar(nsnull),
|
||||
mThread(nsnull),
|
||||
mShutdown(PR_FALSE),
|
||||
mWaiting(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mExecLock = PR_NewLock();
|
||||
}
|
||||
|
||||
mozSqlConnection::~mozSqlConnection()
|
||||
{
|
||||
mRequests.Clear();
|
||||
|
||||
if (mCondVar)
|
||||
PR_DestroyCondVar(mCondVar);
|
||||
PR_DestroyLock(mExecLock);
|
||||
if (mLock)
|
||||
PR_DestroyLock(mLock);
|
||||
}
|
||||
|
||||
// We require a special implementation of Release, which knows about
|
||||
// a circular strong reference
|
||||
NS_IMPL_THREADSAFE_ADDREF(mozSqlConnection)
|
||||
NS_IMPL_THREADSAFE_QUERY_INTERFACE3(mozSqlConnection,
|
||||
mozISqlConnection,
|
||||
nsIRunnable,
|
||||
nsISupportsWeakReference)
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
mozSqlConnection::Release()
|
||||
{
|
||||
PR_AtomicDecrement((PRInt32*)&mRefCnt);
|
||||
// Delete if the last reference is our strong circular reference.
|
||||
if (mThread && mRefCnt == 1) {
|
||||
PR_Lock(mLock);
|
||||
mRequests.Clear();
|
||||
mShutdown = PR_TRUE;
|
||||
if (mWaiting)
|
||||
PR_NotifyCondVar(mCondVar);
|
||||
else
|
||||
CancelExec();
|
||||
PR_Unlock(mLock);
|
||||
return 0;
|
||||
}
|
||||
else if (mRefCnt == 0) {
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::GetServerVersion(nsAString& aServerVersion)
|
||||
{
|
||||
aServerVersion = mServerVersion;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::GetErrorMessage(nsAString& aErrorMessage)
|
||||
{
|
||||
aErrorMessage = mErrorMessage;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::GetLastID(PRInt32* aLastID)
|
||||
{
|
||||
*aLastID = mLastID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::Init(const nsAString & aHost, PRInt32 aPort,
|
||||
const nsAString & aDatabase, const nsAString & aUsername,
|
||||
const nsAString & aPassword)
|
||||
{
|
||||
// descendants have to implement this themselves
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::ExecuteQuery(const nsAString& aQuery, mozISqlResult** _retval)
|
||||
{
|
||||
PR_Lock(mExecLock);
|
||||
nsresult rv = RealExec(aQuery, _retval, nsnull);
|
||||
PR_Unlock(mExecLock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::ExecuteUpdate(const nsAString& aUpdate, PRInt32* _retval)
|
||||
{
|
||||
PR_Lock(mExecLock);
|
||||
nsresult rv = RealExec(aUpdate, nsnull, _retval);
|
||||
PR_Unlock(mExecLock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::AsyncExecuteQuery(const nsAString& aQuery, nsISupports* aCtxt,
|
||||
mozISqlRequestObserver* aObserver,
|
||||
mozISqlRequest **_retval)
|
||||
{
|
||||
if (!mThread) {
|
||||
mLock = PR_NewLock();
|
||||
mCondVar = PR_NewCondVar(mLock);
|
||||
NS_NewThread(getter_AddRefs(mThread), this, 0, PR_UNJOINABLE_THREAD);
|
||||
}
|
||||
|
||||
mozSqlRequest* request = new mozSqlRequest(this);
|
||||
if (! request)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
request->mIsQuery = PR_TRUE;
|
||||
request->mQuery = aQuery;
|
||||
request->mCtxt = aCtxt;
|
||||
|
||||
nsresult rv = NS_GetProxyForObject(NS_CURRENT_EVENTQ,
|
||||
NS_GET_IID(mozISqlRequestObserver),
|
||||
aObserver,
|
||||
PROXY_SYNC | PROXY_ALWAYS,
|
||||
getter_AddRefs(request->mObserver));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PR_Lock(mLock);
|
||||
mRequests.AppendObject(request);
|
||||
if (mWaiting && mRequests.Count() == 1)
|
||||
PR_NotifyCondVar(mCondVar);
|
||||
PR_Unlock(mLock);
|
||||
|
||||
NS_ADDREF(*_retval = request);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::AsyncExecuteUpdate(const nsAString& aQuery, nsISupports* aCtxt,
|
||||
mozISqlRequestObserver* aObserver,
|
||||
mozISqlRequest **_retval)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::BeginTransaction()
|
||||
{
|
||||
PRInt32 affectedRows;
|
||||
return ExecuteUpdate(NS_LITERAL_STRING("begin"), &affectedRows);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::CommitTransaction()
|
||||
{
|
||||
PRInt32 affectedRows;
|
||||
return ExecuteUpdate(NS_LITERAL_STRING("commit"), &affectedRows);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::RollbackTransaction()
|
||||
{
|
||||
PRInt32 affectedRows;
|
||||
return ExecuteUpdate(NS_LITERAL_STRING("rollback"), &affectedRows);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::GetPrimaryKeys(const nsAString& aSchema, const nsAString& aTable, mozISqlResult** _retval)
|
||||
{
|
||||
// descendants have to implement this themselves
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnection::Run()
|
||||
{
|
||||
while(!mShutdown) {
|
||||
PR_Lock(mLock);
|
||||
|
||||
while (mRequests.Count()) {
|
||||
mCurrentRequest = mRequests[0];
|
||||
mRequests.RemoveObjectAt(0);
|
||||
|
||||
|
||||
mozSqlRequest* r = (mozSqlRequest*)mCurrentRequest.get();
|
||||
|
||||
r->mObserver->OnStartRequest(mCurrentRequest, r->mCtxt);
|
||||
|
||||
r->mStatus = mozISqlRequest::STATUS_EXECUTED;
|
||||
|
||||
PR_Unlock(mLock);
|
||||
|
||||
nsresult rv = ExecuteQuery(r->mQuery, getter_AddRefs(r->mResult));
|
||||
|
||||
PR_Lock(mLock);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
r->mStatus = mozISqlRequest::STATUS_COMPLETE;
|
||||
else {
|
||||
r->mStatus = mozISqlRequest::STATUS_ERROR;
|
||||
GetErrorMessage(r->mErrorMessage);
|
||||
}
|
||||
|
||||
r->mObserver->OnStopRequest(mCurrentRequest, r->mCtxt);
|
||||
|
||||
mCurrentRequest = nsnull;
|
||||
|
||||
}
|
||||
|
||||
mWaiting = PR_TRUE;
|
||||
PR_WaitCondVar(mCondVar, PR_INTERVAL_NO_TIMEOUT);
|
||||
mWaiting = PR_FALSE;
|
||||
PR_Unlock(mLock);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlConnection::CancelRequest(mozISqlRequest* aRequest)
|
||||
{
|
||||
PR_Lock(mLock);
|
||||
if (mCurrentRequest == aRequest)
|
||||
CancelExec();
|
||||
else {
|
||||
if (mRequests.RemoveObject(aRequest))
|
||||
((mozSqlRequest*)aRequest)->mStatus = mozISqlRequest::STATUS_CANCELLED;
|
||||
}
|
||||
PR_Unlock(mLock);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
#ifndef mozSqlConnection_h
|
||||
#define mozSqlConnection_h
|
||||
|
||||
#include "prcvar.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsIRunnable.h"
|
||||
#include "mozISqlConnection.h"
|
||||
#include "mozISqlRequest.h"
|
||||
#include "mozISqlResult.h"
|
||||
|
||||
class mozSqlConnection : public mozISqlConnection,
|
||||
public nsIRunnable,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
mozSqlConnection();
|
||||
virtual ~mozSqlConnection();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLCONNECTION
|
||||
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
friend class mozSqlRequest;
|
||||
friend class mozSqlResult;
|
||||
|
||||
protected:
|
||||
virtual nsresult RealExec(const nsAString& aQuery,
|
||||
mozISqlResult** aResult, PRInt32* aAffectedRows) = 0;
|
||||
virtual nsresult CancelExec() = 0;
|
||||
virtual nsresult GetIDName(nsAString& aIDName) = 0;
|
||||
|
||||
nsresult CancelRequest(mozISqlRequest* aRequest);
|
||||
|
||||
nsString mServerVersion;
|
||||
nsString mErrorMessage;
|
||||
PRInt32 mLastID;
|
||||
|
||||
PRLock* mLock;
|
||||
PRCondVar* mCondVar;
|
||||
PRLock* mExecLock;
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
nsCOMArray<mozISqlRequest> mRequests;
|
||||
nsCOMPtr<mozISqlRequest> mCurrentRequest;
|
||||
PRBool mShutdown;
|
||||
PRBool mWaiting;
|
||||
};
|
||||
|
||||
#endif // mozSqlConnection_h
|
||||
@@ -1,86 +0,0 @@
|
||||
#include "mozSqlConnection.h"
|
||||
#include "mozSqlRequest.h"
|
||||
|
||||
mozSqlRequest::mozSqlRequest(mozISqlConnection* aConnection)
|
||||
: mAffectedRows(-1),
|
||||
mIsQuery(PR_TRUE),
|
||||
mStatus(mozISqlRequest::STATUS_NONE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mConnection = do_GetWeakReference(aConnection);
|
||||
}
|
||||
|
||||
mozSqlRequest::~mozSqlRequest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(mozSqlRequest,
|
||||
mozISqlRequest);
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetErrorMessage(nsAString & aErrorMessage)
|
||||
{
|
||||
aErrorMessage = mErrorMessage;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetResult(mozISqlResult * *aResult)
|
||||
{
|
||||
NS_IF_ADDREF(*aResult = mResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetAffectedRows(PRInt32 *aAffectedRows)
|
||||
{
|
||||
*aAffectedRows = mAffectedRows;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetLastID(PRInt32* aLastID)
|
||||
{
|
||||
*aLastID = mLastID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetQuery(nsAString & aQuery)
|
||||
{
|
||||
aQuery = mQuery;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetCtxt(nsISupports * *aCtxt)
|
||||
{
|
||||
NS_IF_ADDREF(*aCtxt = mCtxt);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetObserver(mozISqlRequestObserver * *aObserver)
|
||||
{
|
||||
NS_IF_ADDREF(*aObserver = mObserver);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::GetStatus(PRInt32 *aStatus)
|
||||
{
|
||||
*aStatus = mStatus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlRequest::Cancel()
|
||||
{
|
||||
nsCOMPtr<mozISqlConnection> connection = do_QueryReferent(mConnection);
|
||||
if (!connection)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mozISqlConnection* connectionRaw = connection.get();
|
||||
return ((mozSqlConnection*)connectionRaw)->CancelRequest(this);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
#ifndef mozSqlRequest_h
|
||||
#define mozSqlRequest_h
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIWeakReference.h"
|
||||
#include "mozISqlConnection.h"
|
||||
#include "mozISqlResult.h"
|
||||
#include "mozISqlRequest.h"
|
||||
#include "mozISqlRequestObserver.h"
|
||||
|
||||
class mozSqlRequest : public mozISqlRequest
|
||||
{
|
||||
public:
|
||||
mozSqlRequest(mozISqlConnection* aConnection);
|
||||
virtual ~mozSqlRequest();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLREQUEST
|
||||
|
||||
friend class mozSqlConnection;
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIWeakReference> mConnection;
|
||||
|
||||
nsString mErrorMessage;
|
||||
nsCOMPtr<mozISqlResult> mResult;
|
||||
PRInt32 mAffectedRows;
|
||||
PRInt32 mLastID;
|
||||
|
||||
PRBool mIsQuery;
|
||||
nsString mQuery;
|
||||
nsCOMPtr<nsISupports> mCtxt;
|
||||
nsCOMPtr<mozISqlRequestObserver> mObserver;
|
||||
|
||||
PRInt32 mStatus;
|
||||
|
||||
};
|
||||
|
||||
#endif // mozSqlRequest_h
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,367 +0,0 @@
|
||||
#ifndef mozSqlResult_h
|
||||
#define mozSqlResult_h
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "nsFixedSizeAllocator.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFRemoteDataSource.h"
|
||||
#include "nsIDateTimeFormat.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "mozISqlConnection.h"
|
||||
#include "mozISqlDataSource.h"
|
||||
#include "mozISqlResult.h"
|
||||
#include "mozISqlResultEnumerator.h"
|
||||
#include "mozISqlInputStream.h"
|
||||
|
||||
#define CELL_FLAG_NULL 0x80
|
||||
#define CELL_FLAG_DEFAULT 0x40
|
||||
#define CELL_FLAG_MASK ~(CELL_FLAG_NULL | CELL_FLAG_DEFAULT)
|
||||
|
||||
class ColumnInfo {
|
||||
public:
|
||||
static ColumnInfo*
|
||||
Create(nsFixedSizeAllocator& aAllocator,
|
||||
PRUnichar* aName,
|
||||
PRInt32 aType,
|
||||
PRInt32 aSize,
|
||||
PRInt32 aMod,
|
||||
nsIRDFResource* aProperty) {
|
||||
void* place = aAllocator.Alloc(sizeof(ColumnInfo));
|
||||
return place ? ::new(place) ColumnInfo(aName, aType, aSize, aMod, aProperty) : nsnull;
|
||||
}
|
||||
|
||||
static void
|
||||
Destroy(nsFixedSizeAllocator& aAllocator, ColumnInfo* aColumnInfo) {
|
||||
aColumnInfo->~ColumnInfo();
|
||||
aAllocator.Free(aColumnInfo, sizeof(ColumnInfo));
|
||||
}
|
||||
|
||||
ColumnInfo(PRUnichar* aName, PRInt32 aType, PRInt32 aSize, PRInt32 aMod, nsIRDFResource* aProperty)
|
||||
: mName(aName),
|
||||
mType(aType),
|
||||
mSize(aSize),
|
||||
mMod(aMod),
|
||||
mProperty(aProperty) {
|
||||
NS_IF_ADDREF(mProperty);
|
||||
}
|
||||
|
||||
~ColumnInfo() {
|
||||
if (mName)
|
||||
nsMemory::Free(mName);
|
||||
NS_IF_RELEASE(mProperty);
|
||||
}
|
||||
|
||||
PRUnichar* mName;
|
||||
PRInt32 mType;
|
||||
PRInt32 mSize;
|
||||
PRInt32 mMod;
|
||||
nsIRDFResource* mProperty;
|
||||
|
||||
private:
|
||||
// Hide so that only Create() and Destroy() can be used to
|
||||
// allocate and deallocate from the heap
|
||||
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
|
||||
static void operator delete(void*, size_t) {}
|
||||
};
|
||||
|
||||
class Cell {
|
||||
public:
|
||||
static Cell*
|
||||
Create(nsFixedSizeAllocator& aAllocator,
|
||||
PRInt32 aType) {
|
||||
void* place = aAllocator.Alloc(sizeof(Cell));
|
||||
return place ? ::new(place) Cell(aType) : nsnull;
|
||||
}
|
||||
|
||||
static Cell*
|
||||
Create(nsFixedSizeAllocator& aAllocator,
|
||||
PRInt32 aType,
|
||||
Cell* aSrcCell) {
|
||||
void* place = aAllocator.Alloc(sizeof(Cell));
|
||||
if (! place)
|
||||
return nsnull;
|
||||
Cell* newCell = ::new(place) Cell(aType);
|
||||
Copy(aSrcCell, newCell);
|
||||
return newCell;
|
||||
}
|
||||
|
||||
static void
|
||||
Copy(Cell* aSrcCell, Cell* aDestCell) {
|
||||
if (aSrcCell->IsNull())
|
||||
aDestCell->SetNull(PR_TRUE);
|
||||
else {
|
||||
aDestCell->SetNull(PR_FALSE);
|
||||
PRInt32 type = aSrcCell->GetType();
|
||||
if (type == mozISqlResult::TYPE_STRING)
|
||||
aDestCell->SetString(nsCRT::strdup(aSrcCell->mString));
|
||||
else if (type == mozISqlResult::TYPE_INT)
|
||||
aDestCell->mInt = aSrcCell->mInt;
|
||||
else if (type == mozISqlResult::TYPE_FLOAT ||
|
||||
type == mozISqlResult::TYPE_DECIMAL)
|
||||
aDestCell->mFloat = aSrcCell->mFloat;
|
||||
else if (type == mozISqlResult::TYPE_DATE ||
|
||||
type == mozISqlResult::TYPE_TIME ||
|
||||
type == mozISqlResult::TYPE_DATETIME)
|
||||
aDestCell->mDate = aSrcCell->mDate;
|
||||
else if (type == mozISqlResult::TYPE_BOOL)
|
||||
aDestCell->mBool = aSrcCell->mBool;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Destroy(nsFixedSizeAllocator& aAllocator, Cell* aCell) {
|
||||
aCell->~Cell();
|
||||
aAllocator.Free(aCell, sizeof(Cell));
|
||||
}
|
||||
|
||||
Cell(PRInt32 aType)
|
||||
: mString(nsnull),
|
||||
mType(aType | CELL_FLAG_NULL) {
|
||||
}
|
||||
|
||||
~Cell() {
|
||||
if ((GetType() == mozISqlResult::TYPE_STRING) && mString) {
|
||||
nsMemory::Free(mString);
|
||||
}
|
||||
}
|
||||
|
||||
void SetString(PRUnichar* aString) {
|
||||
if (mString)
|
||||
nsMemory::Free(mString);
|
||||
mString = aString;
|
||||
}
|
||||
|
||||
PRInt32 GetType() {
|
||||
return mType & CELL_FLAG_MASK;
|
||||
}
|
||||
|
||||
void SetNull(PRBool aNull) {
|
||||
mType &= CELL_FLAG_MASK;
|
||||
if (aNull)
|
||||
mType |= CELL_FLAG_NULL;
|
||||
}
|
||||
|
||||
void SetDefault(PRBool aDefault) {
|
||||
mType &= CELL_FLAG_MASK;
|
||||
if (aDefault)
|
||||
mType |= CELL_FLAG_DEFAULT;
|
||||
}
|
||||
|
||||
PRBool IsNull() {
|
||||
return mType & CELL_FLAG_NULL;
|
||||
}
|
||||
|
||||
PRBool IsDefault() {
|
||||
return mType & CELL_FLAG_DEFAULT;
|
||||
}
|
||||
|
||||
union {
|
||||
PRUnichar* mString;
|
||||
PRInt32 mInt;
|
||||
float mFloat;
|
||||
PRInt64 mDate;
|
||||
PRBool mBool;
|
||||
};
|
||||
|
||||
private:
|
||||
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
|
||||
static void operator delete(void*, size_t) {}
|
||||
|
||||
PRInt8 mType;
|
||||
};
|
||||
|
||||
class Row {
|
||||
public:
|
||||
static Row*
|
||||
Create(nsFixedSizeAllocator& aAllocator,
|
||||
nsIRDFResource* aSource,
|
||||
nsVoidArray& aColumnInfo) {
|
||||
void* place = aAllocator.Alloc(sizeof(Row));
|
||||
if (! place)
|
||||
return nsnull;
|
||||
Row* newRow = ::new(place) Row(aSource, aColumnInfo.Count());
|
||||
for (PRInt32 i = 0; i < aColumnInfo.Count(); i++) {
|
||||
Cell* newCell = Cell::Create(aAllocator, ((ColumnInfo*)aColumnInfo[i])->mType);
|
||||
newRow->mCells[i] = newCell;
|
||||
}
|
||||
return newRow;
|
||||
}
|
||||
|
||||
static Row*
|
||||
Create(nsFixedSizeAllocator& aAllocator,
|
||||
nsIRDFResource* aSource,
|
||||
nsVoidArray& aColumnInfo,
|
||||
Row* aSrcRow) {
|
||||
void* place = aAllocator.Alloc(sizeof(Row));
|
||||
if (! place)
|
||||
return nsnull;
|
||||
Row* newRow = ::new(place) Row(aSource, aColumnInfo.Count());
|
||||
for (PRInt32 i = 0; i < aColumnInfo.Count(); i++) {
|
||||
Cell* srcCell = aSrcRow->mCells[i];
|
||||
Cell* newCell = Cell::Create(aAllocator, ((ColumnInfo*)aColumnInfo[i])->mType, srcCell);
|
||||
newRow->mCells[i] = newCell;
|
||||
}
|
||||
return newRow;
|
||||
}
|
||||
|
||||
static void
|
||||
Copy(PRInt32 aColumnCount, Row* aSrcRow, Row* aDestRow) {
|
||||
for (PRInt32 i = 0; i < aColumnCount; i++) {
|
||||
Cell* srcCell = aSrcRow->mCells[i];
|
||||
Cell* destCell = aDestRow->mCells[i];
|
||||
Cell::Copy(srcCell, destCell);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Destroy(nsFixedSizeAllocator& aAllocator, PRInt32 aColumnCount, Row* aRow) {
|
||||
for (PRInt32 i = 0; i < aColumnCount; i++)
|
||||
Cell::Destroy(aAllocator, aRow->mCells[i]);
|
||||
aRow->~Row();
|
||||
aAllocator.Free(aRow, sizeof(*aRow));
|
||||
}
|
||||
|
||||
Row(nsIRDFResource* aSource, PRInt32 aColumnCount)
|
||||
: mSource(aSource)
|
||||
{
|
||||
NS_IF_ADDREF(mSource);
|
||||
mCells = new Cell*[aColumnCount];
|
||||
}
|
||||
|
||||
~Row() {
|
||||
delete[] mCells;
|
||||
NS_IF_RELEASE(mSource);
|
||||
}
|
||||
|
||||
nsIRDFResource* mSource;
|
||||
Cell** mCells;
|
||||
private:
|
||||
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
|
||||
static void operator delete(void*, size_t) {}
|
||||
};
|
||||
|
||||
class mozSqlResult : public mozISqlResult,
|
||||
public mozISqlDataSource,
|
||||
public nsIRDFDataSource,
|
||||
public nsIRDFRemoteDataSource
|
||||
{
|
||||
public:
|
||||
mozSqlResult(mozISqlConnection* aConnection,
|
||||
const nsAString& aQuery);
|
||||
nsresult Init();
|
||||
nsresult Rebuild();
|
||||
virtual ~mozSqlResult();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLRESULT
|
||||
|
||||
NS_DECL_MOZISQLDATASOURCE
|
||||
|
||||
NS_DECL_NSIRDFDATASOURCE
|
||||
|
||||
NS_DECL_NSIRDFREMOTEDATASOURCE
|
||||
|
||||
friend class mozSqlResultEnumerator;
|
||||
friend class mozSqlResultStream;
|
||||
|
||||
protected:
|
||||
virtual nsresult BuildColumnInfo() = 0 ;
|
||||
virtual nsresult BuildRows() = 0;
|
||||
virtual void ClearNativeResult() = 0;
|
||||
|
||||
void ClearColumnInfo();
|
||||
void ClearRows();
|
||||
|
||||
nsresult EnsureTableName();
|
||||
nsresult EnsurePrimaryKeys();
|
||||
|
||||
void AppendValue(Cell* aCell, nsAutoString& aValues);
|
||||
nsresult AppendKeys(Row* aRow, nsAutoString& aKeys);
|
||||
nsresult GetValues(Row* aRow, mozISqlResult** aResult, PRBool aUseID);
|
||||
nsresult CopyValues(mozISqlResult* aResult, Row* aRow);
|
||||
|
||||
virtual nsresult CanInsert(PRBool* _retval) = 0;
|
||||
virtual nsresult CanUpdate(PRBool* _retval) = 0;
|
||||
virtual nsresult CanDelete(PRBool* _retval) = 0;
|
||||
|
||||
nsresult InsertRow(Row* aSrcRow, PRInt32* _retval);
|
||||
nsresult UpdateRow(PRInt32 aRowIndex, Row* aSrcRow, PRInt32* _retval);
|
||||
nsresult DeleteRow(PRInt32 aRowIndex, PRInt32* _retval);
|
||||
nsresult GetCondition(Row* aRow, nsAString& aCurrentCondition);
|
||||
|
||||
static PRInt32 gRefCnt;
|
||||
static nsIRDFService* gRDFService;
|
||||
static nsIDateTimeFormat* gFormat;
|
||||
static nsIRDFResource* kSQL_ResultRoot;
|
||||
static nsIRDFResource* kNC_Child;
|
||||
static nsIRDFLiteral* kNullLiteral;
|
||||
static nsIRDFLiteral* kTrueLiteral;
|
||||
static nsIRDFLiteral* kFalseLiteral;
|
||||
|
||||
nsCOMPtr<mozISqlConnection> mConnection;
|
||||
nsString mErrorMessage;
|
||||
nsString mQuery;
|
||||
nsString mTableName;
|
||||
nsFixedSizeAllocator mAllocator;
|
||||
nsAutoVoidArray mColumnInfo;
|
||||
nsVoidArray mRows;
|
||||
nsObjectHashtable mSources;
|
||||
nsCOMArray<nsIRDFObserver> mObservers;
|
||||
nsCOMPtr<mozISqlResultEnumerator> mPrimaryKeys;
|
||||
PRInt32 mCanInsert;
|
||||
PRInt32 mCanUpdate;
|
||||
PRInt32 mCanDelete;
|
||||
};
|
||||
|
||||
class mozSqlResultEnumerator : public mozISqlResultEnumerator,
|
||||
public nsISimpleEnumerator
|
||||
{
|
||||
public:
|
||||
mozSqlResultEnumerator(mozSqlResult* aResult);
|
||||
virtual ~mozSqlResultEnumerator();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLRESULTENUMERATOR
|
||||
|
||||
NS_DECL_NSISIMPLEENUMERATOR
|
||||
|
||||
private:
|
||||
mozSqlResult* mResult;
|
||||
PRInt32 mCurrentIndex;
|
||||
Row* mCurrentRow;
|
||||
Row* mBuffer;
|
||||
};
|
||||
|
||||
class mozSqlResultStream : public mozISqlInputStream,
|
||||
public nsIInputStream
|
||||
{
|
||||
public:
|
||||
mozSqlResultStream(mozSqlResult* aResult);
|
||||
virtual ~mozSqlResultStream();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLINPUTSTREAM
|
||||
|
||||
NS_DECL_NSIINPUTSTREAM
|
||||
|
||||
protected:
|
||||
nsresult EnsureBuffer();
|
||||
|
||||
private:
|
||||
mozSqlResult* mResult;
|
||||
char* mBuffer;
|
||||
PRUint32 mLength;
|
||||
PRUint32 mPosition;
|
||||
};
|
||||
|
||||
#endif // mozSqlResult_h
|
||||
@@ -1,624 +0,0 @@
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "rdf.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIRDFXMLSink.h"
|
||||
#include "nsIWindowWatcher.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "mozSqlService.h"
|
||||
#include "mozSqlConnection.h"
|
||||
|
||||
#define SQL_NAMESPACE_URI "http://www.mozilla.org/SQL-rdf#"
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
|
||||
nsIRDFService* mozSqlService::gRDFService;
|
||||
nsIRDFContainerUtils* mozSqlService::gRDFContainerUtils;
|
||||
|
||||
nsIRDFResource* mozSqlService::kSQL_AliasesRoot;
|
||||
nsIRDFResource* mozSqlService::kSQL_Name;
|
||||
nsIRDFResource* mozSqlService::kSQL_Type;
|
||||
nsIRDFResource* mozSqlService::kSQL_Hostname;
|
||||
nsIRDFResource* mozSqlService::kSQL_Port;
|
||||
nsIRDFResource* mozSqlService::kSQL_Database;
|
||||
|
||||
|
||||
mozSqlService::mozSqlService()
|
||||
: mConnectionCache(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
mozSqlService::~mozSqlService()
|
||||
{
|
||||
gRDFService->UnregisterDataSource(this);
|
||||
|
||||
delete mConnectionCache;
|
||||
|
||||
NS_IF_RELEASE(kSQL_AliasesRoot);
|
||||
NS_IF_RELEASE(kSQL_Name);
|
||||
NS_IF_RELEASE(kSQL_Type);
|
||||
NS_IF_RELEASE(kSQL_Hostname);
|
||||
NS_IF_RELEASE(kSQL_Port);
|
||||
NS_IF_RELEASE(kSQL_Database);
|
||||
|
||||
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
|
||||
gRDFContainerUtils = nsnull;
|
||||
|
||||
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
|
||||
gRDFService = nsnull;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS3(mozSqlService,
|
||||
mozISqlService,
|
||||
nsIRDFDataSource,
|
||||
nsIRDFRemoteDataSource);
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetErrorMessage(nsAString& aErrorMessage)
|
||||
{
|
||||
aErrorMessage = mErrorMessage;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlService::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService),
|
||||
(nsISupports**) &gRDFService);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = nsServiceManager::GetService(kRDFContainerUtilsCID, NS_GET_IID(nsIRDFContainerUtils),
|
||||
(nsISupports**) &gRDFContainerUtils);
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING("SQL:AliasesRoot"),
|
||||
&kSQL_AliasesRoot);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "name"),
|
||||
&kSQL_Name);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "type"),
|
||||
&kSQL_Type);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "hostname"),
|
||||
&kSQL_Hostname);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "port"),
|
||||
&kSQL_Port);
|
||||
gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "database"),
|
||||
&kSQL_Database);
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = file->AppendNative(NS_LITERAL_CSTRING("sql.rdf"));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString sql;
|
||||
NS_GetURLSpecFromFile(file, sql);
|
||||
|
||||
rv = gRDFService->GetDataSourceBlocking(sql.get(), getter_AddRefs(mInner));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mInner);
|
||||
if (sink) {
|
||||
nsCOMPtr<nsIAtom> prefix = getter_AddRefs(NS_NewAtom("SQL"));
|
||||
sink->AddNameSpace(prefix, NS_ConvertASCIItoUCS2(SQL_NAMESPACE_URI));
|
||||
}
|
||||
|
||||
return gRDFService->RegisterDataSource(this, PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::AddAlias(const nsACString& aURI,
|
||||
const nsAString& aName,
|
||||
const nsAString& aType,
|
||||
const nsAString& aHostname,
|
||||
PRInt32 aPort,
|
||||
const nsAString& aDatabase)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
gRDFService->GetResource(aURI, getter_AddRefs(resource));
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> rdfLiteral;
|
||||
nsCOMPtr<nsIRDFInt> rdfInt;
|
||||
|
||||
gRDFService->GetLiteral(PromiseFlatString(aName).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Assert(resource, kSQL_Name, rdfLiteral, PR_TRUE);
|
||||
|
||||
gRDFService->GetLiteral(PromiseFlatString(aType).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Assert(resource, kSQL_Type, rdfLiteral, PR_TRUE);
|
||||
|
||||
gRDFService->GetLiteral(PromiseFlatString(aHostname).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Assert(resource, kSQL_Hostname, rdfLiteral, PR_TRUE);
|
||||
|
||||
gRDFService->GetIntLiteral(aPort, getter_AddRefs(rdfInt));
|
||||
mInner->Assert(resource, kSQL_Port, rdfInt, PR_TRUE);
|
||||
|
||||
gRDFService->GetLiteral(PromiseFlatString(aDatabase).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Assert(resource, kSQL_Database, rdfLiteral, PR_TRUE);
|
||||
|
||||
nsresult rv = EnsureAliasesContainer();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
mAliasesContainer->AppendElement(resource);
|
||||
|
||||
Flush();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::HasAlias(const nsACString& aURI, PRBool* _retval)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
gRDFService->GetResource(aURI, getter_AddRefs(resource));
|
||||
|
||||
nsresult rv = EnsureAliasesContainer();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PRInt32 aliasIndex;
|
||||
mAliasesContainer->IndexOf(resource, &aliasIndex);
|
||||
|
||||
*_retval = aliasIndex != -1;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetAlias(const nsACString& aURI,
|
||||
nsAString& aName,
|
||||
nsAString& aType,
|
||||
nsAString& aHostname,
|
||||
PRInt32* aPort,
|
||||
nsAString& aDatabase)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
gRDFService->GetResource(aURI, getter_AddRefs(resource));
|
||||
|
||||
nsCOMPtr<nsIRDFNode> rdfNode;
|
||||
nsCOMPtr<nsIRDFLiteral> rdfLiteral;
|
||||
nsCOMPtr<nsIRDFInt> rdfInt;
|
||||
const PRUnichar* value;
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Name, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
if (rdfNode) {
|
||||
rdfLiteral = do_QueryInterface(rdfNode);
|
||||
rdfLiteral->GetValueConst(&value);
|
||||
aName.Assign(value);
|
||||
}
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Type, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
if (rdfNode) {
|
||||
rdfLiteral = do_QueryInterface(rdfNode);
|
||||
rdfLiteral->GetValueConst(&value);
|
||||
aType.Assign(value);
|
||||
}
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Hostname, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
if (rdfNode) {
|
||||
rdfLiteral = do_QueryInterface(rdfNode);
|
||||
rdfLiteral->GetValueConst(&value);
|
||||
aHostname.Assign(value);
|
||||
}
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Port, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
if (rdfNode) {
|
||||
rdfInt = do_QueryInterface(rdfNode);
|
||||
rdfInt->GetValue(aPort);
|
||||
}
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Database, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
if (rdfNode) {
|
||||
rdfLiteral = do_QueryInterface(rdfNode);
|
||||
rdfLiteral->GetValueConst(&value);
|
||||
aDatabase.Assign(value);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::UpdateAlias(const nsACString& aURI,
|
||||
const nsAString& aName,
|
||||
const nsAString& aType,
|
||||
const nsAString& aHostname,
|
||||
PRInt32 aPort,
|
||||
const nsAString& aDatabase)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
gRDFService->GetResource(aURI, getter_AddRefs(resource));
|
||||
|
||||
nsCOMPtr<nsIRDFNode> rdfNode;
|
||||
nsCOMPtr<nsIRDFLiteral> rdfLiteral;
|
||||
nsCOMPtr<nsIRDFInt> rdfInt;
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Name, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
gRDFService->GetLiteral(PromiseFlatString(aName).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Change(resource, kSQL_Name, rdfNode, rdfLiteral);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Type, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
gRDFService->GetLiteral(PromiseFlatString(aType).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Change(resource, kSQL_Type, rdfNode, rdfLiteral);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Hostname, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
gRDFService->GetLiteral(PromiseFlatString(aHostname).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Change(resource, kSQL_Hostname, rdfNode, rdfLiteral);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Port, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
gRDFService->GetIntLiteral(aPort, getter_AddRefs(rdfInt));
|
||||
mInner->Change(resource, kSQL_Port, rdfNode, rdfInt);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Database, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
gRDFService->GetLiteral(PromiseFlatString(aDatabase).get(), getter_AddRefs(rdfLiteral));
|
||||
mInner->Change(resource, kSQL_Database, rdfNode, rdfLiteral);
|
||||
|
||||
Flush();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::RemoveAlias(const nsACString &aURI)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
gRDFService->GetResource(aURI, getter_AddRefs(resource));
|
||||
|
||||
nsCOMPtr<nsIRDFNode> rdfNode;
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Name, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
mInner->Unassert(resource, kSQL_Name, rdfNode);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Type, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
mInner->Unassert(resource, kSQL_Type, rdfNode);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Hostname, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
mInner->Unassert(resource, kSQL_Hostname, rdfNode);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Port, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
mInner->Unassert(resource, kSQL_Port, rdfNode);
|
||||
|
||||
mInner->GetTarget(resource, kSQL_Database, PR_TRUE, getter_AddRefs(rdfNode));
|
||||
mInner->Unassert(resource, kSQL_Database, rdfNode);
|
||||
|
||||
nsresult rv = EnsureAliasesContainer();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
mAliasesContainer->RemoveElement(resource, PR_TRUE);
|
||||
|
||||
Flush();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetConnection(const nsACString &aURI, mozISqlConnection **_retval)
|
||||
{
|
||||
nsCStringKey key(aURI);
|
||||
nsCOMPtr<nsIWeakReference> weakRef;
|
||||
nsCOMPtr<mozISqlConnection> conn;
|
||||
|
||||
if (mConnectionCache) {
|
||||
weakRef = getter_AddRefs(NS_STATIC_CAST(nsIWeakReference*, mConnectionCache->Get(&key)));
|
||||
if (weakRef) {
|
||||
conn = do_QueryReferent(weakRef);
|
||||
if (conn)
|
||||
NS_ADDREF(*_retval = conn);
|
||||
}
|
||||
}
|
||||
|
||||
if (! *_retval) {
|
||||
nsresult rv = GetNewConnection(aURI, getter_AddRefs(conn));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
weakRef = do_GetWeakReference(conn);
|
||||
|
||||
if (! mConnectionCache)
|
||||
mConnectionCache = new nsSupportsHashtable(16);
|
||||
mConnectionCache->Put(&key, weakRef);
|
||||
|
||||
NS_ADDREF(*_retval = conn);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetNewConnection(const nsACString &aURI, mozISqlConnection **_retval)
|
||||
{
|
||||
PRBool hasAlias;
|
||||
HasAlias(aURI, &hasAlias);
|
||||
if (!hasAlias)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsAutoString name;
|
||||
nsAutoString type;
|
||||
nsAutoString hostname;
|
||||
PRInt32 port;
|
||||
nsAutoString database;
|
||||
GetAlias(aURI, name, type, hostname, &port, database);
|
||||
|
||||
nsCAutoString contractID(
|
||||
NS_LITERAL_CSTRING("@mozilla.org/sql/connection;1?type=") +
|
||||
NS_ConvertUCS2toUTF8(type));
|
||||
|
||||
nsCOMPtr<mozISqlConnection> conn = do_CreateInstance(contractID.get());
|
||||
if (! conn)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
|
||||
nsCOMPtr<nsIPrompt> prompter;
|
||||
watcher->GetNewPrompter(0, getter_AddRefs(prompter));
|
||||
|
||||
PRBool retval;
|
||||
do {
|
||||
nsXPIDLString username;
|
||||
nsXPIDLString password;
|
||||
prompter->PromptUsernameAndPassword(
|
||||
nsnull, // in wstring dialogTitle
|
||||
nsnull, // in wstring text
|
||||
getter_Copies(username),
|
||||
getter_Copies(password),
|
||||
nsnull, // in wstring checkMsg
|
||||
nsnull, // inout boolean checkValue
|
||||
&retval
|
||||
);
|
||||
|
||||
if (retval) {
|
||||
rv = conn->Init(hostname, port, database, username, password);
|
||||
if (NS_FAILED(rv)) {
|
||||
conn->GetErrorMessage(mErrorMessage);
|
||||
prompter->Alert(nsnull, mErrorMessage.get());
|
||||
}
|
||||
}
|
||||
} while(retval && NS_FAILED(rv));
|
||||
|
||||
NS_IF_ADDREF(*_retval = conn);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetURI(char** aURI)
|
||||
{
|
||||
if (!aURI)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aURI = nsCRT::strdup("rdf:sql");
|
||||
if (!(*aURI))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetSource(nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget,
|
||||
PRBool aTruthValue,
|
||||
nsIRDFResource** aSource)
|
||||
{
|
||||
return mInner->GetSource(aProperty, aTarget, aTruthValue, aSource);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetSources(nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget,
|
||||
PRBool aTruthValue,
|
||||
nsISimpleEnumerator** aSources) {
|
||||
return mInner->GetSources(aProperty, aTarget, aTruthValue, aSources);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetTarget(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
PRBool aTruthValue,
|
||||
nsIRDFNode** aTarget) {
|
||||
return mInner->GetTarget(aSource, aProperty, aTruthValue, aTarget);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetTargets(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
PRBool aTruthValue,
|
||||
nsISimpleEnumerator** aTargets) {
|
||||
return mInner->GetTargets(aSource, aProperty, aTruthValue, aTargets);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Assert(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget,
|
||||
PRBool aTruthValue)
|
||||
{
|
||||
return mInner->Assert(aSource, aProperty, aTarget, aTruthValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Unassert(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget)
|
||||
{
|
||||
return mInner->Unassert(aSource, aProperty, aTarget);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Change(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aOldTarget,
|
||||
nsIRDFNode* aNewTarget)
|
||||
{
|
||||
return mInner->Change(aSource, aProperty, aOldTarget, aNewTarget);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Move(nsIRDFResource* aOldSource,
|
||||
nsIRDFResource* aNewSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget)
|
||||
{
|
||||
return mInner->Move(aOldSource, aNewSource, aProperty, aTarget);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::HasAssertion(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget,
|
||||
PRBool aTruthValue,
|
||||
PRBool* hasAssertion)
|
||||
{
|
||||
return mInner->HasAssertion(aSource, aProperty, aTarget, aTruthValue, hasAssertion);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::AddObserver(nsIRDFObserver* aObserver)
|
||||
{
|
||||
return mInner->AddObserver(aObserver);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::RemoveObserver(nsIRDFObserver* aObserver)
|
||||
{
|
||||
return mInner->RemoveObserver(aObserver);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::HasArcIn(nsIRDFNode* aNode,
|
||||
nsIRDFResource* aArc,
|
||||
PRBool* _retval)
|
||||
{
|
||||
return mInner->HasArcIn(aNode, aArc, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::HasArcOut(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aArc,
|
||||
PRBool* _retval)
|
||||
{
|
||||
return mInner->HasArcOut(aSource, aArc, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::ArcLabelsIn(nsIRDFNode* aNode,
|
||||
nsISimpleEnumerator** aLabels)
|
||||
{
|
||||
return mInner->ArcLabelsIn(aNode, aLabels);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::ArcLabelsOut(nsIRDFResource* aSource,
|
||||
nsISimpleEnumerator** aLabels)
|
||||
{
|
||||
return mInner->ArcLabelsIn(aSource, aLabels);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetAllResources(nsISimpleEnumerator** aResult)
|
||||
{
|
||||
return mInner->GetAllResources(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetAllCmds(nsIRDFResource* aSource,
|
||||
nsISimpleEnumerator** aCommands)
|
||||
{
|
||||
return mInner->GetAllCmds(aSource, aCommands);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::IsCommandEnabled(nsISupportsArray* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray* aArguments,
|
||||
PRBool* aResult)
|
||||
{
|
||||
return mInner->IsCommandEnabled(aSources, aCommand, aArguments, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::DoCommand(nsISupportsArray* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray* aArguments)
|
||||
{
|
||||
return mInner->DoCommand(aSources, aCommand, aArguments);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::BeginUpdateBatch()
|
||||
{
|
||||
return mInner->BeginUpdateBatch();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::EndUpdateBatch()
|
||||
{
|
||||
return mInner->EndUpdateBatch();
|
||||
}
|
||||
|
||||
|
||||
// nsIRDFRemoteDataSource
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::GetLoaded(PRBool* aResult)
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->GetLoaded(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Init(const char* aURI)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Refresh(PRBool aBlocking)
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->Refresh(aBlocking);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::Flush()
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->Flush();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlService::FlushTo(const char *aURI)
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->FlushTo(aURI);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
mozSqlService::EnsureAliasesContainer()
|
||||
{
|
||||
if (! mAliasesContainer) {
|
||||
PRBool isContainer;
|
||||
nsresult rv = gRDFContainerUtils->IsContainer(mInner, kSQL_AliasesRoot, &isContainer);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!isContainer) {
|
||||
rv = gRDFContainerUtils->MakeSeq(mInner, kSQL_AliasesRoot, getter_AddRefs(mAliasesContainer));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
mAliasesContainer = do_CreateInstance(NS_RDF_CONTRACTID "/container;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mAliasesContainer->Init(mInner, kSQL_AliasesRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#ifndef mozSqlService_h
|
||||
#define mozSqlService_h
|
||||
|
||||
#include "nsHashtable.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFRemoteDataSource.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIRDFContainerUtils.h"
|
||||
#include "mozISqlService.h"
|
||||
|
||||
#define MOZ_SQLSERVICE_CLASSNAME "SQL service"
|
||||
#define MOZ_SQLSERVICE_CID \
|
||||
{0x1ceb35b7, 0xdaa8, 0x4ce4, {0xac, 0x67, 0x12, 0x5f, 0xb1, 0x7c, 0xb0, 0x19}}
|
||||
#define MOZ_SQLSERVICE_CONTRACTID "@mozilla.org/sql/service;1"
|
||||
#define MOZ_SQLDATASOURCE_CONTRACTID "@mozilla.org/rdf/datasource;1?name=sql"
|
||||
|
||||
class mozSqlService : public mozISqlService,
|
||||
public nsIRDFDataSource,
|
||||
public nsIRDFRemoteDataSource
|
||||
{
|
||||
public:
|
||||
mozSqlService();
|
||||
virtual ~mozSqlService();
|
||||
nsresult Init();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_MOZISQLSERVICE
|
||||
NS_DECL_NSIRDFDATASOURCE
|
||||
NS_DECL_NSIRDFREMOTEDATASOURCE
|
||||
|
||||
protected:
|
||||
nsresult EnsureAliasesContainer();
|
||||
|
||||
private:
|
||||
static nsIRDFService* gRDFService;
|
||||
static nsIRDFContainerUtils* gRDFContainerUtils;
|
||||
|
||||
static nsIRDFResource* kSQL_AliasesRoot;
|
||||
static nsIRDFResource* kSQL_Name;
|
||||
static nsIRDFResource* kSQL_Type;
|
||||
static nsIRDFResource* kSQL_Hostname;
|
||||
static nsIRDFResource* kSQL_Port;
|
||||
static nsIRDFResource* kSQL_Database;
|
||||
|
||||
nsString mErrorMessage;
|
||||
nsCOMPtr<nsIRDFDataSource> mInner;
|
||||
nsCOMPtr<nsIRDFContainer> mAliasesContainer;
|
||||
nsSupportsHashtable* mConnectionCache;
|
||||
|
||||
};
|
||||
|
||||
#endif /* mozSqlService_h */
|
||||
@@ -1,21 +0,0 @@
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = \
|
||||
src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
XPI_FILE = sql-$(shell date +%Y%m%d)-$(OS_ARCH).xpi
|
||||
|
||||
xpi:
|
||||
zip -j $(DIST)/$(XPI_FILE) $(srcdir)/install.js
|
||||
cd $(DIST); zip -r $(XPI_FILE) \
|
||||
bin/components/sql.xpt \
|
||||
bin/components/sqlpgsql.xpt \
|
||||
bin/components/$(LIB_PREFIX)sql$(DLL_SUFFIX) \
|
||||
bin/chrome/sql.jar
|
||||
@@ -1,58 +0,0 @@
|
||||
// this function verifies disk space in kilobytes
|
||||
function verifyDiskSpace(dirPath, spaceRequired)
|
||||
{
|
||||
var spaceAvailable;
|
||||
|
||||
// Get the available disk space on the given path
|
||||
spaceAvailable = fileGetDiskSpaceAvailable(dirPath);
|
||||
|
||||
// Convert the available disk space into kilobytes
|
||||
spaceAvailable = parseInt(spaceAvailable / 1024);
|
||||
|
||||
// do the verification
|
||||
if(spaceAvailable < spaceRequired)
|
||||
{
|
||||
logComment("Insufficient disk space: " + dirPath);
|
||||
logComment(" required : " + spaceRequired + " K");
|
||||
logComment(" available: " + spaceAvailable + " K");
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
var srDest = 200;
|
||||
|
||||
var err = initInstall("SQL Support", "SQL", "0.1");
|
||||
logComment("initInstall: " + err);
|
||||
|
||||
var fProgram = getFolder("Program");
|
||||
logComment("fProgram: " + fProgram);
|
||||
|
||||
if (verifyDiskSpace(fProgram, srDest))
|
||||
{
|
||||
err = addDirectory("Program", "0.1", "bin", fProgram, "", true);
|
||||
|
||||
logComment("addDirectory() returned: " + err);
|
||||
|
||||
var chromeFolder = getFolder("Chrome", "sql.jar");
|
||||
registerChrome(CONTENT | DELAYED_CHROME, chromeFolder, "content/sql/");
|
||||
registerChrome(LOCALE | DELAYED_CHROME, chromeFolder, "locale/en-US/sql/");
|
||||
|
||||
err = getLastError();
|
||||
if (err == ACCESS_DENIED) {
|
||||
alert("Unable to write to program directory " + fProgram + ".\n You will need to restart the browser with administrator/root privileges to install this software. After installing as root (or administrator), you will need to restart the browser one more time to register the installed software.\n After the second restart, you can go back to running the browser without privileges!");
|
||||
cancelInstall(err);
|
||||
logComment("cancelInstall() due to error: " + err);
|
||||
}
|
||||
else if (err != SUCCESS) {
|
||||
cancelInstall(err);
|
||||
logComment("cancelInstall() due to error: " + err);
|
||||
}
|
||||
else {
|
||||
performInstall();
|
||||
logComment("performInstall() returned: " + err);
|
||||
}
|
||||
}
|
||||
else
|
||||
cancelInstall(INSUFFICIENT_DISK_SPACE);
|
||||
@@ -1,40 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = sql
|
||||
MODULE_NAME = sqlModule
|
||||
LIBRARY_NAME = sql
|
||||
SHORT_LIBNAME = sql
|
||||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
rdf \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
mozSqlModule.cpp
|
||||
|
||||
SHARED_LIBRARY_LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)sqlbase_s.$(LIB_SUFFIX)
|
||||
|
||||
EXTRA_DSO_LDOPTS = \
|
||||
$(MOZ_COMPONENT_LIBS) \
|
||||
$(MOZ_UNICHARUTIL_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_ENABLE_PGSQL
|
||||
DEFINES += -DMOZ_ENABLE_PGSQL
|
||||
SHARED_LIBRARY_LIBS += $(DIST)/lib/$(LIB_PREFIX)sqlpgsql_s.$(LIB_SUFFIX)
|
||||
EXTRA_DSO_LDOPTS += -L$(MOZ_PGSQL_LIBS) -lpq
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifdef MOZ_ENABLE_PGSQL
|
||||
INCLUDES += -I$(MOZ_PGSQL_INCLUDES)
|
||||
endif
|
||||
@@ -1,33 +0,0 @@
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "mozSqlService.h"
|
||||
#ifdef MOZ_ENABLE_PGSQL
|
||||
#include "mozSqlConnectionPgsql.h"
|
||||
#endif
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozSqlService, Init)
|
||||
#ifdef MOZ_ENABLE_PGSQL
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(mozSqlConnectionPgsql)
|
||||
#endif
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ MOZ_SQLSERVICE_CLASSNAME,
|
||||
MOZ_SQLSERVICE_CID,
|
||||
MOZ_SQLSERVICE_CONTRACTID,
|
||||
mozSqlServiceConstructor
|
||||
},
|
||||
{ MOZ_SQLSERVICE_CLASSNAME,
|
||||
MOZ_SQLSERVICE_CID,
|
||||
MOZ_SQLDATASOURCE_CONTRACTID,
|
||||
mozSqlServiceConstructor
|
||||
},
|
||||
#ifdef MOZ_ENABLE_PGSQL
|
||||
{ MOZ_SQLCONNECTIONPGSQL_CLASSNAME,
|
||||
MOZ_SQLCONNECTIONPGSQL_CID,
|
||||
MOZ_SQLCONNECTIONPGSQL_CONTRACTID,
|
||||
mozSqlConnectionPgsqlConstructor
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("sql", components)
|
||||
@@ -1,10 +0,0 @@
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
DIRS = \
|
||||
public \
|
||||
src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,14 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
MODULE = sql
|
||||
XPIDL_MODULE = sqlpgsql
|
||||
|
||||
XPIDLSRCS = \
|
||||
mozISqlConnectionPgsql.idl \
|
||||
mozISqlResultPgsql.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(0cf1eefe-611d-48fa-ae27-0a6f40d6a33e)]
|
||||
|
||||
interface mozISqlConnectionPgsql : nsISupports
|
||||
{
|
||||
|
||||
};
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(f6573169-286d-4a20-8253-9abb07bdba29)]
|
||||
|
||||
interface mozISqlResultPgsql : nsISupports
|
||||
{
|
||||
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = sql
|
||||
LIBRARY_NAME = sqlpgsql_s
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
locale \
|
||||
rdf \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
mozSqlConnectionPgsql.cpp \
|
||||
mozSqlResultPgsql.cpp
|
||||
|
||||
EXPORTS = \
|
||||
mozSqlConnectionPgsql.h \
|
||||
mozSqlResultPgsql.h
|
||||
|
||||
FORCE_STATIC_LIB=1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
INCLUDES += -I$(MOZ_PGSQL_INCLUDES)
|
||||
@@ -1,240 +0,0 @@
|
||||
#include "prprf.h"
|
||||
#include "mozSqlConnectionPgsql.h"
|
||||
#include "mozSqlResultPgsql.h"
|
||||
|
||||
mozSqlConnectionPgsql::mozSqlConnectionPgsql()
|
||||
: mConnection(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
mozSqlConnectionPgsql::~mozSqlConnectionPgsql()
|
||||
{
|
||||
if (mConnection)
|
||||
PQfinish(mConnection);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(mozSqlConnectionPgsql, mozSqlConnection)
|
||||
NS_IMPL_RELEASE_INHERITED(mozSqlConnectionPgsql, mozSqlConnection)
|
||||
|
||||
// QueryInterface
|
||||
NS_INTERFACE_MAP_BEGIN(mozSqlConnectionPgsql)
|
||||
NS_INTERFACE_MAP_ENTRY(mozISqlConnectionPgsql)
|
||||
NS_INTERFACE_MAP_END_INHERITING(mozSqlConnection)
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnectionPgsql::Init(const nsAString & aHost, PRInt32 aPort,
|
||||
const nsAString & aDatabase, const nsAString & aUsername,
|
||||
const nsAString & aPassword)
|
||||
{
|
||||
if (mConnection)
|
||||
return NS_OK;
|
||||
|
||||
if (aPort == -1)
|
||||
aPort = 5432;
|
||||
char port[11];
|
||||
char options[] = "";
|
||||
char tty[] = "";
|
||||
PR_snprintf(port, 11, "%d", aPort);
|
||||
|
||||
mConnection = PQsetdbLogin(NS_ConvertUCS2toUTF8(aHost).get(),
|
||||
port, options, tty,
|
||||
NS_ConvertUCS2toUTF8(aDatabase).get(),
|
||||
NS_ConvertUCS2toUTF8(aUsername).get(),
|
||||
NS_ConvertUCS2toUTF8(aPassword).get());
|
||||
|
||||
return Setup();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozSqlConnectionPgsql::GetPrimaryKeys(const nsAString& aSchema, const nsAString& aTable, mozISqlResult** _retval)
|
||||
{
|
||||
nsAutoString select;
|
||||
nsAutoString from;
|
||||
nsAutoString where;
|
||||
if (mVersion >= SERVER_VERSION(7,3,0)) {
|
||||
select = NS_LITERAL_STRING("SELECT n.nspname AS TABLE_SCHEM, ");
|
||||
from = NS_LITERAL_STRING(" FROM pg_catalog.pg_namespace n, pg_catalog.pg_class ct, pg_catalog.pg_class ci, pg_catalog.pg_attribute a, pg_catalog.pg_index i");
|
||||
where = NS_LITERAL_STRING(" AND ct.relnamespace = n.oid ");
|
||||
if (!aSchema.IsEmpty()) {
|
||||
where.Append(NS_LITERAL_STRING(" AND n.nspname = '") + aSchema);
|
||||
where.Append(PRUnichar('\''));
|
||||
}
|
||||
}
|
||||
else {
|
||||
select = NS_LITERAL_STRING("SELECT NULL AS TABLE_SCHEM, ");
|
||||
from = NS_LITERAL_STRING(" FROM pg_class ct, pg_class ci, pg_attribute a, pg_index i ");
|
||||
}
|
||||
|
||||
if (!aTable.IsEmpty()) {
|
||||
where.Append(NS_LITERAL_STRING(" AND ct.relname = '") + aTable);
|
||||
where.Append(PRUnichar('\''));
|
||||
}
|
||||
|
||||
NS_NAMED_LITERAL_STRING(select2, " ct.relname AS TABLE_NAME, a.attname AS COLUMN_NAME, a.attnum AS KEY_SEQ, ci.relname AS PK_NAME ");
|
||||
NS_NAMED_LITERAL_STRING(where2, " WHERE ct.oid=i.indrelid AND ci.oid=i.indexrelid AND a.attrelid=ci.oid AND i.indisprimary ");
|
||||
NS_NAMED_LITERAL_STRING(order2, " ORDER BY table_name, pk_name, key_seq");
|
||||
|
||||
return RealExec(select + select2 + from + where2 + where + order2, _retval, nsnull);
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlConnectionPgsql::Setup()
|
||||
{
|
||||
if (PQstatus(mConnection) == CONNECTION_BAD) {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQerrorMessage(mConnection)));
|
||||
mConnection = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PQsetClientEncoding(mConnection, "UNICODE");
|
||||
|
||||
/*
|
||||
PGresult* result = PQexec(mConnection, "SET DATESTYLE TO US");
|
||||
PRInt32 stat = PQresultStatus(result);
|
||||
if (stat != PGRES_COMMAND_OK) {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQresultErrorMessage(result)));
|
||||
PQfinish(mConnection);
|
||||
mConnection = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
*/
|
||||
|
||||
PGresult* result = PQexec(mConnection, "select version()");
|
||||
PRInt32 stat = PQresultStatus(result);
|
||||
if (stat != PGRES_TUPLES_OK) {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQresultErrorMessage(result)));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
char* version = PQgetvalue(result, 0, 0);
|
||||
NS_ConvertUTF8toUCS2 buffer(version);
|
||||
nsAString::const_iterator start, end, iter;
|
||||
buffer.BeginReading(iter);
|
||||
buffer.EndReading(end);
|
||||
while (iter != end && !nsCRT::IsAsciiSpace(*iter))
|
||||
++iter;
|
||||
while (iter != end && nsCRT::IsAsciiSpace(*iter))
|
||||
++iter;
|
||||
start = iter;
|
||||
while (iter != end && !nsCRT::IsAsciiSpace(*iter))
|
||||
++iter;
|
||||
mServerVersion = Substring(start,iter);
|
||||
|
||||
PRInt32 numbers[3] = {0,0,0};
|
||||
mServerVersion.BeginReading(iter);
|
||||
mServerVersion.EndReading(end);
|
||||
for (PRInt32 i = 0; i < 3; i++) {
|
||||
start = iter;
|
||||
while (iter != end && *iter != PRUnichar('.'))
|
||||
++iter;
|
||||
nsAutoString v(Substring(start,iter));
|
||||
PRInt32 err;
|
||||
numbers[i] = v.ToInteger(&err);
|
||||
while (iter != end && *iter == PRUnichar('.'))
|
||||
++iter;
|
||||
}
|
||||
mVersion = SERVER_VERSION(numbers[0], numbers[1], numbers[2]);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlConnectionPgsql::RealExec(const nsAString& aQuery,
|
||||
mozISqlResult** aResult, PRInt32* aAffectedRows)
|
||||
{
|
||||
if (! mConnection)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
PGresult* r;
|
||||
r = PQexec(mConnection, NS_ConvertUCS2toUTF8(aQuery).get());
|
||||
PRInt32 stat = PQresultStatus(r);
|
||||
|
||||
if (PQstatus(mConnection) == CONNECTION_BAD) {
|
||||
PQreset(mConnection);
|
||||
nsresult rv = Setup();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
r = PQexec(mConnection, NS_ConvertUCS2toUTF8(aQuery).get());
|
||||
stat = PQresultStatus(r);
|
||||
}
|
||||
|
||||
if (stat == PGRES_TUPLES_OK) {
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
static char select1[] = "select t.oid, case when t.typbasetype = 0 then t.typname else (select t2.typname from pg_type t2 where t2.oid=t.typbasetype) end as typname from pg_type t where t.oid in (";
|
||||
static char select2[] = "select oid, typname from pg_type where oid in (";
|
||||
char* select;
|
||||
if (mVersion >= SERVER_VERSION(7,3,0))
|
||||
select = select1;
|
||||
else
|
||||
select = select2;
|
||||
PRInt32 columnCount = PQnfields(r);
|
||||
char* query = (char*)malloc(strlen(select) + columnCount * 11 + 2);
|
||||
strcpy(query, select);
|
||||
for (PRInt32 i = 0; i < columnCount; i++) {
|
||||
PRInt32 oid = PQftype(r, i);
|
||||
char oidStr[11];
|
||||
if (i)
|
||||
sprintf(oidStr, ",%d", oid);
|
||||
else
|
||||
sprintf(oidStr, "%d", oid);
|
||||
strcat(query, oidStr);
|
||||
}
|
||||
strcat(query, ")");
|
||||
PGresult* types = PQexec(mConnection, query);
|
||||
free(query);
|
||||
stat = PQresultStatus(types);
|
||||
if (stat != PGRES_TUPLES_OK) {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQresultErrorMessage(types)));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (*aResult) {
|
||||
((mozSqlResultPgsql*)*aResult)->SetResult(r, types);
|
||||
nsresult rv = ((mozSqlResult*)*aResult)->Rebuild();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
NS_ADDREF(*aResult);
|
||||
}
|
||||
else {
|
||||
mozSqlResult* result = new mozSqlResultPgsql(this, aQuery);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
((mozSqlResultPgsql*)result)->SetResult(r, types);
|
||||
nsresult rv = result->Init();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
NS_ADDREF(*aResult = result);
|
||||
}
|
||||
}
|
||||
else if (stat == PGRES_COMMAND_OK) {
|
||||
if (!aAffectedRows)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
PR_sscanf(PQcmdTuples(r), "%d", aAffectedRows);
|
||||
mLastID = PQoidValue(r);
|
||||
}
|
||||
else {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQresultErrorMessage(r)));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlConnectionPgsql::CancelExec()
|
||||
{
|
||||
if (!PQrequestCancel(mConnection)) {
|
||||
mErrorMessage.Assign(NS_ConvertUTF8toUCS2(PQerrorMessage(mConnection)));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlConnectionPgsql::GetIDName(nsAString& aIDName)
|
||||
{
|
||||
aIDName = NS_LITERAL_STRING("OID");
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
#ifndef mozSqlConnectionPgsql_h
|
||||
#define mozSqlConnectionPgsql_h
|
||||
|
||||
#include "libpq-fe.h"
|
||||
#include "mozSqlConnection.h"
|
||||
#include "mozISqlConnectionPgsql.h"
|
||||
|
||||
#define MOZ_SQLCONNECTIONPGSQL_CLASSNAME "PosgreSQL SQL Connection"
|
||||
#define MOZ_SQLCONNECTIONPGSQL_CID \
|
||||
{0x0cf1eefe, 0x611d, 0x48fa, {0xae, 0x27, 0x0a, 0x6f, 0x40, 0xd6, 0xa3, 0x3e }}
|
||||
#define MOZ_SQLCONNECTIONPGSQL_CONTRACTID "@mozilla.org/sql/connection;1?type=pgsql"
|
||||
|
||||
#define SERVER_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
|
||||
class mozSqlConnectionPgsql : public mozSqlConnection,
|
||||
public mozISqlConnectionPgsql
|
||||
{
|
||||
public:
|
||||
mozSqlConnectionPgsql();
|
||||
virtual ~mozSqlConnectionPgsql();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(const nsAString& aHost, PRInt32 aPort,
|
||||
const nsAString& aDatabase, const nsAString& aUsername,
|
||||
const nsAString& aPassword);
|
||||
|
||||
NS_IMETHOD GetPrimaryKeys(const nsAString& aSchema, const nsAString& aTable, mozISqlResult** _retval);
|
||||
|
||||
NS_DECL_MOZISQLCONNECTIONPGSQL
|
||||
|
||||
protected:
|
||||
nsresult Setup();
|
||||
|
||||
virtual nsresult RealExec(const nsAString& aQuery,
|
||||
mozISqlResult** aResult, PRInt32* aAffectedRows);
|
||||
|
||||
virtual nsresult CancelExec();
|
||||
|
||||
virtual nsresult GetIDName(nsAString& aIDName);
|
||||
|
||||
private:
|
||||
PGconn* mConnection;
|
||||
PRInt32 mVersion;
|
||||
};
|
||||
|
||||
#endif // mozSqlConnectionPgsql_h
|
||||
@@ -1,235 +0,0 @@
|
||||
|
||||
#include "prprf.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "mozSqlResultPgsql.h"
|
||||
|
||||
mozSqlResultPgsql::mozSqlResultPgsql(mozISqlConnection* aConnection,
|
||||
const nsAString& aQuery)
|
||||
: mozSqlResult(aConnection, aQuery),
|
||||
mResult(nsnull),
|
||||
mTypes(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
mozSqlResultPgsql::SetResult(PGresult* aResult,
|
||||
PGresult* aTypes)
|
||||
{
|
||||
mResult = aResult;
|
||||
mTypes = aTypes;
|
||||
}
|
||||
|
||||
mozSqlResultPgsql::~mozSqlResultPgsql()
|
||||
{
|
||||
ClearNativeResult();
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(mozSqlResultPgsql, mozSqlResult)
|
||||
NS_IMPL_RELEASE_INHERITED(mozSqlResultPgsql, mozSqlResult)
|
||||
|
||||
// QueryInterface
|
||||
NS_INTERFACE_MAP_BEGIN(mozSqlResultPgsql)
|
||||
NS_INTERFACE_MAP_ENTRY(mozISqlResultPgsql)
|
||||
NS_INTERFACE_MAP_END_INHERITING(mozSqlResult)
|
||||
|
||||
PRInt32
|
||||
mozSqlResultPgsql::GetColType(PRInt32 aColumnIndex)
|
||||
{
|
||||
PRInt32 oid = PQftype(mResult, aColumnIndex);
|
||||
|
||||
for (PRInt32 i = 0; i < PQntuples(mTypes); i++) {
|
||||
char* value = PQgetvalue(mTypes, i, 0);
|
||||
PRInt32 o;
|
||||
PR_sscanf(value, "%d", &o);
|
||||
if (o == oid) {
|
||||
char* type = PQgetvalue(mTypes, i, 1);
|
||||
if (! strcmp(type, "int2"))
|
||||
return mozISqlResult::TYPE_INT;
|
||||
else if (! strcmp(type, "int4"))
|
||||
return mozISqlResult::TYPE_INT;
|
||||
else if (! strcmp(type, "float4"))
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
else if (! strcmp(type, "numeric"))
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
else if (! strcmp(type, "date"))
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
else if (! strcmp(type, "time"))
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
else if (! strcmp(type, "timestamp"))
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
else if (! strcmp(type, "bool"))
|
||||
return mozISqlResult::TYPE_BOOL;
|
||||
else
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
}
|
||||
}
|
||||
|
||||
return mozISqlResult::TYPE_STRING;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::BuildColumnInfo()
|
||||
{
|
||||
for (PRInt32 i = 0; i < PQnfields(mResult); i++) {
|
||||
char* n = PQfname(mResult, i);
|
||||
PRUnichar* name = ToNewUnicode(NS_ConvertUTF8toUCS2(n));
|
||||
PRInt32 type = GetColType(i);
|
||||
PRInt32 size = PQfsize(mResult, i);
|
||||
PRInt32 mod = PQfmod(mResult, i);
|
||||
|
||||
nsCAutoString uri(NS_LITERAL_CSTRING("http://www.mozilla.org/SQL-rdf#"));
|
||||
uri.Append(n);
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
gRDFService->GetResource(uri, getter_AddRefs(property));
|
||||
|
||||
ColumnInfo* columnInfo = ColumnInfo::Create(mAllocator, name, type, size, mod, property);
|
||||
mColumnInfo.AppendElement(columnInfo);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::BuildRows()
|
||||
{
|
||||
for(PRInt32 i = 0; i < PQntuples(mResult); i++) {
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
nsresult rv = gRDFService->GetAnonymousResource(getter_AddRefs(resource));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
Row* row = Row::Create(mAllocator, resource, mColumnInfo);
|
||||
|
||||
for (PRInt32 j = 0; j < mColumnInfo.Count(); j++) {
|
||||
if (! PQgetisnull(mResult, i, j)) {
|
||||
char* value = PQgetvalue(mResult, i, j);
|
||||
Cell* cell = row->mCells[j];
|
||||
cell->SetNull(PR_FALSE);
|
||||
PRInt32 type = cell->GetType();
|
||||
if (type == mozISqlResult::TYPE_STRING)
|
||||
cell->SetString(ToNewUnicode(NS_ConvertUTF8toUCS2(value)));
|
||||
else if (type == mozISqlResult::TYPE_INT)
|
||||
PR_sscanf(value, "%d", &cell->mInt);
|
||||
else if (type == mozISqlResult::TYPE_FLOAT)
|
||||
PR_sscanf(value, "%f", &cell->mFloat);
|
||||
else if (type == mozISqlResult::TYPE_DECIMAL)
|
||||
PR_sscanf(value, "%f", &cell->mFloat);
|
||||
else if (type == mozISqlResult::TYPE_DATE ||
|
||||
type == mozISqlResult::TYPE_TIME ||
|
||||
type == mozISqlResult::TYPE_DATETIME)
|
||||
PR_ParseTimeString(value, PR_FALSE, &cell->mDate);
|
||||
else if (type == mozISqlResult::TYPE_BOOL)
|
||||
cell->mBool = !strcmp(value, "t");
|
||||
}
|
||||
}
|
||||
|
||||
mRows.AppendElement(row);
|
||||
nsVoidKey key(resource);
|
||||
mSources.Put(&key, row);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
mozSqlResultPgsql::ClearNativeResult()
|
||||
{
|
||||
if (mResult) {
|
||||
PQclear(mResult);
|
||||
mResult = nsnull;
|
||||
}
|
||||
if (mTypes) {
|
||||
PQclear(mTypes);
|
||||
mTypes = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::EnsureTablePrivileges()
|
||||
{
|
||||
nsresult rv = EnsureTableName();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
NS_NAMED_LITERAL_STRING(select, "select ");
|
||||
NS_NAMED_LITERAL_STRING(func, "has_table_privilege(SESSION_USER, '");
|
||||
NS_NAMED_LITERAL_STRING(comma, ", ");
|
||||
NS_NAMED_LITERAL_STRING(ins, "', 'INSERT')");
|
||||
NS_NAMED_LITERAL_STRING(upd, "', 'UPDATE')");
|
||||
NS_NAMED_LITERAL_STRING(del, "','DELETE')");
|
||||
|
||||
nsCOMPtr<mozISqlResult> result;
|
||||
rv = mConnection->ExecuteQuery(
|
||||
select + func + mTableName + ins +
|
||||
comma + func + mTableName + upd +
|
||||
comma + func + mTableName + del,
|
||||
getter_AddRefs(result));
|
||||
if (NS_FAILED(rv)) {
|
||||
mConnection->GetErrorMessage(mErrorMessage);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<mozISqlResultEnumerator> enumerator;
|
||||
rv = result->Enumerate(getter_AddRefs(enumerator));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = enumerator->First();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = enumerator->GetBool(0, &mCanInsert);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = enumerator->GetBool(1, &mCanUpdate);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
return enumerator->GetBool(2, &mCanDelete);
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::CanInsert(PRBool* _retval)
|
||||
{
|
||||
if (mCanInsert >= 0) {
|
||||
*_retval = mCanInsert;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = EnsureTablePrivileges();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
*_retval = mCanInsert;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::CanUpdate(PRBool* _retval)
|
||||
{
|
||||
if (mCanUpdate >= 0) {
|
||||
*_retval = mCanUpdate;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = EnsureTablePrivileges();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
*_retval = mCanUpdate;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
mozSqlResultPgsql::CanDelete(PRBool* _retval)
|
||||
{
|
||||
if (mCanDelete >= 0) {
|
||||
*_retval = mCanDelete;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = EnsureTablePrivileges();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
*_retval = mCanDelete;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#ifndef mozSqlResultPgsql_h
|
||||
#define mozSqlResultPgsql_h
|
||||
|
||||
#include "libpq-fe.h"
|
||||
#include "mozSqlResult.h"
|
||||
#include "mozISqlResultPgsql.h"
|
||||
|
||||
class mozSqlResultPgsql : public mozSqlResult,
|
||||
public mozISqlResultPgsql
|
||||
{
|
||||
public:
|
||||
mozSqlResultPgsql(mozISqlConnection* aConnection,
|
||||
const nsAString& aQuery);
|
||||
void SetResult(PGresult* aResult,
|
||||
PGresult* aTypes);
|
||||
virtual ~mozSqlResultPgsql();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_MOZISQLRESULTPGSQL
|
||||
|
||||
protected:
|
||||
PRInt32 GetColType(PRInt32 aColumnIndex);
|
||||
|
||||
virtual nsresult BuildColumnInfo();
|
||||
virtual nsresult BuildRows();
|
||||
virtual void ClearNativeResult();
|
||||
|
||||
nsresult EnsureTablePrivileges();
|
||||
virtual nsresult CanInsert(PRBool* _retval);
|
||||
virtual nsresult CanUpdate(PRBool* _retval);
|
||||
virtual nsresult CanDelete(PRBool* _retval);
|
||||
|
||||
private:
|
||||
PGresult* mResult;
|
||||
PGresult* mTypes;
|
||||
};
|
||||
|
||||
#endif // mozSqlResultPgsql_h
|
||||
@@ -1,15 +0,0 @@
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
XPI_FILE = sqltest-$(shell date +%Y%m%d).xpi
|
||||
|
||||
xpi:
|
||||
zip -j $(DIST)/$(XPI_FILE) $(srcdir)/install.js
|
||||
cd $(DIST); zip -r $(XPI_FILE) \
|
||||
bin/chrome/sqltest.jar
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
|
||||
|
||||
<!-- list all the packages being supplied by this jar -->
|
||||
<RDF:Seq about="urn:mozilla:package:root">
|
||||
<RDF:li resource="urn:mozilla:package:sqltest"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- package information -->
|
||||
<RDF:Description about="urn:mozilla:package:sqltest"
|
||||
chrome:displayName="SQL test"
|
||||
chrome:author="mozilla.org"
|
||||
chrome:name="sqltest">
|
||||
</RDF:Description>
|
||||
|
||||
</RDF:RDF>
|
||||
@@ -1,57 +0,0 @@
|
||||
// this function verifies disk space in kilobytes
|
||||
function verifyDiskSpace(dirPath, spaceRequired)
|
||||
{
|
||||
var spaceAvailable;
|
||||
|
||||
// Get the available disk space on the given path
|
||||
spaceAvailable = fileGetDiskSpaceAvailable(dirPath);
|
||||
|
||||
// Convert the available disk space into kilobytes
|
||||
spaceAvailable = parseInt(spaceAvailable / 1024);
|
||||
|
||||
// do the verification
|
||||
if(spaceAvailable < spaceRequired)
|
||||
{
|
||||
logComment("Insufficient disk space: " + dirPath);
|
||||
logComment(" required : " + spaceRequired + " K");
|
||||
logComment(" available: " + spaceAvailable + " K");
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
var srDest = 100;
|
||||
|
||||
var err = initInstall("SQL test", "SQLTEST", "0.1");
|
||||
logComment("initInstall: " + err);
|
||||
|
||||
var fProgram = getFolder("Program");
|
||||
logComment("fProgram: " + fProgram);
|
||||
|
||||
if (verifyDiskSpace(fProgram, srDest))
|
||||
{
|
||||
err = addDirectory("Program", "0.1", "bin", fProgram, "", true);
|
||||
|
||||
logComment("addDirectory() returned: " + err);
|
||||
|
||||
var chromeFolder = getFolder("Chrome", "sqltest.jar");
|
||||
registerChrome(CONTENT | DELAYED_CHROME, chromeFolder, "content/sqltest/");
|
||||
|
||||
err = getLastError();
|
||||
if (err == ACCESS_DENIED) {
|
||||
alert("Unable to write to program directory " + fProgram + ".\n You will need to restart the browser with administrator/root privileges to install this software. After installing as root (or administrator), you will need to restart the browser one more time to register the installed software.\n After the second restart, you can go back to running the browser without privileges!");
|
||||
cancelInstall(err);
|
||||
logComment("cancelInstall() due to error: " + err);
|
||||
}
|
||||
else if (err != SUCCESS) {
|
||||
cancelInstall(err);
|
||||
logComment("cancelInstall() due to error: " + err);
|
||||
}
|
||||
else {
|
||||
performInstall();
|
||||
logComment("performInstall() returned: " + err);
|
||||
}
|
||||
}
|
||||
else
|
||||
cancelInstall(INSUFFICIENT_DISK_SPACE);
|
||||
@@ -1,7 +0,0 @@
|
||||
sqltest.jar:
|
||||
content/sqltest/contents.rdf (contents.rdf)
|
||||
content/sqltest/sqltest.xul (sqltest.xul)
|
||||
content/sqltest/sqltest.js (sqltest.js)
|
||||
content/sqltest/sqltest.css (sqltest.css)
|
||||
content/sqltest/sqltestDialog.xul (sqltestDialog.xul)
|
||||
content/sqltest/sqltestDialog.js (sqltestDialog.js)
|
||||
@@ -1,8 +0,0 @@
|
||||
treechildren:-moz-tree-cell {
|
||||
border-right: 1px solid ThreeDFace;
|
||||
border-bottom: 1px solid ThreeDFace;
|
||||
}
|
||||
|
||||
.spacer {
|
||||
height: 10px;
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
const alias = "urn:aliases:sqltest";
|
||||
const complete = Components.interfaces.mozISqlRequest.STATUS_COMPLETE;
|
||||
|
||||
var connection;
|
||||
var result;
|
||||
|
||||
var startupObserver = {
|
||||
onStartRequest: function(request, ctxt) {
|
||||
},
|
||||
onStopRequest: function(request, ctxt) {
|
||||
if (request.status == complete) {
|
||||
result = request.result;
|
||||
var ds = result.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
||||
|
||||
var menulist = document.getElementById("statesMenulist");
|
||||
menulist.database.AddDataSource(ds);
|
||||
menulist.builder.rebuild();
|
||||
menulist.selectedIndex = 0;
|
||||
|
||||
var tree = document.getElementById("statesTree");
|
||||
tree.database.AddDataSource(ds);
|
||||
tree.builder.rebuild();
|
||||
}
|
||||
else {
|
||||
alert(request.errorMessage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var observer = {
|
||||
onStartRequest: function(request, ctxt) {
|
||||
},
|
||||
|
||||
onStopRequest: function(request, ctxt) {
|
||||
if (request.status == complete) {
|
||||
var element = document.getElementById("asyncStateName");
|
||||
if (request.result.rowCount) {
|
||||
var enumerator = request.result.enumerate();
|
||||
enumerator.first();
|
||||
element.value = enumerator.getVariant(0);
|
||||
}
|
||||
else {
|
||||
element.value = "Not found";
|
||||
}
|
||||
}
|
||||
else {
|
||||
alert(request.errorMessage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
var service = Components.classes["@mozilla.org/sql/service;1"]
|
||||
.getService(Components.interfaces.mozISqlService);
|
||||
|
||||
if (!service.hasAlias(alias)) {
|
||||
alert("The alias for the sqltest was not defined.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
connection = service.getConnection(alias);
|
||||
}
|
||||
catch (ex) {
|
||||
alert(service.errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
var query = "select code, name from states";
|
||||
var request = connection.asyncExecuteQuery(query, null, startupObserver);
|
||||
}
|
||||
|
||||
function syncFindState() {
|
||||
var code = document.getElementById("syncStateCode").value
|
||||
var query = "select name from states where code = '" + code + "'";
|
||||
try {
|
||||
var result = connection.executeQuery(query);
|
||||
var element = document.getElementById("syncStateName");
|
||||
if (result.rowCount) {
|
||||
var enumerator = result.enumerate();
|
||||
enumerator.first();
|
||||
element.value = enumerator.getVariant(0);
|
||||
}
|
||||
else {
|
||||
element.value = "Not found";
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
alert(connection.errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
function asyncFindState() {
|
||||
var code = document.getElementById("asyncStateCode").value;
|
||||
var query = "select name from states where code = '" + code + "'";
|
||||
var request = connection.asyncExecuteQuery(query, null, observer);
|
||||
}
|
||||
|
||||
function getSelectedRowIndex() {
|
||||
var tree = document.getElementById("statesTree");
|
||||
var currentIndex = tree.currentIndex;
|
||||
var resource = tree.builderView.getResourceAtIndex(currentIndex);
|
||||
var datasource = result.QueryInterface(Components.interfaces.mozISqlDataSource);
|
||||
return datasource.getIndexOfResource(resource);
|
||||
}
|
||||
|
||||
function doInsert() {
|
||||
window.openDialog("sqltestDialog.xul", "testDialog", "chrome,modal=yes,resizable=no", result);
|
||||
}
|
||||
|
||||
function doUpdate() {
|
||||
var rowIndex = this.getSelectedRowIndex();
|
||||
window.openDialog("sqltestDialog.xul", "testDialog", "chrome,modal=yes,resizable=no", result, rowIndex);
|
||||
}
|
||||
|
||||
function doDelete() {
|
||||
var rowIndex = this.getSelectedRowIndex();
|
||||
var enumerator = result.enumerate();
|
||||
enumerator.absolute(rowIndex);
|
||||
try {
|
||||
enumerator.deleteRow();
|
||||
}
|
||||
catch(ex) {
|
||||
alert(enumerator.errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
<?xml-stylesheet href="sqltest.css" type="text/css"?>
|
||||
|
||||
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
orient="vertical"
|
||||
width="640" height="480"
|
||||
title="SQL test"
|
||||
onload="init()">
|
||||
|
||||
<script type="application/x-javascript" src="sqltest.js"/>
|
||||
|
||||
<popupset>
|
||||
<popup id="editContextMenu">
|
||||
<menuitem label="Insert" oncommand="doInsert()"/>
|
||||
<menuitem label="Update" oncommand="doUpdate()"/>
|
||||
<menuitem label="Delete" oncommand="doDelete()"/>
|
||||
</popup>
|
||||
</popupset>
|
||||
|
||||
<tabbox flex="1">
|
||||
<tabs>
|
||||
<tab label="Sync test"/>
|
||||
<tab label="Async test"/>
|
||||
<tab label="Widgets"/>
|
||||
</tabs>
|
||||
<tabpanels flex="1">
|
||||
<vbox>
|
||||
<text class="label" value="Type a state code and then hit ENTER. You should get a state name."/>
|
||||
<spacer class="spacer"/>
|
||||
<grid>
|
||||
<columns>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<text class="label" value="State code:"/>
|
||||
<hbox>
|
||||
<textbox id="syncStateCode" size="2" maxlength="2" onkeyup="if (event.keyCode == 13) syncFindState()"/>
|
||||
</hbox>
|
||||
</row>
|
||||
<row>
|
||||
<text class="label" value="State name:"/>
|
||||
<textbox id="syncStateName"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<text class="label" value="Type a state code and then hit ENTER. You should get a state name."/>
|
||||
<spacer class="spacer"/>
|
||||
<grid>
|
||||
<columns>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<text class="label" value="State code:"/>
|
||||
<hbox>
|
||||
<textbox id="asyncStateCode" size="2" maxlength="2" onkeyup="if (event.keyCode == 13) asyncFindState()"/>
|
||||
</hbox>
|
||||
</row>
|
||||
<row>
|
||||
<text class="label" value="State name:"/>
|
||||
<textbox id="asyncStateName"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<text class="label" value="You should see a menulist filled with all the states."/>
|
||||
<spacer class="spacer"/>
|
||||
<hbox>
|
||||
<menulist id="statesMenulist"
|
||||
datasources="rdf:null" ref="SQL:ResultRoot">
|
||||
<template>
|
||||
<menupopup>
|
||||
<menuitem uri="..."
|
||||
value="rdf:http://www.mozilla.org/SQL-rdf#code"
|
||||
label="rdf:http://www.mozilla.org/SQL-rdf#name"/>
|
||||
</menupopup>
|
||||
</template>
|
||||
</menulist>
|
||||
</hbox>
|
||||
<spacer class="spacer"/>
|
||||
<text value="You should see codes and names of all states in this tree. You can even edit them using the context menu."/>
|
||||
<spacer class="spacer"/>
|
||||
<tree id="statesTree" flex="1"
|
||||
context="editContextMenu"
|
||||
seltype="single" enableColumnDrag="true"
|
||||
datasources="rdf:null" ref="SQL:ResultRoot" flags="dont-build-content">
|
||||
<treecols>
|
||||
<treecol id="codeCol"
|
||||
label="State code"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#code"
|
||||
sortActive="true" sortDirection="ascending"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
<treecol id="nameCol" flex="1"
|
||||
label="State name"
|
||||
sort="rdf:http://www.mozilla.org/SQL-rdf#name"/>
|
||||
</treecols>
|
||||
<template>
|
||||
<treechildren>
|
||||
<treeitem uri="rdf:*">
|
||||
<treerow>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#code"/>
|
||||
<treecell label="rdf:http://www.mozilla.org/SQL-rdf#name"/>
|
||||
</treerow>
|
||||
</treeitem>
|
||||
</treechildren>
|
||||
</template>
|
||||
</tree>
|
||||
</vbox>
|
||||
</tabpanels>
|
||||
</tabbox>
|
||||
|
||||
</window>
|
||||
@@ -1,41 +0,0 @@
|
||||
var result;
|
||||
var enumerator;
|
||||
|
||||
function init() {
|
||||
result = window.arguments[0];
|
||||
enumerator = result.enumerate();
|
||||
if (window.arguments.length == 2) {
|
||||
enumerator.absolute(window.arguments[1]);
|
||||
var columnCount = result.columnCount;
|
||||
for(var i = 0; i < columnCount; i++) {
|
||||
if (!enumerator.isNull(i)) {
|
||||
var element = document.getElementById(result.getColumnName(i));
|
||||
element.value = enumerator.getVariant(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onAccept() {
|
||||
var columnCount = result.columnCount;
|
||||
for (var i = 0; i < columnCount; i++) {
|
||||
var element = document.getElementById(result.getColumnName(i));
|
||||
if (element.value)
|
||||
enumerator.setVariant(i, element.value);
|
||||
else
|
||||
enumerator.setNull(i);
|
||||
}
|
||||
|
||||
try {
|
||||
if (window.arguments.length == 2)
|
||||
enumerator.updateRow();
|
||||
else
|
||||
enumerator.insertRow();
|
||||
}
|
||||
catch(ex) {
|
||||
alert(enumerator.errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
|
||||
<dialog id="testDialog"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="Test dialog"
|
||||
buttons="accept,cancel" buttonpack="center"
|
||||
ondialogaccept="return onAccept();"
|
||||
onload="init()">
|
||||
|
||||
<script type="application/x-javascript" src="sqltestDialog.js"/>
|
||||
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<label value="Code:"/>
|
||||
<hbox>
|
||||
<textbox id="code" size="2" maxlength="2" oninput="this.value = this.value.toUpperCase()"/>
|
||||
</hbox>
|
||||
</row>
|
||||
<row>
|
||||
<label value="Name:"/>
|
||||
<textbox id="name" size="30" maxlength="30"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
||||
</dialog>
|
||||
@@ -1,4 +0,0 @@
|
||||
create table states (
|
||||
code varchar(2) primary key,
|
||||
name varchar(30)
|
||||
);
|
||||
@@ -1,51 +0,0 @@
|
||||
AL Alabama
|
||||
AK Alaska
|
||||
AZ Arizona
|
||||
AR Arkansas
|
||||
CA California
|
||||
CO Colorado
|
||||
CT Connecticut
|
||||
DE Delaware
|
||||
FL Florida
|
||||
GA Georgia
|
||||
HI Hawaii
|
||||
ID Idaho
|
||||
IL Illinois
|
||||
IN Indiana
|
||||
IA Iowa
|
||||
KS Kansas
|
||||
KY Kentucky
|
||||
LA Louisiana
|
||||
ME Maine
|
||||
MD Maryland
|
||||
MA Massachusetts
|
||||
MI Michigan
|
||||
MN Minnesota
|
||||
MS Mississippi
|
||||
MO Missouri
|
||||
MT Montana
|
||||
NE Nebraska
|
||||
NV Nevada
|
||||
NH New Hampshire
|
||||
NJ New Jersey
|
||||
NM New Mexico
|
||||
NY New York
|
||||
NC North Carolina
|
||||
ND North Dakota
|
||||
OH Ohio
|
||||
OK Oklahoma
|
||||
OR Oregon
|
||||
PA Pennsylvania
|
||||
RI Rhode Island
|
||||
SC South Carolina
|
||||
SD South Dakota
|
||||
TN Tennessee
|
||||
TX Texas
|
||||
UT Utah
|
||||
VT Vermont
|
||||
VA Virginia
|
||||
WA Washington
|
||||
DC Washington,D.C.
|
||||
WV West Virginia
|
||||
WI Wisconsin
|
||||
WY Wyoming
|
||||
@@ -1,6 +0,0 @@
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
214
mozilla/js/rhino/Makefile
Normal file
214
mozilla/js/rhino/Makefile
Normal file
@@ -0,0 +1,214 @@
|
||||
#! gmake
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is Rhino code, released
|
||||
# May 6, 1998.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU Public License (the "GPL"), in which case the
|
||||
# provisions of the GPL are applicable instead of those above.
|
||||
# If you wish to allow use of your version of this file only
|
||||
# under the terms of the GPL and not to allow others to use your
|
||||
# version of this file under the NPL, indicate your decision by
|
||||
# deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this
|
||||
# file under either the NPL or the GPL.
|
||||
|
||||
#
|
||||
# Makefile for javascript in java.
|
||||
#
|
||||
|
||||
# This makefile is intended for packaging releases, and probably isn't
|
||||
# suitable for production use - it doesn't attempt to do understand
|
||||
# java dependencies beyond the package level.
|
||||
#
|
||||
# The makefiles for the subdirectories included in this package are
|
||||
# intended to be called by this makefile with the proper CLASSDIR,
|
||||
# PATH_PREFIX etc. variables. Makefiles in subdirectories are
|
||||
# actually executed in the toplevel directory, with the PATH_PREFIX
|
||||
# variable set to the subdirectory where the makefile is located.
|
||||
#
|
||||
# Initial version courtesy Mike Ang.
|
||||
# Next version by Mike McCabe
|
||||
|
||||
# Don't include SHELL define (per GNU manual recommendation) because it
|
||||
# breaks WinNT (with GNU make) builds.
|
||||
# SHELL = /bin/sh
|
||||
|
||||
# Some things we might want to tweek.
|
||||
|
||||
CLASSDIR = classes
|
||||
|
||||
PACKAGE_NAME = org.mozilla.javascript
|
||||
PACKAGE_PATH = org/mozilla/javascript
|
||||
|
||||
# jar filenames and the directories that build them.
|
||||
JS_JAR = js.jar
|
||||
JS_DIR = $(PACKAGE_PATH)
|
||||
JSTOOLS_JAR = jstools.jar
|
||||
JSTOOLS_DIR = $(PACKAGE_PATH)/tools
|
||||
|
||||
JARS = $(JS_JAR) $(JSTOOLS_JAR)
|
||||
|
||||
# It's not polite to store toplevel files in a tarball or zip files.
|
||||
# What is the name of the toplevel directory to store files in?
|
||||
# XXX we should probably add versioning to this.
|
||||
DIST_DIR = jsjava
|
||||
|
||||
# XXX test this with sj
|
||||
JAVAC = javac
|
||||
|
||||
# We don't define JFLAGS but we do export it to child
|
||||
# builds in case it's defined by the environment.
|
||||
# To build optimized (with javac) say 'make JFLAGS=-O'
|
||||
|
||||
GZIP = gzip
|
||||
ZIP = zip
|
||||
UNZIP = unzip
|
||||
|
||||
# Shouldn't need to change anything below here.
|
||||
|
||||
# For Windows NT builds (under GNU make).
|
||||
ifeq ($(OS_TARGET), WINNT)
|
||||
CLASSPATHSEP = '\\;'
|
||||
else
|
||||
CLASSPATHSEP = :
|
||||
endif
|
||||
|
||||
# Make compatibility - use these instead of gmake 'export VARIABLE'
|
||||
EXPORTS = CLASSDIR=$(CLASSDIR) JAVAC=$(JAVAC) JFLAGS=$(JFLAGS) SHELL=$(SHELL) \
|
||||
PACKAGE_PATH=$(PACKAGE_PATH) PACKAGE_NAME=$(PACKAGE_NAME)
|
||||
|
||||
helpmessage : FORCE
|
||||
@echo 'Targets include:'
|
||||
@echo ' all - make jars, examples'
|
||||
@echo ' jars - make js.jar, jstools.jar'
|
||||
@echo ' fast - quick-and-dirty "make jars", for development'
|
||||
@echo ' examples - build the .class files in the examples directory'
|
||||
@echo ' check - perform checks on the source.'
|
||||
@echo ' clean - remove intermediate files'
|
||||
@echo ' clobber - make clean, and remove .jar files'
|
||||
@echo ' zip - make a distribution .zip file'
|
||||
@echo ' zip-source - make a distribution .zip file, with source'
|
||||
@echo ' tar - make a distribution .tar.gz file'
|
||||
@echo ' tar-source - make a distribution .tar.gz, with source'
|
||||
@echo
|
||||
@echo 'Define OS_TARGET to "WINNT" to build on Windows NT with GNU make.'
|
||||
@echo
|
||||
|
||||
all : jars examples
|
||||
|
||||
jars : $(JARS)
|
||||
|
||||
fast : fast_$(JS_JAR) $(JSTOOLS_JAR)
|
||||
|
||||
# Always call the sub-Makefile - which may decide that the jar is up to date.
|
||||
$(JS_JAR) : FORCE
|
||||
$(MAKE) -f $(JS_DIR)/Makefile JAR=$(@) $(EXPORTS) \
|
||||
PATH_PREFIX=$(JS_DIR) \
|
||||
CLASSPATH=.
|
||||
|
||||
fast_$(JS_JAR) :
|
||||
$(MAKE) -f $(JS_DIR)/Makefile JAR=$(JS_JAR) $(EXPORTS) \
|
||||
PATH_PREFIX=$(JS_DIR) \
|
||||
CLASSPATH=. \
|
||||
fast
|
||||
|
||||
$(JSTOOLS_JAR) : $(JS_JAR) FORCE
|
||||
$(MAKE) -f $(JSTOOLS_DIR)/Makefile JAR=$(@) $(EXPORTS) \
|
||||
PATH_PREFIX=$(JSTOOLS_DIR) \
|
||||
CLASSPATH=./$(JS_JAR)$(CLASSPATHSEP).
|
||||
|
||||
examples : $(JS_JAR) FORCE
|
||||
$(MAKE) -f examples/Makefile $(EXPORTS) \
|
||||
PATH_PREFIX=examples \
|
||||
CLASSPATH=./$(JS_JAR)
|
||||
|
||||
# We ask the subdirs to update their MANIFESTs
|
||||
MANIFEST : FORCE
|
||||
$(MAKE) -f $(JS_DIR)/Makefile JAR=$(JS_JAR) $(EXPORTS) \
|
||||
PATH_PREFIX=$(JS_DIR) $(JS_DIR)/MANIFEST
|
||||
$(MAKE) -f $(JSTOOLS_DIR)/Makefile JAR=$(JSTOOLS_JAR) $(EXPORTS) \
|
||||
PATH_PREFIX=$(JSTOOLS_DIR) $(JSTOOLS_DIR)/MANIFEST
|
||||
$(MAKE) -f examples/Makefile $(EXPORTS) \
|
||||
PATH_PREFIX=examples examples/MANIFEST
|
||||
# so ls below always has something to work on
|
||||
touch MANIFEST
|
||||
# examples/Makefile doesn't get included in the
|
||||
# MANIFEST file, (which is used to create the non-source distribution) so
|
||||
# we include it here.
|
||||
cat examples/MANIFEST $(JS_DIR)/MANIFEST \
|
||||
$(JSTOOLS_DIR)/MANIFEST \
|
||||
| xargs ls MANIFEST README.html \
|
||||
$(JARS) \
|
||||
Makefile examples/Makefile \
|
||||
> $(@)
|
||||
|
||||
# Make a MANIFEST file containing only the binaries and documentation.
|
||||
# This could be abstracted further...
|
||||
MANIFEST_binonly : MANIFEST
|
||||
cat examples/MANIFEST \
|
||||
| xargs ls $(JARS) README.html MANIFEST > MANIFEST
|
||||
|
||||
# A subroutine - not intended to be called from outside the makefile.
|
||||
do_zip :
|
||||
# Make sure we get a fresh one
|
||||
- rm -r $(DIST_DIR)
|
||||
- mkdir $(DIST_DIR)
|
||||
- rm $(DIST_DIR).zip
|
||||
cat MANIFEST | xargs $(ZIP) -0 -q $(DIST_DIR).zip
|
||||
mv $(DIST_DIR).zip $(DIST_DIR)
|
||||
cd $(DIST_DIR) ; \
|
||||
$(UNZIP) -q $(DIST_DIR).zip ; \
|
||||
rm $(DIST_DIR).zip
|
||||
$(ZIP) -r -9 -q $(DIST_DIR).zip $(DIST_DIR)
|
||||
- rm -r $(DIST_DIR)
|
||||
|
||||
zip : check jars examples MANIFEST_binonly do_zip
|
||||
|
||||
zip-source : check jars examples MANIFEST do_zip
|
||||
|
||||
# A subroutine - not intended to be called from outside the makefile.
|
||||
do_tar :
|
||||
- rm -r $(DIST_DIR)
|
||||
- mkdir $(DIST_DIR)
|
||||
- rm $(DIST_DIR).tar $(DIST_DIR).tar.gz
|
||||
cat MANIFEST | xargs tar cf $(DIST_DIR).tar
|
||||
mv $(DIST_DIR).tar $(DIST_DIR)
|
||||
cd $(DIST_DIR) ; \
|
||||
tar xf $(DIST_DIR).tar ; \
|
||||
rm $(DIST_DIR).tar
|
||||
tar cf $(DIST_DIR).tar $(DIST_DIR)
|
||||
- rm -r $(DIST_DIR)
|
||||
$(GZIP) -9 $(DIST_DIR).tar
|
||||
|
||||
tar: check jars examples MANIFEST_binonly do_tar
|
||||
|
||||
tar-source : check jars examples MANIFEST do_tar
|
||||
|
||||
# These commands just get passed to the respective sub-Makefiles.
|
||||
clean clobber check:
|
||||
$(MAKE) -f $(JS_DIR)/Makefile $(EXPORTS) JAR=$(JS_JAR) \
|
||||
PATH_PREFIX=$(JS_DIR) $(@)
|
||||
$(MAKE) -f $(JSTOOLS_DIR)/Makefile $(EXPORTS) JAR=$(JSTOOLS_JAR) \
|
||||
PATH_PREFIX=$(JSTOOLS_DIR) $(@)
|
||||
$(MAKE) -f examples/Makefile $(EXPORTS) PATH_PREFIX=examples $(@)
|
||||
|
||||
#emulate .PHONY
|
||||
FORCE :
|
||||
46
mozilla/js/rhino/README.html
Normal file
46
mozilla/js/rhino/README.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<html>
|
||||
<!--
|
||||
- The contents of this file are subject to the Netscape Public
|
||||
- License Version 1.1 (the "License"); you may not use this file
|
||||
- except in compliance with the License. You may obtain a copy of
|
||||
- the License at http://www.mozilla.org/NPL/
|
||||
-
|
||||
- Software distributed under the License is distributed on an "AS
|
||||
- IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
- implied. See the License for the specific language governing
|
||||
- rights and limitations under the License.
|
||||
-
|
||||
- The Original Code is Rhino code, released
|
||||
- May 6, 1999.
|
||||
-
|
||||
- The Initial Developer of the Original Code is Netscape
|
||||
- Communications Corporation. Portions created by Netscape are
|
||||
- Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
||||
- Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
- Norris Boyd
|
||||
-
|
||||
- Alternatively, the contents of this file may be used under the
|
||||
- terms of the GNU Public License (the "GPL"), in which case the
|
||||
- provisions of the GPL are applicable instead of those above.
|
||||
- If you wish to allow use of your version of this file only
|
||||
- under the terms of the GPL and not to allow others to use your
|
||||
- version of this file under the NPL, indicate your decision by
|
||||
- deleting the provisions above and replace them with the notice
|
||||
- and other provisions required by the GPL. If you do not delete
|
||||
- the provisions above, a recipient may use your version of this
|
||||
- file under either the NPL or the GPL.
|
||||
-->
|
||||
<body>
|
||||
<h1>
|
||||
<span CLASS=LXRSHORTDESC>
|
||||
Rhino: JavaScript in Java<p>
|
||||
</span>
|
||||
</h1>
|
||||
<span CLASS=LXRLONGDESC>
|
||||
Rhino is an implementation of JavaScript in Java. Documentation can be found
|
||||
<a href="http://www.mozilla.org/js/rhino/rhino.html">here</a>.
|
||||
</span>
|
||||
</body>
|
||||
</html>
|
||||
105
mozilla/js/rhino/examples/Control.java
Normal file
105
mozilla/js/rhino/examples/Control.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
/**
|
||||
* Example of controlling the JavaScript execution engine.
|
||||
*
|
||||
* We evaluate a script and then manipulate the result.
|
||||
*
|
||||
*/
|
||||
public class Control {
|
||||
|
||||
/**
|
||||
* Main entry point.
|
||||
*
|
||||
* Process arguments as would a normal Java program. Also
|
||||
* create a new Context and associate it with the current thread.
|
||||
* Then set up the execution environment and begin to
|
||||
* execute scripts.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Context cx = Context.enter();
|
||||
|
||||
// Set version to JavaScript1.2 so that we get object-literal style
|
||||
// printing instead of "[object Object]"
|
||||
cx.setLanguageVersion(Context.VERSION_1_2);
|
||||
|
||||
// Initialize the standard objects (Object, Function, etc.)
|
||||
// This must be done before scripts can be executed.
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
|
||||
// Now we can evaluate a script. Let's create a new object
|
||||
// using the object literal notation.
|
||||
Object result = null;
|
||||
try {
|
||||
result = cx.evaluateString(scope, "obj = {a:1, b:['x','y']}",
|
||||
"MySource", 1, null);
|
||||
}
|
||||
catch (JavaScriptException jse) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
Scriptable obj = (Scriptable) scope.get("obj", scope);
|
||||
|
||||
// Should print "obj == result" (Since the result of an assignment
|
||||
// expression is the value that was assigned)
|
||||
System.out.println("obj " + (obj == result ? "==" : "!=") +
|
||||
" result");
|
||||
|
||||
// Should print "obj.a == 1"
|
||||
System.out.println("obj.a == " + obj.get("a", obj));
|
||||
|
||||
Scriptable b = (Scriptable) obj.get("b", obj);
|
||||
|
||||
// Should print "obj.b[0] == x"
|
||||
System.out.println("obj.b[0] == " + b.get(0, b));
|
||||
|
||||
// Should print "obj.b[1] == y"
|
||||
System.out.println("obj.b[1] == " + b.get(1, b));
|
||||
|
||||
try {
|
||||
// Should print {a:1, b:["x", "y"]}
|
||||
Function fn = (Function) ScriptableObject.getProperty(obj, "toString");
|
||||
System.out.println(fn.call(cx, scope, obj, new Object[0]));
|
||||
} catch (JavaScriptException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
cx.exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
55
mozilla/js/rhino/examples/Counter.java
Normal file
55
mozilla/js/rhino/examples/Counter.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
public class Counter extends ScriptableObject {
|
||||
// The zero-argument constructor used by Rhino runtime to create instances
|
||||
public Counter() { }
|
||||
|
||||
// Method jsConstructor defines the JavaScript constructor
|
||||
public void jsConstructor(int a) { count = a; }
|
||||
|
||||
// The class name is defined by the getClassName method
|
||||
public String getClassName() { return "Counter"; }
|
||||
|
||||
// The method jsGet_count defines the count property.
|
||||
public int jsGet_count() { return count++; }
|
||||
|
||||
// Methods can be defined using the jsFunction_ prefix. Here we define
|
||||
// resetCount for JavaScript.
|
||||
public void jsFunction_resetCount() { count = 0; }
|
||||
|
||||
private int count;
|
||||
}
|
||||
178
mozilla/js/rhino/examples/DynamicScopes.java
Normal file
178
mozilla/js/rhino/examples/DynamicScopes.java
Normal file
@@ -0,0 +1,178 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
/**
|
||||
* Example of controlling the JavaScript with multiple scopes and threads.
|
||||
*/
|
||||
public class DynamicScopes {
|
||||
|
||||
/**
|
||||
* Main entry point.
|
||||
*
|
||||
* Set up the shared scope and then spawn new threads that execute
|
||||
* relative to that shared scope. Try compiling functions with and
|
||||
* without dynamic scope to see the effect.
|
||||
*
|
||||
* The expected output is
|
||||
* <pre>
|
||||
* sharedScope
|
||||
* sharedScope
|
||||
* sharedScope
|
||||
* thread0
|
||||
* thread1
|
||||
* thread2
|
||||
* </pre>
|
||||
* The final three lines may be permuted in any order depending on
|
||||
* thread scheduling.
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
throws JavaScriptException
|
||||
{
|
||||
Context cx = Context.enter();
|
||||
try {
|
||||
cx.setCompileFunctionsWithDynamicScope(false);
|
||||
runScripts(cx);
|
||||
cx.setCompileFunctionsWithDynamicScope(true);
|
||||
runScripts(cx);
|
||||
} finally {
|
||||
cx.exit();
|
||||
}
|
||||
}
|
||||
|
||||
static void runScripts(Context cx)
|
||||
throws JavaScriptException
|
||||
{
|
||||
// Initialize the standard objects (Object, Function, etc.)
|
||||
// This must be done before scripts can be executed. The call
|
||||
// returns a new scope that we will share.
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
|
||||
// Now we can evaluate a script and functions will be compiled to
|
||||
// use dynamic scope if the Context is so initialized.
|
||||
String source = "var x = 'sharedScope';" +
|
||||
"function f() { return x; }";
|
||||
cx.evaluateString(scope, source, "MySource", 1, null);
|
||||
|
||||
// Now we spawn some threads that execute a script that calls the
|
||||
// function 'f'. The scope chain looks like this:
|
||||
// <pre>
|
||||
// ------------------
|
||||
// | shared scope |
|
||||
// ------------------
|
||||
// ^
|
||||
// |
|
||||
// ------------------
|
||||
// | per-thread scope |
|
||||
// ------------------
|
||||
// ^
|
||||
// |
|
||||
// ------------------
|
||||
// | f's activation |
|
||||
// ------------------
|
||||
// </pre>
|
||||
// Both the shared scope and the per-thread scope have variables 'x'
|
||||
// defined in them. If 'f' is compiled with dynamic scope enabled,
|
||||
// the 'x' from the per-thread scope will be used. Otherwise, the 'x'
|
||||
// from the shared scope will be used. The 'x' defined in 'g' (which
|
||||
// calls 'f') should not be seen by 'f'.
|
||||
final int threadCount = 3;
|
||||
Thread[] t = new Thread[threadCount];
|
||||
for (int i=0; i < threadCount; i++) {
|
||||
String script = "function g() { var x = 'local'; return f(); }" +
|
||||
"java.lang.System.out.println(g());";
|
||||
t[i] = new Thread(new PerThread(scope, script,
|
||||
"thread" + i));
|
||||
}
|
||||
for (int i=0; i < threadCount; i++)
|
||||
t[i].start();
|
||||
// Don't return in this thread until all the spawned threads have
|
||||
// completed.
|
||||
for (int i=0; i < threadCount; i++) {
|
||||
try {
|
||||
t[i].join();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class PerThread implements Runnable {
|
||||
|
||||
PerThread(Scriptable scope, String script, String x) {
|
||||
this.scope = scope;
|
||||
this.script = script;
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// We need a new Context for this thread.
|
||||
Context cx = Context.enter();
|
||||
try {
|
||||
// We can share the scope.
|
||||
Scriptable threadScope = cx.newObject(scope);
|
||||
threadScope.setPrototype(scope);
|
||||
|
||||
// We want "threadScope" to be a new top-level
|
||||
// scope, so set its parent scope to null. This
|
||||
// means that any variables created by assignments
|
||||
// will be properties of "threadScope".
|
||||
threadScope.setParentScope(null);
|
||||
|
||||
// Create a JavaScript property of the thread scope named
|
||||
// 'x' and save a value for it.
|
||||
threadScope.put("x", threadScope, x);
|
||||
cx.evaluateString(threadScope, script, "threadScript", 1, null);
|
||||
}
|
||||
catch (NotAFunctionException jse) {
|
||||
// ignore
|
||||
}
|
||||
catch (PropertyException jse) {
|
||||
// ignore
|
||||
}
|
||||
catch (JavaScriptException jse) {
|
||||
// ignore
|
||||
}
|
||||
finally {
|
||||
Context.exit();
|
||||
}
|
||||
}
|
||||
private Scriptable scope;
|
||||
private String script;
|
||||
private String x;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
356
mozilla/js/rhino/examples/File.java
Normal file
356
mozilla/js/rhino/examples/File.java
Normal file
@@ -0,0 +1,356 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
import java.io.*;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Define a simple JavaScript File object.
|
||||
*
|
||||
* This isn't intended to be any sort of definitive attempt at a
|
||||
* standard File object for JavaScript, but instead is an example
|
||||
* of a more involved definition of a host object.
|
||||
*
|
||||
* Example of use of the File object:
|
||||
* <pre>
|
||||
* js> defineClass("File")
|
||||
* js> file = new File("myfile.txt");
|
||||
* [object File]
|
||||
* js> file.writeLine("one"); <i>only now is file actually opened</i>
|
||||
* js> file.writeLine("two");
|
||||
* js> file.writeLine("thr", "ee");
|
||||
* js> file.close(); <i>must close file before we can reopen for reading</i>
|
||||
* js> var a = file.readLines(); <i>creates and fills an array with the contents of the file</i>
|
||||
* js> a;
|
||||
* one,two,three
|
||||
* js>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* File errors or end-of-file signaled by thrown Java exceptions will
|
||||
* be wrapped as JavaScript exceptions when called from JavaScript,
|
||||
* and may be caught within JavaScript.
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
public class File extends ScriptableObject {
|
||||
|
||||
/**
|
||||
* The zero-parameter constructor.
|
||||
*
|
||||
* When Context.defineClass is called with this class, it will
|
||||
* construct File.prototype using this constructor.
|
||||
*/
|
||||
public File() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The Java method defining the JavaScript File constructor.
|
||||
*
|
||||
* If the constructor has one or more arguments, and the
|
||||
* first argument is not undefined, the argument is converted
|
||||
* to a string as used as the filename.<p>
|
||||
*
|
||||
* Otherwise System.in or System.out is assumed as appropriate
|
||||
* to the use.
|
||||
*/
|
||||
public static Scriptable jsConstructor(Context cx, Object[] args,
|
||||
Function ctorObj,
|
||||
boolean inNewExpr)
|
||||
{
|
||||
File result = new File();
|
||||
if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
|
||||
result.name = "";
|
||||
result.file = null;
|
||||
} else {
|
||||
result.name = Context.toString(args[0]);
|
||||
result.file = new java.io.File(result.name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this JavaScript class, "File".
|
||||
*/
|
||||
public String getClassName() {
|
||||
return "File";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the file.
|
||||
*
|
||||
* Used to define the "name" property.
|
||||
*/
|
||||
public String jsGet_name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the remaining lines in the file and return them in an array.
|
||||
*
|
||||
* Implements a JavaScript function.<p>
|
||||
*
|
||||
* This is a good example of creating a new array and setting
|
||||
* elements in that array.
|
||||
*
|
||||
* @exception IOException if an error occurred while accessing the file
|
||||
* associated with this object
|
||||
* @exception JavaScriptException if a JavaScript exception occurred
|
||||
* while creating the result array
|
||||
*/
|
||||
public Object jsFunction_readLines()
|
||||
throws IOException, JavaScriptException
|
||||
{
|
||||
Vector v = new Vector();
|
||||
String s;
|
||||
while ((s = jsFunction_readLine()) != null) {
|
||||
v.addElement(s);
|
||||
}
|
||||
Object[] lines = new Object[v.size()];
|
||||
v.copyInto(lines);
|
||||
|
||||
Scriptable scope = ScriptableObject.getTopLevelScope(this);
|
||||
Scriptable result;
|
||||
try {
|
||||
Context cx = Context.getCurrentContext();
|
||||
result = cx.newObject(scope, "Array", lines);
|
||||
} catch (PropertyException e) {
|
||||
throw Context.reportRuntimeError(e.getMessage());
|
||||
} catch (NotAFunctionException e) {
|
||||
throw Context.reportRuntimeError(e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a line.
|
||||
*
|
||||
* Implements a JavaScript function.
|
||||
* @exception IOException if an error occurred while accessing the file
|
||||
* associated with this object, or EOFException if the object
|
||||
* reached the end of the file
|
||||
*/
|
||||
public String jsFunction_readLine() throws IOException {
|
||||
return getReader().readLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a character.
|
||||
*
|
||||
* @exception IOException if an error occurred while accessing the file
|
||||
* associated with this object, or EOFException if the object
|
||||
* reached the end of the file
|
||||
*/
|
||||
public String jsFunction_readChar() throws IOException {
|
||||
int i = getReader().read();
|
||||
if (i == -1)
|
||||
return null;
|
||||
char[] charArray = { (char) i };
|
||||
return new String(charArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write strings.
|
||||
*
|
||||
* Implements a JavaScript function. <p>
|
||||
*
|
||||
* This function takes a variable number of arguments, converts
|
||||
* each argument to a string, and writes that string to the file.
|
||||
* @exception IOException if an error occurred while accessing the file
|
||||
* associated with this object
|
||||
*/
|
||||
public static void jsFunction_write(Context cx, Scriptable thisObj,
|
||||
Object[] args, Function funObj)
|
||||
throws IOException
|
||||
{
|
||||
write0(thisObj, args, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write strings and a newline.
|
||||
*
|
||||
* Implements a JavaScript function.
|
||||
* @exception IOException if an error occurred while accessing the file
|
||||
* associated with this object
|
||||
*
|
||||
*/
|
||||
public static void jsFunction_writeLine(Context cx, Scriptable thisObj,
|
||||
Object[] args, Function funObj)
|
||||
throws IOException
|
||||
{
|
||||
write0(thisObj, args, true);
|
||||
}
|
||||
|
||||
public int jsGet_lineNumber()
|
||||
throws FileNotFoundException
|
||||
{
|
||||
return getReader().getLineNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the file. It may be reopened.
|
||||
*
|
||||
* Implements a JavaScript function.
|
||||
* @exception IOException if an error occurred while accessing the file
|
||||
* associated with this object
|
||||
*/
|
||||
public void jsFunction_close() throws IOException {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
reader = null;
|
||||
} else if (writer != null) {
|
||||
writer.close();
|
||||
writer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalizer.
|
||||
*
|
||||
* Close the file when this object is collected.
|
||||
*/
|
||||
public void finalize() {
|
||||
try {
|
||||
jsFunction_close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Java reader.
|
||||
*/
|
||||
public Object jsFunction_getReader() {
|
||||
if (reader == null)
|
||||
return null;
|
||||
// Here we use toObject() to "wrap" the BufferedReader object
|
||||
// in a Scriptable object so that it can be manipulated by
|
||||
// JavaScript.
|
||||
Scriptable parent = ScriptableObject.getTopLevelScope(this);
|
||||
return Context.toObject(reader, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Java writer.
|
||||
*
|
||||
* @see File#jsFunction_getReader
|
||||
*
|
||||
*/
|
||||
public Object jsFunction_getWriter() {
|
||||
if (writer == null)
|
||||
return null;
|
||||
Scriptable parent = ScriptableObject.getTopLevelScope(this);
|
||||
return Context.toObject(writer, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reader, checking that we're not already writing this file.
|
||||
*/
|
||||
private LineNumberReader getReader() throws FileNotFoundException {
|
||||
if (writer != null) {
|
||||
throw Context.reportRuntimeError("already writing file \""
|
||||
+ name
|
||||
+ "\"");
|
||||
}
|
||||
if (reader == null)
|
||||
reader = new LineNumberReader(file == null
|
||||
? new InputStreamReader(System.in)
|
||||
: new FileReader(file));
|
||||
return reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the guts of write and writeLine.
|
||||
*
|
||||
* Since the two functions differ only in whether they write a
|
||||
* newline character, move the code into a common subroutine.
|
||||
*
|
||||
*/
|
||||
private static void write0(Scriptable thisObj, Object[] args, boolean eol)
|
||||
throws IOException
|
||||
{
|
||||
File thisFile = checkInstance(thisObj);
|
||||
if (thisFile.reader != null) {
|
||||
throw Context.reportRuntimeError("already writing file \""
|
||||
+ thisFile.name
|
||||
+ "\"");
|
||||
}
|
||||
if (thisFile.writer == null)
|
||||
thisFile.writer = new BufferedWriter(
|
||||
thisFile.file == null ? new OutputStreamWriter(System.out)
|
||||
: new FileWriter(thisFile.file));
|
||||
for (int i=0; i < args.length; i++) {
|
||||
String s = Context.toString(args[i]);
|
||||
thisFile.writer.write(s, 0, s.length());
|
||||
}
|
||||
if (eol)
|
||||
thisFile.writer.newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the instanceof check and return the downcasted File object.
|
||||
*
|
||||
* This is necessary since methods may reside in the File.prototype
|
||||
* object and scripts can dynamically alter prototype chains. For example:
|
||||
* <pre>
|
||||
* js> defineClass("File");
|
||||
* js> o = {};
|
||||
* [object Object]
|
||||
* js> o.__proto__ = File.prototype;
|
||||
* [object File]
|
||||
* js> o.write("hi");
|
||||
* js: called on incompatible object
|
||||
* </pre>
|
||||
* The runtime will take care of such checks when non-static Java methods
|
||||
* are defined as JavaScript functions.
|
||||
*/
|
||||
private static File checkInstance(Scriptable obj) {
|
||||
if (obj == null || !(obj instanceof File)) {
|
||||
throw Context.reportRuntimeError("called on incompatible object");
|
||||
}
|
||||
return (File) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Some private data for this class.
|
||||
*/
|
||||
private String name;
|
||||
private java.io.File file; // may be null, meaning to use System.out or .in
|
||||
private LineNumberReader reader;
|
||||
private BufferedWriter writer;
|
||||
}
|
||||
|
||||
168
mozilla/js/rhino/examples/Foo.java
Normal file
168
mozilla/js/rhino/examples/Foo.java
Normal file
@@ -0,0 +1,168 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
/**
|
||||
* An example host object class.
|
||||
*
|
||||
* Here's a shell session showing the Foo object in action:
|
||||
* <pre>
|
||||
* js> defineClass("Foo")
|
||||
* js> foo = new Foo(); <i>A constructor call, see <a href="#Foo">Foo</a> below.</i>
|
||||
* [object Foo] <i>The "Foo" here comes from <a href"#getClassName">getClassName</a>.</i>
|
||||
* js> foo.counter; <i>The counter property is defined by the <code>defineProperty</code></i>
|
||||
* 0 <i>call below and implemented by the <a href="#getCounter">getCounter</a></i>
|
||||
* js> foo.counter; <i>method below.</i>
|
||||
* 1
|
||||
* js> foo.counter;
|
||||
* 2
|
||||
* js> foo.resetCounter(); <i>Results in a call to <a href="#resetCounter">resetCounter</a>.</i>
|
||||
* js> foo.counter; <i>Now the counter has been reset.</i>
|
||||
* 0
|
||||
* js> foo.counter;
|
||||
* 1
|
||||
* js> bar = new Foo(37); <i>Create a new instance.</i>
|
||||
* [object Foo]
|
||||
* js> bar.counter; <i>This instance's counter is distinct from</i>
|
||||
* 37 <i>the other instance's counter.</i>
|
||||
* js> foo.varargs(3, "hi"); <i>Calls <a href="#varargs">varargs</a>.</i>
|
||||
* this = [object Foo]; args = [3, hi]
|
||||
* js> foo[7] = 34; <i>Since we extended ScriptableObject, we get</i>
|
||||
* 34 <i>all the behavior of a JavaScript object</i>
|
||||
* js> foo.a = 23; <i>for free.</i>
|
||||
* 23
|
||||
* js> foo.a + foo[7];
|
||||
* 57
|
||||
* js>
|
||||
* </pre>
|
||||
*
|
||||
* @see org.mozilla.javascript.Context
|
||||
* @see org.mozilla.javascript.Scriptable
|
||||
* @see org.mozilla.javascript.ScriptableObject
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
|
||||
public class Foo extends ScriptableObject {
|
||||
|
||||
/**
|
||||
* The zero-parameter constructor.
|
||||
*
|
||||
* When Context.defineClass is called with this class, it will
|
||||
* construct Foo.prototype using this constructor.
|
||||
*/
|
||||
public Foo() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The Java method defining the JavaScript Foo constructor.
|
||||
*
|
||||
* Takes an initial value for the counter property.
|
||||
* Note that in the example Shell session above, we didn't
|
||||
* supply a argument to the Foo constructor. This means that
|
||||
* the Undefined value is used as the value of the argument,
|
||||
* and when the argument is converted to an integer, Undefined
|
||||
* becomes 0.
|
||||
*/
|
||||
public Foo(int counterStart) {
|
||||
counter = counterStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this JavaScript class, "Foo".
|
||||
*/
|
||||
public String getClassName() {
|
||||
return "Foo";
|
||||
}
|
||||
|
||||
/**
|
||||
* The Java method defining the JavaScript resetCounter function.
|
||||
*
|
||||
* Resets the counter to 0.
|
||||
*/
|
||||
public void jsFunction_resetCounter() {
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Java method implementing the getter for the counter property.
|
||||
* <p>
|
||||
* If "setCounter" had been defined in this class, the runtime would
|
||||
* call the setter when the property is assigned to.
|
||||
*/
|
||||
public int jsGet_counter() {
|
||||
return counter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* An example of a variable-arguments method.
|
||||
*
|
||||
* All variable arguments methods must have the same number and
|
||||
* types of parameters, and must be static. <p>
|
||||
* @param cx the Context of the current thread
|
||||
* @param thisObj the JavaScript 'this' value.
|
||||
* @param args the array of arguments for this call
|
||||
* @param funObj the function object of the invoked JavaScript function
|
||||
* This value is useful to compute a scope using
|
||||
* Context.getTopLevelScope().
|
||||
* @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,
|
||||
Object[] args, Function funObj)
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("this = ");
|
||||
buf.append(Context.toString(thisObj));
|
||||
buf.append("; args = [");
|
||||
for (int i=0; i < args.length; i++) {
|
||||
buf.append(Context.toString(args[i]));
|
||||
if (i+1 != args.length)
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append("]");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A piece of private data for this class.
|
||||
*/
|
||||
private int counter;
|
||||
}
|
||||
|
||||
59
mozilla/js/rhino/examples/Makefile
Normal file
59
mozilla/js/rhino/examples/Makefile
Normal file
@@ -0,0 +1,59 @@
|
||||
#! gmake
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is Rhino code, released
|
||||
# May 6, 1998.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU Public License (the "GPL"), in which case the
|
||||
# provisions of the GPL are applicable instead of those above.
|
||||
# If you wish to allow use of your version of this file only
|
||||
# under the terms of the GPL and not to allow others to use your
|
||||
# version of this file under the NPL, indicate your decision by
|
||||
# deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this
|
||||
# file under either the NPL or the GPL.
|
||||
|
||||
#
|
||||
# Makefile for the examples directory.
|
||||
#
|
||||
# This Makefile just calls $(JAVAC) on all the .java files. This
|
||||
# Makefile is intended to be called from the toplevel Makefile.
|
||||
#
|
||||
|
||||
JSFILES = $(PATH_PREFIX)/*.js
|
||||
SOURCES = $(PATH_PREFIX)/*.java
|
||||
CLASSES = $(PATH_PREFIX)/*.class
|
||||
|
||||
$(CLASSES) : $(SOURCES)
|
||||
$(JAVAC) $(JFLAGS) $(SOURCES)
|
||||
|
||||
clean :
|
||||
- rm $(CLASSES) $(PATH_PREFIX)/MANIFEST
|
||||
|
||||
clobber : clean
|
||||
|
||||
check :
|
||||
|
||||
$(PATH_PREFIX)/MANIFEST : $(SOURCES) $(CLASSES) $(JSFILES)
|
||||
ls $(SOURCES) $(CLASSES) $(JSFILES) \
|
||||
> $(@)
|
||||
|
||||
# Emulate .PHONY
|
||||
FORCE :
|
||||
274
mozilla/js/rhino/examples/Matrix.java
Normal file
274
mozilla/js/rhino/examples/Matrix.java
Normal file
@@ -0,0 +1,274 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Matrix: An example host object class that implements the Scriptable interface.
|
||||
*
|
||||
* Built-in JavaScript arrays don't handle multiple dimensions gracefully: the
|
||||
* script writer must create every array in an array of arrays. The Matrix class
|
||||
* takes care of that by automatically allocating arrays for every index that
|
||||
* is accessed. What's more, the Matrix constructor takes a integer argument
|
||||
* that specifies the dimension of the Matrix. If m is a Matrix with dimension 3,
|
||||
* then m[0] will be a Matrix with dimension 1, and m[0][0] will be an Array.
|
||||
*
|
||||
* Here's a shell session showing the Matrix object in action:
|
||||
* <pre>
|
||||
* js> defineClass("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> m[0]; <i>an array was created automatically!</i>
|
||||
* [3]
|
||||
* js> m[1]; <i>array is created even if we don't set a value</i>
|
||||
* []
|
||||
* js> m.dim; <i>we can access the "dim" property</i>
|
||||
* 2
|
||||
* js> m.dim = 3;
|
||||
* 3
|
||||
* js> m.dim; <i>but not modify it</i>
|
||||
* 2
|
||||
* </pre>
|
||||
*
|
||||
* @see org.mozilla.javascript.Context
|
||||
* @see org.mozilla.javascript.Scriptable
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
public class Matrix implements Scriptable {
|
||||
|
||||
/**
|
||||
* The zero-parameter constructor.
|
||||
*
|
||||
* When Context.defineClass is called with this class, it will
|
||||
* construct Matrix.prototype using this constructor.
|
||||
*/
|
||||
public Matrix() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The Java constructor, also used to define the JavaScript constructor.
|
||||
*/
|
||||
public Matrix(int dimension) {
|
||||
if (dimension <= 0) {
|
||||
throw Context.reportRuntimeError(
|
||||
"Dimension of Matrix must be greater than zero");
|
||||
}
|
||||
dim = dimension;
|
||||
v = new Vector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this JavaScript class, "Matrix".
|
||||
*/
|
||||
public String getClassName() {
|
||||
return "Matrix";
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the "dim" property by returning true if name is
|
||||
* equal to "dim".
|
||||
* <p>
|
||||
* Defines no other properties, i.e., returns false for
|
||||
* all other names.
|
||||
*
|
||||
* @param name the name of the property
|
||||
* @param start the object where lookup began
|
||||
*/
|
||||
public boolean has(String name, Scriptable start) {
|
||||
return name.equals("dim");
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines all numeric properties by returning true.
|
||||
*
|
||||
* @param index the index of the property
|
||||
* @param start the object where lookup began
|
||||
*/
|
||||
public boolean has(int index, Scriptable start) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the named property.
|
||||
* <p>
|
||||
* Handles the "dim" property and returns NOT_FOUND for all
|
||||
* other names.
|
||||
* @param name the property name
|
||||
* @param start the object where the lookup began
|
||||
*/
|
||||
public Object get(String name, Scriptable start) {
|
||||
if (name.equals("dim"))
|
||||
return new Integer(dim);
|
||||
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the indexed property.
|
||||
* <p>
|
||||
* 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) {
|
||||
if (index >= v.size())
|
||||
v.setSize(index+1);
|
||||
Object result = v.elementAt(index);
|
||||
if (result != null)
|
||||
return result;
|
||||
if (dim > 2) {
|
||||
Matrix m = new Matrix(dim-1);
|
||||
m.setParentScope(getParentScope());
|
||||
m.setPrototype(getPrototype());
|
||||
result = m;
|
||||
} else {
|
||||
Context cx = Context.getCurrentContext();
|
||||
Scriptable scope = ScriptableObject.getTopLevelScope(start);
|
||||
result = cx.newArray(scope, 0);
|
||||
}
|
||||
v.setElementAt(result, index);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a named property.
|
||||
*
|
||||
* We do nothing here, so all properties are effectively read-only.
|
||||
*/
|
||||
public void put(String name, Scriptable start, Object value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an indexed property.
|
||||
*
|
||||
* We do nothing here, so all properties are effectively read-only.
|
||||
*/
|
||||
public void put(int index, Scriptable start, Object value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a named property.
|
||||
*
|
||||
* This method shouldn't even be called since we define all properties
|
||||
* as PERMANENT.
|
||||
*/
|
||||
public void delete(String id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an indexed property.
|
||||
*
|
||||
* This method shouldn't even be called since we define all properties
|
||||
* as PERMANENT.
|
||||
*/
|
||||
public void delete(int index) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prototype.
|
||||
*/
|
||||
public Scriptable getPrototype() {
|
||||
return prototype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set prototype.
|
||||
*/
|
||||
public void setPrototype(Scriptable prototype) {
|
||||
this.prototype = prototype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parent.
|
||||
*/
|
||||
public Scriptable getParentScope() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parent.
|
||||
*/
|
||||
public void setParentScope(Scriptable parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get properties.
|
||||
*
|
||||
* We return an empty array since we define all properties to be DONTENUM.
|
||||
*/
|
||||
public Object[] getIds() {
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Default value.
|
||||
*
|
||||
* Use the convenience method from Context that takes care of calling
|
||||
* toString, etc.
|
||||
*/
|
||||
public Object getDefaultValue(Class typeHint) {
|
||||
return "[object Matrix]";
|
||||
}
|
||||
|
||||
/**
|
||||
* instanceof operator.
|
||||
*
|
||||
* We mimick the normal JavaScript instanceof semantics, returning
|
||||
* true if <code>this</code> appears in <code>value</code>'s prototype
|
||||
* chain.
|
||||
*/
|
||||
public boolean hasInstance(Scriptable value) {
|
||||
Scriptable proto = value.getPrototype();
|
||||
while (proto != null) {
|
||||
if (proto.equals(this)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Some private data for this class.
|
||||
*/
|
||||
private int dim;
|
||||
private Vector v;
|
||||
private Scriptable prototype, parent;
|
||||
}
|
||||
7
mozilla/js/rhino/examples/NervousText.html
Normal file
7
mozilla/js/rhino/examples/NervousText.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
This is the NervousText applet in javascript:
|
||||
<applet code=NervousText.class width=200 height=50 >
|
||||
</applet>
|
||||
</body>
|
||||
</html>
|
||||
75
mozilla/js/rhino/examples/NervousText.js
Normal file
75
mozilla/js/rhino/examples/NervousText.js
Normal file
@@ -0,0 +1,75 @@
|
||||
// The Java "NervousText" example ported to JavaScript.
|
||||
// Compile using java org.mozilla.tools.jsc.Main -extends java.applet.Applet -implements java.lang.Runnable NervousText.js
|
||||
/*
|
||||
Adapted from Java code by
|
||||
Daniel Wyszynski
|
||||
Center for Applied Large-Scale Computing (CALC)
|
||||
04-12-95
|
||||
|
||||
Test of text animation.
|
||||
|
||||
kwalrath: Changed string; added thread suspension. 5-9-95
|
||||
*/
|
||||
var Font = java.awt.Font;
|
||||
var Thread = java.lang.Thread;
|
||||
var separated;
|
||||
var s = null;
|
||||
var killme = null;
|
||||
var i;
|
||||
var x_coord = 0, y_coord = 0;
|
||||
var num;
|
||||
var speed=35;
|
||||
var counter =0;
|
||||
var threadSuspended = false; //added by kwalrath
|
||||
|
||||
function init() {
|
||||
resize(150,50);
|
||||
setFont(new Font("TimesRoman",Font.BOLD,36));
|
||||
s = getParameter("text");
|
||||
if (s == null) {
|
||||
s = "Rhino";
|
||||
}
|
||||
separated = s.split('');
|
||||
}
|
||||
|
||||
function start() {
|
||||
if(killme == null)
|
||||
{
|
||||
killme = new java.lang.Thread(java.lang.Runnable(this));
|
||||
killme.start();
|
||||
}
|
||||
}
|
||||
|
||||
function stop() {
|
||||
killme = null;
|
||||
}
|
||||
|
||||
function run() {
|
||||
while (killme != null) {
|
||||
try {Thread.sleep(100);} catch (e){}
|
||||
repaint();
|
||||
}
|
||||
killme = null;
|
||||
}
|
||||
|
||||
function paint(g) {
|
||||
for(i=0;i<separated.length;i++)
|
||||
{
|
||||
x_coord = Math.random()*10+15*i;
|
||||
y_coord = Math.random()*10+36;
|
||||
g.drawChars(separated, i,1,x_coord,y_coord);
|
||||
}
|
||||
}
|
||||
|
||||
/* Added by kwalrath. */
|
||||
function mouseDown(evt, x, y) {
|
||||
if (threadSuspended) {
|
||||
killme.resume();
|
||||
}
|
||||
else {
|
||||
killme.suspend();
|
||||
}
|
||||
threadSuspended = !threadSuspended;
|
||||
return true;
|
||||
}
|
||||
|
||||
73
mozilla/js/rhino/examples/RunScript.java
Normal file
73
mozilla/js/rhino/examples/RunScript.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
/**
|
||||
* RunScript: simplest example of controlling execution of Rhino.
|
||||
*
|
||||
* Collects its arguments from the command line, executes the
|
||||
* script, and prints the result.
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
public class RunScript {
|
||||
public static void main(String args[])
|
||||
throws JavaScriptException
|
||||
{
|
||||
// Creates and enters a Context. The Context stores information
|
||||
// about the execution environment of a script.
|
||||
Context cx = Context.enter();
|
||||
|
||||
// Initialize the standard objects (Object, Function, etc.)
|
||||
// This must be done before scripts can be executed. Returns
|
||||
// a scope object that we use in later calls.
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
|
||||
// Collect the arguments into a single string.
|
||||
String s = "";
|
||||
for (int i=0; i < args.length; i++)
|
||||
s += args[i];
|
||||
|
||||
// Now evaluate the string we've colected.
|
||||
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
|
||||
|
||||
// Convert the result to a string and print it.
|
||||
System.err.println(cx.toString(result));
|
||||
|
||||
// Exit from the context.
|
||||
Context.exit();
|
||||
}
|
||||
}
|
||||
|
||||
63
mozilla/js/rhino/examples/RunScript2.java
Normal file
63
mozilla/js/rhino/examples/RunScript2.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
/**
|
||||
* RunScript2: Like RunScript, but reflects the System.out into JavaScript.
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
public class RunScript2 {
|
||||
public static void main(String args[])
|
||||
throws JavaScriptException
|
||||
{
|
||||
Context cx = Context.enter();
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
|
||||
// Add a global variable "out" that is a JavaScript reflection
|
||||
// of System.out
|
||||
Scriptable jsArgs = Context.toObject(System.out, scope);
|
||||
scope.put("out", scope, jsArgs);
|
||||
|
||||
String s = "";
|
||||
for (int i=0; i < args.length; i++)
|
||||
s += args[i];
|
||||
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
|
||||
System.err.println(cx.toString(result));
|
||||
Context.exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
63
mozilla/js/rhino/examples/RunScript3.java
Normal file
63
mozilla/js/rhino/examples/RunScript3.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
/**
|
||||
* RunScript3: Execute scripts in an environment that includes the
|
||||
* example Counter class.
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
public class RunScript3 {
|
||||
public static void main(String args[])
|
||||
throws Exception
|
||||
{
|
||||
Context cx = Context.enter();
|
||||
Scriptable scope = cx.initStandardObjects(null);
|
||||
|
||||
// Use the Counter class to define a Counter constructor
|
||||
// and prototype in JavaScript.
|
||||
ScriptableObject.defineClass(scope, Counter.class);
|
||||
|
||||
String s = "";
|
||||
for (int i=0; i < args.length; i++)
|
||||
s += args[i];
|
||||
Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);
|
||||
System.err.println(cx.toString(result));
|
||||
Context.exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
352
mozilla/js/rhino/examples/Shell.java
Normal file
352
mozilla/js/rhino/examples/Shell.java
Normal file
@@ -0,0 +1,352 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
import org.mozilla.javascript.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* The shell program.
|
||||
*
|
||||
* Can execute scripts interactively or in batch mode at the command line.
|
||||
* An example of controlling the JavaScript engine.
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
public class Shell extends ScriptableObject {
|
||||
|
||||
/**
|
||||
* Main entry point.
|
||||
*
|
||||
* Process arguments as would a normal Java program. Also
|
||||
* create a new Context and associate it with the current thread.
|
||||
* Then set up the execution environment and begin to
|
||||
* execute scripts.
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
// Associate a new Context with this thread
|
||||
Context cx = Context.enter();
|
||||
|
||||
// A bit of shorthand: since Shell extends ScriptableObject,
|
||||
// we can make it the global object.
|
||||
global = new Shell();
|
||||
|
||||
// Initialize the standard objects (Object, Function, etc.)
|
||||
// This must be done before scripts can be executed.
|
||||
cx.initStandardObjects(global);
|
||||
|
||||
// Define some global functions particular to the shell. Note
|
||||
// that these functions are not part of ECMA.
|
||||
String[] names = { "print", "quit", "version", "load", "help" };
|
||||
try {
|
||||
global.defineFunctionProperties(names, Shell.class,
|
||||
ScriptableObject.DONTENUM);
|
||||
} catch (PropertyException e) {
|
||||
throw new Error(e.getMessage());
|
||||
}
|
||||
|
||||
args = processOptions(cx, args);
|
||||
|
||||
// Set up "arguments" in the global scope to contain the command
|
||||
// line arguments after the name of the script to execute
|
||||
Object[] array = args;
|
||||
if (args.length > 0) {
|
||||
int length = args.length - 1;
|
||||
array = new Object[length];
|
||||
System.arraycopy(args, 1, array, 0, length);
|
||||
}
|
||||
Scriptable argsObj = cx.newArray(global, array);
|
||||
global.defineProperty("arguments", argsObj,
|
||||
ScriptableObject.DONTENUM);
|
||||
|
||||
processSource(cx, args.length == 0 ? null : args[0]);
|
||||
|
||||
cx.exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse arguments.
|
||||
*/
|
||||
public static String[] processOptions(Context cx, String args[]) {
|
||||
for (int i=0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
if (!arg.startsWith("-")) {
|
||||
String[] result = new String[args.length - i];
|
||||
for (int j=i; j < args.length; j++)
|
||||
result[j-i] = args[j];
|
||||
return result;
|
||||
}
|
||||
if (arg.equals("-version")) {
|
||||
if (++i == args.length)
|
||||
usage(arg);
|
||||
double d = cx.toNumber(args[i]);
|
||||
if (d != d)
|
||||
usage(arg);
|
||||
cx.setLanguageVersion((int) d);
|
||||
continue;
|
||||
}
|
||||
usage(arg);
|
||||
}
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return name of this class, the global object.
|
||||
*
|
||||
* This method must be implemented in all concrete classes
|
||||
* extending ScriptableObject.
|
||||
*
|
||||
* @see org.mozilla.javascript.Scriptable#getClassName
|
||||
*/
|
||||
public String getClassName() {
|
||||
return "global";
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a usage message.
|
||||
*/
|
||||
public static void usage(String s) {
|
||||
p("Didn't understand \"" + s + "\".");
|
||||
p("Valid arguments are:");
|
||||
p("-version 100|110|120|130");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a help message.
|
||||
*
|
||||
* This method is defined as a JavaScript function.
|
||||
*/
|
||||
public static void help(String s) {
|
||||
p("");
|
||||
p("Command Description");
|
||||
p("======= ===========");
|
||||
p("help() Display usage and help messages. ");
|
||||
p("defineClass(className) Define an extension using the Java class");
|
||||
p(" named with the string argument. ");
|
||||
p(" Uses ScriptableObject.defineClass(). ");
|
||||
p("load(['foo.js', ...]) Load JavaScript source files named by ");
|
||||
p(" string arguments. ");
|
||||
p("loadClass(className) Load a class named by a string argument.");
|
||||
p(" The class must be a script compiled to a");
|
||||
p(" class file. ");
|
||||
p("print([expr ...]) Evaluate and print expressions. ");
|
||||
p("quit() Quit the shell. ");
|
||||
p("version([number]) Get or set the JavaScript version number.");
|
||||
p("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the string values of its arguments.
|
||||
*
|
||||
* This method is defined as a JavaScript function.
|
||||
* Note that its arguments are of the "varargs" form, which
|
||||
* allows it to handle an arbitrary number of arguments
|
||||
* supplied to the JavaScript function.
|
||||
*
|
||||
*/
|
||||
public static void print(Context cx, Scriptable thisObj,
|
||||
Object[] args, Function funObj)
|
||||
{
|
||||
for (int i=0; i < args.length; i++) {
|
||||
if (i > 0)
|
||||
System.out.print(" ");
|
||||
|
||||
// Convert the arbitrary JavaScript value into a string form.
|
||||
String s = Context.toString(args[i]);
|
||||
|
||||
System.out.print(s);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
/**
|
||||
* Quit the shell.
|
||||
*
|
||||
* This only affects the interactive mode.
|
||||
*
|
||||
* This method is defined as a JavaScript function.
|
||||
*/
|
||||
public static void quit() {
|
||||
quitting = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and set the language version.
|
||||
*
|
||||
* This method is defined as a JavaScript function.
|
||||
*/
|
||||
public static double version(Context cx, Scriptable thisObj,
|
||||
Object[] args, Function funObj)
|
||||
{
|
||||
double result = (double) cx.getLanguageVersion();
|
||||
if (args.length > 0) {
|
||||
double d = cx.toNumber(args[0]);
|
||||
cx.setLanguageVersion((int) d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and execute a set of JavaScript source files.
|
||||
*
|
||||
* This method is defined as a JavaScript function.
|
||||
*
|
||||
*/
|
||||
public static void load(Context cx, Scriptable thisObj,
|
||||
Object[] args, Function funObj)
|
||||
{
|
||||
for (int i=0; i < args.length; i++) {
|
||||
processSource(cx, cx.toString(args[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Evaluate JavaScript source.
|
||||
*
|
||||
* @param cx the current context
|
||||
* @param filename the name of the file to compile, or null
|
||||
* for interactive mode.
|
||||
*/
|
||||
public static void processSource(Context cx, String filename) {
|
||||
if (filename == null) {
|
||||
BufferedReader in = new BufferedReader
|
||||
(new InputStreamReader(System.in));
|
||||
String sourceName = "<stdin>";
|
||||
int lineno = 1;
|
||||
boolean hitEOF = false;
|
||||
do {
|
||||
int startline = lineno;
|
||||
System.err.print("js> ");
|
||||
System.err.flush();
|
||||
try {
|
||||
String source = "";
|
||||
// Collect lines of source to compile.
|
||||
while(true) {
|
||||
String newline;
|
||||
newline = in.readLine();
|
||||
if (newline == null) {
|
||||
hitEOF = true;
|
||||
break;
|
||||
}
|
||||
source = source + newline + "\n";
|
||||
lineno++;
|
||||
// Continue collecting as long as more lines
|
||||
// are needed to complete the current
|
||||
// statement. stringIsCompilableUnit is also
|
||||
// true if the source statement will result in
|
||||
// any error other than one that might be
|
||||
// resolved by appending more source.
|
||||
if (cx.stringIsCompilableUnit(source))
|
||||
break;
|
||||
}
|
||||
Object result = cx.evaluateString(global, source,
|
||||
sourceName, startline,
|
||||
null);
|
||||
if (result != cx.getUndefinedValue()) {
|
||||
System.err.println(cx.toString(result));
|
||||
}
|
||||
}
|
||||
catch (WrappedException we) {
|
||||
// Some form of exception was caught by JavaScript and
|
||||
// propagated up.
|
||||
System.err.println(we.getWrappedException().toString());
|
||||
we.printStackTrace();
|
||||
}
|
||||
catch (EvaluatorException ee) {
|
||||
// Some form of JavaScript error.
|
||||
System.err.println("js: " + ee.getMessage());
|
||||
}
|
||||
catch (JavaScriptException jse) {
|
||||
// Some form of JavaScript error.
|
||||
System.err.println("js: " + jse.getMessage());
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println(ioe.toString());
|
||||
}
|
||||
if (quitting) {
|
||||
// The user executed the quit() function.
|
||||
break;
|
||||
}
|
||||
} while (!hitEOF);
|
||||
System.err.println();
|
||||
} else {
|
||||
FileReader in = null;
|
||||
try {
|
||||
in = new FileReader(filename);
|
||||
}
|
||||
catch (FileNotFoundException ex) {
|
||||
Context.reportError("Couldn't open file \"" + filename + "\".");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Here we evalute the entire contents of the file as
|
||||
// a script. Text is printed only if the print() function
|
||||
// is called.
|
||||
cx.evaluateReader(global, in, filename, 1, null);
|
||||
}
|
||||
catch (WrappedException we) {
|
||||
System.err.println(we.getWrappedException().toString());
|
||||
we.printStackTrace();
|
||||
}
|
||||
catch (EvaluatorException ee) {
|
||||
System.err.println("js: " + ee.getMessage());
|
||||
}
|
||||
catch (JavaScriptException jse) {
|
||||
System.err.println("js: " + jse.getMessage());
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println(ioe.toString());
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println(ioe.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
private static void p(String s) {
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
static Shell global;
|
||||
static boolean quitting;
|
||||
}
|
||||
|
||||
134
mozilla/js/rhino/examples/checkParam.js
Normal file
134
mozilla/js/rhino/examples/checkParam.js
Normal file
@@ -0,0 +1,134 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
/**
|
||||
* checkParam.js
|
||||
*
|
||||
* The files given as arguments on the command line are assumed to be
|
||||
* Java source code files. This program checks to see that the @param
|
||||
* tags in the documentation comments match with the parameters for
|
||||
* the associated Java methods.
|
||||
* <p>
|
||||
* Any errors found are reported.
|
||||
*
|
||||
*/
|
||||
defineClass("File")
|
||||
|
||||
// Return true if "str" ends with "suffix".
|
||||
function stringEndsWith(str, suffix) {
|
||||
return str.substring(str.length - suffix.length) == suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform processing once the end of a documentation comment is seen.
|
||||
*
|
||||
* Look for a parameter list following the end of the comment and
|
||||
* collect the parameters and compare to the @param entries.
|
||||
* Report any discrepancies.
|
||||
* @param f the current file
|
||||
* @param a an array of parameters from @param comments
|
||||
* @param line the string containing the comment end (in case the
|
||||
* parameters are on the same line)
|
||||
*/
|
||||
function processCommentEnd(f, a, line) {
|
||||
while (line != null && !line.match(/\(/))
|
||||
line = f.readLine();
|
||||
while (line != null && !line.match(/\)/))
|
||||
line += f.readLine();
|
||||
if (line === null)
|
||||
return;
|
||||
var m = line.match(/\(([^\)]+)\)/);
|
||||
var args = m ? m[1].split(",") : [];
|
||||
if (a.length != args.length) {
|
||||
print('"' + f.name +
|
||||
'"; line ' + f.lineNumber +
|
||||
' mismatch: had a different number' +
|
||||
' of @param entries and parameters.');
|
||||
} else {
|
||||
for (var i=0; i < a.length; i++) {
|
||||
if (!stringEndsWith(args[i], a[i])) {
|
||||
print('"' + f.name +
|
||||
'"; line ' + f.lineNumber +
|
||||
' mismatch: had "' + a[i] +
|
||||
'" and "' + args[i] + '".');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the given file, looking for mismatched @param lists and
|
||||
* parameter lists.
|
||||
* @param f the file to process
|
||||
*/
|
||||
function processFile(f) {
|
||||
var line;
|
||||
var m;
|
||||
var i = 0;
|
||||
var a = [];
|
||||
outer:
|
||||
while ((line = f.readLine()) != null) {
|
||||
if (line.match(/@param/)) {
|
||||
while (m = line.match(/@param[ ]+([^ ]+)/)) {
|
||||
a[i++] = m[1];
|
||||
line = f.readLine();
|
||||
if (line == null)
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
if (i != 0 && line.match(/\*\//)) {
|
||||
processCommentEnd(f, a, line);
|
||||
i = 0;
|
||||
a = [];
|
||||
}
|
||||
}
|
||||
if (i != 0) {
|
||||
print('"' + f.name +
|
||||
'"; line ' + f.lineNumber +
|
||||
' missing parameters at end of file.');
|
||||
}
|
||||
}
|
||||
|
||||
// main script: process each file in arguments list
|
||||
|
||||
for (var i=0; i < arguments.length; i++) {
|
||||
var filename = String(arguments[i]);
|
||||
print("Checking " + filename + "...");
|
||||
var f = new File(filename);
|
||||
processFile(f);
|
||||
}
|
||||
print("done.");
|
||||
|
||||
70
mozilla/js/rhino/examples/enum.js
Normal file
70
mozilla/js/rhino/examples/enum.js
Normal file
@@ -0,0 +1,70 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick Beard
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
/*
|
||||
enum.js
|
||||
|
||||
Implementing the interface java.util.Enumeration using the new syntax.
|
||||
Note that this syntax is experimental only, and hasn't been approved
|
||||
by ECMA.
|
||||
The same functionality can be had without the new syntax using the
|
||||
uglier syntax:
|
||||
|
||||
var elements = new JavaAdapter(java.util.Enumeration, {
|
||||
index: 0, elements: array,
|
||||
hasMoreElements: function ...
|
||||
nextElement: function ...
|
||||
});
|
||||
|
||||
by Patrick C. Beard.
|
||||
*/
|
||||
|
||||
// an array to enumerate.
|
||||
var array = [0, 1, 2];
|
||||
|
||||
// create an array enumeration.
|
||||
var elements = new java.util.Enumeration() {
|
||||
index: 0, elements: array,
|
||||
hasMoreElements: function() {
|
||||
return (this.index < this.elements.length);
|
||||
},
|
||||
nextElement: function() {
|
||||
return this.elements[this.index++];
|
||||
}
|
||||
};
|
||||
|
||||
// now print out the array by enumerating through the Enumeration
|
||||
while (elements.hasMoreElements())
|
||||
print(elements.nextElement());
|
||||
508
mozilla/js/rhino/examples/jsdoc.js
Normal file
508
mozilla/js/rhino/examples/jsdoc.js
Normal file
@@ -0,0 +1,508 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
* Roland Pennings
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Process a JavaScript source file and process special comments
|
||||
* to produce an HTML file of documentation, similar to javadoc.
|
||||
* @author Norris Boyd
|
||||
* @see rhinotip.jar
|
||||
* @lastmodified xx
|
||||
* @version 1.2 Roland Pennings: Allow multiple files for a function.
|
||||
* @version 1.3 Roland Pennings: Removes ../.. from the input directory name
|
||||
*/
|
||||
defineClass("File")
|
||||
|
||||
var functionDocArray = [];
|
||||
var inputDirName = "";
|
||||
var indexFileArray = [];
|
||||
var indexFile = "";
|
||||
var indexFileName = "index_files";
|
||||
var indexFunctionArray = [];
|
||||
var indexFunction = "";
|
||||
var indexFunctionName = "index_functions";
|
||||
var FileList = [];
|
||||
var DirList = [];
|
||||
var outputdir = null;
|
||||
var debug = 0;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Process JavaScript source file <code>f</code>, writing jsdoc to
|
||||
* file <code>out</code>.
|
||||
* @param f input file
|
||||
* @param fname name of the input file (without the path)
|
||||
* @param inputdir directory of the input file
|
||||
* @param out output file
|
||||
*/
|
||||
function processFile(f, fname, inputdir, out) {
|
||||
var s;
|
||||
var firstLine = true;
|
||||
indexFileArray[fname] = "";
|
||||
|
||||
// write the header of the output file
|
||||
out.writeLine('<HTML><HEADER><TITLE>' + fname + '</TITLE><BODY>');
|
||||
if (inputdir != null) {
|
||||
outstr = '<a name=\"_top_\"></a><pre><a href=\"' + indexFile + '\">Index Files</a> ';
|
||||
outstr += '<a href=\"' + indexFunction + '\">Index Functions</a></pre><hr>';
|
||||
out.writeLine(outstr);
|
||||
}
|
||||
|
||||
// process the input file
|
||||
var comment = "";
|
||||
while ((s = f.readLine()) != null) {
|
||||
var m = s.match(/\/\*\*(.*)/);
|
||||
if (m != null) {
|
||||
// Found a comment start.
|
||||
s = "*" + m[1];
|
||||
do {
|
||||
m = s.match(/(.*)\*\//);
|
||||
if (m != null) {
|
||||
// Found end of comment.
|
||||
comment += m[1];
|
||||
break;
|
||||
}
|
||||
// Strip leading whitespace and "*".
|
||||
comment += s.replace(/^\s*\*/, "");
|
||||
s = f.readLine();
|
||||
} while (s != null);
|
||||
|
||||
if (debug)
|
||||
print("Found comment " + comment);
|
||||
|
||||
if (firstLine) {
|
||||
// We have a comment for the whole file.
|
||||
out.writeLine('<H1>File ' + fname + '</H1>');
|
||||
out.writeLine(processComment(comment,firstLine,fname));
|
||||
out.writeLine('<HR>');
|
||||
firstLine = false;
|
||||
comment = "";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// match the beginning of the function
|
||||
// NB we also match functions without a comment!
|
||||
// if we have two comments one after another only the last one will be taken
|
||||
m = s.match(/^\s*function\s+((\w+)|(\w+)(\s+))\(([^)]*)\)/);
|
||||
if (m != null)
|
||||
{
|
||||
// Found a function start
|
||||
var htmlText = processFunction(m[1], m[2], comment);
|
||||
|
||||
// Save the text in a global variable, so we
|
||||
// can write out a table of contents first.
|
||||
functionDocArray[functionDocArray.length] =
|
||||
{name:m[1], text:htmlText};
|
||||
|
||||
// Store the function also in the indexFunctionArray
|
||||
// so we can have a seperate file with the function table of contents
|
||||
if (indexFunctionArray[m[1]]) {
|
||||
// print("ERROR: function: " + m[1] + " is defined more than once!");
|
||||
// Allow multiple files for a function
|
||||
with (indexFunctionArray[m[1]]) {
|
||||
filename = filename + "|" + fname;
|
||||
// print("filename = " + filename);
|
||||
}
|
||||
} else {
|
||||
indexFunctionArray[m[1]] =
|
||||
{filename:fname};
|
||||
}
|
||||
//reset comment
|
||||
comment = "";
|
||||
}
|
||||
firstLine = false;
|
||||
}
|
||||
|
||||
// Write table of contents.
|
||||
for (var i=0; i < functionDocArray.length; i++) {
|
||||
with (functionDocArray[i]) {
|
||||
out.writeLine('function <A HREF=#' + name +
|
||||
'>' + name + '</A><BR>');
|
||||
}
|
||||
}
|
||||
out.writeLine('<HR>');
|
||||
|
||||
// Now write the saved function documentation.
|
||||
for (i=0; i < functionDocArray.length; i++) {
|
||||
with (functionDocArray[i]) {
|
||||
out.writeLine('<A NAME=' + name + '>');
|
||||
out.writeLine(text);
|
||||
}
|
||||
}
|
||||
out.writeLine('</BODY></HTML>');
|
||||
|
||||
// Now clean up the doc array
|
||||
functionDocArray = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Process function and associated comment.
|
||||
* @param name the name of the function
|
||||
* @param args the args of the function as a single string
|
||||
* @param comment the text of the comment
|
||||
* @return a string for the HTML text of the documentation
|
||||
*/
|
||||
function processFunction(name, args, comment) {
|
||||
if (debug)
|
||||
print("Processing " + name + " " + args + " " + comment);
|
||||
return "<H2>Function " + name + "</H2>" +
|
||||
"<PRE>" +
|
||||
"function " + name + "(" + args + ")" +
|
||||
"</PRE>" +
|
||||
processComment(comment,0,name) +
|
||||
"<P><BR><BR>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Process comment.
|
||||
* @param comment the text of the comment
|
||||
* @param firstLine shows if comment is at the beginning of the file
|
||||
* @param fname name of the file (without path)
|
||||
* @return a string for the HTML text of the documentation
|
||||
*/
|
||||
function processComment(comment,firstLine,fname) {
|
||||
var tags = {};
|
||||
// Use the "lambda" form of regular expression replace,
|
||||
// where the replacement object is a function rather
|
||||
// than a string. The function is called with the
|
||||
// matched text and any parenthetical matches as
|
||||
// arguments, and the result of the function used as the
|
||||
// replacement text.
|
||||
// Here we use the function to build up the "tags" object,
|
||||
// which has a property for each "@" tag that is the name
|
||||
// of the tag, and whose value is an array of the
|
||||
// text following that tag.
|
||||
comment = comment.replace(/@(\w+)\s+([^@]*)/g,
|
||||
function (s, name, text) {
|
||||
var a = tags[name] || [];
|
||||
a.push(text);
|
||||
tags[name] = a;
|
||||
return "";
|
||||
});
|
||||
|
||||
// if we have a comment at the beginning of a file
|
||||
// store the comment for the index file
|
||||
if (firstLine) {
|
||||
indexFileArray[fname] = comment;
|
||||
}
|
||||
|
||||
var out = comment + '<P>';
|
||||
if (tags["param"]) {
|
||||
// Create a table of parameters and their descriptions.
|
||||
var array = tags["param"];
|
||||
var params = "";
|
||||
for (var i=0; i < array.length; i++) {
|
||||
var m = array[i].match(/(\w+)\s+(.*)/);
|
||||
params += '<TR><TD><I>'+m[1]+'</I></TD>' +
|
||||
'<TD>'+m[2]+'</TD></TR>';
|
||||
}
|
||||
out += '<TABLE WIDTH="90%" BORDER=1>';
|
||||
out += '<TR BGCOLOR=0xdddddddd>';
|
||||
out += '<TD><B>Parameter</B></TD>';
|
||||
out += '<TD><B>Description</B></TD></TR>';
|
||||
out += params;
|
||||
out += '</TABLE><P>';
|
||||
}
|
||||
if (tags["return"]) {
|
||||
out += "<DT><B>Returns:</B><DD>";
|
||||
out += tags["return"][0] + "</DL><P>";
|
||||
}
|
||||
if (tags["author"]) {
|
||||
// List the authors together, separated by commas.
|
||||
out += '<DT><B>Author:</B><DD>';
|
||||
var array = tags["author"];
|
||||
for (var i=0; i < array.length; i++) {
|
||||
out += array[i];
|
||||
if (i+1 < array.length)
|
||||
out += ", ";
|
||||
}
|
||||
out += '</DL><P>';
|
||||
}
|
||||
if (tags["version"]) {
|
||||
// Show the version.
|
||||
out += '<DT><B>Version:</B><DD>';
|
||||
var array = tags["version"];
|
||||
for (var i=0; i < array.length; i++) {
|
||||
out += array[i];
|
||||
if (i+1 < array.length)
|
||||
out += "<BR><DD>";
|
||||
}
|
||||
out += '</DL><P>';
|
||||
}
|
||||
if (tags["see"]) {
|
||||
// List the see modules together, separated by <BR>.
|
||||
out += '<DT><B>Dependencies:</B><DD>';
|
||||
var array = tags["see"];
|
||||
for (var i=0; i < array.length; i++) {
|
||||
out += array[i];
|
||||
if (i+1 < array.length)
|
||||
out += "<BR><DD>";
|
||||
}
|
||||
out += '</DL><P>';
|
||||
}
|
||||
if (tags["lastmodified"]) {
|
||||
// Shows a last modified description with client-side js.
|
||||
out += '<DT><B>Last modified:</B><DD>';
|
||||
out += '<script><!--\n';
|
||||
out += 'document.writeln(document.lastModified);\n';
|
||||
out += '// ---></script>\n';
|
||||
out += '</DL><P>';
|
||||
}
|
||||
|
||||
// additional tags can be added here (i.e., "if (tags["see"])...")
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an html output file
|
||||
* @param outputdir directory to put the file
|
||||
* @param htmlfile name of the file
|
||||
*/
|
||||
function CreateOutputFile(outputdir,htmlfile)
|
||||
{
|
||||
if (outputdir==null)
|
||||
{
|
||||
var outname = htmlfile;
|
||||
}
|
||||
else
|
||||
{
|
||||
var separator = Packages.java.io.File.separator;
|
||||
var outname = outputdir + separator + htmlfile.substring(htmlfile.lastIndexOf(separator),htmlfile.length);
|
||||
}
|
||||
print("output file: " + outname);
|
||||
return new File(outname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a javascript file. Puts the generated HTML file in the outdir
|
||||
* @param filename name of the javascript file
|
||||
* @inputdir input directory of the file (default null)
|
||||
*/
|
||||
function processJSFile(filename,inputdir)
|
||||
{
|
||||
if (debug) print("filename = " + filename + " inputdir = " + inputdir);
|
||||
|
||||
if (!filename.match(/\.js$/)) {
|
||||
print("Expected filename to end in '.js'; had instead " +
|
||||
filename + ". I don't treat the file.");
|
||||
} else {
|
||||
if (inputdir==null)
|
||||
{
|
||||
var inname = filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
var separator = Packages.java.io.File.separator;
|
||||
var inname = inputdir + separator + filename;
|
||||
}
|
||||
print("Processing file " + inname);
|
||||
|
||||
var f = new File(inname);
|
||||
|
||||
// create the output file
|
||||
var htmlfile = filename.replace(/\.js$/, ".html");
|
||||
|
||||
var out = CreateOutputFile(outputdir,htmlfile);
|
||||
|
||||
processFile(f, filename, inputdir, out);
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate index files containing links to the processed javascript files
|
||||
* and the generated functions
|
||||
*/
|
||||
function GenerateIndex(dirname)
|
||||
{
|
||||
// construct the files index file
|
||||
var out = CreateOutputFile(outputdir,indexFile);
|
||||
|
||||
// write the beginning of the file
|
||||
out.writeLine('<HTML><HEADER><TITLE>File Index - directory: ' + dirname + '</TITLE><BODY>');
|
||||
out.writeLine('<H1>File Index - directory: ' + dirname + '</H1>\n');
|
||||
out.writeLine('<TABLE WIDTH="90%" BORDER=1>');
|
||||
out.writeLine('<TR BGCOLOR=0xdddddddd>');
|
||||
out.writeLine('<TD><B>File</B></TD>');
|
||||
out.writeLine('<TD><B>Description</B></TD></TR>');
|
||||
|
||||
var separator = Packages.java.io.File.separator;
|
||||
|
||||
// sort the index file array
|
||||
var SortedFileArray = [];
|
||||
for (var fname in indexFileArray)
|
||||
SortedFileArray.push(fname);
|
||||
SortedFileArray.sort();
|
||||
|
||||
for (var i=0; i < SortedFileArray.length; i++) {
|
||||
var fname = SortedFileArray[i];
|
||||
var htmlfile = fname.replace(/\.js$/, ".html");
|
||||
out.writeLine('<TR><TD><A HREF=\"' + htmlfile + '\">' + fname + '</A></TD></TD><TD>');
|
||||
if (indexFileArray[fname])
|
||||
out.writeLine(indexFileArray[fname]);
|
||||
else
|
||||
out.writeLine('No comments');
|
||||
out.writeLine('</TD></TR>\n');
|
||||
}
|
||||
out.writeLine('</TABLE></BODY></HTML>');
|
||||
out.close();
|
||||
|
||||
// construct the functions index file
|
||||
var out = CreateOutputFile(outputdir,indexFunction);
|
||||
|
||||
// write the beginning of the file
|
||||
out.writeLine('<HTML><HEADER><TITLE>Function Index - directory: ' + dirname + '</TITLE><BODY>');
|
||||
out.writeLine('<H1>Function Index - directory: ' + dirname + '</H1>\n');
|
||||
out.writeLine('<TABLE WIDTH="90%" BORDER=1>');
|
||||
out.writeLine('<TR BGCOLOR=0xdddddddd>');
|
||||
out.writeLine('<TD><B>Function</B></TD>');
|
||||
out.writeLine('<TD><B>Files</B></TD></TR>');
|
||||
|
||||
// sort the function array
|
||||
var SortedFunctionArray = [];
|
||||
for (var functionname in indexFunctionArray)
|
||||
SortedFunctionArray.push(functionname);
|
||||
SortedFunctionArray.sort();
|
||||
|
||||
for (var j=0; j < SortedFunctionArray.length; j++) {
|
||||
var funcname = SortedFunctionArray[j];
|
||||
with (indexFunctionArray[funcname]) {
|
||||
var outstr = '<TR><TD>' + funcname + '</TD><TD>';
|
||||
var filelst = filename.split("|");
|
||||
for (var i in filelst) {
|
||||
var htmlfile = filelst[i].replace(/\.js$/, ".html");
|
||||
outstr += '<A HREF=\"' + htmlfile + '#' + funcname + '\">' + filelst[i] + '</A> ';
|
||||
}
|
||||
outstr += '</TD></TR>';
|
||||
out.writeLine(outstr);
|
||||
}
|
||||
}
|
||||
out.writeLine('</TABLE></BODY></HTML>');
|
||||
out.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* prints the options for JSDoc
|
||||
*/
|
||||
function PrintOptions()
|
||||
{
|
||||
print("You can use the following options:\n");
|
||||
print("-d: specify an output directory for the generated html files\n");
|
||||
print("-i: processes all files in an input directory (you can specify several directories)\n");
|
||||
quit();
|
||||
}
|
||||
|
||||
|
||||
// Main Script
|
||||
// first read the arguments
|
||||
if (! arguments)
|
||||
PrintOptions();
|
||||
|
||||
for (var i=0; i < arguments.length; i++) {
|
||||
if (debug) print("argument: + \'" + arguments[i] + "\'");
|
||||
if (arguments[i].match(/^\-/)) {
|
||||
if (String(arguments[i])=="-d"){
|
||||
// output directory for the generated html files
|
||||
|
||||
outputdir = String(arguments[i+1]);
|
||||
if (debug) print("outputdir: + \'" + outputdir + "\'");
|
||||
|
||||
i++;
|
||||
}
|
||||
else if (String(arguments[i])=="-i"){
|
||||
// process all files in an input directory
|
||||
|
||||
DirList.push(String(arguments[i+1]));
|
||||
if (debug) print("inputdir: + \'" + arguments[i+1] + "\'");
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
print("Unknown option: " + arguments[i] + "\n");
|
||||
PrintOptions();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we have a single file
|
||||
if (debug) print("file: + \'" + arguments[i] + "\'");
|
||||
|
||||
FileList.push(String(arguments[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// first handle the single files
|
||||
for (var i in FileList)
|
||||
processJSFile(FileList[i],null);
|
||||
|
||||
// then handle the input directories
|
||||
for (var j in DirList) {
|
||||
var inputdir = String(DirList[j]);
|
||||
|
||||
print("Process input directory: " + inputdir);
|
||||
|
||||
// clean up index arrays
|
||||
var indexFileArray = [];
|
||||
var indexFunctionArray = [];
|
||||
|
||||
// for the directory name get rid of ../../ or ..\..\
|
||||
inputDirName = inputdir.replace(/\.\.\/|\.\.\\/g,"");
|
||||
|
||||
indexFile = indexFileName + "_" + inputDirName + ".html";
|
||||
indexFunction = indexFunctionName + "_" + inputDirName + ".html";
|
||||
|
||||
print("indexFile = " + indexFile);
|
||||
print("indexFunction = " + indexFunction);
|
||||
|
||||
// read the files in the directory
|
||||
var DirFile = new java.io.File(inputdir);
|
||||
var lst = DirFile.list();
|
||||
var separator = Packages.java.io.File.separator;
|
||||
|
||||
for (var i=0; i < lst.length; i++)
|
||||
{
|
||||
processJSFile(String(lst[i]),inputdir);
|
||||
}
|
||||
|
||||
// generate the index files for the input directory
|
||||
GenerateIndex(inputDirName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
54
mozilla/js/rhino/examples/liveConnect.js
Normal file
54
mozilla/js/rhino/examples/liveConnect.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
/**
|
||||
* liveConnect.js: a simple demonstration of JavaScript-to-Java connectivity
|
||||
*/
|
||||
|
||||
// Create a new StringBuffer. Note that the class name must be fully qualified
|
||||
// by its package. Packages other than "java" must start with "Packages", i.e.,
|
||||
// "Packages.javax.servlet...".
|
||||
var sb = new java.lang.StringBuffer();
|
||||
|
||||
// Now add some stuff to the buffer.
|
||||
sb.append("hi, mom");
|
||||
sb.append(3); // this will add "3.0" to the buffer since all JS numbers
|
||||
// are doubles by default
|
||||
sb.append(true);
|
||||
|
||||
// Now print it out. (The toString() method of sb is automatically called
|
||||
// to convert the buffer to a string.)
|
||||
// Should print "hi, mom3.0true".
|
||||
print(sb);
|
||||
53
mozilla/js/rhino/examples/unique.js
Normal file
53
mozilla/js/rhino/examples/unique.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
// unique.js: read the contents of a file and print out the unique lines
|
||||
|
||||
defineClass("File")
|
||||
|
||||
// "arguments[0]" refers to the first argument at the command line to the
|
||||
// script, if present. If not present, "arguments[0]" will be undefined,
|
||||
// which will cause f to read from System.in.
|
||||
var f = new File(arguments[0]);
|
||||
var o = {}
|
||||
var line;
|
||||
while ((line = f.readLine()) != null) {
|
||||
// Use JavaScript objects' inherent nature as an associative
|
||||
// array to provide uniqueness
|
||||
o[line] = true;
|
||||
}
|
||||
for (i in o) {
|
||||
print(i);
|
||||
}
|
||||
BIN
mozilla/js/rhino/macbuild/import
Normal file
BIN
mozilla/js/rhino/macbuild/import
Normal file
Binary file not shown.
BIN
mozilla/js/rhino/macbuild/js.mcp
Normal file
BIN
mozilla/js/rhino/macbuild/js.mcp
Normal file
Binary file not shown.
3388
mozilla/js/rhino/macbuild/js.mcp.xml
Normal file
3388
mozilla/js/rhino/macbuild/js.mcp.xml
Normal file
File diff suppressed because it is too large
Load Diff
BIN
mozilla/js/rhino/macbuild/jsdebug.mcp
Executable file
BIN
mozilla/js/rhino/macbuild/jsdebug.mcp
Executable file
Binary file not shown.
BIN
mozilla/js/rhino/macbuild/jsopt.mcp
Executable file
BIN
mozilla/js/rhino/macbuild/jsopt.mcp
Executable file
Binary file not shown.
2
mozilla/js/rhino/manifest
Normal file
2
mozilla/js/rhino/manifest
Normal file
@@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: org.mozilla.javascript.tools.shell.Main
|
||||
1082
mozilla/js/rhino/org/mozilla/classfile/ByteCode.java
Normal file
1082
mozilla/js/rhino/org/mozilla/classfile/ByteCode.java
Normal file
File diff suppressed because it is too large
Load Diff
1464
mozilla/js/rhino/org/mozilla/classfile/ClassFileWriter.java
Normal file
1464
mozilla/js/rhino/org/mozilla/classfile/ClassFileWriter.java
Normal file
File diff suppressed because it is too large
Load Diff
130
mozilla/js/rhino/org/mozilla/javascript/Arguments.java
Normal file
130
mozilla/js/rhino/org/mozilla/javascript/Arguments.java
Normal file
@@ -0,0 +1,130 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
/**
|
||||
* This class implements the "arguments" object.
|
||||
*
|
||||
* See ECMA 10.1.8
|
||||
*
|
||||
* @see org.mozilla.javascript.NativeCall
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
class Arguments extends ScriptableObject {
|
||||
|
||||
public Arguments(NativeCall activation) {
|
||||
this.activation = activation;
|
||||
|
||||
Scriptable parent = activation.getParentScope();
|
||||
setParentScope(parent);
|
||||
setPrototype(ScriptableObject.getObjectPrototype(parent));
|
||||
|
||||
args = activation.getOriginalArguments();
|
||||
int length = args.length;
|
||||
Object callee = activation.funObj;
|
||||
|
||||
defineProperty("length", new Integer(length),
|
||||
ScriptableObject.DONTENUM);
|
||||
defineProperty("callee", callee, ScriptableObject.DONTENUM);
|
||||
|
||||
hasCaller = (activation.funObj.version <= Context.VERSION_1_3 &&
|
||||
activation.funObj.version != Context.VERSION_DEFAULT);
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return "Arguments";
|
||||
}
|
||||
|
||||
public boolean has(String name, Scriptable start) {
|
||||
return (hasCaller && name.equals("caller")) || super.has(name, start);
|
||||
}
|
||||
|
||||
public boolean has(int index, Scriptable start) {
|
||||
Object[] args = activation.getOriginalArguments();
|
||||
return (0 <= index && index < args.length) || super.has(index, start);
|
||||
}
|
||||
|
||||
public Object get(String name, Scriptable start) {
|
||||
if (hasCaller && name.equals("caller")) {
|
||||
NativeCall caller = activation.caller;
|
||||
if (caller == null || caller.originalArgs == null)
|
||||
return null;
|
||||
return caller.get("arguments", caller);
|
||||
}
|
||||
return super.get(name, start);
|
||||
}
|
||||
|
||||
public Object get(int index, Scriptable start) {
|
||||
if (0 <= index && index < args.length) {
|
||||
NativeFunction f = activation.funObj;
|
||||
if (index < f.argCount)
|
||||
return activation.get(f.names[index+1], activation);
|
||||
return args[index];
|
||||
}
|
||||
return super.get(index, start);
|
||||
}
|
||||
|
||||
public void put(String name, Scriptable start, Object value) {
|
||||
if (name.equals("caller")) {
|
||||
// Set "hasCaller" to false so that we won't look up a
|
||||
// computed value.
|
||||
hasCaller = false;
|
||||
}
|
||||
super.put(name, start, value);
|
||||
}
|
||||
|
||||
public void put(int index, Scriptable start, Object value) {
|
||||
if (0 <= index && index < args.length) {
|
||||
NativeFunction f = activation.funObj;
|
||||
if (index < f.argCount)
|
||||
activation.put(f.names[index+1], activation, value);
|
||||
else
|
||||
args[index] = value;
|
||||
return;
|
||||
}
|
||||
super.put(index, start, value);
|
||||
}
|
||||
|
||||
public void delete(String name) {
|
||||
if (name.equals("caller"))
|
||||
hasCaller = false;
|
||||
super.delete(name);
|
||||
}
|
||||
|
||||
private NativeCall activation;
|
||||
private Object[] args;
|
||||
private boolean hasCaller;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Waldemar Horwat
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
package org.mozilla.javascript;
|
||||
|
||||
final class BinaryDigitReader {
|
||||
int lgBase; // Logarithm of base of number
|
||||
int digit; // Current digit value in radix given by base
|
||||
int digitPos; // Bit position of last bit extracted from digit
|
||||
String digits; // String containing the digits
|
||||
int start; // Index of the first remaining digit
|
||||
int end; // Index past the last remaining digit
|
||||
|
||||
BinaryDigitReader(int base, String digits, int start, int end) {
|
||||
lgBase = 0;
|
||||
while (base != 1) {
|
||||
lgBase++;
|
||||
base >>= 1;
|
||||
}
|
||||
digitPos = 0;
|
||||
this.digits = digits;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
/* Return the next binary digit from the number or -1 if done */
|
||||
int getNextBinaryDigit()
|
||||
{
|
||||
if (digitPos == 0) {
|
||||
if (start == end)
|
||||
return -1;
|
||||
|
||||
char c = digits.charAt(start++);
|
||||
if ('0' <= c && c <= '9')
|
||||
digit = c - '0';
|
||||
else if ('a' <= c && c <= 'z')
|
||||
digit = c - 'a' + 10;
|
||||
else digit = c - 'A' + 10;
|
||||
digitPos = lgBase;
|
||||
}
|
||||
return digit >> --digitPos & 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
// API class
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
/**
|
||||
* Thrown if errors are detected while attempting to define a host object
|
||||
* from a Java class.
|
||||
*/
|
||||
public class ClassDefinitionException extends Exception {
|
||||
|
||||
public ClassDefinitionException(String detail) {
|
||||
super(detail);
|
||||
}
|
||||
}
|
||||
61
mozilla/js/rhino/org/mozilla/javascript/ClassNameHelper.java
Normal file
61
mozilla/js/rhino/org/mozilla/javascript/ClassNameHelper.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
* Roger Lawrence
|
||||
* Andi Vajda
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
public interface ClassNameHelper {
|
||||
|
||||
public String getTargetClassFileName();
|
||||
|
||||
public void setTargetClassFileName(String classFileName);
|
||||
|
||||
public String getTargetPackage();
|
||||
|
||||
public void setTargetPackage(String targetPackage);
|
||||
|
||||
public String getTargetClassFileName(String className);
|
||||
|
||||
public String getGeneratingDirectory();
|
||||
|
||||
public void setTargetExtends(Class extendsClass);
|
||||
|
||||
public void setTargetImplements(Class[] implementsClasses);
|
||||
|
||||
public ClassOutput getClassOutput();
|
||||
|
||||
public void setClassOutput(ClassOutput classOutput);
|
||||
}
|
||||
56
mozilla/js/rhino/org/mozilla/javascript/ClassOutput.java
Normal file
56
mozilla/js/rhino/org/mozilla/javascript/ClassOutput.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Andi Vajda
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
package org.mozilla.javascript;
|
||||
|
||||
// API class
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This interface is implemented by classes interested in the bytecode
|
||||
* generated by the rhino compiler for script objects.
|
||||
*
|
||||
* @see Context
|
||||
* @author Andi Vajda
|
||||
*/
|
||||
public interface ClassOutput {
|
||||
|
||||
/**
|
||||
* @param className the name of the class for which bytecode is ready.
|
||||
* @return a stream into which to write bytecode.
|
||||
* @since 1.5 Release 2
|
||||
*/
|
||||
public OutputStream getOutputStream(String className)
|
||||
throws IOException;
|
||||
1819
mozilla/js/rhino/org/mozilla/javascript/Context.java
Normal file
1819
mozilla/js/rhino/org/mozilla/javascript/Context.java
Normal file
File diff suppressed because it is too large
Load Diff
1197
mozilla/js/rhino/org/mozilla/javascript/DToA.java
Normal file
1197
mozilla/js/rhino/org/mozilla/javascript/DToA.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,63 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
/**
|
||||
* This is the default error reporter for JavaScript.
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
class DefaultErrorReporter implements ErrorReporter {
|
||||
|
||||
public void warning(String message, String sourceName, int line,
|
||||
String lineSource, int lineOffset)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public void error(String message, String sourceName, int line,
|
||||
String lineSource, int lineOffset)
|
||||
{
|
||||
throw new EvaluatorException(message);
|
||||
}
|
||||
|
||||
public EvaluatorException runtimeError(String message, String sourceName,
|
||||
int line, String lineSource,
|
||||
int lineOffset)
|
||||
{
|
||||
return new EvaluatorException(message);
|
||||
}
|
||||
}
|
||||
152
mozilla/js/rhino/org/mozilla/javascript/EcmaError.java
Normal file
152
mozilla/js/rhino/org/mozilla/javascript/EcmaError.java
Normal file
@@ -0,0 +1,152 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Roger Lawrence
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
// API class
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
/**
|
||||
* The class of exceptions raised by the engine as described in
|
||||
* ECMA edition 3. See section 15.11.6 in particular.
|
||||
*/
|
||||
public class EcmaError extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Create an exception with the specified detail message.
|
||||
*
|
||||
* Errors internal to the JavaScript engine will simply throw a
|
||||
* RuntimeException.
|
||||
*
|
||||
* @param nativeError the NativeError object constructed for this error
|
||||
* @param sourceName the name of the source reponsible for the error
|
||||
* @param lineNumber the line number of the source
|
||||
* @param columnNumber the columnNumber of the source (may be zero if
|
||||
* unknown)
|
||||
* @param lineSource the source of the line containing the error (may be
|
||||
* null if unknown)
|
||||
*/
|
||||
public EcmaError(NativeError nativeError, String sourceName,
|
||||
int lineNumber, int columnNumber, String lineSource)
|
||||
{
|
||||
super("EcmaError");
|
||||
errorObject = nativeError;
|
||||
this.sourceName = sourceName;
|
||||
this.lineNumber = lineNumber;
|
||||
this.columnNumber = columnNumber;
|
||||
this.lineSource = lineSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of the error, which currently consists
|
||||
* of the name of the error together with the message.
|
||||
*/
|
||||
public String toString() {
|
||||
if (sourceName != null && lineNumber > 0)
|
||||
return errorObject.toString() + " (" + sourceName +
|
||||
"; line " + lineNumber + ")";
|
||||
else
|
||||
return errorObject.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the error.
|
||||
*
|
||||
* ECMA edition 3 defines the following
|
||||
* errors: EvalError, RangeError, ReferenceError,
|
||||
* SyntaxError, TypeError, and URIError. Additional error names
|
||||
* may be added in the future.
|
||||
*
|
||||
* See ECMA edition 3, 15.11.7.9.
|
||||
*
|
||||
* @return the name of the error.
|
||||
*/
|
||||
public String getName() {
|
||||
return errorObject.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message corresponding to the error.
|
||||
*
|
||||
* See ECMA edition 3, 15.11.7.10.
|
||||
*
|
||||
* @return an implemenation-defined string describing the error.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return errorObject.getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the source containing the error, or null
|
||||
* if that information is not available.
|
||||
*/
|
||||
public String getSourceName() {
|
||||
return sourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the line number of the statement causing the error,
|
||||
* or zero if not available.
|
||||
*/
|
||||
public int getLineNumber() {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error object corresponding to this exception.
|
||||
*/
|
||||
public Scriptable getErrorObject() {
|
||||
return errorObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column number of the location of the error, or zero if unknown.
|
||||
*/
|
||||
public int getColumnNumber() {
|
||||
return columnNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* The source of the line causing the error, or zero if unknown.
|
||||
*/
|
||||
public String getLineSource() {
|
||||
return lineSource;
|
||||
}
|
||||
|
||||
private NativeError errorObject;
|
||||
private String sourceName;
|
||||
private int lineNumber;
|
||||
private int columnNumber;
|
||||
private String lineSource;
|
||||
}
|
||||
103
mozilla/js/rhino/org/mozilla/javascript/ErrorReporter.java
Normal file
103
mozilla/js/rhino/org/mozilla/javascript/ErrorReporter.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
// API class
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
/**
|
||||
* This is interface defines a protocol for the reporting of
|
||||
* errors during JavaScript translation or execution.
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
|
||||
public interface ErrorReporter {
|
||||
|
||||
/**
|
||||
* Report a warning.
|
||||
*
|
||||
* The implementing class may choose to ignore the warning
|
||||
* if it desires.
|
||||
*
|
||||
* @param message a String describing the warning
|
||||
* @param sourceName a String describing the JavaScript source
|
||||
* where the warning occured; typically a filename or URL
|
||||
* @param line the line number associated with the warning
|
||||
* @param lineSource the text of the line (may be null)
|
||||
* @param lineOffset the offset into lineSource where problem was detected
|
||||
*/
|
||||
void warning(String message, String sourceName, int line,
|
||||
String lineSource, int lineOffset);
|
||||
|
||||
/**
|
||||
* Report an error.
|
||||
*
|
||||
* The implementing class is free to throw an exception if
|
||||
* it desires.
|
||||
*
|
||||
* If execution has not yet begun, the JavaScript engine is
|
||||
* free to find additional errors rather than terminating
|
||||
* the translation. It will not execute a script that had
|
||||
* errors, however.
|
||||
*
|
||||
* @param message a String describing the error
|
||||
* @param sourceName a String describing the JavaScript source
|
||||
* where the error occured; typically a filename or URL
|
||||
* @param line the line number associated with the error
|
||||
* @param lineSource the text of the line (may be null)
|
||||
* @param lineOffset the offset into lineSource where problem was detected
|
||||
*/
|
||||
void error(String message, String sourceName, int line,
|
||||
String lineSource, int lineOffset);
|
||||
|
||||
/**
|
||||
* Creates an EvaluatorException that may be thrown.
|
||||
*
|
||||
* runtimeErrors, unlike errors, will always terminate the
|
||||
* current script.
|
||||
*
|
||||
* @param message a String describing the error
|
||||
* @param sourceName a String describing the JavaScript source
|
||||
* where the error occured; typically a filename or URL
|
||||
* @param line the line number associated with the error
|
||||
* @param lineSource the text of the line (may be null)
|
||||
* @param lineOffset the offset into lineSource where problem was detected
|
||||
* @return an EvaluatorException that will be thrown.
|
||||
*/
|
||||
EvaluatorException runtimeError(String message, String sourceName,
|
||||
int line, String lineSource,
|
||||
int lineOffset);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
/**
|
||||
* The class of exceptions thrown by the JavaScript engine.
|
||||
*/
|
||||
public class EvaluatorException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Create an exception with the specified detail message.
|
||||
*
|
||||
* Errors internal to the JavaScript engine will simply throw a
|
||||
* RuntimeException.
|
||||
*
|
||||
* @param detail a message with detail about the exception
|
||||
*/
|
||||
public EvaluatorException(String detail) {
|
||||
super(detail);
|
||||
}
|
||||
|
||||
}
|
||||
342
mozilla/js/rhino/org/mozilla/javascript/FlattenedObject.java
Normal file
342
mozilla/js/rhino/org/mozilla/javascript/FlattenedObject.java
Normal file
@@ -0,0 +1,342 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
* Roger Lawrence
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Manipulate a Scriptable object as if its prototype chain were flattened.
|
||||
* <p>
|
||||
* This class has been deprecated in favor of the static methods
|
||||
* <code>getProperty</code>, <code>putProperty</code>, and
|
||||
* <code>deleteProperty</code>. Those methods provide the
|
||||
* same functionality without the confusing and inefficient need to construct
|
||||
* a new object instance.
|
||||
*
|
||||
* @see org.mozilla.javascript.ScriptableObject
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
|
||||
public class FlattenedObject {
|
||||
|
||||
/**
|
||||
* Construct a new FlattenedObject.
|
||||
*
|
||||
* @param object the object to be viewed with flattened properties
|
||||
* @deprecated
|
||||
*/
|
||||
public FlattenedObject(Scriptable object) {
|
||||
this.obj = object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the associated Scriptable object.
|
||||
* @deprecated
|
||||
*/
|
||||
public Scriptable getObject() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a property exists in an object.
|
||||
*
|
||||
* This is a more convenient (and less efficient) form than
|
||||
* <code>Scriptable.has()</code>.
|
||||
* It returns true if and only if the property
|
||||
* exists in this object or any of the objects in its prototype
|
||||
* chain.
|
||||
*
|
||||
* @param id the property index, which may be either a String or a
|
||||
* Number
|
||||
* @return true if and only if the property exists in the prototype
|
||||
* chain
|
||||
* @see org.mozilla.javascript.Scriptable#has
|
||||
* @deprecated As of 1.5R2, replaced by ScriptableObject.getProperty
|
||||
*/
|
||||
public boolean hasProperty(Object id) {
|
||||
String stringId = ScriptRuntime.toString(id);
|
||||
String s = ScriptRuntime.getStringId(stringId);
|
||||
if (s == null)
|
||||
return getBase(obj, ScriptRuntime.getIntId(stringId)) != null;
|
||||
return getBase(obj, s) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a property of an object.
|
||||
* <p>
|
||||
* This is a more convenient (and less efficient) form than
|
||||
* <code>Scriptable.get()</code>. It corresponds exactly to the
|
||||
* expression <code>obj[id]</code> in JavaScript. This method
|
||||
* will traverse the prototype chain of an object to find the
|
||||
* property.<p>
|
||||
*
|
||||
* If the property does not exist in the object or its prototype
|
||||
* chain, the undefined value will be returned.
|
||||
*
|
||||
* @param id the property index; can be a String or a Number; the
|
||||
* String may contain characters representing a number
|
||||
* @return the value of the property or the undefined value
|
||||
* @see org.mozilla.javascript.Scriptable#get
|
||||
* @see org.mozilla.javascript.Context#getUndefinedValue
|
||||
* @deprecated As of 1.5R2, replaced by ScriptableObject.getProperty
|
||||
*/
|
||||
public Object getProperty(Object id) {
|
||||
String s = ScriptRuntime.getStringId(id);
|
||||
int index = s == null ? ScriptRuntime.getIntId(id) : 0;
|
||||
Scriptable m = obj;
|
||||
Object result;
|
||||
for(;;) {
|
||||
result = s == null ? m.get(index, obj) : m.get(s, obj);
|
||||
if (result != Scriptable.NOT_FOUND)
|
||||
break;
|
||||
m = m.getPrototype();
|
||||
if (m == null)
|
||||
return Undefined.instance;
|
||||
}
|
||||
if (result instanceof Scriptable)
|
||||
return new FlattenedObject((Scriptable) result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property of an object.
|
||||
*
|
||||
* This is a more convenient (and less efficient) form than that
|
||||
* provided in Scriptable. It corresponds exactly to the
|
||||
* expression <code>obj[id] = val</code> in JavaScript.<p>
|
||||
*
|
||||
* @param id the property index, which may be either a String or
|
||||
* a Number
|
||||
* @param value the value of the property
|
||||
* @see org.mozilla.javascript.Scriptable#put
|
||||
* @deprecated As of 1.5R2, replaced by ScriptableObject.putProperty
|
||||
*/
|
||||
public void putProperty(Object id, Object value) {
|
||||
String s = ScriptRuntime.getStringId(id);
|
||||
if (value instanceof FlattenedObject)
|
||||
value = ((FlattenedObject) value).getObject();
|
||||
Scriptable x;
|
||||
if (s == null) {
|
||||
int index = ScriptRuntime.getIntId(id);
|
||||
x = getBase(obj, index);
|
||||
if (x == null)
|
||||
x = obj;
|
||||
x.put(index, obj, value);
|
||||
return;
|
||||
}
|
||||
x = getBase(obj, s);
|
||||
if (x == null)
|
||||
x = obj;
|
||||
x.put(s, obj, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a property.
|
||||
*
|
||||
* This method provides the functionality of the <code>delete</code>
|
||||
* operator in JavaScript.
|
||||
*
|
||||
* @param id the property index, which may be either a String or
|
||||
* a Number
|
||||
* @return true if the property didn't exist, or existed and was removed
|
||||
* @see org.mozilla.javascript.Scriptable#delete
|
||||
* @deprecated as of 1.5R2, replaced by ScriptableObject.deleteProperty
|
||||
*/
|
||||
public boolean deleteProperty(Object id) {
|
||||
String s = ScriptRuntime.getStringId(id);
|
||||
if (s == null) {
|
||||
int index = ScriptRuntime.getIntId(id);
|
||||
Scriptable base = getBase(obj, index);
|
||||
if (base == null)
|
||||
return true;
|
||||
base.delete(index);
|
||||
return !base.has(index, base);
|
||||
}
|
||||
Scriptable base = getBase(obj, s);
|
||||
if (base == null)
|
||||
return true;
|
||||
base.delete(s);
|
||||
return !base.has(s, base);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array that contains the ids of the properties.
|
||||
*
|
||||
* <p>This method will walk the prototype chain and collect the
|
||||
* ids of all objects in the prototype chain.<p>
|
||||
*
|
||||
* If an id appears in more than one object in the prototype chain,
|
||||
* it will only be in the array once. (So all the entries in the
|
||||
* array will be unique respective to equals().)
|
||||
*
|
||||
* @see org.mozilla.javascript.Scriptable#getIds
|
||||
* @deprecated
|
||||
*/
|
||||
public Object[] getIds() {
|
||||
Hashtable h = new Hashtable(11);
|
||||
Scriptable m = obj;
|
||||
while (m != null) {
|
||||
Object[] e = m.getIds();
|
||||
for (int i=0; i < e.length; i++) {
|
||||
h.put(e[i], Boolean.TRUE);
|
||||
}
|
||||
m = m.getPrototype();
|
||||
}
|
||||
Enumeration keys = h.keys();
|
||||
Object elem;
|
||||
Object[] result = new Object[h.size()];
|
||||
int index = 0;
|
||||
while (keys.hasMoreElements()) {
|
||||
elem = keys.nextElement();
|
||||
result[index++] = elem;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consider this object to be a function, and call it.
|
||||
*
|
||||
* @param cx the current Context for this thread
|
||||
* @param thisObj the JavaScript 'this' for the call
|
||||
* @param args the arguments for the call
|
||||
* @return the result of the JavaScript function call
|
||||
* @exception NotAFunctionException if this object is not a function
|
||||
* @exception JavaScriptException if an uncaught JavaScript exception
|
||||
* occurred while executing the function
|
||||
* @see org.mozilla.javascript.Function#call
|
||||
* @deprecated
|
||||
*/
|
||||
public Object call(Context cx, Scriptable thisObj, Object[] args)
|
||||
throws NotAFunctionException,
|
||||
JavaScriptException
|
||||
{
|
||||
if (!(obj instanceof Function)) {
|
||||
throw new NotAFunctionException();
|
||||
}
|
||||
return ScriptRuntime.call(cx, obj, thisObj, args, (Function) obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consider this object to be a function, and invoke it as a
|
||||
* constructor call.
|
||||
*
|
||||
* @param cx the current Context for this thread
|
||||
* @param args the arguments for the constructor call
|
||||
* @return the allocated object
|
||||
* @exception NotAFunctionException if this object is not a function
|
||||
* @exception JavaScriptException if an uncaught JavaScript exception
|
||||
* occurred while executing the constructor
|
||||
* @see org.mozilla.javascript.Function#construct
|
||||
* @deprecated
|
||||
*/
|
||||
public Scriptable construct(Context cx, Object[] args)
|
||||
throws NotAFunctionException,
|
||||
JavaScriptException
|
||||
{
|
||||
if (!(obj instanceof Function)) {
|
||||
throw new NotAFunctionException();
|
||||
}
|
||||
return ScriptRuntime.newObject(cx, obj, args, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property indicated by the id, and invoke it with the
|
||||
* specified arguments.
|
||||
* <p>
|
||||
* For example, for a FlattenedObject <code>obj</code>,
|
||||
* and a Java array <code>a</code> consisting of a single string
|
||||
* <code>"hi"</code>, the call <pre>
|
||||
* obj.callMethod("m", a)</pre>
|
||||
* is equivalent to the JavaScript code <code>obj.m("hi")</code>.<p>
|
||||
*
|
||||
* If the property is not found or is not a function, an
|
||||
* exception will be thrown.
|
||||
*
|
||||
* @param id the Number or String to use to find the function property
|
||||
* to call
|
||||
* @param args the arguments for the constructor call
|
||||
* @return the result of the call
|
||||
* @exception PropertyException if the designated property
|
||||
* was not found
|
||||
* @exception NotAFunctionException if this object is not a function
|
||||
* @exception JavaScriptException if an uncaught JavaScript exception
|
||||
* occurred while executing the method
|
||||
* @see org.mozilla.javascript.Function#call
|
||||
* @deprecated
|
||||
*/
|
||||
public Object callMethod(Object id, Object[] args)
|
||||
throws PropertyException,
|
||||
NotAFunctionException,
|
||||
JavaScriptException
|
||||
{
|
||||
if (!hasProperty(id)) {
|
||||
throw new PropertyException(
|
||||
Context.getMessage("msg.prop.not.found", null));
|
||||
}
|
||||
Object o = getProperty(id);
|
||||
if (o instanceof FlattenedObject)
|
||||
return ((FlattenedObject) o).call(Context.getContext(), obj, args);
|
||||
throw new NotAFunctionException();
|
||||
}
|
||||
|
||||
/****** End of API *******/
|
||||
|
||||
private static Scriptable getBase(Scriptable obj, String s) {
|
||||
Scriptable m = obj;
|
||||
while (m != null) {
|
||||
if (m.has(s, obj))
|
||||
return m;
|
||||
m = m.getPrototype();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Scriptable getBase(Scriptable obj, int index) {
|
||||
Scriptable m = obj;
|
||||
while (m != null) {
|
||||
if (m.has(index, obj))
|
||||
return m;
|
||||
m = m.getPrototype();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Scriptable obj;
|
||||
}
|
||||
|
||||
86
mozilla/js/rhino/org/mozilla/javascript/Function.java
Normal file
86
mozilla/js/rhino/org/mozilla/javascript/Function.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
// API class
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
/**
|
||||
* This is interface that all functions in JavaScript must implement.
|
||||
* The interface provides for calling functions and constructors.
|
||||
*
|
||||
* @see org.mozilla.javascript.Scriptable
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
|
||||
public interface Function extends Scriptable {
|
||||
/**
|
||||
* Call the function.
|
||||
*
|
||||
* Note that the array of arguments is not guaranteed to have
|
||||
* length greater than 0.
|
||||
*
|
||||
* @param cx the current Context for this thread
|
||||
* @param scope the scope to execute the function relative to. This is
|
||||
* set to the value returned by getParentScope() except
|
||||
* when the function is called from a closure.
|
||||
* @param thisObj the JavaScript <code>this</code> object
|
||||
* @param args the array of arguments
|
||||
* @return the result of the call
|
||||
* @exception JavaScriptException if an uncaught exception
|
||||
* occurred while executing the function
|
||||
*/
|
||||
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
|
||||
Object[] args)
|
||||
throws JavaScriptException;
|
||||
|
||||
/**
|
||||
* Call the function as a constructor.
|
||||
*
|
||||
* This method is invoked by the runtime in order to satisfy a use
|
||||
* of the JavaScript <code>new</code> operator. This method is
|
||||
* expected to create a new object and return it.
|
||||
*
|
||||
* @param cx the current Context for this thread
|
||||
* @param scope an enclosing scope of the caller except
|
||||
* when the function is called from a closure.
|
||||
* @param args the array of arguments
|
||||
* @return the allocated object
|
||||
* @exception JavaScriptException if an uncaught exception
|
||||
* occurred while executing the constructor
|
||||
*/
|
||||
public Scriptable construct(Context cx, Scriptable scope, Object[] args)
|
||||
throws JavaScriptException;
|
||||
}
|
||||
94
mozilla/js/rhino/org/mozilla/javascript/FunctionNode.java
Normal file
94
mozilla/js/rhino/org/mozilla/javascript/FunctionNode.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
* Roger Lawrence
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FunctionNode extends Node {
|
||||
|
||||
public FunctionNode(String name, Node left, Node right) {
|
||||
super(TokenStream.FUNCTION, left, right, name);
|
||||
itsVariableTable = new VariableTable();
|
||||
}
|
||||
|
||||
public String getFunctionName() {
|
||||
return getString();
|
||||
}
|
||||
|
||||
public VariableTable getVariableTable() {
|
||||
return itsVariableTable;
|
||||
}
|
||||
|
||||
public boolean requiresActivation() {
|
||||
return itsNeedsActivation;
|
||||
}
|
||||
|
||||
public boolean setRequiresActivation(boolean b) {
|
||||
return itsNeedsActivation = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* There are three types of functions that can be defined. The first
|
||||
* is a function statement. This is a function appearing as a top-level
|
||||
* statement (i.e., not nested inside some other statement) in either a
|
||||
* script or a function.
|
||||
*
|
||||
* The second is a function expression, which is a function appearing in
|
||||
* an expression except for the third type, which is...
|
||||
*
|
||||
* The third type is a function expression where the expression is the
|
||||
* top-level expression in an expression statement.
|
||||
*
|
||||
* The three types of functions have different treatment and must be
|
||||
* distinquished.
|
||||
*/
|
||||
public static final byte FUNCTION_STATEMENT = 1;
|
||||
public static final byte FUNCTION_EXPRESSION = 2;
|
||||
public static final byte FUNCTION_EXPRESSION_STATEMENT = 3;
|
||||
|
||||
public byte getFunctionType() {
|
||||
return itsFunctionType;
|
||||
}
|
||||
|
||||
public void setFunctionType(byte functionType) {
|
||||
itsFunctionType = functionType;
|
||||
}
|
||||
|
||||
protected VariableTable itsVariableTable;
|
||||
protected boolean itsNeedsActivation;
|
||||
protected byte itsFunctionType;
|
||||
}
|
||||
636
mozilla/js/rhino/org/mozilla/javascript/FunctionObject.java
Normal file
636
mozilla/js/rhino/org/mozilla/javascript/FunctionObject.java
Normal file
@@ -0,0 +1,636 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
* Ted Neward
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
// API class
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import java.lang.reflect.*;
|
||||
|
||||
public class FunctionObject extends NativeFunction {
|
||||
|
||||
/**
|
||||
* Create a JavaScript function object from a Java method.
|
||||
*
|
||||
* <p>The <code>member</code> argument must be either a java.lang.reflect.Method
|
||||
* or a java.lang.reflect.Constructor and must match one of two forms.<p>
|
||||
*
|
||||
* The first form is a member with zero or more parameters
|
||||
* of the following types: Object, String, boolean, Scriptable,
|
||||
* byte, short, int, float, or double. The Long type is not supported
|
||||
* because the double representation of a long (which is the
|
||||
* EMCA-mandated storage type for Numbers) may lose precision.
|
||||
* If the member is a Method, the return value must be void or one
|
||||
* of the types allowed for parameters.<p>
|
||||
*
|
||||
* The runtime will perform appropriate conversions based
|
||||
* upon the type of the parameter. A parameter type of
|
||||
* Object specifies that no conversions are to be done. A parameter
|
||||
* of type String will use Context.toString to convert arguments.
|
||||
* Similarly, parameters of type double, boolean, and Scriptable
|
||||
* will cause Context.toNumber, Context.toBoolean, and
|
||||
* Context.toObject, respectively, to be called.<p>
|
||||
*
|
||||
* If the method is not static, the Java 'this' value will
|
||||
* correspond to the JavaScript 'this' value. Any attempt
|
||||
* to call the function with a 'this' value that is not
|
||||
* of the right Java type will result in an error.<p>
|
||||
*
|
||||
* The second form is the variable arguments (or "varargs")
|
||||
* form. If the FunctionObject will be used as a constructor,
|
||||
* the member must have the following parameters
|
||||
* <pre>
|
||||
* (Context cx, Object[] args, Function ctorObj,
|
||||
* boolean inNewExpr)</pre>
|
||||
* and if it is a Method, be static and return an Object result.<p>
|
||||
*
|
||||
* Otherwise, if the FunctionObject will <i>not</i> be used to define a
|
||||
* constructor, the member must be a static Method with parameters
|
||||
* (Context cx, Scriptable thisObj, Object[] args,
|
||||
* Function funObj) </pre>
|
||||
* <pre>
|
||||
* and an Object result.<p>
|
||||
*
|
||||
* When the function varargs form is called as part of a function call,
|
||||
* the <code>args</code> parameter contains the
|
||||
* arguments, with <code>thisObj</code>
|
||||
* set to the JavaScript 'this' value. <code>funObj</code>
|
||||
* is the function object for the invoked function.<p>
|
||||
*
|
||||
* When the constructor varargs form is called or invoked while evaluating
|
||||
* a <code>new</code> expression, <code>args</code> contains the
|
||||
* arguments, <code>ctorObj</code> refers to this FunctionObject, and
|
||||
* <code>inNewExpr</code> is true if and only if a <code>new</code>
|
||||
* expression caused the call. This supports defining a function that
|
||||
* has different behavior when called as a constructor than when
|
||||
* invoked as a normal function call. (For example, the Boolean
|
||||
* constructor, when called as a function,
|
||||
* will convert to boolean rather than creating a new object.)<p>
|
||||
*
|
||||
* @param name the name of the function
|
||||
* @param methodOrConstructor a java.lang.reflect.Method or a java.lang.reflect.Constructor
|
||||
* that defines the object
|
||||
* @param scope enclosing scope of function
|
||||
* @see org.mozilla.javascript.Scriptable
|
||||
*/
|
||||
public FunctionObject(String name, Member methodOrConstructor,
|
||||
Scriptable scope)
|
||||
{
|
||||
String methodName;
|
||||
if (methodOrConstructor instanceof Constructor) {
|
||||
ctor = (Constructor) methodOrConstructor;
|
||||
isStatic = true; // well, doesn't take a 'this'
|
||||
types = ctor.getParameterTypes();
|
||||
methodName = ctor.getName();
|
||||
} else {
|
||||
method = (Method) methodOrConstructor;
|
||||
isStatic = Modifier.isStatic(method.getModifiers());
|
||||
types = method.getParameterTypes();
|
||||
methodName = method.getName();
|
||||
}
|
||||
String myNames[] = { name };
|
||||
super.names = myNames;
|
||||
int length;
|
||||
if (types.length == 4 && (types[1].isArray() || types[2].isArray())) {
|
||||
// Either variable args or an error.
|
||||
if (types[1].isArray()) {
|
||||
if (!isStatic ||
|
||||
types[0] != Context.class ||
|
||||
types[1].getComponentType() != ScriptRuntime.ObjectClass ||
|
||||
types[2] != ScriptRuntime.FunctionClass ||
|
||||
types[3] != Boolean.TYPE)
|
||||
{
|
||||
String[] args = { methodName };
|
||||
String message = Context.getMessage("msg.varargs.ctor",
|
||||
args);
|
||||
throw Context.reportRuntimeError(message);
|
||||
}
|
||||
parmsLength = VARARGS_CTOR;
|
||||
} else {
|
||||
if (!isStatic ||
|
||||
types[0] != Context.class ||
|
||||
types[1] != ScriptRuntime.ScriptableClass ||
|
||||
types[2].getComponentType() != ScriptRuntime.ObjectClass ||
|
||||
types[3] != ScriptRuntime.FunctionClass)
|
||||
{
|
||||
String[] args = { methodName };
|
||||
String message = Context.getMessage("msg.varargs.fun",
|
||||
args);
|
||||
throw Context.reportRuntimeError(message);
|
||||
}
|
||||
parmsLength = VARARGS_METHOD;
|
||||
}
|
||||
// XXX check return type
|
||||
length = 1;
|
||||
} else {
|
||||
parmsLength = (short) types.length;
|
||||
boolean hasConversions = false;
|
||||
for (int i=0; i < parmsLength; i++) {
|
||||
Class type = types[i];
|
||||
if (type == ScriptRuntime.ObjectClass) {
|
||||
// may not need conversions
|
||||
} else if (type == ScriptRuntime.StringClass ||
|
||||
type == ScriptRuntime.BooleanClass ||
|
||||
ScriptRuntime.NumberClass.isAssignableFrom(type) ||
|
||||
Scriptable.class.isAssignableFrom(type))
|
||||
{
|
||||
hasConversions = true;
|
||||
} else if (type == Boolean.TYPE) {
|
||||
hasConversions = true;
|
||||
types[i] = ScriptRuntime.BooleanClass;
|
||||
} else if (type == Byte.TYPE) {
|
||||
hasConversions = true;
|
||||
types[i] = ScriptRuntime.ByteClass;
|
||||
} else if (type == Short.TYPE) {
|
||||
hasConversions = true;
|
||||
types[i] = ScriptRuntime.ShortClass;
|
||||
} else if (type == Integer.TYPE) {
|
||||
hasConversions = true;
|
||||
types[i] = ScriptRuntime.IntegerClass;
|
||||
} else if (type == Float.TYPE) {
|
||||
hasConversions = true;
|
||||
types[i] = ScriptRuntime.FloatClass;
|
||||
} else if (type == Double.TYPE) {
|
||||
hasConversions = true;
|
||||
types[i] = ScriptRuntime.DoubleClass;
|
||||
}
|
||||
// Note that long is not supported; see comments above
|
||||
else {
|
||||
Object[] errArgs = { methodName };
|
||||
throw Context.reportRuntimeError(
|
||||
Context.getMessage("msg.bad.parms", errArgs));
|
||||
}
|
||||
}
|
||||
if (!hasConversions)
|
||||
types = null;
|
||||
length = parmsLength;
|
||||
}
|
||||
|
||||
// Initialize length property
|
||||
lengthPropertyValue = (short) length;
|
||||
|
||||
hasVoidReturn = method != null && method.getReturnType() == Void.TYPE;
|
||||
this.argCount = (short) length;
|
||||
|
||||
setParentScope(scope);
|
||||
setPrototype(getFunctionPrototype(scope));
|
||||
Context cx = Context.getCurrentContext();
|
||||
useDynamicScope = cx != null &&
|
||||
cx.hasCompileFunctionsWithDynamicScope();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override ScriptableObject's has, get, and set in order to define
|
||||
* the "length" property of the function. <p>
|
||||
*
|
||||
* We could also have defined the property using ScriptableObject's
|
||||
* defineProperty method, but that would have consumed a slot in every
|
||||
* FunctionObject. Most FunctionObjects typically don't have any
|
||||
* properties anyway, so having the "length" property would cause us
|
||||
* to allocate an array of slots. <p>
|
||||
*
|
||||
* In particular, this method will return true for
|
||||
* <code>name.equals("length")</code>
|
||||
* and will delegate to the superclass for all other
|
||||
* values of <code>name</code>.
|
||||
*/
|
||||
public boolean has(String name, Scriptable start) {
|
||||
return name.equals("length") || super.has(name, start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override ScriptableObject's has, get, and set in order to define
|
||||
* the "length" property of the function. <p>
|
||||
*
|
||||
* In particular, this method will return the value defined by
|
||||
* the method used to construct the object (number of parameters
|
||||
* of the method, or 1 if the method is a "varargs" form), unless
|
||||
* setLength has been called with a new value.
|
||||
*
|
||||
* @see org.mozilla.javascript.FunctionObject#setLength
|
||||
*/
|
||||
public Object get(String name, Scriptable start) {
|
||||
if (name.equals("length"))
|
||||
return new Integer(lengthPropertyValue);
|
||||
return super.get(name, start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override ScriptableObject's has, get, and set in order to define
|
||||
* the "length" property of the function. <p>
|
||||
*
|
||||
* In particular, this method will ignore all attempts to set the
|
||||
* "length" property and forward all other requests to ScriptableObject.
|
||||
*
|
||||
* @see org.mozilla.javascript.FunctionObject#setLength
|
||||
*/
|
||||
public void put(String name, Scriptable start, Object value) {
|
||||
if (!name.equals("length"))
|
||||
super.put(name, start, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of the "length" property.
|
||||
*
|
||||
* <p>Changing the value of the "length" property of a FunctionObject only
|
||||
* affects the value retrieved from get() and does not affect the way
|
||||
* the method itself is called. <p>
|
||||
*
|
||||
* The "length" property will be defined by default as the number
|
||||
* of parameters of the method used to construct the FunctionObject,
|
||||
* unless the method is a "varargs" form, in which case the "length"
|
||||
* property will be defined to 1.
|
||||
*
|
||||
* @param length the new length
|
||||
*/
|
||||
public void setLength(short length) {
|
||||
lengthPropertyValue = length;
|
||||
}
|
||||
|
||||
// TODO: Make not public
|
||||
/**
|
||||
* Finds methods of a given name in a given class.
|
||||
*
|
||||
* <p>Searches <code>clazz</code> for methods with name
|
||||
* <code>name</code>. Maintains a cache so that multiple
|
||||
* lookups on the same class are cheap.
|
||||
*
|
||||
* @param clazz the class to search
|
||||
* @param name the name of the methods to find
|
||||
* @return an array of the found methods, or null if no methods
|
||||
* by that name were found.
|
||||
* @see java.lang.Class#getMethods
|
||||
*/
|
||||
public static Method[] findMethods(Class clazz, String name) {
|
||||
return findMethods(getMethodList(clazz), name);
|
||||
}
|
||||
|
||||
static Method[] findMethods(Method[] methods, String name) {
|
||||
// Usually we're just looking for a single method, so optimize
|
||||
// for that case.
|
||||
Vector v = null;
|
||||
Method first = null;
|
||||
for (int i=0; i < methods.length; i++) {
|
||||
if (methods[i] == null)
|
||||
continue;
|
||||
if (methods[i].getName().equals(name)) {
|
||||
if (first == null) {
|
||||
first = methods[i];
|
||||
} else {
|
||||
if (v == null) {
|
||||
v = new Vector(5);
|
||||
v.addElement(first);
|
||||
}
|
||||
v.addElement(methods[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (v == null) {
|
||||
if (first == null)
|
||||
return null;
|
||||
Method[] single = { first };
|
||||
return single;
|
||||
}
|
||||
Method[] result = new Method[v.size()];
|
||||
v.copyInto(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static Method[] getMethodList(Class clazz) {
|
||||
Method[] cached = methodsCache; // get once to avoid synchronization
|
||||
if (cached != null && cached[0].getDeclaringClass() == clazz)
|
||||
return cached;
|
||||
Method[] methods = null;
|
||||
try {
|
||||
// getDeclaredMethods may be rejected by the security manager
|
||||
// but getMethods is more expensive
|
||||
if (!sawSecurityException)
|
||||
methods = clazz.getDeclaredMethods();
|
||||
} catch (SecurityException e) {
|
||||
// If we get an exception once, give up on getDeclaredMethods
|
||||
sawSecurityException = true;
|
||||
}
|
||||
if (methods == null) {
|
||||
methods = clazz.getMethods();
|
||||
}
|
||||
int count = 0;
|
||||
for (int i=0; i < methods.length; i++) {
|
||||
if (sawSecurityException
|
||||
? methods[i].getDeclaringClass() != clazz
|
||||
: !Modifier.isPublic(methods[i].getModifiers()))
|
||||
{
|
||||
methods[i] = null;
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
Method[] result = new Method[count];
|
||||
int j=0;
|
||||
for (int i=0; i < methods.length; i++) {
|
||||
if (methods[i] != null)
|
||||
result[j++] = methods[i];
|
||||
}
|
||||
if (result.length > 0 && Context.isCachingEnabled)
|
||||
methodsCache = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define this function as a JavaScript constructor.
|
||||
* <p>
|
||||
* Sets up the "prototype" and "constructor" properties. Also
|
||||
* calls setParent and setPrototype with appropriate values.
|
||||
* Then adds the function object as a property of the given scope, using
|
||||
* <code>prototype.getClassName()</code>
|
||||
* as the name of the property.
|
||||
*
|
||||
* @param scope the scope in which to define the constructor (typically
|
||||
* the global object)
|
||||
* @param prototype the prototype object
|
||||
* @see org.mozilla.javascript.Scriptable#setParentScope
|
||||
* @see org.mozilla.javascript.Scriptable#setPrototype
|
||||
* @see org.mozilla.javascript.Scriptable#getClassName
|
||||
*/
|
||||
public void addAsConstructor(Scriptable scope, Scriptable prototype) {
|
||||
setParentScope(scope);
|
||||
setPrototype(getFunctionPrototype(scope));
|
||||
prototype.setParentScope(this);
|
||||
final int attr = ScriptableObject.DONTENUM |
|
||||
ScriptableObject.PERMANENT |
|
||||
ScriptableObject.READONLY;
|
||||
defineProperty("prototype", prototype, attr);
|
||||
String name = prototype.getClassName();
|
||||
if (!name.equals("With")) {
|
||||
// A "With" object would delegate these calls to the prototype:
|
||||
// not the right thing to do here!
|
||||
if (prototype instanceof ScriptableObject) {
|
||||
((ScriptableObject) prototype).defineProperty("constructor",
|
||||
this, attr);
|
||||
} else {
|
||||
prototype.put("constructor", prototype, this);
|
||||
}
|
||||
}
|
||||
if (scope instanceof ScriptableObject) {
|
||||
((ScriptableObject) scope).defineProperty(name, this,
|
||||
ScriptableObject.DONTENUM);
|
||||
} else {
|
||||
scope.put(name, scope, this);
|
||||
}
|
||||
setParentScope(scope);
|
||||
}
|
||||
|
||||
static public Object convertArg(Scriptable scope,
|
||||
Object arg, Class desired)
|
||||
{
|
||||
if (desired == ScriptRuntime.BooleanClass
|
||||
|| desired == Boolean.TYPE)
|
||||
return ScriptRuntime.toBoolean(arg) ? Boolean.TRUE
|
||||
: Boolean.FALSE;
|
||||
else if (desired == ScriptRuntime.StringClass)
|
||||
return ScriptRuntime.toString(arg);
|
||||
else if (desired == ScriptRuntime.IntegerClass
|
||||
|| desired == Integer.TYPE)
|
||||
return new Integer(ScriptRuntime.toInt32(arg));
|
||||
else if (desired == ScriptRuntime.DoubleClass
|
||||
|| desired == Double.TYPE)
|
||||
return new Double(ScriptRuntime.toNumber(arg));
|
||||
else if (desired == ScriptRuntime.ScriptableClass)
|
||||
return ScriptRuntime.toObject(scope, arg);
|
||||
else if (desired == ScriptRuntime.ObjectClass)
|
||||
return arg;
|
||||
// Note that the long type is not supported; see the javadoc for
|
||||
// the constructor for this class
|
||||
else {
|
||||
Object[] errArgs = { desired.getName() };
|
||||
throw Context.reportRuntimeError(
|
||||
Context.getMessage("msg.cant.convert", errArgs));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs conversions on argument types if needed and
|
||||
* invokes the underlying Java method or constructor.
|
||||
* <p>
|
||||
* Implements Function.call.
|
||||
*
|
||||
* @see org.mozilla.javascript.Function#call
|
||||
* @exception JavaScriptException if the underlying Java method or
|
||||
* constructor threw an exception
|
||||
*/
|
||||
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
|
||||
Object[] args)
|
||||
throws JavaScriptException
|
||||
{
|
||||
if (parmsLength < 0)
|
||||
return callVarargs(cx, thisObj, args, false);
|
||||
|
||||
if (!isStatic) {
|
||||
// OPT: cache "clazz"?
|
||||
Class clazz = method != null ? method.getDeclaringClass()
|
||||
: ctor.getDeclaringClass();
|
||||
while (!clazz.isInstance(thisObj)) {
|
||||
thisObj = thisObj.getPrototype();
|
||||
if (thisObj == null || !useDynamicScope) {
|
||||
// Couldn't find an object to call this on.
|
||||
Object[] errArgs = { names[0] };
|
||||
String msg = Context.getMessage("msg.incompat.call", errArgs);
|
||||
throw NativeGlobal.constructError(cx, "TypeError", msg, scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
Object[] invokeArgs;
|
||||
int i;
|
||||
if (parmsLength == args.length) {
|
||||
invokeArgs = args;
|
||||
// avoid copy loop if no conversions needed
|
||||
i = (types == null) ? parmsLength : 0;
|
||||
} else {
|
||||
invokeArgs = new Object[parmsLength];
|
||||
i = 0;
|
||||
}
|
||||
for (; i < parmsLength; i++) {
|
||||
Object arg = (i < args.length)
|
||||
? args[i]
|
||||
: Undefined.instance;
|
||||
if (types != null) {
|
||||
arg = convertArg(this, arg, types[i]);
|
||||
}
|
||||
invokeArgs[i] = arg;
|
||||
}
|
||||
try {
|
||||
Object result = (method != null)
|
||||
? method.invoke(thisObj, invokeArgs)
|
||||
: ctor.newInstance(invokeArgs);
|
||||
return hasVoidReturn ? Undefined.instance : result;
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw JavaScriptException.wrapException(scope, e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw WrappedException.wrapException(e);
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw WrappedException.wrapException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs conversions on argument types if needed and
|
||||
* invokes the underlying Java method or constructor
|
||||
* to create a new Scriptable object.
|
||||
* <p>
|
||||
* Implements Function.construct.
|
||||
*
|
||||
* @param cx the current Context for this thread
|
||||
* @param scope the scope to execute the function relative to. This
|
||||
* set to the value returned by getParentScope() except
|
||||
* when the function is called from a closure.
|
||||
* @param args arguments to the constructor
|
||||
* @see org.mozilla.javascript.Function#construct
|
||||
* @exception JavaScriptException if the underlying Java method or constructor
|
||||
* threw an exception
|
||||
*/
|
||||
public Scriptable construct(Context cx, Scriptable scope, Object[] args)
|
||||
throws JavaScriptException
|
||||
{
|
||||
if (method == null || parmsLength == VARARGS_CTOR) {
|
||||
Scriptable result;
|
||||
if (method != null) {
|
||||
// Ugly: allow variable-arg constructors that need access to the
|
||||
// scope to get it from the Context. Cleanest solution would be
|
||||
// to modify the varargs form, but that would require users with
|
||||
// the old form to change their code.
|
||||
cx.ctorScope = scope;
|
||||
result = (Scriptable) callVarargs(cx, null, args, true);
|
||||
cx.ctorScope = null;
|
||||
} else {
|
||||
result = (Scriptable) call(cx, scope, null, args);
|
||||
}
|
||||
|
||||
if (result.getPrototype() == null)
|
||||
result.setPrototype(getClassPrototype());
|
||||
if (result.getParentScope() == null) {
|
||||
Scriptable parent = getParentScope();
|
||||
if (result != parent)
|
||||
result.setParentScope(parent);
|
||||
}
|
||||
|
||||
return result;
|
||||
} else if (method != null && !isStatic) {
|
||||
Scriptable result;
|
||||
try {
|
||||
result = (Scriptable) method.getDeclaringClass().newInstance();
|
||||
} catch (IllegalAccessException e) {
|
||||
throw WrappedException.wrapException(e);
|
||||
} catch (InstantiationException e) {
|
||||
throw WrappedException.wrapException(e);
|
||||
}
|
||||
|
||||
result.setPrototype(getClassPrototype());
|
||||
result.setParentScope(getParentScope());
|
||||
|
||||
Object val = call(cx, scope, result, args);
|
||||
if (val != null && val != Undefined.instance &&
|
||||
val instanceof Scriptable)
|
||||
{
|
||||
return (Scriptable) val;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return super.construct(cx, scope, args);
|
||||
}
|
||||
|
||||
private Object callVarargs(Context cx, Scriptable thisObj, Object[] args,
|
||||
boolean inNewExpr)
|
||||
throws JavaScriptException
|
||||
{
|
||||
try {
|
||||
if (parmsLength == VARARGS_METHOD) {
|
||||
Object[] invokeArgs = { cx, thisObj, args, this };
|
||||
Object result = method.invoke(null, invokeArgs);
|
||||
return hasVoidReturn ? Undefined.instance : result;
|
||||
} else {
|
||||
Boolean b = inNewExpr ? Boolean.TRUE : Boolean.FALSE;
|
||||
Object[] invokeArgs = { cx, args, this, b };
|
||||
return (method == null)
|
||||
? ctor.newInstance(invokeArgs)
|
||||
: method.invoke(null, invokeArgs);
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
Throwable target = e.getTargetException();
|
||||
if (target instanceof EvaluatorException)
|
||||
throw (EvaluatorException) target;
|
||||
if (target instanceof EcmaError)
|
||||
throw (EcmaError) target;
|
||||
Scriptable scope = thisObj == null ? this : thisObj;
|
||||
throw JavaScriptException.wrapException(scope, target);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw WrappedException.wrapException(e);
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw WrappedException.wrapException(e);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isVarArgsMethod() {
|
||||
return parmsLength == VARARGS_METHOD;
|
||||
}
|
||||
|
||||
boolean isVarArgsConstructor() {
|
||||
return parmsLength == VARARGS_CTOR;
|
||||
}
|
||||
|
||||
private static final short VARARGS_METHOD = -1;
|
||||
private static final short VARARGS_CTOR = -2;
|
||||
|
||||
private static boolean sawSecurityException;
|
||||
|
||||
static Method[] methodsCache;
|
||||
|
||||
Method method;
|
||||
Constructor ctor;
|
||||
private Class[] types;
|
||||
private short parmsLength;
|
||||
private short lengthPropertyValue;
|
||||
private boolean hasVoidReturn;
|
||||
private boolean isStatic;
|
||||
private boolean useDynamicScope;
|
||||
}
|
||||
1056
mozilla/js/rhino/org/mozilla/javascript/IRFactory.java
Normal file
1056
mozilla/js/rhino/org/mozilla/javascript/IRFactory.java
Normal file
File diff suppressed because it is too large
Load Diff
144
mozilla/js/rhino/org/mozilla/javascript/ImporterTopLevel.java
Normal file
144
mozilla/js/rhino/org/mozilla/javascript/ImporterTopLevel.java
Normal file
@@ -0,0 +1,144 @@
|
||||
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Rhino code, released
|
||||
* May 6, 1999.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Norris Boyd
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
// API class
|
||||
|
||||
package org.mozilla.javascript;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Class ImporterTopLevel
|
||||
*
|
||||
* This class defines a ScriptableObject that can be instantiated
|
||||
* as a top-level ("global") object to provide functionality similar
|
||||
* to Java's "import" statement.
|
||||
* <p>
|
||||
* This class can be used to create a top-level scope using the following code:
|
||||
* <pre>
|
||||
* Scriptable scope = cx.initStandardObjects(new ImporterTopLevel());
|
||||
* </pre>
|
||||
* Then JavaScript code will have access to the following methods:
|
||||
* <ul>
|
||||
* <li>importClass - will "import" a class by making its unqualified name
|
||||
* available as a property of the top-level scope
|
||||
* <li>importPackage - will "import" all the classes of the package by
|
||||
* searching for unqualified names as classes qualified
|
||||
* by the given package.
|
||||
* </ul>
|
||||
* The following code from the shell illustrates this use:
|
||||
* <pre>
|
||||
* js> importClass(java.io.File)
|
||||
* js> f = new File('help.txt')
|
||||
* help.txt
|
||||
* js> importPackage(java.util)
|
||||
* js> v = new Vector()
|
||||
* []
|
||||
*
|
||||
* @author Norris Boyd
|
||||
*/
|
||||
public class ImporterTopLevel extends ScriptableObject {
|
||||
|
||||
public ImporterTopLevel() {
|
||||
String[] names = { "importClass", "importPackage" };
|
||||
|
||||
try {
|
||||
this.defineFunctionProperties(names, ImporterTopLevel.class,
|
||||
ScriptableObject.DONTENUM);
|
||||
} catch (PropertyException e) {
|
||||
throw new Error(); // should never happen
|
||||
}
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return "global";
|
||||
}
|
||||
|
||||
public Object get(String name, Scriptable start) {
|
||||
Object result = super.get(name, start);
|
||||
if (result == NOT_FOUND && importedPackages != null) {
|
||||
for (int i=0; i < importedPackages.size(); i++) {
|
||||
Object o = importedPackages.elementAt(i);
|
||||
NativeJavaPackage p = (NativeJavaPackage) o;
|
||||
Object v = p.getPkgProperty(name, start, false);
|
||||
if (v != null && !(v instanceof NativeJavaPackage)) {
|
||||
if (result == NOT_FOUND) {
|
||||
result = v;
|
||||
} else {
|
||||
String[] args = { result.toString(), v.toString() };
|
||||
throw Context.reportRuntimeError(
|
||||
Context.getMessage("msg.ambig.import",
|
||||
args));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void importClass(Object cl) {
|
||||
if (!(cl instanceof NativeJavaClass)) {
|
||||
String[] args = { Context.toString(cl) };
|
||||
throw Context.reportRuntimeError(
|
||||
Context.getMessage("msg.not.class", args));
|
||||
}
|
||||
String s = ((NativeJavaClass) cl).getClassObject().getName();
|
||||
String n = s.substring(s.lastIndexOf('.')+1);
|
||||
Object val = this.get(n, this);
|
||||
if (val != NOT_FOUND && val != cl) {
|
||||
String[] args = { n };
|
||||
throw Context.reportRuntimeError(
|
||||
Context.getMessage("msg.prop.defined", args));
|
||||
}
|
||||
this.defineProperty(n, cl, DONTENUM);
|
||||
}
|
||||
|
||||
public void importPackage(Object pkg) {
|
||||
if (importedPackages == null)
|
||||
importedPackages = new Vector();
|
||||
if (!(pkg instanceof NativeJavaPackage)) {
|
||||
String[] args = { Context.toString(pkg) };
|
||||
throw Context.reportRuntimeError(
|
||||
Context.getMessage("msg.not.pkg", args));
|
||||
}
|
||||
for (int i=0; i < importedPackages.size(); i++) {
|
||||
if (pkg == importedPackages.elementAt(i))
|
||||
return; // allready in list
|
||||
}
|
||||
importedPackages.addElement(pkg);
|
||||
}
|
||||
|
||||
private Vector importedPackages;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user