execution.cc 22.1 KB
Newer Older
1 2 3 4
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#include "src/execution.h"
6

7 8 9
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/deoptimizer.h"
10
#include "src/messages.h"
11
#include "src/vm-state-inl.h"
12

13 14
namespace v8 {
namespace internal {
15

16 17 18 19 20 21
StackGuard::StackGuard()
    : isolate_(NULL) {
}


void StackGuard::set_interrupt_limits(const ExecutionAccess& lock) {
22
  DCHECK(isolate_ != NULL);
23 24
  thread_local_.set_jslimit(kInterruptLimit);
  thread_local_.set_climit(kInterruptLimit);
25 26 27 28 29
  isolate_->heap()->SetStackLimits();
}


void StackGuard::reset_limits(const ExecutionAccess& lock) {
30
  DCHECK(isolate_ != NULL);
31 32
  thread_local_.set_jslimit(thread_local_.real_jslimit_);
  thread_local_.set_climit(thread_local_.real_climit_);
33 34 35 36
  isolate_->heap()->SetStackLimits();
}


37
static void PrintDeserializedCodeInfo(Handle<JSFunction> function) {
38 39
  if (function->code() == function->shared()->code() &&
      function->shared()->deserialized()) {
40
    PrintF("[Running deserialized script");
41
    Object* script = function->shared()->script();
42 43 44 45 46 47 48
    if (script->IsScript()) {
      Object* name = Script::cast(script)->name();
      if (name->IsString()) {
        PrintF(": %s", String::cast(name)->ToCString().get());
      }
    }
    PrintF("]\n");
49 50 51 52
  }
}


53 54 55 56 57 58
MUST_USE_RESULT static MaybeHandle<Object> Invoke(
    bool is_construct,
    Handle<JSFunction> function,
    Handle<Object> receiver,
    int argc,
    Handle<Object> args[]) {
59
  Isolate* isolate = function->GetIsolate();
60

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  // api callbacks can be called directly.
  if (!is_construct && function->shared()->IsApiFunction()) {
    SaveContext save(isolate);
    isolate->set_context(function->context());
    if (receiver->IsGlobalObject()) {
      receiver = handle(Handle<GlobalObject>::cast(receiver)->global_proxy());
    }
    DCHECK(function->context()->global_object()->IsGlobalObject());
    auto value = Builtins::InvokeApiFunction(function, receiver, argc, args);
    bool has_exception = value.is_null();
    DCHECK(has_exception == isolate->has_pending_exception());
    if (has_exception) {
      isolate->ReportPendingMessages();
      return MaybeHandle<Object>();
    } else {
      isolate->clear_pending_message();
    }
    return value;
  }

81
  // Entering JavaScript.
82
  VMState<JS> state(isolate);
83
  CHECK(AllowJavascriptExecution::IsAllowed(isolate));
84 85 86
  if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) {
    isolate->ThrowIllegalOperation();
    isolate->ReportPendingMessages();
87
    return MaybeHandle<Object>();
88
  }
89 90

