Commit 76e24831 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

API: Added functions to retreive information on indexed properties managed by the embedding layer

BUG=737
TEST=test-api/PixelArrayInfo, test-api/ExternalArrayInfo
Review URL: http://codereview.chromium.org/2818003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4860 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 6b474bc1
...@@ -1570,6 +1570,9 @@ class V8EXPORT Object : public Value { ...@@ -1570,6 +1570,9 @@ class V8EXPORT Object : public Value {
* the backing store is preserved while V8 has a reference. * the backing store is preserved while V8 has a reference.
*/ */
void SetIndexedPropertiesToPixelData(uint8_t* data, int length); 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 * Set the backing store of the indexed properties to be managed by the
...@@ -1581,6 +1584,10 @@ class V8EXPORT Object : public Value { ...@@ -1581,6 +1584,10 @@ class V8EXPORT Object : public Value {
void SetIndexedPropertiesToExternalArrayData(void* data, void SetIndexedPropertiesToExternalArrayData(void* data,
ExternalArrayType array_type, ExternalArrayType array_type,
int number_of_elements); int number_of_elements);
bool HasIndexedPropertiesInExternalArrayData();
void* GetIndexedPropertiesExternalArrayData();
ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
int GetIndexedPropertiesExternalArrayDataLength();
static Local<Object> New(); static Local<Object> New();
static inline Object* Cast(Value* obj); static inline Object* Cast(Value* obj);
......
...@@ -2613,6 +2613,35 @@ void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { ...@@ -2613,6 +2613,35 @@ void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) {
} }
bool v8::Object::HasIndexedPropertiesInPixelData() {
ON_BAILOUT("v8::HasIndexedPropertiesInPixelData()", return false);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
return self->HasPixelElements();
}
uint8_t* v8::Object::GetIndexedPropertiesPixelData() {
ON_BAILOUT("v8::GetIndexedPropertiesPixelData()", return NULL);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
if (self->HasPixelElements()) {
return i::PixelArray::cast(self->elements())->external_pointer();
} else {
return NULL;
}
}
int v8::Object::GetIndexedPropertiesPixelDataLength() {
ON_BAILOUT("v8::GetIndexedPropertiesPixelDataLength()", return -1);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
if (self->HasPixelElements()) {
return i::PixelArray::cast(self->elements())->length();
} else {
return -1;
}
}
void v8::Object::SetIndexedPropertiesToExternalArrayData( void v8::Object::SetIndexedPropertiesToExternalArrayData(
void* data, void* data,
ExternalArrayType array_type, ExternalArrayType array_type,
...@@ -2637,6 +2666,60 @@ void v8::Object::SetIndexedPropertiesToExternalArrayData( ...@@ -2637,6 +2666,60 @@ void v8::Object::SetIndexedPropertiesToExternalArrayData(
} }
bool v8::Object::HasIndexedPropertiesInExternalArrayData() {
ON_BAILOUT("v8::HasIndexedPropertiesInExternalArrayData()", return false);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
return self->HasExternalArrayElements();
}
void* v8::Object::GetIndexedPropertiesExternalArrayData() {
ON_BAILOUT("v8::GetIndexedPropertiesExternalArrayData()", return NULL);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
if (self->HasExternalArrayElements()) {
return i::ExternalArray::cast(self->elements())->external_pointer();
} else {
return NULL;
}
}
ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() {
ON_BAILOUT("v8::GetIndexedPropertiesExternalArrayDataType()",
return static_cast<ExternalArrayType>(-1));
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
switch (self->elements()->map()->instance_type()) {
case i::EXTERNAL_BYTE_ARRAY_TYPE:
return kExternalByteArray;
case i::EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
return kExternalUnsignedByteArray;
case i::EXTERNAL_SHORT_ARRAY_TYPE:
return kExternalShortArray;
case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
return kExternalUnsignedShortArray;
case i::EXTERNAL_INT_ARRAY_TYPE:
return kExternalIntArray;
case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
return kExternalUnsignedIntArray;
case i::EXTERNAL_FLOAT_ARRAY_TYPE:
return kExternalFloatArray;
default:
return static_cast<ExternalArrayType>(-1);
}
}
int v8::Object::GetIndexedPropertiesExternalArrayDataLength() {
ON_BAILOUT("v8::GetIndexedPropertiesExternalArrayDataLength()", return 0);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
if (self->HasExternalArrayElements()) {
return i::ExternalArray::cast(self->elements())->length();
} else {
return -1;
}
}
Local<v8::Object> Function::NewInstance() const { Local<v8::Object> Function::NewInstance() const {
return NewInstance(0, NULL); return NewInstance(0, NULL);
} }
......
...@@ -9637,32 +9637,51 @@ THREADED_TEST(PixelArray) { ...@@ -9637,32 +9637,51 @@ THREADED_TEST(PixelArray) {
} }
template <class ExternalArrayClass, class ElementType> THREADED_TEST(PixelArrayInfo) {
static void ExternalArrayTestHelper(v8::ExternalArrayType array_type,
int64_t low,
int64_t high) {
v8::HandleScope scope; v8::HandleScope scope;
LocalContext context; LocalContext context;
const int kElementCount = 40; for (int size = 0; size < 100; size += 10) {
int element_size = 0; uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size));
v8::Handle<v8::Object> obj = v8::Object::New();
obj->SetIndexedPropertiesToPixelData(pixel_data, size);
CHECK(obj->HasIndexedPropertiesInPixelData());
CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData());
CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength());
free(pixel_data);
}
}
static int ExternalArrayElementSize(v8::ExternalArrayType array_type) {
switch (array_type) { switch (array_type) {
case v8::kExternalByteArray: case v8::kExternalByteArray:
case v8::kExternalUnsignedByteArray: case v8::kExternalUnsignedByteArray:
element_size = 1; return 1;
break; break;
case v8::kExternalShortArray: case v8::kExternalShortArray:
case v8::kExternalUnsignedShortArray: case v8::kExternalUnsignedShortArray:
element_size = 2; return 2;
break; break;
case v8::kExternalIntArray: case v8::kExternalIntArray:
case v8::kExternalUnsignedIntArray: case v8::kExternalUnsignedIntArray:
case v8::kExternalFloatArray: case v8::kExternalFloatArray:
element_size = 4; return 4;
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
break; return -1;
} }
}
template <class ExternalArrayClass, class ElementType>
static void ExternalArrayTestHelper(v8::ExternalArrayType array_type,
int64_t low,
int64_t high) {
v8::HandleScope scope;
LocalContext context;
const int kElementCount = 40;
int element_size = ExternalArrayElementSize(array_type);
ElementType* array_data = ElementType* array_data =
static_cast<ElementType*>(malloc(kElementCount * element_size)); static_cast<ElementType*>(malloc(kElementCount * element_size));
i::Handle<ExternalArrayClass> array = i::Handle<ExternalArrayClass> array =
...@@ -10043,6 +10062,35 @@ THREADED_TEST(ExternalArrays) { ...@@ -10043,6 +10062,35 @@ THREADED_TEST(ExternalArrays) {
} }
void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) {
v8::HandleScope scope;
LocalContext context;
for (int size = 0; size < 100; size += 10) {
int element_size = ExternalArrayElementSize(array_type);
void* external_data = malloc(size * element_size);
v8::Handle<v8::Object> obj = v8::Object::New();
obj->SetIndexedPropertiesToExternalArrayData(
external_data, array_type, size);
CHECK(obj->HasIndexedPropertiesInExternalArrayData());
CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData());
CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType());
CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength());
free(external_data);
}
}
THREADED_TEST(ExternalArrayInfo) {
ExternalArrayInfoTestHelper(v8::kExternalByteArray);
ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray);
ExternalArrayInfoTestHelper(v8::kExternalShortArray);
ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray);
ExternalArrayInfoTestHelper(v8::kExternalIntArray);
ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray);
ExternalArrayInfoTestHelper(v8::kExternalFloatArray);
}
THREADED_TEST(ScriptContextDependence) { THREADED_TEST(ScriptContextDependence) {
v8::HandleScope scope; v8::HandleScope scope;
LocalContext c1; LocalContext c1;
......
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