Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: src/builtins/builtins-error.cc

Issue 2169563003: Revert of Remove stack overflow boilerplate (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/contexts.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "src/property-descriptor.h" 10 #include "src/property-descriptor.h"
12 #include "src/string-builder.h" 11 #include "src/string-builder.h"
13 12
14 namespace v8 { 13 namespace v8 {
15 namespace internal { 14 namespace internal {
16 15
17 // ES6 section 19.5.1.1 Error ( message ) 16 // ES6 section 19.5.1.1 Error ( message )
18 BUILTIN(ErrorConstructor) { 17 BUILTIN(ErrorConstructor) {
19 HandleScope scope(isolate); 18 HandleScope scope(isolate);
20 RETURN_RESULT_OR_FAILURE( 19
21 isolate, 20 // 1. If NewTarget is undefined, let newTarget be the active function object,
22 ConstructError(isolate, args.target<JSFunction>(), 21 // else let newTarget be NewTarget.
23 Handle<Object>::cast(args.new_target()), 22
24 args.atOrUndefined(isolate, 1), SKIP_FIRST, false)); 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;
25 } 66 }
26 67
27 // static 68 // static
28 BUILTIN(ErrorCaptureStackTrace) { 69 BUILTIN(ErrorCaptureStackTrace) {
29 HandleScope scope(isolate); 70 HandleScope scope(isolate);
30 Handle<Object> object_obj = args.atOrUndefined(isolate, 1); 71 Handle<Object> object_obj = args.atOrUndefined(isolate, 1);
31 if (!object_obj->IsJSObject()) { 72 if (!object_obj->IsJSObject()) {
32 THROW_NEW_ERROR_RETURN_FAILURE( 73 THROW_NEW_ERROR_RETURN_FAILURE(
33 isolate, NewTypeError(MessageTemplate::kInvalidArgument, object_obj)); 74 isolate, NewTypeError(MessageTemplate::kInvalidArgument, object_obj));
34 } 75 }
35 Handle<JSObject> object = Handle<JSObject>::cast(object_obj); 76 Handle<JSObject> object = Handle<JSObject>::cast(object_obj);
36 Handle<Object> caller = args.atOrUndefined(isolate, 2); 77 Handle<Object> caller = args.atOrUndefined(isolate, 2);
37 FrameSkipMode mode = caller->IsJSFunction() ? SKIP_UNTIL_SEEN : SKIP_NONE;
38 78
39 // TODO(jgruber): Eagerly format the stack trace and remove accessors.h 79 // TODO(jgruber): Eagerly format the stack trace and remove accessors.h
40 // include. 80 // include.
41 81
42 // Handle writes to the global object. 82 // Handle writes to the global object.
43 83
44 if (object->IsJSGlobalProxy()) { 84 if (object->IsJSGlobalProxy()) {
45 Map* map = object->map(); 85 Map* map = object->map();
46 if (map->has_hidden_prototype()) { 86 if (map->has_hidden_prototype()) {
47 object = handle(JSGlobalObject::cast(map->prototype()), isolate); 87 object = handle(JSGlobalObject::cast(map->prototype()), isolate);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 Map::CopyInsertDescriptor(map, &d, INSERT_TRANSITION); 129 Map::CopyInsertDescriptor(map, &d, INSERT_TRANSITION);
90 JSObject::MigrateToMap(object, new_map, 1); 130 JSObject::MigrateToMap(object, new_map, 1);
91 } 131 }
92 } 132 }
93 133
94 // Collect the stack trace. 134 // Collect the stack trace.
95 135
96 RETURN_FAILURE_ON_EXCEPTION(isolate, 136 RETURN_FAILURE_ON_EXCEPTION(isolate,
97 isolate->CaptureAndSetDetailedStackTrace(object)); 137 isolate->CaptureAndSetDetailedStackTrace(object));
98 RETURN_FAILURE_ON_EXCEPTION( 138 RETURN_FAILURE_ON_EXCEPTION(
99 isolate, isolate->CaptureAndSetSimpleStackTrace(object, mode, caller)); 139 isolate, isolate->CaptureAndSetSimpleStackTrace(object, caller));
100 140
101 return *isolate->factory()->undefined_value(); 141 return *isolate->factory()->undefined_value();
102 } 142 }
103 143
104 namespace { 144 namespace {
105 145
106 MaybeHandle<String> GetStringPropertyOrDefault(Isolate* isolate, 146 MaybeHandle<String> GetStringPropertyOrDefault(Isolate* isolate,
107 Handle<JSReceiver> recv, 147 Handle<JSReceiver> recv,
108 Handle<String> key, 148 Handle<String> key,
109 Handle<String> default_str) { 149 Handle<String> default_str) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // the code unit 0x0020 (SPACE), and msg. 201 // the code unit 0x0020 (SPACE), and msg.
162 IncrementalStringBuilder builder(isolate); 202 IncrementalStringBuilder builder(isolate);
163 builder.AppendString(name); 203 builder.AppendString(name);
164 builder.AppendCString(": "); 204 builder.AppendCString(": ");
165 builder.AppendString(msg); 205 builder.AppendString(msg);
166 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); 206 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish());
167 } 207 }
168 208
169 } // namespace internal 209 } // namespace internal
170 } // namespace v8 210 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698