1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

jsdom, js: start refactoring jsdom; improve JS interfaces; add two attributes for them (#12488)

This commit is contained in:
playX
2021-11-17 12:41:33 +03:00
committed by GitHub
parent 6ac109a7c3
commit 2eb02ff5a7
28 changed files with 282 additions and 1812 deletions

View File

@ -397,3 +397,11 @@ pub fn (a []string) str() string {
res := sb.str()
return res
}
pub fn (a array) to_js_array() JS.Array {
tmp := JS.Array.prototype.constructor()
for i in 0 .. a.len {
tmp.push(a.arr.get(i))
}
return tmp
}

View File

@ -9,14 +9,17 @@ module builtin
pub interface JS.Object {}
[single_impl]
pub interface JS.BigInt {
JS.Any
}
[single_impl]
pub interface JS.Number {
JS.Any
}
[single_impl]
pub interface JS.String {
JS.Any
length JS.Number
@ -34,8 +37,10 @@ pub interface JS.String {
lastIndexOf(needle JS.String) JS.Number
}
[single_impl]
pub interface JS.Boolean {
JS.Any
length JS.Number
}
pub interface JS.Map {

View File

@ -17,7 +17,7 @@ pub fn (s string) runes() []rune {
}
pub fn (s string) slice(a int, b int) string {
return string(s.str.slice(a, b))
return string(s.str.slice(JS.Number(a), JS.Number(b)))
}
pub fn (s string) substr(start int, end int) string {
@ -88,7 +88,7 @@ pub fn (s string) split(dot string) []string {
pub fn (s string) bytes() []byte {
sep := ''
tmparr := s.str.split(sep.str).map(fn (it JS.Any) JS.Any {
return JS.Any(byte(JS.String(it).charCodeAt(0)))
return JS.Any(byte(JS.String(it).charCodeAt(JS.Number(0))))
})
_ := tmparr
mut arr := []byte{}
@ -98,8 +98,8 @@ pub fn (s string) bytes() []byte {
}
pub fn (s string) capitalize() string {
part := string(s.str.slice(1, int(s.str.length)))
return string(s.str.charAt(0).toUpperCase().concat(part.str))
part := string(s.str.slice(JS.Number(1), s.str.length))
return string(s.str.charAt(JS.Number(0)).toUpperCase().concat(part.str))
}
pub fn (s string) clone() string {