v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
messages.cc
Go to the documentation of this file.
1// Copyright 2011 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
6
7#include <memory>
8
9#include "src/api/api-inl.h"
10#include "src/ast/ast.h"
25#include "src/parsing/parsing.h"
26#include "src/roots/roots.h"
28
29namespace v8 {
30namespace internal {
31
33 int end_pos)
34 : script_(script),
35 start_pos_(start_pos),
36 end_pos_(end_pos),
37 bytecode_offset_(-1) {}
38
40 int end_pos, Handle<SharedFunctionInfo> shared)
41 : script_(script),
42 start_pos_(start_pos),
43 end_pos_(end_pos),
44 bytecode_offset_(-1),
45 shared_(shared) {}
46
49 int bytecode_offset)
50 : script_(script),
51 start_pos_(-1),
52 end_pos_(-1),
53 bytecode_offset_(bytecode_offset),
54 shared_(shared) {}
55
57 : start_pos_(-1), end_pos_(-1), bytecode_offset_(-1) {}
58
59// If no message listeners have been registered this one is called
60// by default.
62 const MessageLocation* loc,
63 DirectHandle<Object> message_obj) {
64 std::unique_ptr<char[]> str = GetLocalizedMessage(isolate, message_obj);
65 if (loc == nullptr) {
66 PrintF("%s\n", str.get());
67 } else {
68 HandleScope scope(isolate);
69 DirectHandle<Object> data(loc->script()->name(), isolate);
70 std::unique_ptr<char[]> data_str;
71 if (IsString(*data)) data_str = Cast<String>(data)->ToCString();
72 PrintF("%s:%i: %s\n", data_str ? data_str.get() : "<unknown>",
73 loc->start_pos(), str.get());
74 }
75}
76
78 Isolate* isolate, MessageTemplate message, const MessageLocation* location,
80 int start = -1;
81 int end = -1;
82 int bytecode_offset = -1;
83 DirectHandle<Script> script_handle = isolate->factory()->empty_script();
85 if (location != nullptr && !v8_flags.correctness_fuzzer_suppressions) {
86 start = location->start_pos();
87 end = location->end_pos();
88 script_handle = location->script();
89 bytecode_offset = location->bytecode_offset();
90 shared_info = location->shared();
91 }
92
93 return isolate->factory()->NewJSMessageObject(message, argument, start, end,
94 shared_info, bytecode_offset,
95 script_handle, stack_trace);
96}
97
100 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message);
101
102 if (api_message_obj->ErrorLevel() != v8::Isolate::kMessageError) {
103 ReportMessageNoExceptions(isolate, loc, message, v8::Local<v8::Value>());
104 return;
105 }
106
107 // We are calling into embedder's code which can throw exceptions.
108 // Thus we need to save current exception state, reset it to the clean one
109 // and ignore scheduled exceptions callbacks can throw.
110
111 // We pass the exception object into the message handler callback though.
112 DirectHandle<Object> exception = isolate->factory()->undefined_value();
113 if (isolate->has_exception()) {
114 exception = direct_handle(isolate->exception(), isolate);
115 }
116
117 Isolate::ExceptionScope exception_scope(isolate);
118 isolate->clear_pending_message();
119
120 // Turn the exception on the message into a string if it is an object.
121 if (IsJSObject(message->argument())) {
122 HandleScope scope(isolate);
123 DirectHandle<Object> argument(message->argument(), isolate);
124
125 MaybeDirectHandle<Object> maybe_stringified;
126 DirectHandle<Object> stringified;
127 // Make sure we don't leak uncaught internally generated Error objects.
128 if (IsJSError(*argument)) {
129 maybe_stringified = Object::NoSideEffectsToString(isolate, argument);
130 } else {
131 v8::TryCatch catcher(reinterpret_cast<v8::Isolate*>(isolate));
132 catcher.SetVerbose(false);
133 catcher.SetCaptureMessage(false);
134
135 maybe_stringified = Object::ToString(isolate, argument);
136 }
137
138 if (!maybe_stringified.ToHandle(&stringified)) {
139 isolate->clear_pending_message();
140 stringified = isolate->factory()->exception_string();
141 }
142 message->set_argument(*stringified);
143 }
144
145 v8::Local<v8::Value> api_exception_obj = v8::Utils::ToLocal(exception);
146 ReportMessageNoExceptions(isolate, loc, message, api_exception_obj);
147}
148
150 Isolate* isolate, const MessageLocation* loc, DirectHandle<Object> message,
151 v8::Local<v8::Value> api_exception_obj) {
152 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message);
153 int error_level = api_message_obj->ErrorLevel();
154
155 DirectHandle<ArrayList> global_listeners =
156 isolate->factory()->message_listeners();
157 int global_length = global_listeners->length();
158 if (global_length == 0) {
159 DefaultMessageReport(isolate, loc, message);
160 } else {
161 for (int i = 0; i < global_length; i++) {
162 HandleScope scope(isolate);
163 if (IsUndefined(global_listeners->get(i), isolate)) continue;
164 Tagged<FixedArray> listener = Cast<FixedArray>(global_listeners->get(i));
165 Tagged<Foreign> callback_obj = Cast<Foreign>(listener->get(0));
166 int32_t message_levels =
167 static_cast<int32_t>(Smi::ToInt(listener->get(2)));
168 if (!(message_levels & error_level)) {
169 continue;
170 }
172 callback_obj->foreign_address<kMessageListenerTag>());
173 DirectHandle<Object> callback_data(listener->get(1), isolate);
174 {
175 RCS_SCOPE(isolate, RuntimeCallCounterId::kMessageListenerCallback);
176 // Do not allow exceptions to propagate.
177 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
178 callback(api_message_obj, IsUndefined(*callback_data, isolate)
179 ? api_exception_obj
180 : v8::Utils::ToLocal(callback_data));
181 }
182 }
183 }
184}
185
189 DirectHandle<Object> arg{message->argument(), isolate};
190 return MessageFormatter::Format(isolate, message->type(),
191 base::VectorOf({arg}));
192}
193
195 Isolate* isolate, DirectHandle<Object> data) {
196 HandleScope scope(isolate);
197 return GetMessage(isolate, data)->ToCString();
198}
199
200namespace {
201
202// Convert the raw frames as written by Isolate::CaptureSimpleStackTrace into
203// a JSArray of JSCallSite objects.
204MaybeDirectHandle<JSArray> GetStackFrames(Isolate* isolate,
206 int frame_count = frames->length();
207 DirectHandle<JSFunction> constructor = isolate->callsite_function();
209 isolate->factory()->NewFixedArray(frame_count);
210 for (int i = 0; i < frame_count; ++i) {
212 isolate);
214 ASSIGN_RETURN_ON_EXCEPTION(isolate, site,
215 JSObject::New(constructor, constructor,
219 site, isolate->factory()->call_site_info_symbol(), frame,
220 DONT_ENUM));
221 sites->set(i, *site);
222 }
223
224 return isolate->factory()->NewJSArrayWithElements(sites);
225}
226
227MaybeDirectHandle<Object> AppendErrorString(Isolate* isolate,
228 DirectHandle<Object> error,
229 IncrementalStringBuilder* builder) {
230 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
231 try_catch.SetVerbose(false);
232 try_catch.SetCaptureMessage(false);
233 MaybeDirectHandle<String> err_str = ErrorUtils::ToString(
234 isolate, Cast<Object>(error),
236 if (err_str.is_null()) {
237 // Error.toString threw. Try to return a string representation of the thrown
238 // exception instead.
239
240 DCHECK(isolate->has_exception());
241 if (isolate->is_execution_terminating()) {
242 return {};
243 }
244 DirectHandle<Object> exception(isolate->exception(), isolate);
245 try_catch.Reset();
246
247 err_str = ErrorUtils::ToString(
248 isolate, exception,
250 if (err_str.is_null()) {
251 // Formatting the thrown exception threw again, give up.
252 DCHECK(isolate->has_exception());
253 if (isolate->is_execution_terminating()) return {};
254 builder->AppendCStringLiteral("<error>");
255 } else {
256 // Formatted thrown exception successfully, append it.
257 builder->AppendCStringLiteral("<error: ");
258 builder->AppendString(err_str.ToHandleChecked());
259 builder->AppendCharacter('>');
260 }
261 } else {
262 builder->AppendString(err_str.ToHandleChecked());
263 }
264
265 return error;
266}
267
268class V8_NODISCARD PrepareStackTraceScope {
269 public:
270 explicit PrepareStackTraceScope(Isolate* isolate) : isolate_(isolate) {
271 DCHECK(!isolate_->formatting_stack_trace());
272 isolate_->set_formatting_stack_trace(true);
273 }
274
275 ~PrepareStackTraceScope() { isolate_->set_formatting_stack_trace(false); }
276
277 PrepareStackTraceScope(const PrepareStackTraceScope&) = delete;
278 PrepareStackTraceScope& operator=(const PrepareStackTraceScope&) = delete;
279
280 private:
281 Isolate* isolate_;
282};
283
284} // namespace
285
286// static
288 Isolate* isolate, DirectHandle<JSObject> error,
289 DirectHandle<Object> raw_stack) {
290 if (v8_flags.correctness_fuzzer_suppressions) {
291 return isolate->factory()->empty_string();
292 }
293 DCHECK(IsFixedArray(*raw_stack));
294 auto elems = Cast<FixedArray>(raw_stack);
295
296 const bool in_recursion = isolate->formatting_stack_trace();
297 const bool has_overflowed = i::StackLimitCheck{isolate}.HasOverflowed();
298 DirectHandle<NativeContext> error_context;
299 if (!in_recursion && !has_overflowed &&
300 error->GetCreationContext(isolate).ToHandle(&error_context)) {
301 if (isolate->HasPrepareStackTraceCallback()) {
302 PrepareStackTraceScope scope(isolate);
303
305 ASSIGN_RETURN_ON_EXCEPTION(isolate, sites,
306 GetStackFrames(isolate, elems));
307
310 isolate, result,
311 isolate->RunPrepareStackTraceCallback(error_context, error, sites));
312 return result;
313 } else {
314 DirectHandle<JSFunction> global_error(error_context->error_function(),
315 isolate);
316
317 // If there's a user-specified "prepareStackTrace" function, call it on
318 // the frames and use its result.
319
320 DirectHandle<Object> prepare_stack_trace;
322 isolate, prepare_stack_trace,
323 JSFunction::GetProperty(isolate, global_error, "prepareStackTrace"));
324
325 if (IsJSFunction(*prepare_stack_trace)) {
326 PrepareStackTraceScope scope(isolate);
327
328 isolate->CountUsage(v8::Isolate::kErrorPrepareStackTrace);
329
331 ASSIGN_RETURN_ON_EXCEPTION(isolate, sites,
332 GetStackFrames(isolate, elems));
333
334 constexpr int argc = 2;
335 std::array<DirectHandle<Object>, argc> args;
336 if (V8_UNLIKELY(IsJSGlobalObject(*error))) {
337 // Pass global proxy instead of global object.
338 args[0] = direct_handle(Cast<JSGlobalObject>(*error)->global_proxy(),
339 isolate);
340 } else {
341 args[0] = error;
342 }
343 args[1] = sites;
344
346
348 isolate, result,
349 Execution::Call(isolate, prepare_stack_trace, global_error,
351 return result;
352 }
353 }
354 }
355
356 // Otherwise, run our internal formatting logic.
357 IncrementalStringBuilder builder(isolate);
358
359 RETURN_ON_EXCEPTION(isolate, AppendErrorString(isolate, error, &builder));
360
361 for (int i = 0; i < elems->length(); ++i) {
362 builder.AppendCStringLiteral("\n at ");
363
365 isolate);
366
367 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
368 SerializeCallSiteInfo(isolate, frame, &builder);
369
370 if (isolate->has_exception()) {
371 // CallSite.toString threw. Parts of the current frame might have been
372 // stringified already regardless. Still, try to append a string
373 // representation of the thrown exception.
374
375 DirectHandle<Object> exception(isolate->exception(), isolate);
376 try_catch.Reset();
377
378 MaybeDirectHandle<String> exception_string =
379 ErrorUtils::ToString(isolate, exception);
380 if (exception_string.is_null()) {
381 // Formatting the thrown exception threw again, give up.
382
383 builder.AppendCStringLiteral("<error>");
384 } else {
385 // Formatted thrown exception successfully, append it.
386 builder.AppendCStringLiteral("<error: ");
387 builder.AppendString(exception_string.ToHandleChecked());
388 builder.AppendCStringLiteral("<error>");
389 }
390 }
391 }
392
393 return builder.Finish();
394}
395
397 Isolate* isolate, MessageTemplate index,
399 constexpr size_t kMaxArgs = 3;
400 DirectHandle<String> arg_strings[kMaxArgs];
401 DCHECK_LE(args.size(), kMaxArgs);
402 for (size_t i = 0; i < args.size(); ++i) {
403 DCHECK(!args[i].is_null());
404 arg_strings[i] = Object::NoSideEffectsToString(isolate, args[i]);
405 }
406 v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
407 try_catch.SetVerbose(false);
408 try_catch.SetCaptureMessage(false);
410 isolate, index, base::VectorOf(arg_strings, args.size()));
411 Handle<String> result_string;
412 if (!maybe_result_string.ToHandle(&result_string)) {
413 DCHECK(isolate->has_exception());
414 return isolate->factory()->InternalizeString(
415 base::StaticCharVector("<error>"));
416 }
417 // A string that has been obtained from JS code in this way is
418 // likely to be a complicated ConsString of some sort. We flatten it
419 // here to improve the efficiency of converting it to a C string and
420 // other operations that are likely to take place (see GetLocalizedMessage
421 // for example).
422 return String::Flatten(isolate, result_string);
423}
424
426 switch (index) {
427#define CASE(NAME, STRING) \
428 case MessageTemplate::k##NAME: \
429 return STRING;
431#undef CASE
433 UNREACHABLE();
434 }
435 SBXCHECK(false);
436}
437
439 Isolate* isolate, MessageTemplate index,
441 const char* template_string = TemplateString(index);
442
443 IncrementalStringBuilder builder(isolate);
444
445 // TODO(14386): Get this list empty.
446 static constexpr MessageTemplate kTemplatesWithMismatchedArguments[] = {
447 MessageTemplate::kConstAssign,
448 MessageTemplate::kConstructorNotReceiver,
449 MessageTemplate::kDataCloneErrorDetachedArrayBuffer,
450 MessageTemplate::kDataCloneErrorOutOfMemory,
451 MessageTemplate::kIncompatibleMethodReceiver,
452 MessageTemplate::kInvalidArgument,
453 MessageTemplate::kInvalidArrayLength,
454 MessageTemplate::kInvalidAtomicAccessIndex,
455 MessageTemplate::kInvalidDataViewLength,
456 MessageTemplate::kInvalidIndex,
457 MessageTemplate::kInvalidLhsInAssignment,
458 MessageTemplate::kInvalidLhsInFor,
459 MessageTemplate::kInvalidLhsInPostfixOp,
460 MessageTemplate::kInvalidLhsInPrefixOp,
461 MessageTemplate::kInvalidPrivateBrandReinitialization,
462 MessageTemplate::kInvalidPrivateFieldReinitialization,
463 MessageTemplate::kInvalidPrivateMemberWrite,
464 MessageTemplate::kInvalidRegExpExecResult,
465 MessageTemplate::kInvalidTimeValue,
466 MessageTemplate::kInvalidWeakMapKey,
467 MessageTemplate::kInvalidWeakSetValue,
468 MessageTemplate::kIteratorReduceNoInitial,
469 MessageTemplate::kJsonParseShortString,
470 MessageTemplate::kJsonParseUnexpectedEOS,
471 MessageTemplate::kJsonParseUnexpectedTokenEndStringWithContext,
472 MessageTemplate::kJsonParseUnexpectedTokenShortString,
473 MessageTemplate::kJsonParseUnexpectedTokenStartStringWithContext,
474 MessageTemplate::kJsonParseUnexpectedTokenSurroundStringWithContext,
475 MessageTemplate::kMustBePositive,
476 MessageTemplate::kNotIterable,
477 MessageTemplate::kNotTypedArray,
478 MessageTemplate::kProxyNonObject,
479 MessageTemplate::kProxyPrivate,
480 MessageTemplate::kProxyRevoked,
481 MessageTemplate::kProxyTrapReturnedFalsishFor,
482 MessageTemplate::kReduceNoInitial,
483 MessageTemplate::kSpreadIteratorSymbolNonCallable,
484 MessageTemplate::kSymbolIteratorInvalid,
485 MessageTemplate::kTopLevelAwaitStalled,
486 MessageTemplate::kUndefinedOrNullToObject,
487 MessageTemplate::kUnexpectedStrictReserved,
488 MessageTemplate::kUnexpectedTokenIdentifier,
489 MessageTemplate::kWeakRefsCleanupMustBeCallable};
490
492 for (const char* c = template_string; *c != '\0'; c++) {
493 if (*c == '%') {
494 // %% results in verbatim %.
495 if (*(c + 1) == '%') {
496 c++;
497 builder.AppendCharacter('%');
498 } else {
499 // TODO(14386): Remove this fallback.
500 if (remaining_args.empty()) {
501 if (std::count(std::begin(kTemplatesWithMismatchedArguments),
502 std::end(kTemplatesWithMismatchedArguments), index)) {
503 builder.AppendCString("undefined");
504 } else {
505 FATAL("Missing argument to template (got %zu): %s", args.size(),
506 template_string);
507 }
508 } else {
509 DirectHandle<String> arg = remaining_args[0];
510 remaining_args += 1;
511 builder.AppendString(arg);
512 }
513 }
514 } else {
515 builder.AppendCharacter(*c);
516 }
517 }
518 if (!remaining_args.empty() &&
519 std::count(std::begin(kTemplatesWithMismatchedArguments),
520 std::end(kTemplatesWithMismatchedArguments), index) == 0) {
521 FATAL("Too many arguments to template (expected %zu, got %zu): %s",
522 args.size() - remaining_args.size(), args.size(), template_string);
523 }
524
525 return indirect_handle(builder.Finish(), isolate);
526}
527
529 Isolate* isolate, DirectHandle<JSFunction> target,
531 DirectHandle<Object> options) {
534
535 // When we're passed a JSFunction as new target, we can skip frames until that
536 // specific function is seen instead of unconditionally skipping the first
537 // frame.
538 if (IsJSFunction(*new_target)) {
539 mode = SKIP_UNTIL_SEEN;
540 caller = new_target;
541 }
542
543 return ErrorUtils::Construct(isolate, target, new_target, message, options,
544 mode, caller,
546}
547
549 Isolate* isolate, DirectHandle<JSFunction> target,
552 DirectHandle<Object> caller, StackTraceCollection stack_trace_collection) {
553 if (v8_flags.correctness_fuzzer_suppressions) {
554 // Abort range errors in correctness fuzzing, as their causes differ
555 // across correctness-fuzzing scenarios.
556 if (target.is_identical_to(isolate->range_error_function())) {
557 FATAL("Aborting on range error");
558 }
559 // Ignore error messages in correctness fuzzing, because the spec leaves
560 // room for undefined behavior.
561 message = isolate->factory()->InternalizeUtf8String(
562 "Message suppressed for fuzzers (--correctness-fuzzer-suppressions)");
563 }
564
565 // 1. If NewTarget is undefined, let newTarget be the active function object,
566 // else let newTarget be NewTarget.
567 DirectHandle<JSReceiver> new_target_recv = IsJSReceiver(*new_target)
569 : Cast<JSReceiver>(target);
570
571 // 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%ErrorPrototype%",
572 // « [[ErrorData]] »).
574 ASSIGN_RETURN_ON_EXCEPTION(isolate, err,
575 JSObject::New(target, new_target_recv, {}));
576
577 // 3. If message is not undefined, then
578 // a. Let msg be ? ToString(message).
579 // b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]:
580 // true, [[Enumerable]]: false, [[Configurable]]: true}.
581 // c. Perform ! DefinePropertyOrThrow(O, "message", msgDesc).
582 // 4. Return O.
583 if (!IsUndefined(*message, isolate)) {
584 DirectHandle<String> msg_string;
585 ASSIGN_RETURN_ON_EXCEPTION(isolate, msg_string,
586 Object::ToString(isolate, message));
588 err, isolate->factory()->message_string(),
589 msg_string, DONT_ENUM));
590
591 if (v8_flags.use_original_message_for_stack_trace) {
592 RETURN_ON_EXCEPTION(isolate,
594 err, isolate->factory()->error_message_symbol(),
595 msg_string, DONT_ENUM));
596 }
597 }
598
599 if (!IsUndefined(*options, isolate)) {
600 // If Type(options) is Object and ? HasProperty(options, "cause") then
601 // a. Let cause be ? Get(options, "cause").
602 // b. Perform ! CreateNonEnumerableDataPropertyOrThrow(O, "cause", cause).
603 DirectHandle<Name> cause_string = isolate->factory()->cause_string();
604 if (IsJSReceiver(*options)) {
605 DirectHandle<JSReceiver> js_options = Cast<JSReceiver>(options);
606 Maybe<bool> has_cause =
607 JSObject::HasProperty(isolate, js_options, cause_string);
608 if (has_cause.IsNothing()) {
609 DCHECK((isolate)->has_exception());
610 return MaybeHandle<JSObject>();
611 }
612 if (has_cause.ToChecked()) {
615 isolate, cause,
616 JSObject::GetProperty(isolate, js_options, cause_string));
618 err, cause_string, cause, DONT_ENUM));
619 }
620 }
621 }
622
623 switch (stack_trace_collection) {
625 RETURN_ON_EXCEPTION(isolate,
626 isolate->CaptureAndSetErrorStack(
627 err, mode, indirect_handle(caller, isolate)));
628 break;
630 break;
631 }
632 return err;
633}
634
635namespace {
636
637MaybeHandle<String> GetStringPropertyOrDefault(Isolate* isolate,
640 Handle<String> default_str) {
641 Handle<Object> obj;
642 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj,
643 JSObject::GetProperty(isolate, recv, key));
644
645 Handle<String> str;
646 if (IsUndefined(*obj, isolate)) {
647 str = default_str;
648 } else {
649 ASSIGN_RETURN_ON_EXCEPTION(isolate, str, Object::ToString(isolate, obj));
650 }
651
652 return str;
653}
654
655} // namespace
656
657// ES6 section 19.5.3.4 Error.prototype.toString ( )
660 ToStringMessageSource message_source) {
661 // 1. Let O be the this value.
662 // 2. If Type(O) is not Object, throw a TypeError exception.
664 if (!TryCast<JSReceiver>(receiver, &recv)) {
665 THROW_NEW_ERROR(isolate,
666 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
667 isolate->factory()->NewStringFromAsciiChecked(
668 "Error.prototype.toString"),
669 receiver));
670 }
671 // 3. Let name be ? Get(O, "name").
672 // 4. If name is undefined, let name be "Error"; otherwise let name be
673 // ? ToString(name).
674 DirectHandle<String> name_key = isolate->factory()->name_string();
675 Handle<String> name_default = isolate->factory()->Error_string();
678 isolate, name,
679 GetStringPropertyOrDefault(isolate, recv, name_key, name_default));
680
681 // 5. Let msg be ? Get(O, "message").
682 // 6. If msg is undefined, let msg be the empty String; otherwise let msg be
683 // ? ToString(msg).
684 Handle<String> msg;
685 Handle<String> msg_default = isolate->factory()->empty_string();
686 if (message_source == ToStringMessageSource::kPreferOriginalMessage) {
687 // V8-specific extension for Error.stack: Use the original message with
688 // which the Error constructor was called. This keeps Error.stack consistent
689 // w.r.t. "message" property changes regardless of the time when Error.stack
690 // is accessed the first time.
691 //
692 // If |recv| was not constructed with %Error%, use the "message" property.
694 recv, isolate->factory()->error_message_symbol());
696 if (it.IsFound() && IsUndefined(*result, isolate)) {
697 msg = msg_default;
698 } else if (it.IsFound()) {
699 ASSIGN_RETURN_ON_EXCEPTION(isolate, msg,
700 Object::ToString(isolate, result));
701 }
702 }
703
704 if (msg.is_null()) {
705 DirectHandle<String> msg_key = isolate->factory()->message_string();
707 isolate, msg,
708 GetStringPropertyOrDefault(isolate, recv, msg_key, msg_default));
709 }
710
711 // 7. If name is the empty String, return msg.
712 // 8. If msg is the empty String, return name.
713 if (name->length() == 0) return msg;
714 if (msg->length() == 0) return name;
715
716 // 9. Return the result of concatenating name, the code unit 0x003A (COLON),
717 // the code unit 0x0020 (SPACE), and msg.
718 IncrementalStringBuilder builder(isolate);
719 builder.AppendString(name);
720 builder.AppendCStringLiteral(": ");
721 builder.AppendString(msg);
722
725 indirect_handle(builder.Finish(), isolate));
726 return result;
727}
728
729// static
731 Isolate* isolate, DirectHandle<JSFunction> constructor,
733 FrameSkipMode mode) {
734 if (v8_flags.clear_exceptions_on_js_entry) {
735 // This function used to be implemented in JavaScript, and JSEntry
736 // clears any exceptions - so whenever we'd call this from C++,
737 // exceptions would be cleared. Preserve this behavior.
738 isolate->clear_exception();
739 isolate->clear_pending_message();
740 }
742 DirectHandle<Object> options = isolate->factory()->undefined_value();
743
744 DCHECK(mode != SKIP_UNTIL_SEEN);
745
746 DirectHandle<Object> no_caller;
747 // The call below can't fail because constructor is a builtin.
748 DCHECK(constructor->shared()->HasBuiltinId());
749 return ErrorUtils::Construct(isolate, constructor, constructor, msg, options,
750 mode, no_caller, StackTraceCollection::kEnabled)
751 .ToHandleChecked();
752}
753
754// static
756 Isolate* isolate, DirectHandle<Object> original, MessageTemplate index,
758 if (v8_flags.clear_exceptions_on_js_entry) {
759 // This function used to be implemented in JavaScript, and JSEntry
760 // clears any exceptions - so whenever we'd call this from C++,
761 // exceptions would be cleared. Preserve this behavior.
762 isolate->clear_exception();
763 isolate->clear_pending_message();
764 }
766 DirectHandle<Object> options = isolate->factory()->undefined_value();
767
768 DirectHandle<JSObject> maybe_error_object;
769 DirectHandle<Object> error_stack;
771 if (IsJSObject(*original)) {
772 maybe_error_object = Cast<JSObject>(original);
773 if (!ErrorUtils::GetFormattedStack(isolate, maybe_error_object)
774 .ToHandle(&error_stack)) {
775 DCHECK(isolate->has_exception());
776 DirectHandle<Object> exception =
777 direct_handle(isolate->exception(), isolate);
778 isolate->clear_exception();
779 // Return a new side-effect-free TypeError to be loud about inner error.
780 DirectHandle<String> string =
781 Object::NoSideEffectsToString(isolate, exception);
782 return isolate->factory()->NewTypeError(
783 MessageTemplate::kShadowRealmErrorStackThrows, string);
784 } else if (IsNullOrUndefined(*error_stack)) {
785 // If the error stack property is null or undefined, create a new error.
787 } else if (IsPrimitive(*error_stack)) {
788 // If the error stack property is found (must be a formatted string, not
789 // an unformatted FixedArray), set collection to disabled and reuse the
790 // existing stack. If the `Error.prepareStackTrace` returned a primitive,
791 // use it as the stack as well.
793 } else {
794 // The error stack property is an arbitrary value. Return a new TypeError
795 // about the non-string value.
796 DirectHandle<String> string =
797 Object::NoSideEffectsToString(isolate, error_stack);
798 return isolate->factory()->NewTypeError(
799 MessageTemplate::kShadowRealmErrorStackNonString, string);
800 }
801 }
802
803 DirectHandle<Object> no_caller;
804 DirectHandle<JSFunction> constructor = isolate->type_error_function();
805 DirectHandle<JSObject> new_error =
806 ErrorUtils::Construct(isolate, constructor, constructor, msg, options,
807 FrameSkipMode::SKIP_NONE, no_caller, collection)
808 .ToHandleChecked();
809
810 // If collection is disabled, reuse the existing stack string from the
811 // original error object.
812 if (collection == StackTraceCollection::kDisabled) {
813 // Error stack symbol is a private symbol and set it on an error object
814 // created from built-in error constructor should not throw.
816 isolate, new_error, isolate->factory()->error_stack_symbol(),
818 .Check();
819 }
820
821 return new_error;
822}
823
824namespace {
825
826bool ComputeLocation(Isolate* isolate, MessageLocation* target) {
828 if (!it.done()) {
829 // Compute the location from the function and the relocation info of the
830 // baseline code. For optimized code this will use the deoptimization
831 // information to get canonical location information.
832 FrameSummaries summaries = it.frame()->Summarize();
833 auto& summary = summaries.frames.back().AsJavaScript();
834 Handle<SharedFunctionInfo> shared(summary.function()->shared(), isolate);
835 Handle<Object> script(shared->script(), isolate);
837 int pos =
838 summary.abstract_code()->SourcePosition(isolate, summary.code_offset());
839 if (IsScript(*script) &&
840 !(IsUndefined(Cast<Script>(script)->source(), isolate))) {
841 Handle<Script> casted_script = Cast<Script>(script);
842 *target = MessageLocation(casted_script, pos, pos + 1, shared);
843 return true;
844 }
845 }
846 return false;
847}
848
849DirectHandle<String> BuildDefaultCallSite(Isolate* isolate,
850 DirectHandle<Object> object) {
851 IncrementalStringBuilder builder(isolate);
852
853 builder.AppendString(Object::TypeOf(isolate, object));
854 if (IsString(*object)) {
855 builder.AppendCStringLiteral(" \"");
856 DirectHandle<String> string = Cast<String>(object);
857 // This threshold must be sufficiently far below String::kMaxLength that
858 // the {builder}'s result can never exceed that limit.
859 constexpr int kMaxPrintedStringLength = 100;
860 if (string->length() <= kMaxPrintedStringLength) {
861 builder.AppendString(string);
862 } else {
863 string = isolate->factory()->NewProperSubString(string, 0,
864 kMaxPrintedStringLength);
865 builder.AppendString(string);
866 builder.AppendCStringLiteral("<...>");
867 }
868 builder.AppendCStringLiteral("\"");
869 } else if (IsNull(*object, isolate)) {
870 builder.AppendCStringLiteral(" null");
871 } else if (IsTrue(*object, isolate)) {
872 builder.AppendCStringLiteral(" true");
873 } else if (IsFalse(*object, isolate)) {
874 builder.AppendCStringLiteral(" false");
875 } else if (IsNumber(*object)) {
876 builder.AppendCharacter(' ');
877 builder.AppendString(isolate->factory()->NumberToString(object));
878 }
879
880 return builder.Finish().ToHandleChecked();
881}
882
883DirectHandle<String> RenderCallSite(Isolate* isolate,
884 DirectHandle<Object> object,
885 MessageLocation* location,
887 if (ComputeLocation(isolate, location)) {
888 UnoptimizedCompileFlags flags = UnoptimizedCompileFlags::ForFunctionCompile(
889 isolate, *location->shared());
890 flags.set_is_reparse(true);
891 UnoptimizedCompileState compile_state;
892 ReusableUnoptimizedCompileState reusable_state(isolate);
893 ParseInfo info(isolate, flags, &compile_state, &reusable_state);
894 if (parsing::ParseAny(&info, location->shared(), isolate,
896 info.ast_value_factory()->Internalize(isolate);
897 CallPrinter printer(isolate, location->shared()->IsUserJavaScript());
898 DirectHandle<String> str =
899 printer.Print(info.literal(), location->start_pos());
900 *hint = printer.GetErrorHint();
901 if (str->length() > 0) return str;
902 }
903 }
904 return BuildDefaultCallSite(isolate, object);
905}
906
907MessageTemplate UpdateErrorTemplate(CallPrinter::ErrorHint hint,
908 MessageTemplate default_id) {
909 switch (hint) {
911 return MessageTemplate::kNotIterable;
912
914 return MessageTemplate::kNotCallableOrIterable;
915
917 return MessageTemplate::kNotAsyncIterable;
918
920 return MessageTemplate::kNotCallableOrAsyncIterable;
921
923 return default_id;
924 }
925}
926
927} // namespace
928
930 Isolate* isolate, DirectHandle<Object> source) {
931 MessageLocation location;
933 DirectHandle<String> callsite =
934 RenderCallSite(isolate, source, &location, &hint);
935 MessageTemplate id = MessageTemplate::kNotIterableNoSymbolLoad;
936
937 if (hint == CallPrinter::ErrorHint::kNone) {
938 DirectHandle<Symbol> iterator_symbol =
939 isolate->factory()->iterator_symbol();
940 return isolate->factory()->NewTypeError(id, callsite, iterator_symbol);
941 }
942
943 id = UpdateErrorTemplate(hint, id);
944 return isolate->factory()->NewTypeError(id, callsite);
945}
946
949 DirectHandle<Object> object) {
950 MessageLocation location;
951 DirectHandle<String> callsite;
952 if (ComputeLocation(isolate, &location)) {
954 isolate, *location.shared());
955 flags.set_is_reparse(true);
956 UnoptimizedCompileState compile_state;
957 ReusableUnoptimizedCompileState reusable_state(isolate);
958 ParseInfo info(isolate, flags, &compile_state, &reusable_state);
959 if (parsing::ParseAny(&info, location.shared(), isolate,
961 info.ast_value_factory()->Internalize(isolate);
962 CallPrinter printer(isolate, location.shared()->IsUserJavaScript(),
965 printer.Print(info.literal(), location.start_pos());
966 callsite =
967 str->length() > 0 ? str : BuildDefaultCallSite(isolate, object);
968
969 if (printer.spread_arg() != nullptr) {
970 // Change the message location to point at the property name.
971 int pos = printer.spread_arg()->position();
972 location =
973 MessageLocation(location.script(), pos, pos + 1, location.shared());
974 }
975 } else {
976 callsite = BuildDefaultCallSite(isolate, object);
977 }
978 }
979
980 isolate->ThrowAt(isolate->factory()->NewTypeError(id, callsite, object),
981 &location);
982 return ReadOnlyRoots(isolate).exception();
983}
984
986 Isolate* isolate, DirectHandle<Object> source) {
987 MessageLocation location;
989 DirectHandle<String> callsite =
990 RenderCallSite(isolate, source, &location, &hint);
991 MessageTemplate id = MessageTemplate::kCalledNonCallable;
992 id = UpdateErrorTemplate(hint, id);
993 return isolate->factory()->NewTypeError(id, callsite);
994}
995
997 Isolate* isolate, DirectHandle<Object> source) {
998 MessageLocation location;
1000 DirectHandle<String> callsite =
1001 RenderCallSite(isolate, source, &location, &hint);
1002 MessageTemplate id = MessageTemplate::kNotConstructor;
1003 return isolate->factory()->NewTypeError(id, callsite);
1004}
1005
1007 Isolate* isolate, DirectHandle<Object> object,
1009 DCHECK(IsNullOrUndefined(*object));
1010
1011 MaybeDirectHandle<String> maybe_property_name;
1012
1013 // Try to extract the property name from the given key, if any.
1014 DirectHandle<Object> key_handle;
1015 if (key.ToHandle(&key_handle)) {
1016 if (IsString(*key_handle)) {
1017 maybe_property_name = Cast<String>(key_handle);
1018 } else {
1019 maybe_property_name =
1020 Object::NoSideEffectsToMaybeString(isolate, key_handle);
1021 }
1022 }
1023
1024 DirectHandle<String> callsite;
1025
1026 // Inline the RenderCallSite logic here so that we can additionally access the
1027 // destructuring property.
1028 bool location_computed = false;
1029 bool is_destructuring = false;
1030 MessageLocation location;
1031 if (ComputeLocation(isolate, &location)) {
1032 location_computed = true;
1033
1035 isolate, *location.shared());
1036 flags.set_is_reparse(true);
1037 UnoptimizedCompileState compile_state;
1038 ReusableUnoptimizedCompileState reusable_state(isolate);
1039 ParseInfo info(isolate, flags, &compile_state, &reusable_state);
1040 if (parsing::ParseAny(&info, location.shared(), isolate,
1042 info.ast_value_factory()->Internalize(isolate);
1043 CallPrinter printer(isolate, location.shared()->IsUserJavaScript());
1045 printer.Print(info.literal(), location.start_pos());
1046
1047 int pos = -1;
1048 is_destructuring = printer.destructuring_assignment() != nullptr;
1049
1050 if (is_destructuring) {
1051 // If we don't have one yet, try to extract the property name from the
1052 // destructuring property in the AST.
1053 ObjectLiteralProperty* destructuring_prop =
1054 printer.destructuring_prop();
1055 if (maybe_property_name.is_null() && destructuring_prop != nullptr &&
1056 destructuring_prop->key()->IsPropertyName()) {
1057 maybe_property_name = destructuring_prop->key()
1058 ->AsLiteral()
1059 ->AsRawPropertyName()
1060 ->string();
1061 // Change the message location to point at the property name.
1062 pos = destructuring_prop->key()->position();
1063 }
1064 if (maybe_property_name.is_null()) {
1065 // Change the message location to point at the destructured value.
1066 pos = printer.destructuring_assignment()->value()->position();
1067 }
1068
1069 // If we updated the pos to a valid pos, rewrite the location.
1070 if (pos != -1) {
1071 location = MessageLocation(location.script(), pos, pos + 1,
1072 location.shared());
1073 }
1074 }
1075
1076 if (str->length() > 0) callsite = str;
1077 }
1078 }
1079
1080 if (callsite.is_null()) {
1081 callsite = BuildDefaultCallSite(isolate, object);
1082 }
1083
1085 DirectHandle<String> property_name;
1086 if (is_destructuring) {
1087 if (maybe_property_name.ToHandle(&property_name)) {
1088 error = isolate->factory()->NewTypeError(
1089 MessageTemplate::kNonCoercibleWithProperty, property_name, callsite,
1090 object);
1091 } else {
1092 error = isolate->factory()->NewTypeError(MessageTemplate::kNonCoercible,
1093 callsite, object);
1094 }
1095 } else {
1096 if (!key.ToHandle(&key_handle) ||
1097 !maybe_property_name.ToHandle(&property_name)) {
1098 error = isolate->factory()->NewTypeError(
1099 MessageTemplate::kNonObjectPropertyLoad, object);
1100 } else if (*key_handle == ReadOnlyRoots(isolate).iterator_symbol()) {
1101 error = NewIteratorError(isolate, object);
1102 } else {
1103 error = isolate->factory()->NewTypeError(
1104 MessageTemplate::kNonObjectPropertyLoadWithProperty, object,
1105 property_name);
1106 }
1107 }
1108
1109 if (location_computed) {
1110 isolate->ThrowAt(error, &location);
1111 } else {
1112 isolate->Throw(*error);
1113 }
1114 return ReadOnlyRoots(isolate).exception();
1115}
1116
1117// static
1119 DirectHandle<JSObject> object) {
1120 // TODO(v8:5962): consider adding object->IsWasmExceptionPackage() here
1121 // once it's guaranteed that WasmExceptionPackage has |error_stack_symbol|
1122 // property.
1123 DirectHandle<Name> name = isolate->factory()->error_stack_symbol();
1124 if (IsJSError(*object)) {
1125 DCHECK(JSReceiver::HasOwnProperty(isolate, object, name).FromMaybe(false));
1126 return true;
1127 }
1128 return JSReceiver::HasOwnProperty(isolate, object, name).FromMaybe(false);
1129}
1130
1131// static
1133 Isolate* isolate, DirectHandle<JSReceiver> maybe_error_object) {
1135 maybe_error_object,
1136 isolate->factory()->error_stack_symbol());
1138
1139 if (!it.IsFound()) {
1141 isolate->factory()->undefined_value()};
1142 }
1143 return {it.GetHolder<JSObject>(), result};
1144}
1145
1146// static
1148 Isolate* isolate, DirectHandle<JSObject> maybe_error_object) {
1149 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.stack_trace"), __func__);
1150
1152 ErrorUtils::GetErrorStackProperty(isolate, maybe_error_object);
1153
1154 if (IsErrorStackData(*lookup.error_stack)) {
1155 auto error_stack_data = Cast<ErrorStackData>(lookup.error_stack);
1156 if (error_stack_data->HasFormattedStack()) {
1157 return direct_handle(error_stack_data->formatted_stack(), isolate);
1158 }
1159
1160 DirectHandle<JSObject> error_object =
1161 lookup.error_stack_symbol_holder.ToHandleChecked();
1162 DirectHandle<Object> formatted_stack;
1164 isolate, formatted_stack,
1166 isolate, error_object,
1167 direct_handle(error_stack_data->call_site_infos(), isolate)));
1168 error_stack_data->set_formatted_stack(*formatted_stack);
1169 return formatted_stack;
1170 }
1171
1172 if (IsFixedArray(*lookup.error_stack)) {
1173 DirectHandle<JSObject> error_object =
1174 lookup.error_stack_symbol_holder.ToHandleChecked();
1175 DirectHandle<Object> formatted_stack;
1177 isolate, formatted_stack,
1178 FormatStackTrace(isolate, error_object,
1179 Cast<FixedArray>(lookup.error_stack)));
1181 isolate, Object::SetProperty(isolate, error_object,
1182 isolate->factory()->error_stack_symbol(),
1183 formatted_stack, StoreOrigin::kMaybeKeyed,
1185 return formatted_stack;
1186 }
1187
1188 return lookup.error_stack;
1189}
1190
1191// static
1193 DirectHandle<JSObject> maybe_error_object,
1194 DirectHandle<Object> formatted_stack) {
1196 ErrorUtils::GetErrorStackProperty(isolate, maybe_error_object);
1197
1198 DirectHandle<JSObject> error_object;
1199 // Do nothing in case |maybe_error_object| is not an Error, i.e. its
1200 // prototype doesn't contain objects with |error_stack_symbol| property.
1201 if (!lookup.error_stack_symbol_holder.ToHandle(&error_object)) return;
1202
1203 if (IsErrorStackData(*lookup.error_stack)) {
1204 auto error_stack_data = Cast<ErrorStackData>(lookup.error_stack);
1205 error_stack_data->set_formatted_stack(*formatted_stack);
1206 } else {
1207 Object::SetProperty(isolate, error_object,
1208 isolate->factory()->error_stack_symbol(),
1209 formatted_stack, StoreOrigin::kMaybeKeyed,
1211 .Check();
1212 }
1213}
1214
1215// static
1218 FrameSkipMode mode,
1219 Handle<Object> caller) {
1220 Factory* factory = isolate->factory();
1221 Handle<Name> name = factory->stack_string();
1222
1223 // Explicitly check for frozen objects to simplify things since we need to
1224 // add both "stack" and "error_stack_symbol" properties in one go.
1225 if (!JSObject::IsExtensible(isolate, object)) {
1226 THROW_NEW_ERROR(isolate,
1227 NewTypeError(MessageTemplate::kDefineDisallowed, name));
1228 }
1229
1230 // Add the stack accessors.
1231 PropertyDescriptor desc;
1232 desc.set_enumerable(false);
1233 desc.set_configurable(true);
1234 desc.set_get(factory->error_stack_getter_fun_template());
1235 desc.set_set(factory->error_stack_setter_fun_template());
1237 isolate, object, name, &desc, Just(kThrowOnError));
1238
1239 MAYBE_RETURN(success, {});
1240
1241 // Collect the stack trace and store it in |object|'s private
1242 // "error_stack_symbol" property.
1243 RETURN_ON_EXCEPTION(isolate,
1244 isolate->CaptureAndSetErrorStack(object, mode, caller));
1245
1246 return isolate->factory()->undefined_value();
1247}
1248
1249} // namespace internal
1250} // namespace v8
Isolate * isolate_
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
#define SBXCHECK(condition)
Definition check.h:61
SourcePosition pos
@ kErrorPrepareStackTrace
Definition v8-isolate.h:513
V8_INLINE T ToChecked() const
Definition v8-maybe.h:41
V8_INLINE bool IsNothing() const
Definition v8-maybe.h:35
void SetVerbose(bool value)
Definition api.cc:2856
void Reset()
Definition api.cc:2839
void SetCaptureMessage(bool value)
Definition api.cc:2860
constexpr bool empty() const
Definition vector.h:73
constexpr size_t size() const
Definition vector.h:70
Expression * value() const
Definition ast.h:2171
int position() const
Definition ast.h:155
Expression * spread_arg() const
Assignment * destructuring_assignment() const
DirectHandle< String > Print(FunctionLiteral *program, int position)
ObjectLiteralProperty * destructuring_prop() const
V8_INLINE bool is_null() const
Definition handles.h:693
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
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Object > Call(Isolate *isolate, DirectHandle< Object > callable, DirectHandle< Object > receiver, base::Vector< const DirectHandle< Object > > args)
Definition execution.cc:523
bool IsPropertyName() const
Definition ast.cc:83
V8_INLINE bool is_null() const
Definition handles.h:69
V8_INLINE void AppendCString(const SrcChar *s)
MaybeDirectHandle< String > Finish()
V8_INLINE void AppendCharacter(uint8_t c)
V8_INLINE void AppendString(std::string_view str)
V8_INLINE void AppendCStringLiteral(const char(&literal)[N])
static bool IsExtensible(Isolate *isolate, DirectHandle< JSObject > object)
static V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT MaybeHandle< JSObject > New(DirectHandle< JSFunction > constructor, DirectHandle< JSReceiver > new_target, DirectHandle< AllocationSite > site, NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > V8_EXPORT_PRIVATE SetOwnPropertyIgnoreAttributes(DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyAttributes attributes)
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT Maybe< bool > HasOwnProperty(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Name > name)
static Handle< Object > GetDataProperty(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Name > name)
static V8_WARN_UNUSED_RESULT Maybe< bool > DefineOwnProperty(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Object > key, PropertyDescriptor *desc, Maybe< ShouldThrow > should_throw)
Expression * key() const
Definition ast.h:1247
V8_INLINE DirectHandle< T > ToHandleChecked() const
V8_WARN_UNUSED_RESULT V8_INLINE bool ToHandle(DirectHandle< S > *out) const
V8_INLINE bool is_null() const
V8_WARN_UNUSED_RESULT V8_INLINE bool ToHandle(Handle< S > *out) const
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< SharedFunctionInfo > shared() const
Definition messages.h:54
Handle< Script > script() const
Definition messages.h:50
static V8_EXPORT_PRIVATE DirectHandle< String > NoSideEffectsToString(Isolate *isolate, DirectHandle< Object > input)
Definition objects.cc:687
static V8_WARN_UNUSED_RESULT HandleType< String >::MaybeType ToString(Isolate *isolate, HandleType< T > input)
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT Maybe< bool > SetProperty(LookupIterator *it, DirectHandle< Object > value, StoreOrigin store_origin, Maybe< ShouldThrow > should_throw=Nothing< ShouldThrow >())
Definition objects.cc:2439
static Handle< String > TypeOf(Isolate *isolate, DirectHandle< Object > object)
Definition objects.cc:1001
static V8_EXPORT_PRIVATE MaybeDirectHandle< String > NoSideEffectsToMaybeString(Isolate *isolate, DirectHandle< Object > input)
Definition objects.cc:584
static void EnsureSourcePositionsAvailable(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared_info)
static constexpr int ToInt(const Tagged< Object > object)
Definition smi.h:33
SourcePosition(int script_offset=kNoSourcePosition, int inlining_id=kNotInlined)
static V8_INLINE HandleType< String > Flatten(Isolate *isolate, HandleType< T > string, AllocationType allocation=AllocationType::kYoung)
static UnoptimizedCompileFlags ForFunctionCompile(Isolate *isolate, Tagged< SharedFunctionInfo > shared)
Definition parse-info.cc:46
int start
Handle< SharedFunctionInfo > info
int end
Handle< Script > script_
Tagged< SharedFunctionInfo > shared_
Definition debug.cc:1741
#define RETURN_ON_EXCEPTION(isolate, call)
Definition isolate.h:395
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call)
Definition isolate.h:291
#define THROW_NEW_ERROR(isolate, call)
Definition isolate.h:307
#define MAYBE_RETURN(call, value)
Definition isolate.h:408
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
DirectHandle< Object > new_target
Definition execution.cc:75
TNode< Object > receiver
SharedFunctionInfoRef shared
TNode< Object > callback
ZoneVector< RpoNumber > & result
#define MESSAGE_TEMPLATES(T)
InstructionOperand source
constexpr Vector< const char > StaticCharVector(const char(&array)[N])
Definition vector.h:326
constexpr Vector< T > VectorOf(T *start, size_t size)
Definition vector.h:360
bool ParseAny(ParseInfo *info, DirectHandle< SharedFunctionInfo > shared_info, Isolate *isolate, ReportStatisticsMode mode)
Definition parsing.cc:98
bool TryCast(Tagged< From > value, Tagged< To > *out)
Definition casting.h:77
@ SKIP_UNTIL_SEEN
Definition messages.h:70
bool IsNumber(Tagged< Object > obj)
void PrintF(const char *format,...)
Definition utils.cc:39
V8_INLINE IndirectHandle< T > indirect_handle(DirectHandle< T > handle)
Definition handles.h:757
F FUNCTION_CAST(uint8_t *addr)
Definition globals.h:717
void SerializeCallSiteInfo(Isolate *isolate, DirectHandle< CallSiteInfo > frame, IncrementalStringBuilder *builder)
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
Definition flags.cc:2086
bool IsNullOrUndefined(Tagged< Object > obj, Isolate *isolate)
bool IsPrimitive(Tagged< Object > obj)
V8_EXPORT_PRIVATE FlagValues v8_flags
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset IsNull(value)||IsJSProxy(value)||IsWasmObject(value)||(IsJSObject(value) &&(HeapLayout
Definition map-inl.h:70
kInterpreterTrampolineOffset script
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
void(*)(Local< Message > message, Local< Value > data) MessageCallback
Maybe< T > Just(const T &t)
Definition v8-maybe.h:117
#define RCS_SCOPE(...)
#define FATAL(...)
Definition logging.h:47
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define DCHECK(condition)
Definition logging.h:482
MaybeDirectHandle< JSObject > error_stack_symbol_holder
Definition messages.h:135
std::vector< FrameSummary > frames
Definition frames.h:631
#define TRACE_EVENT0(category_group, name)
#define TRACE_DISABLED_BY_DEFAULT(name)
#define V8_UNLIKELY(condition)
Definition v8config.h:660
#define V8_NODISCARD
Definition v8config.h:693