Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 4 * Copyright (C) 2012 Google Inc. All rights reserved. | 4 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number: :New(context->GetIsolate(), id) }; | 178 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number: :New(context->GetIsolate(), id) }; |
| 179 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks); | 179 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks); |
| 180 v8::Local<v8::Value> injectedScriptValue; | 180 v8::Local<v8::Value> injectedScriptValue; |
| 181 if (!function->Call(context, windowGlobal, WTF_ARRAY_LENGTH(info), info).ToL ocal(&injectedScriptValue)) | 181 if (!function->Call(context, windowGlobal, WTF_ARRAY_LENGTH(info), info).ToL ocal(&injectedScriptValue)) |
| 182 return v8::Local<v8::Object>(); | 182 return v8::Local<v8::Object>(); |
| 183 if (!injectedScriptValue->IsObject()) | 183 if (!injectedScriptValue->IsObject()) |
| 184 return v8::Local<v8::Object>(); | 184 return v8::Local<v8::Object>(); |
| 185 return injectedScriptValue.As<v8::Object>(); | 185 return injectedScriptValue.As<v8::Object>(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 | |
| 189 InjectedScriptManager::InjectScopeExtensionByName::InjectScopeExtensionByName(Er rorString* errorString, InjectedScript* injectedScript, bool injectToAll, const String16& name) | |
| 190 : m_isolate(injectedScript->isolate()) | |
| 191 , m_symbol(V8Debugger::scopeExtensionSymbol(injectedScript->isolate())) | |
| 192 , m_context(injectedScript->context()) | |
| 193 , m_globals(v8::Array::New(injectedScript->isolate())) | |
|
dgozman
2016/03/17 19:16:11
Let's not create array when we don't need it.
kozy
2016/03/17 20:48:56
Done.
| |
| 194 , m_hasError(false) | |
| 195 { | |
| 196 if (name.isEmpty()) | |
| 197 return; | |
| 198 | |
| 199 v8::Local<v8::Object> scopeExtension; | |
| 200 if (!injectedScript->scopeExtensionByName(errorString, name).ToLocal(&scopeE xtension)) { | |
| 201 m_hasError = true; | |
| 202 return; | |
| 203 } | |
| 204 | |
| 205 if (injectToAll) { | |
| 206 InjectedScriptManager::IdToInjectedScriptMap::iterator end = injectedScr ipt->m_manager->m_idToInjectedScript.end(); | |
| 207 for (InjectedScriptManager::IdToInjectedScriptMap::iterator it = injecte dScript->m_manager->m_idToInjectedScript.begin(); it != end; ++it) { | |
| 208 if (it->second->canAccessInspectedWindow()) | |
| 209 setOnGlobal(it->second->context()->Global(), scopeExtension); | |
| 210 } | |
| 211 } else { | |
| 212 setOnGlobal(m_context->Global(), scopeExtension); | |
| 213 } | |
| 214 } | |
| 215 | |
| 216 InjectedScriptManager::InjectScopeExtensionByName::~InjectScopeExtensionByName() | |
| 217 { | |
| 218 if (!m_globals->Length()) | |
| 219 return; | |
| 220 v8::Local<v8::Symbol> scopeExtensionSymbolValue = V8Debugger::scopeExtension Symbol(m_isolate); | |
| 221 for (size_t i = 0; i < m_globals->Length(); ++i) { | |
| 222 v8::Local<v8::Value> global; | |
| 223 bool success = m_globals->Get(m_context, i).ToLocal(&global); | |
|
dgozman
2016/03/17 19:16:11
Let's use vector.
kozy
2016/03/17 20:48:56
Done.
| |
| 224 ASSERT_UNUSED(success, success); | |
| 225 global->ToObject(m_context).ToLocalChecked()->Delete(m_context, scopeExt ensionSymbolValue); | |
| 226 } | |
| 227 } | |
| 228 | |
| 229 void InjectedScriptManager::InjectScopeExtensionByName::setOnGlobal(v8::Local<v8 ::Object> global, v8::Local<v8::Object> scopeExtension) | |
| 230 { | |
| 231 bool success = global->Set(m_context, m_symbol, scopeExtension).FromMaybe(fa lse); | |
| 232 ASSERT_UNUSED(success, success); | |
| 233 success = m_globals->Set(m_context, m_globals->Length(), global).FromMaybe(f alse); | |
| 234 ASSERT_UNUSED(success, success); | |
| 235 } | |
| 236 | |
| 188 } // namespace blink | 237 } // namespace blink |
| OLD | NEW |