diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-07-06 11:20:35 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-07-06 12:22:11 -0400 |
commit | fe404dfce901356dc7a5d38ba70029c72a946f27 (patch) | |
tree | b8ed0d3417e920da1fd4e6278046184d8205a237 /js/os.ts | |
parent | 21e1425656ccebb8d31da95acd83991fb7d728fd (diff) |
Import ts file from prototype without change
From commit 559453cf6cc88283bcf8fdeccd387458f5c63165
Excluding v8worker.d.ts, main.ts, and deno.d.ts.
Updates tslint.json to be original settings.
Diffstat (limited to 'js/os.ts')
-rw-r--r-- | js/os.ts | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/js/os.ts b/js/os.ts new file mode 100644 index 000000000..a51c6ec5d --- /dev/null +++ b/js/os.ts @@ -0,0 +1,65 @@ +// Copyright 2018 Ryan Dahl <ry@tinyclouds.org> +// All rights reserved. MIT License. +import { ModuleInfo } from "./types"; +import { pubInternal } from "./dispatch"; +import { deno as pb } from "./msg.pb"; +import { assert } from "./util"; + +export function exit(exitCode = 0): void { + pubInternal("os", { + command: pb.Msg.Command.EXIT, + exitCode + }); +} + +export function codeFetch( + moduleSpecifier: string, + containingFile: string +): ModuleInfo { + const res = pubInternal("os", { + command: pb.Msg.Command.CODE_FETCH, + codeFetchModuleSpecifier: moduleSpecifier, + codeFetchContainingFile: containingFile + }); + assert(res.command === pb.Msg.Command.CODE_FETCH_RES); + return { + moduleName: res.codeFetchResModuleName, + filename: res.codeFetchResFilename, + sourceCode: res.codeFetchResSourceCode, + outputCode: res.codeFetchResOutputCode + }; +} + +export function codeCache( + filename: string, + sourceCode: string, + outputCode: string +): void { + pubInternal("os", { + command: pb.Msg.Command.CODE_CACHE, + codeCacheFilename: filename, + codeCacheSourceCode: sourceCode, + codeCacheOutputCode: outputCode + }); +} + +export function readFileSync(filename: string): Uint8Array { + const res = pubInternal("os", { + command: pb.Msg.Command.READ_FILE_SYNC, + readFileSyncFilename: filename + }); + return res.readFileSyncData; +} + +export function writeFileSync( + filename: string, + data: Uint8Array, + perm: number +): void { + pubInternal("os", { + command: pb.Msg.Command.WRITE_FILE_SYNC, + writeFileSyncFilename: filename, + writeFileSyncData: data, + writeFileSyncPerm: perm + }); +} |