diff options
Diffstat (limited to 'gin')
-rw-r--r-- | gin/gin.gyp | 1 | ||||
-rw-r--r-- | gin/modules/console.cc | 2 | ||||
-rw-r--r-- | gin/modules/module_registry.cc | 2 | ||||
-rw-r--r-- | gin/public/gin_embedders.h | 21 | ||||
-rw-r--r-- | gin/public/wrapper_info.h | 8 | ||||
-rw-r--r-- | gin/test/gtest.cc | 2 | ||||
-rw-r--r-- | gin/wrapper_info.cc | 3 |
7 files changed, 34 insertions, 5 deletions
diff --git a/gin/gin.gyp b/gin/gin.gyp index 8758932..e0ec34c 100644 --- a/gin/gin.gyp +++ b/gin/gin.gyp @@ -48,6 +48,7 @@ 'try_catch.cc', 'try_catch.h', 'wrapper_info.cc', + 'public/gin_embedders.h', 'public/wrapper_info.h', ], }, diff --git a/gin/modules/console.cc b/gin/modules/console.cc index b3614a8..de86451 100644 --- a/gin/modules/console.cc +++ b/gin/modules/console.cc @@ -28,7 +28,7 @@ void Log(const v8::FunctionCallbackInfo<v8::Value>& info) { std::cout << JoinString(messages, ' ') << std::endl; } -WrapperInfo g_wrapper_info = {}; +WrapperInfo g_wrapper_info = { kEmbedderNativeGin }; } // namespace diff --git a/gin/modules/module_registry.cc b/gin/modules/module_registry.cc index fe9218c..8baa482 100644 --- a/gin/modules/module_registry.cc +++ b/gin/modules/module_registry.cc @@ -74,7 +74,7 @@ void Define(const v8::FunctionCallbackInfo<Value>& info) { registry->AddPendingModule(args.isolate(), pending.Pass()); } -WrapperInfo g_wrapper_info = {}; +WrapperInfo g_wrapper_info = { kEmbedderNativeGin }; Local<FunctionTemplate> GetDefineTemplate(Isolate* isolate) { PerIsolateData* data = PerIsolateData::From(isolate); diff --git a/gin/public/gin_embedders.h b/gin/public/gin_embedders.h new file mode 100644 index 0000000..bffe6e0 --- /dev/null +++ b/gin/public/gin_embedders.h @@ -0,0 +1,21 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GIN_PUBLIC_GIN_EMBEDDERS_H_ +#define GIN_PUBLIC_GIN_EMBEDDERS_H_ + +namespace gin { + +// The GinEmbedder is used to identify the owner of embedder data stored on +// v8 objects, and is used as in index into the embedder data slots of a +// v8::Isolate. + +enum GinEmbedder { + kEmbedderNativeGin, + kEmbedderBlink, +}; + +} // namespace gin + +#endif // GIN_PUBLIC_GIN_EMBEDDERS_H_ diff --git a/gin/public/wrapper_info.h b/gin/public/wrapper_info.h index f1c554e..fe047c0 100644 --- a/gin/public/wrapper_info.h +++ b/gin/public/wrapper_info.h @@ -5,10 +5,16 @@ #ifndef GIN_PUBLIC_WRAPPER_INFO_H_ #define GIN_PUBLIC_WRAPPER_INFO_H_ +#include "gin/public/gin_embedders.h" #include "v8/include/v8.h" namespace gin { +// Gin embedder that use their own WrapperInfo-like structs must ensure that +// the first field is of type GinEmbedderId and has the correct id set. They +// also should use kWrapperInfoIndex to start their WrapperInfo-like struct +// and ensure that all objects have kNumberOfInternalFields internal fields. + enum InternalFields { kWrapperInfoIndex, kEncodedValueIndex, @@ -17,7 +23,7 @@ enum InternalFields { struct WrapperInfo { static WrapperInfo* From(v8::Handle<v8::Object> object); - // Currently we just use the address of this struct for identity. + const GinEmbedder embedder; }; } // namespace gin diff --git a/gin/test/gtest.cc b/gin/test/gtest.cc index 2697282..962bd9a 100644 --- a/gin/test/gtest.cc +++ b/gin/test/gtest.cc @@ -54,7 +54,7 @@ void ExpectEqual(const v8::FunctionCallbackInfo<v8::Value>& info) { EXPECT_TRUE(info[0]->StrictEquals(info[1])) << description; } -WrapperInfo g_wrapper_info = {}; +WrapperInfo g_wrapper_info = { kEmbedderNativeGin }; } // namespace diff --git a/gin/wrapper_info.cc b/gin/wrapper_info.cc index c1c6774..6bf8316 100644 --- a/gin/wrapper_info.cc +++ b/gin/wrapper_info.cc @@ -9,8 +9,9 @@ namespace gin { WrapperInfo* WrapperInfo::From(v8::Handle<v8::Object> object) { if (object->InternalFieldCount() != kNumberOfInternalFields) return NULL; - return static_cast<WrapperInfo*>( + WrapperInfo* info = static_cast<WrapperInfo*>( object->GetAlignedPointerFromInternalField(kWrapperInfoIndex)); + return info->embedder == kEmbedderNativeGin ? info : NULL; } } // namespace gin |