Skip to content

Commit f402c2a

Browse files
committed
impr(inner): split inDeno to jsutils/deno
1 parent 7606722 commit f402c2a

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/pylib/Lib/sys.nim

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ../pystring/strimpl
1919
const weirdTarget = defined(js) or defined(nimscript)
2020
when defined(js):
2121
import std/jsffi
22+
import ../jsutils/deno
2223
when not weirdTarget:
2324
const inFileSystemUtf8os = defined(macosx) or defined(android) or defined(vxworks)
2425
when not inFileSystemUtf8os:
@@ -220,17 +221,30 @@ else:
220221
when defined(nimscript):
221222
template executable*: PyStr = str getCurrentCompilerExe()
222223
elif defined(js):
223-
const execPathJs =
224-
when defined(nodejs): "process.execPath"
225-
else: "typeof Deno === 'undefined' ? '' : Deno.execPath()"
226-
let execPath{.importjs: execPathJs.}: cstring
227-
template executable*: PyStr =
228-
bind execPath
229-
str execPath
224+
when defined(nodejs):
225+
let execPath{.importjs: "process.execPath".}: cstring
226+
template executable*: PyStr =
227+
bind execPath
228+
str $execPath
229+
else:
230+
func getExecPath: cstring =
231+
# Deno.execPath() may ask permission,
232+
# so we only invoke it when called
233+
if inDeno:
234+
asm "`result` = Deno.execPath()"
235+
else: result = ""
236+
template executable*: PyStr =
237+
bind getExecPath
238+
str $getExecPath()
230239
else:
231240
template executable*: PyStr =
232-
## .. note:: when nimscript, this is path of `Nim`;
233-
## otherwise, it's the path of current app/exe.
241+
## returns:
242+
##
243+
## - when nimscript, path of `Nim`;
244+
## - when JavaScript:
245+
## - on browser: empty string
246+
## - on NodeJS/Deno: executable path of Node/Deno
247+
## - otherwise, it's the path of current app/exe.
234248
str getAppFilename()
235249

236250
template getsizeof*(x): int =

src/pylib/jsutils/deno.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
when defined(js):
3+
let inDeno*{.importjs: "typeof Deno === 'undefined'".}: bool
4+

0 commit comments

Comments
 (0)