| 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 "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 |
| OLD | NEW |