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

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

Issue 1165453007: Reland "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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "bindings/core/v8/inspector/InspectorWrapper.h"
7
8 #include "bindings/core/v8/V8ScriptRunner.h"
9 #include "wtf/RefPtr.h"
10
11 namespace blink {
12
13 v8::Local<v8::FunctionTemplate> InspectorWrapperBase::createWrapperTemplate(v8:: Isolate* isolate, const char* className, const Vector<V8MethodConfiguration>& me thods, const Vector<V8AttributeConfiguration>& attributes)
14 {
15 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New (isolate);
16
17 functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, className, v 8::NewStringType::kInternalized).ToLocalChecked());
18 v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceT emplate();
19
20 for (auto& config : attributes) {
21 v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.nam e, v8::NewStringType::kInternalized).ToLocalChecked();
22 instanceTemplate->SetAccessor(v8name, config.callback);
23 }
24
25 for (auto& config : methods) {
26 v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.nam e, v8::NewStringType::kInternalized).ToLocalChecked();
27 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate: :New(isolate, config.callback);
28 functionTemplate->RemovePrototype();
29 instanceTemplate->Set(v8name, functionTemplate, static_cast<v8::Property Attribute>(v8::DontDelete | v8::DontEnum | v8::ReadOnly));
30 }
31
32 return functionTemplate;
33 }
34
35 v8::Local<v8::Object> InspectorWrapperBase::createWrapper(v8::Local<v8::Function Template> constructorTemplate, v8::Local<v8::Context> context)
36 {
37 v8::Local<v8::Function> function;
38 if (!constructorTemplate->GetFunction(context).ToLocal(&function))
39 return v8::Local<v8::Object>();
40
41 // FIXME: don't depend on V8ScriptRunner
42 v8::Isolate* isolate = context->GetIsolate();
43 v8::MaybeLocal<v8::Object> maybeResult = V8ScriptRunner::instantiateObject(i solate, function);
44 v8::Local<v8::Object> result;
45 if (!maybeResult.ToLocal(&result))
46 return v8::Local<v8::Object>();
47
48 return result;
49 }
50
51 void* InspectorWrapperBase::unwrap(v8::Local<v8::Object> object, const char* nam e)
52 {
53 v8::Isolate* isolate = object->GetIsolate();
54 v8::Local<v8::Value> value = object->GetHiddenValue(v8InternalizedString(iso late, name));
55 if (value.IsEmpty())
56 return nullptr;
57 if (!value->IsExternal())
58 return nullptr;
59 return value.As<v8::External>()->Value();
60 }
61
62 v8::Local<v8::String> InspectorWrapperBase::v8InternalizedString(v8::Isolate* is olate, const char* name)
63 {
64 return v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternaliz ed).ToLocalChecked();
65 }
66
67 } // namespace blink
OLDNEW
« 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