本文整理汇总了C++中JSString::zoneFromAnyThread方法的典型用法代码示例。如果您正苦于以下问题:C++ JSString::zoneFromAnyThread方法的具体用法?C++ JSString::zoneFromAnyThread怎么用?C++ JSString::zoneFromAnyThread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSString
的用法示例。
在下文中一共展示了JSString::zoneFromAnyThread方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: key
bool
JSCompartment::wrap(JSContext* cx, MutableHandleString strp)
{
MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(this));
MOZ_ASSERT(cx->compartment() == this);
/* If the string is already in this compartment, we are done. */
JSString* str = strp;
if (str->zoneFromAnyThread() == zone())
return true;
/* If the string is an atom, we don't have to copy. */
if (str->isAtom()) {
MOZ_ASSERT(str->isPermanentAtom() || str->zone()->isAtomsZone());
return true;
}
/* Check the cache. */
RootedValue key(cx, StringValue(str));
if (WrapperMap::Ptr p = crossCompartmentWrappers.lookup(CrossCompartmentKey(key))) {
strp.set(p->value().get().toString());
return true;
}
/* No dice. Make a copy, and cache it. */
JSString* copy = CopyStringPure(cx, str);
if (!copy)
return false;
if (!putWrapper(cx, CrossCompartmentKey(key), StringValue(copy)))
return false;
strp.set(copy);
return true;
}