| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "core/inspector/ScriptArguments.h" | 51 #include "core/inspector/ScriptArguments.h" |
| 52 #include "core/workers/WorkerGlobalScope.h" | 52 #include "core/workers/WorkerGlobalScope.h" |
| 53 #include "platform/EventDispatchForbiddenScope.h" | 53 #include "platform/EventDispatchForbiddenScope.h" |
| 54 #include "platform/RuntimeEnabledFeatures.h" | 54 #include "platform/RuntimeEnabledFeatures.h" |
| 55 #include "platform/TraceEvent.h" | 55 #include "platform/TraceEvent.h" |
| 56 #include "platform/v8_inspector/public/ConsoleTypes.h" | 56 #include "platform/v8_inspector/public/ConsoleTypes.h" |
| 57 #include "public/platform/Platform.h" | 57 #include "public/platform/Platform.h" |
| 58 #include "public/platform/WebScheduler.h" | 58 #include "public/platform/WebScheduler.h" |
| 59 #include "public/platform/WebThread.h" | 59 #include "public/platform/WebThread.h" |
| 60 #include "wtf/AddressSanitizer.h" | 60 #include "wtf/AddressSanitizer.h" |
| 61 #include "wtf/PtrUtil.h" |
| 61 #include "wtf/RefPtr.h" | 62 #include "wtf/RefPtr.h" |
| 62 #include "wtf/text/WTFString.h" | 63 #include "wtf/text/WTFString.h" |
| 63 #include "wtf/typed_arrays/ArrayBufferContents.h" | 64 #include "wtf/typed_arrays/ArrayBufferContents.h" |
| 65 #include <memory> |
| 64 #include <v8-debug.h> | 66 #include <v8-debug.h> |
| 65 #include <v8-profiler.h> | 67 #include <v8-profiler.h> |
| 66 | 68 |
| 67 namespace blink { | 69 namespace blink { |
| 68 | 70 |
| 69 static Frame* findFrame(v8::Isolate* isolate, v8::Local<v8::Object> host, v8::Lo
cal<v8::Value> data) | 71 static Frame* findFrame(v8::Isolate* isolate, v8::Local<v8::Object> host, v8::Lo
cal<v8::Value> data) |
| 70 { | 72 { |
| 71 const WrapperTypeInfo* type = WrapperTypeInfo::unwrap(data); | 73 const WrapperTypeInfo* type = WrapperTypeInfo::unwrap(data); |
| 72 | 74 |
| 73 if (V8Window::wrapperTypeInfo.equals(type)) { | 75 if (V8Window::wrapperTypeInfo.equals(type)) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 118 |
| 117 if (isolate->GetEnteredContext().IsEmpty()) | 119 if (isolate->GetEnteredContext().IsEmpty()) |
| 118 return; | 120 return; |
| 119 | 121 |
| 120 // If called during context initialization, there will be no entered context
. | 122 // If called during context initialization, there will be no entered context
. |
| 121 ScriptState* scriptState = ScriptState::current(isolate); | 123 ScriptState* scriptState = ScriptState::current(isolate); |
| 122 if (!scriptState->contextIsValid()) | 124 if (!scriptState->contextIsValid()) |
| 123 return; | 125 return; |
| 124 | 126 |
| 125 ExecutionContext* context = scriptState->getExecutionContext(); | 127 ExecutionContext* context = scriptState->getExecutionContext(); |
| 126 OwnPtr<SourceLocation> location = SourceLocation::fromMessage(isolate, messa
ge, context); | 128 std::unique_ptr<SourceLocation> location = SourceLocation::fromMessage(isola
te, message, context); |
| 127 | 129 |
| 128 AccessControlStatus accessControlStatus = NotSharableCrossOrigin; | 130 AccessControlStatus accessControlStatus = NotSharableCrossOrigin; |
| 129 if (message->IsOpaque()) | 131 if (message->IsOpaque()) |
| 130 accessControlStatus = OpaqueResource; | 132 accessControlStatus = OpaqueResource; |
| 131 else if (message->IsSharedCrossOrigin()) | 133 else if (message->IsSharedCrossOrigin()) |
| 132 accessControlStatus = SharableCrossOrigin; | 134 accessControlStatus = SharableCrossOrigin; |
| 133 | 135 |
| 134 ErrorEvent* event = ErrorEvent::create(toCoreStringWithNullCheck(message->Ge
t()), std::move(location), &scriptState->world()); | 136 ErrorEvent* event = ErrorEvent::create(toCoreStringWithNullCheck(message->Ge
t()), std::move(location), &scriptState->world()); |
| 135 | 137 |
| 136 String messageForConsole = extractMessageForConsole(isolate, data); | 138 String messageForConsole = extractMessageForConsole(isolate, data); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // Try to get the stack & location from a wrapped exception object (e.g.
DOMException). | 197 // Try to get the stack & location from a wrapped exception object (e.g.
DOMException). |
| 196 ASSERT(exception->IsObject()); | 198 ASSERT(exception->IsObject()); |
| 197 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(exception); | 199 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(exception); |
| 198 v8::Local<v8::Value> error = V8HiddenValue::getHiddenValue(scriptState,
obj, V8HiddenValue::error(isolate)); | 200 v8::Local<v8::Value> error = V8HiddenValue::getHiddenValue(scriptState,
obj, V8HiddenValue::error(isolate)); |
| 199 if (!error.IsEmpty()) | 201 if (!error.IsEmpty()) |
| 200 exception = error; | 202 exception = error; |
| 201 } | 203 } |
| 202 | 204 |
| 203 String errorMessage; | 205 String errorMessage; |
| 204 AccessControlStatus corsStatus = NotSharableCrossOrigin; | 206 AccessControlStatus corsStatus = NotSharableCrossOrigin; |
| 205 OwnPtr<SourceLocation> location; | 207 std::unique_ptr<SourceLocation> location; |
| 206 | 208 |
| 207 v8::Local<v8::Message> message = v8::Exception::CreateMessage(isolate, excep
tion); | 209 v8::Local<v8::Message> message = v8::Exception::CreateMessage(isolate, excep
tion); |
| 208 if (!message.IsEmpty()) { | 210 if (!message.IsEmpty()) { |
| 209 // message->Get() can be empty here. https://crbug.com/450330 | 211 // message->Get() can be empty here. https://crbug.com/450330 |
| 210 errorMessage = toCoreStringWithNullCheck(message->Get()); | 212 errorMessage = toCoreStringWithNullCheck(message->Get()); |
| 211 location = SourceLocation::fromMessage(isolate, message, context); | 213 location = SourceLocation::fromMessage(isolate, message, context); |
| 212 if (message->IsSharedCrossOrigin()) | 214 if (message->IsSharedCrossOrigin()) |
| 213 corsStatus = SharableCrossOrigin; | 215 corsStatus = SharableCrossOrigin; |
| 214 } else { | 216 } else { |
| 215 location = SourceLocation::create(context->url().getString(), 0, 0, null
ptr); | 217 location = SourceLocation::create(context->url().getString(), 0, 0, null
ptr); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 351 |
| 350 initializeV8Common(isolate); | 352 initializeV8Common(isolate); |
| 351 | 353 |
| 352 isolate->SetFatalErrorHandler(reportFatalErrorInMainThread); | 354 isolate->SetFatalErrorHandler(reportFatalErrorInMainThread); |
| 353 isolate->AddMessageListener(messageHandlerInMainThread); | 355 isolate->AddMessageListener(messageHandlerInMainThread); |
| 354 isolate->SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMai
nThread); | 356 isolate->SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMai
nThread); |
| 355 isolate->SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallba
ckInMainThread); | 357 isolate->SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallba
ckInMainThread); |
| 356 | 358 |
| 357 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) { | 359 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) { |
| 358 WebScheduler* scheduler = Platform::current()->currentThread()->schedule
r(); | 360 WebScheduler* scheduler = Platform::current()->currentThread()->schedule
r(); |
| 359 V8PerIsolateData::enableIdleTasks(isolate, adoptPtr(new V8IdleTaskRunner
(scheduler))); | 361 V8PerIsolateData::enableIdleTasks(isolate, wrapUnique(new V8IdleTaskRunn
er(scheduler))); |
| 360 } | 362 } |
| 361 | 363 |
| 362 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread); | 364 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread); |
| 363 | 365 |
| 364 if (v8::HeapProfiler* profiler = isolate->GetHeapProfiler()) | 366 if (v8::HeapProfiler* profiler = isolate->GetHeapProfiler()) |
| 365 profiler->SetWrapperClassInfoProvider(WrapperTypeInfo::NodeClassId, &Ret
ainedDOMInfo::createRetainedDOMInfo); | 367 profiler->SetWrapperClassInfoProvider(WrapperTypeInfo::NodeClassId, &Ret
ainedDOMInfo::createRetainedDOMInfo); |
| 366 | 368 |
| 367 ASSERT(ThreadState::mainThreadState()); | 369 ASSERT(ThreadState::mainThreadState()); |
| 368 ThreadState::mainThreadState()->addInterruptor(adoptPtr(new V8IsolateInterru
ptor(isolate))); | 370 ThreadState::mainThreadState()->addInterruptor(wrapUnique(new V8IsolateInter
ruptor(isolate))); |
| 369 if (RuntimeEnabledFeatures::traceWrappablesEnabled()) { | 371 if (RuntimeEnabledFeatures::traceWrappablesEnabled()) { |
| 370 ThreadState::mainThreadState()->registerTraceDOMWrappers(isolate, | 372 ThreadState::mainThreadState()->registerTraceDOMWrappers(isolate, |
| 371 V8GCController::traceDOMWrappers, | 373 V8GCController::traceDOMWrappers, |
| 372 ScriptWrappableVisitor::invalidateDeadObjectsInMarkingDeque); | 374 ScriptWrappableVisitor::invalidateDeadObjectsInMarkingDeque); |
| 373 } else { | 375 } else { |
| 374 ThreadState::mainThreadState()->registerTraceDOMWrappers(isolate, | 376 ThreadState::mainThreadState()->registerTraceDOMWrappers(isolate, |
| 375 V8GCController::traceDOMWrappers, | 377 V8GCController::traceDOMWrappers, |
| 376 nullptr); | 378 nullptr); |
| 377 } | 379 } |
| 378 | 380 |
| 379 V8PerIsolateData::from(isolate)->setThreadDebugger(adoptPtr(new MainThreadDe
bugger(isolate))); | 381 V8PerIsolateData::from(isolate)->setThreadDebugger(wrapUnique(new MainThread
Debugger(isolate))); |
| 380 } | 382 } |
| 381 | 383 |
| 382 void V8Initializer::shutdownMainThread() | 384 void V8Initializer::shutdownMainThread() |
| 383 { | 385 { |
| 384 ASSERT(isMainThread()); | 386 ASSERT(isMainThread()); |
| 385 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | 387 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); |
| 386 V8PerIsolateData::willBeDestroyed(isolate); | 388 V8PerIsolateData::willBeDestroyed(isolate); |
| 387 V8PerIsolateData::destroy(isolate); | 389 V8PerIsolateData::destroy(isolate); |
| 388 } | 390 } |
| 389 | 391 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 404 return; | 406 return; |
| 405 | 407 |
| 406 // Exceptions that occur in error handler should be ignored since in that ca
se | 408 // Exceptions that occur in error handler should be ignored since in that ca
se |
| 407 // WorkerGlobalScope::reportException will send the exception to the worker
object. | 409 // WorkerGlobalScope::reportException will send the exception to the worker
object. |
| 408 if (perIsolateData->isReportingException()) | 410 if (perIsolateData->isReportingException()) |
| 409 return; | 411 return; |
| 410 | 412 |
| 411 perIsolateData->setReportingException(true); | 413 perIsolateData->setReportingException(true); |
| 412 | 414 |
| 413 ExecutionContext* context = scriptState->getExecutionContext(); | 415 ExecutionContext* context = scriptState->getExecutionContext(); |
| 414 OwnPtr<SourceLocation> location = SourceLocation::fromMessage(isolate, messa
ge, context); | 416 std::unique_ptr<SourceLocation> location = SourceLocation::fromMessage(isola
te, message, context); |
| 415 ErrorEvent* event = ErrorEvent::create(toCoreStringWithNullCheck(message->Ge
t()), std::move(location), &scriptState->world()); | 417 ErrorEvent* event = ErrorEvent::create(toCoreStringWithNullCheck(message->Ge
t()), std::move(location), &scriptState->world()); |
| 416 | 418 |
| 417 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCr
ossOrigin : NotSharableCrossOrigin; | 419 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCr
ossOrigin : NotSharableCrossOrigin; |
| 418 | 420 |
| 419 // If execution termination has been triggered as part of constructing | 421 // If execution termination has been triggered as part of constructing |
| 420 // the error event from the v8::Message, quietly leave. | 422 // the error event from the v8::Message, quietly leave. |
| 421 if (!isolate->IsExecutionTerminating()) { | 423 if (!isolate->IsExecutionTerminating()) { |
| 422 V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, da
ta, scriptState->context()->Global()); | 424 V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, da
ta, scriptState->context()->Global()); |
| 423 scriptState->getExecutionContext()->reportException(event, corsStatus); | 425 scriptState->getExecutionContext()->reportException(event, corsStatus); |
| 424 } | 426 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 438 | 440 |
| 439 isolate->AddMessageListener(messageHandlerInWorker); | 441 isolate->AddMessageListener(messageHandlerInWorker); |
| 440 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); | 442 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); |
| 441 | 443 |
| 442 uint32_t here; | 444 uint32_t here; |
| 443 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi
ze / sizeof(uint32_t*))); | 445 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi
ze / sizeof(uint32_t*))); |
| 444 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); | 446 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); |
| 445 } | 447 } |
| 446 | 448 |
| 447 } // namespace blink | 449 } // namespace blink |
| OLD | NEW |