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 <string.h> // For memcpy, strlen. |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 31 | #include <cmath> // For isnan. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 32 | #include "../include/v8-debug.h" |
| 33 | #include "../include/v8-profiler.h" |
| 34 | #include "../include/v8-testing.h" |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 35 | #include "assert-scope.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | #include "bootstrapper.h" |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 37 | #include "code-stubs.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | #include "compiler.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 39 | #include "conversions-inl.h" |
| 40 | #include "counters.h" |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 41 | #include "cpu-profiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | #include "debug.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 43 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | #include "execution.h" |
| 45 | #include "global-handles.h" |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 46 | #include "heap-profiler.h" |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 47 | #include "heap-snapshot-generator-inl.h" |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 48 | #include "icu_util.h" |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 49 | #include "json-parser.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 50 | #include "messages.h" |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 51 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 52 | #include "natives.h" |
| 53 | #endif |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 54 | #include "parser.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | #include "platform.h" |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 56 | #include "platform/time.h" |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 57 | #include "profile-generator-inl.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 58 | #include "property-details.h" |
| 59 | #include "property.h" |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 60 | #include "runtime.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 61 | #include "runtime-profiler.h" |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 62 | #include "scanner-character-streams.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | #include "snapshot.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 64 | #include "unicode-inl.h" |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 65 | #include "utils/random-number-generator.h" |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 66 | #include "v8threads.h" |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 67 | #include "version.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 68 | #include "vm-state-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 69 | |
| 70 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 71 | #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 72 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 73 | #define ENTER_V8(isolate) \ |
| 74 | ASSERT((isolate)->IsInitialized()); \ |
| 75 | i::VMState<i::OTHER> __state__((isolate)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | |
| 77 | namespace v8 { |
| 78 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 79 | #define ON_BAILOUT(isolate, location, code) \ |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 80 | if (IsExecutionTerminatingCheck(isolate)) { \ |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 81 | code; \ |
| 82 | UNREACHABLE(); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 86 | #define EXCEPTION_PREAMBLE(isolate) \ |
| 87 | (isolate)->handle_scope_implementer()->IncrementCallDepth(); \ |
| 88 | ASSERT(!(isolate)->external_caught_exception()); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | bool has_pending_exception = false |
| 90 | |
| 91 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 92 | #define EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, do_callback) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 93 | do { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 94 | i::HandleScopeImplementer* handle_scope_implementer = \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 95 | (isolate)->handle_scope_implementer(); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 96 | handle_scope_implementer->DecrementCallDepth(); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 97 | if (has_pending_exception) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 98 | if (handle_scope_implementer->CallDepthIsZero() && \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 99 | (isolate)->is_out_of_memory()) { \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 100 | if (!(isolate)->ignore_out_of_memory()) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | i::V8::FatalProcessOutOfMemory(NULL); \ |
| 102 | } \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 103 | bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \ |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 104 | (isolate)->OptionalRescheduleException(call_depth_is_zero); \ |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 105 | do_callback \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 106 | return value; \ |
| 107 | } \ |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 108 | do_callback \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 109 | } while (false) |
| 110 | |
| 111 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 112 | #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \ |
| 113 | EXCEPTION_BAILOUT_CHECK_GENERIC( \ |
| 114 | isolate, value, i::V8::FireCallCompletedCallback(isolate);) |
| 115 | |
| 116 | |
| 117 | #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ |
| 118 | EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;) |
| 119 | |
| 120 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 121 | #define API_ENTRY_CHECK(isolate, msg) \ |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 122 | do { \ |
| 123 | if (v8::Locker::IsActive()) { \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 124 | ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \ |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 125 | msg, \ |
| 126 | "Entering the V8 API without proper locking in place"); \ |
| 127 | } \ |
| 128 | } while (false) |
| 129 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 130 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 131 | // --- E x c e p t i o n B e h a v i o r --- |
| 132 | |
| 133 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 134 | static void DefaultFatalErrorHandler(const char* location, |
| 135 | const char* message) { |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 136 | i::Isolate* isolate = i::Isolate::Current(); |
| 137 | if (isolate->IsInitialized()) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 138 | i::VMState<i::OTHER> state(isolate); |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 139 | API_Fatal(location, message); |
| 140 | } else { |
| 141 | API_Fatal(location, message); |
| 142 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 146 | static FatalErrorCallback GetFatalErrorHandler() { |
| 147 | i::Isolate* isolate = i::Isolate::Current(); |
| 148 | if (isolate->exception_behavior() == NULL) { |
| 149 | isolate->set_exception_behavior(DefaultFatalErrorHandler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 150 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 151 | return isolate->exception_behavior(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 155 | void i::FatalProcessOutOfMemory(const char* location) { |
| 156 | i::V8::FatalProcessOutOfMemory(location, false); |
| 157 | } |
| 158 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 159 | |
| 160 | // When V8 cannot allocated memory FatalProcessOutOfMemory is called. |
| 161 | // The default fatal error handler is called and execution is stopped. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 162 | void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 163 | i::HeapStats heap_stats; |
| 164 | int start_marker; |
| 165 | heap_stats.start_marker = &start_marker; |
| 166 | int new_space_size; |
| 167 | heap_stats.new_space_size = &new_space_size; |
| 168 | int new_space_capacity; |
| 169 | heap_stats.new_space_capacity = &new_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 170 | intptr_t old_pointer_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 171 | heap_stats.old_pointer_space_size = &old_pointer_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 172 | intptr_t old_pointer_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 173 | heap_stats.old_pointer_space_capacity = &old_pointer_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 174 | intptr_t old_data_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 175 | heap_stats.old_data_space_size = &old_data_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 176 | intptr_t old_data_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 177 | heap_stats.old_data_space_capacity = &old_data_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 178 | intptr_t code_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 179 | heap_stats.code_space_size = &code_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 180 | intptr_t code_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 181 | heap_stats.code_space_capacity = &code_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 182 | intptr_t map_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 183 | heap_stats.map_space_size = &map_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 184 | intptr_t map_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 185 | heap_stats.map_space_capacity = &map_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 186 | intptr_t cell_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 187 | heap_stats.cell_space_size = &cell_space_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 188 | intptr_t cell_space_capacity; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 189 | heap_stats.cell_space_capacity = &cell_space_capacity; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 190 | intptr_t property_cell_space_size; |
| 191 | heap_stats.property_cell_space_size = &property_cell_space_size; |
| 192 | intptr_t property_cell_space_capacity; |
| 193 | heap_stats.property_cell_space_capacity = &property_cell_space_capacity; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 194 | intptr_t lo_space_size; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 195 | heap_stats.lo_space_size = &lo_space_size; |
| 196 | int global_handle_count; |
| 197 | heap_stats.global_handle_count = &global_handle_count; |
| 198 | int weak_global_handle_count; |
| 199 | heap_stats.weak_global_handle_count = &weak_global_handle_count; |
| 200 | int pending_global_handle_count; |
| 201 | heap_stats.pending_global_handle_count = &pending_global_handle_count; |
| 202 | int near_death_global_handle_count; |
| 203 | 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] | 204 | int free_global_handle_count; |
| 205 | heap_stats.free_global_handle_count = &free_global_handle_count; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 206 | intptr_t memory_allocator_size; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 207 | heap_stats.memory_allocator_size = &memory_allocator_size; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 208 | intptr_t memory_allocator_capacity; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 209 | heap_stats.memory_allocator_capacity = &memory_allocator_capacity; |
| 210 | int objects_per_type[LAST_TYPE + 1] = {0}; |
| 211 | heap_stats.objects_per_type = objects_per_type; |
| 212 | int size_per_type[LAST_TYPE + 1] = {0}; |
| 213 | heap_stats.size_per_type = size_per_type; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 214 | int os_error; |
| 215 | heap_stats.os_error = &os_error; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 216 | int end_marker; |
| 217 | heap_stats.end_marker = &end_marker; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 218 | i::Isolate* isolate = i::Isolate::Current(); |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 219 | if (isolate->heap()->HasBeenSetUp()) { |
| 220 | // BUG(1718): Don't use the take_snapshot since we don't support |
| 221 | // HeapIterator here without doing a special GC. |
| 222 | isolate->heap()->RecordStats(&heap_stats, false); |
| 223 | } |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 224 | isolate->SignalFatalError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | FatalErrorCallback callback = GetFatalErrorHandler(); |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 226 | const char* message = "Allocation failed - process out of memory"; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 227 | callback(location, message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 228 | // If the callback returns, we stop execution. |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 229 | FATAL("API fatal error handler returned after process out of memory"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | bool Utils::ReportApiFailure(const char* location, const char* message) { |
| 234 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 235 | callback(location, message); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 236 | i::Isolate* isolate = i::Isolate::Current(); |
| 237 | isolate->SignalFatalError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 238 | return false; |
| 239 | } |
| 240 | |
| 241 | |
| 242 | bool V8::IsDead() { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 243 | i::Isolate* isolate = i::Isolate::Current(); |
| 244 | return isolate->IsDead(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | |
| 248 | static inline bool ApiCheck(bool condition, |
| 249 | const char* location, |
| 250 | const char* message) { |
| 251 | return condition ? true : Utils::ReportApiFailure(location, message); |
| 252 | } |
| 253 | |
| 254 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | static bool ReportEmptyHandle(const char* location) { |
| 256 | FatalErrorCallback callback = GetFatalErrorHandler(); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 257 | callback(location, "Reading from empty handle"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 258 | return true; |
| 259 | } |
| 260 | |
| 261 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 262 | static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { |
| 263 | if (!isolate->IsInitialized()) return false; |
| 264 | if (isolate->has_scheduled_exception()) { |
| 265 | return isolate->scheduled_exception() == |
| 266 | isolate->heap()->termination_exception(); |
| 267 | } |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 272 | static inline bool EmptyCheck(const char* location, v8::Handle<v8::Data> obj) { |
| 273 | return obj.IsEmpty() ? ReportEmptyHandle(location) : false; |
| 274 | } |
| 275 | |
| 276 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 277 | static inline bool EmptyCheck(const char* location, const v8::Data* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | return (obj == 0) ? ReportEmptyHandle(location) : false; |
| 279 | } |
| 280 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 281 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 282 | // --- S t a t i c s --- |
| 283 | |
| 284 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 285 | static bool InitializeHelper(i::Isolate* isolate) { |
| 286 | // If the isolate has a function entry hook, it needs to re-build all its |
| 287 | // code stubs with entry hooks embedded, so let's deserialize a snapshot. |
| 288 | if (isolate == NULL || isolate->function_entry_hook() == NULL) { |
| 289 | if (i::Snapshot::Initialize()) |
| 290 | return true; |
| 291 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 292 | return i::V8::Initialize(NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 296 | static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, |
| 297 | const char* location) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 298 | if (isolate != NULL) { |
| 299 | if (isolate->IsInitialized()) return true; |
| 300 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 301 | ASSERT(isolate == i::Isolate::Current()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 302 | return ApiCheck(InitializeHelper(isolate), location, "Error initializing V8"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 303 | } |
| 304 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 305 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 306 | // Some initializing API functions are called early and may be |
| 307 | // called on a thread different from static initializer thread. |
| 308 | // If Isolate API is used, Isolate::Enter() will initialize TLS so |
| 309 | // Isolate::Current() works. If it's a legacy case, then the thread |
| 310 | // may not have TLS initialized yet. However, in initializing APIs it |
| 311 | // may be too early to call EnsureInitialized() - some pre-init |
| 312 | // parameters still have to be configured. |
| 313 | static inline i::Isolate* EnterIsolateIfNeeded() { |
| 314 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
| 315 | if (isolate != NULL) |
| 316 | return isolate; |
| 317 | |
| 318 | i::Isolate::EnterDefaultIsolate(); |
| 319 | isolate = i::Isolate::Current(); |
| 320 | return isolate; |
| 321 | } |
| 322 | |
| 323 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 324 | StartupDataDecompressor::StartupDataDecompressor() |
| 325 | : raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) { |
| 326 | for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { |
| 327 | raw_data[i] = NULL; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | |
| 332 | StartupDataDecompressor::~StartupDataDecompressor() { |
| 333 | for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) { |
| 334 | i::DeleteArray(raw_data[i]); |
| 335 | } |
| 336 | i::DeleteArray(raw_data); |
| 337 | } |
| 338 | |
| 339 | |
| 340 | int StartupDataDecompressor::Decompress() { |
| 341 | int compressed_data_count = V8::GetCompressedStartupDataCount(); |
| 342 | StartupData* compressed_data = |
| 343 | i::NewArray<StartupData>(compressed_data_count); |
| 344 | V8::GetCompressedStartupData(compressed_data); |
| 345 | for (int i = 0; i < compressed_data_count; ++i) { |
| 346 | char* decompressed = raw_data[i] = |
| 347 | i::NewArray<char>(compressed_data[i].raw_size); |
| 348 | if (compressed_data[i].compressed_size != 0) { |
| 349 | int result = DecompressData(decompressed, |
| 350 | &compressed_data[i].raw_size, |
| 351 | compressed_data[i].data, |
| 352 | compressed_data[i].compressed_size); |
| 353 | if (result != 0) return result; |
| 354 | } else { |
| 355 | ASSERT_EQ(0, compressed_data[i].raw_size); |
| 356 | } |
| 357 | compressed_data[i].data = decompressed; |
| 358 | } |
| 359 | V8::SetDecompressedStartupData(compressed_data); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 360 | i::DeleteArray(compressed_data); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 365 | StartupData::CompressionAlgorithm V8::GetCompressedStartupDataAlgorithm() { |
| 366 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 367 | return StartupData::kBZip2; |
| 368 | #else |
| 369 | return StartupData::kUncompressed; |
| 370 | #endif |
| 371 | } |
| 372 | |
| 373 | |
| 374 | enum CompressedStartupDataItems { |
| 375 | kSnapshot = 0, |
| 376 | kSnapshotContext, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 377 | kLibraries, |
| 378 | kExperimentalLibraries, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 379 | kCompressedStartupDataCount |
| 380 | }; |
| 381 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 382 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 383 | int V8::GetCompressedStartupDataCount() { |
| 384 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 385 | return kCompressedStartupDataCount; |
| 386 | #else |
| 387 | return 0; |
| 388 | #endif |
| 389 | } |
| 390 | |
| 391 | |
| 392 | void V8::GetCompressedStartupData(StartupData* compressed_data) { |
| 393 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 394 | compressed_data[kSnapshot].data = |
| 395 | reinterpret_cast<const char*>(i::Snapshot::data()); |
| 396 | compressed_data[kSnapshot].compressed_size = i::Snapshot::size(); |
| 397 | compressed_data[kSnapshot].raw_size = i::Snapshot::raw_size(); |
| 398 | |
| 399 | compressed_data[kSnapshotContext].data = |
| 400 | reinterpret_cast<const char*>(i::Snapshot::context_data()); |
| 401 | compressed_data[kSnapshotContext].compressed_size = |
| 402 | i::Snapshot::context_size(); |
| 403 | compressed_data[kSnapshotContext].raw_size = i::Snapshot::context_raw_size(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 404 | |
| 405 | i::Vector<const i::byte> libraries_source = i::Natives::GetScriptsSource(); |
| 406 | compressed_data[kLibraries].data = |
| 407 | reinterpret_cast<const char*>(libraries_source.start()); |
| 408 | compressed_data[kLibraries].compressed_size = libraries_source.length(); |
| 409 | compressed_data[kLibraries].raw_size = i::Natives::GetRawScriptsSize(); |
| 410 | |
| 411 | i::Vector<const i::byte> exp_libraries_source = |
| 412 | i::ExperimentalNatives::GetScriptsSource(); |
| 413 | compressed_data[kExperimentalLibraries].data = |
| 414 | reinterpret_cast<const char*>(exp_libraries_source.start()); |
| 415 | compressed_data[kExperimentalLibraries].compressed_size = |
| 416 | exp_libraries_source.length(); |
| 417 | compressed_data[kExperimentalLibraries].raw_size = |
| 418 | i::ExperimentalNatives::GetRawScriptsSize(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 419 | #endif |
| 420 | } |
| 421 | |
| 422 | |
| 423 | void V8::SetDecompressedStartupData(StartupData* decompressed_data) { |
| 424 | #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 425 | ASSERT_EQ(i::Snapshot::raw_size(), decompressed_data[kSnapshot].raw_size); |
| 426 | i::Snapshot::set_raw_data( |
| 427 | reinterpret_cast<const i::byte*>(decompressed_data[kSnapshot].data)); |
| 428 | |
| 429 | ASSERT_EQ(i::Snapshot::context_raw_size(), |
| 430 | decompressed_data[kSnapshotContext].raw_size); |
| 431 | i::Snapshot::set_context_raw_data( |
| 432 | reinterpret_cast<const i::byte*>( |
| 433 | decompressed_data[kSnapshotContext].data)); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 434 | |
| 435 | ASSERT_EQ(i::Natives::GetRawScriptsSize(), |
| 436 | decompressed_data[kLibraries].raw_size); |
| 437 | i::Vector<const char> libraries_source( |
| 438 | decompressed_data[kLibraries].data, |
| 439 | decompressed_data[kLibraries].raw_size); |
| 440 | i::Natives::SetRawScriptsSource(libraries_source); |
| 441 | |
| 442 | ASSERT_EQ(i::ExperimentalNatives::GetRawScriptsSize(), |
| 443 | decompressed_data[kExperimentalLibraries].raw_size); |
| 444 | i::Vector<const char> exp_libraries_source( |
| 445 | decompressed_data[kExperimentalLibraries].data, |
| 446 | decompressed_data[kExperimentalLibraries].raw_size); |
| 447 | i::ExperimentalNatives::SetRawScriptsSource(exp_libraries_source); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 448 | #endif |
| 449 | } |
| 450 | |
| 451 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 452 | void V8::SetFatalErrorHandler(FatalErrorCallback that) { |
| 453 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 454 | isolate->set_exception_behavior(that); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 458 | void V8::SetAllowCodeGenerationFromStringsCallback( |
| 459 | AllowCodeGenerationFromStringsCallback callback) { |
| 460 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 461 | isolate->set_allow_code_gen_callback(callback); |
| 462 | } |
| 463 | |
| 464 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 465 | void V8::SetFlagsFromString(const char* str, int length) { |
| 466 | i::FlagList::SetFlagsFromString(str, length); |
| 467 | } |
| 468 | |
| 469 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 470 | void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { |
| 471 | i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); |
| 472 | } |
| 473 | |
| 474 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | v8::Handle<Value> ThrowException(v8::Handle<v8::Value> value) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 476 | return v8::Isolate::GetCurrent()->ThrowException(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | |
| 480 | RegisteredExtension* RegisteredExtension::first_extension_ = NULL; |
| 481 | |
| 482 | |
| 483 | RegisteredExtension::RegisteredExtension(Extension* extension) |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 484 | : extension_(extension) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 485 | |
| 486 | |
| 487 | void RegisteredExtension::Register(RegisteredExtension* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 488 | that->next_ = first_extension_; |
| 489 | first_extension_ = that; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 493 | void RegisteredExtension::UnregisterAll() { |
| 494 | RegisteredExtension* re = first_extension_; |
| 495 | while (re != NULL) { |
| 496 | RegisteredExtension* next = re->next(); |
| 497 | delete re; |
| 498 | re = next; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 503 | void RegisterExtension(Extension* that) { |
| 504 | RegisteredExtension* extension = new RegisteredExtension(that); |
| 505 | RegisteredExtension::Register(extension); |
| 506 | } |
| 507 | |
| 508 | |
| 509 | Extension::Extension(const char* name, |
| 510 | const char* source, |
| 511 | int dep_count, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 512 | const char** deps, |
| 513 | int source_length) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 514 | : name_(name), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 515 | source_length_(source_length >= 0 ? |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 516 | source_length : |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 517 | (source ? static_cast<int>(strlen(source)) : 0)), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 518 | source_(source, source_length_), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 519 | dep_count_(dep_count), |
| 520 | deps_(deps), |
danno@chromium.org | 412fa51 | 2012-09-14 13:28:26 +0000 | [diff] [blame] | 521 | auto_enable_(false) { |
| 522 | CHECK(source != NULL || source_length_ == 0); |
| 523 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 524 | |
| 525 | |
| 526 | v8::Handle<Primitive> Undefined() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 527 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 528 | if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) { |
| 529 | return v8::Handle<v8::Primitive>(); |
| 530 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 531 | return ToApiHandle<Primitive>(isolate->factory()->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | |
| 535 | v8::Handle<Primitive> Null() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 536 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 537 | if (!EnsureInitializedForIsolate(isolate, "v8::Null()")) { |
| 538 | return v8::Handle<v8::Primitive>(); |
| 539 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 540 | return ToApiHandle<Primitive>(isolate->factory()->null_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | |
| 544 | v8::Handle<Boolean> True() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 545 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 546 | if (!EnsureInitializedForIsolate(isolate, "v8::True()")) { |
| 547 | return v8::Handle<Boolean>(); |
| 548 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 549 | return ToApiHandle<Boolean>(isolate->factory()->true_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | |
| 553 | v8::Handle<Boolean> False() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 554 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 555 | if (!EnsureInitializedForIsolate(isolate, "v8::False()")) { |
| 556 | return v8::Handle<Boolean>(); |
| 557 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 558 | return ToApiHandle<Boolean>(isolate->factory()->false_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | |
| 562 | ResourceConstraints::ResourceConstraints() |
| 563 | : max_young_space_size_(0), |
| 564 | max_old_space_size_(0), |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 565 | max_executable_size_(0), |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 566 | stack_limit_(NULL) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 567 | |
| 568 | |
| 569 | bool SetResourceConstraints(ResourceConstraints* constraints) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 570 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
| 571 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 572 | int young_space_size = constraints->max_young_space_size(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 573 | int old_gen_size = constraints->max_old_space_size(); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 574 | int max_executable_size = constraints->max_executable_size(); |
| 575 | 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] | 576 | // After initialization it's too late to change Heap constraints. |
| 577 | ASSERT(!isolate->IsInitialized()); |
| 578 | bool result = isolate->heap()->ConfigureHeap(young_space_size / 2, |
| 579 | old_gen_size, |
| 580 | max_executable_size); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 581 | if (!result) return false; |
| 582 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 583 | if (constraints->stack_limit() != NULL) { |
| 584 | uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 585 | isolate->stack_guard()->SetStackLimit(limit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 586 | } |
| 587 | return true; |
| 588 | } |
| 589 | |
| 590 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 591 | i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 592 | LOG_API(isolate, "Persistent::New"); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 593 | i::Handle<i::Object> result = isolate->global_handles()->Create(*obj); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 594 | #ifdef DEBUG |
| 595 | (*obj)->Verify(); |
| 596 | #endif // DEBUG |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 597 | return result.location(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 601 | i::Object** V8::CopyPersistent(i::Object** obj) { |
| 602 | i::Handle<i::Object> result = i::GlobalHandles::CopyGlobal(obj); |
| 603 | #ifdef DEBUG |
| 604 | (*obj)->Verify(); |
| 605 | #endif // DEBUG |
| 606 | return result.location(); |
| 607 | } |
| 608 | |
| 609 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 610 | void V8::MakeWeak(i::Object** object, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 611 | void* parameters, |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 612 | WeakCallback weak_callback, |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 613 | RevivableCallback weak_reference_callback) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 614 | i::GlobalHandles::MakeWeak(object, |
| 615 | parameters, |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 616 | weak_callback, |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 617 | weak_reference_callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 621 | void V8::ClearWeak(i::Object** obj) { |
| 622 | i::GlobalHandles::ClearWeakness(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 626 | void V8::DisposeGlobal(i::Object** obj) { |
| 627 | i::GlobalHandles::Destroy(obj); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 628 | } |
| 629 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 630 | |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 631 | void V8::Eternalize(Isolate* v8_isolate, Value* value, int* index) { |
| 632 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 633 | i::Object* object = *Utils::OpenHandle(value); |
| 634 | isolate->eternal_handles()->Create(isolate, object, index); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 638 | Local<Value> V8::GetEternal(Isolate* v8_isolate, int index) { |
| 639 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 640 | return Utils::ToLocal(isolate->eternal_handles()->Get(index)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 644 | // --- H a n d l e s --- |
| 645 | |
| 646 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 647 | HandleScope::HandleScope(Isolate* isolate) { |
| 648 | Initialize(isolate); |
| 649 | } |
| 650 | |
| 651 | |
| 652 | void HandleScope::Initialize(Isolate* isolate) { |
| 653 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 654 | API_ENTRY_CHECK(internal_isolate, "HandleScope::HandleScope"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 655 | v8::ImplementationUtilities::HandleScopeData* current = |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 656 | internal_isolate->handle_scope_data(); |
| 657 | isolate_ = internal_isolate; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 658 | prev_next_ = current->next; |
| 659 | prev_limit_ = current->limit; |
| 660 | is_closed_ = false; |
| 661 | current->level++; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | |
| 665 | HandleScope::~HandleScope() { |
| 666 | if (!is_closed_) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 667 | Leave(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 668 | } |
| 669 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 670 | |
| 671 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 672 | void HandleScope::Leave() { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 673 | return i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 677 | int HandleScope::NumberOfHandles() { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 678 | i::Isolate* isolate = i::Isolate::Current(); |
| 679 | if (!EnsureInitializedForIsolate(isolate, "HandleScope::NumberOfHandles")) { |
| 680 | return 0; |
| 681 | } |
| 682 | return i::HandleScope::NumberOfHandles(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 686 | i::Object** HandleScope::CreateHandle(i::Isolate* isolate, i::Object* value) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 687 | return i::HandleScope::CreateHandle(isolate, value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 691 | i::Object** HandleScope::CreateHandle(i::HeapObject* heap_object, |
| 692 | i::Object* value) { |
| 693 | ASSERT(heap_object->IsHeapObject()); |
| 694 | return i::HandleScope::CreateHandle(heap_object->GetIsolate(), value); |
| 695 | } |
| 696 | |
| 697 | |
| 698 | EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) { |
| 699 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 700 | escape_slot_ = CreateHandle(isolate, isolate->heap()->the_hole_value()); |
| 701 | Initialize(v8_isolate); |
| 702 | } |
| 703 | |
| 704 | |
| 705 | i::Object** EscapableHandleScope::Escape(i::Object** escape_value) { |
| 706 | ApiCheck(*escape_slot_ == isolate_->heap()->the_hole_value(), |
| 707 | "EscapeableHandleScope::Escape", |
| 708 | "Escape value set twice"); |
| 709 | if (escape_value == NULL) { |
| 710 | *escape_slot_ = isolate_->heap()->undefined_value(); |
| 711 | return NULL; |
| 712 | } |
| 713 | *escape_slot_ = *escape_value; |
| 714 | return escape_slot_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | |
| 718 | void Context::Enter() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 719 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 720 | i::Isolate* isolate = env->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 721 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 722 | isolate->handle_scope_implementer()->EnterContext(env); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 723 | isolate->handle_scope_implementer()->SaveContext(isolate->context()); |
| 724 | isolate->set_context(*env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | |
| 728 | void Context::Exit() { |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 729 | // TODO(dcarney): fix this once chrome is fixed. |
| 730 | i::Isolate* isolate = i::Isolate::Current(); |
| 731 | i::Handle<i::Context> context = i::Handle<i::Context>::null(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 732 | ENTER_V8(isolate); |
| 733 | if (!ApiCheck(isolate->handle_scope_implementer()->LeaveContext(context), |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 734 | "v8::Context::Exit()", |
| 735 | "Cannot exit non-entered context")) { |
| 736 | return; |
| 737 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 738 | // Content of 'last_context' could be NULL. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 739 | i::Context* last_context = |
| 740 | isolate->handle_scope_implementer()->RestoreContext(); |
| 741 | isolate->set_context(last_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 745 | static void* DecodeSmiToAligned(i::Object* value, const char* location) { |
| 746 | ApiCheck(value->IsSmi(), location, "Not a Smi"); |
| 747 | return reinterpret_cast<void*>(value); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | |
mstarzinger@chromium.org | 0c977e0 | 2013-07-26 10:45:47 +0000 | [diff] [blame] | 751 | static i::Smi* EncodeAlignedAsSmi(void* value, const char* location) { |
| 752 | i::Smi* smi = reinterpret_cast<i::Smi*>(value); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 753 | ApiCheck(smi->IsSmi(), location, "Pointer is not aligned"); |
| 754 | return smi; |
| 755 | } |
| 756 | |
| 757 | |
| 758 | static i::Handle<i::FixedArray> EmbedderDataFor(Context* context, |
| 759 | int index, |
| 760 | bool can_grow, |
| 761 | const char* location) { |
| 762 | i::Handle<i::Context> env = Utils::OpenHandle(context); |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 763 | bool ok = |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 764 | ApiCheck(env->IsNativeContext(), location, "Not a native context") && |
| 765 | ApiCheck(index >= 0, location, "Negative index"); |
| 766 | if (!ok) return i::Handle<i::FixedArray>(); |
| 767 | i::Handle<i::FixedArray> data(env->embedder_data()); |
| 768 | if (index < data->length()) return data; |
| 769 | if (!can_grow) { |
| 770 | Utils::ReportApiFailure(location, "Index too large"); |
| 771 | return i::Handle<i::FixedArray>(); |
svenpanne@chromium.org | fc2a4f4 | 2012-11-07 09:25:55 +0000 | [diff] [blame] | 772 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 773 | int new_size = i::Max(index, data->length() << 1) + 1; |
| 774 | data = env->GetIsolate()->factory()->CopySizeFixedArray(data, new_size); |
| 775 | env->set_embedder_data(*data); |
| 776 | return data; |
| 777 | } |
| 778 | |
| 779 | |
| 780 | v8::Local<v8::Value> Context::SlowGetEmbedderData(int index) { |
| 781 | const char* location = "v8::Context::GetEmbedderData()"; |
| 782 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location); |
| 783 | if (data.is_null()) return Local<Value>(); |
| 784 | i::Handle<i::Object> result(data->get(index), data->GetIsolate()); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 785 | return Utils::ToLocal(result); |
| 786 | } |
| 787 | |
| 788 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 789 | void Context::SetEmbedderData(int index, v8::Handle<Value> value) { |
| 790 | const char* location = "v8::Context::SetEmbedderData()"; |
| 791 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, true, location); |
| 792 | if (data.is_null()) return; |
| 793 | i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 794 | data->set(index, *val); |
| 795 | ASSERT_EQ(*Utils::OpenHandle(*value), |
| 796 | *Utils::OpenHandle(*GetEmbedderData(index))); |
| 797 | } |
| 798 | |
| 799 | |
| 800 | void* Context::SlowGetAlignedPointerFromEmbedderData(int index) { |
| 801 | const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()"; |
| 802 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location); |
| 803 | if (data.is_null()) return NULL; |
| 804 | return DecodeSmiToAligned(data->get(index), location); |
| 805 | } |
| 806 | |
| 807 | |
| 808 | void Context::SetAlignedPointerInEmbedderData(int index, void* value) { |
| 809 | const char* location = "v8::Context::SetAlignedPointerInEmbedderData()"; |
| 810 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, true, location); |
| 811 | data->set(index, EncodeAlignedAsSmi(value, location)); |
| 812 | ASSERT_EQ(value, GetAlignedPointerFromEmbedderData(index)); |
| 813 | } |
| 814 | |
| 815 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 816 | i::Object** v8::HandleScope::RawClose(i::Object** value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 817 | if (!ApiCheck(!is_closed_, |
| 818 | "v8::HandleScope::Close()", |
| 819 | "Local scope has already been closed")) { |
| 820 | return 0; |
| 821 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 822 | LOG_API(isolate_, "CloseHandleScope"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 823 | |
| 824 | // Read the result before popping the handle block. |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 825 | i::Object* result = NULL; |
| 826 | if (value != NULL) { |
| 827 | result = *value; |
| 828 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 829 | is_closed_ = true; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 830 | Leave(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 831 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 832 | if (value == NULL) { |
| 833 | return NULL; |
| 834 | } |
| 835 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 836 | // Allocate a new handle on the previous handle block. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 837 | i::Handle<i::Object> handle(result, isolate_); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 838 | return handle.location(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | |
| 842 | // --- N e a n d e r --- |
| 843 | |
| 844 | |
| 845 | // A constructor cannot easily return an error value, therefore it is necessary |
| 846 | // to check for a dead VM with ON_BAILOUT before constructing any Neander |
| 847 | // objects. To remind you about this there is no HandleScope in the |
| 848 | // NeanderObject constructor. When you add one to the site calling the |
| 849 | // constructor you should check that you ensured the VM was not dead first. |
| 850 | NeanderObject::NeanderObject(int size) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 851 | i::Isolate* isolate = i::Isolate::Current(); |
| 852 | EnsureInitializedForIsolate(isolate, "v8::Nowhere"); |
| 853 | ENTER_V8(isolate); |
| 854 | value_ = isolate->factory()->NewNeanderObject(); |
| 855 | i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 856 | value_->set_elements(*elements); |
| 857 | } |
| 858 | |
| 859 | |
| 860 | int NeanderObject::size() { |
| 861 | return i::FixedArray::cast(value_->elements())->length(); |
| 862 | } |
| 863 | |
| 864 | |
| 865 | NeanderArray::NeanderArray() : obj_(2) { |
| 866 | obj_.set(0, i::Smi::FromInt(0)); |
| 867 | } |
| 868 | |
| 869 | |
| 870 | int NeanderArray::length() { |
| 871 | return i::Smi::cast(obj_.get(0))->value(); |
| 872 | } |
| 873 | |
| 874 | |
| 875 | i::Object* NeanderArray::get(int offset) { |
| 876 | ASSERT(0 <= offset); |
| 877 | ASSERT(offset < length()); |
| 878 | return obj_.get(offset + 1); |
| 879 | } |
| 880 | |
| 881 | |
| 882 | // This method cannot easily return an error value, therefore it is necessary |
| 883 | // to check for a dead VM with ON_BAILOUT before calling it. To remind you |
| 884 | // about this there is no HandleScope in this method. When you add one to the |
| 885 | // site calling this method you should check that you ensured the VM was not |
| 886 | // dead first. |
| 887 | void NeanderArray::add(i::Handle<i::Object> value) { |
| 888 | int length = this->length(); |
| 889 | int size = obj_.size(); |
| 890 | if (length == size - 1) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 891 | i::Factory* factory = i::Isolate::Current()->factory(); |
| 892 | i::Handle<i::FixedArray> new_elms = factory->NewFixedArray(2 * size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 893 | for (int i = 0; i < length; i++) |
| 894 | new_elms->set(i + 1, get(i)); |
| 895 | obj_.value()->set_elements(*new_elms); |
| 896 | } |
| 897 | obj_.set(length + 1, *value); |
| 898 | obj_.set(0, i::Smi::FromInt(length + 1)); |
| 899 | } |
| 900 | |
| 901 | |
| 902 | void NeanderArray::set(int index, i::Object* value) { |
| 903 | if (index < 0 || index >= this->length()) return; |
| 904 | obj_.set(index + 1, value); |
| 905 | } |
| 906 | |
| 907 | |
| 908 | // --- T e m p l a t e --- |
| 909 | |
| 910 | |
| 911 | static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { |
| 912 | that->set_tag(i::Smi::FromInt(type)); |
| 913 | } |
| 914 | |
| 915 | |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 916 | static void TemplateSet(i::Isolate* isolate, |
| 917 | v8::Template* templ, |
| 918 | int length, |
| 919 | v8::Handle<v8::Data>* data) { |
| 920 | i::Handle<i::Object> list(Utils::OpenHandle(templ)->property_list(), isolate); |
| 921 | if (list->IsUndefined()) { |
| 922 | list = NeanderArray().value(); |
| 923 | Utils::OpenHandle(templ)->set_property_list(*list); |
| 924 | } |
| 925 | NeanderArray array(list); |
| 926 | array.add(Utils::OpenHandle(*v8::Integer::New(length))); |
| 927 | for (int i = 0; i < length; i++) { |
| 928 | i::Handle<i::Object> value = data[i].IsEmpty() ? |
| 929 | i::Handle<i::Object>(isolate->factory()->undefined_value()) : |
| 930 | Utils::OpenHandle(*data[i]); |
| 931 | array.add(value); |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | |
| 936 | void Template::Set(v8::Handle<String> name, |
| 937 | v8::Handle<Data> value, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 938 | v8::PropertyAttribute attribute) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 939 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 940 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 941 | i::HandleScope scope(isolate); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 942 | const int kSize = 3; |
| 943 | v8::Handle<v8::Data> data[kSize] = { |
| 944 | name, |
| 945 | value, |
| 946 | v8::Integer::New(attribute)}; |
| 947 | TemplateSet(isolate, this, kSize, data); |
| 948 | } |
| 949 | |
| 950 | |
| 951 | void Template::SetAccessorProperty( |
| 952 | v8::Local<v8::String> name, |
| 953 | v8::Local<FunctionTemplate> getter, |
| 954 | v8::Local<FunctionTemplate> setter, |
| 955 | v8::PropertyAttribute attribute, |
| 956 | v8::AccessControl access_control) { |
| 957 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 958 | ENTER_V8(isolate); |
| 959 | ASSERT(!name.IsEmpty()); |
| 960 | ASSERT(!getter.IsEmpty() || !setter.IsEmpty()); |
| 961 | i::HandleScope scope(isolate); |
| 962 | const int kSize = 5; |
| 963 | v8::Handle<v8::Data> data[kSize] = { |
| 964 | name, |
| 965 | getter, |
| 966 | setter, |
| 967 | v8::Integer::New(attribute), |
| 968 | v8::Integer::New(access_control)}; |
| 969 | TemplateSet(isolate, this, kSize, data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | |
| 973 | // --- F u n c t i o n T e m p l a t e --- |
| 974 | static void InitializeFunctionTemplate( |
| 975 | i::Handle<i::FunctionTemplateInfo> info) { |
| 976 | info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE)); |
| 977 | info->set_flag(0); |
| 978 | } |
| 979 | |
| 980 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 981 | Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 982 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 983 | ENTER_V8(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 984 | i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(), |
| 985 | isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 986 | if (result->IsUndefined()) { |
| 987 | result = Utils::OpenHandle(*ObjectTemplate::New()); |
| 988 | Utils::OpenHandle(this)->set_prototype_template(*result); |
| 989 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 990 | return ToApiHandle<ObjectTemplate>(result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | |
| 994 | void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 995 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 996 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 997 | Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); |
| 998 | } |
| 999 | |
| 1000 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1001 | static Local<FunctionTemplate> FunctionTemplateNew( |
| 1002 | i::Isolate* isolate, |
| 1003 | FunctionCallback callback, |
| 1004 | v8::Handle<Value> data, |
| 1005 | v8::Handle<Signature> signature, |
| 1006 | int length, |
| 1007 | bool do_not_cache) { |
| 1008 | i::Handle<i::Struct> struct_obj = |
| 1009 | isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
| 1010 | i::Handle<i::FunctionTemplateInfo> obj = |
| 1011 | i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
| 1012 | InitializeFunctionTemplate(obj); |
| 1013 | obj->set_do_not_cache(do_not_cache); |
| 1014 | int next_serial_number = 0; |
| 1015 | if (!do_not_cache) { |
| 1016 | next_serial_number = isolate->next_serial_number() + 1; |
| 1017 | isolate->set_next_serial_number(next_serial_number); |
| 1018 | } |
| 1019 | obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
| 1020 | if (callback != 0) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1021 | if (data.IsEmpty()) { |
| 1022 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1023 | } |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1024 | Utils::ToLocal(obj)->SetCallHandler(callback, data); |
| 1025 | } |
| 1026 | obj->set_length(length); |
| 1027 | obj->set_undetectable(false); |
| 1028 | obj->set_needs_access_check(false); |
| 1029 | if (!signature.IsEmpty()) |
| 1030 | obj->set_signature(*Utils::OpenHandle(*signature)); |
| 1031 | return Utils::ToLocal(obj); |
| 1032 | } |
| 1033 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1034 | Local<FunctionTemplate> FunctionTemplate::New( |
| 1035 | FunctionCallback callback, |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1036 | v8::Handle<Value> data, |
| 1037 | v8::Handle<Signature> signature, |
| 1038 | int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1039 | i::Isolate* isolate = i::Isolate::Current(); |
| 1040 | EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); |
| 1041 | LOG_API(isolate, "FunctionTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1042 | ENTER_V8(isolate); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1043 | return FunctionTemplateNew( |
| 1044 | isolate, callback, data, signature, length, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | Local<Signature> Signature::New(Handle<FunctionTemplate> receiver, |
| 1049 | int argc, Handle<FunctionTemplate> argv[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1050 | i::Isolate* isolate = i::Isolate::Current(); |
| 1051 | EnsureInitializedForIsolate(isolate, "v8::Signature::New()"); |
| 1052 | LOG_API(isolate, "Signature::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1053 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1054 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1055 | isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | i::Handle<i::SignatureInfo> obj = |
| 1057 | i::Handle<i::SignatureInfo>::cast(struct_obj); |
| 1058 | if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver)); |
| 1059 | if (argc > 0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1060 | i::Handle<i::FixedArray> args = isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1061 | for (int i = 0; i < argc; i++) { |
| 1062 | if (!argv[i].IsEmpty()) |
| 1063 | args->set(i, *Utils::OpenHandle(*argv[i])); |
| 1064 | } |
| 1065 | obj->set_args(*args); |
| 1066 | } |
| 1067 | return Utils::ToLocal(obj); |
| 1068 | } |
| 1069 | |
| 1070 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1071 | Local<AccessorSignature> AccessorSignature::New( |
| 1072 | Handle<FunctionTemplate> receiver) { |
| 1073 | return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); |
| 1074 | } |
| 1075 | |
| 1076 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1077 | template<typename Operation> |
| 1078 | static Local<Operation> NewDescriptor( |
| 1079 | Isolate* isolate, |
| 1080 | const i::DeclaredAccessorDescriptorData& data, |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1081 | Data* previous_descriptor) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1082 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1083 | i::Handle<i::DeclaredAccessorDescriptor> previous = |
| 1084 | i::Handle<i::DeclaredAccessorDescriptor>(); |
| 1085 | if (previous_descriptor != NULL) { |
| 1086 | previous = Utils::OpenHandle( |
| 1087 | static_cast<DeclaredAccessorDescriptor*>(previous_descriptor)); |
| 1088 | } |
| 1089 | i::Handle<i::DeclaredAccessorDescriptor> descriptor = |
| 1090 | i::DeclaredAccessorDescriptor::Create(internal_isolate, data, previous); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1091 | return Utils::Convert<i::DeclaredAccessorDescriptor, Operation>(descriptor); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | |
| 1095 | Local<RawOperationDescriptor> |
| 1096 | ObjectOperationDescriptor::NewInternalFieldDereference( |
| 1097 | Isolate* isolate, |
| 1098 | int internal_field) { |
| 1099 | i::DeclaredAccessorDescriptorData data; |
| 1100 | data.type = i::kDescriptorObjectDereference; |
| 1101 | data.object_dereference_descriptor.internal_field = internal_field; |
| 1102 | return NewDescriptor<RawOperationDescriptor>(isolate, data, NULL); |
| 1103 | } |
| 1104 | |
| 1105 | |
| 1106 | Local<RawOperationDescriptor> RawOperationDescriptor::NewRawShift( |
| 1107 | Isolate* isolate, |
| 1108 | int16_t byte_offset) { |
| 1109 | i::DeclaredAccessorDescriptorData data; |
| 1110 | data.type = i::kDescriptorPointerShift; |
| 1111 | data.pointer_shift_descriptor.byte_offset = byte_offset; |
| 1112 | return NewDescriptor<RawOperationDescriptor>(isolate, data, this); |
| 1113 | } |
| 1114 | |
| 1115 | |
| 1116 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewHandleDereference( |
| 1117 | Isolate* isolate) { |
| 1118 | i::DeclaredAccessorDescriptorData data; |
| 1119 | data.type = i::kDescriptorReturnObject; |
| 1120 | return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this); |
| 1121 | } |
| 1122 | |
| 1123 | |
| 1124 | Local<RawOperationDescriptor> RawOperationDescriptor::NewRawDereference( |
| 1125 | Isolate* isolate) { |
| 1126 | i::DeclaredAccessorDescriptorData data; |
| 1127 | data.type = i::kDescriptorPointerDereference; |
| 1128 | return NewDescriptor<RawOperationDescriptor>(isolate, data, this); |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewPointerCompare( |
| 1133 | Isolate* isolate, |
| 1134 | void* compare_value) { |
| 1135 | i::DeclaredAccessorDescriptorData data; |
| 1136 | data.type = i::kDescriptorPointerCompare; |
| 1137 | data.pointer_compare_descriptor.compare_value = compare_value; |
| 1138 | return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this); |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewPrimitiveValue( |
| 1143 | Isolate* isolate, |
| 1144 | DeclaredAccessorDescriptorDataType data_type, |
| 1145 | uint8_t bool_offset) { |
| 1146 | i::DeclaredAccessorDescriptorData data; |
| 1147 | data.type = i::kDescriptorPrimitiveValue; |
| 1148 | data.primitive_value_descriptor.data_type = data_type; |
| 1149 | data.primitive_value_descriptor.bool_offset = bool_offset; |
| 1150 | return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this); |
| 1151 | } |
| 1152 | |
| 1153 | |
| 1154 | template<typename T> |
| 1155 | static Local<DeclaredAccessorDescriptor> NewBitmaskCompare( |
| 1156 | Isolate* isolate, |
| 1157 | T bitmask, |
| 1158 | T compare_value, |
| 1159 | RawOperationDescriptor* operation) { |
| 1160 | i::DeclaredAccessorDescriptorData data; |
| 1161 | data.type = i::kDescriptorBitmaskCompare; |
| 1162 | data.bitmask_compare_descriptor.bitmask = bitmask; |
| 1163 | data.bitmask_compare_descriptor.compare_value = compare_value; |
| 1164 | data.bitmask_compare_descriptor.size = sizeof(T); |
| 1165 | return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, operation); |
| 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare8( |
| 1170 | Isolate* isolate, |
| 1171 | uint8_t bitmask, |
| 1172 | uint8_t compare_value) { |
| 1173 | return NewBitmaskCompare(isolate, bitmask, compare_value, this); |
| 1174 | } |
| 1175 | |
| 1176 | |
| 1177 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare16( |
| 1178 | Isolate* isolate, |
| 1179 | uint16_t bitmask, |
| 1180 | uint16_t compare_value) { |
| 1181 | return NewBitmaskCompare(isolate, bitmask, compare_value, this); |
| 1182 | } |
| 1183 | |
| 1184 | |
| 1185 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare32( |
| 1186 | Isolate* isolate, |
| 1187 | uint32_t bitmask, |
| 1188 | uint32_t compare_value) { |
| 1189 | return NewBitmaskCompare(isolate, bitmask, compare_value, this); |
| 1190 | } |
| 1191 | |
| 1192 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1193 | Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) { |
| 1194 | Handle<FunctionTemplate> types[1] = { type }; |
| 1195 | return TypeSwitch::New(1, types); |
| 1196 | } |
| 1197 | |
| 1198 | |
| 1199 | Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1200 | i::Isolate* isolate = i::Isolate::Current(); |
| 1201 | EnsureInitializedForIsolate(isolate, "v8::TypeSwitch::New()"); |
| 1202 | LOG_API(isolate, "TypeSwitch::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1203 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1204 | i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1205 | for (int i = 0; i < argc; i++) |
| 1206 | vector->set(i, *Utils::OpenHandle(*types[i])); |
| 1207 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1208 | isolate->factory()->NewStruct(i::TYPE_SWITCH_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1209 | i::Handle<i::TypeSwitchInfo> obj = |
| 1210 | i::Handle<i::TypeSwitchInfo>::cast(struct_obj); |
| 1211 | obj->set_types(*vector); |
| 1212 | return Utils::ToLocal(obj); |
| 1213 | } |
| 1214 | |
| 1215 | |
| 1216 | int TypeSwitch::match(v8::Handle<Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1217 | i::Isolate* isolate = i::Isolate::Current(); |
| 1218 | LOG_API(isolate, "TypeSwitch::match"); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1219 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1220 | i::Handle<i::Object> obj = Utils::OpenHandle(*value); |
| 1221 | i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this); |
| 1222 | i::FixedArray* types = i::FixedArray::cast(info->types()); |
| 1223 | for (int i = 0; i < types->length(); i++) { |
| 1224 | if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i)))) |
| 1225 | return i + 1; |
| 1226 | } |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1231 | #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 1232 | i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1233 | (obj)->setter(*foreign); \ |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1234 | } while (false) |
| 1235 | |
| 1236 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1237 | void FunctionTemplate::SetCallHandler(FunctionCallback callback, |
| 1238 | v8::Handle<Value> data) { |
| 1239 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1240 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1241 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1242 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1243 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1244 | i::Handle<i::CallHandlerInfo> obj = |
| 1245 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1246 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1247 | if (data.IsEmpty()) { |
| 1248 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1249 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1250 | obj->set_data(*Utils::OpenHandle(*data)); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1251 | Utils::OpenHandle(this)->set_call_code(*obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1255 | static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
| 1256 | i::Handle<i::AccessorInfo> obj, |
| 1257 | v8::Handle<String> name, |
| 1258 | v8::AccessControl settings, |
| 1259 | v8::PropertyAttribute attributes, |
| 1260 | v8::Handle<AccessorSignature> signature) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1261 | obj->set_name(*Utils::OpenHandle(*name)); |
| 1262 | if (settings & ALL_CAN_READ) obj->set_all_can_read(true); |
| 1263 | if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); |
| 1264 | if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true); |
| 1265 | obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1266 | if (!signature.IsEmpty()) { |
| 1267 | obj->set_expected_receiver_type(*Utils::OpenHandle(*signature)); |
| 1268 | } |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1269 | return obj; |
| 1270 | } |
| 1271 | |
| 1272 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1273 | template<typename Getter, typename Setter> |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1274 | static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1275 | v8::Handle<String> name, |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1276 | Getter getter, |
| 1277 | Setter setter, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1278 | v8::Handle<Value> data, |
| 1279 | v8::AccessControl settings, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1280 | v8::PropertyAttribute attributes, |
| 1281 | v8::Handle<AccessorSignature> signature) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1282 | i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate(); |
| 1283 | i::Handle<i::ExecutableAccessorInfo> obj = |
| 1284 | isolate->factory()->NewExecutableAccessorInfo(); |
| 1285 | SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1286 | SET_FIELD_WRAPPED(obj, set_setter, setter); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1287 | if (data.IsEmpty()) { |
| 1288 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1289 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1290 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1291 | return SetAccessorInfoProperties(obj, name, settings, attributes, signature); |
| 1292 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1293 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1294 | |
| 1295 | static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
| 1296 | v8::Handle<String> name, |
| 1297 | v8::Handle<v8::DeclaredAccessorDescriptor> descriptor, |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1298 | void* setter_ignored, |
| 1299 | void* data_ignored, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1300 | v8::AccessControl settings, |
| 1301 | v8::PropertyAttribute attributes, |
| 1302 | v8::Handle<AccessorSignature> signature) { |
| 1303 | i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate(); |
| 1304 | if (descriptor.IsEmpty()) return i::Handle<i::DeclaredAccessorInfo>(); |
| 1305 | i::Handle<i::DeclaredAccessorInfo> obj = |
| 1306 | isolate->factory()->NewDeclaredAccessorInfo(); |
| 1307 | obj->set_descriptor(*Utils::OpenHandle(*descriptor)); |
| 1308 | return SetAccessorInfoProperties(obj, name, settings, attributes, signature); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1313 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 1314 | if (EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1315 | return Local<ObjectTemplate>(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1316 | ENTER_V8(isolate); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1317 | i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this); |
| 1318 | if (handle->instance_template()->IsUndefined()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1319 | Local<ObjectTemplate> templ = |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1320 | ObjectTemplate::New(ToApiHandle<FunctionTemplate>(handle)); |
| 1321 | handle->set_instance_template(*Utils::OpenHandle(*templ)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1322 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1323 | i::Handle<i::ObjectTemplateInfo> result( |
| 1324 | i::ObjectTemplateInfo::cast(handle->instance_template())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1325 | return Utils::ToLocal(result); |
| 1326 | } |
| 1327 | |
| 1328 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1329 | void FunctionTemplate::SetLength(int length) { |
| 1330 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1331 | ENTER_V8(isolate); |
| 1332 | Utils::OpenHandle(this)->set_length(length); |
| 1333 | } |
| 1334 | |
| 1335 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1336 | void FunctionTemplate::SetClassName(Handle<String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1337 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1338 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1339 | Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name)); |
| 1340 | } |
| 1341 | |
| 1342 | |
| 1343 | void FunctionTemplate::SetHiddenPrototype(bool value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1344 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1345 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1346 | Utils::OpenHandle(this)->set_hidden_prototype(value); |
| 1347 | } |
| 1348 | |
| 1349 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1350 | void FunctionTemplate::ReadOnlyPrototype() { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1351 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1352 | ENTER_V8(isolate); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1353 | Utils::OpenHandle(this)->set_read_only_prototype(true); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1356 | |
| 1357 | void FunctionTemplate::RemovePrototype() { |
| 1358 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1359 | ENTER_V8(isolate); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1360 | Utils::OpenHandle(this)->set_remove_prototype(true); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1364 | // --- O b j e c t T e m p l a t e --- |
| 1365 | |
| 1366 | |
| 1367 | Local<ObjectTemplate> ObjectTemplate::New() { |
| 1368 | return New(Local<FunctionTemplate>()); |
| 1369 | } |
| 1370 | |
| 1371 | |
| 1372 | Local<ObjectTemplate> ObjectTemplate::New( |
| 1373 | v8::Handle<FunctionTemplate> constructor) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1374 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1375 | EnsureInitializedForIsolate(isolate, "v8::ObjectTemplate::New()"); |
| 1376 | LOG_API(isolate, "ObjectTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1377 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1378 | i::Handle<i::Struct> struct_obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1379 | isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1380 | i::Handle<i::ObjectTemplateInfo> obj = |
| 1381 | i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); |
| 1382 | InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
| 1383 | if (!constructor.IsEmpty()) |
| 1384 | obj->set_constructor(*Utils::OpenHandle(*constructor)); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1385 | obj->set_internal_field_count(i::Smi::FromInt(0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1386 | return Utils::ToLocal(obj); |
| 1387 | } |
| 1388 | |
| 1389 | |
| 1390 | // Ensure that the object template has a constructor. If no |
| 1391 | // constructor is available we create one. |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1392 | static i::Handle<i::FunctionTemplateInfo> EnsureConstructor( |
| 1393 | ObjectTemplate* object_template) { |
| 1394 | i::Object* obj = Utils::OpenHandle(object_template)->constructor(); |
| 1395 | if (!obj ->IsUndefined()) { |
| 1396 | i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj); |
| 1397 | return i::Handle<i::FunctionTemplateInfo>(info, info->GetIsolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1398 | } |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1399 | Local<FunctionTemplate> templ = FunctionTemplate::New(); |
| 1400 | i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); |
| 1401 | constructor->set_instance_template(*Utils::OpenHandle(object_template)); |
| 1402 | Utils::OpenHandle(object_template)->set_constructor(*constructor); |
| 1403 | return constructor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1407 | static inline void AddPropertyToTemplate( |
| 1408 | i::Handle<i::TemplateInfo> info, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1409 | i::Handle<i::AccessorInfo> obj) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1410 | i::Handle<i::Object> list(info->property_accessors(), info->GetIsolate()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1411 | if (list->IsUndefined()) { |
| 1412 | list = NeanderArray().value(); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1413 | info->set_property_accessors(*list); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1414 | } |
| 1415 | NeanderArray array(list); |
| 1416 | array.add(obj); |
| 1417 | } |
| 1418 | |
| 1419 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1420 | static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
| 1421 | Template* template_obj) { |
| 1422 | return Utils::OpenHandle(template_obj); |
| 1423 | } |
| 1424 | |
| 1425 | |
| 1426 | // TODO(dcarney): remove this with ObjectTemplate::SetAccessor |
| 1427 | static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
| 1428 | ObjectTemplate* object_template) { |
| 1429 | EnsureConstructor(object_template); |
| 1430 | return Utils::OpenHandle(object_template); |
| 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | template<typename Setter, typename Getter, typename Data, typename Template> |
| 1435 | static bool TemplateSetAccessor( |
| 1436 | Template* template_obj, |
| 1437 | v8::Local<String> name, |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1438 | Getter getter, |
| 1439 | Setter setter, |
| 1440 | Data data, |
| 1441 | AccessControl settings, |
| 1442 | PropertyAttribute attribute, |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1443 | v8::Local<AccessorSignature> signature) { |
| 1444 | i::Isolate* isolate = Utils::OpenHandle(template_obj)->GetIsolate(); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1445 | ENTER_V8(isolate); |
| 1446 | i::HandleScope scope(isolate); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1447 | i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( |
| 1448 | name, getter, setter, data, settings, attribute, signature); |
| 1449 | if (obj.is_null()) return false; |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1450 | i::Handle<i::TemplateInfo> info = GetTemplateInfo(template_obj); |
| 1451 | AddPropertyToTemplate(info, obj); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1452 | return true; |
| 1453 | } |
| 1454 | |
| 1455 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1456 | bool Template::SetDeclaredAccessor( |
| 1457 | Local<String> name, |
| 1458 | Local<DeclaredAccessorDescriptor> descriptor, |
| 1459 | PropertyAttribute attribute, |
| 1460 | Local<AccessorSignature> signature, |
| 1461 | AccessControl settings) { |
| 1462 | void* null = NULL; |
| 1463 | return TemplateSetAccessor( |
| 1464 | this, name, descriptor, null, null, settings, attribute, signature); |
| 1465 | } |
| 1466 | |
| 1467 | |
| 1468 | void Template::SetNativeDataProperty(v8::Local<String> name, |
| 1469 | AccessorGetterCallback getter, |
| 1470 | AccessorSetterCallback setter, |
| 1471 | v8::Handle<Value> data, |
| 1472 | PropertyAttribute attribute, |
| 1473 | v8::Local<AccessorSignature> signature, |
| 1474 | AccessControl settings) { |
| 1475 | TemplateSetAccessor( |
| 1476 | this, name, getter, setter, data, settings, attribute, signature); |
| 1477 | } |
| 1478 | |
| 1479 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1480 | void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1481 | AccessorGetterCallback getter, |
| 1482 | AccessorSetterCallback setter, |
| 1483 | v8::Handle<Value> data, |
| 1484 | AccessControl settings, |
| 1485 | PropertyAttribute attribute, |
| 1486 | v8::Handle<AccessorSignature> signature) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1487 | TemplateSetAccessor( |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1488 | this, name, getter, setter, data, settings, attribute, signature); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1492 | void ObjectTemplate::SetNamedPropertyHandler( |
| 1493 | NamedPropertyGetterCallback getter, |
| 1494 | NamedPropertySetterCallback setter, |
| 1495 | NamedPropertyQueryCallback query, |
| 1496 | NamedPropertyDeleterCallback remover, |
| 1497 | NamedPropertyEnumeratorCallback enumerator, |
| 1498 | Handle<Value> data) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1499 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1500 | ENTER_V8(isolate); |
| 1501 | i::HandleScope scope(isolate); |
| 1502 | EnsureConstructor(this); |
| 1503 | i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( |
| 1504 | Utils::OpenHandle(this)->constructor()); |
| 1505 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1506 | i::Handle<i::Struct> struct_obj = |
| 1507 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
| 1508 | i::Handle<i::InterceptorInfo> obj = |
| 1509 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
| 1510 | |
| 1511 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1512 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1513 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1514 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1515 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1516 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1517 | if (data.IsEmpty()) { |
| 1518 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1519 | } |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1520 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1521 | cons->set_named_property_handler(*obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | |
| 1525 | void ObjectTemplate::MarkAsUndetectable() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1526 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1527 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1528 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1529 | EnsureConstructor(this); |
| 1530 | i::FunctionTemplateInfo* constructor = |
| 1531 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1532 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1533 | cons->set_undetectable(true); |
| 1534 | } |
| 1535 | |
| 1536 | |
| 1537 | void ObjectTemplate::SetAccessCheckCallbacks( |
| 1538 | NamedSecurityCallback named_callback, |
| 1539 | IndexedSecurityCallback indexed_callback, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1540 | Handle<Value> data, |
| 1541 | bool turned_on_by_default) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1542 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1543 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1544 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1545 | EnsureConstructor(this); |
| 1546 | |
| 1547 | i::Handle<i::Struct> struct_info = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1548 | isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1549 | i::Handle<i::AccessCheckInfo> info = |
| 1550 | i::Handle<i::AccessCheckInfo>::cast(struct_info); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1551 | |
| 1552 | SET_FIELD_WRAPPED(info, set_named_callback, named_callback); |
| 1553 | SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback); |
| 1554 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1555 | if (data.IsEmpty()) { |
| 1556 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1557 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1558 | info->set_data(*Utils::OpenHandle(*data)); |
| 1559 | |
| 1560 | i::FunctionTemplateInfo* constructor = |
| 1561 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1562 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1563 | cons->set_access_check_info(*info); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1564 | cons->set_needs_access_check(turned_on_by_default); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1568 | void ObjectTemplate::SetIndexedPropertyHandler( |
| 1569 | IndexedPropertyGetterCallback getter, |
| 1570 | IndexedPropertySetterCallback setter, |
| 1571 | IndexedPropertyQueryCallback query, |
| 1572 | IndexedPropertyDeleterCallback remover, |
| 1573 | IndexedPropertyEnumeratorCallback enumerator, |
| 1574 | Handle<Value> data) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1575 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1576 | ENTER_V8(isolate); |
| 1577 | i::HandleScope scope(isolate); |
| 1578 | EnsureConstructor(this); |
| 1579 | i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( |
| 1580 | Utils::OpenHandle(this)->constructor()); |
| 1581 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1582 | i::Handle<i::Struct> struct_obj = |
| 1583 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
| 1584 | i::Handle<i::InterceptorInfo> obj = |
| 1585 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
| 1586 | |
| 1587 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1588 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1589 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1590 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1591 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1592 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1593 | if (data.IsEmpty()) { |
| 1594 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1595 | } |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1596 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1597 | cons->set_indexed_property_handler(*obj); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1601 | void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback, |
| 1602 | Handle<Value> data) { |
| 1603 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1604 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1605 | i::HandleScope scope(isolate); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1606 | EnsureConstructor(this); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1607 | i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1608 | Utils::OpenHandle(this)->constructor()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1609 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1610 | i::Handle<i::Struct> struct_obj = |
| 1611 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
| 1612 | i::Handle<i::CallHandlerInfo> obj = |
| 1613 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
| 1614 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1615 | if (data.IsEmpty()) { |
| 1616 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1617 | } |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1618 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1619 | cons->set_instance_call_handler(*obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1623 | int ObjectTemplate::InternalFieldCount() { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1624 | return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1628 | void ObjectTemplate::SetInternalFieldCount(int value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1629 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1630 | if (!ApiCheck(i::Smi::IsValid(value), |
| 1631 | "v8::ObjectTemplate::SetInternalFieldCount()", |
| 1632 | "Invalid internal field count")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1633 | return; |
| 1634 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1635 | ENTER_V8(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1636 | if (value > 0) { |
| 1637 | // The internal field count is set by the constructor function's |
| 1638 | // construct code, so we ensure that there is a constructor |
| 1639 | // function to do the setting. |
| 1640 | EnsureConstructor(this); |
| 1641 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1642 | Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1646 | // --- S c r i p t D a t a --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1647 | |
| 1648 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1649 | ScriptData* ScriptData::PreCompile(v8::Isolate* isolate, |
| 1650 | const char* input, |
| 1651 | int length) { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1652 | i::Utf8ToUtf16CharacterStream stream( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1653 | reinterpret_cast<const unsigned char*>(input), length); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1654 | return i::PreParserApi::PreParse( |
| 1655 | reinterpret_cast<i::Isolate*>(isolate), &stream); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1659 | ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { |
| 1660 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1661 | i::Isolate* isolate = str->GetIsolate(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1662 | if (str->IsExternalTwoByteString()) { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1663 | i::ExternalTwoByteStringUtf16CharacterStream stream( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1664 | i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1665 | return i::PreParserApi::PreParse(isolate, &stream); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1666 | } else { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1667 | i::GenericStringUtf16CharacterStream stream(str, 0, str->length()); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1668 | return i::PreParserApi::PreParse(isolate, &stream); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1669 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1673 | ScriptData* ScriptData::New(const char* data, int length) { |
| 1674 | // Return an empty ScriptData if the length is obviously invalid. |
| 1675 | if (length % sizeof(unsigned) != 0) { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1676 | return new i::ScriptDataImpl(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | // Copy the data to ensure it is properly aligned. |
| 1680 | int deserialized_data_length = length / sizeof(unsigned); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1681 | // If aligned, don't create a copy of the data. |
| 1682 | if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) { |
| 1683 | return new i::ScriptDataImpl(data, length); |
| 1684 | } |
| 1685 | // Copy the data to align it. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1686 | unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1687 | i::CopyBytes(reinterpret_cast<char*>(deserialized_data), |
| 1688 | data, static_cast<size_t>(length)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1689 | |
| 1690 | return new i::ScriptDataImpl( |
| 1691 | i::Vector<unsigned>(deserialized_data, deserialized_data_length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | |
| 1695 | // --- S c r i p t --- |
| 1696 | |
| 1697 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1698 | Local<Script> Script::New(v8::Handle<String> source, |
| 1699 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1700 | v8::ScriptData* pre_data, |
| 1701 | v8::Handle<String> script_data) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1702 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1703 | i::Isolate* isolate = str->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1704 | ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>()); |
| 1705 | LOG_API(isolate, "Script::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1706 | ENTER_V8(isolate); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1707 | i::SharedFunctionInfo* raw_result = NULL; |
| 1708 | { i::HandleScope scope(isolate); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1709 | i::Handle<i::Object> name_obj; |
| 1710 | int line_offset = 0; |
| 1711 | int column_offset = 0; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1712 | bool is_shared_cross_origin = false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1713 | if (origin != NULL) { |
| 1714 | if (!origin->ResourceName().IsEmpty()) { |
| 1715 | name_obj = Utils::OpenHandle(*origin->ResourceName()); |
| 1716 | } |
| 1717 | if (!origin->ResourceLineOffset().IsEmpty()) { |
| 1718 | line_offset = static_cast<int>(origin->ResourceLineOffset()->Value()); |
| 1719 | } |
| 1720 | if (!origin->ResourceColumnOffset().IsEmpty()) { |
| 1721 | column_offset = |
| 1722 | static_cast<int>(origin->ResourceColumnOffset()->Value()); |
| 1723 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1724 | if (!origin->ResourceIsSharedCrossOrigin().IsEmpty()) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1725 | v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1726 | is_shared_cross_origin = |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1727 | origin->ResourceIsSharedCrossOrigin() == v8::True(v8_isolate); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1728 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1729 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1730 | EXCEPTION_PREAMBLE(isolate); |
| 1731 | i::ScriptDataImpl* pre_data_impl = |
| 1732 | static_cast<i::ScriptDataImpl*>(pre_data); |
| 1733 | // We assert that the pre-data is sane, even though we can actually |
| 1734 | // handle it if it turns out not to be in release mode. |
| 1735 | ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck()); |
| 1736 | // If the pre-data isn't sane we simply ignore it |
| 1737 | if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) { |
| 1738 | pre_data_impl = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1739 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1740 | i::Handle<i::SharedFunctionInfo> result = |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1741 | i::Compiler::Compile(str, |
| 1742 | name_obj, |
| 1743 | line_offset, |
| 1744 | column_offset, |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1745 | is_shared_cross_origin, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1746 | isolate->global_context(), |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1747 | NULL, |
| 1748 | pre_data_impl, |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 1749 | Utils::OpenHandle(*script_data, true), |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 1750 | i::NOT_NATIVES_CODE); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1751 | has_pending_exception = result.is_null(); |
| 1752 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); |
| 1753 | raw_result = *result; |
| 1754 | } |
| 1755 | i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1756 | return ToApiHandle<Script>(result); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | |
| 1760 | Local<Script> Script::New(v8::Handle<String> source, |
| 1761 | v8::Handle<Value> file_name) { |
| 1762 | ScriptOrigin origin(file_name); |
| 1763 | return New(source, &origin); |
| 1764 | } |
| 1765 | |
| 1766 | |
| 1767 | Local<Script> Script::Compile(v8::Handle<String> source, |
| 1768 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1769 | v8::ScriptData* pre_data, |
| 1770 | v8::Handle<String> script_data) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1771 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1772 | i::Isolate* isolate = str->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1773 | ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>()); |
| 1774 | LOG_API(isolate, "Script::Compile"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1775 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1776 | Local<Script> generic = New(source, origin, pre_data, script_data); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1777 | if (generic.IsEmpty()) |
| 1778 | return generic; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1779 | i::Handle<i::Object> obj = Utils::OpenHandle(*generic); |
| 1780 | i::Handle<i::SharedFunctionInfo> function = |
| 1781 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1782 | i::Handle<i::JSFunction> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1783 | isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 1784 | function, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1785 | isolate->global_context()); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1786 | return ToApiHandle<Script>(result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1790 | Local<Script> Script::Compile(v8::Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1791 | v8::Handle<Value> file_name, |
| 1792 | v8::Handle<String> script_data) { |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1793 | ScriptOrigin origin(file_name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1794 | return Compile(source, &origin, 0, script_data); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1798 | Local<Value> Script::Run() { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1799 | // If execution is terminating, Compile(script)->Run() requires this check. |
| 1800 | if (this == NULL) return Local<Value>(); |
| 1801 | i::Handle<i::HeapObject> obj = |
| 1802 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1803 | i::Isolate* isolate = obj->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1804 | ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); |
| 1805 | LOG_API(isolate, "Script::Run"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1806 | ENTER_V8(isolate); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1807 | i::Logger::TimerEventScope timer_scope( |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 1808 | isolate, i::Logger::TimerEventScope::v8_execute); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1809 | i::Object* raw_result = NULL; |
| 1810 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1811 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1812 | i::Handle<i::JSFunction> fun; |
| 1813 | if (obj->IsSharedFunctionInfo()) { |
| 1814 | i::Handle<i::SharedFunctionInfo> |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1815 | function_info(i::SharedFunctionInfo::cast(*obj), isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1816 | fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1817 | function_info, isolate->global_context()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1818 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1819 | fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1820 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1821 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1822 | i::Handle<i::Object> receiver( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1823 | isolate->context()->global_proxy(), isolate); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 1824 | i::Handle<i::Object> result = i::Execution::Call( |
| 1825 | isolate, fun, receiver, 0, NULL, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 1826 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1827 | raw_result = *result; |
| 1828 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1829 | i::Handle<i::Object> result(raw_result, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1830 | return Utils::ToLocal(result); |
| 1831 | } |
| 1832 | |
| 1833 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1834 | static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) { |
| 1835 | i::Handle<i::Object> obj = Utils::OpenHandle(script); |
| 1836 | i::Handle<i::SharedFunctionInfo> result; |
| 1837 | if (obj->IsSharedFunctionInfo()) { |
| 1838 | result = |
| 1839 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
| 1840 | } else { |
| 1841 | result = |
| 1842 | i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()); |
| 1843 | } |
| 1844 | return result; |
| 1845 | } |
| 1846 | |
| 1847 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1848 | Local<Value> Script::Id() { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1849 | i::Handle<i::HeapObject> obj = |
| 1850 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1851 | i::Isolate* isolate = obj->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1852 | ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>()); |
| 1853 | LOG_API(isolate, "Script::Id"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1854 | i::Object* raw_id = NULL; |
| 1855 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1856 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1857 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
| 1858 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1859 | i::Handle<i::Object> id(script->id(), isolate); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1860 | raw_id = *id; |
| 1861 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1862 | i::Handle<i::Object> id(raw_id, isolate); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1863 | return Utils::ToLocal(id); |
| 1864 | } |
| 1865 | |
| 1866 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1867 | int Script::GetId() { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1868 | i::Handle<i::HeapObject> obj = |
| 1869 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1870 | i::Isolate* isolate = obj->GetIsolate(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1871 | ON_BAILOUT(isolate, "v8::Script::Id()", return -1); |
| 1872 | LOG_API(isolate, "Script::Id"); |
| 1873 | { |
| 1874 | i::HandleScope scope(isolate); |
| 1875 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
| 1876 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
| 1877 | return script->id()->value(); |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1882 | int Script::GetLineNumber(int code_pos) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1883 | i::Handle<i::HeapObject> obj = |
| 1884 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1885 | i::Isolate* isolate = obj->GetIsolate(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1886 | ON_BAILOUT(isolate, "v8::Script::GetLineNumber()", return -1); |
| 1887 | LOG_API(isolate, "Script::GetLineNumber"); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1888 | if (obj->IsScript()) { |
| 1889 | i::Handle<i::Script> script = i::Handle<i::Script>(i::Script::cast(*obj)); |
| 1890 | return i::GetScriptLineNumber(script, code_pos); |
| 1891 | } else { |
| 1892 | return -1; |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | |
| 1897 | Handle<Value> Script::GetScriptName() { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1898 | i::Handle<i::HeapObject> obj = |
| 1899 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1900 | i::Isolate* isolate = obj->GetIsolate(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1901 | ON_BAILOUT(isolate, "v8::Script::GetName()", return Handle<String>()); |
| 1902 | LOG_API(isolate, "Script::GetName"); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1903 | if (obj->IsScript()) { |
| 1904 | i::Object* name = i::Script::cast(*obj)->name(); |
| 1905 | return Utils::ToLocal(i::Handle<i::Object>(name, isolate)); |
| 1906 | } else { |
| 1907 | return Handle<String>(); |
| 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1912 | void Script::SetData(v8::Handle<String> data) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1913 | i::Handle<i::HeapObject> obj = |
| 1914 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1915 | i::Isolate* isolate = obj->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1916 | ON_BAILOUT(isolate, "v8::Script::SetData()", return); |
| 1917 | LOG_API(isolate, "Script::SetData"); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1918 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1919 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1920 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1921 | i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1922 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1923 | script->set_data(*raw_data); |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1928 | // --- E x c e p t i o n s --- |
| 1929 | |
| 1930 | |
| 1931 | v8::TryCatch::TryCatch() |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1932 | : isolate_(i::Isolate::Current()), |
| 1933 | next_(isolate_->try_catch_handler_address()), |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1934 | is_verbose_(false), |
ager@chromium.org | 68e7ab7 | 2009-09-23 09:40:39 +0000 | [diff] [blame] | 1935 | can_continue_(true), |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1936 | capture_message_(true), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1937 | rethrow_(false), |
| 1938 | has_terminated_(false) { |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1939 | Reset(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1940 | isolate_->RegisterTryCatchHandler(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | |
| 1944 | v8::TryCatch::~TryCatch() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1945 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1946 | if (rethrow_) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1947 | v8::Isolate* isolate = reinterpret_cast<Isolate*>(isolate_); |
| 1948 | v8::HandleScope scope(isolate); |
| 1949 | v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(isolate, Exception()); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1950 | if (HasCaught() && capture_message_) { |
| 1951 | // If an exception was caught and rethrow_ is indicated, the saved |
| 1952 | // message, script, and location need to be restored to Isolate TLS |
| 1953 | // for reuse. capture_message_ needs to be disabled so that DoThrow() |
| 1954 | // does not create a new message. |
| 1955 | isolate_->thread_local_top()->rethrowing_message_ = true; |
| 1956 | isolate_->RestorePendingMessageFromTryCatch(this); |
| 1957 | } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1958 | isolate_->UnregisterTryCatchHandler(this); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1959 | reinterpret_cast<Isolate*>(isolate_)->ThrowException(exc); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1960 | ASSERT(!isolate_->thread_local_top()->rethrowing_message_); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1961 | } else { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1962 | isolate_->UnregisterTryCatchHandler(this); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1963 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1967 | bool v8::TryCatch::HasCaught() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1968 | return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(); |
| 1969 | } |
| 1970 | |
| 1971 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 1972 | bool v8::TryCatch::CanContinue() const { |
| 1973 | return can_continue_; |
| 1974 | } |
| 1975 | |
| 1976 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1977 | bool v8::TryCatch::HasTerminated() const { |
| 1978 | return has_terminated_; |
| 1979 | } |
| 1980 | |
| 1981 | |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1982 | v8::Handle<v8::Value> v8::TryCatch::ReThrow() { |
| 1983 | if (!HasCaught()) return v8::Local<v8::Value>(); |
| 1984 | rethrow_ = true; |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1985 | return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate_)); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1989 | v8::Local<Value> v8::TryCatch::Exception() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1990 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1991 | if (HasCaught()) { |
| 1992 | // Check for out of memory exception. |
| 1993 | i::Object* exception = reinterpret_cast<i::Object*>(exception_); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1994 | return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1995 | } else { |
| 1996 | return v8::Local<Value>(); |
| 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2001 | v8::Local<Value> v8::TryCatch::StackTrace() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2002 | ASSERT(isolate_ == i::Isolate::Current()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2003 | if (HasCaught()) { |
| 2004 | i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); |
| 2005 | if (!raw_obj->IsJSObject()) return v8::Local<Value>(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2006 | i::HandleScope scope(isolate_); |
| 2007 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2008 | i::Handle<i::String> name = isolate_->factory()->stack_string(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2009 | if (!i::JSReceiver::HasProperty(obj, name)) return v8::Local<Value>(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2010 | i::Handle<i::Object> value = i::GetProperty(isolate_, obj, name); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 2011 | if (value.is_null()) return v8::Local<Value>(); |
| 2012 | return v8::Utils::ToLocal(scope.CloseAndEscape(value)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2013 | } else { |
| 2014 | return v8::Local<Value>(); |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2019 | v8::Local<v8::Message> v8::TryCatch::Message() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2020 | ASSERT(isolate_ == i::Isolate::Current()); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 2021 | i::Object* message = reinterpret_cast<i::Object*>(message_obj_); |
| 2022 | ASSERT(message->IsJSMessageObject() || message->IsTheHole()); |
| 2023 | if (HasCaught() && !message->IsTheHole()) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2024 | return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2025 | } else { |
| 2026 | return v8::Local<v8::Message>(); |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2031 | void v8::TryCatch::Reset() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2032 | ASSERT(isolate_ == i::Isolate::Current()); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 2033 | i::Object* the_hole = isolate_->heap()->the_hole_value(); |
| 2034 | exception_ = the_hole; |
| 2035 | message_obj_ = the_hole; |
| 2036 | message_script_ = the_hole; |
| 2037 | message_start_pos_ = 0; |
| 2038 | message_end_pos_ = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | |
| 2042 | void v8::TryCatch::SetVerbose(bool value) { |
| 2043 | is_verbose_ = value; |
| 2044 | } |
| 2045 | |
| 2046 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2047 | void v8::TryCatch::SetCaptureMessage(bool value) { |
| 2048 | capture_message_ = value; |
| 2049 | } |
| 2050 | |
| 2051 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2052 | // --- M e s s a g e --- |
| 2053 | |
| 2054 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2055 | Local<String> Message::Get() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2056 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2057 | ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2058 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2059 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2060 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2061 | i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2062 | Local<String> result = Utils::ToLocal(raw_result); |
| 2063 | return scope.Close(result); |
| 2064 | } |
| 2065 | |
| 2066 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2067 | v8::Handle<Value> Message::GetScriptResourceName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2068 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2069 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2070 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2071 | i::Handle<i::JSMessageObject> message = |
| 2072 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2073 | // Return this.script.name. |
| 2074 | i::Handle<i::JSValue> script = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2075 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), |
| 2076 | isolate)); |
| 2077 | i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name(), |
| 2078 | isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2079 | return scope.Close(Utils::ToLocal(resource_name)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2083 | v8::Handle<Value> Message::GetScriptData() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2084 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2085 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2086 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2087 | i::Handle<i::JSMessageObject> message = |
| 2088 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2089 | // Return this.script.data. |
| 2090 | i::Handle<i::JSValue> script = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2091 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), |
| 2092 | isolate)); |
| 2093 | 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] | 2094 | return scope.Close(Utils::ToLocal(data)); |
| 2095 | } |
| 2096 | |
| 2097 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2098 | v8::Handle<v8::StackTrace> Message::GetStackTrace() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2099 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2100 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2101 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2102 | i::Handle<i::JSMessageObject> message = |
| 2103 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2104 | i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2105 | if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); |
| 2106 | i::Handle<i::JSArray> stackTrace = |
| 2107 | i::Handle<i::JSArray>::cast(stackFramesObj); |
| 2108 | return scope.Close(Utils::StackTraceToLocal(stackTrace)); |
| 2109 | } |
| 2110 | |
| 2111 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2112 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 2113 | i::Handle<i::Object> recv, |
| 2114 | int argc, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2115 | i::Handle<i::Object> argv[], |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2116 | bool* has_pending_exception) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2117 | i::Isolate* isolate = i::Isolate::Current(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2118 | i::Handle<i::String> fmt_str = |
| 2119 | isolate->factory()->InternalizeUtf8String(name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2120 | i::Object* object_fun = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2121 | isolate->js_builtins_object()->GetPropertyNoExceptionThrown(*fmt_str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2122 | i::Handle<i::JSFunction> fun = |
| 2123 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun)); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 2124 | i::Handle<i::Object> value = i::Execution::Call( |
| 2125 | isolate, fun, recv, argc, argv, has_pending_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2126 | return value; |
| 2127 | } |
| 2128 | |
| 2129 | |
| 2130 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 2131 | i::Handle<i::Object> data, |
| 2132 | bool* has_pending_exception) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2133 | i::Handle<i::Object> argv[] = { data }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2134 | return CallV8HeapFunction(name, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2135 | i::Isolate::Current()->js_builtins_object(), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2136 | ARRAY_SIZE(argv), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2137 | argv, |
| 2138 | has_pending_exception); |
| 2139 | } |
| 2140 | |
| 2141 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2142 | int Message::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2143 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2144 | ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2145 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2146 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2147 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2148 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2149 | i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber", |
| 2150 | Utils::OpenHandle(this), |
| 2151 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2152 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2153 | return static_cast<int>(result->Number()); |
| 2154 | } |
| 2155 | |
| 2156 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2157 | int Message::GetStartPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2158 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2159 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2160 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2161 | i::Handle<i::JSMessageObject> message = |
| 2162 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 2163 | return message->start_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2167 | int Message::GetEndPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2168 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2169 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2170 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2171 | i::Handle<i::JSMessageObject> message = |
| 2172 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 2173 | return message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2177 | int Message::GetStartColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2178 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2179 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2180 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2181 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2182 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2183 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 2184 | "GetPositionInLine", |
| 2185 | data_obj, |
| 2186 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2187 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2188 | return static_cast<int>(start_col_obj->Number()); |
| 2189 | } |
| 2190 | |
| 2191 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2192 | int Message::GetEndColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2193 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2194 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2195 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2196 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2197 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2198 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 2199 | "GetPositionInLine", |
| 2200 | data_obj, |
| 2201 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2202 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2203 | i::Handle<i::JSMessageObject> message = |
| 2204 | i::Handle<i::JSMessageObject>::cast(data_obj); |
| 2205 | int start = message->start_position(); |
| 2206 | int end = message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2207 | return static_cast<int>(start_col_obj->Number()) + (end - start); |
| 2208 | } |
| 2209 | |
| 2210 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2211 | bool Message::IsSharedCrossOrigin() const { |
| 2212 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2213 | ENTER_V8(isolate); |
| 2214 | i::HandleScope scope(isolate); |
| 2215 | i::Handle<i::JSMessageObject> message = |
| 2216 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 2217 | i::Handle<i::JSValue> script = |
| 2218 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), |
| 2219 | isolate)); |
| 2220 | return i::Script::cast(script->value())->is_shared_cross_origin(); |
| 2221 | } |
| 2222 | |
| 2223 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2224 | Local<String> Message::GetSourceLine() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2225 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2226 | ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2227 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2228 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2229 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2230 | i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine", |
| 2231 | Utils::OpenHandle(this), |
| 2232 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2233 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::String>()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2234 | if (result->IsString()) { |
| 2235 | return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result))); |
| 2236 | } else { |
| 2237 | return Local<String>(); |
| 2238 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2242 | void Message::PrintCurrentStackTrace(FILE* out) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2243 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2244 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2245 | isolate->PrintCurrentStackTrace(out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2249 | // --- S t a c k T r a c e --- |
| 2250 | |
| 2251 | Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2252 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2253 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2254 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2255 | i::Handle<i::JSArray> self = Utils::OpenHandle(this); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 2256 | i::Object* raw_object = self->GetElementNoExceptionThrown(isolate, index); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2257 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2258 | return scope.Close(Utils::StackFrameToLocal(obj)); |
| 2259 | } |
| 2260 | |
| 2261 | |
| 2262 | int StackTrace::GetFrameCount() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2263 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2264 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2265 | return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); |
| 2266 | } |
| 2267 | |
| 2268 | |
| 2269 | Local<Array> StackTrace::AsArray() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2270 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2271 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2272 | return Utils::ToLocal(Utils::OpenHandle(this)); |
| 2273 | } |
| 2274 | |
| 2275 | |
| 2276 | Local<StackTrace> StackTrace::CurrentStackTrace(int frame_limit, |
| 2277 | StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2278 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2279 | ENTER_V8(isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2280 | i::Handle<i::JSArray> stackTrace = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2281 | isolate->CaptureCurrentStackTrace(frame_limit, options); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2282 | return Utils::StackTraceToLocal(stackTrace); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | |
| 2286 | // --- S t a c k F r a m e --- |
| 2287 | |
| 2288 | int StackFrame::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2289 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2290 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2291 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2292 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2293 | i::Handle<i::Object> line = GetProperty(self, "lineNumber"); |
| 2294 | if (!line->IsSmi()) { |
| 2295 | return Message::kNoLineNumberInfo; |
| 2296 | } |
| 2297 | return i::Smi::cast(*line)->value(); |
| 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | int StackFrame::GetColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2302 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2303 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2304 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2305 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2306 | i::Handle<i::Object> column = GetProperty(self, "column"); |
| 2307 | if (!column->IsSmi()) { |
| 2308 | return Message::kNoColumnInfo; |
| 2309 | } |
| 2310 | return i::Smi::cast(*column)->value(); |
| 2311 | } |
| 2312 | |
| 2313 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 2314 | int StackFrame::GetScriptId() const { |
| 2315 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 2316 | ENTER_V8(isolate); |
| 2317 | i::HandleScope scope(isolate); |
| 2318 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2319 | i::Handle<i::Object> scriptId = GetProperty(self, "scriptId"); |
| 2320 | if (!scriptId->IsSmi()) { |
| 2321 | return Message::kNoScriptIdInfo; |
| 2322 | } |
| 2323 | return i::Smi::cast(*scriptId)->value(); |
| 2324 | } |
| 2325 | |
| 2326 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2327 | Local<String> StackFrame::GetScriptName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2328 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2329 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2330 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2331 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2332 | i::Handle<i::Object> name = GetProperty(self, "scriptName"); |
| 2333 | if (!name->IsString()) { |
| 2334 | return Local<String>(); |
| 2335 | } |
| 2336 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2337 | } |
| 2338 | |
| 2339 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2340 | Local<String> StackFrame::GetScriptNameOrSourceURL() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2341 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2342 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2343 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2344 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2345 | i::Handle<i::Object> name = GetProperty(self, "scriptNameOrSourceURL"); |
| 2346 | if (!name->IsString()) { |
| 2347 | return Local<String>(); |
| 2348 | } |
| 2349 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2350 | } |
| 2351 | |
| 2352 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2353 | Local<String> StackFrame::GetFunctionName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2354 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2355 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 2356 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2357 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2358 | i::Handle<i::Object> name = GetProperty(self, "functionName"); |
| 2359 | if (!name->IsString()) { |
| 2360 | return Local<String>(); |
| 2361 | } |
| 2362 | return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); |
| 2363 | } |
| 2364 | |
| 2365 | |
| 2366 | bool StackFrame::IsEval() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2367 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2368 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2369 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2370 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2371 | i::Handle<i::Object> is_eval = GetProperty(self, "isEval"); |
| 2372 | return is_eval->IsTrue(); |
| 2373 | } |
| 2374 | |
| 2375 | |
| 2376 | bool StackFrame::IsConstructor() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2377 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2378 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2379 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2380 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2381 | i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor"); |
| 2382 | return is_constructor->IsTrue(); |
| 2383 | } |
| 2384 | |
| 2385 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2386 | // --- J S O N --- |
| 2387 | |
| 2388 | Local<Value> JSON::Parse(Local<String> json_string) { |
| 2389 | i::Isolate* isolate = i::Isolate::Current(); |
| 2390 | EnsureInitializedForIsolate(isolate, "v8::JSON::Parse"); |
| 2391 | ENTER_V8(isolate); |
| 2392 | i::HandleScope scope(isolate); |
| 2393 | i::Handle<i::String> source = i::Handle<i::String>( |
| 2394 | FlattenGetString(Utils::OpenHandle(*json_string))); |
| 2395 | EXCEPTION_PREAMBLE(isolate); |
| 2396 | i::Handle<i::Object> result; |
| 2397 | if (source->IsSeqOneByteString()) { |
| 2398 | result = i::JsonParser<true>::Parse(source); |
| 2399 | } else { |
| 2400 | result = i::JsonParser<false>::Parse(source); |
| 2401 | } |
| 2402 | has_pending_exception = result.is_null(); |
| 2403 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
| 2404 | return Utils::ToLocal( |
| 2405 | i::Handle<i::Object>::cast(scope.CloseAndEscape(result))); |
| 2406 | } |
| 2407 | |
| 2408 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2409 | // --- D a t a --- |
| 2410 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2411 | bool Value::FullIsUndefined() const { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2412 | bool result = Utils::OpenHandle(this)->IsUndefined(); |
| 2413 | ASSERT_EQ(result, QuickIsUndefined()); |
| 2414 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2418 | bool Value::FullIsNull() const { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2419 | bool result = Utils::OpenHandle(this)->IsNull(); |
| 2420 | ASSERT_EQ(result, QuickIsNull()); |
| 2421 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2425 | bool Value::IsTrue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2426 | return Utils::OpenHandle(this)->IsTrue(); |
| 2427 | } |
| 2428 | |
| 2429 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2430 | bool Value::IsFalse() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2431 | return Utils::OpenHandle(this)->IsFalse(); |
| 2432 | } |
| 2433 | |
| 2434 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2435 | bool Value::IsFunction() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2436 | return Utils::OpenHandle(this)->IsJSFunction(); |
| 2437 | } |
| 2438 | |
| 2439 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2440 | bool Value::FullIsString() const { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2441 | bool result = Utils::OpenHandle(this)->IsString(); |
| 2442 | ASSERT_EQ(result, QuickIsString()); |
| 2443 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2447 | bool Value::IsSymbol() const { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2448 | return Utils::OpenHandle(this)->IsSymbol(); |
| 2449 | } |
| 2450 | |
| 2451 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2452 | bool Value::IsArray() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2453 | return Utils::OpenHandle(this)->IsJSArray(); |
| 2454 | } |
| 2455 | |
| 2456 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2457 | bool Value::IsArrayBuffer() const { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2458 | return Utils::OpenHandle(this)->IsJSArrayBuffer(); |
| 2459 | } |
| 2460 | |
| 2461 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2462 | bool Value::IsArrayBufferView() const { |
| 2463 | return Utils::OpenHandle(this)->IsJSArrayBufferView(); |
| 2464 | } |
| 2465 | |
| 2466 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2467 | bool Value::IsTypedArray() const { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2468 | return Utils::OpenHandle(this)->IsJSTypedArray(); |
| 2469 | } |
| 2470 | |
| 2471 | |
| 2472 | #define TYPED_ARRAY_LIST(F) \ |
| 2473 | F(Uint8Array, kExternalUnsignedByteArray) \ |
| 2474 | F(Int8Array, kExternalByteArray) \ |
| 2475 | F(Uint16Array, kExternalUnsignedShortArray) \ |
| 2476 | F(Int16Array, kExternalShortArray) \ |
| 2477 | F(Uint32Array, kExternalUnsignedIntArray) \ |
| 2478 | F(Int32Array, kExternalIntArray) \ |
| 2479 | F(Float32Array, kExternalFloatArray) \ |
| 2480 | F(Float64Array, kExternalDoubleArray) \ |
| 2481 | F(Uint8ClampedArray, kExternalPixelArray) |
| 2482 | |
| 2483 | |
| 2484 | #define VALUE_IS_TYPED_ARRAY(TypedArray, type_const) \ |
| 2485 | bool Value::Is##TypedArray() const { \ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2486 | i::Handle<i::Object> obj = Utils::OpenHandle(this); \ |
| 2487 | if (!obj->IsJSTypedArray()) return false; \ |
| 2488 | return i::JSTypedArray::cast(*obj)->type() == type_const; \ |
| 2489 | } |
| 2490 | |
| 2491 | TYPED_ARRAY_LIST(VALUE_IS_TYPED_ARRAY) |
| 2492 | |
| 2493 | #undef VALUE_IS_TYPED_ARRAY |
| 2494 | |
| 2495 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2496 | bool Value::IsDataView() const { |
| 2497 | return Utils::OpenHandle(this)->IsJSDataView(); |
| 2498 | } |
| 2499 | |
| 2500 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2501 | bool Value::IsObject() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2502 | return Utils::OpenHandle(this)->IsJSObject(); |
| 2503 | } |
| 2504 | |
| 2505 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2506 | bool Value::IsNumber() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2507 | return Utils::OpenHandle(this)->IsNumber(); |
| 2508 | } |
| 2509 | |
| 2510 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2511 | bool Value::IsBoolean() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2512 | return Utils::OpenHandle(this)->IsBoolean(); |
| 2513 | } |
| 2514 | |
| 2515 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2516 | bool Value::IsExternal() const { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2517 | return Utils::OpenHandle(this)->IsExternal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2521 | bool Value::IsInt32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2522 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2523 | if (obj->IsSmi()) return true; |
| 2524 | if (obj->IsNumber()) { |
| 2525 | double value = obj->Number(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2526 | static const i::DoubleRepresentation minus_zero(-0.0); |
| 2527 | i::DoubleRepresentation rep(value); |
| 2528 | if (rep.bits == minus_zero.bits) { |
| 2529 | return false; |
| 2530 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2531 | return i::FastI2D(i::FastD2I(value)) == value; |
| 2532 | } |
| 2533 | return false; |
| 2534 | } |
| 2535 | |
| 2536 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2537 | bool Value::IsUint32() const { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2538 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2539 | if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0; |
| 2540 | if (obj->IsNumber()) { |
| 2541 | double value = obj->Number(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2542 | static const i::DoubleRepresentation minus_zero(-0.0); |
| 2543 | i::DoubleRepresentation rep(value); |
| 2544 | if (rep.bits == minus_zero.bits) { |
| 2545 | return false; |
| 2546 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2547 | return i::FastUI2D(i::FastD2UI(value)) == value; |
| 2548 | } |
| 2549 | return false; |
| 2550 | } |
| 2551 | |
| 2552 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2553 | bool Value::IsDate() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2554 | i::Isolate* isolate = i::Isolate::Current(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2555 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2556 | return obj->HasSpecificClassOf(isolate->heap()->Date_string()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2560 | bool Value::IsStringObject() const { |
| 2561 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2562 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2563 | return obj->HasSpecificClassOf(isolate->heap()->String_string()); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2567 | bool Value::IsSymbolObject() const { |
| 2568 | // TODO(svenpanne): these and other test functions should be written such |
| 2569 | // that they do not use Isolate::Current(). |
| 2570 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2571 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2572 | return obj->HasSpecificClassOf(isolate->heap()->Symbol_string()); |
| 2573 | } |
| 2574 | |
| 2575 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2576 | bool Value::IsNumberObject() const { |
| 2577 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2578 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2579 | return obj->HasSpecificClassOf(isolate->heap()->Number_string()); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | |
| 2583 | static i::Object* LookupBuiltin(i::Isolate* isolate, |
| 2584 | const char* builtin_name) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2585 | i::Handle<i::String> string = |
| 2586 | isolate->factory()->InternalizeUtf8String(builtin_name); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2587 | i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2588 | return builtins->GetPropertyNoExceptionThrown(*string); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | |
| 2592 | static bool CheckConstructor(i::Isolate* isolate, |
| 2593 | i::Handle<i::JSObject> obj, |
| 2594 | const char* class_name) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2595 | i::Object* constr = obj->map()->constructor(); |
| 2596 | if (!constr->IsJSFunction()) return false; |
| 2597 | i::JSFunction* func = i::JSFunction::cast(constr); |
| 2598 | return func->shared()->native() && |
| 2599 | constr == LookupBuiltin(isolate, class_name); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | |
| 2603 | bool Value::IsNativeError() const { |
| 2604 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2605 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2606 | if (obj->IsJSObject()) { |
| 2607 | i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj)); |
| 2608 | return CheckConstructor(isolate, js_obj, "$Error") || |
| 2609 | CheckConstructor(isolate, js_obj, "$EvalError") || |
| 2610 | CheckConstructor(isolate, js_obj, "$RangeError") || |
| 2611 | CheckConstructor(isolate, js_obj, "$ReferenceError") || |
| 2612 | CheckConstructor(isolate, js_obj, "$SyntaxError") || |
| 2613 | CheckConstructor(isolate, js_obj, "$TypeError") || |
| 2614 | CheckConstructor(isolate, js_obj, "$URIError"); |
| 2615 | } else { |
| 2616 | return false; |
| 2617 | } |
| 2618 | } |
| 2619 | |
| 2620 | |
| 2621 | bool Value::IsBooleanObject() const { |
| 2622 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2623 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2624 | return obj->HasSpecificClassOf(isolate->heap()->Boolean_string()); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2628 | bool Value::IsRegExp() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2629 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2630 | return obj->IsJSRegExp(); |
| 2631 | } |
| 2632 | |
| 2633 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2634 | Local<String> Value::ToString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2635 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2636 | i::Handle<i::Object> str; |
| 2637 | if (obj->IsString()) { |
| 2638 | str = obj; |
| 2639 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2640 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2641 | LOG_API(isolate, "ToString"); |
| 2642 | ENTER_V8(isolate); |
| 2643 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2644 | str = i::Execution::ToString(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2645 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2646 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2647 | return ToApiHandle<String>(str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2651 | Local<String> Value::ToDetailString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2652 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2653 | i::Handle<i::Object> str; |
| 2654 | if (obj->IsString()) { |
| 2655 | str = obj; |
| 2656 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2657 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2658 | LOG_API(isolate, "ToDetailString"); |
| 2659 | ENTER_V8(isolate); |
| 2660 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2661 | str = i::Execution::ToDetailString(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2662 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2663 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2664 | return ToApiHandle<String>(str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2668 | Local<v8::Object> Value::ToObject() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2669 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2670 | i::Handle<i::Object> val; |
| 2671 | if (obj->IsJSObject()) { |
| 2672 | val = obj; |
| 2673 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2674 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2675 | LOG_API(isolate, "ToObject"); |
| 2676 | ENTER_V8(isolate); |
| 2677 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2678 | val = i::Execution::ToObject(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2679 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2680 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2681 | return ToApiHandle<Object>(val); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2685 | Local<Boolean> Value::ToBoolean() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2686 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2687 | if (obj->IsBoolean()) { |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2688 | return ToApiHandle<Boolean>(obj); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2689 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2690 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2691 | LOG_API(isolate, "ToBoolean"); |
| 2692 | ENTER_V8(isolate); |
svenpanne@chromium.org | 9faefa4 | 2013-03-08 13:13:16 +0000 | [diff] [blame] | 2693 | i::Handle<i::Object> val = |
| 2694 | isolate->factory()->ToBoolean(obj->BooleanValue()); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2695 | return ToApiHandle<Boolean>(val); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2696 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2700 | Local<Number> Value::ToNumber() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2701 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2702 | i::Handle<i::Object> num; |
| 2703 | if (obj->IsNumber()) { |
| 2704 | num = obj; |
| 2705 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2706 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2707 | LOG_API(isolate, "ToNumber"); |
| 2708 | ENTER_V8(isolate); |
| 2709 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2710 | num = i::Execution::ToNumber(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2711 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Number>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2712 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2713 | return ToApiHandle<Number>(num); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2717 | Local<Integer> Value::ToInteger() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2718 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2719 | i::Handle<i::Object> num; |
| 2720 | if (obj->IsSmi()) { |
| 2721 | num = obj; |
| 2722 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2723 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2724 | LOG_API(isolate, "ToInteger"); |
| 2725 | ENTER_V8(isolate); |
| 2726 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2727 | num = i::Execution::ToInteger(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2728 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2729 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2730 | return ToApiHandle<Integer>(num); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 2734 | void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2735 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2736 | ApiCheck(isolate != NULL && isolate->IsInitialized() && !isolate->IsDead(), |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2737 | "v8::internal::Internals::CheckInitialized()", |
| 2738 | "Isolate is not initialized or V8 has died"); |
| 2739 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2740 | |
| 2741 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2742 | void External::CheckCast(v8::Value* that) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2743 | ApiCheck(Utils::OpenHandle(that)->IsExternal(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2744 | "v8::External::Cast()", |
| 2745 | "Could not convert to external"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2749 | void v8::Object::CheckCast(Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2750 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2751 | ApiCheck(obj->IsJSObject(), |
| 2752 | "v8::Object::Cast()", |
| 2753 | "Could not convert to object"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2757 | void v8::Function::CheckCast(Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2758 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2759 | ApiCheck(obj->IsJSFunction(), |
| 2760 | "v8::Function::Cast()", |
| 2761 | "Could not convert to function"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2765 | void v8::String::CheckCast(v8::Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2766 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2767 | ApiCheck(obj->IsString(), |
| 2768 | "v8::String::Cast()", |
| 2769 | "Could not convert to string"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2773 | void v8::Symbol::CheckCast(v8::Value* that) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2774 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2775 | ApiCheck(obj->IsSymbol(), |
| 2776 | "v8::Symbol::Cast()", |
| 2777 | "Could not convert to symbol"); |
| 2778 | } |
| 2779 | |
| 2780 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2781 | void v8::Number::CheckCast(v8::Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2782 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2783 | ApiCheck(obj->IsNumber(), |
| 2784 | "v8::Number::Cast()", |
| 2785 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2789 | void v8::Integer::CheckCast(v8::Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2790 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2791 | ApiCheck(obj->IsNumber(), |
| 2792 | "v8::Integer::Cast()", |
| 2793 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2797 | void v8::Array::CheckCast(Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2798 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2799 | ApiCheck(obj->IsJSArray(), |
| 2800 | "v8::Array::Cast()", |
| 2801 | "Could not convert to array"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2805 | void v8::ArrayBuffer::CheckCast(Value* that) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2806 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2807 | ApiCheck(obj->IsJSArrayBuffer(), |
| 2808 | "v8::ArrayBuffer::Cast()", |
| 2809 | "Could not convert to ArrayBuffer"); |
| 2810 | } |
| 2811 | |
| 2812 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2813 | void v8::ArrayBufferView::CheckCast(Value* that) { |
| 2814 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2815 | ApiCheck(obj->IsJSArrayBufferView(), |
| 2816 | "v8::ArrayBufferView::Cast()", |
| 2817 | "Could not convert to ArrayBufferView"); |
| 2818 | } |
| 2819 | |
| 2820 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2821 | void v8::TypedArray::CheckCast(Value* that) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2822 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2823 | ApiCheck(obj->IsJSTypedArray(), |
| 2824 | "v8::TypedArray::Cast()", |
| 2825 | "Could not convert to TypedArray"); |
| 2826 | } |
| 2827 | |
| 2828 | |
| 2829 | #define CHECK_TYPED_ARRAY_CAST(ApiClass, typeConst) \ |
| 2830 | void v8::ApiClass::CheckCast(Value* that) { \ |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2831 | i::Handle<i::Object> obj = Utils::OpenHandle(that); \ |
| 2832 | ApiCheck(obj->IsJSTypedArray() && \ |
| 2833 | i::JSTypedArray::cast(*obj)->type() == typeConst, \ |
| 2834 | "v8::" #ApiClass "::Cast()", \ |
| 2835 | "Could not convert to " #ApiClass); \ |
| 2836 | } |
| 2837 | |
| 2838 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2839 | TYPED_ARRAY_LIST(CHECK_TYPED_ARRAY_CAST) |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2840 | |
| 2841 | #undef CHECK_TYPED_ARRAY_CAST |
| 2842 | |
| 2843 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2844 | void v8::DataView::CheckCast(Value* that) { |
| 2845 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2846 | ApiCheck(obj->IsJSDataView(), |
| 2847 | "v8::DataView::Cast()", |
| 2848 | "Could not convert to DataView"); |
| 2849 | } |
| 2850 | |
| 2851 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2852 | void v8::Date::CheckCast(v8::Value* that) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2853 | i::Isolate* isolate = i::Isolate::Current(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2854 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2855 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_string()), |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2856 | "v8::Date::Cast()", |
| 2857 | "Could not convert to date"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2861 | void v8::StringObject::CheckCast(v8::Value* that) { |
| 2862 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2863 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2864 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->String_string()), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2865 | "v8::StringObject::Cast()", |
| 2866 | "Could not convert to StringObject"); |
| 2867 | } |
| 2868 | |
| 2869 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2870 | void v8::SymbolObject::CheckCast(v8::Value* that) { |
| 2871 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2872 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2873 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Symbol_string()), |
| 2874 | "v8::SymbolObject::Cast()", |
| 2875 | "Could not convert to SymbolObject"); |
| 2876 | } |
| 2877 | |
| 2878 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2879 | void v8::NumberObject::CheckCast(v8::Value* that) { |
| 2880 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2881 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2882 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Number_string()), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2883 | "v8::NumberObject::Cast()", |
| 2884 | "Could not convert to NumberObject"); |
| 2885 | } |
| 2886 | |
| 2887 | |
| 2888 | void v8::BooleanObject::CheckCast(v8::Value* that) { |
| 2889 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2890 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2891 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Boolean_string()), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2892 | "v8::BooleanObject::Cast()", |
| 2893 | "Could not convert to BooleanObject"); |
| 2894 | } |
| 2895 | |
| 2896 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2897 | void v8::RegExp::CheckCast(v8::Value* that) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2898 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2899 | ApiCheck(obj->IsJSRegExp(), |
| 2900 | "v8::RegExp::Cast()", |
| 2901 | "Could not convert to regular expression"); |
| 2902 | } |
| 2903 | |
| 2904 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2905 | bool Value::BooleanValue() const { |
svenpanne@chromium.org | 9faefa4 | 2013-03-08 13:13:16 +0000 | [diff] [blame] | 2906 | return Utils::OpenHandle(this)->BooleanValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2910 | double Value::NumberValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2911 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2912 | i::Handle<i::Object> num; |
| 2913 | if (obj->IsNumber()) { |
| 2914 | num = obj; |
| 2915 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2916 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2917 | LOG_API(isolate, "NumberValue"); |
| 2918 | ENTER_V8(isolate); |
| 2919 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2920 | num = i::Execution::ToNumber(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2921 | EXCEPTION_BAILOUT_CHECK(isolate, i::OS::nan_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2922 | } |
| 2923 | return num->Number(); |
| 2924 | } |
| 2925 | |
| 2926 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2927 | int64_t Value::IntegerValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2928 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2929 | i::Handle<i::Object> num; |
| 2930 | if (obj->IsNumber()) { |
| 2931 | num = obj; |
| 2932 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2933 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2934 | LOG_API(isolate, "IntegerValue"); |
| 2935 | ENTER_V8(isolate); |
| 2936 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2937 | num = i::Execution::ToInteger(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2938 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2939 | } |
| 2940 | if (num->IsSmi()) { |
| 2941 | return i::Smi::cast(*num)->value(); |
| 2942 | } else { |
| 2943 | return static_cast<int64_t>(num->Number()); |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2948 | Local<Int32> Value::ToInt32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2949 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2950 | i::Handle<i::Object> num; |
| 2951 | if (obj->IsSmi()) { |
| 2952 | num = obj; |
| 2953 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2954 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2955 | LOG_API(isolate, "ToInt32"); |
| 2956 | ENTER_V8(isolate); |
| 2957 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2958 | num = i::Execution::ToInt32(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2959 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Int32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2960 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2961 | return ToApiHandle<Int32>(num); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2965 | Local<Uint32> Value::ToUint32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2966 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2967 | i::Handle<i::Object> num; |
| 2968 | if (obj->IsSmi()) { |
| 2969 | num = obj; |
| 2970 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2971 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2972 | LOG_API(isolate, "ToUInt32"); |
| 2973 | ENTER_V8(isolate); |
| 2974 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2975 | num = i::Execution::ToUint32(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2976 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2977 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2978 | return ToApiHandle<Uint32>(num); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2982 | Local<Uint32> Value::ToArrayIndex() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2983 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2984 | if (obj->IsSmi()) { |
| 2985 | if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj); |
| 2986 | return Local<Uint32>(); |
| 2987 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2988 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2989 | LOG_API(isolate, "ToArrayIndex"); |
| 2990 | ENTER_V8(isolate); |
| 2991 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2992 | i::Handle<i::Object> string_obj = |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2993 | i::Execution::ToString(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2994 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2995 | i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); |
| 2996 | uint32_t index; |
| 2997 | if (str->AsArrayIndex(&index)) { |
| 2998 | i::Handle<i::Object> value; |
| 2999 | if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3000 | value = i::Handle<i::Object>(i::Smi::FromInt(index), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3001 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3002 | value = isolate->factory()->NewNumber(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3003 | } |
| 3004 | return Utils::Uint32ToLocal(value); |
| 3005 | } |
| 3006 | return Local<Uint32>(); |
| 3007 | } |
| 3008 | |
| 3009 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3010 | int32_t Value::Int32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3011 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3012 | if (obj->IsSmi()) { |
| 3013 | return i::Smi::cast(*obj)->value(); |
| 3014 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3015 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3016 | LOG_API(isolate, "Int32Value (slow)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3017 | ENTER_V8(isolate); |
| 3018 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3019 | i::Handle<i::Object> num = |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3020 | i::Execution::ToInt32(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3021 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3022 | if (num->IsSmi()) { |
| 3023 | return i::Smi::cast(*num)->value(); |
| 3024 | } else { |
| 3025 | return static_cast<int32_t>(num->Number()); |
| 3026 | } |
| 3027 | } |
| 3028 | } |
| 3029 | |
| 3030 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3031 | bool Value::Equals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3032 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 3033 | if (EmptyCheck("v8::Value::Equals()", this) || |
| 3034 | EmptyCheck("v8::Value::Equals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3035 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 3036 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3037 | LOG_API(isolate, "Equals"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3038 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3039 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3040 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3041 | // If both obj and other are JSObjects, we'd better compare by identity |
| 3042 | // immediately when going into JS builtin. The reason is Invoke |
| 3043 | // would overwrite global object receiver with global proxy. |
| 3044 | if (obj->IsJSObject() && other->IsJSObject()) { |
| 3045 | return *obj == *other; |
| 3046 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3047 | i::Handle<i::Object> args[] = { other }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3048 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3049 | i::Handle<i::Object> result = |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3050 | CallV8HeapFunction("EQUALS", obj, ARRAY_SIZE(args), args, |
| 3051 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3052 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3053 | return *result == i::Smi::FromInt(i::EQUAL); |
| 3054 | } |
| 3055 | |
| 3056 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3057 | bool Value::StrictEquals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3058 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 3059 | if (EmptyCheck("v8::Value::StrictEquals()", this) || |
| 3060 | EmptyCheck("v8::Value::StrictEquals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3061 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 3062 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3063 | LOG_API(isolate, "StrictEquals"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3064 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3065 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
| 3066 | // Must check HeapNumber first, since NaN !== NaN. |
| 3067 | if (obj->IsHeapNumber()) { |
| 3068 | if (!other->IsNumber()) return false; |
| 3069 | double x = obj->Number(); |
| 3070 | double y = other->Number(); |
| 3071 | // Must check explicitly for NaN:s on Windows, but -0 works fine. |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 3072 | return x == y && !std::isnan(x) && !std::isnan(y); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3073 | } else if (*obj == *other) { // Also covers Booleans. |
| 3074 | return true; |
| 3075 | } else if (obj->IsSmi()) { |
| 3076 | return other->IsNumber() && obj->Number() == other->Number(); |
| 3077 | } else if (obj->IsString()) { |
| 3078 | return other->IsString() && |
| 3079 | i::String::cast(*obj)->Equals(i::String::cast(*other)); |
| 3080 | } else if (obj->IsUndefined() || obj->IsUndetectableObject()) { |
| 3081 | return other->IsUndefined() || other->IsUndetectableObject(); |
| 3082 | } else { |
| 3083 | return false; |
| 3084 | } |
| 3085 | } |
| 3086 | |
| 3087 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 3088 | bool Value::SameValue(Handle<Value> that) const { |
| 3089 | i::Isolate* isolate = i::Isolate::Current(); |
| 3090 | if (EmptyCheck("v8::Value::SameValue()", this) || |
| 3091 | EmptyCheck("v8::Value::SameValue()", that)) { |
| 3092 | return false; |
| 3093 | } |
| 3094 | LOG_API(isolate, "SameValue"); |
| 3095 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3096 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
| 3097 | return obj->SameValue(*other); |
| 3098 | } |
| 3099 | |
| 3100 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3101 | uint32_t Value::Uint32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3102 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3103 | if (obj->IsSmi()) { |
| 3104 | return i::Smi::cast(*obj)->value(); |
| 3105 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3106 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3107 | LOG_API(isolate, "Uint32Value"); |
| 3108 | ENTER_V8(isolate); |
| 3109 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3110 | i::Handle<i::Object> num = |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3111 | i::Execution::ToUint32(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3112 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3113 | if (num->IsSmi()) { |
| 3114 | return i::Smi::cast(*num)->value(); |
| 3115 | } else { |
| 3116 | return static_cast<uint32_t>(num->Number()); |
| 3117 | } |
| 3118 | } |
| 3119 | } |
| 3120 | |
| 3121 | |
| 3122 | 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] | 3123 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3124 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3125 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3126 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3127 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3128 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 3129 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3130 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3131 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3132 | i::Handle<i::Object> obj = i::SetProperty( |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3133 | isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3134 | self, |
| 3135 | key_obj, |
| 3136 | value_obj, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3137 | static_cast<PropertyAttributes>(attribs), |
| 3138 | i::kNonStrictMode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3139 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3140 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3141 | return true; |
| 3142 | } |
| 3143 | |
| 3144 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3145 | bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3146 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3147 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3148 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3149 | i::HandleScope scope(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3150 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3151 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3152 | EXCEPTION_PREAMBLE(isolate); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3153 | i::Handle<i::Object> obj = i::JSObject::SetElement( |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3154 | self, |
| 3155 | index, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3156 | value_obj, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 3157 | NONE, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3158 | i::kNonStrictMode); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3159 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3160 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3161 | return true; |
| 3162 | } |
| 3163 | |
| 3164 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3165 | bool v8::Object::ForceSet(v8::Handle<Value> key, |
| 3166 | v8::Handle<Value> value, |
| 3167 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3168 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3169 | ON_BAILOUT(isolate, "v8::Object::ForceSet()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3170 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3171 | i::HandleScope scope(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3172 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3173 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3174 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3175 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3176 | i::Handle<i::Object> obj = i::ForceSetProperty( |
| 3177 | self, |
| 3178 | key_obj, |
| 3179 | value_obj, |
| 3180 | static_cast<PropertyAttributes>(attribs)); |
| 3181 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3182 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3183 | return true; |
| 3184 | } |
| 3185 | |
| 3186 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3187 | bool v8::Object::ForceDelete(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3188 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3189 | ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3190 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3191 | i::HandleScope scope(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3192 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3193 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3194 | |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 3195 | // When deleting a property on the global object using ForceDelete |
| 3196 | // deoptimize all functions as optimized code does not check for the hole |
| 3197 | // value with DontDelete properties. We have to deoptimize all contexts |
| 3198 | // because of possible cross-context inlined functions. |
| 3199 | if (self->IsJSGlobalProxy() || self->IsGlobalObject()) { |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 3200 | i::Deoptimizer::DeoptimizeAll(isolate); |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 3201 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3202 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3203 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3204 | i::Handle<i::Object> obj = i::ForceDeleteProperty(self, key_obj); |
| 3205 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3206 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3207 | return obj->IsTrue(); |
| 3208 | } |
| 3209 | |
| 3210 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3211 | Local<Value> v8::Object::Get(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3212 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3213 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
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 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 3216 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3217 | EXCEPTION_PREAMBLE(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3218 | i::Handle<i::Object> result = i::GetProperty(isolate, self, key_obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3219 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3220 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3221 | return Utils::ToLocal(result); |
| 3222 | } |
| 3223 | |
| 3224 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3225 | Local<Value> v8::Object::Get(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3226 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3227 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3228 | ENTER_V8(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3229 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3230 | EXCEPTION_PREAMBLE(isolate); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3231 | i::Handle<i::Object> result = i::Object::GetElement(isolate, self, index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3232 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3233 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3234 | return Utils::ToLocal(result); |
| 3235 | } |
| 3236 | |
| 3237 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3238 | PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { |
| 3239 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3240 | ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()", |
| 3241 | return static_cast<PropertyAttribute>(NONE)); |
| 3242 | ENTER_V8(isolate); |
| 3243 | i::HandleScope scope(isolate); |
| 3244 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3245 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3246 | if (!key_obj->IsName()) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3247 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3248 | key_obj = i::Execution::ToString(isolate, key_obj, &has_pending_exception); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3249 | EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE)); |
| 3250 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3251 | i::Handle<i::Name> key_name = i::Handle<i::Name>::cast(key_obj); |
| 3252 | PropertyAttributes result = self->GetPropertyAttribute(*key_name); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3253 | if (result == ABSENT) return static_cast<PropertyAttribute>(NONE); |
| 3254 | return static_cast<PropertyAttribute>(result); |
| 3255 | } |
| 3256 | |
| 3257 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3258 | Local<Value> v8::Object::GetPrototype() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3259 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3260 | ON_BAILOUT(isolate, "v8::Object::GetPrototype()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3261 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3262 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3263 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3264 | i::Handle<i::Object> result(self->GetPrototype(isolate), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3265 | return Utils::ToLocal(result); |
| 3266 | } |
| 3267 | |
| 3268 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3269 | bool v8::Object::SetPrototype(Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3270 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3271 | ON_BAILOUT(isolate, "v8::Object::SetPrototype()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3272 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3273 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3274 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3275 | // We do not allow exceptions thrown while setting the prototype |
| 3276 | // to propagate outside. |
| 3277 | TryCatch try_catch; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3278 | EXCEPTION_PREAMBLE(isolate); |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 3279 | i::Handle<i::Object> result = i::JSObject::SetPrototype(self, value_obj); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3280 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3281 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3282 | return true; |
| 3283 | } |
| 3284 | |
| 3285 | |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 3286 | Local<Object> v8::Object::FindInstanceInPrototypeChain( |
| 3287 | v8::Handle<FunctionTemplate> tmpl) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3288 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3289 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3290 | "v8::Object::FindInstanceInPrototypeChain()", |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 3291 | return Local<v8::Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3292 | ENTER_V8(isolate); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 3293 | i::JSObject* object = *Utils::OpenHandle(this); |
| 3294 | i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl); |
| 3295 | while (!object->IsInstanceOf(tmpl_info)) { |
| 3296 | i::Object* prototype = object->GetPrototype(); |
| 3297 | if (!prototype->IsJSObject()) return Local<Object>(); |
| 3298 | object = i::JSObject::cast(prototype); |
| 3299 | } |
| 3300 | return Utils::ToLocal(i::Handle<i::JSObject>(object)); |
| 3301 | } |
| 3302 | |
| 3303 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3304 | Local<Array> v8::Object::GetPropertyNames() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3305 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3306 | ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()", |
| 3307 | return Local<v8::Array>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3308 | ENTER_V8(isolate); |
| 3309 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3310 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3311 | bool threw = false; |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3312 | i::Handle<i::FixedArray> value = |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3313 | i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS, &threw); |
| 3314 | if (threw) return Local<v8::Array>(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3315 | // Because we use caching to speed up enumeration it is important |
| 3316 | // to never change the result of the basic enumeration function so |
| 3317 | // we clone the result. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3318 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 3319 | i::Handle<i::JSArray> result = |
| 3320 | isolate->factory()->NewJSArrayWithElements(elms); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3321 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3325 | Local<Array> v8::Object::GetOwnPropertyNames() { |
| 3326 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3327 | ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()", |
| 3328 | return Local<v8::Array>()); |
| 3329 | ENTER_V8(isolate); |
| 3330 | i::HandleScope scope(isolate); |
| 3331 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3332 | bool threw = false; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3333 | i::Handle<i::FixedArray> value = |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3334 | i::GetKeysInFixedArrayFor(self, i::LOCAL_ONLY, &threw); |
| 3335 | if (threw) return Local<v8::Array>(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3336 | // Because we use caching to speed up enumeration it is important |
| 3337 | // to never change the result of the basic enumeration function so |
| 3338 | // we clone the result. |
| 3339 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 3340 | i::Handle<i::JSArray> result = |
| 3341 | isolate->factory()->NewJSArrayWithElements(elms); |
| 3342 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
| 3343 | } |
| 3344 | |
| 3345 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3346 | Local<String> v8::Object::ObjectProtoToString() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3347 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3348 | ON_BAILOUT(isolate, "v8::Object::ObjectProtoToString()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3349 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3350 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3351 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3352 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3353 | i::Handle<i::Object> name(self->class_name(), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3354 | |
| 3355 | // Native implementation of Object.prototype.toString (v8natives.js): |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3356 | // var c = %_ClassOf(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3357 | // if (c === 'Arguments') c = 'Object'; |
| 3358 | // return "[object " + c + "]"; |
| 3359 | |
| 3360 | if (!name->IsString()) { |
| 3361 | return v8::String::New("[object ]"); |
| 3362 | |
| 3363 | } else { |
| 3364 | 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] | 3365 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Arguments"))) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3366 | return v8::String::New("[object Object]"); |
| 3367 | |
| 3368 | } else { |
| 3369 | const char* prefix = "[object "; |
| 3370 | Local<String> str = Utils::ToLocal(class_name); |
| 3371 | const char* postfix = "]"; |
| 3372 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3373 | int prefix_len = i::StrLength(prefix); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3374 | int str_len = str->Utf8Length(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3375 | int postfix_len = i::StrLength(postfix); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3376 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3377 | int buf_len = prefix_len + str_len + postfix_len; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3378 | i::ScopedVector<char> buf(buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3379 | |
| 3380 | // Write prefix. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3381 | char* ptr = buf.start(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3382 | i::OS::MemCopy(ptr, prefix, prefix_len * v8::internal::kCharSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3383 | ptr += prefix_len; |
| 3384 | |
| 3385 | // Write real content. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3386 | str->WriteUtf8(ptr, str_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3387 | ptr += str_len; |
| 3388 | |
| 3389 | // Write postfix. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3390 | i::OS::MemCopy(ptr, postfix, postfix_len * v8::internal::kCharSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3391 | |
| 3392 | // Copy the buffer into a heap-allocated string and return it. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3393 | Local<String> result = v8::String::New(buf.start(), buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3394 | return result; |
| 3395 | } |
| 3396 | } |
| 3397 | } |
| 3398 | |
| 3399 | |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 3400 | Local<Value> v8::Object::GetConstructor() { |
| 3401 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3402 | ON_BAILOUT(isolate, "v8::Object::GetConstructor()", |
| 3403 | return Local<v8::Function>()); |
| 3404 | ENTER_V8(isolate); |
| 3405 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3406 | i::Handle<i::Object> constructor(self->GetConstructor(), isolate); |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 3407 | return Utils::ToLocal(constructor); |
| 3408 | } |
| 3409 | |
| 3410 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 3411 | Local<String> v8::Object::GetConstructorName() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3412 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3413 | ON_BAILOUT(isolate, "v8::Object::GetConstructorName()", |
| 3414 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3415 | ENTER_V8(isolate); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 3416 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3417 | i::Handle<i::String> name(self->constructor_name()); |
| 3418 | return Utils::ToLocal(name); |
| 3419 | } |
| 3420 | |
| 3421 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3422 | bool v8::Object::Delete(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3423 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3424 | ON_BAILOUT(isolate, "v8::Object::Delete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3425 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3426 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3427 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3428 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3429 | EXCEPTION_PREAMBLE(isolate); |
| 3430 | i::Handle<i::Object> obj = i::DeleteProperty(self, key_obj); |
| 3431 | has_pending_exception = obj.is_null(); |
| 3432 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
| 3433 | return obj->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3437 | bool v8::Object::Has(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3438 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3439 | ON_BAILOUT(isolate, "v8::Object::Has()", return false); |
| 3440 | ENTER_V8(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3441 | i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); |
| 3442 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3443 | EXCEPTION_PREAMBLE(isolate); |
| 3444 | i::Handle<i::Object> obj = i::HasProperty(self, key_obj); |
| 3445 | has_pending_exception = obj.is_null(); |
| 3446 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
| 3447 | return obj->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | |
| 3451 | bool v8::Object::Delete(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3452 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3453 | ON_BAILOUT(isolate, "v8::Object::DeleteProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3454 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3455 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3456 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3457 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3458 | return i::JSReceiver::DeleteElement(self, index)->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3459 | } |
| 3460 | |
| 3461 | |
| 3462 | bool v8::Object::Has(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3463 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3464 | ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3465 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3466 | return i::JSReceiver::HasElement(self, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3470 | template<typename Setter, typename Getter, typename Data> |
| 3471 | static inline bool ObjectSetAccessor(Object* obj, |
| 3472 | Handle<String> name, |
| 3473 | Setter getter, |
| 3474 | Getter setter, |
| 3475 | Data data, |
| 3476 | AccessControl settings, |
| 3477 | PropertyAttribute attributes) { |
| 3478 | i::Isolate* isolate = Utils::OpenHandle(obj)->GetIsolate(); |
| 3479 | ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false); |
| 3480 | ENTER_V8(isolate); |
| 3481 | i::HandleScope scope(isolate); |
| 3482 | v8::Handle<AccessorSignature> signature; |
| 3483 | i::Handle<i::AccessorInfo> info = MakeAccessorInfo( |
| 3484 | name, getter, setter, data, settings, attributes, signature); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3485 | if (info.is_null()) return false; |
| 3486 | bool fast = Utils::OpenHandle(obj)->HasFastProperties(); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 3487 | i::Handle<i::Object> result = |
| 3488 | i::JSObject::SetAccessor(Utils::OpenHandle(obj), info); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3489 | if (result.is_null() || result->IsUndefined()) return false; |
| 3490 | if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(obj), 0); |
| 3491 | return true; |
| 3492 | } |
| 3493 | |
| 3494 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3495 | bool Object::SetAccessor(Handle<String> name, |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3496 | AccessorGetterCallback getter, |
| 3497 | AccessorSetterCallback setter, |
| 3498 | v8::Handle<Value> data, |
| 3499 | AccessControl settings, |
| 3500 | PropertyAttribute attributes) { |
| 3501 | return ObjectSetAccessor( |
| 3502 | this, name, getter, setter, data, settings, attributes); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3506 | bool Object::SetDeclaredAccessor(Local<String> name, |
| 3507 | Local<DeclaredAccessorDescriptor> descriptor, |
| 3508 | PropertyAttribute attributes, |
| 3509 | AccessControl settings) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3510 | void* null = NULL; |
| 3511 | return ObjectSetAccessor( |
| 3512 | this, name, descriptor, null, null, settings, attributes); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3516 | bool v8::Object::HasOwnProperty(Handle<String> key) { |
| 3517 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3518 | ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", |
| 3519 | return false); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3520 | return i::JSReceiver::HasLocalProperty( |
| 3521 | Utils::OpenHandle(this), Utils::OpenHandle(*key)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3525 | bool v8::Object::HasRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3526 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3527 | ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3528 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3529 | return Utils::OpenHandle(this)->HasRealNamedProperty( |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3530 | isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3531 | *Utils::OpenHandle(*key)); |
| 3532 | } |
| 3533 | |
| 3534 | |
| 3535 | bool v8::Object::HasRealIndexedProperty(uint32_t index) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3536 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3537 | ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3538 | return false); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3539 | return Utils::OpenHandle(this)->HasRealElementProperty(isolate, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | |
| 3543 | bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3544 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3545 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3546 | "v8::Object::HasRealNamedCallbackProperty()", |
| 3547 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3548 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3549 | return Utils::OpenHandle(this)->HasRealNamedCallbackProperty( |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3550 | isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3551 | *Utils::OpenHandle(*key)); |
| 3552 | } |
| 3553 | |
| 3554 | |
| 3555 | bool v8::Object::HasNamedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3556 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3557 | ON_BAILOUT(isolate, "v8::Object::HasNamedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3558 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3559 | return Utils::OpenHandle(this)->HasNamedInterceptor(); |
| 3560 | } |
| 3561 | |
| 3562 | |
| 3563 | bool v8::Object::HasIndexedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3564 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3565 | ON_BAILOUT(isolate, "v8::Object::HasIndexedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3566 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3567 | return Utils::OpenHandle(this)->HasIndexedInterceptor(); |
| 3568 | } |
| 3569 | |
| 3570 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3571 | static Local<Value> GetPropertyByLookup(i::Isolate* isolate, |
| 3572 | i::Handle<i::JSObject> receiver, |
| 3573 | i::Handle<i::String> name, |
| 3574 | i::LookupResult* lookup) { |
| 3575 | if (!lookup->IsProperty()) { |
| 3576 | // No real property was found. |
| 3577 | return Local<Value>(); |
| 3578 | } |
| 3579 | |
| 3580 | // If the property being looked up is a callback, it can throw |
| 3581 | // an exception. |
| 3582 | EXCEPTION_PREAMBLE(isolate); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3583 | PropertyAttributes ignored; |
| 3584 | i::Handle<i::Object> result = |
| 3585 | i::Object::GetProperty(receiver, receiver, lookup, name, |
| 3586 | &ignored); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3587 | has_pending_exception = result.is_null(); |
| 3588 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3589 | |
| 3590 | return Utils::ToLocal(result); |
| 3591 | } |
| 3592 | |
| 3593 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3594 | Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3595 | Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3596 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3597 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3598 | "v8::Object::GetRealNamedPropertyInPrototypeChain()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3599 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3600 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3601 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3602 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3603 | i::LookupResult lookup(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3604 | self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3605 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3609 | Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3610 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3611 | ON_BAILOUT(isolate, "v8::Object::GetRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3612 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3613 | ENTER_V8(isolate); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3614 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3615 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3616 | i::LookupResult lookup(isolate); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3617 | self_obj->LookupRealNamedProperty(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3618 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3622 | // Turns on access checks by copying the map and setting the check flag. |
| 3623 | // Because the object gets a new map, existing inline cache caching |
| 3624 | // the old map of this object will fail. |
| 3625 | void v8::Object::TurnOnAccessCheck() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3626 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3627 | ON_BAILOUT(isolate, "v8::Object::TurnOnAccessCheck()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3628 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3629 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3630 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3631 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3632 | // When turning on access checks for a global object deoptimize all functions |
| 3633 | // as optimized code does not always handle access checks. |
| 3634 | i::Deoptimizer::DeoptimizeGlobalObject(*obj); |
| 3635 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3636 | i::Handle<i::Map> new_map = |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3637 | isolate->factory()->CopyMap(i::Handle<i::Map>(obj->map())); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3638 | new_map->set_is_access_check_needed(true); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3639 | obj->set_map(*new_map); |
| 3640 | } |
| 3641 | |
| 3642 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3643 | bool v8::Object::IsDirty() { |
| 3644 | return Utils::OpenHandle(this)->IsDirty(); |
| 3645 | } |
| 3646 | |
| 3647 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3648 | Local<v8::Object> v8::Object::Clone() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3649 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3650 | ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3651 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3652 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3653 | EXCEPTION_PREAMBLE(isolate); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3654 | i::Handle<i::JSObject> result = i::JSObject::Copy(self); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3655 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3656 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3657 | return Utils::ToLocal(result); |
| 3658 | } |
| 3659 | |
| 3660 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3661 | static i::Context* GetCreationContext(i::JSObject* object) { |
| 3662 | i::Object* constructor = object->map()->constructor(); |
| 3663 | i::JSFunction* function; |
| 3664 | if (!constructor->IsJSFunction()) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3665 | // Functions have null as a constructor, |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3666 | // but any JSFunction knows its context immediately. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3667 | ASSERT(object->IsJSFunction()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3668 | function = i::JSFunction::cast(object); |
| 3669 | } else { |
| 3670 | function = i::JSFunction::cast(constructor); |
| 3671 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3672 | return function->context()->native_context(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | |
| 3676 | Local<v8::Context> v8::Object::CreationContext() { |
| 3677 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3678 | ON_BAILOUT(isolate, |
| 3679 | "v8::Object::CreationContext()", return Local<v8::Context>()); |
| 3680 | ENTER_V8(isolate); |
| 3681 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3682 | i::Context* context = GetCreationContext(*self); |
| 3683 | return Utils::ToLocal(i::Handle<i::Context>(context)); |
| 3684 | } |
| 3685 | |
| 3686 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3687 | int v8::Object::GetIdentityHash() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3688 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3689 | ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3690 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3691 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3692 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3693 | return i::JSObject::GetIdentityHash(self); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | |
| 3697 | bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, |
| 3698 | v8::Handle<v8::Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3699 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3700 | ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 3701 | if (value.IsEmpty()) return DeleteHiddenValue(key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3702 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3703 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3704 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3705 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3706 | i::Handle<i::String> key_string = |
| 3707 | isolate->factory()->InternalizeString(key_obj); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3708 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3709 | i::Handle<i::Object> result = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3710 | i::JSObject::SetHiddenProperty(self, key_string, value_obj); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3711 | return *result == *self; |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3712 | } |
| 3713 | |
| 3714 | |
| 3715 | 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] | 3716 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3717 | ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()", |
| 3718 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3719 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3720 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3721 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3722 | i::Handle<i::String> key_string = |
| 3723 | isolate->factory()->InternalizeString(key_obj); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3724 | i::Handle<i::Object> result(self->GetHiddenProperty(*key_string), isolate); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3725 | if (result->IsTheHole()) return v8::Local<v8::Value>(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3726 | return Utils::ToLocal(result); |
| 3727 | } |
| 3728 | |
| 3729 | |
| 3730 | bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3731 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3732 | ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3733 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3734 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3735 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3736 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3737 | i::Handle<i::String> key_string = |
| 3738 | isolate->factory()->InternalizeString(key_obj); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 3739 | i::JSObject::DeleteHiddenProperty(self, key_string); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3740 | return true; |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3744 | namespace { |
| 3745 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3746 | static i::ElementsKind GetElementsKindFromExternalArrayType( |
| 3747 | ExternalArrayType array_type) { |
| 3748 | switch (array_type) { |
| 3749 | case kExternalByteArray: |
| 3750 | return i::EXTERNAL_BYTE_ELEMENTS; |
| 3751 | break; |
| 3752 | case kExternalUnsignedByteArray: |
| 3753 | return i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS; |
| 3754 | break; |
| 3755 | case kExternalShortArray: |
| 3756 | return i::EXTERNAL_SHORT_ELEMENTS; |
| 3757 | break; |
| 3758 | case kExternalUnsignedShortArray: |
| 3759 | return i::EXTERNAL_UNSIGNED_SHORT_ELEMENTS; |
| 3760 | break; |
| 3761 | case kExternalIntArray: |
| 3762 | return i::EXTERNAL_INT_ELEMENTS; |
| 3763 | break; |
| 3764 | case kExternalUnsignedIntArray: |
| 3765 | return i::EXTERNAL_UNSIGNED_INT_ELEMENTS; |
| 3766 | break; |
| 3767 | case kExternalFloatArray: |
| 3768 | return i::EXTERNAL_FLOAT_ELEMENTS; |
| 3769 | break; |
| 3770 | case kExternalDoubleArray: |
| 3771 | return i::EXTERNAL_DOUBLE_ELEMENTS; |
| 3772 | break; |
| 3773 | case kExternalPixelArray: |
| 3774 | return i::EXTERNAL_PIXEL_ELEMENTS; |
| 3775 | break; |
| 3776 | } |
| 3777 | UNREACHABLE(); |
| 3778 | return i::DICTIONARY_ELEMENTS; |
| 3779 | } |
| 3780 | |
| 3781 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3782 | void PrepareExternalArrayElements(i::Handle<i::JSObject> object, |
| 3783 | void* data, |
| 3784 | ExternalArrayType array_type, |
| 3785 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3786 | i::Isolate* isolate = object->GetIsolate(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3787 | i::Handle<i::ExternalArray> array = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3788 | isolate->factory()->NewExternalArray(length, array_type, data); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3789 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3790 | i::Handle<i::Map> external_array_map = |
| 3791 | isolate->factory()->GetElementsTransitionMap( |
| 3792 | object, |
| 3793 | GetElementsKindFromExternalArrayType(array_type)); |
| 3794 | |
| 3795 | object->set_map(*external_array_map); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3796 | object->set_elements(*array); |
| 3797 | } |
| 3798 | |
| 3799 | } // namespace |
| 3800 | |
| 3801 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3802 | void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3803 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3804 | ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3805 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3806 | i::HandleScope scope(isolate); |
danno@chromium.org | 412fa51 | 2012-09-14 13:28:26 +0000 | [diff] [blame] | 3807 | if (!ApiCheck(length >= 0 && length <= i::ExternalPixelArray::kMaxLength, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3808 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3809 | "length exceeds max acceptable value")) { |
| 3810 | return; |
| 3811 | } |
| 3812 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3813 | if (!ApiCheck(!self->IsJSArray(), |
| 3814 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3815 | "JSArray is not supported")) { |
| 3816 | return; |
| 3817 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3818 | PrepareExternalArrayElements(self, data, kExternalPixelArray, length); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3822 | bool v8::Object::HasIndexedPropertiesInPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3823 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3824 | ON_BAILOUT(self->GetIsolate(), "v8::HasIndexedPropertiesInPixelData()", |
| 3825 | return false); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3826 | return self->HasExternalPixelElements(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3827 | } |
| 3828 | |
| 3829 | |
| 3830 | uint8_t* v8::Object::GetIndexedPropertiesPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3831 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3832 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelData()", |
| 3833 | return NULL); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3834 | if (self->HasExternalPixelElements()) { |
| 3835 | return i::ExternalPixelArray::cast(self->elements())-> |
| 3836 | external_pixel_pointer(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3837 | } else { |
| 3838 | return NULL; |
| 3839 | } |
| 3840 | } |
| 3841 | |
| 3842 | |
| 3843 | int v8::Object::GetIndexedPropertiesPixelDataLength() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3844 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3845 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelDataLength()", |
| 3846 | return -1); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3847 | if (self->HasExternalPixelElements()) { |
| 3848 | return i::ExternalPixelArray::cast(self->elements())->length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3849 | } else { |
| 3850 | return -1; |
| 3851 | } |
| 3852 | } |
| 3853 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3854 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3855 | void v8::Object::SetIndexedPropertiesToExternalArrayData( |
| 3856 | void* data, |
| 3857 | ExternalArrayType array_type, |
| 3858 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3859 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3860 | ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3861 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3862 | i::HandleScope scope(isolate); |
danno@chromium.org | 412fa51 | 2012-09-14 13:28:26 +0000 | [diff] [blame] | 3863 | if (!ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength, |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3864 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3865 | "length exceeds max acceptable value")) { |
| 3866 | return; |
| 3867 | } |
| 3868 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3869 | if (!ApiCheck(!self->IsJSArray(), |
| 3870 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3871 | "JSArray is not supported")) { |
| 3872 | return; |
| 3873 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3874 | PrepareExternalArrayElements(self, data, array_type, length); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3878 | bool v8::Object::HasIndexedPropertiesInExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3879 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3880 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3881 | "v8::HasIndexedPropertiesInExternalArrayData()", |
| 3882 | return false); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3883 | return self->HasExternalArrayElements(); |
| 3884 | } |
| 3885 | |
| 3886 | |
| 3887 | void* v8::Object::GetIndexedPropertiesExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3888 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3889 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3890 | "v8::GetIndexedPropertiesExternalArrayData()", |
| 3891 | return NULL); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3892 | if (self->HasExternalArrayElements()) { |
| 3893 | return i::ExternalArray::cast(self->elements())->external_pointer(); |
| 3894 | } else { |
| 3895 | return NULL; |
| 3896 | } |
| 3897 | } |
| 3898 | |
| 3899 | |
| 3900 | ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3901 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3902 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3903 | "v8::GetIndexedPropertiesExternalArrayDataType()", |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3904 | return static_cast<ExternalArrayType>(-1)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3905 | switch (self->elements()->map()->instance_type()) { |
| 3906 | case i::EXTERNAL_BYTE_ARRAY_TYPE: |
| 3907 | return kExternalByteArray; |
| 3908 | case i::EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 3909 | return kExternalUnsignedByteArray; |
| 3910 | case i::EXTERNAL_SHORT_ARRAY_TYPE: |
| 3911 | return kExternalShortArray; |
| 3912 | case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 3913 | return kExternalUnsignedShortArray; |
| 3914 | case i::EXTERNAL_INT_ARRAY_TYPE: |
| 3915 | return kExternalIntArray; |
| 3916 | case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 3917 | return kExternalUnsignedIntArray; |
| 3918 | case i::EXTERNAL_FLOAT_ARRAY_TYPE: |
| 3919 | return kExternalFloatArray; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3920 | case i::EXTERNAL_DOUBLE_ARRAY_TYPE: |
| 3921 | return kExternalDoubleArray; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3922 | case i::EXTERNAL_PIXEL_ARRAY_TYPE: |
| 3923 | return kExternalPixelArray; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3924 | default: |
| 3925 | return static_cast<ExternalArrayType>(-1); |
| 3926 | } |
| 3927 | } |
| 3928 | |
| 3929 | |
| 3930 | int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3931 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3932 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3933 | "v8::GetIndexedPropertiesExternalArrayDataLength()", |
| 3934 | return 0); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3935 | if (self->HasExternalArrayElements()) { |
| 3936 | return i::ExternalArray::cast(self->elements())->length(); |
| 3937 | } else { |
| 3938 | return -1; |
| 3939 | } |
| 3940 | } |
| 3941 | |
| 3942 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3943 | bool v8::Object::IsCallable() { |
| 3944 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3945 | ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false); |
| 3946 | ENTER_V8(isolate); |
| 3947 | i::HandleScope scope(isolate); |
| 3948 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3949 | if (obj->IsJSFunction()) return true; |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3950 | return i::Execution::GetFunctionDelegate(isolate, obj)->IsJSFunction(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3954 | Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Value> recv, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3955 | int argc, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3956 | v8::Handle<v8::Value> argv[]) { |
| 3957 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3958 | ON_BAILOUT(isolate, "v8::Object::CallAsFunction()", |
| 3959 | return Local<v8::Value>()); |
| 3960 | LOG_API(isolate, "Object::CallAsFunction"); |
| 3961 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3962 | i::Logger::TimerEventScope timer_scope( |
| 3963 | isolate, i::Logger::TimerEventScope::v8_execute); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3964 | i::HandleScope scope(isolate); |
| 3965 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3966 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3967 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3968 | 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] | 3969 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(); |
| 3970 | if (obj->IsJSFunction()) { |
| 3971 | fun = i::Handle<i::JSFunction>::cast(obj); |
| 3972 | } else { |
| 3973 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3974 | i::Handle<i::Object> delegate = i::Execution::TryGetFunctionDelegate( |
| 3975 | isolate, obj, &has_pending_exception); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3976 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3977 | fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3978 | recv_obj = obj; |
| 3979 | } |
| 3980 | EXCEPTION_PREAMBLE(isolate); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 3981 | i::Handle<i::Object> returned = i::Execution::Call( |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3982 | isolate, fun, recv_obj, argc, args, &has_pending_exception, true); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3983 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3984 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3985 | } |
| 3986 | |
| 3987 | |
| 3988 | Local<v8::Value> Object::CallAsConstructor(int argc, |
| 3989 | v8::Handle<v8::Value> argv[]) { |
| 3990 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3991 | ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()", |
| 3992 | return Local<v8::Object>()); |
| 3993 | LOG_API(isolate, "Object::CallAsConstructor"); |
| 3994 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3995 | i::Logger::TimerEventScope timer_scope( |
| 3996 | isolate, i::Logger::TimerEventScope::v8_execute); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3997 | i::HandleScope scope(isolate); |
| 3998 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3999 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 4000 | 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] | 4001 | if (obj->IsJSFunction()) { |
| 4002 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj); |
| 4003 | EXCEPTION_PREAMBLE(isolate); |
| 4004 | i::Handle<i::Object> returned = |
| 4005 | i::Execution::New(fun, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4006 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4007 | return Utils::ToLocal(scope.CloseAndEscape( |
| 4008 | i::Handle<i::JSObject>::cast(returned))); |
| 4009 | } |
| 4010 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 4011 | i::Handle<i::Object> delegate = i::Execution::TryGetConstructorDelegate( |
| 4012 | isolate, obj, &has_pending_exception); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4013 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 4014 | if (!delegate->IsUndefined()) { |
| 4015 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(delegate); |
| 4016 | EXCEPTION_PREAMBLE(isolate); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 4017 | i::Handle<i::Object> returned = i::Execution::Call( |
| 4018 | isolate, fun, obj, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4019 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4020 | ASSERT(!delegate->IsUndefined()); |
| 4021 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 4022 | } |
| 4023 | return Local<v8::Object>(); |
| 4024 | } |
| 4025 | |
| 4026 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 4027 | Local<Function> Function::New(Isolate* v8_isolate, |
| 4028 | FunctionCallback callback, |
| 4029 | Local<Value> data, |
| 4030 | int length) { |
| 4031 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 4032 | LOG_API(isolate, "Function::New"); |
| 4033 | ENTER_V8(isolate); |
| 4034 | return FunctionTemplateNew( |
| 4035 | isolate, callback, data, Local<Signature>(), length, true)-> |
| 4036 | GetFunction(); |
| 4037 | } |
| 4038 | |
| 4039 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4040 | Local<v8::Object> Function::NewInstance() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4041 | return NewInstance(0, NULL); |
| 4042 | } |
| 4043 | |
| 4044 | |
| 4045 | Local<v8::Object> Function::NewInstance(int argc, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4046 | v8::Handle<v8::Value> argv[]) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4047 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4048 | ON_BAILOUT(isolate, "v8::Function::NewInstance()", |
| 4049 | return Local<v8::Object>()); |
| 4050 | LOG_API(isolate, "Function::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4051 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4052 | i::Logger::TimerEventScope timer_scope( |
| 4053 | isolate, i::Logger::TimerEventScope::v8_execute); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4054 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4055 | i::Handle<i::JSFunction> function = Utils::OpenHandle(this); |
| 4056 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 4057 | 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] | 4058 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4059 | i::Handle<i::Object> returned = |
| 4060 | i::Execution::New(function, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4061 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4062 | return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned))); |
| 4063 | } |
| 4064 | |
| 4065 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4066 | Local<v8::Value> Function::Call(v8::Handle<v8::Value> recv, int argc, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4067 | v8::Handle<v8::Value> argv[]) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4068 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4069 | ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>()); |
| 4070 | LOG_API(isolate, "Function::Call"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4071 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4072 | i::Logger::TimerEventScope timer_scope( |
| 4073 | isolate, i::Logger::TimerEventScope::v8_execute); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4074 | i::Object* raw_result = NULL; |
| 4075 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4076 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4077 | i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); |
| 4078 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 4079 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 4080 | 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] | 4081 | EXCEPTION_PREAMBLE(isolate); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 4082 | i::Handle<i::Object> returned = i::Execution::Call( |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4083 | isolate, fun, recv_obj, argc, args, &has_pending_exception, true); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4084 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4085 | raw_result = *returned; |
| 4086 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 4087 | i::Handle<i::Object> result(raw_result, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4088 | return Utils::ToLocal(result); |
| 4089 | } |
| 4090 | |
| 4091 | |
| 4092 | void Function::SetName(v8::Handle<v8::String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4093 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 4094 | ENTER_V8(isolate); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4095 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4096 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4097 | func->shared()->set_name(*Utils::OpenHandle(*name)); |
| 4098 | } |
| 4099 | |
| 4100 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4101 | Handle<Value> Function::GetName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4102 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 4103 | return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(), |
| 4104 | func->GetIsolate())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 4108 | Handle<Value> Function::GetInferredName() const { |
| 4109 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 4110 | return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(), |
| 4111 | func->GetIsolate())); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 4112 | } |
| 4113 | |
| 4114 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4115 | ScriptOrigin Function::GetScriptOrigin() const { |
| 4116 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4117 | if (func->shared()->script()->IsScript()) { |
| 4118 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4119 | i::Handle<i::Object> scriptName = GetScriptNameOrSourceURL(script); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4120 | v8::ScriptOrigin origin( |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4121 | Utils::ToLocal(scriptName), |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4122 | v8::Integer::New(script->line_offset()->value()), |
| 4123 | v8::Integer::New(script->column_offset()->value())); |
| 4124 | return origin; |
| 4125 | } |
| 4126 | return v8::ScriptOrigin(Handle<Value>()); |
| 4127 | } |
| 4128 | |
| 4129 | |
| 4130 | const int Function::kLineOffsetNotFound = -1; |
| 4131 | |
| 4132 | |
| 4133 | int Function::GetScriptLineNumber() const { |
| 4134 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4135 | if (func->shared()->script()->IsScript()) { |
| 4136 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 4137 | return i::GetScriptLineNumber(script, func->shared()->start_position()); |
| 4138 | } |
| 4139 | return kLineOffsetNotFound; |
| 4140 | } |
| 4141 | |
| 4142 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4143 | int Function::GetScriptColumnNumber() const { |
| 4144 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4145 | if (func->shared()->script()->IsScript()) { |
| 4146 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 4147 | return i::GetScriptColumnNumber(script, func->shared()->start_position()); |
| 4148 | } |
| 4149 | return kLineOffsetNotFound; |
| 4150 | } |
| 4151 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4152 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4153 | Handle<Value> Function::GetScriptId() const { |
| 4154 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 4155 | i::Isolate* isolate = func->GetIsolate(); |
| 4156 | if (!func->shared()->script()->IsScript()) { |
| 4157 | return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 4158 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4159 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 4160 | return Utils::ToLocal(i::Handle<i::Object>(script->id(), isolate)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4161 | } |
| 4162 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4163 | |
| 4164 | int Function::ScriptId() const { |
| 4165 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4166 | if (!func->shared()->script()->IsScript()) return v8::Script::kNoScriptId; |
| 4167 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 4168 | return script->id()->value(); |
| 4169 | } |
| 4170 | |
| 4171 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4172 | int String::Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4173 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4174 | return str->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4175 | } |
| 4176 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 4177 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4178 | bool String::IsOneByte() const { |
| 4179 | i::Handle<i::String> str = Utils::OpenHandle(this); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4180 | return str->HasOnlyOneByteChars(); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4181 | } |
| 4182 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 4183 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 4184 | // Helpers for ContainsOnlyOneByteHelper |
| 4185 | template<size_t size> struct OneByteMask; |
| 4186 | template<> struct OneByteMask<4> { |
| 4187 | static const uint32_t value = 0xFF00FF00; |
| 4188 | }; |
| 4189 | template<> struct OneByteMask<8> { |
| 4190 | static const uint64_t value = V8_2PART_UINT64_C(0xFF00FF00, FF00FF00); |
| 4191 | }; |
| 4192 | static const uintptr_t kOneByteMask = OneByteMask<sizeof(uintptr_t)>::value; |
| 4193 | static const uintptr_t kAlignmentMask = sizeof(uintptr_t) - 1; |
| 4194 | static inline bool Unaligned(const uint16_t* chars) { |
| 4195 | return reinterpret_cast<const uintptr_t>(chars) & kAlignmentMask; |
| 4196 | } |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 4197 | |
| 4198 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 4199 | static inline const uint16_t* Align(const uint16_t* chars) { |
| 4200 | return reinterpret_cast<uint16_t*>( |
| 4201 | reinterpret_cast<uintptr_t>(chars) & ~kAlignmentMask); |
| 4202 | } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4203 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4204 | class ContainsOnlyOneByteHelper { |
| 4205 | public: |
| 4206 | ContainsOnlyOneByteHelper() : is_one_byte_(true) {} |
| 4207 | bool Check(i::String* string) { |
| 4208 | i::ConsString* cons_string = i::String::VisitFlat(this, string, 0); |
| 4209 | if (cons_string == NULL) return is_one_byte_; |
| 4210 | return CheckCons(cons_string); |
| 4211 | } |
| 4212 | void VisitOneByteString(const uint8_t* chars, int length) { |
| 4213 | // Nothing to do. |
| 4214 | } |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4215 | void VisitTwoByteString(const uint16_t* chars, int length) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 4216 | // Accumulated bits. |
| 4217 | uintptr_t acc = 0; |
| 4218 | // Align to uintptr_t. |
| 4219 | const uint16_t* end = chars + length; |
| 4220 | while (Unaligned(chars) && chars != end) { |
| 4221 | acc |= *chars++; |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4222 | } |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 4223 | // Read word aligned in blocks, |
| 4224 | // checking the return value at the end of each block. |
| 4225 | const uint16_t* aligned_end = Align(end); |
| 4226 | const int increment = sizeof(uintptr_t)/sizeof(uint16_t); |
| 4227 | const int inner_loops = 16; |
| 4228 | while (chars + inner_loops*increment < aligned_end) { |
| 4229 | for (int i = 0; i < inner_loops; i++) { |
| 4230 | acc |= *reinterpret_cast<const uintptr_t*>(chars); |
| 4231 | chars += increment; |
| 4232 | } |
| 4233 | // Check for early return. |
| 4234 | if ((acc & kOneByteMask) != 0) { |
| 4235 | is_one_byte_ = false; |
| 4236 | return; |
| 4237 | } |
| 4238 | } |
| 4239 | // Read the rest. |
| 4240 | while (chars != end) { |
| 4241 | acc |= *chars++; |
| 4242 | } |
| 4243 | // Check result. |
| 4244 | if ((acc & kOneByteMask) != 0) is_one_byte_ = false; |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4245 | } |
| 4246 | |
| 4247 | private: |
| 4248 | bool CheckCons(i::ConsString* cons_string) { |
| 4249 | while (true) { |
| 4250 | // Check left side if flat. |
| 4251 | i::String* left = cons_string->first(); |
| 4252 | i::ConsString* left_as_cons = |
| 4253 | i::String::VisitFlat(this, left, 0); |
| 4254 | if (!is_one_byte_) return false; |
| 4255 | // Check right side if flat. |
| 4256 | i::String* right = cons_string->second(); |
| 4257 | i::ConsString* right_as_cons = |
| 4258 | i::String::VisitFlat(this, right, 0); |
| 4259 | if (!is_one_byte_) return false; |
| 4260 | // Standard recurse/iterate trick. |
| 4261 | if (left_as_cons != NULL && right_as_cons != NULL) { |
| 4262 | if (left->length() < right->length()) { |
| 4263 | CheckCons(left_as_cons); |
| 4264 | cons_string = right_as_cons; |
| 4265 | } else { |
| 4266 | CheckCons(right_as_cons); |
| 4267 | cons_string = left_as_cons; |
| 4268 | } |
| 4269 | // Check fast return. |
| 4270 | if (!is_one_byte_) return false; |
| 4271 | continue; |
| 4272 | } |
| 4273 | // Descend left in place. |
| 4274 | if (left_as_cons != NULL) { |
| 4275 | cons_string = left_as_cons; |
| 4276 | continue; |
| 4277 | } |
| 4278 | // Descend right in place. |
| 4279 | if (right_as_cons != NULL) { |
| 4280 | cons_string = right_as_cons; |
| 4281 | continue; |
| 4282 | } |
| 4283 | // Terminate. |
| 4284 | break; |
| 4285 | } |
| 4286 | return is_one_byte_; |
| 4287 | } |
| 4288 | bool is_one_byte_; |
| 4289 | DISALLOW_COPY_AND_ASSIGN(ContainsOnlyOneByteHelper); |
| 4290 | }; |
| 4291 | |
| 4292 | |
| 4293 | bool String::ContainsOnlyOneByte() const { |
| 4294 | i::Handle<i::String> str = Utils::OpenHandle(this); |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4295 | if (str->HasOnlyOneByteChars()) return true; |
| 4296 | ContainsOnlyOneByteHelper helper; |
| 4297 | return helper.Check(*str); |
| 4298 | } |
| 4299 | |
| 4300 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4301 | class Utf8LengthHelper : public i::AllStatic { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4302 | public: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4303 | enum State { |
| 4304 | kEndsWithLeadingSurrogate = 1 << 0, |
| 4305 | kStartsWithTrailingSurrogate = 1 << 1, |
| 4306 | kLeftmostEdgeIsCalculated = 1 << 2, |
| 4307 | kRightmostEdgeIsCalculated = 1 << 3, |
| 4308 | kLeftmostEdgeIsSurrogate = 1 << 4, |
| 4309 | kRightmostEdgeIsSurrogate = 1 << 5 |
| 4310 | }; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4311 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4312 | static const uint8_t kInitialState = 0; |
| 4313 | |
| 4314 | static inline bool EndsWithSurrogate(uint8_t state) { |
| 4315 | return state & kEndsWithLeadingSurrogate; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4316 | } |
| 4317 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4318 | static inline bool StartsWithSurrogate(uint8_t state) { |
| 4319 | return state & kStartsWithTrailingSurrogate; |
| 4320 | } |
| 4321 | |
| 4322 | class Visitor { |
| 4323 | public: |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4324 | inline explicit Visitor() |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4325 | : utf8_length_(0), |
| 4326 | state_(kInitialState) {} |
| 4327 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4328 | void VisitOneByteString(const uint8_t* chars, int length) { |
| 4329 | int utf8_length = 0; |
| 4330 | // Add in length 1 for each non-ASCII character. |
| 4331 | for (int i = 0; i < length; i++) { |
| 4332 | utf8_length += *chars++ >> 7; |
| 4333 | } |
| 4334 | // Add in length 1 for each character. |
| 4335 | utf8_length_ = utf8_length + length; |
| 4336 | state_ = kInitialState; |
| 4337 | } |
| 4338 | |
| 4339 | void VisitTwoByteString(const uint16_t* chars, int length) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4340 | int utf8_length = 0; |
| 4341 | int last_character = unibrow::Utf16::kNoPreviousCharacter; |
| 4342 | for (int i = 0; i < length; i++) { |
| 4343 | uint16_t c = chars[i]; |
| 4344 | utf8_length += unibrow::Utf8::Length(c, last_character); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4345 | last_character = c; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4346 | } |
| 4347 | utf8_length_ = utf8_length; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4348 | uint8_t state = 0; |
| 4349 | if (unibrow::Utf16::IsTrailSurrogate(chars[0])) { |
| 4350 | state |= kStartsWithTrailingSurrogate; |
| 4351 | } |
| 4352 | if (unibrow::Utf16::IsLeadSurrogate(chars[length-1])) { |
| 4353 | state |= kEndsWithLeadingSurrogate; |
| 4354 | } |
| 4355 | state_ = state; |
| 4356 | } |
| 4357 | |
| 4358 | static i::ConsString* VisitFlat(i::String* string, |
| 4359 | int* length, |
| 4360 | uint8_t* state) { |
| 4361 | Visitor visitor; |
| 4362 | i::ConsString* cons_string = i::String::VisitFlat(&visitor, string); |
| 4363 | *length = visitor.utf8_length_; |
| 4364 | *state = visitor.state_; |
| 4365 | return cons_string; |
| 4366 | } |
| 4367 | |
| 4368 | private: |
| 4369 | int utf8_length_; |
| 4370 | uint8_t state_; |
| 4371 | DISALLOW_COPY_AND_ASSIGN(Visitor); |
| 4372 | }; |
| 4373 | |
| 4374 | static inline void MergeLeafLeft(int* length, |
| 4375 | uint8_t* state, |
| 4376 | uint8_t leaf_state) { |
| 4377 | bool edge_surrogate = StartsWithSurrogate(leaf_state); |
| 4378 | if (!(*state & kLeftmostEdgeIsCalculated)) { |
| 4379 | ASSERT(!(*state & kLeftmostEdgeIsSurrogate)); |
| 4380 | *state |= kLeftmostEdgeIsCalculated |
| 4381 | | (edge_surrogate ? kLeftmostEdgeIsSurrogate : 0); |
| 4382 | } else if (EndsWithSurrogate(*state) && edge_surrogate) { |
| 4383 | *length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates; |
| 4384 | } |
| 4385 | if (EndsWithSurrogate(leaf_state)) { |
| 4386 | *state |= kEndsWithLeadingSurrogate; |
| 4387 | } else { |
| 4388 | *state &= ~kEndsWithLeadingSurrogate; |
| 4389 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4390 | } |
| 4391 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4392 | static inline void MergeLeafRight(int* length, |
| 4393 | uint8_t* state, |
| 4394 | uint8_t leaf_state) { |
| 4395 | bool edge_surrogate = EndsWithSurrogate(leaf_state); |
| 4396 | if (!(*state & kRightmostEdgeIsCalculated)) { |
| 4397 | ASSERT(!(*state & kRightmostEdgeIsSurrogate)); |
| 4398 | *state |= (kRightmostEdgeIsCalculated |
| 4399 | | (edge_surrogate ? kRightmostEdgeIsSurrogate : 0)); |
| 4400 | } else if (edge_surrogate && StartsWithSurrogate(*state)) { |
| 4401 | *length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates; |
| 4402 | } |
| 4403 | if (StartsWithSurrogate(leaf_state)) { |
| 4404 | *state |= kStartsWithTrailingSurrogate; |
| 4405 | } else { |
| 4406 | *state &= ~kStartsWithTrailingSurrogate; |
| 4407 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4408 | } |
| 4409 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4410 | static inline void MergeTerminal(int* length, |
| 4411 | uint8_t state, |
| 4412 | uint8_t* state_out) { |
| 4413 | ASSERT((state & kLeftmostEdgeIsCalculated) && |
| 4414 | (state & kRightmostEdgeIsCalculated)); |
| 4415 | if (EndsWithSurrogate(state) && StartsWithSurrogate(state)) { |
| 4416 | *length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates; |
| 4417 | } |
| 4418 | *state_out = kInitialState | |
| 4419 | (state & kLeftmostEdgeIsSurrogate ? kStartsWithTrailingSurrogate : 0) | |
| 4420 | (state & kRightmostEdgeIsSurrogate ? kEndsWithLeadingSurrogate : 0); |
| 4421 | } |
| 4422 | |
| 4423 | static int Calculate(i::ConsString* current, uint8_t* state_out) { |
| 4424 | using namespace internal; |
| 4425 | int total_length = 0; |
| 4426 | uint8_t state = kInitialState; |
| 4427 | while (true) { |
| 4428 | i::String* left = current->first(); |
| 4429 | i::String* right = current->second(); |
| 4430 | uint8_t right_leaf_state; |
| 4431 | uint8_t left_leaf_state; |
| 4432 | int leaf_length; |
| 4433 | ConsString* left_as_cons = |
| 4434 | Visitor::VisitFlat(left, &leaf_length, &left_leaf_state); |
| 4435 | if (left_as_cons == NULL) { |
| 4436 | total_length += leaf_length; |
| 4437 | MergeLeafLeft(&total_length, &state, left_leaf_state); |
| 4438 | } |
| 4439 | ConsString* right_as_cons = |
| 4440 | Visitor::VisitFlat(right, &leaf_length, &right_leaf_state); |
| 4441 | if (right_as_cons == NULL) { |
| 4442 | total_length += leaf_length; |
| 4443 | MergeLeafRight(&total_length, &state, right_leaf_state); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4444 | if (left_as_cons != NULL) { |
| 4445 | // 1 Leaf node. Descend in place. |
| 4446 | current = left_as_cons; |
| 4447 | continue; |
| 4448 | } else { |
| 4449 | // Terminal node. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4450 | MergeTerminal(&total_length, state, state_out); |
| 4451 | return total_length; |
| 4452 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4453 | } else if (left_as_cons == NULL) { |
| 4454 | // 1 Leaf node. Descend in place. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4455 | current = right_as_cons; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4456 | continue; |
| 4457 | } |
| 4458 | // Both strings are ConsStrings. |
| 4459 | // Recurse on smallest. |
| 4460 | if (left->length() < right->length()) { |
| 4461 | total_length += Calculate(left_as_cons, &left_leaf_state); |
| 4462 | MergeLeafLeft(&total_length, &state, left_leaf_state); |
| 4463 | current = right_as_cons; |
| 4464 | } else { |
| 4465 | total_length += Calculate(right_as_cons, &right_leaf_state); |
| 4466 | MergeLeafRight(&total_length, &state, right_leaf_state); |
| 4467 | current = left_as_cons; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4468 | } |
| 4469 | } |
| 4470 | UNREACHABLE(); |
| 4471 | return 0; |
| 4472 | } |
| 4473 | |
| 4474 | static inline int Calculate(i::ConsString* current) { |
| 4475 | uint8_t state = kInitialState; |
| 4476 | return Calculate(current, &state); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | private: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4480 | DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8LengthHelper); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4481 | }; |
| 4482 | |
| 4483 | |
| 4484 | static int Utf8Length(i::String* str, i::Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4485 | int length = str->length(); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4486 | if (length == 0) return 0; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4487 | uint8_t state; |
| 4488 | i::ConsString* cons_string = |
| 4489 | Utf8LengthHelper::Visitor::VisitFlat(str, &length, &state); |
| 4490 | if (cons_string == NULL) return length; |
| 4491 | return Utf8LengthHelper::Calculate(cons_string); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | |
| 4495 | int String::Utf8Length() const { |
| 4496 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 4497 | i::Isolate* isolate = str->GetIsolate(); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4498 | return v8::Utf8Length(*str, isolate); |
| 4499 | } |
| 4500 | |
| 4501 | |
| 4502 | class Utf8WriterVisitor { |
| 4503 | public: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4504 | Utf8WriterVisitor( |
| 4505 | char* buffer, int capacity, bool skip_capacity_check) |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4506 | : early_termination_(false), |
| 4507 | last_character_(unibrow::Utf16::kNoPreviousCharacter), |
| 4508 | buffer_(buffer), |
| 4509 | start_(buffer), |
| 4510 | capacity_(capacity), |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4511 | skip_capacity_check_(capacity == -1 || skip_capacity_check), |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4512 | utf16_chars_read_(0) { |
| 4513 | } |
| 4514 | |
| 4515 | static int WriteEndCharacter(uint16_t character, |
| 4516 | int last_character, |
| 4517 | int remaining, |
| 4518 | char* const buffer) { |
| 4519 | using namespace unibrow; |
| 4520 | ASSERT(remaining > 0); |
| 4521 | // We can't use a local buffer here because Encode needs to modify |
| 4522 | // previous characters in the stream. We know, however, that |
| 4523 | // exactly one character will be advanced. |
| 4524 | if (Utf16::IsTrailSurrogate(character) && |
| 4525 | Utf16::IsLeadSurrogate(last_character)) { |
| 4526 | int written = Utf8::Encode(buffer, character, last_character); |
| 4527 | ASSERT(written == 1); |
| 4528 | return written; |
| 4529 | } |
| 4530 | // Use a scratch buffer to check the required characters. |
| 4531 | char temp_buffer[Utf8::kMaxEncodedSize]; |
| 4532 | // Can't encode using last_character as gcc has array bounds issues. |
| 4533 | int written = Utf8::Encode(temp_buffer, |
| 4534 | character, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4535 | Utf16::kNoPreviousCharacter); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4536 | // Won't fit. |
| 4537 | if (written > remaining) return 0; |
| 4538 | // Copy over the character from temp_buffer. |
| 4539 | for (int j = 0; j < written; j++) { |
| 4540 | buffer[j] = temp_buffer[j]; |
| 4541 | } |
| 4542 | return written; |
| 4543 | } |
| 4544 | |
| 4545 | template<typename Char> |
| 4546 | void Visit(const Char* chars, const int length) { |
| 4547 | using namespace unibrow; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4548 | ASSERT(!early_termination_); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4549 | if (length == 0) return; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4550 | // Copy state to stack. |
| 4551 | char* buffer = buffer_; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4552 | int last_character = |
| 4553 | sizeof(Char) == 1 ? Utf16::kNoPreviousCharacter : last_character_; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4554 | int i = 0; |
| 4555 | // Do a fast loop where there is no exit capacity check. |
| 4556 | while (true) { |
| 4557 | int fast_length; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4558 | if (skip_capacity_check_) { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4559 | fast_length = length; |
| 4560 | } else { |
| 4561 | int remaining_capacity = capacity_ - static_cast<int>(buffer - start_); |
| 4562 | // Need enough space to write everything but one character. |
| 4563 | STATIC_ASSERT(Utf16::kMaxExtraUtf8BytesForOneUtf16CodeUnit == 3); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4564 | int max_size_per_char = sizeof(Char) == 1 ? 2 : 3; |
| 4565 | int writable_length = |
| 4566 | (remaining_capacity - max_size_per_char)/max_size_per_char; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4567 | // Need to drop into slow loop. |
| 4568 | if (writable_length <= 0) break; |
| 4569 | fast_length = i + writable_length; |
| 4570 | if (fast_length > length) fast_length = length; |
| 4571 | } |
| 4572 | // Write the characters to the stream. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4573 | if (sizeof(Char) == 1) { |
| 4574 | for (; i < fast_length; i++) { |
| 4575 | buffer += |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4576 | Utf8::EncodeOneByte(buffer, static_cast<uint8_t>(*chars++)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4577 | ASSERT(capacity_ == -1 || (buffer - start_) <= capacity_); |
| 4578 | } |
| 4579 | } else { |
| 4580 | for (; i < fast_length; i++) { |
| 4581 | uint16_t character = *chars++; |
| 4582 | buffer += Utf8::Encode(buffer, character, last_character); |
| 4583 | last_character = character; |
| 4584 | ASSERT(capacity_ == -1 || (buffer - start_) <= capacity_); |
| 4585 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4586 | } |
| 4587 | // Array is fully written. Exit. |
| 4588 | if (fast_length == length) { |
| 4589 | // Write state back out to object. |
| 4590 | last_character_ = last_character; |
| 4591 | buffer_ = buffer; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4592 | utf16_chars_read_ += length; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4593 | return; |
| 4594 | } |
| 4595 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4596 | ASSERT(!skip_capacity_check_); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4597 | // Slow loop. Must check capacity on each iteration. |
| 4598 | int remaining_capacity = capacity_ - static_cast<int>(buffer - start_); |
| 4599 | ASSERT(remaining_capacity >= 0); |
| 4600 | for (; i < length && remaining_capacity > 0; i++) { |
| 4601 | uint16_t character = *chars++; |
| 4602 | int written = WriteEndCharacter(character, |
| 4603 | last_character, |
| 4604 | remaining_capacity, |
| 4605 | buffer); |
| 4606 | if (written == 0) { |
| 4607 | early_termination_ = true; |
| 4608 | break; |
| 4609 | } |
| 4610 | buffer += written; |
| 4611 | remaining_capacity -= written; |
| 4612 | last_character = character; |
| 4613 | } |
| 4614 | // Write state back out to object. |
| 4615 | last_character_ = last_character; |
| 4616 | buffer_ = buffer; |
| 4617 | utf16_chars_read_ += i; |
| 4618 | } |
| 4619 | |
| 4620 | inline bool IsDone() { |
| 4621 | return early_termination_; |
| 4622 | } |
| 4623 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4624 | inline void VisitOneByteString(const uint8_t* chars, int length) { |
| 4625 | Visit(chars, length); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4626 | } |
| 4627 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4628 | inline void VisitTwoByteString(const uint16_t* chars, int length) { |
| 4629 | Visit(chars, length); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4630 | } |
| 4631 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4632 | int CompleteWrite(bool write_null, int* utf16_chars_read_out) { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4633 | // Write out number of utf16 characters written to the stream. |
| 4634 | if (utf16_chars_read_out != NULL) { |
| 4635 | *utf16_chars_read_out = utf16_chars_read_; |
| 4636 | } |
| 4637 | // Only null terminate if all of the string was written and there's space. |
| 4638 | if (write_null && |
| 4639 | !early_termination_ && |
| 4640 | (capacity_ == -1 || (buffer_ - start_) < capacity_)) { |
| 4641 | *buffer_++ = '\0'; |
| 4642 | } |
| 4643 | return static_cast<int>(buffer_ - start_); |
| 4644 | } |
| 4645 | |
| 4646 | private: |
| 4647 | bool early_termination_; |
| 4648 | int last_character_; |
| 4649 | char* buffer_; |
| 4650 | char* const start_; |
| 4651 | int capacity_; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4652 | bool const skip_capacity_check_; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4653 | int utf16_chars_read_; |
| 4654 | DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8WriterVisitor); |
| 4655 | }; |
| 4656 | |
| 4657 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4658 | static bool RecursivelySerializeToUtf8(i::String* current, |
| 4659 | Utf8WriterVisitor* writer, |
| 4660 | int recursion_budget) { |
| 4661 | while (!writer->IsDone()) { |
| 4662 | i::ConsString* cons_string = i::String::VisitFlat(writer, current); |
| 4663 | if (cons_string == NULL) return true; // Leaf node. |
| 4664 | if (recursion_budget <= 0) return false; |
| 4665 | // Must write the left branch first. |
| 4666 | i::String* first = cons_string->first(); |
| 4667 | bool success = RecursivelySerializeToUtf8(first, |
| 4668 | writer, |
| 4669 | recursion_budget - 1); |
| 4670 | if (!success) return false; |
| 4671 | // Inline tail recurse for right branch. |
| 4672 | current = cons_string->second(); |
| 4673 | } |
| 4674 | return true; |
| 4675 | } |
| 4676 | |
| 4677 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 4678 | int String::WriteUtf8(char* buffer, |
| 4679 | int capacity, |
| 4680 | int* nchars_ref, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4681 | int options) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4682 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4683 | LOG_API(isolate, "String::WriteUtf8"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4684 | ENTER_V8(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4685 | i::Handle<i::String> str = Utils::OpenHandle(this); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4686 | if (options & HINT_MANY_WRITES_EXPECTED) { |
| 4687 | FlattenString(str); // Flatten the string for efficiency. |
| 4688 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4689 | const int string_length = str->length(); |
| 4690 | bool write_null = !(options & NO_NULL_TERMINATION); |
| 4691 | // First check if we can just write the string without checking capacity. |
| 4692 | if (capacity == -1 || capacity / 3 >= string_length) { |
| 4693 | Utf8WriterVisitor writer(buffer, capacity, true); |
| 4694 | const int kMaxRecursion = 100; |
| 4695 | bool success = RecursivelySerializeToUtf8(*str, &writer, kMaxRecursion); |
| 4696 | if (success) return writer.CompleteWrite(write_null, nchars_ref); |
| 4697 | } else if (capacity >= string_length) { |
| 4698 | // First check that the buffer is large enough. |
| 4699 | int utf8_bytes = v8::Utf8Length(*str, str->GetIsolate()); |
| 4700 | if (utf8_bytes <= capacity) { |
| 4701 | // ASCII fast path. |
| 4702 | if (utf8_bytes == string_length) { |
| 4703 | WriteOneByte(reinterpret_cast<uint8_t*>(buffer), 0, capacity, options); |
| 4704 | if (nchars_ref != NULL) *nchars_ref = string_length; |
| 4705 | if (write_null && (utf8_bytes+1 <= capacity)) { |
| 4706 | return string_length + 1; |
| 4707 | } |
| 4708 | return string_length; |
| 4709 | } |
| 4710 | if (write_null && (utf8_bytes+1 > capacity)) { |
| 4711 | options |= NO_NULL_TERMINATION; |
| 4712 | } |
| 4713 | // Recurse once without a capacity limit. |
| 4714 | // This will get into the first branch above. |
| 4715 | // TODO(dcarney) Check max left rec. in Utf8Length and fall through. |
| 4716 | return WriteUtf8(buffer, -1, nchars_ref, options); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4717 | } |
| 4718 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4719 | // Recursive slow path can potentially be unreasonable slow. Flatten. |
| 4720 | str = FlattenGetString(str); |
| 4721 | Utf8WriterVisitor writer(buffer, capacity, false); |
| 4722 | i::String::VisitFlat(&writer, *str); |
| 4723 | return writer.CompleteWrite(write_null, nchars_ref); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
| 4726 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4727 | template<typename CharType> |
| 4728 | static inline int WriteHelper(const String* string, |
| 4729 | CharType* buffer, |
| 4730 | int start, |
| 4731 | int length, |
| 4732 | int options) { |
| 4733 | i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate(); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4734 | LOG_API(isolate, "String::Write"); |
| 4735 | ENTER_V8(isolate); |
| 4736 | ASSERT(start >= 0 && length >= -1); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4737 | i::Handle<i::String> str = Utils::OpenHandle(string); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4738 | isolate->string_tracker()->RecordWrite(str); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4739 | if (options & String::HINT_MANY_WRITES_EXPECTED) { |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4740 | // Flatten the string for efficiency. This applies whether we are |
| 4741 | // using StringCharacterStream or Get(i) to access the characters. |
| 4742 | FlattenString(str); |
| 4743 | } |
| 4744 | int end = start + length; |
| 4745 | if ((length == -1) || (length > str->length() - start) ) |
| 4746 | end = str->length(); |
| 4747 | if (end < 0) return 0; |
| 4748 | i::String::WriteToFlat(*str, buffer, start, end); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4749 | if (!(options & String::NO_NULL_TERMINATION) && |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4750 | (length == -1 || end - start < length)) { |
| 4751 | buffer[end - start] = '\0'; |
| 4752 | } |
| 4753 | return end - start; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4754 | } |
| 4755 | |
| 4756 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4757 | int String::WriteOneByte(uint8_t* buffer, |
| 4758 | int start, |
| 4759 | int length, |
| 4760 | int options) const { |
| 4761 | return WriteHelper(this, buffer, start, length, options); |
| 4762 | } |
| 4763 | |
| 4764 | |
| 4765 | int String::Write(uint16_t* buffer, |
| 4766 | int start, |
| 4767 | int length, |
| 4768 | int options) const { |
| 4769 | return WriteHelper(this, buffer, start, length, options); |
| 4770 | } |
| 4771 | |
| 4772 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4773 | bool v8::String::IsExternal() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4774 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4775 | EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4776 | return i::StringShape(*str).IsExternalTwoByte(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4780 | bool v8::String::IsExternalAscii() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4781 | i::Handle<i::String> str = Utils::OpenHandle(this); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4782 | return i::StringShape(*str).IsExternalAscii(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4786 | void v8::String::VerifyExternalStringResource( |
| 4787 | v8::String::ExternalStringResource* value) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4788 | i::Handle<i::String> str = Utils::OpenHandle(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4789 | const v8::String::ExternalStringResource* expected; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4790 | if (i::StringShape(*str).IsExternalTwoByte()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4791 | const void* resource = |
| 4792 | i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
| 4793 | expected = reinterpret_cast<const ExternalStringResource*>(resource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4794 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4795 | expected = NULL; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4796 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4797 | CHECK_EQ(expected, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4798 | } |
| 4799 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4800 | void v8::String::VerifyExternalStringResourceBase( |
| 4801 | v8::String::ExternalStringResourceBase* value, Encoding encoding) const { |
| 4802 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 4803 | const v8::String::ExternalStringResourceBase* expected; |
| 4804 | Encoding expectedEncoding; |
| 4805 | if (i::StringShape(*str).IsExternalAscii()) { |
| 4806 | const void* resource = |
| 4807 | i::Handle<i::ExternalAsciiString>::cast(str)->resource(); |
| 4808 | expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); |
| 4809 | expectedEncoding = ASCII_ENCODING; |
| 4810 | } else if (i::StringShape(*str).IsExternalTwoByte()) { |
| 4811 | const void* resource = |
| 4812 | i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
| 4813 | expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); |
| 4814 | expectedEncoding = TWO_BYTE_ENCODING; |
| 4815 | } else { |
| 4816 | expected = NULL; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 4817 | expectedEncoding = str->IsOneByteRepresentation() ? ASCII_ENCODING |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4818 | : TWO_BYTE_ENCODING; |
| 4819 | } |
| 4820 | CHECK_EQ(expected, value); |
| 4821 | CHECK_EQ(expectedEncoding, encoding); |
| 4822 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4823 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4824 | const v8::String::ExternalAsciiStringResource* |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4825 | v8::String::GetExternalAsciiStringResource() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4826 | i::Handle<i::String> str = Utils::OpenHandle(this); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4827 | if (i::StringShape(*str).IsExternalAscii()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4828 | const void* resource = |
| 4829 | i::Handle<i::ExternalAsciiString>::cast(str)->resource(); |
| 4830 | return reinterpret_cast<const ExternalAsciiStringResource*>(resource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4831 | } else { |
| 4832 | return NULL; |
| 4833 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4837 | Local<Value> Symbol::Name() const { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4838 | i::Handle<i::Symbol> sym = Utils::OpenHandle(this); |
| 4839 | i::Handle<i::Object> name(sym->name(), sym->GetIsolate()); |
| 4840 | return Utils::ToLocal(name); |
| 4841 | } |
| 4842 | |
| 4843 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4844 | double Number::Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4845 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4846 | return obj->Number(); |
| 4847 | } |
| 4848 | |
| 4849 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4850 | bool Boolean::Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4851 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4852 | return obj->IsTrue(); |
| 4853 | } |
| 4854 | |
| 4855 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4856 | int64_t Integer::Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4857 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4858 | if (obj->IsSmi()) { |
| 4859 | return i::Smi::cast(*obj)->value(); |
| 4860 | } else { |
| 4861 | return static_cast<int64_t>(obj->Number()); |
| 4862 | } |
| 4863 | } |
| 4864 | |
| 4865 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4866 | int32_t Int32::Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4867 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4868 | if (obj->IsSmi()) { |
| 4869 | return i::Smi::cast(*obj)->value(); |
| 4870 | } else { |
| 4871 | return static_cast<int32_t>(obj->Number()); |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4876 | uint32_t Uint32::Value() const { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4877 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4878 | if (obj->IsSmi()) { |
| 4879 | return i::Smi::cast(*obj)->value(); |
| 4880 | } else { |
| 4881 | return static_cast<uint32_t>(obj->Number()); |
| 4882 | } |
| 4883 | } |
| 4884 | |
| 4885 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4886 | int v8::Object::InternalFieldCount() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4887 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4888 | return obj->GetInternalFieldCount(); |
| 4889 | } |
| 4890 | |
| 4891 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4892 | static bool InternalFieldOK(i::Handle<i::JSObject> obj, |
| 4893 | int index, |
| 4894 | const char* location) { |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 4895 | return ApiCheck(index < obj->GetInternalFieldCount(), |
| 4896 | location, |
| 4897 | "Internal field out of bounds"); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | |
| 4901 | Local<Value> v8::Object::SlowGetInternalField(int index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4902 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4903 | const char* location = "v8::Object::GetInternalField()"; |
| 4904 | if (!InternalFieldOK(obj, index, location)) return Local<Value>(); |
| 4905 | i::Handle<i::Object> value(obj->GetInternalField(index), obj->GetIsolate()); |
| 4906 | return Utils::ToLocal(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4907 | } |
| 4908 | |
| 4909 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 4910 | void v8::Object::SetInternalField(int index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4911 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4912 | const char* location = "v8::Object::SetInternalField()"; |
| 4913 | if (!InternalFieldOK(obj, index, location)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4914 | i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 4915 | obj->SetInternalField(index, *val); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4916 | ASSERT_EQ(value, GetInternalField(index)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4917 | } |
| 4918 | |
| 4919 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4920 | void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) { |
| 4921 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4922 | const char* location = "v8::Object::GetAlignedPointerFromInternalField()"; |
| 4923 | if (!InternalFieldOK(obj, index, location)) return NULL; |
| 4924 | return DecodeSmiToAligned(obj->GetInternalField(index), location); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4928 | void v8::Object::SetAlignedPointerInInternalField(int index, void* value) { |
| 4929 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4930 | const char* location = "v8::Object::SetAlignedPointerInInternalField()"; |
| 4931 | if (!InternalFieldOK(obj, index, location)) return; |
| 4932 | obj->SetInternalField(index, EncodeAlignedAsSmi(value, location)); |
| 4933 | ASSERT_EQ(value, GetAlignedPointerFromInternalField(index)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4937 | static void* ExternalValue(i::Object* obj) { |
| 4938 | // Obscure semantics for undefined, but somehow checked in our unit tests... |
| 4939 | if (obj->IsUndefined()) return NULL; |
| 4940 | i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0); |
| 4941 | return i::Foreign::cast(foreign)->foreign_address(); |
| 4942 | } |
| 4943 | |
| 4944 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4945 | // --- E n v i r o n m e n t --- |
| 4946 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4947 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4948 | bool v8::V8::Initialize() { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 4949 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4950 | if (isolate != NULL && isolate->IsInitialized()) { |
| 4951 | return true; |
| 4952 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4953 | return InitializeHelper(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4957 | void v8::V8::SetEntropySource(EntropySource entropy_source) { |
| 4958 | i::RandomNumberGenerator::SetEntropySource(entropy_source); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4962 | void v8::V8::SetReturnAddressLocationResolver( |
| 4963 | ReturnAddressLocationResolver return_address_resolver) { |
| 4964 | i::V8::SetReturnAddressLocationResolver(return_address_resolver); |
| 4965 | } |
| 4966 | |
| 4967 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4968 | bool v8::V8::SetFunctionEntryHook(Isolate* ext_isolate, |
| 4969 | FunctionEntryHook entry_hook) { |
| 4970 | ASSERT(ext_isolate != NULL); |
| 4971 | ASSERT(entry_hook != NULL); |
| 4972 | |
| 4973 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(ext_isolate); |
| 4974 | |
| 4975 | // The entry hook can only be set before the Isolate is initialized, as |
| 4976 | // otherwise the Isolate's code stubs generated at initialization won't |
| 4977 | // contain entry hooks. |
| 4978 | if (isolate->IsInitialized()) |
| 4979 | return false; |
| 4980 | |
| 4981 | // Setting an entry hook is a one-way operation, once set, it cannot be |
| 4982 | // changed or unset. |
| 4983 | if (isolate->function_entry_hook() != NULL) |
| 4984 | return false; |
| 4985 | |
| 4986 | isolate->set_function_entry_hook(entry_hook); |
| 4987 | return true; |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 4991 | void v8::V8::SetJitCodeEventHandler( |
| 4992 | JitCodeEventOptions options, JitCodeEventHandler event_handler) { |
| 4993 | i::Isolate* isolate = i::Isolate::Current(); |
| 4994 | // Ensure that logging is initialized for our isolate. |
| 4995 | isolate->InitializeLoggingAndCounters(); |
| 4996 | isolate->logger()->SetCodeEventHandler(options, event_handler); |
| 4997 | } |
| 4998 | |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 4999 | void v8::V8::SetArrayBufferAllocator( |
| 5000 | ArrayBuffer::Allocator* allocator) { |
| 5001 | if (!ApiCheck(i::V8::ArrayBufferAllocator() == NULL, |
| 5002 | "v8::V8::SetArrayBufferAllocator", |
| 5003 | "ArrayBufferAllocator might only be set once")) |
| 5004 | return; |
| 5005 | i::V8::SetArrayBufferAllocator(allocator); |
| 5006 | } |
| 5007 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5008 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5009 | bool v8::V8::Dispose() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5010 | i::Isolate* isolate = i::Isolate::Current(); |
| 5011 | if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(), |
| 5012 | "v8::V8::Dispose()", |
| 5013 | "Use v8::Isolate::Dispose() for a non-default isolate.")) { |
| 5014 | return false; |
| 5015 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5016 | i::V8::TearDown(); |
| 5017 | return true; |
| 5018 | } |
| 5019 | |
| 5020 | |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 5021 | HeapStatistics::HeapStatistics(): total_heap_size_(0), |
| 5022 | total_heap_size_executable_(0), |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 5023 | total_physical_size_(0), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5024 | used_heap_size_(0), |
| 5025 | heap_size_limit_(0) { } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5026 | |
| 5027 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5028 | void v8::V8::VisitExternalResources(ExternalResourceVisitor* visitor) { |
| 5029 | i::Isolate* isolate = i::Isolate::Current(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5030 | isolate->heap()->VisitExternalResources(visitor); |
| 5031 | } |
| 5032 | |
| 5033 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5034 | class VisitorAdapter : public i::ObjectVisitor { |
| 5035 | public: |
| 5036 | explicit VisitorAdapter(PersistentHandleVisitor* visitor) |
| 5037 | : visitor_(visitor) {} |
| 5038 | virtual void VisitPointers(i::Object** start, i::Object** end) { |
| 5039 | UNREACHABLE(); |
| 5040 | } |
| 5041 | virtual void VisitEmbedderReference(i::Object** p, uint16_t class_id) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5042 | Value* value = ToApi<Value>(i::Handle<i::Object>(p)); |
| 5043 | visitor_->VisitPersistentHandle( |
| 5044 | reinterpret_cast<Persistent<Value>*>(&value), class_id); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5045 | } |
| 5046 | private: |
| 5047 | PersistentHandleVisitor* visitor_; |
| 5048 | }; |
| 5049 | |
| 5050 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5051 | void v8::V8::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) { |
| 5052 | i::Isolate* isolate = i::Isolate::Current(); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 5053 | i::DisallowHeapAllocation no_allocation; |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5054 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5055 | VisitorAdapter visitor_adapter(visitor); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5056 | isolate->global_handles()->IterateAllRootsWithClassIds(&visitor_adapter); |
| 5057 | } |
| 5058 | |
| 5059 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5060 | void v8::V8::VisitHandlesForPartialDependence( |
| 5061 | Isolate* exported_isolate, PersistentHandleVisitor* visitor) { |
| 5062 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exported_isolate); |
| 5063 | ASSERT(isolate == i::Isolate::Current()); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 5064 | i::DisallowHeapAllocation no_allocation; |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5065 | |
| 5066 | VisitorAdapter visitor_adapter(visitor); |
| 5067 | isolate->global_handles()->IterateAllRootsInNewSpaceWithClassIds( |
| 5068 | &visitor_adapter); |
| 5069 | } |
| 5070 | |
| 5071 | |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 5072 | bool v8::V8::IdleNotification(int hint) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5073 | // Returning true tells the caller that it need not |
| 5074 | // continue to call IdleNotification. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5075 | i::Isolate* isolate = i::Isolate::Current(); |
| 5076 | if (isolate == NULL || !isolate->IsInitialized()) return true; |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 5077 | if (!i::FLAG_use_idle_notification) return true; |
| 5078 | return isolate->heap()->IdleNotification(hint); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 5079 | } |
| 5080 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5081 | |
| 5082 | void v8::V8::LowMemoryNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5083 | i::Isolate* isolate = i::Isolate::Current(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5084 | if (isolate == NULL || !isolate->IsInitialized()) return; |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 5085 | isolate->heap()->CollectAllAvailableGarbage("low memory notification"); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5089 | int v8::V8::ContextDisposedNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5090 | i::Isolate* isolate = i::Isolate::Current(); |
| 5091 | if (!isolate->IsInitialized()) return 0; |
| 5092 | return isolate->heap()->NotifyContextDisposed(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5096 | bool v8::V8::InitializeICU() { |
| 5097 | return i::InitializeICU(); |
| 5098 | } |
| 5099 | |
| 5100 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 5101 | const char* v8::V8::GetVersion() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5102 | return i::Version::GetVersion(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5106 | static i::Handle<i::Context> CreateEnvironment( |
| 5107 | i::Isolate* isolate, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5108 | v8::ExtensionConfiguration* extensions, |
| 5109 | v8::Handle<ObjectTemplate> global_template, |
| 5110 | v8::Handle<Value> global_object) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5111 | i::Handle<i::Context> env; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5112 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5113 | // Enter V8 via an ENTER_V8 scope. |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5114 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5115 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5116 | v8::Handle<ObjectTemplate> proxy_template = global_template; |
| 5117 | i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
| 5118 | i::Handle<i::FunctionTemplateInfo> global_constructor; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 5119 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5120 | if (!global_template.IsEmpty()) { |
| 5121 | // Make sure that the global_template has a constructor. |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 5122 | global_constructor = EnsureConstructor(*global_template); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5123 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5124 | // Create a fresh template for the global proxy object. |
| 5125 | proxy_template = ObjectTemplate::New(); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 5126 | proxy_constructor = EnsureConstructor(*proxy_template); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5127 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5128 | // Set the global template to be the prototype template of |
| 5129 | // global proxy template. |
| 5130 | proxy_constructor->set_prototype_template( |
| 5131 | *Utils::OpenHandle(*global_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5132 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5133 | // Migrate security handlers from global_template to |
| 5134 | // proxy_template. Temporarily removing access check |
| 5135 | // information from the global template. |
| 5136 | if (!global_constructor->access_check_info()->IsUndefined()) { |
| 5137 | proxy_constructor->set_access_check_info( |
| 5138 | global_constructor->access_check_info()); |
| 5139 | proxy_constructor->set_needs_access_check( |
| 5140 | global_constructor->needs_access_check()); |
| 5141 | global_constructor->set_needs_access_check(false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5142 | global_constructor->set_access_check_info( |
| 5143 | isolate->heap()->undefined_value()); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5144 | } |
| 5145 | } |
| 5146 | |
| 5147 | // Create the environment. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5148 | env = isolate->bootstrapper()->CreateEnvironment( |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 5149 | Utils::OpenHandle(*global_object, true), |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5150 | proxy_template, |
| 5151 | extensions); |
| 5152 | |
| 5153 | // Restore the access check info on the global template. |
| 5154 | if (!global_template.IsEmpty()) { |
| 5155 | ASSERT(!global_constructor.is_null()); |
| 5156 | ASSERT(!proxy_constructor.is_null()); |
| 5157 | global_constructor->set_access_check_info( |
| 5158 | proxy_constructor->access_check_info()); |
| 5159 | global_constructor->set_needs_access_check( |
| 5160 | proxy_constructor->needs_access_check()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5161 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5162 | isolate->runtime_profiler()->Reset(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5163 | } |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5164 | // Leave V8. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 5165 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5166 | return env; |
| 5167 | } |
| 5168 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5169 | Local<Context> v8::Context::New( |
| 5170 | v8::Isolate* external_isolate, |
| 5171 | v8::ExtensionConfiguration* extensions, |
| 5172 | v8::Handle<ObjectTemplate> global_template, |
| 5173 | v8::Handle<Value> global_object) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5174 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
| 5175 | EnsureInitializedForIsolate(isolate, "v8::Context::New()"); |
| 5176 | LOG_API(isolate, "Context::New"); |
| 5177 | ON_BAILOUT(isolate, "v8::Context::New()", return Local<Context>()); |
| 5178 | i::HandleScope scope(isolate); |
| 5179 | i::Handle<i::Context> env = |
| 5180 | CreateEnvironment(isolate, extensions, global_template, global_object); |
| 5181 | if (env.is_null()) return Local<Context>(); |
| 5182 | return Utils::ToLocal(scope.CloseAndEscape(env)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | |
| 5186 | void v8::Context::SetSecurityToken(Handle<Value> token) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5187 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5188 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5189 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 5190 | i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5191 | env->set_security_token(*token_handle); |
| 5192 | } |
| 5193 | |
| 5194 | |
| 5195 | void v8::Context::UseDefaultSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5196 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5197 | ENTER_V8(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5198 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5199 | env->set_security_token(env->global_object()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | |
| 5203 | Handle<Value> v8::Context::GetSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5204 | i::Isolate* isolate = i::Isolate::Current(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5205 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5206 | i::Object* security_token = env->security_token(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5207 | i::Handle<i::Object> token_handle(security_token, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5208 | return Utils::ToLocal(token_handle); |
| 5209 | } |
| 5210 | |
| 5211 | |
| 5212 | bool Context::HasOutOfMemoryException() { |
| 5213 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 5214 | return env->has_out_of_memory(); |
| 5215 | } |
| 5216 | |
| 5217 | |
| 5218 | bool Context::InContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5219 | return i::Isolate::Current()->context() != NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5223 | v8::Isolate* Context::GetIsolate() { |
| 5224 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 5225 | return reinterpret_cast<Isolate*>(env->GetIsolate()); |
| 5226 | } |
| 5227 | |
| 5228 | |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 5229 | v8::Local<v8::Context> Context::GetEntered() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5230 | i::Isolate* isolate = i::Isolate::Current(); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 5231 | if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5232 | return Local<Context>(); |
| 5233 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5234 | return reinterpret_cast<Isolate*>(isolate)->GetEnteredContext(); |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 5235 | } |
| 5236 | |
| 5237 | |
| 5238 | v8::Local<v8::Context> Context::GetCurrent() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5239 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5240 | return reinterpret_cast<Isolate*>(isolate)->GetCurrentContext(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5241 | } |
| 5242 | |
| 5243 | |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 5244 | v8::Local<v8::Context> Context::GetCalling() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5245 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5246 | return reinterpret_cast<Isolate*>(isolate)->GetCallingContext(); |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 5247 | } |
| 5248 | |
| 5249 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5250 | v8::Local<v8::Object> Context::Global() { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5251 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
| 5252 | i::Isolate* isolate = context->GetIsolate(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5253 | i::Handle<i::Object> global(context->global_proxy(), isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5254 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(global)); |
| 5255 | } |
| 5256 | |
| 5257 | |
| 5258 | void Context::DetachGlobal() { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5259 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
| 5260 | i::Isolate* isolate = context->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5261 | ENTER_V8(isolate); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5262 | isolate->bootstrapper()->DetachGlobal(context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 5266 | void Context::ReattachGlobal(Handle<Object> global_object) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5267 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
| 5268 | i::Isolate* isolate = context->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5269 | ENTER_V8(isolate); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5270 | i::Handle<i::JSGlobalProxy> global_proxy = |
| 5271 | i::Handle<i::JSGlobalProxy>::cast(Utils::OpenHandle(*global_object)); |
| 5272 | isolate->bootstrapper()->ReattachGlobal(context, global_proxy); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5276 | void Context::AllowCodeGenerationFromStrings(bool allow) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5277 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
| 5278 | i::Isolate* isolate = context->GetIsolate(); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5279 | ENTER_V8(isolate); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5280 | context->set_allow_code_gen_from_strings( |
| 5281 | allow ? isolate->heap()->true_value() : isolate->heap()->false_value()); |
| 5282 | } |
| 5283 | |
| 5284 | |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 5285 | bool Context::IsCodeGenerationFromStringsAllowed() { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5286 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 5287 | return !context->allow_code_gen_from_strings()->IsFalse(); |
| 5288 | } |
| 5289 | |
| 5290 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5291 | void Context::SetErrorMessageForCodeGenerationFromStrings( |
| 5292 | Handle<String> error) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5293 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5294 | i::Handle<i::String> error_handle = Utils::OpenHandle(*error); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5295 | context->set_error_message_for_code_gen_from_strings(*error_handle); |
| 5296 | } |
| 5297 | |
| 5298 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5299 | Local<v8::Object> ObjectTemplate::NewInstance() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5300 | i::Isolate* isolate = i::Isolate::Current(); |
| 5301 | ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", |
| 5302 | return Local<v8::Object>()); |
| 5303 | LOG_API(isolate, "ObjectTemplate::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5304 | ENTER_V8(isolate); |
| 5305 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5306 | i::Handle<i::Object> obj = |
| 5307 | i::Execution::InstantiateObject(Utils::OpenHandle(this), |
| 5308 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5309 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5310 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj)); |
| 5311 | } |
| 5312 | |
| 5313 | |
| 5314 | Local<v8::Function> FunctionTemplate::GetFunction() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5315 | i::Isolate* isolate = i::Isolate::Current(); |
| 5316 | ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5317 | return Local<v8::Function>()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5318 | LOG_API(isolate, "FunctionTemplate::GetFunction"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5319 | ENTER_V8(isolate); |
| 5320 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5321 | i::Handle<i::Object> obj = |
| 5322 | i::Execution::InstantiateFunction(Utils::OpenHandle(this), |
| 5323 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5324 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Function>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5325 | return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj)); |
| 5326 | } |
| 5327 | |
| 5328 | |
| 5329 | bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5330 | ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()", |
| 5331 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5332 | i::Object* obj = *Utils::OpenHandle(*value); |
| 5333 | return obj->IsInstanceOf(*Utils::OpenHandle(this)); |
| 5334 | } |
| 5335 | |
| 5336 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5337 | Local<External> v8::External::New(void* value) { |
| 5338 | STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5339 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5340 | EnsureInitializedForIsolate(isolate, "v8::External::New()"); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5341 | LOG_API(isolate, "External::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5342 | ENTER_V8(isolate); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5343 | i::Handle<i::JSObject> external = isolate->factory()->NewExternal(value); |
| 5344 | return Utils::ExternalToLocal(external); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | |
| 5348 | void* External::Value() const { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5349 | return ExternalValue(*Utils::OpenHandle(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 5353 | Local<String> v8::String::Empty() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5354 | i::Isolate* isolate = i::Isolate::Current(); |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 5355 | if (!EnsureInitializedForIsolate(isolate, "v8::String::Empty()")) { |
| 5356 | return v8::Local<String>(); |
| 5357 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5358 | LOG_API(isolate, "String::Empty()"); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5359 | return Utils::ToLocal(isolate->factory()->empty_string()); |
ager@chromium.org | 563b8dc | 2009-03-20 14:23:52 +0000 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5363 | // anonymous namespace for string creation helper functions |
| 5364 | namespace { |
| 5365 | |
| 5366 | inline int StringLength(const char* string) { |
| 5367 | return i::StrLength(string); |
| 5368 | } |
| 5369 | |
| 5370 | |
| 5371 | inline int StringLength(const uint8_t* string) { |
| 5372 | return i::StrLength(reinterpret_cast<const char*>(string)); |
| 5373 | } |
| 5374 | |
| 5375 | |
| 5376 | inline int StringLength(const uint16_t* string) { |
| 5377 | int length = 0; |
| 5378 | while (string[length] != '\0') |
| 5379 | length++; |
| 5380 | return length; |
| 5381 | } |
| 5382 | |
| 5383 | |
| 5384 | inline i::Handle<i::String> NewString(i::Factory* factory, |
| 5385 | String::NewStringType type, |
| 5386 | i::Vector<const char> string) { |
| 5387 | if (type ==String::kInternalizedString) { |
| 5388 | return factory->InternalizeUtf8String(string); |
| 5389 | } |
| 5390 | return factory->NewStringFromUtf8(string); |
| 5391 | } |
| 5392 | |
| 5393 | |
| 5394 | inline i::Handle<i::String> NewString(i::Factory* factory, |
| 5395 | String::NewStringType type, |
| 5396 | i::Vector<const uint8_t> string) { |
| 5397 | if (type == String::kInternalizedString) { |
| 5398 | return factory->InternalizeOneByteString(string); |
| 5399 | } |
| 5400 | return factory->NewStringFromOneByte(string); |
| 5401 | } |
| 5402 | |
| 5403 | |
| 5404 | inline i::Handle<i::String> NewString(i::Factory* factory, |
| 5405 | String::NewStringType type, |
| 5406 | i::Vector<const uint16_t> string) { |
| 5407 | if (type == String::kInternalizedString) { |
| 5408 | return factory->InternalizeTwoByteString(string); |
| 5409 | } |
| 5410 | return factory->NewStringFromTwoByte(string); |
| 5411 | } |
| 5412 | |
| 5413 | |
| 5414 | template<typename Char> |
| 5415 | inline Local<String> NewString(Isolate* v8_isolate, |
| 5416 | const char* location, |
| 5417 | const char* env, |
| 5418 | const Char* data, |
| 5419 | String::NewStringType type, |
| 5420 | int length) { |
| 5421 | i::Isolate* isolate = reinterpret_cast<internal::Isolate*>(v8_isolate); |
| 5422 | EnsureInitializedForIsolate(isolate, location); |
| 5423 | LOG_API(isolate, env); |
| 5424 | if (length == 0 && type != String::kUndetectableString) { |
| 5425 | return String::Empty(); |
| 5426 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5427 | ENTER_V8(isolate); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5428 | if (length == -1) length = StringLength(data); |
| 5429 | i::Handle<i::String> result = NewString( |
| 5430 | isolate->factory(), type, i::Vector<const Char>(data, length)); |
| 5431 | if (type == String::kUndetectableString) { |
| 5432 | result->MarkAsUndetectable(); |
| 5433 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5434 | return Utils::ToLocal(result); |
| 5435 | } |
| 5436 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5437 | } // anonymous namespace |
| 5438 | |
| 5439 | |
| 5440 | Local<String> String::NewFromUtf8(Isolate* isolate, |
| 5441 | const char* data, |
| 5442 | NewStringType type, |
| 5443 | int length) { |
| 5444 | return NewString(isolate, |
| 5445 | "v8::String::NewFromUtf8()", |
| 5446 | "String::NewFromUtf8", |
| 5447 | data, |
| 5448 | type, |
| 5449 | length); |
| 5450 | } |
| 5451 | |
| 5452 | |
| 5453 | Local<String> String::NewFromOneByte(Isolate* isolate, |
| 5454 | const uint8_t* data, |
| 5455 | NewStringType type, |
| 5456 | int length) { |
| 5457 | return NewString(isolate, |
| 5458 | "v8::String::NewFromOneByte()", |
| 5459 | "String::NewFromOneByte", |
| 5460 | data, |
| 5461 | type, |
| 5462 | length); |
| 5463 | } |
| 5464 | |
| 5465 | |
| 5466 | Local<String> String::NewFromTwoByte(Isolate* isolate, |
| 5467 | const uint16_t* data, |
| 5468 | NewStringType type, |
| 5469 | int length) { |
| 5470 | return NewString(isolate, |
| 5471 | "v8::String::NewFromTwoByte()", |
| 5472 | "String::NewFromTwoByte", |
| 5473 | data, |
| 5474 | type, |
| 5475 | length); |
| 5476 | } |
| 5477 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5478 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5479 | 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] | 5480 | i::Handle<i::String> left_string = Utils::OpenHandle(*left); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5481 | i::Isolate* isolate = left_string->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5482 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 5483 | LOG_API(isolate, "String::New(char)"); |
| 5484 | ENTER_V8(isolate); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5485 | i::Handle<i::String> right_string = Utils::OpenHandle(*right); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5486 | i::Handle<i::String> result = isolate->factory()->NewConsString(left_string, |
| 5487 | right_string); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5488 | return Utils::ToLocal(result); |
| 5489 | } |
| 5490 | |
| 5491 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5492 | i::Handle<i::String> NewExternalStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5493 | v8::String::ExternalStringResource* resource) { |
| 5494 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5495 | isolate->factory()->NewExternalStringFromTwoByte(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5496 | return result; |
| 5497 | } |
| 5498 | |
| 5499 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5500 | i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5501 | v8::String::ExternalAsciiStringResource* resource) { |
| 5502 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5503 | isolate->factory()->NewExternalStringFromAscii(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5504 | return result; |
| 5505 | } |
| 5506 | |
| 5507 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5508 | bool RedirectToExternalString(i::Isolate* isolate, |
| 5509 | i::Handle<i::String> parent, |
| 5510 | i::Handle<i::String> external) { |
| 5511 | if (parent->IsConsString()) { |
| 5512 | i::Handle<i::ConsString> cons = i::Handle<i::ConsString>::cast(parent); |
| 5513 | cons->set_first(*external); |
| 5514 | cons->set_second(isolate->heap()->empty_string()); |
| 5515 | } else { |
| 5516 | ASSERT(parent->IsSlicedString()); |
| 5517 | i::Handle<i::SlicedString> slice = i::Handle<i::SlicedString>::cast(parent); |
| 5518 | slice->set_parent(*external); |
| 5519 | slice->set_offset(0); |
| 5520 | } |
| 5521 | return true; |
| 5522 | } |
| 5523 | |
| 5524 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5525 | Local<String> v8::String::NewExternal( |
| 5526 | v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5527 | i::Isolate* isolate = i::Isolate::Current(); |
| 5528 | EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 5529 | LOG_API(isolate, "String::NewExternal"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5530 | ENTER_V8(isolate); |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 5531 | CHECK(resource && resource->data()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5532 | i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); |
| 5533 | isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5534 | return Utils::ToLocal(result); |
| 5535 | } |
| 5536 | |
| 5537 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 5538 | bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5539 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 5540 | i::Isolate* isolate = obj->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5541 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 5542 | return false; // Already an external string. |
| 5543 | } |
| 5544 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5545 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 5546 | return false; |
| 5547 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5548 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 5549 | return false; |
| 5550 | } |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 5551 | CHECK(resource && resource->data()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5552 | |
| 5553 | bool result; |
| 5554 | i::Handle<i::String> external; |
| 5555 | if (isolate->heap()->old_pointer_space()->Contains(*obj)) { |
| 5556 | // We do not allow external strings in the old pointer space. Instead of |
| 5557 | // converting the string in-place, we keep the cons/sliced string and |
| 5558 | // point it to a newly-allocated external string. |
| 5559 | external = NewExternalStringHandle(isolate, resource); |
| 5560 | result = RedirectToExternalString(isolate, obj, external); |
| 5561 | } else { |
| 5562 | result = obj->MakeExternal(resource); |
| 5563 | external = obj; |
| 5564 | } |
| 5565 | |
| 5566 | ASSERT(external->IsExternalString()); |
| 5567 | if (result && !external->IsInternalizedString()) { |
| 5568 | isolate->heap()->external_string_table()->AddString(*external); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 5569 | } |
| 5570 | return result; |
| 5571 | } |
| 5572 | |
| 5573 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5574 | Local<String> v8::String::NewExternal( |
| 5575 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5576 | i::Isolate* isolate = i::Isolate::Current(); |
| 5577 | EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 5578 | LOG_API(isolate, "String::NewExternal"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5579 | ENTER_V8(isolate); |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 5580 | CHECK(resource && resource->data()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5581 | i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); |
| 5582 | isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5583 | return Utils::ToLocal(result); |
| 5584 | } |
| 5585 | |
| 5586 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 5587 | bool v8::String::MakeExternal( |
| 5588 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5589 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 5590 | i::Isolate* isolate = obj->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5591 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 5592 | return false; // Already an external string. |
| 5593 | } |
| 5594 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5595 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 5596 | return false; |
| 5597 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5598 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 5599 | return false; |
| 5600 | } |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 5601 | CHECK(resource && resource->data()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5602 | |
| 5603 | bool result; |
| 5604 | i::Handle<i::String> external; |
| 5605 | if (isolate->heap()->old_pointer_space()->Contains(*obj)) { |
| 5606 | // We do not allow external strings in the old pointer space. Instead of |
| 5607 | // converting the string in-place, we keep the cons/sliced string and |
| 5608 | // point it to a newly-allocated external string. |
| 5609 | external = NewExternalAsciiStringHandle(isolate, resource); |
| 5610 | result = RedirectToExternalString(isolate, obj, external); |
| 5611 | } else { |
| 5612 | result = obj->MakeExternal(resource); |
| 5613 | external = obj; |
| 5614 | } |
| 5615 | |
| 5616 | ASSERT(external->IsExternalString()); |
| 5617 | if (result && !external->IsInternalizedString()) { |
| 5618 | isolate->heap()->external_string_table()->AddString(*external); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 5619 | } |
| 5620 | return result; |
| 5621 | } |
| 5622 | |
| 5623 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5624 | bool v8::String::CanMakeExternal() { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5625 | if (!internal::FLAG_clever_optimizations) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5626 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5627 | i::Isolate* isolate = obj->GetIsolate(); |
jkummerow@chromium.org | 32aa03c | 2013-10-01 08:21:50 +0000 | [diff] [blame] | 5628 | |
| 5629 | // TODO(yangguo): Externalizing sliced/cons strings allocates. |
| 5630 | // This rule can be removed when all code that can |
| 5631 | // trigger an access check is handlified and therefore GC safe. |
| 5632 | if (isolate->heap()->old_pointer_space()->Contains(*obj)) return false; |
| 5633 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5634 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5635 | int size = obj->Size(); // Byte size of the original string. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5636 | if (size < i::ExternalString::kShortSize) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5637 | i::StringShape shape(*obj); |
| 5638 | return !shape.IsExternal(); |
| 5639 | } |
| 5640 | |
| 5641 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5642 | Local<v8::Object> v8::Object::New() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5643 | i::Isolate* isolate = i::Isolate::Current(); |
| 5644 | EnsureInitializedForIsolate(isolate, "v8::Object::New()"); |
| 5645 | LOG_API(isolate, "Object::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5646 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5647 | i::Handle<i::JSObject> obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5648 | isolate->factory()->NewJSObject(isolate->object_function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5649 | return Utils::ToLocal(obj); |
| 5650 | } |
| 5651 | |
| 5652 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5653 | Local<v8::Value> v8::NumberObject::New(double value) { |
| 5654 | i::Isolate* isolate = i::Isolate::Current(); |
| 5655 | EnsureInitializedForIsolate(isolate, "v8::NumberObject::New()"); |
| 5656 | LOG_API(isolate, "NumberObject::New"); |
| 5657 | ENTER_V8(isolate); |
| 5658 | i::Handle<i::Object> number = isolate->factory()->NewNumber(value); |
| 5659 | i::Handle<i::Object> obj = isolate->factory()->ToObject(number); |
| 5660 | return Utils::ToLocal(obj); |
| 5661 | } |
| 5662 | |
| 5663 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5664 | double v8::NumberObject::ValueOf() const { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5665 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5666 | LOG_API(isolate, "NumberObject::NumberValue"); |
| 5667 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5668 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5669 | return jsvalue->value()->Number(); |
| 5670 | } |
| 5671 | |
| 5672 | |
| 5673 | Local<v8::Value> v8::BooleanObject::New(bool value) { |
| 5674 | i::Isolate* isolate = i::Isolate::Current(); |
| 5675 | EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()"); |
| 5676 | LOG_API(isolate, "BooleanObject::New"); |
| 5677 | ENTER_V8(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5678 | i::Handle<i::Object> boolean(value |
| 5679 | ? isolate->heap()->true_value() |
| 5680 | : isolate->heap()->false_value(), |
| 5681 | isolate); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5682 | i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean); |
| 5683 | return Utils::ToLocal(obj); |
| 5684 | } |
| 5685 | |
| 5686 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5687 | bool v8::BooleanObject::ValueOf() const { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5688 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5689 | LOG_API(isolate, "BooleanObject::BooleanValue"); |
| 5690 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5691 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5692 | return jsvalue->value()->IsTrue(); |
| 5693 | } |
| 5694 | |
| 5695 | |
| 5696 | Local<v8::Value> v8::StringObject::New(Handle<String> value) { |
| 5697 | i::Isolate* isolate = i::Isolate::Current(); |
| 5698 | EnsureInitializedForIsolate(isolate, "v8::StringObject::New()"); |
| 5699 | LOG_API(isolate, "StringObject::New"); |
| 5700 | ENTER_V8(isolate); |
| 5701 | i::Handle<i::Object> obj = |
| 5702 | isolate->factory()->ToObject(Utils::OpenHandle(*value)); |
| 5703 | return Utils::ToLocal(obj); |
| 5704 | } |
| 5705 | |
| 5706 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5707 | Local<v8::String> v8::StringObject::ValueOf() const { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5708 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5709 | LOG_API(isolate, "StringObject::StringValue"); |
| 5710 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5711 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5712 | return Utils::ToLocal( |
| 5713 | i::Handle<i::String>(i::String::cast(jsvalue->value()))); |
| 5714 | } |
| 5715 | |
| 5716 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5717 | Local<v8::Value> v8::SymbolObject::New(Isolate* isolate, Handle<Symbol> value) { |
| 5718 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5719 | EnsureInitializedForIsolate(i_isolate, "v8::SymbolObject::New()"); |
| 5720 | LOG_API(i_isolate, "SymbolObject::New"); |
| 5721 | ENTER_V8(i_isolate); |
| 5722 | i::Handle<i::Object> obj = |
| 5723 | i_isolate->factory()->ToObject(Utils::OpenHandle(*value)); |
| 5724 | return Utils::ToLocal(obj); |
| 5725 | } |
| 5726 | |
| 5727 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5728 | Local<v8::Symbol> v8::SymbolObject::ValueOf() const { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5729 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5730 | LOG_API(isolate, "SymbolObject::SymbolValue"); |
| 5731 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5732 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5733 | return Utils::ToLocal( |
| 5734 | i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value()))); |
| 5735 | } |
| 5736 | |
| 5737 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5738 | Local<v8::Value> v8::Date::New(double time) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5739 | i::Isolate* isolate = i::Isolate::Current(); |
| 5740 | EnsureInitializedForIsolate(isolate, "v8::Date::New()"); |
| 5741 | LOG_API(isolate, "Date::New"); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 5742 | if (std::isnan(time)) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5743 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 5744 | time = i::OS::nan_value(); |
| 5745 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5746 | ENTER_V8(isolate); |
| 5747 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5748 | i::Handle<i::Object> obj = |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 5749 | i::Execution::NewDate(isolate, time, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5750 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5751 | return Utils::ToLocal(obj); |
| 5752 | } |
| 5753 | |
| 5754 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5755 | double v8::Date::ValueOf() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5756 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5757 | LOG_API(isolate, "Date::NumberValue"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5758 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5759 | i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj); |
| 5760 | return jsdate->value()->Number(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5764 | void v8::Date::DateTimeConfigurationChangeNotification() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5765 | i::Isolate* isolate = i::Isolate::Current(); |
| 5766 | ON_BAILOUT(isolate, "v8::Date::DateTimeConfigurationChangeNotification()", |
| 5767 | return); |
| 5768 | LOG_API(isolate, "Date::DateTimeConfigurationChangeNotification"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5769 | ENTER_V8(isolate); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5770 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5771 | isolate->date_cache()->ResetDateCache(); |
| 5772 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5773 | i::HandleScope scope(isolate); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5774 | // Get the function ResetDateCache (defined in date.js). |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5775 | i::Handle<i::String> func_name_str = |
| 5776 | isolate->factory()->InternalizeOneByteString( |
| 5777 | STATIC_ASCII_VECTOR("ResetDateCache")); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5778 | i::MaybeObject* result = |
| 5779 | isolate->js_builtins_object()->GetProperty(*func_name_str); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5780 | i::Object* object_func; |
| 5781 | if (!result->ToObject(&object_func)) { |
| 5782 | return; |
| 5783 | } |
| 5784 | |
| 5785 | if (object_func->IsJSFunction()) { |
| 5786 | i::Handle<i::JSFunction> func = |
| 5787 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_func)); |
| 5788 | |
| 5789 | // Call ResetDateCache(0 but expect no exceptions: |
| 5790 | bool caught_exception = false; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 5791 | i::Execution::TryCall(func, |
| 5792 | isolate->js_builtins_object(), |
| 5793 | 0, |
| 5794 | NULL, |
| 5795 | &caught_exception); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5796 | } |
| 5797 | } |
| 5798 | |
| 5799 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5800 | static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5801 | i::Isolate* isolate = i::Isolate::Current(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5802 | uint8_t flags_buf[3]; |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5803 | int num_flags = 0; |
| 5804 | if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; |
| 5805 | if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; |
| 5806 | if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; |
| 5807 | ASSERT(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf))); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5808 | return isolate->factory()->InternalizeOneByteString( |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5809 | i::Vector<const uint8_t>(flags_buf, num_flags)); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | |
| 5813 | Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, |
| 5814 | Flags flags) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5815 | i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5816 | EnsureInitializedForIsolate(isolate, "v8::RegExp::New()"); |
| 5817 | LOG_API(isolate, "RegExp::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5818 | ENTER_V8(isolate); |
| 5819 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5820 | i::Handle<i::JSRegExp> obj = i::Execution::NewJSRegExp( |
| 5821 | Utils::OpenHandle(*pattern), |
| 5822 | RegExpFlagsToString(flags), |
| 5823 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5824 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::RegExp>()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5825 | return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj)); |
| 5826 | } |
| 5827 | |
| 5828 | |
| 5829 | Local<v8::String> v8::RegExp::GetSource() const { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5830 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 5831 | return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); |
| 5832 | } |
| 5833 | |
| 5834 | |
| 5835 | // Assert that the static flags cast in GetFlags is valid. |
| 5836 | #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ |
| 5837 | STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ |
| 5838 | static_cast<int>(i::JSRegExp::internal_flag)) |
| 5839 | REGEXP_FLAG_ASSERT_EQ(kNone, NONE); |
| 5840 | REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL); |
| 5841 | REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE); |
| 5842 | REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE); |
| 5843 | #undef REGEXP_FLAG_ASSERT_EQ |
| 5844 | |
| 5845 | v8::RegExp::Flags v8::RegExp::GetFlags() const { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5846 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 5847 | return static_cast<RegExp::Flags>(obj->GetFlags().value()); |
| 5848 | } |
| 5849 | |
| 5850 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5851 | Local<v8::Array> v8::Array::New(int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5852 | i::Isolate* isolate = i::Isolate::Current(); |
| 5853 | EnsureInitializedForIsolate(isolate, "v8::Array::New()"); |
| 5854 | LOG_API(isolate, "Array::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5855 | ENTER_V8(isolate); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5856 | int real_length = length > 0 ? length : 0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5857 | i::Handle<i::JSArray> obj = isolate->factory()->NewJSArray(real_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 5858 | i::Handle<i::Object> length_obj = |
| 5859 | isolate->factory()->NewNumberFromInt(real_length); |
| 5860 | obj->set_length(*length_obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5861 | return Utils::ToLocal(obj); |
| 5862 | } |
| 5863 | |
| 5864 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5865 | uint32_t v8::Array::Length() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5866 | i::Handle<i::JSArray> obj = Utils::OpenHandle(this); |
| 5867 | i::Object* length = obj->length(); |
| 5868 | if (length->IsSmi()) { |
| 5869 | return i::Smi::cast(length)->value(); |
| 5870 | } else { |
| 5871 | return static_cast<uint32_t>(length->Number()); |
| 5872 | } |
| 5873 | } |
| 5874 | |
| 5875 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5876 | Local<Object> Array::CloneElementAt(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5877 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5878 | ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5879 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5880 | if (!self->HasFastObjectElements()) { |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5881 | return Local<Object>(); |
| 5882 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 5883 | i::FixedArray* elms = i::FixedArray::cast(self->elements()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5884 | i::Object* paragon = elms->get(index); |
| 5885 | if (!paragon->IsJSObject()) { |
| 5886 | return Local<Object>(); |
| 5887 | } |
| 5888 | i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5889 | EXCEPTION_PREAMBLE(isolate); |
| 5890 | ENTER_V8(isolate); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5891 | i::Handle<i::JSObject> result = i::JSObject::Copy(paragon_handle); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5892 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5893 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5894 | return Utils::ToLocal(result); |
| 5895 | } |
| 5896 | |
| 5897 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5898 | bool v8::ArrayBuffer::IsExternal() const { |
| 5899 | return Utils::OpenHandle(this)->is_external(); |
| 5900 | } |
| 5901 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 5902 | |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 5903 | v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5904 | i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); |
| 5905 | ApiCheck(!obj->is_external(), |
| 5906 | "v8::ArrayBuffer::Externalize", |
| 5907 | "ArrayBuffer already externalized"); |
| 5908 | obj->set_is_external(true); |
| 5909 | size_t byte_length = static_cast<size_t>(obj->byte_length()->Number()); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 5910 | Contents contents; |
| 5911 | contents.data_ = obj->backing_store(); |
| 5912 | contents.byte_length_ = byte_length; |
| 5913 | return contents; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 5917 | void v8::ArrayBuffer::Neuter() { |
| 5918 | i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); |
| 5919 | i::Isolate* isolate = obj->GetIsolate(); |
| 5920 | ApiCheck(obj->is_external(), |
| 5921 | "v8::ArrayBuffer::Neuter", |
| 5922 | "Only externalized ArrayBuffers can be neutered"); |
| 5923 | LOG_API(obj->GetIsolate(), "v8::ArrayBuffer::Neuter()"); |
| 5924 | ENTER_V8(isolate); |
| 5925 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5926 | for (i::Handle<i::Object> view_obj(obj->weak_first_view(), isolate); |
| 5927 | !view_obj->IsUndefined();) { |
| 5928 | i::Handle<i::JSArrayBufferView> view(i::JSArrayBufferView::cast(*view_obj)); |
| 5929 | if (view->IsJSTypedArray()) { |
| 5930 | i::JSTypedArray::cast(*view)->Neuter(); |
| 5931 | } else if (view->IsJSDataView()) { |
| 5932 | i::JSDataView::cast(*view)->Neuter(); |
| 5933 | } else { |
| 5934 | UNREACHABLE(); |
| 5935 | } |
| 5936 | view_obj = i::handle(view->weak_next(), isolate); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 5937 | } |
| 5938 | obj->Neuter(); |
| 5939 | } |
| 5940 | |
| 5941 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5942 | size_t v8::ArrayBuffer::ByteLength() const { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5943 | i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); |
| 5944 | return static_cast<size_t>(obj->byte_length()->Number()); |
| 5945 | } |
| 5946 | |
| 5947 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5948 | Local<ArrayBuffer> v8::ArrayBuffer::New(size_t byte_length) { |
| 5949 | i::Isolate* isolate = i::Isolate::Current(); |
| 5950 | EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(size_t)"); |
| 5951 | LOG_API(isolate, "v8::ArrayBuffer::New(size_t)"); |
| 5952 | ENTER_V8(isolate); |
| 5953 | i::Handle<i::JSArrayBuffer> obj = |
| 5954 | isolate->factory()->NewJSArrayBuffer(); |
| 5955 | i::Runtime::SetupArrayBufferAllocatingData(isolate, obj, byte_length); |
| 5956 | return Utils::ToLocal(obj); |
| 5957 | } |
| 5958 | |
| 5959 | |
| 5960 | Local<ArrayBuffer> v8::ArrayBuffer::New(void* data, size_t byte_length) { |
| 5961 | i::Isolate* isolate = i::Isolate::Current(); |
| 5962 | EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(void*, size_t)"); |
| 5963 | LOG_API(isolate, "v8::ArrayBuffer::New(void*, size_t)"); |
| 5964 | ENTER_V8(isolate); |
| 5965 | i::Handle<i::JSArrayBuffer> obj = |
| 5966 | isolate->factory()->NewJSArrayBuffer(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5967 | i::Runtime::SetupArrayBuffer(isolate, obj, true, data, byte_length); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5968 | return Utils::ToLocal(obj); |
| 5969 | } |
| 5970 | |
| 5971 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5972 | Local<ArrayBuffer> v8::ArrayBufferView::Buffer() { |
| 5973 | i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5974 | ASSERT(obj->buffer()->IsJSArrayBuffer()); |
| 5975 | i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer())); |
| 5976 | return Utils::ToLocal(buffer); |
| 5977 | } |
| 5978 | |
| 5979 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5980 | size_t v8::ArrayBufferView::ByteOffset() { |
| 5981 | i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5982 | return static_cast<size_t>(obj->byte_offset()->Number()); |
| 5983 | } |
| 5984 | |
| 5985 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5986 | size_t v8::ArrayBufferView::ByteLength() { |
| 5987 | i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5988 | return static_cast<size_t>(obj->byte_length()->Number()); |
| 5989 | } |
| 5990 | |
| 5991 | |
| 5992 | size_t v8::TypedArray::Length() { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5993 | i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this); |
| 5994 | return static_cast<size_t>(obj->length()->Number()); |
| 5995 | } |
| 5996 | |
| 5997 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5998 | static inline void SetupArrayBufferView( |
| 5999 | i::Isolate* isolate, |
| 6000 | i::Handle<i::JSArrayBufferView> obj, |
| 6001 | i::Handle<i::JSArrayBuffer> buffer, |
| 6002 | size_t byte_offset, |
| 6003 | size_t byte_length) { |
| 6004 | ASSERT(byte_offset + byte_length <= |
| 6005 | static_cast<size_t>(buffer->byte_length()->Number())); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6006 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6007 | obj->set_buffer(*buffer); |
| 6008 | |
| 6009 | obj->set_weak_next(buffer->weak_first_view()); |
| 6010 | buffer->set_weak_first_view(*obj); |
| 6011 | |
| 6012 | i::Handle<i::Object> byte_offset_object = |
| 6013 | isolate->factory()->NewNumberFromSize(byte_offset); |
| 6014 | obj->set_byte_offset(*byte_offset_object); |
| 6015 | |
| 6016 | i::Handle<i::Object> byte_length_object = |
| 6017 | isolate->factory()->NewNumberFromSize(byte_length); |
| 6018 | obj->set_byte_length(*byte_length_object); |
| 6019 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6020 | |
| 6021 | template<typename ElementType, |
| 6022 | ExternalArrayType array_type, |
| 6023 | i::ElementsKind elements_kind> |
| 6024 | i::Handle<i::JSTypedArray> NewTypedArray( |
| 6025 | i::Isolate* isolate, |
| 6026 | Handle<ArrayBuffer> array_buffer, size_t byte_offset, size_t length) { |
| 6027 | i::Handle<i::JSTypedArray> obj = |
| 6028 | isolate->factory()->NewJSTypedArray(array_type); |
| 6029 | i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); |
| 6030 | |
| 6031 | ASSERT(byte_offset % sizeof(ElementType) == 0); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6032 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6033 | SetupArrayBufferView( |
| 6034 | isolate, obj, buffer, byte_offset, length * sizeof(ElementType)); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6035 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6036 | i::Handle<i::Object> length_object = |
| 6037 | isolate->factory()->NewNumberFromSize(length); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6038 | obj->set_length(*length_object); |
| 6039 | |
| 6040 | i::Handle<i::ExternalArray> elements = |
| 6041 | isolate->factory()->NewExternalArray( |
| 6042 | static_cast<int>(length), array_type, |
| 6043 | static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6044 | obj->set_elements(*elements); |
| 6045 | return obj; |
| 6046 | } |
| 6047 | |
| 6048 | |
| 6049 | #define TYPED_ARRAY_NEW(TypedArray, element_type, array_type, elements_kind) \ |
| 6050 | Local<TypedArray> TypedArray::New(Handle<ArrayBuffer> array_buffer, \ |
| 6051 | size_t byte_offset, size_t length) { \ |
| 6052 | i::Isolate* isolate = i::Isolate::Current(); \ |
| 6053 | EnsureInitializedForIsolate(isolate, \ |
| 6054 | "v8::" #TypedArray "::New(Handle<ArrayBuffer>, size_t, size_t)"); \ |
| 6055 | LOG_API(isolate, \ |
| 6056 | "v8::" #TypedArray "::New(Handle<ArrayBuffer>, size_t, size_t)"); \ |
| 6057 | ENTER_V8(isolate); \ |
| 6058 | i::Handle<i::JSTypedArray> obj = \ |
| 6059 | NewTypedArray<element_type, array_type, elements_kind>( \ |
| 6060 | isolate, array_buffer, byte_offset, length); \ |
| 6061 | return Utils::ToLocal##TypedArray(obj); \ |
| 6062 | } |
| 6063 | |
| 6064 | |
| 6065 | TYPED_ARRAY_NEW(Uint8Array, uint8_t, kExternalUnsignedByteArray, |
| 6066 | i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS) |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6067 | TYPED_ARRAY_NEW(Uint8ClampedArray, uint8_t, kExternalPixelArray, |
| 6068 | i::EXTERNAL_PIXEL_ELEMENTS) |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6069 | TYPED_ARRAY_NEW(Int8Array, int8_t, kExternalByteArray, |
| 6070 | i::EXTERNAL_BYTE_ELEMENTS) |
| 6071 | TYPED_ARRAY_NEW(Uint16Array, uint16_t, kExternalUnsignedShortArray, |
| 6072 | i::EXTERNAL_UNSIGNED_SHORT_ELEMENTS) |
| 6073 | TYPED_ARRAY_NEW(Int16Array, int16_t, kExternalShortArray, |
| 6074 | i::EXTERNAL_SHORT_ELEMENTS) |
| 6075 | TYPED_ARRAY_NEW(Uint32Array, uint32_t, kExternalUnsignedIntArray, |
| 6076 | i::EXTERNAL_UNSIGNED_INT_ELEMENTS) |
| 6077 | TYPED_ARRAY_NEW(Int32Array, int32_t, kExternalIntArray, |
| 6078 | i::EXTERNAL_INT_ELEMENTS) |
| 6079 | TYPED_ARRAY_NEW(Float32Array, float, kExternalFloatArray, |
| 6080 | i::EXTERNAL_FLOAT_ELEMENTS) |
| 6081 | TYPED_ARRAY_NEW(Float64Array, double, kExternalDoubleArray, |
| 6082 | i::EXTERNAL_DOUBLE_ELEMENTS) |
| 6083 | |
| 6084 | #undef TYPED_ARRAY_NEW |
| 6085 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6086 | Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer, |
| 6087 | size_t byte_offset, size_t byte_length) { |
| 6088 | i::Isolate* isolate = i::Isolate::Current(); |
| 6089 | EnsureInitializedForIsolate( |
| 6090 | isolate, "v8::DataView::New(void*, size_t, size_t)"); |
| 6091 | LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)"); |
| 6092 | ENTER_V8(isolate); |
| 6093 | i::Handle<i::JSDataView> obj = isolate->factory()->NewJSDataView(); |
| 6094 | i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); |
| 6095 | SetupArrayBufferView( |
| 6096 | isolate, obj, buffer, byte_offset, byte_length); |
| 6097 | return Utils::ToLocal(obj); |
| 6098 | } |
| 6099 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6100 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6101 | Local<Symbol> v8::Symbol::New(Isolate* isolate) { |
| 6102 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6103 | EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()"); |
| 6104 | LOG_API(i_isolate, "Symbol::New()"); |
| 6105 | ENTER_V8(i_isolate); |
| 6106 | i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); |
| 6107 | return Utils::ToLocal(result); |
| 6108 | } |
| 6109 | |
| 6110 | |
| 6111 | Local<Symbol> v8::Symbol::New(Isolate* isolate, const char* data, int length) { |
| 6112 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6113 | EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()"); |
| 6114 | LOG_API(i_isolate, "Symbol::New(char)"); |
| 6115 | ENTER_V8(i_isolate); |
| 6116 | if (length == -1) length = i::StrLength(data); |
| 6117 | i::Handle<i::String> name = i_isolate->factory()->NewStringFromUtf8( |
| 6118 | i::Vector<const char>(data, length)); |
| 6119 | i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); |
| 6120 | result->set_name(*name); |
| 6121 | return Utils::ToLocal(result); |
| 6122 | } |
| 6123 | |
| 6124 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6125 | Local<Number> v8::Number::New(double value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6126 | i::Isolate* isolate = i::Isolate::Current(); |
| 6127 | EnsureInitializedForIsolate(isolate, "v8::Number::New()"); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6128 | return Number::New(reinterpret_cast<Isolate*>(isolate), value); |
| 6129 | } |
| 6130 | |
| 6131 | |
| 6132 | Local<Number> v8::Number::New(Isolate* isolate, double value) { |
| 6133 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6134 | ASSERT(internal_isolate->IsInitialized()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 6135 | if (std::isnan(value)) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6136 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 6137 | value = i::OS::nan_value(); |
| 6138 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6139 | ENTER_V8(internal_isolate); |
| 6140 | i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6141 | return Utils::NumberToLocal(result); |
| 6142 | } |
| 6143 | |
| 6144 | |
| 6145 | Local<Integer> v8::Integer::New(int32_t value) { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 6146 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6147 | EnsureInitializedForIsolate(isolate, "v8::Integer::New()"); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 6148 | return v8::Integer::New(value, reinterpret_cast<Isolate*>(isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6149 | } |
| 6150 | |
| 6151 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6152 | Local<Integer> Integer::NewFromUnsigned(uint32_t value) { |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 6153 | i::Isolate* isolate = i::Isolate::Current(); |
| 6154 | EnsureInitializedForIsolate(isolate, "v8::Integer::NewFromUnsigned()"); |
| 6155 | return Integer::NewFromUnsigned(value, reinterpret_cast<Isolate*>(isolate)); |
| 6156 | } |
| 6157 | |
| 6158 | |
| 6159 | Local<Integer> v8::Integer::New(int32_t value, Isolate* isolate) { |
| 6160 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6161 | ASSERT(internal_isolate->IsInitialized()); |
| 6162 | if (i::Smi::IsValid(value)) { |
| 6163 | return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value), |
| 6164 | internal_isolate)); |
| 6165 | } |
| 6166 | ENTER_V8(internal_isolate); |
| 6167 | i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); |
| 6168 | return Utils::IntegerToLocal(result); |
| 6169 | } |
| 6170 | |
| 6171 | |
| 6172 | Local<Integer> v8::Integer::NewFromUnsigned(uint32_t value, Isolate* isolate) { |
| 6173 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6174 | ASSERT(internal_isolate->IsInitialized()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6175 | bool fits_into_int32_t = (value & (1 << 31)) == 0; |
| 6176 | if (fits_into_int32_t) { |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 6177 | return Integer::New(static_cast<int32_t>(value), isolate); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6178 | } |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 6179 | ENTER_V8(internal_isolate); |
| 6180 | i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6181 | return Utils::IntegerToLocal(result); |
| 6182 | } |
| 6183 | |
| 6184 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6185 | #ifdef DEBUG |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 6186 | v8::AssertNoGCScope::AssertNoGCScope(v8::Isolate* isolate) { |
| 6187 | disallow_heap_allocation_ = new i::DisallowHeapAllocation(); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6188 | } |
| 6189 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6190 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6191 | v8::AssertNoGCScope::~AssertNoGCScope() { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 6192 | delete static_cast<i::DisallowHeapAllocation*>(disallow_heap_allocation_); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6193 | } |
| 6194 | #endif |
| 6195 | |
| 6196 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6197 | void V8::IgnoreOutOfMemoryException() { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 6198 | EnterIsolateIfNeeded()->set_ignore_out_of_memory(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6202 | bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6203 | i::Isolate* isolate = i::Isolate::Current(); |
| 6204 | EnsureInitializedForIsolate(isolate, "v8::V8::AddMessageListener()"); |
| 6205 | ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6206 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6207 | i::HandleScope scope(isolate); |
| 6208 | NeanderArray listeners(isolate->factory()->message_listeners()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6209 | NeanderObject obj(2); |
| 6210 | obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); |
| 6211 | obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value() |
| 6212 | : *Utils::OpenHandle(*data)); |
| 6213 | listeners.add(obj.value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6214 | return true; |
| 6215 | } |
| 6216 | |
| 6217 | |
| 6218 | void V8::RemoveMessageListeners(MessageCallback that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6219 | i::Isolate* isolate = i::Isolate::Current(); |
| 6220 | EnsureInitializedForIsolate(isolate, "v8::V8::RemoveMessageListener()"); |
| 6221 | ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6222 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6223 | i::HandleScope scope(isolate); |
| 6224 | NeanderArray listeners(isolate->factory()->message_listeners()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6225 | for (int i = 0; i < listeners.length(); i++) { |
| 6226 | if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones |
| 6227 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6228 | NeanderObject listener(i::JSObject::cast(listeners.get(i))); |
| 6229 | 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] | 6230 | if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6231 | listeners.set(i, isolate->heap()->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6232 | } |
| 6233 | } |
| 6234 | } |
| 6235 | |
| 6236 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 6237 | void V8::SetCaptureStackTraceForUncaughtExceptions( |
| 6238 | bool capture, |
| 6239 | int frame_limit, |
| 6240 | StackTrace::StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6241 | i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions( |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 6242 | capture, |
| 6243 | frame_limit, |
| 6244 | options); |
| 6245 | } |
| 6246 | |
| 6247 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6248 | void V8::SetCounterFunction(CounterLookupCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 6249 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6250 | isolate->stats_table()->SetCounterFunction(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6251 | } |
| 6252 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6253 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6254 | void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 6255 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6256 | isolate->stats_table()->SetCreateHistogramFunction(callback); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 6257 | isolate->InitializeLoggingAndCounters(); |
| 6258 | isolate->counters()->ResetHistograms(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6259 | } |
| 6260 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6261 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6262 | void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 6263 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6264 | isolate->stats_table()-> |
| 6265 | SetAddHistogramSampleFunction(callback); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6266 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6267 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6268 | void V8::SetFailedAccessCheckCallbackFunction( |
| 6269 | FailedAccessCheckCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6270 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6271 | isolate->SetFailedAccessCheckCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6272 | } |
| 6273 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 6274 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 6275 | intptr_t Isolate::AdjustAmountOfExternalAllocatedMemory( |
| 6276 | intptr_t change_in_bytes) { |
| 6277 | i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap(); |
| 6278 | return heap->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); |
| 6279 | } |
| 6280 | |
| 6281 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 6282 | intptr_t V8::AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 6283 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 6284 | if (isolate == NULL || !isolate->IsInitialized()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6285 | return 0; |
| 6286 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 6287 | Isolate* isolate_ext = reinterpret_cast<Isolate*>(isolate); |
| 6288 | return isolate_ext->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6292 | HeapProfiler* Isolate::GetHeapProfiler() { |
| 6293 | i::HeapProfiler* heap_profiler = |
| 6294 | reinterpret_cast<i::Isolate*>(this)->heap_profiler(); |
| 6295 | return reinterpret_cast<HeapProfiler*>(heap_profiler); |
| 6296 | } |
| 6297 | |
| 6298 | |
| 6299 | CpuProfiler* Isolate::GetCpuProfiler() { |
| 6300 | i::CpuProfiler* cpu_profiler = |
| 6301 | reinterpret_cast<i::Isolate*>(this)->cpu_profiler(); |
| 6302 | return reinterpret_cast<CpuProfiler*>(cpu_profiler); |
| 6303 | } |
| 6304 | |
| 6305 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6306 | bool Isolate::InContext() { |
| 6307 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6308 | return isolate->context() != NULL; |
| 6309 | } |
| 6310 | |
| 6311 | |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 6312 | v8::Local<v8::Context> Isolate::GetCurrentContext() { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6313 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6314 | i::Context* context = isolate->context(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6315 | if (context == NULL) return Local<Context>(); |
| 6316 | i::Context* native_context = context->global_object()->native_context(); |
| 6317 | if (native_context == NULL) return Local<Context>(); |
| 6318 | return Utils::ToLocal(i::Handle<i::Context>(native_context)); |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 6319 | } |
| 6320 | |
| 6321 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6322 | v8::Local<v8::Context> Isolate::GetCallingContext() { |
| 6323 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6324 | i::Handle<i::Object> calling = isolate->GetCallingNativeContext(); |
| 6325 | if (calling.is_null()) return Local<Context>(); |
| 6326 | return Utils::ToLocal(i::Handle<i::Context>::cast(calling)); |
| 6327 | } |
| 6328 | |
| 6329 | |
| 6330 | v8::Local<v8::Context> Isolate::GetEnteredContext() { |
| 6331 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6332 | i::Handle<i::Object> last = |
| 6333 | isolate->handle_scope_implementer()->LastEnteredContext(); |
| 6334 | if (last.is_null()) return Local<Context>(); |
| 6335 | return Utils::ToLocal(i::Handle<i::Context>::cast(last)); |
| 6336 | } |
| 6337 | |
| 6338 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 6339 | v8::Local<Value> Isolate::ThrowException(v8::Local<v8::Value> value) { |
| 6340 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6341 | ENTER_V8(isolate); |
| 6342 | // If we're passed an empty handle, we throw an undefined exception |
| 6343 | // to deal more gracefully with out of memory situations. |
| 6344 | if (value.IsEmpty()) { |
| 6345 | isolate->ScheduleThrow(isolate->heap()->undefined_value()); |
| 6346 | } else { |
| 6347 | isolate->ScheduleThrow(*Utils::OpenHandle(*value)); |
| 6348 | } |
| 6349 | return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 6350 | } |
| 6351 | |
| 6352 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6353 | void Isolate::SetObjectGroupId(const Persistent<Value>& object, |
| 6354 | UniqueId id) { |
| 6355 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); |
| 6356 | internal_isolate->global_handles()->SetObjectGroupId( |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6357 | Utils::OpenPersistent(object).location(), |
| 6358 | id); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | |
| 6362 | void Isolate::SetReferenceFromGroup(UniqueId id, |
| 6363 | const Persistent<Value>& object) { |
| 6364 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6365 | internal_isolate->global_handles()->SetReferenceFromGroup( |
| 6366 | id, |
| 6367 | Utils::OpenPersistent(object).location()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6368 | } |
| 6369 | |
| 6370 | |
| 6371 | void Isolate::SetReference(const Persistent<Object>& parent, |
| 6372 | const Persistent<Value>& child) { |
| 6373 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6374 | i::Object** parent_location = Utils::OpenPersistent(parent).location(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6375 | internal_isolate->global_handles()->SetReference( |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6376 | reinterpret_cast<i::HeapObject**>(parent_location), |
| 6377 | Utils::OpenPersistent(child).location()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6378 | } |
| 6379 | |
| 6380 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6381 | void Isolate::AddGCPrologueCallback(GCPrologueCallback callback, |
| 6382 | GCType gc_type) { |
| 6383 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6384 | isolate->heap()->AddGCPrologueCallback(callback, gc_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6385 | } |
| 6386 | |
| 6387 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6388 | void Isolate::RemoveGCPrologueCallback(GCPrologueCallback callback) { |
| 6389 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6390 | isolate->heap()->RemoveGCPrologueCallback(callback); |
| 6391 | } |
| 6392 | |
| 6393 | |
| 6394 | void Isolate::AddGCEpilogueCallback(GCEpilogueCallback callback, |
| 6395 | GCType gc_type) { |
| 6396 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6397 | isolate->heap()->AddGCEpilogueCallback(callback, gc_type); |
| 6398 | } |
| 6399 | |
| 6400 | |
| 6401 | void Isolate::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { |
| 6402 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6403 | isolate->heap()->RemoveGCEpilogueCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6404 | } |
| 6405 | |
| 6406 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6407 | void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6408 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6409 | isolate->heap()->AddGCPrologueCallback( |
| 6410 | reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback), |
| 6411 | gc_type, |
| 6412 | false); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6413 | } |
| 6414 | |
| 6415 | |
| 6416 | void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6417 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6418 | isolate->heap()->RemoveGCPrologueCallback( |
| 6419 | reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6420 | } |
| 6421 | |
| 6422 | |
| 6423 | void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6424 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6425 | isolate->heap()->AddGCEpilogueCallback( |
| 6426 | reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback), |
| 6427 | gc_type, |
| 6428 | false); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6429 | } |
| 6430 | |
| 6431 | |
| 6432 | void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6433 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6434 | isolate->heap()->RemoveGCEpilogueCallback( |
| 6435 | reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6439 | void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 6440 | ObjectSpace space, |
| 6441 | AllocationAction action) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6442 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6443 | isolate->memory_allocator()->AddMemoryAllocationCallback( |
| 6444 | callback, space, action); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6445 | } |
| 6446 | |
| 6447 | |
| 6448 | void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6449 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6450 | isolate->memory_allocator()->RemoveMemoryAllocationCallback( |
| 6451 | callback); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6452 | } |
| 6453 | |
| 6454 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6455 | void V8::AddCallCompletedCallback(CallCompletedCallback callback) { |
| 6456 | if (callback == NULL) return; |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6457 | i::V8::AddCallCompletedCallback(callback); |
| 6458 | } |
| 6459 | |
| 6460 | |
| 6461 | void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6462 | i::V8::RemoveCallCompletedCallback(callback); |
| 6463 | } |
| 6464 | |
| 6465 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6466 | void V8::TerminateExecution(Isolate* isolate) { |
| 6467 | // If no isolate is supplied, use the default isolate. |
| 6468 | if (isolate != NULL) { |
| 6469 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution(); |
| 6470 | } else { |
| 6471 | i::Isolate::GetDefaultIsolateStackGuard()->TerminateExecution(); |
| 6472 | } |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 6473 | } |
| 6474 | |
| 6475 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 6476 | bool V8::IsExecutionTerminating(Isolate* isolate) { |
| 6477 | i::Isolate* i_isolate = isolate != NULL ? |
| 6478 | reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current(); |
| 6479 | return IsExecutionTerminatingCheck(i_isolate); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 6480 | } |
| 6481 | |
| 6482 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 6483 | void V8::CancelTerminateExecution(Isolate* isolate) { |
| 6484 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6485 | i_isolate->stack_guard()->CancelTerminateExecution(); |
| 6486 | } |
| 6487 | |
| 6488 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6489 | Isolate* Isolate::GetCurrent() { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 6490 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6491 | return reinterpret_cast<Isolate*>(isolate); |
| 6492 | } |
| 6493 | |
| 6494 | |
| 6495 | Isolate* Isolate::New() { |
| 6496 | i::Isolate* isolate = new i::Isolate(); |
| 6497 | return reinterpret_cast<Isolate*>(isolate); |
| 6498 | } |
| 6499 | |
| 6500 | |
| 6501 | void Isolate::Dispose() { |
| 6502 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6503 | if (!ApiCheck(!isolate->IsInUse(), |
| 6504 | "v8::Isolate::Dispose()", |
| 6505 | "Disposing the isolate that is entered by a thread.")) { |
| 6506 | return; |
| 6507 | } |
| 6508 | isolate->TearDown(); |
| 6509 | } |
| 6510 | |
| 6511 | |
| 6512 | void Isolate::Enter() { |
| 6513 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6514 | isolate->Enter(); |
| 6515 | } |
| 6516 | |
| 6517 | |
| 6518 | void Isolate::Exit() { |
| 6519 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6520 | isolate->Exit(); |
| 6521 | } |
| 6522 | |
| 6523 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6524 | void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { |
| 6525 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6526 | if (!isolate->IsInitialized()) { |
| 6527 | heap_statistics->total_heap_size_ = 0; |
| 6528 | heap_statistics->total_heap_size_executable_ = 0; |
| 6529 | heap_statistics->total_physical_size_ = 0; |
| 6530 | heap_statistics->used_heap_size_ = 0; |
| 6531 | heap_statistics->heap_size_limit_ = 0; |
| 6532 | return; |
| 6533 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6534 | i::Heap* heap = isolate->heap(); |
| 6535 | heap_statistics->total_heap_size_ = heap->CommittedMemory(); |
| 6536 | heap_statistics->total_heap_size_executable_ = |
| 6537 | heap->CommittedMemoryExecutable(); |
| 6538 | heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory(); |
| 6539 | heap_statistics->used_heap_size_ = heap->SizeOfObjects(); |
| 6540 | heap_statistics->heap_size_limit_ = heap->MaxReserved(); |
| 6541 | } |
| 6542 | |
| 6543 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6544 | String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) |
| 6545 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6546 | i::Isolate* isolate = i::Isolate::Current(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6547 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6548 | ENTER_V8(isolate); |
| 6549 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6550 | TryCatch try_catch; |
| 6551 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6552 | if (str.IsEmpty()) return; |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 6553 | i::Handle<i::String> i_str = Utils::OpenHandle(*str); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 6554 | length_ = v8::Utf8Length(*i_str, isolate); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6555 | str_ = i::NewArray<char>(length_ + 1); |
| 6556 | str->WriteUtf8(str_); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6557 | } |
| 6558 | |
| 6559 | |
| 6560 | String::Utf8Value::~Utf8Value() { |
| 6561 | i::DeleteArray(str_); |
| 6562 | } |
| 6563 | |
| 6564 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6565 | String::AsciiValue::AsciiValue(v8::Handle<v8::Value> obj) |
| 6566 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6567 | i::Isolate* isolate = i::Isolate::Current(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6568 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6569 | ENTER_V8(isolate); |
| 6570 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6571 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6572 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6573 | if (str.IsEmpty()) return; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6574 | length_ = str->Utf8Length(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6575 | str_ = i::NewArray<char>(length_ + 1); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6576 | str->WriteUtf8(str_); |
| 6577 | ASSERT(i::String::NonAsciiStart(str_, length_) >= length_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6578 | } |
| 6579 | |
| 6580 | |
| 6581 | String::AsciiValue::~AsciiValue() { |
| 6582 | i::DeleteArray(str_); |
| 6583 | } |
| 6584 | |
| 6585 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6586 | String::Value::Value(v8::Handle<v8::Value> obj) |
| 6587 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6588 | i::Isolate* isolate = i::Isolate::Current(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6589 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6590 | ENTER_V8(isolate); |
| 6591 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6592 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6593 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6594 | if (str.IsEmpty()) return; |
| 6595 | length_ = str->Length(); |
| 6596 | str_ = i::NewArray<uint16_t>(length_ + 1); |
| 6597 | str->Write(str_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6598 | } |
| 6599 | |
| 6600 | |
| 6601 | String::Value::~Value() { |
| 6602 | i::DeleteArray(str_); |
| 6603 | } |
| 6604 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6605 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6606 | Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6607 | i::Isolate* isolate = i::Isolate::Current(); |
| 6608 | LOG_API(isolate, "RangeError"); |
| 6609 | ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6610 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6611 | i::Object* error; |
| 6612 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6613 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6614 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6615 | i::Handle<i::Object> result = isolate->factory()->NewRangeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6616 | error = *result; |
| 6617 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6618 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6619 | return Utils::ToLocal(result); |
| 6620 | } |
| 6621 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6622 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6623 | Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6624 | i::Isolate* isolate = i::Isolate::Current(); |
| 6625 | LOG_API(isolate, "ReferenceError"); |
| 6626 | ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6627 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6628 | i::Object* error; |
| 6629 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6630 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6631 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6632 | i::Handle<i::Object> result = |
| 6633 | isolate->factory()->NewReferenceError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6634 | error = *result; |
| 6635 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6636 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6637 | return Utils::ToLocal(result); |
| 6638 | } |
| 6639 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6640 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6641 | Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6642 | i::Isolate* isolate = i::Isolate::Current(); |
| 6643 | LOG_API(isolate, "SyntaxError"); |
| 6644 | ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6645 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6646 | i::Object* error; |
| 6647 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6648 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6649 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6650 | i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6651 | error = *result; |
| 6652 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6653 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6654 | return Utils::ToLocal(result); |
| 6655 | } |
| 6656 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6657 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6658 | Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6659 | i::Isolate* isolate = i::Isolate::Current(); |
| 6660 | LOG_API(isolate, "TypeError"); |
| 6661 | ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6662 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6663 | i::Object* error; |
| 6664 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6665 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6666 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6667 | i::Handle<i::Object> result = isolate->factory()->NewTypeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6668 | error = *result; |
| 6669 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6670 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6671 | return Utils::ToLocal(result); |
| 6672 | } |
| 6673 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6674 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6675 | Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6676 | i::Isolate* isolate = i::Isolate::Current(); |
| 6677 | LOG_API(isolate, "Error"); |
| 6678 | ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6679 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6680 | i::Object* error; |
| 6681 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6682 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6683 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6684 | i::Handle<i::Object> result = isolate->factory()->NewError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6685 | error = *result; |
| 6686 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6687 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6688 | return Utils::ToLocal(result); |
| 6689 | } |
| 6690 | |
| 6691 | |
| 6692 | // --- D e b u g S u p p o r t --- |
| 6693 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6694 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6695 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6696 | bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6697 | i::Isolate* isolate = i::Isolate::Current(); |
| 6698 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()"); |
| 6699 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6700 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6701 | i::HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6702 | i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 6703 | if (that != NULL) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6704 | foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 6705 | } |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 6706 | isolate->debugger()->SetEventListener(foreign, |
| 6707 | Utils::OpenHandle(*data, true)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6708 | return true; |
| 6709 | } |
| 6710 | |
| 6711 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 6712 | bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6713 | Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6714 | i::Isolate* isolate = i::Isolate::Current(); |
| 6715 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6716 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6717 | isolate->debugger()->SetEventListener(Utils::OpenHandle(*that), |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 6718 | Utils::OpenHandle(*data, true)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6719 | return true; |
| 6720 | } |
| 6721 | |
| 6722 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6723 | void Debug::DebugBreak(Isolate* isolate) { |
| 6724 | // If no isolate is supplied, use the default isolate. |
| 6725 | if (isolate != NULL) { |
| 6726 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->DebugBreak(); |
| 6727 | } else { |
| 6728 | i::Isolate::GetDefaultIsolateStackGuard()->DebugBreak(); |
| 6729 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6730 | } |
| 6731 | |
| 6732 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6733 | void Debug::CancelDebugBreak(Isolate* isolate) { |
| 6734 | // If no isolate is supplied, use the default isolate. |
| 6735 | if (isolate != NULL) { |
| 6736 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6737 | internal_isolate->stack_guard()->Continue(i::DEBUGBREAK); |
| 6738 | } else { |
| 6739 | i::Isolate::GetDefaultIsolateStackGuard()->Continue(i::DEBUGBREAK); |
| 6740 | } |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 6741 | } |
| 6742 | |
| 6743 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6744 | void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) { |
| 6745 | // If no isolate is supplied, use the default isolate. |
| 6746 | if (isolate != NULL) { |
| 6747 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6748 | internal_isolate->debugger()->EnqueueDebugCommand(data); |
| 6749 | } else { |
| 6750 | i::Isolate::GetDefaultIsolateDebugger()->EnqueueDebugCommand(data); |
| 6751 | } |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 6752 | } |
| 6753 | |
| 6754 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 6755 | void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6756 | i::Isolate* isolate = i::Isolate::Current(); |
| 6757 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); |
| 6758 | ENTER_V8(isolate); |
| 6759 | isolate->debugger()->SetMessageHandler(handler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6760 | } |
| 6761 | |
| 6762 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6763 | void Debug::SendCommand(Isolate* isolate, |
| 6764 | const uint16_t* command, |
| 6765 | int length, |
| 6766 | ClientData* client_data) { |
| 6767 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6768 | internal_isolate->debugger()->ProcessCommand( |
| 6769 | i::Vector<const uint16_t>(command, length), client_data); |
| 6770 | } |
| 6771 | |
| 6772 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6773 | void Debug::SendCommand(const uint16_t* command, int length, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6774 | ClientData* client_data, |
| 6775 | Isolate* isolate) { |
| 6776 | // If no isolate is supplied, use the default isolate. |
| 6777 | if (isolate != NULL) { |
| 6778 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6779 | internal_isolate->debugger()->ProcessCommand( |
| 6780 | i::Vector<const uint16_t>(command, length), client_data); |
| 6781 | } else { |
| 6782 | i::Isolate::GetDefaultIsolateDebugger()->ProcessCommand( |
| 6783 | i::Vector<const uint16_t>(command, length), client_data); |
| 6784 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6788 | void Debug::SetHostDispatchHandler(HostDispatchHandler handler, |
| 6789 | int period) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6790 | i::Isolate* isolate = i::Isolate::Current(); |
| 6791 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetHostDispatchHandler"); |
| 6792 | ENTER_V8(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 6793 | isolate->debugger()->SetHostDispatchHandler( |
| 6794 | handler, i::TimeDelta::FromMilliseconds(period)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 6795 | } |
| 6796 | |
| 6797 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6798 | void Debug::SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6799 | DebugMessageDispatchHandler handler, bool provide_locker) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6800 | i::Isolate* isolate = i::Isolate::Current(); |
| 6801 | EnsureInitializedForIsolate(isolate, |
| 6802 | "v8::Debug::SetDebugMessageDispatchHandler"); |
| 6803 | ENTER_V8(isolate); |
| 6804 | isolate->debugger()->SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6805 | handler, provide_locker); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6806 | } |
| 6807 | |
| 6808 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 6809 | Local<Value> Debug::Call(v8::Handle<v8::Function> fun, |
| 6810 | v8::Handle<v8::Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6811 | i::Isolate* isolate = i::Isolate::Current(); |
| 6812 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 6813 | ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6814 | ENTER_V8(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6815 | i::Handle<i::Object> result; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6816 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6817 | if (data.IsEmpty()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6818 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 6819 | isolate->factory()->undefined_value(), |
| 6820 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6821 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6822 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 6823 | Utils::OpenHandle(*data), |
| 6824 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6825 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6826 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6827 | return Utils::ToLocal(result); |
| 6828 | } |
| 6829 | |
| 6830 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 6831 | Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6832 | i::Isolate* isolate = i::Isolate::Current(); |
| 6833 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 6834 | ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6835 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 6836 | v8::HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6837 | i::Debug* isolate_debug = isolate->debug(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6838 | isolate_debug->Load(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 6839 | i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global_object()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6840 | i::Handle<i::String> name = isolate->factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 6841 | STATIC_ASCII_VECTOR("MakeMirror")); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6842 | i::Handle<i::Object> fun_obj = i::GetProperty(isolate, debug, name); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 6843 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj); |
| 6844 | v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun); |
| 6845 | const int kArgc = 1; |
| 6846 | v8::Handle<v8::Value> argv[kArgc] = { obj }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6847 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 6848 | v8::Handle<v8::Value> result = v8_fun->Call(Utils::ToLocal(debug), |
| 6849 | kArgc, |
| 6850 | argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6851 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 6852 | return scope.Close(result); |
| 6853 | } |
| 6854 | |
| 6855 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6856 | 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] | 6857 | return i::Isolate::Current()->debugger()->StartAgent(name, port, |
| 6858 | wait_for_connection); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6859 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6860 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6861 | |
| 6862 | void Debug::DisableAgent() { |
| 6863 | return i::Isolate::Current()->debugger()->StopAgent(); |
| 6864 | } |
| 6865 | |
| 6866 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6867 | void Debug::ProcessDebugMessages() { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 6868 | i::Execution::ProcessDebugMessages(i::Isolate::Current(), true); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6869 | } |
| 6870 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 6871 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 6872 | Local<Context> Debug::GetDebugContext() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6873 | i::Isolate* isolate = i::Isolate::Current(); |
| 6874 | EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()"); |
| 6875 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6876 | return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext()); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 6877 | } |
| 6878 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 6879 | |
| 6880 | void Debug::SetLiveEditEnabled(bool enable, Isolate* isolate) { |
| 6881 | // If no isolate is supplied, use the default isolate. |
| 6882 | i::Debugger* debugger; |
| 6883 | if (isolate != NULL) { |
| 6884 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6885 | debugger = internal_isolate->debugger(); |
| 6886 | } else { |
| 6887 | debugger = i::Isolate::GetDefaultIsolateDebugger(); |
| 6888 | } |
| 6889 | debugger->set_live_edit_enabled(enable); |
| 6890 | } |
| 6891 | |
| 6892 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6893 | #endif // ENABLE_DEBUGGER_SUPPORT |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6894 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6895 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6896 | Handle<String> CpuProfileNode::GetFunctionName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6897 | i::Isolate* isolate = i::Isolate::Current(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6898 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
| 6899 | const i::CodeEntry* entry = node->entry(); |
| 6900 | if (!entry->has_name_prefix()) { |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6901 | return ToApiHandle<String>( |
| 6902 | isolate->factory()->InternalizeUtf8String(entry->name())); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6903 | } else { |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6904 | return ToApiHandle<String>(isolate->factory()->NewConsString( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6905 | isolate->factory()->InternalizeUtf8String(entry->name_prefix()), |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6906 | isolate->factory()->InternalizeUtf8String(entry->name()))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6907 | } |
| 6908 | } |
| 6909 | |
| 6910 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 6911 | int CpuProfileNode::GetScriptId() const { |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 6912 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
| 6913 | const i::CodeEntry* entry = node->entry(); |
| 6914 | return entry->script_id(); |
| 6915 | } |
| 6916 | |
| 6917 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6918 | Handle<String> CpuProfileNode::GetScriptResourceName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6919 | i::Isolate* isolate = i::Isolate::Current(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6920 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6921 | return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String( |
| 6922 | node->entry()->resource_name())); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6923 | } |
| 6924 | |
| 6925 | |
| 6926 | int CpuProfileNode::GetLineNumber() const { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6927 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number(); |
| 6928 | } |
| 6929 | |
| 6930 | |
mvstanton@chromium.org | dd6d9ee | 2013-10-11 10:35:37 +0000 | [diff] [blame] | 6931 | int CpuProfileNode::GetColumnNumber() const { |
| 6932 | return reinterpret_cast<const i::ProfileNode*>(this)-> |
| 6933 | entry()->column_number(); |
| 6934 | } |
| 6935 | |
| 6936 | |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 6937 | const char* CpuProfileNode::GetBailoutReason() const { |
| 6938 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
| 6939 | return node->entry()->bailout_reason(); |
| 6940 | } |
| 6941 | |
| 6942 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 6943 | unsigned CpuProfileNode::GetHitCount() const { |
| 6944 | return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks(); |
| 6945 | } |
| 6946 | |
| 6947 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6948 | unsigned CpuProfileNode::GetCallUid() const { |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 6949 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6950 | } |
| 6951 | |
| 6952 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6953 | unsigned CpuProfileNode::GetNodeId() const { |
| 6954 | return reinterpret_cast<const i::ProfileNode*>(this)->id(); |
| 6955 | } |
| 6956 | |
| 6957 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6958 | int CpuProfileNode::GetChildrenCount() const { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6959 | return reinterpret_cast<const i::ProfileNode*>(this)->children()->length(); |
| 6960 | } |
| 6961 | |
| 6962 | |
| 6963 | const CpuProfileNode* CpuProfileNode::GetChild(int index) const { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6964 | const i::ProfileNode* child = |
| 6965 | reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index); |
| 6966 | return reinterpret_cast<const CpuProfileNode*>(child); |
| 6967 | } |
| 6968 | |
| 6969 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6970 | void CpuProfile::Delete() { |
| 6971 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6972 | i::CpuProfiler* profiler = isolate->cpu_profiler(); |
| 6973 | ASSERT(profiler != NULL); |
| 6974 | profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this)); |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6975 | if (profiler->GetProfilesCount() == 0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6976 | // If this was the last profile, clean up all accessory data as well. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6977 | profiler->DeleteAllProfiles(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6978 | } |
| 6979 | } |
| 6980 | |
| 6981 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6982 | unsigned CpuProfile::GetUid() const { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6983 | return reinterpret_cast<const i::CpuProfile*>(this)->uid(); |
| 6984 | } |
| 6985 | |
| 6986 | |
| 6987 | Handle<String> CpuProfile::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6988 | i::Isolate* isolate = i::Isolate::Current(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6989 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6990 | return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String( |
| 6991 | profile->title())); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6995 | const CpuProfileNode* CpuProfile::GetTopDownRoot() const { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6996 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 6997 | return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root()); |
| 6998 | } |
| 6999 | |
| 7000 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7001 | const CpuProfileNode* CpuProfile::GetSample(int index) const { |
| 7002 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 7003 | return reinterpret_cast<const CpuProfileNode*>(profile->sample(index)); |
| 7004 | } |
| 7005 | |
| 7006 | |
danno@chromium.org | 89acc0b | 2013-08-09 20:55:58 +0000 | [diff] [blame] | 7007 | int64_t CpuProfile::GetStartTime() const { |
| 7008 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 7009 | return (profile->start_time() - i::Time::UnixEpoch()).InMicroseconds(); |
danno@chromium.org | 89acc0b | 2013-08-09 20:55:58 +0000 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | |
| 7013 | int64_t CpuProfile::GetEndTime() const { |
| 7014 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 7015 | return (profile->end_time() - i::Time::UnixEpoch()).InMicroseconds(); |
danno@chromium.org | 89acc0b | 2013-08-09 20:55:58 +0000 | [diff] [blame] | 7016 | } |
| 7017 | |
| 7018 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7019 | int CpuProfile::GetSamplesCount() const { |
| 7020 | return reinterpret_cast<const i::CpuProfile*>(this)->samples_count(); |
| 7021 | } |
| 7022 | |
| 7023 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7024 | int CpuProfiler::GetProfileCount() { |
| 7025 | return reinterpret_cast<i::CpuProfiler*>(this)->GetProfilesCount(); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 7026 | } |
| 7027 | |
| 7028 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 7029 | void CpuProfiler::SetSamplingInterval(int us) { |
| 7030 | ASSERT(us >= 0); |
| 7031 | return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval( |
| 7032 | i::TimeDelta::FromMicroseconds(us)); |
| 7033 | } |
| 7034 | |
| 7035 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 7036 | const CpuProfile* CpuProfiler::GetCpuProfile(int index) { |
| 7037 | return reinterpret_cast<const CpuProfile*>( |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 7038 | reinterpret_cast<i::CpuProfiler*>(this)->GetProfile(index)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7039 | } |
| 7040 | |
| 7041 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7042 | void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) { |
| 7043 | reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling( |
| 7044 | *Utils::OpenHandle(*title), record_samples); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 7045 | } |
| 7046 | |
| 7047 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 7048 | const CpuProfile* CpuProfiler::StopCpuProfiling(Handle<String> title) { |
| 7049 | return reinterpret_cast<const CpuProfile*>( |
| 7050 | reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling( |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 7051 | *Utils::OpenHandle(*title))); |
| 7052 | } |
| 7053 | |
| 7054 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7055 | void CpuProfiler::DeleteAllCpuProfiles() { |
| 7056 | reinterpret_cast<i::CpuProfiler*>(this)->DeleteAllProfiles(); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 7057 | } |
| 7058 | |
| 7059 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7060 | void CpuProfiler::SetIdle(bool is_idle) { |
| 7061 | i::Isolate* isolate = reinterpret_cast<i::CpuProfiler*>(this)->isolate(); |
| 7062 | i::StateTag state = isolate->current_vm_state(); |
| 7063 | ASSERT(state == i::EXTERNAL || state == i::IDLE); |
| 7064 | if (isolate->js_entry_sp() != NULL) return; |
| 7065 | if (is_idle) { |
| 7066 | isolate->set_current_vm_state(i::IDLE); |
| 7067 | } else if (state == i::IDLE) { |
| 7068 | isolate->set_current_vm_state(i::EXTERNAL); |
| 7069 | } |
| 7070 | } |
| 7071 | |
| 7072 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7073 | static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) { |
| 7074 | return const_cast<i::HeapGraphEdge*>( |
| 7075 | reinterpret_cast<const i::HeapGraphEdge*>(edge)); |
| 7076 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 7077 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7078 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7079 | HeapGraphEdge::Type HeapGraphEdge::GetType() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7080 | return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7081 | } |
| 7082 | |
| 7083 | |
| 7084 | Handle<Value> HeapGraphEdge::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7085 | i::Isolate* isolate = i::Isolate::Current(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7086 | i::HeapGraphEdge* edge = ToInternal(this); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7087 | switch (edge->type()) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7088 | case i::HeapGraphEdge::kContextVariable: |
| 7089 | case i::HeapGraphEdge::kInternal: |
| 7090 | case i::HeapGraphEdge::kProperty: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 7091 | case i::HeapGraphEdge::kShortcut: |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 7092 | return ToApiHandle<String>( |
| 7093 | isolate->factory()->InternalizeUtf8String(edge->name())); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7094 | case i::HeapGraphEdge::kElement: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 7095 | case i::HeapGraphEdge::kHidden: |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 7096 | case i::HeapGraphEdge::kWeak: |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 7097 | return ToApiHandle<Number>( |
| 7098 | isolate->factory()->NewNumberFromInt(edge->index())); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7099 | default: UNREACHABLE(); |
| 7100 | } |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 7101 | return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7102 | } |
| 7103 | |
| 7104 | |
| 7105 | const HeapGraphNode* HeapGraphEdge::GetFromNode() const { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 7106 | const i::HeapEntry* from = ToInternal(this)->from(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7107 | return reinterpret_cast<const HeapGraphNode*>(from); |
| 7108 | } |
| 7109 | |
| 7110 | |
| 7111 | const HeapGraphNode* HeapGraphEdge::GetToNode() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7112 | const i::HeapEntry* to = ToInternal(this)->to(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7113 | return reinterpret_cast<const HeapGraphNode*>(to); |
| 7114 | } |
| 7115 | |
| 7116 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7117 | static i::HeapEntry* ToInternal(const HeapGraphNode* entry) { |
| 7118 | return const_cast<i::HeapEntry*>( |
| 7119 | reinterpret_cast<const i::HeapEntry*>(entry)); |
| 7120 | } |
| 7121 | |
| 7122 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7123 | HeapGraphNode::Type HeapGraphNode::GetType() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7124 | return static_cast<HeapGraphNode::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7125 | } |
| 7126 | |
| 7127 | |
| 7128 | Handle<String> HeapGraphNode::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7129 | i::Isolate* isolate = i::Isolate::Current(); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 7130 | return ToApiHandle<String>( |
| 7131 | isolate->factory()->InternalizeUtf8String(ToInternal(this)->name())); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7132 | } |
| 7133 | |
| 7134 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7135 | SnapshotObjectId HeapGraphNode::GetId() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7136 | return ToInternal(this)->id(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 7137 | } |
| 7138 | |
| 7139 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7140 | int HeapGraphNode::GetSelfSize() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7141 | return ToInternal(this)->self_size(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7142 | } |
| 7143 | |
| 7144 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7145 | int HeapGraphNode::GetChildrenCount() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7146 | return ToInternal(this)->children().length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7147 | } |
| 7148 | |
| 7149 | |
| 7150 | const HeapGraphEdge* HeapGraphNode::GetChild(int index) const { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7151 | return reinterpret_cast<const HeapGraphEdge*>( |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 7152 | ToInternal(this)->children()[index]); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7153 | } |
| 7154 | |
| 7155 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7156 | v8::Handle<v8::Value> HeapGraphNode::GetHeapValue() const { |
| 7157 | i::Isolate* isolate = i::Isolate::Current(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7158 | i::Handle<i::HeapObject> object = ToInternal(this)->GetHeapObject(); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 7159 | return !object.is_null() ? |
| 7160 | ToApiHandle<Value>(object) : |
| 7161 | ToApiHandle<Value>(isolate->factory()->undefined_value()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7162 | } |
| 7163 | |
| 7164 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7165 | static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) { |
| 7166 | return const_cast<i::HeapSnapshot*>( |
| 7167 | reinterpret_cast<const i::HeapSnapshot*>(snapshot)); |
| 7168 | } |
| 7169 | |
| 7170 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7171 | void HeapSnapshot::Delete() { |
| 7172 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7173 | if (isolate->heap_profiler()->GetSnapshotsCount() > 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7174 | ToInternal(this)->Delete(); |
| 7175 | } else { |
| 7176 | // If this is the last snapshot, clean up all accessory data as well. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7177 | isolate->heap_profiler()->DeleteAllSnapshots(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7178 | } |
| 7179 | } |
| 7180 | |
| 7181 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7182 | unsigned HeapSnapshot::GetUid() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7183 | return ToInternal(this)->uid(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7184 | } |
| 7185 | |
| 7186 | |
| 7187 | Handle<String> HeapSnapshot::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7188 | i::Isolate* isolate = i::Isolate::Current(); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 7189 | return ToApiHandle<String>( |
| 7190 | isolate->factory()->InternalizeUtf8String(ToInternal(this)->title())); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7191 | } |
| 7192 | |
| 7193 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 7194 | const HeapGraphNode* HeapSnapshot::GetRoot() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7195 | return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7196 | } |
| 7197 | |
| 7198 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7199 | const HeapGraphNode* HeapSnapshot::GetNodeById(SnapshotObjectId id) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7200 | return reinterpret_cast<const HeapGraphNode*>( |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7201 | ToInternal(this)->GetEntryById(id)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7202 | } |
| 7203 | |
| 7204 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 7205 | int HeapSnapshot::GetNodesCount() const { |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 7206 | return ToInternal(this)->entries().length(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 7207 | } |
| 7208 | |
| 7209 | |
| 7210 | const HeapGraphNode* HeapSnapshot::GetNode(int index) const { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 7211 | return reinterpret_cast<const HeapGraphNode*>( |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 7212 | &ToInternal(this)->entries().at(index)); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 7213 | } |
| 7214 | |
| 7215 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7216 | SnapshotObjectId HeapSnapshot::GetMaxSnapshotJSObjectId() const { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7217 | return ToInternal(this)->max_snapshot_js_object_id(); |
| 7218 | } |
| 7219 | |
| 7220 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 7221 | void HeapSnapshot::Serialize(OutputStream* stream, |
| 7222 | HeapSnapshot::SerializationFormat format) const { |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 7223 | ApiCheck(format == kJSON, |
| 7224 | "v8::HeapSnapshot::Serialize", |
| 7225 | "Unknown serialization format"); |
| 7226 | ApiCheck(stream->GetOutputEncoding() == OutputStream::kAscii, |
| 7227 | "v8::HeapSnapshot::Serialize", |
| 7228 | "Unsupported output encoding"); |
| 7229 | ApiCheck(stream->GetChunkSize() > 0, |
| 7230 | "v8::HeapSnapshot::Serialize", |
| 7231 | "Invalid stream chunk size"); |
| 7232 | i::HeapSnapshotJSONSerializer serializer(ToInternal(this)); |
| 7233 | serializer.Serialize(stream); |
| 7234 | } |
| 7235 | |
| 7236 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7237 | int HeapProfiler::GetSnapshotCount() { |
| 7238 | return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7239 | } |
| 7240 | |
| 7241 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7242 | const HeapSnapshot* HeapProfiler::GetHeapSnapshot(int index) { |
| 7243 | return reinterpret_cast<const HeapSnapshot*>( |
| 7244 | reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7245 | } |
| 7246 | |
| 7247 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7248 | SnapshotObjectId HeapProfiler::GetObjectId(Handle<Value> value) { |
| 7249 | i::Handle<i::Object> obj = Utils::OpenHandle(*value); |
| 7250 | return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotObjectId(obj); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 7251 | } |
| 7252 | |
| 7253 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7254 | const HeapSnapshot* HeapProfiler::TakeHeapSnapshot( |
| 7255 | Handle<String> title, |
| 7256 | ActivityControl* control, |
| 7257 | ObjectNameResolver* resolver) { |
| 7258 | return reinterpret_cast<const HeapSnapshot*>( |
| 7259 | reinterpret_cast<i::HeapProfiler*>(this)->TakeSnapshot( |
| 7260 | *Utils::OpenHandle(*title), control, resolver)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7261 | } |
| 7262 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 7263 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7264 | void HeapProfiler::StartTrackingHeapObjects() { |
| 7265 | reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 7266 | } |
| 7267 | |
| 7268 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7269 | void HeapProfiler::StopTrackingHeapObjects() { |
| 7270 | reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking(); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 7271 | } |
| 7272 | |
| 7273 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7274 | SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream) { |
| 7275 | return reinterpret_cast<i::HeapProfiler*>(this)->PushHeapObjectsStats(stream); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 7276 | } |
| 7277 | |
| 7278 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7279 | void HeapProfiler::DeleteAllHeapSnapshots() { |
| 7280 | reinterpret_cast<i::HeapProfiler*>(this)->DeleteAllSnapshots(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7281 | } |
| 7282 | |
| 7283 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7284 | void HeapProfiler::SetWrapperClassInfoProvider(uint16_t class_id, |
| 7285 | WrapperInfoCallback callback) { |
| 7286 | reinterpret_cast<i::HeapProfiler*>(this)->DefineWrapperClass(class_id, |
| 7287 | callback); |
| 7288 | } |
| 7289 | |
| 7290 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7291 | size_t HeapProfiler::GetProfilerMemorySize() { |
| 7292 | return reinterpret_cast<i::HeapProfiler*>(this)-> |
| 7293 | GetMemorySizeUsedByProfiler(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 7294 | } |
| 7295 | |
| 7296 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7297 | void HeapProfiler::SetRetainedObjectInfo(UniqueId id, |
| 7298 | RetainedObjectInfo* info) { |
| 7299 | reinterpret_cast<i::HeapProfiler*>(this)->SetRetainedObjectInfo(id, info); |
| 7300 | } |
| 7301 | |
| 7302 | |
mstarzinger@chromium.org | a2e1a40 | 2013-10-15 08:25:05 +0000 | [diff] [blame] | 7303 | void HeapProfiler::StartRecordingHeapAllocations() { |
| 7304 | reinterpret_cast<i::HeapProfiler*>(this)->StartHeapAllocationsRecording(); |
| 7305 | } |
| 7306 | |
| 7307 | |
| 7308 | void HeapProfiler::StopRecordingHeapAllocations() { |
| 7309 | reinterpret_cast<i::HeapProfiler*>(this)->StopHeapAllocationsRecording(); |
| 7310 | } |
| 7311 | |
| 7312 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7313 | v8::Testing::StressType internal::Testing::stress_type_ = |
| 7314 | v8::Testing::kStressTypeOpt; |
| 7315 | |
| 7316 | |
| 7317 | void Testing::SetStressRunType(Testing::StressType type) { |
| 7318 | internal::Testing::set_stress_type(type); |
| 7319 | } |
| 7320 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 7321 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7322 | int Testing::GetStressRuns() { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 7323 | if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7324 | #ifdef DEBUG |
| 7325 | // In debug mode the code runs much slower so stressing will only make two |
| 7326 | // runs. |
| 7327 | return 2; |
| 7328 | #else |
| 7329 | return 5; |
| 7330 | #endif |
| 7331 | } |
| 7332 | |
| 7333 | |
| 7334 | static void SetFlagsFromString(const char* flags) { |
| 7335 | V8::SetFlagsFromString(flags, i::StrLength(flags)); |
| 7336 | } |
| 7337 | |
| 7338 | |
| 7339 | void Testing::PrepareStressRun(int run) { |
| 7340 | static const char* kLazyOptimizations = |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 7341 | "--prepare-always-opt " |
| 7342 | "--max-inlined-source-size=999999 " |
| 7343 | "--max-inlined-nodes=999999 " |
| 7344 | "--max-inlined-nodes-cumulative=999999 " |
| 7345 | "--noalways-opt"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7346 | static const char* kForcedOptimizations = "--always-opt"; |
| 7347 | |
| 7348 | // If deoptimization stressed turn on frequent deoptimization. If no value |
| 7349 | // is spefified through --deopt-every-n-times use a default default value. |
| 7350 | static const char* kDeoptEvery13Times = "--deopt-every-n-times=13"; |
| 7351 | if (internal::Testing::stress_type() == Testing::kStressTypeDeopt && |
| 7352 | internal::FLAG_deopt_every_n_times == 0) { |
| 7353 | SetFlagsFromString(kDeoptEvery13Times); |
| 7354 | } |
| 7355 | |
| 7356 | #ifdef DEBUG |
| 7357 | // As stressing in debug mode only make two runs skip the deopt stressing |
| 7358 | // here. |
| 7359 | if (run == GetStressRuns() - 1) { |
| 7360 | SetFlagsFromString(kForcedOptimizations); |
| 7361 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7362 | SetFlagsFromString(kLazyOptimizations); |
| 7363 | } |
| 7364 | #else |
| 7365 | if (run == GetStressRuns() - 1) { |
| 7366 | SetFlagsFromString(kForcedOptimizations); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 7367 | } else if (run != GetStressRuns() - 2) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7368 | SetFlagsFromString(kLazyOptimizations); |
| 7369 | } |
| 7370 | #endif |
| 7371 | } |
| 7372 | |
| 7373 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7374 | // TODO(svenpanne) Deprecate this. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 7375 | void Testing::DeoptimizeAll() { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7376 | i::Isolate* isolate = i::Isolate::Current(); |
| 7377 | i::HandleScope scope(isolate); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 7378 | internal::Deoptimizer::DeoptimizeAll(isolate); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 7379 | } |
| 7380 | |
| 7381 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7382 | namespace internal { |
| 7383 | |
| 7384 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7385 | void HandleScopeImplementer::FreeThreadResources() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7386 | Free(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7387 | } |
| 7388 | |
| 7389 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7390 | char* HandleScopeImplementer::ArchiveThread(char* storage) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 7391 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7392 | isolate_->handle_scope_data(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7393 | handle_scope_data_ = *current; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7394 | OS::MemCopy(storage, this, sizeof(*this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7395 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7396 | ResetAfterArchive(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7397 | current->Initialize(); |
| 7398 | |
| 7399 | return storage + ArchiveSpacePerThread(); |
| 7400 | } |
| 7401 | |
| 7402 | |
| 7403 | int HandleScopeImplementer::ArchiveSpacePerThread() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7404 | return sizeof(HandleScopeImplementer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7405 | } |
| 7406 | |
| 7407 | |
| 7408 | char* HandleScopeImplementer::RestoreThread(char* storage) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7409 | OS::MemCopy(this, storage, sizeof(*this)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7410 | *isolate_->handle_scope_data() = handle_scope_data_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7411 | return storage + ArchiveSpacePerThread(); |
| 7412 | } |
| 7413 | |
| 7414 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 7415 | void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7416 | #ifdef DEBUG |
| 7417 | bool found_block_before_deferred = false; |
| 7418 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7419 | // Iterate over all handles in the blocks except for the last. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7420 | for (int i = blocks()->length() - 2; i >= 0; --i) { |
| 7421 | Object** block = blocks()->at(i); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7422 | if (last_handle_before_deferred_block_ != NULL && |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 7423 | (last_handle_before_deferred_block_ <= &block[kHandleBlockSize]) && |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7424 | (last_handle_before_deferred_block_ >= block)) { |
| 7425 | v->VisitPointers(block, last_handle_before_deferred_block_); |
| 7426 | ASSERT(!found_block_before_deferred); |
| 7427 | #ifdef DEBUG |
| 7428 | found_block_before_deferred = true; |
| 7429 | #endif |
| 7430 | } else { |
| 7431 | v->VisitPointers(block, &block[kHandleBlockSize]); |
| 7432 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7433 | } |
| 7434 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7435 | ASSERT(last_handle_before_deferred_block_ == NULL || |
| 7436 | found_block_before_deferred); |
| 7437 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7438 | // Iterate over live handles in the last block (if any). |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7439 | if (!blocks()->is_empty()) { |
| 7440 | v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 7441 | } |
| 7442 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 7443 | List<Context*>* context_lists[2] = { &saved_contexts_, &entered_contexts_}; |
| 7444 | for (unsigned i = 0; i < ARRAY_SIZE(context_lists); i++) { |
| 7445 | if (context_lists[i]->is_empty()) continue; |
| 7446 | Object** start = reinterpret_cast<Object**>(&context_lists[i]->first()); |
| 7447 | v->VisitPointers(start, start + context_lists[i]->length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7448 | } |
| 7449 | } |
| 7450 | |
| 7451 | |
| 7452 | void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 7453 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7454 | isolate_->handle_scope_data(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7455 | handle_scope_data_ = *current; |
| 7456 | IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7457 | } |
| 7458 | |
| 7459 | |
| 7460 | char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 7461 | HandleScopeImplementer* scope_implementer = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7462 | reinterpret_cast<HandleScopeImplementer*>(storage); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 7463 | scope_implementer->IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7464 | return storage + ArchiveSpacePerThread(); |
| 7465 | } |
| 7466 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7467 | |
| 7468 | DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 7469 | DeferredHandles* deferred = |
| 7470 | new DeferredHandles(isolate()->handle_scope_data()->next, isolate()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7471 | |
| 7472 | while (!blocks_.is_empty()) { |
| 7473 | Object** block_start = blocks_.last(); |
| 7474 | Object** block_limit = &block_start[kHandleBlockSize]; |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 7475 | // We should not need to check for SealHandleScope here. Assert this. |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7476 | ASSERT(prev_limit == block_limit || |
| 7477 | !(block_start <= prev_limit && prev_limit <= block_limit)); |
| 7478 | if (prev_limit == block_limit) break; |
| 7479 | deferred->blocks_.Add(blocks_.last()); |
| 7480 | blocks_.RemoveLast(); |
| 7481 | } |
| 7482 | |
| 7483 | // deferred->blocks_ now contains the blocks installed on the |
| 7484 | // HandleScope stack since BeginDeferredScope was called, but in |
| 7485 | // reverse order. |
| 7486 | |
| 7487 | ASSERT(prev_limit == NULL || !blocks_.is_empty()); |
| 7488 | |
| 7489 | ASSERT(!blocks_.is_empty() && prev_limit != NULL); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7490 | ASSERT(last_handle_before_deferred_block_ != NULL); |
| 7491 | last_handle_before_deferred_block_ = NULL; |
| 7492 | return deferred; |
| 7493 | } |
| 7494 | |
| 7495 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7496 | void HandleScopeImplementer::BeginDeferredScope() { |
| 7497 | ASSERT(last_handle_before_deferred_block_ == NULL); |
| 7498 | last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next; |
| 7499 | } |
| 7500 | |
| 7501 | |
| 7502 | DeferredHandles::~DeferredHandles() { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 7503 | isolate_->UnlinkDeferredHandles(this); |
| 7504 | |
| 7505 | for (int i = 0; i < blocks_.length(); i++) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 7506 | #ifdef ENABLE_HANDLE_ZAPPING |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 7507 | HandleScope::ZapRange(blocks_[i], &blocks_[i][kHandleBlockSize]); |
| 7508 | #endif |
| 7509 | isolate_->handle_scope_implementer()->ReturnBlock(blocks_[i]); |
| 7510 | } |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7511 | } |
| 7512 | |
| 7513 | |
| 7514 | void DeferredHandles::Iterate(ObjectVisitor* v) { |
| 7515 | ASSERT(!blocks_.is_empty()); |
| 7516 | |
| 7517 | ASSERT((first_block_limit_ >= blocks_.first()) && |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7518 | (first_block_limit_ <= &(blocks_.first())[kHandleBlockSize])); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7519 | |
| 7520 | v->VisitPointers(blocks_.first(), first_block_limit_); |
| 7521 | |
| 7522 | for (int i = 1; i < blocks_.length(); i++) { |
| 7523 | v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
| 7524 | } |
| 7525 | } |
| 7526 | |
| 7527 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7528 | void InvokeAccessorGetterCallback( |
| 7529 | v8::Local<v8::String> property, |
| 7530 | const v8::PropertyCallbackInfo<v8::Value>& info, |
| 7531 | v8::AccessorGetterCallback getter) { |
| 7532 | // Leaving JavaScript. |
| 7533 | Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7534 | Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>( |
| 7535 | getter)); |
| 7536 | VMState<EXTERNAL> state(isolate); |
| 7537 | ExternalCallbackScope call_scope(isolate, getter_address); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 7538 | getter(property, info); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7539 | } |
| 7540 | |
| 7541 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7542 | void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info, |
| 7543 | v8::FunctionCallback callback) { |
| 7544 | Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7545 | Address callback_address = |
| 7546 | reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7547 | VMState<EXTERNAL> state(isolate); |
| 7548 | ExternalCallbackScope call_scope(isolate, callback_address); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 7549 | callback(info); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7550 | } |
| 7551 | |
| 7552 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7553 | } } // namespace v8::internal |