v.gen.js: add more array tests and fixes (#11014)

This commit is contained in:
playX 2021-08-01 14:08:49 +03:00 committed by GitHub
parent 77e9ed417f
commit 836ac54d12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 356 additions and 15 deletions

View file

@ -87,8 +87,21 @@ pub fn (mut a array) sort_with_compare(compare voidptr) {
#a.arr.sort(compare)
}
#function $sortComparator(a, b)
#{
#"use strict";
#a = a.$toJS();
#b = b.$toJS();
#
#if (a > b) return 1;
#if (a < b) return -1;
#return 0;
#
#
#}
pub fn (mut a array) sort() {
#a.arr.sort()
#a.arr.sort($sortComparator)
}
pub fn (a array) index(v string) int {
@ -137,7 +150,7 @@ pub fn (a array) str() string {
#array.prototype[Symbol.iterator] = function () { return this.arr[Symbol.iterator](); }
#array.prototype.entries = function () { return this.arr.entries(); }
#array.prototype.map = function(callback) { return this.arr.map(callback); }
#array.prototype.map = function(callback) { return new builtin.array(this.arr.map(callback)); }
#array.prototype.filter = function(callback) { return new array(this.arr.filter( function (it) { return (+callback(it)) != 0; } )); }
#Object.defineProperty(array.prototype,'cap',{ get: function () { return this.len; } })
// delete deletes array element at index `i`.

8
vlib/builtin/js/int.js.v Normal file
View file

@ -0,0 +1,8 @@
module builtin
pub fn (i int) str() string {
mut res := ''
#res = new builtin.string( i )
return res
}

View file

@ -3,7 +3,7 @@ module builtin
pub struct string {
pub:
str JS.String
len u32
len int
}
pub fn (s string) slice(a int, b int) string {