| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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/messages.h" | 5 #include "src/messages.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/bootstrapper.h" | |
| 9 #include "src/execution.h" | 8 #include "src/execution.h" |
| 10 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
| 11 #include "src/keys.h" | 10 #include "src/keys.h" |
| 12 #include "src/string-builder.h" | 11 #include "src/string-builder.h" |
| 13 #include "src/wasm/wasm-module.h" | 12 #include "src/wasm/wasm-module.h" |
| 14 | 13 |
| 15 namespace v8 { | 14 namespace v8 { |
| 16 namespace internal { | 15 namespace internal { |
| 17 | 16 |
| 18 MessageLocation::MessageLocation(Handle<Script> script, int start_pos, | 17 MessageLocation::MessageLocation(Handle<Script> script, int start_pos, |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 builder.AppendString(arg); | 440 builder.AppendString(arg); |
| 442 } | 441 } |
| 443 } else { | 442 } else { |
| 444 builder.AppendCharacter(*c); | 443 builder.AppendCharacter(*c); |
| 445 } | 444 } |
| 446 } | 445 } |
| 447 | 446 |
| 448 return builder.Finish(); | 447 return builder.Finish(); |
| 449 } | 448 } |
| 450 | 449 |
| 451 MaybeHandle<Object> ConstructError(Isolate* isolate, Handle<JSFunction> target, | |
| 452 Handle<Object> new_target, | |
| 453 Handle<Object> message, FrameSkipMode mode, | |
| 454 bool suppress_detailed_trace) { | |
| 455 // 1. If NewTarget is undefined, let newTarget be the active function object, | |
| 456 // else let newTarget be NewTarget. | |
| 457 | |
| 458 Handle<JSReceiver> new_target_recv = | |
| 459 new_target->IsJSReceiver() ? Handle<JSReceiver>::cast(new_target) | |
| 460 : Handle<JSReceiver>::cast(target); | |
| 461 | |
| 462 // 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%ErrorPrototype%", | |
| 463 // « [[ErrorData]] »). | |
| 464 Handle<JSObject> err; | |
| 465 ASSIGN_RETURN_ON_EXCEPTION(isolate, err, | |
| 466 JSObject::New(target, new_target_recv), Object); | |
| 467 | |
| 468 // 3. If message is not undefined, then | |
| 469 // a. Let msg be ? ToString(message). | |
| 470 // b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: | |
| 471 // true, [[Enumerable]]: false, [[Configurable]]: true}. | |
| 472 // c. Perform ! DefinePropertyOrThrow(O, "message", msgDesc). | |
| 473 // 4. Return O. | |
| 474 | |
| 475 if (!message->IsUndefined(isolate)) { | |
| 476 Handle<String> msg_string; | |
| 477 ASSIGN_RETURN_ON_EXCEPTION(isolate, msg_string, | |
| 478 Object::ToString(isolate, message), Object); | |
| 479 RETURN_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( | |
| 480 err, isolate->factory()->message_string(), | |
| 481 msg_string, DONT_ENUM), | |
| 482 Object); | |
| 483 } | |
| 484 | |
| 485 // Optionally capture a more detailed stack trace for the message. | |
| 486 if (!suppress_detailed_trace) { | |
| 487 RETURN_ON_EXCEPTION(isolate, isolate->CaptureAndSetDetailedStackTrace(err), | |
| 488 Object); | |
| 489 } | |
| 490 // Capture a simple stack trace for the stack property. | |
| 491 RETURN_ON_EXCEPTION(isolate, isolate->CaptureAndSetSimpleStackTrace( | |
| 492 err, mode, Handle<Object>()), | |
| 493 Object); | |
| 494 | |
| 495 return err; | |
| 496 } | |
| 497 | 450 |
| 498 } // namespace internal | 451 } // namespace internal |
| 499 } // namespace v8 | 452 } // namespace v8 |
| OLD | NEW |