[Webkit-unassigned] [Bug 131704] Simple ES6 feature:String prototype additions

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Sep 19 00:46:53 PDT 2014


--- Comment #42 from Diego Pino <dpino at igalia.com>  2014-09-19 00:46:50 PST ---
(In reply to comment #41)
> (From update of attachment 238045 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=238045&action=review
> > Source/WTF/wtf/text/StringImpl.cpp:1424
> > +bool StringImpl::startsWith(StringImpl& matchString, unsigned startOffset, bool caseSensitive) const
> > +{
> > +    return equalInner(const_cast<StringImpl&>(*this), startOffset, matchString, caseSensitive);
> > +}
> We should follow this up by removing all the const on StringImpl member functions since it’s an immutable class, and all StringImpl are const; when we remove the const from this one, we can remove the const_cast.

I'm a bit lost at this. This is the current declaration of equalInner:

equalInner(StringImpl& stringImpl, unsigned startOffset, ...)

It's declared without a 'const' modifier, since the class it's inmutable and it's not needed.

In startsWith, dereferencing 'this' returns a 'const StringImpl'. I need to remove the constness from *this to call equalInner, and that's what the casting does: const_cast<StringImpl&>(*this), converts a 'const StringImpl' to a 'StringImpl&'.

The compiler complains if I don't do the casting. Calling 'equalInner(*this,...) returns this:

../../Source/WTF/wtf/text/StringImpl.cpp: In member function 'bool WTF::StringImpl::startsWith(WTF::StringImpl&, unsigned int, bool) const':
../../Source/WTF/wtf/text/StringImpl.cpp:1423:24: error: invalid initialization of reference of type 'WTF::StringImpl&' from expression of type 'const WTF::StringImpl'

Another possibility is to declare equalInner as 'equalInner(const String&, ...)' and pass '*this' without removing the constness.

Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

More information about the webkit-unassigned mailing list