TiValue TiString::replaceCharacter(TiExcState* exec, UChar character, const UString& replacement) { if (!isRope()) { unsigned matchPosition = m_value.find(character); if (matchPosition == UString::NotFound) return TiValue(this); return jsString(exec, m_value.substr(0, matchPosition), replacement, m_value.substr(matchPosition + 1)); } RopeIterator end; // Count total fibers and find matching string. size_t fiberCount = 0; UStringImpl* matchString = 0; int matchPosition = -1; for (RopeIterator it(m_other.m_fibers, m_fiberCount); it != end; ++it) { ++fiberCount; if (matchString) continue; UStringImpl* string = *it; matchPosition = string->find(character); if (matchPosition == -1) continue; matchString = string; } if (!matchString) return this; RopeBuilder builder(replacement.size() ? fiberCount + 2 : fiberCount + 1); if (UNLIKELY(builder.isOutOfMemory())) return throwOutOfMemoryError(exec); for (RopeIterator it(m_other.m_fibers, m_fiberCount); it != end; ++it) { UStringImpl* string = *it; if (string != matchString) { builder.append(UString(string)); continue; } builder.append(UString(string).substr(0, matchPosition)); if (replacement.size()) builder.append(replacement); builder.append(UString(string).substr(matchPosition + 1)); matchString = 0; } TiGlobalData* globalData = &exec->globalData(); return TiValue(new (globalData) TiString(globalData, builder.release())); }
void Profiler::willExecute(TiExcState* exec, const UString& sourceURL, int startingLineNumber) { ASSERT(!m_currentProfiles.isEmpty()); CallIdentifier callIdentifier = createCallIdentifier(exec, TiValue(), sourceURL, startingLineNumber); dispatchFunctionToProfiles(m_currentProfiles, &ProfileGenerator::willExecute, callIdentifier, exec->lexicalGlobalObject()->profileGroup()); }
TiValue TiPropertyNameIterator::get(TiExcState* exec, TiObject* base, size_t i) { TiValue identifier = m_jsStrings[i].get(); if (m_cachedStructure.get() == base->structure() && m_cachedPrototypeChain.get() == base->structure()->prototypeChain(exec)) return identifier; if (!base->hasProperty(exec, Identifier(exec, asString(identifier)->value(exec)))) return TiValue(); return identifier; }
static ALWAYS_INLINE TiValue callDefaultValueFunction(TiExcState* exec, const TiObject* object, const Identifier& propertyName) { TiValue function = object->get(exec, propertyName); CallData callData; CallType callType = function.getCallData(callData); if (callType == CallTypeNone) return exec->exception(); // Prevent "toString" and "valueOf" from observing execution if an exception // is pending. if (exec->hadException()) return exec->exception(); TiValue result = call(exec, function, callType, callData, const_cast<TiObject*>(object), exec->emptyList()); ASSERT(!result.isGetterSetter()); if (exec->hadException()) return exec->exception(); if (result.isObject()) return TiValue(); return result; }
TiValue jsNumberCell(TiExcState*, double) { ASSERT_NOT_REACHED(); return TiValue(); }
void Profiler::exceptionUnwind(TiExcState* handlerCallFrame) { ASSERT(!m_currentProfiles.isEmpty()); dispatchFunctionToProfiles(handlerCallFrame, m_currentProfiles, &ProfileGenerator::exceptionUnwind, createCallIdentifier(handlerCallFrame, TiValue(), "", 0), handlerCallFrame->lexicalGlobalObject()->profileGroup()); }
void Profiler::didExecute(TiExcState* callerCallFrame, const UString& sourceURL, int startingLineNumber) { ASSERT(!m_currentProfiles.isEmpty()); dispatchFunctionToProfiles(callerCallFrame, m_currentProfiles, &ProfileGenerator::didExecute, createCallIdentifier(callerCallFrame, TiValue(), sourceURL, startingLineNumber), callerCallFrame->lexicalGlobalObject()->profileGroup()); }