Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions gjstest/internal/cpp/run_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,16 @@ static void ProcessTestSuite(
std::unordered_map<std::string, double>* test_durations) {
StringAppendF(output, "[----------]\n");

const Local<Array> test_names = test_functions->GetPropertyNames();
const Local<Array> test_names =
test_functions->GetPropertyNames(isolate->GetCurrentContext())
.ToLocalChecked();
for (uint32 i = 0; i < test_names->Length(); ++i) {
const Local<Value> name = test_names->Get(i);
const Local<Value> test_function = test_functions->Get(name);
CHECK(test_function->IsFunction());

// Skip this test if it doesn't match our filter.
const string string_name = ConvertToString(name);
const string string_name = ConvertToString(isolate, name);
if (!RE2::FullMatch(string_name, test_filter)) continue;

tests_run->push_back(string_name);
Expand Down Expand Up @@ -279,9 +281,10 @@ bool RunTests(
Handle<Value> args[] = { test_suite };
const Local<Value> test_functions_value =
get_test_functions->Call(
isolate.get()->GetCurrentContext(),
context->Global(),
arraysize(args),
args);
args).ToLocalChecked();
CHECK(test_functions_value->IsObject());
const Local<Object> test_functions =
Local<Object>::Cast(test_functions_value);
Expand Down Expand Up @@ -329,7 +332,7 @@ bool RunTests(

CHECK(coverage_result->IsString());

*coverage_info += ConvertToString(coverage_result);
*coverage_info += ConvertToString(isolate.get(), coverage_result);
}

return success;
Expand Down
11 changes: 7 additions & 4 deletions gjstest/internal/cpp/test_case.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using v8::Function;
using v8::Handle;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
using v8::TryCatch;
using v8::Value;
Expand All @@ -42,7 +43,7 @@ Local<Function> TestCase::GetFunctionNamed(const string& name) const {
v8::Handle<v8::Value> TestCase::LogString(
const v8::FunctionCallbackInfo<v8::Value>& cb_info) {
CHECK_EQ(1, cb_info.Length());
const string message = ConvertToString(cb_info[0]);
const string message = ConvertToString(isolate_, cb_info[0]);
StringAppendF(&this->output, "%s\n", message.c_str());

return v8::Undefined(isolate_);
Expand All @@ -53,7 +54,7 @@ v8::Handle<v8::Value> TestCase::LogString(
v8::Handle<v8::Value> TestCase::RecordFailure(
const v8::FunctionCallbackInfo<v8::Value>& cb_info) {
CHECK_EQ(1, cb_info.Length());
const string message = ConvertToString(cb_info[0]);
const string message = ConvertToString(isolate_, cb_info[0]);

this->succeeded = false;
StringAppendF(&this->output, "%s\n\n", message.c_str());
Expand Down Expand Up @@ -123,14 +124,16 @@ void TestCase::Run() {
// Run the test.
TryCatch try_catch(isolate_);
Handle<Value> args[] = { test_function_, test_env };
const Local<Value> result =
const MaybeLocal<Value> maybe_result =
run_test->Call(
isolate_->GetCurrentContext(),
isolate_->GetCurrentContext()->Global(),
arraysize(args),
args);

// Was there an exception while running the test?
if (result.IsEmpty()) {
Local<Value> result;
if (!maybe_result.ToLocal(&result)) {
succeeded = false;

const string description = DescribeError(try_catch);
Expand Down
28 changes: 18 additions & 10 deletions gjstest/internal/cpp/v8_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ static Local<String> ConvertString(
return String::NewFromUtf8(
isolate,
s.data(),
String::kNormalString,
s.size());
v8::NewStringType::kNormal,
s.size()).ToLocalChecked();
}

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

Expand All @@ -106,7 +107,7 @@ void ConvertToStringVector(
const uint32 length = array->Length();

for (uint32 i = 0; i < length; ++i) {
result->push_back(ConvertToString(array->Get(i)));
result->push_back(ConvertToString(isolate, array->Get(i)));
}
}

Expand Down Expand Up @@ -139,7 +140,11 @@ Local<Value> ExecuteJs(
}

// Run the script.
auto result = script->BindToCurrentContext()->Run();
Local<Value> result;
if (!script->BindToCurrentContext()->Run(isolate->GetCurrentContext())
.ToLocal(&result)) {
return Local<Value>();
}

// Give v8 a chance to process any foreground tasks that are pending.
while (v8::platform::PumpMessageLoop(platform_, isolate)) {}
Expand All @@ -148,8 +153,10 @@ Local<Value> ExecuteJs(
}

std::string DescribeError(const TryCatch& try_catch) {
const std::string exception = ConvertToString(try_catch.Exception());
const Local<Message> message = try_catch.Message();
Isolate* const isolate = message->GetIsolate();
const std::string exception =
ConvertToString(isolate, try_catch.Exception());

// If there's no message, just return the exception.
if (message.IsEmpty()) return exception;
Expand All @@ -159,8 +166,9 @@ std::string DescribeError(const TryCatch& try_catch) {
// foo.js:7: ReferenceError: blah is not defined.
//
const std::string filename =
ConvertToString(message->GetScriptResourceName());
const int line = message->GetLineNumber();
ConvertToString(message->GetIsolate(), message->GetScriptResourceName());
const int line = message->GetLineNumber(isolate->GetCurrentContext())
.ToChecked();

// Sometimes for multi-line errors there is no line number.
if (!line) {
Expand Down Expand Up @@ -219,7 +227,7 @@ Local<Function> MakeFunction(
isolate,
RunAssociatedCallback,
data)
->GetFunction();
->GetFunction(isolate->GetCurrentContext()).ToLocalChecked();

result->SetName(ConvertString(isolate, name));

Expand Down
3 changes: 2 additions & 1 deletion gjstest/internal/cpp/v8_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ typedef std::shared_ptr<v8::Isolate> IsolateHandle;
IsolateHandle CreateIsolate();

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

// Convert the supplied value, which must be an array, into a vector of strings.
void ConvertToStringVector(
Expand Down