  // Placeholder for return value.
91
  Object* value = NULL;
92

93 94 95 96 97
  typedef Object* (*JSEntryFunction)(byte* entry,
                                     Object* function,
                                     Object* receiver,
                                     int argc,
                                     Object*** args);
98

99 100 101
  Handle<Code> code = is_construct
      ? isolate->factory()->js_construct_entry_code()
      : isolate->factory()->js_entry_code();
102

103 104 105 106
  // Convert calls on global objects to be calls on the global
  // receiver instead to avoid having a 'this' pointer which refers
  // directly to a global object.
  if (receiver->IsGlobalObject()) {
107
    receiver = handle(Handle<GlobalObject>::cast(receiver)->global_proxy());
108 109
  }

110 111
  // Make sure that the global object of the context we're about to
  // make the current one is indeed a global object.
112
  DCHECK(function->context()->global_object()->IsGlobalObject());
113

114 115
  {
    // Save and restore context around invocation and block the
116
    // allocation of handles without explicit handle scopes.
117
    SaveContext save(isolate);
118
    SealHandleScope shs(isolate);
119
    JSEntryFunction stub_entry = FUNCTION_CAST<JSEntryFunction>(code->entry());
120 121

    // Call the function through the right JS entry stub.
122 123 124 125
    byte* function_entry = function->code()->entry();
    JSFunction* func = *function;
    Object* recv = *receiver;
    Object*** argv = reinterpret_cast<Object***>(args);
126
    if (FLAG_profile_deserialization) PrintDeserializedCodeInfo(function);
127 128
    value =
        CALL_GENERATED_CODE(stub_entry, function_entry, func, recv, argc, argv);
129 130
  }

131
#ifdef VERIFY_HEAP
132 133 134
  if (FLAG_verify_heap) {
    value->ObjectVerify();
  }
135 136
#endif

137
  // Update the pending exception flag and return the value.
138
  bool has_exception = value->IsException();
139
  DCHECK(has_exception == isolate->has_pending_exception());
140
  if (has_exception) {
141
    isolate->ReportPendingMessages();
142
    // Reset stepping state when script exits with uncaught exception.
143
    if (isolate->debug()->is_active()) {
144 145
      isolate->debug()->ClearStepping();
    }
146
    return MaybeHandle<Object>();
147
  } else {
148
    isolate->clear_pending_message();
149 150
  }

151
  return Handle<Object>(value, isolate);
152 153 154
}


155 156 157 158 159 160
MaybeHandle<Object> Execution::Call(Isolate* isolate,
                                    Handle<Object> callable,
                                    Handle<Object> receiver,
                                    int argc,
                                    Handle<Object> argv[],
                                    bool convert_receiver) {
161
  if (!callable->IsJSFunction()) {
162 163
    ASSIGN_RETURN_ON_EXCEPTION(
        isolate, callable, TryGetFunctionDelegate(isolate, callable), Object);
164 165
  }
  Handle<JSFunction> func = Handle<JSFunction>::cast(callable);
166

167
  // In sloppy mode, convert receiver.
168
  if (convert_receiver && !receiver->IsJSReceiver() &&
169
      !func->shared()->native() && is_sloppy(func->shared()->language_mode())) {
170
    if (receiver->IsUndefined() || receiver->IsNull()) {
171
      receiver = handle(func->global_proxy());
172
      DCHECK(!receiver->IsJSBuiltinsObject());
173
    } else {
174 175
      ASSIGN_RETURN_ON_EXCEPTION(
          isolate, receiver, ToObject(isolate, receiver), Object);
176 177 178
    }
  }

179
  return Invoke(false, func, receiver, argc, argv);
180 181 182
}


183 184 185
MaybeHandle<Object> Execution::New(Handle<JSFunction> func,
                                   int argc,
                                   Handle<Object> argv[]) {
186
  return Invoke(true, func, handle(func->global_proxy()), argc, argv);
187 188 189
}


190
MaybeHandle<Object> Execution::TryCall(Handle<JSFunction> func,
191
                                       Handle<Object> receiver, int argc,
192
                                       Handle<Object> args[],
193 194 195 196 197
                                       MaybeHandle<Object>* exception_out) {
  bool is_termination = false;
  Isolate* isolate = func->GetIsolate();
  MaybeHandle<Object> maybe_result;
  if (exception_out != NULL) *exception_out = MaybeHandle<Object>();
198
  // Enter a try-block while executing the JavaScript code. To avoid
199 200 201
  // duplicate error printing it must be non-verbose.  Also, to avoid
  // creating message objects during stack overflow we shouldn't
  // capture messages.
202 203 204 205 206 207 208 209 210 211 212
  {
    v8::TryCatch catcher;
    catcher.SetVerbose(false);
    catcher.SetCaptureMessage(false);

    maybe_result = Invoke(false, func, receiver, argc, args);

    if (maybe_result.is_null()) {
      DCHECK(catcher.HasCaught());
      DCHECK(isolate->has_pending_exception());
      DCHECK(isolate->external_caught_exception());
213 214 215 216 217
      if (isolate->pending_exception() ==
          isolate->heap()->termination_exception()) {
        is_termination = true;
      } else {
        if (exception_out != NULL) {
218 219
          *exception_out = v8::Utils::OpenHandle(*catcher.Exception());
        }
220
      }
221
      isolate->OptionalRescheduleException(true);
222
    }
223

224 225
    DCHECK(!isolate->has_pending_exception());
  }
226 227 228 229

  // Re-request terminate execution interrupt to trigger later.
  if (is_termination) isolate->stack_guard()->RequestTerminateExecution();

230
  return maybe_result;
231 232 233
}


234 235
Handle<Object> Execution::GetFunctionDelegate(Isolate* isolate,
                                              Handle<Object> object) {
236
  DCHECK(!object->IsJSFunction());
237
  Factory* factory = isolate->factory();
238 239 240 241

  // If you return a function from here, it will be called when an
  // attempt is made to call the given object as a function.

242
  // If object is a function proxy, get its handler. Iterate if necessary.
243 244 245 246
  Object* fun = *object;
  while (fun->IsJSFunctionProxy()) {
    fun = JSFunctionProxy::cast(fun)->call_trap();
  }
247
  if (fun->IsJSFunction()) return Handle<Object>(fun, isolate);
248

249 250
  // Objects created through the API can have an instance-call handler
  // that should be used when calling the object as a function.
251 252
  if (fun->IsHeapObject() &&
      HeapObject::cast(fun)->map()->has_instance_call_handler()) {
253
    return Handle<JSFunction>(
254
        isolate->native_context()->call_as_function_delegate());
255 256
  }

257
  return factory->undefined_value();
258 259 260
}


261 262
MaybeHandle<Object> Execution::TryGetFunctionDelegate(Isolate* isolate,
                                                      Handle<Object> object) {
263
  DCHECK(!object->IsJSFunction());
264

265
  // If object is a function proxy, get its handler. Iterate if necessary.
266 267 268 269
  Object* fun = *object;
  while (fun->IsJSFunctionProxy()) {
    fun = JSFunctionProxy::cast(fun)->call_trap();
  }
270
  if (fun->IsJSFunction()) return Handle<Object>(fun, isolate);
271

272 273
  // Objects created through the API can have an instance-call handler
  // that should be used when calling the object as a function.
274 275
  if (fun->IsHeapObject() &&
      HeapObject::cast(fun)->map()->has_instance_call_handler()) {
276
    return Handle<JSFunction>(
277
        isolate->native_context()->call_as_function_delegate());
278 279 280 281
  }

  // If the Object doesn't have an instance-call handler we should
  // throw a non-callable exception.
282 283
  THROW_NEW_ERROR(isolate,
                  NewTypeError(MessageTemplate::kCalledNonCallable, object),
284
                  Object);
285 286 287
}


288 289
Handle<Object> Execution::GetConstructorDelegate(Isolate* isolate,
                                                 Handle<Object> object) {
290
  DCHECK(!object->IsJSFunction());
291 292 293 294

  // If you return a function from here, it will be called when an
  // attempt is made to call the given object as a constructor.

295 296 297 298 299
  // If object is a function proxies, get its handler. Iterate if necessary.
  Object* fun = *object;
  while (fun->IsJSFunctionProxy()) {
    fun = JSFunctionProxy::cast(fun)->call_trap();
  }
300
  if (fun->IsJSFunction()) return Handle<Object>(fun, isolate);
301

302 303
  // Objects created through the API can have an instance-call handler
  // that should be used when calling the object as a function.
304 305
  if (fun->IsHeapObject() &&
      HeapObject::cast(fun)->map()->has_instance_call_handler()) {
306
    return Handle<JSFunction>(
307
        isolate->native_context()->call_as_constructor_delegate());
308 309
  }

310
  return isolate->factory()->undefined_value();
311 312 313
}


314 315
MaybeHandle<Object> Execution::TryGetConstructorDelegate(
    Isolate* isolate, Handle<Object> object) {
316
  DCHECK(!object->IsJSFunction());
317 318 319 320

  // If you return a function from here, it will be called when an
  // attempt is made to call the given object as a constructor.

321 322 323 324 325
  // If object is a function proxies, get its handler. Iterate if necessary.
  Object* fun = *object;
  while (fun->IsJSFunctionProxy()) {
    fun = JSFunctionProxy::cast(fun)->call_trap();
  }
326
  if (fun->IsJSFunction()) return Handle<Object>(fun, isolate);
327

328 329
  // Objects created through the API can have an instance-call handler
  // that should be used when calling the object as a function.
330 331
  if (fun->IsHeapObject() &&
      HeapObject::cast(fun)->map()->has_instance_call_handler()) {
332
    return Handle<JSFunction>(
333
        isolate->native_context()->call_as_constructor_delegate());
334 335 336 337
  }

  // If the Object doesn't have an instance-call handler we should
  // throw a non-callable exception.
338 339
  THROW_NEW_ERROR(isolate,
                  NewTypeError(MessageTemplate::kCalledNonCallable, object),
340
                  Object);
341 342 343
}


344
void StackGuard::EnableInterrupts() {
345
  ExecutionAccess access(isolate_);
346 347
  if (has_pending_interrupts(access)) {
    set_interrupt_limits(access);
348 349 350 351 352
  }
}


void StackGuard::SetStackLimit(uintptr_t limit) {
353
  ExecutionAccess access(isolate_);
354
  // If the current limits are special (e.g. due to a pending interrupt) then
355
  // leave them alone.
356
  uintptr_t jslimit = SimulatorStack::JsLimitFromCLimit(isolate_, limit);
357 358
  if (thread_local_.jslimit() == thread_local_.real_jslimit_) {
    thread_local_.set_jslimit(jslimit);
359
  }
360 361
  if (thread_local_.climit() == thread_local_.real_climit_) {
    thread_local_.set_climit(limit);
362
  }
363 364
  thread_local_.real_climit_ = limit;
  thread_local_.real_jslimit_ = jslimit;
365 366 367 368
}


void StackGuard::DisableInterrupts() {
369
  ExecutionAccess access(isolate_);
370 371 372 373
  reset_limits(access);
}


374
void StackGuard::PushPostponeInterruptsScope(PostponeInterruptsScope* scope) {
375
  ExecutionAccess access(isolate_);
376 377 378 379 380 381 382 383
  // Intercept already requested interrupts.
  int intercepted = thread_local_.interrupt_flags_ & scope->intercept_mask_;
  scope->intercepted_flags_ = intercepted;
  thread_local_.interrupt_flags_ &= ~intercepted;
  if (!has_pending_interrupts(access)) reset_limits(access);
  // Add scope to the chain.
  scope->prev_ = thread_local_.postpone_interrupts_;
  thread_local_.postpone_interrupts_ = scope;
384 385 386
}


387
void StackGuard::PopPostponeInterruptsScope() {
388
  ExecutionAccess access(isolate_);
389 390
  PostponeInterruptsScope* top = thread_local_.postpone_interrupts_;
  // Make intercepted interrupts active.
391
  DCHECK((thread_local_.interrupt_flags_ & top->intercept_mask_) == 0);
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
  thread_local_.interrupt_flags_ |= top->intercepted_flags_;
  if (has_pending_interrupts(access)) set_interrupt_limits(access);
  // Remove scope from chain.
  thread_local_.postpone_interrupts_ = top->prev_;
}


bool StackGuard::CheckInterrupt(InterruptFlag flag) {
  ExecutionAccess access(isolate_);
  return thread_local_.interrupt_flags_ & flag;
}


void StackGuard::RequestInterrupt(InterruptFlag flag) {
  ExecutionAccess access(isolate_);
  // Check the chain of PostponeInterruptsScopes for interception.
  if (thread_local_.postpone_interrupts_ &&
      thread_local_.postpone_interrupts_->Intercept(flag)) {
    return;
  }

  // Not intercepted.  Set as active interrupt flag.
  thread_local_.interrupt_flags_ |= flag;
415
  set_interrupt_limits(access);
416 417 418
}


419
void StackGuard::ClearInterrupt(InterruptFlag flag) {
420
  ExecutionAccess access(isolate_);
421 422 423 424 425
  // Clear the interrupt flag from the chain of PostponeInterruptsScopes.
  for (PostponeInterruptsScope* current = thread_local_.postpone_interrupts_;
       current != NULL;
       current = current->prev_) {
    current->intercepted_flags_ &= ~flag;
426
  }
427 428 429 430

  // Clear the interrupt flag from the active interrupt flags.
  thread_local_.interrupt_flags_ &= ~flag;
  if (!has_pending_interrupts(access)) reset_limits(access);
431 432 433
}


434 435
bool StackGuard::CheckAndClearInterrupt(InterruptFlag flag) {
  ExecutionAccess access(isolate_);
436 437 438
  bool result = (thread_local_.interrupt_flags_ & flag);
  thread_local_.interrupt_flags_ &= ~flag;
  if (!has_pending_interrupts(access)) reset_limits(access);
439 440 441 442
  return result;
}


443
char* StackGuard::ArchiveStackGuard(char* to) {
444
  ExecutionAccess access(isolate_);
445
  MemCopy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal));
