Skip to content

Commit d1dc2e2

Browse files
committed
[js] Serialize the boolification spec.
1 parent df02637 commit d1dc2e2

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/vm/js/nqp-runtime/serialization.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ var REFVAR_VM_HASH_STR_VAR = 10;
3636
var REFVAR_STATIC_CODEREF = 11;
3737
var REFVAR_CLONED_CODEREF = 12;
3838

39+
var STABLE_BOOLIFICATION_SPEC_MODE_MASK = 0x0F;
40+
var STABLE_HAS_CONTAINER_SPEC = 0x10;
41+
var STABLE_HAS_INVOCATION_SPEC = 0x20;
42+
var STABLE_HAS_HLL_OWNER = 0x40;
43+
3944
function BinaryWriteCursor(writer) {
4045
this.buffer = new Buffer(1024);
4146
this.writer = writer;
@@ -465,16 +470,16 @@ SerializationWriter.prototype.serializeSTable = function(st) {
465470
/*TODO serialize boolifcation spec*/
466471
var flags;
467472

468-
if (false) {
469-
//if (st->boolification_spec->mode >= 0xF) {
470-
// MVM_exception_throw_adhoc(tc,
471-
// "Serialization error: boolification spec mode %u out of range and can't be serialized",
472-
// st->boolification_spec->mode);
473-
//}
474-
//flags = st->boolification_spec->mode;
473+
if (st.boolificationSpec) {
474+
var mode = st.boolificationSpec.mode;
475+
if (mode >= 0xF) {
476+
throw "Serialization error: boolification spec mode " + mode + " out of range and can't be serialized";
477+
}
478+
flags = mode;
475479
} else {
476480
flags = 0xF;
477481
}
482+
478483
/*
479484
if (st->container_spec != NULL)
480485
flags |= STABLE_HAS_CONTAINER_SPEC;
@@ -484,14 +489,13 @@ SerializationWriter.prototype.serializeSTable = function(st) {
484489
flags |= STABLE_HAS_HLL_OWNER;
485490
*/
486491

487-
/* Boolification spec. */
488492
this.stables_data.U8(flags);
489493

490-
/*writeInt(st.BoolificationSpec == null ? 0 : 1);
491-
if (st.BoolificationSpec != null) {
492-
writeInt(st.BoolificationSpec.Mode);
493-
writeRef(st.BoolificationSpec.Method);
494-
}*/
494+
/* Boolification spec. */
495+
496+
if (st.boolificationSpec) {
497+
this.stables_data.ref(st.boolificationSpec.method);
498+
}
495499

496500
/*this.stables_data.writeInt(st.ContainerSpec == null ? 0 : 1);
497501
if (st.ContainerSpec != null) {

src/vm/js/nqp-runtime/sixmodel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function STable(REPR, HOW) {
2929
}
3030

3131
STable.prototype.setboolspec = function(mode, method) {
32+
this.boolificationSpec = {mode: mode, method: method};
3233
if (mode == 0) {
3334
this.obj_constructor.prototype.$$to_bool = function(ctx) {
3435
return method.$call(ctx, {}, this);

0 commit comments

Comments
 (0)