LCOV - code coverage report
Current view: top level - src/runtime - runtime-internal.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 253 315 80.3 %
Date: 2019-01-20 Functions: 47 97 48.5 %

          Line data    Source code
       1             : // Copyright 2014 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include <memory>
       6             : 
       7             : #include "src/api.h"
       8             : #include "src/arguments-inl.h"
       9             : #include "src/ast/ast-traversal-visitor.h"
      10             : #include "src/ast/prettyprinter.h"
      11             : #include "src/bootstrapper.h"
      12             : #include "src/builtins/builtins.h"
      13             : #include "src/conversions.h"
      14             : #include "src/counters.h"
      15             : #include "src/debug/debug.h"
      16             : #include "src/frames-inl.h"
      17             : #include "src/isolate-inl.h"
      18             : #include "src/message-template.h"
      19             : #include "src/objects/js-array-inl.h"
      20             : #include "src/parsing/parse-info.h"
      21             : #include "src/parsing/parsing.h"
      22             : #include "src/runtime/runtime-utils.h"
      23             : #include "src/snapshot/snapshot.h"
      24             : #include "src/string-builder-inl.h"
      25             : 
      26             : namespace v8 {
      27             : namespace internal {
      28             : 
      29           0 : RUNTIME_FUNCTION(Runtime_CheckIsBootstrapping) {
      30             :   SealHandleScope shs(isolate);
      31             :   DCHECK_EQ(0, args.length());
      32           0 :   CHECK(isolate->bootstrapper()->IsActive());
      33             :   return ReadOnlyRoots(isolate).undefined_value();
      34             : }
      35             : 
      36           0 : RUNTIME_FUNCTION(Runtime_FatalProcessOutOfMemoryInAllocateRaw) {
      37           0 :   HandleScope scope(isolate);
      38             :   DCHECK_EQ(0, args.length());
      39           0 :   isolate->heap()->FatalProcessOutOfMemory("CodeStubAssembler::AllocateRaw");
      40           0 :   UNREACHABLE();
      41             : }
      42             : 
      43           0 : RUNTIME_FUNCTION(Runtime_FatalProcessOutOfMemoryInvalidArrayLength) {
      44           0 :   HandleScope scope(isolate);
      45             :   DCHECK_EQ(0, args.length());
      46           0 :   isolate->heap()->FatalProcessOutOfMemory("invalid array length");
      47           0 :   UNREACHABLE();
      48             : }
      49             : 
      50      177161 : RUNTIME_FUNCTION(Runtime_Throw) {
      51      177161 :   HandleScope scope(isolate);
      52             :   DCHECK_EQ(1, args.length());
      53      177161 :   return isolate->Throw(args[0]);
      54             : }
      55             : 
      56       83929 : RUNTIME_FUNCTION(Runtime_ReThrow) {
      57       83929 :   HandleScope scope(isolate);
      58             :   DCHECK_EQ(1, args.length());
      59       83929 :   return isolate->ReThrow(args[0]);
      60             : }
      61             : 
      62        2137 : RUNTIME_FUNCTION(Runtime_ThrowStackOverflow) {
      63             :   SealHandleScope shs(isolate);
      64             :   DCHECK_LE(0, args.length());
      65        2137 :   return isolate->StackOverflow();
      66             : }
      67             : 
      68           0 : RUNTIME_FUNCTION(Runtime_ThrowSymbolAsyncIteratorInvalid) {
      69           0 :   HandleScope scope(isolate);
      70             :   DCHECK_EQ(0, args.length());
      71           0 :   THROW_NEW_ERROR_RETURN_FAILURE(
      72           0 :       isolate, NewTypeError(MessageTemplate::kSymbolAsyncIteratorInvalid));
      73             : }
      74             : 
      75             : #define THROW_ERROR(isolate, args, call)                               \
      76             :   HandleScope scope(isolate);                                          \
      77             :   DCHECK_LE(1, args.length());                                         \
      78             :   CONVERT_SMI_ARG_CHECKED(message_id_smi, 0);                          \
      79             :                                                                        \
      80             :   Handle<Object> undefined = isolate->factory()->undefined_value();    \
      81             :   Handle<Object> arg0 = (args.length() > 1) ? args.at(1) : undefined;  \
      82             :   Handle<Object> arg1 = (args.length() > 2) ? args.at(2) : undefined;  \
      83             :   Handle<Object> arg2 = (args.length() > 3) ? args.at(3) : undefined;  \
      84             :                                                                        \
      85             :   MessageTemplate message_id = MessageTemplateFromInt(message_id_smi); \
      86             :                                                                        \
      87             :   THROW_NEW_ERROR_RETURN_FAILURE(isolate, call(message_id, arg0, arg1, arg2));
      88             : 
      89       11880 : RUNTIME_FUNCTION(Runtime_ThrowRangeError) {
      90       35640 :   THROW_ERROR(isolate, args, NewRangeError);
      91             : }
      92             : 
      93       75882 : RUNTIME_FUNCTION(Runtime_ThrowTypeError) {
      94      227646 :   THROW_ERROR(isolate, args, NewTypeError);
      95             : }
      96             : 
      97             : #undef THROW_ERROR
      98             : 
      99             : namespace {
     100             : 
     101         563 : const char* ElementsKindToType(ElementsKind fixed_elements_kind) {
     102         563 :   switch (fixed_elements_kind) {
     103             : #define ELEMENTS_KIND_CASE(Type, type, TYPE, ctype) \
     104             :   case TYPE##_ELEMENTS:                             \
     105             :     return #Type "Array";
     106             : 
     107           0 :     TYPED_ARRAYS(ELEMENTS_KIND_CASE)
     108             : #undef ELEMENTS_KIND_CASE
     109             : 
     110             :     default:
     111           0 :       UNREACHABLE();
     112             :   }
     113             : }
     114             : 
     115             : }  // namespace
     116             : 
     117         563 : RUNTIME_FUNCTION(Runtime_ThrowInvalidTypedArrayAlignment) {
     118         563 :   HandleScope scope(isolate);
     119             :   DCHECK_EQ(2, args.length());
     120        1126 :   CONVERT_ARG_HANDLE_CHECKED(Map, map, 0);
     121        1126 :   CONVERT_ARG_HANDLE_CHECKED(String, problem_string, 1);
     122             : 
     123         563 :   ElementsKind kind = map->elements_kind();
     124             : 
     125             :   Handle<String> type =
     126         563 :       isolate->factory()->NewStringFromAsciiChecked(ElementsKindToType(kind));
     127             : 
     128             :   ExternalArrayType external_type;
     129             :   size_t size;
     130         563 :   Factory::TypeAndSizeForElementsKind(kind, &external_type, &size);
     131             :   Handle<Object> element_size =
     132         563 :       handle(Smi::FromInt(static_cast<int>(size)), isolate);
     133             : 
     134        1126 :   THROW_NEW_ERROR_RETURN_FAILURE(
     135             :       isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayAlignment,
     136         563 :                              problem_string, type, element_size));
     137             : }
     138             : 
     139     1325171 : RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) {
     140             :   SealHandleScope shs(isolate);
     141             :   DCHECK_EQ(0, args.length());
     142     1325171 :   return isolate->UnwindAndFindHandler();
     143             : }
     144             : 
     145         576 : RUNTIME_FUNCTION(Runtime_PromoteScheduledException) {
     146             :   SealHandleScope shs(isolate);
     147             :   DCHECK_EQ(0, args.length());
     148         576 :   return isolate->PromoteScheduledException();
     149             : }
     150             : 
     151       23932 : RUNTIME_FUNCTION(Runtime_ThrowReferenceError) {
     152       23932 :   HandleScope scope(isolate);
     153             :   DCHECK_EQ(1, args.length());
     154       23932 :   CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
     155       47864 :   THROW_NEW_ERROR_RETURN_FAILURE(
     156       23932 :       isolate, NewReferenceError(MessageTemplate::kNotDefined, name));
     157             : }
     158             : 
     159         153 : RUNTIME_FUNCTION(Runtime_NewTypeError) {
     160         153 :   HandleScope scope(isolate);
     161             :   DCHECK_EQ(2, args.length());
     162         306 :   CONVERT_INT32_ARG_CHECKED(template_index, 0);
     163         153 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
     164         153 :   MessageTemplate message_template = MessageTemplateFromInt(template_index);
     165         306 :   return *isolate->factory()->NewTypeError(message_template, arg0);
     166             : }
     167             : 
     168         117 : RUNTIME_FUNCTION(Runtime_NewReferenceError) {
     169         117 :   HandleScope scope(isolate);
     170             :   DCHECK_EQ(2, args.length());
     171         234 :   CONVERT_INT32_ARG_CHECKED(template_index, 0);
     172         117 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
     173         117 :   MessageTemplate message_template = MessageTemplateFromInt(template_index);
     174         234 :   return *isolate->factory()->NewReferenceError(message_template, arg0);
     175             : }
     176             : 
     177           0 : RUNTIME_FUNCTION(Runtime_NewSyntaxError) {
     178           0 :   HandleScope scope(isolate);
     179             :   DCHECK_EQ(2, args.length());
     180           0 :   CONVERT_INT32_ARG_CHECKED(template_index, 0);
     181           0 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
     182           0 :   MessageTemplate message_template = MessageTemplateFromInt(template_index);
     183           0 :   return *isolate->factory()->NewSyntaxError(message_template, arg0);
     184             : }
     185             : 
     186         191 : RUNTIME_FUNCTION(Runtime_ThrowInvalidStringLength) {
     187         191 :   HandleScope scope(isolate);
     188         382 :   THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError());
     189             : }
     190             : 
     191         360 : RUNTIME_FUNCTION(Runtime_ThrowIteratorResultNotAnObject) {
     192         360 :   HandleScope scope(isolate);
     193             :   DCHECK_EQ(1, args.length());
     194         360 :   CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
     195         720 :   THROW_NEW_ERROR_RETURN_FAILURE(
     196             :       isolate,
     197         360 :       NewTypeError(MessageTemplate::kIteratorResultNotAnObject, value));
     198             : }
     199             : 
     200           9 : RUNTIME_FUNCTION(Runtime_ThrowThrowMethodMissing) {
     201           9 :   HandleScope scope(isolate);
     202             :   DCHECK_EQ(0, args.length());
     203          18 :   THROW_NEW_ERROR_RETURN_FAILURE(
     204           9 :       isolate, NewTypeError(MessageTemplate::kThrowMethodMissing));
     205             : }
     206             : 
     207         261 : RUNTIME_FUNCTION(Runtime_ThrowSymbolIteratorInvalid) {
     208         261 :   HandleScope scope(isolate);
     209             :   DCHECK_EQ(0, args.length());
     210         522 :   THROW_NEW_ERROR_RETURN_FAILURE(
     211         261 :       isolate, NewTypeError(MessageTemplate::kSymbolIteratorInvalid));
     212             : }
     213             : 
     214        1086 : RUNTIME_FUNCTION(Runtime_ThrowNotConstructor) {
     215        1086 :   HandleScope scope(isolate);
     216             :   DCHECK_EQ(1, args.length());
     217        1086 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     218        2172 :   THROW_NEW_ERROR_RETURN_FAILURE(
     219        1086 :       isolate, NewTypeError(MessageTemplate::kNotConstructor, object));
     220             : }
     221             : 
     222        1284 : RUNTIME_FUNCTION(Runtime_ThrowApplyNonFunction) {
     223        1284 :   HandleScope scope(isolate);
     224             :   DCHECK_EQ(1, args.length());
     225        1284 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     226        1284 :   Handle<String> type = Object::TypeOf(isolate, object);
     227        2568 :   THROW_NEW_ERROR_RETURN_FAILURE(
     228        1284 :       isolate, NewTypeError(MessageTemplate::kApplyNonFunction, object, type));
     229             : }
     230             : 
     231       24371 : RUNTIME_FUNCTION(Runtime_StackGuard) {
     232             :   SealHandleScope shs(isolate);
     233             :   DCHECK_EQ(0, args.length());
     234             : 
     235             :   // First check if this is a real stack overflow.
     236       24371 :   StackLimitCheck check(isolate);
     237       24371 :   if (check.JsHasOverflowed()) {
     238         579 :     return isolate->StackOverflow();
     239             :   }
     240             : 
     241       23792 :   return isolate->stack_guard()->HandleInterrupts();
     242             : }
     243             : 
     244      149522 : RUNTIME_FUNCTION(Runtime_Interrupt) {
     245             :   SealHandleScope shs(isolate);
     246             :   DCHECK_EQ(0, args.length());
     247      149522 :   return isolate->stack_guard()->HandleInterrupts();
     248             : }
     249             : 
     250      162452 : RUNTIME_FUNCTION(Runtime_AllocateInNewSpace) {
     251      162452 :   HandleScope scope(isolate);
     252             :   DCHECK_EQ(1, args.length());
     253      324904 :   CONVERT_SMI_ARG_CHECKED(size, 0);
     254      162452 :   CHECK(IsAligned(size, kTaggedSize));
     255      162452 :   CHECK_GT(size, 0);
     256      162452 :   CHECK_LE(size, kMaxRegularHeapObjectSize);
     257      324904 :   return *isolate->factory()->NewFillerObject(size, false, NEW_SPACE);
     258             : }
     259             : 
     260       33548 : RUNTIME_FUNCTION(Runtime_AllocateInTargetSpace) {
     261       33548 :   HandleScope scope(isolate);
     262             :   DCHECK_EQ(2, args.length());
     263       67096 :   CONVERT_SMI_ARG_CHECKED(size, 0);
     264       67096 :   CONVERT_SMI_ARG_CHECKED(flags, 1);
     265       33548 :   CHECK(IsAligned(size, kTaggedSize));
     266       33548 :   CHECK_GT(size, 0);
     267       33548 :   bool double_align = AllocateDoubleAlignFlag::decode(flags);
     268       33548 :   AllocationSpace space = AllocateTargetSpace::decode(flags);
     269       33548 :   CHECK(size <= kMaxRegularHeapObjectSize || space == LO_SPACE);
     270       67096 :   return *isolate->factory()->NewFillerObject(size, double_align, space);
     271             : }
     272             : 
     273         207 : RUNTIME_FUNCTION(Runtime_AllocateSeqOneByteString) {
     274         207 :   HandleScope scope(isolate);
     275             :   DCHECK_EQ(1, args.length());
     276         414 :   CONVERT_SMI_ARG_CHECKED(length, 0);
     277         207 :   if (length == 0) return ReadOnlyRoots(isolate).empty_string();
     278             :   Handle<SeqOneByteString> result;
     279         414 :   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
     280             :       isolate, result, isolate->factory()->NewRawOneByteString(length));
     281         207 :   return *result;
     282             : }
     283             : 
     284           0 : RUNTIME_FUNCTION(Runtime_AllocateSeqTwoByteString) {
     285           0 :   HandleScope scope(isolate);
     286             :   DCHECK_EQ(1, args.length());
     287           0 :   CONVERT_SMI_ARG_CHECKED(length, 0);
     288           0 :   if (length == 0) return ReadOnlyRoots(isolate).empty_string();
     289             :   Handle<SeqTwoByteString> result;
     290           0 :   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
     291             :       isolate, result, isolate->factory()->NewRawTwoByteString(length));
     292           0 :   return *result;
     293             : }
     294             : 
     295             : namespace {
     296             : 
     297        7779 : bool ComputeLocation(Isolate* isolate, MessageLocation* target) {
     298        7779 :   JavaScriptFrameIterator it(isolate);
     299        7779 :   if (!it.done()) {
     300             :     // Compute the location from the function and the relocation info of the
     301             :     // baseline code. For optimized code this will use the deoptimization
     302             :     // information to get canonical location information.
     303             :     std::vector<FrameSummary> frames;
     304        7767 :     it.frame()->Summarize(&frames);
     305        7767 :     auto& summary = frames.back().AsJavaScript();
     306       15534 :     Handle<SharedFunctionInfo> shared(summary.function()->shared(), isolate);
     307       15534 :     Handle<Object> script(shared->script(), isolate);
     308        7767 :     int pos = summary.abstract_code()->SourcePosition(summary.code_offset());
     309       30231 :     if (script->IsScript() &&
     310       21627 :         !(Handle<Script>::cast(script)->source()->IsUndefined(isolate))) {
     311        6930 :       Handle<Script> casted_script = Handle<Script>::cast(script);
     312        6930 :       *target = MessageLocation(casted_script, pos, pos + 1, shared);
     313             :       return true;
     314         837 :     }
     315             :   }
     316             :   return false;
     317             : }
     318             : 
     319        1800 : Handle<String> BuildDefaultCallSite(Isolate* isolate, Handle<Object> object) {
     320        1800 :   IncrementalStringBuilder builder(isolate);
     321             : 
     322        1800 :   builder.AppendString(Object::TypeOf(isolate, object));
     323        3600 :   if (object->IsString()) {
     324             :     builder.AppendCString(" \"");
     325          36 :     builder.AppendString(Handle<String>::cast(object));
     326             :     builder.AppendCString("\"");
     327        3528 :   } else if (object->IsNull(isolate)) {
     328             :     builder.AppendCString(" ");
     329         486 :     builder.AppendString(isolate->factory()->null_string());
     330        2556 :   } else if (object->IsTrue(isolate)) {
     331             :     builder.AppendCString(" ");
     332          36 :     builder.AppendString(isolate->factory()->true_string());
     333        2484 :   } else if (object->IsFalse(isolate)) {
     334             :     builder.AppendCString(" ");
     335           0 :     builder.AppendString(isolate->factory()->false_string());
     336        2484 :   } else if (object->IsNumber()) {
     337             :     builder.AppendCString(" ");
     338         135 :     builder.AppendString(isolate->factory()->NumberToString(object));
     339             :   }
     340             : 
     341        3600 :   return builder.Finish().ToHandleChecked();
     342             : }
     343             : 
     344        7572 : Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object,
     345             :                               CallPrinter::ErrorHint* hint) {
     346        7572 :   MessageLocation location;
     347        7572 :   if (ComputeLocation(isolate, &location)) {
     348        6723 :     ParseInfo info(isolate, location.shared());
     349        6723 :     if (parsing::ParseAny(&info, location.shared(), isolate)) {
     350        6330 :       info.ast_value_factory()->Internalize(isolate);
     351        6330 :       CallPrinter printer(isolate, location.shared()->IsUserJavaScript());
     352        6330 :       Handle<String> str = printer.Print(info.literal(), location.start_pos());
     353        6330 :       *hint = printer.GetErrorHint();
     354        6330 :       if (str->length() > 0) return str;
     355             :     } else {
     356         393 :       isolate->clear_pending_exception();
     357         951 :     }
     358             :   }
     359        1800 :   return BuildDefaultCallSite(isolate, object);
     360             : }
     361             : 
     362        4281 : MessageTemplate UpdateErrorTemplate(CallPrinter::ErrorHint hint,
     363             :                                     MessageTemplate default_id) {
     364        4299 :   switch (hint) {
     365             :     case CallPrinter::ErrorHint::kNormalIterator:
     366             :       return MessageTemplate::kNotIterable;
     367             : 
     368             :     case CallPrinter::ErrorHint::kCallAndNormalIterator:
     369          54 :       return MessageTemplate::kNotCallableOrIterable;
     370             : 
     371             :     case CallPrinter::ErrorHint::kAsyncIterator:
     372           9 :       return MessageTemplate::kNotAsyncIterable;
     373             : 
     374             :     case CallPrinter::ErrorHint::kCallAndAsyncIterator:
     375           0 :       return MessageTemplate::kNotCallableOrAsyncIterable;
     376             : 
     377             :     case CallPrinter::ErrorHint::kNone:
     378        4191 :       return default_id;
     379             :   }
     380           0 :   return default_id;
     381             : }
     382             : 
     383             : }  // namespace
     384             : 
     385        1044 : MaybeHandle<Object> Runtime::ThrowIteratorError(Isolate* isolate,
     386             :                                                 Handle<Object> object) {
     387        1044 :   CallPrinter::ErrorHint hint = CallPrinter::kNone;
     388        1044 :   Handle<String> callsite = RenderCallSite(isolate, object, &hint);
     389             :   MessageTemplate id = MessageTemplate::kNotIterableNoSymbolLoad;
     390             : 
     391        1044 :   if (hint == CallPrinter::kNone) {
     392             :     Handle<Symbol> iterator_symbol = isolate->factory()->iterator_symbol();
     393        1026 :     THROW_NEW_ERROR(isolate, NewTypeError(id, callsite, iterator_symbol),
     394             :                     Object);
     395             :   }
     396             : 
     397             :   id = UpdateErrorTemplate(hint, id);
     398          18 :   THROW_NEW_ERROR(isolate, NewTypeError(id, callsite), Object);
     399             : }
     400             : 
     401         261 : RUNTIME_FUNCTION(Runtime_ThrowIteratorError) {
     402         261 :   HandleScope scope(isolate);
     403             :   DCHECK_EQ(1, args.length());
     404         261 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     405         522 :   RETURN_RESULT_OR_FAILURE(isolate,
     406         261 :                            Runtime::ThrowIteratorError(isolate, object));
     407             : }
     408             : 
     409        4281 : RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) {
     410        4281 :   HandleScope scope(isolate);
     411             :   DCHECK_EQ(1, args.length());
     412        4281 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     413        4281 :   CallPrinter::ErrorHint hint = CallPrinter::kNone;
     414        4281 :   Handle<String> callsite = RenderCallSite(isolate, object, &hint);
     415             :   MessageTemplate id = MessageTemplate::kCalledNonCallable;
     416        4281 :   id = UpdateErrorTemplate(hint, id);
     417        8562 :   THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(id, callsite));
     418             : }
     419             : 
     420        2247 : RUNTIME_FUNCTION(Runtime_ThrowConstructedNonConstructable) {
     421        2247 :   HandleScope scope(isolate);
     422             :   DCHECK_EQ(1, args.length());
     423        2247 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     424        2247 :   CallPrinter::ErrorHint hint = CallPrinter::kNone;
     425        2247 :   Handle<String> callsite = RenderCallSite(isolate, object, &hint);
     426             :   MessageTemplate id = MessageTemplate::kNotConstructor;
     427        4494 :   THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(id, callsite));
     428             : }
     429             : 
     430             : namespace {
     431             : 
     432             : // Helper visitor for ThrowPatternAssignmentNonCoercible which finds an
     433             : // object literal (representing a destructuring assignment) at a given source
     434             : // position.
     435             : class PatternFinder final : public AstTraversalVisitor<PatternFinder> {
     436             :  public:
     437         207 :   PatternFinder(Isolate* isolate, Expression* root, int position)
     438             :       : AstTraversalVisitor(isolate, root),
     439             :         position_(position),
     440         207 :         object_literal_(nullptr) {}
     441             : 
     442         207 :   ObjectLiteral* object_literal() const { return object_literal_; }
     443             : 
     444             :  private:
     445             :   // This is required so that the overriden Visit* methods can be
     446             :   // called by the base class (template).
     447             :   friend class AstTraversalVisitor<PatternFinder>;
     448             : 
     449         279 :   void VisitObjectLiteral(ObjectLiteral* lit) {
     450             :     // TODO(leszeks): This could be smarter in only traversing object literals
     451             :     // that are known to be a destructuring pattern. We could then also
     452             :     // potentially find the corresponding assignment value and report that too.
     453         279 :     if (lit->position() == position_) {
     454         207 :       object_literal_ = lit;
     455         486 :       return;
     456             :     }
     457          72 :     AstTraversalVisitor::VisitObjectLiteral(lit);
     458             :   }
     459             : 
     460             :   int position_;
     461             :   ObjectLiteral* object_literal_;
     462             : };
     463             : 
     464             : }  // namespace
     465             : 
     466         207 : RUNTIME_FUNCTION(Runtime_ThrowPatternAssignmentNonCoercible) {
     467         207 :   HandleScope scope(isolate);
     468             :   DCHECK_EQ(0, args.length());
     469             : 
     470             :   // Find the object literal representing the destructuring assignment, so that
     471             :   // we can try to attribute the error to a property name on it rather than to
     472             :   // the literal itself.
     473             :   MaybeHandle<String> maybe_property_name;
     474         207 :   MessageLocation location;
     475         207 :   if (ComputeLocation(isolate, &location)) {
     476         207 :     ParseInfo info(isolate, location.shared());
     477         207 :     if (parsing::ParseAny(&info, location.shared(), isolate)) {
     478         207 :       info.ast_value_factory()->Internalize(isolate);
     479             : 
     480         207 :       PatternFinder finder(isolate, info.literal(), location.start_pos());
     481         207 :       finder.Run();
     482         207 :       if (finder.object_literal()) {
     483          36 :         for (ObjectLiteralProperty* pattern_property :
     484         207 :              *finder.object_literal()->properties()) {
     485         117 :           Expression* key = pattern_property->key();
     486         117 :           if (key->IsPropertyName()) {
     487          81 :             int pos = key->position();
     488             :             maybe_property_name =
     489         162 :                 key->AsLiteral()->AsRawPropertyName()->string();
     490             :             // Change the message location to point at the property name.
     491             :             location = MessageLocation(location.script(), pos, pos + 1,
     492          81 :                                        location.shared());
     493             :             break;
     494             :           }
     495             :         }
     496             :       }
     497             :     } else {
     498           0 :       isolate->clear_pending_exception();
     499         207 :     }
     500             :   }
     501             : 
     502             :   // Create a "non-coercible" type error with a property name if one is
     503             :   // available, otherwise create a generic one.
     504             :   Handle<Object> error;
     505             :   Handle<String> property_name;
     506         207 :   if (maybe_property_name.ToHandle(&property_name)) {
     507             :     error = isolate->factory()->NewTypeError(
     508          81 :         MessageTemplate::kNonCoercibleWithProperty, property_name);
     509             :   } else {
     510         126 :     error = isolate->factory()->NewTypeError(MessageTemplate::kNonCoercible);
     511             :   }
     512             : 
     513             :   // Explicitly pass the calculated location, as we may have updated it to match
     514             :   // the property name.
     515         207 :   return isolate->Throw(*error, &location);
     516             : }
     517             : 
     518         522 : RUNTIME_FUNCTION(Runtime_ThrowConstructorReturnedNonObject) {
     519         522 :   HandleScope scope(isolate);
     520             :   DCHECK_EQ(0, args.length());
     521             : 
     522        1044 :   THROW_NEW_ERROR_RETURN_FAILURE(
     523             :       isolate,
     524         522 :       NewTypeError(MessageTemplate::kDerivedConstructorReturnedNonObject));
     525             : }
     526             : 
     527             : // ES6 section 7.3.17 CreateListFromArrayLike (obj)
     528       16538 : RUNTIME_FUNCTION(Runtime_CreateListFromArrayLike) {
     529       16538 :   HandleScope scope(isolate);
     530             :   DCHECK_EQ(1, args.length());
     531       16538 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     532       33076 :   RETURN_RESULT_OR_FAILURE(isolate, Object::CreateListFromArrayLike(
     533       16538 :                                         isolate, object, ElementTypes::kAll));
     534             : }
     535             : 
     536         630 : RUNTIME_FUNCTION(Runtime_IncrementUseCounter) {
     537         630 :   HandleScope scope(isolate);
     538             :   DCHECK_EQ(1, args.length());
     539        1260 :   CONVERT_SMI_ARG_CHECKED(counter, 0);
     540         630 :   isolate->CountUsage(static_cast<v8::Isolate::UseCounterFeature>(counter));
     541         630 :   return ReadOnlyRoots(isolate).undefined_value();
     542             : }
     543             : 
     544           0 : RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) {
     545           0 :   HandleScope scope(isolate);
     546             : 
     547             :   // Append any worker thread runtime call stats to the main table before
     548             :   // printing.
     549             :   isolate->counters()->worker_thread_runtime_call_stats()->AddToMainTable(
     550           0 :       isolate->counters()->runtime_call_stats());
     551             : 
     552           0 :   if (args.length() == 0) {
     553             :     // Without arguments, the result is returned as a string.
     554             :     DCHECK_EQ(0, args.length());
     555           0 :     std::stringstream stats_stream;
     556           0 :     isolate->counters()->runtime_call_stats()->Print(stats_stream);
     557             :     Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(
     558           0 :         stats_stream.str().c_str());
     559           0 :     isolate->counters()->runtime_call_stats()->Reset();
     560           0 :     return *result;
     561             :   } else {
     562             :     DCHECK_LE(args.length(), 2);
     563             :     std::FILE* f;
     564           0 :     if (args[0]->IsString()) {
     565             :       // With a string argument, the results are appended to that file.
     566           0 :       CONVERT_ARG_HANDLE_CHECKED(String, arg0, 0);
     567             :       DisallowHeapAllocation no_gc;
     568           0 :       String::FlatContent flat = arg0->GetFlatContent(no_gc);
     569             :       const char* filename =
     570           0 :           reinterpret_cast<const char*>(&(flat.ToOneByteVector()[0]));
     571           0 :       f = std::fopen(filename, "a");
     572             :       DCHECK_NOT_NULL(f);
     573             :     } else {
     574             :       // With an integer argument, the results are written to stdout/stderr.
     575           0 :       CONVERT_SMI_ARG_CHECKED(fd, 0);
     576             :       DCHECK(fd == 1 || fd == 2);
     577           0 :       f = fd == 1 ? stdout : stderr;
     578             :     }
     579             :     // The second argument (if any) is a message header to be printed.
     580           0 :     if (args.length() >= 2) {
     581           0 :       CONVERT_ARG_HANDLE_CHECKED(String, arg1, 1);
     582           0 :       arg1->PrintOn(f);
     583           0 :       std::fputc('\n', f);
     584           0 :       std::fflush(f);
     585             :     }
     586           0 :     OFStream stats_stream(f);
     587           0 :     isolate->counters()->runtime_call_stats()->Print(stats_stream);
     588           0 :     isolate->counters()->runtime_call_stats()->Reset();
     589           0 :     if (args[0]->IsString())
     590           0 :       std::fclose(f);
     591             :     else
     592           0 :       std::fflush(f);
     593           0 :     return ReadOnlyRoots(isolate).undefined_value();
     594           0 :   }
     595             : }
     596             : 
     597      107560 : RUNTIME_FUNCTION(Runtime_OrdinaryHasInstance) {
     598      107560 :   HandleScope scope(isolate);
     599             :   DCHECK_EQ(2, args.length());
     600      107560 :   CONVERT_ARG_HANDLE_CHECKED(Object, callable, 0);
     601      107560 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 1);
     602      215120 :   RETURN_RESULT_OR_FAILURE(
     603      107560 :       isolate, Object::OrdinaryHasInstance(isolate, callable, object));
     604             : }
     605             : 
     606          18 : RUNTIME_FUNCTION(Runtime_Typeof) {
     607          18 :   HandleScope scope(isolate);
     608             :   DCHECK_EQ(1, args.length());
     609          18 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     610          36 :   return *Object::TypeOf(isolate, object);
     611             : }
     612             : 
     613          54 : RUNTIME_FUNCTION(Runtime_AllowDynamicFunction) {
     614          54 :   HandleScope scope(isolate);
     615             :   DCHECK_EQ(1, args.length());
     616         108 :   CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0);
     617         108 :   Handle<JSObject> global_proxy(target->global_proxy(), isolate);
     618             :   return *isolate->factory()->ToBoolean(
     619         108 :       Builtins::AllowDynamicFunction(isolate, target, global_proxy));
     620             : }
     621             : 
     622         210 : RUNTIME_FUNCTION(Runtime_CreateAsyncFromSyncIterator) {
     623         210 :   HandleScope scope(isolate);
     624             :   DCHECK_EQ(1, args.length());
     625             : 
     626         210 :   CONVERT_ARG_HANDLE_CHECKED(Object, sync_iterator, 0);
     627             : 
     628         420 :   if (!sync_iterator->IsJSReceiver()) {
     629           0 :     THROW_NEW_ERROR_RETURN_FAILURE(
     630             :         isolate, NewTypeError(MessageTemplate::kSymbolIteratorInvalid));
     631             :   }
     632             : 
     633             :   Handle<Object> next;
     634         630 :   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
     635             :       isolate, next,
     636             :       Object::GetProperty(isolate, sync_iterator,
     637             :                           isolate->factory()->next_string()));
     638             : 
     639             :   return *isolate->factory()->NewJSAsyncFromSyncIterator(
     640         420 :       Handle<JSReceiver>::cast(sync_iterator), next);
     641             : }
     642             : 
     643        2560 : RUNTIME_FUNCTION(Runtime_CreateTemplateObject) {
     644        2560 :   HandleScope scope(isolate);
     645             :   DCHECK_EQ(1, args.length());
     646        5120 :   CONVERT_ARG_HANDLE_CHECKED(TemplateObjectDescription, description, 0);
     647             : 
     648        5120 :   return *TemplateObjectDescription::CreateTemplateObject(isolate, description);
     649             : }
     650             : 
     651          33 : RUNTIME_FUNCTION(Runtime_ReportMessage) {
     652             :   // Helper to report messages and continue JS execution. This is intended to
     653             :   // behave similarly to reporting exceptions which reach the top-level in
     654             :   // Execution.cc, but allow the JS code to continue. This is useful for
     655             :   // implementing algorithms such as RunMicrotasks in JS.
     656          33 :   HandleScope scope(isolate);
     657             :   DCHECK_EQ(1, args.length());
     658             : 
     659          33 :   CONVERT_ARG_HANDLE_CHECKED(Object, message_obj, 0);
     660             : 
     661             :   DCHECK(!isolate->has_pending_exception());
     662          33 :   isolate->set_pending_exception(*message_obj);
     663          33 :   isolate->ReportPendingMessagesFromJavaScript();
     664          33 :   isolate->clear_pending_exception();
     665          33 :   return ReadOnlyRoots(isolate).undefined_value();
     666             : }
     667             : 
     668          18 : RUNTIME_FUNCTION(Runtime_GetInitializerFunction) {
     669          18 :   HandleScope scope(isolate);
     670             :   DCHECK_EQ(1, args.length());
     671             : 
     672          36 :   CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0);
     673          18 :   Handle<Symbol> key = isolate->factory()->class_fields_symbol();
     674          18 :   Handle<Object> initializer = JSReceiver::GetDataProperty(constructor, key);
     675          18 :   return *initializer;
     676             : }
     677             : }  // namespace internal
     678      183867 : }  // namespace v8

Generated by: LCOV version 1.10