Skip to content

Commit

Permalink
fix a typo in the structuredClone feature detection, close #1106
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jul 16, 2022
1 parent bba906e commit 99da3ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions 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)
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/modules/web.structured-clone.js
Expand Up @@ -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);
});
};

Expand Down
19 changes: 14 additions & 5 deletions tests/compat/tests.js
Expand Up @@ -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,
Expand Down

0 comments on commit 99da3ba

Please sign in to comment.