diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-01-20 13:40:20 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-01-22 12:41:23 +0000 |
commit | 7961cea6d1041e3e454dae6a1da660b453efd238 (patch) | |
tree | c0eeb4a9ff9ba32986289c1653d9608e53ccb444 /chromium/v8/src/runtime/runtime-internal.cc | |
parent | b7034d0803538058e5c9d904ef03cf5eab34f6ef (diff) | |
download | qtwebengine-chromium-7961cea6d1041e3e454dae6a1da660b453efd238.tar.gz |
BASELINE: Update Chromium to 78.0.3904.130
Change-Id: If185e0c0061b3437531c97c9c8c78f239352a68b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/v8/src/runtime/runtime-internal.cc')
-rw-r--r-- | chromium/v8/src/runtime/runtime-internal.cc | 219 |
1 files changed, 15 insertions, 204 deletions
diff --git a/chromium/v8/src/runtime/runtime-internal.cc b/chromium/v8/src/runtime/runtime-internal.cc index 4b8a0e38a1e..80f9baa48d3 100644 --- a/chromium/v8/src/runtime/runtime-internal.cc +++ b/chromium/v8/src/runtime/runtime-internal.cc @@ -13,6 +13,8 @@ #include "src/execution/arguments-inl.h" #include "src/execution/frames-inl.h" #include "src/execution/isolate-inl.h" +#include "src/execution/messages.h" +#include "src/handles/maybe-handles.h" #include "src/init/bootstrapper.h" #include "src/logging/counters.h" #include "src/numbers/conversions.h" @@ -322,7 +324,8 @@ RUNTIME_FUNCTION(Runtime_AllocateInYoungGeneration) { double_align = false; return *isolate->factory()->NewFillerObject(size, double_align, - AllocationType::kYoung); + AllocationType::kYoung, + AllocationOrigin::kGeneratedCode); } RUNTIME_FUNCTION(Runtime_AllocateInOldGeneration) { @@ -339,7 +342,8 @@ RUNTIME_FUNCTION(Runtime_AllocateInOldGeneration) { CHECK(size <= kMaxRegularHeapObjectSize); } return *isolate->factory()->NewFillerObject(size, double_align, - AllocationType::kOld); + AllocationType::kOld, + AllocationOrigin::kGeneratedCode); } RUNTIME_FUNCTION(Runtime_AllocateByteArray) { @@ -372,228 +376,35 @@ RUNTIME_FUNCTION(Runtime_AllocateSeqTwoByteString) { return *result; } -namespace { - -bool ComputeLocation(Isolate* isolate, MessageLocation* target) { - JavaScriptFrameIterator it(isolate); - if (!it.done()) { - // Compute the location from the function and the relocation info of the - // baseline code. For optimized code this will use the deoptimization - // information to get canonical location information. - std::vector<FrameSummary> frames; - it.frame()->Summarize(&frames); - auto& summary = frames.back().AsJavaScript(); - Handle<SharedFunctionInfo> shared(summary.function()->shared(), isolate); - Handle<Object> script(shared->script(), isolate); - SharedFunctionInfo::EnsureSourcePositionsAvailable(isolate, shared); - int pos = summary.abstract_code()->SourcePosition(summary.code_offset()); - if (script->IsScript() && - !(Handle<Script>::cast(script)->source().IsUndefined(isolate))) { - Handle<Script> casted_script = Handle<Script>::cast(script); - *target = MessageLocation(casted_script, pos, pos + 1, shared); - return true; - } - } - return false; -} - -Handle<String> BuildDefaultCallSite(Isolate* isolate, Handle<Object> object) { - IncrementalStringBuilder builder(isolate); - - builder.AppendString(Object::TypeOf(isolate, object)); - if (object->IsString()) { - builder.AppendCString(" \""); - builder.AppendString(Handle<String>::cast(object)); - builder.AppendCString("\""); - } else if (object->IsNull(isolate)) { - builder.AppendCString(" "); - builder.AppendString(isolate->factory()->null_string()); - } else if (object->IsTrue(isolate)) { - builder.AppendCString(" "); - builder.AppendString(isolate->factory()->true_string()); - } else if (object->IsFalse(isolate)) { - builder.AppendCString(" "); - builder.AppendString(isolate->factory()->false_string()); - } else if (object->IsNumber()) { - builder.AppendCString(" "); - builder.AppendString(isolate->factory()->NumberToString(object)); - } - - return builder.Finish().ToHandleChecked(); -} - -Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object, - CallPrinter::ErrorHint* hint) { - MessageLocation location; - if (ComputeLocation(isolate, &location)) { - ParseInfo info(isolate, location.shared()); - if (parsing::ParseAny(&info, location.shared(), isolate)) { - info.ast_value_factory()->Internalize(isolate); - CallPrinter printer(isolate, location.shared()->IsUserJavaScript()); - Handle<String> str = printer.Print(info.literal(), location.start_pos()); - *hint = printer.GetErrorHint(); - if (str->length() > 0) return str; - } else { - isolate->clear_pending_exception(); - } - } - return BuildDefaultCallSite(isolate, object); -} - -MessageTemplate UpdateErrorTemplate(CallPrinter::ErrorHint hint, - MessageTemplate default_id) { - switch (hint) { - case CallPrinter::ErrorHint::kNormalIterator: - return MessageTemplate::kNotIterable; - - case CallPrinter::ErrorHint::kCallAndNormalIterator: - return MessageTemplate::kNotCallableOrIterable; - - case CallPrinter::ErrorHint::kAsyncIterator: - return MessageTemplate::kNotAsyncIterable; - - case CallPrinter::ErrorHint::kCallAndAsyncIterator: - return MessageTemplate::kNotCallableOrAsyncIterable; - - case CallPrinter::ErrorHint::kNone: - return default_id; - } - return default_id; -} - -} // namespace - -MaybeHandle<Object> Runtime::ThrowIteratorError(Isolate* isolate, - Handle<Object> object) { - CallPrinter::ErrorHint hint = CallPrinter::kNone; - Handle<String> callsite = RenderCallSite(isolate, object, &hint); - MessageTemplate id = MessageTemplate::kNotIterableNoSymbolLoad; - - if (hint == CallPrinter::kNone) { - Handle<Symbol> iterator_symbol = isolate->factory()->iterator_symbol(); - THROW_NEW_ERROR(isolate, NewTypeError(id, callsite, iterator_symbol), - Object); - } - - id = UpdateErrorTemplate(hint, id); - THROW_NEW_ERROR(isolate, NewTypeError(id, callsite), Object); -} - RUNTIME_FUNCTION(Runtime_ThrowIteratorError) { HandleScope scope(isolate); DCHECK_EQ(1, args.length()); CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); - RETURN_RESULT_OR_FAILURE(isolate, - Runtime::ThrowIteratorError(isolate, object)); + return isolate->Throw(*ErrorUtils::NewIteratorError(isolate, object)); } RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) { HandleScope scope(isolate); DCHECK_EQ(1, args.length()); CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); - CallPrinter::ErrorHint hint = CallPrinter::kNone; - Handle<String> callsite = RenderCallSite(isolate, object, &hint); - MessageTemplate id = MessageTemplate::kCalledNonCallable; - id = UpdateErrorTemplate(hint, id); - THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(id, callsite)); + return isolate->Throw( + *ErrorUtils::NewCalledNonCallableError(isolate, object)); } RUNTIME_FUNCTION(Runtime_ThrowConstructedNonConstructable) { HandleScope scope(isolate); DCHECK_EQ(1, args.length()); CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); - CallPrinter::ErrorHint hint = CallPrinter::kNone; - Handle<String> callsite = RenderCallSite(isolate, object, &hint); - MessageTemplate id = MessageTemplate::kNotConstructor; - THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(id, callsite)); + return isolate->Throw( + *ErrorUtils::NewConstructedNonConstructable(isolate, object)); } -namespace { - -// Helper visitor for ThrowPatternAssignmentNonCoercible which finds an -// object literal (representing a destructuring assignment) at a given source -// position. -class PatternFinder final : public AstTraversalVisitor<PatternFinder> { - public: - PatternFinder(Isolate* isolate, Expression* root, int position) - : AstTraversalVisitor(isolate, root), - position_(position), - object_literal_(nullptr) {} - - ObjectLiteral* object_literal() const { return object_literal_; } - - private: - // This is required so that the overriden Visit* methods can be - // called by the base class (template). - friend class AstTraversalVisitor<PatternFinder>; - - void VisitObjectLiteral(ObjectLiteral* lit) { - // TODO(leszeks): This could be smarter in only traversing object literals - // that are known to be a destructuring pattern. We could then also - // potentially find the corresponding assignment value and report that too. - if (lit->position() == position_) { - object_literal_ = lit; - return; - } - AstTraversalVisitor::VisitObjectLiteral(lit); - } - - int position_; - ObjectLiteral* object_literal_; -}; - -} // namespace - RUNTIME_FUNCTION(Runtime_ThrowPatternAssignmentNonCoercible) { HandleScope scope(isolate); - DCHECK_EQ(0, args.length()); - - // Find the object literal representing the destructuring assignment, so that - // we can try to attribute the error to a property name on it rather than to - // the literal itself. - MaybeHandle<String> maybe_property_name; - MessageLocation location; - if (ComputeLocation(isolate, &location)) { - ParseInfo info(isolate, location.shared()); - if (parsing::ParseAny(&info, location.shared(), isolate)) { - info.ast_value_factory()->Internalize(isolate); - - PatternFinder finder(isolate, info.literal(), location.start_pos()); - finder.Run(); - if (finder.object_literal()) { - for (ObjectLiteralProperty* pattern_property : - *finder.object_literal()->properties()) { - Expression* key = pattern_property->key(); - if (key->IsPropertyName()) { - int pos = key->position(); - maybe_property_name = - key->AsLiteral()->AsRawPropertyName()->string(); - // Change the message location to point at the property name. - location = MessageLocation(location.script(), pos, pos + 1, - location.shared()); - break; - } - } - } - } else { - isolate->clear_pending_exception(); - } - } - - // Create a "non-coercible" type error with a property name if one is - // available, otherwise create a generic one. - Handle<Object> error; - Handle<String> property_name; - if (maybe_property_name.ToHandle(&property_name)) { - error = isolate->factory()->NewTypeError( - MessageTemplate::kNonCoercibleWithProperty, property_name); - } else { - error = isolate->factory()->NewTypeError(MessageTemplate::kNonCoercible); - } - - // Explicitly pass the calculated location, as we may have updated it to match - // the property name. - return isolate->Throw(*error, &location); + DCHECK_EQ(1, args.length()); + CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); + return ErrorUtils::ThrowLoadFromNullOrUndefined(isolate, object, + MaybeHandle<Object>()); } RUNTIME_FUNCTION(Runtime_ThrowConstructorReturnedNonObject) { |