OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/pending-compilation-error-handler.h" | 5 #include "src/pending-compilation-error-handler.h" |
6 | 6 |
7 #include "src/debug.h" | 7 #include "src/debug.h" |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 void PendingCompilationErrorHandler::ThrowPendingError(Isolate* isolate, | 15 void PendingCompilationErrorHandler::ThrowPendingError(Isolate* isolate, |
16 Handle<Script> script) { | 16 Handle<Script> script) { |
17 if (!has_pending_error_) return; | 17 if (!has_pending_error_) return; |
18 MessageLocation location(script, start_position_, end_position_); | 18 MessageLocation location(script, start_position_, end_position_); |
19 Factory* factory = isolate->factory(); | 19 Factory* factory = isolate->factory(); |
20 bool has_arg = arg_ != NULL || char_arg_ != NULL || !handle_arg_.is_null(); | 20 Handle<String> argument; |
21 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); | |
22 if (arg_ != NULL) { | 21 if (arg_ != NULL) { |
23 Handle<String> arg_string = arg_->string(); | 22 argument = arg_->string(); |
24 elements->set(0, *arg_string); | |
25 } else if (char_arg_ != NULL) { | 23 } else if (char_arg_ != NULL) { |
26 Handle<String> arg_string = | 24 argument = |
27 factory->NewStringFromUtf8(CStrVector(char_arg_)).ToHandleChecked(); | 25 factory->NewStringFromUtf8(CStrVector(char_arg_)).ToHandleChecked(); |
28 elements->set(0, *arg_string); | |
29 } else if (!handle_arg_.is_null()) { | 26 } else if (!handle_arg_.is_null()) { |
30 elements->set(0, *handle_arg_); | 27 argument = handle_arg_; |
31 } | 28 } |
32 isolate->debug()->OnCompileError(script); | 29 isolate->debug()->OnCompileError(script); |
33 | 30 |
34 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | |
35 Handle<Object> error; | 31 Handle<Object> error; |
36 | |
37 switch (error_type_) { | 32 switch (error_type_) { |
38 case kReferenceError: | 33 case kReferenceError: |
39 error = factory->NewError("MakeReferenceError", message_, array); | 34 error = factory->NewError("MakeReferenceError", message_, argument); |
40 break; | 35 break; |
41 case kSyntaxError: | 36 case kSyntaxError: |
42 error = factory->NewError("MakeSyntaxError", message_, array); | 37 error = factory->NewError("MakeSyntaxError", message_, argument); |
| 38 break; |
| 39 default: |
| 40 UNREACHABLE(); |
43 break; | 41 break; |
44 } | 42 } |
45 | 43 |
46 Handle<JSObject> jserror = Handle<JSObject>::cast(error); | 44 Handle<JSObject> jserror = Handle<JSObject>::cast(error); |
47 | 45 |
48 Handle<Name> key_start_pos = factory->error_start_pos_symbol(); | 46 Handle<Name> key_start_pos = factory->error_start_pos_symbol(); |
49 JSObject::SetProperty(jserror, key_start_pos, | 47 JSObject::SetProperty(jserror, key_start_pos, |
50 handle(Smi::FromInt(location.start_pos()), isolate), | 48 handle(Smi::FromInt(location.start_pos()), isolate), |
51 SLOPPY).Check(); | 49 SLOPPY).Check(); |
52 | 50 |
53 Handle<Name> key_end_pos = factory->error_end_pos_symbol(); | 51 Handle<Name> key_end_pos = factory->error_end_pos_symbol(); |
54 JSObject::SetProperty(jserror, key_end_pos, | 52 JSObject::SetProperty(jserror, key_end_pos, |
55 handle(Smi::FromInt(location.end_pos()), isolate), | 53 handle(Smi::FromInt(location.end_pos()), isolate), |
56 SLOPPY).Check(); | 54 SLOPPY).Check(); |
57 | 55 |
58 Handle<Name> key_script = factory->error_script_symbol(); | 56 Handle<Name> key_script = factory->error_script_symbol(); |
59 JSObject::SetProperty(jserror, key_script, script, SLOPPY).Check(); | 57 JSObject::SetProperty(jserror, key_script, script, SLOPPY).Check(); |
60 | 58 |
61 isolate->Throw(*error, &location); | 59 isolate->Throw(*error, &location); |
62 } | 60 } |
63 } | 61 } |
64 } // namespace v8::internal | 62 } // namespace v8::internal |
OLD | NEW |