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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/inspector/V8JavaScriptCallFrame.cpp
diff --git a/Source/bindings/core/v8/inspector/V8JavaScriptCallFrame.cpp b/Source/bindings/core/v8/inspector/V8JavaScriptCallFrame.cpp
index cdd72446a88175ef209d45e39a7fcadfb258f6ec..52e4d112870140d4fdda608527d1efa300da1739 100644
--- a/Source/bindings/core/v8/inspector/V8JavaScriptCallFrame.cpp
+++ b/Source/bindings/core/v8/inspector/V8JavaScriptCallFrame.cpp
@@ -5,11 +5,7 @@
#include "config.h"
#include "bindings/core/v8/inspector/V8JavaScriptCallFrame.h"
-#include "bindings/core/v8/inspector/InspectorWrapper.h"
-#include "core/inspector/JavaScriptCallFrame.h"
#include "wtf/RefPtr.h"
-#include "wtf/StdLibExtras.h"
-#include <algorithm>
namespace blink {
@@ -137,11 +133,12 @@ void scopeTypeMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
info.GetReturnValue().Set(impl->scopeType(scopeIndex));
}
-char hiddenPropertyName[] = "v8inspector::JavaScriptCallFrame";
-char className[] = "V8JavaScriptCallFrame";
-using JavaScriptCallFrameWrapper = InspectorWrapper<JavaScriptCallFrame, hiddenPropertyName, className>;
+struct V8AttributeConfiguration {
+ const char* name;
+ v8::AccessorNameGetterCallback callback;
+};
-const JavaScriptCallFrameWrapper::V8AttributeConfiguration V8JavaScriptCallFrameAttributes[] = {
+const V8AttributeConfiguration V8JavaScriptCallFrameAttributes[] = {
{"scopeChain", scopeChainAttributeGetterCallback},
{"thisObject", thisObjectAttributeGetterCallback},
{"returnValue", returnValueAttributeGetterCallback},
@@ -157,34 +154,98 @@ const JavaScriptCallFrameWrapper::V8AttributeConfiguration V8JavaScriptCallFrame
{"isAtReturn", isAtReturnAttributeGetterCallback},
};
-const JavaScriptCallFrameWrapper::V8MethodConfiguration V8JavaScriptCallFrameMethods[] = {
+struct V8MethodConfiguration {
+ const char* name;
+ v8::FunctionCallback callback;
+};
+
+const V8MethodConfiguration V8JavaScriptCallFrameMethods[] = {
{"evaluateWithExceptionDetails", evaluateWithExceptionDetailsMethodCallback},
{"restart", restartMethodCallback},
{"setVariableValue", setVariableValueMethodCallback},
{"scopeType", scopeTypeMethodCallback},
};
+class WeakCallbackData final {
+public:
+ WeakCallbackData(v8::Isolate* isolate, PassRefPtr<JavaScriptCallFrame> frame, v8::Local<v8::Object> wrapper)
+ : m_frame(frame)
+ , m_persistent(isolate, wrapper)
+ {
+ m_persistent.SetWeak(this, &WeakCallbackData::weakCallback, v8::WeakCallbackType::kParameter);
+ }
+
+ RefPtr<JavaScriptCallFrame> m_frame;
+
+private:
+ static void weakCallback(const v8::WeakCallbackInfo<WeakCallbackData>& info)
+ {
+ delete info.GetParameter();
+ }
+
+ v8::Global<v8::Object> m_persistent;
+};
+
} // namespace
v8::Local<v8::FunctionTemplate> V8JavaScriptCallFrame::createWrapperTemplate(v8::Isolate* isolate)
{
- Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_ARRAY_LENGTH(V8JavaScriptCallFrameMethods));
- std::copy(V8JavaScriptCallFrameMethods, V8JavaScriptCallFrameMethods + WTF_ARRAY_LENGTH(V8JavaScriptCallFrameMethods), methods.begin());
- Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes(WTF_ARRAY_LENGTH(V8JavaScriptCallFrameAttributes));
- std::copy(V8JavaScriptCallFrameAttributes, V8JavaScriptCallFrameAttributes + WTF_ARRAY_LENGTH(V8JavaScriptCallFrameAttributes), attributes.begin());
- return JavaScriptCallFrameWrapper::createWrapperTemplate(isolate, methods, attributes);
+ v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate);
+
+ functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "JavaScriptCallFrame", v8::NewStringType::kInternalized).ToLocalChecked());
+ v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate();
+ for (auto& config : V8JavaScriptCallFrameAttributes) {
+ v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.name, v8::NewStringType::kInternalized).ToLocalChecked();
+ instanceTemplate->SetAccessor(v8name, config.callback);
+ }
+
+ for (auto& config : V8JavaScriptCallFrameMethods) {
+ v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.name, v8::NewStringType::kInternalized).ToLocalChecked();
+ v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate, config.callback);
+ functionTemplate->RemovePrototype();
+ instanceTemplate->Set(v8name, functionTemplate);
+ }
+
+ return functionTemplate;
}
v8::Local<v8::Object> V8JavaScriptCallFrame::wrap(v8::Local<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context, PassRefPtr<JavaScriptCallFrame> frame)
{
+ RefPtr<JavaScriptCallFrame> impl(frame);
+ v8::Local<v8::Function> function;
+ if (!constructorTemplate->GetFunction(context).ToLocal(&function))
+ return v8::Local<v8::Object>();
+
+ v8::MaybeLocal<v8::Object> maybeResult = function->NewInstance(context);
+ v8::Local<v8::Object> result;
+ if (!maybeResult.ToLocal(&result))
+ return v8::Local<v8::Object>();
+
+ v8::Isolate* isolate = context->GetIsolate();
+ v8::Local<v8::External> objectReference = v8::External::New(isolate, new WeakCallbackData(isolate, impl, result));
+ result->SetHiddenValue(hiddenPropertyName(isolate), objectReference);
+
// Store template for .caller callback
- frame->setWrapperTemplate(constructorTemplate, context->GetIsolate());
- return JavaScriptCallFrameWrapper::wrap(constructorTemplate, context, frame);
+ impl->setWrapperTemplate(constructorTemplate, isolate);
+
+ return result;
}
JavaScriptCallFrame* V8JavaScriptCallFrame::unwrap(v8::Local<v8::Object> object)
{
- return JavaScriptCallFrameWrapper::unwrap(object);
+ v8::Isolate* isolate = object->GetIsolate();
+ v8::Local<v8::Value> value = object->GetHiddenValue(hiddenPropertyName(isolate));
+ if (value.IsEmpty())
+ return nullptr;
+ if (!value->IsExternal())
+ return nullptr;
+ void* data = value.As<v8::External>()->Value();
+ return reinterpret_cast<WeakCallbackData*>(data)->m_frame.get();
+}
+
+v8::Local<v8::String> V8JavaScriptCallFrame::hiddenPropertyName(v8::Isolate* isolate)
+{
+ return v8::String::NewFromUtf8(isolate, "v8inspector::JavaScriptCallFrame", v8::NewStringType::kInternalized).ToLocalChecked();
}
} // namespace blink
« 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