Repository: denoland/deno
Pull request: fix(ext/node): make Buffer work with resizable ABs

Enables `parallel/test-buffer-resizable.js`

Changed files:
filename: ext/node/polyfills/internal/buffer.mjs
patch: @@ -993,9 +993,7 @@ function fromArrayBuffer(obj, byteOffset, length) {
     throw new codes.ERR_BUFFER_OUT_OF_BOUNDS("offset");
   }
 
-  if (length === undefined) {
-    length = maxLength;
-  } else {
+  if (length !== undefined) {
     // Convert length to non-negative integer.
     length = +length;
     if (length > 0) {

filename: tests/node_compat/config.jsonc
patch: @@ -294,6 +294,7 @@
       "test-buffer-readfloat.js",
       "test-buffer-readint.js",
       "test-buffer-readuint.js",
+      "test-buffer-resizable.js",
       "test-buffer-safe-unsafe.js",
       "test-buffer-set-inspect-max-bytes.js",
       "test-buffer-sharedarraybuffer.js",

filename: tests/node_compat/runner/TODO.md
patch: @@ -1,7 +1,7 @@
 <!-- deno-fmt-ignore-file -->
 # Remaining Node Tests
 
-1181 tests out of 3993 have been ported from Node 23.9.0 (29.58% ported, 70.95% remaining).
+1184 tests out of 3993 have been ported from Node 23.9.0 (29.65% ported, 70.87% remaining).
 
 NOTE: This file should not be manually edited. Please edit `tests/node_compat/config.json` and run `deno task setup` in `tests/node_compat/runner` dir instead.
 
@@ -291,7 +291,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co
 - [parallel/test-buffer-pending-deprecation.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-buffer-pending-deprecation.js)
 - [parallel/test-buffer-pool-untransferable.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-buffer-pool-untransferable.js)
 - [parallel/test-buffer-prototype-inspect.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-buffer-prototype-inspect.js)
-- [parallel/test-buffer-resizable.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-buffer-resizable.js)
 - [parallel/test-c-ares.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-c-ares.js)
 - [parallel/test-child-process-advanced-serialization-largebuffer.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-child-process-advanced-serialization-largebuffer.js)
 - [parallel/test-child-process-advanced-serialization-splitted-length-field.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-child-process-advanced-serialization-splitted-length-field.js)

filename: tests/node_compat/test/parallel/test-buffer-resizable.js
patch: @@ -0,0 +1,36 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 23.9.0
+// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
+
+// Flags: --no-warnings
+'use strict';
+
+require('../common');
+const { Buffer } = require('node:buffer');
+const { strictEqual } = require('node:assert');
+const { describe, it } = require('node:test');
+
+describe('Using resizable ArrayBuffer with Buffer...', () => {
+  it('works as expected', () => {
+    const ab = new ArrayBuffer(10, { maxByteLength: 20 });
+    const buffer = Buffer.from(ab, 1);
+    strictEqual(buffer.byteLength, 9);
+    ab.resize(15);
+    strictEqual(buffer.byteLength, 14);
+    ab.resize(5);
+    strictEqual(buffer.byteLength, 4);
+  });
+
+  it('works with the deprecated constructor also', () => {
+    const ab = new ArrayBuffer(10, { maxByteLength: 20 });
+    const buffer = new Buffer(ab, 1);
+    strictEqual(buffer.byteLength, 9);
+    ab.resize(15);
+    strictEqual(buffer.byteLength, 14);
+    ab.resize(5);
+    strictEqual(buffer.byteLength, 4);
+  });
+});