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 3 // found in the LICENSE file. 4 5 #include "src/pending-compilation-error-handler.h" 6 7 #include "src/debug/debug.h" 8 #include "src/handles.h" 9 #include "src/isolate.h" 10 #include "src/messages.h" 11 12 namespace v8 { 13 namespace internal { 14 15 void PendingCompilationErrorHandler::ThrowPendingError(Isolate* isolate, 16 Handle<Script> script) { 17 if (!has_pending_error_) return; 18 MessageLocation location(script, start_position_, end_position_); 19 Factory* factory = isolate->factory(); 20 Handle<String> argument; 21 if (arg_ != NULL) { 22 argument = arg_->string(); 23 } else if (char_arg_ != NULL) { 24 argument = 25 factory->NewStringFromUtf8(CStrVector(char_arg_)).ToHandleChecked(); 26 } else if (!handle_arg_.is_null()) { 27 argument = handle_arg_; 28 } 29 isolate->debug()->OnCompileError(script); 30 31 Handle<Object> error; 32 switch (error_type_) { 33 case kReferenceError: 34 error = factory->NewReferenceError(message_, argument); 35 break; 36 case kSyntaxError: 37 error = factory->NewSyntaxError(message_, argument); 38 break; 39 default: 40 UNREACHABLE(); 41 break; 42 } 43 44 if (!error->IsJSObject()) { 45 isolate->Throw(*error, &location); 46 return; 47 } 48 49 Handle<JSObject> jserror = Handle<JSObject>::cast(error); 50 51 Handle<Name> key_start_pos = factory->error_start_pos_symbol(); 52 JSObject::SetProperty(jserror, key_start_pos, 53 handle(Smi::FromInt(location.start_pos()), isolate), 54 SLOPPY).Check(); 55 56 Handle<Name> key_end_pos = factory->error_end_pos_symbol(); 57 JSObject::SetProperty(jserror, key_end_pos, 58 handle(Smi::FromInt(location.end_pos()), isolate), 59 SLOPPY).Check(); 60 61 Handle<Name> key_script = factory->error_script_symbol(); 62 JSObject::SetProperty(jserror, key_script, script, SLOPPY).Check(); 63 64 isolate->Throw(*error, &location); 65 } 66 } // namespace internal 67 } // namespace v8 68