446
  ThreadLocal blank;
447 448 449 450 451 452 453

  // Set the stack limits using the old thread_local_.
  // TODO(isolates): This was the old semantics of constructing a ThreadLocal
  //                 (as the ctor called SetStackLimits, which looked at the
  //                 current thread_local_ from StackGuard)-- but is this
  //                 really what was intended?
  isolate_->heap()->SetStackLimits();
454
  thread_local_ = blank;
455

456 457 458 459 460
  return to + sizeof(ThreadLocal);
}


char* StackGuard::RestoreStackGuard(char* from) {
461
  ExecutionAccess access(isolate_);
462
  MemCopy(reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal));
463
  isolate_->heap()->SetStackLimits();
464 465 466 467
  return from + sizeof(ThreadLocal);
}


468
void StackGuard::FreeThreadResources() {
469 470 471
  Isolate::PerIsolateThreadData* per_thread =
      isolate_->FindOrAllocatePerThreadDataForThisThread();
  per_thread->set_stack_limit(thread_local_.real_climit_);
472 473 474 475
}


void StackGuard::ThreadLocal::Clear() {
476
  real_jslimit_ = kIllegalLimit;
477
  set_jslimit(kIllegalLimit);
478
  real_climit_ = kIllegalLimit;
479
  set_climit(kIllegalLimit);
480
  postpone_interrupts_ = NULL;
481 482 483 484
  interrupt_flags_ = 0;
}


