https://bugs.webkit.org/show_bug.cgi?id=187338
Reviewed by Mark Lam.
getTypedArrayImpl is overridden only by typed arrays and DataView. Since the number of these classes
are limited, we do not need to add this function to MethodTable: dispatching it in JSArrayBufferView is fine.
This patch removes getTypedArrayImpl from MethodTable, and moves it to JSArrayBufferView.
* runtime/ClassInfo.h:
* runtime/GenericTypedArrayView.h:
(JSC::GenericTypedArrayView::data const): Deleted.
(JSC::GenericTypedArrayView::set): Deleted.
(JSC::GenericTypedArrayView::setRange): Deleted.
(JSC::GenericTypedArrayView::zeroRange): Deleted.
(JSC::GenericTypedArrayView::zeroFill): Deleted.
(JSC::GenericTypedArrayView::length const): Deleted.
(JSC::GenericTypedArrayView::item const): Deleted.
(JSC::GenericTypedArrayView::set const): Deleted.
(JSC::GenericTypedArrayView::setNative const): Deleted.
(JSC::GenericTypedArrayView::getRange): Deleted.
(JSC::GenericTypedArrayView::checkInboundData const): Deleted.
(JSC::GenericTypedArrayView::internalByteLength const): Deleted.
* runtime/JSArrayBufferView.cpp:
(JSC::JSArrayBufferView::possiblySharedImpl):
* runtime/JSArrayBufferView.h:
* runtime/JSArrayBufferViewInlines.h:
(JSC::JSArrayBufferView::possiblySharedImpl): Deleted.
* runtime/JSCell.cpp:
(JSC::JSCell::getTypedArrayImpl): Deleted.
* runtime/JSCell.h:
* runtime/JSDataView.cpp:
(JSC::JSDataView::getTypedArrayImpl): Deleted.
* runtime/JSDataView.h:
* runtime/JSGenericTypedArrayView.h:
* runtime/JSGenericTypedArrayViewInlines.h:
(JSC::JSGenericTypedArrayView<Adaptor>::getTypedArrayImpl): Deleted.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233721
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2018-07-05 Yusuke Suzuki <utatane.tea@gmail.com>
+
+ [JSC] Remove getTypedArrayImpl
+ https://bugs.webkit.org/show_bug.cgi?id=187338
+
+ Reviewed by Mark Lam.
+
+ getTypedArrayImpl is overridden only by typed arrays and DataView. Since the number of these classes
+ are limited, we do not need to add this function to MethodTable: dispatching it in JSArrayBufferView is fine.
+ This patch removes getTypedArrayImpl from MethodTable, and moves it to JSArrayBufferView.
+
+ * runtime/ClassInfo.h:
+ * runtime/GenericTypedArrayView.h:
+ (JSC::GenericTypedArrayView::data const): Deleted.
+ (JSC::GenericTypedArrayView::set): Deleted.
+ (JSC::GenericTypedArrayView::setRange): Deleted.
+ (JSC::GenericTypedArrayView::zeroRange): Deleted.
+ (JSC::GenericTypedArrayView::zeroFill): Deleted.
+ (JSC::GenericTypedArrayView::length const): Deleted.
+ (JSC::GenericTypedArrayView::item const): Deleted.
+ (JSC::GenericTypedArrayView::set const): Deleted.
+ (JSC::GenericTypedArrayView::setNative const): Deleted.
+ (JSC::GenericTypedArrayView::getRange): Deleted.
+ (JSC::GenericTypedArrayView::checkInboundData const): Deleted.
+ (JSC::GenericTypedArrayView::internalByteLength const): Deleted.
+ * runtime/JSArrayBufferView.cpp:
+ (JSC::JSArrayBufferView::possiblySharedImpl):
+ * runtime/JSArrayBufferView.h:
+ * runtime/JSArrayBufferViewInlines.h:
+ (JSC::JSArrayBufferView::possiblySharedImpl): Deleted.
+ * runtime/JSCell.cpp:
+ (JSC::JSCell::getTypedArrayImpl): Deleted.
+ * runtime/JSCell.h:
+ * runtime/JSDataView.cpp:
+ (JSC::JSDataView::getTypedArrayImpl): Deleted.
+ * runtime/JSDataView.h:
+ * runtime/JSGenericTypedArrayView.h:
+ * runtime/JSGenericTypedArrayViewInlines.h:
+ (JSC::JSGenericTypedArrayView<Adaptor>::getTypedArrayImpl): Deleted.
+
2018-07-10 Keith Miller <keith_miller@apple.com>
hasOwnProperty returns true for out of bounds property index on TypedArray
using DefineOwnPropertyFunctionPtr = bool (*)(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool);
DefineOwnPropertyFunctionPtr WTF_METHOD_TABLE_ENTRY(defineOwnProperty);
- using GetTypedArrayImpl = RefPtr<ArrayBufferView> (*)(JSArrayBufferView*);
- GetTypedArrayImpl WTF_METHOD_TABLE_ENTRY(getTypedArrayImpl);
-
using PreventExtensionsFunctionPtr = bool (*)(JSObject*, ExecState*);
PreventExtensionsFunctionPtr WTF_METHOD_TABLE_ENTRY(preventExtensions);
&ClassName::toStringName, \
&ClassName::customHasInstance, \
&ClassName::defineOwnProperty, \
- &ClassName::getTypedArrayImpl, \
&ClassName::preventExtensions, \
&ClassName::isExtensible, \
&ClassName::setPrototype, \
namespace JSC {
template<typename Adaptor>
-class GenericTypedArrayView : public ArrayBufferView {
+class GenericTypedArrayView final : public ArrayBufferView {
protected:
GenericTypedArrayView(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length);
#include "config.h"
#include "JSArrayBufferView.h"
+#include "GenericTypedArrayViewInlines.h"
#include "JSArrayBuffer.h"
#include "JSCInlines.h"
+#include "JSGenericTypedArrayViewInlines.h"
#include "JSTypedArrays.h"
#include "TypeError.h"
#include "TypedArrayController.h"
+#include "TypedArrays.h"
#include <wtf/Gigacage.h>
namespace JSC {
}
static const constexpr size_t ElementSizeData[] = {
- sizeof(typename Int8Adaptor::Type), // Int8ArrayType
- sizeof(typename Uint8Adaptor::Type), // Uint8ArrayType
- sizeof(typename Uint8ClampedAdaptor::Type), // Uint8ClampedArrayType
- sizeof(typename Int16Adaptor::Type), // Int16ArrayType
- sizeof(typename Uint16Adaptor::Type), // Uint16ArrayType
- sizeof(typename Int32Adaptor::Type), // Int32ArrayType
- sizeof(typename Uint32Adaptor::Type), // Uint32ArrayType
- sizeof(typename Float32Adaptor::Type), // Float32ArrayType
- sizeof(typename Float64Adaptor::Type), // Float64ArrayType
+#define FACTORY(type) sizeof(typename type ## Adaptor::Type),
+ FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(FACTORY)
+#undef FACTORY
};
-static_assert(std::is_final<JSInt8Array>::value, "");
-static_assert(std::is_final<JSUint8Array>::value, "");
-static_assert(std::is_final<JSUint8ClampedArray>::value, "");
-static_assert(std::is_final<JSInt16Array>::value, "");
-static_assert(std::is_final<JSUint16Array>::value, "");
-static_assert(std::is_final<JSInt32Array>::value, "");
-static_assert(std::is_final<JSUint32Array>::value, "");
-static_assert(std::is_final<JSFloat32Array>::value, "");
-static_assert(std::is_final<JSFloat64Array>::value, "");
+#define FACTORY(type) static_assert(std::is_final<JS ## type ## Array>::value, "");
+FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(FACTORY)
+#undef FACTORY
static inline size_t elementSize(JSType type)
{
return buffer.get();
}
+// Allocates the full-on native buffer and moves data into the C heap if
+// necessary. Note that this never allocates in the GC heap.
+RefPtr<ArrayBufferView> JSArrayBufferView::possiblySharedImpl()
+{
+ ArrayBuffer* buffer = possiblySharedBuffer();
+ unsigned byteOffset = this->byteOffset();
+ unsigned length = this->length();
+ switch (type()) {
+#define FACTORY(type) \
+ case type ## ArrayType: \
+ return type ## Array::create(buffer, byteOffset, length);
+ FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(FACTORY)
+#undef FACTORY
+ case DataViewType:
+ return DataView::create(buffer, byteOffset, length);
+ default:
+ RELEASE_ASSERT_NOT_REACHED();
+ return nullptr;
+ }
+}
+
} // namespace JSC
namespace WTF {
JSArrayBuffer* unsharedJSBuffer(ExecState* exec);
JSArrayBuffer* possiblySharedJSBuffer(ExecState* exec);
RefPtr<ArrayBufferView> unsharedImpl();
- RefPtr<ArrayBufferView> possiblySharedImpl();
+ JS_EXPORT_PRIVATE RefPtr<ArrayBufferView> possiblySharedImpl();
bool isNeutered() { return hasArrayBuffer() && !vector(); }
void neuter();
return butterfly()->indexingHeader()->arrayBuffer();
}
-inline RefPtr<ArrayBufferView> JSArrayBufferView::possiblySharedImpl()
-{
- return methodTable()->getTypedArrayImpl(this);
-}
-
inline RefPtr<ArrayBufferView> JSArrayBufferView::unsharedImpl()
{
RefPtr<ArrayBufferView> result = possiblySharedImpl();
return false;
}
-RefPtr<ArrayBufferView> JSCell::getTypedArrayImpl(JSArrayBufferView*)
-{
- RELEASE_ASSERT_NOT_REACHED();
- return nullptr;
-}
-
uint32_t JSCell::getEnumerableLength(ExecState*, JSObject*)
{
RELEASE_ASSERT_NOT_REACHED();
static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned propertyName, PropertySlot&);
- JS_EXPORT_PRIVATE static RefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
private:
friend class LLIntOffsetsExtractor;
Base::getOwnNonIndexPropertyNames(thisObject, exec, array, mode);
}
-RefPtr<ArrayBufferView> JSDataView::getTypedArrayImpl(JSArrayBufferView* object)
-{
- JSDataView* thisObject = jsCast<JSDataView*>(object);
- return thisObject->possiblySharedTypedImpl();
-}
-
Structure* JSDataView::createStructure(
VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
- static RefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
-
public:
static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
static size_t estimatedSize(JSCell*);
static void visitChildren(JSCell*, SlotVisitor&);
- // Allocates the full-on native buffer and moves data into the C heap if
- // necessary. Note that this never allocates in the GC heap.
- static RefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
-
private:
// Returns true if successful, and false on error; it will throw on error.
template<typename OtherAdaptor>
}
template<typename IntegralType>
- static bool ALWAYS_INLINE sortComparison(IntegralType a, IntegralType b)
- {
- if (a >= 0 || b >= 0)
- return a < b;
- return a > b;
- }
-
- template<typename IntegralType>
void sortFloat()
{
ASSERT(sizeof(IntegralType) == sizeof(ElementType));
purifyArray();
IntegralType* array = reinterpret_cast_ptr<IntegralType*>(typedVector());
- std::sort(array, array + m_length, sortComparison<IntegralType>);
+ std::sort(array, array + m_length, [] (IntegralType a, IntegralType b) {
+ if (a >= 0 || b >= 0)
+ return a < b;
+ return a > b;
+ });
}
}
}
-template<typename Adaptor>
-RefPtr<ArrayBufferView> JSGenericTypedArrayView<Adaptor>::getTypedArrayImpl(JSArrayBufferView* object)
-{
- JSGenericTypedArrayView* thisObject = jsCast<JSGenericTypedArrayView*>(object);
- return thisObject->possiblySharedTypedImpl();
-}
-
} // namespace JSC
DerivedArrayType,
// End JSArray types.
- // Start JSArrayBufferView types.
+ // Start JSArrayBufferView types. Keep in sync with the order of FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW.
Int8ArrayType,
Uint8ArrayType,
Uint8ClampedArrayType,
struct ClassInfo;
+// Keep in sync with the order of JSType.
#define FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(macro) \
macro(Int8) \
macro(Uint8) \