Commit 3efe2c5e authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

Fix deprecated V8 function use in V8UnitTest

Fixes use of deprecated Object::Get/Set V8 functions by instead using
the Context version and checking the return values.

Bug: v8:7283, v8:8562
Change-Id: Idf2b5b596a431ad249d9bbcbf8f295537b2bab80
Reviewed-on: https://chromium-review.googlesource.com/c/1452177
Auto-Submit: Dan Elphick <delphick@chromium.org>
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629121}
parent bc47faf4
...@@ -97,10 +97,13 @@ bool V8UnitTest::RunJavascriptTestF(const std::string& test_fixture, ...@@ -97,10 +97,13 @@ bool V8UnitTest::RunJavascriptTestF(const std::string& test_fixture,
v8::MicrotasksScope microtasks( v8::MicrotasksScope microtasks(
isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Local<v8::Value> function_property = context->Global()->Get( v8::Local<v8::Value> function_property =
v8::String::NewFromUtf8(isolate, "runTest", context->Global()
v8::NewStringType::kInternalized) ->Get(context,
.ToLocalChecked()); v8::String::NewFromUtf8(isolate, "runTest",
v8::NewStringType::kInternalized)
.ToLocalChecked())
.ToLocalChecked();
EXPECT_FALSE(function_property.IsEmpty()); EXPECT_FALSE(function_property.IsEmpty());
if (::testing::Test::HasNonfatalFailure()) if (::testing::Test::HasNonfatalFailure())
return false; return false;
...@@ -111,14 +114,20 @@ bool V8UnitTest::RunJavascriptTestF(const std::string& test_fixture, ...@@ -111,14 +114,20 @@ bool V8UnitTest::RunJavascriptTestF(const std::string& test_fixture,
v8::Local<v8::Function>::Cast(function_property); v8::Local<v8::Function>::Cast(function_property);
v8::Local<v8::Array> params = v8::Array::New(isolate); v8::Local<v8::Array> params = v8::Array::New(isolate);
params->Set(0, v8::String::NewFromUtf8(isolate, test_fixture.data(), params
v8::NewStringType::kNormal, ->Set(context, 0,
test_fixture.size()) v8::String::NewFromUtf8(isolate, test_fixture.data(),
.ToLocalChecked()); v8::NewStringType::kNormal,
params->Set( test_fixture.size())
1, v8::String::NewFromUtf8(isolate, test_name.data(), .ToLocalChecked())
v8::NewStringType::kNormal, test_name.size()) .Check();
.ToLocalChecked()); params
->Set(
context, 1,
v8::String::NewFromUtf8(isolate, test_name.data(),
v8::NewStringType::kNormal, test_name.size())
.ToLocalChecked())
.Check();
v8::Local<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
v8::Boolean::New(isolate, false), v8::Boolean::New(isolate, false),
v8::String::NewFromUtf8(isolate, "RUN_TEST_F", v8::NewStringType::kNormal) v8::String::NewFromUtf8(isolate, "RUN_TEST_F", v8::NewStringType::kNormal)
...@@ -224,7 +233,7 @@ void V8UnitTest::SetUp() { ...@@ -224,7 +233,7 @@ void V8UnitTest::SetUp() {
v8::NewStringType::kInternalized) v8::NewStringType::kInternalized)
.ToLocalChecked(), .ToLocalChecked(),
console->NewInstance(context).ToLocalChecked()) console->NewInstance(context).ToLocalChecked())
.ToChecked(); .Check();
} }
} }
...@@ -234,14 +243,16 @@ void V8UnitTest::SetGlobalStringVar(const std::string& var_name, ...@@ -234,14 +243,16 @@ void V8UnitTest::SetGlobalStringVar(const std::string& var_name,
v8::Local<v8::Context> context = v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate, context_); v8::Local<v8::Context>::New(isolate, context_);
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
context->Global()->Set( context->Global()
v8::String::NewFromUtf8(isolate, var_name.c_str(), ->Set(context,
v8::NewStringType::kInternalized, v8::String::NewFromUtf8(isolate, var_name.c_str(),
var_name.length()) v8::NewStringType::kInternalized,
.ToLocalChecked(), var_name.length())
v8::String::NewFromUtf8(isolate, value.c_str(), .ToLocalChecked(),
v8::NewStringType::kNormal, value.length()) v8::String::NewFromUtf8(isolate, value.c_str(),
.ToLocalChecked()); v8::NewStringType::kNormal, value.length())
.ToLocalChecked())
.Check();
} }
void V8UnitTest::ExecuteScriptInContext(const base::StringPiece& script_source, void V8UnitTest::ExecuteScriptInContext(const base::StringPiece& script_source,
...@@ -306,10 +317,13 @@ void V8UnitTest::TestFunction(const std::string& function_name) { ...@@ -306,10 +317,13 @@ void V8UnitTest::TestFunction(const std::string& function_name) {
v8::MicrotasksScope microtasks( v8::MicrotasksScope microtasks(
isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Local<v8::Value> function_property = context->Global()->Get( v8::Local<v8::Value> function_property =
v8::String::NewFromUtf8(isolate, function_name.c_str(), context->Global()
v8::NewStringType::kInternalized) ->Get(context,
.ToLocalChecked()); v8::String::NewFromUtf8(isolate, function_name.c_str(),
v8::NewStringType::kInternalized)
.ToLocalChecked())
.ToLocalChecked();
ASSERT_FALSE(function_property.IsEmpty()); ASSERT_FALSE(function_property.IsEmpty());
ASSERT_TRUE(function_property->IsFunction()); ASSERT_TRUE(function_property->IsFunction());
v8::Local<v8::Function> function = v8::Local<v8::Function> function =
...@@ -354,9 +368,12 @@ void V8UnitTest::ChromeSend(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -354,9 +368,12 @@ void V8UnitTest::ChromeSend(const v8::FunctionCallbackInfo<v8::Value>& args) {
EXPECT_EQ(2U, test_result->Length()); EXPECT_EQ(2U, test_result->Length());
if (::testing::Test::HasNonfatalFailure()) if (::testing::Test::HasNonfatalFailure())
return; return;
g_test_result_ok = test_result->Get(0)->BooleanValue(isolate); v8::Local<v8::Context> context = isolate->GetCurrentContext();
g_test_result_ok =
test_result->Get(context, 0).ToLocalChecked()->BooleanValue(isolate);
if (!g_test_result_ok) { if (!g_test_result_ok) {
v8::String::Utf8Value message(isolate, test_result->Get(1)); v8::String::Utf8Value message(
isolate, test_result->Get(context, 1).ToLocalChecked());
LOG(ERROR) << *message; LOG(ERROR) << *message;
} }
} }
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