mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 14:30:27 +02:00
Add toJSON stack overflow test
This commit is contained in:
parent
2255a0ff11
commit
1eff480aca
35
test/built-ins/JSON/stringify/value-tojson-stack-overflow.js
Normal file
35
test/built-ins/JSON/stringify/value-tojson-stack-overflow.js
Normal 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 toJSON throws an expected error.
|
||||
---*/
|
||||
|
||||
var getStackOverflowError = function() {
|
||||
try {
|
||||
return getStackOverflowError();
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
};
|
||||
|
||||
var StackOverflowError = getStackOverflowError().constructor;
|
||||
|
||||
var obj = {};
|
||||
obj.toJSON = function() {
|
||||
return {key: obj};
|
||||
};
|
||||
|
||||
assert.throws(StackOverflowError, function() {
|
||||
JSON.stringify(obj);
|
||||
});
|
||||
|
||||
var arr = [];
|
||||
arr.toJSON = function() {
|
||||
return [arr];
|
||||
};
|
||||
|
||||
assert.throws(StackOverflowError, function() {
|
||||
JSON.stringify(arr);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user