@@ -14,6 +14,9 @@ const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {})
14
14
const { Widgets } = devtools . require ( "devtools/webconsole/console-output" ) ;
15
15
const { VariablesView } = Cu . import ( "resource:///modules/devtools/VariablesView.jsm" , { } ) ;
16
16
17
+ // Platform
18
+ const { Services } = Cu . import ( "resource://gre/modules/Services.jsm" , { } ) ;
19
+
17
20
const XHTML_NS = "http://www.w3.org/1999/xhtml" ;
18
21
19
22
/**
@@ -57,7 +60,10 @@ var JQueryRenderer = {
57
60
emptySlots = 0 ;
58
61
}
59
62
60
- let shortVal = this . message . shortenValueGrip ( item ) ;
63
+ // shortenValueGrip API has been introduced in Firefox 38
64
+ let shortVal = this . message . shortenValueGrip ?
65
+ this . message . shortenValueGrip ( item ) : shortenValueGrip ( ) ;
66
+
61
67
let elem = this . message . _renderValueGrip ( shortVal , { concise : true } ) ;
62
68
this . element . appendChild ( elem ) ;
63
69
@@ -122,6 +128,29 @@ var JQueryRenderer = {
122
128
}
123
129
} ;
124
130
131
+ // Helpers
132
+
133
+ /**
134
+ * Can be removed when Firefox 38 (Fx38) is the minimum required version.
135
+ */
136
+ function shortenValueGrip ( grip ) {
137
+ let MAX_STRING_GRIP_LENGTH = 36 ;
138
+ let ELLIPSIS = Services . prefs . getComplexValue ( "intl.ellipsis" ,
139
+ Ci . nsIPrefLocalizedString ) . data ;
140
+
141
+ let shortVal = grip ;
142
+ if ( typeof ( grip ) == "string" ) {
143
+ shortVal = grip . replace ( / ( \r \n | \n | \r ) / gm, " " ) ;
144
+ if ( shortVal . length > MAX_STRING_GRIP_LENGTH ) {
145
+ shortVal = shortVal . substring ( 0 , MAX_STRING_GRIP_LENGTH - 1 ) + ELLIPSIS ;
146
+ }
147
+ }
148
+
149
+ return shortVal ;
150
+ }
151
+
152
+ // Registration
153
+
125
154
Widgets . ObjectRenderers . add ( JQueryRenderer ) ;
126
155
127
156
// Exports from this module
0 commit comments