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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 357 |
356 initializeV8Common(isolate); | 358 initializeV8Common(isolate); |
357 | 359 |
358 isolate->SetFatalErrorHandler(reportFatalErrorInMainThread); | 360 isolate->SetFatalErrorHandler(reportFatalErrorInMainThread); |
359 isolate->AddMessageListener(messageHandlerInMainThread); | 361 isolate->AddMessageListener(messageHandlerInMainThread); |
360 isolate->SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMai
nThread); | 362 isolate->SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMai
nThread); |
361 isolate->SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallba
ckInMainThread); | 363 isolate->SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallba
ckInMainThread); |
362 | 364 |
363 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) { | 365 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) { |
364 WebScheduler* scheduler = Platform::current()->currentThread()->schedule
r(); | 366 WebScheduler* scheduler = Platform::current()->currentThread()->schedule
r(); |
365 V8PerIsolateData::enableIdleTasks(isolate, adoptPtr(new V8IdleTaskRunner
(scheduler))); | 367 V8PerIsolateData::enableIdleTasks(isolate, wrapUnique(new V8IdleTaskRunn
er(scheduler))); |
366 } | 368 } |
367 | 369 |
368 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread); | 370 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread); |
369 | 371 |
370 if (v8::HeapProfiler* profiler = isolate->GetHeapProfiler()) | 372 if (v8::HeapProfiler* profiler = isolate->GetHeapProfiler()) |
371 profiler->SetWrapperClassInfoProvider(WrapperTypeInfo::NodeClassId, &Ret
ainedDOMInfo::createRetainedDOMInfo); | 373 profiler->SetWrapperClassInfoProvider(WrapperTypeInfo::NodeClassId, &Ret
ainedDOMInfo::createRetainedDOMInfo); |
372 | 374 |
373 ASSERT(ThreadState::mainThreadState()); | 375 ASSERT(ThreadState::mainThreadState()); |
374 ThreadState::mainThreadState()->addInterruptor(adoptPtr(new V8IsolateInterru
ptor(isolate))); | 376 ThreadState::mainThreadState()->addInterruptor(wrapUnique(new V8IsolateInter
ruptor(isolate))); |
375 if (RuntimeEnabledFeatures::traceWrappablesEnabled()) { | 377 if (RuntimeEnabledFeatures::traceWrappablesEnabled()) { |
376 ThreadState::mainThreadState()->registerTraceDOMWrappers(isolate, | 378 ThreadState::mainThreadState()->registerTraceDOMWrappers(isolate, |
377 V8GCController::traceDOMWrappers, | 379 V8GCController::traceDOMWrappers, |
378 ScriptWrappableVisitor::invalidateDeadObjectsInMarkingDeque); | 380 ScriptWrappableVisitor::invalidateDeadObjectsInMarkingDeque); |
379 } else { | 381 } else { |
380 ThreadState::mainThreadState()->registerTraceDOMWrappers(isolate, | 382 ThreadState::mainThreadState()->registerTraceDOMWrappers(isolate, |
381 V8GCController::traceDOMWrappers, | 383 V8GCController::traceDOMWrappers, |
382 nullptr); | 384 nullptr); |
383 } | 385 } |
384 | 386 |
385 V8PerIsolateData::from(isolate)->setThreadDebugger(adoptPtr(new MainThreadDe
bugger(isolate))); | 387 V8PerIsolateData::from(isolate)->setThreadDebugger(wrapUnique(new MainThread
Debugger(isolate))); |
386 } | 388 } |
387 | 389 |
388 void V8Initializer::shutdownMainThread() | 390 void V8Initializer::shutdownMainThread() |
389 { | 391 { |
390 ASSERT(isMainThread()); | 392 ASSERT(isMainThread()); |
391 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | 393 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); |
392 V8PerIsolateData::willBeDestroyed(isolate); | 394 V8PerIsolateData::willBeDestroyed(isolate); |
393 V8PerIsolateData::destroy(isolate); | 395 V8PerIsolateData::destroy(isolate); |
394 } | 396 } |
395 | 397 |
(...skipping 14 matching lines...) Expand all Loading... |
410 return; | 412 return; |
411 | 413 |
412 // Exceptions that occur in error handler should be ignored since in that ca
se | 414 // Exceptions that occur in error handler should be ignored since in that ca
se |
413 // WorkerGlobalScope::reportException will send the exception to the worker
object. | 415 // WorkerGlobalScope::reportException will send the exception to the worker
object. |
414 if (perIsolateData->isReportingException()) | 416 if (perIsolateData->isReportingException()) |
415 return; | 417 return; |
416 | 418 |
417 perIsolateData->setReportingException(true); | 419 perIsolateData->setReportingException(true); |
418 | 420 |
419 ExecutionContext* context = scriptState->getExecutionContext(); | 421 ExecutionContext* context = scriptState->getExecutionContext(); |
420 OwnPtr<SourceLocation> location = SourceLocation::fromMessage(isolate, messa
ge, context); | 422 std::unique_ptr<SourceLocation> location = SourceLocation::fromMessage(isola
te, message, context); |
421 ErrorEvent* event = ErrorEvent::create(toCoreStringWithNullCheck(message->Ge
t()), std::move(location), &scriptState->world()); | 423 ErrorEvent* event = ErrorEvent::create(toCoreStringWithNullCheck(message->Ge
t()), std::move(location), &scriptState->world()); |
422 | 424 |
423 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCr
ossOrigin : NotSharableCrossOrigin; | 425 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCr
ossOrigin : NotSharableCrossOrigin; |
424 | 426 |
425 // If execution termination has been triggered as part of constructing | 427 // If execution termination has been triggered as part of constructing |
426 // the error event from the v8::Message, quietly leave. | 428 // the error event from the v8::Message, quietly leave. |
427 if (!isolate->IsExecutionTerminating()) { | 429 if (!isolate->IsExecutionTerminating()) { |
428 V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, da
ta, scriptState->context()->Global()); | 430 V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, da
ta, scriptState->context()->Global()); |
429 scriptState->getExecutionContext()->reportException(event, corsStatus); | 431 scriptState->getExecutionContext()->reportException(event, corsStatus); |
430 } | 432 } |
(...skipping 13 matching lines...) Expand all Loading... |
444 | 446 |
445 isolate->AddMessageListener(messageHandlerInWorker); | 447 isolate->AddMessageListener(messageHandlerInWorker); |
446 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); | 448 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); |
447 | 449 |
448 uint32_t here; | 450 uint32_t here; |
449 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi
ze / sizeof(uint32_t*))); | 451 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi
ze / sizeof(uint32_t*))); |
450 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); | 452 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); |
451 } | 453 } |
452 | 454 |
453 } // namespace blink | 455 } // namespace blink |
OLD | NEW |