authorgravatar for wink@saville.comWink Saville <wink@saville.com> 2018-11-18 10:14:37-08:00
committergravatar for wink@saville.comWink Saville <wink@saville.com> 2018-11-18 10:14:37-08:00
log8d54cbb834ab606ecfe23c6514cbac699319f60c
tree1b60a2ecdb86c497b3ab4cfe589d29f66a6e1985
parente9b47d960b81dfc1fd70c5ae663b4b692ab0b19d
signature Commit is signed but in an unrecognized format.

Fix pushToParent to work for arrays of Objects

The reference `*array` is a copy of the value on the stack. Instead use a reference to top of stack. This is the same technique used above for `var object` in `Value.String`. Added two simple tests.

1 files changed, 10 insertions(+), 2 deletions(-)

std/json.zig+10-2
...@@ -1323,7 +1323,8 @@ pub const Parser = struct {...@@ -1323,7 +1323,8 @@ pub const Parser = struct {
1323 p.state = State.ObjectKey;1323 p.state = State.ObjectKey;
1324 },1324 },
1325 // Array Parent -> [ ..., <array>, value ]1325 // Array Parent -> [ ..., <array>, value ]
1326 Value.Array => |*array| {1326 Value.Array => {
1327 var array = &p.stack.items[p.stack.len - 1].Array;
1327 try array.append(value);1328 try array.append(value);
1328 p.state = State.ArrayValue;1329 p.state = State.ArrayValue;
1329 },1330 },
...@@ -1364,7 +1365,8 @@ test "json parser dynamic" {...@@ -1364,7 +1365,8 @@ test "json parser dynamic" {
1364 \\ "Width": 1001365 \\ "Width": 100
1365 \\ },1366 \\ },
1366 \\ "Animated" : false,1367 \\ "Animated" : false,
1367 \\ "IDs": [116, 943, 234, 38793]1368 \\ "IDs": [116, 943, 234, 38793],
1369 \\ "ArrayOfObject": [{"n": "m"}]
1368 \\ }1370 \\ }
1369 \\}1371 \\}
1370 ;1372 ;
...@@ -1387,4 +1389,10 @@ test "json parser dynamic" {...@@ -1387,4 +1389,10 @@ test "json parser dynamic" {
13871389
1388 const animated = image.Object.get("Animated").?.value;1390 const animated = image.Object.get("Animated").?.value;
1389 debug.assert(animated.Bool == false);1391 debug.assert(animated.Bool == false);
1392
1393 const array_of_object = image.Object.get("ArrayOfObject").?.value;
1394 debug.assert(array_of_object.Array.len == 1);
1395
1396 const obj0 = array_of_object.Array.at(0).Object.get("n").?.value;
1397 debug.assert(mem.eql(u8, obj0.String, "m"));
1390}1398}