summaryrefslogtreecommitdiff
path: root/serde_v8/src/payload.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-10-20 00:00:45 +0200
committerGitHub <noreply@github.com>2021-10-20 00:00:45 +0200
commit4f48efcc55b9e6cc0dd212ebd8e729909efed1ab (patch)
tree78f06eff5e21bddc9c6be0a3fc809d2b4a5932cb /serde_v8/src/payload.rs
parentad20e52c27a88b8481b2d8e169bde4a9b4952cb6 (diff)
chore: return serde_v8 to main repo (#12500)
Reduces fragmentation, avoids version drift and facilitates coordinating serde_v8 and op-layer changes
Diffstat (limited to 'serde_v8/src/payload.rs')
-rw-r--r--serde_v8/src/payload.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/serde_v8/src/payload.rs b/serde_v8/src/payload.rs
new file mode 100644
index 000000000..816158f93
--- /dev/null
+++ b/serde_v8/src/payload.rs
@@ -0,0 +1,34 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+use rusty_v8 as v8;
+
+// TODO: maybe add a Payload type that holds scope & v8::Value
+// so it can implement Deserialize by itself
+
+// Classifies v8::Values into sub-types
+pub enum ValueType {
+ Null,
+ Bool,
+ Number,
+ String,
+ Array,
+ 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_object() {
+ return Self::Object;
+ } else if v.is_null_or_undefined() {
+ return Self::Null;
+ }
+ panic!("serde_v8: unknown ValueType for v8::Value")
+ }
+}