start at jsContext and jsRuntime implementations, enough to run trivial script

This commit is contained in:
shaver 1998-07-08 16:53:49 +00:00
Родитель 916e4c3e8c
Коммит f49ed3305e
13 изменённых файлов: 798 добавлений и 85 удалений

156
js/src/xpcom/Makefile Normal file
Просмотреть файл

@ -0,0 +1,156 @@
#! gmake
# 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.
DEPTH = ../../..
LIBRARY_NAME = jsxpcom
ifeq ($(subst /,_,$(shell uname -s)),OS2)
ifndef XCFLAGS
OS2_IMPLIB=1
LIBRARY = jsxpcom$(MOZ_BITS)$(VERSION_NUMBER).$(LIB_SUFFIX)
DEF_FILE = jsxpcomos2$(VERSION_NUMBER).def
EXTRA_LIBS = $(LIBNSPR) $(LIBNSJAVA)
else
EXTRA_LIBS = $(LIBNSPR) $(LIBNSJAVA) $(OBJDIR)/libjs.lib
endif
endif
MODULE = jsxpcom
REQUIRES = xpcom js nspr
CSRCS = $(NULL)
CPPSRCS = jxext.cpp \
jsContext.cpp \
jsRuntime.cpp \
jsScriptable.cpp \
$(NULL)
PROGCSRCS = common.c \
$(NULL)
PROGCPPSRCS = jsxpcom.cpp \
$(NULL)
PROGOBJS = $(addprefix $(OBJDIR)/, $(PROGCPPSRCS:.cpp=.o)) \
$(addprefix $(OBJDIR)/, $(PROGCSRCS:.c=.o)) \
$(NULL)
EXPORTS = jsIExtension.h \
jsIContext.h \
jsIRuntime.h \
jsIScript.h \
jsIScriptable.h \
$(NULL)
INCLUDES += -I$(PUBLIC)/xpcom -I$(PUBLIC)/js
PROGRAM = jsxpcom
# use the C++ compiler to do the final link
CPP_PROG_LINK = 1
# `libs' just does libs, `install' does programs
LIBS_NEQ_INSTALL = 1
# XXX this is not XP
LDFLAGS += -rdynamic
include $(DEPTH)/config/rules.mk
export::
libs:: $(SHARED_LIBRARY) $(LIBRARY)
install:: $(PROGRAM)
ifndef BUILD_OPT
MOCHAFILE = 1
endif
ifdef JSFILE
DEFINES += -DJSFILE
endif
ifdef JS_THREADSAFE
DEFINES += -DJS_THREADSAFE
endif
ifdef JS_NO_THIN_LOCKS
DEFINES += -DJS_USE_ONLY_NSPR_LOCKS
endif
ifdef JS_VERSION
DEFINES += -DJS_VERSION=$(JS_VERSION)
endif
ifeq ($(CPU_ARCH),sparc)
ifndef JS_NO_ULTRA
ULTRA_OPTIONS := -xarch=v8plus,-DULTRA_SPARC
ULTRA_OPTIONSCC := -DULTRA_SPARC
else
ULTRA_OPTIONS := -xarch=v8
ULTRA_OPTIONSCC :=
endif
ifeq ($(shell uname -m),sun4u)
ASFLAGS += -Wa,$(ULTRA_OPTIONS),-P,-L,-D_ASM,-D__STDC__=0 $(ULTRA_OPTIONSCC)
else
ASFLAGS += -Wa,-xarch=v8,-P,-L,-D_ASM,-D__STDC__=0
endif
endif # sparc
INCLUDES += -I.
ifdef NSPR20
INCLUDES += -I$(DIST)/include/nspr20/pr
else
INCLUDES += -I$(XPDIST)/public/nspr
endif
ifndef NSBUILDROOT
JSJAVA_STUBHEADERS = -I$(DEPTH)/sun-java/include/_gen \
-I$(DEPTH)/sun-java/netscape/javascript/_jri \
-I$(DEPTH)/sun-java/netscape/security/_jri
else
JSJAVA_STUBHEADERS = -I$(JRI_GEN_DIR) -I$(JDK_GEN_DIR)
endif
JSJAVA_CFLAGS = -I$(DEPTH)/sun-java/md-include \
-I$(DEPTH)/sun-java/include \
$(JSJAVA_STUBHEADERS)
# LIBNSPR includes unneeded libmsgc21.a, but abstracts nspr version,
# etc. nicely.
LDFLAGS += -L$(DIST)/bin -lxpcom -lreg -ljsxpcom -ljs $(LIBNSPR) -lplc21 -lm
ifeq ($(OS_ARCH), OSF1)
LDFLAGS += -lc_r
endif
ifeq ($(OS_ARCH), SunOS)
LDFLAGS += -lposix4 -ldl -lnsl -lsocket
endif
ifeq ($(OS_ARCH), Linux)
LDFLAGS += -ldl
endif
jsxpcom: $(PROGRAM)
.PHONY: jsxpcom$(BIN_SUFFIX)

