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

Unified Diff: Source/bindings/core/v8/inspector/InspectorWrapper.cpp

Issue 1157313006: DevTools: extract common inspector bindigns code into InspectorWrapper (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
Index: Source/bindings/core/v8/inspector/InspectorWrapper.cpp
diff --git a/Source/bindings/core/v8/inspector/InspectorWrapper.cpp b/Source/bindings/core/v8/inspector/InspectorWrapper.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e2ca3794d188f82360d84d40c57256186fd349ae
--- /dev/null
+++ b/Source/bindings/core/v8/inspector/InspectorWrapper.cpp
@@ -0,0 +1,67 @@
+// Copyright 2015 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.
+
+#include "config.h"
+#include "bindings/core/v8/inspector/InspectorWrapper.h"
+
+#include "bindings/core/v8/V8ScriptRunner.h"
+#include "wtf/RefPtr.h"
+
+namespace blink {
+
+v8::Local<v8::FunctionTemplate> InspectorWrapperBase::createWrapperTemplate(v8::Isolate* isolate, const char* className, const Vector<V8MethodConfiguration>& methods, const Vector<V8AttributeConfiguration>& attributes)
+{
+ v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(isolate);
+
+ functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, className, v8::NewStringType::kInternalized).ToLocalChecked());
+ v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate();
+
+ for (auto& config : attributes) {
+ v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.name, v8::NewStringType::kInternalized).ToLocalChecked();
+ instanceTemplate->SetAccessor(v8name, config.callback);
+ }
+
+ for (auto& config : methods) {
+ 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, static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::DontEnum | v8::ReadOnly));
+ }
+
+ return functionTemplate;
+}
+
+v8::Local<v8::Object> InspectorWrapperBase::createWrapper(v8::Local<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context)
+{
+ v8::Local<v8::Function> function;
+ if (!constructorTemplate->GetFunction(context).ToLocal(&function))
+ return v8::Local<v8::Object>();
+
+ // FIXME: don't depend on V8ScriptRunner
+ v8::Isolate* isolate = context->GetIsolate();
+ v8::MaybeLocal<v8::Object> maybeResult = V8ScriptRunner::instantiateObject(isolate, function);
+ v8::Local<v8::Object> result;
+ if (!maybeResult.ToLocal(&result))
+ return v8::Local<v8::Object>();
+
+ return result;
+}
+
+void* InspectorWrapperBase::unwrap(v8::Local<v8::Object> object, const char* name)
+{
+ v8::Isolate* isolate = object->GetIsolate();
+ v8::Local<v8::Value> value = object->GetHiddenValue(v8InternalizedString(isolate, name));
+ if (value.IsEmpty())
+ return nullptr;
+ if (!value->IsExternal())
+ return nullptr;
+ return value.As<v8::External>()->Value();
+}
+
+v8::Local<v8::String> InspectorWrapperBase::v8InternalizedString(v8::Isolate* isolate, const char* name)
+{
+ return v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized).ToLocalChecked();
+}
+
+} // namespace blink
« no previous file with comments | « Source/bindings/core/v8/inspector/InspectorWrapper.h ('k') | Source/bindings/core/v8/inspector/V8InjectedScriptHost.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698