Commit 6a4cfb8d authored by Erik Luo's avatar Erik Luo Committed by Commit Bot

DevTools: release objects generated for REPL preview

Bug: none
Change-Id: Ic24e0f08fa6d55461d7bdd50d6164b00e47ab950
Reviewed-on: https://chromium-review.googlesource.com/1200402
Commit-Queue: Erik Luo <luoe@chromium.org>
Reviewed-by: default avatarJoel Einbinder <einbinder@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589860}
parent edefa9e1
...@@ -107,8 +107,10 @@ Console.ConsolePin = class extends Common.Object { ...@@ -107,8 +107,10 @@ Console.ConsolePin = class extends Common.Object {
nameElement.title = expression; nameElement.title = expression;
this._pinElement[Console.ConsolePin._PinSymbol] = this; this._pinElement[Console.ConsolePin._PinSymbol] = this;
/** @type {?SDK.RemoteObject} */ /** @type {?SDK.RuntimeModel.EvaluationResult} */
this._resultObject = null; this._lastResult = null;
/** @type {?SDK.ExecutionContext} */
this._lastExecutionContext = null;
/** @type {?UI.TextEditor} */ /** @type {?UI.TextEditor} */
this._editor = null; this._editor = null;
this._committedExpression = expression; this._committedExpression = expression;
...@@ -165,8 +167,8 @@ Console.ConsolePin = class extends Common.Object { ...@@ -165,8 +167,8 @@ Console.ConsolePin = class extends Common.Object {
* @param {!UI.ContextMenu} contextMenu * @param {!UI.ContextMenu} contextMenu
*/ */
appendToContextMenu(contextMenu) { appendToContextMenu(contextMenu) {
if (this._resultObject) if (this._lastResult && this._lastResult.object)
contextMenu.appendApplicableItems(this._resultObject); contextMenu.appendApplicableItems(this._lastResult.object);
} }
/** /**
...@@ -179,9 +181,12 @@ Console.ConsolePin = class extends Common.Object { ...@@ -179,9 +181,12 @@ Console.ConsolePin = class extends Common.Object {
const isEditing = this._pinElement.hasFocus(); const isEditing = this._pinElement.hasFocus();
const throwOnSideEffect = isEditing && text !== this._committedExpression; const throwOnSideEffect = isEditing && text !== this._committedExpression;
const timeout = throwOnSideEffect ? 250 : undefined; const timeout = throwOnSideEffect ? 250 : undefined;
this._lastExecutionContext = UI.context.flavor(SDK.ExecutionContext);
const {preview, result} = await ObjectUI.JavaScriptREPL.evaluateAndBuildPreview( const {preview, result} = await ObjectUI.JavaScriptREPL.evaluateAndBuildPreview(
text, throwOnSideEffect, timeout, !isEditing /* allowErrors */); text, throwOnSideEffect, timeout, !isEditing /* allowErrors */);
this._resultObject = result ? (result.object || null) : null; if (this._lastResult)
this._lastExecutionContext.runtimeModel.releaseEvaluationResult(this._lastResult);
this._lastResult = result || null;
const previewText = preview.deepTextContent(); const previewText = preview.deepTextContent();
if (!previewText || previewText !== this._pinPreview.deepTextContent()) { if (!previewText || previewText !== this._pinPreview.deepTextContent()) {
this._pinPreview.removeChildren(); this._pinPreview.removeChildren();
......
...@@ -96,6 +96,7 @@ Console.ConsolePrompt = class extends UI.Widget { ...@@ -96,6 +96,7 @@ Console.ConsolePrompt = class extends UI.Widget {
*/ */
async _requestPreview() { async _requestPreview() {
const text = this._editor.textWithCurrentSuggestion().trim(); const text = this._editor.textWithCurrentSuggestion().trim();
const executionContext = UI.context.flavor(SDK.ExecutionContext);
const {preview, result} = const {preview, result} =
await ObjectUI.JavaScriptREPL.evaluateAndBuildPreview(text, true /* throwOnSideEffect */, 500); await ObjectUI.JavaScriptREPL.evaluateAndBuildPreview(text, true /* throwOnSideEffect */, 500);
this._innerPreviewElement.removeChildren(); this._innerPreviewElement.removeChildren();
...@@ -108,6 +109,8 @@ Console.ConsolePrompt = class extends UI.Widget { ...@@ -108,6 +109,8 @@ Console.ConsolePrompt = class extends UI.Widget {
this._highlightingNode = false; this._highlightingNode = false;
SDK.OverlayModel.hideDOMNodeHighlight(); SDK.OverlayModel.hideDOMNodeHighlight();
} }
if (result)
executionContext.runtimeModel.releaseEvaluationResult(result);
} }
/** /**
......
...@@ -209,6 +209,19 @@ SDK.RuntimeModel = class extends SDK.SDKModel { ...@@ -209,6 +209,19 @@ SDK.RuntimeModel = class extends SDK.SDKModel {
this._agent.releaseObjectGroup(objectGroupName); this._agent.releaseObjectGroup(objectGroupName);
} }
/**
* @param {!SDK.RuntimeModel.EvaluationResult} result
*/
releaseEvaluationResult(result) {
if (result.object)
result.object.release();
if (result.exceptionDetails && result.exceptionDetails.exception) {
const exception = result.exceptionDetails.exception;
const exceptionObject = this.createRemoteObject({type: exception.type, objectId: exception.objectId});
exceptionObject.release();
}
}
runIfWaitingForDebugger() { runIfWaitingForDebugger() {
this._agent.runIfWaitingForDebugger(); this._agent.runIfWaitingForDebugger();
} }
......
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