| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // Allowing error events in private scripts is safe because error events
don't propagate to | 151 // Allowing error events in private scripts is safe because error events
don't propagate to |
| 152 // other isolated worlds (which means that the error events won't fire a
ny event listeners | 152 // other isolated worlds (which means that the error events won't fire a
ny event listeners |
| 153 // in user's scripts). | 153 // in user's scripts). |
| 154 EventDispatchForbiddenScope::AllowUserAgentEvents allowUserAgentEvents; | 154 EventDispatchForbiddenScope::AllowUserAgentEvents allowUserAgentEvents; |
| 155 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); | 155 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); |
| 156 } else { | 156 } else { |
| 157 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); | 157 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 typedef WillBeHeapDeque<ScriptValue> PromiseRejectMessageQueue; | 161 namespace { |
| 162 |
| 163 class PromiseRejectMessage { |
| 164 public: |
| 165 PromiseRejectMessage(const ScriptValue& promise, PassRefPtrWillBeRawPtr<Scri
ptCallStack> callStack) |
| 166 : m_promise(promise) |
| 167 , m_callStack(callStack) |
| 168 { |
| 169 } |
| 170 |
| 171 const ScriptValue m_promise; |
| 172 const RefPtrWillBeMember<ScriptCallStack> m_callStack; |
| 173 }; |
| 174 |
| 175 } // namespace |
| 176 |
| 177 typedef WillBeHeapDeque<PromiseRejectMessage> PromiseRejectMessageQueue; |
| 162 | 178 |
| 163 static PromiseRejectMessageQueue& promiseRejectMessageQueue() | 179 static PromiseRejectMessageQueue& promiseRejectMessageQueue() |
| 164 { | 180 { |
| 165 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<PromiseRejectMessageQueue>, queue
, (adoptPtrWillBeNoop(new PromiseRejectMessageQueue()))); | 181 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<PromiseRejectMessageQueue>, queue
, (adoptPtrWillBeNoop(new PromiseRejectMessageQueue()))); |
| 166 return *queue; | 182 return *queue; |
| 167 } | 183 } |
| 168 | 184 |
| 169 void V8Initializer::reportRejectedPromises() | 185 void V8Initializer::reportRejectedPromises() |
| 170 { | 186 { |
| 171 ASSERT(isMainThread()); | 187 ASSERT(isMainThread()); |
| 172 | 188 |
| 173 PromiseRejectMessageQueue& queue = promiseRejectMessageQueue(); | 189 PromiseRejectMessageQueue& queue = promiseRejectMessageQueue(); |
| 174 while (!queue.isEmpty()) { | 190 while (!queue.isEmpty()) { |
| 175 ScriptValue promise = queue.takeFirst(); | 191 PromiseRejectMessage message = queue.takeFirst(); |
| 176 ScriptState* scriptState = promise.scriptState(); | 192 ScriptState* scriptState = message.m_promise.scriptState(); |
| 177 if (!scriptState->contextIsValid()) | 193 if (!scriptState->contextIsValid()) |
| 178 continue; | 194 continue; |
| 179 ScriptState::Scope scope(scriptState); | 195 ScriptState::Scope scope(scriptState); |
| 180 | 196 |
| 181 ASSERT(!promise.isEmpty()); | 197 ASSERT(!message.m_promise.isEmpty()); |
| 182 v8::Handle<v8::Value> value = promise.v8Value(); | 198 v8::Handle<v8::Value> value = message.m_promise.v8Value(); |
| 183 ASSERT(!value.IsEmpty() && value->IsPromise()); | 199 ASSERT(!value.IsEmpty() && value->IsPromise()); |
| 184 if (v8::Handle<v8::Promise>::Cast(value)->HasHandler()) | 200 if (v8::Handle<v8::Promise>::Cast(value)->HasHandler()) |
| 185 continue; | 201 continue; |
| 186 | 202 |
| 187 ExecutionContext* executionContext = scriptState->executionContext(); | 203 ExecutionContext* executionContext = scriptState->executionContext(); |
| 188 if (!executionContext) | 204 if (!executionContext) |
| 189 continue; | 205 continue; |
| 190 | 206 |
| 191 const String errorMessage = "Unhandled promise rejection"; | 207 const String errorMessage = "Unhandled promise rejection"; |
| 192 Vector<ScriptValue> args; | 208 Vector<ScriptValue> args; |
| 193 args.append(ScriptValue(scriptState, v8String(scriptState->isolate(), er
rorMessage))); | 209 args.append(ScriptValue(scriptState, v8String(scriptState->isolate(), er
rorMessage))); |
| 194 args.append(promise); | 210 args.append(message.m_promise); |
| 195 RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::create(
scriptState, args); | 211 RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::create(
scriptState, args); |
| 196 | 212 |
| 197 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::crea
te(JSMessageSource, ErrorMessageLevel, errorMessage, "", 0); | 213 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::crea
te(JSMessageSource, ErrorMessageLevel, errorMessage); |
| 198 consoleMessage->setScriptArguments(arguments); | 214 consoleMessage->setScriptArguments(arguments); |
| 215 consoleMessage->setCallStack(message.m_callStack); |
| 199 executionContext->addConsoleMessage(consoleMessage.release()); | 216 executionContext->addConsoleMessage(consoleMessage.release()); |
| 200 } | 217 } |
| 201 } | 218 } |
| 202 | 219 |
| 203 static void promiseRejectHandlerInMainThread(v8::PromiseRejectMessage message) | 220 static void promiseRejectHandlerInMainThread(v8::PromiseRejectMessage message) |
| 204 { | 221 { |
| 205 ASSERT(isMainThread()); | 222 ASSERT(isMainThread()); |
| 206 | 223 |
| 207 if (message.GetEvent() != v8::kPromiseRejectWithNoHandler) | 224 if (message.GetEvent() != v8::kPromiseRejectWithNoHandler) |
| 208 return; | 225 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 219 v8::Isolate* isolate = promise->GetIsolate(); | 236 v8::Isolate* isolate = promise->GetIsolate(); |
| 220 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); | 237 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
| 221 if (context.IsEmpty()) | 238 if (context.IsEmpty()) |
| 222 return; | 239 return; |
| 223 v8::Handle<v8::Value> global = V8Window::findInstanceInPrototypeChain(contex
t->Global(), context->GetIsolate()); | 240 v8::Handle<v8::Value> global = V8Window::findInstanceInPrototypeChain(contex
t->Global(), context->GetIsolate()); |
| 224 if (global.IsEmpty()) | 241 if (global.IsEmpty()) |
| 225 return; | 242 return; |
| 226 if (!toFrameIfNotDetached(context)) | 243 if (!toFrameIfNotDetached(context)) |
| 227 return; | 244 return; |
| 228 | 245 |
| 246 RefPtrWillBeRawPtr<ScriptCallStack> callStack = nullptr; |
| 247 v8::Handle<v8::StackTrace> stackTrace = message.GetStackTrace(); |
| 248 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) |
| 249 callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallSt
ackSizeToCapture, isolate); |
| 250 |
| 229 ScriptState* scriptState = ScriptState::from(context); | 251 ScriptState* scriptState = ScriptState::from(context); |
| 230 promiseRejectMessageQueue().append(ScriptValue(scriptState, promise)); | 252 promiseRejectMessageQueue().append(PromiseRejectMessage(ScriptValue(scriptSt
ate, promise), callStack)); |
| 231 } | 253 } |
| 232 | 254 |
| 233 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8
::AccessType type, v8::Local<v8::Value> data) | 255 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8
::AccessType type, v8::Local<v8::Value> data) |
| 234 { | 256 { |
| 235 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 257 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 236 LocalFrame* target = findFrame(host, data, isolate); | 258 LocalFrame* target = findFrame(host, data, isolate); |
| 237 if (!target) | 259 if (!target) |
| 238 return; | 260 return; |
| 239 LocalDOMWindow* targetWindow = target->domWindow(); | 261 LocalDOMWindow* targetWindow = target->domWindow(); |
| 240 | 262 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 initializeV8Common(isolate); | 364 initializeV8Common(isolate); |
| 343 | 365 |
| 344 v8::V8::AddMessageListener(messageHandlerInWorker); | 366 v8::V8::AddMessageListener(messageHandlerInWorker); |
| 345 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); | 367 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); |
| 346 | 368 |
| 347 uint32_t here; | 369 uint32_t here; |
| 348 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi
ze / sizeof(uint32_t*))); | 370 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi
ze / sizeof(uint32_t*))); |
| 349 } | 371 } |
| 350 | 372 |
| 351 } // namespace blink | 373 } // namespace blink |
| OLD | NEW |