本文整理汇总了C++中JSRuntime::pod_realloc方法的典型用法代码示例。如果您正苦于以下问题:C++ JSRuntime::pod_realloc方法的具体用法?C++ JSRuntime::pod_realloc怎么用?C++ JSRuntime::pod_realloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSRuntime
的用法示例。
在下文中一共展示了JSRuntime::pod_realloc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PodZero
uint32_t
Table::grow(uint32_t delta, JSContext* cx)
{
// This isn't just an optimization: movingGrowable() assumes that
// onMovingGrowTable does not fire when length == maximum.
if (!delta)
return length_;
uint32_t oldLength = length_;
CheckedInt<uint32_t> newLength = oldLength;
newLength += delta;
if (!newLength.isValid() || newLength.value() > MaxTableLength)
return -1;
if (maximum_ && newLength.value() > maximum_.value())
return -1;
MOZ_ASSERT(movingGrowable());
JSRuntime* rt = cx; // Use JSRuntime's MallocProvider to avoid throwing.
// Note that realloc does not release array_'s pointee (which is returned by
// externalArray()) on failure which is exactly what we need here.
ExternalTableElem* newArray = rt->pod_realloc(externalArray(), length_, newLength.value());
if (!newArray)
return -1;
Unused << array_.release();
array_.reset((uint8_t*)newArray);
// Realloc does not zero the delta for us.
PodZero(newArray + length_, delta);
length_ = newLength.value();
if (observers_.initialized()) {
for (InstanceSet::Range r = observers_.all(); !r.empty(); r.popFront())
r.front()->instance().onMovingGrowTable();
}
return oldLength;
}