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

Side by Side Diff: Source/bindings/core/v8/inspector/V8JavaScriptCallFrame.cpp

Issue 1168003002: Revert "Oilpan: fix build after r196583." (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 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 #include "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/inspector/V8JavaScriptCallFrame.h" 6 #include "bindings/core/v8/inspector/V8JavaScriptCallFrame.h"
7 7
8 #include "bindings/core/v8/inspector/InspectorWrapper.h"
9 #include "core/inspector/JavaScriptCallFrame.h"
10 #include "wtf/RefPtr.h" 8 #include "wtf/RefPtr.h"
11 #include "wtf/StdLibExtras.h"
12 #include <algorithm>
13 9
14 namespace blink { 10 namespace blink {
15 11
16 namespace { 12 namespace {
17 13
18 void callerAttributeGetterCallback(v8::Local<v8::Name>, const v8::PropertyCallba ckInfo<v8::Value>& info) 14 void callerAttributeGetterCallback(v8::Local<v8::Name>, const v8::PropertyCallba ckInfo<v8::Value>& info)
19 { 15 {
20 JavaScriptCallFrame* impl = V8JavaScriptCallFrame::unwrap(info.Holder()); 16 JavaScriptCallFrame* impl = V8JavaScriptCallFrame::unwrap(info.Holder());
21 JavaScriptCallFrame* caller = impl->caller(); 17 JavaScriptCallFrame* caller = impl->caller();
22 if (!caller) 18 if (!caller)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void scopeTypeMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 126 void scopeTypeMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
131 { 127 {
132 JavaScriptCallFrame* impl = V8JavaScriptCallFrame::unwrap(info.Holder()); 128 JavaScriptCallFrame* impl = V8JavaScriptCallFrame::unwrap(info.Holder());
133 v8::Maybe<int32_t> maybeScopeIndex = info[0]->Int32Value(info.GetIsolate()-> GetCurrentContext()); 129 v8::Maybe<int32_t> maybeScopeIndex = info[0]->Int32Value(info.GetIsolate()-> GetCurrentContext());
134 if (maybeScopeIndex.IsNothing()) 130 if (maybeScopeIndex.IsNothing())
135 return; 131 return;
136 int scopeIndex = maybeScopeIndex.FromJust(); 132 int scopeIndex = maybeScopeIndex.FromJust();
137 info.GetReturnValue().Set(impl->scopeType(scopeIndex)); 133 info.GetReturnValue().Set(impl->scopeType(scopeIndex));
138 } 134 }
139 135
140 char hiddenPropertyName[] = "v8inspector::JavaScriptCallFrame"; 136 struct V8AttributeConfiguration {
141 char className[] = "V8JavaScriptCallFrame"; 137 const char* name;
142 using JavaScriptCallFrameWrapper = InspectorWrapper<JavaScriptCallFrame, hiddenP ropertyName, className>; 138 v8::AccessorNameGetterCallback callback;
139 };
143 140
144 const JavaScriptCallFrameWrapper::V8AttributeConfiguration V8JavaScriptCallFrame Attributes[] = { 141 const V8AttributeConfiguration V8JavaScriptCallFrameAttributes[] = {
145 {"scopeChain", scopeChainAttributeGetterCallback}, 142 {"scopeChain", scopeChainAttributeGetterCallback},
146 {"thisObject", thisObjectAttributeGetterCallback}, 143 {"thisObject", thisObjectAttributeGetterCallback},
147 {"returnValue", returnValueAttributeGetterCallback}, 144 {"returnValue", returnValueAttributeGetterCallback},
148 145
149 {"caller", callerAttributeGetterCallback}, 146 {"caller", callerAttributeGetterCallback},
150 {"sourceID", sourceIDAttributeGetterCallback}, 147 {"sourceID", sourceIDAttributeGetterCallback},
151 {"line", lineAttributeGetterCallback}, 148 {"line", lineAttributeGetterCallback},
152 {"column", columnAttributeGetterCallback}, 149 {"column", columnAttributeGetterCallback},
153 {"stepInPositions", stepInPositionsAttributeGetterCallback}, 150 {"stepInPositions", stepInPositionsAttributeGetterCallback},
154 {"functionName", functionNameAttributeGetterCallback}, 151 {"functionName", functionNameAttributeGetterCallback},
155 {"functionLine", functionLineAttributeGetterCallback}, 152 {"functionLine", functionLineAttributeGetterCallback},
156 {"functionColumn", functionColumnAttributeGetterCallback}, 153 {"functionColumn", functionColumnAttributeGetterCallback},
157 {"isAtReturn", isAtReturnAttributeGetterCallback}, 154 {"isAtReturn", isAtReturnAttributeGetterCallback},
158 }; 155 };
159 156
160 const JavaScriptCallFrameWrapper::V8MethodConfiguration V8JavaScriptCallFrameMet hods[] = { 157 struct V8MethodConfiguration {
158 const char* name;
159 v8::FunctionCallback callback;
160 };
161
162 const V8MethodConfiguration V8JavaScriptCallFrameMethods[] = {
161 {"evaluateWithExceptionDetails", evaluateWithExceptionDetailsMethodCallback} , 163 {"evaluateWithExceptionDetails", evaluateWithExceptionDetailsMethodCallback} ,
162 {"restart", restartMethodCallback}, 164 {"restart", restartMethodCallback},
163 {"setVariableValue", setVariableValueMethodCallback}, 165 {"setVariableValue", setVariableValueMethodCallback},
164 {"scopeType", scopeTypeMethodCallback}, 166 {"scopeType", scopeTypeMethodCallback},
165 }; 167 };
166 168
169 class WeakCallbackData final {
170 public:
171 WeakCallbackData(v8::Isolate* isolate, PassRefPtr<JavaScriptCallFrame> frame , v8::Local<v8::Object> wrapper)
172 : m_frame(frame)
173 , m_persistent(isolate, wrapper)
174 {
175 m_persistent.SetWeak(this, &WeakCallbackData::weakCallback, v8::WeakCall backType::kParameter);
176 }
177
178 RefPtr<JavaScriptCallFrame> m_frame;
179
180 private:
181 static void weakCallback(const v8::WeakCallbackInfo<WeakCallbackData>& info)
182 {
183 delete info.GetParameter();
184 }
185
186 v8::Global<v8::Object> m_persistent;
187 };
188
167 } // namespace 189 } // namespace
168 190
169 v8::Local<v8::FunctionTemplate> V8JavaScriptCallFrame::createWrapperTemplate(v8: :Isolate* isolate) 191 v8::Local<v8::FunctionTemplate> V8JavaScriptCallFrame::createWrapperTemplate(v8: :Isolate* isolate)
170 { 192 {
171 Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_ARRAY_LENGTH (V8JavaScriptCallFrameMethods)); 193 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New (isolate);
172 std::copy(V8JavaScriptCallFrameMethods, V8JavaScriptCallFrameMethods + WTF_A RRAY_LENGTH(V8JavaScriptCallFrameMethods), methods.begin()); 194
173 Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes(WTF_ARRAY_ LENGTH(V8JavaScriptCallFrameAttributes)); 195 functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "JavaScriptC allFrame", v8::NewStringType::kInternalized).ToLocalChecked());
174 std::copy(V8JavaScriptCallFrameAttributes, V8JavaScriptCallFrameAttributes + WTF_ARRAY_LENGTH(V8JavaScriptCallFrameAttributes), attributes.begin()); 196 v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceT emplate();
175 return JavaScriptCallFrameWrapper::createWrapperTemplate(isolate, methods, a ttributes); 197 for (auto& config : V8JavaScriptCallFrameAttributes) {
198 v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.nam e, v8::NewStringType::kInternalized).ToLocalChecked();
199 instanceTemplate->SetAccessor(v8name, config.callback);
200 }
201
202 for (auto& config : V8JavaScriptCallFrameMethods) {
203 v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.nam e, v8::NewStringType::kInternalized).ToLocalChecked();
204 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate: :New(isolate, config.callback);
205 functionTemplate->RemovePrototype();
206 instanceTemplate->Set(v8name, functionTemplate);
207 }
208
209 return functionTemplate;
176 } 210 }
177 211
178 v8::Local<v8::Object> V8JavaScriptCallFrame::wrap(v8::Local<v8::FunctionTemplate > constructorTemplate, v8::Local<v8::Context> context, PassRefPtr<JavaScriptCall Frame> frame) 212 v8::Local<v8::Object> V8JavaScriptCallFrame::wrap(v8::Local<v8::FunctionTemplate > constructorTemplate, v8::Local<v8::Context> context, PassRefPtr<JavaScriptCall Frame> frame)
179 { 213 {
214 RefPtr<JavaScriptCallFrame> impl(frame);
215 v8::Local<v8::Function> function;
216 if (!constructorTemplate->GetFunction(context).ToLocal(&function))
217 return v8::Local<v8::Object>();
218
219 v8::MaybeLocal<v8::Object> maybeResult = function->NewInstance(context);
220 v8::Local<v8::Object> result;
221 if (!maybeResult.ToLocal(&result))
222 return v8::Local<v8::Object>();
223
224 v8::Isolate* isolate = context->GetIsolate();
225 v8::Local<v8::External> objectReference = v8::External::New(isolate, new Wea kCallbackData(isolate, impl, result));
226 result->SetHiddenValue(hiddenPropertyName(isolate), objectReference);
227
180 // Store template for .caller callback 228 // Store template for .caller callback
181 frame->setWrapperTemplate(constructorTemplate, context->GetIsolate()); 229 impl->setWrapperTemplate(constructorTemplate, isolate);
182 return JavaScriptCallFrameWrapper::wrap(constructorTemplate, context, frame) ; 230
231 return result;
183 } 232 }
184 233
185 JavaScriptCallFrame* V8JavaScriptCallFrame::unwrap(v8::Local<v8::Object> object) 234 JavaScriptCallFrame* V8JavaScriptCallFrame::unwrap(v8::Local<v8::Object> object)
186 { 235 {
187 return JavaScriptCallFrameWrapper::unwrap(object); 236 v8::Isolate* isolate = object->GetIsolate();
237 v8::Local<v8::Value> value = object->GetHiddenValue(hiddenPropertyName(isola te));
238 if (value.IsEmpty())
239 return nullptr;
240 if (!value->IsExternal())
241 return nullptr;
242 void* data = value.As<v8::External>()->Value();
243 return reinterpret_cast<WeakCallbackData*>(data)->m_frame.get();
244 }
245
246 v8::Local<v8::String> V8JavaScriptCallFrame::hiddenPropertyName(v8::Isolate* iso late)
247 {
248 return v8::String::NewFromUtf8(isolate, "v8inspector::JavaScriptCallFrame", v8::NewStringType::kInternalized).ToLocalChecked();
188 } 249 }
189 250
190 } // namespace blink 251 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/inspector/V8JavaScriptCallFrame.h ('k') | Source/bindings/core/v8/v8.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698