fatsify核心功能示例测试!!!
This commit is contained in:
35
node_modules/secure-json-parse/benchmarks/ignore.js
generated
vendored
Normal file
35
node_modules/secure-json-parse/benchmarks/ignore.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict'
|
||||
|
||||
const Benchmark = require('benchmark')
|
||||
const sjson = require('..')
|
||||
|
||||
const internals = {
|
||||
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }'
|
||||
}
|
||||
|
||||
const suite = new Benchmark.Suite()
|
||||
|
||||
suite
|
||||
.add('JSON.parse', () => {
|
||||
JSON.parse(internals.text)
|
||||
})
|
||||
.add('secure-json-parse parse', () => {
|
||||
sjson.parse(internals.text, { protoAction: 'ignore' })
|
||||
})
|
||||
.add('secure-json-parse safeParse', () => {
|
||||
sjson.safeParse(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) {
|
||||
return value
|
||||
}
|
||||
40
node_modules/secure-json-parse/benchmarks/no__proto__.js
generated
vendored
Normal file
40
node_modules/secure-json-parse/benchmarks/no__proto__.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict'
|
||||
|
||||
const Benchmark = require('benchmark')
|
||||
const sjson = 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('secure-json-parse parse', () => {
|
||||
sjson.parse(internals.text)
|
||||
})
|
||||
.add('secure-json-parse safeParse', () => {
|
||||
sjson.safeParse(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
|
||||
}
|
||||
15
node_modules/secure-json-parse/benchmarks/package.json
generated
vendored
Normal file
15
node_modules/secure-json-parse/benchmarks/package.json
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "benchmarks",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"valid": "node valid.js",
|
||||
"ignore": "node ignore.js",
|
||||
"no_proto": "node no__proto__.js",
|
||||
"remove": "node remove.js",
|
||||
"throw": "node throw.js",
|
||||
"all": "node --version && npm run valid && npm run ignore && npm run no_proto && npm run remove && npm run throw"
|
||||
},
|
||||
"dependencies": {
|
||||
"benchmark": "^2.1.4"
|
||||
}
|
||||
}
|
||||
39
node_modules/secure-json-parse/benchmarks/remove.js
generated
vendored
Normal file
39
node_modules/secure-json-parse/benchmarks/remove.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
'use strict'
|
||||
|
||||
const Benchmark = require('benchmark')
|
||||
const sjson = require('..')
|
||||
|
||||
const internals = {
|
||||
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }'
|
||||
}
|
||||
|
||||
const suite = new Benchmark.Suite()
|
||||
|
||||
suite
|
||||
.add('JSON.parse', () => {
|
||||
JSON.parse(internals.text)
|
||||
})
|
||||
.add('secure-json-parse parse', () => {
|
||||
sjson.parse(internals.text, { protoAction: 'remove' })
|
||||
})
|
||||
.add('secure-json-parse safeParse', () => {
|
||||
sjson.safeParse(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 === '__proto__') {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
49
node_modules/secure-json-parse/benchmarks/throw.js
generated
vendored
Normal file
49
node_modules/secure-json-parse/benchmarks/throw.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
'use strict'
|
||||
|
||||
const Benchmark = require('benchmark')
|
||||
const sjson = require('..')
|
||||
|
||||
const internals = {
|
||||
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }',
|
||||
invalid: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } } }'
|
||||
}
|
||||
|
||||
const suite = new Benchmark.Suite()
|
||||
|
||||
suite
|
||||
.add('JSON.parse valid', () => {
|
||||
JSON.parse(internals.text)
|
||||
})
|
||||
.add('JSON.parse error', () => {
|
||||
try {
|
||||
JSON.parse(internals.invalid)
|
||||
} catch { }
|
||||
})
|
||||
.add('secure-json-parse parse', () => {
|
||||
try {
|
||||
sjson.parse(internals.invalid)
|
||||
} catch { }
|
||||
})
|
||||
.add('secure-json-parse safeParse', () => {
|
||||
sjson.safeParse(internals.invalid)
|
||||
})
|
||||
.add('reviver', () => {
|
||||
try {
|
||||
JSON.parse(internals.invalid, internals.reviver)
|
||||
} catch { }
|
||||
})
|
||||
.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 === '__proto__') {
|
||||
throw new Error('kaboom')
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
49
node_modules/secure-json-parse/benchmarks/valid.js
generated
vendored
Normal file
49
node_modules/secure-json-parse/benchmarks/valid.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
'use strict'
|
||||
|
||||
const Benchmark = require('benchmark')
|
||||
const sjson = require('..')
|
||||
|
||||
const internals = {
|
||||
text: '{ "a": 5, "b": 6, "c": { "d": 0, "e": "text", "f": { "g": 2 } } }',
|
||||
proto: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }'
|
||||
}
|
||||
|
||||
const suite = new Benchmark.Suite()
|
||||
|
||||
suite
|
||||
.add('JSON.parse', () => {
|
||||
JSON.parse(internals.text)
|
||||
})
|
||||
.add('JSON.parse proto', () => {
|
||||
JSON.parse(internals.proto)
|
||||
})
|
||||
.add('secure-json-parse parse', () => {
|
||||
sjson.parse(internals.text)
|
||||
})
|
||||
.add('secure-json-parse parse proto', () => {
|
||||
sjson.parse(internals.text, { constructorAction: 'ignore', protoAction: 'ignore' })
|
||||
})
|
||||
.add('secure-json-parse safeParse', () => {
|
||||
sjson.safeParse(internals.text)
|
||||
})
|
||||
.add('secure-json-parse safeParse proto', () => {
|
||||
sjson.safeParse(internals.proto)
|
||||
})
|
||||
.add('JSON.parse 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 === '__proto__') {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
Reference in New Issue
Block a user