Skip to content

Commit

Permalink
deps: v8: [objects] Determine host objects with serializer delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Apr 9, 2023
1 parent 1cda3f3 commit 4765038
Show file tree
Hide file tree
Showing 7 changed files with 15,080 additions and 3 deletions.
14 changes: 14 additions & 0 deletions deps/v8/include/v8-value-serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ class V8_EXPORT ValueSerializer {
*/
virtual void ThrowDataCloneError(Local<String> message) = 0;

/**
* The embedder overrides this method to enable custom host object filter
* with Delegate::IsHostObject.
*
* This method is called at most once per serializer.
*/
virtual bool HasCustomHostObject(Isolate* isolate);

/**
* The embedder overrides this method to determine if an JS object is a
* host object and needs to be serialized by the host.
*/
virtual Maybe<bool> IsHostObject(Isolate* isolate, Local<Object> object);

/**
* The embedder overrides this method to write some kind of host object, if
* possible. If not, a suitable exception should be thrown and
Expand Down
13 changes: 13 additions & 0 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3569,6 +3569,19 @@ Maybe<bool> ValueSerializer::Delegate::WriteHostObject(Isolate* v8_isolate,
return Nothing<bool>();
}

bool ValueSerializer::Delegate::HasCustomHostObject(Isolate* v8_isolate) {
return false;
}

Maybe<bool> ValueSerializer::Delegate::IsHostObject(Isolate* v8_isolate,
Local<Object> object) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
i::Handle<i::JSObject> js_object =
i::Handle<i::JSObject>::cast(Utils::OpenHandle(*object));
return Just<bool>(
i::JSObject::GetEmbedderFieldCount(js_object->map(i_isolate)));
}

Maybe<uint32_t> ValueSerializer::Delegate::GetSharedArrayBufferId(
Isolate* v8_isolate, Local<SharedArrayBuffer> shared_array_buffer) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
Expand Down
Loading

0 comments on commit 4765038

Please sign in to comment.