Changeset 34361 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Jun 4, 2008, 11:10:15 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin.

Fix JSClassCreate to work with old JSCore API threading model.

No change on SunSpider.

  • API/JSClassRef.cpp: (OpaqueJSClass::OpaqueJSClass): Since JSClass is constructed without a context, there is no way for it to create Identifiers. Also, added initializeThreading(), just for good measure.
  • API/JSCallbackObjectFunctions.h: (KJS::::getPropertyNames): Make an Identifier out of the string here, because propertyNames.add() needs that.
  • kjs/identifier.cpp:
  • kjs/identifier.h: (KJS::Identifier::equal):
  • kjs/ustring.cpp: (KJS::equal): Moved equal() from identifier.h to ustring.h, because it's not really about Identifiers, and to make it possible to use it from StrHash. Include StrHash.h from ustring.h to avoid having the behavior depend on headers that happen to be included.
  • wtf/StrHash.h: Removed.
  • kjs/ustring.h: Made RefPtr<UString::Rep> use the same default hash as UString::Rep* (it used to default to pointer equality). Moved the whole StrHash header into ustring.h.
  • JavaScriptCore.exp: Export equal() for WebCore use (this StrHash is used in c_class.cpp, jni_class.cpp, and npruntime.cpp).
Location:
trunk/JavaScriptCore/kjs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/identifier.cpp

    r32799 r34361  
    2929#include <wtf/FastMalloc.h>
    3030#include <wtf/HashSet.h>
    31 #include <wtf/StrHash.h>
    3231#if USE(MULTIPLE_THREADS)
    3332#include <wtf/ThreadSpecific.h>
     
    112111        return false;
    113112    const UChar *d = r->data();
    114     for (int i = 0; i != length; ++i)
    115         if (d[i] != s[i])
    116             return false;
    117     return true;
    118 }
    119 
    120 bool Identifier::equal(const UString::Rep *r, const UString::Rep *b)
    121 {
    122     int length = r->len;
    123     if (length != b->len)
    124         return false;
    125     const UChar *d = r->data();
    126     const UChar *s = b->data();
    127113    for (int i = 0; i != length; ++i)
    128114        if (d[i] != s[i])
  • trunk/JavaScriptCore/kjs/identifier.h

    r32222 r34361  
    6666        static bool equal(const UString::Rep*, const char*);
    6767        static bool equal(const UString::Rep*, const UChar*, int length);
    68         static bool equal(const UString::Rep*, const UString::Rep*);
     68        static bool equal(const UString::Rep* a, const UString::Rep* b) { return KJS::equal(a, b); }
    6969
    7070        static PassRefPtr<UString::Rep> add(const char*);
  • trunk/JavaScriptCore/kjs/ustring.cpp

    r33941 r34361  
    13161316}
    13171317
     1318bool equal(const UString::Rep* r, const UString::Rep* b)
     1319{
     1320    int length = r->len;
     1321    if (length != b->len)
     1322        return false;
     1323    const UChar* d = r->data();
     1324    const UChar* s = b->data();
     1325    for (int i = 0; i != length; ++i)
     1326        if (d[i] != s[i])
     1327            return false;
     1328    return true;
     1329}
     1330
    13181331CString UString::UTF8String(bool strict) const
    13191332{
  • trunk/JavaScriptCore/kjs/ustring.h

    r33941 r34361  
    382382  int compare(const UString &, const UString &);
    383383
     384  bool equal(const UString::Rep*, const UString::Rep*);
     385
     386
    384387inline UString::UString()
    385388  : m_rep(&Rep::null)
     
    430433}
    431434
    432 } // namespace
     435} // namespace KJS
     436
     437
     438namespace WTF {
     439
     440    template<typename T> struct DefaultHash;
     441    template<typename T> struct StrHash;
     442
     443    template<> struct StrHash<KJS::UString::Rep*> {
     444        static unsigned hash(const KJS::UString::Rep* key) { return key->hash(); }
     445        static bool equal(const KJS::UString::Rep* a, const KJS::UString::Rep* b) { return KJS::equal(a, b); }
     446        static const bool safeToCompareToEmptyOrDeleted = false;
     447    };
     448
     449    template<> struct StrHash<RefPtr<KJS::UString::Rep> > : public StrHash<KJS::UString::Rep*> {
     450        using StrHash<KJS::UString::Rep*>::hash;
     451        static unsigned hash(const RefPtr<KJS::UString::Rep>& key) { return key->hash(); }
     452        using StrHash<KJS::UString::Rep*>::equal;
     453        static bool equal(const RefPtr<KJS::UString::Rep>& a, const RefPtr<KJS::UString::Rep>& b) { return KJS::equal(a.get(), b.get()); }
     454        static bool equal(const KJS::UString::Rep* a, const RefPtr<KJS::UString::Rep>& b) { return KJS::equal(a, b.get()); }
     455        static bool equal(const RefPtr<KJS::UString::Rep>& a, const KJS::UString::Rep* b) { return KJS::equal(a.get(), b); }
     456
     457        static const bool safeToCompareToEmptyOrDeleted = false;
     458    };
     459
     460    template<> struct DefaultHash<KJS::UString::Rep*> {
     461        typedef StrHash<KJS::UString::Rep*> Hash;
     462    };
     463
     464    template<> struct DefaultHash<RefPtr<KJS::UString::Rep> > {
     465        typedef StrHash<RefPtr<KJS::UString::Rep> > Hash;
     466    };
     467} // namespace WTF
    433468
    434469#endif
Note: See TracChangeset for help on using the changeset viewer.