summary refs log tree commit diff stats
path: root/lib/js
Commit message (Expand)AuthorAgeFilesLines
* Add StorageEvent and correct Storage object (#16865)Antonis Geralis2021-01-291-8/+18
* js: improve tests + some docs (#16727)Timothee Cour2021-01-161-0/+1
* clean up the docs of some modules under lib/js (#16579)flywind2021-01-047-55/+55
* big steps torwards an efficient, simple IC implementation (#16543)Andreas Rumpf2021-01-021-2/+2
* Add assertions for jsconsole (#16460)Juan Carlos2020-12-301-1/+33
* styleCheck: Fix some inconsistent identifiers (#16177)ee72020-12-212-7/+7
* Fix broken links in docs (#16336)Elliot Waite2020-12-141-1/+1
* add math.isNaN (#16179)Timothee Cour2020-12-111-0/+1
* js module also uses runnableExamples (#16229)flywind2020-12-022-40/+32
* add `**` to jsffi (#16141)flywind2020-11-261-0/+1
* Add documentElement to Document. (#15943)treeform2020-11-131-0/+1
* add parent property to window in dom.nim (#15922)Bung2020-11-121-0/+1
* proc params as syms (#15332)cooldome2020-09-161-1/+9
* dom.Navigator add missing attributes (#15310)Juan Carlos2020-09-141-1/+16
* Fix #15183 (#15300)Juan Carlos2020-09-111-10/+13
* jsre: try to fix nightlies (#15057)Miran2020-07-241-0/+3
* Shadow Dom apis (#14979)Bung2020-07-212-0/+37
* add missing props,procs (#14978)Bung2020-07-141-0/+12
* Add missing dom.nim things (#14944)treeform2020-07-091-2/+30
* Add jsre (#14870)Juan Carlos2020-07-031-0/+43
* Clean out dom (#14855)Juan Carlos2020-06-301-4/+0
* Add all missing css properties to dom.nim. (#14825)treeform2020-06-261-4/+270
* Add hasAttribute method to dom.nim. (#14814)treeform2020-06-251-0/+1
* Export fields from the Selection object. (#14752)treeform2020-06-211-0/+7
* Add css white-space property to dom.nim. (#14743)treeform2020-06-211-0/+1
* Add clipPath to dom.nim. (#14435)treeform2020-05-241-1/+2
* Add missing attributes and methods to JavaScript DOM (#14428)Mildred Ki'Lya2020-05-221-0/+14
* fixes a bug reported in https://forum.nim-lang.org/t/6361 (#14422)Andreas Rumpf2020-05-211-31/+31
* move since from inclrtl to std/private/since (#14188)hlaaftana2020-05-021-1/+1
* add FileReader Web API to js dom (#14105)cooldome2020-04-271-9/+59
* Fixes #14110 (#14111)Jae Yang2020-04-251-1/+1
* changed type() to typeof() in docs and error messages (#14084)hlaaftana2020-04-241-1/+1
* Fix the getSelection method. (#13632)treeform2020-04-211-1/+8
* fix newDomParser (#13981)Timothee Cour2020-04-161-1/+1
* Add jsdomparser (#13920)Juan Carlos2020-04-131-1/+18
* Jsconsole update (#12448)Juan Carlos2020-04-021-35/+36
* Add more JS stuff to dom.nim (#13483)treeform2020-03-111-26/+45
* scrollTop must be settable (#13263)Jairo2020-01-271-0/+1
* Add "origin" to window.location (#13251)Jairo2020-01-241-0/+1
* Fix many broken linksJjp1372019-10-222-2/+2
* Improve jsconsole adding the rest of the stable api as documented on the stan...Juan Carlos2019-10-171-1/+26
* JS: gensym is stricter for 'this'; refs #12246 [backport]Araq2019-09-301-1/+1
* importjs symbol (#12218)Arne Döring2019-09-201-4/+4
* fix failing JS testsnarimiran2019-07-221-1/+0
* Add `opacity` to JS `Style`Benjamin Summerton2019-07-211-0/+2
* libffi: style changesAraq2019-06-191-50/+50
* Fix header inconsistencies in documentation (#11071)Zed2019-04-231-1/+1
* some dom proc correction and complement (#10684)liuxiaodong2019-02-151-4/+9
* DOM module: re-add more missing stuffAraq2019-02-081-1/+36
* DOM module: add more missing stuffAraq2019-02-071-0/+3
an class="p">, floor, ceil, `mod`, cbrt, arcsinh, arccosh, arctanh, erf, erfc, gamma, lgamma when declared(math.copySign): from math import copySign when declared(math.signbit): from math import signbit from os import getEnv, existsEnv, dirExists, fileExists, putEnv, walkDir, getAppFilename, raiseOSError, osLastError from md5 import getMD5 from times import cpuTime from hashes import hash from osproc import nil from sighashes import symBodyDigest # There are some useful procs in vmconv. import vmconv template mathop(op) {.dirty.} = registerCallback(c, "stdlib.math." & astToStr(op), `op Wrapper`) template osop(op) {.dirty.} = registerCallback(c, "stdlib.os." & astToStr(op), `op Wrapper`) template timesop(op) {.dirty.} = registerCallback(c, "stdlib.times." & astToStr(op), `op Wrapper`) template systemop(op) {.dirty.} = registerCallback(c, "stdlib.system." & astToStr(op), `op Wrapper`) template ioop(op) {.dirty.} = registerCallback(c, "stdlib.io." & astToStr(op), `op Wrapper`) template macrosop(op) {.dirty.} = registerCallback(c, "stdlib.macros." & astToStr(op), `op Wrapper`) template md5op(op) {.dirty.} = registerCallback(c, "stdlib.md5." & astToStr(op), `op Wrapper`) template wrap1f_math(op) {.dirty.} = proc `op Wrapper`(a: VmArgs) {.nimcall.} = doAssert a.numArgs == 1 setResult(a, op(getFloat(a, 0))) mathop op template wrap2f_math(op) {.dirty.} = proc `op Wrapper`(a: VmArgs) {.nimcall.} = setResult(a, op(getFloat(a, 0), getFloat(a, 1))) mathop op template wrap0(op, modop) {.dirty.} = proc `op Wrapper`(a: VmArgs) {.nimcall.} = setResult(a, op()) modop op template wrap1s(op, modop) {.dirty.} = proc `op Wrapper`(a: VmArgs) {.nimcall.} = setResult(a, op(getString(a, 0))) modop op template wrap2s(op, modop) {.dirty.} = proc `op Wrapper`(a: VmArgs) {.nimcall.} = setResult(a, op(getString(a, 0), getString(a, 1))) modop op template wrap2si(op, modop) {.dirty.} = proc `op Wrapper`(a: VmArgs) {.nimcall.} = setResult(a, op(getString(a, 0), getInt(a, 1))) modop op template wrap1svoid(op, modop) {.dirty.} = proc `op Wrapper`(a: VmArgs) {.nimcall.} = op(getString(a, 0)) modop op template wrap2svoid(op, modop) {.dirty.} = proc `op Wrapper`(a: VmArgs) {.nimcall.} = op(getString(a, 0), getString(a, 1)) modop op template wrapDangerous(op, modop) {.dirty.} = if vmopsDanger notin c.config.features and (defined(nimsuggest) or c.config.cmd == cmdCheck): proc `op Wrapper`(a: VmArgs) {.nimcall.} = discard modop op else: proc `op Wrapper`(a: VmArgs) {.nimcall.} = op(getString(a, 0), getString(a, 1)) modop op proc getCurrentExceptionMsgWrapper(a: VmArgs) {.nimcall.} = setResult(a, if a.currentException.isNil: "" else: a.currentException[3].skipColon.strVal) proc getCurrentExceptionWrapper(a: VmArgs) {.nimcall.} = setResult(a, a.currentException) proc staticWalkDirImpl(path: string, relative: bool): PNode = result = newNode(nkBracket) for k, f in walkDir(path, relative): result.add toLit((k, f)) when defined(nimHasInvariant): from std / compilesettings import SingleValueSetting, MultipleValueSetting proc querySettingImpl(conf: ConfigRef, switch: BiggestInt): string = case SingleValueSetting(switch) of arguments: result = conf.arguments of outFile: result = conf.outFile.string of outDir: result = conf.outDir.string of nimcacheDir: result = conf.getNimcacheDir().string of projectName: result = conf.projectName of projectPath: result = conf.projectPath.string of projectFull: result = conf.projectFull.string of command: result = conf.command of commandLine: result = conf.commandLine of linkOptions: result = conf.linkOptions of compileOptions: result = conf.compileOptions of ccompilerPath: result = conf.cCompilerPath of backend: result = $conf.backend of libPath: result = conf.libpath.string proc querySettingSeqImpl(conf: ConfigRef, switch: BiggestInt): seq[string] = template copySeq(field: untyped): untyped = for i in field: result.add i.string case MultipleValueSetting(switch) of nimblePaths: copySeq(conf.nimblePaths) of searchPaths: copySeq(conf.searchPaths) of lazyPaths: copySeq(conf.lazyPaths) of commandArgs: result = conf.commandArgs of cincludes: copySeq(conf.cIncludes) of clibs: copySeq(conf.cLibs) proc registerAdditionalOps*(c: PCtx) = proc gorgeExWrapper(a: VmArgs) = let ret = opGorge(getString(a, 0), getString(a, 1), getString(a, 2), a.currentLineInfo, c.config) setResult a, ret.toLit proc getProjectPathWrapper(a: VmArgs) = setResult a, c.config.projectPath.string wrap1f_math(sqrt) wrap1f_math(cbrt) wrap1f_math(ln) wrap1f_math(log10) wrap1f_math(log2) wrap1f_math(exp) wrap1f_math(arccos) wrap1f_math(arcsin) wrap1f_math(arctan) wrap1f_math(arcsinh) wrap1f_math(arccosh) wrap1f_math(arctanh) wrap2f_math(arctan2) wrap1f_math(cos) wrap1f_math(cosh) wrap2f_math(hypot) wrap1f_math(sinh) wrap1f_math(sin) wrap1f_math(tan) wrap1f_math(tanh) wrap2f_math(pow) wrap1f_math(trunc) wrap1f_math(floor) wrap1f_math(ceil) wrap1f_math(erf) wrap1f_math(erfc) wrap1f_math(gamma) wrap1f_math(lgamma) when declared(copySign): wrap2f_math(copySign) when declared(signbit): wrap1f_math(signbit) registerCallback c, "stdlib.math.round", proc (a: VmArgs) {.nimcall.} = let n = a.numArgs case n of 1: setResult(a, round(getFloat(a, 0))) of 2: setResult(a, round(getFloat(a, 0), getInt(a, 1).int)) else: doAssert false, $n wrap1s(getMD5, md5op) proc `mod Wrapper`(a: VmArgs) {.nimcall.} = setResult(a, `mod`(getFloat(a, 0), getFloat(a, 1))) registerCallback(c, "stdlib.math.mod", `mod Wrapper`) when defined(nimcore): wrap2s(getEnv, osop) wrap1s(existsEnv, osop) wrap2svoid(putEnv, osop) wrap1s(dirExists, osop) wrap1s(fileExists, osop) wrapDangerous(writeFile, ioop) wrap1s(readFile, ioop) wrap2si(readLines, ioop) systemop getCurrentExceptionMsg systemop getCurrentException registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} = setResult(a, staticWalkDirImpl(getString(a, 0), getBool(a, 1))) when defined(nimHasInvariant): registerCallback c, "stdlib.compilesettings.querySetting", proc (a: VmArgs) = setResult(a, querySettingImpl(c.config, getInt(a, 0))) registerCallback c, "stdlib.compilesettings.querySettingSeq", proc (a: VmArgs) = setResult(a, querySettingSeqImpl(c.config, getInt(a, 0))) if defined(nimsuggest) or c.config.cmd == cmdCheck: discard "don't run staticExec for 'nim suggest'" else: systemop gorgeEx macrosop getProjectPath registerCallback c, "stdlib.os.getCurrentCompilerExe", proc (a: VmArgs) {.nimcall.} = setResult(a, getAppFilename()) registerCallback c, "stdlib.macros.symBodyHash", proc (a: VmArgs) = let n = getNode(a, 0) if n.kind != nkSym: stackTrace(c, PStackFrame(prc: c.prc.sym, comesFrom: 0, next: nil), c.exceptionInstr, "symBodyHash() requires a symbol. '" & $n & "' is of kind '" & $n.kind & "'", n.info) setResult(a, $symBodyDigest(c.graph, n.sym)) registerCallback c, "stdlib.macros.isExported", proc(a: VmArgs) = let n = getNode(a, 0) if n.kind != nkSym: stackTrace(c, PStackFrame(prc: c.prc.sym, comesFrom: 0, next: nil), c.exceptionInstr, "isExported() requires a symbol. '" & $n & "' is of kind '" & $n.kind & "'", n.info) setResult(a, sfExported in n.sym.flags) proc hashVmImpl(a: VmArgs) = var res = hashes.hash(a.getString(0), a.getInt(1).int, a.getInt(2).int) if c.config.backend == backendJs: # emulate JS's terrible integers: res = cast[int32](res) setResult(a, res) registerCallback c, "stdlib.hashes.hashVmImpl", hashVmImpl proc hashVmImplByte(a: VmArgs) = # nkBracket[...] let sPos = a.getInt(1).int let ePos = a.getInt(2).int let arr = a.getNode(0) var bytes = newSeq[byte](arr.len) for i in 0..<arr.len: bytes[i] = byte(arr[i].intVal and 0xff) var res = hashes.hash(bytes, sPos, ePos) if c.config.backend == backendJs: # emulate JS's terrible integers: res = cast[int32](res) setResult(a, res) registerCallback c, "stdlib.hashes.hashVmImplByte", hashVmImplByte registerCallback c, "stdlib.hashes.hashVmImplChar", hashVmImplByte if optBenchmarkVM in c.config.globalOptions or vmopsDanger in c.config.features: wrap0(cpuTime, timesop) else: proc cpuTime(): float = 5.391245e-44 # Randomly chosen wrap0(cpuTime, timesop) if vmopsDanger in c.config.features: ## useful procs but these should be opt-in because they may impact ## reproducible builds and users need to understand that this runs at CT. ## Note that `staticExec` can already do equal amount of damage so it's more ## of a semantic issue than a security issue. registerCallback c, "stdlib.os.getCurrentDir", proc (a: VmArgs) {.nimcall.} = setResult(a, os.getCurrentDir()) registerCallback c, "stdlib.osproc.execCmdEx", proc (a: VmArgs) {.nimcall.} = let options = getNode(a, 1).fromLit(set[osproc.ProcessOption]) a.setResult osproc.execCmdEx(getString(a, 0), options).toLit registerCallback c, "stdlib.times.getTime", proc (a: VmArgs) {.nimcall.} = setResult(a, times.getTime().toLit) proc getEffectList(c: PCtx; a: VmArgs; effectIndex: int) = let fn = getNode(a, 0) if fn.typ != nil and fn.typ.n != nil and fn.typ.n[0].len >= effectListLen and fn.typ.n[0][effectIndex] != nil: var list = newNodeI(nkBracket, fn.info) for e in fn.typ.n[0][effectIndex]: list.add opMapTypeInstToAst(c.cache, e.typ.skipTypes({tyRef}), e.info, c.idgen) setResult(a, list) registerCallback c, "stdlib.effecttraits.getRaisesListImpl", proc (a: VmArgs) = getEffectList(c, a, exceptionEffects) registerCallback c, "stdlib.effecttraits.getTagsListImpl", proc (a: VmArgs) = getEffectList(c, a, tagEffects) registerCallback c, "stdlib.effecttraits.isGcSafeImpl", proc (a: VmArgs) = let fn = getNode(a, 0) setResult(a, fn.typ != nil and tfGcSafe in fn.typ.flags) registerCallback c, "stdlib.effecttraits.hasNoSideEffectsImpl", proc (a: VmArgs) = let fn = getNode(a, 0) setResult(a, (fn.typ != nil and tfNoSideEffect in fn.typ.flags) or (fn.kind == nkSym and fn.sym.kind == skFunc)) registerCallback c, "stdlib.typetraits.hasClosureImpl", proc (a: VmArgs) = let fn = getNode(a, 0) setResult(a, fn.kind == nkClosure or (fn.typ != nil and fn.typ.callConv == ccClosure))