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/JSObject.cpp

    r178756 r178894  
    340340    // Try indexed put first. This is required for correctness, since loads on property names that appear like
    341341    // valid indices will never look in the named property storage.
    342     unsigned i = propertyName.asIndex();
    343     if (i != PropertyName::NotAnIndex) {
    344         putByIndex(thisObject, exec, i, value, slot.isStrictMode());
     342    if (Optional<uint32_t> index = propertyName.asIndex()) {
     343        putByIndex(thisObject, exec, index.value(), value, slot.isStrictMode());
    345344        return;
    346345    }
     
    11991198    ASSERT(value.isGetterSetter() && (attributes & Accessor));
    12001199
    1201     unsigned index = propertyName.asIndex();
    1202     if (index != PropertyName::NotAnIndex) {
    1203         putDirectIndex(exec, index, value, attributes, PutDirectIndexLikePutDirect);
     1200    if (Optional<uint32_t> index = propertyName.asIndex()) {
     1201        putDirectIndex(exec, index.value(), value, attributes, PutDirectIndexLikePutDirect);
    12041202        return;
    12051203    }
     
    12101208void JSObject::putDirectCustomAccessor(VM& vm, PropertyName propertyName, JSValue value, unsigned attributes)
    12111209{
    1212     ASSERT(propertyName.asIndex() == PropertyName::NotAnIndex);
     1210    ASSERT(!propertyName.asIndex());
    12131211
    12141212    PutPropertySlot slot(this);
     
    12581256    JSObject* thisObject = jsCast<JSObject*>(cell);
    12591257   
    1260     unsigned i = propertyName.asIndex();
    1261     if (i != PropertyName::NotAnIndex)
    1262         return thisObject->methodTable(exec->vm())->deletePropertyByIndex(thisObject, exec, i);
     1258    if (Optional<uint32_t> index = propertyName.asIndex())
     1259        return thisObject->methodTable(exec->vm())->deletePropertyByIndex(thisObject, exec, index.value());
    12631260
    12641261    if (!thisObject->staticFunctionsReified())
     
    25032500void JSObject::putDirectMayBeIndex(ExecState* exec, PropertyName propertyName, JSValue value)
    25042501{
    2505     unsigned asIndex = propertyName.asIndex();
    2506     if (asIndex == PropertyName::NotAnIndex)
     2502    if (Optional<uint32_t> index = propertyName.asIndex())
     2503        putDirectIndex(exec, index.value(), value);
     2504    else
    25072505        putDirect(exec->vm(), propertyName, value);
    2508     else
    2509         putDirectIndex(exec, asIndex, value);
    25102506}
    25112507
     
    26602656{
    26612657    // If it's an array index, then use the indexed property storage.
    2662     unsigned index = propertyName.asIndex();
    2663     if (index != PropertyName::NotAnIndex) {
     2658    if (Optional<uint32_t> index = propertyName.asIndex()) {
    26642659        // 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.
    26652660        // d. Reject if succeeded is false.
     
    26682663        // 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.
    26692664        // f. Return true.
    2670         return object->defineOwnIndexedProperty(exec, index, descriptor, throwException);
     2665        return object->defineOwnIndexedProperty(exec, index.value(), descriptor, throwException);
    26712666    }
    26722667   
Note: See TracChangeset for help on using the changeset viewer.