Home | History | Annotate | Download | only in runtime
      1 /*
      2  *  Copyright (C) 1999-2000 Harri Porten (porten (at) kde.org)
      3  *  Copyright (C) 2003, 2007, 2008 Apple Inc. All Rights Reserved.
      4  *
      5  *  This library is free software; you can redistribute it and/or
      6  *  modify it under the terms of the GNU Lesser General Public
      7  *  License as published by the Free Software Foundation; either
      8  *  version 2 of the License, or (at your option) any later version.
      9  *
     10  *  This library is distributed in the hope that it will be useful,
     11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  *  Lesser General Public License for more details.
     14  *
     15  *  You should have received a copy of the GNU Lesser General Public
     16  *  License along with this library; if not, write to the Free Software
     17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     18  *
     19  */
     20 
     21 #ifndef RegExpObject_h
     22 #define RegExpObject_h
     23 
     24 #include "JSObjectWithGlobalObject.h"
     25 #include "RegExp.h"
     26 
     27 namespace JSC {
     28 
     29     class RegExpObject : public JSObjectWithGlobalObject {
     30     public:
     31         typedef JSObjectWithGlobalObject Base;
     32 
     33         RegExpObject(JSGlobalObject*, Structure*, NonNullPassRefPtr<RegExp>);
     34         virtual ~RegExpObject();
     35 
     36         void setRegExp(PassRefPtr<RegExp> r) { d->regExp = r; }
     37         RegExp* regExp() const { return d->regExp.get(); }
     38 
     39         void setLastIndex(size_t lastIndex)
     40         {
     41             d->lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
     42         }
     43         void setLastIndex(JSGlobalData& globalData, JSValue lastIndex)
     44         {
     45             d->lastIndex.set(globalData, this, lastIndex);
     46         }
     47         JSValue getLastIndex() const
     48         {
     49             return d->lastIndex.get();
     50         }
     51 
     52         JSValue test(ExecState*);
     53         JSValue exec(ExecState*);
     54 
     55         virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
     56         virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
     57         virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
     58 
     59         static JS_EXPORTDATA const ClassInfo s_info;
     60 
     61         static Structure* createStructure(JSGlobalData& globalData, JSValue prototype)
     62         {
     63             return Structure::create(globalData, prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
     64         }
     65 
     66     protected:
     67         static const unsigned StructureFlags = OverridesMarkChildren | OverridesGetOwnPropertySlot | JSObjectWithGlobalObject::StructureFlags;
     68 
     69     private:
     70         virtual void markChildren(MarkStack&);
     71 
     72         bool match(ExecState*);
     73 
     74         struct RegExpObjectData {
     75             WTF_MAKE_FAST_ALLOCATED;
     76         public:
     77             RegExpObjectData(NonNullPassRefPtr<RegExp> regExp)
     78                 : regExp(regExp)
     79             {
     80                 lastIndex.setWithoutWriteBarrier(jsNumber(0));
     81             }
     82 
     83             RefPtr<RegExp> regExp;
     84             WriteBarrier<Unknown> lastIndex;
     85         };
     86 #if COMPILER(MSVC)
     87         friend void WTF::deleteOwnedPtr<RegExpObjectData>(RegExpObjectData*);
     88 #endif
     89         OwnPtr<RegExpObjectData> d;
     90     };
     91 
     92     RegExpObject* asRegExpObject(JSValue);
     93 
     94     inline RegExpObject* asRegExpObject(JSValue value)
     95     {
     96         ASSERT(asObject(value)->inherits(&RegExpObject::s_info));
     97         return static_cast<RegExpObject*>(asObject(value));
     98     }
     99 
    100 } // namespace JSC
    101 
    102 #endif // RegExpObject_h
    103