Commit a91811e1 authored by jgruber's avatar jgruber Committed by Commit bot

Move remaining Message functions to C++

BUG=

Review-Url: https://codereview.chromium.org/2224973002
Cr-Commit-Position: refs/heads/master@{#38529}
parent e2e676d5
......@@ -2452,16 +2452,12 @@ v8::Local<v8::StackTrace> Message::GetStackTrace() const {
Maybe<int> Message::GetLineNumber(Local<Context> context) const {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, Message, GetLineNumber, int);
i::Handle<i::JSFunction> fun = isolate->message_get_line_number();
i::Handle<i::Object> undefined = isolate->factory()->undefined_value();
i::Handle<i::Object> args[] = {Utils::OpenHandle(this)};
i::Handle<i::Object> result;
has_pending_exception =
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int);
return Just(static_cast<int>(result->Number()));
auto self = Utils::OpenHandle(this);
i::Isolate* isolate = self->GetIsolate();
ENTER_V8(isolate);
EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
auto msg = i::Handle<i::JSMessageObject>::cast(self);
return Just(msg->GetLineNumber());
}
......@@ -2484,16 +2480,12 @@ int Message::GetEndPosition() const {
Maybe<int> Message::GetStartColumn(Local<Context> context) const {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, Message, GetStartColumn, int);
i::Handle<i::JSFunction> fun = isolate->message_get_column_number();
i::Handle<i::Object> undefined = isolate->factory()->undefined_value();
i::Handle<i::Object> args[] = {Utils::OpenHandle(this)};
i::Handle<i::Object> result;
has_pending_exception =
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int);
return Just(static_cast<int>(result->Number()));
auto self = Utils::OpenHandle(this);
i::Isolate* isolate = self->GetIsolate();
ENTER_V8(isolate);
EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
auto msg = i::Handle<i::JSMessageObject>::cast(self);
return Just(msg->GetColumnNumber());
}
......@@ -2506,18 +2498,15 @@ int Message::GetStartColumn() const {
Maybe<int> Message::GetEndColumn(Local<Context> context) const {
auto self = Utils::OpenHandle(this);
PREPARE_FOR_EXECUTION_PRIMITIVE(context, Message, GetEndColumn, int);
i::Handle<i::JSFunction> fun = isolate->message_get_column_number();
i::Handle<i::Object> undefined = isolate->factory()->undefined_value();
i::Handle<i::Object> args[] = {self};
i::Handle<i::Object> result;
has_pending_exception =
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int);
int start = self->start_position();
int end = self->end_position();
return Just(static_cast<int>(result->Number()) + (end - start));
i::Isolate* isolate = self->GetIsolate();
ENTER_V8(isolate);
EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
auto msg = i::Handle<i::JSMessageObject>::cast(self);
const int column_number = msg->GetColumnNumber();
if (column_number == -1) return Just(-1);
const int start = self->start_position();
const int end = self->end_position();
return Just(column_number + (end - start));
}
......@@ -2550,20 +2539,12 @@ bool Message::IsOpaque() const {
MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const {
PREPARE_FOR_EXECUTION(context, Message, GetSourceLine, String);
i::Handle<i::JSFunction> fun = isolate->message_get_source_line();
i::Handle<i::Object> undefined = isolate->factory()->undefined_value();
i::Handle<i::Object> args[] = {Utils::OpenHandle(this)};
i::Handle<i::Object> result;
has_pending_exception =
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION(String);
Local<String> str;
if (result->IsString()) {
str = Utils::ToLocal(i::Handle<i::String>::cast(result));
}
RETURN_ESCAPED(str);
auto self = Utils::OpenHandle(this);
i::Isolate* isolate = self->GetIsolate();
ENTER_V8(isolate);
EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
auto msg = i::Handle<i::JSMessageObject>::cast(self);
RETURN_ESCAPED(Utils::ToLocal(msg->GetSourceLine()));
}
......
......@@ -78,9 +78,6 @@ enum ContextLookupFlags {
V(MAP_GET_METHOD_INDEX, JSFunction, map_get) \
V(MAP_HAS_METHOD_INDEX, JSFunction, map_has) \
V(MAP_SET_METHOD_INDEX, JSFunction, map_set) \
V(MESSAGE_GET_COLUMN_NUMBER_INDEX, JSFunction, message_get_column_number) \
V(MESSAGE_GET_LINE_NUMBER_INDEX, JSFunction, message_get_line_number) \
V(MESSAGE_GET_SOURCE_LINE_INDEX, JSFunction, message_get_source_line) \
V(OBJECT_VALUE_OF, JSFunction, object_value_of) \
V(OBJECT_TO_STRING, JSFunction, object_to_string) \
V(PROMISE_CATCH_INDEX, JSFunction, promise_catch) \
......
......@@ -163,9 +163,6 @@ define COMPILATION_TYPE_HOST = 0;
define COMPILATION_TYPE_EVAL = 1;
define COMPILATION_TYPE_JSON = 2;
# Matches Messages::kNoLineNumberInfo from v8.h
define kNoLineNumberInfo = 0;
# Must match PropertyFilter in property-details.h
define PROPERTY_FILTER_NONE = 0;
define PROPERTY_FILTER_ONLY_ENUMERABLE = 2;
......
......@@ -73,43 +73,4 @@ utils.SetUpLockedPrototype(Script, [
]
);
// -------------------------------------------------------------------
// Message
function GetLineNumber(message) {
var start_position = %MessageGetStartPosition(message);
if (start_position == -1) return kNoLineNumberInfo;
var script = %MessageGetScript(message);
var location = script.locationFromPosition(start_position, true);
if (location == null) return kNoLineNumberInfo;
return location.line + 1;
}
//Returns the offset of the given position within the containing line.
function GetColumnNumber(message) {
var script = %MessageGetScript(message);
var start_position = %MessageGetStartPosition(message);
var location = script.locationFromPosition(start_position, true);
if (location == null) return -1;
return location.column;
}
// Returns the source code line containing the given source
// position, or the empty string if the position is invalid.
function GetSourceLine(message) {
var script = %MessageGetScript(message);
var start_position = %MessageGetStartPosition(message);
var location = script.locationFromPosition(start_position, true);
if (location == null) return "";
return location.sourceText;
}
%InstallToContext([
"message_get_column_number", GetColumnNumber,
"message_get_line_number", GetLineNumber,
"message_get_source_line", GetSourceLine,
]);
});
......@@ -18898,6 +18898,62 @@ void JSDate::SetCachedFields(int64_t local_time_ms, DateCache* date_cache) {
set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
}
namespace {
Script* ScriptFromJSValue(Object* in) {
DCHECK(in->IsJSValue());
JSValue* jsvalue = JSValue::cast(in);
DCHECK(jsvalue->value()->IsScript());
return Script::cast(jsvalue->value());
}
} // namespace
int JSMessageObject::GetLineNumber() const {
if (start_position() == -1) return Message::kNoLineNumberInfo;
Handle<Script> the_script = handle(ScriptFromJSValue(script()));
Script::PositionInfo info;
const Script::OffsetFlag offset_flag = Script::WITH_OFFSET;
if (!the_script->GetPositionInfo(start_position(), &info, offset_flag)) {
return Message::kNoLineNumberInfo;
}
return info.line + 1;
}
int JSMessageObject::GetColumnNumber() const {
if (start_position() == -1) return -1;
Handle<Script> the_script = handle(ScriptFromJSValue(script()));
Script::PositionInfo info;
const Script::OffsetFlag offset_flag = Script::WITH_OFFSET;
if (!the_script->GetPositionInfo(start_position(), &info, offset_flag)) {
return -1;
}
return info.column; // Note: No '+1' in contrast to GetLineNumber.
}
Handle<String> JSMessageObject::GetSourceLine() const {
Handle<Script> the_script = handle(ScriptFromJSValue(script()));
Isolate* isolate = the_script->GetIsolate();
if (the_script->type() == Script::TYPE_WASM) {
return isolate->factory()->empty_string();
}
Script::PositionInfo info;
const Script::OffsetFlag offset_flag = Script::WITH_OFFSET;
if (!the_script->GetPositionInfo(start_position(), &info, offset_flag)) {
return isolate->factory()->empty_string();
}
Handle<String> src = handle(String::cast(the_script->source()), isolate);
return isolate->factory()->NewSubString(src, info.line_start, info.line_end);
}
void JSArrayBuffer::Neuter() {
CHECK(is_neuterable());
......
......@@ -8139,6 +8139,15 @@ class JSMessageObject: public JSObject {
inline int end_position() const;
inline void set_end_position(int value);
int GetLineNumber() const;
// Returns the offset of the given position within the containing line.
int GetColumnNumber() const;
// Returns the source code line containing the given source
// position, or the empty string if the position is invalid.
Handle<String> GetSourceLine() const;
DECLARE_CAST(JSMessageObject)
// Dispatched behavior.
......
......@@ -368,22 +368,6 @@ RUNTIME_FUNCTION(Runtime_AllocateSeqTwoByteString) {
}
RUNTIME_FUNCTION(Runtime_MessageGetStartPosition) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_CHECKED(JSMessageObject, message, 0);
return Smi::FromInt(message->start_position());
}
RUNTIME_FUNCTION(Runtime_MessageGetScript) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_CHECKED(JSMessageObject, message, 0);
return message->script();
}
RUNTIME_FUNCTION(Runtime_IS_VAR) {
UNREACHABLE(); // implemented as macro in the parser
return NULL;
......
......@@ -296,8 +296,6 @@ namespace internal {
F(Interrupt, 0, 1) \
F(IS_VAR, 1, 1) \
F(IsWasmObject, 1, 1) \
F(MessageGetScript, 1, 1) \
F(MessageGetStartPosition, 1, 1) \
F(NewReferenceError, 2, 1) \
F(NewSyntaxError, 2, 1) \
F(NewTypeError, 2, 1) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment