summaryrefslogtreecommitdiffstats
path: root/gin
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-20 08:24:04 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-20 08:24:04 +0000
commit73dcce9f7bb7c309baa7032183772b8fd554db7d (patch)
tree1efbeffecce74feb4ef9e74be9f00e143aefb623 /gin
parent13d954df9638ae453e2b180e7aa3feffa5da768b (diff)
downloadchromium_src-73dcce9f7bb7c309baa7032183772b8fd554db7d.zip
chromium_src-73dcce9f7bb7c309baa7032183772b8fd554db7d.tar.gz
chromium_src-73dcce9f7bb7c309baa7032183772b8fd554db7d.tar.bz2
gin: Make it possible to use gin array buffers when running on top of blink
This approach won't let use share an array buffer with blink, however, it's good enough for a mojo js app. For gin::Wrappable objects that want to interact with blink APIs, they need to provide a custom converter to and from WebArrayBuffer(View) BUG=none R=abarth@chromium.org, dslomov@chromium.org, sky@chromium.org Review URL: https://codereview.chromium.org/172133002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252190 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin')
-rw-r--r--gin/array_buffer.cc29
-rw-r--r--gin/isolate_holder.cc15
-rw-r--r--gin/per_isolate_data.cc6
-rw-r--r--gin/per_isolate_data.h4
-rw-r--r--gin/public/isolate_holder.h10
5 files changed, 44 insertions, 20 deletions
diff --git a/gin/array_buffer.cc b/gin/array_buffer.cc
index ee9f2a5..68237bc 100644
--- a/gin/array_buffer.cc
+++ b/gin/array_buffer.cc
@@ -2,17 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "gin/array_buffer.h"
-
#include <stdlib.h>
+#include "base/logging.h"
+#include "gin/array_buffer.h"
+#include "gin/per_isolate_data.h"
+
namespace gin {
+namespace {
+
+gin::WrapperInfo g_array_buffer_wrapper_info = {gin::kEmbedderNativeGin};
+
+} // namespace
+
COMPILE_ASSERT(V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT == 2,
array_buffers_must_have_two_internal_fields);
-static const int kBufferViewPrivateIndex = 0;
-
// ArrayBufferAllocator -------------------------------------------------------
void* ArrayBufferAllocator::Allocate(size_t length) {
@@ -72,6 +78,7 @@ class ArrayBuffer::Private : public base::RefCounted<ArrayBuffer::Private> {
v8::Persistent<v8::ArrayBuffer> array_buffer_;
scoped_refptr<Private> self_reference_;
+ v8::Isolate* isolate_;
void* buffer_;
size_t length_;
};
@@ -79,28 +86,34 @@ class ArrayBuffer::Private : public base::RefCounted<ArrayBuffer::Private> {
scoped_refptr<ArrayBuffer::Private> ArrayBuffer::Private::From(
v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> array) {
if (array->IsExternal()) {
+ CHECK_EQ(WrapperInfo::From(v8::Handle<v8::Object>::Cast(array)),
+ &g_array_buffer_wrapper_info)
+ << "Cannot mix blink and gin ArrayBuffers";
return make_scoped_refptr(static_cast<Private*>(
- array->GetAlignedPointerFromInternalField(kBufferViewPrivateIndex)));
+ array->GetAlignedPointerFromInternalField(kEncodedValueIndex)));
}
return make_scoped_refptr(new Private(isolate, array));
}
ArrayBuffer::Private::Private(v8::Isolate* isolate,
v8::Handle<v8::ArrayBuffer> array)
- : array_buffer_(isolate, array) {
+ : array_buffer_(isolate, array), isolate_(isolate) {
// Take ownership of the array buffer.
+ CHECK(!array->IsExternal());
v8::ArrayBuffer::Contents contents = array->Externalize();
buffer_ = contents.Data();
length_ = contents.ByteLength();
- array->SetAlignedPointerInInternalField(kBufferViewPrivateIndex, this);
+ array->SetAlignedPointerInInternalField(kWrapperInfoIndex,
+ &g_array_buffer_wrapper_info);
+ array->SetAlignedPointerInInternalField(kEncodedValueIndex, this);
self_reference_ = this; // Cleared in WeakCallback.
array_buffer_.SetWeak(this, WeakCallback);
}
ArrayBuffer::Private::~Private() {
- ArrayBufferAllocator::SharedInstance()->Free(buffer_, length_);
+ PerIsolateData::From(isolate_)->allocator()->Free(buffer_, length_);
}
void ArrayBuffer::Private::WeakCallback(
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc
index 411f26a..430a716 100644
--- a/gin/isolate_holder.cc
+++ b/gin/isolate_holder.cc
@@ -53,14 +53,21 @@ IsolateHolder::IsolateHolder()
constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
base::SysInfo::NumberOfProcessors());
v8::SetResourceConstraints(isolate_, &constraints);
- Init();
+ Init(ArrayBufferAllocator::SharedInstance());
}
IsolateHolder::IsolateHolder(v8::Isolate* isolate)
: isolate_owner_(false),
isolate_(isolate) {
EnsureV8Initialized(false);
- Init();
+ Init(NULL);
+}
+
+IsolateHolder::IsolateHolder(v8::Isolate* isolate,
+ v8::ArrayBuffer::Allocator* allocator)
+ : isolate_owner_(false), isolate_(isolate) {
+ EnsureV8Initialized(false);
+ Init(allocator);
}
IsolateHolder::~IsolateHolder() {
@@ -69,10 +76,10 @@ IsolateHolder::~IsolateHolder() {
isolate_->Dispose();
}
-void IsolateHolder::Init() {
+void IsolateHolder::Init(v8::ArrayBuffer::Allocator* allocator) {
v8::Isolate::Scope isolate_scope(isolate_);
v8::HandleScope handle_scope(isolate_);
- isolate_data_.reset(new PerIsolateData(isolate_));
+ isolate_data_.reset(new PerIsolateData(isolate_, allocator));
}
} // namespace gin
diff --git a/gin/per_isolate_data.cc b/gin/per_isolate_data.cc
index 6c2397b..7de9047 100644
--- a/gin/per_isolate_data.cc
+++ b/gin/per_isolate_data.cc
@@ -5,6 +5,7 @@
#include "gin/per_isolate_data.h"
#include "gin/public/gin_embedders.h"
+using v8::ArrayBuffer;
using v8::Eternal;
using v8::Isolate;
using v8::Local;
@@ -14,8 +15,9 @@ using v8::ObjectTemplate;
namespace gin {
-PerIsolateData::PerIsolateData(Isolate* isolate)
- : isolate_(isolate) {
+PerIsolateData::PerIsolateData(Isolate* isolate,
+ ArrayBuffer::Allocator* allocator)
+ : isolate_(isolate), allocator_(allocator) {
isolate_->SetData(kEmbedderNativeGin, this);
}
diff --git a/gin/per_isolate_data.h b/gin/per_isolate_data.h
index ed93545..18c230b 100644
--- a/gin/per_isolate_data.h
+++ b/gin/per_isolate_data.h
@@ -18,7 +18,7 @@ namespace gin {
// class stores all the Gin-related data that varies per isolate.
class GIN_EXPORT PerIsolateData {
public:
- explicit PerIsolateData(v8::Isolate* isolate);
+ PerIsolateData(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator);
~PerIsolateData();
static PerIsolateData* From(v8::Isolate* isolate);
@@ -39,6 +39,7 @@ class GIN_EXPORT PerIsolateData {
v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info);
v8::Isolate* isolate() { return isolate_; }
+ v8::ArrayBuffer::Allocator* allocator() { return allocator_; }
private:
typedef std::map<
@@ -49,6 +50,7 @@ class GIN_EXPORT PerIsolateData {
// PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is
// owned by the IsolateHolder, which also owns the PerIsolateData.
v8::Isolate* isolate_;
+ v8::ArrayBuffer::Allocator* allocator_;
ObjectTemplateMap object_templates_;
FunctionTemplateMap function_templates_;
diff --git a/gin/public/isolate_holder.h b/gin/public/isolate_holder.h
index d68e4d5..67c2335 100644
--- a/gin/public/isolate_holder.h
+++ b/gin/public/isolate_holder.h
@@ -8,10 +8,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "gin/gin_export.h"
-
-namespace v8 {
-class Isolate;
-}
+#include "v8/include/v8.h"
namespace gin {
@@ -30,6 +27,9 @@ class PerIsolateData;
class GIN_EXPORT IsolateHolder {
public:
IsolateHolder();
+ IsolateHolder(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator);
+
+ // TODO(jochen): Remove.
explicit IsolateHolder(v8::Isolate* isolate);
~IsolateHolder();
@@ -37,7 +37,7 @@ class GIN_EXPORT IsolateHolder {
v8::Isolate* isolate() { return isolate_; }
private:
- void Init();
+ void Init(v8::ArrayBuffer::Allocator* allocator);
bool isolate_owner_;
v8::Isolate* isolate_;