LCOV - code coverage report
Current view: top level - src - pending-compilation-error-handler.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 23 24 95.8 %
Date: 2017-04-26 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright 2015 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/pending-compilation-error-handler.h"
       6             : 
       7             : #include "src/ast/ast-value-factory.h"
       8             : #include "src/debug/debug.h"
       9             : #include "src/handles.h"
      10             : #include "src/isolate.h"
      11             : #include "src/messages.h"
      12             : #include "src/objects-inl.h"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : 
      17      585862 : Handle<String> PendingCompilationErrorHandler::ArgumentString(
      18             :     Isolate* isolate) {
      19      585862 :   if (arg_ != NULL) return arg_->string();
      20      467856 :   if (char_arg_ != NULL) {
      21             :     return isolate->factory()
      22             :         ->NewStringFromUtf8(CStrVector(char_arg_))
      23      469824 :         .ToHandleChecked();
      24             :   }
      25             :   return isolate->factory()->undefined_string();
      26             : }
      27             : 
      28      210178 : Handle<String> PendingCompilationErrorHandler::FormatMessage(Isolate* isolate) {
      29             :   return MessageTemplate::FormatMessage(isolate, message_,
      30      420356 :                                         ArgumentString(isolate));
      31             : }
      32             : 
      33      751368 : void PendingCompilationErrorHandler::ThrowPendingError(Isolate* isolate,
      34             :                                                        Handle<Script> script) {
      35      375720 :   if (!has_pending_error_) return;
      36      375684 :   MessageLocation location(script, start_position_, end_position_);
      37             :   Factory* factory = isolate->factory();
      38      375684 :   Handle<String> argument = ArgumentString(isolate);
      39      375684 :   isolate->debug()->OnCompileError(script);
      40             : 
      41             :   Handle<Object> error;
      42      375684 :   switch (error_type_) {
      43             :     case kReferenceError:
      44        6750 :       error = factory->NewReferenceError(message_, argument);
      45        6750 :       break;
      46             :     case kSyntaxError:
      47      368934 :       error = factory->NewSyntaxError(message_, argument);
      48      368934 :       break;
      49             :     default:
      50           0 :       UNREACHABLE();
      51             :       break;
      52             :   }
      53             : 
      54      375684 :   if (!error->IsJSObject()) {
      55          36 :     isolate->Throw(*error, &location);
      56          36 :     return;
      57             :   }
      58             : 
      59             :   Handle<JSObject> jserror = Handle<JSObject>::cast(error);
      60             : 
      61             :   Handle<Name> key_start_pos = factory->error_start_pos_symbol();
      62             :   JSObject::SetProperty(jserror, key_start_pos,
      63             :                         handle(Smi::FromInt(location.start_pos()), isolate),
      64     1126944 :                         SLOPPY).Check();
      65             : 
      66             :   Handle<Name> key_end_pos = factory->error_end_pos_symbol();
      67             :   JSObject::SetProperty(jserror, key_end_pos,
      68             :                         handle(Smi::FromInt(location.end_pos()), isolate),
      69     1126944 :                         SLOPPY).Check();
      70             : 
      71             :   Handle<Name> key_script = factory->error_script_symbol();
      72      751296 :   JSObject::SetProperty(jserror, key_script, script, SLOPPY).Check();
      73             : 
      74      375648 :   isolate->Throw(*error, &location);
      75             : }
      76             : }  // namespace internal
      77             : }  // namespace v8

Generated by: LCOV version 1.10