From be8e774ffe8d0a839ac8e59991efa39b2ed20e16 Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Tue, 27 Jun 2000 03:21:33 +0000 Subject: [PATCH] Fixed type management. git-svn-id: svn://10.0.0.236/trunk@73279 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/js2/jstypes.h | 38 ++++++++++++++++++++++++-------------- mozilla/js2/src/jstypes.h | 38 ++++++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/mozilla/js/js2/jstypes.h b/mozilla/js/js2/jstypes.h index 6bb75fd5739..19f74e4f229 100644 --- a/mozilla/js/js2/jstypes.h +++ b/mozilla/js/js2/jstypes.h @@ -442,26 +442,29 @@ namespace JSTypes { JSValue& setVariable(const String& name, const JSValue& value) { - return setProperty(name, value); + return (mProperties[name] = value); } JSValue& defineVariable(const String& name, JSType* type, const JSValue& value) { - if (type != &Any_Type) setType(name, type); - return setProperty(name, value); + if (type != &Any_Type) + mTypes[name] = type; + return (mProperties[name] = value); } JSValue& defineVariable(const String& name, JSType* type) { - if (type != &Any_Type) setType(name, type); - return setProperty(name, kUndefinedValue); + if (type != &Any_Type) + mTypes[name] = type; + return (mProperties[name] = kUndefinedValue); } void setType(const String& name, JSType* type) { - JSProperties::iterator i = mTypes.find(name); - if (i != mTypes.end()) - i->second = type; + // only type variables that are defined in this scope. + JSProperties::iterator i = mProperties.find(name); + if (i != mProperties.end()) + mTypes[name] = type; else if (mParent) mParent->setType(name, type); @@ -469,12 +472,19 @@ namespace JSTypes { JSType* getType(const String& name) { - JSProperties::const_iterator i = mTypes.find(name); - if (i != mTypes.end()) - return i->second.type; - if (mParent) - return mParent->getType(name); - return &Any_Type; + JSType* result = &Any_Type; + // only consider types for variables defined in this scope. + JSProperties::const_iterator i = mProperties.find(name); + if (i != mProperties.end()) { + i = mTypes.find(name); + if (i != mTypes.end()) + result = i->second.type; + } else { + // see if variable is defined in parent scope. + if (mParent) + result = mParent->getType(name); + } + return result; } JSValue& defineFunction(const String& name, ICodeModule* iCode) diff --git a/mozilla/js2/src/jstypes.h b/mozilla/js2/src/jstypes.h index 6bb75fd5739..19f74e4f229 100644 --- a/mozilla/js2/src/jstypes.h +++ b/mozilla/js2/src/jstypes.h @@ -442,26 +442,29 @@ namespace JSTypes { JSValue& setVariable(const String& name, const JSValue& value) { - return setProperty(name, value); + return (mProperties[name] = value); } JSValue& defineVariable(const String& name, JSType* type, const JSValue& value) { - if (type != &Any_Type) setType(name, type); - return setProperty(name, value); + if (type != &Any_Type) + mTypes[name] = type; + return (mProperties[name] = value); } JSValue& defineVariable(const String& name, JSType* type) { - if (type != &Any_Type) setType(name, type); - return setProperty(name, kUndefinedValue); + if (type != &Any_Type) + mTypes[name] = type; + return (mProperties[name] = kUndefinedValue); } void setType(const String& name, JSType* type) { - JSProperties::iterator i = mTypes.find(name); - if (i != mTypes.end()) - i->second = type; + // only type variables that are defined in this scope. + JSProperties::iterator i = mProperties.find(name); + if (i != mProperties.end()) + mTypes[name] = type; else if (mParent) mParent->setType(name, type); @@ -469,12 +472,19 @@ namespace JSTypes { JSType* getType(const String& name) { - JSProperties::const_iterator i = mTypes.find(name); - if (i != mTypes.end()) - return i->second.type; - if (mParent) - return mParent->getType(name); - return &Any_Type; + JSType* result = &Any_Type; + // only consider types for variables defined in this scope. + JSProperties::const_iterator i = mProperties.find(name); + if (i != mProperties.end()) { + i = mTypes.find(name); + if (i != mTypes.end()) + result = i->second.type; + } else { + // see if variable is defined in parent scope. + if (mParent) + result = mParent->getType(name); + } + return result; } JSValue& defineFunction(const String& name, ICodeModule* iCode)