Skip to content

Commit 250beb3

Browse files
committed
[js] Make the REPR put methods on STable in setup_STable rather then an assortment of hacky places.
1 parent eea75dc commit 250beb3

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

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

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -496,21 +496,16 @@ function P6int() {
496496
P6int.prototype.flattened_default = 0;
497497
P6int.prototype.boxed_primitive = 1;
498498

499-
P6int.prototype.basic_constructor = basic_constructor;
500-
P6int.prototype.basic_type_object_for = basic_type_object_for;
501-
502-
P6int.prototype.create_obj_constructor = function(STable) {
503-
var c = this.basic_constructor(STable);
504-
505-
STable.obj_constructor = c; // HACK it's set again later, we set it for addInternalMethod
499+
P6int.prototype.create_obj_constructor = basic_constructor;
500+
P6int.prototype.type_object_for = basic_type_object_for;
506501

502+
P6int.prototype.setup_STable = function(STable) {
507503
STable.addInternalMethod('$$set_int', function(value) {
508504
this.value = value;
509505
});
510506
STable.addInternalMethod('$$get_int', function() {
511507
return this.value;
512508
});
513-
return c;
514509
};
515510

516511
P6int.prototype.compose = function(STable, repr_info_hash) {
@@ -538,11 +533,6 @@ P6int.prototype.serialize = function(data, obj) {
538533
};
539534

540535

541-
P6int.prototype.type_object_for = function(HOW) {
542-
var type_object = this.basic_type_object_for(HOW);
543-
return type_object;
544-
};
545-
546536
module.exports.P6int = P6int;
547537

548538
function P6num() {
@@ -677,28 +667,24 @@ function P6bigint() {
677667
}
678668
P6bigint.prototype.create_obj_constructor = basic_constructor;
679669

680-
P6bigint.prototype.basic_type_object_for = basic_type_object_for;
681-
682-
P6bigint.prototype.type_object_for = function(HOW) {
683-
var type_object = this.basic_type_object_for(HOW);
670+
P6bigint.prototype.type_object_for = basic_type_object_for;
684671

685-
this._STable.addInternalMethod('$$set_int', function(value) {
672+
P6bigint.prototype.setup_STable = function(STable) {
673+
STable.addInternalMethod('$$set_int', function(value) {
686674
this.value = bignum(value);
687675
});
688676

689-
this._STable.addInternalMethod('$$get_int', function() {
677+
STable.addInternalMethod('$$get_int', function() {
690678
return this.value.toNumber() | 0;
691679
});
692680

693-
this._STable.addInternalMethod('$$set_bignum', function(value) {
681+
STable.addInternalMethod('$$set_bignum', function(value) {
694682
this.value = value;
695683
});
696684

697-
this._STable.addInternalMethod('$$get_bignum', function() {
685+
STable.addInternalMethod('$$get_bignum', function() {
698686
return this.value;
699687
});
700-
701-
return type_object;
702688
};
703689

704690
P6bigint.prototype.generateBoxingMethods = function(repr, attr) {
@@ -779,12 +765,9 @@ MultiDimArray.prototype.compose = function(STable, repr_info_hash) {
779765
};
780766
MultiDimArray.prototype.allocate = basic_allocate;
781767

782-
MultiDimArray.prototype.basic_constructor = basic_constructor;
783-
MultiDimArray.prototype.create_obj_constructor = function(STable) {
784-
var c = this.basic_constructor(STable);
785-
786-
STable.obj_constructor = c; // HACK it's set again later, we set it for addInternalMethod
768+
MultiDimArray.prototype.create_obj_constructor = basic_constructor;
787769

770+
MultiDimArray.prototype.setup_STable = function(STable) {
788771
STable.addInternalMethod('$$numdimensions', function(value) {
789772
if (this.type_object_) {
790773
throw new NQPException('Cannot get number of dimensions of a type object');
@@ -910,9 +893,6 @@ MultiDimArray.prototype.create_obj_constructor = function(STable) {
910893
STable.addInternalMethod('$$atpos', function(index) {
911894
return this.$$atposnd(new NQPArray([index]));
912895
});
913-
914-
915-
return c;
916896
};
917897

918898
MultiDimArray.prototype.serialize_repr_data = function(st, cursor) {
@@ -999,15 +979,12 @@ VMException.prototype.type_object_for = basic_type_object_for;
999979
VMException.prototype.compose = noop_compose;
1000980
VMException.prototype.basic_type_object_for = basic_type_object_for;
1001981

1002-
VMException.prototype.basic_constructor = basic_constructor;
982+
VMException.prototype.create_obj_constructor = basic_constructor;
1003983

1004-
VMException.prototype.create_obj_constructor = function(STable) {
1005-
var c = this.basic_constructor(STable);
1006-
STable.obj_constructor = c; // HACK it's set again later, we set it for addInternalMethod
984+
VMException.prototype.setup_STable = function(STable) {
1007985
STable.addInternalMethod('$$get_str', function() {
1008986
return this.message;
1009987
});
1010-
return c;
1011988
};
1012989

1013990
module.exports.VMException = VMException;

0 commit comments

Comments
 (0)