Skip to content

Commit 9b746f0

Browse files
committed
add zip loader
1 parent 2a2530b commit 9b746f0

File tree

5 files changed

+171
-65
lines changed

5 files changed

+171
-65
lines changed

files.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html>
22
<head><meta charset="utf-8">
33
<title>Test262 Web Runner</title>
4+
<script src="jszip.min.js"></script>
45
<script src="files.js"></script>
56
<script src="main.js"></script>
67
<style>
@@ -14,6 +15,7 @@
1415
</style>
1516
</head>
1617
<body>
18+
<input type="file" accept=".zip" id="zipload" style="display: none;">
1719
Placeholder<br>
1820
<div id="error"></div>
1921
<div id="tree"></div>

jszip.min.js

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

list-files.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

main.js

Lines changed: 154 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -381,56 +381,64 @@ function runTest262Test(src, pass, fail) {
381381

382382

383383
window.addEventListener('load', function() {
384-
(function renderTree(tree, container, path, hide) {
385-
var list = container.appendChild(document.createElement('ul'));
386-
tree.forEach(function(item) {
387-
var li = document.createElement('li');
388-
item.element = li; // mutating cached data, woo
389-
if (item.type === 'dir') {
390-
li.innerText = '[+] ' + item.name;
391-
var status = li.appendChild(document.createElement('span'));
392-
status.style.paddingLeft = '5px';
393-
renderTree(item.files, li, path + item.name + '/', true);
394-
li.addEventListener('click', function(e) {
395-
if (e.target !== li) return;
396-
e.stopPropagation();
397-
var subtree = li.querySelector('ul');
398-
if (subtree.style.display === 'none') {
399-
subtree.style.display = '';
400-
} else {
401-
subtree.style.display = 'none';
402-
}
403-
});
404-
} else {
405-
li.innerText = item.name;
406-
li.path = path + item.name; // todo find a better way of doing this
407-
var status = li.appendChild(document.createElement('span'));
408-
status.style.paddingLeft = '5px';
409-
li.addEventListener('click', function(e) {
410-
if (e.target !== li) return;
411-
e.stopPropagation();
412-
load(path + item.name, function(task, data) {
413-
runTest262Test(data, function() {
414-
status.innerText = 'Pass!';
415-
status.className = 'pass';
416-
}, function(msg) {
417-
status.innerText = msg;
418-
status.className = 'fail';
419-
});
420-
complete(task);
421-
}, function(task) {
422-
status.innerText = 'Load failed.';
423-
status.className = 'fail';
424-
complete(task);
425-
});
426-
});
427-
}
428-
list.appendChild(li);
429-
});
430-
if (hide) list.style.display = 'none';
431-
})(files, document.getElementById('tree'), './test262/test/', false);
384+
// (function renderTree(tree, container, path, hide) {
385+
// var list = container.appendChild(document.createElement('ul'));
386+
// tree.forEach(function(item) {
387+
// var li = document.createElement('li');
388+
// item.element = li; // mutating cached data, woo
389+
// if (item.type === 'dir') {
390+
// li.innerText = '[+] ' + item.name;
391+
// var status = li.appendChild(document.createElement('span'));
392+
// status.style.paddingLeft = '5px';
393+
// renderTree(item.files, li, path + item.name + '/', true);
394+
// li.addEventListener('click', function(e) {
395+
// if (e.target !== li) return;
396+
// e.stopPropagation();
397+
// var subtree = li.querySelector('ul');
398+
// if (subtree.style.display === 'none') {
399+
// subtree.style.display = '';
400+
// } else {
401+
// subtree.style.display = 'none';
402+
// }
403+
// });
404+
// } else {
405+
// li.innerText = item.name;
406+
// li.path = path + item.name; // todo find a better way of doing this
407+
// var status = li.appendChild(document.createElement('span'));
408+
// status.style.paddingLeft = '5px';
409+
// li.addEventListener('click', function(e) {
410+
// if (e.target !== li) return;
411+
// e.stopPropagation();
412+
// load(path + item.name, function(task, data) {
413+
// runTest262Test(data, function() {
414+
// status.innerText = 'Pass!';
415+
// status.className = 'pass';
416+
// }, function(msg) {
417+
// status.innerText = msg;
418+
// status.className = 'fail';
419+
// });
420+
// complete(task);
421+
// }, function(task) {
422+
// status.innerText = 'Load failed.';
423+
// status.className = 'fail';
424+
// complete(task);
425+
// });
426+
// });
427+
// }
428+
// list.appendChild(li);
429+
// });
430+
// if (hide) list.style.display = 'none';
431+
// })(files, document.getElementById('tree'), './test262/test/', false);
432432

433433
//runTest262Test('1 1');
434+
435+
436+
var ele = document.getElementById('zipload');
437+
ele.addEventListener('change', function(){
438+
if (!ele.files[0]) return;
439+
loadZip(ele.files[0]);
440+
});
441+
434442
});
435443

436444

@@ -532,3 +540,101 @@ function runTree(root) {
532540
// loadSubtree(path, container, handleSubtree);
533541
// }
534542
// // recur('test/annexB/built-ins', document.getElementById('tree'));
543+
544+
545+
// document.getElementById('zipload').click();
546+
547+
548+
function getStructure(zip, predicate) {
549+
var structure = Object.create(null);
550+
structure.type = 'dir';
551+
structure.name = '.';
552+
structure.files = Object.create(null);
553+
zip.forEach(function(path, file) {
554+
if (!predicate(path)) return;
555+
path = path.split('/');
556+
if (path[path.length - 1] === '') return; // i.e. directory
557+
var dir = structure;
558+
for (var i = 0; i < path.length - 1; ++i) {
559+
if (!Object.prototype.hasOwnProperty.call(dir.files, path[i])) {
560+
dir.files[path[i]] = Object.create(null);
561+
dir.files[path[i]].type = 'dir';
562+
dir.files[path[i]].name = path[i];
563+
dir.files[path[i]].files = Object.create(null);
564+
}
565+
dir = dir.files[path[i]];
566+
}
567+
var obj = Object.create(null);
568+
obj.type = 'file';
569+
obj.name = path[path.length - 1];
570+
obj.file = file;
571+
dir.files[path[path.length - 1]] = obj;
572+
});
573+
return structure;
574+
}
575+
576+
function renderTree(tree, container, path, hide) {
577+
var list = container.appendChild(document.createElement('ul'));
578+
Object.keys(tree).sort().forEach(function(key) {
579+
var item = tree[key];
580+
var li = document.createElement('li');
581+
item.element = li; // mutating cached data, woo
582+
if (item.type === 'dir') {
583+
li.innerText = '[+] ' + item.name;
584+
var status = li.appendChild(document.createElement('span'));
585+
status.style.paddingLeft = '5px';
586+
renderTree(item.files, li, path + item.name + '/', true);
587+
li.addEventListener('click', function(e) {
588+
if (e.target !== li) return;
589+
e.stopPropagation();
590+
var subtree = li.querySelector('ul');
591+
if (subtree.style.display === 'none') {
592+
subtree.style.display = '';
593+
} else {
594+
subtree.style.display = 'none';
595+
}
596+
});
597+
} else {
598+
li.innerText = item.name;
599+
li.path = path + item.name; // todo find a better way of doing this
600+
var status = li.appendChild(document.createElement('span'));
601+
status.style.paddingLeft = '5px';
602+
li.addEventListener('click', function(e) {
603+
if (e.target !== li) return;
604+
e.stopPropagation();
605+
load(path + item.name, function(task, data) {
606+
runTest262Test(data, function() {
607+
status.innerText = 'Pass!';
608+
status.className = 'pass';
609+
}, function(msg) {
610+
status.innerText = msg;
611+
status.className = 'fail';
612+
});
613+
complete(task);
614+
}, function(task) {
615+
status.innerText = 'Load failed.';
616+
status.className = 'fail';
617+
complete(task);
618+
});
619+
});
620+
}
621+
list.appendChild(li);
622+
});
623+
if (hide) list.style.display = 'none';
624+
}
625+
626+
// (files, document.getElementById('tree'), './test262/test/', false);
627+
628+
function loadZip(z) {
629+
JSZip.loadAsync(z).then(z => {
630+
var tree = getStructure(z, function(path) { return path.match(/\.js$/) && !path.match(/_FIXTURE\.js/); });
631+
var keys = Object.keys(tree.files);
632+
if (keys.length === 1) tree = tree.files[keys[0]];
633+
if (!tree.files.test || !tree.files.test.type === 'dir' || !tree.files.harness || !tree.files.harness.files['assert.js'] || !tree.files.harness.files['sta.js']) {
634+
throw "Doesn't look like a test262 bundle to me!";
635+
}
636+
renderTree(tree.files.test.files, document.getElementById('tree'), './test262/test/', false);
637+
});
638+
}
639+
640+

0 commit comments

Comments
 (0)