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

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

Issue 2810743003: Move ScriptState::GetExecutionContext (Part 3) (Closed)
Patch Set: Rebase 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 29 matching lines...) Expand all
40 #include "bindings/core/v8/V8ErrorEvent.h" 40 #include "bindings/core/v8/V8ErrorEvent.h"
41 #include "bindings/core/v8/V8ErrorHandler.h" 41 #include "bindings/core/v8/V8ErrorHandler.h"
42 #include "bindings/core/v8/V8GCController.h" 42 #include "bindings/core/v8/V8GCController.h"
43 #include "bindings/core/v8/V8IdleTaskRunner.h" 43 #include "bindings/core/v8/V8IdleTaskRunner.h"
44 #include "bindings/core/v8/V8Location.h" 44 #include "bindings/core/v8/V8Location.h"
45 #include "bindings/core/v8/V8PerContextData.h" 45 #include "bindings/core/v8/V8PerContextData.h"
46 #include "bindings/core/v8/V8PrivateProperty.h" 46 #include "bindings/core/v8/V8PrivateProperty.h"
47 #include "bindings/core/v8/V8Window.h" 47 #include "bindings/core/v8/V8Window.h"
48 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 48 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
49 #include "core/dom/Document.h" 49 #include "core/dom/Document.h"
50 #include "core/dom/ExecutionContext.h"
50 #include "core/frame/LocalDOMWindow.h" 51 #include "core/frame/LocalDOMWindow.h"
51 #include "core/frame/LocalFrame.h" 52 #include "core/frame/LocalFrame.h"
52 #include "core/frame/csp/ContentSecurityPolicy.h" 53 #include "core/frame/csp/ContentSecurityPolicy.h"
53 #include "core/inspector/ConsoleMessage.h" 54 #include "core/inspector/ConsoleMessage.h"
54 #include "core/inspector/MainThreadDebugger.h" 55 #include "core/inspector/MainThreadDebugger.h"
55 #include "core/workers/WorkerGlobalScope.h" 56 #include "core/workers/WorkerGlobalScope.h"
56 #include "platform/EventDispatchForbiddenScope.h" 57 #include "platform/EventDispatchForbiddenScope.h"
57 #include "platform/RuntimeEnabledFeatures.h" 58 #include "platform/RuntimeEnabledFeatures.h"
58 #include "platform/instrumentation/tracing/TraceEvent.h" 59 #include "platform/instrumentation/tracing/TraceEvent.h"
59 #include "platform/loader/fetch/AccessControlStatus.h" 60 #include "platform/loader/fetch/AccessControlStatus.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 160 v8::Isolate* isolate = v8::Isolate::GetCurrent();
160 161
161 if (isolate->GetEnteredContext().IsEmpty()) 162 if (isolate->GetEnteredContext().IsEmpty())
162 return; 163 return;
163 164
164 // If called during context initialization, there will be no entered context. 165 // If called during context initialization, there will be no entered context.
165 ScriptState* script_state = ScriptState::Current(isolate); 166 ScriptState* script_state = ScriptState::Current(isolate);
166 if (!script_state->ContextIsValid()) 167 if (!script_state->ContextIsValid())
167 return; 168 return;
168 169
169 ExecutionContext* context = script_state->GetExecutionContext(); 170 ExecutionContext* context = ExecutionContext::From(script_state);
170 std::unique_ptr<SourceLocation> location = 171 std::unique_ptr<SourceLocation> location =
171 SourceLocation::FromMessage(isolate, message, context); 172 SourceLocation::FromMessage(isolate, message, context);
172 173
173 if (message->ErrorLevel() != v8::Isolate::kMessageError) { 174 if (message->ErrorLevel() != v8::Isolate::kMessageError) {
174 context->AddConsoleMessage(ConsoleMessage::Create( 175 context->AddConsoleMessage(ConsoleMessage::Create(
175 kJSMessageSource, 176 kJSMessageSource,
176 MessageLevelFromNonFatalErrorLevel(message->ErrorLevel()), 177 MessageLevelFromNonFatalErrorLevel(message->ErrorLevel()),
177 ToCoreStringWithNullCheck(message->Get()), std::move(location))); 178 ToCoreStringWithNullCheck(message->Get()), std::move(location)));
178 return; 179 return;
179 } 180 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 ScriptState* script_state) { 218 ScriptState* script_state) {
218 if (data.GetEvent() == v8::kPromiseHandlerAddedAfterReject) { 219 if (data.GetEvent() == v8::kPromiseHandlerAddedAfterReject) {
219 rejected_promises.HandlerAdded(data); 220 rejected_promises.HandlerAdded(data);
220 return; 221 return;
221 } 222 }
222 223
223 ASSERT(data.GetEvent() == v8::kPromiseRejectWithNoHandler); 224 ASSERT(data.GetEvent() == v8::kPromiseRejectWithNoHandler);
224 225
225 v8::Local<v8::Promise> promise = data.GetPromise(); 226 v8::Local<v8::Promise> promise = data.GetPromise();
226 v8::Isolate* isolate = promise->GetIsolate(); 227 v8::Isolate* isolate = promise->GetIsolate();
227 ExecutionContext* context = script_state->GetExecutionContext(); 228 ExecutionContext* context = ExecutionContext::From(script_state);
228 229
229 v8::Local<v8::Value> exception = data.GetValue(); 230 v8::Local<v8::Value> exception = data.GetValue();
230 if (V8DOMWrapper::IsWrapper(isolate, exception)) { 231 if (V8DOMWrapper::IsWrapper(isolate, exception)) {
231 // Try to get the stack & location from a wrapped exception object (e.g. 232 // Try to get the stack & location from a wrapped exception object (e.g.
232 // DOMException). 233 // DOMException).
233 ASSERT(exception->IsObject()); 234 ASSERT(exception->IsObject());
234 auto private_error = V8PrivateProperty::GetDOMExceptionError(isolate); 235 auto private_error = V8PrivateProperty::GetDOMExceptionError(isolate);
235 v8::Local<v8::Value> error = 236 v8::Local<v8::Value> error =
236 private_error.GetOrUndefined(exception.As<v8::Object>()); 237 private_error.GetOrUndefined(exception.As<v8::Object>());
237 if (!error->IsUndefined()) 238 if (!error->IsUndefined())
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 288
288 static void PromiseRejectHandlerInWorker(v8::PromiseRejectMessage data) { 289 static void PromiseRejectHandlerInWorker(v8::PromiseRejectMessage data) {
289 v8::Local<v8::Promise> promise = data.GetPromise(); 290 v8::Local<v8::Promise> promise = data.GetPromise();
290 291
291 // Bail out if called during context initialization. 292 // Bail out if called during context initialization.
292 v8::Isolate* isolate = promise->GetIsolate(); 293 v8::Isolate* isolate = promise->GetIsolate();
293 ScriptState* script_state = ScriptState::Current(isolate); 294 ScriptState* script_state = ScriptState::Current(isolate);
294 if (!script_state->ContextIsValid()) 295 if (!script_state->ContextIsValid())
295 return; 296 return;
296 297
297 ExecutionContext* execution_context = script_state->GetExecutionContext(); 298 ExecutionContext* execution_context = ExecutionContext::From(script_state);
298 if (!execution_context) 299 if (!execution_context)
299 return; 300 return;
300 301
301 ASSERT(execution_context->IsWorkerGlobalScope()); 302 ASSERT(execution_context->IsWorkerGlobalScope());
302 WorkerOrWorkletScriptController* script_controller = 303 WorkerOrWorkletScriptController* script_controller =
303 ToWorkerGlobalScope(execution_context)->ScriptController(); 304 ToWorkerGlobalScope(execution_context)->ScriptController();
304 ASSERT(script_controller); 305 ASSERT(script_controller);
305 306
306 PromiseRejectHandler(data, *script_controller->GetRejectedPromises(), 307 PromiseRejectHandler(data, *script_controller->GetRejectedPromises(),
307 script_state); 308 script_state);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 return; 521 return;
521 522
522 // Exceptions that occur in error handler should be ignored since in that case 523 // Exceptions that occur in error handler should be ignored since in that case
523 // WorkerGlobalScope::dispatchErrorEvent will send the exception to the worker 524 // WorkerGlobalScope::dispatchErrorEvent will send the exception to the worker
524 // object. 525 // object.
525 if (per_isolate_data->IsReportingException()) 526 if (per_isolate_data->IsReportingException())
526 return; 527 return;
527 528
528 per_isolate_data->SetReportingException(true); 529 per_isolate_data->SetReportingException(true);
529 530
530 ExecutionContext* context = script_state->GetExecutionContext(); 531 ExecutionContext* context = ExecutionContext::From(script_state);
531 std::unique_ptr<SourceLocation> location = 532 std::unique_ptr<SourceLocation> location =
532 SourceLocation::FromMessage(isolate, message, context); 533 SourceLocation::FromMessage(isolate, message, context);
533 534
534 if (message->ErrorLevel() != v8::Isolate::kMessageError) { 535 if (message->ErrorLevel() != v8::Isolate::kMessageError) {
535 context->AddConsoleMessage(ConsoleMessage::Create( 536 context->AddConsoleMessage(ConsoleMessage::Create(
536 kJSMessageSource, 537 kJSMessageSource,
537 MessageLevelFromNonFatalErrorLevel(message->ErrorLevel()), 538 MessageLevelFromNonFatalErrorLevel(message->ErrorLevel()),
538 ToCoreStringWithNullCheck(message->Get()), std::move(location))); 539 ToCoreStringWithNullCheck(message->Get()), std::move(location)));
539 return; 540 return;
540 } 541 }
541 542
542 ErrorEvent* event = 543 ErrorEvent* event =
543 ErrorEvent::Create(ToCoreStringWithNullCheck(message->Get()), 544 ErrorEvent::Create(ToCoreStringWithNullCheck(message->Get()),
544 std::move(location), &script_state->World()); 545 std::move(location), &script_state->World());
545 546
546 AccessControlStatus cors_status = message->IsSharedCrossOrigin() 547 AccessControlStatus cors_status = message->IsSharedCrossOrigin()
547 ? kSharableCrossOrigin 548 ? kSharableCrossOrigin
548 : kNotSharableCrossOrigin; 549 : kNotSharableCrossOrigin;
549 550
550 // If execution termination has been triggered as part of constructing 551 // If execution termination has been triggered as part of constructing
551 // the error event from the v8::Message, quietly leave. 552 // the error event from the v8::Message, quietly leave.
552 if (!isolate->IsExecutionTerminating()) { 553 if (!isolate->IsExecutionTerminating()) {
553 V8ErrorHandler::StoreExceptionOnErrorEventWrapper( 554 V8ErrorHandler::StoreExceptionOnErrorEventWrapper(
554 script_state, event, data, script_state->GetContext()->Global()); 555 script_state, event, data, script_state->GetContext()->Global());
555 script_state->GetExecutionContext()->DispatchErrorEvent(event, cors_status); 556 ExecutionContext::From(script_state)
557 ->DispatchErrorEvent(event, cors_status);
556 } 558 }
557 559
558 per_isolate_data->SetReportingException(false); 560 per_isolate_data->SetReportingException(false);
559 } 561 }
560 562
561 // Stack size for workers is limited to 500KB because default stack size for 563 // Stack size for workers is limited to 500KB because default stack size for
562 // secondary threads is 512KB on Mac OS X. See GetDefaultThreadStackSize() in 564 // secondary threads is 512KB on Mac OS X. See GetDefaultThreadStackSize() in
563 // base/threading/platform_thread_mac.mm for details. 565 // base/threading/platform_thread_mac.mm for details.
564 static const int kWorkerMaxStackSize = 500 * 1024; 566 static const int kWorkerMaxStackSize = 500 * 1024;
565 567
(...skipping 12 matching lines...) Expand all
578 v8::Isolate::kMessageLog); 580 v8::Isolate::kMessageLog);
579 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); 581 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker);
580 582
581 uint32_t here; 583 uint32_t here;
582 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - 584 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) -
583 kWorkerMaxStackSize); 585 kWorkerMaxStackSize);
584 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); 586 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker);
585 } 587 }
586 588
587 } // namespace blink 589 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698