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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp

Issue 2817533003: Replace ASSERT, RELEASE_ASSERT, and ASSERT_NOT_REACHED in bindings (Closed)
Patch Set: fixed dcheck build error Created 3 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 V8Window::findInstanceInPrototypeChain(host, isolate); 84 V8Window::findInstanceInPrototypeChain(host, isolate);
85 if (window_wrapper.IsEmpty()) 85 if (window_wrapper.IsEmpty())
86 return 0; 86 return 0;
87 return V8Window::toImpl(window_wrapper)->GetFrame(); 87 return V8Window::toImpl(window_wrapper)->GetFrame();
88 } 88 }
89 89
90 if (V8Location::wrapperTypeInfo.Equals(type)) 90 if (V8Location::wrapperTypeInfo.Equals(type))
91 return V8Location::toImpl(host)->GetFrame(); 91 return V8Location::toImpl(host)->GetFrame();
92 92
93 // This function can handle only those types listed above. 93 // This function can handle only those types listed above.
94 ASSERT_NOT_REACHED(); 94 NOTREACHED();
95 return 0; 95 return 0;
96 } 96 }
97 97
98 static void ReportFatalErrorInMainThread(const char* location, 98 static void ReportFatalErrorInMainThread(const char* location,
99 const char* message) { 99 const char* message) {
100 int memory_usage_mb = Platform::Current()->ActualMemoryUsageMB(); 100 int memory_usage_mb = Platform::Current()->ActualMemoryUsageMB();
101 DVLOG(1) << "V8 error: " << message << " (" << location 101 DVLOG(1) << "V8 error: " << message << " (" << location
102 << "). Current memory usage: " << memory_usage_mb << " MB"; 102 << "). Current memory usage: " << memory_usage_mb << " MB";
103 CRASH(); 103 CRASH();
104 } 104 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 // NOTE: when editing this, please also edit the error messages we throw when 151 // NOTE: when editing this, please also edit the error messages we throw when
152 // the size is exceeded (see uses of the constant), which use the human-friendly 152 // the size is exceeded (see uses of the constant), which use the human-friendly
153 // "4KB" text. 153 // "4KB" text.
154 const size_t kWasmWireBytesLimit = 1 << 12; 154 const size_t kWasmWireBytesLimit = 1 << 12;
155 155
156 } // namespace 156 } // namespace
157 157
158 void V8Initializer::MessageHandlerInMainThread(v8::Local<v8::Message> message, 158 void V8Initializer::MessageHandlerInMainThread(v8::Local<v8::Message> message,
159 v8::Local<v8::Value> data) { 159 v8::Local<v8::Value> data) {
160 ASSERT(IsMainThread()); 160 DCHECK(IsMainThread());
161 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 161 v8::Isolate* isolate = v8::Isolate::GetCurrent();
162 162
163 if (isolate->GetEnteredContext().IsEmpty()) 163 if (isolate->GetEnteredContext().IsEmpty())
164 return; 164 return;
165 165
166 // If called during context initialization, there will be no entered context. 166 // If called during context initialization, there will be no entered context.
167 ScriptState* script_state = ScriptState::Current(isolate); 167 ScriptState* script_state = ScriptState::Current(isolate);
168 if (!script_state->ContextIsValid()) 168 if (!script_state->ContextIsValid())
169 return; 169 return;
170 170
(...skipping 24 matching lines...) Expand all
195 event->SetUnsanitizedMessage("Uncaught " + message_for_console); 195 event->SetUnsanitizedMessage("Uncaught " + message_for_console);
196 196
197 V8ErrorHandler::StoreExceptionOnErrorEventWrapper( 197 V8ErrorHandler::StoreExceptionOnErrorEventWrapper(
198 script_state, event, data, script_state->GetContext()->Global()); 198 script_state, event, data, script_state->GetContext()->Global());
199 context->DispatchErrorEvent(event, access_control_status); 199 context->DispatchErrorEvent(event, access_control_status);
200 } 200 }
201 201
202 namespace { 202 namespace {
203 203
204 static RejectedPromises& RejectedPromisesOnMainThread() { 204 static RejectedPromises& RejectedPromisesOnMainThread() {
205 ASSERT(IsMainThread()); 205 DCHECK(IsMainThread());
206 DEFINE_STATIC_LOCAL(RefPtr<RejectedPromises>, rejected_promises, 206 DEFINE_STATIC_LOCAL(RefPtr<RejectedPromises>, rejected_promises,
207 (RejectedPromises::Create())); 207 (RejectedPromises::Create()));
208 return *rejected_promises; 208 return *rejected_promises;
209 } 209 }
210 210
211 } // namespace 211 } // namespace
212 212
213 void V8Initializer::ReportRejectedPromisesOnMainThread() { 213 void V8Initializer::ReportRejectedPromisesOnMainThread() {
214 RejectedPromisesOnMainThread().ProcessQueue(); 214 RejectedPromisesOnMainThread().ProcessQueue();
215 } 215 }
216 216
217 static void PromiseRejectHandler(v8::PromiseRejectMessage data, 217 static void PromiseRejectHandler(v8::PromiseRejectMessage data,
218 RejectedPromises& rejected_promises, 218 RejectedPromises& rejected_promises,
219 ScriptState* script_state) { 219 ScriptState* script_state) {
220 if (data.GetEvent() == v8::kPromiseHandlerAddedAfterReject) { 220 if (data.GetEvent() == v8::kPromiseHandlerAddedAfterReject) {
221 rejected_promises.HandlerAdded(data); 221 rejected_promises.HandlerAdded(data);
222 return; 222 return;
223 } 223 }
224 224
225 ASSERT(data.GetEvent() == v8::kPromiseRejectWithNoHandler); 225 DCHECK_EQ(data.GetEvent(), v8::kPromiseRejectWithNoHandler);
226 226
227 v8::Local<v8::Promise> promise = data.GetPromise(); 227 v8::Local<v8::Promise> promise = data.GetPromise();
228 v8::Isolate* isolate = promise->GetIsolate(); 228 v8::Isolate* isolate = promise->GetIsolate();
229 ExecutionContext* context = ExecutionContext::From(script_state); 229 ExecutionContext* context = ExecutionContext::From(script_state);
230 230
231 v8::Local<v8::Value> exception = data.GetValue(); 231 v8::Local<v8::Value> exception = data.GetValue();
232 if (V8DOMWrapper::IsWrapper(isolate, exception)) { 232 if (V8DOMWrapper::IsWrapper(isolate, exception)) {
233 // Try to get the stack & location from a wrapped exception object (e.g. 233 // Try to get the stack & location from a wrapped exception object (e.g.
234 // DOMException). 234 // DOMException).
235 ASSERT(exception->IsObject()); 235 DCHECK(exception->IsObject());
236 auto private_error = V8PrivateProperty::GetDOMExceptionError(isolate); 236 auto private_error = V8PrivateProperty::GetDOMExceptionError(isolate);
237 v8::Local<v8::Value> error = 237 v8::Local<v8::Value> error =
238 private_error.GetOrUndefined(exception.As<v8::Object>()); 238 private_error.GetOrUndefined(exception.As<v8::Object>());
239 if (!error->IsUndefined()) 239 if (!error->IsUndefined())
240 exception = error; 240 exception = error;
241 } 241 }
242 242
243 String error_message; 243 String error_message;
244 AccessControlStatus cors_status = kNotSharableCrossOrigin; 244 AccessControlStatus cors_status = kNotSharableCrossOrigin;
245 std::unique_ptr<SourceLocation> location; 245 std::unique_ptr<SourceLocation> location;
(...skipping 14 matching lines...) Expand all
260 String message_for_console = 260 String message_for_console =
261 ExtractMessageForConsole(isolate, data.GetValue()); 261 ExtractMessageForConsole(isolate, data.GetValue());
262 if (!message_for_console.IsEmpty()) 262 if (!message_for_console.IsEmpty())
263 error_message = "Uncaught " + message_for_console; 263 error_message = "Uncaught " + message_for_console;
264 264
265 rejected_promises.RejectedWithNoHandler(script_state, data, error_message, 265 rejected_promises.RejectedWithNoHandler(script_state, data, error_message,
266 std::move(location), cors_status); 266 std::move(location), cors_status);
267 } 267 }
268 268
269 static void PromiseRejectHandlerInMainThread(v8::PromiseRejectMessage data) { 269 static void PromiseRejectHandlerInMainThread(v8::PromiseRejectMessage data) {
270 ASSERT(IsMainThread()); 270 DCHECK(IsMainThread());
271 271
272 v8::Local<v8::Promise> promise = data.GetPromise(); 272 v8::Local<v8::Promise> promise = data.GetPromise();
273 273
274 v8::Isolate* isolate = promise->GetIsolate(); 274 v8::Isolate* isolate = promise->GetIsolate();
275 275
276 // TODO(ikilpatrick): Remove this check, extensions tests that use 276 // TODO(ikilpatrick): Remove this check, extensions tests that use
277 // extensions::ModuleSystemTest incorrectly don't have a valid script state. 277 // extensions::ModuleSystemTest incorrectly don't have a valid script state.
278 LocalDOMWindow* window = CurrentDOMWindow(isolate); 278 LocalDOMWindow* window = CurrentDOMWindow(isolate);
279 if (!window || !window->IsCurrentlyDisplayedInFrame()) 279 if (!window || !window->IsCurrentlyDisplayedInFrame())
280 return; 280 return;
(...skipping 12 matching lines...) Expand all
293 // Bail out if called during context initialization. 293 // Bail out if called during context initialization.
294 v8::Isolate* isolate = promise->GetIsolate(); 294 v8::Isolate* isolate = promise->GetIsolate();
295 ScriptState* script_state = ScriptState::Current(isolate); 295 ScriptState* script_state = ScriptState::Current(isolate);
296 if (!script_state->ContextIsValid()) 296 if (!script_state->ContextIsValid())
297 return; 297 return;
298 298
299 ExecutionContext* execution_context = ExecutionContext::From(script_state); 299 ExecutionContext* execution_context = ExecutionContext::From(script_state);
300 if (!execution_context) 300 if (!execution_context)
301 return; 301 return;
302 302
303 ASSERT(execution_context->IsWorkerGlobalScope()); 303 DCHECK(execution_context->IsWorkerGlobalScope());
304 WorkerOrWorkletScriptController* script_controller = 304 WorkerOrWorkletScriptController* script_controller =
305 ToWorkerGlobalScope(execution_context)->ScriptController(); 305 ToWorkerGlobalScope(execution_context)->ScriptController();
306 ASSERT(script_controller); 306 DCHECK(script_controller);
307 307
308 PromiseRejectHandler(data, *script_controller->GetRejectedPromises(), 308 PromiseRejectHandler(data, *script_controller->GetRejectedPromises(),
309 script_state); 309 script_state);
310 } 310 }
311 311
312 static void FailedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, 312 static void FailedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host,
313 v8::AccessType type, 313 v8::AccessType type,
314 v8::Local<v8::Value> data) { 314 v8::Local<v8::Value> data) {
315 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 315 v8::Isolate* isolate = v8::Isolate::GetCurrent();
316 Frame* target = FindFrame(isolate, host, data); 316 Frame* target = FindFrame(isolate, host, data);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 process_total += diff; 440 process_total += diff;
441 DCHECK_GE(process_total, 0) 441 DCHECK_GE(process_total, 0)
442 << "total amount = " << process_total << ", diff = " << diff; 442 << "total amount = " << process_total << ", diff = " << diff;
443 } 443 }
444 #endif 444 #endif
445 445
446 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(diff); 446 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(diff);
447 } 447 }
448 448
449 void V8Initializer::InitializeMainThread() { 449 void V8Initializer::InitializeMainThread() {
450 ASSERT(IsMainThread()); 450 DCHECK(IsMainThread());
451 451
452 WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory); 452 WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory);
453 453
454 DEFINE_STATIC_LOCAL(ArrayBufferAllocator, array_buffer_allocator, ()); 454 DEFINE_STATIC_LOCAL(ArrayBufferAllocator, array_buffer_allocator, ());
455 auto v8_extras_mode = RuntimeEnabledFeatures::experimentalV8ExtrasEnabled() 455 auto v8_extras_mode = RuntimeEnabledFeatures::experimentalV8ExtrasEnabled()
456 ? gin::IsolateHolder::kStableAndExperimentalV8Extras 456 ? gin::IsolateHolder::kStableAndExperimentalV8Extras
457 : gin::IsolateHolder::kStableV8Extras; 457 : gin::IsolateHolder::kStableV8Extras;
458 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, 458 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
459 v8_extras_mode, &array_buffer_allocator); 459 v8_extras_mode, &array_buffer_allocator);
460 460
(...skipping 26 matching lines...) Expand all
487 } 487 }
488 488
489 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInMainThread); 489 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInMainThread);
490 490
491 if (v8::HeapProfiler* profiler = isolate->GetHeapProfiler()) { 491 if (v8::HeapProfiler* profiler = isolate->GetHeapProfiler()) {
492 profiler->SetWrapperClassInfoProvider( 492 profiler->SetWrapperClassInfoProvider(
493 WrapperTypeInfo::kNodeClassId, &RetainedDOMInfo::CreateRetainedDOMInfo); 493 WrapperTypeInfo::kNodeClassId, &RetainedDOMInfo::CreateRetainedDOMInfo);
494 profiler->SetGetRetainerInfosCallback(&V8GCController::GetRetainerInfos); 494 profiler->SetGetRetainerInfosCallback(&V8GCController::GetRetainerInfos);
495 } 495 }
496 496
497 ASSERT(ThreadState::MainThreadState()); 497 DCHECK(ThreadState::MainThreadState());
498 ThreadState::MainThreadState()->RegisterTraceDOMWrappers( 498 ThreadState::MainThreadState()->RegisterTraceDOMWrappers(
499 isolate, V8GCController::TraceDOMWrappers, 499 isolate, V8GCController::TraceDOMWrappers,
500 ScriptWrappableVisitor::InvalidateDeadObjectsInMarkingDeque, 500 ScriptWrappableVisitor::InvalidateDeadObjectsInMarkingDeque,
501 ScriptWrappableVisitor::PerformCleanup); 501 ScriptWrappableVisitor::PerformCleanup);
502 502
503 V8PerIsolateData::From(isolate)->SetThreadDebugger( 503 V8PerIsolateData::From(isolate)->SetThreadDebugger(
504 WTF::MakeUnique<MainThreadDebugger>(isolate)); 504 WTF::MakeUnique<MainThreadDebugger>(isolate));
505 505
506 BindingSecurity::InitWrapperCreationSecurityCheck(); 506 BindingSecurity::InitWrapperCreationSecurityCheck();
507 } 507 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 v8::Isolate::kMessageLog); 583 v8::Isolate::kMessageLog);
584 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); 584 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker);
585 585
586 uint32_t here; 586 uint32_t here;
587 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - 587 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) -
588 kWorkerMaxStackSize); 588 kWorkerMaxStackSize);
589 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); 589 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker);
590 } 590 }
591 591
592 } // namespace blink 592 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698