Repository navigation
feat(codemode): add Node's Buffer - #64365
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
This looks sound to me. I ran Code Mode programs on the base and on this branch. On the base, Buffer is undefined. With the PR, the documented behaviour works:
JSON.parse(buf)and string coercion give the text.slice/subarrayreturn Buffers that share the original bytes.write/copy/fillwrite into the program's bytes.- Host errors keep Node's
code. - Buffers cross extensions as Buffers in both directions, including inside nested objects.
The codemode suite passes (1654 tests), and so does tsc --noEmit.
Public API: unchanged. The new global only exists inside Code Mode programs; nothing in the SDK, server, plugins, config or CLI changes.
I have no blocking concerns.
3 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
None.
Type of change
What does this PR do?
Code Mode programs get Node's
Buffer. Today they only haveUint8Array, so Node-style code likefs.readFileSync(p).toString()orJSON.parse(buffer)gets"104,105"instead of text. This is the binary type #61186 needs forfsto behave like Node.How it works:
TypeErrorwith Node'sERR_UNKNOWN_ENCODING.from,alloc,allocUnsafe,concat,byteLength,compare,isBuffer,isEncoding. Methods:toString,toJSON,slice/subarray(views on the same bytes),equals,compare,indexOf,includes,write,fill,copy, and the integer and floatread*/write*methods.Buffer(Node and Bun), so the package still runs in browsers, whereBufferstays undefined.Not included: the
BigInt64read/write methods (programs have no BigInt), andUint8Arraymethods likemapreturn aUint8Arrayrather than aBuffer.How did you verify your code works?
test/buffer.test.ts: encodings and string coercion,instanceof/isBuffer,concatand shared-memorysubarray, number reads and writes,toJSONand the unknown-encoding error, crossing an extension in both directions as a Buffer, andimport("node:buffer").test/snapshot.test.ts.packages/codemode:bun test(1654 pass) andCODEMODE_ROUNDTRIP=1for the new tests,bun typecheck.Screenshots / recordings
Not a UI change.
Checklist