OSDN Git Service

funcprotoの中に、ツールとしていくつかのライブラリを収納
authordhrname <dhrname@users.sourceforge.jp>
Fri, 13 Sep 2013 11:40:44 +0000 (20:40 +0900)
committerdhrname <dhrname@users.sourceforge.jp>
Fri, 13 Sep 2013 11:40:44 +0000 (20:40 +0900)
tool/funcproto/a.txt [new file with mode: 0644]
tool/funcproto/b.txt [new file with mode: 0644]
tool/funcproto/openfile.js [new file with mode: 0644]
tool/funcproto/sleep.js [new file with mode: 0644]

diff --git a/tool/funcproto/a.txt b/tool/funcproto/a.txt
new file mode 100644 (file)
index 0000000..274c005
--- /dev/null
@@ -0,0 +1 @@
+1234
\ No newline at end of file
diff --git a/tool/funcproto/b.txt b/tool/funcproto/b.txt
new file mode 100644 (file)
index 0000000..ff74a0e
--- /dev/null
@@ -0,0 +1 @@
+5678
\ No newline at end of file
diff --git a/tool/funcproto/openfile.js b/tool/funcproto/openfile.js
new file mode 100644 (file)
index 0000000..fc23ef2
--- /dev/null
@@ -0,0 +1,60 @@
+/*MIT License*/\r
+
+Function.prototype.open = function() {\r
+  if (arguments.length === 0) {\r
+    throw new Error("no arguments error");\r
+  }\r
+  var that = this,               // Callback Function\r
+      handle = [],               // File Handler\r
+      fileNames = Array.prototype.slice.call(arguments),\r
+      fileName = fileNames.shift(),\r
+      xhr = new XMLHttpRequest();\r
+  handle.read = function () {\r
+    return this.join("\n");\r
+  };\r
+  handle.write = function (text) {\r
+    xhr.open("POST", fileName);\r
+    xhr.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");\r
+    xhr.send(text);\r
+  };\r
+  xhr.onreadystatechange = function() {\r
+    if (xhr.readyState === 4) {\r
+      if ((xhr.status === 200) || (xhr.status > 400)) {\r
+        var text = (xhr.status === 200) ? xhr.responseText : "";\r
+        handle.push((handle[fileName] = text));\r
+        if (fileNames.length !== 0) {\r
+          fileName = fileNames.shift();\r
+          f();\r
+        } else {                                  //Load End\r
+          xhr.onreadystatechange = function() {}; //to solve the problem about a memory leak for IE 8\r
+          that(handle);\r
+          text = fileNames = xhr = handle = f = void 0;\r
+        }\r
+      }\r
+    }\r
+  };\r
+  var f = function() {\r
+    xhr.open("GET", fileName);\r
+    xhr.send();\r
+  };\r
+  f();\r
+};\r
+\r
+f.open("a.txt", "b.txt", "UNDEF.txt", "UNDEF.txt", "b.txt");\r
+\r
+function f (file) {\r
+  describe("File::open", function() {\r
+    it("for a read method", function() {\r
+      expect(file.read()).toEqual("1234\n5678\n\n\n5678");\r
+      expect(file["a.txt"]).toEqual("1234");\r
+      expect(file["b.txt"]).toEqual("5678");\r
+      expect(file[0]).toEqual("1234");\r
+      expect(file[1]).toEqual("5678");\r
+      expect(file["UNDEF.txt"]).toEqual("");\r
+      expect(file[2]).toEqual("");\r
+      expect(file[3]).toEqual("");\r
+      expect(file[4]).toEqual("5678");\r
+    });\r
+  });\r
+  __start_();\r
+};
\ No newline at end of file
diff --git a/tool/funcproto/sleep.js b/tool/funcproto/sleep.js
new file mode 100644 (file)
index 0000000..3fbf9ba
--- /dev/null
@@ -0,0 +1,12 @@
+/*MIT License*/\r
+\r
+Function.prototype.sleep = function(){\r
+};\r
+\r
+(function() {\r
+  describe("Async::sleep", function() {\r
+    it("", function() {\r
+    });\r
+  });\r
+  __start_();\r
+}).sleep();
\ No newline at end of file