return it->second;
}
+/**
+ * Retrieves a value from a dictionary.
+ *
+ * @param key The key whose value should be retrieved.
+ * @param result The value of the dictionary item (only set when the key exists)
+ * @returns true if the key exists, false otherwise.
+ */
+bool Dictionary::Get(const String& key, Value *result) const
+{
+ ASSERT(!OwnsLock());
+ ObjectLock olock(this);
+
+ std::map<String, Value>::const_iterator it = m_Data.find(key);
+
+ if (it == m_Data.end())
+ return false;
+
+ *result = it->second;
+ return true;
+}
+
/**
* Sets a value in the dictionary.
*
{ }
Value Get(const String& key) const;
+ bool Get(const String& key, Value *result) const;
void Set(const String& key, const Value& value);
bool Contains(const String& key) const;
ExpressionResult VariableExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
{
- if (frame.Locals && frame.Locals->Contains(m_Variable))
- return frame.Locals->Get(m_Variable);
+ Value value;
+
+ if (frame.Locals && frame.Locals->Get(m_Variable, &value))
+ return value;
else if (frame.Self.IsObject() && frame.Locals != static_cast<Object::Ptr>(frame.Self) && VMOps::HasField(frame.Self, m_Variable))
return VMOps::GetField(frame.Self, m_Variable, m_DebugInfo);
else
public:
static inline Value Variable(ScriptFrame& frame, const String& name, const DebugInfo& debugInfo = DebugInfo())
{
- if (frame.Locals && frame.Locals->Contains(name))
- return frame.Locals->Get(name);
+ Value value;
+ if (frame.Locals && frame.Locals->Get(name, &value))
+ return value;
else if (frame.Self.IsObject() && frame.Locals != static_cast<Object::Ptr>(frame.Self) && HasField(frame.Self, name))
return GetField(frame.Self, name, debugInfo);
else
Dictionary::Ptr dict = dynamic_pointer_cast<Dictionary>(object);
if (dict) {
- if (dict->Contains(field))
- return dict->Get(field);
+ Value value;
+ if (dict->Get(field, &value))
+ return value;
else
return GetPrototypeField(context, field, false, debugInfo);
}