mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-24 15:19:31 -05:00
to_rust_cow_lossy
This commit is contained in:
parent
ac7fadce6f
commit
8baec0f34f
2 changed files with 20 additions and 24 deletions
|
@ -1228,22 +1228,6 @@ void v8__String__ValueView__DESTRUCT(v8::String::ValueView* self) {
|
||||||
self->~ValueView();
|
self->~ValueView();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool v8__String__ValueView__is_one_byte(const v8::String::ValueView& self) {
|
|
||||||
return self.is_one_byte();
|
|
||||||
}
|
|
||||||
|
|
||||||
const void* v8__String__ValueView__data(const v8::String::ValueView& self) {
|
|
||||||
if (self.is_one_byte()) {
|
|
||||||
return reinterpret_cast<const void*>(self.data8());
|
|
||||||
} else {
|
|
||||||
return reinterpret_cast<const void*>(self.data16());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int v8__String__ValueView__length(const v8::String::ValueView& self) {
|
|
||||||
return self.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
const v8::Symbol* v8__Symbol__New(v8::Isolate* isolate,
|
const v8::Symbol* v8__Symbol__New(v8::Isolate* isolate,
|
||||||
const v8::String* description) {
|
const v8::String* description) {
|
||||||
return local_to_ptr(v8::Symbol::New(isolate, ptr_to_local(description)));
|
return local_to_ptr(v8::Symbol::New(isolate, ptr_to_local(description)));
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::String;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
use std::ffi::c_int;
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
use std::hint::unreachable_unchecked;
|
use std::hint::unreachable_unchecked;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
@ -124,9 +125,14 @@ extern "C" {
|
||||||
string: *const String,
|
string: *const String,
|
||||||
);
|
);
|
||||||
fn v8__String__ValueView__DESTRUCT(this: *mut ValueView);
|
fn v8__String__ValueView__DESTRUCT(this: *mut ValueView);
|
||||||
fn v8__String__ValueView__is_one_byte(this: *const ValueView) -> bool;
|
}
|
||||||
fn v8__String__ValueView__data(this: *const ValueView) -> *const c_void;
|
|
||||||
fn v8__String__ValueView__length(this: *const ValueView) -> int;
|
#[repr(C)]
|
||||||
|
struct ValueViewRaw {
|
||||||
|
flat_str: Local<'static, String>,
|
||||||
|
data: *const c_void,
|
||||||
|
length: c_int,
|
||||||
|
is_one_byte: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
|
@ -1170,12 +1176,18 @@ impl<'s> ValueView<'s> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn data(&self) -> ValueViewData<'_> {
|
pub fn data(&self) -> ValueViewData<'_> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let data = v8__String__ValueView__data(self);
|
let this = &*(self as *const _ as *const ValueViewRaw);
|
||||||
let length = v8__String__ValueView__length(self) as usize;
|
let length = this.length as usize;
|
||||||
if v8__String__ValueView__is_one_byte(self) {
|
if this.is_one_byte {
|
||||||
ValueViewData::OneByte(std::slice::from_raw_parts(data as _, length))
|
ValueViewData::OneByte(std::slice::from_raw_parts(
|
||||||
|
this.data as _,
|
||||||
|
length,
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
ValueViewData::TwoByte(std::slice::from_raw_parts(data as _, length))
|
ValueViewData::TwoByte(std::slice::from_raw_parts(
|
||||||
|
this.data as _,
|
||||||
|
length,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue