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"
|
|
|
|
|
|
|
|
#include "src/debug.h"
|
|
|
|
#include "src/handles.h"
|
|
|
|
#include "src/isolate.h"
|
|
|
|
#include "src/messages.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
void PendingCompilationErrorHandler::ThrowPendingError(Isolate* isolate,
|
|
|
|
Handle<Script> script) {
|
|
|
|
if (!has_pending_error_) return;
|
|
|
|
MessageLocation location(script, start_position_, end_position_);
|
|
|
|
Factory* factory = isolate->factory();
|
2015-03-24 16:46:53 +00:00
|
|
|
bool has_arg = arg_ != NULL || char_arg_ != NULL || !handle_arg_.is_null();
|
2015-02-25 14:17:39 +00:00
|
|
|
Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0);
|
|
|
|
if (arg_ != NULL) {
|
|
|
|
Handle<String> arg_string = arg_->string();
|
|
|
|
elements->set(0, *arg_string);
|
|
|
|
} else if (char_arg_ != NULL) {
|
|
|
|
Handle<String> arg_string =
|
|
|
|
factory->NewStringFromUtf8(CStrVector(char_arg_)).ToHandleChecked();
|
|
|
|
elements->set(0, *arg_string);
|
2015-03-24 16:46:53 +00:00
|
|
|
} else if (!handle_arg_.is_null()) {
|
|
|
|
elements->set(0, *handle_arg_);
|
2015-02-25 14:17:39 +00:00
|
|
|
}
|
|
|
|
isolate->debug()->OnCompileError(script);
|
|
|
|
|
|
|
|
Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
|
|
|
|
Handle<Object> error;
|
|
|
|
|
|
|
|
switch (error_type_) {
|
|
|
|
case kReferenceError:
|
2015-05-15 13:32:32 +00:00
|
|
|
error = factory->NewError("MakeReferenceError", message_, array);
|
2015-02-25 14:17:39 +00:00
|
|
|
break;
|
|
|
|
case kSyntaxError:
|
2015-05-15 13:32:32 +00:00
|
|
|
error = factory->NewError("MakeSyntaxError", message_, array);
|
2015-02-25 14:17:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace v8::internal
|