| OLD | NEW |
| (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 "platform/v8_inspector/InspectorWrapper.h" | |
| 6 | |
| 7 #include "platform/v8_inspector/V8Compat.h" | |
| 8 #include "platform/v8_inspector/public/V8DebuggerClient.h" | |
| 9 | |
| 10 #include <v8-debug.h> | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 v8::Local<v8::FunctionTemplate> InspectorWrapperBase::createWrapperTemplate(v8::
Isolate* isolate, const char* className, const protocol::Vector<V8MethodConfigur
ation>& methods, const protocol::Vector<V8AttributeConfiguration>& attributes) | |
| 15 { | |
| 16 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New
(isolate); | |
| 17 | |
| 18 functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, className, v
8::NewStringType::kInternalized).ToLocalChecked()); | |
| 19 v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceT
emplate(); | |
| 20 | |
| 21 for (auto& config : attributes) { | |
| 22 v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.nam
e, v8::NewStringType::kInternalized).ToLocalChecked(); | |
| 23 instanceTemplate->SetAccessor(v8name, config.callback); | |
| 24 } | |
| 25 | |
| 26 for (auto& config : methods) { | |
| 27 v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.nam
e, v8::NewStringType::kInternalized).ToLocalChecked(); | |
| 28 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate:
:New(isolate, config.callback); | |
| 29 functionTemplate->RemovePrototype(); | |
| 30 instanceTemplate->Set(v8name, functionTemplate, static_cast<v8::Property
Attribute>(v8::DontDelete | v8::DontEnum | v8::ReadOnly)); | |
| 31 } | |
| 32 | |
| 33 return functionTemplate; | |
| 34 } | |
| 35 | |
| 36 v8::Local<v8::Object> InspectorWrapperBase::createWrapper(v8::Local<v8::Function
Template> constructorTemplate, v8::Local<v8::Context> context) | |
| 37 { | |
| 38 v8::MicrotasksScope microtasks(context->GetIsolate(), v8::MicrotasksScope::k
DoNotRunMicrotasks); | |
| 39 v8::Local<v8::Function> function; | |
| 40 if (!constructorTemplate->GetFunction(context).ToLocal(&function)) | |
| 41 return v8::Local<v8::Object>(); | |
| 42 | |
| 43 v8::Local<v8::Object> result; | |
| 44 if (!function->NewInstance(context).ToLocal(&result)) | |
| 45 return v8::Local<v8::Object>(); | |
| 46 return result; | |
| 47 } | |
| 48 | |
| 49 void* InspectorWrapperBase::unwrap(v8::Local<v8::Context> context, v8::Local<v8:
:Object> object, const char* name) | |
| 50 { | |
| 51 v8::Isolate* isolate = context->GetIsolate(); | |
| 52 ASSERT(context != v8::Debug::GetDebugContext(isolate)); | |
| 53 | |
| 54 v8::Local<v8::Private> privateKey = v8::Private::ForApi(isolate, v8::String:
:NewFromUtf8(isolate, name, v8::NewStringType::kInternalized).ToLocalChecked()); | |
| 55 | |
| 56 v8::Local<v8::Value> value; | |
| 57 if (!object->GetPrivate(context, privateKey).ToLocal(&value)) | |
| 58 return nullptr; | |
| 59 if (!value->IsExternal()) | |
| 60 return nullptr; | |
| 61 return value.As<v8::External>()->Value(); | |
| 62 } | |
| 63 | |
| 64 v8::Local<v8::String> InspectorWrapperBase::v8InternalizedString(v8::Isolate* is
olate, const char* name) | |
| 65 { | |
| 66 return v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternaliz
ed).ToLocalChecked(); | |
| 67 } | |
| 68 | |
| 69 } // namespace blink | |
| OLD | NEW |