From 3f07b83d17b74ddb98e6f3445c287084a1c96e41 Mon Sep 17 00:00:00 2001 From: "bjorn%netscape.com" Date: Tue, 4 Aug 1998 20:34:20 +0000 Subject: [PATCH] Additional xpcom support for JS. Currently not in use by anyone. See MyScriptable.{h,cpp} for an example of how to use this interface. --- js/src/xpcom/JSWrapper.cpp | 0 js/src/xpcom/JSWrapper.h | 0 js/src/xpcom/MyScriptable.cpp | 0 js/src/xpcom/MyScriptable.h | 0 js/src/xpcom/jsContext.cpp | 338 --------------------------------- js/src/xpcom/jsContext.h | 83 -------- js/src/xpcom/jsIContext.h | 201 -------------------- js/src/xpcom/jsIScriptable.cpp | 0 js/src/xpcom/jsIScriptable.h | 208 ++++++++++++++------ js/src/xpcom/jsRuntime.cpp | 53 ------ js/src/xpcom/main.cpp | 0 js/src/xpcom/xpcom.dsp | 141 ++++++++++++++ 12 files changed, 286 insertions(+), 738 deletions(-) create mode 100644 js/src/xpcom/JSWrapper.cpp create mode 100644 js/src/xpcom/JSWrapper.h create mode 100644 js/src/xpcom/MyScriptable.cpp create mode 100644 js/src/xpcom/MyScriptable.h create mode 100644 js/src/xpcom/jsIScriptable.cpp create mode 100644 js/src/xpcom/main.cpp create mode 100644 js/src/xpcom/xpcom.dsp diff --git a/js/src/xpcom/JSWrapper.cpp b/js/src/xpcom/JSWrapper.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/js/src/xpcom/JSWrapper.h b/js/src/xpcom/JSWrapper.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/js/src/xpcom/MyScriptable.cpp b/js/src/xpcom/MyScriptable.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/js/src/xpcom/MyScriptable.h b/js/src/xpcom/MyScriptable.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/js/src/xpcom/jsContext.cpp b/js/src/xpcom/jsContext.cpp index f91e2adcff8..e69de29bb2d 100644 --- a/js/src/xpcom/jsContext.cpp +++ b/js/src/xpcom/jsContext.cpp @@ -1,338 +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. - */ - -/* - * jsContext.cpp -- implementation of the jsIContext interface for the JSAPI. - */ - -extern "C" { -#include -} - -#include -#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 = icx->newStringCopyZ(message); - if (!str) - return; - icx->reporter->reportError(icx, 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 = scope->getJSObject(this); - 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) -{ - JSObject *obj = scope->getJSObject(this); - if (!obj) - return NS_ERROR_FAILURE; - if (!JS_InitStandardClasses(cx, obj)) - return NS_ERROR_FAILURE; - return NS_OK; -} - -void -jsContext::reportWarning(JSString *message) -{ - /* XXX fill in report, make varargs */ - if (reporter) - reporter->reportWarning(this, 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 -} - -JSString * -jsContext::newStringCopyZ(const char *string) -{ - return JS_NewStringCopyZ(cx, string); -} - -JSString * -jsContext::newUCStringCopyZ(const jschar *string) -{ - return JS_NewUCStringCopyZ(cx, string); -} - -JSString * -jsContext::newStringCopyN(const char *string, size_t len) -{ - return JS_NewStringCopyN(cx, string, len); -} - -JSString * -jsContext::newUCStringCopyN(const jschar *string, size_t len) -{ - return JS_NewUCStringCopyN(cx, string, len); -} - -JSString * -jsContext::newString(char *string, size_t len) -{ - return JS_NewString(cx, string, len); -} - -JSString * -jsContext::newUCString(jschar *string, size_t len) -{ - return JS_NewUCString(cx, string, len); -} - -JSBool -jsContext::addRoot(void *root) -{ - return JS_AddRoot(cx, root); -} - -JSBool -jsContext::addNamedRoot(void *root, const char *name) -{ - return JS_AddNamedRoot(cx, root, name); -} - -JSBool -jsContext::removeRoot(void *root) -{ - return JS_RemoveRoot(cx, root); -} diff --git a/js/src/xpcom/jsContext.h b/js/src/xpcom/jsContext.h index e9025a53d42..e69de29bb2d 100644 --- a/js/src/xpcom/jsContext.h +++ b/js/src/xpcom/jsContext.h @@ -1,83 +0,0 @@ -#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); - - JSString *newStringCopyZ(const char *string); - JSString *newUCStringCopyZ(const jschar *string); - JSString *newStringCopyN(const char *string, size_t len); - JSString *newUCStringCopyN(const jschar *string, size_t len); - JSString *newString(char *string, size_t len); - JSString *newUCString(jschar *string, size_t len); - - JSBool addRoot(void *root); - JSBool addNamedRoot(void *root, const char *name); - JSBool removeRoot(void *root); - - friend class jsRuntime; - friend class jsScriptable; - friend void ErrorReporterHandler(JSContext *cx, const char *message, - JSErrorReport *report); - NS_DECL_ISUPPORTS -}; - -#endif /* JS_CONTEXT_H */ diff --git a/js/src/xpcom/jsIContext.h b/js/src/xpcom/jsIContext.h index 3d1800eb539..e69de29bb2d 100644 --- a/js/src/xpcom/jsIContext.h +++ b/js/src/xpcom/jsIContext.h @@ -1,201 +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. - */ - -/* - * jsIContext.h --- the XPCOM interface to the core JS engine functionality. - */ - -class jsIContext; - -#ifndef JS_ICONTEXT_H -#define JS_ICONTEXT_H - -#include -#include -#include "jsIScript.h" -#include "jsIScriptable.h" -#include "jsIFunction.h" -#include "jsIErrorReporter.h" - -#define JS_ICONTEXT_IID \ - { 0, 0, 0, \ - {0, 0, 0, 0, 0, 0, 0, 0}} - -/** - * jsIContext interface declaration - */ - -class jsIContext: public nsISupports { - public: - /** - * Compile a JavaScript function. - * @return NULL on error, compiled jsIFunction *otherwise. - */ - virtual jsIFunction *compileFunction(jsIScriptable *scope, - JSString *source, - JSString *sourceName, - int lineno) = 0; - /** - * Decompile a JavaScript script to equivalent source. - */ - virtual JSString *decompileScript(jsIScript *script, - jsIScriptable *scope, - int indent) = 0; - /** - * Decompile a JavaScript function to equivalent source, including - * the function declaration and parameter list. - * - * Provides function body of '[native code]' if the provided - * jsIFunction * isn't of JS-source heritage. - */ - virtual JSString *decompileFunction(jsIFunction *fun, - int indent) = 0; - - /** - * Decompile the body of a JavaScript function. - * - * Provides function body of '[native code]' if the provided - * jsIFunction * isn't of JS-source heritage. - */ - virtual JSString *decompileFunctionBody(jsIFunction *fun, - int indent) = 0; - - /** - * Create a new JavaScript object. This is equivalent to evaluating - * "new Object()", which requires that the value "Object" in the - * provided scope is a function. - */ - virtual jsIScriptable *newObject(jsIScriptable *scope) = 0; - - /** - * Create a new JavaScript object by executing the named constructor. - * This requires that the value named by the constructorName argument. - */ - virtual jsIScriptable *newObject(jsIScriptable *scope, - JSString *constructorName) = 0; - - /** - * Create a new JavaScript object by executing the named constructor - * with the provided arguments. - */ - virtual jsIScriptable *newObject(jsIScriptable *scope, - JSString *constructorName, - jsval *argv, - uintN argc) = 0; - - /** - * Create a new JavaScript Array with the specified inital length. - */ - virtual jsIScriptable *newArray(jsIScriptable *scope, - uintN length) = 0; - - /** - * Create a new JavaScript array with the provided initial contents. - */ - virtual jsIScriptable *newArray(jsIScriptable *scope, - jsval *elements, - uintN length) = 0; - - /** - * Convert a jsval to a JavaScript boolean value. - * Note: the return value indicates the success of the operation, - * not the resulting boolean value. *bp stores the new boolean value. - */ - NS_IMETHOD toBoolean(jsval v, JSBool *bp) = 0; - - /** - * Convert a jsval to a (newly-allocated) JavaScript number value. - */ - virtual jsdouble *toNumber(jsval v) = 0; - - /** - * Convert a jsval to a JavaScript string value. - */ - virtual JSString *toString(jsval v) = 0; - - /** - * Convert a jsval to a JavaScript object. The provided scope is - * used to look up constructors Number, String and Boolean as required. - */ - virtual jsIScriptable *toScriptable(jsval v, jsIScriptable *scope) = 0; - - /** - * Evaluate a JavaScript source string. - */ - NS_IMETHOD evaluateString(jsIScriptable *scope, - JSString *source, - JSString *sourceName, - uintN lineno, - jsval *rval) = 0; - - /** - * Initialize the standard (ECMA-plus) objects in the given scope. - * Makes scope an ECMA `global object'. - */ - NS_IMETHOD initStandardObjects(jsIScriptable *scope) = 0; - - /** - * Report a (usually fatal) runtime error. - */ - virtual void reportError(JSString *message) = 0; - - /** - * Report a warning. - */ - virtual void reportWarning(JSString *message) = 0; - - /** - * Change the error reporter for this context. - */ - virtual jsIErrorReporter *setErrorReporter(jsIErrorReporter *reporter) = 0; - - /** - * Set the current language version. - */ - virtual uintN setLanguageVersion(uintN version) = 0; - - /** - * Get the current language version. - */ - virtual uintN getLanguageVersion(void) = 0; - - /** - * Associate the Context with the current thread. - * This should be called whenever a Context is operated upon by a - * new thread. - */ - virtual void enter(void) = 0; - - /** - * Break the Context-thread association. - */ - virtual void exit(void) = 0; - - virtual JSString *newStringCopyZ(const char *string) = 0; - virtual JSString *newUCStringCopyZ(const jschar *string) = 0; - virtual JSString *newStringCopyN(const char *string, size_t len) = 0; - virtual JSString *newUCStringCopyN(const jschar *string, size_t len) = 0; - virtual JSString *newString(char *string, size_t len) = 0; - virtual JSString *newUCString(jschar *string, size_t len) = 0; - - virtual JSBool addRoot(void *root) = 0; - virtual JSBool addNamedRoot(void *root, const char *name) = 0; - virtual JSBool removeRoot(void *root) = 0; -}; - -#endif /* JS_ICONTEXT_H */ diff --git a/js/src/xpcom/jsIScriptable.cpp b/js/src/xpcom/jsIScriptable.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/js/src/xpcom/jsIScriptable.h b/js/src/xpcom/jsIScriptable.h index fbbc6615a76..3c1a29b17b8 100644 --- a/js/src/xpcom/jsIScriptable.h +++ b/js/src/xpcom/jsIScriptable.h @@ -1,71 +1,153 @@ -/* -*- 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. - */ - -/* - * jsIScriptable.h -- the XPCOM interface to native JavaScript objects. - */ - -class jsIScriptable; /* for mutually-dependent includes */ - -#ifndef JS_ISCRIPTABLE_H -#define JS_ISCRIPTABLE_H - +#ifndef _jsIScriptable +#define _jsIScriptable +#include "jsapi.h" #include "nsISupports.h" -#include "jsIContext.h" -#include #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 JSString *getClassName(jsIContext *) = 0; - - /* XXX use jsid for name/index? */ - NS_IMETHOD get(jsIContext *cx, const char *name, jsval *vp) = 0; - NS_IMETHOD has(jsIContext *cx, jsval id, JSBool *bp) = 0; - NS_IMETHOD put(jsIContext *cx, const char *name, jsval v) = 0; - NS_IMETHOD del(jsIContext *cx, jsval id) = 0; - - virtual jsIScriptable *getPrototype(jsIContext *cx) = 0; - NS_IMETHOD setPrototype(jsIContext *cx, jsIScriptable *prototype) = 0; - virtual jsIScriptable *getParentScope(jsIContext *cx) = 0; - NS_IMETHOD setParentScope(jsIContext *cx, jsIScriptable *parent) = 0; - /* virtual JSIdArray *getIds(); */ - NS_IMETHOD getDefaultValue(jsIContext *cx, JSType hint, jsval *vp) = 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. - */ - NS_IMETHOD setJSObject(jsIContext *, JSObject *)= 0; +class Meth { +public: + virtual nsresult invoke(int argc, jsval* args, jsval* rval) =0; + virtual void SetJSContext(JSContext* cx) =0; + virtual JSContext* GetJSContext() =0; + virtual void SetJSVal(JSContext* cx, jsval v) =0; + virtual jsval GetJSVal(JSContext* cx) =0; + virtual int AddRef() =0; + virtual int SubRef() =0; }; -#endif /* JS_ISCRIPTABLE_H */ +#define Method(C) Method_##C +#define DefMethodClass(C)\ +class C;\ +class Method_##C : public Meth {\ + JSContext* cx; \ + jsval mval;\ + int _ref;\ +public:\ + C* thisptr; \ + nsresult (C::*method)(JSContext* cx, int argc, jsval* args, jsval* rval);\ + virtual nsresult invoke(int argc, jsval* args, jsval* rval) {\ + return (thisptr->*method)(cx,argc,args,rval);\ + }\ + virtual void SetJSContext(JSContext* _cx) {\ + cx = _cx;\ + }\ + virtual JSContext* GetJSContext() {\ + return cx;\ + }\ + virtual void SetJSVal(JSContext* cx, jsval v) {\ + if (mval)\ + JS_RemoveRoot(cx,&mval);\ + mval = v;\ + JS_AddRoot(cx,&mval);\ + }\ + virtual jsval GetJSVal(JSContext* cx) {\ + return mval;\ + }\ + virtual int AddRef() {\ + return _ref++;\ + }\ + virtual int SubRef() {\ + return --_ref;\ + }\ + Method_##C() : cx(NULL), mval(0), _ref(0) {}\ + ~Method_##C() {\ + if (mval)\ + JS_RemoveRoot(cx,&mval);\ + }\ +} + +class jsIScriptable : public nsISupports { +public: + // static conversion between JS and C++ + static JS_PUBLIC_API(nsresult) FromJS(JSContext* cx, jsval v, double* d); + static JS_PUBLIC_API(nsresult) FromJS(JSContext* cx, jsval v, char** s, size_t n); + static JS_PUBLIC_API(nsresult) FromJS(JSContext* cx, jsval v, jsIScriptable** o); + static JS_PUBLIC_API(nsresult) ToJS(JSContext* cx, double d, jsval* v); + static JS_PUBLIC_API(nsresult) ToJS(JSContext* cx, char* s, jsval* v); + static JS_PUBLIC_API(nsresult) ToJS(JSContext* cx, jsIScriptable* o, jsval* v); + static JS_PUBLIC_API(nsresult) ToJS(JSContext* cx, Meth* m, jsval* v); + virtual JSObject* GetJS() =0; // returns the peer JS object + virtual void SetJS(JSObject *o) =0; // sets the peer + virtual nsresult get(JSContext* cx, char* p, jsval* v) =0; // gets the property + virtual nsresult put(JSContext* cx, char* p, jsval v) =0; // sets ... + virtual char** GetIds() =0; // returns an array with the identifiers (ints or strings) that can be enumerated + virtual JSObject *getParent(JSContext* cx) =0; + virtual void setParent(JSContext* cx, JSObject *o) =0; + virtual JSObject* getProto(JSContext* cx) =0; + virtual void setProto(JSContext* cx, JSObject *o) =0; +}; + +#define Scriptable(C) jsScriptable_##C +#define DefScriptableClass(C)\ +DefMethodClass(C);\ +class jsScriptable_##C : public jsIScriptable {\ + JSObject* obj;\ + int _ref;\ + int sz;\ + char** names;\ + Method(C)* meths;\ +public:\ + NS_DECL_ISUPPORTS;\ + jsScriptable_##C(int _sz=0) : _ref(0), sz(_sz), obj(NULL) {\ + names = new char*[sz];\ + meths = new Method(C)[sz];\ + for (int i=0; icx) - return cx; - return NULL; -} diff --git a/js/src/xpcom/main.cpp b/js/src/xpcom/main.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/js/src/xpcom/xpcom.dsp b/js/src/xpcom/xpcom.dsp new file mode 100644 index 00000000000..a83ee67a6e5 --- /dev/null +++ b/js/src/xpcom/xpcom.dsp @@ -0,0 +1,141 @@ +# Microsoft Developer Studio Project File - Name="xpcom" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=xpcom - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "xpcom.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "xpcom.mak" CFG="xpcom - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "xpcom - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "xpcom - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "xpcom - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 + +!ELSEIF "$(CFG)" == "xpcom - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "EXPORT_JS_API" /D "_WIN32" /D "WIN32" /D "_DEBUG" /D "DEBUG" /D "XP_PC" /D "_WINDOWS" /D "JSFILE" /D "JS_THREADSAFE" /D "NSPR20" /FR /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib H:\trees\ns\dist\WINNT4.0_DBG.OBJ\lib\libnspr21.lib h:\trees\mozilla.org\mozilla\dist\WIN32_D.OBJ\lib\xpcom32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "xpcom - Win32 Release" +# Name "xpcom - Win32 Debug" +# Begin Source File + +SOURCE=.\jsContext.cpp +# End Source File +# Begin Source File + +SOURCE=.\jsContext.h +# End Source File +# Begin Source File + +SOURCE=.\jsIContext.h +# End Source File +# Begin Source File + +SOURCE=.\jsIErrorReporter.h +# End Source File +# Begin Source File + +SOURCE=.\jsIFunction.h +# End Source File +# Begin Source File + +SOURCE=.\jsIRuntime.h +# End Source File +# Begin Source File + +SOURCE=.\jsIScript.h +# End Source File +# Begin Source File + +SOURCE=.\jsIScriptable.cpp +# End Source File +# Begin Source File + +SOURCE=.\jsIScriptable.h +# End Source File +# Begin Source File + +SOURCE=.\jsRuntime.cpp +# End Source File +# Begin Source File + +SOURCE=.\jsRuntime.h +# End Source File +# Begin Source File + +SOURCE=.\JSWrapper.cpp +# End Source File +# Begin Source File + +SOURCE=.\JSWrapper.h +# End Source File +# End Target +# End Project