@@ -31,40 +31,73 @@ assert(test_object.Has(newObject, 'test_number'));
31
31
assert . strictEqual ( newObject . test_number , 987654321 ) ;
32
32
assert . strictEqual ( newObject . test_string , 'test string' ) ;
33
33
34
- // test_object.Inflate increases all properties by 1
35
- const cube = {
36
- x : 10 ,
37
- y : 10 ,
38
- z : 10
39
- } ;
34
+ {
35
+ // test_object.Inflate increases all properties by 1
36
+ const cube = {
37
+ x : 10 ,
38
+ y : 10 ,
39
+ z : 10
40
+ } ;
40
41
41
- assert . deepStrictEqual ( test_object . Inflate ( cube ) , { x : 11 , y : 11 , z : 11 } ) ;
42
- assert . deepStrictEqual ( test_object . Inflate ( cube ) , { x : 12 , y : 12 , z : 12 } ) ;
43
- assert . deepStrictEqual ( test_object . Inflate ( cube ) , { x : 13 , y : 13 , z : 13 } ) ;
44
- cube . t = 13 ;
45
- assert . deepStrictEqual ( test_object . Inflate ( cube ) , { x : 14 , y : 14 , z : 14 , t : 14 } ) ;
46
-
47
- const sym1 = Symbol ( '1' ) ;
48
- const sym2 = Symbol ( '2' ) ;
49
- const sym3 = Symbol ( '3' ) ;
50
- const sym4 = Symbol ( '4' ) ;
51
- const object2 = {
52
- [ sym1 ] : '@@iterator' ,
53
- [ sym2 ] : sym3
54
- } ;
42
+ assert . deepStrictEqual ( test_object . Inflate ( cube ) , { x : 11 , y : 11 , z : 11 } ) ;
43
+ assert . deepStrictEqual ( test_object . Inflate ( cube ) , { x : 12 , y : 12 , z : 12 } ) ;
44
+ assert . deepStrictEqual ( test_object . Inflate ( cube ) , { x : 13 , y : 13 , z : 13 } ) ;
45
+ cube . t = 13 ;
46
+ assert . deepStrictEqual (
47
+ test_object . Inflate ( cube ) , { x : 14 , y : 14 , z : 14 , t : 14 } ) ;
48
+
49
+ const sym1 = Symbol ( '1' ) ;
50
+ const sym2 = Symbol ( '2' ) ;
51
+ const sym3 = Symbol ( '3' ) ;
52
+ const sym4 = Symbol ( '4' ) ;
53
+ const object2 = {
54
+ [ sym1 ] : '@@iterator' ,
55
+ [ sym2 ] : sym3
56
+ } ;
57
+
58
+ assert ( test_object . Has ( object2 , sym1 ) ) ;
59
+ assert ( test_object . Has ( object2 , sym2 ) ) ;
60
+ assert . strictEqual ( test_object . Get ( object2 , sym1 ) , '@@iterator' ) ;
61
+ assert . strictEqual ( test_object . Get ( object2 , sym2 ) , sym3 ) ;
62
+ assert ( test_object . Set ( object2 , 'string' , 'value' ) ) ;
63
+ assert ( test_object . Set ( object2 , sym4 , 123 ) ) ;
64
+ assert ( test_object . Has ( object2 , 'string' ) ) ;
65
+ assert ( test_object . Has ( object2 , sym4 ) ) ;
66
+ assert . strictEqual ( test_object . Get ( object2 , 'string' ) , 'value' ) ;
67
+ assert . strictEqual ( test_object . Get ( object2 , sym4 ) , 123 ) ;
68
+ }
69
+
70
+ {
71
+ // Wrap a pointer in a JS object, then verify the pointer can be unwrapped.
72
+ const wrapper = { } ;
73
+ test_object . Wrap ( wrapper ) ;
74
+
75
+ assert ( test_object . Unwrap ( wrapper ) ) ;
76
+ }
77
+
78
+ {
79
+ // Verify that wrapping doesn't break an object's prototype chain.
80
+ const wrapper = { } ;
81
+ const protoA = { protoA : true } ;
82
+ Object . setPrototypeOf ( wrapper , protoA ) ;
83
+ test_object . Wrap ( wrapper ) ;
84
+
85
+ assert ( test_object . Unwrap ( wrapper ) ) ;
86
+ assert ( wrapper . protoA ) ;
87
+ }
88
+
89
+ {
90
+ // Verify the pointer can be unwrapped after inserting in the prototype chain.
91
+ const wrapper = { } ;
92
+ const protoA = { protoA : true } ;
93
+ Object . setPrototypeOf ( wrapper , protoA ) ;
94
+ test_object . Wrap ( wrapper ) ;
95
+
96
+ const protoB = { protoB : true } ;
97
+ Object . setPrototypeOf ( protoB , Object . getPrototypeOf ( wrapper ) ) ;
98
+ Object . setPrototypeOf ( wrapper , protoB ) ;
55
99
56
- assert ( test_object . Has ( object2 , sym1 ) ) ;
57
- assert ( test_object . Has ( object2 , sym2 ) ) ;
58
- assert . strictEqual ( test_object . Get ( object2 , sym1 ) , '@@iterator' ) ;
59
- assert . strictEqual ( test_object . Get ( object2 , sym2 ) , sym3 ) ;
60
- assert ( test_object . Set ( object2 , 'string' , 'value' ) ) ;
61
- assert ( test_object . Set ( object2 , sym4 , 123 ) ) ;
62
- assert ( test_object . Has ( object2 , 'string' ) ) ;
63
- assert ( test_object . Has ( object2 , sym4 ) ) ;
64
- assert . strictEqual ( test_object . Get ( object2 , 'string' ) , 'value' ) ;
65
- assert . strictEqual ( test_object . Get ( object2 , sym4 ) , 123 ) ;
66
-
67
- // Wrap a pointer in a JS object, then verify that the pointer can be unwrapped.
68
- const wrapper = { } ;
69
- test_object . Wrap ( wrapper ) ;
70
- assert ( test_object . Unwrap ( wrapper ) ) ;
100
+ assert ( test_object . Unwrap ( wrapper ) ) ;
101
+ assert ( wrapper . protoA , true ) ;
102
+ assert ( wrapper . protoB , true ) ;
103
+ }
0 commit comments