485
bool StackGuard::ThreadLocal::Initialize(Isolate* isolate) {
486
  bool should_set_stack_limits = false;
487
  if (real_climit_ == kIllegalLimit) {
488
    const uintptr_t kLimitSize = FLAG_stack_size * KB;
489
    DCHECK(GetCurrentStackPosition() > kLimitSize);
490
    uintptr_t limit = GetCurrentStackPosition() - kLimitSize;
491
    real_jslimit_ = SimulatorStack::JsLimitFromCLimit(isolate, limit);
492
    set_jslimit(SimulatorStack::JsLimitFromCLimit(isolate, limit));
493
    real_climit_ = limit;
494
    set_climit(limit);
495
    should_set_stack_limits = true;
496
  }
497
  postpone_interrupts_ = NULL;
498
  interrupt_flags_ = 0;
499
  return should_set_stack_limits;
500 501 502 503 504
}


void StackGuard::ClearThread(const ExecutionAccess& lock) {
  thread_local_.Clear();
505
  isolate_->heap()->SetStackLimits();
506 507 508 509
}


void StackGuard::InitThread(const ExecutionAccess& lock) {
510 511 512 513
  if (thread_local_.Initialize(isolate_)) isolate_->heap()->SetStackLimits();
  Isolate::PerIsolateThreadData* per_thread =
      isolate_->FindOrAllocatePerThreadDataForThisThread();
  uintptr_t stored_limit = per_thread->stack_limit();
514
  // You should hold the ExecutionAccess lock when you call this.
515
  if (stored_limit != 0) {
516
    SetStackLimit(stored_limit);
517
  }
518 519 520
}


