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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/InspectorWrapper.h

Issue 1769273004: Remove V8RecrusionScope, cleanup call sites. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium 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 #ifndef InspectorWrapper_h 5 #ifndef InspectorWrapper_h
6 #define InspectorWrapper_h 6 #define InspectorWrapper_h
7 7
8 #include "platform/inspector_protocol/Collections.h" 8 #include "platform/inspector_protocol/Collections.h"
9 #include "wtf/PassOwnPtr.h" 9 #include "wtf/PassOwnPtr.h"
10 #include <v8.h> 10 #include <v8.h>
11 11
12 namespace blink { 12 namespace blink {
13 13
14 class V8DebuggerClient;
15
16 class InspectorWrapperBase { 14 class InspectorWrapperBase {
17 public: 15 public:
18 struct V8MethodConfiguration { 16 struct V8MethodConfiguration {
19 const char* name; 17 const char* name;
20 v8::FunctionCallback callback; 18 v8::FunctionCallback callback;
21 }; 19 };
22 20
23 struct V8AttributeConfiguration { 21 struct V8AttributeConfiguration {
24 const char* name; 22 const char* name;
25 v8::AccessorNameGetterCallback callback; 23 v8::AccessorNameGetterCallback callback;
26 }; 24 };
27 25
28 static v8::Local<v8::FunctionTemplate> createWrapperTemplate(v8::Isolate*, c onst char* className, const protocol::Vector<V8MethodConfiguration>& methods, co nst protocol::Vector<V8AttributeConfiguration>& attributes); 26 static v8::Local<v8::FunctionTemplate> createWrapperTemplate(v8::Isolate*, c onst char* className, const protocol::Vector<V8MethodConfiguration>& methods, co nst protocol::Vector<V8AttributeConfiguration>& attributes);
29 27
30 protected: 28 protected:
31 static v8::Local<v8::Object> createWrapper(V8DebuggerClient*, v8::Local<v8:: FunctionTemplate>, v8::Local<v8::Context>); 29 static v8::Local<v8::Object> createWrapper(v8::Local<v8::FunctionTemplate>, v8::Local<v8::Context>);
32 static void* unwrap(v8::Local<v8::Context>, v8::Local<v8::Object>, const cha r* name); 30 static void* unwrap(v8::Local<v8::Context>, v8::Local<v8::Object>, const cha r* name);
33 31
34 static v8::Local<v8::String> v8InternalizedString(v8::Isolate*, const char* name); 32 static v8::Local<v8::String> v8InternalizedString(v8::Isolate*, const char* name);
35 }; 33 };
36 34
37 template<class T, char* const hiddenPropertyName, char* const className> 35 template<class T, char* const hiddenPropertyName, char* const className>
38 class InspectorWrapper final : public InspectorWrapperBase { 36 class InspectorWrapper final : public InspectorWrapperBase {
39 public: 37 public:
40 class WeakCallbackData final { 38 class WeakCallbackData final {
41 public: 39 public:
(...skipping 22 matching lines...) Expand all
64 } 62 }
65 63
66 v8::Global<v8::Object> m_persistent; 64 v8::Global<v8::Object> m_persistent;
67 }; 65 };
68 66
69 static v8::Local<v8::FunctionTemplate> createWrapperTemplate(v8::Isolate* is olate, const protocol::Vector<V8MethodConfiguration>& methods, const protocol::V ector<V8AttributeConfiguration>& attributes) 67 static v8::Local<v8::FunctionTemplate> createWrapperTemplate(v8::Isolate* is olate, const protocol::Vector<V8MethodConfiguration>& methods, const protocol::V ector<V8AttributeConfiguration>& attributes)
70 { 68 {
71 return InspectorWrapperBase::createWrapperTemplate(isolate, className, m ethods, attributes); 69 return InspectorWrapperBase::createWrapperTemplate(isolate, className, m ethods, attributes);
72 } 70 }
73 71
74 static v8::Local<v8::Object> wrap(V8DebuggerClient* client, v8::Local<v8::Fu nctionTemplate> constructorTemplate, v8::Local<v8::Context> context, T* object) 72 static v8::Local<v8::Object> wrap(v8::Local<v8::FunctionTemplate> constructo rTemplate, v8::Local<v8::Context> context, T* object)
75 { 73 {
76 v8::Context::Scope contextScope(context); 74 v8::Context::Scope contextScope(context);
77 v8::Local<v8::Object> result = InspectorWrapperBase::createWrapper(clien t, constructorTemplate, context); 75 v8::Local<v8::Object> result = InspectorWrapperBase::createWrapper(const ructorTemplate, context);
78 if (result.IsEmpty()) 76 if (result.IsEmpty())
79 return v8::Local<v8::Object>(); 77 return v8::Local<v8::Object>();
80 v8::Isolate* isolate = context->GetIsolate(); 78 v8::Isolate* isolate = context->GetIsolate();
81 v8::Local<v8::External> objectReference = v8::External::New(isolate, new WeakCallbackData(isolate, object, result)); 79 v8::Local<v8::External> objectReference = v8::External::New(isolate, new WeakCallbackData(isolate, object, result));
82 80
83 v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, v8::Str ing::NewFromUtf8(isolate, hiddenPropertyName, v8::NewStringType::kInternalized). ToLocalChecked()); 81 v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, v8::Str ing::NewFromUtf8(isolate, hiddenPropertyName, v8::NewStringType::kInternalized). ToLocalChecked());
84 result->SetPrivate(context, privateKey, objectReference); 82 result->SetPrivate(context, privateKey, objectReference);
85 return result; 83 return result;
86 } 84 }
87 85
88 static v8::Local<v8::Object> wrap(V8DebuggerClient* client, v8::Local<v8::Fu nctionTemplate> constructorTemplate, v8::Local<v8::Context> context, PassOwnPtr< T> object) 86 static v8::Local<v8::Object> wrap(v8::Local<v8::FunctionTemplate> constructo rTemplate, v8::Local<v8::Context> context, PassOwnPtr<T> object)
89 { 87 {
90 v8::Context::Scope contextScope(context); 88 v8::Context::Scope contextScope(context);
91 v8::Local<v8::Object> result = InspectorWrapperBase::createWrapper(clien t, constructorTemplate, context); 89 v8::Local<v8::Object> result = InspectorWrapperBase::createWrapper(const ructorTemplate, context);
92 if (result.IsEmpty()) 90 if (result.IsEmpty())
93 return v8::Local<v8::Object>(); 91 return v8::Local<v8::Object>();
94 v8::Isolate* isolate = context->GetIsolate(); 92 v8::Isolate* isolate = context->GetIsolate();
95 v8::Local<v8::External> objectReference = v8::External::New(isolate, new WeakCallbackData(isolate, object, result)); 93 v8::Local<v8::External> objectReference = v8::External::New(isolate, new WeakCallbackData(isolate, object, result));
96 94
97 v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, v8::Str ing::NewFromUtf8(isolate, hiddenPropertyName, v8::NewStringType::kInternalized). ToLocalChecked()); 95 v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, v8::Str ing::NewFromUtf8(isolate, hiddenPropertyName, v8::NewStringType::kInternalized). ToLocalChecked());
98 result->SetPrivate(context, privateKey, objectReference); 96 result->SetPrivate(context, privateKey, objectReference);
99 return result; 97 return result;
100 } 98 }
101 99
102 static T* unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> objec t) 100 static T* unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> objec t)
103 { 101 {
104 void* data = InspectorWrapperBase::unwrap(context, object, hiddenPropert yName); 102 void* data = InspectorWrapperBase::unwrap(context, object, hiddenPropert yName);
105 if (!data) 103 if (!data)
106 return nullptr; 104 return nullptr;
107 return reinterpret_cast<WeakCallbackData*>(data)->m_impl; 105 return reinterpret_cast<WeakCallbackData*>(data)->m_impl;
108 } 106 }
109 }; 107 };
110 108
111 } // namespace blink 109 } // namespace blink
112 110
113 #endif // InspectorWrapper_h 111 #endif // InspectorWrapper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698