From 54ae6377045fea1dc04eab8ce3caef4dbcff97bc Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc@chromium.org>
Date: Mon, 22 Jan 2024 23:58:03 +0000
Subject: [PATCH] Remove second argument to `ErrnoError`. NFC

There was only one single place (out of hundreds) where this was set
and one single place in `doStat` where it was read.

I removed the `doStat` workaround by updating `mayLookup` instead.
---
 src/library_fs.js                                      |  6 +++---
 src/library_syscall.js                                 | 10 +---------
 test/other/metadce/test_metadce_cxx_ctors1.gzsize      |  2 +-
 test/other/metadce/test_metadce_cxx_ctors1.jssize      |  2 +-
 test/other/metadce/test_metadce_cxx_ctors2.gzsize      |  2 +-
 test/other/metadce/test_metadce_cxx_ctors2.jssize      |  2 +-
 test/other/metadce/test_metadce_cxx_except.gzsize      |  2 +-
 test/other/metadce/test_metadce_cxx_except.jssize      |  2 +-
 test/other/metadce/test_metadce_cxx_except_wasm.gzsize |  2 +-
 test/other/metadce/test_metadce_cxx_except_wasm.jssize |  2 +-
 test/other/metadce/test_metadce_cxx_mangle.gzsize      |  2 +-
 test/other/metadce/test_metadce_cxx_mangle.jssize      |  2 +-
 test/other/metadce/test_metadce_cxx_noexcept.gzsize    |  2 +-
 test/other/metadce/test_metadce_cxx_noexcept.jssize    |  2 +-
 test/other/metadce/test_metadce_files_js_fs.gzsize     |  2 +-
 test/other/metadce/test_metadce_files_js_fs.jssize     |  2 +-
 16 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/src/library_fs.js b/src/library_fs.js
