erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 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 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 28 | #include "api.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 29 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 30 | #include <math.h> // For isnan. |
| 31 | #include <string.h> // For memcpy, strlen. |
| 32 | #include "../include/v8-debug.h" |
| 33 | #include "../include/v8-profiler.h" |
| 34 | #include "../include/v8-testing.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | #include "bootstrapper.h" |
| 36 | #include "compiler.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 37 | #include "conversions-inl.h" |
| 38 | #include "counters.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | #include "debug.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 40 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | #include "execution.h" |
| 42 | #include "global-handles.h" |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 43 | #include "heap-profiler.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 44 | #include "messages.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 45 | #include "parser.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | #include "platform.h" |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 47 | #include "profile-generator-inl.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 48 | #include "property-details.h" |
| 49 | #include "property.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 50 | #include "runtime-profiler.h" |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 51 | #include "scanner-character-streams.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | #include "snapshot.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 53 | #include "unicode-inl.h" |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 54 | #include "v8threads.h" |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 55 | #include "version.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 56 | #include "vm-state-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | |
| 58 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 59 | #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 60 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 61 | #define ENTER_V8(isolate) \ |
| 62 | ASSERT((isolate)->IsInitialized()); \ |
| 63 | i::VMState __state__((isolate), i::OTHER) |
| 64 | #define LEAVE_V8(isolate) \ |
| 65 | i::VMState __state__((isolate), i::EXTERNAL) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 66 | |
| 67 | namespace v8 { |
| 68 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 69 | #define ON_BAILOUT(isolate, location, code) \ |
| 70 | if (IsDeadCheck(isolate, location) || \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 71 | IsExecutionTerminatingCheck(isolate)) { \ |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 72 | code; \ |
| 73 | UNREACHABLE(); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 77 | #define EXCEPTION_PREAMBLE(isolate) \ |
| 78 | (isolate)->handle_scope_implementer()->IncrementCallDepth(); \ |
| 79 | ASSERT(!(isolate)->external_caught_exception()); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 80 | bool has_pending_exception = false |
| 81 | |
| 82 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 83 | #define EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, do_callback) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 84 | do { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 85 | i::HandleScopeImplementer* handle_scope_implementer = \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 86 | (isolate)->handle_scope_implementer(); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 87 | handle_scope_implementer->DecrementCallDepth(); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 88 | if (has_pending_exception) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 89 | if (handle_scope_implementer->CallDepthIsZero() && \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 90 | (isolate)->is_out_of_memory()) { \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 91 | if (!(isolate)->ignore_out_of_memory()) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | i::V8::FatalProcessOutOfMemory(NULL); \ |
| 93 | } \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 94 | bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 95 | (isolate)->OptionalRescheduleException(call_depth_is_zero); \ |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 96 | do_callback \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 97 | return value; \ |
| 98 | } \ |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 99 | do_callback \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 100 | } while (false) |
| 101 | |
| 102 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 103 | #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \ |
| 104 | EXCEPTION_BAILOUT_CHECK_GENERIC( \ |
| 105 | isolate, value, i::V8::FireCallCompletedCallback(isolate);) |
| 106 | |
| 107 | |
| 108 | #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ |
| 109 | EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;) |
| 110 | |
| 111 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 112 | #define API_ENTRY_CHECK(isolate, msg) \ |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 113 | do { \ |
| 114 | if (v8::Locker::IsActive()) { \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 115 | ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \ |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 116 | msg, \ |
| 117 | "Entering the V8 API without proper locking in place"); \ |
| 118 | } \ |
| 119 | } while (false) |
| 120 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 121 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | // --- E x c e p t i o n B e h a v i o r --- |
| 123 | |
| 124 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | static void DefaultFatalErrorHandler(const char* location, |
| 126 | const char* message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 127 | i::VMState __state__(i::Isolate::Current(), i::OTHER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 128 | API_Fatal(location, message); |
| 129 | } |
| 130 | |
| 131 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 132 | static FatalErrorCallback GetFatalErrorHandler() { |
| 133 | i::Isolate* isolate = i::Isolate::Current(); |
| 134 | if (isolate->exception_behavior() == NULL) { |
| 135 | isolate->set_exception_behavior(DefaultFatalErrorHandler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 136 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 137 | return isolate->exception_behavior(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 141 | void i::FatalProcessOutOfMemory(const char* location) { |
| 142 | i::V8::FatalProcessOutOfMemory(location, false); |
| 143 | } |
| 144 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 145 | |
| 146 | // When V8 cannot allocated memory FatalProcessOutOfMemory is called. |
| 147 | // The default fatal error handler is called and execution is stopped. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 148 | void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 149 | i::HeapStats heap_stats; |
| 150 | int start_marker; |
| 151 | heap_stats.start_marker = &start_marker; |
| 152 | int new_space_size; |
| 153 | heap_stats.new_space_size = &new_space_size; |
| 154 | int new_space_capacity; |
| 155 | heap_stats.new_space_capacity = &new_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 156 | intptr_t old_pointer_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 157 | heap_stats.old_pointer_space_size = &old_pointer_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 158 | intptr_t old_pointer_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 159 | heap_stats.old_pointer_space_capacity = &old_pointer_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 160 | intptr_t old_data_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 161 | heap_stats.old_data_space_size = &old_data_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 162 | intptr_t old_data_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 163 | heap_stats.old_data_space_capacity = &old_data_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 164 | intptr_t code_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 165 | heap_stats.code_space_size = &code_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 166 | intptr_t code_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 167 | heap_stats.code_space_capacity = &code_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 168 | intptr_t map_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 169 | heap_stats.map_space_size = &map_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 170 | intptr_t map_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 171 | heap_stats.map_space_capacity = &map_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 172 | intptr_t cell_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 173 | heap_stats.cell_space_size = &cell_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 174 | intptr_t cell_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 175 | heap_stats.cell_space_capacity = &cell_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 176 | intptr_t lo_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 177 | heap_stats.lo_space_size = &lo_space_size; |
| 178 | int global_handle_count; |
| 179 | heap_stats.global_handle_count = &global_handle_count; |
| 180 | int weak_global_handle_count; |
| 181 | heap_stats.weak_global_handle_count = &weak_global_handle_count; |
| 182 | int pending_global_handle_count; |
| 183 | heap_stats.pending_global_handle_count = &pending_global_handle_count; |
| 184 | int near_death_global_handle_count; |
| 185 | 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] | 186 | int free_global_handle_count; |
| 187 | heap_stats.free_global_handle_count = &free_global_handle_count; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 188 | intptr_t memory_allocator_size; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 189 | heap_stats.memory_allocator_size = &memory_allocator_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 190 | intptr_t memory_allocator_capacity; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 191 | heap_stats.memory_allocator_capacity = &memory_allocator_capacity; |
| 192 | int objects_per_type[LAST_TYPE + 1] = {0}; |
| 193 | heap_stats.objects_per_type = objects_per_type; |
| 194 | int size_per_type[LAST_TYPE + 1] = {0}; |
| 195 | heap_stats.size_per_type = size_per_type; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 196 | int os_error; |
| 197 | heap_stats.os_error = &os_error; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 198 | int end_marker; |
| 199 | heap_stats.end_marker = &end_marker; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 200 | i::Isolate* isolate = i::Isolate::Current(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 201 | // BUG(1718): |
| 202 | // Don't use the take_snapshot since we don't support HeapIterator here |
| 203 | // without doing a special GC. |
| 204 | isolate->heap()->RecordStats(&heap_stats, false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 205 | i::V8::SetFatalError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | FatalErrorCallback callback = GetFatalErrorHandler(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 207 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 208 | LEAVE_V8(isolate); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 209 | callback(location, "Allocation failed - process out of memory"); |
| 210 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 211 | // If the callback returns, we stop execution. |
| 212 | UNREACHABLE(); |
| 213 | } |
| 214 | |
| 215 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | bool Utils::ReportApiFailure(const char* location, const char* message) { |
| 217 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 218 | callback(location, message); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 219 | i::V8::SetFatalError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 220 | return false; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | bool V8::IsDead() { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 225 | return i::V8::IsDead(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | |
| 229 | static inline bool ApiCheck(bool condition, |
| 230 | const char* location, |
| 231 | const char* message) { |
| 232 | return condition ? true : Utils::ReportApiFailure(location, message); |
| 233 | } |
| 234 | |
| 235 | |
| 236 | static bool ReportV8Dead(const char* location) { |
| 237 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 238 | callback(location, "V8 is no longer usable"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 239 | return true; |
| 240 | } |
| 241 | |
| 242 | |
| 243 | static bool ReportEmptyHandle(const char* location) { |
| 244 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 245 | callback(location, "Reading from empty handle"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 246 | return true; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 251 | * 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] | 252 | * out of memory at some point this check will fail. It should be called on |
| 253 | * entry to all methods that touch anything in the heap, except destructors |
| 254 | * which you sometimes can't avoid calling after the vm has crashed. Functions |
| 255 | * that call EnsureInitialized or ON_BAILOUT don't have to also call |
| 256 | * IsDeadCheck. ON_BAILOUT has the advantage over EnsureInitialized that you |
| 257 | * can arrange to return if the VM is dead. This is needed to ensure that no VM |
| 258 | * heap allocations are attempted on a dead VM. EnsureInitialized has the |
| 259 | * advantage over ON_BAILOUT that it actually initializes the VM if this has not |
| 260 | * yet been done. |
| 261 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 262 | static inline bool IsDeadCheck(i::Isolate* isolate, const char* location) { |
| 263 | return !isolate->IsInitialized() |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 264 | && i::V8::IsDead() ? ReportV8Dead(location) : false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 268 | static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { |
| 269 | if (!isolate->IsInitialized()) return false; |
| 270 | if (isolate->has_scheduled_exception()) { |
| 271 | return isolate->scheduled_exception() == |
| 272 | isolate->heap()->termination_exception(); |
| 273 | } |
| 274 | return false; |
| 275 | } |
| 276 | |
| 277 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | static inline bool EmptyCheck(const char* location, v8::Handle<v8::Data> obj) { |
| 279 | return obj.IsEmpty() ? ReportEmptyHandle(location) : false; |
| 280 | } |
| 281 | |
| 282 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 283 | static inline bool EmptyCheck(const char* location, const v8::Data* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 284 | return (obj == 0) ? ReportEmptyHandle(location) : false; |
| 285 | } |
| 286 | |
| 287 | // --- S t a t i c s --- |
| 288 | |
| 289 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 290 | static bool InitializeHelper() { |
| 291 | if (i::Snapshot::Initialize()) return true; |
| 292 | return i::V8::Initialize(NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 296 | static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, |
| 297 | const char* location) { |
| 298 | if (IsDeadCheck(isolate, location)) return false; |
| 299 | if (isolate != NULL) { |
| 300 | if (isolate->IsInitialized()) return true; |
| 301 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 302 | ASSERT(isolate == i::Isolate::Current()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 303 | return ApiCheck(InitializeHelper(), location, "Error initializing V8"); |
| 304 | } |
| 305 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 306 | // Some initializing API functions are called early and may be |
| 307 | // called on a thread different from static initializer thread. |
| 308 | // If Isolate API is used, Isolate::Enter() will initialize TLS so |
| 309 | // Isolate::Current() works. If it's a legacy case, then the thread |
| 310 | // may not have TLS initialized yet. However, in initializing APIs it |
| 311 | // may be too early to call EnsureInitialized() - some pre-init |
| 312 | // parameters still have to be configured. |
| 313 | static inline i::Isolate* EnterIsolateIfNeeded() { |
| 314 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 315 | if (isolate != NULL) |
| 316 | return isolate; |
| 317 | |
| 318 | i::Isolate::EnterDefaultIsolate(); |
| 319 | isolate = i::Isolate::Current(); |
| 320 | return isolate; |
| 321 | } |
| 322 | |
| 323 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 324 | StartupDataDecompressor::StartupDataDecompressor() |
| 325 | : raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) { |
| 326 | for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { |
| 327 | raw_data[i] = NULL; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | |
| 332 | StartupDataDecompressor::~StartupDataDecompressor() { |
| 333 | for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { |
| 334 | i::DeleteArray(raw_data[i]); |
| 335 | } |
| 336 | i::DeleteArray(raw_data); |
| 337 | } |
| 338 | |
| 339 | |
| 340 | int StartupDataDecompressor::Decompress() { |
| 341 | int compressed_data_count = V8::GetCompressedStartupDataCount(); |
| 342 | StartupData* compressed_data = |
| 343 | i::NewArray<StartupData>(compressed_data_count); |
| 344 | V8::GetCompressedStartupData(compressed_data); |
| 345 | for (int i = 0; i < compressed_data_count; ++i) { |
| 346 | char* decompressed = raw_data[i] = |
| 347 | i::NewArray<char>(compressed_data[i].raw_size); |
| 348 | if (compressed_data[i].compressed_size != 0) { |
| 349 | int result = DecompressData(decompressed, |
| 350 | &compressed_data[i].raw_size, |
| 351 | compressed_data[i].data, |
| 352 | compressed_data[i].compressed_size); |
| 353 | if (result != 0) return result; |
| 354 | } else { |
| 355 | ASSERT_EQ(0, compressed_data[i].raw_size); |
| 356 | } |
| 357 | compressed_data[i].data = decompressed; |
| 358 | } |
| 359 | V8::SetDecompressedStartupData(compressed_data); |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 364 | StartupData::CompressionAlgorithm V8::GetCompressedStartupDataAlgorithm() { |
| 365 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 366 | return StartupData::kBZip2; |
| 367 | #else |
| 368 | return StartupData::kUncompressed; |
| 369 | #endif |
| 370 | } |
| 371 | |
| 372 | |
| 373 | enum CompressedStartupDataItems { |
| 374 | kSnapshot = 0, |
| 375 | kSnapshotContext, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 376 | kLibraries, |
| 377 | kExperimentalLibraries, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 378 | kCompressedStartupDataCount |
| 379 | }; |
| 380 | |
| 381 | int V8::GetCompressedStartupDataCount() { |
| 382 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 383 | return kCompressedStartupDataCount; |
| 384 | #else |
| 385 | return 0; |
| 386 | #endif |
| 387 | } |
| 388 | |
| 389 | |
| 390 | void V8::GetCompressedStartupData(StartupData* compressed_data) { |
| 391 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 392 | compressed_data[kSnapshot].data = |
| 393 | reinterpret_cast<const char*>(i::Snapshot::data()); |
| 394 | compressed_data[kSnapshot].compressed_size = i::Snapshot::size(); |
| 395 | compressed_data[kSnapshot].raw_size = i::Snapshot::raw_size(); |
| 396 | |
| 397 | compressed_data[kSnapshotContext].data = |
| 398 | reinterpret_cast<const char*>(i::Snapshot::context_data()); |
| 399 | compressed_data[kSnapshotContext].compressed_size = |
| 400 | i::Snapshot::context_size(); |
| 401 | compressed_data[kSnapshotContext].raw_size = i::Snapshot::context_raw_size(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 402 | |
| 403 | i::Vector<const i::byte> libraries_source = i::Natives::GetScriptsSource(); |
| 404 | compressed_data[kLibraries].data = |
| 405 | reinterpret_cast<const char*>(libraries_source.start()); |
| 406 | compressed_data[kLibraries].compressed_size = libraries_source.length(); |
| 407 | compressed_data[kLibraries].raw_size = i::Natives::GetRawScriptsSize(); |
| 408 | |
| 409 | i::Vector<const i::byte> exp_libraries_source = |
| 410 | i::ExperimentalNatives::GetScriptsSource(); |
| 411 | compressed_data[kExperimentalLibraries].data = |
| 412 | reinterpret_cast<const char*>(exp_libraries_source.start()); |
| 413 | compressed_data[kExperimentalLibraries].compressed_size = |
| 414 | exp_libraries_source.length(); |
| 415 | compressed_data[kExperimentalLibraries].raw_size = |
| 416 | i::ExperimentalNatives::GetRawScriptsSize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 417 | #endif |
| 418 | } |
| 419 | |
| 420 | |
| 421 | void V8::SetDecompressedStartupData(StartupData* decompressed_data) { |
| 422 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 423 | ASSERT_EQ(i::Snapshot::raw_size(), decompressed_data[kSnapshot].raw_size); |
| 424 | i::Snapshot::set_raw_data( |
| 425 | reinterpret_cast<const i::byte*>(decompressed_data[kSnapshot].data)); |
| 426 | |
| 427 | ASSERT_EQ(i::Snapshot::context_raw_size(), |
| 428 | decompressed_data[kSnapshotContext].raw_size); |
| 429 | i::Snapshot::set_context_raw_data( |
| 430 | reinterpret_cast<const i::byte*>( |
| 431 | decompressed_data[kSnapshotContext].data)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 432 | |
| 433 | ASSERT_EQ(i::Natives::GetRawScriptsSize(), |
| 434 | decompressed_data[kLibraries].raw_size); |
| 435 | i::Vector<const char> libraries_source( |
| 436 | decompressed_data[kLibraries].data, |
| 437 | decompressed_data[kLibraries].raw_size); |
| 438 | i::Natives::SetRawScriptsSource(libraries_source); |
| 439 | |
| 440 | ASSERT_EQ(i::ExperimentalNatives::GetRawScriptsSize(), |
| 441 | decompressed_data[kExperimentalLibraries].raw_size); |
| 442 | i::Vector<const char> exp_libraries_source( |
| 443 | decompressed_data[kExperimentalLibraries].data, |
| 444 | decompressed_data[kExperimentalLibraries].raw_size); |
| 445 | i::ExperimentalNatives::SetRawScriptsSource(exp_libraries_source); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 446 | #endif |
| 447 | } |
| 448 | |
| 449 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 450 | void V8::SetFatalErrorHandler(FatalErrorCallback that) { |
| 451 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 452 | isolate->set_exception_behavior(that); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 456 | void V8::SetAllowCodeGenerationFromStringsCallback( |
| 457 | AllowCodeGenerationFromStringsCallback callback) { |
| 458 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 459 | isolate->set_allow_code_gen_callback(callback); |
| 460 | } |
| 461 | |
| 462 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 463 | #ifdef DEBUG |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 464 | void ImplementationUtilities::ZapHandleRange(i::Object** begin, |
| 465 | i::Object** end) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 466 | i::HandleScope::ZapRange(begin, end); |
| 467 | } |
| 468 | #endif |
| 469 | |
| 470 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 471 | void V8::SetFlagsFromString(const char* str, int length) { |
| 472 | i::FlagList::SetFlagsFromString(str, length); |
| 473 | } |
| 474 | |
| 475 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 476 | void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { |
| 477 | i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); |
| 478 | } |
| 479 | |
| 480 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 481 | v8::Handle<Value> ThrowException(v8::Handle<v8::Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 482 | i::Isolate* isolate = i::Isolate::Current(); |
| 483 | if (IsDeadCheck(isolate, "v8::ThrowException()")) { |
| 484 | return v8::Handle<Value>(); |
| 485 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 486 | ENTER_V8(isolate); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 487 | // If we're passed an empty handle, we throw an undefined exception |
| 488 | // to deal more gracefully with out of memory situations. |
| 489 | if (value.IsEmpty()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 490 | isolate->ScheduleThrow(isolate->heap()->undefined_value()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 491 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 492 | isolate->ScheduleThrow(*Utils::OpenHandle(*value)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 493 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 494 | return v8::Undefined(); |
| 495 | } |
| 496 | |
| 497 | |
| 498 | RegisteredExtension* RegisteredExtension::first_extension_ = NULL; |
| 499 | |
| 500 | |
| 501 | RegisteredExtension::RegisteredExtension(Extension* extension) |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 502 | : extension_(extension) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 503 | |
| 504 | |
| 505 | void RegisteredExtension::Register(RegisteredExtension* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 506 | that->next_ = first_extension_; |
| 507 | first_extension_ = that; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | |
| 511 | void RegisterExtension(Extension* that) { |
| 512 | RegisteredExtension* extension = new RegisteredExtension(that); |
| 513 | RegisteredExtension::Register(extension); |
| 514 | } |
| 515 | |
| 516 | |
| 517 | Extension::Extension(const char* name, |
| 518 | const char* source, |
| 519 | int dep_count, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 520 | const char** deps, |
| 521 | int source_length) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 522 | : name_(name), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 523 | source_length_(source_length >= 0 ? |
| 524 | source_length : (source ? strlen(source) : 0)), |
| 525 | source_(source, source_length_), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | dep_count_(dep_count), |
| 527 | deps_(deps), |
| 528 | auto_enable_(false) { } |
| 529 | |
| 530 | |
| 531 | v8::Handle<Primitive> Undefined() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 532 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 533 | if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) { |
| 534 | return v8::Handle<v8::Primitive>(); |
| 535 | } |
| 536 | return v8::Handle<Primitive>(ToApi<Primitive>( |
| 537 | isolate->factory()->undefined_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | |
| 541 | v8::Handle<Primitive> Null() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 542 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 543 | if (!EnsureInitializedForIsolate(isolate, "v8::Null()")) { |
| 544 | return v8::Handle<v8::Primitive>(); |
| 545 | } |
| 546 | return v8::Handle<Primitive>( |
| 547 | ToApi<Primitive>(isolate->factory()->null_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | |
| 551 | v8::Handle<Boolean> True() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 552 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 553 | if (!EnsureInitializedForIsolate(isolate, "v8::True()")) { |
| 554 | return v8::Handle<Boolean>(); |
| 555 | } |
| 556 | return v8::Handle<Boolean>( |
| 557 | ToApi<Boolean>(isolate->factory()->true_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | |
| 561 | v8::Handle<Boolean> False() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 562 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 563 | if (!EnsureInitializedForIsolate(isolate, "v8::False()")) { |
| 564 | return v8::Handle<Boolean>(); |
| 565 | } |
| 566 | return v8::Handle<Boolean>( |
| 567 | ToApi<Boolean>(isolate->factory()->false_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | |
| 571 | ResourceConstraints::ResourceConstraints() |
| 572 | : max_young_space_size_(0), |
| 573 | max_old_space_size_(0), |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 574 | max_executable_size_(0), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 575 | stack_limit_(NULL) { } |
| 576 | |
| 577 | |
| 578 | bool SetResourceConstraints(ResourceConstraints* constraints) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 579 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 580 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 581 | int young_space_size = constraints->max_young_space_size(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 582 | int old_gen_size = constraints->max_old_space_size(); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 583 | int max_executable_size = constraints->max_executable_size(); |
| 584 | 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] | 585 | // After initialization it's too late to change Heap constraints. |
| 586 | ASSERT(!isolate->IsInitialized()); |
| 587 | bool result = isolate->heap()->ConfigureHeap(young_space_size / 2, |
| 588 | old_gen_size, |
| 589 | max_executable_size); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 590 | if (!result) return false; |
| 591 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 592 | if (constraints->stack_limit() != NULL) { |
| 593 | uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 594 | isolate->stack_guard()->SetStackLimit(limit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 595 | } |
| 596 | return true; |
| 597 | } |
| 598 | |
| 599 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 600 | i::Object** V8::GlobalizeReference(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 601 | i::Isolate* isolate = i::Isolate::Current(); |
| 602 | if (IsDeadCheck(isolate, "V8::Persistent::New")) return NULL; |
| 603 | LOG_API(isolate, "Persistent::New"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 604 | i::Handle<i::Object> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 605 | isolate->global_handles()->Create(*obj); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 606 | return result.location(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 610 | void V8::MakeWeak(i::Object** object, void* parameters, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 611 | WeakReferenceCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 612 | i::Isolate* isolate = i::Isolate::Current(); |
| 613 | LOG_API(isolate, "MakeWeak"); |
| 614 | isolate->global_handles()->MakeWeak(object, parameters, |
| 615 | callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 619 | void V8::ClearWeak(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 620 | i::Isolate* isolate = i::Isolate::Current(); |
| 621 | LOG_API(isolate, "ClearWeak"); |
| 622 | isolate->global_handles()->ClearWeakness(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 626 | void V8::MarkIndependent(i::Object** object) { |
| 627 | i::Isolate* isolate = i::Isolate::Current(); |
| 628 | LOG_API(isolate, "MakeIndependent"); |
| 629 | isolate->global_handles()->MarkIndependent(object); |
| 630 | } |
| 631 | |
| 632 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 633 | bool V8::IsGlobalNearDeath(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 634 | i::Isolate* isolate = i::Isolate::Current(); |
| 635 | LOG_API(isolate, "IsGlobalNearDeath"); |
| 636 | if (!isolate->IsInitialized()) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 637 | return i::GlobalHandles::IsNearDeath(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 641 | bool V8::IsGlobalWeak(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 642 | i::Isolate* isolate = i::Isolate::Current(); |
| 643 | LOG_API(isolate, "IsGlobalWeak"); |
| 644 | if (!isolate->IsInitialized()) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 645 | return i::GlobalHandles::IsWeak(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 649 | void V8::DisposeGlobal(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 650 | i::Isolate* isolate = i::Isolate::Current(); |
| 651 | LOG_API(isolate, "DisposeGlobal"); |
| 652 | if (!isolate->IsInitialized()) return; |
| 653 | isolate->global_handles()->Destroy(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | // --- H a n d l e s --- |
| 657 | |
| 658 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 659 | HandleScope::HandleScope() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 660 | i::Isolate* isolate = i::Isolate::Current(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 661 | API_ENTRY_CHECK(isolate, "HandleScope::HandleScope"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 662 | v8::ImplementationUtilities::HandleScopeData* current = |
| 663 | isolate->handle_scope_data(); |
| 664 | isolate_ = isolate; |
| 665 | prev_next_ = current->next; |
| 666 | prev_limit_ = current->limit; |
| 667 | is_closed_ = false; |
| 668 | current->level++; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | |
| 672 | HandleScope::~HandleScope() { |
| 673 | if (!is_closed_) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 674 | Leave(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 675 | } |
| 676 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 677 | |
| 678 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 679 | void HandleScope::Leave() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 680 | ASSERT(isolate_ == i::Isolate::Current()); |
| 681 | v8::ImplementationUtilities::HandleScopeData* current = |
| 682 | isolate_->handle_scope_data(); |
| 683 | current->level--; |
| 684 | ASSERT(current->level >= 0); |
| 685 | current->next = prev_next_; |
| 686 | if (current->limit != prev_limit_) { |
| 687 | current->limit = prev_limit_; |
| 688 | i::HandleScope::DeleteExtensions(isolate_); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | #ifdef DEBUG |
| 692 | i::HandleScope::ZapRange(prev_next_, prev_limit_); |
| 693 | #endif |
| 694 | } |
| 695 | |
| 696 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 697 | int HandleScope::NumberOfHandles() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 698 | EnsureInitializedForIsolate( |
| 699 | i::Isolate::Current(), "HandleScope::NumberOfHandles"); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 700 | return i::HandleScope::NumberOfHandles(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 704 | i::Object** HandleScope::CreateHandle(i::Object* value) { |
| 705 | return i::HandleScope::CreateHandle(value, i::Isolate::Current()); |
| 706 | } |
| 707 | |
| 708 | |
| 709 | i::Object** HandleScope::CreateHandle(i::HeapObject* value) { |
| 710 | ASSERT(value->IsHeapObject()); |
| 711 | return reinterpret_cast<i::Object**>( |
| 712 | i::HandleScope::CreateHandle(value, value->GetIsolate())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | |
| 716 | void Context::Enter() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 717 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 718 | i::Isolate* isolate = env->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 719 | if (IsDeadCheck(isolate, "v8::Context::Enter()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 720 | ENTER_V8(isolate); |
| 721 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 722 | isolate->handle_scope_implementer()->EnterContext(env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 723 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 724 | isolate->handle_scope_implementer()->SaveContext(isolate->context()); |
| 725 | isolate->set_context(*env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | |
| 729 | void Context::Exit() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 730 | // Exit is essentially a static function and doesn't use the |
| 731 | // receiver, so we have to get the current isolate from the thread |
| 732 | // local. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 733 | i::Isolate* isolate = i::Isolate::Current(); |
| 734 | if (!isolate->IsInitialized()) return; |
| 735 | |
| 736 | if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(), |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 737 | "v8::Context::Exit()", |
| 738 | "Cannot exit non-entered context")) { |
| 739 | return; |
| 740 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 741 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 742 | // Content of 'last_context' could be NULL. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 743 | i::Context* last_context = |
| 744 | isolate->handle_scope_implementer()->RestoreContext(); |
| 745 | isolate->set_context(last_context); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 746 | isolate->set_context_exit_happened(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 750 | void Context::SetData(v8::Handle<String> data) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 751 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 752 | i::Isolate* isolate = env->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 753 | if (IsDeadCheck(isolate, "v8::Context::SetData()")) return; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 754 | i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
| 755 | ASSERT(env->IsGlobalContext()); |
| 756 | if (env->IsGlobalContext()) { |
| 757 | env->set_data(*raw_data); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
| 761 | |
| 762 | v8::Local<v8::Value> Context::GetData() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 763 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 764 | i::Isolate* isolate = env->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 765 | if (IsDeadCheck(isolate, "v8::Context::GetData()")) { |
| 766 | return v8::Local<Value>(); |
| 767 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 768 | i::Object* raw_result = NULL; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 769 | ASSERT(env->IsGlobalContext()); |
| 770 | if (env->IsGlobalContext()) { |
| 771 | raw_result = env->data(); |
| 772 | } else { |
| 773 | return Local<Value>(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 774 | } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 775 | i::Handle<i::Object> result(raw_result, isolate); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 776 | return Utils::ToLocal(result); |
| 777 | } |
| 778 | |
| 779 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 780 | i::Object** v8::HandleScope::RawClose(i::Object** value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 781 | if (!ApiCheck(!is_closed_, |
| 782 | "v8::HandleScope::Close()", |
| 783 | "Local scope has already been closed")) { |
| 784 | return 0; |
| 785 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 786 | LOG_API(isolate_, "CloseHandleScope"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 787 | |
| 788 | // Read the result before popping the handle block. |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 789 | i::Object* result = NULL; |
| 790 | if (value != NULL) { |
| 791 | result = *value; |
| 792 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 793 | is_closed_ = true; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 794 | Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 795 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 796 | if (value == NULL) { |
| 797 | return NULL; |
| 798 | } |
| 799 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 800 | // Allocate a new handle on the previous handle block. |
| 801 | i::Handle<i::Object> handle(result); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 802 | return handle.location(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | |
| 806 | // --- N e a n d e r --- |
| 807 | |
| 808 | |
| 809 | // A constructor cannot easily return an error value, therefore it is necessary |
| 810 | // to check for a dead VM with ON_BAILOUT before constructing any Neander |
| 811 | // objects. To remind you about this there is no HandleScope in the |
| 812 | // NeanderObject constructor. When you add one to the site calling the |
| 813 | // constructor you should check that you ensured the VM was not dead first. |
| 814 | NeanderObject::NeanderObject(int size) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 815 | i::Isolate* isolate = i::Isolate::Current(); |
| 816 | EnsureInitializedForIsolate(isolate, "v8::Nowhere"); |
| 817 | ENTER_V8(isolate); |
| 818 | value_ = isolate->factory()->NewNeanderObject(); |
| 819 | i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 820 | value_->set_elements(*elements); |
| 821 | } |
| 822 | |
| 823 | |
| 824 | int NeanderObject::size() { |
| 825 | return i::FixedArray::cast(value_->elements())->length(); |
| 826 | } |
| 827 | |
| 828 | |
| 829 | NeanderArray::NeanderArray() : obj_(2) { |
| 830 | obj_.set(0, i::Smi::FromInt(0)); |
| 831 | } |
| 832 | |
| 833 | |
| 834 | int NeanderArray::length() { |
| 835 | return i::Smi::cast(obj_.get(0))->value(); |
| 836 | } |
| 837 | |
| 838 | |
| 839 | i::Object* NeanderArray::get(int offset) { |
| 840 | ASSERT(0 <= offset); |
| 841 | ASSERT(offset < length()); |
| 842 | return obj_.get(offset + 1); |
| 843 | } |
| 844 | |
| 845 | |
| 846 | // This method cannot easily return an error value, therefore it is necessary |
| 847 | // to check for a dead VM with ON_BAILOUT before calling it. To remind you |
| 848 | // about this there is no HandleScope in this method. When you add one to the |
| 849 | // site calling this method you should check that you ensured the VM was not |
| 850 | // dead first. |
| 851 | void NeanderArray::add(i::Handle<i::Object> value) { |
| 852 | int length = this->length(); |
| 853 | int size = obj_.size(); |
| 854 | if (length == size - 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 855 | i::Handle<i::FixedArray> new_elms = FACTORY->NewFixedArray(2 * size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 856 | for (int i = 0; i < length; i++) |
| 857 | new_elms->set(i + 1, get(i)); |
| 858 | obj_.value()->set_elements(*new_elms); |
| 859 | } |
| 860 | obj_.set(length + 1, *value); |
| 861 | obj_.set(0, i::Smi::FromInt(length + 1)); |
| 862 | } |
| 863 | |
| 864 | |
| 865 | void NeanderArray::set(int index, i::Object* value) { |
| 866 | if (index < 0 || index >= this->length()) return; |
| 867 | obj_.set(index + 1, value); |
| 868 | } |
| 869 | |
| 870 | |
| 871 | // --- T e m p l a t e --- |
| 872 | |
| 873 | |
| 874 | static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { |
| 875 | that->set_tag(i::Smi::FromInt(type)); |
| 876 | } |
| 877 | |
| 878 | |
| 879 | void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, |
| 880 | v8::PropertyAttribute attribute) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 881 | i::Isolate* isolate = i::Isolate::Current(); |
| 882 | if (IsDeadCheck(isolate, "v8::Template::Set()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 883 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 884 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 885 | i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list()); |
| 886 | if (list->IsUndefined()) { |
| 887 | list = NeanderArray().value(); |
| 888 | Utils::OpenHandle(this)->set_property_list(*list); |
| 889 | } |
| 890 | NeanderArray array(list); |
| 891 | array.add(Utils::OpenHandle(*name)); |
| 892 | array.add(Utils::OpenHandle(*value)); |
| 893 | array.add(Utils::OpenHandle(*v8::Integer::New(attribute))); |
| 894 | } |
| 895 | |
| 896 | |
| 897 | // --- F u n c t i o n T e m p l a t e --- |
| 898 | static void InitializeFunctionTemplate( |
| 899 | i::Handle<i::FunctionTemplateInfo> info) { |
| 900 | info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE)); |
| 901 | info->set_flag(0); |
| 902 | } |
| 903 | |
| 904 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 905 | Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 906 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 907 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::PrototypeTemplate()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 908 | return Local<ObjectTemplate>(); |
| 909 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 910 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 911 | i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template()); |
| 912 | if (result->IsUndefined()) { |
| 913 | result = Utils::OpenHandle(*ObjectTemplate::New()); |
| 914 | Utils::OpenHandle(this)->set_prototype_template(*result); |
| 915 | } |
| 916 | return Local<ObjectTemplate>(ToApi<ObjectTemplate>(result)); |
| 917 | } |
| 918 | |
| 919 | |
| 920 | void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 921 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 922 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 923 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 924 | Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); |
| 925 | } |
| 926 | |
| 927 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 928 | Local<FunctionTemplate> FunctionTemplate::New(InvocationCallback callback, |
| 929 | v8::Handle<Value> data, v8::Handle<Signature> signature) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 930 | i::Isolate* isolate = i::Isolate::Current(); |
| 931 | EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); |
| 932 | LOG_API(isolate, "FunctionTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 933 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 934 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 935 | isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 936 | i::Handle<i::FunctionTemplateInfo> obj = |
| 937 | i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
| 938 | InitializeFunctionTemplate(obj); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 939 | int next_serial_number = isolate->next_serial_number(); |
| 940 | isolate->set_next_serial_number(next_serial_number + 1); |
| 941 | obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 942 | if (callback != 0) { |
| 943 | if (data.IsEmpty()) data = v8::Undefined(); |
| 944 | Utils::ToLocal(obj)->SetCallHandler(callback, data); |
| 945 | } |
| 946 | obj->set_undetectable(false); |
| 947 | obj->set_needs_access_check(false); |
| 948 | |
| 949 | if (!signature.IsEmpty()) |
| 950 | obj->set_signature(*Utils::OpenHandle(*signature)); |
| 951 | return Utils::ToLocal(obj); |
| 952 | } |
| 953 | |
| 954 | |
| 955 | Local<Signature> Signature::New(Handle<FunctionTemplate> receiver, |
| 956 | int argc, Handle<FunctionTemplate> argv[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 957 | i::Isolate* isolate = i::Isolate::Current(); |
| 958 | EnsureInitializedForIsolate(isolate, "v8::Signature::New()"); |
| 959 | LOG_API(isolate, "Signature::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 960 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 961 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 962 | isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 963 | i::Handle<i::SignatureInfo> obj = |
| 964 | i::Handle<i::SignatureInfo>::cast(struct_obj); |
| 965 | if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver)); |
| 966 | if (argc > 0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 967 | i::Handle<i::FixedArray> args = 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 | if (!argv[i].IsEmpty()) |
| 970 | args->set(i, *Utils::OpenHandle(*argv[i])); |
| 971 | } |
| 972 | obj->set_args(*args); |
| 973 | } |
| 974 | return Utils::ToLocal(obj); |
| 975 | } |
| 976 | |
| 977 | |
| 978 | Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) { |
| 979 | Handle<FunctionTemplate> types[1] = { type }; |
| 980 | return TypeSwitch::New(1, types); |
| 981 | } |
| 982 | |
| 983 | |
| 984 | Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 985 | i::Isolate* isolate = i::Isolate::Current(); |
| 986 | EnsureInitializedForIsolate(isolate, "v8::TypeSwitch::New()"); |
| 987 | LOG_API(isolate, "TypeSwitch::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 988 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 989 | i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 990 | for (int i = 0; i < argc; i++) |
| 991 | vector->set(i, *Utils::OpenHandle(*types[i])); |
| 992 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 993 | isolate->factory()->NewStruct(i::TYPE_SWITCH_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 994 | i::Handle<i::TypeSwitchInfo> obj = |
| 995 | i::Handle<i::TypeSwitchInfo>::cast(struct_obj); |
| 996 | obj->set_types(*vector); |
| 997 | return Utils::ToLocal(obj); |
| 998 | } |
| 999 | |
| 1000 | |
| 1001 | int TypeSwitch::match(v8::Handle<Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1002 | i::Isolate* isolate = i::Isolate::Current(); |
| 1003 | LOG_API(isolate, "TypeSwitch::match"); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1004 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1005 | i::Handle<i::Object> obj = Utils::OpenHandle(*value); |
| 1006 | i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this); |
| 1007 | i::FixedArray* types = i::FixedArray::cast(info->types()); |
| 1008 | for (int i = 0; i < types->length(); i++) { |
| 1009 | if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i)))) |
| 1010 | return i + 1; |
| 1011 | } |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1016 | #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
| 1017 | i::Handle<i::Object> foreign = FromCData(cdata); \ |
| 1018 | (obj)->setter(*foreign); \ |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1019 | } while (false) |
| 1020 | |
| 1021 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1022 | void FunctionTemplate::SetCallHandler(InvocationCallback callback, |
| 1023 | v8::Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1024 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1025 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetCallHandler()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1026 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1027 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1028 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1029 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1030 | i::Handle<i::CallHandlerInfo> obj = |
| 1031 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1032 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1033 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1034 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1035 | Utils::OpenHandle(this)->set_call_code(*obj); |
| 1036 | } |
| 1037 | |
| 1038 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1039 | static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
| 1040 | v8::Handle<String> name, |
| 1041 | AccessorGetter getter, |
| 1042 | AccessorSetter setter, |
| 1043 | v8::Handle<Value> data, |
| 1044 | v8::AccessControl settings, |
| 1045 | v8::PropertyAttribute attributes) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1046 | i::Handle<i::AccessorInfo> obj = FACTORY->NewAccessorInfo(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1047 | ASSERT(getter != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1048 | SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1049 | SET_FIELD_WRAPPED(obj, set_setter, setter); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1050 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1051 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1052 | obj->set_name(*Utils::OpenHandle(*name)); |
| 1053 | if (settings & ALL_CAN_READ) obj->set_all_can_read(true); |
| 1054 | if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); |
| 1055 | if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true); |
| 1056 | obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); |
| 1057 | return obj; |
| 1058 | } |
| 1059 | |
| 1060 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1061 | void FunctionTemplate::AddInstancePropertyAccessor( |
| 1062 | v8::Handle<String> name, |
| 1063 | AccessorGetter getter, |
| 1064 | AccessorSetter setter, |
| 1065 | v8::Handle<Value> data, |
| 1066 | v8::AccessControl settings, |
| 1067 | v8::PropertyAttribute attributes) { |
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, |
| 1070 | "v8::FunctionTemplate::AddInstancePropertyAccessor()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1071 | return; |
| 1072 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1073 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1074 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1075 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1076 | i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name, |
| 1077 | getter, setter, data, |
| 1078 | settings, attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1079 | i::Handle<i::Object> list(Utils::OpenHandle(this)->property_accessors()); |
| 1080 | if (list->IsUndefined()) { |
| 1081 | list = NeanderArray().value(); |
| 1082 | Utils::OpenHandle(this)->set_property_accessors(*list); |
| 1083 | } |
| 1084 | NeanderArray array(list); |
| 1085 | array.add(obj); |
| 1086 | } |
| 1087 | |
| 1088 | |
| 1089 | Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1090 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1091 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::InstanceTemplate()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1092 | || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) |
| 1093 | return Local<ObjectTemplate>(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1094 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1095 | if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) { |
| 1096 | Local<ObjectTemplate> templ = |
| 1097 | ObjectTemplate::New(v8::Handle<FunctionTemplate>(this)); |
| 1098 | Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ)); |
| 1099 | } |
| 1100 | i::Handle<i::ObjectTemplateInfo> result(i::ObjectTemplateInfo::cast( |
| 1101 | Utils::OpenHandle(this)->instance_template())); |
| 1102 | return Utils::ToLocal(result); |
| 1103 | } |
| 1104 | |
| 1105 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1106 | void FunctionTemplate::SetClassName(Handle<String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1107 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1108 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetClassName()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1109 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1110 | Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name)); |
| 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | void FunctionTemplate::SetHiddenPrototype(bool value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1115 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1116 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetHiddenPrototype()")) { |
| 1117 | return; |
| 1118 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1119 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1120 | Utils::OpenHandle(this)->set_hidden_prototype(value); |
| 1121 | } |
| 1122 | |
| 1123 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1124 | void FunctionTemplate::ReadOnlyPrototype() { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1125 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1126 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetPrototypeAttributes()")) { |
| 1127 | return; |
| 1128 | } |
| 1129 | ENTER_V8(isolate); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1130 | Utils::OpenHandle(this)->set_read_only_prototype(true); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1134 | void FunctionTemplate::SetNamedInstancePropertyHandler( |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1135 | NamedPropertyGetter getter, |
| 1136 | NamedPropertySetter setter, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1137 | NamedPropertyQuery query, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1138 | NamedPropertyDeleter remover, |
| 1139 | NamedPropertyEnumerator enumerator, |
| 1140 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1141 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1142 | if (IsDeadCheck(isolate, |
| 1143 | "v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1144 | return; |
| 1145 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1146 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1147 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1148 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1149 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1150 | i::Handle<i::InterceptorInfo> obj = |
| 1151 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1152 | |
| 1153 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1154 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1155 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1156 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1157 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1158 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1159 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1160 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1161 | Utils::OpenHandle(this)->set_named_property_handler(*obj); |
| 1162 | } |
| 1163 | |
| 1164 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1165 | void FunctionTemplate::SetIndexedInstancePropertyHandler( |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1166 | IndexedPropertyGetter getter, |
| 1167 | IndexedPropertySetter setter, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1168 | IndexedPropertyQuery query, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1169 | IndexedPropertyDeleter remover, |
| 1170 | IndexedPropertyEnumerator enumerator, |
| 1171 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1172 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1173 | if (IsDeadCheck(isolate, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1174 | "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) { |
| 1175 | return; |
| 1176 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1177 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1178 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1179 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1180 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1181 | i::Handle<i::InterceptorInfo> obj = |
| 1182 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1183 | |
| 1184 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1185 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1186 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1187 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1188 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1189 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1190 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1191 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1192 | Utils::OpenHandle(this)->set_indexed_property_handler(*obj); |
| 1193 | } |
| 1194 | |
| 1195 | |
| 1196 | void FunctionTemplate::SetInstanceCallAsFunctionHandler( |
| 1197 | InvocationCallback callback, |
| 1198 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1199 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1200 | if (IsDeadCheck(isolate, |
| 1201 | "v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1202 | return; |
| 1203 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1204 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1205 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1206 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1207 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1208 | i::Handle<i::CallHandlerInfo> obj = |
| 1209 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1210 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1211 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1212 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1213 | Utils::OpenHandle(this)->set_instance_call_handler(*obj); |
| 1214 | } |
| 1215 | |
| 1216 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1217 | // --- O b j e c t T e m p l a t e --- |
| 1218 | |
| 1219 | |
| 1220 | Local<ObjectTemplate> ObjectTemplate::New() { |
| 1221 | return New(Local<FunctionTemplate>()); |
| 1222 | } |
| 1223 | |
| 1224 | |
| 1225 | Local<ObjectTemplate> ObjectTemplate::New( |
| 1226 | v8::Handle<FunctionTemplate> constructor) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1227 | i::Isolate* isolate = i::Isolate::Current(); |
| 1228 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::New()")) { |
| 1229 | return Local<ObjectTemplate>(); |
| 1230 | } |
| 1231 | EnsureInitializedForIsolate(isolate, "v8::ObjectTemplate::New()"); |
| 1232 | LOG_API(isolate, "ObjectTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1233 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1234 | i::Handle<i::Struct> struct_obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1235 | isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1236 | i::Handle<i::ObjectTemplateInfo> obj = |
| 1237 | i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); |
| 1238 | InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
| 1239 | if (!constructor.IsEmpty()) |
| 1240 | obj->set_constructor(*Utils::OpenHandle(*constructor)); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1241 | obj->set_internal_field_count(i::Smi::FromInt(0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1242 | return Utils::ToLocal(obj); |
| 1243 | } |
| 1244 | |
| 1245 | |
| 1246 | // Ensure that the object template has a constructor. If no |
| 1247 | // constructor is available we create one. |
| 1248 | static void EnsureConstructor(ObjectTemplate* object_template) { |
| 1249 | if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { |
| 1250 | Local<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1251 | i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); |
| 1252 | constructor->set_instance_template(*Utils::OpenHandle(object_template)); |
| 1253 | Utils::OpenHandle(object_template)->set_constructor(*constructor); |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | |
| 1258 | void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
| 1259 | AccessorGetter getter, |
| 1260 | AccessorSetter setter, |
| 1261 | v8::Handle<Value> data, |
| 1262 | AccessControl settings, |
| 1263 | PropertyAttribute attribute) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1264 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1265 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1266 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1267 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1268 | EnsureConstructor(this); |
| 1269 | i::FunctionTemplateInfo* constructor = |
| 1270 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1271 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1272 | Utils::ToLocal(cons)->AddInstancePropertyAccessor(name, |
| 1273 | getter, |
| 1274 | setter, |
| 1275 | data, |
| 1276 | settings, |
| 1277 | attribute); |
| 1278 | } |
| 1279 | |
| 1280 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1281 | void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 1282 | NamedPropertySetter setter, |
| 1283 | NamedPropertyQuery query, |
| 1284 | NamedPropertyDeleter remover, |
| 1285 | NamedPropertyEnumerator enumerator, |
| 1286 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1287 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1288 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) { |
| 1289 | return; |
| 1290 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1291 | ENTER_V8(isolate); |
| 1292 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1293 | EnsureConstructor(this); |
| 1294 | i::FunctionTemplateInfo* constructor = |
| 1295 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1296 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1297 | Utils::ToLocal(cons)->SetNamedInstancePropertyHandler(getter, |
| 1298 | setter, |
| 1299 | query, |
| 1300 | remover, |
| 1301 | enumerator, |
| 1302 | data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | |
| 1306 | void ObjectTemplate::MarkAsUndetectable() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1307 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1308 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::MarkAsUndetectable()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1309 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1310 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1311 | EnsureConstructor(this); |
| 1312 | i::FunctionTemplateInfo* constructor = |
| 1313 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1314 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1315 | cons->set_undetectable(true); |
| 1316 | } |
| 1317 | |
| 1318 | |
| 1319 | void ObjectTemplate::SetAccessCheckCallbacks( |
| 1320 | NamedSecurityCallback named_callback, |
| 1321 | IndexedSecurityCallback indexed_callback, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1322 | Handle<Value> data, |
| 1323 | bool turned_on_by_default) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1324 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1325 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessCheckCallbacks()")) { |
| 1326 | return; |
| 1327 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1328 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1329 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1330 | EnsureConstructor(this); |
| 1331 | |
| 1332 | i::Handle<i::Struct> struct_info = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1333 | isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1334 | i::Handle<i::AccessCheckInfo> info = |
| 1335 | i::Handle<i::AccessCheckInfo>::cast(struct_info); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1336 | |
| 1337 | SET_FIELD_WRAPPED(info, set_named_callback, named_callback); |
| 1338 | SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback); |
| 1339 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1340 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1341 | info->set_data(*Utils::OpenHandle(*data)); |
| 1342 | |
| 1343 | i::FunctionTemplateInfo* constructor = |
| 1344 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1345 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1346 | cons->set_access_check_info(*info); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1347 | cons->set_needs_access_check(turned_on_by_default); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1351 | void ObjectTemplate::SetIndexedPropertyHandler( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1352 | IndexedPropertyGetter getter, |
| 1353 | IndexedPropertySetter setter, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1354 | IndexedPropertyQuery query, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1355 | IndexedPropertyDeleter remover, |
| 1356 | IndexedPropertyEnumerator enumerator, |
| 1357 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1358 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1359 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetIndexedPropertyHandler()")) { |
| 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); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1368 | Utils::ToLocal(cons)->SetIndexedInstancePropertyHandler(getter, |
| 1369 | setter, |
| 1370 | query, |
| 1371 | remover, |
| 1372 | enumerator, |
| 1373 | data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | void ObjectTemplate::SetCallAsFunctionHandler(InvocationCallback callback, |
| 1378 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1379 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1380 | if (IsDeadCheck(isolate, |
| 1381 | "v8::ObjectTemplate::SetCallAsFunctionHandler()")) { |
| 1382 | return; |
| 1383 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1384 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1385 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1386 | EnsureConstructor(this); |
| 1387 | i::FunctionTemplateInfo* constructor = |
| 1388 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1389 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1390 | Utils::ToLocal(cons)->SetInstanceCallAsFunctionHandler(callback, data); |
| 1391 | } |
| 1392 | |
| 1393 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1394 | int ObjectTemplate::InternalFieldCount() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1395 | if (IsDeadCheck(Utils::OpenHandle(this)->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1396 | "v8::ObjectTemplate::InternalFieldCount()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1397 | return 0; |
| 1398 | } |
| 1399 | return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1403 | void ObjectTemplate::SetInternalFieldCount(int value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1404 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1405 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetInternalFieldCount()")) { |
| 1406 | return; |
| 1407 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1408 | if (!ApiCheck(i::Smi::IsValid(value), |
| 1409 | "v8::ObjectTemplate::SetInternalFieldCount()", |
| 1410 | "Invalid internal field count")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1411 | return; |
| 1412 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1413 | ENTER_V8(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1414 | if (value > 0) { |
| 1415 | // The internal field count is set by the constructor function's |
| 1416 | // construct code, so we ensure that there is a constructor |
| 1417 | // function to do the setting. |
| 1418 | EnsureConstructor(this); |
| 1419 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1420 | Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1424 | // --- S c r i p t D a t a --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1425 | |
| 1426 | |
| 1427 | ScriptData* ScriptData::PreCompile(const char* input, int length) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1428 | i::Utf8ToUC16CharacterStream stream( |
| 1429 | reinterpret_cast<const unsigned char*>(input), length); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1430 | return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_scoping); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1434 | ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { |
| 1435 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1436 | if (str->IsExternalTwoByteString()) { |
| 1437 | i::ExternalTwoByteStringUC16CharacterStream stream( |
| 1438 | i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1439 | return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_scoping); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1440 | } else { |
| 1441 | i::GenericStringUC16CharacterStream stream(str, 0, str->length()); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1442 | return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_scoping); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1443 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1447 | ScriptData* ScriptData::New(const char* data, int length) { |
| 1448 | // Return an empty ScriptData if the length is obviously invalid. |
| 1449 | if (length % sizeof(unsigned) != 0) { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1450 | return new i::ScriptDataImpl(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | // Copy the data to ensure it is properly aligned. |
| 1454 | int deserialized_data_length = length / sizeof(unsigned); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1455 | // If aligned, don't create a copy of the data. |
| 1456 | if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) { |
| 1457 | return new i::ScriptDataImpl(data, length); |
| 1458 | } |
| 1459 | // Copy the data to align it. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1460 | unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1461 | i::OS::MemCopy(deserialized_data, data, length); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1462 | |
| 1463 | return new i::ScriptDataImpl( |
| 1464 | i::Vector<unsigned>(deserialized_data, deserialized_data_length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | |
| 1468 | // --- S c r i p t --- |
| 1469 | |
| 1470 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1471 | Local<Script> Script::New(v8::Handle<String> source, |
| 1472 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1473 | v8::ScriptData* pre_data, |
| 1474 | v8::Handle<String> script_data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1475 | i::Isolate* isolate = i::Isolate::Current(); |
| 1476 | ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>()); |
| 1477 | LOG_API(isolate, "Script::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1478 | ENTER_V8(isolate); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1479 | i::SharedFunctionInfo* raw_result = NULL; |
| 1480 | { i::HandleScope scope(isolate); |
| 1481 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1482 | i::Handle<i::Object> name_obj; |
| 1483 | int line_offset = 0; |
| 1484 | int column_offset = 0; |
| 1485 | if (origin != NULL) { |
| 1486 | if (!origin->ResourceName().IsEmpty()) { |
| 1487 | name_obj = Utils::OpenHandle(*origin->ResourceName()); |
| 1488 | } |
| 1489 | if (!origin->ResourceLineOffset().IsEmpty()) { |
| 1490 | line_offset = static_cast<int>(origin->ResourceLineOffset()->Value()); |
| 1491 | } |
| 1492 | if (!origin->ResourceColumnOffset().IsEmpty()) { |
| 1493 | column_offset = |
| 1494 | static_cast<int>(origin->ResourceColumnOffset()->Value()); |
| 1495 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1496 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1497 | EXCEPTION_PREAMBLE(isolate); |
| 1498 | i::ScriptDataImpl* pre_data_impl = |
| 1499 | static_cast<i::ScriptDataImpl*>(pre_data); |
| 1500 | // We assert that the pre-data is sane, even though we can actually |
| 1501 | // handle it if it turns out not to be in release mode. |
| 1502 | ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck()); |
| 1503 | // If the pre-data isn't sane we simply ignore it |
| 1504 | if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) { |
| 1505 | pre_data_impl = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1506 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1507 | i::Handle<i::SharedFunctionInfo> result = |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1508 | i::Compiler::Compile(str, |
| 1509 | name_obj, |
| 1510 | line_offset, |
| 1511 | column_offset, |
| 1512 | NULL, |
| 1513 | pre_data_impl, |
| 1514 | Utils::OpenHandle(*script_data), |
| 1515 | i::NOT_NATIVES_CODE); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1516 | has_pending_exception = result.is_null(); |
| 1517 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); |
| 1518 | raw_result = *result; |
| 1519 | } |
| 1520 | i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1521 | return Local<Script>(ToApi<Script>(result)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | |
| 1525 | Local<Script> Script::New(v8::Handle<String> source, |
| 1526 | v8::Handle<Value> file_name) { |
| 1527 | ScriptOrigin origin(file_name); |
| 1528 | return New(source, &origin); |
| 1529 | } |
| 1530 | |
| 1531 | |
| 1532 | Local<Script> Script::Compile(v8::Handle<String> source, |
| 1533 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1534 | v8::ScriptData* pre_data, |
| 1535 | v8::Handle<String> script_data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1536 | i::Isolate* isolate = i::Isolate::Current(); |
| 1537 | ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>()); |
| 1538 | LOG_API(isolate, "Script::Compile"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1539 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1540 | Local<Script> generic = New(source, origin, pre_data, script_data); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1541 | if (generic.IsEmpty()) |
| 1542 | return generic; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1543 | i::Handle<i::Object> obj = Utils::OpenHandle(*generic); |
| 1544 | i::Handle<i::SharedFunctionInfo> function = |
| 1545 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1546 | i::Handle<i::JSFunction> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1547 | isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 1548 | function, |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1549 | isolate->global_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1550 | return Local<Script>(ToApi<Script>(result)); |
| 1551 | } |
| 1552 | |
| 1553 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1554 | Local<Script> Script::Compile(v8::Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1555 | v8::Handle<Value> file_name, |
| 1556 | v8::Handle<String> script_data) { |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1557 | ScriptOrigin origin(file_name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1558 | return Compile(source, &origin, 0, script_data); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1562 | Local<Value> Script::Run() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1563 | i::Isolate* isolate = i::Isolate::Current(); |
| 1564 | ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); |
| 1565 | LOG_API(isolate, "Script::Run"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1566 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1567 | i::Object* raw_result = NULL; |
| 1568 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1569 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1570 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 1571 | i::Handle<i::JSFunction> fun; |
| 1572 | if (obj->IsSharedFunctionInfo()) { |
| 1573 | i::Handle<i::SharedFunctionInfo> |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1574 | function_info(i::SharedFunctionInfo::cast(*obj), isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1575 | fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1576 | function_info, isolate->global_context()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1577 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1578 | fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1579 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1580 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1581 | i::Handle<i::Object> receiver( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1582 | isolate->context()->global_proxy(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1583 | i::Handle<i::Object> result = |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1584 | i::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 1585 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1586 | raw_result = *result; |
| 1587 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1588 | i::Handle<i::Object> result(raw_result, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1589 | return Utils::ToLocal(result); |
| 1590 | } |
| 1591 | |
| 1592 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1593 | static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) { |
| 1594 | i::Handle<i::Object> obj = Utils::OpenHandle(script); |
| 1595 | i::Handle<i::SharedFunctionInfo> result; |
| 1596 | if (obj->IsSharedFunctionInfo()) { |
| 1597 | result = |
| 1598 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
| 1599 | } else { |
| 1600 | result = |
| 1601 | i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()); |
| 1602 | } |
| 1603 | return result; |
| 1604 | } |
| 1605 | |
| 1606 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1607 | Local<Value> Script::Id() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1608 | i::Isolate* isolate = i::Isolate::Current(); |
| 1609 | ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>()); |
| 1610 | LOG_API(isolate, "Script::Id"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1611 | i::Object* raw_id = NULL; |
| 1612 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1613 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1614 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
| 1615 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1616 | i::Handle<i::Object> id(script->id()); |
| 1617 | raw_id = *id; |
| 1618 | } |
| 1619 | i::Handle<i::Object> id(raw_id); |
| 1620 | return Utils::ToLocal(id); |
| 1621 | } |
| 1622 | |
| 1623 | |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1624 | void Script::SetData(v8::Handle<String> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1625 | i::Isolate* isolate = i::Isolate::Current(); |
| 1626 | ON_BAILOUT(isolate, "v8::Script::SetData()", return); |
| 1627 | LOG_API(isolate, "Script::SetData"); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1628 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1629 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1630 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1631 | i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1632 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1633 | script->set_data(*raw_data); |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1638 | // --- E x c e p t i o n s --- |
| 1639 | |
| 1640 | |
| 1641 | v8::TryCatch::TryCatch() |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1642 | : isolate_(i::Isolate::Current()), |
| 1643 | next_(isolate_->try_catch_handler_address()), |
| 1644 | exception_(isolate_->heap()->the_hole_value()), |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1645 | message_(i::Smi::FromInt(0)), |
| 1646 | is_verbose_(false), |
ager@chromium.org | 68e7ab7 | 2009-09-23 09:40:39 +0000 | [diff] [blame] | 1647 | can_continue_(true), |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1648 | capture_message_(true), |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1649 | rethrow_(false) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1650 | isolate_->RegisterTryCatchHandler(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | |
| 1654 | v8::TryCatch::~TryCatch() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1655 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1656 | if (rethrow_) { |
| 1657 | v8::HandleScope scope; |
| 1658 | v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(Exception()); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1659 | isolate_->UnregisterTryCatchHandler(this); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1660 | v8::ThrowException(exc); |
| 1661 | } else { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1662 | isolate_->UnregisterTryCatchHandler(this); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1663 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1667 | bool v8::TryCatch::HasCaught() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1668 | return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(); |
| 1669 | } |
| 1670 | |
| 1671 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 1672 | bool v8::TryCatch::CanContinue() const { |
| 1673 | return can_continue_; |
| 1674 | } |
| 1675 | |
| 1676 | |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1677 | v8::Handle<v8::Value> v8::TryCatch::ReThrow() { |
| 1678 | if (!HasCaught()) return v8::Local<v8::Value>(); |
| 1679 | rethrow_ = true; |
| 1680 | return v8::Undefined(); |
| 1681 | } |
| 1682 | |
| 1683 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1684 | v8::Local<Value> v8::TryCatch::Exception() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1685 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1686 | if (HasCaught()) { |
| 1687 | // Check for out of memory exception. |
| 1688 | i::Object* exception = reinterpret_cast<i::Object*>(exception_); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1689 | return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1690 | } else { |
| 1691 | return v8::Local<Value>(); |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1696 | v8::Local<Value> v8::TryCatch::StackTrace() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1697 | ASSERT(isolate_ == i::Isolate::Current()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1698 | if (HasCaught()) { |
| 1699 | i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); |
| 1700 | if (!raw_obj->IsJSObject()) return v8::Local<Value>(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1701 | i::HandleScope scope(isolate_); |
| 1702 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); |
| 1703 | i::Handle<i::String> name = isolate_->factory()->LookupAsciiSymbol("stack"); |
| 1704 | if (!obj->HasProperty(*name)) return v8::Local<Value>(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1705 | i::Handle<i::Object> value = i::GetProperty(obj, name); |
| 1706 | if (value.is_null()) return v8::Local<Value>(); |
| 1707 | return v8::Utils::ToLocal(scope.CloseAndEscape(value)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1708 | } else { |
| 1709 | return v8::Local<Value>(); |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1714 | v8::Local<v8::Message> v8::TryCatch::Message() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1715 | ASSERT(isolate_ == i::Isolate::Current()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1716 | if (HasCaught() && message_ != i::Smi::FromInt(0)) { |
| 1717 | i::Object* message = reinterpret_cast<i::Object*>(message_); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1718 | return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1719 | } else { |
| 1720 | return v8::Local<v8::Message>(); |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1725 | void v8::TryCatch::Reset() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1726 | ASSERT(isolate_ == i::Isolate::Current()); |
| 1727 | exception_ = isolate_->heap()->the_hole_value(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1728 | message_ = i::Smi::FromInt(0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | |
| 1732 | void v8::TryCatch::SetVerbose(bool value) { |
| 1733 | is_verbose_ = value; |
| 1734 | } |
| 1735 | |
| 1736 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1737 | void v8::TryCatch::SetCaptureMessage(bool value) { |
| 1738 | capture_message_ = value; |
| 1739 | } |
| 1740 | |
| 1741 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1742 | // --- M e s s a g e --- |
| 1743 | |
| 1744 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1745 | Local<String> Message::Get() 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 | ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1748 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1749 | HandleScope scope; |
| 1750 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 1751 | i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(obj); |
| 1752 | Local<String> result = Utils::ToLocal(raw_result); |
| 1753 | return scope.Close(result); |
| 1754 | } |
| 1755 | |
| 1756 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1757 | v8::Handle<Value> Message::GetScriptResourceName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1758 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1759 | if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceName()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1760 | return Local<String>(); |
| 1761 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1762 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1763 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1764 | i::Handle<i::JSMessageObject> message = |
| 1765 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1766 | // Return this.script.name. |
| 1767 | i::Handle<i::JSValue> script = |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1768 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1769 | 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] | 1770 | return scope.Close(Utils::ToLocal(resource_name)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1774 | v8::Handle<Value> Message::GetScriptData() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1775 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1776 | if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceData()")) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1777 | return Local<Value>(); |
| 1778 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1779 | ENTER_V8(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1780 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1781 | i::Handle<i::JSMessageObject> message = |
| 1782 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1783 | // Return this.script.data. |
| 1784 | i::Handle<i::JSValue> script = |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1785 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script())); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1786 | i::Handle<i::Object> data(i::Script::cast(script->value())->data()); |
| 1787 | return scope.Close(Utils::ToLocal(data)); |
| 1788 | } |
| 1789 | |
| 1790 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1791 | v8::Handle<v8::StackTrace> Message::GetStackTrace() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1792 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1793 | if (IsDeadCheck(isolate, "v8::Message::GetStackTrace()")) { |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1794 | return Local<v8::StackTrace>(); |
| 1795 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1796 | ENTER_V8(isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1797 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1798 | i::Handle<i::JSMessageObject> message = |
| 1799 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1800 | i::Handle<i::Object> stackFramesObj(message->stack_frames()); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1801 | if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); |
| 1802 | i::Handle<i::JSArray> stackTrace = |
| 1803 | i::Handle<i::JSArray>::cast(stackFramesObj); |
| 1804 | return scope.Close(Utils::StackTraceToLocal(stackTrace)); |
| 1805 | } |
| 1806 | |
| 1807 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1808 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 1809 | i::Handle<i::Object> recv, |
| 1810 | int argc, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1811 | i::Handle<i::Object> argv[], |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1812 | bool* has_pending_exception) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1813 | i::Isolate* isolate = i::Isolate::Current(); |
| 1814 | i::Handle<i::String> fmt_str = isolate->factory()->LookupAsciiSymbol(name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1815 | i::Object* object_fun = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1816 | isolate->js_builtins_object()->GetPropertyNoExceptionThrown(*fmt_str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1817 | i::Handle<i::JSFunction> fun = |
| 1818 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun)); |
| 1819 | i::Handle<i::Object> value = |
| 1820 | i::Execution::Call(fun, recv, argc, argv, has_pending_exception); |
| 1821 | return value; |
| 1822 | } |
| 1823 | |
| 1824 | |
| 1825 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 1826 | i::Handle<i::Object> data, |
| 1827 | bool* has_pending_exception) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1828 | i::Handle<i::Object> argv[] = { data }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1829 | return CallV8HeapFunction(name, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1830 | i::Isolate::Current()->js_builtins_object(), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1831 | ARRAY_SIZE(argv), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1832 | argv, |
| 1833 | has_pending_exception); |
| 1834 | } |
| 1835 | |
| 1836 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1837 | int Message::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1838 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1839 | ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1840 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1841 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1842 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1843 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1844 | i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber", |
| 1845 | Utils::OpenHandle(this), |
| 1846 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1847 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1848 | return static_cast<int>(result->Number()); |
| 1849 | } |
| 1850 | |
| 1851 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1852 | int Message::GetStartPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1853 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1854 | if (IsDeadCheck(isolate, "v8::Message::GetStartPosition()")) return 0; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1855 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1856 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1857 | i::Handle<i::JSMessageObject> message = |
| 1858 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1859 | return message->start_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1863 | int Message::GetEndPosition() 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::GetEndPosition()")) return 0; |
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); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1868 | i::Handle<i::JSMessageObject> message = |
| 1869 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1870 | return message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1874 | int Message::GetStartColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1875 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1876 | if (IsDeadCheck(isolate, "v8::Message::GetStartColumn()")) { |
| 1877 | return kNoColumnInfo; |
| 1878 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1879 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1880 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1881 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1882 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1883 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 1884 | "GetPositionInLine", |
| 1885 | data_obj, |
| 1886 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1887 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1888 | return static_cast<int>(start_col_obj->Number()); |
| 1889 | } |
| 1890 | |
| 1891 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1892 | int Message::GetEndColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1893 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1894 | if (IsDeadCheck(isolate, "v8::Message::GetEndColumn()")) return kNoColumnInfo; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1895 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1896 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1897 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1898 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1899 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 1900 | "GetPositionInLine", |
| 1901 | data_obj, |
| 1902 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1903 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1904 | i::Handle<i::JSMessageObject> message = |
| 1905 | i::Handle<i::JSMessageObject>::cast(data_obj); |
| 1906 | int start = message->start_position(); |
| 1907 | int end = message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1908 | return static_cast<int>(start_col_obj->Number()) + (end - start); |
| 1909 | } |
| 1910 | |
| 1911 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1912 | Local<String> Message::GetSourceLine() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1913 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1914 | ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1915 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1916 | HandleScope scope; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1917 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1918 | i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine", |
| 1919 | Utils::OpenHandle(this), |
| 1920 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1921 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::String>()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1922 | if (result->IsString()) { |
| 1923 | return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result))); |
| 1924 | } else { |
| 1925 | return Local<String>(); |
| 1926 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1930 | void Message::PrintCurrentStackTrace(FILE* out) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1931 | i::Isolate* isolate = i::Isolate::Current(); |
| 1932 | if (IsDeadCheck(isolate, "v8::Message::PrintCurrentStackTrace()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1933 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1934 | isolate->PrintCurrentStackTrace(out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1938 | // --- S t a c k T r a c e --- |
| 1939 | |
| 1940 | Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1941 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1942 | if (IsDeadCheck(isolate, "v8::StackTrace::GetFrame()")) { |
| 1943 | return Local<StackFrame>(); |
| 1944 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1945 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1946 | HandleScope scope; |
| 1947 | i::Handle<i::JSArray> self = Utils::OpenHandle(this); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1948 | i::Object* raw_object = self->GetElementNoExceptionThrown(index); |
| 1949 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1950 | return scope.Close(Utils::StackFrameToLocal(obj)); |
| 1951 | } |
| 1952 | |
| 1953 | |
| 1954 | int StackTrace::GetFrameCount() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1955 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1956 | if (IsDeadCheck(isolate, "v8::StackTrace::GetFrameCount()")) return -1; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1957 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1958 | return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); |
| 1959 | } |
| 1960 | |
| 1961 | |
| 1962 | Local<Array> StackTrace::AsArray() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1963 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1964 | if (IsDeadCheck(isolate, "v8::StackTrace::AsArray()")) Local<Array>(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1965 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1966 | return Utils::ToLocal(Utils::OpenHandle(this)); |
| 1967 | } |
| 1968 | |
| 1969 | |
| 1970 | Local<StackTrace> StackTrace::CurrentStackTrace(int frame_limit, |
| 1971 | StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1972 | i::Isolate* isolate = i::Isolate::Current(); |
| 1973 | if (IsDeadCheck(isolate, "v8::StackTrace::CurrentStackTrace()")) { |
| 1974 | Local<StackTrace>(); |
| 1975 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1976 | ENTER_V8(isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1977 | i::Handle<i::JSArray> stackTrace = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1978 | isolate->CaptureCurrentStackTrace(frame_limit, options); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1979 | return Utils::StackTraceToLocal(stackTrace); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | |
| 1983 | // --- S t a c k F r a m e --- |
| 1984 | |
| 1985 | int StackFrame::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1986 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1987 | if (IsDeadCheck(isolate, "v8::StackFrame::GetLineNumber()")) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1988 | return Message::kNoLineNumberInfo; |
| 1989 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1990 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1991 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1992 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 1993 | i::Handle<i::Object> line = GetProperty(self, "lineNumber"); |
| 1994 | if (!line->IsSmi()) { |
| 1995 | return Message::kNoLineNumberInfo; |
| 1996 | } |
| 1997 | return i::Smi::cast(*line)->value(); |
| 1998 | } |
| 1999 | |
| 2000 | |
| 2001 | int StackFrame::GetColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2002 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2003 | if (IsDeadCheck(isolate, "v8::StackFrame::GetColumn()")) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2004 | return Message::kNoColumnInfo; |
| 2005 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2006 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2007 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2008 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2009 | i::Handle<i::Object> column = GetProperty(self, "column"); |
| 2010 | if (!column->IsSmi()) { |
| 2011 | return Message::kNoColumnInfo; |
| 2012 | } |
| 2013 | return i::Smi::cast(*column)->value(); |
| 2014 | } |
| 2015 | |
| 2016 | |
| 2017 | Local<String> StackFrame::GetScriptName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2018 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2019 | if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptName()")) { |
| 2020 | return Local<String>(); |
| 2021 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2022 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2023 | HandleScope scope; |
| 2024 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2025 | i::Handle<i::Object> name = GetProperty(self, "scriptName"); |
| 2026 | if (!name->IsString()) { |
| 2027 | return Local<String>(); |
| 2028 | } |
| 2029 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2030 | } |
| 2031 | |
| 2032 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2033 | Local<String> StackFrame::GetScriptNameOrSourceURL() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2034 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2035 | if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptNameOrSourceURL()")) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2036 | return Local<String>(); |
| 2037 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2038 | ENTER_V8(isolate); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2039 | HandleScope scope; |
| 2040 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2041 | i::Handle<i::Object> name = GetProperty(self, "scriptNameOrSourceURL"); |
| 2042 | if (!name->IsString()) { |
| 2043 | return Local<String>(); |
| 2044 | } |
| 2045 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2046 | } |
| 2047 | |
| 2048 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2049 | Local<String> StackFrame::GetFunctionName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2050 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2051 | if (IsDeadCheck(isolate, "v8::StackFrame::GetFunctionName()")) { |
| 2052 | return Local<String>(); |
| 2053 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2054 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2055 | HandleScope scope; |
| 2056 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2057 | i::Handle<i::Object> name = GetProperty(self, "functionName"); |
| 2058 | if (!name->IsString()) { |
| 2059 | return Local<String>(); |
| 2060 | } |
| 2061 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2062 | } |
| 2063 | |
| 2064 | |
| 2065 | bool StackFrame::IsEval() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2066 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2067 | if (IsDeadCheck(isolate, "v8::StackFrame::IsEval()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2068 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2069 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2070 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2071 | i::Handle<i::Object> is_eval = GetProperty(self, "isEval"); |
| 2072 | return is_eval->IsTrue(); |
| 2073 | } |
| 2074 | |
| 2075 | |
| 2076 | bool StackFrame::IsConstructor() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2077 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2078 | if (IsDeadCheck(isolate, "v8::StackFrame::IsConstructor()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2079 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2080 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2081 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2082 | i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor"); |
| 2083 | return is_constructor->IsTrue(); |
| 2084 | } |
| 2085 | |
| 2086 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2087 | // --- D a t a --- |
| 2088 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2089 | bool Value::IsUndefined() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2090 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUndefined()")) { |
| 2091 | return false; |
| 2092 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2093 | return Utils::OpenHandle(this)->IsUndefined(); |
| 2094 | } |
| 2095 | |
| 2096 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2097 | bool Value::IsNull() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2098 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNull()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2099 | return Utils::OpenHandle(this)->IsNull(); |
| 2100 | } |
| 2101 | |
| 2102 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2103 | bool Value::IsTrue() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2104 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsTrue()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2105 | return Utils::OpenHandle(this)->IsTrue(); |
| 2106 | } |
| 2107 | |
| 2108 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2109 | bool Value::IsFalse() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2110 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFalse()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2111 | return Utils::OpenHandle(this)->IsFalse(); |
| 2112 | } |
| 2113 | |
| 2114 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2115 | bool Value::IsFunction() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2116 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFunction()")) { |
| 2117 | return false; |
| 2118 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2119 | return Utils::OpenHandle(this)->IsJSFunction(); |
| 2120 | } |
| 2121 | |
| 2122 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2123 | bool Value::FullIsString() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2124 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsString()")) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2125 | bool result = Utils::OpenHandle(this)->IsString(); |
| 2126 | ASSERT_EQ(result, QuickIsString()); |
| 2127 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2131 | bool Value::IsArray() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2132 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArray()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2133 | return Utils::OpenHandle(this)->IsJSArray(); |
| 2134 | } |
| 2135 | |
| 2136 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2137 | bool Value::IsObject() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2138 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2139 | return Utils::OpenHandle(this)->IsJSObject(); |
| 2140 | } |
| 2141 | |
| 2142 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2143 | bool Value::IsNumber() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2144 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2145 | return Utils::OpenHandle(this)->IsNumber(); |
| 2146 | } |
| 2147 | |
| 2148 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2149 | bool Value::IsBoolean() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2150 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsBoolean()")) { |
| 2151 | return false; |
| 2152 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2153 | return Utils::OpenHandle(this)->IsBoolean(); |
| 2154 | } |
| 2155 | |
| 2156 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2157 | bool Value::IsExternal() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2158 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsExternal()")) { |
| 2159 | return false; |
| 2160 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2161 | return Utils::OpenHandle(this)->IsForeign(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2165 | bool Value::IsInt32() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2166 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsInt32()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2167 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2168 | if (obj->IsSmi()) return true; |
| 2169 | if (obj->IsNumber()) { |
| 2170 | double value = obj->Number(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2171 | static const i::DoubleRepresentation minus_zero(-0.0); |
| 2172 | i::DoubleRepresentation rep(value); |
| 2173 | if (rep.bits == minus_zero.bits) { |
| 2174 | return false; |
| 2175 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2176 | return i::FastI2D(i::FastD2I(value)) == value; |
| 2177 | } |
| 2178 | return false; |
| 2179 | } |
| 2180 | |
| 2181 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2182 | bool Value::IsUint32() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2183 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUint32()")) return false; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2184 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2185 | if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0; |
| 2186 | if (obj->IsNumber()) { |
| 2187 | double value = obj->Number(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2188 | static const i::DoubleRepresentation minus_zero(-0.0); |
| 2189 | i::DoubleRepresentation rep(value); |
| 2190 | if (rep.bits == minus_zero.bits) { |
| 2191 | return false; |
| 2192 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2193 | return i::FastUI2D(i::FastD2UI(value)) == value; |
| 2194 | } |
| 2195 | return false; |
| 2196 | } |
| 2197 | |
| 2198 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2199 | bool Value::IsDate() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2200 | i::Isolate* isolate = i::Isolate::Current(); |
| 2201 | if (IsDeadCheck(isolate, "v8::Value::IsDate()")) return false; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2202 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2203 | return obj->HasSpecificClassOf(isolate->heap()->Date_symbol()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2207 | bool Value::IsStringObject() const { |
| 2208 | i::Isolate* isolate = i::Isolate::Current(); |
| 2209 | if (IsDeadCheck(isolate, "v8::Value::IsStringObject()")) return false; |
| 2210 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2211 | return obj->HasSpecificClassOf(isolate->heap()->String_symbol()); |
| 2212 | } |
| 2213 | |
| 2214 | |
| 2215 | bool Value::IsNumberObject() const { |
| 2216 | i::Isolate* isolate = i::Isolate::Current(); |
| 2217 | if (IsDeadCheck(isolate, "v8::Value::IsNumberObject()")) return false; |
| 2218 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2219 | return obj->HasSpecificClassOf(isolate->heap()->Number_symbol()); |
| 2220 | } |
| 2221 | |
| 2222 | |
| 2223 | static i::Object* LookupBuiltin(i::Isolate* isolate, |
| 2224 | const char* builtin_name) { |
| 2225 | i::Handle<i::String> symbol = |
| 2226 | isolate->factory()->LookupAsciiSymbol(builtin_name); |
| 2227 | i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object(); |
| 2228 | return builtins->GetPropertyNoExceptionThrown(*symbol); |
| 2229 | } |
| 2230 | |
| 2231 | |
| 2232 | static bool CheckConstructor(i::Isolate* isolate, |
| 2233 | i::Handle<i::JSObject> obj, |
| 2234 | const char* class_name) { |
| 2235 | return obj->map()->constructor() == LookupBuiltin(isolate, class_name); |
| 2236 | } |
| 2237 | |
| 2238 | |
| 2239 | bool Value::IsNativeError() const { |
| 2240 | i::Isolate* isolate = i::Isolate::Current(); |
| 2241 | if (IsDeadCheck(isolate, "v8::Value::IsNativeError()")) return false; |
| 2242 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2243 | if (obj->IsJSObject()) { |
| 2244 | i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj)); |
| 2245 | return CheckConstructor(isolate, js_obj, "$Error") || |
| 2246 | CheckConstructor(isolate, js_obj, "$EvalError") || |
| 2247 | CheckConstructor(isolate, js_obj, "$RangeError") || |
| 2248 | CheckConstructor(isolate, js_obj, "$ReferenceError") || |
| 2249 | CheckConstructor(isolate, js_obj, "$SyntaxError") || |
| 2250 | CheckConstructor(isolate, js_obj, "$TypeError") || |
| 2251 | CheckConstructor(isolate, js_obj, "$URIError"); |
| 2252 | } else { |
| 2253 | return false; |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | |
| 2258 | bool Value::IsBooleanObject() const { |
| 2259 | i::Isolate* isolate = i::Isolate::Current(); |
| 2260 | if (IsDeadCheck(isolate, "v8::Value::IsBooleanObject()")) return false; |
| 2261 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2262 | return obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol()); |
| 2263 | } |
| 2264 | |
| 2265 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2266 | bool Value::IsRegExp() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2267 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsRegExp()")) return false; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2268 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2269 | return obj->IsJSRegExp(); |
| 2270 | } |
| 2271 | |
| 2272 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2273 | Local<String> Value::ToString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2274 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2275 | i::Handle<i::Object> str; |
| 2276 | if (obj->IsString()) { |
| 2277 | str = obj; |
| 2278 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2279 | i::Isolate* isolate = i::Isolate::Current(); |
| 2280 | if (IsDeadCheck(isolate, "v8::Value::ToString()")) { |
| 2281 | return Local<String>(); |
| 2282 | } |
| 2283 | LOG_API(isolate, "ToString"); |
| 2284 | ENTER_V8(isolate); |
| 2285 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2286 | str = i::Execution::ToString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2287 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2288 | } |
| 2289 | return Local<String>(ToApi<String>(str)); |
| 2290 | } |
| 2291 | |
| 2292 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2293 | Local<String> Value::ToDetailString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2294 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2295 | i::Handle<i::Object> str; |
| 2296 | if (obj->IsString()) { |
| 2297 | str = 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::ToDetailString()")) { |
| 2301 | return Local<String>(); |
| 2302 | } |
| 2303 | LOG_API(isolate, "ToDetailString"); |
| 2304 | ENTER_V8(isolate); |
| 2305 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2306 | str = i::Execution::ToDetailString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2307 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2308 | } |
| 2309 | return Local<String>(ToApi<String>(str)); |
| 2310 | } |
| 2311 | |
| 2312 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2313 | Local<v8::Object> Value::ToObject() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2314 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2315 | i::Handle<i::Object> val; |
| 2316 | if (obj->IsJSObject()) { |
| 2317 | val = obj; |
| 2318 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2319 | i::Isolate* isolate = i::Isolate::Current(); |
| 2320 | if (IsDeadCheck(isolate, "v8::Value::ToObject()")) { |
| 2321 | return Local<v8::Object>(); |
| 2322 | } |
| 2323 | LOG_API(isolate, "ToObject"); |
| 2324 | ENTER_V8(isolate); |
| 2325 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2326 | val = i::Execution::ToObject(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2327 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2328 | } |
| 2329 | return Local<v8::Object>(ToApi<Object>(val)); |
| 2330 | } |
| 2331 | |
| 2332 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2333 | Local<Boolean> Value::ToBoolean() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2334 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2335 | if (obj->IsBoolean()) { |
| 2336 | return Local<Boolean>(ToApi<Boolean>(obj)); |
| 2337 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2338 | i::Isolate* isolate = i::Isolate::Current(); |
| 2339 | if (IsDeadCheck(isolate, "v8::Value::ToBoolean()")) { |
| 2340 | return Local<Boolean>(); |
| 2341 | } |
| 2342 | LOG_API(isolate, "ToBoolean"); |
| 2343 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2344 | i::Handle<i::Object> val = i::Execution::ToBoolean(obj); |
| 2345 | return Local<Boolean>(ToApi<Boolean>(val)); |
| 2346 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2350 | Local<Number> Value::ToNumber() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2351 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2352 | i::Handle<i::Object> num; |
| 2353 | if (obj->IsNumber()) { |
| 2354 | num = obj; |
| 2355 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2356 | i::Isolate* isolate = i::Isolate::Current(); |
| 2357 | if (IsDeadCheck(isolate, "v8::Value::ToNumber()")) { |
| 2358 | return Local<Number>(); |
| 2359 | } |
| 2360 | LOG_API(isolate, "ToNumber"); |
| 2361 | ENTER_V8(isolate); |
| 2362 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2363 | num = i::Execution::ToNumber(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2364 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Number>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2365 | } |
| 2366 | return Local<Number>(ToApi<Number>(num)); |
| 2367 | } |
| 2368 | |
| 2369 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2370 | Local<Integer> Value::ToInteger() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2371 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2372 | i::Handle<i::Object> num; |
| 2373 | if (obj->IsSmi()) { |
| 2374 | num = obj; |
| 2375 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2376 | i::Isolate* isolate = i::Isolate::Current(); |
| 2377 | if (IsDeadCheck(isolate, "v8::Value::ToInteger()")) return Local<Integer>(); |
| 2378 | LOG_API(isolate, "ToInteger"); |
| 2379 | ENTER_V8(isolate); |
| 2380 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2381 | num = i::Execution::ToInteger(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2382 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2383 | } |
| 2384 | return Local<Integer>(ToApi<Integer>(num)); |
| 2385 | } |
| 2386 | |
| 2387 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2388 | void External::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2389 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2390 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2391 | ApiCheck(obj->IsForeign(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2392 | "v8::External::Cast()", |
| 2393 | "Could not convert to external"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2397 | void v8::Object::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2398 | if (IsDeadCheck(i::Isolate::Current(), "v8::Object::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2399 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2400 | ApiCheck(obj->IsJSObject(), |
| 2401 | "v8::Object::Cast()", |
| 2402 | "Could not convert to object"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2406 | void v8::Function::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2407 | if (IsDeadCheck(i::Isolate::Current(), "v8::Function::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2408 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2409 | ApiCheck(obj->IsJSFunction(), |
| 2410 | "v8::Function::Cast()", |
| 2411 | "Could not convert to function"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2415 | void v8::String::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2416 | if (IsDeadCheck(i::Isolate::Current(), "v8::String::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2417 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2418 | ApiCheck(obj->IsString(), |
| 2419 | "v8::String::Cast()", |
| 2420 | "Could not convert to string"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2424 | void v8::Number::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2425 | if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2426 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2427 | ApiCheck(obj->IsNumber(), |
| 2428 | "v8::Number::Cast()", |
| 2429 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2433 | void v8::Integer::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2434 | if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2435 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2436 | ApiCheck(obj->IsNumber(), |
| 2437 | "v8::Integer::Cast()", |
| 2438 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2442 | void v8::Array::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2443 | if (IsDeadCheck(i::Isolate::Current(), "v8::Array::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2444 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2445 | ApiCheck(obj->IsJSArray(), |
| 2446 | "v8::Array::Cast()", |
| 2447 | "Could not convert to array"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2451 | void v8::Date::CheckCast(v8::Value* that) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2452 | i::Isolate* isolate = i::Isolate::Current(); |
| 2453 | if (IsDeadCheck(isolate, "v8::Date::Cast()")) return; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2454 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2455 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_symbol()), |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2456 | "v8::Date::Cast()", |
| 2457 | "Could not convert to date"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2461 | void v8::StringObject::CheckCast(v8::Value* that) { |
| 2462 | i::Isolate* isolate = i::Isolate::Current(); |
| 2463 | if (IsDeadCheck(isolate, "v8::StringObject::Cast()")) return; |
| 2464 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2465 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->String_symbol()), |
| 2466 | "v8::StringObject::Cast()", |
| 2467 | "Could not convert to StringObject"); |
| 2468 | } |
| 2469 | |
| 2470 | |
| 2471 | void v8::NumberObject::CheckCast(v8::Value* that) { |
| 2472 | i::Isolate* isolate = i::Isolate::Current(); |
| 2473 | if (IsDeadCheck(isolate, "v8::NumberObject::Cast()")) return; |
| 2474 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2475 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Number_symbol()), |
| 2476 | "v8::NumberObject::Cast()", |
| 2477 | "Could not convert to NumberObject"); |
| 2478 | } |
| 2479 | |
| 2480 | |
| 2481 | void v8::BooleanObject::CheckCast(v8::Value* that) { |
| 2482 | i::Isolate* isolate = i::Isolate::Current(); |
| 2483 | if (IsDeadCheck(isolate, "v8::BooleanObject::Cast()")) return; |
| 2484 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2485 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol()), |
| 2486 | "v8::BooleanObject::Cast()", |
| 2487 | "Could not convert to BooleanObject"); |
| 2488 | } |
| 2489 | |
| 2490 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2491 | void v8::RegExp::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2492 | if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::Cast()")) return; |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2493 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2494 | ApiCheck(obj->IsJSRegExp(), |
| 2495 | "v8::RegExp::Cast()", |
| 2496 | "Could not convert to regular expression"); |
| 2497 | } |
| 2498 | |
| 2499 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2500 | bool Value::BooleanValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2501 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2502 | if (obj->IsBoolean()) { |
| 2503 | return obj->IsTrue(); |
| 2504 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2505 | i::Isolate* isolate = i::Isolate::Current(); |
| 2506 | if (IsDeadCheck(isolate, "v8::Value::BooleanValue()")) return false; |
| 2507 | LOG_API(isolate, "BooleanValue"); |
| 2508 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2509 | i::Handle<i::Object> value = i::Execution::ToBoolean(obj); |
| 2510 | return value->IsTrue(); |
| 2511 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2515 | double Value::NumberValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2516 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2517 | i::Handle<i::Object> num; |
| 2518 | if (obj->IsNumber()) { |
| 2519 | num = obj; |
| 2520 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2521 | i::Isolate* isolate = i::Isolate::Current(); |
| 2522 | if (IsDeadCheck(isolate, "v8::Value::NumberValue()")) { |
| 2523 | return i::OS::nan_value(); |
| 2524 | } |
| 2525 | LOG_API(isolate, "NumberValue"); |
| 2526 | ENTER_V8(isolate); |
| 2527 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2528 | num = i::Execution::ToNumber(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2529 | EXCEPTION_BAILOUT_CHECK(isolate, i::OS::nan_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2530 | } |
| 2531 | return num->Number(); |
| 2532 | } |
| 2533 | |
| 2534 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2535 | int64_t Value::IntegerValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2536 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2537 | i::Handle<i::Object> num; |
| 2538 | if (obj->IsNumber()) { |
| 2539 | num = obj; |
| 2540 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2541 | i::Isolate* isolate = i::Isolate::Current(); |
| 2542 | if (IsDeadCheck(isolate, "v8::Value::IntegerValue()")) return 0; |
| 2543 | LOG_API(isolate, "IntegerValue"); |
| 2544 | ENTER_V8(isolate); |
| 2545 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2546 | num = i::Execution::ToInteger(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2547 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2548 | } |
| 2549 | if (num->IsSmi()) { |
| 2550 | return i::Smi::cast(*num)->value(); |
| 2551 | } else { |
| 2552 | return static_cast<int64_t>(num->Number()); |
| 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2557 | Local<Int32> Value::ToInt32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2558 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2559 | i::Handle<i::Object> num; |
| 2560 | if (obj->IsSmi()) { |
| 2561 | num = obj; |
| 2562 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2563 | i::Isolate* isolate = i::Isolate::Current(); |
| 2564 | if (IsDeadCheck(isolate, "v8::Value::ToInt32()")) return Local<Int32>(); |
| 2565 | LOG_API(isolate, "ToInt32"); |
| 2566 | ENTER_V8(isolate); |
| 2567 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2568 | num = i::Execution::ToInt32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2569 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Int32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2570 | } |
| 2571 | return Local<Int32>(ToApi<Int32>(num)); |
| 2572 | } |
| 2573 | |
| 2574 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2575 | Local<Uint32> Value::ToUint32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2576 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2577 | i::Handle<i::Object> num; |
| 2578 | if (obj->IsSmi()) { |
| 2579 | num = obj; |
| 2580 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2581 | i::Isolate* isolate = i::Isolate::Current(); |
| 2582 | if (IsDeadCheck(isolate, "v8::Value::ToUint32()")) return Local<Uint32>(); |
| 2583 | LOG_API(isolate, "ToUInt32"); |
| 2584 | ENTER_V8(isolate); |
| 2585 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2586 | num = i::Execution::ToUint32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2587 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2588 | } |
| 2589 | return Local<Uint32>(ToApi<Uint32>(num)); |
| 2590 | } |
| 2591 | |
| 2592 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2593 | Local<Uint32> Value::ToArrayIndex() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2594 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2595 | if (obj->IsSmi()) { |
| 2596 | if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj); |
| 2597 | return Local<Uint32>(); |
| 2598 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2599 | i::Isolate* isolate = i::Isolate::Current(); |
| 2600 | if (IsDeadCheck(isolate, "v8::Value::ToArrayIndex()")) return Local<Uint32>(); |
| 2601 | LOG_API(isolate, "ToArrayIndex"); |
| 2602 | ENTER_V8(isolate); |
| 2603 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2604 | i::Handle<i::Object> string_obj = |
| 2605 | i::Execution::ToString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2606 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2607 | i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); |
| 2608 | uint32_t index; |
| 2609 | if (str->AsArrayIndex(&index)) { |
| 2610 | i::Handle<i::Object> value; |
| 2611 | if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) { |
| 2612 | value = i::Handle<i::Object>(i::Smi::FromInt(index)); |
| 2613 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2614 | value = isolate->factory()->NewNumber(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2615 | } |
| 2616 | return Utils::Uint32ToLocal(value); |
| 2617 | } |
| 2618 | return Local<Uint32>(); |
| 2619 | } |
| 2620 | |
| 2621 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2622 | int32_t Value::Int32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2623 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2624 | if (obj->IsSmi()) { |
| 2625 | return i::Smi::cast(*obj)->value(); |
| 2626 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2627 | i::Isolate* isolate = i::Isolate::Current(); |
| 2628 | if (IsDeadCheck(isolate, "v8::Value::Int32Value()")) return 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2629 | LOG_API(isolate, "Int32Value (slow)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2630 | ENTER_V8(isolate); |
| 2631 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2632 | i::Handle<i::Object> num = |
| 2633 | i::Execution::ToInt32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2634 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2635 | if (num->IsSmi()) { |
| 2636 | return i::Smi::cast(*num)->value(); |
| 2637 | } else { |
| 2638 | return static_cast<int32_t>(num->Number()); |
| 2639 | } |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2644 | bool Value::Equals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2645 | i::Isolate* isolate = i::Isolate::Current(); |
| 2646 | if (IsDeadCheck(isolate, "v8::Value::Equals()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2647 | || EmptyCheck("v8::Value::Equals()", this) |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2648 | || EmptyCheck("v8::Value::Equals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2649 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2650 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2651 | LOG_API(isolate, "Equals"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2652 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2653 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2654 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2655 | // If both obj and other are JSObjects, we'd better compare by identity |
| 2656 | // immediately when going into JS builtin. The reason is Invoke |
| 2657 | // would overwrite global object receiver with global proxy. |
| 2658 | if (obj->IsJSObject() && other->IsJSObject()) { |
| 2659 | return *obj == *other; |
| 2660 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2661 | i::Handle<i::Object> args[] = { other }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2662 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2663 | i::Handle<i::Object> result = |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2664 | CallV8HeapFunction("EQUALS", obj, ARRAY_SIZE(args), args, |
| 2665 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2666 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2667 | return *result == i::Smi::FromInt(i::EQUAL); |
| 2668 | } |
| 2669 | |
| 2670 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2671 | bool Value::StrictEquals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2672 | i::Isolate* isolate = i::Isolate::Current(); |
| 2673 | if (IsDeadCheck(isolate, "v8::Value::StrictEquals()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2674 | || EmptyCheck("v8::Value::StrictEquals()", this) |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2675 | || EmptyCheck("v8::Value::StrictEquals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2676 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2677 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2678 | LOG_API(isolate, "StrictEquals"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2679 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2680 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
| 2681 | // Must check HeapNumber first, since NaN !== NaN. |
| 2682 | if (obj->IsHeapNumber()) { |
| 2683 | if (!other->IsNumber()) return false; |
| 2684 | double x = obj->Number(); |
| 2685 | double y = other->Number(); |
| 2686 | // Must check explicitly for NaN:s on Windows, but -0 works fine. |
| 2687 | return x == y && !isnan(x) && !isnan(y); |
| 2688 | } else if (*obj == *other) { // Also covers Booleans. |
| 2689 | return true; |
| 2690 | } else if (obj->IsSmi()) { |
| 2691 | return other->IsNumber() && obj->Number() == other->Number(); |
| 2692 | } else if (obj->IsString()) { |
| 2693 | return other->IsString() && |
| 2694 | i::String::cast(*obj)->Equals(i::String::cast(*other)); |
| 2695 | } else if (obj->IsUndefined() || obj->IsUndetectableObject()) { |
| 2696 | return other->IsUndefined() || other->IsUndetectableObject(); |
| 2697 | } else { |
| 2698 | return false; |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2703 | uint32_t Value::Uint32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2704 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2705 | if (obj->IsSmi()) { |
| 2706 | return i::Smi::cast(*obj)->value(); |
| 2707 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2708 | i::Isolate* isolate = i::Isolate::Current(); |
| 2709 | if (IsDeadCheck(isolate, "v8::Value::Uint32Value()")) return 0; |
| 2710 | LOG_API(isolate, "Uint32Value"); |
| 2711 | ENTER_V8(isolate); |
| 2712 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2713 | i::Handle<i::Object> num = |
| 2714 | i::Execution::ToUint32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2715 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2716 | if (num->IsSmi()) { |
| 2717 | return i::Smi::cast(*num)->value(); |
| 2718 | } else { |
| 2719 | return static_cast<uint32_t>(num->Number()); |
| 2720 | } |
| 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | |
| 2725 | 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] | 2726 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2727 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2728 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2729 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2730 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2731 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 2732 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2733 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2734 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2735 | i::Handle<i::Object> obj = i::SetProperty( |
| 2736 | self, |
| 2737 | key_obj, |
| 2738 | value_obj, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2739 | static_cast<PropertyAttributes>(attribs), |
| 2740 | i::kNonStrictMode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2741 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2742 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2743 | return true; |
| 2744 | } |
| 2745 | |
| 2746 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2747 | bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2748 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2749 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2750 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2751 | i::HandleScope scope(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2752 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2753 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2754 | EXCEPTION_PREAMBLE(isolate); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2755 | i::Handle<i::Object> obj = i::JSObject::SetElement( |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2756 | self, |
| 2757 | index, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2758 | value_obj, |
| 2759 | i::kNonStrictMode); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2760 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2761 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2762 | return true; |
| 2763 | } |
| 2764 | |
| 2765 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2766 | bool v8::Object::ForceSet(v8::Handle<Value> key, |
| 2767 | v8::Handle<Value> value, |
| 2768 | v8::PropertyAttribute attribs) { |
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::ForceSet()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2771 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2772 | i::HandleScope scope(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2773 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2774 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2775 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2776 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2777 | i::Handle<i::Object> obj = i::ForceSetProperty( |
| 2778 | self, |
| 2779 | key_obj, |
| 2780 | value_obj, |
| 2781 | static_cast<PropertyAttributes>(attribs)); |
| 2782 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2783 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2784 | return true; |
| 2785 | } |
| 2786 | |
| 2787 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2788 | bool v8::Object::ForceDelete(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2789 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2790 | ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2791 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2792 | i::HandleScope scope(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2793 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2794 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2795 | |
| 2796 | // When turning on access checks for a global object deoptimize all functions |
| 2797 | // as optimized code does not always handle access checks. |
| 2798 | i::Deoptimizer::DeoptimizeGlobalObject(*self); |
| 2799 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2800 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2801 | i::Handle<i::Object> obj = i::ForceDeleteProperty(self, key_obj); |
| 2802 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2803 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2804 | return obj->IsTrue(); |
| 2805 | } |
| 2806 | |
| 2807 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2808 | Local<Value> v8::Object::Get(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2809 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2810 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2811 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2812 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 2813 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2814 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2815 | i::Handle<i::Object> result = i::GetProperty(self, key_obj); |
| 2816 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2817 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2818 | return Utils::ToLocal(result); |
| 2819 | } |
| 2820 | |
| 2821 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2822 | Local<Value> v8::Object::Get(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2823 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2824 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2825 | ENTER_V8(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2826 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2827 | EXCEPTION_PREAMBLE(isolate); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2828 | i::Handle<i::Object> result = i::Object::GetElement(self, index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2829 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2830 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2831 | return Utils::ToLocal(result); |
| 2832 | } |
| 2833 | |
| 2834 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2835 | PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { |
| 2836 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2837 | ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()", |
| 2838 | return static_cast<PropertyAttribute>(NONE)); |
| 2839 | ENTER_V8(isolate); |
| 2840 | i::HandleScope scope(isolate); |
| 2841 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2842 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2843 | if (!key_obj->IsString()) { |
| 2844 | EXCEPTION_PREAMBLE(isolate); |
| 2845 | key_obj = i::Execution::ToString(key_obj, &has_pending_exception); |
| 2846 | EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE)); |
| 2847 | } |
| 2848 | i::Handle<i::String> key_string = i::Handle<i::String>::cast(key_obj); |
| 2849 | PropertyAttributes result = self->GetPropertyAttribute(*key_string); |
| 2850 | if (result == ABSENT) return static_cast<PropertyAttribute>(NONE); |
| 2851 | return static_cast<PropertyAttribute>(result); |
| 2852 | } |
| 2853 | |
| 2854 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2855 | Local<Value> v8::Object::GetPrototype() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2856 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2857 | ON_BAILOUT(isolate, "v8::Object::GetPrototype()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2858 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2859 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2860 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2861 | i::Handle<i::Object> result(self->GetPrototype()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2862 | return Utils::ToLocal(result); |
| 2863 | } |
| 2864 | |
| 2865 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2866 | bool v8::Object::SetPrototype(Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2867 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2868 | ON_BAILOUT(isolate, "v8::Object::SetPrototype()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2869 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2870 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2871 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2872 | // We do not allow exceptions thrown while setting the prototype |
| 2873 | // to propagate outside. |
| 2874 | TryCatch try_catch; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2875 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2876 | i::Handle<i::Object> result = i::SetPrototype(self, value_obj); |
| 2877 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2878 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2879 | return true; |
| 2880 | } |
| 2881 | |
| 2882 | |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2883 | Local<Object> v8::Object::FindInstanceInPrototypeChain( |
| 2884 | v8::Handle<FunctionTemplate> tmpl) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2885 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2886 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2887 | "v8::Object::FindInstanceInPrototypeChain()", |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2888 | return Local<v8::Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2889 | ENTER_V8(isolate); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2890 | i::JSObject* object = *Utils::OpenHandle(this); |
| 2891 | i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl); |
| 2892 | while (!object->IsInstanceOf(tmpl_info)) { |
| 2893 | i::Object* prototype = object->GetPrototype(); |
| 2894 | if (!prototype->IsJSObject()) return Local<Object>(); |
| 2895 | object = i::JSObject::cast(prototype); |
| 2896 | } |
| 2897 | return Utils::ToLocal(i::Handle<i::JSObject>(object)); |
| 2898 | } |
| 2899 | |
| 2900 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2901 | Local<Array> v8::Object::GetPropertyNames() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2902 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2903 | ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()", |
| 2904 | return Local<v8::Array>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2905 | ENTER_V8(isolate); |
| 2906 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2907 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2908 | bool threw = false; |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2909 | i::Handle<i::FixedArray> value = |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2910 | i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS, &threw); |
| 2911 | if (threw) return Local<v8::Array>(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2912 | // Because we use caching to speed up enumeration it is important |
| 2913 | // to never change the result of the basic enumeration function so |
| 2914 | // we clone the result. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2915 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 2916 | i::Handle<i::JSArray> result = |
| 2917 | isolate->factory()->NewJSArrayWithElements(elms); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2918 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2922 | Local<Array> v8::Object::GetOwnPropertyNames() { |
| 2923 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2924 | ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()", |
| 2925 | return Local<v8::Array>()); |
| 2926 | ENTER_V8(isolate); |
| 2927 | i::HandleScope scope(isolate); |
| 2928 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2929 | bool threw = false; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2930 | i::Handle<i::FixedArray> value = |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2931 | i::GetKeysInFixedArrayFor(self, i::LOCAL_ONLY, &threw); |
| 2932 | if (threw) return Local<v8::Array>(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2933 | // Because we use caching to speed up enumeration it is important |
| 2934 | // to never change the result of the basic enumeration function so |
| 2935 | // we clone the result. |
| 2936 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 2937 | i::Handle<i::JSArray> result = |
| 2938 | isolate->factory()->NewJSArrayWithElements(elms); |
| 2939 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
| 2940 | } |
| 2941 | |
| 2942 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2943 | Local<String> v8::Object::ObjectProtoToString() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2944 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2945 | ON_BAILOUT(isolate, "v8::Object::ObjectProtoToString()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2946 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2947 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2948 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2949 | |
| 2950 | i::Handle<i::Object> name(self->class_name()); |
| 2951 | |
| 2952 | // Native implementation of Object.prototype.toString (v8natives.js): |
| 2953 | // var c = %ClassOf(this); |
| 2954 | // if (c === 'Arguments') c = 'Object'; |
| 2955 | // return "[object " + c + "]"; |
| 2956 | |
| 2957 | if (!name->IsString()) { |
| 2958 | return v8::String::New("[object ]"); |
| 2959 | |
| 2960 | } else { |
| 2961 | i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); |
| 2962 | if (class_name->IsEqualTo(i::CStrVector("Arguments"))) { |
| 2963 | return v8::String::New("[object Object]"); |
| 2964 | |
| 2965 | } else { |
| 2966 | const char* prefix = "[object "; |
| 2967 | Local<String> str = Utils::ToLocal(class_name); |
| 2968 | const char* postfix = "]"; |
| 2969 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2970 | int prefix_len = i::StrLength(prefix); |
| 2971 | int str_len = str->Length(); |
| 2972 | int postfix_len = i::StrLength(postfix); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2973 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2974 | int buf_len = prefix_len + str_len + postfix_len; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2975 | i::ScopedVector<char> buf(buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2976 | |
| 2977 | // Write prefix. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2978 | char* ptr = buf.start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2979 | memcpy(ptr, prefix, prefix_len * v8::internal::kCharSize); |
| 2980 | ptr += prefix_len; |
| 2981 | |
| 2982 | // Write real content. |
| 2983 | str->WriteAscii(ptr, 0, str_len); |
| 2984 | ptr += str_len; |
| 2985 | |
| 2986 | // Write postfix. |
| 2987 | memcpy(ptr, postfix, postfix_len * v8::internal::kCharSize); |
| 2988 | |
| 2989 | // Copy the buffer into a heap-allocated string and return it. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2990 | Local<String> result = v8::String::New(buf.start(), buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2991 | return result; |
| 2992 | } |
| 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2997 | Local<String> v8::Object::GetConstructorName() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2998 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2999 | ON_BAILOUT(isolate, "v8::Object::GetConstructorName()", |
| 3000 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3001 | ENTER_V8(isolate); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 3002 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3003 | i::Handle<i::String> name(self->constructor_name()); |
| 3004 | return Utils::ToLocal(name); |
| 3005 | } |
| 3006 | |
| 3007 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3008 | bool v8::Object::Delete(v8::Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3009 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3010 | ON_BAILOUT(isolate, "v8::Object::Delete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3011 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3012 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3013 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3014 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3015 | return i::JSObject::DeleteProperty(self, key_obj)->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | |
| 3019 | bool v8::Object::Has(v8::Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3020 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3021 | ON_BAILOUT(isolate, "v8::Object::Has()", return false); |
| 3022 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3023 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3024 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
| 3025 | return self->HasProperty(*key_obj); |
| 3026 | } |
| 3027 | |
| 3028 | |
| 3029 | bool v8::Object::Delete(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3030 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3031 | ON_BAILOUT(isolate, "v8::Object::DeleteProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3032 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3033 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3034 | HandleScope scope; |
| 3035 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3036 | return i::JSObject::DeleteElement(self, index)->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | |
| 3040 | bool v8::Object::Has(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3041 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3042 | ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3043 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3044 | return self->HasElement(index); |
| 3045 | } |
| 3046 | |
| 3047 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3048 | bool Object::SetAccessor(Handle<String> name, |
| 3049 | AccessorGetter getter, |
| 3050 | AccessorSetter setter, |
| 3051 | v8::Handle<Value> data, |
| 3052 | AccessControl settings, |
| 3053 | PropertyAttribute attributes) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3054 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3055 | ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3056 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3057 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3058 | i::Handle<i::AccessorInfo> info = MakeAccessorInfo(name, |
| 3059 | getter, setter, data, |
| 3060 | settings, attributes); |
| 3061 | i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(this), info); |
| 3062 | return !result.is_null() && !result->IsUndefined(); |
| 3063 | } |
| 3064 | |
| 3065 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3066 | bool v8::Object::HasOwnProperty(Handle<String> key) { |
| 3067 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3068 | ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", |
| 3069 | return false); |
| 3070 | return Utils::OpenHandle(this)->HasLocalProperty( |
| 3071 | *Utils::OpenHandle(*key)); |
| 3072 | } |
| 3073 | |
| 3074 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3075 | bool v8::Object::HasRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3076 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3077 | ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3078 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3079 | return Utils::OpenHandle(this)->HasRealNamedProperty( |
| 3080 | *Utils::OpenHandle(*key)); |
| 3081 | } |
| 3082 | |
| 3083 | |
| 3084 | bool v8::Object::HasRealIndexedProperty(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3085 | ON_BAILOUT(Utils::OpenHandle(this)->GetIsolate(), |
| 3086 | "v8::Object::HasRealIndexedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3087 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3088 | return Utils::OpenHandle(this)->HasRealElementProperty(index); |
| 3089 | } |
| 3090 | |
| 3091 | |
| 3092 | bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3093 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3094 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3095 | "v8::Object::HasRealNamedCallbackProperty()", |
| 3096 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3097 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3098 | return Utils::OpenHandle(this)->HasRealNamedCallbackProperty( |
| 3099 | *Utils::OpenHandle(*key)); |
| 3100 | } |
| 3101 | |
| 3102 | |
| 3103 | bool v8::Object::HasNamedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3104 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3105 | ON_BAILOUT(isolate, "v8::Object::HasNamedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3106 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3107 | return Utils::OpenHandle(this)->HasNamedInterceptor(); |
| 3108 | } |
| 3109 | |
| 3110 | |
| 3111 | bool v8::Object::HasIndexedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3112 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3113 | ON_BAILOUT(isolate, "v8::Object::HasIndexedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3114 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3115 | return Utils::OpenHandle(this)->HasIndexedInterceptor(); |
| 3116 | } |
| 3117 | |
| 3118 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3119 | static Local<Value> GetPropertyByLookup(i::Isolate* isolate, |
| 3120 | i::Handle<i::JSObject> receiver, |
| 3121 | i::Handle<i::String> name, |
| 3122 | i::LookupResult* lookup) { |
| 3123 | if (!lookup->IsProperty()) { |
| 3124 | // No real property was found. |
| 3125 | return Local<Value>(); |
| 3126 | } |
| 3127 | |
| 3128 | // If the property being looked up is a callback, it can throw |
| 3129 | // an exception. |
| 3130 | EXCEPTION_PREAMBLE(isolate); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3131 | PropertyAttributes ignored; |
| 3132 | i::Handle<i::Object> result = |
| 3133 | i::Object::GetProperty(receiver, receiver, lookup, name, |
| 3134 | &ignored); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3135 | has_pending_exception = result.is_null(); |
| 3136 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3137 | |
| 3138 | return Utils::ToLocal(result); |
| 3139 | } |
| 3140 | |
| 3141 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3142 | Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3143 | Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3144 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3145 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3146 | "v8::Object::GetRealNamedPropertyInPrototypeChain()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3147 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3148 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3149 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3150 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3151 | i::LookupResult lookup(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3152 | self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3153 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3157 | Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3158 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3159 | ON_BAILOUT(isolate, "v8::Object::GetRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3160 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3161 | ENTER_V8(isolate); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3162 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3163 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3164 | i::LookupResult lookup(isolate); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3165 | self_obj->LookupRealNamedProperty(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3166 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3170 | // Turns on access checks by copying the map and setting the check flag. |
| 3171 | // Because the object gets a new map, existing inline cache caching |
| 3172 | // the old map of this object will fail. |
| 3173 | void v8::Object::TurnOnAccessCheck() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3174 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3175 | ON_BAILOUT(isolate, "v8::Object::TurnOnAccessCheck()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3176 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3177 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3178 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3179 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3180 | // When turning on access checks for a global object deoptimize all functions |
| 3181 | // as optimized code does not always handle access checks. |
| 3182 | i::Deoptimizer::DeoptimizeGlobalObject(*obj); |
| 3183 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3184 | i::Handle<i::Map> new_map = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3185 | isolate->factory()->CopyMapDropTransitions(i::Handle<i::Map>(obj->map())); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3186 | new_map->set_is_access_check_needed(true); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3187 | obj->set_map(*new_map); |
| 3188 | } |
| 3189 | |
| 3190 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3191 | bool v8::Object::IsDirty() { |
| 3192 | return Utils::OpenHandle(this)->IsDirty(); |
| 3193 | } |
| 3194 | |
| 3195 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3196 | Local<v8::Object> v8::Object::Clone() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3197 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3198 | ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3199 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3200 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3201 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3202 | i::Handle<i::JSObject> result = i::Copy(self); |
| 3203 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3204 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3205 | return Utils::ToLocal(result); |
| 3206 | } |
| 3207 | |
| 3208 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3209 | static i::Context* GetCreationContext(i::JSObject* object) { |
| 3210 | i::Object* constructor = object->map()->constructor(); |
| 3211 | i::JSFunction* function; |
| 3212 | if (!constructor->IsJSFunction()) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3213 | // Functions have null as a constructor, |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3214 | // but any JSFunction knows its context immediately. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3215 | ASSERT(object->IsJSFunction()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3216 | function = i::JSFunction::cast(object); |
| 3217 | } else { |
| 3218 | function = i::JSFunction::cast(constructor); |
| 3219 | } |
| 3220 | return function->context()->global_context(); |
| 3221 | } |
| 3222 | |
| 3223 | |
| 3224 | Local<v8::Context> v8::Object::CreationContext() { |
| 3225 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3226 | ON_BAILOUT(isolate, |
| 3227 | "v8::Object::CreationContext()", return Local<v8::Context>()); |
| 3228 | ENTER_V8(isolate); |
| 3229 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3230 | i::Context* context = GetCreationContext(*self); |
| 3231 | return Utils::ToLocal(i::Handle<i::Context>(context)); |
| 3232 | } |
| 3233 | |
| 3234 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3235 | int v8::Object::GetIdentityHash() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3236 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3237 | ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3238 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3239 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3240 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3241 | return i::JSObject::GetIdentityHash(self); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | |
| 3245 | bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, |
| 3246 | v8::Handle<v8::Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3247 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3248 | ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3249 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3250 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3251 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3252 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3253 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3254 | i::Handle<i::Object> result = |
| 3255 | i::JSObject::SetHiddenProperty(self, key_obj, value_obj); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3256 | return *result == *self; |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | |
| 3260 | 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] | 3261 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3262 | ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()", |
| 3263 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3264 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3265 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3266 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3267 | i::Handle<i::Object> result(self->GetHiddenProperty(*key_obj)); |
| 3268 | if (result->IsUndefined()) return v8::Local<v8::Value>(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3269 | return Utils::ToLocal(result); |
| 3270 | } |
| 3271 | |
| 3272 | |
| 3273 | bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3274 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3275 | ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3276 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3277 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3278 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3279 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3280 | self->DeleteHiddenProperty(*key_obj); |
| 3281 | return true; |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3285 | namespace { |
| 3286 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3287 | static i::ElementsKind GetElementsKindFromExternalArrayType( |
| 3288 | ExternalArrayType array_type) { |
| 3289 | switch (array_type) { |
| 3290 | case kExternalByteArray: |
| 3291 | return i::EXTERNAL_BYTE_ELEMENTS; |
| 3292 | break; |
| 3293 | case kExternalUnsignedByteArray: |
| 3294 | return i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS; |
| 3295 | break; |
| 3296 | case kExternalShortArray: |
| 3297 | return i::EXTERNAL_SHORT_ELEMENTS; |
| 3298 | break; |
| 3299 | case kExternalUnsignedShortArray: |
| 3300 | return i::EXTERNAL_UNSIGNED_SHORT_ELEMENTS; |
| 3301 | break; |
| 3302 | case kExternalIntArray: |
| 3303 | return i::EXTERNAL_INT_ELEMENTS; |
| 3304 | break; |
| 3305 | case kExternalUnsignedIntArray: |
| 3306 | return i::EXTERNAL_UNSIGNED_INT_ELEMENTS; |
| 3307 | break; |
| 3308 | case kExternalFloatArray: |
| 3309 | return i::EXTERNAL_FLOAT_ELEMENTS; |
| 3310 | break; |
| 3311 | case kExternalDoubleArray: |
| 3312 | return i::EXTERNAL_DOUBLE_ELEMENTS; |
| 3313 | break; |
| 3314 | case kExternalPixelArray: |
| 3315 | return i::EXTERNAL_PIXEL_ELEMENTS; |
| 3316 | break; |
| 3317 | } |
| 3318 | UNREACHABLE(); |
| 3319 | return i::DICTIONARY_ELEMENTS; |
| 3320 | } |
| 3321 | |
| 3322 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3323 | void PrepareExternalArrayElements(i::Handle<i::JSObject> object, |
| 3324 | void* data, |
| 3325 | ExternalArrayType array_type, |
| 3326 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3327 | i::Isolate* isolate = object->GetIsolate(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3328 | i::Handle<i::ExternalArray> array = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3329 | isolate->factory()->NewExternalArray(length, array_type, data); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3330 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3331 | i::Handle<i::Map> external_array_map = |
| 3332 | isolate->factory()->GetElementsTransitionMap( |
| 3333 | object, |
| 3334 | GetElementsKindFromExternalArrayType(array_type)); |
| 3335 | |
| 3336 | object->set_map(*external_array_map); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3337 | object->set_elements(*array); |
| 3338 | } |
| 3339 | |
| 3340 | } // namespace |
| 3341 | |
| 3342 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3343 | void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3344 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3345 | ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3346 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3347 | i::HandleScope scope(isolate); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3348 | if (!ApiCheck(length <= i::ExternalPixelArray::kMaxLength, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3349 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3350 | "length exceeds max acceptable value")) { |
| 3351 | return; |
| 3352 | } |
| 3353 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3354 | if (!ApiCheck(!self->IsJSArray(), |
| 3355 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3356 | "JSArray is not supported")) { |
| 3357 | return; |
| 3358 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3359 | PrepareExternalArrayElements(self, data, kExternalPixelArray, length); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3363 | bool v8::Object::HasIndexedPropertiesInPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3364 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3365 | ON_BAILOUT(self->GetIsolate(), "v8::HasIndexedPropertiesInPixelData()", |
| 3366 | return false); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3367 | return self->HasExternalPixelElements(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | |
| 3371 | uint8_t* v8::Object::GetIndexedPropertiesPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3372 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3373 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelData()", |
| 3374 | return NULL); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3375 | if (self->HasExternalPixelElements()) { |
| 3376 | return i::ExternalPixelArray::cast(self->elements())-> |
| 3377 | external_pixel_pointer(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3378 | } else { |
| 3379 | return NULL; |
| 3380 | } |
| 3381 | } |
| 3382 | |
| 3383 | |
| 3384 | int v8::Object::GetIndexedPropertiesPixelDataLength() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3385 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3386 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelDataLength()", |
| 3387 | return -1); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3388 | if (self->HasExternalPixelElements()) { |
| 3389 | return i::ExternalPixelArray::cast(self->elements())->length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3390 | } else { |
| 3391 | return -1; |
| 3392 | } |
| 3393 | } |
| 3394 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3395 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3396 | void v8::Object::SetIndexedPropertiesToExternalArrayData( |
| 3397 | void* data, |
| 3398 | ExternalArrayType array_type, |
| 3399 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3400 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3401 | ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3402 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3403 | i::HandleScope scope(isolate); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3404 | if (!ApiCheck(length <= i::ExternalArray::kMaxLength, |
| 3405 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3406 | "length exceeds max acceptable value")) { |
| 3407 | return; |
| 3408 | } |
| 3409 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3410 | if (!ApiCheck(!self->IsJSArray(), |
| 3411 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3412 | "JSArray is not supported")) { |
| 3413 | return; |
| 3414 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3415 | PrepareExternalArrayElements(self, data, array_type, length); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3419 | bool v8::Object::HasIndexedPropertiesInExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3420 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3421 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3422 | "v8::HasIndexedPropertiesInExternalArrayData()", |
| 3423 | return false); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3424 | return self->HasExternalArrayElements(); |
| 3425 | } |
| 3426 | |
| 3427 | |
| 3428 | void* v8::Object::GetIndexedPropertiesExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3429 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3430 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3431 | "v8::GetIndexedPropertiesExternalArrayData()", |
| 3432 | return NULL); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3433 | if (self->HasExternalArrayElements()) { |
| 3434 | return i::ExternalArray::cast(self->elements())->external_pointer(); |
| 3435 | } else { |
| 3436 | return NULL; |
| 3437 | } |
| 3438 | } |
| 3439 | |
| 3440 | |
| 3441 | ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3442 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3443 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3444 | "v8::GetIndexedPropertiesExternalArrayDataType()", |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3445 | return static_cast<ExternalArrayType>(-1)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3446 | switch (self->elements()->map()->instance_type()) { |
| 3447 | case i::EXTERNAL_BYTE_ARRAY_TYPE: |
| 3448 | return kExternalByteArray; |
| 3449 | case i::EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 3450 | return kExternalUnsignedByteArray; |
| 3451 | case i::EXTERNAL_SHORT_ARRAY_TYPE: |
| 3452 | return kExternalShortArray; |
| 3453 | case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 3454 | return kExternalUnsignedShortArray; |
| 3455 | case i::EXTERNAL_INT_ARRAY_TYPE: |
| 3456 | return kExternalIntArray; |
| 3457 | case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 3458 | return kExternalUnsignedIntArray; |
| 3459 | case i::EXTERNAL_FLOAT_ARRAY_TYPE: |
| 3460 | return kExternalFloatArray; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3461 | case i::EXTERNAL_DOUBLE_ARRAY_TYPE: |
| 3462 | return kExternalDoubleArray; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3463 | case i::EXTERNAL_PIXEL_ARRAY_TYPE: |
| 3464 | return kExternalPixelArray; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3465 | default: |
| 3466 | return static_cast<ExternalArrayType>(-1); |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | |
| 3471 | int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3472 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3473 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3474 | "v8::GetIndexedPropertiesExternalArrayDataLength()", |
| 3475 | return 0); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3476 | if (self->HasExternalArrayElements()) { |
| 3477 | return i::ExternalArray::cast(self->elements())->length(); |
| 3478 | } else { |
| 3479 | return -1; |
| 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3484 | bool v8::Object::IsCallable() { |
| 3485 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3486 | ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false); |
| 3487 | ENTER_V8(isolate); |
| 3488 | i::HandleScope scope(isolate); |
| 3489 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3490 | if (obj->IsJSFunction()) return true; |
| 3491 | return i::Execution::GetFunctionDelegate(obj)->IsJSFunction(); |
| 3492 | } |
| 3493 | |
| 3494 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3495 | Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Object> recv, |
| 3496 | int argc, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3497 | v8::Handle<v8::Value> argv[]) { |
| 3498 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3499 | ON_BAILOUT(isolate, "v8::Object::CallAsFunction()", |
| 3500 | return Local<v8::Value>()); |
| 3501 | LOG_API(isolate, "Object::CallAsFunction"); |
| 3502 | ENTER_V8(isolate); |
| 3503 | i::HandleScope scope(isolate); |
| 3504 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3505 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3506 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3507 | i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3508 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(); |
| 3509 | if (obj->IsJSFunction()) { |
| 3510 | fun = i::Handle<i::JSFunction>::cast(obj); |
| 3511 | } else { |
| 3512 | EXCEPTION_PREAMBLE(isolate); |
| 3513 | i::Handle<i::Object> delegate = |
| 3514 | i::Execution::TryGetFunctionDelegate(obj, &has_pending_exception); |
| 3515 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3516 | fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3517 | recv_obj = obj; |
| 3518 | } |
| 3519 | EXCEPTION_PREAMBLE(isolate); |
| 3520 | i::Handle<i::Object> returned = |
| 3521 | i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3522 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3523 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3524 | } |
| 3525 | |
| 3526 | |
| 3527 | Local<v8::Value> Object::CallAsConstructor(int argc, |
| 3528 | v8::Handle<v8::Value> argv[]) { |
| 3529 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3530 | ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()", |
| 3531 | return Local<v8::Object>()); |
| 3532 | LOG_API(isolate, "Object::CallAsConstructor"); |
| 3533 | ENTER_V8(isolate); |
| 3534 | i::HandleScope scope(isolate); |
| 3535 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3536 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3537 | i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3538 | if (obj->IsJSFunction()) { |
| 3539 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj); |
| 3540 | EXCEPTION_PREAMBLE(isolate); |
| 3541 | i::Handle<i::Object> returned = |
| 3542 | i::Execution::New(fun, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3543 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3544 | return Utils::ToLocal(scope.CloseAndEscape( |
| 3545 | i::Handle<i::JSObject>::cast(returned))); |
| 3546 | } |
| 3547 | EXCEPTION_PREAMBLE(isolate); |
| 3548 | i::Handle<i::Object> delegate = |
| 3549 | i::Execution::TryGetConstructorDelegate(obj, &has_pending_exception); |
| 3550 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3551 | if (!delegate->IsUndefined()) { |
| 3552 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3553 | EXCEPTION_PREAMBLE(isolate); |
| 3554 | i::Handle<i::Object> returned = |
| 3555 | i::Execution::Call(fun, obj, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3556 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3557 | ASSERT(!delegate->IsUndefined()); |
| 3558 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3559 | } |
| 3560 | return Local<v8::Object>(); |
| 3561 | } |
| 3562 | |
| 3563 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3564 | Local<v8::Object> Function::NewInstance() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3565 | return NewInstance(0, NULL); |
| 3566 | } |
| 3567 | |
| 3568 | |
| 3569 | Local<v8::Object> Function::NewInstance(int argc, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3570 | v8::Handle<v8::Value> argv[]) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3571 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3572 | ON_BAILOUT(isolate, "v8::Function::NewInstance()", |
| 3573 | return Local<v8::Object>()); |
| 3574 | LOG_API(isolate, "Function::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3575 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3576 | HandleScope scope; |
| 3577 | i::Handle<i::JSFunction> function = Utils::OpenHandle(this); |
| 3578 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3579 | i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3580 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3581 | i::Handle<i::Object> returned = |
| 3582 | i::Execution::New(function, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3583 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3584 | return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned))); |
| 3585 | } |
| 3586 | |
| 3587 | |
| 3588 | Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc, |
| 3589 | v8::Handle<v8::Value> argv[]) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3590 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3591 | ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>()); |
| 3592 | LOG_API(isolate, "Function::Call"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3593 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3594 | i::Object* raw_result = NULL; |
| 3595 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3596 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3597 | i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); |
| 3598 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3599 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3600 | i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3601 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3602 | i::Handle<i::Object> returned = |
| 3603 | i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3604 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3605 | raw_result = *returned; |
| 3606 | } |
| 3607 | i::Handle<i::Object> result(raw_result); |
| 3608 | return Utils::ToLocal(result); |
| 3609 | } |
| 3610 | |
| 3611 | |
| 3612 | void Function::SetName(v8::Handle<v8::String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3613 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3614 | ENTER_V8(isolate); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3615 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3616 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3617 | func->shared()->set_name(*Utils::OpenHandle(*name)); |
| 3618 | } |
| 3619 | |
| 3620 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3621 | Handle<Value> Function::GetName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3622 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3623 | return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name())); |
| 3624 | } |
| 3625 | |
| 3626 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3627 | Handle<Value> Function::GetInferredName() const { |
| 3628 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3629 | return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name())); |
| 3630 | } |
| 3631 | |
| 3632 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3633 | ScriptOrigin Function::GetScriptOrigin() const { |
| 3634 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3635 | if (func->shared()->script()->IsScript()) { |
| 3636 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 3637 | v8::ScriptOrigin origin( |
| 3638 | Utils::ToLocal(i::Handle<i::Object>(script->name())), |
| 3639 | v8::Integer::New(script->line_offset()->value()), |
| 3640 | v8::Integer::New(script->column_offset()->value())); |
| 3641 | return origin; |
| 3642 | } |
| 3643 | return v8::ScriptOrigin(Handle<Value>()); |
| 3644 | } |
| 3645 | |
| 3646 | |
| 3647 | const int Function::kLineOffsetNotFound = -1; |
| 3648 | |
| 3649 | |
| 3650 | int Function::GetScriptLineNumber() const { |
| 3651 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3652 | if (func->shared()->script()->IsScript()) { |
| 3653 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 3654 | return i::GetScriptLineNumber(script, func->shared()->start_position()); |
| 3655 | } |
| 3656 | return kLineOffsetNotFound; |
| 3657 | } |
| 3658 | |
| 3659 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3660 | int Function::GetScriptColumnNumber() const { |
| 3661 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3662 | if (func->shared()->script()->IsScript()) { |
| 3663 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 3664 | return i::GetScriptColumnNumber(script, func->shared()->start_position()); |
| 3665 | } |
| 3666 | return kLineOffsetNotFound; |
| 3667 | } |
| 3668 | |
| 3669 | Handle<Value> Function::GetScriptId() const { |
| 3670 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3671 | if (!func->shared()->script()->IsScript()) |
| 3672 | return v8::Undefined(); |
| 3673 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 3674 | return Utils::ToLocal(i::Handle<i::Object>(script->id())); |
| 3675 | } |
| 3676 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3677 | int String::Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3678 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3679 | if (IsDeadCheck(str->GetIsolate(), "v8::String::Length()")) return 0; |
| 3680 | return str->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3684 | int String::Utf8Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3685 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3686 | if (IsDeadCheck(str->GetIsolate(), "v8::String::Utf8Length()")) return 0; |
| 3687 | return str->Utf8Length(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3691 | int String::WriteUtf8(char* buffer, |
| 3692 | int capacity, |
| 3693 | int* nchars_ref, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3694 | int options) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3695 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3696 | if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; |
| 3697 | LOG_API(isolate, "String::WriteUtf8"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3698 | ENTER_V8(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3699 | i::Handle<i::String> str = Utils::OpenHandle(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3700 | if (str->IsAsciiRepresentation()) { |
| 3701 | int len; |
| 3702 | if (capacity == -1) { |
| 3703 | capacity = str->length() + 1; |
| 3704 | len = str->length(); |
| 3705 | } else { |
| 3706 | len = i::Min(capacity, str->length()); |
| 3707 | } |
| 3708 | i::String::WriteToFlat(*str, buffer, 0, len); |
| 3709 | if (nchars_ref != NULL) *nchars_ref = len; |
| 3710 | if (!(options & NO_NULL_TERMINATION) && capacity > len) { |
| 3711 | buffer[len] = '\0'; |
| 3712 | return len + 1; |
| 3713 | } |
| 3714 | return len; |
| 3715 | } |
| 3716 | |
| 3717 | i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3718 | isolate->string_tracker()->RecordWrite(str); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3719 | if (options & HINT_MANY_WRITES_EXPECTED) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3720 | // Flatten the string for efficiency. This applies whether we are |
| 3721 | // using StringInputBuffer or Get(i) to access the characters. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3722 | FlattenString(str); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3723 | } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3724 | write_input_buffer.Reset(0, *str); |
| 3725 | int len = str->length(); |
| 3726 | // Encode the first K - 3 bytes directly into the buffer since we |
| 3727 | // know there's room for them. If no capacity is given we copy all |
| 3728 | // of them here. |
| 3729 | int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); |
| 3730 | int i; |
| 3731 | int pos = 0; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3732 | int nchars = 0; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3733 | for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) { |
| 3734 | i::uc32 c = write_input_buffer.GetNext(); |
| 3735 | int written = unibrow::Utf8::Encode(buffer + pos, c); |
| 3736 | pos += written; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3737 | nchars++; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3738 | } |
| 3739 | if (i < len) { |
| 3740 | // For the last characters we need to check the length for each one |
| 3741 | // because they may be longer than the remaining space in the |
| 3742 | // buffer. |
| 3743 | char intermediate[unibrow::Utf8::kMaxEncodedSize]; |
| 3744 | for (; i < len && pos < capacity; i++) { |
| 3745 | i::uc32 c = write_input_buffer.GetNext(); |
| 3746 | int written = unibrow::Utf8::Encode(intermediate, c); |
| 3747 | if (pos + written <= capacity) { |
| 3748 | for (int j = 0; j < written; j++) |
| 3749 | buffer[pos + j] = intermediate[j]; |
| 3750 | pos += written; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3751 | nchars++; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3752 | } else { |
| 3753 | // We've reached the end of the buffer |
| 3754 | break; |
| 3755 | } |
| 3756 | } |
| 3757 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3758 | if (nchars_ref != NULL) *nchars_ref = nchars; |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3759 | if (!(options & NO_NULL_TERMINATION) && |
| 3760 | (i == len && (capacity == -1 || pos < capacity))) |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3761 | buffer[pos++] = '\0'; |
| 3762 | return pos; |
| 3763 | } |
| 3764 | |
| 3765 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3766 | int String::WriteAscii(char* buffer, |
| 3767 | int start, |
| 3768 | int length, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3769 | int options) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3770 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3771 | if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0; |
| 3772 | LOG_API(isolate, "String::WriteAscii"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3773 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3774 | i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3775 | ASSERT(start >= 0 && length >= -1); |
| 3776 | i::Handle<i::String> str = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3777 | isolate->string_tracker()->RecordWrite(str); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3778 | if (options & HINT_MANY_WRITES_EXPECTED) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3779 | // Flatten the string for efficiency. This applies whether we are |
| 3780 | // using StringInputBuffer or Get(i) to access the characters. |
| 3781 | str->TryFlatten(); |
| 3782 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3783 | int end = length; |
| 3784 | if ( (length == -1) || (length > str->length() - start) ) |
| 3785 | end = str->length() - start; |
| 3786 | if (end < 0) return 0; |
| 3787 | write_input_buffer.Reset(start, *str); |
| 3788 | int i; |
| 3789 | for (i = 0; i < end; i++) { |
| 3790 | char c = static_cast<char>(write_input_buffer.GetNext()); |
| 3791 | if (c == '\0') c = ' '; |
| 3792 | buffer[i] = c; |
| 3793 | } |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3794 | if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3795 | buffer[i] = '\0'; |
| 3796 | return i; |
| 3797 | } |
| 3798 | |
| 3799 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3800 | int String::Write(uint16_t* buffer, |
| 3801 | int start, |
| 3802 | int length, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3803 | int options) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3804 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3805 | if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; |
| 3806 | LOG_API(isolate, "String::Write"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3807 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3808 | ASSERT(start >= 0 && length >= -1); |
| 3809 | i::Handle<i::String> str = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3810 | isolate->string_tracker()->RecordWrite(str); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3811 | if (options & HINT_MANY_WRITES_EXPECTED) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3812 | // Flatten the string for efficiency. This applies whether we are |
| 3813 | // using StringInputBuffer or Get(i) to access the characters. |
| 3814 | str->TryFlatten(); |
| 3815 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3816 | int end = start + length; |
| 3817 | if ((length == -1) || (length > str->length() - start) ) |
| 3818 | end = str->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3819 | if (end < 0) return 0; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3820 | i::String::WriteToFlat(*str, buffer, start, end); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3821 | if (!(options & NO_NULL_TERMINATION) && |
| 3822 | (length == -1 || end - start < length)) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3823 | buffer[end - start] = '\0'; |
| 3824 | } |
| 3825 | return end - start; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3829 | bool v8::String::IsExternal() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3830 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3831 | if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { |
| 3832 | return false; |
| 3833 | } |
| 3834 | EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3835 | return i::StringShape(*str).IsExternalTwoByte(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3839 | bool v8::String::IsExternalAscii() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3840 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3841 | if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternalAscii()")) { |
| 3842 | return false; |
| 3843 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3844 | return i::StringShape(*str).IsExternalAscii(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3848 | void v8::String::VerifyExternalStringResource( |
| 3849 | v8::String::ExternalStringResource* value) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3850 | i::Handle<i::String> str = Utils::OpenHandle(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3851 | const v8::String::ExternalStringResource* expected; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3852 | if (i::StringShape(*str).IsExternalTwoByte()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3853 | const void* resource = |
| 3854 | i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
| 3855 | expected = reinterpret_cast<const ExternalStringResource*>(resource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3856 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3857 | expected = NULL; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3858 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3859 | CHECK_EQ(expected, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3863 | const v8::String::ExternalAsciiStringResource* |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3864 | v8::String::GetExternalAsciiStringResource() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3865 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3866 | if (IsDeadCheck(str->GetIsolate(), |
| 3867 | "v8::String::GetExternalAsciiStringResource()")) { |
| 3868 | return NULL; |
| 3869 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3870 | if (i::StringShape(*str).IsExternalAscii()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3871 | const void* resource = |
| 3872 | i::Handle<i::ExternalAsciiString>::cast(str)->resource(); |
| 3873 | return reinterpret_cast<const ExternalAsciiStringResource*>(resource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3874 | } else { |
| 3875 | return NULL; |
| 3876 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3880 | double Number::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3881 | if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3882 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3883 | return obj->Number(); |
| 3884 | } |
| 3885 | |
| 3886 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3887 | bool Boolean::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3888 | if (IsDeadCheck(i::Isolate::Current(), "v8::Boolean::Value()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3889 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3890 | return obj->IsTrue(); |
| 3891 | } |
| 3892 | |
| 3893 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3894 | int64_t Integer::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3895 | if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3896 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3897 | if (obj->IsSmi()) { |
| 3898 | return i::Smi::cast(*obj)->value(); |
| 3899 | } else { |
| 3900 | return static_cast<int64_t>(obj->Number()); |
| 3901 | } |
| 3902 | } |
| 3903 | |
| 3904 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3905 | int32_t Int32::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3906 | if (IsDeadCheck(i::Isolate::Current(), "v8::Int32::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3907 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3908 | if (obj->IsSmi()) { |
| 3909 | return i::Smi::cast(*obj)->value(); |
| 3910 | } else { |
| 3911 | return static_cast<int32_t>(obj->Number()); |
| 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3916 | uint32_t Uint32::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3917 | if (IsDeadCheck(i::Isolate::Current(), "v8::Uint32::Value()")) return 0; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3918 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3919 | if (obj->IsSmi()) { |
| 3920 | return i::Smi::cast(*obj)->value(); |
| 3921 | } else { |
| 3922 | return static_cast<uint32_t>(obj->Number()); |
| 3923 | } |
| 3924 | } |
| 3925 | |
| 3926 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3927 | int v8::Object::InternalFieldCount() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3928 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3929 | if (IsDeadCheck(obj->GetIsolate(), "v8::Object::InternalFieldCount()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3930 | return 0; |
| 3931 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3932 | return obj->GetInternalFieldCount(); |
| 3933 | } |
| 3934 | |
| 3935 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3936 | Local<Value> v8::Object::CheckedGetInternalField(int index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3937 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3938 | if (IsDeadCheck(obj->GetIsolate(), "v8::Object::GetInternalField()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3939 | return Local<Value>(); |
| 3940 | } |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3941 | if (!ApiCheck(index < obj->GetInternalFieldCount(), |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3942 | "v8::Object::GetInternalField()", |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3943 | "Reading internal field out of bounds")) { |
| 3944 | return Local<Value>(); |
| 3945 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3946 | i::Handle<i::Object> value(obj->GetInternalField(index)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3947 | Local<Value> result = Utils::ToLocal(value); |
| 3948 | #ifdef DEBUG |
| 3949 | Local<Value> unchecked = UncheckedGetInternalField(index); |
| 3950 | ASSERT(unchecked.IsEmpty() || (unchecked == result)); |
| 3951 | #endif |
| 3952 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3956 | void v8::Object::SetInternalField(int index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3957 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3958 | i::Isolate* isolate = obj->GetIsolate(); |
| 3959 | if (IsDeadCheck(isolate, "v8::Object::SetInternalField()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3960 | return; |
| 3961 | } |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3962 | if (!ApiCheck(index < obj->GetInternalFieldCount(), |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3963 | "v8::Object::SetInternalField()", |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3964 | "Writing internal field out of bounds")) { |
| 3965 | return; |
| 3966 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3967 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3968 | i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 3969 | obj->SetInternalField(index, *val); |
| 3970 | } |
| 3971 | |
| 3972 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3973 | static bool CanBeEncodedAsSmi(void* ptr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3974 | const uintptr_t address = reinterpret_cast<uintptr_t>(ptr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3975 | return ((address & i::kEncodablePointerMask) == 0); |
| 3976 | } |
| 3977 | |
| 3978 | |
| 3979 | static i::Smi* EncodeAsSmi(void* ptr) { |
| 3980 | ASSERT(CanBeEncodedAsSmi(ptr)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3981 | const uintptr_t address = reinterpret_cast<uintptr_t>(ptr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3982 | i::Smi* result = reinterpret_cast<i::Smi*>(address << i::kPointerToSmiShift); |
| 3983 | ASSERT(i::Internals::HasSmiTag(result)); |
| 3984 | ASSERT_EQ(result, i::Smi::FromInt(result->value())); |
| 3985 | ASSERT_EQ(ptr, i::Internals::GetExternalPointerFromSmi(result)); |
| 3986 | return result; |
| 3987 | } |
| 3988 | |
| 3989 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3990 | void v8::Object::SetPointerInInternalField(int index, void* value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3991 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3992 | ENTER_V8(isolate); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3993 | if (CanBeEncodedAsSmi(value)) { |
| 3994 | Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value)); |
| 3995 | } else { |
| 3996 | HandleScope scope; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3997 | i::Handle<i::Foreign> foreign = |
| 3998 | isolate->factory()->NewForeign( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3999 | reinterpret_cast<i::Address>(value), i::TENURED); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4000 | if (!foreign.is_null()) |
| 4001 | Utils::OpenHandle(this)->SetInternalField(index, *foreign); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4002 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4003 | ASSERT_EQ(value, GetPointerFromInternalField(index)); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4007 | // --- E n v i r o n m e n t --- |
| 4008 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4009 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4010 | bool v8::V8::Initialize() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4011 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 4012 | if (isolate != NULL && isolate->IsInitialized()) { |
| 4013 | return true; |
| 4014 | } |
| 4015 | return InitializeHelper(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4019 | void v8::V8::SetEntropySource(EntropySource source) { |
| 4020 | i::V8::SetEntropySource(source); |
| 4021 | } |
| 4022 | |
| 4023 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4024 | bool v8::V8::Dispose() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4025 | i::Isolate* isolate = i::Isolate::Current(); |
| 4026 | if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(), |
| 4027 | "v8::V8::Dispose()", |
| 4028 | "Use v8::Isolate::Dispose() for a non-default isolate.")) { |
| 4029 | return false; |
| 4030 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4031 | i::V8::TearDown(); |
| 4032 | return true; |
| 4033 | } |
| 4034 | |
| 4035 | |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 4036 | HeapStatistics::HeapStatistics(): total_heap_size_(0), |
| 4037 | total_heap_size_executable_(0), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4038 | used_heap_size_(0), |
| 4039 | heap_size_limit_(0) { } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4040 | |
| 4041 | |
| 4042 | void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4043 | if (!i::Isolate::Current()->IsInitialized()) { |
| 4044 | // Isolate is unitialized thus heap is not configured yet. |
| 4045 | heap_statistics->set_total_heap_size(0); |
| 4046 | heap_statistics->set_total_heap_size_executable(0); |
| 4047 | heap_statistics->set_used_heap_size(0); |
| 4048 | heap_statistics->set_heap_size_limit(0); |
| 4049 | return; |
| 4050 | } |
| 4051 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4052 | i::Heap* heap = i::Isolate::Current()->heap(); |
| 4053 | heap_statistics->set_total_heap_size(heap->CommittedMemory()); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 4054 | heap_statistics->set_total_heap_size_executable( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4055 | heap->CommittedMemoryExecutable()); |
| 4056 | heap_statistics->set_used_heap_size(heap->SizeOfObjects()); |
| 4057 | heap_statistics->set_heap_size_limit(heap->MaxReserved()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4058 | } |
| 4059 | |
| 4060 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4061 | void v8::V8::VisitExternalResources(ExternalResourceVisitor* visitor) { |
| 4062 | i::Isolate* isolate = i::Isolate::Current(); |
| 4063 | IsDeadCheck(isolate, "v8::V8::VisitExternalResources"); |
| 4064 | isolate->heap()->VisitExternalResources(visitor); |
| 4065 | } |
| 4066 | |
| 4067 | |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4068 | bool v8::V8::IdleNotification(int hint) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4069 | // Returning true tells the caller that it need not |
| 4070 | // continue to call IdleNotification. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4071 | i::Isolate* isolate = i::Isolate::Current(); |
| 4072 | if (isolate == NULL || !isolate->IsInitialized()) return true; |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4073 | return i::V8::IdleNotification(hint); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4074 | } |
| 4075 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4076 | |
| 4077 | void v8::V8::LowMemoryNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4078 | i::Isolate* isolate = i::Isolate::Current(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4079 | if (isolate == NULL || !isolate->IsInitialized()) return; |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame^] | 4080 | isolate->heap()->CollectAllAvailableGarbage("low memory notification"); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4084 | int v8::V8::ContextDisposedNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4085 | i::Isolate* isolate = i::Isolate::Current(); |
| 4086 | if (!isolate->IsInitialized()) return 0; |
| 4087 | return isolate->heap()->NotifyContextDisposed(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4091 | const char* v8::V8::GetVersion() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4092 | return i::Version::GetVersion(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4096 | static i::Handle<i::FunctionTemplateInfo> |
| 4097 | EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) { |
| 4098 | if (templ->constructor()->IsUndefined()) { |
| 4099 | Local<FunctionTemplate> constructor = FunctionTemplate::New(); |
| 4100 | Utils::OpenHandle(*constructor)->set_instance_template(*templ); |
| 4101 | templ->set_constructor(*Utils::OpenHandle(*constructor)); |
| 4102 | } |
| 4103 | return i::Handle<i::FunctionTemplateInfo>( |
| 4104 | i::FunctionTemplateInfo::cast(templ->constructor())); |
| 4105 | } |
| 4106 | |
| 4107 | |
| 4108 | Persistent<Context> v8::Context::New( |
| 4109 | v8::ExtensionConfiguration* extensions, |
| 4110 | v8::Handle<ObjectTemplate> global_template, |
| 4111 | v8::Handle<Value> global_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4112 | i::Isolate* isolate = i::Isolate::Current(); |
| 4113 | EnsureInitializedForIsolate(isolate, "v8::Context::New()"); |
| 4114 | LOG_API(isolate, "Context::New"); |
| 4115 | ON_BAILOUT(isolate, "v8::Context::New()", return Persistent<Context>()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4116 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4117 | // Enter V8 via an ENTER_V8 scope. |
| 4118 | i::Handle<i::Context> env; |
| 4119 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4120 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4121 | v8::Handle<ObjectTemplate> proxy_template = global_template; |
| 4122 | i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
| 4123 | i::Handle<i::FunctionTemplateInfo> global_constructor; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4124 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4125 | if (!global_template.IsEmpty()) { |
| 4126 | // Make sure that the global_template has a constructor. |
| 4127 | global_constructor = |
| 4128 | EnsureConstructor(Utils::OpenHandle(*global_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4129 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4130 | // Create a fresh template for the global proxy object. |
| 4131 | proxy_template = ObjectTemplate::New(); |
| 4132 | proxy_constructor = |
| 4133 | EnsureConstructor(Utils::OpenHandle(*proxy_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4134 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4135 | // Set the global template to be the prototype template of |
| 4136 | // global proxy template. |
| 4137 | proxy_constructor->set_prototype_template( |
| 4138 | *Utils::OpenHandle(*global_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4139 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4140 | // Migrate security handlers from global_template to |
| 4141 | // proxy_template. Temporarily removing access check |
| 4142 | // information from the global template. |
| 4143 | if (!global_constructor->access_check_info()->IsUndefined()) { |
| 4144 | proxy_constructor->set_access_check_info( |
| 4145 | global_constructor->access_check_info()); |
| 4146 | proxy_constructor->set_needs_access_check( |
| 4147 | global_constructor->needs_access_check()); |
| 4148 | global_constructor->set_needs_access_check(false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4149 | global_constructor->set_access_check_info( |
| 4150 | isolate->heap()->undefined_value()); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | // Create the environment. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4155 | env = isolate->bootstrapper()->CreateEnvironment( |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4156 | isolate, |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4157 | Utils::OpenHandle(*global_object), |
| 4158 | proxy_template, |
| 4159 | extensions); |
| 4160 | |
| 4161 | // Restore the access check info on the global template. |
| 4162 | if (!global_template.IsEmpty()) { |
| 4163 | ASSERT(!global_constructor.is_null()); |
| 4164 | ASSERT(!proxy_constructor.is_null()); |
| 4165 | global_constructor->set_access_check_info( |
| 4166 | proxy_constructor->access_check_info()); |
| 4167 | global_constructor->set_needs_access_check( |
| 4168 | proxy_constructor->needs_access_check()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4169 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4170 | isolate->runtime_profiler()->Reset(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4171 | } |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4172 | // Leave V8. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4173 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4174 | if (env.is_null()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4175 | return Persistent<Context>(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4176 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4177 | return Persistent<Context>(Utils::ToLocal(env)); |
| 4178 | } |
| 4179 | |
| 4180 | |
| 4181 | void v8::Context::SetSecurityToken(Handle<Value> token) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4182 | i::Isolate* isolate = i::Isolate::Current(); |
| 4183 | if (IsDeadCheck(isolate, "v8::Context::SetSecurityToken()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4184 | return; |
| 4185 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4186 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4187 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4188 | i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4189 | env->set_security_token(*token_handle); |
| 4190 | } |
| 4191 | |
| 4192 | |
| 4193 | void v8::Context::UseDefaultSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4194 | i::Isolate* isolate = i::Isolate::Current(); |
| 4195 | if (IsDeadCheck(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4196 | "v8::Context::UseDefaultSecurityToken()")) { |
| 4197 | return; |
| 4198 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4199 | ENTER_V8(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4200 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4201 | env->set_security_token(env->global()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | |
| 4205 | Handle<Value> v8::Context::GetSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4206 | i::Isolate* isolate = i::Isolate::Current(); |
| 4207 | if (IsDeadCheck(isolate, "v8::Context::GetSecurityToken()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4208 | return Handle<Value>(); |
| 4209 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4210 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4211 | i::Object* security_token = env->security_token(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4212 | i::Handle<i::Object> token_handle(security_token); |
| 4213 | return Utils::ToLocal(token_handle); |
| 4214 | } |
| 4215 | |
| 4216 | |
| 4217 | bool Context::HasOutOfMemoryException() { |
| 4218 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4219 | return env->has_out_of_memory(); |
| 4220 | } |
| 4221 | |
| 4222 | |
| 4223 | bool Context::InContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4224 | return i::Isolate::Current()->context() != NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4225 | } |
| 4226 | |
| 4227 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4228 | v8::Local<v8::Context> Context::GetEntered() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4229 | i::Isolate* isolate = i::Isolate::Current(); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4230 | if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4231 | return Local<Context>(); |
| 4232 | } |
| 4233 | i::Handle<i::Object> last = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4234 | isolate->handle_scope_implementer()->LastEnteredContext(); |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4235 | if (last.is_null()) return Local<Context>(); |
| 4236 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(last); |
| 4237 | return Utils::ToLocal(context); |
| 4238 | } |
| 4239 | |
| 4240 | |
| 4241 | v8::Local<v8::Context> Context::GetCurrent() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4242 | i::Isolate* isolate = i::Isolate::Current(); |
| 4243 | if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4244 | return Local<Context>(); |
| 4245 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4246 | i::Handle<i::Object> current = isolate->global_context(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4247 | if (current.is_null()) return Local<Context>(); |
| 4248 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(current); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4249 | return Utils::ToLocal(context); |
| 4250 | } |
| 4251 | |
| 4252 | |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4253 | v8::Local<v8::Context> Context::GetCalling() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4254 | i::Isolate* isolate = i::Isolate::Current(); |
| 4255 | if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4256 | return Local<Context>(); |
| 4257 | } |
| 4258 | i::Handle<i::Object> calling = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4259 | isolate->GetCallingGlobalContext(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4260 | if (calling.is_null()) return Local<Context>(); |
| 4261 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(calling); |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4262 | return Utils::ToLocal(context); |
| 4263 | } |
| 4264 | |
| 4265 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4266 | v8::Local<v8::Object> Context::Global() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4267 | if (IsDeadCheck(i::Isolate::Current(), "v8::Context::Global()")) { |
| 4268 | return Local<v8::Object>(); |
| 4269 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4270 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4271 | i::Handle<i::Context> context = |
| 4272 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4273 | i::Handle<i::Object> global(context->global_proxy()); |
| 4274 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(global)); |
| 4275 | } |
| 4276 | |
| 4277 | |
| 4278 | void Context::DetachGlobal() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4279 | i::Isolate* isolate = i::Isolate::Current(); |
| 4280 | if (IsDeadCheck(isolate, "v8::Context::DetachGlobal()")) return; |
| 4281 | ENTER_V8(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4282 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4283 | i::Handle<i::Context> context = |
| 4284 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4285 | isolate->bootstrapper()->DetachGlobal(context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4289 | void Context::ReattachGlobal(Handle<Object> global_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4290 | i::Isolate* isolate = i::Isolate::Current(); |
| 4291 | if (IsDeadCheck(isolate, "v8::Context::ReattachGlobal()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4292 | ENTER_V8(isolate); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4293 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4294 | i::Handle<i::Context> context = |
| 4295 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4296 | isolate->bootstrapper()->ReattachGlobal( |
| 4297 | context, |
| 4298 | Utils::OpenHandle(*global_object)); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4302 | void Context::AllowCodeGenerationFromStrings(bool allow) { |
| 4303 | i::Isolate* isolate = i::Isolate::Current(); |
| 4304 | if (IsDeadCheck(isolate, "v8::Context::AllowCodeGenerationFromStrings()")) { |
| 4305 | return; |
| 4306 | } |
| 4307 | ENTER_V8(isolate); |
| 4308 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4309 | i::Handle<i::Context> context = |
| 4310 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
| 4311 | context->set_allow_code_gen_from_strings( |
| 4312 | allow ? isolate->heap()->true_value() : isolate->heap()->false_value()); |
| 4313 | } |
| 4314 | |
| 4315 | |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4316 | bool Context::IsCodeGenerationFromStringsAllowed() { |
| 4317 | i::Isolate* isolate = i::Isolate::Current(); |
| 4318 | if (IsDeadCheck(isolate, |
| 4319 | "v8::Context::IsCodeGenerationFromStringsAllowed()")) { |
| 4320 | return false; |
| 4321 | } |
| 4322 | ENTER_V8(isolate); |
| 4323 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4324 | i::Handle<i::Context> context = |
| 4325 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
| 4326 | return !context->allow_code_gen_from_strings()->IsFalse(); |
| 4327 | } |
| 4328 | |
| 4329 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4330 | void V8::SetWrapperClassId(i::Object** global_handle, uint16_t class_id) { |
| 4331 | i::GlobalHandles::SetWrapperClassId(global_handle, class_id); |
| 4332 | } |
| 4333 | |
| 4334 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4335 | Local<v8::Object> ObjectTemplate::NewInstance() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4336 | i::Isolate* isolate = i::Isolate::Current(); |
| 4337 | ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", |
| 4338 | return Local<v8::Object>()); |
| 4339 | LOG_API(isolate, "ObjectTemplate::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4340 | ENTER_V8(isolate); |
| 4341 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4342 | i::Handle<i::Object> obj = |
| 4343 | i::Execution::InstantiateObject(Utils::OpenHandle(this), |
| 4344 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4345 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4346 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj)); |
| 4347 | } |
| 4348 | |
| 4349 | |
| 4350 | Local<v8::Function> FunctionTemplate::GetFunction() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4351 | i::Isolate* isolate = i::Isolate::Current(); |
| 4352 | ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4353 | return Local<v8::Function>()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4354 | LOG_API(isolate, "FunctionTemplate::GetFunction"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4355 | ENTER_V8(isolate); |
| 4356 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4357 | i::Handle<i::Object> obj = |
| 4358 | i::Execution::InstantiateFunction(Utils::OpenHandle(this), |
| 4359 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4360 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Function>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4361 | return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj)); |
| 4362 | } |
| 4363 | |
| 4364 | |
| 4365 | bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4366 | ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()", |
| 4367 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4368 | i::Object* obj = *Utils::OpenHandle(*value); |
| 4369 | return obj->IsInstanceOf(*Utils::OpenHandle(this)); |
| 4370 | } |
| 4371 | |
| 4372 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4373 | static Local<External> ExternalNewImpl(void* data) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4374 | return Utils::ToLocal(FACTORY->NewForeign(static_cast<i::Address>(data))); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | static void* ExternalValueImpl(i::Handle<i::Object> obj) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4378 | return reinterpret_cast<void*>(i::Foreign::cast(*obj)->foreign_address()); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4379 | } |
| 4380 | |
| 4381 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4382 | Local<Value> v8::External::Wrap(void* data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4383 | i::Isolate* isolate = i::Isolate::Current(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4384 | STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4385 | EnsureInitializedForIsolate(isolate, "v8::External::Wrap()"); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4386 | LOG_API(isolate, "External::Wrap"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4387 | ENTER_V8(isolate); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4388 | |
| 4389 | v8::Local<v8::Value> result = CanBeEncodedAsSmi(data) |
| 4390 | ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data))) |
| 4391 | : v8::Local<v8::Value>(ExternalNewImpl(data)); |
| 4392 | |
| 4393 | ASSERT_EQ(data, Unwrap(result)); |
| 4394 | return result; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4395 | } |
| 4396 | |
| 4397 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4398 | void* v8::Object::SlowGetPointerFromInternalField(int index) { |
| 4399 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4400 | i::Object* value = obj->GetInternalField(index); |
| 4401 | if (value->IsSmi()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4402 | return i::Internals::GetExternalPointerFromSmi(value); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4403 | } else if (value->IsForeign()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4404 | return reinterpret_cast<void*>(i::Foreign::cast(value)->foreign_address()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4405 | } else { |
| 4406 | return NULL; |
| 4407 | } |
| 4408 | } |
| 4409 | |
| 4410 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4411 | void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4412 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Unwrap()")) return 0; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4413 | i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); |
| 4414 | void* result; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4415 | if (obj->IsSmi()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4416 | result = i::Internals::GetExternalPointerFromSmi(*obj); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4417 | } else if (obj->IsForeign()) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4418 | result = ExternalValueImpl(obj); |
| 4419 | } else { |
| 4420 | result = NULL; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4421 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4422 | ASSERT_EQ(result, QuickUnwrap(wrapper)); |
| 4423 | return result; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4424 | } |
| 4425 | |
| 4426 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4427 | Local<External> v8::External::New(void* data) { |
| 4428 | STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4429 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4430 | EnsureInitializedForIsolate(isolate, "v8::External::New()"); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4431 | LOG_API(isolate, "External::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4432 | ENTER_V8(isolate); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4433 | return ExternalNewImpl(data); |
| 4434 | } |
| 4435 | |
| 4436 | |
| 4437 | void* External::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4438 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Value()")) return 0; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4439 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4440 | return ExternalValueImpl(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4444 | Local<String> v8::String::Empty() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4445 | i::Isolate* isolate = i::Isolate::Current(); |
| 4446 | EnsureInitializedForIsolate(isolate, "v8::String::Empty()"); |
| 4447 | LOG_API(isolate, "String::Empty()"); |
| 4448 | return Utils::ToLocal(isolate->factory()->empty_symbol()); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4452 | Local<String> v8::String::New(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4453 | i::Isolate* isolate = i::Isolate::Current(); |
| 4454 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4455 | LOG_API(isolate, "String::New(char)"); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4456 | if (length == 0) return Empty(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4457 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4458 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4459 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4460 | isolate->factory()->NewStringFromUtf8( |
| 4461 | i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4462 | return Utils::ToLocal(result); |
| 4463 | } |
| 4464 | |
| 4465 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4466 | 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] | 4467 | i::Handle<i::String> left_string = Utils::OpenHandle(*left); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4468 | i::Isolate* isolate = left_string->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4469 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4470 | LOG_API(isolate, "String::New(char)"); |
| 4471 | ENTER_V8(isolate); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4472 | i::Handle<i::String> right_string = Utils::OpenHandle(*right); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4473 | i::Handle<i::String> result = isolate->factory()->NewConsString(left_string, |
| 4474 | right_string); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4475 | return Utils::ToLocal(result); |
| 4476 | } |
| 4477 | |
| 4478 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4479 | Local<String> v8::String::NewUndetectable(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4480 | i::Isolate* isolate = i::Isolate::Current(); |
| 4481 | EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()"); |
| 4482 | LOG_API(isolate, "String::NewUndetectable(char)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4483 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4484 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4485 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4486 | isolate->factory()->NewStringFromUtf8( |
| 4487 | i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4488 | result->MarkAsUndetectable(); |
| 4489 | return Utils::ToLocal(result); |
| 4490 | } |
| 4491 | |
| 4492 | |
| 4493 | static int TwoByteStringLength(const uint16_t* data) { |
| 4494 | int length = 0; |
| 4495 | while (data[length] != '\0') length++; |
| 4496 | return length; |
| 4497 | } |
| 4498 | |
| 4499 | |
| 4500 | Local<String> v8::String::New(const uint16_t* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4501 | i::Isolate* isolate = i::Isolate::Current(); |
| 4502 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4503 | LOG_API(isolate, "String::New(uint16_)"); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4504 | if (length == 0) return Empty(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4505 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4506 | if (length == -1) length = TwoByteStringLength(data); |
| 4507 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4508 | isolate->factory()->NewStringFromTwoByte( |
| 4509 | i::Vector<const uint16_t>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4510 | return Utils::ToLocal(result); |
| 4511 | } |
| 4512 | |
| 4513 | |
| 4514 | Local<String> v8::String::NewUndetectable(const uint16_t* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4515 | i::Isolate* isolate = i::Isolate::Current(); |
| 4516 | EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()"); |
| 4517 | LOG_API(isolate, "String::NewUndetectable(uint16_)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4518 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4519 | if (length == -1) length = TwoByteStringLength(data); |
| 4520 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4521 | isolate->factory()->NewStringFromTwoByte( |
| 4522 | i::Vector<const uint16_t>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4523 | result->MarkAsUndetectable(); |
| 4524 | return Utils::ToLocal(result); |
| 4525 | } |
| 4526 | |
| 4527 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4528 | i::Handle<i::String> NewExternalStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4529 | v8::String::ExternalStringResource* resource) { |
| 4530 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4531 | isolate->factory()->NewExternalStringFromTwoByte(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4532 | return result; |
| 4533 | } |
| 4534 | |
| 4535 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4536 | i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4537 | v8::String::ExternalAsciiStringResource* resource) { |
| 4538 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4539 | isolate->factory()->NewExternalStringFromAscii(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4540 | return result; |
| 4541 | } |
| 4542 | |
| 4543 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4544 | Local<String> v8::String::NewExternal( |
| 4545 | v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4546 | i::Isolate* isolate = i::Isolate::Current(); |
| 4547 | EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 4548 | LOG_API(isolate, "String::NewExternal"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4549 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4550 | i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); |
| 4551 | isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4552 | return Utils::ToLocal(result); |
| 4553 | } |
| 4554 | |
| 4555 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4556 | bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4557 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 4558 | i::Isolate* isolate = obj->GetIsolate(); |
| 4559 | if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4560 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 4561 | return false; // Already an external string. |
| 4562 | } |
| 4563 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4564 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 4565 | return false; |
| 4566 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4567 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 4568 | return false; |
| 4569 | } |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4570 | bool result = obj->MakeExternal(resource); |
| 4571 | if (result && !obj->IsSymbol()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4572 | isolate->heap()->external_string_table()->AddString(*obj); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4573 | } |
| 4574 | return result; |
| 4575 | } |
| 4576 | |
| 4577 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4578 | Local<String> v8::String::NewExternal( |
| 4579 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4580 | i::Isolate* isolate = i::Isolate::Current(); |
| 4581 | EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 4582 | LOG_API(isolate, "String::NewExternal"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4583 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4584 | i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); |
| 4585 | isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4586 | return Utils::ToLocal(result); |
| 4587 | } |
| 4588 | |
| 4589 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4590 | bool v8::String::MakeExternal( |
| 4591 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4592 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 4593 | i::Isolate* isolate = obj->GetIsolate(); |
| 4594 | if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4595 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 4596 | return false; // Already an external string. |
| 4597 | } |
| 4598 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4599 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 4600 | return false; |
| 4601 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4602 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 4603 | return false; |
| 4604 | } |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4605 | bool result = obj->MakeExternal(resource); |
| 4606 | if (result && !obj->IsSymbol()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4607 | isolate->heap()->external_string_table()->AddString(*obj); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4608 | } |
| 4609 | return result; |
| 4610 | } |
| 4611 | |
| 4612 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4613 | bool v8::String::CanMakeExternal() { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4614 | if (!internal::FLAG_clever_optimizations) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4615 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4616 | i::Isolate* isolate = obj->GetIsolate(); |
| 4617 | if (IsDeadCheck(isolate, "v8::String::CanMakeExternal()")) return false; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4618 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4619 | int size = obj->Size(); // Byte size of the original string. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4620 | if (size < i::ExternalString::kShortSize) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4621 | i::StringShape shape(*obj); |
| 4622 | return !shape.IsExternal(); |
| 4623 | } |
| 4624 | |
| 4625 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4626 | Local<v8::Object> v8::Object::New() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4627 | i::Isolate* isolate = i::Isolate::Current(); |
| 4628 | EnsureInitializedForIsolate(isolate, "v8::Object::New()"); |
| 4629 | LOG_API(isolate, "Object::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4630 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4631 | i::Handle<i::JSObject> obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4632 | isolate->factory()->NewJSObject(isolate->object_function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4633 | return Utils::ToLocal(obj); |
| 4634 | } |
| 4635 | |
| 4636 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4637 | Local<v8::Value> v8::NumberObject::New(double value) { |
| 4638 | i::Isolate* isolate = i::Isolate::Current(); |
| 4639 | EnsureInitializedForIsolate(isolate, "v8::NumberObject::New()"); |
| 4640 | LOG_API(isolate, "NumberObject::New"); |
| 4641 | ENTER_V8(isolate); |
| 4642 | i::Handle<i::Object> number = isolate->factory()->NewNumber(value); |
| 4643 | i::Handle<i::Object> obj = isolate->factory()->ToObject(number); |
| 4644 | return Utils::ToLocal(obj); |
| 4645 | } |
| 4646 | |
| 4647 | |
| 4648 | double v8::NumberObject::NumberValue() const { |
| 4649 | i::Isolate* isolate = i::Isolate::Current(); |
| 4650 | if (IsDeadCheck(isolate, "v8::NumberObject::NumberValue()")) return 0; |
| 4651 | LOG_API(isolate, "NumberObject::NumberValue"); |
| 4652 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4653 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4654 | return jsvalue->value()->Number(); |
| 4655 | } |
| 4656 | |
| 4657 | |
| 4658 | Local<v8::Value> v8::BooleanObject::New(bool value) { |
| 4659 | i::Isolate* isolate = i::Isolate::Current(); |
| 4660 | EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()"); |
| 4661 | LOG_API(isolate, "BooleanObject::New"); |
| 4662 | ENTER_V8(isolate); |
| 4663 | i::Handle<i::Object> boolean(value ? isolate->heap()->true_value() |
| 4664 | : isolate->heap()->false_value()); |
| 4665 | i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean); |
| 4666 | return Utils::ToLocal(obj); |
| 4667 | } |
| 4668 | |
| 4669 | |
| 4670 | bool v8::BooleanObject::BooleanValue() const { |
| 4671 | i::Isolate* isolate = i::Isolate::Current(); |
| 4672 | if (IsDeadCheck(isolate, "v8::BooleanObject::BooleanValue()")) return 0; |
| 4673 | LOG_API(isolate, "BooleanObject::BooleanValue"); |
| 4674 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4675 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4676 | return jsvalue->value()->IsTrue(); |
| 4677 | } |
| 4678 | |
| 4679 | |
| 4680 | Local<v8::Value> v8::StringObject::New(Handle<String> value) { |
| 4681 | i::Isolate* isolate = i::Isolate::Current(); |
| 4682 | EnsureInitializedForIsolate(isolate, "v8::StringObject::New()"); |
| 4683 | LOG_API(isolate, "StringObject::New"); |
| 4684 | ENTER_V8(isolate); |
| 4685 | i::Handle<i::Object> obj = |
| 4686 | isolate->factory()->ToObject(Utils::OpenHandle(*value)); |
| 4687 | return Utils::ToLocal(obj); |
| 4688 | } |
| 4689 | |
| 4690 | |
| 4691 | Local<v8::String> v8::StringObject::StringValue() const { |
| 4692 | i::Isolate* isolate = i::Isolate::Current(); |
| 4693 | if (IsDeadCheck(isolate, "v8::StringObject::StringValue()")) { |
| 4694 | return Local<v8::String>(); |
| 4695 | } |
| 4696 | LOG_API(isolate, "StringObject::StringValue"); |
| 4697 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4698 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4699 | return Utils::ToLocal( |
| 4700 | i::Handle<i::String>(i::String::cast(jsvalue->value()))); |
| 4701 | } |
| 4702 | |
| 4703 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4704 | Local<v8::Value> v8::Date::New(double time) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4705 | i::Isolate* isolate = i::Isolate::Current(); |
| 4706 | EnsureInitializedForIsolate(isolate, "v8::Date::New()"); |
| 4707 | LOG_API(isolate, "Date::New"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4708 | if (isnan(time)) { |
| 4709 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 4710 | time = i::OS::nan_value(); |
| 4711 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4712 | ENTER_V8(isolate); |
| 4713 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4714 | i::Handle<i::Object> obj = |
| 4715 | i::Execution::NewDate(time, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4716 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4717 | return Utils::ToLocal(obj); |
| 4718 | } |
| 4719 | |
| 4720 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4721 | double v8::Date::NumberValue() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4722 | i::Isolate* isolate = i::Isolate::Current(); |
| 4723 | if (IsDeadCheck(isolate, "v8::Date::NumberValue()")) return 0; |
| 4724 | LOG_API(isolate, "Date::NumberValue"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4725 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4726 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4727 | return jsvalue->value()->Number(); |
| 4728 | } |
| 4729 | |
| 4730 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4731 | void v8::Date::DateTimeConfigurationChangeNotification() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4732 | i::Isolate* isolate = i::Isolate::Current(); |
| 4733 | ON_BAILOUT(isolate, "v8::Date::DateTimeConfigurationChangeNotification()", |
| 4734 | return); |
| 4735 | LOG_API(isolate, "Date::DateTimeConfigurationChangeNotification"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4736 | ENTER_V8(isolate); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4737 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4738 | i::HandleScope scope(isolate); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4739 | // Get the function ResetDateCache (defined in date-delay.js). |
| 4740 | i::Handle<i::String> func_name_str = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4741 | isolate->factory()->LookupAsciiSymbol("ResetDateCache"); |
| 4742 | i::MaybeObject* result = |
| 4743 | isolate->js_builtins_object()->GetProperty(*func_name_str); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4744 | i::Object* object_func; |
| 4745 | if (!result->ToObject(&object_func)) { |
| 4746 | return; |
| 4747 | } |
| 4748 | |
| 4749 | if (object_func->IsJSFunction()) { |
| 4750 | i::Handle<i::JSFunction> func = |
| 4751 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_func)); |
| 4752 | |
| 4753 | // Call ResetDateCache(0 but expect no exceptions: |
| 4754 | bool caught_exception = false; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4755 | i::Execution::TryCall(func, |
| 4756 | isolate->js_builtins_object(), |
| 4757 | 0, |
| 4758 | NULL, |
| 4759 | &caught_exception); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4760 | } |
| 4761 | } |
| 4762 | |
| 4763 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4764 | static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { |
| 4765 | char flags_buf[3]; |
| 4766 | int num_flags = 0; |
| 4767 | if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; |
| 4768 | if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; |
| 4769 | if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; |
| 4770 | ASSERT(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4771 | return FACTORY->LookupSymbol( |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4772 | i::Vector<const char>(flags_buf, num_flags)); |
| 4773 | } |
| 4774 | |
| 4775 | |
| 4776 | Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, |
| 4777 | Flags flags) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4778 | i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4779 | EnsureInitializedForIsolate(isolate, "v8::RegExp::New()"); |
| 4780 | LOG_API(isolate, "RegExp::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4781 | ENTER_V8(isolate); |
| 4782 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4783 | i::Handle<i::JSRegExp> obj = i::Execution::NewJSRegExp( |
| 4784 | Utils::OpenHandle(*pattern), |
| 4785 | RegExpFlagsToString(flags), |
| 4786 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4787 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::RegExp>()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4788 | return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj)); |
| 4789 | } |
| 4790 | |
| 4791 | |
| 4792 | Local<v8::String> v8::RegExp::GetSource() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4793 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4794 | if (IsDeadCheck(isolate, "v8::RegExp::GetSource()")) { |
| 4795 | return Local<v8::String>(); |
| 4796 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4797 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 4798 | return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); |
| 4799 | } |
| 4800 | |
| 4801 | |
| 4802 | // Assert that the static flags cast in GetFlags is valid. |
| 4803 | #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ |
| 4804 | STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ |
| 4805 | static_cast<int>(i::JSRegExp::internal_flag)) |
| 4806 | REGEXP_FLAG_ASSERT_EQ(kNone, NONE); |
| 4807 | REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL); |
| 4808 | REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE); |
| 4809 | REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE); |
| 4810 | #undef REGEXP_FLAG_ASSERT_EQ |
| 4811 | |
| 4812 | v8::RegExp::Flags v8::RegExp::GetFlags() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4813 | if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::GetFlags()")) { |
| 4814 | return v8::RegExp::kNone; |
| 4815 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4816 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 4817 | return static_cast<RegExp::Flags>(obj->GetFlags().value()); |
| 4818 | } |
| 4819 | |
| 4820 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4821 | Local<v8::Array> v8::Array::New(int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4822 | i::Isolate* isolate = i::Isolate::Current(); |
| 4823 | EnsureInitializedForIsolate(isolate, "v8::Array::New()"); |
| 4824 | LOG_API(isolate, "Array::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4825 | ENTER_V8(isolate); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4826 | int real_length = length > 0 ? length : 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4827 | i::Handle<i::JSArray> obj = isolate->factory()->NewJSArray(real_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4828 | i::Handle<i::Object> length_obj = |
| 4829 | isolate->factory()->NewNumberFromInt(real_length); |
| 4830 | obj->set_length(*length_obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4831 | return Utils::ToLocal(obj); |
| 4832 | } |
| 4833 | |
| 4834 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4835 | uint32_t v8::Array::Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4836 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4837 | if (IsDeadCheck(isolate, "v8::Array::Length()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4838 | i::Handle<i::JSArray> obj = Utils::OpenHandle(this); |
| 4839 | i::Object* length = obj->length(); |
| 4840 | if (length->IsSmi()) { |
| 4841 | return i::Smi::cast(length)->value(); |
| 4842 | } else { |
| 4843 | return static_cast<uint32_t>(length->Number()); |
| 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4848 | Local<Object> Array::CloneElementAt(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4849 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4850 | ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4851 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 4852 | if (!self->HasFastElements()) { |
| 4853 | return Local<Object>(); |
| 4854 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4855 | i::FixedArray* elms = i::FixedArray::cast(self->elements()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4856 | i::Object* paragon = elms->get(index); |
| 4857 | if (!paragon->IsJSObject()) { |
| 4858 | return Local<Object>(); |
| 4859 | } |
| 4860 | i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4861 | EXCEPTION_PREAMBLE(isolate); |
| 4862 | ENTER_V8(isolate); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4863 | i::Handle<i::JSObject> result = i::Copy(paragon_handle); |
| 4864 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4865 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4866 | return Utils::ToLocal(result); |
| 4867 | } |
| 4868 | |
| 4869 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4870 | Local<String> v8::String::NewSymbol(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4871 | i::Isolate* isolate = i::Isolate::Current(); |
| 4872 | EnsureInitializedForIsolate(isolate, "v8::String::NewSymbol()"); |
| 4873 | LOG_API(isolate, "String::NewSymbol(char)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4874 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4875 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4876 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4877 | isolate->factory()->LookupSymbol(i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4878 | return Utils::ToLocal(result); |
| 4879 | } |
| 4880 | |
| 4881 | |
| 4882 | Local<Number> v8::Number::New(double value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4883 | i::Isolate* isolate = i::Isolate::Current(); |
| 4884 | EnsureInitializedForIsolate(isolate, "v8::Number::New()"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4885 | if (isnan(value)) { |
| 4886 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 4887 | value = i::OS::nan_value(); |
| 4888 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4889 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4890 | i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4891 | return Utils::NumberToLocal(result); |
| 4892 | } |
| 4893 | |
| 4894 | |
| 4895 | Local<Integer> v8::Integer::New(int32_t value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4896 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 4897 | EnsureInitializedForIsolate(isolate, "v8::Integer::New()"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4898 | if (i::Smi::IsValid(value)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4899 | return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value), |
| 4900 | isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4901 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4902 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4903 | i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4904 | return Utils::IntegerToLocal(result); |
| 4905 | } |
| 4906 | |
| 4907 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4908 | Local<Integer> Integer::NewFromUnsigned(uint32_t value) { |
| 4909 | bool fits_into_int32_t = (value & (1 << 31)) == 0; |
| 4910 | if (fits_into_int32_t) { |
| 4911 | return Integer::New(static_cast<int32_t>(value)); |
| 4912 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4913 | i::Isolate* isolate = i::Isolate::Current(); |
| 4914 | ENTER_V8(isolate); |
| 4915 | i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4916 | return Utils::IntegerToLocal(result); |
| 4917 | } |
| 4918 | |
| 4919 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4920 | void V8::IgnoreOutOfMemoryException() { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4921 | EnterIsolateIfNeeded()->set_ignore_out_of_memory(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | |
| 4925 | bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4926 | i::Isolate* isolate = i::Isolate::Current(); |
| 4927 | EnsureInitializedForIsolate(isolate, "v8::V8::AddMessageListener()"); |
| 4928 | ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4929 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4930 | i::HandleScope scope(isolate); |
| 4931 | NeanderArray listeners(isolate->factory()->message_listeners()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4932 | NeanderObject obj(2); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4933 | obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4934 | obj.set(1, data.IsEmpty() ? |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4935 | isolate->heap()->undefined_value() : |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4936 | *Utils::OpenHandle(*data)); |
| 4937 | listeners.add(obj.value()); |
| 4938 | return true; |
| 4939 | } |
| 4940 | |
| 4941 | |
| 4942 | void V8::RemoveMessageListeners(MessageCallback that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4943 | i::Isolate* isolate = i::Isolate::Current(); |
| 4944 | EnsureInitializedForIsolate(isolate, "v8::V8::RemoveMessageListener()"); |
| 4945 | ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4946 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4947 | i::HandleScope scope(isolate); |
| 4948 | NeanderArray listeners(isolate->factory()->message_listeners()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4949 | for (int i = 0; i < listeners.length(); i++) { |
| 4950 | if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones |
| 4951 | |
| 4952 | NeanderObject listener(i::JSObject::cast(listeners.get(i))); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4953 | i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4954 | if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4955 | listeners.set(i, isolate->heap()->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4956 | } |
| 4957 | } |
| 4958 | } |
| 4959 | |
| 4960 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4961 | void V8::SetCaptureStackTraceForUncaughtExceptions( |
| 4962 | bool capture, |
| 4963 | int frame_limit, |
| 4964 | StackTrace::StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4965 | i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions( |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4966 | capture, |
| 4967 | frame_limit, |
| 4968 | options); |
| 4969 | } |
| 4970 | |
| 4971 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4972 | void V8::SetCounterFunction(CounterLookupCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 4973 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4974 | if (IsDeadCheck(isolate, "v8::V8::SetCounterFunction()")) return; |
| 4975 | isolate->stats_table()->SetCounterFunction(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4976 | } |
| 4977 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4978 | void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 4979 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4980 | if (IsDeadCheck(isolate, "v8::V8::SetCreateHistogramFunction()")) return; |
| 4981 | isolate->stats_table()->SetCreateHistogramFunction(callback); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4982 | } |
| 4983 | |
| 4984 | void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 4985 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4986 | if (IsDeadCheck(isolate, "v8::V8::SetAddHistogramSampleFunction()")) return; |
| 4987 | isolate->stats_table()-> |
| 4988 | SetAddHistogramSampleFunction(callback); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4989 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4990 | |
| 4991 | void V8::EnableSlidingStateWindow() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4992 | i::Isolate* isolate = i::Isolate::Current(); |
| 4993 | if (IsDeadCheck(isolate, "v8::V8::EnableSlidingStateWindow()")) return; |
| 4994 | isolate->logger()->EnableSlidingStateWindow(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4995 | } |
| 4996 | |
| 4997 | |
| 4998 | void V8::SetFailedAccessCheckCallbackFunction( |
| 4999 | FailedAccessCheckCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5000 | i::Isolate* isolate = i::Isolate::Current(); |
| 5001 | if (IsDeadCheck(isolate, "v8::V8::SetFailedAccessCheckCallbackFunction()")) { |
| 5002 | return; |
| 5003 | } |
| 5004 | isolate->SetFailedAccessCheckCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5005 | } |
| 5006 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5007 | void V8::AddObjectGroup(Persistent<Value>* objects, |
| 5008 | size_t length, |
| 5009 | RetainedObjectInfo* info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5010 | i::Isolate* isolate = i::Isolate::Current(); |
| 5011 | if (IsDeadCheck(isolate, "v8::V8::AddObjectGroup()")) return; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 5012 | STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5013 | isolate->global_handles()->AddObjectGroup( |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5014 | reinterpret_cast<i::Object***>(objects), length, info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5018 | void V8::AddImplicitReferences(Persistent<Object> parent, |
| 5019 | Persistent<Value>* children, |
| 5020 | size_t length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5021 | i::Isolate* isolate = i::Isolate::Current(); |
| 5022 | if (IsDeadCheck(isolate, "v8::V8::AddImplicitReferences()")) return; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5023 | STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5024 | isolate->global_handles()->AddImplicitReferences( |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 5025 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(*parent)).location(), |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5026 | reinterpret_cast<i::Object***>(children), length); |
| 5027 | } |
| 5028 | |
| 5029 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 5030 | int V8::AdjustAmountOfExternalAllocatedMemory(int change_in_bytes) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5031 | i::Isolate* isolate = i::Isolate::Current(); |
| 5032 | if (IsDeadCheck(isolate, "v8::V8::AdjustAmountOfExternalAllocatedMemory()")) { |
| 5033 | return 0; |
| 5034 | } |
| 5035 | return isolate->heap()->AdjustAmountOfExternalAllocatedMemory( |
| 5036 | change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5040 | void V8::SetGlobalGCPrologueCallback(GCCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5041 | i::Isolate* isolate = i::Isolate::Current(); |
| 5042 | if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return; |
| 5043 | isolate->heap()->SetGlobalGCPrologueCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | |
| 5047 | void V8::SetGlobalGCEpilogueCallback(GCCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5048 | i::Isolate* isolate = i::Isolate::Current(); |
| 5049 | if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCEpilogueCallback()")) return; |
| 5050 | isolate->heap()->SetGlobalGCEpilogueCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5054 | void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5055 | i::Isolate* isolate = i::Isolate::Current(); |
| 5056 | if (IsDeadCheck(isolate, "v8::V8::AddGCPrologueCallback()")) return; |
| 5057 | isolate->heap()->AddGCPrologueCallback(callback, gc_type); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5058 | } |
| 5059 | |
| 5060 | |
| 5061 | void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5062 | i::Isolate* isolate = i::Isolate::Current(); |
| 5063 | if (IsDeadCheck(isolate, "v8::V8::RemoveGCPrologueCallback()")) return; |
| 5064 | isolate->heap()->RemoveGCPrologueCallback(callback); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5065 | } |
| 5066 | |
| 5067 | |
| 5068 | void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5069 | i::Isolate* isolate = i::Isolate::Current(); |
| 5070 | if (IsDeadCheck(isolate, "v8::V8::AddGCEpilogueCallback()")) return; |
| 5071 | isolate->heap()->AddGCEpilogueCallback(callback, gc_type); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | |
| 5075 | void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5076 | i::Isolate* isolate = i::Isolate::Current(); |
| 5077 | if (IsDeadCheck(isolate, "v8::V8::RemoveGCEpilogueCallback()")) return; |
| 5078 | isolate->heap()->RemoveGCEpilogueCallback(callback); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5082 | void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 5083 | ObjectSpace space, |
| 5084 | AllocationAction action) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5085 | i::Isolate* isolate = i::Isolate::Current(); |
| 5086 | if (IsDeadCheck(isolate, "v8::V8::AddMemoryAllocationCallback()")) return; |
| 5087 | isolate->memory_allocator()->AddMemoryAllocationCallback( |
| 5088 | callback, space, action); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | |
| 5092 | void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5093 | i::Isolate* isolate = i::Isolate::Current(); |
| 5094 | if (IsDeadCheck(isolate, "v8::V8::RemoveMemoryAllocationCallback()")) return; |
| 5095 | isolate->memory_allocator()->RemoveMemoryAllocationCallback( |
| 5096 | callback); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5100 | void V8::AddCallCompletedCallback(CallCompletedCallback callback) { |
| 5101 | if (callback == NULL) return; |
| 5102 | i::Isolate* isolate = i::Isolate::Current(); |
| 5103 | if (IsDeadCheck(isolate, "v8::V8::AddLeaveScriptCallback()")) return; |
| 5104 | i::V8::AddCallCompletedCallback(callback); |
| 5105 | } |
| 5106 | |
| 5107 | |
| 5108 | void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) { |
| 5109 | i::Isolate* isolate = i::Isolate::Current(); |
| 5110 | if (IsDeadCheck(isolate, "v8::V8::RemoveLeaveScriptCallback()")) return; |
| 5111 | i::V8::RemoveCallCompletedCallback(callback); |
| 5112 | } |
| 5113 | |
| 5114 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5115 | void V8::PauseProfiler() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 5116 | i::Isolate* isolate = i::Isolate::Current(); |
| 5117 | isolate->logger()->PauseProfiler(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5118 | } |
| 5119 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5120 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5121 | void V8::ResumeProfiler() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 5122 | i::Isolate* isolate = i::Isolate::Current(); |
| 5123 | isolate->logger()->ResumeProfiler(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5124 | } |
| 5125 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5126 | |
| 5127 | bool V8::IsProfilerPaused() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 5128 | i::Isolate* isolate = i::Isolate::Current(); |
| 5129 | return isolate->logger()->IsProfilerPaused(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 5130 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5131 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5132 | |
| 5133 | int V8::GetCurrentThreadId() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5134 | i::Isolate* isolate = i::Isolate::Current(); |
| 5135 | EnsureInitializedForIsolate(isolate, "V8::GetCurrentThreadId()"); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5136 | return isolate->thread_id().ToInteger(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5137 | } |
| 5138 | |
| 5139 | |
| 5140 | void V8::TerminateExecution(int thread_id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5141 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5142 | if (!isolate->IsInitialized()) return; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 5143 | API_ENTRY_CHECK(isolate, "V8::TerminateExecution()"); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5144 | // If the thread_id identifies the current thread just terminate |
| 5145 | // execution right away. Otherwise, ask the thread manager to |
| 5146 | // terminate the thread with the given id if any. |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5147 | i::ThreadId internal_tid = i::ThreadId::FromInteger(thread_id); |
| 5148 | if (isolate->thread_id().Equals(internal_tid)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5149 | isolate->stack_guard()->TerminateExecution(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5150 | } else { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5151 | isolate->thread_manager()->TerminateExecution(internal_tid); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5152 | } |
| 5153 | } |
| 5154 | |
| 5155 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5156 | void V8::TerminateExecution(Isolate* isolate) { |
| 5157 | // If no isolate is supplied, use the default isolate. |
| 5158 | if (isolate != NULL) { |
| 5159 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution(); |
| 5160 | } else { |
| 5161 | i::Isolate::GetDefaultIsolateStackGuard()->TerminateExecution(); |
| 5162 | } |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5163 | } |
| 5164 | |
| 5165 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5166 | bool V8::IsExecutionTerminating(Isolate* isolate) { |
| 5167 | i::Isolate* i_isolate = isolate != NULL ? |
| 5168 | reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current(); |
| 5169 | return IsExecutionTerminatingCheck(i_isolate); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 5170 | } |
| 5171 | |
| 5172 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5173 | Isolate* Isolate::GetCurrent() { |
| 5174 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 5175 | return reinterpret_cast<Isolate*>(isolate); |
| 5176 | } |
| 5177 | |
| 5178 | |
| 5179 | Isolate* Isolate::New() { |
| 5180 | i::Isolate* isolate = new i::Isolate(); |
| 5181 | return reinterpret_cast<Isolate*>(isolate); |
| 5182 | } |
| 5183 | |
| 5184 | |
| 5185 | void Isolate::Dispose() { |
| 5186 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5187 | if (!ApiCheck(!isolate->IsInUse(), |
| 5188 | "v8::Isolate::Dispose()", |
| 5189 | "Disposing the isolate that is entered by a thread.")) { |
| 5190 | return; |
| 5191 | } |
| 5192 | isolate->TearDown(); |
| 5193 | } |
| 5194 | |
| 5195 | |
| 5196 | void Isolate::Enter() { |
| 5197 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5198 | isolate->Enter(); |
| 5199 | } |
| 5200 | |
| 5201 | |
| 5202 | void Isolate::Exit() { |
| 5203 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5204 | isolate->Exit(); |
| 5205 | } |
| 5206 | |
| 5207 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5208 | void Isolate::SetData(void* data) { |
| 5209 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5210 | isolate->SetData(data); |
| 5211 | } |
| 5212 | |
| 5213 | void* Isolate::GetData() { |
| 5214 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5215 | return isolate->GetData(); |
| 5216 | } |
| 5217 | |
| 5218 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5219 | String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) |
| 5220 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5221 | i::Isolate* isolate = i::Isolate::Current(); |
| 5222 | if (IsDeadCheck(isolate, "v8::String::Utf8Value::Utf8Value()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5223 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5224 | ENTER_V8(isolate); |
| 5225 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5226 | TryCatch try_catch; |
| 5227 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5228 | if (str.IsEmpty()) return; |
| 5229 | length_ = str->Utf8Length(); |
| 5230 | str_ = i::NewArray<char>(length_ + 1); |
| 5231 | str->WriteUtf8(str_); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | |
| 5235 | String::Utf8Value::~Utf8Value() { |
| 5236 | i::DeleteArray(str_); |
| 5237 | } |
| 5238 | |
| 5239 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5240 | String::AsciiValue::AsciiValue(v8::Handle<v8::Value> obj) |
| 5241 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5242 | i::Isolate* isolate = i::Isolate::Current(); |
| 5243 | if (IsDeadCheck(isolate, "v8::String::AsciiValue::AsciiValue()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5244 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5245 | ENTER_V8(isolate); |
| 5246 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5247 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5248 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5249 | if (str.IsEmpty()) return; |
| 5250 | length_ = str->Length(); |
| 5251 | str_ = i::NewArray<char>(length_ + 1); |
| 5252 | str->WriteAscii(str_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
| 5255 | |
| 5256 | String::AsciiValue::~AsciiValue() { |
| 5257 | i::DeleteArray(str_); |
| 5258 | } |
| 5259 | |
| 5260 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5261 | String::Value::Value(v8::Handle<v8::Value> obj) |
| 5262 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5263 | i::Isolate* isolate = i::Isolate::Current(); |
| 5264 | if (IsDeadCheck(isolate, "v8::String::Value::Value()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5265 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5266 | ENTER_V8(isolate); |
| 5267 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5268 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5269 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5270 | if (str.IsEmpty()) return; |
| 5271 | length_ = str->Length(); |
| 5272 | str_ = i::NewArray<uint16_t>(length_ + 1); |
| 5273 | str->Write(str_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | |
| 5277 | String::Value::~Value() { |
| 5278 | i::DeleteArray(str_); |
| 5279 | } |
| 5280 | |
| 5281 | Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5282 | i::Isolate* isolate = i::Isolate::Current(); |
| 5283 | LOG_API(isolate, "RangeError"); |
| 5284 | ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5285 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5286 | i::Object* error; |
| 5287 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5288 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5289 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5290 | i::Handle<i::Object> result = isolate->factory()->NewRangeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5291 | error = *result; |
| 5292 | } |
| 5293 | i::Handle<i::Object> result(error); |
| 5294 | return Utils::ToLocal(result); |
| 5295 | } |
| 5296 | |
| 5297 | Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5298 | i::Isolate* isolate = i::Isolate::Current(); |
| 5299 | LOG_API(isolate, "ReferenceError"); |
| 5300 | ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5301 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5302 | i::Object* error; |
| 5303 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5304 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5305 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5306 | i::Handle<i::Object> result = |
| 5307 | isolate->factory()->NewReferenceError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5308 | error = *result; |
| 5309 | } |
| 5310 | i::Handle<i::Object> result(error); |
| 5311 | return Utils::ToLocal(result); |
| 5312 | } |
| 5313 | |
| 5314 | Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5315 | i::Isolate* isolate = i::Isolate::Current(); |
| 5316 | LOG_API(isolate, "SyntaxError"); |
| 5317 | ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5318 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5319 | i::Object* error; |
| 5320 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5321 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5322 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5323 | i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5324 | error = *result; |
| 5325 | } |
| 5326 | i::Handle<i::Object> result(error); |
| 5327 | return Utils::ToLocal(result); |
| 5328 | } |
| 5329 | |
| 5330 | Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5331 | i::Isolate* isolate = i::Isolate::Current(); |
| 5332 | LOG_API(isolate, "TypeError"); |
| 5333 | ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5334 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5335 | i::Object* error; |
| 5336 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5337 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5338 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5339 | i::Handle<i::Object> result = isolate->factory()->NewTypeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5340 | error = *result; |
| 5341 | } |
| 5342 | i::Handle<i::Object> result(error); |
| 5343 | return Utils::ToLocal(result); |
| 5344 | } |
| 5345 | |
| 5346 | Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5347 | i::Isolate* isolate = i::Isolate::Current(); |
| 5348 | LOG_API(isolate, "Error"); |
| 5349 | ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5350 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5351 | i::Object* error; |
| 5352 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5353 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5354 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5355 | i::Handle<i::Object> result = isolate->factory()->NewError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5356 | error = *result; |
| 5357 | } |
| 5358 | i::Handle<i::Object> result(error); |
| 5359 | return Utils::ToLocal(result); |
| 5360 | } |
| 5361 | |
| 5362 | |
| 5363 | // --- D e b u g S u p p o r t --- |
| 5364 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5365 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5366 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5367 | static void EventCallbackWrapper(const v8::Debug::EventDetails& event_details) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5368 | i::Isolate* isolate = i::Isolate::Current(); |
| 5369 | if (isolate->debug_event_callback() != NULL) { |
| 5370 | isolate->debug_event_callback()(event_details.GetEvent(), |
| 5371 | event_details.GetExecutionState(), |
| 5372 | event_details.GetEventData(), |
| 5373 | event_details.GetCallbackData()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5374 | } |
| 5375 | } |
| 5376 | |
| 5377 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5378 | bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5379 | i::Isolate* isolate = i::Isolate::Current(); |
| 5380 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener()"); |
| 5381 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5382 | ENTER_V8(isolate); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5383 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5384 | isolate->set_debug_event_callback(that); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5385 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5386 | i::HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5387 | i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5388 | if (that != NULL) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5389 | foreign = |
| 5390 | isolate->factory()->NewForeign(FUNCTION_ADDR(EventCallbackWrapper)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5391 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5392 | isolate->debugger()->SetEventListener(foreign, Utils::OpenHandle(*data)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5393 | return true; |
| 5394 | } |
| 5395 | |
| 5396 | |
| 5397 | bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5398 | i::Isolate* isolate = i::Isolate::Current(); |
| 5399 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()"); |
| 5400 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5401 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5402 | i::HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5403 | i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5404 | if (that != NULL) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5405 | foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5406 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5407 | isolate->debugger()->SetEventListener(foreign, Utils::OpenHandle(*data)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5408 | return true; |
| 5409 | } |
| 5410 | |
| 5411 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5412 | bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5413 | Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5414 | i::Isolate* isolate = i::Isolate::Current(); |
| 5415 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5416 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5417 | isolate->debugger()->SetEventListener(Utils::OpenHandle(*that), |
| 5418 | Utils::OpenHandle(*data)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5419 | return true; |
| 5420 | } |
| 5421 | |
| 5422 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5423 | void Debug::DebugBreak(Isolate* isolate) { |
| 5424 | // If no isolate is supplied, use the default isolate. |
| 5425 | if (isolate != NULL) { |
| 5426 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->DebugBreak(); |
| 5427 | } else { |
| 5428 | i::Isolate::GetDefaultIsolateStackGuard()->DebugBreak(); |
| 5429 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5433 | void Debug::CancelDebugBreak(Isolate* isolate) { |
| 5434 | // If no isolate is supplied, use the default isolate. |
| 5435 | if (isolate != NULL) { |
| 5436 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5437 | internal_isolate->stack_guard()->Continue(i::DEBUGBREAK); |
| 5438 | } else { |
| 5439 | i::Isolate::GetDefaultIsolateStackGuard()->Continue(i::DEBUGBREAK); |
| 5440 | } |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 5441 | } |
| 5442 | |
| 5443 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5444 | void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) { |
| 5445 | // If no isolate is supplied, use the default isolate. |
| 5446 | if (isolate != NULL) { |
| 5447 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5448 | internal_isolate->debugger()->EnqueueDebugCommand(data); |
| 5449 | } else { |
| 5450 | i::Isolate::GetDefaultIsolateDebugger()->EnqueueDebugCommand(data); |
| 5451 | } |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 5452 | } |
| 5453 | |
| 5454 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5455 | static void MessageHandlerWrapper(const v8::Debug::Message& message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5456 | i::Isolate* isolate = i::Isolate::Current(); |
| 5457 | if (isolate->message_handler()) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5458 | v8::String::Value json(message.GetJSON()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5459 | (isolate->message_handler())(*json, json.length(), message.GetClientData()); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5464 | void Debug::SetMessageHandler(v8::Debug::MessageHandler handler, |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5465 | bool message_handler_thread) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5466 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5467 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); |
| 5468 | ENTER_V8(isolate); |
| 5469 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5470 | // Message handler thread not supported any more. Parameter temporally left in |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5471 | // the API for client compatibility reasons. |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5472 | CHECK(!message_handler_thread); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5473 | |
| 5474 | // 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] | 5475 | isolate->set_message_handler(handler); |
| 5476 | if (handler != NULL) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5477 | isolate->debugger()->SetMessageHandler(MessageHandlerWrapper); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5478 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5479 | isolate->debugger()->SetMessageHandler(NULL); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5480 | } |
| 5481 | } |
| 5482 | |
| 5483 | |
| 5484 | void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5485 | i::Isolate* isolate = i::Isolate::Current(); |
| 5486 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); |
| 5487 | ENTER_V8(isolate); |
| 5488 | isolate->debugger()->SetMessageHandler(handler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5489 | } |
| 5490 | |
| 5491 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5492 | void Debug::SendCommand(const uint16_t* command, int length, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5493 | ClientData* client_data, |
| 5494 | Isolate* isolate) { |
| 5495 | // If no isolate is supplied, use the default isolate. |
| 5496 | if (isolate != NULL) { |
| 5497 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5498 | internal_isolate->debugger()->ProcessCommand( |
| 5499 | i::Vector<const uint16_t>(command, length), client_data); |
| 5500 | } else { |
| 5501 | i::Isolate::GetDefaultIsolateDebugger()->ProcessCommand( |
| 5502 | i::Vector<const uint16_t>(command, length), client_data); |
| 5503 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5504 | } |
| 5505 | |
| 5506 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5507 | void Debug::SetHostDispatchHandler(HostDispatchHandler handler, |
| 5508 | int period) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5509 | i::Isolate* isolate = i::Isolate::Current(); |
| 5510 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetHostDispatchHandler"); |
| 5511 | ENTER_V8(isolate); |
| 5512 | isolate->debugger()->SetHostDispatchHandler(handler, period); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5516 | void Debug::SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5517 | DebugMessageDispatchHandler handler, bool provide_locker) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5518 | i::Isolate* isolate = i::Isolate::Current(); |
| 5519 | EnsureInitializedForIsolate(isolate, |
| 5520 | "v8::Debug::SetDebugMessageDispatchHandler"); |
| 5521 | ENTER_V8(isolate); |
| 5522 | isolate->debugger()->SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5523 | handler, provide_locker); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5524 | } |
| 5525 | |
| 5526 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5527 | Local<Value> Debug::Call(v8::Handle<v8::Function> fun, |
| 5528 | v8::Handle<v8::Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5529 | i::Isolate* isolate = i::Isolate::Current(); |
| 5530 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 5531 | ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5532 | ENTER_V8(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5533 | i::Handle<i::Object> result; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5534 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5535 | if (data.IsEmpty()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5536 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 5537 | isolate->factory()->undefined_value(), |
| 5538 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5539 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5540 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 5541 | Utils::OpenHandle(*data), |
| 5542 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5543 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5544 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5545 | return Utils::ToLocal(result); |
| 5546 | } |
| 5547 | |
| 5548 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5549 | Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5550 | i::Isolate* isolate = i::Isolate::Current(); |
| 5551 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 5552 | ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5553 | ENTER_V8(isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5554 | v8::HandleScope scope; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5555 | i::Debug* isolate_debug = isolate->debug(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5556 | isolate_debug->Load(); |
| 5557 | i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global()); |
| 5558 | i::Handle<i::String> name = |
| 5559 | isolate->factory()->LookupAsciiSymbol("MakeMirror"); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5560 | i::Handle<i::Object> fun_obj = i::GetProperty(debug, name); |
| 5561 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj); |
| 5562 | v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun); |
| 5563 | const int kArgc = 1; |
| 5564 | v8::Handle<v8::Value> argv[kArgc] = { obj }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5565 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5566 | v8::Handle<v8::Value> result = v8_fun->Call(Utils::ToLocal(debug), |
| 5567 | kArgc, |
| 5568 | argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5569 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5570 | return scope.Close(result); |
| 5571 | } |
| 5572 | |
| 5573 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5574 | 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] | 5575 | return i::Isolate::Current()->debugger()->StartAgent(name, port, |
| 5576 | wait_for_connection); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5577 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5578 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5579 | |
| 5580 | void Debug::DisableAgent() { |
| 5581 | return i::Isolate::Current()->debugger()->StopAgent(); |
| 5582 | } |
| 5583 | |
| 5584 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5585 | void Debug::ProcessDebugMessages() { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5586 | i::Execution::ProcessDebugMessages(true); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5587 | } |
| 5588 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 5589 | Local<Context> Debug::GetDebugContext() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5590 | i::Isolate* isolate = i::Isolate::Current(); |
| 5591 | EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()"); |
| 5592 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5593 | return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext()); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 5594 | } |
| 5595 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5596 | #endif // ENABLE_DEBUGGER_SUPPORT |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5597 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5598 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5599 | Handle<String> CpuProfileNode::GetFunctionName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5600 | i::Isolate* isolate = i::Isolate::Current(); |
| 5601 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetFunctionName"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5602 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
| 5603 | const i::CodeEntry* entry = node->entry(); |
| 5604 | if (!entry->has_name_prefix()) { |
| 5605 | return Handle<String>(ToApi<String>( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5606 | isolate->factory()->LookupAsciiSymbol(entry->name()))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5607 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5608 | return Handle<String>(ToApi<String>(isolate->factory()->NewConsString( |
| 5609 | isolate->factory()->LookupAsciiSymbol(entry->name_prefix()), |
| 5610 | isolate->factory()->LookupAsciiSymbol(entry->name())))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5611 | } |
| 5612 | } |
| 5613 | |
| 5614 | |
| 5615 | Handle<String> CpuProfileNode::GetScriptResourceName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5616 | i::Isolate* isolate = i::Isolate::Current(); |
| 5617 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetScriptResourceName"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5618 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5619 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5620 | node->entry()->resource_name()))); |
| 5621 | } |
| 5622 | |
| 5623 | |
| 5624 | int CpuProfileNode::GetLineNumber() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5625 | i::Isolate* isolate = i::Isolate::Current(); |
| 5626 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetLineNumber"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5627 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number(); |
| 5628 | } |
| 5629 | |
| 5630 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5631 | double CpuProfileNode::GetTotalTime() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5632 | i::Isolate* isolate = i::Isolate::Current(); |
| 5633 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalTime"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5634 | return reinterpret_cast<const i::ProfileNode*>(this)->GetTotalMillis(); |
| 5635 | } |
| 5636 | |
| 5637 | |
| 5638 | double CpuProfileNode::GetSelfTime() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5639 | i::Isolate* isolate = i::Isolate::Current(); |
| 5640 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfTime"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5641 | return reinterpret_cast<const i::ProfileNode*>(this)->GetSelfMillis(); |
| 5642 | } |
| 5643 | |
| 5644 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5645 | double CpuProfileNode::GetTotalSamplesCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5646 | i::Isolate* isolate = i::Isolate::Current(); |
| 5647 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalSamplesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5648 | return reinterpret_cast<const i::ProfileNode*>(this)->total_ticks(); |
| 5649 | } |
| 5650 | |
| 5651 | |
| 5652 | double CpuProfileNode::GetSelfSamplesCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5653 | i::Isolate* isolate = i::Isolate::Current(); |
| 5654 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfSamplesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5655 | return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks(); |
| 5656 | } |
| 5657 | |
| 5658 | |
| 5659 | unsigned CpuProfileNode::GetCallUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5660 | i::Isolate* isolate = i::Isolate::Current(); |
| 5661 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetCallUid"); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 5662 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5663 | } |
| 5664 | |
| 5665 | |
| 5666 | int CpuProfileNode::GetChildrenCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5667 | i::Isolate* isolate = i::Isolate::Current(); |
| 5668 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetChildrenCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5669 | return reinterpret_cast<const i::ProfileNode*>(this)->children()->length(); |
| 5670 | } |
| 5671 | |
| 5672 | |
| 5673 | const CpuProfileNode* CpuProfileNode::GetChild(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5674 | i::Isolate* isolate = i::Isolate::Current(); |
| 5675 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetChild"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5676 | const i::ProfileNode* child = |
| 5677 | reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index); |
| 5678 | return reinterpret_cast<const CpuProfileNode*>(child); |
| 5679 | } |
| 5680 | |
| 5681 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5682 | void CpuProfile::Delete() { |
| 5683 | i::Isolate* isolate = i::Isolate::Current(); |
| 5684 | IsDeadCheck(isolate, "v8::CpuProfile::Delete"); |
| 5685 | i::CpuProfiler::DeleteProfile(reinterpret_cast<i::CpuProfile*>(this)); |
| 5686 | if (i::CpuProfiler::GetProfilesCount() == 0 && |
| 5687 | !i::CpuProfiler::HasDetachedProfiles()) { |
| 5688 | // If this was the last profile, clean up all accessory data as well. |
| 5689 | i::CpuProfiler::DeleteAllProfiles(); |
| 5690 | } |
| 5691 | } |
| 5692 | |
| 5693 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5694 | unsigned CpuProfile::GetUid() 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::CpuProfile::GetUid"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5697 | return reinterpret_cast<const i::CpuProfile*>(this)->uid(); |
| 5698 | } |
| 5699 | |
| 5700 | |
| 5701 | Handle<String> CpuProfile::GetTitle() 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::CpuProfile::GetTitle"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5704 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5705 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5706 | profile->title()))); |
| 5707 | } |
| 5708 | |
| 5709 | |
| 5710 | const CpuProfileNode* CpuProfile::GetBottomUpRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5711 | i::Isolate* isolate = i::Isolate::Current(); |
| 5712 | IsDeadCheck(isolate, "v8::CpuProfile::GetBottomUpRoot"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5713 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 5714 | return reinterpret_cast<const CpuProfileNode*>(profile->bottom_up()->root()); |
| 5715 | } |
| 5716 | |
| 5717 | |
| 5718 | const CpuProfileNode* CpuProfile::GetTopDownRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5719 | i::Isolate* isolate = i::Isolate::Current(); |
| 5720 | IsDeadCheck(isolate, "v8::CpuProfile::GetTopDownRoot"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5721 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 5722 | return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root()); |
| 5723 | } |
| 5724 | |
| 5725 | |
| 5726 | int CpuProfiler::GetProfilesCount() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5727 | i::Isolate* isolate = i::Isolate::Current(); |
| 5728 | IsDeadCheck(isolate, "v8::CpuProfiler::GetProfilesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5729 | return i::CpuProfiler::GetProfilesCount(); |
| 5730 | } |
| 5731 | |
| 5732 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5733 | const CpuProfile* CpuProfiler::GetProfile(int index, |
| 5734 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5735 | i::Isolate* isolate = i::Isolate::Current(); |
| 5736 | IsDeadCheck(isolate, "v8::CpuProfiler::GetProfile"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5737 | return reinterpret_cast<const CpuProfile*>( |
| 5738 | i::CpuProfiler::GetProfile( |
| 5739 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 5740 | index)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5744 | const CpuProfile* CpuProfiler::FindProfile(unsigned uid, |
| 5745 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5746 | i::Isolate* isolate = i::Isolate::Current(); |
| 5747 | IsDeadCheck(isolate, "v8::CpuProfiler::FindProfile"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5748 | return reinterpret_cast<const CpuProfile*>( |
| 5749 | i::CpuProfiler::FindProfile( |
| 5750 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 5751 | uid)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5752 | } |
| 5753 | |
| 5754 | |
| 5755 | void CpuProfiler::StartProfiling(Handle<String> title) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5756 | i::Isolate* isolate = i::Isolate::Current(); |
| 5757 | IsDeadCheck(isolate, "v8::CpuProfiler::StartProfiling"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5758 | i::CpuProfiler::StartProfiling(*Utils::OpenHandle(*title)); |
| 5759 | } |
| 5760 | |
| 5761 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5762 | const CpuProfile* CpuProfiler::StopProfiling(Handle<String> title, |
| 5763 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5764 | i::Isolate* isolate = i::Isolate::Current(); |
| 5765 | IsDeadCheck(isolate, "v8::CpuProfiler::StopProfiling"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5766 | return reinterpret_cast<const CpuProfile*>( |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5767 | i::CpuProfiler::StopProfiling( |
| 5768 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 5769 | *Utils::OpenHandle(*title))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5770 | } |
| 5771 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5772 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5773 | void CpuProfiler::DeleteAllProfiles() { |
| 5774 | i::Isolate* isolate = i::Isolate::Current(); |
| 5775 | IsDeadCheck(isolate, "v8::CpuProfiler::DeleteAllProfiles"); |
| 5776 | i::CpuProfiler::DeleteAllProfiles(); |
| 5777 | } |
| 5778 | |
| 5779 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5780 | static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) { |
| 5781 | return const_cast<i::HeapGraphEdge*>( |
| 5782 | reinterpret_cast<const i::HeapGraphEdge*>(edge)); |
| 5783 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5784 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5785 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5786 | HeapGraphEdge::Type HeapGraphEdge::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5787 | i::Isolate* isolate = i::Isolate::Current(); |
| 5788 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetType"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5789 | return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | |
| 5793 | Handle<Value> HeapGraphEdge::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5794 | i::Isolate* isolate = i::Isolate::Current(); |
| 5795 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetName"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5796 | i::HeapGraphEdge* edge = ToInternal(this); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5797 | switch (edge->type()) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5798 | case i::HeapGraphEdge::kContextVariable: |
| 5799 | case i::HeapGraphEdge::kInternal: |
| 5800 | case i::HeapGraphEdge::kProperty: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5801 | case i::HeapGraphEdge::kShortcut: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5802 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5803 | edge->name()))); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5804 | case i::HeapGraphEdge::kElement: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5805 | case i::HeapGraphEdge::kHidden: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5806 | return Handle<Number>(ToApi<Number>(isolate->factory()->NewNumberFromInt( |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5807 | edge->index()))); |
| 5808 | default: UNREACHABLE(); |
| 5809 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5810 | return v8::Undefined(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | |
| 5814 | const HeapGraphNode* HeapGraphEdge::GetFromNode() 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::HeapGraphEdge::GetFromNode"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5817 | const i::HeapEntry* from = ToInternal(this)->From(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5818 | return reinterpret_cast<const HeapGraphNode*>(from); |
| 5819 | } |
| 5820 | |
| 5821 | |
| 5822 | const HeapGraphNode* HeapGraphEdge::GetToNode() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5823 | i::Isolate* isolate = i::Isolate::Current(); |
| 5824 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetToNode"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5825 | const i::HeapEntry* to = ToInternal(this)->to(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5826 | return reinterpret_cast<const HeapGraphNode*>(to); |
| 5827 | } |
| 5828 | |
| 5829 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5830 | static i::HeapEntry* ToInternal(const HeapGraphNode* entry) { |
| 5831 | return const_cast<i::HeapEntry*>( |
| 5832 | reinterpret_cast<const i::HeapEntry*>(entry)); |
| 5833 | } |
| 5834 | |
| 5835 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5836 | HeapGraphNode::Type HeapGraphNode::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5837 | i::Isolate* isolate = i::Isolate::Current(); |
| 5838 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetType"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5839 | return static_cast<HeapGraphNode::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | |
| 5843 | Handle<String> HeapGraphNode::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5844 | i::Isolate* isolate = i::Isolate::Current(); |
| 5845 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetName"); |
| 5846 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5847 | ToInternal(this)->name()))); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5848 | } |
| 5849 | |
| 5850 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 5851 | uint64_t HeapGraphNode::GetId() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5852 | i::Isolate* isolate = i::Isolate::Current(); |
| 5853 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetId"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5854 | return ToInternal(this)->id(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5858 | int HeapGraphNode::GetSelfSize() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5859 | i::Isolate* isolate = i::Isolate::Current(); |
| 5860 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetSelfSize"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5861 | return ToInternal(this)->self_size(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5865 | int HeapGraphNode::GetRetainedSize(bool exact) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5866 | i::Isolate* isolate = i::Isolate::Current(); |
| 5867 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainedSize"); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5868 | return ToInternal(this)->RetainedSize(exact); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | |
| 5872 | int HeapGraphNode::GetChildrenCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5873 | i::Isolate* isolate = i::Isolate::Current(); |
| 5874 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetChildrenCount"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5875 | return ToInternal(this)->children().length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5876 | } |
| 5877 | |
| 5878 | |
| 5879 | const HeapGraphEdge* HeapGraphNode::GetChild(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5880 | i::Isolate* isolate = i::Isolate::Current(); |
| 5881 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetChild"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5882 | return reinterpret_cast<const HeapGraphEdge*>( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5883 | &ToInternal(this)->children()[index]); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5884 | } |
| 5885 | |
| 5886 | |
| 5887 | int HeapGraphNode::GetRetainersCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5888 | i::Isolate* isolate = i::Isolate::Current(); |
| 5889 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainersCount"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5890 | return ToInternal(this)->retainers().length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | |
| 5894 | const HeapGraphEdge* HeapGraphNode::GetRetainer(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5895 | i::Isolate* isolate = i::Isolate::Current(); |
| 5896 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainer"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5897 | return reinterpret_cast<const HeapGraphEdge*>( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5898 | ToInternal(this)->retainers()[index]); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5899 | } |
| 5900 | |
| 5901 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5902 | const HeapGraphNode* HeapGraphNode::GetDominatorNode() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5903 | i::Isolate* isolate = i::Isolate::Current(); |
| 5904 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetDominatorNode"); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5905 | return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->dominator()); |
| 5906 | } |
| 5907 | |
| 5908 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5909 | v8::Handle<v8::Value> HeapGraphNode::GetHeapValue() const { |
| 5910 | i::Isolate* isolate = i::Isolate::Current(); |
| 5911 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetHeapValue"); |
| 5912 | i::Handle<i::HeapObject> object = ToInternal(this)->GetHeapObject(); |
| 5913 | return v8::Handle<Value>(!object.is_null() ? |
| 5914 | ToApi<Value>(object) : ToApi<Value>( |
| 5915 | isolate->factory()->undefined_value())); |
| 5916 | } |
| 5917 | |
| 5918 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5919 | static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) { |
| 5920 | return const_cast<i::HeapSnapshot*>( |
| 5921 | reinterpret_cast<const i::HeapSnapshot*>(snapshot)); |
| 5922 | } |
| 5923 | |
| 5924 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5925 | void HeapSnapshot::Delete() { |
| 5926 | i::Isolate* isolate = i::Isolate::Current(); |
| 5927 | IsDeadCheck(isolate, "v8::HeapSnapshot::Delete"); |
| 5928 | if (i::HeapProfiler::GetSnapshotsCount() > 1) { |
| 5929 | ToInternal(this)->Delete(); |
| 5930 | } else { |
| 5931 | // If this is the last snapshot, clean up all accessory data as well. |
| 5932 | i::HeapProfiler::DeleteAllSnapshots(); |
| 5933 | } |
| 5934 | } |
| 5935 | |
| 5936 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5937 | HeapSnapshot::Type HeapSnapshot::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5938 | i::Isolate* isolate = i::Isolate::Current(); |
| 5939 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetType"); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5940 | return static_cast<HeapSnapshot::Type>(ToInternal(this)->type()); |
| 5941 | } |
| 5942 | |
| 5943 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5944 | unsigned HeapSnapshot::GetUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5945 | i::Isolate* isolate = i::Isolate::Current(); |
| 5946 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetUid"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5947 | return ToInternal(this)->uid(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5948 | } |
| 5949 | |
| 5950 | |
| 5951 | Handle<String> HeapSnapshot::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5952 | i::Isolate* isolate = i::Isolate::Current(); |
| 5953 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetTitle"); |
| 5954 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5955 | ToInternal(this)->title()))); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5956 | } |
| 5957 | |
| 5958 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 5959 | const HeapGraphNode* HeapSnapshot::GetRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5960 | i::Isolate* isolate = i::Isolate::Current(); |
| 5961 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetHead"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5962 | return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5966 | const HeapGraphNode* HeapSnapshot::GetNodeById(uint64_t id) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5967 | i::Isolate* isolate = i::Isolate::Current(); |
| 5968 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodeById"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5969 | return reinterpret_cast<const HeapGraphNode*>( |
| 5970 | ToInternal(this)->GetEntryById(id)); |
| 5971 | } |
| 5972 | |
| 5973 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5974 | int HeapSnapshot::GetNodesCount() const { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5975 | i::Isolate* isolate = i::Isolate::Current(); |
| 5976 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodesCount"); |
| 5977 | return ToInternal(this)->entries()->length(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5978 | } |
| 5979 | |
| 5980 | |
| 5981 | const HeapGraphNode* HeapSnapshot::GetNode(int index) const { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5982 | i::Isolate* isolate = i::Isolate::Current(); |
| 5983 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNode"); |
| 5984 | return reinterpret_cast<const HeapGraphNode*>( |
| 5985 | ToInternal(this)->entries()->at(index)); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5989 | void HeapSnapshot::Serialize(OutputStream* stream, |
| 5990 | HeapSnapshot::SerializationFormat format) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5991 | i::Isolate* isolate = i::Isolate::Current(); |
| 5992 | IsDeadCheck(isolate, "v8::HeapSnapshot::Serialize"); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5993 | ApiCheck(format == kJSON, |
| 5994 | "v8::HeapSnapshot::Serialize", |
| 5995 | "Unknown serialization format"); |
| 5996 | ApiCheck(stream->GetOutputEncoding() == OutputStream::kAscii, |
| 5997 | "v8::HeapSnapshot::Serialize", |
| 5998 | "Unsupported output encoding"); |
| 5999 | ApiCheck(stream->GetChunkSize() > 0, |
| 6000 | "v8::HeapSnapshot::Serialize", |
| 6001 | "Invalid stream chunk size"); |
| 6002 | i::HeapSnapshotJSONSerializer serializer(ToInternal(this)); |
| 6003 | serializer.Serialize(stream); |
| 6004 | } |
| 6005 | |
| 6006 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6007 | int HeapProfiler::GetSnapshotsCount() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6008 | i::Isolate* isolate = i::Isolate::Current(); |
| 6009 | IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotsCount"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6010 | return i::HeapProfiler::GetSnapshotsCount(); |
| 6011 | } |
| 6012 | |
| 6013 | |
| 6014 | const HeapSnapshot* HeapProfiler::GetSnapshot(int index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6015 | i::Isolate* isolate = i::Isolate::Current(); |
| 6016 | IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshot"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6017 | return reinterpret_cast<const HeapSnapshot*>( |
| 6018 | i::HeapProfiler::GetSnapshot(index)); |
| 6019 | } |
| 6020 | |
| 6021 | |
| 6022 | const HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6023 | i::Isolate* isolate = i::Isolate::Current(); |
| 6024 | IsDeadCheck(isolate, "v8::HeapProfiler::FindSnapshot"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6025 | return reinterpret_cast<const HeapSnapshot*>( |
| 6026 | i::HeapProfiler::FindSnapshot(uid)); |
| 6027 | } |
| 6028 | |
| 6029 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6030 | const HeapSnapshot* HeapProfiler::TakeSnapshot(Handle<String> title, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 6031 | HeapSnapshot::Type type, |
| 6032 | ActivityControl* control) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6033 | i::Isolate* isolate = i::Isolate::Current(); |
| 6034 | IsDeadCheck(isolate, "v8::HeapProfiler::TakeSnapshot"); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6035 | i::HeapSnapshot::Type internal_type = i::HeapSnapshot::kFull; |
| 6036 | switch (type) { |
| 6037 | case HeapSnapshot::kFull: |
| 6038 | internal_type = i::HeapSnapshot::kFull; |
| 6039 | break; |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6040 | default: |
| 6041 | UNREACHABLE(); |
| 6042 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6043 | return reinterpret_cast<const HeapSnapshot*>( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 6044 | i::HeapProfiler::TakeSnapshot( |
| 6045 | *Utils::OpenHandle(*title), internal_type, control)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6046 | } |
| 6047 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6048 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6049 | void HeapProfiler::DeleteAllSnapshots() { |
| 6050 | i::Isolate* isolate = i::Isolate::Current(); |
| 6051 | IsDeadCheck(isolate, "v8::HeapProfiler::DeleteAllSnapshots"); |
| 6052 | i::HeapProfiler::DeleteAllSnapshots(); |
| 6053 | } |
| 6054 | |
| 6055 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6056 | void HeapProfiler::DefineWrapperClass(uint16_t class_id, |
| 6057 | WrapperInfoCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6058 | i::Isolate::Current()->heap_profiler()->DefineWrapperClass(class_id, |
| 6059 | callback); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6060 | } |
| 6061 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6062 | |
| 6063 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6064 | v8::Testing::StressType internal::Testing::stress_type_ = |
| 6065 | v8::Testing::kStressTypeOpt; |
| 6066 | |
| 6067 | |
| 6068 | void Testing::SetStressRunType(Testing::StressType type) { |
| 6069 | internal::Testing::set_stress_type(type); |
| 6070 | } |
| 6071 | |
| 6072 | int Testing::GetStressRuns() { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 6073 | if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6074 | #ifdef DEBUG |
| 6075 | // In debug mode the code runs much slower so stressing will only make two |
| 6076 | // runs. |
| 6077 | return 2; |
| 6078 | #else |
| 6079 | return 5; |
| 6080 | #endif |
| 6081 | } |
| 6082 | |
| 6083 | |
| 6084 | static void SetFlagsFromString(const char* flags) { |
| 6085 | V8::SetFlagsFromString(flags, i::StrLength(flags)); |
| 6086 | } |
| 6087 | |
| 6088 | |
| 6089 | void Testing::PrepareStressRun(int run) { |
| 6090 | static const char* kLazyOptimizations = |
| 6091 | "--prepare-always-opt --nolimit-inlining " |
| 6092 | "--noalways-opt --noopt-eagerly"; |
| 6093 | static const char* kEagerOptimizations = "--opt-eagerly"; |
| 6094 | static const char* kForcedOptimizations = "--always-opt"; |
| 6095 | |
| 6096 | // If deoptimization stressed turn on frequent deoptimization. If no value |
| 6097 | // is spefified through --deopt-every-n-times use a default default value. |
| 6098 | static const char* kDeoptEvery13Times = "--deopt-every-n-times=13"; |
| 6099 | if (internal::Testing::stress_type() == Testing::kStressTypeDeopt && |
| 6100 | internal::FLAG_deopt_every_n_times == 0) { |
| 6101 | SetFlagsFromString(kDeoptEvery13Times); |
| 6102 | } |
| 6103 | |
| 6104 | #ifdef DEBUG |
| 6105 | // As stressing in debug mode only make two runs skip the deopt stressing |
| 6106 | // here. |
| 6107 | if (run == GetStressRuns() - 1) { |
| 6108 | SetFlagsFromString(kForcedOptimizations); |
| 6109 | } else { |
| 6110 | SetFlagsFromString(kEagerOptimizations); |
| 6111 | SetFlagsFromString(kLazyOptimizations); |
| 6112 | } |
| 6113 | #else |
| 6114 | if (run == GetStressRuns() - 1) { |
| 6115 | SetFlagsFromString(kForcedOptimizations); |
| 6116 | } else if (run == GetStressRuns() - 2) { |
| 6117 | SetFlagsFromString(kEagerOptimizations); |
| 6118 | } else { |
| 6119 | SetFlagsFromString(kLazyOptimizations); |
| 6120 | } |
| 6121 | #endif |
| 6122 | } |
| 6123 | |
| 6124 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6125 | void Testing::DeoptimizeAll() { |
| 6126 | internal::Deoptimizer::DeoptimizeAll(); |
| 6127 | } |
| 6128 | |
| 6129 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6130 | namespace internal { |
| 6131 | |
| 6132 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6133 | void HandleScopeImplementer::FreeThreadResources() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6134 | Free(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6135 | } |
| 6136 | |
| 6137 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6138 | char* HandleScopeImplementer::ArchiveThread(char* storage) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 6139 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6140 | isolate_->handle_scope_data(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6141 | handle_scope_data_ = *current; |
| 6142 | memcpy(storage, this, sizeof(*this)); |
| 6143 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6144 | ResetAfterArchive(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6145 | current->Initialize(); |
| 6146 | |
| 6147 | return storage + ArchiveSpacePerThread(); |
| 6148 | } |
| 6149 | |
| 6150 | |
| 6151 | int HandleScopeImplementer::ArchiveSpacePerThread() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6152 | return sizeof(HandleScopeImplementer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | |
| 6156 | char* HandleScopeImplementer::RestoreThread(char* storage) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6157 | memcpy(this, storage, sizeof(*this)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6158 | *isolate_->handle_scope_data() = handle_scope_data_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6159 | return storage + ArchiveSpacePerThread(); |
| 6160 | } |
| 6161 | |
| 6162 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6163 | void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6164 | // Iterate over all handles in the blocks except for the last. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6165 | for (int i = blocks()->length() - 2; i >= 0; --i) { |
| 6166 | Object** block = blocks()->at(i); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6167 | v->VisitPointers(block, &block[kHandleBlockSize]); |
| 6168 | } |
| 6169 | |
| 6170 | // Iterate over live handles in the last block (if any). |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6171 | if (!blocks()->is_empty()) { |
| 6172 | v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6173 | } |
| 6174 | |
| 6175 | if (!saved_contexts_.is_empty()) { |
| 6176 | Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
| 6177 | v->VisitPointers(start, start + saved_contexts_.length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6178 | } |
| 6179 | } |
| 6180 | |
| 6181 | |
| 6182 | void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 6183 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6184 | isolate_->handle_scope_data(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6185 | handle_scope_data_ = *current; |
| 6186 | IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | |
| 6190 | char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6191 | HandleScopeImplementer* scope_implementer = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6192 | reinterpret_cast<HandleScopeImplementer*>(storage); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6193 | scope_implementer->IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6194 | return storage + ArchiveSpacePerThread(); |
| 6195 | } |
| 6196 | |
| 6197 | } } // namespace v8::internal |