Skip to content

Commit 491bcc1

Browse files
committed
[js] Implement UNBOX_INT, UNBOX_NUM, BIGINT, HAS_ELEMS boolification modes.
1 parent 0d10b92 commit 491bcc1

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ STable.prototype.setboolspec = function(mode, method) {
3333
this.obj_constructor.prototype.$$to_bool = function(ctx) {
3434
return method.$call(ctx, {}, this);
3535
};
36+
} else if (mode == 1) {
37+
this.obj_constructor.prototype.$$to_bool = function(ctx) {
38+
return this.$$get_int() == 0 ? 0 : 1;
39+
};
40+
} else if (mode == 2) {
41+
this.obj_constructor.prototype.$$to_bool = function(ctx) {
42+
return this.$$get_num() == 0 ? 0 : 1;
43+
};
3644
} else if (mode == 3) {
3745
this.obj_constructor.prototype.$$to_bool = function(ctx) {
3846
return this.$$get_str() == '' ? 0 : 1;
@@ -44,8 +52,16 @@ STable.prototype.setboolspec = function(mode, method) {
4452
};
4553
} else if (mode == 5) {
4654
// this is the default - do nothing
47-
} else if (mode == 7 || mode == 8) {
55+
} else if (mode == 6) {
56+
this.obj_constructor.prototype.$$to_bool = function(ctx) {
57+
return this.$$get_bignum().eq(0) ? 0 : 1;
58+
};
59+
} else if (mode == 7) {
4860
// STUB
61+
} else if (mode == 8) {
62+
this.obj_constructor.prototype.$$to_bool = function(ctx) {
63+
return this.$$elems() ? 1 : 0;
64+
};
4965
} else {
5066
throw 'setboolspec with mode: ' + mode + ' NYI';
5167
}

0 commit comments

Comments
 (0)