コード例 #1
0
static void promiseRejectHandler(v8::PromiseRejectMessage data, RejectedPromises& rejectedPromises, const String& fallbackResourceName)
{
    if (data.GetEvent() == v8::kPromiseHandlerAddedAfterReject) {
        rejectedPromises.handlerAdded(data);
        return;
    }

    ASSERT(data.GetEvent() == v8::kPromiseRejectWithNoHandler);

    v8::Local<v8::Promise> promise = data.GetPromise();
    v8::Isolate* isolate = promise->GetIsolate();
    ScriptState* scriptState = ScriptState::current(isolate);

    v8::Local<v8::Value> exception = data.GetValue();
    if (V8DOMWrapper::isWrapper(isolate, exception)) {
        // Try to get the stack & location from a wrapped exception object (e.g. DOMException).
        ASSERT(exception->IsObject());
        v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(exception);
        v8::Local<v8::Value> error = V8HiddenValue::getHiddenValue(scriptState, obj, V8HiddenValue::error(isolate));
        if (!error.IsEmpty())
            exception = error;
    }

    int scriptId = 0;
    int lineNumber = 0;
    int columnNumber = 0;
    String resourceName = fallbackResourceName;
    String errorMessage;
    AccessControlStatus corsStatus = NotSharableCrossOrigin;
    RefPtrWillBeRawPtr<ScriptCallStack> callStack = nullptr;

    v8::Local<v8::Message> message = v8::Exception::CreateMessage(isolate, exception);
    if (!message.IsEmpty()) {
        V8StringResource<> v8ResourceName(message->GetScriptOrigin().ResourceName());
        if (v8ResourceName.prepare())
            resourceName = v8ResourceName;
        scriptId = message->GetScriptOrigin().ScriptID()->Value();
        if (v8Call(message->GetLineNumber(scriptState->context()), lineNumber)
            && v8Call(message->GetStartColumn(scriptState->context()), columnNumber))
            ++columnNumber;
        // message->Get() can be empty here. https://crbug.com/450330
        errorMessage = toCoreStringWithNullCheck(message->Get());
        callStack = extractCallStack(isolate, message, &scriptId);
        if (message->IsSharedCrossOrigin())
            corsStatus = SharableCrossOrigin;
    }

    String messageForConsole = extractMessageForConsole(isolate, data.GetValue());
    if (!messageForConsole.isEmpty())
        errorMessage = "Uncaught " + messageForConsole;

    rejectedPromises.rejectedWithNoHandler(scriptState, data, errorMessage, resourceName, scriptId, lineNumber, columnNumber, callStack, corsStatus);
}
コード例 #2
0
ファイル: V8Initializer.cpp プロジェクト: ollie314/chromium
static void promiseRejectHandler(v8::PromiseRejectMessage data,
                                 RejectedPromises& rejectedPromises,
                                 ScriptState* scriptState) {
  if (data.GetEvent() == v8::kPromiseHandlerAddedAfterReject) {
    rejectedPromises.handlerAdded(data);
    return;
  }

  ASSERT(data.GetEvent() == v8::kPromiseRejectWithNoHandler);

  v8::Local<v8::Promise> promise = data.GetPromise();
  v8::Isolate* isolate = promise->GetIsolate();
  ExecutionContext* context = scriptState->getExecutionContext();

  v8::Local<v8::Value> exception = data.GetValue();
  if (V8DOMWrapper::isWrapper(isolate, exception)) {
    // Try to get the stack & location from a wrapped exception object (e.g.
    // DOMException).
    ASSERT(exception->IsObject());
    auto privateError = V8PrivateProperty::getDOMExceptionError(isolate);
    v8::Local<v8::Value> error = privateError.getOrUndefined(
        scriptState->context(), exception.As<v8::Object>());
    if (!error->IsUndefined())
      exception = error;
  }

  String errorMessage;
  AccessControlStatus corsStatus = NotSharableCrossOrigin;
  std::unique_ptr<SourceLocation> location;

  v8::Local<v8::Message> message =
      v8::Exception::CreateMessage(isolate, exception);
  if (!message.IsEmpty()) {
    // message->Get() can be empty here. https://crbug.com/450330
    errorMessage = toCoreStringWithNullCheck(message->Get());
    location = SourceLocation::fromMessage(isolate, message, context);
    if (message->IsSharedCrossOrigin())
      corsStatus = SharableCrossOrigin;
  } else {
    location =
        SourceLocation::create(context->url().getString(), 0, 0, nullptr);
  }

  String messageForConsole = extractMessageForConsole(isolate, data.GetValue());
  if (!messageForConsole.isEmpty())
    errorMessage = "Uncaught " + messageForConsole;

  rejectedPromises.rejectedWithNoHandler(scriptState, data, errorMessage,
                                         std::move(location), corsStatus);
}