@@ -227,4 +227,53 @@ function test (binding) {
227227 assert . strictEqual ( binding . object . setPrototype ( obj , prototype ) , true ) ;
228228 assert . strictEqual ( Object . getPrototypeOf ( obj ) , prototype ) ;
229229 }
230+
231+ if ( 'createObjectWithProperties' in binding . object ) {
232+ {
233+ const prototype = { } ;
234+ const names = [ 'name' , 'age' , 'active' , Symbol . for ( 'id' ) ] ;
235+ const values = [ 'Foo' , 42 , true , 12345 ] ;
236+ const obj = binding . object . createObjectWithProperties ( prototype , names , values ) ;
237+ const descriptors = Object . getOwnPropertyDescriptors ( obj ) ;
238+
239+ assert . strictEqual ( Object . getPrototypeOf ( obj ) , prototype ) ;
240+
241+ assert . equal ( Reflect . ownKeys ( descriptors ) . length , names . length ) ;
242+
243+ for ( let i = 0 ; i < names . length ; i ++ ) {
244+ const expectedName = names [ i ] ;
245+ const expectedValue = values [ i ] ;
246+
247+ assert . ok ( expectedName in descriptors ) ;
248+ assert . strictEqual ( descriptors [ expectedName ] . value , expectedValue ) ;
249+ }
250+ }
251+
252+ {
253+ // Test `null` Napi::Value passed as prototype
254+ const prototype = null ;
255+ const obj = binding . object . createObjectWithProperties ( prototype ) ;
256+ assert . strictEqual ( Object . getPrototypeOf ( obj ) , prototype ) ;
257+ }
258+
259+ {
260+ // Test empty Napi::Value passed as prototype
261+ const obj = binding . object . createObjectWithProperties ( ) ;
262+ assert . strictEqual ( Object . getPrototypeOf ( obj ) , null ) ;
263+ }
264+
265+ {
266+ // Test mismatch in length between property names and values
267+ const expectedErrorMessage = 'Mismatch in size of property names and values' ;
268+
269+ try {
270+ binding . object . createObjectWithProperties ( null , [ 'foo' ] , [ ] ) ;
271+ throw new Error ( `Expected error "${ expectedErrorMessage } " was not thrown` ) ;
272+ } catch ( e ) {
273+ if ( e . message !== expectedErrorMessage ) {
274+ throw e ;
275+ }
276+ }
277+ }
278+ }
230279}
0 commit comments