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

jsgen: fixes and improvements

This commit is contained in:
spaceface777
2020-06-20 13:22:49 +02:00
committed by GitHub
parent ddd83f1fc6
commit a02aff9126
23 changed files with 376 additions and 1364 deletions

View File

@@ -4,13 +4,40 @@
module builtin
fn JS.console.log(arg ...string)
fn JS.process.stdout.write(arg string)
pub fn println(s any) {
JS.console.log(s)
}
pub fn print(s any) {
JS.process.stdout.write(s)
// TODO
// $if js.node {
JS.process.stdout.write(s)
// } $else {
// panic('Cannot `print` in a browser, use `println` instead')
// }
}
pub fn eprintln(s any) {
JS.console.error(s)
}
pub fn eprint(s any) {
// TODO
// $if js.node {
JS.process.stderr.write(s)
// } $else {
// panic('Cannot `eprint` in a browser, use `eprintln` instead')
// }
}
// Exits the process in node, and halts execution in the browser
// because `process.exit` is undefined. Workaround for not having
// a 'real' way to exit in the browser.
pub fn exit(c int) {
JS.process.exit(c)
}
pub fn panic(s string) {
eprintln('V panic: $s')
exit(1)
}

View File

@@ -0,0 +1,65 @@
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
// This file contains JS functions present in both node and the browser.
// They have been ported from their TypeScript definitions.
module builtin
// Top level functions
fn JS.eval(string) any
fn JS.parseInt(string, f64) f64
fn JS.parseFloat(string) f64
fn JS.isNaN(f64) bool
fn JS.isFinite(f64) bool
fn JS.decodeURI(string) string
fn JS.decodeURIComponent(string) string
fn JS.encodeURI(string) string
type EncodeURIComponentArg = string | f64 | bool
fn JS.encodeURIComponent(EncodeURIComponentArg) string
fn JS.escape(string) string
fn JS.unescape(string) string
// console
fn JS.console.assert(bool, ...any)
fn JS.console.clear()
fn JS.console.count(string)
fn JS.console.countReset(string)
fn JS.console.debug(...any)
fn JS.console.dir(any, any)
fn JS.console.dirxml(...any)
fn JS.console.error(...any)
fn JS.console.exception(string, ...any)
fn JS.console.group(...any)
fn JS.console.groupCollapsed(...any)
fn JS.console.groupEnd()
fn JS.console.info(...any)
fn JS.console.log(...any)
fn JS.console.table(any, []string)
fn JS.console.time(string)
fn JS.console.timeEnd(string)
fn JS.console.timeLog(string, ...any)
fn JS.console.timeStamp(string)
fn JS.console.trace(...any)
fn JS.console.warn(...any)
// Math
fn JS.Math.abs(f64) f64
fn JS.Math.acos(f64) f64
fn JS.Math.asin(f64) f64
fn JS.Math.atan(f64) f64
fn JS.Math.atan2(f64, f64) f64
fn JS.Math.ceil(f64) f64
fn JS.Math.cos(f64) f64
fn JS.Math.exp(f64) f64
fn JS.Math.floor(f64) f64
fn JS.Math.log(f64) f64
fn JS.Math.max(...f64) f64
fn JS.Math.min(...f64) f64
fn JS.Math.pow(f64, f64) f64
fn JS.Math.random() f64
fn JS.Math.round(f64) f64
fn JS.Math.sin(f64) f64
fn JS.Math.sqrt(f64) f64
fn JS.Math.tan(f64) f64

View File

@@ -0,0 +1,53 @@
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
// This file contains JS functions only present in the browser.
// They have been ported from their TypeScript definitions.
module builtin
// Window
fn JS.atob(string) string
fn JS.btoa(string) string
fn JS.clearInterval(int)
fn JS.clearTimeout(int)
// fn JS.createImageBitmap(ImageBitmapSource, ImageBitmapOptions) Promise<ImageBitmap>
// fn JS.createImageBitmap(ImageBitmapSource, int, int, int, int, ImageBitmapOptions) Promise<ImageBitmap>
// TODO: js async attribute
// [js_async]
// fn JS.fetch(RequestInfo, RequestInit) Promise<Response>
fn JS.queueMicrotask(fn())
fn JS.setInterval(any, int, ...any) int
fn JS.setTimeout(any, int, ...any) int
fn JS.alert(any)
fn JS.blur()
fn JS.captureEvents()
fn JS.close()
fn JS.confirm(string) bool
// fn JS.departFocus(NavigationReason, FocusNavigationOrigin)
fn JS.focus()
// fn JS.getComputedStyle(Element, string | null) CSSStyleDeclaration
// fn JS.getMatchedCSSRules(Element, string | null) CSSRuleList
// fn JS.getSelection() Selection | null
// fn JS.matchMedia(string) MediaQueryList
fn JS.moveBy(int, int)
fn JS.moveTo(int, int)
fn JS.msWriteProfilerMark(string)
// fn JS.open(string, string, string, bool) ?Window
// fn JS.postMessage(any, string, []Transferable)
fn JS.print()
fn JS.prompt(string, string) ?string
fn JS.releaseEvents()
fn JS.resizeBy(int, int)
fn JS.resizeTo(int, int)
// fn JS.scroll(ScrollToOptions)
fn JS.scroll(int, int)
//fn JS.scrollBy(ScrollToOptions)
fn JS.scrollBy(int, int)
// fn JS.scrollTo(ScrollToOptions)
fn JS.scrollTo(int, int)
fn JS.stop()

View File

@@ -0,0 +1,14 @@
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
// This file contains JS functions only present in node.js.
// They have been ported from their TypeScript definitions.
module builtin
fn JS.process.exit(int)
fn JS.process.stdout.write(string) bool
fn JS.process.stdout.writeln(string) bool
fn JS.process.stderr.write(string) bool
fn JS.process.stderr.writeln(string) bool