Repository: denoland/deno_core (rust)

Issue:
Public JS Error classes should accept the options argument
Currently public error classes (`BadResource`, `Interrupted`, and `NotCapable`) do not accept the 2nd argument. That is inconvenient when the downstream implementation want to use, for example, `cause` option of Error class (See https://github.com/denoland/deno/pull/27463/files#diff-847a11c353dfb7aeae6e35bc104b83a091ef797bdfc559d22ccfc804a3615000R380 for example)

Pull request description:
feat: support options in error constructors
This PR adds support of the 2nd arguments (`options`) to JS error constructors (`BadResource`, `Interrupted`, and `NotCapable`). closes #1031

By this change, downstream implementations can use `cause` option of `Error` class.

Patch:
diff --git a/core/01_core.js b/core/01_core.js
index 17db6e5..71d9474 100644
--- a/core/01_core.js
+++ b/core/01_core.js
@@ -301,24 +301,24 @@
   // errors in the JS code (eg. "deno_net") so they are provided in "Deno.core"
   // but later reexported on "Deno.errors"
   class BadResource extends Error {
-    constructor(msg) {
-      super(msg);
+    constructor(msg, options) {
+      super(msg, options);
       this.name = "BadResource";
     }
   }
   const BadResourcePrototype = BadResource.prototype;
 
   class Interrupted extends Error {
-    constructor(msg) {
-      super(msg);
+    constructor(msg, options) {
+      super(msg, options);
       this.name = "Interrupted";
     }
   }
   const InterruptedPrototype = Interrupted.prototype;
 
   class NotCapable extends Error {
-    constructor(msg) {
-      super(msg);
+    constructor(msg, options) {
+      super(msg, options);
       this.name = "NotCapable";
     }
   }


Test patch:
diff --git a/testing/unit/error_test.ts b/testing/unit/error_test.ts
index 53d77d2..060d665 100644
--- a/testing/unit/error_test.ts
+++ b/testing/unit/error_test.ts
@@ -10,3 +10,22 @@ test(function testCustomError() {
     assert(e instanceof Deno.core.BadResource);
   }
 });
+
+test(function testJsErrorConstructors() {
+  const error = new Error("message");
+  const badResource = new Deno.core.BadResource("bad resource", {
+    cause: error,
+  });
+  assertEquals(badResource.message, "bad resource");
+  assertEquals(badResource.cause, error);
+
+  const Interrupted = new Deno.core.Interrupted("interrupted", {
+    cause: error,
+  });
+  assertEquals(Interrupted.message, "interrupted");
+  assertEquals(Interrupted.cause, error);
+
+  const notCapable = new Deno.core.NotCapable("not capable", { cause: error });
+  assertEquals(notCapable.message, "not capable");
+  assertEquals(notCapable.cause, error);
+});