This commit is contained in:
kipp%netscape.com 1998-07-16 01:19:02 +00:00
Родитель a79127243a
Коммит 98fa2a4633
10 изменённых файлов: 9 добавлений и 2384 удалений

Просмотреть файл

@ -17,7 +17,7 @@
DEPTH=../.. DEPTH=../..
DIRS = coreDom coreEvents events DIRS = coreDom coreEvents events html
DEFINES = -D_IMPL_NS_DOM DEFINES = -D_IMPL_NS_DOM

Просмотреть файл

@ -17,43 +17,6 @@
DEPTH=../.. DEPTH=../..
include $(DEPTH)/config/config.mk DIRS = base coreDOM html build
DIRS = coreDOM
LIBRARY_NAME = jsdom
MODULE = raptor
REQUIRES = xpcom raptor dom js netlib
LCFLAGS = -D_IMPL_NS_DOM
CPPSRCS = \
nsJSEnvironment.cpp \
nsJSWindow.cpp \
nsJSNavigator.cpp \
nsGlobalWindow.cpp \
$(NULL)
ifeq ($(OS_ARCH),IRIX)
LD = $(CCC)
LD_ALL = -all
LD_NONE = -none
endif
# These must be maintained in the proper order for Linux.
EXTRA_DSO_LDOPTS = \
$(LD_ALL) \
$(DIST)/lib/libdomcore_s.a \
$(LD_NONE) \
$(DIST)/bin/libraptorbase.so \
$(DIST)/bin/libnetlib.so \
$(DIST)/bin/libxpcom.so \
$(DIST)/bin/libnspr21.so \
$(DIST)/bin/libplds21.so \
$(DIST)/bin/libplc21.so \
-lm
include $(DEPTH)/config/rules.mk include $(DEPTH)/config/rules.mk

Просмотреть файл

@ -17,7 +17,7 @@
DEPTH=../../.. DEPTH=../../..
LIBRARY_NAME = domcore_s LIBRARY_NAME = jsdomcore_s
CPPSRCS = \ CPPSRCS = \
nsJSNode.cpp \ nsJSNode.cpp \
@ -37,8 +37,8 @@ MODULE = raptor
REQUIRES = xpcom raptor dom js netlib REQUIRES = xpcom raptor dom js netlib
include $(DEPTH)/config/config.mk
MKSHLIB := MKSHLIB :=
include $(DEPTH)/config/rules.mk include $(DEPTH)/config/rules.mk
export:: $(LIBRARY)

Просмотреть файл

@ -17,7 +17,7 @@
DEPTH=../../.. DEPTH=../../..
LIBRARY_NAME = domhtml_s LIBRARY_NAME = jsdomhtml_s
CPPSRCS = \ CPPSRCS = \
nsJSHTMLIFrameElement.cpp \ nsJSHTMLIFrameElement.cpp \
@ -81,14 +81,14 @@ CPPSRCS = \
nsJSHTMLUListElement.cpp \ nsJSHTMLUListElement.cpp \
$(NULL) $(NULL)
LIBRARY_NAME = jsdom
DEFINES = -D_IMPL_NS_DOM DEFINES = -D_IMPL_NS_DOM
MODULE = raptor MODULE = raptor
REQUIRES = xpcom raptor dom js netlib REQUIRES = xpcom raptor dom js netlib
include $(DEPTH)/config/config.mk
MKSHLIB := MKSHLIB :=
include $(DEPTH)/config/rules.mk include $(DEPTH)/config/rules.mk

Просмотреть файл

@ -18,47 +18,6 @@
DEPTH=..\.. DEPTH=..\..
IGNORE_MANIFEST=1 IGNORE_MANIFEST=1
DIRS = coreDOM DIRS = base coreDOM html build
MAKE_OBJ_TYPE = DLL
DLLNAME = jsdom
DLL=.\$(OBJDIR)\$(DLLNAME).dll
DEFINES=-D_IMPL_NS_DOM -DWIN32_LEAN_AND_MEAN
CPPSRCS = \
nsJSEnvironment.cpp \
nsJSWindow.cpp \
nsJSNavigator.cpp \
nsGlobalWindow.cpp \
$(NULL)
MODULE=raptor
REQUIRES=xpcom raptor js netlib
CPP_OBJS= .\$(OBJDIR)\nsJSEnvironment.obj .\$(OBJDIR)\nsJSWindow.obj \
.\$(OBJDIR)\nsGlobalWindow.obj .\$(OBJDIR)\nsJSNavigator.obj
LINCS=-I$(XPDIST)\public\xpcom -I$(XPDIST)\public\raptor -I$(XPDIST)\public\dom -I$(XPDIST)\public\js -I$(PUBLIC)\netlib
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
LLIBS= \
$(DIST)\lib\libplc21.lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\js3240.lib \
$(DIST)\lib\domcore_s.lib \
$(LIBNSPR)
include <$(DEPTH)\config\rules.mak> include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

Просмотреть файл

