1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

Add console.log

This commit is contained in:
Ryan Dahl 2018-05-14 01:30:56 -04:00
parent bfb3cd7a5c
commit 1a80bcb250
3 changed files with 41 additions and 4 deletions

17
main.ts
View file

@ -1,9 +1,22 @@
//import * as ts from "typescript"; //import * as ts from "typescript";
import { main as pb } from "./msg.pb" import { main as pb } from "./msg.pb"
import "./util";
function load(argv: string[]): void {
console.log("Load argv", argv);
}
V8Worker2.recv((ab: ArrayBuffer) => { V8Worker2.recv((ab: ArrayBuffer) => {
let msg = pb.Msg.decode(new Uint8Array(ab)); const msg = pb.Msg.decode(new Uint8Array(ab));
V8Worker2.print("msg.argv", msg.argv); switch (msg.kind) {
case pb.Msg.MsgKind.LOAD:
load(msg.argv);
break;
default:
console.log("Unknown message", msg);
break;
}
}); });
V8Worker2.print("Hello"); V8Worker2.print("Hello");

View file

@ -1,5 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"allowJs": true,
"module": "commonjs", "module": "commonjs",
"noImplicitAny": true, "noImplicitAny": true,
"sourceMap": true, "sourceMap": true,
@ -7,7 +8,7 @@
"preserveConstEnums": true, "preserveConstEnums": true,
"declaration": true, "declaration": true,
"target": "es5", "target": "es5",
"lib": ["es2015", "dom"], "lib": ["es2015"],
"noEmit": true, "noEmit": true,
"noUnusedLocals": true, "noUnusedLocals": true,
"noImplicitReturns": true, "noImplicitReturns": true,
@ -19,5 +20,5 @@
"allowUnreachableCode": false, "allowUnreachableCode": false,
"experimentalDecorators": true "experimentalDecorators": true
}, },
"include": ["*.ts"] "include": ["*.ts", "*.js"]
} }

23
util.ts Normal file
View file

@ -0,0 +1,23 @@
// If you use the eval function indirectly, by invoking it via a reference
// other than eval, as of ECMAScript 5 it works in the global scope rather than
// the local scope. This means, for instance, that function declarations create
// global functions, and that the code being evaluated doesn't have access to
// local variables within the scope where it's being called.
const globalEval = eval;
// A reference to the global object.
const _global = globalEval("this");
_global["console"] = {
log(...args: any[]): void {
const out: string[] = [];
for (let a of args) {
if (typeof(a) === "string") {
out.push(a);
} else {
out.push(JSON.stringify(a));
}
}
V8Worker2.print(out.join(" "));
}
};