279
js/src/xpcom/jsContext.cpp Normal file
Просмотреть файл

@ -0,0 +1,279 @@
/* -*- Mode: cc; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* jsContext.cpp -- implementation of the jsIContext interface for the JSAPI.
*/
extern "C" {
#include <jsapi.h>
}
#include <nsISupports.h>
#include "jsContext.h"
#include "jsScriptable.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIContextIID, JS_ICONTEXT_IID);
NS_IMPL_ISUPPORTS(jsContext, kIContextIID);
static void
ErrorReporterHandler(JSContext *cx, const char* message,
JSErrorReport *report)
{
JSString *str;
jsContext *icx = (jsContext *)JS_GetContextPrivate(cx);
if (!icx)
/* well, we can't exactly report an error... */
return;
str = JS_NewStringCopyZ(cx, message);
if (!str)
return;
icx->reporter->reportError(str, report);
}
jsContext::jsContext (JSRuntime *rt, uintN stacksize)
{
cx = JS_NewContext(rt, stacksize);
reporter = NULL;
if (cx) {
JS_SetErrorReporter(cx, ::ErrorReporterHandler);
JS_SetContextPrivate(cx, (void *)this);
}
/*
* jsRuntime checks this->cx to see if we're valid when creating
* contexts via the factory method jsRuntime::newContext.
*/
}
jsContext::~jsContext()
{
JS_DestroyContext(cx);
}
JSContext *
jsContext::getJSContext()
{
return cx;
}
jsIFunction *
jsContext::compileFunction(jsIScriptable *scope,
JSString *source,
JSString *sourceName,
int lineno)
{
/* NS_ERROR_NOT_IMPLEMENTED */
return NULL;
}
JSString *
jsContext::decompileScript(jsIScript *script,
jsIScriptable *scope,
int indent)
{
/* NS_ERROR_NOT_IMPLEMENTED */
return NULL;
}
JSString *
jsContext::decompileFunction(jsIFunction *fun,
int indent)
{
/* NS_ERROR_NOT_IMPLEMENTED */
return NULL;
}
JSString *
jsContext::decompileFunctionBody(jsIFunction *fun,
int indent)
{
/* NS_ERROR_NOT_IMPLEMENTED */
return NULL;
}
jsIScriptable *
jsContext::newObject(jsIScriptable *scope)
{
return newObject(scope, NULL, NULL, 0);
}
jsIScriptable *
jsContext::newObject(jsIScriptable *scope,
JSString *constructorName)
{
return newObject(scope, constructorName, NULL, 0);
}
jsIScriptable *
jsContext::newObject(jsIScriptable *scope,
JSString *constructorName,
jsval *argv,
uintN argc)
{
/* NS_ERROR_NOT_IMPLEMENTED */
return NULL;
}
jsIScriptable *
jsContext::newArray(jsIScriptable *scope)
{
return newArray(scope, NULL, 0);
}
jsIScriptable *
jsContext::newArray(jsIScriptable *scope,
uintN length)
{
return newArray(scope, NULL, length);
}
jsIScriptable *
jsContext::newArray(jsIScriptable *scope,
jsval *elements,
uintN length)
{
/* NS_ERROR_NOT_IMPLEMENTED */
return NULL;
}
nsresult
jsContext::toBoolean(jsval v, JSBool *bp)
{
if (!JS_ValueToBoolean(cx, v, bp))
return NS_ERROR_FAILURE;
return NS_OK;
}
jsdouble *
jsContext::toNumber(jsval v)
{
jsdouble d;
if (!JS_ValueToNumber(cx, v, &d))
return NULL;
return JS_NewDouble(cx, d);
}
JSString *
jsContext::toString(jsval v)
{
return JS_ValueToString(cx, v);
}
jsIScriptable *
jsContext::toScriptable(jsval v, jsIScriptable *scope)
{
/* NS_ERROR_NOT_IMPLEMENTED */
return NULL;
}
JSObject *jsScriptableCreateJSObjectProxy(jsIContext *cx, jsIScriptable *scope)
{
JSObject *obj = ((jsScriptable *)scope)->getJSObject(cx);
if (!obj) {
/* XXX construct a proxy object */
return NULL;
}
return obj;
}
jsIScriptable *jsScriptableCreateFromJSObject(jsIContext *cx, JSObject *obj)
{
return new jsScriptable(cx, obj);
}
nsresult
jsContext::evaluateString(jsIScriptable *scope,
JSString *source,
JSString *sourceName,
uintN lineno,
jsval *rval)
{
JSObject *obj = ::jsScriptableCreateJSObjectProxy(this, scope);
if (!obj)
return NS_ERROR_FAILURE;
if (!JS_EvaluateScript(cx, obj, JS_GetStringBytes(source),
JS_GetStringLength(source),
JS_GetStringBytes(sourceName),
JS_GetStringLength(sourceName),
rval))
return NS_ERROR_FAILURE;
return NS_OK;
}
nsresult
jsContext::initStandardObjects(jsIScriptable *scope)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
void
jsContext::reportWarning(JSString *message)
{
/* XXX fill in report, make varargs */
if (reporter)
reporter->reportWarning(message, NULL);
};
void
jsContext::reportError(JSString *message)
{
/* XXX */
JS_ReportError(cx, JS_GetStringBytes(message));
#if 0
if (reporter)
reporter->reportError(message, NULL);
#endif
}
jsIErrorReporter *
jsContext::setErrorReporter(jsIErrorReporter *er)
{
jsIErrorReporter *older = reporter;
reporter = er;
return older;
}
uintN
jsContext::setLanguageVersion(uintN version)
{
return (uintN)JS_SetVersion(cx, (JSVersion)version);
}
uintN
jsContext::getLanguageVersion()
{
return JS_GetVersion(cx);
}
void
jsContext::enter()
{
#ifdef JS_THREADSAFE
(void)JS_SetContextThread(cx);
#endif
}
void
jsContext::exit()
{
#ifdef JS_THREADSAFE
(void)JS_ClearContextThread(cx);
#endif
}

72
js/src/xpcom/jsContext.h Normal file
Просмотреть файл

@ -0,0 +1,72 @@
#ifndef JS_CONTEXT_H
#define JS_CONTEXT_H
#include "jsIContext.h"
#include "jsRuntime.h"
#include "jsScriptable.h"
static void ErrorReporterHandler(JSContext *cx, const char *message,
JSErrorReport *report);
class jsContext: public jsIContext {
JSContext *cx;
jsIErrorReporter *reporter;
public:
jsContext() { };
jsContext(JSRuntime *rt, uintN stacksize);
~jsContext();
/**
* We shouldn't need this, but for now...
*/
JSContext *getJSContext(void);
jsIFunction *compileFunction(jsIScriptable *scope,
JSString *source,
JSString *sourceName,
int lineno);
JSString *decompileScript(jsIScript *script,
jsIScriptable *scope,
int indent);
JSString *decompileFunction(jsIFunction *fun,
int indent);
JSString *decompileFunctionBody(jsIFunction *fun,
int indent);
jsIScriptable *newObject(jsIScriptable *scope);
jsIScriptable *newObject(jsIScriptable *scope,
JSString *constructorName);
jsIScriptable *newObject(jsIScriptable *scope,
JSString *constructorName,
jsval *argv,
uintN argc);
jsIScriptable *newArray(jsIScriptable *scope);
jsIScriptable *newArray(jsIScriptable *scope,
uintN length);
jsIScriptable *newArray(jsIScriptable *scope,
jsval *elements,
uintN length);
nsresult toBoolean(jsval v, JSBool *bp);
jsdouble *toNumber(jsval v);
JSString *toString(jsval v);
jsIScriptable *toScriptable(jsval v, jsIScriptable *scope);
nsresult evaluateString(jsIScriptable *scope,
JSString *source,
JSString *sourceName,
uintN lineno,
jsval *rval);
nsresult initStandardObjects(jsIScriptable *scope);
void reportError(JSString *message);
void reportWarning(JSString *message);
jsIErrorReporter *setErrorReporter(jsIErrorReporter *reporter);
uintN setLanguageVersion(uintN version);
uintN getLanguageVersion(void);
void enter(void);
void exit(void);
friend class jsRuntime;
friend class jsScriptable;
friend void ErrorReporterHandler(JSContext *cx, const char *message,
JSErrorReport *report);
NS_DECL_ISUPPORTS
};
#endif /* JS_CONTEXT_H */

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

