本文整理汇总了C++中JSArray::get方法的典型用法代码示例。如果您正苦于以下问题:C++ JSArray::get方法的具体用法?C++ JSArray::get怎么用?C++ JSArray::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSArray
的用法示例。
在下文中一共展示了JSArray::get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: arrayProtoFuncToString
EncodedJSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
bool isRealArray = isJSArray(&exec->globalData(), thisValue);
if (!isRealArray && !thisValue.inherits(&JSArray::info))
return throwVMTypeError(exec);
JSArray* thisObj = asArray(thisValue);
HashSet<JSObject*>& arrayVisitedElements = exec->globalData().arrayVisitedElements;
if (arrayVisitedElements.size() >= MaxSmallThreadReentryDepth) {
if (arrayVisitedElements.size() >= exec->globalData().maxReentryDepth)
return throwVMError(exec, createStackOverflowError(exec));
}
bool alreadyVisited = !arrayVisitedElements.add(thisObj).second;
if (alreadyVisited)
return JSValue::encode(jsEmptyString(exec)); // return an empty string, avoiding infinite recursion.
//FYWEBKITMOD begin: setting up StringJoiner (while integrating r148721 due to fix of bug 114779). But not using 'ConstructFromLiteral' optimization which we dont have in our webkit.
unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
//WebCore::String separator(",", WebCore::String::ConstructFromLiteral);
//JSStringJoiner stringJoiner(separator, length);
JSStringJoiner stringJoiner(",", length);
//FYWEBKITMOD end
unsigned totalSize = length ? length - 1 : 0;
Vector<RefPtr<UString::Rep>, 256> strBuffer(length);
for (unsigned k = 0; k < length; k++) {
JSValue element;
if (isRealArray && thisObj->canGetIndex(k))
element = thisObj->getIndex(k);
else {
element = thisObj->get(exec, k);
//FYWEBKITMOD begin: added while integrating r148721 due to fix of bug 114779
if (exec->hadException())
return JSValue::encode(jsUndefined());
//FYWEBKITMOD end
}
//FYWEBKITMOD begin: removed (USE_FIX 1) old implementation which joined the strings manually and added usage of JSStringJoiner (while integrating r148721 due to fix of bug 114779)
#define USE_FIX 1 //keep this defined!!!
#ifdef USE_FIX
if (element.isUndefinedOrNull())
stringJoiner.append(WebCore::String()); //FYWEBKITMOD:
else
stringJoiner.append(element.toString(exec).rep()); //FYWEBKITMOD: using toString() instead of new toWTFString(). Only difference is an optimization used in the toWTFString() case.
if (exec->hadException())
return JSValue::encode(jsUndefined());
}
arrayVisitedElements.remove(thisObj);
return JSValue::encode(stringJoiner.build(exec));
#else
if (element.isUndefinedOrNull())
continue;
UString str = element.toString(exec);
strBuffer[k] = str.rep();
totalSize += str.size();
if (!strBuffer.data()) {
throwOutOfMemoryError(exec);
}
if (exec->hadException())
break;
}