Commit 40f6e80d authored by yangguo's avatar yangguo Committed by Commit bot

Remove property loads from js builtins objects from runtime.

R=cbruni@chromium.org

Review URL: https://codereview.chromium.org/1293113002

Cr-Commit-Position: refs/heads/master@{#30199}
parent ec4bb0e9
......@@ -2275,31 +2275,15 @@ v8::Local<v8::StackTrace> Message::GetStackTrace() const {
}
MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction(
i::Isolate* isolate, const char* name, i::Handle<i::Object> recv, int argc,
i::Handle<i::Object> argv[]) {
i::Handle<i::Object> object_fun =
i::Object::GetProperty(
isolate, isolate->js_builtins_object(), name).ToHandleChecked();
i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(object_fun);
return i::Execution::Call(isolate, fun, recv, argc, argv);
}
MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction(
i::Isolate* isolate, const char* name, i::Handle<i::Object> data) {
i::Handle<i::Object> argv[] = { data };
return CallV8HeapFunction(isolate, name, isolate->js_builtins_object(),
arraysize(argv), argv);
}
Maybe<int> Message::GetLineNumber(Local<Context> context) const {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::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 =
!CallV8HeapFunction(isolate, "$messageGetLineNumber",
Utils::OpenHandle(this)).ToHandle(&result);
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int);
return Just(static_cast<int>(result->Number()));
}
......@@ -2326,13 +2310,15 @@ int Message::GetEndPosition() const {
Maybe<int> Message::GetStartColumn(Local<Context> context) const {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetStartColumn()",
int);
auto self = Utils::OpenHandle(this);
i::Handle<i::Object> start_col_obj;
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 =
!CallV8HeapFunction(isolate, "$messageGetPositionInLine", self)
.ToHandle(&start_col_obj);
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int);
return Just(static_cast<int>(start_col_obj->Number()));
return Just(static_cast<int>(result->Number()));
}
......@@ -2344,16 +2330,19 @@ int Message::GetStartColumn() const {
Maybe<int> Message::GetEndColumn(Local<Context> context) const {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetEndColumn()", int);
auto self = Utils::OpenHandle(this);
i::Handle<i::Object> start_col_obj;
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::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 =
!CallV8HeapFunction(isolate, "$messageGetPositionInLine", self)
.ToHandle(&start_col_obj);
!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>(start_col_obj->Number()) + (end - start));
return Just(static_cast<int>(result->Number()) + (end - start));
}
......@@ -2387,10 +2376,13 @@ bool Message::IsOpaque() const {
MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const {
PREPARE_FOR_EXECUTION(context, "v8::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 =
!CallV8HeapFunction(isolate, "$messageGetSourceLine",
Utils::OpenHandle(this)).ToHandle(&result);
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION(String);
Local<String> str;
if (result->IsString()) {
......@@ -3380,9 +3372,11 @@ Maybe<bool> Value::Equals(Local<Context> context, Local<Value> that) const {
}
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Value::Equals()", bool);
i::Handle<i::Object> args[] = { other };
i::Handle<i::JSFunction> fun(i::JSFunction::cast(
isolate->js_builtins_object()->javascript_builtin(i::Builtins::EQUALS)));
i::Handle<i::Object> result;
has_pending_exception =
!CallV8HeapFunction(isolate, "EQUALS", self, arraysize(args), args)
!i::Execution::Call(isolate, fun, self, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return Just(*result == i::Smi::FromInt(i::EQUAL));
......@@ -3512,11 +3506,12 @@ Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context,
i::Handle<i::JSArray> desc_array =
isolate->factory()->NewJSArrayWithElements(desc, i::FAST_ELEMENTS, 3);
i::Handle<i::Object> args[] = {self, key_obj, value_obj, desc_array};
i::Handle<i::Object> undefined = isolate->factory()->undefined_value();
i::Handle<i::JSFunction> fun = isolate->object_define_own_property();
i::Handle<i::Object> result;
has_pending_exception =
!CallV8HeapFunction(isolate, "$objectDefineOwnProperty",
isolate->factory()->undefined_value(),
arraysize(args), args).ToHandle(&result);
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return Just(result->BooleanValue());
}
......@@ -3648,11 +3643,12 @@ MaybeLocal<Value> v8::Object::GetOwnPropertyDescriptor(Local<Context> context,
auto obj = Utils::OpenHandle(this);
auto key_name = Utils::OpenHandle(*key);
i::Handle<i::Object> args[] = { obj, key_name };
i::Handle<i::JSFunction> fun = isolate->object_get_own_property_descriptor();
i::Handle<i::Object> undefined = isolate->factory()->undefined_value();
i::Handle<i::Object> result;
has_pending_exception =
!CallV8HeapFunction(isolate, "$objectGetOwnPropertyDescriptor",
isolate->factory()->undefined_value(),
arraysize(args), args).ToHandle(&result);
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION(Value);
RETURN_ESCAPED(Utils::ToLocal(result));
}
......
......@@ -1754,6 +1754,16 @@ void Bootstrapper::ImportNatives(Isolate* isolate, Handle<JSObject> container) {
INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun);
INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor",
to_complete_property_descriptor);
INSTALL_NATIVE(JSFunction, "ObjectDefineOwnProperty",
object_define_own_property);
INSTALL_NATIVE(JSFunction, "ObjectGetOwnPropertyDescriptor",
object_get_own_property_descriptor);
INSTALL_NATIVE(JSFunction, "MessageGetLineNumber", message_get_line_number);
INSTALL_NATIVE(JSFunction, "MessageGetColumnNumber",
message_get_column_number);
INSTALL_NATIVE(JSFunction, "MessageGetSourceLine", message_get_source_line);
INSTALL_NATIVE(JSObject, "StackOverflowBoilerplate",
stack_overflow_boilerplate);
INSTALL_NATIVE(JSFunction, "JsonSerializeAdapter", json_serialize_adapter);
INSTALL_NATIVE(JSFunction, "Error", error_function);
......
......@@ -172,6 +172,13 @@ enum BindingFlags {
promise_has_user_defined_reject_handler) \
V(TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, JSFunction, \
to_complete_property_descriptor) \
V(OBJECT_DEFINE_OWN_PROPERTY_INDEX, JSFunction, object_define_own_property) \
V(OBJECT_GET_OWN_PROPERTY_DESCROPTOR_INDEX, JSFunction, \
object_get_own_property_descriptor) \
V(MESSAGE_GET_LINE_NUMBER_INDEX, JSFunction, message_get_line_number) \
V(MESSAGE_GET_COLUMN_NUMBER_INDEX, JSFunction, message_get_column_number) \
V(MESSAGE_GET_SOURCE_LINE_INDEX, JSFunction, message_get_source_line) \
V(STACK_OVERFLOW_BOILERPLATE_INDEX, JSObject, stack_overflow_boilerplate) \
V(JSON_SERIALIZE_ADAPTER_INDEX, JSFunction, json_serialize_adapter) \
V(DERIVED_HAS_TRAP_INDEX, JSFunction, derived_has_trap) \
V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \
......
......@@ -845,14 +845,8 @@ Object* Isolate::StackOverflow() {
// At this point we cannot create an Error object using its javascript
// constructor. Instead, we copy the pre-constructed boilerplate and
// attach the stack trace as a hidden property.
Handle<String> key = factory()->stack_overflow_string();
Handle<Object> boilerplate =
Object::GetProperty(js_builtins_object(), key).ToHandleChecked();
if (boilerplate->IsUndefined()) {
return Throw(heap()->undefined_value(), nullptr);
}
Handle<JSObject> exception =
factory()->CopyJSObject(Handle<JSObject>::cast(boilerplate));
Handle<JSObject> boilerplate = stack_overflow_boilerplate();
Handle<JSObject> exception = factory()->CopyJSObject(boilerplate);
Throw(*exception, nullptr);
CaptureAndSetSimpleStackTrace(exception, factory()->undefined_value());
......
......@@ -5,12 +5,7 @@
// -------------------------------------------------------------------
var $errorToString;
var $getStackTraceLine;
var $internalErrorSymbol;
var $messageGetPositionInLine;
var $messageGetLineNumber;
var $messageGetSourceLine;
var $stackOverflowBoilerplate;
var $stackTraceSymbol;
var MakeError;
var MakeEvalError;
......@@ -213,6 +208,16 @@ function GetLineNumber(message) {
}
//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) {
......@@ -223,6 +228,7 @@ function GetSourceLine(message) {
return location.sourceText();
}
/**
* Find a line number given a specific source position.
* @param {number} position The source position.
......@@ -556,17 +562,6 @@ utils.SetUpLockedPrototype(SourceSlice,
);
// Returns the offset of the given position within the containing
// line.
function GetPositionInLine(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;
}
function GetStackTraceLine(recv, fun, pos, isGlobal) {
return new CallSite(recv, fun, pos, false).toString();
}
......@@ -1005,9 +1000,6 @@ utils.InstallFunctions(GlobalError.prototype, DONT_ENUM,
['toString', ErrorToString]);
$errorToString = ErrorToString;
$messageGetPositionInLine = GetPositionInLine;
$messageGetLineNumber = GetLineNumber;
$messageGetSourceLine = GetSourceLine;
MakeError = function(type, arg0, arg1, arg2) {
return MakeGenericError(GlobalError, type, arg0, arg1, arg2);
......@@ -1031,8 +1023,8 @@ MakeURIError = function() {
// Boilerplate for exceptions for stack overflows. Used from
// Isolate::StackOverflow().
$stackOverflowBoilerplate = MakeRangeError(kStackOverflow);
%DefineAccessorPropertyUnchecked($stackOverflowBoilerplate, 'stack',
var StackOverflowBoilerplate = MakeRangeError(kStackOverflow);
%DefineAccessorPropertyUnchecked(StackOverflowBoilerplate, 'stack',
StackTraceGetter, StackTraceSetter,
DONT_ENUM);
......@@ -1059,6 +1051,10 @@ utils.ExportToRuntime(function(to) {
to.NoSideEffectToString = NoSideEffectToString;
to.ToDetailString = ToDetailString;
to.MakeError = MakeGenericError;
to.MessageGetLineNumber = GetLineNumber;
to.MessageGetColumnNumber = GetColumnNumber;
to.MessageGetSourceLine = GetSourceLine;
to.StackOverflowBoilerplate = StackOverflowBoilerplate;
});
});
......@@ -3,8 +3,6 @@
// found in the LICENSE file.
var $functionSourceString;
var $objectDefineOwnProperty;
var $objectGetOwnPropertyDescriptor;
(function(global, utils) {
......@@ -1785,8 +1783,6 @@ function GetIterator(obj, method) {
// Exports
$functionSourceString = FunctionSourceString;
$objectDefineOwnProperty = DefineOwnPropertyFromAPI;
$objectGetOwnPropertyDescriptor = ObjectGetOwnPropertyDescriptor;
utils.ObjectDefineProperties = ObjectDefineProperties;
utils.ObjectDefineProperty = ObjectDefineProperty;
......@@ -1812,6 +1808,8 @@ utils.Export(function(to) {
utils.ExportToRuntime(function(to) {
to.GlobalEval = GlobalEval;
to.ObjectDefineOwnProperty = DefineOwnPropertyFromAPI;
to.ObjectGetOwnPropertyDescriptor = ObjectGetOwnPropertyDescriptor;
to.ToCompletePropertyDescriptor = ToCompletePropertyDescriptor;
});
......
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