mirror of
https://github.com/tc39/test262.git
synced 2025-07-21 13:04:39 +02:00
Remove unused 'clone_object_check'
This commit is contained in:
parent
965e505fb8
commit
e8b9a6a1d9
@ -237,113 +237,3 @@ allow_unused: True
|
|||||||
}
|
}
|
||||||
|
|
||||||
})(this);
|
})(this);
|
||||||
|
|
||||||
|
|
||||||
(function(global) {
|
|
||||||
|
|
||||||
// The Worker constructor can take a relative URL, but different test runners
|
|
||||||
// run in different enough environments that it doesn't all just automatically
|
|
||||||
// work. For the shell, we use just a filename; for the browser, see browser.js.
|
|
||||||
var workerDir = '';
|
|
||||||
|
|
||||||
// Assert that cloning b does the right thing as far as we can tell.
|
|
||||||
// Caveat: getters in b must produce the same value each time they're
|
|
||||||
// called. We may call them several times.
|
|
||||||
//
|
|
||||||
// If desc is provided, then the very first thing we do to b is clone it.
|
|
||||||
// (The self-modifying object test counts on this.)
|
|
||||||
//
|
|
||||||
function clone_object_check(b, desc) {
|
|
||||||
function classOf(obj) {
|
|
||||||
return Object.prototype.toString.call(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ownProperties(obj) {
|
|
||||||
return Object.getOwnPropertyNames(obj).
|
|
||||||
map(function (p) { return [p, Object.getOwnPropertyDescriptor(obj, p)]; });
|
|
||||||
}
|
|
||||||
|
|
||||||
function isArrayLength(obj, pair) {
|
|
||||||
return Array.isArray(obj) && pair[0] == "length";
|
|
||||||
}
|
|
||||||
|
|
||||||
function isCloneable(obj, pair) {
|
|
||||||
return isArrayLength(obj, pair) || (typeof pair[0] === 'string' && pair[1].enumerable);
|
|
||||||
}
|
|
||||||
|
|
||||||
function notIndex(p) {
|
|
||||||
var u = p >>> 0;
|
|
||||||
return !("" + u == p && u != 0xffffffff);
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertIsCloneOf(a, b, path) {
|
|
||||||
assertEq(a === b, false);
|
|
||||||
|
|
||||||
var ca = classOf(a);
|
|
||||||
assertEq(ca, classOf(b), path);
|
|
||||||
|
|
||||||
assertEq(Object.getPrototypeOf(a),
|
|
||||||
ca == "[object Object]" ? Object.prototype : Array.prototype,
|
|
||||||
path);
|
|
||||||
|
|
||||||
// 'b', the original object, may have non-enumerable or XMLName
|
|
||||||
// properties; ignore them (except .length, if it's an Array).
|
|
||||||
// 'a', the clone, should not have any non-enumerable properties
|
|
||||||
// (except .length, if it's an Array) or XMLName properties.
|
|
||||||
var pb = ownProperties(b).filter(function(element) {
|
|
||||||
return isCloneable(b, element);
|
|
||||||
});
|
|
||||||
var pa = ownProperties(a);
|
|
||||||
for (var i = 0; i < pa.length; i++) {
|
|
||||||
assertEq(typeof pa[i][0], "string", "clone should not have E4X properties " + path);
|
|
||||||
if (!isCloneable(a, pa[i])) {
|
|
||||||
throw new Error("non-cloneable clone property " + pa[i][0] + " " + path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that, apart from properties whose names are array indexes,
|
|
||||||
// the enumerable properties appear in the same order.
|
|
||||||
var aNames = pa.map(function (pair) { return pair[1]; }).filter(notIndex);
|
|
||||||
var bNames = pa.map(function (pair) { return pair[1]; }).filter(notIndex);
|
|
||||||
assertEq(aNames.join(","), bNames.join(","), path);
|
|
||||||
|
|
||||||
// Check that the lists are the same when including array indexes.
|
|
||||||
function byName(a, b) { a = a[0]; b = b[0]; return a < b ? -1 : a === b ? 0 : 1; }
|
|
||||||
pa.sort(byName);
|
|
||||||
pb.sort(byName);
|
|
||||||
assertEq(pa.length, pb.length, "should see the same number of properties " + path);
|
|
||||||
for (var i = 0; i < pa.length; i++) {
|
|
||||||
var aName = pa[i][0];
|
|
||||||
var bName = pb[i][0];
|
|
||||||
assertEq(aName, bName, path);
|
|
||||||
|
|
||||||
var path2 = path + "." + aName;
|
|
||||||
var da = pa[i][1];
|
|
||||||
var db = pb[i][1];
|
|
||||||
if (!isArrayLength(a, pa[i])) {
|
|
||||||
assertEq(da.configurable, true, path2);
|
|
||||||
}
|
|
||||||
assertEq(da.writable, true, path2);
|
|
||||||
assertEq("value" in da, true, path2);
|
|
||||||
var va = da.value;
|
|
||||||
var vb = b[pb[i][0]];
|
|
||||||
if (typeof va === "object" && va !== null)
|
|
||||||
queue.push([va, vb, path2]);
|
|
||||||
else
|
|
||||||
assertEq(va, vb, path2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var banner = "while testing clone of " + (desc || JSON.stringify(b));
|
|
||||||
var a = deserialize(serialize(b));
|
|
||||||
var queue = [[a, b, banner]];
|
|
||||||
while (queue.length) {
|
|
||||||
var triple = queue.shift();
|
|
||||||
assertIsCloneOf(triple[0], triple[1], triple[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return a; // for further testing
|
|
||||||
}
|
|
||||||
global.clone_object_check = clone_object_check;
|
|
||||||
|
|
||||||
})(this);
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user