Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Oct 20, 2024
1 parent dda9da4 commit 974e426
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fn build_binding() {
.allowlist_item("v8__.*")
.allowlist_item("cppgc__.*")
.allowlist_item("RustObj")
.allowlist_item("ExternalConstOneByteStringResource")
.generate()
.expect("Unable to generate bindings");

Expand Down
25 changes: 0 additions & 25 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1124,31 +1124,6 @@ class ExternalStaticOneByteStringResource
const int _length;
};

// NOTE: This class is never used and only serves as a reference for
// the OneByteConst struct created on Rust-side.
class ExternalConstOneByteStringResource
: public v8::String::ExternalOneByteStringResource {
public:
ExternalConstOneByteStringResource(int length) : _length(length) {
static_assert(offsetof(ExternalConstOneByteStringResource, _length) ==
sizeof(size_t) * 2,
"ExternalConstOneByteStringResource's length was not at "
"offset of sizeof(size_t) * 2");
static_assert(
sizeof(ExternalConstOneByteStringResource) == sizeof(size_t) * 3,
"ExternalConstOneByteStringResource size was not sizeof(size_t) * 3");
static_assert(
alignof(ExternalConstOneByteStringResource) == sizeof(size_t),
"ExternalConstOneByteStringResource align was not sizeof(size_t)");
}
const char* data() const override { return nullptr; }
size_t length() const override { return _length; }
void Dispose() override {}

private:
const int _length;
};

const v8::String* v8__String__NewExternalOneByteConst(
v8::Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
return maybe_local_to_ptr(v8::String::NewExternalOneByte(isolate, resource));
Expand Down
25 changes: 25 additions & 0 deletions src/binding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,28 @@ static uint32_t v8__MINOR_VERSION = V8_MINOR_VERSION;
static uint32_t v8__BUILD_NUMBER = V8_BUILD_NUMBER;
static uint32_t v8__PATCH_LEVEL = V8_PATCH_LEVEL;
static const char* v8__VERSION_STRING = V8_VERSION_STRING;

// NOTE: This class is never used and only serves as a reference for
// the OneByteConst struct created on Rust-side.
class ExternalConstOneByteStringResource
: public v8::String::ExternalOneByteStringResource {
public:
ExternalConstOneByteStringResource(int length) : _length(length) {
static_assert(offsetof(ExternalConstOneByteStringResource, _length) ==
sizeof(size_t) * 2,
"ExternalConstOneByteStringResource's length was not at "
"offset of sizeof(size_t) * 2");
static_assert(
sizeof(ExternalConstOneByteStringResource) == sizeof(size_t) * 3,
"ExternalConstOneByteStringResource size was not sizeof(size_t) * 3");
static_assert(
alignof(ExternalConstOneByteStringResource) == sizeof(size_t),
"ExternalConstOneByteStringResource align was not sizeof(size_t)");
}
const char* data() const override { return nullptr; }
size_t length() const override { return _length; }
void Dispose() override {}

private:
const int _length;
};
4 changes: 4 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,13 @@ extern "C" fn one_byte_const_length(this: *const OneByteConst) -> usize {
// SAFETY: Only called from C++ with a valid OneByteConst pointer.
unsafe { (*this).length }
}
extern "C" fn one_byte_const_unaccount(_isolate: *mut Isolate) {}

type OneByteConstNoOp = extern "C" fn(*const OneByteConst);
type OneByteConstIsCacheable = extern "C" fn(*const OneByteConst) -> bool;
type OneByteConstData = extern "C" fn(*const OneByteConst) -> *const char;
type OneByteConstLength = extern "C" fn(*const OneByteConst) -> usize;
type OneByteConstUnaccount = extern "C" fn(*mut Isolate);

#[repr(C)]
struct OneByteConstVtable {
Expand Down Expand Up @@ -279,6 +281,7 @@ struct OneByteConstVtable {
#[cfg(not(target_family = "windows"))]
delete2: OneByteConstNoOp,
is_cacheable: OneByteConstIsCacheable,
unaccount: OneByteConstUnaccount,
dispose: OneByteConstNoOp,
lock: OneByteConstNoOp,
unlock: OneByteConstNoOp,
Expand All @@ -294,6 +297,7 @@ const ONE_BYTE_CONST_VTABLE: OneByteConstVtable = OneByteConstVtable {
#[cfg(not(target_family = "windows"))]
delete2: one_byte_const_no_op,
is_cacheable: one_byte_const_is_cacheable,
unaccount: one_byte_const_unaccount,
dispose: one_byte_const_no_op,
lock: one_byte_const_no_op,
unlock: one_byte_const_no_op,
Expand Down

0 comments on commit 974e426

Please sign in to comment.