Changeset 30109 in webkit
- Timestamp:
- Feb 9, 2008, 10:09:42 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r30105 r30109 1 2008-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 1 24 2008-02-08 Oliver Hunt <oliver@apple.com> 2 25 -
trunk/JavaScriptCore/kjs/nodes.h
r30105 r30109 335 335 public: 336 336 RegExpNode(const UString& pattern, const UString& flags) KJS_FAST_CALL 337 : m_regExp( new RegExp(pattern, flags))337 : m_regExp(RegExp::create(pattern, flags)) 338 338 { 339 339 } -
trunk/JavaScriptCore/kjs/regexp.cpp
r28173 r30109 1 1 // -*- c-basic-offset: 2 -*- 2 2 /* 3 * This file is part of the KDE libraries4 3 * 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. 6 5 * 7 6 * This library is free software; you can redistribute it and/or … … 25 24 26 25 #include "lexer.h" 26 #include <pcre/pcre.h> 27 27 #include <stdio.h> 28 28 #include <stdlib.h> 29 29 #include <string.h> 30 30 #include <wtf/Assertions.h> 31 #include <wtf/OwnArrayPtr.h> 31 32 32 33 namespace KJS { 33 34 34 RegExp::RegExp(const UString& pattern) 35 : m_pattern(pattern) 35 inline RegExp::RegExp(const UString& pattern) 36 : RefCounted<RegExp>(1) 37 , m_pattern(pattern) 36 38 , m_flagBits(0) 37 39 , m_constructionError(0) … … 42 44 } 43 45 44 RegExp::RegExp(const UString& pattern, const UString& flags) 45 : m_pattern(pattern) 46 PassRefPtr<RegExp> RegExp::create(const UString& pattern) 47 { 48 return adoptRef(new RegExp(pattern)); 49 } 50 51 inline RegExp::RegExp(const UString& pattern, const UString& flags) 52 : RefCounted<RegExp>(1) 53 , m_pattern(pattern) 46 54 , m_flags(flags) 47 55 , m_flagBits(0) … … 69 77 m_regExp = jsRegExpCompile(reinterpret_cast<const ::UChar*>(pattern.data()), pattern.size(), 70 78 ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); 79 } 80 81 PassRefPtr<RegExp> RegExp::create(const UString& pattern, const UString& flags) 82 { 83 return adoptRef(new RegExp(pattern, flags)); 71 84 } 72 85 -
trunk/JavaScriptCore/kjs/regexp.h
r28468 r30109 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 2 * 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. 5 4 * 6 5 * This library is free software; you can redistribute it and/or … … 24 23 25 24 #include "ustring.h" 26 #include <pcre/pcre.h> 27 #include <sys/types.h> 28 #include <wtf/OwnArrayPtr.h> 25 #include <wtf/Forward.h> 29 26 #include <wtf/RefCounted.h> 27 28 struct JSRegExp; 30 29 31 30 namespace KJS { 32 31 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; 39 65 }; 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 };72 66 73 67 } // namespace -
trunk/JavaScriptCore/kjs/regexp_object.cpp
r30040 r30109 96 96 UString pattern = args.isEmpty() ? UString("") : arg0->toString(exec); 97 97 UString flags = arg1->isUndefined() ? UString("") : arg1->toString(exec); 98 regExp = new RegExp(pattern, flags);98 regExp = RegExp::create(pattern, flags); 99 99 } 100 100 … … 450 450 UString flags = arg1->isUndefined() ? UString("") : arg1->toString(exec); 451 451 452 return createRegExpImp(exec, new RegExp(pattern, flags));452 return createRegExpImp(exec, RegExp::create(pattern, flags)); 453 453 } 454 454 -
trunk/JavaScriptCore/kjs/string_object.cpp
r30040 r30109 534 534 535 535 UString u = s; 536 RegExp* reg; 537 RegExp* tmpReg = 0; 536 RefPtr<RegExp> reg; 538 537 RegExpImp* imp = 0; 539 538 if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpImp::info)) { … … 545 544 * replaced with the result of the expression new RegExp(regexp). 546 545 */ 547 reg = tmpReg = new RegExp(a0->toString(exec));546 reg = RegExp::create(a0->toString(exec)); 548 547 } 549 548 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalGlobalObject()->regExpConstructor()); 550 549 int pos; 551 550 int matchLength; 552 regExpObj->performMatch(reg , u, 0, pos, matchLength);551 regExpObj->performMatch(reg.get(), u, 0, pos, matchLength); 553 552 JSValue* result; 554 553 if (!(reg->global())) { … … 566 565 lastIndex = pos; 567 566 pos += matchLength == 0 ? 1 : matchLength; 568 regExpObj->performMatch(reg , u, pos, pos, matchLength);567 regExpObj->performMatch(reg.get(), u, pos, pos, matchLength); 569 568 } 570 569 if (imp) … … 579 578 } 580 579 } 581 delete tmpReg;582 580 return result; 583 581 } … … 591 589 592 590 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(); 597 594 } else { 598 595 /* … … 601 598 * replaced with the result of the expression new RegExp(regexp). 602 599 */ 603 reg = tmpReg = new RegExp(a0->toString(exec));600 reg = RegExp::create(a0->toString(exec)); 604 601 } 605 602 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalGlobalObject()->regExpConstructor()); 606 603 int pos; 607 604 int matchLength; 608 regExpObj->performMatch(reg, u, 0, pos, matchLength); 609 delete tmpReg; 605 regExpObj->performMatch(reg.get(), u, 0, pos, matchLength); 610 606 return jsNumber(pos); 611 607 }
Note:
See TracChangeset
for help on using the changeset viewer.