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...) 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...) 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 DCHECK(false); | |
jochen (gone - plz use gerrit)
2016/12/14 11:42:43
NOTREACHED();
bradn
2016/12/14 12:18:14
Done.
| |
143 } | |
144 return level; | |
145 } | |
146 }; | |
jochen (gone - plz use gerrit)
2016/12/14 11:42:43
no ; at the end of namespace. Please also add a co
bradn
2016/12/14 12:18:14
Done.
| |
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 231 matching lines...) Loading... | |
379 : gin::IsolateHolder::kStableV8Extras; | 414 : gin::IsolateHolder::kStableV8Extras; |
380 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, | 415 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, |
381 v8ExtrasMode, &arrayBufferAllocator); | 416 v8ExtrasMode, &arrayBufferAllocator); |
382 | 417 |
383 v8::Isolate* isolate = V8PerIsolateData::initialize(); | 418 v8::Isolate* isolate = V8PerIsolateData::initialize(); |
384 | 419 |
385 initializeV8Common(isolate); | 420 initializeV8Common(isolate); |
386 | 421 |
387 isolate->SetOOMErrorHandler(reportOOMErrorInMainThread); | 422 isolate->SetOOMErrorHandler(reportOOMErrorInMainThread); |
388 isolate->SetFatalErrorHandler(reportFatalErrorInMainThread); | 423 isolate->SetFatalErrorHandler(reportFatalErrorInMainThread); |
389 isolate->AddMessageListener(messageHandlerInMainThread); | 424 isolate->AddMessageListenerWithErrorLevel( |
425 messageHandlerInMainThread, | |
426 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | | |
427 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | | |
428 v8::Isolate::kMessageLog); | |
390 isolate->SetFailedAccessCheckCallbackFunction( | 429 isolate->SetFailedAccessCheckCallbackFunction( |
391 failedAccessCheckCallbackInMainThread); | 430 failedAccessCheckCallbackInMainThread); |
392 isolate->SetAllowCodeGenerationFromStringsCallback( | 431 isolate->SetAllowCodeGenerationFromStringsCallback( |
393 codeGenerationCheckCallbackInMainThread); | 432 codeGenerationCheckCallbackInMainThread); |
394 | 433 |
395 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) { | 434 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) { |
396 WebScheduler* scheduler = Platform::current()->currentThread()->scheduler(); | 435 WebScheduler* scheduler = Platform::current()->currentThread()->scheduler(); |
397 V8PerIsolateData::enableIdleTasks( | 436 V8PerIsolateData::enableIdleTasks( |
398 isolate, WTF::makeUnique<V8IdleTaskRunner>(scheduler)); | 437 isolate, WTF::makeUnique<V8IdleTaskRunner>(scheduler)); |
399 } | 438 } |
(...skipping 49 matching lines...) Loading... | |
449 // WorkerGlobalScope::dispatchErrorEvent will send the exception to the worker | 488 // WorkerGlobalScope::dispatchErrorEvent will send the exception to the worker |
450 // object. | 489 // object. |
451 if (perIsolateData->isReportingException()) | 490 if (perIsolateData->isReportingException()) |
452 return; | 491 return; |
453 | 492 |
454 perIsolateData->setReportingException(true); | 493 perIsolateData->setReportingException(true); |
455 | 494 |
456 ExecutionContext* context = scriptState->getExecutionContext(); | 495 ExecutionContext* context = scriptState->getExecutionContext(); |
457 std::unique_ptr<SourceLocation> location = | 496 std::unique_ptr<SourceLocation> location = |
458 SourceLocation::fromMessage(isolate, message, context); | 497 SourceLocation::fromMessage(isolate, message, context); |
498 | |
499 if (message->ErrorLevel() != v8::Isolate::kMessageError) { | |
500 context->addConsoleMessage(ConsoleMessage::create( | |
501 JSMessageSource, | |
502 MessageLevelFromNonFatalErrorLevel(message->ErrorLevel()), | |
503 toCoreStringWithNullCheck(message->Get()), std::move(location))); | |
504 return; | |
505 } | |
506 | |
459 ErrorEvent* event = | 507 ErrorEvent* event = |
460 ErrorEvent::create(toCoreStringWithNullCheck(message->Get()), | 508 ErrorEvent::create(toCoreStringWithNullCheck(message->Get()), |
461 std::move(location), &scriptState->world()); | 509 std::move(location), &scriptState->world()); |
462 | 510 |
463 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() | 511 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() |
464 ? SharableCrossOrigin | 512 ? SharableCrossOrigin |
465 : NotSharableCrossOrigin; | 513 : NotSharableCrossOrigin; |
466 | 514 |
467 // If execution termination has been triggered as part of constructing | 515 // If execution termination has been triggered as part of constructing |
468 // the error event from the v8::Message, quietly leave. | 516 // the error event from the v8::Message, quietly leave. |
(...skipping 12 matching lines...) Loading... | |
481 static const int kWorkerMaxStackSize = 500 * 1024; | 529 static const int kWorkerMaxStackSize = 500 * 1024; |
482 | 530 |
483 // This function uses a local stack variable to determine the isolate's stack | 531 // This function uses a local stack variable to determine the isolate's stack |
484 // limit. AddressSanitizer may relocate that local variable to a fake stack, | 532 // limit. AddressSanitizer may relocate that local variable to a fake stack, |
485 // which may lead to problems during JavaScript execution. Therefore we disable | 533 // which may lead to problems during JavaScript execution. Therefore we disable |
486 // AddressSanitizer for V8Initializer::initializeWorker(). | 534 // AddressSanitizer for V8Initializer::initializeWorker(). |
487 NO_SANITIZE_ADDRESS | 535 NO_SANITIZE_ADDRESS |
488 void V8Initializer::initializeWorker(v8::Isolate* isolate) { | 536 void V8Initializer::initializeWorker(v8::Isolate* isolate) { |
489 initializeV8Common(isolate); | 537 initializeV8Common(isolate); |
490 | 538 |
491 isolate->AddMessageListener(messageHandlerInWorker); | 539 isolate->AddMessageListenerWithErrorLevel( |
540 messageHandlerInWorker, | |
541 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | | |
542 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | | |
543 v8::Isolate::kMessageLog); | |
492 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); | 544 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); |
493 | 545 |
494 uint32_t here; | 546 uint32_t here; |
495 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - | 547 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - |
496 kWorkerMaxStackSize); | 548 kWorkerMaxStackSize); |
497 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); | 549 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); |
498 } | 550 } |
499 | 551 |
500 } // namespace blink | 552 } // namespace blink |
OLD | NEW |