Add replacer stack overflow test

This commit is contained in:
Alexey Shvayka 2020-03-04 14:25:11 +02:00 committed by Rick Waldron
parent d2b5f63a15
commit 2255a0ff11
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-json.stringify
description: >
Stack overflow due to infinite recursion in replacer throws an expected error.
---*/
var getStackOverflowError = function() {
try {
return getStackOverflowError();
} catch (err) {
return err;
}
};
var StackOverflowError = getStackOverflowError().constructor;
var obj = {};
var objReplacer = function() {
return {key: obj};
};
assert.throws(StackOverflowError, function() {
JSON.stringify(null, objReplacer);
});
var arr = [];
var arrReplacer = function() {
return [arr];
};
assert.throws(StackOverflowError, function() {
JSON.stringify(null, arrReplacer);
});