LCOV - code coverage report
Current view: top level - src/runtime - runtime-internal.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 218 286 76.2 %
Date: 2017-04-26 Functions: 41 97 42.3 %

          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/wasm/wasm-module.h"
      21             : 
      22             : namespace v8 {
      23             : namespace internal {
      24             : 
      25       52756 : RUNTIME_FUNCTION(Runtime_CheckIsBootstrapping) {
      26             :   SealHandleScope shs(isolate);
      27             :   DCHECK_EQ(0, args.length());
      28       26378 :   CHECK(isolate->bootstrapper()->IsActive());
      29       26378 :   return isolate->heap()->undefined_value();
      30             : }
      31             : 
      32             : 
      33         237 : RUNTIME_FUNCTION(Runtime_ExportFromRuntime) {
      34          79 :   HandleScope scope(isolate);
      35             :   DCHECK_EQ(1, args.length());
      36         158 :   CONVERT_ARG_HANDLE_CHECKED(JSObject, container, 0);
      37          79 :   CHECK(isolate->bootstrapper()->IsActive());
      38             :   JSObject::NormalizeProperties(container, KEEP_INOBJECT_PROPERTIES, 10,
      39          79 :                                 "ExportFromRuntime");
      40          79 :   Bootstrapper::ExportFromRuntime(isolate, container);
      41          79 :   JSObject::MigrateSlowToFast(container, 0, "ExportFromRuntime");
      42          79 :   return *container;
      43             : }
      44             : 
      45             : 
      46         948 : RUNTIME_FUNCTION(Runtime_InstallToContext) {
      47         316 :   HandleScope scope(isolate);
      48             :   DCHECK_EQ(1, args.length());
      49         632 :   CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
      50         316 :   CHECK(array->HasFastElements());
      51         316 :   CHECK(isolate->bootstrapper()->IsActive());
      52         316 :   Handle<Context> native_context = isolate->native_context();
      53         316 :   Handle<FixedArray> fixed_array(FixedArray::cast(array->elements()));
      54         316 :   int length = Smi::cast(array->length())->value();
      55        1501 :   for (int i = 0; i < length; i += 2) {
      56        1501 :     CHECK(fixed_array->get(i)->IsString());
      57        1501 :     Handle<String> name(String::cast(fixed_array->get(i)));
      58        4503 :     CHECK(fixed_array->get(i + 1)->IsJSObject());
      59        1501 :     Handle<JSObject> object(JSObject::cast(fixed_array->get(i + 1)));
      60        1501 :     int index = Context::ImportedFieldIndexForName(name);
      61        1501 :     if (index == Context::kNotFound) {
      62         237 :       index = Context::IntrinsicIndexForName(name);
      63             :     }
      64        1501 :     CHECK(index != Context::kNotFound);
      65        1501 :     native_context->set(index, *object);
      66             :   }
      67         316 :   return isolate->heap()->undefined_value();
      68             : }
      69             : 
      70             : 
      71      581792 : RUNTIME_FUNCTION(Runtime_Throw) {
      72      290896 :   HandleScope scope(isolate);
      73             :   DCHECK_EQ(1, args.length());
      74      290896 :   return isolate->Throw(args[0]);
      75             : }
      76             : 
      77             : 
      78       45180 : RUNTIME_FUNCTION(Runtime_ReThrow) {
      79       22590 :   HandleScope scope(isolate);
      80             :   DCHECK_EQ(1, args.length());
      81       22590 :   return isolate->ReThrow(args[0]);
      82             : }
      83             : 
      84             : 
      85        2694 : RUNTIME_FUNCTION(Runtime_ThrowStackOverflow) {
      86             :   SealHandleScope shs(isolate);
      87             :   DCHECK_LE(0, args.length());
      88        1347 :   return isolate->StackOverflow();
      89             : }
      90             : 
      91           0 : RUNTIME_FUNCTION(Runtime_ThrowSymbolAsyncIteratorInvalid) {
      92           0 :   HandleScope scope(isolate);
      93             :   DCHECK_EQ(0, args.length());
      94           0 :   THROW_NEW_ERROR_RETURN_FAILURE(
      95           0 :       isolate, NewTypeError(MessageTemplate::kSymbolAsyncIteratorInvalid));
      96             : }
      97             : 
      98             : #define THROW_ERROR(isolate, args, call)                              \
      99             :   HandleScope scope(isolate);                                         \
     100             :   DCHECK_LE(1, args.length());                                        \
     101             :   CONVERT_SMI_ARG_CHECKED(message_id_smi, 0);                         \
     102             :                                                                       \
     103             :   Handle<Object> undefined = isolate->factory()->undefined_value();   \
     104             :   Handle<Object> arg0 = (args.length() > 1) ? args.at(1) : undefined; \
     105             :   Handle<Object> arg1 = (args.length() > 2) ? args.at(2) : undefined; \
     106             :   Handle<Object> arg2 = (args.length() > 3) ? args.at(3) : undefined; \
     107             :                                                                       \
     108             :   MessageTemplate::Template message_id =                              \
     109             :       static_cast<MessageTemplate::Template>(message_id_smi);         \
     110             :                                                                       \
     111             :   THROW_NEW_ERROR_RETURN_FAILURE(isolate, call(message_id, arg0, arg1, arg2));
     112             : 
     113        3026 : RUNTIME_FUNCTION(Runtime_ThrowRangeError) {
     114        4539 :   THROW_ERROR(isolate, args, NewRangeError);
     115             : }
     116             : 
     117        9906 : RUNTIME_FUNCTION(Runtime_ThrowTypeError) {
     118       14859 :   THROW_ERROR(isolate, args, NewTypeError);
     119             : }
     120             : 
     121             : #undef THROW_ERROR
     122             : 
     123             : namespace {
     124             : 
     125         835 : const char* ElementsKindToType(ElementsKind fixed_elements_kind) {
     126         835 :   switch (fixed_elements_kind) {
     127             : #define ELEMENTS_KIND_CASE(Type, type, TYPE, ctype, size) \
     128             :   case TYPE##_ELEMENTS:                                   \
     129             :     return #Type "Array";
     130             : 
     131           0 :     TYPED_ARRAYS(ELEMENTS_KIND_CASE)
     132             : #undef ELEMENTS_KIND_CASE
     133             : 
     134             :     default:
     135           0 :       UNREACHABLE();
     136             :       return "";
     137             :   }
     138             : }
     139             : 
     140             : }  // namespace
     141             : 
     142        1670 : RUNTIME_FUNCTION(Runtime_ThrowInvalidTypedArrayAlignment) {
     143         835 :   HandleScope scope(isolate);
     144             :   DCHECK_EQ(2, args.length());
     145        1670 :   CONVERT_ARG_HANDLE_CHECKED(Map, map, 0);
     146        1670 :   CONVERT_ARG_HANDLE_CHECKED(String, problem_string, 1);
     147             : 
     148         835 :   ElementsKind kind = map->elements_kind();
     149             : 
     150             :   Handle<String> type =
     151         835 :       isolate->factory()->NewStringFromAsciiChecked(ElementsKindToType(kind));
     152             : 
     153             :   ExternalArrayType external_type =
     154         835 :       isolate->factory()->GetArrayTypeFromElementsKind(kind);
     155         835 :   size_t size = isolate->factory()->GetExternalArrayElementSize(external_type);
     156             :   Handle<Object> element_size =
     157         835 :       handle(Smi::FromInt(static_cast<int>(size)), isolate);
     158             : 
     159        1670 :   THROW_NEW_ERROR_RETURN_FAILURE(
     160             :       isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayAlignment,
     161         835 :                              problem_string, type, element_size));
     162             : }
     163             : 
     164     2648940 : RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) {
     165             :   SealHandleScope shs(isolate);
     166             :   DCHECK_EQ(0, args.length());
     167     1324470 :   return isolate->UnwindAndFindHandler();
     168             : }
     169             : 
     170             : 
     171        4894 : RUNTIME_FUNCTION(Runtime_PromoteScheduledException) {
     172             :   SealHandleScope shs(isolate);
     173             :   DCHECK_EQ(0, args.length());
     174        2447 :   return isolate->PromoteScheduledException();
     175             : }
     176             : 
     177             : 
     178       73330 : RUNTIME_FUNCTION(Runtime_ThrowReferenceError) {
     179       36665 :   HandleScope scope(isolate);
     180             :   DCHECK_EQ(1, args.length());
     181       36665 :   CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
     182       73330 :   THROW_NEW_ERROR_RETURN_FAILURE(
     183       36665 :       isolate, NewReferenceError(MessageTemplate::kNotDefined, name));
     184             : }
     185             : 
     186             : 
     187         938 : RUNTIME_FUNCTION(Runtime_NewTypeError) {
     188         469 :   HandleScope scope(isolate);
     189             :   DCHECK_EQ(2, args.length());
     190         938 :   CONVERT_INT32_ARG_CHECKED(template_index, 0);
     191         469 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
     192             :   auto message_template =
     193         469 :       static_cast<MessageTemplate::Template>(template_index);
     194         938 :   return *isolate->factory()->NewTypeError(message_template, arg0);
     195             : }
     196             : 
     197             : 
     198         376 : RUNTIME_FUNCTION(Runtime_NewReferenceError) {
     199         188 :   HandleScope scope(isolate);
     200             :   DCHECK_EQ(2, args.length());
     201         376 :   CONVERT_INT32_ARG_CHECKED(template_index, 0);
     202         188 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
     203             :   auto message_template =
     204         188 :       static_cast<MessageTemplate::Template>(template_index);
     205         376 :   return *isolate->factory()->NewReferenceError(message_template, arg0);
     206             : }
     207             : 
     208             : 
     209           0 : RUNTIME_FUNCTION(Runtime_NewSyntaxError) {
     210           0 :   HandleScope scope(isolate);
     211             :   DCHECK_EQ(2, args.length());
     212           0 :   CONVERT_INT32_ARG_CHECKED(template_index, 0);
     213           0 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
     214             :   auto message_template =
     215           0 :       static_cast<MessageTemplate::Template>(template_index);
     216           0 :   return *isolate->factory()->NewSyntaxError(message_template, arg0);
     217             : }
     218             : 
     219         600 : RUNTIME_FUNCTION(Runtime_ThrowCannotConvertToPrimitive) {
     220         300 :   HandleScope scope(isolate);
     221         600 :   THROW_NEW_ERROR_RETURN_FAILURE(
     222         300 :       isolate, NewTypeError(MessageTemplate::kCannotConvertToPrimitive));
     223             : }
     224             : 
     225           0 : RUNTIME_FUNCTION(Runtime_ThrowIllegalInvocation) {
     226           0 :   HandleScope scope(isolate);
     227             :   DCHECK_EQ(0, args.length());
     228           0 :   THROW_NEW_ERROR_RETURN_FAILURE(
     229           0 :       isolate, NewTypeError(MessageTemplate::kIllegalInvocation));
     230             : }
     231             : 
     232        6504 : RUNTIME_FUNCTION(Runtime_ThrowIncompatibleMethodReceiver) {
     233        3252 :   HandleScope scope(isolate);
     234             :   DCHECK_EQ(2, args.length());
     235        3252 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 0);
     236        3252 :   CONVERT_ARG_HANDLE_CHECKED(Object, arg1, 1);
     237        6504 :   THROW_NEW_ERROR_RETURN_FAILURE(
     238             :       isolate,
     239        3252 :       NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, arg0, arg1));
     240             : }
     241             : 
     242           0 : RUNTIME_FUNCTION(Runtime_ThrowInvalidHint) {
     243           0 :   HandleScope scope(isolate);
     244             :   DCHECK_EQ(1, args.length());
     245           0 :   CONVERT_ARG_HANDLE_CHECKED(Object, hint, 0);
     246           0 :   THROW_NEW_ERROR_RETURN_FAILURE(
     247           0 :       isolate, NewTypeError(MessageTemplate::kInvalidHint, hint));
     248             : }
     249             : 
     250         130 : RUNTIME_FUNCTION(Runtime_ThrowInvalidStringLength) {
     251          65 :   HandleScope scope(isolate);
     252         130 :   THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError());
     253             : }
     254             : 
     255         870 : RUNTIME_FUNCTION(Runtime_ThrowIteratorResultNotAnObject) {
     256         435 :   HandleScope scope(isolate);
     257             :   DCHECK_EQ(1, args.length());
     258         435 :   CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
     259         870 :   THROW_NEW_ERROR_RETURN_FAILURE(
     260             :       isolate,
     261         435 :       NewTypeError(MessageTemplate::kIteratorResultNotAnObject, value));
     262             : }
     263             : 
     264         168 : RUNTIME_FUNCTION(Runtime_ThrowSymbolIteratorInvalid) {
     265          84 :   HandleScope scope(isolate);
     266             :   DCHECK_EQ(0, args.length());
     267         168 :   THROW_NEW_ERROR_RETURN_FAILURE(
     268          84 :       isolate, NewTypeError(MessageTemplate::kSymbolIteratorInvalid));
     269             : }
     270             : 
     271        2090 : RUNTIME_FUNCTION(Runtime_ThrowNonCallableInInstanceOfCheck) {
     272        1045 :   HandleScope scope(isolate);
     273        2090 :   THROW_NEW_ERROR_RETURN_FAILURE(
     274        1045 :       isolate, NewTypeError(MessageTemplate::kNonCallableInInstanceOfCheck));
     275             : }
     276             : 
     277        1312 : RUNTIME_FUNCTION(Runtime_ThrowNonObjectInInstanceOfCheck) {
     278         656 :   HandleScope scope(isolate);
     279        1312 :   THROW_NEW_ERROR_RETURN_FAILURE(
     280         656 :       isolate, NewTypeError(MessageTemplate::kNonObjectInInstanceOfCheck));
     281             : }
     282             : 
     283         674 : RUNTIME_FUNCTION(Runtime_ThrowNotConstructor) {
     284         337 :   HandleScope scope(isolate);
     285             :   DCHECK_EQ(1, args.length());
     286         337 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     287         674 :   THROW_NEW_ERROR_RETURN_FAILURE(
     288         337 :       isolate, NewTypeError(MessageTemplate::kNotConstructor, object));
     289             : }
     290             : 
     291         338 : RUNTIME_FUNCTION(Runtime_ThrowGeneratorRunning) {
     292         169 :   HandleScope scope(isolate);
     293             :   DCHECK_EQ(0, args.length());
     294         338 :   THROW_NEW_ERROR_RETURN_FAILURE(
     295         169 :       isolate, NewTypeError(MessageTemplate::kGeneratorRunning));
     296             : }
     297             : 
     298        3384 : RUNTIME_FUNCTION(Runtime_ThrowApplyNonFunction) {
     299        1692 :   HandleScope scope(isolate);
     300             :   DCHECK_EQ(1, args.length());
     301        1692 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     302        1692 :   Handle<String> type = Object::TypeOf(isolate, object);
     303        3384 :   THROW_NEW_ERROR_RETURN_FAILURE(
     304        1692 :       isolate, NewTypeError(MessageTemplate::kApplyNonFunction, object, type));
     305             : }
     306             : 
     307             : 
     308      408478 : RUNTIME_FUNCTION(Runtime_StackGuard) {
     309             :   SealHandleScope shs(isolate);
     310             :   DCHECK_EQ(0, args.length());
     311             : 
     312             :   // First check if this is a real stack overflow.
     313      204239 :   StackLimitCheck check(isolate);
     314      204239 :   if (check.JsHasOverflowed()) {
     315         815 :     return isolate->StackOverflow();
     316             :   }
     317             : 
     318      203424 :   return isolate->stack_guard()->HandleInterrupts();
     319             : }
     320             : 
     321             : 
     322     1026596 : RUNTIME_FUNCTION(Runtime_Interrupt) {
     323             :   SealHandleScope shs(isolate);
     324             :   DCHECK_EQ(0, args.length());
     325      513298 :   return isolate->stack_guard()->HandleInterrupts();
     326             : }
     327             : 
     328             : 
     329      362744 : RUNTIME_FUNCTION(Runtime_AllocateInNewSpace) {
     330      181372 :   HandleScope scope(isolate);
     331             :   DCHECK_EQ(1, args.length());
     332      362744 :   CONVERT_SMI_ARG_CHECKED(size, 0);
     333      181372 :   CHECK(IsAligned(size, kPointerSize));
     334      181372 :   CHECK(size > 0);
     335      181372 :   CHECK(size <= kMaxRegularHeapObjectSize);
     336      362744 :   return *isolate->factory()->NewFillerObject(size, false, NEW_SPACE);
     337             : }
     338             : 
     339             : 
     340       46228 : RUNTIME_FUNCTION(Runtime_AllocateInTargetSpace) {
     341       23114 :   HandleScope scope(isolate);
     342             :   DCHECK_EQ(2, args.length());
     343       46228 :   CONVERT_SMI_ARG_CHECKED(size, 0);
     344       46228 :   CONVERT_SMI_ARG_CHECKED(flags, 1);
     345       23114 :   CHECK(IsAligned(size, kPointerSize));
     346       23114 :   CHECK(size > 0);
     347       23114 :   bool double_align = AllocateDoubleAlignFlag::decode(flags);
     348       23114 :   AllocationSpace space = AllocateTargetSpace::decode(flags);
     349       23114 :   CHECK(size <= kMaxRegularHeapObjectSize || space == LO_SPACE);
     350       46228 :   return *isolate->factory()->NewFillerObject(size, double_align, space);
     351             : }
     352             : 
     353           0 : RUNTIME_FUNCTION(Runtime_AllocateSeqOneByteString) {
     354           0 :   HandleScope scope(isolate);
     355             :   DCHECK_EQ(1, args.length());
     356           0 :   CONVERT_SMI_ARG_CHECKED(length, 0);
     357           0 :   if (length == 0) return isolate->heap()->empty_string();
     358             :   Handle<SeqOneByteString> result;
     359           0 :   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
     360             :       isolate, result, isolate->factory()->NewRawOneByteString(length));
     361           0 :   return *result;
     362             : }
     363             : 
     364           0 : RUNTIME_FUNCTION(Runtime_AllocateSeqTwoByteString) {
     365           0 :   HandleScope scope(isolate);
     366             :   DCHECK_EQ(1, args.length());
     367           0 :   CONVERT_SMI_ARG_CHECKED(length, 0);
     368           0 :   if (length == 0) return isolate->heap()->empty_string();
     369             :   Handle<SeqTwoByteString> result;
     370           0 :   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
     371             :       isolate, result, isolate->factory()->NewRawTwoByteString(length));
     372           0 :   return *result;
     373             : }
     374             : 
     375             : 
     376           0 : RUNTIME_FUNCTION(Runtime_IS_VAR) {
     377           0 :   UNREACHABLE();  // implemented as macro in the parser
     378             :   return NULL;
     379             : }
     380             : 
     381             : 
     382             : namespace {
     383             : 
     384        9731 : bool ComputeLocation(Isolate* isolate, MessageLocation* target) {
     385        9731 :   JavaScriptFrameIterator it(isolate);
     386        9731 :   if (!it.done()) {
     387             :     // Compute the location from the function and the relocation info of the
     388             :     // baseline code. For optimized code this will use the deoptimization
     389             :     // information to get canonical location information.
     390        9710 :     List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
     391        9710 :     it.frame()->Summarize(&frames);
     392        9710 :     auto& summary = frames.last().AsJavaScript();
     393             :     Handle<SharedFunctionInfo> shared(summary.function()->shared());
     394             :     Handle<Object> script(shared->script(), isolate);
     395        9710 :     int pos = summary.abstract_code()->SourcePosition(summary.code_offset());
     396       19168 :     if (script->IsScript() &&
     397             :         !(Handle<Script>::cast(script)->source()->IsUndefined(isolate))) {
     398        9458 :       Handle<Script> casted_script = Handle<Script>::cast(script);
     399        9458 :       *target = MessageLocation(casted_script, pos, pos + 1, shared);
     400             :       return true;
     401             :     }
     402             :   }
     403             :   return false;
     404             : }
     405             : 
     406             : 
     407        9731 : Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object) {
     408        9731 :   MessageLocation location;
     409        9731 :   if (ComputeLocation(isolate, &location)) {
     410        9458 :     std::unique_ptr<ParseInfo> info(new ParseInfo(location.shared()));
     411        9458 :     if (parsing::ParseAny(info.get(), isolate)) {
     412        8810 :       CallPrinter printer(isolate, location.shared()->IsUserJavaScript());
     413        8810 :       Handle<String> str = printer.Print(info->literal(), location.start_pos());
     414        8810 :       if (str->length() > 0) return str;
     415             :     } else {
     416             :       isolate->clear_pending_exception();
     417             :     }
     418             :   }
     419        2552 :   return Object::TypeOf(isolate, object);
     420             : }
     421             : 
     422             : }  // namespace
     423             : 
     424       13422 : RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) {
     425        6711 :   HandleScope scope(isolate);
     426             :   DCHECK_EQ(1, args.length());
     427        6711 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     428        6711 :   Handle<String> callsite = RenderCallSite(isolate, object);
     429       13422 :   THROW_NEW_ERROR_RETURN_FAILURE(
     430        6711 :       isolate, NewTypeError(MessageTemplate::kCalledNonCallable, callsite));
     431             : }
     432             : 
     433        3296 : RUNTIME_FUNCTION(Runtime_ThrowCalledOnNullOrUndefined) {
     434        1648 :   HandleScope scope(isolate);
     435             :   DCHECK_EQ(1, args.length());
     436        3296 :   CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
     437        3296 :   THROW_NEW_ERROR_RETURN_FAILURE(
     438        1648 :       isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, name));
     439             : }
     440             : 
     441        6040 : RUNTIME_FUNCTION(Runtime_ThrowConstructedNonConstructable) {
     442        3020 :   HandleScope scope(isolate);
     443             :   DCHECK_EQ(1, args.length());
     444        3020 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     445        3020 :   Handle<String> callsite = RenderCallSite(isolate, object);
     446        6040 :   THROW_NEW_ERROR_RETURN_FAILURE(
     447        3020 :       isolate, NewTypeError(MessageTemplate::kNotConstructor, callsite));
     448             : }
     449             : 
     450        1040 : RUNTIME_FUNCTION(Runtime_ThrowConstructorReturnedNonObject) {
     451         520 :   HandleScope scope(isolate);
     452             :   DCHECK_EQ(0, args.length());
     453         520 :   if (FLAG_harmony_restrict_constructor_return) {
     454         392 :     THROW_NEW_ERROR_RETURN_FAILURE(
     455             :         isolate,
     456             :         NewTypeError(MessageTemplate::kClassConstructorReturnedNonObject));
     457             :   }
     458             : 
     459         648 :   THROW_NEW_ERROR_RETURN_FAILURE(
     460             :       isolate,
     461         520 :       NewTypeError(MessageTemplate::kDerivedConstructorReturnedNonObject));
     462             : }
     463             : 
     464        3104 : RUNTIME_FUNCTION(Runtime_ThrowUndefinedOrNullToObject) {
     465        1552 :   HandleScope scope(isolate);
     466             :   DCHECK_EQ(1, args.length());
     467        3104 :   CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
     468        3104 :   THROW_NEW_ERROR_RETURN_FAILURE(
     469        1552 :       isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject, name));
     470             : }
     471             : 
     472             : // ES6 section 7.3.17 CreateListFromArrayLike (obj)
     473       50218 : RUNTIME_FUNCTION(Runtime_CreateListFromArrayLike) {
     474       25109 :   HandleScope scope(isolate);
     475             :   DCHECK_EQ(1, args.length());
     476       25109 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     477       50218 :   RETURN_RESULT_OR_FAILURE(isolate, Object::CreateListFromArrayLike(
     478       25109 :                                         isolate, object, ElementTypes::kAll));
     479             : }
     480             : 
     481             : 
     482        1792 : RUNTIME_FUNCTION(Runtime_IncrementUseCounter) {
     483         896 :   HandleScope scope(isolate);
     484             :   DCHECK_EQ(1, args.length());
     485        1792 :   CONVERT_SMI_ARG_CHECKED(counter, 0);
     486         896 :   isolate->CountUsage(static_cast<v8::Isolate::UseCounterFeature>(counter));
     487         896 :   return isolate->heap()->undefined_value();
     488             : }
     489             : 
     490           0 : RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) {
     491           0 :   HandleScope scope(isolate);
     492           0 :   if (args.length() == 0) {
     493             :     // Without arguments, the result is returned as a string.
     494             :     DCHECK_EQ(0, args.length());
     495           0 :     std::stringstream stats_stream;
     496           0 :     isolate->counters()->runtime_call_stats()->Print(stats_stream);
     497             :     Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(
     498           0 :         stats_stream.str().c_str());
     499           0 :     isolate->counters()->runtime_call_stats()->Reset();
     500           0 :     return *result;
     501             :   } else {
     502             :     DCHECK_LE(args.length(), 2);
     503             :     std::FILE* f;
     504           0 :     if (args[0]->IsString()) {
     505             :       // With a string argument, the results are appended to that file.
     506           0 :       CONVERT_ARG_HANDLE_CHECKED(String, arg0, 0);
     507           0 :       String::FlatContent flat = arg0->GetFlatContent();
     508             :       const char* filename =
     509           0 :           reinterpret_cast<const char*>(&(flat.ToOneByteVector()[0]));
     510           0 :       f = std::fopen(filename, "a");
     511             :       DCHECK_NOT_NULL(f);
     512             :     } else {
     513             :       // With an integer argument, the results are written to stdout/stderr.
     514           0 :       CONVERT_SMI_ARG_CHECKED(fd, 0);
     515             :       DCHECK(fd == 1 || fd == 2);
     516           0 :       f = fd == 1 ? stdout : stderr;
     517             :     }
     518             :     // The second argument (if any) is a message header to be printed.
     519           0 :     if (args.length() >= 2) {
     520           0 :       CONVERT_ARG_HANDLE_CHECKED(String, arg1, 1);
     521           0 :       arg1->PrintOn(f);
     522           0 :       std::fputc('\n', f);
     523           0 :       std::fflush(f);
     524             :     }
     525           0 :     OFStream stats_stream(f);
     526           0 :     isolate->counters()->runtime_call_stats()->Print(stats_stream);
     527           0 :     isolate->counters()->runtime_call_stats()->Reset();
     528           0 :     if (args[0]->IsString())
     529           0 :       std::fclose(f);
     530             :     else
     531           0 :       std::fflush(f);
     532           0 :     return isolate->heap()->undefined_value();
     533           0 :   }
     534             : }
     535             : 
     536      357398 : RUNTIME_FUNCTION(Runtime_OrdinaryHasInstance) {
     537      178699 :   HandleScope scope(isolate);
     538             :   DCHECK_EQ(2, args.length());
     539      178699 :   CONVERT_ARG_HANDLE_CHECKED(Object, callable, 0);
     540      178699 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 1);
     541      357398 :   RETURN_RESULT_OR_FAILURE(
     542      178699 :       isolate, Object::OrdinaryHasInstance(isolate, callable, object));
     543             : }
     544             : 
     545           0 : RUNTIME_FUNCTION(Runtime_Typeof) {
     546           0 :   HandleScope scope(isolate);
     547             :   DCHECK_EQ(1, args.length());
     548           0 :   CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
     549           0 :   return *Object::TypeOf(isolate, object);
     550             : }
     551             : 
     552         172 : RUNTIME_FUNCTION(Runtime_AllowDynamicFunction) {
     553          86 :   HandleScope scope(isolate);
     554             :   DCHECK_EQ(1, args.length());
     555         172 :   CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0);
     556          86 :   Handle<JSObject> global_proxy(target->global_proxy(), isolate);
     557             :   return *isolate->factory()->ToBoolean(
     558         172 :       Builtins::AllowDynamicFunction(isolate, target, global_proxy));
     559             : }
     560             : 
     561         664 : RUNTIME_FUNCTION(Runtime_CreateAsyncFromSyncIterator) {
     562         332 :   HandleScope scope(isolate);
     563             :   DCHECK_EQ(1, args.length());
     564             : 
     565         332 :   CONVERT_ARG_HANDLE_CHECKED(Object, sync_iterator, 0);
     566             : 
     567         332 :   if (!sync_iterator->IsJSReceiver()) {
     568           0 :     THROW_NEW_ERROR_RETURN_FAILURE(
     569             :         isolate, NewTypeError(MessageTemplate::kSymbolIteratorInvalid));
     570             :   }
     571             : 
     572             :   return *isolate->factory()->NewJSAsyncFromSyncIterator(
     573         664 :       Handle<JSReceiver>::cast(sync_iterator));
     574             : }
     575             : 
     576             : }  // namespace internal
     577             : }  // namespace v8

Generated by: LCOV version 1.10