sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "api.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 31 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 32 | #include "arguments.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | #include "bootstrapper.h" |
| 34 | #include "compiler.h" |
| 35 | #include "debug.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 36 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | #include "execution.h" |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 38 | #include "flags.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | #include "global-handles.h" |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 40 | #include "heap-profiler.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 41 | #include "messages.h" |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 42 | #include "natives.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 43 | #include "parser.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | #include "platform.h" |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 45 | #include "profile-generator-inl.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 46 | #include "runtime-profiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | #include "serialize.h" |
| 48 | #include "snapshot.h" |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 49 | #include "v8threads.h" |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 50 | #include "version.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 51 | #include "vm-state-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 53 | #include "../include/v8-profiler.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 54 | #include "../include/v8-testing.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 56 | #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 58 | #define ENTER_V8(isolate) \ |
| 59 | ASSERT((isolate)->IsInitialized()); \ |
| 60 | i::VMState __state__((isolate), i::OTHER) |
| 61 | #define LEAVE_V8(isolate) \ |
| 62 | i::VMState __state__((isolate), i::EXTERNAL) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | |
| 64 | namespace v8 { |
| 65 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 66 | #define ON_BAILOUT(isolate, location, code) \ |
| 67 | if (IsDeadCheck(isolate, location) || \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 68 | IsExecutionTerminatingCheck(isolate)) { \ |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 69 | code; \ |
| 70 | UNREACHABLE(); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 74 | #define EXCEPTION_PREAMBLE(isolate) \ |
| 75 | (isolate)->handle_scope_implementer()->IncrementCallDepth(); \ |
| 76 | ASSERT(!(isolate)->external_caught_exception()); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 77 | bool has_pending_exception = false |
| 78 | |
| 79 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 80 | #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 81 | do { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 82 | i::HandleScopeImplementer* handle_scope_implementer = \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 83 | (isolate)->handle_scope_implementer(); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 84 | handle_scope_implementer->DecrementCallDepth(); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 85 | if (has_pending_exception) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 86 | if (handle_scope_implementer->CallDepthIsZero() && \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 87 | (isolate)->is_out_of_memory()) { \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 88 | if (!(isolate)->ignore_out_of_memory()) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | i::V8::FatalProcessOutOfMemory(NULL); \ |
| 90 | } \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 91 | bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 92 | (isolate)->OptionalRescheduleException(call_depth_is_zero); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 93 | return value; \ |
| 94 | } \ |
| 95 | } while (false) |
| 96 | |
| 97 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 98 | #define API_ENTRY_CHECK(isolate, msg) \ |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 99 | do { \ |
| 100 | if (v8::Locker::IsActive()) { \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 101 | ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \ |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 102 | msg, \ |
| 103 | "Entering the V8 API without proper locking in place"); \ |
| 104 | } \ |
| 105 | } while (false) |
| 106 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 107 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 108 | // --- E x c e p t i o n B e h a v i o r --- |
| 109 | |
| 110 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 111 | static void DefaultFatalErrorHandler(const char* location, |
| 112 | const char* message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 113 | i::VMState __state__(i::Isolate::Current(), i::OTHER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 114 | API_Fatal(location, message); |
| 115 | } |
| 116 | |
| 117 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 118 | static FatalErrorCallback GetFatalErrorHandler() { |
| 119 | i::Isolate* isolate = i::Isolate::Current(); |
| 120 | if (isolate->exception_behavior() == NULL) { |
| 121 | isolate->set_exception_behavior(DefaultFatalErrorHandler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 123 | return isolate->exception_behavior(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 127 | void i::FatalProcessOutOfMemory(const char* location) { |
| 128 | i::V8::FatalProcessOutOfMemory(location, false); |
| 129 | } |
| 130 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 131 | |
| 132 | // When V8 cannot allocated memory FatalProcessOutOfMemory is called. |
| 133 | // The default fatal error handler is called and execution is stopped. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 134 | void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 135 | i::HeapStats heap_stats; |
| 136 | int start_marker; |
| 137 | heap_stats.start_marker = &start_marker; |
| 138 | int new_space_size; |
| 139 | heap_stats.new_space_size = &new_space_size; |
| 140 | int new_space_capacity; |
| 141 | heap_stats.new_space_capacity = &new_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 142 | intptr_t old_pointer_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 143 | heap_stats.old_pointer_space_size = &old_pointer_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 144 | intptr_t old_pointer_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 145 | heap_stats.old_pointer_space_capacity = &old_pointer_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 146 | intptr_t old_data_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 147 | heap_stats.old_data_space_size = &old_data_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 148 | intptr_t old_data_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 149 | heap_stats.old_data_space_capacity = &old_data_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 150 | intptr_t code_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 151 | heap_stats.code_space_size = &code_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 152 | intptr_t code_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 153 | heap_stats.code_space_capacity = &code_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 154 | intptr_t map_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 155 | heap_stats.map_space_size = &map_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 156 | intptr_t map_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 157 | heap_stats.map_space_capacity = &map_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 158 | intptr_t cell_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 159 | heap_stats.cell_space_size = &cell_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 160 | intptr_t cell_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 161 | heap_stats.cell_space_capacity = &cell_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 162 | intptr_t lo_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 163 | heap_stats.lo_space_size = &lo_space_size; |
| 164 | int global_handle_count; |
| 165 | heap_stats.global_handle_count = &global_handle_count; |
| 166 | int weak_global_handle_count; |
| 167 | heap_stats.weak_global_handle_count = &weak_global_handle_count; |
| 168 | int pending_global_handle_count; |
| 169 | heap_stats.pending_global_handle_count = &pending_global_handle_count; |
| 170 | int near_death_global_handle_count; |
| 171 | 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] | 172 | int free_global_handle_count; |
| 173 | heap_stats.free_global_handle_count = &free_global_handle_count; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 174 | intptr_t memory_allocator_size; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 175 | heap_stats.memory_allocator_size = &memory_allocator_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 176 | intptr_t memory_allocator_capacity; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 177 | heap_stats.memory_allocator_capacity = &memory_allocator_capacity; |
| 178 | int objects_per_type[LAST_TYPE + 1] = {0}; |
| 179 | heap_stats.objects_per_type = objects_per_type; |
| 180 | int size_per_type[LAST_TYPE + 1] = {0}; |
| 181 | heap_stats.size_per_type = size_per_type; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 182 | int os_error; |
| 183 | heap_stats.os_error = &os_error; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 184 | int end_marker; |
| 185 | heap_stats.end_marker = &end_marker; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 186 | i::Isolate* isolate = i::Isolate::Current(); |
| 187 | isolate->heap()->RecordStats(&heap_stats, take_snapshot); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 188 | i::V8::SetFatalError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 189 | FatalErrorCallback callback = GetFatalErrorHandler(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 190 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 191 | LEAVE_V8(isolate); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 192 | callback(location, "Allocation failed - process out of memory"); |
| 193 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 194 | // If the callback returns, we stop execution. |
| 195 | UNREACHABLE(); |
| 196 | } |
| 197 | |
| 198 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | bool Utils::ReportApiFailure(const char* location, const char* message) { |
| 200 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 201 | callback(location, message); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 202 | i::V8::SetFatalError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 203 | return false; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | bool V8::IsDead() { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 208 | return i::V8::IsDead(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | |
| 212 | static inline bool ApiCheck(bool condition, |
| 213 | const char* location, |
| 214 | const char* message) { |
| 215 | return condition ? true : Utils::ReportApiFailure(location, message); |
| 216 | } |
| 217 | |
| 218 | |
| 219 | static bool ReportV8Dead(const char* location) { |
| 220 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 221 | callback(location, "V8 is no longer usable"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 222 | return true; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | static bool ReportEmptyHandle(const char* location) { |
| 227 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 228 | callback(location, "Reading from empty handle"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 229 | return true; |
| 230 | } |
| 231 | |
| 232 | |
| 233 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 234 | * 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] | 235 | * out of memory at some point this check will fail. It should be called on |
| 236 | * entry to all methods that touch anything in the heap, except destructors |
| 237 | * which you sometimes can't avoid calling after the vm has crashed. Functions |
| 238 | * that call EnsureInitialized or ON_BAILOUT don't have to also call |
| 239 | * IsDeadCheck. ON_BAILOUT has the advantage over EnsureInitialized that you |
| 240 | * can arrange to return if the VM is dead. This is needed to ensure that no VM |
| 241 | * heap allocations are attempted on a dead VM. EnsureInitialized has the |
| 242 | * advantage over ON_BAILOUT that it actually initializes the VM if this has not |
| 243 | * yet been done. |
| 244 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 245 | static inline bool IsDeadCheck(i::Isolate* isolate, const char* location) { |
| 246 | return !isolate->IsInitialized() |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 247 | && i::V8::IsDead() ? ReportV8Dead(location) : false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 251 | static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { |
| 252 | if (!isolate->IsInitialized()) return false; |
| 253 | if (isolate->has_scheduled_exception()) { |
| 254 | return isolate->scheduled_exception() == |
| 255 | isolate->heap()->termination_exception(); |
| 256 | } |
| 257 | return false; |
| 258 | } |
| 259 | |
| 260 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 261 | static inline bool EmptyCheck(const char* location, v8::Handle<v8::Data> obj) { |
| 262 | return obj.IsEmpty() ? ReportEmptyHandle(location) : false; |
| 263 | } |
| 264 | |
| 265 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 266 | static inline bool EmptyCheck(const char* location, const v8::Data* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 267 | return (obj == 0) ? ReportEmptyHandle(location) : false; |
| 268 | } |
| 269 | |
| 270 | // --- S t a t i c s --- |
| 271 | |
| 272 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 273 | static bool InitializeHelper() { |
| 274 | if (i::Snapshot::Initialize()) return true; |
| 275 | return i::V8::Initialize(NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 279 | static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, |
| 280 | const char* location) { |
| 281 | if (IsDeadCheck(isolate, location)) return false; |
| 282 | if (isolate != NULL) { |
| 283 | if (isolate->IsInitialized()) return true; |
| 284 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 285 | ASSERT(isolate == i::Isolate::Current()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 286 | return ApiCheck(InitializeHelper(), location, "Error initializing V8"); |
| 287 | } |
| 288 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 289 | // Some initializing API functions are called early and may be |
| 290 | // called on a thread different from static initializer thread. |
| 291 | // If Isolate API is used, Isolate::Enter() will initialize TLS so |
| 292 | // Isolate::Current() works. If it's a legacy case, then the thread |
| 293 | // may not have TLS initialized yet. However, in initializing APIs it |
| 294 | // may be too early to call EnsureInitialized() - some pre-init |
| 295 | // parameters still have to be configured. |
| 296 | static inline i::Isolate* EnterIsolateIfNeeded() { |
| 297 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 298 | if (isolate != NULL) |
| 299 | return isolate; |
| 300 | |
| 301 | i::Isolate::EnterDefaultIsolate(); |
| 302 | isolate = i::Isolate::Current(); |
| 303 | return isolate; |
| 304 | } |
| 305 | |
| 306 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 307 | StartupDataDecompressor::StartupDataDecompressor() |
| 308 | : raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) { |
| 309 | for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { |
| 310 | raw_data[i] = NULL; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | |
| 315 | StartupDataDecompressor::~StartupDataDecompressor() { |
| 316 | for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { |
| 317 | i::DeleteArray(raw_data[i]); |
| 318 | } |
| 319 | i::DeleteArray(raw_data); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | int StartupDataDecompressor::Decompress() { |
| 324 | int compressed_data_count = V8::GetCompressedStartupDataCount(); |
| 325 | StartupData* compressed_data = |
| 326 | i::NewArray<StartupData>(compressed_data_count); |
| 327 | V8::GetCompressedStartupData(compressed_data); |
| 328 | for (int i = 0; i < compressed_data_count; ++i) { |
| 329 | char* decompressed = raw_data[i] = |
| 330 | i::NewArray<char>(compressed_data[i].raw_size); |
| 331 | if (compressed_data[i].compressed_size != 0) { |
| 332 | int result = DecompressData(decompressed, |
| 333 | &compressed_data[i].raw_size, |
| 334 | compressed_data[i].data, |
| 335 | compressed_data[i].compressed_size); |
| 336 | if (result != 0) return result; |
| 337 | } else { |
| 338 | ASSERT_EQ(0, compressed_data[i].raw_size); |
| 339 | } |
| 340 | compressed_data[i].data = decompressed; |
| 341 | } |
| 342 | V8::SetDecompressedStartupData(compressed_data); |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 347 | StartupData::CompressionAlgorithm V8::GetCompressedStartupDataAlgorithm() { |
| 348 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 349 | return StartupData::kBZip2; |
| 350 | #else |
| 351 | return StartupData::kUncompressed; |
| 352 | #endif |
| 353 | } |
| 354 | |
| 355 | |
| 356 | enum CompressedStartupDataItems { |
| 357 | kSnapshot = 0, |
| 358 | kSnapshotContext, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 359 | kLibraries, |
| 360 | kExperimentalLibraries, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 361 | kCompressedStartupDataCount |
| 362 | }; |
| 363 | |
| 364 | int V8::GetCompressedStartupDataCount() { |
| 365 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 366 | return kCompressedStartupDataCount; |
| 367 | #else |
| 368 | return 0; |
| 369 | #endif |
| 370 | } |
| 371 | |
| 372 | |
| 373 | void V8::GetCompressedStartupData(StartupData* compressed_data) { |
| 374 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 375 | compressed_data[kSnapshot].data = |
| 376 | reinterpret_cast<const char*>(i::Snapshot::data()); |
| 377 | compressed_data[kSnapshot].compressed_size = i::Snapshot::size(); |
| 378 | compressed_data[kSnapshot].raw_size = i::Snapshot::raw_size(); |
| 379 | |
| 380 | compressed_data[kSnapshotContext].data = |
| 381 | reinterpret_cast<const char*>(i::Snapshot::context_data()); |
| 382 | compressed_data[kSnapshotContext].compressed_size = |
| 383 | i::Snapshot::context_size(); |
| 384 | compressed_data[kSnapshotContext].raw_size = i::Snapshot::context_raw_size(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 385 | |
| 386 | i::Vector<const i::byte> libraries_source = i::Natives::GetScriptsSource(); |
| 387 | compressed_data[kLibraries].data = |
| 388 | reinterpret_cast<const char*>(libraries_source.start()); |
| 389 | compressed_data[kLibraries].compressed_size = libraries_source.length(); |
| 390 | compressed_data[kLibraries].raw_size = i::Natives::GetRawScriptsSize(); |
| 391 | |
| 392 | i::Vector<const i::byte> exp_libraries_source = |
| 393 | i::ExperimentalNatives::GetScriptsSource(); |
| 394 | compressed_data[kExperimentalLibraries].data = |
| 395 | reinterpret_cast<const char*>(exp_libraries_source.start()); |
| 396 | compressed_data[kExperimentalLibraries].compressed_size = |
| 397 | exp_libraries_source.length(); |
| 398 | compressed_data[kExperimentalLibraries].raw_size = |
| 399 | i::ExperimentalNatives::GetRawScriptsSize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 400 | #endif |
| 401 | } |
| 402 | |
| 403 | |
| 404 | void V8::SetDecompressedStartupData(StartupData* decompressed_data) { |
| 405 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 406 | ASSERT_EQ(i::Snapshot::raw_size(), decompressed_data[kSnapshot].raw_size); |
| 407 | i::Snapshot::set_raw_data( |
| 408 | reinterpret_cast<const i::byte*>(decompressed_data[kSnapshot].data)); |
| 409 | |
| 410 | ASSERT_EQ(i::Snapshot::context_raw_size(), |
| 411 | decompressed_data[kSnapshotContext].raw_size); |
| 412 | i::Snapshot::set_context_raw_data( |
| 413 | reinterpret_cast<const i::byte*>( |
| 414 | decompressed_data[kSnapshotContext].data)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 415 | |
| 416 | ASSERT_EQ(i::Natives::GetRawScriptsSize(), |
| 417 | decompressed_data[kLibraries].raw_size); |
| 418 | i::Vector<const char> libraries_source( |
| 419 | decompressed_data[kLibraries].data, |
| 420 | decompressed_data[kLibraries].raw_size); |
| 421 | i::Natives::SetRawScriptsSource(libraries_source); |
| 422 | |
| 423 | ASSERT_EQ(i::ExperimentalNatives::GetRawScriptsSize(), |
| 424 | decompressed_data[kExperimentalLibraries].raw_size); |
| 425 | i::Vector<const char> exp_libraries_source( |
| 426 | decompressed_data[kExperimentalLibraries].data, |
| 427 | decompressed_data[kExperimentalLibraries].raw_size); |
| 428 | i::ExperimentalNatives::SetRawScriptsSource(exp_libraries_source); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 429 | #endif |
| 430 | } |
| 431 | |
| 432 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 433 | void V8::SetFatalErrorHandler(FatalErrorCallback that) { |
| 434 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 435 | isolate->set_exception_behavior(that); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 439 | void V8::SetAllowCodeGenerationFromStringsCallback( |
| 440 | AllowCodeGenerationFromStringsCallback callback) { |
| 441 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 442 | isolate->set_allow_code_gen_callback(callback); |
| 443 | } |
| 444 | |
| 445 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 446 | #ifdef DEBUG |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 447 | void ImplementationUtilities::ZapHandleRange(i::Object** begin, |
| 448 | i::Object** end) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 449 | i::HandleScope::ZapRange(begin, end); |
| 450 | } |
| 451 | #endif |
| 452 | |
| 453 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 454 | void V8::SetFlagsFromString(const char* str, int length) { |
| 455 | i::FlagList::SetFlagsFromString(str, length); |
| 456 | } |
| 457 | |
| 458 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 459 | void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { |
| 460 | i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); |
| 461 | } |
| 462 | |
| 463 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 464 | v8::Handle<Value> ThrowException(v8::Handle<v8::Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 465 | i::Isolate* isolate = i::Isolate::Current(); |
| 466 | if (IsDeadCheck(isolate, "v8::ThrowException()")) { |
| 467 | return v8::Handle<Value>(); |
| 468 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 469 | ENTER_V8(isolate); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 470 | // If we're passed an empty handle, we throw an undefined exception |
| 471 | // to deal more gracefully with out of memory situations. |
| 472 | if (value.IsEmpty()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 473 | isolate->ScheduleThrow(isolate->heap()->undefined_value()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 474 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 475 | isolate->ScheduleThrow(*Utils::OpenHandle(*value)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 476 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 477 | return v8::Undefined(); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | RegisteredExtension* RegisteredExtension::first_extension_ = NULL; |
| 482 | |
| 483 | |
| 484 | RegisteredExtension::RegisteredExtension(Extension* extension) |
| 485 | : extension_(extension), state_(UNVISITED) { } |
| 486 | |
| 487 | |
| 488 | void RegisteredExtension::Register(RegisteredExtension* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 489 | that->next_ = first_extension_; |
| 490 | first_extension_ = that; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | |
| 494 | void RegisterExtension(Extension* that) { |
| 495 | RegisteredExtension* extension = new RegisteredExtension(that); |
| 496 | RegisteredExtension::Register(extension); |
| 497 | } |
| 498 | |
| 499 | |
| 500 | Extension::Extension(const char* name, |
| 501 | const char* source, |
| 502 | int dep_count, |
| 503 | const char** deps) |
| 504 | : name_(name), |
| 505 | source_(source), |
| 506 | dep_count_(dep_count), |
| 507 | deps_(deps), |
| 508 | auto_enable_(false) { } |
| 509 | |
| 510 | |
| 511 | v8::Handle<Primitive> Undefined() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 512 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 513 | if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) { |
| 514 | return v8::Handle<v8::Primitive>(); |
| 515 | } |
| 516 | return v8::Handle<Primitive>(ToApi<Primitive>( |
| 517 | isolate->factory()->undefined_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | |
| 521 | v8::Handle<Primitive> Null() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 522 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 523 | if (!EnsureInitializedForIsolate(isolate, "v8::Null()")) { |
| 524 | return v8::Handle<v8::Primitive>(); |
| 525 | } |
| 526 | return v8::Handle<Primitive>( |
| 527 | ToApi<Primitive>(isolate->factory()->null_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | |
| 531 | v8::Handle<Boolean> True() { |
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::True()")) { |
| 534 | return v8::Handle<Boolean>(); |
| 535 | } |
| 536 | return v8::Handle<Boolean>( |
| 537 | ToApi<Boolean>(isolate->factory()->true_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | |
| 541 | v8::Handle<Boolean> False() { |
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::False()")) { |
| 544 | return v8::Handle<Boolean>(); |
| 545 | } |
| 546 | return v8::Handle<Boolean>( |
| 547 | ToApi<Boolean>(isolate->factory()->false_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | |
| 551 | ResourceConstraints::ResourceConstraints() |
| 552 | : max_young_space_size_(0), |
| 553 | max_old_space_size_(0), |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 554 | max_executable_size_(0), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | stack_limit_(NULL) { } |
| 556 | |
| 557 | |
| 558 | bool SetResourceConstraints(ResourceConstraints* constraints) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 559 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 560 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 561 | int young_space_size = constraints->max_young_space_size(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 562 | int old_gen_size = constraints->max_old_space_size(); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 563 | int max_executable_size = constraints->max_executable_size(); |
| 564 | 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] | 565 | // After initialization it's too late to change Heap constraints. |
| 566 | ASSERT(!isolate->IsInitialized()); |
| 567 | bool result = isolate->heap()->ConfigureHeap(young_space_size / 2, |
| 568 | old_gen_size, |
| 569 | max_executable_size); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 570 | if (!result) return false; |
| 571 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 572 | if (constraints->stack_limit() != NULL) { |
| 573 | uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 574 | isolate->stack_guard()->SetStackLimit(limit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 575 | } |
| 576 | return true; |
| 577 | } |
| 578 | |
| 579 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 580 | i::Object** V8::GlobalizeReference(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 581 | i::Isolate* isolate = i::Isolate::Current(); |
| 582 | if (IsDeadCheck(isolate, "V8::Persistent::New")) return NULL; |
| 583 | LOG_API(isolate, "Persistent::New"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 584 | i::Handle<i::Object> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 585 | isolate->global_handles()->Create(*obj); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 586 | return result.location(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 590 | void V8::MakeWeak(i::Object** object, void* parameters, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 591 | WeakReferenceCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 592 | i::Isolate* isolate = i::Isolate::Current(); |
| 593 | LOG_API(isolate, "MakeWeak"); |
| 594 | isolate->global_handles()->MakeWeak(object, parameters, |
| 595 | callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 599 | void V8::ClearWeak(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 600 | i::Isolate* isolate = i::Isolate::Current(); |
| 601 | LOG_API(isolate, "ClearWeak"); |
| 602 | isolate->global_handles()->ClearWeakness(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 606 | void V8::MarkIndependent(i::Object** object) { |
| 607 | i::Isolate* isolate = i::Isolate::Current(); |
| 608 | LOG_API(isolate, "MakeIndependent"); |
| 609 | isolate->global_handles()->MarkIndependent(object); |
| 610 | } |
| 611 | |
| 612 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 613 | bool V8::IsGlobalNearDeath(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 614 | i::Isolate* isolate = i::Isolate::Current(); |
| 615 | LOG_API(isolate, "IsGlobalNearDeath"); |
| 616 | if (!isolate->IsInitialized()) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 617 | return i::GlobalHandles::IsNearDeath(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 621 | bool V8::IsGlobalWeak(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 622 | i::Isolate* isolate = i::Isolate::Current(); |
| 623 | LOG_API(isolate, "IsGlobalWeak"); |
| 624 | if (!isolate->IsInitialized()) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 625 | return i::GlobalHandles::IsWeak(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 629 | void V8::DisposeGlobal(i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 630 | i::Isolate* isolate = i::Isolate::Current(); |
| 631 | LOG_API(isolate, "DisposeGlobal"); |
| 632 | if (!isolate->IsInitialized()) return; |
| 633 | isolate->global_handles()->Destroy(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | // --- H a n d l e s --- |
| 637 | |
| 638 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 639 | HandleScope::HandleScope() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 640 | i::Isolate* isolate = i::Isolate::Current(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 641 | API_ENTRY_CHECK(isolate, "HandleScope::HandleScope"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 642 | v8::ImplementationUtilities::HandleScopeData* current = |
| 643 | isolate->handle_scope_data(); |
| 644 | isolate_ = isolate; |
| 645 | prev_next_ = current->next; |
| 646 | prev_limit_ = current->limit; |
| 647 | is_closed_ = false; |
| 648 | current->level++; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | |
| 652 | HandleScope::~HandleScope() { |
| 653 | if (!is_closed_) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 654 | Leave(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 655 | } |
| 656 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 657 | |
| 658 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 659 | void HandleScope::Leave() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 660 | ASSERT(isolate_ == i::Isolate::Current()); |
| 661 | v8::ImplementationUtilities::HandleScopeData* current = |
| 662 | isolate_->handle_scope_data(); |
| 663 | current->level--; |
| 664 | ASSERT(current->level >= 0); |
| 665 | current->next = prev_next_; |
| 666 | if (current->limit != prev_limit_) { |
| 667 | current->limit = prev_limit_; |
| 668 | i::HandleScope::DeleteExtensions(isolate_); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | #ifdef DEBUG |
| 672 | i::HandleScope::ZapRange(prev_next_, prev_limit_); |
| 673 | #endif |
| 674 | } |
| 675 | |
| 676 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 677 | int HandleScope::NumberOfHandles() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 678 | EnsureInitializedForIsolate( |
| 679 | i::Isolate::Current(), "HandleScope::NumberOfHandles"); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 680 | return i::HandleScope::NumberOfHandles(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 684 | i::Object** HandleScope::CreateHandle(i::Object* value) { |
| 685 | return i::HandleScope::CreateHandle(value, i::Isolate::Current()); |
| 686 | } |
| 687 | |
| 688 | |
| 689 | i::Object** HandleScope::CreateHandle(i::HeapObject* value) { |
| 690 | ASSERT(value->IsHeapObject()); |
| 691 | return reinterpret_cast<i::Object**>( |
| 692 | i::HandleScope::CreateHandle(value, value->GetIsolate())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | |
| 696 | void Context::Enter() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 697 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 698 | i::Isolate* isolate = env->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 699 | if (IsDeadCheck(isolate, "v8::Context::Enter()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 700 | ENTER_V8(isolate); |
| 701 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 702 | isolate->handle_scope_implementer()->EnterContext(env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 703 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 704 | isolate->handle_scope_implementer()->SaveContext(isolate->context()); |
| 705 | isolate->set_context(*env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | |
| 709 | void Context::Exit() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 710 | // Exit is essentially a static function and doesn't use the |
| 711 | // receiver, so we have to get the current isolate from the thread |
| 712 | // local. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 713 | i::Isolate* isolate = i::Isolate::Current(); |
| 714 | if (!isolate->IsInitialized()) return; |
| 715 | |
| 716 | if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(), |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 717 | "v8::Context::Exit()", |
| 718 | "Cannot exit non-entered context")) { |
| 719 | return; |
| 720 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 721 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 722 | // Content of 'last_context' could be NULL. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 723 | i::Context* last_context = |
| 724 | isolate->handle_scope_implementer()->RestoreContext(); |
| 725 | isolate->set_context(last_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 729 | void Context::SetData(v8::Handle<String> data) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 730 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 731 | i::Isolate* isolate = env->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 732 | if (IsDeadCheck(isolate, "v8::Context::SetData()")) return; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 733 | i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
| 734 | ASSERT(env->IsGlobalContext()); |
| 735 | if (env->IsGlobalContext()) { |
| 736 | env->set_data(*raw_data); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
| 740 | |
| 741 | v8::Local<v8::Value> Context::GetData() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 742 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 743 | i::Isolate* isolate = env->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 744 | if (IsDeadCheck(isolate, "v8::Context::GetData()")) { |
| 745 | return v8::Local<Value>(); |
| 746 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 747 | i::Object* raw_result = NULL; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 748 | ASSERT(env->IsGlobalContext()); |
| 749 | if (env->IsGlobalContext()) { |
| 750 | raw_result = env->data(); |
| 751 | } else { |
| 752 | return Local<Value>(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 753 | } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 754 | i::Handle<i::Object> result(raw_result, isolate); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 755 | return Utils::ToLocal(result); |
| 756 | } |
| 757 | |
| 758 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 759 | i::Object** v8::HandleScope::RawClose(i::Object** value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 760 | if (!ApiCheck(!is_closed_, |
| 761 | "v8::HandleScope::Close()", |
| 762 | "Local scope has already been closed")) { |
| 763 | return 0; |
| 764 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 765 | LOG_API(isolate_, "CloseHandleScope"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 766 | |
| 767 | // Read the result before popping the handle block. |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 768 | i::Object* result = NULL; |
| 769 | if (value != NULL) { |
| 770 | result = *value; |
| 771 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 772 | is_closed_ = true; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 773 | Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 774 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 775 | if (value == NULL) { |
| 776 | return NULL; |
| 777 | } |
| 778 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 779 | // Allocate a new handle on the previous handle block. |
| 780 | i::Handle<i::Object> handle(result); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 781 | return handle.location(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | |
| 785 | // --- N e a n d e r --- |
| 786 | |
| 787 | |
| 788 | // A constructor cannot easily return an error value, therefore it is necessary |
| 789 | // to check for a dead VM with ON_BAILOUT before constructing any Neander |
| 790 | // objects. To remind you about this there is no HandleScope in the |
| 791 | // NeanderObject constructor. When you add one to the site calling the |
| 792 | // constructor you should check that you ensured the VM was not dead first. |
| 793 | NeanderObject::NeanderObject(int size) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 794 | i::Isolate* isolate = i::Isolate::Current(); |
| 795 | EnsureInitializedForIsolate(isolate, "v8::Nowhere"); |
| 796 | ENTER_V8(isolate); |
| 797 | value_ = isolate->factory()->NewNeanderObject(); |
| 798 | i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 799 | value_->set_elements(*elements); |
| 800 | } |
| 801 | |
| 802 | |
| 803 | int NeanderObject::size() { |
| 804 | return i::FixedArray::cast(value_->elements())->length(); |
| 805 | } |
| 806 | |
| 807 | |
| 808 | NeanderArray::NeanderArray() : obj_(2) { |
| 809 | obj_.set(0, i::Smi::FromInt(0)); |
| 810 | } |
| 811 | |
| 812 | |
| 813 | int NeanderArray::length() { |
| 814 | return i::Smi::cast(obj_.get(0))->value(); |
| 815 | } |
| 816 | |
| 817 | |
| 818 | i::Object* NeanderArray::get(int offset) { |
| 819 | ASSERT(0 <= offset); |
| 820 | ASSERT(offset < length()); |
| 821 | return obj_.get(offset + 1); |
| 822 | } |
| 823 | |
| 824 | |
| 825 | // This method cannot easily return an error value, therefore it is necessary |
| 826 | // to check for a dead VM with ON_BAILOUT before calling it. To remind you |
| 827 | // about this there is no HandleScope in this method. When you add one to the |
| 828 | // site calling this method you should check that you ensured the VM was not |
| 829 | // dead first. |
| 830 | void NeanderArray::add(i::Handle<i::Object> value) { |
| 831 | int length = this->length(); |
| 832 | int size = obj_.size(); |
| 833 | if (length == size - 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 834 | i::Handle<i::FixedArray> new_elms = FACTORY->NewFixedArray(2 * size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 835 | for (int i = 0; i < length; i++) |
| 836 | new_elms->set(i + 1, get(i)); |
| 837 | obj_.value()->set_elements(*new_elms); |
| 838 | } |
| 839 | obj_.set(length + 1, *value); |
| 840 | obj_.set(0, i::Smi::FromInt(length + 1)); |
| 841 | } |
| 842 | |
| 843 | |
| 844 | void NeanderArray::set(int index, i::Object* value) { |
| 845 | if (index < 0 || index >= this->length()) return; |
| 846 | obj_.set(index + 1, value); |
| 847 | } |
| 848 | |
| 849 | |
| 850 | // --- T e m p l a t e --- |
| 851 | |
| 852 | |
| 853 | static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { |
| 854 | that->set_tag(i::Smi::FromInt(type)); |
| 855 | } |
| 856 | |
| 857 | |
| 858 | void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, |
| 859 | v8::PropertyAttribute attribute) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 860 | i::Isolate* isolate = i::Isolate::Current(); |
| 861 | if (IsDeadCheck(isolate, "v8::Template::Set()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 862 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 863 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 864 | i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list()); |
| 865 | if (list->IsUndefined()) { |
| 866 | list = NeanderArray().value(); |
| 867 | Utils::OpenHandle(this)->set_property_list(*list); |
| 868 | } |
| 869 | NeanderArray array(list); |
| 870 | array.add(Utils::OpenHandle(*name)); |
| 871 | array.add(Utils::OpenHandle(*value)); |
| 872 | array.add(Utils::OpenHandle(*v8::Integer::New(attribute))); |
| 873 | } |
| 874 | |
| 875 | |
| 876 | // --- F u n c t i o n T e m p l a t e --- |
| 877 | static void InitializeFunctionTemplate( |
| 878 | i::Handle<i::FunctionTemplateInfo> info) { |
| 879 | info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE)); |
| 880 | info->set_flag(0); |
| 881 | } |
| 882 | |
| 883 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 884 | Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 885 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 886 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::PrototypeTemplate()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 887 | return Local<ObjectTemplate>(); |
| 888 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 889 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 890 | i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template()); |
| 891 | if (result->IsUndefined()) { |
| 892 | result = Utils::OpenHandle(*ObjectTemplate::New()); |
| 893 | Utils::OpenHandle(this)->set_prototype_template(*result); |
| 894 | } |
| 895 | return Local<ObjectTemplate>(ToApi<ObjectTemplate>(result)); |
| 896 | } |
| 897 | |
| 898 | |
| 899 | void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 900 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 901 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 902 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 903 | Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); |
| 904 | } |
| 905 | |
| 906 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 907 | Local<FunctionTemplate> FunctionTemplate::New(InvocationCallback callback, |
| 908 | v8::Handle<Value> data, v8::Handle<Signature> signature) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 909 | i::Isolate* isolate = i::Isolate::Current(); |
| 910 | EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); |
| 911 | LOG_API(isolate, "FunctionTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 912 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 913 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 914 | isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 915 | i::Handle<i::FunctionTemplateInfo> obj = |
| 916 | i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
| 917 | InitializeFunctionTemplate(obj); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 918 | int next_serial_number = isolate->next_serial_number(); |
| 919 | isolate->set_next_serial_number(next_serial_number + 1); |
| 920 | obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | if (callback != 0) { |
| 922 | if (data.IsEmpty()) data = v8::Undefined(); |
| 923 | Utils::ToLocal(obj)->SetCallHandler(callback, data); |
| 924 | } |
| 925 | obj->set_undetectable(false); |
| 926 | obj->set_needs_access_check(false); |
| 927 | |
| 928 | if (!signature.IsEmpty()) |
| 929 | obj->set_signature(*Utils::OpenHandle(*signature)); |
| 930 | return Utils::ToLocal(obj); |
| 931 | } |
| 932 | |
| 933 | |
| 934 | Local<Signature> Signature::New(Handle<FunctionTemplate> receiver, |
| 935 | int argc, Handle<FunctionTemplate> argv[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 936 | i::Isolate* isolate = i::Isolate::Current(); |
| 937 | EnsureInitializedForIsolate(isolate, "v8::Signature::New()"); |
| 938 | LOG_API(isolate, "Signature::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 939 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 940 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 941 | isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 942 | i::Handle<i::SignatureInfo> obj = |
| 943 | i::Handle<i::SignatureInfo>::cast(struct_obj); |
| 944 | if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver)); |
| 945 | if (argc > 0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 946 | i::Handle<i::FixedArray> args = isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 947 | for (int i = 0; i < argc; i++) { |
| 948 | if (!argv[i].IsEmpty()) |
| 949 | args->set(i, *Utils::OpenHandle(*argv[i])); |
| 950 | } |
| 951 | obj->set_args(*args); |
| 952 | } |
| 953 | return Utils::ToLocal(obj); |
| 954 | } |
| 955 | |
| 956 | |
| 957 | Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) { |
| 958 | Handle<FunctionTemplate> types[1] = { type }; |
| 959 | return TypeSwitch::New(1, types); |
| 960 | } |
| 961 | |
| 962 | |
| 963 | Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 964 | i::Isolate* isolate = i::Isolate::Current(); |
| 965 | EnsureInitializedForIsolate(isolate, "v8::TypeSwitch::New()"); |
| 966 | LOG_API(isolate, "TypeSwitch::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 967 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 968 | i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 969 | for (int i = 0; i < argc; i++) |
| 970 | vector->set(i, *Utils::OpenHandle(*types[i])); |
| 971 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 972 | isolate->factory()->NewStruct(i::TYPE_SWITCH_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 973 | i::Handle<i::TypeSwitchInfo> obj = |
| 974 | i::Handle<i::TypeSwitchInfo>::cast(struct_obj); |
| 975 | obj->set_types(*vector); |
| 976 | return Utils::ToLocal(obj); |
| 977 | } |
| 978 | |
| 979 | |
| 980 | int TypeSwitch::match(v8::Handle<Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 981 | i::Isolate* isolate = i::Isolate::Current(); |
| 982 | LOG_API(isolate, "TypeSwitch::match"); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 983 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 984 | i::Handle<i::Object> obj = Utils::OpenHandle(*value); |
| 985 | i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this); |
| 986 | i::FixedArray* types = i::FixedArray::cast(info->types()); |
| 987 | for (int i = 0; i < types->length(); i++) { |
| 988 | if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i)))) |
| 989 | return i + 1; |
| 990 | } |
| 991 | return 0; |
| 992 | } |
| 993 | |
| 994 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 995 | #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
| 996 | i::Handle<i::Object> foreign = FromCData(cdata); \ |
| 997 | (obj)->setter(*foreign); \ |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 998 | } while (false) |
| 999 | |
| 1000 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1001 | void FunctionTemplate::SetCallHandler(InvocationCallback callback, |
| 1002 | v8::Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1003 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1004 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetCallHandler()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1005 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1006 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1007 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1008 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1009 | i::Handle<i::CallHandlerInfo> obj = |
| 1010 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1011 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1012 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1013 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1014 | Utils::OpenHandle(this)->set_call_code(*obj); |
| 1015 | } |
| 1016 | |
| 1017 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1018 | static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
| 1019 | v8::Handle<String> name, |
| 1020 | AccessorGetter getter, |
| 1021 | AccessorSetter setter, |
| 1022 | v8::Handle<Value> data, |
| 1023 | v8::AccessControl settings, |
| 1024 | v8::PropertyAttribute attributes) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1025 | i::Handle<i::AccessorInfo> obj = FACTORY->NewAccessorInfo(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1026 | ASSERT(getter != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1027 | SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1028 | SET_FIELD_WRAPPED(obj, set_setter, setter); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1029 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1030 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1031 | obj->set_name(*Utils::OpenHandle(*name)); |
| 1032 | if (settings & ALL_CAN_READ) obj->set_all_can_read(true); |
| 1033 | if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); |
| 1034 | if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true); |
| 1035 | obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); |
| 1036 | return obj; |
| 1037 | } |
| 1038 | |
| 1039 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1040 | void FunctionTemplate::AddInstancePropertyAccessor( |
| 1041 | v8::Handle<String> name, |
| 1042 | AccessorGetter getter, |
| 1043 | AccessorSetter setter, |
| 1044 | v8::Handle<Value> data, |
| 1045 | v8::AccessControl settings, |
| 1046 | v8::PropertyAttribute attributes) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1047 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1048 | if (IsDeadCheck(isolate, |
| 1049 | "v8::FunctionTemplate::AddInstancePropertyAccessor()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1050 | return; |
| 1051 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1052 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1053 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1054 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1055 | i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name, |
| 1056 | getter, setter, data, |
| 1057 | settings, attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1058 | i::Handle<i::Object> list(Utils::OpenHandle(this)->property_accessors()); |
| 1059 | if (list->IsUndefined()) { |
| 1060 | list = NeanderArray().value(); |
| 1061 | Utils::OpenHandle(this)->set_property_accessors(*list); |
| 1062 | } |
| 1063 | NeanderArray array(list); |
| 1064 | array.add(obj); |
| 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1069 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1070 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::InstanceTemplate()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1071 | || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) |
| 1072 | return Local<ObjectTemplate>(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1073 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1074 | if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) { |
| 1075 | Local<ObjectTemplate> templ = |
| 1076 | ObjectTemplate::New(v8::Handle<FunctionTemplate>(this)); |
| 1077 | Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ)); |
| 1078 | } |
| 1079 | i::Handle<i::ObjectTemplateInfo> result(i::ObjectTemplateInfo::cast( |
| 1080 | Utils::OpenHandle(this)->instance_template())); |
| 1081 | return Utils::ToLocal(result); |
| 1082 | } |
| 1083 | |
| 1084 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1085 | void FunctionTemplate::SetClassName(Handle<String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1086 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1087 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetClassName()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1088 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1089 | Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name)); |
| 1090 | } |
| 1091 | |
| 1092 | |
| 1093 | void FunctionTemplate::SetHiddenPrototype(bool value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1094 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1095 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetHiddenPrototype()")) { |
| 1096 | return; |
| 1097 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1098 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1099 | Utils::OpenHandle(this)->set_hidden_prototype(value); |
| 1100 | } |
| 1101 | |
| 1102 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1103 | void FunctionTemplate::ReadOnlyPrototype() { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1104 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1105 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetPrototypeAttributes()")) { |
| 1106 | return; |
| 1107 | } |
| 1108 | ENTER_V8(isolate); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1109 | Utils::OpenHandle(this)->set_read_only_prototype(true); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1113 | void FunctionTemplate::SetNamedInstancePropertyHandler( |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1114 | NamedPropertyGetter getter, |
| 1115 | NamedPropertySetter setter, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1116 | NamedPropertyQuery query, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1117 | NamedPropertyDeleter remover, |
| 1118 | NamedPropertyEnumerator enumerator, |
| 1119 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1120 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1121 | if (IsDeadCheck(isolate, |
| 1122 | "v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1123 | return; |
| 1124 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1125 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1126 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1127 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1128 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1129 | i::Handle<i::InterceptorInfo> obj = |
| 1130 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1131 | |
| 1132 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1133 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1134 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1135 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1136 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1137 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1138 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1139 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1140 | Utils::OpenHandle(this)->set_named_property_handler(*obj); |
| 1141 | } |
| 1142 | |
| 1143 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1144 | void FunctionTemplate::SetIndexedInstancePropertyHandler( |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1145 | IndexedPropertyGetter getter, |
| 1146 | IndexedPropertySetter setter, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1147 | IndexedPropertyQuery query, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1148 | IndexedPropertyDeleter remover, |
| 1149 | IndexedPropertyEnumerator enumerator, |
| 1150 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1151 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1152 | if (IsDeadCheck(isolate, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1153 | "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) { |
| 1154 | return; |
| 1155 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1156 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1157 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1158 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1159 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1160 | i::Handle<i::InterceptorInfo> obj = |
| 1161 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1162 | |
| 1163 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1164 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1165 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1166 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1167 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1168 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1169 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1170 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1171 | Utils::OpenHandle(this)->set_indexed_property_handler(*obj); |
| 1172 | } |
| 1173 | |
| 1174 | |
| 1175 | void FunctionTemplate::SetInstanceCallAsFunctionHandler( |
| 1176 | InvocationCallback callback, |
| 1177 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1178 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1179 | if (IsDeadCheck(isolate, |
| 1180 | "v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1181 | return; |
| 1182 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1183 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1184 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1185 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1186 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1187 | i::Handle<i::CallHandlerInfo> obj = |
| 1188 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1189 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
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_instance_call_handler(*obj); |
| 1193 | } |
| 1194 | |
| 1195 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1196 | // --- O b j e c t T e m p l a t e --- |
| 1197 | |
| 1198 | |
| 1199 | Local<ObjectTemplate> ObjectTemplate::New() { |
| 1200 | return New(Local<FunctionTemplate>()); |
| 1201 | } |
| 1202 | |
| 1203 | |
| 1204 | Local<ObjectTemplate> ObjectTemplate::New( |
| 1205 | v8::Handle<FunctionTemplate> constructor) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1206 | i::Isolate* isolate = i::Isolate::Current(); |
| 1207 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::New()")) { |
| 1208 | return Local<ObjectTemplate>(); |
| 1209 | } |
| 1210 | EnsureInitializedForIsolate(isolate, "v8::ObjectTemplate::New()"); |
| 1211 | LOG_API(isolate, "ObjectTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1212 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1213 | i::Handle<i::Struct> struct_obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1214 | isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1215 | i::Handle<i::ObjectTemplateInfo> obj = |
| 1216 | i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); |
| 1217 | InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
| 1218 | if (!constructor.IsEmpty()) |
| 1219 | obj->set_constructor(*Utils::OpenHandle(*constructor)); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1220 | obj->set_internal_field_count(i::Smi::FromInt(0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1221 | return Utils::ToLocal(obj); |
| 1222 | } |
| 1223 | |
| 1224 | |
| 1225 | // Ensure that the object template has a constructor. If no |
| 1226 | // constructor is available we create one. |
| 1227 | static void EnsureConstructor(ObjectTemplate* object_template) { |
| 1228 | if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { |
| 1229 | Local<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1230 | i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); |
| 1231 | constructor->set_instance_template(*Utils::OpenHandle(object_template)); |
| 1232 | Utils::OpenHandle(object_template)->set_constructor(*constructor); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | |
| 1237 | void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
| 1238 | AccessorGetter getter, |
| 1239 | AccessorSetter setter, |
| 1240 | v8::Handle<Value> data, |
| 1241 | AccessControl settings, |
| 1242 | PropertyAttribute attribute) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1243 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1244 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1245 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1246 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1247 | EnsureConstructor(this); |
| 1248 | i::FunctionTemplateInfo* constructor = |
| 1249 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1250 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1251 | Utils::ToLocal(cons)->AddInstancePropertyAccessor(name, |
| 1252 | getter, |
| 1253 | setter, |
| 1254 | data, |
| 1255 | settings, |
| 1256 | attribute); |
| 1257 | } |
| 1258 | |
| 1259 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1260 | void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 1261 | NamedPropertySetter setter, |
| 1262 | NamedPropertyQuery query, |
| 1263 | NamedPropertyDeleter remover, |
| 1264 | NamedPropertyEnumerator enumerator, |
| 1265 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1266 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1267 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) { |
| 1268 | return; |
| 1269 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1270 | ENTER_V8(isolate); |
| 1271 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1272 | EnsureConstructor(this); |
| 1273 | i::FunctionTemplateInfo* constructor = |
| 1274 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1275 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1276 | Utils::ToLocal(cons)->SetNamedInstancePropertyHandler(getter, |
| 1277 | setter, |
| 1278 | query, |
| 1279 | remover, |
| 1280 | enumerator, |
| 1281 | data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | |
| 1285 | void ObjectTemplate::MarkAsUndetectable() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1286 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1287 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::MarkAsUndetectable()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1288 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1289 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1290 | EnsureConstructor(this); |
| 1291 | i::FunctionTemplateInfo* constructor = |
| 1292 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1293 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1294 | cons->set_undetectable(true); |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | void ObjectTemplate::SetAccessCheckCallbacks( |
| 1299 | NamedSecurityCallback named_callback, |
| 1300 | IndexedSecurityCallback indexed_callback, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1301 | Handle<Value> data, |
| 1302 | bool turned_on_by_default) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1303 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1304 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessCheckCallbacks()")) { |
| 1305 | return; |
| 1306 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1307 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1308 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1309 | EnsureConstructor(this); |
| 1310 | |
| 1311 | i::Handle<i::Struct> struct_info = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1312 | isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1313 | i::Handle<i::AccessCheckInfo> info = |
| 1314 | i::Handle<i::AccessCheckInfo>::cast(struct_info); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1315 | |
| 1316 | SET_FIELD_WRAPPED(info, set_named_callback, named_callback); |
| 1317 | SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback); |
| 1318 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1319 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1320 | info->set_data(*Utils::OpenHandle(*data)); |
| 1321 | |
| 1322 | i::FunctionTemplateInfo* constructor = |
| 1323 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1324 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1325 | cons->set_access_check_info(*info); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1326 | cons->set_needs_access_check(turned_on_by_default); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1330 | void ObjectTemplate::SetIndexedPropertyHandler( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1331 | IndexedPropertyGetter getter, |
| 1332 | IndexedPropertySetter setter, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1333 | IndexedPropertyQuery query, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1334 | IndexedPropertyDeleter remover, |
| 1335 | IndexedPropertyEnumerator enumerator, |
| 1336 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1337 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1338 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetIndexedPropertyHandler()")) { |
| 1339 | return; |
| 1340 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1341 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1342 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1343 | EnsureConstructor(this); |
| 1344 | i::FunctionTemplateInfo* constructor = |
| 1345 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1346 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1347 | Utils::ToLocal(cons)->SetIndexedInstancePropertyHandler(getter, |
| 1348 | setter, |
| 1349 | query, |
| 1350 | remover, |
| 1351 | enumerator, |
| 1352 | data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | |
| 1356 | void ObjectTemplate::SetCallAsFunctionHandler(InvocationCallback callback, |
| 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, |
| 1360 | "v8::ObjectTemplate::SetCallAsFunctionHandler()")) { |
| 1361 | return; |
| 1362 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1363 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1364 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1365 | EnsureConstructor(this); |
| 1366 | i::FunctionTemplateInfo* constructor = |
| 1367 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1368 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1369 | Utils::ToLocal(cons)->SetInstanceCallAsFunctionHandler(callback, data); |
| 1370 | } |
| 1371 | |
| 1372 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1373 | int ObjectTemplate::InternalFieldCount() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1374 | if (IsDeadCheck(Utils::OpenHandle(this)->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1375 | "v8::ObjectTemplate::InternalFieldCount()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1376 | return 0; |
| 1377 | } |
| 1378 | return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1382 | void ObjectTemplate::SetInternalFieldCount(int value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1383 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1384 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetInternalFieldCount()")) { |
| 1385 | return; |
| 1386 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1387 | if (!ApiCheck(i::Smi::IsValid(value), |
| 1388 | "v8::ObjectTemplate::SetInternalFieldCount()", |
| 1389 | "Invalid internal field count")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1390 | return; |
| 1391 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1392 | ENTER_V8(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1393 | if (value > 0) { |
| 1394 | // The internal field count is set by the constructor function's |
| 1395 | // construct code, so we ensure that there is a constructor |
| 1396 | // function to do the setting. |
| 1397 | EnsureConstructor(this); |
| 1398 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1399 | Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(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 | // --- S c r i p t D a t a --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1404 | |
| 1405 | |
| 1406 | ScriptData* ScriptData::PreCompile(const char* input, int length) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1407 | i::Utf8ToUC16CharacterStream stream( |
| 1408 | reinterpret_cast<const unsigned char*>(input), length); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 1409 | return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_block_scoping); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1413 | ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { |
| 1414 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1415 | if (str->IsExternalTwoByteString()) { |
| 1416 | i::ExternalTwoByteStringUC16CharacterStream stream( |
| 1417 | i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 1418 | return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_block_scoping); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1419 | } else { |
| 1420 | i::GenericStringUC16CharacterStream stream(str, 0, str->length()); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 1421 | return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_block_scoping); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1422 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1426 | ScriptData* ScriptData::New(const char* data, int length) { |
| 1427 | // Return an empty ScriptData if the length is obviously invalid. |
| 1428 | if (length % sizeof(unsigned) != 0) { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1429 | return new i::ScriptDataImpl(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | // Copy the data to ensure it is properly aligned. |
| 1433 | int deserialized_data_length = length / sizeof(unsigned); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1434 | // If aligned, don't create a copy of the data. |
| 1435 | if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) { |
| 1436 | return new i::ScriptDataImpl(data, length); |
| 1437 | } |
| 1438 | // Copy the data to align it. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1439 | unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1440 | i::OS::MemCopy(deserialized_data, data, length); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1441 | |
| 1442 | return new i::ScriptDataImpl( |
| 1443 | i::Vector<unsigned>(deserialized_data, deserialized_data_length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | |
| 1447 | // --- S c r i p t --- |
| 1448 | |
| 1449 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1450 | Local<Script> Script::New(v8::Handle<String> source, |
| 1451 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1452 | v8::ScriptData* pre_data, |
| 1453 | v8::Handle<String> script_data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1454 | i::Isolate* isolate = i::Isolate::Current(); |
| 1455 | ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>()); |
| 1456 | LOG_API(isolate, "Script::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1457 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1458 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1459 | i::Handle<i::Object> name_obj; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1460 | int line_offset = 0; |
| 1461 | int column_offset = 0; |
| 1462 | if (origin != NULL) { |
| 1463 | if (!origin->ResourceName().IsEmpty()) { |
| 1464 | name_obj = Utils::OpenHandle(*origin->ResourceName()); |
| 1465 | } |
| 1466 | if (!origin->ResourceLineOffset().IsEmpty()) { |
| 1467 | line_offset = static_cast<int>(origin->ResourceLineOffset()->Value()); |
| 1468 | } |
| 1469 | if (!origin->ResourceColumnOffset().IsEmpty()) { |
| 1470 | column_offset = static_cast<int>(origin->ResourceColumnOffset()->Value()); |
| 1471 | } |
| 1472 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1473 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1474 | i::ScriptDataImpl* pre_data_impl = static_cast<i::ScriptDataImpl*>(pre_data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1475 | // We assert that the pre-data is sane, even though we can actually |
| 1476 | // handle it if it turns out not to be in release mode. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1477 | ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1478 | // If the pre-data isn't sane we simply ignore it |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1479 | if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) { |
| 1480 | pre_data_impl = NULL; |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1481 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1482 | i::Handle<i::SharedFunctionInfo> result = |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1483 | i::Compiler::Compile(str, |
| 1484 | name_obj, |
| 1485 | line_offset, |
| 1486 | column_offset, |
| 1487 | NULL, |
| 1488 | pre_data_impl, |
| 1489 | Utils::OpenHandle(*script_data), |
| 1490 | i::NOT_NATIVES_CODE); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1491 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1492 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1493 | return Local<Script>(ToApi<Script>(result)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | |
| 1497 | Local<Script> Script::New(v8::Handle<String> source, |
| 1498 | v8::Handle<Value> file_name) { |
| 1499 | ScriptOrigin origin(file_name); |
| 1500 | return New(source, &origin); |
| 1501 | } |
| 1502 | |
| 1503 | |
| 1504 | Local<Script> Script::Compile(v8::Handle<String> source, |
| 1505 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1506 | v8::ScriptData* pre_data, |
| 1507 | v8::Handle<String> script_data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1508 | i::Isolate* isolate = i::Isolate::Current(); |
| 1509 | ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>()); |
| 1510 | LOG_API(isolate, "Script::Compile"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1511 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1512 | Local<Script> generic = New(source, origin, pre_data, script_data); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1513 | if (generic.IsEmpty()) |
| 1514 | return generic; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1515 | i::Handle<i::Object> obj = Utils::OpenHandle(*generic); |
| 1516 | i::Handle<i::SharedFunctionInfo> function = |
| 1517 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1518 | i::Handle<i::JSFunction> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1519 | isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 1520 | function, |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1521 | isolate->global_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1522 | return Local<Script>(ToApi<Script>(result)); |
| 1523 | } |
| 1524 | |
| 1525 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1526 | Local<Script> Script::Compile(v8::Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1527 | v8::Handle<Value> file_name, |
| 1528 | v8::Handle<String> script_data) { |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1529 | ScriptOrigin origin(file_name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1530 | return Compile(source, &origin, 0, script_data); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1534 | Local<Value> Script::Run() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1535 | i::Isolate* isolate = i::Isolate::Current(); |
| 1536 | ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); |
| 1537 | LOG_API(isolate, "Script::Run"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1538 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1539 | i::Object* raw_result = NULL; |
| 1540 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1541 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1542 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 1543 | i::Handle<i::JSFunction> fun; |
| 1544 | if (obj->IsSharedFunctionInfo()) { |
| 1545 | i::Handle<i::SharedFunctionInfo> |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1546 | function_info(i::SharedFunctionInfo::cast(*obj), isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1547 | fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1548 | function_info, isolate->global_context()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1549 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1550 | fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1551 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1552 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1553 | i::Handle<i::Object> receiver( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1554 | isolate->context()->global_proxy(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1555 | i::Handle<i::Object> result = |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1556 | i::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1557 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1558 | raw_result = *result; |
| 1559 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1560 | i::Handle<i::Object> result(raw_result, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1561 | return Utils::ToLocal(result); |
| 1562 | } |
| 1563 | |
| 1564 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1565 | static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) { |
| 1566 | i::Handle<i::Object> obj = Utils::OpenHandle(script); |
| 1567 | i::Handle<i::SharedFunctionInfo> result; |
| 1568 | if (obj->IsSharedFunctionInfo()) { |
| 1569 | result = |
| 1570 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
| 1571 | } else { |
| 1572 | result = |
| 1573 | i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()); |
| 1574 | } |
| 1575 | return result; |
| 1576 | } |
| 1577 | |
| 1578 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1579 | Local<Value> Script::Id() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1580 | i::Isolate* isolate = i::Isolate::Current(); |
| 1581 | ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>()); |
| 1582 | LOG_API(isolate, "Script::Id"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1583 | i::Object* raw_id = NULL; |
| 1584 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1585 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1586 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
| 1587 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1588 | i::Handle<i::Object> id(script->id()); |
| 1589 | raw_id = *id; |
| 1590 | } |
| 1591 | i::Handle<i::Object> id(raw_id); |
| 1592 | return Utils::ToLocal(id); |
| 1593 | } |
| 1594 | |
| 1595 | |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1596 | void Script::SetData(v8::Handle<String> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1597 | i::Isolate* isolate = i::Isolate::Current(); |
| 1598 | ON_BAILOUT(isolate, "v8::Script::SetData()", return); |
| 1599 | LOG_API(isolate, "Script::SetData"); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1600 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1601 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1602 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1603 | i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1604 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1605 | script->set_data(*raw_data); |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1610 | // --- E x c e p t i o n s --- |
| 1611 | |
| 1612 | |
| 1613 | v8::TryCatch::TryCatch() |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1614 | : isolate_(i::Isolate::Current()), |
| 1615 | next_(isolate_->try_catch_handler_address()), |
| 1616 | exception_(isolate_->heap()->the_hole_value()), |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1617 | message_(i::Smi::FromInt(0)), |
| 1618 | is_verbose_(false), |
ager@chromium.org | 68e7ab7 | 2009-09-23 09:40:39 +0000 | [diff] [blame] | 1619 | can_continue_(true), |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1620 | capture_message_(true), |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1621 | rethrow_(false) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1622 | isolate_->RegisterTryCatchHandler(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | |
| 1626 | v8::TryCatch::~TryCatch() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1627 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1628 | if (rethrow_) { |
| 1629 | v8::HandleScope scope; |
| 1630 | v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(Exception()); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1631 | isolate_->UnregisterTryCatchHandler(this); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1632 | v8::ThrowException(exc); |
| 1633 | } else { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1634 | isolate_->UnregisterTryCatchHandler(this); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1635 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1639 | bool v8::TryCatch::HasCaught() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1640 | return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(); |
| 1641 | } |
| 1642 | |
| 1643 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 1644 | bool v8::TryCatch::CanContinue() const { |
| 1645 | return can_continue_; |
| 1646 | } |
| 1647 | |
| 1648 | |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1649 | v8::Handle<v8::Value> v8::TryCatch::ReThrow() { |
| 1650 | if (!HasCaught()) return v8::Local<v8::Value>(); |
| 1651 | rethrow_ = true; |
| 1652 | return v8::Undefined(); |
| 1653 | } |
| 1654 | |
| 1655 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1656 | v8::Local<Value> v8::TryCatch::Exception() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1657 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1658 | if (HasCaught()) { |
| 1659 | // Check for out of memory exception. |
| 1660 | i::Object* exception = reinterpret_cast<i::Object*>(exception_); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1661 | return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1662 | } else { |
| 1663 | return v8::Local<Value>(); |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1668 | v8::Local<Value> v8::TryCatch::StackTrace() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1669 | ASSERT(isolate_ == i::Isolate::Current()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1670 | if (HasCaught()) { |
| 1671 | i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); |
| 1672 | if (!raw_obj->IsJSObject()) return v8::Local<Value>(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1673 | i::HandleScope scope(isolate_); |
| 1674 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); |
| 1675 | i::Handle<i::String> name = isolate_->factory()->LookupAsciiSymbol("stack"); |
| 1676 | if (!obj->HasProperty(*name)) return v8::Local<Value>(); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1677 | i::Handle<i::Object> value = i::GetProperty(obj, name); |
| 1678 | if (value.is_null()) return v8::Local<Value>(); |
| 1679 | return v8::Utils::ToLocal(scope.CloseAndEscape(value)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1680 | } else { |
| 1681 | return v8::Local<Value>(); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1686 | v8::Local<v8::Message> v8::TryCatch::Message() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1687 | ASSERT(isolate_ == i::Isolate::Current()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1688 | if (HasCaught() && message_ != i::Smi::FromInt(0)) { |
| 1689 | i::Object* message = reinterpret_cast<i::Object*>(message_); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1690 | return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1691 | } else { |
| 1692 | return v8::Local<v8::Message>(); |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1697 | void v8::TryCatch::Reset() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1698 | ASSERT(isolate_ == i::Isolate::Current()); |
| 1699 | exception_ = isolate_->heap()->the_hole_value(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1700 | message_ = i::Smi::FromInt(0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | |
| 1704 | void v8::TryCatch::SetVerbose(bool value) { |
| 1705 | is_verbose_ = value; |
| 1706 | } |
| 1707 | |
| 1708 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1709 | void v8::TryCatch::SetCaptureMessage(bool value) { |
| 1710 | capture_message_ = value; |
| 1711 | } |
| 1712 | |
| 1713 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1714 | // --- M e s s a g e --- |
| 1715 | |
| 1716 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1717 | Local<String> Message::Get() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1718 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1719 | ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1720 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1721 | HandleScope scope; |
| 1722 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 1723 | i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(obj); |
| 1724 | Local<String> result = Utils::ToLocal(raw_result); |
| 1725 | return scope.Close(result); |
| 1726 | } |
| 1727 | |
| 1728 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1729 | v8::Handle<Value> Message::GetScriptResourceName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1730 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1731 | if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceName()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1732 | return Local<String>(); |
| 1733 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1734 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1735 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1736 | i::Handle<i::JSMessageObject> message = |
| 1737 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1738 | // Return this.script.name. |
| 1739 | i::Handle<i::JSValue> script = |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1740 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1741 | 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] | 1742 | return scope.Close(Utils::ToLocal(resource_name)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1746 | v8::Handle<Value> Message::GetScriptData() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1747 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1748 | if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceData()")) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1749 | return Local<Value>(); |
| 1750 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1751 | ENTER_V8(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1752 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1753 | i::Handle<i::JSMessageObject> message = |
| 1754 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1755 | // Return this.script.data. |
| 1756 | i::Handle<i::JSValue> script = |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1757 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script())); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1758 | i::Handle<i::Object> data(i::Script::cast(script->value())->data()); |
| 1759 | return scope.Close(Utils::ToLocal(data)); |
| 1760 | } |
| 1761 | |
| 1762 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1763 | v8::Handle<v8::StackTrace> Message::GetStackTrace() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1764 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1765 | if (IsDeadCheck(isolate, "v8::Message::GetStackTrace()")) { |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1766 | return Local<v8::StackTrace>(); |
| 1767 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1768 | ENTER_V8(isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1769 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1770 | i::Handle<i::JSMessageObject> message = |
| 1771 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1772 | i::Handle<i::Object> stackFramesObj(message->stack_frames()); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1773 | if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); |
| 1774 | i::Handle<i::JSArray> stackTrace = |
| 1775 | i::Handle<i::JSArray>::cast(stackFramesObj); |
| 1776 | return scope.Close(Utils::StackTraceToLocal(stackTrace)); |
| 1777 | } |
| 1778 | |
| 1779 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1780 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 1781 | i::Handle<i::Object> recv, |
| 1782 | int argc, |
| 1783 | i::Object** argv[], |
| 1784 | bool* has_pending_exception) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1785 | i::Isolate* isolate = i::Isolate::Current(); |
| 1786 | i::Handle<i::String> fmt_str = isolate->factory()->LookupAsciiSymbol(name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1787 | i::Object* object_fun = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1788 | isolate->js_builtins_object()->GetPropertyNoExceptionThrown(*fmt_str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1789 | i::Handle<i::JSFunction> fun = |
| 1790 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun)); |
| 1791 | i::Handle<i::Object> value = |
| 1792 | i::Execution::Call(fun, recv, argc, argv, has_pending_exception); |
| 1793 | return value; |
| 1794 | } |
| 1795 | |
| 1796 | |
| 1797 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 1798 | i::Handle<i::Object> data, |
| 1799 | bool* has_pending_exception) { |
| 1800 | i::Object** argv[1] = { data.location() }; |
| 1801 | return CallV8HeapFunction(name, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1802 | i::Isolate::Current()->js_builtins_object(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1803 | 1, |
| 1804 | argv, |
| 1805 | has_pending_exception); |
| 1806 | } |
| 1807 | |
| 1808 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1809 | int Message::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1810 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1811 | ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1812 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1813 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1814 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1815 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1816 | i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber", |
| 1817 | Utils::OpenHandle(this), |
| 1818 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1819 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1820 | return static_cast<int>(result->Number()); |
| 1821 | } |
| 1822 | |
| 1823 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1824 | int Message::GetStartPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1825 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1826 | if (IsDeadCheck(isolate, "v8::Message::GetStartPosition()")) return 0; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1827 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1828 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1829 | i::Handle<i::JSMessageObject> message = |
| 1830 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1831 | return message->start_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1835 | int Message::GetEndPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1836 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1837 | if (IsDeadCheck(isolate, "v8::Message::GetEndPosition()")) return 0; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1838 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1839 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1840 | i::Handle<i::JSMessageObject> message = |
| 1841 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1842 | return message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1846 | int Message::GetStartColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1847 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1848 | if (IsDeadCheck(isolate, "v8::Message::GetStartColumn()")) { |
| 1849 | return kNoColumnInfo; |
| 1850 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1851 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1852 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1853 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1854 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1855 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 1856 | "GetPositionInLine", |
| 1857 | data_obj, |
| 1858 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1859 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1860 | return static_cast<int>(start_col_obj->Number()); |
| 1861 | } |
| 1862 | |
| 1863 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1864 | int Message::GetEndColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1865 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1866 | if (IsDeadCheck(isolate, "v8::Message::GetEndColumn()")) return kNoColumnInfo; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1867 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1868 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1869 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1870 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1871 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 1872 | "GetPositionInLine", |
| 1873 | data_obj, |
| 1874 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1875 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1876 | i::Handle<i::JSMessageObject> message = |
| 1877 | i::Handle<i::JSMessageObject>::cast(data_obj); |
| 1878 | int start = message->start_position(); |
| 1879 | int end = message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1880 | return static_cast<int>(start_col_obj->Number()) + (end - start); |
| 1881 | } |
| 1882 | |
| 1883 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1884 | Local<String> Message::GetSourceLine() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1885 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1886 | ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1887 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1888 | HandleScope scope; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1889 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1890 | i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine", |
| 1891 | Utils::OpenHandle(this), |
| 1892 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1893 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::String>()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1894 | if (result->IsString()) { |
| 1895 | return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result))); |
| 1896 | } else { |
| 1897 | return Local<String>(); |
| 1898 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1902 | void Message::PrintCurrentStackTrace(FILE* out) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1903 | i::Isolate* isolate = i::Isolate::Current(); |
| 1904 | if (IsDeadCheck(isolate, "v8::Message::PrintCurrentStackTrace()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1905 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1906 | isolate->PrintCurrentStackTrace(out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1910 | // --- S t a c k T r a c e --- |
| 1911 | |
| 1912 | Local<StackFrame> StackTrace::GetFrame(uint32_t index) 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 | if (IsDeadCheck(isolate, "v8::StackTrace::GetFrame()")) { |
| 1915 | return Local<StackFrame>(); |
| 1916 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1917 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1918 | HandleScope scope; |
| 1919 | i::Handle<i::JSArray> self = Utils::OpenHandle(this); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1920 | i::Object* raw_object = self->GetElementNoExceptionThrown(index); |
| 1921 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1922 | return scope.Close(Utils::StackFrameToLocal(obj)); |
| 1923 | } |
| 1924 | |
| 1925 | |
| 1926 | int StackTrace::GetFrameCount() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1927 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1928 | if (IsDeadCheck(isolate, "v8::StackTrace::GetFrameCount()")) return -1; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1929 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1930 | return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); |
| 1931 | } |
| 1932 | |
| 1933 | |
| 1934 | Local<Array> StackTrace::AsArray() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1935 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1936 | if (IsDeadCheck(isolate, "v8::StackTrace::AsArray()")) Local<Array>(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1937 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1938 | return Utils::ToLocal(Utils::OpenHandle(this)); |
| 1939 | } |
| 1940 | |
| 1941 | |
| 1942 | Local<StackTrace> StackTrace::CurrentStackTrace(int frame_limit, |
| 1943 | StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1944 | i::Isolate* isolate = i::Isolate::Current(); |
| 1945 | if (IsDeadCheck(isolate, "v8::StackTrace::CurrentStackTrace()")) { |
| 1946 | Local<StackTrace>(); |
| 1947 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1948 | ENTER_V8(isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1949 | i::Handle<i::JSArray> stackTrace = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1950 | isolate->CaptureCurrentStackTrace(frame_limit, options); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1951 | return Utils::StackTraceToLocal(stackTrace); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | |
| 1955 | // --- S t a c k F r a m e --- |
| 1956 | |
| 1957 | int StackFrame::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1958 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1959 | if (IsDeadCheck(isolate, "v8::StackFrame::GetLineNumber()")) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1960 | return Message::kNoLineNumberInfo; |
| 1961 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1962 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1963 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1964 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 1965 | i::Handle<i::Object> line = GetProperty(self, "lineNumber"); |
| 1966 | if (!line->IsSmi()) { |
| 1967 | return Message::kNoLineNumberInfo; |
| 1968 | } |
| 1969 | return i::Smi::cast(*line)->value(); |
| 1970 | } |
| 1971 | |
| 1972 | |
| 1973 | int StackFrame::GetColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1974 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1975 | if (IsDeadCheck(isolate, "v8::StackFrame::GetColumn()")) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1976 | return Message::kNoColumnInfo; |
| 1977 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1978 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1979 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1980 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 1981 | i::Handle<i::Object> column = GetProperty(self, "column"); |
| 1982 | if (!column->IsSmi()) { |
| 1983 | return Message::kNoColumnInfo; |
| 1984 | } |
| 1985 | return i::Smi::cast(*column)->value(); |
| 1986 | } |
| 1987 | |
| 1988 | |
| 1989 | Local<String> StackFrame::GetScriptName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1990 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1991 | if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptName()")) { |
| 1992 | return Local<String>(); |
| 1993 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1994 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1995 | HandleScope scope; |
| 1996 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 1997 | i::Handle<i::Object> name = GetProperty(self, "scriptName"); |
| 1998 | if (!name->IsString()) { |
| 1999 | return Local<String>(); |
| 2000 | } |
| 2001 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2002 | } |
| 2003 | |
| 2004 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2005 | Local<String> StackFrame::GetScriptNameOrSourceURL() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2006 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2007 | if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptNameOrSourceURL()")) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2008 | return Local<String>(); |
| 2009 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2010 | ENTER_V8(isolate); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2011 | HandleScope scope; |
| 2012 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2013 | i::Handle<i::Object> name = GetProperty(self, "scriptNameOrSourceURL"); |
| 2014 | if (!name->IsString()) { |
| 2015 | return Local<String>(); |
| 2016 | } |
| 2017 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2018 | } |
| 2019 | |
| 2020 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2021 | Local<String> StackFrame::GetFunctionName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2022 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2023 | if (IsDeadCheck(isolate, "v8::StackFrame::GetFunctionName()")) { |
| 2024 | return Local<String>(); |
| 2025 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2026 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2027 | HandleScope scope; |
| 2028 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2029 | i::Handle<i::Object> name = GetProperty(self, "functionName"); |
| 2030 | if (!name->IsString()) { |
| 2031 | return Local<String>(); |
| 2032 | } |
| 2033 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2034 | } |
| 2035 | |
| 2036 | |
| 2037 | bool StackFrame::IsEval() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2038 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2039 | if (IsDeadCheck(isolate, "v8::StackFrame::IsEval()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2040 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2041 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2042 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2043 | i::Handle<i::Object> is_eval = GetProperty(self, "isEval"); |
| 2044 | return is_eval->IsTrue(); |
| 2045 | } |
| 2046 | |
| 2047 | |
| 2048 | bool StackFrame::IsConstructor() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2049 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2050 | if (IsDeadCheck(isolate, "v8::StackFrame::IsConstructor()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2051 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2052 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2053 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2054 | i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor"); |
| 2055 | return is_constructor->IsTrue(); |
| 2056 | } |
| 2057 | |
| 2058 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2059 | // --- D a t a --- |
| 2060 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2061 | bool Value::IsUndefined() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2062 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUndefined()")) { |
| 2063 | return false; |
| 2064 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2065 | return Utils::OpenHandle(this)->IsUndefined(); |
| 2066 | } |
| 2067 | |
| 2068 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2069 | bool Value::IsNull() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2070 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNull()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2071 | return Utils::OpenHandle(this)->IsNull(); |
| 2072 | } |
| 2073 | |
| 2074 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2075 | bool Value::IsTrue() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2076 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsTrue()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2077 | return Utils::OpenHandle(this)->IsTrue(); |
| 2078 | } |
| 2079 | |
| 2080 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2081 | bool Value::IsFalse() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2082 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFalse()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2083 | return Utils::OpenHandle(this)->IsFalse(); |
| 2084 | } |
| 2085 | |
| 2086 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2087 | bool Value::IsFunction() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2088 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFunction()")) { |
| 2089 | return false; |
| 2090 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2091 | return Utils::OpenHandle(this)->IsJSFunction(); |
| 2092 | } |
| 2093 | |
| 2094 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2095 | bool Value::FullIsString() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2096 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsString()")) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2097 | bool result = Utils::OpenHandle(this)->IsString(); |
| 2098 | ASSERT_EQ(result, QuickIsString()); |
| 2099 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2103 | bool Value::IsArray() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2104 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArray()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2105 | return Utils::OpenHandle(this)->IsJSArray(); |
| 2106 | } |
| 2107 | |
| 2108 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2109 | bool Value::IsObject() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2110 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2111 | return Utils::OpenHandle(this)->IsJSObject(); |
| 2112 | } |
| 2113 | |
| 2114 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2115 | bool Value::IsNumber() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2116 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2117 | return Utils::OpenHandle(this)->IsNumber(); |
| 2118 | } |
| 2119 | |
| 2120 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2121 | bool Value::IsBoolean() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2122 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsBoolean()")) { |
| 2123 | return false; |
| 2124 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2125 | return Utils::OpenHandle(this)->IsBoolean(); |
| 2126 | } |
| 2127 | |
| 2128 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2129 | bool Value::IsExternal() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2130 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsExternal()")) { |
| 2131 | return false; |
| 2132 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2133 | return Utils::OpenHandle(this)->IsForeign(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2137 | bool Value::IsInt32() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2138 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsInt32()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2139 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2140 | if (obj->IsSmi()) return true; |
| 2141 | if (obj->IsNumber()) { |
| 2142 | double value = obj->Number(); |
| 2143 | return i::FastI2D(i::FastD2I(value)) == value; |
| 2144 | } |
| 2145 | return false; |
| 2146 | } |
| 2147 | |
| 2148 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2149 | bool Value::IsUint32() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2150 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUint32()")) return false; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2151 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2152 | if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0; |
| 2153 | if (obj->IsNumber()) { |
| 2154 | double value = obj->Number(); |
| 2155 | return i::FastUI2D(i::FastD2UI(value)) == value; |
| 2156 | } |
| 2157 | return false; |
| 2158 | } |
| 2159 | |
| 2160 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2161 | bool Value::IsDate() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2162 | i::Isolate* isolate = i::Isolate::Current(); |
| 2163 | if (IsDeadCheck(isolate, "v8::Value::IsDate()")) return false; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2164 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2165 | return obj->HasSpecificClassOf(isolate->heap()->Date_symbol()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2169 | bool Value::IsStringObject() const { |
| 2170 | i::Isolate* isolate = i::Isolate::Current(); |
| 2171 | if (IsDeadCheck(isolate, "v8::Value::IsStringObject()")) return false; |
| 2172 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2173 | return obj->HasSpecificClassOf(isolate->heap()->String_symbol()); |
| 2174 | } |
| 2175 | |
| 2176 | |
| 2177 | bool Value::IsNumberObject() const { |
| 2178 | i::Isolate* isolate = i::Isolate::Current(); |
| 2179 | if (IsDeadCheck(isolate, "v8::Value::IsNumberObject()")) return false; |
| 2180 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2181 | return obj->HasSpecificClassOf(isolate->heap()->Number_symbol()); |
| 2182 | } |
| 2183 | |
| 2184 | |
| 2185 | static i::Object* LookupBuiltin(i::Isolate* isolate, |
| 2186 | const char* builtin_name) { |
| 2187 | i::Handle<i::String> symbol = |
| 2188 | isolate->factory()->LookupAsciiSymbol(builtin_name); |
| 2189 | i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object(); |
| 2190 | return builtins->GetPropertyNoExceptionThrown(*symbol); |
| 2191 | } |
| 2192 | |
| 2193 | |
| 2194 | static bool CheckConstructor(i::Isolate* isolate, |
| 2195 | i::Handle<i::JSObject> obj, |
| 2196 | const char* class_name) { |
| 2197 | return obj->map()->constructor() == LookupBuiltin(isolate, class_name); |
| 2198 | } |
| 2199 | |
| 2200 | |
| 2201 | bool Value::IsNativeError() const { |
| 2202 | i::Isolate* isolate = i::Isolate::Current(); |
| 2203 | if (IsDeadCheck(isolate, "v8::Value::IsNativeError()")) return false; |
| 2204 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2205 | if (obj->IsJSObject()) { |
| 2206 | i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj)); |
| 2207 | return CheckConstructor(isolate, js_obj, "$Error") || |
| 2208 | CheckConstructor(isolate, js_obj, "$EvalError") || |
| 2209 | CheckConstructor(isolate, js_obj, "$RangeError") || |
| 2210 | CheckConstructor(isolate, js_obj, "$ReferenceError") || |
| 2211 | CheckConstructor(isolate, js_obj, "$SyntaxError") || |
| 2212 | CheckConstructor(isolate, js_obj, "$TypeError") || |
| 2213 | CheckConstructor(isolate, js_obj, "$URIError"); |
| 2214 | } else { |
| 2215 | return false; |
| 2216 | } |
| 2217 | } |
| 2218 | |
| 2219 | |
| 2220 | bool Value::IsBooleanObject() const { |
| 2221 | i::Isolate* isolate = i::Isolate::Current(); |
| 2222 | if (IsDeadCheck(isolate, "v8::Value::IsBooleanObject()")) return false; |
| 2223 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2224 | return obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol()); |
| 2225 | } |
| 2226 | |
| 2227 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2228 | bool Value::IsRegExp() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2229 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsRegExp()")) return false; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2230 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2231 | return obj->IsJSRegExp(); |
| 2232 | } |
| 2233 | |
| 2234 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2235 | Local<String> Value::ToString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2236 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2237 | i::Handle<i::Object> str; |
| 2238 | if (obj->IsString()) { |
| 2239 | str = obj; |
| 2240 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2241 | i::Isolate* isolate = i::Isolate::Current(); |
| 2242 | if (IsDeadCheck(isolate, "v8::Value::ToString()")) { |
| 2243 | return Local<String>(); |
| 2244 | } |
| 2245 | LOG_API(isolate, "ToString"); |
| 2246 | ENTER_V8(isolate); |
| 2247 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2248 | str = i::Execution::ToString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2249 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2250 | } |
| 2251 | return Local<String>(ToApi<String>(str)); |
| 2252 | } |
| 2253 | |
| 2254 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2255 | Local<String> Value::ToDetailString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2256 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2257 | i::Handle<i::Object> str; |
| 2258 | if (obj->IsString()) { |
| 2259 | str = obj; |
| 2260 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2261 | i::Isolate* isolate = i::Isolate::Current(); |
| 2262 | if (IsDeadCheck(isolate, "v8::Value::ToDetailString()")) { |
| 2263 | return Local<String>(); |
| 2264 | } |
| 2265 | LOG_API(isolate, "ToDetailString"); |
| 2266 | ENTER_V8(isolate); |
| 2267 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2268 | str = i::Execution::ToDetailString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2269 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2270 | } |
| 2271 | return Local<String>(ToApi<String>(str)); |
| 2272 | } |
| 2273 | |
| 2274 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2275 | Local<v8::Object> Value::ToObject() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2276 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2277 | i::Handle<i::Object> val; |
| 2278 | if (obj->IsJSObject()) { |
| 2279 | val = obj; |
| 2280 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2281 | i::Isolate* isolate = i::Isolate::Current(); |
| 2282 | if (IsDeadCheck(isolate, "v8::Value::ToObject()")) { |
| 2283 | return Local<v8::Object>(); |
| 2284 | } |
| 2285 | LOG_API(isolate, "ToObject"); |
| 2286 | ENTER_V8(isolate); |
| 2287 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2288 | val = i::Execution::ToObject(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2289 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2290 | } |
| 2291 | return Local<v8::Object>(ToApi<Object>(val)); |
| 2292 | } |
| 2293 | |
| 2294 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2295 | Local<Boolean> Value::ToBoolean() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2296 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2297 | if (obj->IsBoolean()) { |
| 2298 | return Local<Boolean>(ToApi<Boolean>(obj)); |
| 2299 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2300 | i::Isolate* isolate = i::Isolate::Current(); |
| 2301 | if (IsDeadCheck(isolate, "v8::Value::ToBoolean()")) { |
| 2302 | return Local<Boolean>(); |
| 2303 | } |
| 2304 | LOG_API(isolate, "ToBoolean"); |
| 2305 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2306 | i::Handle<i::Object> val = i::Execution::ToBoolean(obj); |
| 2307 | return Local<Boolean>(ToApi<Boolean>(val)); |
| 2308 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2312 | Local<Number> Value::ToNumber() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2313 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2314 | i::Handle<i::Object> num; |
| 2315 | if (obj->IsNumber()) { |
| 2316 | num = obj; |
| 2317 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2318 | i::Isolate* isolate = i::Isolate::Current(); |
| 2319 | if (IsDeadCheck(isolate, "v8::Value::ToNumber()")) { |
| 2320 | return Local<Number>(); |
| 2321 | } |
| 2322 | LOG_API(isolate, "ToNumber"); |
| 2323 | ENTER_V8(isolate); |
| 2324 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2325 | num = i::Execution::ToNumber(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2326 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Number>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2327 | } |
| 2328 | return Local<Number>(ToApi<Number>(num)); |
| 2329 | } |
| 2330 | |
| 2331 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2332 | Local<Integer> Value::ToInteger() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2333 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2334 | i::Handle<i::Object> num; |
| 2335 | if (obj->IsSmi()) { |
| 2336 | num = 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::ToInteger()")) return Local<Integer>(); |
| 2340 | LOG_API(isolate, "ToInteger"); |
| 2341 | ENTER_V8(isolate); |
| 2342 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2343 | num = i::Execution::ToInteger(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2344 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2345 | } |
| 2346 | return Local<Integer>(ToApi<Integer>(num)); |
| 2347 | } |
| 2348 | |
| 2349 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2350 | void External::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2351 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2352 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2353 | ApiCheck(obj->IsForeign(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2354 | "v8::External::Cast()", |
| 2355 | "Could not convert to external"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2359 | void v8::Object::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2360 | if (IsDeadCheck(i::Isolate::Current(), "v8::Object::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2361 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2362 | ApiCheck(obj->IsJSObject(), |
| 2363 | "v8::Object::Cast()", |
| 2364 | "Could not convert to object"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2368 | void v8::Function::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2369 | if (IsDeadCheck(i::Isolate::Current(), "v8::Function::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2370 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2371 | ApiCheck(obj->IsJSFunction(), |
| 2372 | "v8::Function::Cast()", |
| 2373 | "Could not convert to function"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2377 | void v8::String::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2378 | if (IsDeadCheck(i::Isolate::Current(), "v8::String::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2379 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2380 | ApiCheck(obj->IsString(), |
| 2381 | "v8::String::Cast()", |
| 2382 | "Could not convert to string"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2386 | void v8::Number::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2387 | if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2388 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2389 | ApiCheck(obj->IsNumber(), |
| 2390 | "v8::Number::Cast()", |
| 2391 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2395 | void v8::Integer::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2396 | if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2397 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2398 | ApiCheck(obj->IsNumber(), |
| 2399 | "v8::Integer::Cast()", |
| 2400 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2404 | void v8::Array::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2405 | if (IsDeadCheck(i::Isolate::Current(), "v8::Array::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2406 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2407 | ApiCheck(obj->IsJSArray(), |
| 2408 | "v8::Array::Cast()", |
| 2409 | "Could not convert to array"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2413 | void v8::Date::CheckCast(v8::Value* that) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2414 | i::Isolate* isolate = i::Isolate::Current(); |
| 2415 | if (IsDeadCheck(isolate, "v8::Date::Cast()")) return; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2416 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2417 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_symbol()), |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2418 | "v8::Date::Cast()", |
| 2419 | "Could not convert to date"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2423 | void v8::StringObject::CheckCast(v8::Value* that) { |
| 2424 | i::Isolate* isolate = i::Isolate::Current(); |
| 2425 | if (IsDeadCheck(isolate, "v8::StringObject::Cast()")) return; |
| 2426 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2427 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->String_symbol()), |
| 2428 | "v8::StringObject::Cast()", |
| 2429 | "Could not convert to StringObject"); |
| 2430 | } |
| 2431 | |
| 2432 | |
| 2433 | void v8::NumberObject::CheckCast(v8::Value* that) { |
| 2434 | i::Isolate* isolate = i::Isolate::Current(); |
| 2435 | if (IsDeadCheck(isolate, "v8::NumberObject::Cast()")) return; |
| 2436 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2437 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Number_symbol()), |
| 2438 | "v8::NumberObject::Cast()", |
| 2439 | "Could not convert to NumberObject"); |
| 2440 | } |
| 2441 | |
| 2442 | |
| 2443 | void v8::BooleanObject::CheckCast(v8::Value* that) { |
| 2444 | i::Isolate* isolate = i::Isolate::Current(); |
| 2445 | if (IsDeadCheck(isolate, "v8::BooleanObject::Cast()")) return; |
| 2446 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2447 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol()), |
| 2448 | "v8::BooleanObject::Cast()", |
| 2449 | "Could not convert to BooleanObject"); |
| 2450 | } |
| 2451 | |
| 2452 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2453 | void v8::RegExp::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2454 | if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::Cast()")) return; |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2455 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2456 | ApiCheck(obj->IsJSRegExp(), |
| 2457 | "v8::RegExp::Cast()", |
| 2458 | "Could not convert to regular expression"); |
| 2459 | } |
| 2460 | |
| 2461 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2462 | bool Value::BooleanValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2463 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2464 | if (obj->IsBoolean()) { |
| 2465 | return obj->IsTrue(); |
| 2466 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2467 | i::Isolate* isolate = i::Isolate::Current(); |
| 2468 | if (IsDeadCheck(isolate, "v8::Value::BooleanValue()")) return false; |
| 2469 | LOG_API(isolate, "BooleanValue"); |
| 2470 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2471 | i::Handle<i::Object> value = i::Execution::ToBoolean(obj); |
| 2472 | return value->IsTrue(); |
| 2473 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2477 | double Value::NumberValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2478 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2479 | i::Handle<i::Object> num; |
| 2480 | if (obj->IsNumber()) { |
| 2481 | num = obj; |
| 2482 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2483 | i::Isolate* isolate = i::Isolate::Current(); |
| 2484 | if (IsDeadCheck(isolate, "v8::Value::NumberValue()")) { |
| 2485 | return i::OS::nan_value(); |
| 2486 | } |
| 2487 | LOG_API(isolate, "NumberValue"); |
| 2488 | ENTER_V8(isolate); |
| 2489 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2490 | num = i::Execution::ToNumber(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2491 | EXCEPTION_BAILOUT_CHECK(isolate, i::OS::nan_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2492 | } |
| 2493 | return num->Number(); |
| 2494 | } |
| 2495 | |
| 2496 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2497 | int64_t Value::IntegerValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2498 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2499 | i::Handle<i::Object> num; |
| 2500 | if (obj->IsNumber()) { |
| 2501 | num = obj; |
| 2502 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2503 | i::Isolate* isolate = i::Isolate::Current(); |
| 2504 | if (IsDeadCheck(isolate, "v8::Value::IntegerValue()")) return 0; |
| 2505 | LOG_API(isolate, "IntegerValue"); |
| 2506 | ENTER_V8(isolate); |
| 2507 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2508 | num = i::Execution::ToInteger(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2509 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2510 | } |
| 2511 | if (num->IsSmi()) { |
| 2512 | return i::Smi::cast(*num)->value(); |
| 2513 | } else { |
| 2514 | return static_cast<int64_t>(num->Number()); |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2519 | Local<Int32> Value::ToInt32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2520 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2521 | i::Handle<i::Object> num; |
| 2522 | if (obj->IsSmi()) { |
| 2523 | num = obj; |
| 2524 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2525 | i::Isolate* isolate = i::Isolate::Current(); |
| 2526 | if (IsDeadCheck(isolate, "v8::Value::ToInt32()")) return Local<Int32>(); |
| 2527 | LOG_API(isolate, "ToInt32"); |
| 2528 | ENTER_V8(isolate); |
| 2529 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2530 | num = i::Execution::ToInt32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2531 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Int32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2532 | } |
| 2533 | return Local<Int32>(ToApi<Int32>(num)); |
| 2534 | } |
| 2535 | |
| 2536 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2537 | Local<Uint32> Value::ToUint32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2538 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2539 | i::Handle<i::Object> num; |
| 2540 | if (obj->IsSmi()) { |
| 2541 | num = obj; |
| 2542 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2543 | i::Isolate* isolate = i::Isolate::Current(); |
| 2544 | if (IsDeadCheck(isolate, "v8::Value::ToUint32()")) return Local<Uint32>(); |
| 2545 | LOG_API(isolate, "ToUInt32"); |
| 2546 | ENTER_V8(isolate); |
| 2547 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2548 | num = i::Execution::ToUint32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2549 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2550 | } |
| 2551 | return Local<Uint32>(ToApi<Uint32>(num)); |
| 2552 | } |
| 2553 | |
| 2554 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2555 | Local<Uint32> Value::ToArrayIndex() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2556 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2557 | if (obj->IsSmi()) { |
| 2558 | if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj); |
| 2559 | return Local<Uint32>(); |
| 2560 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2561 | i::Isolate* isolate = i::Isolate::Current(); |
| 2562 | if (IsDeadCheck(isolate, "v8::Value::ToArrayIndex()")) return Local<Uint32>(); |
| 2563 | LOG_API(isolate, "ToArrayIndex"); |
| 2564 | ENTER_V8(isolate); |
| 2565 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2566 | i::Handle<i::Object> string_obj = |
| 2567 | i::Execution::ToString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2568 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2569 | i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); |
| 2570 | uint32_t index; |
| 2571 | if (str->AsArrayIndex(&index)) { |
| 2572 | i::Handle<i::Object> value; |
| 2573 | if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) { |
| 2574 | value = i::Handle<i::Object>(i::Smi::FromInt(index)); |
| 2575 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2576 | value = isolate->factory()->NewNumber(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2577 | } |
| 2578 | return Utils::Uint32ToLocal(value); |
| 2579 | } |
| 2580 | return Local<Uint32>(); |
| 2581 | } |
| 2582 | |
| 2583 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2584 | int32_t Value::Int32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2585 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2586 | if (obj->IsSmi()) { |
| 2587 | return i::Smi::cast(*obj)->value(); |
| 2588 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2589 | i::Isolate* isolate = i::Isolate::Current(); |
| 2590 | if (IsDeadCheck(isolate, "v8::Value::Int32Value()")) return 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2591 | LOG_API(isolate, "Int32Value (slow)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2592 | ENTER_V8(isolate); |
| 2593 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2594 | i::Handle<i::Object> num = |
| 2595 | i::Execution::ToInt32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2596 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2597 | if (num->IsSmi()) { |
| 2598 | return i::Smi::cast(*num)->value(); |
| 2599 | } else { |
| 2600 | return static_cast<int32_t>(num->Number()); |
| 2601 | } |
| 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2606 | bool Value::Equals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2607 | i::Isolate* isolate = i::Isolate::Current(); |
| 2608 | if (IsDeadCheck(isolate, "v8::Value::Equals()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2609 | || EmptyCheck("v8::Value::Equals()", this) |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2610 | || EmptyCheck("v8::Value::Equals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2611 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2612 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2613 | LOG_API(isolate, "Equals"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2614 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2615 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2616 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2617 | // If both obj and other are JSObjects, we'd better compare by identity |
| 2618 | // immediately when going into JS builtin. The reason is Invoke |
| 2619 | // would overwrite global object receiver with global proxy. |
| 2620 | if (obj->IsJSObject() && other->IsJSObject()) { |
| 2621 | return *obj == *other; |
| 2622 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2623 | i::Object** args[1] = { other.location() }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2624 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2625 | i::Handle<i::Object> result = |
| 2626 | CallV8HeapFunction("EQUALS", obj, 1, args, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2627 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2628 | return *result == i::Smi::FromInt(i::EQUAL); |
| 2629 | } |
| 2630 | |
| 2631 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2632 | bool Value::StrictEquals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2633 | i::Isolate* isolate = i::Isolate::Current(); |
| 2634 | if (IsDeadCheck(isolate, "v8::Value::StrictEquals()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2635 | || EmptyCheck("v8::Value::StrictEquals()", this) |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2636 | || EmptyCheck("v8::Value::StrictEquals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2637 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2638 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2639 | LOG_API(isolate, "StrictEquals"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2640 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2641 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
| 2642 | // Must check HeapNumber first, since NaN !== NaN. |
| 2643 | if (obj->IsHeapNumber()) { |
| 2644 | if (!other->IsNumber()) return false; |
| 2645 | double x = obj->Number(); |
| 2646 | double y = other->Number(); |
| 2647 | // Must check explicitly for NaN:s on Windows, but -0 works fine. |
| 2648 | return x == y && !isnan(x) && !isnan(y); |
| 2649 | } else if (*obj == *other) { // Also covers Booleans. |
| 2650 | return true; |
| 2651 | } else if (obj->IsSmi()) { |
| 2652 | return other->IsNumber() && obj->Number() == other->Number(); |
| 2653 | } else if (obj->IsString()) { |
| 2654 | return other->IsString() && |
| 2655 | i::String::cast(*obj)->Equals(i::String::cast(*other)); |
| 2656 | } else if (obj->IsUndefined() || obj->IsUndetectableObject()) { |
| 2657 | return other->IsUndefined() || other->IsUndetectableObject(); |
| 2658 | } else { |
| 2659 | return false; |
| 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2664 | uint32_t Value::Uint32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2665 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2666 | if (obj->IsSmi()) { |
| 2667 | return i::Smi::cast(*obj)->value(); |
| 2668 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2669 | i::Isolate* isolate = i::Isolate::Current(); |
| 2670 | if (IsDeadCheck(isolate, "v8::Value::Uint32Value()")) return 0; |
| 2671 | LOG_API(isolate, "Uint32Value"); |
| 2672 | ENTER_V8(isolate); |
| 2673 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2674 | i::Handle<i::Object> num = |
| 2675 | i::Execution::ToUint32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2676 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2677 | if (num->IsSmi()) { |
| 2678 | return i::Smi::cast(*num)->value(); |
| 2679 | } else { |
| 2680 | return static_cast<uint32_t>(num->Number()); |
| 2681 | } |
| 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | |
| 2686 | 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] | 2687 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2688 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2689 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2690 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2691 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2692 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 2693 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2694 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2695 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2696 | i::Handle<i::Object> obj = i::SetProperty( |
| 2697 | self, |
| 2698 | key_obj, |
| 2699 | value_obj, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2700 | static_cast<PropertyAttributes>(attribs), |
| 2701 | i::kNonStrictMode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2702 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2703 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2704 | return true; |
| 2705 | } |
| 2706 | |
| 2707 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2708 | bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2709 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2710 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2711 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2712 | i::HandleScope scope(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2713 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2714 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2715 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2716 | i::Handle<i::Object> obj = i::SetElement( |
| 2717 | self, |
| 2718 | index, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2719 | value_obj, |
| 2720 | i::kNonStrictMode); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2721 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2722 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2723 | return true; |
| 2724 | } |
| 2725 | |
| 2726 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2727 | bool v8::Object::ForceSet(v8::Handle<Value> key, |
| 2728 | v8::Handle<Value> value, |
| 2729 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2730 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2731 | ON_BAILOUT(isolate, "v8::Object::ForceSet()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2732 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2733 | i::HandleScope scope(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2734 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2735 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2736 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2737 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2738 | i::Handle<i::Object> obj = i::ForceSetProperty( |
| 2739 | self, |
| 2740 | key_obj, |
| 2741 | value_obj, |
| 2742 | static_cast<PropertyAttributes>(attribs)); |
| 2743 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2744 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2745 | return true; |
| 2746 | } |
| 2747 | |
| 2748 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2749 | bool v8::Object::ForceDelete(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2750 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2751 | ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2752 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2753 | i::HandleScope scope(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2754 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2755 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2756 | |
| 2757 | // When turning on access checks for a global object deoptimize all functions |
| 2758 | // as optimized code does not always handle access checks. |
| 2759 | i::Deoptimizer::DeoptimizeGlobalObject(*self); |
| 2760 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2761 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2762 | i::Handle<i::Object> obj = i::ForceDeleteProperty(self, key_obj); |
| 2763 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2764 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2765 | return obj->IsTrue(); |
| 2766 | } |
| 2767 | |
| 2768 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2769 | Local<Value> v8::Object::Get(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2770 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2771 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2772 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2773 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 2774 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2775 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2776 | i::Handle<i::Object> result = i::GetProperty(self, key_obj); |
| 2777 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2778 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2779 | return Utils::ToLocal(result); |
| 2780 | } |
| 2781 | |
| 2782 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2783 | Local<Value> v8::Object::Get(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2784 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2785 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2786 | ENTER_V8(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2787 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2788 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2789 | i::Handle<i::Object> result = i::GetElement(self, index); |
| 2790 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2791 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2792 | return Utils::ToLocal(result); |
| 2793 | } |
| 2794 | |
| 2795 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2796 | PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { |
| 2797 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2798 | ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()", |
| 2799 | return static_cast<PropertyAttribute>(NONE)); |
| 2800 | ENTER_V8(isolate); |
| 2801 | i::HandleScope scope(isolate); |
| 2802 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2803 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2804 | if (!key_obj->IsString()) { |
| 2805 | EXCEPTION_PREAMBLE(isolate); |
| 2806 | key_obj = i::Execution::ToString(key_obj, &has_pending_exception); |
| 2807 | EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE)); |
| 2808 | } |
| 2809 | i::Handle<i::String> key_string = i::Handle<i::String>::cast(key_obj); |
| 2810 | PropertyAttributes result = self->GetPropertyAttribute(*key_string); |
| 2811 | if (result == ABSENT) return static_cast<PropertyAttribute>(NONE); |
| 2812 | return static_cast<PropertyAttribute>(result); |
| 2813 | } |
| 2814 | |
| 2815 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2816 | Local<Value> v8::Object::GetPrototype() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2817 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2818 | ON_BAILOUT(isolate, "v8::Object::GetPrototype()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2819 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2820 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2821 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 2822 | i::Handle<i::Object> result = i::GetPrototype(self); |
| 2823 | return Utils::ToLocal(result); |
| 2824 | } |
| 2825 | |
| 2826 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2827 | bool v8::Object::SetPrototype(Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2828 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2829 | ON_BAILOUT(isolate, "v8::Object::SetPrototype()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2830 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2831 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2832 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2833 | // We do not allow exceptions thrown while setting the prototype |
| 2834 | // to propagate outside. |
| 2835 | TryCatch try_catch; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2836 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2837 | i::Handle<i::Object> result = i::SetPrototype(self, value_obj); |
| 2838 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2839 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2840 | return true; |
| 2841 | } |
| 2842 | |
| 2843 | |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2844 | Local<Object> v8::Object::FindInstanceInPrototypeChain( |
| 2845 | v8::Handle<FunctionTemplate> tmpl) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2846 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2847 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2848 | "v8::Object::FindInstanceInPrototypeChain()", |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2849 | return Local<v8::Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2850 | ENTER_V8(isolate); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2851 | i::JSObject* object = *Utils::OpenHandle(this); |
| 2852 | i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl); |
| 2853 | while (!object->IsInstanceOf(tmpl_info)) { |
| 2854 | i::Object* prototype = object->GetPrototype(); |
| 2855 | if (!prototype->IsJSObject()) return Local<Object>(); |
| 2856 | object = i::JSObject::cast(prototype); |
| 2857 | } |
| 2858 | return Utils::ToLocal(i::Handle<i::JSObject>(object)); |
| 2859 | } |
| 2860 | |
| 2861 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2862 | Local<Array> v8::Object::GetPropertyNames() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2863 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2864 | ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()", |
| 2865 | return Local<v8::Array>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2866 | ENTER_V8(isolate); |
| 2867 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2868 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 2869 | i::Handle<i::FixedArray> value = |
| 2870 | i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2871 | // Because we use caching to speed up enumeration it is important |
| 2872 | // to never change the result of the basic enumeration function so |
| 2873 | // we clone the result. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2874 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 2875 | i::Handle<i::JSArray> result = |
| 2876 | isolate->factory()->NewJSArrayWithElements(elms); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2877 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2881 | Local<Array> v8::Object::GetOwnPropertyNames() { |
| 2882 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2883 | ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()", |
| 2884 | return Local<v8::Array>()); |
| 2885 | ENTER_V8(isolate); |
| 2886 | i::HandleScope scope(isolate); |
| 2887 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2888 | i::Handle<i::FixedArray> value = |
| 2889 | i::GetKeysInFixedArrayFor(self, i::LOCAL_ONLY); |
| 2890 | // Because we use caching to speed up enumeration it is important |
| 2891 | // to never change the result of the basic enumeration function so |
| 2892 | // we clone the result. |
| 2893 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 2894 | i::Handle<i::JSArray> result = |
| 2895 | isolate->factory()->NewJSArrayWithElements(elms); |
| 2896 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
| 2897 | } |
| 2898 | |
| 2899 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2900 | Local<String> v8::Object::ObjectProtoToString() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2901 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2902 | ON_BAILOUT(isolate, "v8::Object::ObjectProtoToString()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2903 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2904 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2905 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2906 | |
| 2907 | i::Handle<i::Object> name(self->class_name()); |
| 2908 | |
| 2909 | // Native implementation of Object.prototype.toString (v8natives.js): |
| 2910 | // var c = %ClassOf(this); |
| 2911 | // if (c === 'Arguments') c = 'Object'; |
| 2912 | // return "[object " + c + "]"; |
| 2913 | |
| 2914 | if (!name->IsString()) { |
| 2915 | return v8::String::New("[object ]"); |
| 2916 | |
| 2917 | } else { |
| 2918 | i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); |
| 2919 | if (class_name->IsEqualTo(i::CStrVector("Arguments"))) { |
| 2920 | return v8::String::New("[object Object]"); |
| 2921 | |
| 2922 | } else { |
| 2923 | const char* prefix = "[object "; |
| 2924 | Local<String> str = Utils::ToLocal(class_name); |
| 2925 | const char* postfix = "]"; |
| 2926 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2927 | int prefix_len = i::StrLength(prefix); |
| 2928 | int str_len = str->Length(); |
| 2929 | int postfix_len = i::StrLength(postfix); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2930 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2931 | int buf_len = prefix_len + str_len + postfix_len; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2932 | i::ScopedVector<char> buf(buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2933 | |
| 2934 | // Write prefix. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2935 | char* ptr = buf.start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2936 | memcpy(ptr, prefix, prefix_len * v8::internal::kCharSize); |
| 2937 | ptr += prefix_len; |
| 2938 | |
| 2939 | // Write real content. |
| 2940 | str->WriteAscii(ptr, 0, str_len); |
| 2941 | ptr += str_len; |
| 2942 | |
| 2943 | // Write postfix. |
| 2944 | memcpy(ptr, postfix, postfix_len * v8::internal::kCharSize); |
| 2945 | |
| 2946 | // Copy the buffer into a heap-allocated string and return it. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2947 | Local<String> result = v8::String::New(buf.start(), buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2948 | return result; |
| 2949 | } |
| 2950 | } |
| 2951 | } |
| 2952 | |
| 2953 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2954 | Local<String> v8::Object::GetConstructorName() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2955 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2956 | ON_BAILOUT(isolate, "v8::Object::GetConstructorName()", |
| 2957 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2958 | ENTER_V8(isolate); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 2959 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2960 | i::Handle<i::String> name(self->constructor_name()); |
| 2961 | return Utils::ToLocal(name); |
| 2962 | } |
| 2963 | |
| 2964 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2965 | bool v8::Object::Delete(v8::Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2966 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2967 | ON_BAILOUT(isolate, "v8::Object::Delete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2968 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2969 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2970 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2971 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
| 2972 | return i::DeleteProperty(self, key_obj)->IsTrue(); |
| 2973 | } |
| 2974 | |
| 2975 | |
| 2976 | bool v8::Object::Has(v8::Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2977 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2978 | ON_BAILOUT(isolate, "v8::Object::Has()", return false); |
| 2979 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2980 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2981 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
| 2982 | return self->HasProperty(*key_obj); |
| 2983 | } |
| 2984 | |
| 2985 | |
| 2986 | bool v8::Object::Delete(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2987 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2988 | ON_BAILOUT(isolate, "v8::Object::DeleteProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2989 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2990 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2991 | HandleScope scope; |
| 2992 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2993 | return i::DeleteElement(self, index)->IsTrue(); |
| 2994 | } |
| 2995 | |
| 2996 | |
| 2997 | bool v8::Object::Has(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2998 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2999 | ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3000 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3001 | return self->HasElement(index); |
| 3002 | } |
| 3003 | |
| 3004 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3005 | bool Object::SetAccessor(Handle<String> name, |
| 3006 | AccessorGetter getter, |
| 3007 | AccessorSetter setter, |
| 3008 | v8::Handle<Value> data, |
| 3009 | AccessControl settings, |
| 3010 | PropertyAttribute attributes) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3011 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3012 | ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3013 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3014 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3015 | i::Handle<i::AccessorInfo> info = MakeAccessorInfo(name, |
| 3016 | getter, setter, data, |
| 3017 | settings, attributes); |
| 3018 | i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(this), info); |
| 3019 | return !result.is_null() && !result->IsUndefined(); |
| 3020 | } |
| 3021 | |
| 3022 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3023 | bool v8::Object::HasOwnProperty(Handle<String> key) { |
| 3024 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3025 | ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", |
| 3026 | return false); |
| 3027 | return Utils::OpenHandle(this)->HasLocalProperty( |
| 3028 | *Utils::OpenHandle(*key)); |
| 3029 | } |
| 3030 | |
| 3031 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3032 | bool v8::Object::HasRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3033 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3034 | ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3035 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3036 | return Utils::OpenHandle(this)->HasRealNamedProperty( |
| 3037 | *Utils::OpenHandle(*key)); |
| 3038 | } |
| 3039 | |
| 3040 | |
| 3041 | bool v8::Object::HasRealIndexedProperty(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3042 | ON_BAILOUT(Utils::OpenHandle(this)->GetIsolate(), |
| 3043 | "v8::Object::HasRealIndexedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3044 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3045 | return Utils::OpenHandle(this)->HasRealElementProperty(index); |
| 3046 | } |
| 3047 | |
| 3048 | |
| 3049 | bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3050 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3051 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3052 | "v8::Object::HasRealNamedCallbackProperty()", |
| 3053 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3054 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3055 | return Utils::OpenHandle(this)->HasRealNamedCallbackProperty( |
| 3056 | *Utils::OpenHandle(*key)); |
| 3057 | } |
| 3058 | |
| 3059 | |
| 3060 | bool v8::Object::HasNamedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3061 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3062 | ON_BAILOUT(isolate, "v8::Object::HasNamedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3063 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3064 | return Utils::OpenHandle(this)->HasNamedInterceptor(); |
| 3065 | } |
| 3066 | |
| 3067 | |
| 3068 | bool v8::Object::HasIndexedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3069 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3070 | ON_BAILOUT(isolate, "v8::Object::HasIndexedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3071 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3072 | return Utils::OpenHandle(this)->HasIndexedInterceptor(); |
| 3073 | } |
| 3074 | |
| 3075 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3076 | static Local<Value> GetPropertyByLookup(i::Isolate* isolate, |
| 3077 | i::Handle<i::JSObject> receiver, |
| 3078 | i::Handle<i::String> name, |
| 3079 | i::LookupResult* lookup) { |
| 3080 | if (!lookup->IsProperty()) { |
| 3081 | // No real property was found. |
| 3082 | return Local<Value>(); |
| 3083 | } |
| 3084 | |
| 3085 | // If the property being looked up is a callback, it can throw |
| 3086 | // an exception. |
| 3087 | EXCEPTION_PREAMBLE(isolate); |
| 3088 | i::Handle<i::Object> result = i::GetProperty(receiver, name, lookup); |
| 3089 | has_pending_exception = result.is_null(); |
| 3090 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3091 | |
| 3092 | return Utils::ToLocal(result); |
| 3093 | } |
| 3094 | |
| 3095 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3096 | Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3097 | Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3098 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3099 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3100 | "v8::Object::GetRealNamedPropertyInPrototypeChain()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3101 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3102 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3103 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3104 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
| 3105 | i::LookupResult lookup; |
| 3106 | self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3107 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3111 | Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) { |
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::GetRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3114 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3115 | ENTER_V8(isolate); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3116 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3117 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
| 3118 | i::LookupResult lookup; |
| 3119 | self_obj->LookupRealNamedProperty(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3120 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3124 | // Turns on access checks by copying the map and setting the check flag. |
| 3125 | // Because the object gets a new map, existing inline cache caching |
| 3126 | // the old map of this object will fail. |
| 3127 | void v8::Object::TurnOnAccessCheck() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3128 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3129 | ON_BAILOUT(isolate, "v8::Object::TurnOnAccessCheck()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3130 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3131 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3132 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3133 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3134 | // When turning on access checks for a global object deoptimize all functions |
| 3135 | // as optimized code does not always handle access checks. |
| 3136 | i::Deoptimizer::DeoptimizeGlobalObject(*obj); |
| 3137 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3138 | i::Handle<i::Map> new_map = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3139 | isolate->factory()->CopyMapDropTransitions(i::Handle<i::Map>(obj->map())); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3140 | new_map->set_is_access_check_needed(true); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3141 | obj->set_map(*new_map); |
| 3142 | } |
| 3143 | |
| 3144 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3145 | bool v8::Object::IsDirty() { |
| 3146 | return Utils::OpenHandle(this)->IsDirty(); |
| 3147 | } |
| 3148 | |
| 3149 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3150 | Local<v8::Object> v8::Object::Clone() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3151 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3152 | ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3153 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3154 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3155 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3156 | i::Handle<i::JSObject> result = i::Copy(self); |
| 3157 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3158 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3159 | return Utils::ToLocal(result); |
| 3160 | } |
| 3161 | |
| 3162 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3163 | static i::Context* GetCreationContext(i::JSObject* object) { |
| 3164 | i::Object* constructor = object->map()->constructor(); |
| 3165 | i::JSFunction* function; |
| 3166 | if (!constructor->IsJSFunction()) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3167 | // Functions have null as a constructor, |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3168 | // but any JSFunction knows its context immediately. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3169 | ASSERT(object->IsJSFunction()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3170 | function = i::JSFunction::cast(object); |
| 3171 | } else { |
| 3172 | function = i::JSFunction::cast(constructor); |
| 3173 | } |
| 3174 | return function->context()->global_context(); |
| 3175 | } |
| 3176 | |
| 3177 | |
| 3178 | Local<v8::Context> v8::Object::CreationContext() { |
| 3179 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3180 | ON_BAILOUT(isolate, |
| 3181 | "v8::Object::CreationContext()", return Local<v8::Context>()); |
| 3182 | ENTER_V8(isolate); |
| 3183 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3184 | i::Context* context = GetCreationContext(*self); |
| 3185 | return Utils::ToLocal(i::Handle<i::Context>(context)); |
| 3186 | } |
| 3187 | |
| 3188 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3189 | int v8::Object::GetIdentityHash() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3190 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3191 | ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3192 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3193 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3194 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3195 | return i::GetIdentityHash(self); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | |
| 3199 | bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, |
| 3200 | v8::Handle<v8::Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3201 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3202 | ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3203 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3204 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3205 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3206 | i::Handle<i::Object> hidden_props(i::GetHiddenProperties( |
| 3207 | self, |
| 3208 | i::JSObject::ALLOW_CREATION)); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3209 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3210 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3211 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3212 | i::Handle<i::Object> obj = i::SetProperty( |
| 3213 | hidden_props, |
| 3214 | key_obj, |
| 3215 | value_obj, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3216 | static_cast<PropertyAttributes>(None), |
| 3217 | i::kNonStrictMode); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3218 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3219 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3220 | return true; |
| 3221 | } |
| 3222 | |
| 3223 | |
| 3224 | v8::Local<v8::Value> v8::Object::GetHiddenValue(v8::Handle<v8::String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3225 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3226 | ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()", |
| 3227 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3228 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3229 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3230 | i::Handle<i::Object> hidden_props(i::GetHiddenProperties( |
| 3231 | self, |
| 3232 | i::JSObject::OMIT_CREATION)); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3233 | if (hidden_props->IsUndefined()) { |
| 3234 | return v8::Local<v8::Value>(); |
| 3235 | } |
| 3236 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3237 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3238 | i::Handle<i::Object> result = i::GetProperty(hidden_props, key_obj); |
| 3239 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3240 | EXCEPTION_BAILOUT_CHECK(isolate, v8::Local<v8::Value>()); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3241 | if (result->IsUndefined()) { |
| 3242 | return v8::Local<v8::Value>(); |
| 3243 | } |
| 3244 | return Utils::ToLocal(result); |
| 3245 | } |
| 3246 | |
| 3247 | |
| 3248 | bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3249 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3250 | ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3251 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3252 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3253 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3254 | i::Handle<i::Object> hidden_props(i::GetHiddenProperties( |
| 3255 | self, |
| 3256 | i::JSObject::OMIT_CREATION)); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3257 | if (hidden_props->IsUndefined()) { |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 3258 | return true; |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3259 | } |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 3260 | i::Handle<i::JSObject> js_obj(i::JSObject::cast(*hidden_props)); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3261 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
kasperl@chromium.org | acae378 | 2009-04-11 09:17:08 +0000 | [diff] [blame] | 3262 | return i::DeleteProperty(js_obj, key_obj)->IsTrue(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3266 | namespace { |
| 3267 | |
| 3268 | void PrepareExternalArrayElements(i::Handle<i::JSObject> object, |
| 3269 | void* data, |
| 3270 | ExternalArrayType array_type, |
| 3271 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3272 | i::Isolate* isolate = object->GetIsolate(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3273 | i::Handle<i::ExternalArray> array = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3274 | isolate->factory()->NewExternalArray(length, array_type, data); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3275 | |
| 3276 | // If the object already has external elements, create a new, unique |
| 3277 | // map if the element type is now changing, because assumptions about |
| 3278 | // generated code based on the receiver's map will be invalid. |
| 3279 | i::Handle<i::HeapObject> elements(object->elements()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3280 | bool cant_reuse_map = |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3281 | elements->map()->IsUndefined() || |
| 3282 | !elements->map()->has_external_array_elements() || |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3283 | elements->map() != isolate->heap()->MapForExternalArrayType(array_type); |
| 3284 | if (cant_reuse_map) { |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3285 | i::Handle<i::Map> external_array_map = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3286 | isolate->factory()->GetExternalArrayElementsMap( |
| 3287 | i::Handle<i::Map>(object->map()), |
| 3288 | array_type, |
| 3289 | object->HasFastProperties()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3290 | object->set_map(*external_array_map); |
| 3291 | } |
| 3292 | object->set_elements(*array); |
| 3293 | } |
| 3294 | |
| 3295 | } // namespace |
| 3296 | |
| 3297 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3298 | void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3299 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3300 | ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3301 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3302 | i::HandleScope scope(isolate); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3303 | if (!ApiCheck(length <= i::ExternalPixelArray::kMaxLength, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3304 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3305 | "length exceeds max acceptable value")) { |
| 3306 | return; |
| 3307 | } |
| 3308 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3309 | if (!ApiCheck(!self->IsJSArray(), |
| 3310 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3311 | "JSArray is not supported")) { |
| 3312 | return; |
| 3313 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3314 | PrepareExternalArrayElements(self, data, kExternalPixelArray, length); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3318 | bool v8::Object::HasIndexedPropertiesInPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3319 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3320 | ON_BAILOUT(self->GetIsolate(), "v8::HasIndexedPropertiesInPixelData()", |
| 3321 | return false); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3322 | return self->HasExternalPixelElements(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | |
| 3326 | uint8_t* v8::Object::GetIndexedPropertiesPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3327 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3328 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelData()", |
| 3329 | return NULL); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3330 | if (self->HasExternalPixelElements()) { |
| 3331 | return i::ExternalPixelArray::cast(self->elements())-> |
| 3332 | external_pixel_pointer(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3333 | } else { |
| 3334 | return NULL; |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | |
| 3339 | int v8::Object::GetIndexedPropertiesPixelDataLength() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3340 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3341 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelDataLength()", |
| 3342 | return -1); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3343 | if (self->HasExternalPixelElements()) { |
| 3344 | return i::ExternalPixelArray::cast(self->elements())->length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3345 | } else { |
| 3346 | return -1; |
| 3347 | } |
| 3348 | } |
| 3349 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3350 | void v8::Object::SetIndexedPropertiesToExternalArrayData( |
| 3351 | void* data, |
| 3352 | ExternalArrayType array_type, |
| 3353 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3354 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3355 | ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3356 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3357 | i::HandleScope scope(isolate); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3358 | if (!ApiCheck(length <= i::ExternalArray::kMaxLength, |
| 3359 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3360 | "length exceeds max acceptable value")) { |
| 3361 | return; |
| 3362 | } |
| 3363 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3364 | if (!ApiCheck(!self->IsJSArray(), |
| 3365 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3366 | "JSArray is not supported")) { |
| 3367 | return; |
| 3368 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3369 | PrepareExternalArrayElements(self, data, array_type, length); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3373 | bool v8::Object::HasIndexedPropertiesInExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3374 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3375 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3376 | "v8::HasIndexedPropertiesInExternalArrayData()", |
| 3377 | return false); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3378 | return self->HasExternalArrayElements(); |
| 3379 | } |
| 3380 | |
| 3381 | |
| 3382 | void* v8::Object::GetIndexedPropertiesExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3383 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3384 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3385 | "v8::GetIndexedPropertiesExternalArrayData()", |
| 3386 | return NULL); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3387 | if (self->HasExternalArrayElements()) { |
| 3388 | return i::ExternalArray::cast(self->elements())->external_pointer(); |
| 3389 | } else { |
| 3390 | return NULL; |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | |
| 3395 | ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3396 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3397 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3398 | "v8::GetIndexedPropertiesExternalArrayDataType()", |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3399 | return static_cast<ExternalArrayType>(-1)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3400 | switch (self->elements()->map()->instance_type()) { |
| 3401 | case i::EXTERNAL_BYTE_ARRAY_TYPE: |
| 3402 | return kExternalByteArray; |
| 3403 | case i::EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 3404 | return kExternalUnsignedByteArray; |
| 3405 | case i::EXTERNAL_SHORT_ARRAY_TYPE: |
| 3406 | return kExternalShortArray; |
| 3407 | case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 3408 | return kExternalUnsignedShortArray; |
| 3409 | case i::EXTERNAL_INT_ARRAY_TYPE: |
| 3410 | return kExternalIntArray; |
| 3411 | case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 3412 | return kExternalUnsignedIntArray; |
| 3413 | case i::EXTERNAL_FLOAT_ARRAY_TYPE: |
| 3414 | return kExternalFloatArray; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3415 | case i::EXTERNAL_DOUBLE_ARRAY_TYPE: |
| 3416 | return kExternalDoubleArray; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3417 | case i::EXTERNAL_PIXEL_ARRAY_TYPE: |
| 3418 | return kExternalPixelArray; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3419 | default: |
| 3420 | return static_cast<ExternalArrayType>(-1); |
| 3421 | } |
| 3422 | } |
| 3423 | |
| 3424 | |
| 3425 | int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3426 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3427 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3428 | "v8::GetIndexedPropertiesExternalArrayDataLength()", |
| 3429 | return 0); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3430 | if (self->HasExternalArrayElements()) { |
| 3431 | return i::ExternalArray::cast(self->elements())->length(); |
| 3432 | } else { |
| 3433 | return -1; |
| 3434 | } |
| 3435 | } |
| 3436 | |
| 3437 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3438 | bool v8::Object::IsCallable() { |
| 3439 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3440 | ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false); |
| 3441 | ENTER_V8(isolate); |
| 3442 | i::HandleScope scope(isolate); |
| 3443 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3444 | if (obj->IsJSFunction()) return true; |
| 3445 | return i::Execution::GetFunctionDelegate(obj)->IsJSFunction(); |
| 3446 | } |
| 3447 | |
| 3448 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3449 | Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Object> recv, int argc, |
| 3450 | v8::Handle<v8::Value> argv[]) { |
| 3451 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3452 | ON_BAILOUT(isolate, "v8::Object::CallAsFunction()", |
| 3453 | return Local<v8::Value>()); |
| 3454 | LOG_API(isolate, "Object::CallAsFunction"); |
| 3455 | ENTER_V8(isolate); |
| 3456 | i::HandleScope scope(isolate); |
| 3457 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3458 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3459 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 3460 | i::Object*** args = reinterpret_cast<i::Object***>(argv); |
| 3461 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(); |
| 3462 | if (obj->IsJSFunction()) { |
| 3463 | fun = i::Handle<i::JSFunction>::cast(obj); |
| 3464 | } else { |
| 3465 | EXCEPTION_PREAMBLE(isolate); |
| 3466 | i::Handle<i::Object> delegate = |
| 3467 | i::Execution::TryGetFunctionDelegate(obj, &has_pending_exception); |
| 3468 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3469 | fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3470 | recv_obj = obj; |
| 3471 | } |
| 3472 | EXCEPTION_PREAMBLE(isolate); |
| 3473 | i::Handle<i::Object> returned = |
| 3474 | i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); |
| 3475 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3476 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3477 | } |
| 3478 | |
| 3479 | |
| 3480 | Local<v8::Value> Object::CallAsConstructor(int argc, |
| 3481 | v8::Handle<v8::Value> argv[]) { |
| 3482 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3483 | ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()", |
| 3484 | return Local<v8::Object>()); |
| 3485 | LOG_API(isolate, "Object::CallAsConstructor"); |
| 3486 | ENTER_V8(isolate); |
| 3487 | i::HandleScope scope(isolate); |
| 3488 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3489 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 3490 | i::Object*** args = reinterpret_cast<i::Object***>(argv); |
| 3491 | if (obj->IsJSFunction()) { |
| 3492 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj); |
| 3493 | EXCEPTION_PREAMBLE(isolate); |
| 3494 | i::Handle<i::Object> returned = |
| 3495 | i::Execution::New(fun, argc, args, &has_pending_exception); |
| 3496 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3497 | return Utils::ToLocal(scope.CloseAndEscape( |
| 3498 | i::Handle<i::JSObject>::cast(returned))); |
| 3499 | } |
| 3500 | EXCEPTION_PREAMBLE(isolate); |
| 3501 | i::Handle<i::Object> delegate = |
| 3502 | i::Execution::TryGetConstructorDelegate(obj, &has_pending_exception); |
| 3503 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3504 | if (!delegate->IsUndefined()) { |
| 3505 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3506 | EXCEPTION_PREAMBLE(isolate); |
| 3507 | i::Handle<i::Object> returned = |
| 3508 | i::Execution::Call(fun, obj, argc, args, &has_pending_exception); |
| 3509 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3510 | ASSERT(!delegate->IsUndefined()); |
| 3511 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3512 | } |
| 3513 | return Local<v8::Object>(); |
| 3514 | } |
| 3515 | |
| 3516 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3517 | Local<v8::Object> Function::NewInstance() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3518 | return NewInstance(0, NULL); |
| 3519 | } |
| 3520 | |
| 3521 | |
| 3522 | Local<v8::Object> Function::NewInstance(int argc, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3523 | v8::Handle<v8::Value> argv[]) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3524 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3525 | ON_BAILOUT(isolate, "v8::Function::NewInstance()", |
| 3526 | return Local<v8::Object>()); |
| 3527 | LOG_API(isolate, "Function::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3528 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3529 | HandleScope scope; |
| 3530 | i::Handle<i::JSFunction> function = Utils::OpenHandle(this); |
| 3531 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 3532 | i::Object*** args = reinterpret_cast<i::Object***>(argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3533 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3534 | i::Handle<i::Object> returned = |
| 3535 | i::Execution::New(function, argc, args, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3536 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3537 | return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned))); |
| 3538 | } |
| 3539 | |
| 3540 | |
| 3541 | Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc, |
| 3542 | v8::Handle<v8::Value> argv[]) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3543 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3544 | ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>()); |
| 3545 | LOG_API(isolate, "Function::Call"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3546 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3547 | i::Object* raw_result = NULL; |
| 3548 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3549 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3550 | i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); |
| 3551 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3552 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 3553 | i::Object*** args = reinterpret_cast<i::Object***>(argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3554 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3555 | i::Handle<i::Object> returned = |
| 3556 | i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3557 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3558 | raw_result = *returned; |
| 3559 | } |
| 3560 | i::Handle<i::Object> result(raw_result); |
| 3561 | return Utils::ToLocal(result); |
| 3562 | } |
| 3563 | |
| 3564 | |
| 3565 | void Function::SetName(v8::Handle<v8::String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3566 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3567 | ENTER_V8(isolate); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3568 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3569 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3570 | func->shared()->set_name(*Utils::OpenHandle(*name)); |
| 3571 | } |
| 3572 | |
| 3573 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3574 | Handle<Value> Function::GetName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3575 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3576 | return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name())); |
| 3577 | } |
| 3578 | |
| 3579 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3580 | ScriptOrigin Function::GetScriptOrigin() const { |
| 3581 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3582 | if (func->shared()->script()->IsScript()) { |
| 3583 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 3584 | v8::ScriptOrigin origin( |
| 3585 | Utils::ToLocal(i::Handle<i::Object>(script->name())), |
| 3586 | v8::Integer::New(script->line_offset()->value()), |
| 3587 | v8::Integer::New(script->column_offset()->value())); |
| 3588 | return origin; |
| 3589 | } |
| 3590 | return v8::ScriptOrigin(Handle<Value>()); |
| 3591 | } |
| 3592 | |
| 3593 | |
| 3594 | const int Function::kLineOffsetNotFound = -1; |
| 3595 | |
| 3596 | |
| 3597 | int Function::GetScriptLineNumber() const { |
| 3598 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3599 | if (func->shared()->script()->IsScript()) { |
| 3600 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 3601 | return i::GetScriptLineNumber(script, func->shared()->start_position()); |
| 3602 | } |
| 3603 | return kLineOffsetNotFound; |
| 3604 | } |
| 3605 | |
| 3606 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3607 | int String::Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3608 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3609 | if (IsDeadCheck(str->GetIsolate(), "v8::String::Length()")) return 0; |
| 3610 | return str->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3614 | int String::Utf8Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3615 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3616 | if (IsDeadCheck(str->GetIsolate(), "v8::String::Utf8Length()")) return 0; |
| 3617 | return str->Utf8Length(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3621 | int String::WriteUtf8(char* buffer, |
| 3622 | int capacity, |
| 3623 | int* nchars_ref, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3624 | int options) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3625 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3626 | if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; |
| 3627 | LOG_API(isolate, "String::WriteUtf8"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3628 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3629 | i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3630 | i::Handle<i::String> str = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3631 | isolate->string_tracker()->RecordWrite(str); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3632 | if (options & HINT_MANY_WRITES_EXPECTED) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3633 | // Flatten the string for efficiency. This applies whether we are |
| 3634 | // using StringInputBuffer or Get(i) to access the characters. |
| 3635 | str->TryFlatten(); |
| 3636 | } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3637 | write_input_buffer.Reset(0, *str); |
| 3638 | int len = str->length(); |
| 3639 | // Encode the first K - 3 bytes directly into the buffer since we |
| 3640 | // know there's room for them. If no capacity is given we copy all |
| 3641 | // of them here. |
| 3642 | int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); |
| 3643 | int i; |
| 3644 | int pos = 0; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3645 | int nchars = 0; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3646 | for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) { |
| 3647 | i::uc32 c = write_input_buffer.GetNext(); |
| 3648 | int written = unibrow::Utf8::Encode(buffer + pos, c); |
| 3649 | pos += written; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3650 | nchars++; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3651 | } |
| 3652 | if (i < len) { |
| 3653 | // For the last characters we need to check the length for each one |
| 3654 | // because they may be longer than the remaining space in the |
| 3655 | // buffer. |
| 3656 | char intermediate[unibrow::Utf8::kMaxEncodedSize]; |
| 3657 | for (; i < len && pos < capacity; i++) { |
| 3658 | i::uc32 c = write_input_buffer.GetNext(); |
| 3659 | int written = unibrow::Utf8::Encode(intermediate, c); |
| 3660 | if (pos + written <= capacity) { |
| 3661 | for (int j = 0; j < written; j++) |
| 3662 | buffer[pos + j] = intermediate[j]; |
| 3663 | pos += written; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3664 | nchars++; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3665 | } else { |
| 3666 | // We've reached the end of the buffer |
| 3667 | break; |
| 3668 | } |
| 3669 | } |
| 3670 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3671 | if (nchars_ref != NULL) *nchars_ref = nchars; |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3672 | if (!(options & NO_NULL_TERMINATION) && |
| 3673 | (i == len && (capacity == -1 || pos < capacity))) |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3674 | buffer[pos++] = '\0'; |
| 3675 | return pos; |
| 3676 | } |
| 3677 | |
| 3678 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3679 | int String::WriteAscii(char* buffer, |
| 3680 | int start, |
| 3681 | int length, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3682 | int options) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3683 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3684 | if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0; |
| 3685 | LOG_API(isolate, "String::WriteAscii"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3686 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3687 | i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3688 | ASSERT(start >= 0 && length >= -1); |
| 3689 | i::Handle<i::String> str = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3690 | isolate->string_tracker()->RecordWrite(str); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3691 | if (options & HINT_MANY_WRITES_EXPECTED) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3692 | // Flatten the string for efficiency. This applies whether we are |
| 3693 | // using StringInputBuffer or Get(i) to access the characters. |
| 3694 | str->TryFlatten(); |
| 3695 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3696 | int end = length; |
| 3697 | if ( (length == -1) || (length > str->length() - start) ) |
| 3698 | end = str->length() - start; |
| 3699 | if (end < 0) return 0; |
| 3700 | write_input_buffer.Reset(start, *str); |
| 3701 | int i; |
| 3702 | for (i = 0; i < end; i++) { |
| 3703 | char c = static_cast<char>(write_input_buffer.GetNext()); |
| 3704 | if (c == '\0') c = ' '; |
| 3705 | buffer[i] = c; |
| 3706 | } |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3707 | if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3708 | buffer[i] = '\0'; |
| 3709 | return i; |
| 3710 | } |
| 3711 | |
| 3712 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3713 | int String::Write(uint16_t* buffer, |
| 3714 | int start, |
| 3715 | int length, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3716 | int options) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3717 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3718 | if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; |
| 3719 | LOG_API(isolate, "String::Write"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3720 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3721 | ASSERT(start >= 0 && length >= -1); |
| 3722 | i::Handle<i::String> str = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3723 | isolate->string_tracker()->RecordWrite(str); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3724 | if (options & HINT_MANY_WRITES_EXPECTED) { |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 3725 | // Flatten the string for efficiency. This applies whether we are |
| 3726 | // using StringInputBuffer or Get(i) to access the characters. |
| 3727 | str->TryFlatten(); |
| 3728 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3729 | int end = start + length; |
| 3730 | if ((length == -1) || (length > str->length() - start) ) |
| 3731 | end = str->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3732 | if (end < 0) return 0; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3733 | i::String::WriteToFlat(*str, buffer, start, end); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 3734 | if (!(options & NO_NULL_TERMINATION) && |
| 3735 | (length == -1 || end - start < length)) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3736 | buffer[end - start] = '\0'; |
| 3737 | } |
| 3738 | return end - start; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3742 | bool v8::String::IsExternal() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3743 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3744 | if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { |
| 3745 | return false; |
| 3746 | } |
| 3747 | EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3748 | return i::StringShape(*str).IsExternalTwoByte(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3752 | bool v8::String::IsExternalAscii() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3753 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3754 | if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternalAscii()")) { |
| 3755 | return false; |
| 3756 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3757 | return i::StringShape(*str).IsExternalAscii(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3761 | void v8::String::VerifyExternalStringResource( |
| 3762 | v8::String::ExternalStringResource* value) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3763 | i::Handle<i::String> str = Utils::OpenHandle(this); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3764 | v8::String::ExternalStringResource* expected; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3765 | if (i::StringShape(*str).IsExternalTwoByte()) { |
| 3766 | void* resource = i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3767 | expected = reinterpret_cast<ExternalStringResource*>(resource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3768 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3769 | expected = NULL; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3770 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3771 | CHECK_EQ(expected, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | |
| 3775 | v8::String::ExternalAsciiStringResource* |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3776 | v8::String::GetExternalAsciiStringResource() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3777 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3778 | if (IsDeadCheck(str->GetIsolate(), |
| 3779 | "v8::String::GetExternalAsciiStringResource()")) { |
| 3780 | return NULL; |
| 3781 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3782 | if (i::StringShape(*str).IsExternalAscii()) { |
| 3783 | void* resource = i::Handle<i::ExternalAsciiString>::cast(str)->resource(); |
| 3784 | return reinterpret_cast<ExternalAsciiStringResource*>(resource); |
| 3785 | } else { |
| 3786 | return NULL; |
| 3787 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3791 | double Number::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3792 | if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3793 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3794 | return obj->Number(); |
| 3795 | } |
| 3796 | |
| 3797 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3798 | bool Boolean::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3799 | if (IsDeadCheck(i::Isolate::Current(), "v8::Boolean::Value()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3800 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3801 | return obj->IsTrue(); |
| 3802 | } |
| 3803 | |
| 3804 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3805 | int64_t Integer::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3806 | if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3807 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3808 | if (obj->IsSmi()) { |
| 3809 | return i::Smi::cast(*obj)->value(); |
| 3810 | } else { |
| 3811 | return static_cast<int64_t>(obj->Number()); |
| 3812 | } |
| 3813 | } |
| 3814 | |
| 3815 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3816 | int32_t Int32::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3817 | if (IsDeadCheck(i::Isolate::Current(), "v8::Int32::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3818 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3819 | if (obj->IsSmi()) { |
| 3820 | return i::Smi::cast(*obj)->value(); |
| 3821 | } else { |
| 3822 | return static_cast<int32_t>(obj->Number()); |
| 3823 | } |
| 3824 | } |
| 3825 | |
| 3826 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3827 | uint32_t Uint32::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3828 | if (IsDeadCheck(i::Isolate::Current(), "v8::Uint32::Value()")) return 0; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3829 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3830 | if (obj->IsSmi()) { |
| 3831 | return i::Smi::cast(*obj)->value(); |
| 3832 | } else { |
| 3833 | return static_cast<uint32_t>(obj->Number()); |
| 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3838 | int v8::Object::InternalFieldCount() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3839 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3840 | if (IsDeadCheck(obj->GetIsolate(), "v8::Object::InternalFieldCount()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3841 | return 0; |
| 3842 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3843 | return obj->GetInternalFieldCount(); |
| 3844 | } |
| 3845 | |
| 3846 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3847 | Local<Value> v8::Object::CheckedGetInternalField(int index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3848 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3849 | if (IsDeadCheck(obj->GetIsolate(), "v8::Object::GetInternalField()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3850 | return Local<Value>(); |
| 3851 | } |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3852 | if (!ApiCheck(index < obj->GetInternalFieldCount(), |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3853 | "v8::Object::GetInternalField()", |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3854 | "Reading internal field out of bounds")) { |
| 3855 | return Local<Value>(); |
| 3856 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3857 | i::Handle<i::Object> value(obj->GetInternalField(index)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3858 | Local<Value> result = Utils::ToLocal(value); |
| 3859 | #ifdef DEBUG |
| 3860 | Local<Value> unchecked = UncheckedGetInternalField(index); |
| 3861 | ASSERT(unchecked.IsEmpty() || (unchecked == result)); |
| 3862 | #endif |
| 3863 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3867 | void v8::Object::SetInternalField(int index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3868 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3869 | i::Isolate* isolate = obj->GetIsolate(); |
| 3870 | if (IsDeadCheck(isolate, "v8::Object::SetInternalField()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3871 | return; |
| 3872 | } |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3873 | if (!ApiCheck(index < obj->GetInternalFieldCount(), |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3874 | "v8::Object::SetInternalField()", |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 3875 | "Writing internal field out of bounds")) { |
| 3876 | return; |
| 3877 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3878 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3879 | i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 3880 | obj->SetInternalField(index, *val); |
| 3881 | } |
| 3882 | |
| 3883 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3884 | static bool CanBeEncodedAsSmi(void* ptr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3885 | const uintptr_t address = reinterpret_cast<uintptr_t>(ptr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3886 | return ((address & i::kEncodablePointerMask) == 0); |
| 3887 | } |
| 3888 | |
| 3889 | |
| 3890 | static i::Smi* EncodeAsSmi(void* ptr) { |
| 3891 | ASSERT(CanBeEncodedAsSmi(ptr)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 3892 | const uintptr_t address = reinterpret_cast<uintptr_t>(ptr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3893 | i::Smi* result = reinterpret_cast<i::Smi*>(address << i::kPointerToSmiShift); |
| 3894 | ASSERT(i::Internals::HasSmiTag(result)); |
| 3895 | ASSERT_EQ(result, i::Smi::FromInt(result->value())); |
| 3896 | ASSERT_EQ(ptr, i::Internals::GetExternalPointerFromSmi(result)); |
| 3897 | return result; |
| 3898 | } |
| 3899 | |
| 3900 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3901 | void v8::Object::SetPointerInInternalField(int index, void* value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3902 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3903 | ENTER_V8(isolate); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3904 | if (CanBeEncodedAsSmi(value)) { |
| 3905 | Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value)); |
| 3906 | } else { |
| 3907 | HandleScope scope; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3908 | i::Handle<i::Foreign> foreign = |
| 3909 | isolate->factory()->NewForeign( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3910 | reinterpret_cast<i::Address>(value), i::TENURED); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3911 | if (!foreign.is_null()) |
| 3912 | Utils::OpenHandle(this)->SetInternalField(index, *foreign); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3913 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3914 | ASSERT_EQ(value, GetPointerFromInternalField(index)); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3918 | // --- E n v i r o n m e n t --- |
| 3919 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3920 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3921 | bool v8::V8::Initialize() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3922 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 3923 | if (isolate != NULL && isolate->IsInitialized()) { |
| 3924 | return true; |
| 3925 | } |
| 3926 | return InitializeHelper(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 3930 | void v8::V8::SetEntropySource(EntropySource source) { |
| 3931 | i::V8::SetEntropySource(source); |
| 3932 | } |
| 3933 | |
| 3934 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3935 | bool v8::V8::Dispose() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3936 | i::Isolate* isolate = i::Isolate::Current(); |
| 3937 | if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(), |
| 3938 | "v8::V8::Dispose()", |
| 3939 | "Use v8::Isolate::Dispose() for a non-default isolate.")) { |
| 3940 | return false; |
| 3941 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 3942 | i::V8::TearDown(); |
| 3943 | return true; |
| 3944 | } |
| 3945 | |
| 3946 | |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3947 | HeapStatistics::HeapStatistics(): total_heap_size_(0), |
| 3948 | total_heap_size_executable_(0), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3949 | used_heap_size_(0), |
| 3950 | heap_size_limit_(0) { } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3951 | |
| 3952 | |
| 3953 | void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3954 | i::Heap* heap = i::Isolate::Current()->heap(); |
| 3955 | heap_statistics->set_total_heap_size(heap->CommittedMemory()); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 3956 | heap_statistics->set_total_heap_size_executable( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3957 | heap->CommittedMemoryExecutable()); |
| 3958 | heap_statistics->set_used_heap_size(heap->SizeOfObjects()); |
| 3959 | heap_statistics->set_heap_size_limit(heap->MaxReserved()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3963 | bool v8::V8::IdleNotification() { |
| 3964 | // Returning true tells the caller that it need not |
| 3965 | // continue to call IdleNotification. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3966 | if (!i::Isolate::Current()->IsInitialized()) return true; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3967 | return i::V8::IdleNotification(); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3970 | |
| 3971 | void v8::V8::LowMemoryNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3972 | i::Isolate* isolate = i::Isolate::Current(); |
| 3973 | if (!isolate->IsInitialized()) return; |
| 3974 | isolate->heap()->CollectAllGarbage(true); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3978 | int v8::V8::ContextDisposedNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3979 | i::Isolate* isolate = i::Isolate::Current(); |
| 3980 | if (!isolate->IsInitialized()) return 0; |
| 3981 | return isolate->heap()->NotifyContextDisposed(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3985 | const char* v8::V8::GetVersion() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3986 | return i::Version::GetVersion(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3990 | static i::Handle<i::FunctionTemplateInfo> |
| 3991 | EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) { |
| 3992 | if (templ->constructor()->IsUndefined()) { |
| 3993 | Local<FunctionTemplate> constructor = FunctionTemplate::New(); |
| 3994 | Utils::OpenHandle(*constructor)->set_instance_template(*templ); |
| 3995 | templ->set_constructor(*Utils::OpenHandle(*constructor)); |
| 3996 | } |
| 3997 | return i::Handle<i::FunctionTemplateInfo>( |
| 3998 | i::FunctionTemplateInfo::cast(templ->constructor())); |
| 3999 | } |
| 4000 | |
| 4001 | |
| 4002 | Persistent<Context> v8::Context::New( |
| 4003 | v8::ExtensionConfiguration* extensions, |
| 4004 | v8::Handle<ObjectTemplate> global_template, |
| 4005 | v8::Handle<Value> global_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4006 | i::Isolate* isolate = i::Isolate::Current(); |
| 4007 | EnsureInitializedForIsolate(isolate, "v8::Context::New()"); |
| 4008 | LOG_API(isolate, "Context::New"); |
| 4009 | ON_BAILOUT(isolate, "v8::Context::New()", return Persistent<Context>()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4010 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4011 | // Enter V8 via an ENTER_V8 scope. |
| 4012 | i::Handle<i::Context> env; |
| 4013 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4014 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4015 | v8::Handle<ObjectTemplate> proxy_template = global_template; |
| 4016 | i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
| 4017 | i::Handle<i::FunctionTemplateInfo> global_constructor; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4018 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4019 | if (!global_template.IsEmpty()) { |
| 4020 | // Make sure that the global_template has a constructor. |
| 4021 | global_constructor = |
| 4022 | EnsureConstructor(Utils::OpenHandle(*global_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4023 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4024 | // Create a fresh template for the global proxy object. |
| 4025 | proxy_template = ObjectTemplate::New(); |
| 4026 | proxy_constructor = |
| 4027 | EnsureConstructor(Utils::OpenHandle(*proxy_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4028 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4029 | // Set the global template to be the prototype template of |
| 4030 | // global proxy template. |
| 4031 | proxy_constructor->set_prototype_template( |
| 4032 | *Utils::OpenHandle(*global_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4033 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4034 | // Migrate security handlers from global_template to |
| 4035 | // proxy_template. Temporarily removing access check |
| 4036 | // information from the global template. |
| 4037 | if (!global_constructor->access_check_info()->IsUndefined()) { |
| 4038 | proxy_constructor->set_access_check_info( |
| 4039 | global_constructor->access_check_info()); |
| 4040 | proxy_constructor->set_needs_access_check( |
| 4041 | global_constructor->needs_access_check()); |
| 4042 | global_constructor->set_needs_access_check(false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4043 | global_constructor->set_access_check_info( |
| 4044 | isolate->heap()->undefined_value()); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4045 | } |
| 4046 | } |
| 4047 | |
| 4048 | // Create the environment. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4049 | env = isolate->bootstrapper()->CreateEnvironment( |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 4050 | isolate, |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4051 | Utils::OpenHandle(*global_object), |
| 4052 | proxy_template, |
| 4053 | extensions); |
| 4054 | |
| 4055 | // Restore the access check info on the global template. |
| 4056 | if (!global_template.IsEmpty()) { |
| 4057 | ASSERT(!global_constructor.is_null()); |
| 4058 | ASSERT(!proxy_constructor.is_null()); |
| 4059 | global_constructor->set_access_check_info( |
| 4060 | proxy_constructor->access_check_info()); |
| 4061 | global_constructor->set_needs_access_check( |
| 4062 | proxy_constructor->needs_access_check()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4063 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4064 | isolate->runtime_profiler()->Reset(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4065 | } |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4066 | // Leave V8. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4067 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 4068 | if (env.is_null()) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4069 | return Persistent<Context>(); |
| 4070 | return Persistent<Context>(Utils::ToLocal(env)); |
| 4071 | } |
| 4072 | |
| 4073 | |
| 4074 | void v8::Context::SetSecurityToken(Handle<Value> token) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4075 | i::Isolate* isolate = i::Isolate::Current(); |
| 4076 | if (IsDeadCheck(isolate, "v8::Context::SetSecurityToken()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4077 | return; |
| 4078 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4079 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4080 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4081 | i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4082 | env->set_security_token(*token_handle); |
| 4083 | } |
| 4084 | |
| 4085 | |
| 4086 | void v8::Context::UseDefaultSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4087 | i::Isolate* isolate = i::Isolate::Current(); |
| 4088 | if (IsDeadCheck(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4089 | "v8::Context::UseDefaultSecurityToken()")) { |
| 4090 | return; |
| 4091 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4092 | ENTER_V8(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4093 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4094 | env->set_security_token(env->global()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | |
| 4098 | Handle<Value> v8::Context::GetSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4099 | i::Isolate* isolate = i::Isolate::Current(); |
| 4100 | if (IsDeadCheck(isolate, "v8::Context::GetSecurityToken()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4101 | return Handle<Value>(); |
| 4102 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4103 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4104 | i::Object* security_token = env->security_token(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4105 | i::Handle<i::Object> token_handle(security_token); |
| 4106 | return Utils::ToLocal(token_handle); |
| 4107 | } |
| 4108 | |
| 4109 | |
| 4110 | bool Context::HasOutOfMemoryException() { |
| 4111 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4112 | return env->has_out_of_memory(); |
| 4113 | } |
| 4114 | |
| 4115 | |
| 4116 | bool Context::InContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4117 | return i::Isolate::Current()->context() != NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4121 | v8::Local<v8::Context> Context::GetEntered() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4122 | i::Isolate* isolate = i::Isolate::Current(); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4123 | if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4124 | return Local<Context>(); |
| 4125 | } |
| 4126 | i::Handle<i::Object> last = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4127 | isolate->handle_scope_implementer()->LastEnteredContext(); |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4128 | if (last.is_null()) return Local<Context>(); |
| 4129 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(last); |
| 4130 | return Utils::ToLocal(context); |
| 4131 | } |
| 4132 | |
| 4133 | |
| 4134 | v8::Local<v8::Context> Context::GetCurrent() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4135 | i::Isolate* isolate = i::Isolate::Current(); |
| 4136 | if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4137 | return Local<Context>(); |
| 4138 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4139 | i::Handle<i::Object> current = isolate->global_context(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4140 | if (current.is_null()) return Local<Context>(); |
| 4141 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(current); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4142 | return Utils::ToLocal(context); |
| 4143 | } |
| 4144 | |
| 4145 | |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4146 | v8::Local<v8::Context> Context::GetCalling() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4147 | i::Isolate* isolate = i::Isolate::Current(); |
| 4148 | if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4149 | return Local<Context>(); |
| 4150 | } |
| 4151 | i::Handle<i::Object> calling = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4152 | isolate->GetCallingGlobalContext(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4153 | if (calling.is_null()) return Local<Context>(); |
| 4154 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(calling); |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4155 | return Utils::ToLocal(context); |
| 4156 | } |
| 4157 | |
| 4158 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4159 | v8::Local<v8::Object> Context::Global() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4160 | if (IsDeadCheck(i::Isolate::Current(), "v8::Context::Global()")) { |
| 4161 | return Local<v8::Object>(); |
| 4162 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4163 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4164 | i::Handle<i::Context> context = |
| 4165 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4166 | i::Handle<i::Object> global(context->global_proxy()); |
| 4167 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(global)); |
| 4168 | } |
| 4169 | |
| 4170 | |
| 4171 | void Context::DetachGlobal() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4172 | i::Isolate* isolate = i::Isolate::Current(); |
| 4173 | if (IsDeadCheck(isolate, "v8::Context::DetachGlobal()")) return; |
| 4174 | ENTER_V8(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4175 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4176 | i::Handle<i::Context> context = |
| 4177 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4178 | isolate->bootstrapper()->DetachGlobal(context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4182 | void Context::ReattachGlobal(Handle<Object> global_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4183 | i::Isolate* isolate = i::Isolate::Current(); |
| 4184 | if (IsDeadCheck(isolate, "v8::Context::ReattachGlobal()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4185 | ENTER_V8(isolate); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4186 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4187 | i::Handle<i::Context> context = |
| 4188 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4189 | isolate->bootstrapper()->ReattachGlobal( |
| 4190 | context, |
| 4191 | Utils::OpenHandle(*global_object)); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4195 | void Context::AllowCodeGenerationFromStrings(bool allow) { |
| 4196 | i::Isolate* isolate = i::Isolate::Current(); |
| 4197 | if (IsDeadCheck(isolate, "v8::Context::AllowCodeGenerationFromStrings()")) { |
| 4198 | return; |
| 4199 | } |
| 4200 | ENTER_V8(isolate); |
| 4201 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4202 | i::Handle<i::Context> context = |
| 4203 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
| 4204 | context->set_allow_code_gen_from_strings( |
| 4205 | allow ? isolate->heap()->true_value() : isolate->heap()->false_value()); |
| 4206 | } |
| 4207 | |
| 4208 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4209 | void V8::SetWrapperClassId(i::Object** global_handle, uint16_t class_id) { |
| 4210 | i::GlobalHandles::SetWrapperClassId(global_handle, class_id); |
| 4211 | } |
| 4212 | |
| 4213 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4214 | Local<v8::Object> ObjectTemplate::NewInstance() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4215 | i::Isolate* isolate = i::Isolate::Current(); |
| 4216 | ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", |
| 4217 | return Local<v8::Object>()); |
| 4218 | LOG_API(isolate, "ObjectTemplate::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4219 | ENTER_V8(isolate); |
| 4220 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4221 | i::Handle<i::Object> obj = |
| 4222 | i::Execution::InstantiateObject(Utils::OpenHandle(this), |
| 4223 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4224 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4225 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj)); |
| 4226 | } |
| 4227 | |
| 4228 | |
| 4229 | Local<v8::Function> FunctionTemplate::GetFunction() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4230 | i::Isolate* isolate = i::Isolate::Current(); |
| 4231 | ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4232 | return Local<v8::Function>()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4233 | LOG_API(isolate, "FunctionTemplate::GetFunction"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4234 | ENTER_V8(isolate); |
| 4235 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4236 | i::Handle<i::Object> obj = |
| 4237 | i::Execution::InstantiateFunction(Utils::OpenHandle(this), |
| 4238 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4239 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Function>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4240 | return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj)); |
| 4241 | } |
| 4242 | |
| 4243 | |
| 4244 | bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4245 | ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()", |
| 4246 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4247 | i::Object* obj = *Utils::OpenHandle(*value); |
| 4248 | return obj->IsInstanceOf(*Utils::OpenHandle(this)); |
| 4249 | } |
| 4250 | |
| 4251 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4252 | static Local<External> ExternalNewImpl(void* data) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4253 | return Utils::ToLocal(FACTORY->NewForeign(static_cast<i::Address>(data))); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | static void* ExternalValueImpl(i::Handle<i::Object> obj) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4257 | return reinterpret_cast<void*>(i::Foreign::cast(*obj)->address()); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4261 | Local<Value> v8::External::Wrap(void* data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4262 | i::Isolate* isolate = i::Isolate::Current(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4263 | STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4264 | EnsureInitializedForIsolate(isolate, "v8::External::Wrap()"); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4265 | LOG_API(isolate, "External::Wrap"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4266 | ENTER_V8(isolate); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4267 | |
| 4268 | v8::Local<v8::Value> result = CanBeEncodedAsSmi(data) |
| 4269 | ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data))) |
| 4270 | : v8::Local<v8::Value>(ExternalNewImpl(data)); |
| 4271 | |
| 4272 | ASSERT_EQ(data, Unwrap(result)); |
| 4273 | return result; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4274 | } |
| 4275 | |
| 4276 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4277 | void* v8::Object::SlowGetPointerFromInternalField(int index) { |
| 4278 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4279 | i::Object* value = obj->GetInternalField(index); |
| 4280 | if (value->IsSmi()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4281 | return i::Internals::GetExternalPointerFromSmi(value); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4282 | } else if (value->IsForeign()) { |
| 4283 | return reinterpret_cast<void*>(i::Foreign::cast(value)->address()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4284 | } else { |
| 4285 | return NULL; |
| 4286 | } |
| 4287 | } |
| 4288 | |
| 4289 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4290 | void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4291 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Unwrap()")) return 0; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4292 | i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); |
| 4293 | void* result; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4294 | if (obj->IsSmi()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4295 | result = i::Internals::GetExternalPointerFromSmi(*obj); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4296 | } else if (obj->IsForeign()) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4297 | result = ExternalValueImpl(obj); |
| 4298 | } else { |
| 4299 | result = NULL; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4300 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4301 | ASSERT_EQ(result, QuickUnwrap(wrapper)); |
| 4302 | return result; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4306 | Local<External> v8::External::New(void* data) { |
| 4307 | STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4308 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4309 | EnsureInitializedForIsolate(isolate, "v8::External::New()"); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4310 | LOG_API(isolate, "External::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4311 | ENTER_V8(isolate); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4312 | return ExternalNewImpl(data); |
| 4313 | } |
| 4314 | |
| 4315 | |
| 4316 | void* External::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4317 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Value()")) return 0; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4318 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4319 | return ExternalValueImpl(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4323 | Local<String> v8::String::Empty() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4324 | i::Isolate* isolate = i::Isolate::Current(); |
| 4325 | EnsureInitializedForIsolate(isolate, "v8::String::Empty()"); |
| 4326 | LOG_API(isolate, "String::Empty()"); |
| 4327 | return Utils::ToLocal(isolate->factory()->empty_symbol()); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4331 | Local<String> v8::String::New(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4332 | i::Isolate* isolate = i::Isolate::Current(); |
| 4333 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4334 | LOG_API(isolate, "String::New(char)"); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4335 | if (length == 0) return Empty(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4336 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4337 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4338 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4339 | isolate->factory()->NewStringFromUtf8( |
| 4340 | i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4341 | return Utils::ToLocal(result); |
| 4342 | } |
| 4343 | |
| 4344 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4345 | 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] | 4346 | i::Handle<i::String> left_string = Utils::OpenHandle(*left); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4347 | i::Isolate* isolate = left_string->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4348 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4349 | LOG_API(isolate, "String::New(char)"); |
| 4350 | ENTER_V8(isolate); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4351 | i::Handle<i::String> right_string = Utils::OpenHandle(*right); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4352 | i::Handle<i::String> result = isolate->factory()->NewConsString(left_string, |
| 4353 | right_string); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4354 | return Utils::ToLocal(result); |
| 4355 | } |
| 4356 | |
| 4357 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4358 | Local<String> v8::String::NewUndetectable(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4359 | i::Isolate* isolate = i::Isolate::Current(); |
| 4360 | EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()"); |
| 4361 | LOG_API(isolate, "String::NewUndetectable(char)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4362 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4363 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4364 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4365 | isolate->factory()->NewStringFromUtf8( |
| 4366 | i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4367 | result->MarkAsUndetectable(); |
| 4368 | return Utils::ToLocal(result); |
| 4369 | } |
| 4370 | |
| 4371 | |
| 4372 | static int TwoByteStringLength(const uint16_t* data) { |
| 4373 | int length = 0; |
| 4374 | while (data[length] != '\0') length++; |
| 4375 | return length; |
| 4376 | } |
| 4377 | |
| 4378 | |
| 4379 | Local<String> v8::String::New(const uint16_t* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4380 | i::Isolate* isolate = i::Isolate::Current(); |
| 4381 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4382 | LOG_API(isolate, "String::New(uint16_)"); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4383 | if (length == 0) return Empty(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4384 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4385 | if (length == -1) length = TwoByteStringLength(data); |
| 4386 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4387 | isolate->factory()->NewStringFromTwoByte( |
| 4388 | i::Vector<const uint16_t>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4389 | return Utils::ToLocal(result); |
| 4390 | } |
| 4391 | |
| 4392 | |
| 4393 | Local<String> v8::String::NewUndetectable(const uint16_t* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4394 | i::Isolate* isolate = i::Isolate::Current(); |
| 4395 | EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()"); |
| 4396 | LOG_API(isolate, "String::NewUndetectable(uint16_)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4397 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4398 | if (length == -1) length = TwoByteStringLength(data); |
| 4399 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4400 | isolate->factory()->NewStringFromTwoByte( |
| 4401 | i::Vector<const uint16_t>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4402 | result->MarkAsUndetectable(); |
| 4403 | return Utils::ToLocal(result); |
| 4404 | } |
| 4405 | |
| 4406 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4407 | i::Handle<i::String> NewExternalStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4408 | v8::String::ExternalStringResource* resource) { |
| 4409 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4410 | isolate->factory()->NewExternalStringFromTwoByte(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4411 | return result; |
| 4412 | } |
| 4413 | |
| 4414 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4415 | i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4416 | v8::String::ExternalAsciiStringResource* resource) { |
| 4417 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4418 | isolate->factory()->NewExternalStringFromAscii(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4419 | return result; |
| 4420 | } |
| 4421 | |
| 4422 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4423 | Local<String> v8::String::NewExternal( |
| 4424 | v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4425 | i::Isolate* isolate = i::Isolate::Current(); |
| 4426 | EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 4427 | LOG_API(isolate, "String::NewExternal"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4428 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4429 | i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); |
| 4430 | isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4431 | return Utils::ToLocal(result); |
| 4432 | } |
| 4433 | |
| 4434 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4435 | bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4436 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 4437 | i::Isolate* isolate = obj->GetIsolate(); |
| 4438 | if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4439 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 4440 | return false; // Already an external string. |
| 4441 | } |
| 4442 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4443 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 4444 | return false; |
| 4445 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4446 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 4447 | return false; |
| 4448 | } |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4449 | bool result = obj->MakeExternal(resource); |
| 4450 | if (result && !obj->IsSymbol()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4451 | isolate->heap()->external_string_table()->AddString(*obj); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4452 | } |
| 4453 | return result; |
| 4454 | } |
| 4455 | |
| 4456 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4457 | Local<String> v8::String::NewExternal( |
| 4458 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4459 | i::Isolate* isolate = i::Isolate::Current(); |
| 4460 | EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 4461 | LOG_API(isolate, "String::NewExternal"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4462 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4463 | i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); |
| 4464 | isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4465 | return Utils::ToLocal(result); |
| 4466 | } |
| 4467 | |
| 4468 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4469 | bool v8::String::MakeExternal( |
| 4470 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4471 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 4472 | i::Isolate* isolate = obj->GetIsolate(); |
| 4473 | if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4474 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 4475 | return false; // Already an external string. |
| 4476 | } |
| 4477 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4478 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 4479 | return false; |
| 4480 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4481 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 4482 | return false; |
| 4483 | } |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4484 | bool result = obj->MakeExternal(resource); |
| 4485 | if (result && !obj->IsSymbol()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4486 | isolate->heap()->external_string_table()->AddString(*obj); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4487 | } |
| 4488 | return result; |
| 4489 | } |
| 4490 | |
| 4491 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4492 | bool v8::String::CanMakeExternal() { |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4493 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4494 | i::Isolate* isolate = obj->GetIsolate(); |
| 4495 | if (IsDeadCheck(isolate, "v8::String::CanMakeExternal()")) return false; |
| 4496 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 4497 | return false; |
| 4498 | } |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4499 | int size = obj->Size(); // Byte size of the original string. |
| 4500 | if (size < i::ExternalString::kSize) |
| 4501 | return false; |
| 4502 | i::StringShape shape(*obj); |
| 4503 | return !shape.IsExternal(); |
| 4504 | } |
| 4505 | |
| 4506 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4507 | Local<v8::Object> v8::Object::New() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4508 | i::Isolate* isolate = i::Isolate::Current(); |
| 4509 | EnsureInitializedForIsolate(isolate, "v8::Object::New()"); |
| 4510 | LOG_API(isolate, "Object::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4511 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4512 | i::Handle<i::JSObject> obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4513 | isolate->factory()->NewJSObject(isolate->object_function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4514 | return Utils::ToLocal(obj); |
| 4515 | } |
| 4516 | |
| 4517 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4518 | Local<v8::Value> v8::NumberObject::New(double value) { |
| 4519 | i::Isolate* isolate = i::Isolate::Current(); |
| 4520 | EnsureInitializedForIsolate(isolate, "v8::NumberObject::New()"); |
| 4521 | LOG_API(isolate, "NumberObject::New"); |
| 4522 | ENTER_V8(isolate); |
| 4523 | i::Handle<i::Object> number = isolate->factory()->NewNumber(value); |
| 4524 | i::Handle<i::Object> obj = isolate->factory()->ToObject(number); |
| 4525 | return Utils::ToLocal(obj); |
| 4526 | } |
| 4527 | |
| 4528 | |
| 4529 | double v8::NumberObject::NumberValue() const { |
| 4530 | i::Isolate* isolate = i::Isolate::Current(); |
| 4531 | if (IsDeadCheck(isolate, "v8::NumberObject::NumberValue()")) return 0; |
| 4532 | LOG_API(isolate, "NumberObject::NumberValue"); |
| 4533 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4534 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4535 | return jsvalue->value()->Number(); |
| 4536 | } |
| 4537 | |
| 4538 | |
| 4539 | Local<v8::Value> v8::BooleanObject::New(bool value) { |
| 4540 | i::Isolate* isolate = i::Isolate::Current(); |
| 4541 | EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()"); |
| 4542 | LOG_API(isolate, "BooleanObject::New"); |
| 4543 | ENTER_V8(isolate); |
| 4544 | i::Handle<i::Object> boolean(value ? isolate->heap()->true_value() |
| 4545 | : isolate->heap()->false_value()); |
| 4546 | i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean); |
| 4547 | return Utils::ToLocal(obj); |
| 4548 | } |
| 4549 | |
| 4550 | |
| 4551 | bool v8::BooleanObject::BooleanValue() const { |
| 4552 | i::Isolate* isolate = i::Isolate::Current(); |
| 4553 | if (IsDeadCheck(isolate, "v8::BooleanObject::BooleanValue()")) return 0; |
| 4554 | LOG_API(isolate, "BooleanObject::BooleanValue"); |
| 4555 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4556 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4557 | return jsvalue->value()->IsTrue(); |
| 4558 | } |
| 4559 | |
| 4560 | |
| 4561 | Local<v8::Value> v8::StringObject::New(Handle<String> value) { |
| 4562 | i::Isolate* isolate = i::Isolate::Current(); |
| 4563 | EnsureInitializedForIsolate(isolate, "v8::StringObject::New()"); |
| 4564 | LOG_API(isolate, "StringObject::New"); |
| 4565 | ENTER_V8(isolate); |
| 4566 | i::Handle<i::Object> obj = |
| 4567 | isolate->factory()->ToObject(Utils::OpenHandle(*value)); |
| 4568 | return Utils::ToLocal(obj); |
| 4569 | } |
| 4570 | |
| 4571 | |
| 4572 | Local<v8::String> v8::StringObject::StringValue() const { |
| 4573 | i::Isolate* isolate = i::Isolate::Current(); |
| 4574 | if (IsDeadCheck(isolate, "v8::StringObject::StringValue()")) { |
| 4575 | return Local<v8::String>(); |
| 4576 | } |
| 4577 | LOG_API(isolate, "StringObject::StringValue"); |
| 4578 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4579 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4580 | return Utils::ToLocal( |
| 4581 | i::Handle<i::String>(i::String::cast(jsvalue->value()))); |
| 4582 | } |
| 4583 | |
| 4584 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4585 | Local<v8::Value> v8::Date::New(double time) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4586 | i::Isolate* isolate = i::Isolate::Current(); |
| 4587 | EnsureInitializedForIsolate(isolate, "v8::Date::New()"); |
| 4588 | LOG_API(isolate, "Date::New"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4589 | if (isnan(time)) { |
| 4590 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 4591 | time = i::OS::nan_value(); |
| 4592 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4593 | ENTER_V8(isolate); |
| 4594 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4595 | i::Handle<i::Object> obj = |
| 4596 | i::Execution::NewDate(time, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4597 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4598 | return Utils::ToLocal(obj); |
| 4599 | } |
| 4600 | |
| 4601 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4602 | double v8::Date::NumberValue() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4603 | i::Isolate* isolate = i::Isolate::Current(); |
| 4604 | if (IsDeadCheck(isolate, "v8::Date::NumberValue()")) return 0; |
| 4605 | LOG_API(isolate, "Date::NumberValue"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4606 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4607 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 4608 | return jsvalue->value()->Number(); |
| 4609 | } |
| 4610 | |
| 4611 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4612 | void v8::Date::DateTimeConfigurationChangeNotification() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4613 | i::Isolate* isolate = i::Isolate::Current(); |
| 4614 | ON_BAILOUT(isolate, "v8::Date::DateTimeConfigurationChangeNotification()", |
| 4615 | return); |
| 4616 | LOG_API(isolate, "Date::DateTimeConfigurationChangeNotification"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4617 | ENTER_V8(isolate); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4618 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4619 | i::HandleScope scope(isolate); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4620 | // Get the function ResetDateCache (defined in date-delay.js). |
| 4621 | i::Handle<i::String> func_name_str = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4622 | isolate->factory()->LookupAsciiSymbol("ResetDateCache"); |
| 4623 | i::MaybeObject* result = |
| 4624 | isolate->js_builtins_object()->GetProperty(*func_name_str); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4625 | i::Object* object_func; |
| 4626 | if (!result->ToObject(&object_func)) { |
| 4627 | return; |
| 4628 | } |
| 4629 | |
| 4630 | if (object_func->IsJSFunction()) { |
| 4631 | i::Handle<i::JSFunction> func = |
| 4632 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_func)); |
| 4633 | |
| 4634 | // Call ResetDateCache(0 but expect no exceptions: |
| 4635 | bool caught_exception = false; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4636 | i::Execution::TryCall(func, |
| 4637 | isolate->js_builtins_object(), |
| 4638 | 0, |
| 4639 | NULL, |
| 4640 | &caught_exception); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4641 | } |
| 4642 | } |
| 4643 | |
| 4644 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4645 | static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { |
| 4646 | char flags_buf[3]; |
| 4647 | int num_flags = 0; |
| 4648 | if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; |
| 4649 | if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; |
| 4650 | if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; |
| 4651 | ASSERT(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4652 | return FACTORY->LookupSymbol( |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4653 | i::Vector<const char>(flags_buf, num_flags)); |
| 4654 | } |
| 4655 | |
| 4656 | |
| 4657 | Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, |
| 4658 | Flags flags) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4659 | i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4660 | EnsureInitializedForIsolate(isolate, "v8::RegExp::New()"); |
| 4661 | LOG_API(isolate, "RegExp::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4662 | ENTER_V8(isolate); |
| 4663 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4664 | i::Handle<i::JSRegExp> obj = i::Execution::NewJSRegExp( |
| 4665 | Utils::OpenHandle(*pattern), |
| 4666 | RegExpFlagsToString(flags), |
| 4667 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4668 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::RegExp>()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4669 | return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj)); |
| 4670 | } |
| 4671 | |
| 4672 | |
| 4673 | Local<v8::String> v8::RegExp::GetSource() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4674 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4675 | if (IsDeadCheck(isolate, "v8::RegExp::GetSource()")) { |
| 4676 | return Local<v8::String>(); |
| 4677 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4678 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 4679 | return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); |
| 4680 | } |
| 4681 | |
| 4682 | |
| 4683 | // Assert that the static flags cast in GetFlags is valid. |
| 4684 | #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ |
| 4685 | STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ |
| 4686 | static_cast<int>(i::JSRegExp::internal_flag)) |
| 4687 | REGEXP_FLAG_ASSERT_EQ(kNone, NONE); |
| 4688 | REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL); |
| 4689 | REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE); |
| 4690 | REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE); |
| 4691 | #undef REGEXP_FLAG_ASSERT_EQ |
| 4692 | |
| 4693 | v8::RegExp::Flags v8::RegExp::GetFlags() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4694 | if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::GetFlags()")) { |
| 4695 | return v8::RegExp::kNone; |
| 4696 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4697 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 4698 | return static_cast<RegExp::Flags>(obj->GetFlags().value()); |
| 4699 | } |
| 4700 | |
| 4701 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4702 | Local<v8::Array> v8::Array::New(int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4703 | i::Isolate* isolate = i::Isolate::Current(); |
| 4704 | EnsureInitializedForIsolate(isolate, "v8::Array::New()"); |
| 4705 | LOG_API(isolate, "Array::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4706 | ENTER_V8(isolate); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4707 | int real_length = length > 0 ? length : 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4708 | i::Handle<i::JSArray> obj = isolate->factory()->NewJSArray(real_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4709 | i::Handle<i::Object> length_obj = |
| 4710 | isolate->factory()->NewNumberFromInt(real_length); |
| 4711 | obj->set_length(*length_obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4712 | return Utils::ToLocal(obj); |
| 4713 | } |
| 4714 | |
| 4715 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4716 | uint32_t v8::Array::Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4717 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4718 | if (IsDeadCheck(isolate, "v8::Array::Length()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4719 | i::Handle<i::JSArray> obj = Utils::OpenHandle(this); |
| 4720 | i::Object* length = obj->length(); |
| 4721 | if (length->IsSmi()) { |
| 4722 | return i::Smi::cast(length)->value(); |
| 4723 | } else { |
| 4724 | return static_cast<uint32_t>(length->Number()); |
| 4725 | } |
| 4726 | } |
| 4727 | |
| 4728 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4729 | Local<Object> Array::CloneElementAt(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4730 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4731 | ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4732 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 4733 | if (!self->HasFastElements()) { |
| 4734 | return Local<Object>(); |
| 4735 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4736 | i::FixedArray* elms = i::FixedArray::cast(self->elements()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4737 | i::Object* paragon = elms->get(index); |
| 4738 | if (!paragon->IsJSObject()) { |
| 4739 | return Local<Object>(); |
| 4740 | } |
| 4741 | i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4742 | EXCEPTION_PREAMBLE(isolate); |
| 4743 | ENTER_V8(isolate); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4744 | i::Handle<i::JSObject> result = i::Copy(paragon_handle); |
| 4745 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4746 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 4747 | return Utils::ToLocal(result); |
| 4748 | } |
| 4749 | |
| 4750 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4751 | Local<String> v8::String::NewSymbol(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4752 | i::Isolate* isolate = i::Isolate::Current(); |
| 4753 | EnsureInitializedForIsolate(isolate, "v8::String::NewSymbol()"); |
| 4754 | LOG_API(isolate, "String::NewSymbol(char)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4755 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4756 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4757 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4758 | isolate->factory()->LookupSymbol(i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4759 | return Utils::ToLocal(result); |
| 4760 | } |
| 4761 | |
| 4762 | |
| 4763 | Local<Number> v8::Number::New(double value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4764 | i::Isolate* isolate = i::Isolate::Current(); |
| 4765 | EnsureInitializedForIsolate(isolate, "v8::Number::New()"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4766 | if (isnan(value)) { |
| 4767 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 4768 | value = i::OS::nan_value(); |
| 4769 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4770 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4771 | i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4772 | return Utils::NumberToLocal(result); |
| 4773 | } |
| 4774 | |
| 4775 | |
| 4776 | Local<Integer> v8::Integer::New(int32_t value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4777 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 4778 | EnsureInitializedForIsolate(isolate, "v8::Integer::New()"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4779 | if (i::Smi::IsValid(value)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4780 | return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value), |
| 4781 | isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4782 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4783 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4784 | i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4785 | return Utils::IntegerToLocal(result); |
| 4786 | } |
| 4787 | |
| 4788 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4789 | Local<Integer> Integer::NewFromUnsigned(uint32_t value) { |
| 4790 | bool fits_into_int32_t = (value & (1 << 31)) == 0; |
| 4791 | if (fits_into_int32_t) { |
| 4792 | return Integer::New(static_cast<int32_t>(value)); |
| 4793 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4794 | i::Isolate* isolate = i::Isolate::Current(); |
| 4795 | ENTER_V8(isolate); |
| 4796 | i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4797 | return Utils::IntegerToLocal(result); |
| 4798 | } |
| 4799 | |
| 4800 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4801 | void V8::IgnoreOutOfMemoryException() { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4802 | EnterIsolateIfNeeded()->set_ignore_out_of_memory(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | |
| 4806 | bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4807 | i::Isolate* isolate = i::Isolate::Current(); |
| 4808 | EnsureInitializedForIsolate(isolate, "v8::V8::AddMessageListener()"); |
| 4809 | ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4810 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4811 | i::HandleScope scope(isolate); |
| 4812 | NeanderArray listeners(isolate->factory()->message_listeners()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4813 | NeanderObject obj(2); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4814 | obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4815 | obj.set(1, data.IsEmpty() ? |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4816 | isolate->heap()->undefined_value() : |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4817 | *Utils::OpenHandle(*data)); |
| 4818 | listeners.add(obj.value()); |
| 4819 | return true; |
| 4820 | } |
| 4821 | |
| 4822 | |
| 4823 | void V8::RemoveMessageListeners(MessageCallback that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4824 | i::Isolate* isolate = i::Isolate::Current(); |
| 4825 | EnsureInitializedForIsolate(isolate, "v8::V8::RemoveMessageListener()"); |
| 4826 | ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4827 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4828 | i::HandleScope scope(isolate); |
| 4829 | NeanderArray listeners(isolate->factory()->message_listeners()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4830 | for (int i = 0; i < listeners.length(); i++) { |
| 4831 | if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones |
| 4832 | |
| 4833 | NeanderObject listener(i::JSObject::cast(listeners.get(i))); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4834 | i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0))); |
| 4835 | if (callback_obj->address() == FUNCTION_ADDR(that)) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4836 | listeners.set(i, isolate->heap()->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4837 | } |
| 4838 | } |
| 4839 | } |
| 4840 | |
| 4841 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4842 | void V8::SetCaptureStackTraceForUncaughtExceptions( |
| 4843 | bool capture, |
| 4844 | int frame_limit, |
| 4845 | StackTrace::StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4846 | i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions( |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4847 | capture, |
| 4848 | frame_limit, |
| 4849 | options); |
| 4850 | } |
| 4851 | |
| 4852 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4853 | void V8::SetCounterFunction(CounterLookupCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 4854 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4855 | if (IsDeadCheck(isolate, "v8::V8::SetCounterFunction()")) return; |
| 4856 | isolate->stats_table()->SetCounterFunction(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4857 | } |
| 4858 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4859 | void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 4860 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4861 | if (IsDeadCheck(isolate, "v8::V8::SetCreateHistogramFunction()")) return; |
| 4862 | isolate->stats_table()->SetCreateHistogramFunction(callback); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 4866 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4867 | if (IsDeadCheck(isolate, "v8::V8::SetAddHistogramSampleFunction()")) return; |
| 4868 | isolate->stats_table()-> |
| 4869 | SetAddHistogramSampleFunction(callback); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4870 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4871 | |
| 4872 | void V8::EnableSlidingStateWindow() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4873 | i::Isolate* isolate = i::Isolate::Current(); |
| 4874 | if (IsDeadCheck(isolate, "v8::V8::EnableSlidingStateWindow()")) return; |
| 4875 | isolate->logger()->EnableSlidingStateWindow(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4876 | } |
| 4877 | |
| 4878 | |
| 4879 | void V8::SetFailedAccessCheckCallbackFunction( |
| 4880 | FailedAccessCheckCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4881 | i::Isolate* isolate = i::Isolate::Current(); |
| 4882 | if (IsDeadCheck(isolate, "v8::V8::SetFailedAccessCheckCallbackFunction()")) { |
| 4883 | return; |
| 4884 | } |
| 4885 | isolate->SetFailedAccessCheckCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4886 | } |
| 4887 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4888 | void V8::AddObjectGroup(Persistent<Value>* objects, |
| 4889 | size_t length, |
| 4890 | RetainedObjectInfo* info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4891 | i::Isolate* isolate = i::Isolate::Current(); |
| 4892 | if (IsDeadCheck(isolate, "v8::V8::AddObjectGroup()")) return; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4893 | STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4894 | isolate->global_handles()->AddObjectGroup( |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4895 | reinterpret_cast<i::Object***>(objects), length, info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4896 | } |
| 4897 | |
| 4898 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4899 | void V8::AddImplicitReferences(Persistent<Object> parent, |
| 4900 | Persistent<Value>* children, |
| 4901 | size_t length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4902 | i::Isolate* isolate = i::Isolate::Current(); |
| 4903 | if (IsDeadCheck(isolate, "v8::V8::AddImplicitReferences()")) return; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4904 | STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4905 | isolate->global_handles()->AddImplicitReferences( |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4906 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(*parent)).location(), |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4907 | reinterpret_cast<i::Object***>(children), length); |
| 4908 | } |
| 4909 | |
| 4910 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4911 | int V8::AdjustAmountOfExternalAllocatedMemory(int change_in_bytes) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4912 | i::Isolate* isolate = i::Isolate::Current(); |
| 4913 | if (IsDeadCheck(isolate, "v8::V8::AdjustAmountOfExternalAllocatedMemory()")) { |
| 4914 | return 0; |
| 4915 | } |
| 4916 | return isolate->heap()->AdjustAmountOfExternalAllocatedMemory( |
| 4917 | change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4918 | } |
| 4919 | |
| 4920 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4921 | void V8::SetGlobalGCPrologueCallback(GCCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4922 | i::Isolate* isolate = i::Isolate::Current(); |
| 4923 | if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return; |
| 4924 | isolate->heap()->SetGlobalGCPrologueCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | |
| 4928 | void V8::SetGlobalGCEpilogueCallback(GCCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4929 | i::Isolate* isolate = i::Isolate::Current(); |
| 4930 | if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCEpilogueCallback()")) return; |
| 4931 | isolate->heap()->SetGlobalGCEpilogueCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4935 | void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4936 | i::Isolate* isolate = i::Isolate::Current(); |
| 4937 | if (IsDeadCheck(isolate, "v8::V8::AddGCPrologueCallback()")) return; |
| 4938 | isolate->heap()->AddGCPrologueCallback(callback, gc_type); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4939 | } |
| 4940 | |
| 4941 | |
| 4942 | void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4943 | i::Isolate* isolate = i::Isolate::Current(); |
| 4944 | if (IsDeadCheck(isolate, "v8::V8::RemoveGCPrologueCallback()")) return; |
| 4945 | isolate->heap()->RemoveGCPrologueCallback(callback); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | |
| 4949 | void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4950 | i::Isolate* isolate = i::Isolate::Current(); |
| 4951 | if (IsDeadCheck(isolate, "v8::V8::AddGCEpilogueCallback()")) return; |
| 4952 | isolate->heap()->AddGCEpilogueCallback(callback, gc_type); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | |
| 4956 | void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4957 | i::Isolate* isolate = i::Isolate::Current(); |
| 4958 | if (IsDeadCheck(isolate, "v8::V8::RemoveGCEpilogueCallback()")) return; |
| 4959 | isolate->heap()->RemoveGCEpilogueCallback(callback); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4960 | } |
| 4961 | |
| 4962 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4963 | void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 4964 | ObjectSpace space, |
| 4965 | AllocationAction action) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4966 | i::Isolate* isolate = i::Isolate::Current(); |
| 4967 | if (IsDeadCheck(isolate, "v8::V8::AddMemoryAllocationCallback()")) return; |
| 4968 | isolate->memory_allocator()->AddMemoryAllocationCallback( |
| 4969 | callback, space, action); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4970 | } |
| 4971 | |
| 4972 | |
| 4973 | void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4974 | i::Isolate* isolate = i::Isolate::Current(); |
| 4975 | if (IsDeadCheck(isolate, "v8::V8::RemoveMemoryAllocationCallback()")) return; |
| 4976 | isolate->memory_allocator()->RemoveMemoryAllocationCallback( |
| 4977 | callback); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4981 | void V8::PauseProfiler() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4982 | i::Isolate* isolate = i::Isolate::Current(); |
| 4983 | isolate->logger()->PauseProfiler(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4984 | } |
| 4985 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4986 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4987 | void V8::ResumeProfiler() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4988 | i::Isolate* isolate = i::Isolate::Current(); |
| 4989 | isolate->logger()->ResumeProfiler(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4990 | } |
| 4991 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4992 | |
| 4993 | bool V8::IsProfilerPaused() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4994 | i::Isolate* isolate = i::Isolate::Current(); |
| 4995 | return isolate->logger()->IsProfilerPaused(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4996 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 4997 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4998 | |
| 4999 | int V8::GetCurrentThreadId() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5000 | i::Isolate* isolate = i::Isolate::Current(); |
| 5001 | EnsureInitializedForIsolate(isolate, "V8::GetCurrentThreadId()"); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5002 | return isolate->thread_id().ToInteger(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | |
| 5006 | void V8::TerminateExecution(int thread_id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5007 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5008 | if (!isolate->IsInitialized()) return; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 5009 | API_ENTRY_CHECK(isolate, "V8::TerminateExecution()"); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5010 | // If the thread_id identifies the current thread just terminate |
| 5011 | // execution right away. Otherwise, ask the thread manager to |
| 5012 | // terminate the thread with the given id if any. |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5013 | i::ThreadId internal_tid = i::ThreadId::FromInteger(thread_id); |
| 5014 | if (isolate->thread_id().Equals(internal_tid)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5015 | isolate->stack_guard()->TerminateExecution(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5016 | } else { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5017 | isolate->thread_manager()->TerminateExecution(internal_tid); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5018 | } |
| 5019 | } |
| 5020 | |
| 5021 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5022 | void V8::TerminateExecution(Isolate* isolate) { |
| 5023 | // If no isolate is supplied, use the default isolate. |
| 5024 | if (isolate != NULL) { |
| 5025 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution(); |
| 5026 | } else { |
| 5027 | i::Isolate::GetDefaultIsolateStackGuard()->TerminateExecution(); |
| 5028 | } |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5032 | bool V8::IsExecutionTerminating(Isolate* isolate) { |
| 5033 | i::Isolate* i_isolate = isolate != NULL ? |
| 5034 | reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current(); |
| 5035 | return IsExecutionTerminatingCheck(i_isolate); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5039 | Isolate* Isolate::GetCurrent() { |
| 5040 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 5041 | return reinterpret_cast<Isolate*>(isolate); |
| 5042 | } |
| 5043 | |
| 5044 | |
| 5045 | Isolate* Isolate::New() { |
| 5046 | i::Isolate* isolate = new i::Isolate(); |
| 5047 | return reinterpret_cast<Isolate*>(isolate); |
| 5048 | } |
| 5049 | |
| 5050 | |
| 5051 | void Isolate::Dispose() { |
| 5052 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5053 | if (!ApiCheck(!isolate->IsInUse(), |
| 5054 | "v8::Isolate::Dispose()", |
| 5055 | "Disposing the isolate that is entered by a thread.")) { |
| 5056 | return; |
| 5057 | } |
| 5058 | isolate->TearDown(); |
| 5059 | } |
| 5060 | |
| 5061 | |
| 5062 | void Isolate::Enter() { |
| 5063 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5064 | isolate->Enter(); |
| 5065 | } |
| 5066 | |
| 5067 | |
| 5068 | void Isolate::Exit() { |
| 5069 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5070 | isolate->Exit(); |
| 5071 | } |
| 5072 | |
| 5073 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5074 | void Isolate::SetData(void* data) { |
| 5075 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5076 | isolate->SetData(data); |
| 5077 | } |
| 5078 | |
| 5079 | void* Isolate::GetData() { |
| 5080 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5081 | return isolate->GetData(); |
| 5082 | } |
| 5083 | |
| 5084 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5085 | String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) |
| 5086 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5087 | i::Isolate* isolate = i::Isolate::Current(); |
| 5088 | if (IsDeadCheck(isolate, "v8::String::Utf8Value::Utf8Value()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5089 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5090 | ENTER_V8(isolate); |
| 5091 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5092 | TryCatch try_catch; |
| 5093 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5094 | if (str.IsEmpty()) return; |
| 5095 | length_ = str->Utf8Length(); |
| 5096 | str_ = i::NewArray<char>(length_ + 1); |
| 5097 | str->WriteUtf8(str_); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | |
| 5101 | String::Utf8Value::~Utf8Value() { |
| 5102 | i::DeleteArray(str_); |
| 5103 | } |
| 5104 | |
| 5105 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5106 | String::AsciiValue::AsciiValue(v8::Handle<v8::Value> obj) |
| 5107 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5108 | i::Isolate* isolate = i::Isolate::Current(); |
| 5109 | if (IsDeadCheck(isolate, "v8::String::AsciiValue::AsciiValue()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5110 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5111 | ENTER_V8(isolate); |
| 5112 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5113 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5114 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5115 | if (str.IsEmpty()) return; |
| 5116 | length_ = str->Length(); |
| 5117 | str_ = i::NewArray<char>(length_ + 1); |
| 5118 | str->WriteAscii(str_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | |
| 5122 | String::AsciiValue::~AsciiValue() { |
| 5123 | i::DeleteArray(str_); |
| 5124 | } |
| 5125 | |
| 5126 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5127 | String::Value::Value(v8::Handle<v8::Value> obj) |
| 5128 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5129 | i::Isolate* isolate = i::Isolate::Current(); |
| 5130 | if (IsDeadCheck(isolate, "v8::String::Value::Value()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5131 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5132 | ENTER_V8(isolate); |
| 5133 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5134 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5135 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5136 | if (str.IsEmpty()) return; |
| 5137 | length_ = str->Length(); |
| 5138 | str_ = i::NewArray<uint16_t>(length_ + 1); |
| 5139 | str->Write(str_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | |
| 5143 | String::Value::~Value() { |
| 5144 | i::DeleteArray(str_); |
| 5145 | } |
| 5146 | |
| 5147 | Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5148 | i::Isolate* isolate = i::Isolate::Current(); |
| 5149 | LOG_API(isolate, "RangeError"); |
| 5150 | ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5151 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5152 | i::Object* error; |
| 5153 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5154 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5155 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5156 | i::Handle<i::Object> result = isolate->factory()->NewRangeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5157 | error = *result; |
| 5158 | } |
| 5159 | i::Handle<i::Object> result(error); |
| 5160 | return Utils::ToLocal(result); |
| 5161 | } |
| 5162 | |
| 5163 | Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5164 | i::Isolate* isolate = i::Isolate::Current(); |
| 5165 | LOG_API(isolate, "ReferenceError"); |
| 5166 | ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5167 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5168 | i::Object* error; |
| 5169 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5170 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5171 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5172 | i::Handle<i::Object> result = |
| 5173 | isolate->factory()->NewReferenceError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5174 | error = *result; |
| 5175 | } |
| 5176 | i::Handle<i::Object> result(error); |
| 5177 | return Utils::ToLocal(result); |
| 5178 | } |
| 5179 | |
| 5180 | Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5181 | i::Isolate* isolate = i::Isolate::Current(); |
| 5182 | LOG_API(isolate, "SyntaxError"); |
| 5183 | ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5184 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5185 | i::Object* error; |
| 5186 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5187 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5188 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5189 | i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5190 | error = *result; |
| 5191 | } |
| 5192 | i::Handle<i::Object> result(error); |
| 5193 | return Utils::ToLocal(result); |
| 5194 | } |
| 5195 | |
| 5196 | Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5197 | i::Isolate* isolate = i::Isolate::Current(); |
| 5198 | LOG_API(isolate, "TypeError"); |
| 5199 | ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5200 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5201 | i::Object* error; |
| 5202 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5203 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5204 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5205 | i::Handle<i::Object> result = isolate->factory()->NewTypeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5206 | error = *result; |
| 5207 | } |
| 5208 | i::Handle<i::Object> result(error); |
| 5209 | return Utils::ToLocal(result); |
| 5210 | } |
| 5211 | |
| 5212 | Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5213 | i::Isolate* isolate = i::Isolate::Current(); |
| 5214 | LOG_API(isolate, "Error"); |
| 5215 | ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5216 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5217 | i::Object* error; |
| 5218 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5219 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5220 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5221 | i::Handle<i::Object> result = isolate->factory()->NewError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5222 | error = *result; |
| 5223 | } |
| 5224 | i::Handle<i::Object> result(error); |
| 5225 | return Utils::ToLocal(result); |
| 5226 | } |
| 5227 | |
| 5228 | |
| 5229 | // --- D e b u g S u p p o r t --- |
| 5230 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5231 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5232 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5233 | static void EventCallbackWrapper(const v8::Debug::EventDetails& event_details) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5234 | i::Isolate* isolate = i::Isolate::Current(); |
| 5235 | if (isolate->debug_event_callback() != NULL) { |
| 5236 | isolate->debug_event_callback()(event_details.GetEvent(), |
| 5237 | event_details.GetExecutionState(), |
| 5238 | event_details.GetEventData(), |
| 5239 | event_details.GetCallbackData()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5240 | } |
| 5241 | } |
| 5242 | |
| 5243 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5244 | bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5245 | i::Isolate* isolate = i::Isolate::Current(); |
| 5246 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener()"); |
| 5247 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5248 | ENTER_V8(isolate); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5249 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5250 | isolate->set_debug_event_callback(that); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5251 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5252 | i::HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5253 | i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5254 | if (that != NULL) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5255 | foreign = |
| 5256 | isolate->factory()->NewForeign(FUNCTION_ADDR(EventCallbackWrapper)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5257 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5258 | isolate->debugger()->SetEventListener(foreign, Utils::OpenHandle(*data)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5259 | return true; |
| 5260 | } |
| 5261 | |
| 5262 | |
| 5263 | bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5264 | i::Isolate* isolate = i::Isolate::Current(); |
| 5265 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()"); |
| 5266 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5267 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5268 | i::HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5269 | i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5270 | if (that != NULL) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5271 | foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5272 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5273 | isolate->debugger()->SetEventListener(foreign, Utils::OpenHandle(*data)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5274 | return true; |
| 5275 | } |
| 5276 | |
| 5277 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5278 | bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5279 | Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5280 | i::Isolate* isolate = i::Isolate::Current(); |
| 5281 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5282 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5283 | isolate->debugger()->SetEventListener(Utils::OpenHandle(*that), |
| 5284 | Utils::OpenHandle(*data)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5285 | return true; |
| 5286 | } |
| 5287 | |
| 5288 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5289 | void Debug::DebugBreak(Isolate* isolate) { |
| 5290 | // If no isolate is supplied, use the default isolate. |
| 5291 | if (isolate != NULL) { |
| 5292 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->DebugBreak(); |
| 5293 | } else { |
| 5294 | i::Isolate::GetDefaultIsolateStackGuard()->DebugBreak(); |
| 5295 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5299 | void Debug::CancelDebugBreak(Isolate* isolate) { |
| 5300 | // If no isolate is supplied, use the default isolate. |
| 5301 | if (isolate != NULL) { |
| 5302 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5303 | internal_isolate->stack_guard()->Continue(i::DEBUGBREAK); |
| 5304 | } else { |
| 5305 | i::Isolate::GetDefaultIsolateStackGuard()->Continue(i::DEBUGBREAK); |
| 5306 | } |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 5307 | } |
| 5308 | |
| 5309 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5310 | void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) { |
| 5311 | // If no isolate is supplied, use the default isolate. |
| 5312 | if (isolate != NULL) { |
| 5313 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5314 | internal_isolate->debugger()->EnqueueDebugCommand(data); |
| 5315 | } else { |
| 5316 | i::Isolate::GetDefaultIsolateDebugger()->EnqueueDebugCommand(data); |
| 5317 | } |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5321 | static void MessageHandlerWrapper(const v8::Debug::Message& message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5322 | i::Isolate* isolate = i::Isolate::Current(); |
| 5323 | if (isolate->message_handler()) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5324 | v8::String::Value json(message.GetJSON()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5325 | (isolate->message_handler())(*json, json.length(), message.GetClientData()); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5326 | } |
| 5327 | } |
| 5328 | |
| 5329 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5330 | void Debug::SetMessageHandler(v8::Debug::MessageHandler handler, |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5331 | bool message_handler_thread) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5332 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5333 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); |
| 5334 | ENTER_V8(isolate); |
| 5335 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5336 | // Message handler thread not supported any more. Parameter temporally left in |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5337 | // the API for client compatibility reasons. |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5338 | CHECK(!message_handler_thread); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5339 | |
| 5340 | // 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] | 5341 | isolate->set_message_handler(handler); |
| 5342 | if (handler != NULL) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5343 | isolate->debugger()->SetMessageHandler(MessageHandlerWrapper); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5344 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5345 | isolate->debugger()->SetMessageHandler(NULL); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5346 | } |
| 5347 | } |
| 5348 | |
| 5349 | |
| 5350 | void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5351 | i::Isolate* isolate = i::Isolate::Current(); |
| 5352 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); |
| 5353 | ENTER_V8(isolate); |
| 5354 | isolate->debugger()->SetMessageHandler(handler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5358 | void Debug::SendCommand(const uint16_t* command, int length, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5359 | ClientData* client_data, |
| 5360 | Isolate* isolate) { |
| 5361 | // If no isolate is supplied, use the default isolate. |
| 5362 | if (isolate != NULL) { |
| 5363 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5364 | internal_isolate->debugger()->ProcessCommand( |
| 5365 | i::Vector<const uint16_t>(command, length), client_data); |
| 5366 | } else { |
| 5367 | i::Isolate::GetDefaultIsolateDebugger()->ProcessCommand( |
| 5368 | i::Vector<const uint16_t>(command, length), client_data); |
| 5369 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5373 | void Debug::SetHostDispatchHandler(HostDispatchHandler handler, |
| 5374 | int period) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5375 | i::Isolate* isolate = i::Isolate::Current(); |
| 5376 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetHostDispatchHandler"); |
| 5377 | ENTER_V8(isolate); |
| 5378 | isolate->debugger()->SetHostDispatchHandler(handler, period); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5379 | } |
| 5380 | |
| 5381 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5382 | void Debug::SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5383 | DebugMessageDispatchHandler handler, bool provide_locker) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5384 | i::Isolate* isolate = i::Isolate::Current(); |
| 5385 | EnsureInitializedForIsolate(isolate, |
| 5386 | "v8::Debug::SetDebugMessageDispatchHandler"); |
| 5387 | ENTER_V8(isolate); |
| 5388 | isolate->debugger()->SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5389 | handler, provide_locker); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5393 | Local<Value> Debug::Call(v8::Handle<v8::Function> fun, |
| 5394 | v8::Handle<v8::Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5395 | i::Isolate* isolate = i::Isolate::Current(); |
| 5396 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 5397 | ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5398 | ENTER_V8(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5399 | i::Handle<i::Object> result; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5400 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5401 | if (data.IsEmpty()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5402 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 5403 | isolate->factory()->undefined_value(), |
| 5404 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5405 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5406 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 5407 | Utils::OpenHandle(*data), |
| 5408 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5409 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5410 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5411 | return Utils::ToLocal(result); |
| 5412 | } |
| 5413 | |
| 5414 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5415 | Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5416 | i::Isolate* isolate = i::Isolate::Current(); |
| 5417 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 5418 | ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5419 | ENTER_V8(isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5420 | v8::HandleScope scope; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5421 | i::Debug* isolate_debug = isolate->debug(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5422 | isolate_debug->Load(); |
| 5423 | i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global()); |
| 5424 | i::Handle<i::String> name = |
| 5425 | isolate->factory()->LookupAsciiSymbol("MakeMirror"); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5426 | i::Handle<i::Object> fun_obj = i::GetProperty(debug, name); |
| 5427 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj); |
| 5428 | v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun); |
| 5429 | const int kArgc = 1; |
| 5430 | v8::Handle<v8::Value> argv[kArgc] = { obj }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5431 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5432 | v8::Handle<v8::Value> result = v8_fun->Call(Utils::ToLocal(debug), |
| 5433 | kArgc, |
| 5434 | argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5435 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5436 | return scope.Close(result); |
| 5437 | } |
| 5438 | |
| 5439 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5440 | 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] | 5441 | return i::Isolate::Current()->debugger()->StartAgent(name, port, |
| 5442 | wait_for_connection); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5443 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5444 | |
| 5445 | void Debug::ProcessDebugMessages() { |
| 5446 | i::Execution::ProcessDebugMesssages(true); |
| 5447 | } |
| 5448 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 5449 | Local<Context> Debug::GetDebugContext() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5450 | i::Isolate* isolate = i::Isolate::Current(); |
| 5451 | EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()"); |
| 5452 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5453 | return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext()); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 5454 | } |
| 5455 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5456 | #endif // ENABLE_DEBUGGER_SUPPORT |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5457 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5458 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5459 | Handle<String> CpuProfileNode::GetFunctionName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5460 | i::Isolate* isolate = i::Isolate::Current(); |
| 5461 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetFunctionName"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5462 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
| 5463 | const i::CodeEntry* entry = node->entry(); |
| 5464 | if (!entry->has_name_prefix()) { |
| 5465 | return Handle<String>(ToApi<String>( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5466 | isolate->factory()->LookupAsciiSymbol(entry->name()))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5467 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5468 | return Handle<String>(ToApi<String>(isolate->factory()->NewConsString( |
| 5469 | isolate->factory()->LookupAsciiSymbol(entry->name_prefix()), |
| 5470 | isolate->factory()->LookupAsciiSymbol(entry->name())))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5471 | } |
| 5472 | } |
| 5473 | |
| 5474 | |
| 5475 | Handle<String> CpuProfileNode::GetScriptResourceName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5476 | i::Isolate* isolate = i::Isolate::Current(); |
| 5477 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetScriptResourceName"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5478 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5479 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5480 | node->entry()->resource_name()))); |
| 5481 | } |
| 5482 | |
| 5483 | |
| 5484 | int CpuProfileNode::GetLineNumber() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5485 | i::Isolate* isolate = i::Isolate::Current(); |
| 5486 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetLineNumber"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5487 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number(); |
| 5488 | } |
| 5489 | |
| 5490 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5491 | double CpuProfileNode::GetTotalTime() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5492 | i::Isolate* isolate = i::Isolate::Current(); |
| 5493 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalTime"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5494 | return reinterpret_cast<const i::ProfileNode*>(this)->GetTotalMillis(); |
| 5495 | } |
| 5496 | |
| 5497 | |
| 5498 | double CpuProfileNode::GetSelfTime() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5499 | i::Isolate* isolate = i::Isolate::Current(); |
| 5500 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfTime"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5501 | return reinterpret_cast<const i::ProfileNode*>(this)->GetSelfMillis(); |
| 5502 | } |
| 5503 | |
| 5504 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5505 | double CpuProfileNode::GetTotalSamplesCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5506 | i::Isolate* isolate = i::Isolate::Current(); |
| 5507 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalSamplesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5508 | return reinterpret_cast<const i::ProfileNode*>(this)->total_ticks(); |
| 5509 | } |
| 5510 | |
| 5511 | |
| 5512 | double CpuProfileNode::GetSelfSamplesCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5513 | i::Isolate* isolate = i::Isolate::Current(); |
| 5514 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfSamplesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5515 | return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks(); |
| 5516 | } |
| 5517 | |
| 5518 | |
| 5519 | unsigned CpuProfileNode::GetCallUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5520 | i::Isolate* isolate = i::Isolate::Current(); |
| 5521 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetCallUid"); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 5522 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
| 5525 | |
| 5526 | int CpuProfileNode::GetChildrenCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5527 | i::Isolate* isolate = i::Isolate::Current(); |
| 5528 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetChildrenCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5529 | return reinterpret_cast<const i::ProfileNode*>(this)->children()->length(); |
| 5530 | } |
| 5531 | |
| 5532 | |
| 5533 | const CpuProfileNode* CpuProfileNode::GetChild(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5534 | i::Isolate* isolate = i::Isolate::Current(); |
| 5535 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetChild"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5536 | const i::ProfileNode* child = |
| 5537 | reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index); |
| 5538 | return reinterpret_cast<const CpuProfileNode*>(child); |
| 5539 | } |
| 5540 | |
| 5541 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5542 | void CpuProfile::Delete() { |
| 5543 | i::Isolate* isolate = i::Isolate::Current(); |
| 5544 | IsDeadCheck(isolate, "v8::CpuProfile::Delete"); |
| 5545 | i::CpuProfiler::DeleteProfile(reinterpret_cast<i::CpuProfile*>(this)); |
| 5546 | if (i::CpuProfiler::GetProfilesCount() == 0 && |
| 5547 | !i::CpuProfiler::HasDetachedProfiles()) { |
| 5548 | // If this was the last profile, clean up all accessory data as well. |
| 5549 | i::CpuProfiler::DeleteAllProfiles(); |
| 5550 | } |
| 5551 | } |
| 5552 | |
| 5553 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5554 | unsigned CpuProfile::GetUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5555 | i::Isolate* isolate = i::Isolate::Current(); |
| 5556 | IsDeadCheck(isolate, "v8::CpuProfile::GetUid"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5557 | return reinterpret_cast<const i::CpuProfile*>(this)->uid(); |
| 5558 | } |
| 5559 | |
| 5560 | |
| 5561 | Handle<String> CpuProfile::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5562 | i::Isolate* isolate = i::Isolate::Current(); |
| 5563 | IsDeadCheck(isolate, "v8::CpuProfile::GetTitle"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5564 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5565 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5566 | profile->title()))); |
| 5567 | } |
| 5568 | |
| 5569 | |
| 5570 | const CpuProfileNode* CpuProfile::GetBottomUpRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5571 | i::Isolate* isolate = i::Isolate::Current(); |
| 5572 | IsDeadCheck(isolate, "v8::CpuProfile::GetBottomUpRoot"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5573 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 5574 | return reinterpret_cast<const CpuProfileNode*>(profile->bottom_up()->root()); |
| 5575 | } |
| 5576 | |
| 5577 | |
| 5578 | const CpuProfileNode* CpuProfile::GetTopDownRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5579 | i::Isolate* isolate = i::Isolate::Current(); |
| 5580 | IsDeadCheck(isolate, "v8::CpuProfile::GetTopDownRoot"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5581 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 5582 | return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root()); |
| 5583 | } |
| 5584 | |
| 5585 | |
| 5586 | int CpuProfiler::GetProfilesCount() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5587 | i::Isolate* isolate = i::Isolate::Current(); |
| 5588 | IsDeadCheck(isolate, "v8::CpuProfiler::GetProfilesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5589 | return i::CpuProfiler::GetProfilesCount(); |
| 5590 | } |
| 5591 | |
| 5592 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5593 | const CpuProfile* CpuProfiler::GetProfile(int index, |
| 5594 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5595 | i::Isolate* isolate = i::Isolate::Current(); |
| 5596 | IsDeadCheck(isolate, "v8::CpuProfiler::GetProfile"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5597 | return reinterpret_cast<const CpuProfile*>( |
| 5598 | i::CpuProfiler::GetProfile( |
| 5599 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 5600 | index)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5604 | const CpuProfile* CpuProfiler::FindProfile(unsigned uid, |
| 5605 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5606 | i::Isolate* isolate = i::Isolate::Current(); |
| 5607 | IsDeadCheck(isolate, "v8::CpuProfiler::FindProfile"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5608 | return reinterpret_cast<const CpuProfile*>( |
| 5609 | i::CpuProfiler::FindProfile( |
| 5610 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 5611 | uid)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | |
| 5615 | void CpuProfiler::StartProfiling(Handle<String> title) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5616 | i::Isolate* isolate = i::Isolate::Current(); |
| 5617 | IsDeadCheck(isolate, "v8::CpuProfiler::StartProfiling"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5618 | i::CpuProfiler::StartProfiling(*Utils::OpenHandle(*title)); |
| 5619 | } |
| 5620 | |
| 5621 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5622 | const CpuProfile* CpuProfiler::StopProfiling(Handle<String> title, |
| 5623 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5624 | i::Isolate* isolate = i::Isolate::Current(); |
| 5625 | IsDeadCheck(isolate, "v8::CpuProfiler::StopProfiling"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5626 | return reinterpret_cast<const CpuProfile*>( |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5627 | i::CpuProfiler::StopProfiling( |
| 5628 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 5629 | *Utils::OpenHandle(*title))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5630 | } |
| 5631 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5632 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5633 | void CpuProfiler::DeleteAllProfiles() { |
| 5634 | i::Isolate* isolate = i::Isolate::Current(); |
| 5635 | IsDeadCheck(isolate, "v8::CpuProfiler::DeleteAllProfiles"); |
| 5636 | i::CpuProfiler::DeleteAllProfiles(); |
| 5637 | } |
| 5638 | |
| 5639 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5640 | static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) { |
| 5641 | return const_cast<i::HeapGraphEdge*>( |
| 5642 | reinterpret_cast<const i::HeapGraphEdge*>(edge)); |
| 5643 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5644 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5645 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5646 | HeapGraphEdge::Type HeapGraphEdge::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5647 | i::Isolate* isolate = i::Isolate::Current(); |
| 5648 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetType"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5649 | return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5650 | } |
| 5651 | |
| 5652 | |
| 5653 | Handle<Value> HeapGraphEdge::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5654 | i::Isolate* isolate = i::Isolate::Current(); |
| 5655 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetName"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5656 | i::HeapGraphEdge* edge = ToInternal(this); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5657 | switch (edge->type()) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5658 | case i::HeapGraphEdge::kContextVariable: |
| 5659 | case i::HeapGraphEdge::kInternal: |
| 5660 | case i::HeapGraphEdge::kProperty: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5661 | case i::HeapGraphEdge::kShortcut: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5662 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5663 | edge->name()))); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5664 | case i::HeapGraphEdge::kElement: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5665 | case i::HeapGraphEdge::kHidden: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5666 | return Handle<Number>(ToApi<Number>(isolate->factory()->NewNumberFromInt( |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5667 | edge->index()))); |
| 5668 | default: UNREACHABLE(); |
| 5669 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5670 | return v8::Undefined(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5671 | } |
| 5672 | |
| 5673 | |
| 5674 | const HeapGraphNode* HeapGraphEdge::GetFromNode() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5675 | i::Isolate* isolate = i::Isolate::Current(); |
| 5676 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetFromNode"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5677 | const i::HeapEntry* from = ToInternal(this)->From(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5678 | return reinterpret_cast<const HeapGraphNode*>(from); |
| 5679 | } |
| 5680 | |
| 5681 | |
| 5682 | const HeapGraphNode* HeapGraphEdge::GetToNode() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5683 | i::Isolate* isolate = i::Isolate::Current(); |
| 5684 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetToNode"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5685 | const i::HeapEntry* to = ToInternal(this)->to(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5686 | return reinterpret_cast<const HeapGraphNode*>(to); |
| 5687 | } |
| 5688 | |
| 5689 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5690 | static i::HeapEntry* ToInternal(const HeapGraphNode* entry) { |
| 5691 | return const_cast<i::HeapEntry*>( |
| 5692 | reinterpret_cast<const i::HeapEntry*>(entry)); |
| 5693 | } |
| 5694 | |
| 5695 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5696 | HeapGraphNode::Type HeapGraphNode::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5697 | i::Isolate* isolate = i::Isolate::Current(); |
| 5698 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetType"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5699 | return static_cast<HeapGraphNode::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5700 | } |
| 5701 | |
| 5702 | |
| 5703 | Handle<String> HeapGraphNode::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5704 | i::Isolate* isolate = i::Isolate::Current(); |
| 5705 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetName"); |
| 5706 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5707 | ToInternal(this)->name()))); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5708 | } |
| 5709 | |
| 5710 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 5711 | uint64_t HeapGraphNode::GetId() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5712 | i::Isolate* isolate = i::Isolate::Current(); |
| 5713 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetId"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5714 | return ToInternal(this)->id(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5718 | int HeapGraphNode::GetSelfSize() 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::HeapGraphNode::GetSelfSize"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5721 | return ToInternal(this)->self_size(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5725 | int HeapGraphNode::GetRetainedSize(bool exact) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5726 | i::Isolate* isolate = i::Isolate::Current(); |
| 5727 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainedSize"); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5728 | return ToInternal(this)->RetainedSize(exact); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5729 | } |
| 5730 | |
| 5731 | |
| 5732 | int HeapGraphNode::GetChildrenCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5733 | i::Isolate* isolate = i::Isolate::Current(); |
| 5734 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetChildrenCount"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5735 | return ToInternal(this)->children().length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5736 | } |
| 5737 | |
| 5738 | |
| 5739 | const HeapGraphEdge* HeapGraphNode::GetChild(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5740 | i::Isolate* isolate = i::Isolate::Current(); |
| 5741 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetChild"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5742 | return reinterpret_cast<const HeapGraphEdge*>( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5743 | &ToInternal(this)->children()[index]); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | |
| 5747 | int HeapGraphNode::GetRetainersCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5748 | i::Isolate* isolate = i::Isolate::Current(); |
| 5749 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainersCount"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5750 | return ToInternal(this)->retainers().length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5751 | } |
| 5752 | |
| 5753 | |
| 5754 | const HeapGraphEdge* HeapGraphNode::GetRetainer(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5755 | i::Isolate* isolate = i::Isolate::Current(); |
| 5756 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainer"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5757 | return reinterpret_cast<const HeapGraphEdge*>( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5758 | ToInternal(this)->retainers()[index]); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
| 5761 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5762 | const HeapGraphNode* HeapGraphNode::GetDominatorNode() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5763 | i::Isolate* isolate = i::Isolate::Current(); |
| 5764 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetDominatorNode"); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 5765 | return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->dominator()); |
| 5766 | } |
| 5767 | |
| 5768 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5769 | static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) { |
| 5770 | return const_cast<i::HeapSnapshot*>( |
| 5771 | reinterpret_cast<const i::HeapSnapshot*>(snapshot)); |
| 5772 | } |
| 5773 | |
| 5774 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5775 | void HeapSnapshot::Delete() { |
| 5776 | i::Isolate* isolate = i::Isolate::Current(); |
| 5777 | IsDeadCheck(isolate, "v8::HeapSnapshot::Delete"); |
| 5778 | if (i::HeapProfiler::GetSnapshotsCount() > 1) { |
| 5779 | ToInternal(this)->Delete(); |
| 5780 | } else { |
| 5781 | // If this is the last snapshot, clean up all accessory data as well. |
| 5782 | i::HeapProfiler::DeleteAllSnapshots(); |
| 5783 | } |
| 5784 | } |
| 5785 | |
| 5786 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5787 | HeapSnapshot::Type HeapSnapshot::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5788 | i::Isolate* isolate = i::Isolate::Current(); |
| 5789 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetType"); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5790 | return static_cast<HeapSnapshot::Type>(ToInternal(this)->type()); |
| 5791 | } |
| 5792 | |
| 5793 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5794 | unsigned HeapSnapshot::GetUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5795 | i::Isolate* isolate = i::Isolate::Current(); |
| 5796 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetUid"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5797 | return ToInternal(this)->uid(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | |
| 5801 | Handle<String> HeapSnapshot::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5802 | i::Isolate* isolate = i::Isolate::Current(); |
| 5803 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetTitle"); |
| 5804 | return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5805 | ToInternal(this)->title()))); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 5809 | const HeapGraphNode* HeapSnapshot::GetRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5810 | i::Isolate* isolate = i::Isolate::Current(); |
| 5811 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetHead"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5812 | return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5813 | } |
| 5814 | |
| 5815 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5816 | const HeapGraphNode* HeapSnapshot::GetNodeById(uint64_t id) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5817 | i::Isolate* isolate = i::Isolate::Current(); |
| 5818 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodeById"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5819 | return reinterpret_cast<const HeapGraphNode*>( |
| 5820 | ToInternal(this)->GetEntryById(id)); |
| 5821 | } |
| 5822 | |
| 5823 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5824 | int HeapSnapshot::GetNodesCount() const { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5825 | i::Isolate* isolate = i::Isolate::Current(); |
| 5826 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodesCount"); |
| 5827 | return ToInternal(this)->entries()->length(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5828 | } |
| 5829 | |
| 5830 | |
| 5831 | const HeapGraphNode* HeapSnapshot::GetNode(int index) const { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5832 | i::Isolate* isolate = i::Isolate::Current(); |
| 5833 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNode"); |
| 5834 | return reinterpret_cast<const HeapGraphNode*>( |
| 5835 | ToInternal(this)->entries()->at(index)); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5839 | void HeapSnapshot::Serialize(OutputStream* stream, |
| 5840 | HeapSnapshot::SerializationFormat format) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5841 | i::Isolate* isolate = i::Isolate::Current(); |
| 5842 | IsDeadCheck(isolate, "v8::HeapSnapshot::Serialize"); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 5843 | ApiCheck(format == kJSON, |
| 5844 | "v8::HeapSnapshot::Serialize", |
| 5845 | "Unknown serialization format"); |
| 5846 | ApiCheck(stream->GetOutputEncoding() == OutputStream::kAscii, |
| 5847 | "v8::HeapSnapshot::Serialize", |
| 5848 | "Unsupported output encoding"); |
| 5849 | ApiCheck(stream->GetChunkSize() > 0, |
| 5850 | "v8::HeapSnapshot::Serialize", |
| 5851 | "Invalid stream chunk size"); |
| 5852 | i::HeapSnapshotJSONSerializer serializer(ToInternal(this)); |
| 5853 | serializer.Serialize(stream); |
| 5854 | } |
| 5855 | |
| 5856 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5857 | int HeapProfiler::GetSnapshotsCount() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5858 | i::Isolate* isolate = i::Isolate::Current(); |
| 5859 | IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotsCount"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5860 | return i::HeapProfiler::GetSnapshotsCount(); |
| 5861 | } |
| 5862 | |
| 5863 | |
| 5864 | const HeapSnapshot* HeapProfiler::GetSnapshot(int index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5865 | i::Isolate* isolate = i::Isolate::Current(); |
| 5866 | IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshot"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5867 | return reinterpret_cast<const HeapSnapshot*>( |
| 5868 | i::HeapProfiler::GetSnapshot(index)); |
| 5869 | } |
| 5870 | |
| 5871 | |
| 5872 | const HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5873 | i::Isolate* isolate = i::Isolate::Current(); |
| 5874 | IsDeadCheck(isolate, "v8::HeapProfiler::FindSnapshot"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5875 | return reinterpret_cast<const HeapSnapshot*>( |
| 5876 | i::HeapProfiler::FindSnapshot(uid)); |
| 5877 | } |
| 5878 | |
| 5879 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5880 | const HeapSnapshot* HeapProfiler::TakeSnapshot(Handle<String> title, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5881 | HeapSnapshot::Type type, |
| 5882 | ActivityControl* control) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5883 | i::Isolate* isolate = i::Isolate::Current(); |
| 5884 | IsDeadCheck(isolate, "v8::HeapProfiler::TakeSnapshot"); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5885 | i::HeapSnapshot::Type internal_type = i::HeapSnapshot::kFull; |
| 5886 | switch (type) { |
| 5887 | case HeapSnapshot::kFull: |
| 5888 | internal_type = i::HeapSnapshot::kFull; |
| 5889 | break; |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5890 | default: |
| 5891 | UNREACHABLE(); |
| 5892 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5893 | return reinterpret_cast<const HeapSnapshot*>( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5894 | i::HeapProfiler::TakeSnapshot( |
| 5895 | *Utils::OpenHandle(*title), internal_type, control)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 5896 | } |
| 5897 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5898 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5899 | void HeapProfiler::DeleteAllSnapshots() { |
| 5900 | i::Isolate* isolate = i::Isolate::Current(); |
| 5901 | IsDeadCheck(isolate, "v8::HeapProfiler::DeleteAllSnapshots"); |
| 5902 | i::HeapProfiler::DeleteAllSnapshots(); |
| 5903 | } |
| 5904 | |
| 5905 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5906 | void HeapProfiler::DefineWrapperClass(uint16_t class_id, |
| 5907 | WrapperInfoCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5908 | i::Isolate::Current()->heap_profiler()->DefineWrapperClass(class_id, |
| 5909 | callback); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5910 | } |
| 5911 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5912 | |
| 5913 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5914 | v8::Testing::StressType internal::Testing::stress_type_ = |
| 5915 | v8::Testing::kStressTypeOpt; |
| 5916 | |
| 5917 | |
| 5918 | void Testing::SetStressRunType(Testing::StressType type) { |
| 5919 | internal::Testing::set_stress_type(type); |
| 5920 | } |
| 5921 | |
| 5922 | int Testing::GetStressRuns() { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5923 | if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5924 | #ifdef DEBUG |
| 5925 | // In debug mode the code runs much slower so stressing will only make two |
| 5926 | // runs. |
| 5927 | return 2; |
| 5928 | #else |
| 5929 | return 5; |
| 5930 | #endif |
| 5931 | } |
| 5932 | |
| 5933 | |
| 5934 | static void SetFlagsFromString(const char* flags) { |
| 5935 | V8::SetFlagsFromString(flags, i::StrLength(flags)); |
| 5936 | } |
| 5937 | |
| 5938 | |
| 5939 | void Testing::PrepareStressRun(int run) { |
| 5940 | static const char* kLazyOptimizations = |
| 5941 | "--prepare-always-opt --nolimit-inlining " |
| 5942 | "--noalways-opt --noopt-eagerly"; |
| 5943 | static const char* kEagerOptimizations = "--opt-eagerly"; |
| 5944 | static const char* kForcedOptimizations = "--always-opt"; |
| 5945 | |
| 5946 | // If deoptimization stressed turn on frequent deoptimization. If no value |
| 5947 | // is spefified through --deopt-every-n-times use a default default value. |
| 5948 | static const char* kDeoptEvery13Times = "--deopt-every-n-times=13"; |
| 5949 | if (internal::Testing::stress_type() == Testing::kStressTypeDeopt && |
| 5950 | internal::FLAG_deopt_every_n_times == 0) { |
| 5951 | SetFlagsFromString(kDeoptEvery13Times); |
| 5952 | } |
| 5953 | |
| 5954 | #ifdef DEBUG |
| 5955 | // As stressing in debug mode only make two runs skip the deopt stressing |
| 5956 | // here. |
| 5957 | if (run == GetStressRuns() - 1) { |
| 5958 | SetFlagsFromString(kForcedOptimizations); |
| 5959 | } else { |
| 5960 | SetFlagsFromString(kEagerOptimizations); |
| 5961 | SetFlagsFromString(kLazyOptimizations); |
| 5962 | } |
| 5963 | #else |
| 5964 | if (run == GetStressRuns() - 1) { |
| 5965 | SetFlagsFromString(kForcedOptimizations); |
| 5966 | } else if (run == GetStressRuns() - 2) { |
| 5967 | SetFlagsFromString(kEagerOptimizations); |
| 5968 | } else { |
| 5969 | SetFlagsFromString(kLazyOptimizations); |
| 5970 | } |
| 5971 | #endif |
| 5972 | } |
| 5973 | |
| 5974 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5975 | void Testing::DeoptimizeAll() { |
| 5976 | internal::Deoptimizer::DeoptimizeAll(); |
| 5977 | } |
| 5978 | |
| 5979 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5980 | namespace internal { |
| 5981 | |
| 5982 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5983 | void HandleScopeImplementer::FreeThreadResources() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5984 | Free(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5985 | } |
| 5986 | |
| 5987 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5988 | char* HandleScopeImplementer::ArchiveThread(char* storage) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 5989 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5990 | isolate_->handle_scope_data(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5991 | handle_scope_data_ = *current; |
| 5992 | memcpy(storage, this, sizeof(*this)); |
| 5993 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5994 | ResetAfterArchive(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5995 | current->Initialize(); |
| 5996 | |
| 5997 | return storage + ArchiveSpacePerThread(); |
| 5998 | } |
| 5999 | |
| 6000 | |
| 6001 | int HandleScopeImplementer::ArchiveSpacePerThread() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6002 | return sizeof(HandleScopeImplementer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | |
| 6006 | char* HandleScopeImplementer::RestoreThread(char* storage) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6007 | memcpy(this, storage, sizeof(*this)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6008 | *isolate_->handle_scope_data() = handle_scope_data_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6009 | return storage + ArchiveSpacePerThread(); |
| 6010 | } |
| 6011 | |
| 6012 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6013 | void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6014 | // Iterate over all handles in the blocks except for the last. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6015 | for (int i = blocks()->length() - 2; i >= 0; --i) { |
| 6016 | Object** block = blocks()->at(i); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6017 | v->VisitPointers(block, &block[kHandleBlockSize]); |
| 6018 | } |
| 6019 | |
| 6020 | // Iterate over live handles in the last block (if any). |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6021 | if (!blocks()->is_empty()) { |
| 6022 | v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6023 | } |
| 6024 | |
| 6025 | if (!saved_contexts_.is_empty()) { |
| 6026 | Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
| 6027 | v->VisitPointers(start, start + saved_contexts_.length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6028 | } |
| 6029 | } |
| 6030 | |
| 6031 | |
| 6032 | void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 6033 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6034 | isolate_->handle_scope_data(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6035 | handle_scope_data_ = *current; |
| 6036 | IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6037 | } |
| 6038 | |
| 6039 | |
| 6040 | char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6041 | HandleScopeImplementer* scope_implementer = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6042 | reinterpret_cast<HandleScopeImplementer*>(storage); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6043 | scope_implementer->IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6044 | return storage + ArchiveSpacePerThread(); |
| 6045 | } |
| 6046 | |
| 6047 | } } // namespace v8::internal |