| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/inspector/InjectedScriptNative.h" | 5 #include "src/inspector/InjectedScriptNative.h" |
| 6 | 6 |
| 7 namespace v8_inspector { | 7 namespace v8_inspector { |
| 8 | 8 |
| 9 InjectedScriptNative::InjectedScriptNative(v8::Isolate* isolate) | 9 InjectedScriptNative::InjectedScriptNative(v8::Isolate* isolate) |
| 10 : m_lastBoundObjectId(1), m_isolate(isolate) {} | 10 : m_lastBoundObjectId(1), m_isolate(isolate) {} |
| 11 | 11 |
| 12 static const char privateKeyName[] = "v8-inspector#injectedScript"; | 12 static const char privateKeyName[] = "v8-inspector#injectedScript"; |
| 13 | 13 |
| 14 InjectedScriptNative::~InjectedScriptNative() {} | 14 InjectedScriptNative::~InjectedScriptNative() {} |
| 15 | 15 |
| 16 void InjectedScriptNative::setOnInjectedScriptHost( | 16 void InjectedScriptNative::setOnInjectedScriptHost( |
| 17 v8::Local<v8::Object> injectedScriptHost) { | 17 v8::Local<v8::Object> injectedScriptHost) { |
| 18 v8::HandleScope handleScope(m_isolate); | 18 v8::HandleScope handleScope(m_isolate); |
| 19 v8::Local<v8::External> external = v8::External::New(m_isolate, this); | 19 v8::Local<v8::External> external = v8::External::New(m_isolate, this); |
| 20 v8::Local<v8::Private> privateKey = v8::Private::ForApi( | 20 v8::Local<v8::Private> privateKey = v8::Private::ForApi( |
| 21 m_isolate, v8::String::NewFromUtf8(m_isolate, privateKeyName, | 21 m_isolate, v8::String::NewFromUtf8(m_isolate, privateKeyName, |
| 22 v8::NewStringType::kInternalized) | 22 v8::NewStringType::kInternalized) |
| 23 .ToLocalChecked()); | 23 .ToLocalChecked()); |
| 24 injectedScriptHost->SetPrivate(m_isolate->GetCurrentContext(), privateKey, | 24 injectedScriptHost->SetPrivate(m_isolate->GetCurrentContext(), privateKey, |
| 25 external); | 25 external); |
| 26 } | 26 } |
| 27 | 27 |
| 28 InjectedScriptNative* InjectedScriptNative::fromInjectedScriptHost( | 28 InjectedScriptNative* InjectedScriptNative::fromInjectedScriptHost( |
| 29 v8::Local<v8::Object> injectedScriptObject) { | 29 v8::Isolate* isolate, v8::Local<v8::Object> injectedScriptObject) { |
| 30 v8::Isolate* isolate = injectedScriptObject->GetIsolate(); | |
| 31 v8::HandleScope handleScope(isolate); | 30 v8::HandleScope handleScope(isolate); |
| 32 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 31 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 33 v8::Local<v8::Private> privateKey = v8::Private::ForApi( | 32 v8::Local<v8::Private> privateKey = v8::Private::ForApi( |
| 34 isolate, v8::String::NewFromUtf8(isolate, privateKeyName, | 33 isolate, v8::String::NewFromUtf8(isolate, privateKeyName, |
| 35 v8::NewStringType::kInternalized) | 34 v8::NewStringType::kInternalized) |
| 36 .ToLocalChecked()); | 35 .ToLocalChecked()); |
| 37 v8::Local<v8::Value> value = | 36 v8::Local<v8::Value> value = |
| 38 injectedScriptObject->GetPrivate(context, privateKey).ToLocalChecked(); | 37 injectedScriptObject->GetPrivate(context, privateKey).ToLocalChecked(); |
| 39 DCHECK(value->IsExternal()); | 38 DCHECK(value->IsExternal()); |
| 40 v8::Local<v8::External> external = value.As<v8::External>(); | 39 v8::Local<v8::External> external = value.As<v8::External>(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 80 |
| 82 String16 InjectedScriptNative::groupName(int objectId) const { | 81 String16 InjectedScriptNative::groupName(int objectId) const { |
| 83 if (objectId <= 0) return String16(); | 82 if (objectId <= 0) return String16(); |
| 84 IdToObjectGroupName::const_iterator iterator = | 83 IdToObjectGroupName::const_iterator iterator = |
| 85 m_idToObjectGroupName.find(objectId); | 84 m_idToObjectGroupName.find(objectId); |
| 86 return iterator != m_idToObjectGroupName.end() ? iterator->second | 85 return iterator != m_idToObjectGroupName.end() ? iterator->second |
| 87 : String16(); | 86 : String16(); |
| 88 } | 87 } |
| 89 | 88 |
| 90 } // namespace v8_inspector | 89 } // namespace v8_inspector |
| OLD | NEW |