summaryrefslogtreecommitdiff
path: root/deno2/js
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2018-06-14 14:31:31 +0200
committerBert Belder <bertbelder@gmail.com>2018-06-14 17:24:00 +0200
commit4f6c8ba54bca4f62fbe4e7dba2fc3c4a7c2f1bb2 (patch)
tree32c9b75a1bc217406952ca1b5f89f57968f37e5a /deno2/js
parentfb98474239a7ffb145e529dbcf069866b2e9296e (diff)
deno2: add global `deno` namespace
Diffstat (limited to 'deno2/js')
-rw-r--r--deno2/js/deno.d.ts11
-rw-r--r--deno2/js/main.ts16
-rw-r--r--deno2/js/mock_runtime.js20
-rw-r--r--deno2/js/package.json2
-rw-r--r--deno2/js/yarn.lock14
5 files changed, 42 insertions, 21 deletions
diff --git a/deno2/js/deno.d.ts b/deno2/js/deno.d.ts
index 4c797a5f6..4f8a7bc3d 100644
--- a/deno2/js/deno.d.ts
+++ b/deno2/js/deno.d.ts
@@ -1,6 +1,11 @@
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// All rights reserved. MIT License.
type MessageCallback = (msg: ArrayBuffer) => void;
-declare function denoSub(channel: string, cb: MessageCallback): void;
-declare function denoPub(channel: string, msg: ArrayBuffer): null | ArrayBuffer;
-declare function denoPrint(x: string): void;
+
+interface Deno {
+ sub(channel: string, cb: MessageCallback): void;
+ pub(channel: string, msg: ArrayBuffer): null | ArrayBuffer;
+ print(x: string): void;
+}
+
+declare let deno: Deno;
diff --git a/deno2/js/main.ts b/deno2/js/main.ts
index baa19638f..d2d61f419 100644
--- a/deno2/js/main.ts
+++ b/deno2/js/main.ts
@@ -6,13 +6,13 @@ const globalEval = eval;
const window = globalEval("this");
window["denoMain"] = () => {
- denoPrint(`ts.version: ${ts.version}`);
- const res = denoPub("startDeno2", emptyArrayBuffer());
- //denoPrint(`after`);
+ deno.print(`ts.version: ${ts.version}`);
+ const res = deno.pub("startDeno2", emptyArrayBuffer());
+ //deno.print(`after`);
const resUi8 = new Uint8Array(res);
- denoPrint(`before`);
+ deno.print(`before`);
const msg = pb.Msg.decode(resUi8);
- denoPrint(`after`);
+ deno.print(`after`);
const {
startCwd: cwd,
startArgv: argv,
@@ -21,11 +21,11 @@ window["denoMain"] = () => {
startMainMap: mainMap
} = msg;
- denoPrint(`cwd: ${cwd}`);
- denoPrint(`debugFlag: ${debugFlag}`);
+ deno.print(`cwd: ${cwd}`);
+ deno.print(`debugFlag: ${debugFlag}`);
for (let i = 0; i < argv.length; i++) {
- denoPrint(`argv[${i}] ${argv[i]}`);
+ deno.print(`argv[${i}] ${argv[i]}`);
}
};
diff --git a/deno2/js/mock_runtime.js b/deno2/js/mock_runtime.js
index 07e5a2ca8..f16161cf7 100644
--- a/deno2/js/mock_runtime.js
+++ b/deno2/js/mock_runtime.js
@@ -11,7 +11,7 @@ function typedArrayToArrayBuffer(ta) {
}
function CanCallFunction() {
- denoPrint("Hello world from foo");
+ deno.print("Hello world from foo");
return "foo";
}
@@ -27,14 +27,14 @@ function TypedArraySnapshots() {
}
function PubSuccess() {
- denoSub((channel, msg) => {
+ deno.sub((channel, msg) => {
assert(channel === "PubSuccess");
- denoPrint("PubSuccess: ok");
+ deno.print("PubSuccess: ok");
});
}
function PubByteLength() {
- denoSub((channel, msg) => {
+ deno.sub((channel, msg) => {
assert(channel === "PubByteLength");
assert(msg instanceof ArrayBuffer);
assert(msg.byteLength === 3);
@@ -44,16 +44,16 @@ function PubByteLength() {
function SubReturnEmpty() {
const ui8 = new Uint8Array("abc".split("").map(c => c.charCodeAt(0)));
const ab = typedArrayToArrayBuffer(ui8);
- let r = denoPub("SubReturnEmpty", ab);
+ let r = deno.pub("SubReturnEmpty", ab);
assert(r == null);
- r = denoPub("SubReturnEmpty", ab);
+ r = deno.pub("SubReturnEmpty", ab);
assert(r == null);
}
function SubReturnBar() {
const ui8 = new Uint8Array("abc".split("").map(c => c.charCodeAt(0)));
const ab = typedArrayToArrayBuffer(ui8);
- const r = denoPub("SubReturnBar", ab);
+ const r = deno.pub("SubReturnBar", ab);
assert(r instanceof ArrayBuffer);
assert(r.byteLength === 3);
const rui8 = new Uint8Array(r);
@@ -62,8 +62,8 @@ function SubReturnBar() {
}
function DoubleSubFails() {
- // denoSub is an internal function and should only be called once from the
+ // deno.sub is an internal function and should only be called once from the
// runtime.
- denoSub((channel, msg) => assert(false));
- denoSub((channel, msg) => assert(false));
+ deno.sub((channel, msg) => assert(false));
+ deno.sub((channel, msg) => assert(false));
}
diff --git a/deno2/js/package.json b/deno2/js/package.json
index 7bc37323e..eb6cfd7fd 100644
--- a/deno2/js/package.json
+++ b/deno2/js/package.json
@@ -1,5 +1,7 @@
{
"devDependencies": {
+ "@types/base64-js": "^1.2.5",
+ "@types/source-map-support": "^0.4.1",
"parcel-bundler": "^1.8.1",
"protobufjs": "^6.8.6",
"typescript": "^2.9.1"
diff --git a/deno2/js/yarn.lock b/deno2/js/yarn.lock
index f7ab0c541..b6294e55e 100644
--- a/deno2/js/yarn.lock
+++ b/deno2/js/yarn.lock
@@ -45,14 +45,28 @@
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
+"@types/base64-js@^1.2.5":
+ version "1.2.5"
+ resolved "https://registry.yarnpkg.com/@types/base64-js/-/base64-js-1.2.5.tgz#582b2476169a6cba460a214d476c744441d873d5"
+
"@types/long@^3.0.32":
version "3.0.32"
resolved "https://registry.yarnpkg.com/@types/long/-/long-3.0.32.tgz#f4e5af31e9e9b196d8e5fca8a5e2e20aa3d60b69"
+"@types/node@*":
+ version "10.3.3"
+ resolved "https://registry.yarnpkg.com/@types/node/-/node-10.3.3.tgz#8798d9e39af2fa604f715ee6a6b19796528e46c3"
+
"@types/node@^8.9.4":
version "8.10.19"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.19.tgz#66b5b6325c048cbf4512b7a88b0e79c2ee99d3d2"
+"@types/source-map-support@^0.4.1":
+ version "0.4.1"
+ resolved "https://registry.yarnpkg.com/@types/source-map-support/-/source-map-support-0.4.1.tgz#ad77158e8c6695a16629ef82b9fb9dfe7c610ac0"
+ dependencies:
+ "@types/node" "*"
+
abbrev@1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"