| 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_RESULT_OR_FAILURE( |
| 20 // 1. If NewTarget is undefined, let newTarget be the active function object, | 21 isolate, |
| 21 // else let newTarget be NewTarget. | 22 ConstructError(isolate, args.target<JSFunction>(), |
| 22 | 23 Handle<Object>::cast(args.new_target()), |
| 23 Handle<JSFunction> target = args.target<JSFunction>(); | 24 args.atOrUndefined(isolate, 1), SKIP_FIRST, false)); |
| 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 } | 25 } |
| 67 | 26 |
| 68 // static | 27 // static |
| 69 BUILTIN(ErrorCaptureStackTrace) { | 28 BUILTIN(ErrorCaptureStackTrace) { |
| 70 HandleScope scope(isolate); | 29 HandleScope scope(isolate); |
| 71 Handle<Object> object_obj = args.atOrUndefined(isolate, 1); | 30 Handle<Object> object_obj = args.atOrUndefined(isolate, 1); |
| 72 if (!object_obj->IsJSObject()) { | 31 if (!object_obj->IsJSObject()) { |
| 73 THROW_NEW_ERROR_RETURN_FAILURE( | 32 THROW_NEW_ERROR_RETURN_FAILURE( |
| 74 isolate, NewTypeError(MessageTemplate::kInvalidArgument, object_obj)); | 33 isolate, NewTypeError(MessageTemplate::kInvalidArgument, object_obj)); |
| 75 } | 34 } |
| 76 Handle<JSObject> object = Handle<JSObject>::cast(object_obj); | 35 Handle<JSObject> object = Handle<JSObject>::cast(object_obj); |
| 77 Handle<Object> caller = args.atOrUndefined(isolate, 2); | 36 Handle<Object> caller = args.atOrUndefined(isolate, 2); |
| 37 FrameSkipMode mode = caller->IsJSFunction() ? SKIP_UNTIL_SEEN : SKIP_NONE; |
| 78 | 38 |
| 79 // TODO(jgruber): Eagerly format the stack trace and remove accessors.h | 39 // TODO(jgruber): Eagerly format the stack trace and remove accessors.h |
| 80 // include. | 40 // include. |
| 81 | 41 |
| 82 // Handle writes to the global object. | 42 // Handle writes to the global object. |
| 83 | 43 |
| 84 if (object->IsJSGlobalProxy()) { | 44 if (object->IsJSGlobalProxy()) { |
| 85 Map* map = object->map(); | 45 Map* map = object->map(); |
| 86 if (map->has_hidden_prototype()) { | 46 if (map->has_hidden_prototype()) { |
| 87 object = handle(JSGlobalObject::cast(map->prototype()), isolate); | 47 object = handle(JSGlobalObject::cast(map->prototype()), isolate); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 Map::CopyInsertDescriptor(map, &d, INSERT_TRANSITION); | 89 Map::CopyInsertDescriptor(map, &d, INSERT_TRANSITION); |
| 130 JSObject::MigrateToMap(object, new_map, 1); | 90 JSObject::MigrateToMap(object, new_map, 1); |
| 131 } | 91 } |
| 132 } | 92 } |
| 133 | 93 |
| 134 // Collect the stack trace. | 94 // Collect the stack trace. |
| 135 | 95 |
| 136 RETURN_FAILURE_ON_EXCEPTION(isolate, | 96 RETURN_FAILURE_ON_EXCEPTION(isolate, |
| 137 isolate->CaptureAndSetDetailedStackTrace(object)); | 97 isolate->CaptureAndSetDetailedStackTrace(object)); |
| 138 RETURN_FAILURE_ON_EXCEPTION( | 98 RETURN_FAILURE_ON_EXCEPTION( |
| 139 isolate, isolate->CaptureAndSetSimpleStackTrace(object, caller)); | 99 isolate, isolate->CaptureAndSetSimpleStackTrace(object, mode, caller)); |
| 140 | 100 |
| 141 return *isolate->factory()->undefined_value(); | 101 return *isolate->factory()->undefined_value(); |
| 142 } | 102 } |
| 143 | 103 |
| 144 namespace { | 104 namespace { |
| 145 | 105 |
| 146 MaybeHandle<String> GetStringPropertyOrDefault(Isolate* isolate, | 106 MaybeHandle<String> GetStringPropertyOrDefault(Isolate* isolate, |
| 147 Handle<JSReceiver> recv, | 107 Handle<JSReceiver> recv, |
| 148 Handle<String> key, | 108 Handle<String> key, |
| 149 Handle<String> default_str) { | 109 Handle<String> default_str) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // the code unit 0x0020 (SPACE), and msg. | 161 // the code unit 0x0020 (SPACE), and msg. |
| 202 IncrementalStringBuilder builder(isolate); | 162 IncrementalStringBuilder builder(isolate); |
| 203 builder.AppendString(name); | 163 builder.AppendString(name); |
| 204 builder.AppendCString(": "); | 164 builder.AppendCString(": "); |
| 205 builder.AppendString(msg); | 165 builder.AppendString(msg); |
| 206 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); | 166 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); |
| 207 } | 167 } |
| 208 | 168 |
| 209 } // namespace internal | 169 } // namespace internal |
| 210 } // namespace v8 | 170 } // namespace v8 |
| OLD | NEW |