521 522
// --- C a l l s   t o   n a t i v e s ---

523
#define RETURN_NATIVE_CALL(name, args)                                  \
524 525
  do {                                                                  \
    Handle<Object> argv[] = args;                                       \
526 527
    return Call(isolate,                                                \
                isolate->name##_fun(),                                  \
528
                isolate->js_builtins_object(),                          \
529
                arraysize(argv), argv);                                \
530 531 532
  } while (false)


533 534 535
MaybeHandle<Object> Execution::ToNumber(
    Isolate* isolate, Handle<Object> obj) {
  RETURN_NATIVE_CALL(to_number, { obj });
536 537 538
}


539 540 541
MaybeHandle<Object> Execution::ToString(
    Isolate* isolate, Handle<Object> obj) {
  RETURN_NATIVE_CALL(to_string, { obj });
542 543 544
}


545 546 547
MaybeHandle<Object> Execution::ToDetailString(
    Isolate* isolate, Handle<Object> obj) {
  RETURN_NATIVE_CALL(to_detail_string, { obj });
548 549 550
}


551 552
MaybeHandle<Object> Execution::ToObject(
    Isolate* isolate, Handle<Object> obj) {
553
  if (obj->IsSpecObject()) return obj;
554
  RETURN_NATIVE_CALL(to_object, { obj });
555 556 557
}


