Example #1
0
static String notAFunctionSourceAppender(const String& originalMessage, const String& sourceText, RuntimeType type, ErrorInstance::SourceTextWhereErrorOccurred occurrence)
{
    ASSERT(type != TypeFunction);

    if (occurrence == ErrorInstance::FoundApproximateSource)
        return defaultApproximateSourceError(originalMessage, sourceText);

    ASSERT(occurrence == ErrorInstance::FoundExactSource);
    auto notAFunctionIndex = originalMessage.reverseFind("is not a function");
    RELEASE_ASSERT(notAFunctionIndex != notFound);
    StringView displayValue;
    if (originalMessage.is8Bit()) 
        displayValue = StringView(originalMessage.characters8(), notAFunctionIndex - 1);
    else
        displayValue = StringView(originalMessage.characters16(), notAFunctionIndex - 1);

    String base = functionCallBase(sourceText);
    StringBuilder builder;
    builder.append(base);
    builder.appendLiteral(" is not a function. (In '");
    builder.append(sourceText);
    builder.appendLiteral("', '");
    builder.append(base);
    builder.appendLiteral("' is ");
    if (type == TypeObject)
        builder.appendLiteral("an instance of ");
    builder.append(displayValue);
    builder.appendLiteral(")");

    return builder.toString();
}
Example #2
0
void MarkupAccumulator::appendCharactersReplacingEntities(StringBuilder& result, const String& source, unsigned offset, unsigned length, EntityMask entityMask)
{
    DEFINE_STATIC_LOCAL(const CString, ampReference, ("&"));
    DEFINE_STATIC_LOCAL(const CString, ltReference, ("<"));
    DEFINE_STATIC_LOCAL(const CString, gtReference, (">"));
    DEFINE_STATIC_LOCAL(const CString, quotReference, ("""));
    DEFINE_STATIC_LOCAL(const CString, nbspReference, (" "));

    static const EntityDescription entityMaps[] = {
        { '&', ampReference, EntityAmp },
        { '<', ltReference, EntityLt },
        { '>', gtReference, EntityGt },
        { '"', quotReference, EntityQuot },
        { noBreakSpace, nbspReference, EntityNbsp },
    };

    if (!(offset + length))
        return;

    ASSERT(offset + length <= source.length());
    if (source.is8Bit())
        appendCharactersReplacingEntitiesInternal(result, source.characters8() + offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask);
    else
        appendCharactersReplacingEntitiesInternal(result, source.characters16() + offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask);
}
Example #3
0
int nextBreakablePositionIgnoringNBSP(LazyLineBreakIterator& lazyBreakIterator, int pos)
{
    String string = lazyBreakIterator.string();
    if (string.is8Bit())
        return nextBreakablePosition<LChar, false>(lazyBreakIterator, string.characters8(), string.length(), pos);
    return nextBreakablePosition<UChar, false>(lazyBreakIterator, string.characters16(), string.length(), pos);
}
Example #4
0
EncodedJSValue regExpObjectSource(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
{
    String pattern = asRegExpObject(slotBase)->regExp()->pattern();
    if (pattern.is8Bit())
        return JSValue::encode(regExpObjectSourceInternal(exec, pattern, pattern.characters8(), pattern.length()));
    return JSValue::encode(regExpObjectSourceInternal(exec, pattern, pattern.characters16(), pattern.length()));
}
Example #5
0
static inline bool hasNonASCIIOrUpper(const String& string)
{
    unsigned length = string.length();

    if (string.is8Bit())
        return hasNonASCIIOrUpper(string.characters8(), length);
    return hasNonASCIIOrUpper(string.characters16(), length);
}
static bool propertyNameMatchesAttributeName(const String& propertyName, const String& attributeName)
{
    if (!attributeName.startsWith("data-"))
        return false;

    unsigned propertyLength = propertyName.length();
    unsigned attributeLength = attributeName.length();

    if (propertyName.is8Bit()) {
        if (attributeName.is8Bit())
            return propertyNameMatchesAttributeName(propertyName.characters8(), attributeName.characters8(), propertyLength, attributeLength);
        return propertyNameMatchesAttributeName(propertyName.characters8(), attributeName.characters16(), propertyLength, attributeLength);
    }

    if (attributeName.is8Bit())
        return propertyNameMatchesAttributeName(propertyName.characters16(), attributeName.characters8(), propertyLength, attributeLength);
    return propertyNameMatchesAttributeName(propertyName.characters16(), attributeName.characters16(), propertyLength, attributeLength);
}
Example #7
0
void WebView::getUrl(const uint16_t* &url, int &len)
{
    len = 0;
    if (!m_mainFrame || !core(m_mainFrame)->loader() || !core(m_mainFrame)->loader()->documentLoader())
        return;
    String uri = core(m_mainFrame)->loader()->documentLoader()->url().string();
    len = uri.length();
    url = uri.characters16();
}
Example #8
0
bool protocolIs(const String& url, const char* protocol)
{
    assertProtocolIsGood(protocol);
    if (url.isNull())
        return false;
    if (url.is8Bit())
        return url::FindAndCompareScheme(asURLChar8Subtle(url), url.length(), protocol, 0);
    return url::FindAndCompareScheme(url.characters16(), url.length(), protocol, 0);
}
Example #9
0
void KURL::init(const KURL& base, const String& relative, const WTF::TextEncoding* queryEncoding)
{
    if (!relative.isNull() && relative.is8Bit()) {
        StringUTF8Adaptor relativeUTF8(relative);
        init(base, relativeUTF8.data(), relativeUTF8.length(), queryEncoding);
    } else
        init(base, relative.characters16(), relative.length(), queryEncoding);
    initProtocolIsInHTTPFamily();
    initInnerURL();
}
Example #10
0
bool Color::parseHexColor(const String& name, RGBA32& rgb)
{
    unsigned length = name.length();

    if (!length)
        return false;
    if (name.is8Bit())
        return parseHexColor(name.characters8(), name.length(), rgb);
    return parseHexColor(name.characters16(), name.length(), rgb);
}
Example #11
0
static bool parseFontSize(const String& input, int& size)
{
    if (input.isEmpty())
        return false;

    if (input.is8Bit())
        return parseFontSize(input.characters8(), input.length(), size);

    return parseFontSize(input.characters16(), input.length(), size);
}
LinkHeaderSet::LinkHeaderSet(const String& header)
{
    if (header.isNull())
        return;

    if (header.is8Bit())
        init(header.characters8(), header.length());
    else
        init(header.characters16(), header.length());
}
Example #13
0
static inline void addCaseFoldedCharacters(StringHasher& hasher, const String& string)
{
    if (string.isEmpty())
        return;
    if (string.is8Bit()) {
        hasher.addCharacters<LChar, CaseFoldingHash::foldCase<LChar>>(string.characters8(), string.length());
        return;
    }
    hasher.addCharacters<UChar, CaseFoldingHash::foldCase<UChar>>(string.characters16(), string.length());
}
Example #14
0
Color::Color(const String& name)
{
    if (name[0] == '#') {
        if (name.is8Bit())
            m_valid = parseHexColor(name.characters8() + 1, name.length() - 1, m_color);
        else
            m_valid = parseHexColor(name.characters16() + 1, name.length() - 1, m_color);
    } else {
        setNamedColor(name);
    }
}
Example #15
0
void SpaceSplitString::Data::createVector(const String& string)
{
    unsigned length = string.length();

    if (string.is8Bit()) {
        createVector(string.characters8(), length);
        return;
    }

    createVector(string.characters16(), length);
}
Example #16
0
JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string)
{
    ExecState* exec = toJS(ctx);
    APIEntryShim entryShim(exec);
    String str = string->string();
    if (str.is8Bit()) {
        LiteralParser<LChar> parser(exec, str.characters8(), str.length(), StrictJSON);
        return toRef(exec, parser.tryLiteralParse());
    }
    LiteralParser<UChar> parser(exec, str.characters16(), str.length(), StrictJSON);
    return toRef(exec, parser.tryLiteralParse());
}
Example #17
0
bool parseNumberOptionalNumber(const String& string, float& x, float& y) {
    if (string.isEmpty())
        return false;

    if (string.is8Bit()) {
        const LChar* ptr = string.characters8();
        const LChar* end = ptr + string.length();
        return genericParseNumberOptionalNumber(ptr, end, x, y);
    }
    const UChar* ptr = string.characters16();
    const UChar* end = ptr + string.length();
    return genericParseNumberOptionalNumber(ptr, end, x, y);
}
Example #18
0
bool SVGViewSpec::parseViewSpec(const String& spec)
{
    if (spec.isEmpty() || !m_contextElement)
        return false;
    if (spec.is8Bit()) {
        const LChar* ptr = spec.characters8();
        const LChar* end = ptr + spec.length();
        return parseViewSpecInternal(ptr, end);
    }
    const UChar* ptr = spec.characters16();
    const UChar* end = ptr + spec.length();
    return parseViewSpecInternal(ptr, end);
}
bool parseNumberOrPercentage(const String& string, float& number)
{
    if (string.isEmpty())
        return false;

    if (string.is8Bit()) {
        const LChar* ptr = string.characters8();
        const LChar* end = ptr + string.length();
        return genericParseNumberOrPercentage(ptr, end, number);
    }
    const UChar* ptr = string.characters16();
    const UChar* end = ptr + string.length();
    return genericParseNumberOrPercentage(ptr, end, number);
}
Example #20
0
void TextRun::setText(const String& string)
{
    m_len = string.length();
    if (!m_len) {
        m_data.characters8 = 0;
        m_is8Bit = true;
        return;
    }
    m_is8Bit = string.is8Bit();
    if (m_is8Bit)
        m_data.characters8 = string.characters8();
    else
        m_data.characters16 = string.characters16();
}
Example #21
0
TextRun constructTextRun(const Font& font,
                         const String& string,
                         const ComputedStyle& style,
                         TextDirection direction,
                         TextRunFlags flags) {
  unsigned length = string.length();
  if (!length)
    return constructTextRunInternal(font, static_cast<const LChar*>(nullptr),
                                    length, style, direction, flags);
  if (string.is8Bit())
    return constructTextRunInternal(font, string.characters8(), length, style,
                                    direction, flags);
  return constructTextRunInternal(font, string.characters16(), length, style,
                                  direction, flags);
}
Example #22
0
void SVGStringList::setValueAsString(const String& data, ExceptionState&)
{
    // FIXME: Add more error checking and reporting.
    m_values.clear();
    if (data.isEmpty())
        return;
    if (data.is8Bit()) {
        const LChar* ptr = data.characters8();
        const LChar* end = ptr + data.length();
        parseInternal(ptr, end);
    } else {
        const UChar* ptr = data.characters16();
        const UChar* end = ptr + data.length();
        parseInternal(ptr, end);
    }
}
SVGParsingError SVGPointList::setValueAsString(const String& value)
{
    clear();

    if (value.isEmpty())
        return SVGParseStatus::NoError;

    if (value.is8Bit()) {
        const LChar* ptr = value.characters8();
        const LChar* end = ptr + value.length();
        return parse(ptr, end);
    }
    const UChar* ptr = value.characters16();
    const UChar* end = ptr + value.length();
    return parse(ptr, end);
}
Example #24
0
static float numericPrefix(const String& keyString, const String& valueString, Document* document, bool* ok = 0)
{
    size_t parsedLength;
    float value;
    if (valueString.is8Bit())
        value = charactersToFloat(valueString.characters8(), valueString.length(), parsedLength);
    else
        value = charactersToFloat(valueString.characters16(), valueString.length(), parsedLength);
    if (!parsedLength) {
        reportViewportWarning(document, UnrecognizedViewportArgumentValueError, valueString, keyString);
        if (ok)
            *ok = false;
        return 0;
    }
    if (parsedLength < valueString.length())
        reportViewportWarning(document, TruncatedViewportArgumentValueError, valueString, keyString);
    if (ok)
        *ok = true;
    return value;
}
static inline void addToHarfBuzzBufferInternal(hb_buffer_t* buffer,
    const FontDescription& fontDescription, const UChar* normalizedBuffer,
    unsigned normalizedBufferLength, unsigned startIndex, unsigned numCharacters)
{
    // TODO: Revisit whether we can always fill the hb_buffer_t with the
    // full run text, but only specify startIndex and numCharacters for the part
    // to be shaped. Then simplify/change the complicated index computations in
    // extractShapeResults().
    if (fontDescription.variant() == FontVariantSmallCaps) {
        String upperText = String(normalizedBuffer, normalizedBufferLength)
            .upper();
        // TextRun is 16 bit, therefore upperText is 16 bit, even after we call
        // makeUpper().
        ASSERT(!upperText.is8Bit());
        hb_buffer_add_utf16(buffer, toUint16(upperText.characters16()),
            normalizedBufferLength, startIndex, numCharacters);
    } else {
        hb_buffer_add_utf16(buffer, toUint16(normalizedBuffer),
            normalizedBufferLength, startIndex, numCharacters);
    }
}
void SVGPreserveAspectRatio::setValueAsString(const String& string, ExceptionState& exceptionState)
{
    setDefault();

    if (string.isEmpty())
        return;

    bool valid = false;
    if (string.is8Bit()) {
        const LChar* ptr = string.characters8();
        const LChar* end = ptr + string.length();
        valid = parseInternal(ptr, end, true);
    } else {
        const UChar* ptr = string.characters16();
        const UChar* end = ptr + string.length();
        valid = parseInternal(ptr, end, true);
    }

    if (!valid) {
        exceptionState.throwDOMException(SyntaxError, "The value provided ('" + string + "') is invalid.");
    }
}
Example #27
0
bool SVGFontData::applySVGGlyphSelection(WidthIterator& iterator, GlyphData& glyphData, bool mirror, unsigned currentCharacter, unsigned& advanceLength) const
{
    const TextRun& run = iterator.run();
    Vector<SVGGlyph::ArabicForm>& arabicForms = iterator.arabicForms();
    ASSERT(run.charactersLength() >= currentCharacter);

    // Associate text with arabic forms, if needed.
    String remainingTextInRun;

    if (run.is8Bit()) {
        remainingTextInRun = String(run.data8(currentCharacter), run.charactersLength() - currentCharacter);
        remainingTextInRun = Font::normalizeSpaces(remainingTextInRun.characters8(), remainingTextInRun.length());
    } else {
        remainingTextInRun = String(run.data16(currentCharacter), run.charactersLength() - currentCharacter);
        remainingTextInRun = Font::normalizeSpaces(remainingTextInRun.characters16(), remainingTextInRun.length());
    }

    if (mirror)
        remainingTextInRun = createStringWithMirroredCharacters(remainingTextInRun);
    if (!currentCharacter && arabicForms.isEmpty())
        arabicForms = charactersWithArabicForm(remainingTextInRun, mirror);

    SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement();
    ASSERT(svgFontFaceElement);

    SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontElement();
    ASSERT(associatedFontElement);

    RenderObject* renderObject = 0;
    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
        renderObject = &static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();

    String language;
    bool isVerticalText = false;
    Vector<String> altGlyphNames;

    if (renderObject) {
        RenderElement* parentRenderer = renderObject->isRenderElement() ? toRenderElement(renderObject) : renderObject->parent();
        ASSERT(parentRenderer);

        isVerticalText = parentRenderer->style().svgStyle().isVerticalWritingMode();
        if (Element* parentRendererElement = parentRenderer->element()) {
            language = parentRendererElement->getAttribute(XMLNames::langAttr);

            if (isSVGAltGlyphElement(parentRendererElement)) {
                SVGAltGlyphElement* altGlyph = toSVGAltGlyphElement(parentRendererElement);
                if (!altGlyph->hasValidGlyphElements(altGlyphNames))
                    altGlyphNames.clear();
            }
        }
    }

    Vector<SVGGlyph> glyphs;
    size_t altGlyphNamesSize = altGlyphNames.size();
    if (altGlyphNamesSize) {
        for (size_t index = 0; index < altGlyphNamesSize; ++index)
            associatedFontElement->collectGlyphsForGlyphName(altGlyphNames[index], glyphs);

        // Assign the unicodeStringLength now that its known.
        size_t glyphsSize = glyphs.size();
        for (size_t i = 0; i < glyphsSize; ++i)
            glyphs[i].unicodeStringLength = run.length();

        // Do not check alt glyphs for compatibility. Just return the first one.
        // Later code will fail if we do not do this and the glyph is incompatible.
        if (glyphsSize) {
            SVGGlyph& svgGlyph = glyphs[0];
            iterator.setLastGlyphName(svgGlyph.glyphName);
            glyphData.glyph = svgGlyph.tableEntry;
            advanceLength = svgGlyph.unicodeStringLength;
            return true;
        }
    } else
        associatedFontElement->collectGlyphsForString(remainingTextInRun, glyphs);

    size_t glyphsSize = glyphs.size();
    for (size_t i = 0; i < glyphsSize; ++i) {
        SVGGlyph& svgGlyph = glyphs[i];
        if (svgGlyph.isPartOfLigature)
            continue;
        if (!isCompatibleGlyph(svgGlyph, isVerticalText, language, arabicForms, currentCharacter, currentCharacter + svgGlyph.unicodeStringLength))
            continue;
        iterator.setLastGlyphName(svgGlyph.glyphName);
        glyphData.glyph = svgGlyph.tableEntry;
        advanceLength = svgGlyph.unicodeStringLength;
        return true;
    }

    iterator.setLastGlyphName(String());
    return false;
}
static bool resolveRelative(const KURL& base, const String& relative, url_canon::RawCanonOutput<2048>* buffer)
{
    // We use these low-level GURL functions to avoid converting back and forth from UTF-8 unnecessarily.
    url_parse::Parsed parsed;
    StringUTF8Adaptor baseUTF8(base.string());
    if (relative.is8Bit()) {
        StringUTF8Adaptor relativeUTF8(relative);
        return url_util::ResolveRelative(baseUTF8.data(), baseUTF8.length(), base.parsed(), relativeUTF8.data(), relativeUTF8.length(), 0, buffer, &parsed);
    }
    return url_util::ResolveRelative(baseUTF8.data(), baseUTF8.length(), base.parsed(), relative.characters16(), relative.length(), 0, buffer, &parsed);
}