|
1 |
| -'use strict'; |
2 |
| - |
3 |
| -const Benchmark = require('benchmark'); |
4 |
| -const Bourne = require('..'); |
| 1 | +'use strict' |
5 | 2 |
|
| 3 | +const Benchmark = require('benchmark') |
| 4 | +const Bourne = require('..') |
6 | 5 |
|
7 | 6 | const internals = {
|
8 |
| - text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }', |
9 |
| - invalid: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } } }' |
10 |
| -}; |
11 |
| - |
12 |
| - |
13 |
| -const suite = new Benchmark.Suite(); |
| 7 | + text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }', |
| 8 | + invalid: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } } }' |
| 9 | +} |
14 | 10 |
|
| 11 | +const suite = new Benchmark.Suite() |
15 | 12 |
|
16 | 13 | suite
|
17 |
| - .add('JSON.parse', () => { |
18 |
| - |
19 |
| - JSON.parse(internals.text); |
20 |
| - }) |
21 |
| - .add('JSON.parse error', () => { |
22 |
| - |
23 |
| - try { |
24 |
| - JSON.parse(internals.invalid); |
25 |
| - } |
26 |
| - catch (ignoreErr) { } |
27 |
| - }) |
28 |
| - .add('Bourne.parse', () => { |
29 |
| - |
30 |
| - try { |
31 |
| - Bourne.parse(internals.text); |
32 |
| - } |
33 |
| - catch (ignoreErr) { } |
34 |
| - }) |
35 |
| - .add('reviver', () => { |
36 |
| - |
37 |
| - try { |
38 |
| - JSON.parse(internals.text, internals.reviver); |
39 |
| - } |
40 |
| - catch (ignoreErr) { } |
41 |
| - }) |
42 |
| - .on('cycle', (event) => { |
43 |
| - |
44 |
| - console.log(String(event.target)); |
45 |
| - }) |
46 |
| - .on('complete', function () { |
47 |
| - |
48 |
| - console.log('Fastest is ' + this.filter('fastest').map('name')); |
49 |
| - }) |
50 |
| - .run({ async: true }); |
51 |
| - |
| 14 | + .add('JSON.parse', () => { |
| 15 | + JSON.parse(internals.text) |
| 16 | + }) |
| 17 | + .add('JSON.parse error', () => { |
| 18 | + try { |
| 19 | + JSON.parse(internals.invalid) |
| 20 | + } catch (ignoreErr) { } |
| 21 | + }) |
| 22 | + .add('Bourne.parse', () => { |
| 23 | + try { |
| 24 | + Bourne.parse(internals.text) |
| 25 | + } catch (ignoreErr) { } |
| 26 | + }) |
| 27 | + .add('reviver', () => { |
| 28 | + try { |
| 29 | + JSON.parse(internals.text, internals.reviver) |
| 30 | + } catch (ignoreErr) { } |
| 31 | + }) |
| 32 | + .on('cycle', (event) => { |
| 33 | + console.log(String(event.target)) |
| 34 | + }) |
| 35 | + .on('complete', function () { |
| 36 | + console.log('Fastest is ' + this.filter('fastest').map('name')) |
| 37 | + }) |
| 38 | + .run({ async: true }) |
52 | 39 |
|
53 | 40 | internals.reviver = function (key, value) {
|
| 41 | + if (key === '__proto__') { |
| 42 | + throw new Error('kaboom') |
| 43 | + } |
54 | 44 |
|
55 |
| - if (key === '__proto__') { |
56 |
| - throw new Error('kaboom'); |
57 |
| - } |
58 |
| - |
59 |
| - return value; |
60 |
| -}; |
61 |
| - |
| 45 | + return value |
| 46 | +} |
0 commit comments