Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: src/api.cc

Issue 6546036: Combine typed and pixel arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: final version Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | src/arm/code-stubs-arm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2738 matching lines...) Expand 10 before | Expand all | Expand 10 after
2749 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, false)); 2749 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, false));
2750 if (hidden_props->IsUndefined()) { 2750 if (hidden_props->IsUndefined()) {
2751 return true; 2751 return true;
2752 } 2752 }
2753 i::Handle<i::JSObject> js_obj(i::JSObject::cast(*hidden_props)); 2753 i::Handle<i::JSObject> js_obj(i::JSObject::cast(*hidden_props));
2754 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); 2754 i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
2755 return i::DeleteProperty(js_obj, key_obj)->IsTrue(); 2755 return i::DeleteProperty(js_obj, key_obj)->IsTrue();
2756 } 2756 }
2757 2757
2758 2758
2759 namespace {
2760
2761 void PrepareExternalArrayElements(i::Handle<i::JSObject> object,
2762 void* data,
2763 ExternalArrayType array_type,
2764 int length) {
2765 i::Handle<i::ExternalArray> array =
2766 i::Factory::NewExternalArray(length, array_type, data);
2767
2768 // If the object already has external elements, create a new, unique
2769 // map if the element type is now changing, because assumptions about
2770 // generated code based on the receiver's map will be invalid.
2771 i::Handle<i::HeapObject> elements(object->elements());
2772 bool force_unique_map =
2773 elements->map()->IsUndefined() ||
2774 !elements->map()->has_external_array_elements() ||
2775 elements->map() != i::Heap::MapForExternalArrayType(array_type);
2776 if (force_unique_map) {
2777 i::Handle<i::Map> external_array_map =
2778 i::Factory::NewExternalArrayElementsMap(
2779 i::Handle<i::Map>(object->map()));
2780 object->set_map(*external_array_map);
2781 }
2782 object->set_elements(*array);
2783 }
2784
2785 } // namespace
2786
2787
2759 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { 2788 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) {
2760 ON_BAILOUT("v8::SetElementsToPixelData()", return); 2789 ON_BAILOUT("v8::SetElementsToPixelData()", return);
2761 ENTER_V8; 2790 ENTER_V8;
2762 HandleScope scope; 2791 HandleScope scope;
2763 if (!ApiCheck(length <= i::PixelArray::kMaxLength, 2792 if (!ApiCheck(length <= i::ExternalPixelArray::kMaxLength,
2764 "v8::Object::SetIndexedPropertiesToPixelData()", 2793 "v8::Object::SetIndexedPropertiesToPixelData()",
2765 "length exceeds max acceptable value")) { 2794 "length exceeds max acceptable value")) {
2766 return; 2795 return;
2767 } 2796 }
2768 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2797 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2769 if (!ApiCheck(!self->IsJSArray(), 2798 if (!ApiCheck(!self->IsJSArray(),
2770 "v8::Object::SetIndexedPropertiesToPixelData()", 2799 "v8::Object::SetIndexedPropertiesToPixelData()",
2771 "JSArray is not supported")) { 2800 "JSArray is not supported")) {
2772 return; 2801 return;
2773 } 2802 }
2774 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(length, data); 2803 PrepareExternalArrayElements(self, data, kExternalPixelArray, length);
2775 i::Handle<i::Map> pixel_array_map =
2776 i::Factory::GetPixelArrayElementsMap(i::Handle<i::Map>(self->map()));
2777 self->set_map(*pixel_array_map);
2778 self->set_elements(*pixels);
2779 } 2804 }
2780 2805
2781 2806
2782 bool v8::Object::HasIndexedPropertiesInPixelData() { 2807 bool v8::Object::HasIndexedPropertiesInPixelData() {
2783 ON_BAILOUT("v8::HasIndexedPropertiesInPixelData()", return false); 2808 ON_BAILOUT("v8::HasIndexedPropertiesInPixelData()", return false);
2784 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2809 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2785 return self->HasPixelElements(); 2810 return self->HasExternalPixelElements();
2786 } 2811 }
2787 2812
2788 2813
2789 uint8_t* v8::Object::GetIndexedPropertiesPixelData() { 2814 uint8_t* v8::Object::GetIndexedPropertiesPixelData() {
2790 ON_BAILOUT("v8::GetIndexedPropertiesPixelData()", return NULL); 2815 ON_BAILOUT("v8::GetIndexedPropertiesPixelData()", return NULL);
2791 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2816 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2792 if (self->HasPixelElements()) { 2817 if (self->HasExternalPixelElements()) {
2793 return i::PixelArray::cast(self->elements())->external_pointer(); 2818 return i::ExternalPixelArray::cast(self->elements())->
2819 external_pixel_pointer();
2794 } else { 2820 } else {
2795 return NULL; 2821 return NULL;
2796 } 2822 }
2797 } 2823 }
2798 2824
2799 2825
2800 int v8::Object::GetIndexedPropertiesPixelDataLength() { 2826 int v8::Object::GetIndexedPropertiesPixelDataLength() {
2801 ON_BAILOUT("v8::GetIndexedPropertiesPixelDataLength()", return -1); 2827 ON_BAILOUT("v8::GetIndexedPropertiesPixelDataLength()", return -1);
2802 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2828 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2803 if (self->HasPixelElements()) { 2829 if (self->HasExternalPixelElements()) {
2804 return i::PixelArray::cast(self->elements())->length(); 2830 return i::ExternalPixelArray::cast(self->elements())->length();
2805 } else { 2831 } else {
2806 return -1; 2832 return -1;
2807 } 2833 }
2808 } 2834 }
2809 2835
2810
2811 void v8::Object::SetIndexedPropertiesToExternalArrayData( 2836 void v8::Object::SetIndexedPropertiesToExternalArrayData(
2812 void* data, 2837 void* data,
2813 ExternalArrayType array_type, 2838 ExternalArrayType array_type,
2814 int length) { 2839 int length) {
2815 ON_BAILOUT("v8::SetIndexedPropertiesToExternalArrayData()", return); 2840 ON_BAILOUT("v8::SetIndexedPropertiesToExternalArrayData()", return);
2816 ENTER_V8; 2841 ENTER_V8;
2817 HandleScope scope; 2842 HandleScope scope;
2818 if (!ApiCheck(length <= i::ExternalArray::kMaxLength, 2843 if (!ApiCheck(length <= i::ExternalArray::kMaxLength,
2819 "v8::Object::SetIndexedPropertiesToExternalArrayData()", 2844 "v8::Object::SetIndexedPropertiesToExternalArrayData()",
2820 "length exceeds max acceptable value")) { 2845 "length exceeds max acceptable value")) {
2821 return; 2846 return;
2822 } 2847 }
2823 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2848 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2824 if (!ApiCheck(!self->IsJSArray(), 2849 if (!ApiCheck(!self->IsJSArray(),
2825 "v8::Object::SetIndexedPropertiesToExternalArrayData()", 2850 "v8::Object::SetIndexedPropertiesToExternalArrayData()",
2826 "JSArray is not supported")) { 2851 "JSArray is not supported")) {
2827 return; 2852 return;
2828 } 2853 }
2829 i::Handle<i::ExternalArray> array = 2854 PrepareExternalArrayElements(self, data, array_type, length);
2830 i::Factory::NewExternalArray(length, array_type, data);
2831 i::Handle<i::Map> slow_map =
2832 i::Factory::GetSlowElementsMap(i::Handle<i::Map>(self->map()));
2833 self->set_map(*slow_map);
2834 self->set_elements(*array);
2835 } 2855 }
2836 2856
2837 2857
2838 bool v8::Object::HasIndexedPropertiesInExternalArrayData() { 2858 bool v8::Object::HasIndexedPropertiesInExternalArrayData() {
2839 ON_BAILOUT("v8::HasIndexedPropertiesInExternalArrayData()", return false); 2859 ON_BAILOUT("v8::HasIndexedPropertiesInExternalArrayData()", return false);
2840 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2860 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2841 return self->HasExternalArrayElements(); 2861 return self->HasExternalArrayElements();
2842 } 2862 }
2843 2863
2844 2864
(...skipping 20 matching lines...) Expand all
2865 case i::EXTERNAL_SHORT_ARRAY_TYPE: 2885 case i::EXTERNAL_SHORT_ARRAY_TYPE:
2866 return kExternalShortArray; 2886 return kExternalShortArray;
2867 case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: 2887 case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
2868 return kExternalUnsignedShortArray; 2888 return kExternalUnsignedShortArray;
2869 case i::EXTERNAL_INT_ARRAY_TYPE: 2889 case i::EXTERNAL_INT_ARRAY_TYPE:
2870 return kExternalIntArray; 2890 return kExternalIntArray;
2871 case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: 2891 case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
2872 return kExternalUnsignedIntArray; 2892 return kExternalUnsignedIntArray;
2873 case i::EXTERNAL_FLOAT_ARRAY_TYPE: 2893 case i::EXTERNAL_FLOAT_ARRAY_TYPE:
2874 return kExternalFloatArray; 2894 return kExternalFloatArray;
2895 case i::EXTERNAL_PIXEL_ARRAY_TYPE:
2896 return kExternalPixelArray;
2875 default: 2897 default:
2876 return static_cast<ExternalArrayType>(-1); 2898 return static_cast<ExternalArrayType>(-1);
2877 } 2899 }
2878 } 2900 }
2879 2901
2880 2902
2881 int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { 2903 int v8::Object::GetIndexedPropertiesExternalArrayDataLength() {
2882 ON_BAILOUT("v8::GetIndexedPropertiesExternalArrayDataLength()", return 0); 2904 ON_BAILOUT("v8::GetIndexedPropertiesExternalArrayDataLength()", return 0);
2883 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2905 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2884 if (self->HasExternalArrayElements()) { 2906 if (self->HasExternalArrayElements()) {
(...skipping 2298 matching lines...) Expand 10 before | Expand all | Expand 10 after
5183 5205
5184 5206
5185 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 5207 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
5186 HandleScopeImplementer* thread_local = 5208 HandleScopeImplementer* thread_local =
5187 reinterpret_cast<HandleScopeImplementer*>(storage); 5209 reinterpret_cast<HandleScopeImplementer*>(storage);
5188 thread_local->IterateThis(v); 5210 thread_local->IterateThis(v);
5189 return storage + ArchiveSpacePerThread(); 5211 return storage + ArchiveSpacePerThread();
5190 } 5212 }
5191 5213
5192 } } // namespace v8::internal 5214 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/arm/code-stubs-arm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698