mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.3 KiB
75 lines
1.3 KiB
12 years ago
|
/*===
|
||
|
TypeError
|
||
|
TypeError
|
||
|
TypeError
|
||
|
===*/
|
||
|
|
||
|
/* TypeError is required for cyclic structures. */
|
||
|
|
||
12 years ago
|
function testCycle1() {
|
||
|
var obj = { foo: 1 };
|
||
|
obj.cycle = obj;
|
||
|
print(JSON.stringify(obj));
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
function testCycle2() {
|
||
|
var obj1 = { foo: 1 };
|
||
|
var obj2 = { bar: 2 };
|
||
|
obj1.cycle = obj2;
|
||
|
obj2.cycle = obj1;
|
||
|
print(JSON.stringify(obj1));
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
function testCycle3() {
|
||
|
var obj1 = { foo: 1 };
|
||
|
var obj2 = { bar: 2 };
|
||
|
var obj3 = { quux: 3 };
|
||
|
obj1.cycle = obj2;
|
||
|
obj2.cycle = obj3;
|
||
|
obj3.cycle = obj1;
|
||
|
print(JSON.stringify(obj1));
|
||
|
}
|
||
12 years ago
|
|
||
|
try {
|
||
12 years ago
|
testCycle1();
|
||
|
} catch (e) {
|
||
|
print(e.name);
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
testCycle2();
|
||
12 years ago
|
} catch (e) {
|
||
|
print(e.name);
|
||
|
}
|
||
|
|
||
|
try {
|
||
12 years ago
|
testCycle3();
|
||
12 years ago
|
} catch (e) {
|
||
|
print(e.name);
|
||
|
}
|
||
|
|
||
12 years ago
|
/*===
|
||
|
{"foo":1,"bar":2,"ref1":{"quux":3,"baz":4,"ref1":{"quuux":5},"ref2":{"quuux":5}},"ref2":{"quux":3,"baz":4,"ref1":{"quuux":5},"ref2":{"quuux":5}}}
|
||
|
===*/
|
||
|
|
||
|
/* The following visits the same object multiple times, but not in a cycle.
|
||
|
* This test ensures that any loop stack or hash map is unwound correctly.
|
||
|
*/
|
||
|
|
||
|
function testNoCycle1() {
|
||
|
var obj1 = { foo: 1, bar: 2 };
|
||
|
var obj2 = { quux: 3, baz: 4 };
|
||
|
var obj3 = { quuux: 5 };
|
||
|
obj1.ref1 = obj2;
|
||
|
obj1.ref2 = obj2;
|
||
|
obj2.ref1 = obj3;
|
||
|
obj2.ref2 = obj3;
|
||
|
print(JSON.stringify(obj1));
|
||
|
}
|
||
|
|
||
12 years ago
|
try {
|
||
12 years ago
|
testNoCycle1();
|
||
12 years ago
|
} catch (e) {
|
||
|
print(e.name);
|
||
|
}
|