mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
wip
This commit is contained in:
parent
96d1cf443d
commit
26d583fb22
12 changed files with 186 additions and 84 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -792,6 +792,7 @@ dependencies = [
|
||||||
"deno_ast",
|
"deno_ast",
|
||||||
"deno_bench_util",
|
"deno_bench_util",
|
||||||
"deno_broadcast_channel",
|
"deno_broadcast_channel",
|
||||||
|
"deno_cache",
|
||||||
"deno_console",
|
"deno_console",
|
||||||
"deno_core",
|
"deno_core",
|
||||||
"deno_crypto",
|
"deno_crypto",
|
||||||
|
@ -1139,6 +1140,7 @@ version = "0.70.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atty",
|
"atty",
|
||||||
"deno_broadcast_channel",
|
"deno_broadcast_channel",
|
||||||
|
"deno_cache",
|
||||||
"deno_console",
|
"deno_console",
|
||||||
"deno_core",
|
"deno_core",
|
||||||
"deno_crypto",
|
"deno_crypto",
|
||||||
|
|
|
@ -27,6 +27,7 @@ path = "./bench/lsp_bench_standalone.rs"
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
deno_broadcast_channel = { version = "0.56.0", path = "../ext/broadcast_channel" }
|
deno_broadcast_channel = { version = "0.56.0", path = "../ext/broadcast_channel" }
|
||||||
deno_console = { version = "0.62.0", path = "../ext/console" }
|
deno_console = { version = "0.62.0", path = "../ext/console" }
|
||||||
|
deno_cache = { version = "0.1.0", path = "../ext/cache" }
|
||||||
deno_core = { version = "0.144.0", path = "../core" }
|
deno_core = { version = "0.144.0", path = "../core" }
|
||||||
deno_crypto = { version = "0.76.0", path = "../ext/crypto" }
|
deno_crypto = { version = "0.76.0", path = "../ext/crypto" }
|
||||||
deno_fetch = { version = "0.85.0", path = "../ext/fetch" }
|
deno_fetch = { version = "0.85.0", path = "../ext/fetch" }
|
||||||
|
|
|
@ -81,6 +81,7 @@ fn create_compiler_snapshot(
|
||||||
) {
|
) {
|
||||||
// libs that are being provided by op crates.
|
// libs that are being provided by op crates.
|
||||||
let mut op_crate_libs = HashMap::new();
|
let mut op_crate_libs = HashMap::new();
|
||||||
|
op_crate_libs.insert("deno.caches", deno_cache::get_declaration());
|
||||||
op_crate_libs.insert("deno.console", deno_console::get_declaration());
|
op_crate_libs.insert("deno.console", deno_console::get_declaration());
|
||||||
op_crate_libs.insert("deno.url", deno_url::get_declaration());
|
op_crate_libs.insert("deno.url", deno_url::get_declaration());
|
||||||
op_crate_libs.insert("deno.web", deno_web::get_declaration());
|
op_crate_libs.insert("deno.web", deno_web::get_declaration());
|
||||||
|
|
256
ext/cache/01_cache.js
vendored
256
ext/cache/01_cache.js
vendored
|
@ -3,105 +3,195 @@
|
||||||
/// <reference path="../../core/internal.d.ts" />
|
/// <reference path="../../core/internal.d.ts" />
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const core = window.Deno.core;
|
function queryCache(requestQuery, options = {}, targetStorage = new Map()) {
|
||||||
const webidl = window.__bootstrap.webidl;
|
const resultList = new Map();
|
||||||
const {
|
// let storage = null;
|
||||||
SafeArrayIterator,
|
// Ignore step 2-4;
|
||||||
Symbol,
|
for (const [request, response] of targetStorage.entries()) {
|
||||||
SymbolFor,
|
if (requestMatchesCatchedItem(requestQuery, request, response, options)) {
|
||||||
ObjectDefineProperty,
|
resultList.set(request, response);
|
||||||
ObjectFromEntries,
|
}
|
||||||
ObjectEntries,
|
}
|
||||||
ReflectGet,
|
return resultList;
|
||||||
ReflectHas,
|
}
|
||||||
Proxy,
|
|
||||||
} = window.__bootstrap.primordials;
|
|
||||||
|
|
||||||
const _persistent = Symbol("[[persistent]]");
|
function requestMatchesCachedItem(
|
||||||
|
requestQuery,
|
||||||
|
request,
|
||||||
|
response = null,
|
||||||
|
options = {},
|
||||||
|
) {
|
||||||
|
// Step 1.
|
||||||
|
if (options["ignoreMethod"] === false && request.method !== "GET") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2.
|
||||||
|
let queryURL = requestQuery.url;
|
||||||
|
let cachedURL = request.url;
|
||||||
|
if (options["ignoreSearch"] === true) {
|
||||||
|
queryURL = "";
|
||||||
|
cachedURL = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 5.
|
||||||
|
{
|
||||||
|
const a = new URL(queryURL);
|
||||||
|
const b = new URL(cachedURL);
|
||||||
|
if (
|
||||||
|
a.host !== b.host || a.pathname !== b.pathname || a.search !== b.search
|
||||||
|
) {
|
||||||
|
// TODO(@satyarohith): think about exclude fragment flag
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 6.
|
||||||
|
if (
|
||||||
|
(response === null && options["ignoreVary"] === true) ||
|
||||||
|
!response.headers.has("Vary")
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 7.
|
||||||
|
const varyHeader = response.headers.get("Vary");
|
||||||
|
// TODO(@satyarohith): do the parsing of the vary header.
|
||||||
|
const fieldValues = varyHeader.split(",").map((field) => field.trim());
|
||||||
|
for (const fieldValue of fieldValues) {
|
||||||
|
if (
|
||||||
|
fieldValue === "*" ||
|
||||||
|
request.headers.get(fieldValue) !== requestQuery.headers.get(fieldValue)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
class CacheStorage {
|
class CacheStorage {
|
||||||
#storage;
|
#storage;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
webidl.illegalConstructor();
|
this.#storage = new Map();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
get length() {
|
// deno-lint-ignore require-await
|
||||||
webidl.assertBranded(this, StoragePrototype);
|
async match(_request, _options) {
|
||||||
return core.opSync("op_webstorage_length", this[_persistent]);
|
// TODO(@satyarohith): implement the algorithm.
|
||||||
|
return Promise.resolve(new Response("hello world"));
|
||||||
}
|
}
|
||||||
|
// deno-lint-ignore require-await
|
||||||
key(index) {
|
async open(cacheName) {
|
||||||
webidl.assertBranded(this, StoragePrototype);
|
if (!this.#storage.has(cacheName)) {
|
||||||
const prefix = "Failed to execute 'key' on 'Storage'";
|
this.#storage.set(cacheName, new Cache(cacheName));
|
||||||
webidl.requiredArguments(arguments.length, 1, { prefix });
|
}
|
||||||
index = webidl.converters["unsigned long"](index, {
|
return Promise.resolve(this.#storage.get(cacheName));
|
||||||
prefix,
|
|
||||||
context: "Argument 1",
|
|
||||||
});
|
|
||||||
|
|
||||||
return core.opSync("op_webstorage_key", index, this[_persistent]);
|
|
||||||
}
|
}
|
||||||
|
// deno-lint-ignore require-await
|
||||||
setItem(key, value) {
|
async has(cacheName) {
|
||||||
webidl.assertBranded(this, StoragePrototype);
|
return Promise.resolve(this.#storage.has(cacheName));
|
||||||
const prefix = "Failed to execute 'setItem' on 'Storage'";
|
|
||||||
webidl.requiredArguments(arguments.length, 2, { prefix });
|
|
||||||
key = webidl.converters.DOMString(key, {
|
|
||||||
prefix,
|
|
||||||
context: "Argument 1",
|
|
||||||
});
|
|
||||||
value = webidl.converters.DOMString(value, {
|
|
||||||
prefix,
|
|
||||||
context: "Argument 2",
|
|
||||||
});
|
|
||||||
|
|
||||||
core.opSync("op_webstorage_set", key, value, this[_persistent]);
|
|
||||||
}
|
}
|
||||||
|
// deno-lint-ignore require-await
|
||||||
getItem(key) {
|
async delete(cacheName) {
|
||||||
webidl.assertBranded(this, StoragePrototype);
|
return Promise.resolve(this.#storage.delete(cacheName));
|
||||||
const prefix = "Failed to execute 'getItem' on 'Storage'";
|
|
||||||
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
||||||
key = webidl.converters.DOMString(key, {
|
|
||||||
prefix,
|
|
||||||
context: "Argument 1",
|
|
||||||
});
|
|
||||||
|
|
||||||
return core.opSync("op_webstorage_get", key, this[_persistent]);
|
|
||||||
}
|
}
|
||||||
|
// deno-lint-ignore require-await
|
||||||
removeItem(key) {
|
async keys() {
|
||||||
webidl.assertBranded(this, StoragePrototype);
|
return Promise.resolve(Array.from(this.#storage.keys()));
|
||||||
const prefix = "Failed to execute 'removeItem' on 'Storage'";
|
|
||||||
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
||||||
key = webidl.converters.DOMString(key, {
|
|
||||||
prefix,
|
|
||||||
context: "Argument 1",
|
|
||||||
});
|
|
||||||
|
|
||||||
core.opSync("op_webstorage_remove", key, this[_persistent]);
|
|
||||||
}
|
|
||||||
|
|
||||||
clear() {
|
|
||||||
webidl.assertBranded(this, StoragePrototype);
|
|
||||||
core.opSync("op_webstorage_clear", this[_persistent]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.__bootstrap.webStorage = {
|
class Cache {
|
||||||
localStorage() {
|
#storage;
|
||||||
if (!localStorage) {
|
#name;
|
||||||
localStorage = createStorage(true);
|
constructor(cacheName) {
|
||||||
|
this.#name = cacheName;
|
||||||
|
this.#storage = new Map();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
// async match(request, options) {}
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
|
async matchAll(request, options = {}) {
|
||||||
|
let r = null;
|
||||||
|
// Step 2.
|
||||||
|
if (request instanceof Request) {
|
||||||
|
if (request.method !== "GET" && !options?.ignoreMethod) {
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
|
r = request;
|
||||||
|
} else if (request instanceof string) {
|
||||||
|
try {
|
||||||
|
r = new Request(request);
|
||||||
|
} catch (error) {
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return localStorage;
|
|
||||||
},
|
// Step 5.
|
||||||
sessionStorage() {
|
const responses = [];
|
||||||
if (!sessionStorage) {
|
// Step 5.2
|
||||||
sessionStorage = createStorage(false);
|
if (r === null) {
|
||||||
|
for (const [_request, response] of this.#storage.entries()) {
|
||||||
|
responses.push(response);
|
||||||
|
}
|
||||||
|
// Step 5.3
|
||||||
|
} else {
|
||||||
|
const requestResponses = queryCache(r, options, this.#storage);
|
||||||
|
for (const response of requestResponses.values()) {
|
||||||
|
responses.push(response);
|
||||||
|
}
|
||||||
|
// Skip 5.4.
|
||||||
}
|
}
|
||||||
return sessionStorage;
|
// Step 5.5
|
||||||
},
|
|
||||||
Storage,
|
return Promise.resolve(responses);
|
||||||
|
}
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
|
async add(request) {
|
||||||
|
const requests = [request];
|
||||||
|
return this.addAll(requests);
|
||||||
|
}
|
||||||
|
|
||||||
|
// async addAll(requests) {
|
||||||
|
// const responsePromises = [];
|
||||||
|
// const requestList = [];
|
||||||
|
// for (const request of requests) {
|
||||||
|
// if (
|
||||||
|
// request instanceof Request &&
|
||||||
|
// request.scheme !== "http" && request.scheme !== "https" ||
|
||||||
|
// request.method !== "GET"
|
||||||
|
// ) {
|
||||||
|
// return Promise.reject(new TypeError("type error"));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// put(request, response) {
|
||||||
|
// let innerRequest = null;
|
||||||
|
// if (request instanceof Request) {
|
||||||
|
// innerRequest = request;
|
||||||
|
// } else {
|
||||||
|
// try {
|
||||||
|
// innerRequest = new Request(request);
|
||||||
|
// } catch (error) {
|
||||||
|
// throw Promise.reject(error);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async delete(request, options) {}
|
||||||
|
// deno-lint-ignore require-await
|
||||||
|
async keys() {
|
||||||
|
return Promise.resolve(Array.from(this.#storage.keys()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.__bootstrap.caches = {
|
||||||
|
CacheStorage,
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
0
ext/cache/lib.deno_cache.d.ts
vendored
Normal file
0
ext/cache/lib.deno_cache.d.ts
vendored
Normal file
2
ext/cache/lib.rs
vendored
2
ext/cache/lib.rs
vendored
|
@ -14,5 +14,5 @@ pub fn init() -> Extension {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_declaration() -> PathBuf {
|
pub fn get_declaration() -> PathBuf {
|
||||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_console.d.ts")
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_cache.d.ts")
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ path = "examples/hello_runtime.rs"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
deno_broadcast_channel = { version = "0.56.0", path = "../ext/broadcast_channel" }
|
deno_broadcast_channel = { version = "0.56.0", path = "../ext/broadcast_channel" }
|
||||||
|
deno_cache = { version = "0.1.0", path = "../ext/cache" }
|
||||||
deno_console = { version = "0.62.0", path = "../ext/console" }
|
deno_console = { version = "0.62.0", path = "../ext/console" }
|
||||||
deno_core = { version = "0.144.0", path = "../core" }
|
deno_core = { version = "0.144.0", path = "../core" }
|
||||||
deno_crypto = { version = "0.76.0", path = "../ext/crypto" }
|
deno_crypto = { version = "0.76.0", path = "../ext/crypto" }
|
||||||
|
@ -46,6 +47,7 @@ winapi = "0.3.9"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
deno_broadcast_channel = { version = "0.56.0", path = "../ext/broadcast_channel" }
|
deno_broadcast_channel = { version = "0.56.0", path = "../ext/broadcast_channel" }
|
||||||
|
deno_cache = { version = "0.1.0", path = "../ext/cache" }
|
||||||
deno_console = { version = "0.62.0", path = "../ext/console" }
|
deno_console = { version = "0.62.0", path = "../ext/console" }
|
||||||
deno_core = { version = "0.144.0", path = "../core" }
|
deno_core = { version = "0.144.0", path = "../core" }
|
||||||
deno_crypto = { version = "0.76.0", path = "../ext/crypto" }
|
deno_crypto = { version = "0.76.0", path = "../ext/crypto" }
|
||||||
|
|
|
@ -142,6 +142,7 @@ mod not_docs {
|
||||||
fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<PathBuf>) {
|
fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<PathBuf>) {
|
||||||
let extensions: Vec<Extension> = vec![
|
let extensions: Vec<Extension> = vec![
|
||||||
deno_webidl::init(),
|
deno_webidl::init(),
|
||||||
|
deno_cache::init(),
|
||||||
deno_console::init(),
|
deno_console::init(),
|
||||||
deno_url::init(),
|
deno_url::init(),
|
||||||
deno_tls::init(),
|
deno_tls::init(),
|
||||||
|
|
|
@ -49,6 +49,7 @@ delete Intl.v8BreakIterator;
|
||||||
const encoding = window.__bootstrap.encoding;
|
const encoding = window.__bootstrap.encoding;
|
||||||
const colors = window.__bootstrap.colors;
|
const colors = window.__bootstrap.colors;
|
||||||
const Console = window.__bootstrap.console.Console;
|
const Console = window.__bootstrap.console.Console;
|
||||||
|
const CacheStorage = window.__bootstrap.caches.CacheStorage;
|
||||||
const inspectArgs = window.__bootstrap.console.inspectArgs;
|
const inspectArgs = window.__bootstrap.console.inspectArgs;
|
||||||
const quoteString = window.__bootstrap.console.quoteString;
|
const quoteString = window.__bootstrap.console.quoteString;
|
||||||
const compression = window.__bootstrap.compression;
|
const compression = window.__bootstrap.compression;
|
||||||
|
@ -466,6 +467,7 @@ delete Intl.v8BreakIterator;
|
||||||
btoa: util.writable(base64.btoa),
|
btoa: util.writable(base64.btoa),
|
||||||
clearInterval: util.writable(timers.clearInterval),
|
clearInterval: util.writable(timers.clearInterval),
|
||||||
clearTimeout: util.writable(timers.clearTimeout),
|
clearTimeout: util.writable(timers.clearTimeout),
|
||||||
|
caches: util.nonEnumerable(new CacheStorage()),
|
||||||
console: util.nonEnumerable(
|
console: util.nonEnumerable(
|
||||||
new Console((msg, level) => core.print(msg, level > 1)),
|
new Console((msg, level) => core.print(msg, level > 1)),
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
pub use deno_broadcast_channel;
|
pub use deno_broadcast_channel;
|
||||||
|
pub use deno_cache;
|
||||||
pub use deno_console;
|
pub use deno_console;
|
||||||
pub use deno_core;
|
pub use deno_core;
|
||||||
pub use deno_crypto;
|
pub use deno_crypto;
|
||||||
|
|
|
@ -374,6 +374,7 @@ impl WebWorker {
|
||||||
let mut extensions: Vec<Extension> = vec![
|
let mut extensions: Vec<Extension> = vec![
|
||||||
// Web APIs
|
// Web APIs
|
||||||
deno_webidl::init(),
|
deno_webidl::init(),
|
||||||
|
deno_cache::init(),
|
||||||
deno_console::init(),
|
deno_console::init(),
|
||||||
deno_url::init(),
|
deno_url::init(),
|
||||||
deno_web::init::<Permissions>(
|
deno_web::init::<Permissions>(
|
||||||
|
|
|
@ -117,6 +117,7 @@ impl MainWorker {
|
||||||
let mut extensions: Vec<Extension> = vec![
|
let mut extensions: Vec<Extension> = vec![
|
||||||
// Web APIs
|
// Web APIs
|
||||||
deno_webidl::init(),
|
deno_webidl::init(),
|
||||||
|
deno_cache::init(),
|
||||||
deno_console::init(),
|
deno_console::init(),
|
||||||
deno_url::init(),
|
deno_url::init(),
|
||||||
deno_web::init::<Permissions>(
|
deno_web::init::<Permissions>(
|
||||||
|
|
Loading…
Reference in a new issue