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 { ...@@ -2452,16 +2452,12 @@ v8::Local<v8::StackTrace> Message::GetStackTrace() const {
Maybe<int> Message::GetLineNumber(Local<Context> context) const { Maybe<int> Message::GetLineNumber(Local<Context> context) const {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, Message, GetLineNumber, int); auto self = Utils::OpenHandle(this);
i::Handle<i::JSFunction> fun = isolate->message_get_line_number(); i::Isolate* isolate = self->GetIsolate();
i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); ENTER_V8(isolate);
i::Handle<i::Object> args[] = {Utils::OpenHandle(this)}; EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::Object> result; auto msg = i::Handle<i::JSMessageObject>::cast(self);
has_pending_exception = return Just(msg->GetLineNumber());
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int);
return Just(static_cast<int>(result->Number()));
} }
...@@ -2484,16 +2480,12 @@ int Message::GetEndPosition() const { ...@@ -2484,16 +2480,12 @@ int Message::GetEndPosition() const {
Maybe<int> Message::GetStartColumn(Local<Context> context) const { Maybe<int> Message::GetStartColumn(Local<Context> context) const {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, Message, GetStartColumn, int); auto self = Utils::OpenHandle(this);
i::Handle<i::JSFunction> fun = isolate->message_get_column_number(); i::Isolate* isolate = self->GetIsolate();
i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); ENTER_V8(isolate);
i::Handle<i::Object> args[] = {Utils::OpenHandle(this)}; EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::Object> result; auto msg = i::Handle<i::JSMessageObject>::cast(self);
has_pending_exception = return Just(msg->GetColumnNumber());
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int);
return Just(static_cast<int>(result->Number()));
} }
...@@ -2506,18 +2498,15 @@ int Message::GetStartColumn() const { ...@@ -2506,18 +2498,15 @@ int Message::GetStartColumn() const {
Maybe<int> Message::GetEndColumn(Local<Context> context) const { Maybe<int> Message::GetEndColumn(Local<Context> context) const {
auto self = Utils::OpenHandle(this); auto self = Utils::OpenHandle(this);
PREPARE_FOR_EXECUTION_PRIMITIVE(context, Message, GetEndColumn, int); i::Isolate* isolate = self->GetIsolate();
i::Handle<i::JSFunction> fun = isolate->message_get_column_number(); ENTER_V8(isolate);
i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::Object> args[] = {self}; auto msg = i::Handle<i::JSMessageObject>::cast(self);
i::Handle<i::Object> result; const int column_number = msg->GetColumnNumber();
has_pending_exception = if (column_number == -1) return Just(-1);
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args) const int start = self->start_position();
.ToHandle(&result); const int end = self->end_position();
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int); return Just(column_number + (end - start));
int start = self->start_position();
int end = self->end_position();
return Just(static_cast<int>(result->Number()) + (end - start));
} }
...@@ -2550,20 +2539,12 @@ bool Message::IsOpaque() const { ...@@ -2550,20 +2539,12 @@ bool Message::IsOpaque() const {
MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const { MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const {
PREPARE_FOR_EXECUTION(context, Message, GetSourceLine, String); auto self = Utils::OpenHandle(this);
i::Handle<i::JSFunction> fun = isolate->message_get_source_line(); i::Isolate* isolate = self->GetIsolate();
i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); ENTER_V8(isolate);
i::Handle<i::Object> args[] = {Utils::OpenHandle(this)}; EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::Object> result; auto msg = i::Handle<i::JSMessageObject>::cast(self);
has_pending_exception = RETURN_ESCAPED(Utils::ToLocal(msg->GetSourceLine()));
!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);
} }
......
...@@ -78,9 +78,6 @@ enum ContextLookupFlags { ...@@ -78,9 +78,6 @@ enum ContextLookupFlags {
V(MAP_GET_METHOD_INDEX, JSFunction, map_get) \ V(MAP_GET_METHOD_INDEX, JSFunction, map_get) \
V(MAP_HAS_METHOD_INDEX, JSFunction, map_has) \ V(MAP_HAS_METHOD_INDEX, JSFunction, map_has) \
V(MAP_SET_METHOD_INDEX, JSFunction, map_set) \ 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_VALUE_OF, JSFunction, object_value_of) \
V(OBJECT_TO_STRING, JSFunction, object_to_string) \ V(OBJECT_TO_STRING, JSFunction, object_to_string) \
V(PROMISE_CATCH_INDEX, JSFunction, promise_catch) \ V(PROMISE_CATCH_INDEX, JSFunction, promise_catch) \
......
...@@ -163,9 +163,6 @@ define COMPILATION_TYPE_HOST = 0; ...@@ -163,9 +163,6 @@ define COMPILATION_TYPE_HOST = 0;
define COMPILATION_TYPE_EVAL = 1; define COMPILATION_TYPE_EVAL = 1;
define COMPILATION_TYPE_JSON = 2; define COMPILATION_TYPE_JSON = 2;
# Matches Messages::kNoLineNumberInfo from v8.h
define kNoLineNumberInfo = 0;
# Must match PropertyFilter in property-details.h # Must match PropertyFilter in property-details.h
define PROPERTY_FILTER_NONE = 0; define PROPERTY_FILTER_NONE = 0;
define PROPERTY_FILTER_ONLY_ENUMERABLE = 2; define PROPERTY_FILTER_ONLY_ENUMERABLE = 2;
......
...@@ -73,43 +73,4 @@ utils.SetUpLockedPrototype(Script, [ ...@@ -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) { ...@@ -18898,6 +18898,62 @@ void JSDate::SetCachedFields(int64_t local_time_ms, DateCache* date_cache) {
set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 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() { void JSArrayBuffer::Neuter() {
CHECK(is_neuterable()); CHECK(is_neuterable());
......
...@@ -8139,6 +8139,15 @@ class JSMessageObject: public JSObject { ...@@ -8139,6 +8139,15 @@ class JSMessageObject: public JSObject {
inline int end_position() const; inline int end_position() const;
inline void set_end_position(int value); 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) DECLARE_CAST(JSMessageObject)
// Dispatched behavior. // Dispatched behavior.
......
...@@ -368,22 +368,6 @@ RUNTIME_FUNCTION(Runtime_AllocateSeqTwoByteString) { ...@@ -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) { RUNTIME_FUNCTION(Runtime_IS_VAR) {
UNREACHABLE(); // implemented as macro in the parser UNREACHABLE(); // implemented as macro in the parser
return NULL; return NULL;
......
...@@ -296,8 +296,6 @@ namespace internal { ...@@ -296,8 +296,6 @@ namespace internal {
F(Interrupt, 0, 1) \ F(Interrupt, 0, 1) \
F(IS_VAR, 1, 1) \ F(IS_VAR, 1, 1) \
F(IsWasmObject, 1, 1) \ F(IsWasmObject, 1, 1) \
F(MessageGetScript, 1, 1) \
F(MessageGetStartPosition, 1, 1) \
F(NewReferenceError, 2, 1) \ F(NewReferenceError, 2, 1) \
F(NewSyntaxError, 2, 1) \ F(NewSyntaxError, 2, 1) \
F(NewTypeError, 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