Reviewed by Mitz.
- http://bugs.webkit.org/show_bug.cgi?id=17256
Change RegExp to start its ref count at 1, not 0
We'll want to do this to every RefCounted class, one at a time.
* kjs/nodes.h:
(KJS::RegExpNode::RegExpNode): Use RegExp::create instead of new RegExp.
* kjs/regexp.cpp:
(KJS::RegExp::RegExp): Marked inline, set initial ref count to 1.
(KJS::RegExp::create): Added. Calls new RegExp then adopts the initial ref.
* kjs/regexp.h: Reformatted. Made the constructors private. Added static
create functions that return objects already wrapped in PassRefPtr.
* kjs/regexp_object.cpp:
(KJS::regExpProtoFuncCompile): Use RegExp::create instead of new RegExp.
(KJS::RegExpObjectImp::construct): Ditto.
* kjs/string_object.cpp:
(KJS::stringProtoFuncMatch): Ditto.
(KJS::stringProtoFuncSearch): Ditto.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@30109 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/kjs/regexp.h b/JavaScriptCore/kjs/regexp.h
index 2c62085..1930ac9 100644
--- a/JavaScriptCore/kjs/regexp.h
+++ b/JavaScriptCore/kjs/regexp.h
@@ -1,7 +1,6 @@
-// -*- c-basic-offset: 2 -*-
/*
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
- * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,53 +22,48 @@
#define KJS_REGEXP_H
#include "ustring.h"
-#include <pcre/pcre.h>
-#include <sys/types.h>
-#include <wtf/OwnArrayPtr.h>
+#include <wtf/Forward.h>
#include <wtf/RefCounted.h>
+struct JSRegExp;
+
namespace KJS {
- class RegExp : public RefCounted<RegExp> {
- private:
- enum {
- Global = 1,
- IgnoreCase = 2,
- Multiline = 4
+ class RegExp : public RefCounted<RegExp> {
+ public:
+ static PassRefPtr<RegExp> create(const UString& pattern);
+ static PassRefPtr<RegExp> create(const UString& pattern, const UString& flags);
+ ~RegExp();
+
+ bool global() const { return m_flagBits & Global; }
+ bool ignoreCase() const { return m_flagBits & IgnoreCase; }
+ bool multiline() const { return m_flagBits & Multiline; }
+
+ const UString& pattern() const { return m_pattern; }
+ const UString& flags() const { return m_flags; }
+
+ bool isValid() const { return !m_constructionError; }
+ const char* errorMessage() const { return m_constructionError; }
+
+ int match(const UString&, int offset, OwnArrayPtr<int>* ovector = 0);
+ unsigned numSubpatterns() const { return m_numSubpatterns; }
+
+ private:
+ RegExp(const UString& pattern);
+ RegExp(const UString& pattern, const UString& flags);
+
+ void compile();
+
+ enum FlagBits { Global = 1, IgnoreCase = 2, Multiline = 4 };
+
+ UString m_pattern; // FIXME: Just decompile m_regExp instead of storing this.
+ UString m_flags; // FIXME: Just decompile m_regExp instead of storing this.
+ int m_flagBits;
+ JSRegExp* m_regExp;
+ const char* m_constructionError;
+ unsigned m_numSubpatterns;
};
- public:
- RegExp(const UString& pattern);
- RegExp(const UString& pattern, const UString& flags);
- ~RegExp();
-
- bool global() const { return m_flagBits & Global; }
- bool ignoreCase() const { return m_flagBits & IgnoreCase; }
- bool multiline() const { return m_flagBits & Multiline; }
-
- const UString& pattern() const { return m_pattern; }
- const UString& flags() const { return m_flags; }
-
- bool isValid() const { return !m_constructionError; }
- const char* errorMessage() const { return m_constructionError; }
-
- int match(const UString&, int offset, OwnArrayPtr<int>* ovector = 0);
- unsigned numSubpatterns() const { return m_numSubpatterns; }
-
- private:
- void compile();
-
- // Data supplied by caller.
- UString m_pattern; // FIXME: Just decompile m_regExp instead of storing this.
- UString m_flags; // FIXME: Just decompile m_regExp instead of storing this.
- int m_flagBits;
-
- // Data supplied by PCRE.
- JSRegExp* m_regExp;
- const char* m_constructionError;
- unsigned m_numSubpatterns;
- };
-
} // namespace
#endif