Commit 1926227b authored by yann300's avatar yann300

add comments

parent 39d7b2f0
...@@ -10,6 +10,14 @@ class RefType { ...@@ -10,6 +10,14 @@ class RefType {
this.basicType = 'RefType' this.basicType = 'RefType'
} }
/**
* decode the type from the stack
*
* @param {Int} stackDepth - position of the type in the stack
* @param {Array} stack - stack
* @return {String} - memory
* @return {Object} - storage
*/
decodeFromStack (stackDepth, stack, memory, storage) { decodeFromStack (stackDepth, stack, memory, storage) {
if (stack.length - 1 < stackDepth) { if (stack.length - 1 < stackDepth) {
return { error: '<decoding failed - stack underflow ' + stackDepth + '>' } return { error: '<decoding failed - stack underflow ' + stackDepth + '>' }
...@@ -19,6 +27,13 @@ class RefType { ...@@ -19,6 +27,13 @@ class RefType {
return decodeInternal(this, offset, memory, storage) return decodeInternal(this, offset, memory, storage)
} }
/**
* decode the type with the @arg offset location from the memory or storage
*
* @param {Int} offset - position of the type in the memory
* @return {String} - memory
* @return {Object} - storage
*/
decode (offset, memory, storage) { decode (offset, memory, storage) {
offset = memory.substr(2 * offset, 64) offset = memory.substr(2 * offset, 64)
offset = parseInt(offset, 16) offset = parseInt(offset, 16)
......
...@@ -9,11 +9,26 @@ class ValueType { ...@@ -9,11 +9,26 @@ class ValueType {
this.basicType = 'ValueType' this.basicType = 'ValueType'
} }
/**
* decode the type with the @arg location from the storage
*
* @param {Object} location - containing offset and slot
* @param {Object} storageContent - storageContent (storage)
* @return {Object} - decoded value
*/
decodeFromStorage (location, storageContent) { decodeFromStorage (location, storageContent) {
var value = util.extractHexValue(location, storageContent, this.storageBytes) var value = util.extractHexValue(location, storageContent, this.storageBytes)
return this.decodeValue(value) return this.decodeValue(value)
} }
/**
* decode the type from the stack
*
* @param {Int} stackDepth - position of the type in the stack
* @param {Array} stack - stack
* @param {String} - memory
* @return {Object} - decoded value
*/
decodeFromStack (stackDepth, stack, memory) { decodeFromStack (stackDepth, stack, memory) {
if (stackDepth >= stack.length) { if (stackDepth >= stack.length) {
return this.decodeValue('') return this.decodeValue('')
...@@ -22,11 +37,25 @@ class ValueType { ...@@ -22,11 +37,25 @@ class ValueType {
} }
} }
/**
* decode the type with the @arg offset location from the memory
*
* @param {Int} stackDepth - position of the type in the stack
* @return {String} - memory
* @return {Object} - decoded value
*/
decodeFromMemory (offset, memory) { decodeFromMemory (offset, memory) {
var value = memory.substr(2 * offset, 64) var value = memory.substr(2 * offset, 64)
return this.decodeValue(util.extractHexByteSlice(value, this.storageBytes, 0)) return this.decodeValue(util.extractHexByteSlice(value, this.storageBytes, 0))
} }
/**
* decode the type with the @arg offset location from the memory
*
* @param {Int} offset - position of the type in the memory
* @return {String} - memory
* @return {Object} - storage
*/
decode (offset, memory) { decode (offset, memory) {
return this.decodeFromMemory(offset, memory) return this.decodeFromMemory(offset, memory)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment