Ignore:
Timestamp:
Jan 22, 2015, 12:54:52 AM (10 years ago)
Author:
Yusuke Suzuki
Message:

put_by_val_direct need to check the property is index or not for using putDirect / putDirectIndex
https://bugs.webkit.org/show_bug.cgi?id=140426

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

In the put_by_val_direct operation, we use JSObject::putDirect.
However, it only accepts non-index property. For index property, we need to use JSObject::putDirectIndex.
This patch changes Identifier::asIndex() to return Optional<uint32_t>.
It forces callers to check the value is index or not explicitly.
Additionally, it checks toString-ed Identifier is index or not to choose putDirect / putDirectIndex.

  • bytecode/GetByIdStatus.cpp:

(JSC::GetByIdStatus::computeFor):

  • bytecode/PutByIdStatus.cpp:

(JSC::PutByIdStatus::computeFor):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::emitDirectPutById):

  • dfg/DFGOperations.cpp:

(JSC::DFG::operationPutByValInternal):

  • jit/JITOperations.cpp:
  • jit/Repatch.cpp:

(JSC::emitPutTransitionStubAndGetOldStructure):

  • jsc.cpp:
  • llint/LLIntSlowPaths.cpp:

(JSC::LLInt::LLINT_SLOW_PATH_DECL):

  • runtime/Arguments.cpp:

(JSC::Arguments::getOwnPropertySlot):
(JSC::Arguments::put):
(JSC::Arguments::deleteProperty):
(JSC::Arguments::defineOwnProperty):

  • runtime/ArrayPrototype.cpp:

(JSC::arrayProtoFuncSort):

  • runtime/JSArray.cpp:

(JSC::JSArray::defineOwnProperty):

  • runtime/JSCJSValue.cpp:

(JSC::JSValue::putToPrimitive):

  • runtime/JSGenericTypedArrayViewInlines.h:

(JSC::JSGenericTypedArrayView<Adaptor>::getOwnPropertySlot):
(JSC::JSGenericTypedArrayView<Adaptor>::put):
(JSC::JSGenericTypedArrayView<Adaptor>::defineOwnProperty):
(JSC::JSGenericTypedArrayView<Adaptor>::deleteProperty):

  • runtime/JSObject.cpp:

(JSC::JSObject::put):
(JSC::JSObject::putDirectAccessor):
(JSC::JSObject::putDirectCustomAccessor):
(JSC::JSObject::deleteProperty):
(JSC::JSObject::putDirectMayBeIndex):
(JSC::JSObject::defineOwnProperty):

  • runtime/JSObject.h:

(JSC::JSObject::getOwnPropertySlot):
(JSC::JSObject::getPropertySlot):
(JSC::JSObject::putDirectInternal):

  • runtime/JSString.cpp:

(JSC::JSString::getStringPropertyDescriptor):

  • runtime/JSString.h:

(JSC::JSString::getStringPropertySlot):

  • runtime/LiteralParser.cpp:

(JSC::LiteralParser<CharType>::parse):

  • runtime/PropertyName.h:

(JSC::toUInt32FromCharacters):
(JSC::toUInt32FromStringImpl):
(JSC::PropertyName::asIndex):

  • runtime/PropertyNameArray.cpp:

(JSC::PropertyNameArray::add):

  • runtime/StringObject.cpp:

(JSC::StringObject::deleteProperty):

  • runtime/Structure.cpp:

(JSC::Structure::prototypeChainMayInterceptStoreTo):

Source/WebCore:

Test: js/dfg-put-by-val-direct-with-edge-numbers.html

  • bindings/js/JSDOMWindowCustom.cpp:

(WebCore::JSDOMWindow::getOwnPropertySlot):

  • bindings/js/JSHTMLAllCollectionCustom.cpp:

(WebCore::callHTMLAllCollection):
(WebCore::JSHTMLAllCollection::item):

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateGetOwnPropertySlotBody):
(GenerateImplementation):

  • bindings/scripts/test/JS/JSFloat64Array.cpp:

(WebCore::JSFloat64Array::getOwnPropertySlot):
(WebCore::JSFloat64Array::getOwnPropertyDescriptor):
(WebCore::JSFloat64Array::put):

  • bindings/scripts/test/JS/JSTestEventTarget.cpp:

(WebCore::JSTestEventTarget::getOwnPropertySlot):

  • bridge/runtime_array.cpp:

(JSC::RuntimeArray::getOwnPropertySlot):
(JSC::RuntimeArray::put):

LayoutTests:

  • js/dfg-put-by-val-direct-with-edge-numbers-expected.txt: Added.
  • js/dfg-put-by-val-direct-with-edge-numbers.html: Added.
  • js/script-tests/dfg-put-by-val-direct-with-edge-numbers.js: Added.

(lookupWithKey):
(dfgShouldThrow):
(lookupWithKey2):
(toStringThrowsError.toString):

File:
1 edited

Legend:

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

    r178756 r178894  
    2929#include "Identifier.h"
    3030#include "PrivateName.h"
     31#include <wtf/Optional.h>
    3132
    3233namespace JSC {
    3334
    3435template <typename CharType>
    35 ALWAYS_INLINE uint32_t toUInt32FromCharacters(const CharType* characters, unsigned length)
     36ALWAYS_INLINE Optional<uint32_t> toUInt32FromCharacters(const CharType* characters, unsigned length)
    3637{
    3738    // An empty string is not a number.
    3839    if (!length)
    39         return UINT_MAX;
     40        return Nullopt;
    4041
    4142    // Get the first character, turning it into a digit.
    4243    uint32_t value = characters[0] - '0';
    4344    if (value > 9)
    44         return UINT_MAX;
     45        return Nullopt;
    4546   
    4647    // Check for leading zeros. If the first characher is 0, then the
    4748    // length of the string must be one - e.g. "042" is not equal to "42".
    4849    if (!value && length > 1)
    49         return UINT_MAX;
     50        return Nullopt;
    5051   
    5152    while (--length) {
    5253        // Multiply value by 10, checking for overflow out of 32 bits.
    5354        if (value > 0xFFFFFFFFU / 10)
    54             return UINT_MAX;
     55            return Nullopt;
    5556        value *= 10;
    5657       
     
    5859        uint32_t newValue = *(++characters) - '0';
    5960        if (newValue > 9)
    60             return UINT_MAX;
     61            return Nullopt;
    6162       
    6263        // Add in the old value, checking for overflow out of 32 bits.
    6364        newValue += value;
    6465        if (newValue < value)
    65             return UINT_MAX;
     66            return Nullopt;
    6667        value = newValue;
    6768    }
    68    
     69
     70    if (value == UINT_MAX)
     71        return Nullopt;
    6972    return value;
    7073}
    7174
    72 ALWAYS_INLINE uint32_t toUInt32FromStringImpl(StringImpl* impl)
     75ALWAYS_INLINE Optional<uint32_t> toUInt32FromStringImpl(StringImpl* impl)
    7376{
    7477    if (impl->is8Bit())
     
    110113    static const uint32_t NotAnIndex = UINT_MAX;
    111114
    112     uint32_t asIndex()
     115    Optional<uint32_t> asIndex()
    113116    {
    114         return m_impl ? toUInt32FromStringImpl(m_impl) : NotAnIndex;
     117        return m_impl ? toUInt32FromStringImpl(m_impl) : Nullopt;
    115118    }
    116    
     119
    117120    void dump(PrintStream& out) const
    118121    {
Note: See TracChangeset for help on using the changeset viewer.