Returns true if the array contains the specified value, false otherwise.
+### Array#freeze <a id="array-freeze"></a>
+
+Signature:
+
+ function freeze()
+
+Disallows further modifications to this array. Trying to modify the array will result in an exception.
+
### Array#len <a id="array-len"></a>
Signature:
Returns true if a dictionary item with the specified `key` exists, false otherwise.
+### Dictionary#freeze <a id="dictionary-freeze"></a>
+
+Signature:
+
+ function freeze()
+
+Disallows further modifications to this dictionary. Trying to modify the dictionary will result in an exception.
+
### Dictionary#len <a id="dictionary-len"></a>
Signature:
return Array::FromSet(result);
}
+static void ArrayFreeze()
+{
+ ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
+ Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
+ self->Freeze();
+}
+
Object::Ptr Array::GetPrototype()
{
static Dictionary::Ptr prototype = new Dictionary({
{ "filter", new Function("Array#filter", ArrayFilter, { "func" }, true) },
{ "any", new Function("Array#any", ArrayAny, { "func" }, true) },
{ "all", new Function("Array#all", ArrayAll, { "func" }, true) },
- { "unique", new Function("Array#unique", ArrayUnique, {}, true) }
+ { "unique", new Function("Array#unique", ArrayUnique, {}, true) },
+ { "freeze", new Function("Array#freeze", ArrayFreeze, {}) }
});
return prototype;
{
ObjectLock olock(this);
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
m_Data.at(index) = value;
}
{
ObjectLock olock(this);
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
m_Data.at(index).Swap(value);
}
{
ObjectLock olock(this);
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
m_Data.push_back(std::move(value));
}
ASSERT(index <= m_Data.size());
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
m_Data.insert(m_Data.begin() + index, std::move(value));
}
{
ObjectLock olock(this);
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
m_Data.erase(m_Data.begin() + index);
}
{
ASSERT(OwnsLock());
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
m_Data.erase(it);
}
{
ObjectLock olock(this);
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
m_Data.resize(newSize);
}
{
ObjectLock olock(this);
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
m_Data.clear();
}
{
ObjectLock olock(this);
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
m_Data.reserve(newSize);
}
ObjectLock olock(this);
ObjectLock xlock(dest);
+ if (dest->m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
std::copy(m_Data.begin(), m_Data.end(), std::back_inserter(dest->m_Data));
}
void Array::Sort()
{
ObjectLock olock(this);
+
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be modified."));
+
std::sort(m_Data.begin(), m_Data.end());
}
return msgbuf.str();
}
+void Array::Freeze()
+{
+ ObjectLock olock(this);
+ m_Frozen = true;
+}
+
Value Array::GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const
{
int index;
String ToString() const override;
+ void Freeze();
+
Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
void SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo) override;
private:
std::vector<Value> m_Data; /**< The data for the array. */
+ bool m_Frozen{false};
};
Array::Iterator begin(const Array::Ptr& x);
return new Array(std::move(values));
}
+static void DictionaryFreeze()
+{
+ ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
+ Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
+ self->Freeze();
+}
+
Object::Ptr Dictionary::GetPrototype()
{
static Dictionary::Ptr prototype = new Dictionary({
{ "contains", new Function("Dictionary#contains", DictionaryContains, { "key" }, true) },
{ "shallow_clone", new Function("Dictionary#shallow_clone", DictionaryShallowClone, {}, true) },
{ "keys", new Function("Dictionary#keys", DictionaryKeys, {}, true) },
- { "values", new Function("Dictionary#values", DictionaryValues, {}, true) }
+ { "values", new Function("Dictionary#values", DictionaryValues, {}, true) },
+ { "freeze", new Function("Dictionary#freeze", DictionaryFreeze, {}) }
});
return prototype;
{
ObjectLock olock(this);
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be modified."));
+
m_Data[key] = std::move(value);
}
{
ASSERT(OwnsLock());
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be modified."));
+
m_Data.erase(it);
}
{
ObjectLock olock(this);
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be modified."));
+
Dictionary::Iterator it;
it = m_Data.find(key);
{
ObjectLock olock(this);
+ if (m_Frozen)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be modified."));
+
m_Data.clear();
}
return msgbuf.str();
}
+void Dictionary::Freeze()
+{
+ ObjectLock olock(this);
+ m_Frozen = true;
+}
+
Value Dictionary::GetFieldByName(const String& field, bool, const DebugInfo& debugInfo) const
{
Value value;
String ToString() const override;
+ void Freeze();
+
Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
void SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo) override;
bool HasOwnField(const String& field) const override;
private:
std::map<String, Value> m_Data; /**< The data for the dictionary. */
+ bool m_Frozen{false};
};
Dictionary::Iterator begin(const Dictionary::Ptr& x);