Skip to content

Commit 9c8cb4a

Browse files
committed
Use UI strings, do some minor refactoring.
1 parent 83f5ad9 commit 9c8cb4a

File tree

2 files changed

+59
-45
lines changed

2 files changed

+59
-45
lines changed

src/ecma-debugger/templates.js

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
;(function()
22
{
33
var self = this;
4+
5+
var STRING_MAX_VALUE_LENGTH = 30;
6+
7+
var TYPE_UNDEFINED = 0;
8+
var TYPE_NULL = 1;
9+
var TYPE_TRUE = 2;
10+
var TYPE_FALSE = 3;
11+
var TYPE_NAN = 4;
12+
var TYPE_PLUS_INFINITY = 5;
13+
var TYPE_MINUS_INFINITY = 6;
14+
var TYPE_NUMBER = 7;
15+
var TYPE_STRING = 8;
16+
var TYPE_OBJECT = 9;
17+
18+
var types = {};
19+
types[TYPE_UNDEFINED] = "undefined";
20+
types[TYPE_NULL] = "null";
21+
types[TYPE_TRUE] = "boolean";
22+
types[TYPE_FALSE] = "boolean";
23+
types[TYPE_NAN] = "number";
24+
types[TYPE_PLUS_INFINITY] = "number";
25+
types[TYPE_MINUS_INFINITY] = "number";
26+
types[TYPE_NUMBER] = "number";
27+
types[TYPE_STRING] = "string";
28+
29+
var names = {};
30+
names[TYPE_TRUE] = "true";
31+
names[TYPE_FALSE] = "false";
32+
names[TYPE_NAN] = "NaN";
33+
names[TYPE_PLUS_INFINITY] = "Infinity";
34+
names[TYPE_MINUS_INFINITY] = "-Infinity";
35+
436
this.hello = function(enviroment)
537
{
638
var ret = ["ul"];
@@ -323,43 +355,14 @@
323355

324356
this.return_value = function(retval, rt_id, search_term)
325357
{
326-
var STRING_MAX_VALUE_LENGTH = 30;
327-
// TODO: move constants
328-
var UNDEFINED = 0;
329-
var NULL = 1;
330-
var TRUE = 2;
331-
var FALSE = 3;
332-
var NAN = 4;
333-
var PLUS_INFINITY = 5;
334-
var MINUS_INFINITY = 6;
335-
var NUMBER = 7;
336-
var STRING = 8;
337-
var OBJECT = 9;
338-
var types = {};
339-
types[UNDEFINED] = "undefined";
340-
types[NULL] = "null";
341-
types[TRUE] = "boolean";
342-
types[FALSE] = "boolean";
343-
types[NAN] = "number";
344-
types[PLUS_INFINITY] = "number";
345-
types[MINUS_INFINITY] = "number";
346-
types[NUMBER] = "number";
347-
types[STRING] = "string";
348-
var names = {};
349-
names[TRUE] = "true";
350-
names[FALSE] = "false";
351-
names[NAN] = "NaN";
352-
names[PLUS_INFINITY] = "Infinity";
353-
names[MINUS_INFINITY] = "-Infinity";
354-
355358
var search_re = new RegExp(search_term, "ig")
356359
var value_template = [];
357360
var value = "";
358361
var type = types[retval.value.type];
359362
switch (retval.value.type)
360363
{
361-
case UNDEFINED:
362-
case NULL:
364+
case TYPE_UNDEFINED:
365+
case TYPE_NULL:
363366
if (search_re.test(type))
364367
{
365368
value_template.push(
@@ -373,11 +376,11 @@
373376
}
374377
break;
375378

376-
case TRUE:
377-
case FALSE:
378-
case NAN:
379-
case PLUS_INFINITY:
380-
case MINUS_INFINITY:
379+
case TYPE_TRUE:
380+
case TYPE_FALSE:
381+
case TYPE_NAN:
382+
case TYPE_PLUS_INFINITY:
383+
case TYPE_MINUS_INFINITY:
381384
value = names[retval.value.type];
382385
if (search_re.test(value))
383386
{
@@ -392,7 +395,7 @@
392395
}
393396
break;
394397

395-
case NUMBER:
398+
case TYPE_NUMBER:
396399
value = String(retval.value.number);
397400
if (search_re.test(value))
398401
{
@@ -407,7 +410,7 @@
407410
}
408411
break;
409412

410-
case STRING:
413+
case TYPE_STRING:
411414
value = retval.value.str;
412415
if (search_re.test(value))
413416
{
@@ -446,7 +449,7 @@
446449
}
447450
break;
448451

449-
case OBJECT:
452+
case TYPE_OBJECT:
450453
var object = retval.value.object;
451454
var name = object.className === "Function" && !object.functionName
452455
? ui_strings.S_ANONYMOUS_FUNCTION_NAME
@@ -460,22 +463,22 @@
460463
var from_script_id = retval.positionFrom.scriptID;
461464
var from_uri = from_script_id && runtimes.getScript(from_script_id)
462465
? (runtimes.getScript(from_script_id).uri || runtimes.getRuntime(rt_id).uri)
463-
: "<unknown script>";
466+
: ui_strings.S_UNKNOWN_SCRIPT;
464467
var to_script_id = retval.positionTo.scriptID;
465468
var to_uri = to_script_id && runtimes.getScript(to_script_id)
466469
? (runtimes.getScript(to_script_id).uri || runtimes.getRuntime(rt_id).uri)
467-
: "<unknown script>";
470+
: ui_strings.S_UNKNOWN_SCRIPT;
468471

469472
var object = retval.functionFrom;
470473
var func_model = new cls.InspectableJSObject(rt_id,
471474
object.objectID,
472475
object.functionName || ui_strings.S_ANONYMOUS_FUNCTION_NAME,
473476
object.className);
474-
var func_search_term = (value_template.length !== 0) ? null : search_term;
477+
var func_search_term = value_template.length ? null : search_term;
475478
var func = window.templates.inspected_js_object(func_model, true, null, func_search_term);
476479

477480
// If there is no function or value, don't show anything
478-
if (func === "" && value_template.length === 0)
481+
if (func === "" && !value_template.length)
479482
return [];
480483

481484
return [
@@ -485,7 +488,8 @@
485488
"↱",
486489
"class", "return-value-arrow return-value-arrow-from",
487490
"handler", "goto-script-line",
488-
"title", "Returned from " + window.helpers.basename(from_uri) + ":" + retval.positionFrom.lineNumber,
491+
"title", ui_strings.S_RETURN_VALUES_FUNCTION_FROM.replace("%s", window.helpers.basename(from_uri))
492+
.replace("%s", retval.positionFrom.lineNumber),
489493
"data-script-id", String(retval.positionFrom.scriptID),
490494
"data-script-line", String(retval.positionFrom.lineNumber)
491495
],
@@ -498,7 +502,8 @@
498502
"↳",
499503
"class", "return-value-arrow return-value-arrow-to",
500504
"handler", "goto-script-line",
501-
"title", "Returned to " + window.helpers.basename(to_uri) + ":" + retval.positionTo.lineNumber,
505+
"title", ui_strings.S_RETURN_VALUES_FUNCTION_TO.replace("%s", window.helpers.basename(to_uri))
506+
.replace("%s", retval.positionTo.lineNumber),
502507
"data-script-id", String(retval.positionTo.scriptID),
503508
"data-script-line", String(retval.positionTo.lineNumber)
504509
],

src/ui-strings/ui_strings-en.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,3 +1694,12 @@ ui_strings.S_SCRIPT_TYPE_EXTENSIONJS = "Extension";
16941694

16951695
/* DESC: Script type for events in the profiler */
16961696
ui_strings.S_SCRIPT_TYPE_DEBUGGER = "Debugger";
1697+
1698+
/* DESC: String shown instead of filename when file name is missing */
1699+
ui_strings.S_UNKNOWN_SCRIPT = "(Unknown script)";
1700+
1701+
/* DESC: Tooltip displayed when hovering the arrow going back in Return Values. The first variable is a file name, the second a line number */
1702+
ui_strings.S_RETURN_VALUES_FUNCTION_FROM = "Returned from %s:%s";
1703+
1704+
/* DESC: Tooltip displayed when hovering the arrow going forward in Return Values. The first variable is a file name, the second a line number */
1705+
ui_strings.S_RETURN_VALUES_FUNCTION_TO = "Returned to %s:%s";

0 commit comments

Comments
 (0)