jslint 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,86 @@
1
+ // intercept.html
2
+ // 2009-08-21
3
+
4
+ // This file makes it possible for JSLint to run as an ADsafe widget by
5
+ // adding lib features.
6
+
7
+ // It provides a JSON cookie facility. Each widget is allowed to create a
8
+ // single JSON cookie.
9
+
10
+ // It also provides a way for the widget to call JSLint. The widget cannot
11
+ // call JSLint directly because it is loaded as a global variable. I don't
12
+ // want to change that because other versions of JSLint depend on that.
13
+
14
+ /*jslint nomen: false */
15
+
16
+ /*global ADSAFE, document, JSLINT */
17
+
18
+ /*members ___nodes___, _intercept, cookie, edition, get, getTime,
19
+ indexOf, innerHTML, jslint, length, parse, replace, report, set,
20
+ setTime, slice, stringify, toGMTString
21
+ */
22
+
23
+
24
+ "use strict";
25
+ ADSAFE._intercept(function (id, dom, lib, bunch) {
26
+
27
+ // Give every widget access to a cookie. The name of the cookie will be the
28
+ // same as the id of the widget.
29
+
30
+ lib.cookie = {
31
+ get: function () {
32
+
33
+ // Get the raw cookie. Extract this widget's cookie, and parse it.
34
+
35
+ var c = ' ' + document.cookie + ';',
36
+ s = c.indexOf((' ' + id + '=')),
37
+ v;
38
+ try {
39
+ if (s >= 0) {
40
+ s += id.length + 2;
41
+ v = JSON.parse(c.slice(s, c.indexOf(';', s)));
42
+ }
43
+ } catch (ignore) {}
44
+ return v;
45
+ },
46
+ set: function (value) {
47
+
48
+ // Set a cookie. It must be under 2000 in length. Escapify equal sign
49
+ // and semicolon if necessary.
50
+
51
+ var d,
52
+ text = JSON.stringify(value)
53
+ .replace(/[=]/g, '\\u003d')
54
+ .replace(/[;]/g, '\\u003b');
55
+
56
+ if (text.length < 2000) {
57
+ d = new Date();
58
+ d.setTime(d.getTime() + 1e9);
59
+ document.cookie = id + "=" + text +
60
+ ';expires=' + d.toGMTString();
61
+ }
62
+ }
63
+ };
64
+ });
65
+
66
+ ADSAFE._intercept(function (id, dom, lib, bunch) {
67
+
68
+ // Give only the JSLINT_ widget access to the JSLINT function.
69
+ // We add a jslint function to its lib that calls JSLINT and
70
+ // then calls JSLINT.report, and stuffs the html result into
71
+ // a node provided by the widget. A widget does not get direct
72
+ // access to nodes.
73
+
74
+ // We also add an edition function to the lib that gives the
75
+ // widget access to the current edition string.
76
+
77
+ if (id === 'JSLINT_') {
78
+ lib.jslint = function (source, options, output) {
79
+ JSLINT(source, options);
80
+ output.___nodes___[0].innerHTML = JSLINT.report();
81
+ };
82
+ lib.edition = function () {
83
+ return JSLINT.edition;
84
+ };
85
+ }
86
+ });
data/jslint/json2.js ADDED
@@ -0,0 +1,472 @@
1
+ /*
2
+ http://www.JSON.org/json2.js
3
+ 2010-08-25
4
+
5
+ Public Domain.
6
+
7
+ NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
8
+
9
+ See http://www.JSON.org/js.html
10
+
11
+ This code should be minified before deployment.
12
+ See http://javascript.crockford.com/jsmin.html
13
+
14
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
15
+ NOT CONTROL.
16
+
17
+ This file creates a global JSON object containing two methods: stringify
18
+ and parse.
19
+
20
+ JSON.stringify(value, replacer, space)
21
+ value any JavaScript value, usually an object or array.
22
+
23
+ replacer an optional parameter that determines how object
24
+ values are stringified for objects. It can be a
25
+ function or an array of strings.
26
+
27
+ space an optional parameter that specifies the indentation
28
+ of nested structures. If it is omitted, the text will
29
+ be packed without extra whitespace. If it is a number,
30
+ it will specify the number of spaces to indent at each
31
+ level. If it is a string (such as '\t' or '&nbsp;'),
32
+ it contains the characters used to indent at each level.
33
+
34
+ This method produces a JSON text from a JavaScript value.
35
+
36
+ When an object value is found, if the object contains a toJSON
37
+ method, its toJSON method will be called and the result will be
38
+ stringified. A toJSON method does not serialize: it returns the
39
+ value represented by the name/value pair that should be serialized,
40
+ or undefined if nothing should be serialized. The toJSON method
41
+ will be passed the key associated with the value, and this will be
42
+ bound to the value
43
+
44
+ For example, this would serialize Dates as ISO strings.
45
+
46
+ Date.prototype.toJSON = function (key) {
47
+ function f(n) {
48
+ // Format integers to have at least two digits.
49
+ return n < 10 ? '0' + n : n;
50
+ }
51
+
52
+ return this.getUTCFullYear() + '-' +
53
+ f(this.getUTCMonth() + 1) + '-' +
54
+ f(this.getUTCDate()) + 'T' +
55
+ f(this.getUTCHours()) + ':' +
56
+ f(this.getUTCMinutes()) + ':' +
57
+ f(this.getUTCSeconds()) + 'Z';
58
+ };
59
+
60
+ You can provide an optional replacer method. It will be passed the
61
+ key and value of each member, with this bound to the containing
62
+ object. The value that is returned from your method will be
63
+ serialized. If your method returns undefined, then the member will
64
+ be excluded from the serialization.
65
+
66
+ If the replacer parameter is an array of strings, then it will be
67
+ used to select the members to be serialized. It filters the results
68
+ such that only members with keys listed in the replacer array are
69
+ stringified.
70
+
71
+ Values that do not have JSON representations, such as undefined or
72
+ functions, will not be serialized. Such values in objects will be
73
+ dropped; in arrays they will be replaced with null. You can use
74
+ a replacer function to replace those with JSON values.
75
+ JSON.stringify(undefined) returns undefined.
76
+
77
+ The optional space parameter produces a stringification of the
78
+ value that is filled with line breaks and indentation to make it
79
+ easier to read.
80
+
81
+ If the space parameter is a non-empty string, then that string will
82
+ be used for indentation. If the space parameter is a number, then
83
+ the indentation will be that many spaces.
84
+
85
+ Example:
86
+
87
+ text = JSON.stringify(['e', {pluribus: 'unum'}]);
88
+ // text is '["e",{"pluribus":"unum"}]'
89
+
90
+ text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
91
+ // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
92
+
93
+ text = JSON.stringify([new Date()], function (key, value) {
94
+ return this[key] instanceof Date ?
95
+ 'Date(' + this[key] + ')' : value;
96
+ });
97
+ // text is '["Date(---current time---)"]'
98
+
99
+ JSON.parse(text, reviver)
100
+ This method parses a JSON text to produce an object or array.
101
+ It can throw a SyntaxError exception.
102
+
103
+ The optional reviver parameter is a function that can filter and
104
+ transform the results. It receives each of the keys and values,
105
+ and its return value is used instead of the original value.
106
+ If it returns what it received, then the structure is not modified.
107
+ If it returns undefined then the member is deleted.
108
+
109
+ Example:
110
+
111
+ // Parse the text. Values that look like ISO date strings will
112
+ // be converted to Date objects.
113
+
114
+ myData = JSON.parse(text, function (key, value) {
115
+ var a;
116
+ if (typeof value === 'string') {
117
+ a =
118
+ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
119
+ if (a) {
120
+ return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
121
+ +a[5], +a[6]));
122
+ }
123
+ }
124
+ return value;
125
+ });
126
+
127
+ myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
128
+ var d;
129
+ if (typeof value === 'string' &&
130
+ value.slice(0, 5) === 'Date(' &&
131
+ value.slice(-1) === ')') {
132
+ d = new Date(value.slice(5, -1));
133
+ if (d) {
134
+ return d;
135
+ }
136
+ }
137
+ return value;
138
+ });
139
+
140
+ This is a reference implementation. You are free to copy, modify, or
141
+ redistribute.
142
+ */
143
+
144
+ /*jslint evil: true, strict: false */
145
+
146
+ /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
147
+ call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
148
+ getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
149
+ lastIndex, length, parse, prototype, push, replace, slice, stringify,
150
+ test, toJSON, toString, valueOf
151
+ */
152
+
153
+ // Create a JSON object only if one does not already exist. We create the
154
+ // methods in a closure to avoid creating global variables.
155
+
156
+ if (!this.JSON) {
157
+ this.JSON = {};
158
+ }
159
+
160
+ (function () {
161
+
162
+ function f(n) {
163
+ // Format integers to have at least two digits.
164
+ return n < 10 ? '0' + n : n;
165
+ }
166
+
167
+ if (typeof Date.prototype.toJSON !== 'function') {
168
+
169
+ Date.prototype.toJSON = function (key) {
170
+
171
+ return isFinite(this.valueOf()) ?
172
+ this.getUTCFullYear() + '-' +
173
+ f(this.getUTCMonth() + 1) + '-' +
174
+ f(this.getUTCDate()) + 'T' +
175
+ f(this.getUTCHours()) + ':' +
176
+ f(this.getUTCMinutes()) + ':' +
177
+ f(this.getUTCSeconds()) + 'Z' : null;
178
+ };
179
+
180
+ String.prototype.toJSON =
181
+ Number.prototype.toJSON =
182
+ Boolean.prototype.toJSON = function (key) {
183
+ return this.valueOf();
184
+ };
185
+ }
186
+
187
+ var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
188
+ escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
189
+ gap,
190
+ indent,
191
+ meta = { // table of character substitutions
192
+ '\b': '\\b',
193
+ '\t': '\\t',
194
+ '\n': '\\n',
195
+ '\f': '\\f',
196
+ '\r': '\\r',
197
+ '"' : '\\"',
198
+ '\\': '\\\\'
199
+ },
200
+ rep;
201
+
202
+ function quote(string) {
203
+
204
+ // If the string contains no control characters, no quote characters, and no
205
+ // backslash characters, then we can safely slap some quotes around it.
206
+ // Otherwise we must also replace the offending characters with safe escape
207
+ // sequences.
208
+
209
+ escapable.lastIndex = 0;
210
+ return escapable.test(string) ?
211
+ '"' + string.replace(escapable, function (a) {
212
+ var c = meta[a];
213
+ return typeof c === 'string' ? c :
214
+ '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
215
+ }) + '"' :
216
+ '"' + string + '"';
217
+ }
218
+
219
+ function str(key, holder) {
220
+
221
+ // Produce a string from holder[key].
222
+
223
+ var i, // The loop counter.
224
+ k, // The member key.
225
+ v, // The member value.
226
+ length,
227
+ mind = gap,
228
+ partial,
229
+ value = holder[key];
230
+
231
+ // If the value has a toJSON method, call it to obtain a replacement value.
232
+
233
+ if (value && typeof value === 'object' &&
234
+ typeof value.toJSON === 'function') {
235
+ value = value.toJSON(key);
236
+ }
237
+
238
+ // If we were called with a replacer function, then call the replacer to
239
+ // obtain a replacement value.
240
+
241
+ if (typeof rep === 'function') {
242
+ value = rep.call(holder, key, value);
243
+ }
244
+
245
+ // What happens next depends on the value's type.
246
+
247
+ switch (typeof value) {
248
+ case 'string':
249
+ return quote(value);
250
+
251
+ case 'number':
252
+
253
+ // JSON numbers must be finite. Encode non-finite numbers as null.
254
+
255
+ return isFinite(value) ? String(value) : 'null';
256
+
257
+ case 'boolean':
258
+ case 'null':
259
+
260
+ // If the value is a boolean or null, convert it to a string. Note:
261
+ // typeof null does not produce 'null'. The case is included here in
262
+ // the remote chance that this gets fixed someday.
263
+
264
+ return String(value);
265
+
266
+ // If the type is 'object', we might be dealing with an object or an array or
267
+ // null.
268
+
269
+ case 'object':
270
+
271
+ // Due to a specification blunder in ECMAScript, typeof null is 'object',
272
+ // so watch out for that case.
273
+
274
+ if (!value) {
275
+ return 'null';
276
+ }
277
+
278
+ // Make an array to hold the partial results of stringifying this object value.
279
+
280
+ gap += indent;
281
+ partial = [];
282
+
283
+ // Is the value an array?
284
+
285
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
286
+
287
+ // The value is an array. Stringify every element. Use null as a placeholder
288
+ // for non-JSON values.
289
+
290
+ length = value.length;
291
+ for (i = 0; i < length; i += 1) {
292
+ partial[i] = str(i, value) || 'null';
293
+ }
294
+
295
+ // Join all of the elements together, separated with commas, and wrap them in
296
+ // brackets.
297
+
298
+ v = partial.length === 0 ? '[]' :
299
+ gap ? '[\n' + gap +
300
+ partial.join(',\n' + gap) + '\n' +
301
+ mind + ']' :
302
+ '[' + partial.join(',') + ']';
303
+ gap = mind;
304
+ return v;
305
+ }
306
+
307
+ // If the replacer is an array, use it to select the members to be stringified.
308
+
309
+ if (rep && typeof rep === 'object') {
310
+ length = rep.length;
311
+ for (i = 0; i < length; i += 1) {
312
+ k = rep[i];
313
+ if (typeof k === 'string') {
314
+ v = str(k, value);
315
+ if (v) {
316
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
317
+ }
318
+ }
319
+ }
320
+ } else {
321
+
322
+ // Otherwise, iterate through all of the keys in the object.
323
+
324
+ for (k in value) {
325
+ if (Object.hasOwnProperty.call(value, k)) {
326
+ v = str(k, value);
327
+ if (v) {
328
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
329
+ }
330
+ }
331
+ }
332
+ }
333
+
334
+ // Join all of the member texts together, separated with commas,
335
+ // and wrap them in braces.
336
+
337
+ v = partial.length === 0 ? '{}' :
338
+ gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
339
+ mind + '}' : '{' + partial.join(',') + '}';
340
+ gap = mind;
341
+ return v;
342
+ }
343
+ }
344
+
345
+ // If the JSON object does not yet have a stringify method, give it one.
346
+
347
+ if (typeof JSON.stringify !== 'function') {
348
+ JSON.stringify = function (value, replacer, space) {
349
+
350
+ // The stringify method takes a value and an optional replacer, and an optional
351
+ // space parameter, and returns a JSON text. The replacer can be a function
352
+ // that can replace values, or an array of strings that will select the keys.
353
+ // A default replacer method can be provided. Use of the space parameter can
354
+ // produce text that is more easily readable.
355
+
356
+ var i;
357
+ gap = '';
358
+ indent = '';
359
+
360
+ // If the space parameter is a number, make an indent string containing that
361
+ // many spaces.
362
+
363
+ if (typeof space === 'number') {
364
+ for (i = 0; i < space; i += 1) {
365
+ indent += ' ';
366
+ }
367
+
368
+ // If the space parameter is a string, it will be used as the indent string.
369
+
370
+ } else if (typeof space === 'string') {
371
+ indent = space;
372
+ }
373
+
374
+ // If there is a replacer, it must be a function or an array.
375
+ // Otherwise, throw an error.
376
+
377
+ rep = replacer;
378
+ if (replacer && typeof replacer !== 'function' &&
379
+ (typeof replacer !== 'object' ||
380
+ typeof replacer.length !== 'number')) {
381
+ throw new Error('JSON.stringify');
382
+ }
383
+
384
+ // Make a fake root object containing our value under the key of ''.
385
+ // Return the result of stringifying the value.
386
+
387
+ return str('', {'': value});
388
+ };
389
+ }
390
+
391
+ // If the JSON object does not yet have a parse method, give it one.
392
+
393
+ if (typeof JSON.parse !== 'function') {
394
+ JSON.parse = function (text, reviver) {
395
+
396
+ // The parse method takes a text and an optional reviver function, and returns
397
+ // a JavaScript value if the text is a valid JSON text.
398
+
399
+ var j;
400
+
401
+ function walk(holder, key) {
402
+
403
+ // The walk method is used to recursively walk the resulting structure so
404
+ // that modifications can be made.
405
+
406
+ var k, v, value = holder[key];
407
+ if (value && typeof value === 'object') {
408
+ for (k in value) {
409
+ if (Object.hasOwnProperty.call(value, k)) {
410
+ v = walk(value, k);
411
+ if (v !== undefined) {
412
+ value[k] = v;
413
+ } else {
414
+ delete value[k];
415
+ }
416
+ }
417
+ }
418
+ }
419
+ return reviver.call(holder, key, value);
420
+ }
421
+
422
+ // Parsing happens in four stages. In the first stage, we replace certain
423
+ // Unicode characters with escape sequences. JavaScript handles many characters
424
+ // incorrectly, either silently deleting them, or treating them as line endings.
425
+
426
+ text = String(text);
427
+ cx.lastIndex = 0;
428
+ if (cx.test(text)) {
429
+ text = text.replace(cx, function (a) {
430
+ return '\\u' +
431
+ ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
432
+ });
433
+ }
434
+
435
+ // In the second stage, we run the text against regular expressions that look
436
+ // for non-JSON patterns. We are especially concerned with '()' and 'new'
437
+ // because they can cause invocation, and '=' because it can cause mutation.
438
+ // But just to be safe, we want to reject all unexpected forms.
439
+
440
+ // We split the second stage into 4 regexp operations in order to work around
441
+ // crippling inefficiencies in IE's and Safari's regexp engines. First we
442
+ // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
443
+ // replace all simple value tokens with ']' characters. Third, we delete all
444
+ // open brackets that follow a colon or comma or that begin the text. Finally,
445
+ // we look to see that the remaining characters are only whitespace or ']' or
446
+ // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
447
+
448
+ if (/^[\],:{}\s]*$/
449
+ .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
450
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
451
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
452
+
453
+ // In the third stage we use the eval function to compile the text into a
454
+ // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
455
+ // in JavaScript: it can begin a block or an object literal. We wrap the text
456
+ // in parens to eliminate the ambiguity.
457
+
458
+ j = eval('(' + text + ')');
459
+
460
+ // In the optional fourth stage, we recursively walk the new structure, passing
461
+ // each name/value pair to a reviver function for possible transformation.
462
+
463
+ return typeof reviver === 'function' ?
464
+ walk({'': j}, '') : j;
465
+ }
466
+
467
+ // If the text is not JSON parseable, then a SyntaxError is thrown.
468
+
469
+ throw new SyntaxError('JSON.parse');
470
+ };
471
+ }
472
+ }());