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

Side by Side Diff: src/api.cc

Issue 1092923002: Remove support for externally backed elements from the API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « src/api.h ('k') | src/d8.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 2655 matching lines...) Expand 10 before | Expand all | Expand 10 after
2666 bool Value::IsArrayBufferView() const { 2666 bool Value::IsArrayBufferView() const {
2667 return Utils::OpenHandle(this)->IsJSArrayBufferView(); 2667 return Utils::OpenHandle(this)->IsJSArrayBufferView();
2668 } 2668 }
2669 2669
2670 2670
2671 bool Value::IsTypedArray() const { 2671 bool Value::IsTypedArray() const {
2672 return Utils::OpenHandle(this)->IsJSTypedArray(); 2672 return Utils::OpenHandle(this)->IsJSTypedArray();
2673 } 2673 }
2674 2674
2675 2675
2676 #define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \ 2676 #define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \
2677 bool Value::Is##Type##Array() const { \ 2677 bool Value::Is##Type##Array() const { \
2678 i::Handle<i::Object> obj = Utils::OpenHandle(this); \ 2678 i::Handle<i::Object> obj = Utils::OpenHandle(this); \
2679 return obj->IsJSTypedArray() && \ 2679 return obj->IsJSTypedArray() && \
2680 i::JSTypedArray::cast(*obj)->type() == kExternal##Type##Array; \ 2680 i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \
2681 } 2681 }
2682 2682
2683 TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY) 2683 TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY)
2684 2684
2685 #undef VALUE_IS_TYPED_ARRAY 2685 #undef VALUE_IS_TYPED_ARRAY
2686 2686
2687 2687
2688 bool Value::IsDataView() const { 2688 bool Value::IsDataView() const {
2689 return Utils::OpenHandle(this)->IsJSDataView(); 2689 return Utils::OpenHandle(this)->IsJSDataView();
2690 } 2690 }
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
3084 i::Handle<i::Object> obj = Utils::OpenHandle(that); 3084 i::Handle<i::Object> obj = Utils::OpenHandle(that);
3085 Utils::ApiCheck(obj->IsJSTypedArray(), 3085 Utils::ApiCheck(obj->IsJSTypedArray(),
3086 "v8::TypedArray::Cast()", 3086 "v8::TypedArray::Cast()",
3087 "Could not convert to TypedArray"); 3087 "Could not convert to TypedArray");
3088 } 3088 }
3089 3089
3090 3090
3091 #define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype, size) \ 3091 #define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype, size) \
3092 void v8::Type##Array::CheckCast(Value* that) { \ 3092 void v8::Type##Array::CheckCast(Value* that) { \
3093 i::Handle<i::Object> obj = Utils::OpenHandle(that); \ 3093 i::Handle<i::Object> obj = Utils::OpenHandle(that); \
3094 Utils::ApiCheck(obj->IsJSTypedArray() && \ 3094 Utils::ApiCheck( \
3095 i::JSTypedArray::cast(*obj)->type() == \ 3095 obj->IsJSTypedArray() && \
3096 kExternal##Type##Array, \ 3096 i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array, \
3097 "v8::" #Type "Array::Cast()", \ 3097 "v8::" #Type "Array::Cast()", "Could not convert to " #Type "Array"); \
3098 "Could not convert to " #Type "Array"); \
3099 } 3098 }
3100 3099
3101 3100
3102 TYPED_ARRAYS(CHECK_TYPED_ARRAY_CAST) 3101 TYPED_ARRAYS(CHECK_TYPED_ARRAY_CAST)
3103 3102
3104 #undef CHECK_TYPED_ARRAY_CAST 3103 #undef CHECK_TYPED_ARRAY_CAST
3105 3104
3106 3105
3107 void v8::DataView::CheckCast(Value* that) { 3106 void v8::DataView::CheckCast(Value* that) {
3108 i::Handle<i::Object> obj = Utils::OpenHandle(that); 3107 i::Handle<i::Object> obj = Utils::OpenHandle(that);
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
4191 i::HandleScope scope(isolate); 4190 i::HandleScope scope(isolate);
4192 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 4191 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
4193 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); 4192 i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
4194 i::Handle<i::String> key_string = 4193 i::Handle<i::String> key_string =
4195 isolate->factory()->InternalizeString(key_obj); 4194 isolate->factory()->InternalizeString(key_obj);
4196 i::JSObject::DeleteHiddenProperty(self, key_string); 4195 i::JSObject::DeleteHiddenProperty(self, key_string);
4197 return true; 4196 return true;
4198 } 4197 }
4199 4198
4200 4199
4201 namespace {
4202
4203 static i::ElementsKind GetElementsKindFromExternalArrayType(
4204 ExternalArrayType array_type) {
4205 switch (array_type) {
4206 #define ARRAY_TYPE_TO_ELEMENTS_KIND(Type, type, TYPE, ctype, size) \
4207 case kExternal##Type##Array: \
4208 return i::EXTERNAL_##TYPE##_ELEMENTS;
4209
4210 TYPED_ARRAYS(ARRAY_TYPE_TO_ELEMENTS_KIND)
4211 #undef ARRAY_TYPE_TO_ELEMENTS_KIND
4212 }
4213 UNREACHABLE();
4214 return i::DICTIONARY_ELEMENTS;
4215 }
4216
4217
4218 void PrepareExternalArrayElements(i::Handle<i::JSObject> object,
4219 void* data,
4220 ExternalArrayType array_type,
4221 int length) {
4222 i::Isolate* isolate = object->GetIsolate();
4223 i::Handle<i::ExternalArray> array =
4224 isolate->factory()->NewExternalArray(length, array_type, data);
4225
4226 i::Handle<i::Map> external_array_map =
4227 i::JSObject::GetElementsTransitionMap(
4228 object,
4229 GetElementsKindFromExternalArrayType(array_type));
4230
4231 i::JSObject::SetMapAndElements(object, external_array_map, array);
4232 }
4233
4234 } // namespace
4235
4236
4237 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) {
4238 auto self = Utils::OpenHandle(this);
4239 auto isolate = self->GetIsolate();
4240 ENTER_V8(isolate);
4241 i::HandleScope scope(isolate);
4242 if (!Utils::ApiCheck(length >= 0 &&
4243 length <= i::ExternalUint8ClampedArray::kMaxLength,
4244 "v8::Object::SetIndexedPropertiesToPixelData()",
4245 "length exceeds max acceptable value")) {
4246 return;
4247 }
4248 if (!Utils::ApiCheck(!self->IsJSArray(),
4249 "v8::Object::SetIndexedPropertiesToPixelData()",
4250 "JSArray is not supported")) {
4251 return;
4252 }
4253 PrepareExternalArrayElements(self, data, kExternalUint8ClampedArray, length);
4254 }
4255
4256
4257 bool v8::Object::HasIndexedPropertiesInPixelData() {
4258 auto self = Utils::OpenHandle(this);
4259 return self->HasExternalUint8ClampedElements();
4260 }
4261
4262
4263 uint8_t* v8::Object::GetIndexedPropertiesPixelData() {
4264 auto self = Utils::OpenHandle(this);
4265 if (self->HasExternalUint8ClampedElements()) {
4266 return i::ExternalUint8ClampedArray::cast(self->elements())->
4267 external_uint8_clamped_pointer();
4268 }
4269 return nullptr;
4270 }
4271
4272
4273 int v8::Object::GetIndexedPropertiesPixelDataLength() {
4274 auto self = Utils::OpenHandle(this);
4275 if (self->HasExternalUint8ClampedElements()) {
4276 return i::ExternalUint8ClampedArray::cast(self->elements())->length();
4277 }
4278 return -1;
4279 }
4280
4281
4282 void v8::Object::SetIndexedPropertiesToExternalArrayData(
4283 void* data,
4284 ExternalArrayType array_type,
4285 int length) {
4286 auto self = Utils::OpenHandle(this);
4287 auto isolate = self->GetIsolate();
4288 ENTER_V8(isolate);
4289 i::HandleScope scope(isolate);
4290 if (!Utils::ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength,
4291 "v8::Object::SetIndexedPropertiesToExternalArrayData()",
4292 "length exceeds max acceptable value")) {
4293 return;
4294 }
4295 if (!Utils::ApiCheck(!self->IsJSArray(),
4296 "v8::Object::SetIndexedPropertiesToExternalArrayData()",
4297 "JSArray is not supported")) {
4298 return;
4299 }
4300 PrepareExternalArrayElements(self, data, array_type, length);
4301 }
4302
4303
4304 bool v8::Object::HasIndexedPropertiesInExternalArrayData() {
4305 auto self = Utils::OpenHandle(this);
4306 return self->HasExternalArrayElements();
4307 }
4308
4309
4310 void* v8::Object::GetIndexedPropertiesExternalArrayData() {
4311 auto self = Utils::OpenHandle(this);
4312 if (self->HasExternalArrayElements()) {
4313 return i::ExternalArray::cast(self->elements())->external_pointer();
4314 }
4315 return nullptr;
4316 }
4317
4318
4319 ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() {
4320 auto self = Utils::OpenHandle(this);
4321 switch (self->elements()->map()->instance_type()) {
4322 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \
4323 case i::EXTERNAL_##TYPE##_ARRAY_TYPE: \
4324 return kExternal##Type##Array;
4325 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE)
4326 #undef INSTANCE_TYPE_TO_ARRAY_TYPE
4327 default:
4328 return static_cast<ExternalArrayType>(-1);
4329 }
4330 }
4331
4332
4333 int v8::Object::GetIndexedPropertiesExternalArrayDataLength() {
4334 auto self = Utils::OpenHandle(this);
4335 if (self->HasExternalArrayElements()) {
4336 return i::ExternalArray::cast(self->elements())->length();
4337 }
4338 return -1;
4339 }
4340
4341
4342 bool v8::Object::IsCallable() { 4200 bool v8::Object::IsCallable() {
4343 auto self = Utils::OpenHandle(this); 4201 auto self = Utils::OpenHandle(this);
4344 return self->IsCallable(); 4202 return self->IsCallable();
4345 } 4203 }
4346 4204
4347 4205
4348 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context, 4206 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context,
4349 Handle<Value> recv, int argc, 4207 Handle<Value> recv, int argc,
4350 Handle<Value> argv[]) { 4208 Handle<Value> argv[]) {
4351 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, "v8::Object::CallAsFunction()", 4209 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, "v8::Object::CallAsFunction()",
(...skipping 2155 matching lines...) Expand 10 before | Expand all | Expand 10 after
6507 "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)"); \ 6365 "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)"); \
6508 ENTER_V8(isolate); \ 6366 ENTER_V8(isolate); \
6509 if (!Utils::ApiCheck(length <= static_cast<size_t>(i::Smi::kMaxValue), \ 6367 if (!Utils::ApiCheck(length <= static_cast<size_t>(i::Smi::kMaxValue), \
6510 "v8::" #Type \ 6368 "v8::" #Type \
6511 "Array::New(Handle<ArrayBuffer>, size_t, size_t)", \ 6369 "Array::New(Handle<ArrayBuffer>, size_t, size_t)", \
6512 "length exceeds max allowed value")) { \ 6370 "length exceeds max allowed value")) { \
6513 return Local<Type##Array>(); \ 6371 return Local<Type##Array>(); \
6514 } \ 6372 } \
6515 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); \ 6373 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); \
6516 i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \ 6374 i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \
6517 v8::kExternal##Type##Array, buffer, byte_offset, length); \ 6375 i::kExternal##Type##Array, buffer, byte_offset, length); \
6518 return Utils::ToLocal##Type##Array(obj); \ 6376 return Utils::ToLocal##Type##Array(obj); \
6519 } 6377 }
6520 6378
6521 6379
6522 TYPED_ARRAYS(TYPED_ARRAY_NEW) 6380 TYPED_ARRAYS(TYPED_ARRAY_NEW)
6523 #undef TYPED_ARRAY_NEW 6381 #undef TYPED_ARRAY_NEW
6524 6382
6525 Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer, 6383 Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer,
6526 size_t byte_offset, size_t byte_length) { 6384 size_t byte_offset, size_t byte_length) {
6527 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); 6385 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
(...skipping 1582 matching lines...) Expand 10 before | Expand all | Expand 10 after
8110 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7968 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8111 Address callback_address = 7969 Address callback_address =
8112 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7970 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8113 VMState<EXTERNAL> state(isolate); 7971 VMState<EXTERNAL> state(isolate);
8114 ExternalCallbackScope call_scope(isolate, callback_address); 7972 ExternalCallbackScope call_scope(isolate, callback_address);
8115 callback(info); 7973 callback(info);
8116 } 7974 }
8117 7975
8118 7976
8119 } } // namespace v8::internal 7977 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/api.h ('k') | src/d8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698