Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: ports/thttpd/nacl.js

Issue 1415743013: Run jshint over all JavaScript files (Closed) Base URL: https://chromium.googlesource.com/external/naclports.git@repo_conf
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ports/snes9x/snes9x.js ('k') | ports/vim/vim.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 var uploadURL = 'http://localhost:8006/tmp/' 7 /* jshint evil: true */
8 /* globals $, FileError */
9
10 'use strict';
11
12 var uploadURL = 'http://localhost:8006/tmp/';
8 13
9 function moduleDidLoad() { 14 function moduleDidLoad() {
10 $("#status_field").text("SUCCESS") 15 $("#status_field").text("SUCCESS");
11 } 16 }
12 17
13 function is_array(input) { 18 function is_array(input) {
14 return typeof(input) == 'object' && (input instanceof Array); 19 return typeof(input) == 'object' && (input instanceof Array);
15 } 20 }
16 21
17 function escapeHTML(szHTML) { 22 function escapeHTML(szHTML) {
18 return szHTML.split("&").join("&amp;").split( "<").join("&lt;").split(">") 23 return szHTML.split("&").join("&amp;").split( "<").join("&lt;").split(">")
19 .join("&gt;").split("\n").join("<br />").replace(" ", "&nbsp;") 24 .join("&gt;").split("\n").join("<br />").replace(" ", "&nbsp;")
20 .replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;") 25 .replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
21 } 26 }
22 27
23 28
24 function handleMessage(message_event) { 29 function handleMessage(message_event) {
25 if (message_event.data == null || message_event.data == "null") { 30 if (message_event.data === null || message_event.data == "null") {
26 console.log("warning: null message") 31 console.log("warning: null message");
27 return 32 return;
28 } 33 }
29 console.log(message_event.data); 34 console.log(message_event.data);
30 var data = eval('('+message_event.data+')'); 35 var data = eval('('+message_event.data+')');
31 if (data == null) { 36 if (data === null) {
32 console.log("warning: null data") 37 console.log("warning: null data");
33 return 38 return;
34 } 39 }
35 40
36 if (data.result && data.type == "network error") { 41 if (data.result && data.type == "network error") {
37 $("#status_field").html("Failure") 42 $("#status_field").html("Failure");
38 $("#log").html("Network initialization error. Please supply the following " 43 $("#log").html("Network initialization error. Please supply the following" +
39 + "flags to chrome: --enable-nacl --allow-nacl-socket-api=localhost") 44 " flags to chrome: --enable-nacl --allow-nacl-socket-api=localhost");
40 } else { 45 } else {
41 $("#log").html("<pre>" + message_event.data + "</pre>") 46 $("#log").html("<pre>" + message_event.data + "</pre>");
42 } 47 }
43 } 48 }
44 49
45 function uploadFile(file) { 50 function uploadFile(file) {
46 (function(f) { 51 (function(f) {
47 fs.root.getFile(file.name, {create: true, exclusive: true}, 52 window.fs.root.getFile(file.name, {create: true, exclusive: true},
48 function(fileEntry) { 53 function(fileEntry) {
49 fileEntry.createWriter(function(fileWriter) { 54 fileEntry.createWriter(function(fileWriter) {
50 fileWriter.write(f); // Note: write() can take a File or Blob object. 55 fileWriter.write(f); // Note: write() can take a File or Blob object.
51 var url = uploadURL + file.name; 56 var url = uploadURL + file.name;
52 $("#log").html("File uploaded! Checkout at <a target=\"_blank\" href=\"" + url + "\">" + url + "</a>") 57 $("#log").html("File uploaded! Checkout at <a target=\"_blank\" href=\"" +
58 url + "\">" + url + "</a>");
53 }, errorHandler); 59 }, errorHandler);
54 }, errorHandler); 60 }, errorHandler);
55 })(file); 61 })(file);
56 } 62 }
57 63
58 function handleFileSelect(evt) { 64 function handleFileSelect(evt) {
59 var files = this.files; 65 var files = evt.srcElement.files;
60 for (var i = 0, file; file = files[i]; ++i) { 66 for (var i = 0; i < files.length; i++) {
61 uploadFile(file) 67 uploadFile(files[i]);
62 } 68 }
63 } 69 }
64 70
65 function toArray(list) { 71 function toArray(list) {
66 return Array.prototype.slice.call(list || [], 0); 72 return Array.prototype.slice.call(list || [], 0);
67 } 73 }
68 74
69 function onInitFs(fs) { 75 function onInitFs(fs) {
70 console.log('opened fs: ' + fs.name); 76 console.log('opened fs: ' + fs.name);
71 77
72 fs.root.getDirectory("/", {}, function (dir) { // readdir 78 fs.root.getDirectory("/", {}, function (dir) { // readdir
73 var dirReader = dir.createReader(); 79 var dirReader = dir.createReader();
74 var handleEntries = function(results) { 80 var handleEntries = function(results) {
75 if (results.length == 0) 81 if (results.length === 0)
76 return; 82 return;
77 results = toArray(results); 83 results = toArray(results);
78 results.forEach(function(entry, i) { 84 results.forEach(function(entry, i) {
79 var url = uploadURL + entry.name 85 var url = uploadURL + entry.name;
80 $("#listing").append('<a target="_blank" href="' + url + '">' + entry.na me + "</a><br>\n"); 86 $("#listing").append('<a target="_blank" href="' + url + '">' + entry.na me + "</a><br>\n");
81 }); 87 });
82 dirReader.readEntries(handleEntries) 88 dirReader.readEntries(handleEntries);
83 }; 89 };
84 dirReader.readEntries(handleEntries) 90 dirReader.readEntries(handleEntries);
85 }); 91 });
86 window.fs = fs 92 window.fs = fs;
87 } 93 }
88 94
89 function errorHandler(e) { 95 function errorHandler(e) {
90 var msg = ''; 96 var msg = '';
91 97
92 switch (e.code) { 98 switch (e.code) {
93 case FileError.QUOTA_EXCEEDED_ERR: 99 case FileError.QUOTA_EXCEEDED_ERR:
94 msg = 'QUOTA_EXCEEDED_ERR'; 100 msg = 'QUOTA_EXCEEDED_ERR';
95 break; 101 break;
96 case FileError.NOT_FOUND_ERR: 102 case FileError.NOT_FOUND_ERR:
97 msg = 'NOT_FOUND_ERR'; 103 msg = 'NOT_FOUND_ERR';
98 break; 104 break;
99 case FileError.SECURITY_ERR: 105 case FileError.SECURITY_ERR:
100 msg = 'SECURITY_ERR'; 106 msg = 'SECURITY_ERR';
101 break; 107 break;
102 case FileError.INVALID_MODIFICATION_ERR: 108 case FileError.INVALID_MODIFICATION_ERR:
103 msg = 'INVALID_MODIFICATION_ERR'; 109 msg = 'INVALID_MODIFICATION_ERR';
104 break; 110 break;
105 case FileError.INVALID_STATE_ERR: 111 case FileError.INVALID_STATE_ERR:
106 msg = 'INVALID_STATE_ERR'; 112 msg = 'INVALID_STATE_ERR';
107 break; 113 break;
108 default: 114 default:
109 msg = 'Unknown Error'; 115 msg = 'Unknown Error';
110 break; 116 break;
111 }; 117 }
112 $("#log").html("Error uploading file.") 118 $("#log").html("Error uploading file.");
113 console.log('Error: ' + msg); 119 console.log('Error: ' + msg);
114 } 120 }
115 121
116 $(document).ready(function() { 122 $(document).ready(function() {
117 window.URL = window.URL || window.webkitURL; 123 window.URL = window.URL || window.webkitURL;
118 window.requestFileSystem = window.requestFileSystem 124 window.requestFileSystem = window.requestFileSystem ||
119 || window.webkitRequestFileSystem; 125 window.webkitRequestFileSystem;
120 navigator.webkitPersistentStorage.requestQuota(1024*1024, 126 navigator.webkitPersistentStorage.requestQuota(1024*1024,
121 function(grantedBytes) { 127 function(grantedBytes) {
122 window.requestFileSystem(TEMPORARY, grantedBytes, onInitFs, errorHandler); 128 window.requestFileSystem(window.TEMPORARY, grantedBytes, onInitFs,
129 errorHandler);
123 }, function(e) { 130 }, function(e) {
124 console.log('Error', e); 131 console.log('Error', e);
125 }); 132 });
126 133
127 var listener = document.getElementById('listener'); 134 var listener = document.getElementById('listener');
128 listener.addEventListener('load', moduleDidLoad, true); 135 listener.addEventListener('load', moduleDidLoad, true);
129 listener.addEventListener('message', handleMessage, true); 136 listener.addEventListener('message', handleMessage, true);
130 137
131 document.getElementById('upfile').addEventListener( 138 document.getElementById('upfile').addEventListener(
132 'change', handleFileSelect, false); 139 'change', handleFileSelect, false);
133 }) 140 });
OLDNEW
« no previous file with comments | « ports/snes9x/snes9x.js ('k') | ports/vim/vim.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698