OLD | NEW |
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 30 matching lines...) Expand all Loading... |
41 #include "bindings/core/v8/V8Location.h" | 41 #include "bindings/core/v8/V8Location.h" |
42 #include "bindings/core/v8/V8PerContextData.h" | 42 #include "bindings/core/v8/V8PerContextData.h" |
43 #include "bindings/core/v8/V8PrivateProperty.h" | 43 #include "bindings/core/v8/V8PrivateProperty.h" |
44 #include "bindings/core/v8/V8Window.h" | 44 #include "bindings/core/v8/V8Window.h" |
45 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 45 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
46 #include "core/dom/Document.h" | 46 #include "core/dom/Document.h" |
47 #include "core/fetch/AccessControlStatus.h" | 47 #include "core/fetch/AccessControlStatus.h" |
48 #include "core/frame/LocalDOMWindow.h" | 48 #include "core/frame/LocalDOMWindow.h" |
49 #include "core/frame/LocalFrame.h" | 49 #include "core/frame/LocalFrame.h" |
50 #include "core/frame/csp/ContentSecurityPolicy.h" | 50 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 51 #include "core/inspector/ConsoleMessage.h" |
51 #include "core/inspector/MainThreadDebugger.h" | 52 #include "core/inspector/MainThreadDebugger.h" |
52 #include "core/workers/WorkerGlobalScope.h" | 53 #include "core/workers/WorkerGlobalScope.h" |
53 #include "platform/EventDispatchForbiddenScope.h" | 54 #include "platform/EventDispatchForbiddenScope.h" |
54 #include "platform/RuntimeEnabledFeatures.h" | 55 #include "platform/RuntimeEnabledFeatures.h" |
55 #include "platform/tracing/TraceEvent.h" | 56 #include "platform/tracing/TraceEvent.h" |
56 #include "public/platform/Platform.h" | 57 #include "public/platform/Platform.h" |
57 #include "public/platform/WebScheduler.h" | 58 #include "public/platform/WebScheduler.h" |
58 #include "public/platform/WebThread.h" | 59 #include "public/platform/WebThread.h" |
59 #include "wtf/AddressSanitizer.h" | 60 #include "wtf/AddressSanitizer.h" |
60 #include "wtf/PtrUtil.h" | 61 #include "wtf/PtrUtil.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 const WrapperTypeInfo* type = toWrapperTypeInfo(obj); | 112 const WrapperTypeInfo* type = toWrapperTypeInfo(obj); |
112 if (V8DOMException::wrapperTypeInfo.isSubclass(type)) { | 113 if (V8DOMException::wrapperTypeInfo.isSubclass(type)) { |
113 DOMException* exception = V8DOMException::toImpl(obj); | 114 DOMException* exception = V8DOMException::toImpl(obj); |
114 if (exception && !exception->messageForConsole().isEmpty()) | 115 if (exception && !exception->messageForConsole().isEmpty()) |
115 return exception->toStringForConsole(); | 116 return exception->toStringForConsole(); |
116 } | 117 } |
117 } | 118 } |
118 return emptyString(); | 119 return emptyString(); |
119 } | 120 } |
120 | 121 |
| 122 namespace { |
| 123 MessageLevel MessageLevelFromNonFatalErrorLevel(int errorLevel) { |
| 124 MessageLevel level = ErrorMessageLevel; |
| 125 switch (errorLevel) { |
| 126 case v8::Isolate::kMessageLog: |
| 127 level = LogMessageLevel; |
| 128 break; |
| 129 case v8::Isolate::kMessageWarning: |
| 130 level = WarningMessageLevel; |
| 131 break; |
| 132 case v8::Isolate::kMessageDebug: |
| 133 level = DebugMessageLevel; |
| 134 break; |
| 135 case v8::Isolate::kMessageInfo: |
| 136 level = InfoMessageLevel; |
| 137 break; |
| 138 case v8::Isolate::kMessageError: |
| 139 level = InfoMessageLevel; |
| 140 break; |
| 141 default: |
| 142 NOTREACHED(); |
| 143 } |
| 144 return level; |
| 145 } |
| 146 } // namespace |
| 147 |
121 void V8Initializer::messageHandlerInMainThread(v8::Local<v8::Message> message, | 148 void V8Initializer::messageHandlerInMainThread(v8::Local<v8::Message> message, |
122 v8::Local<v8::Value> data) { | 149 v8::Local<v8::Value> data) { |
123 ASSERT(isMainThread()); | 150 ASSERT(isMainThread()); |
124 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 151 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
125 | 152 |
126 if (isolate->GetEnteredContext().IsEmpty()) | 153 if (isolate->GetEnteredContext().IsEmpty()) |
127 return; | 154 return; |
128 | 155 |
129 // If called during context initialization, there will be no entered context. | 156 // If called during context initialization, there will be no entered context. |
130 ScriptState* scriptState = ScriptState::current(isolate); | 157 ScriptState* scriptState = ScriptState::current(isolate); |
131 if (!scriptState->contextIsValid()) | 158 if (!scriptState->contextIsValid()) |
132 return; | 159 return; |
133 | 160 |
134 ExecutionContext* context = scriptState->getExecutionContext(); | 161 ExecutionContext* context = scriptState->getExecutionContext(); |
135 std::unique_ptr<SourceLocation> location = | 162 std::unique_ptr<SourceLocation> location = |
136 SourceLocation::fromMessage(isolate, message, context); | 163 SourceLocation::fromMessage(isolate, message, context); |
137 | 164 |
| 165 if (message->ErrorLevel() != v8::Isolate::kMessageError) { |
| 166 context->addConsoleMessage(ConsoleMessage::create( |
| 167 JSMessageSource, |
| 168 MessageLevelFromNonFatalErrorLevel(message->ErrorLevel()), |
| 169 toCoreStringWithNullCheck(message->Get()), std::move(location))); |
| 170 return; |
| 171 } |
| 172 |
138 AccessControlStatus accessControlStatus = NotSharableCrossOrigin; | 173 AccessControlStatus accessControlStatus = NotSharableCrossOrigin; |
139 if (message->IsOpaque()) | 174 if (message->IsOpaque()) |
140 accessControlStatus = OpaqueResource; | 175 accessControlStatus = OpaqueResource; |
141 else if (message->IsSharedCrossOrigin()) | 176 else if (message->IsSharedCrossOrigin()) |
142 accessControlStatus = SharableCrossOrigin; | 177 accessControlStatus = SharableCrossOrigin; |
143 | 178 |
144 ErrorEvent* event = | 179 ErrorEvent* event = |
145 ErrorEvent::create(toCoreStringWithNullCheck(message->Get()), | 180 ErrorEvent::create(toCoreStringWithNullCheck(message->Get()), |
146 std::move(location), &scriptState->world()); | 181 std::move(location), &scriptState->world()); |
147 | 182 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 : gin::IsolateHolder::kStableV8Extras; | 402 : gin::IsolateHolder::kStableV8Extras; |
368 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, | 403 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, |
369 v8ExtrasMode, &arrayBufferAllocator); | 404 v8ExtrasMode, &arrayBufferAllocator); |
370 | 405 |
371 v8::Isolate* isolate = V8PerIsolateData::initialize(); | 406 v8::Isolate* isolate = V8PerIsolateData::initialize(); |
372 | 407 |
373 initializeV8Common(isolate); | 408 initializeV8Common(isolate); |
374 | 409 |
375 isolate->SetOOMErrorHandler(reportOOMErrorInMainThread); | 410 isolate->SetOOMErrorHandler(reportOOMErrorInMainThread); |
376 isolate->SetFatalErrorHandler(reportFatalErrorInMainThread); | 411 isolate->SetFatalErrorHandler(reportFatalErrorInMainThread); |
377 isolate->AddMessageListener(messageHandlerInMainThread); | 412 isolate->AddMessageListenerWithErrorLevel( |
| 413 messageHandlerInMainThread, |
| 414 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | |
| 415 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | |
| 416 v8::Isolate::kMessageLog); |
378 isolate->SetFailedAccessCheckCallbackFunction( | 417 isolate->SetFailedAccessCheckCallbackFunction( |
379 failedAccessCheckCallbackInMainThread); | 418 failedAccessCheckCallbackInMainThread); |
380 isolate->SetAllowCodeGenerationFromStringsCallback( | 419 isolate->SetAllowCodeGenerationFromStringsCallback( |
381 codeGenerationCheckCallbackInMainThread); | 420 codeGenerationCheckCallbackInMainThread); |
382 | 421 |
383 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) { | 422 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) { |
384 WebScheduler* scheduler = Platform::current()->currentThread()->scheduler(); | 423 WebScheduler* scheduler = Platform::current()->currentThread()->scheduler(); |
385 V8PerIsolateData::enableIdleTasks( | 424 V8PerIsolateData::enableIdleTasks( |
386 isolate, WTF::makeUnique<V8IdleTaskRunner>(scheduler)); | 425 isolate, WTF::makeUnique<V8IdleTaskRunner>(scheduler)); |
387 } | 426 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 // WorkerGlobalScope::dispatchErrorEvent will send the exception to the worker | 476 // WorkerGlobalScope::dispatchErrorEvent will send the exception to the worker |
438 // object. | 477 // object. |
439 if (perIsolateData->isReportingException()) | 478 if (perIsolateData->isReportingException()) |
440 return; | 479 return; |
441 | 480 |
442 perIsolateData->setReportingException(true); | 481 perIsolateData->setReportingException(true); |
443 | 482 |
444 ExecutionContext* context = scriptState->getExecutionContext(); | 483 ExecutionContext* context = scriptState->getExecutionContext(); |
445 std::unique_ptr<SourceLocation> location = | 484 std::unique_ptr<SourceLocation> location = |
446 SourceLocation::fromMessage(isolate, message, context); | 485 SourceLocation::fromMessage(isolate, message, context); |
| 486 |
| 487 if (message->ErrorLevel() != v8::Isolate::kMessageError) { |
| 488 context->addConsoleMessage(ConsoleMessage::create( |
| 489 JSMessageSource, |
| 490 MessageLevelFromNonFatalErrorLevel(message->ErrorLevel()), |
| 491 toCoreStringWithNullCheck(message->Get()), std::move(location))); |
| 492 return; |
| 493 } |
| 494 |
447 ErrorEvent* event = | 495 ErrorEvent* event = |
448 ErrorEvent::create(toCoreStringWithNullCheck(message->Get()), | 496 ErrorEvent::create(toCoreStringWithNullCheck(message->Get()), |
449 std::move(location), &scriptState->world()); | 497 std::move(location), &scriptState->world()); |
450 | 498 |
451 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() | 499 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() |
452 ? SharableCrossOrigin | 500 ? SharableCrossOrigin |
453 : NotSharableCrossOrigin; | 501 : NotSharableCrossOrigin; |
454 | 502 |
455 // If execution termination has been triggered as part of constructing | 503 // If execution termination has been triggered as part of constructing |
456 // the error event from the v8::Message, quietly leave. | 504 // the error event from the v8::Message, quietly leave. |
(...skipping 12 matching lines...) Expand all Loading... |
469 static const int kWorkerMaxStackSize = 500 * 1024; | 517 static const int kWorkerMaxStackSize = 500 * 1024; |
470 | 518 |
471 // This function uses a local stack variable to determine the isolate's stack | 519 // This function uses a local stack variable to determine the isolate's stack |
472 // limit. AddressSanitizer may relocate that local variable to a fake stack, | 520 // limit. AddressSanitizer may relocate that local variable to a fake stack, |
473 // which may lead to problems during JavaScript execution. Therefore we disable | 521 // which may lead to problems during JavaScript execution. Therefore we disable |
474 // AddressSanitizer for V8Initializer::initializeWorker(). | 522 // AddressSanitizer for V8Initializer::initializeWorker(). |
475 NO_SANITIZE_ADDRESS | 523 NO_SANITIZE_ADDRESS |
476 void V8Initializer::initializeWorker(v8::Isolate* isolate) { | 524 void V8Initializer::initializeWorker(v8::Isolate* isolate) { |
477 initializeV8Common(isolate); | 525 initializeV8Common(isolate); |
478 | 526 |
479 isolate->AddMessageListener(messageHandlerInWorker); | 527 isolate->AddMessageListenerWithErrorLevel( |
| 528 messageHandlerInWorker, |
| 529 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | |
| 530 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | |
| 531 v8::Isolate::kMessageLog); |
480 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); | 532 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); |
481 | 533 |
482 uint32_t here; | 534 uint32_t here; |
483 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - | 535 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - |
484 kWorkerMaxStackSize); | 536 kWorkerMaxStackSize); |
485 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); | 537 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); |
486 } | 538 } |
487 | 539 |
488 } // namespace blink | 540 } // namespace blink |
OLD | NEW |