diff --git a/app/current/src/main/scala/io/scalajs/nodejs/buffer/Buffer.scala b/app/current/src/main/scala/io/scalajs/nodejs/buffer/Buffer.scala index 5023bb7bc..18bec8963 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/buffer/Buffer.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/buffer/Buffer.scala @@ -784,33 +784,30 @@ class Buffer private[this] () extends Uint8Array( /* dummy to trick constructor * @see https://nodejs.org/api/buffer.html#buffer_buf_readbiguint64be_offset */ @enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12) - def readBigInt64BE(offset: Int = js.native): Buffer.UnsafeBigInt = js.native + def readBigInt64BE(offset: Int = js.native): scalajs.js.BigInt = js.native /** * @see https://nodejs.org/api/buffer.html#buffer_buf_readbiguint64le_offset */ @enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12) - def readBigUInt64LE(offset: Int = js.native): Buffer.UnsafeBigInt = js.native + def readBigUInt64LE(offset: Int = js.native): scalajs.js.BigInt = js.native /** * @see https://nodejs.org/api/buffer.html#buffer_buf_writebigint64be_value_offset */ @enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12) - def writeBigInt64BE(value: Buffer.UnsafeBigInt, offset: Int = js.native): Int = js.native + def writeBigInt64BE(value: scalajs.js.BigInt, offset: Int = js.native): Int = js.native /** * @see https://nodejs.org/api/buffer.html#buffer_buf_writebigint64le_value_offset */ @enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12) - def writeBigInt64LE(value: Buffer.UnsafeBigInt, offset: Int = js.native): Int = js.native + def writeBigInt64LE(value: scalajs.js.BigInt, offset: Int = js.native): Int = js.native } @js.native @JSGlobal object Buffer extends js.Object { - // TODO: Node.js added BigInt-related things (e.g. readBigInt64BE). Should support when Scala.js support it - type UnsafeBigInt = js.Dynamic - ///////////////////////////////////////////////////////////////////////////////// // Properties ///////////////////////////////////////////////////////////////////////////////// diff --git a/app/current/src/main/scala/io/scalajs/nodejs/fs/Fs.scala b/app/current/src/main/scala/io/scalajs/nodejs/fs/Fs.scala index ca532a28d..a0486981e 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/fs/Fs.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/fs/Fs.scala @@ -285,14 +285,14 @@ trait Fs extends IEventEmitter with FSConstants { */ def fstat(fd: FileDescriptor, callback: FsCallback1[Stats]): Unit = js.native - def fstat(fd: FileDescriptor, options: StatOptions, callback: FsCallback1[Stats]): Unit = js.native + def fstat(fd: FileDescriptor, options: StatOptions, callback: FsCallback1[StatsVariant]): Unit = js.native /** * Synchronous fstat(2). * @param fd the file descriptor * @return an instance of [[fs.Stats]]. */ - def fstatSync(fd: FileDescriptor, options: StatOptions = js.native): Stats = js.native + def fstatSync(fd: FileDescriptor, options: StatOptions = js.native): StatsVariant = js.native /** * Asynchronous fsync(2). No arguments other than a possible exception are given to the completion callback. @@ -399,7 +399,7 @@ trait Fs extends IEventEmitter with FSConstants { */ def linkSync(existingPath: Path, newPath: Path): Unit = js.native - def lstat(path: Path, options: StatOptions, callback: FsCallback1[Stats]): Unit = js.native + def lstat(path: Path, options: StatOptions, callback: FsCallback1[StatsVariant]): Unit = js.native /** * Asynchronous lstat(2). @@ -417,7 +417,7 @@ trait Fs extends IEventEmitter with FSConstants { */ def lstatSync(path: Path): Stats = js.native - def lstatSync(path: Path, options: StatOptions): Stats = js.native + def lstatSync(path: Path, options: StatOptions): StatsVariant = js.native /** * Asynchronous mkdir(2). No arguments other than a possible exception are given to the completion callback. @@ -798,7 +798,7 @@ trait Fs extends IEventEmitter with FSConstants { */ def stat(path: Path, callback: FsCallback1[Stats]): Stats = js.native - def stat(path: Path, options: StatOptions, callback: FsCallback1[Stats]): Stats = js.native + def stat(path: Path, options: StatOptions, callback: FsCallback1[StatsVariant]): StatsVariant = js.native /** * Synchronous stat(2). Returns an instance of [[fs.Stats]]. @@ -806,7 +806,7 @@ trait Fs extends IEventEmitter with FSConstants { */ def statSync(path: Path): Stats = js.native - def statSync(path: Path, options: StatOptions): Stats = js.native + def statSync(path: Path, options: StatOptions): StatsVariant = js.native /** * Asynchronous symlink(2). No arguments other than a possible exception are given to the completion callback. @@ -1131,7 +1131,7 @@ object Fs extends Fs { def lchmod(path: Path, mode: FileMode): js.Promise[Unit] = js.native def lchown(path: Path, uid: UID, gid: GID): js.Promise[Unit] = js.native def link(existingPath: Path, newPath: Path): js.Promise[Unit] = js.native - def lstat(path: Path, options: StatOptions): js.Promise[Stats] = js.native + def lstat(path: Path, options: StatOptions): js.Promise[StatsVariant] = js.native def mkdir(path: Path, options: MkdirOptions = js.native): js.Promise[Unit] = js.native def mkdir(path: Path, mode: FileMode): js.Promise[Unit] = js.native def mkdtemp(prefix: String, options: FileEncodingOptions): js.Promise[String] = js.native @@ -1147,7 +1147,7 @@ object Fs extends Fs { def rmdir(path: Path): js.Promise[Unit] = js.native @enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12) def rmdir(path: Path, options: RmdirOptions): js.Promise[Unit] = js.native - def stat(path: Path, options: StatOptions = js.native): js.Promise[Stats] = js.native + def stat(path: Path, options: StatOptions = js.native): js.Promise[StatsVariant] = js.native def symlink(target: Path, path: Path, `type`: String = js.native): js.Promise[Unit] = js.native def truncate(path: Path, length: Int = js.native): js.Promise[Unit] = js.native def unlink(path: Path): js.Promise[Unit] = js.native @@ -1173,7 +1173,7 @@ object Fs extends Fs { def readFile(encoding: String): js.Promise[String] = js.native def readFile(options: ReadFileOptions): js.Promise[Output] = js.native def stat(): js.Promise[Stats] = js.native - def stat(options: StatOptions): js.Promise[Stats] = js.native + def stat(options: StatOptions): js.Promise[StatsVariant] = js.native def sync(): js.Promise[Unit] = js.native def truncate(): js.Promise[Unit] = js.native def truncate(length: Int): js.Promise[Unit] = js.native diff --git a/app/current/src/main/scala/io/scalajs/nodejs/fs/Stats.scala b/app/current/src/main/scala/io/scalajs/nodejs/fs/Stats.scala index 4623a02d5..1778c1442 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/fs/Stats.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/fs/Stats.scala @@ -3,74 +3,46 @@ package fs import scala.scalajs.js -/** - * fs.Stats (Stat Time Values) - Objects returned from fs.stat(), fs.lstat() and fs.fstat() and their synchronous - * counterparts are of this type. - * @example - * {{{ - * Stats { - * dev: 2114, - * ino: 48064969, - * mode: 33188, - * nlink: 1, - * uid: 85, - * gid: 100, - * rdev: 0, - * size: 527, - * blksize: 4096, - * blocks: 8, - * atimeMs: 1318289051000.1, - * mtimeMs: 1318289051000.1, - * ctimeMs: 1318289051000.1, - * birthtimeMs: 1318289051000.1, - * atime: Mon, 10 Oct 2011 23:24:11 GMT, - * mtime: Mon, 10 Oct 2011 23:24:11 GMT, - * ctime: Mon, 10 Oct 2011 23:24:11 GMT, - * birthtime: Mon, 10 Oct 2011 23:24:11 GMT - * } - * }}} - * @since 0.1.21 - */ -// TODO: BigIntStats if Scala.js added BigInt support @js.native -trait Stats extends js.Object { +trait IStats[TInt, TFloat] extends js.Object { + ///////////////////////////////////////////////////////////////////////////////// // Properties ///////////////////////////////////////////////////////////////////////////////// - def dev: Int = js.native + def dev: TInt = js.native - def ino: Double = js.native + def ino: TFloat = js.native - def mode: FileMode = js.native + def mode: TInt = js.native - def nlink: Int = js.native + def nlink: TInt = js.native - def uid: UID = js.native + def uid: TInt = js.native - def gid: GID = js.native + def gid: TInt = js.native - def rdev: Int = js.native + def rdev: TInt = js.native - def size: Double = js.native + def size: TFloat = js.native - def blksize: Int = js.native + def blksize: TInt = js.native - def blocks: Int = js.native + def blocks: TInt = js.native /** * "Access Time" - Time when file data last accessed. Changed by the mknod(2), utimes(2), and read(2) system calls. */ def atime: js.Date = js.native - def atimeMs: Double = js.native + def atimeMs: TFloat = js.native /** * "Modified Time" - Time when file data last modified. Changed by the mknod(2), utimes(2), and write(2) system calls. */ def mtime: js.Date = js.native - def mtimeMs: Double = js.native + def mtimeMs: TFloat = js.native /** * "Change Time" - Time when file status was last changed (inode data modification). Changed by the chmod(2), @@ -78,7 +50,7 @@ trait Stats extends js.Object { */ def ctime: js.Date = js.native - def ctimeMs: Double = js.native + def ctimeMs: TFloat = js.native /** * "Birth Time" - Time of file creation. Set once when the file is created. On filesystems where birthtime is not @@ -88,7 +60,7 @@ trait Stats extends js.Object { */ def birthtime: js.Date = js.native - def birthtimeMs: Double = js.native + def birthtimeMs: TFloat = js.native ///////////////////////////////////////////////////////////////////////////////// // Methods @@ -111,3 +83,75 @@ trait Stats extends js.Object { def isSocket(): Boolean = js.native } + +/** + * fs.Stats (Stat Time Values) - Objects returned from fs.stat(), fs.lstat() and fs.fstat() and their synchronous + * counterparts are of this type. + * @example + * {{{ + * Stats { + * dev: 2114, + * ino: 48064969, + * mode: 33188, + * nlink: 1, + * uid: 85, + * gid: 100, + * rdev: 0, + * size: 527, + * blksize: 4096, + * blocks: 8, + * atimeMs: 1318289051000.1, + * mtimeMs: 1318289051000.1, + * ctimeMs: 1318289051000.1, + * birthtimeMs: 1318289051000.1, + * atime: Mon, 10 Oct 2011 23:24:11 GMT, + * mtime: Mon, 10 Oct 2011 23:24:11 GMT, + * ctime: Mon, 10 Oct 2011 23:24:11 GMT, + * birthtime: Mon, 10 Oct 2011 23:24:11 GMT + * } + * }}} + * @since 0.1.21 + */ +@js.native +trait Stats extends IStats[Int, Double] + +/** + * fs.Stats (Stat Time Values) - Objects returned from fs.stat(), fs.lstat() and fs.fstat() and their synchronous + * counterparts are of this type. + * + * @example + * {{{ + * BigIntStats { + * dev: 2114n, + * ino: 48064969n, + * mode: 33188n, + * nlink: 1n, + * uid: 85n, + * gid: 100n, + * rdev: 0n, + * size: 527n, + * blksize: 4096n, + * blocks: 8n, + * atimeMs: 1318289051000n, + * mtimeMs: 1318289051000n, + * ctimeMs: 1318289051000n, + * birthtimeMs: 1318289051000n, + * atimeNs: 1318289051000000000n, + * mtimeNs: 1318289051000000000n, + * ctimeNs: 1318289051000000000n, + * birthtimeNs: 1318289051000000000n, + * atime: Mon, 10 Oct 2011 23:24:11 GMT, + * mtime: Mon, 10 Oct 2011 23:24:11 GMT, + * ctime: Mon, 10 Oct 2011 23:24:11 GMT, + * birthtime: Mon, 10 Oct 2011 23:24:11 GMT + * } + * }}} + * @since 0.1.21 + */ +@js.native +trait BigIntStats extends IStats[BigInt, BigInt] { + def atimeNs: BigInt = js.native + def mtimeNs: BigInt = js.native + def ctimeNs: BigInt = js.native + def birthtimeNs: BigInt = js.native +} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/fs/package.scala b/app/current/src/main/scala/io/scalajs/nodejs/fs/package.scala index c0a5a81d3..fb323d17d 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/fs/package.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/fs/package.scala @@ -24,6 +24,8 @@ package object fs { type Dirent = Fs.Dirent + type StatsVariant = Stats | BigIntStats + ///////////////////////////////////////////////////////////////////////////////// // Implicit conversions and classes ///////////////////////////////////////////////////////////////////////////////// @@ -89,8 +91,8 @@ package object fs { def fdatasyncFuture(fd: FileDescriptor): Future[Unit] = promiseWithError0[FileIOError](instance.fdatasync(fd, _)) @inline - def fstatFuture(fd: FileDescriptor, options: StatOptions): Future[Stats] = { - promiseWithError1[FileIOError, Stats](instance.fstat(fd, options, _)) + def fstatFuture(fd: FileDescriptor, options: StatOptions): Future[StatsVariant] = { + promiseWithError1[FileIOError, StatsVariant](instance.fstat(fd, options, _)) } @inline @@ -129,8 +131,8 @@ package object fs { } @inline - def lstatFuture(path: Path, options: StatOptions): Future[Stats] = { - promiseWithError1[FileIOError, Stats](instance.lstat(path, options, _)) + def lstatFuture(path: Path, options: StatOptions): Future[StatsVariant] = { + promiseWithError1[FileIOError, StatsVariant](instance.lstat(path, options, _)) } @inline @@ -324,8 +326,8 @@ package object fs { def statFuture(path: Path): Future[Stats] = promiseWithError1[FileIOError, Stats](instance.stat(path, _)) @inline - def statFuture(path: Path, options: StatOptions): Future[Stats] = { - promiseWithError1[FileIOError, Stats](instance.stat(path, options, _)) + def statFuture(path: Path, options: StatOptions): Future[StatsVariant] = { + promiseWithError1[FileIOError, StatsVariant](instance.stat(path, options, _)) } @inline diff --git a/app/current/src/main/scala/io/scalajs/nodejs/process/Process.scala b/app/current/src/main/scala/io/scalajs/nodejs/process/Process.scala index f697fd312..372f3132d 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/process/Process.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/process/Process.scala @@ -480,8 +480,7 @@ class WarningOptions( @js.native trait HrTime extends js.Function1[js.Array[Int], js.Array[Int]] with js.Function0[js.Array[Int]] { - // TODO: js.BigInt - def bigint(): js.Any = js.native + def bigint(): js.BigInt = js.native } @enableMembersIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12) diff --git a/app/current/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala b/app/current/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala index 292110d8f..e7dac910b 100644 --- a/app/current/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala +++ b/app/current/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala @@ -1,6 +1,5 @@ package io.scalajs.nodejs.buffer -import io.scalajs.nodejs.buffer.Buffer import org.scalatest.FunSpec import scala.scalajs.js @@ -11,7 +10,7 @@ import scala.scalajs.js class BufferTest extends FunSpec { it("should support writeBigInt64BE, writeBigInt64LE, writeBigInt64BE and writeBigInt64BE") { val buf = Buffer.allocUnsafe(8) - val v = js.Dynamic.global.BigInt("0x0102030405060708") + val v = js.BigInt("0x0102030405060708") buf.writeBigInt64BE(v, 0); assert(Buffer.compare(buf, Buffer.from(js.Array(1, 2, 3, 4, 5, 6, 7, 8))) === 0) } diff --git a/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/process/ProcessTest.scala b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/process/ProcessTest.scala index 520c2964c..6eba4f1e4 100644 --- a/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/process/ProcessTest.scala +++ b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/process/ProcessTest.scala @@ -43,7 +43,6 @@ class ProcessTest extends FunSpec { } it("hrtime.bigint") { - // TODO: js.BigInt val value = Process.hrtime.bigint() assert(value.toString().matches("^\\d+$")) }