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

Side by Side Diff: src/api.cc

Issue 1149203003: Revert of Implement SharedArrayBuffer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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/arraybuffer.js » ('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 2659 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 return Utils::OpenHandle(this)->IsSymbol(); 2670 return Utils::OpenHandle(this)->IsSymbol();
2671 } 2671 }
2672 2672
2673 2673
2674 bool Value::IsArray() const { 2674 bool Value::IsArray() const {
2675 return Utils::OpenHandle(this)->IsJSArray(); 2675 return Utils::OpenHandle(this)->IsJSArray();
2676 } 2676 }
2677 2677
2678 2678
2679 bool Value::IsArrayBuffer() const { 2679 bool Value::IsArrayBuffer() const {
2680 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2680 return Utils::OpenHandle(this)->IsJSArrayBuffer();
2681 return obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared();
2682 } 2681 }
2683 2682
2684 2683
2685 bool Value::IsArrayBufferView() const { 2684 bool Value::IsArrayBufferView() const {
2686 return Utils::OpenHandle(this)->IsJSArrayBufferView(); 2685 return Utils::OpenHandle(this)->IsJSArrayBufferView();
2687 } 2686 }
2688 2687
2689 2688
2690 bool Value::IsTypedArray() const { 2689 bool Value::IsTypedArray() const {
2691 return Utils::OpenHandle(this)->IsJSTypedArray(); 2690 return Utils::OpenHandle(this)->IsJSTypedArray();
2692 } 2691 }
2693 2692
2694 2693
2695 #define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \ 2694 #define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \
2696 bool Value::Is##Type##Array() const { \ 2695 bool Value::Is##Type##Array() const { \
2697 i::Handle<i::Object> obj = Utils::OpenHandle(this); \ 2696 i::Handle<i::Object> obj = Utils::OpenHandle(this); \
2698 return obj->IsJSTypedArray() && \ 2697 return obj->IsJSTypedArray() && \
2699 i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \ 2698 i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \
2700 } 2699 }
2701 2700
2702
2703 TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY) 2701 TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY)
2704 2702
2705 #undef VALUE_IS_TYPED_ARRAY 2703 #undef VALUE_IS_TYPED_ARRAY
2706 2704
2707 2705
2708 bool Value::IsDataView() const { 2706 bool Value::IsDataView() const {
2709 return Utils::OpenHandle(this)->IsJSDataView(); 2707 return Utils::OpenHandle(this)->IsJSDataView();
2710 } 2708 }
2711 2709
2712 2710
2713 bool Value::IsSharedArrayBuffer() const {
2714 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2715 return obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared();
2716 }
2717
2718
2719 bool Value::IsObject() const { 2711 bool Value::IsObject() const {
2720 return Utils::OpenHandle(this)->IsJSObject(); 2712 return Utils::OpenHandle(this)->IsJSObject();
2721 } 2713 }
2722 2714
2723 2715
2724 bool Value::IsNumber() const { 2716 bool Value::IsNumber() const {
2725 return Utils::OpenHandle(this)->IsNumber(); 2717 return Utils::OpenHandle(this)->IsNumber();
2726 } 2718 }
2727 2719
2728 2720
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
3085 3077
3086 void v8::Promise::Resolver::CheckCast(Value* that) { 3078 void v8::Promise::Resolver::CheckCast(Value* that) {
3087 Utils::ApiCheck(that->IsPromise(), 3079 Utils::ApiCheck(that->IsPromise(),
3088 "v8::Promise::Resolver::Cast()", 3080 "v8::Promise::Resolver::Cast()",
3089 "Could not convert to promise resolver"); 3081 "Could not convert to promise resolver");
3090 } 3082 }
3091 3083
3092 3084
3093 void v8::ArrayBuffer::CheckCast(Value* that) { 3085 void v8::ArrayBuffer::CheckCast(Value* that) {
3094 i::Handle<i::Object> obj = Utils::OpenHandle(that); 3086 i::Handle<i::Object> obj = Utils::OpenHandle(that);
3095 Utils::ApiCheck( 3087 Utils::ApiCheck(obj->IsJSArrayBuffer(),
3096 obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared(), 3088 "v8::ArrayBuffer::Cast()",
3097 "v8::ArrayBuffer::Cast()", "Could not convert to ArrayBuffer"); 3089 "Could not convert to ArrayBuffer");
3098 } 3090 }
3099 3091
3100 3092
3101 void v8::ArrayBufferView::CheckCast(Value* that) { 3093 void v8::ArrayBufferView::CheckCast(Value* that) {
3102 i::Handle<i::Object> obj = Utils::OpenHandle(that); 3094 i::Handle<i::Object> obj = Utils::OpenHandle(that);
3103 Utils::ApiCheck(obj->IsJSArrayBufferView(), 3095 Utils::ApiCheck(obj->IsJSArrayBufferView(),
3104 "v8::ArrayBufferView::Cast()", 3096 "v8::ArrayBufferView::Cast()",
3105 "Could not convert to ArrayBufferView"); 3097 "Could not convert to ArrayBufferView");
3106 } 3098 }
3107 3099
(...skipping 22 matching lines...) Expand all
3130 3122
3131 3123
3132 void v8::DataView::CheckCast(Value* that) { 3124 void v8::DataView::CheckCast(Value* that) {
3133 i::Handle<i::Object> obj = Utils::OpenHandle(that); 3125 i::Handle<i::Object> obj = Utils::OpenHandle(that);
3134 Utils::ApiCheck(obj->IsJSDataView(), 3126 Utils::ApiCheck(obj->IsJSDataView(),
3135 "v8::DataView::Cast()", 3127 "v8::DataView::Cast()",
3136 "Could not convert to DataView"); 3128 "Could not convert to DataView");
3137 } 3129 }
3138 3130
3139 3131
3140 void v8::SharedArrayBuffer::CheckCast(Value* that) {
3141 i::Handle<i::Object> obj = Utils::OpenHandle(that);
3142 Utils::ApiCheck(
3143 obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared(),
3144 "v8::SharedArrayBuffer::Cast()",
3145 "Could not convert to SharedArrayBuffer");
3146 }
3147
3148
3149 void v8::Date::CheckCast(v8::Value* that) { 3132 void v8::Date::CheckCast(v8::Value* that) {
3150 i::Handle<i::Object> obj = Utils::OpenHandle(that); 3133 i::Handle<i::Object> obj = Utils::OpenHandle(that);
3151 i::Isolate* isolate = NULL; 3134 i::Isolate* isolate = NULL;
3152 if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate(); 3135 if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
3153 Utils::ApiCheck(isolate != NULL && 3136 Utils::ApiCheck(isolate != NULL &&
3154 obj->HasSpecificClassOf(isolate->heap()->Date_string()), 3137 obj->HasSpecificClassOf(isolate->heap()->Date_string()),
3155 "v8::Date::Cast()", 3138 "v8::Date::Cast()",
3156 "Could not convert to date"); 3139 "Could not convert to date");
3157 } 3140 }
3158 3141
(...skipping 3154 matching lines...) Expand 10 before | Expand all | Expand 10 after
6313 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); 6296 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
6314 return static_cast<size_t>(obj->byte_length()->Number()); 6297 return static_cast<size_t>(obj->byte_length()->Number());
6315 } 6298 }
6316 6299
6317 6300
6318 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) { 6301 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) {
6319 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6302 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6320 LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)"); 6303 LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)");
6321 ENTER_V8(i_isolate); 6304 ENTER_V8(i_isolate);
6322 i::Handle<i::JSArrayBuffer> obj = 6305 i::Handle<i::JSArrayBuffer> obj =
6323 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared); 6306 i_isolate->factory()->NewJSArrayBuffer();
6324 i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length); 6307 i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length);
6325 return Utils::ToLocal(obj); 6308 return Utils::ToLocal(obj);
6326 } 6309 }
6327 6310
6328 6311
6329 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data, 6312 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data,
6330 size_t byte_length, 6313 size_t byte_length,
6331 ArrayBufferCreationMode mode) { 6314 ArrayBufferCreationMode mode) {
6332 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6315 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6333 LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)"); 6316 LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)");
6334 ENTER_V8(i_isolate); 6317 ENTER_V8(i_isolate);
6335 i::Handle<i::JSArrayBuffer> obj = 6318 i::Handle<i::JSArrayBuffer> obj =
6336 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared); 6319 i_isolate->factory()->NewJSArrayBuffer();
6337 i::Runtime::SetupArrayBuffer(i_isolate, obj, 6320 i::Runtime::SetupArrayBuffer(i_isolate, obj,
6338 mode == ArrayBufferCreationMode::kExternalized, 6321 mode == ArrayBufferCreationMode::kExternalized,
6339 data, byte_length); 6322 data, byte_length);
6340 return Utils::ToLocal(obj); 6323 return Utils::ToLocal(obj);
6341 } 6324 }
6342 6325
6343 6326
6344 Local<ArrayBuffer> v8::ArrayBufferView::Buffer() { 6327 Local<ArrayBuffer> v8::ArrayBufferView::Buffer() {
6345 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); 6328 i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
6346 i::Handle<i::JSArrayBuffer> buffer; 6329 i::Handle<i::JSArrayBuffer> buffer;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
6432 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); 6415 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
6433 i::Isolate* isolate = buffer->GetIsolate(); 6416 i::Isolate* isolate = buffer->GetIsolate();
6434 LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)"); 6417 LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)");
6435 ENTER_V8(isolate); 6418 ENTER_V8(isolate);
6436 i::Handle<i::JSDataView> obj = 6419 i::Handle<i::JSDataView> obj =
6437 isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length); 6420 isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length);
6438 return Utils::ToLocal(obj); 6421 return Utils::ToLocal(obj);
6439 } 6422 }
6440 6423
6441 6424
6442 bool v8::SharedArrayBuffer::IsExternal() const {
6443 return Utils::OpenHandle(this)->is_external();
6444 }
6445
6446
6447 v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::Externalize() {
6448 i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
6449 i::Isolate* isolate = self->GetIsolate();
6450 Utils::ApiCheck(!self->is_external(), "v8::SharedArrayBuffer::Externalize",
6451 "SharedArrayBuffer already externalized");
6452 self->set_is_external(true);
6453 isolate->heap()->UnregisterArrayBuffer(self->backing_store());
6454 return GetContents();
6455 }
6456
6457
6458 v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::GetContents() {
6459 i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
6460 size_t byte_length = static_cast<size_t>(self->byte_length()->Number());
6461 Contents contents;
6462 contents.data_ = self->backing_store();
6463 contents.byte_length_ = byte_length;
6464 return contents;
6465 }
6466
6467
6468 size_t v8::SharedArrayBuffer::ByteLength() const {
6469 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
6470 return static_cast<size_t>(obj->byte_length()->Number());
6471 }
6472
6473
6474 Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(Isolate* isolate,
6475 size_t byte_length) {
6476 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6477 LOG_API(i_isolate, "v8::SharedArrayBuffer::New(size_t)");
6478 ENTER_V8(i_isolate);
6479 i::Handle<i::JSArrayBuffer> obj =
6480 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
6481 i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length, true,
6482 i::SharedFlag::kShared);
6483 return Utils::ToLocalShared(obj);
6484 }
6485
6486
6487 Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(
6488 Isolate* isolate, void* data, size_t byte_length,
6489 ArrayBufferCreationMode mode) {
6490 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6491 LOG_API(i_isolate, "v8::SharedArrayBuffer::New(void*, size_t)");
6492 ENTER_V8(i_isolate);
6493 i::Handle<i::JSArrayBuffer> obj =
6494 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
6495 i::Runtime::SetupArrayBuffer(i_isolate, obj,
6496 mode == ArrayBufferCreationMode::kExternalized,
6497 data, byte_length, i::SharedFlag::kShared);
6498 return Utils::ToLocalShared(obj);
6499 }
6500
6501
6502 Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) { 6425 Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) {
6503 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6426 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6504 LOG_API(i_isolate, "Symbol::New()"); 6427 LOG_API(i_isolate, "Symbol::New()");
6505 ENTER_V8(i_isolate); 6428 ENTER_V8(i_isolate);
6506 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); 6429 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
6507 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name)); 6430 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name));
6508 return Utils::ToLocal(result); 6431 return Utils::ToLocal(result);
6509 } 6432 }
6510 6433
6511 6434
(...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after
8156 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8079 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8157 Address callback_address = 8080 Address callback_address =
8158 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8081 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8159 VMState<EXTERNAL> state(isolate); 8082 VMState<EXTERNAL> state(isolate);
8160 ExternalCallbackScope call_scope(isolate, callback_address); 8083 ExternalCallbackScope call_scope(isolate, callback_address);
8161 callback(info); 8084 callback(info);
8162 } 8085 }
8163 8086
8164 8087
8165 } } // namespace v8::internal 8088 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/api.h ('k') | src/arraybuffer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698