Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 555af843168431b33f6891d9e0981c233160483b..87793aefe38976eda21a5d000a28431889a49a67 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -2756,11 +2756,40 @@ bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) { |
} |
+namespace { |
+ |
+void PrepareExternalArrayElements(i::Handle<i::JSObject> object, |
+ void* data, |
+ ExternalArrayType array_type, |
+ int length) { |
+ i::Handle<i::ExternalArray> array = |
+ i::Factory::NewExternalArray(length, array_type, data); |
+ |
+ // If the object already has external elements, create a new, unique |
+ // map if the element type is now changing, because assumptions about |
+ // generated code based on the receiver's map will be invalid. |
+ i::Handle<i::HeapObject> elements(object->elements()); |
+ bool force_unique_map = |
+ elements->map()->IsUndefined() || |
+ !elements->map()->has_external_array_elements() || |
+ elements->map() != i::Heap::MapForExternalArrayType(array_type); |
+ if (force_unique_map) { |
+ i::Handle<i::Map> external_array_map = |
+ i::Factory::NewExternalArrayElementsMap( |
+ i::Handle<i::Map>(object->map())); |
+ object->set_map(*external_array_map); |
+ } |
+ object->set_elements(*array); |
+} |
+ |
+} // namespace |
+ |
+ |
void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { |
ON_BAILOUT("v8::SetElementsToPixelData()", return); |
ENTER_V8; |
HandleScope scope; |
- if (!ApiCheck(length <= i::PixelArray::kMaxLength, |
+ if (!ApiCheck(length <= i::ExternalPixelArray::kMaxLength, |
"v8::Object::SetIndexedPropertiesToPixelData()", |
"length exceeds max acceptable value")) { |
return; |
@@ -2771,26 +2800,23 @@ void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { |
"JSArray is not supported")) { |
return; |
} |
- i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(length, data); |
- i::Handle<i::Map> pixel_array_map = |
- i::Factory::GetPixelArrayElementsMap(i::Handle<i::Map>(self->map())); |
- self->set_map(*pixel_array_map); |
- self->set_elements(*pixels); |
+ PrepareExternalArrayElements(self, data, kExternalPixelArray, length); |
} |
bool v8::Object::HasIndexedPropertiesInPixelData() { |
ON_BAILOUT("v8::HasIndexedPropertiesInPixelData()", return false); |
i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
- return self->HasPixelElements(); |
+ return self->HasExternalPixelElements(); |
} |
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(); |
+ if (self->HasExternalPixelElements()) { |
+ return i::ExternalPixelArray::cast(self->elements())-> |
+ external_pixel_pointer(); |
} else { |
return NULL; |
} |
@@ -2800,14 +2826,13 @@ uint8_t* v8::Object::GetIndexedPropertiesPixelData() { |
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(); |
+ if (self->HasExternalPixelElements()) { |
+ return i::ExternalPixelArray::cast(self->elements())->length(); |
} else { |
return -1; |
} |
} |
- |
void v8::Object::SetIndexedPropertiesToExternalArrayData( |
void* data, |
ExternalArrayType array_type, |
@@ -2826,12 +2851,7 @@ void v8::Object::SetIndexedPropertiesToExternalArrayData( |
"JSArray is not supported")) { |
return; |
} |
- i::Handle<i::ExternalArray> array = |
- i::Factory::NewExternalArray(length, array_type, data); |
- i::Handle<i::Map> slow_map = |
- i::Factory::GetSlowElementsMap(i::Handle<i::Map>(self->map())); |
- self->set_map(*slow_map); |
- self->set_elements(*array); |
+ PrepareExternalArrayElements(self, data, array_type, length); |
} |
@@ -2872,6 +2892,8 @@ ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { |
return kExternalUnsignedIntArray; |
case i::EXTERNAL_FLOAT_ARRAY_TYPE: |
return kExternalFloatArray; |
+ case i::EXTERNAL_PIXEL_ARRAY_TYPE: |
+ return kExternalPixelArray; |
default: |
return static_cast<ExternalArrayType>(-1); |
} |