зеркало из https://github.com/mozilla/gecko-dev.git
Bug 901351 - Tests. r=jorendorff
--HG-- extra : rebase_source : 6c35e645511632868953dec45fa0a3b86e0f9f34
This commit is contained in:
Родитель
cdc3a731cf
Коммит
95b32dc109
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
* Contributor:
|
||||
* Jeff Walden <jwalden+code@mit.edu>
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 901351;
|
||||
var summary = "Behavior when the JSON.parse reviver mutates the holder array";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
if (typeof newGlobal !== "function")
|
||||
{
|
||||
var newGlobal = function()
|
||||
{
|
||||
return { evaluate: eval };
|
||||
};
|
||||
}
|
||||
|
||||
var proxyObj = null;
|
||||
|
||||
var arr = JSON.parse('[0, 1]', function(prop, v) {
|
||||
if (prop === "0")
|
||||
{
|
||||
proxyObj = newGlobal().evaluate("({ c: 17, d: 42 })");
|
||||
this[1] = proxyObj;
|
||||
}
|
||||
return v;
|
||||
});
|
||||
|
||||
assertEq(arr[0], 0);
|
||||
assertEq(arr[1], proxyObj);
|
||||
assertEq(arr[1].c, 17);
|
||||
assertEq(arr[1].d, 42);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
||||
print("Tests complete");
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
* Contributor:
|
||||
* Jeff Walden <jwalden+code@mit.edu>
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 901380;
|
||||
var summary = "Behavior when JSON.parse walks over a non-native object";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
var typedArray = null;
|
||||
|
||||
var observedTypedArrayElementCount = 0;
|
||||
|
||||
var arr = JSON.parse('[0, 1]', function(prop, v) {
|
||||
if (prop === "0" && Array.isArray(this)) // exclude typedArray[0]
|
||||
{
|
||||
typedArray = new Int8Array(1);
|
||||
this[1] = typedArray;
|
||||
}
|
||||
if (this instanceof Int8Array)
|
||||
{
|
||||
assertEq(prop, "0");
|
||||
observedTypedArrayElementCount++;
|
||||
}
|
||||
return v;
|
||||
});
|
||||
|
||||
assertEq(arr[0], 0);
|
||||
assertEq(arr[1], typedArray);
|
||||
|
||||
assertEq(observedTypedArrayElementCount, 1);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
||||
print("Tests complete");
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
* Contributor:
|
||||
* Jeff Walden <jwalden+code@mit.edu>
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 901351;
|
||||
var summary = "Behavior when the JSON.parse reviver mutates the holder array";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
var proxyObj = null;
|
||||
|
||||
var arr = JSON.parse('[0, 1]', function(prop, v) {
|
||||
if (prop === "0")
|
||||
{
|
||||
proxyObj = new Proxy({ c: 17, d: 42 }, {});
|
||||
this[1] = proxyObj;
|
||||
}
|
||||
return v;
|
||||
});
|
||||
|
||||
assertEq(arr[0], 0);
|
||||
assertEq(arr[1], proxyObj);
|
||||
assertEq(arr[1].c, 17);
|
||||
assertEq(arr[1].d, 42);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
||||
print("Tests complete");
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
* Contributor:
|
||||
* Jeff Walden <jwalden+code@mit.edu>
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 901351;
|
||||
var summary = "Behavior when the JSON.parse reviver mutates the holder object";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
if (typeof newGlobal !== "function")
|
||||
{
|
||||
var newGlobal = function()
|
||||
{
|
||||
return { evaluate: eval };
|
||||
};
|
||||
}
|
||||
|
||||
// A little trickiness to account for the undefined-ness of property
|
||||
// enumeration order.
|
||||
var first = "unset";
|
||||
|
||||
var proxyObj = null;
|
||||
|
||||
var obj = JSON.parse('{ "a": 0, "b": 1 }', function(prop, v) {
|
||||
if (first === "unset")
|
||||
{
|
||||
first = prop;
|
||||
var second = (prop === "a") ? "b" : "a";
|
||||
|
||||
proxyObj = newGlobal().evaluate("({ c: 42, d: 17 })");
|
||||
Object.defineProperty(this, second, { value: proxyObj });
|
||||
}
|
||||
return v;
|
||||
});
|
||||
|
||||
if (first === "a")
|
||||
{
|
||||
assertEq(obj.a, 0);
|
||||
assertEq(obj.b, proxyObj);
|
||||
assertEq(obj.b.c, 42);
|
||||
assertEq(obj.b.d, 17);
|
||||
}
|
||||
else
|
||||
{
|
||||
assertEq(obj.a, proxyObj);
|
||||
assertEq(obj.a.c, 42);
|
||||
assertEq(obj.a.d, 17);
|
||||
assertEq(obj.b, 1);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
||||
print("Tests complete");
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
* Contributor:
|
||||
* Jeff Walden <jwalden+code@mit.edu>
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 901380;
|
||||
var summary = "Behavior when JSON.parse walks over a non-native object";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
// A little trickiness to account for the undefined-ness of property
|
||||
// enumeration order.
|
||||
var first = "unset";
|
||||
|
||||
var observedTypedArrayElementCount = 0;
|
||||
|
||||
var typedArray = null;
|
||||
|
||||
var obj = JSON.parse('{ "a": 0, "b": 1 }', function(prop, v) {
|
||||
if (first === "unset")
|
||||
{
|
||||
first = prop;
|
||||
var second = (prop === "a") ? "b" : "a";
|
||||
typedArray = new Int8Array(1);
|
||||
Object.defineProperty(this, second, { value: typedArray });
|
||||
}
|
||||
if (this instanceof Int8Array)
|
||||
{
|
||||
assertEq(prop, "0");
|
||||
observedTypedArrayElementCount++;
|
||||
}
|
||||
return v;
|
||||
});
|
||||
|
||||
if (first === "a")
|
||||
{
|
||||
assertEq(obj.a, 0);
|
||||
assertEq(obj.b, typedArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
assertEq(obj.a, typedArray);
|
||||
assertEq(obj.b, 1);
|
||||
}
|
||||
|
||||
assertEq(observedTypedArrayElementCount, 1);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
||||
print("Tests complete");
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/licenses/publicdomain/
|
||||
* Contributor:
|
||||
* Jeff Walden <jwalden+code@mit.edu>
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 901351;
|
||||
var summary = "Behavior when the JSON.parse reviver mutates the holder object";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
// A little trickiness to account for the undefined-ness of property
|
||||
// enumeration order.
|
||||
var first = "unset";
|
||||
|
||||
var proxyObj = null;
|
||||
|
||||
var obj = JSON.parse('{ "a": 0, "b": 1 }', function(prop, v) {
|
||||
if (first === "unset")
|
||||
{
|
||||
first = prop;
|
||||
var second = (prop === "a") ? "b" : "a";
|
||||
|
||||
proxyObj = new Proxy({ c: 42, d: 17 }, {});
|
||||
Object.defineProperty(this, second, { value: proxyObj });
|
||||
}
|
||||
return v;
|
||||
});
|
||||
|
||||
if (first === "a")
|
||||
{
|
||||
assertEq(obj.a, 0);
|
||||
assertEq(obj.b, proxyObj);
|
||||
assertEq(obj.b.c, 42);
|
||||
assertEq(obj.b.d, 17);
|
||||
}
|
||||
else
|
||||
{
|
||||
assertEq(obj.a, proxyObj);
|
||||
assertEq(obj.a.c, 42);
|
||||
assertEq(obj.a.d, 17);
|
||||
assertEq(obj.b, 1);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
||||
print("Tests complete");
|
Загрузка…
Ссылка в новой задаче