index f14e01e5e0b34..3b9a29b31d86d 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -231,7 +231,7 @@ FS.staticInit();` +
     lookupNode(parent, name) {
       var errCode = FS.mayLookup(parent);
       if (errCode) {
-        throw new FS.ErrnoError(errCode, parent);
+        throw new FS.ErrnoError(errCode);
       }
       var hash = FS.hashName(parent.id, name);
 #if CASE_INSENSITIVE_FS
@@ -316,6 +316,7 @@ FS.staticInit();` +
       return 0;
     },
     mayLookup(dir) {
+      if (!FS.isDir(dir.mode)) return {{{ cDefs.ENOTDIR }}};
       var errCode = FS.nodePermissions(dir, 'x');
       if (errCode) return errCode;
       if (!dir.node_ops.lookup) return {{{ cDefs.EACCES }}};
@@ -1408,7 +1409,7 @@ FS.staticInit();` +
     },
     ensureErrnoError() {
       if (FS.ErrnoError) return;
-      FS.ErrnoError = /** @this{Object} */ function ErrnoError(errno, node) {
+      FS.ErrnoError = /** @this{Object} */ function ErrnoError(errno) {
         // We set the `name` property to be able to identify `FS.ErrnoError`
         // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway.
         // - when using PROXYFS, an error can come from an underlying FS
@@ -1416,7 +1417,6 @@ FS.staticInit();` +
         // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs.
         // we'll use the reliable test `err.name == "ErrnoError"` instead
         this.name = 'ErrnoError';
-        this.node = node;
         this.setErrno = /** @this{Object} */ function(errno) {
           this.errno = errno;
 #if ASSERTIONS
diff --git a/src/library_syscall.js b/src/library_syscall.js
index a147f642fe0e9..318f30caf3f08 100644
--- a/src/library_syscall.js
+++ b/src/library_syscall.js
@@ -42,15 +42,7 @@ var SyscallsLibrary = {
     },
 
     doStat(func, path, buf) {
-      try {
-        var stat = func(path);
-      } catch (e) {
-        if (e && e.node && PATH.normalize(path) !== PATH.normalize(FS.getPath(e.node))) {
-          // an error occurred while trying to look up the path; we should just report ENOTDIR
-          return -{{{ cDefs.ENOTDIR }}};
-        }
-        throw e;
-      }
+      var stat = func(path);
       {{{ makeSetValue('buf', C_STRUCTS.stat.st_dev, 'stat.dev', 'i32') }}};
       {{{ makeSetValue('buf', C_STRUCTS.stat.st_mode, 'stat.mode', 'i32') }}};
       {{{ makeSetValue('buf', C_STRUCTS.stat.st_nlink, 'stat.nlink', SIZE_TYPE) }}};
diff --git a/test/other/metadce/test_metadce_cxx_ctors1.gzsize b/test/other/metadce/test_metadce_cxx_ctors1.gzsize
index c946ea20daca1..87e1a92de80b2 100644
--- a/test/other/metadce/test_metadce_cxx_ctors1.gzsize
+++ b/test/other/metadce/test_metadce_cxx_ctors1.gzsize
@@ -1 +1 @@
-9936
+9932
diff --git a/test/other/metadce/test_metadce_cxx_ctors1.jssize b/test/other/metadce/test_metadce_cxx_ctors1.jssize
index 51e8a38986449..ef8d02c7b4c52 100644
--- a/test/other/metadce/test_metadce_cxx_ctors1.jssize
+++ b/test/other/metadce/test_metadce_cxx_ctors1.jssize
@@ -1 +1 @@
-24683
+24693
diff --git a/test/other/metadce/test_metadce_cxx_ctors2.gzsize b/test/other/metadce/test_metadce_cxx_ctors2.gzsize
index d89ecd30cd70d..e075aaa54a983 100644
--- a/test/other/metadce/test_metadce_cxx_ctors2.gzsize
+++ b/test/other/metadce/test_metadce_cxx_ctors2.gzsize
@@ -1 +1 @@
-9921
+9915
diff --git a/test/other/metadce/test_metadce_cxx_ctors2.jssize b/test/other/metadce/test_metadce_cxx_ctors2.jssize
index e9737da1ce9cc..b32c1ee20e951 100644
--- a/test/other/metadce/test_metadce_cxx_ctors2.jssize
+++ b/test/other/metadce/test_metadce_cxx_ctors2.jssize
@@ -1 +1 @@
-24651
+24661
diff --git a/test/other/metadce/test_metadce_cxx_except.gzsize b/test/other/metadce/test_metadce_cxx_except.gzsize
index 1d58657569060..deca973733bad 100644
--- a/test/other/metadce/test_metadce_cxx_except.gzsize
+++ b/test/other/metadce/test_metadce_cxx_except.gzsize
@@ -1 +1 @@
-11015
+11010
diff --git a/test/other/metadce/test_metadce_cxx_except.jssize b/test/other/metadce/test_metadce_cxx_except.jssize
index 6a6dc7c715c97..d7bf552030bbc 100644
--- a/test/other/metadce/test_metadce_cxx_except.jssize
+++ b/test/other/metadce/test_metadce_cxx_except.jssize
@@ -1 +1 @@
-28573
+28583
diff --git a/test/other/metadce/test_metadce_cxx_except_wasm.gzsize b/test/other/metadce/test_metadce_cxx_except_wasm.gzsize
index 3a31f4b39a85b..55223f1554dc1 100644
--- a/test/other/metadce/test_metadce_cxx_except_wasm.gzsize
+++ b/test/other/metadce/test_metadce_cxx_except_wasm.gzsize
@@ -1 +1 @@
-9903
+9899
diff --git a/test/other/metadce/test_metadce_cxx_except_wasm.jssize b/test/other/metadce/test_metadce_cxx_except_wasm.jssize
index 7ad84412db248..b85dcbb09ed54 100644
--- a/test/other/metadce/test_metadce_cxx_except_wasm.jssize
+++ b/test/other/metadce/test_metadce_cxx_except_wasm.jssize
@@ -1 +1 @@
-24576
+24586
diff --git a/test/other/metadce/test_metadce_cxx_mangle.gzsize b/test/other/metadce/test_metadce_cxx_mangle.gzsize
index 853337070d62f..d817e31f8830c 100644
--- a/test/other/metadce/test_metadce_cxx_mangle.gzsize
+++ b/test/other/metadce/test_metadce_cxx_mangle.gzsize
@@ -1 +1 @@
-11021
+11016
diff --git a/test/other/metadce/test_metadce_cxx_mangle.jssize b/test/other/metadce/test_metadce_cxx_mangle.jssize
index 6a6dc7c715c97..d7bf552030bbc 100644
--- a/test/other/metadce/test_metadce_cxx_mangle.jssize
+++ b/test/other/metadce/test_metadce_cxx_mangle.jssize
@@ -1 +1 @@
-28573
+28583
diff --git a/test/other/metadce/test_metadce_cxx_noexcept.gzsize b/test/other/metadce/test_metadce_cxx_noexcept.gzsize
index c946ea20daca1..87e1a92de80b2 100644
--- a/test/other/metadce/test_metadce_cxx_noexcept.gzsize
+++ b/test/other/metadce/test_metadce_cxx_noexcept.gzsize
@@ -1 +1 @@
-9936
+9932
diff --git a/test/other/metadce/test_metadce_cxx_noexcept.jssize b/test/other/metadce/test_metadce_cxx_noexcept.jssize
index 51e8a38986449..ef8d02c7b4c52 100644
--- a/test/other/metadce/test_metadce_cxx_noexcept.jssize
+++ b/test/other/metadce/test_metadce_cxx_noexcept.jssize
@@ -1 +1 @@
-24683
+24693
diff --git a/test/other/metadce/test_metadce_files_js_fs.gzsize b/test/other/metadce/test_metadce_files_js_fs.gzsize
index 3e457d7772948..fc1347e76e0df 100644
--- a/test/other/metadce/test_metadce_files_js_fs.gzsize
+++ b/test/other/metadce/test_metadce_files_js_fs.gzsize
@@ -1 +1 @@
-7874
+7871
diff --git a/test/other/metadce/test_metadce_files_js_fs.jssize b/test/other/metadce/test_metadce_files_js_fs.jssize
index 0677ec7a1898e..b3945f1ded561 100644
--- a/test/other/metadce/test_metadce_files_js_fs.jssize
+++ b/test/other/metadce/test_metadce_files_js_fs.jssize
@@ -1 +1 @@
-19705
+19715
