LCOV - code coverage report
Current view: top level - src/runtime - runtime-internal.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 259 322 80.4 %
Date: 2017-10-20 Functions: 48 105 45.7 %

          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 "src/runtime/runtime-utils.h"
       6             : 
       7             : #include <memory>
       8             : 
       9             : #include "src/arguments.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/debug/debug.h"
      15             : #include "src/frames-inl.h"
      16             : #include "src/isolate-inl.h"
      17             : #include "src/messages.h"
      18             : #include "src/parsing/parse-info.h"
      19             : #include "src/parsing/parsing.h"
      20             : #include "src/snapshot/snapshot.h"
      21             : 
      22             : namespace v8 {
      23             : namespace internal {
      24             : 
      25       33848 : RUNTIME_FUNCTION(Runtime_CheckIsBootstrapping) {
      26             :   SealHandleScope shs(isolate);
      27             :   DCHECK_EQ(0, args.length());
      28       16924 :   CHECK(isolate->bootstrapper()->IsActive());
      29       16924 :   return isolate->heap()->undefined_value();
      30             : }
      31             : 
      32         183 : RUNTIME_FUNCTION(Runtime_ExportFromRuntime) {
      33             :   HandleScope scope(isolate);
      34             :   DCHECK_EQ(1, args.length());
      35         122 :   CONVERT_ARG_HANDLE_CHECKED(JSObject, container, 0);
      36          61 :   CHECK(isolate->bootstrapper()->IsActive());
      37             :   JSObject::NormalizeProperties(container, KEEP_INOBJECT_PROPERTIES, 10,
      38          61 :                                 "ExportFromRuntime");
      39          61 :   Bootstrapper::ExportFromRuntime(isolate, container);
      40          61 :   JSObject::MigrateSlowToFast(container, 0, "ExportFromRuntime");
      41          61 :   return *container;
      42             : }
      43             : 
      44         366 : RUNTIME_FUNCTION(Runtime_InstallToContext) {
      45         122 :   HandleScope scope(isolate);
      46             :   DCHECK_EQ(1, args.length());
      47         244 :   CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
      48         122 :   CHECK(array->HasFastElements());
      49         122 :   CHECK(isolate->bootstrapper()->IsActive());
      50         122 :   Handle<Context> native_context = isolate->native_context();
      51         122 :   Handle<FixedArray> fixed_array(FixedArray::cast(array->elements()));
      52         122 :   int length = Smi::ToInt(array->length());
      53         732 :   for (int i = 0; i < length; i += 2) {
      54        1464 :     CHECK(fixed_array->get(i)->IsString());
      55         732 :     Handle<String> name(String::cast(fixed_array->get(i)));
      56        1464 :     CHECK(fixed_array->get(i + 1)->IsJSObject());
      57         732 :     Handle<JSObject> object(JSObject::cast(fixed_array->get(i + 1)));
      58         732 :     int index = Context::ImportedFieldIndexForName(name);
      59         732 :     if (index == Context::kNotFound) {
      60         122 :       index = Context::IntrinsicIndexForName(name);
      61             :     }
      62         732 :     CHECK_NE(index, Context::kNotFound);
      63         732 :     native_context->set(index, *object);
      64             :   }
      65         122 :   return isolate->heap()->undefined_value();
      66             : }
      67             : 
      68      365116 : RUNTIME_FUNCTION(Runtime_Throw) {
      69      182558 :   HandleScope scope(isolate);
      70             :   DCHECK_EQ(1, args.length());
      71      182558 :   return isolate->Throw(args[0]);
      72             : }
      73             : 
      74       46576 : RUNTIME_FUNCTION(Runtime_ReThrow) {
      75       23288 :   HandleScope scope(isolate);
      76             :   DCHECK_EQ(1, args.length());
      77       23288 :   return isolate->ReThrow(args[0]);
      78             : }
      79             : 
      80        2456 : RUNTIME_FUNCTION(Runtime_ThrowStackOverflow) {
      81             :   SealHandleScope shs(isolate);
      82             :   DCHECK_LE(0, args.length());
      83        1228 :   return isolate->StackOverflow();
      84             : }
      85             : 
      86           0 : RUNTIME_FUNCTION(Runtime_ThrowSymbolAsyncIteratorInvalid) {
      87           0 :   HandleScope scope(isolate);
      88             :   DCHECK_EQ(0, args.length());
      89           0 :   THROW_NEW_ERROR_RETURN_FAILURE(
      90           0 :       isolate, NewTypeError(MessageTemplate::kSymbolAsyncIteratorInvalid));
      91             : }
      92             : 
      93             : #define THROW_ERROR(isolate, args, call)                              \
      94             :   HandleScope scope(isolate);                                         \
      95             :   DCHECK_LE(1, args.length());                                        \
      96             :   CONVERT_SMI_ARG_CHECKED(message_id_smi, 0);                         \
      97             :                                                                       \
      98             :   Handle<Object> undefined = isolate->factory()->undefined_value();   \
      99             :   Handle<Object> arg0 = (args.length() > 1) ? args.at(1) : undefined; \
     100             :   Handle<Object> arg1 = (args.length() > 2) ? args.at(2) : undefined; \
     101             :   Handle<Object> arg2 = (args.length() > 3) ? args.at(3) : undefined; \
     102             :                                                                       \
     103             :   MessageTemplate::Template message_id =                              \
     104             :       static_cast<MessageTemplate::Template>(message_id_smi);         \
     105             :                                                                       \
     106             :   THROW_NEW_ERROR_RETURN_FAILURE(isolate, call(message_id, arg0, arg1, arg2));
     107             : 
     108        2194 : RUNTIME_FUNCTION(Runtime_ThrowRangeError) {
     109        3291 :   THROW_ERROR(isolate, args, NewRangeError);
     110             : }
     111             : 
     112       11672 : RUNTIME_FUNCTION(Runtime_ThrowTypeError) {
     113       17508 :   THROW_ERROR(isolate, args, NewTypeError);
     114             : }
     115             : 
     116             : #undef THROW_ERROR
     117             : 
     118             : namespace {
     119             : 
     120         560 : const char* ElementsKindToType(ElementsKind fixed_elements_kind) {
     121         560 :   switch (fixed_elements_kind) {
     122             : #define ELEMENTS_KIND_CASE(Type, type, TYPE, ctype, size) \
     123             :   case TYPE##_ELEMENTS:                                   \
     124             :     return #Type "Array";
     125             : 
     126           0 :     TYPED_ARRAYS(ELEMENTS_KIND_CASE)
     127             : #undef ELEMENTS_KIND_CASE
     128             : 
     129             :     default:
     130           0 :       UNREACHABLE();
     131             :   }
     132             : }
     133             : 
     134             : }  // namespace
     135             : 
     136        1120 : RUNTIME_FUNCTION(Runtime_ThrowInvalidTypedArrayAlignment) {
     137         560 :   HandleScope scope(isolate);
     138             :   DCHECK_EQ(2, args.length());
     139        1120 :   CONVERT_ARG_HANDLE_CHECKED(Map, map, 0);
     140        1120 :   CONVERT_ARG_HANDLE_CHECKED(String, problem_string, 1);
     141             : 
     142         560 :   ElementsKind kind = map->elements_kind();
     143             : 
     144             :   Handle<String> type =
     145         560 :       isolate->factory()->NewStringFromAsciiChecked(ElementsKindToType(kind));
     146             : 
     147             :   ExternalArrayType external_type =
     148         560 :       isolate->factory()->GetArrayTypeFromElementsKind(kind);
     149         560 :   size_t size = isolate->factory()->GetExternalArrayElementSize(external_type);
     150             :   Handle<Object> element_size =
     151         560 :       handle(Smi::FromInt(static_cast<int>(size)), isolate);
     152             : 
     153        1120 :   THROW_NEW_ERROR_RETURN_FAILURE(
     154             :       isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayAlignment,
     155         560 :                              problem_string, type, element_size));
     156             : }
     157             : 
     158     2167402 : RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) {
     159             :   SealHandleScope shs(isolate);
     160             :   DCHECK_EQ(0, args.length());
     161     1083701 :   return isolate->UnwindAndFindHandler();
     162             : }
     163             : 
     164        2628 : RUNTIME_FUNCTION(Runtime_PromoteScheduledException) {
     165             :   SealHandleScope shs(isolate);
     166             :   DCHECK_EQ(0, args.length());
     167        1314 :   return isolate->PromoteScheduledException();
     168             : }
     169             : 
     170       47276 : RUNTIME_FUNCTION(Runtime_ThrowReferenceError) {
     171       23638 :   HandleScope scope(isolate);
     172             :   DCHECK_EQ(1, args.length());
     173       23638 :   CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
     174       47276 :   THROW_NEW_ERROR_RETURN_FAILURE(
     175       23638 :       isolate, NewReferenceError(MessageTemplate::kNotDefined, name));
     176             : }
     177             : 
     178         588 : RUNTIME_FUNCTION(Runtime_NewTypeError) {
     179         294 :   HandleScope scope(isolate);
     180             :   DCHECK_EQ(2, args.length());
     181         588 :   CONVERT_INT32_ARG_CHECKED(template_index, 0);
     182         294 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
     183             :   auto message_template =
     184         294 :       static_cast<MessageTemplate::Template>(template_index);
     185         588 :   return *isolate->factory()->NewTypeError(message_template, arg0);
     186             : }
     187             : 
     188         246 : RUNTIME_FUNCTION(Runtime_NewReferenceError) {
     189         123 :   HandleScope scope(isolate);
     190             :   DCHECK_EQ(2, args.length());
     191         246 :   CONVERT_INT32_ARG_CHECKED(template_index, 0);
     192         123 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
     193             :   auto message_template =
     194         123 :       static_cast<MessageTemplate::Template>(template_index);
     195         246 :   return *isolate->factory()->NewReferenceError(message_template, arg0);
     196             : }
     197             : 
     198           0 : RUNTIME_FUNCTION(Runtime_NewSyntaxError) {
     199           0 :   HandleScope scope(isolate);
     200             :   DCHECK_EQ(2, args.length());
     201           0 :   CONVERT_INT32_ARG_CHECKED(template_index, 0);
     202           0 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
     203             :   auto message_template =
     204           0 :       static_cast<MessageTemplate::Template>(template_index);
     205           0 :   return *isolate->factory()->NewSyntaxError(message_template, arg0);
     206             : }
     207             : 
     208         400 : RUNTIME_FUNCTION(Runtime_ThrowCannotConvertToPrimitive) {
     209         200 :   HandleScope scope(isolate);
     210         400 :   THROW_NEW_ERROR_RETURN_FAILURE(
     211         200 :       isolate, NewTypeError(MessageTemplate::kCannotConvertToPrimitive));
     212             : }
     213             : 
     214        6284 : RUNTIME_FUNCTION(Runtime_ThrowIncompatibleMethodReceiver) {
     215        3142 :   HandleScope scope(isolate);
     216             :   DCHECK_EQ(2, args.length());
     217        3142 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 0);
     218        3142 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg1, 1);
     219        6284 :   THROW_NEW_ERROR_RETURN_FAILURE(
     220             :       isolate,
     221        3142 :       NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, arg0, arg1));
     222             : }
     223             : 
     224           0 : RUNTIME_FUNCTION(Runtime_ThrowInvalidHint) {
     225           0 :   HandleScope scope(isolate);
     226             :   DCHECK_EQ(1, args.length());
     227           0 :   CONVERT_ARG_HANDLE_CHECKED(Object, hint, 0);
     228           0 :   THROW_NEW_ERROR_RETURN_FAILURE(
     229           0 :       isolate, NewTypeError(MessageTemplate::kInvalidHint, hint));
     230             : }
     231             : 
     232         232 : RUNTIME_FUNCTION(Runtime_ThrowInvalidStringLength) {
     233         116 :   HandleScope scope(isolate);
     234         232 :   THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError());
     235             : }
     236             : 
     237         560 : RUNTIME_FUNCTION(Runtime_ThrowIteratorResultNotAnObject) {
     238         280 :   HandleScope scope(isolate);
     239             :   DCHECK_EQ(1, args.length());
     240         280 :   CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
     241         560 :   THROW_NEW_ERROR_RETURN_FAILURE(
     242             :       isolate,
     243         280 :       NewTypeError(MessageTemplate::kIteratorResultNotAnObject, value));
     244             : }
     245             : 
     246          18 : RUNTIME_FUNCTION(Runtime_ThrowThrowMethodMissing) {
     247           9 :   HandleScope scope(isolate);
     248             :   DCHECK_EQ(0, args.length());
     249          18 :   THROW_NEW_ERROR_RETURN_FAILURE(
     250           9 :       isolate, NewTypeError(MessageTemplate::kThrowMethodMissing));
     251             : }
     252             : 
     253          72 : RUNTIME_FUNCTION(Runtime_ThrowSymbolIteratorInvalid) {
     254          36 :   HandleScope scope(isolate);
     255             :   DCHECK_EQ(0, args.length());
     256          72 :   THROW_NEW_ERROR_RETURN_FAILURE(
     257          36 :       isolate, NewTypeError(MessageTemplate::kSymbolIteratorInvalid));
     258             : }
     259             : 
     260        1390 : RUNTIME_FUNCTION(Runtime_ThrowNonCallableInInstanceOfCheck) {
     261         695 :   HandleScope scope(isolate);
     262        1390 :   THROW_NEW_ERROR_RETURN_FAILURE(
     263         695 :       isolate, NewTypeError(MessageTemplate::kNonCallableInInstanceOfCheck));
     264             : }
     265             : 
     266         872 : RUNTIME_FUNCTION(Runtime_ThrowNonObjectInInstanceOfCheck) {
     267         436 :   HandleScope scope(isolate);
     268         872 :   THROW_NEW_ERROR_RETURN_FAILURE(
     269         436 :       isolate, NewTypeError(MessageTemplate::kNonObjectInInstanceOfCheck));
     270             : }
     271             : 
     272        1730 : RUNTIME_FUNCTION(Runtime_ThrowNotConstructor) {
     273         865 :   HandleScope scope(isolate);
     274             :   DCHECK_EQ(1, args.length());
     275         865 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     276        1730 :   THROW_NEW_ERROR_RETURN_FAILURE(
     277         865 :       isolate, NewTypeError(MessageTemplate::kNotConstructor, object));
     278             : }
     279             : 
     280         218 : RUNTIME_FUNCTION(Runtime_ThrowGeneratorRunning) {
     281         109 :   HandleScope scope(isolate);
     282             :   DCHECK_EQ(0, args.length());
     283         218 :   THROW_NEW_ERROR_RETURN_FAILURE(
     284         109 :       isolate, NewTypeError(MessageTemplate::kGeneratorRunning));
     285             : }
     286             : 
     287        2616 : RUNTIME_FUNCTION(Runtime_ThrowApplyNonFunction) {
     288        1308 :   HandleScope scope(isolate);
     289             :   DCHECK_EQ(1, args.length());
     290        1308 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     291        1308 :   Handle<String> type = Object::TypeOf(isolate, object);
     292        2616 :   THROW_NEW_ERROR_RETURN_FAILURE(
     293        1308 :       isolate, NewTypeError(MessageTemplate::kApplyNonFunction, object, type));
     294             : }
     295             : 
     296      259548 : RUNTIME_FUNCTION(Runtime_StackGuard) {
     297             :   SealHandleScope shs(isolate);
     298             :   DCHECK_EQ(0, args.length());
     299             : 
     300             :   // First check if this is a real stack overflow.
     301      129774 :   StackLimitCheck check(isolate);
     302      129774 :   if (check.JsHasOverflowed()) {
     303        1460 :     return isolate->StackOverflow();
     304             :   }
     305             : 
     306      128314 :   return isolate->stack_guard()->HandleInterrupts();
     307             : }
     308             : 
     309      322752 : RUNTIME_FUNCTION(Runtime_Interrupt) {
     310             :   SealHandleScope shs(isolate);
     311             :   DCHECK_EQ(0, args.length());
     312      161376 :   return isolate->stack_guard()->HandleInterrupts();
     313             : }
     314             : 
     315      237486 : RUNTIME_FUNCTION(Runtime_AllocateInNewSpace) {
     316      118743 :   HandleScope scope(isolate);
     317             :   DCHECK_EQ(1, args.length());
     318      237486 :   CONVERT_SMI_ARG_CHECKED(size, 0);
     319      118743 :   CHECK(IsAligned(size, kPointerSize));
     320      118743 :   CHECK_GT(size, 0);
     321      118743 :   CHECK_LE(size, kMaxRegularHeapObjectSize);
     322      237486 :   return *isolate->factory()->NewFillerObject(size, false, NEW_SPACE);
     323             : }
     324             : 
     325       61038 : RUNTIME_FUNCTION(Runtime_AllocateInTargetSpace) {
     326       30519 :   HandleScope scope(isolate);
     327             :   DCHECK_EQ(2, args.length());
     328       61038 :   CONVERT_SMI_ARG_CHECKED(size, 0);
     329       61038 :   CONVERT_SMI_ARG_CHECKED(flags, 1);
     330       30519 :   CHECK(IsAligned(size, kPointerSize));
     331       30519 :   CHECK_GT(size, 0);
     332       30519 :   bool double_align = AllocateDoubleAlignFlag::decode(flags);
     333       30519 :   AllocationSpace space = AllocateTargetSpace::decode(flags);
     334       30519 :   CHECK(size <= kMaxRegularHeapObjectSize || space == LO_SPACE);
     335       61038 :   return *isolate->factory()->NewFillerObject(size, double_align, space);
     336             : }
     337             : 
     338           0 : RUNTIME_FUNCTION(Runtime_AllocateSeqOneByteString) {
     339           0 :   HandleScope scope(isolate);
     340             :   DCHECK_EQ(1, args.length());
     341           0 :   CONVERT_SMI_ARG_CHECKED(length, 0);
     342           0 :   if (length == 0) return isolate->heap()->empty_string();
     343             :   Handle<SeqOneByteString> result;
     344           0 :   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
     345             :       isolate, result, isolate->factory()->NewRawOneByteString(length));
     346           0 :   return *result;
     347             : }
     348             : 
     349           0 : RUNTIME_FUNCTION(Runtime_AllocateSeqTwoByteString) {
     350           0 :   HandleScope scope(isolate);
     351             :   DCHECK_EQ(1, args.length());
     352           0 :   CONVERT_SMI_ARG_CHECKED(length, 0);
     353           0 :   if (length == 0) return isolate->heap()->empty_string();
     354             :   Handle<SeqTwoByteString> result;
     355           0 :   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
     356             :       isolate, result, isolate->factory()->NewRawTwoByteString(length));
     357           0 :   return *result;
     358             : }
     359             : 
     360           0 : RUNTIME_FUNCTION(Runtime_IS_VAR) {
     361           0 :   UNREACHABLE();  // implemented as macro in the parser
     362             : }
     363             : 
     364             : namespace {
     365             : 
     366        7833 : bool ComputeLocation(Isolate* isolate, MessageLocation* target) {
     367        7833 :   JavaScriptFrameIterator it(isolate);
     368        7833 :   if (!it.done()) {
     369             :     // Compute the location from the function and the relocation info of the
     370             :     // baseline code. For optimized code this will use the deoptimization
     371             :     // information to get canonical location information.
     372             :     std::vector<FrameSummary> frames;
     373        7815 :     frames.reserve(FLAG_max_inlining_levels + 1);
     374        7815 :     it.frame()->Summarize(&frames);
     375        7815 :     auto& summary = frames.back().AsJavaScript();
     376             :     Handle<SharedFunctionInfo> shared(summary.function()->shared());
     377             :     Handle<Object> script(shared->script(), isolate);
     378        7815 :     int pos = summary.abstract_code()->SourcePosition(summary.code_offset());
     379       15319 :     if (script->IsScript() &&
     380             :         !(Handle<Script>::cast(script)->source()->IsUndefined(isolate))) {
     381        7504 :       Handle<Script> casted_script = Handle<Script>::cast(script);
     382        7504 :       *target = MessageLocation(casted_script, pos, pos + 1, shared);
     383             :       return true;
     384         311 :     }
     385             :   }
     386             :   return false;
     387             : }
     388             : 
     389        7833 : Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object,
     390             :                               CallPrinter::ErrorHint* hint) {
     391        7833 :   MessageLocation location;
     392        7833 :   if (ComputeLocation(isolate, &location)) {
     393        7504 :     ParseInfo info(location.shared());
     394        7504 :     if (parsing::ParseAny(&info, location.shared(), isolate)) {
     395        7060 :       info.ast_value_factory()->Internalize(isolate);
     396        7060 :       CallPrinter printer(isolate, location.shared()->IsUserJavaScript());
     397        7060 :       Handle<String> str = printer.Print(info.literal(), location.start_pos());
     398        7060 :       *hint = printer.GetErrorHint();
     399        7060 :       if (str->length() > 0) return str;
     400             :     } else {
     401             :       isolate->clear_pending_exception();
     402        1495 :     }
     403             :   }
     404        1824 :   return Object::TypeOf(isolate, object);
     405             : }
     406             : 
     407        4630 : MessageTemplate::Template UpdateErrorTemplate(
     408             :     CallPrinter::ErrorHint hint, MessageTemplate::Template default_id) {
     409        4722 :   switch (hint) {
     410             :     case CallPrinter::ErrorHint::kNormalIterator:
     411             :       return MessageTemplate::kNotIterable;
     412             : 
     413             :     case CallPrinter::ErrorHint::kCallAndNormalIterator:
     414          99 :       return MessageTemplate::kNotCallableOrIterable;
     415             : 
     416             :     case CallPrinter::ErrorHint::kAsyncIterator:
     417           9 :       return MessageTemplate::kNotAsyncIterable;
     418             : 
     419             :     case CallPrinter::ErrorHint::kCallAndAsyncIterator:
     420           0 :       return MessageTemplate::kNotCallableOrAsyncIterable;
     421             : 
     422             :     case CallPrinter::ErrorHint::kNone:
     423        4441 :       return default_id;
     424             :   }
     425           0 :   return default_id;
     426             : }
     427             : 
     428             : }  // namespace
     429             : 
     430         202 : MaybeHandle<Object> Runtime::ThrowIteratorError(Isolate* isolate,
     431             :                                                 Handle<Object> object) {
     432         202 :   CallPrinter::ErrorHint hint = CallPrinter::kNone;
     433         202 :   Handle<String> callsite = RenderCallSite(isolate, object, &hint);
     434             :   MessageTemplate::Template id = MessageTemplate::kNonObjectPropertyLoad;
     435             : 
     436         202 :   if (hint == CallPrinter::kNone) {
     437             :     Handle<Symbol> iterator_symbol = isolate->factory()->iterator_symbol();
     438         220 :     THROW_NEW_ERROR(isolate, NewTypeError(id, iterator_symbol, callsite),
     439             :                     Object);
     440             :   }
     441             : 
     442             :   id = UpdateErrorTemplate(hint, id);
     443         184 :   THROW_NEW_ERROR(isolate, NewTypeError(id, callsite), Object);
     444             : }
     445             : 
     446        9260 : RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) {
     447        4630 :   HandleScope scope(isolate);
     448             :   DCHECK_EQ(1, args.length());
     449        4630 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     450        4630 :   CallPrinter::ErrorHint hint = CallPrinter::kNone;
     451        4630 :   Handle<String> callsite = RenderCallSite(isolate, object, &hint);
     452             :   MessageTemplate::Template id = MessageTemplate::kCalledNonCallable;
     453        4630 :   id = UpdateErrorTemplate(hint, id);
     454        9260 :   THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(id, callsite));
     455             : }
     456             : 
     457        4960 : RUNTIME_FUNCTION(Runtime_ThrowCalledOnNullOrUndefined) {
     458        2480 :   HandleScope scope(isolate);
     459             :   DCHECK_EQ(1, args.length());
     460        4960 :   CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
     461        4960 :   THROW_NEW_ERROR_RETURN_FAILURE(
     462        2480 :       isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, name));
     463             : }
     464             : 
     465        6002 : RUNTIME_FUNCTION(Runtime_ThrowConstructedNonConstructable) {
     466        3001 :   HandleScope scope(isolate);
     467             :   DCHECK_EQ(1, args.length());
     468        3001 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     469        3001 :   CallPrinter::ErrorHint hint = CallPrinter::kNone;
     470        3001 :   Handle<String> callsite = RenderCallSite(isolate, object, &hint);
     471             :   MessageTemplate::Template id = MessageTemplate::kNotConstructor;
     472        6002 :   THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(id, callsite));
     473             : }
     474             : 
     475        2992 : RUNTIME_FUNCTION(Runtime_ThrowConstructorReturnedNonObject) {
     476        1496 :   HandleScope scope(isolate);
     477             :   DCHECK_EQ(0, args.length());
     478        1496 :   if (FLAG_harmony_restrict_constructor_return) {
     479        1980 :     THROW_NEW_ERROR_RETURN_FAILURE(
     480             :         isolate,
     481             :         NewTypeError(MessageTemplate::kClassConstructorReturnedNonObject));
     482             :   }
     483             : 
     484        1012 :   THROW_NEW_ERROR_RETURN_FAILURE(
     485             :       isolate,
     486        1496 :       NewTypeError(MessageTemplate::kDerivedConstructorReturnedNonObject));
     487             : }
     488             : 
     489        6412 : RUNTIME_FUNCTION(Runtime_ThrowUndefinedOrNullToObject) {
     490        3206 :   HandleScope scope(isolate);
     491             :   DCHECK_EQ(1, args.length());
     492        6412 :   CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
     493        6412 :   THROW_NEW_ERROR_RETURN_FAILURE(
     494        3206 :       isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject, name));
     495             : }
     496             : 
     497             : // ES6 section 7.3.17 CreateListFromArrayLike (obj)
     498       32894 : RUNTIME_FUNCTION(Runtime_CreateListFromArrayLike) {
     499       16447 :   HandleScope scope(isolate);
     500             :   DCHECK_EQ(1, args.length());
     501       16447 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     502       32894 :   RETURN_RESULT_OR_FAILURE(isolate, Object::CreateListFromArrayLike(
     503       16447 :                                         isolate, object, ElementTypes::kAll));
     504             : }
     505             : 
     506      201524 : RUNTIME_FUNCTION(Runtime_DeserializeLazy) {
     507      100762 :   HandleScope scope(isolate);
     508             :   DCHECK_EQ(1, args.length());
     509      201524 :   CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
     510             : 
     511             :   DCHECK(FLAG_lazy_deserialization);
     512             : 
     513      100762 :   Handle<SharedFunctionInfo> shared(function->shared(), isolate);
     514      100762 :   int builtin_id = shared->lazy_deserialization_builtin_id();
     515             : 
     516             :   // At this point, the builtins table should definitely have DeserializeLazy
     517             :   // set at the position of the target builtin. Also, we should never lazily
     518             :   // deserialize DeserializeLazy.
     519             : 
     520             :   DCHECK_NE(Builtins::kDeserializeLazy, builtin_id);
     521             :   DCHECK_EQ(Builtins::kDeserializeLazy,
     522             :             isolate->builtins()->builtin(builtin_id)->builtin_index());
     523             : 
     524             :   // The DeserializeLazy builtin tail-calls the deserialized builtin. This only
     525             :   // works with JS-linkage.
     526             :   DCHECK(Builtins::IsLazy(builtin_id));
     527             :   DCHECK_EQ(Builtins::TFJ, Builtins::KindOf(builtin_id));
     528             : 
     529      100762 :   if (FLAG_trace_lazy_deserialization) {
     530           0 :     PrintF("Lazy-deserializing %s\n", Builtins::name(builtin_id));
     531             :   }
     532             : 
     533      100762 :   Code* code = Snapshot::DeserializeBuiltin(isolate, builtin_id);
     534             :   DCHECK_EQ(builtin_id, code->builtin_index());
     535             :   DCHECK_EQ(code, isolate->builtins()->builtin(builtin_id));
     536      100762 :   shared->set_code(code);
     537      100762 :   function->set_code(code);
     538             : 
     539      100762 :   return code;
     540             : }
     541             : 
     542        1178 : RUNTIME_FUNCTION(Runtime_IncrementUseCounter) {
     543         589 :   HandleScope scope(isolate);
     544             :   DCHECK_EQ(1, args.length());
     545        1178 :   CONVERT_SMI_ARG_CHECKED(counter, 0);
     546         589 :   isolate->CountUsage(static_cast<v8::Isolate::UseCounterFeature>(counter));
     547         589 :   return isolate->heap()->undefined_value();
     548             : }
     549             : 
     550        1384 : RUNTIME_FUNCTION(
     551             :     Runtime_IncrementUseCounterConstructorReturnNonUndefinedPrimitive) {
     552         692 :   HandleScope scope(isolate);
     553             :   DCHECK_EQ(0, args.length());
     554             :   isolate->CountUsage(
     555         692 :       v8::Isolate::UseCounterFeature::kConstructorNonUndefinedPrimitiveReturn);
     556         692 :   return isolate->heap()->undefined_value();
     557             : }
     558             : 
     559           0 : RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) {
     560           0 :   HandleScope scope(isolate);
     561           0 :   if (args.length() == 0) {
     562             :     // Without arguments, the result is returned as a string.
     563             :     DCHECK_EQ(0, args.length());
     564           0 :     std::stringstream stats_stream;
     565           0 :     isolate->counters()->runtime_call_stats()->Print(stats_stream);
     566             :     Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(
     567           0 :         stats_stream.str().c_str());
     568           0 :     isolate->counters()->runtime_call_stats()->Reset();
     569           0 :     return *result;
     570             :   } else {
     571             :     DCHECK_LE(args.length(), 2);
     572             :     std::FILE* f;
     573           0 :     if (args[0]->IsString()) {
     574             :       // With a string argument, the results are appended to that file.
     575           0 :       CONVERT_ARG_HANDLE_CHECKED(String, arg0, 0);
     576           0 :       String::FlatContent flat = arg0->GetFlatContent();
     577             :       const char* filename =
     578           0 :           reinterpret_cast<const char*>(&(flat.ToOneByteVector()[0]));
     579           0 :       f = std::fopen(filename, "a");
     580             :       DCHECK_NOT_NULL(f);
     581             :     } else {
     582             :       // With an integer argument, the results are written to stdout/stderr.
     583           0 :       CONVERT_SMI_ARG_CHECKED(fd, 0);
     584             :       DCHECK(fd == 1 || fd == 2);
     585           0 :       f = fd == 1 ? stdout : stderr;
     586             :     }
     587             :     // The second argument (if any) is a message header to be printed.
     588           0 :     if (args.length() >= 2) {
     589           0 :       CONVERT_ARG_HANDLE_CHECKED(String, arg1, 1);
     590           0 :       arg1->PrintOn(f);
     591           0 :       std::fputc('\n', f);
     592           0 :       std::fflush(f);
     593             :     }
     594           0 :     OFStream stats_stream(f);
     595           0 :     isolate->counters()->runtime_call_stats()->Print(stats_stream);
     596           0 :     isolate->counters()->runtime_call_stats()->Reset();
     597           0 :     if (args[0]->IsString())
     598           0 :       std::fclose(f);
     599             :     else
     600           0 :       std::fflush(f);
     601           0 :     return isolate->heap()->undefined_value();
     602           0 :   }
     603             : }
     604             : 
     605      239308 : RUNTIME_FUNCTION(Runtime_OrdinaryHasInstance) {
     606      119654 :   HandleScope scope(isolate);
     607             :   DCHECK_EQ(2, args.length());
     608      119654 :   CONVERT_ARG_HANDLE_CHECKED(Object, callable, 0);
     609      119654 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 1);
     610      239308 :   RETURN_RESULT_OR_FAILURE(
     611      119654 :       isolate, Object::OrdinaryHasInstance(isolate, callable, object));
     612             : }
     613             : 
     614          36 : RUNTIME_FUNCTION(Runtime_Typeof) {
     615          18 :   HandleScope scope(isolate);
     616             :   DCHECK_EQ(1, args.length());
     617          18 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     618          36 :   return *Object::TypeOf(isolate, object);
     619             : }
     620             : 
     621         112 : RUNTIME_FUNCTION(Runtime_AllowDynamicFunction) {
     622          56 :   HandleScope scope(isolate);
     623             :   DCHECK_EQ(1, args.length());
     624         112 :   CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0);
     625          56 :   Handle<JSObject> global_proxy(target->global_proxy(), isolate);
     626             :   return *isolate->factory()->ToBoolean(
     627         112 :       Builtins::AllowDynamicFunction(isolate, target, global_proxy));
     628             : }
     629             : 
     630         420 : RUNTIME_FUNCTION(Runtime_CreateAsyncFromSyncIterator) {
     631         210 :   HandleScope scope(isolate);
     632             :   DCHECK_EQ(1, args.length());
     633             : 
     634         210 :   CONVERT_ARG_HANDLE_CHECKED(Object, sync_iterator, 0);
     635             : 
     636         210 :   if (!sync_iterator->IsJSReceiver()) {
     637           0 :     THROW_NEW_ERROR_RETURN_FAILURE(
     638             :         isolate, NewTypeError(MessageTemplate::kSymbolIteratorInvalid));
     639             :   }
     640             : 
     641             :   return *isolate->factory()->NewJSAsyncFromSyncIterator(
     642         420 :       Handle<JSReceiver>::cast(sync_iterator));
     643             : }
     644             : 
     645        4620 : RUNTIME_FUNCTION(Runtime_GetTemplateObject) {
     646        2310 :   HandleScope scope(isolate);
     647             :   DCHECK_EQ(1, args.length());
     648        4620 :   CONVERT_ARG_HANDLE_CHECKED(TemplateObjectDescription, description, 0);
     649             : 
     650             :   return *TemplateObjectDescription::GetTemplateObject(
     651        4620 :       description, isolate->native_context());
     652             : }
     653             : 
     654             : }  // namespace internal
     655             : }  // namespace v8

Generated by: LCOV version 1.10