Ignore:
Timestamp:
Apr 6, 2015, 5:40:33 AM (10 years ago)
Author:
Yusuke Suzuki
Message:

Return Optional<uint32_t> from PropertyName::asIndex
https://bugs.webkit.org/show_bug.cgi?id=143422

Reviewed by Darin Adler.

Source/JavaScriptCore:

PropertyName::asIndex returns uint32_t and use UINT_MAX as NotAnIndex.
But it's not obvious to callers.

This patch changes

  1. PropertyName::asIndex() to return Optional<uint32_t> and
  2. function name asIndex() to parseIndex().

It forces callers to check the value is index or not explicitly.

  • bytecode/GetByIdStatus.cpp:

(JSC::GetByIdStatus::computeFor):

  • bytecode/PutByIdStatus.cpp:

(JSC::PutByIdStatus::computeFor):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::emitDirectPutById):

  • jit/Repatch.cpp:

(JSC::emitPutTransitionStubAndGetOldStructure):

  • jsc.cpp:
  • runtime/ArrayPrototype.cpp:

(JSC::arrayProtoFuncSort):

  • runtime/GenericArgumentsInlines.h:

(JSC::GenericArguments<Type>::getOwnPropertySlot):
(JSC::GenericArguments<Type>::put):
(JSC::GenericArguments<Type>::deleteProperty):
(JSC::GenericArguments<Type>::defineOwnProperty):

  • runtime/Identifier.h:

(JSC::parseIndex):
(JSC::Identifier::isSymbol):

  • 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::parseIndex):
(JSC::toUInt32FromCharacters): Deleted.
(JSC::toUInt32FromStringImpl): Deleted.
(JSC::PropertyName::asIndex): Deleted.

  • runtime/PropertyNameArray.cpp:

(JSC::PropertyNameArray::add):

  • runtime/StringObject.cpp:

(JSC::StringObject::deleteProperty):

  • runtime/Structure.cpp:

(JSC::Structure::prototypeChainMayInterceptStoreTo):

Source/WebCore:

  • bindings/js/JSDOMWindowCustom.cpp:

(WebCore::JSDOMWindow::getOwnPropertySlot):
(WebCore::JSDOMWindow::getOwnPropertySlotByIndex):

  • 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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSObject.cpp

    r182280 r182406  
    380380    // Try indexed put first. This is required for correctness, since loads on property names that appear like
    381381    // valid indices will never look in the named property storage.
    382     unsigned i = propertyName.asIndex();
    383     if (i != PropertyName::NotAnIndex) {
    384         putByIndex(thisObject, exec, i, value, slot.isStrictMode());
     382    if (Optional<uint32_t> index = parseIndex(propertyName)) {
     383        putByIndex(thisObject, exec, index.value(), value, slot.isStrictMode());
    385384        return;
    386385    }
     
    12391238    ASSERT(value.isGetterSetter() && (attributes & Accessor));
    12401239
    1241     unsigned index = propertyName.asIndex();
    1242     if (index != PropertyName::NotAnIndex) {
    1243         putDirectIndex(exec, index, value, attributes, PutDirectIndexLikePutDirect);
     1240    if (Optional<uint32_t> index = parseIndex(propertyName)) {
     1241        putDirectIndex(exec, index.value(), value, attributes, PutDirectIndexLikePutDirect);
    12441242        return;
    12451243    }
     
    12501248void JSObject::putDirectCustomAccessor(VM& vm, PropertyName propertyName, JSValue value, unsigned attributes)
    12511249{
    1252     ASSERT(propertyName.asIndex() == PropertyName::NotAnIndex);
     1250    ASSERT(!parseIndex(propertyName));
    12531251
    12541252    PutPropertySlot slot(this);
     
    12981296    JSObject* thisObject = jsCast<JSObject*>(cell);
    12991297   
    1300     unsigned i = propertyName.asIndex();
    1301     if (i != PropertyName::NotAnIndex)
    1302         return thisObject->methodTable(exec->vm())->deletePropertyByIndex(thisObject, exec, i);
     1298    if (Optional<uint32_t> index = parseIndex(propertyName))
     1299        return thisObject->methodTable(exec->vm())->deletePropertyByIndex(thisObject, exec, index.value());
    13031300
    13041301    if (!thisObject->staticFunctionsReified())
     
    25532550void JSObject::putDirectMayBeIndex(ExecState* exec, PropertyName propertyName, JSValue value)
    25542551{
    2555     unsigned asIndex = propertyName.asIndex();
    2556     if (asIndex == PropertyName::NotAnIndex)
     2552    if (Optional<uint32_t> index = parseIndex(propertyName))
     2553        putDirectIndex(exec, index.value(), value);
     2554    else
    25572555        putDirect(exec->vm(), propertyName, value);
    2558     else
    2559         putDirectIndex(exec, asIndex, value);
    25602556}
    25612557
     
    27102706{
    27112707    // If it's an array index, then use the indexed property storage.
    2712     unsigned index = propertyName.asIndex();
    2713     if (index != PropertyName::NotAnIndex) {
     2708    if (Optional<uint32_t> index = parseIndex(propertyName)) {
    27142709        // c. Let succeeded be the result of calling the default [[DefineOwnProperty]] internal method (8.12.9) on A passing P, Desc, and false as arguments.
    27152710        // d. Reject if succeeded is false.
     
    27182713        // e.ii. Call the default [[DefineOwnProperty]] internal method (8.12.9) on A passing "length", oldLenDesc, and false as arguments. This call will always return true.
    27192714        // f. Return true.
    2720         return object->defineOwnIndexedProperty(exec, index, descriptor, throwException);
     2715        return object->defineOwnIndexedProperty(exec, index.value(), descriptor, throwException);
    27212716    }
    27222717   
Note: See TracChangeset for help on using the changeset viewer.