From fe85e51ec16a86d569f3cea2eb70dc43c9fbc0e8 Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Wed, 2 Aug 2000 03:53:04 +0000 Subject: [PATCH] fixing warnings, removing need for JStrings to be copied for mClass git-svn-id: svn://10.0.0.236/trunk@75384 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/js2/jstypes.cpp | 25 ++++----- mozilla/js/js2/jstypes.h | 108 ++++++++++++++++++------------------ mozilla/js2/src/jstypes.cpp | 25 ++++----- mozilla/js2/src/jstypes.h | 108 ++++++++++++++++++------------------ 4 files changed, 130 insertions(+), 136 deletions(-) diff --git a/mozilla/js/js2/jstypes.cpp b/mozilla/js/js2/jstypes.cpp index 3f54f657fff..318d51ab4e2 100644 --- a/mozilla/js/js2/jstypes.cpp +++ b/mozilla/js/js2/jstypes.cpp @@ -76,8 +76,8 @@ struct ObjectFunctionEntry { }; -JSObject *JSObject::objectPrototypeObject = JSObject::initJSObject(); -String JSObject::ObjectString = widenCString("Object"); +JSObject* JSObject::ObjectPrototypeObject = JSObject::initJSObject(); +JSString* JSObject::ObjectString = new JSString("Object"); // This establishes the ur-prototype, there's a timing issue // here - the JSObject static initializers have to run before @@ -98,12 +98,9 @@ void JSObject::initObjectObject(JSScope *g) { JSNativeFunction *objCon = new JSNativeFunction(objectConstructor); - objCon->setProperty(widenCString("prototype"), JSValue(objectPrototypeObject)); + objCon->setProperty(widenCString("prototype"), JSValue(ObjectPrototypeObject)); - - - - g->setProperty(ObjectString, JSValue(objCon)); + g->setProperty(*ObjectString, JSValue(objCon)); } @@ -149,8 +146,8 @@ JSValue function_call(Context *cx, const JSValues& argv) -String JSFunction::FunctionString = widenCString("Function"); -JSObject *JSFunction::functionPrototypeObject = NULL; // the 'original Function prototype object' +JSString* JSFunction::FunctionString = new JSString("Function"); +JSObject* JSFunction::FunctionPrototypeObject = NULL; // the 'original Function prototype object' struct FunctionFunctionEntry { char *name; @@ -165,21 +162,21 @@ struct FunctionFunctionEntry { void JSFunction::initFunctionObject(JSScope *g) { // first build the Function Prototype Object - functionPrototypeObject = new JSNativeFunction(functionPrototypeFunction); + FunctionPrototypeObject = new JSNativeFunction(functionPrototypeFunction); for (int i = 0; i < sizeof(FunctionFunctions) / sizeof(FunctionFunctionEntry); i++) - functionPrototypeObject->setProperty(widenCString(FunctionFunctions[i].name), JSValue(new JSNativeFunction(FunctionFunctions[i].fn) ) ); + FunctionPrototypeObject->setProperty(widenCString(FunctionFunctions[i].name), JSValue(new JSNativeFunction(FunctionFunctions[i].fn) ) ); // now the Function Constructor Object JSNativeFunction *functionConstructorObject = new JSNativeFunction(function_constructor); - functionConstructorObject->setPrototype(functionPrototypeObject); + functionConstructorObject->setPrototype(FunctionPrototypeObject); functionConstructorObject->setProperty(widenCString("length"), JSValue((int32)1)); - functionConstructorObject->setProperty(widenCString("prototype"), JSValue(functionPrototypeObject)); + functionConstructorObject->setProperty(widenCString("prototype"), JSValue(FunctionPrototypeObject)); // This is interesting - had to use defineVariable here to specify a type because // when left as Any_Type (via setProperty), the Function predefined type interacted // badly with this value. (I think setProperty perhaps should have reset the entry // in mTypes) (?) - g->defineVariable(FunctionString, &Function_Type, JSValue(functionConstructorObject)); + g->defineVariable(*FunctionString, &Function_Type, JSValue(functionConstructorObject)); } /**************************************************************************************/ diff --git a/mozilla/js/js2/jstypes.h b/mozilla/js/js2/jstypes.h index b398aab7833..b14c9a68c39 100644 --- a/mozilla/js/js2/jstypes.h +++ b/mozilla/js/js2/jstypes.h @@ -59,9 +59,9 @@ namespace JSTypes { class JSObject; class JSArray; + class JSString; class JSFunction; class JSScope; - class JSString; class JSType; class Context; @@ -226,13 +226,13 @@ namespace JSTypes { JSString* mClass; // this is the internal [[Class]] property static JSObject *initJSObject(); - static String ObjectString; - static JSObject *objectPrototypeObject; + static JSString *ObjectString; + static JSObject *ObjectPrototypeObject; - void init(JSObject* prototype); + void init(JSObject* prototype) { mPrototype = prototype; mType = &Any_Type; mClass = ObjectString; } public: - JSObject() { init(objectPrototypeObject); } + JSObject() { init(ObjectPrototypeObject); } JSObject(JSValue &constructor) { init(constructor.object->getProperty(widenCString("prototype")).object); } JSObject(JSObject *prototype) { init(prototype); } @@ -362,49 +362,6 @@ namespace JSTypes { } }; - /** - * Private representation of a JS function. This simply - * holds a reference to the iCode module that is the - * compiled code of the function. - */ - class JSFunction : public JSObject { - static String FunctionString; - static JSObject *functionPrototypeObject; - ICodeModule* mICode; - protected: - JSFunction() : mICode(0) {} - - typedef JavaScript::gc_traits_finalizable traits; - typedef gc_allocator allocator; - - public: - static void JSFunction::initFunctionObject(JSScope *g); - - JSFunction(ICodeModule* iCode); - ~JSFunction(); - - void* operator new(size_t) { return allocator::allocate(1); } - - ICodeModule* getICode() { return mICode; } - virtual bool isNative() { return false; } - }; - - class JSNativeFunction : public JSFunction { - public: - typedef JSValue (*JSCode)(Context *cx, const JSValues& argv); - JSCode mCode; - JSNativeFunction(JSCode code) : mCode(code) {} - virtual bool isNative() { return true; } - }; - - class JSBinaryOperator : public JSFunction { - public: - typedef JSValue (*JSBinaryCode)(const JSValue& arg1, const JSValue& arg2); - JSBinaryCode mCode; - JSBinaryOperator(JSBinaryCode code) : mCode(code) {} - virtual bool isNative() { return true; } - }; - #if defined(XP_UNIX) // bastring.cc defines a funky operator new that assumes a byte-allocator. typedef string_char_traits JSCharTraits; @@ -447,6 +404,55 @@ namespace JSTypes { return f; } + /** + * Private representation of a JS function. This simply + * holds a reference to the iCode module that is the + * compiled code of the function. + */ + class JSFunction : public JSObject { + static JSString* FunctionString; + static JSObject* FunctionPrototypeObject; + ICodeModule* mICode; + protected: + JSFunction() : mICode(0) {} + + typedef JavaScript::gc_traits_finalizable traits; + typedef gc_allocator allocator; + + public: + static void JSFunction::initFunctionObject(JSScope *g); + + JSFunction(ICodeModule* iCode) + : JSObject(FunctionPrototypeObject), + mICode(iCode) + { + setClass(FunctionString); + } + + ~JSFunction(); + + void* operator new(size_t) { return allocator::allocate(1); } + + ICodeModule* getICode() { return mICode; } + virtual bool isNative() { return false; } + }; + + class JSNativeFunction : public JSFunction { + public: + typedef JSValue (*JSCode)(Context *cx, const JSValues& argv); + JSCode mCode; + JSNativeFunction(JSCode code) : mCode(code) {} + virtual bool isNative() { return true; } + }; + + class JSBinaryOperator : public JSFunction { + public: + typedef JSValue (*JSBinaryCode)(const JSValue& arg1, const JSValue& arg2); + JSBinaryCode mCode; + JSBinaryOperator(JSBinaryCode code) : mCode(code) {} + virtual bool isNative() { return true; } + }; + /** * Provides a set of nested scopes. */ @@ -561,12 +567,6 @@ namespace JSTypes { int32 distance(const JSType *other) const; }; - - inline void JSObject::init(JSObject* prototype) { mPrototype = prototype; mType = &Any_Type; mClass = new JSString(ObjectString); } - - inline JSFunction::JSFunction(ICodeModule* iCode) : mICode(iCode), JSObject(functionPrototypeObject) { setClass(new JSString(FunctionString)); } - - } /* namespace JSTypes */ } /* namespace JavaScript */ diff --git a/mozilla/js2/src/jstypes.cpp b/mozilla/js2/src/jstypes.cpp index 3f54f657fff..318d51ab4e2 100644 --- a/mozilla/js2/src/jstypes.cpp +++ b/mozilla/js2/src/jstypes.cpp @@ -76,8 +76,8 @@ struct ObjectFunctionEntry { }; -JSObject *JSObject::objectPrototypeObject = JSObject::initJSObject(); -String JSObject::ObjectString = widenCString("Object"); +JSObject* JSObject::ObjectPrototypeObject = JSObject::initJSObject(); +JSString* JSObject::ObjectString = new JSString("Object"); // This establishes the ur-prototype, there's a timing issue // here - the JSObject static initializers have to run before @@ -98,12 +98,9 @@ void JSObject::initObjectObject(JSScope *g) { JSNativeFunction *objCon = new JSNativeFunction(objectConstructor); - objCon->setProperty(widenCString("prototype"), JSValue(objectPrototypeObject)); + objCon->setProperty(widenCString("prototype"), JSValue(ObjectPrototypeObject)); - - - - g->setProperty(ObjectString, JSValue(objCon)); + g->setProperty(*ObjectString, JSValue(objCon)); } @@ -149,8 +146,8 @@ JSValue function_call(Context *cx, const JSValues& argv) -String JSFunction::FunctionString = widenCString("Function"); -JSObject *JSFunction::functionPrototypeObject = NULL; // the 'original Function prototype object' +JSString* JSFunction::FunctionString = new JSString("Function"); +JSObject* JSFunction::FunctionPrototypeObject = NULL; // the 'original Function prototype object' struct FunctionFunctionEntry { char *name; @@ -165,21 +162,21 @@ struct FunctionFunctionEntry { void JSFunction::initFunctionObject(JSScope *g) { // first build the Function Prototype Object - functionPrototypeObject = new JSNativeFunction(functionPrototypeFunction); + FunctionPrototypeObject = new JSNativeFunction(functionPrototypeFunction); for (int i = 0; i < sizeof(FunctionFunctions) / sizeof(FunctionFunctionEntry); i++) - functionPrototypeObject->setProperty(widenCString(FunctionFunctions[i].name), JSValue(new JSNativeFunction(FunctionFunctions[i].fn) ) ); + FunctionPrototypeObject->setProperty(widenCString(FunctionFunctions[i].name), JSValue(new JSNativeFunction(FunctionFunctions[i].fn) ) ); // now the Function Constructor Object JSNativeFunction *functionConstructorObject = new JSNativeFunction(function_constructor); - functionConstructorObject->setPrototype(functionPrototypeObject); + functionConstructorObject->setPrototype(FunctionPrototypeObject); functionConstructorObject->setProperty(widenCString("length"), JSValue((int32)1)); - functionConstructorObject->setProperty(widenCString("prototype"), JSValue(functionPrototypeObject)); + functionConstructorObject->setProperty(widenCString("prototype"), JSValue(FunctionPrototypeObject)); // This is interesting - had to use defineVariable here to specify a type because // when left as Any_Type (via setProperty), the Function predefined type interacted // badly with this value. (I think setProperty perhaps should have reset the entry // in mTypes) (?) - g->defineVariable(FunctionString, &Function_Type, JSValue(functionConstructorObject)); + g->defineVariable(*FunctionString, &Function_Type, JSValue(functionConstructorObject)); } /**************************************************************************************/ diff --git a/mozilla/js2/src/jstypes.h b/mozilla/js2/src/jstypes.h index b398aab7833..b14c9a68c39 100644 --- a/mozilla/js2/src/jstypes.h +++ b/mozilla/js2/src/jstypes.h @@ -59,9 +59,9 @@ namespace JSTypes { class JSObject; class JSArray; + class JSString; class JSFunction; class JSScope; - class JSString; class JSType; class Context; @@ -226,13 +226,13 @@ namespace JSTypes { JSString* mClass; // this is the internal [[Class]] property static JSObject *initJSObject(); - static String ObjectString; - static JSObject *objectPrototypeObject; + static JSString *ObjectString; + static JSObject *ObjectPrototypeObject; - void init(JSObject* prototype); + void init(JSObject* prototype) { mPrototype = prototype; mType = &Any_Type; mClass = ObjectString; } public: - JSObject() { init(objectPrototypeObject); } + JSObject() { init(ObjectPrototypeObject); } JSObject(JSValue &constructor) { init(constructor.object->getProperty(widenCString("prototype")).object); } JSObject(JSObject *prototype) { init(prototype); } @@ -362,49 +362,6 @@ namespace JSTypes { } }; - /** - * Private representation of a JS function. This simply - * holds a reference to the iCode module that is the - * compiled code of the function. - */ - class JSFunction : public JSObject { - static String FunctionString; - static JSObject *functionPrototypeObject; - ICodeModule* mICode; - protected: - JSFunction() : mICode(0) {} - - typedef JavaScript::gc_traits_finalizable traits; - typedef gc_allocator allocator; - - public: - static void JSFunction::initFunctionObject(JSScope *g); - - JSFunction(ICodeModule* iCode); - ~JSFunction(); - - void* operator new(size_t) { return allocator::allocate(1); } - - ICodeModule* getICode() { return mICode; } - virtual bool isNative() { return false; } - }; - - class JSNativeFunction : public JSFunction { - public: - typedef JSValue (*JSCode)(Context *cx, const JSValues& argv); - JSCode mCode; - JSNativeFunction(JSCode code) : mCode(code) {} - virtual bool isNative() { return true; } - }; - - class JSBinaryOperator : public JSFunction { - public: - typedef JSValue (*JSBinaryCode)(const JSValue& arg1, const JSValue& arg2); - JSBinaryCode mCode; - JSBinaryOperator(JSBinaryCode code) : mCode(code) {} - virtual bool isNative() { return true; } - }; - #if defined(XP_UNIX) // bastring.cc defines a funky operator new that assumes a byte-allocator. typedef string_char_traits JSCharTraits; @@ -447,6 +404,55 @@ namespace JSTypes { return f; } + /** + * Private representation of a JS function. This simply + * holds a reference to the iCode module that is the + * compiled code of the function. + */ + class JSFunction : public JSObject { + static JSString* FunctionString; + static JSObject* FunctionPrototypeObject; + ICodeModule* mICode; + protected: + JSFunction() : mICode(0) {} + + typedef JavaScript::gc_traits_finalizable traits; + typedef gc_allocator allocator; + + public: + static void JSFunction::initFunctionObject(JSScope *g); + + JSFunction(ICodeModule* iCode) + : JSObject(FunctionPrototypeObject), + mICode(iCode) + { + setClass(FunctionString); + } + + ~JSFunction(); + + void* operator new(size_t) { return allocator::allocate(1); } + + ICodeModule* getICode() { return mICode; } + virtual bool isNative() { return false; } + }; + + class JSNativeFunction : public JSFunction { + public: + typedef JSValue (*JSCode)(Context *cx, const JSValues& argv); + JSCode mCode; + JSNativeFunction(JSCode code) : mCode(code) {} + virtual bool isNative() { return true; } + }; + + class JSBinaryOperator : public JSFunction { + public: + typedef JSValue (*JSBinaryCode)(const JSValue& arg1, const JSValue& arg2); + JSBinaryCode mCode; + JSBinaryOperator(JSBinaryCode code) : mCode(code) {} + virtual bool isNative() { return true; } + }; + /** * Provides a set of nested scopes. */ @@ -561,12 +567,6 @@ namespace JSTypes { int32 distance(const JSType *other) const; }; - - inline void JSObject::init(JSObject* prototype) { mPrototype = prototype; mType = &Any_Type; mClass = new JSString(ObjectString); } - - inline JSFunction::JSFunction(ICodeModule* iCode) : mICode(iCode), JSObject(functionPrototypeObject) { setClass(new JSString(FunctionString)); } - - } /* namespace JSTypes */ } /* namespace JavaScript */