OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
6 #include "src/builtins/builtins-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
7 | 7 |
8 #include "src/messages.h" | 8 #include "src/messages.h" |
9 #include "src/property-descriptor.h" | 9 #include "src/property-descriptor.h" |
10 #include "src/string-builder.h" | 10 #include "src/string-builder.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 // ES6 section 19.5.1.1 Error ( message ) | 15 // ES6 section 19.5.1.1 Error ( message ) |
16 BUILTIN(ErrorConstructor) { | 16 BUILTIN(ErrorConstructor) { |
17 HandleScope scope(isolate); | 17 HandleScope scope(isolate); |
| 18 |
| 19 FrameSkipMode mode = SKIP_FIRST; |
| 20 Handle<Object> caller; |
| 21 |
| 22 // When we're passed a JSFunction as new target, we can skip frames until that |
| 23 // specific function is seen instead of unconditionally skipping the first |
| 24 // frame. |
| 25 if (args.new_target()->IsJSFunction()) { |
| 26 mode = SKIP_UNTIL_SEEN; |
| 27 caller = args.new_target(); |
| 28 } |
| 29 |
18 RETURN_RESULT_OR_FAILURE( | 30 RETURN_RESULT_OR_FAILURE( |
19 isolate, | 31 isolate, ErrorUtils::Construct(isolate, args.target<JSFunction>(), |
20 ErrorUtils::Construct(isolate, args.target<JSFunction>(), | 32 Handle<Object>::cast(args.new_target()), |
21 Handle<Object>::cast(args.new_target()), | 33 args.atOrUndefined(isolate, 1), mode, |
22 args.atOrUndefined(isolate, 1), SKIP_FIRST, false)); | 34 caller, false)); |
23 } | 35 } |
24 | 36 |
25 // static | 37 // static |
26 BUILTIN(ErrorCaptureStackTrace) { | 38 BUILTIN(ErrorCaptureStackTrace) { |
27 HandleScope scope(isolate); | 39 HandleScope scope(isolate); |
28 Handle<Object> object_obj = args.atOrUndefined(isolate, 1); | 40 Handle<Object> object_obj = args.atOrUndefined(isolate, 1); |
29 if (!object_obj->IsJSObject()) { | 41 if (!object_obj->IsJSObject()) { |
30 THROW_NEW_ERROR_RETURN_FAILURE( | 42 THROW_NEW_ERROR_RETURN_FAILURE( |
31 isolate, NewTypeError(MessageTemplate::kInvalidArgument, object_obj)); | 43 isolate, NewTypeError(MessageTemplate::kInvalidArgument, object_obj)); |
32 } | 44 } |
(...skipping 29 matching lines...) Expand all Loading... |
62 return isolate->heap()->undefined_value(); | 74 return isolate->heap()->undefined_value(); |
63 } | 75 } |
64 | 76 |
65 // ES6 section 19.5.3.4 Error.prototype.toString ( ) | 77 // ES6 section 19.5.3.4 Error.prototype.toString ( ) |
66 BUILTIN(ErrorPrototypeToString) { | 78 BUILTIN(ErrorPrototypeToString) { |
67 HandleScope scope(isolate); | 79 HandleScope scope(isolate); |
68 RETURN_RESULT_OR_FAILURE(isolate, | 80 RETURN_RESULT_OR_FAILURE(isolate, |
69 ErrorUtils::ToString(isolate, args.receiver())); | 81 ErrorUtils::ToString(isolate, args.receiver())); |
70 } | 82 } |
71 | 83 |
| 84 BUILTIN(MakeGenericError) { |
| 85 HandleScope scope(isolate); |
| 86 |
| 87 Handle<Object> constructor = args.atOrUndefined(isolate, 1); |
| 88 Handle<Object> template_index = args.atOrUndefined(isolate, 2); |
| 89 Handle<Object> arg0 = args.atOrUndefined(isolate, 3); |
| 90 Handle<Object> arg1 = args.atOrUndefined(isolate, 4); |
| 91 Handle<Object> arg2 = args.atOrUndefined(isolate, 5); |
| 92 |
| 93 DCHECK(constructor->IsJSFunction()); |
| 94 DCHECK(template_index->IsSmi()); |
| 95 |
| 96 RETURN_RESULT_OR_FAILURE( |
| 97 isolate, |
| 98 ErrorUtils::MakeGenericError( |
| 99 isolate, Handle<JSFunction>::cast(constructor), |
| 100 Smi::cast(*template_index)->value(), arg0, arg1, arg2, SKIP_FIRST)); |
| 101 } |
| 102 |
72 } // namespace internal | 103 } // namespace internal |
73 } // namespace v8 | 104 } // namespace v8 |
OLD | NEW |