1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00
denoland-deno/serde_v8/payload.rs
Heyang Zhou 92ebf4afe5
feat(ext/kv): key-value store (#18232)
This commit adds unstable "Deno.openKv()" API that allows to open
a key-value database at a specified path.

---------

Co-authored-by: Luca Casonato <hello@lcas.dev>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-03-22 12:13:24 +08:00

43 lines
1 KiB
Rust

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// TODO: maybe add a Payload type that holds scope & v8::Value
// so it can implement Deserialize by itself
// Classifies v8::Values into sub-types
#[derive(Debug)]
pub enum ValueType {
Null,
Bool,
Number,
BigInt,
String,
Array,
ArrayBuffer,
ArrayBufferView,
Object,
}
impl ValueType {
pub fn from_v8(v: v8::Local<v8::Value>) -> ValueType {
if v.is_boolean() {
return Self::Bool;
} else if v.is_number() {
return Self::Number;
} else if v.is_string() {
return Self::String;
} else if v.is_array() {
return Self::Array;
} else if v.is_big_int() {
return Self::BigInt;
} else if v.is_array_buffer() {
return Self::ArrayBuffer;
} else if v.is_array_buffer_view() {
return Self::ArrayBufferView;
} else if v.is_object() {
return Self::Object;
} else if v.is_null_or_undefined() {
return Self::Null;
}
panic!("serde_v8: unknown ValueType for v8::Value")
}
}