558 559 560
MaybeHandle<Object> Execution::ToInteger(
    Isolate* isolate, Handle<Object> obj) {
  RETURN_NATIVE_CALL(to_integer, { obj });
561 562 563
}


564 565 566
MaybeHandle<Object> Execution::ToUint32(
    Isolate* isolate, Handle<Object> obj) {
  RETURN_NATIVE_CALL(to_uint32, { obj });
567 568 569
}


570 571 572
MaybeHandle<Object> Execution::ToInt32(
    Isolate* isolate, Handle<Object> obj) {
  RETURN_NATIVE_CALL(to_int32, { obj });
573 574 575
}


576 577 578 579 580 581
MaybeHandle<Object> Execution::ToLength(
    Isolate* isolate, Handle<Object> obj) {
  RETURN_NATIVE_CALL(to_length, { obj });
}


582
MaybeHandle<Object> Execution::NewDate(Isolate* isolate, double time) {
583
  Handle<Object> time_obj = isolate->factory()->NewNumber(time);
584
  RETURN_NATIVE_CALL(create_date, { time_obj });
585 586 587 588 589 590
}


#undef RETURN_NATIVE_CALL


591 592 593
MaybeHandle<JSRegExp> Execution::NewJSRegExp(Handle<String> pattern,
                                             Handle<String> flags) {
  Isolate* isolate = pattern->GetIsolate();
594
  Handle<JSFunction> function = Handle<JSFunction>(
595 596 597 598 599 600
      isolate->native_context()->regexp_function());
  Handle<Object> re_obj;
  ASSIGN_RETURN_ON_EXCEPTION(
      isolate, re_obj,
      RegExpImpl::CreateRegExpLiteral(function, pattern, flags),
      JSRegExp);
601 602 603 604
  return Handle<JSRegExp>::cast(re_obj);
}


