int IDBKey::compare(const IDBKey* other) const { ASSERT(other); if (m_type != other->m_type) return m_type > other->m_type ? -1 : 1; switch (m_type) { case ArrayType: for (size_t i = 0; i < m_array.size() && i < other->m_array.size(); ++i) { if (int result = m_array[i]->compare(other->m_array[i].get())) return result; } if (m_array.size() < other->m_array.size()) return -1; if (m_array.size() > other->m_array.size()) return 1; return 0; case StringType: return -codePointCompare(other->m_string, m_string); case DateType: return (m_date < other->m_date) ? -1 : (m_date > other->m_date) ? 1 : 0; case NumberType: return (m_number < other->m_number) ? -1 : (m_number > other-> m_number) ? 1 : 0; case InvalidType: case MinType: ASSERT_NOT_REACHED(); return 0; } ASSERT_NOT_REACHED(); return 0; }
int IndexNamesKey::compare(const IndexNamesKey& other) { ASSERT(m_objectStoreId >= 0); if (int x = compareInts(m_objectStoreId, other.m_objectStoreId)) return x; return codePointCompare(m_indexName, other.m_indexName); }
void JSModuleNamespaceObject::finishCreation(VM& vm, JSGlobalObject* globalObject, JSModuleRecord* moduleRecord, const IdentifierSet& exports) { Base::finishCreation(vm); ASSERT(inherits(info())); // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects // Quoted from the spec: // A List containing the String values of the exported names exposed as own properties of this object. // The list is ordered as if an Array of those String values had been sorted using Array.prototype.sort using SortCompare as comparefn. // // Sort the exported names by the code point order. Vector<UniquedStringImpl*> temporaryVector(exports.size(), nullptr); std::transform(exports.begin(), exports.end(), temporaryVector.begin(), [](const RefPtr<WTF::UniquedStringImpl>& ref) { return ref.get(); }); std::sort(temporaryVector.begin(), temporaryVector.end(), [] (UniquedStringImpl* lhs, UniquedStringImpl* rhs) { return codePointCompare(lhs, rhs) < 0; }); for (auto* identifier : temporaryVector) m_exports.add(identifier); m_moduleRecord.set(vm, this, moduleRecord); JSC_NATIVE_FUNCTION(vm.propertyNames->iteratorSymbol, moduleNamespaceObjectSymbolIterator, DontEnum, 0); putDirect(vm, vm.propertyNames->toStringTagSymbol, jsString(&vm, "Module"), DontEnum | ReadOnly); // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-getprototypeof // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-setprototypeof-v // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-isextensible // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-preventextensions preventExtensions(vm); }
MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtr<ExpressionVector> exprs) : m_restrictor(r) , m_mediaType(mediaType.lower()) , m_expressions(exprs) , m_ignored(false) { if (!m_expressions) { m_expressions = adoptPtr(new ExpressionVector); return; } std::sort(m_expressions->begin(), m_expressions->end(), [](const OwnPtr<MediaQueryExp>& a, const OwnPtr<MediaQueryExp>& b) { return codePointCompare(a->serialize(), b->serialize()) < 0; }); // remove all duplicated expressions String key; for (int i = m_expressions->size() - 1; i >= 0; --i) { // if not all of the expressions is valid the media query must be ignored. if (!m_ignored) m_ignored = !m_expressions->at(i)->isValid(); if (m_expressions->at(i)->serialize() == key) m_expressions->remove(i); else key = m_expressions->at(i)->serialize(); } }
int IDBKey::compare(const IDBKey& other) const { if (m_type != other.m_type) return m_type > other.m_type ? -1 : 1; switch (m_type) { case KeyType::Array: for (size_t i = 0; i < m_array.size() && i < other.m_array.size(); ++i) { if (int result = m_array[i]->compare(*other.m_array[i])) return result; } if (m_array.size() < other.m_array.size()) return -1; if (m_array.size() > other.m_array.size()) return 1; return 0; case KeyType::String: return -codePointCompare(other.m_string, m_string); case KeyType::Date: case KeyType::Number: return (m_number < other.m_number) ? -1 : ((m_number > other. m_number) ? 1 : 0); case KeyType::Invalid: case KeyType::Min: case KeyType::Max: ASSERT_NOT_REACHED(); return 0; } ASSERT_NOT_REACHED(); return 0; }
Vector<RefPtr<AudioTrack>> CaptionUserPreferences::sortedTrackListForMenu(AudioTrackList* trackList) { ASSERT(trackList); Vector<RefPtr<AudioTrack>> tracksForMenu; for (unsigned i = 0, length = trackList->length(); i < length; ++i) { AudioTrack* track = trackList->item(i); tracksForMenu.append(track); } std::sort(tracksForMenu.begin(), tracksForMenu.end(), [](const RefPtr<AudioTrack>& a, const RefPtr<AudioTrack>& b) { return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0; }); return tracksForMenu; }
int IDBKeyData::compare(const IDBKeyData& other) const { if (m_type == KeyType::Invalid) { if (other.m_type != KeyType::Invalid) return -1; if (other.m_type == KeyType::Invalid) return 0; } else if (other.m_type == KeyType::Invalid) return 1; // The IDBKey::m_type enum is in reverse sort order. if (m_type != other.m_type) return m_type < other.m_type ? 1 : -1; // The types are the same, so handle actual value comparison. switch (m_type) { case KeyType::Invalid: // Invalid type should have been fully handled above ASSERT_NOT_REACHED(); return 0; case KeyType::Array: for (size_t i = 0; i < m_arrayValue.size() && i < other.m_arrayValue.size(); ++i) { if (int result = m_arrayValue[i].compare(other.m_arrayValue[i])) return result; } if (m_arrayValue.size() < other.m_arrayValue.size()) return -1; if (m_arrayValue.size() > other.m_arrayValue.size()) return 1; return 0; case KeyType::String: return codePointCompare(m_stringValue, other.m_stringValue); case KeyType::Date: case KeyType::Number: if (m_numberValue == other.m_numberValue) return 0; return m_numberValue > other.m_numberValue ? 1 : -1; case KeyType::Max: case KeyType::Min: return 0; } ASSERT_NOT_REACHED(); return 0; }
int IDBKey::compare(const IDBKey& other) const { if (m_type != other.m_type) return m_type > other.m_type ? -1 : 1; switch (m_type) { case KeyType::Array: { auto& array = WTF::get<IDBKeyVector>(m_value); auto& otherArray = WTF::get<IDBKeyVector>(other.m_value); for (size_t i = 0; i < array.size() && i < otherArray.size(); ++i) { if (int result = array[i]->compare(*otherArray[i])) return result; } if (array.size() < otherArray.size()) return -1; if (array.size() > otherArray.size()) return 1; return 0; } case KeyType::Binary: return compareBinaryKeyData(WTF::get<ThreadSafeDataBuffer>(m_value), WTF::get<ThreadSafeDataBuffer>(other.m_value)); case KeyType::String: return -codePointCompare(WTF::get<String>(other.m_value), WTF::get<String>(m_value)); case KeyType::Date: case KeyType::Number: { auto number = WTF::get<double>(m_value); auto otherNumber = WTF::get<double>(other.m_value); return (number < otherNumber) ? -1 : ((number > otherNumber) ? 1 : 0); } case KeyType::Invalid: case KeyType::Min: case KeyType::Max: ASSERT_NOT_REACHED(); return 0; } ASSERT_NOT_REACHED(); return 0; }
Vector<RefPtr<TextTrack>> CaptionUserPreferences::sortedTrackListForMenu(TextTrackList* trackList) { ASSERT(trackList); Vector<RefPtr<TextTrack>> tracksForMenu; for (unsigned i = 0, length = trackList->length(); i < length; ++i) { TextTrack* track = trackList->item(i); const AtomicString& kind = track->kind(); if (kind == TextTrack::captionsKeyword() || kind == TextTrack::descriptionsKeyword() || kind == TextTrack::subtitlesKeyword()) tracksForMenu.append(track); } std::sort(tracksForMenu.begin(), tracksForMenu.end(), [](const RefPtr<TextTrack>& a, const RefPtr<TextTrack>& b) { return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0; }); tracksForMenu.insert(0, TextTrack::captionMenuOffItem()); tracksForMenu.insert(1, TextTrack::captionMenuAutomaticItem()); return tracksForMenu; }
int IDBKey::compare(const IDBKey* other) const { ASSERT(other); if (m_type != other->m_type) return m_type > other->m_type ? -1 : 1; switch (m_type) { case StringType: return -codePointCompare(other->m_string, m_string); case DateType: return (m_date < other->m_date) ? -1 : (m_date > other->m_date) ? 1 : 0; case NumberType: return (m_number < other->m_number) ? -1 : (m_number > other-> m_number) ? 1 : 0; case NullType: return 0; } ASSERT_NOT_REACHED(); return 0; }
int codePointCompare(const String& a, const String& b) { return codePointCompare(a.impl(), b.impl()); }
static bool expressionCompare(const OwnPtr<MediaQueryExp>& a, const OwnPtr<MediaQueryExp>& b) { return codePointCompare(a->serialize(), b->serialize()) < 0; }
static bool historyItemCompare(const RefPtr<WebCore::HistoryItem>& a, const RefPtr<WebCore::HistoryItem>& b) { return codePointCompare(a->urlString(), b->urlString()) < 0; }
int ObjectStoreNamesKey::compare(const ObjectStoreNamesKey& other) { return codePointCompare(m_objectStoreName, other.m_objectStoreName); }
int DatabaseNameKey::compare(const DatabaseNameKey& other) { if (int x = codePointCompare(m_origin, other.m_origin)) return x; return codePointCompare(m_databaseName, other.m_databaseName); }
static bool expressionCompare(const MediaQueryExp* a, const MediaQueryExp* b) { return codePointCompare(a->serialize(), b->serialize()) < 0; }
static bool textTrackCompare(const RefPtr<TextTrack>& a, const RefPtr<TextTrack>& b) { return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0; }