Changeset 30109 in webkit


Ignore:
Timestamp:
Feb 9, 2008 10:09:42 AM (16 years ago)
Author:
Darin Adler
Message:

Reviewed by Mitz.

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.
Location:
trunk/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r30105 r30109  
     12008-02-09  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Mitz.
     4
     5        - http://bugs.webkit.org/show_bug.cgi?id=17256
     6          Change RegExp to start its ref count at 1, not 0
     7
     8        We'll want to do this to every RefCounted class, one at a time.
     9
     10        * kjs/nodes.h:
     11        (KJS::RegExpNode::RegExpNode): Use RegExp::create instead of new RegExp.
     12        * kjs/regexp.cpp:
     13        (KJS::RegExp::RegExp): Marked inline, set initial ref count to 1.
     14        (KJS::RegExp::create): Added. Calls new RegExp then adopts the initial ref.
     15        * kjs/regexp.h: Reformatted. Made the constructors private. Added static
     16        create functions that return objects already wrapped in PassRefPtr.
     17        * kjs/regexp_object.cpp:
     18        (KJS::regExpProtoFuncCompile): Use RegExp::create instead of new RegExp.
     19        (KJS::RegExpObjectImp::construct): Ditto.
     20        * kjs/string_object.cpp:
     21        (KJS::stringProtoFuncMatch): Ditto.
     22        (KJS::stringProtoFuncSearch): Ditto.
     23
    1242008-02-08  Oliver Hunt  <oliver@apple.com>
    225
  • trunk/JavaScriptCore/kjs/nodes.h

    r30105 r30109  
    335335    public:
    336336        RegExpNode(const UString& pattern, const UString& flags) KJS_FAST_CALL
    337             : m_regExp(new RegExp(pattern, flags))
     337            : m_regExp(RegExp::create(pattern, flags))
    338338        {
    339339        }
  • trunk/JavaScriptCore/kjs/regexp.cpp

    r28173 r30109  
    11// -*- c-basic-offset: 2 -*-
    22/*
    3  *  This file is part of the KDE libraries
    43 *  Copyright (C) 1999-2001, 2004 Harri Porten (porten@kde.org)
    5  *  Copyright (c) 2007, Apple Inc.
     4 *  Copyright (c) 2007, 2008 Apple Inc. All rights reserved.
    65 *
    76 *  This library is free software; you can redistribute it and/or
     
    2524
    2625#include "lexer.h"
     26#include <pcre/pcre.h>
    2727#include <stdio.h>
    2828#include <stdlib.h>
    2929#include <string.h>
    3030#include <wtf/Assertions.h>
     31#include <wtf/OwnArrayPtr.h>
    3132
    3233namespace KJS {
    3334
    34 RegExp::RegExp(const UString& pattern)
    35   : m_pattern(pattern)
     35inline RegExp::RegExp(const UString& pattern)
     36  : RefCounted<RegExp>(1)
     37  , m_pattern(pattern)
    3638  , m_flagBits(0)
    3739  , m_constructionError(0)
     
    4244}
    4345
    44 RegExp::RegExp(const UString& pattern, const UString& flags)
    45   : m_pattern(pattern)
     46PassRefPtr<RegExp> RegExp::create(const UString& pattern)
     47{
     48    return adoptRef(new RegExp(pattern));
     49}
     50
     51inline RegExp::RegExp(const UString& pattern, const UString& flags)
     52  : RefCounted<RegExp>(1)
     53  , m_pattern(pattern)
    4654  , m_flags(flags)
    4755  , m_flagBits(0)
     
    6977    m_regExp = jsRegExpCompile(reinterpret_cast<const ::UChar*>(pattern.data()), pattern.size(),
    7078        ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError);
     79}
     80
     81PassRefPtr<RegExp> RegExp::create(const UString& pattern, const UString& flags)
     82{
     83    return adoptRef(new RegExp(pattern, flags));
    7184}
    7285
  • trunk/JavaScriptCore/kjs/regexp.h

    r28468 r30109  
    1 // -*- c-basic-offset: 2 -*-
    21/*
    32 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
    4  *  Copyright (C) 2007 Apple Inc. All rights reserved.
     3 *  Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
    54 *
    65 *  This library is free software; you can redistribute it and/or
     
    2423
    2524#include "ustring.h"
    26 #include <pcre/pcre.h>
    27 #include <sys/types.h>
    28 #include <wtf/OwnArrayPtr.h>
     25#include <wtf/Forward.h>
    2926#include <wtf/RefCounted.h>
     27
     28struct JSRegExp;
    3029
    3130namespace KJS {
    3231
    33   class RegExp : public RefCounted<RegExp> {
    34   private:
    35     enum {
    36         Global = 1,
    37         IgnoreCase = 2,
    38         Multiline = 4
     32    class RegExp : public RefCounted<RegExp> {
     33    public:
     34        static PassRefPtr<RegExp> create(const UString& pattern);
     35        static PassRefPtr<RegExp> create(const UString& pattern, const UString& flags);
     36        ~RegExp();
     37
     38        bool global() const { return m_flagBits & Global; }
     39        bool ignoreCase() const { return m_flagBits & IgnoreCase; }
     40        bool multiline() const { return m_flagBits & Multiline; }
     41
     42        const UString& pattern() const { return m_pattern; }
     43        const UString& flags() const { return m_flags; }
     44
     45        bool isValid() const { return !m_constructionError; }
     46        const char* errorMessage() const { return m_constructionError; }
     47
     48        int match(const UString&, int offset, OwnArrayPtr<int>* ovector = 0);
     49        unsigned numSubpatterns() const { return m_numSubpatterns; }
     50
     51    private:
     52        RegExp(const UString& pattern);
     53        RegExp(const UString& pattern, const UString& flags);
     54
     55        void compile();
     56
     57        enum FlagBits { Global = 1, IgnoreCase = 2, Multiline = 4 };
     58
     59        UString m_pattern; // FIXME: Just decompile m_regExp instead of storing this.
     60        UString m_flags; // FIXME: Just decompile m_regExp instead of storing this.
     61        int m_flagBits;
     62        JSRegExp* m_regExp;
     63        const char* m_constructionError;
     64        unsigned m_numSubpatterns;
    3965    };
    40 
    41   public:
    42     RegExp(const UString& pattern);
    43     RegExp(const UString& pattern, const UString& flags);
    44     ~RegExp();
    45    
    46     bool global() const { return m_flagBits & Global; }
    47     bool ignoreCase() const { return m_flagBits & IgnoreCase; }
    48     bool multiline() const { return m_flagBits & Multiline; }
    49 
    50     const UString& pattern() const { return m_pattern; }
    51     const UString& flags() const { return m_flags; }
    52 
    53     bool isValid() const { return !m_constructionError; }
    54     const char* errorMessage() const { return m_constructionError; }
    55 
    56     int match(const UString&, int offset, OwnArrayPtr<int>* ovector = 0);
    57     unsigned numSubpatterns() const { return m_numSubpatterns; }
    58 
    59   private:
    60     void compile();
    61    
    62     // Data supplied by caller.
    63     UString m_pattern; // FIXME: Just decompile m_regExp instead of storing this.
    64     UString m_flags; // FIXME: Just decompile m_regExp instead of storing this.
    65     int m_flagBits;
    66 
    67     // Data supplied by PCRE.
    68     JSRegExp* m_regExp;
    69     const char* m_constructionError;
    70     unsigned m_numSubpatterns;
    71   };
    7266
    7367} // namespace
  • trunk/JavaScriptCore/kjs/regexp_object.cpp

    r30040 r30109  
    9696        UString pattern = args.isEmpty() ? UString("") : arg0->toString(exec);
    9797        UString flags = arg1->isUndefined() ? UString("") : arg1->toString(exec);
    98         regExp = new RegExp(pattern, flags);
     98        regExp = RegExp::create(pattern, flags);
    9999    }
    100100
     
    450450  UString flags = arg1->isUndefined() ? UString("") : arg1->toString(exec);
    451451 
    452   return createRegExpImp(exec, new RegExp(pattern, flags));
     452  return createRegExpImp(exec, RegExp::create(pattern, flags));
    453453}
    454454
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r30040 r30109  
    534534
    535535    UString u = s;
    536     RegExp* reg;
    537     RegExp* tmpReg = 0;
     536    RefPtr<RegExp> reg;
    538537    RegExpImp* imp = 0;
    539538    if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpImp::info)) {
     
    545544       *  replaced with the result of the expression new RegExp(regexp).
    546545       */
    547       reg = tmpReg = new RegExp(a0->toString(exec));
     546      reg = RegExp::create(a0->toString(exec));
    548547    }
    549548    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalGlobalObject()->regExpConstructor());
    550549    int pos;
    551550    int matchLength;
    552     regExpObj->performMatch(reg, u, 0, pos, matchLength);
     551    regExpObj->performMatch(reg.get(), u, 0, pos, matchLength);
    553552    JSValue* result;
    554553    if (!(reg->global())) {
     
    566565        lastIndex = pos;
    567566        pos += matchLength == 0 ? 1 : matchLength;
    568         regExpObj->performMatch(reg, u, pos, pos, matchLength);
     567        regExpObj->performMatch(reg.get(), u, pos, pos, matchLength);
    569568      }
    570569      if (imp)
     
    579578      }
    580579    }
    581     delete tmpReg;
    582580    return result;
    583581}
     
    591589
    592590    UString u = s;
    593     RegExp* reg;
    594     RegExp* tmpReg = 0;
    595     if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpImp::info)) {
    596       reg = static_cast<RegExpImp *>(a0)->regExp();
     591    RefPtr<RegExp> reg;
     592    if (a0->isObject() && static_cast<JSObject*>(a0)->inherits(&RegExpImp::info)) {
     593      reg = static_cast<RegExpImp*>(a0)->regExp();
    597594    } else {
    598595      /*
     
    601598       *  replaced with the result of the expression new RegExp(regexp).
    602599       */
    603       reg = tmpReg = new RegExp(a0->toString(exec));
     600      reg = RegExp::create(a0->toString(exec));
    604601    }
    605602    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalGlobalObject()->regExpConstructor());
    606603    int pos;
    607604    int matchLength;
    608     regExpObj->performMatch(reg, u, 0, pos, matchLength);
    609     delete tmpReg;
     605    regExpObj->performMatch(reg.get(), u, 0, pos, matchLength);
    610606    return jsNumber(pos);
    611607}
Note: See TracChangeset for help on using the changeset viewer.