Ignore:
Timestamp:
Sep 25, 2020, 4:51:33 AM (5 years ago)
Author:
Alexey Shvayka
Message:

DataView instances should not have own "byteLength" and "byteOffset" properties
https://bugs.webkit.org/show_bug.cgi?id=149906

Reviewed by Ross Kirsling.

JSTests:

  • stress/dataview-no-own-properties.js: Added.

Source/JavaScriptCore:

Following JSDataView::getOwnPropertySlot() deletion in r266529, this patch
removes related method overrides that incorrectly reported "byteLength" and
"byteOffset" as own properties of DataView instances [1].

This change brings DataView objects in compliance with invariants of internal
methods [2] and aligns JSC with V8 and SpiderMonkey.
DataView microbenchmarks are neutral.

[1]: https://tc39.es/ecma262/#sec-properties-of-dataview-instances
[2]: https://tc39.es/ecma262/#sec-invariants-of-the-essential-internal-methods

  • runtime/JSDataView.cpp:

(JSC::JSDataView::put): Deleted.
(JSC::JSDataView::defineOwnProperty): Deleted.
(JSC::JSDataView::deleteProperty): Deleted.
(JSC::JSDataView::getOwnNonIndexPropertyNames): Deleted.

  • runtime/JSDataView.h:

LayoutTests:

  • inspector/model/remote-object/object-expected.txt:
File:
1 edited

Legend:

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

    r266529 r267564  
    105105}
    106106
    107 bool JSDataView::put(
    108     JSCell* cell, JSGlobalObject* globalObject, PropertyName propertyName, JSValue value,
    109     PutPropertySlot& slot)
    110 {
    111     VM& vm = globalObject->vm();
    112     auto scope = DECLARE_THROW_SCOPE(vm);
    113     JSDataView* thisObject = jsCast<JSDataView*>(cell);
    114 
    115     if (UNLIKELY(isThisValueAltered(slot, thisObject)))
    116         RELEASE_AND_RETURN(scope, ordinarySetSlow(globalObject, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode()));
    117 
    118     if (propertyName == vm.propertyNames->byteLength
    119         || propertyName == vm.propertyNames->byteOffset)
    120         return typeError(globalObject, scope, slot.isStrictMode(), "Attempting to write to read-only typed array property."_s);
    121 
    122     RELEASE_AND_RETURN(scope, Base::put(thisObject, globalObject, propertyName, value, slot));
    123 }
    124 
    125 bool JSDataView::defineOwnProperty(
    126     JSObject* object, JSGlobalObject* globalObject, PropertyName propertyName,
    127     const PropertyDescriptor& descriptor, bool shouldThrow)
    128 {
    129     VM& vm = globalObject->vm();
    130     auto scope = DECLARE_THROW_SCOPE(vm);
    131     JSDataView* thisObject = jsCast<JSDataView*>(object);
    132     if (propertyName == vm.propertyNames->byteLength
    133         || propertyName == vm.propertyNames->byteOffset)
    134         return typeError(globalObject, scope, shouldThrow, "Attempting to define read-only typed array property."_s);
    135 
    136     RELEASE_AND_RETURN(scope, Base::defineOwnProperty(thisObject, globalObject, propertyName, descriptor, shouldThrow));
    137 }
    138 
    139 bool JSDataView::deleteProperty(
    140     JSCell* cell, JSGlobalObject* globalObject, PropertyName propertyName, DeletePropertySlot& slot)
    141 {
    142     VM& vm = globalObject->vm();
    143     JSDataView* thisObject = jsCast<JSDataView*>(cell);
    144     if (propertyName == vm.propertyNames->byteLength
    145         || propertyName == vm.propertyNames->byteOffset)
    146         return false;
    147 
    148     return Base::deleteProperty(thisObject, globalObject, propertyName, slot);
    149 }
    150 
    151 void JSDataView::getOwnNonIndexPropertyNames(
    152     JSObject* object, JSGlobalObject* globalObject, PropertyNameArray& array, EnumerationMode mode)
    153 {
    154     VM& vm = globalObject->vm();
    155     JSDataView* thisObject = jsCast<JSDataView*>(object);
    156    
    157     if (mode.includeDontEnumProperties()) {
    158         array.add(vm.propertyNames->byteOffset);
    159         array.add(vm.propertyNames->byteLength);
    160     }
    161    
    162     Base::getOwnNonIndexPropertyNames(thisObject, globalObject, array, mode);
    163 }
    164 
    165107Structure* JSDataView::createStructure(
    166108    VM& vm, JSGlobalObject* globalObject, JSValue prototype)
Note: See TracChangeset for help on using the changeset viewer.