[serializer] pass internal fields deserializer callback as argument.
Background to this is that blink needs to be able to pass different internal fields deserialization callbacks for individual to-be-deserialized contexts. R=jochen@chromium.org, peria@chromium.org BUG=chromium:617892 Review-Url: https://codereview.chromium.org/2619203002 Cr-Commit-Position: refs/heads/master@{#42132}
This commit is contained in:
parent
4805790c60
commit
081193d5b1
23
include/v8.h
23
include/v8.h
@ -6307,8 +6307,7 @@ class V8_EXPORT Isolate {
|
||||
create_histogram_callback(nullptr),
|
||||
add_histogram_sample_callback(nullptr),
|
||||
array_buffer_allocator(nullptr),
|
||||
external_references(nullptr),
|
||||
deserialize_internal_fields_callback(nullptr) {}
|
||||
external_references(nullptr) {}
|
||||
|
||||
/**
|
||||
* The optional entry_hook allows the host application to provide the
|
||||
@ -6364,12 +6363,6 @@ class V8_EXPORT Isolate {
|
||||
* entire lifetime of the isolate.
|
||||
*/
|
||||
intptr_t* external_references;
|
||||
|
||||
/**
|
||||
* Specifies an optional callback to deserialize internal fields. It
|
||||
* should match the SerializeInternalFieldCallback used to serialize.
|
||||
*/
|
||||
DeserializeInternalFieldsCallback deserialize_internal_fields_callback;
|
||||
};
|
||||
|
||||
|
||||
@ -7676,9 +7669,12 @@ class V8_EXPORT SnapshotCreator {
|
||||
* Add additional context to be included in the snapshot blob.
|
||||
* The snapshot will include the global proxy.
|
||||
*
|
||||
* \param callback optional callback to serialize internal fields.
|
||||
*
|
||||
* \returns the index of the context in the snapshot blob.
|
||||
*/
|
||||
size_t AddContext(Local<Context> context);
|
||||
size_t AddContext(Local<Context> context,
|
||||
SerializeInternalFieldsCallback callback = nullptr);
|
||||
|
||||
/**
|
||||
* Add a template to be included in the snapshot blob.
|
||||
@ -7691,12 +7687,10 @@ class V8_EXPORT SnapshotCreator {
|
||||
* This must not be called from within a handle scope.
|
||||
* \param function_code_handling whether to include compiled function code
|
||||
* in the snapshot.
|
||||
* \param callback to serialize embedder-set internal fields.
|
||||
* \returns { nullptr, 0 } on failure, and a startup snapshot on success. The
|
||||
* caller acquires ownership of the data array in the return value.
|
||||
*/
|
||||
StartupData CreateBlob(FunctionCodeHandling function_code_handling,
|
||||
SerializeInternalFieldsCallback callback = nullptr);
|
||||
StartupData CreateBlob(FunctionCodeHandling function_code_handling);
|
||||
|
||||
// Disallow copying and assigning.
|
||||
SnapshotCreator(const SnapshotCreator&) = delete;
|
||||
@ -8009,6 +8003,10 @@ class V8_EXPORT Context {
|
||||
* \param context_snapshot_index The index of the context snapshot to
|
||||
* deserialize from. Use v8::Context::New for the default snapshot.
|
||||
*
|
||||
* \param internal_fields_deserializer Optional callback to deserialize
|
||||
* internal fields. It should match the SerializeInternalFieldCallback used
|
||||
* to serialize.
|
||||
*
|
||||
* \param extensions See v8::Context::New.
|
||||
*
|
||||
* \param global_object See v8::Context::New.
|
||||
@ -8016,6 +8014,7 @@ class V8_EXPORT Context {
|
||||
|
||||
static MaybeLocal<Context> FromSnapshot(
|
||||
Isolate* isolate, size_t context_snapshot_index,
|
||||
DeserializeInternalFieldsCallback internal_fields_deserializer = nullptr,
|
||||
ExtensionConfiguration* extensions = nullptr,
|
||||
MaybeLocal<Value> global_object = MaybeLocal<Value>());
|
||||
|
||||
|
57
src/api.cc
57
src/api.cc
@ -476,6 +476,7 @@ struct SnapshotCreatorData {
|
||||
Persistent<Context> default_context_;
|
||||
PersistentValueVector<Context> contexts_;
|
||||
PersistentValueVector<Template> templates_;
|
||||
std::vector<SerializeInternalFieldsCallback> internal_fields_serializers_;
|
||||
bool created_;
|
||||
};
|
||||
|
||||
@ -522,7 +523,8 @@ void SnapshotCreator::SetDefaultContext(Local<Context> context) {
|
||||
data->default_context_.Reset(isolate, context);
|
||||
}
|
||||
|
||||
size_t SnapshotCreator::AddContext(Local<Context> context) {
|
||||
size_t SnapshotCreator::AddContext(Local<Context> context,
|
||||
SerializeInternalFieldsCallback callback) {
|
||||
DCHECK(!context.IsEmpty());
|
||||
SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
|
||||
DCHECK(!data->created_);
|
||||
@ -530,6 +532,7 @@ size_t SnapshotCreator::AddContext(Local<Context> context) {
|
||||
CHECK_EQ(isolate, context->GetIsolate());
|
||||
size_t index = static_cast<int>(data->contexts_.Size());
|
||||
data->contexts_.Append(context);
|
||||
data->internal_fields_serializers_.push_back(callback);
|
||||
return index;
|
||||
}
|
||||
|
||||
@ -545,8 +548,7 @@ size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) {
|
||||
}
|
||||
|
||||
StartupData SnapshotCreator::CreateBlob(
|
||||
SnapshotCreator::FunctionCodeHandling function_code_handling,
|
||||
SerializeInternalFieldsCallback callback) {
|
||||
SnapshotCreator::FunctionCodeHandling function_code_handling) {
|
||||
SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
|
||||
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_);
|
||||
DCHECK(!data->created_);
|
||||
@ -612,15 +614,16 @@ StartupData SnapshotCreator::CreateBlob(
|
||||
i::List<i::SnapshotData*> context_snapshots(num_additional_contexts + 1);
|
||||
|
||||
{
|
||||
// The default snapshot does not support internal fields.
|
||||
i::PartialSerializer partial_serializer(isolate, &startup_serializer,
|
||||
callback);
|
||||
nullptr);
|
||||
partial_serializer.Serialize(&default_context, false);
|
||||
context_snapshots.Add(new i::SnapshotData(&partial_serializer));
|
||||
}
|
||||
|
||||
for (int i = 0; i < num_additional_contexts; i++) {
|
||||
i::PartialSerializer partial_serializer(isolate, &startup_serializer,
|
||||
callback);
|
||||
i::PartialSerializer partial_serializer(
|
||||
isolate, &startup_serializer, data->internal_fields_serializers_[i]);
|
||||
partial_serializer.Serialize(&contexts[i], true);
|
||||
context_snapshots.Add(new i::SnapshotData(&partial_serializer));
|
||||
}
|
||||
@ -6170,10 +6173,11 @@ struct InvokeBootstrapper<i::Context> {
|
||||
i::Handle<i::Context> Invoke(
|
||||
i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
|
||||
v8::Local<v8::ObjectTemplate> global_object_template,
|
||||
v8::ExtensionConfiguration* extensions, size_t context_snapshot_index) {
|
||||
v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer) {
|
||||
return isolate->bootstrapper()->CreateEnvironment(
|
||||
maybe_global_proxy, global_object_template, extensions,
|
||||
context_snapshot_index);
|
||||
context_snapshot_index, internal_fields_deserializer);
|
||||
}
|
||||
};
|
||||
|
||||
@ -6182,7 +6186,8 @@ struct InvokeBootstrapper<i::JSGlobalProxy> {
|
||||
i::Handle<i::JSGlobalProxy> Invoke(
|
||||
i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
|
||||
v8::Local<v8::ObjectTemplate> global_object_template,
|
||||
v8::ExtensionConfiguration* extensions, size_t context_snapshot_index) {
|
||||
v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer) {
|
||||
USE(extensions);
|
||||
USE(context_snapshot_index);
|
||||
return isolate->bootstrapper()->NewRemoteContext(maybe_global_proxy,
|
||||
@ -6194,7 +6199,8 @@ template <typename ObjectType>
|
||||
static i::Handle<ObjectType> CreateEnvironment(
|
||||
i::Isolate* isolate, v8::ExtensionConfiguration* extensions,
|
||||
v8::MaybeLocal<ObjectTemplate> maybe_global_template,
|
||||
v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index) {
|
||||
v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer) {
|
||||
i::Handle<ObjectType> result;
|
||||
|
||||
// Enter V8 via an ENTER_V8 scope.
|
||||
@ -6244,8 +6250,9 @@ static i::Handle<ObjectType> CreateEnvironment(
|
||||
}
|
||||
// Create the environment.
|
||||
InvokeBootstrapper<ObjectType> invoke;
|
||||
result = invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions,
|
||||
context_snapshot_index);
|
||||
result =
|
||||
invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions,
|
||||
context_snapshot_index, internal_fields_deserializer);
|
||||
|
||||
// Restore the access check info on the global template.
|
||||
if (!maybe_global_template.IsEmpty()) {
|
||||
@ -6262,20 +6269,20 @@ static i::Handle<ObjectType> CreateEnvironment(
|
||||
return result;
|
||||
}
|
||||
|
||||
Local<Context> NewContext(v8::Isolate* external_isolate,
|
||||
v8::ExtensionConfiguration* extensions,
|
||||
v8::MaybeLocal<ObjectTemplate> global_template,
|
||||
v8::MaybeLocal<Value> global_object,
|
||||
size_t context_snapshot_index) {
|
||||
Local<Context> NewContext(
|
||||
v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions,
|
||||
v8::MaybeLocal<ObjectTemplate> global_template,
|
||||
v8::MaybeLocal<Value> global_object, size_t context_snapshot_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer) {
|
||||
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
|
||||
TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext");
|
||||
LOG_API(isolate, Context, New);
|
||||
i::HandleScope scope(isolate);
|
||||
ExtensionConfiguration no_extensions;
|
||||
if (extensions == NULL) extensions = &no_extensions;
|
||||
i::Handle<i::Context> env =
|
||||
CreateEnvironment<i::Context>(isolate, extensions, global_template,
|
||||
global_object, context_snapshot_index);
|
||||
i::Handle<i::Context> env = CreateEnvironment<i::Context>(
|
||||
isolate, extensions, global_template, global_object,
|
||||
context_snapshot_index, internal_fields_deserializer);
|
||||
if (env.is_null()) {
|
||||
if (isolate->has_pending_exception()) {
|
||||
isolate->OptionalRescheduleException(true);
|
||||
@ -6290,11 +6297,12 @@ Local<Context> v8::Context::New(v8::Isolate* external_isolate,
|
||||
v8::MaybeLocal<ObjectTemplate> global_template,
|
||||
v8::MaybeLocal<Value> global_object) {
|
||||
return NewContext(external_isolate, extensions, global_template,
|
||||
global_object, 0);
|
||||
global_object, 0, nullptr);
|
||||
}
|
||||
|
||||
MaybeLocal<Context> v8::Context::FromSnapshot(
|
||||
v8::Isolate* external_isolate, size_t context_snapshot_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer,
|
||||
v8::ExtensionConfiguration* extensions, MaybeLocal<Value> global_object) {
|
||||
size_t index_including_default_context = context_snapshot_index + 1;
|
||||
if (!i::Snapshot::HasContextSnapshot(
|
||||
@ -6303,7 +6311,8 @@ MaybeLocal<Context> v8::Context::FromSnapshot(
|
||||
return MaybeLocal<Context>();
|
||||
}
|
||||
return NewContext(external_isolate, extensions, MaybeLocal<ObjectTemplate>(),
|
||||
global_object, index_including_default_context);
|
||||
global_object, index_including_default_context,
|
||||
internal_fields_deserializer);
|
||||
}
|
||||
|
||||
MaybeLocal<Object> v8::Context::NewRemoteContext(
|
||||
@ -6325,7 +6334,7 @@ MaybeLocal<Object> v8::Context::NewRemoteContext(
|
||||
"Global template needs to have access check handlers.");
|
||||
i::Handle<i::JSGlobalProxy> global_proxy =
|
||||
CreateEnvironment<i::JSGlobalProxy>(isolate, nullptr, global_template,
|
||||
global_object, 0);
|
||||
global_object, 0, nullptr);
|
||||
if (global_proxy.is_null()) {
|
||||
if (isolate->has_pending_exception()) {
|
||||
isolate->OptionalRescheduleException(true);
|
||||
@ -8057,8 +8066,6 @@ Isolate* Isolate::New(const Isolate::CreateParams& params) {
|
||||
}
|
||||
|
||||
isolate->set_api_external_references(params.external_references);
|
||||
isolate->set_deserialize_internal_fields_callback(
|
||||
params.deserialize_internal_fields_callback);
|
||||
SetResourceConstraints(isolate, params.constraints);
|
||||
// TODO(jochen): Once we got rid of Isolate::Current(), we can remove this.
|
||||
Isolate::Scope isolate_scope(v8_isolate);
|
||||
|
@ -140,7 +140,9 @@ class Genesis BASE_EMBEDDED {
|
||||
public:
|
||||
Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
||||
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
||||
size_t context_snapshot_index, GlobalContextType context_type);
|
||||
size_t context_snapshot_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer,
|
||||
GlobalContextType context_type);
|
||||
Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
||||
v8::Local<v8::ObjectTemplate> global_proxy_template);
|
||||
~Genesis() { }
|
||||
@ -309,10 +311,12 @@ Handle<Context> Bootstrapper::CreateEnvironment(
|
||||
MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
||||
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
||||
v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer,
|
||||
GlobalContextType context_type) {
|
||||
HandleScope scope(isolate_);
|
||||
Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template,
|
||||
context_snapshot_index, context_type);
|
||||
context_snapshot_index, internal_fields_deserializer,
|
||||
context_type);
|
||||
Handle<Context> env = genesis.result();
|
||||
if (env.is_null() || !InstallExtensions(env, extensions)) {
|
||||
return Handle<Context>();
|
||||
@ -4512,10 +4516,12 @@ class NoTrackDoubleFieldsForSerializerScope {
|
||||
bool enabled_;
|
||||
};
|
||||
|
||||
Genesis::Genesis(Isolate* isolate,
|
||||
MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
||||
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
||||
size_t context_snapshot_index, GlobalContextType context_type)
|
||||
Genesis::Genesis(
|
||||
Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
||||
v8::Local<v8::ObjectTemplate> global_proxy_template,
|
||||
size_t context_snapshot_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer,
|
||||
GlobalContextType context_type)
|
||||
: isolate_(isolate), active_(isolate->bootstrapper()) {
|
||||
NoTrackDoubleFieldsForSerializerScope disable_scope(isolate);
|
||||
result_ = Handle<Context>::null();
|
||||
@ -4562,7 +4568,8 @@ Genesis::Genesis(Isolate* isolate,
|
||||
// Also create a context from scratch to expose natives, if required by flag.
|
||||
if (!isolate->initialized_from_snapshot() ||
|
||||
!Snapshot::NewContextFromSnapshot(isolate, global_proxy,
|
||||
context_snapshot_index)
|
||||
context_snapshot_index,
|
||||
internal_fields_deserializer)
|
||||
.ToHandle(&native_context_)) {
|
||||
native_context_ = Handle<Context>();
|
||||
}
|
||||
|
@ -80,6 +80,7 @@ class Bootstrapper final {
|
||||
MaybeHandle<JSGlobalProxy> maybe_global_proxy,
|
||||
v8::Local<v8::ObjectTemplate> global_object_template,
|
||||
v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer,
|
||||
GlobalContextType context_type = FULL_CONTEXT);
|
||||
|
||||
Handle<JSGlobalProxy> NewRemoteContext(
|
||||
|
@ -465,7 +465,7 @@ bool Debug::Load() {
|
||||
static const int kFirstContextSnapshotIndex = 0;
|
||||
Handle<Context> context = isolate_->bootstrapper()->CreateEnvironment(
|
||||
MaybeHandle<JSGlobalProxy>(), v8::Local<ObjectTemplate>(), &no_extensions,
|
||||
kFirstContextSnapshotIndex, DEBUG_CONTEXT);
|
||||
kFirstContextSnapshotIndex, nullptr, DEBUG_CONTEXT);
|
||||
|
||||
// Fail if no context could be created.
|
||||
if (context.is_null()) return false;
|
||||
|
@ -404,8 +404,6 @@ typedef List<HeapObject*> DebugObjectCache;
|
||||
V(intptr_t*, api_external_references, nullptr) \
|
||||
V(AddressToIndexHashMap*, external_reference_map, nullptr) \
|
||||
V(HeapObjectToIndexHashMap*, root_index_map, nullptr) \
|
||||
V(v8::DeserializeInternalFieldsCallback, \
|
||||
deserialize_internal_fields_callback, nullptr) \
|
||||
V(int, pending_microtask_count, 0) \
|
||||
V(int, debug_microtask_count, kDebugPromiseFirstID) \
|
||||
V(HStatistics*, hstatistics, nullptr) \
|
||||
|
@ -112,7 +112,8 @@ void Deserializer::Deserialize(Isolate* isolate) {
|
||||
}
|
||||
|
||||
MaybeHandle<Object> Deserializer::DeserializePartial(
|
||||
Isolate* isolate, Handle<JSGlobalProxy> global_proxy) {
|
||||
Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer) {
|
||||
Initialize(isolate);
|
||||
if (!ReserveSpace()) {
|
||||
V8::FatalProcessOutOfMemory("deserialize context");
|
||||
@ -129,7 +130,7 @@ MaybeHandle<Object> Deserializer::DeserializePartial(
|
||||
Object* root;
|
||||
VisitPointer(&root);
|
||||
DeserializeDeferredObjects();
|
||||
DeserializeInternalFields();
|
||||
DeserializeInternalFields(internal_fields_deserializer);
|
||||
|
||||
isolate->heap()->RegisterReservationsForBlackAllocation(reservations_);
|
||||
|
||||
@ -214,14 +215,13 @@ void Deserializer::DeserializeDeferredObjects() {
|
||||
}
|
||||
}
|
||||
|
||||
void Deserializer::DeserializeInternalFields() {
|
||||
void Deserializer::DeserializeInternalFields(
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer) {
|
||||
if (!source_.HasMore() || source_.Get() != kInternalFieldsData) return;
|
||||
DisallowHeapAllocation no_gc;
|
||||
DisallowJavascriptExecution no_js(isolate_);
|
||||
DisallowCompilation no_compile(isolate_);
|
||||
v8::DeserializeInternalFieldsCallback callback =
|
||||
isolate_->deserialize_internal_fields_callback();
|
||||
DCHECK_NOT_NULL(callback);
|
||||
DCHECK_NOT_NULL(internal_fields_deserializer);
|
||||
for (int code = source_.Get(); code != kSynchronize; code = source_.Get()) {
|
||||
HandleScope scope(isolate_);
|
||||
int space = code & kSpaceMask;
|
||||
@ -233,8 +233,8 @@ void Deserializer::DeserializeInternalFields() {
|
||||
int size = source_.GetInt();
|
||||
byte* data = new byte[size];
|
||||
source_.CopyRaw(data, size);
|
||||
callback(v8::Utils::ToLocal(obj), index,
|
||||
{reinterpret_cast<char*>(data), size});
|
||||
internal_fields_deserializer(v8::Utils::ToLocal(obj), index,
|
||||
{reinterpret_cast<char*>(data), size});
|
||||
delete[] data;
|
||||
}
|
||||
}
|
||||
|
@ -48,8 +48,9 @@ class Deserializer : public SerializerDeserializer {
|
||||
void Deserialize(Isolate* isolate);
|
||||
|
||||
// Deserialize a single object and the objects reachable from it.
|
||||
MaybeHandle<Object> DeserializePartial(Isolate* isolate,
|
||||
Handle<JSGlobalProxy> global_proxy);
|
||||
MaybeHandle<Object> DeserializePartial(
|
||||
Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer);
|
||||
|
||||
// Deserialize an object graph. Fail gracefully.
|
||||
MaybeHandle<HeapObject> DeserializeObject(Isolate* isolate);
|
||||
@ -88,7 +89,8 @@ class Deserializer : public SerializerDeserializer {
|
||||
}
|
||||
|
||||
void DeserializeDeferredObjects();
|
||||
void DeserializeInternalFields();
|
||||
void DeserializeInternalFields(
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer);
|
||||
|
||||
void FlushICacheForNewIsolate();
|
||||
void FlushICacheForNewCodeObjectsAndRecordEmbeddedObjects();
|
||||
|
@ -102,7 +102,10 @@ void PartialSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
|
||||
|
||||
if (obj->IsJSObject()) {
|
||||
JSObject* jsobj = JSObject::cast(obj);
|
||||
if (jsobj->GetInternalFieldCount() > 0) internal_field_holders_.Add(jsobj);
|
||||
if (jsobj->GetInternalFieldCount() > 0) {
|
||||
DCHECK_NOT_NULL(serialize_internal_fields_);
|
||||
internal_field_holders_.Add(jsobj);
|
||||
}
|
||||
}
|
||||
|
||||
// Object has not yet been serialized. Serialize it here.
|
||||
|
@ -50,8 +50,8 @@ bool Snapshot::Initialize(Isolate* isolate) {
|
||||
}
|
||||
|
||||
MaybeHandle<Context> Snapshot::NewContextFromSnapshot(
|
||||
Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
|
||||
size_t context_index) {
|
||||
Isolate* isolate, Handle<JSGlobalProxy> global_proxy, size_t context_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer) {
|
||||
if (!isolate->snapshot_available()) return Handle<Context>();
|
||||
base::ElapsedTimer timer;
|
||||
if (FLAG_profile_deserialization) timer.Start();
|
||||
@ -62,8 +62,8 @@ MaybeHandle<Context> Snapshot::NewContextFromSnapshot(
|
||||
SnapshotData snapshot_data(context_data);
|
||||
Deserializer deserializer(&snapshot_data);
|
||||
|
||||
MaybeHandle<Object> maybe_context =
|
||||
deserializer.DeserializePartial(isolate, global_proxy);
|
||||
MaybeHandle<Object> maybe_context = deserializer.DeserializePartial(
|
||||
isolate, global_proxy, internal_fields_deserializer);
|
||||
Handle<Object> result;
|
||||
if (!maybe_context.ToHandle(&result)) return MaybeHandle<Context>();
|
||||
CHECK(result->IsContext());
|
||||
|
@ -59,7 +59,8 @@ class Snapshot : public AllStatic {
|
||||
// Create a new context using the internal partial snapshot.
|
||||
static MaybeHandle<Context> NewContextFromSnapshot(
|
||||
Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
|
||||
size_t context_index);
|
||||
size_t context_index,
|
||||
v8::DeserializeInternalFieldsCallback internal_fields_deserializer);
|
||||
|
||||
static bool HaveASnapshotToStartFrom(Isolate* isolate);
|
||||
|
||||
|
@ -321,7 +321,7 @@ UNINITIALIZED_TEST(PartialSerializerObject) {
|
||||
{
|
||||
SnapshotData snapshot_data(partial_blob);
|
||||
Deserializer deserializer(&snapshot_data);
|
||||
root = deserializer.DeserializePartial(isolate, global_proxy)
|
||||
root = deserializer.DeserializePartial(isolate, global_proxy, nullptr)
|
||||
.ToHandleChecked();
|
||||
CHECK(root->IsString());
|
||||
}
|
||||
@ -330,7 +330,7 @@ UNINITIALIZED_TEST(PartialSerializerObject) {
|
||||
{
|
||||
SnapshotData snapshot_data(partial_blob);
|
||||
Deserializer deserializer(&snapshot_data);
|
||||
root2 = deserializer.DeserializePartial(isolate, global_proxy)
|
||||
root2 = deserializer.DeserializePartial(isolate, global_proxy, nullptr)
|
||||
.ToHandleChecked();
|
||||
CHECK(root2->IsString());
|
||||
CHECK(root.is_identical_to(root2));
|
||||
@ -419,7 +419,7 @@ UNINITIALIZED_TEST(PartialSerializerContext) {
|
||||
{
|
||||
SnapshotData snapshot_data(partial_blob);
|
||||
Deserializer deserializer(&snapshot_data);
|
||||
root = deserializer.DeserializePartial(isolate, global_proxy)
|
||||
root = deserializer.DeserializePartial(isolate, global_proxy, nullptr)
|
||||
.ToHandleChecked();
|
||||
CHECK(root->IsContext());
|
||||
CHECK(Handle<Context>::cast(root)->global_proxy() == *global_proxy);
|
||||
@ -429,7 +429,7 @@ UNINITIALIZED_TEST(PartialSerializerContext) {
|
||||
{
|
||||
SnapshotData snapshot_data(partial_blob);
|
||||
Deserializer deserializer(&snapshot_data);
|
||||
root2 = deserializer.DeserializePartial(isolate, global_proxy)
|
||||
root2 = deserializer.DeserializePartial(isolate, global_proxy, nullptr)
|
||||
.ToHandleChecked();
|
||||
CHECK(root2->IsContext());
|
||||
CHECK(!root.is_identical_to(root2));
|
||||
@ -539,7 +539,7 @@ UNINITIALIZED_TEST(PartialSerializerCustomContext) {
|
||||
{
|
||||
SnapshotData snapshot_data(partial_blob);
|
||||
Deserializer deserializer(&snapshot_data);
|
||||
root = deserializer.DeserializePartial(isolate, global_proxy)
|
||||
root = deserializer.DeserializePartial(isolate, global_proxy, nullptr)
|
||||
.ToHandleChecked();
|
||||
CHECK(root->IsContext());
|
||||
Handle<Context> context = Handle<Context>::cast(root);
|
||||
@ -2203,6 +2203,8 @@ TEST(SnapshotCreatorTemplates) {
|
||||
global_template->Set(v8_str("f"), callback);
|
||||
v8::Local<v8::Context> context =
|
||||
v8::Context::New(isolate, no_extension, global_template);
|
||||
creator.SetDefaultContext(context);
|
||||
context = v8::Context::New(isolate, no_extension, global_template);
|
||||
v8::Local<v8::ObjectTemplate> object_template =
|
||||
v8::ObjectTemplate::New(isolate);
|
||||
object_template->SetInternalFieldCount(3);
|
||||
@ -2229,12 +2231,12 @@ TEST(SnapshotCreatorTemplates) {
|
||||
c->SetInternalField(2, field_external);
|
||||
CHECK(context->Global()->Set(context, v8_str("a"), a).FromJust());
|
||||
|
||||
creator.SetDefaultContext(context);
|
||||
CHECK_EQ(0u, creator.AddContext(context, SerializeInternalFields));
|
||||
CHECK_EQ(0u, creator.AddTemplate(callback));
|
||||
CHECK_EQ(1u, creator.AddTemplate(global_template));
|
||||
}
|
||||
blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear,
|
||||
SerializeInternalFields);
|
||||
blob =
|
||||
creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
|
||||
|
||||
delete a1;
|
||||
delete b0;
|
||||
@ -2246,14 +2248,15 @@ TEST(SnapshotCreatorTemplates) {
|
||||
params.snapshot_blob = &blob;
|
||||
params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
||||
params.external_references = original_external_references;
|
||||
params.deserialize_internal_fields_callback = DeserializeInternalFields;
|
||||
v8::Isolate* isolate = v8::Isolate::New(params);
|
||||
{
|
||||
v8::Isolate::Scope isolate_scope(isolate);
|
||||
{
|
||||
// Create a new context without a new object template.
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Context> context = v8::Context::New(isolate);
|
||||
v8::Local<v8::Context> context =
|
||||
v8::Context::FromSnapshot(isolate, 0, DeserializeInternalFields)
|
||||
.ToLocalChecked();
|
||||
v8::Context::Scope context_scope(context);
|
||||
ExpectInt32("f()", 42);
|
||||
|
||||
@ -2320,26 +2323,6 @@ TEST(SnapshotCreatorTemplates) {
|
||||
for (auto data : deserialized_data) delete data;
|
||||
deserialized_data.clear();
|
||||
}
|
||||
|
||||
{
|
||||
// Create a context with a new object template. It is merged into the
|
||||
// deserialized global object.
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::ExtensionConfiguration* no_extension = nullptr;
|
||||
v8::Local<v8::ObjectTemplate> global_template =
|
||||
v8::ObjectTemplate::New(isolate);
|
||||
global_template->Set(
|
||||
v8_str("g"),
|
||||
v8::FunctionTemplate::New(isolate, SerializedCallbackReplacement));
|
||||
v8::Local<v8::Context> context =
|
||||
v8::Context::New(isolate, no_extension, global_template);
|
||||
v8::Context::Scope context_scope(context);
|
||||
ExpectInt32("g()", 1337);
|
||||
ExpectInt32("f()", 42);
|
||||
|
||||
for (auto data : deserialized_data) delete data;
|
||||
deserialized_data.clear();
|
||||
}
|
||||
}
|
||||
isolate->Dispose();
|
||||
}
|
||||
@ -2425,10 +2408,10 @@ TEST(SnapshotCreatorIncludeGlobalProxy) {
|
||||
.ToLocalChecked())
|
||||
.FromJust());
|
||||
|
||||
CHECK_EQ(0u, creator.AddContext(context));
|
||||
CHECK_EQ(0u, creator.AddContext(context, SerializeInternalFields));
|
||||
}
|
||||
blob = creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear,
|
||||
SerializeInternalFields);
|
||||
blob =
|
||||
creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
|
||||
}
|
||||
|
||||
{
|
||||
@ -2436,7 +2419,6 @@ TEST(SnapshotCreatorIncludeGlobalProxy) {
|
||||
params.snapshot_blob = &blob;
|
||||
params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
||||
params.external_references = original_external_references;
|
||||
params.deserialize_internal_fields_callback = DeserializeInternalFields;
|
||||
v8::Isolate* isolate = v8::Isolate::New(params);
|
||||
{
|
||||
v8::Isolate::Scope isolate_scope(isolate);
|
||||
@ -2470,7 +2452,8 @@ TEST(SnapshotCreatorIncludeGlobalProxy) {
|
||||
// will use the global object from the snapshot, including interceptor.
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Context> context =
|
||||
v8::Context::FromSnapshot(isolate, 0).ToLocalChecked();
|
||||
v8::Context::FromSnapshot(isolate, 0, DeserializeInternalFields)
|
||||
.ToLocalChecked();
|
||||
{
|
||||
v8::Context::Scope context_scope(context);
|
||||
ExpectInt32("f()", 42);
|
||||
@ -2497,7 +2480,8 @@ TEST(SnapshotCreatorIncludeGlobalProxy) {
|
||||
// New context, but reuse global proxy.
|
||||
v8::ExtensionConfiguration* no_extensions = nullptr;
|
||||
v8::Local<v8::Context> context2 =
|
||||
v8::Context::FromSnapshot(isolate, 0, no_extensions, global)
|
||||
v8::Context::FromSnapshot(isolate, 0, DeserializeInternalFields,
|
||||
no_extensions, global)
|
||||
.ToLocalChecked();
|
||||
{
|
||||
v8::Context::Scope context_scope(context2);
|
||||
|
Loading…
Reference in New Issue
Block a user