From 8e1176a5fa09bb7c72ea85cf726fb4314cbf9ece Mon Sep 17 00:00:00 2001 From: yangguo Date: Tue, 18 Aug 2015 02:55:40 -0700 Subject: [PATCH] Reland of move property loads from js builtins objects from runtime. (patchset #1 id:1 of https://codereview.chromium.org/1297803003/ ) Reason for revert: Debug isolate failure has nothing to do with this CL. Original issue's description: > Revert of Remove property loads from js builtins objects from runtime. (patchset #2 id:20001 of https://codereview.chromium.org/1293113002/ ) > > Reason for revert: > Still failures in debug-isolates tests > > Original issue's description: > > Remove property loads from js builtins objects from runtime. > > > > R=cbruni@chromium.org > > > > Committed: https://crrev.com/40f6e80d22d2e146b781aa661b76087ab9a492c4 > > Cr-Commit-Position: refs/heads/master@{#30199} > > > > Committed: https://crrev.com/f22d0f205031054a5f3116e052c81ae85741e8e0 > > Cr-Commit-Position: refs/heads/master@{#30209} > > TBR=cbruni@chromium.org,hpayer@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Committed: https://crrev.com/4106a4cbb701b5fe7d0b639e28a4ebfca5c05630 > Cr-Commit-Position: refs/heads/master@{#30213} TBR=cbruni@chromium.org,hpayer@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/1298733003 Cr-Commit-Position: refs/heads/master@{#30215} --- src/api.cc | 76 +++++++++++++++++++++++++---------------------------- src/bootstrapper.cc | 10 +++++++ src/contexts.h | 7 +++++ src/heap/heap.h | 1 - src/isolate.cc | 20 +++++++------- src/messages.js | 38 ++++++++++++--------------- src/v8natives.js | 6 ++--- 7 files changed, 83 insertions(+), 75 deletions(-) diff --git a/src/api.cc b/src/api.cc index 46cac75..469d9c6 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2275,31 +2275,15 @@ v8::Local Message::GetStackTrace() const { } -MUST_USE_RESULT static i::MaybeHandle CallV8HeapFunction( - i::Isolate* isolate, const char* name, i::Handle recv, int argc, - i::Handle argv[]) { - i::Handle object_fun = - i::Object::GetProperty( - isolate, isolate->js_builtins_object(), name).ToHandleChecked(); - i::Handle fun = i::Handle::cast(object_fun); - return i::Execution::Call(isolate, fun, recv, argc, argv); -} - - -MUST_USE_RESULT static i::MaybeHandle CallV8HeapFunction( - i::Isolate* isolate, const char* name, i::Handle data) { - i::Handle argv[] = { data }; - return CallV8HeapFunction(isolate, name, isolate->js_builtins_object(), - arraysize(argv), argv); -} - - Maybe Message::GetLineNumber(Local context) const { PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetLineNumber()", int); + i::Handle fun = isolate->message_get_line_number(); + i::Handle undefined = isolate->factory()->undefined_value(); + i::Handle args[] = {Utils::OpenHandle(this)}; i::Handle 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(result->Number())); } @@ -2326,13 +2310,15 @@ int Message::GetEndPosition() const { Maybe Message::GetStartColumn(Local context) const { PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetStartColumn()", int); - auto self = Utils::OpenHandle(this); - i::Handle start_col_obj; + i::Handle fun = isolate->message_get_column_number(); + i::Handle undefined = isolate->factory()->undefined_value(); + i::Handle args[] = {Utils::OpenHandle(this)}; + i::Handle 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(start_col_obj->Number())); + return Just(static_cast(result->Number())); } @@ -2344,16 +2330,19 @@ int Message::GetStartColumn() const { Maybe Message::GetEndColumn(Local context) const { - PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetEndColumn()", int); auto self = Utils::OpenHandle(this); - i::Handle start_col_obj; + PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetEndColumn()", int); + i::Handle fun = isolate->message_get_column_number(); + i::Handle undefined = isolate->factory()->undefined_value(); + i::Handle args[] = {self}; + i::Handle 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(start_col_obj->Number()) + (end - start)); + return Just(static_cast(result->Number()) + (end - start)); } @@ -2387,10 +2376,13 @@ bool Message::IsOpaque() const { MaybeLocal Message::GetSourceLine(Local context) const { PREPARE_FOR_EXECUTION(context, "v8::Message::GetSourceLine()", String); + i::Handle fun = isolate->message_get_source_line(); + i::Handle undefined = isolate->factory()->undefined_value(); + i::Handle args[] = {Utils::OpenHandle(this)}; i::Handle 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 str; if (result->IsString()) { @@ -3380,9 +3372,11 @@ Maybe Value::Equals(Local context, Local that) const { } PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Value::Equals()", bool); i::Handle args[] = { other }; + i::Handle fun(i::JSFunction::cast( + isolate->js_builtins_object()->javascript_builtin(i::Builtins::EQUALS))); i::Handle 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 v8::Object::DefineOwnProperty(v8::Local context, i::Handle desc_array = isolate->factory()->NewJSArrayWithElements(desc, i::FAST_ELEMENTS, 3); i::Handle args[] = {self, key_obj, value_obj, desc_array}; + i::Handle undefined = isolate->factory()->undefined_value(); + i::Handle fun = isolate->object_define_own_property(); i::Handle 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 v8::Object::GetOwnPropertyDescriptor(Local context, auto obj = Utils::OpenHandle(this); auto key_name = Utils::OpenHandle(*key); i::Handle args[] = { obj, key_name }; + i::Handle fun = isolate->object_get_own_property_descriptor(); + i::Handle undefined = isolate->factory()->undefined_value(); i::Handle 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)); } diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 62d417e..5f4e0995 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -1754,6 +1754,16 @@ void Bootstrapper::ImportNatives(Isolate* isolate, Handle 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); diff --git a/src/contexts.h b/src/contexts.h index 9271b06..9e6fc0e 100644 --- a/src/contexts.h +++ b/src/contexts.h @@ -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) \ diff --git a/src/heap/heap.h b/src/heap/heap.h index 7286378..43b4d25 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -275,7 +275,6 @@ namespace internal { V(toJSON_string, "toJSON") \ V(KeyedLoadMonomorphic_string, "KeyedLoadMonomorphic") \ V(KeyedStoreMonomorphic_string, "KeyedStoreMonomorphic") \ - V(stack_overflow_string, "$stackOverflowBoilerplate") \ V(illegal_access_string, "illegal access") \ V(cell_value_string, "%cell_value") \ V(illegal_argument_string, "illegal argument") \ diff --git a/src/isolate.cc b/src/isolate.cc index 06cca0a..155e9ea 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -845,17 +845,19 @@ 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 key = factory()->stack_overflow_string(); - Handle boilerplate = - Object::GetProperty(js_builtins_object(), key).ToHandleChecked(); - if (boilerplate->IsUndefined()) { - return Throw(heap()->undefined_value(), nullptr); - } - Handle exception = - factory()->CopyJSObject(Handle::cast(boilerplate)); + Handle exception; + if (bootstrapper()->IsActive()) { + // There is no boilerplate to use during bootstrapping. + exception = factory()->NewStringFromAsciiChecked( + MessageTemplate::TemplateString(MessageTemplate::kStackOverflow)); + } else { + Handle boilerplate = stack_overflow_boilerplate(); + Handle copy = factory()->CopyJSObject(boilerplate); + CaptureAndSetSimpleStackTrace(copy, factory()->undefined_value()); + exception = copy; + } Throw(*exception, nullptr); - CaptureAndSetSimpleStackTrace(exception, factory()->undefined_value()); #ifdef VERIFY_HEAP if (FLAG_verify_heap && FLAG_stress_compaction) { heap()->CollectAllAvailableGarbage("trigger compaction"); diff --git a/src/messages.js b/src/messages.js index 712dba4..a111660 100644 --- a/src/messages.js +++ b/src/messages.js @@ -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; }); }); diff --git a/src/v8natives.js b/src/v8natives.js index a492547..9d37e7c 100644 --- a/src/v8natives.js +++ b/src/v8natives.js @@ -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; }); -- 2.7.4