@ -1,988 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nscore.h"
#include "prmem.h"
#include "prtime.h"
#include "plstr.h"
#include "prinrval.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptContext.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
#include "nsIDOMDocument.h"
#include "nsIDOMNavigator.h"
#include "nsINetService.h"
#include "nsINetContainerApplication.h"
#include "nsITimer.h"
#include "jsapi.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIDOMWindowIID, NS_IDOMWINDOW_IID);
static NS_DEFINE_IID(kIDOMNavigatorIID, NS_IDOMNAVIGATOR_IID);
typedef struct nsTimeoutImpl nsTimeoutImpl;
// Global object for scripting
class GlobalWindowImpl : public nsIScriptObjectOwner, public nsIScriptGlobalObject, public nsIDOMWindow
{
public:
GlobalWindowImpl();
~GlobalWindowImpl();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD ResetScriptObject();
NS_IMETHOD_(void) SetContext(nsIScriptContext *aContext);
NS_IMETHOD_(void) SetNewDocument(nsIDOMDocument *aDocument);
NS_IMETHOD GetWindow(nsIDOMWindow** aWindow);
NS_IMETHOD GetSelf(nsIDOMWindow** aSelf);
NS_IMETHOD GetDocument(nsIDOMDocument** aDocument);
NS_IMETHOD GetNavigator(nsIDOMNavigator** aNavigator);
NS_IMETHOD Dump(const nsString& aStr);
NS_IMETHOD Alert(const nsString& aStr);
NS_IMETHOD ClearTimeout(PRInt32 aTimerID);
NS_IMETHOD ClearInterval(PRInt32 aTimerID);
NS_IMETHOD SetTimeout(JSContext *cx, jsval *argv, PRUint32 argc,
PRInt32* aReturn);
NS_IMETHOD SetInterval(JSContext *cx, jsval *argv, PRUint32 argc,
PRInt32* aReturn);
friend void nsGlobalWindow_RunTimeout(nsITimer *aTimer, void *aClosure);
protected:
void RunTimeout(nsTimeoutImpl *aTimeout);
nsresult ClearTimeoutOrInterval(PRInt32 aTimerID);
nsresult SetTimeoutOrInterval(JSContext *cx, jsval *argv,
PRUint32 argc, PRInt32* aReturn,
PRBool aIsInterval);
void InsertTimeoutIntoList(nsTimeoutImpl **aInsertionPoint,
nsTimeoutImpl *aTimeout);
void ClearAllTimeouts();
void DropTimeout(nsTimeoutImpl *aTimeout);
void HoldTimeout(nsTimeoutImpl *aTimeout);
nsIScriptContext *mContext;
void *mScriptObject;
nsIDOMDocument *mDocument;
nsIDOMNavigator *mNavigator;
nsTimeoutImpl *mTimeouts;
nsTimeoutImpl **mTimeoutInsertionPoint;
nsTimeoutImpl *mRunningTimeout;
PRUint32 mTimeoutPublicIdCounter;
};
/*
* Timeout struct that holds information about each JavaScript
* timeout.
*/
struct nsTimeoutImpl {
PRInt32 ref_count; /* reference count to shared usage */
GlobalWindowImpl *window; /* window for which this timeout fires */
char *expr; /* the JS expression to evaluate */
JSObject *funobj; /* or function to call, if !expr */
nsITimer *timer; /* The actual timer object */
jsval *argv; /* function actual arguments */
PRUint16 argc; /* and argument count */
PRUint16 spare; /* alignment padding */
PRUint32 public_id; /* Returned as value of setTimeout() */
PRInt32 interval; /* Non-zero if repetitive timeout */
PRInt64 when; /* nominal time to run this timeout */
JSVersion version; /* Version of JavaScript to execute */
JSPrincipals *principals; /* principals with which to execute */
char *filename; /* filename of setTimeout call */
PRUint32 lineno; /* line number of setTimeout call */
nsTimeoutImpl *next;
};
// Script "navigator" object
class NavigatorImpl : public nsIScriptObjectOwner, public nsIDOMNavigator {
public:
NavigatorImpl();
~NavigatorImpl();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD ResetScriptObject();
NS_IMETHOD GetUserAgent(nsString& aUserAgent);
NS_IMETHOD GetAppCodeName(nsString& aAppCodeName);
NS_IMETHOD GetAppVersion(nsString& aAppVersion);
NS_IMETHOD GetAppName(nsString& aAppName);
NS_IMETHOD GetLanguage(nsString& aLanguage);
NS_IMETHOD GetPlatform(nsString& aPlatform);
NS_IMETHOD GetSecurityPolicy(nsString& aSecurityPolicy);
NS_IMETHOD JavaEnabled(PRBool* aReturn);
protected:
void *mScriptObject;
};
GlobalWindowImpl::GlobalWindowImpl()
{
mContext = nsnull;
mScriptObject = nsnull;
mDocument = nsnull;
mNavigator = nsnull;
mTimeouts = nsnull;
mTimeoutInsertionPoint = nsnull;
mRunningTimeout = nsnull;
mTimeoutPublicIdCounter = 1;
}
GlobalWindowImpl::~GlobalWindowImpl()
{
if (nsnull != mScriptObject) {
JS_RemoveRoot((JSContext *)mContext->GetNativeContext(), &mScriptObject);
mScriptObject = nsnull;
}
if (nsnull != mContext) {
NS_RELEASE(mContext);
}
if (nsnull != mDocument) {
NS_RELEASE(mDocument);
}
NS_IF_RELEASE(mNavigator);
}
NS_IMPL_ADDREF(GlobalWindowImpl)
NS_IMPL_RELEASE(GlobalWindowImpl)
nsresult
GlobalWindowImpl::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIScriptGlobalObjectIID)) {
*aInstancePtrResult = (void*) ((nsIScriptGlobalObject*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMWindowIID)) {
*aInstancePtrResult = (void*) ((nsIDOMWindow*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptGlobalObject*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsresult
GlobalWindowImpl::ResetScriptObject()
{
mScriptObject = nsnull;
return NS_OK;
}
nsresult
GlobalWindowImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
res = NS_NewScriptWindow(aContext, this, nsnull, &mScriptObject);
JS_AddNamedRoot((JSContext *)aContext->GetNativeContext(),
&mScriptObject, "window_object");
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP_(void)
GlobalWindowImpl::SetContext(nsIScriptContext *aContext)
{
if (mContext) {
NS_RELEASE(mContext);
}
mContext = aContext;
NS_ADDREF(mContext);
}
NS_IMETHODIMP_(void)
GlobalWindowImpl::SetNewDocument(nsIDOMDocument *aDocument)
{
if (nsnull != mDocument) {
ClearAllTimeouts();
if (nsnull != mScriptObject) {
JS_ClearScope((JSContext *)mContext->GetNativeContext(),
(JSObject *)mScriptObject);
}
NS_RELEASE(mDocument);
}
mDocument = aDocument;
if (nsnull != mDocument) {
NS_ADDREF(mDocument);
if (nsnull != mContext) {
mContext->InitContext(this);
}
}
JS_GC((JSContext *)mContext->GetNativeContext());
}
NS_IMETHODIMP
GlobalWindowImpl::GetWindow(nsIDOMWindow** aWindow)
{
*aWindow = this;
NS_ADDREF(this);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetSelf(nsIDOMWindow** aWindow)
{
*aWindow = this;
NS_ADDREF(this);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetDocument(nsIDOMDocument** aDocument)
{
*aDocument = mDocument;
NS_ADDREF(mDocument);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetNavigator(nsIDOMNavigator** aNavigator)
{
if (nsnull == mNavigator) {
mNavigator = new NavigatorImpl();
NS_IF_ADDREF(mNavigator);
}
*aNavigator = mNavigator;
NS_IF_ADDREF(mNavigator);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::Dump(const nsString& aStr)
{
char *cstr = aStr.ToNewCString();
if (nsnull != cstr) {
printf("%s", cstr);
delete [] cstr;
}
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::Alert(const nsString& aStr)
{
// XXX Temporary
return Dump(aStr);
}
nsresult
GlobalWindowImpl::ClearTimeoutOrInterval(PRInt32 aTimerID)
{
PRUint32 public_id;
nsTimeoutImpl **top, *timeout;
public_id = (PRUint32)aTimerID;
if (!public_id) /* id of zero is reserved for internal use */
return NS_ERROR_FAILURE;
for (top = &mTimeouts; ((timeout = *top) != NULL); top = &timeout->next) {
if (timeout->public_id == public_id) {
if (mRunningTimeout == timeout) {
/* We're running from inside the timeout. Mark this
timeout for deferred deletion by the code in
win_run_timeout() */
timeout->interval = 0;
}
else {
/* Delete the timeout from the pending timeout list */
*top = timeout->next;
if (timeout->timer) {
timeout->timer->Cancel();
NS_RELEASE(timeout->timer);
DropTimeout(timeout);
}
DropTimeout(timeout);
}
break;
}
}
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::ClearTimeout(PRInt32 aTimerID)
{
return ClearTimeoutOrInterval(aTimerID);
}
NS_IMETHODIMP
GlobalWindowImpl::ClearInterval(PRInt32 aTimerID)
{
return ClearTimeoutOrInterval(aTimerID);
}
void
GlobalWindowImpl::ClearAllTimeouts()
{
nsTimeoutImpl *timeout, *next;
for (timeout = mTimeouts; timeout; timeout = next) {
/* If RunTimeout() is higher up on the stack for this
window, e.g. as a result of document.write from a timeout,
then we need to reset the list insertion point for
newly-created timeouts in case the user adds a timeout,
before we pop the stack back to RunTimeout. */
if (mRunningTimeout == timeout)
mTimeoutInsertionPoint = nsnull;
next = timeout->next;
if (timeout->timer) {
timeout->timer->Cancel();
NS_RELEASE(timeout->timer);
// Drop the count since the timer isn't going to hold on
// anymore.
DropTimeout(timeout);
}
// Drop the count since we're removing it from the list.
DropTimeout(timeout);
}
mTimeouts = NULL;
}
void
GlobalWindowImpl::HoldTimeout(nsTimeoutImpl *aTimeout)
{
aTimeout->ref_count++;
}
void
GlobalWindowImpl::DropTimeout(nsTimeoutImpl *aTimeout)
{
JSContext *cx;
if (--aTimeout->ref_count > 0) {
return;
}
cx = (JSContext *)mContext->GetNativeContext();
if (aTimeout->expr) {
PR_FREEIF(aTimeout->expr);
}
else if (aTimeout->funobj) {
JS_RemoveRoot(cx, &aTimeout->funobj);
if (aTimeout->argv) {
int i;
for (i = 0; i < aTimeout->argc; i++)
JS_RemoveRoot(cx, &aTimeout->argv[i]);
PR_FREEIF(aTimeout->argv);
}
}
NS_IF_RELEASE(aTimeout->timer);
PR_FREEIF(aTimeout->filename);
NS_IF_RELEASE(aTimeout->window);
PR_DELETE(aTimeout);
}
void
GlobalWindowImpl::InsertTimeoutIntoList(nsTimeoutImpl **aList,
nsTimeoutImpl *aTimeout)
{
nsTimeoutImpl *to;
while ((to = *aList) != nsnull) {
if (LL_CMP(to->when, >, aTimeout->when))
break;
aList = &to->next;
}
aTimeout->next = to;
*aList = aTimeout;
// Increment the ref_count since we're in the list
HoldTimeout(aTimeout);
}
void
nsGlobalWindow_RunTimeout(nsITimer *aTimer, void *aClosure)
{
nsTimeoutImpl *timeout = (nsTimeoutImpl *)aClosure;
timeout->window->RunTimeout(timeout);
// Drop the ref_count since the timer won't be holding on to the
// timeout struct anymore
timeout->window->DropTimeout(timeout);
}
void
GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout)
{
nsTimeoutImpl *next, *timeout;
nsTimeoutImpl *last_expired_timeout;
nsTimeoutImpl dummy_timeout;
JSContext *cx;
PRInt64 now;
jsval result;
nsITimer *timer;
timer = aTimeout->timer;
cx = (JSContext *)mContext->GetNativeContext();
/*
* A native timer has gone off. See which of our timeouts need
* servicing
*/
LL_I2L(now, PR_IntervalNow());
/* The timeout list is kept in deadline order. Discover the
latest timeout whose deadline has expired. On some platforms,
native timeout events fire "early", so we need to test the
timer as well as the deadline. */
last_expired_timeout = nsnull;
for (timeout = mTimeouts; timeout; timeout = timeout->next) {
if ((timeout == aTimeout) || !LL_CMP(timeout->when, >, now))
last_expired_timeout = timeout;
}
/* Maybe the timeout that the event was fired for has been deleted
and there are no others timeouts with deadlines that make them
eligible for execution yet. Go away. */
if (!last_expired_timeout)
return;
/* Insert a dummy timeout into the list of timeouts between the portion
of the list that we are about to process now and those timeouts that
will be processed in a future call to win_run_timeout(). This dummy
timeout serves as the head of the list for any timeouts inserted as
a result of running a timeout. */
dummy_timeout.timer = NULL;
dummy_timeout.public_id = 0;
dummy_timeout.next = last_expired_timeout->next;
last_expired_timeout->next = &dummy_timeout;
/* Don't let ClearWindowTimeouts throw away our stack-allocated
dummy timeout. */
dummy_timeout.ref_count = 2;
mTimeoutInsertionPoint = &dummy_timeout.next;
for (timeout = mTimeouts; timeout != &dummy_timeout; timeout = next) {
next = timeout->next;
/* Hold the timeout in case expr or funobj releases its doc. */
mRunningTimeout = timeout;
if (timeout->expr) {
/* Evaluate the timeout expression. */
JS_EvaluateScript(cx, (JSObject *)mScriptObject,
timeout->expr,
PL_strlen(timeout->expr),
timeout->filename, timeout->lineno,
&result);
}
else {
PRInt64 lateness64;
PRInt32 lateness;
/* Add "secret" final argument that indicates timeout
lateness in milliseconds */
LL_SUB(lateness64, now, timeout->when);
LL_L2I(lateness, lateness64);
lateness = PR_IntervalToMilliseconds(lateness);
timeout->argv[timeout->argc] = INT_TO_JSVAL((jsint)lateness);
JS_CallFunctionValue(cx, (JSObject *)mScriptObject,
OBJECT_TO_JSVAL(timeout->funobj),
timeout->argc + 1, timeout->argv, &result);
}
mRunningTimeout = nsnull;
/* If we have a regular interval timer, we re-fire the
* timeout, accounting for clock drift.
*/
if (timeout->interval) {
/* Compute time to next timeout for interval timer. */
PRInt32 delay32;
PRInt64 interval, delay;
LL_I2L(interval, PR_MillisecondsToInterval(timeout->interval));
LL_ADD(timeout->when, timeout->when, interval);
LL_I2L(now, PR_IntervalNow());
LL_SUB(delay, timeout->when, now);
LL_L2I(delay32, delay);
/* If the next interval timeout is already supposed to
* have happened then run the timeout immediately.
*/
if (delay32 < 0) {
delay32 = 0;
}
delay32 = PR_IntervalToMilliseconds(delay32);
NS_IF_RELEASE(timeout->timer);
/* Reschedule timeout. Account for possible error return in
code below that checks for zero toid. */
nsresult err = NS_NewTimer(&timeout->timer);
if (NS_OK != err) {
return;
}
err = timeout->timer->Init(nsGlobalWindow_RunTimeout, timeout,
delay32);
if (NS_OK != err) {
return;
}
// Increment ref_count to indicate that this timer is holding
// on to the timeout struct.
HoldTimeout(timeout);
}
/* Running a timeout can cause another timeout to be deleted,
so we need to reset the pointer to the following timeout. */
next = timeout->next;
mTimeouts = next;
// Drop timeout struct since it's out of the list
DropTimeout(timeout);
/* Free the timeout if this is not a repeating interval
* timeout (or if it was an interval timeout, but we were
* unsuccessful at rescheduling it.)
*/
if (timeout->interval && timeout->timer) {
/* Reschedule an interval timeout */
/* Insert interval timeout onto list sorted in deadline order. */
InsertTimeoutIntoList(mTimeoutInsertionPoint, timeout);
}
}
/* Take the dummy timeout off the head of the list */
mTimeouts = dummy_timeout.next;
mTimeoutInsertionPoint = nsnull;
}
static const char *kSetIntervalStr = "setInterval";
static const char *kSetTimeoutStr = "setTimeout";
nsresult
GlobalWindowImpl::SetTimeoutOrInterval(JSContext *cx,
jsval *argv,
PRUint32 argc,
PRInt32* aReturn,
PRBool aIsInterval)
{
char *expr = nsnull;
JSObject *funobj = nsnull;
JSString *str;
nsTimeoutImpl *timeout, **insertion_point;
jsdouble interval;
PRInt64 now, delta;
if (argc >= 2) {
if (!JS_ValueToNumber(cx, argv[1], &interval)) {
JS_ReportError(cx, "Second argument to %s must be a millisecond interval",
aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
return NS_ERROR_ILLEGAL_VALUE;
}
switch (JS_TypeOfValue(cx, argv[0])) {
case JSTYPE_FUNCTION:
funobj = JSVAL_TO_OBJECT(argv[0]);
break;
case JSTYPE_STRING:
case JSTYPE_OBJECT:
if (!(str = JS_ValueToString(cx, argv[0])))
return NS_ERROR_FAILURE;
expr = PL_strdup(JS_GetStringBytes(str));
if (nsnull == expr)
return NS_ERROR_OUT_OF_MEMORY;
break;
default:
JS_ReportError(cx, "useless %s call (missing quotes around argument?)", aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
return NS_ERROR_FAILURE;
}
timeout = PR_NEWZAP(nsTimeoutImpl);
if (nsnull == timeout) {
PR_FREEIF(expr);
return NS_ERROR_OUT_OF_MEMORY;
}
// Initial ref_count to indicate that this timeout struct will
// be held as the closure of a timer.
timeout->ref_count = 1;
if (aIsInterval)
timeout->interval = (PRInt32)interval;
timeout->expr = expr;
timeout->funobj = funobj;
if (expr) {
timeout->argv = 0;
timeout->argc = 0;
}
else {
int i;
/* Leave an extra slot for a secret final argument that
indicates to the called function how "late" the timeout is. */
timeout->argv = (jsval *)PR_MALLOC((argc - 1) * sizeof(jsval));
if (nsnull == timeout->argv) {
DropTimeout(timeout);
return NS_ERROR_OUT_OF_MEMORY;
}
if (!JS_AddNamedRoot(cx, &timeout->funobj, "timeout.funobj")) {
DropTimeout(timeout);
return NS_ERROR_FAILURE;
}
timeout->argc = 0;
for (i = 2; (PRUint32)i < argc; i++) {
timeout->argv[i - 2] = argv[i];
if (!JS_AddNamedRoot(cx, &timeout->argv[i - 2], "timeout.argv[i]")) {
DropTimeout(timeout);
return NS_ERROR_FAILURE;
}
timeout->argc++;
}
}
LL_I2L(now, PR_IntervalNow());
LL_D2L(delta, PR_MillisecondsToInterval((PRUint32)interval));
LL_ADD(timeout->when, now, delta);
nsresult err = NS_NewTimer(&timeout->timer);
if (NS_OK != err) {
DropTimeout(timeout);
return err;
}
err = timeout->timer->Init(nsGlobalWindow_RunTimeout, timeout,
(PRInt32)interval);
if (NS_OK != err) {
DropTimeout(timeout);
return err;
}
timeout->window = this;
NS_ADDREF(this);
if (mTimeoutInsertionPoint == NULL)
insertion_point = &mTimeouts;
else
insertion_point = mTimeoutInsertionPoint;
InsertTimeoutIntoList(insertion_point, timeout);
timeout->public_id = ++mTimeoutPublicIdCounter;
*aReturn = timeout->public_id;
}
else {
JS_ReportError(cx, "Function %s requires at least 2 parameters", aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::SetTimeout(JSContext *cx,
jsval *argv,
PRUint32 argc,
PRInt32* aReturn)
{
return SetTimeoutOrInterval(cx, argv, argc, aReturn, PR_FALSE);
}
NS_IMETHODIMP
GlobalWindowImpl::SetInterval(JSContext *cx,
jsval *argv,
PRUint32 argc,
PRInt32* aReturn)
{
return SetTimeoutOrInterval(cx, argv, argc, aReturn, PR_TRUE);
}
extern "C" NS_DOM nsresult
NS_NewScriptGlobalObject(nsIScriptGlobalObject **aResult)
{
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
GlobalWindowImpl *global = new GlobalWindowImpl();
if (nsnull == global) {
return NS_ERROR_OUT_OF_MEMORY;
}
return global->QueryInterface(kIScriptGlobalObjectIID, (void **)aResult);
}
//
// Navigator class implementation
//
NavigatorImpl::NavigatorImpl()
{
mScriptObject = nsnull;
}
NavigatorImpl::~NavigatorImpl()
{
}
NS_IMPL_ADDREF(NavigatorImpl)
NS_IMPL_RELEASE(NavigatorImpl)
nsresult
NavigatorImpl::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMNavigatorIID)) {
*aInstancePtrResult = (void*) ((nsIDOMNavigator*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsresult
NavigatorImpl::ResetScriptObject()
{
mScriptObject = nsnull;
return NS_OK;
}
nsresult
NavigatorImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
res = NS_NewScriptNavigator(aContext, this, global, &mScriptObject);
NS_IF_RELEASE(global);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetUserAgent(nsString& aUserAgent)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
nsAutoString appVersion;
container->GetAppCodeName(aUserAgent);
container->GetAppVersion(appVersion);
aUserAgent.Append('/');
aUserAgent.Append(appVersion);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetAppCodeName(nsString& aAppCodeName)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
res = container->GetAppCodeName(aAppCodeName);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetAppVersion(nsString& aAppVersion)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
res = container->GetAppVersion(aAppVersion);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetAppName(nsString& aAppName)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
res = container->GetAppName(aAppName);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetLanguage(nsString& aLanguage)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
res = container->GetLanguage(aLanguage);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetPlatform(nsString& aPlatform)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
res = container->GetPlatform(aPlatform);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetSecurityPolicy(nsString& aSecurityPolicy)
{
return NS_OK;
}
NS_IMETHODIMP
NavigatorImpl::JavaEnabled(PRBool* aReturn)
{
*aReturn = PR_FALSE;
return NS_OK;
}

Просмотреть файл

@ -1,165 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsJSEnvironment.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIDOMText.h"
#include "nsIDOMAttribute.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMNodeList.h"
const uint32 gGCSize = 4L * 1024L * 1024L;
const size_t gStackSize = 8192;
static NS_DEFINE_IID(kIScriptContextIID, NS_ISCRIPTCONTEXT_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
nsJSContext::nsJSContext(JSRuntime *aRuntime)
{
mRefCnt = 0;
mContext = JS_NewContext(aRuntime, gStackSize);
JS_SetContextPrivate(mContext, (void *)this);
}
nsJSContext::~nsJSContext()
{
JS_DestroyContext(mContext);
}
NS_IMPL_ISUPPORTS(nsJSContext, kIScriptContextIID);
PRBool nsJSContext::EvaluateString(const char *aScript,
PRUint32 aScriptSize,
jsval *aRetValue)
{
return ::JS_EvaluateScript(mContext,
JS_GetGlobalObject(mContext),
aScript,
aScriptSize,
NULL,
0,
aRetValue);
}
nsIScriptGlobalObject* nsJSContext::GetGlobalObject()
{
JSObject *global = JS_GetGlobalObject(mContext);
nsIScriptGlobalObject *script_global;
if (nsnull != global) {
script_global = (nsIScriptGlobalObject *)JS_GetPrivate(mContext, global);
NS_ADDREF(script_global);
return script_global;
}
else {
return nsnull;
}
}
void* nsJSContext::GetNativeContext()
{
return (void *)mContext;
}
nsresult nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
{
nsresult result = NS_ERROR_FAILURE;
nsIScriptObjectOwner *owner;
JSObject *global;
nsresult res = aGlobalObject->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
if (NS_OK == res) {
res = owner->GetScriptObject(this, (void **)&global);
// init standard classes
if ((NS_OK == res) && ::JS_InitStandardClasses(mContext, global)) {
JS_SetGlobalObject(mContext, global);
res = InitClasses(); // this will complete the global object initialization
}
NS_RELEASE(owner);
}
return res;
}
nsresult nsJSContext::InitClasses()
{
nsresult res = NS_ERROR_FAILURE;
nsIScriptGlobalObject *global = GetGlobalObject();
if (NS_OK == NS_InitWindowClass(this, global) &&
NS_OK == NS_InitNodeClass(this, nsnull) &&
NS_OK == NS_InitElementClass(this, nsnull) &&
NS_OK == NS_InitDocumentClass(this, nsnull) &&
NS_OK == NS_InitTextClass(this, nsnull) &&
NS_OK == NS_InitAttributeClass(this, nsnull) &&
NS_OK == NS_InitNamedNodeMapClass(this, nsnull) &&
NS_OK == NS_InitNodeListClass(this, nsnull)) {
res = NS_OK;
}
NS_RELEASE(global);
return res;
}
nsJSEnvironment *nsJSEnvironment::sTheEnvironment = nsnull;
nsJSEnvironment *
nsJSEnvironment::GetScriptingEnvironment()
{
if (nsnull == sTheEnvironment) {
sTheEnvironment = new nsJSEnvironment();
}
return sTheEnvironment;
}
nsJSEnvironment::nsJSEnvironment()
{
mRuntime = JS_Init(gGCSize);
}
nsJSEnvironment::~nsJSEnvironment()
{
JS_Finish(mRuntime);
}
nsIScriptContext* nsJSEnvironment::GetNewContext()
{
nsIScriptContext *context;
context = new nsJSContext(mRuntime);
NS_ADDREF(context);
return context;
}
extern "C" NS_DOM nsresult NS_CreateContext(nsIScriptGlobalObject *aGlobal, nsIScriptContext **aContext)
{
nsJSEnvironment *environment = nsJSEnvironment::GetScriptingEnvironment();
*aContext = environment->GetNewContext();
(*aContext)->InitContext(aGlobal);
aGlobal->SetContext(*aContext);
return NS_OK;
}

Просмотреть файл

@ -1,56 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsJSEnvironment_h___
#define nsJSEnvironment_h___
#include "nsIScriptContext.h"
class nsJSContext : public nsIScriptContext {
private:
JSContext *mContext;
public:
nsJSContext(JSRuntime *aRuntime);
~nsJSContext();
NS_DECL_ISUPPORTS
virtual PRBool EvaluateString(const char *aScript,
PRUint32 aScriptSize,
jsval *aRetValue);
virtual nsIScriptGlobalObject* GetGlobalObject();
virtual void* GetNativeContext();
virtual nsresult InitClasses();
virtual nsresult InitContext(nsIScriptGlobalObject *aGlobalObject);
};
class nsJSEnvironment {
private:
static nsJSEnvironment *sTheEnvironment;
JSRuntime *mRuntime;
public:
nsJSEnvironment();
~nsJSEnvironment();
nsIScriptContext* GetNewContext();
static nsJSEnvironment *GetScriptingEnvironment();
};
#endif /* nsJSEnvironment_h___ */

Просмотреть файл

@ -1,463 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMNavigator.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kINavigatorIID, NS_IDOMNAVIGATOR_IID);
NS_DEF_PTR(nsIDOMNavigator);
//
// Navigator property ids
//
enum Navigator_slots {
NAVIGATOR_USERAGENT = -11,
NAVIGATOR_APPCODENAME = -12,
NAVIGATOR_APPVERSION = -13,
NAVIGATOR_APPNAME = -14,
NAVIGATOR_LANGUAGE = -15,
NAVIGATOR_PLATFORM = -16,
NAVIGATOR_SECURITYPOLICY = -17
};
/***********************************************************************/
//
// Navigator Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetNavigatorProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMNavigator *a = (nsIDOMNavigator*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case NAVIGATOR_USERAGENT:
{
nsAutoString prop;
if (NS_OK == a->GetUserAgent(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case NAVIGATOR_APPCODENAME:
{
nsAutoString prop;
if (NS_OK == a->GetAppCodeName(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case NAVIGATOR_APPVERSION:
{
nsAutoString prop;
if (NS_OK == a->GetAppVersion(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case NAVIGATOR_APPNAME:
{
nsAutoString prop;
if (NS_OK == a->GetAppName(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case NAVIGATOR_LANGUAGE:
{
nsAutoString prop;
if (NS_OK == a->GetLanguage(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case NAVIGATOR_PLATFORM:
{
nsAutoString prop;
if (NS_OK == a->GetPlatform(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case NAVIGATOR_SECURITYPOLICY:
{
nsAutoString prop;
if (NS_OK == a->GetSecurityPolicy(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->GetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
else {
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->GetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
return PR_TRUE;
}
/***********************************************************************/
//
// Navigator Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetNavigatorProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMNavigator *a = (nsIDOMNavigator*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->SetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
else {
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->SetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
return PR_TRUE;
}
//
// Navigator finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeNavigator(JSContext *cx, JSObject *obj)
{
nsIDOMNavigator *a = (nsIDOMNavigator*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
owner->ResetScriptObject();
NS_RELEASE(owner);
}
NS_RELEASE(a);
}
}
//
// Navigator enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateNavigator(JSContext *cx, JSObject *obj)
{
nsIDOMNavigator *a = (nsIDOMNavigator*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->EnumerateProperty(cx);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// Navigator resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveNavigator(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMNavigator *a = (nsIDOMNavigator*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->Resolve(cx, id);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// Native method JavaEnabled
//
PR_STATIC_CALLBACK(JSBool)
NavigatorJavaEnabled(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNavigator *nativeThis = (nsIDOMNavigator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRBool nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->JavaEnabled(&nativeRet)) {
return JS_FALSE;
}
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function javaEnabled requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for Navigator
//
JSClass NavigatorClass = {
"Navigator",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetNavigatorProperty,
SetNavigatorProperty,
EnumerateNavigator,
ResolveNavigator,
JS_ConvertStub,
FinalizeNavigator
};
//
// Navigator class properties
//
static JSPropertySpec NavigatorProperties[] =
{
{"userAgent", NAVIGATOR_USERAGENT, JSPROP_ENUMERATE | JSPROP_READONLY},
{"appCodeName", NAVIGATOR_APPCODENAME, JSPROP_ENUMERATE | JSPROP_READONLY},
{"appVersion", NAVIGATOR_APPVERSION, JSPROP_ENUMERATE | JSPROP_READONLY},
{"appName", NAVIGATOR_APPNAME, JSPROP_ENUMERATE | JSPROP_READONLY},
{"language", NAVIGATOR_LANGUAGE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"platform", NAVIGATOR_PLATFORM, JSPROP_ENUMERATE | JSPROP_READONLY},
{"securityPolicy", NAVIGATOR_SECURITYPOLICY, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
//
// Navigator class methods
//
static JSFunctionSpec NavigatorMethods[] =
{
{"javaEnabled", NavigatorJavaEnabled, 0},
{0}
};
//
// Navigator constructor
//
PR_STATIC_CALLBACK(JSBool)
Navigator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// Navigator class initialization
//
nsresult NS_InitNavigatorClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "Navigator", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&NavigatorClass, // JSClass
Navigator, // JSNative ctor
0, // ctor args
NavigatorProperties, // proto props
NavigatorMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new Navigator JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptNavigator(nsIScriptContext *aContext, nsIDOMNavigator *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptNavigator");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitNavigatorClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &NavigatorClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports);
NS_ADDREF(aSupports);
}
else {
return NS_ERROR_FAILURE;
}
return NS_OK;
}

Просмотреть файл

@ -1,625 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMNavigator.h"
#include "nsIDOMDocument.h"
#include "nsIDOMWindow.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kINavigatorIID, NS_IDOMNAVIGATOR_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID);
NS_DEF_PTR(nsIDOMNavigator);
NS_DEF_PTR(nsIDOMDocument);
NS_DEF_PTR(nsIDOMWindow);
//
// Window property ids
//
enum Window_slots {
WINDOW_WINDOW = -11,
WINDOW_SELF = -12,
WINDOW_DOCUMENT = -13,
WINDOW_NAVIGATOR = -14
};
/***********************************************************************/
//
// Window Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMWindow *a = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case WINDOW_WINDOW:
{
nsIDOMWindow* prop;
if (NS_OK == a->GetWindow(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case WINDOW_SELF:
{
nsIDOMWindow* prop;
if (NS_OK == a->GetSelf(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case WINDOW_DOCUMENT:
{
nsIDOMDocument* prop;
if (NS_OK == a->GetDocument(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case WINDOW_NAVIGATOR:
{
nsIDOMNavigator* prop;
if (NS_OK == a->GetNavigator(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->GetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
else {
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->GetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
return PR_TRUE;
}
/***********************************************************************/
//
// Window Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMWindow *a = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->SetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
else {
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->SetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
return PR_TRUE;
}
//
// Window finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeWindow(JSContext *cx, JSObject *obj)
{
}
//
// Window enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateWindow(JSContext *cx, JSObject *obj)
{
nsIDOMWindow *a = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->EnumerateProperty(cx);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// Window resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveWindow(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMWindow *a = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->Resolve(cx, id);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// Native method Dump
//
PR_STATIC_CALLBACK(JSBool)
WindowDump(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
JSString *jsstring0 = JS_ValueToString(cx, argv[0]);
if (nsnull != jsstring0) {
b0.SetString(JS_GetStringChars(jsstring0));
}
else {
b0.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->Dump(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function dump requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Alert
//
PR_STATIC_CALLBACK(JSBool)
WindowAlert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
JSString *jsstring0 = JS_ValueToString(cx, argv[0]);
if (nsnull != jsstring0) {
b0.SetString(JS_GetStringChars(jsstring0));
}
else {
b0.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->Alert(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function alert requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ClearTimeout
//
PR_STATIC_CALLBACK(JSBool)
WindowClearTimeout(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (NS_OK != nativeThis->ClearTimeout(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function clearTimeout requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ClearInterval
//
PR_STATIC_CALLBACK(JSBool)
WindowClearInterval(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (NS_OK != nativeThis->ClearInterval(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function clearInterval requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method SetTimeout
//
PR_STATIC_CALLBACK(JSBool)
WindowSetTimeout(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->SetTimeout(cx, argv+0, argc-0, &nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function setTimeout requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method SetInterval
//
PR_STATIC_CALLBACK(JSBool)
WindowSetInterval(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->SetInterval(cx, argv+0, argc-0, &nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function setInterval requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for Window
//
JSClass WindowClass = {
"Window",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetWindowProperty,
SetWindowProperty,
EnumerateWindow,
ResolveWindow,
JS_ConvertStub,
FinalizeWindow
};
//
// Window class properties
//
static JSPropertySpec WindowProperties[] =
{
{"window", WINDOW_WINDOW, JSPROP_ENUMERATE | JSPROP_READONLY},
{"self", WINDOW_SELF, JSPROP_ENUMERATE | JSPROP_READONLY},
{"document", WINDOW_DOCUMENT, JSPROP_ENUMERATE | JSPROP_READONLY},
{"navigator", WINDOW_NAVIGATOR, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
//
// Window class methods
//
static JSFunctionSpec WindowMethods[] =
{
{"dump", WindowDump, 1},
{"alert", WindowAlert, 1},
{"clearTimeout", WindowClearTimeout, 1},
{"clearInterval", WindowClearInterval, 1},
{"setTimeout", WindowSetTimeout, 0},
{"setInterval", WindowSetInterval, 0},
{0}
};
//
// Window constructor
//
PR_STATIC_CALLBACK(JSBool)
Window(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// Window class initialization
//
nsresult NS_InitWindowClass(nsIScriptContext *aContext,
nsIScriptGlobalObject *aGlobal)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *global = JS_GetGlobalObject(jscontext);
JS_DefineProperties(jscontext, global, WindowProperties);
JS_DefineFunctions(jscontext, global, WindowMethods);
return NS_OK;
}
//
// Method for creating a new Window JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptWindow(nsIScriptContext *aContext, nsIDOMWindow *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null arg");
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *global = ::JS_NewObject(jscontext, &WindowClass, NULL, NULL);
if (global) {
// The global object has a to be defined in two step:
// 1- create a generic object, with no prototype and no parent which
// will be passed to JS_InitStandardClasses. JS_InitStandardClasses
// will make it the global object
// 2- define the global object to be what you really want it to be.
//
// The js runtime is not fully initialized before JS_InitStandardClasses
// is called, so part of the global object initialization has to be moved
// after JS_InitStandardClasses
// assign "this" to the js object, don't AddRef
::JS_SetPrivate(jscontext, global, aSupports);
*aReturn = (void*)global;
return NS_OK;
}
return NS_ERROR_FAILURE;
}