Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // Copyright 2015 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5 | #ifndef V8_ISOLATE_INL_H_ |
| 6 | #define V8_ISOLATE_INL_H_ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/isolate.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9 | #include "src/objects-inl.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 14 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 15 | void Isolate::set_context(Context* context) { |
| 16 | DCHECK(context == NULL || context->IsContext()); |
| 17 | thread_local_top_.context_ = context; |
| 18 | } |
| 19 | |
| 20 | |
| 21 | Object* Isolate::pending_exception() { |
| 22 | DCHECK(has_pending_exception()); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 23 | DCHECK(!thread_local_top_.pending_exception_->IsException(this)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 24 | return thread_local_top_.pending_exception_; |
| 25 | } |
| 26 | |
| 27 | |
| 28 | void Isolate::set_pending_exception(Object* exception_obj) { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 29 | DCHECK(!exception_obj->IsException(this)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 30 | thread_local_top_.pending_exception_ = exception_obj; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | void Isolate::clear_pending_exception() { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 35 | DCHECK(!thread_local_top_.pending_exception_->IsException(this)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 36 | thread_local_top_.pending_exception_ = heap_.the_hole_value(); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | bool Isolate::has_pending_exception() { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 41 | DCHECK(!thread_local_top_.pending_exception_->IsException(this)); |
| 42 | return !thread_local_top_.pending_exception_->IsTheHole(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | |
| 46 | void Isolate::clear_pending_message() { |
| 47 | thread_local_top_.pending_message_obj_ = heap_.the_hole_value(); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | Object* Isolate::scheduled_exception() { |
| 52 | DCHECK(has_scheduled_exception()); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 53 | DCHECK(!thread_local_top_.scheduled_exception_->IsException(this)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 54 | return thread_local_top_.scheduled_exception_; |
| 55 | } |
| 56 | |
| 57 | |
| 58 | bool Isolate::has_scheduled_exception() { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 59 | DCHECK(!thread_local_top_.scheduled_exception_->IsException(this)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 60 | return thread_local_top_.scheduled_exception_ != heap_.the_hole_value(); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | void Isolate::clear_scheduled_exception() { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 65 | DCHECK(!thread_local_top_.scheduled_exception_->IsException(this)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 66 | thread_local_top_.scheduled_exception_ = heap_.the_hole_value(); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | bool Isolate::is_catchable_by_javascript(Object* exception) { |
| 71 | return exception != heap()->termination_exception(); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | Handle<JSGlobalObject> Isolate::global_object() { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 76 | return handle(context()->global_object(), this); |
| 77 | } |
| 78 | |
| 79 | Handle<JSObject> Isolate::global_proxy() { |
| 80 | return handle(context()->global_proxy(), this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | |
| 84 | Isolate::ExceptionScope::ExceptionScope(Isolate* isolate) |
| 85 | : isolate_(isolate), |
| 86 | pending_exception_(isolate_->pending_exception(), isolate_) {} |
| 87 | |
| 88 | |
| 89 | Isolate::ExceptionScope::~ExceptionScope() { |
| 90 | isolate_->set_pending_exception(*pending_exception_); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | #define NATIVE_CONTEXT_FIELD_ACCESSOR(index, type, name) \ |
| 95 | Handle<type> Isolate::name() { \ |
| 96 | return Handle<type>(native_context()->name(), this); \ |
| 97 | } \ |
| 98 | bool Isolate::is_##name(type* value) { \ |
| 99 | return native_context()->is_##name(value); \ |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 100 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 101 | NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSOR) |
| 102 | #undef NATIVE_CONTEXT_FIELD_ACCESSOR |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 103 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 104 | bool Isolate::IsArraySpeciesLookupChainIntact() { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 105 | // Note: It would be nice to have debug checks to make sure that the |
| 106 | // species protector is accurate, but this would be hard to do for most of |
| 107 | // what the protector stands for: |
| 108 | // - You'd need to traverse the heap to check that no Array instance has |
| 109 | // a constructor property |
| 110 | // - To check that Array[Symbol.species] == Array, JS code has to execute, |
| 111 | // but JS cannot be invoked in callstack overflow situations |
| 112 | // All that could be checked reliably is that |
| 113 | // Array.prototype.constructor == Array. Given that limitation, no check is |
| 114 | // done here. In place, there are mjsunit tests harmony/array-species* which |
| 115 | // ensure that behavior is correct in various invalid protector cases. |
| 116 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 117 | Cell* species_cell = heap()->species_protector(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 118 | return species_cell->value()->IsSmi() && |
| 119 | Smi::cast(species_cell->value())->value() == kArrayProtectorValid; |
| 120 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 121 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 122 | bool Isolate::IsHasInstanceLookupChainIntact() { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 123 | PropertyCell* has_instance_cell = heap()->has_instance_protector(); |
| 124 | return has_instance_cell->value() == Smi::FromInt(kArrayProtectorValid); |
| 125 | } |
| 126 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 127 | } // namespace internal |
| 128 | } // namespace v8 |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 129 | |
| 130 | #endif // V8_ISOLATE_INL_H_ |