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