v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
builtins-error.cc
Go to the documentation of this file.
1// Copyright 2016 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
14
15namespace v8 {
16namespace internal {
17
18// ES6 section 19.5.1.1 Error ( message )
19BUILTIN(ErrorConstructor) {
20 HandleScope scope(isolate);
21 DirectHandle<Object> options = args.atOrUndefined(isolate, 2);
23 isolate, ErrorUtils::Construct(isolate, args.target(), args.new_target(),
24 args.atOrUndefined(isolate, 1), options));
25}
26
27// static
28BUILTIN(ErrorCaptureStackTrace) {
29 HandleScope scope(isolate);
30 Handle<Object> object_obj = args.atOrUndefined(isolate, 1);
31
32 isolate->CountUsage(v8::Isolate::kErrorCaptureStackTrace);
33
34 if (!IsJSObject(*object_obj)) {
36 isolate, NewTypeError(MessageTemplate::kInvalidArgument, object_obj));
37 }
38
39 DirectHandle<JSObject> object = Cast<JSObject>(object_obj);
40 Handle<Object> caller = args.atOrUndefined(isolate, 2);
41 FrameSkipMode mode = IsJSFunction(*caller) ? SKIP_UNTIL_SEEN : SKIP_FIRST;
42
43 // Collect the stack trace and install the stack accessors.
45 isolate, ErrorUtils::CaptureStackTrace(isolate, object, mode, caller));
46 return ReadOnlyRoots(isolate).undefined_value();
47}
48
49// ES6 section 19.5.3.4 Error.prototype.toString ( )
50BUILTIN(ErrorPrototypeToString) {
51 HandleScope scope(isolate);
53 ErrorUtils::ToString(isolate, args.receiver()));
54}
55
56// https://tc39.es/proposal-is-error/
57BUILTIN(ErrorIsError) {
58 HandleScope scope(isolate);
59 DirectHandle<Object> obj = args.atOrUndefined(isolate, 1);
60
61 isolate->CountUsage(v8::Isolate::kErrorIsError);
62
63 // 1. If argument is not an Object, return false.
64 // 2. If argument has an [[ErrorData]] internal slot, return true.
65 // 3. Return false.
66
67 if (IsHeapObject(*obj)) {
68 Tagged<Map> obj_map = Cast<HeapObject>(*obj)->map();
69 // DOMExceptions should return true. See
70 // https://github.com/whatwg/webidl/pull/1421
71 return *isolate->factory()->ToBoolean(
72 InstanceTypeChecker::IsJSError(obj_map) ||
73 (IsJSApiWrapperObject(obj_map) &&
74 isolate->IsJSApiWrapperNativeError(Cast<JSReceiver>(obj))));
75 } else {
76 return ReadOnlyRoots(isolate).false_value();
77 }
78}
79
80} // namespace internal
81} // namespace v8
#define BUILTIN(name)
@ kErrorCaptureStackTrace
Definition v8-isolate.h:512
static V8_EXPORT_PRIVATE MaybeHandle< String > ToString(Isolate *isolate, DirectHandle< Object > recv, ToStringMessageSource message_source=ToStringMessageSource::kCurrentMessageProperty)
Definition messages.cc:658
static MaybeDirectHandle< JSObject > Construct(Isolate *isolate, DirectHandle< JSFunction > target, DirectHandle< Object > new_target, DirectHandle< Object > message, DirectHandle< Object > options)
Definition messages.cc:528
static MaybeHandle< Object > CaptureStackTrace(Isolate *isolate, DirectHandle< JSObject > object, FrameSkipMode mode, Handle< Object > caller)
Definition messages.cc:1216
#define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call)
Definition isolate.h:294
#define RETURN_FAILURE_ON_EXCEPTION(isolate, call)
Definition isolate.h:368
#define RETURN_RESULT_OR_FAILURE(isolate, call)
Definition isolate.h:264
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
@ SKIP_UNTIL_SEEN
Definition messages.h:70
V8_INLINE constexpr bool IsHeapObject(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:669
bool IsJSApiWrapperObject(Tagged< Map > map)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150