summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/ops/mod.rs1
-rw-r--r--cli/ops/resources.rs40
-rw-r--r--cli/rt/11_resources.js23
-rw-r--r--cli/rt/26_fetch.js11
-rw-r--r--cli/rt/27_websocket.js5
-rw-r--r--cli/rt/30_files.js9
-rw-r--r--cli/rt/30_net.js7
-rw-r--r--cli/rt/40_fs_events.js3
-rw-r--r--cli/rt/40_process.js3
-rw-r--r--cli/rt/40_repl.js3
-rw-r--r--cli/rt/40_testing.js6
-rw-r--r--cli/rt/90_deno_ns.js2
-rw-r--r--cli/rt/99_main.js4
-rw-r--r--cli/tests/unit/resources_test.ts2
-rw-r--r--cli/web_worker.rs11
-rw-r--r--cli/worker.rs3
16 files changed, 37 insertions, 96 deletions
diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs
index 1e622463e..288e3d0c0 100644
--- a/cli/ops/mod.rs
+++ b/cli/ops/mod.rs
@@ -19,7 +19,6 @@ pub mod plugin;
pub mod process;
pub mod random;
pub mod repl;
-pub mod resources;
pub mod runtime;
pub mod runtime_compiler;
pub mod signal;
diff --git a/cli/ops/resources.rs b/cli/ops/resources.rs
deleted file mode 100644
index bd6ba2941..000000000
--- a/cli/ops/resources.rs
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-
-use deno_core::error::bad_resource_id;
-use deno_core::error::AnyError;
-use deno_core::OpState;
-use deno_core::ZeroCopyBuf;
-use serde::Deserialize;
-use serde_json::Value;
-
-pub fn init(rt: &mut deno_core::JsRuntime) {
- super::reg_json_sync(rt, "op_resources", op_resources);
- super::reg_json_sync(rt, "op_close", op_close);
-}
-
-fn op_resources(
- state: &mut OpState,
- _args: Value,
- _zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, AnyError> {
- let serialized_resources = state.resource_table.entries();
- Ok(json!(serialized_resources))
-}
-
-/// op_close removes a resource from the resource table.
-fn op_close(
- state: &mut OpState,
- args: Value,
- _zero_copy: &mut [ZeroCopyBuf],
-) -> Result<Value, AnyError> {
- #[derive(Deserialize)]
- struct CloseArgs {
- rid: i32,
- }
- let args: CloseArgs = serde_json::from_value(args)?;
- state
- .resource_table
- .close(args.rid as u32)
- .ok_or_else(bad_resource_id)?;
- Ok(json!({}))
-}
diff --git a/cli/rt/11_resources.js b/cli/rt/11_resources.js
deleted file mode 100644
index 9a1595b78..000000000
--- a/cli/rt/11_resources.js
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-
-((window) => {
- const core = window.Deno.core;
-
- function resources() {
- const res = core.jsonOpSync("op_resources");
- const resources = {};
- for (const resourceTuple of res) {
- resources[resourceTuple[0]] = resourceTuple[1];
- }
- return resources;
- }
-
- function close(rid) {
- core.jsonOpSync("op_close", { rid });
- }
-
- window.__bootstrap.resources = {
- close,
- resources,
- };
-})(this);
diff --git a/cli/rt/26_fetch.js b/cli/rt/26_fetch.js
index ca36d7ba4..b337fbe10 100644
--- a/cli/rt/26_fetch.js
+++ b/cli/rt/26_fetch.js
@@ -5,7 +5,6 @@
const { notImplemented } = window.__bootstrap.util;
const { getHeaderValueParams, isTypedArray } = window.__bootstrap.webUtil;
const { Blob, bytesSymbol: blobBytesSymbol } = window.__bootstrap.blob;
- const { close } = window.__bootstrap.resources;
const Body = window.__bootstrap.body;
const { ReadableStream } = window.__bootstrap.streams;
const { MultipartBuilder } = window.__bootstrap.multipart;
@@ -24,7 +23,7 @@
this.rid = rid;
}
close() {
- close(this.rid);
+ core.close(this.rid);
}
}
@@ -290,7 +289,7 @@
) {
// We won't use body of received response, so close it now
// otherwise it will be kept in resource table.
- close(fetchResponse.bodyRid);
+ core.close(fetchResponse.bodyRid);
responseBody = null;
} else {
responseBody = new ReadableStream({
@@ -300,7 +299,7 @@
const result = await core.jsonOpAsync("op_fetch_read", { rid });
if (!result || !result.chunk) {
controller.close();
- close(rid);
+ core.close(rid);
} else {
// TODO(ry) This is terribly inefficient. Make this zero-copy.
const chunk = new Uint8Array(result.chunk);
@@ -309,12 +308,12 @@
} catch (e) {
controller.error(e);
controller.close();
- close(rid);
+ core.close(rid);
}
},
cancel() {
// When reader.cancel() is called
- close(rid);
+ core.close(rid);
},
});
}
diff --git a/cli/rt/27_websocket.js b/cli/rt/27_websocket.js
index d7fc03169..ee114170d 100644
--- a/cli/rt/27_websocket.js
+++ b/cli/rt/27_websocket.js
@@ -2,7 +2,6 @@
((window) => {
const core = window.Deno.core;
- const { close } = window.__bootstrap.resources;
const { requiredArguments } = window.__bootstrap.webUtil;
const CONNECTING = 0;
const OPEN = 1;
@@ -71,7 +70,7 @@
event.target = this;
this.onclose?.(event);
this.dispatchEvent(event);
- close(this.#rid);
+ core.close(this.#rid);
});
const event = new Event("error");
@@ -242,7 +241,7 @@
event.target = this;
this.onclose?.(event);
this.dispatchEvent(event);
- close(this.#rid);
+ core.close(this.#rid);
});
}
}
diff --git a/cli/rt/30_files.js b/cli/rt/30_files.js
index ff6b85ae5..e492da218 100644
--- a/cli/rt/30_files.js
+++ b/cli/rt/30_files.js
@@ -2,7 +2,6 @@
((window) => {
const core = window.Deno.core;
- const { close } = window.__bootstrap.resources;
const { read, readSync, write, writeSync } = window.__bootstrap.io;
const { pathFromURL } = window.__bootstrap.util;
@@ -104,7 +103,7 @@
}
close() {
- close(this.rid);
+ core.close(this.rid);
}
}
@@ -122,7 +121,7 @@
}
close() {
- close(this.rid);
+ core.close(this.rid);
}
}
@@ -140,7 +139,7 @@
}
close() {
- close(this.rid);
+ core.close(this.rid);
}
}
@@ -158,7 +157,7 @@
}
close() {
- close(this.rid);
+ core.close(this.rid);
}
}
diff --git a/cli/rt/30_net.js b/cli/rt/30_net.js
index 8c3dcb4ba..53de5200d 100644
--- a/cli/rt/30_net.js
+++ b/cli/rt/30_net.js
@@ -4,7 +4,6 @@
const core = window.Deno.core;
const { errors } = window.__bootstrap.errors;
const { read, write } = window.__bootstrap.io;
- const { close } = window.__bootstrap.resources;
const ShutdownMode = {
// See http://man7.org/linux/man-pages/man2/shutdown.2.html
@@ -88,7 +87,7 @@
}
close() {
- close(this.rid);
+ core.close(this.rid);
}
// TODO(lucacasonato): make this unavailable in stable
@@ -138,7 +137,7 @@
}
close() {
- close(this.rid);
+ core.close(this.rid);
}
[Symbol.asyncIterator]() {
@@ -187,7 +186,7 @@
}
close() {
- close(this.rid);
+ core.close(this.rid);
}
async *[Symbol.asyncIterator]() {
diff --git a/cli/rt/40_fs_events.js b/cli/rt/40_fs_events.js
index 43c0a4b92..a36adecba 100644
--- a/cli/rt/40_fs_events.js
+++ b/cli/rt/40_fs_events.js
@@ -3,7 +3,6 @@
((window) => {
const core = window.Deno.core;
const { errors } = window.__bootstrap.errors;
- const { close } = window.__bootstrap.resources;
class FsWatcher {
#rid = 0;
@@ -31,7 +30,7 @@
}
return(value) {
- close(this.rid);
+ core.close(this.rid);
return Promise.resolve({ value, done: true });
}
diff --git a/cli/rt/40_process.js b/cli/rt/40_process.js
index e188e9c6a..b46a1aead 100644
--- a/cli/rt/40_process.js
+++ b/cli/rt/40_process.js
@@ -3,7 +3,6 @@
((window) => {
const core = window.Deno.core;
const { File } = window.__bootstrap.files;
- const { close } = window.__bootstrap.resources;
const { readAll } = window.__bootstrap.buffer;
const { assert, pathFromURL } = window.__bootstrap.util;
@@ -78,7 +77,7 @@
}
close() {
- close(this.rid);
+ core.close(this.rid);
}
kill(signo) {
diff --git a/cli/rt/40_repl.js b/cli/rt/40_repl.js
index 8b05aa4c3..273687d93 100644
--- a/cli/rt/40_repl.js
+++ b/cli/rt/40_repl.js
@@ -4,7 +4,6 @@
const core = window.Deno.core;
const exit = window.__bootstrap.os.exit;
const version = window.__bootstrap.version.version;
- const close = window.__bootstrap.resources.close;
const inspectArgs = window.__bootstrap.console.inspectArgs;
function opStartRepl(historyFile) {
@@ -90,7 +89,7 @@
const quitRepl = (exitCode) => {
// Special handling in case user calls deno.close(3).
try {
- close(rid); // close signals Drop on REPL and saves history.
+ core.close(rid); // close signals Drop on REPL and saves history.
} catch {}
exit(exitCode);
};
diff --git a/cli/rt/40_testing.js b/cli/rt/40_testing.js
index 128f8ca93..c374e0ca6 100644
--- a/cli/rt/40_testing.js
+++ b/cli/rt/40_testing.js
@@ -1,13 +1,13 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
((window) => {
+ const core = window.Deno.core;
const { gray, green, italic, red, yellow } = window.__bootstrap.colors;
const { exit } = window.__bootstrap.os;
const { Console, inspectArgs } = window.__bootstrap.console;
const { stdout } = window.__bootstrap.files;
const { exposeForTest } = window.__bootstrap.internals;
const { metrics } = window.__bootstrap.metrics;
- const { resources } = window.__bootstrap.resources;
const { assert } = window.__bootstrap.util;
const disabledConsole = new Console(() => {});
@@ -64,9 +64,9 @@ finishing test case.`,
fn,
) {
return async function resourceSanitizer() {
- const pre = resources();
+ const pre = core.resources();
await fn();
- const post = resources();
+ const post = core.resources();
const preStr = JSON.stringify(pre, null, 2);
const postStr = JSON.stringify(post, null, 2);
diff --git a/cli/rt/90_deno_ns.js b/cli/rt/90_deno_ns.js
index 23ab12924..3a41e6bd1 100644
--- a/cli/rt/90_deno_ns.js
+++ b/cli/rt/90_deno_ns.js
@@ -53,8 +53,6 @@ __bootstrap.denoNs = {
env: __bootstrap.os.env,
exit: __bootstrap.os.exit,
execPath: __bootstrap.os.execPath,
- resources: __bootstrap.resources.resources,
- close: __bootstrap.resources.close,
Buffer: __bootstrap.buffer.Buffer,
readAll: __bootstrap.buffer.readAll,
readAllSync: __bootstrap.buffer.readAllSync,
diff --git a/cli/rt/99_main.js b/cli/rt/99_main.js
index 03bd77be4..02834dcf3 100644
--- a/cli/rt/99_main.js
+++ b/cli/rt/99_main.js
@@ -308,6 +308,8 @@ delete Object.prototype.__proto__;
core,
internal: internalSymbol,
[internalSymbol]: internalObject,
+ resources: core.resources,
+ close: core.close,
...denoNs,
};
Object.defineProperties(finalDenoNs, {
@@ -361,6 +363,8 @@ delete Object.prototype.__proto__;
core,
internal: internalSymbol,
[internalSymbol]: internalObject,
+ resources: core.resources,
+ close: core.close,
...denoNs,
};
if (useDenoNamespace) {
diff --git a/cli/tests/unit/resources_test.ts b/cli/tests/unit/resources_test.ts
index 5742fd6a0..4e4288ff9 100644
--- a/cli/tests/unit/resources_test.ts
+++ b/cli/tests/unit/resources_test.ts
@@ -4,7 +4,7 @@ import { unitTest, assertEquals, assert, assertThrows } from "./test_util.ts";
unitTest(function resourcesCloseBadArgs(): void {
assertThrows(() => {
Deno.close((null as unknown) as number);
- }, Deno.errors.InvalidData);
+ }, TypeError);
});
unitTest(function resourcesStdio(): void {
diff --git a/cli/web_worker.rs b/cli/web_worker.rs
index 3484a598d..bad017914 100644
--- a/cli/web_worker.rs
+++ b/cli/web_worker.rs
@@ -117,7 +117,16 @@ impl WebWorker {
ops::worker_host::init(&mut web_worker.worker);
ops::idna::init(&mut web_worker.worker);
ops::io::init(&mut web_worker.worker);
- ops::resources::init(&mut web_worker.worker);
+ ops::reg_json_sync(
+ &mut web_worker.worker,
+ "op_close",
+ deno_core::op_close,
+ );
+ ops::reg_json_sync(
+ &mut web_worker.worker,
+ "op_resources",
+ deno_core::op_resources,
+ );
ops::errors::init(&mut web_worker.worker);
ops::timers::init(&mut web_worker.worker);
ops::fetch::init(&mut web_worker.worker);
diff --git a/cli/worker.rs b/cli/worker.rs
index 6d5f37175..6c22ba92b 100644
--- a/cli/worker.rs
+++ b/cli/worker.rs
@@ -287,7 +287,8 @@ impl MainWorker {
ops::process::init(&mut worker);
ops::random::init(&mut worker);
ops::repl::init(&mut worker);
- ops::resources::init(&mut worker);
+ ops::reg_json_sync(&mut worker, "op_close", deno_core::op_close);
+ ops::reg_json_sync(&mut worker, "op_resources", deno_core::op_resources);
ops::signal::init(&mut worker);
ops::timers::init(&mut worker);
ops::tty::init(&mut worker);