@ -20,11 +20,14 @@
* jsIContext.h --- the XPCOM interface to the core JS engine functionality.
*/
class jsIContext;
#ifndef JS_ICONTEXT_H
#define JS_ICONTEXT_H
#include "nsISupports.h"
#include <nsISupports.h>
#include <jsapi.h>
#include "jsIScript.h"
#include "jsIScriptable.h"
#include "jsIFunction.h"
#include "jsIErrorReporter.h"
@ -33,34 +36,6 @@
{ 0, 0, 0, \
{0, 0, 0, 0, 0, 0, 0, 0}}
#define JS_IRUNTIME_IID \
{ 0, 0, 0, \
{0, 0, 0, 0, 0, 0, 0, 0}}
#define JS_ISCRIPT_IID \
{ 0, 0, 0, \
{0, 0, 0, 0, 0, 0, 0, 0}}
/**
* jsIScript interface declaration
*/
class jsIScript: public nsISupports {
public:
virtual jsIScript() = 0;
virtual ~jsIScript() = 0;
};
/**
* jsIRuntime interface declaration.
*/
class jsIRuntime: public nsISupports {
public:
virtual jsIRuntime() = 0;
virtual ~jsIRuntime() = 0;
};
/**
* jsIContext interface declaration
*/
@ -144,7 +119,7 @@ class jsIContext: public nsISupports {
NS_IMETHOD toBoolean(jsval v, JSBool *bp) = 0;
/**
* Convert a jsval to a JavaScript number value.
* Convert a jsval to a (newly-allocated) JavaScript number value.
*/
virtual jsdouble *toNumber(jsval v) = 0;
@ -157,7 +132,7 @@ class jsIContext: public nsISupports {
* Convert a jsval to a JavaScript object. The provided scope is
* used to look up constructors Number, String and Boolean as required.
*/
virtual jsIScriptable *toObject(jsval v, jsIScriptable *scope) = 0;
virtual jsIScriptable *toScriptable(jsval v, jsIScriptable *scope) = 0;
/**
* Evaluate a JavaScript source string.
@ -165,7 +140,8 @@ class jsIContext: public nsISupports {
NS_IMETHOD evaluateString(jsIScriptable *scope,
JSString *source,
JSString *sourceName,
uintN lineno) = 0;
uintN lineno,
jsval *rval) = 0;
/**
* Initialize the standard (ECMA-plus) objects in the given scope.
@ -176,12 +152,12 @@ class jsIContext: public nsISupports {
/**
* Report a (usually fatal) runtime error.
*/
NS_IMETHOD reportError(JSString *message) = 0;
virtual void reportError(JSString *message) = 0;
/**
* Report a warning.
*/
NS_IMETHOD reportWarning(JSString *message) = 0;
virtual void reportWarning(JSString *message) = 0;
/**
* Change the error reporter for this context.
@ -191,7 +167,7 @@ class jsIContext: public nsISupports {
/**
* Set the current language version.
*/
NS_IMETHOD setLanguageVersion(uintN version) = 0;
virtual uintN setLanguageVersion(uintN version) = 0;
/**
* Get the current language version.
@ -203,18 +179,13 @@ class jsIContext: public nsISupports {
* This should be called whenever a Context is operated upon by a
* new thread.
*/
NS_IMETHOD enter(void);
virtual void enter(void) = 0;
/**
* Break the Context-thread association.
*/
NS_IMETHOD exit(void);
virtual void exit(void) = 0;
/**
* Create a new Context.
*/
virtual Context(jsIRuntime *runtime, uintN stacksize) = 0;
virtual ~Context() = 0;
};
};
#endif /* JS_ICONTEXT_H */

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

