File tree Expand file tree Collapse file tree 3 files changed +57
-3
lines changed Expand file tree Collapse file tree 3 files changed +57
-3
lines changed Original file line number Diff line number Diff line change 11'use strict'
22
3+ const { NullObject } = require ( './null-object' )
34const httpMethodStrategy = require ( './strategies/http-method' )
45
56class HandlerStorage {
@@ -61,11 +62,20 @@ class HandlerStorage {
6162 }
6263
6364 _compileCreateParamsObject ( params ) {
64- const lines = [ ]
65+ const fnBody = [ ]
66+
67+ fnBody . push ( 'const fn = function _createParamsObject (paramsArray) {' )
68+
69+ fnBody . push ( 'const params = new NullObject()' )
6570 for ( let i = 0 ; i < params . length ; i ++ ) {
66- lines . push ( `'${ params [ i ] } ': paramsArray[${ i } ]` )
71+ fnBody . push ( `params[ '${ params [ i ] } '] = paramsArray[${ i } ]` )
6772 }
68- return new Function ( 'paramsArray' , `return {${ lines . join ( ',' ) } }` ) // eslint-disable-line
73+ fnBody . push ( 'return params' )
74+ fnBody . push ( '}' )
75+
76+ fnBody . push ( 'return fn' )
77+
78+ return new Function ( 'NullObject' , fnBody . join ( '\n' ) ) ( NullObject ) // eslint-disable-line
6979 }
7080
7181 _getHandlerMatchingConstraints ( ) {
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const NullObject = function ( ) { }
4+ NullObject . prototype = Object . create ( null )
5+
6+ module . exports = {
7+ NullObject
8+ }
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const { test } = require ( 'tap' )
4+ const { NullObject } = require ( '../lib/null-object' )
5+
6+ test ( 'NullObject' , t => {
7+ t . plan ( 2 )
8+ const nullObject = new NullObject ( )
9+ t . ok ( nullObject instanceof NullObject )
10+ t . ok ( typeof nullObject === 'object' )
11+ } )
12+
13+ test ( 'has no methods from generic Object class' , t => {
14+ function getAllPropertyNames ( obj ) {
15+ var props = [ ]
16+
17+ do {
18+ Object . getOwnPropertyNames ( obj ) . forEach ( function ( prop ) {
19+ if ( props . indexOf ( prop ) === - 1 ) {
20+ props . push ( prop )
21+ }
22+ } )
23+ } while ( obj = Object . getPrototypeOf ( obj ) ) // eslint-disable-line
24+
25+ return props
26+ }
27+ const propertyNames = getAllPropertyNames ( { } )
28+ t . plan ( propertyNames . length + 1 )
29+
30+ const nullObject = new NullObject ( )
31+
32+ for ( const propertyName of propertyNames ) {
33+ t . notOk ( propertyName in nullObject , propertyName )
34+ }
35+ t . equal ( getAllPropertyNames ( nullObject ) . length , 0 )
36+ } )
You can’t perform that action at this time.
0 commit comments