Skip to content

Commit b254f43

Browse files
committed
in work
1 parent c94f32a commit b254f43

File tree

11 files changed

+214
-291
lines changed

11 files changed

+214
-291
lines changed

packages/cubejs-backend-native/src/node_export.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,15 @@ pub fn reset_logger(mut cx: FunctionContext) -> JsResult<JsUndefined> {
604604

605605
fn build_sql_and_params(cx: FunctionContext) -> JsResult<JsValue> {
606606
neon_run_with_guarded_lifetime(cx, |neon_context_holder| {
607-
let options =
608-
NativeObjectHandle::<NeonInnerTypes<FunctionContext<'static>>>::new(NeonObject::new(
607+
let options = NativeObjectHandle::<NeonInnerTypes<FunctionContext<'static>>>::new(
608+
NeonObject::new(
609609
neon_context_holder.clone(),
610610
neon_context_holder
611611
.with_context(|cx| cx.argument::<JsValue>(0))
612612
.unwrap()?,
613-
));
613+
)
614+
.unwrap(),
615+
);
614616

615617
let safe_call_fn = neon_context_holder
616618
.with_context(|cx| {
@@ -635,7 +637,7 @@ fn build_sql_and_params(cx: FunctionContext) -> JsResult<JsValue> {
635637
let res = base_query.build_sql_and_params();
636638

637639
let result: NeonObject<FunctionContext<'static>> = res.into_object();
638-
let result = result.into_object();
640+
let result = result.get_object().unwrap();
639641
Ok(result)
640642
})
641643
}

rust/cubenativeutils/src/wrappers/neon/context.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,47 +229,47 @@ impl<C: Context<'static> + 'static> NativeContext<NeonInnerTypes<C>> for Context
229229
let obj = NeonObject::new(
230230
self.clone(),
231231
self.with_context(|cx| cx.boolean(v).upcast())?,
232-
);
232+
)?;
233233
obj.into_boolean()
234234
}
235235

236236
fn string(&self, v: String) -> Result<NeonString<C>, CubeError> {
237-
let obj = NeonObject::new(self.clone(), self.with_context(|cx| cx.string(v).upcast())?);
237+
let obj = NeonObject::new(self.clone(), self.with_context(|cx| cx.string(v).upcast())?)?;
238238
obj.into_string()
239239
}
240240

241241
fn number(&self, v: f64) -> Result<NeonNumber<C>, CubeError> {
242-
let obj = NeonObject::new(self.clone(), self.with_context(|cx| cx.number(v).upcast())?);
242+
let obj = NeonObject::new(self.clone(), self.with_context(|cx| cx.number(v).upcast())?)?;
243243
obj.into_number()
244244
}
245245

246246
fn undefined(&self) -> Result<NativeObjectHandle<NeonInnerTypes<C>>, CubeError> {
247247
Ok(NativeObjectHandle::new(NeonObject::new(
248248
self.clone(),
249249
self.with_context(|cx| cx.undefined().upcast())?,
250-
)))
250+
)?))
251251
}
252252

253253
fn null(&self) -> Result<NativeObjectHandle<NeonInnerTypes<C>>, CubeError> {
254254
Ok(NativeObjectHandle::new(NeonObject::new(
255255
self.clone(),
256256
self.with_context(|cx| cx.null().upcast())?,
257-
)))
257+
)?))
258258
}
259259

260260
fn empty_array(&self) -> Result<NeonArray<C>, CubeError> {
261261
let obj = NeonObject::new(
262262
self.clone(),
263263
self.with_context(|cx| cx.empty_array().upcast())?,
264-
);
264+
)?;
265265
obj.into_array()
266266
}
267267

268268
fn empty_struct(&self) -> Result<NeonStruct<C>, CubeError> {
269269
let obj = NeonObject::new(
270270
self.clone(),
271271
self.with_context(|cx| cx.empty_object().upcast())?,
272-
);
272+
)?;
273273
obj.into_struct()
274274
}
275275
fn to_string_fn(&self, result: String) -> Result<NeonFunction<C>, CubeError> {
@@ -280,7 +280,7 @@ impl<C: Context<'static> + 'static> NativeContext<NeonInnerTypes<C>> for Context
280280
.unwrap()
281281
.upcast()
282282
})?,
283-
);
283+
)?;
284284
obj.into_function()
285285
}
286286
}
Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,84 @@
1-
use super::{NeonObject, NeonTypeHandle};
21
use super::primitive_root_holder::*;
2+
use super::{NeonObject, RootHolder};
33
use crate::wrappers::neon::inner_types::NeonInnerTypes;
4-
use std::marker::PhantomData;
54

