本文整理汇总了C++中JSValue::toThisJSString方法的典型用法代码示例。如果您正苦于以下问题:C++ JSValue::toThisJSString方法的具体用法?C++ JSValue::toThisJSString怎么用?C++ JSValue::toThisJSString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSValue
的用法示例。
在下文中一共展示了JSValue::toThisJSString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stringProtoFuncToUpperCase
JSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
{
JSString* sVal = thisValue.toThisJSString(exec);
const UString& s = sVal->value();
int sSize = s.size();
if (!sSize)
return sVal;
const UChar* sData = s.data();
Vector<UChar> buffer(sSize);
UChar ored = 0;
for (int i = 0; i < sSize; i++) {
UChar c = sData[i];
ored |= c;
buffer[i] = toASCIIUpper(c);
}
if (!(ored & ~0x7f))
return jsString(exec, UString(buffer.releaseBuffer(), sSize, false));
bool error;
int length = Unicode::toUpper(buffer.data(), sSize, sData, sSize, &error);
if (error) {
buffer.resize(length);
length = Unicode::toUpper(buffer.data(), length, sData, sSize, &error);
if (error)
return sVal;
}
if (length == sSize && memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0)
return sVal;
return jsString(exec, UString(buffer.releaseBuffer(), length, false));
}
示例2: objectProtoFuncToLocaleString
EncodedJSValue JSC_HOST_CALL objectProtoFuncToLocaleString(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
return JSValue::encode(thisValue.toThisJSString(exec));
}
示例3: stringProtoFuncReplace
JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
JSString* sourceVal = thisValue.toThisJSString(exec);
const UString& source = sourceVal->value();
JSValue pattern = args.at(0);
JSValue replacement = args.at(1);
UString replacementString;
CallData callData;
CallType callType = replacement.getCallData(callData);
if (callType == CallTypeNone)
replacementString = replacement.toString(exec);
if (pattern.isObject(&RegExpObject::info)) {
RegExp* reg = asRegExpObject(pattern)->regExp();
bool global = reg->global();
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
int lastIndex = 0;
int startPosition = 0;
Vector<UString::Range, 16> sourceRanges;
Vector<UString, 16> replacements;
// This is either a loop (if global is set) or a one-way (if not).
if (global && callType == CallTypeJS) {
// reg->numSubpatterns() + 1 for pattern args, + 2 for match start and sourceValue
int argCount = reg->numSubpatterns() + 1 + 2;
JSFunction* func = asFunction(replacement);
CachedCall cachedCall(exec, func, argCount, exec->exceptionSlot());
if (exec->hadException())
return jsNull();
while (true) {
int matchIndex;
int matchLen;
int* ovector;
regExpConstructor->performMatch(reg, source, startPosition, matchIndex, matchLen, &ovector);
if (matchIndex < 0)
break;
sourceRanges.append(UString::Range(lastIndex, matchIndex - lastIndex));
int completeMatchStart = ovector[0];
unsigned i = 0;
for (; i < reg->numSubpatterns() + 1; ++i) {
int matchStart = ovector[i * 2];
int matchLen = ovector[i * 2 + 1] - matchStart;
if (matchStart < 0)
cachedCall.setArgument(i, jsUndefined());
else
cachedCall.setArgument(i, jsSubstring(exec, source, matchStart, matchLen));
}
cachedCall.setArgument(i++, jsNumber(exec, completeMatchStart));
cachedCall.setArgument(i++, sourceVal);
cachedCall.setThis(exec->globalThisValue());
replacements.append(cachedCall.call().toString(cachedCall.newCallFrame()));
if (exec->hadException())
break;
lastIndex = matchIndex + matchLen;
startPosition = lastIndex;
// special case of empty match
if (matchLen == 0) {
startPosition++;
if (startPosition > source.size())
break;
}
}
} else {
do {
int matchIndex;
int matchLen;
int* ovector;
regExpConstructor->performMatch(reg, source, startPosition, matchIndex, matchLen, &ovector);
if (matchIndex < 0)
break;
sourceRanges.append(UString::Range(lastIndex, matchIndex - lastIndex));
if (callType != CallTypeNone) {
int completeMatchStart = ovector[0];
MarkedArgumentBuffer args;
for (unsigned i = 0; i < reg->numSubpatterns() + 1; ++i) {
int matchStart = ovector[i * 2];
int matchLen = ovector[i * 2 + 1] - matchStart;
if (matchStart < 0)
args.append(jsUndefined());
else
args.append(jsSubstring(exec, source, matchStart, matchLen));
}
args.append(jsNumber(exec, completeMatchStart));
//.........这里部分代码省略.........
示例4: objectProtoFuncToLocaleString
JSValue QT_FASTCALL objectProtoFuncToLocaleString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
{
return thisValue.toThisJSString(exec);
}