sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "api.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 31 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 32 | #include "arguments.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | #include "bootstrapper.h" |
| 34 | #include "compiler.h" |
| 35 | #include "debug.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 36 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | #include "execution.h" |
| 38 | #include "global-handles.h" |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 39 | #include "heap-profiler.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 40 | #include "messages.h" |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 41 | #include "natives.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 42 | #include "parser.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 43 | #include "platform.h" |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 44 | #include "profile-generator-inl.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 45 | #include "runtime-profiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | #include "serialize.h" |
| 47 | #include "snapshot.h" |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 48 | #include "v8threads.h" |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 49 | #include "version.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 50 | #include "vm-state-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 51 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 52 | #include "../include/v8-profiler.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 53 | #include "../include/v8-testing.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 54 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 55 | #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 56 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 57 | #define ENTER_V8(isolate) \ |
| 58 | ASSERT((isolate)->IsInitialized()); \ |
| 59 | i::VMState __state__((isolate), i::OTHER) |
| 60 | #define LEAVE_V8(isolate) \ |
| 61 | i::VMState __state__((isolate), i::EXTERNAL) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 62 | |
| 63 | namespace v8 { |
| 64 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 65 | #define ON_BAILOUT(isolate, location, code) \ |
| 66 | if (IsDeadCheck(isolate, location) || \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 67 | IsExecutionTerminatingCheck(isolate)) { \ |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 68 | code; \ |
| 69 | UNREACHABLE(); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 73 | #define EXCEPTION_PREAMBLE(isolate) \ |
| 74 | (isolate)->handle_scope_implementer()->IncrementCallDepth(); \ |
| 75 | ASSERT(!(isolate)->external_caught_exception()); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | bool has_pending_exception = false |
| 77 | |
| 78 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 79 | #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 80 | do { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 81 | i::HandleScopeImplementer* handle_scope_implementer = \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 82 | (isolate)->handle_scope_implementer(); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 83 | handle_scope_implementer->DecrementCallDepth(); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 84 | if (has_pending_exception) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 85 | if (handle_scope_implementer->CallDepthIsZero() && \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 86 | (isolate)->is_out_of_memory()) { \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 87 | if (!(isolate)->ignore_out_of_memory()) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 88 | i::V8::FatalProcessOutOfMemory(NULL); \ |
| 89 | } \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 90 | bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 91 | (isolate)->OptionalRescheduleException(call_depth_is_zero); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | return value; \ |
| 93 | } \ |
| 94 | } while (false) |
| 95 | |
| 96 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 97 | #define API_ENTRY_CHECK(isolate, msg) \ |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 98 | do { \ |
| 99 | if (v8::Locker::IsActive()) { \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 100 | ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \ |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 101 | msg, \ |
| 102 | "Entering the V8 API without proper locking in place"); \ |
| 103 | } \ |
| 104 | } while (false) |
| 105 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 106 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 107 | // --- E x c e p t i o n B e h a v i o r --- |
| 108 | |
| 109 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 110 | static void DefaultFatalErrorHandler(const char* location, |
| 111 | const char* message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 112 | i::VMState __state__(i::Isolate::Current(), i::OTHER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | API_Fatal(location, message); |
| 114 | } |
| 115 | |
| 116 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 117 | static FatalErrorCallback GetFatalErrorHandler() { |
| 118 | i::Isolate* isolate = i::Isolate::Current(); |
| 119 | if (isolate->exception_behavior() == NULL) { |
| 120 | isolate->set_exception_behavior(DefaultFatalErrorHandler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 121 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 122 | return isolate->exception_behavior(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 126 | void i::FatalProcessOutOfMemory(const char* location) { |
| 127 | i::V8::FatalProcessOutOfMemory(location, false); |
| 128 | } |
| 129 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 130 | |
| 131 | // When V8 cannot allocated memory FatalProcessOutOfMemory is called. |
| 132 | // The default fatal error handler is called and execution is stopped. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 133 | void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 134 | i::HeapStats heap_stats; |
| 135 | int start_marker; |
| 136 | heap_stats.start_marker = &start_marker; |
| 137 | int new_space_size; |
| 138 | heap_stats.new_space_size = &new_space_size; |
| 139 | int new_space_capacity; |
| 140 | heap_stats.new_space_capacity = &new_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 141 | intptr_t old_pointer_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 142 | heap_stats.old_pointer_space_size = &old_pointer_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 143 | intptr_t old_pointer_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 144 | heap_stats.old_pointer_space_capacity = &old_pointer_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 145 | intptr_t old_data_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 146 | heap_stats.old_data_space_size = &old_data_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 147 | intptr_t old_data_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 148 | heap_stats.old_data_space_capacity = &old_data_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 149 | intptr_t code_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 150 | heap_stats.code_space_size = &code_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 151 | intptr_t code_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 152 | heap_stats.code_space_capacity = &code_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 153 | intptr_t map_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 154 | heap_stats.map_space_size = &map_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 155 | intptr_t map_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 156 | heap_stats.map_space_capacity = &map_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 157 | intptr_t cell_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 158 | heap_stats.cell_space_size = &cell_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 159 | intptr_t cell_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 160 | heap_stats.cell_space_capacity = &cell_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 161 | intptr_t lo_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 162 | heap_stats.lo_space_size = &lo_space_size; |
| 163 | int global_handle_count; |
| 164 | heap_stats.global_handle_count = &global_handle_count; |
| 165 | int weak_global_handle_count; |
| 166 | heap_stats.weak_global_handle_count = &weak_global_handle_count; |
| 167 | int pending_global_handle_count; |
| 168 | heap_stats.pending_global_handle_count = &pending_global_handle_count; |
| 169 | int near_death_global_handle_count; |
| 170 | heap_stats.near_death_global_handle_count = &near_death_global_handle_count; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 171 | int free_global_handle_count; |
| 172 | heap_stats.free_global_handle_count = &free_global_handle_count; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 173 | intptr_t memory_allocator_size; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 174 | heap_stats.memory_allocator_size = &memory_allocator_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 175 | intptr_t memory_allocator_capacity; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 176 | heap_stats.memory_allocator_capacity = &memory_allocator_capacity; |
| 177 | int objects_per_type[LAST_TYPE + 1] = {0}; |
| 178 | heap_stats.objects_per_type = objects_per_type; |
| 179 | int size_per_type[LAST_TYPE + 1] = {0}; |
| 180 | heap_stats.size_per_type = size_per_type; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 181 | int os_error; |
| 182 | heap_stats.os_error = &os_error; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 183 | int end_marker; |
| 184 | heap_stats.end_marker = &end_marker; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 185 | i::Isolate* isolate = i::Isolate::Current(); |
| 186 | isolate->heap()->RecordStats(&heap_stats, take_snapshot); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 187 | i::V8::SetFatalError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 188 | FatalErrorCallback callback = GetFatalErrorHandler(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 189 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 190 | LEAVE_V8(isolate); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 191 | callback(location, "Allocation failed - process out of memory"); |
| 192 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | // If the callback returns, we stop execution. |
| 194 | UNREACHABLE(); |
| 195 | } |
| 196 | |
| 197 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 198 | bool Utils::ReportApiFailure(const char* location, const char* message) { |
| 199 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 200 | callback(location, message); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 201 | i::V8::SetFatalError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 202 | return false; |
| 203 | } |
| 204 | |
| 205 | |
| 206 | bool V8::IsDead() { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 207 | return i::V8::IsDead(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | |
| 211 | static inline bool ApiCheck(bool condition, |
| 212 | const char* location, |
| 213 | const char* message) { |
| 214 | return condition ? true : Utils::ReportApiFailure(location, message); |
| 215 | } |
| 216 | |
| 217 | |
| 218 | static bool ReportV8Dead(const char* location) { |
| 219 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 220 | callback(location, "V8 is no longer usable"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 221 | return true; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | static bool ReportEmptyHandle(const char* location) { |
| 226 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 227 | callback(location, "Reading from empty handle"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 228 | return true; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 233 | * IsDeadCheck checks that the vm is usable. If, for instance, the vm has been |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 234 | * out of memory at some point this check will fail. It should be called on |
| 235 | * entry to all methods that touch anything in the heap, except destructors |
| 236 | * which you sometimes can't avoid calling after the vm has crashed. Functions |
| 237 | * that call EnsureInitialized or ON_BAILOUT don't have to also call |
| 238 | * IsDeadCheck. ON_BAILOUT has the advantage over EnsureInitialized that you |
| 239 | * can arrange to return if the VM is dead. This is needed to ensure that no VM |
| 240 | * heap allocations are attempted on a dead VM. EnsureInitialized has the |
| 241 | * advantage over ON_BAILOUT that it actually initializes the VM if this has not |
| 242 | * yet been done. |
| 243 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 244 | static inline bool IsDeadCheck(i::Isolate* isolate, const char* location) { |
| 245 | return !isolate->IsInitialized() |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 246 | && i::V8::IsDead() ? ReportV8Dead(location) : false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 250 | static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { |
| 251 | if (!isolate->IsInitialized()) return false; |
| 252 | if (isolate->has_scheduled_exception()) { |
| 253 | return isolate->scheduled_exception() == |
| 254 | isolate->heap()->termination_exception(); |
| 255 | } |
| 256 | return false; |
| 257 | } |
| 258 | |
| 259 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 260 | static inline bool EmptyCheck(const char* location, v8::Handle<v8::Data> obj) { |
| 261 | return obj.IsEmpty() ? ReportEmptyHandle(location) : false; |
| 262 | } |
| 263 | |
| 264 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 265 | static inline bool EmptyCheck(const char* location, const v8::Data* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 266 | return (obj == 0) ? ReportEmptyHandle(location) : false; |
| 267 | } |
| 268 | |
| 269 | // --- S t a t i c s --- |
| 270 | |
| 271 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 272 | static bool InitializeHelper() { |
| 273 | if (i::Snapshot::Initialize()) return true; |
| 274 | return i::V8::Initialize(NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 278 | static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, |
| 279 | const char* location) { |
| 280 | if (IsDeadCheck(isolate, location)) return false; |
| 281 | if (isolate != NULL) { |
| 282 | if (isolate->IsInitialized()) return true; |
| 283 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 284 | ASSERT(isolate == i::Isolate::Current()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 285 | return ApiCheck(InitializeHelper(), location, "Error initializing V8"); |
| 286 | } |
| 287 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 288 | // Some initializing API functions are called early and may be |
| 289 | // called on a thread different from static initializer thread. |
| 290 | // If Isolate API is used, Isolate::Enter() will initialize TLS so |
| 291 | // Isolate::Current() works. If it's a legacy case, then the thread |
| 292 | // may not have TLS initialized yet. However, in initializing APIs it |
| 293 | // may be too early to call EnsureInitialized() - some pre-init |
| 294 | // parameters still have to be configured. |
| 295 | static inline i::Isolate* EnterIsolateIfNeeded() { |
| 296 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 297 | if (isolate != NULL) |
| 298 | return isolate; |
| 299 | |
| 300 | i::Isolate::EnterDefaultIsolate(); |
| 301 | isolate = i::Isolate::Current(); |
| 302 | return isolate; |
| 303 | } |
| 304 | |
| 305 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 306 | StartupDataDecompressor::StartupDataDecompressor() |
| 307 | : raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) { |
| 308 | for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { |
| 309 | raw_data[i] = NULL; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | |
| 314 | StartupDataDecompressor::~StartupDataDecompressor() { |
| 315 | for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { |
| 316 | i::DeleteArray(raw_data[i]); |
| 317 | } |
| 318 | i::DeleteArray(raw_data); |
| 319 | } |
| 320 | |
| 321 | |
| 322 | int StartupDataDecompressor::Decompress() { |
| 323 | int compressed_data_count = V8::GetCompressedStartupDataCount(); |
| 324 | StartupData* compressed_data = |
| 325 | i::NewArray<StartupData>(compressed_data_count); |
| 326 | V8::GetCompressedStartupData(compressed_data); |
| 327 | for (int i = 0; i < compressed_data_count; ++i) { |
| 328 | char* decompressed = raw_data[i] = |
| 329 | i::NewArray<char>(compressed_data[i].raw_size); |
| 330 | if (compressed_data[i].compressed_size != 0) { |
| 331 | int result = DecompressData(decompressed, |
| 332 | &compressed_data[i].raw_size, |
| 333 | compressed_data[i].data, |
| 334 | compressed_data[i].compressed_size); |
| 335 | if (result != 0) return result; |
| 336 | } else { |
| 337 | ASSERT_EQ(0, compressed_data[i].raw_size); |
| 338 | } |
| 339 | compressed_data[i].data = decompressed; |
| 340 | } |
| 341 | V8::SetDecompressedStartupData(compressed_data); |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 346 | StartupData::CompressionAlgorithm V8::GetCompressedStartupDataAlgorithm() { |
| 347 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 348 | return StartupData::kBZip2; |
| 349 | #else |
| 350 | return StartupData::kUncompressed; |
| 351 | #endif |
| 352 | } |
| 353 | |
| 354 | |
| 355 | enum CompressedStartupDataItems { |
| 356 | kSnapshot = 0, |
| 357 | kSnapshotContext, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 358 | kLibraries, |
| 359 | kExperimentalLibraries, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 360 | kCompressedStartupDataCount |
| 361 | }; |
| 362 | |
| 363 | int V8::GetCompressedStartupDataCount() { |
| 364 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 365 | return kCompressedStartupDataCount; |
| 366 | #else |
| 367 | return 0; |
| 368 | #endif |
| 369 | } |
| 370 | |
| 371 | |
| 372 | void V8::GetCompressedStartupData(StartupData* compressed_data) { |
| 373 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 374 | compressed_data[kSnapshot].data = |
| 375 | reinterpret_cast<const char*>(i::Snapshot::data()); |
| 376 | compressed_data[kSnapshot].compressed_size = i::Snapshot::size(); |
| 377 | compressed_data[kSnapshot].raw_size = i::Snapshot::raw_size(); |
| 378 | |
| 379 | compressed_data[kSnapshotContext].data = |
| 380 | reinterpret_cast<const char*>(i::Snapshot::context_data()); |
| 381 | compressed_data[kSnapshotContext].compressed_size = |
| 382 | i::Snapshot::context_size(); |
| 383 | compressed_data[kSnapshotContext].raw_size = i::Snapshot::context_raw_size(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 384 | |
| 385 | i::Vector<const i::byte> libraries_source = i::Natives::GetScriptsSource(); |
| 386 | compressed_data[kLibraries].data = |
| 387 | reinterpret_cast<const char*>(libraries_source.start()); |
| 388 | compressed_data[kLibraries].compressed_size = libraries_source.length(); |
| 389 | compressed_data[kLibraries].raw_size = i::Natives::GetRawScriptsSize(); |
| 390 | |
| 391 | i::Vector<const i::byte> exp_libraries_source = |
| 392 | i::ExperimentalNatives::GetScriptsSource(); |
| 393 | compressed_data[kExperimentalLibraries].data = |
| 394 | reinterpret_cast<const char*>(exp_libraries_source.start()); |
| 395 | compressed_data[kExperimentalLibraries].compressed_size = |
| 396 | exp_libraries_source.length(); |
| 397 | compressed_data[kExperimentalLibraries].raw_size = |
| 398 | i::ExperimentalNatives::GetRawScriptsSize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 399 | #endif |
| 400 | } |
| 401 | |
| 402 | |
| 403 | void V8::SetDecompressedStartupData(StartupData* decompressed_data) { |
| 404 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 405 | ASSERT_EQ(i::Snapshot::raw_size(), decompressed_data[kSnapshot].raw_size); |
| 406 | i::Snapshot::set_raw_data( |
| 407 | reinterpret_cast<const i::byte*>(decompressed_data[kSnapshot].data)); |
| 408 | |
| 409 | ASSERT_EQ(i::Snapshot::context_raw_size(), |
| 410 | decompressed_data[kSnapshotContext].raw_size); |
| 411 | i::Snapshot::set_context_raw_data( |
| 412 | reinterpret_cast<const i::byte*>( |
| 413 | decompressed_data[kSnapshotContext].data)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 414 | |
| 415 | ASSERT_EQ(i::Natives::GetRawScriptsSize(), |
| 416 | decompressed_data[kLibraries].raw_size); |
| 417 | i::Vector<const char> libraries_source( |
| 418 | decompressed_data[kLibraries].data, |
| 419 | decompressed_data[kLibraries].raw_size); |
| 420 | i::Natives::SetRawScriptsSource(libraries_source); |
| 421 | |
| 422 | ASSERT_EQ(i::ExperimentalNatives::GetRawScriptsSize(), |
| 423 | decompressed_data[kExperimentalLibraries].raw_size); |
| 424 | i::Vector<const char> exp_libraries_source( |
| 425 | decompressed_data[kExperimentalLibraries].data, |
| 426 | decompressed_data[kExperimentalLibraries].raw_size); |
| 427 | i::ExperimentalNatives::SetRawScriptsSource(exp_libraries_source); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 428 | #endif |
| 429 | } |
| 430 | |
| 431 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 432 | void V8::SetFatalErrorHandler(FatalErrorCallback that) { |
| 433 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 434 | isolate->set_exception_behavior(that); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 438 | void V8::SetAllowCodeGenerationFromStringsCallback( |
| 439 | AllowCodeGenerationFromStringsCallback callback) { |
| 440 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 441 | isolate->set_allow_code_gen_callback(callback); |
| 442 | } |
| 443 | |
| 444 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 445 | #ifdef DEBUG |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 446 | void ImplementationUtilities::ZapHandleRange(i::Object** begin, |
| 447 | i::Object** end) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 448 | i::HandleScope::ZapRange(begin, end); |
| 449 | } |
| 450 | #endif |
| 451 | |
| 452 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 453 | void V8::SetFlagsFromString(const char* str, int length) { |
| 454 | i::FlagList::SetFlagsFromString(str, length); |
| 455 | } |
| 456 | |
| 457 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 458 | void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { |
| 459 | i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); |
| 460 | } |
| 461 | |
| 462 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 463 | v8::Handle<Value> ThrowException(v8::Handle<v8::Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 464 | i::Isolate* isolate = i::Isolate::Current(); |
| 465 | if (IsDeadCheck(isolate, "v8::ThrowException()")) { |
| 466 | return v8::Handle<Value>(); |
| 467 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 468 | ENTER_V8(isolate); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 469 | // If we're passed an empty handle, we throw an undefined exception |
| 470 | // to deal more gracefully with out of memory situations. |
| 471 | if (value.IsEmpty()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 472 | isolate->ScheduleThrow(isolate->heap()->undefined_value()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 473 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 474 | isolate->ScheduleThrow(*Utils::OpenHandle(*value)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 475 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 476 | return v8::Undefined(); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | RegisteredExtension* RegisteredExtension::first_extension_ = NULL; |
| 481 | |
| 482 | |
| 483 | RegisteredExtension::RegisteredExtension(Extension* extension) |
| 484 | : extension_(extension), state_(UNVISITED) { } |
| 485 | |
| 486 | |
| 487 | void RegisteredExtension::Register(RegisteredExtension* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 488 | that->next_ = first_extension_; |
| 489 | first_extension_ = that; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | |
| 493 | void RegisterExtension(Extension* that) { |
| 494 | RegisteredExtension* extension = new RegisteredExtension(that); |
| 495 | RegisteredExtension::Register(extension); |
| 496 | } |
| 497 | |
| 498 | |
| 499 | Extension::Extension(const char* name, |
| 500 | const char* source, |
| 501 | int dep_count, |
| 502 | const char** deps) |
| 503 | : name_(name), |
| 504 | source_(source), |
| 505 | dep_count_(dep_count), |
| 506 | deps_(deps), |
| 507 | auto_enable_(false) { } |
| 508 | |
| 509 | |
| 510 | v8::Handle<Primitive> Undefined() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 511 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 512 | if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) { |
| 513 | return v8::Handle<v8::Primitive>(); |
| 514 | } |
| 515 | return v8::Handle<Primitive>(ToApi<Primitive>( |
| 516 | isolate->factory()->undefined_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | |
| 520 | v8::Handle<Primitive> Null() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 521 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 522 | if (!EnsureInitializedForIsolate(isolate, "v8::Null()")) { |
| 523 | return v8::Handle<v8::Primitive>(); |
| 524 | } |
| 525 | return v8::Handle<Primitive>( |
| 526 | ToApi<Primitive>(isolate->factory()->null_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | |
| 530 | v8::Handle<Boolean> True() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 531 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 532 | if (!EnsureInitializedForIsolate(isolate, "v8::True()")) { |
| 533 | return v8::Handle<Boolean>(); |
| 534 | } |
| 535 | return v8::Handle<Boolean>( |
| 536 | ToApi<Boolean>(isolate->factory()->true_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
| 540 | v8::Handle<Boolean> False() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 541 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 542 | if (!EnsureInitializedForIsolate(isolate, "v8::False()")) { |
| 543 | return v8::Handle<Boolean>(); |
| 544 | } |
| 545 | return v8::Handle<Boolean>( |
| 546 | ToApi<Boolean>(isolate->factory()->false_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | |
| 550 | ResourceConstraints::ResourceConstraints() |
| 551 | : max_young_space_size_(0), |
| 552 | max_old_space_size_(0), |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 553 | max_executable_size_(0), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 554 | stack_limit_(NULL) { } |
| 555 | |
| 556 | |
| 557 | bool SetResourceConstraints(ResourceConstraints* constraints) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 558 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 559 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 560 | int young_space_size = constraints->max_young_space_size(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 561 | int old_gen_size = constraints->max_old_space_size(); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 562 | int max_executable_size = constraints->max_executable_size(); |
| 563 | if (young_space_size != 0 || old_gen_size != 0 || max_executable_size != 0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 564 | // After initialization it's too late to change Heap constraints. |
| 565 | ASSERT(!isolate->IsInitialized()); |
| 566 | bool result = isolate->heap()->ConfigureHeap(young_space_size / 2, |
| 567 | old_gen_size, |
| 568 | max_executable_size); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 569 | if (!result) return false; |
| 570 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 571 | if (constraints->stack_limit() != NULL) { |
| 572 | uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 573 | isolate->stack_guard()->SetStackLimit(limit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 574 | } |
| 575 | return true; |
| 576 | } |
| 577 | |
| 578 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 579 | i::Object** V8::GlobalizeReference(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 580 | i::Isolate* isolate = i::Isolate::Current(); |
| 581 | if (IsDeadCheck(isolate, "V8::Persistent::New")) return NULL; |
| 582 | LOG_API(isolate, "Persistent::New"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 583 | i::Handle<i::Object> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 584 | isolate->global_handles()->Create(*obj); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 585 | return result.location(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 589 | void V8::MakeWeak(i::Object** object, void* parameters, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 590 | WeakReferenceCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 591 | i::Isolate* isolate = i::Isolate::Current(); |
| 592 | LOG_API(isolate, "MakeWeak"); |
| 593 | isolate->global_handles()->MakeWeak(object, parameters, |
| 594 | callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 598 | void V8::ClearWeak(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 599 | i::Isolate* isolate = i::Isolate::Current(); |
| 600 | LOG_API(isolate, "ClearWeak"); |
| 601 | isolate->global_handles()->ClearWeakness(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 605 | void V8::MarkIndependent(i::Object** object) { |
| 606 | i::Isolate* isolate = i::Isolate::Current(); |
| 607 | LOG_API(isolate, "MakeIndependent"); |
| 608 | isolate->global_handles()->MarkIndependent(object); |
| 609 | } |
| 610 | |
| 611 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 612 | bool V8::IsGlobalNearDeath(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 613 | i::Isolate* isolate = i::Isolate::Current(); |
| 614 | LOG_API(isolate, "IsGlobalNearDeath"); |
| 615 | if (!isolate->IsInitialized()) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 616 | return i::GlobalHandles::IsNearDeath(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 620 | bool V8::IsGlobalWeak(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 621 | i::Isolate* isolate = i::Isolate::Current(); |
| 622 | LOG_API(isolate, "IsGlobalWeak"); |
| 623 | if (!isolate->IsInitialized()) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 624 | return i::GlobalHandles::IsWeak(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 628 | void V8::DisposeGlobal(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 629 | i::Isolate* isolate = i::Isolate::Current(); |
| 630 | LOG_API(isolate, "DisposeGlobal"); |
| 631 | if (!isolate->IsInitialized()) return; |
| 632 | isolate->global_handles()->Destroy(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | // --- H a n d l e s --- |
| 636 | |
| 637 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 638 | HandleScope::HandleScope() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 639 | i::Isolate* isolate = i::Isolate::Current(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 640 | API_ENTRY_CHECK(isolate, "HandleScope::HandleScope"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 641 | v8::ImplementationUtilities::HandleScopeData* current = |
| 642 | isolate->handle_scope_data(); |
| 643 | isolate_ = isolate; |
| 644 | prev_next_ = current->next; |
| 645 | prev_limit_ = current->limit; |
| 646 | is_closed_ = false; |
| 647 | current->level++; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | |
| 651 | HandleScope::~HandleScope() { |
| 652 | if (!is_closed_) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 653 | Leave(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 654 | } |
| 655 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 656 | |
| 657 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 658 | void HandleScope::Leave() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 659 | ASSERT(isolate_ == i::Isolate::Current()); |
| 660 | v8::ImplementationUtilities::HandleScopeData* current = |
| 661 | isolate_->handle_scope_data(); |
| 662 | current->level--; |
| 663 | ASSERT(current->level >= 0); |
| 664 | current->next = prev_next_; |
| 665 | if (current->limit != prev_limit_) { |
| 666 | current->limit = prev_limit_; |
| 667 | i::HandleScope::DeleteExtensions(isolate_); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | #ifdef DEBUG |
| 671 | i::HandleScope::ZapRange(prev_next_, prev_limit_); |
| 672 | #endif |
| 673 | } |
| 674 | |
| 675 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 676 | int HandleScope::NumberOfHandles() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 677 | EnsureInitializedForIsolate( |
| 678 | i::Isolate::Current(), "HandleScope::NumberOfHandles"); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 679 | return i::HandleScope::NumberOfHandles(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 683 | i::Object** HandleScope::CreateHandle(i::Object* value) { |
| 684 | return i::HandleScope::CreateHandle(value, i::Isolate::Current()); |
| 685 | } |
| 686 | |
| 687 | |
| 688 | i::Object** HandleScope::CreateHandle(i::HeapObject* value) { |
| 689 | ASSERT(value->IsHeapObject()); |
| 690 | return reinterpret_cast<i::Object**>( |
| 691 | i::HandleScope::CreateHandle(value, value->GetIsolate())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | |
| 695 | void Context::Enter() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 696 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 697 | i::Isolate* isolate = env->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 698 | if (IsDeadCheck(isolate, "v8::Context::Enter()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 699 | ENTER_V8(isolate); |
| 700 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 701 | isolate->handle_scope_implementer()->EnterContext(env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 702 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 703 | isolate->handle_scope_implementer()->SaveContext(isolate->context()); |
| 704 | isolate->set_context(*env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | |
| 708 | void Context::Exit() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 709 | // Exit is essentially a static function and doesn't use the |
| 710 | // receiver, so we have to get the current isolate from the thread |
| 711 | // local. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 712 | i::Isolate* isolate = i::Isolate::Current(); |
| 713 | if (!isolate->IsInitialized()) return; |
| 714 | |
| 715 | if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(), |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 716 | "v8::Context::Exit()", |
| 717 | "Cannot exit non-entered context")) { |
| 718 | return; |
| 719 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 720 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 721 | // Content of 'last_context' could be NULL. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 722 | i::Context* last_context = |
| 723 | isolate->handle_scope_implementer()->RestoreContext(); |
| 724 | isolate->set_context(last_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 728 | void Context::SetData(v8::Handle<String> data) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 729 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 730 | i::Isolate* isolate = env->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 731 | if (IsDeadCheck(isolate, "v8::Context::SetData()")) return; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 732 | i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
| 733 | ASSERT(env->IsGlobalContext()); |
| 734 | if (env->IsGlobalContext()) { |
| 735 | env->set_data(*raw_data); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | |
| 739 | |
| 740 | v8::Local<v8::Value> Context::GetData() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 741 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 742 | i::Isolate* isolate = env->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 743 | if (IsDeadCheck(isolate, "v8::Context::GetData()")) { |
| 744 | return v8::Local<Value>(); |
| 745 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 746 | i::Object* raw_result = NULL; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 747 | ASSERT(env->IsGlobalContext()); |
| 748 | if (env->IsGlobalContext()) { |
| 749 | raw_result = env->data(); |
| 750 | } else { |
| 751 | return Local<Value>(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 752 | } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 753 | i::Handle<i::Object> result(raw_result, isolate); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 754 | return Utils::ToLocal(result); |
| 755 | } |
| 756 | |
| 757 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 758 | i::Object** v8::HandleScope::RawClose(i::Object** value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 759 | if (!ApiCheck(!is_closed_, |
| 760 | "v8::HandleScope::Close()", |
| 761 | "Local scope has already been closed")) { |
| 762 | return 0; |
| 763 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 764 | LOG_API(isolate_, "CloseHandleScope"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 765 | |
| 766 | // Read the result before popping the handle block. |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 767 | i::Object* result = NULL; |
| 768 | if (value != NULL) { |
| 769 | result = *value; |
| 770 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 771 | is_closed_ = true; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 772 | Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 773 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 774 | if (value == NULL) { |
| 775 | return NULL; |
| 776 | } |
| 777 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 778 | // Allocate a new handle on the previous handle block. |
| 779 | i::Handle<i::Object> handle(result); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 780 | return handle.location(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | |
| 784 | // --- N e a n d e r --- |
| 785 | |
| 786 | |
| 787 | // A constructor cannot easily return an error value, therefore it is necessary |
| 788 | // to check for a dead VM with ON_BAILOUT before constructing any Neander |
| 789 | // objects. To remind you about this there is no HandleScope in the |
| 790 | // NeanderObject constructor. When you add one to the site calling the |
| 791 | // constructor you should check that you ensured the VM was not dead first. |
| 792 | NeanderObject::NeanderObject(int size) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 793 | i::Isolate* isolate = i::Isolate::Current(); |
| 794 | EnsureInitializedForIsolate(isolate, "v8::Nowhere"); |
| 795 | ENTER_V8(isolate); |
| 796 | value_ = isolate->factory()->NewNeanderObject(); |
| 797 | i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 798 | value_->set_elements(*elements); |
| 799 | } |
| 800 | |
| 801 | |
| 802 | int NeanderObject::size() { |
| 803 | return i::FixedArray::cast(value_->elements())->length(); |
| 804 | } |
| 805 | |
| 806 | |
| 807 | NeanderArray::NeanderArray() : obj_(2) { |
| 808 | obj_.set(0, i::Smi::FromInt(0)); |
| 809 | } |
| 810 | |
| 811 | |
| 812 | int NeanderArray::length() { |
| 813 | return i::Smi::cast(obj_.get(0))->value(); |
| 814 | } |
| 815 | |
| 816 | |
| 817 | i::Object* NeanderArray::get(int offset) { |
| 818 | ASSERT(0 <= offset); |
| 819 | ASSERT(offset < length()); |
| 820 | return obj_.get(offset + 1); |
| 821 | } |
| 822 | |
| 823 | |
| 824 | // This method cannot easily return an error value, therefore it is necessary |
| 825 | // to check for a dead VM with ON_BAILOUT before calling it. To remind you |
| 826 | // about this there is no HandleScope in this method. When you add one to the |
| 827 | // site calling this method you should check that you ensured the VM was not |
| 828 | // dead first. |
| 829 | void NeanderArray::add(i::Handle<i::Object> value) { |
| 830 | int length = this->length(); |
| 831 | int size = obj_.size(); |
| 832 | if (length == size - 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 833 | i::Handle<i::FixedArray> new_elms = FACTORY->NewFixedArray(2 * size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 834 | for (int i = 0; i < length; i++) |
| 835 | new_elms->set(i + 1, get(i)); |
| 836 | obj_.value()->set_elements(*new_elms); |
| 837 | } |
| 838 | obj_.set(length + 1, *value); |
| 839 | obj_.set(0, i::Smi::FromInt(length + 1)); |
| 840 | } |
| 841 | |
| 842 | |
| 843 | void NeanderArray::set(int index, i::Object* value) { |
| 844 | if (index < 0 || index >= this->length()) return; |
| 845 | obj_.set(index + 1, value); |
| 846 | } |
| 847 | |
| 848 | |
| 849 | // --- T e m p l a t e --- |
| 850 | |
| 851 | |
| 852 | static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { |
| 853 | that->set_tag(i::Smi::FromInt(type)); |
| 854 | } |
| 855 | |
| 856 | |
| 857 | void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, |
| 858 | v8::PropertyAttribute attribute) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 859 | i::Isolate* isolate = i::Isolate::Current(); |
| 860 | if (IsDeadCheck(isolate, "v8::Template::Set()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 861 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 862 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list()); |
| 864 | if (list->IsUndefined()) { |
| 865 | list = NeanderArray().value(); |
| 866 | Utils::OpenHandle(this)->set_property_list(*list); |
| 867 | } |
| 868 | NeanderArray array(list); |
| 869 | array.add(Utils::OpenHandle(*name)); |
| 870 | array.add(Utils::OpenHandle(*value)); |
| 871 | array.add(Utils::OpenHandle(*v8::Integer::New(attribute))); |
| 872 | } |
| 873 | |
| 874 | |
| 875 | // --- F u n c t i o n T e m p l a t e --- |
| 876 | static void InitializeFunctionTemplate( |
| 877 | i::Handle<i::FunctionTemplateInfo> info) { |
| 878 | info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE)); |
| 879 | info->set_flag(0); |
| 880 | } |
| 881 | |
| 882 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 883 | Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 884 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 885 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::PrototypeTemplate()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 886 | return Local<ObjectTemplate>(); |
| 887 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 888 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 889 | i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template()); |
| 890 | if (result->IsUndefined()) { |
| 891 | result = Utils::OpenHandle(*ObjectTemplate::New()); |
| 892 | Utils::OpenHandle(this)->set_prototype_template(*result); |
| 893 | } |
| 894 | return Local<ObjectTemplate>(ToApi<ObjectTemplate>(result)); |
| 895 | } |
| 896 | |
| 897 | |
| 898 | void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 899 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 900 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 901 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 902 | Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); |
| 903 | } |
| 904 | |
| 905 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 906 | Local<FunctionTemplate> FunctionTemplate::New(InvocationCallback callback, |
| 907 | v8::Handle<Value> data, v8::Handle<Signature> signature) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 908 | i::Isolate* isolate = i::Isolate::Current(); |
| 909 | EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); |
| 910 | LOG_API(isolate, "FunctionTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 911 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 912 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 913 | isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 914 | i::Handle<i::FunctionTemplateInfo> obj = |
| 915 | i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
| 916 | InitializeFunctionTemplate(obj); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 917 | int next_serial_number = isolate->next_serial_number(); |
| 918 | isolate->set_next_serial_number(next_serial_number + 1); |
| 919 | obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 920 | if (callback != 0) { |
| 921 | if (data.IsEmpty()) data = v8::Undefined(); |
| 922 | Utils::ToLocal(obj)->SetCallHandler(callback, data); |
| 923 | } |
| 924 | obj->set_undetectable(false); |
| 925 | obj->set_needs_access_check(false); |
| 926 | |
| 927 | if (!signature.IsEmpty()) |
| 928 | obj->set_signature(*Utils::OpenHandle(*signature)); |
| 929 | return Utils::ToLocal(obj); |
| 930 | } |
| 931 | |
| 932 | |
| 933 | Local<Signature> Signature::New(Handle<FunctionTemplate> receiver, |
| 934 | int argc, Handle<FunctionTemplate> argv[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 935 | i::Isolate* isolate = i::Isolate::Current(); |
| 936 | EnsureInitializedForIsolate(isolate, "v8::Signature::New()"); |
| 937 | LOG_API(isolate, "Signature::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 938 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 939 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 940 | isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 941 | i::Handle<i::SignatureInfo> obj = |
| 942 | i::Handle<i::SignatureInfo>::cast(struct_obj); |
| 943 | if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver)); |
| 944 | if (argc > 0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 945 | i::Handle<i::FixedArray> args = isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 946 | for (int i = 0; i < argc; i++) { |
| 947 | if (!argv[i].IsEmpty()) |
| 948 | args->set(i, *Utils::OpenHandle(*argv[i])); |
| 949 | } |
| 950 | obj->set_args(*args); |
| 951 | } |
| 952 | return Utils::ToLocal(obj); |
| 953 | } |
| 954 | |
| 955 | |
| 956 | Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) { |
| 957 | Handle<FunctionTemplate> types[1] = { type }; |
| 958 | return TypeSwitch::New(1, types); |
| 959 | } |
| 960 | |
| 961 | |
| 962 | Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 963 | i::Isolate* isolate = i::Isolate::Current(); |
| 964 | EnsureInitializedForIsolate(isolate, "v8::TypeSwitch::New()"); |
| 965 | LOG_API(isolate, "TypeSwitch::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 966 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 967 | i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 968 | for (int i = 0; i < argc; i++) |
| 969 | vector->set(i, *Utils::OpenHandle(*types[i])); |
| 970 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 971 | isolate->factory()->NewStruct(i::TYPE_SWITCH_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 972 | i::Handle<i::TypeSwitchInfo> obj = |
| 973 | i::Handle<i::TypeSwitchInfo>::cast(struct_obj); |
| 974 | obj->set_types(*vector); |
| 975 | return Utils::ToLocal(obj); |
| 976 | } |
| 977 | |
| 978 | |
| 979 | int TypeSwitch::match(v8::Handle<Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 980 | i::Isolate* isolate = i::Isolate::Current(); |
| 981 | LOG_API(isolate, "TypeSwitch::match"); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 982 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 983 | i::Handle<i::Object> obj = Utils::OpenHandle(*value); |
| 984 | i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this); |
| 985 | i::FixedArray* types = i::FixedArray::cast(info->types()); |
| 986 | for (int i = 0; i < types->length(); i++) { |
| 987 | if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i)))) |
| 988 | return i + 1; |
| 989 | } |
| 990 | return 0; |
| 991 | } |
| 992 | |
| 993 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 994 | #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
| 995 | i::Handle<i::Object> foreign = FromCData(cdata); \ |
| 996 | (obj)->setter(*foreign); \ |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 997 | } while (false) |
| 998 | |
| 999 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1000 | void FunctionTemplate::SetCallHandler(InvocationCallback callback, |
| 1001 | v8::Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1002 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1003 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetCallHandler()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1004 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1005 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1006 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1007 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1008 | i::Handle<i::CallHandlerInfo> obj = |
| 1009 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1010 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1011 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1012 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1013 | Utils::OpenHandle(this)->set_call_code(*obj); |
| 1014 | } |
| 1015 | |
| 1016 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1017 | static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
| 1018 | v8::Handle<String> name, |
| 1019 | AccessorGetter getter, |
| 1020 | AccessorSetter setter, |
| 1021 | v8::Handle<Value> data, |
| 1022 | v8::AccessControl settings, |
| 1023 | v8::PropertyAttribute attributes) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1024 | i::Handle<i::AccessorInfo> obj = FACTORY->NewAccessorInfo(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1025 | ASSERT(getter != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1026 | SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1027 | SET_FIELD_WRAPPED(obj, set_setter, setter); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1028 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1029 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1030 | obj->set_name(*Utils::OpenHandle(*name)); |
| 1031 | if (settings & ALL_CAN_READ) obj->set_all_can_read(true); |
| 1032 | if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); |
| 1033 | if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true); |
| 1034 | obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); |
| 1035 | return obj; |
| 1036 | } |
| 1037 | |
| 1038 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1039 | void FunctionTemplate::AddInstancePropertyAccessor( |
| 1040 | v8::Handle<String> name, |
| 1041 | AccessorGetter getter, |
| 1042 | AccessorSetter setter, |
| 1043 | v8::Handle<Value> data, |
| 1044 | v8::AccessControl settings, |
| 1045 | v8::PropertyAttribute attributes) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1046 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1047 | if (IsDeadCheck(isolate, |
| 1048 | "v8::FunctionTemplate::AddInstancePropertyAccessor()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1049 | return; |
| 1050 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1051 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1052 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1053 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1054 | i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name, |
| 1055 | getter, setter, data, |
| 1056 | settings, attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1057 | i::Handle<i::Object> list(Utils::OpenHandle(this)->property_accessors()); |
| 1058 | if (list->IsUndefined()) { |
| 1059 | list = NeanderArray().value(); |
| 1060 | Utils::OpenHandle(this)->set_property_accessors(*list); |
| 1061 | } |
| 1062 | NeanderArray array(list); |
| 1063 | array.add(obj); |
| 1064 | } |
| 1065 | |
| 1066 | |
| 1067 | Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1068 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1069 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::InstanceTemplate()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1070 | || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) |
| 1071 | return Local<ObjectTemplate>(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1072 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1073 | if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) { |
| 1074 | Local<ObjectTemplate> templ = |
| 1075 | ObjectTemplate::New(v8::Handle<FunctionTemplate>(this)); |
| 1076 | Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ)); |
| 1077 | } |
| 1078 | i::Handle<i::ObjectTemplateInfo> result(i::ObjectTemplateInfo::cast( |
| 1079 | Utils::OpenHandle(this)->instance_template())); |
| 1080 | return Utils::ToLocal(result); |
| 1081 | } |
| 1082 | |
| 1083 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1084 | void FunctionTemplate::SetClassName(Handle<String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1085 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1086 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetClassName()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1087 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1088 | Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name)); |
| 1089 | } |
| 1090 | |
| 1091 | |
| 1092 | void FunctionTemplate::SetHiddenPrototype(bool value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1093 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1094 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetHiddenPrototype()")) { |
| 1095 | return; |
| 1096 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1097 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1098 | Utils::OpenHandle(this)->set_hidden_prototype(value); |
| 1099 | } |
| 1100 | |
| 1101 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1102 | void FunctionTemplate::ReadOnlyPrototype() { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1103 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1104 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetPrototypeAttributes()")) { |
| 1105 | return; |
| 1106 | } |
| 1107 | ENTER_V8(isolate); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1108 | Utils::OpenHandle(this)->set_read_only_prototype(true); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1112 | void FunctionTemplate::SetNamedInstancePropertyHandler( |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1113 | NamedPropertyGetter getter, |
| 1114 | NamedPropertySetter setter, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1115 | NamedPropertyQuery query, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1116 | NamedPropertyDeleter remover, |
| 1117 | NamedPropertyEnumerator enumerator, |
| 1118 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1119 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1120 | if (IsDeadCheck(isolate, |
| 1121 | "v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1122 | return; |
| 1123 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1124 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1125 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1126 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1127 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1128 | i::Handle<i::InterceptorInfo> obj = |
| 1129 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1130 | |
| 1131 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1132 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1133 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1134 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1135 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1136 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1137 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1138 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1139 | Utils::OpenHandle(this)->set_named_property_handler(*obj); |
| 1140 | } |
| 1141 | |
| 1142 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1143 | void FunctionTemplate::SetIndexedInstancePropertyHandler( |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1144 | IndexedPropertyGetter getter, |
| 1145 | IndexedPropertySetter setter, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1146 | IndexedPropertyQuery query, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1147 | IndexedPropertyDeleter remover, |
| 1148 | IndexedPropertyEnumerator enumerator, |
| 1149 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1150 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1151 | if (IsDeadCheck(isolate, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1152 | "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) { |
| 1153 | return; |
| 1154 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1155 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1156 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1157 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1158 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1159 | i::Handle<i::InterceptorInfo> obj = |
| 1160 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1161 | |
| 1162 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1163 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1164 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1165 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1166 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1167 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1168 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1169 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1170 | Utils::OpenHandle(this)->set_indexed_property_handler(*obj); |
| 1171 | } |
| 1172 | |
| 1173 | |
| 1174 | void FunctionTemplate::SetInstanceCallAsFunctionHandler( |
| 1175 | InvocationCallback callback, |
| 1176 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1177 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1178 | if (IsDeadCheck(isolate, |
| 1179 | "v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1180 | return; |
| 1181 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1182 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1183 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1184 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1185 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1186 | i::Handle<i::CallHandlerInfo> obj = |
| 1187 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1188 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1189 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1190 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1191 | Utils::OpenHandle(this)->set_instance_call_handler(*obj); |
| 1192 | } |
| 1193 | |
| 1194 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1195 | // --- O b j e c t T e m p l a t e --- |
| 1196 | |
| 1197 | |
| 1198 | Local<ObjectTemplate> ObjectTemplate::New() { |
| 1199 | return New(Local<FunctionTemplate>()); |
| 1200 | } |
| 1201 | |
| 1202 | |
| 1203 | Local<ObjectTemplate> ObjectTemplate::New( |
| 1204 | v8::Handle<FunctionTemplate> constructor) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1205 | i::Isolate* isolate = i::Isolate::Current(); |
| 1206 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::New()")) { |
| 1207 | return Local<ObjectTemplate>(); |
| 1208 | } |
| 1209 | EnsureInitializedForIsolate(isolate, "v8::ObjectTemplate::New()"); |
| 1210 | LOG_API(isolate, "ObjectTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1211 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1212 | i::Handle<i::Struct> struct_obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1213 | isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1214 | i::Handle<i::ObjectTemplateInfo> obj = |
| 1215 | i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); |
| 1216 | InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
| 1217 | if (!constructor.IsEmpty()) |
| 1218 | obj->set_constructor(*Utils::OpenHandle(*constructor)); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1219 | obj->set_internal_field_count(i::Smi::FromInt(0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1220 | return Utils::ToLocal(obj); |
| 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | // Ensure that the object template has a constructor. If no |
| 1225 | // constructor is available we create one. |
| 1226 | static void EnsureConstructor(ObjectTemplate* object_template) { |
| 1227 | if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { |
| 1228 | Local<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1229 | i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); |
| 1230 | constructor->set_instance_template(*Utils::OpenHandle(object_template)); |
| 1231 | Utils::OpenHandle(object_template)->set_constructor(*constructor); |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | |
| 1236 | void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
| 1237 | AccessorGetter getter, |
| 1238 | AccessorSetter setter, |
| 1239 | v8::Handle<Value> data, |
| 1240 | AccessControl settings, |
| 1241 | PropertyAttribute attribute) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1242 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1243 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1244 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1245 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1246 | EnsureConstructor(this); |
| 1247 | i::FunctionTemplateInfo* constructor = |
| 1248 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1249 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1250 | Utils::ToLocal(cons)->AddInstancePropertyAccessor(name, |
| 1251 | getter, |
| 1252 | setter, |
| 1253 | data, |
| 1254 | settings, |
| 1255 | attribute); |
| 1256 | } |
| 1257 | |
| 1258 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1259 | void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 1260 | NamedPropertySetter setter, |
| 1261 | NamedPropertyQuery query, |
| 1262 | NamedPropertyDeleter remover, |
| 1263 | NamedPropertyEnumerator enumerator, |
| 1264 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1265 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1266 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) { |
| 1267 | return; |
| 1268 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1269 | ENTER_V8(isolate); |
| 1270 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1271 | EnsureConstructor(this); |
| 1272 | i::FunctionTemplateInfo* constructor = |
| 1273 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1274 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1275 | Utils::ToLocal(cons)->SetNamedInstancePropertyHandler(getter, |
| 1276 | setter, |
| 1277 | query, |
| 1278 | remover, |
| 1279 | enumerator, |
| 1280 | data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | void ObjectTemplate::MarkAsUndetectable() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1285 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1286 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::MarkAsUndetectable()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1287 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1288 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1289 | EnsureConstructor(this); |
| 1290 | i::FunctionTemplateInfo* constructor = |
| 1291 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1292 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1293 | cons->set_undetectable(true); |
| 1294 | } |
| 1295 | |
| 1296 | |
| 1297 | void ObjectTemplate::SetAccessCheckCallbacks( |
| 1298 | NamedSecurityCallback named_callback, |
| 1299 | IndexedSecurityCallback indexed_callback, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1300 | Handle<Value> data, |
| 1301 | bool turned_on_by_default) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1302 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1303 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessCheckCallbacks()")) { |
| 1304 | return; |
| 1305 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1306 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1307 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1308 | EnsureConstructor(this); |
| 1309 | |
| 1310 | i::Handle<i::Struct> struct_info = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1311 | isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1312 | i::Handle<i::AccessCheckInfo> info = |
| 1313 | i::Handle<i::AccessCheckInfo>::cast(struct_info); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1314 | |
| 1315 | SET_FIELD_WRAPPED(info, set_named_callback, named_callback); |
| 1316 | SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback); |
| 1317 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1318 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1319 | info->set_data(*Utils::OpenHandle(*data)); |
| 1320 | |
| 1321 | i::FunctionTemplateInfo* constructor = |
| 1322 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1323 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1324 | cons->set_access_check_info(*info); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1325 | cons->set_needs_access_check(turned_on_by_default); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1329 | void ObjectTemplate::SetIndexedPropertyHandler( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1330 | IndexedPropertyGetter getter, |
| 1331 | IndexedPropertySetter setter, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1332 | IndexedPropertyQuery query, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1333 | IndexedPropertyDeleter remover, |
| 1334 | IndexedPropertyEnumerator enumerator, |
| 1335 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1336 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1337 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetIndexedPropertyHandler()")) { |
| 1338 | return; |
| 1339 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1340 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1341 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1342 | EnsureConstructor(this); |
| 1343 | i::FunctionTemplateInfo* constructor = |
| 1344 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1345 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1346 | Utils::ToLocal(cons)->SetIndexedInstancePropertyHandler(getter, |
| 1347 | setter, |
| 1348 | query, |
| 1349 | remover, |
| 1350 | enumerator, |
| 1351 | data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | |
| 1355 | void ObjectTemplate::SetCallAsFunctionHandler(InvocationCallback callback, |
| 1356 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1357 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1358 | if (IsDeadCheck(isolate, |
| 1359 | "v8::ObjectTemplate::SetCallAsFunctionHandler()")) { |
| 1360 | return; |
| 1361 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1362 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1363 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1364 | EnsureConstructor(this); |
| 1365 | i::FunctionTemplateInfo* constructor = |
| 1366 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1367 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1368 | Utils::ToLocal(cons)->SetInstanceCallAsFunctionHandler(callback, data); |
| 1369 | } |
| 1370 | |
| 1371 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1372 | int ObjectTemplate::InternalFieldCount() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1373 | if (IsDeadCheck(Utils::OpenHandle(this)->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1374 | "v8::ObjectTemplate::InternalFieldCount()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1375 | return 0; |
| 1376 | } |
| 1377 | return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1381 | void ObjectTemplate::SetInternalFieldCount(int value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1382 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1383 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetInternalFieldCount()")) { |
| 1384 | return; |
| 1385 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1386 | if (!ApiCheck(i::Smi::IsValid(value), |
| 1387 | "v8::ObjectTemplate::SetInternalFieldCount()", |
| 1388 | "Invalid internal field count")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1389 | return; |
| 1390 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1391 | ENTER_V8(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1392 | if (value > 0) { |
| 1393 | // The internal field count is set by the constructor function's |
| 1394 | // construct code, so we ensure that there is a constructor |
| 1395 | // function to do the setting. |
| 1396 | EnsureConstructor(this); |
| 1397 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1398 | Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1402 | // --- S c r i p t D a t a --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1403 | |
| 1404 | |
| 1405 | ScriptData* ScriptData::PreCompile(const char* input, int length) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1406 | i::Utf8ToUC16CharacterStream stream( |
| 1407 | reinterpret_cast<const unsigned char*>(input), length); |
| 1408 | return i::ParserApi::PreParse(&stream, NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1412 | ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { |
| 1413 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1414 | if (str->IsExternalTwoByteString()) { |
| 1415 | i::ExternalTwoByteStringUC16CharacterStream stream( |
| 1416 | i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); |
| 1417 | return i::ParserApi::PreParse(&stream, NULL); |
| 1418 | } else { |
| 1419 | i::GenericStringUC16CharacterStream stream(str, 0, str->length()); |
| 1420 | return i::ParserApi::PreParse(&stream, NULL); |
| 1421 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1425 | ScriptData* ScriptData::New(const char* data, int length) { |
| 1426 | // Return an empty ScriptData if the length is obviously invalid. |
| 1427 | if (length % sizeof(unsigned) != 0) { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1428 | return new i::ScriptDataImpl(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | // Copy the data to ensure it is properly aligned. |
| 1432 | int deserialized_data_length = length / sizeof(unsigned); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1433 | // If aligned, don't create a copy of the data. |
| 1434 | if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) { |
| 1435 | return new i::ScriptDataImpl(data, length); |
| 1436 | } |
| 1437 | // Copy the data to align it. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1438 | unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1439 | i::OS::MemCopy(deserialized_data, data, length); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1440 | |
| 1441 | return new i::ScriptDataImpl( |
| 1442 | i::Vector<unsigned>(deserialized_data, deserialized_data_length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | |
| 1446 | // --- S c r i p t --- |
| 1447 | |
| 1448 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1449 | Local<Script> Script::New(v8::Handle<String> source, |
| 1450 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1451 | v8::ScriptData* pre_data, |
| 1452 | v8::Handle<String> script_data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1453 | i::Isolate* isolate = i::Isolate::Current(); |
| 1454 | ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>()); |
| 1455 | LOG_API(isolate, "Script::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1456 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1457 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1458 | i::Handle<i::Object> name_obj; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1459 | int line_offset = 0; |
| 1460 | int column_offset = 0; |
| 1461 | if (origin != NULL) { |
| 1462 | if (!origin->ResourceName().IsEmpty()) { |
| 1463 | name_obj = Utils::OpenHandle(*origin->ResourceName()); |
| 1464 | } |
| 1465 | if (!origin->ResourceLineOffset().IsEmpty()) { |
| 1466 | line_offset = static_cast<int>(origin->ResourceLineOffset()->Value()); |
| 1467 | } |
| 1468 | if (!origin->ResourceColumnOffset().IsEmpty()) { |
| 1469 | column_offset = static_cast<int>(origin->ResourceColumnOffset()->Value()); |
| 1470 | } |
| 1471 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1472 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1473 | i::ScriptDataImpl* pre_data_impl = static_cast<i::ScriptDataImpl*>(pre_data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1474 | // We assert that the pre-data is sane, even though we can actually |
| 1475 | // handle it if it turns out not to be in release mode. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1476 | ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1477 | // If the pre-data isn't sane we simply ignore it |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1478 | if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) { |
| 1479 | pre_data_impl = NULL; |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1480 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1481 | i::Handle<i::SharedFunctionInfo> result = |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1482 | i::Compiler::Compile(str, |
| 1483 | name_obj, |
| 1484 | line_offset, |
| 1485 | column_offset, |
| 1486 | NULL, |
| 1487 | pre_data_impl, |
| 1488 | Utils::OpenHandle(*script_data), |
| 1489 | i::NOT_NATIVES_CODE); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1490 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1491 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1492 | return Local<Script>(ToApi<Script>(result)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | |
| 1496 | Local<Script> Script::New(v8::Handle<String> source, |
| 1497 | v8::Handle<Value> file_name) { |
| 1498 | ScriptOrigin origin(file_name); |
| 1499 | return New(source, &origin); |
| 1500 | } |
| 1501 | |
| 1502 | |
| 1503 | Local<Script> Script::Compile(v8::Handle<String> source, |
| 1504 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1505 | v8::ScriptData* pre_data, |
| 1506 | v8::Handle<String> script_data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1507 | i::Isolate* isolate = i::Isolate::Current(); |
| 1508 | ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>()); |
| 1509 | LOG_API(isolate, "Script::Compile"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1510 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1511 | Local<Script> generic = New(source, origin, pre_data, script_data); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1512 | if (generic.IsEmpty()) |
| 1513 | return generic; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1514 | i::Handle<i::Object> obj = Utils::OpenHandle(*generic); |
| 1515 | i::Handle<i::SharedFunctionInfo> function = |
| 1516 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1517 | i::Handle<i::JSFunction> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1518 | isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 1519 | function, |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1520 | isolate->global_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1521 | return Local<Script>(ToApi<Script>(result)); |
| 1522 | } |
| 1523 | |
| 1524 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1525 | Local<Script> Script::Compile(v8::Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1526 | v8::Handle<Value> file_name, |
| 1527 | v8::Handle<String> script_data) { |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1528 | ScriptOrigin origin(file_name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1529 | return Compile(source, &origin, 0, script_data); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1533 | Local<Value> Script::Run() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1534 | i::Isolate* isolate = i::Isolate::Current(); |
| 1535 | ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); |
| 1536 | LOG_API(isolate, "Script::Run"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1537 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1538 | i::Object* raw_result = NULL; |
| 1539 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1540 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1541 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 1542 | i::Handle<i::JSFunction> fun; |
| 1543 | if (obj->IsSharedFunctionInfo()) { |
| 1544 | i::Handle<i::SharedFunctionInfo> |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1545 | function_info(i::SharedFunctionInfo::cast(*obj), isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1546 | fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1547 | function_info, isolate->global_context()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1548 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1549 | fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1550 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1551 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1552 | i::Handle<i::Object> receiver( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1553 | isolate->context()->global_proxy(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1554 | i::Handle<i::Object> result = |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1555 | i::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1556 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1557 | raw_result = *result; |
| 1558 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1559 | i::Handle<i::Object> result(raw_result, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1560 | return Utils::ToLocal(result); |
| 1561 | } |
| 1562 | |
| 1563 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1564 | static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) { |
| 1565 | i::Handle<i::Object> obj = Utils::OpenHandle(script); |
| 1566 | i::Handle<i::SharedFunctionInfo> result; |
| 1567 | if (obj->IsSharedFunctionInfo()) { |
| 1568 | result = |
| 1569 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
| 1570 | } else { |
| 1571 | result = |
| 1572 | i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()); |
| 1573 | } |
| 1574 | return result; |
| 1575 | } |
| 1576 | |
| 1577 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1578 | Local<Value> Script::Id() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1579 | i::Isolate* isolate = i::Isolate::Current(); |
| 1580 | ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>()); |
| 1581 | LOG_API(isolate, "Script::Id"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1582 | i::Object* raw_id = NULL; |
| 1583 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1584 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1585 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
| 1586 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1587 | i::Handle<i::Object> id(script->id()); |
| 1588 | raw_id = *id; |
| 1589 | } |
| 1590 | i::Handle<i::Object> id(raw_id); |
| 1591 | return Utils::ToLocal(id); |
| 1592 | } |
| 1593 | |
| 1594 | |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1595 | void Script::SetData(v8::Handle<String> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1596 | i::Isolate* isolate = i::Isolate::Current(); |
| 1597 | ON_BAILOUT(isolate, "v8::Script::SetData()", return); |
| 1598 | LOG_API(isolate, "Script::SetData"); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1599 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1600 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1601 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1602 | i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1603 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1604 | script->set_data(*raw_data); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1609 | // --- E x c e p t i o n s --- |
| 1610 | |
| 1611 | |
| 1612 | v8::TryCatch::TryCatch() |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1613 | : isolate_(i::Isolate::Current()), |
| 1614 | next_(isolate_->try_catch_handler_address()), |
| 1615 | exception_(isolate_->heap()->the_hole_value()), |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1616 | message_(i::Smi::FromInt(0)), |
| 1617 | is_verbose_(false), |
ager@chromium.org | 68e7ab7 | 2009-09-23 09:40:39 +0000 | [diff] [blame] | 1618 | can_continue_(true), |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1619 | capture_message_(true), |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1620 | rethrow_(false) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1621 | isolate_->RegisterTryCatchHandler(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | |
| 1625 | v8::TryCatch::~TryCatch() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1626 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1627 | if (rethrow_) { |
| 1628 | v8::HandleScope scope; |
| 1629 | v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(Exception()); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1630 | isolate_->UnregisterTryCatchHandler(this); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1631 | v8::ThrowException(exc); |
| 1632 | } else { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1633 | isolate_->UnregisterTryCatchHandler(this); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1634 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1638 | bool v8::TryCatch::HasCaught() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1639 | return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(); |
| 1640 | } |
| 1641 | |
| 1642 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 1643 | bool v8::TryCatch::CanContinue() const { |
| 1644 | return can_continue_; |
| 1645 | } |
| 1646 | |
| 1647 | |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1648 | v8::Handle<v8::Value> v8::TryCatch::ReThrow() { |
| 1649 | if (!HasCaught()) return v8::Local<v8::Value>(); |
| 1650 | rethrow_ = true; |
| 1651 | return v8::Undefined(); |
| 1652 | } |
| 1653 | |
| 1654 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1655 | v8::Local<Value> v8::TryCatch::Exception() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1656 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1657 | if (HasCaught()) { |
| 1658 | // Check for out of memory exception. |
| 1659 | i::Object* exception = reinterpret_cast<i::Object*>(exception_); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1660 | return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1661 | } else { |
| 1662 | return v8::Local<Value>(); |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1667 | v8::Local<Value> v8::TryCatch::StackTrace() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1668 | ASSERT(isolate_ == i::Isolate::Current()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1669 | if (HasCaught()) { |
| 1670 | i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); |
| 1671 | if (!raw_obj->IsJSObject()) return v8::Local<Value>(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1672 | i::HandleScope scope(isolate_); |
| 1673 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); |
| 1674 | i::Handle<i::String> name = isolate_->factory()->LookupAsciiSymbol("stack"); |
| 1675 | if (!obj->HasProperty(*name)) return v8::Local<Value>(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1676 | i::Handle<i::Object> value = i::GetProperty(obj, name); |
| 1677 | if (value.is_null()) return v8::Local<Value>(); |
| 1678 | return v8::Utils::ToLocal(scope.CloseAndEscape(value)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1679 | } else { |
| 1680 | return v8::Local<Value>(); |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1685 | v8::Local<v8::Message> v8::TryCatch::Message() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1686 | ASSERT(isolate_ == i::Isolate::Current()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1687 | if (HasCaught() && message_ != i::Smi::FromInt(0)) { |
| 1688 | i::Object* message = reinterpret_cast<i::Object*>(message_); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1689 | return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1690 | } else { |
| 1691 | return v8::Local<v8::Message>(); |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1696 | void v8::TryCatch::Reset() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1697 | ASSERT(isolate_ == i::Isolate::Current()); |
| 1698 | exception_ = isolate_->heap()->the_hole_value(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1699 | message_ = i::Smi::FromInt(0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | |
| 1703 | void v8::TryCatch::SetVerbose(bool value) { |
| 1704 | is_verbose_ = value; |
| 1705 | } |
| 1706 | |
| 1707 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1708 | void v8::TryCatch::SetCaptureMessage(bool value) { |
| 1709 | capture_message_ = value; |
| 1710 | } |
| 1711 | |
| 1712 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1713 | // --- M e s s a g e --- |
| 1714 | |
| 1715 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1716 | Local<String> Message::Get() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1717 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1718 | ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1719 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1720 | HandleScope scope; |
| 1721 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 1722 | i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(obj); |
| 1723 | Local<String> result = Utils::ToLocal(raw_result); |
| 1724 | return scope.Close(result); |
| 1725 | } |
| 1726 | |
| 1727 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1728 | v8::Handle<Value> Message::GetScriptResourceName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1729 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1730 | if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceName()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1731 | return Local<String>(); |
| 1732 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1733 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1734 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1735 | i::Handle<i::JSMessageObject> message = |
| 1736 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1737 | // Return this.script.name. |
| 1738 | i::Handle<i::JSValue> script = |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1739 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1740 | i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1741 | return scope.Close(Utils::ToLocal(resource_name)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1745 | v8::Handle<Value> Message::GetScriptData() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1746 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1747 | if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceData()")) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1748 | return Local<Value>(); |
| 1749 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1750 | ENTER_V8(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1751 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1752 | i::Handle<i::JSMessageObject> message = |
| 1753 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1754 | // Return this.script.data. |
| 1755 | i::Handle<i::JSValue> script = |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1756 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script())); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1757 | i::Handle<i::Object> data(i::Script::cast(script->value())->data()); |
| 1758 | return scope.Close(Utils::ToLocal(data)); |
| 1759 | } |
| 1760 | |
| 1761 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1762 | v8::Handle<v8::StackTrace> Message::GetStackTrace() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1763 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1764 | if (IsDeadCheck(isolate, "v8::Message::GetStackTrace()")) { |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1765 | return Local<v8::StackTrace>(); |
| 1766 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1767 | ENTER_V8(isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1768 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1769 | i::Handle<i::JSMessageObject> message = |
| 1770 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1771 | i::Handle<i::Object> stackFramesObj(message->stack_frames()); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1772 | if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); |
| 1773 | i::Handle<i::JSArray> stackTrace = |
| 1774 | i::Handle<i::JSArray>::cast(stackFramesObj); |
| 1775 | return scope.Close(Utils::StackTraceToLocal(stackTrace)); |
| 1776 | } |
| 1777 | |
| 1778 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1779 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 1780 | i::Handle<i::Object> recv, |
| 1781 | int argc, |
| 1782 | i::Object** argv[], |
| 1783 | bool* has_pending_exception) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1784 | i::Isolate* isolate = i::Isolate::Current(); |
| 1785 | i::Handle<i::String> fmt_str = isolate->factory()->LookupAsciiSymbol(name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1786 | i::Object* object_fun = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1787 | isolate->js_builtins_object()->GetPropertyNoExceptionThrown(*fmt_str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1788 | i::Handle<i::JSFunction> fun = |
| 1789 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun)); |
| 1790 | i::Handle<i::Object> value = |
| 1791 | i::Execution::Call(fun, recv, argc, argv, has_pending_exception); |
| 1792 | return value; |
| 1793 | } |
| 1794 | |
| 1795 | |
| 1796 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 1797 | i::Handle<i::Object> data, |
| 1798 | bool* has_pending_exception) { |
| 1799 | i::Object** argv[1] = { data.location() }; |
| 1800 | return CallV8HeapFunction(name, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1801 | i::Isolate::Current()->js_builtins_object(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1802 | 1, |
| 1803 | argv, |
| 1804 | has_pending_exception); |
| 1805 | } |
| 1806 | |
| 1807 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1808 | int Message::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1809 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1810 | ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1811 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1812 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1813 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1814 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1815 | i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber", |
| 1816 | Utils::OpenHandle(this), |
| 1817 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1818 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1819 | return static_cast<int>(result->Number()); |
| 1820 | } |
| 1821 | |
| 1822 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1823 | int Message::GetStartPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1824 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1825 | if (IsDeadCheck(isolate, "v8::Message::GetStartPosition()")) return 0; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1826 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1827 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1828 | i::Handle<i::JSMessageObject> message = |
| 1829 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1830 | return message->start_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1834 | int Message::GetEndPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1835 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1836 | if (IsDeadCheck(isolate, "v8::Message::GetEndPosition()")) return 0; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1837 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1838 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1839 | i::Handle<i::JSMessageObject> message = |
| 1840 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1841 | return message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1845 | int Message::GetStartColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1846 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1847 | if (IsDeadCheck(isolate, "v8::Message::GetStartColumn()")) { |
| 1848 | return kNoColumnInfo; |
| 1849 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1850 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1851 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1852 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1853 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1854 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 1855 | "GetPositionInLine", |
| 1856 | data_obj, |
| 1857 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1858 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1859 | return static_cast<int>(start_col_obj->Number()); |
| 1860 | } |
| 1861 | |
| 1862 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1863 | int Message::GetEndColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1864 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1865 | if (IsDeadCheck(isolate, "v8::Message::GetEndColumn()")) return kNoColumnInfo; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1866 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1867 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1868 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1869 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1870 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 1871 | "GetPositionInLine", |
| 1872 | data_obj, |
| 1873 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1874 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1875 | i::Handle<i::JSMessageObject> message = |
| 1876 | i::Handle<i::JSMessageObject>::cast(data_obj); |
| 1877 | int start = message->start_position(); |
| 1878 | int end = message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1879 | return static_cast<int>(start_col_obj->Number()) + (end - start); |
| 1880 | } |
| 1881 | |
| 1882 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1883 | Local<String> Message::GetSourceLine() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1884 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1885 | ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1886 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1887 | HandleScope scope; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1888 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1889 | i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine", |
| 1890 | Utils::OpenHandle(this), |
| 1891 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1892 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::String>()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1893 | if (result->IsString()) { |
| 1894 | return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result))); |
| 1895 | } else { |
| 1896 | return Local<String>(); |
| 1897 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1901 | void Message::PrintCurrentStackTrace(FILE* out) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1902 | i::Isolate* isolate = i::Isolate::Current(); |
| 1903 | if (IsDeadCheck(isolate, "v8::Message::PrintCurrentStackTrace()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1904 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1905 | isolate->PrintCurrentStackTrace(out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1909 | // --- S t a c k T r a c e --- |
| 1910 | |
| 1911 | Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1912 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1913 | if (IsDeadCheck(isolate, "v8::StackTrace::GetFrame()")) { |
| 1914 | return Local<StackFrame>(); |
| 1915 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1916 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1917 | HandleScope scope; |
| 1918 | i::Handle<i::JSArray> self = Utils::OpenHandle(this); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1919 | i::Object* raw_object = self->GetElementNoExceptionThrown(index); |
| 1920 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1921 | return scope.Close(Utils::StackFrameToLocal(obj)); |
| 1922 | } |
| 1923 | |
| 1924 | |
| 1925 | int StackTrace::GetFrameCount() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1926 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1927 | if (IsDeadCheck(isolate, "v8::StackTrace::GetFrameCount()")) return -1; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1928 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1929 | return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); |
| 1930 | } |
| 1931 | |
| 1932 | |
| 1933 | Local<Array> StackTrace::AsArray() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1934 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1935 | if (IsDeadCheck(isolate, "v8::StackTrace::AsArray()")) Local<Array>(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1936 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1937 | return Utils::ToLocal(Utils::OpenHandle(this)); |
| 1938 | } |
| 1939 | |
| 1940 | |
| 1941 | Local<StackTrace> StackTrace::CurrentStackTrace(int frame_limit, |
| 1942 | StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1943 | i::Isolate* isolate = i::Isolate::Current(); |
| 1944 | if (IsDeadCheck(isolate, "v8::StackTrace::CurrentStackTrace()")) { |
| 1945 | Local<StackTrace>(); |
| 1946 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1947 | ENTER_V8(isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1948 | i::Handle<i::JSArray> stackTrace = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1949 | isolate->CaptureCurrentStackTrace(frame_limit, options); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1950 | return Utils::StackTraceToLocal(stackTrace); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | |
| 1954 | // --- S t a c k F r a m e --- |
| 1955 | |
| 1956 | int StackFrame::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1957 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1958 | if (IsDeadCheck(isolate, "v8::StackFrame::GetLineNumber()")) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1959 | return Message::kNoLineNumberInfo; |
| 1960 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1961 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1962 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1963 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 1964 | i::Handle<i::Object> line = GetProperty(self, "lineNumber"); |
| 1965 | if (!line->IsSmi()) { |
| 1966 | return Message::kNoLineNumberInfo; |
| 1967 | } |
| 1968 | return i::Smi::cast(*line)->value(); |
| 1969 | } |
| 1970 | |
| 1971 | |
| 1972 | int StackFrame::GetColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1973 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1974 | if (IsDeadCheck(isolate, "v8::StackFrame::GetColumn()")) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1975 | return Message::kNoColumnInfo; |
| 1976 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1977 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1978 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1979 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 1980 | i::Handle<i::Object> column = GetProperty(self, "column"); |
| 1981 | if (!column->IsSmi()) { |
| 1982 | return Message::kNoColumnInfo; |
| 1983 | } |
| 1984 | return i::Smi::cast(*column)->value(); |
| 1985 | } |
| 1986 | |
| 1987 | |
| 1988 | Local<String> StackFrame::GetScriptName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1989 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1990 | if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptName()")) { |
| 1991 | return Local<String>(); |
| 1992 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1993 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1994 | HandleScope scope; |
| 1995 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 1996 | i::Handle<i::Object> name = GetProperty(self, "scriptName"); |
| 1997 | if (!name->IsString()) { |
| 1998 | return Local<String>(); |
| 1999 | } |
| 2000 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2001 | } |
| 2002 | |
| 2003 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2004 | Local<String> StackFrame::GetScriptNameOrSourceURL() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2005 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2006 | if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptNameOrSourceURL()")) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2007 | return Local<String>(); |
| 2008 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2009 | ENTER_V8(isolate); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2010 | HandleScope scope; |
| 2011 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2012 | i::Handle<i::Object> name = GetProperty(self, "scriptNameOrSourceURL"); |
| 2013 | if (!name->IsString()) { |
| 2014 | return Local<String>(); |
| 2015 | } |
| 2016 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2017 | } |
| 2018 | |
| 2019 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2020 | Local<String> StackFrame::GetFunctionName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2021 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2022 | if (IsDeadCheck(isolate, "v8::StackFrame::GetFunctionName()")) { |
| 2023 | return Local<String>(); |
| 2024 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2025 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2026 | HandleScope scope; |
| 2027 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2028 | i::Handle<i::Object> name = GetProperty(self, "functionName"); |
| 2029 | if (!name->IsString()) { |
| 2030 | return Local<String>(); |
| 2031 | } |
| 2032 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2033 | } |
| 2034 | |
| 2035 | |
| 2036 | bool StackFrame::IsEval() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2037 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2038 | if (IsDeadCheck(isolate, "v8::StackFrame::IsEval()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2039 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2040 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2041 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2042 | i::Handle<i::Object> is_eval = GetProperty(self, "isEval"); |
| 2043 | return is_eval->IsTrue(); |
| 2044 | } |
| 2045 | |
| 2046 | |
| 2047 | bool StackFrame::IsConstructor() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2048 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2049 | if (IsDeadCheck(isolate, "v8::StackFrame::IsConstructor()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2050 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2051 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2052 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2053 | i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor"); |
| 2054 | return is_constructor->IsTrue(); |
| 2055 | } |
| 2056 | |
| 2057 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2058 | // --- D a t a --- |
| 2059 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2060 | bool Value::IsUndefined() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2061 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUndefined()")) { |
| 2062 | return false; |
| 2063 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2064 | return Utils::OpenHandle(this)->IsUndefined(); |
| 2065 | } |
| 2066 | |
| 2067 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2068 | bool Value::IsNull() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2069 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNull()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2070 | return Utils::OpenHandle(this)->IsNull(); |
| 2071 | } |
| 2072 | |
| 2073 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2074 | bool Value::IsTrue() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2075 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsTrue()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2076 | return Utils::OpenHandle(this)->IsTrue(); |
| 2077 | } |
| 2078 | |
| 2079 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2080 | bool Value::IsFalse() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2081 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFalse()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2082 | return Utils::OpenHandle(this)->IsFalse(); |
| 2083 | } |
| 2084 | |
| 2085 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2086 | bool Value::IsFunction() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2087 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFunction()")) { |
| 2088 | return false; |
| 2089 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2090 | return Utils::OpenHandle(this)->IsJSFunction(); |
| 2091 | } |
| 2092 | |
| 2093 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2094 | bool Value::FullIsString() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2095 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsString()")) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2096 | bool result = Utils::OpenHandle(this)->IsString(); |
| 2097 | ASSERT_EQ(result, QuickIsString()); |
| 2098 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2102 | bool Value::IsArray() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2103 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArray()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2104 | return Utils::OpenHandle(this)->IsJSArray(); |
| 2105 | } |
| 2106 | |
| 2107 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2108 | bool Value::IsObject() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2109 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2110 | return Utils::OpenHandle(this)->IsJSObject(); |
| 2111 | } |
| 2112 | |
| 2113 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2114 | bool Value::IsNumber() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2115 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2116 | return Utils::OpenHandle(this)->IsNumber(); |
| 2117 | } |
| 2118 | |
| 2119 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2120 | bool Value::IsBoolean() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2121 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsBoolean()")) { |
| 2122 | return false; |
| 2123 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2124 | return Utils::OpenHandle(this)->IsBoolean(); |
| 2125 | } |
| 2126 | |
| 2127 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2128 | bool Value::IsExternal() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2129 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsExternal()")) { |
| 2130 | return false; |
| 2131 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2132 | return Utils::OpenHandle(this)->IsForeign(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2136 | bool Value::IsInt32() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2137 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsInt32()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2138 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2139 | if (obj->IsSmi()) return true; |
| 2140 | if (obj->IsNumber()) { |
| 2141 | double value = obj->Number(); |
| 2142 | return i::FastI2D(i::FastD2I(value)) == value; |
| 2143 | } |
| 2144 | return false; |
| 2145 | } |
| 2146 | |
| 2147 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2148 | bool Value::IsUint32() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2149 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUint32()")) return false; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2150 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2151 | if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0; |
| 2152 | if (obj->IsNumber()) { |
| 2153 | double value = obj->Number(); |
| 2154 | return i::FastUI2D(i::FastD2UI(value)) == value; |
| 2155 | } |
| 2156 | return false; |
| 2157 | } |
| 2158 | |
| 2159 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2160 | bool Value::IsDate() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2161 | i::Isolate* isolate = i::Isolate::Current(); |
| 2162 | if (IsDeadCheck(isolate, "v8::Value::IsDate()")) return false; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2163 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2164 | return obj->HasSpecificClassOf(isolate->heap()->Date_symbol()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2168 | bool Value::IsStringObject() const { |
| 2169 | i::Isolate* isolate = i::Isolate::Current(); |
| 2170 | if (IsDeadCheck(isolate, "v8::Value::IsStringObject()")) return false; |
| 2171 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2172 | return obj->HasSpecificClassOf(isolate->heap()->String_symbol()); |
| 2173 | } |
| 2174 | |
| 2175 | |
| 2176 | bool Value::IsNumberObject() const { |
| 2177 | i::Isolate* isolate = i::Isolate::Current(); |
| 2178 | if (IsDeadCheck(isolate, "v8::Value::IsNumberObject()")) return false; |
| 2179 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2180 | return obj->HasSpecificClassOf(isolate->heap()->Number_symbol()); |
| 2181 | } |
| 2182 | |
| 2183 | |
| 2184 | static i::Object* LookupBuiltin(i::Isolate* isolate, |
| 2185 | const char* builtin_name) { |
| 2186 | i::Handle<i::String> symbol = |
| 2187 | isolate->factory()->LookupAsciiSymbol(builtin_name); |
| 2188 | i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object(); |
| 2189 | return builtins->GetPropertyNoExceptionThrown(*symbol); |
| 2190 | } |
| 2191 | |
| 2192 | |
| 2193 | static bool CheckConstructor(i::Isolate* isolate, |
| 2194 | i::Handle<i::JSObject> obj, |
| 2195 | const char* class_name) { |
| 2196 | return obj->map()->constructor() == LookupBuiltin(isolate, class_name); |
| 2197 | } |
| 2198 | |
| 2199 | |
| 2200 | bool Value::IsNativeError() const { |
| 2201 | i::Isolate* isolate = i::Isolate::Current(); |
| 2202 | if (IsDeadCheck(isolate, "v8::Value::IsNativeError()")) return false; |
| 2203 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2204 | if (obj->IsJSObject()) { |
| 2205 | i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj)); |
| 2206 | return CheckConstructor(isolate, js_obj, "$Error") || |
| 2207 | CheckConstructor(isolate, js_obj, "$EvalError") || |
| 2208 | CheckConstructor(isolate, js_obj, "$RangeError") || |
| 2209 | CheckConstructor(isolate, js_obj, "$ReferenceError") || |
| 2210 | CheckConstructor(isolate, js_obj, "$SyntaxError") || |
| 2211 | CheckConstructor(isolate, js_obj, "$TypeError") || |
| 2212 | CheckConstructor(isolate, js_obj, "$URIError"); |
| 2213 | } else { |
| 2214 | return false; |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | |
| 2219 | bool Value::IsBooleanObject() const { |
| 2220 | i::Isolate* isolate = i::Isolate::Current(); |
| 2221 | if (IsDeadCheck(isolate, "v8::Value::IsBooleanObject()")) return false; |
| 2222 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2223 | return obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol()); |
| 2224 | } |
| 2225 | |
| 2226 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2227 | bool Value::IsRegExp() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2228 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsRegExp()")) return false; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2229 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2230 | return obj->IsJSRegExp(); |
| 2231 | } |
| 2232 | |
| 2233 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2234 | Local<String> Value::ToString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2235 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2236 | i::Handle<i::Object> str; |
| 2237 | if (obj->IsString()) { |
| 2238 | str = obj; |
| 2239 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2240 | i::Isolate* isolate = i::Isolate::Current(); |
| 2241 | if (IsDeadCheck(isolate, "v8::Value::ToString()")) { |
| 2242 | return Local<String>(); |
| 2243 | } |
| 2244 | LOG_API(isolate, "ToString"); |
| 2245 | ENTER_V8(isolate); |
| 2246 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2247 | str = i::Execution::ToString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2248 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2249 | } |
| 2250 | return Local<String>(ToApi<String>(str)); |
| 2251 | } |
| 2252 | |
| 2253 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2254 | Local<String> Value::ToDetailString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2255 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2256 | i::Handle<i::Object> str; |
| 2257 | if (obj->IsString()) { |
| 2258 | str = obj; |
| 2259 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2260 | i::Isolate* isolate = i::Isolate::Current(); |
| 2261 | if (IsDeadCheck(isolate, "v8::Value::ToDetailString()")) { |
| 2262 | return Local<String>(); |
| 2263 | } |
| 2264 | LOG_API(isolate, "ToDetailString"); |
| 2265 | ENTER_V8(isolate); |
| 2266 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2267 | str = i::Execution::ToDetailString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2268 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2269 | } |
| 2270 | return Local<String>(ToApi<String>(str)); |
| 2271 | } |
| 2272 | |
| 2273 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2274 | Local<v8::Object> Value::ToObject() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2275 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2276 | i::Handle<i::Object> val; |
| 2277 | if (obj->IsJSObject()) { |
| 2278 | val = obj; |
| 2279 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2280 | i::Isolate* isolate = i::Isolate::Current(); |
| 2281 | if (IsDeadCheck(isolate, "v8::Value::ToObject()")) { |
| 2282 | return Local<v8::Object>(); |
| 2283 | } |
| 2284 | LOG_API(isolate, "ToObject"); |
| 2285 | ENTER_V8(isolate); |
| 2286 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2287 | val = i::Execution::ToObject(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2288 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2289 | } |
| 2290 | return Local<v8::Object>(ToApi<Object>(val)); |
| 2291 | } |
| 2292 | |
| 2293 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2294 | Local<Boolean> Value::ToBoolean() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2295 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2296 | if (obj->IsBoolean()) { |
| 2297 | return Local<Boolean>(ToApi<Boolean>(obj)); |
| 2298 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2299 | i::Isolate* isolate = i::Isolate::Current(); |
| 2300 | if (IsDeadCheck(isolate, "v8::Value::ToBoolean()")) { |
| 2301 | return Local<Boolean>(); |
| 2302 | } |
| 2303 | LOG_API(isolate, "ToBoolean"); |
| 2304 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2305 | i::Handle<i::Object> val = i::Execution::ToBoolean(obj); |
| 2306 | return Local<Boolean>(ToApi<Boolean>(val)); |
| 2307 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2311 | Local<Number> Value::ToNumber() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2312 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2313 | i::Handle<i::Object> num; |
| 2314 | if (obj->IsNumber()) { |
| 2315 | num = obj; |
| 2316 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2317 | i::Isolate* isolate = i::Isolate::Current(); |
| 2318 | if (IsDeadCheck(isolate, "v8::Value::ToNumber()")) { |
| 2319 | return Local<Number>(); |
| 2320 | } |
| 2321 | LOG_API(isolate, "ToNumber"); |
| 2322 | ENTER_V8(isolate); |
| 2323 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2324 | num = i::Execution::ToNumber(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2325 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Number>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2326 | } |
| 2327 | return Local<Number>(ToApi<Number>(num)); |
| 2328 | } |
| 2329 | |
| 2330 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2331 | Local<Integer> Value::ToInteger() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2332 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2333 | i::Handle<i::Object> num; |
| 2334 | if (obj->IsSmi()) { |
| 2335 | num = obj; |
| 2336 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2337 | i::Isolate* isolate = i::Isolate::Current(); |
| 2338 | if (IsDeadCheck(isolate, "v8::Value::ToInteger()")) return Local<Integer>(); |
| 2339 | LOG_API(isolate, "ToInteger"); |
| 2340 | ENTER_V8(isolate); |
| 2341 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2342 | num = i::Execution::ToInteger(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2343 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2344 | } |
| 2345 | return Local<Integer>(ToApi<Integer>(num)); |
| 2346 | } |
| 2347 | |
| 2348 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2349 | void External::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2350 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2351 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2352 | ApiCheck(obj->IsForeign(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2353 | "v8::External::Cast()", |
| 2354 | "Could not convert to external"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2358 | void v8::Object::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2359 | if (IsDeadCheck(i::Isolate::Current(), "v8::Object::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2360 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2361 | ApiCheck(obj->IsJSObject(), |
| 2362 | "v8::Object::Cast()", |
| 2363 | "Could not convert to object"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2367 | void v8::Function::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2368 | if (IsDeadCheck(i::Isolate::Current(), "v8::Function::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2369 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2370 | ApiCheck(obj->IsJSFunction(), |
| 2371 | "v8::Function::Cast()", |
| 2372 | "Could not convert to function"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2376 | void v8::String::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2377 | if (IsDeadCheck(i::Isolate::Current(), "v8::String::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2378 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2379 | ApiCheck(obj->IsString(), |
| 2380 | "v8::String::Cast()", |
| 2381 | "Could not convert to string"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2385 | void v8::Number::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2386 | if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2387 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2388 | ApiCheck(obj->IsNumber(), |
| 2389 | "v8::Number::Cast()", |
| 2390 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2394 | void v8::Integer::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2395 | if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2396 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2397 | ApiCheck(obj->IsNumber(), |
| 2398 | "v8::Integer::Cast()", |
| 2399 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2403 | void v8::Array::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2404 | if (IsDeadCheck(i::Isolate::Current(), "v8::Array::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2405 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2406 | ApiCheck(obj->IsJSArray(), |
| 2407 | "v8::Array::Cast()", |
| 2408 | "Could not convert to array"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2412 | void v8::Date::CheckCast(v8::Value* that) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2413 | i::Isolate* isolate = i::Isolate::Current(); |
| 2414 | if (IsDeadCheck(isolate, "v8::Date::Cast()")) return; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2415 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2416 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_symbol()), |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2417 | "v8::Date::Cast()", |
| 2418 | "Could not convert to date"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2422 | void v8::StringObject::CheckCast(v8::Value* that) { |
| 2423 | i::Isolate* isolate = i::Isolate::Current(); |
| 2424 | if (IsDeadCheck(isolate, "v8::StringObject::Cast()")) return; |
| 2425 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2426 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->String_symbol()), |
| 2427 | "v8::StringObject::Cast()", |
| 2428 | "Could not convert to StringObject"); |
| 2429 | } |
| 2430 | |
| 2431 | |
| 2432 | void v8::NumberObject::CheckCast(v8::Value* that) { |
| 2433 | i::Isolate* isolate = i::Isolate::Current(); |
| 2434 | if (IsDeadCheck(isolate, "v8::NumberObject::Cast()")) return; |
| 2435 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2436 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Number_symbol()), |
| 2437 | "v8::NumberObject::Cast()", |
| 2438 | "Could not convert to NumberObject"); |
| 2439 | } |
| 2440 | |
| 2441 | |
| 2442 | void v8::BooleanObject::CheckCast(v8::Value* that) { |
| 2443 | i::Isolate* isolate = i::Isolate::Current(); |
| 2444 | if (IsDeadCheck(isolate, "v8::BooleanObject::Cast()")) return; |
| 2445 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2446 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol()), |
| 2447 | "v8::BooleanObject::Cast()", |
| 2448 | "Could not convert to BooleanObject"); |
| 2449 | } |
| 2450 | |
| 2451 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2452 | void v8::RegExp::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2453 | if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::Cast()")) return; |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2454 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2455 | ApiCheck(obj->IsJSRegExp(), |
| 2456 | "v8::RegExp::Cast()", |
| 2457 | "Could not convert to regular expression"); |
| 2458 | } |
| 2459 | |
| 2460 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2461 | bool Value::BooleanValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2462 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2463 | if (obj->IsBoolean()) { |
| 2464 | return obj->IsTrue(); |
| 2465 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2466 | i::Isolate* isolate = i::Isolate::Current(); |
| 2467 | if (IsDeadCheck(isolate, "v8::Value::BooleanValue()")) return false; |
| 2468 | LOG_API(isolate, "BooleanValue"); |
| 2469 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2470 | i::Handle<i::Object> value = i::Execution::ToBoolean(obj); |
| 2471 | return value->IsTrue(); |
| 2472 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2476 | double Value::NumberValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2477 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2478 | i::Handle<i::Object> num; |
| 2479 | if (obj->IsNumber()) { |
| 2480 | num = obj; |
| 2481 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2482 | i::Isolate* isolate = i::Isolate::Current(); |
| 2483 | if (IsDeadCheck(isolate, "v8::Value::NumberValue()")) { |
| 2484 | return i::OS::nan_value(); |
| 2485 | } |
| 2486 | LOG_API(isolate, "NumberValue"); |
| 2487 | ENTER_V8(isolate); |
| 2488 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2489 | num = i::Execution::ToNumber(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2490 | EXCEPTION_BAILOUT_CHECK(isolate, i::OS::nan_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2491 | } |
| 2492 | return num->Number(); |
| 2493 | } |
| 2494 | |
| 2495 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2496 | int64_t Value::IntegerValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2497 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2498 | i::Handle<i::Object> num; |
| 2499 | if (obj->IsNumber()) { |
| 2500 | num = obj; |
| 2501 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2502 | i::Isolate* isolate = i::Isolate::Current(); |
| 2503 | if (IsDeadCheck(isolate, "v8::Value::IntegerValue()")) return 0; |
| 2504 | LOG_API(isolate, "IntegerValue"); |
| 2505 | ENTER_V8(isolate); |
| 2506 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2507 | num = i::Execution::ToInteger(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2508 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2509 | } |
| 2510 | if (num->IsSmi()) { |
| 2511 | return i::Smi::cast(*num)->value(); |
| 2512 | } else { |
| 2513 | return static_cast<int64_t>(num->Number()); |
| 2514 | } |
| 2515 | } |
| 2516 | |
| 2517 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2518 | Local<Int32> Value::ToInt32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2519 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2520 | i::Handle<i::Object> num; |
| 2521 | if (obj->IsSmi()) { |
| 2522 | num = obj; |
| 2523 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2524 | i::Isolate* isolate = i::Isolate::Current(); |
| 2525 | if (IsDeadCheck(isolate, "v8::Value::ToInt32()")) return Local<Int32>(); |
| 2526 | LOG_API(isolate, "ToInt32"); |
| 2527 | ENTER_V8(isolate); |
| 2528 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2529 | num = i::Execution::ToInt32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2530 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Int32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2531 | } |
| 2532 | return Local<Int32>(ToApi<Int32>(num)); |
| 2533 | } |
| 2534 | |
| 2535 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2536 | Local<Uint32> Value::ToUint32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2537 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2538 | i::Handle<i::Object> num; |
| 2539 | if (obj->IsSmi()) { |
| 2540 | num = obj; |
| 2541 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2542 | i::Isolate* isolate = i::Isolate::Current(); |
| 2543 | if (IsDeadCheck(isolate, "v8::Value::ToUint32()")) return Local<Uint32>(); |
| 2544 | LOG_API(isolate, "ToUInt32"); |
| 2545 | ENTER_V8(isolate); |
| 2546 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2547 | num = i::Execution::ToUint32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2548 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2549 | } |
| 2550 | return Local<Uint32>(ToApi<Uint32>(num)); |
| 2551 | } |
| 2552 | |
| 2553 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2554 | Local<Uint32> Value::ToArrayIndex() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2555 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2556 | if (obj->IsSmi()) { |
| 2557 | if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj); |
| 2558 | return Local<Uint32>(); |
| 2559 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2560 | i::Isolate* isolate = i::Isolate::Current(); |
| 2561 | if (IsDeadCheck(isolate, "v8::Value::ToArrayIndex()")) return Local<Uint32>(); |
| 2562 | LOG_API(isolate, "ToArrayIndex"); |
| 2563 | ENTER_V8(isolate); |
| 2564 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2565 | i::Handle<i::Object> string_obj = |
| 2566 | i::Execution::ToString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2567 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2568 | i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); |
| 2569 | uint32_t index; |
| 2570 | if (str->AsArrayIndex(&index)) { |
| 2571 | i::Handle<i::Object> value; |
| 2572 | if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) { |
| 2573 | value = i::Handle<i::Object>(i::Smi::FromInt(index)); |
| 2574 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2575 | value = isolate->factory()->NewNumber(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2576 | } |
| 2577 | return Utils::Uint32ToLocal(value); |
| 2578 | } |
| 2579 | return Local<Uint32>(); |
| 2580 | } |
| 2581 | |
| 2582 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2583 | int32_t Value::Int32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2584 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2585 | if (obj->IsSmi()) { |
| 2586 | return i::Smi::cast(*obj)->value(); |
| 2587 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2588 | i::Isolate* isolate = i::Isolate::Current(); |
| 2589 | if (IsDeadCheck(isolate, "v8::Value::Int32Value()")) return 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2590 | LOG_API(isolate, "Int32Value (slow)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2591 | ENTER_V8(isolate); |
| 2592 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2593 | i::Handle<i::Object> num = |
| 2594 | i::Execution::ToInt32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2595 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2596 | if (num->IsSmi()) { |
| 2597 | return i::Smi::cast(*num)->value(); |
| 2598 | } else { |
| 2599 | return static_cast<int32_t>(num->Number()); |
| 2600 | } |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2605 | bool Value::Equals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2606 | i::Isolate* isolate = i::Isolate::Current(); |
| 2607 | if (IsDeadCheck(isolate, "v8::Value::Equals()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2608 | || EmptyCheck("v8::Value::Equals()", this) |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2609 | || EmptyCheck("v8::Value::Equals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2610 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2611 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2612 | LOG_API(isolate, "Equals"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2613 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2614 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2615 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2616 | // If both obj and other are JSObjects, we'd better compare by identity |
| 2617 | // immediately when going into JS builtin. The reason is Invoke |
| 2618 | // would overwrite global object receiver with global proxy. |
| 2619 | if (obj->IsJSObject() && other->IsJSObject()) { |
| 2620 | return *obj == *other; |
| 2621 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2622 | i::Object** args[1] = { other.location() }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2623 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2624 | i::Handle<i::Object> result = |
| 2625 | CallV8HeapFunction("EQUALS", obj, 1, args, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2626 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2627 | return *result == i::Smi::FromInt(i::EQUAL); |
| 2628 | } |
| 2629 | |
| 2630 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2631 | bool Value::StrictEquals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2632 | i::Isolate* isolate = i::Isolate::Current(); |
| 2633 | if (IsDeadCheck(isolate, "v8::Value::StrictEquals()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2634 | || EmptyCheck("v8::Value::StrictEquals()", this) |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2635 | || EmptyCheck("v8::Value::StrictEquals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2636 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2637 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2638 | LOG_API(isolate, "StrictEquals"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2639 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2640 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
| 2641 | // Must check HeapNumber first, since NaN !== NaN. |
| 2642 | if (obj->IsHeapNumber()) { |
| 2643 | if (!other->IsNumber()) return false; |
| 2644 | double x = obj->Number(); |
| 2645 | double y = other->Number(); |
| 2646 | // Must check explicitly for NaN:s on Windows, but -0 works fine. |
| 2647 | return x == y && !isnan(x) && !isnan(y); |
| 2648 | } else if (*obj == *other) { // Also covers Booleans. |
| 2649 | return true; |
| 2650 | } else if (obj->IsSmi()) { |
| 2651 | return other->IsNumber() && obj->Number() == other->Number(); |
| 2652 | } else if (obj->IsString()) { |
| 2653 | return other->IsString() && |
| 2654 | i::String::cast(*obj)->Equals(i::String::cast(*other)); |
| 2655 | } else if (obj->IsUndefined() || obj->IsUndetectableObject()) { |
| 2656 | return other->IsUndefined() || other->IsUndetectableObject(); |
| 2657 | } else { |
| 2658 | return false; |
| 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2663 | uint32_t Value::Uint32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2664 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2665 | if (obj->IsSmi()) { |
| 2666 | return i::Smi::cast(*obj)->value(); |
| 2667 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2668 | i::Isolate* isolate = i::Isolate::Current(); |
| 2669 | if (IsDeadCheck(isolate, "v8::Value::Uint32Value()")) return 0; |
| 2670 | LOG_API(isolate, "Uint32Value"); |
| 2671 | ENTER_V8(isolate); |
| 2672 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2673 | i::Handle<i::Object> num = |
| 2674 | i::Execution::ToUint32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2675 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2676 | if (num->IsSmi()) { |
| 2677 | return i::Smi::cast(*num)->value(); |
| 2678 | } else { |
| 2679 | return static_cast<uint32_t>(num->Number()); |
| 2680 | } |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | |
| 2685 | bool v8::Object::Set(v8::Handle<Value> key, v8::Handle<Value> value, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2686 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2687 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2688 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2689 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2690 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2691 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 2692 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2693 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2694 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2695 | i::Handle<i::Object> obj = i::SetProperty( |
| 2696 | self, |
| 2697 | key_obj, |
| 2698 | value_obj, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2699 | static_cast<PropertyAttributes>(attribs), |
| 2700 | i::kNonStrictMode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2701 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2702 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2703 | return true; |
| 2704 | } |
| 2705 | |
| 2706 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2707 | bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2708 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2709 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2710 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2711 | i::HandleScope scope(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2712 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2713 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2714 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2715 | i::Handle<i::Object> obj = i::SetElement( |
| 2716 | self, |
| 2717 | index, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2718 | value_obj, |
| 2719 | i::kNonStrictMode); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2720 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2721 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2722 | return true; |
| 2723 | } |
| 2724 | |
| 2725 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2726 | bool v8::Object::ForceSet(v8::Handle<Value> key, |
| 2727 | v8::Handle<Value> value, |
| 2728 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2729 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2730 | ON_BAILOUT(isolate, "v8::Object::ForceSet()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2731 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2732 | i::HandleScope scope(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2733 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2734 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2735 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2736 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2737 | i::Handle<i::Object> obj = i::ForceSetProperty( |
| 2738 | self, |
| 2739 | key_obj, |
| 2740 | value_obj, |
| 2741 | static_cast<PropertyAttributes>(attribs)); |
| 2742 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2743 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2744 | return true; |
| 2745 | } |
| 2746 | |
| 2747 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2748 | bool v8::Object::ForceDelete(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2749 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2750 | ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2751 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2752 | i::HandleScope scope(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2753 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2754 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2755 | |
| 2756 | // When turning on access checks for a global object deoptimize all functions |
| 2757 | // as optimized code does not always handle access checks. |
| 2758 | i::Deoptimizer::DeoptimizeGlobalObject(*self); |
| 2759 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2760 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2761 | i::Handle<i::Object> obj = i::ForceDeleteProperty(self, key_obj); |
| 2762 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2763 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2764 | return obj->IsTrue(); |
| 2765 | } |
| 2766 | |
| 2767 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2768 | Local<Value> v8::Object::Get(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2769 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2770 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2771 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2772 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 2773 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2774 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2775 | i::Handle<i::Object> result = i::GetProperty(self, key_obj); |
| 2776 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2777 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2778 | return Utils::ToLocal(result); |
| 2779 | } |
| 2780 | |
| 2781 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2782 | Local<Value> v8::Object::Get(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2783 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2784 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2785 | ENTER_V8(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2786 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2787 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2788 | i::Handle<i::Object> result = i::GetElement(self, index); |
| 2789 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2790 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2791 | return Utils::ToLocal(result); |
| 2792 | } |
| 2793 | |
| 2794 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2795 | PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { |
| 2796 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2797 | ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()", |
| 2798 | return static_cast<PropertyAttribute>(NONE)); |
| 2799 | ENTER_V8(isolate); |
| 2800 | i::HandleScope scope(isolate); |
| 2801 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2802 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2803 | if (!key_obj->IsString()) { |
| 2804 | EXCEPTION_PREAMBLE(isolate); |
| 2805 | key_obj = i::Execution::ToString(key_obj, &has_pending_exception); |
| 2806 | EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE)); |
| 2807 | } |
| 2808 | i::Handle<i::String> key_string = i::Handle<i::String>::cast(key_obj); |
| 2809 | PropertyAttributes result = self->GetPropertyAttribute(*key_string); |
| 2810 | if (result == ABSENT) return static_cast<PropertyAttribute>(NONE); |
| 2811 | return static_cast<PropertyAttribute>(result); |
| 2812 | } |
| 2813 | |
| 2814 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2815 | Local<Value> v8::Object::GetPrototype() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2816 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2817 | ON_BAILOUT(isolate, "v8::Object::GetPrototype()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2818 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2819 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2820 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 2821 | i::Handle<i::Object> result = i::GetPrototype(self); |
| 2822 | return Utils::ToLocal(result); |
| 2823 | } |
| 2824 | |
| 2825 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2826 | bool v8::Object::SetPrototype(Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2827 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2828 | ON_BAILOUT(isolate, "v8::Object::SetPrototype()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2829 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2830 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2831 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2832 | // We do not allow exceptions thrown while setting the prototype |
| 2833 | // to propagate outside. |
| 2834 | TryCatch try_catch; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2835 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2836 | i::Handle<i::Object> result = i::SetPrototype(self, value_obj); |
| 2837 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2838 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2839 | return true; |
| 2840 | } |
| 2841 | |
| 2842 | |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2843 | Local<Object> v8::Object::FindInstanceInPrototypeChain( |
| 2844 | v8::Handle<FunctionTemplate> tmpl) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2845 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2846 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2847 | "v8::Object::FindInstanceInPrototypeChain()", |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2848 | return Local<v8::Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2849 | ENTER_V8(isolate); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2850 | i::JSObject* object = *Utils::OpenHandle(this); |
| 2851 | i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl); |
| 2852 | while (!object->IsInstanceOf(tmpl_info)) { |
| 2853 | i::Object* prototype = object->GetPrototype(); |
| 2854 | if (!prototype->IsJSObject()) return Local<Object>(); |
| 2855 | object = i::JSObject::cast(prototype); |
| 2856 | } |
| 2857 | return Utils::ToLocal(i::Handle<i::JSObject>(object)); |
| 2858 | } |
| 2859 | |
| 2860 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2861 | Local<Array> v8::Object::GetPropertyNames() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2862 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2863 | ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()", |
| 2864 | return Local<v8::Array>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2865 | ENTER_V8(isolate); |
| 2866 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2867 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2868 | i::Handle<i::FixedArray> value = |
| 2869 | i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2870 | // Because we use caching to speed up enumeration it is important |
| 2871 | // to never change the result of the basic enumeration function so |
| 2872 | // we clone the result. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2873 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 2874 | i::Handle<i::JSArray> result = |
| 2875 | isolate->factory()->NewJSArrayWithElements(elms); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2876 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2880 | Local<Array> v8::Object::GetOwnPropertyNames() { |
| 2881 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2882 | ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()", |
| 2883 | return Local<v8::Array>()); |
| 2884 | ENTER_V8(isolate); |
| 2885 | i::HandleScope scope(isolate); |
| 2886 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2887 | i::Handle<i::FixedArray> value = |
| 2888 | i::GetKeysInFixedArrayFor(self, i::LOCAL_ONLY); |
| 2889 | // Because we use caching to speed up enumeration it is important |
| 2890 | // to never change the result of the basic enumeration function so |
| 2891 | // we clone the result. |
| 2892 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 2893 | i::Handle<i::JSArray> result = |
| 2894 | isolate->factory()->NewJSArrayWithElements(elms); |
| 2895 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
| 2896 | } |
| 2897 | |
| 2898 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2899 | Local<String> v8::Object::ObjectProtoToString() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2900 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2901 | ON_BAILOUT(isolate, "v8::Object::ObjectProtoToString()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2902 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2903 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2904 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2905 | |
| 2906 | i::Handle<i::Object> name(self->class_name()); |
| 2907 | |
| 2908 | // Native implementation of Object.prototype.toString (v8natives.js): |
| 2909 | // var c = %ClassOf(this); |
| 2910 | // if (c === 'Arguments') c = 'Object'; |
| 2911 | // return "[object " + c + "]"; |
| 2912 | |
| 2913 | if (!name->IsString()) { |
| 2914 | return v8::String::New("[object ]"); |
| 2915 | |
| 2916 | } else { |
| 2917 | i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); |
| 2918 | if (class_name->IsEqualTo(i::CStrVector("Arguments"))) { |
| 2919 | return v8::String::New("[object Object]"); |
| 2920 | |
| 2921 | } else { |
| 2922 | const char* prefix = "[object "; |
| 2923 | Local<String> str = Utils::ToLocal(class_name); |
| 2924 | const char* postfix = "]"; |
| 2925 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2926 | int prefix_len = i::StrLength(prefix); |
| 2927 | int str_len = str->Length(); |
| 2928 | int postfix_len = i::StrLength(postfix); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2929 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2930 | int buf_len = prefix_len + str_len + postfix_len; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2931 | i::ScopedVector<char> buf(buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2932 | |
| 2933 | // Write prefix. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2934 | char* ptr = buf.start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2935 | memcpy(ptr, prefix, prefix_len * v8::internal::kCharSize); |
| 2936 | ptr += prefix_len; |
| 2937 | |
| 2938 | // Write real content. |
| 2939 | str->WriteAscii(ptr, 0, str_len); |
| 2940 | ptr += str_len; |
| 2941 | |
| 2942 | // Write postfix. |
| 2943 | memcpy(ptr, postfix, postfix_len * v8::internal::kCharSize); |
| 2944 | |
| 2945 | // Copy the buffer into a heap-allocated string and return it. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2946 | Local<String> result = v8::String::New(buf.start(), buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2947 | return result; |
| 2948 | } |
| 2949 | } |
| 2950 | } |
| 2951 | |
| 2952 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2953 | Local<String> v8::Object::GetConstructorName() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2954 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2955 | ON_BAILOUT(isolate, "v8::Object::GetConstructorName()", |
| 2956 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2957 | ENTER_V8(isolate); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2958 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2959 | i::Handle<i::String> name(self->constructor_name()); |
| 2960 | return Utils::ToLocal(name); |
| 2961 | } |
| 2962 | |
| 2963 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2964 | bool v8::Object::Delete(v8::Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2965 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2966 | ON_BAILOUT(isolate, "v8::Object::Delete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2967 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2968 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2969 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2970 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
| 2971 | return i::DeleteProperty(self, key_obj)->IsTrue(); |
| 2972 | } |
| 2973 | |
| 2974 | |
| 2975 | bool v8::Object::Has(v8::Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2976 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2977 | ON_BAILOUT(isolate, "v8::Object::Has()", return false); |
| 2978 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2979 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2980 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
| 2981 | return self->HasProperty(*key_obj); |
| 2982 | } |
| 2983 | |
| 2984 | |
| 2985 | bool v8::Object::Delete(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2986 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2987 | ON_BAILOUT(isolate, "v8::Object::DeleteProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2988 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2989 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2990 | HandleScope scope; |
| 2991 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2992 | return i::DeleteElement(self, index)->IsTrue(); |
| 2993 | } |
| 2994 | |
| 2995 | |
| 2996 | bool v8::Object::Has(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2997 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2998 | ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2999 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3000 | return self->HasElement(index); |
| 3001 | } |
| 3002 | |
| 3003 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3004 | bool Object::SetAccessor(Handle<String> name, |
| 3005 | AccessorGetter getter, |
| 3006 | AccessorSetter setter, |
| 3007 | v8::Handle<Value> data, |
| 3008 | AccessControl settings, |
| 3009 | PropertyAttribute attributes) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3010 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3011 | ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3012 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3013 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3014 | i::Handle<i::AccessorInfo> info = MakeAccessorInfo(name, |
| 3015 | getter, setter, data, |
| 3016 | settings, attributes); |
| 3017 | i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(this), info); |
| 3018 | return !result.is_null() && !result->IsUndefined(); |
| 3019 | } |
| 3020 | |
| 3021 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3022 | bool v8::Object::HasOwnProperty(Handle<String> key) { |
| 3023 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3024 | ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", |
| 3025 | return false); |
| 3026 | return Utils::OpenHandle(this)->HasLocalProperty( |
| 3027 | *Utils::OpenHandle(*key)); |
| 3028 | } |
| 3029 | |
| 3030 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3031 | bool v8::Object::HasRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3032 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3033 | ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3034 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3035 | return Utils::OpenHandle(this)->HasRealNamedProperty( |
| 3036 | *Utils::OpenHandle(*key)); |
| 3037 | } |
| 3038 | |
| 3039 | |
| 3040 | bool v8::Object::HasRealIndexedProperty(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3041 | ON_BAILOUT(Utils::OpenHandle(this)->GetIsolate(), |
| 3042 | "v8::Object::HasRealIndexedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3043 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3044 | return Utils::OpenHandle(this)->HasRealElementProperty(index); |
| 3045 | } |
| 3046 | |
| 3047 | |
| 3048 | bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3049 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3050 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3051 | "v8::Object::HasRealNamedCallbackProperty()", |
| 3052 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3053 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3054 | return Utils::OpenHandle(this)->HasRealNamedCallbackProperty( |
| 3055 | *Utils::OpenHandle(*key)); |
| 3056 | } |
| 3057 | |
| 3058 | |
| 3059 | bool v8::Object::HasNamedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3060 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3061 | ON_BAILOUT(isolate, "v8::Object::HasNamedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3062 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3063 | return Utils::OpenHandle(this)->HasNamedInterceptor(); |
| 3064 | } |
| 3065 | |
| 3066 | |
| 3067 | bool v8::Object::HasIndexedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3068 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3069 | ON_BAILOUT(isolate, "v8::Object::HasIndexedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3070 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3071 | return Utils::OpenHandle(this)->HasIndexedInterceptor(); |
| 3072 | } |
| 3073 | |
| 3074 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3075 | static Local<Value> GetPropertyByLookup(i::Isolate* isolate, |
| 3076 | i::Handle<i::JSObject> receiver, |
| 3077 | i::Handle<i::String> name, |
| 3078 | i::LookupResult* lookup) { |
| 3079 | if (!lookup->IsProperty()) { |
| 3080 | // No real property was found. |
| 3081 | return Local<Value>(); |
| 3082 | } |
| 3083 | |
| 3084 | // If the property being looked up is a callback, it can throw |
| 3085 | // an exception. |
| 3086 | EXCEPTION_PREAMBLE(isolate); |
| 3087 | i::Handle<i::Object> result = i::GetProperty(receiver, name, lookup); |
| 3088 | has_pending_exception = result.is_null(); |
| 3089 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3090 | |
| 3091 | return Utils::ToLocal(result); |
| 3092 | } |
| 3093 | |
| 3094 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3095 | Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3096 | Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3097 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3098 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3099 | "v8::Object::GetRealNamedPropertyInPrototypeChain()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3100 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3101 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3102 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3103 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
| 3104 | i::LookupResult lookup; |
| 3105 | self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3106 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3107 | } |
| 3108 | |
| 3109 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3110 | Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3111 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3112 | ON_BAILOUT(isolate, "v8::Object::GetRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3113 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3114 | ENTER_V8(isolate); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3115 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3116 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
| 3117 | i::LookupResult lookup; |
| 3118 | self_obj->LookupRealNamedProperty(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3119 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3123 | // Turns on access checks by copying the map and setting the check flag. |
| 3124 | // Because the object gets a new map, existing inline cache caching |
| 3125 | // the old map of this object will fail. |
| 3126 | void v8::Object::TurnOnAccessCheck() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3127 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3128 | ON_BAILOUT(isolate, "v8::Object::TurnOnAccessCheck()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3129 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3130 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3131 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3132 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3133 | // When turning on access checks for a global object deoptimize all functions |
| 3134 | // as optimized code does not always handle access checks. |
| 3135 | i::Deoptimizer::DeoptimizeGlobalObject(*obj); |
| 3136 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3137 | i::Handle<i::Map> new_map = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3138 | isolate->factory()->CopyMapDropTransitions(i::Handle<i::Map>(obj->map())); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3139 | new_map->set_is_access_check_needed(true); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3140 | obj->set_map(*new_map); |
| 3141 | } |
| 3142 | |
| 3143 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3144 | bool v8::Object::IsDirty() { |
| 3145 | return Utils::OpenHandle(this)->IsDirty(); |
| 3146 | } |
| 3147 | |
| 3148 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3149 | Local<v8::Object> v8::Object::Clone() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3150 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3151 | ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3152 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3153 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3154 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3155 | i::Handle<i::JSObject> result = i::Copy(self); |
| 3156 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3157 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3158 | return Utils::ToLocal(result); |
| 3159 | } |
| 3160 | |
| 3161 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3162 | static i::Context* GetCreationContext(i::JSObject* object) { |
| 3163 | i::Object* constructor = object->map()->constructor(); |
| 3164 | i::JSFunction* function; |
| 3165 | if (!constructor->IsJSFunction()) { |
| 3166 | // API functions have null as a constructor, |
| 3167 | // but any JSFunction knows its context immediately. |
| 3168 | ASSERT(object->IsJSFunction() && |
| 3169 | i::JSFunction::cast(object)->shared()->IsApiFunction()); |
| 3170 | function = i::JSFunction::cast(object); |
| 3171 | } else { |
| 3172 | function = i::JSFunction::cast(constructor); |
| 3173 | } |
| 3174 | return function->context()->global_context(); |
| 3175 | } |
| 3176 | |
| 3177 | |
| 3178 | Local<v8::Context> v8::Object::CreationContext() { |
| 3179 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3180 | ON_BAILOUT(isolate, |
| 3181 | "v8::Object::CreationContext()", return Local<v8::Context>()); |
| 3182 | ENTER_V8(isolate); |
| 3183 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3184 | i::Context* context = GetCreationContext(*self); |
| 3185 | return Utils::ToLocal(i::Handle<i::Context>(context)); |
| 3186 | } |
| 3187 | |
| 3188 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3189 | int v8::Object::GetIdentityHash() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3190 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3191 | ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3192 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3193 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3194 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3195 | return i::GetIdentityHash(self); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | |
| 3199 | bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, |
| 3200 | v8::Handle<v8::Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3201 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3202 | ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3203 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3204 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3205 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3206 | i::Handle<i::Object> hidden_props(i::GetHiddenProperties( |
| 3207 | self, |
| 3208 | i::JSObject::ALLOW_CREATION)); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3209 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3210 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3211 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3212 | i::Handle<i::Object> obj = i::SetProperty( |
| 3213 | hidden_props, |
| 3214 | key_obj, |
| 3215 | value_obj, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3216 | static_cast<PropertyAttributes>(None), |
| 3217 | i::kNonStrictMode); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3218 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3219 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3220 | return true; |
| 3221 | } |
| 3222 | |
| 3223 | |
| 3224 | v8::Local<v8::Value> v8::Object::GetHiddenValue(v8::Handle<v8::String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3225 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3226 | ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()", |
| 3227 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3228 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3229 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3230 | i::Handle<i::Object> hidden_props(i::GetHiddenProperties( |
| 3231 | self, |
| 3232 | i::JSObject::OMIT_CREATION)); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3233 | if (hidden_props->IsUndefined()) { |
| 3234 | return v8::Local<v8::Value>(); |
| 3235 | } |
| 3236 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3237 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3238 | i::Handle<i::Object> result = i::GetProperty(hidden_props, key_obj); |
| 3239 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3240 | EXCEPTION_BAILOUT_CHECK(isolate, v8::Local<v8::Value>()); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3241 | if (result->IsUndefined()) { |
| 3242 | return v8::Local<v8::Value>(); |
| 3243 | } |
| 3244 | return Utils::ToLocal(result); |
| 3245 | } |
| 3246 | |
| 3247 | |
| 3248 | bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3249 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3250 | ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3251 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3252 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3253 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3254 | i::Handle<i::Object> hidden_props(i::GetHiddenProperties( |
| 3255 | self, |
| 3256 | i::JSObject::OMIT_CREATION)); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3257 | if (hidden_props->IsUndefined()) { |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 3258 | return true; |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3259 | } |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 3260 | i::Handle<i::JSObject> js_obj(i::JSObject::cast(*hidden_props)); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3261 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 3262 | return i::DeleteProperty(js_obj, key_obj)->IsTrue(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3266 | namespace { |
| 3267 | |
| 3268 | void PrepareExternalArrayElements(i::Handle<i::JSObject> object, |
| 3269 | void* data, |
| 3270 | ExternalArrayType array_type, |
| 3271 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3272 | i::Isolate* isolate = object->GetIsolate(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3273 | i::Handle<i::ExternalArray> array = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3274 | isolate->factory()->NewExternalArray(length, array_type, data); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3275 | |
| 3276 | // If the object already has external elements, create a new, unique |
| 3277 | // map if the element type is now changing, because assumptions about |
| 3278 | // generated code based on the receiver's map will be invalid. |
| 3279 | i::Handle<i::HeapObject> elements(object->elements()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3280 | bool cant_reuse_map = |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3281 | elements->map()->IsUndefined() || |
| 3282 | !elements->map()->has_external_array_elements() || |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3283 | elements->map() != isolate->heap()->MapForExternalArrayType(array_type); |
| 3284 | if (cant_reuse_map) { |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3285 | i::Handle<i::Map> external_array_map = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3286 | isolate->factory()->GetExternalArrayElementsMap( |
| 3287 | i::Handle<i::Map>(object->map()), |
| 3288 | array_type, |
| 3289 | object->HasFastProperties()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3290 | object->set_map(*external_array_map); |
| 3291 | } |
| 3292 | object->set_elements(*array); |
| 3293 | } |
| 3294 | |
| 3295 | } // namespace |
| 3296 | |
| 3297 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3298 | void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3299 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3300 | ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3301 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3302 | i::HandleScope scope(isolate); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3303 | if (!ApiCheck(length <= i::ExternalPixelArray::kMaxLength, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3304 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3305 | "length exceeds max acceptable value")) { |
| 3306 | return; |
| 3307 | } |
| 3308 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3309 | if (!ApiCheck(!self->IsJSArray(), |
| 3310 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3311 | "JSArray is not supported")) { |
| 3312 | return; |
| 3313 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3314 | PrepareExternalArrayElements(self, data, kExternalPixelArray, length); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3318 | bool v8::Object::HasIndexedPropertiesInPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3319 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3320 | ON_BAILOUT(self->GetIsolate(), "v8::HasIndexedPropertiesInPixelData()", |
| 3321 | return false); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3322 | return self->HasExternalPixelElements(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | |
| 3326 | uint8_t* v8::Object::GetIndexedPropertiesPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3327 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3328 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelData()", |
| 3329 | return NULL); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3330 | if (self->HasExternalPixelElements()) { |
| 3331 | return i::ExternalPixelArray::cast(self->elements())-> |
| 3332 | external_pixel_pointer(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3333 | } else { |
| 3334 | return NULL; |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | |
| 3339 | int v8::Object::GetIndexedPropertiesPixelDataLength() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3340 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3341 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelDataLength()", |
| 3342 | return -1); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3343 | if (self->HasExternalPixelElements()) { |
| 3344 | return i::ExternalPixelArray::cast(self->elements())->length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3345 | } else { |
| 3346 | return -1; |
| 3347 | } |
| 3348 | } |
| 3349 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3350 | void v8::Object::SetIndexedPropertiesToExternalArrayData( |
| 3351 | void* data, |
| 3352 | ExternalArrayType array_type, |
| 3353 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3354 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3355 | ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3356 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3357 | i::HandleScope scope(isolate); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3358 | if (!ApiCheck(length <= i::ExternalArray::kMaxLength, |
| 3359 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3360 | "length exceeds max acceptable value")) { |
| 3361 | return; |
| 3362 | } |
| 3363 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3364 | if (!ApiCheck(!self->IsJSArray(), |
| 3365 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3366 | "JSArray is not supported")) { |
| 3367 | return; |
| 3368 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3369 | PrepareExternalArrayElements(self, data, array_type, length); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3373 | bool v8::Object::HasIndexedPropertiesInExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3374 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3375 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3376 | "v8::HasIndexedPropertiesInExternalArrayData()", |
| 3377 | return false); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3378 | return self->HasExternalArrayElements(); |
| 3379 | } |
| 3380 | |
| 3381 | |
| 3382 | void* v8::Object::GetIndexedPropertiesExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3383 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3384 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3385 | "v8::GetIndexedPropertiesExternalArrayData()", |
| 3386 | return NULL); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3387 | if (self->HasExternalArrayElements()) { |
| 3388 | return i::ExternalArray::cast(self->elements())->external_pointer(); |
| 3389 | } else { |
| 3390 | return NULL; |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | |
| 3395 | ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3396 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3397 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3398 | "v8::GetIndexedPropertiesExternalArrayDataType()", |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3399 | return static_cast<ExternalArrayType>(-1)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3400 | switch (self->elements()->map()->instance_type()) { |
| 3401 | case i::EXTERNAL_BYTE_ARRAY_TYPE: |
| 3402 | return kExternalByteArray; |
| 3403 | case i::EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 3404 | return kExternalUnsignedByteArray; |
| 3405 | case i::EXTERNAL_SHORT_ARRAY_TYPE: |
| 3406 | return kExternalShortArray; |
| 3407 | case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 3408 | return kExternalUnsignedShortArray; |
| 3409 | case i::EXTERNAL_INT_ARRAY_TYPE: |
| 3410 | return kExternalIntArray; |
| 3411 | case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 3412 | return kExternalUnsignedIntArray; |
| 3413 | case i::EXTERNAL_FLOAT_ARRAY_TYPE: |
| 3414 | return kExternalFloatArray; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3415 | case i::EXTERNAL_DOUBLE_ARRAY_TYPE: |
| 3416 | return kExternalDoubleArray; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3417 | case i::EXTERNAL_PIXEL_ARRAY_TYPE: |
| 3418 | return kExternalPixelArray; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3419 | default: |
| 3420 | return static_cast<ExternalArrayType>(-1); |
| 3421 | } |
| 3422 | } |
| 3423 | |
| 3424 | |
| 3425 | int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3426 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3427 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3428 | "v8::GetIndexedPropertiesExternalArrayDataLength()", |
| 3429 | return 0); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3430 | if (self->HasExternalArrayElements()) { |
| 3431 | return i::ExternalArray::cast(self->elements())->length(); |
| 3432 | } else { |
| 3433 | return -1; |
| 3434 | } |
| 3435 | } |
| 3436 | |
| 3437 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3438 | bool v8::Object::IsCallable() { |
| 3439 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3440 | ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false); |
| 3441 | ENTER_V8(isolate); |
| 3442 | i::HandleScope scope(isolate); |
| 3443 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3444 | if (obj->IsJSFunction()) return true; |
| 3445 | return i::Execution::GetFunctionDelegate(obj)->IsJSFunction(); |
| 3446 | } |
| 3447 | |
| 3448 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3449 | Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Object> recv, int argc, |
| 3450 | v8::Handle<v8::Value> argv[]) { |
| 3451 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3452 | ON_BAILOUT(isolate, "v8::Object::CallAsFunction()", |
| 3453 | return Local<v8::Value>()); |
| 3454 | LOG_API(isolate, "Object::CallAsFunction"); |
| 3455 | ENTER_V8(isolate); |
| 3456 | i::HandleScope scope(isolate); |
| 3457 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3458 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3459 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 3460 | i::Object*** args = reinterpret_cast<i::Object***>(argv); |
| 3461 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(); |
| 3462 | if (obj->IsJSFunction()) { |
| 3463 | fun = i::Handle<i::JSFunction>::cast(obj); |
| 3464 | } else { |
| 3465 | EXCEPTION_PREAMBLE(isolate); |
| 3466 | i::Handle<i::Object> delegate = |
| 3467 | i::Execution::TryGetFunctionDelegate(obj, &has_pending_exception); |
| 3468 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3469 | fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3470 | recv_obj = obj; |
| 3471 | } |
| 3472 | EXCEPTION_PREAMBLE(isolate); |
| 3473 | i::Handle<i::Object> returned = |
| 3474 | i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); |
| 3475 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3476 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3477 | } |
| 3478 | |
| 3479 | |
| 3480 | Local<v8::Value> Object::CallAsConstructor(int argc, |
| 3481 | v8::Handle<v8::Value> argv[]) { |
| 3482 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3483 | ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()", |
| 3484 | return Local<v8::Object>()); |
| 3485 | LOG_API(isolate, "Object::CallAsConstructor"); |
| 3486 | ENTER_V8(isolate); |
| 3487 | i::HandleScope scope(isolate); |
| 3488 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3489 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 3490 | i::Object*** args = reinterpret_cast<i::Object***>(argv); |
| 3491 | if (obj->IsJSFunction()) { |
| 3492 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj); |
| 3493 | EXCEPTION_PREAMBLE(isolate); |
| 3494 | i::Handle<i::Object> returned = |
| 3495 | i::Execution::New(fun, argc, args, &has_pending_exception); |
| 3496 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3497 | return Utils::ToLocal(scope.CloseAndEscape( |
| 3498 | i::Handle<i::JSObject>::cast(returned))); |
| 3499 | } |
| 3500 | EXCEPTION_PREAMBLE(isolate); |
| 3501 | i::Handle<i::Object> delegate = |
| 3502 | i::Execution::TryGetConstructorDelegate(obj, &has_pending_exception); |
| 3503 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3504 | if (!delegate->IsUndefined()) { |
| 3505 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3506 | EXCEPTION_PREAMBLE(isolate); |
| 3507 | i::Handle<i::Object> returned = |
| 3508 | i::Execution::Call(fun, obj, argc, args, &has_pending_exception); |
| 3509 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3510 | ASSERT(!delegate->IsUndefined()); |
| 3511 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3512 | } |
| 3513 | return Local<v8::Object>(); |
| 3514 | } |
| 3515 | |
| 3516 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3517 | Local<v8::Object> Function::NewInstance() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3518 | return NewInstance(0, NULL); |
| 3519 | } |
| 3520 | |
| 3521 | |
| 3522 | Local<v8::Object> Function::NewInstance(int argc, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3523 | v8::Handle<v8::Value> argv[]) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3524 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3525 | ON_BAILOUT(isolate, "v8::Function::NewInstance()", |
| 3526 | return Local<v8::Object>()); |
| 3527 | LOG_API(isolate, "Function::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3528 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3529 | HandleScope scope; |
| 3530 | i::Handle<i::JSFunction> function = Utils::OpenHandle(this); |
| 3531 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 3532 | i::Object*** args = reinterpret_cast<i::Object***>(argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3533 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3534 | i::Handle<i::Object> returned = |
| 3535 | i::Execution::New(function, argc, args, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3536 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3537 | return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned))); |
| 3538 | } |
| 3539 | |
| 3540 | |
| 3541 | Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc, |
| 3542 | v8::Handle<v8::Value> argv[]) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3543 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3544 | ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>()); |
| 3545 | LOG_API(isolate, "Function::Call"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3546 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3547 | i::Object* raw_result = NULL; |
| 3548 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3549 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3550 | i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); |
| 3551 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3552 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 3553 | i::Object*** args = reinterpret_cast<i::Object***>(argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3554 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3555 | i::Handle<i::Object> returned = |
| 3556 | i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3557 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3558 | raw_result = *returned; |
| 3559 | } |
| 3560 | i::Handle<i::Object> result(raw_result); |
| 3561 | return Utils::ToLocal(result); |
| 3562 | } |
| 3563 | |
| 3564 | |
| 3565 | void Function::SetName(v8::Handle<v8::String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3566 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3567 | ENTER_V8(isolate); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3568 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3569 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3570 | func->shared()->set_name(*Utils::OpenHandle(*name)); |
| 3571 | } |
| 3572 | |
| 3573 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3574 | Handle<Value> Function::GetName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3575 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3576 | return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name())); |
| 3577 | } |
| 3578 | |
| 3579 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3580 | ScriptOrigin Function::GetScriptOrigin() const { |
| 3581 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3582 | if (func->shared()->script()->IsScript()) { |
| 3583 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 3584 | v8::ScriptOrigin origin( |
| 3585 | Utils::ToLocal(i::Handle<i::Object>(script->name())), |
| 3586 | v8::Integer::New(script->line_offset()->value()), |
| 3587 | v8::Integer::New(script->column_offset()->value())); |
| 3588 | return origin; |
| 3589 | } |
| 3590 | return v8::ScriptOrigin(Handle<Value>()); |
| 3591 | } |
| 3592 | |
| 3593 | |
| 3594 | const int Function::kLineOffsetNotFound = -1; |
| 3595 | |
| 3596 | |
| 3597 | int Function::GetScriptLineNumber() const { |
| 3598 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3599 | if (func->shared()->script()->IsScript()) { |
| 3600 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 3601 | return i::GetScriptLineNumber(script, func->shared()->start_position()); |
| 3602 | } |
| 3603 | return kLineOffsetNotFound; |
| 3604 | } |
| 3605 | |
| 3606 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3607 | int String::Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3608 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3609 | if (IsDeadCheck(str->GetIsolate(), "v8::String::Length()")) return 0; |
| 3610 | return str->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3614 | int String::Utf8Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3615 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3616 | if (IsDeadCheck(str->GetIsolate(), "v8::String::Utf8Length()")) return 0; |
| 3617 | return str->Utf8Length(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3621 | int String::WriteUtf8(char* buffer, |
| 3622 | int capacity, |
| 3623 | int* nchars_ref, |
| 3624 | WriteHints hints) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3625 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3626 | if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; |
| 3627 | LOG_API(isolate, "String::WriteUtf8"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3628 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3629 | i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3630 | i::Handle<i::String> str = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3631 | isolate->string_tracker()->RecordWrite(str); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3632 | if (hints & HINT_MANY_WRITES_EXPECTED) { |
| 3633 | // Flatten the string for efficiency. This applies whether we are |
| 3634 | // using StringInputBuffer or Get(i) to access the characters. |
| 3635 | str->TryFlatten(); |
| 3636 | } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3637 | write_input_buffer.Reset(0, *str); |
| 3638 | int len = str->length(); |
| 3639 | // Encode the first K - 3 bytes directly into the buffer since we |
| 3640 | // know there's room for them. If no capacity is given we copy all |
| 3641 | // of them here. |
| 3642 | int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); |
| 3643 | int i; |
| 3644 | int pos = 0; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3645 | int nchars = 0; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3646 | for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) { |
| 3647 | i::uc32 c = write_input_buffer.GetNext(); |
| 3648 | int written = unibrow::Utf8::Encode(buffer + pos, c); |
| 3649 | pos += written; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3650 | nchars++; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3651 | } |
| 3652 | if (i < len) { |
| 3653 | // For the last characters we need to check the length for each one |
| 3654 | // because they may be longer than the remaining space in the |
| 3655 | // buffer. |
| 3656 | char intermediate[unibrow::Utf8::kMaxEncodedSize]; |
| 3657 | for (; i < len && pos < capacity; i++) { |
| 3658 | i::uc32 c = write_input_buffer.GetNext(); |
| 3659 | int written = unibrow::Utf8::Encode(intermediate, c); |
| 3660 | if (pos + written <= capacity) { |
| 3661 | for (int j = 0; j < written; j++) |
| 3662 | buffer[pos + j] = intermediate[j]; |
| 3663 | pos += written; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3664 | nchars++; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3665 | } else { |
| 3666 | // We've reached the end of the buffer |
| 3667 | break; |
| 3668 | } |
| 3669 | } |
| 3670 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3671 | if (nchars_ref != NULL) *nchars_ref = nchars; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3672 | if (i == len && (capacity == -1 || pos < capacity)) |
| 3673 | buffer[pos++] = '\0'; |
| 3674 | return pos; |
| 3675 | } |
| 3676 | |
| 3677 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3678 | int String::WriteAscii(char* buffer, |
| 3679 | int start, |
| 3680 | int length, |
| 3681 | WriteHints hints) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3682 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3683 | if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0; |
| 3684 | LOG_API(isolate, "String::WriteAscii"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3685 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3686 | i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3687 | ASSERT(start >= 0 && length >= -1); |
| 3688 | i::Handle<i::String> str = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3689 | isolate->string_tracker()->RecordWrite(str); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3690 | if (hints & HINT_MANY_WRITES_EXPECTED) { |
| 3691 | // Flatten the string for efficiency. This applies whether we are |
| 3692 | // using StringInputBuffer or Get(i) to access the characters. |
| 3693 | str->TryFlatten(); |
| 3694 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3695 | int end = length; |
| 3696 | if ( (length == -1) || (length > str->length() - start) ) |
| 3697 | end = str->length() - start; |
| 3698 | if (end < 0) return 0; |
| 3699 | write_input_buffer.Reset(start, *str); |
| 3700 | int i; |
| 3701 | for (i = 0; i < end; i++) { |
| 3702 | char c = static_cast<char>(write_input_buffer.GetNext()); |
| 3703 | if (c == '\0') c = ' '; |
| 3704 | buffer[i] = c; |
| 3705 | } |
| 3706 | if (length == -1 || i < length) |
| 3707 | buffer[i] = '\0'; |
| 3708 | return i; |
| 3709 | } |
| 3710 | |
| 3711 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3712 | int String::Write(uint16_t* buffer, |
| 3713 | int start, |
| 3714 | int length, |
| 3715 | WriteHints hints) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3716 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3717 | if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; |
| 3718 | LOG_API(isolate, "String::Write"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3719 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3720 | ASSERT(start >= 0 && length >= -1); |
| 3721 | i::Handle<i::String> str = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3722 | isolate->string_tracker()->RecordWrite(str); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3723 | if (hints & HINT_MANY_WRITES_EXPECTED) { |
| 3724 | // Flatten the string for efficiency. This applies whether we are |
| 3725 | // using StringInputBuffer or Get(i) to access the characters. |
| 3726 | str->TryFlatten(); |
| 3727 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3728 | int end = start + length; |
| 3729 | if ((length == -1) || (length > str->length() - start) ) |
| 3730 | end = str->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3731 | if (end < 0) return 0; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3732 | i::String::WriteToFlat(*str, buffer, start, end); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3733 | if (length == -1 || end - start < length) { |
| 3734 | buffer[end - start] = '\0'; |
| 3735 | } |
| 3736 | return end - start; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3740 | bool v8::String::IsExternal() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3741 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3742 | if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { |
| 3743 | return false; |
| 3744 | } |
| 3745 | EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3746 | return i::StringShape(*str).IsExternalTwoByte(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3750 | bool v8::String::IsExternalAscii() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3751 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3752 | if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternalAscii()")) { |
| 3753 | return false; |
| 3754 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3755 | return i::StringShape(*str).IsExternalAscii(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3759 | void v8::String::VerifyExternalStringResource( |
| 3760 | v8::String::ExternalStringResource* value) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3761 | i::Handle<i::String> str = Utils::OpenHandle(this); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3762 | v8::String::ExternalStringResource* expected; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3763 | if (i::StringShape(*str).IsExternalTwoByte()) { |
| 3764 | void* resource = i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3765 | expected = reinterpret_cast<ExternalStringResource*>(resource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3766 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3767 | expected = NULL; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3768 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3769 | CHECK_EQ(expected, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | |
| 3773 | v8::String::ExternalAsciiStringResource* |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3774 | v8::String::GetExternalAsciiStringResource() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3775 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3776 | if (IsDeadCheck(str->GetIsolate(), |
| 3777 | "v8::String::GetExternalAsciiStringResource()")) { |
| 3778 | return NULL; |
| 3779 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3780 | if (i::StringShape(*str).IsExternalAscii()) { |
| 3781 | void* resource = i::Handle<i::ExternalAsciiString>::cast(str)->resource(); |
| 3782 | return reinterpret_cast<ExternalAsciiStringResource*>(resource); |
| 3783 | } else { |
| 3784 | return NULL; |
| 3785 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3789 | double Number::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3790 | if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3791 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3792 | return obj->Number(); |
| 3793 | } |
| 3794 | |
| 3795 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3796 | bool Boolean::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3797 | if (IsDeadCheck(i::Isolate::Current(), "v8::Boolean::Value()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3798 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3799 | return obj->IsTrue(); |
| 3800 | } |
| 3801 | |
| 3802 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3803 | int64_t Integer::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3804 | if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3805 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3806 | if (obj->IsSmi()) { |
| 3807 | return i::Smi::cast(*obj)->value(); |
| 3808 | } else { |
| 3809 | return static_cast<int64_t>(obj->Number()); |
| 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3814 | int32_t Int32::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3815 | if (IsDeadCheck(i::Isolate::Current(), "v8::Int32::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3816 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3817 | if (obj->IsSmi()) { |
| 3818 | return i::Smi::cast(*obj)->value(); |
| 3819 | } else { |
| 3820 | return static_cast<int32_t>(obj->Number()); |
| 3821 | } |
| 3822 | } |
| 3823 | |
| 3824 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3825 | uint32_t Uint32::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3826 | if (IsDeadCheck(i::Isolate::Current(), "v8::Uint32::Value()")) return 0; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3827 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3828 | if (obj->IsSmi()) { |
| 3829 | return i::Smi::cast(*obj)->value(); |
| 3830 | } else { |
| 3831 | return static_cast<uint32_t>(obj->Number()); |
| 3832 | } |
| 3833 | } |
| 3834 | |
| 3835 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3836 | int v8::Object::InternalFieldCount() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3837 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3838 | if (IsDeadCheck(obj->GetIsolate(), "v8::Object::InternalFieldCount()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3839 | return 0; |
| 3840 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3841 | return obj->GetInternalFieldCount(); |
| 3842 | } |
| 3843 | |
| 3844 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3845 | Local<Value> v8::Object::CheckedGetInternalField(int index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3846 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3847 | if (IsDeadCheck(obj->GetIsolate(), "v8::Object::GetInternalField()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3848 | return Local<Value>(); |
| 3849 | } |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3850 | if (!ApiCheck(index < obj->GetInternalFieldCount(), |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3851 | "v8::Object::GetInternalField()", |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3852 | "Reading internal field out of bounds")) { |
| 3853 | return Local<Value>(); |
| 3854 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3855 | i::Handle<i::Object> value(obj->GetInternalField(index)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3856 | Local<Value> result = Utils::ToLocal(value); |
| 3857 | #ifdef DEBUG |
| 3858 | Local<Value> unchecked = UncheckedGetInternalField(index); |
| 3859 | ASSERT(unchecked.IsEmpty() || (unchecked == result)); |
| 3860 | #endif |
| 3861 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3862 | } |
| 3863 | |
| 3864 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3865 | void v8::Object::SetInternalField(int index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3866 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3867 | i::Isolate* isolate = obj->GetIsolate(); |
| 3868 | if (IsDeadCheck(isolate, "v8::Object::SetInternalField()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3869 | return; |
| 3870 | } |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3871 | if (!ApiCheck(index < obj->GetInternalFieldCount(), |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3872 | "v8::Object::SetInternalField()", |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3873 | "Writing internal field out of bounds")) { |
| 3874 | return; |
| 3875 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3876 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3877 | i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 3878 | obj->SetInternalField(index, *val); |
| 3879 | } |
| 3880 | |
| 3881 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3882 | static bool CanBeEncodedAsSmi(void* ptr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3883 | const uintptr_t address = reinterpret_cast<uintptr_t>(ptr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3884 | return ((address & i::kEncodablePointerMask) == 0); |
| 3885 | } |
| 3886 | |
| 3887 | |
| 3888 | static i::Smi* EncodeAsSmi(void* ptr) { |
| 3889 | ASSERT(CanBeEncodedAsSmi(ptr)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3890 | const uintptr_t address = reinterpret_cast<uintptr_t>(ptr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3891 | i::Smi* result = reinterpret_cast<i::Smi*>(address << i::kPointerToSmiShift); |
| 3892 | ASSERT(i::Internals::HasSmiTag(result)); |
| 3893 | ASSERT_EQ(result, i::Smi::FromInt(result->value())); |
| 3894 | ASSERT_EQ(ptr, i::Internals::GetExternalPointerFromSmi(result)); |
| 3895 | return result; |
| 3896 | } |
| 3897 | |
| 3898 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3899 | void v8::Object::SetPointerInInternalField(int index, void* value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3900 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3901 | ENTER_V8(isolate); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3902 | if (CanBeEncodedAsSmi(value)) { |
| 3903 | Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value)); |
| 3904 | } else { |
| 3905 | HandleScope scope; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3906 | i::Handle<i::Foreign> foreign = |
| 3907 | isolate->factory()->NewForeign( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3908 | reinterpret_cast<i::Address>(value), i::TENURED); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3909 | if (!foreign.is_null()) |
| 3910 | Utils::OpenHandle(this)->SetInternalField(index, *foreign); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3911 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3912 | ASSERT_EQ(value, GetPointerFromInternalField(index)); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3916 | // --- E n v i r o n m e n t --- |
| 3917 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3918 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3919 | bool v8::V8::Initialize() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3920 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 3921 | if (isolate != NULL && isolate->IsInitialized()) { |
| 3922 | return true; |
| 3923 | } |
| 3924 | return InitializeHelper(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3925 | } |
| 3926 | |
| 3927 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 3928 | void v8::V8::SetEntropySource(EntropySource source) { |
| 3929 | i::V8::SetEntropySource(source); |
| 3930 | } |
| 3931 | |
| 3932 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3933 | bool v8::V8::Dispose() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3934 | i::Isolate* isolate = i::Isolate::Current(); |
| 3935 | if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(), |
| 3936 | "v8::V8::Dispose()", |
| 3937 | "Use v8::Isolate::Dispose() for a non-default isolate.")) { |
| 3938 | return false; |
| 3939 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3940 | i::V8::TearDown(); |
| 3941 | return true; |
| 3942 | } |
| 3943 | |
| 3944 | |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3945 | HeapStatistics::HeapStatistics(): total_heap_size_(0), |
| 3946 | total_heap_size_executable_(0), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3947 | used_heap_size_(0), |
| 3948 | heap_size_limit_(0) { } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3949 | |
| 3950 | |
| 3951 | void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3952 | i::Heap* heap = i::Isolate::Current()->heap(); |
| 3953 | heap_statistics->set_total_heap_size(heap->CommittedMemory()); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3954 | heap_statistics->set_total_heap_size_executable( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3955 | heap->CommittedMemoryExecutable()); |
| 3956 | heap_statistics->set_used_heap_size(heap->SizeOfObjects()); |
| 3957 | heap_statistics->set_heap_size_limit(heap->MaxReserved()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3958 | } |
| 3959 | |
| 3960 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3961 | bool v8::V8::IdleNotification() { |
| 3962 | // Returning true tells the caller that it need not |
| 3963 | // continue to call IdleNotification. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3964 | if (!i::Isolate::Current()->IsInitialized()) return true; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3965 | return i::V8::IdleNotification(); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 3966 | } |
| 3967 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3968 | |
| 3969 | void v8::V8::LowMemoryNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3970 | i::Isolate* isolate = i::Isolate::Current(); |
| 3971 | if (!isolate->IsInitialized()) return; |
| 3972 | isolate->heap()->CollectAllGarbage(true); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3976 | int v8::V8::ContextDisposedNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3977 | i::Isolate* isolate = i::Isolate::Current(); |
| 3978 | if (!isolate->IsInitialized()) return 0; |
| 3979 | return isolate->heap()->NotifyContextDisposed(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3983 | const char* v8::V8::GetVersion() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3984 | return i::Version::GetVersion(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3988 | static i::Handle<i::FunctionTemplateInfo> |
| 3989 | EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) { |
| 3990 | if (templ->constructor()->IsUndefined()) { |
| 3991 | Local<FunctionTemplate> constructor = FunctionTemplate::New(); |
| 3992 | Utils::OpenHandle(*constructor)->set_instance_template(*templ); |
| 3993 | templ->set_constructor(*Utils::OpenHandle(*constructor)); |
| 3994 | } |
| 3995 | return i::Handle<i::FunctionTemplateInfo>( |
| 3996 | i::FunctionTemplateInfo::cast(templ->constructor())); |
| 3997 | } |
| 3998 | |
| 3999 | |
| 4000 | Persistent<Context> v8::Context::New( |
| 4001 | v8::ExtensionConfiguration* extensions, |
| 4002 | v8::Handle<ObjectTemplate> global_template, |
| 4003 | v8::Handle<Value> global_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4004 | i::Isolate* isolate = i::Isolate::Current(); |
| 4005 | EnsureInitializedForIsolate(isolate, "v8::Context::New()"); |
| 4006 | LOG_API(isolate, "Context::New"); |
| 4007 | ON_BAILOUT(isolate, "v8::Context::New()", return Persistent<Context>()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4008 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4009 | // Enter V8 via an ENTER_V8 scope. |
| 4010 | i::Handle<i::Context> env; |
| 4011 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4012 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4013 | v8::Handle<ObjectTemplate> proxy_template = global_template; |
| 4014 | i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
| 4015 | i::Handle<i::FunctionTemplateInfo> global_constructor; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4016 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4017 | if (!global_template.IsEmpty()) { |
| 4018 | // Make sure that the global_template has a constructor. |
| 4019 | global_constructor = |
| 4020 | EnsureConstructor(Utils::OpenHandle(*global_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4021 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4022 | // Create a fresh template for the global proxy object. |
| 4023 | proxy_template = ObjectTemplate::New(); |
| 4024 | proxy_constructor = |
| 4025 | EnsureConstructor(Utils::OpenHandle(*proxy_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4026 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4027 | // Set the global template to be the prototype template of |
| 4028 | // global proxy template. |
| 4029 | proxy_constructor->set_prototype_template( |
| 4030 | *Utils::OpenHandle(*global_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4031 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4032 | // Migrate security handlers from global_template to |
| 4033 | // proxy_template. Temporarily removing access check |
| 4034 | // information from the global template. |
| 4035 | if (!global_constructor->access_check_info()->IsUndefined()) { |
| 4036 | proxy_constructor->set_access_check_info( |
| 4037 | global_constructor->access_check_info()); |
| 4038 | proxy_constructor->set_needs_access_check( |
| 4039 | global_constructor->needs_access_check()); |
| 4040 | global_constructor->set_needs_access_check(false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4041 | global_constructor->set_access_check_info( |
| 4042 | isolate->heap()->undefined_value()); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4043 | } |
| 4044 | } |
| 4045 | |
| 4046 | // Create the environment. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4047 | env = isolate->bootstrapper()->CreateEnvironment( |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4048 | isolate, |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4049 | Utils::OpenHandle(*global_object), |
| 4050 | proxy_template, |
| 4051 | extensions); |
| 4052 | |
| 4053 | // Restore the access check info on the global template. |
| 4054 | if (!global_template.IsEmpty()) { |
| 4055 | ASSERT(!global_constructor.is_null()); |
| 4056 | ASSERT(!proxy_constructor.is_null()); |
| 4057 | global_constructor->set_access_check_info( |
| 4058 | proxy_constructor->access_check_info()); |
| 4059 | global_constructor->set_needs_access_check( |
| 4060 | proxy_constructor->needs_access_check()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4061 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4062 | isolate->runtime_profiler()->Reset(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4063 | } |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4064 | // Leave V8. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4065 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 4066 | if (env.is_null()) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4067 | return Persistent<Context>(); |
| 4068 | return Persistent<Context>(Utils::ToLocal(env)); |
| 4069 | } |
| 4070 | |
| 4071 | |
| 4072 | void v8::Context::SetSecurityToken(Handle<Value> token) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4073 | i::Isolate* isolate = i::Isolate::Current(); |
| 4074 | if (IsDeadCheck(isolate, "v8::Context::SetSecurityToken()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4075 | return; |
| 4076 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4077 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4078 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4079 | i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4080 | env->set_security_token(*token_handle); |
| 4081 | } |
| 4082 | |
| 4083 | |
| 4084 | void v8::Context::UseDefaultSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4085 | i::Isolate* isolate = i::Isolate::Current(); |
| 4086 | if (IsDeadCheck(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4087 | "v8::Context::UseDefaultSecurityToken()")) { |
| 4088 | return; |
| 4089 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4090 | ENTER_V8(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4091 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4092 | env->set_security_token(env->global()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | |
| 4096 | Handle<Value> v8::Context::GetSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4097 | i::Isolate* isolate = i::Isolate::Current(); |
| 4098 | if (IsDeadCheck(isolate, "v8::Context::GetSecurityToken()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4099 | return Handle<Value>(); |
| 4100 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4101 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4102 | i::Object* security_token = env->security_token(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4103 | i::Handle<i::Object> token_handle(security_token); |
| 4104 | return Utils::ToLocal(token_handle); |
| 4105 | } |
| 4106 | |
| 4107 | |
| 4108 | bool Context::HasOutOfMemoryException() { |
| 4109 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4110 | return env->has_out_of_memory(); |
| 4111 | } |
| 4112 | |
| 4113 | |
| 4114 | bool Context::InContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4115 | return i::Isolate::Current()->context() != NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4119 | v8::Local<v8::Context> Context::GetEntered() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4120 | i::Isolate* isolate = i::Isolate::Current(); |
| 4121 | if (IsDeadCheck(isolate, "v8::Context::GetEntered()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4122 | return Local<Context>(); |
| 4123 | } |
| 4124 | i::Handle<i::Object> last = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4125 | isolate->handle_scope_implementer()->LastEnteredContext(); |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4126 | if (last.is_null()) return Local<Context>(); |
| 4127 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(last); |
| 4128 | return Utils::ToLocal(context); |
| 4129 | } |
| 4130 | |
| 4131 | |
| 4132 | v8::Local<v8::Context> Context::GetCurrent() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4133 | i::Isolate* isolate = i::Isolate::Current(); |
| 4134 | if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4135 | return Local<Context>(); |
| 4136 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4137 | i::Handle<i::Object> current = isolate->global_context(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4138 | if (current.is_null()) return Local<Context>(); |
| 4139 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(current); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4140 | return Utils::ToLocal(context); |
| 4141 | } |
| 4142 | |
| 4143 | |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4144 | v8::Local<v8::Context> Context::GetCalling() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4145 | i::Isolate* isolate = i::Isolate::Current(); |
| 4146 | if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4147 | return Local<Context>(); |
| 4148 | } |
| 4149 | i::Handle<i::Object> calling = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4150 | isolate->GetCallingGlobalContext(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4151 | if (calling.is_null()) return Local<Context>(); |
| 4152 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(calling); |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4153 | return Utils::ToLocal(context); |
| 4154 | } |
| 4155 | |
| 4156 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4157 | v8::Local<v8::Object> Context::Global() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4158 | if (IsDeadCheck(i::Isolate::Current(), "v8::Context::Global()")) { |
| 4159 | return Local<v8::Object>(); |
| 4160 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4161 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4162 | i::Handle<i::Context> context = |
| 4163 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4164 | i::Handle<i::Object> global(context->global_proxy()); |
| 4165 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(global)); |
| 4166 | } |
| 4167 | |
| 4168 | |
| 4169 | void Context::DetachGlobal() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4170 | i::Isolate* isolate = i::Isolate::Current(); |
| 4171 | if (IsDeadCheck(isolate, "v8::Context::DetachGlobal()")) return; |
| 4172 | ENTER_V8(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4173 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4174 | i::Handle<i::Context> context = |
| 4175 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4176 | isolate->bootstrapper()->DetachGlobal(context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4180 | void Context::ReattachGlobal(Handle<Object> global_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4181 | i::Isolate* isolate = i::Isolate::Current(); |
| 4182 | if (IsDeadCheck(isolate, "v8::Context::ReattachGlobal()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4183 | ENTER_V8(isolate); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4184 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4185 | i::Handle<i::Context> context = |
| 4186 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4187 | isolate->bootstrapper()->ReattachGlobal( |
| 4188 | context, |
| 4189 | Utils::OpenHandle(*global_object)); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4193 | void Context::AllowCodeGenerationFromStrings(bool allow) { |
| 4194 | i::Isolate* isolate = i::Isolate::Current(); |
| 4195 | if (IsDeadCheck(isolate, "v8::Context::AllowCodeGenerationFromStrings()")) { |
| 4196 | return; |
| 4197 | } |
| 4198 | ENTER_V8(isolate); |
| 4199 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4200 | i::Handle<i::Context> context = |
| 4201 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
| 4202 | context->set_allow_code_gen_from_strings( |
| 4203 | allow ? isolate->heap()->true_value() : isolate->heap()->false_value()); |
| 4204 | } |
| 4205 | |
| 4206 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4207 | void V8::SetWrapperClassId(i::Object** global_handle, uint16_t class_id) { |
| 4208 | i::GlobalHandles::SetWrapperClassId(global_handle, class_id); |
| 4209 | } |
| 4210 | |
| 4211 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4212 | Local<v8::Object> ObjectTemplate::NewInstance() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4213 | i::Isolate* isolate = i::Isolate::Current(); |
| 4214 | ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", |
| 4215 | return Local<v8::Object>()); |
| 4216 | LOG_API(isolate, "ObjectTemplate::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4217 | ENTER_V8(isolate); |
| 4218 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4219 | i::Handle<i::Object> obj = |
| 4220 | i::Execution::InstantiateObject(Utils::OpenHandle(this), |
| 4221 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4222 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4223 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj)); |
| 4224 | } |
| 4225 | |
| 4226 | |
| 4227 | Local<v8::Function> FunctionTemplate::GetFunction() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4228 | i::Isolate* isolate = i::Isolate::Current(); |
| 4229 | ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4230 | return Local<v8::Function>()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4231 | LOG_API(isolate, "FunctionTemplate::GetFunction"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4232 | ENTER_V8(isolate); |
| 4233 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4234 | i::Handle<i::Object> obj = |
| 4235 | i::Execution::InstantiateFunction(Utils::OpenHandle(this), |
| 4236 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4237 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Function>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4238 | return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj)); |
| 4239 | } |
| 4240 | |
| 4241 | |
| 4242 | bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4243 | ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()", |
| 4244 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4245 | i::Object* obj = *Utils::OpenHandle(*value); |
| 4246 | return obj->IsInstanceOf(*Utils::OpenHandle(this)); |
| 4247 | } |
| 4248 | |
| 4249 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4250 | static Local<External> ExternalNewImpl(void* data) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4251 | return Utils::ToLocal(FACTORY->NewForeign(static_cast<i::Address>(data))); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | static void* ExternalValueImpl(i::Handle<i::Object> obj) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4255 | return reinterpret_cast<void*>(i::Foreign::cast(*obj)->address()); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4256 | } |
| 4257 | |
| 4258 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4259 | Local<Value> v8::External::Wrap(void* data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4260 | i::Isolate* isolate = i::Isolate::Current(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4261 | STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4262 | EnsureInitializedForIsolate(isolate, "v8::External::Wrap()"); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 4263 | LOG_API(isolate, "External::Wrap"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4264 | ENTER_V8(isolate); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4265 | |
| 4266 | v8::Local<v8::Value> result = CanBeEncodedAsSmi(data) |
| 4267 | ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data))) |
| 4268 | : v8::Local<v8::Value>(ExternalNewImpl(data)); |
| 4269 | |
| 4270 | ASSERT_EQ(data, Unwrap(result)); |
| 4271 | return result; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4275 | void* v8::Object::SlowGetPointerFromInternalField(int index) { |
| 4276 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4277 | i::Object* value = obj->GetInternalField(index); |
| 4278 | if (value->IsSmi()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4279 | return i::Internals::GetExternalPointerFromSmi(value); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4280 | } else if (value->IsForeign()) { |
| 4281 | return reinterpret_cast<void*>(i::Foreign::cast(value)->address()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4282 | } else { |
| 4283 | return NULL; |
| 4284 | } |
| 4285 | } |
| 4286 | |
| 4287 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4288 | void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4289 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Unwrap()")) return 0; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4290 | i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); |
| 4291 | void* result; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4292 | if (obj->IsSmi()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4293 | result = i::Internals::GetExternalPointerFromSmi(*obj); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4294 | } else if (obj->IsForeign()) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4295 | result = ExternalValueImpl(obj); |
| 4296 | } else { |
| 4297 | result = NULL; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4298 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4299 | ASSERT_EQ(result, QuickUnwrap(wrapper)); |
| 4300 | return result; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4304 | Local<External> v8::External::New(void* data) { |
| 4305 | STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4306 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4307 | EnsureInitializedForIsolate(isolate, "v8::External::New()"); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 4308 | LOG_API(isolate, "External::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4309 | ENTER_V8(isolate); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4310 | return ExternalNewImpl(data); |
| 4311 | } |
| 4312 | |
| 4313 | |
| 4314 | void* External::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4315 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Value()")) return 0; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4316 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4317 | return ExternalValueImpl(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4321 | Local<String> v8::String::Empty() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4322 | i::Isolate* isolate = i::Isolate::Current(); |
| 4323 | EnsureInitializedForIsolate(isolate, "v8::String::Empty()"); |
| 4324 | LOG_API(isolate, "String::Empty()"); |
| 4325 | return Utils::ToLocal(isolate->factory()->empty_symbol()); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4329 | Local<String> v8::String::New(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4330 | i::Isolate* isolate = i::Isolate::Current(); |
| 4331 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4332 | LOG_API(isolate, "String::New(char)"); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4333 | if (length == 0) return Empty(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4334 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4335 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4336 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4337 | isolate->factory()->NewStringFromUtf8( |
| 4338 | i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4339 | return Utils::ToLocal(result); |
| 4340 | } |
| 4341 | |
| 4342 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4343 | Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4344 | i::Handle<i::String> left_string = Utils::OpenHandle(*left); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4345 | i::Isolate* isolate = left_string->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4346 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4347 | LOG_API(isolate, "String::New(char)"); |
| 4348 | ENTER_V8(isolate); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4349 | i::Handle<i::String> right_string = Utils::OpenHandle(*right); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4350 | i::Handle<i::String> result = isolate->factory()->NewConsString(left_string, |
| 4351 | right_string); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4352 | return Utils::ToLocal(result); |
| 4353 | } |
| 4354 | |
| 4355 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4356 | Local<String> v8::String::NewUndetectable(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4357 | i::Isolate* isolate = i::Isolate::Current(); |
| 4358 | EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()"); |
| 4359 | LOG_API(isolate, "String::NewUndetectable(char)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4360 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4361 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4362 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4363 | isolate->factory()->NewStringFromUtf8( |
| 4364 | i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4365 | result->MarkAsUndetectable(); |
| 4366 | return Utils::ToLocal(result); |
| 4367 | } |
| 4368 | |
| 4369 | |
| 4370 | static int TwoByteStringLength(const uint16_t* data) { |
| 4371 | int length = 0; |
| 4372 | while (data[length] != '\0') length++; |
| 4373 | return length; |
| 4374 | } |
| 4375 | |
| 4376 | |
| 4377 | Local<String> v8::String::New(const uint16_t* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4378 | i::Isolate* isolate = i::Isolate::Current(); |
| 4379 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4380 | LOG_API(isolate, "String::New(uint16_)"); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4381 | if (length == 0) return Empty(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4382 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4383 | if (length == -1) length = TwoByteStringLength(data); |
| 4384 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4385 | isolate->factory()->NewStringFromTwoByte( |
| 4386 | i::Vector<const uint16_t>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4387 | return Utils::ToLocal(result); |
| 4388 | } |
| 4389 | |
| 4390 | |
| 4391 | Local<String> v8::String::NewUndetectable(const uint16_t* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4392 | i::Isolate* isolate = i::Isolate::Current(); |
| 4393 | EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()"); |
| 4394 | LOG_API(isolate, "String::NewUndetectable(uint16_)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4395 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4396 | if (length == -1) length = TwoByteStringLength(data); |
| 4397 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4398 | isolate->factory()->NewStringFromTwoByte( |
| 4399 | i::Vector<const uint16_t>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4400 | result->MarkAsUndetectable(); |
| 4401 | return Utils::ToLocal(result); |
| 4402 | } |
| 4403 | |
| 4404 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4405 | i::Handle<i::String> NewExternalStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4406 | v8::String::ExternalStringResource* resource) { |
| 4407 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4408 | isolate->factory()->NewExternalStringFromTwoByte(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4409 | return result; |
| 4410 | } |
| 4411 | |
| 4412 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4413 | i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4414 | v8::String::ExternalAsciiStringResource* resource) { |
| 4415 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4416 | isolate->factory()->NewExternalStringFromAscii(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4417 | return result; |
| 4418 | } |
| 4419 | |
| 4420 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4421 | Local<String> v8::String::NewExternal( |
| 4422 | v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4423 | i::Isolate* isolate = i::Isolate::Current(); |
| 4424 | EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 4425 | LOG_API(isolate, "String::NewExternal"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4426 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4427 | i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); |
| 4428 | isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4429 | return Utils::ToLocal(result); |
| 4430 | } |
| 4431 | |
| 4432 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4433 | bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4434 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 4435 | i::Isolate* isolate = obj->GetIsolate(); |
| 4436 | if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4437 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 4438 | return false; // Already an external string. |
| 4439 | } |
| 4440 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4441 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 4442 | return false; |
| 4443 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4444 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 4445 | return false; |
| 4446 | } |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4447 | bool result = obj->MakeExternal(resource); |
| 4448 | if (result && !obj->IsSymbol()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4449 | isolate->heap()->external_string_table()->AddString(*obj); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4450 | } |
| 4451 | return result; |
| 4452 | } |
| 4453 | |
| 4454 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4455 | Local<String> v8::String::NewExternal( |
| 4456 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4457 | i::Isolate* isolate = i::Isolate::Current(); |
| 4458 | EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 4459 | LOG_API(isolate, "String::NewExternal"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4460 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4461 | i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); |
| 4462 | isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4463 | return Utils::ToLocal(result); |
| 4464 | } |
| 4465 | |
| 4466 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4467 | bool v8::String::MakeExternal( |
| 4468 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4469 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 4470 | i::Isolate* isolate = obj->GetIsolate(); |
| 4471 | if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4472 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 4473 | return false; // Already an external string. |
| 4474 | } |
| 4475 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4476 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 4477 | return false; |
| 4478 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4479 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 4480 | return false; |
| 4481 | } |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4482 | bool result = obj->MakeExternal(resource); |
| 4483 | if (result && !obj->IsSymbol()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4484 | isolate->heap()->external_string_table()->AddString(*obj); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4485 | } |
| 4486 | return result; |
| 4487 | } |
| 4488 | |
| 4489 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4490 | bool v8::String::CanMakeExternal() { |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4491 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4492 | i::Isolate* isolate = obj->GetIsolate(); |
| 4493 | if (IsDeadCheck(isolate, "v8::String::CanMakeExternal()")) return false; |
| 4494 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 4495 | return false; |
| 4496 | } |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4497 | int size = obj->Size(); // Byte size of the original string. |
| 4498 | if (size < i::ExternalString::kSize) |
| 4499 | return false; |
| 4500 | i::StringShape shape(*obj); |
| 4501 | return !shape.IsExternal(); |
| 4502 | } |
| 4503 | |
| 4504 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4505 | Local<v8::Object> v8::Object::New() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4506 | i::Isolate* isolate = i::Isolate::Current(); |
| 4507 | EnsureInitializedForIsolate(isolate, "v8::Object::New()"); |
| 4508 | LOG_API(isolate, "Object::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4509 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4510 | i::Handle<i::JSObject> obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4511 | isolate->factory()->NewJSObject(isolate->object_function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4512 | return Utils::ToLocal(obj); |
| 4513 | } |
| 4514 | |
| 4515 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4516 | Local<v8::Value> v8::NumberObject::New(double value) { |
| 4517 | i::Isolate* isolate = i::Isolate::Current(); |
| 4518 | EnsureInitializedForIsolate(isolate, "v8::NumberObject::New()"); |
| 4519 | LOG_API(isolate, "NumberObject::New"); |
| 4520 | ENTER_V8(isolate); |
| 4521 | i::Handle<i::Object> number = isolate->factory()->NewNumber(value); |
| 4522 | i::Handle<i::Object> obj = isolate->factory()->ToObject(number); |
| 4523 | return Utils::ToLocal(obj); |
| 4524 | } |
| 4525 | |
| 4526 | |
| 4527 | double v8::NumberObject::NumberValue() const { |
| 4528 | i::Isolate* isolate = i::Isolate::Current(); |
| 4529 | if (IsDeadCheck(isolate, "v8::NumberObject::NumberValue()")) return 0; |
| 4530 | LOG_API(isolate, "NumberObject::NumberValue"); |
| 4531 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4532 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4533 | return jsvalue->value()->Number(); |
| 4534 | } |
| 4535 | |
| 4536 | |
| 4537 | Local<v8::Value> v8::BooleanObject::New(bool value) { |
| 4538 | i::Isolate* isolate = i::Isolate::Current(); |
| 4539 | EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()"); |
| 4540 | LOG_API(isolate, "BooleanObject::New"); |
| 4541 | ENTER_V8(isolate); |
| 4542 | i::Handle<i::Object> boolean(value ? isolate->heap()->true_value() |
| 4543 | : isolate->heap()->false_value()); |
| 4544 | i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean); |
| 4545 | return Utils::ToLocal(obj); |
| 4546 | } |
| 4547 | |
| 4548 | |
| 4549 | bool v8::BooleanObject::BooleanValue() const { |
| 4550 | i::Isolate* isolate = i::Isolate::Current(); |
| 4551 | if (IsDeadCheck(isolate, "v8::BooleanObject::BooleanValue()")) return 0; |
| 4552 | LOG_API(isolate, "BooleanObject::BooleanValue"); |
| 4553 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4554 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4555 | return jsvalue->value()->IsTrue(); |
| 4556 | } |
| 4557 | |
| 4558 | |
| 4559 | Local<v8::Value> v8::StringObject::New(Handle<String> value) { |
| 4560 | i::Isolate* isolate = i::Isolate::Current(); |
| 4561 | EnsureInitializedForIsolate(isolate, "v8::StringObject::New()"); |
| 4562 | LOG_API(isolate, "StringObject::New"); |
| 4563 | ENTER_V8(isolate); |
| 4564 | i::Handle<i::Object> obj = |
| 4565 | isolate->factory()->ToObject(Utils::OpenHandle(*value)); |
| 4566 | return Utils::ToLocal(obj); |
| 4567 | } |
| 4568 | |
| 4569 | |
| 4570 | Local<v8::String> v8::StringObject::StringValue() const { |
| 4571 | i::Isolate* isolate = i::Isolate::Current(); |
| 4572 | if (IsDeadCheck(isolate, "v8::StringObject::StringValue()")) { |
| 4573 | return Local<v8::String>(); |
| 4574 | } |
| 4575 | LOG_API(isolate, "StringObject::StringValue"); |
| 4576 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4577 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4578 | return Utils::ToLocal( |
| 4579 | i::Handle<i::String>(i::String::cast(jsvalue->value()))); |
| 4580 | } |
| 4581 | |
| 4582 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4583 | Local<v8::Value> v8::Date::New(double time) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4584 | i::Isolate* isolate = i::Isolate::Current(); |
| 4585 | EnsureInitializedForIsolate(isolate, "v8::Date::New()"); |
| 4586 | LOG_API(isolate, "Date::New"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4587 | if (isnan(time)) { |
| 4588 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 4589 | time = i::OS::nan_value(); |
| 4590 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4591 | ENTER_V8(isolate); |
| 4592 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4593 | i::Handle<i::Object> obj = |
| 4594 | i::Execution::NewDate(time, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4595 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4596 | return Utils::ToLocal(obj); |
| 4597 | } |
| 4598 | |
| 4599 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4600 | double v8::Date::NumberValue() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4601 | i::Isolate* isolate = i::Isolate::Current(); |
| 4602 | if (IsDeadCheck(isolate, "v8::Date::NumberValue()")) return 0; |
| 4603 | LOG_API(isolate, "Date::NumberValue"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4604 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4605 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4606 | return jsvalue->value()->Number(); |
| 4607 | } |
| 4608 | |
| 4609 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4610 | void v8::Date::DateTimeConfigurationChangeNotification() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4611 | i::Isolate* isolate = i::Isolate::Current(); |
| 4612 | ON_BAILOUT(isolate, "v8::Date::DateTimeConfigurationChangeNotification()", |
| 4613 | return); |
| 4614 | LOG_API(isolate, "Date::DateTimeConfigurationChangeNotification"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4615 | ENTER_V8(isolate); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4616 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4617 | i::HandleScope scope(isolate); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4618 | // Get the function ResetDateCache (defined in date-delay.js). |
| 4619 | i::Handle<i::String> func_name_str = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4620 | isolate->factory()->LookupAsciiSymbol("ResetDateCache"); |
| 4621 | i::MaybeObject* result = |
| 4622 | isolate->js_builtins_object()->GetProperty(*func_name_str); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4623 | i::Object* object_func; |
| 4624 | if (!result->ToObject(&object_func)) { |
| 4625 | return; |
| 4626 | } |
| 4627 | |
| 4628 | if (object_func->IsJSFunction()) { |
| 4629 | i::Handle<i::JSFunction> func = |
| 4630 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_func)); |
| 4631 | |
| 4632 | // Call ResetDateCache(0 but expect no exceptions: |
| 4633 | bool caught_exception = false; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4634 | i::Execution::TryCall(func, |
| 4635 | isolate->js_builtins_object(), |
| 4636 | 0, |
| 4637 | NULL, |
| 4638 | &caught_exception); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4639 | } |
| 4640 | } |
| 4641 | |
| 4642 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4643 | static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { |
| 4644 | char flags_buf[3]; |
| 4645 | int num_flags = 0; |
| 4646 | if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; |
| 4647 | if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; |
| 4648 | if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; |
| 4649 | ASSERT(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4650 | return FACTORY->LookupSymbol( |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4651 | i::Vector<const char>(flags_buf, num_flags)); |
| 4652 | } |
| 4653 | |
| 4654 | |
| 4655 | Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, |
| 4656 | Flags flags) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4657 | i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4658 | EnsureInitializedForIsolate(isolate, "v8::RegExp::New()"); |
| 4659 | LOG_API(isolate, "RegExp::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4660 | ENTER_V8(isolate); |
| 4661 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4662 | i::Handle<i::JSRegExp> obj = i::Execution::NewJSRegExp( |
| 4663 | Utils::OpenHandle(*pattern), |
| 4664 | RegExpFlagsToString(flags), |
| 4665 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4666 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::RegExp>()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4667 | return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj)); |
| 4668 | } |
| 4669 | |
| 4670 | |
| 4671 | Local<v8::String> v8::RegExp::GetSource() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4672 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4673 | if (IsDeadCheck(isolate, "v8::RegExp::GetSource()")) { |
| 4674 | return Local<v8::String>(); |
| 4675 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4676 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 4677 | return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); |
| 4678 | } |
| 4679 | |
| 4680 | |
| 4681 | // Assert that the static flags cast in GetFlags is valid. |
| 4682 | #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ |
| 4683 | STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ |
| 4684 | static_cast<int>(i::JSRegExp::internal_flag)) |
| 4685 | REGEXP_FLAG_ASSERT_EQ(kNone, NONE); |
| 4686 | REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL); |
| 4687 | REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE); |
| 4688 | REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE); |
| 4689 | #undef REGEXP_FLAG_ASSERT_EQ |
| 4690 | |
| 4691 | v8::RegExp::Flags v8::RegExp::GetFlags() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4692 | if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::GetFlags()")) { |
| 4693 | return v8::RegExp::kNone; |
| 4694 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4695 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 4696 | return static_cast<RegExp::Flags>(obj->GetFlags().value()); |
| 4697 | } |
| 4698 | |
| 4699 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4700 | Local<v8::Array> v8::Array::New(int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4701 | i::Isolate* isolate = i::Isolate::Current(); |
| 4702 | EnsureInitializedForIsolate(isolate, "v8::Array::New()"); |
| 4703 | LOG_API(isolate, "Array::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4704 | ENTER_V8(isolate); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4705 | int real_length = length > 0 ? length : 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4706 | i::Handle<i::JSArray> obj = isolate->factory()->NewJSArray(real_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4707 | i::Handle<i::Object> length_obj = |
| 4708 | isolate->factory()->NewNumberFromInt(real_length); |
| 4709 | obj->set_length(*length_obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4710 | return Utils::ToLocal(obj); |
| 4711 | } |
| 4712 | |
| 4713 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4714 | uint32_t v8::Array::Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4715 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4716 | if (IsDeadCheck(isolate, "v8::Array::Length()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4717 | i::Handle<i::JSArray> obj = Utils::OpenHandle(this); |
| 4718 | i::Object* length = obj->length(); |
| 4719 | if (length->IsSmi()) { |
| 4720 | return i::Smi::cast(length)->value(); |
| 4721 | } else { |
| 4722 | return static_cast<uint32_t>(length->Number()); |
| 4723 | } |
| 4724 | } |
| 4725 | |
| 4726 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4727 | Local<Object> Array::CloneElementAt(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4728 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4729 | ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4730 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 4731 | if (!self->HasFastElements()) { |
| 4732 | return Local<Object>(); |
| 4733 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4734 | i::FixedArray* elms = i::FixedArray::cast(self->elements()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4735 | i::Object* paragon = elms->get(index); |
| 4736 | if (!paragon->IsJSObject()) { |
| 4737 | return Local<Object>(); |
| 4738 | } |
| 4739 | i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4740 | EXCEPTION_PREAMBLE(isolate); |
| 4741 | ENTER_V8(isolate); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4742 | i::Handle<i::JSObject> result = i::Copy(paragon_handle); |
| 4743 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4744 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4745 | return Utils::ToLocal(result); |
| 4746 | } |
| 4747 | |
| 4748 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4749 | Local<String> v8::String::NewSymbol(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4750 | i::Isolate* isolate = i::Isolate::Current(); |
| 4751 | EnsureInitializedForIsolate(isolate, "v8::String::NewSymbol()"); |
| 4752 | LOG_API(isolate, "String::NewSymbol(char)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4753 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4754 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4755 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4756 | isolate->factory()->LookupSymbol(i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4757 | return Utils::ToLocal(result); |
| 4758 | } |
| 4759 | |
| 4760 | |
| 4761 | Local<Number> v8::Number::New(double value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4762 | i::Isolate* isolate = i::Isolate::Current(); |
| 4763 | EnsureInitializedForIsolate(isolate, "v8::Number::New()"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4764 | if (isnan(value)) { |
| 4765 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 4766 | value = i::OS::nan_value(); |
| 4767 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4768 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4769 | i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4770 | return Utils::NumberToLocal(result); |
| 4771 | } |
| 4772 | |
| 4773 | |
| 4774 | Local<Integer> v8::Integer::New(int32_t value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4775 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 4776 | EnsureInitializedForIsolate(isolate, "v8::Integer::New()"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4777 | if (i::Smi::IsValid(value)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4778 | return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value), |
| 4779 | isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4780 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4781 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4782 | i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4783 | return Utils::IntegerToLocal(result); |
| 4784 | } |
| 4785 | |
| 4786 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4787 | Local<Integer> Integer::NewFromUnsigned(uint32_t value) { |
| 4788 | bool fits_into_int32_t = (value & (1 << 31)) == 0; |
| 4789 | if (fits_into_int32_t) { |
| 4790 | return Integer::New(static_cast<int32_t>(value)); |
| 4791 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4792 | i::Isolate* isolate = i::Isolate::Current(); |
| 4793 | ENTER_V8(isolate); |
| 4794 | i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4795 | return Utils::IntegerToLocal(result); |
| 4796 | } |
| 4797 | |
| 4798 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4799 | void V8::IgnoreOutOfMemoryException() { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 4800 | EnterIsolateIfNeeded()->set_ignore_out_of_memory(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | |
| 4804 | bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4805 | i::Isolate* isolate = i::Isolate::Current(); |
| 4806 | EnsureInitializedForIsolate(isolate, "v8::V8::AddMessageListener()"); |
| 4807 | ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4808 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4809 | i::HandleScope scope(isolate); |
| 4810 | NeanderArray listeners(isolate->factory()->message_listeners()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4811 | NeanderObject obj(2); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4812 | obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4813 | obj.set(1, data.IsEmpty() ? |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4814 | isolate->heap()->undefined_value() : |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4815 | *Utils::OpenHandle(*data)); |
| 4816 | listeners.add(obj.value()); |
| 4817 | return true; |
| 4818 | } |
| 4819 | |
| 4820 | |
| 4821 | void V8::RemoveMessageListeners(MessageCallback that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4822 | i::Isolate* isolate = i::Isolate::Current(); |
| 4823 | EnsureInitializedForIsolate(isolate, "v8::V8::RemoveMessageListener()"); |
| 4824 | ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4825 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4826 | i::HandleScope scope(isolate); |
| 4827 | NeanderArray listeners(isolate->factory()->message_listeners()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4828 | for (int i = 0; i < listeners.length(); i++) { |
| 4829 | if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones |
| 4830 | |
| 4831 | NeanderObject listener(i::JSObject::cast(listeners.get(i))); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4832 | i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0))); |
| 4833 | if (callback_obj->address() == FUNCTION_ADDR(that)) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4834 | listeners.set(i, isolate->heap()->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4835 | } |
| 4836 | } |
| 4837 | } |
| 4838 | |
| 4839 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4840 | void V8::SetCaptureStackTraceForUncaughtExceptions( |
| 4841 | bool capture, |
| 4842 | int frame_limit, |
| 4843 | StackTrace::StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4844 | i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions( |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4845 | capture, |
| 4846 | frame_limit, |
| 4847 | options); |
| 4848 | } |
| 4849 | |
| 4850 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4851 | void V8::SetCounterFunction(CounterLookupCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 4852 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4853 | if (IsDeadCheck(isolate, "v8::V8::SetCounterFunction()")) return; |
| 4854 | isolate->stats_table()->SetCounterFunction(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4857 | void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 4858 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4859 | if (IsDeadCheck(isolate, "v8::V8::SetCreateHistogramFunction()")) return; |
| 4860 | isolate->stats_table()->SetCreateHistogramFunction(callback); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4861 | } |
| 4862 | |
| 4863 | void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 4864 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4865 | if (IsDeadCheck(isolate, "v8::V8::SetAddHistogramSampleFunction()")) return; |
| 4866 | isolate->stats_table()-> |
| 4867 | SetAddHistogramSampleFunction(callback); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4868 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4869 | |
| 4870 | void V8::EnableSlidingStateWindow() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4871 | i::Isolate* isolate = i::Isolate::Current(); |
| 4872 | if (IsDeadCheck(isolate, "v8::V8::EnableSlidingStateWindow()")) return; |
| 4873 | isolate->logger()->EnableSlidingStateWindow(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | |
| 4877 | void V8::SetFailedAccessCheckCallbackFunction( |
| 4878 | FailedAccessCheckCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4879 | i::Isolate* isolate = i::Isolate::Current(); |
| 4880 | if (IsDeadCheck(isolate, "v8::V8::SetFailedAccessCheckCallbackFunction()")) { |
| 4881 | return; |
| 4882 | } |
| 4883 | isolate->SetFailedAccessCheckCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4884 | } |
| 4885 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4886 | void V8::AddObjectGroup(Persistent<Value>* objects, |
| 4887 | size_t length, |
| 4888 | RetainedObjectInfo* info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4889 | i::Isolate* isolate = i::Isolate::Current(); |
| 4890 | if (IsDeadCheck(isolate, "v8::V8::AddObjectGroup()")) return; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4891 | STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4892 | isolate->global_handles()->AddObjectGroup( |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4893 | reinterpret_cast<i::Object***>(objects), length, info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4894 | } |
| 4895 | |
| 4896 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4897 | void V8::AddImplicitReferences(Persistent<Object> parent, |
| 4898 | Persistent<Value>* children, |
| 4899 | size_t length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4900 | i::Isolate* isolate = i::Isolate::Current(); |
| 4901 | if (IsDeadCheck(isolate, "v8::V8::AddImplicitReferences()")) return; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4902 | STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4903 | isolate->global_handles()->AddImplicitReferences( |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4904 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(*parent)).location(), |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4905 | reinterpret_cast<i::Object***>(children), length); |
| 4906 | } |
| 4907 | |
| 4908 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4909 | int V8::AdjustAmountOfExternalAllocatedMemory(int change_in_bytes) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4910 | i::Isolate* isolate = i::Isolate::Current(); |
| 4911 | if (IsDeadCheck(isolate, "v8::V8::AdjustAmountOfExternalAllocatedMemory()")) { |
| 4912 | return 0; |
| 4913 | } |
| 4914 | return isolate->heap()->AdjustAmountOfExternalAllocatedMemory( |
| 4915 | change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
| 4918 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4919 | void V8::SetGlobalGCPrologueCallback(GCCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4920 | i::Isolate* isolate = i::Isolate::Current(); |
| 4921 | if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return; |
| 4922 | isolate->heap()->SetGlobalGCPrologueCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | |
| 4926 | void V8::SetGlobalGCEpilogueCallback(GCCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4927 | i::Isolate* isolate = i::Isolate::Current(); |
| 4928 | if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCEpilogueCallback()")) return; |
| 4929 | isolate->heap()->SetGlobalGCEpilogueCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4933 | void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4934 | i::Isolate* isolate = i::Isolate::Current(); |
| 4935 | if (IsDeadCheck(isolate, "v8::V8::AddGCPrologueCallback()")) return; |
| 4936 | isolate->heap()->AddGCPrologueCallback(callback, gc_type); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | |
| 4940 | void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4941 | i::Isolate* isolate = i::Isolate::Current(); |
| 4942 | if (IsDeadCheck(isolate, "v8::V8::RemoveGCPrologueCallback()")) return; |
| 4943 | isolate->heap()->RemoveGCPrologueCallback(callback); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | |
| 4947 | void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4948 | i::Isolate* isolate = i::Isolate::Current(); |
| 4949 | if (IsDeadCheck(isolate, "v8::V8::AddGCEpilogueCallback()")) return; |
| 4950 | isolate->heap()->AddGCEpilogueCallback(callback, gc_type); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4951 | } |
| 4952 | |
| 4953 | |
| 4954 | void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4955 | i::Isolate* isolate = i::Isolate::Current(); |
| 4956 | if (IsDeadCheck(isolate, "v8::V8::RemoveGCEpilogueCallback()")) return; |
| 4957 | isolate->heap()->RemoveGCEpilogueCallback(callback); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4961 | void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 4962 | ObjectSpace space, |
| 4963 | AllocationAction action) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4964 | i::Isolate* isolate = i::Isolate::Current(); |
| 4965 | if (IsDeadCheck(isolate, "v8::V8::AddMemoryAllocationCallback()")) return; |
| 4966 | isolate->memory_allocator()->AddMemoryAllocationCallback( |
| 4967 | callback, space, action); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4968 | } |
| 4969 | |
| 4970 | |
| 4971 | void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4972 | i::Isolate* isolate = i::Isolate::Current(); |
| 4973 | if (IsDeadCheck(isolate, "v8::V8::RemoveMemoryAllocationCallback()")) return; |
| 4974 | isolate->memory_allocator()->RemoveMemoryAllocationCallback( |
| 4975 | callback); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4979 | void V8::PauseProfiler() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4980 | i::Isolate* isolate = i::Isolate::Current(); |
| 4981 | isolate->logger()->PauseProfiler(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4982 | } |
| 4983 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4984 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4985 | void V8::ResumeProfiler() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4986 | i::Isolate* isolate = i::Isolate::Current(); |
| 4987 | isolate->logger()->ResumeProfiler(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4988 | } |
| 4989 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4990 | |
| 4991 | bool V8::IsProfilerPaused() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4992 | i::Isolate* isolate = i::Isolate::Current(); |
| 4993 | return isolate->logger()->IsProfilerPaused(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4994 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 4995 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4996 | |
| 4997 | int V8::GetCurrentThreadId() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4998 | i::Isolate* isolate = i::Isolate::Current(); |
| 4999 | EnsureInitializedForIsolate(isolate, "V8::GetCurrentThreadId()"); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5000 | return isolate->thread_id().ToInteger(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5001 | } |
| 5002 | |
| 5003 | |
| 5004 | void V8::TerminateExecution(int thread_id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5005 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5006 | if (!isolate->IsInitialized()) return; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 5007 | API_ENTRY_CHECK(isolate, "V8::TerminateExecution()"); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5008 | // If the thread_id identifies the current thread just terminate |
| 5009 | // execution right away. Otherwise, ask the thread manager to |
| 5010 | // terminate the thread with the given id if any. |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5011 | i::ThreadId internal_tid = i::ThreadId::FromInteger(thread_id); |
| 5012 | if (isolate->thread_id().Equals(internal_tid)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5013 | isolate->stack_guard()->TerminateExecution(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5014 | } else { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5015 | isolate->thread_manager()->TerminateExecution(internal_tid); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5016 | } |
| 5017 | } |
| 5018 | |
| 5019 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5020 | void V8::TerminateExecution(Isolate* isolate) { |
| 5021 | // If no isolate is supplied, use the default isolate. |
| 5022 | if (isolate != NULL) { |
| 5023 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution(); |
| 5024 | } else { |
| 5025 | i::Isolate::GetDefaultIsolateStackGuard()->TerminateExecution(); |
| 5026 | } |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5027 | } |
| 5028 | |
| 5029 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5030 | bool V8::IsExecutionTerminating(Isolate* isolate) { |
| 5031 | i::Isolate* i_isolate = isolate != NULL ? |
| 5032 | reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current(); |
| 5033 | return IsExecutionTerminatingCheck(i_isolate); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 5034 | } |
| 5035 | |
| 5036 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5037 | Isolate* Isolate::GetCurrent() { |
| 5038 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 5039 | return reinterpret_cast<Isolate*>(isolate); |
| 5040 | } |
| 5041 | |
| 5042 | |
| 5043 | Isolate* Isolate::New() { |
| 5044 | i::Isolate* isolate = new i::Isolate(); |
| 5045 | return reinterpret_cast<Isolate*>(isolate); |
| 5046 | } |
| 5047 | |
| 5048 | |
| 5049 | void Isolate::Dispose() { |
| 5050 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5051 | if (!ApiCheck(!isolate->IsInUse(), |
| 5052 | "v8::Isolate::Dispose()", |
| 5053 | "Disposing the isolate that is entered by a thread.")) { |
| 5054 | return; |
| 5055 | } |
| 5056 | isolate->TearDown(); |
| 5057 | } |
| 5058 | |
| 5059 | |
| 5060 | void Isolate::Enter() { |
| 5061 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5062 | isolate->Enter(); |
| 5063 | } |
| 5064 | |
| 5065 | |
| 5066 | void Isolate::Exit() { |
| 5067 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5068 | isolate->Exit(); |
| 5069 | } |
| 5070 | |
| 5071 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5072 | void Isolate::SetData(void* data) { |
| 5073 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5074 | isolate->SetData(data); |
| 5075 | } |
| 5076 | |
| 5077 | void* Isolate::GetData() { |
| 5078 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5079 | return isolate->GetData(); |
| 5080 | } |
| 5081 | |
| 5082 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5083 | String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) |
| 5084 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5085 | i::Isolate* isolate = i::Isolate::Current(); |
| 5086 | if (IsDeadCheck(isolate, "v8::String::Utf8Value::Utf8Value()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5087 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5088 | ENTER_V8(isolate); |
| 5089 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5090 | TryCatch try_catch; |
| 5091 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5092 | if (str.IsEmpty()) return; |
| 5093 | length_ = str->Utf8Length(); |
| 5094 | str_ = i::NewArray<char>(length_ + 1); |
| 5095 | str->WriteUtf8(str_); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5096 | } |
| 5097 | |
| 5098 | |
| 5099 | String::Utf8Value::~Utf8Value() { |
| 5100 | i::DeleteArray(str_); |
| 5101 | } |
| 5102 | |
| 5103 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5104 | String::AsciiValue::AsciiValue(v8::Handle<v8::Value> obj) |
| 5105 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5106 | i::Isolate* isolate = i::Isolate::Current(); |
| 5107 | if (IsDeadCheck(isolate, "v8::String::AsciiValue::AsciiValue()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5108 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5109 | ENTER_V8(isolate); |
| 5110 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5111 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5112 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5113 | if (str.IsEmpty()) return; |
| 5114 | length_ = str->Length(); |
| 5115 | str_ = i::NewArray<char>(length_ + 1); |
| 5116 | str->WriteAscii(str_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5117 | } |
| 5118 | |
| 5119 | |
| 5120 | String::AsciiValue::~AsciiValue() { |
| 5121 | i::DeleteArray(str_); |
| 5122 | } |
| 5123 | |
| 5124 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5125 | String::Value::Value(v8::Handle<v8::Value> obj) |
| 5126 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5127 | i::Isolate* isolate = i::Isolate::Current(); |
| 5128 | if (IsDeadCheck(isolate, "v8::String::Value::Value()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5129 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5130 | ENTER_V8(isolate); |
| 5131 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5132 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5133 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5134 | if (str.IsEmpty()) return; |
| 5135 | length_ = str->Length(); |
| 5136 | str_ = i::NewArray<uint16_t>(length_ + 1); |
| 5137 | str->Write(str_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | |
| 5141 | String::Value::~Value() { |
| 5142 | i::DeleteArray(str_); |
| 5143 | } |
| 5144 | |
| 5145 | Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5146 | i::Isolate* isolate = i::Isolate::Current(); |
| 5147 | LOG_API(isolate, "RangeError"); |
| 5148 | ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5149 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5150 | i::Object* error; |
| 5151 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5152 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5153 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5154 | i::Handle<i::Object> result = isolate->factory()->NewRangeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5155 | error = *result; |
| 5156 | } |
| 5157 | i::Handle<i::Object> result(error); |
| 5158 | return Utils::ToLocal(result); |
| 5159 | } |
| 5160 | |
| 5161 | Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5162 | i::Isolate* isolate = i::Isolate::Current(); |
| 5163 | LOG_API(isolate, "ReferenceError"); |
| 5164 | ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5165 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5166 | i::Object* error; |
| 5167 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5168 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5169 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5170 | i::Handle<i::Object> result = |
| 5171 | isolate->factory()->NewReferenceError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5172 | error = *result; |
| 5173 | } |
| 5174 | i::Handle<i::Object> result(error); |
| 5175 | return Utils::ToLocal(result); |
| 5176 | } |
| 5177 | |
| 5178 | Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5179 | i::Isolate* isolate = i::Isolate::Current(); |
| 5180 | LOG_API(isolate, "SyntaxError"); |
| 5181 | ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5182 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5183 | i::Object* error; |
| 5184 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5185 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5186 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5187 | i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5188 | error = *result; |
| 5189 | } |
| 5190 | i::Handle<i::Object> result(error); |
| 5191 | return Utils::ToLocal(result); |
| 5192 | } |
| 5193 | |
| 5194 | Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5195 | i::Isolate* isolate = i::Isolate::Current(); |
| 5196 | LOG_API(isolate, "TypeError"); |
| 5197 | ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5198 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5199 | i::Object* error; |
| 5200 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5201 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5202 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5203 | i::Handle<i::Object> result = isolate->factory()->NewTypeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5204 | error = *result; |
| 5205 | } |
| 5206 | i::Handle<i::Object> result(error); |
| 5207 | return Utils::ToLocal(result); |
| 5208 | } |
| 5209 | |
| 5210 | Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5211 | i::Isolate* isolate = i::Isolate::Current(); |
| 5212 | LOG_API(isolate, "Error"); |
| 5213 | ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5214 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5215 | i::Object* error; |
| 5216 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5217 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5218 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5219 | i::Handle<i::Object> result = isolate->factory()->NewError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5220 | error = *result; |
| 5221 | } |
| 5222 | i::Handle<i::Object> result(error); |
| 5223 | return Utils::ToLocal(result); |
| 5224 | } |
| 5225 | |
| 5226 | |
| 5227 | // --- D e b u g S u p p o r t --- |
| 5228 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5229 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5230 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5231 | static void EventCallbackWrapper(const v8::Debug::EventDetails& event_details) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5232 | i::Isolate* isolate = i::Isolate::Current(); |
| 5233 | if (isolate->debug_event_callback() != NULL) { |
| 5234 | isolate->debug_event_callback()(event_details.GetEvent(), |
| 5235 | event_details.GetExecutionState(), |
| 5236 | event_details.GetEventData(), |
| 5237 | event_details.GetCallbackData()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5238 | } |
| 5239 | } |
| 5240 | |
| 5241 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5242 | bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5243 | i::Isolate* isolate = i::Isolate::Current(); |
| 5244 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener()"); |
| 5245 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5246 | ENTER_V8(isolate); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5247 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5248 | isolate->set_debug_event_callback(that); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5249 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5250 | i::HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5251 | i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5252 | if (that != NULL) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5253 | foreign = |
| 5254 | isolate->factory()->NewForeign(FUNCTION_ADDR(EventCallbackWrapper)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5255 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5256 | isolate->debugger()->SetEventListener(foreign, Utils::OpenHandle(*data)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5257 | return true; |
| 5258 | } |
| 5259 | |
| 5260 | |
| 5261 | bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5262 | i::Isolate* isolate = i::Isolate::Current(); |
| 5263 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()"); |
| 5264 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5265 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5266 | i::HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5267 | i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5268 | if (that != NULL) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5269 | foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5270 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5271 | isolate->debugger()->SetEventListener(foreign, Utils::OpenHandle(*data)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5272 | return true; |
| 5273 | } |
| 5274 | |
| 5275 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5276 | bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5277 | Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5278 | i::Isolate* isolate = i::Isolate::Current(); |
| 5279 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5280 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5281 | isolate->debugger()->SetEventListener(Utils::OpenHandle(*that), |
| 5282 | Utils::OpenHandle(*data)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5283 | return true; |
| 5284 | } |
| 5285 | |
| 5286 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5287 | void Debug::DebugBreak(Isolate* isolate) { |
| 5288 | // If no isolate is supplied, use the default isolate. |
| 5289 | if (isolate != NULL) { |
| 5290 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->DebugBreak(); |
| 5291 | } else { |
| 5292 | i::Isolate::GetDefaultIsolateStackGuard()->DebugBreak(); |
| 5293 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5297 | void Debug::CancelDebugBreak(Isolate* isolate) { |
| 5298 | // If no isolate is supplied, use the default isolate. |
| 5299 | if (isolate != NULL) { |
| 5300 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5301 | internal_isolate->stack_guard()->Continue(i::DEBUGBREAK); |
| 5302 | } else { |
| 5303 | i::Isolate::GetDefaultIsolateStackGuard()->Continue(i::DEBUGBREAK); |
| 5304 | } |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5308 | void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) { |
| 5309 | // If no isolate is supplied, use the default isolate. |
| 5310 | if (isolate != NULL) { |
| 5311 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5312 | internal_isolate->debugger()->EnqueueDebugCommand(data); |
| 5313 | } else { |
| 5314 | i::Isolate::GetDefaultIsolateDebugger()->EnqueueDebugCommand(data); |
| 5315 | } |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5319 | static void MessageHandlerWrapper(const v8::Debug::Message& message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5320 | i::Isolate* isolate = i::Isolate::Current(); |
| 5321 | if (isolate->message_handler()) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5322 | v8::String::Value json(message.GetJSON()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5323 | (isolate->message_handler())(*json, json.length(), message.GetClientData()); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5324 | } |
| 5325 | } |
| 5326 | |
| 5327 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5328 | void Debug::SetMessageHandler(v8::Debug::MessageHandler handler, |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5329 | bool message_handler_thread) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5330 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5331 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); |
| 5332 | ENTER_V8(isolate); |
| 5333 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5334 | // Message handler thread not supported any more. Parameter temporally left in |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5335 | // the API for client compatibility reasons. |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5336 | CHECK(!message_handler_thread); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5337 | |
| 5338 | // TODO(sgjesse) support the old message handler API through a simple wrapper. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5339 | isolate->set_message_handler(handler); |
| 5340 | if (handler != NULL) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5341 | isolate->debugger()->SetMessageHandler(MessageHandlerWrapper); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5342 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5343 | isolate->debugger()->SetMessageHandler(NULL); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5344 | } |
| 5345 | } |
| 5346 | |
| 5347 | |
| 5348 | void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5349 | i::Isolate* isolate = i::Isolate::Current(); |
| 5350 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); |
| 5351 | ENTER_V8(isolate); |
| 5352 | isolate->debugger()->SetMessageHandler(handler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5353 | } |
| 5354 | |
| 5355 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5356 | void Debug::SendCommand(const uint16_t* command, int length, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5357 | ClientData* client_data, |
| 5358 | Isolate* isolate) { |
| 5359 | // If no isolate is supplied, use the default isolate. |
| 5360 | if (isolate != NULL) { |
| 5361 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5362 | internal_isolate->debugger()->ProcessCommand( |
| 5363 | i::Vector<const uint16_t>(command, length), client_data); |
| 5364 | } else { |
| 5365 | i::Isolate::GetDefaultIsolateDebugger()->ProcessCommand( |
| 5366 | i::Vector<const uint16_t>(command, length), client_data); |
| 5367 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5371 | void Debug::SetHostDispatchHandler(HostDispatchHandler handler, |
| 5372 | int period) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5373 | i::Isolate* isolate = i::Isolate::Current(); |
| 5374 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetHostDispatchHandler"); |
| 5375 | ENTER_V8(isolate); |
| 5376 | isolate->debugger()->SetHostDispatchHandler(handler, period); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5377 | } |
| 5378 | |
| 5379 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5380 | void Debug::SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5381 | DebugMessageDispatchHandler handler, bool provide_locker) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5382 | i::Isolate* isolate = i::Isolate::Current(); |
| 5383 | EnsureInitializedForIsolate(isolate, |
| 5384 | "v8::Debug::SetDebugMessageDispatchHandler"); |
| 5385 | ENTER_V8(isolate); |
| 5386 | isolate->debugger()->SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5387 | handler, provide_locker); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5391 | Local<Value> Debug::Call(v8::Handle<v8::Function> fun, |
| 5392 | v8::Handle<v8::Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5393 | i::Isolate* isolate = i::Isolate::Current(); |
| 5394 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 5395 | ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5396 | ENTER_V8(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5397 | i::Handle<i::Object> result; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5398 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5399 | if (data.IsEmpty()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5400 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 5401 | isolate->factory()->undefined_value(), |
| 5402 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5403 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5404 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 5405 | Utils::OpenHandle(*data), |
| 5406 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5407 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5408 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5409 | return Utils::ToLocal(result); |
| 5410 | } |
| 5411 | |
| 5412 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5413 | Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5414 | i::Isolate* isolate = i::Isolate::Current(); |
| 5415 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 5416 | ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5417 | ENTER_V8(isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5418 | v8::HandleScope scope; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5419 | i::Debug* isolate_debug = isolate->debug(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5420 | isolate_debug->Load(); |
| 5421 | i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global()); |
| 5422 | i::Handle<i::String> name = |
| 5423 | isolate->factory()->LookupAsciiSymbol("MakeMirror"); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5424 | i::Handle<i::Object> fun_obj = i::GetProperty(debug, name); |
| 5425 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj); |
| 5426 | v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun); |
| 5427 | const int kArgc = 1; |
| 5428 | v8::Handle<v8::Value> argv[kArgc] = { obj }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5429 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5430 | v8::Handle<v8::Value> result = v8_fun->Call(Utils::ToLocal(debug), |
| 5431 | kArgc, |
| 5432 | argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5433 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5434 | return scope.Close(result); |
| 5435 | } |
| 5436 | |
| 5437 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5438 | bool Debug::EnableAgent(const char* name, int port, bool wait_for_connection) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5439 | return i::Isolate::Current()->debugger()->StartAgent(name, port, |
| 5440 | wait_for_connection); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5441 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5442 | |
| 5443 | void Debug::ProcessDebugMessages() { |
| 5444 | i::Execution::ProcessDebugMesssages(true); |
| 5445 | } |
| 5446 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 5447 | Local<Context> Debug::GetDebugContext() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5448 | i::Isolate* isolate = i::Isolate::Current(); |
| 5449 | EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()"); |
| 5450 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5451 | return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext()); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 5452 | } |
| 5453 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5454 | #endif // ENABLE_DEBUGGER_SUPPORT |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5455 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5456 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5457 | Handle<String> CpuProfileNode::GetFunctionName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5458 | i::Isolate* isolate = i::Isolate::Current(); |
| 5459 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetFunctionName"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5460 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
| 5461 | const i::CodeEntry* entry = node->entry(); |
| 5462 | if (!entry->has_name_prefix()) { |
| 5463 | return Handle<String>(ToApi<String>( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5464 | isolate->factory()->LookupAsciiSymbol(entry->name()))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5465 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5466 | return Handle<String>(ToApi<String>(isolate->factory()->NewConsString( |
| 5467 | isolate->factory()->LookupAsciiSymbol(entry->name_prefix()), |
| 5468 | isolate->factory()->LookupAsciiSymbol(entry->name())))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5469 | } |
| 5470 | } |
| 5471 | |
| 5472 | |
| 5473 | Handle<String> CpuProfileNode::GetScriptResourceName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5474 | i::Isolate* isolate = i::Isolate::Current(); |
| 5475 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetScriptResourceName"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5476 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5477 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5478 | node->entry()->resource_name()))); |
| 5479 | } |
| 5480 | |
| 5481 | |
| 5482 | int CpuProfileNode::GetLineNumber() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5483 | i::Isolate* isolate = i::Isolate::Current(); |
| 5484 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetLineNumber"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5485 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number(); |
| 5486 | } |
| 5487 | |
| 5488 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5489 | double CpuProfileNode::GetTotalTime() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5490 | i::Isolate* isolate = i::Isolate::Current(); |
| 5491 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalTime"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5492 | return reinterpret_cast<const i::ProfileNode*>(this)->GetTotalMillis(); |
| 5493 | } |
| 5494 | |
| 5495 | |
| 5496 | double CpuProfileNode::GetSelfTime() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5497 | i::Isolate* isolate = i::Isolate::Current(); |
| 5498 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfTime"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5499 | return reinterpret_cast<const i::ProfileNode*>(this)->GetSelfMillis(); |
| 5500 | } |
| 5501 | |
| 5502 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5503 | double CpuProfileNode::GetTotalSamplesCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5504 | i::Isolate* isolate = i::Isolate::Current(); |
| 5505 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalSamplesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5506 | return reinterpret_cast<const i::ProfileNode*>(this)->total_ticks(); |
| 5507 | } |
| 5508 | |
| 5509 | |
| 5510 | double CpuProfileNode::GetSelfSamplesCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5511 | i::Isolate* isolate = i::Isolate::Current(); |
| 5512 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfSamplesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5513 | return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks(); |
| 5514 | } |
| 5515 | |
| 5516 | |
| 5517 | unsigned CpuProfileNode::GetCallUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5518 | i::Isolate* isolate = i::Isolate::Current(); |
| 5519 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetCallUid"); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 5520 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | |
| 5524 | int CpuProfileNode::GetChildrenCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5525 | i::Isolate* isolate = i::Isolate::Current(); |
| 5526 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetChildrenCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5527 | return reinterpret_cast<const i::ProfileNode*>(this)->children()->length(); |
| 5528 | } |
| 5529 | |
| 5530 | |
| 5531 | const CpuProfileNode* CpuProfileNode::GetChild(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5532 | i::Isolate* isolate = i::Isolate::Current(); |
| 5533 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetChild"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5534 | const i::ProfileNode* child = |
| 5535 | reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index); |
| 5536 | return reinterpret_cast<const CpuProfileNode*>(child); |
| 5537 | } |
| 5538 | |
| 5539 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5540 | void CpuProfile::Delete() { |
| 5541 | i::Isolate* isolate = i::Isolate::Current(); |
| 5542 | IsDeadCheck(isolate, "v8::CpuProfile::Delete"); |
| 5543 | i::CpuProfiler::DeleteProfile(reinterpret_cast<i::CpuProfile*>(this)); |
| 5544 | if (i::CpuProfiler::GetProfilesCount() == 0 && |
| 5545 | !i::CpuProfiler::HasDetachedProfiles()) { |
| 5546 | // If this was the last profile, clean up all accessory data as well. |
| 5547 | i::CpuProfiler::DeleteAllProfiles(); |
| 5548 | } |
| 5549 | } |
| 5550 | |
| 5551 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5552 | unsigned CpuProfile::GetUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5553 | i::Isolate* isolate = i::Isolate::Current(); |
| 5554 | IsDeadCheck(isolate, "v8::CpuProfile::GetUid"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5555 | return reinterpret_cast<const i::CpuProfile*>(this)->uid(); |
| 5556 | } |
| 5557 | |
| 5558 | |
| 5559 | Handle<String> CpuProfile::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5560 | i::Isolate* isolate = i::Isolate::Current(); |
| 5561 | IsDeadCheck(isolate, "v8::CpuProfile::GetTitle"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5562 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5563 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5564 | profile->title()))); |
| 5565 | } |
| 5566 | |
| 5567 | |
| 5568 | const CpuProfileNode* CpuProfile::GetBottomUpRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5569 | i::Isolate* isolate = i::Isolate::Current(); |
| 5570 | IsDeadCheck(isolate, "v8::CpuProfile::GetBottomUpRoot"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5571 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 5572 | return reinterpret_cast<const CpuProfileNode*>(profile->bottom_up()->root()); |
| 5573 | } |
| 5574 | |
| 5575 | |
| 5576 | const CpuProfileNode* CpuProfile::GetTopDownRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5577 | i::Isolate* isolate = i::Isolate::Current(); |
| 5578 | IsDeadCheck(isolate, "v8::CpuProfile::GetTopDownRoot"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5579 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 5580 | return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root()); |
| 5581 | } |
| 5582 | |
| 5583 | |
| 5584 | int CpuProfiler::GetProfilesCount() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5585 | i::Isolate* isolate = i::Isolate::Current(); |
| 5586 | IsDeadCheck(isolate, "v8::CpuProfiler::GetProfilesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5587 | return i::CpuProfiler::GetProfilesCount(); |
| 5588 | } |
| 5589 | |
| 5590 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5591 | const CpuProfile* CpuProfiler::GetProfile(int index, |
| 5592 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5593 | i::Isolate* isolate = i::Isolate::Current(); |
| 5594 | IsDeadCheck(isolate, "v8::CpuProfiler::GetProfile"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5595 | return reinterpret_cast<const CpuProfile*>( |
| 5596 | i::CpuProfiler::GetProfile( |
| 5597 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 5598 | index)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5599 | } |
| 5600 | |
| 5601 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5602 | const CpuProfile* CpuProfiler::FindProfile(unsigned uid, |
| 5603 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5604 | i::Isolate* isolate = i::Isolate::Current(); |
| 5605 | IsDeadCheck(isolate, "v8::CpuProfiler::FindProfile"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5606 | return reinterpret_cast<const CpuProfile*>( |
| 5607 | i::CpuProfiler::FindProfile( |
| 5608 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 5609 | uid)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5610 | } |
| 5611 | |
| 5612 | |
| 5613 | void CpuProfiler::StartProfiling(Handle<String> title) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5614 | i::Isolate* isolate = i::Isolate::Current(); |
| 5615 | IsDeadCheck(isolate, "v8::CpuProfiler::StartProfiling"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5616 | i::CpuProfiler::StartProfiling(*Utils::OpenHandle(*title)); |
| 5617 | } |
| 5618 | |
| 5619 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5620 | const CpuProfile* CpuProfiler::StopProfiling(Handle<String> title, |
| 5621 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5622 | i::Isolate* isolate = i::Isolate::Current(); |
| 5623 | IsDeadCheck(isolate, "v8::CpuProfiler::StopProfiling"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5624 | return reinterpret_cast<const CpuProfile*>( |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5625 | i::CpuProfiler::StopProfiling( |
| 5626 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 5627 | *Utils::OpenHandle(*title))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5628 | } |
| 5629 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5630 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5631 | void CpuProfiler::DeleteAllProfiles() { |
| 5632 | i::Isolate* isolate = i::Isolate::Current(); |
| 5633 | IsDeadCheck(isolate, "v8::CpuProfiler::DeleteAllProfiles"); |
| 5634 | i::CpuProfiler::DeleteAllProfiles(); |
| 5635 | } |
| 5636 | |
| 5637 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5638 | static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) { |
| 5639 | return const_cast<i::HeapGraphEdge*>( |
| 5640 | reinterpret_cast<const i::HeapGraphEdge*>(edge)); |
| 5641 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5642 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5643 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5644 | HeapGraphEdge::Type HeapGraphEdge::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5645 | i::Isolate* isolate = i::Isolate::Current(); |
| 5646 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetType"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5647 | return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5648 | } |
| 5649 | |
| 5650 | |
| 5651 | Handle<Value> HeapGraphEdge::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5652 | i::Isolate* isolate = i::Isolate::Current(); |
| 5653 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetName"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5654 | i::HeapGraphEdge* edge = ToInternal(this); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5655 | switch (edge->type()) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5656 | case i::HeapGraphEdge::kContextVariable: |
| 5657 | case i::HeapGraphEdge::kInternal: |
| 5658 | case i::HeapGraphEdge::kProperty: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5659 | case i::HeapGraphEdge::kShortcut: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5660 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5661 | edge->name()))); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5662 | case i::HeapGraphEdge::kElement: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5663 | case i::HeapGraphEdge::kHidden: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5664 | return Handle<Number>(ToApi<Number>(isolate->factory()->NewNumberFromInt( |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5665 | edge->index()))); |
| 5666 | default: UNREACHABLE(); |
| 5667 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5668 | return v8::Undefined(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | |
| 5672 | const HeapGraphNode* HeapGraphEdge::GetFromNode() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5673 | i::Isolate* isolate = i::Isolate::Current(); |
| 5674 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetFromNode"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5675 | const i::HeapEntry* from = ToInternal(this)->From(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5676 | return reinterpret_cast<const HeapGraphNode*>(from); |
| 5677 | } |
| 5678 | |
| 5679 | |
| 5680 | const HeapGraphNode* HeapGraphEdge::GetToNode() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5681 | i::Isolate* isolate = i::Isolate::Current(); |
| 5682 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetToNode"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5683 | const i::HeapEntry* to = ToInternal(this)->to(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5684 | return reinterpret_cast<const HeapGraphNode*>(to); |
| 5685 | } |
| 5686 | |
| 5687 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5688 | static i::HeapEntry* ToInternal(const HeapGraphNode* entry) { |
| 5689 | return const_cast<i::HeapEntry*>( |
| 5690 | reinterpret_cast<const i::HeapEntry*>(entry)); |
| 5691 | } |
| 5692 | |
| 5693 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5694 | HeapGraphNode::Type HeapGraphNode::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5695 | i::Isolate* isolate = i::Isolate::Current(); |
| 5696 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetType"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5697 | return static_cast<HeapGraphNode::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | |
| 5701 | Handle<String> HeapGraphNode::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5702 | i::Isolate* isolate = i::Isolate::Current(); |
| 5703 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetName"); |
| 5704 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5705 | ToInternal(this)->name()))); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 5709 | uint64_t HeapGraphNode::GetId() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5710 | i::Isolate* isolate = i::Isolate::Current(); |
| 5711 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetId"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5712 | return ToInternal(this)->id(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 5713 | } |
| 5714 | |
| 5715 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5716 | int HeapGraphNode::GetSelfSize() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5717 | i::Isolate* isolate = i::Isolate::Current(); |
| 5718 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetSelfSize"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5719 | return ToInternal(this)->self_size(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5723 | int HeapGraphNode::GetRetainedSize(bool exact) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5724 | i::Isolate* isolate = i::Isolate::Current(); |
| 5725 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainedSize"); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5726 | return ToInternal(this)->RetainedSize(exact); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5727 | } |
| 5728 | |
| 5729 | |
| 5730 | int HeapGraphNode::GetChildrenCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5731 | i::Isolate* isolate = i::Isolate::Current(); |
| 5732 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetChildrenCount"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5733 | return ToInternal(this)->children().length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5734 | } |
| 5735 | |
| 5736 | |
| 5737 | const HeapGraphEdge* HeapGraphNode::GetChild(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5738 | i::Isolate* isolate = i::Isolate::Current(); |
| 5739 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetChild"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5740 | return reinterpret_cast<const HeapGraphEdge*>( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5741 | &ToInternal(this)->children()[index]); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5742 | } |
| 5743 | |
| 5744 | |
| 5745 | int HeapGraphNode::GetRetainersCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5746 | i::Isolate* isolate = i::Isolate::Current(); |
| 5747 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainersCount"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5748 | return ToInternal(this)->retainers().length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5749 | } |
| 5750 | |
| 5751 | |
| 5752 | const HeapGraphEdge* HeapGraphNode::GetRetainer(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5753 | i::Isolate* isolate = i::Isolate::Current(); |
| 5754 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainer"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5755 | return reinterpret_cast<const HeapGraphEdge*>( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5756 | ToInternal(this)->retainers()[index]); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5757 | } |
| 5758 | |
| 5759 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5760 | const HeapGraphNode* HeapGraphNode::GetDominatorNode() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5761 | i::Isolate* isolate = i::Isolate::Current(); |
| 5762 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetDominatorNode"); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5763 | return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->dominator()); |
| 5764 | } |
| 5765 | |
| 5766 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5767 | static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) { |
| 5768 | return const_cast<i::HeapSnapshot*>( |
| 5769 | reinterpret_cast<const i::HeapSnapshot*>(snapshot)); |
| 5770 | } |
| 5771 | |
| 5772 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5773 | void HeapSnapshot::Delete() { |
| 5774 | i::Isolate* isolate = i::Isolate::Current(); |
| 5775 | IsDeadCheck(isolate, "v8::HeapSnapshot::Delete"); |
| 5776 | if (i::HeapProfiler::GetSnapshotsCount() > 1) { |
| 5777 | ToInternal(this)->Delete(); |
| 5778 | } else { |
| 5779 | // If this is the last snapshot, clean up all accessory data as well. |
| 5780 | i::HeapProfiler::DeleteAllSnapshots(); |
| 5781 | } |
| 5782 | } |
| 5783 | |
| 5784 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5785 | HeapSnapshot::Type HeapSnapshot::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5786 | i::Isolate* isolate = i::Isolate::Current(); |
| 5787 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetType"); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5788 | return static_cast<HeapSnapshot::Type>(ToInternal(this)->type()); |
| 5789 | } |
| 5790 | |
| 5791 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5792 | unsigned HeapSnapshot::GetUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5793 | i::Isolate* isolate = i::Isolate::Current(); |
| 5794 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetUid"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5795 | return ToInternal(this)->uid(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | |
| 5799 | Handle<String> HeapSnapshot::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5800 | i::Isolate* isolate = i::Isolate::Current(); |
| 5801 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetTitle"); |
| 5802 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5803 | ToInternal(this)->title()))); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 5807 | const HeapGraphNode* HeapSnapshot::GetRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5808 | i::Isolate* isolate = i::Isolate::Current(); |
| 5809 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetHead"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5810 | return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5814 | const HeapGraphNode* HeapSnapshot::GetNodeById(uint64_t id) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5815 | i::Isolate* isolate = i::Isolate::Current(); |
| 5816 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodeById"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5817 | return reinterpret_cast<const HeapGraphNode*>( |
| 5818 | ToInternal(this)->GetEntryById(id)); |
| 5819 | } |
| 5820 | |
| 5821 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5822 | int HeapSnapshot::GetNodesCount() const { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5823 | i::Isolate* isolate = i::Isolate::Current(); |
| 5824 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodesCount"); |
| 5825 | return ToInternal(this)->entries()->length(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | |
| 5829 | const HeapGraphNode* HeapSnapshot::GetNode(int index) const { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5830 | i::Isolate* isolate = i::Isolate::Current(); |
| 5831 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNode"); |
| 5832 | return reinterpret_cast<const HeapGraphNode*>( |
| 5833 | ToInternal(this)->entries()->at(index)); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5834 | } |
| 5835 | |
| 5836 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5837 | void HeapSnapshot::Serialize(OutputStream* stream, |
| 5838 | HeapSnapshot::SerializationFormat format) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5839 | i::Isolate* isolate = i::Isolate::Current(); |
| 5840 | IsDeadCheck(isolate, "v8::HeapSnapshot::Serialize"); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5841 | ApiCheck(format == kJSON, |
| 5842 | "v8::HeapSnapshot::Serialize", |
| 5843 | "Unknown serialization format"); |
| 5844 | ApiCheck(stream->GetOutputEncoding() == OutputStream::kAscii, |
| 5845 | "v8::HeapSnapshot::Serialize", |
| 5846 | "Unsupported output encoding"); |
| 5847 | ApiCheck(stream->GetChunkSize() > 0, |
| 5848 | "v8::HeapSnapshot::Serialize", |
| 5849 | "Invalid stream chunk size"); |
| 5850 | i::HeapSnapshotJSONSerializer serializer(ToInternal(this)); |
| 5851 | serializer.Serialize(stream); |
| 5852 | } |
| 5853 | |
| 5854 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5855 | int HeapProfiler::GetSnapshotsCount() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5856 | i::Isolate* isolate = i::Isolate::Current(); |
| 5857 | IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotsCount"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5858 | return i::HeapProfiler::GetSnapshotsCount(); |
| 5859 | } |
| 5860 | |
| 5861 | |
| 5862 | const HeapSnapshot* HeapProfiler::GetSnapshot(int index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5863 | i::Isolate* isolate = i::Isolate::Current(); |
| 5864 | IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshot"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5865 | return reinterpret_cast<const HeapSnapshot*>( |
| 5866 | i::HeapProfiler::GetSnapshot(index)); |
| 5867 | } |
| 5868 | |
| 5869 | |
| 5870 | const HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5871 | i::Isolate* isolate = i::Isolate::Current(); |
| 5872 | IsDeadCheck(isolate, "v8::HeapProfiler::FindSnapshot"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5873 | return reinterpret_cast<const HeapSnapshot*>( |
| 5874 | i::HeapProfiler::FindSnapshot(uid)); |
| 5875 | } |
| 5876 | |
| 5877 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5878 | const HeapSnapshot* HeapProfiler::TakeSnapshot(Handle<String> title, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5879 | HeapSnapshot::Type type, |
| 5880 | ActivityControl* control) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5881 | i::Isolate* isolate = i::Isolate::Current(); |
| 5882 | IsDeadCheck(isolate, "v8::HeapProfiler::TakeSnapshot"); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5883 | i::HeapSnapshot::Type internal_type = i::HeapSnapshot::kFull; |
| 5884 | switch (type) { |
| 5885 | case HeapSnapshot::kFull: |
| 5886 | internal_type = i::HeapSnapshot::kFull; |
| 5887 | break; |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5888 | default: |
| 5889 | UNREACHABLE(); |
| 5890 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5891 | return reinterpret_cast<const HeapSnapshot*>( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5892 | i::HeapProfiler::TakeSnapshot( |
| 5893 | *Utils::OpenHandle(*title), internal_type, control)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5894 | } |
| 5895 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5896 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5897 | void HeapProfiler::DeleteAllSnapshots() { |
| 5898 | i::Isolate* isolate = i::Isolate::Current(); |
| 5899 | IsDeadCheck(isolate, "v8::HeapProfiler::DeleteAllSnapshots"); |
| 5900 | i::HeapProfiler::DeleteAllSnapshots(); |
| 5901 | } |
| 5902 | |
| 5903 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5904 | void HeapProfiler::DefineWrapperClass(uint16_t class_id, |
| 5905 | WrapperInfoCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5906 | i::Isolate::Current()->heap_profiler()->DefineWrapperClass(class_id, |
| 5907 | callback); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5908 | } |
| 5909 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5910 | |
| 5911 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5912 | v8::Testing::StressType internal::Testing::stress_type_ = |
| 5913 | v8::Testing::kStressTypeOpt; |
| 5914 | |
| 5915 | |
| 5916 | void Testing::SetStressRunType(Testing::StressType type) { |
| 5917 | internal::Testing::set_stress_type(type); |
| 5918 | } |
| 5919 | |
| 5920 | int Testing::GetStressRuns() { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5921 | if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5922 | #ifdef DEBUG |
| 5923 | // In debug mode the code runs much slower so stressing will only make two |
| 5924 | // runs. |
| 5925 | return 2; |
| 5926 | #else |
| 5927 | return 5; |
| 5928 | #endif |
| 5929 | } |
| 5930 | |
| 5931 | |
| 5932 | static void SetFlagsFromString(const char* flags) { |
| 5933 | V8::SetFlagsFromString(flags, i::StrLength(flags)); |
| 5934 | } |
| 5935 | |
| 5936 | |
| 5937 | void Testing::PrepareStressRun(int run) { |
| 5938 | static const char* kLazyOptimizations = |
| 5939 | "--prepare-always-opt --nolimit-inlining " |
| 5940 | "--noalways-opt --noopt-eagerly"; |
| 5941 | static const char* kEagerOptimizations = "--opt-eagerly"; |
| 5942 | static const char* kForcedOptimizations = "--always-opt"; |
| 5943 | |
| 5944 | // If deoptimization stressed turn on frequent deoptimization. If no value |
| 5945 | // is spefified through --deopt-every-n-times use a default default value. |
| 5946 | static const char* kDeoptEvery13Times = "--deopt-every-n-times=13"; |
| 5947 | if (internal::Testing::stress_type() == Testing::kStressTypeDeopt && |
| 5948 | internal::FLAG_deopt_every_n_times == 0) { |
| 5949 | SetFlagsFromString(kDeoptEvery13Times); |
| 5950 | } |
| 5951 | |
| 5952 | #ifdef DEBUG |
| 5953 | // As stressing in debug mode only make two runs skip the deopt stressing |
| 5954 | // here. |
| 5955 | if (run == GetStressRuns() - 1) { |
| 5956 | SetFlagsFromString(kForcedOptimizations); |
| 5957 | } else { |
| 5958 | SetFlagsFromString(kEagerOptimizations); |
| 5959 | SetFlagsFromString(kLazyOptimizations); |
| 5960 | } |
| 5961 | #else |
| 5962 | if (run == GetStressRuns() - 1) { |
| 5963 | SetFlagsFromString(kForcedOptimizations); |
| 5964 | } else if (run == GetStressRuns() - 2) { |
| 5965 | SetFlagsFromString(kEagerOptimizations); |
| 5966 | } else { |
| 5967 | SetFlagsFromString(kLazyOptimizations); |
| 5968 | } |
| 5969 | #endif |
| 5970 | } |
| 5971 | |
| 5972 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5973 | void Testing::DeoptimizeAll() { |
| 5974 | internal::Deoptimizer::DeoptimizeAll(); |
| 5975 | } |
| 5976 | |
| 5977 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5978 | namespace internal { |
| 5979 | |
| 5980 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5981 | void HandleScopeImplementer::FreeThreadResources() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5982 | Free(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5986 | char* HandleScopeImplementer::ArchiveThread(char* storage) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5987 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5988 | isolate_->handle_scope_data(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5989 | handle_scope_data_ = *current; |
| 5990 | memcpy(storage, this, sizeof(*this)); |
| 5991 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5992 | ResetAfterArchive(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5993 | current->Initialize(); |
| 5994 | |
| 5995 | return storage + ArchiveSpacePerThread(); |
| 5996 | } |
| 5997 | |
| 5998 | |
| 5999 | int HandleScopeImplementer::ArchiveSpacePerThread() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6000 | return sizeof(HandleScopeImplementer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | |
| 6004 | char* HandleScopeImplementer::RestoreThread(char* storage) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6005 | memcpy(this, storage, sizeof(*this)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6006 | *isolate_->handle_scope_data() = handle_scope_data_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6007 | return storage + ArchiveSpacePerThread(); |
| 6008 | } |
| 6009 | |
| 6010 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6011 | void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6012 | // Iterate over all handles in the blocks except for the last. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6013 | for (int i = blocks()->length() - 2; i >= 0; --i) { |
| 6014 | Object** block = blocks()->at(i); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6015 | v->VisitPointers(block, &block[kHandleBlockSize]); |
| 6016 | } |
| 6017 | |
| 6018 | // Iterate over live handles in the last block (if any). |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6019 | if (!blocks()->is_empty()) { |
| 6020 | v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6021 | } |
| 6022 | |
| 6023 | if (!saved_contexts_.is_empty()) { |
| 6024 | Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
| 6025 | v->VisitPointers(start, start + saved_contexts_.length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6026 | } |
| 6027 | } |
| 6028 | |
| 6029 | |
| 6030 | void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 6031 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6032 | isolate_->handle_scope_data(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6033 | handle_scope_data_ = *current; |
| 6034 | IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6035 | } |
| 6036 | |
| 6037 | |
| 6038 | char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6039 | HandleScopeImplementer* scope_implementer = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6040 | reinterpret_cast<HandleScopeImplementer*>(storage); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6041 | scope_implementer->IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6042 | return storage + ArchiveSpacePerThread(); |
| 6043 | } |
| 6044 | |
| 6045 | } } // namespace v8::internal |