From 99da3ba36ff652d5abbad394441883fe00fc8eee Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Sat, 16 Jul 2022 17:12:42 +0700 Subject: [PATCH] fix a typo in the `structuredClone` feature detection, close #1106 --- CHANGELOG.md | 1 + .../core-js/modules/web.structured-clone.js | 2 +- tests/compat/tests.js | 19 ++++++++++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e09b5897b793..2e8455be8598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Changelog ##### Unreleased +- Fixed a typo in the `structuredClone` feature detection, [#1106](https://github.com/zloirock/core-js/issues/1106) - Added Opera Android 70 compat data mapping ##### [3.23.4 - 2022.07.10](https://github.com/zloirock/core-js/releases/tag/v3.23.4) diff --git a/packages/core-js/modules/web.structured-clone.js b/packages/core-js/modules/web.structured-clone.js index 209039dc77e6..306246cfc048 100644 --- a/packages/core-js/modules/web.structured-clone.js +++ b/packages/core-js/modules/web.structured-clone.js @@ -69,7 +69,7 @@ var checkErrorsCloning = function (structuredCloneImplementation, $Error) { return !fails(function () { var error = new $Error(); var test = structuredCloneImplementation({ a: error, b: error }); - return !(test && test.a === test.b && test.a instanceof $Error && test.stack === error.stack); + return !(test && test.a === test.b && test.a instanceof $Error && test.a.stack === error.stack); }); }; diff --git a/tests/compat/tests.js b/tests/compat/tests.js index 1b50487a8553..50a12ac20ec7 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -1858,11 +1858,20 @@ GLOBAL.tests = { 'web.set-interval': TIMERS, 'web.set-timeout': TIMERS, 'web.structured-clone': function () { - var error = new Error(); - var test = structuredClone({ a: error, b: error }); - if (!(test && test.a === test.b && test.a instanceof Error && test.stack === error.stack)) return false; - test = structuredClone(new AggregateError([1], 'a', { cause: 3 })); - return test.name == 'AggregateError' && test.errors[0] == 1 && test.message == 'a' && test.cause == 3; + function checkErrorsCloning(structuredCloneImplementation, $Error) { + var error = new $Error(); + var test = structuredCloneImplementation({ a: error, b: error }); + return test && test.a === test.b && test.a instanceof $Error && test.a.stack === error.stack; + } + + function checkNewErrorsCloningSemantic(structuredCloneImplementation) { + var test = structuredCloneImplementation(new AggregateError([1], 'message', { cause: 3 })); + return test.name == 'AggregateError' && test.errors[0] == 1 && test.message == 'message' && test.cause == 3; + } + + return checkErrorsCloning(structuredClone, Error) + && checkErrorsCloning(structuredClone, DOMException) + && checkNewErrorsCloningSemantic(structuredClone); }, // TODO: Remove this module from `core-js@4` since it's split to submodules 'web.timers': TIMERS,