mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-21 20:28:58 +00:00
Add String::get_external_string_resource_base and get_external_string_resource (#1396)
This commit is contained in:
parent
eb48d037c9
commit
e04dc7baf4
3
.gn
3
.gn
@ -70,6 +70,9 @@ default_args = {
|
|||||||
# fails to compile.
|
# fails to compile.
|
||||||
v8_enable_maglev = false
|
v8_enable_maglev = false
|
||||||
|
|
||||||
|
# Enable V8 object print for debugging.
|
||||||
|
# v8_enable_object_print = true
|
||||||
|
|
||||||
# Enable Deno-specific extra bindings
|
# Enable Deno-specific extra bindings
|
||||||
deno_enable_extras = true
|
deno_enable_extras = true
|
||||||
}
|
}
|
||||||
|
@ -1033,6 +1033,16 @@ int v8__String__WriteUtf8(const v8::String& self, v8::Isolate* isolate,
|
|||||||
return self.WriteUtf8(isolate, buffer, length, nchars_ref, options);
|
return self.WriteUtf8(isolate, buffer, length, nchars_ref, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const v8::String::ExternalStringResource* v8__String__GetExternalStringResource(
|
||||||
|
const v8::String& self) {
|
||||||
|
return self.GetExternalStringResource();
|
||||||
|
}
|
||||||
|
|
||||||
|
const v8::String::ExternalStringResourceBase* v8__String__GetExternalStringResourceBase(
|
||||||
|
const v8::String& self, v8::String::Encoding* encoding_out) {
|
||||||
|
return self.GetExternalStringResourceBase(encoding_out);
|
||||||
|
}
|
||||||
|
|
||||||
class ExternalStaticOneByteStringResource
|
class ExternalStaticOneByteStringResource
|
||||||
: public v8::String::ExternalOneByteStringResource {
|
: public v8::String::ExternalOneByteStringResource {
|
||||||
public:
|
public:
|
||||||
|
@ -2,11 +2,13 @@ use std::borrow::Cow;
|
|||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::mem::MaybeUninit;
|
use std::mem::MaybeUninit;
|
||||||
|
use std::ptr::NonNull;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
use crate::support::char;
|
use crate::support::char;
|
||||||
use crate::support::int;
|
use crate::support::int;
|
||||||
use crate::support::size_t;
|
use crate::support::size_t;
|
||||||
|
use crate::support::Opaque;
|
||||||
use crate::HandleScope;
|
use crate::HandleScope;
|
||||||
use crate::Isolate;
|
use crate::Isolate;
|
||||||
use crate::Local;
|
use crate::Local;
|
||||||
@ -69,6 +71,14 @@ extern "C" {
|
|||||||
options: WriteOptions,
|
options: WriteOptions,
|
||||||
) -> int;
|
) -> int;
|
||||||
|
|
||||||
|
fn v8__String__GetExternalStringResource(
|
||||||
|
this: *const String,
|
||||||
|
) -> *mut ExternalStringResource;
|
||||||
|
fn v8__String__GetExternalStringResourceBase(
|
||||||
|
this: *const String,
|
||||||
|
encoding: *mut Encoding,
|
||||||
|
) -> *mut ExternalOneByteStringResourceBase;
|
||||||
|
|
||||||
fn v8__String__NewExternalOneByte(
|
fn v8__String__NewExternalOneByte(
|
||||||
isolate: *mut Isolate,
|
isolate: *mut Isolate,
|
||||||
onebyte_const: *const OneByteConst,
|
onebyte_const: *const OneByteConst,
|
||||||
@ -95,6 +105,19 @@ extern "C" {
|
|||||||
fn v8__String__ContainsOnlyOneByte(this: *const String) -> bool;
|
fn v8__String__ContainsOnlyOneByte(this: *const String) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub enum Encoding {
|
||||||
|
Unknown = 0,
|
||||||
|
OneByte = 1,
|
||||||
|
TwoByte = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct ExternalStringResource(Opaque);
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct ExternalOneByteStringResourceBase(Opaque);
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct OneByteConst {
|
pub struct OneByteConst {
|
||||||
@ -500,6 +523,27 @@ impl String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the ExternalStringResource for an external string.
|
||||||
|
//
|
||||||
|
// Returns None if is_external() doesn't return true.
|
||||||
|
pub fn get_external_string_resource(
|
||||||
|
&self,
|
||||||
|
) -> Option<NonNull<ExternalStringResource>> {
|
||||||
|
NonNull::new(unsafe { v8__String__GetExternalStringResource(self) })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_external_string_resource_base(
|
||||||
|
&self,
|
||||||
|
) -> (Option<NonNull<ExternalOneByteStringResourceBase>>, Encoding) {
|
||||||
|
let mut encoding = Encoding::Unknown;
|
||||||
|
(
|
||||||
|
NonNull::new(unsafe {
|
||||||
|
v8__String__GetExternalStringResourceBase(self, &mut encoding)
|
||||||
|
}),
|
||||||
|
encoding,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// True if string is external
|
/// True if string is external
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_external(&self) -> bool {
|
pub fn is_external(&self) -> bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user