-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathno__proto__.js
executable file
·47 lines (31 loc) · 1.02 KB
/
no__proto__.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const Benchmark = require('benchmark');
const Bourne = require('..');
const internals = {
text: '{ "a": 5, "b": 6, "proto": { "x": 7 }, "c": { "d": 0, "e": "text", "\\u005f\\u005fproto": { "y": 8 }, "f": { "g": 2 } } }',
suspectRx: /"(?:_|\\u005f)(?:_|\\u005f)(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006f)(?:t|\\u0074)(?:o|\\u006f)(?:_|\\u005f)(?:_|\\u005f)"/
};
const suite = new Benchmark.Suite();
suite
.add('JSON.parse', () => {
JSON.parse(internals.text);
})
.add('Bourne.parse', () => {
Bourne.parse(internals.text);
})
.add('reviver', () => {
JSON.parse(internals.text, internals.reviver);
})
.on('cycle', (event) => {
console.log(String(event.target));
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ async: true });
internals.reviver = function (key, value) {
if (key.match(internals.suspectRx)) {
return undefined;
}
return value;
};