605
Handle<Object> Execution::CharAt(Handle<String> string, uint32_t index) {
606 607 608
  Isolate* isolate = string->GetIsolate();
  Factory* factory = isolate->factory();

609 610
  int int_index = static_cast<int>(index);
  if (int_index < 0 || int_index >= string->length()) {
611
    return factory->undefined_value();
612 613
  }

614
  Handle<Object> char_at = Object::GetProperty(
615 616
      isolate->js_builtins_object(),
      factory->char_at_string()).ToHandleChecked();
617
  if (!char_at->IsJSFunction()) {
618
    return factory->undefined_value();
619 620
  }

621
  Handle<Object> index_object = factory->NewNumberFromInt(int_index);
622
  Handle<Object> index_arg[] = { index_object };
623
  Handle<Object> result;
624 625
  if (!TryCall(Handle<JSFunction>::cast(char_at),
               string,
626
               arraysize(index_arg),
627 628 629
               index_arg).ToHandle(&result)) {
    return factory->undefined_value();
  }
630 631 632 633 634 635 636 637
  return result;
}


Handle<String> Execution::GetStackTraceLine(Handle<Object> recv,
                                            Handle<JSFunction> fun,
                                            Handle<Object> pos,
                                            Handle<Object> is_global) {
638
  Isolate* isolate = fun->GetIsolate();
639
  Handle<Object> args[] = { recv, fun, pos, is_global };
640 641 642
  MaybeHandle<Object> maybe_result =
      TryCall(isolate->get_stack_trace_line_fun(),
              isolate->js_builtins_object(),
643
              arraysize(args),
644 645 646 647
              args);
  Handle<Object> result;
  if (!maybe_result.ToHandle(&result) || !result->IsString()) {
    return isolate->factory()->empty_string();
648 649
  }

650 651 652 653
  return Handle<String>::cast(result);
}


654 655 656 657 658 659 660
void StackGuard::CheckAndHandleGCInterrupt() {
  if (CheckAndClearInterrupt(GC_REQUEST)) {
    isolate_->heap()->HandleGCRequest();
  }
}


661
Object* StackGuard::HandleInterrupts() {
662
  if (CheckAndClearInterrupt(GC_REQUEST)) {
663
    isolate_->heap()->HandleGCRequest();
664
  }
665

666
  if (CheckDebugBreak() || CheckDebugCommand()) {
667
    isolate_->debug()->HandleDebugBreak();
668
  }
669

670 671 672
  if (CheckAndClearInterrupt(TERMINATE_EXECUTION)) {
    return isolate_->TerminateExecution();
  }
673

674 675 676
  if (CheckAndClearInterrupt(DEOPT_MARKED_ALLOCATION_SITES)) {
    isolate_->heap()->DeoptMarkedAllocationSites();
  }
677

678
  if (CheckAndClearInterrupt(INSTALL_CODE)) {
679
    DCHECK(isolate_->concurrent_recompilation_enabled());
680
    isolate_->optimizing_compile_dispatcher()->InstallOptimizedFunctions();
681
  }
682

683
  if (CheckAndClearInterrupt(API_INTERRUPT)) {
684 685
    // Callbacks must be invoked outside of ExecusionAccess lock.
    isolate_->InvokeApiInterruptCallbacks();
686
  }
687

688 689 690 691
  isolate_->counters()->stack_interrupts()->Increment();
  isolate_->counters()->runtime_profiler_ticks()->Increment();
  isolate_->runtime_profiler()->OptimizeNow();

692
  return isolate_->heap()->undefined_value();
693 694
}

695
} }  // namespace v8::internal