Commit 4a24b642 authored by pfeldman's avatar pfeldman Committed by Commit bot

DevTools: migrate injectedscript from ScriptValue to v8::Global.

BUG=580337

Review URL: https://codereview.chromium.org/1648463002

Cr-Commit-Position: refs/heads/master@{#371952}
parent 0915b0fa
......@@ -30,7 +30,6 @@
#include "core/inspector/InjectedScriptManager.h"
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8ScriptRunner.h"
#include "core/inspector/InjectedScriptHost.h"
......
......@@ -31,7 +31,6 @@
#ifndef InjectedScript_h
#define InjectedScript_h
#include "bindings/core/v8/ScriptValue.h"
#include "core/InspectorTypeBuilder.h"
#include "core/inspector/InjectedScriptManager.h"
#include "core/inspector/InjectedScriptNative.h"
......@@ -41,6 +40,7 @@
namespace blink {
class InjectedScriptManager;
class JSONValue;
class RemoteObjectId;
class ScriptFunctionCall;
......@@ -53,11 +53,6 @@ class InjectedScript final {
public:
~InjectedScript();
ScriptState* scriptState() const
{
return m_injectedScriptObject.scriptState();
}
void evaluate(
ErrorString*,
const String& expression,
......@@ -112,20 +107,25 @@ public:
void setCustomObjectFormatterEnabled(bool);
int contextId() { return m_contextId; }
v8::Isolate* isolate() { return m_isolate; }
v8::Local<v8::Context> context() const;
void dispose();
private:
friend InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context>);
InjectedScript(v8::Local<v8::Object>, V8DebuggerClient*, PassRefPtr<InjectedScriptNative>, int contextId);
InjectedScript(InjectedScriptManager*, v8::Local<v8::Context>, v8::Local<v8::Object>, V8DebuggerClient*, PassRefPtr<InjectedScriptNative>, int contextId);
bool canAccessInspectedWindow() const;
v8::Local<v8::Context> v8Context() const;
v8::Local<v8::Value> v8Value() const;
v8::Local<v8::Value> callFunctionWithEvalEnabled(ScriptFunctionCall&, bool& hadException) const;
void makeCall(ScriptFunctionCall&, RefPtr<JSONValue>* result);
void makeEvalCall(ErrorString*, ScriptFunctionCall&, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* = 0);
void makeCallWithExceptionDetails(ScriptFunctionCall&, RefPtr<JSONValue>* result, RefPtr<TypeBuilder::Debugger::ExceptionDetails>*);
InjectedScriptManager* m_manager;
v8::Isolate* m_isolate;
ScriptValue m_injectedScriptObject;
v8::Global<v8::Context> m_context;
v8::Global<v8::Value> m_value;
V8DebuggerClient* m_client;
RefPtr<InjectedScriptNative> m_native;
int m_contextId;
......
......@@ -30,7 +30,6 @@
#include "core/inspector/InjectedScriptHost.h"
#include "bindings/core/v8/ScriptValue.h"
#include "core/inspector/InspectorConsoleAgent.h"
#include "core/inspector/v8/V8Debugger.h"
#include "core/inspector/v8/V8DebuggerAgent.h"
......
......@@ -46,7 +46,6 @@ class EventTarget;
class InjectedScriptHostClient;
class InspectorConsoleAgent;
class JSONValue;
class ScriptValue;
class V8DebuggerAgent;
class V8Debugger;
......
......@@ -30,7 +30,6 @@
#include "core/inspector/InjectedScriptManager.h"
#include "bindings/core/v8/ScriptValue.h"
#include "core/inspector/InjectedScript.h"
#include "core/inspector/InjectedScriptHost.h"
#include "core/inspector/InjectedScriptNative.h"
......@@ -91,10 +90,15 @@ void InjectedScriptManager::discardInjectedScripts()
int InjectedScriptManager::discardInjectedScriptFor(v8::Local<v8::Context> context)
{
int contextId = V8Debugger::contextId(context);
m_idToInjectedScript.remove(contextId);
discardInjectedScript(contextId);
return contextId;
}
void InjectedScriptManager::discardInjectedScript(int contextId)
{
m_idToInjectedScript.remove(contextId);
}
void InjectedScriptManager::releaseObjectGroup(const String& objectGroup)
{
Vector<int> keys;
......@@ -130,12 +134,13 @@ InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context>
if (it != m_idToInjectedScript.end())
return it->value.get();
if (!m_client->callingContextCanAccessContext(context))
v8::Local<v8::Context> callingContext = context->GetIsolate()->GetCallingContext();
if (!callingContext.IsEmpty() && !m_client->callingContextCanAccessContext(callingContext, context))
return nullptr;
RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScriptNative(context->GetIsolate()));
v8::Local<v8::Object> injectedScriptValue = createInjectedScript(injectedScriptSource(), context, contextId, injectedScriptNative.get());
OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(injectedScriptValue, m_client, injectedScriptNative.release(), contextId));
v8::Local<v8::Object> object = createInjectedScript(injectedScriptSource(), context, contextId, injectedScriptNative.get());
OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(this, context, object, m_client, injectedScriptNative.release(), contextId));
InjectedScript* resultPtr = result.get();
if (m_customObjectFormatterEnabled)
result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled);
......
......@@ -60,6 +60,7 @@ public:
InjectedScript* findInjectedScript(RemoteObjectIdBase*) const;
void discardInjectedScripts();
int discardInjectedScriptFor(v8::Local<v8::Context>);
void discardInjectedScript(int);
void releaseObjectGroup(const String& objectGroup);
void setCustomObjectFormatterEnabled(bool);
......
......@@ -25,6 +25,7 @@
#include "core/inspector/InspectorConsoleAgent.h"
#include "bindings/core/v8/ScriptValue.h"
#include "core/inspector/ConsoleMessage.h"
#include "core/inspector/ConsoleMessageStorage.h"
#include "core/inspector/IdentifiersFactory.h"
......
......@@ -1220,13 +1220,13 @@ Node* InspectorDOMAgent::nodeForRemoteId(ErrorString* errorString, const String&
*errorString = "Cannot find context for specified object id";
return nullptr;
}
ScriptState::Scope scope(injectedScript->scriptState());
v8::HandleScope handles(injectedScript->isolate());
v8::Local<v8::Value> value = injectedScript->findObject(*remoteId);
if (value.IsEmpty()) {
*errorString = "Node for given objectId not found";
return nullptr;
}
v8::Isolate* isolate = injectedScript->scriptState()->isolate();
v8::Isolate* isolate = injectedScript->isolate();
if (!V8Node::hasInstance(value, isolate)) {
*errorString = "Object id doesn't reference a Node";
return nullptr;
......
......@@ -367,7 +367,12 @@ void InspectorDOMDebuggerAgent::getEventListeners(ErrorString* errorString, cons
*errorString = "Inspected frame has gone";
return;
}
ScriptState* state = injectedScript->scriptState();
v8::HandleScope handles(injectedScript->isolate());
ScriptState* state = ScriptState::from(injectedScript->context());
if (!state) {
*errorString = "Inspected frame has gone";
return;
}
ScriptState::Scope scope(state);
v8::Local<v8::Value> value = injectedScript->findObject(*remoteId);
if (value.IsEmpty()) {
......@@ -382,9 +387,8 @@ void InspectorDOMDebuggerAgent::getEventListeners(ErrorString* errorString, cons
void InspectorDOMDebuggerAgent::eventListeners(InjectedScript* injectedScript, v8::Local<v8::Value> object, const String& objectGroup, RefPtr<TypeBuilder::Array<TypeBuilder::DOMDebugger::EventListener>>& listenersArray)
{
ScriptState* state = injectedScript->scriptState();
EventListenerInfoMap eventInformation;
InspectorDOMDebuggerAgent::eventListenersInfoForTarget(state->isolate(), object, eventInformation);
InspectorDOMDebuggerAgent::eventListenersInfoForTarget(injectedScript->isolate(), object, eventInformation);
for (const auto& it : eventInformation) {
for (const auto& it2 : *it.value) {
if (!it2.useCapture)
......@@ -408,8 +412,7 @@ PassRefPtr<TypeBuilder::DOMDebugger::EventListener> InspectorDOMDebuggerAgent::b
if (info.handler.IsEmpty())
return nullptr;
ScriptState* scriptState = injectedScript->scriptState();
v8::Isolate* isolate = scriptState->isolate();
v8::Isolate* isolate = injectedScript->isolate();
v8::Local<v8::Function> function = eventListenerEffectiveFunction(isolate, info.handler);
if (function.IsEmpty())
return nullptr;
......
......@@ -366,7 +366,8 @@ void InspectorHeapProfilerAgent::getHeapObjectId(ErrorString* errorString, const
*errorString = "Inspected context has gone";
return;
}
ScriptState::Scope scope(injectedScript->scriptState());
v8::HandleScope handles(injectedScript->isolate());
v8::Local<v8::Value> value = injectedScript->findObject(*remoteId);
if (value.IsEmpty() || value->IsUndefined()) {
*errorString = "Object with given id not found";
......
......@@ -33,6 +33,7 @@
#include "bindings/core/v8/BindingSecurity.h"
#include "bindings/core/v8/DOMWrapperWorld.h"
#include "bindings/core/v8/V8Window.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "core/inspector/InspectorTaskRunner.h"
#include "core/inspector/v8/V8Debugger.h"
......@@ -124,12 +125,10 @@ void MainThreadDebugger::quitMessageLoopOnPause()
m_clientMessageLoop->quitNow();
}
bool MainThreadDebugger::callingContextCanAccessContext(v8::Local<v8::Context> context)
bool MainThreadDebugger::callingContextCanAccessContext(v8::Local<v8::Context> calling, v8::Local<v8::Context> target)
{
if (context.IsEmpty())
return false;
DOMWindow* window = toDOMWindow(context->GetIsolate(), context->Global());
return window && BindingSecurity::shouldAllowAccessTo(context->GetIsolate(), callingDOMWindow(context->GetIsolate()), window, DoNotReportSecurityError);
DOMWindow* window = toDOMWindow(target);
return window && BindingSecurity::shouldAllowAccessTo(m_isolate, toLocalDOMWindow(toDOMWindow(calling)), window, DoNotReportSecurityError);
}
} // namespace blink
......@@ -77,7 +77,7 @@ private:
// V8DebuggerClient implementation.
void runMessageLoopOnPause(int contextGroupId) override;
void quitMessageLoopOnPause() override;
bool callingContextCanAccessContext(v8::Local<v8::Context>) override;
bool callingContextCanAccessContext(v8::Local<v8::Context> calling, v8::Local<v8::Context> target) override;
static WTF::Mutex& creationMutex();
......
......@@ -137,7 +137,13 @@ void PageDebuggerAgent::compileScript(ErrorString* errorString, const String& ex
*errorString = "Inspected frame has gone";
return;
}
ExecutionContext* executionContext = injectedScript->scriptState()->executionContext();
v8::HandleScope handles(injectedScript->isolate());
ExecutionContext* executionContext = toExecutionContext(injectedScript->context());
if (!executionContext) {
*errorString = "Inspected frame has gone";
return;
}
RefPtrWillBeRawPtr<LocalFrame> protect(toDocument(executionContext)->frame());
InspectorDebuggerAgent::compileScript(errorString, expression, sourceURL, persistScript, executionContextId, scriptId, exceptionDetails);
if (!scriptId->isAssigned())
......@@ -155,7 +161,12 @@ void PageDebuggerAgent::runScript(ErrorString* errorString, const ScriptId& scri
*errorString = "Inspected frame has gone";
return;
}
ExecutionContext* executionContext = injectedScript->scriptState()->executionContext();
v8::HandleScope handles(injectedScript->isolate());
ExecutionContext* executionContext = toExecutionContext(injectedScript->context());
if (!executionContext) {
*errorString = "Inspected frame has gone";
return;
}
String sourceURL = m_compiledScriptURLs.take(scriptId);
LocalFrame* frame = toDocument(executionContext)->frame();
......
......@@ -78,7 +78,7 @@ void WorkerThreadDebugger::quitMessageLoopOnPause()
m_paused = false;
}
bool WorkerThreadDebugger::callingContextCanAccessContext(v8::Local<v8::Context> context)
bool WorkerThreadDebugger::callingContextCanAccessContext(v8::Local<v8::Context> calling, v8::Local<v8::Context> target)
{
return true;
}
......
......@@ -49,7 +49,7 @@ public:
// V8DebuggerClient implementation.
void runMessageLoopOnPause(int contextGroupId) override;
void quitMessageLoopOnPause() override;
bool callingContextCanAccessContext(v8::Local<v8::Context>) override;
bool callingContextCanAccessContext(v8::Local<v8::Context> calling, v8::Local<v8::Context> target) override;
private:
WorkerThread* m_workerThread;
......
......@@ -980,12 +980,13 @@ void V8DebuggerAgentImpl::compileScript(ErrorString* errorString, const String&
if (!checkEnabled(errorString))
return;
InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript(executionContextId);
if (!injectedScript || !injectedScript->scriptState()->contextIsValid()) {
if (!injectedScript) {
*errorString = "Inspected frame has gone";
return;
}
ScriptState::Scope scope(injectedScript->scriptState());
v8::HandleScope handles(injectedScript->isolate());
v8::Context::Scope scope(injectedScript->context());
v8::Local<v8::String> source = v8String(m_isolate, expression);
v8::TryCatch tryCatch(m_isolate);
v8::Local<v8::Script> script;
......@@ -1025,11 +1026,12 @@ void V8DebuggerAgentImpl::runScript(ErrorString* errorString, const ScriptId& sc
return;
}
ScriptState* scriptState = injectedScript->scriptState();
ScriptState::Scope scope(scriptState);
v8::HandleScope handles(m_isolate);
v8::Context::Scope scope(injectedScript->context());
v8::Local<v8::Script> script = v8::Local<v8::Script>::New(m_isolate, m_compiledScripts.Remove(scriptId));
ScriptState* scriptState = ScriptState::from(injectedScript->context());
if (script.IsEmpty() || !scriptState->contextIsValid()) {
if (script.IsEmpty() || !scriptState) {
*errorString = "Script execution failed";
return;
}
......
......@@ -20,7 +20,7 @@ public:
virtual void runMessageLoopOnPause(int contextGroupId) = 0;
virtual void quitMessageLoopOnPause() = 0;
virtual void eventListeners(v8::Local<v8::Value>, EventListenerInfoMap&) = 0;
virtual bool callingContextCanAccessContext(v8::Local<v8::Context>) = 0;
virtual bool callingContextCanAccessContext(v8::Local<v8::Context> calling, v8::Local<v8::Context> target) = 0;
virtual v8::MaybeLocal<v8::Value> callFunction(v8::Local<v8::Function>, v8::Local<v8::Context>, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]) = 0;
};
......
......@@ -135,10 +135,10 @@ private:
using AgentsMap = HashMap<int, V8DebuggerAgentImpl*>;
AgentsMap m_agentsMap;
bool m_breakpointsActivated;
v8::UniquePersistent<v8::FunctionTemplate> m_breakProgramCallbackTemplate;
v8::UniquePersistent<v8::Object> m_debuggerScript;
v8::UniquePersistent<v8::Context> m_debuggerContext;
v8::UniquePersistent<v8::FunctionTemplate> m_callFrameWrapperTemplate;
v8::Global<v8::FunctionTemplate> m_breakProgramCallbackTemplate;
v8::Global<v8::Object> m_debuggerScript;
v8::Global<v8::Context> m_debuggerContext;
v8::Global<v8::FunctionTemplate> m_callFrameWrapperTemplate;
v8::Local<v8::Object> m_executionState;
v8::Local<v8::Context> m_pausedContext;
bool m_runningNestedMessageLoop;
......
......@@ -5,7 +5,6 @@
#include "core/inspector/v8/V8InjectedScriptHost.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/V8AbstractEventListener.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8DOMException.h"
......
......@@ -317,6 +317,7 @@ WebInspector.ExecutionContext.prototype = {
function evalCallback(error, result, wasThrown, exceptionDetails)
{
if (error) {
console.error(error);
callback(null, false);
return;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment