Commit 53cc6486 authored by jochen's avatar jochen Committed by Commit bot

Remove support for externally backed elements from the API

Embedders should use ArrayBuffers instead

BUG=v8:3996
LOG=y
R=verwaest@chromium.org,dslomov@chromium.org,kbr@chromium.org

Review URL: https://codereview.chromium.org/1092923002

Cr-Commit-Position: refs/heads/master@{#27939}
parent 36f17ed0
......@@ -2593,29 +2593,6 @@ enum PropertyAttribute {
DontDelete = 1 << 2
};
enum ExternalArrayType {
kExternalInt8Array = 1,
kExternalUint8Array,
kExternalInt16Array,
kExternalUint16Array,
kExternalInt32Array,
kExternalUint32Array,
kExternalFloat32Array,
kExternalFloat64Array,
kExternalUint8ClampedArray,
// Legacy constant names
kExternalByteArray = kExternalInt8Array,
kExternalUnsignedByteArray = kExternalUint8Array,
kExternalShortArray = kExternalInt16Array,
kExternalUnsignedShortArray = kExternalUint16Array,
kExternalIntArray = kExternalInt32Array,
kExternalUnsignedIntArray = kExternalUint32Array,
kExternalFloatArray = kExternalFloat32Array,
kExternalDoubleArray = kExternalFloat64Array,
kExternalPixelArray = kExternalUint8ClampedArray
};
/**
* Accessor[Getter|Setter] are used as callback functions when
* setting|getting a particular property. See Object and ObjectTemplate's
......@@ -2965,33 +2942,6 @@ class V8_EXPORT Object : public Value {
*/
Local<Context> CreationContext();
/**
* Set the backing store of the indexed properties to be managed by the
* embedding layer. Access to the indexed properties will follow the rules
* spelled out in CanvasPixelArray.
* Note: The embedding program still owns the data and needs to ensure that
* the backing store is preserved while V8 has a reference.
*/
void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
bool HasIndexedPropertiesInPixelData();
uint8_t* GetIndexedPropertiesPixelData();
int GetIndexedPropertiesPixelDataLength();
/**
* Set the backing store of the indexed properties to be managed by the
* embedding layer. Access to the indexed properties will follow the rules
* spelled out for the CanvasArray subtypes in the WebGL specification.
* Note: The embedding program still owns the data and needs to ensure that
* the backing store is preserved while V8 has a reference.
*/
void SetIndexedPropertiesToExternalArrayData(void* data,
ExternalArrayType array_type,
int number_of_elements);
bool HasIndexedPropertiesInExternalArrayData();
void* GetIndexedPropertiesExternalArrayData();
ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
int GetIndexedPropertiesExternalArrayDataLength();
/**
* Checks whether a callback is set by the
* ObjectTemplate::SetCallAsFunctionHandler method.
......
......@@ -2674,11 +2674,11 @@ bool Value::IsTypedArray() const {
}
#define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \
bool Value::Is##Type##Array() const { \
i::Handle<i::Object> obj = Utils::OpenHandle(this); \
return obj->IsJSTypedArray() && \
i::JSTypedArray::cast(*obj)->type() == kExternal##Type##Array; \
#define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \
bool Value::Is##Type##Array() const { \
i::Handle<i::Object> obj = Utils::OpenHandle(this); \
return obj->IsJSTypedArray() && \
i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \
}
TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY)
......@@ -3092,11 +3092,10 @@ void v8::TypedArray::CheckCast(Value* that) {
#define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype, size) \
void v8::Type##Array::CheckCast(Value* that) { \
i::Handle<i::Object> obj = Utils::OpenHandle(that); \
Utils::ApiCheck(obj->IsJSTypedArray() && \
i::JSTypedArray::cast(*obj)->type() == \
kExternal##Type##Array, \
"v8::" #Type "Array::Cast()", \
"Could not convert to " #Type "Array"); \
Utils::ApiCheck( \
obj->IsJSTypedArray() && \
i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array, \
"v8::" #Type "Array::Cast()", "Could not convert to " #Type "Array"); \
}
......@@ -4199,147 +4198,6 @@ bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) {
}
namespace {
static i::ElementsKind GetElementsKindFromExternalArrayType(
ExternalArrayType array_type) {
switch (array_type) {
#define ARRAY_TYPE_TO_ELEMENTS_KIND(Type, type, TYPE, ctype, size) \
case kExternal##Type##Array: \
return i::EXTERNAL_##TYPE##_ELEMENTS;
TYPED_ARRAYS(ARRAY_TYPE_TO_ELEMENTS_KIND)
#undef ARRAY_TYPE_TO_ELEMENTS_KIND
}
UNREACHABLE();
return i::DICTIONARY_ELEMENTS;
}
void PrepareExternalArrayElements(i::Handle<i::JSObject> object,
void* data,
ExternalArrayType array_type,
int length) {
i::Isolate* isolate = object->GetIsolate();
i::Handle<i::ExternalArray> array =
isolate->factory()->NewExternalArray(length, array_type, data);
i::Handle<i::Map> external_array_map =
i::JSObject::GetElementsTransitionMap(
object,
GetElementsKindFromExternalArrayType(array_type));
i::JSObject::SetMapAndElements(object, external_array_map, array);
}
} // namespace
void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) {
auto self = Utils::OpenHandle(this);
auto isolate = self->GetIsolate();
ENTER_V8(isolate);
i::HandleScope scope(isolate);
if (!Utils::ApiCheck(length >= 0 &&
length <= i::ExternalUint8ClampedArray::kMaxLength,
"v8::Object::SetIndexedPropertiesToPixelData()",
"length exceeds max acceptable value")) {
return;
}
if (!Utils::ApiCheck(!self->IsJSArray(),
"v8::Object::SetIndexedPropertiesToPixelData()",
"JSArray is not supported")) {
return;
}
PrepareExternalArrayElements(self, data, kExternalUint8ClampedArray, length);
}
bool v8::Object::HasIndexedPropertiesInPixelData() {
auto self = Utils::OpenHandle(this);
return self->HasExternalUint8ClampedElements();
}
uint8_t* v8::Object::GetIndexedPropertiesPixelData() {
auto self = Utils::OpenHandle(this);
if (self->HasExternalUint8ClampedElements()) {
return i::ExternalUint8ClampedArray::cast(self->elements())->
external_uint8_clamped_pointer();
}
return nullptr;
}
int v8::Object::GetIndexedPropertiesPixelDataLength() {
auto self = Utils::OpenHandle(this);
if (self->HasExternalUint8ClampedElements()) {
return i::ExternalUint8ClampedArray::cast(self->elements())->length();
}
return -1;
}
void v8::Object::SetIndexedPropertiesToExternalArrayData(
void* data,
ExternalArrayType array_type,
int length) {
auto self = Utils::OpenHandle(this);
auto isolate = self->GetIsolate();
ENTER_V8(isolate);
i::HandleScope scope(isolate);
if (!Utils::ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength,
"v8::Object::SetIndexedPropertiesToExternalArrayData()",
"length exceeds max acceptable value")) {
return;
}
if (!Utils::ApiCheck(!self->IsJSArray(),
"v8::Object::SetIndexedPropertiesToExternalArrayData()",
"JSArray is not supported")) {
return;
}
PrepareExternalArrayElements(self, data, array_type, length);
}
bool v8::Object::HasIndexedPropertiesInExternalArrayData() {
auto self = Utils::OpenHandle(this);
return self->HasExternalArrayElements();
}
void* v8::Object::GetIndexedPropertiesExternalArrayData() {
auto self = Utils::OpenHandle(this);
if (self->HasExternalArrayElements()) {
return i::ExternalArray::cast(self->elements())->external_pointer();
}
return nullptr;
}
ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() {
auto self = Utils::OpenHandle(this);
switch (self->elements()->map()->instance_type()) {
#define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \
case i::EXTERNAL_##TYPE##_ARRAY_TYPE: \
return kExternal##Type##Array;
TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE)
#undef INSTANCE_TYPE_TO_ARRAY_TYPE
default:
return static_cast<ExternalArrayType>(-1);
}
}
int v8::Object::GetIndexedPropertiesExternalArrayDataLength() {
auto self = Utils::OpenHandle(this);
if (self->HasExternalArrayElements()) {
return i::ExternalArray::cast(self->elements())->length();
}
return -1;
}
bool v8::Object::IsCallable() {
auto self = Utils::OpenHandle(this);
return self->IsCallable();
......@@ -6522,7 +6380,7 @@ size_t v8::TypedArray::Length() {
} \
i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); \
i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \
v8::kExternal##Type##Array, buffer, byte_offset, length); \
i::kExternal##Type##Array, buffer, byte_offset, length); \
return Utils::ToLocal##Type##Array(obj); \
}
......
......@@ -339,11 +339,11 @@ inline bool ToLocal(v8::internal::MaybeHandle<v8::internal::Object> maybe,
}
#define MAKE_TO_LOCAL_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \
Local<v8::Type##Array> Utils::ToLocal##Type##Array( \
v8::internal::Handle<v8::internal::JSTypedArray> obj) { \
DCHECK(obj->type() == kExternal##Type##Array); \
return Convert<v8::internal::JSTypedArray, v8::Type##Array>(obj); \
#define MAKE_TO_LOCAL_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \
Local<v8::Type##Array> Utils::ToLocal##Type##Array( \
v8::internal::Handle<v8::internal::JSTypedArray> obj) { \
DCHECK(obj->type() == v8::internal::kExternal##Type##Array); \
return Convert<v8::internal::JSTypedArray, v8::Type##Array>(obj); \
}
......
......@@ -385,24 +385,6 @@ class Shell : public i::AllStatic {
static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
static Handle<FunctionTemplate> CreateArrayBufferTemplate(FunctionCallback);
static Handle<FunctionTemplate> CreateArrayTemplate(FunctionCallback);
static Handle<Value> CreateExternalArrayBuffer(Isolate* isolate,
Handle<Object> buffer,
int32_t size);
static Handle<Object> CreateExternalArray(Isolate* isolate,
Handle<Object> array,
Handle<Object> buffer,
ExternalArrayType type,
int32_t length,
int32_t byteLength,
int32_t byteOffset,
int32_t element_size);
static void CreateExternalArray(
const v8::FunctionCallbackInfo<v8::Value>& args,
ExternalArrayType type,
int32_t element_size);
static void ExternalArrayWeakCallback(Isolate* isolate,
Persistent<Object>* object,
uint8_t* data);
};
......
......@@ -186,6 +186,19 @@ enum MutableMode {
};
enum ExternalArrayType {
kExternalInt8Array = 1,
kExternalUint8Array,
kExternalInt16Array,
kExternalUint16Array,
kExternalInt32Array,
kExternalUint32Array,
kExternalFloat32Array,
kExternalFloat64Array,
kExternalUint8ClampedArray,
};
static const int kGrowICDelta = STORE_AND_GROW_NO_TRANSITION -
STANDARD_STORE;
STATIC_ASSERT(STANDARD_STORE == 0);
......
......@@ -258,7 +258,7 @@ TEST(RunLoadStoreArrayBuffer) {
const int index = 12;
const int array_length = 2 * index;
ElementAccess buffer_access =
AccessBuilder::ForTypedArrayElement(v8::kExternalInt8Array, true);
AccessBuilder::ForTypedArrayElement(kExternalInt8Array, true);
Node* backing_store = t.LoadField(
AccessBuilder::ForJSArrayBufferBackingStore(), t.Parameter(0));
Node* load =
......
This diff is collapsed.
......@@ -5317,7 +5317,7 @@ TEST(WritableVsImmortalRoots) {
}
static void TestRightTrimFixedTypedArray(v8::ExternalArrayType type,
static void TestRightTrimFixedTypedArray(i::ExternalArrayType type,
int initial_length,
int elements_to_trim) {
v8::HandleScope scope(CcTest::isolate());
......@@ -5353,17 +5353,17 @@ TEST(Regress472513) {
// typed array header smashing with free space filler (crbug/472513).
// 64-bit cases.
TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 32, 6);
TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 32 - 7, 6);
TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 16, 6);
TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 16 - 3, 6);
TestRightTrimFixedTypedArray(v8::kExternalUint32Array, 8, 6);
TestRightTrimFixedTypedArray(v8::kExternalUint32Array, 8 - 1, 6);
TestRightTrimFixedTypedArray(i::kExternalUint8Array, 32, 6);
TestRightTrimFixedTypedArray(i::kExternalUint8Array, 32 - 7, 6);
TestRightTrimFixedTypedArray(i::kExternalUint16Array, 16, 6);
TestRightTrimFixedTypedArray(i::kExternalUint16Array, 16 - 3, 6);
TestRightTrimFixedTypedArray(i::kExternalUint32Array, 8, 6);
TestRightTrimFixedTypedArray(i::kExternalUint32Array, 8 - 1, 6);
// 32-bit cases.
TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 16, 3);
TestRightTrimFixedTypedArray(v8::kExternalUint8Array, 16 - 3, 3);
TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 8, 3);
TestRightTrimFixedTypedArray(v8::kExternalUint16Array, 8 - 1, 3);
TestRightTrimFixedTypedArray(v8::kExternalUint32Array, 4, 3);
TestRightTrimFixedTypedArray(i::kExternalUint8Array, 16, 3);
TestRightTrimFixedTypedArray(i::kExternalUint8Array, 16 - 3, 3);
TestRightTrimFixedTypedArray(i::kExternalUint16Array, 8, 3);
TestRightTrimFixedTypedArray(i::kExternalUint16Array, 8 - 1, 3);
TestRightTrimFixedTypedArray(i::kExternalUint32Array, 4, 3);
}
......@@ -10,32 +10,6 @@
namespace v8 {
std::ostream& operator<<(std::ostream& os, ExternalArrayType type) {
switch (type) {
case kExternalInt8Array:
return os << "ExternalInt8Array";
case kExternalUint8Array:
return os << "ExternalUint8Array";
case kExternalInt16Array:
return os << "ExternalInt16Array";
case kExternalUint16Array:
return os << "ExternalUint16Array";
case kExternalInt32Array:
return os << "ExternalInt32Array";
case kExternalUint32Array:
return os << "ExternalUint32Array";
case kExternalFloat32Array:
return os << "ExternalFloat32Array";
case kExternalFloat64Array:
return os << "ExternalFloat64Array";
case kExternalUint8ClampedArray:
return os << "ExternalUint8ClampedArray";
}
UNREACHABLE();
return os;
}
// static
Isolate* TestWithIsolate::isolate_ = NULL;
......
......@@ -13,8 +13,6 @@
namespace v8 {
std::ostream& operator<<(std::ostream&, ExternalArrayType);
class TestWithIsolate : public virtual ::testing::Test {
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment