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/accessors.h" | 8 #include "src/accessors.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/messages.h" |
10 #include "src/property-descriptor.h" | 11 #include "src/property-descriptor.h" |
11 #include "src/string-builder.h" | 12 #include "src/string-builder.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 | 16 |
16 // ES6 section 19.5.1.1 Error ( message ) | 17 // ES6 section 19.5.1.1 Error ( message ) |
17 BUILTIN(ErrorConstructor) { | 18 BUILTIN(ErrorConstructor) { |
18 HandleScope scope(isolate); | 19 HandleScope scope(isolate); |
19 | 20 return ConstructError(isolate, args.target<JSFunction>(), |
20 // 1. If NewTarget is undefined, let newTarget be the active function object, | 21 Handle<Object>::cast(args.new_target()), |
21 // else let newTarget be NewTarget. | 22 args.atOrUndefined(isolate, 1)); |
22 | |
23 Handle<JSFunction> target = args.target<JSFunction>(); | |
24 Handle<JSReceiver> new_target; | |
25 if (args.new_target()->IsJSReceiver()) { | |
26 new_target = Handle<JSReceiver>::cast(args.new_target()); | |
27 } else { | |
28 new_target = target; | |
29 } | |
30 | |
31 // 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%ErrorPrototype%", | |
32 // « [[ErrorData]] »). | |
33 Handle<JSObject> err; | |
34 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, err, | |
35 JSObject::New(target, new_target)); | |
36 | |
37 // 3. If message is not undefined, then | |
38 // a. Let msg be ? ToString(message). | |
39 // b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: | |
40 // true, [[Enumerable]]: false, [[Configurable]]: true}. | |
41 // c. Perform ! DefinePropertyOrThrow(O, "message", msgDesc). | |
42 // 4. Return O. | |
43 | |
44 Handle<Object> msg = args.atOrUndefined(isolate, 1); | |
45 if (!msg->IsUndefined(isolate)) { | |
46 Handle<String> msg_string; | |
47 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, msg_string, | |
48 Object::ToString(isolate, msg)); | |
49 RETURN_FAILURE_ON_EXCEPTION( | |
50 isolate, | |
51 JSObject::SetOwnPropertyIgnoreAttributes( | |
52 err, isolate->factory()->message_string(), msg_string, DONT_ENUM)); | |
53 } | |
54 | |
55 // Capture the stack trace unless we're setting up. | |
56 if (!isolate->bootstrapper()->IsActive()) { | |
57 // Optionally capture a more detailed stack trace for the message. | |
58 RETURN_FAILURE_ON_EXCEPTION(isolate, | |
59 isolate->CaptureAndSetDetailedStackTrace(err)); | |
60 // Capture a simple stack trace for the stack property. | |
61 RETURN_FAILURE_ON_EXCEPTION(isolate, | |
62 isolate->CaptureAndSetSimpleStackTrace(err)); | |
63 } | |
64 | |
65 return *err; | |
66 } | 23 } |
67 | 24 |
68 // static | 25 // static |
69 BUILTIN(ErrorCaptureStackTrace) { | 26 BUILTIN(ErrorCaptureStackTrace) { |
70 HandleScope scope(isolate); | 27 HandleScope scope(isolate); |
71 Handle<Object> object_obj = args.atOrUndefined(isolate, 1); | 28 Handle<Object> object_obj = args.atOrUndefined(isolate, 1); |
72 if (!object_obj->IsJSObject()) { | 29 if (!object_obj->IsJSObject()) { |
73 THROW_NEW_ERROR_RETURN_FAILURE( | 30 THROW_NEW_ERROR_RETURN_FAILURE( |
74 isolate, NewTypeError(MessageTemplate::kInvalidArgument, object_obj)); | 31 isolate, NewTypeError(MessageTemplate::kInvalidArgument, object_obj)); |
75 } | 32 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // the code unit 0x0020 (SPACE), and msg. | 150 // the code unit 0x0020 (SPACE), and msg. |
194 IncrementalStringBuilder builder(isolate); | 151 IncrementalStringBuilder builder(isolate); |
195 builder.AppendString(name); | 152 builder.AppendString(name); |
196 builder.AppendCString(": "); | 153 builder.AppendCString(": "); |
197 builder.AppendString(msg); | 154 builder.AppendString(msg); |
198 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); | 155 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); |
199 } | 156 } |
200 | 157 |
201 } // namespace internal | 158 } // namespace internal |
202 } // namespace v8 | 159 } // namespace v8 |
OLD | NEW |