| Index: Source/devtools/front_end/components/ExecutionContextSelector.js
|
| diff --git a/Source/devtools/front_end/components/ExecutionContextSelector.js b/Source/devtools/front_end/components/ExecutionContextSelector.js
|
| index 51967919cd27f3a9b6ae3fd44ade4f099ae3f0a4..745e389bddf2fda01553c4ffe2e80ad2a87d1c32 100644
|
| --- a/Source/devtools/front_end/components/ExecutionContextSelector.js
|
| +++ b/Source/devtools/front_end/components/ExecutionContextSelector.js
|
| @@ -17,6 +17,9 @@ WebInspector.ExecutionContextSelector.prototype = {
|
| */
|
| targetAdded: function(target)
|
| {
|
| + if (!WebInspector.context.flavor(WebInspector.Target))
|
| + WebInspector.context.setFlavor(WebInspector.Target, target);
|
| +
|
| target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCreated, this);
|
| target.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextDestroyed, this);
|
| },
|
| @@ -28,7 +31,8 @@ WebInspector.ExecutionContextSelector.prototype = {
|
| {
|
| target.runtimeModel.removeEventListener(WebInspector.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCreated, this);
|
| target.runtimeModel.removeEventListener(WebInspector.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextDestroyed, this);
|
| - if (WebInspector.context.flavor(WebInspector.ExecutionContext).target() === target)
|
| + var currentExecutionContext = this.currentExecutionContext();
|
| + if (currentExecutionContext && currentExecutionContext.target() === target || this.currentTarget() === target)
|
| this._currentExecutionContextGone();
|
| },
|
|
|
| @@ -39,7 +43,7 @@ WebInspector.ExecutionContextSelector.prototype = {
|
| {
|
| var executionContext = /** @type {!WebInspector.ExecutionContext}*/ (event.data);
|
| if (!WebInspector.context.flavor(WebInspector.ExecutionContext))
|
| - WebInspector.context.setFlavor(WebInspector.ExecutionContext, executionContext);
|
| + this.setCurrentExecutionContext(executionContext);
|
| },
|
|
|
| /**
|
| @@ -59,13 +63,95 @@ WebInspector.ExecutionContextSelector.prototype = {
|
| for (var i = 0; i < targets.length; ++i) {
|
| var executionContexts = targets[i].runtimeModel.executionContexts();
|
| if (executionContexts.length) {
|
| - newContext = executionContexts[0];
|
| - break;
|
| + this.setCurrentExecutionContext(executionContexts[0]);
|
| + return;
|
| }
|
| }
|
| + WebInspector.context.setFlavor(WebInspector.ExecutionContext, null);
|
| + WebInspector.context.setFlavor(WebInspector.Target, targets.length ? targets[0] : null);
|
| + },
|
| +
|
| + /**
|
| + * @param {?WebInspector.ExecutionContext} executionContext
|
| + */
|
| + setCurrentExecutionContext: function(executionContext)
|
| + {
|
| + if (executionContext)
|
| + WebInspector.context.setFlavor(WebInspector.Target, executionContext.target());
|
| + WebInspector.context.setFlavor(WebInspector.ExecutionContext, executionContext);
|
| + },
|
| +
|
| + /**
|
| + * @param {?WebInspector.Target} target
|
| + */
|
| + setCurrentTarget: function(target)
|
| + {
|
| + WebInspector.context.setFlavor(WebInspector.Target, target);
|
| + var executionContexts = target ? target.runtimeModel.executionContexts() : [];
|
| + if (!executionContexts.length)
|
| + return;
|
| +
|
| + var newContext = executionContexts[0];
|
| + for (var i = 1; i < executionContexts.length; ++i) {
|
| + if (executionContexts[i].isMainWorldContext)
|
| + newContext = executionContexts[i];
|
| + }
|
| WebInspector.context.setFlavor(WebInspector.ExecutionContext, newContext);
|
| - }
|
| + },
|
| +
|
| + /**
|
| + * @return {?WebInspector.ExecutionContext}
|
| + */
|
| + currentExecutionContext: function()
|
| + {
|
| + return WebInspector.context.flavor(WebInspector.ExecutionContext);
|
| + },
|
| +
|
| + /**
|
| + * @return {?WebInspector.Target}
|
| + */
|
| + currentTarget: function()
|
| + {
|
| + return WebInspector.context.flavor(WebInspector.Target);
|
| + },
|
| +
|
| + /**
|
| + * @param {function(new:T, ...)} flavorType
|
| + * @param {function(?T)} listener
|
| + * @param {!Object=} thisObject
|
| + * @template T
|
| + */
|
| + _addChangeListener: function(flavorType, listener, thisObject)
|
| + {
|
| + WebInspector.context.addFlavorChangeListener(flavorType, callback);
|
|
|
| + /**
|
| + * @param {!WebInspector.Event} event
|
| + */
|
| + function callback(event)
|
| + {
|
| + listener.call(thisObject, event.data);
|
| + }
|
| +
|
| + },
|
| +
|
| + /**
|
| + * @param {function(?WebInspector.ExecutionContext)} listener
|
| + * @param {!Object=} thisObject
|
| + */
|
| + addExecutionContextChangeListener: function(listener, thisObject)
|
| + {
|
| + this._addChangeListener(WebInspector.ExecutionContext, listener, thisObject);
|
| + },
|
| +
|
| + /**
|
| + * @param {function(?WebInspector.Target)} listener
|
| + * @param {!Object=} thisObject
|
| + */
|
| + addTargetChangeListener: function(listener, thisObject)
|
| + {
|
| + this._addChangeListener(WebInspector.Target, listener, thisObject);
|
| + }
|
| }
|
|
|
| /**
|
| @@ -87,4 +173,9 @@ WebInspector.ExecutionContextSelector.completionsForTextPromptInCurrentContext =
|
| var expressionString = expressionRange.toString();
|
| var prefix = wordRange.toString();
|
| executionContext.completionsForExpression(expressionString, prefix, force, completionsReadyCallback);
|
| -}
|
| +}
|
| +
|
| +/**
|
| + * @type {!WebInspector.ExecutionContextSelector}
|
| + */
|
| +WebInspector.executionContextSelector;
|
|
|