chromium/third_party/blink/renderer/platform/bindings/source_location.h

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_SOURCE_LOCATION_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_SOURCE_LOCATION_H_

#include <memory>

#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"
#include "v8/include/v8-inspector.h"

namespace perfetto::protos::pbzero {
class BlinkSourceLocation;
}  // namespace perfetto::protos::pbzero

namespace blink {

class ExecutionContext;
class TracedValue;

// A location in JS source code.
// CaptureSourceLocation at the bottom of this file captures SourceLocation and
// return it. CaptureSourceLocation that depends on
// third_party/blink/renderer/core/ is in
// third_party/blink/renderer/bindings/core/v8/capture_source_location.h. We can
// capture SourceLocation using ExecutionContext.
class PLATFORM_EXPORT SourceLocation {};

// Zero lineNumber and columnNumber mean unknown. Captures current stack
// trace.
PLATFORM_EXPORT std::unique_ptr<SourceLocation> CaptureSourceLocation(
    const String& url,
    unsigned line_number,
    unsigned column_number);

// Returns SourceLocation if non-empty stack trace exists.
// If stack trace doesn't exists or it's empty, returns nullptr.
// This is the same when CaptureSourceLocation(ExecutionContext* = nullptr) in
// bindings/core/v8/capture_source_location.h
PLATFORM_EXPORT std::unique_ptr<SourceLocation> CaptureSourceLocation();

// Captures current stack trace from function.
PLATFORM_EXPORT std::unique_ptr<SourceLocation> CaptureSourceLocation(
    v8::Isolate* isolate,
    v8::Local<v8::Function>);

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_SOURCE_LOCATION_H_