Skip to content

Commit

Permalink
Get WrapperTypeInfo via ScriptWrappable
Browse files Browse the repository at this point in the history
as opposed to using a dedicated internal field for that.

Bug: 328117814
Change-Id: I01f9aff3ad8a41fafbd2655d23f076a0f76fdc57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5455405
Reviewed-by: Nate Chapin <japhet@chromium.org>
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1288405}
  • Loading branch information
caseq authored and Chromium LUCI CQ committed Apr 16, 2024
1 parent 6079b17 commit 81b6e3d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Expand Up @@ -271,6 +271,22 @@ void DeserializeInternalFieldCallback(v8::Local<v8::Object> object,
}
}

namespace {
// We only care for WrapperTypeInfo and do not supply an actual instance of
// the document. Since we need a script wrappable to get type info now, this
// class is a minimal implementation of ScriptWrappable that returns correct
// type info for HTMLDocument.
class DummyHTMLDocumentForSnapshot : public ScriptWrappable {
public:
DummyHTMLDocumentForSnapshot() = default;

private:
const WrapperTypeInfo* GetWrapperTypeInfo() const override {
return V8HTMLDocument::GetWrapperTypeInfo();
}
};
} // namespace

void TakeSnapshotForWorld(v8::SnapshotCreator* snapshot_creator,
const DOMWrapperWorld& world) {
v8::Isolate* isolate = snapshot_creator->GetIsolate();
Expand Down Expand Up @@ -300,11 +316,9 @@ void TakeSnapshotForWorld(v8::SnapshotCreator* snapshot_creator,
v8::Local<v8::Object> document_wrapper = CreatePlatformObject(
isolate, context, world, document_wrapper_type_info);

int indices[] = {kV8DOMWrapperObjectIndex, kV8DOMWrapperTypeIndex};
void* values[] = {nullptr,
const_cast<WrapperTypeInfo*>(document_wrapper_type_info)};
document_wrapper->SetAlignedPointerInInternalFields(std::size(indices),
indices, values);
V8DOMWrapper::SetNativeInfo(
isolate, document_wrapper, document_wrapper_type_info,
MakeGarbageCollected<DummyHTMLDocumentForSnapshot>());

V8PrivateProperty::GetWindowDocumentCachedAccessor(isolate).Set(
context->Global(), document_wrapper);
Expand Down
Expand Up @@ -57,13 +57,14 @@ v8::Local<v8::Template> WrapperTypeInfo::GetV8ClassTemplate(
return v8_template;
}

const WrapperTypeInfo* ToWrapperTypeInfo(
const v8::TracedReference<v8::Object>& wrapper) {
return GetInternalField<WrapperTypeInfo, kV8DOMWrapperTypeIndex>(wrapper);
}

const WrapperTypeInfo* ToWrapperTypeInfo(v8::Local<v8::Object> wrapper) {
return GetInternalField<WrapperTypeInfo, kV8DOMWrapperTypeIndex>(wrapper);
const auto* wrappable = ToScriptWrappable(wrapper->GetIsolate(), wrapper);
const WrapperTypeInfo* type_info =
wrappable ? wrappable->GetWrapperTypeInfo() : nullptr;
DCHECK_EQ(
type_info,
(GetInternalField<WrapperTypeInfo, kV8DOMWrapperTypeIndex>(wrapper)));
return type_info;
}

} // namespace blink
Expand Up @@ -206,9 +206,6 @@ inline ScriptWrappable* ToScriptWrappable(v8::Isolate* isolate,
wrapper);
}

PLATFORM_EXPORT const WrapperTypeInfo* ToWrapperTypeInfo(
const v8::TracedReference<v8::Object>& wrapper);

PLATFORM_EXPORT const WrapperTypeInfo* ToWrapperTypeInfo(
v8::Local<v8::Object> wrapper);

Expand Down

0 comments on commit 81b6e3d

Please sign in to comment.