Esempio n. 1
0
// static
std::unique_ptr<SourceLocation> SourceLocation::fromFunction(
    v8::Local<v8::Function> function) {
  if (!function.IsEmpty())
    return SourceLocation::create(
        toCoreStringWithUndefinedOrNullCheck(
            function->GetScriptOrigin().ResourceName()),
        function->GetScriptLineNumber() + 1,
        function->GetScriptColumnNumber() + 1, nullptr, function->ScriptId());
  return SourceLocation::create(String(), 0, 0, nullptr, 0);
}
v8::Local<v8::Object> JavaScriptCallFrame::createExceptionDetails(v8::Isolate* isolate, v8::Local<v8::Message> message)
{
    v8::Local<v8::Object> exceptionDetails = v8::Object::New(isolate);
    exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "text"), message->Get());
    exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "url"), message->GetScriptOrigin().ResourceName());
    exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "scriptId"), v8::Integer::New(isolate, message->GetScriptOrigin().ScriptID()->Value()));
    exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "line"), v8::Integer::New(isolate, message->GetLineNumber()));
    exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "column"), v8::Integer::New(isolate, message->GetStartColumn()));
    if (!message->GetStackTrace().IsEmpty())
        exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "stackTrace"), message->GetStackTrace()->AsArray());
    else
        exceptionDetails->Set(v8::String::NewFromUtf8(isolate, "stackTrace"), v8::Undefined(isolate));
    return exceptionDetails;
}
Esempio n. 3
0
std::unique_ptr<protocol::Runtime::ExceptionDetails> InjectedScript::createExceptionDetails(v8::Local<v8::Message> message)
{
    std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetailsObject = protocol::Runtime::ExceptionDetails::create()
        .setText(toProtocolString(message->Get()))
        .setScriptId(String16::fromInteger(message->GetScriptOrigin().ScriptID()->Value()))
        .setLineNumber(message->GetLineNumber(m_context->context()).FromMaybe(1) - 1)
        .setColumnNumber(message->GetStartColumn(m_context->context()).FromMaybe(0))
        .build();

    v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace();
    if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0)
        exceptionDetailsObject->setStackTrace(m_context->inspector()->debugger()->createStackTrace(stackTrace)->buildInspectorObjectImpl());
    return exceptionDetailsObject;
}
Esempio n. 4
0
static PassRefPtrWillBeRawPtr<ScriptCallStack> extractCallStack(v8::Isolate* isolate, v8::Local<v8::Message> message, int* const scriptId)
{
    v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace();
    RefPtrWillBeRawPtr<ScriptCallStack> callStack = nullptr;
    *scriptId = message->GetScriptOrigin().ScriptID()->Value();
    // Currently stack trace is only collected when inspector is open.
    if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) {
        callStack = createScriptCallStack(isolate, stackTrace, ScriptCallStack::maxCallStackSizeToCapture);
        bool success = false;
        int topScriptId = callStack->at(0).scriptId().toInt(&success);
        if (success && topScriptId == *scriptId)
            *scriptId = 0;
    }
    return callStack.release();
}
Esempio n. 5
0
// static
std::unique_ptr<SourceLocation> SourceLocation::fromMessage(
    v8::Isolate* isolate,
    v8::Local<v8::Message> message,
    ExecutionContext* executionContext) {
  v8::Local<v8::StackTrace> stack = message->GetStackTrace();
  std::unique_ptr<v8_inspector::V8StackTrace> stackTrace = nullptr;
  V8PerIsolateData* data = V8PerIsolateData::from(isolate);
  if (data && data->threadDebugger())
    stackTrace = data->threadDebugger()->v8Inspector()->createStackTrace(stack);

  int scriptId = message->GetScriptOrigin().ScriptID()->Value();
  if (!stack.IsEmpty() && stack->GetFrameCount() > 0) {
    int topScriptId = stack->GetFrame(0)->GetScriptId();
    if (topScriptId == scriptId)
      scriptId = 0;
  }

  int lineNumber = 0;
  int columnNumber = 0;
  if (v8Call(message->GetLineNumber(isolate->GetCurrentContext()),
             lineNumber) &&
      v8Call(message->GetStartColumn(isolate->GetCurrentContext()),
             columnNumber))
    ++columnNumber;

  if ((!scriptId || !lineNumber) && stackTrace && !stackTrace->isEmpty())
    return SourceLocation::createFromNonEmptyV8StackTrace(std::move(stackTrace),
                                                          0);

  String url = toCoreStringWithUndefinedOrNullCheck(
      message->GetScriptOrigin().ResourceName());
  if (url.isNull())
    url = executionContext->url();
  return SourceLocation::create(url, lineNumber, columnNumber,
                                std::move(stackTrace), scriptId);
}
Esempio n. 6
0
static void messageHandlerInWorker(v8::Local<v8::Message> message, v8::Local<v8::Value> data)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    V8PerIsolateData* perIsolateData = V8PerIsolateData::from(isolate);
    // Exceptions that occur in error handler should be ignored since in that case
    // WorkerGlobalScope::reportException will send the exception to the worker object.
    if (perIsolateData->isReportingException())
        return;
    perIsolateData->setReportingException(true);

    ScriptState* scriptState = ScriptState::current(isolate);
    // During the frame teardown, there may not be a valid context.
    if (ExecutionContext* context = scriptState->executionContext()) {
        String errorMessage = toCoreStringWithNullCheck(message->Get());
        TOSTRING_VOID(V8StringResource<>, sourceURL, message->GetScriptOrigin().ResourceName());
        int scriptId = 0;
        RefPtrWillBeRawPtr<ScriptCallStack> callStack = extractCallStack(isolate, message, &scriptId);

        int lineNumber = 0;
        int columnNumber = 0;
        if (v8Call(message->GetLineNumber(scriptState->context()), lineNumber)
            && v8Call(message->GetStartColumn(scriptState->context()), columnNumber))
            ++columnNumber;
        RefPtrWillBeRawPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, lineNumber, columnNumber, &DOMWrapperWorld::current(isolate));
        AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCrossOrigin : NotSharableCrossOrigin;

        // If execution termination has been triggered as part of constructing
        // the error event from the v8::Message, quietly leave.
        if (!v8::V8::IsExecutionTerminating(isolate)) {
            V8ErrorHandler::storeExceptionOnErrorEventWrapper(isolate, event.get(), data, scriptState->context()->Global());
            context->reportException(event.release(), scriptId, callStack, corsStatus);
        }
    }

    perIsolateData->setReportingException(false);
}
Esempio n. 7
0
static String extractResourceName(v8::Local<v8::Message> message, const Document* document)
{
    v8::Local<v8::Value> resourceName = message->GetScriptOrigin().ResourceName();
    bool shouldUseDocumentURL = document && (resourceName.IsEmpty() || !resourceName->IsString());
    return shouldUseDocumentURL ? document->url() : toCoreString(resourceName.As<v8::String>());
}