Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/JavaScriptCompiler.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium 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
5 /** 4 /**
6 * @constructor 5 * @unrestricted
7 * @param {!WebInspector.JavaScriptSourceFrame} sourceFrame
8 */ 6 */
9 WebInspector.JavaScriptCompiler = function(sourceFrame) 7 WebInspector.JavaScriptCompiler = class {
10 { 8 /**
9 * @param {!WebInspector.JavaScriptSourceFrame} sourceFrame
10 */
11 constructor(sourceFrame) {
11 this._sourceFrame = sourceFrame; 12 this._sourceFrame = sourceFrame;
12 this._compiling = false; 13 this._compiling = false;
14 }
15
16 scheduleCompile() {
17 if (this._compiling) {
18 this._recompileScheduled = true;
19 return;
20 }
21 if (this._timeout)
22 clearTimeout(this._timeout);
23 this._timeout = setTimeout(this._compile.bind(this), WebInspector.JavaScript Compiler.CompileDelay);
24 }
25
26 /**
27 * @return {?WebInspector.Target}
28 */
29 _findTarget() {
30 var targets = WebInspector.targetManager.targets();
31 var sourceCode = this._sourceFrame.uiSourceCode();
32 for (var i = 0; i < targets.length; ++i) {
33 var scriptFile = WebInspector.debuggerWorkspaceBinding.scriptFile(sourceCo de, targets[i]);
34 if (scriptFile)
35 return targets[i];
36 }
37 return WebInspector.targetManager.mainTarget();
38 }
39
40 _compile() {
41 var target = this._findTarget();
42 if (!target)
43 return;
44 var runtimeModel = target.runtimeModel;
45 var currentExecutionContext = WebInspector.context.flavor(WebInspector.Execu tionContext);
46 if (!currentExecutionContext)
47 return;
48
49 this._compiling = true;
50 var code = this._sourceFrame.textEditor.text();
51 runtimeModel.compileScript(code, '', false, currentExecutionContext.id, comp ileCallback.bind(this, target));
52
53 /**
54 * @param {!WebInspector.Target} target
55 * @param {!RuntimeAgent.ScriptId=} scriptId
56 * @param {?RuntimeAgent.ExceptionDetails=} exceptionDetails
57 * @this {WebInspector.JavaScriptCompiler}
58 */
59 function compileCallback(target, scriptId, exceptionDetails) {
60 this._compiling = false;
61 if (this._recompileScheduled) {
62 delete this._recompileScheduled;
63 this.scheduleCompile();
64 return;
65 }
66 if (!exceptionDetails)
67 return;
68 var text = WebInspector.ConsoleMessage.simpleTextFromException(exceptionDe tails);
69 this._sourceFrame.uiSourceCode().addLineMessage(
70 WebInspector.UISourceCode.Message.Level.Error, text, exceptionDetails. lineNumber,
71 exceptionDetails.columnNumber);
72 this._compilationFinishedForTest();
73 }
74 }
75
76 _compilationFinishedForTest() {
77 }
13 }; 78 };
14 79
15 WebInspector.JavaScriptCompiler.CompileDelay = 1000; 80 WebInspector.JavaScriptCompiler.CompileDelay = 1000;
16
17 WebInspector.JavaScriptCompiler.prototype = {
18 scheduleCompile: function()
19 {
20 if (this._compiling) {
21 this._recompileScheduled = true;
22 return;
23 }
24 if (this._timeout)
25 clearTimeout(this._timeout);
26 this._timeout = setTimeout(this._compile.bind(this), WebInspector.JavaSc riptCompiler.CompileDelay);
27 },
28
29 /**
30 * @return {?WebInspector.Target}
31 */
32 _findTarget: function()
33 {
34 var targets = WebInspector.targetManager.targets();
35 var sourceCode = this._sourceFrame.uiSourceCode();
36 for (var i = 0; i < targets.length; ++i) {
37 var scriptFile = WebInspector.debuggerWorkspaceBinding.scriptFile(so urceCode, targets[i]);
38 if (scriptFile)
39 return targets[i];
40 }
41 return WebInspector.targetManager.mainTarget();
42 },
43
44 _compile: function()
45 {
46 var target = this._findTarget();
47 if (!target)
48 return;
49 var runtimeModel = target.runtimeModel;
50 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext);
51 if (!currentExecutionContext)
52 return;
53
54 this._compiling = true;
55 var code = this._sourceFrame.textEditor.text();
56 runtimeModel.compileScript(code, "", false, currentExecutionContext.id, compileCallback.bind(this, target));
57
58 /**
59 * @param {!WebInspector.Target} target
60 * @param {!RuntimeAgent.ScriptId=} scriptId
61 * @param {?RuntimeAgent.ExceptionDetails=} exceptionDetails
62 * @this {WebInspector.JavaScriptCompiler}
63 */
64 function compileCallback(target, scriptId, exceptionDetails)
65 {
66 this._compiling = false;
67 if (this._recompileScheduled) {
68 delete this._recompileScheduled;
69 this.scheduleCompile();
70 return;
71 }
72 if (!exceptionDetails)
73 return;
74 var text = WebInspector.ConsoleMessage.simpleTextFromException(excep tionDetails);
75 this._sourceFrame.uiSourceCode().addLineMessage(WebInspector.UISourc eCode.Message.Level.Error, text, exceptionDetails.lineNumber, exceptionDetails.c olumnNumber);
76 this._compilationFinishedForTest();
77 }
78 },
79
80 _compilationFinishedForTest: function() {}
81 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698