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

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

Powered by Google App Engine
This is Rietveld 408576698