From dfe528198d363ebc883da84dc816bce112ecd24b Mon Sep 17 00:00:00 2001
From: crowlKats <13135287+crowlKats@users.noreply.github.com>
Date: Mon, 10 May 2021 12:02:47 +0200
Subject: feat: add WebStorage API (#7819)
This commit introduces localStorage and sessionStorage.
---
cli/build.rs | 6 ++++++
cli/dts/lib.deno.window.d.ts | 5 +++++
cli/main.rs | 11 ++++++++++-
cli/standalone.rs | 1 +
cli/tsc.rs | 2 ++
5 files changed, 24 insertions(+), 1 deletion(-)
(limited to 'cli')
diff --git a/cli/build.rs b/cli/build.rs
index eb8a71c8c..116ce8167 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -16,6 +16,7 @@ use deno_runtime::deno_url;
use deno_runtime::deno_web;
use deno_runtime::deno_webgpu;
use deno_runtime::deno_websocket;
+use deno_runtime::deno_webstorage;
use regex::Regex;
use std::collections::HashMap;
use std::env;
@@ -71,6 +72,7 @@ fn create_compiler_snapshot(
op_crate_libs.insert("deno.fetch", deno_fetch::get_declaration());
op_crate_libs.insert("deno.webgpu", deno_webgpu::get_declaration());
op_crate_libs.insert("deno.websocket", deno_websocket::get_declaration());
+ op_crate_libs.insert("deno.webstorage", deno_webstorage::get_declaration());
op_crate_libs.insert("deno.crypto", deno_crypto::get_declaration());
// ensure we invalidate the build properly.
@@ -290,6 +292,10 @@ fn main() {
"cargo:rustc-env=DENO_WEBSOCKET_LIB_PATH={}",
deno_websocket::get_declaration().display()
);
+ println!(
+ "cargo:rustc-env=DENO_WEBSTORAGE_LIB_PATH={}",
+ deno_webstorage::get_declaration().display()
+ );
println!(
"cargo:rustc-env=DENO_CRYPTO_LIB_PATH={}",
deno_crypto::get_declaration().display()
diff --git a/cli/dts/lib.deno.window.d.ts b/cli/dts/lib.deno.window.d.ts
index b7eca1e24..3c985e641 100644
--- a/cli/dts/lib.deno.window.d.ts
+++ b/cli/dts/lib.deno.window.d.ts
@@ -4,6 +4,7 @@
///
///
///
+///
///
declare class Window extends EventTarget {
@@ -22,12 +23,16 @@ declare class Window extends EventTarget {
navigator: Navigator;
Location: typeof Location;
location: Location;
+ localStorage: Storage;
+ sessionStorage: Storage;
}
declare var window: Window & typeof globalThis;
declare var self: Window & typeof globalThis;
declare var onload: ((this: Window, ev: Event) => any) | null;
declare var onunload: ((this: Window, ev: Event) => any) | null;
+declare var localStorage: Storage;
+declare var sessionStorage: Storage;
declare class Navigator {
constructor();
diff --git a/cli/main.rs b/cli/main.rs
index d20462c96..43c1cd0b2 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -204,6 +204,14 @@ pub fn create_main_worker(
no_color: !colors::use_color(),
get_error_class_fn: Some(&crate::errors::get_error_class_name),
location: program_state.flags.location.clone(),
+ location_data_dir: program_state.flags.location.clone().map(|loc| {
+ program_state
+ .dir
+ .root
+ .clone()
+ .join("location_data")
+ .join(checksum::gen(&[loc.to_string().as_bytes()]))
+ }),
blob_url_store: program_state.blob_url_store.clone(),
};
@@ -295,7 +303,7 @@ fn print_cache_info(
pub fn get_types(unstable: bool) -> String {
let mut types = format!(
- "{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}",
+ "{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}",
crate::tsc::DENO_NS_LIB,
crate::tsc::DENO_CONSOLE_LIB,
crate::tsc::DENO_URL_LIB,
@@ -304,6 +312,7 @@ pub fn get_types(unstable: bool) -> String {
crate::tsc::DENO_FETCH_LIB,
crate::tsc::DENO_WEBGPU_LIB,
crate::tsc::DENO_WEBSOCKET_LIB,
+ crate::tsc::DENO_WEBSTORAGE_LIB,
crate::tsc::DENO_CRYPTO_LIB,
crate::tsc::SHARED_GLOBALS_LIB,
crate::tsc::WINDOW_LIB,
diff --git a/cli/standalone.rs b/cli/standalone.rs
index 83879a163..e0b131eb8 100644
--- a/cli/standalone.rs
+++ b/cli/standalone.rs
@@ -191,6 +191,7 @@ pub async fn run(
no_color: !colors::use_color(),
get_error_class_fn: Some(&get_error_class_name),
location: metadata.location,
+ location_data_dir: None,
blob_url_store,
};
let mut worker =
diff --git a/cli/tsc.rs b/cli/tsc.rs
index e2fc80676..7abae5ca1 100644
--- a/cli/tsc.rs
+++ b/cli/tsc.rs
@@ -37,6 +37,8 @@ pub static DENO_FETCH_LIB: &str = include_str!(env!("DENO_FETCH_LIB_PATH"));
pub static DENO_WEBGPU_LIB: &str = include_str!(env!("DENO_WEBGPU_LIB_PATH"));
pub static DENO_WEBSOCKET_LIB: &str =
include_str!(env!("DENO_WEBSOCKET_LIB_PATH"));
+pub static DENO_WEBSTORAGE_LIB: &str =
+ include_str!(env!("DENO_WEBSTORAGE_LIB_PATH"));
pub static DENO_CRYPTO_LIB: &str = include_str!(env!("DENO_CRYPTO_LIB_PATH"));
pub static SHARED_GLOBALS_LIB: &str =
include_str!("dts/lib.deno.shared_globals.d.ts");
--
cgit v1.2.3