Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Replace deprecated v8::Handle with v8::Local
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenfarrar committed May 2, 2019
1 parent 8e0ff2b commit a9c3511
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 33 deletions.
9 changes: 4 additions & 5 deletions gjstest/internal/cpp/run_tests.cc
Expand Up @@ -39,7 +39,6 @@
using v8::Array; using v8::Array;
using v8::Context; using v8::Context;
using v8::Function; using v8::Function;
using v8::Handle;
using v8::HandleScope; using v8::HandleScope;
using v8::Isolate; using v8::Isolate;
using v8::Local; using v8::Local;
Expand Down Expand Up @@ -135,7 +134,7 @@ static Local<Function> GetFunctionNamed(
static void ProcessTestCase( static void ProcessTestCase(
v8::Isolate* const isolate, v8::Isolate* const isolate,
const string& name, const string& name,
const Handle<Function>& test_function, const Local<Function>& test_function,
bool* success, bool* success,
string* output, string* output,
std::unordered_map<std::string, string>* test_failure_messages, std::unordered_map<std::string, string>* test_failure_messages,
Expand Down Expand Up @@ -176,7 +175,7 @@ static void ProcessTestCase(
static void ProcessTestSuite( static void ProcessTestSuite(
v8::Isolate* const isolate, v8::Isolate* const isolate,
const RE2& test_filter, const RE2& test_filter,
const Handle<Object>& test_functions, const Local<Object>& test_functions,
bool* success, bool* success,
string* output, string* output,
std::vector<string>* tests_run, std::vector<string>* tests_run,
Expand Down Expand Up @@ -225,7 +224,7 @@ bool RunTests(


// Create a context in which to run scripts and ensure that it's used whenever // Create a context in which to run scripts and ensure that it's used whenever
// a context is needed below. // 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); const Context::Scope context_scope(context);


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


// Get the map of test functions registered for this test suite. // 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 = const Local<Value> test_functions_value =
get_test_functions->Call( get_test_functions->Call(
context->Global(), context->Global(),
Expand Down
11 changes: 5 additions & 6 deletions gjstest/internal/cpp/test_case.cc
Expand Up @@ -22,7 +22,6 @@


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


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


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


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


// Create a test environment. // 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 = const Local<Object> test_env =
test_env_constructor test_env_constructor
->NewInstance(isolate_->GetCurrentContext(), arraysize(test_env_args), ->NewInstance(isolate_->GetCurrentContext(), arraysize(test_env_args),
Expand All @@ -124,7 +123,7 @@ void TestCase::Run() {


// Run the test. // Run the test.
TryCatch try_catch(isolate_); TryCatch try_catch(isolate_);
Handle<Value> args[] = { test_function_, test_env }; Local<Value> args[] = { test_function_, test_env };
const Local<Value> result = const Local<Value> result =
run_test->Call( run_test->Call(
isolate_->GetCurrentContext()->Global(), isolate_->GetCurrentContext()->Global(),
Expand Down
8 changes: 4 additions & 4 deletions gjstest/internal/cpp/test_case.h
Expand Up @@ -34,7 +34,7 @@ class TestCase {
// gjstest.registerTestCase. // gjstest.registerTestCase.
TestCase( TestCase(
v8::Isolate* isolate, 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 // 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 // context is currently active in which all of the test's dependencies have
Expand All @@ -57,7 +57,7 @@ class TestCase {


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


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


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


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


DISALLOW_COPY_AND_ASSIGN(TestCase); DISALLOW_COPY_AND_ASSIGN(TestCase);
Expand Down
7 changes: 3 additions & 4 deletions gjstest/internal/cpp/v8_utils.cc
Expand Up @@ -28,7 +28,6 @@ using v8::Context;
using v8::External; using v8::External;
using v8::Function; using v8::Function;
using v8::FunctionTemplate; using v8::FunctionTemplate;
using v8::Handle;
using v8::Isolate; using v8::Isolate;
using v8::Local; using v8::Local;
using v8::MaybeLocal; using v8::MaybeLocal;
Expand Down Expand Up @@ -91,14 +90,14 @@ static Local<String> ConvertString(
s.size()); 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); const String::Utf8Value utf8_value(isolate, value);
return std::string(*utf8_value, utf8_value.length()); return std::string(*utf8_value, utf8_value.length());
} }


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


Expand Down
8 changes: 4 additions & 4 deletions gjstest/internal/cpp/v8_utils.h
Expand Up @@ -37,12 +37,12 @@ IsolateHandle CreateIsolate();


// Convert the supplied value to a UTF-8 string. // Convert the supplied value to a UTF-8 string.
std::string ConvertToString(v8::Isolate* isolate, 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. // Convert the supplied value, which must be an array, into a vector of strings.
void ConvertToStringVector( void ConvertToStringVector(
v8::Isolate* isolate, v8::Isolate* isolate,
const v8::Handle<v8::Value>& value, const v8::Local<v8::Value>& value,
std::vector<std::string>* result); std::vector<std::string>* result);


// Execute the supplied string as JS in the current context, returning the // Execute the supplied string as JS in the current context, returning the
Expand All @@ -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 // C++ functions exported by v8 must accept a FunctionCallbackInfo<Value> object
// and return a handle to a Value. // and return a handle to a Value.
typedef std::function< typedef std::function<
v8::Handle<v8::Value>(const v8::FunctionCallbackInfo<v8::Value>&)> v8::Local<v8::Value>(const v8::FunctionCallbackInfo<v8::Value>&)>
V8FunctionCallback; V8FunctionCallback;


// Export a JS function with the given name in the supplied template, invoking // Export a JS function with the given name in the supplied template, invoking
Expand All @@ -75,7 +75,7 @@ void RegisterFunction(
v8::Isolate* isolate, v8::Isolate* isolate,
const std::string& name, const std::string& name,
V8FunctionCallback* callback, 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 // 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 // when invoked. The callback must continue to exist for as long as the function
Expand Down
19 changes: 9 additions & 10 deletions gjstest/internal/cpp/v8_utils_test.cc
Expand Up @@ -29,7 +29,6 @@ using testing::HasSubstr;


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


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


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


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


// Create a template that exports two functions to add to the two counters. // 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( RegisterFunction(
"addToCounter1", "addToCounter1",
Expand All @@ -331,7 +330,7 @@ TEST_F(RegisterFunctionTest, CallsAppropriateCallback) {


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


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


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

0 comments on commit a9c3511

Please sign in to comment.