Skip to content

Commit

Permalink
[js] Fix serialization and deserialization of boot int/str arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Jun 13, 2019
1 parent 9af6015 commit 9b64eca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/vm/js/nqp-runtime/BOOT.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ module.exports.createArray = function(array) {
module.exports.createIntArray = function(array) {
return exports.IntArray.$$STable.REPR.allocateFromArray(exports.IntArray.$$STable, array);
};

module.exports.createStrArray = function(array) {
return exports.StrArray.$$STable.REPR.allocateFromArray(exports.StrArray.$$STable, array);
};
10 changes: 5 additions & 5 deletions src/vm/js/nqp-runtime/deserialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ class BinaryCursor {
* @param {Function} readElem - a callback that reads in a single element
* @return {Object} bootArray containing the elements
*/
array(readElem) {
array(readElem, create) {
const elems = this.varint();
const array = [];
for (let i = 0; i < elems; i++) {
array.push(readElem(this));
}
const bootArray = BOOT.createArray(array);
const bootArray = create(array);
if (this.sc.currentObject) {
bootArray.$$SC = this.sc;
this.sc.ownedObjects.set(bootArray, this.sc.currentObject);
Expand Down Expand Up @@ -326,11 +326,11 @@ class BinaryCursor {
case REFVAR_VM_STR:
return new NQPStr(this.str());
case REFVAR_VM_ARR_VAR:
return this.array(cursor => cursor.variant());
return this.array(cursor => cursor.variant(), array => BOOT.createArray(array));
case REFVAR_VM_ARR_STR:
return this.array(cursor => cursor.str());
return this.array(cursor => cursor.str(), array => BOOT.createStrArray(array));
case REFVAR_VM_ARR_INT:
return this.array(cursor => cursor.varint());
return this.array(cursor => cursor.varint(), array => BOOT.createIntArray(array));
case REFVAR_VM_HASH_STR_VAR:
return this.hashOfVariants(this);
case REFVAR_STATIC_CODEREF:
Expand Down
4 changes: 4 additions & 0 deletions src/vm/js/nqp-runtime/serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ class BinaryWriteCursor {
discrim = REFVAR_VM_STR;
} else if (ref.$$STable === BOOT.Array.$$STable) {
discrim = REFVAR_VM_ARR_VAR;
} else if (ref.$$STable === BOOT.IntArray.$$STable) {
discrim = REFVAR_VM_ARR_INT;
} else if (ref.$$STable === BOOT.StrArray.$$STable) {
discrim = REFVAR_VM_ARR_STR;
} else if (ref instanceof Hash) {
discrim = REFVAR_VM_HASH_STR_VAR;
} else if (ref instanceof CodeRef || typeof ref == 'function') {
Expand Down

0 comments on commit 9b64eca

Please sign in to comment.