Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(864)

Side by Side Diff: chrome/test/base/v8_unit_test.cc

Issue 1804043002: Revert of Remove V8RecrusionScope, cleanup call sites. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/guest_view/renderer/guest_view_container.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/base/v8_unit_test.h" 5 #include "chrome/test/base/v8_unit_test.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
13 #include "third_party/WebKit/public/web/WebKit.h" 13 #include "third_party/WebKit/public/web/WebKit.h"
14 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
14 15
15 namespace { 16 namespace {
16 17
17 // |args| are passed through the various JavaScript logging functions such as 18 // |args| are passed through the various JavaScript logging functions such as
18 // console.log. Returns a string appropriate for logging with LOG(severity). 19 // console.log. Returns a string appropriate for logging with LOG(severity).
19 std::string LogArgs2String(const v8::FunctionCallbackInfo<v8::Value>& args) { 20 std::string LogArgs2String(const v8::FunctionCallbackInfo<v8::Value>& args) {
20 std::string message; 21 std::string message;
21 bool first = true; 22 bool first = true;
22 for (int i = 0; i < args.Length(); i++) { 23 for (int i = 0; i < args.Length(); i++) {
23 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 24 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 g_test_result_ok = false; 89 g_test_result_ok = false;
89 std::string test_js; 90 std::string test_js;
90 if (!ExecuteJavascriptLibraries()) 91 if (!ExecuteJavascriptLibraries())
91 return false; 92 return false;
92 93
93 v8::Isolate* isolate = blink::mainThreadIsolate(); 94 v8::Isolate* isolate = blink::mainThreadIsolate();
94 v8::HandleScope handle_scope(isolate); 95 v8::HandleScope handle_scope(isolate);
95 v8::Local<v8::Context> context = 96 v8::Local<v8::Context> context =
96 v8::Local<v8::Context>::New(isolate, context_); 97 v8::Local<v8::Context>::New(isolate, context_);
97 v8::Context::Scope context_scope(context); 98 v8::Context::Scope context_scope(context);
98 v8::MicrotasksScope microtasks( 99 blink::WebScopedMicrotaskSuppression microtasks_scope;
99 isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
100 100
101 v8::Local<v8::Value> function_property = 101 v8::Local<v8::Value> function_property =
102 context->Global()->Get(v8::String::NewFromUtf8(isolate, "runTest")); 102 context->Global()->Get(v8::String::NewFromUtf8(isolate, "runTest"));
103 EXPECT_FALSE(function_property.IsEmpty()); 103 EXPECT_FALSE(function_property.IsEmpty());
104 if (::testing::Test::HasNonfatalFailure()) 104 if (::testing::Test::HasNonfatalFailure())
105 return false; 105 return false;
106 EXPECT_TRUE(function_property->IsFunction()); 106 EXPECT_TRUE(function_property->IsFunction());
107 if (::testing::Test::HasNonfatalFailure()) 107 if (::testing::Test::HasNonfatalFailure())
108 return false; 108 return false;
109 v8::Local<v8::Function> function = 109 v8::Local<v8::Function> function =
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 isolate, value.c_str(), v8::String::kNormalString, value.length())); 204 isolate, value.c_str(), v8::String::kNormalString, value.length()));
205 } 205 }
206 206
207 void V8UnitTest::ExecuteScriptInContext(const base::StringPiece& script_source, 207 void V8UnitTest::ExecuteScriptInContext(const base::StringPiece& script_source,
208 const base::StringPiece& script_name) { 208 const base::StringPiece& script_name) {
209 v8::Isolate* isolate = blink::mainThreadIsolate(); 209 v8::Isolate* isolate = blink::mainThreadIsolate();
210 v8::HandleScope handle_scope(isolate); 210 v8::HandleScope handle_scope(isolate);
211 v8::Local<v8::Context> context = 211 v8::Local<v8::Context> context =
212 v8::Local<v8::Context>::New(isolate, context_); 212 v8::Local<v8::Context>::New(isolate, context_);
213 v8::Context::Scope context_scope(context); 213 v8::Context::Scope context_scope(context);
214 v8::MicrotasksScope microtasks( 214 blink::WebScopedMicrotaskSuppression microtasks_scope;
215 isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
216 v8::Local<v8::String> source = 215 v8::Local<v8::String> source =
217 v8::String::NewFromUtf8(isolate, 216 v8::String::NewFromUtf8(isolate,
218 script_source.data(), 217 script_source.data(),
219 v8::String::kNormalString, 218 v8::String::kNormalString,
220 script_source.size()); 219 script_source.size());
221 v8::Local<v8::String> name = 220 v8::Local<v8::String> name =
222 v8::String::NewFromUtf8(isolate, 221 v8::String::NewFromUtf8(isolate,
223 script_name.data(), 222 script_name.data(),
224 v8::String::kNormalString, 223 v8::String::kNormalString,
225 script_name.size()); 224 script_name.size());
(...skipping 28 matching lines...) Expand all
254 } 253 }
255 return str; 254 return str;
256 } 255 }
257 256
258 void V8UnitTest::TestFunction(const std::string& function_name) { 257 void V8UnitTest::TestFunction(const std::string& function_name) {
259 v8::Isolate* isolate = blink::mainThreadIsolate(); 258 v8::Isolate* isolate = blink::mainThreadIsolate();
260 v8::HandleScope handle_scope(isolate); 259 v8::HandleScope handle_scope(isolate);
261 v8::Local<v8::Context> context = 260 v8::Local<v8::Context> context =
262 v8::Local<v8::Context>::New(isolate, context_); 261 v8::Local<v8::Context>::New(isolate, context_);
263 v8::Context::Scope context_scope(context); 262 v8::Context::Scope context_scope(context);
264 v8::MicrotasksScope microtasks( 263 blink::WebScopedMicrotaskSuppression microtasks_scope;
265 isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
266 264
267 v8::Local<v8::Value> function_property = context->Global()->Get( 265 v8::Local<v8::Value> function_property = context->Global()->Get(
268 v8::String::NewFromUtf8(isolate, function_name.c_str())); 266 v8::String::NewFromUtf8(isolate, function_name.c_str()));
269 ASSERT_FALSE(function_property.IsEmpty()); 267 ASSERT_FALSE(function_property.IsEmpty());
270 ASSERT_TRUE(function_property->IsFunction()); 268 ASSERT_TRUE(function_property->IsFunction());
271 v8::Local<v8::Function> function = 269 v8::Local<v8::Function> function =
272 v8::Local<v8::Function>::Cast(function_property); 270 v8::Local<v8::Function>::Cast(function_property);
273 271
274 v8::TryCatch try_catch(isolate); 272 v8::TryCatch try_catch(isolate);
275 v8::Local<v8::Value> result = function->Call(context->Global(), 0, NULL); 273 v8::Local<v8::Value> result = function->Call(context->Global(), 0, NULL);
(...skipping 30 matching lines...) Expand all
306 v8::Local<v8::Array> test_result(args[1].As<v8::Array>()); 304 v8::Local<v8::Array> test_result(args[1].As<v8::Array>());
307 EXPECT_EQ(2U, test_result->Length()); 305 EXPECT_EQ(2U, test_result->Length());
308 if (::testing::Test::HasNonfatalFailure()) 306 if (::testing::Test::HasNonfatalFailure())
309 return; 307 return;
310 g_test_result_ok = test_result->Get(0)->BooleanValue(); 308 g_test_result_ok = test_result->Get(0)->BooleanValue();
311 if (!g_test_result_ok) { 309 if (!g_test_result_ok) {
312 v8::String::Utf8Value message(test_result->Get(1)); 310 v8::String::Utf8Value message(test_result->Get(1));
313 LOG(ERROR) << *message; 311 LOG(ERROR) << *message;
314 } 312 }
315 } 313 }
OLDNEW
« no previous file with comments | « no previous file | components/guest_view/renderer/guest_view_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698