@ -24,25 +24,25 @@
#define JS_IERRORREPORTER_H
#include "nsISupports.h"
extern "C" {
#include <jsapi.h>
}
class jsIErrorReporter: public nsISupports {
public:
virtual jsIErrorReporter() = 0;
jsIErrorReporter();
virtual ~jsIErrorReporter() = 0;
/**
* Report a warning.
*/
NS_IMETHOD reportWarning(JSString *message,
JSString *sourceName,
uintN lineno) = 0;
JSErrorReport *report) = 0;
/**
* Report an error.
*/
NS_IMETHOD reportError(JSString *message,
JSString *sourceName,
uintN lineno) = 0;
JSErrorReport *report) = 0;
};

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

@ -1,35 +0,0 @@
/* -*- Mode: cc; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* jsIFunction.h -- the XPCOM interface to JavaScript function objects.
*/
#ifndef JS_IFUNCTION_H
#define JS_IFUNCTION_H
#include "nsISupports.h"
#include <jsapi.h>
class jsIFunction: public nsISupports {
public:
virtual jsIFunction() = 0;
virtual ~jsIFunction() = 0;
};
#endif /* JS_IFUNCTION_H */

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

0
js/src/xpcom/jsIScript.h Normal file
Просмотреть файл

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

@ -20,16 +20,53 @@
* jsIScriptable.h -- the XPCOM interface to native JavaScript objects.
*/
class jsIScriptable; /* for mutually-dependent includes */
#ifndef JS_ISCRIPTABLE_H
#define JS_ISCRIPTABLE_H
#include "nsISupports.h"
#include "jsIContext.h"
#include <jsapi.h>
#define JS_ISCRIPTABLE_IID \
{ 0, 0, 0, \
{0, 0, 0, 0, 0, 0, 0, 0}}
#define JSSCRIPTABLE_NOT_FOUND -1
class jsIScriptable: public nsISupports {
public:
virtual jsIScriptable() = 0;
virtual ~jsIScriptable() = 0;
virtual JSString *getClassName() = 0;
/* XXX use jsid for name/index? */
virtual jsval get(jsval id) = 0;
virtual JSBool has(jsval id) = 0;
virtual void put(jsval id, jsval v) = 0;
virtual void del(jsval id) = 0;
virtual jsIScriptable *getPrototype() = 0;
virtual void setPrototype(jsIScriptable *prototype) = 0;
virtual jsIScriptable *getParentScope() = 0;
virtual void setParentScope(jsIScriptable *parent) = 0;
/* virtual JSIdArray *getIds(); */
virtual jsval getDefaultValue(JSType hint) = 0;
virtual JSBool hasInstance(jsIScriptable *instance) = 0;
/**
* Return a classic JSAPI JSObject * for this object.
* Return NULL if you don't know how to, and the engine will
* construct a proxy for you.
*/
virtual JSObject *getJSObject(jsIContext *) = 0;
/**
* Set the JSObject proxy for this object (typically one created
* by the engine in response to a NULL return fron getJSObject).
* Context is provided for GC rooting and other tasks. Be sure
* to unroot the proxy in your destructor, etc.
*/
virtual void setJSObject(jsIContext *, JSObject *)= 0;
};
#endif /* JS_ISCRIPTABLE_H */

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

