isolate-inl.h 4.31 KB
Newer Older
1 2 3 4
// Copyright 2015 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 6
#ifndef V8_EXECUTION_ISOLATE_INL_H_
#define V8_EXECUTION_ISOLATE_INL_H_
7

8
#include "src/execution/isolate.h"
9
#include "src/objects/cell-inl.h"
10
#include "src/objects/js-function.h"
11
#include "src/objects/objects-inl.h"
12 13
#include "src/objects/oddball.h"
#include "src/objects/property-cell.h"
14
#include "src/objects/regexp-match-info.h"
15
#include "src/objects/shared-function-info.h"
16 17 18 19

namespace v8 {
namespace internal {

20 21 22 23
IsolateAllocationMode Isolate::isolate_allocation_mode() {
  return isolate_allocator_->mode();
}

24
void Isolate::set_context(Context context) {
25
  DCHECK(context.is_null() || context.IsContext());
26
  thread_local_top()->context_ = context;
27 28
}

29
Handle<NativeContext> Isolate::native_context() {
30
  DCHECK(!context().is_null());
31
  return handle(context().native_context(), this);
32 33
}

34
NativeContext Isolate::raw_native_context() {
35
  DCHECK(!context().is_null());
36
  return context().native_context();
37
}
38

39
Object Isolate::pending_exception() {
40
  DCHECK(has_pending_exception());
41
  DCHECK(!thread_local_top()->pending_exception_.IsException(this));
42
  return thread_local_top()->pending_exception_;
43 44
}

45
void Isolate::set_pending_exception(Object exception_obj) {
46
  DCHECK(!exception_obj.IsException(this));
47
  thread_local_top()->pending_exception_ = exception_obj;
48 49 50
}

void Isolate::clear_pending_exception() {
51
  DCHECK(!thread_local_top()->pending_exception_.IsException(this));
52
  thread_local_top()->pending_exception_ = ReadOnlyRoots(this).the_hole_value();
53 54 55
}

bool Isolate::has_pending_exception() {
56 57
  DCHECK(!thread_local_top()->pending_exception_.IsException(this));
  return !thread_local_top()->pending_exception_.IsTheHole(this);
58 59 60
}

void Isolate::clear_pending_message() {
61 62
  thread_local_top()->pending_message_obj_ =
      ReadOnlyRoots(this).the_hole_value();
63 64
}

65
Object Isolate::scheduled_exception() {
66
  DCHECK(has_scheduled_exception());
67
  DCHECK(!thread_local_top()->scheduled_exception_.IsException(this));
68
  return thread_local_top()->scheduled_exception_;
69 70 71
}

bool Isolate::has_scheduled_exception() {
72
  DCHECK(!thread_local_top()->scheduled_exception_.IsException(this));
73
  return thread_local_top()->scheduled_exception_ !=
74
         ReadOnlyRoots(this).the_hole_value();
75 76 77
}

void Isolate::clear_scheduled_exception() {
78
  DCHECK(!thread_local_top()->scheduled_exception_.IsException(this));
79 80
  thread_local_top()->scheduled_exception_ =
      ReadOnlyRoots(this).the_hole_value();
81 82
}

83
bool Isolate::is_catchable_by_javascript(Object exception) {
84
  return exception != ReadOnlyRoots(heap()).termination_exception();
85 86
}

87 88 89 90 91 92 93 94 95 96 97 98
bool Isolate::is_catchable_by_wasm(Object exception) {
  if (!is_catchable_by_javascript(exception)) return false;
  if (!exception.IsJSObject()) return true;
  // We don't allocate, but the LookupIterator interface expects a handle.
  DisallowHeapAllocation no_gc;
  HandleScope handle_scope(this);
  LookupIterator it(this, handle(JSReceiver::cast(exception), this),
                    factory()->wasm_uncatchable_symbol(),
                    LookupIterator::OWN_SKIP_INTERCEPTOR);
  return !JSReceiver::HasProperty(&it).FromJust();
}

99
void Isolate::FireBeforeCallEnteredCallback() {
100 101 102 103 104
  for (auto& callback : before_call_entered_callbacks_) {
    callback(reinterpret_cast<v8::Isolate*>(this));
  }
}

105
Handle<JSGlobalObject> Isolate::global_object() {
106
  return handle(context().global_object(), this);
107 108
}

109
Handle<JSGlobalProxy> Isolate::global_proxy() {
110
  return handle(context().global_proxy(), this);
111 112 113 114 115 116 117 118 119 120
}

Isolate::ExceptionScope::ExceptionScope(Isolate* isolate)
    : isolate_(isolate),
      pending_exception_(isolate_->pending_exception(), isolate_) {}

Isolate::ExceptionScope::~ExceptionScope() {
  isolate_->set_pending_exception(*pending_exception_);
}

121 122 123 124 125 126
#define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name)    \
  Handle<type> Isolate::name() {                            \
    return Handle<type>(raw_native_context().name(), this); \
  }                                                         \
  bool Isolate::is_##name(type value) {                     \
    return raw_native_context().is_##name(value);           \
127 128 129 130 131 132 133
  }
NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
#undef NATIVE_CONTEXT_FIELD_ACCESSOR

}  // namespace internal
}  // namespace v8

134
#endif  // V8_EXECUTION_ISOLATE_INL_H_