Repository: denoland/deno
Pull request: test(ext/node): respect --allow-natives-syntax v8 flag in compat test runner

This PR enables `parallel/test-buffer-write-fast.js`.

The test case uses `--allow-natives-syntax` flag. This change add handling of that flag and passes it to `--v8-flags` option of Deno.

Changed files:
filename: tests/node_compat/common.ts
patch: @@ -167,6 +167,9 @@ export async function runNodeCompatTestCase(
         v8Flags.push("--expose-gc");
         knownGlobals.push("gc");
         break;
+      case "--allow-natives-syntax":
+        v8Flags.push("--allow-natives-syntax");
+        break;
       default:
         break;
     }

filename: tests/node_compat/config.jsonc
patch: @@ -304,6 +304,7 @@
       "test-buffer-tostring-range.js",
       "test-buffer-tostring-rangeerror.js",
       "test-buffer-tostring.js",
+      "test-buffer-write-fast.js",
       "test-buffer-write.js",
       "test-buffer-writedouble.js",
       "test-buffer-writefloat.js",

filename: tests/node_compat/run_all_test_unmodified.ts
patch: @@ -127,6 +127,9 @@ function getV8Flags(source: string): string[] {
       case "--expose-gc":
         v8Flags.push("--expose-gc");
         break;
+      case "--allow-natives-syntax":
+        v8Flags.push("--allow-natives-syntax");
+        break;
       default:
         break;
     }

filename: tests/node_compat/runner/TODO.md
patch: @@ -1,7 +1,7 @@
 <!-- deno-fmt-ignore-file -->
 # Remaining Node Tests
 
-1177 tests out of 3993 have been ported from Node 23.9.0 (29.48% ported, 71.05% remaining).
+1178 tests out of 3993 have been ported from Node 23.9.0 (29.50% ported, 71.02% 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.
 
@@ -292,7 +292,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co
 - [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-buffer-write-fast.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-buffer-write-fast.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-write-fast.js
patch: @@ -0,0 +1,52 @@
+// 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: --expose-internals --no-warnings --allow-natives-syntax
+'use strict';
+
+const common = require('../common');
+const assert = require('assert');
+
+const { internalBinding } = require('internal/test/binding');
+
+function testFastUtf8Write() {
+  {
+    const buf = Buffer.from('\x80');
+
+    assert.strictEqual(buf[0], 194);
+    assert.strictEqual(buf[1], 128);
+  }
+
+  {
+    const buf = Buffer.alloc(64);
+    const newBuf = buf.subarray(0, buf.write('éñüçßÆ'));
+    assert.deepStrictEqual(newBuf, Buffer.from([195, 169, 195, 177, 195, 188, 195, 167, 195, 159, 195, 134]));
+  }
+
+  {
+    const buf = Buffer.alloc(64);
+    const newBuf = buf.subarray(0, buf.write('¿'));
+    assert.deepStrictEqual(newBuf, Buffer.from([194, 191]));
+  }
+
+  {
+    const buf = Buffer.from(new ArrayBuffer(34), 0, 16);
+    const str = Buffer.from([50, 83, 127, 39, 104, 8, 74, 65, 108, 123, 5, 4, 82, 10, 7, 53]).toString();
+    const newBuf = buf.subarray(0, buf.write(str));
+    assert.deepStrictEqual(newBuf, Buffer.from([ 50, 83, 127, 39, 104, 8, 74, 65, 108, 123, 5, 4, 82, 10, 7, 53]));
+  }
+}
+
+eval('%PrepareFunctionForOptimization(Buffer.prototype.utf8Write)');
+testFastUtf8Write();
+eval('%OptimizeFunctionOnNextCall(Buffer.prototype.utf8Write)');
+testFastUtf8Write();
+
+if (common.isDebug) {
+  const { getV8FastApiCallCount } = internalBinding('debug');
+  assert(getV8FastApiCallCount('buffer.writeString'), 4);
+}