forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
108 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { main as pb } from "./msg.pb"; | ||
import { TextDecoder } from "text-encoding"; | ||
|
||
// TODO move this to types.ts | ||
type TypedArray = Uint8Array | Float32Array | Int32Array; | ||
|
||
export function exit(code = 0): void { | ||
sendMsgFromObject({ | ||
kind: pb.Msg.MsgKind.EXIT, | ||
code | ||
}); | ||
} | ||
|
||
export function readFileSync(filename: string): string { | ||
const res = sendMsgFromObject({ | ||
kind: pb.Msg.MsgKind.READ_FILE_SYNC, | ||
path: filename | ||
}); | ||
if (res.error != null && res.error.length > 0) { | ||
throw Error(res.error); | ||
} | ||
const decoder = new TextDecoder("utf8"); | ||
return decoder.decode(res.data); | ||
} | ||
|
||
function typedArrayToArrayBuffer(ta: TypedArray): ArrayBuffer { | ||
const ab = ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength); | ||
return ab as ArrayBuffer; | ||
} | ||
|
||
function sendMsgFromObject(obj: pb.IMsg): null | pb.Msg { | ||
const msg = pb.Msg.fromObject(obj); | ||
const ui8 = pb.Msg.encode(msg).finish(); | ||
const ab = typedArrayToArrayBuffer(ui8); | ||
const resBuf = V8Worker2.send(ab); | ||
if (resBuf != null && resBuf.byteLength > 0) { | ||
return pb.Msg.decode(new Uint8Array(resBuf)); | ||
} else { | ||
return null; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { printHello } from "./subdir/print_hello.ts"; | ||
|
||
printHello(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function printHello(): void { | ||
console.log("Hello"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters