Ignore:
Timestamp:
May 11, 2017, 4:05:01 PM (8 years ago)
Author:
[email protected]
Message:

Callers of JSString::unsafeView() should check exceptions
https://bugs.webkit.org/show_bug.cgi?id=171995

Reviewed by Mark Lam.

unsafeView() can throw OOME. So, callers of unsafeView() should check for exceptions before trying
to access the view.

Also, I made the functions surrounding unsafeView() take ExecState* not ExecState&, to comply with
the rest of JSC.

  • dfg/DFGOperations.cpp:
  • jsc.cpp:

(printInternal):
(functionDebug):

  • runtime/ArrayPrototype.cpp:

(JSC::arrayProtoFuncJoin):

  • runtime/FunctionConstructor.cpp:

(JSC::constructFunctionSkippingEvalEnabledCheck):

  • runtime/IntlCollatorPrototype.cpp:

(JSC::IntlCollatorFuncCompare):

  • runtime/JSGenericTypedArrayViewPrototypeFunctions.h:

(JSC::genericTypedArrayViewProtoFuncJoin):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncParseFloat):

  • runtime/JSONObject.cpp:

(JSC::JSONProtoFuncParse):

  • runtime/JSString.cpp:

(JSC::JSString::getPrimitiveNumber):
(JSC::JSString::toNumber):

  • runtime/JSString.h:

(JSC::JSString::getIndex):
(JSC::JSRopeString::unsafeView):
(JSC::JSRopeString::viewWithUnderlyingString):
(JSC::JSString::unsafeView):
(JSC::JSString::viewWithUnderlyingString):

  • runtime/JSStringJoiner.h:

(JSC::JSStringJoiner::appendWithoutSideEffects):
(JSC::JSStringJoiner::append):

  • runtime/ParseInt.h:

(JSC::toStringView):

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncRepeatCharacter):
(JSC::stringProtoFuncCharAt):
(JSC::stringProtoFuncCharCodeAt):
(JSC::stringProtoFuncIndexOf):
(JSC::stringProtoFuncNormalize):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r212365 r216699  
    2929#include "PropertySlot.h"
    3030#include "Structure.h"
     31#include "ThrowScope.h"
    3132#include <array>
    3233#include <wtf/text/StringView.h>
     
    157158    RefPtr<AtomicStringImpl> toExistingAtomicString(ExecState*) const;
    158159
    159     StringViewWithUnderlyingString viewWithUnderlyingString(ExecState&) const;
     160    StringViewWithUnderlyingString viewWithUnderlyingString(ExecState*) const;
    160161
    161162    inline bool equal(ExecState*, JSString* other) const;
     
    235236
    236237    String& string() { ASSERT(!isRope()); return m_value; }
    237     StringView unsafeView(ExecState&) const;
     238    StringView unsafeView(ExecState*) const;
    238239
    239240    friend JSString* jsString(ExecState*, JSString*, JSString*);
     
    431432    void resolveRopeInternal16NoSubstring(UChar*) const;
    432433    void clearFibers() const;
    433     StringView unsafeView(ExecState&) const;
    434     StringViewWithUnderlyingString viewWithUnderlyingString(ExecState&) const;
     434    StringView unsafeView(ExecState*) const;
     435    StringViewWithUnderlyingString viewWithUnderlyingString(ExecState*) const;
    435436
    436437    WriteBarrierBase<JSString>& fiber(unsigned i) const
     
    557558inline JSString* JSString::getIndex(ExecState* exec, unsigned i)
    558559{
     560    VM& vm = exec->vm();
     561    auto scope = DECLARE_THROW_SCOPE(vm);
    559562    ASSERT(canGetIndex(i));
    560     return jsSingleCharacterString(exec, unsafeView(*exec)[i]);
     563    StringView view = unsafeView(exec);
     564    RETURN_IF_EXCEPTION(scope, nullptr);
     565    return jsSingleCharacterString(exec, view[i]);
    561566}
    562567
     
    706711}
    707712
    708 ALWAYS_INLINE StringView JSRopeString::unsafeView(ExecState& state) const
     713ALWAYS_INLINE StringView JSRopeString::unsafeView(ExecState* exec) const
    709714{
    710715    if (isSubstring()) {
     
    713718        return StringView(substringBase()->m_value.characters16() + substringOffset(), length());
    714719    }
    715     resolveRope(&state);
     720    resolveRope(exec);
    716721    return m_value;
    717722}
    718723
    719 ALWAYS_INLINE StringViewWithUnderlyingString JSRopeString::viewWithUnderlyingString(ExecState& state) const
     724ALWAYS_INLINE StringViewWithUnderlyingString JSRopeString::viewWithUnderlyingString(ExecState* exec) const
    720725{
    721726    if (isSubstring()) {
     
    725730        return { { base.characters16() + substringOffset(), length() }, base };
    726731    }
    727     resolveRope(&state);
     732    resolveRope(exec);
    728733    return { m_value, m_value };
    729734}
    730735
    731 ALWAYS_INLINE StringView JSString::unsafeView(ExecState& state) const
     736ALWAYS_INLINE StringView JSString::unsafeView(ExecState* exec) const
    732737{
    733738    if (isRope())
    734         return static_cast<const JSRopeString*>(this)->unsafeView(state);
     739        return static_cast<const JSRopeString*>(this)->unsafeView(exec);
    735740    return m_value;
    736741}
    737742
    738 ALWAYS_INLINE StringViewWithUnderlyingString JSString::viewWithUnderlyingString(ExecState& state) const
     743ALWAYS_INLINE StringViewWithUnderlyingString JSString::viewWithUnderlyingString(ExecState* exec) const
    739744{
    740745    if (isRope())
    741         return static_cast<const JSRopeString&>(*this).viewWithUnderlyingString(state);
     746        return static_cast<const JSRopeString&>(*this).viewWithUnderlyingString(exec);
    742747    return { m_value, m_value };
    743748}
Note: See TracChangeset for help on using the changeset viewer.