mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-24 14:42:13 +00:00
Fix implicit string to bool conversion (#567)
This commit is contained in:
parent
85de20c4fc
commit
abf3de9076
@ -42,7 +42,7 @@ export class String {
|
||||
);
|
||||
} else {
|
||||
code -= 0x10000;
|
||||
let hi: u32 = (code >>> 10) + 0xD800;
|
||||
let hi: u32 = (code >>> 10) + 0xD800;
|
||||
let lo: u32 = (code & 0x3FF) + 0xDC00;
|
||||
store<u32>(
|
||||
changetype<usize>(out),
|
||||
@ -110,9 +110,9 @@ export class String {
|
||||
assert(this !== null);
|
||||
if (other === null) other = changetype<String>("null");
|
||||
|
||||
var thisLen: isize = this.length;
|
||||
var thisLen: isize = this.length;
|
||||
var otherLen: isize = other.length;
|
||||
var outLen: usize = thisLen + otherLen;
|
||||
var outLen: usize = thisLen + otherLen;
|
||||
if (outLen == 0) return changetype<String>("");
|
||||
var out = allocateUnsafe(outLen);
|
||||
copyUnsafe(out, 0, this, 0, thisLen);
|
||||
@ -141,6 +141,11 @@ export class String {
|
||||
return !compareUnsafe(left, 0, right, 0, leftLength);
|
||||
}
|
||||
|
||||
@operator.prefix("!")
|
||||
private static __not(str: String): bool {
|
||||
return str === null || !str.length;
|
||||
}
|
||||
|
||||
@operator("!=")
|
||||
private static __ne(left: String, right: String): bool {
|
||||
return !this.__eq(left, right);
|
||||
@ -345,8 +350,8 @@ export class String {
|
||||
var out = allocateUnsafe(targetLength);
|
||||
if (len > padLen) {
|
||||
let count = (len - 1) / padLen;
|
||||
let base = count * padLen;
|
||||
let rest = len - base;
|
||||
let base = count * padLen;
|
||||
let rest = len - base;
|
||||
repeatUnsafe(out, 0, padString, count);
|
||||
if (rest) copyUnsafe(out, base, padString, 0, rest);
|
||||
} else {
|
||||
@ -394,9 +399,9 @@ export class String {
|
||||
}
|
||||
|
||||
slice(beginIndex: i32, endIndex: i32 = i32.MAX_VALUE): String {
|
||||
var len = this.length;
|
||||
var len = this.length;
|
||||
var begin = beginIndex < 0 ? max(beginIndex + len, 0) : min(beginIndex, len);
|
||||
var end = endIndex < 0 ? max(endIndex + len, 0) : min(endIndex, len);
|
||||
var end = endIndex < 0 ? max(endIndex + len, 0) : min(endIndex, len);
|
||||
len = end - begin;
|
||||
if (len <= 0) return changetype<String>("");
|
||||
var out = allocateUnsafe(len);
|
||||
@ -512,7 +517,7 @@ export class String {
|
||||
cp = (
|
||||
(cp & 7) << 18 |
|
||||
(load<u8>(ptr + ptrPos++) & 63) << 12 |
|
||||
(load<u8>(ptr + ptrPos++) & 63) << 6 |
|
||||
(load<u8>(ptr + ptrPos++) & 63) << 6 |
|
||||
load<u8>(ptr + ptrPos++) & 63
|
||||
) - 0x10000;
|
||||
store<u16>(buf + bufPos, 0xD800 + (cp >> 10));
|
||||
@ -523,7 +528,7 @@ export class String {
|
||||
assert(ptrPos + 2 <= len);
|
||||
store<u16>(buf + bufPos,
|
||||
(cp & 15) << 12 |
|
||||
(load<u8>(ptr + ptrPos++) & 63) << 6 |
|
||||
(load<u8>(ptr + ptrPos++) & 63) << 6 |
|
||||
load<u8>(ptr + ptrPos++) & 63
|
||||
);
|
||||
bufPos += 2;
|
||||
@ -548,8 +553,8 @@ export class String {
|
||||
++off; ++pos;
|
||||
} else if (c1 < 2048) {
|
||||
let ptr = buf + off;
|
||||
store<u8>(ptr, c1 >> 6 | 192);
|
||||
store<u8>(ptr, c1 & 63 | 128, 1);
|
||||
store<u8>(ptr, c1 >> 6 | 192);
|
||||
store<u8>(ptr, c1 & 63 | 128, 1);
|
||||
off += 2; ++pos;
|
||||
} else {
|
||||
let ptr = buf + off;
|
||||
@ -559,15 +564,15 @@ export class String {
|
||||
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
||||
store<u8>(ptr, c1 >> 18 | 240);
|
||||
store<u8>(ptr, c1 >> 12 & 63 | 128, 1);
|
||||
store<u8>(ptr, c1 >> 6 & 63 | 128, 2);
|
||||
store<u8>(ptr, c1 >> 6 & 63 | 128, 2);
|
||||
store<u8>(ptr, c1 & 63 | 128, 3);
|
||||
off += 4; pos += 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
store<u8>(ptr, c1 >> 12 | 224);
|
||||
store<u8>(ptr, c1 >> 6 & 63 | 128, 1);
|
||||
store<u8>(ptr, c1 & 63 | 128, 2);
|
||||
store<u8>(ptr, c1 >> 12 | 224);
|
||||
store<u8>(ptr, c1 >> 6 & 63 | 128, 1);
|
||||
store<u8>(ptr, c1 & 63 | 128, 2);
|
||||
off += 3; ++pos;
|
||||
}
|
||||
}
|
||||
|
@ -2348,7 +2348,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 2072
|
||||
i32.const 249
|
||||
i32.const 254
|
||||
i32.const 4
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -3525,7 +3525,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 2072
|
||||
i32.const 249
|
||||
i32.const 254
|
||||
i32.const 4
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -115,7 +115,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 16
|
||||
i32.const 224
|
||||
i32.const 229
|
||||
i32.const 4
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -199,7 +199,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 16
|
||||
i32.const 224
|
||||
i32.const 229
|
||||
i32.const 4
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -6238,7 +6238,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 4056
|
||||
i32.const 249
|
||||
i32.const 254
|
||||
i32.const 4
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -11617,7 +11617,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 4056
|
||||
i32.const 249
|
||||
i32.const 254
|
||||
i32.const 4
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -1525,7 +1525,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 72
|
||||
i32.const 507
|
||||
i32.const 512
|
||||
i32.const 8
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -1572,7 +1572,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 72
|
||||
i32.const 511
|
||||
i32.const 516
|
||||
i32.const 8
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -1651,7 +1651,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 72
|
||||
i32.const 523
|
||||
i32.const 528
|
||||
i32.const 8
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -1706,7 +1706,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 72
|
||||
i32.const 532
|
||||
i32.const 537
|
||||
i32.const 4
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -2008,7 +2008,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 72
|
||||
i32.const 507
|
||||
i32.const 512
|
||||
i32.const 8
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -2062,7 +2062,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 72
|
||||
i32.const 511
|
||||
i32.const 516
|
||||
i32.const 8
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -2157,7 +2157,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 72
|
||||
i32.const 523
|
||||
i32.const 528
|
||||
i32.const 8
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -2220,7 +2220,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 72
|
||||
i32.const 532
|
||||
i32.const 537
|
||||
i32.const 4
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,10 @@ assert(changetype<usize>(str) == changetype<usize>("hi, I'm a string"));
|
||||
assert(str.length == 16);
|
||||
assert(str.charCodeAt(0) == 0x68);
|
||||
|
||||
assert(!!"" == false);
|
||||
assert(!!"\0" == true);
|
||||
assert(!!"a" == true);
|
||||
|
||||
assert(String.fromCharCode(0) == "\0");
|
||||
assert(String.fromCharCode(54) == "6");
|
||||
assert(String.fromCharCode(0x10000 + 54) == "6");
|
||||
@ -222,8 +226,8 @@ assert(utoa64(u64.MAX_VALUE) == "18446744073709551615");
|
||||
|
||||
assert(itoa64(0) == "0");
|
||||
assert(itoa64(-1234) == "-1234");
|
||||
assert(itoa64(0xffffffff) == "4294967295");
|
||||
assert(itoa64(-0xffffffff) == "-4294967295");
|
||||
assert(itoa64(0xffffffff) == "4294967295");
|
||||
assert(itoa64(-0xffffffff) == "-4294967295");
|
||||
assert(itoa64(68719476735) == "68719476735");
|
||||
assert(itoa64(-68719476735) == "-68719476735");
|
||||
assert(itoa64(-868719476735) == "-868719476735");
|
||||
@ -233,13 +237,13 @@ assert(itoa64(i64.MAX_VALUE) == "9223372036854775807");
|
||||
assert(itoa64(i64.MIN_VALUE) == "-9223372036854775808");
|
||||
|
||||
// special cases
|
||||
assert(dtoa(0.0) == "0.0");
|
||||
assert(dtoa(0.0) == "0.0");
|
||||
assert(dtoa(-0.0) == "0.0");
|
||||
assert(dtoa(NaN) == "NaN");
|
||||
assert(dtoa(NaN) == "NaN");
|
||||
assert(dtoa(+Infinity) == "Infinity");
|
||||
assert(dtoa(-Infinity) == "-Infinity");
|
||||
assert(dtoa(+f64.EPSILON) == "2.220446049250313e-16");
|
||||
assert(dtoa(-f64.EPSILON) == "-2.220446049250313e-16");
|
||||
assert(dtoa(+f64.EPSILON) == "2.220446049250313e-16");
|
||||
assert(dtoa(-f64.EPSILON) == "-2.220446049250313e-16");
|
||||
assert(dtoa(+f64.MAX_VALUE) == "1.7976931348623157e+308");
|
||||
assert(dtoa(-f64.MAX_VALUE) == "-1.7976931348623157e+308");
|
||||
assert(dtoa(4.185580496821357e+298) == "4.185580496821357e+298");
|
||||
@ -256,44 +260,44 @@ assert(dtoa(5e-324) == "5e-324");
|
||||
// Actual: 1.2344999999999999e+21
|
||||
// assert(dtoa(1.2345e+21) == "1.2345e+21");
|
||||
|
||||
assert(dtoa(1.0) == "1.0");
|
||||
assert(dtoa(0.1) == "0.1");
|
||||
assert(dtoa(1.0) == "1.0");
|
||||
assert(dtoa(0.1) == "0.1");
|
||||
assert(dtoa(-1.0) == "-1.0");
|
||||
assert(dtoa(-0.1) == "-0.1");
|
||||
|
||||
assert(dtoa(1e+6) == "1000000.0");
|
||||
assert(dtoa(1e-6) == "0.000001");
|
||||
assert(dtoa(1e+6) == "1000000.0");
|
||||
assert(dtoa(1e-6) == "0.000001");
|
||||
assert(dtoa(-1e+6) == "-1000000.0");
|
||||
assert(dtoa(-1e-6) == "-0.000001");
|
||||
assert(dtoa(1e+7) == "10000000.0");
|
||||
assert(dtoa(1e-7) == "1e-7");
|
||||
assert(dtoa(1e+7) == "10000000.0");
|
||||
assert(dtoa(1e-7) == "1e-7");
|
||||
|
||||
assert(dtoa(1e+308) == "1e+308");
|
||||
assert(dtoa(1e+308) == "1e+308");
|
||||
assert(dtoa(-1e+308) == "-1e+308");
|
||||
assert(dtoa(1e+309) == "Infinity");
|
||||
assert(dtoa(1e+309) == "Infinity");
|
||||
assert(dtoa(-1e+309) == "-Infinity");
|
||||
assert(dtoa(1e-308) == "1e-308");
|
||||
assert(dtoa(1e-308) == "1e-308");
|
||||
assert(dtoa(-1e-308) == "-1e-308");
|
||||
assert(dtoa(1e-323) == "1e-323");
|
||||
assert(dtoa(1e-323) == "1e-323");
|
||||
assert(dtoa(-1e-323) == "-1e-323");
|
||||
assert(dtoa(1e-324) == "0.0");
|
||||
assert(dtoa(1e-324) == "0.0");
|
||||
|
||||
assert(dtoa(4294967272) == "4294967272.0");
|
||||
assert(dtoa(1.23121456734562345678e-8) == "1.2312145673456234e-8");
|
||||
// assert(dtoa(-0.0000010471975511965976) == "-0.0000010471975511965976"); // FIXME
|
||||
assert(dtoa(555555555.55555555) == "555555555.5555556");
|
||||
assert(dtoa(0.9999999999999999) == "0.9999999999999999");
|
||||
assert(dtoa(555555555.55555555) == "555555555.5555556");
|
||||
assert(dtoa(0.9999999999999999) == "0.9999999999999999");
|
||||
assert(dtoa(0.99999999999999995) == "1.0");
|
||||
assert(dtoa(1234e-2) == "12.34");
|
||||
assert(dtoa(1234e-2) == "12.34");
|
||||
// assert(dtoa(0.1 + 0.2) == "0.30000000000000004"); // FIXME
|
||||
assert(dtoa(1.0 / 3.0) == "0.3333333333333333");
|
||||
assert(dtoa(1.234e+20) == "123400000000000000000.0");
|
||||
assert(dtoa(1.234e+21) == "1.234e+21");
|
||||
assert(dtoa(2.71828) == "2.71828");
|
||||
assert(dtoa(2.71828e-2) == "0.0271828");
|
||||
assert(dtoa(2.71828e+2) == "271.828");
|
||||
assert(dtoa(1.1e+128) == "1.1e+128");
|
||||
assert(dtoa(1.1e-64) == "1.1e-64");
|
||||
assert(dtoa(1.0 / 3.0) == "0.3333333333333333");
|
||||
assert(dtoa(1.234e+20) == "123400000000000000000.0");
|
||||
assert(dtoa(1.234e+21) == "1.234e+21");
|
||||
assert(dtoa(2.71828) == "2.71828");
|
||||
assert(dtoa(2.71828e-2) == "0.0271828");
|
||||
assert(dtoa(2.71828e+2) == "271.828");
|
||||
assert(dtoa(1.1e+128) == "1.1e+128");
|
||||
assert(dtoa(1.1e-64) == "1.1e-64");
|
||||
assert(dtoa(0.000035689) == "0.000035689");
|
||||
|
||||
// assert(dtoa(f32.MAX_VALUE) == "3.4028234663852886e+38"); // FIXME
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user