Skip to content
This repository
Browse code

Start putting in the framework for developing the javascript kernel

  • Loading branch information...
commit 7832503579f87128865f26581513deb12d24892a 1 parent c86e8e5
Stefan O'Rear authored

Showing 2 changed files with 48 additions and 0 deletions. Show diff stats Hide diff stats

  1. +9 0 js/index.html
  2. +39 0 js/niecza.js
9 js/index.html
... ... @@ -0,0 +1,9 @@
  1 +<html>
  2 + <head>
  3 + <title>Niecza/JS test harness</title>
  4 + <script src="niecza.js"></script>
  5 + <script>Niecza.Serialization.loadSerFile('CORE.ser', function(){});</script>
  6 + </head>
  7 + <body>
  8 + </body>
  9 +</html>
39 js/niecza.js
... ... @@ -0,0 +1,39 @@
  1 +// This will be moved to m4 later
  2 +
  3 +(function() {
  4 +
  5 +var Niecza = {};
  6 +
  7 +var NSer = Niecza.Serialization = {};
  8 +
  9 +var NSThaw = Niecza.Serialization.Thaw = function (buffer, callback) {
  10 + this.buffer = buffer;
  11 + this.view = new DataView(buffer);
  12 + this.offset = 0;
  13 +};
  14 +
  15 +NSThaw.prototype.$className = 'Niecza.Serialization.Thaw';
  16 +
  17 +
  18 +NSer.loadSerFileEnd = function(ev) {
  19 + var xhr = ev.target,
  20 + cb = xhr.nieczaCallback;
  21 + if (xhr.status >= 200 && xhr.status < 300) {
  22 + new NSThaw(xhr.response, cb);
  23 + } else {
  24 + cb(false, xhr.statusText, xhr);
  25 + }
  26 +};
  27 +
  28 +NSer.loadSerFile = function (url, callback) {
  29 + var xhr = new XMLHttpRequest();
  30 + xhr.responseType = 'arraybuffer';
  31 + xhr.onloadend = NSer.loadSerFileEnd;
  32 + xhr.nieczaCallback = callback;
  33 + xhr.open('GET', url);
  34 + xhr.send(null);
  35 +};
  36 +
  37 +window.Niecza = Niecza;
  38 +
  39 +})();

0 comments on commit 7832503

Please sign in to comment.
Something went wrong with that request. Please try again.