[json] Make json parsing iterative
This avoids the need to throw range errors when we run out of stack, limiting us only by available memory. The main parser loop is implemented by two subloops. The first subloop finishes whenever it generates primitive values, empty arrays, or empty objects. If a non-empty object or array is started, the loop continues to parse its first member. The second subloop consumes produced values and either adds them to the parent array or object, or returns it. The second loop finishes whenever a next value needs to be produced. When the loop itself produces a finished array or object, the loop continues. Exceptions are handled by moving the cursor to end-of-input. Upon end-of-input, the first loop sets the continuation to "kFail". That causes the second loop to tear down continuation stack and related handle scopes, resulting in an empty handle. The CL additionally buffers all named properties and elements so we can immediately allocate a correctly shaped object. For object elements we'll take flat array or dictionary encoding depending on what is more efficient. This means that element handles are now allocated in their parent HandleScope, rather than having local handlescopes per-property (of big objects); which is why I've adjusted the handle-count test to not allocate as many properties. In the future it would be nice to not have to allocate (as many) handles since almost everything in the JSON graph will survive JSON parsing... Bug: chromium:710383 Change-Id: Ia3a7fd0ac260fb1c0e5f929276792b2f8e5fc0ca Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1609802Reviewed-by: Hannes Payer <hpayer@chromium.org> Reviewed-by: Igor Sheludko <ishell@chromium.org> Commit-Queue: Toon Verwaest <verwaest@chromium.org> Cr-Commit-Position: refs/heads/master@{#61533}
Showing
This diff is collapsed.
Please
register
or
sign in
to comment