From bf888d942a8a0f70094f9d8cd90155fe19bc65ca Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Fri, 13 Dec 2024 21:22:29 +0900 Subject: [PATCH] feat(ext/web): add `[[ErrorData]]` slot to `DOMException` (#27342) --- ext/web/01_dom_exception.js | 15 +++++++++------ tests/unit_node/util_test.ts | 2 +- tests/wpt/runner/expectation.json | 15 +++++---------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js index 38e4d088e50dfc..db2996e0c674d1 100644 --- a/ext/web/01_dom_exception.js +++ b/ext/web/01_dom_exception.js @@ -9,14 +9,15 @@ import { primordials } from "ext:core/mod.js"; const { + Error, ErrorPrototype, - ErrorCaptureStackTrace, ObjectDefineProperty, ObjectCreate, ObjectEntries, ObjectHasOwn, ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, + ReflectConstruct, Symbol, SymbolFor, } = primordials; @@ -107,12 +108,14 @@ class DOMException { ); const code = nameToCodeMapping[name] ?? 0; - this[_message] = message; - this[_name] = name; - this[_code] = code; - this[webidl.brand] = webidl.brand; + // execute Error constructor to have stack property and [[ErrorData]] internal slot + const error = ReflectConstruct(Error, [], new.target); + error[_message] = message; + error[_name] = name; + error[_code] = code; + error[webidl.brand] = webidl.brand; - ErrorCaptureStackTrace(this, DOMException); + return error; } get message() { diff --git a/tests/unit_node/util_test.ts b/tests/unit_node/util_test.ts index 6267018b126f7c..af174b0f4d08fc 100644 --- a/tests/unit_node/util_test.ts +++ b/tests/unit_node/util_test.ts @@ -224,7 +224,7 @@ Deno.test({ fn() { assert(util.types.isNativeError(new Error())); assert(util.types.isNativeError(new TypeError())); - assert(!util.types.isNativeError(new DOMException())); + assert(util.types.isNativeError(new DOMException())); }, }); diff --git a/tests/wpt/runner/expectation.json b/tests/wpt/runner/expectation.json index 5776fdb486b212..6025ce42a46d81 100644 --- a/tests/wpt/runner/expectation.json +++ b/tests/wpt/runner/expectation.json @@ -3594,16 +3594,13 @@ "DOMException-constructor-behavior.any.html": true, "DOMException-constructor-behavior.any.worker.html": true, "DOMException-custom-bindings.any.html": true, - "DOMException-custom-bindings.any.worker.html": true + "DOMException-custom-bindings.any.worker.html": true, + "exceptions.html": false }, "class-string-interface.any.html": true, "class-string-interface.any.worker.html": true, - "class-string-iterator-prototype-object.any.html": [ - "Object.prototype.toString applied after deleting @@toStringTag" - ], - "class-string-iterator-prototype-object.any.worker.html": [ - "Object.prototype.toString applied after deleting @@toStringTag" - ], + "class-string-iterator-prototype-object.any.html": true, + "class-string-iterator-prototype-object.any.worker.html": true, "class-string-named-properties-object.window.html": false, "global-immutable-prototype.any.html": [ "Setting to a different prototype" @@ -9754,7 +9751,6 @@ "structured-cloning-error-stack-optional.sub.window.html": [ "page-created Error (cross-site iframe)", "page-created Error (same-origin iframe)", - "page-created DOMException (structuredClone())", "page-created DOMException (cross-site iframe)", "page-created DOMException (same-origin iframe)", "JS-engine-created TypeError (cross-site iframe)", @@ -9762,8 +9758,7 @@ "web API-created TypeError (cross-site iframe)", "web API-created TypeError (same-origin iframe)", "web API-created DOMException (cross-site iframe)", - "web API-created DOMException (same-origin iframe)", - "page-created DOMException (worker)" + "web API-created DOMException (same-origin iframe)" ], "transfer-errors.window.html": false, "window-postmessage.window.html": false