Add tests for accessing Error.stack on error objects in dictionary mode

This CL adds two mjsunit tests that transition an error object to
dictionary mode before and after Error.stack is formatted and verify
that the custom 'stack' property accessor works as intended.

Bug: v8:8742
Change-Id: I4beb52c75b94533c10fac007f41117ab8915fac8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1649789
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Auto-Submit: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62078}
This commit is contained in:
Simon Zünd 2019-06-11 09:36:18 +02:00 committed by Commit Bot
parent 06930f7420
commit 0381794b8c

View File

@ -73,3 +73,31 @@
assertEquals(error[42], "Who needs stack traces anyway?");
assertEquals(error.stack, undefined); // No getter.
})();
(function TestFormatStackPropertyInDictionaryMode() {
Error.prepareStackTrace = (error, frames) => {
return "<formatted stack trace>";
};
const error = new Error("foo");
error[%MaxSmi()] = 42;
assertTrue(%HasDictionaryElements(error));
// Check it twice.
assertEquals(error.stack, "<formatted stack trace>");
assertEquals(error.stack, "<formatted stack trace>");
})();
(function TestTransitionToDictionaryModeAfterFormatting() {
Error.prepareStackTrace = (error, frames) => {
return "<formatted stack trace>";
};
const error = new Error("foo");
assertFalse(%HasDictionaryElements(error));
assertEquals(error.stack, "<formatted stack trace>");
error[%MaxSmi()] = 42;
assertTrue(%HasDictionaryElements(error));
assertEquals(error.stack, "<formatted stack trace>");
})();