Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 define(function() { | 5 define(function() { |
| 6 | 6 |
| 7 // Memory ------------------------------------------------------------------- | 7 // Memory ------------------------------------------------------------------- |
| 8 | 8 |
| 9 function store8(memory, pointer, val) { | 9 function store8(memory, pointer, val) { |
| 10 memory[pointer] = val; | 10 memory[pointer] = val; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 } | 38 } |
| 39 | 39 |
| 40 function load32(memory, pointer) { | 40 function load32(memory, pointer) { |
| 41 return (memory[pointer + 0] << 0) + | 41 return (memory[pointer + 0] << 0) + |
| 42 (memory[pointer + 1] << 8) + | 42 (memory[pointer + 1] << 8) + |
| 43 (memory[pointer + 2] << 16) + | 43 (memory[pointer + 2] << 16) + |
| 44 (memory[pointer + 3] << 24); | 44 (memory[pointer + 3] << 24); |
| 45 } | 45 } |
| 46 | 46 |
| 47 function load64(memory, pointer) { | 47 function load64(memory, pointer) { |
| 48 var low = load32(memory, pointer); | 48 var low = Math.abs(load32(memory, pointer)); |
| 49 var high = load32(memory, pointer + 4); | 49 var high = Math.abs(load32(memory, pointer + 4)); |
| 50 return low + high * 0x10000; | 50 return low + high * 0x100000000; |
| 51 } | 51 } |
| 52 | 52 |
| 53 var kAlignment = 8; | 53 var kAlignment = 8; |
| 54 | 54 |
| 55 function align(size) { | 55 function align(size) { |
| 56 return size + (kAlignment - (size % kAlignment)) % kAlignment; | 56 return size + (kAlignment - (size % kAlignment)) % kAlignment; |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Buffer ------------------------------------------------------------------- | 59 // Buffer ------------------------------------------------------------------- |
| 60 | 60 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 91 var kStructHeaderSize = 8; | 91 var kStructHeaderSize = 8; |
| 92 var kMessageHeaderSize = 8; | 92 var kMessageHeaderSize = 8; |
| 93 | 93 |
| 94 // Decoder ------------------------------------------------------------------ | 94 // Decoder ------------------------------------------------------------------ |
| 95 | 95 |
| 96 function Decoder(memory, handles, base) { | 96 function Decoder(memory, handles, base) { |
| 97 this.memory = memory; | 97 this.memory = memory; |
| 98 this.handles = handles; | 98 this.handles = handles; |
| 99 this.base = base; | 99 this.base = base; |
| 100 this.next = base; | 100 this.next = base; |
| 101 this.viewU32 = new Uint32Array( | |
| 102 this.memory.buffer, 0, | |
| 103 Math.floor(this.memory.length / Uint32Array.BYTES_PER_ELEMENT)); | |
| 101 } | 104 } |
| 102 | 105 |
| 103 Decoder.prototype.skip = function(offset) { | 106 Decoder.prototype.skip = function(offset) { |
| 104 this.next += offset; | 107 this.next += offset; |
| 105 }; | 108 }; |
| 106 | 109 |
| 107 Decoder.prototype.read8 = function() { | 110 Decoder.prototype.read8 = function() { |
| 108 var result = load8(this.memory, this.next); | 111 var result = load8(this.memory, this.next); |
| 109 this.next += 1; | 112 this.next += 1; |
| 110 return result; | 113 return result; |
| 111 }; | 114 }; |
| 112 | 115 |
| 113 Decoder.prototype.read32 = function() { | 116 Decoder.prototype.read32 = function() { |
| 114 var result = load32(this.memory, this.next); | 117 var result = this.viewU32[this.next / this.viewU32.BYTES_PER_ELEMENT]; |
| 115 this.next += 4; | 118 this.next += this.viewU32.BYTES_PER_ELEMENT; |
| 116 return result; | 119 return result; |
| 117 }; | 120 }; |
| 118 | 121 |
| 119 Decoder.prototype.read64 = function() { | 122 Decoder.prototype.read64 = function() { |
| 123 var low = this.read32(); | |
| 124 var high = this.read32(); | |
| 125 return low + high * 0x100000000; | |
| 126 | |
| 120 var result = load64(this.memory, this.next); | 127 var result = load64(this.memory, this.next); |
| 121 this.next += 8; | 128 this.next += 8; |
| 122 return result; | 129 return result; |
|
abarth-chromium
2013/12/20 04:21:02
These last few lines are dead now. You can probab
Aaron Boodman
2013/12/20 05:42:24
Eep. Thanks.
| |
| 123 }; | 130 }; |
| 124 | 131 |
| 125 Decoder.prototype.decodePointer = function() { | 132 Decoder.prototype.decodePointer = function() { |
| 126 // TODO(abarth): To correctly decode a pointer, we need to know the real | 133 // TODO(abarth): To correctly decode a pointer, we need to know the real |
| 127 // base address of the array buffer. | 134 // base address of the array buffer. |
| 128 var offsetPointer = this.next; | 135 var offsetPointer = this.next; |
| 129 var offset = this.read64(); | 136 var offset = this.read64(); |
| 130 if (!offset) | 137 if (!offset) |
| 131 return 0; | 138 return 0; |
| 132 return offsetPointer + offset; | 139 return offsetPointer + offset; |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 exports.kMessageHeaderSize = kMessageHeaderSize; | 443 exports.kMessageHeaderSize = kMessageHeaderSize; |
| 437 exports.Uint8 = Uint8; | 444 exports.Uint8 = Uint8; |
| 438 exports.Uint16 = Uint16; | 445 exports.Uint16 = Uint16; |
| 439 exports.Uint32 = Uint32; | 446 exports.Uint32 = Uint32; |
| 440 exports.Uint64 = Uint64; | 447 exports.Uint64 = Uint64; |
| 441 exports.PointerTo = PointerTo; | 448 exports.PointerTo = PointerTo; |
| 442 exports.ArrayOf = ArrayOf; | 449 exports.ArrayOf = ArrayOf; |
| 443 exports.Handle = Handle; | 450 exports.Handle = Handle; |
| 444 return exports; | 451 return exports; |
| 445 }); | 452 }); |
| OLD | NEW |