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

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

Issue 1885833002: Make messageHandlerInMainThread support main-thread worklets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Currently stack trace is only collected when inspector is open. 104 // Currently stack trace is only collected when inspector is open.
105 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) { 105 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) {
106 callStack = ScriptCallStack::create(isolate, stackTrace); 106 callStack = ScriptCallStack::create(isolate, stackTrace);
107 int topScriptId = stackTrace->GetFrame(0)->GetScriptId(); 107 int topScriptId = stackTrace->GetFrame(0)->GetScriptId();
108 if (topScriptId == *scriptId) 108 if (topScriptId == *scriptId)
109 *scriptId = 0; 109 *scriptId = 0;
110 } 110 }
111 return callStack.release(); 111 return callStack.release();
112 } 112 }
113 113
114 static String extractResourceName(v8::Local<v8::Message> message, const Document * document) 114 static String extractResourceName(v8::Local<v8::Message> message, const Executio nContext* context)
115 { 115 {
116 v8::Local<v8::Value> resourceName = message->GetScriptOrigin().ResourceName( ); 116 v8::Local<v8::Value> resourceName = message->GetScriptOrigin().ResourceName( );
117 bool shouldUseDocumentURL = document && (resourceName.IsEmpty() || !resource Name->IsString()); 117 bool shouldUseDocumentURL = context && context->isDocument() && (resourceNam e.IsEmpty() || !resourceName->IsString());
118 return shouldUseDocumentURL ? document->url() : toCoreString(resourceName.As <v8::String>()); 118 return shouldUseDocumentURL ? context->url() : toCoreString(resourceName.As< v8::String>());
119 } 119 }
120 120
121 static String extractMessageForConsole(v8::Isolate* isolate, v8::Local<v8::Value > data) 121 static String extractMessageForConsole(v8::Isolate* isolate, v8::Local<v8::Value > data)
122 { 122 {
123 if (V8DOMWrapper::isWrapper(isolate, data)) { 123 if (V8DOMWrapper::isWrapper(isolate, data)) {
124 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(data); 124 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(data);
125 const WrapperTypeInfo* type = toWrapperTypeInfo(obj); 125 const WrapperTypeInfo* type = toWrapperTypeInfo(obj);
126 if (V8DOMException::wrapperTypeInfo.isSubclass(type)) { 126 if (V8DOMException::wrapperTypeInfo.isSubclass(type)) {
127 DOMException* exception = V8DOMException::toImpl(obj); 127 DOMException* exception = V8DOMException::toImpl(obj);
128 if (exception && !exception->messageForConsole().isEmpty()) 128 if (exception && !exception->messageForConsole().isEmpty())
(...skipping 10 matching lines...) Expand all
139 int columnNumber = 0; 139 int columnNumber = 0;
140 if (v8Call(message->GetLineNumber(scriptState->context()), lineNumber) 140 if (v8Call(message->GetLineNumber(scriptState->context()), lineNumber)
141 && v8Call(message->GetStartColumn(scriptState->context()), columnNumber) ) 141 && v8Call(message->GetStartColumn(scriptState->context()), columnNumber) )
142 ++columnNumber; 142 ++columnNumber;
143 return ErrorEvent::create(errorMessage, resourceName, lineNumber, columnNumb er, &scriptState->world()); 143 return ErrorEvent::create(errorMessage, resourceName, lineNumber, columnNumb er, &scriptState->world());
144 } 144 }
145 145
146 static void messageHandlerInMainThread(v8::Local<v8::Message> message, v8::Local <v8::Value> data) 146 static void messageHandlerInMainThread(v8::Local<v8::Message> message, v8::Local <v8::Value> data)
147 { 147 {
148 ASSERT(isMainThread()); 148 ASSERT(isMainThread());
149
149 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 150 v8::Isolate* isolate = v8::Isolate::GetCurrent();
150 // If called during context initialization, there will be no entered window. 151 ScriptState* scriptState = ScriptState::current(isolate);
152 ExecutionContext* context = scriptState->getExecutionContext();
153
154 // If called during context initialization, there will be no entered context .
151 // TODO(haraken): Add a helper method to get an entered window that may be n ull. 155 // TODO(haraken): Add a helper method to get an entered window that may be n ull.
152 LocalDOMWindow* enteredWindow = toLocalDOMWindow(toDOMWindow(isolate->GetEnt eredContext())); 156 if (!context)
153 if (!enteredWindow || !enteredWindow->isCurrentlyDisplayedInFrame()) 157 return;
158
159 if (context->isDocument() && !toDocument(context)->domWindow()->isCurrentlyD isplayedInFrame())
ikilpatrick 2016/04/13 04:21:09 Is toDocument(context)->domWindow() safe? (non-nul
haraken 2016/04/13 04:38:48 This can change existing behavior because the ente
ikilpatrick 2016/04/13 23:26:53 Done. Tried to clean up the other ScriptState chec
154 return; 160 return;
155 161
156 int scriptId = 0; 162 int scriptId = 0;
157 RefPtr<ScriptCallStack> callStack = extractCallStack(isolate, message, &scri ptId); 163 RefPtr<ScriptCallStack> callStack = extractCallStack(isolate, message, &scri ptId);
158 164
159 AccessControlStatus accessControlStatus = NotSharableCrossOrigin; 165 AccessControlStatus accessControlStatus = NotSharableCrossOrigin;
160 if (message->IsOpaque()) 166 if (message->IsOpaque())
161 accessControlStatus = OpaqueResource; 167 accessControlStatus = OpaqueResource;
162 else if (message->IsSharedCrossOrigin()) 168 else if (message->IsSharedCrossOrigin())
163 accessControlStatus = SharableCrossOrigin; 169 accessControlStatus = SharableCrossOrigin;
164 170
165 ScriptState* scriptState = ScriptState::current(isolate); 171 String resourceName = extractResourceName(message, context);
166
167 String resourceName = extractResourceName(message, enteredWindow->document() );
168 ErrorEvent* event = createErrorEventFromMesssage(scriptState, message, resou rceName); 172 ErrorEvent* event = createErrorEventFromMesssage(scriptState, message, resou rceName);
169 173
170 String messageForConsole = extractMessageForConsole(isolate, data); 174 String messageForConsole = extractMessageForConsole(isolate, data);
171 if (!messageForConsole.isEmpty()) 175 if (!messageForConsole.isEmpty())
172 event->setUnsanitizedMessage("Uncaught " + messageForConsole); 176 event->setUnsanitizedMessage("Uncaught " + messageForConsole);
173 177
174 // This method might be called while we're creating a new context. In this c ase, we 178 // This method might be called while we're creating a new context. In this c ase, we
175 // avoid storing the exception object, as we can't create a wrapper during c ontext creation. 179 // avoid storing the exception object, as we can't create a wrapper during c ontext creation.
176 // FIXME: Can we even get here during initialization now that we bail out wh en GetEntered returns an empty handle? 180 // FIXME: Can we even get here during initialization now that we bail out wh en GetEntered returns an empty handle?
177 LocalFrame* frame = enteredWindow->document()->frame(); 181 if (context->isDocument()) {
178 if (frame && frame->script().existingWindowProxy(scriptState->world())) { 182 LocalFrame* frame = toDocument(context)->frame();
179 V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, da ta, scriptState->context()->Global()); 183 if (frame && frame->script().existingWindowProxy(scriptState->world())) {
184 V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event , data, scriptState->context()->Global());
185 }
180 } 186 }
181 187
182 if (scriptState->world().isPrivateScriptIsolatedWorld()) { 188 if (scriptState->world().isPrivateScriptIsolatedWorld()) {
183 // We allow a private script to dispatch error events even in a EventDis patchForbiddenScope scope. 189 // We allow a private script to dispatch error events even in a EventDis patchForbiddenScope scope.
184 // Without having this ability, it's hard to debug the private script be cause syntax errors 190 // Without having this ability, it's hard to debug the private script be cause syntax errors
185 // in the private script are not reported to console (the private script just crashes silently). 191 // in the private script are not reported to console (the private script just crashes silently).
186 // Allowing error events in private scripts is safe because error events don't propagate to 192 // Allowing error events in private scripts is safe because error events don't propagate to
187 // other isolated worlds (which means that the error events won't fire a ny event listeners 193 // other isolated worlds (which means that the error events won't fire a ny event listeners
188 // in user's scripts). 194 // in user's scripts).
189 EventDispatchForbiddenScope::AllowUserAgentEvents allowUserAgentEvents; 195 EventDispatchForbiddenScope::AllowUserAgentEvents allowUserAgentEvents;
190 enteredWindow->document()->reportException(event, scriptId, callStack, a ccessControlStatus); 196 context->reportException(event, scriptId, callStack, accessControlStatus );
191 } else { 197 } else {
192 enteredWindow->document()->reportException(event, scriptId, callStack, a ccessControlStatus); 198 context->reportException(event, scriptId, callStack, accessControlStatus );
193 } 199 }
194 } 200 }
195 201
196 namespace { 202 namespace {
197 203
198 static RejectedPromises& rejectedPromisesOnMainThread() 204 static RejectedPromises& rejectedPromisesOnMainThread()
199 { 205 {
200 ASSERT(isMainThread()); 206 ASSERT(isMainThread());
201 DEFINE_STATIC_LOCAL(RefPtr<RejectedPromises>, rejectedPromises, (RejectedPro mises::create())); 207 DEFINE_STATIC_LOCAL(RefPtr<RejectedPromises>, rejectedPromises, (RejectedPro mises::create()));
202 return *rejectedPromises; 208 return *rejectedPromises;
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 465
460 isolate->AddMessageListener(messageHandlerInWorker); 466 isolate->AddMessageListener(messageHandlerInWorker);
461 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); 467 isolate->SetFatalErrorHandler(reportFatalErrorInWorker);
462 468
463 uint32_t here; 469 uint32_t here;
464 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi ze / sizeof(uint32_t*))); 470 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi ze / sizeof(uint32_t*)));
465 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); 471 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker);
466 } 472 }
467 473
468 } // namespace blink 474 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698