Skip to content
Permalink
Browse files

Replace deprecated v8::Handle with v8::Local

  • Loading branch information...
stephenfarrar committed May 2, 2019
1 parent 8e0ff2b commit a9c3511359385cd178508713fdc76315babae27b
@@ -39,7 +39,6 @@
using v8::Array;
using v8::Context;
using v8::Function;
using v8::Handle;
using v8::HandleScope;
using v8::Isolate;
using v8::Local;
@@ -135,7 +134,7 @@ static Local<Function> GetFunctionNamed(
static void ProcessTestCase(
v8::Isolate* const isolate,
const string& name,
const Handle<Function>& test_function,
const Local<Function>& test_function,
bool* success,
string* output,
std::unordered_map<std::string, string>* test_failure_messages,
@@ -176,7 +175,7 @@ static void ProcessTestCase(
static void ProcessTestSuite(
v8::Isolate* const isolate,
const RE2& test_filter,
const Handle<Object>& test_functions,
const Local<Object>& test_functions,
bool* success,
string* output,
std::vector<string>* tests_run,
@@ -225,7 +224,7 @@ bool RunTests(

// Create a context in which to run scripts and ensure that it's used whenever
// a context is needed below.
const Handle<Context> context(Context::New(isolate.get()));
const Local<Context> context(Context::New(isolate.get()));
const Context::Scope context_scope(context);

// Run all of the scripts.
@@ -273,7 +272,7 @@ bool RunTests(
CHECK(test_suite->IsObject());

// Get the map of test functions registered for this test suite.
Handle<Value> args[] = { test_suite };
Local<Value> args[] = { test_suite };
const Local<Value> test_functions_value =
get_test_functions->Call(
context->Global(),
@@ -22,7 +22,6 @@

using v8::Context;
using v8::Function;
using v8::Handle;
using v8::Isolate;
using v8::Local;
using v8::Object;
@@ -41,7 +40,7 @@ Local<Function> TestCase::GetFunctionNamed(const string& name) const {
}

// Log the supplied string to the test's output.
v8::Handle<v8::Value> TestCase::LogString(
v8::Local<v8::Value> TestCase::LogString(
const v8::FunctionCallbackInfo<v8::Value>& cb_info) {
CHECK_EQ(1, cb_info.Length());
const string message = ConvertToString(isolate_, cb_info[0]);
@@ -52,7 +51,7 @@ v8::Handle<v8::Value> TestCase::LogString(

// Record the test as having failed, and extract a failure message from the JS
// arguments and append it to the existing messages, if any.
v8::Handle<v8::Value> TestCase::RecordFailure(
v8::Local<v8::Value> TestCase::RecordFailure(
const v8::FunctionCallbackInfo<v8::Value>& cb_info) {
CHECK_EQ(1, cb_info.Length());
const string message = ConvertToString(isolate_, cb_info[0]);
@@ -66,7 +65,7 @@ v8::Handle<v8::Value> TestCase::RecordFailure(

TestCase::TestCase(
v8::Isolate* const isolate,
const Handle<Function>& test_function)
const Local<Function>& test_function)
: isolate_(CHECK_NOTNULL(isolate)),
test_function_(test_function) {
CHECK(test_function_->IsFunction());
@@ -115,7 +114,7 @@ void TestCase::Run() {
&report_failure_cb);

// Create a test environment.
Handle<Value> test_env_args[] = { log, report_failure, get_current_stack };
Local<Value> test_env_args[] = { log, report_failure, get_current_stack };
const Local<Object> test_env =
test_env_constructor
->NewInstance(isolate_->GetCurrentContext(), arraysize(test_env_args),
@@ -124,7 +123,7 @@ void TestCase::Run() {

// Run the test.
TryCatch try_catch(isolate_);
Handle<Value> args[] = { test_function_, test_env };
Local<Value> args[] = { test_function_, test_env };
const Local<Value> result =
run_test->Call(
isolate_->GetCurrentContext()->Global(),
@@ -34,7 +34,7 @@ class TestCase {
// gjstest.registerTestCase.
TestCase(
v8::Isolate* isolate,
const v8::Handle<v8::Function>& test_function);
const v8::Local<v8::Function>& test_function);

// Run the test case and fill in the properties below. It is assumed that a
// context is currently active in which all of the test's dependencies have
@@ -57,7 +57,7 @@ class TestCase {

private:
v8::Isolate* const isolate_;
const v8::Handle<v8::Function> test_function_;
const v8::Local<v8::Function> test_function_;

///////////////////////////////////
// Helpers
@@ -66,10 +66,10 @@ class TestCase {
v8::Local<v8::Function> GetFunctionNamed(
const string& name) const;

v8::Handle<v8::Value> LogString(
v8::Local<v8::Value> LogString(
const v8::FunctionCallbackInfo<v8::Value>& cb_info);

v8::Handle<v8::Value> RecordFailure(
v8::Local<v8::Value> RecordFailure(
const v8::FunctionCallbackInfo<v8::Value>& cb_info);

DISALLOW_COPY_AND_ASSIGN(TestCase);
@@ -28,7 +28,6 @@ using v8::Context;
using v8::External;
using v8::Function;
using v8::FunctionTemplate;
using v8::Handle;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
@@ -91,14 +90,14 @@ static Local<String> ConvertString(
s.size());
}

std::string ConvertToString(v8::Isolate* isolate, const Handle<Value>& value) {
std::string ConvertToString(v8::Isolate* isolate, const Local<Value>& value) {
const String::Utf8Value utf8_value(isolate, value);
return std::string(*utf8_value, utf8_value.length());
}

void ConvertToStringVector(
v8::Isolate* const isolate,
const v8::Handle<v8::Value>& value,
const v8::Local<v8::Value>& value,
std::vector<std::string>* result) {
CHECK(!value.IsEmpty()) << "value must be non-empty";
CHECK(value->IsArray()) << "value must be an array";
@@ -188,7 +187,7 @@ void RegisterFunction(
Isolate* const isolate,
const std::string& name,
V8FunctionCallback* callback,
Handle<ObjectTemplate>* tmpl) {
Local<ObjectTemplate>* tmpl) {
// Wrap up the callback in an External that can be decoded later.
const Local<Value> data = External::New(isolate, CHECK_NOTNULL(callback));

@@ -37,12 +37,12 @@ IsolateHandle CreateIsolate();

// Convert the supplied value to a UTF-8 string.
std::string ConvertToString(v8::Isolate* isolate,
const v8::Handle<v8::Value>& value);
const v8::Local<v8::Value>& value);

// Convert the supplied value, which must be an array, into a vector of strings.
void ConvertToStringVector(
v8::Isolate* isolate,
const v8::Handle<v8::Value>& value,
const v8::Local<v8::Value>& value,
std::vector<std::string>* result);

// Execute the supplied string as JS in the current context, returning the
@@ -64,7 +64,7 @@ std::string DescribeError(v8::Isolate*, const v8::TryCatch& try_catch);
// C++ functions exported by v8 must accept a FunctionCallbackInfo<Value> object
// and return a handle to a Value.
typedef std::function<
v8::Handle<v8::Value>(const v8::FunctionCallbackInfo<v8::Value>&)>
v8::Local<v8::Value>(const v8::FunctionCallbackInfo<v8::Value>&)>
V8FunctionCallback;

// Export a JS function with the given name in the supplied template, invoking
@@ -75,7 +75,7 @@ void RegisterFunction(
v8::Isolate* isolate,
const std::string& name,
V8FunctionCallback* callback,
v8::Handle<v8::ObjectTemplate>* tmpl);
v8::Local<v8::ObjectTemplate>* tmpl);

// Create a JS function with the supplied name that calls the given callback
// when invoked. The callback must continue to exist for as long as the function
@@ -29,7 +29,6 @@ using testing::HasSubstr;

using v8::Context;
using v8::Function;
using v8::Handle;
using v8::HandleScope;
using v8::Integer;
using v8::Isolate;
@@ -50,7 +49,7 @@ namespace gjstest {
class V8UtilsTest : public ::testing::Test {
protected:
void ConvertToStringVector(
const v8::Handle<v8::Value>& value,
const v8::Local<v8::Value>& value,
std::vector<std::string>* const result) {
return ::gjstest::ConvertToStringVector(
isolate_.get(),
@@ -82,7 +81,7 @@ class V8UtilsTest : public ::testing::Test {
void RegisterFunction(
const std::string& name,
V8FunctionCallback* const callback,
v8::Handle<v8::ObjectTemplate>* const tmpl) {
v8::Local<v8::ObjectTemplate>* const tmpl) {
return ::gjstest::RegisterFunction(
isolate_.get(),
name,
@@ -103,11 +102,11 @@ class V8UtilsTest : public ::testing::Test {
const v8::Isolate::Scope isolate_scope_{ isolate_.get() };

const HandleScope handle_scope_{ isolate_.get() };
const Handle<ObjectTemplate> global_template_{
const Local<ObjectTemplate> global_template_{
ObjectTemplate::New(isolate_.get()),
};

const Handle<Context> context_{
const Local<Context> context_{
Context::New(
isolate_.get(),
nullptr, // No extensions
@@ -287,7 +286,7 @@ TEST_F(ConvertToStringVectorTest, NonEmptyArray) {
// RegisterFunction
////////////////////////////////////////////////////////////////////////

static Handle<Value> AddToCounter(
static Local<Value> AddToCounter(
Isolate* const isolate,
uint32* counter,
const v8::FunctionCallbackInfo<Value>& cb_info) {
@@ -317,7 +316,7 @@ TEST_F(RegisterFunctionTest, CallsAppropriateCallback) {
std::placeholders::_1);

// Create a template that exports two functions to add to the two counters.
Handle<ObjectTemplate> global_template = ObjectTemplate::New(isolate_.get());
Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate_.get());

RegisterFunction(
"addToCounter1",
@@ -331,7 +330,7 @@ TEST_F(RegisterFunctionTest, CallsAppropriateCallback) {

// Create a context in which to run scripts and ensure that it's used whenever
// a context is needed below. Export the global functions configured above.
const Handle<Context> context(
const Local<Context> context(
Context::New(
CHECK_NOTNULL(isolate_.get()),
NULL, // No extensions
@@ -373,8 +372,8 @@ TEST_F(MakeFunctionTest, Name) {
TEST_F(MakeFunctionTest, CallsCallback) {
ASSERT_FALSE(func_.IsEmpty());

Handle<Value> one_args[] = { MakeInteger(1) };
Handle<Value> seventeen_args[] = { MakeInteger(17) };
Local<Value> one_args[] = { MakeInteger(1) };
Local<Value> seventeen_args[] = { MakeInteger(17) };

func_->Call(
isolate_.get()->GetCurrentContext()->Global(),

0 comments on commit a9c3511

Please sign in to comment.
You can’t perform that action at this time.