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

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

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

Powered by Google App Engine
This is Rietveld 408576698