mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
wip
This commit is contained in:
parent
f0e01682cc
commit
96d1cf443d
6 changed files with 155 additions and 0 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -914,6 +914,13 @@ dependencies = [
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deno_cache"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"deno_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deno_console"
|
name = "deno_console"
|
||||||
version = "0.62.0"
|
version = "0.62.0"
|
||||||
|
|
|
@ -12,6 +12,7 @@ members = [
|
||||||
"test_ffi",
|
"test_ffi",
|
||||||
"test_util",
|
"test_util",
|
||||||
"ext/broadcast_channel",
|
"ext/broadcast_channel",
|
||||||
|
"ext/cache",
|
||||||
"ext/console",
|
"ext/console",
|
||||||
"ext/crypto",
|
"ext/crypto",
|
||||||
"ext/fetch",
|
"ext/fetch",
|
||||||
|
|
107
ext/cache/01_cache.js
vendored
Normal file
107
ext/cache/01_cache.js
vendored
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
/// <reference path="../../core/internal.d.ts" />
|
||||||
|
|
||||||
|
((window) => {
|
||||||
|
const core = window.Deno.core;
|
||||||
|
const webidl = window.__bootstrap.webidl;
|
||||||
|
const {
|
||||||
|
SafeArrayIterator,
|
||||||
|
Symbol,
|
||||||
|
SymbolFor,
|
||||||
|
ObjectDefineProperty,
|
||||||
|
ObjectFromEntries,
|
||||||
|
ObjectEntries,
|
||||||
|
ReflectGet,
|
||||||
|
ReflectHas,
|
||||||
|
Proxy,
|
||||||
|
} = window.__bootstrap.primordials;
|
||||||
|
|
||||||
|
const _persistent = Symbol("[[persistent]]");
|
||||||
|
|
||||||
|
class CacheStorage {
|
||||||
|
#storage;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
webidl.illegalConstructor();
|
||||||
|
}
|
||||||
|
|
||||||
|
get length() {
|
||||||
|
webidl.assertBranded(this, StoragePrototype);
|
||||||
|
return core.opSync("op_webstorage_length", this[_persistent]);
|
||||||
|
}
|
||||||
|
|
||||||
|
key(index) {
|
||||||
|
webidl.assertBranded(this, StoragePrototype);
|
||||||
|
const prefix = "Failed to execute 'key' on 'Storage'";
|
||||||
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
||||||
|
index = webidl.converters["unsigned long"](index, {
|
||||||
|
prefix,
|
||||||
|
context: "Argument 1",
|
||||||
|
});
|
||||||
|
|
||||||
|
return core.opSync("op_webstorage_key", index, this[_persistent]);
|
||||||
|
}
|
||||||
|
|
||||||
|
setItem(key, value) {
|
||||||
|
webidl.assertBranded(this, StoragePrototype);
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
getItem(key) {
|
||||||
|
webidl.assertBranded(this, StoragePrototype);
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeItem(key) {
|
||||||
|
webidl.assertBranded(this, StoragePrototype);
|
||||||
|
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 = {
|
||||||
|
localStorage() {
|
||||||
|
if (!localStorage) {
|
||||||
|
localStorage = createStorage(true);
|
||||||
|
}
|
||||||
|
return localStorage;
|
||||||
|
},
|
||||||
|
sessionStorage() {
|
||||||
|
if (!sessionStorage) {
|
||||||
|
sessionStorage = createStorage(false);
|
||||||
|
}
|
||||||
|
return sessionStorage;
|
||||||
|
},
|
||||||
|
Storage,
|
||||||
|
};
|
||||||
|
})(this);
|
17
ext/cache/Cargo.toml
vendored
Normal file
17
ext/cache/Cargo.toml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "deno_cache"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["the Deno authors"]
|
||||||
|
edition = "2021"
|
||||||
|
license = "MIT"
|
||||||
|
readme = "README.md"
|
||||||
|
repository = "https://github.com/denoland/deno"
|
||||||
|
description = "Implementation of Cache API for Deno"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "lib.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
deno_core = { version = "0.144.0", path = "../../core" }
|
5
ext/cache/README.md
vendored
Normal file
5
ext/cache/README.md
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# deno_cache
|
||||||
|
|
||||||
|
This crate implements the Cache API.
|
||||||
|
|
||||||
|
Spec: https://console.spec.whatwg.org/
|
18
ext/cache/lib.rs
vendored
Normal file
18
ext/cache/lib.rs
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
use deno_core::include_js_files;
|
||||||
|
use deno_core::Extension;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub fn init() -> Extension {
|
||||||
|
Extension::builder()
|
||||||
|
.js(include_js_files!(
|
||||||
|
prefix "deno:ext/cache",
|
||||||
|
"01_cache.js",
|
||||||
|
))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_declaration() -> PathBuf {
|
||||||
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_console.d.ts")
|
||||||
|
}
|
Loading…
Reference in a new issue