From eebf37f7a5aa0352f43d2fcbe0a0be02143ab141 Mon Sep 17 00:00:00 2001 From: Pawel Murias Date: Tue, 17 Jan 2017 17:02:25 +0100 Subject: [PATCH] [js] Decont before converting objects to num or int instead of having a hack on containers. --- src/vm/js/nqp-runtime/container-specs.js | 42 ------------------------ src/vm/js/nqp-runtime/runtime.js | 3 +- 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/src/vm/js/nqp-runtime/container-specs.js b/src/vm/js/nqp-runtime/container-specs.js index 9bf50d5455..6686a35be7 100644 --- a/src/vm/js/nqp-runtime/container-specs.js +++ b/src/vm/js/nqp-runtime/container-specs.js @@ -83,18 +83,6 @@ class NativeRef { if (primitiveType == 1) { // int this.STable.addInternalMethods(class { - $getInt(ctx, value) { - return this.get(); - } - - $$getNum() { - return this.get(); - } - - $$getStr() { - return this.get().toString(); - } - $$iscont_i() { return 1; } @@ -136,18 +124,6 @@ class NativeRef { }); } else if (primitiveType == 2) { // num this.STable.addInternalMethods(class { - $$getInt(ctx, value) { - return this.get() | 0; - } - - $$getNum(ctx, value) { - return this.get(); - } - - $$getStr(ctx, value) { - return this.get().toString(); - } - $$iscont_n() { return 1; } @@ -189,20 +165,6 @@ class NativeRef { }); } else if (primitiveType == 3) { // str this.STable.addInternalMethods(class { - $$getInt(ctx, value) { - var ret = parseFloat(this.get()); - return isNaN(ret) ? 0 : ret | 0; - } - - $$getNum(ctx, value) { - var ret = parseFloat(this.get()); - return isNaN(ret) ? 0 : ret; - } - - $$getStr(ctx, value) { - return this.get().toString(); - } - $$iscont_s() { return 1; } @@ -224,10 +186,6 @@ class NativeRef { return this.get(); } - $$getStr(ctx, value) { - return this.get(); - } - $$decont(ctx, value) { var hll = STable.hllOwner; if (hll === undefined) { diff --git a/src/vm/js/nqp-runtime/runtime.js b/src/vm/js/nqp-runtime/runtime.js index da58f2f7c0..d16fd1a784 100644 --- a/src/vm/js/nqp-runtime/runtime.js +++ b/src/vm/js/nqp-runtime/runtime.js @@ -158,7 +158,8 @@ exports.toStr = function(arg_, ctx) { } }; -exports.toNum = function(arg, ctx) { +exports.toNum = function(arg_, ctx) { + let arg = arg_.$$decont(ctx); if (typeof arg == 'number') { return arg; } else if (arg === Null) {