erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 28 | #include "api.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 29 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 30 | #include <math.h> // For isnan. |
| 31 | #include <string.h> // For memcpy, strlen. |
| 32 | #include "../include/v8-debug.h" |
| 33 | #include "../include/v8-profiler.h" |
| 34 | #include "../include/v8-testing.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | #include "bootstrapper.h" |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 36 | #include "code-stubs.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | #include "compiler.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 38 | #include "conversions-inl.h" |
| 39 | #include "counters.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | #include "debug.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 41 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | #include "execution.h" |
| 43 | #include "global-handles.h" |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 44 | #include "heap-profiler.h" |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 45 | #include "heap-snapshot-generator-inl.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 46 | #include "messages.h" |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 47 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 48 | #include "natives.h" |
| 49 | #endif |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 50 | #include "parser.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 51 | #include "platform.h" |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 52 | #include "profile-generator-inl.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 53 | #include "property-details.h" |
| 54 | #include "property.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 55 | #include "runtime-profiler.h" |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 56 | #include "scanner-character-streams.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | #include "snapshot.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 58 | #include "unicode-inl.h" |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 59 | #include "v8threads.h" |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 60 | #include "version.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 61 | #include "vm-state-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 62 | |
| 63 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 64 | #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 66 | #define ENTER_V8(isolate) \ |
| 67 | ASSERT((isolate)->IsInitialized()); \ |
| 68 | i::VMState __state__((isolate), i::OTHER) |
| 69 | #define LEAVE_V8(isolate) \ |
| 70 | i::VMState __state__((isolate), i::EXTERNAL) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | |
| 72 | namespace v8 { |
| 73 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 74 | #define ON_BAILOUT(isolate, location, code) \ |
| 75 | if (IsDeadCheck(isolate, location) || \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 76 | IsExecutionTerminatingCheck(isolate)) { \ |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 77 | code; \ |
| 78 | UNREACHABLE(); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 82 | #define EXCEPTION_PREAMBLE(isolate) \ |
| 83 | (isolate)->handle_scope_implementer()->IncrementCallDepth(); \ |
| 84 | ASSERT(!(isolate)->external_caught_exception()); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 85 | bool has_pending_exception = false |
| 86 | |
| 87 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 88 | #define EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, do_callback) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | do { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 90 | i::HandleScopeImplementer* handle_scope_implementer = \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 91 | (isolate)->handle_scope_implementer(); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 92 | handle_scope_implementer->DecrementCallDepth(); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 93 | if (has_pending_exception) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 94 | if (handle_scope_implementer->CallDepthIsZero() && \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 95 | (isolate)->is_out_of_memory()) { \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 96 | if (!(isolate)->ignore_out_of_memory()) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 97 | i::V8::FatalProcessOutOfMemory(NULL); \ |
| 98 | } \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 99 | bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 100 | (isolate)->OptionalRescheduleException(call_depth_is_zero); \ |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 101 | do_callback \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 102 | return value; \ |
| 103 | } \ |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 104 | do_callback \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | } while (false) |
| 106 | |
| 107 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 108 | #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \ |
| 109 | EXCEPTION_BAILOUT_CHECK_GENERIC( \ |
| 110 | isolate, value, i::V8::FireCallCompletedCallback(isolate);) |
| 111 | |
| 112 | |
| 113 | #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ |
| 114 | EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;) |
| 115 | |
| 116 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 117 | #define API_ENTRY_CHECK(isolate, msg) \ |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 118 | do { \ |
| 119 | if (v8::Locker::IsActive()) { \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 120 | ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \ |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 121 | msg, \ |
| 122 | "Entering the V8 API without proper locking in place"); \ |
| 123 | } \ |
| 124 | } while (false) |
| 125 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 126 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | // --- E x c e p t i o n B e h a v i o r --- |
| 128 | |
| 129 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 130 | static void DefaultFatalErrorHandler(const char* location, |
| 131 | const char* message) { |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 132 | i::Isolate* isolate = i::Isolate::Current(); |
| 133 | if (isolate->IsInitialized()) { |
| 134 | i::VMState __state__(isolate, i::OTHER); |
| 135 | API_Fatal(location, message); |
| 136 | } else { |
| 137 | API_Fatal(location, message); |
| 138 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 142 | static FatalErrorCallback GetFatalErrorHandler() { |
| 143 | i::Isolate* isolate = i::Isolate::Current(); |
| 144 | if (isolate->exception_behavior() == NULL) { |
| 145 | isolate->set_exception_behavior(DefaultFatalErrorHandler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 146 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 147 | return isolate->exception_behavior(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 151 | void i::FatalProcessOutOfMemory(const char* location) { |
| 152 | i::V8::FatalProcessOutOfMemory(location, false); |
| 153 | } |
| 154 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 155 | |
| 156 | // When V8 cannot allocated memory FatalProcessOutOfMemory is called. |
| 157 | // The default fatal error handler is called and execution is stopped. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 158 | void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 159 | i::HeapStats heap_stats; |
| 160 | int start_marker; |
| 161 | heap_stats.start_marker = &start_marker; |
| 162 | int new_space_size; |
| 163 | heap_stats.new_space_size = &new_space_size; |
| 164 | int new_space_capacity; |
| 165 | heap_stats.new_space_capacity = &new_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 166 | intptr_t old_pointer_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 167 | heap_stats.old_pointer_space_size = &old_pointer_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 168 | intptr_t old_pointer_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 169 | heap_stats.old_pointer_space_capacity = &old_pointer_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 170 | intptr_t old_data_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 171 | heap_stats.old_data_space_size = &old_data_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 172 | intptr_t old_data_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 173 | heap_stats.old_data_space_capacity = &old_data_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 174 | intptr_t code_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 175 | heap_stats.code_space_size = &code_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 176 | intptr_t code_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 177 | heap_stats.code_space_capacity = &code_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 178 | intptr_t map_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 179 | heap_stats.map_space_size = &map_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 180 | intptr_t map_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 181 | heap_stats.map_space_capacity = &map_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 182 | intptr_t cell_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 183 | heap_stats.cell_space_size = &cell_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 184 | intptr_t cell_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 185 | heap_stats.cell_space_capacity = &cell_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 186 | intptr_t lo_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 187 | heap_stats.lo_space_size = &lo_space_size; |
| 188 | int global_handle_count; |
| 189 | heap_stats.global_handle_count = &global_handle_count; |
| 190 | int weak_global_handle_count; |
| 191 | heap_stats.weak_global_handle_count = &weak_global_handle_count; |
| 192 | int pending_global_handle_count; |
| 193 | heap_stats.pending_global_handle_count = &pending_global_handle_count; |
| 194 | int near_death_global_handle_count; |
| 195 | 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] | 196 | int free_global_handle_count; |
| 197 | heap_stats.free_global_handle_count = &free_global_handle_count; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 198 | intptr_t memory_allocator_size; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 199 | heap_stats.memory_allocator_size = &memory_allocator_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 200 | intptr_t memory_allocator_capacity; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 201 | heap_stats.memory_allocator_capacity = &memory_allocator_capacity; |
| 202 | int objects_per_type[LAST_TYPE + 1] = {0}; |
| 203 | heap_stats.objects_per_type = objects_per_type; |
| 204 | int size_per_type[LAST_TYPE + 1] = {0}; |
| 205 | heap_stats.size_per_type = size_per_type; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 206 | int os_error; |
| 207 | heap_stats.os_error = &os_error; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 208 | int end_marker; |
| 209 | heap_stats.end_marker = &end_marker; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 210 | i::Isolate* isolate = i::Isolate::Current(); |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 211 | if (isolate->heap()->HasBeenSetUp()) { |
| 212 | // BUG(1718): Don't use the take_snapshot since we don't support |
| 213 | // HeapIterator here without doing a special GC. |
| 214 | isolate->heap()->RecordStats(&heap_stats, false); |
| 215 | } |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 216 | i::V8::SetFatalError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 217 | FatalErrorCallback callback = GetFatalErrorHandler(); |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 218 | const char* message = "Allocation failed - process out of memory"; |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 219 | { |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 220 | if (isolate->IsInitialized()) { |
| 221 | LEAVE_V8(isolate); |
| 222 | callback(location, message); |
| 223 | } else { |
| 224 | callback(location, message); |
| 225 | } |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 226 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 227 | // If the callback returns, we stop execution. |
| 228 | UNREACHABLE(); |
| 229 | } |
| 230 | |
| 231 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 232 | bool Utils::ReportApiFailure(const char* location, const char* message) { |
| 233 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 234 | callback(location, message); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 235 | i::V8::SetFatalError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 236 | return false; |
| 237 | } |
| 238 | |
| 239 | |
| 240 | bool V8::IsDead() { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 241 | return i::V8::IsDead(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | |
| 245 | static inline bool ApiCheck(bool condition, |
| 246 | const char* location, |
| 247 | const char* message) { |
| 248 | return condition ? true : Utils::ReportApiFailure(location, message); |
| 249 | } |
| 250 | |
| 251 | |
| 252 | static bool ReportV8Dead(const char* location) { |
| 253 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 254 | callback(location, "V8 is no longer usable"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | return true; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | static bool ReportEmptyHandle(const char* location) { |
| 260 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 261 | callback(location, "Reading from empty handle"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 262 | return true; |
| 263 | } |
| 264 | |
| 265 | |
| 266 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 267 | * 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] | 268 | * out of memory at some point this check will fail. It should be called on |
| 269 | * entry to all methods that touch anything in the heap, except destructors |
| 270 | * which you sometimes can't avoid calling after the vm has crashed. Functions |
| 271 | * that call EnsureInitialized or ON_BAILOUT don't have to also call |
| 272 | * IsDeadCheck. ON_BAILOUT has the advantage over EnsureInitialized that you |
| 273 | * can arrange to return if the VM is dead. This is needed to ensure that no VM |
| 274 | * heap allocations are attempted on a dead VM. EnsureInitialized has the |
| 275 | * advantage over ON_BAILOUT that it actually initializes the VM if this has not |
| 276 | * yet been done. |
| 277 | */ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 278 | static inline bool IsDeadCheck(i::Isolate* isolate, const char* location) { |
| 279 | return !isolate->IsInitialized() |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 280 | && i::V8::IsDead() ? ReportV8Dead(location) : false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 284 | static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { |
| 285 | if (!isolate->IsInitialized()) return false; |
| 286 | if (isolate->has_scheduled_exception()) { |
| 287 | return isolate->scheduled_exception() == |
| 288 | isolate->heap()->termination_exception(); |
| 289 | } |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 294 | static inline bool EmptyCheck(const char* location, v8::Handle<v8::Data> obj) { |
| 295 | return obj.IsEmpty() ? ReportEmptyHandle(location) : false; |
| 296 | } |
| 297 | |
| 298 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 299 | static inline bool EmptyCheck(const char* location, const v8::Data* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 300 | return (obj == 0) ? ReportEmptyHandle(location) : false; |
| 301 | } |
| 302 | |
| 303 | // --- S t a t i c s --- |
| 304 | |
| 305 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 306 | static bool InitializeHelper() { |
| 307 | if (i::Snapshot::Initialize()) return true; |
| 308 | return i::V8::Initialize(NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 312 | static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, |
| 313 | const char* location) { |
| 314 | if (IsDeadCheck(isolate, location)) return false; |
| 315 | if (isolate != NULL) { |
| 316 | if (isolate->IsInitialized()) return true; |
| 317 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 318 | ASSERT(isolate == i::Isolate::Current()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 319 | return ApiCheck(InitializeHelper(), location, "Error initializing V8"); |
| 320 | } |
| 321 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 322 | // Some initializing API functions are called early and may be |
| 323 | // called on a thread different from static initializer thread. |
| 324 | // If Isolate API is used, Isolate::Enter() will initialize TLS so |
| 325 | // Isolate::Current() works. If it's a legacy case, then the thread |
| 326 | // may not have TLS initialized yet. However, in initializing APIs it |
| 327 | // may be too early to call EnsureInitialized() - some pre-init |
| 328 | // parameters still have to be configured. |
| 329 | static inline i::Isolate* EnterIsolateIfNeeded() { |
| 330 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 331 | if (isolate != NULL) |
| 332 | return isolate; |
| 333 | |
| 334 | i::Isolate::EnterDefaultIsolate(); |
| 335 | isolate = i::Isolate::Current(); |
| 336 | return isolate; |
| 337 | } |
| 338 | |
| 339 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 340 | StartupDataDecompressor::StartupDataDecompressor() |
| 341 | : raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) { |
| 342 | for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { |
| 343 | raw_data[i] = NULL; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | |
| 348 | StartupDataDecompressor::~StartupDataDecompressor() { |
| 349 | for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { |
| 350 | i::DeleteArray(raw_data[i]); |
| 351 | } |
| 352 | i::DeleteArray(raw_data); |
| 353 | } |
| 354 | |
| 355 | |
| 356 | int StartupDataDecompressor::Decompress() { |
| 357 | int compressed_data_count = V8::GetCompressedStartupDataCount(); |
| 358 | StartupData* compressed_data = |
| 359 | i::NewArray<StartupData>(compressed_data_count); |
| 360 | V8::GetCompressedStartupData(compressed_data); |
| 361 | for (int i = 0; i < compressed_data_count; ++i) { |
| 362 | char* decompressed = raw_data[i] = |
| 363 | i::NewArray<char>(compressed_data[i].raw_size); |
| 364 | if (compressed_data[i].compressed_size != 0) { |
| 365 | int result = DecompressData(decompressed, |
| 366 | &compressed_data[i].raw_size, |
| 367 | compressed_data[i].data, |
| 368 | compressed_data[i].compressed_size); |
| 369 | if (result != 0) return result; |
| 370 | } else { |
| 371 | ASSERT_EQ(0, compressed_data[i].raw_size); |
| 372 | } |
| 373 | compressed_data[i].data = decompressed; |
| 374 | } |
| 375 | V8::SetDecompressedStartupData(compressed_data); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 376 | i::DeleteArray(compressed_data); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 381 | StartupData::CompressionAlgorithm V8::GetCompressedStartupDataAlgorithm() { |
| 382 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 383 | return StartupData::kBZip2; |
| 384 | #else |
| 385 | return StartupData::kUncompressed; |
| 386 | #endif |
| 387 | } |
| 388 | |
| 389 | |
| 390 | enum CompressedStartupDataItems { |
| 391 | kSnapshot = 0, |
| 392 | kSnapshotContext, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 393 | kLibraries, |
| 394 | kExperimentalLibraries, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 395 | kCompressedStartupDataCount |
| 396 | }; |
| 397 | |
| 398 | int V8::GetCompressedStartupDataCount() { |
| 399 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 400 | return kCompressedStartupDataCount; |
| 401 | #else |
| 402 | return 0; |
| 403 | #endif |
| 404 | } |
| 405 | |
| 406 | |
| 407 | void V8::GetCompressedStartupData(StartupData* compressed_data) { |
| 408 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 409 | compressed_data[kSnapshot].data = |
| 410 | reinterpret_cast<const char*>(i::Snapshot::data()); |
| 411 | compressed_data[kSnapshot].compressed_size = i::Snapshot::size(); |
| 412 | compressed_data[kSnapshot].raw_size = i::Snapshot::raw_size(); |
| 413 | |
| 414 | compressed_data[kSnapshotContext].data = |
| 415 | reinterpret_cast<const char*>(i::Snapshot::context_data()); |
| 416 | compressed_data[kSnapshotContext].compressed_size = |
| 417 | i::Snapshot::context_size(); |
| 418 | compressed_data[kSnapshotContext].raw_size = i::Snapshot::context_raw_size(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 419 | |
| 420 | i::Vector<const i::byte> libraries_source = i::Natives::GetScriptsSource(); |
| 421 | compressed_data[kLibraries].data = |
| 422 | reinterpret_cast<const char*>(libraries_source.start()); |
| 423 | compressed_data[kLibraries].compressed_size = libraries_source.length(); |
| 424 | compressed_data[kLibraries].raw_size = i::Natives::GetRawScriptsSize(); |
| 425 | |
| 426 | i::Vector<const i::byte> exp_libraries_source = |
| 427 | i::ExperimentalNatives::GetScriptsSource(); |
| 428 | compressed_data[kExperimentalLibraries].data = |
| 429 | reinterpret_cast<const char*>(exp_libraries_source.start()); |
| 430 | compressed_data[kExperimentalLibraries].compressed_size = |
| 431 | exp_libraries_source.length(); |
| 432 | compressed_data[kExperimentalLibraries].raw_size = |
| 433 | i::ExperimentalNatives::GetRawScriptsSize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 434 | #endif |
| 435 | } |
| 436 | |
| 437 | |
| 438 | void V8::SetDecompressedStartupData(StartupData* decompressed_data) { |
| 439 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 440 | ASSERT_EQ(i::Snapshot::raw_size(), decompressed_data[kSnapshot].raw_size); |
| 441 | i::Snapshot::set_raw_data( |
| 442 | reinterpret_cast<const i::byte*>(decompressed_data[kSnapshot].data)); |
| 443 | |
| 444 | ASSERT_EQ(i::Snapshot::context_raw_size(), |
| 445 | decompressed_data[kSnapshotContext].raw_size); |
| 446 | i::Snapshot::set_context_raw_data( |
| 447 | reinterpret_cast<const i::byte*>( |
| 448 | decompressed_data[kSnapshotContext].data)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 449 | |
| 450 | ASSERT_EQ(i::Natives::GetRawScriptsSize(), |
| 451 | decompressed_data[kLibraries].raw_size); |
| 452 | i::Vector<const char> libraries_source( |
| 453 | decompressed_data[kLibraries].data, |
| 454 | decompressed_data[kLibraries].raw_size); |
| 455 | i::Natives::SetRawScriptsSource(libraries_source); |
| 456 | |
| 457 | ASSERT_EQ(i::ExperimentalNatives::GetRawScriptsSize(), |
| 458 | decompressed_data[kExperimentalLibraries].raw_size); |
| 459 | i::Vector<const char> exp_libraries_source( |
| 460 | decompressed_data[kExperimentalLibraries].data, |
| 461 | decompressed_data[kExperimentalLibraries].raw_size); |
| 462 | i::ExperimentalNatives::SetRawScriptsSource(exp_libraries_source); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 463 | #endif |
| 464 | } |
| 465 | |
| 466 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 467 | void V8::SetFatalErrorHandler(FatalErrorCallback that) { |
| 468 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 469 | isolate->set_exception_behavior(that); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 473 | void V8::SetAllowCodeGenerationFromStringsCallback( |
| 474 | AllowCodeGenerationFromStringsCallback callback) { |
| 475 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 476 | isolate->set_allow_code_gen_callback(callback); |
| 477 | } |
| 478 | |
| 479 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 480 | #ifdef DEBUG |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 481 | void ImplementationUtilities::ZapHandleRange(i::Object** begin, |
| 482 | i::Object** end) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 483 | i::HandleScope::ZapRange(begin, end); |
| 484 | } |
| 485 | #endif |
| 486 | |
| 487 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 488 | void V8::SetFlagsFromString(const char* str, int length) { |
| 489 | i::FlagList::SetFlagsFromString(str, length); |
| 490 | } |
| 491 | |
| 492 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 493 | void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { |
| 494 | i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); |
| 495 | } |
| 496 | |
| 497 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 498 | v8::Handle<Value> ThrowException(v8::Handle<v8::Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 499 | i::Isolate* isolate = i::Isolate::Current(); |
| 500 | if (IsDeadCheck(isolate, "v8::ThrowException()")) { |
| 501 | return v8::Handle<Value>(); |
| 502 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 503 | ENTER_V8(isolate); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 504 | // If we're passed an empty handle, we throw an undefined exception |
| 505 | // to deal more gracefully with out of memory situations. |
| 506 | if (value.IsEmpty()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 507 | isolate->ScheduleThrow(isolate->heap()->undefined_value()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 508 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 509 | isolate->ScheduleThrow(*Utils::OpenHandle(*value)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 510 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 511 | return v8::Undefined(); |
| 512 | } |
| 513 | |
| 514 | |
| 515 | RegisteredExtension* RegisteredExtension::first_extension_ = NULL; |
| 516 | |
| 517 | |
| 518 | RegisteredExtension::RegisteredExtension(Extension* extension) |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 519 | : extension_(extension) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 520 | |
| 521 | |
| 522 | void RegisteredExtension::Register(RegisteredExtension* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 523 | that->next_ = first_extension_; |
| 524 | first_extension_ = that; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 528 | void RegisteredExtension::UnregisterAll() { |
| 529 | RegisteredExtension* re = first_extension_; |
| 530 | while (re != NULL) { |
| 531 | RegisteredExtension* next = re->next(); |
| 532 | delete re; |
| 533 | re = next; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | void RegisterExtension(Extension* that) { |
| 539 | RegisteredExtension* extension = new RegisteredExtension(that); |
| 540 | RegisteredExtension::Register(extension); |
| 541 | } |
| 542 | |
| 543 | |
| 544 | Extension::Extension(const char* name, |
| 545 | const char* source, |
| 546 | int dep_count, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 547 | const char** deps, |
| 548 | int source_length) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 549 | : name_(name), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 550 | source_length_(source_length >= 0 ? |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 551 | source_length : |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 552 | (source ? static_cast<int>(strlen(source)) : 0)), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 553 | source_(source, source_length_), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 554 | dep_count_(dep_count), |
| 555 | deps_(deps), |
danno@chromium.org | 412fa51 | 2012-09-14 13:28:26 +0000 | [diff] [blame] | 556 | auto_enable_(false) { |
| 557 | CHECK(source != NULL || source_length_ == 0); |
| 558 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 559 | |
| 560 | |
| 561 | v8::Handle<Primitive> Undefined() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 562 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 563 | if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) { |
| 564 | return v8::Handle<v8::Primitive>(); |
| 565 | } |
| 566 | return v8::Handle<Primitive>(ToApi<Primitive>( |
| 567 | isolate->factory()->undefined_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | |
| 571 | v8::Handle<Primitive> Null() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 572 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 573 | if (!EnsureInitializedForIsolate(isolate, "v8::Null()")) { |
| 574 | return v8::Handle<v8::Primitive>(); |
| 575 | } |
| 576 | return v8::Handle<Primitive>( |
| 577 | ToApi<Primitive>(isolate->factory()->null_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | |
| 581 | v8::Handle<Boolean> True() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 582 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 583 | if (!EnsureInitializedForIsolate(isolate, "v8::True()")) { |
| 584 | return v8::Handle<Boolean>(); |
| 585 | } |
| 586 | return v8::Handle<Boolean>( |
| 587 | ToApi<Boolean>(isolate->factory()->true_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | |
| 591 | v8::Handle<Boolean> False() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 592 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 593 | if (!EnsureInitializedForIsolate(isolate, "v8::False()")) { |
| 594 | return v8::Handle<Boolean>(); |
| 595 | } |
| 596 | return v8::Handle<Boolean>( |
| 597 | ToApi<Boolean>(isolate->factory()->false_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | |
| 601 | ResourceConstraints::ResourceConstraints() |
| 602 | : max_young_space_size_(0), |
| 603 | max_old_space_size_(0), |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 604 | max_executable_size_(0), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 605 | stack_limit_(NULL) { } |
| 606 | |
| 607 | |
| 608 | bool SetResourceConstraints(ResourceConstraints* constraints) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 609 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 610 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 611 | int young_space_size = constraints->max_young_space_size(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 612 | int old_gen_size = constraints->max_old_space_size(); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 613 | int max_executable_size = constraints->max_executable_size(); |
| 614 | 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] | 615 | // After initialization it's too late to change Heap constraints. |
| 616 | ASSERT(!isolate->IsInitialized()); |
| 617 | bool result = isolate->heap()->ConfigureHeap(young_space_size / 2, |
| 618 | old_gen_size, |
| 619 | max_executable_size); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 620 | if (!result) return false; |
| 621 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 622 | if (constraints->stack_limit() != NULL) { |
| 623 | uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 624 | isolate->stack_guard()->SetStackLimit(limit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 625 | } |
| 626 | return true; |
| 627 | } |
| 628 | |
| 629 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 630 | i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 631 | if (IsDeadCheck(isolate, "V8::Persistent::New")) return NULL; |
| 632 | LOG_API(isolate, "Persistent::New"); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 633 | i::Handle<i::Object> result = isolate->global_handles()->Create(*obj); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 634 | return result.location(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 638 | void V8::MakeWeak(i::Isolate* isolate, |
| 639 | i::Object** object, |
| 640 | void* parameters, |
| 641 | WeakReferenceCallback weak_reference_callback, |
| 642 | NearDeathCallback near_death_callback) { |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 643 | ASSERT(isolate == i::Isolate::Current()); |
| 644 | LOG_API(isolate, "MakeWeak"); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 645 | isolate->global_handles()->MakeWeak(object, |
| 646 | parameters, |
| 647 | weak_reference_callback, |
| 648 | near_death_callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 652 | void V8::ClearWeak(i::Isolate* isolate, i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 653 | LOG_API(isolate, "ClearWeak"); |
| 654 | isolate->global_handles()->ClearWeakness(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 658 | void V8::DisposeGlobal(i::Isolate* isolate, i::Object** obj) { |
| 659 | ASSERT(isolate == i::Isolate::Current()); |
| 660 | LOG_API(isolate, "DisposeGlobal"); |
| 661 | if (!isolate->IsInitialized()) return; |
| 662 | isolate->global_handles()->Destroy(obj); |
| 663 | } |
| 664 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 665 | // --- H a n d l e s --- |
| 666 | |
| 667 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 668 | HandleScope::HandleScope() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 669 | i::Isolate* isolate = i::Isolate::Current(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 670 | API_ENTRY_CHECK(isolate, "HandleScope::HandleScope"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 671 | v8::ImplementationUtilities::HandleScopeData* current = |
| 672 | isolate->handle_scope_data(); |
| 673 | isolate_ = isolate; |
| 674 | prev_next_ = current->next; |
| 675 | prev_limit_ = current->limit; |
| 676 | is_closed_ = false; |
| 677 | current->level++; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | |
| 681 | HandleScope::~HandleScope() { |
| 682 | if (!is_closed_) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 683 | Leave(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 684 | } |
| 685 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 686 | |
| 687 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 688 | void HandleScope::Leave() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 689 | ASSERT(isolate_ == i::Isolate::Current()); |
| 690 | v8::ImplementationUtilities::HandleScopeData* current = |
| 691 | isolate_->handle_scope_data(); |
| 692 | current->level--; |
| 693 | ASSERT(current->level >= 0); |
| 694 | current->next = prev_next_; |
| 695 | if (current->limit != prev_limit_) { |
| 696 | current->limit = prev_limit_; |
| 697 | i::HandleScope::DeleteExtensions(isolate_); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | #ifdef DEBUG |
| 701 | i::HandleScope::ZapRange(prev_next_, prev_limit_); |
| 702 | #endif |
| 703 | } |
| 704 | |
| 705 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 706 | int HandleScope::NumberOfHandles() { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 707 | i::Isolate* isolate = i::Isolate::Current(); |
| 708 | if (!EnsureInitializedForIsolate(isolate, "HandleScope::NumberOfHandles")) { |
| 709 | return 0; |
| 710 | } |
| 711 | return i::HandleScope::NumberOfHandles(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 715 | i::Object** HandleScope::CreateHandle(i::Object* value) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 716 | return i::HandleScope::CreateHandle(i::Isolate::Current(), value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 720 | i::Object** HandleScope::CreateHandle(i::Isolate* isolate, i::Object* value) { |
| 721 | ASSERT(isolate == i::Isolate::Current()); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 722 | return i::HandleScope::CreateHandle(isolate, value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 726 | i::Object** HandleScope::CreateHandle(i::HeapObject* value) { |
| 727 | ASSERT(value->IsHeapObject()); |
| 728 | return reinterpret_cast<i::Object**>( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 729 | i::HandleScope::CreateHandle(value->GetIsolate(), value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | |
| 733 | void Context::Enter() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 734 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 735 | i::Isolate* isolate = env->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 736 | if (IsDeadCheck(isolate, "v8::Context::Enter()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 737 | ENTER_V8(isolate); |
| 738 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 739 | isolate->handle_scope_implementer()->EnterContext(env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 740 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 741 | isolate->handle_scope_implementer()->SaveContext(isolate->context()); |
| 742 | isolate->set_context(*env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | |
| 746 | void Context::Exit() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 747 | // Exit is essentially a static function and doesn't use the |
| 748 | // receiver, so we have to get the current isolate from the thread |
| 749 | // local. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 750 | i::Isolate* isolate = i::Isolate::Current(); |
| 751 | if (!isolate->IsInitialized()) return; |
| 752 | |
| 753 | if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(), |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 754 | "v8::Context::Exit()", |
| 755 | "Cannot exit non-entered context")) { |
| 756 | return; |
| 757 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 758 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 759 | // Content of 'last_context' could be NULL. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 760 | i::Context* last_context = |
| 761 | isolate->handle_scope_implementer()->RestoreContext(); |
| 762 | isolate->set_context(last_context); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 763 | isolate->set_context_exit_happened(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 767 | static void* DecodeSmiToAligned(i::Object* value, const char* location) { |
| 768 | ApiCheck(value->IsSmi(), location, "Not a Smi"); |
| 769 | return reinterpret_cast<void*>(value); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 773 | static i::Smi* EncodeAlignedAsSmi(void* value, const char* location) { |
| 774 | i::Smi* smi = reinterpret_cast<i::Smi*>(value); |
| 775 | ApiCheck(smi->IsSmi(), location, "Pointer is not aligned"); |
| 776 | return smi; |
| 777 | } |
| 778 | |
| 779 | |
| 780 | static i::Handle<i::FixedArray> EmbedderDataFor(Context* context, |
| 781 | int index, |
| 782 | bool can_grow, |
| 783 | const char* location) { |
| 784 | i::Handle<i::Context> env = Utils::OpenHandle(context); |
| 785 | bool ok = !IsDeadCheck(env->GetIsolate(), location) && |
| 786 | ApiCheck(env->IsNativeContext(), location, "Not a native context") && |
| 787 | ApiCheck(index >= 0, location, "Negative index"); |
| 788 | if (!ok) return i::Handle<i::FixedArray>(); |
| 789 | i::Handle<i::FixedArray> data(env->embedder_data()); |
| 790 | if (index < data->length()) return data; |
| 791 | if (!can_grow) { |
| 792 | Utils::ReportApiFailure(location, "Index too large"); |
| 793 | return i::Handle<i::FixedArray>(); |
svenpanne@chromium.org | fc2a4f4 | 2012-11-07 09:25:55 +0000 | [diff] [blame] | 794 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 795 | int new_size = i::Max(index, data->length() << 1) + 1; |
| 796 | data = env->GetIsolate()->factory()->CopySizeFixedArray(data, new_size); |
| 797 | env->set_embedder_data(*data); |
| 798 | return data; |
| 799 | } |
| 800 | |
| 801 | |
| 802 | v8::Local<v8::Value> Context::SlowGetEmbedderData(int index) { |
| 803 | const char* location = "v8::Context::GetEmbedderData()"; |
| 804 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location); |
| 805 | if (data.is_null()) return Local<Value>(); |
| 806 | i::Handle<i::Object> result(data->get(index), data->GetIsolate()); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 807 | return Utils::ToLocal(result); |
| 808 | } |
| 809 | |
| 810 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 811 | void Context::SetEmbedderData(int index, v8::Handle<Value> value) { |
| 812 | const char* location = "v8::Context::SetEmbedderData()"; |
| 813 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, true, location); |
| 814 | if (data.is_null()) return; |
| 815 | i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 816 | data->set(index, *val); |
| 817 | ASSERT_EQ(*Utils::OpenHandle(*value), |
| 818 | *Utils::OpenHandle(*GetEmbedderData(index))); |
| 819 | } |
| 820 | |
| 821 | |
| 822 | void* Context::SlowGetAlignedPointerFromEmbedderData(int index) { |
| 823 | const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()"; |
| 824 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location); |
| 825 | if (data.is_null()) return NULL; |
| 826 | return DecodeSmiToAligned(data->get(index), location); |
| 827 | } |
| 828 | |
| 829 | |
| 830 | void Context::SetAlignedPointerInEmbedderData(int index, void* value) { |
| 831 | const char* location = "v8::Context::SetAlignedPointerInEmbedderData()"; |
| 832 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, true, location); |
| 833 | data->set(index, EncodeAlignedAsSmi(value, location)); |
| 834 | ASSERT_EQ(value, GetAlignedPointerFromEmbedderData(index)); |
| 835 | } |
| 836 | |
| 837 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 838 | i::Object** v8::HandleScope::RawClose(i::Object** value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 839 | if (!ApiCheck(!is_closed_, |
| 840 | "v8::HandleScope::Close()", |
| 841 | "Local scope has already been closed")) { |
| 842 | return 0; |
| 843 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 844 | LOG_API(isolate_, "CloseHandleScope"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 845 | |
| 846 | // Read the result before popping the handle block. |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 847 | i::Object* result = NULL; |
| 848 | if (value != NULL) { |
| 849 | result = *value; |
| 850 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 851 | is_closed_ = true; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 852 | Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 853 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 854 | if (value == NULL) { |
| 855 | return NULL; |
| 856 | } |
| 857 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | // Allocate a new handle on the previous handle block. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 859 | i::Handle<i::Object> handle(result, isolate_); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 860 | return handle.location(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | |
| 864 | // --- N e a n d e r --- |
| 865 | |
| 866 | |
| 867 | // A constructor cannot easily return an error value, therefore it is necessary |
| 868 | // to check for a dead VM with ON_BAILOUT before constructing any Neander |
| 869 | // objects. To remind you about this there is no HandleScope in the |
| 870 | // NeanderObject constructor. When you add one to the site calling the |
| 871 | // constructor you should check that you ensured the VM was not dead first. |
| 872 | NeanderObject::NeanderObject(int size) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 873 | i::Isolate* isolate = i::Isolate::Current(); |
| 874 | EnsureInitializedForIsolate(isolate, "v8::Nowhere"); |
| 875 | ENTER_V8(isolate); |
| 876 | value_ = isolate->factory()->NewNeanderObject(); |
| 877 | i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 878 | value_->set_elements(*elements); |
| 879 | } |
| 880 | |
| 881 | |
| 882 | int NeanderObject::size() { |
| 883 | return i::FixedArray::cast(value_->elements())->length(); |
| 884 | } |
| 885 | |
| 886 | |
| 887 | NeanderArray::NeanderArray() : obj_(2) { |
| 888 | obj_.set(0, i::Smi::FromInt(0)); |
| 889 | } |
| 890 | |
| 891 | |
| 892 | int NeanderArray::length() { |
| 893 | return i::Smi::cast(obj_.get(0))->value(); |
| 894 | } |
| 895 | |
| 896 | |
| 897 | i::Object* NeanderArray::get(int offset) { |
| 898 | ASSERT(0 <= offset); |
| 899 | ASSERT(offset < length()); |
| 900 | return obj_.get(offset + 1); |
| 901 | } |
| 902 | |
| 903 | |
| 904 | // This method cannot easily return an error value, therefore it is necessary |
| 905 | // to check for a dead VM with ON_BAILOUT before calling it. To remind you |
| 906 | // about this there is no HandleScope in this method. When you add one to the |
| 907 | // site calling this method you should check that you ensured the VM was not |
| 908 | // dead first. |
| 909 | void NeanderArray::add(i::Handle<i::Object> value) { |
| 910 | int length = this->length(); |
| 911 | int size = obj_.size(); |
| 912 | if (length == size - 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 913 | i::Handle<i::FixedArray> new_elms = FACTORY->NewFixedArray(2 * size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 914 | for (int i = 0; i < length; i++) |
| 915 | new_elms->set(i + 1, get(i)); |
| 916 | obj_.value()->set_elements(*new_elms); |
| 917 | } |
| 918 | obj_.set(length + 1, *value); |
| 919 | obj_.set(0, i::Smi::FromInt(length + 1)); |
| 920 | } |
| 921 | |
| 922 | |
| 923 | void NeanderArray::set(int index, i::Object* value) { |
| 924 | if (index < 0 || index >= this->length()) return; |
| 925 | obj_.set(index + 1, value); |
| 926 | } |
| 927 | |
| 928 | |
| 929 | // --- T e m p l a t e --- |
| 930 | |
| 931 | |
| 932 | static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { |
| 933 | that->set_tag(i::Smi::FromInt(type)); |
| 934 | } |
| 935 | |
| 936 | |
| 937 | void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, |
| 938 | v8::PropertyAttribute attribute) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 939 | i::Isolate* isolate = i::Isolate::Current(); |
| 940 | if (IsDeadCheck(isolate, "v8::Template::Set()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 941 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 942 | i::HandleScope scope(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 943 | i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 944 | if (list->IsUndefined()) { |
| 945 | list = NeanderArray().value(); |
| 946 | Utils::OpenHandle(this)->set_property_list(*list); |
| 947 | } |
| 948 | NeanderArray array(list); |
| 949 | array.add(Utils::OpenHandle(*name)); |
| 950 | array.add(Utils::OpenHandle(*value)); |
| 951 | array.add(Utils::OpenHandle(*v8::Integer::New(attribute))); |
| 952 | } |
| 953 | |
| 954 | |
| 955 | // --- F u n c t i o n T e m p l a t e --- |
| 956 | static void InitializeFunctionTemplate( |
| 957 | i::Handle<i::FunctionTemplateInfo> info) { |
| 958 | info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE)); |
| 959 | info->set_flag(0); |
| 960 | } |
| 961 | |
| 962 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 963 | Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 964 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 965 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::PrototypeTemplate()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 966 | return Local<ObjectTemplate>(); |
| 967 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 968 | ENTER_V8(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 969 | i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(), |
| 970 | isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 971 | if (result->IsUndefined()) { |
| 972 | result = Utils::OpenHandle(*ObjectTemplate::New()); |
| 973 | Utils::OpenHandle(this)->set_prototype_template(*result); |
| 974 | } |
| 975 | return Local<ObjectTemplate>(ToApi<ObjectTemplate>(result)); |
| 976 | } |
| 977 | |
| 978 | |
| 979 | void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 980 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 981 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 982 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 983 | Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); |
| 984 | } |
| 985 | |
| 986 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 987 | Local<FunctionTemplate> FunctionTemplate::New(InvocationCallback callback, |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 988 | v8::Handle<Value> data, v8::Handle<Signature> signature, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 989 | i::Isolate* isolate = i::Isolate::Current(); |
| 990 | EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); |
| 991 | LOG_API(isolate, "FunctionTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 992 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 993 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 994 | isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 995 | i::Handle<i::FunctionTemplateInfo> obj = |
| 996 | i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
| 997 | InitializeFunctionTemplate(obj); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 998 | int next_serial_number = isolate->next_serial_number(); |
| 999 | isolate->set_next_serial_number(next_serial_number + 1); |
| 1000 | obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1001 | if (callback != 0) { |
| 1002 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1003 | Utils::ToLocal(obj)->SetCallHandler(callback, data); |
| 1004 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1005 | obj->set_length(length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1006 | obj->set_undetectable(false); |
| 1007 | obj->set_needs_access_check(false); |
| 1008 | |
| 1009 | if (!signature.IsEmpty()) |
| 1010 | obj->set_signature(*Utils::OpenHandle(*signature)); |
| 1011 | return Utils::ToLocal(obj); |
| 1012 | } |
| 1013 | |
| 1014 | |
| 1015 | Local<Signature> Signature::New(Handle<FunctionTemplate> receiver, |
| 1016 | int argc, Handle<FunctionTemplate> argv[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1017 | i::Isolate* isolate = i::Isolate::Current(); |
| 1018 | EnsureInitializedForIsolate(isolate, "v8::Signature::New()"); |
| 1019 | LOG_API(isolate, "Signature::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1020 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1021 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1022 | isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1023 | i::Handle<i::SignatureInfo> obj = |
| 1024 | i::Handle<i::SignatureInfo>::cast(struct_obj); |
| 1025 | if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver)); |
| 1026 | if (argc > 0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1027 | i::Handle<i::FixedArray> args = isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1028 | for (int i = 0; i < argc; i++) { |
| 1029 | if (!argv[i].IsEmpty()) |
| 1030 | args->set(i, *Utils::OpenHandle(*argv[i])); |
| 1031 | } |
| 1032 | obj->set_args(*args); |
| 1033 | } |
| 1034 | return Utils::ToLocal(obj); |
| 1035 | } |
| 1036 | |
| 1037 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1038 | Local<AccessorSignature> AccessorSignature::New( |
| 1039 | Handle<FunctionTemplate> receiver) { |
| 1040 | return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); |
| 1041 | } |
| 1042 | |
| 1043 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1044 | Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) { |
| 1045 | Handle<FunctionTemplate> types[1] = { type }; |
| 1046 | return TypeSwitch::New(1, types); |
| 1047 | } |
| 1048 | |
| 1049 | |
| 1050 | Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1051 | i::Isolate* isolate = i::Isolate::Current(); |
| 1052 | EnsureInitializedForIsolate(isolate, "v8::TypeSwitch::New()"); |
| 1053 | LOG_API(isolate, "TypeSwitch::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1054 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1055 | i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | for (int i = 0; i < argc; i++) |
| 1057 | vector->set(i, *Utils::OpenHandle(*types[i])); |
| 1058 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1059 | isolate->factory()->NewStruct(i::TYPE_SWITCH_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1060 | i::Handle<i::TypeSwitchInfo> obj = |
| 1061 | i::Handle<i::TypeSwitchInfo>::cast(struct_obj); |
| 1062 | obj->set_types(*vector); |
| 1063 | return Utils::ToLocal(obj); |
| 1064 | } |
| 1065 | |
| 1066 | |
| 1067 | int TypeSwitch::match(v8::Handle<Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1068 | i::Isolate* isolate = i::Isolate::Current(); |
| 1069 | LOG_API(isolate, "TypeSwitch::match"); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1070 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1071 | i::Handle<i::Object> obj = Utils::OpenHandle(*value); |
| 1072 | i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this); |
| 1073 | i::FixedArray* types = i::FixedArray::cast(info->types()); |
| 1074 | for (int i = 0; i < types->length(); i++) { |
| 1075 | if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i)))) |
| 1076 | return i + 1; |
| 1077 | } |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
| 1081 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1082 | #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
| 1083 | i::Handle<i::Object> foreign = FromCData(cdata); \ |
| 1084 | (obj)->setter(*foreign); \ |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1085 | } while (false) |
| 1086 | |
| 1087 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1088 | void FunctionTemplate::SetCallHandler(InvocationCallback callback, |
| 1089 | v8::Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1090 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1091 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetCallHandler()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1092 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1093 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1094 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1095 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1096 | i::Handle<i::CallHandlerInfo> obj = |
| 1097 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1098 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1099 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1100 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1101 | Utils::OpenHandle(this)->set_call_code(*obj); |
| 1102 | } |
| 1103 | |
| 1104 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1105 | static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
| 1106 | v8::Handle<String> name, |
| 1107 | AccessorGetter getter, |
| 1108 | AccessorSetter setter, |
| 1109 | v8::Handle<Value> data, |
| 1110 | v8::AccessControl settings, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1111 | v8::PropertyAttribute attributes, |
| 1112 | v8::Handle<AccessorSignature> signature) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1113 | i::Handle<i::ExecutableAccessorInfo> obj = |
| 1114 | FACTORY->NewExecutableAccessorInfo(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1115 | SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1116 | SET_FIELD_WRAPPED(obj, set_setter, setter); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1117 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1118 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1119 | obj->set_name(*Utils::OpenHandle(*name)); |
| 1120 | if (settings & ALL_CAN_READ) obj->set_all_can_read(true); |
| 1121 | if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); |
| 1122 | if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true); |
| 1123 | obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1124 | if (!signature.IsEmpty()) { |
| 1125 | obj->set_expected_receiver_type(*Utils::OpenHandle(*signature)); |
| 1126 | } |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1127 | return obj; |
| 1128 | } |
| 1129 | |
| 1130 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1131 | void FunctionTemplate::AddInstancePropertyAccessor( |
| 1132 | v8::Handle<String> name, |
| 1133 | AccessorGetter getter, |
| 1134 | AccessorSetter setter, |
| 1135 | v8::Handle<Value> data, |
| 1136 | v8::AccessControl settings, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1137 | v8::PropertyAttribute attributes, |
| 1138 | v8::Handle<AccessorSignature> signature) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1139 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1140 | if (IsDeadCheck(isolate, |
| 1141 | "v8::FunctionTemplate::AddInstancePropertyAccessor()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1142 | return; |
| 1143 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1144 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1145 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1146 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1147 | i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name, getter, setter, data, |
| 1148 | settings, attributes, |
| 1149 | signature); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1150 | i::Handle<i::Object> list(Utils::OpenHandle(this)->property_accessors(), |
| 1151 | isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1152 | if (list->IsUndefined()) { |
| 1153 | list = NeanderArray().value(); |
| 1154 | Utils::OpenHandle(this)->set_property_accessors(*list); |
| 1155 | } |
| 1156 | NeanderArray array(list); |
| 1157 | array.add(obj); |
| 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1162 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1163 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::InstanceTemplate()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1164 | || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) |
| 1165 | return Local<ObjectTemplate>(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1166 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1167 | if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) { |
| 1168 | Local<ObjectTemplate> templ = |
| 1169 | ObjectTemplate::New(v8::Handle<FunctionTemplate>(this)); |
| 1170 | Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ)); |
| 1171 | } |
| 1172 | i::Handle<i::ObjectTemplateInfo> result(i::ObjectTemplateInfo::cast( |
| 1173 | Utils::OpenHandle(this)->instance_template())); |
| 1174 | return Utils::ToLocal(result); |
| 1175 | } |
| 1176 | |
| 1177 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1178 | void FunctionTemplate::SetLength(int length) { |
| 1179 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1180 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetLength()")) return; |
| 1181 | ENTER_V8(isolate); |
| 1182 | Utils::OpenHandle(this)->set_length(length); |
| 1183 | } |
| 1184 | |
| 1185 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1186 | void FunctionTemplate::SetClassName(Handle<String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1187 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1188 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetClassName()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1189 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1190 | Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name)); |
| 1191 | } |
| 1192 | |
| 1193 | |
| 1194 | void FunctionTemplate::SetHiddenPrototype(bool value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1195 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1196 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetHiddenPrototype()")) { |
| 1197 | return; |
| 1198 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1199 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1200 | Utils::OpenHandle(this)->set_hidden_prototype(value); |
| 1201 | } |
| 1202 | |
| 1203 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1204 | void FunctionTemplate::ReadOnlyPrototype() { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1205 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 1206 | if (IsDeadCheck(isolate, "v8::FunctionTemplate::ReadOnlyPrototype()")) { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1207 | return; |
| 1208 | } |
| 1209 | ENTER_V8(isolate); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1210 | Utils::OpenHandle(this)->set_read_only_prototype(true); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1214 | void FunctionTemplate::SetNamedInstancePropertyHandler( |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1215 | NamedPropertyGetter getter, |
| 1216 | NamedPropertySetter setter, |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1217 | NamedPropertyQuery query, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1218 | NamedPropertyDeleter remover, |
| 1219 | NamedPropertyEnumerator enumerator, |
| 1220 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1221 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1222 | if (IsDeadCheck(isolate, |
| 1223 | "v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1224 | return; |
| 1225 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1226 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1227 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1228 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1229 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1230 | i::Handle<i::InterceptorInfo> obj = |
| 1231 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1232 | |
| 1233 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1234 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1235 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1236 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1237 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1238 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1239 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1240 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1241 | Utils::OpenHandle(this)->set_named_property_handler(*obj); |
| 1242 | } |
| 1243 | |
| 1244 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1245 | void FunctionTemplate::SetIndexedInstancePropertyHandler( |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1246 | IndexedPropertyGetter getter, |
| 1247 | IndexedPropertySetter setter, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1248 | IndexedPropertyQuery query, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1249 | IndexedPropertyDeleter remover, |
| 1250 | IndexedPropertyEnumerator enumerator, |
| 1251 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1252 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1253 | if (IsDeadCheck(isolate, |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1254 | "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) { |
| 1255 | return; |
| 1256 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1257 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1258 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1259 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1260 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1261 | i::Handle<i::InterceptorInfo> obj = |
| 1262 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1263 | |
| 1264 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1265 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1266 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1267 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1268 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1269 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1270 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1271 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1272 | Utils::OpenHandle(this)->set_indexed_property_handler(*obj); |
| 1273 | } |
| 1274 | |
| 1275 | |
| 1276 | void FunctionTemplate::SetInstanceCallAsFunctionHandler( |
| 1277 | InvocationCallback callback, |
| 1278 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1279 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1280 | if (IsDeadCheck(isolate, |
| 1281 | "v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1282 | return; |
| 1283 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1284 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1285 | i::HandleScope scope(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1286 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1287 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1288 | i::Handle<i::CallHandlerInfo> obj = |
| 1289 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1290 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1291 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1292 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1293 | Utils::OpenHandle(this)->set_instance_call_handler(*obj); |
| 1294 | } |
| 1295 | |
| 1296 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1297 | // --- O b j e c t T e m p l a t e --- |
| 1298 | |
| 1299 | |
| 1300 | Local<ObjectTemplate> ObjectTemplate::New() { |
| 1301 | return New(Local<FunctionTemplate>()); |
| 1302 | } |
| 1303 | |
| 1304 | |
| 1305 | Local<ObjectTemplate> ObjectTemplate::New( |
| 1306 | v8::Handle<FunctionTemplate> constructor) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1307 | i::Isolate* isolate = i::Isolate::Current(); |
| 1308 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::New()")) { |
| 1309 | return Local<ObjectTemplate>(); |
| 1310 | } |
| 1311 | EnsureInitializedForIsolate(isolate, "v8::ObjectTemplate::New()"); |
| 1312 | LOG_API(isolate, "ObjectTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1313 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1314 | i::Handle<i::Struct> struct_obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1315 | isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1316 | i::Handle<i::ObjectTemplateInfo> obj = |
| 1317 | i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); |
| 1318 | InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
| 1319 | if (!constructor.IsEmpty()) |
| 1320 | obj->set_constructor(*Utils::OpenHandle(*constructor)); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1321 | obj->set_internal_field_count(i::Smi::FromInt(0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1322 | return Utils::ToLocal(obj); |
| 1323 | } |
| 1324 | |
| 1325 | |
| 1326 | // Ensure that the object template has a constructor. If no |
| 1327 | // constructor is available we create one. |
| 1328 | static void EnsureConstructor(ObjectTemplate* object_template) { |
| 1329 | if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { |
| 1330 | Local<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1331 | i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); |
| 1332 | constructor->set_instance_template(*Utils::OpenHandle(object_template)); |
| 1333 | Utils::OpenHandle(object_template)->set_constructor(*constructor); |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | |
| 1338 | void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
| 1339 | AccessorGetter getter, |
| 1340 | AccessorSetter setter, |
| 1341 | v8::Handle<Value> data, |
| 1342 | AccessControl settings, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1343 | PropertyAttribute attribute, |
| 1344 | v8::Handle<AccessorSignature> signature) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1345 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1346 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1347 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1348 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1349 | EnsureConstructor(this); |
| 1350 | i::FunctionTemplateInfo* constructor = |
| 1351 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1352 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1353 | Utils::ToLocal(cons)->AddInstancePropertyAccessor(name, |
| 1354 | getter, |
| 1355 | setter, |
| 1356 | data, |
| 1357 | settings, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1358 | attribute, |
| 1359 | signature); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1363 | void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter, |
| 1364 | NamedPropertySetter setter, |
| 1365 | NamedPropertyQuery query, |
| 1366 | NamedPropertyDeleter remover, |
| 1367 | NamedPropertyEnumerator enumerator, |
| 1368 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1369 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1370 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) { |
| 1371 | return; |
| 1372 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1373 | ENTER_V8(isolate); |
| 1374 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1375 | EnsureConstructor(this); |
| 1376 | i::FunctionTemplateInfo* constructor = |
| 1377 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1378 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1379 | Utils::ToLocal(cons)->SetNamedInstancePropertyHandler(getter, |
| 1380 | setter, |
| 1381 | query, |
| 1382 | remover, |
| 1383 | enumerator, |
| 1384 | data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | |
| 1388 | void ObjectTemplate::MarkAsUndetectable() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1389 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1390 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::MarkAsUndetectable()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1391 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1392 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1393 | EnsureConstructor(this); |
| 1394 | i::FunctionTemplateInfo* constructor = |
| 1395 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1396 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1397 | cons->set_undetectable(true); |
| 1398 | } |
| 1399 | |
| 1400 | |
| 1401 | void ObjectTemplate::SetAccessCheckCallbacks( |
| 1402 | NamedSecurityCallback named_callback, |
| 1403 | IndexedSecurityCallback indexed_callback, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1404 | Handle<Value> data, |
| 1405 | bool turned_on_by_default) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1406 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1407 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessCheckCallbacks()")) { |
| 1408 | return; |
| 1409 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1410 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1411 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1412 | EnsureConstructor(this); |
| 1413 | |
| 1414 | i::Handle<i::Struct> struct_info = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1415 | isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1416 | i::Handle<i::AccessCheckInfo> info = |
| 1417 | i::Handle<i::AccessCheckInfo>::cast(struct_info); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1418 | |
| 1419 | SET_FIELD_WRAPPED(info, set_named_callback, named_callback); |
| 1420 | SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback); |
| 1421 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1422 | if (data.IsEmpty()) data = v8::Undefined(); |
| 1423 | info->set_data(*Utils::OpenHandle(*data)); |
| 1424 | |
| 1425 | i::FunctionTemplateInfo* constructor = |
| 1426 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1427 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1428 | cons->set_access_check_info(*info); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1429 | cons->set_needs_access_check(turned_on_by_default); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1433 | void ObjectTemplate::SetIndexedPropertyHandler( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1434 | IndexedPropertyGetter getter, |
| 1435 | IndexedPropertySetter setter, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1436 | IndexedPropertyQuery query, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1437 | IndexedPropertyDeleter remover, |
| 1438 | IndexedPropertyEnumerator enumerator, |
| 1439 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1440 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1441 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetIndexedPropertyHandler()")) { |
| 1442 | return; |
| 1443 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1444 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1445 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1446 | EnsureConstructor(this); |
| 1447 | i::FunctionTemplateInfo* constructor = |
| 1448 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1449 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1450 | Utils::ToLocal(cons)->SetIndexedInstancePropertyHandler(getter, |
| 1451 | setter, |
| 1452 | query, |
| 1453 | remover, |
| 1454 | enumerator, |
| 1455 | data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | void ObjectTemplate::SetCallAsFunctionHandler(InvocationCallback callback, |
| 1460 | Handle<Value> data) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1461 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1462 | if (IsDeadCheck(isolate, |
| 1463 | "v8::ObjectTemplate::SetCallAsFunctionHandler()")) { |
| 1464 | return; |
| 1465 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1466 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1467 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1468 | EnsureConstructor(this); |
| 1469 | i::FunctionTemplateInfo* constructor = |
| 1470 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1471 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1472 | Utils::ToLocal(cons)->SetInstanceCallAsFunctionHandler(callback, data); |
| 1473 | } |
| 1474 | |
| 1475 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1476 | int ObjectTemplate::InternalFieldCount() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1477 | if (IsDeadCheck(Utils::OpenHandle(this)->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1478 | "v8::ObjectTemplate::InternalFieldCount()")) { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1479 | return 0; |
| 1480 | } |
| 1481 | return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1485 | void ObjectTemplate::SetInternalFieldCount(int value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1486 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1487 | if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetInternalFieldCount()")) { |
| 1488 | return; |
| 1489 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1490 | if (!ApiCheck(i::Smi::IsValid(value), |
| 1491 | "v8::ObjectTemplate::SetInternalFieldCount()", |
| 1492 | "Invalid internal field count")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1493 | return; |
| 1494 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1495 | ENTER_V8(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1496 | if (value > 0) { |
| 1497 | // The internal field count is set by the constructor function's |
| 1498 | // construct code, so we ensure that there is a constructor |
| 1499 | // function to do the setting. |
| 1500 | EnsureConstructor(this); |
| 1501 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1502 | Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1506 | // --- S c r i p t D a t a --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1507 | |
| 1508 | |
| 1509 | ScriptData* ScriptData::PreCompile(const char* input, int length) { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1510 | i::Utf8ToUtf16CharacterStream stream( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1511 | reinterpret_cast<const unsigned char*>(input), length); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1512 | return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_scoping); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1516 | ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { |
| 1517 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1518 | if (str->IsExternalTwoByteString()) { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1519 | i::ExternalTwoByteStringUtf16CharacterStream stream( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1520 | i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1521 | return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_scoping); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1522 | } else { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1523 | i::GenericStringUtf16CharacterStream stream(str, 0, str->length()); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1524 | return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_scoping); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1525 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1529 | ScriptData* ScriptData::New(const char* data, int length) { |
| 1530 | // Return an empty ScriptData if the length is obviously invalid. |
| 1531 | if (length % sizeof(unsigned) != 0) { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1532 | return new i::ScriptDataImpl(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | // Copy the data to ensure it is properly aligned. |
| 1536 | int deserialized_data_length = length / sizeof(unsigned); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1537 | // If aligned, don't create a copy of the data. |
| 1538 | if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) { |
| 1539 | return new i::ScriptDataImpl(data, length); |
| 1540 | } |
| 1541 | // Copy the data to align it. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1542 | unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1543 | i::OS::MemCopy(deserialized_data, data, length); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1544 | |
| 1545 | return new i::ScriptDataImpl( |
| 1546 | i::Vector<unsigned>(deserialized_data, deserialized_data_length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | |
| 1550 | // --- S c r i p t --- |
| 1551 | |
| 1552 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1553 | Local<Script> Script::New(v8::Handle<String> source, |
| 1554 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1555 | v8::ScriptData* pre_data, |
| 1556 | v8::Handle<String> script_data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1557 | i::Isolate* isolate = i::Isolate::Current(); |
| 1558 | ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>()); |
| 1559 | LOG_API(isolate, "Script::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1560 | ENTER_V8(isolate); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1561 | i::SharedFunctionInfo* raw_result = NULL; |
| 1562 | { i::HandleScope scope(isolate); |
| 1563 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1564 | i::Handle<i::Object> name_obj; |
| 1565 | int line_offset = 0; |
| 1566 | int column_offset = 0; |
| 1567 | if (origin != NULL) { |
| 1568 | if (!origin->ResourceName().IsEmpty()) { |
| 1569 | name_obj = Utils::OpenHandle(*origin->ResourceName()); |
| 1570 | } |
| 1571 | if (!origin->ResourceLineOffset().IsEmpty()) { |
| 1572 | line_offset = static_cast<int>(origin->ResourceLineOffset()->Value()); |
| 1573 | } |
| 1574 | if (!origin->ResourceColumnOffset().IsEmpty()) { |
| 1575 | column_offset = |
| 1576 | static_cast<int>(origin->ResourceColumnOffset()->Value()); |
| 1577 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1578 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1579 | EXCEPTION_PREAMBLE(isolate); |
| 1580 | i::ScriptDataImpl* pre_data_impl = |
| 1581 | static_cast<i::ScriptDataImpl*>(pre_data); |
| 1582 | // We assert that the pre-data is sane, even though we can actually |
| 1583 | // handle it if it turns out not to be in release mode. |
| 1584 | ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck()); |
| 1585 | // If the pre-data isn't sane we simply ignore it |
| 1586 | if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) { |
| 1587 | pre_data_impl = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1588 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1589 | i::Handle<i::SharedFunctionInfo> result = |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1590 | i::Compiler::Compile(str, |
| 1591 | name_obj, |
| 1592 | line_offset, |
| 1593 | column_offset, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1594 | isolate->global_context(), |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1595 | NULL, |
| 1596 | pre_data_impl, |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 1597 | Utils::OpenHandle(*script_data, true), |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1598 | i::NOT_NATIVES_CODE); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1599 | has_pending_exception = result.is_null(); |
| 1600 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); |
| 1601 | raw_result = *result; |
| 1602 | } |
| 1603 | i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1604 | return Local<Script>(ToApi<Script>(result)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | |
| 1608 | Local<Script> Script::New(v8::Handle<String> source, |
| 1609 | v8::Handle<Value> file_name) { |
| 1610 | ScriptOrigin origin(file_name); |
| 1611 | return New(source, &origin); |
| 1612 | } |
| 1613 | |
| 1614 | |
| 1615 | Local<Script> Script::Compile(v8::Handle<String> source, |
| 1616 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1617 | v8::ScriptData* pre_data, |
| 1618 | v8::Handle<String> script_data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1619 | i::Isolate* isolate = i::Isolate::Current(); |
| 1620 | ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>()); |
| 1621 | LOG_API(isolate, "Script::Compile"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1622 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1623 | Local<Script> generic = New(source, origin, pre_data, script_data); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1624 | if (generic.IsEmpty()) |
| 1625 | return generic; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1626 | i::Handle<i::Object> obj = Utils::OpenHandle(*generic); |
| 1627 | i::Handle<i::SharedFunctionInfo> function = |
| 1628 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1629 | i::Handle<i::JSFunction> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1630 | isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 1631 | function, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1632 | isolate->global_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1633 | return Local<Script>(ToApi<Script>(result)); |
| 1634 | } |
| 1635 | |
| 1636 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1637 | Local<Script> Script::Compile(v8::Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1638 | v8::Handle<Value> file_name, |
| 1639 | v8::Handle<String> script_data) { |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1640 | ScriptOrigin origin(file_name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1641 | return Compile(source, &origin, 0, script_data); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1645 | Local<Value> Script::Run() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1646 | i::Isolate* isolate = i::Isolate::Current(); |
| 1647 | ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); |
| 1648 | LOG_API(isolate, "Script::Run"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1649 | ENTER_V8(isolate); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1650 | i::Logger::TimerEventScope timer_scope( |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 1651 | isolate, i::Logger::TimerEventScope::v8_execute); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1652 | i::Object* raw_result = NULL; |
| 1653 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1654 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1655 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 1656 | i::Handle<i::JSFunction> fun; |
| 1657 | if (obj->IsSharedFunctionInfo()) { |
| 1658 | i::Handle<i::SharedFunctionInfo> |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1659 | function_info(i::SharedFunctionInfo::cast(*obj), isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1660 | fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1661 | function_info, isolate->global_context()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1662 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1663 | fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1664 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1665 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1666 | i::Handle<i::Object> receiver( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1667 | isolate->context()->global_proxy(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1668 | i::Handle<i::Object> result = |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1669 | i::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 1670 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1671 | raw_result = *result; |
| 1672 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1673 | i::Handle<i::Object> result(raw_result, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1674 | return Utils::ToLocal(result); |
| 1675 | } |
| 1676 | |
| 1677 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1678 | static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) { |
| 1679 | i::Handle<i::Object> obj = Utils::OpenHandle(script); |
| 1680 | i::Handle<i::SharedFunctionInfo> result; |
| 1681 | if (obj->IsSharedFunctionInfo()) { |
| 1682 | result = |
| 1683 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
| 1684 | } else { |
| 1685 | result = |
| 1686 | i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()); |
| 1687 | } |
| 1688 | return result; |
| 1689 | } |
| 1690 | |
| 1691 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1692 | Local<Value> Script::Id() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1693 | i::Isolate* isolate = i::Isolate::Current(); |
| 1694 | ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>()); |
| 1695 | LOG_API(isolate, "Script::Id"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1696 | i::Object* raw_id = NULL; |
| 1697 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1698 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1699 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
| 1700 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1701 | i::Handle<i::Object> id(script->id(), isolate); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1702 | raw_id = *id; |
| 1703 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1704 | i::Handle<i::Object> id(raw_id, isolate); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1705 | return Utils::ToLocal(id); |
| 1706 | } |
| 1707 | |
| 1708 | |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1709 | void Script::SetData(v8::Handle<String> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1710 | i::Isolate* isolate = i::Isolate::Current(); |
| 1711 | ON_BAILOUT(isolate, "v8::Script::SetData()", return); |
| 1712 | LOG_API(isolate, "Script::SetData"); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1713 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1714 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1715 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1716 | i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1717 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1718 | script->set_data(*raw_data); |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1723 | // --- E x c e p t i o n s --- |
| 1724 | |
| 1725 | |
| 1726 | v8::TryCatch::TryCatch() |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1727 | : isolate_(i::Isolate::Current()), |
| 1728 | next_(isolate_->try_catch_handler_address()), |
| 1729 | exception_(isolate_->heap()->the_hole_value()), |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1730 | message_(i::Smi::FromInt(0)), |
| 1731 | is_verbose_(false), |
ager@chromium.org | 68e7ab7 | 2009-09-23 09:40:39 +0000 | [diff] [blame] | 1732 | can_continue_(true), |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1733 | capture_message_(true), |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1734 | rethrow_(false) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1735 | isolate_->RegisterTryCatchHandler(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | |
| 1739 | v8::TryCatch::~TryCatch() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1740 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1741 | if (rethrow_) { |
| 1742 | v8::HandleScope scope; |
| 1743 | v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(Exception()); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1744 | isolate_->UnregisterTryCatchHandler(this); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1745 | v8::ThrowException(exc); |
| 1746 | } else { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1747 | isolate_->UnregisterTryCatchHandler(this); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1748 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1752 | bool v8::TryCatch::HasCaught() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1753 | return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(); |
| 1754 | } |
| 1755 | |
| 1756 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 1757 | bool v8::TryCatch::CanContinue() const { |
| 1758 | return can_continue_; |
| 1759 | } |
| 1760 | |
| 1761 | |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1762 | v8::Handle<v8::Value> v8::TryCatch::ReThrow() { |
| 1763 | if (!HasCaught()) return v8::Local<v8::Value>(); |
| 1764 | rethrow_ = true; |
| 1765 | return v8::Undefined(); |
| 1766 | } |
| 1767 | |
| 1768 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1769 | v8::Local<Value> v8::TryCatch::Exception() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1770 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1771 | if (HasCaught()) { |
| 1772 | // Check for out of memory exception. |
| 1773 | i::Object* exception = reinterpret_cast<i::Object*>(exception_); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1774 | return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1775 | } else { |
| 1776 | return v8::Local<Value>(); |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1781 | v8::Local<Value> v8::TryCatch::StackTrace() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1782 | ASSERT(isolate_ == i::Isolate::Current()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1783 | if (HasCaught()) { |
| 1784 | i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); |
| 1785 | if (!raw_obj->IsJSObject()) return v8::Local<Value>(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1786 | i::HandleScope scope(isolate_); |
| 1787 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 1788 | i::Handle<i::String> name = isolate_->factory()->stack_string(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1789 | if (!obj->HasProperty(*name)) return v8::Local<Value>(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1790 | i::Handle<i::Object> value = i::GetProperty(isolate_, obj, name); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1791 | if (value.is_null()) return v8::Local<Value>(); |
| 1792 | return v8::Utils::ToLocal(scope.CloseAndEscape(value)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1793 | } else { |
| 1794 | return v8::Local<Value>(); |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1799 | v8::Local<v8::Message> v8::TryCatch::Message() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1800 | ASSERT(isolate_ == i::Isolate::Current()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1801 | if (HasCaught() && message_ != i::Smi::FromInt(0)) { |
| 1802 | i::Object* message = reinterpret_cast<i::Object*>(message_); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1803 | return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1804 | } else { |
| 1805 | return v8::Local<v8::Message>(); |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1810 | void v8::TryCatch::Reset() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1811 | ASSERT(isolate_ == i::Isolate::Current()); |
| 1812 | exception_ = isolate_->heap()->the_hole_value(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1813 | message_ = i::Smi::FromInt(0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | |
| 1817 | void v8::TryCatch::SetVerbose(bool value) { |
| 1818 | is_verbose_ = value; |
| 1819 | } |
| 1820 | |
| 1821 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1822 | void v8::TryCatch::SetCaptureMessage(bool value) { |
| 1823 | capture_message_ = value; |
| 1824 | } |
| 1825 | |
| 1826 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1827 | // --- M e s s a g e --- |
| 1828 | |
| 1829 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1830 | Local<String> Message::Get() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1831 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1832 | ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1833 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1834 | HandleScope scope; |
| 1835 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1836 | i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1837 | Local<String> result = Utils::ToLocal(raw_result); |
| 1838 | return scope.Close(result); |
| 1839 | } |
| 1840 | |
| 1841 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1842 | v8::Handle<Value> Message::GetScriptResourceName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1843 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1844 | if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceName()")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1845 | return Local<String>(); |
| 1846 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1847 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1848 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1849 | i::Handle<i::JSMessageObject> message = |
| 1850 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1851 | // Return this.script.name. |
| 1852 | i::Handle<i::JSValue> script = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1853 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), |
| 1854 | isolate)); |
| 1855 | i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name(), |
| 1856 | isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1857 | return scope.Close(Utils::ToLocal(resource_name)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1861 | v8::Handle<Value> Message::GetScriptData() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1862 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1863 | if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceData()")) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1864 | return Local<Value>(); |
| 1865 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1866 | ENTER_V8(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1867 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1868 | i::Handle<i::JSMessageObject> message = |
| 1869 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1870 | // Return this.script.data. |
| 1871 | i::Handle<i::JSValue> script = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1872 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), |
| 1873 | isolate)); |
| 1874 | i::Handle<i::Object> data(i::Script::cast(script->value())->data(), isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1875 | return scope.Close(Utils::ToLocal(data)); |
| 1876 | } |
| 1877 | |
| 1878 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1879 | v8::Handle<v8::StackTrace> Message::GetStackTrace() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1880 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1881 | if (IsDeadCheck(isolate, "v8::Message::GetStackTrace()")) { |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1882 | return Local<v8::StackTrace>(); |
| 1883 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1884 | ENTER_V8(isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1885 | HandleScope scope; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1886 | i::Handle<i::JSMessageObject> message = |
| 1887 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1888 | i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1889 | if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); |
| 1890 | i::Handle<i::JSArray> stackTrace = |
| 1891 | i::Handle<i::JSArray>::cast(stackFramesObj); |
| 1892 | return scope.Close(Utils::StackTraceToLocal(stackTrace)); |
| 1893 | } |
| 1894 | |
| 1895 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1896 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 1897 | i::Handle<i::Object> recv, |
| 1898 | int argc, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1899 | i::Handle<i::Object> argv[], |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1900 | bool* has_pending_exception) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1901 | i::Isolate* isolate = i::Isolate::Current(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 1902 | i::Handle<i::String> fmt_str = |
| 1903 | isolate->factory()->InternalizeUtf8String(name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1904 | i::Object* object_fun = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1905 | isolate->js_builtins_object()->GetPropertyNoExceptionThrown(*fmt_str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1906 | i::Handle<i::JSFunction> fun = |
| 1907 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun)); |
| 1908 | i::Handle<i::Object> value = |
| 1909 | i::Execution::Call(fun, recv, argc, argv, has_pending_exception); |
| 1910 | return value; |
| 1911 | } |
| 1912 | |
| 1913 | |
| 1914 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 1915 | i::Handle<i::Object> data, |
| 1916 | bool* has_pending_exception) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1917 | i::Handle<i::Object> argv[] = { data }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1918 | return CallV8HeapFunction(name, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1919 | i::Isolate::Current()->js_builtins_object(), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1920 | ARRAY_SIZE(argv), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1921 | argv, |
| 1922 | has_pending_exception); |
| 1923 | } |
| 1924 | |
| 1925 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1926 | int Message::GetLineNumber() 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 | ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1929 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1930 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1931 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1932 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1933 | i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber", |
| 1934 | Utils::OpenHandle(this), |
| 1935 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1936 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1937 | return static_cast<int>(result->Number()); |
| 1938 | } |
| 1939 | |
| 1940 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1941 | int Message::GetStartPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1942 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1943 | if (IsDeadCheck(isolate, "v8::Message::GetStartPosition()")) return 0; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1944 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1945 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1946 | i::Handle<i::JSMessageObject> message = |
| 1947 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1948 | return message->start_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1952 | int Message::GetEndPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1953 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1954 | if (IsDeadCheck(isolate, "v8::Message::GetEndPosition()")) return 0; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1955 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1956 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1957 | i::Handle<i::JSMessageObject> message = |
| 1958 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1959 | return message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1963 | int Message::GetStartColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1964 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1965 | if (IsDeadCheck(isolate, "v8::Message::GetStartColumn()")) { |
| 1966 | return kNoColumnInfo; |
| 1967 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1968 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1969 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1970 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1971 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1972 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 1973 | "GetPositionInLine", |
| 1974 | data_obj, |
| 1975 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1976 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1977 | return static_cast<int>(start_col_obj->Number()); |
| 1978 | } |
| 1979 | |
| 1980 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1981 | int Message::GetEndColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1982 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1983 | if (IsDeadCheck(isolate, "v8::Message::GetEndColumn()")) return kNoColumnInfo; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1984 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1985 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1986 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1987 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1988 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 1989 | "GetPositionInLine", |
| 1990 | data_obj, |
| 1991 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1992 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1993 | i::Handle<i::JSMessageObject> message = |
| 1994 | i::Handle<i::JSMessageObject>::cast(data_obj); |
| 1995 | int start = message->start_position(); |
| 1996 | int end = message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1997 | return static_cast<int>(start_col_obj->Number()) + (end - start); |
| 1998 | } |
| 1999 | |
| 2000 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2001 | Local<String> Message::GetSourceLine() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2002 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2003 | ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2004 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2005 | HandleScope scope; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2006 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2007 | i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine", |
| 2008 | Utils::OpenHandle(this), |
| 2009 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2010 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::String>()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2011 | if (result->IsString()) { |
| 2012 | return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result))); |
| 2013 | } else { |
| 2014 | return Local<String>(); |
| 2015 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2019 | void Message::PrintCurrentStackTrace(FILE* out) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2020 | i::Isolate* isolate = i::Isolate::Current(); |
| 2021 | if (IsDeadCheck(isolate, "v8::Message::PrintCurrentStackTrace()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2022 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2023 | isolate->PrintCurrentStackTrace(out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2027 | // --- S t a c k T r a c e --- |
| 2028 | |
| 2029 | Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2030 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2031 | if (IsDeadCheck(isolate, "v8::StackTrace::GetFrame()")) { |
| 2032 | return Local<StackFrame>(); |
| 2033 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2034 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2035 | HandleScope scope; |
| 2036 | i::Handle<i::JSArray> self = Utils::OpenHandle(this); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2037 | i::Object* raw_object = self->GetElementNoExceptionThrown(index); |
| 2038 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2039 | return scope.Close(Utils::StackFrameToLocal(obj)); |
| 2040 | } |
| 2041 | |
| 2042 | |
| 2043 | int StackTrace::GetFrameCount() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2044 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2045 | if (IsDeadCheck(isolate, "v8::StackTrace::GetFrameCount()")) return -1; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2046 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2047 | return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); |
| 2048 | } |
| 2049 | |
| 2050 | |
| 2051 | Local<Array> StackTrace::AsArray() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2052 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2053 | if (IsDeadCheck(isolate, "v8::StackTrace::AsArray()")) Local<Array>(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2054 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2055 | return Utils::ToLocal(Utils::OpenHandle(this)); |
| 2056 | } |
| 2057 | |
| 2058 | |
| 2059 | Local<StackTrace> StackTrace::CurrentStackTrace(int frame_limit, |
| 2060 | StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2061 | i::Isolate* isolate = i::Isolate::Current(); |
| 2062 | if (IsDeadCheck(isolate, "v8::StackTrace::CurrentStackTrace()")) { |
| 2063 | Local<StackTrace>(); |
| 2064 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2065 | ENTER_V8(isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2066 | i::Handle<i::JSArray> stackTrace = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2067 | isolate->CaptureCurrentStackTrace(frame_limit, options); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2068 | return Utils::StackTraceToLocal(stackTrace); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | |
| 2072 | // --- S t a c k F r a m e --- |
| 2073 | |
| 2074 | int StackFrame::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2075 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2076 | if (IsDeadCheck(isolate, "v8::StackFrame::GetLineNumber()")) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2077 | return Message::kNoLineNumberInfo; |
| 2078 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2079 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2080 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2081 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2082 | i::Handle<i::Object> line = GetProperty(self, "lineNumber"); |
| 2083 | if (!line->IsSmi()) { |
| 2084 | return Message::kNoLineNumberInfo; |
| 2085 | } |
| 2086 | return i::Smi::cast(*line)->value(); |
| 2087 | } |
| 2088 | |
| 2089 | |
| 2090 | int StackFrame::GetColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2091 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2092 | if (IsDeadCheck(isolate, "v8::StackFrame::GetColumn()")) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2093 | return Message::kNoColumnInfo; |
| 2094 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2095 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2096 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2097 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2098 | i::Handle<i::Object> column = GetProperty(self, "column"); |
| 2099 | if (!column->IsSmi()) { |
| 2100 | return Message::kNoColumnInfo; |
| 2101 | } |
| 2102 | return i::Smi::cast(*column)->value(); |
| 2103 | } |
| 2104 | |
| 2105 | |
| 2106 | Local<String> StackFrame::GetScriptName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2107 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2108 | if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptName()")) { |
| 2109 | return Local<String>(); |
| 2110 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2111 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2112 | HandleScope scope; |
| 2113 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2114 | i::Handle<i::Object> name = GetProperty(self, "scriptName"); |
| 2115 | if (!name->IsString()) { |
| 2116 | return Local<String>(); |
| 2117 | } |
| 2118 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2119 | } |
| 2120 | |
| 2121 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2122 | Local<String> StackFrame::GetScriptNameOrSourceURL() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2123 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2124 | if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptNameOrSourceURL()")) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2125 | return Local<String>(); |
| 2126 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2127 | ENTER_V8(isolate); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2128 | HandleScope scope; |
| 2129 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2130 | i::Handle<i::Object> name = GetProperty(self, "scriptNameOrSourceURL"); |
| 2131 | if (!name->IsString()) { |
| 2132 | return Local<String>(); |
| 2133 | } |
| 2134 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2135 | } |
| 2136 | |
| 2137 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2138 | Local<String> StackFrame::GetFunctionName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2139 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2140 | if (IsDeadCheck(isolate, "v8::StackFrame::GetFunctionName()")) { |
| 2141 | return Local<String>(); |
| 2142 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2143 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2144 | HandleScope scope; |
| 2145 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2146 | i::Handle<i::Object> name = GetProperty(self, "functionName"); |
| 2147 | if (!name->IsString()) { |
| 2148 | return Local<String>(); |
| 2149 | } |
| 2150 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2151 | } |
| 2152 | |
| 2153 | |
| 2154 | bool StackFrame::IsEval() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2155 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2156 | if (IsDeadCheck(isolate, "v8::StackFrame::IsEval()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2157 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2158 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2159 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2160 | i::Handle<i::Object> is_eval = GetProperty(self, "isEval"); |
| 2161 | return is_eval->IsTrue(); |
| 2162 | } |
| 2163 | |
| 2164 | |
| 2165 | bool StackFrame::IsConstructor() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2166 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2167 | if (IsDeadCheck(isolate, "v8::StackFrame::IsConstructor()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2168 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2169 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2170 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2171 | i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor"); |
| 2172 | return is_constructor->IsTrue(); |
| 2173 | } |
| 2174 | |
| 2175 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2176 | // --- D a t a --- |
| 2177 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2178 | bool Value::FullIsUndefined() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2179 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUndefined()")) { |
| 2180 | return false; |
| 2181 | } |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2182 | bool result = Utils::OpenHandle(this)->IsUndefined(); |
| 2183 | ASSERT_EQ(result, QuickIsUndefined()); |
| 2184 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2188 | bool Value::FullIsNull() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2189 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNull()")) return false; |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2190 | bool result = Utils::OpenHandle(this)->IsNull(); |
| 2191 | ASSERT_EQ(result, QuickIsNull()); |
| 2192 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2196 | bool Value::IsTrue() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2197 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsTrue()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2198 | return Utils::OpenHandle(this)->IsTrue(); |
| 2199 | } |
| 2200 | |
| 2201 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2202 | bool Value::IsFalse() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2203 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFalse()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2204 | return Utils::OpenHandle(this)->IsFalse(); |
| 2205 | } |
| 2206 | |
| 2207 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2208 | bool Value::IsFunction() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2209 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFunction()")) { |
| 2210 | return false; |
| 2211 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2212 | return Utils::OpenHandle(this)->IsJSFunction(); |
| 2213 | } |
| 2214 | |
| 2215 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2216 | bool Value::FullIsString() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2217 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsString()")) return false; |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2218 | bool result = Utils::OpenHandle(this)->IsString(); |
| 2219 | ASSERT_EQ(result, QuickIsString()); |
| 2220 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2224 | bool Value::IsArray() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2225 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArray()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2226 | return Utils::OpenHandle(this)->IsJSArray(); |
| 2227 | } |
| 2228 | |
| 2229 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2230 | bool Value::IsObject() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2231 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2232 | return Utils::OpenHandle(this)->IsJSObject(); |
| 2233 | } |
| 2234 | |
| 2235 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2236 | bool Value::IsNumber() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2237 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2238 | return Utils::OpenHandle(this)->IsNumber(); |
| 2239 | } |
| 2240 | |
| 2241 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2242 | bool Value::IsBoolean() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2243 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsBoolean()")) { |
| 2244 | return false; |
| 2245 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2246 | return Utils::OpenHandle(this)->IsBoolean(); |
| 2247 | } |
| 2248 | |
| 2249 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2250 | bool Value::IsExternal() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2251 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsExternal()")) { |
| 2252 | return false; |
| 2253 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2254 | return Utils::OpenHandle(this)->IsExternal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2258 | bool Value::IsInt32() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2259 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsInt32()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2260 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2261 | if (obj->IsSmi()) return true; |
| 2262 | if (obj->IsNumber()) { |
| 2263 | double value = obj->Number(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2264 | static const i::DoubleRepresentation minus_zero(-0.0); |
| 2265 | i::DoubleRepresentation rep(value); |
| 2266 | if (rep.bits == minus_zero.bits) { |
| 2267 | return false; |
| 2268 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2269 | return i::FastI2D(i::FastD2I(value)) == value; |
| 2270 | } |
| 2271 | return false; |
| 2272 | } |
| 2273 | |
| 2274 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2275 | bool Value::IsUint32() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2276 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUint32()")) return false; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2277 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2278 | if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0; |
| 2279 | if (obj->IsNumber()) { |
| 2280 | double value = obj->Number(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2281 | static const i::DoubleRepresentation minus_zero(-0.0); |
| 2282 | i::DoubleRepresentation rep(value); |
| 2283 | if (rep.bits == minus_zero.bits) { |
| 2284 | return false; |
| 2285 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2286 | return i::FastUI2D(i::FastD2UI(value)) == value; |
| 2287 | } |
| 2288 | return false; |
| 2289 | } |
| 2290 | |
| 2291 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2292 | bool Value::IsDate() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2293 | i::Isolate* isolate = i::Isolate::Current(); |
| 2294 | if (IsDeadCheck(isolate, "v8::Value::IsDate()")) return false; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2295 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 2296 | return obj->HasSpecificClassOf(isolate->heap()->Date_string()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2300 | bool Value::IsStringObject() const { |
| 2301 | i::Isolate* isolate = i::Isolate::Current(); |
| 2302 | if (IsDeadCheck(isolate, "v8::Value::IsStringObject()")) return false; |
| 2303 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 2304 | return obj->HasSpecificClassOf(isolate->heap()->String_string()); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | |
| 2308 | bool Value::IsNumberObject() const { |
| 2309 | i::Isolate* isolate = i::Isolate::Current(); |
| 2310 | if (IsDeadCheck(isolate, "v8::Value::IsNumberObject()")) return false; |
| 2311 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 2312 | return obj->HasSpecificClassOf(isolate->heap()->Number_string()); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | |
| 2316 | static i::Object* LookupBuiltin(i::Isolate* isolate, |
| 2317 | const char* builtin_name) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 2318 | i::Handle<i::String> string = |
| 2319 | isolate->factory()->InternalizeUtf8String(builtin_name); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2320 | i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 2321 | return builtins->GetPropertyNoExceptionThrown(*string); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | |
| 2325 | static bool CheckConstructor(i::Isolate* isolate, |
| 2326 | i::Handle<i::JSObject> obj, |
| 2327 | const char* class_name) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2328 | i::Object* constr = obj->map()->constructor(); |
| 2329 | if (!constr->IsJSFunction()) return false; |
| 2330 | i::JSFunction* func = i::JSFunction::cast(constr); |
| 2331 | return func->shared()->native() && |
| 2332 | constr == LookupBuiltin(isolate, class_name); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | |
| 2336 | bool Value::IsNativeError() const { |
| 2337 | i::Isolate* isolate = i::Isolate::Current(); |
| 2338 | if (IsDeadCheck(isolate, "v8::Value::IsNativeError()")) return false; |
| 2339 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2340 | if (obj->IsJSObject()) { |
| 2341 | i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj)); |
| 2342 | return CheckConstructor(isolate, js_obj, "$Error") || |
| 2343 | CheckConstructor(isolate, js_obj, "$EvalError") || |
| 2344 | CheckConstructor(isolate, js_obj, "$RangeError") || |
| 2345 | CheckConstructor(isolate, js_obj, "$ReferenceError") || |
| 2346 | CheckConstructor(isolate, js_obj, "$SyntaxError") || |
| 2347 | CheckConstructor(isolate, js_obj, "$TypeError") || |
| 2348 | CheckConstructor(isolate, js_obj, "$URIError"); |
| 2349 | } else { |
| 2350 | return false; |
| 2351 | } |
| 2352 | } |
| 2353 | |
| 2354 | |
| 2355 | bool Value::IsBooleanObject() const { |
| 2356 | i::Isolate* isolate = i::Isolate::Current(); |
| 2357 | if (IsDeadCheck(isolate, "v8::Value::IsBooleanObject()")) return false; |
| 2358 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 2359 | return obj->HasSpecificClassOf(isolate->heap()->Boolean_string()); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2363 | bool Value::IsRegExp() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2364 | if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsRegExp()")) return false; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2365 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2366 | return obj->IsJSRegExp(); |
| 2367 | } |
| 2368 | |
| 2369 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2370 | Local<String> Value::ToString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2371 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2372 | i::Handle<i::Object> str; |
| 2373 | if (obj->IsString()) { |
| 2374 | str = obj; |
| 2375 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2376 | i::Isolate* isolate = i::Isolate::Current(); |
| 2377 | if (IsDeadCheck(isolate, "v8::Value::ToString()")) { |
| 2378 | return Local<String>(); |
| 2379 | } |
| 2380 | LOG_API(isolate, "ToString"); |
| 2381 | ENTER_V8(isolate); |
| 2382 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2383 | str = i::Execution::ToString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2384 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2385 | } |
| 2386 | return Local<String>(ToApi<String>(str)); |
| 2387 | } |
| 2388 | |
| 2389 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2390 | Local<String> Value::ToDetailString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2391 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2392 | i::Handle<i::Object> str; |
| 2393 | if (obj->IsString()) { |
| 2394 | str = obj; |
| 2395 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2396 | i::Isolate* isolate = i::Isolate::Current(); |
| 2397 | if (IsDeadCheck(isolate, "v8::Value::ToDetailString()")) { |
| 2398 | return Local<String>(); |
| 2399 | } |
| 2400 | LOG_API(isolate, "ToDetailString"); |
| 2401 | ENTER_V8(isolate); |
| 2402 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2403 | str = i::Execution::ToDetailString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2404 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2405 | } |
| 2406 | return Local<String>(ToApi<String>(str)); |
| 2407 | } |
| 2408 | |
| 2409 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2410 | Local<v8::Object> Value::ToObject() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2411 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2412 | i::Handle<i::Object> val; |
| 2413 | if (obj->IsJSObject()) { |
| 2414 | val = obj; |
| 2415 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2416 | i::Isolate* isolate = i::Isolate::Current(); |
| 2417 | if (IsDeadCheck(isolate, "v8::Value::ToObject()")) { |
| 2418 | return Local<v8::Object>(); |
| 2419 | } |
| 2420 | LOG_API(isolate, "ToObject"); |
| 2421 | ENTER_V8(isolate); |
| 2422 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2423 | val = i::Execution::ToObject(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2424 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2425 | } |
| 2426 | return Local<v8::Object>(ToApi<Object>(val)); |
| 2427 | } |
| 2428 | |
| 2429 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2430 | Local<Boolean> Value::ToBoolean() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2431 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2432 | if (obj->IsBoolean()) { |
| 2433 | return Local<Boolean>(ToApi<Boolean>(obj)); |
| 2434 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2435 | i::Isolate* isolate = i::Isolate::Current(); |
| 2436 | if (IsDeadCheck(isolate, "v8::Value::ToBoolean()")) { |
| 2437 | return Local<Boolean>(); |
| 2438 | } |
| 2439 | LOG_API(isolate, "ToBoolean"); |
| 2440 | ENTER_V8(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2441 | i::Handle<i::Object> val = i::Execution::ToBoolean(isolate, obj); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2442 | return Local<Boolean>(ToApi<Boolean>(val)); |
| 2443 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2447 | Local<Number> Value::ToNumber() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2448 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2449 | i::Handle<i::Object> num; |
| 2450 | if (obj->IsNumber()) { |
| 2451 | num = obj; |
| 2452 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2453 | i::Isolate* isolate = i::Isolate::Current(); |
| 2454 | if (IsDeadCheck(isolate, "v8::Value::ToNumber()")) { |
| 2455 | return Local<Number>(); |
| 2456 | } |
| 2457 | LOG_API(isolate, "ToNumber"); |
| 2458 | ENTER_V8(isolate); |
| 2459 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2460 | num = i::Execution::ToNumber(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2461 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Number>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2462 | } |
| 2463 | return Local<Number>(ToApi<Number>(num)); |
| 2464 | } |
| 2465 | |
| 2466 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2467 | Local<Integer> Value::ToInteger() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2468 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2469 | i::Handle<i::Object> num; |
| 2470 | if (obj->IsSmi()) { |
| 2471 | num = obj; |
| 2472 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2473 | i::Isolate* isolate = i::Isolate::Current(); |
| 2474 | if (IsDeadCheck(isolate, "v8::Value::ToInteger()")) return Local<Integer>(); |
| 2475 | LOG_API(isolate, "ToInteger"); |
| 2476 | ENTER_V8(isolate); |
| 2477 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2478 | num = i::Execution::ToInteger(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2479 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2480 | } |
| 2481 | return Local<Integer>(ToApi<Integer>(num)); |
| 2482 | } |
| 2483 | |
| 2484 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2485 | void External::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2486 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Cast()")) return; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2487 | ApiCheck(Utils::OpenHandle(that)->IsExternal(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2488 | "v8::External::Cast()", |
| 2489 | "Could not convert to external"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2493 | void v8::Object::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2494 | if (IsDeadCheck(i::Isolate::Current(), "v8::Object::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2495 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2496 | ApiCheck(obj->IsJSObject(), |
| 2497 | "v8::Object::Cast()", |
| 2498 | "Could not convert to object"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2502 | void v8::Function::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2503 | if (IsDeadCheck(i::Isolate::Current(), "v8::Function::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2504 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2505 | ApiCheck(obj->IsJSFunction(), |
| 2506 | "v8::Function::Cast()", |
| 2507 | "Could not convert to function"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2511 | void v8::String::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2512 | if (IsDeadCheck(i::Isolate::Current(), "v8::String::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2513 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2514 | ApiCheck(obj->IsString(), |
| 2515 | "v8::String::Cast()", |
| 2516 | "Could not convert to string"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2520 | void v8::Number::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2521 | if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2522 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2523 | ApiCheck(obj->IsNumber(), |
| 2524 | "v8::Number::Cast()", |
| 2525 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2529 | void v8::Integer::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2530 | if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2531 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2532 | ApiCheck(obj->IsNumber(), |
| 2533 | "v8::Integer::Cast()", |
| 2534 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2538 | void v8::Array::CheckCast(Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2539 | if (IsDeadCheck(i::Isolate::Current(), "v8::Array::Cast()")) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2540 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2541 | ApiCheck(obj->IsJSArray(), |
| 2542 | "v8::Array::Cast()", |
| 2543 | "Could not convert to array"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2547 | void v8::Date::CheckCast(v8::Value* that) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2548 | i::Isolate* isolate = i::Isolate::Current(); |
| 2549 | if (IsDeadCheck(isolate, "v8::Date::Cast()")) return; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2550 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 2551 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_string()), |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2552 | "v8::Date::Cast()", |
| 2553 | "Could not convert to date"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2557 | void v8::StringObject::CheckCast(v8::Value* that) { |
| 2558 | i::Isolate* isolate = i::Isolate::Current(); |
| 2559 | if (IsDeadCheck(isolate, "v8::StringObject::Cast()")) return; |
| 2560 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 2561 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->String_string()), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2562 | "v8::StringObject::Cast()", |
| 2563 | "Could not convert to StringObject"); |
| 2564 | } |
| 2565 | |
| 2566 | |
| 2567 | void v8::NumberObject::CheckCast(v8::Value* that) { |
| 2568 | i::Isolate* isolate = i::Isolate::Current(); |
| 2569 | if (IsDeadCheck(isolate, "v8::NumberObject::Cast()")) return; |
| 2570 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 2571 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Number_string()), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2572 | "v8::NumberObject::Cast()", |
| 2573 | "Could not convert to NumberObject"); |
| 2574 | } |
| 2575 | |
| 2576 | |
| 2577 | void v8::BooleanObject::CheckCast(v8::Value* that) { |
| 2578 | i::Isolate* isolate = i::Isolate::Current(); |
| 2579 | if (IsDeadCheck(isolate, "v8::BooleanObject::Cast()")) return; |
| 2580 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 2581 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Boolean_string()), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2582 | "v8::BooleanObject::Cast()", |
| 2583 | "Could not convert to BooleanObject"); |
| 2584 | } |
| 2585 | |
| 2586 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2587 | void v8::RegExp::CheckCast(v8::Value* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2588 | if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::Cast()")) return; |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2589 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2590 | ApiCheck(obj->IsJSRegExp(), |
| 2591 | "v8::RegExp::Cast()", |
| 2592 | "Could not convert to regular expression"); |
| 2593 | } |
| 2594 | |
| 2595 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2596 | bool Value::BooleanValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2597 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2598 | if (obj->IsBoolean()) { |
| 2599 | return obj->IsTrue(); |
| 2600 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2601 | i::Isolate* isolate = i::Isolate::Current(); |
| 2602 | if (IsDeadCheck(isolate, "v8::Value::BooleanValue()")) return false; |
| 2603 | LOG_API(isolate, "BooleanValue"); |
| 2604 | ENTER_V8(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2605 | i::Handle<i::Object> value = i::Execution::ToBoolean(isolate, obj); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2606 | return value->IsTrue(); |
| 2607 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2611 | double Value::NumberValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2612 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2613 | i::Handle<i::Object> num; |
| 2614 | if (obj->IsNumber()) { |
| 2615 | num = obj; |
| 2616 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2617 | i::Isolate* isolate = i::Isolate::Current(); |
| 2618 | if (IsDeadCheck(isolate, "v8::Value::NumberValue()")) { |
| 2619 | return i::OS::nan_value(); |
| 2620 | } |
| 2621 | LOG_API(isolate, "NumberValue"); |
| 2622 | ENTER_V8(isolate); |
| 2623 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2624 | num = i::Execution::ToNumber(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2625 | EXCEPTION_BAILOUT_CHECK(isolate, i::OS::nan_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2626 | } |
| 2627 | return num->Number(); |
| 2628 | } |
| 2629 | |
| 2630 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2631 | int64_t Value::IntegerValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2632 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2633 | i::Handle<i::Object> num; |
| 2634 | if (obj->IsNumber()) { |
| 2635 | num = obj; |
| 2636 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2637 | i::Isolate* isolate = i::Isolate::Current(); |
| 2638 | if (IsDeadCheck(isolate, "v8::Value::IntegerValue()")) return 0; |
| 2639 | LOG_API(isolate, "IntegerValue"); |
| 2640 | ENTER_V8(isolate); |
| 2641 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2642 | num = i::Execution::ToInteger(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2643 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2644 | } |
| 2645 | if (num->IsSmi()) { |
| 2646 | return i::Smi::cast(*num)->value(); |
| 2647 | } else { |
| 2648 | return static_cast<int64_t>(num->Number()); |
| 2649 | } |
| 2650 | } |
| 2651 | |
| 2652 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2653 | Local<Int32> Value::ToInt32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2654 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2655 | i::Handle<i::Object> num; |
| 2656 | if (obj->IsSmi()) { |
| 2657 | num = obj; |
| 2658 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2659 | i::Isolate* isolate = i::Isolate::Current(); |
| 2660 | if (IsDeadCheck(isolate, "v8::Value::ToInt32()")) return Local<Int32>(); |
| 2661 | LOG_API(isolate, "ToInt32"); |
| 2662 | ENTER_V8(isolate); |
| 2663 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2664 | num = i::Execution::ToInt32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2665 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Int32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2666 | } |
| 2667 | return Local<Int32>(ToApi<Int32>(num)); |
| 2668 | } |
| 2669 | |
| 2670 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2671 | Local<Uint32> Value::ToUint32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2672 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2673 | i::Handle<i::Object> num; |
| 2674 | if (obj->IsSmi()) { |
| 2675 | num = obj; |
| 2676 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2677 | i::Isolate* isolate = i::Isolate::Current(); |
| 2678 | if (IsDeadCheck(isolate, "v8::Value::ToUint32()")) return Local<Uint32>(); |
| 2679 | LOG_API(isolate, "ToUInt32"); |
| 2680 | ENTER_V8(isolate); |
| 2681 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2682 | num = i::Execution::ToUint32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2683 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2684 | } |
| 2685 | return Local<Uint32>(ToApi<Uint32>(num)); |
| 2686 | } |
| 2687 | |
| 2688 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2689 | Local<Uint32> Value::ToArrayIndex() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2690 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2691 | if (obj->IsSmi()) { |
| 2692 | if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj); |
| 2693 | return Local<Uint32>(); |
| 2694 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2695 | i::Isolate* isolate = i::Isolate::Current(); |
| 2696 | if (IsDeadCheck(isolate, "v8::Value::ToArrayIndex()")) return Local<Uint32>(); |
| 2697 | LOG_API(isolate, "ToArrayIndex"); |
| 2698 | ENTER_V8(isolate); |
| 2699 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2700 | i::Handle<i::Object> string_obj = |
| 2701 | i::Execution::ToString(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2702 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2703 | i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); |
| 2704 | uint32_t index; |
| 2705 | if (str->AsArrayIndex(&index)) { |
| 2706 | i::Handle<i::Object> value; |
| 2707 | if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2708 | value = i::Handle<i::Object>(i::Smi::FromInt(index), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2709 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2710 | value = isolate->factory()->NewNumber(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2711 | } |
| 2712 | return Utils::Uint32ToLocal(value); |
| 2713 | } |
| 2714 | return Local<Uint32>(); |
| 2715 | } |
| 2716 | |
| 2717 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2718 | int32_t Value::Int32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2719 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2720 | if (obj->IsSmi()) { |
| 2721 | return i::Smi::cast(*obj)->value(); |
| 2722 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2723 | i::Isolate* isolate = i::Isolate::Current(); |
| 2724 | if (IsDeadCheck(isolate, "v8::Value::Int32Value()")) return 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2725 | LOG_API(isolate, "Int32Value (slow)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2726 | ENTER_V8(isolate); |
| 2727 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2728 | i::Handle<i::Object> num = |
| 2729 | i::Execution::ToInt32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2730 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2731 | if (num->IsSmi()) { |
| 2732 | return i::Smi::cast(*num)->value(); |
| 2733 | } else { |
| 2734 | return static_cast<int32_t>(num->Number()); |
| 2735 | } |
| 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2740 | bool Value::Equals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2741 | i::Isolate* isolate = i::Isolate::Current(); |
| 2742 | if (IsDeadCheck(isolate, "v8::Value::Equals()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2743 | || EmptyCheck("v8::Value::Equals()", this) |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2744 | || EmptyCheck("v8::Value::Equals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2745 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2746 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2747 | LOG_API(isolate, "Equals"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2748 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2749 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2750 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2751 | // If both obj and other are JSObjects, we'd better compare by identity |
| 2752 | // immediately when going into JS builtin. The reason is Invoke |
| 2753 | // would overwrite global object receiver with global proxy. |
| 2754 | if (obj->IsJSObject() && other->IsJSObject()) { |
| 2755 | return *obj == *other; |
| 2756 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2757 | i::Handle<i::Object> args[] = { other }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2758 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2759 | i::Handle<i::Object> result = |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2760 | CallV8HeapFunction("EQUALS", obj, ARRAY_SIZE(args), args, |
| 2761 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2762 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2763 | return *result == i::Smi::FromInt(i::EQUAL); |
| 2764 | } |
| 2765 | |
| 2766 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2767 | bool Value::StrictEquals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2768 | i::Isolate* isolate = i::Isolate::Current(); |
| 2769 | if (IsDeadCheck(isolate, "v8::Value::StrictEquals()") |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2770 | || EmptyCheck("v8::Value::StrictEquals()", this) |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2771 | || EmptyCheck("v8::Value::StrictEquals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2772 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2773 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2774 | LOG_API(isolate, "StrictEquals"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2775 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2776 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
| 2777 | // Must check HeapNumber first, since NaN !== NaN. |
| 2778 | if (obj->IsHeapNumber()) { |
| 2779 | if (!other->IsNumber()) return false; |
| 2780 | double x = obj->Number(); |
| 2781 | double y = other->Number(); |
| 2782 | // Must check explicitly for NaN:s on Windows, but -0 works fine. |
| 2783 | return x == y && !isnan(x) && !isnan(y); |
| 2784 | } else if (*obj == *other) { // Also covers Booleans. |
| 2785 | return true; |
| 2786 | } else if (obj->IsSmi()) { |
| 2787 | return other->IsNumber() && obj->Number() == other->Number(); |
| 2788 | } else if (obj->IsString()) { |
| 2789 | return other->IsString() && |
| 2790 | i::String::cast(*obj)->Equals(i::String::cast(*other)); |
| 2791 | } else if (obj->IsUndefined() || obj->IsUndetectableObject()) { |
| 2792 | return other->IsUndefined() || other->IsUndetectableObject(); |
| 2793 | } else { |
| 2794 | return false; |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2799 | uint32_t Value::Uint32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2800 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2801 | if (obj->IsSmi()) { |
| 2802 | return i::Smi::cast(*obj)->value(); |
| 2803 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2804 | i::Isolate* isolate = i::Isolate::Current(); |
| 2805 | if (IsDeadCheck(isolate, "v8::Value::Uint32Value()")) return 0; |
| 2806 | LOG_API(isolate, "Uint32Value"); |
| 2807 | ENTER_V8(isolate); |
| 2808 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2809 | i::Handle<i::Object> num = |
| 2810 | i::Execution::ToUint32(obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2811 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2812 | if (num->IsSmi()) { |
| 2813 | return i::Smi::cast(*num)->value(); |
| 2814 | } else { |
| 2815 | return static_cast<uint32_t>(num->Number()); |
| 2816 | } |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | |
| 2821 | 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] | 2822 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2823 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2824 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2825 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2826 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2827 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 2828 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2829 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2830 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2831 | i::Handle<i::Object> obj = i::SetProperty( |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2832 | isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2833 | self, |
| 2834 | key_obj, |
| 2835 | value_obj, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2836 | static_cast<PropertyAttributes>(attribs), |
| 2837 | i::kNonStrictMode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2838 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2839 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2840 | return true; |
| 2841 | } |
| 2842 | |
| 2843 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2844 | bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2845 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2846 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2847 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2848 | i::HandleScope scope(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2849 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2850 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2851 | EXCEPTION_PREAMBLE(isolate); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2852 | i::Handle<i::Object> obj = i::JSObject::SetElement( |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2853 | self, |
| 2854 | index, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2855 | value_obj, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2856 | NONE, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2857 | i::kNonStrictMode); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2858 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2859 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2860 | return true; |
| 2861 | } |
| 2862 | |
| 2863 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2864 | bool v8::Object::ForceSet(v8::Handle<Value> key, |
| 2865 | v8::Handle<Value> value, |
| 2866 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2867 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2868 | ON_BAILOUT(isolate, "v8::Object::ForceSet()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2869 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2870 | i::HandleScope scope(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2871 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2872 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2873 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2874 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2875 | i::Handle<i::Object> obj = i::ForceSetProperty( |
| 2876 | self, |
| 2877 | key_obj, |
| 2878 | value_obj, |
| 2879 | static_cast<PropertyAttributes>(attribs)); |
| 2880 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2881 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2882 | return true; |
| 2883 | } |
| 2884 | |
| 2885 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2886 | bool v8::Object::ForceDelete(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2887 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2888 | ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2889 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2890 | i::HandleScope scope(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2891 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2892 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2893 | |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 2894 | // When deleting a property on the global object using ForceDelete |
| 2895 | // deoptimize all functions as optimized code does not check for the hole |
| 2896 | // value with DontDelete properties. We have to deoptimize all contexts |
| 2897 | // because of possible cross-context inlined functions. |
| 2898 | if (self->IsJSGlobalProxy() || self->IsGlobalObject()) { |
| 2899 | i::Deoptimizer::DeoptimizeAll(); |
| 2900 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2901 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2902 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2903 | i::Handle<i::Object> obj = i::ForceDeleteProperty(self, key_obj); |
| 2904 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2905 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2906 | return obj->IsTrue(); |
| 2907 | } |
| 2908 | |
| 2909 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2910 | Local<Value> v8::Object::Get(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2911 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2912 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2913 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2914 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 2915 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2916 | EXCEPTION_PREAMBLE(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2917 | i::Handle<i::Object> result = i::GetProperty(isolate, self, key_obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2918 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2919 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2920 | return Utils::ToLocal(result); |
| 2921 | } |
| 2922 | |
| 2923 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2924 | Local<Value> v8::Object::Get(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2925 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2926 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2927 | ENTER_V8(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2928 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2929 | EXCEPTION_PREAMBLE(isolate); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2930 | i::Handle<i::Object> result = i::Object::GetElement(self, index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2931 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2932 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2933 | return Utils::ToLocal(result); |
| 2934 | } |
| 2935 | |
| 2936 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2937 | PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { |
| 2938 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2939 | ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()", |
| 2940 | return static_cast<PropertyAttribute>(NONE)); |
| 2941 | ENTER_V8(isolate); |
| 2942 | i::HandleScope scope(isolate); |
| 2943 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2944 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 2945 | if (!key_obj->IsString()) { |
| 2946 | EXCEPTION_PREAMBLE(isolate); |
| 2947 | key_obj = i::Execution::ToString(key_obj, &has_pending_exception); |
| 2948 | EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE)); |
| 2949 | } |
| 2950 | i::Handle<i::String> key_string = i::Handle<i::String>::cast(key_obj); |
| 2951 | PropertyAttributes result = self->GetPropertyAttribute(*key_string); |
| 2952 | if (result == ABSENT) return static_cast<PropertyAttribute>(NONE); |
| 2953 | return static_cast<PropertyAttribute>(result); |
| 2954 | } |
| 2955 | |
| 2956 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2957 | Local<Value> v8::Object::GetPrototype() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2958 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2959 | ON_BAILOUT(isolate, "v8::Object::GetPrototype()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2960 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2961 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2962 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2963 | i::Handle<i::Object> result(self->GetPrototype(isolate), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2964 | return Utils::ToLocal(result); |
| 2965 | } |
| 2966 | |
| 2967 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2968 | bool v8::Object::SetPrototype(Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2969 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2970 | ON_BAILOUT(isolate, "v8::Object::SetPrototype()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2971 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2972 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2973 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2974 | // We do not allow exceptions thrown while setting the prototype |
| 2975 | // to propagate outside. |
| 2976 | TryCatch try_catch; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2977 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2978 | i::Handle<i::Object> result = i::SetPrototype(self, value_obj); |
| 2979 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2980 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2981 | return true; |
| 2982 | } |
| 2983 | |
| 2984 | |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2985 | Local<Object> v8::Object::FindInstanceInPrototypeChain( |
| 2986 | v8::Handle<FunctionTemplate> tmpl) { |
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, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2989 | "v8::Object::FindInstanceInPrototypeChain()", |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2990 | return Local<v8::Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2991 | ENTER_V8(isolate); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 2992 | i::JSObject* object = *Utils::OpenHandle(this); |
| 2993 | i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl); |
| 2994 | while (!object->IsInstanceOf(tmpl_info)) { |
| 2995 | i::Object* prototype = object->GetPrototype(); |
| 2996 | if (!prototype->IsJSObject()) return Local<Object>(); |
| 2997 | object = i::JSObject::cast(prototype); |
| 2998 | } |
| 2999 | return Utils::ToLocal(i::Handle<i::JSObject>(object)); |
| 3000 | } |
| 3001 | |
| 3002 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3003 | Local<Array> v8::Object::GetPropertyNames() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3004 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3005 | ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()", |
| 3006 | return Local<v8::Array>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3007 | ENTER_V8(isolate); |
| 3008 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3009 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3010 | bool threw = false; |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3011 | i::Handle<i::FixedArray> value = |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3012 | i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS, &threw); |
| 3013 | if (threw) return Local<v8::Array>(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3014 | // Because we use caching to speed up enumeration it is important |
| 3015 | // to never change the result of the basic enumeration function so |
| 3016 | // we clone the result. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3017 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 3018 | i::Handle<i::JSArray> result = |
| 3019 | isolate->factory()->NewJSArrayWithElements(elms); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3020 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3024 | Local<Array> v8::Object::GetOwnPropertyNames() { |
| 3025 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3026 | ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()", |
| 3027 | return Local<v8::Array>()); |
| 3028 | ENTER_V8(isolate); |
| 3029 | i::HandleScope scope(isolate); |
| 3030 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3031 | bool threw = false; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3032 | i::Handle<i::FixedArray> value = |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3033 | i::GetKeysInFixedArrayFor(self, i::LOCAL_ONLY, &threw); |
| 3034 | if (threw) return Local<v8::Array>(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3035 | // Because we use caching to speed up enumeration it is important |
| 3036 | // to never change the result of the basic enumeration function so |
| 3037 | // we clone the result. |
| 3038 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 3039 | i::Handle<i::JSArray> result = |
| 3040 | isolate->factory()->NewJSArrayWithElements(elms); |
| 3041 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
| 3042 | } |
| 3043 | |
| 3044 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3045 | Local<String> v8::Object::ObjectProtoToString() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3046 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3047 | ON_BAILOUT(isolate, "v8::Object::ObjectProtoToString()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3048 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3049 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3050 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3051 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3052 | i::Handle<i::Object> name(self->class_name(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3053 | |
| 3054 | // Native implementation of Object.prototype.toString (v8natives.js): |
| 3055 | // var c = %ClassOf(this); |
| 3056 | // if (c === 'Arguments') c = 'Object'; |
| 3057 | // return "[object " + c + "]"; |
| 3058 | |
| 3059 | if (!name->IsString()) { |
| 3060 | return v8::String::New("[object ]"); |
| 3061 | |
| 3062 | } else { |
| 3063 | i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3064 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Arguments"))) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3065 | return v8::String::New("[object Object]"); |
| 3066 | |
| 3067 | } else { |
| 3068 | const char* prefix = "[object "; |
| 3069 | Local<String> str = Utils::ToLocal(class_name); |
| 3070 | const char* postfix = "]"; |
| 3071 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3072 | int prefix_len = i::StrLength(prefix); |
| 3073 | int str_len = str->Length(); |
| 3074 | int postfix_len = i::StrLength(postfix); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3075 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3076 | int buf_len = prefix_len + str_len + postfix_len; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3077 | i::ScopedVector<char> buf(buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3078 | |
| 3079 | // Write prefix. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3080 | char* ptr = buf.start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3081 | memcpy(ptr, prefix, prefix_len * v8::internal::kCharSize); |
| 3082 | ptr += prefix_len; |
| 3083 | |
| 3084 | // Write real content. |
| 3085 | str->WriteAscii(ptr, 0, str_len); |
| 3086 | ptr += str_len; |
| 3087 | |
| 3088 | // Write postfix. |
| 3089 | memcpy(ptr, postfix, postfix_len * v8::internal::kCharSize); |
| 3090 | |
| 3091 | // Copy the buffer into a heap-allocated string and return it. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3092 | Local<String> result = v8::String::New(buf.start(), buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3093 | return result; |
| 3094 | } |
| 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 3099 | Local<Value> v8::Object::GetConstructor() { |
| 3100 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3101 | ON_BAILOUT(isolate, "v8::Object::GetConstructor()", |
| 3102 | return Local<v8::Function>()); |
| 3103 | ENTER_V8(isolate); |
| 3104 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3105 | i::Handle<i::Object> constructor(self->GetConstructor(), isolate); |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 3106 | return Utils::ToLocal(constructor); |
| 3107 | } |
| 3108 | |
| 3109 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 3110 | Local<String> v8::Object::GetConstructorName() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3111 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3112 | ON_BAILOUT(isolate, "v8::Object::GetConstructorName()", |
| 3113 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3114 | ENTER_V8(isolate); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 3115 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3116 | i::Handle<i::String> name(self->constructor_name()); |
| 3117 | return Utils::ToLocal(name); |
| 3118 | } |
| 3119 | |
| 3120 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3121 | bool v8::Object::Delete(v8::Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3122 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3123 | ON_BAILOUT(isolate, "v8::Object::Delete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3124 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3125 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3126 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3127 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3128 | return i::JSObject::DeleteProperty(self, key_obj)->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | |
| 3132 | bool v8::Object::Has(v8::Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3133 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3134 | ON_BAILOUT(isolate, "v8::Object::Has()", return false); |
| 3135 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3136 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3137 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
| 3138 | return self->HasProperty(*key_obj); |
| 3139 | } |
| 3140 | |
| 3141 | |
| 3142 | bool v8::Object::Delete(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3143 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3144 | ON_BAILOUT(isolate, "v8::Object::DeleteProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3145 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3146 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3147 | HandleScope scope; |
| 3148 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3149 | return i::JSObject::DeleteElement(self, index)->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | |
| 3153 | bool v8::Object::Has(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3154 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3155 | ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3156 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3157 | return self->HasElement(index); |
| 3158 | } |
| 3159 | |
| 3160 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3161 | bool Object::SetAccessor(Handle<String> name, |
| 3162 | AccessorGetter getter, |
| 3163 | AccessorSetter setter, |
| 3164 | v8::Handle<Value> data, |
| 3165 | AccessControl settings, |
| 3166 | PropertyAttribute attributes) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3167 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3168 | ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3169 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3170 | i::HandleScope scope(isolate); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3171 | v8::Handle<AccessorSignature> signature; |
| 3172 | i::Handle<i::AccessorInfo> info = MakeAccessorInfo(name, getter, setter, data, |
| 3173 | settings, attributes, |
| 3174 | signature); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 3175 | bool fast = Utils::OpenHandle(this)->HasFastProperties(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3176 | i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(this), info); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 3177 | if (result.is_null() || result->IsUndefined()) return false; |
| 3178 | if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(this), 0); |
| 3179 | return true; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3183 | bool v8::Object::HasOwnProperty(Handle<String> key) { |
| 3184 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3185 | ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", |
| 3186 | return false); |
| 3187 | return Utils::OpenHandle(this)->HasLocalProperty( |
| 3188 | *Utils::OpenHandle(*key)); |
| 3189 | } |
| 3190 | |
| 3191 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3192 | bool v8::Object::HasRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3193 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3194 | ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3195 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3196 | return Utils::OpenHandle(this)->HasRealNamedProperty( |
| 3197 | *Utils::OpenHandle(*key)); |
| 3198 | } |
| 3199 | |
| 3200 | |
| 3201 | bool v8::Object::HasRealIndexedProperty(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3202 | ON_BAILOUT(Utils::OpenHandle(this)->GetIsolate(), |
| 3203 | "v8::Object::HasRealIndexedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3204 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3205 | return Utils::OpenHandle(this)->HasRealElementProperty(index); |
| 3206 | } |
| 3207 | |
| 3208 | |
| 3209 | bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3210 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3211 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3212 | "v8::Object::HasRealNamedCallbackProperty()", |
| 3213 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3214 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3215 | return Utils::OpenHandle(this)->HasRealNamedCallbackProperty( |
| 3216 | *Utils::OpenHandle(*key)); |
| 3217 | } |
| 3218 | |
| 3219 | |
| 3220 | bool v8::Object::HasNamedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3221 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3222 | ON_BAILOUT(isolate, "v8::Object::HasNamedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3223 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3224 | return Utils::OpenHandle(this)->HasNamedInterceptor(); |
| 3225 | } |
| 3226 | |
| 3227 | |
| 3228 | bool v8::Object::HasIndexedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3229 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3230 | ON_BAILOUT(isolate, "v8::Object::HasIndexedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3231 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3232 | return Utils::OpenHandle(this)->HasIndexedInterceptor(); |
| 3233 | } |
| 3234 | |
| 3235 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3236 | static Local<Value> GetPropertyByLookup(i::Isolate* isolate, |
| 3237 | i::Handle<i::JSObject> receiver, |
| 3238 | i::Handle<i::String> name, |
| 3239 | i::LookupResult* lookup) { |
| 3240 | if (!lookup->IsProperty()) { |
| 3241 | // No real property was found. |
| 3242 | return Local<Value>(); |
| 3243 | } |
| 3244 | |
| 3245 | // If the property being looked up is a callback, it can throw |
| 3246 | // an exception. |
| 3247 | EXCEPTION_PREAMBLE(isolate); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3248 | PropertyAttributes ignored; |
| 3249 | i::Handle<i::Object> result = |
| 3250 | i::Object::GetProperty(receiver, receiver, lookup, name, |
| 3251 | &ignored); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3252 | has_pending_exception = result.is_null(); |
| 3253 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3254 | |
| 3255 | return Utils::ToLocal(result); |
| 3256 | } |
| 3257 | |
| 3258 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3259 | Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3260 | Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3261 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3262 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3263 | "v8::Object::GetRealNamedPropertyInPrototypeChain()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3264 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3265 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3266 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3267 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3268 | i::LookupResult lookup(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3269 | self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3270 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3274 | Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3275 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3276 | ON_BAILOUT(isolate, "v8::Object::GetRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3277 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3278 | ENTER_V8(isolate); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3279 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3280 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3281 | i::LookupResult lookup(isolate); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3282 | self_obj->LookupRealNamedProperty(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3283 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3284 | } |
| 3285 | |
| 3286 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3287 | // Turns on access checks by copying the map and setting the check flag. |
| 3288 | // Because the object gets a new map, existing inline cache caching |
| 3289 | // the old map of this object will fail. |
| 3290 | void v8::Object::TurnOnAccessCheck() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3291 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3292 | ON_BAILOUT(isolate, "v8::Object::TurnOnAccessCheck()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3293 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3294 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3295 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3296 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3297 | // When turning on access checks for a global object deoptimize all functions |
| 3298 | // as optimized code does not always handle access checks. |
| 3299 | i::Deoptimizer::DeoptimizeGlobalObject(*obj); |
| 3300 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3301 | i::Handle<i::Map> new_map = |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3302 | isolate->factory()->CopyMap(i::Handle<i::Map>(obj->map())); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3303 | new_map->set_is_access_check_needed(true); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3304 | obj->set_map(*new_map); |
| 3305 | } |
| 3306 | |
| 3307 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3308 | bool v8::Object::IsDirty() { |
| 3309 | return Utils::OpenHandle(this)->IsDirty(); |
| 3310 | } |
| 3311 | |
| 3312 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3313 | Local<v8::Object> v8::Object::Clone() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3314 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3315 | ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3316 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3317 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3318 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3319 | i::Handle<i::JSObject> result = i::Copy(self); |
| 3320 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3321 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3322 | return Utils::ToLocal(result); |
| 3323 | } |
| 3324 | |
| 3325 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3326 | static i::Context* GetCreationContext(i::JSObject* object) { |
| 3327 | i::Object* constructor = object->map()->constructor(); |
| 3328 | i::JSFunction* function; |
| 3329 | if (!constructor->IsJSFunction()) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3330 | // Functions have null as a constructor, |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3331 | // but any JSFunction knows its context immediately. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3332 | ASSERT(object->IsJSFunction()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3333 | function = i::JSFunction::cast(object); |
| 3334 | } else { |
| 3335 | function = i::JSFunction::cast(constructor); |
| 3336 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3337 | return function->context()->native_context(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | |
| 3341 | Local<v8::Context> v8::Object::CreationContext() { |
| 3342 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3343 | ON_BAILOUT(isolate, |
| 3344 | "v8::Object::CreationContext()", return Local<v8::Context>()); |
| 3345 | ENTER_V8(isolate); |
| 3346 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3347 | i::Context* context = GetCreationContext(*self); |
| 3348 | return Utils::ToLocal(i::Handle<i::Context>(context)); |
| 3349 | } |
| 3350 | |
| 3351 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3352 | int v8::Object::GetIdentityHash() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3353 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3354 | ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3355 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3356 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3357 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3358 | return i::JSObject::GetIdentityHash(self); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | |
| 3362 | bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, |
| 3363 | v8::Handle<v8::Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3364 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3365 | ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 3366 | if (value.IsEmpty()) return DeleteHiddenValue(key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3367 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3368 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3369 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3370 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 3371 | i::Handle<i::String> key_string = |
| 3372 | isolate->factory()->InternalizeString(key_obj); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3373 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3374 | i::Handle<i::Object> result = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 3375 | i::JSObject::SetHiddenProperty(self, key_string, value_obj); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3376 | return *result == *self; |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | |
| 3380 | 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] | 3381 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3382 | ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()", |
| 3383 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3384 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3385 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3386 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 3387 | i::Handle<i::String> key_string = FACTORY->InternalizeString(key_obj); |
| 3388 | i::Handle<i::Object> result(self->GetHiddenProperty(*key_string), isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3389 | if (result->IsUndefined()) return v8::Local<v8::Value>(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3390 | return Utils::ToLocal(result); |
| 3391 | } |
| 3392 | |
| 3393 | |
| 3394 | bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3395 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3396 | ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3397 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3398 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3399 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3400 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 3401 | i::Handle<i::String> key_string = FACTORY->InternalizeString(key_obj); |
| 3402 | self->DeleteHiddenProperty(*key_string); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3403 | return true; |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3407 | namespace { |
| 3408 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3409 | static i::ElementsKind GetElementsKindFromExternalArrayType( |
| 3410 | ExternalArrayType array_type) { |
| 3411 | switch (array_type) { |
| 3412 | case kExternalByteArray: |
| 3413 | return i::EXTERNAL_BYTE_ELEMENTS; |
| 3414 | break; |
| 3415 | case kExternalUnsignedByteArray: |
| 3416 | return i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS; |
| 3417 | break; |
| 3418 | case kExternalShortArray: |
| 3419 | return i::EXTERNAL_SHORT_ELEMENTS; |
| 3420 | break; |
| 3421 | case kExternalUnsignedShortArray: |
| 3422 | return i::EXTERNAL_UNSIGNED_SHORT_ELEMENTS; |
| 3423 | break; |
| 3424 | case kExternalIntArray: |
| 3425 | return i::EXTERNAL_INT_ELEMENTS; |
| 3426 | break; |
| 3427 | case kExternalUnsignedIntArray: |
| 3428 | return i::EXTERNAL_UNSIGNED_INT_ELEMENTS; |
| 3429 | break; |
| 3430 | case kExternalFloatArray: |
| 3431 | return i::EXTERNAL_FLOAT_ELEMENTS; |
| 3432 | break; |
| 3433 | case kExternalDoubleArray: |
| 3434 | return i::EXTERNAL_DOUBLE_ELEMENTS; |
| 3435 | break; |
| 3436 | case kExternalPixelArray: |
| 3437 | return i::EXTERNAL_PIXEL_ELEMENTS; |
| 3438 | break; |
| 3439 | } |
| 3440 | UNREACHABLE(); |
| 3441 | return i::DICTIONARY_ELEMENTS; |
| 3442 | } |
| 3443 | |
| 3444 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3445 | void PrepareExternalArrayElements(i::Handle<i::JSObject> object, |
| 3446 | void* data, |
| 3447 | ExternalArrayType array_type, |
| 3448 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3449 | i::Isolate* isolate = object->GetIsolate(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3450 | i::Handle<i::ExternalArray> array = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3451 | isolate->factory()->NewExternalArray(length, array_type, data); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3452 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3453 | i::Handle<i::Map> external_array_map = |
| 3454 | isolate->factory()->GetElementsTransitionMap( |
| 3455 | object, |
| 3456 | GetElementsKindFromExternalArrayType(array_type)); |
| 3457 | |
| 3458 | object->set_map(*external_array_map); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3459 | object->set_elements(*array); |
| 3460 | } |
| 3461 | |
| 3462 | } // namespace |
| 3463 | |
| 3464 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3465 | void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3466 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3467 | ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3468 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3469 | i::HandleScope scope(isolate); |
danno@chromium.org | 412fa51 | 2012-09-14 13:28:26 +0000 | [diff] [blame] | 3470 | if (!ApiCheck(length >= 0 && length <= i::ExternalPixelArray::kMaxLength, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3471 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3472 | "length exceeds max acceptable value")) { |
| 3473 | return; |
| 3474 | } |
| 3475 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3476 | if (!ApiCheck(!self->IsJSArray(), |
| 3477 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3478 | "JSArray is not supported")) { |
| 3479 | return; |
| 3480 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3481 | PrepareExternalArrayElements(self, data, kExternalPixelArray, length); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3485 | bool v8::Object::HasIndexedPropertiesInPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3486 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3487 | ON_BAILOUT(self->GetIsolate(), "v8::HasIndexedPropertiesInPixelData()", |
| 3488 | return false); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3489 | return self->HasExternalPixelElements(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | |
| 3493 | uint8_t* v8::Object::GetIndexedPropertiesPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3494 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3495 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelData()", |
| 3496 | return NULL); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3497 | if (self->HasExternalPixelElements()) { |
| 3498 | return i::ExternalPixelArray::cast(self->elements())-> |
| 3499 | external_pixel_pointer(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3500 | } else { |
| 3501 | return NULL; |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | |
| 3506 | int v8::Object::GetIndexedPropertiesPixelDataLength() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3507 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3508 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelDataLength()", |
| 3509 | return -1); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3510 | if (self->HasExternalPixelElements()) { |
| 3511 | return i::ExternalPixelArray::cast(self->elements())->length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3512 | } else { |
| 3513 | return -1; |
| 3514 | } |
| 3515 | } |
| 3516 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3517 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3518 | void v8::Object::SetIndexedPropertiesToExternalArrayData( |
| 3519 | void* data, |
| 3520 | ExternalArrayType array_type, |
| 3521 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3522 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3523 | ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3524 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3525 | i::HandleScope scope(isolate); |
danno@chromium.org | 412fa51 | 2012-09-14 13:28:26 +0000 | [diff] [blame] | 3526 | if (!ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength, |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3527 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3528 | "length exceeds max acceptable value")) { |
| 3529 | return; |
| 3530 | } |
| 3531 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3532 | if (!ApiCheck(!self->IsJSArray(), |
| 3533 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3534 | "JSArray is not supported")) { |
| 3535 | return; |
| 3536 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3537 | PrepareExternalArrayElements(self, data, array_type, length); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3541 | bool v8::Object::HasIndexedPropertiesInExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3542 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3543 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3544 | "v8::HasIndexedPropertiesInExternalArrayData()", |
| 3545 | return false); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3546 | return self->HasExternalArrayElements(); |
| 3547 | } |
| 3548 | |
| 3549 | |
| 3550 | void* v8::Object::GetIndexedPropertiesExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3551 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3552 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3553 | "v8::GetIndexedPropertiesExternalArrayData()", |
| 3554 | return NULL); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3555 | if (self->HasExternalArrayElements()) { |
| 3556 | return i::ExternalArray::cast(self->elements())->external_pointer(); |
| 3557 | } else { |
| 3558 | return NULL; |
| 3559 | } |
| 3560 | } |
| 3561 | |
| 3562 | |
| 3563 | ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3564 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3565 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3566 | "v8::GetIndexedPropertiesExternalArrayDataType()", |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3567 | return static_cast<ExternalArrayType>(-1)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3568 | switch (self->elements()->map()->instance_type()) { |
| 3569 | case i::EXTERNAL_BYTE_ARRAY_TYPE: |
| 3570 | return kExternalByteArray; |
| 3571 | case i::EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 3572 | return kExternalUnsignedByteArray; |
| 3573 | case i::EXTERNAL_SHORT_ARRAY_TYPE: |
| 3574 | return kExternalShortArray; |
| 3575 | case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 3576 | return kExternalUnsignedShortArray; |
| 3577 | case i::EXTERNAL_INT_ARRAY_TYPE: |
| 3578 | return kExternalIntArray; |
| 3579 | case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 3580 | return kExternalUnsignedIntArray; |
| 3581 | case i::EXTERNAL_FLOAT_ARRAY_TYPE: |
| 3582 | return kExternalFloatArray; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3583 | case i::EXTERNAL_DOUBLE_ARRAY_TYPE: |
| 3584 | return kExternalDoubleArray; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3585 | case i::EXTERNAL_PIXEL_ARRAY_TYPE: |
| 3586 | return kExternalPixelArray; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3587 | default: |
| 3588 | return static_cast<ExternalArrayType>(-1); |
| 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | |
| 3593 | int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3594 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3595 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3596 | "v8::GetIndexedPropertiesExternalArrayDataLength()", |
| 3597 | return 0); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3598 | if (self->HasExternalArrayElements()) { |
| 3599 | return i::ExternalArray::cast(self->elements())->length(); |
| 3600 | } else { |
| 3601 | return -1; |
| 3602 | } |
| 3603 | } |
| 3604 | |
| 3605 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3606 | bool v8::Object::IsCallable() { |
| 3607 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3608 | ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false); |
| 3609 | ENTER_V8(isolate); |
| 3610 | i::HandleScope scope(isolate); |
| 3611 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3612 | if (obj->IsJSFunction()) return true; |
| 3613 | return i::Execution::GetFunctionDelegate(obj)->IsJSFunction(); |
| 3614 | } |
| 3615 | |
| 3616 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3617 | Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Object> recv, |
| 3618 | int argc, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3619 | v8::Handle<v8::Value> argv[]) { |
| 3620 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3621 | ON_BAILOUT(isolate, "v8::Object::CallAsFunction()", |
| 3622 | return Local<v8::Value>()); |
| 3623 | LOG_API(isolate, "Object::CallAsFunction"); |
| 3624 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3625 | i::Logger::TimerEventScope timer_scope( |
| 3626 | isolate, i::Logger::TimerEventScope::v8_execute); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3627 | i::HandleScope scope(isolate); |
| 3628 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3629 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3630 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3631 | i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3632 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(); |
| 3633 | if (obj->IsJSFunction()) { |
| 3634 | fun = i::Handle<i::JSFunction>::cast(obj); |
| 3635 | } else { |
| 3636 | EXCEPTION_PREAMBLE(isolate); |
| 3637 | i::Handle<i::Object> delegate = |
| 3638 | i::Execution::TryGetFunctionDelegate(obj, &has_pending_exception); |
| 3639 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3640 | fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3641 | recv_obj = obj; |
| 3642 | } |
| 3643 | EXCEPTION_PREAMBLE(isolate); |
| 3644 | i::Handle<i::Object> returned = |
| 3645 | i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3646 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3647 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3648 | } |
| 3649 | |
| 3650 | |
| 3651 | Local<v8::Value> Object::CallAsConstructor(int argc, |
| 3652 | v8::Handle<v8::Value> argv[]) { |
| 3653 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3654 | ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()", |
| 3655 | return Local<v8::Object>()); |
| 3656 | LOG_API(isolate, "Object::CallAsConstructor"); |
| 3657 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3658 | i::Logger::TimerEventScope timer_scope( |
| 3659 | isolate, i::Logger::TimerEventScope::v8_execute); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3660 | i::HandleScope scope(isolate); |
| 3661 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3662 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3663 | i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3664 | if (obj->IsJSFunction()) { |
| 3665 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj); |
| 3666 | EXCEPTION_PREAMBLE(isolate); |
| 3667 | i::Handle<i::Object> returned = |
| 3668 | i::Execution::New(fun, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3669 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3670 | return Utils::ToLocal(scope.CloseAndEscape( |
| 3671 | i::Handle<i::JSObject>::cast(returned))); |
| 3672 | } |
| 3673 | EXCEPTION_PREAMBLE(isolate); |
| 3674 | i::Handle<i::Object> delegate = |
| 3675 | i::Execution::TryGetConstructorDelegate(obj, &has_pending_exception); |
| 3676 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3677 | if (!delegate->IsUndefined()) { |
| 3678 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3679 | EXCEPTION_PREAMBLE(isolate); |
| 3680 | i::Handle<i::Object> returned = |
| 3681 | i::Execution::Call(fun, obj, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3682 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3683 | ASSERT(!delegate->IsUndefined()); |
| 3684 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3685 | } |
| 3686 | return Local<v8::Object>(); |
| 3687 | } |
| 3688 | |
| 3689 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3690 | Local<v8::Object> Function::NewInstance() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3691 | return NewInstance(0, NULL); |
| 3692 | } |
| 3693 | |
| 3694 | |
| 3695 | Local<v8::Object> Function::NewInstance(int argc, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3696 | v8::Handle<v8::Value> argv[]) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3697 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3698 | ON_BAILOUT(isolate, "v8::Function::NewInstance()", |
| 3699 | return Local<v8::Object>()); |
| 3700 | LOG_API(isolate, "Function::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3701 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3702 | i::Logger::TimerEventScope timer_scope( |
| 3703 | isolate, i::Logger::TimerEventScope::v8_execute); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3704 | HandleScope scope; |
| 3705 | i::Handle<i::JSFunction> function = Utils::OpenHandle(this); |
| 3706 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3707 | i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3708 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3709 | i::Handle<i::Object> returned = |
| 3710 | i::Execution::New(function, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3711 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3712 | return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned))); |
| 3713 | } |
| 3714 | |
| 3715 | |
| 3716 | Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc, |
| 3717 | v8::Handle<v8::Value> argv[]) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3718 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3719 | ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>()); |
| 3720 | LOG_API(isolate, "Function::Call"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3721 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3722 | i::Logger::TimerEventScope timer_scope( |
| 3723 | isolate, i::Logger::TimerEventScope::v8_execute); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3724 | i::Object* raw_result = NULL; |
| 3725 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3726 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3727 | i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); |
| 3728 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3729 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3730 | i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3731 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3732 | i::Handle<i::Object> returned = |
| 3733 | i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3734 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3735 | raw_result = *returned; |
| 3736 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3737 | i::Handle<i::Object> result(raw_result, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3738 | return Utils::ToLocal(result); |
| 3739 | } |
| 3740 | |
| 3741 | |
| 3742 | void Function::SetName(v8::Handle<v8::String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3743 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3744 | ENTER_V8(isolate); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3745 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3746 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3747 | func->shared()->set_name(*Utils::OpenHandle(*name)); |
| 3748 | } |
| 3749 | |
| 3750 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3751 | Handle<Value> Function::GetName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3752 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3753 | return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(), |
| 3754 | func->GetIsolate())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3758 | Handle<Value> Function::GetInferredName() const { |
| 3759 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3760 | return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(), |
| 3761 | func->GetIsolate())); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3765 | ScriptOrigin Function::GetScriptOrigin() const { |
| 3766 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3767 | if (func->shared()->script()->IsScript()) { |
| 3768 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3769 | i::Handle<i::Object> scriptName = GetScriptNameOrSourceURL(script); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3770 | v8::ScriptOrigin origin( |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3771 | Utils::ToLocal(scriptName), |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3772 | v8::Integer::New(script->line_offset()->value()), |
| 3773 | v8::Integer::New(script->column_offset()->value())); |
| 3774 | return origin; |
| 3775 | } |
| 3776 | return v8::ScriptOrigin(Handle<Value>()); |
| 3777 | } |
| 3778 | |
| 3779 | |
| 3780 | const int Function::kLineOffsetNotFound = -1; |
| 3781 | |
| 3782 | |
| 3783 | int Function::GetScriptLineNumber() const { |
| 3784 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3785 | if (func->shared()->script()->IsScript()) { |
| 3786 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 3787 | return i::GetScriptLineNumber(script, func->shared()->start_position()); |
| 3788 | } |
| 3789 | return kLineOffsetNotFound; |
| 3790 | } |
| 3791 | |
| 3792 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3793 | int Function::GetScriptColumnNumber() const { |
| 3794 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3795 | if (func->shared()->script()->IsScript()) { |
| 3796 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 3797 | return i::GetScriptColumnNumber(script, func->shared()->start_position()); |
| 3798 | } |
| 3799 | return kLineOffsetNotFound; |
| 3800 | } |
| 3801 | |
| 3802 | Handle<Value> Function::GetScriptId() const { |
| 3803 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 3804 | if (!func->shared()->script()->IsScript()) |
| 3805 | return v8::Undefined(); |
| 3806 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3807 | return Utils::ToLocal(i::Handle<i::Object>(script->id(), func->GetIsolate())); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3810 | int String::Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3811 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3812 | if (IsDeadCheck(str->GetIsolate(), "v8::String::Length()")) return 0; |
| 3813 | return str->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3816 | bool String::MayContainNonAscii() const { |
| 3817 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3818 | if (IsDeadCheck(str->GetIsolate(), "v8::String::MayContainNonAscii()")) { |
| 3819 | return false; |
| 3820 | } |
| 3821 | return !str->HasOnlyAsciiChars(); |
| 3822 | } |
| 3823 | |
| 3824 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3825 | bool String::IsOneByte() const { |
| 3826 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3827 | if (IsDeadCheck(str->GetIsolate(), "v8::String::IsOneByte()")) { |
| 3828 | return false; |
| 3829 | } |
| 3830 | return str->IsOneByteConvertible(); |
| 3831 | } |
| 3832 | |
| 3833 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 3834 | class Utf8LengthVisitor { |
| 3835 | public: |
| 3836 | explicit Utf8LengthVisitor() |
| 3837 | : utf8_length_(0), |
| 3838 | last_character_(unibrow::Utf16::kNoPreviousCharacter) {} |
| 3839 | |
| 3840 | inline int GetLength() { |
| 3841 | return utf8_length_; |
| 3842 | } |
| 3843 | |
| 3844 | template<typename Char> |
| 3845 | inline void Visit(const Char* chars, unsigned length) { |
| 3846 | ASSERT(length > 0); |
| 3847 | // TODO(dcarney) Add back ascii fast path. |
| 3848 | int utf8_length = 0; |
| 3849 | int last_character = last_character_; |
| 3850 | for (unsigned i = 0; i < length; i++) { |
| 3851 | uint16_t c = chars[i]; |
| 3852 | utf8_length += unibrow::Utf8::Length(c, last_character); |
| 3853 | last_character = c; |
| 3854 | } |
| 3855 | last_character_ = last_character; |
| 3856 | utf8_length_ += utf8_length; |
| 3857 | } |
| 3858 | |
| 3859 | inline void VisitOneByteString(const uint8_t* chars, unsigned length) { |
| 3860 | Visit(chars, length); |
| 3861 | } |
| 3862 | |
| 3863 | inline void VisitTwoByteString(const uint16_t* chars, unsigned length) { |
| 3864 | Visit(chars, length); |
| 3865 | } |
| 3866 | |
| 3867 | private: |
| 3868 | int utf8_length_; |
| 3869 | int last_character_; |
| 3870 | DISALLOW_COPY_AND_ASSIGN(Utf8LengthVisitor); |
| 3871 | }; |
| 3872 | |
| 3873 | |
| 3874 | static int Utf8Length(i::String* str, i::Isolate* isolate) { |
| 3875 | unsigned length = static_cast<unsigned>(str->length()); |
| 3876 | if (length == 0) return 0; |
| 3877 | int32_t type = str->map()->instance_type(); |
| 3878 | Utf8LengthVisitor visitor; |
| 3879 | // Non ConsString branch. |
| 3880 | if ((type & i::kStringRepresentationMask) != i::kConsStringTag) { |
| 3881 | i::ConsStringNullOp null_op; |
| 3882 | i::String::Visit(str, 0, visitor, null_op, type, length); |
| 3883 | return visitor.GetLength(); |
| 3884 | } |
| 3885 | i::ConsStringIteratorOp* op = isolate->write_iterator(); |
| 3886 | unsigned offset = 0; |
| 3887 | i::String* leaf = op->Operate(str, &offset, &type, &length); |
| 3888 | ASSERT(leaf != NULL); |
| 3889 | while (leaf != NULL) { |
| 3890 | i::ConsStringNullOp null_op; |
| 3891 | ASSERT(offset == 0); |
| 3892 | i::String::Visit(leaf, 0, visitor, null_op, type, length); |
| 3893 | leaf = op->ContinueOperation(&type, &length); |
| 3894 | } |
| 3895 | return visitor.GetLength(); |
| 3896 | } |
| 3897 | |
| 3898 | |
| 3899 | int String::Utf8Length() const { |
| 3900 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3901 | i::Isolate* isolate = str->GetIsolate(); |
| 3902 | if (IsDeadCheck(isolate, "v8::String::Utf8Length()")) return 0; |
| 3903 | return v8::Utf8Length(*str, isolate); |
| 3904 | } |
| 3905 | |
| 3906 | |
| 3907 | class Utf8WriterVisitor { |
| 3908 | public: |
| 3909 | Utf8WriterVisitor(char* buffer, int capacity) |
| 3910 | : early_termination_(false), |
| 3911 | last_character_(unibrow::Utf16::kNoPreviousCharacter), |
| 3912 | buffer_(buffer), |
| 3913 | start_(buffer), |
| 3914 | capacity_(capacity), |
| 3915 | utf16_chars_read_(0) { |
| 3916 | } |
| 3917 | |
| 3918 | static int WriteEndCharacter(uint16_t character, |
| 3919 | int last_character, |
| 3920 | int remaining, |
| 3921 | char* const buffer) { |
| 3922 | using namespace unibrow; |
| 3923 | ASSERT(remaining > 0); |
| 3924 | // We can't use a local buffer here because Encode needs to modify |
| 3925 | // previous characters in the stream. We know, however, that |
| 3926 | // exactly one character will be advanced. |
| 3927 | if (Utf16::IsTrailSurrogate(character) && |
| 3928 | Utf16::IsLeadSurrogate(last_character)) { |
| 3929 | int written = Utf8::Encode(buffer, character, last_character); |
| 3930 | ASSERT(written == 1); |
| 3931 | return written; |
| 3932 | } |
| 3933 | // Use a scratch buffer to check the required characters. |
| 3934 | char temp_buffer[Utf8::kMaxEncodedSize]; |
| 3935 | // Can't encode using last_character as gcc has array bounds issues. |
| 3936 | int written = Utf8::Encode(temp_buffer, |
| 3937 | character, |
| 3938 | unibrow::Utf16::kNoPreviousCharacter); |
| 3939 | // Won't fit. |
| 3940 | if (written > remaining) return 0; |
| 3941 | // Copy over the character from temp_buffer. |
| 3942 | for (int j = 0; j < written; j++) { |
| 3943 | buffer[j] = temp_buffer[j]; |
| 3944 | } |
| 3945 | return written; |
| 3946 | } |
| 3947 | |
| 3948 | template<typename Char> |
| 3949 | void Visit(const Char* chars, const int length) { |
| 3950 | using namespace unibrow; |
| 3951 | // TODO(dcarney): Add back ascii fast path. |
| 3952 | ASSERT(!early_termination_); |
| 3953 | ASSERT(length > 0); |
| 3954 | // Copy state to stack. |
| 3955 | char* buffer = buffer_; |
| 3956 | int last_character = last_character_; |
| 3957 | int i = 0; |
| 3958 | // Do a fast loop where there is no exit capacity check. |
| 3959 | while (true) { |
| 3960 | int fast_length; |
| 3961 | if (capacity_ == -1) { |
| 3962 | fast_length = length; |
| 3963 | } else { |
| 3964 | int remaining_capacity = capacity_ - static_cast<int>(buffer - start_); |
| 3965 | // Need enough space to write everything but one character. |
| 3966 | STATIC_ASSERT(Utf16::kMaxExtraUtf8BytesForOneUtf16CodeUnit == 3); |
| 3967 | int writable_length = (remaining_capacity - 3)/3; |
| 3968 | // Need to drop into slow loop. |
| 3969 | if (writable_length <= 0) break; |
| 3970 | fast_length = i + writable_length; |
| 3971 | if (fast_length > length) fast_length = length; |
| 3972 | } |
| 3973 | // Write the characters to the stream. |
| 3974 | for (; i < fast_length; i++) { |
| 3975 | uint16_t character = *chars++; |
| 3976 | buffer += Utf8::Encode(buffer, character, last_character); |
| 3977 | last_character = character; |
| 3978 | ASSERT(capacity_ == -1 || (buffer - start_) <= capacity_); |
| 3979 | } |
| 3980 | // Array is fully written. Exit. |
| 3981 | if (fast_length == length) { |
| 3982 | // Write state back out to object. |
| 3983 | last_character_ = last_character; |
| 3984 | buffer_ = buffer; |
| 3985 | utf16_chars_read_ += i; |
| 3986 | return; |
| 3987 | } |
| 3988 | } |
| 3989 | ASSERT(capacity_ != -1); |
| 3990 | // Slow loop. Must check capacity on each iteration. |
| 3991 | int remaining_capacity = capacity_ - static_cast<int>(buffer - start_); |
| 3992 | ASSERT(remaining_capacity >= 0); |
| 3993 | for (; i < length && remaining_capacity > 0; i++) { |
| 3994 | uint16_t character = *chars++; |
| 3995 | int written = WriteEndCharacter(character, |
| 3996 | last_character, |
| 3997 | remaining_capacity, |
| 3998 | buffer); |
| 3999 | if (written == 0) { |
| 4000 | early_termination_ = true; |
| 4001 | break; |
| 4002 | } |
| 4003 | buffer += written; |
| 4004 | remaining_capacity -= written; |
| 4005 | last_character = character; |
| 4006 | } |
| 4007 | // Write state back out to object. |
| 4008 | last_character_ = last_character; |
| 4009 | buffer_ = buffer; |
| 4010 | utf16_chars_read_ += i; |
| 4011 | } |
| 4012 | |
| 4013 | inline bool IsDone() { |
| 4014 | return early_termination_; |
| 4015 | } |
| 4016 | |
| 4017 | inline void VisitOneByteString(const uint8_t* chars, unsigned length) { |
| 4018 | Visit(chars, static_cast<int>(length)); |
| 4019 | } |
| 4020 | |
| 4021 | inline void VisitTwoByteString(const uint16_t* chars, unsigned length) { |
| 4022 | Visit(chars, static_cast<int>(length)); |
| 4023 | } |
| 4024 | |
| 4025 | inline int CompleteWrite(bool write_null, int* utf16_chars_read_out) { |
| 4026 | // Write out number of utf16 characters written to the stream. |
| 4027 | if (utf16_chars_read_out != NULL) { |
| 4028 | *utf16_chars_read_out = utf16_chars_read_; |
| 4029 | } |
| 4030 | // Only null terminate if all of the string was written and there's space. |
| 4031 | if (write_null && |
| 4032 | !early_termination_ && |
| 4033 | (capacity_ == -1 || (buffer_ - start_) < capacity_)) { |
| 4034 | *buffer_++ = '\0'; |
| 4035 | } |
| 4036 | return static_cast<int>(buffer_ - start_); |
| 4037 | } |
| 4038 | |
| 4039 | private: |
| 4040 | bool early_termination_; |
| 4041 | int last_character_; |
| 4042 | char* buffer_; |
| 4043 | char* const start_; |
| 4044 | int capacity_; |
| 4045 | int utf16_chars_read_; |
| 4046 | DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8WriterVisitor); |
| 4047 | }; |
| 4048 | |
| 4049 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 4050 | int String::WriteUtf8(char* buffer, |
| 4051 | int capacity, |
| 4052 | int* nchars_ref, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4053 | int options) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4054 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4055 | if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; |
| 4056 | LOG_API(isolate, "String::WriteUtf8"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4057 | ENTER_V8(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4058 | i::Handle<i::String> str = Utils::OpenHandle(this); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4059 | if (options & HINT_MANY_WRITES_EXPECTED) { |
| 4060 | FlattenString(str); // Flatten the string for efficiency. |
| 4061 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4062 | Utf8WriterVisitor writer(buffer, capacity); |
| 4063 | i::ConsStringIteratorOp* op = isolate->write_iterator(); |
| 4064 | op->Reset(); |
| 4065 | int32_t type = str->map()->instance_type(); |
| 4066 | unsigned str_length = static_cast<unsigned>(str->length()); |
| 4067 | if (str_length != 0) { |
| 4068 | i::String::Visit(*str, 0, writer, *op, type, str_length); |
| 4069 | while (!writer.IsDone()) { |
| 4070 | unsigned length_out; |
| 4071 | i::String* next = op->ContinueOperation(&type, &length_out); |
| 4072 | if (next == NULL) break; |
| 4073 | // TODO(dcarney): need an asserting null op. |
| 4074 | i::ConsStringNullOp null_op; |
| 4075 | i::String::Visit(next, 0, writer, null_op, type, length_out); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4076 | } |
| 4077 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4078 | return writer.CompleteWrite(!(options & NO_NULL_TERMINATION), nchars_ref); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 4082 | int String::WriteAscii(char* buffer, |
| 4083 | int start, |
| 4084 | int length, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4085 | int options) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4086 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4087 | if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0; |
| 4088 | LOG_API(isolate, "String::WriteAscii"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4089 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4090 | ASSERT(start >= 0 && length >= -1); |
| 4091 | i::Handle<i::String> str = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4092 | isolate->string_tracker()->RecordWrite(str); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4093 | if (options & HINT_MANY_WRITES_EXPECTED) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4094 | FlattenString(str); // Flatten the string for efficiency. |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 4095 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4096 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4097 | if (str->HasOnlyAsciiChars()) { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4098 | // WriteToFlat is faster than using the StringCharacterStream. |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4099 | if (length == -1) length = str->length() + 1; |
| 4100 | int len = i::Min(length, str->length() - start); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4101 | i::String::WriteToFlat(*str, |
| 4102 | reinterpret_cast<uint8_t*>(buffer), |
| 4103 | start, |
| 4104 | start + len); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4105 | if (!(options & PRESERVE_ASCII_NULL)) { |
| 4106 | for (int i = 0; i < len; i++) { |
| 4107 | if (buffer[i] == '\0') buffer[i] = ' '; |
| 4108 | } |
| 4109 | } |
| 4110 | if (!(options & NO_NULL_TERMINATION) && length > len) { |
| 4111 | buffer[len] = '\0'; |
| 4112 | } |
| 4113 | return len; |
| 4114 | } |
| 4115 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4116 | int end = length; |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4117 | if ((length == -1) || (length > str->length() - start)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4118 | end = str->length() - start; |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4119 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4120 | if (end < 0) return 0; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4121 | i::StringCharacterStream write_stream(*str, isolate->write_iterator(), start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4122 | int i; |
| 4123 | for (i = 0; i < end; i++) { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4124 | char c = static_cast<char>(write_stream.GetNext()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4125 | if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' '; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4126 | buffer[i] = c; |
| 4127 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4128 | if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4129 | buffer[i] = '\0'; |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4130 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4131 | return i; |
| 4132 | } |
| 4133 | |
| 4134 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4135 | template<typename CharType> |
| 4136 | static inline int WriteHelper(const String* string, |
| 4137 | CharType* buffer, |
| 4138 | int start, |
| 4139 | int length, |
| 4140 | int options) { |
| 4141 | i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate(); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4142 | if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; |
| 4143 | LOG_API(isolate, "String::Write"); |
| 4144 | ENTER_V8(isolate); |
| 4145 | ASSERT(start >= 0 && length >= -1); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4146 | i::Handle<i::String> str = Utils::OpenHandle(string); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4147 | isolate->string_tracker()->RecordWrite(str); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4148 | if (options & String::HINT_MANY_WRITES_EXPECTED) { |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4149 | // Flatten the string for efficiency. This applies whether we are |
| 4150 | // using StringCharacterStream or Get(i) to access the characters. |
| 4151 | FlattenString(str); |
| 4152 | } |
| 4153 | int end = start + length; |
| 4154 | if ((length == -1) || (length > str->length() - start) ) |
| 4155 | end = str->length(); |
| 4156 | if (end < 0) return 0; |
| 4157 | i::String::WriteToFlat(*str, buffer, start, end); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4158 | if (!(options & String::NO_NULL_TERMINATION) && |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4159 | (length == -1 || end - start < length)) { |
| 4160 | buffer[end - start] = '\0'; |
| 4161 | } |
| 4162 | return end - start; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4166 | int String::WriteOneByte(uint8_t* buffer, |
| 4167 | int start, |
| 4168 | int length, |
| 4169 | int options) const { |
| 4170 | return WriteHelper(this, buffer, start, length, options); |
| 4171 | } |
| 4172 | |
| 4173 | |
| 4174 | int String::Write(uint16_t* buffer, |
| 4175 | int start, |
| 4176 | int length, |
| 4177 | int options) const { |
| 4178 | return WriteHelper(this, buffer, start, length, options); |
| 4179 | } |
| 4180 | |
| 4181 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4182 | bool v8::String::IsExternal() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4183 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4184 | if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) { |
| 4185 | return false; |
| 4186 | } |
| 4187 | EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4188 | return i::StringShape(*str).IsExternalTwoByte(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4192 | bool v8::String::IsExternalAscii() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4193 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4194 | if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternalAscii()")) { |
| 4195 | return false; |
| 4196 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4197 | return i::StringShape(*str).IsExternalAscii(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4201 | void v8::String::VerifyExternalStringResource( |
| 4202 | v8::String::ExternalStringResource* value) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4203 | i::Handle<i::String> str = Utils::OpenHandle(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4204 | const v8::String::ExternalStringResource* expected; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4205 | if (i::StringShape(*str).IsExternalTwoByte()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4206 | const void* resource = |
| 4207 | i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
| 4208 | expected = reinterpret_cast<const ExternalStringResource*>(resource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4209 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4210 | expected = NULL; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4211 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4212 | CHECK_EQ(expected, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4213 | } |
| 4214 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4215 | void v8::String::VerifyExternalStringResourceBase( |
| 4216 | v8::String::ExternalStringResourceBase* value, Encoding encoding) const { |
| 4217 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 4218 | const v8::String::ExternalStringResourceBase* expected; |
| 4219 | Encoding expectedEncoding; |
| 4220 | if (i::StringShape(*str).IsExternalAscii()) { |
| 4221 | const void* resource = |
| 4222 | i::Handle<i::ExternalAsciiString>::cast(str)->resource(); |
| 4223 | expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); |
| 4224 | expectedEncoding = ASCII_ENCODING; |
| 4225 | } else if (i::StringShape(*str).IsExternalTwoByte()) { |
| 4226 | const void* resource = |
| 4227 | i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
| 4228 | expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); |
| 4229 | expectedEncoding = TWO_BYTE_ENCODING; |
| 4230 | } else { |
| 4231 | expected = NULL; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 4232 | expectedEncoding = str->IsOneByteRepresentation() ? ASCII_ENCODING |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4233 | : TWO_BYTE_ENCODING; |
| 4234 | } |
| 4235 | CHECK_EQ(expected, value); |
| 4236 | CHECK_EQ(expectedEncoding, encoding); |
| 4237 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4238 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4239 | const v8::String::ExternalAsciiStringResource* |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4240 | v8::String::GetExternalAsciiStringResource() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4241 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4242 | if (IsDeadCheck(str->GetIsolate(), |
| 4243 | "v8::String::GetExternalAsciiStringResource()")) { |
| 4244 | return NULL; |
| 4245 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4246 | if (i::StringShape(*str).IsExternalAscii()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4247 | const void* resource = |
| 4248 | i::Handle<i::ExternalAsciiString>::cast(str)->resource(); |
| 4249 | return reinterpret_cast<const ExternalAsciiStringResource*>(resource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4250 | } else { |
| 4251 | return NULL; |
| 4252 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4256 | double Number::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4257 | if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4258 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4259 | return obj->Number(); |
| 4260 | } |
| 4261 | |
| 4262 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4263 | bool Boolean::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4264 | if (IsDeadCheck(i::Isolate::Current(), "v8::Boolean::Value()")) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4265 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4266 | return obj->IsTrue(); |
| 4267 | } |
| 4268 | |
| 4269 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4270 | int64_t Integer::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4271 | if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4272 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4273 | if (obj->IsSmi()) { |
| 4274 | return i::Smi::cast(*obj)->value(); |
| 4275 | } else { |
| 4276 | return static_cast<int64_t>(obj->Number()); |
| 4277 | } |
| 4278 | } |
| 4279 | |
| 4280 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4281 | int32_t Int32::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4282 | if (IsDeadCheck(i::Isolate::Current(), "v8::Int32::Value()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4283 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4284 | if (obj->IsSmi()) { |
| 4285 | return i::Smi::cast(*obj)->value(); |
| 4286 | } else { |
| 4287 | return static_cast<int32_t>(obj->Number()); |
| 4288 | } |
| 4289 | } |
| 4290 | |
| 4291 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4292 | uint32_t Uint32::Value() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4293 | if (IsDeadCheck(i::Isolate::Current(), "v8::Uint32::Value()")) return 0; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4294 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4295 | if (obj->IsSmi()) { |
| 4296 | return i::Smi::cast(*obj)->value(); |
| 4297 | } else { |
| 4298 | return static_cast<uint32_t>(obj->Number()); |
| 4299 | } |
| 4300 | } |
| 4301 | |
| 4302 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4303 | int v8::Object::InternalFieldCount() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4304 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4305 | if (IsDeadCheck(obj->GetIsolate(), "v8::Object::InternalFieldCount()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4306 | return 0; |
| 4307 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4308 | return obj->GetInternalFieldCount(); |
| 4309 | } |
| 4310 | |
| 4311 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4312 | static bool InternalFieldOK(i::Handle<i::JSObject> obj, |
| 4313 | int index, |
| 4314 | const char* location) { |
| 4315 | return !IsDeadCheck(obj->GetIsolate(), location) && |
| 4316 | ApiCheck(index < obj->GetInternalFieldCount(), |
| 4317 | location, |
| 4318 | "Internal field out of bounds"); |
| 4319 | } |
| 4320 | |
| 4321 | |
| 4322 | Local<Value> v8::Object::SlowGetInternalField(int index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4323 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4324 | const char* location = "v8::Object::GetInternalField()"; |
| 4325 | if (!InternalFieldOK(obj, index, location)) return Local<Value>(); |
| 4326 | i::Handle<i::Object> value(obj->GetInternalField(index), obj->GetIsolate()); |
| 4327 | return Utils::ToLocal(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 4331 | void v8::Object::SetInternalField(int index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4332 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4333 | const char* location = "v8::Object::SetInternalField()"; |
| 4334 | if (!InternalFieldOK(obj, index, location)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4335 | i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 4336 | obj->SetInternalField(index, *val); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4337 | ASSERT_EQ(value, GetInternalField(index)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4341 | void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) { |
| 4342 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4343 | const char* location = "v8::Object::GetAlignedPointerFromInternalField()"; |
| 4344 | if (!InternalFieldOK(obj, index, location)) return NULL; |
| 4345 | return DecodeSmiToAligned(obj->GetInternalField(index), location); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4349 | void v8::Object::SetAlignedPointerInInternalField(int index, void* value) { |
| 4350 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4351 | const char* location = "v8::Object::SetAlignedPointerInInternalField()"; |
| 4352 | if (!InternalFieldOK(obj, index, location)) return; |
| 4353 | obj->SetInternalField(index, EncodeAlignedAsSmi(value, location)); |
| 4354 | ASSERT_EQ(value, GetAlignedPointerFromInternalField(index)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4358 | static void* ExternalValue(i::Object* obj) { |
| 4359 | // Obscure semantics for undefined, but somehow checked in our unit tests... |
| 4360 | if (obj->IsUndefined()) return NULL; |
| 4361 | i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0); |
| 4362 | return i::Foreign::cast(foreign)->foreign_address(); |
| 4363 | } |
| 4364 | |
| 4365 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4366 | // --- E n v i r o n m e n t --- |
| 4367 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4368 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4369 | bool v8::V8::Initialize() { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 4370 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4371 | if (isolate != NULL && isolate->IsInitialized()) { |
| 4372 | return true; |
| 4373 | } |
| 4374 | return InitializeHelper(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4378 | void v8::V8::SetEntropySource(EntropySource source) { |
| 4379 | i::V8::SetEntropySource(source); |
| 4380 | } |
| 4381 | |
| 4382 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4383 | void v8::V8::SetReturnAddressLocationResolver( |
| 4384 | ReturnAddressLocationResolver return_address_resolver) { |
| 4385 | i::V8::SetReturnAddressLocationResolver(return_address_resolver); |
| 4386 | } |
| 4387 | |
| 4388 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4389 | bool v8::V8::SetFunctionEntryHook(FunctionEntryHook entry_hook) { |
| 4390 | return i::ProfileEntryHookStub::SetFunctionEntryHook(entry_hook); |
| 4391 | } |
| 4392 | |
| 4393 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4394 | void v8::V8::SetJitCodeEventHandler( |
| 4395 | JitCodeEventOptions options, JitCodeEventHandler event_handler) { |
| 4396 | i::Isolate* isolate = i::Isolate::Current(); |
| 4397 | // Ensure that logging is initialized for our isolate. |
| 4398 | isolate->InitializeLoggingAndCounters(); |
| 4399 | isolate->logger()->SetCodeEventHandler(options, event_handler); |
| 4400 | } |
| 4401 | |
| 4402 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4403 | bool v8::V8::Dispose() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4404 | i::Isolate* isolate = i::Isolate::Current(); |
| 4405 | if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(), |
| 4406 | "v8::V8::Dispose()", |
| 4407 | "Use v8::Isolate::Dispose() for a non-default isolate.")) { |
| 4408 | return false; |
| 4409 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 4410 | i::V8::TearDown(); |
| 4411 | return true; |
| 4412 | } |
| 4413 | |
| 4414 | |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 4415 | HeapStatistics::HeapStatistics(): total_heap_size_(0), |
| 4416 | total_heap_size_executable_(0), |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 4417 | total_physical_size_(0), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4418 | used_heap_size_(0), |
| 4419 | heap_size_limit_(0) { } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4420 | |
| 4421 | |
| 4422 | void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4423 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 4424 | if (isolate == NULL || !isolate->IsInitialized()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4425 | // Isolate is unitialized thus heap is not configured yet. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4426 | heap_statistics->total_heap_size_ = 0; |
| 4427 | heap_statistics->total_heap_size_executable_ = 0; |
| 4428 | heap_statistics->total_physical_size_ = 0; |
| 4429 | heap_statistics->used_heap_size_ = 0; |
| 4430 | heap_statistics->heap_size_limit_ = 0; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4431 | return; |
| 4432 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 4433 | Isolate* ext_isolate = reinterpret_cast<Isolate*>(isolate); |
| 4434 | return ext_isolate->GetHeapStatistics(heap_statistics); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4438 | void v8::V8::VisitExternalResources(ExternalResourceVisitor* visitor) { |
| 4439 | i::Isolate* isolate = i::Isolate::Current(); |
| 4440 | IsDeadCheck(isolate, "v8::V8::VisitExternalResources"); |
| 4441 | isolate->heap()->VisitExternalResources(visitor); |
| 4442 | } |
| 4443 | |
| 4444 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4445 | class VisitorAdapter : public i::ObjectVisitor { |
| 4446 | public: |
| 4447 | explicit VisitorAdapter(PersistentHandleVisitor* visitor) |
| 4448 | : visitor_(visitor) {} |
| 4449 | virtual void VisitPointers(i::Object** start, i::Object** end) { |
| 4450 | UNREACHABLE(); |
| 4451 | } |
| 4452 | virtual void VisitEmbedderReference(i::Object** p, uint16_t class_id) { |
| 4453 | visitor_->VisitPersistentHandle(ToApi<Value>(i::Handle<i::Object>(p)), |
| 4454 | class_id); |
| 4455 | } |
| 4456 | private: |
| 4457 | PersistentHandleVisitor* visitor_; |
| 4458 | }; |
| 4459 | |
| 4460 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4461 | void v8::V8::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) { |
| 4462 | i::Isolate* isolate = i::Isolate::Current(); |
| 4463 | IsDeadCheck(isolate, "v8::V8::VisitHandlesWithClassId"); |
| 4464 | |
| 4465 | i::AssertNoAllocation no_allocation; |
| 4466 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4467 | VisitorAdapter visitor_adapter(visitor); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 4468 | isolate->global_handles()->IterateAllRootsWithClassIds(&visitor_adapter); |
| 4469 | } |
| 4470 | |
| 4471 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 4472 | void v8::V8::VisitHandlesForPartialDependence( |
| 4473 | Isolate* exported_isolate, PersistentHandleVisitor* visitor) { |
| 4474 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exported_isolate); |
| 4475 | ASSERT(isolate == i::Isolate::Current()); |
| 4476 | IsDeadCheck(isolate, "v8::V8::VisitHandlesForPartialDependence"); |
| 4477 | |
| 4478 | i::AssertNoAllocation no_allocation; |
| 4479 | |
| 4480 | VisitorAdapter visitor_adapter(visitor); |
| 4481 | isolate->global_handles()->IterateAllRootsInNewSpaceWithClassIds( |
| 4482 | &visitor_adapter); |
| 4483 | } |
| 4484 | |
| 4485 | |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4486 | bool v8::V8::IdleNotification(int hint) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4487 | // Returning true tells the caller that it need not |
| 4488 | // continue to call IdleNotification. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4489 | i::Isolate* isolate = i::Isolate::Current(); |
| 4490 | if (isolate == NULL || !isolate->IsInitialized()) return true; |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 4491 | return i::V8::IdleNotification(hint); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 4492 | } |
| 4493 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4494 | |
| 4495 | void v8::V8::LowMemoryNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4496 | i::Isolate* isolate = i::Isolate::Current(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4497 | if (isolate == NULL || !isolate->IsInitialized()) return; |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 4498 | isolate->heap()->CollectAllAvailableGarbage("low memory notification"); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 4499 | } |
| 4500 | |
| 4501 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4502 | int v8::V8::ContextDisposedNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4503 | i::Isolate* isolate = i::Isolate::Current(); |
| 4504 | if (!isolate->IsInitialized()) return 0; |
| 4505 | return isolate->heap()->NotifyContextDisposed(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 4506 | } |
| 4507 | |
| 4508 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4509 | const char* v8::V8::GetVersion() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4510 | return i::Version::GetVersion(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4514 | static i::Handle<i::FunctionTemplateInfo> |
| 4515 | EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) { |
| 4516 | if (templ->constructor()->IsUndefined()) { |
| 4517 | Local<FunctionTemplate> constructor = FunctionTemplate::New(); |
| 4518 | Utils::OpenHandle(*constructor)->set_instance_template(*templ); |
| 4519 | templ->set_constructor(*Utils::OpenHandle(*constructor)); |
| 4520 | } |
| 4521 | return i::Handle<i::FunctionTemplateInfo>( |
| 4522 | i::FunctionTemplateInfo::cast(templ->constructor())); |
| 4523 | } |
| 4524 | |
| 4525 | |
| 4526 | Persistent<Context> v8::Context::New( |
| 4527 | v8::ExtensionConfiguration* extensions, |
| 4528 | v8::Handle<ObjectTemplate> global_template, |
| 4529 | v8::Handle<Value> global_object) { |
danno@chromium.org | 4f821d9 | 2012-04-05 11:02:02 +0000 | [diff] [blame] | 4530 | i::Isolate::EnsureDefaultIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4531 | i::Isolate* isolate = i::Isolate::Current(); |
| 4532 | EnsureInitializedForIsolate(isolate, "v8::Context::New()"); |
| 4533 | LOG_API(isolate, "Context::New"); |
| 4534 | ON_BAILOUT(isolate, "v8::Context::New()", return Persistent<Context>()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4535 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4536 | // Enter V8 via an ENTER_V8 scope. |
| 4537 | i::Handle<i::Context> env; |
| 4538 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4539 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4540 | v8::Handle<ObjectTemplate> proxy_template = global_template; |
| 4541 | i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
| 4542 | i::Handle<i::FunctionTemplateInfo> global_constructor; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4543 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4544 | if (!global_template.IsEmpty()) { |
| 4545 | // Make sure that the global_template has a constructor. |
| 4546 | global_constructor = |
| 4547 | EnsureConstructor(Utils::OpenHandle(*global_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4548 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4549 | // Create a fresh template for the global proxy object. |
| 4550 | proxy_template = ObjectTemplate::New(); |
| 4551 | proxy_constructor = |
| 4552 | EnsureConstructor(Utils::OpenHandle(*proxy_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4553 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4554 | // Set the global template to be the prototype template of |
| 4555 | // global proxy template. |
| 4556 | proxy_constructor->set_prototype_template( |
| 4557 | *Utils::OpenHandle(*global_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4558 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4559 | // Migrate security handlers from global_template to |
| 4560 | // proxy_template. Temporarily removing access check |
| 4561 | // information from the global template. |
| 4562 | if (!global_constructor->access_check_info()->IsUndefined()) { |
| 4563 | proxy_constructor->set_access_check_info( |
| 4564 | global_constructor->access_check_info()); |
| 4565 | proxy_constructor->set_needs_access_check( |
| 4566 | global_constructor->needs_access_check()); |
| 4567 | global_constructor->set_needs_access_check(false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4568 | global_constructor->set_access_check_info( |
| 4569 | isolate->heap()->undefined_value()); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4570 | } |
| 4571 | } |
| 4572 | |
| 4573 | // Create the environment. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4574 | env = isolate->bootstrapper()->CreateEnvironment( |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 4575 | Utils::OpenHandle(*global_object, true), |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4576 | proxy_template, |
| 4577 | extensions); |
| 4578 | |
| 4579 | // Restore the access check info on the global template. |
| 4580 | if (!global_template.IsEmpty()) { |
| 4581 | ASSERT(!global_constructor.is_null()); |
| 4582 | ASSERT(!proxy_constructor.is_null()); |
| 4583 | global_constructor->set_access_check_info( |
| 4584 | proxy_constructor->access_check_info()); |
| 4585 | global_constructor->set_needs_access_check( |
| 4586 | proxy_constructor->needs_access_check()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4587 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4588 | isolate->runtime_profiler()->Reset(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4589 | } |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 4590 | // Leave V8. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4591 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4592 | if (env.is_null()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4593 | return Persistent<Context>(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4594 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4595 | return Persistent<Context>(Utils::ToLocal(env)); |
| 4596 | } |
| 4597 | |
| 4598 | |
| 4599 | void v8::Context::SetSecurityToken(Handle<Value> token) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4600 | i::Isolate* isolate = i::Isolate::Current(); |
| 4601 | if (IsDeadCheck(isolate, "v8::Context::SetSecurityToken()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4602 | return; |
| 4603 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4604 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4605 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4606 | i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4607 | env->set_security_token(*token_handle); |
| 4608 | } |
| 4609 | |
| 4610 | |
| 4611 | void v8::Context::UseDefaultSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4612 | i::Isolate* isolate = i::Isolate::Current(); |
| 4613 | if (IsDeadCheck(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4614 | "v8::Context::UseDefaultSecurityToken()")) { |
| 4615 | return; |
| 4616 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4617 | ENTER_V8(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4618 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4619 | env->set_security_token(env->global_object()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | |
| 4623 | Handle<Value> v8::Context::GetSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4624 | i::Isolate* isolate = i::Isolate::Current(); |
| 4625 | if (IsDeadCheck(isolate, "v8::Context::GetSecurityToken()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4626 | return Handle<Value>(); |
| 4627 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4628 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4629 | i::Object* security_token = env->security_token(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 4630 | i::Handle<i::Object> token_handle(security_token, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4631 | return Utils::ToLocal(token_handle); |
| 4632 | } |
| 4633 | |
| 4634 | |
| 4635 | bool Context::HasOutOfMemoryException() { |
| 4636 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4637 | return env->has_out_of_memory(); |
| 4638 | } |
| 4639 | |
| 4640 | |
| 4641 | bool Context::InContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4642 | return i::Isolate::Current()->context() != NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4646 | v8::Isolate* Context::GetIsolate() { |
| 4647 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 4648 | return reinterpret_cast<Isolate*>(env->GetIsolate()); |
| 4649 | } |
| 4650 | |
| 4651 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4652 | v8::Local<v8::Context> Context::GetEntered() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4653 | i::Isolate* isolate = i::Isolate::Current(); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4654 | if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4655 | return Local<Context>(); |
| 4656 | } |
| 4657 | i::Handle<i::Object> last = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4658 | isolate->handle_scope_implementer()->LastEnteredContext(); |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 4659 | if (last.is_null()) return Local<Context>(); |
| 4660 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(last); |
| 4661 | return Utils::ToLocal(context); |
| 4662 | } |
| 4663 | |
| 4664 | |
| 4665 | v8::Local<v8::Context> Context::GetCurrent() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4666 | i::Isolate* isolate = i::Isolate::Current(); |
| 4667 | if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4668 | return Local<Context>(); |
| 4669 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4670 | i::Handle<i::Object> current = isolate->native_context(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4671 | if (current.is_null()) return Local<Context>(); |
| 4672 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(current); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4673 | return Utils::ToLocal(context); |
| 4674 | } |
| 4675 | |
| 4676 | |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4677 | v8::Local<v8::Context> Context::GetCalling() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4678 | i::Isolate* isolate = i::Isolate::Current(); |
| 4679 | if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4680 | return Local<Context>(); |
| 4681 | } |
| 4682 | i::Handle<i::Object> calling = |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4683 | isolate->GetCallingNativeContext(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4684 | if (calling.is_null()) return Local<Context>(); |
| 4685 | i::Handle<i::Context> context = i::Handle<i::Context>::cast(calling); |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 4686 | return Utils::ToLocal(context); |
| 4687 | } |
| 4688 | |
| 4689 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4690 | v8::Local<v8::Object> Context::Global() { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4691 | i::Isolate* isolate = i::Isolate::Current(); |
| 4692 | if (IsDeadCheck(isolate, "v8::Context::Global()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4693 | return Local<v8::Object>(); |
| 4694 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4695 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4696 | i::Handle<i::Context> context = |
| 4697 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4698 | i::Handle<i::Object> global(context->global_proxy(), isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4699 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(global)); |
| 4700 | } |
| 4701 | |
| 4702 | |
| 4703 | void Context::DetachGlobal() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4704 | i::Isolate* isolate = i::Isolate::Current(); |
| 4705 | if (IsDeadCheck(isolate, "v8::Context::DetachGlobal()")) return; |
| 4706 | ENTER_V8(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4707 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4708 | i::Handle<i::Context> context = |
| 4709 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4710 | isolate->bootstrapper()->DetachGlobal(context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4714 | void Context::ReattachGlobal(Handle<Object> global_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4715 | i::Isolate* isolate = i::Isolate::Current(); |
| 4716 | if (IsDeadCheck(isolate, "v8::Context::ReattachGlobal()")) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4717 | ENTER_V8(isolate); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4718 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4719 | i::Handle<i::Context> context = |
| 4720 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4721 | i::Handle<i::JSGlobalProxy> global_proxy = |
| 4722 | i::Handle<i::JSGlobalProxy>::cast(Utils::OpenHandle(*global_object)); |
| 4723 | isolate->bootstrapper()->ReattachGlobal(context, global_proxy); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
| 4726 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 4727 | void Context::AllowCodeGenerationFromStrings(bool allow) { |
| 4728 | i::Isolate* isolate = i::Isolate::Current(); |
| 4729 | if (IsDeadCheck(isolate, "v8::Context::AllowCodeGenerationFromStrings()")) { |
| 4730 | return; |
| 4731 | } |
| 4732 | ENTER_V8(isolate); |
| 4733 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4734 | i::Handle<i::Context> context = |
| 4735 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
| 4736 | context->set_allow_code_gen_from_strings( |
| 4737 | allow ? isolate->heap()->true_value() : isolate->heap()->false_value()); |
| 4738 | } |
| 4739 | |
| 4740 | |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4741 | bool Context::IsCodeGenerationFromStringsAllowed() { |
| 4742 | i::Isolate* isolate = i::Isolate::Current(); |
| 4743 | if (IsDeadCheck(isolate, |
| 4744 | "v8::Context::IsCodeGenerationFromStringsAllowed()")) { |
| 4745 | return false; |
| 4746 | } |
| 4747 | ENTER_V8(isolate); |
| 4748 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4749 | i::Handle<i::Context> context = |
| 4750 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
| 4751 | return !context->allow_code_gen_from_strings()->IsFalse(); |
| 4752 | } |
| 4753 | |
| 4754 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4755 | void Context::SetErrorMessageForCodeGenerationFromStrings( |
| 4756 | Handle<String> error) { |
| 4757 | i::Isolate* isolate = i::Isolate::Current(); |
| 4758 | if (IsDeadCheck(isolate, |
| 4759 | "v8::Context::SetErrorMessageForCodeGenerationFromStrings()")) { |
| 4760 | return; |
| 4761 | } |
| 4762 | ENTER_V8(isolate); |
| 4763 | i::Object** ctx = reinterpret_cast<i::Object**>(this); |
| 4764 | i::Handle<i::Context> context = |
| 4765 | i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 4766 | i::Handle<i::String> error_handle = Utils::OpenHandle(*error); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4767 | context->set_error_message_for_code_gen_from_strings(*error_handle); |
| 4768 | } |
| 4769 | |
| 4770 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4771 | Local<v8::Object> ObjectTemplate::NewInstance() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4772 | i::Isolate* isolate = i::Isolate::Current(); |
| 4773 | ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", |
| 4774 | return Local<v8::Object>()); |
| 4775 | LOG_API(isolate, "ObjectTemplate::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4776 | ENTER_V8(isolate); |
| 4777 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4778 | i::Handle<i::Object> obj = |
| 4779 | i::Execution::InstantiateObject(Utils::OpenHandle(this), |
| 4780 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4781 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4782 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj)); |
| 4783 | } |
| 4784 | |
| 4785 | |
| 4786 | Local<v8::Function> FunctionTemplate::GetFunction() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4787 | i::Isolate* isolate = i::Isolate::Current(); |
| 4788 | ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4789 | return Local<v8::Function>()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4790 | LOG_API(isolate, "FunctionTemplate::GetFunction"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4791 | ENTER_V8(isolate); |
| 4792 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4793 | i::Handle<i::Object> obj = |
| 4794 | i::Execution::InstantiateFunction(Utils::OpenHandle(this), |
| 4795 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4796 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Function>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4797 | return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj)); |
| 4798 | } |
| 4799 | |
| 4800 | |
| 4801 | bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4802 | ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()", |
| 4803 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4804 | i::Object* obj = *Utils::OpenHandle(*value); |
| 4805 | return obj->IsInstanceOf(*Utils::OpenHandle(this)); |
| 4806 | } |
| 4807 | |
| 4808 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4809 | Local<External> v8::External::New(void* value) { |
| 4810 | STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4811 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4812 | EnsureInitializedForIsolate(isolate, "v8::External::New()"); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4813 | LOG_API(isolate, "External::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4814 | ENTER_V8(isolate); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4815 | i::Handle<i::JSObject> external = isolate->factory()->NewExternal(value); |
| 4816 | return Utils::ExternalToLocal(external); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4817 | } |
| 4818 | |
| 4819 | |
| 4820 | void* External::Value() const { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4821 | if (IsDeadCheck(i::Isolate::Current(), "v8::External::Value()")) return NULL; |
| 4822 | return ExternalValue(*Utils::OpenHandle(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4826 | Local<String> v8::String::Empty() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4827 | i::Isolate* isolate = i::Isolate::Current(); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 4828 | if (!EnsureInitializedForIsolate(isolate, "v8::String::Empty()")) { |
| 4829 | return v8::Local<String>(); |
| 4830 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4831 | LOG_API(isolate, "String::Empty()"); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4832 | return Utils::ToLocal(isolate->factory()->empty_string()); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4836 | Local<String> v8::String::New(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4837 | i::Isolate* isolate = i::Isolate::Current(); |
| 4838 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4839 | LOG_API(isolate, "String::New(char)"); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4840 | if (length == 0) return Empty(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4841 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4842 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4843 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4844 | isolate->factory()->NewStringFromUtf8( |
| 4845 | i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4846 | return Utils::ToLocal(result); |
| 4847 | } |
| 4848 | |
| 4849 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4850 | 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] | 4851 | i::Handle<i::String> left_string = Utils::OpenHandle(*left); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4852 | i::Isolate* isolate = left_string->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4853 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4854 | LOG_API(isolate, "String::New(char)"); |
| 4855 | ENTER_V8(isolate); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4856 | i::Handle<i::String> right_string = Utils::OpenHandle(*right); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4857 | i::Handle<i::String> result = isolate->factory()->NewConsString(left_string, |
| 4858 | right_string); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4859 | return Utils::ToLocal(result); |
| 4860 | } |
| 4861 | |
| 4862 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4863 | Local<String> v8::String::NewUndetectable(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4864 | i::Isolate* isolate = i::Isolate::Current(); |
| 4865 | EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()"); |
| 4866 | LOG_API(isolate, "String::NewUndetectable(char)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4867 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4868 | if (length == -1) length = i::StrLength(data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4869 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4870 | isolate->factory()->NewStringFromUtf8( |
| 4871 | i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4872 | result->MarkAsUndetectable(); |
| 4873 | return Utils::ToLocal(result); |
| 4874 | } |
| 4875 | |
| 4876 | |
| 4877 | static int TwoByteStringLength(const uint16_t* data) { |
| 4878 | int length = 0; |
| 4879 | while (data[length] != '\0') length++; |
| 4880 | return length; |
| 4881 | } |
| 4882 | |
| 4883 | |
| 4884 | Local<String> v8::String::New(const uint16_t* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4885 | i::Isolate* isolate = i::Isolate::Current(); |
| 4886 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 4887 | LOG_API(isolate, "String::New(uint16_)"); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 4888 | if (length == 0) return Empty(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4889 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4890 | if (length == -1) length = TwoByteStringLength(data); |
| 4891 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4892 | isolate->factory()->NewStringFromTwoByte( |
| 4893 | i::Vector<const uint16_t>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4894 | return Utils::ToLocal(result); |
| 4895 | } |
| 4896 | |
| 4897 | |
| 4898 | Local<String> v8::String::NewUndetectable(const uint16_t* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4899 | i::Isolate* isolate = i::Isolate::Current(); |
| 4900 | EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()"); |
| 4901 | LOG_API(isolate, "String::NewUndetectable(uint16_)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4902 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4903 | if (length == -1) length = TwoByteStringLength(data); |
| 4904 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4905 | isolate->factory()->NewStringFromTwoByte( |
| 4906 | i::Vector<const uint16_t>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4907 | result->MarkAsUndetectable(); |
| 4908 | return Utils::ToLocal(result); |
| 4909 | } |
| 4910 | |
| 4911 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4912 | i::Handle<i::String> NewExternalStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4913 | v8::String::ExternalStringResource* resource) { |
| 4914 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4915 | isolate->factory()->NewExternalStringFromTwoByte(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4916 | return result; |
| 4917 | } |
| 4918 | |
| 4919 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4920 | i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4921 | v8::String::ExternalAsciiStringResource* resource) { |
| 4922 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4923 | isolate->factory()->NewExternalStringFromAscii(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4924 | return result; |
| 4925 | } |
| 4926 | |
| 4927 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4928 | Local<String> v8::String::NewExternal( |
| 4929 | v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4930 | i::Isolate* isolate = i::Isolate::Current(); |
| 4931 | EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 4932 | LOG_API(isolate, "String::NewExternal"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4933 | ENTER_V8(isolate); |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 4934 | CHECK(resource && resource->data()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4935 | i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); |
| 4936 | isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4937 | return Utils::ToLocal(result); |
| 4938 | } |
| 4939 | |
| 4940 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4941 | bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4942 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 4943 | i::Isolate* isolate = obj->GetIsolate(); |
| 4944 | if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4945 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 4946 | return false; // Already an external string. |
| 4947 | } |
| 4948 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4949 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 4950 | return false; |
| 4951 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4952 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 4953 | return false; |
| 4954 | } |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 4955 | CHECK(resource && resource->data()); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4956 | bool result = obj->MakeExternal(resource); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4957 | if (result && !obj->IsInternalizedString()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4958 | isolate->heap()->external_string_table()->AddString(*obj); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4959 | } |
| 4960 | return result; |
| 4961 | } |
| 4962 | |
| 4963 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4964 | Local<String> v8::String::NewExternal( |
| 4965 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4966 | i::Isolate* isolate = i::Isolate::Current(); |
| 4967 | EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 4968 | LOG_API(isolate, "String::NewExternal"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4969 | ENTER_V8(isolate); |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 4970 | CHECK(resource && resource->data()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4971 | i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); |
| 4972 | isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4973 | return Utils::ToLocal(result); |
| 4974 | } |
| 4975 | |
| 4976 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4977 | bool v8::String::MakeExternal( |
| 4978 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4979 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 4980 | i::Isolate* isolate = obj->GetIsolate(); |
| 4981 | if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4982 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 4983 | return false; // Already an external string. |
| 4984 | } |
| 4985 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4986 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 4987 | return false; |
| 4988 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4989 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 4990 | return false; |
| 4991 | } |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 4992 | CHECK(resource && resource->data()); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4993 | bool result = obj->MakeExternal(resource); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 4994 | if (result && !obj->IsInternalizedString()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4995 | isolate->heap()->external_string_table()->AddString(*obj); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4996 | } |
| 4997 | return result; |
| 4998 | } |
| 4999 | |
| 5000 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5001 | bool v8::String::CanMakeExternal() { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5002 | if (!internal::FLAG_clever_optimizations) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5003 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5004 | i::Isolate* isolate = obj->GetIsolate(); |
| 5005 | if (IsDeadCheck(isolate, "v8::String::CanMakeExternal()")) return false; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5006 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5007 | int size = obj->Size(); // Byte size of the original string. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5008 | if (size < i::ExternalString::kShortSize) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5009 | i::StringShape shape(*obj); |
| 5010 | return !shape.IsExternal(); |
| 5011 | } |
| 5012 | |
| 5013 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5014 | Local<v8::Object> v8::Object::New() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5015 | i::Isolate* isolate = i::Isolate::Current(); |
| 5016 | EnsureInitializedForIsolate(isolate, "v8::Object::New()"); |
| 5017 | LOG_API(isolate, "Object::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5018 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5019 | i::Handle<i::JSObject> obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5020 | isolate->factory()->NewJSObject(isolate->object_function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5021 | return Utils::ToLocal(obj); |
| 5022 | } |
| 5023 | |
| 5024 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5025 | Local<v8::Value> v8::NumberObject::New(double value) { |
| 5026 | i::Isolate* isolate = i::Isolate::Current(); |
| 5027 | EnsureInitializedForIsolate(isolate, "v8::NumberObject::New()"); |
| 5028 | LOG_API(isolate, "NumberObject::New"); |
| 5029 | ENTER_V8(isolate); |
| 5030 | i::Handle<i::Object> number = isolate->factory()->NewNumber(value); |
| 5031 | i::Handle<i::Object> obj = isolate->factory()->ToObject(number); |
| 5032 | return Utils::ToLocal(obj); |
| 5033 | } |
| 5034 | |
| 5035 | |
| 5036 | double v8::NumberObject::NumberValue() const { |
| 5037 | i::Isolate* isolate = i::Isolate::Current(); |
| 5038 | if (IsDeadCheck(isolate, "v8::NumberObject::NumberValue()")) return 0; |
| 5039 | LOG_API(isolate, "NumberObject::NumberValue"); |
| 5040 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5041 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5042 | return jsvalue->value()->Number(); |
| 5043 | } |
| 5044 | |
| 5045 | |
| 5046 | Local<v8::Value> v8::BooleanObject::New(bool value) { |
| 5047 | i::Isolate* isolate = i::Isolate::Current(); |
| 5048 | EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()"); |
| 5049 | LOG_API(isolate, "BooleanObject::New"); |
| 5050 | ENTER_V8(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5051 | i::Handle<i::Object> boolean(value |
| 5052 | ? isolate->heap()->true_value() |
| 5053 | : isolate->heap()->false_value(), |
| 5054 | isolate); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5055 | i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean); |
| 5056 | return Utils::ToLocal(obj); |
| 5057 | } |
| 5058 | |
| 5059 | |
| 5060 | bool v8::BooleanObject::BooleanValue() const { |
| 5061 | i::Isolate* isolate = i::Isolate::Current(); |
| 5062 | if (IsDeadCheck(isolate, "v8::BooleanObject::BooleanValue()")) return 0; |
| 5063 | LOG_API(isolate, "BooleanObject::BooleanValue"); |
| 5064 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5065 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5066 | return jsvalue->value()->IsTrue(); |
| 5067 | } |
| 5068 | |
| 5069 | |
| 5070 | Local<v8::Value> v8::StringObject::New(Handle<String> value) { |
| 5071 | i::Isolate* isolate = i::Isolate::Current(); |
| 5072 | EnsureInitializedForIsolate(isolate, "v8::StringObject::New()"); |
| 5073 | LOG_API(isolate, "StringObject::New"); |
| 5074 | ENTER_V8(isolate); |
| 5075 | i::Handle<i::Object> obj = |
| 5076 | isolate->factory()->ToObject(Utils::OpenHandle(*value)); |
| 5077 | return Utils::ToLocal(obj); |
| 5078 | } |
| 5079 | |
| 5080 | |
| 5081 | Local<v8::String> v8::StringObject::StringValue() const { |
| 5082 | i::Isolate* isolate = i::Isolate::Current(); |
| 5083 | if (IsDeadCheck(isolate, "v8::StringObject::StringValue()")) { |
| 5084 | return Local<v8::String>(); |
| 5085 | } |
| 5086 | LOG_API(isolate, "StringObject::StringValue"); |
| 5087 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5088 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5089 | return Utils::ToLocal( |
| 5090 | i::Handle<i::String>(i::String::cast(jsvalue->value()))); |
| 5091 | } |
| 5092 | |
| 5093 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5094 | Local<v8::Value> v8::Date::New(double time) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5095 | i::Isolate* isolate = i::Isolate::Current(); |
| 5096 | EnsureInitializedForIsolate(isolate, "v8::Date::New()"); |
| 5097 | LOG_API(isolate, "Date::New"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5098 | if (isnan(time)) { |
| 5099 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 5100 | time = i::OS::nan_value(); |
| 5101 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5102 | ENTER_V8(isolate); |
| 5103 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5104 | i::Handle<i::Object> obj = |
| 5105 | i::Execution::NewDate(time, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5106 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5107 | return Utils::ToLocal(obj); |
| 5108 | } |
| 5109 | |
| 5110 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5111 | double v8::Date::NumberValue() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5112 | i::Isolate* isolate = i::Isolate::Current(); |
| 5113 | if (IsDeadCheck(isolate, "v8::Date::NumberValue()")) return 0; |
| 5114 | LOG_API(isolate, "Date::NumberValue"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5115 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5116 | i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj); |
| 5117 | return jsdate->value()->Number(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5118 | } |
| 5119 | |
| 5120 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5121 | void v8::Date::DateTimeConfigurationChangeNotification() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5122 | i::Isolate* isolate = i::Isolate::Current(); |
| 5123 | ON_BAILOUT(isolate, "v8::Date::DateTimeConfigurationChangeNotification()", |
| 5124 | return); |
| 5125 | LOG_API(isolate, "Date::DateTimeConfigurationChangeNotification"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5126 | ENTER_V8(isolate); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5127 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5128 | isolate->date_cache()->ResetDateCache(); |
| 5129 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5130 | i::HandleScope scope(isolate); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5131 | // Get the function ResetDateCache (defined in date.js). |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 5132 | i::Handle<i::String> func_name_str = |
| 5133 | isolate->factory()->InternalizeOneByteString( |
| 5134 | STATIC_ASCII_VECTOR("ResetDateCache")); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5135 | i::MaybeObject* result = |
| 5136 | isolate->js_builtins_object()->GetProperty(*func_name_str); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5137 | i::Object* object_func; |
| 5138 | if (!result->ToObject(&object_func)) { |
| 5139 | return; |
| 5140 | } |
| 5141 | |
| 5142 | if (object_func->IsJSFunction()) { |
| 5143 | i::Handle<i::JSFunction> func = |
| 5144 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_func)); |
| 5145 | |
| 5146 | // Call ResetDateCache(0 but expect no exceptions: |
| 5147 | bool caught_exception = false; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 5148 | i::Execution::TryCall(func, |
| 5149 | isolate->js_builtins_object(), |
| 5150 | 0, |
| 5151 | NULL, |
| 5152 | &caught_exception); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5153 | } |
| 5154 | } |
| 5155 | |
| 5156 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5157 | static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5158 | uint8_t flags_buf[3]; |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5159 | int num_flags = 0; |
| 5160 | if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; |
| 5161 | if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; |
| 5162 | if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; |
| 5163 | ASSERT(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf))); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 5164 | return FACTORY->InternalizeOneByteString( |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5165 | i::Vector<const uint8_t>(flags_buf, num_flags)); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | |
| 5169 | Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, |
| 5170 | Flags flags) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5171 | i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5172 | EnsureInitializedForIsolate(isolate, "v8::RegExp::New()"); |
| 5173 | LOG_API(isolate, "RegExp::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5174 | ENTER_V8(isolate); |
| 5175 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5176 | i::Handle<i::JSRegExp> obj = i::Execution::NewJSRegExp( |
| 5177 | Utils::OpenHandle(*pattern), |
| 5178 | RegExpFlagsToString(flags), |
| 5179 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5180 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::RegExp>()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5181 | return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj)); |
| 5182 | } |
| 5183 | |
| 5184 | |
| 5185 | Local<v8::String> v8::RegExp::GetSource() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5186 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5187 | if (IsDeadCheck(isolate, "v8::RegExp::GetSource()")) { |
| 5188 | return Local<v8::String>(); |
| 5189 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5190 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 5191 | return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); |
| 5192 | } |
| 5193 | |
| 5194 | |
| 5195 | // Assert that the static flags cast in GetFlags is valid. |
| 5196 | #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ |
| 5197 | STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ |
| 5198 | static_cast<int>(i::JSRegExp::internal_flag)) |
| 5199 | REGEXP_FLAG_ASSERT_EQ(kNone, NONE); |
| 5200 | REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL); |
| 5201 | REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE); |
| 5202 | REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE); |
| 5203 | #undef REGEXP_FLAG_ASSERT_EQ |
| 5204 | |
| 5205 | v8::RegExp::Flags v8::RegExp::GetFlags() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5206 | if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::GetFlags()")) { |
| 5207 | return v8::RegExp::kNone; |
| 5208 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5209 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 5210 | return static_cast<RegExp::Flags>(obj->GetFlags().value()); |
| 5211 | } |
| 5212 | |
| 5213 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5214 | Local<v8::Array> v8::Array::New(int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5215 | i::Isolate* isolate = i::Isolate::Current(); |
| 5216 | EnsureInitializedForIsolate(isolate, "v8::Array::New()"); |
| 5217 | LOG_API(isolate, "Array::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5218 | ENTER_V8(isolate); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5219 | int real_length = length > 0 ? length : 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5220 | i::Handle<i::JSArray> obj = isolate->factory()->NewJSArray(real_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 5221 | i::Handle<i::Object> length_obj = |
| 5222 | isolate->factory()->NewNumberFromInt(real_length); |
| 5223 | obj->set_length(*length_obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5224 | return Utils::ToLocal(obj); |
| 5225 | } |
| 5226 | |
| 5227 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5228 | uint32_t v8::Array::Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5229 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5230 | if (IsDeadCheck(isolate, "v8::Array::Length()")) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5231 | i::Handle<i::JSArray> obj = Utils::OpenHandle(this); |
| 5232 | i::Object* length = obj->length(); |
| 5233 | if (length->IsSmi()) { |
| 5234 | return i::Smi::cast(length)->value(); |
| 5235 | } else { |
| 5236 | return static_cast<uint32_t>(length->Number()); |
| 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5241 | Local<Object> Array::CloneElementAt(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5242 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5243 | ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5244 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5245 | if (!self->HasFastObjectElements()) { |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5246 | return Local<Object>(); |
| 5247 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 5248 | i::FixedArray* elms = i::FixedArray::cast(self->elements()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5249 | i::Object* paragon = elms->get(index); |
| 5250 | if (!paragon->IsJSObject()) { |
| 5251 | return Local<Object>(); |
| 5252 | } |
| 5253 | i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5254 | EXCEPTION_PREAMBLE(isolate); |
| 5255 | ENTER_V8(isolate); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5256 | i::Handle<i::JSObject> result = i::Copy(paragon_handle); |
| 5257 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5258 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5259 | return Utils::ToLocal(result); |
| 5260 | } |
| 5261 | |
| 5262 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5263 | Local<String> v8::String::NewSymbol(const char* data, int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5264 | i::Isolate* isolate = i::Isolate::Current(); |
| 5265 | EnsureInitializedForIsolate(isolate, "v8::String::NewSymbol()"); |
| 5266 | LOG_API(isolate, "String::NewSymbol(char)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5267 | ENTER_V8(isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5268 | if (length == -1) length = i::StrLength(data); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 5269 | i::Handle<i::String> result = isolate->factory()->InternalizeUtf8String( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5270 | i::Vector<const char>(data, length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5271 | return Utils::ToLocal(result); |
| 5272 | } |
| 5273 | |
| 5274 | |
| 5275 | Local<Number> v8::Number::New(double value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5276 | i::Isolate* isolate = i::Isolate::Current(); |
| 5277 | EnsureInitializedForIsolate(isolate, "v8::Number::New()"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5278 | if (isnan(value)) { |
| 5279 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 5280 | value = i::OS::nan_value(); |
| 5281 | } |
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 | i::Handle<i::Object> result = isolate->factory()->NewNumber(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5284 | return Utils::NumberToLocal(result); |
| 5285 | } |
| 5286 | |
| 5287 | |
| 5288 | Local<Integer> v8::Integer::New(int32_t value) { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 5289 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5290 | EnsureInitializedForIsolate(isolate, "v8::Integer::New()"); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5291 | return v8::Integer::New(value, reinterpret_cast<Isolate*>(isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5292 | } |
| 5293 | |
| 5294 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5295 | Local<Integer> Integer::NewFromUnsigned(uint32_t value) { |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5296 | i::Isolate* isolate = i::Isolate::Current(); |
| 5297 | EnsureInitializedForIsolate(isolate, "v8::Integer::NewFromUnsigned()"); |
| 5298 | return Integer::NewFromUnsigned(value, reinterpret_cast<Isolate*>(isolate)); |
| 5299 | } |
| 5300 | |
| 5301 | |
| 5302 | Local<Integer> v8::Integer::New(int32_t value, Isolate* isolate) { |
| 5303 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5304 | ASSERT(internal_isolate->IsInitialized()); |
| 5305 | if (i::Smi::IsValid(value)) { |
| 5306 | return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value), |
| 5307 | internal_isolate)); |
| 5308 | } |
| 5309 | ENTER_V8(internal_isolate); |
| 5310 | i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); |
| 5311 | return Utils::IntegerToLocal(result); |
| 5312 | } |
| 5313 | |
| 5314 | |
| 5315 | Local<Integer> v8::Integer::NewFromUnsigned(uint32_t value, Isolate* isolate) { |
| 5316 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5317 | ASSERT(internal_isolate->IsInitialized()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5318 | bool fits_into_int32_t = (value & (1 << 31)) == 0; |
| 5319 | if (fits_into_int32_t) { |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5320 | return Integer::New(static_cast<int32_t>(value), isolate); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5321 | } |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5322 | ENTER_V8(internal_isolate); |
| 5323 | i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5324 | return Utils::IntegerToLocal(result); |
| 5325 | } |
| 5326 | |
| 5327 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5328 | void V8::IgnoreOutOfMemoryException() { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5329 | EnterIsolateIfNeeded()->set_ignore_out_of_memory(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5333 | bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5334 | i::Isolate* isolate = i::Isolate::Current(); |
| 5335 | EnsureInitializedForIsolate(isolate, "v8::V8::AddMessageListener()"); |
| 5336 | ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5337 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5338 | i::HandleScope scope(isolate); |
| 5339 | NeanderArray listeners(isolate->factory()->message_listeners()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5340 | NeanderObject obj(2); |
| 5341 | obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); |
| 5342 | obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value() |
| 5343 | : *Utils::OpenHandle(*data)); |
| 5344 | listeners.add(obj.value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5345 | return true; |
| 5346 | } |
| 5347 | |
| 5348 | |
| 5349 | void V8::RemoveMessageListeners(MessageCallback that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5350 | i::Isolate* isolate = i::Isolate::Current(); |
| 5351 | EnsureInitializedForIsolate(isolate, "v8::V8::RemoveMessageListener()"); |
| 5352 | ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5353 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5354 | i::HandleScope scope(isolate); |
| 5355 | NeanderArray listeners(isolate->factory()->message_listeners()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5356 | for (int i = 0; i < listeners.length(); i++) { |
| 5357 | if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones |
| 5358 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5359 | NeanderObject listener(i::JSObject::cast(listeners.get(i))); |
| 5360 | i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5361 | if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5362 | listeners.set(i, isolate->heap()->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5363 | } |
| 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5368 | void V8::SetCaptureStackTraceForUncaughtExceptions( |
| 5369 | bool capture, |
| 5370 | int frame_limit, |
| 5371 | StackTrace::StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5372 | i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions( |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5373 | capture, |
| 5374 | frame_limit, |
| 5375 | options); |
| 5376 | } |
| 5377 | |
| 5378 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5379 | void V8::SetCounterFunction(CounterLookupCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 5380 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5381 | if (IsDeadCheck(isolate, "v8::V8::SetCounterFunction()")) return; |
| 5382 | isolate->stats_table()->SetCounterFunction(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5383 | } |
| 5384 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5385 | void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 5386 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5387 | if (IsDeadCheck(isolate, "v8::V8::SetCreateHistogramFunction()")) return; |
| 5388 | isolate->stats_table()->SetCreateHistogramFunction(callback); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 5389 | isolate->InitializeLoggingAndCounters(); |
| 5390 | isolate->counters()->ResetHistograms(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 5394 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5395 | if (IsDeadCheck(isolate, "v8::V8::SetAddHistogramSampleFunction()")) return; |
| 5396 | isolate->stats_table()-> |
| 5397 | SetAddHistogramSampleFunction(callback); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5398 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5399 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5400 | void V8::SetFailedAccessCheckCallbackFunction( |
| 5401 | FailedAccessCheckCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5402 | i::Isolate* isolate = i::Isolate::Current(); |
| 5403 | if (IsDeadCheck(isolate, "v8::V8::SetFailedAccessCheckCallbackFunction()")) { |
| 5404 | return; |
| 5405 | } |
| 5406 | isolate->SetFailedAccessCheckCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5407 | } |
| 5408 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5409 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5410 | void V8::AddObjectGroup(Persistent<Value>* objects, |
| 5411 | size_t length, |
| 5412 | RetainedObjectInfo* info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5413 | i::Isolate* isolate = i::Isolate::Current(); |
| 5414 | if (IsDeadCheck(isolate, "v8::V8::AddObjectGroup()")) return; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 5415 | STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5416 | isolate->global_handles()->AddObjectGroup( |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5417 | reinterpret_cast<i::Object***>(objects), length, info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5418 | } |
| 5419 | |
| 5420 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5421 | void V8::AddObjectGroup(Isolate* exported_isolate, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5422 | Persistent<Value>* objects, |
| 5423 | size_t length, |
| 5424 | RetainedObjectInfo* info) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5425 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exported_isolate); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 5426 | ASSERT(isolate == i::Isolate::Current()); |
| 5427 | if (IsDeadCheck(isolate, "v8::V8::AddObjectGroup()")) return; |
| 5428 | STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); |
| 5429 | isolate->global_handles()->AddObjectGroup( |
| 5430 | reinterpret_cast<i::Object***>(objects), length, info); |
| 5431 | } |
| 5432 | |
| 5433 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5434 | void V8::AddImplicitReferences(Persistent<Object> parent, |
| 5435 | Persistent<Value>* children, |
| 5436 | size_t length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5437 | i::Isolate* isolate = i::Isolate::Current(); |
| 5438 | if (IsDeadCheck(isolate, "v8::V8::AddImplicitReferences()")) return; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5439 | STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5440 | isolate->global_handles()->AddImplicitReferences( |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 5441 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(*parent)).location(), |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5442 | reinterpret_cast<i::Object***>(children), length); |
| 5443 | } |
| 5444 | |
| 5445 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 5446 | intptr_t V8::AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 5447 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 5448 | if (isolate == NULL || !isolate->IsInitialized() || |
| 5449 | IsDeadCheck(isolate, "v8::V8::AdjustAmountOfExternalAllocatedMemory()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5450 | return 0; |
| 5451 | } |
| 5452 | return isolate->heap()->AdjustAmountOfExternalAllocatedMemory( |
| 5453 | change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5457 | void V8::SetGlobalGCPrologueCallback(GCCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5458 | i::Isolate* isolate = i::Isolate::Current(); |
| 5459 | if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return; |
| 5460 | isolate->heap()->SetGlobalGCPrologueCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5461 | } |
| 5462 | |
| 5463 | |
| 5464 | void V8::SetGlobalGCEpilogueCallback(GCCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5465 | i::Isolate* isolate = i::Isolate::Current(); |
| 5466 | if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCEpilogueCallback()")) return; |
| 5467 | isolate->heap()->SetGlobalGCEpilogueCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5471 | void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5472 | i::Isolate* isolate = i::Isolate::Current(); |
| 5473 | if (IsDeadCheck(isolate, "v8::V8::AddGCPrologueCallback()")) return; |
| 5474 | isolate->heap()->AddGCPrologueCallback(callback, gc_type); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | |
| 5478 | void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5479 | i::Isolate* isolate = i::Isolate::Current(); |
| 5480 | if (IsDeadCheck(isolate, "v8::V8::RemoveGCPrologueCallback()")) return; |
| 5481 | isolate->heap()->RemoveGCPrologueCallback(callback); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | |
| 5485 | void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5486 | i::Isolate* isolate = i::Isolate::Current(); |
| 5487 | if (IsDeadCheck(isolate, "v8::V8::AddGCEpilogueCallback()")) return; |
| 5488 | isolate->heap()->AddGCEpilogueCallback(callback, gc_type); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5489 | } |
| 5490 | |
| 5491 | |
| 5492 | void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5493 | i::Isolate* isolate = i::Isolate::Current(); |
| 5494 | if (IsDeadCheck(isolate, "v8::V8::RemoveGCEpilogueCallback()")) return; |
| 5495 | isolate->heap()->RemoveGCEpilogueCallback(callback); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5496 | } |
| 5497 | |
| 5498 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5499 | void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 5500 | ObjectSpace space, |
| 5501 | AllocationAction action) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5502 | i::Isolate* isolate = i::Isolate::Current(); |
| 5503 | if (IsDeadCheck(isolate, "v8::V8::AddMemoryAllocationCallback()")) return; |
| 5504 | isolate->memory_allocator()->AddMemoryAllocationCallback( |
| 5505 | callback, space, action); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5506 | } |
| 5507 | |
| 5508 | |
| 5509 | void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5510 | i::Isolate* isolate = i::Isolate::Current(); |
| 5511 | if (IsDeadCheck(isolate, "v8::V8::RemoveMemoryAllocationCallback()")) return; |
| 5512 | isolate->memory_allocator()->RemoveMemoryAllocationCallback( |
| 5513 | callback); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5517 | void V8::AddCallCompletedCallback(CallCompletedCallback callback) { |
| 5518 | if (callback == NULL) return; |
danno@chromium.org | 74d57b1 | 2012-04-04 14:34:26 +0000 | [diff] [blame] | 5519 | i::Isolate::EnsureDefaultIsolate(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5520 | i::Isolate* isolate = i::Isolate::Current(); |
| 5521 | if (IsDeadCheck(isolate, "v8::V8::AddLeaveScriptCallback()")) return; |
| 5522 | i::V8::AddCallCompletedCallback(callback); |
| 5523 | } |
| 5524 | |
| 5525 | |
| 5526 | void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) { |
danno@chromium.org | 74d57b1 | 2012-04-04 14:34:26 +0000 | [diff] [blame] | 5527 | i::Isolate::EnsureDefaultIsolate(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5528 | i::Isolate* isolate = i::Isolate::Current(); |
| 5529 | if (IsDeadCheck(isolate, "v8::V8::RemoveLeaveScriptCallback()")) return; |
| 5530 | i::V8::RemoveCallCompletedCallback(callback); |
| 5531 | } |
| 5532 | |
| 5533 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5534 | void V8::PauseProfiler() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 5535 | i::Isolate* isolate = i::Isolate::Current(); |
| 5536 | isolate->logger()->PauseProfiler(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5537 | } |
| 5538 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5539 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5540 | void V8::ResumeProfiler() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 5541 | i::Isolate* isolate = i::Isolate::Current(); |
| 5542 | isolate->logger()->ResumeProfiler(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5543 | } |
| 5544 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5545 | |
| 5546 | bool V8::IsProfilerPaused() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 5547 | i::Isolate* isolate = i::Isolate::Current(); |
| 5548 | return isolate->logger()->IsProfilerPaused(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 5549 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5550 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5551 | |
| 5552 | int V8::GetCurrentThreadId() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5553 | i::Isolate* isolate = i::Isolate::Current(); |
| 5554 | EnsureInitializedForIsolate(isolate, "V8::GetCurrentThreadId()"); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5555 | return isolate->thread_id().ToInteger(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5556 | } |
| 5557 | |
| 5558 | |
| 5559 | void V8::TerminateExecution(int thread_id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5560 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5561 | if (!isolate->IsInitialized()) return; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 5562 | API_ENTRY_CHECK(isolate, "V8::TerminateExecution()"); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5563 | // If the thread_id identifies the current thread just terminate |
| 5564 | // execution right away. Otherwise, ask the thread manager to |
| 5565 | // terminate the thread with the given id if any. |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5566 | i::ThreadId internal_tid = i::ThreadId::FromInteger(thread_id); |
| 5567 | if (isolate->thread_id().Equals(internal_tid)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5568 | isolate->stack_guard()->TerminateExecution(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5569 | } else { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5570 | isolate->thread_manager()->TerminateExecution(internal_tid); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5571 | } |
| 5572 | } |
| 5573 | |
| 5574 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5575 | void V8::TerminateExecution(Isolate* isolate) { |
| 5576 | // If no isolate is supplied, use the default isolate. |
| 5577 | if (isolate != NULL) { |
| 5578 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution(); |
| 5579 | } else { |
| 5580 | i::Isolate::GetDefaultIsolateStackGuard()->TerminateExecution(); |
| 5581 | } |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5582 | } |
| 5583 | |
| 5584 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 5585 | bool V8::IsExecutionTerminating(Isolate* isolate) { |
| 5586 | i::Isolate* i_isolate = isolate != NULL ? |
| 5587 | reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current(); |
| 5588 | return IsExecutionTerminatingCheck(i_isolate); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5592 | Isolate* Isolate::GetCurrent() { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 5593 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5594 | return reinterpret_cast<Isolate*>(isolate); |
| 5595 | } |
| 5596 | |
| 5597 | |
| 5598 | Isolate* Isolate::New() { |
| 5599 | i::Isolate* isolate = new i::Isolate(); |
| 5600 | return reinterpret_cast<Isolate*>(isolate); |
| 5601 | } |
| 5602 | |
| 5603 | |
| 5604 | void Isolate::Dispose() { |
| 5605 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5606 | if (!ApiCheck(!isolate->IsInUse(), |
| 5607 | "v8::Isolate::Dispose()", |
| 5608 | "Disposing the isolate that is entered by a thread.")) { |
| 5609 | return; |
| 5610 | } |
| 5611 | isolate->TearDown(); |
| 5612 | } |
| 5613 | |
| 5614 | |
| 5615 | void Isolate::Enter() { |
| 5616 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5617 | isolate->Enter(); |
| 5618 | } |
| 5619 | |
| 5620 | |
| 5621 | void Isolate::Exit() { |
| 5622 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5623 | isolate->Exit(); |
| 5624 | } |
| 5625 | |
| 5626 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 5627 | void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { |
| 5628 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 5629 | i::Heap* heap = isolate->heap(); |
| 5630 | heap_statistics->total_heap_size_ = heap->CommittedMemory(); |
| 5631 | heap_statistics->total_heap_size_executable_ = |
| 5632 | heap->CommittedMemoryExecutable(); |
| 5633 | heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory(); |
| 5634 | heap_statistics->used_heap_size_ = heap->SizeOfObjects(); |
| 5635 | heap_statistics->heap_size_limit_ = heap->MaxReserved(); |
| 5636 | } |
| 5637 | |
| 5638 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5639 | String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) |
| 5640 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5641 | i::Isolate* isolate = i::Isolate::Current(); |
| 5642 | if (IsDeadCheck(isolate, "v8::String::Utf8Value::Utf8Value()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5643 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5644 | ENTER_V8(isolate); |
| 5645 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5646 | TryCatch try_catch; |
| 5647 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5648 | if (str.IsEmpty()) return; |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 5649 | i::Handle<i::String> i_str = Utils::OpenHandle(*str); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 5650 | length_ = v8::Utf8Length(*i_str, isolate); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5651 | str_ = i::NewArray<char>(length_ + 1); |
| 5652 | str->WriteUtf8(str_); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5653 | } |
| 5654 | |
| 5655 | |
| 5656 | String::Utf8Value::~Utf8Value() { |
| 5657 | i::DeleteArray(str_); |
| 5658 | } |
| 5659 | |
| 5660 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5661 | String::AsciiValue::AsciiValue(v8::Handle<v8::Value> obj) |
| 5662 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5663 | i::Isolate* isolate = i::Isolate::Current(); |
| 5664 | if (IsDeadCheck(isolate, "v8::String::AsciiValue::AsciiValue()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5665 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5666 | ENTER_V8(isolate); |
| 5667 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5668 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5669 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5670 | if (str.IsEmpty()) return; |
| 5671 | length_ = str->Length(); |
| 5672 | str_ = i::NewArray<char>(length_ + 1); |
| 5673 | str->WriteAscii(str_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | |
| 5677 | String::AsciiValue::~AsciiValue() { |
| 5678 | i::DeleteArray(str_); |
| 5679 | } |
| 5680 | |
| 5681 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5682 | String::Value::Value(v8::Handle<v8::Value> obj) |
| 5683 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5684 | i::Isolate* isolate = i::Isolate::Current(); |
| 5685 | if (IsDeadCheck(isolate, "v8::String::Value::Value()")) return; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5686 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5687 | ENTER_V8(isolate); |
| 5688 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5689 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5690 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5691 | if (str.IsEmpty()) return; |
| 5692 | length_ = str->Length(); |
| 5693 | str_ = i::NewArray<uint16_t>(length_ + 1); |
| 5694 | str->Write(str_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | |
| 5698 | String::Value::~Value() { |
| 5699 | i::DeleteArray(str_); |
| 5700 | } |
| 5701 | |
| 5702 | Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5703 | i::Isolate* isolate = i::Isolate::Current(); |
| 5704 | LOG_API(isolate, "RangeError"); |
| 5705 | ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5706 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5707 | i::Object* error; |
| 5708 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5709 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5710 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5711 | i::Handle<i::Object> result = isolate->factory()->NewRangeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5712 | error = *result; |
| 5713 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5714 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5715 | return Utils::ToLocal(result); |
| 5716 | } |
| 5717 | |
| 5718 | Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5719 | i::Isolate* isolate = i::Isolate::Current(); |
| 5720 | LOG_API(isolate, "ReferenceError"); |
| 5721 | ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5722 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5723 | i::Object* error; |
| 5724 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5725 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5726 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5727 | i::Handle<i::Object> result = |
| 5728 | isolate->factory()->NewReferenceError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5729 | error = *result; |
| 5730 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5731 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5732 | return Utils::ToLocal(result); |
| 5733 | } |
| 5734 | |
| 5735 | Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5736 | i::Isolate* isolate = i::Isolate::Current(); |
| 5737 | LOG_API(isolate, "SyntaxError"); |
| 5738 | ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5739 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5740 | i::Object* error; |
| 5741 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5742 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5743 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5744 | i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5745 | error = *result; |
| 5746 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5747 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5748 | return Utils::ToLocal(result); |
| 5749 | } |
| 5750 | |
| 5751 | Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5752 | i::Isolate* isolate = i::Isolate::Current(); |
| 5753 | LOG_API(isolate, "TypeError"); |
| 5754 | ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5755 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5756 | i::Object* error; |
| 5757 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5758 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5759 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5760 | i::Handle<i::Object> result = isolate->factory()->NewTypeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5761 | error = *result; |
| 5762 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5763 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5764 | return Utils::ToLocal(result); |
| 5765 | } |
| 5766 | |
| 5767 | Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5768 | i::Isolate* isolate = i::Isolate::Current(); |
| 5769 | LOG_API(isolate, "Error"); |
| 5770 | ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5771 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5772 | i::Object* error; |
| 5773 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5774 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5775 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5776 | i::Handle<i::Object> result = isolate->factory()->NewError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5777 | error = *result; |
| 5778 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5779 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5780 | return Utils::ToLocal(result); |
| 5781 | } |
| 5782 | |
| 5783 | |
| 5784 | // --- D e b u g S u p p o r t --- |
| 5785 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5786 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5787 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5788 | static void EventCallbackWrapper(const v8::Debug::EventDetails& event_details) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5789 | i::Isolate* isolate = i::Isolate::Current(); |
| 5790 | if (isolate->debug_event_callback() != NULL) { |
| 5791 | isolate->debug_event_callback()(event_details.GetEvent(), |
| 5792 | event_details.GetExecutionState(), |
| 5793 | event_details.GetEventData(), |
| 5794 | event_details.GetCallbackData()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5795 | } |
| 5796 | } |
| 5797 | |
| 5798 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5799 | bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5800 | i::Isolate* isolate = i::Isolate::Current(); |
| 5801 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener()"); |
| 5802 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5803 | ENTER_V8(isolate); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5804 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5805 | isolate->set_debug_event_callback(that); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5806 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5807 | i::HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5808 | i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5809 | if (that != NULL) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5810 | foreign = |
| 5811 | isolate->factory()->NewForeign(FUNCTION_ADDR(EventCallbackWrapper)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5812 | } |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 5813 | isolate->debugger()->SetEventListener(foreign, |
| 5814 | Utils::OpenHandle(*data, true)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5815 | return true; |
| 5816 | } |
| 5817 | |
| 5818 | |
| 5819 | bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5820 | i::Isolate* isolate = i::Isolate::Current(); |
| 5821 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()"); |
| 5822 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5823 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5824 | i::HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5825 | i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5826 | if (that != NULL) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5827 | foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5828 | } |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 5829 | isolate->debugger()->SetEventListener(foreign, |
| 5830 | Utils::OpenHandle(*data, true)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5831 | return true; |
| 5832 | } |
| 5833 | |
| 5834 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5835 | bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5836 | Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5837 | i::Isolate* isolate = i::Isolate::Current(); |
| 5838 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5839 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5840 | isolate->debugger()->SetEventListener(Utils::OpenHandle(*that), |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 5841 | Utils::OpenHandle(*data, true)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5842 | return true; |
| 5843 | } |
| 5844 | |
| 5845 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5846 | void Debug::DebugBreak(Isolate* isolate) { |
| 5847 | // If no isolate is supplied, use the default isolate. |
| 5848 | if (isolate != NULL) { |
| 5849 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->DebugBreak(); |
| 5850 | } else { |
| 5851 | i::Isolate::GetDefaultIsolateStackGuard()->DebugBreak(); |
| 5852 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5856 | void Debug::CancelDebugBreak(Isolate* isolate) { |
| 5857 | // If no isolate is supplied, use the default isolate. |
| 5858 | if (isolate != NULL) { |
| 5859 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5860 | internal_isolate->stack_guard()->Continue(i::DEBUGBREAK); |
| 5861 | } else { |
| 5862 | i::Isolate::GetDefaultIsolateStackGuard()->Continue(i::DEBUGBREAK); |
| 5863 | } |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5867 | void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) { |
| 5868 | // If no isolate is supplied, use the default isolate. |
| 5869 | if (isolate != NULL) { |
| 5870 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5871 | internal_isolate->debugger()->EnqueueDebugCommand(data); |
| 5872 | } else { |
| 5873 | i::Isolate::GetDefaultIsolateDebugger()->EnqueueDebugCommand(data); |
| 5874 | } |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 5875 | } |
| 5876 | |
| 5877 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5878 | static void MessageHandlerWrapper(const v8::Debug::Message& message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5879 | i::Isolate* isolate = i::Isolate::Current(); |
| 5880 | if (isolate->message_handler()) { |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5881 | v8::String::Value json(message.GetJSON()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5882 | (isolate->message_handler())(*json, json.length(), message.GetClientData()); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5887 | void Debug::SetMessageHandler(v8::Debug::MessageHandler handler, |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5888 | bool message_handler_thread) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5889 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5890 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); |
| 5891 | ENTER_V8(isolate); |
| 5892 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5893 | // Message handler thread not supported any more. Parameter temporally left in |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5894 | // the API for client compatibility reasons. |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5895 | CHECK(!message_handler_thread); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5896 | |
| 5897 | // 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] | 5898 | isolate->set_message_handler(handler); |
| 5899 | if (handler != NULL) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5900 | isolate->debugger()->SetMessageHandler(MessageHandlerWrapper); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5901 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5902 | isolate->debugger()->SetMessageHandler(NULL); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5903 | } |
| 5904 | } |
| 5905 | |
| 5906 | |
| 5907 | void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5908 | i::Isolate* isolate = i::Isolate::Current(); |
| 5909 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); |
| 5910 | ENTER_V8(isolate); |
| 5911 | isolate->debugger()->SetMessageHandler(handler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5915 | void Debug::SendCommand(const uint16_t* command, int length, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5916 | ClientData* client_data, |
| 5917 | Isolate* isolate) { |
| 5918 | // If no isolate is supplied, use the default isolate. |
| 5919 | if (isolate != NULL) { |
| 5920 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5921 | internal_isolate->debugger()->ProcessCommand( |
| 5922 | i::Vector<const uint16_t>(command, length), client_data); |
| 5923 | } else { |
| 5924 | i::Isolate::GetDefaultIsolateDebugger()->ProcessCommand( |
| 5925 | i::Vector<const uint16_t>(command, length), client_data); |
| 5926 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5927 | } |
| 5928 | |
| 5929 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5930 | void Debug::SetHostDispatchHandler(HostDispatchHandler handler, |
| 5931 | int period) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5932 | i::Isolate* isolate = i::Isolate::Current(); |
| 5933 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetHostDispatchHandler"); |
| 5934 | ENTER_V8(isolate); |
| 5935 | isolate->debugger()->SetHostDispatchHandler(handler, period); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5936 | } |
| 5937 | |
| 5938 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5939 | void Debug::SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5940 | DebugMessageDispatchHandler handler, bool provide_locker) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5941 | i::Isolate* isolate = i::Isolate::Current(); |
| 5942 | EnsureInitializedForIsolate(isolate, |
| 5943 | "v8::Debug::SetDebugMessageDispatchHandler"); |
| 5944 | ENTER_V8(isolate); |
| 5945 | isolate->debugger()->SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5946 | handler, provide_locker); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5947 | } |
| 5948 | |
| 5949 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5950 | Local<Value> Debug::Call(v8::Handle<v8::Function> fun, |
| 5951 | v8::Handle<v8::Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5952 | i::Isolate* isolate = i::Isolate::Current(); |
| 5953 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 5954 | ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5955 | ENTER_V8(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5956 | i::Handle<i::Object> result; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5957 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5958 | if (data.IsEmpty()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5959 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 5960 | isolate->factory()->undefined_value(), |
| 5961 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5962 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5963 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 5964 | Utils::OpenHandle(*data), |
| 5965 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5966 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5967 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5968 | return Utils::ToLocal(result); |
| 5969 | } |
| 5970 | |
| 5971 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5972 | Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5973 | i::Isolate* isolate = i::Isolate::Current(); |
| 5974 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 5975 | ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5976 | ENTER_V8(isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5977 | v8::HandleScope scope; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5978 | i::Debug* isolate_debug = isolate->debug(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5979 | isolate_debug->Load(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5980 | i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global_object()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 5981 | i::Handle<i::String> name = isolate->factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 5982 | STATIC_ASCII_VECTOR("MakeMirror")); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5983 | i::Handle<i::Object> fun_obj = i::GetProperty(isolate, debug, name); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5984 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj); |
| 5985 | v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun); |
| 5986 | const int kArgc = 1; |
| 5987 | v8::Handle<v8::Value> argv[kArgc] = { obj }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5988 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5989 | v8::Handle<v8::Value> result = v8_fun->Call(Utils::ToLocal(debug), |
| 5990 | kArgc, |
| 5991 | argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5992 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5993 | return scope.Close(result); |
| 5994 | } |
| 5995 | |
| 5996 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5997 | 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] | 5998 | return i::Isolate::Current()->debugger()->StartAgent(name, port, |
| 5999 | wait_for_connection); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6000 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6001 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6002 | |
| 6003 | void Debug::DisableAgent() { |
| 6004 | return i::Isolate::Current()->debugger()->StopAgent(); |
| 6005 | } |
| 6006 | |
| 6007 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6008 | void Debug::ProcessDebugMessages() { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6009 | i::Execution::ProcessDebugMessages(true); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6010 | } |
| 6011 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 6012 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 6013 | Local<Context> Debug::GetDebugContext() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6014 | i::Isolate* isolate = i::Isolate::Current(); |
| 6015 | EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()"); |
| 6016 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6017 | return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext()); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 6018 | } |
| 6019 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 6020 | |
| 6021 | void Debug::SetLiveEditEnabled(bool enable, Isolate* isolate) { |
| 6022 | // If no isolate is supplied, use the default isolate. |
| 6023 | i::Debugger* debugger; |
| 6024 | if (isolate != NULL) { |
| 6025 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6026 | debugger = internal_isolate->debugger(); |
| 6027 | } else { |
| 6028 | debugger = i::Isolate::GetDefaultIsolateDebugger(); |
| 6029 | } |
| 6030 | debugger->set_live_edit_enabled(enable); |
| 6031 | } |
| 6032 | |
| 6033 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6034 | #endif // ENABLE_DEBUGGER_SUPPORT |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6035 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6036 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6037 | Handle<String> CpuProfileNode::GetFunctionName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6038 | i::Isolate* isolate = i::Isolate::Current(); |
| 6039 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetFunctionName"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6040 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
| 6041 | const i::CodeEntry* entry = node->entry(); |
| 6042 | if (!entry->has_name_prefix()) { |
| 6043 | return Handle<String>(ToApi<String>( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6044 | isolate->factory()->InternalizeUtf8String(entry->name()))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6045 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6046 | return Handle<String>(ToApi<String>(isolate->factory()->NewConsString( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6047 | isolate->factory()->InternalizeUtf8String(entry->name_prefix()), |
| 6048 | isolate->factory()->InternalizeUtf8String(entry->name())))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6049 | } |
| 6050 | } |
| 6051 | |
| 6052 | |
| 6053 | Handle<String> CpuProfileNode::GetScriptResourceName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6054 | i::Isolate* isolate = i::Isolate::Current(); |
| 6055 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetScriptResourceName"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6056 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6057 | return Handle<String>(ToApi<String>(isolate->factory()->InternalizeUtf8String( |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6058 | node->entry()->resource_name()))); |
| 6059 | } |
| 6060 | |
| 6061 | |
| 6062 | int CpuProfileNode::GetLineNumber() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6063 | i::Isolate* isolate = i::Isolate::Current(); |
| 6064 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetLineNumber"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6065 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number(); |
| 6066 | } |
| 6067 | |
| 6068 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6069 | double CpuProfileNode::GetTotalTime() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6070 | i::Isolate* isolate = i::Isolate::Current(); |
| 6071 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalTime"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6072 | return reinterpret_cast<const i::ProfileNode*>(this)->GetTotalMillis(); |
| 6073 | } |
| 6074 | |
| 6075 | |
| 6076 | double CpuProfileNode::GetSelfTime() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6077 | i::Isolate* isolate = i::Isolate::Current(); |
| 6078 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfTime"); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6079 | return reinterpret_cast<const i::ProfileNode*>(this)->GetSelfMillis(); |
| 6080 | } |
| 6081 | |
| 6082 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6083 | double CpuProfileNode::GetTotalSamplesCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6084 | i::Isolate* isolate = i::Isolate::Current(); |
| 6085 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalSamplesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6086 | return reinterpret_cast<const i::ProfileNode*>(this)->total_ticks(); |
| 6087 | } |
| 6088 | |
| 6089 | |
| 6090 | double CpuProfileNode::GetSelfSamplesCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6091 | i::Isolate* isolate = i::Isolate::Current(); |
| 6092 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfSamplesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6093 | return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks(); |
| 6094 | } |
| 6095 | |
| 6096 | |
| 6097 | unsigned CpuProfileNode::GetCallUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6098 | i::Isolate* isolate = i::Isolate::Current(); |
| 6099 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetCallUid"); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 6100 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | |
| 6104 | int CpuProfileNode::GetChildrenCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6105 | i::Isolate* isolate = i::Isolate::Current(); |
| 6106 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetChildrenCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6107 | return reinterpret_cast<const i::ProfileNode*>(this)->children()->length(); |
| 6108 | } |
| 6109 | |
| 6110 | |
| 6111 | const CpuProfileNode* CpuProfileNode::GetChild(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6112 | i::Isolate* isolate = i::Isolate::Current(); |
| 6113 | IsDeadCheck(isolate, "v8::CpuProfileNode::GetChild"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6114 | const i::ProfileNode* child = |
| 6115 | reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index); |
| 6116 | return reinterpret_cast<const CpuProfileNode*>(child); |
| 6117 | } |
| 6118 | |
| 6119 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6120 | void CpuProfile::Delete() { |
| 6121 | i::Isolate* isolate = i::Isolate::Current(); |
| 6122 | IsDeadCheck(isolate, "v8::CpuProfile::Delete"); |
| 6123 | i::CpuProfiler::DeleteProfile(reinterpret_cast<i::CpuProfile*>(this)); |
| 6124 | if (i::CpuProfiler::GetProfilesCount() == 0 && |
| 6125 | !i::CpuProfiler::HasDetachedProfiles()) { |
| 6126 | // If this was the last profile, clean up all accessory data as well. |
| 6127 | i::CpuProfiler::DeleteAllProfiles(); |
| 6128 | } |
| 6129 | } |
| 6130 | |
| 6131 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6132 | unsigned CpuProfile::GetUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6133 | i::Isolate* isolate = i::Isolate::Current(); |
| 6134 | IsDeadCheck(isolate, "v8::CpuProfile::GetUid"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6135 | return reinterpret_cast<const i::CpuProfile*>(this)->uid(); |
| 6136 | } |
| 6137 | |
| 6138 | |
| 6139 | Handle<String> CpuProfile::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6140 | i::Isolate* isolate = i::Isolate::Current(); |
| 6141 | IsDeadCheck(isolate, "v8::CpuProfile::GetTitle"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6142 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6143 | return Handle<String>(ToApi<String>(isolate->factory()->InternalizeUtf8String( |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6144 | profile->title()))); |
| 6145 | } |
| 6146 | |
| 6147 | |
| 6148 | const CpuProfileNode* CpuProfile::GetBottomUpRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6149 | i::Isolate* isolate = i::Isolate::Current(); |
| 6150 | IsDeadCheck(isolate, "v8::CpuProfile::GetBottomUpRoot"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6151 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 6152 | return reinterpret_cast<const CpuProfileNode*>(profile->bottom_up()->root()); |
| 6153 | } |
| 6154 | |
| 6155 | |
| 6156 | const CpuProfileNode* CpuProfile::GetTopDownRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6157 | i::Isolate* isolate = i::Isolate::Current(); |
| 6158 | IsDeadCheck(isolate, "v8::CpuProfile::GetTopDownRoot"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6159 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 6160 | return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root()); |
| 6161 | } |
| 6162 | |
| 6163 | |
| 6164 | int CpuProfiler::GetProfilesCount() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6165 | i::Isolate* isolate = i::Isolate::Current(); |
| 6166 | IsDeadCheck(isolate, "v8::CpuProfiler::GetProfilesCount"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6167 | return i::CpuProfiler::GetProfilesCount(); |
| 6168 | } |
| 6169 | |
| 6170 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6171 | const CpuProfile* CpuProfiler::GetProfile(int index, |
| 6172 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6173 | i::Isolate* isolate = i::Isolate::Current(); |
| 6174 | IsDeadCheck(isolate, "v8::CpuProfiler::GetProfile"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6175 | return reinterpret_cast<const CpuProfile*>( |
| 6176 | i::CpuProfiler::GetProfile( |
| 6177 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 6178 | index)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6182 | const CpuProfile* CpuProfiler::FindProfile(unsigned uid, |
| 6183 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6184 | i::Isolate* isolate = i::Isolate::Current(); |
| 6185 | IsDeadCheck(isolate, "v8::CpuProfiler::FindProfile"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6186 | return reinterpret_cast<const CpuProfile*>( |
| 6187 | i::CpuProfiler::FindProfile( |
| 6188 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 6189 | uid)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | |
| 6193 | void CpuProfiler::StartProfiling(Handle<String> title) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6194 | i::Isolate* isolate = i::Isolate::Current(); |
| 6195 | IsDeadCheck(isolate, "v8::CpuProfiler::StartProfiling"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6196 | i::CpuProfiler::StartProfiling(*Utils::OpenHandle(*title)); |
| 6197 | } |
| 6198 | |
| 6199 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6200 | const CpuProfile* CpuProfiler::StopProfiling(Handle<String> title, |
| 6201 | Handle<Value> security_token) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6202 | i::Isolate* isolate = i::Isolate::Current(); |
| 6203 | IsDeadCheck(isolate, "v8::CpuProfiler::StopProfiling"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6204 | return reinterpret_cast<const CpuProfile*>( |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6205 | i::CpuProfiler::StopProfiling( |
| 6206 | security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), |
| 6207 | *Utils::OpenHandle(*title))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6208 | } |
| 6209 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6210 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6211 | void CpuProfiler::DeleteAllProfiles() { |
| 6212 | i::Isolate* isolate = i::Isolate::Current(); |
| 6213 | IsDeadCheck(isolate, "v8::CpuProfiler::DeleteAllProfiles"); |
| 6214 | i::CpuProfiler::DeleteAllProfiles(); |
| 6215 | } |
| 6216 | |
| 6217 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6218 | static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) { |
| 6219 | return const_cast<i::HeapGraphEdge*>( |
| 6220 | reinterpret_cast<const i::HeapGraphEdge*>(edge)); |
| 6221 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 6222 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6223 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6224 | HeapGraphEdge::Type HeapGraphEdge::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6225 | i::Isolate* isolate = i::Isolate::Current(); |
| 6226 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetType"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6227 | return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | |
| 6231 | Handle<Value> HeapGraphEdge::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6232 | i::Isolate* isolate = i::Isolate::Current(); |
| 6233 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetName"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6234 | i::HeapGraphEdge* edge = ToInternal(this); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6235 | switch (edge->type()) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6236 | case i::HeapGraphEdge::kContextVariable: |
| 6237 | case i::HeapGraphEdge::kInternal: |
| 6238 | case i::HeapGraphEdge::kProperty: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 6239 | case i::HeapGraphEdge::kShortcut: |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6240 | return Handle<String>(ToApi<String>( |
| 6241 | isolate->factory()->InternalizeUtf8String(edge->name()))); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6242 | case i::HeapGraphEdge::kElement: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 6243 | case i::HeapGraphEdge::kHidden: |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6244 | return Handle<Number>(ToApi<Number>( |
| 6245 | isolate->factory()->NewNumberFromInt(edge->index()))); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6246 | default: UNREACHABLE(); |
| 6247 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6248 | return v8::Undefined(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | |
| 6252 | const HeapGraphNode* HeapGraphEdge::GetFromNode() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6253 | i::Isolate* isolate = i::Isolate::Current(); |
| 6254 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetFromNode"); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6255 | const i::HeapEntry* from = ToInternal(this)->from(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6256 | return reinterpret_cast<const HeapGraphNode*>(from); |
| 6257 | } |
| 6258 | |
| 6259 | |
| 6260 | const HeapGraphNode* HeapGraphEdge::GetToNode() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6261 | i::Isolate* isolate = i::Isolate::Current(); |
| 6262 | IsDeadCheck(isolate, "v8::HeapGraphEdge::GetToNode"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6263 | const i::HeapEntry* to = ToInternal(this)->to(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6264 | return reinterpret_cast<const HeapGraphNode*>(to); |
| 6265 | } |
| 6266 | |
| 6267 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6268 | static i::HeapEntry* ToInternal(const HeapGraphNode* entry) { |
| 6269 | return const_cast<i::HeapEntry*>( |
| 6270 | reinterpret_cast<const i::HeapEntry*>(entry)); |
| 6271 | } |
| 6272 | |
| 6273 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6274 | HeapGraphNode::Type HeapGraphNode::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6275 | i::Isolate* isolate = i::Isolate::Current(); |
| 6276 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetType"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6277 | return static_cast<HeapGraphNode::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6278 | } |
| 6279 | |
| 6280 | |
| 6281 | Handle<String> HeapGraphNode::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6282 | i::Isolate* isolate = i::Isolate::Current(); |
| 6283 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetName"); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6284 | return Handle<String>(ToApi<String>(isolate->factory()->InternalizeUtf8String( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6285 | ToInternal(this)->name()))); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6286 | } |
| 6287 | |
| 6288 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6289 | SnapshotObjectId HeapGraphNode::GetId() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6290 | i::Isolate* isolate = i::Isolate::Current(); |
| 6291 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetId"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6292 | return ToInternal(this)->id(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6296 | int HeapGraphNode::GetSelfSize() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6297 | i::Isolate* isolate = i::Isolate::Current(); |
| 6298 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetSelfSize"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6299 | return ToInternal(this)->self_size(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6300 | } |
| 6301 | |
| 6302 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6303 | int HeapGraphNode::GetChildrenCount() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6304 | i::Isolate* isolate = i::Isolate::Current(); |
| 6305 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetChildrenCount"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6306 | return ToInternal(this)->children().length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6307 | } |
| 6308 | |
| 6309 | |
| 6310 | const HeapGraphEdge* HeapGraphNode::GetChild(int index) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6311 | i::Isolate* isolate = i::Isolate::Current(); |
| 6312 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetChild"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6313 | return reinterpret_cast<const HeapGraphEdge*>( |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 6314 | ToInternal(this)->children()[index]); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6315 | } |
| 6316 | |
| 6317 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6318 | v8::Handle<v8::Value> HeapGraphNode::GetHeapValue() const { |
| 6319 | i::Isolate* isolate = i::Isolate::Current(); |
| 6320 | IsDeadCheck(isolate, "v8::HeapGraphNode::GetHeapValue"); |
| 6321 | i::Handle<i::HeapObject> object = ToInternal(this)->GetHeapObject(); |
| 6322 | return v8::Handle<Value>(!object.is_null() ? |
| 6323 | ToApi<Value>(object) : ToApi<Value>( |
| 6324 | isolate->factory()->undefined_value())); |
| 6325 | } |
| 6326 | |
| 6327 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6328 | static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) { |
| 6329 | return const_cast<i::HeapSnapshot*>( |
| 6330 | reinterpret_cast<const i::HeapSnapshot*>(snapshot)); |
| 6331 | } |
| 6332 | |
| 6333 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6334 | void HeapSnapshot::Delete() { |
| 6335 | i::Isolate* isolate = i::Isolate::Current(); |
| 6336 | IsDeadCheck(isolate, "v8::HeapSnapshot::Delete"); |
| 6337 | if (i::HeapProfiler::GetSnapshotsCount() > 1) { |
| 6338 | ToInternal(this)->Delete(); |
| 6339 | } else { |
| 6340 | // If this is the last snapshot, clean up all accessory data as well. |
| 6341 | i::HeapProfiler::DeleteAllSnapshots(); |
| 6342 | } |
| 6343 | } |
| 6344 | |
| 6345 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6346 | HeapSnapshot::Type HeapSnapshot::GetType() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6347 | i::Isolate* isolate = i::Isolate::Current(); |
| 6348 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetType"); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6349 | return static_cast<HeapSnapshot::Type>(ToInternal(this)->type()); |
| 6350 | } |
| 6351 | |
| 6352 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6353 | unsigned HeapSnapshot::GetUid() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6354 | i::Isolate* isolate = i::Isolate::Current(); |
| 6355 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetUid"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6356 | return ToInternal(this)->uid(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6357 | } |
| 6358 | |
| 6359 | |
| 6360 | Handle<String> HeapSnapshot::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6361 | i::Isolate* isolate = i::Isolate::Current(); |
| 6362 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetTitle"); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 6363 | return Handle<String>(ToApi<String>(isolate->factory()->InternalizeUtf8String( |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6364 | ToInternal(this)->title()))); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6365 | } |
| 6366 | |
| 6367 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 6368 | const HeapGraphNode* HeapSnapshot::GetRoot() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6369 | i::Isolate* isolate = i::Isolate::Current(); |
| 6370 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetHead"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6371 | return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6372 | } |
| 6373 | |
| 6374 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6375 | const HeapGraphNode* HeapSnapshot::GetNodeById(SnapshotObjectId id) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6376 | i::Isolate* isolate = i::Isolate::Current(); |
| 6377 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodeById"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6378 | return reinterpret_cast<const HeapGraphNode*>( |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6379 | ToInternal(this)->GetEntryById(id)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
| 6382 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 6383 | int HeapSnapshot::GetNodesCount() const { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 6384 | i::Isolate* isolate = i::Isolate::Current(); |
| 6385 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodesCount"); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 6386 | return ToInternal(this)->entries().length(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 6387 | } |
| 6388 | |
| 6389 | |
| 6390 | const HeapGraphNode* HeapSnapshot::GetNode(int index) const { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 6391 | i::Isolate* isolate = i::Isolate::Current(); |
| 6392 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetNode"); |
| 6393 | return reinterpret_cast<const HeapGraphNode*>( |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 6394 | &ToInternal(this)->entries().at(index)); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 6395 | } |
| 6396 | |
| 6397 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6398 | SnapshotObjectId HeapSnapshot::GetMaxSnapshotJSObjectId() const { |
| 6399 | i::Isolate* isolate = i::Isolate::Current(); |
| 6400 | IsDeadCheck(isolate, "v8::HeapSnapshot::GetMaxSnapshotJSObjectId"); |
| 6401 | return ToInternal(this)->max_snapshot_js_object_id(); |
| 6402 | } |
| 6403 | |
| 6404 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6405 | void HeapSnapshot::Serialize(OutputStream* stream, |
| 6406 | HeapSnapshot::SerializationFormat format) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6407 | i::Isolate* isolate = i::Isolate::Current(); |
| 6408 | IsDeadCheck(isolate, "v8::HeapSnapshot::Serialize"); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 6409 | ApiCheck(format == kJSON, |
| 6410 | "v8::HeapSnapshot::Serialize", |
| 6411 | "Unknown serialization format"); |
| 6412 | ApiCheck(stream->GetOutputEncoding() == OutputStream::kAscii, |
| 6413 | "v8::HeapSnapshot::Serialize", |
| 6414 | "Unsupported output encoding"); |
| 6415 | ApiCheck(stream->GetChunkSize() > 0, |
| 6416 | "v8::HeapSnapshot::Serialize", |
| 6417 | "Invalid stream chunk size"); |
| 6418 | i::HeapSnapshotJSONSerializer serializer(ToInternal(this)); |
| 6419 | serializer.Serialize(stream); |
| 6420 | } |
| 6421 | |
| 6422 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6423 | int HeapProfiler::GetSnapshotsCount() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6424 | i::Isolate* isolate = i::Isolate::Current(); |
| 6425 | IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotsCount"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6426 | return i::HeapProfiler::GetSnapshotsCount(); |
| 6427 | } |
| 6428 | |
| 6429 | |
| 6430 | const HeapSnapshot* HeapProfiler::GetSnapshot(int index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6431 | i::Isolate* isolate = i::Isolate::Current(); |
| 6432 | IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshot"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6433 | return reinterpret_cast<const HeapSnapshot*>( |
| 6434 | i::HeapProfiler::GetSnapshot(index)); |
| 6435 | } |
| 6436 | |
| 6437 | |
| 6438 | const HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6439 | i::Isolate* isolate = i::Isolate::Current(); |
| 6440 | IsDeadCheck(isolate, "v8::HeapProfiler::FindSnapshot"); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6441 | return reinterpret_cast<const HeapSnapshot*>( |
| 6442 | i::HeapProfiler::FindSnapshot(uid)); |
| 6443 | } |
| 6444 | |
| 6445 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6446 | SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Value> value) { |
| 6447 | i::Isolate* isolate = i::Isolate::Current(); |
| 6448 | IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotObjectId"); |
| 6449 | i::Handle<i::Object> obj = Utils::OpenHandle(*value); |
| 6450 | return i::HeapProfiler::GetSnapshotObjectId(obj); |
| 6451 | } |
| 6452 | |
| 6453 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6454 | const HeapSnapshot* HeapProfiler::TakeSnapshot(Handle<String> title, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 6455 | HeapSnapshot::Type type, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 6456 | ActivityControl* control, |
| 6457 | ObjectNameResolver* resolver) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6458 | i::Isolate* isolate = i::Isolate::Current(); |
| 6459 | IsDeadCheck(isolate, "v8::HeapProfiler::TakeSnapshot"); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6460 | i::HeapSnapshot::Type internal_type = i::HeapSnapshot::kFull; |
| 6461 | switch (type) { |
| 6462 | case HeapSnapshot::kFull: |
| 6463 | internal_type = i::HeapSnapshot::kFull; |
| 6464 | break; |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6465 | default: |
| 6466 | UNREACHABLE(); |
| 6467 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6468 | return reinterpret_cast<const HeapSnapshot*>( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 6469 | i::HeapProfiler::TakeSnapshot( |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 6470 | *Utils::OpenHandle(*title), internal_type, control, resolver)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 6471 | } |
| 6472 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6473 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 6474 | void HeapProfiler::StartHeapObjectsTracking() { |
| 6475 | i::Isolate* isolate = i::Isolate::Current(); |
| 6476 | IsDeadCheck(isolate, "v8::HeapProfiler::StartHeapObjectsTracking"); |
| 6477 | i::HeapProfiler::StartHeapObjectsTracking(); |
| 6478 | } |
| 6479 | |
| 6480 | |
| 6481 | void HeapProfiler::StopHeapObjectsTracking() { |
| 6482 | i::Isolate* isolate = i::Isolate::Current(); |
| 6483 | IsDeadCheck(isolate, "v8::HeapProfiler::StopHeapObjectsTracking"); |
| 6484 | i::HeapProfiler::StopHeapObjectsTracking(); |
| 6485 | } |
| 6486 | |
| 6487 | |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 6488 | SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) { |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 6489 | i::Isolate* isolate = i::Isolate::Current(); |
| 6490 | IsDeadCheck(isolate, "v8::HeapProfiler::PushHeapObjectsStats"); |
| 6491 | return i::HeapProfiler::PushHeapObjectsStats(stream); |
| 6492 | } |
| 6493 | |
| 6494 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6495 | void HeapProfiler::DeleteAllSnapshots() { |
| 6496 | i::Isolate* isolate = i::Isolate::Current(); |
| 6497 | IsDeadCheck(isolate, "v8::HeapProfiler::DeleteAllSnapshots"); |
| 6498 | i::HeapProfiler::DeleteAllSnapshots(); |
| 6499 | } |
| 6500 | |
| 6501 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6502 | void HeapProfiler::DefineWrapperClass(uint16_t class_id, |
| 6503 | WrapperInfoCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6504 | i::Isolate::Current()->heap_profiler()->DefineWrapperClass(class_id, |
| 6505 | callback); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6506 | } |
| 6507 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6508 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6509 | int HeapProfiler::GetPersistentHandleCount() { |
| 6510 | i::Isolate* isolate = i::Isolate::Current(); |
| 6511 | return isolate->global_handles()->NumberOfGlobalHandles(); |
| 6512 | } |
| 6513 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6514 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 6515 | size_t HeapProfiler::GetMemorySizeUsedByProfiler() { |
| 6516 | return i::HeapProfiler::GetMemorySizeUsedByProfiler(); |
| 6517 | } |
| 6518 | |
| 6519 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6520 | v8::Testing::StressType internal::Testing::stress_type_ = |
| 6521 | v8::Testing::kStressTypeOpt; |
| 6522 | |
| 6523 | |
| 6524 | void Testing::SetStressRunType(Testing::StressType type) { |
| 6525 | internal::Testing::set_stress_type(type); |
| 6526 | } |
| 6527 | |
| 6528 | int Testing::GetStressRuns() { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 6529 | if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6530 | #ifdef DEBUG |
| 6531 | // In debug mode the code runs much slower so stressing will only make two |
| 6532 | // runs. |
| 6533 | return 2; |
| 6534 | #else |
| 6535 | return 5; |
| 6536 | #endif |
| 6537 | } |
| 6538 | |
| 6539 | |
| 6540 | static void SetFlagsFromString(const char* flags) { |
| 6541 | V8::SetFlagsFromString(flags, i::StrLength(flags)); |
| 6542 | } |
| 6543 | |
| 6544 | |
| 6545 | void Testing::PrepareStressRun(int run) { |
| 6546 | static const char* kLazyOptimizations = |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 6547 | "--prepare-always-opt " |
| 6548 | "--max-inlined-source-size=999999 " |
| 6549 | "--max-inlined-nodes=999999 " |
| 6550 | "--max-inlined-nodes-cumulative=999999 " |
| 6551 | "--noalways-opt"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6552 | static const char* kForcedOptimizations = "--always-opt"; |
| 6553 | |
| 6554 | // If deoptimization stressed turn on frequent deoptimization. If no value |
| 6555 | // is spefified through --deopt-every-n-times use a default default value. |
| 6556 | static const char* kDeoptEvery13Times = "--deopt-every-n-times=13"; |
| 6557 | if (internal::Testing::stress_type() == Testing::kStressTypeDeopt && |
| 6558 | internal::FLAG_deopt_every_n_times == 0) { |
| 6559 | SetFlagsFromString(kDeoptEvery13Times); |
| 6560 | } |
| 6561 | |
| 6562 | #ifdef DEBUG |
| 6563 | // As stressing in debug mode only make two runs skip the deopt stressing |
| 6564 | // here. |
| 6565 | if (run == GetStressRuns() - 1) { |
| 6566 | SetFlagsFromString(kForcedOptimizations); |
| 6567 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6568 | SetFlagsFromString(kLazyOptimizations); |
| 6569 | } |
| 6570 | #else |
| 6571 | if (run == GetStressRuns() - 1) { |
| 6572 | SetFlagsFromString(kForcedOptimizations); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 6573 | } else if (run != GetStressRuns() - 2) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6574 | SetFlagsFromString(kLazyOptimizations); |
| 6575 | } |
| 6576 | #endif |
| 6577 | } |
| 6578 | |
| 6579 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 6580 | // TODO(svenpanne) Deprecate this. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6581 | void Testing::DeoptimizeAll() { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 6582 | i::Isolate* isolate = i::Isolate::Current(); |
| 6583 | i::HandleScope scope(isolate); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6584 | internal::Deoptimizer::DeoptimizeAll(); |
| 6585 | } |
| 6586 | |
| 6587 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6588 | namespace internal { |
| 6589 | |
| 6590 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6591 | void HandleScopeImplementer::FreeThreadResources() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6592 | Free(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6593 | } |
| 6594 | |
| 6595 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6596 | char* HandleScopeImplementer::ArchiveThread(char* storage) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 6597 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6598 | isolate_->handle_scope_data(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6599 | handle_scope_data_ = *current; |
| 6600 | memcpy(storage, this, sizeof(*this)); |
| 6601 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6602 | ResetAfterArchive(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6603 | current->Initialize(); |
| 6604 | |
| 6605 | return storage + ArchiveSpacePerThread(); |
| 6606 | } |
| 6607 | |
| 6608 | |
| 6609 | int HandleScopeImplementer::ArchiveSpacePerThread() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6610 | return sizeof(HandleScopeImplementer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6611 | } |
| 6612 | |
| 6613 | |
| 6614 | char* HandleScopeImplementer::RestoreThread(char* storage) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6615 | memcpy(this, storage, sizeof(*this)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6616 | *isolate_->handle_scope_data() = handle_scope_data_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6617 | return storage + ArchiveSpacePerThread(); |
| 6618 | } |
| 6619 | |
| 6620 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6621 | void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 6622 | #ifdef DEBUG |
| 6623 | bool found_block_before_deferred = false; |
| 6624 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6625 | // Iterate over all handles in the blocks except for the last. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6626 | for (int i = blocks()->length() - 2; i >= 0; --i) { |
| 6627 | Object** block = blocks()->at(i); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 6628 | if (last_handle_before_deferred_block_ != NULL && |
| 6629 | (last_handle_before_deferred_block_ < &block[kHandleBlockSize]) && |
| 6630 | (last_handle_before_deferred_block_ >= block)) { |
| 6631 | v->VisitPointers(block, last_handle_before_deferred_block_); |
| 6632 | ASSERT(!found_block_before_deferred); |
| 6633 | #ifdef DEBUG |
| 6634 | found_block_before_deferred = true; |
| 6635 | #endif |
| 6636 | } else { |
| 6637 | v->VisitPointers(block, &block[kHandleBlockSize]); |
| 6638 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6639 | } |
| 6640 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 6641 | ASSERT(last_handle_before_deferred_block_ == NULL || |
| 6642 | found_block_before_deferred); |
| 6643 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6644 | // Iterate over live handles in the last block (if any). |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6645 | if (!blocks()->is_empty()) { |
| 6646 | v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | if (!saved_contexts_.is_empty()) { |
| 6650 | Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
| 6651 | v->VisitPointers(start, start + saved_contexts_.length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6652 | } |
| 6653 | } |
| 6654 | |
| 6655 | |
| 6656 | void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 6657 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6658 | isolate_->handle_scope_data(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6659 | handle_scope_data_ = *current; |
| 6660 | IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6661 | } |
| 6662 | |
| 6663 | |
| 6664 | char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6665 | HandleScopeImplementer* scope_implementer = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6666 | reinterpret_cast<HandleScopeImplementer*>(storage); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 6667 | scope_implementer->IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6668 | return storage + ArchiveSpacePerThread(); |
| 6669 | } |
| 6670 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 6671 | |
| 6672 | DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 6673 | DeferredHandles* deferred = |
| 6674 | new DeferredHandles(isolate()->handle_scope_data()->next, isolate()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 6675 | |
| 6676 | while (!blocks_.is_empty()) { |
| 6677 | Object** block_start = blocks_.last(); |
| 6678 | Object** block_limit = &block_start[kHandleBlockSize]; |
| 6679 | // We should not need to check for NoHandleAllocation here. Assert |
| 6680 | // this. |
| 6681 | ASSERT(prev_limit == block_limit || |
| 6682 | !(block_start <= prev_limit && prev_limit <= block_limit)); |
| 6683 | if (prev_limit == block_limit) break; |
| 6684 | deferred->blocks_.Add(blocks_.last()); |
| 6685 | blocks_.RemoveLast(); |
| 6686 | } |
| 6687 | |
| 6688 | // deferred->blocks_ now contains the blocks installed on the |
| 6689 | // HandleScope stack since BeginDeferredScope was called, but in |
| 6690 | // reverse order. |
| 6691 | |
| 6692 | ASSERT(prev_limit == NULL || !blocks_.is_empty()); |
| 6693 | |
| 6694 | ASSERT(!blocks_.is_empty() && prev_limit != NULL); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 6695 | ASSERT(last_handle_before_deferred_block_ != NULL); |
| 6696 | last_handle_before_deferred_block_ = NULL; |
| 6697 | return deferred; |
| 6698 | } |
| 6699 | |
| 6700 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 6701 | void HandleScopeImplementer::BeginDeferredScope() { |
| 6702 | ASSERT(last_handle_before_deferred_block_ == NULL); |
| 6703 | last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next; |
| 6704 | } |
| 6705 | |
| 6706 | |
| 6707 | DeferredHandles::~DeferredHandles() { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 6708 | isolate_->UnlinkDeferredHandles(this); |
| 6709 | |
| 6710 | for (int i = 0; i < blocks_.length(); i++) { |
| 6711 | #ifdef DEBUG |
| 6712 | HandleScope::ZapRange(blocks_[i], &blocks_[i][kHandleBlockSize]); |
| 6713 | #endif |
| 6714 | isolate_->handle_scope_implementer()->ReturnBlock(blocks_[i]); |
| 6715 | } |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 6716 | } |
| 6717 | |
| 6718 | |
| 6719 | void DeferredHandles::Iterate(ObjectVisitor* v) { |
| 6720 | ASSERT(!blocks_.is_empty()); |
| 6721 | |
| 6722 | ASSERT((first_block_limit_ >= blocks_.first()) && |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 6723 | (first_block_limit_ <= &(blocks_.first())[kHandleBlockSize])); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 6724 | |
| 6725 | v->VisitPointers(blocks_.first(), first_block_limit_); |
| 6726 | |
| 6727 | for (int i = 1; i < blocks_.length(); i++) { |
| 6728 | v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
| 6729 | } |
| 6730 | } |
| 6731 | |
| 6732 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6733 | } } // namespace v8::internal |