blob: da36f769a0a98b3dcf55bb08fc4cf4daf5dc2580 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
Ben Murdoch257744e2011-11-30 15:57:28 +00005#ifndef V8_ISOLATE_INL_H_
6#define V8_ISOLATE_INL_H_
Steve Blocka7e24c12009-10-30 11:49:00 +00007
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/isolate.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009#include "src/objects-inl.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000010
11namespace v8 {
12namespace internal {
13
Steve Blocka7e24c12009-10-30 11:49:00 +000014
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000015void Isolate::set_context(Context* context) {
16 DCHECK(context == NULL || context->IsContext());
17 thread_local_top_.context_ = context;
18}
19
20
21Object* Isolate::pending_exception() {
22 DCHECK(has_pending_exception());
23 DCHECK(!thread_local_top_.pending_exception_->IsException());
24 return thread_local_top_.pending_exception_;
25}
26
27
28void Isolate::set_pending_exception(Object* exception_obj) {
29 DCHECK(!exception_obj->IsException());
30 thread_local_top_.pending_exception_ = exception_obj;
31}
32
33
34void Isolate::clear_pending_exception() {
35 DCHECK(!thread_local_top_.pending_exception_->IsException());
36 thread_local_top_.pending_exception_ = heap_.the_hole_value();
37}
38
39
40bool Isolate::has_pending_exception() {
41 DCHECK(!thread_local_top_.pending_exception_->IsException());
42 return !thread_local_top_.pending_exception_->IsTheHole();
43}
44
45
46void Isolate::clear_pending_message() {
47 thread_local_top_.pending_message_obj_ = heap_.the_hole_value();
48}
49
50
51Object* Isolate::scheduled_exception() {
52 DCHECK(has_scheduled_exception());
53 DCHECK(!thread_local_top_.scheduled_exception_->IsException());
54 return thread_local_top_.scheduled_exception_;
55}
56
57
58bool Isolate::has_scheduled_exception() {
59 DCHECK(!thread_local_top_.scheduled_exception_->IsException());
60 return thread_local_top_.scheduled_exception_ != heap_.the_hole_value();
61}
62
63
64void Isolate::clear_scheduled_exception() {
65 DCHECK(!thread_local_top_.scheduled_exception_->IsException());
66 thread_local_top_.scheduled_exception_ = heap_.the_hole_value();
67}
68
69
70bool Isolate::is_catchable_by_javascript(Object* exception) {
71 return exception != heap()->termination_exception();
72}
73
74
75Handle<JSGlobalObject> Isolate::global_object() {
76 return Handle<JSGlobalObject>(context()->global_object(), this);
77}
78
79
80Isolate::ExceptionScope::ExceptionScope(Isolate* isolate)
81 : isolate_(isolate),
82 pending_exception_(isolate_->pending_exception(), isolate_) {}
83
84
85Isolate::ExceptionScope::~ExceptionScope() {
86 isolate_->set_pending_exception(*pending_exception_);
87}
88
89
90#define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \
91 Handle<type> Isolate::name() { \
92 return Handle<type>(native_context()->name(), this); \
93 } \
94 bool Isolate::is_##name(type* value) { \
95 return native_context()->is_##name(value); \
Ben Murdoch3ef787d2012-04-12 10:51:47 +010096 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000097NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR)
98#undef NATIVE_CONTEXT_FIELD_ACCESSOR
Ben Murdoch3ef787d2012-04-12 10:51:47 +010099
Ben Murdochda12d292016-06-02 14:46:10 +0100100bool Isolate::IsArraySpeciesLookupChainIntact() {
101 if (!FLAG_harmony_species) return true;
102 // Note: It would be nice to have debug checks to make sure that the
103 // species protector is accurate, but this would be hard to do for most of
104 // what the protector stands for:
105 // - You'd need to traverse the heap to check that no Array instance has
106 // a constructor property
107 // - To check that Array[Symbol.species] == Array, JS code has to execute,
108 // but JS cannot be invoked in callstack overflow situations
109 // All that could be checked reliably is that
110 // Array.prototype.constructor == Array. Given that limitation, no check is
111 // done here. In place, there are mjsunit tests harmony/array-species* which
112 // ensure that behavior is correct in various invalid protector cases.
113
114 PropertyCell* species_cell = heap()->species_protector();
115 return species_cell->value()->IsSmi() &&
116 Smi::cast(species_cell->value())->value() == kArrayProtectorValid;
117}
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100118
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000119} // namespace internal
120} // namespace v8
Ben Murdoch257744e2011-11-30 15:57:28 +0000121
122#endif // V8_ISOLATE_INL_H_