webcpp's rules apply here: read the superproject's CODING-GUIDELINES.md (https://github.com/webcpporg/webcpp/blob/main/CODING-GUIDELINES.md), whose chapter 15 gives document's design decisions with their reasons, and its AGENTS.md (https://github.com/webcpporg/webcpp/blob/main/AGENTS.md) first. This file holds only what is specific to document.
- webcpp's own library (
"port-of": null): a JSON document whose behaviour is JavaScript's. Node is its oracle:test/oracleruns the same cases in Node and in C++, and the bytes must agree. - Its core never throws. Every operation that can fail returns
result; it finds its room in the heap before it allocates, so a full heap is an error value. Only the sugar (v = x,as<T>(),as_string(),as_bool(),parse_or_throw) throws, and each carries the constraintdetail::exceptions_enabled, so a build without exceptions refuses a call to it. - The JavaScript API (
js/) is built byjs/Jamfile,js/shared/Jamfileandjs/npm/Jamfileinto the build directory, and installed intojs/packagefrom there.test/js/Jamfiletests it as the own lanejs(b2 toolset=emscripten libs/document/test/js//js), so that the lint compilesjs/binding.cpp,js/binding.hppandjs/shared/binding.cppand the CI runs the tests. The C++ names are snake_case; the JavaScript names (NativeDocument,getDecimal) appear only in theEMSCRIPTEN_BINDINGSregistrations, which the wrappers and the tests use. - One image. A 64-byte header, then Boost.Interprocess's
rbtree_best_fitheap, used directly; every pointer in it anoffset_ptr<..., std::int64_t, std::uint64_t, 8>.
- Never include
managed_external_buffer.hpp,segment_manager.hpp,allocators/allocator.hpporsync/mutex_family.hppfrom Boost.Interprocess: they throw bare and do not compile without exceptions. - No floating point outside
js_traitsand its codec; no hashed container; nodes are built in place (emplace), never copied from a temporary; the allocator zeroes every block it hands out and frees. - Every allocation an operation makes outside the image goes through the document's allocator,
rebound (
detail::rebound, constructed from it, never converted to), and is made before the operation's first change, so that with exceptions an allocator's failure, whichdetail::unless_allocation_failsalone catches (std::bad_alloc, a type derived from it, or Boost.Interprocess'sbad_alloc), iserrc::capacitywith the document's content as it was; an erasure, a lookup and==allocate nothing, and aconstoperation allocates in the document's allocator only as the page's "Reads from several threads" lists. An image's blocks the allocator gives at another alignment than 16 are given back, and a change a place cannot take is refused before its value is prepared. Theallocator*tests count the globaloperator newand fail an operation at each of its allocations: a container of the standard allocator in an operation fails them. Boost.JSON's suspension stack, in a parse fed in chunks, is the one exception. - The values of
errcandkind, the category's identity0x646f63756d656e74("document") and the image's header layout never change; a layout change raises the image's format version. - Boost.MultiIndex erases an element whose
modifythrows: amodifyonly swaps prepared values. asio.hppis the one header that includes Boost.Asio, which builds natively only: the convenience header leaves it out,test/Jamfilecompiles it alone natively, and every program that includes it is declarednative.
doc/document.adocincludes one file per section, in this order:introduction.adoc,gains.adoc,js-module.adoc,javascript.adoc,handles.adoc,numbers.adoc,strings.adoc,order.adoc,arrays.adoc,containers.adoc,stringify.adoc,parsing.adoc,streams.adoc,selectors.adoc,traits.adoc,images.adoc,allocation.adoc,wire.adoc,sharing.adoc,boost-json.adoc,exceptions.adoc,errors.adoc,testing.adoc,benchmarks.adoc, then the reference and the changelog.b2 libs/document/docbuilds it with the strict reference.- Each
@see "<title>"of a Doc Comment names a section's title: "Introduction", "What C++ gives JavaScript", "Using it from JavaScript", "From JavaScript", "Handles", "Numbers", "Strings, dates and bytes", "Key order", "Arrays", "Containers", "Writing JSON", "Parsing", "Streams of documents", "Selectors", "Traits", "Images", "Allocators", "Images on the wire", "Sealed images", "Sharing", "Compared with Boost.JSON", "The sugar that throws", "Errors", "Testing", "Benchmarks". Renaming a section renames its@seelines in the same commit; doc-check fails otherwise. - The guide's programs are
example/document_<topic>.cpp, each with its.expected, whose lines are what Node prints for the same JavaScript wherever the page does not say otherwise; check a new output against Node before committing it. The page shows their regions by tag and their outputs bylines=: a change to a program's output checks thelines=ranges of the sections that show it. document_stream_js.cppis the one example that Node drives (document_stream_js.mjs, underwebcpp.driveinexample/Jamfile), on emscripten only and in the own lanejs: the script compares what it prints withdocument_stream_js.expected, which it is given by path.document_javascript.cppshows the sugar and declares<exception-handling>on;document_no_exceptions.cppdeclares<exception-handling>off. Every other example builds both ways.document_image.expectedholds a digest of an image, which is the same on every target: a change to the image's layout, or to what the example stores, changes it on every target at once.document_allocators.expectedis C++'s alone, which its section says: its JSON lines are what Node prints for the same steps, and it prints nothing that depends on where a resource's bytes go (a count or size of allocations), which libstdc++'s and libc++'s growth policies and small-string buffers make differ between targets.- The README copies
example/document_quick_start.cpp[tag=program]and its output; doc-check compares the copy at every doc build.