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

Side by Side Diff: src/api.cc

Issue 15001041: Externalization API for ArrayBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 6001 matching lines...) Expand 10 before | Expand all | Expand 10 after
6012 i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); 6012 i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon));
6013 EXCEPTION_PREAMBLE(isolate); 6013 EXCEPTION_PREAMBLE(isolate);
6014 ENTER_V8(isolate); 6014 ENTER_V8(isolate);
6015 i::Handle<i::JSObject> result = i::Copy(paragon_handle); 6015 i::Handle<i::JSObject> result = i::Copy(paragon_handle);
6016 has_pending_exception = result.is_null(); 6016 has_pending_exception = result.is_null();
6017 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); 6017 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
6018 return Utils::ToLocal(result); 6018 return Utils::ToLocal(result);
6019 } 6019 }
6020 6020
6021 6021
6022 bool v8::ArrayBuffer::IsExternal() const {
6023 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
Sven Panne 2013/05/23 07:57:01 Just remove this line and the following IsDeadChec
Dmitry Lomov (no reviews) 2013/05/23 08:42:15 Done.
6024 if (IsDeadCheck(isolate, "v8::ArrayBuffer::IsExternal()")) return 0;
6025 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
Sven Panne 2013/05/23 07:57:01 Nit: No need to name this temporary.
Dmitry Lomov (no reviews) 2013/05/23 08:42:15 Done.
6026 return obj->is_external();
6027 }
6028
6029 v8::ArrayBufferContents::~ArrayBufferContents() {
6030 if (data_ != NULL) {
Sven Panne 2013/05/23 07:57:01 No need for this guard, free(NULL) is by definitio
Dmitry Lomov (no reviews) 2013/05/23 08:42:15 Done.
6031 free(data_);
6032 data_ = NULL;
6033 }
6034 byte_length_ = 0;
6035 }
6036
6037
6038 void v8::ArrayBuffer::Externalize(ArrayBufferContents* contents) {
6039 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
Sven Panne 2013/05/23 07:57:01 Kill the IsDeadCheck here, too.
Dmitry Lomov (no reviews) 2013/05/23 08:42:15 Done.
6040 if (IsDeadCheck(isolate, "v8::ArrayBuffer::Data()")) return;
6041 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
6042 ApiCheck(!obj->is_external(),
6043 "v8::ArrayBuffer::Externalize",
6044 "ArrayBuffer already externalized");
6045 obj->set_is_external(true);
6046 size_t byte_length = static_cast<size_t>(obj->byte_length()->Number());
6047 contents->data_ = obj->backing_store();
Sven Panne 2013/05/23 07:57:01 We silently overwrite any previous backing store i
Dmitry Lomov (no reviews) 2013/05/23 08:42:15 As discussed offline, added an ApiCheck On 2013/05
6048 contents->byte_length_ = byte_length;
6049 }
6050
6051
6022 size_t v8::ArrayBuffer::ByteLength() const { 6052 size_t v8::ArrayBuffer::ByteLength() const {
6023 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 6053 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
6024 if (IsDeadCheck(isolate, "v8::ArrayBuffer::ByteLength()")) return 0; 6054 if (IsDeadCheck(isolate, "v8::ArrayBuffer::ByteLength()")) return 0;
6025 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); 6055 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
6026 return static_cast<size_t>(obj->byte_length()->Number()); 6056 return static_cast<size_t>(obj->byte_length()->Number());
6027 } 6057 }
6028 6058
6029 6059
6030 void* v8::ArrayBuffer::Data() const {
6031 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
6032 if (IsDeadCheck(isolate, "v8::ArrayBuffer::Data()")) return 0;
6033 i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
6034 return obj->backing_store();
6035 }
6036
6037
6038 Local<ArrayBuffer> v8::ArrayBuffer::New(size_t byte_length) { 6060 Local<ArrayBuffer> v8::ArrayBuffer::New(size_t byte_length) {
6039 i::Isolate* isolate = i::Isolate::Current(); 6061 i::Isolate* isolate = i::Isolate::Current();
6040 EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(size_t)"); 6062 EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(size_t)");
6041 LOG_API(isolate, "v8::ArrayBuffer::New(size_t)"); 6063 LOG_API(isolate, "v8::ArrayBuffer::New(size_t)");
6042 ENTER_V8(isolate); 6064 ENTER_V8(isolate);
6043 i::Handle<i::JSArrayBuffer> obj = 6065 i::Handle<i::JSArrayBuffer> obj =
6044 isolate->factory()->NewJSArrayBuffer(); 6066 isolate->factory()->NewJSArrayBuffer();
6045 i::Runtime::SetupArrayBufferAllocatingData(isolate, obj, byte_length); 6067 i::Runtime::SetupArrayBufferAllocatingData(isolate, obj, byte_length);
6046 return Utils::ToLocal(obj); 6068 return Utils::ToLocal(obj);
6047 } 6069 }
6048 6070
6049 6071
6050 Local<ArrayBuffer> v8::ArrayBuffer::New(void* data, size_t byte_length) { 6072 Local<ArrayBuffer> v8::ArrayBuffer::New(void* data, size_t byte_length) {
6051 i::Isolate* isolate = i::Isolate::Current(); 6073 i::Isolate* isolate = i::Isolate::Current();
6052 EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(void*, size_t)"); 6074 EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(void*, size_t)");
6053 LOG_API(isolate, "v8::ArrayBuffer::New(void*, size_t)"); 6075 LOG_API(isolate, "v8::ArrayBuffer::New(void*, size_t)");
6054 ENTER_V8(isolate); 6076 ENTER_V8(isolate);
6055 i::Handle<i::JSArrayBuffer> obj = 6077 i::Handle<i::JSArrayBuffer> obj =
6056 isolate->factory()->NewJSArrayBuffer(); 6078 isolate->factory()->NewJSArrayBuffer();
6057 i::Runtime::SetupArrayBuffer(isolate, obj, data, byte_length); 6079 i::Runtime::SetupArrayBuffer(isolate, obj, true, data, byte_length);
6058 return Utils::ToLocal(obj); 6080 return Utils::ToLocal(obj);
6059 } 6081 }
6060 6082
6061 6083
6062 Local<ArrayBuffer> v8::TypedArray::Buffer() { 6084 Local<ArrayBuffer> v8::TypedArray::Buffer() {
6063 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 6085 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
6064 if (IsDeadCheck(isolate, "v8::TypedArray::Buffer()")) 6086 if (IsDeadCheck(isolate, "v8::TypedArray::Buffer()"))
6065 return Local<ArrayBuffer>(); 6087 return Local<ArrayBuffer>();
6066 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this); 6088 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this);
6067 ASSERT(obj->buffer()->IsJSArrayBuffer()); 6089 ASSERT(obj->buffer()->IsJSArrayBuffer());
(...skipping 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after
7874 7896
7875 v->VisitPointers(blocks_.first(), first_block_limit_); 7897 v->VisitPointers(blocks_.first(), first_block_limit_);
7876 7898
7877 for (int i = 1; i < blocks_.length(); i++) { 7899 for (int i = 1; i < blocks_.length(); i++) {
7878 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); 7900 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
7879 } 7901 }
7880 } 7902 }
7881 7903
7882 7904
7883 } } // namespace v8::internal 7905 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698