v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
messages.h
Go to the documentation of this file.
1// Copyright 2006-2008 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_EXECUTION_MESSAGES_H_
6#define V8_EXECUTION_MESSAGES_H_
7
8// The infrastructure used for (localized) message reporting in V8.
9//
10// Note: there's a big unresolved issue about ownership of the data
11// structures used by this framework.
12
13#include <memory>
14
16#include "src/base/vector.h"
18#include "src/handles/handles.h"
20
21namespace v8 {
22class Value;
23
24namespace internal {
25
26// Forward declarations.
27class AbstractCode;
28class JSMessageObject;
29class LookupIterator;
30class PrimitiveHeapObject;
31class SharedFunctionInfo;
32class SourceInfo;
33class StackTraceInfo;
34class WasmInstanceObject;
35
37 public:
38 // Constructors for when source positions are already known.
39 // TODO(delphick): Collapse to a single constructor with a default parameter
40 // when we stop using the GCC that requires this separation.
41 MessageLocation(Handle<Script> script, int start_pos, int end_pos);
42 MessageLocation(Handle<Script> script, int start_pos, int end_pos,
44 // Constructor for when source positions were not collected but which can be
45 // reconstructed from the SharedFunctionInfo and bytecode offset.
47 int bytecode_offset);
49
50 Handle<Script> script() const { return script_; }
51 int start_pos() const { return start_pos_; }
52 int end_pos() const { return end_pos_; }
53 int bytecode_offset() const { return bytecode_offset_; }
55
56 private:
62};
63
64// Determines how stack trace collection skips frames.
66 // Unconditionally skips the first frame. Used e.g. when the Error constructor
67 // is called, in which case the first frame is always a BUILTIN_EXIT frame.
69 // Skip all frames until a specified caller function is seen.
72};
73
74class ErrorUtils : public AllStatic {
75 public:
76 // |kDisabled| is useful when you don't need the stack information at all, for
77 // example when creating a deserialized error.
83 DirectHandle<Object> options);
85 Isolate* isolate, DirectHandle<JSFunction> target,
88 DirectHandle<Object> caller, StackTraceCollection stack_trace_collection);
89
95 Isolate* isolate, DirectHandle<Object> recv,
96 ToStringMessageSource message_source =
98
100 Isolate* isolate, DirectHandle<JSFunction> constructor,
102 FrameSkipMode mode);
103
105 Isolate* isolate, DirectHandle<Object> original, MessageTemplate index,
107
108 // Formats a textual stack trace from the given structured stack trace.
109 // Note that this can call arbitrary JS code through Error.prepareStackTrace.
111 Isolate* isolate, DirectHandle<JSObject> error,
112 DirectHandle<Object> stack_trace);
113
115 DirectHandle<Object> source);
117 Isolate* isolate, DirectHandle<Object> source);
119 Isolate* isolate, DirectHandle<Object> source);
120 // Returns the Exception sentinel.
123 DirectHandle<Object> object);
124 // Returns the Exception sentinel.
126 Isolate* isolate, DirectHandle<Object> object,
128
129 // Returns true if given object has own |error_stack_symbol| property.
130 static bool HasErrorStackSymbolOwnProperty(Isolate* isolate,
132
134 // The holder of the |error_stack_symbol| or empty handle.
136 // The value of the |error_stack_symbol| property or |undefined_value|.
138 };
139 // Gets |error_stack_symbol| property value by looking up the prototype chain.
141 Isolate* isolate, DirectHandle<JSReceiver> maybe_error_object);
142
144 Isolate* isolate, DirectHandle<JSObject> maybe_error_object);
145 static void SetFormattedStack(Isolate* isolate,
146 DirectHandle<JSObject> maybe_error_object,
147 DirectHandle<Object> formatted_stack);
148
149 // Collects the stack trace and installs the stack property accessors.
152 FrameSkipMode mode,
153 Handle<Object> caller);
154};
155
157 public:
158 V8_EXPORT_PRIVATE static const char* TemplateString(MessageTemplate index);
159
161 Isolate* isolate, MessageTemplate index,
163
165 Isolate* isolate, MessageTemplate index,
167};
168
169// A message handler is a convenience interface for accessing the list
170// of message listeners registered in an environment
172 public:
173 // Returns a message object for the API to use.
175 Isolate* isolate, MessageTemplate type, const MessageLocation* location,
176 DirectHandle<Object> argument,
177 DirectHandle<StackTraceInfo> stack_trace =
179
180 // Report a formatted message (needs JS allocation).
182 Isolate* isolate, const MessageLocation* loc,
184
185 static void DefaultMessageReport(Isolate* isolate, const MessageLocation* loc,
186 DirectHandle<Object> message_obj);
189 static std::unique_ptr<char[]> GetLocalizedMessage(Isolate* isolate,
191
192 private:
193 static void ReportMessageNoExceptions(Isolate* isolate,
194 const MessageLocation* loc,
195 DirectHandle<Object> message_obj,
196 Local<Value> api_exception_obj);
197};
198
199} // namespace internal
200} // namespace v8
201
202#endif // V8_EXECUTION_MESSAGES_H_
static MaybeDirectHandle< Object > FormatStackTrace(Isolate *isolate, DirectHandle< JSObject > error, DirectHandle< Object > stack_trace)
Definition messages.cc:287
static bool HasErrorStackSymbolOwnProperty(Isolate *isolate, DirectHandle< JSObject > object)
Definition messages.cc:1118
static MaybeDirectHandle< Object > GetFormattedStack(Isolate *isolate, DirectHandle< JSObject > maybe_error_object)
Definition messages.cc:1147
static Handle< JSObject > MakeGenericError(Isolate *isolate, DirectHandle< JSFunction > constructor, MessageTemplate index, base::Vector< const DirectHandle< Object > > args, FrameSkipMode mode)
Definition messages.cc:730
static Tagged< Object > ThrowLoadFromNullOrUndefined(Isolate *isolate, DirectHandle< Object > object, MaybeDirectHandle< Object > key)
Definition messages.cc:1006
static DirectHandle< JSObject > NewCalledNonCallableError(Isolate *isolate, DirectHandle< Object > source)
Definition messages.cc:985
static V8_EXPORT_PRIVATE MaybeHandle< String > ToString(Isolate *isolate, DirectHandle< Object > recv, ToStringMessageSource message_source=ToStringMessageSource::kCurrentMessageProperty)
Definition messages.cc:658
static StackPropertyLookupResult GetErrorStackProperty(Isolate *isolate, DirectHandle< JSReceiver > maybe_error_object)
Definition messages.cc:1132
static void SetFormattedStack(Isolate *isolate, DirectHandle< JSObject > maybe_error_object, DirectHandle< Object > formatted_stack)
Definition messages.cc:1192
static DirectHandle< JSObject > NewIteratorError(Isolate *isolate, DirectHandle< Object > source)
Definition messages.cc:929
static MaybeDirectHandle< JSObject > Construct(Isolate *isolate, DirectHandle< JSFunction > target, DirectHandle< Object > new_target, DirectHandle< Object > message, DirectHandle< Object > options)
Definition messages.cc:528
static DirectHandle< JSObject > ShadowRealmConstructTypeErrorCopy(Isolate *isolate, DirectHandle< Object > original, MessageTemplate index, base::Vector< const DirectHandle< Object > > args)
Definition messages.cc:755
static MaybeHandle< Object > CaptureStackTrace(Isolate *isolate, DirectHandle< JSObject > object, FrameSkipMode mode, Handle< Object > caller)
Definition messages.cc:1216
static Tagged< Object > ThrowSpreadArgError(Isolate *isolate, MessageTemplate id, DirectHandle< Object > object)
Definition messages.cc:947
static DirectHandle< JSObject > NewConstructedNonConstructable(Isolate *isolate, DirectHandle< Object > source)
Definition messages.cc:996
static V8_EXPORT_PRIVATE const char * TemplateString(MessageTemplate index)
Definition messages.cc:425
static V8_EXPORT_PRIVATE MaybeHandle< String > TryFormat(Isolate *isolate, MessageTemplate index, base::Vector< const DirectHandle< String > > args)
Definition messages.cc:438
static DirectHandle< String > Format(Isolate *isolate, MessageTemplate index, base::Vector< const DirectHandle< Object > > args)
Definition messages.cc:396
static DirectHandle< String > GetMessage(Isolate *isolate, DirectHandle< Object > data)
Definition messages.cc:186
static V8_EXPORT_PRIVATE void ReportMessage(Isolate *isolate, const MessageLocation *loc, DirectHandle< JSMessageObject > message)
Definition messages.cc:98
static std::unique_ptr< char[]> GetLocalizedMessage(Isolate *isolate, DirectHandle< Object > data)
Definition messages.cc:194
static void DefaultMessageReport(Isolate *isolate, const MessageLocation *loc, DirectHandle< Object > message_obj)
Definition messages.cc:61
static void ReportMessageNoExceptions(Isolate *isolate, const MessageLocation *loc, DirectHandle< Object > message_obj, Local< Value > api_exception_obj)
Definition messages.cc:149
static V8_EXPORT_PRIVATE Handle< JSMessageObject > MakeMessageObject(Isolate *isolate, MessageTemplate type, const MessageLocation *location, DirectHandle< Object > argument, DirectHandle< StackTraceInfo > stack_trace=DirectHandle< StackTraceInfo >::null())
Definition messages.cc:77
Handle< Script > script_
Definition messages.h:57
Handle< SharedFunctionInfo > shared() const
Definition messages.h:54
Handle< SharedFunctionInfo > shared_
Definition messages.h:61
Handle< Script > script() const
Definition messages.h:50
Handle< Script > script_
Tagged< SharedFunctionInfo > shared_
Definition debug.cc:1741
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
DirectHandle< Object > new_target
Definition execution.cc:75
@ SKIP_UNTIL_SEEN
Definition messages.h:70
#define V8_EXPORT_PRIVATE
Definition macros.h:460
MaybeDirectHandle< JSObject > error_stack_symbol_holder
Definition messages.h:135