@ -0,0 +1,53 @@
/* -*- Mode: cc; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* jsRuntime.cpp -- implementation of the jsIContext interface for the JSAPI.
*/
#include "jsRuntime.h"
static NS_DEFINE_IID(kIRuntime, JS_IRUNTIME_IID);
static int jsRuntime::runtimeCount = 0;
jsRuntime::jsRuntime(uint32 maxbytes)
{
rt = JS_NewRuntime(maxbytes);
if (rt)
runtimeCount++;
/* and what if it _doesn't_ work? */
}
jsRuntime::~jsRuntime()
{
JS_DestroyRuntime(rt);
if (!--runtimeCount) {
JS_ShutDown();
}
}
NS_IMPL_ISUPPORTS(jsRuntime, kIRuntime);
jsIContext *jsRuntime::newContext(size_t stacksize)
{
jsContext *cx = new jsContext(rt, stacksize);
if (cx->cx)
return cx;
return NULL;
}

0
js/src/xpcom/jsRuntime.h Normal file
Просмотреть файл

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

@ -0,0 +1,125 @@
/* -*- Mode: cc; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "jsScriptable.h"
#include "jsContext.h"
static NS_DEFINE_IID(kIScriptableIID, JS_ISCRIPTABLE_IID);
NS_IMPL_ISUPPORTS(jsScriptable, kIScriptableIID);
jsScriptable::jsScriptable(jsIContext *cx, JSObject *object)
{
/* cx->addRoot(&obj); */
/* cx->addRoot(&className); */
setJSObject(cx, object);
}
jsScriptable::~jsScriptable()
{
/* cx->removeRoot(&obj); */
/* cx->removeRoot(&className); */
}
JSObject *jsScriptable::getJSObject(jsIContext *cx)
{
return obj;
}
void
jsScriptable::setJSObject(jsIContext *cx, JSObject *object)
{
obj = object;
jsContext *icx = (jsContext *)cx;
className = JS_NewStringCopyZ(icx->cx,
#ifdef JS_THREADSAFE
JS_GetClass(icx->cx, object)
#else
JS_GetClass(object)
#endif
->name);
/* XXX update proto and parent */
}
JSString *
jsScriptable::getClassName()
{
return className;
}
jsval
jsScriptable::get(jsval id)
{
return JSVAL_VOID;
}
JSBool
jsScriptable::has(jsval id)
{
return JS_FALSE;
}
void
jsScriptable::put(jsval id, jsval v)
{
}
void
jsScriptable::del(jsval id)
{
}
jsIScriptable *
jsScriptable::getPrototype()
{
return proto;
}
void
jsScriptable::setPrototype(jsIScriptable *prototype)
{
proto = prototype;
/* set the prototype of the underlying JSObject * */
}
jsIScriptable *
jsScriptable::getParentScope()
{
return parent;
}
void
jsScriptable::setParentScope(jsIScriptable *parent)
{
this->parent = parent;
/* set parent of underlying JSObject */
}
jsval
jsScriptable::getDefaultValue(JSType hint)
{
return JSVAL_VOID;
}
JSBool
jsScriptable::hasInstance(jsIScriptable *instance)
{
return JS_FALSE;
}

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

@ -0,0 +1,55 @@
/* -*- Mode: cc; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef JS_SCRIPTABLE_H
#define JS_SCRIPTABLE_H
#include "jsIScriptable.h"
extern "C" {
#include <jsapi.h>
}
class jsScriptable: public jsIScriptable {
JSObject *obj;
JSString *className;
jsIScriptable *proto, *parent;
public:
NS_DECL_ISUPPORTS;
jsScriptable(jsIContext *, JSObject *);
~jsScriptable();
JSString *getClassName();
/* XXX use jsid for name/index? */
jsval get(jsval id);
JSBool has(jsval id);
void put(jsval id, jsval v);
void del(jsval id);
jsIScriptable *getPrototype();
void setPrototype(jsIScriptable *prototype);
jsIScriptable *getParentScope();
void setParentScope(jsIScriptable *parent);
/* JSIdArray *getIds(); */
jsval getDefaultValue(JSType hint);
JSBool hasInstance(jsIScriptable *instance);
JSObject *getJSObject(jsIContext *);
void setJSObject(jsIContext *, JSObject *);
};
#endif /* JS_SCRIPTABLE_H */