Commit cd43b83b authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

[snapshot] extend test case for serializing externals.

R=jgruber@chromium.org

Change-Id: I887d31bcb55a52de6fa984bd9b5854f90182cf1f
Reviewed-on: https://chromium-review.googlesource.com/983776Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52280}
parent 5d728ef4
......@@ -2284,8 +2284,17 @@ TEST(SnapshotCreatorMultipleContexts) {
delete[] blob.data;
}
static int serialized_static_field = 314;
static void SerializedCallback(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Data()->IsExternal()) {
CHECK_EQ(args.Data().As<v8::External>()->Value(),
static_cast<void*>(&serialized_static_field));
int* value =
reinterpret_cast<int*>(args.Data().As<v8::External>()->Value());
(*value)++;
}
args.GetReturnValue().Set(v8_num(42));
}
......@@ -2308,8 +2317,6 @@ static void AccessorForSerialization(
info.GetReturnValue().Set(v8_num(2017));
}
static int serialized_static_field = 314;
class SerializedExtension : public v8::Extension {
public:
SerializedExtension()
......@@ -2639,8 +2646,10 @@ TEST(SnapshotCreatorTemplates) {
v8::ExtensionConfiguration* no_extension = nullptr;
v8::Local<v8::ObjectTemplate> global_template =
v8::ObjectTemplate::New(isolate);
v8::Local<v8::External> external =
v8::External::New(isolate, &serialized_static_field);
v8::Local<v8::FunctionTemplate> callback =
v8::FunctionTemplate::New(isolate, SerializedCallback);
v8::FunctionTemplate::New(isolate, SerializedCallback, external);
global_template->Set(v8_str("f"), callback);
v8::Local<v8::Context> context =
v8::Context::New(isolate, no_extension, global_template);
......@@ -2652,6 +2661,7 @@ TEST(SnapshotCreatorTemplates) {
v8::Context::Scope context_scope(context);
ExpectInt32("f()", 42);
CHECK_EQ(315, serialized_static_field);
v8::Local<v8::Object> a =
object_template->NewInstance(context).ToLocalChecked();
......@@ -2707,6 +2717,7 @@ TEST(SnapshotCreatorTemplates) {
.ToLocalChecked();
v8::Context::Scope context_scope(context);
ExpectInt32("f()", 42);
CHECK_EQ(316, serialized_static_field);
// Retrieve the snapshotted object template.
v8::Local<v8::ObjectTemplate> obj_template =
......@@ -2716,6 +2727,7 @@ TEST(SnapshotCreatorTemplates) {
obj_template->NewInstance(context).ToLocalChecked();
CHECK(context->Global()->Set(context, v8_str("o"), object).FromJust());
ExpectInt32("o.f()", 42);
CHECK_EQ(317, serialized_static_field);
// Check that it instantiates to the same prototype.
ExpectTrue("o.f.prototype === f.prototype");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment