We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 588b485 commit 60d7ff0Copy full SHA for 60d7ff0
6 files changed
libquickjs-sys/embed/quickjs
src/serde/de.rs
@@ -174,6 +174,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
174
JsTag::Bool => visitor.visit_bool(current.to_bool()?),
175
JsTag::Null => visitor.visit_unit(),
176
JsTag::String => visitor.visit_string(current.to_string()?),
177
+ JsTag::RopeString => visitor.visit_string(current.to_string()?),
178
JsTag::Float64 => visitor.visit_f64(current.to_float()?),
179
JsTag::Object => {
180
if current.is_array() {
src/value/tag.rs
@@ -12,6 +12,7 @@ pub enum JsTag {
12
BigInt = q::JS_TAG_BIG_INT,
13
Symbol = q::JS_TAG_SYMBOL,
14
String = q::JS_TAG_STRING,
15
+ RopeString = q::JS_TAG_STRING_ROPE,
16
Module = q::JS_TAG_MODULE,
17
FunctionBytecode = q::JS_TAG_FUNCTION_BYTECODE,
18
Object = q::JS_TAG_OBJECT,
@@ -39,6 +40,7 @@ impl JsTag {
39
40
q::JS_TAG_MODULE => JsTag::Module,
41
q::JS_TAG_OBJECT => JsTag::Object,
42
q::JS_TAG_STRING => JsTag::String,
43
+ q::JS_TAG_STRING_ROPE => JsTag::RopeString,
44
q::JS_TAG_SYMBOL => JsTag::Symbol,
45
q::JS_TAG_FLOAT64 => JsTag::Float64,
46
q::JS_TAG_EXCEPTION => JsTag::Exception,
@@ -65,6 +67,7 @@ impl JsTag {
65
67
JsTag::BigInt => q::JS_TAG_FUNCTION_BYTECODE,
66
68
JsTag::Symbol => q::JS_TAG_SYMBOL,
69
JsTag::String => q::JS_TAG_STRING,
70
+ JsTag::RopeString => q::JS_TAG_STRING_ROPE,
71
JsTag::Module => q::JS_TAG_MODULE,
72
JsTag::FunctionBytecode => q::JS_TAG_FUNCTION_BYTECODE,
73
JsTag::Object => q::JS_TAG_OBJECT,
src/value/value.rs
@@ -251,7 +251,7 @@ impl OwnedJsValue {
251
/// Check if this value is a Javascript string.
252
#[inline]
253
pub fn is_string(&self) -> bool {
254
- self.tag() == JsTag::String
+ unsafe { q::JS_Ext_IsString(self.value) }
255
}
256
257
/// Check if this value is a bytecode compiled function.
@@ -292,7 +292,8 @@ impl OwnedJsValue {
292
293
/// Convert this value into a string
294
pub fn to_string(&self) -> Result<String, ValueError> {
295
- self.check_tag(JsTag::String)?;
+ self.check_tag(JsTag::String)
296
+ .or_else(|_| self.check_tag(JsTag::RopeString))?;
297
let ptr =
298
unsafe { q::JS_ToCStringLen2(self.context, std::ptr::null_mut(), self.value, false) };
299
tests/convert.rs
@@ -30,6 +30,17 @@ fn test_try_from_owned_js_value() {
30
let value: String = js_value.try_into().unwrap();
31
assert_eq!(value, "hello");
32
33
+ // test with rope string
34
+ let js_value: OwnedJsValue = context
35
+ .eval(
36
+ &format!("var x = `{}`; x + x", include_str!("fixtures/long_string.txt")),
37
+ false,
38
+ )
+ .unwrap();
+ assert!(js_value.is_string());
+ let value: String = js_value.try_into().unwrap();
+ assert!(value.starts_with("Lorem ipsum"));
+
let js_value: OwnedJsValue = context.eval(r#"({"key": "value"})"#, false).unwrap();
let value: HashMap<String, String> = js_value.try_into().unwrap();
assert_eq!(value, HashMap::from([("key".into(), "value".into())]));
0 commit comments