LCOV - code coverage report
Current view: top level - src/builtins - builtins-error.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 27 36 75.0 %
Date: 2019-01-20 Functions: 11 27 40.7 %

          Line data    Source code
       1             : // Copyright 2016 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/accessors.h"
       6             : #include "src/builtins/builtins-utils-inl.h"
       7             : #include "src/builtins/builtins.h"
       8             : #include "src/counters.h"
       9             : #include "src/messages.h"
      10             : #include "src/objects-inl.h"
      11             : #include "src/objects/api-callbacks.h"
      12             : #include "src/property-descriptor.h"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : 
      17             : // ES6 section 19.5.1.1 Error ( message )
      18       91012 : BUILTIN(ErrorConstructor) {
      19             :   HandleScope scope(isolate);
      20             : 
      21             :   FrameSkipMode mode = SKIP_FIRST;
      22             :   Handle<Object> caller;
      23             : 
      24             :   // When we're passed a JSFunction as new target, we can skip frames until that
      25             :   // specific function is seen instead of unconditionally skipping the first
      26             :   // frame.
      27       68259 :   if (args.new_target()->IsJSFunction()) {
      28             :     mode = SKIP_UNTIL_SEEN;
      29       22315 :     caller = args.new_target();
      30             :   }
      31             : 
      32       45515 :   RETURN_RESULT_OR_FAILURE(
      33             :       isolate, ErrorUtils::Construct(isolate, args.target(),
      34             :                                      Handle<Object>::cast(args.new_target()),
      35             :                                      args.atOrUndefined(isolate, 1), mode,
      36             :                                      caller, false));
      37             : }
      38             : 
      39             : // static
      40         684 : BUILTIN(ErrorCaptureStackTrace) {
      41             :   HandleScope scope(isolate);
      42             :   Handle<Object> object_obj = args.atOrUndefined(isolate, 1);
      43             : 
      44         171 :   isolate->CountUsage(v8::Isolate::kErrorCaptureStackTrace);
      45             : 
      46         342 :   if (!object_obj->IsJSObject()) {
      47          18 :     THROW_NEW_ERROR_RETURN_FAILURE(
      48             :         isolate, NewTypeError(MessageTemplate::kInvalidArgument, object_obj));
      49             :   }
      50             : 
      51         162 :   Handle<JSObject> object = Handle<JSObject>::cast(object_obj);
      52             :   Handle<Object> caller = args.atOrUndefined(isolate, 2);
      53         324 :   FrameSkipMode mode = caller->IsJSFunction() ? SKIP_UNTIL_SEEN : SKIP_FIRST;
      54             : 
      55             :   // Collect the stack trace.
      56             : 
      57         324 :   RETURN_FAILURE_ON_EXCEPTION(isolate,
      58             :                               isolate->CaptureAndSetDetailedStackTrace(object));
      59         324 :   RETURN_FAILURE_ON_EXCEPTION(
      60             :       isolate, isolate->CaptureAndSetSimpleStackTrace(object, mode, caller));
      61             : 
      62             :   // Add the stack accessors.
      63             : 
      64             :   Handle<AccessorInfo> error_stack = isolate->factory()->error_stack_accessor();
      65         324 :   Handle<Name> name(Name::cast(error_stack->name()), isolate);
      66             : 
      67             :   // Explicitly check for frozen objects. Other access checks are performed by
      68             :   // the LookupIterator in SetAccessor below.
      69         162 :   if (!JSObject::IsExtensible(object)) {
      70             :     return isolate->Throw(*isolate->factory()->NewTypeError(
      71          54 :         MessageTemplate::kDefineDisallowed, name));
      72             :   }
      73             : 
      74         270 :   RETURN_FAILURE_ON_EXCEPTION(
      75             :       isolate, JSObject::SetAccessor(object, name, error_stack, DONT_ENUM));
      76         135 :   return ReadOnlyRoots(isolate).undefined_value();
      77             : }
      78             : 
      79             : // ES6 section 19.5.3.4 Error.prototype.toString ( )
      80     1189336 : BUILTIN(ErrorPrototypeToString) {
      81             :   HandleScope scope(isolate);
      82      607938 :   RETURN_RESULT_OR_FAILURE(isolate,
      83             :                            ErrorUtils::ToString(isolate, args.receiver()));
      84             : }
      85             : 
      86             : namespace {
      87             : 
      88          32 : Object MakeGenericError(Isolate* isolate, BuiltinArguments args,
      89             :                         Handle<JSFunction> constructor) {
      90             :   Handle<Object> template_index = args.atOrUndefined(isolate, 1);
      91          32 :   Handle<Object> arg0 = args.atOrUndefined(isolate, 2);
      92          32 :   Handle<Object> arg1 = args.atOrUndefined(isolate, 3);
      93          32 :   Handle<Object> arg2 = args.atOrUndefined(isolate, 4);
      94             : 
      95             :   DCHECK(template_index->IsSmi());
      96             : 
      97          64 :   RETURN_RESULT_OR_FAILURE(
      98             :       isolate, ErrorUtils::MakeGenericError(
      99             :                    isolate, constructor,
     100             :                    MessageTemplateFromInt(Smi::ToInt(*template_index)), arg0,
     101             :                    arg1, arg2, SKIP_NONE));
     102             : }
     103             : 
     104             : }  // namespace
     105             : 
     106           0 : BUILTIN(MakeError) {
     107             :   HandleScope scope(isolate);
     108           0 :   return MakeGenericError(isolate, args, isolate->error_function());
     109             : }
     110             : 
     111           0 : BUILTIN(MakeRangeError) {
     112             :   HandleScope scope(isolate);
     113           0 :   return MakeGenericError(isolate, args, isolate->range_error_function());
     114             : }
     115             : 
     116           0 : BUILTIN(MakeSyntaxError) {
     117             :   HandleScope scope(isolate);
     118           0 :   return MakeGenericError(isolate, args, isolate->syntax_error_function());
     119             : }
     120             : 
     121         128 : BUILTIN(MakeTypeError) {
     122             :   HandleScope scope(isolate);
     123          64 :   return MakeGenericError(isolate, args, isolate->type_error_function());
     124             : }
     125             : 
     126           0 : BUILTIN(MakeURIError) {
     127             :   HandleScope scope(isolate);
     128           0 :   Handle<JSFunction> constructor = isolate->uri_error_function();
     129             :   Handle<Object> undefined = isolate->factory()->undefined_value();
     130             :   MessageTemplate template_index = MessageTemplate::kURIMalformed;
     131           0 :   RETURN_RESULT_OR_FAILURE(
     132             :       isolate,
     133             :       ErrorUtils::MakeGenericError(isolate, constructor, template_index,
     134             :                                    undefined, undefined, undefined, SKIP_NONE));
     135             : }
     136             : 
     137             : }  // namespace internal
     138      183867 : }  // namespace v8

Generated by: LCOV version 1.10