2015-02-25 14:17:39 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/pending-compilation-error-handler.h"
|
|
|
|
|
2016-09-06 08:59:41 +00:00
|
|
|
#include "src/ast/ast-value-factory.h"
|
2015-07-31 11:07:50 +00:00
|
|
|
#include "src/debug/debug.h"
|
2015-02-25 14:17:39 +00:00
|
|
|
#include "src/handles.h"
|
|
|
|
#include "src/isolate.h"
|
|
|
|
#include "src/messages.h"
|
2017-02-09 08:35:03 +00:00
|
|
|
#include "src/objects-inl.h"
|
2015-02-25 14:17:39 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2016-11-15 10:15:43 +00:00
|
|
|
Handle<String> PendingCompilationErrorHandler::ArgumentString(
|
|
|
|
Isolate* isolate) {
|
2017-10-13 16:33:03 +00:00
|
|
|
if (arg_ != nullptr) return arg_->string();
|
|
|
|
if (char_arg_ != nullptr) {
|
2016-11-15 10:15:43 +00:00
|
|
|
return isolate->factory()
|
|
|
|
->NewStringFromUtf8(CStrVector(char_arg_))
|
|
|
|
.ToHandleChecked();
|
|
|
|
}
|
|
|
|
return isolate->factory()->undefined_string();
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<String> PendingCompilationErrorHandler::FormatMessage(Isolate* isolate) {
|
|
|
|
return MessageTemplate::FormatMessage(isolate, message_,
|
|
|
|
ArgumentString(isolate));
|
|
|
|
}
|
|
|
|
|
2015-02-25 14:17:39 +00:00
|
|
|
void PendingCompilationErrorHandler::ThrowPendingError(Isolate* isolate,
|
|
|
|
Handle<Script> script) {
|
|
|
|
if (!has_pending_error_) return;
|
|
|
|
MessageLocation location(script, start_position_, end_position_);
|
|
|
|
Factory* factory = isolate->factory();
|
2016-11-15 10:15:43 +00:00
|
|
|
Handle<String> argument = ArgumentString(isolate);
|
2015-02-25 14:17:39 +00:00
|
|
|
isolate->debug()->OnCompileError(script);
|
|
|
|
|
|
|
|
Handle<Object> error;
|
|
|
|
switch (error_type_) {
|
|
|
|
case kReferenceError:
|
2015-08-17 11:02:31 +00:00
|
|
|
error = factory->NewReferenceError(message_, argument);
|
2015-02-25 14:17:39 +00:00
|
|
|
break;
|
|
|
|
case kSyntaxError:
|
2015-08-17 11:02:31 +00:00
|
|
|
error = factory->NewSyntaxError(message_, argument);
|
2015-05-18 08:34:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2015-02-25 14:17:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-10 17:42:01 +00:00
|
|
|
if (!error->IsJSObject()) {
|
|
|
|
isolate->Throw(*error, &location);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-25 14:17:39 +00:00
|
|
|
Handle<JSObject> jserror = Handle<JSObject>::cast(error);
|
|
|
|
|
|
|
|
Handle<Name> key_start_pos = factory->error_start_pos_symbol();
|
|
|
|
JSObject::SetProperty(jserror, key_start_pos,
|
|
|
|
handle(Smi::FromInt(location.start_pos()), isolate),
|
|
|
|
SLOPPY).Check();
|
|
|
|
|
|
|
|
Handle<Name> key_end_pos = factory->error_end_pos_symbol();
|
|
|
|
JSObject::SetProperty(jserror, key_end_pos,
|
|
|
|
handle(Smi::FromInt(location.end_pos()), isolate),
|
|
|
|
SLOPPY).Check();
|
|
|
|
|
|
|
|
Handle<Name> key_script = factory->error_script_symbol();
|
|
|
|
JSObject::SetProperty(jserror, key_script, script, SLOPPY).Check();
|
|
|
|
|
|
|
|
isolate->Throw(*error, &location);
|
|
|
|
}
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|