6-
use crate::wrappers::object::{NativeBoolean, NativeBox, NativeNumber, NativeString, NativeType};
5+
use crate::wrappers::object::{NativeBoolean, NativeNumber, NativeString, NativeType};
76
use cubesql::CubeError;
87
use neon::prelude::*;
9-
use std::ops::Deref;
108

119
pub struct NeonString<C: Context<'static>> {
12-
object: NeonTypeHandle<C, JsString>,
10+
holder: PrimitiveNeonTypeHolder<C, JsString>,
1311
}
1412

1513
impl<C: Context<'static>> NeonString<C> {
16-
pub fn new(object: NeonTypeHandle<C, JsString>) -> Self {
17-
Self { object }
14+
pub fn new(holder: PrimitiveNeonTypeHolder<C, JsString>) -> Self {
15+
Self { holder }
1816
}
1917
}
2018

2119
impl<C: Context<'static> + 'static> NativeType<NeonInnerTypes<C>> for NeonString<C> {
2220
fn into_object(self) -> NeonObject<C> {
23-
self.object.upcast()
21+
let root_holder = RootHolder::from_typed(self.holder);
22+
NeonObject::form_root(root_holder)
2423
}
2524
}
2625

2726
impl<C: Context<'static> + 'static> NativeString<NeonInnerTypes<C>> for NeonString<C> {
2827
fn value(&self) -> Result<String, CubeError> {
29-
self.object
28+
self.holder
3029
.map_neon_object::<_, _>(|cx, object| Ok(object.value(cx)))?
3130
}
3231
}
3332

3433
pub struct NeonNumber<C: Context<'static>> {
35-
object: NeonTypeHandle<C, JsNumber>,
34+
holder: PrimitiveNeonTypeHolder<C, JsNumber>,
3635
}
3736

3837
impl<C: Context<'static>> NeonNumber<C> {
39-
pub fn new(object: NeonTypeHandle<C, JsNumber>) -> Self {
40-
Self { object }
38+
pub fn new(holder: PrimitiveNeonTypeHolder<C, JsNumber>) -> Self {
39+
Self { holder }
4140
}
4241
}
4342

4443
impl<C: Context<'static> + 'static> NativeType<NeonInnerTypes<C>> for NeonNumber<C> {
4544
fn into_object(self) -> NeonObject<C> {
46-
self.object.upcast()
45+
let root_holder = RootHolder::from_typed(self.holder);
46+
NeonObject::form_root(root_holder)
4747
}
4848
}
4949

5050
impl<C: Context<'static> + 'static> NativeNumber<NeonInnerTypes<C>> for NeonNumber<C> {
5151
fn value(&self) -> Result<f64, CubeError> {
52-
self.object
52+
self.holder
5353
.map_neon_object::<_, _>(|cx, object| Ok(object.value(cx)))?
5454
}
5555
}
5656

5757
pub struct NeonBoolean<C: Context<'static>> {
58-
object: NeonTypeHandle<C, JsBoolean>,
58+
holder: PrimitiveNeonTypeHolder<C, JsBoolean>,
5959
}
6060

6161
impl<C: Context<'static>> NeonBoolean<C> {
62-
pub fn new(object: NeonTypeHandle<C, JsBoolean>) -> Self {
63-
Self { object }
62+
pub fn new(holder: PrimitiveNeonTypeHolder<C, JsBoolean>) -> Self {
63+
Self { holder }
6464
}
6565
}
6666

6767
impl<C: Context<'static> + 'static> NativeType<NeonInnerTypes<C>> for NeonBoolean<C> {
6868
fn into_object(self) -> NeonObject<C> {
69-
self.object.upcast()
69+
let root_holder = RootHolder::from_typed(self.holder);
70+
NeonObject::form_root(root_holder)
7071
}
7172
}
7273

