Ignore:
Timestamp:
Sep 3, 2020, 10:04:09 AM (5 years ago)
Author:
Ross Kirsling
Message:

[JSC] Add missing detached buffer errors for DataView
https://bugs.webkit.org/show_bug.cgi?id=216062

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/detached-buffer-typeerror.js:

Add new test.

  • stress/dataview-jit-neuter.js:
  • stress/native-constructors-length.js:

Update existing tests.

  • test262/expectations.yaml:

Mark 74 test cases as passing.

Source/JavaScriptCore:

DataView methods are often expected to throw a TypeError if the underlying ArrayBuffer is detached
(or neutered, in older terminology) -- this patch adds a slew of missing cases from the following spec section:

At the same time:

  • get rid of JSDataView::getOwnPropertySlot, which was turning dataViewProtoGetterByte{Length,Offset} into mostly unreachable code and erroneously causing byte{Length,Offset} to have property descriptors
  • perform some simple cleanup of neighboring error calls / messages
  • fix value of DataView.length (our only other DataView spec bug)
  • runtime/JSDataView.cpp:

(JSC::JSDataView::create):
(JSC::JSDataView::getOwnPropertySlot): Deleted.

  • runtime/JSDataView.h:
  • runtime/JSDataViewPrototype.cpp:

(JSC::getData):
(JSC::setData):
(JSC::dataViewProtoGetterByteLength):
(JSC::dataViewProtoGetterByteOffset):

  • runtime/JSGenericTypedArrayViewConstructorInlines.h:

(JSC::JSGenericTypedArrayViewConstructor<ViewClass>::finishCreation):

LayoutTests:

  • fast/canvas/webgl/arraybuffer-transfer-of-control.html:
  • js/dom/constructor-length.html:
  • js/script-tests/typedarray-constructors.js:
  • js/typedarray-constructors-expected.txt:
  • platform/glib/js/dom/constructor-length-expected.txt:
  • platform/ios/js/dom/constructor-length-expected.txt:
  • platform/mac/js/dom/constructor-length-expected.txt:
  • platform/win/js/dom/constructor-length-expected.txt:
  • platform/wincairo/js/dom/constructor-length-expected.txt:

Update tests and expectations.

File:
1 edited

Legend:

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

    r261755 r266529  
    4949
    5050    ASSERT(buffer);
     51    if (buffer->isNeutered()) {
     52        throwTypeError(globalObject, scope, "Buffer is already detached"_s);
     53        return nullptr;
     54    }
    5155    if (!ArrayBufferView::verifySubRangeLength(*buffer, byteOffset, byteLength, sizeof(uint8_t))) {
    52         throwVMError(globalObject, scope, createRangeError(globalObject, "Length out of range of buffer"_s));
     56        throwRangeError(globalObject, scope, "Length out of range of buffer"_s);
    5357        return nullptr;
    5458    }
    5559    if (!ArrayBufferView::verifyByteOffsetAlignment(byteOffset, sizeof(uint8_t))) {
    56         throwException(globalObject, scope, createRangeError(globalObject, "Byte offset is not aligned"_s));
     60        throwRangeError(globalObject, scope, "Byte offset is not aligned"_s);
    5761        return nullptr;
    5862    }
     63
    5964    ConstructionContext context(
    6065        structure, buffer.copyRef(), byteOffset, byteLength, ConstructionContext::DataView);
     
    98103{
    99104    return DataView::create(unsharedBuffer(), byteOffset(), length());
    100 }
    101 
    102 bool JSDataView::getOwnPropertySlot(
    103     JSObject* object, JSGlobalObject* globalObject, PropertyName propertyName, PropertySlot& slot)
    104 {
    105     VM& vm = globalObject->vm();
    106     JSDataView* thisObject = jsCast<JSDataView*>(object);
    107     if (propertyName == vm.propertyNames->byteLength) {
    108         slot.setValue(thisObject, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly, jsNumber(thisObject->m_length));
    109         return true;
    110     }
    111     if (propertyName == vm.propertyNames->byteOffset) {
    112         slot.setValue(thisObject, PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly, jsNumber(thisObject->byteOffset()));
    113         return true;
    114     }
    115 
    116     return Base::getOwnPropertySlot(thisObject, globalObject, propertyName, slot);
    117105}
    118106
Note: See TracChangeset for help on using the changeset viewer.