Repository navigation
src: use per-type tags for cppgc wrappers #67131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ void CppgcMixin::Wrap(T* ptr, Realm* realm, v8::Local<v8::Object> obj) { | |
| ptr->traced_reference_ = v8::TracedReference<v8::Object>(isolate, obj); | ||
| // Note that ptr must be of concrete type T in Wrap. | ||
| auto* wrappable = static_cast<v8::Object::Wrappable*>(ptr); | ||
| v8::Object::Wrap<v8::CppHeapPointerTag::kDefaultTag>(isolate, obj, wrappable); | ||
| v8::Object::Wrap<T::kCppHeapPointerTag>(isolate, obj, wrappable); | ||
| // Keep the layout consistent with BaseObjects. | ||
| obj->SetAlignedPointerInInternalField( | ||
| kEmbedderType, | ||
|
|
@@ -32,19 +32,13 @@ void CppgcMixin::Wrap(T* ptr, Environment* env, v8::Local<v8::Object> obj) { | |
|
|
||
| template <typename T> | ||
| T* CppgcMixin::Unwrap(v8::Local<v8::Object> obj) { | ||
| // We are not using v8::Object::Unwrap currently because that requires | ||
| // access to isolate which the ASSIGN_OR_RETURN_UNWRAP macro that we'll shim | ||
| // with ASSIGN_OR_RETURN_UNWRAP_GC doesn't take, and we also want a | ||
| // signature consistent with BaseObject::Unwrap() to avoid churn. Since | ||
| // cppgc-managed objects share the same layout as BaseObjects, just unwrap | ||
| // from the pointer in the internal field, which should be valid as long as | ||
| // the object is still alive. | ||
| // The isolate is not passed in to keep the signature consistent with | ||
| // BaseObject::Unwrap() and the ASSIGN_OR_RETURN_UNWRAP_CPPGC macro. | ||
| if (obj->InternalFieldCount() != T::kInternalFieldCount) { | ||
| return nullptr; | ||
| } | ||
| T* ptr = static_cast<T*>(obj->GetAlignedPointerFromInternalField( | ||
| T::kSlot, EmbedderDataTag::kDefault)); | ||
| return ptr; | ||
| return v8::Object::Unwrap<T::kCppHeapPointerTag, T>(v8::Isolate::GetCurrent(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically every caller of |
||
| obj); | ||
| } | ||
|
|
||
| v8::Local<v8::Object> CppgcMixin::object() const { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I think the setter of
T::kSlotabove inWrapseems redundant now if this usesv8::Object::Unwrap.