Changeset 178751 in webkit for trunk/Source/JavaScriptCore/jit


Ignore:
Timestamp:
Jan 20, 2015, 1:14:48 PM (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):
(lookupWithKey2):
(toStringThrowsError.toString):

  • resources/js-test-pre.js:
Location:
trunk/Source/JavaScriptCore/jit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jit/JITOperations.cpp

    r178441 r178751  
    5252#include "LegacyProfiler.h"
    5353#include "ObjectConstructor.h"
     54#include "PropertyName.h"
    5455#include "Repatch.h"
    5556#include "RepatchBuffer.h"
     
    481482static void directPutByVal(CallFrame* callFrame, JSObject* baseObject, JSValue subscript, JSValue value)
    482483{
     484    bool isStrictMode = callFrame->codeBlock()->isStrictMode();
    483485    if (LIKELY(subscript.isUInt32())) {
    484         uint32_t i = subscript.asUInt32();
    485         baseObject->putDirectIndex(callFrame, i, value);
    486     } else if (isName(subscript)) {
    487         PutPropertySlot slot(baseObject, callFrame->codeBlock()->isStrictMode());
     486        uint32_t index = subscript.asUInt32();
     487        ASSERT_WITH_MESSAGE(index != PropertyName::NotAnIndex, "Since JSValue::isUInt32 returns true only when the boxed value is int32_t and positive, it doesn't return true for uint32_t max value that is PropertyName::NotAnIndex.");
     488        baseObject->putDirectIndex(callFrame, index, value, 0, isStrictMode ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow);
     489        return;
     490    }
     491
     492    if (subscript.isDouble()) {
     493        double subscriptAsDouble = subscript.asDouble();
     494        uint32_t subscriptAsUInt32 = static_cast<uint32_t>(subscriptAsDouble);
     495        if (subscriptAsDouble == subscriptAsUInt32 && subscriptAsUInt32 != PropertyName::NotAnIndex) {
     496            baseObject->putDirectIndex(callFrame, subscriptAsUInt32, value, 0, isStrictMode ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow);
     497            return;
     498        }
     499    }
     500
     501    if (isName(subscript)) {
     502        PutPropertySlot slot(baseObject, isStrictMode);
    488503        baseObject->putDirect(callFrame->vm(), jsCast<NameInstance*>(subscript.asCell())->privateName(), value, slot);
    489     } else {
    490         Identifier property = subscript.toString(callFrame)->toIdentifier(callFrame);
    491         if (!callFrame->vm().exception()) { // Don't put to an object if toString threw an exception.
    492             PutPropertySlot slot(baseObject, callFrame->codeBlock()->isStrictMode());
    493             baseObject->putDirect(callFrame->vm(), property, value, slot);
    494         }
     504        return;
     505    }
     506
     507    // Don't put to an object if toString throws an exception.
     508    Identifier property = subscript.toString(callFrame)->toIdentifier(callFrame);
     509    if (callFrame->vm().exception())
     510        return;
     511
     512    PropertyName propertyName(property);
     513    if (Optional<uint32_t> index = propertyName.asIndex())
     514        baseObject->putDirectIndex(callFrame, index.value(), value, 0, isStrictMode ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow);
     515    else {
     516        PutPropertySlot slot(baseObject, isStrictMode);
     517        baseObject->putDirect(callFrame->vm(), propertyName, value, slot);
    495518    }
    496519}
  • trunk/Source/JavaScriptCore/jit/Repatch.cpp

    r178693 r178751  
    990990    PropertyName pname(ident);
    991991    Structure* oldStructure = structure;
    992     if (!oldStructure->isObject() || oldStructure->isDictionary() || pname.asIndex() != PropertyName::NotAnIndex)
     992    if (!oldStructure->isObject() || oldStructure->isDictionary() || pname.asIndex())
    993993        return nullptr;
    994994
Note: See TracChangeset for help on using the changeset viewer.