Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / mojo / apps / js / bindings / codec.js
index edaa005..5df5803 100644 (file)
@@ -95,6 +95,9 @@ define(function() {
     this.viewU32 = new Uint32Array(
         this.memory.buffer, 0,
         Math.floor(this.memory.length / Uint32Array.BYTES_PER_ELEMENT));
+    this.viewFloat = new Float32Array(
+        this.memory.buffer, 0,
+        Math.floor(this.memory.length / Float32Array.BYTES_PER_ELEMENT));
   }
 
   Decoder.prototype.skip = function(offset) {
@@ -119,6 +122,12 @@ define(function() {
     return low + high * 0x100000000;
   };
 
+  Decoder.prototype.decodeFloat = function() {
+    var result = this.viewFloat[this.next / this.viewFloat.BYTES_PER_ELEMENT];
+    this.next += this.viewFloat.BYTES_PER_ELEMENT;
+    return result;
+  };
+
   Decoder.prototype.decodePointer = function() {
     // TODO(abarth): To correctly decode a pointer, we need to know the real
     // base address of the array buffer.
@@ -203,6 +212,14 @@ define(function() {
     this.next += 8;
   };
 
+  Encoder.prototype.encodeFloat = function(val) {
+    var floatBuffer = new Float32Array(1);
+    floatBuffer[0] = val;
+    var buffer = new Uint8Array(floatBuffer.buffer, 0);
+    for (var i = 0; i < buffer.length; ++i)
+      this.buffer.memory[this.next++] = buffer[i];
+  };
+
   Encoder.prototype.encodePointer = function(pointer) {
     if (!pointer)
       return this.write64(0);