js: fix string.bytes codegen, readline, add tests for strings (#12060)

This commit is contained in:
playX 2021-10-04 18:28:30 +03:00 committed by GitHub
parent e94e08475d
commit 8d1ba52d0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 399 additions and 30 deletions

View file

@ -45,9 +45,9 @@ fn (mut a array_buffer) set(ix int, val voidptr) {
#array_buffer.prototype.set = function(ix,val) { array_buffer_set(this,ix,val); }
struct array {
mut:
pub mut:
arr array_buffer
pub:
len int
cap int
}
@ -67,6 +67,14 @@ fn v_sort(mut arr array, comparator fn (voidptr, voidptr) int) {
}
}
// trim trims the array length to "index" without modifying the allocated data. If "index" is greater
// than len nothing will be changed.
pub fn (mut a array) trim(index int) {
if index < a.len {
a.len = index
}
}
#function flatIntoArray(target, source, sourceLength, targetIndex, depth) {
#"use strict";
#
@ -368,7 +376,7 @@ pub fn (a &array) free() {
// todo: once (a []byte) will work rewrite this
pub fn (a array) bytestr() string {
res := ''
#a.arr.arr.forEach((item) => res.str += String.fromCharCode(+item))
#for (let i = 0;i < a.arr.len.valueOf();i++) res.str += String.fromCharCode(a.arr.get(new int(i)))
return res
}