7374
impl<C: Context<'static> + 'static> NativeBoolean<NeonInnerTypes<C>> for NeonBoolean<C> {
7475
fn value(&self) -> Result<bool, CubeError> {
75-
self.object
76+
self.holder
7677
.map_neon_object::<_, _>(|cx, object| Ok(object.value(cx)))?
7778
}
7879
}
7980

80-
pub struct NeonBox<C: Context<'static>, T: 'static> {
81+
/* pub struct NeonBox<C: Context<'static>, T: 'static> {
8182
object: NeonTypeHandle<C, JsBox<T>>,
8283
_marker: PhantomData<T>,
8384
}
@@ -101,4 +102,4 @@ impl<C: Context<'static> + 'static, T: 'static> NativeBox<NeonInnerTypes<C>, T>
101102
fn deref_value(&self) -> &T {
102103
self.object.get_object_ref().deref()
103104
}
104-
}
105+
} */

rust/cubenativeutils/src/wrappers/neon/object/mod.rs

Lines changed: 1 addition & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -7,176 +7,7 @@ pub mod object_root_holder;
77
pub mod primitive_root_holder;
88
pub mod root_holder;
99

10-
use neon_object::*;
10+
pub use neon_object::*;
1111
use object_root_holder::*;
1212
use primitive_root_holder::*;
1313
use root_holder::*;
14-
15-
use self::{
16-
base_types::{NeonBoolean, NeonNumber, NeonString},
17-
neon_array::NeonArray,
18-
neon_function::NeonFunction,
19-
neon_struct::NeonStruct,
20-
};
21-
use super::inner_types::NeonInnerTypes;
22-
use crate::wrappers::{
23-
neon::context::{ContextHolder, SafeCallFn},
24-
object::NativeObject,
25-
};
26-
use cubesql::CubeError;
27-
use neon::prelude::*;
28-
29-
pub struct NeonTypeHandle<C: Context<'static>, V: Value + 'static> {
30-
context: ContextHolder<C>,
31-
object: Handle<'static, V>,
32-
}
33-
34-
impl<C: Context<'static> + 'static, V: Value + 'static> NeonTypeHandle<C, V> {
35-
pub fn new(context: ContextHolder<C>, object: Handle<'static, V>) -> Self {
36-
Self { context, object }
37-
}
38-
39-
fn get_context(&self) -> ContextHolder<C> {
40-
self.context.clone()
41-
}
42-
43-
pub fn get_object(&self) -> Handle<'static, V> {
44-
self.object
45-
}
46-
47-
pub fn get_object_ref(&self) -> &Handle<'static, V> {
48-
&self.object
49-
}
50-
51-
pub fn into_object(self) -> Handle<'static, V> {
52-
self.object
53-
}
54-
55-
pub fn upcast(&self) -> NeonObject<C> {
56-
NeonObject::new(self.context.clone(), self.object.upcast())
57-
}
58-
59-
pub fn map_neon_object<T, F>(&self, f: F) -> Result<T, CubeError>
60-
where
61-
F: FnOnce(&mut C, &Handle<'static, V>) -> T,
62-
{
63-
self.context.with_context(|cx| f(cx, &self.object))
64-
}
65-
66-
pub fn map_neon_object_with_safe_call_fn<T, F>(&self, f: F) -> Result<T, CubeError>
67-
where
68-
F: FnOnce(&mut C, &Handle<'static, V>, SafeCallFn) -> T,
69-
{
70-
self.context
71-
.with_context_and_safe_fn(|cx, safe_call_fn| f(cx, &self.object, safe_call_fn))
72-
}
73-
74-
pub fn is_a<U: Value>(&self) -> Result<bool, CubeError> {
75-
self.context.with_context(|cx| self.object.is_a::<U, _>(cx))
76-
}
77-
}
78-
79-
impl<C: Context<'static>, V: Value + 'static> Clone for NeonTypeHandle<C, V> {
80-
fn clone(&self) -> Self {
81-
Self {
82-
context: self.context.clone(),
83-
object: self.object,
84-
}
85-
}
86-
}
87-
88-
pub struct NeonObject<C: Context<'static>> {
89-
context: ContextHolder<C>,
90-
object: Handle<'static, JsValue>,
91-
}
92-
93-
impl<C: Context<'static> + 'static> NeonObject<C> {
94-
pub fn new(context: ContextHolder<C>, object: Handle<'static, JsValue>) -> Self {
95-
Self { context, object }
96-
}
97-
98-
pub fn get_object(&self) -> Handle<'static, JsValue> {
99-
self.object
100-
}
101-
102-
pub fn get_object_ref(&self) -> &Handle<'static, JsValue> {
103-
&self.object
104-
}
105-
106-
pub fn into_object(self) -> Handle<'static, JsValue> {
107-
self.object
108-
}
109-
110-
pub fn is_a<U: Value>(&self) -> Result<bool, CubeError> {
111-
self.context.with_context(|cx| self.object.is_a::<U, _>(cx))
112-
}
113-
114-
pub fn downcast<U: Value>(&self) -> Result<NeonTypeHandle<C, U>, CubeError> {
115-
let obj = self.context.with_context(|cx| {
116-
self.object
117-
.downcast::<U, _>(cx)
118-
.map_err(|_| CubeError::internal("Downcast error".to_string()))
119-
})??;
120-
Ok(NeonTypeHandle::new(self.context.clone(), obj))
121-
}
122-
123-
pub fn downcast_with_err_msg<U: Value>(
124-
&self,
125-
msg: &str,
126-
) -> Result<NeonTypeHandle<C, U>, CubeError> {
127-
let obj = self.context.with_context(|cx| {
128-
self.object
129-
.downcast::<U, _>(cx)
130-
.map_err(|_| CubeError::internal(msg.to_string()))
131-
})??;
132-
Ok(NeonTypeHandle::new(self.context.clone(), obj))
133-
}
134-
}
135-
136-
impl<C: Context<'static> + 'static> NativeObject<NeonInnerTypes<C>> for NeonObject<C> {
137-
fn get_context(&self) -> ContextHolder<C> {
138-
self.context.clone()
139-
}
140-
141-
fn into_struct(self) -> Result<NeonStruct<C>, CubeError> {
142-
let obj = self.downcast_with_err_msg::<JsObject>("NeonObject is not the JsObject")?;
143-
Ok(NeonStruct::new(obj))
144-
}
145-
fn into_function(self) -> Result<NeonFunction<C>, CubeError> {
146-
let obj = self.downcast_with_err_msg::<JsFunction>("NeonObject is not the JsArray")?;
147-
Ok(NeonFunction::new(obj))
148-
}
149-
fn into_array(self) -> Result<NeonArray<C>, CubeError> {
150-
let obj = self.downcast_with_err_msg::<JsArray>("NeonObject is not the JsArray")?;
151-
Ok(NeonArray::new(obj))
152-
}
153-
fn into_string(self) -> Result<NeonString<C>, CubeError> {
154-
let obj = self.downcast_with_err_msg::<JsString>("NeonObject is not the JsString")?;
155-
Ok(NeonString::new(obj))
156-
}
157-
fn into_number(self) -> Result<NeonNumber<C>, CubeError> {
158-
let obj = self.downcast_with_err_msg::<JsNumber>("NeonObject is not the JsNumber")?;
159-
Ok(NeonNumber::new(obj))
160-
}
161-
fn into_boolean(self) -> Result<NeonBoolean<C>, CubeError> {
162-
let obj = self.downcast_with_err_msg::<JsBoolean>("NeonObject is not the JsBoolean")?;
163-
Ok(NeonBoolean::new(obj))
164-
}
165-
166-
fn is_null(&self) -> Result<bool, CubeError> {
167-
self.is_a::<JsNull>()
168-
}
169-
170-
fn is_undefined(&self) -> Result<bool, CubeError> {
171-
self.is_a::<JsUndefined>()
172-
}
173-
}
174-
175-
impl<C: Context<'static>> Clone for NeonObject<C> {
176-
fn clone(&self) -> Self {
177-
Self {
178-
context: self.context.clone(),
179-
object: self.object,
180-
}
181-
}
182-
}

0 commit comments

Comments
 (0)